diff --git a/cmake/Modules/protobuf.cmake b/cmake/Modules/protobuf.cmake index c86a567..6546ab8 100644 --- a/cmake/Modules/protobuf.cmake +++ b/cmake/Modules/protobuf.cmake @@ -29,6 +29,8 @@ function(protobuf_generate_cpp) OUTPUT "${protoDIR}/${protoFILENAME}.pb.cc" DEPENDS "${protoDIR}/${protoFILENAME}.proto" COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto" + + # COMMAND protoc --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto" ) ENDFOREACH(proto) diff --git a/include/WHISPER/Messages/Protos/join.pb.cc b/include/WHISPER/Messages/Protos/join.pb.cc index 9edd0a0..2abbb8b 100644 --- a/include/WHISPER/Messages/Protos/join.pb.cc +++ b/include/WHISPER/Messages/Protos/join.pb.cc @@ -4,20 +4,22 @@ #include "join.pb.h" #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + namespace messages { namespace join { PROTOBUF_CONSTEXPR Join::Join( @@ -26,86 +28,60 @@ PROTOBUF_CONSTEXPR Join::Join( , /*decltype(_impl_.port_)*/0u , /*decltype(_impl_._cached_size_)*/{}} {} struct JoinDefaultTypeInternal { - PROTOBUF_CONSTEXPR JoinDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR JoinDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~JoinDefaultTypeInternal() {} union { Join _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 JoinDefaultTypeInternal _Join_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 JoinDefaultTypeInternal _Join_default_instance_; } // namespace join } // namespace messages static ::_pb::Metadata file_level_metadata_join_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_join_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_join_2eproto = nullptr; -const uint32_t TableStruct_join_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::messages::join::Join, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::messages::join::Join, _impl_.port_), - PROTOBUF_FIELD_OFFSET(::messages::join::Join, _impl_.srcaddress_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_join_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_join_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::messages::join::Join)}, +const uint32_t TableStruct_join_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::messages::join::Join, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::messages::join::Join, _impl_.port_), + PROTOBUF_FIELD_OFFSET(::messages::join::Join, _impl_.srcaddress_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::messages::join::Join)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::messages::join::_Join_default_instance_._instance, -}; -const char descriptor_table_protodef_join_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\njoin.proto\022\rmessages.join\"(\n\004Join\022\014\n\004p" - "ort\030\001 \001(\r\022\022\n\nsrcAddress\030\002 \001(\tb\006proto3" -}; -static ::absl::once_flag descriptor_table_join_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_join_2eproto = { - false, - false, - 77, - descriptor_table_protodef_join_2eproto, - "join.proto", - &descriptor_table_join_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_join_2eproto::offsets, - file_level_metadata_join_2eproto, - file_level_enum_descriptors_join_2eproto, - file_level_service_descriptors_join_2eproto, + &::messages::join::_Join_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_join_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\njoin.proto\022\rmessages.join\"(\n\004Join\022\014\n\004p" + "ort\030\001 \001(\r\022\022\n\nsrcAddress\030\002 \001(\tb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_join_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_join_2eproto = { + false, false, 77, descriptor_table_protodef_join_2eproto, + "join.proto", + &descriptor_table_join_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_join_2eproto::offsets, + file_level_metadata_join_2eproto, file_level_enum_descriptors_join_2eproto, + file_level_service_descriptors_join_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_join_2eproto_getter() { return &descriptor_table_join_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_join_2eproto(&descriptor_table_join_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_join_2eproto(&descriptor_table_join_2eproto); namespace messages { namespace join { + // =================================================================== class Join::_Internal { @@ -184,7 +160,6 @@ void Join::Clear() { } const char* Join::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -233,7 +208,6 @@ failure: uint8_t* Join::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:messages.join.Join) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -263,7 +237,6 @@ uint8_t* Join::_InternalSerialize( } size_t Join::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:messages.join.Join) size_t total_size = 0; @@ -296,7 +269,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Join::GetClassData() const { r void Join::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:messages.join.Join) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -335,11 +307,11 @@ void Join::InternalSwap(Join* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Join::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_join_2eproto_getter, &descriptor_table_join_2eproto_once, file_level_metadata_join_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) } // namespace join } // namespace messages @@ -349,5 +321,6 @@ Arena::CreateMaybeMessage< ::messages::join::Join >(Arena* arena) { return Arena::CreateMessageInternal< ::messages::join::Join >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/include/WHISPER/Messages/Protos/join.pb.h b/include/WHISPER/Messages/Protos/join.pb.h index 415c872..4ca2e52 100644 --- a/include/WHISPER/Messages/Protos/join.pb.h +++ b/include/WHISPER/Messages/Protos/join.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: join.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_join_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_join_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_join_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_join_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_join_2eproto - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,8 +43,7 @@ PROTOBUF_NAMESPACE_CLOSE struct TableStruct_join_2eproto { static const uint32_t offsets[]; }; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_join_2eproto; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_join_2eproto; namespace messages { namespace join { class Join; @@ -58,18 +52,13 @@ extern JoinDefaultTypeInternal _Join_default_instance_; } // namespace join } // namespace messages PROTOBUF_NAMESPACE_OPEN -template <> -::messages::join::Join* Arena::CreateMaybeMessage<::messages::join::Join>(Arena*); +template<> ::messages::join::Join* Arena::CreateMaybeMessage<::messages::join::Join>(Arena*); PROTOBUF_NAMESPACE_CLOSE - namespace messages { namespace join { // =================================================================== - -// ------------------------------------------------------------------- - class Join final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:messages.join.Join) */ { public: @@ -173,7 +162,7 @@ class Join final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "messages.join.Join"; } protected: @@ -235,17 +224,12 @@ class Join final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Join // uint32 port = 1; @@ -260,7 +244,7 @@ inline uint32_t Join::port() const { return _internal_port(); } inline void Join::_internal_set_port(uint32_t value) { - + _impl_.port_ = value; } inline void Join::set_port(uint32_t value) { @@ -292,11 +276,11 @@ inline const std::string& Join::_internal_srcaddress() const { return _impl_.srcaddress_.Get(); } inline void Join::_internal_set_srcaddress(const std::string& value) { - + _impl_.srcaddress_.Set(value, GetArenaForAllocation()); } inline std::string* Join::_internal_mutable_srcaddress() { - + return _impl_.srcaddress_.Mutable(GetArenaForAllocation()); } inline std::string* Join::release_srcaddress() { @@ -304,6 +288,11 @@ inline std::string* Join::release_srcaddress() { return _impl_.srcaddress_.Release(); } inline void Join::set_allocated_srcaddress(std::string* srcaddress) { + if (srcaddress != nullptr) { + + } else { + + } _impl_.srcaddress_.SetAllocated(srcaddress, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.srcaddress_.IsDefault()) { @@ -314,16 +303,15 @@ inline void Join::set_allocated_srcaddress(std::string* srcaddress) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) + } // namespace join } // namespace messages - // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_join_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_join_2eproto diff --git a/include/WHISPER/Messages/Protos/leave.pb.cc b/include/WHISPER/Messages/Protos/leave.pb.cc index d99a3dd..9c650d8 100644 --- a/include/WHISPER/Messages/Protos/leave.pb.cc +++ b/include/WHISPER/Messages/Protos/leave.pb.cc @@ -4,20 +4,22 @@ #include "leave.pb.h" #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + namespace messages { namespace leave { PROTOBUF_CONSTEXPR Leave::Leave( @@ -26,86 +28,60 @@ PROTOBUF_CONSTEXPR Leave::Leave( , /*decltype(_impl_.port_)*/0u , /*decltype(_impl_._cached_size_)*/{}} {} struct LeaveDefaultTypeInternal { - PROTOBUF_CONSTEXPR LeaveDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR LeaveDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~LeaveDefaultTypeInternal() {} union { Leave _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 LeaveDefaultTypeInternal _Leave_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 LeaveDefaultTypeInternal _Leave_default_instance_; } // namespace leave } // namespace messages static ::_pb::Metadata file_level_metadata_leave_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_leave_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_leave_2eproto = nullptr; -const uint32_t TableStruct_leave_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _impl_.port_), - PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _impl_.srcaddress_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_leave_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_leave_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::messages::leave::Leave)}, +const uint32_t TableStruct_leave_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _impl_.port_), + PROTOBUF_FIELD_OFFSET(::messages::leave::Leave, _impl_.srcaddress_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::messages::leave::Leave)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::messages::leave::_Leave_default_instance_._instance, -}; -const char descriptor_table_protodef_leave_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\013leave.proto\022\016messages.leave\")\n\005Leave\022\014" - "\n\004port\030\001 \001(\r\022\022\n\nsrcAddress\030\002 \001(\tb\006proto3" -}; -static ::absl::once_flag descriptor_table_leave_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_leave_2eproto = { - false, - false, - 80, - descriptor_table_protodef_leave_2eproto, - "leave.proto", - &descriptor_table_leave_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_leave_2eproto::offsets, - file_level_metadata_leave_2eproto, - file_level_enum_descriptors_leave_2eproto, - file_level_service_descriptors_leave_2eproto, + &::messages::leave::_Leave_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_leave_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\013leave.proto\022\016messages.leave\")\n\005Leave\022\014" + "\n\004port\030\001 \001(\r\022\022\n\nsrcAddress\030\002 \001(\tb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_leave_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_leave_2eproto = { + false, false, 80, descriptor_table_protodef_leave_2eproto, + "leave.proto", + &descriptor_table_leave_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_leave_2eproto::offsets, + file_level_metadata_leave_2eproto, file_level_enum_descriptors_leave_2eproto, + file_level_service_descriptors_leave_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_leave_2eproto_getter() { return &descriptor_table_leave_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_leave_2eproto(&descriptor_table_leave_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_leave_2eproto(&descriptor_table_leave_2eproto); namespace messages { namespace leave { + // =================================================================== class Leave::_Internal { @@ -184,7 +160,6 @@ void Leave::Clear() { } const char* Leave::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -233,7 +208,6 @@ failure: uint8_t* Leave::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:messages.leave.Leave) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -263,7 +237,6 @@ uint8_t* Leave::_InternalSerialize( } size_t Leave::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:messages.leave.Leave) size_t total_size = 0; @@ -296,7 +269,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Leave::GetClassData() const { void Leave::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:messages.leave.Leave) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -335,11 +307,11 @@ void Leave::InternalSwap(Leave* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Leave::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_leave_2eproto_getter, &descriptor_table_leave_2eproto_once, file_level_metadata_leave_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) } // namespace leave } // namespace messages @@ -349,5 +321,6 @@ Arena::CreateMaybeMessage< ::messages::leave::Leave >(Arena* arena) { return Arena::CreateMessageInternal< ::messages::leave::Leave >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/include/WHISPER/Messages/Protos/leave.pb.h b/include/WHISPER/Messages/Protos/leave.pb.h index 922ba49..607b435 100644 --- a/include/WHISPER/Messages/Protos/leave.pb.h +++ b/include/WHISPER/Messages/Protos/leave.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: leave.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_leave_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_leave_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_leave_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_leave_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_leave_2eproto - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,8 +43,7 @@ PROTOBUF_NAMESPACE_CLOSE struct TableStruct_leave_2eproto { static const uint32_t offsets[]; }; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_leave_2eproto; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_leave_2eproto; namespace messages { namespace leave { class Leave; @@ -58,18 +52,13 @@ extern LeaveDefaultTypeInternal _Leave_default_instance_; } // namespace leave } // namespace messages PROTOBUF_NAMESPACE_OPEN -template <> -::messages::leave::Leave* Arena::CreateMaybeMessage<::messages::leave::Leave>(Arena*); +template<> ::messages::leave::Leave* Arena::CreateMaybeMessage<::messages::leave::Leave>(Arena*); PROTOBUF_NAMESPACE_CLOSE - namespace messages { namespace leave { // =================================================================== - -// ------------------------------------------------------------------- - class Leave final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:messages.leave.Leave) */ { public: @@ -173,7 +162,7 @@ class Leave final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "messages.leave.Leave"; } protected: @@ -235,17 +224,12 @@ class Leave final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Leave // uint32 port = 1; @@ -260,7 +244,7 @@ inline uint32_t Leave::port() const { return _internal_port(); } inline void Leave::_internal_set_port(uint32_t value) { - + _impl_.port_ = value; } inline void Leave::set_port(uint32_t value) { @@ -292,11 +276,11 @@ inline const std::string& Leave::_internal_srcaddress() const { return _impl_.srcaddress_.Get(); } inline void Leave::_internal_set_srcaddress(const std::string& value) { - + _impl_.srcaddress_.Set(value, GetArenaForAllocation()); } inline std::string* Leave::_internal_mutable_srcaddress() { - + return _impl_.srcaddress_.Mutable(GetArenaForAllocation()); } inline std::string* Leave::release_srcaddress() { @@ -304,6 +288,11 @@ inline std::string* Leave::release_srcaddress() { return _impl_.srcaddress_.Release(); } inline void Leave::set_allocated_srcaddress(std::string* srcaddress) { + if (srcaddress != nullptr) { + + } else { + + } _impl_.srcaddress_.SetAllocated(srcaddress, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.srcaddress_.IsDefault()) { @@ -314,16 +303,15 @@ inline void Leave::set_allocated_srcaddress(std::string* srcaddress) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) + } // namespace leave } // namespace messages - // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_leave_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_leave_2eproto diff --git a/include/WHISPER/Messages/Protos/message.pb.cc b/include/WHISPER/Messages/Protos/message.pb.cc index 619d442..164cb71 100644 --- a/include/WHISPER/Messages/Protos/message.pb.cc +++ b/include/WHISPER/Messages/Protos/message.pb.cc @@ -4,20 +4,22 @@ #include "message.pb.h" #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + namespace messages { namespace header { PROTOBUF_CONSTEXPR Message::Message( @@ -29,96 +31,69 @@ PROTOBUF_CONSTEXPR Message::Message( , /*decltype(_impl_.sourceid_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct MessageDefaultTypeInternal { - PROTOBUF_CONSTEXPR MessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MessageDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MessageDefaultTypeInternal() {} union { Message _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MessageDefaultTypeInternal _Message_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MessageDefaultTypeInternal _Message_default_instance_; } // namespace header } // namespace messages static ::_pb::Metadata file_level_metadata_message_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_message_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_message_2eproto = nullptr; -const uint32_t TableStruct_message_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.topic_), - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.msgtype_), - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.sourcetype_), - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.sourceid_), - PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.payload_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_message_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_message_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::messages::header::Message)}, +const uint32_t TableStruct_message_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.topic_), + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.msgtype_), + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.sourcetype_), + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.sourceid_), + PROTOBUF_FIELD_OFFSET(::messages::header::Message, _impl_.payload_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::messages::header::Message)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::messages::header::_Message_default_instance_._instance, -}; -const char descriptor_table_protodef_message_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\rmessage.proto\022\017messages.header\032\031google" - "/protobuf/any.proto\"v\n\007Message\022\r\n\005topic\030" - "\001 \001(\r\022\017\n\007msgType\030\002 \001(\005\022\022\n\nsourceType\030\003 \001" - "(\005\022\020\n\010sourceID\030\004 \001(\005\022%\n\007payload\030\005 \003(\0132\024." - "google.protobuf.Anyb\006proto3" -}; -static const ::_pbi::DescriptorTable* const descriptor_table_message_2eproto_deps[1] = - { - &::descriptor_table_google_2fprotobuf_2fany_2eproto, -}; -static ::absl::once_flag descriptor_table_message_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_message_2eproto = { - false, - false, - 187, - descriptor_table_protodef_message_2eproto, - "message.proto", - &descriptor_table_message_2eproto_once, - descriptor_table_message_2eproto_deps, - 1, - 1, - schemas, - file_default_instances, - TableStruct_message_2eproto::offsets, - file_level_metadata_message_2eproto, - file_level_enum_descriptors_message_2eproto, - file_level_service_descriptors_message_2eproto, + &::messages::header::_Message_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_message_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\rmessage.proto\022\017messages.header\032\031google" + "/protobuf/any.proto\"v\n\007Message\022\r\n\005topic\030" + "\001 \001(\r\022\017\n\007msgType\030\002 \001(\005\022\022\n\nsourceType\030\003 \001" + "(\005\022\020\n\010sourceID\030\004 \001(\005\022%\n\007payload\030\005 \003(\0132\024." + "google.protobuf.Anyb\006proto3" + ; +static const ::_pbi::DescriptorTable* const descriptor_table_message_2eproto_deps[1] = { + &::descriptor_table_google_2fprotobuf_2fany_2eproto, +}; +static ::_pbi::once_flag descriptor_table_message_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_message_2eproto = { + false, false, 187, descriptor_table_protodef_message_2eproto, + "message.proto", + &descriptor_table_message_2eproto_once, descriptor_table_message_2eproto_deps, 1, 1, + schemas, file_default_instances, TableStruct_message_2eproto::offsets, + file_level_metadata_message_2eproto, file_level_enum_descriptors_message_2eproto, + file_level_service_descriptors_message_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_message_2eproto_getter() { return &descriptor_table_message_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_message_2eproto(&descriptor_table_message_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_message_2eproto(&descriptor_table_message_2eproto); namespace messages { namespace header { + // =================================================================== class Message::_Internal { @@ -198,7 +173,6 @@ void Message::Clear() { } const char* Message::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -274,7 +248,6 @@ failure: uint8_t* Message::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:messages.header.Message) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -320,7 +293,6 @@ uint8_t* Message::_InternalSerialize( } size_t Message::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:messages.header.Message) size_t total_size = 0; @@ -368,7 +340,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Message::GetClassData() const void Message::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:messages.header.Message) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -414,11 +385,11 @@ void Message::InternalSwap(Message* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Message::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_message_2eproto_getter, &descriptor_table_message_2eproto_once, file_level_metadata_message_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) } // namespace header } // namespace messages @@ -428,5 +399,6 @@ Arena::CreateMaybeMessage< ::messages::header::Message >(Arena* arena) { return Arena::CreateMessageInternal< ::messages::header::Message >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/include/WHISPER/Messages/Protos/message.pb.h b/include/WHISPER/Messages/Protos/message.pb.h index 4f442d9..f3bd045 100644 --- a/include/WHISPER/Messages/Protos/message.pb.h +++ b/include/WHISPER/Messages/Protos/message.pb.h @@ -1,44 +1,39 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: message.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_message_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_message_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_message_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_message_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/any.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_message_2eproto - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -49,8 +44,7 @@ PROTOBUF_NAMESPACE_CLOSE struct TableStruct_message_2eproto { static const uint32_t offsets[]; }; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_message_2eproto; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_message_2eproto; namespace messages { namespace header { class Message; @@ -59,18 +53,13 @@ extern MessageDefaultTypeInternal _Message_default_instance_; } // namespace header } // namespace messages PROTOBUF_NAMESPACE_OPEN -template <> -::messages::header::Message* Arena::CreateMaybeMessage<::messages::header::Message>(Arena*); +template<> ::messages::header::Message* Arena::CreateMaybeMessage<::messages::header::Message>(Arena*); PROTOBUF_NAMESPACE_CLOSE - namespace messages { namespace header { // =================================================================== - -// ------------------------------------------------------------------- - class Message final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:messages.header.Message) */ { public: @@ -174,7 +163,7 @@ class Message final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "messages.header.Message"; } protected: @@ -273,17 +262,12 @@ class Message final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Message // uint32 topic = 1; @@ -298,7 +282,7 @@ inline uint32_t Message::topic() const { return _internal_topic(); } inline void Message::_internal_set_topic(uint32_t value) { - + _impl_.topic_ = value; } inline void Message::set_topic(uint32_t value) { @@ -318,7 +302,7 @@ inline int32_t Message::msgtype() const { return _internal_msgtype(); } inline void Message::_internal_set_msgtype(int32_t value) { - + _impl_.msgtype_ = value; } inline void Message::set_msgtype(int32_t value) { @@ -338,7 +322,7 @@ inline int32_t Message::sourcetype() const { return _internal_sourcetype(); } inline void Message::_internal_set_sourcetype(int32_t value) { - + _impl_.sourcetype_ = value; } inline void Message::set_sourcetype(int32_t value) { @@ -358,7 +342,7 @@ inline int32_t Message::sourceid() const { return _internal_sourceid(); } inline void Message::_internal_set_sourceid(int32_t value) { - + _impl_.sourceid_ = value; } inline void Message::set_sourceid(int32_t value) { @@ -404,16 +388,15 @@ Message::payload() const { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) + } // namespace header } // namespace messages - // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_message_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_message_2eproto diff --git a/include/WHISPER/Messages/Protos/raw_track.pb.cc b/include/WHISPER/Messages/Protos/raw_track.pb.cc index b521ccb..14f9a57 100644 --- a/include/WHISPER/Messages/Protos/raw_track.pb.cc +++ b/include/WHISPER/Messages/Protos/raw_track.pb.cc @@ -4,20 +4,22 @@ #include "raw_track.pb.h" #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + namespace messages { namespace raw_track { PROTOBUF_CONSTEXPR RawTrack::RawTrack( @@ -25,85 +27,59 @@ PROTOBUF_CONSTEXPR RawTrack::RawTrack( /*decltype(_impl_.trackno_)*/0u , /*decltype(_impl_._cached_size_)*/{}} {} struct RawTrackDefaultTypeInternal { - PROTOBUF_CONSTEXPR RawTrackDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR RawTrackDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~RawTrackDefaultTypeInternal() {} union { RawTrack _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 RawTrackDefaultTypeInternal _RawTrack_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 RawTrackDefaultTypeInternal _RawTrack_default_instance_; } // namespace raw_track } // namespace messages static ::_pb::Metadata file_level_metadata_raw_5ftrack_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_raw_5ftrack_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_raw_5ftrack_2eproto = nullptr; -const uint32_t TableStruct_raw_5ftrack_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::messages::raw_track::RawTrack, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::messages::raw_track::RawTrack, _impl_.trackno_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_raw_5ftrack_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_raw_5ftrack_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::messages::raw_track::RawTrack)}, +const uint32_t TableStruct_raw_5ftrack_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::messages::raw_track::RawTrack, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::messages::raw_track::RawTrack, _impl_.trackno_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::messages::raw_track::RawTrack)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::messages::raw_track::_RawTrack_default_instance_._instance, -}; -const char descriptor_table_protodef_raw_5ftrack_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\017raw_track.proto\022\022messages.raw_track\"\033\n" - "\010RawTrack\022\017\n\007trackNo\030\001 \001(\rb\006proto3" -}; -static ::absl::once_flag descriptor_table_raw_5ftrack_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_raw_5ftrack_2eproto = { - false, - false, - 74, - descriptor_table_protodef_raw_5ftrack_2eproto, - "raw_track.proto", - &descriptor_table_raw_5ftrack_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_raw_5ftrack_2eproto::offsets, - file_level_metadata_raw_5ftrack_2eproto, - file_level_enum_descriptors_raw_5ftrack_2eproto, - file_level_service_descriptors_raw_5ftrack_2eproto, + &::messages::raw_track::_RawTrack_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_raw_5ftrack_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\017raw_track.proto\022\022messages.raw_track\"\033\n" + "\010RawTrack\022\017\n\007trackNo\030\001 \001(\rb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_raw_5ftrack_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_raw_5ftrack_2eproto = { + false, false, 74, descriptor_table_protodef_raw_5ftrack_2eproto, + "raw_track.proto", + &descriptor_table_raw_5ftrack_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_raw_5ftrack_2eproto::offsets, + file_level_metadata_raw_5ftrack_2eproto, file_level_enum_descriptors_raw_5ftrack_2eproto, + file_level_service_descriptors_raw_5ftrack_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_raw_5ftrack_2eproto_getter() { return &descriptor_table_raw_5ftrack_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_raw_5ftrack_2eproto(&descriptor_table_raw_5ftrack_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_raw_5ftrack_2eproto(&descriptor_table_raw_5ftrack_2eproto); namespace messages { namespace raw_track { + // =================================================================== class RawTrack::_Internal { @@ -117,9 +93,14 @@ RawTrack::RawTrack(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:messages.raw_track.RawTrack) } RawTrack::RawTrack(const RawTrack& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + RawTrack* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.trackno_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.trackno_ = from._impl_.trackno_; // @@protoc_insertion_point(copy_constructor:messages.raw_track.RawTrack) } @@ -161,7 +142,6 @@ void RawTrack::Clear() { } const char* RawTrack::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -200,7 +180,6 @@ failure: uint8_t* RawTrack::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:messages.raw_track.RawTrack) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -220,7 +199,6 @@ uint8_t* RawTrack::_InternalSerialize( } size_t RawTrack::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:messages.raw_track.RawTrack) size_t total_size = 0; @@ -246,7 +224,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*RawTrack::GetClassData() const void RawTrack::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:messages.raw_track.RawTrack) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -276,11 +253,11 @@ void RawTrack::InternalSwap(RawTrack* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata RawTrack::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_raw_5ftrack_2eproto_getter, &descriptor_table_raw_5ftrack_2eproto_once, file_level_metadata_raw_5ftrack_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) } // namespace raw_track } // namespace messages @@ -290,5 +267,6 @@ Arena::CreateMaybeMessage< ::messages::raw_track::RawTrack >(Arena* arena) { return Arena::CreateMessageInternal< ::messages::raw_track::RawTrack >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/include/WHISPER/Messages/Protos/raw_track.pb.h b/include/WHISPER/Messages/Protos/raw_track.pb.h index 832eb76..5724122 100644 --- a/include/WHISPER/Messages/Protos/raw_track.pb.h +++ b/include/WHISPER/Messages/Protos/raw_track.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: raw_track.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_raw_5ftrack_2eproto - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,8 +43,7 @@ PROTOBUF_NAMESPACE_CLOSE struct TableStruct_raw_5ftrack_2eproto { static const uint32_t offsets[]; }; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_raw_5ftrack_2eproto; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_raw_5ftrack_2eproto; namespace messages { namespace raw_track { class RawTrack; @@ -58,18 +52,13 @@ extern RawTrackDefaultTypeInternal _RawTrack_default_instance_; } // namespace raw_track } // namespace messages PROTOBUF_NAMESPACE_OPEN -template <> -::messages::raw_track::RawTrack* Arena::CreateMaybeMessage<::messages::raw_track::RawTrack>(Arena*); +template<> ::messages::raw_track::RawTrack* Arena::CreateMaybeMessage<::messages::raw_track::RawTrack>(Arena*); PROTOBUF_NAMESPACE_CLOSE - namespace messages { namespace raw_track { // =================================================================== - -// ------------------------------------------------------------------- - class RawTrack final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:messages.raw_track.RawTrack) */ { public: @@ -173,7 +162,7 @@ class RawTrack final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "messages.raw_track.RawTrack"; } protected: @@ -219,17 +208,12 @@ class RawTrack final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // RawTrack // uint32 trackNo = 1; @@ -244,7 +228,7 @@ inline uint32_t RawTrack::trackno() const { return _internal_trackno(); } inline void RawTrack::_internal_set_trackno(uint32_t value) { - + _impl_.trackno_ = value; } inline void RawTrack::set_trackno(uint32_t value) { @@ -253,16 +237,15 @@ inline void RawTrack::set_trackno(uint32_t value) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) + } // namespace raw_track } // namespace messages - // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_raw_5ftrack_2eproto diff --git a/libs/protobuf/.bazelignore b/libs/protobuf/.bazelignore index dc5c301..5c3a81c 100644 --- a/libs/protobuf/.bazelignore +++ b/libs/protobuf/.bazelignore @@ -1,4 +1,4 @@ # These are fetched as external repositories. -third_party/abseil-cpp +third_party/benchmark third_party/googletest _build/ diff --git a/libs/protobuf/.bazelrc b/libs/protobuf/.bazelrc deleted file mode 100644 index de30d6b..0000000 --- a/libs/protobuf/.bazelrc +++ /dev/null @@ -1,35 +0,0 @@ -build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 - -build:dbg --compilation_mode=dbg - -build:opt --compilation_mode=opt - -build:san-common --config=dbg --strip=never --copt=-O0 --copt=-fno-omit-frame-pointer - -build:asan --config=san-common --copt=-fsanitize=address --linkopt=-fsanitize=address -build:asan --copt=-DADDRESS_SANITIZER=1 -# ASAN hits ODR violations with shared linkage due to rules_proto. -build:asan --dynamic_mode=off - -build:msan --config=san-common --copt=-fsanitize=memory --linkopt=-fsanitize=memory -build:msan --copt=-fsanitize-memory-track-origins -build:msan --copt=-fsanitize-memory-use-after-dtor -build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1 -build:msan --copt=-DMEMORY_SANITIZER=1 - -# Use our instrumented LLVM libc++ in Kokoro. -build:kokoro-msan --config=msan -build:kokoro-msan --linkopt=-L/opt/libcxx_msan/lib -build:kokoro-msan --linkopt=-Wl,-rpath,/opt/libcxx_msan/lib -build:kokoro-msan --cxxopt=-stdlib=libc++ --linkopt=-stdlib=libc++ - - -build:tsan --config=san-common --copt=-fsanitize=thread --linkopt=-fsanitize=thread -build:tsan --copt=-DTHREAD_SANITIZER=1 - -build:ubsan --config=san-common --copt=-fsanitize=undefined --linkopt=-fsanitize=undefined -build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 -build:ubsan --copt=-DUNDEFINED_SANITIZER=1 -# Workaround for the fact that Bazel links with $CC, not $CXX -# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748 -build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr diff --git a/libs/protobuf/.github/ISSUE_TEMPLATE/bug_report.md b/libs/protobuf/.github/ISSUE_TEMPLATE/bug_report.md index 88bc074..f9411a6 100644 --- a/libs/protobuf/.github/ISSUE_TEMPLATE/bug_report.md +++ b/libs/protobuf/.github/ISSUE_TEMPLATE/bug_report.md @@ -2,7 +2,7 @@ name: Bug report about: Create a report to help us improve title: '' -labels: 'untriaged' +labels: '' assignees: '' --- @@ -16,7 +16,7 @@ Stack Overflow is also a useful if unofficial resource https://stackoverflow.com --> **What version of protobuf and what language are you using?** -Version: main/v3.6.0/v3.5.0 etc. (NOTE: please try updating to the latest version of protoc/runtime possible beforehand to attempt to resolve your problem) +Version: main/v3.6.0/v3.5.0 etc. Language: C++/Java/Python/C#/Ruby/PHP/Objective-C/Javascript **What operating system (Linux, Windows, ...) and version?** diff --git a/libs/protobuf/.github/ISSUE_TEMPLATE/feature_request.md b/libs/protobuf/.github/ISSUE_TEMPLATE/feature_request.md index ada9ed7..28b9bc9 100644 --- a/libs/protobuf/.github/ISSUE_TEMPLATE/feature_request.md +++ b/libs/protobuf/.github/ISSUE_TEMPLATE/feature_request.md @@ -2,7 +2,7 @@ name: Feature request about: Suggest an idea for this project title: '' -labels: 'untriaged' +labels: '' assignees: '' --- diff --git a/libs/protobuf/.github/workflows/codespell.yml b/libs/protobuf/.github/workflows/codespell.yml index b32c0a2..887c8a2 100644 --- a/libs/protobuf/.github/workflows/codespell.yml +++ b/libs/protobuf/.github/workflows/codespell.yml @@ -13,4 +13,4 @@ jobs: with: check_filenames: true skip: ./.git,./conformance/third_party,*.snk,*.pb,*.pb.cc,*.pb.h,./src/google/protobuf/testdata,./objectivec/Tests,./python/compatibility_tests/v2.5.0/tests/google/protobuf/internal,./.github/workflows/codespell.yml - ignore_words_list: "alow,alse,ba,chec,cleare,copyable,cloneable,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur,falsy" + ignore_words_list: "alow,alse,ba,cleare,copyable,cloneable,dedup,dur,errorprone,falsy,files',fo,fundementals,hel,importd,inout,leapyear,nd,nin,ois,ons,parseable,process',ro,te,testof,ue,unparseable,wasn,wee,gae,keyserver,objext,od,optin,streem,sur" diff --git a/libs/protobuf/.github/workflows/generated_cmake.yml b/libs/protobuf/.github/workflows/generated_cmake.yml deleted file mode 100644 index 640bd13..0000000 --- a/libs/protobuf/.github/workflows/generated_cmake.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Generate CMake File Lists - -on: - push: - branches: - - main - - '[0-9]+.x' - # The 21.x branch predates support for auto-generation of the CMake file - # lists, so we make sure to exclude it. - - '!21.x' - -jobs: - cmake: - if: github.repository == 'protocolbuffers/protobuf' - runs-on: ubuntu-latest - - strategy: - fail-fast: false # Don't cancel all jobs if one fails. - - steps: - - uses: actions/checkout@v3 - with: - # Note: this token has an expiration date, so if the workflow starts - # failing then you may need to generate a fresh token. - token: ${{ secrets.BOT_ACCESS_TOKEN }} - - name: Configure name and email address in Git - run: cd ${{ github.workspace }} && git config user.name "Protobuf Team Bot" && git config user.email "protobuf-team-bot@google.com" - - name: Commit and push update - run: cd ${{ github.workspace }} && ./cmake/push_auto_update.sh diff --git a/libs/protobuf/.github/workflows/objc_cocoapods.yml b/libs/protobuf/.github/workflows/objc_cocoapods.yml index dd330a8..d828ae3 100644 --- a/libs/protobuf/.github/workflows/objc_cocoapods.yml +++ b/libs/protobuf/.github/workflows/objc_cocoapods.yml @@ -24,7 +24,8 @@ jobs: strategy: fail-fast: false matrix: - PLATFORM: ["ios", "macos", "tvos", "watchos"] + # Add back 'watchos'. See CocoaPods/CocoaPods#11558 + PLATFORM: ["ios", "macos", "tvos"] CONFIGURATION: ["Debug", "Release"] steps: - uses: actions/checkout@v2 diff --git a/libs/protobuf/.github/workflows/php-ext.yml b/libs/protobuf/.github/workflows/php-ext.yml index f24f6bf..4d3af3e 100644 --- a/libs/protobuf/.github/workflows/php-ext.yml +++ b/libs/protobuf/.github/workflows/php-ext.yml @@ -15,6 +15,16 @@ jobs: - php:7.4-cli - php:8.1-cli steps: + - name: Install python3 + run: | + apt-get update -q + apt-get install -qy python3 + - name: Install bazel + run: | + apt-get install -qy wget + mkdir $HOME/bin + wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/5.3.2/bazel-5.3.2-linux-x86_64 + chmod a+x $HOME/bin/bazel - name: Install git run: | apt-get update -q @@ -23,20 +33,15 @@ jobs: uses: actions/checkout@v3 with: submodules: recursive - - name: Prepare source code - run: | - rm -rf "$GITHUB_WORKSPACE/php/ext/google/protobuf/third_party" - cp -r "$GITHUB_WORKSPACE/third_party" "$GITHUB_WORKSPACE/php/ext/google/protobuf" - cp "$GITHUB_WORKSPACE/LICENSE" "$GITHUB_WORKSPACE/php/ext/google/protobuf" - name: Create package run: | - cd /tmp - rm -rf protobuf-*.tgz - pecl package "$GITHUB_WORKSPACE/php/ext/google/protobuf/package.xml" + cd $GITHUB_WORKSPACE + rm -rf bazel-bin/php/protobuf-*.tgz + $HOME/bin/bazel build php:release - name: Compile extension run: | cd /tmp - MAKE="make -j$(nproc)" pecl install protobuf-*.tgz + MAKE="make -j$(nproc)" pecl install $GITHUB_WORKSPACE/bazel-bin/php/protobuf-*.tgz - name: Enable extension run: docker-php-ext-enable protobuf - name: Inspect extension diff --git a/libs/protobuf/.gitignore b/libs/protobuf/.gitignore index ea95cc9..62de6f1 100644 --- a/libs/protobuf/.gitignore +++ b/libs/protobuf/.gitignore @@ -1,24 +1,29 @@ -# CMake-generated files -.ninja_deps -.ninja_logs -cmake/protobuf/*.cmake -cmake_install.cmake -CMakeCache.txt -CTestTestfile.cmake -CMakeFiles/* -Testing/Temporary/* +# autogen.sh-generated files +Makefile.in +src/Makefile.in +config.guess +config.h.in +config.sub +configure +depcomp +install-sh +ltmain.sh +missing -/core -/protoc -/test_plugin -/tests -/lite-test -/protoc-*.* +aclocal.m4 +m4/libtool.m4 +m4/ltoptions.m4 +m4/ltsugar.m4 +m4/ltversion.m4 +m4/lt~obsolete.m4 +autom4te.cache # downloaded files /gmock # in-tree configure-generated files +Makefile +src/Makefile /config.h config.log config.status @@ -33,8 +38,8 @@ stamp-h1 *.o *.lo *.la +src/.libs *.so -*.a .dirstamp @@ -55,6 +60,8 @@ python/build/ python/docs/_build/ src/js_embed +src/protoc +src/unittest_proto_middleman # vim generated *.swp diff --git a/libs/protobuf/.gitmodules b/libs/protobuf/.gitmodules index db938cf..bcd125a 100644 --- a/libs/protobuf/.gitmodules +++ b/libs/protobuf/.gitmodules @@ -1,14 +1,7 @@ +[submodule "third_party/benchmark"] + path = third_party/benchmark + url = https://github.com/google/benchmark.git [submodule "third_party/googletest"] path = third_party/googletest url = https://github.com/google/googletest.git ignore = dirty -[submodule "third_party/abseil-cpp"] - path = third_party/abseil-cpp - url = https://github.com/abseil/abseil-cpp.git - branch = lts_2022_06_23 -[submodule "third_party/jsoncpp"] - path = third_party/jsoncpp - url = https://github.com/open-source-parsers/jsoncpp.git -[submodule "third_party/utf8_range"] - path = third_party/utf8_range - url = https://github.com/protocolbuffers/utf8_range.git diff --git a/libs/protobuf/BUILD.bazel b/libs/protobuf/BUILD.bazel index b980d99..0f6e41e 100644 --- a/libs/protobuf/BUILD.bazel +++ b/libs/protobuf/BUILD.bazel @@ -1,16 +1,251 @@ # Bazel (https://bazel.build/) BUILD file for Protobuf. -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") -load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library") +load("@rules_python//python:defs.bzl", "py_library") +load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library") load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS") -load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library") +load( + ":protobuf.bzl", + "adapt_proto_library", + "cc_proto_library", + "internal_copied_filegroup", + "internal_protobuf_py_tests", + "py_proto_library", +) licenses(["notice"]) exports_files(["LICENSE"]) +################################################################################ +# Protobuf Runtime Library +################################################################################ + +cc_library( + name = "protobuf_lite", + srcs = [ + # AUTOGEN(protobuf_lite_srcs) + "src/google/protobuf/any_lite.cc", + "src/google/protobuf/arena.cc", + "src/google/protobuf/arenastring.cc", + "src/google/protobuf/arenaz_sampler.cc", + "src/google/protobuf/extension_set.cc", + "src/google/protobuf/generated_enum_util.cc", + "src/google/protobuf/generated_message_tctable_lite.cc", + "src/google/protobuf/generated_message_util.cc", + "src/google/protobuf/implicit_weak_message.cc", + "src/google/protobuf/inlined_string_field.cc", + "src/google/protobuf/io/coded_stream.cc", + "src/google/protobuf/io/io_win32.cc", + "src/google/protobuf/io/strtod.cc", + "src/google/protobuf/io/zero_copy_stream.cc", + "src/google/protobuf/io/zero_copy_stream_impl.cc", + "src/google/protobuf/io/zero_copy_stream_impl_lite.cc", + "src/google/protobuf/map.cc", + "src/google/protobuf/message_lite.cc", + "src/google/protobuf/parse_context.cc", + "src/google/protobuf/repeated_field.cc", + "src/google/protobuf/repeated_ptr_field.cc", + "src/google/protobuf/stubs/bytestream.cc", + "src/google/protobuf/stubs/common.cc", + "src/google/protobuf/stubs/int128.cc", + "src/google/protobuf/stubs/status.cc", + "src/google/protobuf/stubs/statusor.cc", + "src/google/protobuf/stubs/stringpiece.cc", + "src/google/protobuf/stubs/stringprintf.cc", + "src/google/protobuf/stubs/structurally_valid.cc", + "src/google/protobuf/stubs/strutil.cc", + "src/google/protobuf/stubs/time.cc", + "src/google/protobuf/wire_format_lite.cc", + ], + hdrs = glob([ + "src/google/protobuf/**/*.h", + "src/google/protobuf/**/*.inc", + ]), + copts = COPTS, + includes = ["src/"], + linkopts = LINK_OPTS, + visibility = ["//visibility:public"], +) + +cc_library( + name = "protobuf", + srcs = [ + # AUTOGEN(protobuf_srcs) + "src/google/protobuf/any.cc", + "src/google/protobuf/any.pb.cc", + "src/google/protobuf/api.pb.cc", + "src/google/protobuf/compiler/importer.cc", + "src/google/protobuf/compiler/parser.cc", + "src/google/protobuf/descriptor.cc", + "src/google/protobuf/descriptor.pb.cc", + "src/google/protobuf/descriptor_database.cc", + "src/google/protobuf/duration.pb.cc", + "src/google/protobuf/dynamic_message.cc", + "src/google/protobuf/empty.pb.cc", + "src/google/protobuf/extension_set_heavy.cc", + "src/google/protobuf/field_mask.pb.cc", + "src/google/protobuf/generated_message_bases.cc", + "src/google/protobuf/generated_message_reflection.cc", + "src/google/protobuf/generated_message_tctable_full.cc", + "src/google/protobuf/io/gzip_stream.cc", + "src/google/protobuf/io/printer.cc", + "src/google/protobuf/io/tokenizer.cc", + "src/google/protobuf/map_field.cc", + "src/google/protobuf/message.cc", + "src/google/protobuf/reflection_ops.cc", + "src/google/protobuf/service.cc", + "src/google/protobuf/source_context.pb.cc", + "src/google/protobuf/struct.pb.cc", + "src/google/protobuf/stubs/substitute.cc", + "src/google/protobuf/text_format.cc", + "src/google/protobuf/timestamp.pb.cc", + "src/google/protobuf/type.pb.cc", + "src/google/protobuf/unknown_field_set.cc", + "src/google/protobuf/util/delimited_message_util.cc", + "src/google/protobuf/util/field_comparator.cc", + "src/google/protobuf/util/field_mask_util.cc", + "src/google/protobuf/util/internal/datapiece.cc", + "src/google/protobuf/util/internal/default_value_objectwriter.cc", + "src/google/protobuf/util/internal/error_listener.cc", + "src/google/protobuf/util/internal/field_mask_utility.cc", + "src/google/protobuf/util/internal/json_escaping.cc", + "src/google/protobuf/util/internal/json_objectwriter.cc", + "src/google/protobuf/util/internal/json_stream_parser.cc", + "src/google/protobuf/util/internal/object_writer.cc", + "src/google/protobuf/util/internal/proto_writer.cc", + "src/google/protobuf/util/internal/protostream_objectsource.cc", + "src/google/protobuf/util/internal/protostream_objectwriter.cc", + "src/google/protobuf/util/internal/type_info.cc", + "src/google/protobuf/util/internal/utility.cc", + "src/google/protobuf/util/json_util.cc", + "src/google/protobuf/util/message_differencer.cc", + "src/google/protobuf/util/time_util.cc", + "src/google/protobuf/util/type_resolver_util.cc", + "src/google/protobuf/wire_format.cc", + "src/google/protobuf/wrappers.pb.cc", + ], + hdrs = glob([ + "src/**/*.h", + "src/**/*.inc", + ]), + copts = COPTS, + includes = ["src/"], + linkopts = LINK_OPTS, + visibility = ["//visibility:public"], + deps = [":protobuf_lite"] + select({ + "//build_defs:config_msvc": [], + "//conditions:default": ["@zlib//:zlib"], + }), +) + +# This provides just the header files for use in projects that need to build +# shared libraries for dynamic loading. This target is available until Bazel +# adds native support for such use cases. +# TODO(keveman): Remove this target once the support gets added to Bazel. +cc_library( + name = "protobuf_headers", + hdrs = glob([ + "src/**/*.h", + "src/**/*.inc", + ]), + includes = ["src/"], + visibility = ["//visibility:public"], +) + +# DEPRECATED: Prefer :well_known_type_protos for the Well-Known Types +# (https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) +# or :descriptor_proto(_srcs) for descriptor.proto (source), or +# :compiler_plugin_proto for compiler/plugin.proto. +filegroup( + name = "well_known_protos", + srcs = [ + "src/google/protobuf/compiler/plugin.proto", + "src/google/protobuf/descriptor.proto", + ":well_known_type_protos", + ], + deprecation = "Prefer :well_known_type_protos instead.", + visibility = ["//visibility:public"], +) + +filegroup( + name = "well_known_type_protos", + srcs = [ + "src/google/protobuf/any.proto", + "src/google/protobuf/api.proto", + "src/google/protobuf/duration.proto", + "src/google/protobuf/empty.proto", + "src/google/protobuf/field_mask.proto", + "src/google/protobuf/source_context.proto", + "src/google/protobuf/struct.proto", + "src/google/protobuf/timestamp.proto", + "src/google/protobuf/type.proto", + "src/google/protobuf/wrappers.proto", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "built_in_runtime_protos", + srcs = [ + "src/google/protobuf/compiler/plugin.proto", + "src/google/protobuf/descriptor.proto", + ], + visibility = ["//:__subpackages__"], +) + +exports_files( + srcs = [ + "src/google/protobuf/any.proto", + "src/google/protobuf/api.proto", + "src/google/protobuf/compiler/plugin.proto", + "src/google/protobuf/descriptor.proto", + "src/google/protobuf/duration.proto", + "src/google/protobuf/empty.proto", + "src/google/protobuf/field_mask.proto", + "src/google/protobuf/source_context.proto", + "src/google/protobuf/struct.proto", + "src/google/protobuf/timestamp.proto", + "src/google/protobuf/type.proto", + "src/google/protobuf/wrappers.proto", + ], + visibility = ["//pkg:__pkg__"], +) + +alias( + name = "lite_well_known_protos", + actual = ":well_known_type_protos", + visibility = ["//visibility:public"], +) + +adapt_proto_library( + name = "cc_wkt_protos_genproto", + visibility = ["//visibility:public"], + deps = [ + "//:any_proto", + "//:api_proto", + "//:compiler_plugin_proto", + "//:descriptor_proto", + "//:duration_proto", + "//:empty_proto", + "//:field_mask_proto", + "//:source_context_proto", + "//:struct_proto", + "//:timestamp_proto", + "//:type_proto", + "//:wrappers_proto", + ], +) + +cc_library( + name = "cc_wkt_protos", + deprecation = "Only for backward compatibility. Do not use.", + visibility = ["//visibility:public"], +) + ################################################################################ # Well Known Types Proto Library Rules # @@ -21,206 +256,507 @@ exports_files(["LICENSE"]) # # java_proto_library( # name = "any_java_proto", -# deps = ["@com_google_protobuf//:any_proto"], +# deps = ["@com_google_protobuf//:any_proto], # ) ################################################################################ -alias( +proto_library( name = "any_proto", - actual = "//src/google/protobuf:any_proto", + srcs = ["src/google/protobuf/any.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "api_proto", - actual = "//src/google/protobuf:api_proto", + srcs = ["src/google/protobuf/api.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], + deps = [ + "//:source_context_proto", + "//:type_proto", + ], ) -alias( +proto_library( name = "duration_proto", - actual = "//src/google/protobuf:duration_proto", + srcs = ["//:src/google/protobuf/duration.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "empty_proto", - actual = "//src/google/protobuf:empty_proto", + srcs = ["src/google/protobuf/empty.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "field_mask_proto", - actual = "//src/google/protobuf:field_mask_proto", + srcs = ["src/google/protobuf/field_mask.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "source_context_proto", - actual = "//src/google/protobuf:source_context_proto", + srcs = ["src/google/protobuf/source_context.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "struct_proto", - actual = "//src/google/protobuf:struct_proto", + srcs = ["src/google/protobuf/struct.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "timestamp_proto", - actual = "//src/google/protobuf:timestamp_proto", + srcs = ["src/google/protobuf/timestamp.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -alias( +proto_library( name = "type_proto", - actual = "//src/google/protobuf:type_proto", + srcs = ["src/google/protobuf/type.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], + deps = [ + "//:any_proto", + "//:source_context_proto", + ], ) -alias( +proto_library( name = "wrappers_proto", - actual = "//src/google/protobuf:wrappers_proto", + srcs = ["src/google/protobuf/wrappers.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -# Source files: these are aliases to a filegroup, not a `proto_library`. -# -# (This is _probably_ not what you want.) -alias( - name = "lite_well_known_protos", - actual = "//src/google/protobuf:well_known_type_protos", # filegroup - visibility = ["//visibility:public"], -) +# Built-in runtime types -alias( - name = "well_known_type_protos", - actual = "//src/google/protobuf:well_known_type_protos", # filegroup - visibility = ["//visibility:public"], -) - -# Built-in runtime protos: these are part of protobuf's internal -# implementation, but are not Well-Known Types. - -alias( - name = "descriptor_proto", - actual = "//src/google/protobuf:descriptor_proto", # proto_library - visibility = ["//visibility:public"], -) - -alias( - name = "descriptor_proto_srcs", - actual = "//src/google/protobuf:descriptor_proto_srcs", # filegroup - visibility = ["//visibility:public"], -) - -alias( +proto_library( name = "compiler_plugin_proto", - actual = "//src/google/protobuf/compiler:plugin_proto", # proto_library + srcs = ["src/google/protobuf/compiler/plugin.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], + deps = ["//:descriptor_proto"], ) -cc_library( - name = "cc_wkt_protos", - deprecation = "Only for backward compatibility. Do not use.", +proto_library( + name = "descriptor_proto", + srcs = ["src/google/protobuf/descriptor.proto"], + strip_import_prefix = "src", visibility = ["//visibility:public"], ) -# Source protos that are typically part of the protobuf runtime. -# -# DEPRECATED: Prefer :well_known_type_protos for the Well-Known Types -# (https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) -# or :descriptor_proto(_srcs) for descriptor.proto (source), or -# :compiler_plugin_proto for compiler/plugin.proto. -filegroup( - name = "well_known_protos", - srcs = [ - ":descriptor_proto_srcs", - ":well_known_type_protos", - "//src/google/protobuf/compiler:plugin.proto", - ], - deprecation = "Prefer :well_known_type_protos instead.", - visibility = ["//visibility:public"], -) - -internal_ruby_proto_library( - name = "well_known_ruby_protos", - srcs = [":well_known_protos"], - includes = ["src"], - visibility = [ - "//conformance:__pkg__", - "//ruby:__subpackages__", - ], -) - ################################################################################ # Protocol Buffers Compiler ################################################################################ -cc_binary( - name = "protoc", - copts = COPTS, - linkopts = LINK_OPTS + PROTOC_LINK_OPTS, - visibility = ["//visibility:public"], - deps = ["//src/google/protobuf/compiler:protoc_lib"], -) - -################################################################################ -# C++ runtime -################################################################################ - -# The "lite" runtime works for .proto files that specify the option: -# optimize_for = LITE_RUNTIME; -# -# The lite runtime does not include the `Reflection` APIs (including -# `Descriptor` and related types) or Well-Known Types. -# -# See also: -# https://developers.google.com/protocol-buffers/docs/reference/cpp-generated#message -# https://developers.google.com/protocol-buffers/docs/reference/google.protobuf -alias( - name = "protobuf_lite", - actual = "//src/google/protobuf:protobuf_lite", - visibility = ["//visibility:public"], -) - cc_library( - name = "protobuf", - hdrs = glob([ - "src/**/*.h", - "src/**/*.inc", - ]), + name = "protoc_lib", + srcs = [ + # AUTOGEN(protoc_lib_srcs) + "src/google/protobuf/compiler/code_generator.cc", + "src/google/protobuf/compiler/command_line_interface.cc", + "src/google/protobuf/compiler/cpp/enum.cc", + "src/google/protobuf/compiler/cpp/enum_field.cc", + "src/google/protobuf/compiler/cpp/extension.cc", + "src/google/protobuf/compiler/cpp/field.cc", + "src/google/protobuf/compiler/cpp/file.cc", + "src/google/protobuf/compiler/cpp/generator.cc", + "src/google/protobuf/compiler/cpp/helpers.cc", + "src/google/protobuf/compiler/cpp/map_field.cc", + "src/google/protobuf/compiler/cpp/message.cc", + "src/google/protobuf/compiler/cpp/message_field.cc", + "src/google/protobuf/compiler/cpp/padding_optimizer.cc", + "src/google/protobuf/compiler/cpp/parse_function_generator.cc", + "src/google/protobuf/compiler/cpp/primitive_field.cc", + "src/google/protobuf/compiler/cpp/service.cc", + "src/google/protobuf/compiler/cpp/string_field.cc", + "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc", + "src/google/protobuf/compiler/csharp/csharp_enum.cc", + "src/google/protobuf/compiler/csharp/csharp_enum_field.cc", + "src/google/protobuf/compiler/csharp/csharp_field_base.cc", + "src/google/protobuf/compiler/csharp/csharp_generator.cc", + "src/google/protobuf/compiler/csharp/csharp_helpers.cc", + "src/google/protobuf/compiler/csharp/csharp_map_field.cc", + "src/google/protobuf/compiler/csharp/csharp_message.cc", + "src/google/protobuf/compiler/csharp/csharp_message_field.cc", + "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc", + "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc", + "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc", + "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc", + "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc", + "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc", + "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc", + "src/google/protobuf/compiler/java/context.cc", + "src/google/protobuf/compiler/java/doc_comment.cc", + "src/google/protobuf/compiler/java/enum.cc", + "src/google/protobuf/compiler/java/enum_field.cc", + "src/google/protobuf/compiler/java/enum_field_lite.cc", + "src/google/protobuf/compiler/java/enum_lite.cc", + "src/google/protobuf/compiler/java/extension.cc", + "src/google/protobuf/compiler/java/extension_lite.cc", + "src/google/protobuf/compiler/java/field.cc", + "src/google/protobuf/compiler/java/file.cc", + "src/google/protobuf/compiler/java/generator.cc", + "src/google/protobuf/compiler/java/generator_factory.cc", + "src/google/protobuf/compiler/java/helpers.cc", + "src/google/protobuf/compiler/java/kotlin_generator.cc", + "src/google/protobuf/compiler/java/map_field.cc", + "src/google/protobuf/compiler/java/map_field_lite.cc", + "src/google/protobuf/compiler/java/message.cc", + "src/google/protobuf/compiler/java/message_builder.cc", + "src/google/protobuf/compiler/java/message_builder_lite.cc", + "src/google/protobuf/compiler/java/message_field.cc", + "src/google/protobuf/compiler/java/message_field_lite.cc", + "src/google/protobuf/compiler/java/message_lite.cc", + "src/google/protobuf/compiler/java/name_resolver.cc", + "src/google/protobuf/compiler/java/primitive_field.cc", + "src/google/protobuf/compiler/java/primitive_field_lite.cc", + "src/google/protobuf/compiler/java/service.cc", + "src/google/protobuf/compiler/java/shared_code_generator.cc", + "src/google/protobuf/compiler/java/string_field.cc", + "src/google/protobuf/compiler/java/string_field_lite.cc", + "src/google/protobuf/compiler/objectivec/objectivec_enum.cc", + "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc", + "src/google/protobuf/compiler/objectivec/objectivec_extension.cc", + "src/google/protobuf/compiler/objectivec/objectivec_field.cc", + "src/google/protobuf/compiler/objectivec/objectivec_file.cc", + "src/google/protobuf/compiler/objectivec/objectivec_generator.cc", + "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc", + "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc", + "src/google/protobuf/compiler/objectivec/objectivec_message.cc", + "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc", + "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc", + "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc", + "src/google/protobuf/compiler/php/php_generator.cc", + "src/google/protobuf/compiler/plugin.cc", + "src/google/protobuf/compiler/plugin.pb.cc", + "src/google/protobuf/compiler/python/generator.cc", + "src/google/protobuf/compiler/python/helpers.cc", + "src/google/protobuf/compiler/python/pyi_generator.cc", + "src/google/protobuf/compiler/ruby/ruby_generator.cc", + "src/google/protobuf/compiler/subprocess.cc", + "src/google/protobuf/compiler/zip_writer.cc", + ], copts = COPTS, - include_prefix = "google/protobuf/io", + includes = ["src/"], linkopts = LINK_OPTS, visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/util:delimited_message_util", - "//src/google/protobuf/util:differencer", - "//src/google/protobuf/util:field_mask_util", - "//src/google/protobuf/util:json_util", - "//src/google/protobuf/util:time_util", - "//src/google/protobuf/util:type_resolver_util", + deps = [":protobuf"], +) + +cc_binary( + name = "protoc", + srcs = ["src/google/protobuf/compiler/main.cc"], + linkopts = LINK_OPTS + PROTOC_LINK_OPTS, + visibility = ["//visibility:public"], + deps = [":protoc_lib"], +) + +################################################################################ +# Tests +################################################################################ + +filegroup( + name = "testdata", + srcs = glob(["src/google/protobuf/testdata/**/*"]), + visibility = [ + "//:__subpackages__", + "@upb//:__subpackages__", ], ) -# This provides just the header files for use in projects that need to build -# shared libraries for dynamic loading. This target is available until Bazel -# adds native support for such use cases. -# TODO(keveman): Remove this target once the support gets added to Bazel. -alias( - name = "protobuf_headers", - actual = "//src/google/protobuf:protobuf_headers", - visibility = ["//visibility:public"], +RELATIVE_LITE_TEST_PROTOS = [ + # AUTOGEN(lite_test_protos) + "google/protobuf/map_lite_unittest.proto", + "google/protobuf/unittest_import_lite.proto", + "google/protobuf/unittest_import_public_lite.proto", + "google/protobuf/unittest_lite.proto", +] + +LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS] + +RELATIVE_TEST_PROTOS = [ + # AUTOGEN(test_protos) + "google/protobuf/any_test.proto", + "google/protobuf/compiler/cpp/test_bad_identifiers.proto", + "google/protobuf/compiler/cpp/test_large_enum_value.proto", + "google/protobuf/map_proto2_unittest.proto", + "google/protobuf/map_unittest.proto", + "google/protobuf/unittest.proto", + "google/protobuf/unittest_arena.proto", + "google/protobuf/unittest_custom_options.proto", + "google/protobuf/unittest_drop_unknown_fields.proto", + "google/protobuf/unittest_embed_optimize_for.proto", + "google/protobuf/unittest_empty.proto", + "google/protobuf/unittest_enormous_descriptor.proto", + "google/protobuf/unittest_import.proto", + "google/protobuf/unittest_import_public.proto", + "google/protobuf/unittest_lazy_dependencies.proto", + "google/protobuf/unittest_lazy_dependencies_custom_option.proto", + "google/protobuf/unittest_lazy_dependencies_enum.proto", + "google/protobuf/unittest_lite_imports_nonlite.proto", + "google/protobuf/unittest_mset.proto", + "google/protobuf/unittest_mset_wire_format.proto", + "google/protobuf/unittest_no_field_presence.proto", + "google/protobuf/unittest_no_generic_services.proto", + "google/protobuf/unittest_optimize_for.proto", + "google/protobuf/unittest_preserve_unknown_enum.proto", + "google/protobuf/unittest_preserve_unknown_enum2.proto", + "google/protobuf/unittest_proto3.proto", + "google/protobuf/unittest_proto3_arena.proto", + "google/protobuf/unittest_proto3_arena_lite.proto", + "google/protobuf/unittest_proto3_lite.proto", + "google/protobuf/unittest_proto3_optional.proto", + "google/protobuf/unittest_well_known_types.proto", + "google/protobuf/util/internal/testdata/anys.proto", + "google/protobuf/util/internal/testdata/books.proto", + "google/protobuf/util/internal/testdata/default_value.proto", + "google/protobuf/util/internal/testdata/default_value_test.proto", + "google/protobuf/util/internal/testdata/field_mask.proto", + "google/protobuf/util/internal/testdata/maps.proto", + "google/protobuf/util/internal/testdata/oneofs.proto", + "google/protobuf/util/internal/testdata/proto3.proto", + "google/protobuf/util/internal/testdata/struct.proto", + "google/protobuf/util/internal/testdata/timestamp_duration.proto", + "google/protobuf/util/internal/testdata/wrappers.proto", + "google/protobuf/util/json_format.proto", + "google/protobuf/util/json_format_proto3.proto", + "google/protobuf/util/message_differencer_unittest.proto", +] + +TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS] + +GENERIC_RELATIVE_TEST_PROTOS = [ + "google/protobuf/map_proto2_unittest.proto", + "google/protobuf/map_unittest.proto", + "google/protobuf/unittest.proto", + "google/protobuf/unittest_arena.proto", + "google/protobuf/unittest_custom_options.proto", + "google/protobuf/unittest_drop_unknown_fields.proto", + "google/protobuf/unittest_embed_optimize_for.proto", + "google/protobuf/unittest_empty.proto", + "google/protobuf/unittest_enormous_descriptor.proto", + "google/protobuf/unittest_import.proto", + "google/protobuf/unittest_import_public.proto", + "google/protobuf/unittest_lazy_dependencies.proto", + "google/protobuf/unittest_lazy_dependencies_custom_option.proto", + "google/protobuf/unittest_lazy_dependencies_enum.proto", + "google/protobuf/unittest_lite_imports_nonlite.proto", + "google/protobuf/unittest_mset.proto", + "google/protobuf/unittest_mset_wire_format.proto", + "google/protobuf/unittest_no_field_presence.proto", + "google/protobuf/unittest_no_generic_services.proto", + "google/protobuf/unittest_optimize_for.proto", + "google/protobuf/unittest_preserve_unknown_enum.proto", + "google/protobuf/unittest_preserve_unknown_enum2.proto", + "google/protobuf/unittest_proto3.proto", + "google/protobuf/unittest_proto3_arena.proto", + "google/protobuf/unittest_proto3_arena_lite.proto", + "google/protobuf/unittest_proto3_lite.proto", + "google/protobuf/unittest_proto3_optional.proto", + "google/protobuf/unittest_well_known_types.proto", +] + +GENERIC_TEST_PROTOS = ["src/" + s for s in GENERIC_RELATIVE_TEST_PROTOS] + +proto_library( + name = "generic_test_protos", + srcs = LITE_TEST_PROTOS + GENERIC_TEST_PROTOS, + strip_import_prefix = "src", + visibility = ["//:__subpackages__"], + deps = [ + "//:any_proto", + "//:api_proto", + "//:descriptor_proto", + "//:duration_proto", + "//:empty_proto", + "//:field_mask_proto", + "//:source_context_proto", + "//:struct_proto", + "//:timestamp_proto", + "//:type_proto", + "//:wrappers_proto", + ], ) -alias( - name = "json", - actual = "//src/google/protobuf/json", - visibility = ["//visibility:public"], +cc_proto_library( + name = "cc_test_protos", + srcs = LITE_TEST_PROTOS + TEST_PROTOS, + include = "src", + default_runtime = ":protobuf", + protoc = ":protoc", + deps = [":cc_wkt_protos"], +) + +COMMON_TEST_SRCS = [ + # AUTOGEN(common_test_srcs) + "src/google/protobuf/arena_test_util.cc", + "src/google/protobuf/map_lite_test_util.cc", + "src/google/protobuf/test_util_lite.cc", + "src/google/protobuf/map_test_util.inc", + "src/google/protobuf/reflection_tester.cc", + "src/google/protobuf/test_util.cc", + "src/google/protobuf/test_util.inc", + "src/google/protobuf/testing/file.cc", + "src/google/protobuf/testing/googletest.cc", +] + +cc_binary( + name = "test_plugin", + testonly = True, + srcs = [ + # AUTOGEN(test_plugin_srcs) + "src/google/protobuf/compiler/mock_code_generator.cc", + "src/google/protobuf/compiler/test_plugin.cc", + "src/google/protobuf/testing/file.cc", + ], + deps = [ + ":protobuf", + ":protoc_lib", + "@com_google_googletest//:gtest", + ], +) + +cc_test( + name = "win32_test", + srcs = ["src/google/protobuf/io/io_win32_unittest.cc"], + tags = [ + "manual", + "windows", + ], + deps = [ + ":protobuf_lite", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "protobuf_test", + srcs = COMMON_TEST_SRCS + [ + # AUTOGEN(test_srcs) + "src/google/protobuf/any_test.cc", + "src/google/protobuf/arena_unittest.cc", + "src/google/protobuf/arenastring_unittest.cc", + "src/google/protobuf/arenaz_sampler_test.cc", + "src/google/protobuf/compiler/annotation_test_util.cc", + "src/google/protobuf/compiler/command_line_interface_unittest.cc", + "src/google/protobuf/compiler/cpp/bootstrap_unittest.cc", + "src/google/protobuf/compiler/cpp/metadata_test.cc", + "src/google/protobuf/compiler/cpp/move_unittest.cc", + "src/google/protobuf/compiler/cpp/plugin_unittest.cc", + "src/google/protobuf/compiler/cpp/unittest.cc", + "src/google/protobuf/compiler/cpp/unittest.inc", + "src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc", + "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc", + "src/google/protobuf/compiler/importer_unittest.cc", + "src/google/protobuf/compiler/java/doc_comment_unittest.cc", + "src/google/protobuf/compiler/java/plugin_unittest.cc", + "src/google/protobuf/compiler/mock_code_generator.cc", + "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc", + "src/google/protobuf/compiler/parser_unittest.cc", + "src/google/protobuf/compiler/python/plugin_unittest.cc", + "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc", + "src/google/protobuf/descriptor_database_unittest.cc", + "src/google/protobuf/descriptor_unittest.cc", + "src/google/protobuf/drop_unknown_fields_test.cc", + "src/google/protobuf/dynamic_message_unittest.cc", + "src/google/protobuf/extension_set_unittest.cc", + "src/google/protobuf/generated_message_reflection_unittest.cc", + "src/google/protobuf/generated_message_tctable_lite_test.cc", + "src/google/protobuf/inlined_string_field_unittest.cc", + "src/google/protobuf/io/coded_stream_unittest.cc", + "src/google/protobuf/io/io_win32_unittest.cc", + "src/google/protobuf/io/printer_unittest.cc", + "src/google/protobuf/io/tokenizer_unittest.cc", + "src/google/protobuf/io/zero_copy_stream_unittest.cc", + "src/google/protobuf/map_field_test.cc", + "src/google/protobuf/map_test.cc", + "src/google/protobuf/map_test.inc", + "src/google/protobuf/message_unittest.cc", + "src/google/protobuf/message_unittest.inc", + "src/google/protobuf/no_field_presence_test.cc", + "src/google/protobuf/preserve_unknown_enum_test.cc", + "src/google/protobuf/proto3_arena_lite_unittest.cc", + "src/google/protobuf/proto3_arena_unittest.cc", + "src/google/protobuf/proto3_lite_unittest.cc", + "src/google/protobuf/proto3_lite_unittest.inc", + "src/google/protobuf/reflection_ops_unittest.cc", + "src/google/protobuf/repeated_field_reflection_unittest.cc", + "src/google/protobuf/repeated_field_unittest.cc", + "src/google/protobuf/stubs/bytestream_unittest.cc", + "src/google/protobuf/stubs/common_unittest.cc", + "src/google/protobuf/stubs/int128_unittest.cc", + "src/google/protobuf/stubs/status_test.cc", + "src/google/protobuf/stubs/statusor_test.cc", + "src/google/protobuf/stubs/stringpiece_unittest.cc", + "src/google/protobuf/stubs/stringprintf_unittest.cc", + "src/google/protobuf/stubs/structurally_valid_unittest.cc", + "src/google/protobuf/stubs/strutil_unittest.cc", + "src/google/protobuf/stubs/template_util_unittest.cc", + "src/google/protobuf/stubs/time_test.cc", + "src/google/protobuf/text_format_unittest.cc", + "src/google/protobuf/unknown_field_set_unittest.cc", + "src/google/protobuf/util/delimited_message_util_test.cc", + "src/google/protobuf/util/field_comparator_test.cc", + "src/google/protobuf/util/field_mask_util_test.cc", + "src/google/protobuf/util/internal/default_value_objectwriter_test.cc", + "src/google/protobuf/util/internal/json_objectwriter_test.cc", + "src/google/protobuf/util/internal/json_stream_parser_test.cc", + "src/google/protobuf/util/internal/protostream_objectsource_test.cc", + "src/google/protobuf/util/internal/protostream_objectwriter_test.cc", + "src/google/protobuf/util/internal/type_info_test_helper.cc", + "src/google/protobuf/util/json_util_test.cc", + "src/google/protobuf/util/message_differencer_unittest.cc", + "src/google/protobuf/util/time_util_test.cc", + "src/google/protobuf/util/type_resolver_util_test.cc", + "src/google/protobuf/well_known_types_unittest.cc", + "src/google/protobuf/wire_format_unittest.cc", + "src/google/protobuf/wire_format_unittest.inc", + ], + copts = COPTS + select({ + "//build_defs:config_msvc": [], + "//conditions:default": [ + "-Wno-deprecated-declarations", + ], + }), + data = [ + # Files for csharp_bootstrap_unittest.cc. + "//conformance:all_files", + ":test_plugin", + ] + glob([ + "src/google/protobuf/**/*", + ]) + glob( + [ + # Files for csharp_bootstrap_unittest.cc. + "csharp/src/**/*", + ], + allow_empty = True, + ), + includes = [ + "src/", + ], + linkopts = LINK_OPTS, + deps = [ + ":cc_test_protos", + ":protobuf", + ":protoc_lib", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ] + select({ + "//build_defs:config_msvc": [], + "//conditions:default": ["@zlib//:zlib"], + }), ) ################################################################################ @@ -261,57 +797,288 @@ alias( # Python support ################################################################################ -alias( - name = "protobuf_python", - actual = "//python:protobuf_python", - visibility = ["//visibility:public"], -) - -alias( +py_library( name = "python_srcs", - actual = "//python:python_srcs", + srcs = glob( + [ + "python/google/protobuf/**/*.py", + ], + ), + imports = ["python"], + srcs_version = "PY2AND3", visibility = ["@upb//:__subpackages__"], ) -alias( +py_library( name = "python_test_srcs", - actual = "//python:python_test_srcs", + srcs = glob( + [ + "python/google/protobuf/internal/*_test.py", + "python/google/protobuf/internal/test_util.py", + ], + ), + imports = ["python"], + srcs_version = "PY3", visibility = ["@upb//:__subpackages__"], ) -alias( +cc_binary( + name = "python/google/protobuf/internal/_api_implementation.so", + srcs = ["python/google/protobuf/internal/api_implementation.cc"], + copts = COPTS + [ + "-DPYTHON_PROTO2_CPP_IMPL_V2", + ], + linkshared = 1, + linkstatic = 1, + tags = [ + # Exclude this target from wildcard expansion (//...) because it may + # not even be buildable. It will be built if it is needed according + # to :use_fast_cpp_protos. + # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes + "manual", + ], + deps = select({ + "//conditions:default": [], + ":use_fast_cpp_protos": ["//external:python_headers"], + }), +) + +cc_binary( + name = "python/google/protobuf/pyext/_message.so", + srcs = glob([ + "python/google/protobuf/pyext/*.cc", + "python/google/protobuf/pyext/*.h", + ]), + copts = COPTS + [ + "-DGOOGLE_PROTOBUF_HAS_ONEOF=1", + ] + select({ + "//conditions:default": [], + ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"], + }), + includes = [ + "python/", + "src/", + ], + linkshared = 1, + linkstatic = 1, + tags = [ + # Exclude this target from wildcard expansion (//...) because it may + # not even be buildable. It will be built if it is needed according + # to :use_fast_cpp_protos. + # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes + "manual", + ], + deps = [ + ":protobuf", + ":proto_api", + ] + select({ + "//conditions:default": [], + ":use_fast_cpp_protos": ["//external:python_headers"], + }), +) + +config_setting( + name = "use_fast_cpp_protos", + values = { + "define": "use_fast_cpp_protos=true", + }, + visibility = [ + # Public, but Protobuf only visibility. + "//:__subpackages__", + ], +) + +config_setting( + name = "allow_oversize_protos", + values = { + "define": "allow_oversize_protos=true", + }, + visibility = [ + # Public, but Protobuf only visibility. + "//:__subpackages__", + ], +) + +# Copy the builtin proto files from src/google/protobuf to +# python/google/protobuf. This way, the generated Python sources will be in the +# same directory as the Python runtime sources. This is necessary for the +# modules to be imported correctly since they are all part of the same Python +# package. +internal_copied_filegroup( + name = "protos_python", + srcs = [ + "src/google/protobuf/any.proto", + "src/google/protobuf/api.proto", + "src/google/protobuf/compiler/plugin.proto", + "src/google/protobuf/descriptor.proto", + "src/google/protobuf/duration.proto", + "src/google/protobuf/empty.proto", + "src/google/protobuf/field_mask.proto", + "src/google/protobuf/source_context.proto", + "src/google/protobuf/struct.proto", + "src/google/protobuf/timestamp.proto", + "src/google/protobuf/type.proto", + "src/google/protobuf/wrappers.proto", + ], + dest = "python", + strip_prefix = "src", +) + +py_proto_library( name = "well_known_types_py_pb2", - actual = "//python:well_known_types_py_pb2", + srcs = [ + "python/google/protobuf/any.proto", + "python/google/protobuf/api.proto", + "python/google/protobuf/compiler/plugin.proto", + "python/google/protobuf/descriptor.proto", + "python/google/protobuf/duration.proto", + "python/google/protobuf/empty.proto", + "python/google/protobuf/field_mask.proto", + "python/google/protobuf/source_context.proto", + "python/google/protobuf/struct.proto", + "python/google/protobuf/timestamp.proto", + "python/google/protobuf/type.proto", + "python/google/protobuf/wrappers.proto", + ], + include = "python", + default_runtime = "", + protoc = ":protoc", + srcs_version = "PY2AND3", visibility = ["//visibility:public"], ) -alias( +py_library( + name = "protobuf_python", + data = select({ + "//conditions:default": [], + ":use_fast_cpp_protos": [ + ":python/google/protobuf/internal/_api_implementation.so", + ":python/google/protobuf/pyext/_message.so", + ], + }), + visibility = ["//visibility:public"], + deps = [ + ":python_srcs", + ":well_known_types_py_pb2", + ], +) + +# Copy the test proto files from src/google/protobuf to +# python/google/protobuf. This way, the generated Python sources will be in the +# same directory as the Python runtime sources. This is necessary for the +# modules to be imported correctly by the tests since they are all part of the +# same Python package. +internal_copied_filegroup( + name = "protos_python_test", + srcs = LITE_TEST_PROTOS + TEST_PROTOS, + dest = "python", + strip_prefix = "src", +) + +# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in +# which case we can simply add :protos_python_test in srcs. +COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS] + +COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS] + +py_proto_library( name = "python_common_test_protos", - actual = "//python:python_common_test_protos", + srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS, + include = "python", + default_runtime = "", + protoc = ":protoc", + srcs_version = "PY2AND3", visibility = ["//visibility:public"], + deps = [":well_known_types_py_pb2"], ) -alias( +py_proto_library( name = "python_specific_test_protos", - actual = "//python:python_specific_test_protos", + srcs = glob([ + "python/google/protobuf/internal/*.proto", + "python/google/protobuf/internal/import_test_package/*.proto", + ]), + include = "python", + default_runtime = ":protobuf_python", + protoc = ":protoc", + srcs_version = "PY2AND3", visibility = ["//visibility:public"], + deps = [":python_common_test_protos"], +) + +py_library( + name = "python_tests", + srcs = glob( + [ + "python/google/protobuf/internal/*_test.py", + "python/google/protobuf/internal/test_util.py", + "python/google/protobuf/internal/import_test_package/__init__.py", + ], + ), + imports = ["python"], + srcs_version = "PY2AND3", + deps = [ + ":protobuf_python", + ":python_common_test_protos", + ":python_specific_test_protos", + ], +) + +internal_protobuf_py_tests( + name = "python_tests_batch", + data = glob([ + "src/google/protobuf/**/*", + ]), + modules = [ + "descriptor_database_test", + "descriptor_pool_test", + "descriptor_test", + "generator_test", + "json_format_test", + "message_factory_test", + "message_test", + "proto_builder_test", + "reflection_test", + "service_reflection_test", + "symbol_database_test", + "text_encoding_test", + "text_format_test", + "unknown_fields_test", + "wire_format_test", + ], + deps = [":python_tests"], +) + +cc_library( + name = "proto_api", + hdrs = ["python/google/protobuf/proto_api.h"], + visibility = ["//visibility:public"], + deps = [ + "//external:python_headers", + ], ) proto_lang_toolchain( name = "cc_toolchain", blacklisted_protos = [ + "@com_google_protobuf//:any_proto", + "@com_google_protobuf//:api_proto", "@com_google_protobuf//:compiler_plugin_proto", "@com_google_protobuf//:descriptor_proto", + "@com_google_protobuf//:duration_proto", + "@com_google_protobuf//:empty_proto", + "@com_google_protobuf//:field_mask_proto", + "@com_google_protobuf//:source_context_proto", + "@com_google_protobuf//:struct_proto", + "@com_google_protobuf//:timestamp_proto", + "@com_google_protobuf//:type_proto", + "@com_google_protobuf//:wrappers_proto", ], command_line = "--cpp_out=$(OUT)", runtime = ":protobuf", visibility = ["//visibility:public"], ) -################################################################################ -# Objective-C support -################################################################################ - alias( name = "objectivec", actual = "//objectivec", @@ -327,88 +1094,92 @@ alias( ) ################################################################################ -# Test protos +# Test generated proto support ################################################################################ -alias( - name = "lite_test_proto_srcs", - actual = "//src/google/protobuf:lite_test_proto_srcs", # proto_library - visibility = ["//:__subpackages__"], -) - -alias( - name = "lite_test_protos", - actual = "//src/google/protobuf:lite_test_protos", # proto_library - visibility = ["//:__subpackages__"], -) - -alias( - name = "test_proto_srcs", - actual = "//src/google/protobuf:test_proto_srcs", # filegroup - visibility = ["//:__subpackages__"], -) - -alias( - name = "test_protos", - actual = "//src/google/protobuf:test_protos", # proto_library - visibility = ["//:__subpackages__"], -) - -# Validate generated proto source inputs: - genrule( name = "generated_protos", - testonly = 1, - srcs = ["//src/google/protobuf:test_proto_srcs"], + srcs = ["src/google/protobuf/unittest_import.proto"], outs = ["unittest_gen_import.proto"], - cmd = "cat src/google/protobuf/unittest_import.proto > $@", + cmd = "cat $(SRCS) | sed 's|google/|src/google/|' > $(OUTS)", ) proto_library( name = "generated_protos_proto", - testonly = 1, - srcs = [":generated_protos"], - deps = ["//src/google/protobuf:generic_test_protos"], + srcs = [ + "src/google/protobuf/unittest_import_public.proto", + "unittest_gen_import.proto", + ], ) -internal_py_proto_library( +py_proto_library( name = "generated_protos_py", - testonly = 1, - srcs = [":generated_protos"], + srcs = [ + "src/google/protobuf/unittest_import_public.proto", + "unittest_gen_import.proto", + ], default_runtime = "", protoc = ":protoc", - deps = ["//python:python_common_test_protos"], ) ################################################################################ # Conformance tests ################################################################################ -cc_proto_library( - name = "test_messages_proto2_cc_proto", - visibility = [ - "//conformance:__pkg__", - "//src:__subpackages__", - ], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], +alias( + name = "conformance_test_runner", + actual = "//conformance:conformance_test_runner", + visibility = ["//visibility:public"], ) -cc_proto_library( - name = "test_messages_proto3_cc_proto", - visibility = [ - "//conformance:__pkg__", - "//src:__subpackages__", - ], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], +proto_library( + name = "test_messages_proto2_proto", + strip_import_prefix = "src", + srcs = ["src/google/protobuf/test_messages_proto2.proto"], + visibility = ["//visibility:public"], ) +proto_library( + name = "test_messages_proto3_proto", + strip_import_prefix = "src", + srcs = ["src/google/protobuf/test_messages_proto3.proto"], + visibility = ["//visibility:public"], + deps = [ + ":any_proto", + ":duration_proto", + ":field_mask_proto", + ":struct_proto", + ":timestamp_proto", + ":wrappers_proto", + ], +) + +# TODO: re-enable this test if appropriate, or replace with something that +# uses the new setup. +# sh_test( +# name = "build_files_updated_unittest", +# srcs = [ +# "build_files_updated_unittest.sh", +# ], +# data = [ +# "BUILD", +# "cmake/extract_includes.bat.in", +# "cmake/libprotobuf.cmake", +# "cmake/libprotobuf-lite.cmake", +# "cmake/libprotoc.cmake", +# "cmake/tests.cmake", +# "src/Makefile.am", +# "update_file_lists.sh", +# ], +# ) + java_proto_library( name = "test_messages_proto2_java_proto", visibility = [ "//conformance:__pkg__", "//java:__subpackages__", ], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], + deps = [":test_messages_proto2_proto"], ) java_proto_library( @@ -417,7 +1188,7 @@ java_proto_library( "//conformance:__pkg__", "//java:__subpackages__", ], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], + deps = [":test_messages_proto3_proto"], ) java_lite_proto_library( @@ -426,7 +1197,7 @@ java_lite_proto_library( "//conformance:__pkg__", "//java:__subpackages__", ], - deps = ["//src/google/protobuf:test_messages_proto2_proto"], + deps = [":test_messages_proto2_proto"], ) java_lite_proto_library( @@ -435,89 +1206,7 @@ java_lite_proto_library( "//conformance:__pkg__", "//java:__subpackages__", ], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], -) - -internal_objc_proto_library( - name = "test_messages_proto2_objc_proto", - testonly = 1, - srcs = ["//src/google/protobuf:test_messages_proto2.proto"], - includes = ["src/google/protobuf"], - visibility = [ - "//conformance:__pkg__", - "//objectivec:__subpackages__", - ], -) - -internal_objc_proto_library( - name = "test_messages_proto3_objc_proto", - testonly = 1, - srcs = ["//src/google/protobuf:test_messages_proto3.proto"], - includes = [ - "src/google/protobuf", - # The above must come first. - "src", - ], - proto_deps = [":well_known_protos"], - visibility = [ - "//conformance:__pkg__", - "//objectivec:__subpackages__", - ], -) - -internal_php_proto_library( - name = "test_messages_proto3_php_proto", - testonly = 1, - srcs = ["//src/google/protobuf:test_messages_proto3.proto"], - outs = [ - "GPBMetadata/TestMessagesProto3.php", - "Protobuf_test_messages/Proto3/EnumOnlyProto3.php", - "Protobuf_test_messages/Proto3/EnumOnlyProto3/PBBool.php", - "Protobuf_test_messages/Proto3/ForeignEnum.php", - "Protobuf_test_messages/Proto3/ForeignMessage.php", - "Protobuf_test_messages/Proto3/NullHypothesisProto3.php", - "Protobuf_test_messages/Proto3/TestAllTypesProto3.php", - "Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php", - "Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php", - "Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php", - ], - includes = [ - "src/google/protobuf", - # The above must come first. - "src", - ], - proto_deps = [":well_known_protos"], - visibility = [ - "//conformance:__pkg__", - "//php:__subpackages__", - ], -) - -internal_ruby_proto_library( - name = "test_messages_proto2_ruby_proto", - testonly = 1, - srcs = ["//src/google/protobuf:test_messages_proto2.proto"], - includes = ["src/google/protobuf"], - visibility = [ - "//conformance:__pkg__", - "//ruby:__subpackages__", - ], -) - -internal_ruby_proto_library( - name = "test_messages_proto3_ruby_proto", - testonly = 1, - srcs = ["//src/google/protobuf:test_messages_proto3.proto"], - includes = [ - "src/google/protobuf", - # The above must come first. - "src", - ], - proto_deps = [":well_known_protos"], - visibility = [ - "//conformance:__pkg__", - "//ruby:__subpackages__", - ], + deps = [":test_messages_proto3_proto"], ) filegroup( @@ -526,6 +1215,46 @@ filegroup( visibility = ["//visibility:public"], ) +# Kotlin proto rules + +proto_library( + name = "kt_unittest_lite", + srcs = [ + "src/google/protobuf/map_lite_unittest.proto", + "src/google/protobuf/unittest_import_lite.proto", + "src/google/protobuf/unittest_import_public_lite.proto", + "src/google/protobuf/unittest_lite.proto", + ], + visibility = ["//java/kotlin-lite:__subpackages__"], + strip_import_prefix = "src", +) + +proto_library( + name = "kt_unittest", + srcs = [ + "src/google/protobuf/map_proto2_unittest.proto", + "src/google/protobuf/unittest.proto", + "src/google/protobuf/unittest_import.proto", + "src/google/protobuf/unittest_import_public.proto", + ], + visibility = ["//java/kotlin:__subpackages__"], + strip_import_prefix = "src", +) + +proto_library( + name = "kt_proto3_unittest", + srcs = [ + "src/google/protobuf/unittest_import.proto", + "src/google/protobuf/unittest_import_public.proto", + "src/google/protobuf/unittest_proto3.proto", + ], + visibility = [ + "//java/kotlin:__subpackages__", + "//java/kotlin-lite:__subpackages__", + ], + strip_import_prefix = "src", +) + ################################################################################ # Packaging rules ################################################################################ @@ -539,6 +1268,22 @@ pkg_files( "cmake/*.cmake", "cmake/*.in", "editors/*", + + # Several of these files are generated by autogen.sh, so using + # glob() lets us ignore them if they are missing. (This is not good + # practice, though.) + "Makefile.in", + "aclocal.m4", + "ar-lib", + "compile", + "config*", + "depcomp", + "install-sh", + "ltmain.sh", + "m4/*.m4", + "missing", + "protobuf*.pc.in", + "test-driver", ], allow_empty = True, ) + [ @@ -547,20 +1292,37 @@ pkg_files( "CMakeLists.txt", "CONTRIBUTORS.txt", "LICENSE", + "Makefile.am", "README.md", "WORKSPACE", + "autogen.sh", + "build_files_updated_unittest.sh", "cmake/CMakeLists.txt", "cmake/README.md", - "cmake/update_file_lists.sh", "generate_descriptor_proto.sh", "maven_install.json", + "update_file_lists.sh", "//third_party:BUILD.bazel", "//third_party:zlib.BUILD", + "//util/python:BUILD.bazel", ], strip_prefix = strip_prefix.from_root(""), visibility = ["//pkg:__pkg__"], ) +# C++ runtime +pkg_files( + name = "cpp_dist_files", + srcs = glob( + ["src/**/*"], + exclude = [ + "src/google/protobuf/compiler/objectivec/method_dump.sh", # not in autotools dist + ], + ), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + # Additional files for C# pkg_files( name = "csharp_dist_files", @@ -578,3 +1340,29 @@ pkg_files( ], visibility = ["//pkg:__pkg__"], ) + +# Python runtime +pkg_files( + name = "python_dist_files", + srcs = glob([ + "python/google/**/*.proto", + "python/google/**/*.py", + "python/google/protobuf/internal/*.cc", + "python/google/protobuf/pyext/*.cc", + "python/google/protobuf/pyext/*.h", + ]) + [ + "python/MANIFEST.in", + "python/README.md", + "python/google/protobuf/proto_api.h", + "python/google/protobuf/pyext/README", + "python/google/protobuf/python_protobuf.h", + "python/mox.py", + "python/release.sh", + "python/setup.cfg", + "python/setup.py", + "python/stubout.py", + "python/tox.ini", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/libs/protobuf/CHANGES.txt b/libs/protobuf/CHANGES.txt index c110dcb..cf6a74d 100644 --- a/libs/protobuf/CHANGES.txt +++ b/libs/protobuf/CHANGES.txt @@ -1,71 +1,28 @@ -2022-07-01 Unreleased version - C++ - * cpp_generated_lib_linked support is removed in protoc - * Reduced .pb.o object file size slightly by explicitly instantiating - InternalMetadata templates in the runtime. - * Add C++20 keywords guarded by PROTOBUF_FUTURE_CPP20_KEYWORDS - * Fixed crash in ThreadLocalStorage for pre-C++17 compilers on 32-bit ARM. - * Clarified that JSON API non-OK statuses are not a stable API. - * Added a default implementation of MessageDifferencer::Reporter methods. - * proto2::MapPair is now an alias to std::pair. - * Hide C++ RepeatedField::UnsafeArenaSwap - * Use table-driven parser for reflection based objects. - * Update Map's InternalSwap() to take a pointer to the other Map. - * Add ARM-optimized Varint decoding functions. - * Minor optimization for parsing groups - * Declare ReflectiveProtoHook class - * Reduce size of VarintParse code in protocol buffers, by calling the shared - routine after handling just one-byte varint encoding inline, rather than - handling one-byte and two-byte varints inline. - * Avoid inlining some large heavily duplicated routines in repeated_ptr_field.h - * Add ReflectiveProtoHook to Reflection. - * Turns on table-driven parser for reflection based objects. - * Save code space by avoiding inlining of large-in-aggregate code-space MessageLite::~MessageLite destructor. - * Undefine the macro `linux` when compiling protobuf - * Reduce memory consumption of MessageSet parsing. - * Save code space by avoiding inlining of large-in-aggregate code-space MessageLite::~MessageLite destructor. - * Breaking change: delete Arena::Init - * Make a PROTOBUF_POISON/UNPOISON to reduce noise in the source - * Put alignment functions in "arena_align.h" - * Split off `cleanup` arena functions into "arena_cleanup.h" - * Fix signed / unsigned match in CHECK_EQ - * Kill Atomic<>. it's not pulling it's weight - * Move AllocationPolicy out of arena_impl, and unify arena_config for bazel - * Fix failure case in table-driven parser. - * Add a new JSON parser. - * Removed old JSON parsing code. - * Introduce the Printer::{SetRedactDebugString,SetRandomizeDebugString} private flags. - * Introduce global flags to control Printer::{SetRedactDebugString, SetRandomizeDebugString}. - * proto3 string fields no longer trigger clang-tidy warning bugprone-branch-clone. +2022-12-07 version 21.11 (C++/Java/Python/PHP/Objective-C/C#/Ruby) + Python + * Add license file to pypi wheels (#10936) + * Fix round-trip bug (#10158) - - Kotlin - * Suppress deprecation warnings in Kotlin generated code. - * Kotlin generated code comments now use kdoc format instead of javadoc. - * Escape keywords in package names in proto generated code - * Add Kotlin enum int value getters and setters +2022-11-29 version 21.10 (C++/Java/Python/PHP/Objective-C/C#/Ruby) Java - * Performance improvement for repeated use of FieldMaskUtil#merge by caching - constructed FieldMaskTrees. - * Optimized Java proto serialization gencode for protos having many extension ranges with few fields in between. - * More thoroughly annotate public generated code in Java lite protocol buffers. - * Fixed Bug in proto3 java lite repeated enum fields. Failed to call copyOnWrite before modifying previously built message. Causes modification to already "built" messages that should be immutable. - * Fix Java reflection serialization of empty packed fields. - * Refactoring java full runtime to reuse sub-message builders and prepare to migrate parsing logic from parse constructor to builder. - * Fix TextFormat parser to build up recurring (but supposedly not repeated) sub-messages directly from text rather than building a new sub-message and merging the fully formed message into the existing field. - * Make message-type extensions merge from wire-format instead of building up instances and merging afterwards. This has much better performance. - * Change the Lite runtime to prefer merging from the wireformat into mutable messages rather than building up a new immutable object before merging. This way results in fewer allocations and copy operations. - * Move proto wireformat parsing functionality from the private "parsing constructor" to the Builder class. + * Use bit-field int values in buildPartial to skip work on unset groups of fields. (#10960) + * Mark nested builder as clean after clear is called (#10984) + UPB + * Fix UPB_LIKELY() for 32-bit Windows builds; update protobuf_deps to point to the current upb 21.x (#11028) + Other + * Add public modifiers to kotlin code (#11068) + +2022-10-26 version 21.9 (C++/Java/Python/PHP/Objective-C/C#/Ruby) + + C++ + * Update zlib to 1.2.13 (#10819) Python - * Changes ordering of printed fields in .pyi files from lexicographic to the same ordering found in the proto descriptor. - * Adds GeneratedCodeInfo annotations to python proto .pyi outputs as a base64 encoded docstring in the last line of the .pyi file for code analysis tools. - * Fix message factory's behavior in python cpp extension to return same message classes for same descriptor, even if the factories are different. - * Add type annotation for enum value fields in enum classes. + * Target MacOS 10.9 to fix #10799 (#10807) - Compiler - * Print full path name of source .proto file on error + Ruby + * Replace libc strdup usage with internal impl to restore musl compat (#10818) 2022-10-18 version 21.8 (C++/Java/Python/PHP/Objective-C/C#/Ruby) @@ -81,6 +38,7 @@ Ruby * Auto capitalize enums name in Ruby (#10454) (#10763) + 2022-09-29 version 21.7 (C++/Java/Python/PHP/Objective-C/C#/Ruby) Java * Refactoring java full runtime to reuse sub-message builders and prepare to @@ -110,6 +68,7 @@ C++ Python * Fixed comparison of maps in Python. + 2022-07-25 version 21.4 (C++/Java/Python/PHP/Objective-C/C#/Ruby) C++ @@ -246,7 +205,6 @@ C++ Java * Update protobuf_version.bzl to separate protoc and per-language java … (#9900) * 6x speedup in ArrayEncoder.writeUInt32NotTag - * Java generated code is no longer compatible with runtimes 2.6.1 and earlier Python * Increment python major version to 4 in version.json for python upb (#9926) @@ -258,7 +216,6 @@ C++ * Due to the breaking changes for Python, the major version number for Python has been incremented. * The binary wheel for macOS now supports Apple silicon. - * In TextFormat, transform UnicodeDecodeError into ParseError. PHP diff --git a/libs/protobuf/CMakeLists.txt b/libs/protobuf/CMakeLists.txt index dead8be..04cb330 100644 --- a/libs/protobuf/CMakeLists.txt +++ b/libs/protobuf/CMakeLists.txt @@ -19,10 +19,6 @@ endif() if(POLICY CMP0091) cmake_policy(SET CMP0091 NEW) endif() -# Honor visibility properties for all target types. -if(POLICY CMP0063) - cmake_policy(SET CMP0063 NEW) -endif() # Project project(protobuf C CXX) @@ -36,32 +32,15 @@ if(protobuf_DEPRECATED_CMAKE_SUBDIRECTORY_USAGE) get_filename_component(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} DIRECTORY) endif() -# Add C++14 flags -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 14) -endif() -if(CYGWIN) - string(REGEX_MATCH "-std=gnu\\+\\+([0-9]+)" _protobuf_CXX_STD "${CMAKE_CXX_FLAGS}") -endif() -if(NOT _protobuf_CXX_STD) - set(_protobuf_CXX_STD "${CMAKE_CXX_STANDARD}") -endif() -if(_protobuf_CXX_STD LESS "14") - message(FATAL_ERROR "Protocol Buffers requires at least C++14, but is configured for C++${_protobuf_CXX_STD}") -endif() -if(CYGWIN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++${_protobuf_CXX_STD}") +# Add c++11 flags +if (CYGWIN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") else() - set(CMAKE_CXX_STANDARD ${_protobuf_CXX_STD}) + set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) endif() -# For -fvisibility=hidden and -fvisibility-inlines-hidden -set(CMAKE_C_VISIBILITY_PRESET hidden) -set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) - # The Intel compiler isn't able to deal with noinline member functions of # template classes defined in headers. As such it spams the output with # warning #2196: routine is both "inline" and "noinline" @@ -78,11 +57,9 @@ endif() option(protobuf_BUILD_TESTS "Build tests" ON) option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF) option(protobuf_BUILD_EXAMPLES "Build examples" OFF) -option(protobuf_BUILD_PROTOBUF_BINARIES "Build protobuf libraries and protoc compiler" ON) option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON) option(protobuf_BUILD_LIBPROTOC "Build libprotoc" OFF) option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" OFF) -option(protobuf_TEST_XML_OUTDIR "Output directory for XML logs from tests." "") if (BUILD_SHARED_LIBS) set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON) else (BUILD_SHARED_LIBS) @@ -100,23 +77,27 @@ mark_as_advanced(protobuf_DEBUG_POSTFIX) # User options include(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake) -if (protobuf_BUILD_SHARED_LIBS) - # This is necessary for linking in Abseil. - set(CMAKE_POSITION_INDEPENDENT_CODE ON) -endif () - -# Version metadata -set(protobuf_VERSION_STRING "3.21.4") -set(protobuf_DESCRIPTION "Protocol Buffers") -set(protobuf_CONTACT "protobuf@googlegroups.com") - # Overrides for option dependencies if (protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TESTS) set(protobuf_BUILD_LIBPROTOC ON) endif () -if (NOT protobuf_BUILD_PROTOBUF_BINARIES) - set(protobuf_INSTALL OFF) -endif() +# Path to main configure script +set(protobuf_CONFIGURE_SCRIPT "${protobuf_SOURCE_DIR}/configure.ac") + +# Parse configure script +set(protobuf_AC_INIT_REGEX + "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$") +file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE + LIMIT_COUNT 1 REGEX "^AC_INIT") +# Description +string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1" + protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}") +# Version +string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2" + protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}") +# Contact +string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3" + protobuf_CONTACT "${protobuf_AC_INIT_LINE}") # Parse version tweaks set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+)([-]rc[-]|\\.)?([0-9]*)$") string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1" @@ -181,14 +162,6 @@ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map) find_package(Threads REQUIRED) -# We can install dependencies from submodules if we're running -# CMake v3.13 or newer. -if(CMAKE_VERSION VERSION_LESS 3.13) - set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE OFF) -else() - set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE ON) -endif() - set(_protobuf_FIND_ZLIB) if (protobuf_WITH_ZLIB) find_package(ZLIB) @@ -221,7 +194,7 @@ set(protobuf_LINK_LIBATOMIC false) if (NOT MSVC) include(CheckCXXSourceCompiles) set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) - set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++14) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++11) check_cxx_source_compiles(" #include int main() { @@ -269,12 +242,12 @@ endif (protobuf_BUILD_SHARED_LIBS) if (MSVC) if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # Build with multiple processes - add_compile_options(/MP) + add_definitions(/MP) endif() # Set source file and execution character sets to UTF-8 - add_compile_options(/utf-8) + add_definitions(/utf-8) # MSVC warning suppressions - add_compile_options( + add_definitions( /wd4065 # switch statement contains 'default' but no 'case' labels /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' @@ -289,16 +262,23 @@ if (MSVC) /wd4996 # The compiler encountered a deprecated declaration. ) # Allow big object - add_compile_options(/bigobj) + add_definitions(/bigobj) string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) string(REPLACE "." "," protobuf_RC_FILEVERSION "${protobuf_VERSION}") + configure_file(${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in extract_includes.bat) # Suppress linker warnings about files with no symbols defined. - string(APPEND CMAKE_STATIC_LINKER_FLAGS " /ignore:4221") + set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221") - # use English language (0x409) in resource compiler - string(APPEND CMAKE_RC_FLAGS " -l0x409") + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Configure Resource Compiler + enable_language(RC) + # use English language (0x409) in resource compiler + set(rc_flags "/l0x409") + # fix rc.exe invocations because of usage of add_definitions() + set(CMAKE_RC_COMPILE_OBJECT " ${rc_flags} /fo ") + endif() # Generate the version.rc file used elsewhere. configure_file(${protobuf_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) @@ -324,54 +304,28 @@ if (protobuf_UNICODE) add_definitions(-DUNICODE -D_UNICODE) endif (protobuf_UNICODE) -set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library") -set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package") +include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake) +include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake) +if (protobuf_BUILD_LIBPROTOC) + include(${protobuf_SOURCE_DIR}/cmake/libprotoc.cmake) +endif (protobuf_BUILD_LIBPROTOC) +if (protobuf_BUILD_PROTOC_BINARIES) + include(${protobuf_SOURCE_DIR}/cmake/protoc.cmake) + if (NOT DEFINED protobuf_PROTOC_EXE) + set(protobuf_PROTOC_EXE protoc) + endif (NOT DEFINED protobuf_PROTOC_EXE) +endif (protobuf_BUILD_PROTOC_BINARIES) -include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake) - -if (protobuf_BUILD_PROTOBUF_BINARIES) - include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake) - if (NOT DEFINED protobuf_LIB_PROTOBUF_LITE) - set(protobuf_LIB_PROTOBUF_LITE libprotobuf-lite) - endif () - include(${protobuf_SOURCE_DIR}/cmake/libprotobuf.cmake) - if (NOT DEFINED protobuf_LIB_PROTOBUF) - set(protobuf_LIB_PROTOBUF libprotobuf) - endif () - if (protobuf_BUILD_LIBPROTOC) - include(${protobuf_SOURCE_DIR}/cmake/libprotoc.cmake) - if (NOT DEFINED protobuf_LIB_PROTOC) - set(protobuf_LIB_PROTOC libprotoc) - endif () - endif () - if (protobuf_BUILD_PROTOC_BINARIES) - include(${protobuf_SOURCE_DIR}/cmake/protoc.cmake) - if (NOT DEFINED protobuf_PROTOC_EXE) - set(protobuf_PROTOC_EXE protoc) - endif () - endif () -else () - find_package(Protobuf NO_MODULE) - if (Protobuf_FOUND) - set(protobuf_PROTOC_EXE protobuf::protoc) - set(protobuf_LIB_PROTOC protobuf::libprotoc) - set(protobuf_LIB_PROTOBUF protobuf::libprotobuf) - set(protobuf_LIB_PROTOBUF_LITE protobuf::libprotobuf-lite) - message(STATUS "CMake installation of Protobuf found.") - endif () -endif () - -# Ensure we have a protoc executable and protobuf libraries if we need one +# Ensure we have a protoc executable if we need one if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLES) if (NOT DEFINED protobuf_PROTOC_EXE) - find_program(protobuf_PROTOC_EXE protoc REQUIRED) - message(STATUS "Found system ${protobuf_PROTOC_EXE}.") + find_program(protobuf_PROTOC_EXE protoc) + if (NOT protobuf_PROTOC_EXE) + message(FATAL "Build requires 'protoc' but binary not found and not building protoc.") + endif () endif () if(protobuf_VERBOSE) message(STATUS "Using protoc : ${protobuf_PROTOC_EXE}") - message(STATUS "Using libprotobuf : ${protobuf_LIB_PROTOBUF}") - message(STATUS "Using libprotobuf-lite : ${protobuf_LIB_PROTOBUF_LITE}") - message(STATUS "Using libprotoc : ${protobuf_LIB_PROTOC}") endif(protobuf_VERBOSE) endif () diff --git a/libs/protobuf/Makefile.am b/libs/protobuf/Makefile.am new file mode 100644 index 0000000..681cd8c --- /dev/null +++ b/libs/protobuf/Makefile.am @@ -0,0 +1,1292 @@ +## Process this file with automake to produce Makefile.in + +ACLOCAL_AMFLAGS = -I m4 + +AUTOMAKE_OPTIONS = foreign + +# Build . before src so that our all-local and clean-local hooks kicks in at +# the right time. +SUBDIRS = . src + +# Always include third_party directories in distributions. +# +# Note that distribution artifacts will be produced by Bazel in the future. +# See pkg/BUILD.bazel for overall definitions. +DIST_SUBDIRS = src conformance benchmarks third_party/googletest + +# Build gmock before we build protobuf tests. We don't add gmock to SUBDIRS +# because then "make check" would also build and run all of gmock's own tests, +# which takes a lot of time and is generally not useful to us. Also, we don't +# want "make install" to recurse into gmock since we don't want to overwrite +# the installed version of gmock if there is one. +check-local: + @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock" + @cd third_party/googletest/googletest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la + @cd third_party/googletest/googlemock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la + +# We would like to clean gmock when "make clean" is invoked. But we have to +# be careful because clean-local is also invoked during "make distclean", but +# "make distclean" already recurses into gmock because it's listed among the +# DIST_SUBDIRS. distclean will delete gmock/Makefile, so if we then try to +# cd to the directory again and "make clean" it will fail. So, check that the +# Makefile exists before recursing. +clean-local: + @if test -e third_party/googletest/Makefile; then \ + echo "Making clean in googletest"; \ + cd third_party/googletest && $(MAKE) $(AM_MAKEFLAGS) clean; \ + fi; \ + if test -e conformance/Makefile; then \ + echo "Making clean in conformance"; \ + cd conformance && $(MAKE) $(AM_MAKEFLAGS) clean; \ + fi; \ + if test -e benchmarks/Makefile; then \ + echo "Making clean in benchmarks"; \ + cd benchmarks && $(MAKE) $(AM_MAKEFLAGS) clean; \ + fi; \ + if test -e objectivec/DevTools; then \ + echo "Cleaning any ObjC pyc files"; \ + rm -f objectivec/DevTools/*.pyc; \ + fi + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = protobuf.pc protobuf-lite.pc + +# Note: please keep this in sync with the dist_files rule in csharp/BUILD.bazel. +csharp_EXTRA_DIST= \ + global.json \ + csharp/.editorconfig \ + csharp/.gitignore \ + csharp/CHANGES.txt \ + csharp/Google.Protobuf.Tools.targets \ + csharp/Google.Protobuf.Tools.nuspec \ + csharp/NuGet.Config \ + csharp/README.md \ + csharp/build_packages.bat \ + csharp/build_tools.sh \ + csharp/buildall.bat \ + csharp/buildall.sh \ + csharp/generate_protos.sh \ + csharp/install_dotnet_sdk.ps1 \ + csharp/keys/Google.Protobuf.public.snk \ + csharp/keys/Google.Protobuf.snk \ + csharp/keys/README.md \ + csharp/protos/README.md \ + csharp/protos/map_unittest_proto3.proto \ + csharp/protos/old_extensions1.proto \ + csharp/protos/old_extensions2.proto \ + csharp/protos/unittest_issue6936_a.proto \ + csharp/protos/unittest_issue6936_b.proto \ + csharp/protos/unittest_issue6936_c.proto \ + csharp/protos/unittest_custom_options_proto3.proto \ + csharp/protos/unittest_import_public_proto3.proto \ + csharp/protos/unittest_import_public.proto \ + csharp/protos/unittest_import_proto3.proto \ + csharp/protos/unittest_import.proto \ + csharp/protos/unittest_issues.proto \ + csharp/protos/unittest_proto3.proto \ + csharp/protos/unittest_selfreferential_options.proto \ + csharp/protos/unittest.proto \ + csharp/src/AddressBook/AddPerson.cs \ + csharp/src/AddressBook/Addressbook.cs \ + csharp/src/AddressBook/AddressBook.csproj \ + csharp/src/AddressBook/ListPeople.cs \ + csharp/src/AddressBook/Program.cs \ + csharp/src/AddressBook/SampleUsage.cs \ + csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs \ + csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs \ + csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs \ + csharp/src/Google.Protobuf.Benchmarks/ByteStringBenchmark.cs \ + csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj \ + csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs \ + csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs \ + csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs \ + csharp/src/Google.Protobuf.Benchmarks/Program.cs \ + csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto \ + csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs \ + csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs \ + csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs \ + csharp/src/Google.Protobuf.Conformance/Conformance.cs \ + csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj \ + csharp/src/Google.Protobuf.Conformance/Program.cs \ + csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj \ + csharp/src/Google.Protobuf.JsonDump/Program.cs \ + csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs \ + csharp/src/Google.Protobuf.Test/ByteStringTest.cs \ + csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \ + csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \ + csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs \ + csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs \ + csharp/src/Google.Protobuf.Test/Collections/ProtobufEqualityComparersTest.cs \ + csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs \ + csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs \ + csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs \ + csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs \ + csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs \ + csharp/src/Google.Protobuf.Test/EqualityTester.cs \ + csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs \ + csharp/src/Google.Protobuf.Test/FieldCodecTest.cs \ + csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs \ + csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs \ + csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs \ + csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj \ + csharp/src/Google.Protobuf.Test/IssuesTest.cs \ + csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \ + csharp/src/Google.Protobuf.Test/JsonParserTest.cs \ + csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \ + csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs \ + csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs \ + csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs \ + csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs \ + csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs \ + csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs \ + csharp/src/Google.Protobuf.Test/SampleEnum.cs \ + csharp/src/Google.Protobuf.Test/SampleMessages.cs \ + csharp/src/Google.Protobuf.Test/SampleNaNs.cs \ + csharp/src/Google.Protobuf.Test/TestCornerCases.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936A.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/ForeignMessagePartial.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/OldExtensions1.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/OldExtensions2.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs \ + csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs \ + csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs \ + csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs \ + csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs \ + csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs \ + csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs \ + csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs \ + csharp/src/Google.Protobuf.Test/testprotos.pb \ + csharp/src/Google.Protobuf.sln \ + csharp/src/Google.Protobuf/ByteArray.cs \ + csharp/src/Google.Protobuf/ByteString.cs \ + csharp/src/Google.Protobuf/ByteStringAsync.cs \ + csharp/src/Google.Protobuf/CodedInputStream.cs \ + csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs \ + csharp/src/Google.Protobuf/CodedOutputStream.cs \ + csharp/src/Google.Protobuf/Collections/Lists.cs \ + csharp/src/Google.Protobuf/Collections/MapField.cs \ + csharp/src/Google.Protobuf/Collections/ProtobufEqualityComparers.cs \ + csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs \ + csharp/src/Google.Protobuf/Collections/RepeatedField.cs \ + csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMembersAttribute.cs \ + csharp/src/Google.Protobuf/Compatibility/DynamicallyAccessedMemberTypes.cs \ + csharp/src/Google.Protobuf/Compatibility/MethodInfoExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/RequiresUnreferencedCodeAttribute.cs \ + csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs \ + csharp/src/Google.Protobuf/Compatibility/UnconditionalSuppressMessageAttribute.cs \ + csharp/src/Google.Protobuf/Extension.cs \ + csharp/src/Google.Protobuf/ExtensionRegistry.cs \ + csharp/src/Google.Protobuf/ExtensionSet.cs \ + csharp/src/Google.Protobuf/ExtensionValue.cs \ + csharp/src/Google.Protobuf/FieldCodec.cs \ + csharp/src/Google.Protobuf/FieldMaskTree.cs \ + csharp/src/Google.Protobuf/FrameworkPortability.cs \ + csharp/src/Google.Protobuf/Google.Protobuf.csproj \ + csharp/src/Google.Protobuf/IBufferMessage.cs \ + csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs \ + csharp/src/Google.Protobuf/IDeepCloneable.cs \ + csharp/src/Google.Protobuf/IExtendableMessage.cs \ + csharp/src/Google.Protobuf/IMessage.cs \ + csharp/src/Google.Protobuf/InvalidJsonException.cs \ + csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs \ + csharp/src/Google.Protobuf/JsonFormatter.cs \ + csharp/src/Google.Protobuf/JsonParser.cs \ + csharp/src/Google.Protobuf/JsonToken.cs \ + csharp/src/Google.Protobuf/JsonTokenizer.cs \ + csharp/src/Google.Protobuf/LimitedInputStream.cs \ + csharp/src/Google.Protobuf/MessageExtensions.cs \ + csharp/src/Google.Protobuf/MessageParser.cs \ + csharp/src/Google.Protobuf/ObjectIntPair.cs \ + csharp/src/Google.Protobuf/ParseContext.cs \ + csharp/src/Google.Protobuf/ParserInternalState.cs \ + csharp/src/Google.Protobuf/ParsingPrimitives.cs \ + csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs \ + csharp/src/Google.Protobuf/ParsingPrimitivesWrappers.cs \ + csharp/src/Google.Protobuf/ProtoPreconditions.cs \ + csharp/src/Google.Protobuf/SegmentedBufferHelper.cs \ + csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs \ + csharp/src/Google.Protobuf/Reflection/CustomOptions.cs \ + csharp/src/Google.Protobuf/Reflection/Descriptor.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs \ + csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs \ + csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/ExtensionAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs \ + csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs \ + csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/FieldType.cs \ + csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs \ + csharp/src/Google.Protobuf/Reflection/IDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs \ + csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs \ + csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs \ + csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs \ + csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Any.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Api.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Type.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs \ + csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs \ + csharp/src/Google.Protobuf/WireFormat.cs \ + csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs \ + csharp/src/Google.Protobuf/WritingPrimitives.cs \ + csharp/src/Google.Protobuf/WriterInternalState.cs \ + csharp/src/Google.Protobuf/WriteContext.cs \ + csharp/src/Google.Protobuf/WriteBufferHelper.cs \ + csharp/src/Google.Protobuf/UnknownField.cs \ + csharp/src/Google.Protobuf/UnknownFieldSet.cs \ + csharp/src/Google.Protobuf/UnsafeByteOperations.cs + +# Note: please keep this in sync with the dist_files rules under java/.../BUILD.bazel. +java_EXTRA_DIST= \ + java/README.md \ + java/bom/pom.xml \ + java/core/BUILD.bazel \ + java/core/generate-sources-build.xml \ + java/core/generate-test-sources-build.xml \ + java/core/pom.xml \ + java/core/pom_template.xml \ + java/core/src/main/java/com/google/protobuf/AbstractMessage.java \ + java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java \ + java/core/src/main/java/com/google/protobuf/AbstractParser.java \ + java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java \ + java/core/src/main/java/com/google/protobuf/AllocatedBuffer.java \ + java/core/src/main/java/com/google/protobuf/Android.java \ + java/core/src/main/java/com/google/protobuf/ArrayDecoders.java \ + java/core/src/main/java/com/google/protobuf/BinaryReader.java \ + java/core/src/main/java/com/google/protobuf/BinaryWriter.java \ + java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java \ + java/core/src/main/java/com/google/protobuf/BlockingService.java \ + java/core/src/main/java/com/google/protobuf/BooleanArrayList.java \ + java/core/src/main/java/com/google/protobuf/BufferAllocator.java \ + java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java \ + java/core/src/main/java/com/google/protobuf/ByteOutput.java \ + java/core/src/main/java/com/google/protobuf/ByteString.java \ + java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java \ + java/core/src/main/java/com/google/protobuf/CheckReturnValue.java \ + java/core/src/main/java/com/google/protobuf/CodedInputStream.java \ + java/core/src/main/java/com/google/protobuf/CodedInputStreamReader.java \ + java/core/src/main/java/com/google/protobuf/CodedOutputStream.java \ + java/core/src/main/java/com/google/protobuf/CodedOutputStreamWriter.java \ + java/core/src/main/java/com/google/protobuf/CompileTimeConstant.java \ + java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java \ + java/core/src/main/java/com/google/protobuf/Descriptors.java \ + java/core/src/main/java/com/google/protobuf/DiscardUnknownFieldsParser.java \ + java/core/src/main/java/com/google/protobuf/DoubleArrayList.java \ + java/core/src/main/java/com/google/protobuf/DynamicMessage.java \ + java/core/src/main/java/com/google/protobuf/ExperimentalApi.java \ + java/core/src/main/java/com/google/protobuf/Extension.java \ + java/core/src/main/java/com/google/protobuf/ExtensionLite.java \ + java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java \ + java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java \ + java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java \ + java/core/src/main/java/com/google/protobuf/ExtensionSchema.java \ + java/core/src/main/java/com/google/protobuf/ExtensionSchemaFull.java \ + java/core/src/main/java/com/google/protobuf/ExtensionSchemaLite.java \ + java/core/src/main/java/com/google/protobuf/ExtensionSchemas.java \ + java/core/src/main/java/com/google/protobuf/FieldInfo.java \ + java/core/src/main/java/com/google/protobuf/FieldSet.java \ + java/core/src/main/java/com/google/protobuf/FieldType.java \ + java/core/src/main/java/com/google/protobuf/FloatArrayList.java \ + java/core/src/main/java/com/google/protobuf/GeneratedMessage.java \ + java/core/src/main/java/com/google/protobuf/GeneratedMessageInfoFactory.java \ + java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java \ + java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java \ + java/core/src/main/java/com/google/protobuf/InlineMe.java \ + java/core/src/main/java/com/google/protobuf/IntArrayList.java \ + java/core/src/main/java/com/google/protobuf/Internal.java \ + java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java \ + java/core/src/main/java/com/google/protobuf/IterableByteBufferInputStream.java \ + java/core/src/main/java/com/google/protobuf/JavaType.java \ + java/core/src/main/java/com/google/protobuf/LazyField.java \ + java/core/src/main/java/com/google/protobuf/LazyFieldLite.java \ + java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java \ + java/core/src/main/java/com/google/protobuf/LazyStringList.java \ + java/core/src/main/java/com/google/protobuf/ListFieldSchema.java \ + java/core/src/main/java/com/google/protobuf/LongArrayList.java \ + java/core/src/main/java/com/google/protobuf/ManifestSchemaFactory.java \ + java/core/src/main/java/com/google/protobuf/MapEntry.java \ + java/core/src/main/java/com/google/protobuf/MapEntryLite.java \ + java/core/src/main/java/com/google/protobuf/MapField.java \ + java/core/src/main/java/com/google/protobuf/MapFieldLite.java \ + java/core/src/main/java/com/google/protobuf/MapFieldSchema.java \ + java/core/src/main/java/com/google/protobuf/MapFieldSchemaFull.java \ + java/core/src/main/java/com/google/protobuf/MapFieldSchemaLite.java \ + java/core/src/main/java/com/google/protobuf/MapFieldSchemas.java \ + java/core/src/main/java/com/google/protobuf/Message.java \ + java/core/src/main/java/com/google/protobuf/MessageInfo.java \ + java/core/src/main/java/com/google/protobuf/MessageInfoFactory.java \ + java/core/src/main/java/com/google/protobuf/MessageLite.java \ + java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java \ + java/core/src/main/java/com/google/protobuf/MessageLiteToString.java \ + java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java \ + java/core/src/main/java/com/google/protobuf/MessageReflection.java \ + java/core/src/main/java/com/google/protobuf/MessageSchema.java \ + java/core/src/main/java/com/google/protobuf/MessageSetSchema.java \ + java/core/src/main/java/com/google/protobuf/MutabilityOracle.java \ + java/core/src/main/java/com/google/protobuf/NewInstanceSchema.java \ + java/core/src/main/java/com/google/protobuf/NewInstanceSchemaFull.java \ + java/core/src/main/java/com/google/protobuf/NewInstanceSchemaLite.java \ + java/core/src/main/java/com/google/protobuf/NewInstanceSchemas.java \ + java/core/src/main/java/com/google/protobuf/NioByteString.java \ + java/core/src/main/java/com/google/protobuf/OneofInfo.java \ + java/core/src/main/java/com/google/protobuf/Parser.java \ + java/core/src/main/java/com/google/protobuf/PrimitiveNonBoxingCollection.java \ + java/core/src/main/java/com/google/protobuf/ProtoSyntax.java \ + java/core/src/main/java/com/google/protobuf/Protobuf.java \ + java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java \ + java/core/src/main/java/com/google/protobuf/ProtobufLists.java \ + java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java \ + java/core/src/main/java/com/google/protobuf/ProtocolStringList.java \ + java/core/src/main/java/com/google/protobuf/RawMessageInfo.java \ + java/core/src/main/java/com/google/protobuf/Reader.java \ + java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java \ + java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java \ + java/core/src/main/java/com/google/protobuf/RopeByteString.java \ + java/core/src/main/java/com/google/protobuf/RpcCallback.java \ + java/core/src/main/java/com/google/protobuf/RpcChannel.java \ + java/core/src/main/java/com/google/protobuf/RpcController.java \ + java/core/src/main/java/com/google/protobuf/RpcUtil.java \ + java/core/src/main/java/com/google/protobuf/Schema.java \ + java/core/src/main/java/com/google/protobuf/SchemaFactory.java \ + java/core/src/main/java/com/google/protobuf/SchemaUtil.java \ + java/core/src/main/java/com/google/protobuf/Service.java \ + java/core/src/main/java/com/google/protobuf/ServiceException.java \ + java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java \ + java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java \ + java/core/src/main/java/com/google/protobuf/SmallSortedMap.java \ + java/core/src/main/java/com/google/protobuf/StructuralMessageInfo.java \ + java/core/src/main/java/com/google/protobuf/TextFormat.java \ + java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java \ + java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java \ + java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java \ + java/core/src/main/java/com/google/protobuf/TypeRegistry.java \ + java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java \ + java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java \ + java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java \ + java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java \ + java/core/src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java \ + java/core/src/main/java/com/google/protobuf/UnknownFieldSetSchema.java \ + java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java \ + java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java \ + java/core/src/main/java/com/google/protobuf/UnsafeUtil.java \ + java/core/src/main/java/com/google/protobuf/Utf8.java \ + java/core/src/main/java/com/google/protobuf/WireFormat.java \ + java/core/src/main/java/com/google/protobuf/Writer.java \ + java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java \ + java/core/src/test/java/com/google/protobuf/AbstractProto2LiteSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/AbstractProto2SchemaTest.java \ + java/core/src/test/java/com/google/protobuf/AbstractProto3LiteSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/AbstractProto3SchemaTest.java \ + java/core/src/test/java/com/google/protobuf/AbstractSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/AnyTest.java \ + java/core/src/test/java/com/google/protobuf/ArrayDecodersTest.java \ + java/core/src/test/java/com/google/protobuf/BinaryProtocolTest.java \ + java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java \ + java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java \ + java/core/src/test/java/com/google/protobuf/ByteStringTest.java \ + java/core/src/test/java/com/google/protobuf/CachedFieldSizeTest.java \ + java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java \ + java/core/src/test/java/com/google/protobuf/CodedAdapterTest.java \ + java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java \ + java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java \ + java/core/src/test/java/com/google/protobuf/DecodeUtf8Test.java \ + java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java \ + java/core/src/test/java/com/google/protobuf/DescriptorsTest.java \ + java/core/src/test/java/com/google/protobuf/DiscardUnknownFieldsTest.java \ + java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java \ + java/core/src/test/java/com/google/protobuf/EnumTest.java \ + java/core/src/test/java/com/google/protobuf/ExperimentalMessageFactory.java \ + java/core/src/test/java/com/google/protobuf/ExperimentalSerializationUtil.java \ + java/core/src/test/java/com/google/protobuf/ExperimentalTestDataProvider.java \ + java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java \ + java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java \ + java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java \ + java/core/src/test/java/com/google/protobuf/IntArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/InvalidProtocolBufferExceptionTest.java \ + java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java \ + java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java \ + java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java \ + java/core/src/test/java/com/google/protobuf/LazyFieldTest.java \ + java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java \ + java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java \ + java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java \ + java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java \ + java/core/src/test/java/com/google/protobuf/LongArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java \ + java/core/src/test/java/com/google/protobuf/MapForProto2Test.java \ + java/core/src/test/java/com/google/protobuf/MapLiteTest.java \ + java/core/src/test/java/com/google/protobuf/MapTest.java \ + java/core/src/test/java/com/google/protobuf/MessageTest.java \ + java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java \ + java/core/src/test/java/com/google/protobuf/NioByteStringTest.java \ + java/core/src/test/java/com/google/protobuf/PackedFieldTest.java \ + java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java \ + java/core/src/test/java/com/google/protobuf/ParserLiteTest.java \ + java/core/src/test/java/com/google/protobuf/ParserTest.java \ + java/core/src/test/java/com/google/protobuf/Proto2ExtensionLookupSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/Proto2LiteSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/Proto2MessageFactory.java \ + java/core/src/test/java/com/google/protobuf/Proto2MessageLiteFactory.java \ + java/core/src/test/java/com/google/protobuf/Proto2SchemaTest.java \ + java/core/src/test/java/com/google/protobuf/Proto2UnknownEnumValueTest.java \ + java/core/src/test/java/com/google/protobuf/Proto3LiteSchemaTest.java \ + java/core/src/test/java/com/google/protobuf/Proto3MessageFactory.java \ + java/core/src/test/java/com/google/protobuf/Proto3MessageLiteFactory.java \ + java/core/src/test/java/com/google/protobuf/Proto3SchemaTest.java \ + java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java \ + java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java \ + java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java \ + java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java \ + java/core/src/test/java/com/google/protobuf/ServiceTest.java \ + java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java \ + java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java \ + java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java \ + java/core/src/test/java/com/google/protobuf/TestBadIdentifiersLite.java \ + java/core/src/test/java/com/google/protobuf/TestSchemas.java \ + java/core/src/test/java/com/google/protobuf/TestSchemasLite.java \ + java/core/src/test/java/com/google/protobuf/TestUtil.java \ + java/core/src/test/java/com/google/protobuf/TestUtilLite.java \ + java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java \ + java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java \ + java/core/src/test/java/com/google/protobuf/TextFormatTest.java \ + java/core/src/test/java/com/google/protobuf/TypeRegistryTest.java \ + java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java \ + java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \ + java/core/src/test/java/com/google/protobuf/UnknownFieldSetPerformanceTest.java \ + java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \ + java/core/src/test/java/com/google/protobuf/Utf8Test.java \ + java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java \ + java/core/src/test/java/com/google/protobuf/WireFormatLiteTest.java \ + java/core/src/test/java/com/google/protobuf/WireFormatTest.java \ + java/core/src/test/java/com/google/protobuf/WrappersLiteOfMethodTest.java \ + java/core/src/test/java/com/google/protobuf/WrappersOfMethodTest.java \ + java/core/src/test/proto/com/google/protobuf/any_test.proto \ + java/core/src/test/proto/com/google/protobuf/cached_field_size_test.proto \ + java/core/src/test/proto/com/google/protobuf/deprecated_file.proto \ + java/core/src/test/proto/com/google/protobuf/dynamic_message_test.proto \ + java/core/src/test/proto/com/google/protobuf/field_presence_test.proto \ + java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto \ + java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto \ + java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto \ + java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto \ + java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto \ + java/core/src/test/proto/com/google/protobuf/map_lite_test.proto \ + java/core/src/test/proto/com/google/protobuf/map_test.proto \ + java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto \ + java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto \ + java/core/src/test/proto/com/google/protobuf/nested_extension.proto \ + java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto \ + java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto \ + java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto \ + java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto \ + java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto \ + java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto \ + java/core/src/test/proto/com/google/protobuf/packed_field_test.proto \ + java/core/src/test/proto/com/google/protobuf/proto2_message.proto \ + java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto \ + java/core/src/test/proto/com/google/protobuf/proto2_unknown_enum_values.proto \ + java/core/src/test/proto/com/google/protobuf/proto3_message.proto \ + java/core/src/test/proto/com/google/protobuf/proto3_message_lite.proto \ + java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto \ + java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto \ + java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto \ + java/core/src/test/proto/com/google/protobuf/test_custom_options.proto \ + java/core/src/test/proto/com/google/protobuf/wrappers_test.proto \ + java/internal/BUILD.bazel \ + java/internal/testing.bzl \ + java/kotlin/BUILD.bazel \ + java/kotlin/generate-sources-build.xml \ + java/kotlin/generate-test-sources-build.xml \ + java/kotlin/pom.xml \ + java/kotlin/pom_template.xml \ + java/kotlin/src/main/kotlin/com/google/protobuf/Anies.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/ByteStrings.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/DslMap.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/DslProxy.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt\ + java/kotlin/src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt \ + java/kotlin/src/main/kotlin/com/google/protobuf/UnmodifiableCollections.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/AniesTest.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/ByteStringsTest.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/DslMapTest.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt\ + java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt \ + java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt \ + java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto2.proto \ + java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto \ + java/kotlin/src/test/proto/com/google/protobuf/example_extensible_message.proto \ + java/kotlin/src/test/proto/com/google/protobuf/multiple_files_proto3.proto \ + java/kotlin-lite/BUILD.bazel \ + java/kotlin-lite/generate-sources-build.xml \ + java/kotlin-lite/generate-test-sources-build.xml \ + java/kotlin-lite/lite.awk \ + java/kotlin-lite/pom.xml \ + java/kotlin-lite/pom_template.xml \ + java/kotlin-lite/process-lite-sources-build.xml \ + java/kotlin-lite/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt\ + java/kotlin-lite/src/test/kotlin/com/google/protobuf/ExtendableMessageLiteExtensionsTest.kt\ + java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt \ + java/lite.md \ + java/lite/BUILD.bazel \ + java/lite/generate-sources-build.xml \ + java/lite/generate-test-sources-build.xml \ + java/lite/lite.awk \ + java/lite/pom.xml \ + java/lite/pom_template.xml \ + java/lite/process-lite-sources-build.xml \ + java/lite/src/test/java/com/google/protobuf/LiteTest.java \ + java/BUILD.bazel \ + java/pom.xml \ + java/util/BUILD.bazel \ + java/util/pom.xml \ + java/util/pom_template.xml \ + java/util/src/main/java/com/google/protobuf/util/Durations.java \ + java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java \ + java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java \ + java/util/src/main/java/com/google/protobuf/util/JsonFormat.java \ + java/util/src/main/java/com/google/protobuf/util/Structs.java \ + java/util/src/main/java/com/google/protobuf/util/Timestamps.java \ + java/util/src/main/java/com/google/protobuf/util/Values.java \ + java/util/src/test/java/com/google/protobuf/util/DurationsTest.java \ + java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java \ + java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java \ + java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java \ + java/util/src/test/java/com/google/protobuf/util/StructsTest.java \ + java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java \ + java/util/src/test/java/com/google/protobuf/util/ValuesTest.java \ + java/util/src/test/proto/com/google/protobuf/util/json_test.proto + +# Note: please keep this in sync with the dist_files rule in objectivec/BUILD.bazel. +objectivec_EXTRA_DIST= \ + objectivec/.clang-format \ + objectivec/BUILD.bazel \ + objectivec/DevTools/check_version_stamps.sh \ + objectivec/DevTools/compile_testing_protos.sh \ + objectivec/DevTools/full_mac_build.sh \ + objectivec/DevTools/pddm.py \ + objectivec/DevTools/pddm_tests.py \ + objectivec/generate_well_known_types.sh \ + objectivec/google/protobuf/Any.pbobjc.h \ + objectivec/google/protobuf/Api.pbobjc.h \ + objectivec/google/protobuf/Duration.pbobjc.h \ + objectivec/google/protobuf/Empty.pbobjc.h \ + objectivec/google/protobuf/FieldMask.pbobjc.h \ + objectivec/google/protobuf/SourceContext.pbobjc.h \ + objectivec/google/protobuf/Struct.pbobjc.h \ + objectivec/google/protobuf/Timestamp.pbobjc.h \ + objectivec/google/protobuf/Type.pbobjc.h \ + objectivec/google/protobuf/Wrappers.pbobjc.h \ + objectivec/GPBAny.pbobjc.h \ + objectivec/GPBAny.pbobjc.m \ + objectivec/GPBApi.pbobjc.h \ + objectivec/GPBApi.pbobjc.m \ + objectivec/GPBArray.h \ + objectivec/GPBArray.m \ + objectivec/GPBArray_PackagePrivate.h \ + objectivec/GPBBootstrap.h \ + objectivec/GPBCodedInputStream.h \ + objectivec/GPBCodedInputStream.m \ + objectivec/GPBCodedInputStream_PackagePrivate.h \ + objectivec/GPBCodedOutputStream.h \ + objectivec/GPBCodedOutputStream.m \ + objectivec/GPBCodedOutputStream_PackagePrivate.h \ + objectivec/GPBDescriptor.h \ + objectivec/GPBDescriptor.m \ + objectivec/GPBDescriptor_PackagePrivate.h \ + objectivec/GPBDictionary.h \ + objectivec/GPBDictionary.m \ + objectivec/GPBDictionary_PackagePrivate.h \ + objectivec/GPBDuration.pbobjc.h \ + objectivec/GPBDuration.pbobjc.m \ + objectivec/GPBEmpty.pbobjc.h \ + objectivec/GPBEmpty.pbobjc.m \ + objectivec/GPBExtensionInternals.h \ + objectivec/GPBExtensionInternals.m \ + objectivec/GPBExtensionRegistry.h \ + objectivec/GPBExtensionRegistry.m \ + objectivec/GPBFieldMask.pbobjc.h \ + objectivec/GPBFieldMask.pbobjc.m \ + objectivec/GPBMessage.h \ + objectivec/GPBMessage.m \ + objectivec/GPBMessage_PackagePrivate.h \ + objectivec/GPBProtocolBuffers.h \ + objectivec/GPBProtocolBuffers.m \ + objectivec/GPBProtocolBuffers_RuntimeSupport.h \ + objectivec/GPBRootObject.h \ + objectivec/GPBRootObject.m \ + objectivec/GPBRootObject_PackagePrivate.h \ + objectivec/GPBRuntimeTypes.h \ + objectivec/GPBSourceContext.pbobjc.h \ + objectivec/GPBSourceContext.pbobjc.m \ + objectivec/GPBStruct.pbobjc.h \ + objectivec/GPBStruct.pbobjc.m \ + objectivec/GPBTimestamp.pbobjc.h \ + objectivec/GPBTimestamp.pbobjc.m \ + objectivec/GPBType.pbobjc.h \ + objectivec/GPBType.pbobjc.m \ + objectivec/GPBUnknownField.h \ + objectivec/GPBUnknownField.m \ + objectivec/GPBUnknownField_PackagePrivate.h \ + objectivec/GPBUnknownFieldSet.h \ + objectivec/GPBUnknownFieldSet.m \ + objectivec/GPBUnknownFieldSet_PackagePrivate.h \ + objectivec/GPBUtilities.h \ + objectivec/GPBUtilities.m \ + objectivec/GPBUtilities_PackagePrivate.h \ + objectivec/GPBWellKnownTypes.h \ + objectivec/GPBWellKnownTypes.m \ + objectivec/GPBWireFormat.h \ + objectivec/GPBWireFormat.m \ + objectivec/GPBWrappers.pbobjc.h \ + objectivec/GPBWrappers.pbobjc.m \ + objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj \ + objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata \ + objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist \ + objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \ + objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \ + objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \ + objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj \ + objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata \ + objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist \ + objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \ + objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \ + objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \ + objectivec/ProtocolBuffers_tvOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \ + objectivec/README.md \ + objectivec/Tests/golden_message \ + objectivec/Tests/golden_packed_fields_message \ + objectivec/Tests/GPBARCUnittestProtos.m \ + objectivec/Tests/GPBArrayTests.m \ + objectivec/Tests/GPBCodedInputStreamTests.m \ + objectivec/Tests/GPBCodedOuputStreamTests.m \ + objectivec/Tests/GPBCompileTest01.m \ + objectivec/Tests/GPBCompileTest02.m \ + objectivec/Tests/GPBCompileTest03.m \ + objectivec/Tests/GPBCompileTest04.m \ + objectivec/Tests/GPBCompileTest05.m \ + objectivec/Tests/GPBCompileTest06.m \ + objectivec/Tests/GPBCompileTest07.m \ + objectivec/Tests/GPBCompileTest08.m \ + objectivec/Tests/GPBCompileTest09.m \ + objectivec/Tests/GPBCompileTest10.m \ + objectivec/Tests/GPBCompileTest11.m \ + objectivec/Tests/GPBCompileTest12.m \ + objectivec/Tests/GPBCompileTest13.m \ + objectivec/Tests/GPBCompileTest14.m \ + objectivec/Tests/GPBCompileTest15.m \ + objectivec/Tests/GPBCompileTest16.m \ + objectivec/Tests/GPBCompileTest17.m \ + objectivec/Tests/GPBCompileTest18.m \ + objectivec/Tests/GPBCompileTest19.m \ + objectivec/Tests/GPBCompileTest20.m \ + objectivec/Tests/GPBCompileTest21.m \ + objectivec/Tests/GPBCompileTest22.m \ + objectivec/Tests/GPBCompileTest23.m \ + objectivec/Tests/GPBCompileTest24.m \ + objectivec/Tests/GPBCompileTest25.m \ + objectivec/Tests/GPBConcurrencyTests.m \ + objectivec/Tests/GPBDescriptorTests.m \ + objectivec/Tests/GPBDictionaryTests+Bool.m \ + objectivec/Tests/GPBDictionaryTests+Int32.m \ + objectivec/Tests/GPBDictionaryTests+Int64.m \ + objectivec/Tests/GPBDictionaryTests+String.m \ + objectivec/Tests/GPBDictionaryTests+UInt32.m \ + objectivec/Tests/GPBDictionaryTests+UInt64.m \ + objectivec/Tests/GPBDictionaryTests.m \ + objectivec/Tests/GPBDictionaryTests.pddm \ + objectivec/Tests/GPBExtensionRegistryTest.m \ + objectivec/Tests/GPBMessageTests+ClassNames.m \ + objectivec/Tests/GPBMessageTests+Merge.m \ + objectivec/Tests/GPBMessageTests+Runtime.m \ + objectivec/Tests/GPBMessageTests+Serialization.m \ + objectivec/Tests/GPBMessageTests.m \ + objectivec/Tests/GPBObjectiveCPlusPlusTest.mm \ + objectivec/Tests/GPBPerfTests.m \ + objectivec/Tests/GPBSwiftTests.swift \ + objectivec/Tests/GPBTestUtilities.h \ + objectivec/Tests/GPBTestUtilities.m \ + objectivec/Tests/GPBUnittestProtos.m \ + objectivec/Tests/GPBUnittestProtos2.m \ + objectivec/Tests/GPBUnknownFieldSetTest.m \ + objectivec/Tests/GPBUtilitiesTests.m \ + objectivec/Tests/GPBWellKnownTypesTest.m \ + objectivec/Tests/GPBWireFormatTests.m \ + objectivec/Tests/text_format_extensions_unittest_data.txt \ + objectivec/Tests/text_format_map_unittest_data.txt \ + objectivec/Tests/text_format_unittest_data.txt \ + objectivec/Tests/unittest_cycle.proto \ + objectivec/Tests/unittest_deprecated.proto \ + objectivec/Tests/unittest_deprecated_file.proto \ + objectivec/Tests/unittest_extension_chain_a.proto \ + objectivec/Tests/unittest_extension_chain_b.proto \ + objectivec/Tests/unittest_extension_chain_c.proto \ + objectivec/Tests/unittest_extension_chain_d.proto \ + objectivec/Tests/unittest_extension_chain_e.proto \ + objectivec/Tests/unittest_extension_chain_f.proto \ + objectivec/Tests/unittest_extension_chain_g.proto \ + objectivec/Tests/unittest_objc.proto \ + objectivec/Tests/unittest_objc_options.proto \ + objectivec/Tests/unittest_objc_startup.proto \ + objectivec/Tests/unittest_runtime_proto2.proto \ + objectivec/Tests/unittest_runtime_proto3.proto \ + objectivec/Tests/UnitTests-Bridging-Header.h \ + objectivec/Tests/UnitTests-Info.plist \ + Protobuf.podspec + +# Note: please keep this in sync with the dist_files rule in php/BUILD.bazel. +php_EXTRA_DIST= \ + php/README.md \ + php/REFCOUNTING.md \ + php/composer.json \ + php/composer.json.dist \ + php/ext/google/protobuf/arena.c \ + php/ext/google/protobuf/arena.h \ + php/ext/google/protobuf/array.c \ + php/ext/google/protobuf/array.h \ + php/ext/google/protobuf/config.m4 \ + php/ext/google/protobuf/convert.c \ + php/ext/google/protobuf/convert.h \ + php/ext/google/protobuf/def.c \ + php/ext/google/protobuf/def.h \ + php/ext/google/protobuf/generate_package_xml.sh \ + php/ext/google/protobuf/map.c \ + php/ext/google/protobuf/map.h \ + php/ext/google/protobuf/message.c \ + php/ext/google/protobuf/message.h \ + php/ext/google/protobuf/names.c \ + php/ext/google/protobuf/names.h \ + php/ext/google/protobuf/php-upb.c \ + php/ext/google/protobuf/php-upb.h \ + php/ext/google/protobuf/php_protobuf.h \ + php/ext/google/protobuf/protobuf.c \ + php/ext/google/protobuf/protobuf.h \ + php/ext/google/protobuf/template_package.xml \ + php/ext/google/protobuf/wkt.inc \ + php/ext/google/protobuf/tests/unnecessary_zval.phpt \ + php/generate_descriptor_protos.sh \ + php/generate_test_protos.sh \ + php/release.sh \ + php/src/GPBMetadata/Google/Protobuf/Any.php \ + php/src/GPBMetadata/Google/Protobuf/Api.php \ + php/src/GPBMetadata/Google/Protobuf/Duration.php \ + php/src/GPBMetadata/Google/Protobuf/FieldMask.php \ + php/src/GPBMetadata/Google/Protobuf/GPBEmpty.php \ + php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \ + php/src/GPBMetadata/Google/Protobuf/SourceContext.php \ + php/src/GPBMetadata/Google/Protobuf/Struct.php \ + php/src/GPBMetadata/Google/Protobuf/Timestamp.php \ + php/src/GPBMetadata/Google/Protobuf/Type.php \ + php/src/GPBMetadata/Google/Protobuf/Wrappers.php \ + php/src/Google/Protobuf/Any.php \ + php/src/Google/Protobuf/Api.php \ + php/src/Google/Protobuf/BoolValue.php \ + php/src/Google/Protobuf/BytesValue.php \ + php/src/Google/Protobuf/Descriptor.php \ + php/src/Google/Protobuf/DescriptorPool.php \ + php/src/Google/Protobuf/DoubleValue.php \ + php/src/Google/Protobuf/Duration.php \ + php/src/Google/Protobuf/Enum.php \ + php/src/Google/Protobuf/EnumDescriptor.php \ + php/src/Google/Protobuf/EnumValue.php \ + php/src/Google/Protobuf/EnumValueDescriptor.php \ + php/src/Google/Protobuf/Field.php \ + php/src/Google/Protobuf/FieldDescriptor.php \ + php/src/Google/Protobuf/FieldMask.php \ + php/src/Google/Protobuf/Field/Cardinality.php \ + php/src/Google/Protobuf/Field_Cardinality.php \ + php/src/Google/Protobuf/Field/Kind.php \ + php/src/Google/Protobuf/Field_Kind.php \ + php/src/Google/Protobuf/FloatValue.php \ + php/src/Google/Protobuf/GPBEmpty.php \ + php/src/Google/Protobuf/Int32Value.php \ + php/src/Google/Protobuf/Int64Value.php \ + php/src/Google/Protobuf/Internal/AnyBase.php \ + php/src/Google/Protobuf/Internal/CodedInputStream.php \ + php/src/Google/Protobuf/Internal/CodedOutputStream.php \ + php/src/Google/Protobuf/Internal/Descriptor.php \ + php/src/Google/Protobuf/Internal/DescriptorPool.php \ + php/src/Google/Protobuf/Internal/DescriptorProto.php \ + php/src/Google/Protobuf/Internal/DescriptorProto/ExtensionRange.php \ + php/src/Google/Protobuf/Internal/DescriptorProto/ReservedRange.php \ + php/src/Google/Protobuf/Internal/EnumBuilderContext.php \ + php/src/Google/Protobuf/Internal/EnumDescriptor.php \ + php/src/Google/Protobuf/Internal/EnumDescriptorProto.php \ + php/src/Google/Protobuf/Internal/EnumDescriptorProto/EnumReservedRange.php \ + php/src/Google/Protobuf/Internal/EnumOptions.php \ + php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php \ + php/src/Google/Protobuf/Internal/EnumValueOptions.php \ + php/src/Google/Protobuf/Internal/ExtensionRangeOptions.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \ + php/src/Google/Protobuf/Internal/FieldDescriptor.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto/Label.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto/Type.php \ + php/src/Google/Protobuf/Internal/FieldOptions.php \ + php/src/Google/Protobuf/Internal/FieldOptions/CType.php \ + php/src/Google/Protobuf/Internal/FieldOptions/JSType.php \ + php/src/Google/Protobuf/Internal/FileDescriptor.php \ + php/src/Google/Protobuf/Internal/FileDescriptorProto.php \ + php/src/Google/Protobuf/Internal/FileDescriptorSet.php \ + php/src/Google/Protobuf/Internal/FileOptions.php \ + php/src/Google/Protobuf/Internal/FileOptions/OptimizeMode.php \ + php/src/Google/Protobuf/Internal/GPBDecodeException.php \ + php/src/Google/Protobuf/Internal/GPBJsonWire.php \ + php/src/Google/Protobuf/Internal/GPBLabel.php \ + php/src/Google/Protobuf/Internal/GPBType.php \ + php/src/Google/Protobuf/Internal/GPBUtil.php \ + php/src/Google/Protobuf/Internal/GPBWire.php \ + php/src/Google/Protobuf/Internal/GPBWireType.php \ + php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \ + php/src/Google/Protobuf/Internal/GeneratedCodeInfo/Annotation.php \ + php/src/Google/Protobuf/Internal/GetPublicDescriptorTrait.php \ + php/src/Google/Protobuf/Internal/HasPublicDescriptorTrait.php \ + php/src/Google/Protobuf/Internal/MapEntry.php \ + php/src/Google/Protobuf/Internal/MapField.php \ + php/src/Google/Protobuf/Internal/MapFieldIter.php \ + php/src/Google/Protobuf/Internal/Message.php \ + php/src/Google/Protobuf/Internal/MessageBuilderContext.php \ + php/src/Google/Protobuf/Internal/MessageOptions.php \ + php/src/Google/Protobuf/Internal/MethodDescriptorProto.php \ + php/src/Google/Protobuf/Internal/MethodOptions.php \ + php/src/Google/Protobuf/Internal/MethodOptions/IdempotencyLevel.php \ + php/src/Google/Protobuf/Internal/OneofDescriptor.php \ + php/src/Google/Protobuf/Internal/OneofDescriptorProto.php \ + php/src/Google/Protobuf/Internal/OneofField.php \ + php/src/Google/Protobuf/Internal/OneofOptions.php \ + php/src/Google/Protobuf/Internal/RawInputStream.php \ + php/src/Google/Protobuf/Internal/RepeatedField.php \ + php/src/Google/Protobuf/Internal/RepeatedFieldIter.php \ + php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php \ + php/src/Google/Protobuf/Internal/ServiceOptions.php \ + php/src/Google/Protobuf/Internal/SourceCodeInfo.php \ + php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php \ + php/src/Google/Protobuf/Internal/TimestampBase.php \ + php/src/Google/Protobuf/Internal/UninterpretedOption.php \ + php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php \ + php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php \ + php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php \ + php/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php \ + php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php \ + php/src/Google/Protobuf/Internal/FieldOptions_CType.php \ + php/src/Google/Protobuf/Internal/FieldOptions_JSType.php \ + php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php \ + php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php \ + php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php \ + php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php \ + php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php \ + php/src/Google/Protobuf/ListValue.php \ + php/src/Google/Protobuf/Method.php \ + php/src/Google/Protobuf/Mixin.php \ + php/src/Google/Protobuf/NullValue.php \ + php/src/Google/Protobuf/OneofDescriptor.php \ + php/src/Google/Protobuf/Option.php \ + php/src/Google/Protobuf/SourceContext.php \ + php/src/Google/Protobuf/StringValue.php \ + php/src/Google/Protobuf/Struct.php \ + php/src/Google/Protobuf/Syntax.php \ + php/src/Google/Protobuf/Timestamp.php \ + php/src/Google/Protobuf/Type.php \ + php/src/Google/Protobuf/UInt32Value.php \ + php/src/Google/Protobuf/UInt64Value.php \ + php/src/Google/Protobuf/Value.php \ + php/src/phpdoc.dist.xml \ + php/tests/ArrayTest.php \ + php/tests/compatibility_test.sh \ + php/tests/compile_extension.sh \ + php/tests/DescriptorsTest.php \ + php/tests/EncodeDecodeTest.php \ + php/tests/force_c_ext.php \ + php/tests/gdb_test.sh \ + php/tests/generated_previous/GPBMetadata/ProtoPrevious/TestPreviouslyUnreservedMessage.php \ + php/tests/generated_previous/Previous/readonly.php \ + php/tests/GeneratedClassTest.php \ + php/tests/GeneratedPhpdocTest.php \ + php/tests/GeneratedServiceTest.php \ + php/tests/MapFieldTest.php \ + php/tests/memory_leak_test.php \ + php/tests/memory_leak_test.sh \ + php/tests/multirequest.php \ + php/tests/multirequest.sh \ + php/tests/PhpImplementationTest.php \ + php/tests/PreviouslyGeneratedClassTest.php \ + php/tests/proto/empty/echo.proto \ + php/tests/proto/test.proto \ + php/tests/proto/test_descriptors.proto \ + php/tests/proto/test_empty_php_namespace.proto \ + php/tests/proto/test_import_descriptor_proto.proto \ + php/tests/proto/test_include.proto \ + php/tests/proto/test_no_namespace.proto \ + php/tests/proto/test_php_namespace.proto \ + php/tests/proto/test_prefix.proto \ + php/tests/proto/test_reserved_enum_lower.proto \ + php/tests/proto/test_reserved_enum_upper.proto \ + php/tests/proto/test_reserved_enum_value_lower.proto \ + php/tests/proto/test_reserved_enum_value_upper.proto \ + php/tests/proto/test_reserved_message_lower.proto \ + php/tests/proto/test_reserved_message_upper.proto \ + php/tests/proto/test_service.proto \ + php/tests/proto/test_service_namespace.proto \ + php/tests/proto/test_wrapper_type_setters.proto \ + php/tests/proto_previous/test_previously_unreserved_message.proto \ + php/tests/test_base.php \ + php/tests/test_util.php \ + php/tests/valgrind.supp \ + php/tests/WellKnownTest.php \ + php/tests/WrapperTypeSettersTest.php + +# Note: please keep this in sync with the python_dist_files rule in BUILD.bazel. +python_EXTRA_DIST= \ + python/MANIFEST.in \ + python/google/__init__.py \ + python/google/protobuf/__init__.py \ + python/google/protobuf/compiler/__init__.py \ + python/google/protobuf/descriptor.py \ + python/google/protobuf/descriptor_database.py \ + python/google/protobuf/descriptor_pool.py \ + python/google/protobuf/internal/__init__.py \ + python/google/protobuf/internal/_parameterized.py \ + python/google/protobuf/internal/any_test.proto \ + python/google/protobuf/internal/any_test.proto \ + python/google/protobuf/internal/api_implementation.cc \ + python/google/protobuf/internal/api_implementation.py \ + python/google/protobuf/internal/builder.py \ + python/google/protobuf/internal/containers.py \ + python/google/protobuf/internal/decoder.py \ + python/google/protobuf/internal/descriptor_database_test.py \ + python/google/protobuf/internal/descriptor_pool_test.py \ + python/google/protobuf/internal/descriptor_pool_test1.proto \ + python/google/protobuf/internal/descriptor_pool_test2.proto \ + python/google/protobuf/internal/descriptor_test.py \ + python/google/protobuf/internal/encoder.py \ + python/google/protobuf/internal/enum_type_wrapper.py \ + python/google/protobuf/internal/extension_dict.py \ + python/google/protobuf/internal/factory_test1.proto \ + python/google/protobuf/internal/factory_test2.proto \ + python/google/protobuf/internal/file_options_test.proto \ + python/google/protobuf/internal/generator_test.py \ + python/google/protobuf/internal/import_test.py \ + python/google/protobuf/internal/import_test_package/__init__.py \ + python/google/protobuf/internal/import_test_package/import_public.proto \ + python/google/protobuf/internal/import_test_package/import_public_nested.proto \ + python/google/protobuf/internal/import_test_package/inner.proto \ + python/google/protobuf/internal/import_test_package/outer.proto \ + python/google/protobuf/internal/json_format_test.py \ + python/google/protobuf/internal/keywords_test.py \ + python/google/protobuf/internal/message_factory_test.py \ + python/google/protobuf/internal/message_listener.py \ + python/google/protobuf/internal/message_set_extensions.proto \ + python/google/protobuf/internal/message_test.py \ + python/google/protobuf/internal/missing_enum_values.proto \ + python/google/protobuf/internal/more_extensions.proto \ + python/google/protobuf/internal/more_extensions_dynamic.proto \ + python/google/protobuf/internal/more_messages.proto \ + python/google/protobuf/internal/no_package.proto \ + python/google/protobuf/internal/packed_field_test.proto \ + python/google/protobuf/internal/proto_builder_test.py \ + python/google/protobuf/internal/python_message.py \ + python/google/protobuf/internal/python_protobuf.cc \ + python/google/protobuf/internal/reflection_test.py \ + python/google/protobuf/internal/service_reflection_test.py \ + python/google/protobuf/internal/symbol_database_test.py \ + python/google/protobuf/internal/test_bad_identifiers.proto \ + python/google/protobuf/internal/test_proto3_optional.proto \ + python/google/protobuf/internal/test_util.py \ + python/google/protobuf/internal/testing_refleaks.py \ + python/google/protobuf/internal/text_encoding_test.py \ + python/google/protobuf/internal/text_format_test.py \ + python/google/protobuf/internal/type_checkers.py \ + python/google/protobuf/internal/unknown_fields_test.py \ + python/google/protobuf/internal/well_known_types.py \ + python/google/protobuf/internal/well_known_types.py \ + python/google/protobuf/internal/well_known_types_test.py \ + python/google/protobuf/internal/well_known_types_test.py \ + python/google/protobuf/internal/wire_format.py \ + python/google/protobuf/internal/wire_format_test.py \ + python/google/protobuf/json_format.py \ + python/google/protobuf/message.py \ + python/google/protobuf/message_factory.py \ + python/google/protobuf/proto_api.h \ + python/google/protobuf/proto_builder.py \ + python/google/protobuf/pyext/README \ + python/google/protobuf/pyext/__init__.py \ + python/google/protobuf/pyext/cpp_message.py \ + python/google/protobuf/pyext/descriptor.cc \ + python/google/protobuf/pyext/descriptor.h \ + python/google/protobuf/pyext/descriptor_containers.cc \ + python/google/protobuf/pyext/descriptor_containers.h \ + python/google/protobuf/pyext/descriptor_database.cc \ + python/google/protobuf/pyext/descriptor_database.h \ + python/google/protobuf/pyext/descriptor_pool.cc \ + python/google/protobuf/pyext/descriptor_pool.h \ + python/google/protobuf/pyext/extension_dict.cc \ + python/google/protobuf/pyext/extension_dict.h \ + python/google/protobuf/pyext/map_container.cc \ + python/google/protobuf/pyext/map_container.h \ + python/google/protobuf/pyext/message.cc \ + python/google/protobuf/pyext/message.h \ + python/google/protobuf/pyext/field.cc \ + python/google/protobuf/pyext/field.h \ + python/google/protobuf/pyext/unknown_fields.cc \ + python/google/protobuf/pyext/unknown_fields.h \ + python/google/protobuf/pyext/message_factory.cc \ + python/google/protobuf/pyext/message_factory.h \ + python/google/protobuf/pyext/message_module.cc \ + python/google/protobuf/pyext/proto2_api_test.proto \ + python/google/protobuf/pyext/python.proto \ + python/google/protobuf/pyext/repeated_composite_container.cc \ + python/google/protobuf/pyext/repeated_composite_container.h \ + python/google/protobuf/pyext/repeated_scalar_container.cc \ + python/google/protobuf/pyext/repeated_scalar_container.h \ + python/google/protobuf/pyext/safe_numerics.h \ + python/google/protobuf/pyext/scoped_pyobject_ptr.h \ + python/google/protobuf/pyext/unknown_field_set.cc \ + python/google/protobuf/pyext/unknown_field_set.h \ + python/google/protobuf/python_protobuf.h \ + python/google/protobuf/reflection.py \ + python/google/protobuf/service.py \ + python/google/protobuf/service_reflection.py \ + python/google/protobuf/symbol_database.py \ + python/google/protobuf/text_encoding.py \ + python/google/protobuf/text_format.py \ + python/google/protobuf/unknown_fields.py \ + python/google/protobuf/util/__init__.py \ + python/release.sh \ + python/mox.py \ + python/setup.cfg \ + python/setup.py \ + python/stubout.py \ + python/tox.ini \ + python/README.md + +# Note: please keep this in sync with the dist_files rule in ruby/BUILD.bazel. +ruby_EXTRA_DIST= \ + ruby/Gemfile \ + ruby/.gitignore \ + ruby/README.md \ + ruby/Rakefile \ + ruby/compatibility_tests/v3.0.0/tests/test_import.proto \ + ruby/compatibility_tests/v3.0.0/tests/stress.rb \ + ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb \ + ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb \ + ruby/compatibility_tests/v3.0.0/tests/generated_code.proto \ + ruby/compatibility_tests/v3.0.0/tests/basic.rb \ + ruby/compatibility_tests/v3.0.0/test.sh \ + ruby/compatibility_tests/v3.0.0/Rakefile \ + ruby/compatibility_tests/v3.0.0/README.md \ + ruby/ext/google/protobuf_c/convert.c \ + ruby/ext/google/protobuf_c/convert.h \ + ruby/ext/google/protobuf_c/defs.c \ + ruby/ext/google/protobuf_c/defs.h \ + ruby/ext/google/protobuf_c/extconf.rb \ + ruby/ext/google/protobuf_c/map.c \ + ruby/ext/google/protobuf_c/map.h \ + ruby/ext/google/protobuf_c/message.c \ + ruby/ext/google/protobuf_c/message.h \ + ruby/ext/google/protobuf_c/protobuf.c \ + ruby/ext/google/protobuf_c/protobuf.h \ + ruby/ext/google/protobuf_c/repeated_field.c \ + ruby/ext/google/protobuf_c/repeated_field.h \ + ruby/ext/google/protobuf_c/ruby-upb.c \ + ruby/ext/google/protobuf_c/ruby-upb.h \ + ruby/ext/google/protobuf_c/wrap_memcpy.c \ + ruby/google-protobuf.gemspec \ + ruby/lib/google/protobuf/descriptor_dsl.rb \ + ruby/lib/google/protobuf/message_exts.rb \ + ruby/lib/google/protobuf/repeated_field.rb \ + ruby/lib/google/protobuf/well_known_types.rb \ + ruby/lib/google/protobuf.rb \ + ruby/pom.xml \ + ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyFileDescriptor.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java \ + ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java \ + ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java \ + ruby/src/main/java/com/google/protobuf/jruby/Utils.java \ + ruby/src/main/java/google/ProtobufJavaService.java \ + ruby/src/main/sentinel.proto \ + ruby/tests/basic_proto2.rb \ + ruby/tests/basic_test_proto2.proto \ + ruby/tests/basic_test.proto \ + ruby/tests/basic.rb \ + ruby/tests/common_tests.rb \ + ruby/tests/encode_decode_test.rb \ + ruby/tests/gc_test.rb \ + ruby/tests/repeated_field_test.rb \ + ruby/tests/stress.rb \ + ruby/tests/generated_code_proto2_test.rb \ + ruby/tests/generated_code_proto2.proto \ + ruby/tests/generated_code.proto \ + ruby/tests/multi_level_nesting_test.proto \ + ruby/tests/multi_level_nesting_test.rb \ + ruby/tests/test_import_proto2.proto \ + ruby/tests/test_import.proto \ + ruby/tests/test_ruby_package_proto2.proto \ + ruby/tests/test_ruby_package.proto \ + ruby/tests/generated_code_test.rb \ + ruby/tests/well_known_types_test.rb \ + ruby/tests/type_errors.rb \ + ruby/travis-test.sh + +all_EXTRA_DIST=$(csharp_EXTRA_DIST) $(java_EXTRA_DIST) $(objectivec_EXTRA_DIST) $(php_EXTRA_DIST) $(python_EXTRA_DIST) $(ruby_EXTRA_DIST) + +# Note: please keep this in sync with the common_dist_files rule in BUILD.bazel. +EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \ + autogen.sh \ + generate_descriptor_proto.sh \ + README.md \ + LICENSE \ + CONTRIBUTORS.txt \ + CHANGES.txt \ + update_file_lists.sh \ + BUILD.bazel \ + WORKSPACE \ + CMakeLists.txt \ + build_defs/BUILD.bazel \ + build_defs/cc_proto_blacklist_test.bzl \ + build_defs/compiler_config_setting.bzl \ + build_defs/cpp_opts.bzl \ + build_files_updated_unittest.sh \ + cmake/CMakeLists.txt \ + cmake/README.md \ + cmake/conformance.cmake \ + cmake/examples.cmake \ + cmake/extract_includes.bat.in \ + cmake/install.cmake \ + cmake/libprotobuf-lite.cmake \ + cmake/libprotobuf.cmake \ + cmake/libprotoc.cmake \ + cmake/protobuf-config-version.cmake.in \ + cmake/protobuf-config.cmake.in \ + cmake/protobuf-lite.pc.cmake \ + cmake/protobuf-module.cmake.in \ + cmake/protobuf-options.cmake \ + cmake/protobuf.pc.cmake \ + cmake/protoc.cmake \ + cmake/tests.cmake \ + cmake/version.rc.in \ + csharp/BUILD.bazel \ + editors/README.txt \ + editors/proto.vim \ + editors/protobuf-mode.el \ + examples/AddPerson.java \ + examples/BUILD.bazel \ + examples/CMakeLists.txt \ + examples/ListPeople.java \ + examples/Makefile \ + examples/README.md \ + examples/WORKSPACE \ + examples/add_person.cc \ + examples/add_person.dart \ + examples/add_person.py \ + examples/addressbook.proto \ + examples/go/cmd/add_person/add_person.go \ + examples/go/cmd/add_person/add_person_test.go \ + examples/go/cmd/list_people/list_people.go \ + examples/go/cmd/list_people/list_people_test.go \ + examples/go/go.sum \ + examples/go/go.mod \ + examples/list_people.cc \ + examples/list_people.dart \ + examples/list_people.py \ + examples/pubspec.yaml \ + conformance/BUILD.bazel \ + conformance/defs.bzl \ + maven_install.json \ + php/BUILD.bazel \ + protobuf.bzl \ + protobuf_deps.bzl \ + protobuf_release.bzl \ + protobuf_version.bzl \ + ruby/BUILD.bazel \ + third_party/zlib.BUILD \ + util/python/BUILD.bazel + +# Deletes all the files generated by autogen.sh. +MAINTAINERCLEANFILES = \ + aclocal.m4 \ + ar-lib \ + config.guess \ + config.sub \ + configure \ + depcomp \ + install-sh \ + ltmain.sh \ + Makefile.in \ + missing \ + mkinstalldirs \ + config.h.in \ + stamp.h.in \ + m4/ltsugar.m4 \ + m4/libtool.m4 \ + m4/ltversion.m4 \ + m4/lt~obsolete.m4 \ + m4/ltoptions.m4 diff --git a/libs/protobuf/Protobuf-C++.podspec b/libs/protobuf/Protobuf-C++.podspec index 54a962d..43a3213 100644 --- a/libs/protobuf/Protobuf-C++.podspec +++ b/libs/protobuf/Protobuf-C++.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Protobuf-C++' - s.version = '3.21.8' + s.version = '3.21.12' s.summary = 'Protocol Buffers v3 runtime library for C++.' s.homepage = 'https://github.com/google/protobuf' s.license = 'BSD-3-Clause' @@ -13,7 +13,8 @@ Pod::Spec.new do |s| s.source_files = 'src/google/protobuf/*.{h,cc,inc}', 'src/google/protobuf/stubs/*.{h,cc}', 'src/google/protobuf/io/*.{h,cc}', - 'src/google/protobuf/util/*.{h,cc}' + 'src/google/protobuf/util/*.{h,cc}', + 'src/google/protobuf/util/internal/*.{h,cc}' # Excluding all the tests in the directories above s.exclude_files = 'src/google/**/*_test.{h,cc,inc}', diff --git a/libs/protobuf/Protobuf.podspec b/libs/protobuf/Protobuf.podspec index 48fceea..ebb533d 100644 --- a/libs/protobuf/Protobuf.podspec +++ b/libs/protobuf/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.21.8' + s.version = '3.21.12' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' @@ -34,10 +34,10 @@ Pod::Spec.new do |s| s.user_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' } s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' } - s.ios.deployment_target = '10.0' - s.osx.deployment_target = '10.12' - s.tvos.deployment_target = '12.0' - s.watchos.deployment_target = '6.0' + s.ios.deployment_target = '9.0' + s.osx.deployment_target = '10.9' + s.tvos.deployment_target = '9.0' + s.watchos.deployment_target = '2.0' s.requires_arc = false # The unittest need the generate sources from the testing related .proto diff --git a/libs/protobuf/README.md b/libs/protobuf/README.md index 3377f3a..c2e6575 100644 --- a/libs/protobuf/README.md +++ b/libs/protobuf/README.md @@ -42,7 +42,8 @@ to use the github main version at HEAD, or you need to modify protobuf code, or you are using C++, it's recommended to build your own protoc binary from source. -If you would like to build protoc binary from source, see the [C++ Installation Instructions](src/README.md). +If you would like to build protoc binary from source, see the [C++ Installation +Instructions](src/README.md). Protobuf Runtime Installation ----------------------------- @@ -62,7 +63,6 @@ how to install protobuf runtime for that specific language: | Go | [protocolbuffers/protobuf-go](https://github.com/protocolbuffers/protobuf-go)| | PHP | [php](php) | | Dart | [dart-lang/protobuf](https://github.com/dart-lang/protobuf) | -| Javascript | [protocolbuffers/protobuf-javascript](https://github.com/protocolbuffers/protobuf-javascript)| Quick Start ----------- @@ -82,10 +82,3 @@ The complete documentation for Protocol Buffers is available via the web at: https://developers.google.com/protocol-buffers/ - -Developer Community -------------------- - -To be alerted to upcoming changes in Protocol Buffers and connect with protobuf developers and users, -[join the Google Group](https://groups.google.com/g/protobuf). - diff --git a/libs/protobuf/WORKSPACE b/libs/protobuf/WORKSPACE index fb152a2..d01122a 100644 --- a/libs/protobuf/WORKSPACE +++ b/libs/protobuf/WORKSPACE @@ -9,32 +9,32 @@ local_repository( http_archive( name = "com_google_googletest", - sha256 = "ea54c9845568cb31c03f2eddc7a40f7f83912d04ab977ff50ec33278119548dd", - strip_prefix = "googletest-4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774", + sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb", + strip_prefix = "googletest-release-1.10.0", urls = [ - "https://github.com/google/googletest/archive/4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774.tar.gz", + "https://mirror.bazel.build/github.com/google/googletest/archive/release-1.10.0.tar.gz", + "https://github.com/google/googletest/archive/release-1.10.0.tar.gz", ], ) http_archive( - name = "com_googlesource_code_re2", - sha256 = "906d0df8ff48f8d3a00a808827f009a840190f404559f649cb8e4d7143255ef9", - strip_prefix = "re2-a276a8c738735a0fe45a6ee590fe2df69bcf4502", - urls = ["https://github.com/google/re2/archive/a276a8c738735a0fe45a6ee590fe2df69bcf4502.zip"], # 2022-04-08 -) - -# Bazel platform rules. -http_archive( - name = "platforms", - sha256 = "a879ea428c6d56ab0ec18224f976515948822451473a80d06c2e50af0bbe5121", - strip_prefix = "platforms-da5541f26b7de1dc8e04c075c99df5351742a4a2", - urls = ["https://github.com/bazelbuild/platforms/archive/da5541f26b7de1dc8e04c075c99df5351742a4a2.zip"], # 2022-05-27 + name = "com_github_google_benchmark", + sha256 = "2a778d821997df7d8646c9c59b8edb9a573a6e04c534c01892a40aa524a7b68c", + strip_prefix = "benchmark-bf585a2789e30585b4e3ce6baf11ef2750b54677", + urls = [ + "https://github.com/google/benchmark/archive/bf585a2789e30585b4e3ce6baf11ef2750b54677.zip", + ], ) # Load common dependencies. load("//:protobuf_deps.bzl", "PROTOBUF_MAVEN_ARTIFACTS", "protobuf_deps") protobuf_deps() +bind( + name = "python_headers", + actual = "//util/python:python_headers", +) + load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( @@ -55,13 +55,6 @@ pinned_maven_install() # For `cc_proto_blacklist_test` and `build_test`. load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") -load("@rules_python//python:pip.bzl", "pip_install") - -pip_install( - name="pip_deps", - requirements = "//python:requirements.txt" -) - bazel_skylib_workspace() load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") @@ -76,14 +69,3 @@ kt_register_toolchains() load("@upb//bazel:workspace_deps.bzl", "upb_deps") upb_deps() - -load("@upb//bazel:system_python.bzl", "system_python") -system_python(name = "local_config_python") - -load("@utf8_range//:workspace_deps.bzl", "utf8_range_deps") -utf8_range_deps() - -bind( - name = "python_headers", - actual = "@local_config_python//:python_headers", -) diff --git a/libs/protobuf/appveyor.yml b/libs/protobuf/appveyor.yml index 1e2834b..91f737a 100644 --- a/libs/protobuf/appveyor.yml +++ b/libs/protobuf/appveyor.yml @@ -3,16 +3,16 @@ configuration: environment: matrix: - # Only test few combinations: "Visual Studio 2017 (15) + Win64/MinGW + Debug + DLL". We can + # Only test few combinations: "Visual Studio 2015 (14) + Win64/MinGW + Debug + DLL". We can # test more combinations but AppVeyor just takes too long to finish (each # combination takes ~15mins). - platform: MinGW language: cpp - image: Visual Studio 2017 + image: Visual Studio 2015 - platform: Win64 language: cpp - image: Visual Studio 2017 + image: Visual Studio 2015 BUILD_DLL: ON UNICODE: ON @@ -35,8 +35,8 @@ install: before_build: - if %platform%==MinGW set generator=MinGW Makefiles - - if %platform%==Win32 set generator=Visual Studio 15 - - if %platform%==Win64 set generator=Visual Studio 15 Win64 + - if %platform%==Win32 set generator=Visual Studio 14 + - if %platform%==Win64 set generator=Visual Studio 14 Win64 - if %platform%==Win32 set vcplatform=Win32 - if %platform%==Win64 set vcplatform=x64 diff --git a/libs/protobuf/autogen.sh b/libs/protobuf/autogen.sh new file mode 100755 index 0000000..105bf09 --- /dev/null +++ b/libs/protobuf/autogen.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# Run this script to generate the configure script and other files that will +# be included in the distribution. These files are not checked in because they +# are automatically generated. + +set -e + +if [ ! -z "$@" ]; then + for argument in "$@"; do + case $argument in + # make curl silent + "-s") + curlopts="-s" + ;; + esac + done +fi + +# Check that we're being run from the right directory. +if test ! -f src/google/protobuf/stubs/common.h; then + cat >&2 << __EOF__ +Could not find source code. Make sure you are running this script from the +root of the distribution tree. +__EOF__ + exit 1 +fi + +set -ex + +# The absence of a m4 directory in googletest causes autoreconf to fail when +# building under the CentOS docker image. It's a warning in regular build on +# Ubuntu/gLinux as well. (This is only needed if git submodules have been +# initialized, which is typically only needed for testing; see the installation +# instructions for details.) +if test -d third_party/googletest; then + mkdir -p third_party/googletest/m4 +fi + +# TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings. +autoreconf -f -i -Wall,no-obsolete + +rm -rf autom4te.cache config.h.in~ +exit 0 diff --git a/libs/protobuf/benchmarks/BUILD.bazel b/libs/protobuf/benchmarks/BUILD.bazel new file mode 100644 index 0000000..36f6283 --- /dev/null +++ b/libs/protobuf/benchmarks/BUILD.bazel @@ -0,0 +1,98 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +proto_library( + name = "benchmarks_proto", + srcs = [ + "benchmarks.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "benchmarks_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +java_proto_library( + name = "benchmarks_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "benchmarks_proto", + ], +) + +proto_library( + name = "google_size_proto", + srcs = [ + "google_size.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +cc_proto_library( + name = "google_size_cc_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) + +java_proto_library( + name = "google_size_java_proto", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "google_size_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob( + [ + "*", + "python/*.cc", + "util/*.cc", + ], + exclude = [ + "__init__.py", # not in autotools dist + "go/*", + ], + ), + strip_prefix = strip_prefix.from_root(""), +) + +# Convenience filegroup for all files that should be packaged. +pkg_filegroup( + name = "all_dist_files", + srcs = [ + ":dist_files", + "//benchmarks/cpp:dist_files", + # "//benchmarks/datasets:dist_files", # not in autotools dist + "//benchmarks/datasets/google_message1/proto2:dist_files", + "//benchmarks/datasets/google_message1/proto3:dist_files", + "//benchmarks/datasets/google_message2:dist_files", + "//benchmarks/datasets/google_message3:dist_files", + "//benchmarks/datasets/google_message4:dist_files", + ], + visibility = ["//pkg:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/Makefile.am b/libs/protobuf/benchmarks/Makefile.am new file mode 100644 index 0000000..ed57978 --- /dev/null +++ b/libs/protobuf/benchmarks/Makefile.am @@ -0,0 +1,664 @@ +benchmarks_protoc_inputs_benchmark_wrapper = \ + benchmarks.proto + +benchmarks_protoc_inputs = \ + datasets/google_message1/proto3/benchmark_message1_proto3.proto + +benchmarks_protoc_inputs_proto2 = \ + datasets/google_message1/proto2/benchmark_message1_proto2.proto \ + datasets/google_message2/benchmark_message2.proto \ + datasets/google_message3/benchmark_message3.proto \ + datasets/google_message3/benchmark_message3_1.proto \ + datasets/google_message3/benchmark_message3_2.proto \ + datasets/google_message3/benchmark_message3_3.proto \ + datasets/google_message3/benchmark_message3_4.proto \ + datasets/google_message3/benchmark_message3_5.proto \ + datasets/google_message3/benchmark_message3_6.proto \ + datasets/google_message3/benchmark_message3_7.proto \ + datasets/google_message3/benchmark_message3_8.proto \ + datasets/google_message4/benchmark_message4.proto \ + datasets/google_message4/benchmark_message4_1.proto \ + datasets/google_message4/benchmark_message4_2.proto \ + datasets/google_message4/benchmark_message4_3.proto + +make_tmp_dir: + mkdir -p 'tmp/java/src/main/java' + touch make_tmp_dir + + +# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is +# relative to srcdir, which may not be the same as the current directory when +# building out-of-tree. +protoc_middleman: make_tmp_dir $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks_protoc_inputs) $(well_known_type_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd/cpp --java_out=$$oldpwd/tmp/java/src/main/java --python_out=$$oldpwd/tmp $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) ) + touch protoc_middleman + +protoc_middleman2: make_tmp_dir $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks_protoc_inputs_proto2) $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd/cpp --java_out=$$oldpwd/tmp/java/src/main/java --python_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2) ) + touch protoc_middleman2 + +all_data = $$(find $$(cd $(srcdir) && pwd) -type f -name "dataset.*.pb" -not -path "$$(cd $(srcdir) && pwd)/tmp/*") + +############# CPP RULES ############## + +benchmarks_protoc_outputs = \ + cpp/benchmarks.pb.cc \ + cpp/datasets/google_message1/proto3/benchmark_message1_proto3.pb.cc + +benchmarks_protoc_outputs_header = \ + cpp/benchmarks.pb.h \ + cpp/datasets/google_message1/proto3/benchmark_message1_proto3.pb.h + +benchmarks_protoc_outputs_proto2_header = \ + cpp/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h \ + cpp/datasets/google_message2/benchmark_message2.pb.h \ + cpp/datasets/google_message3/benchmark_message3.pb.h \ + cpp/datasets/google_message3/benchmark_message3_1.pb.h \ + cpp/datasets/google_message3/benchmark_message3_2.pb.h \ + cpp/datasets/google_message3/benchmark_message3_3.pb.h \ + cpp/datasets/google_message3/benchmark_message3_4.pb.h \ + cpp/datasets/google_message3/benchmark_message3_5.pb.h \ + cpp/datasets/google_message3/benchmark_message3_6.pb.h \ + cpp/datasets/google_message3/benchmark_message3_7.pb.h \ + cpp/datasets/google_message3/benchmark_message3_8.pb.h \ + cpp/datasets/google_message4/benchmark_message4.pb.h \ + cpp/datasets/google_message4/benchmark_message4_1.pb.h \ + cpp/datasets/google_message4/benchmark_message4_2.pb.h \ + cpp/datasets/google_message4/benchmark_message4_3.pb.h + +benchmarks_protoc_outputs_proto2 = \ + cpp/datasets/google_message1/proto2/benchmark_message1_proto2.pb.cc \ + cpp/datasets/google_message2/benchmark_message2.pb.cc \ + cpp/datasets/google_message3/benchmark_message3.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_1.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_2.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_3.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_4.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_5.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_6.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_7.pb.cc \ + cpp/datasets/google_message3/benchmark_message3_8.pb.cc \ + cpp/datasets/google_message4/benchmark_message4.pb.cc \ + cpp/datasets/google_message4/benchmark_message4_1.pb.cc \ + cpp/datasets/google_message4/benchmark_message4_2.pb.cc \ + cpp/datasets/google_message4/benchmark_message4_3.pb.cc + + +$(benchmarks_protoc_outputs): protoc_middleman +$(benchmarks_protoc_outputs_header): protoc_middleman +$(benchmarks_protoc_outputs_proto2): protoc_middleman2 +$(benchmarks_protoc_outputs_proto2_header): protoc_middleman2 + +initialize_submodule: + oldpwd=`pwd` + cd $(top_srcdir) && git submodule update --init -r third_party/benchmark && cd third_party/benchmark \ + && cmake -DCMAKE_BUILD_TYPE=Release && make + cd $$oldpwd + touch initialize_submodule + +$(top_srcdir)/third_party/benchmark/src/libbenchmark.a: initialize_submodule + +AM_CXXFLAGS = $(NO_OPT_CXXFLAGS) $(PROTOBUF_OPT_FLAG) -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare + +bin_PROGRAMS = cpp-benchmark + +cpp_benchmark_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a +cpp_benchmark_SOURCES = cpp/cpp_benchmark.cc +cpp_benchmark_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp -I$(top_srcdir)/third_party/benchmark/include +# Explicit deps because BUILT_SOURCES are only done before a "make all/check" +# so a direct "make test_cpp" could fail if parallel enough. +# See: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html#Recording-Dependencies-manually +cpp/cpp_benchmark-cpp_benchmark.$(OBJEXT): $(benchmarks_protoc_outputs) $(benchmarks_protoc_outputs_proto2) $(benchmarks_protoc_outputs_header) $(benchmarks_protoc_outputs_proto2_header) $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a +cpp/benchmark-cpp_benchmark.$(OBJEXT): $(benchmarks_protoc_outputs) $(benchmarks_protoc_outputs_proto2) $(benchmarks_protoc_outputs_header) $(benchmarks_protoc_outputs_proto2_header) $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a +nodist_cpp_benchmark_SOURCES = \ + $(benchmarks_protoc_outputs) \ + $(benchmarks_protoc_outputs_proto2) \ + $(benchmarks_protoc_outputs_proto2_header) \ + $(benchmarks_protoc_outputs_header) + +cpp: protoc_middleman protoc_middleman2 cpp-benchmark initialize_submodule + ./cpp-benchmark $(all_data) + +############ CPP RULES END ############ + +############# JAVA RULES ############## + +java_benchmark_testing_files = \ + java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java + +javac_middleman: $(java_benchmark_testing_files) protoc_middleman protoc_middleman2 + cp -r $(srcdir)/java tmp + mkdir -p tmp/java/lib + cp $(top_srcdir)/java/core/target/*.jar tmp/java/lib/protobuf-java.jar + cd tmp/java && mvn clean compile assembly:single -Dprotobuf.version=$(PACKAGE_VERSION) && cd ../.. + @touch javac_middleman + +java-benchmark: javac_middleman + @echo "Writing shortcut script java-benchmark..." + @echo '#! /bin/bash' > java-benchmark + @echo 'all_data=""' >> java-benchmark + @echo 'conf=()' >> java-benchmark + @echo 'data_files=""' >> java-benchmark + @echo 'for arg in $$@; do if [[ $${arg:0:1} == "-" ]]; then conf+=($$arg); else data_files+="$$arg,"; fi; done' >> java-benchmark + @echo 'java -cp '\"tmp/java/target/*:$(top_srcdir)/java/core/target/*:$(top_srcdir)/java/util/target/*\"" \\" >>java-benchmark + @echo ' com.google.caliper.runner.CaliperMain com.google.protobuf.ProtoCaliperBenchmark -i runtime '"\\" >> java-benchmark + @echo ' -b serializeToByteArray,serializeToMemoryStream,deserializeFromByteArray,deserializeFromMemoryStream '"\\" >> java-benchmark + @echo ' -DdataFile=$${data_files:0:-1} $${conf[*]}' >> java-benchmark + @chmod +x java-benchmark + +java: protoc_middleman protoc_middleman2 java-benchmark + ./java-benchmark $(all_data) + +############# JAVA RULES END ############## + + +############# PYTHON RULES ############## + +python_add_init: protoc_middleman protoc_middleman2 + all_file=`find tmp -type f -regex '.*\.py'` && \ + for file in $${all_file[@]}; do \ + path="$${file%/*}"; \ + while true; do \ + touch "$$path/__init__.py" && chmod +x "$$path/__init__.py"; \ + if [[ $$path != *"/"* ]]; then break; fi; \ + path=$${path%/*}; \ + done \ + done + +python_cpp_pkg_flags = `pkg-config --cflags --libs python3` + +lib_LTLIBRARIES = libbenchmark_messages.la +libbenchmark_messages_la_SOURCES = python/python_benchmark_messages.cc +libbenchmark_messages_la_LIBADD = $(top_srcdir)/src/.libs/libprotobuf.la +libbenchmark_messages_la_LDFLAGS = -version-info 1:0:0 -export-dynamic +libbenchmark_messages_la_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp $(python_cpp_pkg_flags) +libbenchmark_messages_la-python_benchmark_messages.$(OBJEXT): $(benchmarks_protoc_outputs_header) $(benchmarks_protoc_outputs_proto2_header) $(benchmarks_protoc_outputs) $(benchmarks_protoc_outputs_proto2) +nodist_libbenchmark_messages_la_SOURCES = \ + $(benchmarks_protoc_outputs) \ + $(benchmarks_protoc_outputs_proto2) \ + $(benchmarks_protoc_outputs_proto2_header) \ + $(benchmarks_protoc_outputs_header) + +python-pure-python-benchmark: python_add_init + @echo "Writing shortcut script python-pure-python-benchmark..." + @echo '#! /bin/bash' > python-pure-python-benchmark + @echo export LD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-pure-python-benchmark + @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-pure-python-benchmark + @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'python\' >> python-pure-python-benchmark + @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-pure-python-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-pure-python-benchmark + @chmod +x python-pure-python-benchmark + +python-cpp-reflection-benchmark: python_add_init + @echo "Writing shortcut script python-cpp-reflection-benchmark..." + @echo '#! /bin/bash' > python-cpp-reflection-benchmark + @echo export LD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-reflection-benchmark + @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-reflection-benchmark + @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-reflection-benchmark + @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-reflection-benchmark + @echo python3 tmp/py_benchmark.py '$$@' >> python-cpp-reflection-benchmark + @chmod +x python-cpp-reflection-benchmark + +python-cpp-generated-code-benchmark: python_add_init libbenchmark_messages.la + @echo "Writing shortcut script python-cpp-generated-code-benchmark..." + @echo '#! /bin/bash' > python-cpp-generated-code-benchmark + @echo export LD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-generated-code-benchmark + @echo export DYLD_LIBRARY_PATH=$(top_srcdir)/src/.libs >> python-cpp-generated-code-benchmark + @echo export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=\'cpp\' >> python-cpp-generated-code-benchmark + @echo cp $(srcdir)/python/py_benchmark.py tmp >> python-cpp-generated-code-benchmark + @echo python3 tmp/py_benchmark.py --cpp_generated '$$@' >> python-cpp-generated-code-benchmark + @chmod +x python-cpp-generated-code-benchmark + +python-pure-python: python-pure-python-benchmark + ./python-pure-python-benchmark $(all_data) + +python-cpp-reflection: python-cpp-reflection-benchmark + ./python-cpp-reflection-benchmark $(all_data) + +python-cpp-generated-code: python-cpp-generated-code-benchmark + ./python-cpp-generated-code-benchmark $(all_data) + +############# PYTHON RULES END ############## + +############# GO RULES BEGIN ############## + +benchmarks_protoc_inputs_proto2_message1 = \ + datasets/google_message1/proto2/benchmark_message1_proto2.proto + +benchmarks_protoc_inputs_proto2_message2 = \ + datasets/google_message2/benchmark_message2.proto + +benchmarks_protoc_inputs_proto2_message3 = \ + datasets/google_message3/benchmark_message3.proto \ + datasets/google_message3/benchmark_message3_1.proto \ + datasets/google_message3/benchmark_message3_2.proto \ + datasets/google_message3/benchmark_message3_3.proto \ + datasets/google_message3/benchmark_message3_4.proto \ + datasets/google_message3/benchmark_message3_5.proto \ + datasets/google_message3/benchmark_message3_6.proto \ + datasets/google_message3/benchmark_message3_7.proto \ + datasets/google_message3/benchmark_message3_8.proto + +benchmarks_protoc_inputs_proto2_message4 = \ + datasets/google_message4/benchmark_message4.proto \ + datasets/google_message4/benchmark_message4_1.proto \ + datasets/google_message4/benchmark_message4_2.proto \ + datasets/google_message4/benchmark_message4_3.proto + +go_protoc_middleman: make_tmp_dir $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks_protoc_inputs) $(well_known_type_protoc_inputs) $(benchmarks_protoc_inputs_proto2_message1) $(benchmarks_protoc_inputs_proto2_message2) $(benchmarks_protoc_inputs_proto2_message3) $(benchmarks_protoc_inputs_proto2_message4) $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --go_out=$$oldpwd/tmp $(benchmarks_protoc_inputs_proto2_message4) ) + touch go_protoc_middleman + +go-benchmark: go_protoc_middleman + @echo "Writing shortcut script go-benchmark..." + @echo '#! /bin/bash' > go-benchmark + @echo 'cd $(srcdir)/go' >> go-benchmark + @echo 'all_data=""' >> go-benchmark + @echo 'conf=()' >> go-benchmark + @echo 'data_files=()' >> go-benchmark + @echo 'for arg in $$@; do if [[ $${arg:0:1} == "-" ]]; then conf+=($$arg); else data_files+=("$$arg"); fi; done' >> go-benchmark + @echo 'go test -bench=. $${conf[*]} -- $${data_files[*]}' >> go-benchmark + @echo 'cd ..' >> go-benchmark + @chmod +x go-benchmark + +go: go_protoc_middleman go-benchmark + ./go-benchmark $(all_data) + +############# GO RULES END ############## + +############# GOGO RULES BEGIN ############ + +cpp_no_group_benchmarks_protoc_outputs_header = \ + gogo/cpp_no_group/benchmarks.pb.h \ + gogo/cpp_no_group/datasets/google_message1/proto3/benchmark_message1_proto3.pb.h + +cpp_no_group_benchmarks_protoc_outputs = \ + gogo/cpp_no_group/benchmarks.pb.cc \ + gogo/cpp_no_group/datasets/google_message1/proto3/benchmark_message1_proto3.pb.cc + +cpp_no_group_benchmarks_protoc_outputs_proto2_header = \ + gogo/cpp_no_group/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h \ + gogo/cpp_no_group/datasets/google_message2/benchmark_message2.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_1.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_2.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_3.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_4.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_5.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_6.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_7.pb.h \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_8.pb.h \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4.pb.h \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_1.pb.h \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_2.pb.h \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_3.pb.h + +cpp_no_group_benchmarks_protoc_outputs_proto2 = \ + gogo/cpp_no_group/datasets/google_message1/proto2/benchmark_message1_proto2.pb.cc \ + gogo/cpp_no_group/datasets/google_message2/benchmark_message2.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_1.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_2.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_3.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_4.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_5.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_6.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_7.pb.cc \ + gogo/cpp_no_group/datasets/google_message3/benchmark_message3_8.pb.cc \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4.pb.cc \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_1.pb.cc \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_2.pb.cc \ + gogo/cpp_no_group/datasets/google_message4/benchmark_message4_3.pb.cc + +$(cpp_no_group_benchmarks_protoc_outputs): cpp_no_group_protoc_middleman +$(cpp_no_group_benchmarks_protoc_outputs_header): cpp_no_group_protoc_middleman +$(cpp_no_group_benchmarks_protoc_outputs_proto2): cpp_no_group_protoc_middleman +$(cpp_no_group_benchmarks_protoc_outputs_proto2_header): cpp_no_group_protoc_middleman + +generate_cpp_no_group_benchmark_code: + cp $(srcdir)/cpp/cpp_benchmark.cc gogo/cpp_no_group/cpp_benchmark.cc + sed -i -e "s/\#include \"datasets/\#include \"gogo\/cpp_no_group\/datasets/g" gogo/cpp_no_group/cpp_benchmark.cc + sed -i -e "s/\#include \"benchmarks.pb.h/\#include \"gogo\/cpp_no_group\/benchmarks.pb.h/g" gogo/cpp_no_group/cpp_benchmark.cc + touch generate_cpp_no_group_benchmark_code + +bin_PROGRAMS += cpp-no-group-benchmark +cpp_no_group_benchmark_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a +cpp_no_group_benchmark_SOURCES = gogo/cpp_no_group/cpp_benchmark.cc +cpp_no_group_benchmark_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/gogo/cpp_no_group -I$(top_srcdir)/third_party/benchmark/include +# Explicit deps because BUILT_SOURCES are only done before a "make all/check" +# so a direct "make test_cpp" could fail if parallel enough. +# See: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html#Recording-Dependencies-manually +gogo/cpp_no_group/cpp_no_group_benchmark-cpp_benchmark.$(OBJEXT): $(cpp_no_group_benchmarks_protoc_outputs) $(cpp_no_group_benchmarks_protoc_outputs_proto2) $(cpp_no_group_benchmarks_protoc_outputs_header) \ + $(cpp_no_group_benchmarks_protoc_outputs_proto2_header) $(top_srcdir)/third_party/benchmark/src/libbenchmark.a generate_cpp_no_group_benchmark_code +gogo/cpp_no_group/cpp_benchmark.cc: generate_cpp_no_group_benchmark_code +nodist_cpp_no_group_benchmark_SOURCES = \ + $(cpp_no_group_benchmarks_protoc_outputs_proto2) \ + $(cpp_no_group_benchmarks_protoc_outputs) \ + $(cpp_no_group_benchmarks_protoc_outputs_header) \ + $(cpp_no_group_benchmarks_protoc_outputs_proto2_header) + +cpp_no_group: cpp_no_group_protoc_middleman generate_gogo_data cpp-no-group-benchmark + ./cpp-no-group-benchmark $(gogo_data) + +gogo_proto_middleman: protoc-gen-gogoproto + mkdir -p "tmp/gogo_proto" + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I$(srcdir) -I$(top_srcdir) --plugin=protoc-gen-gogoproto --gogoproto_out=$$oldpwd/tmp/gogo_proto $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2) ) + touch gogo_proto_middleman + +gogo_data = $$(for data in $(all_data); do echo "tmp/gogo_data$${data\#$(srcdir)}"; done | xargs) + +generate_gogo_data: protoc_middleman protoc_middleman2 gogo-data-scrubber + mkdir -p `dirname $(gogo_data)` + ./gogo-data-scrubber $(all_data) $(gogo_data) + touch generate_gogo_data + +make_tmp_dir_gogo: + mkdir -p tmp/go_no_group/benchmark_code + mkdir -p tmp/gogofast/benchmark_code + mkdir -p tmp/gogofaster/benchmark_code + mkdir -p tmp/gogoslick/benchmark_code + touch make_tmp_dir_gogo + +go_no_group_protoc_middleman: make_tmp_dir_gogo $(top_srcdir)/src/protoc$(EXEEXT) gogo_proto_middleman $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --go_out=$$oldpwd/tmp/go_no_group $(benchmarks_protoc_inputs_proto2_message4) ) + touch go_no_group_protoc_middleman + +cpp_no_group_protoc_middleman: make_tmp_dir_gogo $(top_srcdir)/src/protoc$(EXEEXT) gogo_proto_middleman $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --cpp_out=$$oldpwd/gogo/cpp_no_group $(benchmarks_protoc_inputs_proto2_message4) ) + touch cpp_no_group_protoc_middleman + +gogofast_protoc_middleman: make_tmp_dir_gogo $(top_srcdir)/src/protoc$(EXEEXT) gogo_proto_middleman $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofast_out=$$oldpwd/tmp/gogofast $(benchmarks_protoc_inputs_proto2_message4) ) + touch gogofast_protoc_middleman + +gogofaster_protoc_middleman: make_tmp_dir_gogo $(top_srcdir)/src/protoc$(EXEEXT) gogo_proto_middleman $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogofaster_out=$$oldpwd/tmp/gogofaster $(benchmarks_protoc_inputs_proto2_message4) ) + touch gogofaster_protoc_middleman + +gogoslick_protoc_middleman: make_tmp_dir_gogo $(top_srcdir)/src/protoc$(EXEEXT) gogo_proto_middleman $(well_known_type_protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs_benchmark_wrapper) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs_proto2_message1) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs_proto2_message2) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs_proto2_message3) ) + oldpwd=`pwd` && ( cd $(srcdir)/tmp/gogo_proto && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$$oldpwd/$(top_srcdir)/src --gogoslick_out=$$oldpwd/tmp/gogoslick $(benchmarks_protoc_inputs_proto2_message4) ) + touch gogoslick_protoc_middleman + +generate-gogo-benchmark-code: + @echo '#! /bin/bash' > generate-gogo-benchmark-code + @echo 'cp $(srcdir)/go/go_benchmark_test.go tmp/$$1/benchmark_code/$$1_benchmark1_test.go' >> generate-gogo-benchmark-code + @echo 'sed -i -e "s/\.\.\/tmp/../g" tmp/$$1/benchmark_code/$$1_benchmark1_test.go' >> generate-gogo-benchmark-code + @echo 'sed -i -e "s/b\.Run(\"\(.*\)\"/b.Run(\"\1\_$$1\"/g" tmp/$$1/benchmark_code/$$1_benchmark1_test.go' >> generate-gogo-benchmark-code + @echo 'if [[ $$2 == 1 ]]; then sed -i -e "s/github\.com\/golang/github.com\/gogo/g" tmp/$$1/benchmark_code/$$1_benchmark1_test.go; fi ' >> generate-gogo-benchmark-code + @chmod +x generate-gogo-benchmark-code + +generate_all_gogo_benchmark_code: generate-gogo-benchmark-code make_tmp_dir_gogo + ./generate-gogo-benchmark-code go_no_group 0 + ./generate-gogo-benchmark-code gogofast 1 + ./generate-gogo-benchmark-code gogofaster 1 + ./generate-gogo-benchmark-code gogoslick 1 + +gogo-benchmark: + @echo "Writing shortcut script gogo-benchmark..." + @echo '#! /bin/bash' > gogo-benchmark + @echo 'cd tmp/$$1/benchmark_code' >> gogo-benchmark + @echo 'shift' >> gogo-benchmark + @echo 'all_data=""' >> gogo-benchmark + @echo 'for data_file in $$@; do all_data="$$all_data ../../../$$data_file"; done' >> gogo-benchmark + @echo 'go test -bench=. -- $$all_data' >> gogo-benchmark + @echo 'cd ../..' >> gogo-benchmark + @chmod +x gogo-benchmark + +go_no_group: go_no_group_protoc_middleman generate_gogo_data generate_all_gogo_benchmark_code gogo-benchmark + ./gogo-benchmark go_no_group $(gogo_data) + +gogofast: gogofast_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code + ./gogo-benchmark gogofast $(gogo_data) + +gogofaster: gogofaster_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code + ./gogo-benchmark gogofaster $(gogo_data) + +gogoslick: gogoslick_protoc_middleman generate_gogo_data gogo-benchmark generate_all_gogo_benchmark_code + ./gogo-benchmark gogoslick $(gogo_data) + + +############# GOGO RULES END ############ + + +############ UTIL RULES BEGIN ############ + +bin_PROGRAMS += protoc-gen-gogoproto gogo-data-scrubber protoc-gen-proto2_to_proto3 proto3-data-stripper + +protoc_gen_gogoproto_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/src/libprotoc.la +protoc_gen_gogoproto_SOURCES = util/protoc-gen-gogoproto.cc +protoc_gen_gogoproto_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp -I$(srcdir)/util + +gogo_data_scrubber_LDADD = $(top_srcdir)/src/libprotobuf.la +gogo_data_scrubber_SOURCES = util/gogo_data_scrubber.cc +gogo_data_scrubber_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp -I$(srcdir)/util +util/gogo_data_scrubber-gogo_data_scrubber.$(OBJEXT): $(benchmarks_protoc_outputs) $(benchmarks_protoc_outputs_proto2) $(benchmarks_protoc_outputs_header) $(benchmarks_protoc_outputs_proto2_header) +nodist_gogo_data_scrubber_SOURCES = \ + $(benchmarks_protoc_outputs) \ + $(benchmarks_protoc_outputs_proto2) \ + $(benchmarks_protoc_outputs_proto2_header) \ + $(benchmarks_protoc_outputs_header) + +protoc_gen_proto2_to_proto3_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/src/libprotoc.la +protoc_gen_proto2_to_proto3_SOURCES = util/protoc-gen-proto2_to_proto3.cc +protoc_gen_proto2_to_proto3_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp -I$(srcdir)/util + +proto3_data_stripper_LDADD = $(top_srcdir)/src/libprotobuf.la +proto3_data_stripper_SOURCES = util/proto3_data_stripper.cc +proto3_data_stripper_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)/cpp -I$(srcdir)/util +util/proto3_data_stripper-proto3_data_stripper.$(OBJEXT): $(benchmarks_protoc_outputs) $(benchmarks_protoc_outputs_proto2) $(benchmarks_protoc_outputs_header) $(benchmarks_protoc_outputs_proto2_header) +nodist_proto3_data_stripper_SOURCES = \ + $(benchmarks_protoc_outputs) \ + $(benchmarks_protoc_outputs_proto2) \ + $(benchmarks_protoc_outputs_proto2_header) \ + $(benchmarks_protoc_outputs_header) + + +############ UTIL RULES END ############ + +############ PROTO3 PREPARATION BEGIN ############# + +proto3_proto_middleman: protoc-gen-proto2_to_proto3 + mkdir -p "tmp/proto3_proto" + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I$(srcdir) -I$(top_srcdir) --plugin=protoc-gen-proto2_to_proto3 --proto2_to_proto3_out=$$oldpwd/tmp/proto3_proto $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2) ) + touch proto3_proto_middleman + +full_srcdir = $$(cd $(srcdir) && pwd) +proto3_data = $$(for data in $(all_data); do echo $(full_srcdir)"/tmp/proto3_data$${data\#$(full_srcdir)}"; done | xargs) + +generate_proto3_data: protoc_middleman protoc_middleman2 proto3-data-stripper + mkdir -p `dirname $(proto3_data)` + ./proto3-data-stripper $(all_data) $(proto3_data) + touch generate_proto3_data + +############ PROTO3 PREPARATION END ############# + +############ PHP RULES BEGIN ################# + +proto3_middleman_php: proto3_proto_middleman + mkdir -p "tmp/php" + oldpwd=`pwd` && ( cd tmp/proto3_proto && $$oldpwd/../src/protoc$(EXEEXT) -I$(srcdir) -I$(top_srcdir) --php_out=$$oldpwd/tmp/php $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2) ) + touch proto3_middleman_php + +php-benchmark: proto3_middleman_php generate_proto3_data + mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" + cp php/autoload.php "tmp/php" + @echo "Writing shortcut script php-benchmark..." + @echo '#! /bin/bash' > php-benchmark + @echo 'export PROTOBUF_PHP_SRCDIR="$$(cd $(top_srcdir) && pwd)/php/src"' >> php-benchmark + @echo 'cd tmp/php' >> php-benchmark + @echo 'export CURRENT_DIR=$$(pwd)' >> php-benchmark + @echo 'php -d auto_prepend_file="autoload.php" -d include_path="$$(pwd)" Google/Protobuf/Benchmark/PhpBenchmark.php $$@' >> php-benchmark + @echo 'cd ../..' >> php-benchmark + @chmod +x php-benchmark + +php: php-benchmark proto3_middleman_php + ./php-benchmark --behavior_prefix="php" $(proto3_data) + +php_c_extension: + cd $(top_srcdir)/php/ext/google/protobuf && phpize && ./configure CFLAGS='-O3' && make -j8 + +php-c-benchmark: proto3_middleman_php generate_proto3_data php_c_extension php_c_extension + mkdir -p "tmp/php/Google/Protobuf/Benchmark" && cp php/PhpBenchmark.php "tmp/php/Google/Protobuf/Benchmark" + cp php/autoload.php "tmp/php" + @echo "Writing shortcut script php-c-benchmark..." + @echo '#! /bin/bash' > php-c-benchmark + @echo 'export PROTOBUF_PHP_SRCDIR="$$(cd $(top_srcdir) && pwd)/php/src"' >> php-c-benchmark + @echo 'export PROTOBUF_PHP_EXTDIR="$$PROTOBUF_PHP_SRCDIR/../ext/google/protobuf/modules"' >> php-c-benchmark + @echo 'cd tmp/php' >> php-c-benchmark + @echo 'export CURRENT_DIR=$$(pwd)' >> php-c-benchmark + @echo 'php -d auto_prepend_file="autoload.php" -d include_path="$$(pwd)" -d extension="$$PROTOBUF_PHP_EXTDIR/protobuf.so" Google/Protobuf/Benchmark/PhpBenchmark.php $$@' >> php-c-benchmark + @echo 'cd ../..' >> php-c-benchmark + @chmod +x php-c-benchmark + +php_c: php-c-benchmark proto3_middleman_php + ./php-c-benchmark --behavior_prefix="php_c" $(proto3_data) + + +############ PHP RULES END ################# + +############ protobuf.js RULE BEGIN ############# + +pbjs_preparation: + mkdir -p tmp/protobuf.js + cd tmp/protobuf.js && git clone https://github.com/dcodeIO/protobuf.js.git && \ + cd protobuf.js && npm install && npm run build + cd tmp/protobuf.js && npm install benchmark + cp protobuf.js/* tmp/protobuf.js + cp js/benchmark_suite.js tmp/protobuf.js + touch pbjs_preparation + +pbjs_middleman: pbjs_preparation + export OLDDIR=$$(pwd) && cd tmp/protobuf.js && node generate_pbjs_files.js --target static-module --include_path=$$OLDDIR -o generated_bundle_code.js $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2) + touch pbjs_middleman + +pbjs-benchmark: pbjs_middleman + @echo '#! /bin/bash' > pbjs-benchmark + @echo 'cd tmp/protobuf.js' >> pbjs-benchmark + @echo 'sed -i "s/protobufjs/.\/protobuf.js/g" generated_bundle_code.js' >> pbjs-benchmark + @echo 'env NODE_PATH=".:./node_modules:$$NODE_PATH" node protobufjs_benchmark.js $$@' >> pbjs-benchmark + @chmod +x pbjs-benchmark + +pbjs: pbjs-benchmark + ./pbjs-benchmark $(all_data) + +############ protobuf.js RULE END ############# + +############ JS RULE BEGIN ############# + +js_preparation: + mkdir -p tmp/js + oldpwd=$$(pwd) && cd $(top_srcdir)/js && npm install && npm test + cd tmp/js && npm install benchmark + cp js/* tmp/js + touch js_preparation + +js_middleman: js_preparation + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --js_out=import_style=commonjs,binary:$$oldpwd/tmp/js $(benchmarks_protoc_inputs) $(benchmarks_protoc_inputs_benchmark_wrapper) $(benchmarks_protoc_inputs_proto2)) + touch js_middleman + +js-benchmark: js_middleman + @echo '#! /bin/bash' > js-benchmark + @echo 'export TOP_JS_SRCDIR=$$(cd $(top_srcdir)/js && pwd)' >> js-benchmark + @echo 'cd tmp/js' >> js-benchmark + @echo 'env NODE_PATH="$$TOP_JS_SRCDIR:.:./node_modules:$$NODE_PATH" node --max-old-space-size=4096 js_benchmark.js $$@' >> js-benchmark + @chmod +x js-benchmark + +js: js-benchmark + ./js-benchmark $(all_data) + +############ JS RULE END ############# + +EXTRA_DIST = \ + $(benchmarks_protoc_inputs_benchmark_wrapper) \ + $(benchmarks_protoc_inputs) \ + $(benchmarks_protoc_inputs_proto2) \ + google_size.proto + +MAINTAINERCLEANFILES = \ + Makefile.in + +CLEANFILES = \ + $(benchmarks_protoc_outputs) \ + $(benchmarks_protoc_outputs_header) \ + $(benchmarks_protoc_outputs_proto2) \ + $(benchmarks_protoc_outputs_proto2_header) \ + initialize_submodule \ + make_tmp_dir \ + protoc_middleman \ + protoc_middleman2 \ + javac_middleman \ + java-benchmark \ + python_cpp_proto_library \ + python-pure-python-benchmark \ + python-cpp-reflection-benchmark \ + python-cpp-generated-code-benchmark \ + go-benchmark \ + go_protoc_middleman \ + make_tmp_dir_gogo \ + gogo_proto_middleman \ + generate_gogo_data \ + go_no_group_protoc_middleman \ + go_no_group \ + go-no-group-benchmark \ + $(cpp_no_group_benchmarks_protoc_outputs_header) \ + $(cpp_no_group_benchmarks_protoc_outputs) \ + $(cpp_no_group_benchmarks_protoc_outputs_proto2_header) \ + $(cpp_no_group_benchmarks_protoc_outputs_proto2) \ + generate_all_gogo_benchmark_code \ + generate-gogo-benchmark-code \ + cpp_no_group_protoc_middleman \ + generate_cpp_no_group_benchmark_code \ + generate_gogo_benchmark_code \ + gogofast_protoc_middleman \ + gogofast \ + gogofaster_protoc_middleman \ + gogofaster \ + gogoslick_protoc_middleman \ + gogoslick \ + gogo-benchmark \ + gogo/cpp_no_group/cpp_benchmark.* \ + proto3_proto_middleman \ + generate_proto3_data \ + php-benchmark \ + php-c-benchmark \ + proto3_middleman_php \ + pbjs_preparation \ + pbjs_middleman \ + pbjs-benchmark \ + js_preparation \ + js_middleman \ + js-benchmark + +clean-local: + -rm -rf tmp/* + diff --git a/libs/protobuf/benchmarks/README.md b/libs/protobuf/benchmarks/README.md new file mode 100644 index 0000000..70c3596 --- /dev/null +++ b/libs/protobuf/benchmarks/README.md @@ -0,0 +1,239 @@ + +# Protocol Buffers Benchmarks + +This directory contains benchmarking schemas and data sets that you +can use to test a variety of performance scenarios against your +protobuf language runtime. If you are looking for performance +numbers of officially supported languages, see [Protobuf Performance]( +https://github.com/protocolbuffers/protobuf/blob/main/docs/performance.md). + +## Prerequisite + +First, you need to follow the instruction in the root directory's README to +build your language's protobuf, then: + +### CPP +You need to install [cmake](https://cmake.org/) before building the benchmark. + +We are using [google/benchmark](https://github.com/google/benchmark) as the +benchmark tool for testing cpp. This will be automatically made during build the +cpp benchmark. + +The cpp protobuf performance can be improved by linking with +[TCMalloc](https://google.github.io/tcmalloc). + +### Java +We're using maven to build the java benchmarks, which is the same as to build +the Java protobuf. There're no other tools need to install. We're using +[google/caliper](https://github.com/google/caliper) as benchmark tool, which +can be automatically included by maven. + +### Python +We're using python C++ API for testing the generated +CPP proto version of python protobuf, which is also a prerequisite for Python +protobuf cpp implementation. You need to install the correct version of Python +C++ extension package before run generated CPP proto version of Python +protobuf's benchmark. e.g. under Ubuntu, you need to + +``` +$ sudo apt-get install python-dev +$ sudo apt-get install python3-dev +``` +And you also need to make sure `pkg-config` is installed. + +### Go +Go protobufs are maintained at [github.com/golang/protobuf]( +http://github.com/golang/protobuf). If not done already, you need to install the +toolchain and the Go protoc-gen-go plugin for protoc. + +To install protoc-gen-go, run: + +``` +$ go get -u github.com/golang/protobuf/protoc-gen-go +$ export PATH=$PATH:$(go env GOPATH)/bin +``` + +The first command installs `protoc-gen-go` into the `bin` directory in your local `GOPATH`. +The second command adds the `bin` directory to your `PATH` so that `protoc` can locate the plugin later. + +### PHP +PHP benchmark's requirement is the same as PHP protobuf's requirements. The benchmark will automatically +include PHP protobuf's src and build the c extension if required. + +### Node.js +Node.js benchmark need [node](https://nodejs.org/en/)(higher than V6) and [npm](https://www.npmjs.com/) package manager installed. This benchmark is using the [benchmark](https://www.npmjs.com/package/benchmark) framework to test, which needn't to manually install. And another prerequisite is [protobuf js](https://github.com/protocolbuffers/protobuf/tree/main/js), which needn't to manually install either + +### C# +The C# benchmark code is built as part of the main Google.Protobuf +solution. It requires the .NET Core SDK, and depends on +[BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet), which +will be downloaded automatically. + +## Run instructions + +To run all the benchmark dataset: + +### Java: + +First build the Java binary in the usual way with Maven: + +``` +$ cd java +$ mvn install +``` + +Assuming that completes successfully, + +``` +$ cd ../benchmarks +$ make java +``` + +### CPP: + +``` +$ make cpp +``` + +For linking with tcmalloc: + +``` +$ env LD_PRELOAD={directory to libtcmalloc.so} make cpp +``` + +### Python: + +We have three versions of python protobuf implementation: pure python, cpp +reflection and cpp generated code. To run these version benchmark, you need to: + +#### Pure Python: + +``` +$ make python-pure-python +``` + +#### CPP reflection: + +``` +$ make python-cpp-reflection +``` + +#### CPP generated code: + +``` +$ make python-cpp-generated-code +``` + +### Go +``` +$ make go +``` + + +### PHP +We have two version of php protobuf implementation: pure php, php with c extension. To run these version benchmark, you need to: +#### Pure PHP +``` +$ make php +``` +#### PHP with c extension +``` +$ make php_c +``` + +### Node.js +``` +$ make js +``` + +To run a specific dataset or run with specific options: + +### Java: + +``` +$ make java-benchmark +$ ./java-benchmark $(specific generated dataset file name) [$(caliper options)] +``` + +### CPP: + +``` +$ make cpp-benchmark +$ ./cpp-benchmark $(specific generated dataset file name) [$(benchmark options)] +``` + +### Python: + +For Python benchmark we have `--json` for outputting the json result + +#### Pure Python: + +``` +$ make python-pure-python-benchmark +$ ./python-pure-python-benchmark [--json] $(specific generated dataset file name) +``` + +#### CPP reflection: + +``` +$ make python-cpp-reflection-benchmark +$ ./python-cpp-reflection-benchmark [--json] $(specific generated dataset file name) +``` + +#### CPP generated code: + +``` +$ make python-cpp-generated-code-benchmark +$ ./python-cpp-generated-code-benchmark [--json] $(specific generated dataset file name) +``` + +### Go: +``` +$ make go-benchmark +$ ./go-benchmark $(specific generated dataset file name) [go testing options] +``` + +### PHP +#### Pure PHP +``` +$ make php-benchmark +$ ./php-benchmark $(specific generated dataset file name) +``` +#### PHP with c extension +``` +$ make php-c-benchmark +$ ./php-c-benchmark $(specific generated dataset file name) +``` + +### Node.js +``` +$ make js-benchmark +$ ./js-benchmark $(specific generated dataset file name) +``` + +### C# +From `csharp/src/Google.Protobuf.Benchmarks`, run: + +``` +$ dotnet run -c Release +``` + +We intend to add support for this within the makefile in due course. + +## Benchmark datasets + +Each data set is in the format of benchmarks.proto: + +1. name is the benchmark dataset's name. +2. message_name is the benchmark's message type full name (including package and message name) +3. payload is the list of raw data. + +The schema for the datasets is described in `benchmarks.proto`. + +Benchmark likely want to run several benchmarks against each data set (parse, +serialize, possibly JSON, possibly using different APIs, etc). + +We would like to add more data sets. In general we will favor data sets +that make the overall suite diverse without being too large or having +too many similar tests. Ideally everyone can run through the entire +suite without the test run getting too long. diff --git a/libs/protobuf/benchmarks/__init__.py b/libs/protobuf/benchmarks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/libs/protobuf/benchmarks/benchmarks.proto b/libs/protobuf/benchmarks/benchmarks.proto new file mode 100644 index 0000000..51c0b54 --- /dev/null +++ b/libs/protobuf/benchmarks/benchmarks.proto @@ -0,0 +1,63 @@ +// 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. + +syntax = "proto3"; +package benchmarks; +option java_package = "com.google.protobuf.benchmarks"; + +message BenchmarkDataset { + // Name of the benchmark dataset. This should be unique across all datasets. + // Should only contain word characters: [a-zA-Z0-9_] + string name = 1; + + // Fully-qualified name of the protobuf message for this dataset. + // It will be one of the messages defined benchmark_messages_proto2.proto + // or benchmark_messages_proto3.proto. + // + // Implementations that do not support reflection can implement this with + // an explicit "if/else" chain that lists every known message defined + // in those files. + string message_name = 2; + + // The payload(s) for this dataset. They should be parsed or serialized + // in sequence, in a loop, ie. + // + // while (!benchmarkDone) { // Benchmark runner decides when to exit. + // for (i = 0; i < benchmark.payload.length; i++) { + // parse(benchmark.payload[i]) + // } + // } + // + // This is intended to let datasets include a variety of data to provide + // potentially more realistic results than just parsing the same message + // over and over. A single message parsed repeatedly could yield unusually + // good branch prediction performance. + repeated bytes payload = 3; +} diff --git a/libs/protobuf/benchmarks/cpp/BUILD.bazel b/libs/protobuf/benchmarks/cpp/BUILD.bazel new file mode 100644 index 0000000..7a3d3ba --- /dev/null +++ b/libs/protobuf/benchmarks/cpp/BUILD.bazel @@ -0,0 +1,26 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +cc_binary( + name = "cpp", + srcs = [ + "cpp_benchmark.cc", + ], + tags = ["benchmark"], + deps = [ + "//:protobuf", + "//benchmarks:benchmarks_cc_proto", + "//benchmarks/datasets:cc_protos", + "@com_github_google_benchmark//:benchmark_main", + ], +) + +pkg_files( + name = "dist_files", + srcs = [ + "BUILD.bazel", + "cpp_benchmark.cc", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/cpp/cpp_benchmark.cc b/libs/protobuf/benchmarks/cpp/cpp_benchmark.cc new file mode 100644 index 0000000..036d234 --- /dev/null +++ b/libs/protobuf/benchmarks/cpp/cpp_benchmark.cc @@ -0,0 +1,254 @@ +// 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 +#include +#include "benchmark/benchmark.h" +#include "benchmarks.pb.h" +#include "datasets/google_message1/proto2/benchmark_message1_proto2.pb.h" +#include "datasets/google_message1/proto3/benchmark_message1_proto3.pb.h" +#include "datasets/google_message2/benchmark_message2.pb.h" +#include "datasets/google_message3/benchmark_message3.pb.h" +#include "datasets/google_message4/benchmark_message4.pb.h" + + +#define PREFIX "dataset." +#define SUFFIX ".pb" + +using benchmarks::BenchmarkDataset; +using google::protobuf::Arena; +using google::protobuf::Descriptor; +using google::protobuf::DescriptorPool; +using google::protobuf::Message; +using google::protobuf::MessageFactory; + +class Fixture : public benchmark::Fixture { + public: + Fixture(const BenchmarkDataset& dataset, const std::string& suffix) { + for (int i = 0; i < dataset.payload_size(); i++) { + payloads_.push_back(dataset.payload(i)); + } + + const Descriptor* d = + DescriptorPool::generated_pool()->FindMessageTypeByName( + dataset.message_name()); + + if (!d) { + std::cerr << "Couldn't find message named '" << dataset.message_name() + << "\n"; + } + + prototype_ = MessageFactory::generated_factory()->GetPrototype(d); + SetName((dataset.name() + suffix).c_str()); + } + + protected: + std::vector payloads_; + const Message* prototype_; +}; + +class WrappingCounter { + public: + WrappingCounter(size_t limit) : value_(0), limit_(limit) {} + + size_t Next() { + size_t ret = value_; + if (++value_ == limit_) { + value_ = 0; + } + return ret; + } + + private: + size_t value_; + size_t limit_; +}; + +template +class ParseNewFixture : public Fixture { + public: + ParseNewFixture(const BenchmarkDataset& dataset) + : Fixture(dataset, "_parse_new") {} + + virtual void BenchmarkCase(benchmark::State& state) { + WrappingCounter i(payloads_.size()); + size_t total = 0; + + while (state.KeepRunning()) { + T m; + const std::string& payload = payloads_[i.Next()]; + total += payload.size(); + m.ParseFromString(payload); + } + + state.SetBytesProcessed(total); + } +}; + +template +class ParseNewArenaFixture : public Fixture { + public: + ParseNewArenaFixture(const BenchmarkDataset& dataset) + : Fixture(dataset, "_parse_newarena") {} + + virtual void BenchmarkCase(benchmark::State& state) { + WrappingCounter i(payloads_.size()); + size_t total = 0; + Arena arena; + + while (state.KeepRunning()) { + arena.Reset(); + Message* m = Arena::CreateMessage(&arena); + const std::string& payload = payloads_[i.Next()]; + total += payload.size(); + m->ParseFromString(payload); + } + + state.SetBytesProcessed(total); + } +}; + +template +class ParseReuseFixture : public Fixture { + public: + ParseReuseFixture(const BenchmarkDataset& dataset) + : Fixture(dataset, "_parse_reuse") {} + + virtual void BenchmarkCase(benchmark::State& state) { + T m; + WrappingCounter i(payloads_.size()); + size_t total = 0; + + while (state.KeepRunning()) { + const std::string& payload = payloads_[i.Next()]; + total += payload.size(); + m.ParseFromString(payload); + } + + state.SetBytesProcessed(total); + } +}; + +template +class SerializeFixture : public Fixture { + public: + SerializeFixture(const BenchmarkDataset& dataset) + : Fixture(dataset, "_serialize") { + for (size_t i = 0; i < payloads_.size(); i++) { + message_.push_back(new T); + message_.back()->ParseFromString(payloads_[i]); + } + } + + ~SerializeFixture() { + for (size_t i = 0; i < message_.size(); i++) { + delete message_[i]; + } + } + + virtual void BenchmarkCase(benchmark::State& state) { + size_t total = 0; + std::string str; + WrappingCounter i(payloads_.size()); + + while (state.KeepRunning()) { + str.clear(); + message_[i.Next()]->SerializeToString(&str); + total += str.size(); + } + + state.SetBytesProcessed(total); + } + + private: + std::vector message_; +}; + +std::string ReadFile(const std::string& name) { + std::ifstream file(name.c_str()); + GOOGLE_CHECK(file.is_open()) << "Couldn't find file '" << name << + "', please make sure you are running " + "this command from the benchmarks/ " + "directory.\n"; + return std::string((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); +} + +template +void RegisterBenchmarksForType(const BenchmarkDataset& dataset) { + ::benchmark::internal::RegisterBenchmarkInternal( + new ParseNewFixture(dataset)); + ::benchmark::internal::RegisterBenchmarkInternal( + new ParseReuseFixture(dataset)); + ::benchmark::internal::RegisterBenchmarkInternal( + new ParseNewArenaFixture(dataset)); + ::benchmark::internal::RegisterBenchmarkInternal( + new SerializeFixture(dataset)); +} + +void RegisterBenchmarks(const std::string& dataset_bytes) { + BenchmarkDataset dataset; + GOOGLE_CHECK(dataset.ParseFromString(dataset_bytes)); + + if (dataset.message_name() == "benchmarks.proto3.GoogleMessage1") { + RegisterBenchmarksForType(dataset); + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage1") { + RegisterBenchmarksForType(dataset); + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage2") { + RegisterBenchmarksForType(dataset); + } else if (dataset.message_name() == + "benchmarks.google_message3.GoogleMessage3") { + RegisterBenchmarksForType + (dataset); + } else if (dataset.message_name() == + "benchmarks.google_message4.GoogleMessage4") { + RegisterBenchmarksForType + (dataset); + } else { + std::cerr << "Unknown message type: " << dataset.message_name(); + exit(1); + } +} + +int main(int argc, char *argv[]) { + ::benchmark::Initialize(&argc, argv); + if (argc == 1) { + std::cerr << "Usage: ./cpp-benchmark " << std::endl; + std::cerr << "input data is in the format of \"benchmarks.proto\"" + << std::endl; + return 1; + } else { + for (int i = 1; i < argc; i++) { + RegisterBenchmarks(ReadFile(argv[i])); + } + } + + ::benchmark::RunSpecifiedBenchmarks(); +} diff --git a/libs/protobuf/benchmarks/datasets/BUILD.bazel b/libs/protobuf/benchmarks/datasets/BUILD.bazel new file mode 100644 index 0000000..2a8b402 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/BUILD.bazel @@ -0,0 +1,67 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@rules_java//java:defs.bzl", "java_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "//benchmarks/datasets/google_message1/proto2:datasets", + "//benchmarks/datasets/google_message1/proto3:datasets", + "//benchmarks/datasets/google_message2:datasets", + "//benchmarks/datasets/google_message3:datasets", + "//benchmarks/datasets/google_message4:datasets", + ], + visibility = [ + "//benchmarks:__subpackages__", + ], +) + +proto_library( + name = "protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_proto", + ], +) + +cc_library( + name = "cc_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + deps = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_cc_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_cc_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_cc_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_cc_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_cc_proto", + ], +) + +java_library( + name = "java_protos", + visibility = [ + "//benchmarks:__subpackages__", + ], + exports = [ + "//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_java_proto", + "//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_java_proto", + "//benchmarks/datasets/google_message2:benchmark_message2_java_proto", + "//benchmarks/datasets/google_message3:benchmark_message3_java_proto", + "//benchmarks/datasets/google_message4:benchmark_message4_java_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = ["BUILD.bazel"], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto2/BUILD.bazel b/libs/protobuf/benchmarks/datasets/google_message1/proto2/BUILD.bazel new file mode 100644 index 0000000..30caed5 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message1/proto2/BUILD.bazel @@ -0,0 +1,52 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto2_proto", + srcs = [ + "benchmark_message1_proto2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto2_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob(["*"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.proto b/libs/protobuf/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.proto new file mode 100644 index 0000000..e404b9f --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.proto @@ -0,0 +1,108 @@ +// 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. + +// Benchmark messages for proto2. + +syntax = "proto2"; + +package benchmarks.proto2; +option java_package = "com.google.protobuf.benchmarks"; + +// This is the default, but we specify it here explicitly. +option optimize_for = SPEED; + +option cc_enable_arenas = true; + +message GoogleMessage1 { + required string field1 = 1; + optional string field9 = 9; + optional string field18 = 18; + optional bool field80 = 80 [default = false]; + optional bool field81 = 81 [default = true]; + required int32 field2 = 2; + required int32 field3 = 3; + optional int32 field280 = 280; + optional int32 field6 = 6 [default = 0]; + optional int64 field22 = 22; + optional string field4 = 4; + repeated fixed64 field5 = 5; + optional bool field59 = 59 [default = false]; + optional string field7 = 7; + optional int32 field16 = 16; + optional int32 field130 = 130 [default = 0]; + optional bool field12 = 12 [default = true]; + optional bool field17 = 17 [default = true]; + optional bool field13 = 13 [default = true]; + optional bool field14 = 14 [default = true]; + optional int32 field104 = 104 [default = 0]; + optional int32 field100 = 100 [default = 0]; + optional int32 field101 = 101 [default = 0]; + optional string field102 = 102; + optional string field103 = 103; + optional int32 field29 = 29 [default = 0]; + optional bool field30 = 30 [default = false]; + optional int32 field60 = 60 [default = -1]; + optional int32 field271 = 271 [default = -1]; + optional int32 field272 = 272 [default = -1]; + optional int32 field150 = 150; + optional int32 field23 = 23 [default = 0]; + optional bool field24 = 24 [default = false]; + optional int32 field25 = 25 [default = 0]; + optional GoogleMessage1SubMessage field15 = 15; + optional bool field78 = 78; + optional int32 field67 = 67 [default = 0]; + optional int32 field68 = 68; + optional int32 field128 = 128 [default = 0]; + optional string field129 = 129 [default = "xxxxxxxxxxxxxxxxxxxxx"]; + optional int32 field131 = 131 [default = 0]; +} + +message GoogleMessage1SubMessage { + optional int32 field1 = 1 [default = 0]; + optional int32 field2 = 2 [default = 0]; + optional int32 field3 = 3 [default = 0]; + optional string field15 = 15; + optional bool field12 = 12 [default = true]; + optional int64 field13 = 13; + optional int64 field14 = 14; + optional int32 field16 = 16; + optional int32 field19 = 19 [default = 2]; + optional bool field20 = 20 [default = true]; + optional bool field28 = 28 [default = true]; + optional fixed64 field21 = 21; + optional int32 field22 = 22; + optional bool field23 = 23 [default = false]; + optional bool field206 = 206 [default = false]; + optional fixed32 field203 = 203; + optional int32 field204 = 204; + optional string field205 = 205; + optional uint64 field207 = 207; + optional uint64 field300 = 300; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb b/libs/protobuf/benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb new file mode 100644 index 0000000..f6fe784 Binary files /dev/null and b/libs/protobuf/benchmarks/datasets/google_message1/proto2/dataset.google_message1_proto2.pb differ diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto3/BUILD.bazel b/libs/protobuf/benchmarks/datasets/google_message1/proto3/BUILD.bazel new file mode 100644 index 0000000..0dc59d1 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message1/proto3/BUILD.bazel @@ -0,0 +1,52 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message1_proto3.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message1_proto3_proto", + srcs = [ + "benchmark_message1_proto3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message1_proto3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) + +java_proto_library( + name = "benchmark_message1_proto3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message1_proto3_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob(["*"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.proto b/libs/protobuf/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.proto new file mode 100644 index 0000000..8aee2f6 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.proto @@ -0,0 +1,108 @@ +// 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. + +// Benchmark messages for proto3. + +syntax = "proto3"; + +package benchmarks.proto3; +option java_package = "com.google.protobuf.benchmarks"; + +// This is the default, but we specify it here explicitly. +option optimize_for = SPEED; + +option cc_enable_arenas = true; + +message GoogleMessage1 { + string field1 = 1; + string field9 = 9; + string field18 = 18; + bool field80 = 80; + bool field81 = 81; + int32 field2 = 2; + int32 field3 = 3; + int32 field280 = 280; + int32 field6 = 6; + int64 field22 = 22; + string field4 = 4; + repeated fixed64 field5 = 5; + bool field59 = 59; + string field7 = 7; + int32 field16 = 16; + int32 field130 = 130; + bool field12 = 12; + bool field17 = 17; + bool field13 = 13; + bool field14 = 14; + int32 field104 = 104; + int32 field100 = 100; + int32 field101 = 101; + string field102 = 102; + string field103 = 103; + int32 field29 = 29; + bool field30 = 30; + int32 field60 = 60; + int32 field271 = 271; + int32 field272 = 272; + int32 field150 = 150; + int32 field23 = 23; + bool field24 = 24; + int32 field25 = 25; + GoogleMessage1SubMessage field15 = 15; + bool field78 = 78; + int32 field67 = 67; + int32 field68 = 68; + int32 field128 = 128; + string field129 = 129; + int32 field131 = 131; +} + +message GoogleMessage1SubMessage { + int32 field1 = 1; + int32 field2 = 2; + int32 field3 = 3; + string field15 = 15; + bool field12 = 12; + int64 field13 = 13; + int64 field14 = 14; + int32 field16 = 16; + int32 field19 = 19; + bool field20 = 20; + bool field28 = 28; + fixed64 field21 = 21; + int32 field22 = 22; + bool field23 = 23; + bool field206 = 206; + fixed32 field203 = 203; + int32 field204 = 204; + string field205 = 205; + uint64 field207 = 207; + uint64 field300 = 300; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb b/libs/protobuf/benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb new file mode 100644 index 0000000..4955bed Binary files /dev/null and b/libs/protobuf/benchmarks/datasets/google_message1/proto3/dataset.google_message1_proto3.pb differ diff --git a/libs/protobuf/benchmarks/datasets/google_message2/BUILD.bazel b/libs/protobuf/benchmarks/datasets/google_message2/BUILD.bazel new file mode 100644 index 0000000..f3d66a2 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message2/BUILD.bazel @@ -0,0 +1,52 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [ + "dataset.google_message2.pb", + ], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message2_proto", + srcs = [ + "benchmark_message2.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message2_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) + +java_proto_library( + name = "benchmark_message2_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message2_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob(["*"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message2/benchmark_message2.proto b/libs/protobuf/benchmarks/datasets/google_message2/benchmark_message2.proto new file mode 100644 index 0000000..500c5d6 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message2/benchmark_message2.proto @@ -0,0 +1,108 @@ +// 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. + +// LINT: ALLOW_GROUPS + +// Benchmark messages for proto2. + +syntax = "proto2"; + +package benchmarks.proto2; +option java_package = "com.google.protobuf.benchmarks"; + +// This is the default, but we specify it here explicitly. +option optimize_for = SPEED; + +option cc_enable_arenas = true; + +message GoogleMessage2 { + optional string field1 = 1; + optional int64 field3 = 3; + optional int64 field4 = 4; + optional int64 field30 = 30; + optional bool field75 = 75 [default = false]; + optional string field6 = 6; + optional bytes field2 = 2; + optional int32 field21 = 21 [default = 0]; + optional int32 field71 = 71; + optional float field25 = 25; + optional int32 field109 = 109 [default = 0]; + optional int32 field210 = 210 [default = 0]; + optional int32 field211 = 211 [default = 0]; + optional int32 field212 = 212 [default = 0]; + optional int32 field213 = 213 [default = 0]; + optional int32 field216 = 216 [default = 0]; + optional int32 field217 = 217 [default = 0]; + optional int32 field218 = 218 [default = 0]; + optional int32 field220 = 220 [default = 0]; + optional int32 field221 = 221 [default = 0]; + optional float field222 = 222 [default = 0.0]; + optional int32 field63 = 63; + + repeated group Group1 = 10 { + required float field11 = 11; + optional float field26 = 26; + optional string field12 = 12; + optional string field13 = 13; + repeated string field14 = 14; + required uint64 field15 = 15; + optional int32 field5 = 5; + optional string field27 = 27; + optional int32 field28 = 28; + optional string field29 = 29; + optional string field16 = 16; + repeated string field22 = 22; + repeated int32 field73 = 73; + optional int32 field20 = 20 [default = 0]; + optional string field24 = 24; + optional GoogleMessage2GroupedMessage field31 = 31; + } + repeated string field128 = 128; + optional int64 field131 = 131; + repeated string field127 = 127; + optional int32 field129 = 129; + repeated int64 field130 = 130; + optional bool field205 = 205 [default = false]; + optional bool field206 = 206 [default = false]; +} + +message GoogleMessage2GroupedMessage { + optional float field1 = 1; + optional float field2 = 2; + optional float field3 = 3 [default = 0.0]; + optional bool field4 = 4; + optional bool field5 = 5; + optional bool field6 = 6 [default = true]; + optional bool field7 = 7 [default = false]; + optional float field8 = 8; + optional bool field9 = 9; + optional float field10 = 10; + optional int64 field11 = 11; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message2/dataset.google_message2.pb b/libs/protobuf/benchmarks/datasets/google_message2/dataset.google_message2.pb new file mode 100644 index 0000000..3fa0e49 Binary files /dev/null and b/libs/protobuf/benchmarks/datasets/google_message2/dataset.google_message2.pb differ diff --git a/libs/protobuf/benchmarks/datasets/google_message3/BUILD.bazel b/libs/protobuf/benchmarks/datasets/google_message3/BUILD.bazel new file mode 100644 index 0000000..a729e50 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/BUILD.bazel @@ -0,0 +1,58 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message3_proto", + srcs = [ + "benchmark_message3.proto", + "benchmark_message3_1.proto", + "benchmark_message3_2.proto", + "benchmark_message3_3.proto", + "benchmark_message3_4.proto", + "benchmark_message3_5.proto", + "benchmark_message3_6.proto", + "benchmark_message3_7.proto", + "benchmark_message3_8.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message3_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) + +java_proto_library( + name = "benchmark_message3_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message3_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob(["*"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3.proto new file mode 100644 index 0000000..82422f9 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3.proto @@ -0,0 +1,566 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_1.proto"; +import "datasets/google_message3/benchmark_message3_2.proto"; +import "datasets/google_message3/benchmark_message3_3.proto"; +import "datasets/google_message3/benchmark_message3_4.proto"; +import "datasets/google_message3/benchmark_message3_5.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message GoogleMessage3 { + optional .benchmarks.google_message3.Message37487 field37519 = 2; + optional .benchmarks.google_message3.Message36876 field37520 = 3; + optional .benchmarks.google_message3.Message13062 field37521 = 4; + optional .benchmarks.google_message3.Message952 field37522 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field37523 = 6; + optional .benchmarks.google_message3.UnusedEmptyMessage field37524 = 7; + optional .benchmarks.google_message3.UnusedEmptyMessage field37525 = 8; + optional .benchmarks.google_message3.UnusedEmptyMessage field37526 = 9; + optional .benchmarks.google_message3.UnusedEmptyMessage field37527 = 10; + optional .benchmarks.google_message3.UnusedEmptyMessage field37528 = 11; + optional .benchmarks.google_message3.UnusedEmptyMessage field37529 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field37530 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field37531 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field37532 = 15; + optional .benchmarks.google_message3.UnusedEmptyMessage field37533 = 16; +} + +message Message1327 { + repeated .benchmarks.google_message3.UnusedEmptyMessage field1369 = 1; + repeated .benchmarks.google_message3.Message1328 field1370 = 3; + repeated .benchmarks.google_message3.UnusedEmptyMessage field1371 = 5; + repeated .benchmarks.google_message3.UnusedEmptyMessage field1372 = 6; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message1327 field1373 = 23104162; + } +} + +message Message3672 { + optional .benchmarks.google_message3.Enum3476 field3727 = 1; + optional int32 field3728 = 11; + optional int32 field3729 = 2; + repeated group Message3673 = 3 { + required .benchmarks.google_message3.Enum3476 field3738 = 4; + required int32 field3739 = 5; + } + repeated group Message3674 = 6 { + required .benchmarks.google_message3.Enum3476 field3740 = 7; + required int32 field3741 = 8; + } + optional bool field3732 = 9; + optional int32 field3733 = 10; + optional .benchmarks.google_message3.Enum3476 field3734 = 20; + optional int32 field3735 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field3736 = 50; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message3672 field3737 = 3144435; + } +} + +message Message3804 { + required int64 field3818 = 1; + required bool field3819 = 2; + repeated .benchmarks.google_message3.Enum3805 field3820 = 4; + optional int32 field3821 = 5; + optional bool field3822 = 6; + optional int64 field3823 = 7; + optional .benchmarks.google_message3.Enum3783 field3824 = 8; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message3804 field3825 = 59241828; + } +} + +message Message6849 { + repeated .benchmarks.google_message3.Message6850 field6910 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message6849 field6911 = 107558455; + } +} + +message Message6866 { + repeated .benchmarks.google_message3.Message6863 field6973 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message6866 field6974 = 22259060; + } +} + +message Message6870 { + repeated .benchmarks.google_message3.Message6871 field6991 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message6870 field6992 = 90034652; + } +} + +message Message7651 { + optional string field7685 = 1; + optional int64 field7686 = 2; + optional int64 field7687 = 3; + optional int64 field7688 = 4; + optional int32 field7689 = 5; + optional int32 field7690 = 6; + optional int32 field7691 = 7; + optional int32 field7692 = 8; + optional int32 field7693 = 9; + optional int32 field7694 = 10; + optional int32 field7695 = 11; + optional int32 field7696 = 12; + optional int32 field7697 = 13; + optional int32 field7698 = 14; + optional int32 field7699 = 15; + optional int32 field7700 = 16; + optional int32 field7701 = 17; + optional int32 field7702 = 18; + optional bool field7703 = 19; + repeated int32 field7704 = 20; + repeated int32 field7705 = 21; + repeated string field7706 = 22; + repeated string field7707 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field7708 = 24; + optional int32 field7709 = 25; + optional int32 field7710 = 26; + optional int32 field7711 = 27; + optional int32 field7712 = 43; + optional int32 field7713 = 28; + optional int32 field7714 = 29; + repeated .benchmarks.google_message3.Message7547 field7715 = 30; + repeated .benchmarks.google_message3.Message7547 field7716 = 31; + repeated .benchmarks.google_message3.UnusedEmptyMessage field7717 = 32; + repeated string field7718 = 33; + repeated string field7719 = 34; + repeated .benchmarks.google_message3.Message7648 field7720 = 35; + optional bool field7721 = 36; + optional bool field7722 = 37; + optional bool field7723 = 38; + optional bool field7724 = 39; + optional .benchmarks.google_message3.UnusedEmptyMessage field7725 = 40; + optional .benchmarks.google_message3.UnusedEnum field7726 = 41; + optional .benchmarks.google_message3.Enum7654 field7727 = 42; + optional string field7728 = 44; + optional .benchmarks.google_message3.UnusedEmptyMessage field7729 = 45; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message7651 field7730 = 55876009; + } +} + +message Message7864 { + optional string field7866 = 1; + optional string field7867 = 2; + repeated .benchmarks.google_message3.Message7865 field7868 = 5; + repeated .benchmarks.google_message3.Message7865 field7869 = 6; + repeated .benchmarks.google_message3.Message7865 field7870 = 7; + repeated .benchmarks.google_message3.UnusedEmptyMessage field7871 = 8; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message7864 field7872 = 44542730; + } +} + +message Message7929 { + optional int64 field7942 = 1; + optional int64 field7943 = 4; + optional int64 field7944 = 5; + optional int64 field7945 = 12; + optional int64 field7946 = 13; + optional int64 field7947 = 18; + optional int64 field7948 = 6; + optional int64 field7949 = 7; + repeated .benchmarks.google_message3.Message7919 field7950 = 8; + repeated .benchmarks.google_message3.UnusedEmptyMessage field7951 = 20; + repeated .benchmarks.google_message3.Message7920 field7952 = 14; + repeated .benchmarks.google_message3.Message7921 field7953 = 15; + repeated .benchmarks.google_message3.Message7928 field7954 = 17; + optional int64 field7955 = 19; + optional bool field7956 = 2; + optional int64 field7957 = 3; + optional int64 field7958 = 9; + repeated .benchmarks.google_message3.UnusedEmptyMessage field7959 = 10; + repeated bytes field7960 = 11; + optional int64 field7961 = 16; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message7929 field7962 = 53392238; + } +} + +message Message8508 { + repeated .benchmarks.google_message3.Message8511 field8517 = 8; + repeated .benchmarks.google_message3.Message8512 field8518 = 9; + repeated .benchmarks.google_message3.Message8513 field8519 = 11; + optional bool field8520 = 13; + optional .benchmarks.google_message3.Message8514 field8521 = 14; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8522 = 15; + repeated .benchmarks.google_message3.Message8515 field8523 = 16; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8524 = 17; + optional int64 field8525 = 1; + optional float field8526 = 2; + optional int64 field8527 = 3; + optional int64 field8528 = 4; + optional int32 field8529 = 5; + optional bytes field8530 = 6; + repeated bytes field8531 = 7; + optional bool field8532 = 10; + optional bytes field8533 = 12; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message8508 field8534 = 3811804; + } +} + +message Message9122 { + optional float field9132 = 1; + optional float field9133 = 2; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message9122 field9134 = 120398939; + } +} + +message Message10177 { + repeated .benchmarks.google_message3.Message10155 field10270 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message10177 field10271 = 26801105; + } +} + +message Message10278 { + repeated int32 field10286 = 1 [packed = true]; + repeated int32 field10287 = 2 [packed = true]; + optional int32 field10288 = 3; + extend .benchmarks.google_message3.Message10155 { + optional .benchmarks.google_message3.Message10278 field10289 = 29374161; + } +} + +message Message10323 { + repeated .benchmarks.google_message3.Message10320 field10360 = 1; + extend .benchmarks.google_message3.Message10155 { + optional .benchmarks.google_message3.Message10323 field10361 = 27922524; + } +} + +message Message10324 { + repeated .benchmarks.google_message3.Message10322 field10362 = 1; + optional .benchmarks.google_message3.Message10321 field10363 = 2; + extend .benchmarks.google_message3.Message10155 { + optional .benchmarks.google_message3.Message10324 field10364 = 27832297; + } +} + +message Message11990 { + repeated .benchmarks.google_message3.Message11988 field12030 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message11990 field12031 = 21265426; + } +} + +message Message12691 { + optional string field12713 = 1; + optional int32 field12714 = 2; + optional .benchmarks.google_message3.Message12668 field12715 = 3; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message12691 field12716 = 28426536; + } +} + +message Message12870 { + required int32 field12879 = 1; + optional int32 field12880 = 7; + required int32 field12881 = 2; + optional uint64 field12882 = 3; + optional string field12883 = 2001; + optional fixed64 field12884 = 4; + repeated fixed64 field12885 = 14; + optional int32 field12886 = 9; + optional int64 field12887 = 18; + repeated .benchmarks.google_message3.Message12870 field12888 = 8; + optional int32 field12889 = 5; + optional uint64 field12890 = 6; + optional int32 field12891 = 10; + optional int32 field12892 = 11; + optional double field12893 = 12; + optional .benchmarks.google_message3.Message12825 field12894 = 13; + optional double field12895 = 15; + optional string field12896 = 16; + optional .benchmarks.google_message3.Enum12871 field12897 = 17; + optional int32 field12898 = 19; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message12870 field12899 = 5447656; + } +} + +message Message13154 { + required float field13164 = 1; + required float field13165 = 2; + extend .benchmarks.google_message3.Message13145 { + optional .benchmarks.google_message3.Message13154 field13166 = 47301086; + } +} + +message Message16507 { + optional bool field16510 = 3; + optional bool field16511 = 4; + optional bool field16512 = 14; + repeated string field16513 = 5; + repeated string field16514 = 6; + optional string field16515 = 8; + repeated int32 field16516 = 9; + repeated int32 field16517 = 10; + optional int32 field16518 = 7; + optional string field16519 = 15; + repeated string field16520 = 11; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16521 = 27; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16522 = 22; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16523 = 28; + optional string field16524 = 18; + optional int32 field16525 = 19; + optional int32 field16526 = 20; + optional .benchmarks.google_message3.UnusedEmptyMessage field16527 = 23; + optional bool field16528 = 24; + repeated string field16529 = 25; + optional double field16530 = 26; + optional .benchmarks.google_message3.Message16478 field16531 = 30; + optional bool field16532 = 31; + optional string field16533 = 32; + optional bool field16534 = 33; + optional bool field16535 = 35; + optional bool field16536 = 36; + optional bool field16537 = 37; + optional bool field16538 = 38; + optional bool field16539 = 39; + optional bool field16540 = 40; + repeated string field16541 = 41; + extensions 21 to 21; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message16507 field16542 = 5569941; + } +} + +message Message16564 { + repeated .benchmarks.google_message3.Message16552 field16568 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message16564 field16569 = 25830030; + } +} + +message Message16661 { + repeated .benchmarks.google_message3.Message16660 field16671 = 1; + repeated uint64 field16672 = 2; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message16661 field16673 = 31274398; + } +} + +message Message16746 { + repeated .benchmarks.google_message3.Message16727 field16806 = 1; + optional bool field16807 = 2; + optional bool field16808 = 3; + repeated .benchmarks.google_message3.Message16725 field16809 = 4; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message16746 field16810 = 28406765; + } +} + +message Message17786 { + repeated group Message17787 = 1 { + required int32 field18177 = 2; + required int32 field18178 = 3; + optional .benchmarks.google_message3.Message17783 field18179 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field18180 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field18181 = 6; + repeated .benchmarks.google_message3.UnusedEmptyMessage field18182 = 8; + optional .benchmarks.google_message3.UnusedEmptyMessage field18183 = 9; + optional .benchmarks.google_message3.Message17726 field18184 = 10; + optional .benchmarks.google_message3.UnusedEmptyMessage field18185 = 11; + optional .benchmarks.google_message3.Message16945 field18186 = 102; + optional .benchmarks.google_message3.UnusedEmptyMessage field18187 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field18188 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field18189 = 7; + optional .benchmarks.google_message3.UnusedEmptyMessage field18190 = 100; + optional .benchmarks.google_message3.UnusedEmptyMessage field18191 = 101; + optional .benchmarks.google_message3.UnusedEmptyMessage field18192 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field18193 = 19; + optional .benchmarks.google_message3.UnusedEmptyMessage field18194 = 22; + optional .benchmarks.google_message3.UnusedEmptyMessage field18195 = 24; + optional .benchmarks.google_message3.Enum16925 field18196 = 21; + optional bool field18197 = 18; + repeated .benchmarks.google_message3.UnusedEnum field18198 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field18199 = 15; + optional string field18200 = 16; + optional string field18201 = 17; + optional bool field18202 = 99; + } + repeated .benchmarks.google_message3.Message17782 field18175 = 20; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message17786 field18176 = 11823055; + } +} + +message Message22857 { + repeated .benchmarks.google_message3.Message22853 field22874 = 1; + extend .benchmarks.google_message3.Message10155 { + optional .benchmarks.google_message3.Message22857 field22875 = 67799715; + } +} + +message Message24404 { + repeated group Message24405 = 1 { + required int32 field24686 = 2; + required int32 field24687 = 3; + optional .benchmarks.google_message3.Message24317 field24688 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field24689 = 5; + optional .benchmarks.google_message3.Message24376 field24690 = 6; + optional .benchmarks.google_message3.Message24345 field24691 = 7; + optional .benchmarks.google_message3.UnusedEmptyMessage field24692 = 8; + optional .benchmarks.google_message3.Message24379 field24693 = 9; + optional .benchmarks.google_message3.UnusedEmptyMessage field24694 = 10; + optional .benchmarks.google_message3.UnusedEmptyMessage field24695 = 11; + optional .benchmarks.google_message3.Message24391 field24696 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field24697 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field24698 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field24699 = 22; + optional .benchmarks.google_message3.UnusedEmptyMessage field24700 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field24701 = 25; + optional .benchmarks.google_message3.Enum16925 field24702 = 18; + optional float field24703 = 20; + optional bool field24704 = 19; + repeated .benchmarks.google_message3.Enum16891 field24705 = 24; + optional .benchmarks.google_message3.UnusedEmptyMessage field24706 = 15; + optional string field24707 = 16; + optional string field24708 = 17; + optional float field24709 = 21; + optional bool field24710 = 26; + optional .benchmarks.google_message3.UnusedEnum field24711 = 27; + optional bool field24712 = 28; + optional .benchmarks.google_message3.UnusedEnum field24713 = 29; + optional bool field24714 = 31; + optional bool field24715 = 99; + optional int64 field24716 = 32; + } + optional .benchmarks.google_message3.Message24403 field24684 = 30; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message24404 field24685 = 9129287; + } +} + +message Message27300 { + repeated .benchmarks.google_message3.UnusedEmptyMessage field27302 = 1; + optional string field27303 = 2; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message27300 field27304 = 24956467; + } +} + +message Message27453 { + optional string field27459 = 15; + repeated string field27460 = 1; + repeated float field27461 = 6; + repeated int32 field27462 = 27; + repeated int32 field27463 = 28; + repeated .benchmarks.google_message3.Message27454 field27464 = 24; + repeated string field27465 = 2; + repeated float field27466 = 7; + repeated string field27467 = 22; + repeated string field27468 = 23; + optional string field27469 = 26; + repeated .benchmarks.google_message3.Message27357 field27470 = 8; + optional .benchmarks.google_message3.Message27360 field27471 = 16; + optional string field27472 = 25; + optional string field27473 = 11; + optional bool field27474 = 13; + optional bool field27475 = 14; + optional bool field27476 = 17; + optional .benchmarks.google_message3.UnusedEmptyMessage field27477 = 12; + optional bool field27478 = 34268945; + optional bool field27479 = 20; + optional string field27480 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field27481 = 10; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message27453 field27482 = 8086204; + } +} + +extend .benchmarks.google_message3.Message16945 { + optional string field17026 = 472; + repeated string field17027 = 818; + optional .benchmarks.google_message3.Message0 field17031 = 215; + repeated .benchmarks.google_message3.Message0 field17032 = 292; + repeated .benchmarks.google_message3.Message0 field17038 = 234; + repeated .benchmarks.google_message3.Message0 field17039 = 235; + optional .benchmarks.google_message3.Message0 field17042 = 246; + optional string field17043 = 224; + optional string field17044 = 225; + repeated string field17048 = 63; + repeated string field17049 = 64; + repeated .benchmarks.google_message3.Message0 field17052 = 233; + repeated .benchmarks.google_message3.Message0 field17053 = 66; + repeated string field17056 = 275; + optional string field17057 = 226; + repeated .benchmarks.google_message3.Message0 field17060 = 27; + repeated string field17073 = 75; + repeated .benchmarks.google_message3.Message0 field17076 = 77; + repeated string field17078 = 296; + repeated .benchmarks.google_message3.Message0 field17082 = 160; + repeated .benchmarks.google_message3.Message0 field17091 = 585; + repeated .benchmarks.google_message3.Message0 field17098 = 987; + repeated .benchmarks.google_message3.Message0 field17101 = 157; + repeated string field17102 = 158; + repeated string field17107 = 166; + repeated string field17133 = 567; + repeated string field17134 = 572; + repeated string field17160 = 49; + repeated string field17168 = 32; + repeated string field17170 = 34; + repeated .benchmarks.google_message3.Message0 field17172 = 509; + repeated string field17174 = 39; + repeated .benchmarks.google_message3.Message0 field17175 = 40; + repeated .benchmarks.google_message3.Message0 field17178 = 511; + repeated .benchmarks.google_message3.Message0 field17185 = 50; + repeated int32 field17207 = 1081; + repeated .benchmarks.google_message3.Message0 field17238 = 184; + repeated .benchmarks.google_message3.Message0 field17289 = 177; + repeated .benchmarks.google_message3.Message0 field17290 = 178; + repeated .benchmarks.google_message3.Message0 field17296 = 474; + repeated string field17298 = 44; + repeated .benchmarks.google_message3.Message0 field17301 = 47; + optional .benchmarks.google_message3.Message0 field17412 = 21; + repeated .benchmarks.google_message3.Message0 field17438 = 132; + repeated .benchmarks.google_message3.Message0 field17458 = 512; + repeated string field17460 = 560; + repeated string field17466 = 552; + repeated .benchmarks.google_message3.Message0 field17617 = 1080; + repeated int32 field17618 = 1084; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_1.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_1.proto new file mode 100644 index 0000000..1ee5c9e --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_1.proto @@ -0,0 +1,1298 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_2.proto"; +import "datasets/google_message3/benchmark_message3_3.proto"; +import "datasets/google_message3/benchmark_message3_5.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message34390 { + repeated .benchmarks.google_message3.Message34387 field34452 = 1; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message34390 field34453 = 92144610; + } +} + +message Message34624 { + optional .benchmarks.google_message3.Message34621 field34683 = 1; + optional .benchmarks.google_message3.Message34621 field34684 = 2; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message34624 field34685 = 18178548; + } +} + +message Message34791 { + optional fixed64 field34793 = 1; + repeated group Message34792 = 2 { + required string field34808 = 3; + optional string field34809 = 4; + } + optional int32 field34795 = 5; + optional int32 field34796 = 6; + optional int32 field34797 = 7; + optional int32 field34798 = 8; + optional int32 field34799 = 9; + optional int32 field34800 = 10; + optional bool field34801 = 11; + optional float field34802 = 12; + optional int32 field34803 = 13; + optional string field34804 = 14; + optional int64 field34805 = 15; + repeated fixed64 field34806 = 17 [packed = true]; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message34791 field34807 = 6330340; + } +} + +message Message35483 { + optional int32 field35499 = 1; + optional string field35500 = 2; + optional string field35501 = 3; + optional string field35502 = 4; + repeated .benchmarks.google_message3.Message35476 field35503 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field35504 = 6; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message35483 field35505 = 7913554; + } +} + +message Message35807 { + optional int32 field35810 = 1; + optional int32 field35811 = 2; + optional int32 field35812 = 3; + optional int32 field35813 = 4; + optional int32 field35814 = 5; + optional int32 field35815 = 6; + optional int32 field35816 = 7; + optional int32 field35817 = 8; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message35807 field35818 = 3803299; + } +} + +message Message37487 { + optional bytes field37501 = 2; + optional bool field37502 = 3; +} + +message Message13062 { + optional int64 field13075 = 1; + optional string field13076 = 2; + optional int32 field13077 = 3; + optional string field13078 = 4; + optional int32 field13079 = 5; +} + +message Message952 { + repeated .benchmarks.google_message3.Message949 field963 = 1; +} + +message Message36876 { + optional .benchmarks.google_message3.Message2356 field36980 = 1; + repeated group Message36877 = 111 { + required string field37044 = 112; + optional int32 field37045 = 113; + optional bytes field37046 = 114; + optional int32 field37047 = 115; + optional int32 field37048 = 157; + } + repeated group Message36878 = 168 {} + repeated group Message36879 = 55 { + required string field37050 = 56; + optional int32 field37051 = 69; + } + repeated .benchmarks.google_message3.UnusedEmptyMessage field36984 = 78; + optional group Message36880 = 137 {} + optional uint64 field36986 = 59; + optional bytes field36987 = 121; + optional .benchmarks.google_message3.UnusedEmptyMessage field36988 = 2; + optional .benchmarks.google_message3.Message7029 field36989 = 118; + optional .benchmarks.google_message3.Message35573 field36990 = 11; + optional .benchmarks.google_message3.UnusedEmptyMessage field36991 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field36992 = 22; + optional float field36993 = 13; + optional int32 field36994 = 20; + optional bool field36995 = 51; + optional bool field36996 = 57; + repeated .benchmarks.google_message3.UnusedEmptyMessage field36997 = 100; + optional int32 field36998 = 47; + optional int32 field36999 = 48; + optional .benchmarks.google_message3.UnusedEmptyMessage field37000 = 68; + repeated group Message36881 = 23 {} + optional .benchmarks.google_message3.Message4144 field37002 = 125; + repeated group Message36882 = 35 {} + optional .benchmarks.google_message3.UnusedEmptyMessage field37004 = 49; + optional .benchmarks.google_message3.Message18921 field37005 = 52; + optional .benchmarks.google_message3.Message36858 field37006 = 46; + optional .benchmarks.google_message3.Message18831 field37007 = 54; + optional .benchmarks.google_message3.UnusedEmptyMessage field37008 = 58; + optional .benchmarks.google_message3.Message18283 field37009 = 10; + optional string field37010 = 44; + optional string field37011 = 103; + optional .benchmarks.google_message3.Message0 field37012 = 43; + optional .benchmarks.google_message3.Message0 field37013 = 143; + optional .benchmarks.google_message3.UnusedEmptyMessage field37014 = 53; + optional .benchmarks.google_message3.Message36869 field37015 = 15; + optional group Message36883 = 3 {} + repeated group Message36884 = 16 {} + repeated group Message36885 = 27 {} + optional group Message36886 = 32 {} + repeated .benchmarks.google_message3.UnusedEnum field37020 = 71; + repeated int32 field37021 = 70; + optional .benchmarks.google_message3.UnusedEmptyMessage field37022 = 66; + optional .benchmarks.google_message3.Message13090 field37023 = 67; + optional group Message36887 = 62 {} + repeated .benchmarks.google_message3.Message10155 field37025 = 50; + repeated .benchmarks.google_message3.Message11874 field37026 = 151; + optional string field37027 = 12; + optional int64 field37028 = 72; + optional .benchmarks.google_message3.UnusedEmptyMessage field37029 = 73; + optional .benchmarks.google_message3.Message35546 field37030 = 108; + optional group Message36888 = 74 { + optional uint64 field37089 = 75; + optional bool field37090 = 76; + optional uint64 field37091 = 165; + optional double field37092 = 166; + optional uint64 field37093 = 109; + optional bytes field37094 = 122; + } + repeated .benchmarks.google_message3.Message19255 field37032 = 104; + optional .benchmarks.google_message3.Message33968 field37033 = 105; + optional bool field37034 = 106; + repeated .benchmarks.google_message3.UnusedEmptyMessage field37035 = 107; + optional .benchmarks.google_message3.Message6644 field37036 = 110; + optional bytes field37037 = 133; + optional group Message36889 = 116 { + optional int64 field37095 = 117; + optional string field37096 = 145; + optional int32 field37097 = 123; + optional bool field37098 = 163; + optional int32 field37099 = 164; + optional int32 field37100 = 149; + optional .benchmarks.google_message3.UnusedEmptyMessage field37101 = 129; + optional .benchmarks.google_message3.Message13174 field37102 = 124; + optional .benchmarks.google_message3.Message13169 field37103 = 128; + optional uint64 field37104 = 132; + repeated .benchmarks.google_message3.Enum36890 field37105 = 131; + optional bool field37106 = 134; + optional bool field37107 = 140; + optional .benchmarks.google_message3.UnusedEmptyMessage field37108 = 135; + optional float field37109 = 136; + optional float field37110 = 156; + optional bool field37111 = 142; + optional int64 field37112 = 167; + optional .benchmarks.google_message3.UnusedEmptyMessage field37113 = 146; + optional bool field37114 = 148; + optional .benchmarks.google_message3.UnusedEmptyMessage field37115 = 154; + optional .benchmarks.google_message3.UnusedEnum field37116 = 158; + repeated .benchmarks.google_message3.UnusedEnum field37117 = 159; + optional int32 field37118 = 160; + repeated string field37119 = 161; + } + repeated group Message36910 = 119 {} + optional group Message36911 = 126 { + optional .benchmarks.google_message3.UnusedEmptyMessage field37121 = 127; + optional .benchmarks.google_message3.Message35538 field37122 = 130; + optional .benchmarks.google_message3.Message35540 field37123 = 144; + optional .benchmarks.google_message3.Message35542 field37124 = 150; + } + optional group Message36912 = 152 { + optional .benchmarks.google_message3.Message3901 field37125 = 153; + optional .benchmarks.google_message3.Message3901 field37126 = 162; + } + optional .benchmarks.google_message3.UnusedEmptyMessage field37042 = 155; +} + +message Message1328 {} + +message Message6850 {} + +message Message6863 { + optional .benchmarks.google_message3.Enum6858 field6931 = 1; + optional .benchmarks.google_message3.Enum6858 field6932 = 2; + optional .benchmarks.google_message3.UnusedEnum field6933 = 36; + optional bool field6934 = 27; + optional .benchmarks.google_message3.Message6773 field6935 = 26; + optional int32 field6936 = 30; + optional int32 field6937 = 37; + optional .benchmarks.google_message3.Enum6815 field6938 = 31; + optional string field6939 = 3; + optional int32 field6940 = 4; + optional .benchmarks.google_message3.Enum6822 field6941 = 15; + optional bool field6942 = 10; + optional bool field6943 = 17; + optional float field6944 = 18; + optional float field6945 = 19; + optional int32 field6946 = 5; + optional int32 field6947 = 6; + optional bool field6948 = 7; + optional int32 field6949 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field6950 = 8; + optional uint64 field6951 = 9; + optional string field6952 = 11; + optional bytes field6953 = 13; + optional int32 field6954 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field6955 = 16; + optional .benchmarks.google_message3.UnusedEmptyMessage field6956 = 22; + optional .benchmarks.google_message3.Message3886 field6957 = 38; + optional string field6958 = 20; + optional uint32 field6959 = 21; + optional .benchmarks.google_message3.Message6743 field6960 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field6961 = 29; + optional .benchmarks.google_message3.UnusedEmptyMessage field6962 = 33; + optional bool field6963 = 34; +} + +message Message6871 {} + +message Message7547 { + required bytes field7549 = 1; + required int32 field7550 = 2; +} + +message Message7648 { + optional string field7669 = 1; + optional int32 field7670 = 2; + optional int32 field7671 = 3; + optional int32 field7672 = 4; + optional int32 field7673 = 5; + optional int32 field7674 = 6; + optional float field7675 = 7; + optional bool field7676 = 8; + optional bool field7677 = 9; + optional bool field7678 = 10; + optional bool field7679 = 11; + optional bool field7680 = 12; +} + +message Message7865 {} + +message Message7928 { + optional string field7940 = 1; + optional int64 field7941 = 2; +} + +message Message7919 { + optional fixed64 field7931 = 1; + optional int64 field7932 = 2; + optional bytes field7933 = 3; +} + +message Message7920 { + optional int64 field7934 = 1; + optional int64 field7935 = 2; +} + +message Message7921 { + optional int32 field7936 = 1; + optional int64 field7937 = 2; + optional float field7938 = 3; + optional .benchmarks.google_message3.UnusedEnum field7939 = 4; +} + +message Message8511 { + optional .benchmarks.google_message3.Message8224 field8539 = 1; + optional string field8540 = 2; + optional bool field8541 = 3; + optional int64 field8542 = 4; + optional string field8543 = 5; +} + +message Message8512 { + optional .benchmarks.google_message3.Message8301 field8544 = 1; + optional .benchmarks.google_message3.Message8302 field8545 = 2; + optional string field8546 = 3; + optional bool field8547 = 4; + optional int64 field8548 = 5; + optional string field8549 = 6; +} + +message Message8513 { + repeated .benchmarks.google_message3.Message8392 field8550 = 1; + optional string field8551 = 2; + optional bool field8552 = 3; + optional string field8553 = 4; +} + +message Message8514 { + optional string field8554 = 1; + optional int64 field8555 = 2; + optional bool field8556 = 3; + repeated .benchmarks.google_message3.Message8130 field8557 = 4; + optional string field8558 = 5; +} + +message Message8515 { + optional .benchmarks.google_message3.Message8479 field8559 = 1; + optional .benchmarks.google_message3.Message8478 field8560 = 2; + optional string field8561 = 3; +} + +message Message10320 { + optional .benchmarks.google_message3.Enum10335 field10347 = 1; + repeated .benchmarks.google_message3.Message10319 field10348 = 2; + optional int32 field10349 = 3; + optional int32 field10350 = 4; + optional int32 field10351 = 5; + optional int32 field10352 = 6; + optional .benchmarks.google_message3.Enum10337 field10353 = 7; +} + +message Message10321 { + optional int32 field10354 = 1; + optional int32 field10355 = 2; + optional uint64 field10356 = 3; +} + +message Message10322 { + optional .benchmarks.google_message3.Message4016 field10357 = 1; + optional bool field10358 = 2; + optional bool field10359 = 3; +} + +message Message11988 { + optional string field12021 = 1; + optional string field12022 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field12023 = 3; + optional .benchmarks.google_message3.Message10155 field12024 = 4; +} + +message Message12668 { + repeated .benchmarks.google_message3.Message12669 field12677 = 1; + optional int32 field12678 = 2; + optional int32 field12679 = 3; + optional int32 field12680 = 4; +} + +message Message12825 { + repeated .benchmarks.google_message3.Message12818 field12862 = 1; + optional int32 field12863 = 2; + optional .benchmarks.google_message3.Message12819 field12864 = 3; + optional .benchmarks.google_message3.Message12820 field12865 = 4; + optional int32 field12866 = 5; + repeated .benchmarks.google_message3.Message12821 field12867 = 6; + repeated .benchmarks.google_message3.UnusedEmptyMessage field12868 = 7; +} + +message Message16478 { + repeated .benchmarks.google_message3.Message16479 field16481 = 1; + optional bool field16482 = 3; + optional int32 field16483 = 2; +} + +message Message16552 { + optional fixed64 field16565 = 1; + optional int32 field16566 = 2; + optional .benchmarks.google_message3.Enum16553 field16567 = 3; +} + +message Message16660 { + optional string field16668 = 1; + optional string field16669 = 2; + optional int32 field16670 = 3; +} + +message Message16727 { + required .benchmarks.google_message3.Enum16728 field16782 = 1; + required string field16783 = 2; + optional string field16784 = 3; + optional int32 field16785 = 23; + required string field16786 = 4; + optional string field16787 = 5; + optional string field16788 = 6; + required .benchmarks.google_message3.Enum16732 field16789 = 7; + optional string field16790 = 8; + optional string field16791 = 9; + optional string field16792 = 10; + optional .benchmarks.google_message3.Enum16738 field16793 = 11; + optional int32 field16794 = 12; + repeated .benchmarks.google_message3.Message16722 field16795 = 13; + optional bool field16796 = 19; + optional bool field16797 = 24; + optional string field16798 = 14; + optional int64 field16799 = 15; + optional bool field16800 = 16; + optional string field16801 = 17; + optional .benchmarks.google_message3.Enum16698 field16802 = 18; + optional .benchmarks.google_message3.Message16724 field16803 = 20; + optional bool field16804 = 22; + optional .benchmarks.google_message3.UnusedEmptyMessage field16805 = 25; + extensions 1000 to 536870911; +} + +message Message16725 { + optional .benchmarks.google_message3.Enum16728 field16774 = 1; + repeated string field16775 = 2; +} + +message Message17726 { + optional string field17801 = 1; + repeated string field17802 = 2; + optional string field17803 = 3; + repeated string field17804 = 4; + optional string field17805 = 5; + repeated string field17806 = 6; + optional string field17807 = 7; + optional string field17808 = 8; + repeated string field17809 = 15; + repeated string field17810 = 16; + repeated string field17811 = 17; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17812 = 18; + optional string field17813 = 9; + optional string field17814 = 10; + optional string field17815 = 11; + optional string field17816 = 12; + optional string field17817 = 13; + optional string field17818 = 14; + optional string field17819 = 19; + repeated .benchmarks.google_message3.Message17728 field17820 = 20; + repeated .benchmarks.google_message3.Message17728 field17821 = 21; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17822 = 30; +} + +message Message17782 { + optional string field18153 = 1; + optional string field18154 = 2; +} + +message Message17783 { + optional string field18155 = 1; + optional string field18156 = 2; + optional string field18157 = 3; + repeated group Message17784 = 4 { + optional string field18162 = 5; + optional string field18163 = 6; + optional string field18164 = 7; + repeated string field18165 = 8; + optional string field18166 = 17; + optional string field18167 = 18; + } + repeated group Message17785 = 9 { + optional string field18168 = 10; + optional string field18169 = 11; + optional .benchmarks.google_message3.Message17783 field18170 = 12; + optional string field18171 = 13; + optional string field18172 = 14; + repeated string field18173 = 15; + } + repeated string field18160 = 16; +} + +message Message16945 { + optional string field16946 = 1; + optional string field16947 = 2; + optional string field16948 = 3; + optional string field16949 = 4; + optional string field16950 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field16951 = 872; + repeated .benchmarks.google_message3.Message0 field16952 = 16; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16953 = 54; + repeated .benchmarks.google_message3.Message0 field16954 = 55; + repeated string field16955 = 58; + repeated string field16956 = 59; + repeated string field16957 = 62; + repeated string field16958 = 37; + repeated string field16959 = 18; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16960 = 38; + repeated .benchmarks.google_message3.Message0 field16961 = 67; + repeated .benchmarks.google_message3.Message0 field16962 = 130; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16963 = 136; + repeated string field16964 = 138; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16965 = 156; + repeated string field16966 = 139; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16967 = 126; + repeated string field16968 = 152; + repeated .benchmarks.google_message3.Message0 field16969 = 183; + repeated string field16970 = 168; + repeated string field16971 = 212; + repeated string field16972 = 213; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16973 = 189; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16974 = 190; + repeated string field16975 = 191; + repeated string field16976 = 192; + repeated .benchmarks.google_message3.Message0 field16977 = 193; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16978 = 194; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16979 = 195; + repeated int32 field16980 = 196; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16981 = 95; + repeated string field16982 = 96; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16983 = 97; + repeated string field16984 = 1086; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16985 = 98; + repeated string field16986 = 99; + repeated string field16987 = 100; + repeated string field16988 = 48; + optional string field16989 = 22; + repeated .benchmarks.google_message3.UnusedEmptyMessage field16990 = 51; + repeated string field16991 = 81; + repeated string field16992 = 85; + repeated string field16993 = 169; + optional .benchmarks.google_message3.UnusedEmptyMessage field16994 = 260; + optional int32 field16995 = 198; + optional int32 field16996 = 204; + optional string field16997 = 1087; + repeated string field16998 = 197; + repeated string field16999 = 206; + optional string field17000 = 211; + repeated string field17001 = 205; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17002 = 68; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17003 = 69; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17004 = 70; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17005 = 71; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17006 = 72; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17007 = 19; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17008 = 24; + optional .benchmarks.google_message3.UnusedEmptyMessage field17009 = 23; + repeated .benchmarks.google_message3.Message0 field17010 = 131; + repeated string field17011 = 133; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17012 = 142; + repeated string field17013 = 143; + repeated .benchmarks.google_message3.UnusedEmptyMessage field17014 = 153; + repeated .benchmarks.google_message3.Message0 field17015 = 170; + repeated string field17016 = 171; + repeated string field17017 = 172; + repeated string field17018 = 173; + repeated string field17019 = 174; + repeated string field17020 = 175; + repeated string field17021 = 186; + repeated string field17022 = 101; + repeated .benchmarks.google_message3.Message0 field17023 = 102; + repeated string field17024 = 274; + extensions 17 to 17; + extensions 21 to 21; + extensions 25 to 25; + extensions 27 to 27; + extensions 29 to 29; + extensions 30 to 30; + extensions 31 to 31; + extensions 32 to 32; + extensions 33 to 33; + extensions 34 to 34; + extensions 35 to 35; + extensions 36 to 36; + extensions 39 to 39; + extensions 40 to 40; + extensions 41 to 41; + extensions 42 to 42; + extensions 43 to 43; + extensions 44 to 44; + extensions 45 to 45; + extensions 46 to 46; + extensions 47 to 47; + extensions 49 to 49; + extensions 50 to 50; + extensions 52 to 52; + extensions 53 to 53; + extensions 56 to 56; + extensions 57 to 57; + extensions 60 to 60; + extensions 61 to 61; + extensions 63 to 63; + extensions 64 to 64; + extensions 65 to 65; + extensions 66 to 66; + extensions 73 to 73; + extensions 74 to 74; + extensions 75 to 75; + extensions 76 to 76; + extensions 77 to 77; + extensions 78 to 78; + extensions 79 to 79; + extensions 80 to 80; + extensions 82 to 82; + extensions 83 to 83; + extensions 84 to 84; + extensions 86 to 86; + extensions 87 to 87; + extensions 88 to 88; + extensions 89 to 89; + extensions 90 to 90; + extensions 91 to 91; + extensions 92 to 92; + extensions 93 to 93; + extensions 94 to 94; + extensions 103 to 103; + extensions 104 to 104; + extensions 105 to 105; + extensions 106 to 106; + extensions 107 to 107; + extensions 108 to 108; + extensions 109 to 109; + extensions 110 to 110; + extensions 111 to 111; + extensions 112 to 112; + extensions 113 to 113; + extensions 114 to 114; + extensions 115 to 115; + extensions 116 to 116; + extensions 117 to 117; + extensions 118 to 118; + extensions 119 to 119; + extensions 120 to 120; + extensions 121 to 121; + extensions 122 to 122; + extensions 123 to 123; + extensions 124 to 124; + extensions 125 to 125; + extensions 127 to 127; + extensions 128 to 128; + extensions 129 to 129; + extensions 132 to 132; + extensions 134 to 134; + extensions 135 to 135; + extensions 137 to 137; + extensions 140 to 140; + extensions 141 to 141; + extensions 144 to 144; + extensions 145 to 145; + extensions 146 to 146; + extensions 147 to 147; + extensions 148 to 148; + extensions 149 to 149; + extensions 150 to 150; + extensions 151 to 151; + extensions 154 to 154; + extensions 155 to 155; + extensions 157 to 157; + extensions 158 to 158; + extensions 159 to 159; + extensions 160 to 160; + extensions 161 to 161; + extensions 162 to 162; + extensions 163 to 163; + extensions 164 to 164; + extensions 165 to 165; + extensions 166 to 166; + extensions 167 to 167; + extensions 176 to 176; + extensions 177 to 177; + extensions 178 to 178; + extensions 179 to 179; + extensions 180 to 180; + extensions 181 to 181; + extensions 182 to 182; + extensions 184 to 184; + extensions 185 to 185; + extensions 187 to 187; + extensions 188 to 188; + extensions 199 to 199; + extensions 200 to 200; + extensions 201 to 201; + extensions 202 to 202; + extensions 203 to 203; + extensions 207 to 207; + extensions 208 to 208; + extensions 209 to 209; + extensions 210 to 210; + extensions 214 to 214; + extensions 215 to 215; + extensions 216 to 216; + extensions 217 to 217; + extensions 218 to 218; + extensions 219 to 219; + extensions 220 to 220; + extensions 221 to 221; + extensions 222 to 222; + extensions 223 to 223; + extensions 224 to 224; + extensions 225 to 225; + extensions 226 to 226; + extensions 227 to 227; + extensions 228 to 228; + extensions 229 to 229; + extensions 230 to 230; + extensions 231 to 231; + extensions 232 to 232; + extensions 233 to 233; + extensions 234 to 234; + extensions 235 to 235; + extensions 236 to 236; + extensions 237 to 237; + extensions 238 to 238; + extensions 239 to 239; + extensions 240 to 240; + extensions 241 to 241; + extensions 242 to 242; + extensions 243 to 243; + extensions 244 to 244; + extensions 245 to 245; + extensions 246 to 246; + extensions 247 to 247; + extensions 248 to 248; + extensions 249 to 249; + extensions 250 to 250; + extensions 251 to 251; + extensions 252 to 252; + extensions 253 to 253; + extensions 254 to 254; + extensions 255 to 255; + extensions 256 to 256; + extensions 257 to 257; + extensions 258 to 258; + extensions 259 to 259; + extensions 261 to 261; + extensions 262 to 262; + extensions 263 to 263; + extensions 264 to 264; + extensions 265 to 265; + extensions 266 to 266; + extensions 267 to 267; + extensions 268 to 268; + extensions 269 to 269; + extensions 270 to 270; + extensions 271 to 271; + extensions 272 to 272; + extensions 273 to 273; + extensions 275 to 275; + extensions 276 to 276; + extensions 277 to 277; + extensions 278 to 278; + extensions 279 to 279; + extensions 280 to 280; + extensions 281 to 281; + extensions 282 to 282; + extensions 283 to 283; + extensions 284 to 284; + extensions 285 to 285; + extensions 286 to 286; + extensions 290 to 290; + extensions 291 to 291; + extensions 292 to 292; + extensions 293 to 293; + extensions 294 to 294; + extensions 295 to 295; + extensions 296 to 296; + extensions 297 to 297; + extensions 298 to 298; + extensions 299 to 299; + extensions 300 to 300; + extensions 301 to 301; + extensions 302 to 302; + extensions 303 to 303; + extensions 304 to 304; + extensions 305 to 305; + extensions 306 to 306; + extensions 307 to 307; + extensions 308 to 308; + extensions 309 to 309; + extensions 310 to 310; + extensions 311 to 311; + extensions 312 to 312; + extensions 313 to 313; + extensions 314 to 314; + extensions 315 to 315; + extensions 316 to 316; + extensions 317 to 317; + extensions 318 to 318; + extensions 319 to 319; + extensions 320 to 320; + extensions 321 to 321; + extensions 322 to 322; + extensions 323 to 323; + extensions 324 to 324; + extensions 325 to 325; + extensions 326 to 326; + extensions 327 to 327; + extensions 328 to 328; + extensions 329 to 329; + extensions 330 to 330; + extensions 331 to 331; + extensions 332 to 332; + extensions 333 to 333; + extensions 334 to 334; + extensions 335 to 335; + extensions 336 to 336; + extensions 337 to 337; + extensions 338 to 338; + extensions 339 to 339; + extensions 340 to 340; + extensions 341 to 341; + extensions 342 to 342; + extensions 343 to 343; + extensions 344 to 344; + extensions 345 to 345; + extensions 346 to 346; + extensions 347 to 347; + extensions 348 to 348; + extensions 349 to 349; + extensions 350 to 350; + extensions 351 to 351; + extensions 352 to 352; + extensions 353 to 353; + extensions 354 to 354; + extensions 355 to 355; + extensions 356 to 356; + extensions 357 to 357; + extensions 358 to 358; + extensions 359 to 359; + extensions 360 to 360; + extensions 361 to 361; + extensions 362 to 362; + extensions 363 to 363; + extensions 364 to 364; + extensions 365 to 365; + extensions 366 to 366; + extensions 367 to 367; + extensions 368 to 368; + extensions 369 to 369; + extensions 370 to 370; + extensions 371 to 371; + extensions 372 to 372; + extensions 373 to 373; + extensions 374 to 374; + extensions 375 to 375; + extensions 376 to 376; + extensions 377 to 377; + extensions 378 to 378; + extensions 379 to 379; + extensions 380 to 380; + extensions 381 to 381; + extensions 382 to 382; + extensions 383 to 383; + extensions 384 to 384; + extensions 385 to 385; + extensions 386 to 386; + extensions 387 to 387; + extensions 388 to 388; + extensions 389 to 389; + extensions 390 to 390; + extensions 391 to 391; + extensions 392 to 392; + extensions 393 to 393; + extensions 394 to 394; + extensions 395 to 395; + extensions 396 to 396; + extensions 397 to 397; + extensions 398 to 398; + extensions 399 to 399; + extensions 400 to 400; + extensions 401 to 401; + extensions 402 to 402; + extensions 403 to 403; + extensions 404 to 404; + extensions 405 to 405; + extensions 406 to 406; + extensions 407 to 407; + extensions 408 to 408; + extensions 409 to 409; + extensions 410 to 410; + extensions 411 to 411; + extensions 412 to 412; + extensions 413 to 413; + extensions 414 to 414; + extensions 415 to 415; + extensions 416 to 416; + extensions 417 to 417; + extensions 418 to 418; + extensions 419 to 419; + extensions 420 to 420; + extensions 421 to 421; + extensions 422 to 422; + extensions 423 to 423; + extensions 424 to 424; + extensions 425 to 425; + extensions 426 to 426; + extensions 427 to 427; + extensions 428 to 428; + extensions 429 to 429; + extensions 430 to 430; + extensions 431 to 431; + extensions 432 to 432; + extensions 433 to 433; + extensions 434 to 434; + extensions 435 to 435; + extensions 436 to 436; + extensions 437 to 437; + extensions 438 to 438; + extensions 439 to 439; + extensions 440 to 440; + extensions 441 to 441; + extensions 442 to 442; + extensions 443 to 443; + extensions 444 to 444; + extensions 445 to 445; + extensions 446 to 446; + extensions 447 to 447; + extensions 448 to 448; + extensions 449 to 449; + extensions 450 to 450; + extensions 451 to 451; + extensions 452 to 452; + extensions 453 to 453; + extensions 454 to 454; + extensions 455 to 455; + extensions 456 to 456; + extensions 457 to 457; + extensions 458 to 458; + extensions 459 to 459; + extensions 460 to 460; + extensions 461 to 461; + extensions 462 to 462; + extensions 463 to 463; + extensions 464 to 464; + extensions 465 to 465; + extensions 466 to 466; + extensions 467 to 467; + extensions 468 to 468; + extensions 469 to 469; + extensions 470 to 470; + extensions 471 to 471; + extensions 472 to 472; + extensions 473 to 473; + extensions 474 to 474; + extensions 509 to 509; + extensions 511 to 511; + extensions 512 to 512; + extensions 513 to 513; + extensions 514 to 514; + extensions 515 to 515; + extensions 516 to 516; + extensions 517 to 517; + extensions 518 to 518; + extensions 519 to 519; + extensions 520 to 520; + extensions 521 to 521; + extensions 522 to 522; + extensions 523 to 523; + extensions 524 to 524; + extensions 525 to 525; + extensions 526 to 526; + extensions 527 to 527; + extensions 528 to 528; + extensions 529 to 529; + extensions 530 to 530; + extensions 531 to 531; + extensions 532 to 532; + extensions 533 to 533; + extensions 534 to 534; + extensions 535 to 535; + extensions 536 to 536; + extensions 537 to 537; + extensions 538 to 538; + extensions 539 to 539; + extensions 540 to 540; + extensions 541 to 541; + extensions 542 to 542; + extensions 543 to 543; + extensions 544 to 544; + extensions 545 to 545; + extensions 546 to 546; + extensions 547 to 547; + extensions 548 to 548; + extensions 549 to 549; + extensions 550 to 550; + extensions 551 to 551; + extensions 552 to 552; + extensions 553 to 553; + extensions 554 to 554; + extensions 555 to 555; + extensions 556 to 556; + extensions 557 to 557; + extensions 558 to 558; + extensions 559 to 559; + extensions 560 to 560; + extensions 561 to 561; + extensions 562 to 562; + extensions 563 to 563; + extensions 564 to 564; + extensions 565 to 565; + extensions 566 to 566; + extensions 567 to 567; + extensions 568 to 568; + extensions 569 to 569; + extensions 570 to 570; + extensions 571 to 571; + extensions 572 to 572; + extensions 573 to 573; + extensions 574 to 574; + extensions 575 to 575; + extensions 576 to 576; + extensions 577 to 577; + extensions 578 to 578; + extensions 579 to 579; + extensions 580 to 580; + extensions 581 to 581; + extensions 582 to 582; + extensions 583 to 583; + extensions 584 to 584; + extensions 585 to 585; + extensions 586 to 586; + extensions 587 to 587; + extensions 588 to 588; + extensions 589 to 589; + extensions 590 to 590; + extensions 604 to 604; + extensions 605 to 605; + extensions 606 to 606; + extensions 607 to 607; + extensions 608 to 608; + extensions 609 to 609; + extensions 610 to 610; + extensions 611 to 611; + extensions 612 to 612; + extensions 613 to 613; + extensions 614 to 614; + extensions 615 to 615; + extensions 616 to 616; + extensions 617 to 617; + extensions 618 to 618; + extensions 619 to 619; + extensions 620 to 620; + extensions 621 to 621; + extensions 622 to 622; + extensions 623 to 623; + extensions 624 to 624; + extensions 625 to 625; + extensions 626 to 626; + extensions 627 to 627; + extensions 628 to 628; + extensions 629 to 629; + extensions 813 to 813; + extensions 814 to 814; + extensions 815 to 815; + extensions 816 to 816; + extensions 817 to 817; + extensions 818 to 818; + extensions 819 to 819; + extensions 820 to 820; + extensions 821 to 821; + extensions 822 to 822; + extensions 823 to 823; + extensions 824 to 824; + extensions 827 to 827; + extensions 828 to 828; + extensions 829 to 829; + extensions 830 to 830; + extensions 831 to 831; + extensions 832 to 832; + extensions 833 to 833; + extensions 834 to 834; + extensions 835 to 835; + extensions 836 to 836; + extensions 837 to 837; + extensions 838 to 838; + extensions 839 to 839; + extensions 840 to 840; + extensions 841 to 841; + extensions 842 to 842; + extensions 843 to 843; + extensions 844 to 844; + extensions 845 to 845; + extensions 846 to 846; + extensions 847 to 847; + extensions 848 to 848; + extensions 849 to 849; + extensions 850 to 850; + extensions 851 to 851; + extensions 852 to 852; + extensions 853 to 853; + extensions 854 to 854; + extensions 855 to 855; + extensions 856 to 856; + extensions 857 to 857; + extensions 858 to 858; + extensions 859 to 859; + extensions 860 to 860; + extensions 861 to 861; + extensions 862 to 862; + extensions 863 to 863; + extensions 864 to 864; + extensions 865 to 865; + extensions 866 to 866; + extensions 867 to 867; + extensions 868 to 868; + extensions 869 to 869; + extensions 870 to 870; + extensions 871 to 871; + extensions 880 to 880; + extensions 881 to 881; + extensions 882 to 882; + extensions 883 to 883; + extensions 884 to 884; + extensions 885 to 885; + extensions 886 to 886; + extensions 887 to 887; + extensions 888 to 888; + extensions 890 to 890; + extensions 891 to 891; + extensions 892 to 892; + extensions 912 to 912; + extensions 914 to 914; + extensions 915 to 915; + extensions 916 to 916; + extensions 917 to 917; + extensions 918 to 918; + extensions 919 to 919; + extensions 920 to 920; + extensions 921 to 921; + extensions 922 to 922; + extensions 923 to 923; + extensions 924 to 924; + extensions 925 to 925; + extensions 926 to 926; + extensions 927 to 927; + extensions 928 to 928; + extensions 929 to 929; + extensions 930 to 930; + extensions 931 to 931; + extensions 932 to 932; + extensions 933 to 933; + extensions 934 to 934; + extensions 935 to 935; + extensions 936 to 936; + extensions 937 to 937; + extensions 938 to 938; + extensions 939 to 939; + extensions 940 to 940; + extensions 941 to 941; + extensions 942 to 942; + extensions 943 to 943; + extensions 944 to 944; + extensions 945 to 945; + extensions 946 to 946; + extensions 947 to 947; + extensions 949 to 949; + extensions 950 to 950; + extensions 951 to 951; + extensions 952 to 952; + extensions 954 to 954; + extensions 955 to 955; + extensions 956 to 956; + extensions 957 to 957; + extensions 958 to 958; + extensions 959 to 959; + extensions 960 to 960; + extensions 961 to 961; + extensions 962 to 962; + extensions 963 to 963; + extensions 964 to 964; + extensions 965 to 965; + extensions 966 to 966; + extensions 967 to 967; + extensions 968 to 968; + extensions 969 to 969; + extensions 970 to 970; + extensions 971 to 971; + extensions 972 to 972; + extensions 973 to 973; + extensions 974 to 974; + extensions 975 to 975; + extensions 976 to 976; + extensions 977 to 977; + extensions 978 to 978; + extensions 979 to 979; + extensions 980 to 980; + extensions 981 to 981; + extensions 982 to 982; + extensions 983 to 983; + extensions 984 to 984; + extensions 985 to 985; + extensions 987 to 987; + extensions 988 to 988; + extensions 1000 to 1000; + extensions 1001 to 1001; + extensions 1002 to 1002; + extensions 1003 to 1003; + extensions 1004 to 1004; + extensions 1005 to 1005; + extensions 1006 to 1006; + extensions 1007 to 1007; + extensions 1008 to 1008; + extensions 1009 to 1009; + extensions 1010 to 1010; + extensions 1011 to 1011; + extensions 1012 to 1012; + extensions 1013 to 1013; + extensions 1014 to 1014; + extensions 1015 to 1015; + extensions 1016 to 1016; + extensions 1017 to 1017; + extensions 1018 to 1018; + extensions 1019 to 1019; + extensions 1020 to 1020; + extensions 1021 to 1021; + extensions 1022 to 1022; + extensions 1023 to 1023; + extensions 1024 to 1024; + extensions 1025 to 1025; + extensions 1026 to 1026; + extensions 1027 to 1027; + extensions 1028 to 1028; + extensions 1029 to 1029; + extensions 1030 to 1030; + extensions 1031 to 1031; + extensions 1032 to 1032; + extensions 1033 to 1033; + extensions 1034 to 1034; + extensions 1035 to 1035; + extensions 1036 to 1036; + extensions 1037 to 1037; + extensions 1038 to 1038; + extensions 1039 to 1039; + extensions 1040 to 1040; + extensions 1041 to 1041; + extensions 1042 to 1042; + extensions 1043 to 1043; + extensions 1044 to 1044; + extensions 1045 to 1045; + extensions 1046 to 1046; + extensions 1047 to 1047; + extensions 1048 to 1048; + extensions 1049 to 1049; + extensions 1050 to 1050; + extensions 1051 to 1051; + extensions 1052 to 1052; + extensions 1053 to 1053; + extensions 1054 to 1054; + extensions 1055 to 1055; + extensions 1056 to 1056; + extensions 1057 to 1057; + extensions 1058 to 1058; + extensions 1079 to 1079; + extensions 1080 to 1080; + extensions 1081 to 1081; + extensions 1082 to 1082; + extensions 1083 to 1083; + extensions 1084 to 1084; + extensions 1085 to 1085; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message16945 field17025 = 22068132; + } +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_2.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_2.proto new file mode 100644 index 0000000..d123a72 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_2.proto @@ -0,0 +1,528 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_3.proto"; +import "datasets/google_message3/benchmark_message3_4.proto"; +import "datasets/google_message3/benchmark_message3_5.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message22853 { + optional .benchmarks.google_message3.Enum22854 field22869 = 1; + repeated uint32 field22870 = 2 [packed = true]; + repeated float field22871 = 3 [packed = true]; + repeated float field22872 = 5 [packed = true]; + optional .benchmarks.google_message3.UnusedEmptyMessage field22873 = 4; +} + +message Message24345 { + optional string field24533 = 1; + optional .benchmarks.google_message3.UnusedEnum field24534 = 22; + optional .benchmarks.google_message3.Message24346 field24535 = 2; + optional string field24536 = 3; + optional string field24537 = 4; + optional .benchmarks.google_message3.UnusedEnum field24538 = 23; + optional string field24539 = 5; + required string field24540 = 6; + optional string field24541 = 7; + optional string field24542 = 8; + optional .benchmarks.google_message3.Message24316 field24543 = 9; + optional .benchmarks.google_message3.Message24376 field24544 = 10; + optional string field24545 = 11; + optional string field24546 = 19; + optional string field24547 = 20; + optional string field24548 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field24549 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field24550 = 13; + repeated string field24551 = 14; + optional string field24552 = 15; + optional int32 field24553 = 18; + optional .benchmarks.google_message3.Message24379 field24554 = 16; + optional string field24555 = 17; + repeated .benchmarks.google_message3.Message24356 field24556 = 24; + repeated .benchmarks.google_message3.Message24366 field24557 = 25; +} + +message Message24403 { + optional .benchmarks.google_message3.Message24401 field24681 = 1; + optional .benchmarks.google_message3.Message24402 field24682 = 2; +} + +message Message24391 { + optional string field24631 = 1; + optional string field24632 = 2; + repeated string field24633 = 3; + optional string field24634 = 4; + repeated string field24635 = 5; + repeated string field24636 = 16; + optional string field24637 = 17; + optional .benchmarks.google_message3.UnusedEmptyMessage field24638 = 25; + optional string field24639 = 7; + optional string field24640 = 18; + optional string field24641 = 19; + optional string field24642 = 20; + optional int32 field24643 = 24; + optional .benchmarks.google_message3.Message24379 field24644 = 8; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24645 = 9; + optional .benchmarks.google_message3.UnusedEmptyMessage field24646 = 10; + optional .benchmarks.google_message3.UnusedEmptyMessage field24647 = 11; + optional .benchmarks.google_message3.UnusedEmptyMessage field24648 = 12; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24649 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field24650 = 14; + optional string field24651 = 21; + optional int32 field24652 = 22; + optional int32 field24653 = 23; + repeated string field24654 = 15; + repeated string field24655 = 6; +} + +message Message27454 {} + +message Message27357 { + optional string field27410 = 1; + optional float field27411 = 2; + optional string field27412 = 3; + optional bool field27413 = 4; + optional bool field27414 = 5; +} + +message Message27360 { + optional .benchmarks.google_message3.Message27358 field27426 = 1; + optional .benchmarks.google_message3.Enum27361 field27427 = 2; + optional .benchmarks.google_message3.Message27358 field27428 = 3; + repeated .benchmarks.google_message3.UnusedEmptyMessage field27429 = 4; +} + +message Message34387 { + optional string field34446 = 1; + repeated .benchmarks.google_message3.Message34381 field34447 = 2; + optional .benchmarks.google_message3.UnusedEnum field34448 = 3; + optional .benchmarks.google_message3.Enum34388 field34449 = 4; + optional int64 field34450 = 5; +} + +message Message34621 { + optional double field34651 = 1; + optional double field34652 = 2; + optional double field34653 = 3; + optional double field34654 = 4; + optional double field34655 = 11; + optional .benchmarks.google_message3.UnusedEmptyMessage field34656 = 13; + optional .benchmarks.google_message3.Message34619 field34657 = 14; + optional string field34658 = 5; + optional string field34659 = 9; + optional double field34660 = 12; + optional bytes field34661 = 19; + optional string field34662 = 15; + optional string field34663 = 16; + optional string field34664 = 17; + optional .benchmarks.google_message3.UnusedEmptyMessage field34665 = 18; + optional .benchmarks.google_message3.Message34621 field34666 = 20; + repeated .benchmarks.google_message3.UnusedEmptyMessage field34667 = 100; + optional .benchmarks.google_message3.UnusedEmptyMessage field34668 = 101; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message34621 field34669 = 17562023; + } +} + +message Message35476 { + optional string field35484 = 1; + optional string field35485 = 2; + optional string field35486 = 3; + optional .benchmarks.google_message3.Enum35477 field35487 = 4; + optional float field35488 = 5; + optional float field35489 = 6; + optional float field35490 = 7; + optional float field35491 = 8; + optional .benchmarks.google_message3.UnusedEmptyMessage field35492 = 9; + optional int32 field35493 = 10; + optional int32 field35494 = 11; + optional int32 field35495 = 12; + optional string field35496 = 13; + optional string field35497 = 14; +} + +message Message949 { + optional string field955 = 1; + optional int64 field956 = 2; + optional int64 field957 = 3; + optional .benchmarks.google_message3.Message730 field958 = 4; + repeated string field959 = 5; + optional string field960 = 6; + optional bool field961 = 7; +} + +message Message36869 { + optional int32 field36970 = 1; + optional int32 field36971 = 2; +} + +message Message33968 { + repeated group Message33969 = 1 {} + repeated .benchmarks.google_message3.Message33958 field33989 = 3; + optional .benchmarks.google_message3.UnusedEmptyMessage field33990 = 106; + optional bool field33991 = 108; + optional .benchmarks.google_message3.UnusedEnum field33992 = 107; +} + +message Message6644 { + optional .benchmarks.google_message3.UnusedEmptyMessage field6701 = 8; + optional string field6702 = 1; + optional double field6703 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field6704 = 9; + optional bytes field6705 = 3; + optional bytes field6706 = 19; + optional .benchmarks.google_message3.Message6637 field6707 = 4; + repeated .benchmarks.google_message3.Message6126 field6708 = 18; + optional bool field6709 = 6; + optional .benchmarks.google_message3.Message6643 field6710 = 10; + optional string field6711 = 12; + optional .benchmarks.google_message3.UnusedEmptyMessage field6712 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field6713 = 15; + optional .benchmarks.google_message3.UnusedEmptyMessage field6714 = 16; + optional int32 field6715 = 17; + optional .benchmarks.google_message3.UnusedEmptyMessage field6716 = 20; +} + +message Message18831 { + repeated group Message18832 = 1 { + optional int32 field18836 = 2; + optional string field18837 = 5; + optional float field18838 = 3; + optional float field18839 = 9; + optional int32 field18840 = 11; + repeated uint64 field18841 = 4; + repeated group Message18833 = 6 { + required uint64 field18843 = 7; + optional string field18844 = 8; + optional float field18845 = 10; + optional int32 field18846 = 12; + optional bool field18847 = 13; + } + } +} + +message Message13090 { + optional .benchmarks.google_message3.Message13083 field13141 = 1; + optional .benchmarks.google_message3.Message13088 field13142 = 2; +} + +message Message11874 { + optional .benchmarks.google_message3.Message10391 field11888 = 3; + optional string field11889 = 4; + optional .benchmarks.google_message3.Message11873 field11890 = 6; + optional bool field11891 = 7; + extensions 1 to 1; + extensions 2 to 2; + extensions 5 to 5; +} + +message Message4144 { + repeated group Message4145 = 1 { + required .benchmarks.google_message3.Enum4146 field4165 = 2; + required int32 field4166 = 3; + optional .benchmarks.google_message3.Enum4160 field4167 = 9; + optional bytes field4168 = 4; + optional .benchmarks.google_message3.Enum4152 field4169 = 5; + optional string field4170 = 6; + } +} + +message Message35573 { + optional fixed64 field35695 = 16; + optional string field35696 = 1000; + optional string field35697 = 1004; + optional int32 field35698 = 1003; + repeated group Message35574 = 1012 {} + optional int64 field35700 = 1011; + optional int64 field35701 = 1005; + optional int64 field35702 = 1006; + optional int64 field35703 = 1007; + optional int64 field35704 = 1008; + repeated group Message35575 = 1 { + optional int64 field35709 = 2; + optional string field35710 = 3; + optional string field35711 = 19; + optional int32 field35712 = 20; + optional int32 field35713 = 21; + optional int32 field35714 = 22; + optional bool field35715 = 23; + optional int32 field35716 = 47; + optional int32 field35717 = 48; + optional bool field35718 = 24; + optional fixed64 field35719 = 25; + optional bytes field35720 = 52; + optional int32 field35721 = 18; + optional fixed32 field35722 = 43; + optional bool field35723 = 26; + optional int32 field35724 = 27; + optional int32 field35725 = 17; + optional bool field35726 = 45; + repeated int32 field35727 = 33; + repeated int32 field35728 = 58; + optional float field35729 = 34; + optional float field35730 = 1009; + optional int32 field35731 = 28; + repeated fixed64 field35732 = 1001; + repeated fixed64 field35733 = 1002; + optional int32 field35734 = 44; + optional int32 field35735 = 50; + optional int32 field35736 = 36; + optional int32 field35737 = 40; + optional bool field35738 = 1016; + optional bool field35739 = 1010; + optional int32 field35740 = 37; + optional int32 field35741 = 38; + optional string field35742 = 46; + optional uint32 field35743 = 60; + repeated bytes field35744 = 56; + optional .benchmarks.google_message3.Message0 field35745 = 57; + required group Message35576 = 4 { + optional fixed64 field35747 = 5; + optional int32 field35748 = 6; + optional int32 field35749 = 49; + optional int32 field35750 = 7; + optional uint32 field35751 = 59; + optional int32 field35752 = 14; + optional int32 field35753 = 15; + optional int32 field35754 = 35; + optional bytes field35755 = 53; + optional int32 field35756 = 8; + optional string field35757 = 9; + optional fixed64 field35758 = 10; + optional int32 field35759 = 11; + optional int32 field35760 = 12; + optional int32 field35761 = 41; + optional int32 field35762 = 30; + optional int32 field35763 = 31; + optional int32 field35764 = 13; + optional bytes field35765 = 39; + optional string field35766 = 29; + optional int32 field35767 = 42; + repeated int32 field35768 = 32; + repeated int32 field35769 = 51; + optional int64 field35770 = 54; + optional .benchmarks.google_message3.Message0 field35771 = 55; + } + } +} + +message Message36858 { + repeated int32 field36956 = 1; + repeated string field36957 = 2; + repeated string field36958 = 12; + optional int32 field36959 = 3; + optional int32 field36960 = 4; + optional int32 field36961 = 14; + optional string field36962 = 11; + optional bool field36963 = 5; + optional bool field36964 = 13; + optional int64 field36965 = 6; + optional .benchmarks.google_message3.Message35506 field36966 = 7; + repeated group Message36859 = 8 { + required .benchmarks.google_message3.Enum36860 field36968 = 9; + optional float field36969 = 10; + } +} + +message Message13174 { + required int32 field13237 = 6; + optional int32 field13238 = 3; + required int32 field13239 = 4; + optional int32 field13240 = 8; + optional double field13241 = 5; + optional double field13242 = 7; + optional int32 field13243 = 17; + optional int32 field13244 = 19; + optional double field13245 = 20; + optional int32 field13246 = 9; + optional double field13247 = 10; + optional int32 field13248 = 11; + optional .benchmarks.google_message3.Message13151 field13249 = 21; + optional int32 field13250 = 1; + optional double field13251 = 2; + optional double field13252 = 15; + optional double field13253 = 16; + optional double field13254 = 12; + optional double field13255 = 13; + optional double field13256 = 14; + optional int32 field13257 = 18; +} + +message Message18283 { + optional .benchmarks.google_message3.UnusedEmptyMessage field18478 = 1; + optional int32 field18479 = 4; + optional int32 field18480 = 106; + optional int32 field18481 = 107; + optional int32 field18482 = 108; + optional int32 field18483 = 109; + optional int32 field18484 = 105; + optional int32 field18485 = 113; + optional int32 field18486 = 114; + optional int32 field18487 = 124; + optional int32 field18488 = 125; + optional int32 field18489 = 128; + optional int32 field18490 = 135; + optional bool field18491 = 166; + optional bool field18492 = 136; + optional int32 field18493 = 140; + optional int32 field18494 = 171; + optional int32 field18495 = 148; + optional int32 field18496 = 145; + optional float field18497 = 117; + optional int32 field18498 = 146; + optional string field18499 = 3; + optional .benchmarks.google_message3.UnusedEmptyMessage field18500 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field18501 = 6; + optional .benchmarks.google_message3.UnusedEmptyMessage field18502 = 9; + optional .benchmarks.google_message3.Message18253 field18503 = 155; + optional .benchmarks.google_message3.UnusedEmptyMessage field18504 = 184; + optional .benchmarks.google_message3.UnusedEmptyMessage field18505 = 163; + optional .benchmarks.google_message3.UnusedEmptyMessage field18506 = 16; + repeated int32 field18507 = 20; + repeated int32 field18508 = 7; + repeated string field18509 = 194; + optional bytes field18510 = 30; + optional int32 field18511 = 31; + optional .benchmarks.google_message3.UnusedEmptyMessage field18512 = 178; + optional string field18513 = 8; + optional float field18514 = 2; + optional float field18515 = 100; + optional float field18516 = 101; + optional float field18517 = 102; + optional int32 field18518 = 103; + repeated .benchmarks.google_message3.UnusedEmptyMessage field18519 = 104; + optional int32 field18520 = 110; + optional int32 field18521 = 112; + optional .benchmarks.google_message3.UnusedEmptyMessage field18522 = 111; + optional .benchmarks.google_message3.UnusedEmptyMessage field18523 = 115; + optional .benchmarks.google_message3.UnusedEmptyMessage field18524 = 119; + optional .benchmarks.google_message3.UnusedEmptyMessage field18525 = 127; + optional .benchmarks.google_message3.UnusedEmptyMessage field18526 = 185; + optional int32 field18527 = 120; + optional int32 field18528 = 132; + optional .benchmarks.google_message3.UnusedEmptyMessage field18529 = 126; + optional .benchmarks.google_message3.UnusedEmptyMessage field18530 = 129; + optional .benchmarks.google_message3.UnusedEmptyMessage field18531 = 131; + optional fixed64 field18532 = 150; + optional int32 field18533 = 133; + optional int32 field18534 = 134; + optional int32 field18535 = 139; + optional fixed64 field18536 = 137; + optional fixed64 field18537 = 138; + optional .benchmarks.google_message3.UnusedEmptyMessage field18538 = 141; + optional int32 field18539 = 142; + optional int32 field18540 = 181; + optional .benchmarks.google_message3.Message16816 field18541 = 143; + optional .benchmarks.google_message3.Message16685 field18542 = 154; + optional int32 field18543 = 144; + optional int64 field18544 = 147; + optional int64 field18545 = 149; + optional int32 field18546 = 151; + optional int32 field18547 = 152; + optional int32 field18548 = 153; + optional float field18549 = 161; + optional .benchmarks.google_message3.Message0 field18550 = 123; + repeated int64 field18551 = 156; + optional int32 field18552 = 157; + repeated fixed64 field18553 = 188; + optional int32 field18554 = 158; + optional .benchmarks.google_message3.UnusedEmptyMessage field18555 = 159; + optional bool field18556 = 160; + optional uint64 field18557 = 162; + optional int32 field18558 = 164; + optional .benchmarks.google_message3.UnusedEmptyMessage field18559 = 10; + optional .benchmarks.google_message3.UnusedEmptyMessage field18560 = 167; + optional int32 field18561 = 168; + repeated fixed64 field18562 = 169; + repeated string field18563 = 170; + optional .benchmarks.google_message3.UnusedEmptyMessage field18564 = 172; + optional int64 field18565 = 173; + optional .benchmarks.google_message3.UnusedEmptyMessage field18566 = 174; + optional int64 field18567 = 175; + optional uint32 field18568 = 189; + optional .benchmarks.google_message3.UnusedEmptyMessage field18569 = 176; + optional .benchmarks.google_message3.UnusedEmptyMessage field18570 = 177; + optional uint32 field18571 = 179; + optional uint32 field18572 = 180; + optional .benchmarks.google_message3.UnusedEmptyMessage field18573 = 182; + optional .benchmarks.google_message3.UnusedEmptyMessage field18574 = 183; + optional .benchmarks.google_message3.UnusedEmptyMessage field18575 = 121; + optional .benchmarks.google_message3.UnusedEmptyMessage field18576 = 186; + optional .benchmarks.google_message3.UnusedEmptyMessage field18577 = 187; + optional .benchmarks.google_message3.UnusedEmptyMessage field18578 = 190; + optional int32 field18579 = 191; + optional float field18580 = 192; + optional bool field18581 = 193; + extensions 116 to 116; + extensions 118 to 118; + extensions 130 to 130; + extensions 165 to 165; +} + +message Message13169 { + repeated .benchmarks.google_message3.Message13168 field13223 = 1; + required .benchmarks.google_message3.Message13167 field13224 = 2; + optional string field13225 = 3; +} + +message Message19255 { + optional string field19257 = 1; +} + +message Message35542 { + optional bool field35543 = 1; + optional bool field35544 = 2; + optional bool field35545 = 3; +} + +message Message3901 { + optional int32 field3990 = 1; + optional int32 field3991 = 2; + optional int32 field3992 = 3; + optional int32 field3993 = 4; + optional int32 field3994 = 7; + optional int32 field3995 = 8; + optional int32 field3996 = 9; + optional int32 field3997 = 10; + optional int32 field3998 = 11; + optional int32 field3999 = 12; + optional .benchmarks.google_message3.UnusedEnum field4000 = 6; + optional int32 field4001 = 5; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_3.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_3.proto new file mode 100644 index 0000000..2e534a6 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_3.proto @@ -0,0 +1,496 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_4.proto"; +import "datasets/google_message3/benchmark_message3_5.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message35546 { + optional int64 field35556 = 1; + optional int32 field35557 = 2; + optional bool field35558 = 3; + optional int64 field35559 = 13; + optional group Message35547 = 4 { + required int32 field35569 = 5; + required int32 field35570 = 6; + } + optional group Message35548 = 10 { + required int64 field35571 = 11; + required int64 field35572 = 12; + } + optional bool field35562 = 14; + optional bool field35563 = 15; + optional int32 field35564 = 16; + optional bool field35565 = 17; + optional bool field35566 = 18; + optional string field35567 = 100; +} + +message Message2356 { + optional .benchmarks.google_message3.Message1374 field2368 = 121; + optional uint64 field2369 = 1; + optional int32 field2370 = 2; + optional int32 field2371 = 17; + required string field2372 = 3; + optional int32 field2373 = 7; + optional bytes field2374 = 8; + optional string field2375 = 4; + optional string field2376 = 101; + optional int32 field2377 = 102; + optional int32 field2378 = 103; + optional int32 field2379 = 104; + optional int32 field2380 = 113; + optional int32 field2381 = 114; + optional int32 field2382 = 115; + optional int32 field2383 = 117; + optional int32 field2384 = 118; + optional int32 field2385 = 119; + optional int32 field2386 = 105; + optional bytes field2387 = 5; + optional group Message2357 = 6 { + optional int64 field2399 = 9; + optional int32 field2400 = 10; + optional int32 field2401 = 11; + optional int32 field2402 = 12; + optional int32 field2403 = 13; + optional int32 field2404 = 116; + optional int32 field2405 = 106; + required bytes field2406 = 14; + optional int32 field2407 = 45; + optional int32 field2408 = 112; + optional bool field2409 = 122; + optional bytes field2410 = 124; + } + optional string field2389 = 120; + optional group Message2358 = 107 {} + repeated group Message2359 = 40 { + optional string field2413 = 41; + optional string field2414 = 42; + optional string field2415 = 43; + optional string field2416 = 44; + optional int32 field2417 = 46; + optional string field2418 = 47; + optional float field2419 = 110; + optional float field2420 = 111; + } + optional int32 field2392 = 50; + optional .benchmarks.google_message3.UnusedEmptyMessage field2393 = 60; + optional .benchmarks.google_message3.UnusedEmptyMessage field2394 = 70; + optional .benchmarks.google_message3.UnusedEmptyMessage field2395 = 80; + optional .benchmarks.google_message3.UnusedEmptyMessage field2396 = 90; + optional string field2397 = 100; + optional string field2398 = 123; +} + +message Message7029 { + required int32 field7183 = 1; + optional int32 field7184 = 2; + optional int32 field7185 = 3; + optional int32 field7186 = 4; + optional int32 field7187 = 5; + optional int32 field7188 = 6; + optional int32 field7189 = 17; + optional int32 field7190 = 18; + optional int32 field7191 = 49; + optional int32 field7192 = 28; + optional int32 field7193 = 33; + optional int32 field7194 = 25; + optional int32 field7195 = 26; + optional int32 field7196 = 40; + optional int32 field7197 = 41; + optional int32 field7198 = 42; + optional int32 field7199 = 43; + optional int32 field7200 = 19; + optional int32 field7201 = 7; + optional int32 field7202 = 8; + optional int32 field7203 = 9; + optional int32 field7204 = 10; + optional int32 field7205 = 11; + optional int32 field7206 = 12; + repeated group Message7030 = 13 { + optional string field7226 = 14; + optional string field7227 = 15; + optional int64 field7228 = 16; + } + repeated group Message7031 = 21 { + optional string field7229 = 22; + optional int32 field7230 = 23; + optional int32 field7231 = 24; + optional int32 field7232 = 30; + optional int32 field7233 = 31; + optional int32 field7234 = 35; + } + optional int32 field7209 = 20; + optional float field7210 = 27; + optional int32 field7211 = 29; + optional int32 field7212 = 32; + optional string field7213 = 48; + optional bool field7214 = 34; + optional int32 field7215 = 36; + optional float field7216 = 37; + optional bool field7217 = 38; + optional bool field7218 = 39; + optional .benchmarks.google_message3.UnusedEmptyMessage field7219 = 44; + optional int32 field7220 = 45; + optional int32 field7221 = 46; + optional int32 field7222 = 47; + optional .benchmarks.google_message3.UnusedEmptyMessage field7223 = 50; + optional int32 field7224 = 51; +} + +message Message35538 { + required int64 field35539 = 1; +} + +message Message18921 { + optional string field18946 = 1; + optional fixed64 field18947 = 2; + optional int32 field18948 = 3; + optional double field18949 = 4; + optional bool field18950 = 17; + optional bool field18951 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field18952 = 24; + repeated group Message18922 = 5 { + optional uint64 field18959 = 6; + optional string field18960 = 13; + optional bool field18961 = 21; + optional bool field18962 = 33; + optional int32 field18963 = 7; + optional int32 field18964 = 8; + optional string field18965 = 9; + optional .benchmarks.google_message3.Message18856 field18966 = 10; + optional uint64 field18967 = 34; + optional .benchmarks.google_message3.UnusedEmptyMessage field18968 = 11; + optional uint64 field18969 = 35; + optional float field18970 = 12; + repeated string field18971 = 14; + optional bool field18972 = 15; + optional bool field18973 = 16; + optional float field18974 = 22; + optional int32 field18975 = 18; + optional int32 field18976 = 19; + optional int32 field18977 = 20; + optional .benchmarks.google_message3.UnusedEmptyMessage field18978 = 25; + optional .benchmarks.google_message3.UnusedEnum field18979 = 26; + repeated string field18980 = 27; + optional float field18981 = 28; + } + repeated .benchmarks.google_message3.UnusedEmptyMessage field18954 = 29; + repeated .benchmarks.google_message3.Message18943 field18955 = 30; + repeated .benchmarks.google_message3.Message18944 field18956 = 31; + repeated .benchmarks.google_message3.UnusedEmptyMessage field18957 = 32; +} + +message Message35540 { + optional bool field35541 = 1; +} + +message Message3886 { + repeated group Message3887 = 1 { + required string field3932 = 2; + optional string field3933 = 9; + optional .benchmarks.google_message3.Message3850 field3934 = 3; + optional bytes field3935 = 8; + } +} + +message Message6743 { + optional .benchmarks.google_message3.Message6721 field6759 = 1; + optional .benchmarks.google_message3.Message6723 field6760 = 2; + optional .benchmarks.google_message3.Message6723 field6761 = 8; + optional .benchmarks.google_message3.Message6725 field6762 = 3; + optional .benchmarks.google_message3.Message6726 field6763 = 4; + optional .benchmarks.google_message3.Message6733 field6764 = 5; + optional .benchmarks.google_message3.Message6734 field6765 = 6; + optional .benchmarks.google_message3.Message6742 field6766 = 7; +} + +message Message6773 { + optional .benchmarks.google_message3.Enum6769 field6794 = 1; + optional int32 field6795 = 9; + optional .benchmarks.google_message3.UnusedEnum field6796 = 10; + optional int32 field6797 = 11; + optional int32 field6798 = 2; + optional .benchmarks.google_message3.Enum6774 field6799 = 3; + optional double field6800 = 5; + optional double field6801 = 7; + optional double field6802 = 8; + optional .benchmarks.google_message3.Enum6782 field6803 = 6; +} + +message Message8224 { + optional .benchmarks.google_message3.UnusedEmptyMessage field8255 = 1; + optional .benchmarks.google_message3.Message8184 field8256 = 2; + optional .benchmarks.google_message3.Message7966 field8257 = 3; + optional string field8258 = 4; + optional string field8259 = 5; + optional bool field8260 = 6; + optional int64 field8261 = 7; + optional string field8262 = 8; + optional int64 field8263 = 9; + optional double field8264 = 10; + optional int64 field8265 = 11; + repeated string field8266 = 12; + optional int64 field8267 = 13; + optional int32 field8268 = 14; + optional int32 field8269 = 15; + optional int64 field8270 = 16; + optional double field8271 = 17; + optional .benchmarks.google_message3.UnusedEmptyMessage field8272 = 18; + optional .benchmarks.google_message3.UnusedEmptyMessage field8273 = 19; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8274 = 20; + optional bool field8275 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field8276 = 22; + optional .benchmarks.google_message3.UnusedEmptyMessage field8277 = 23; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8278 = 24; + optional .benchmarks.google_message3.UnusedEmptyMessage field8279 = 25; + optional bool field8280 = 26; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8281 = 27; +} + +message Message8392 { + optional string field8395 = 1; + optional string field8396 = 2; + optional .benchmarks.google_message3.Message7966 field8397 = 3; + optional string field8398 = 4; + optional string field8399 = 5; + optional string field8400 = 6; + optional string field8401 = 7; + optional string field8402 = 8; + optional string field8403 = 9; +} + +message Message8130 { + optional string field8156 = 1; + optional string field8157 = 2; + optional string field8158 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field8159 = 6; + repeated string field8160 = 7; + optional int64 field8161 = 8; + optional .benchmarks.google_message3.UnusedEmptyMessage field8162 = 9; + optional string field8163 = 10; + optional string field8164 = 11; + optional string field8165 = 12; + optional string field8166 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field8167 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field8168 = 15; + optional string field8169 = 16; + optional .benchmarks.google_message3.UnusedEnum field8170 = 17; + optional .benchmarks.google_message3.UnusedEnum field8171 = 18; + optional bool field8172 = 19; + optional bool field8173 = 20; + optional double field8174 = 21; + optional int32 field8175 = 22; + optional int32 field8176 = 23; + optional .benchmarks.google_message3.UnusedEmptyMessage field8177 = 24; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8178 = 25; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8179 = 26; +} + +message Message8478 { + optional string field8489 = 7; + optional .benchmarks.google_message3.Message7966 field8490 = 1; + optional .benchmarks.google_message3.Message8476 field8491 = 2; + optional int64 field8492 = 3; + optional .benchmarks.google_message3.Message8476 field8493 = 4; + repeated .benchmarks.google_message3.Message8477 field8494 = 5; + optional .benchmarks.google_message3.Message8454 field8495 = 6; + optional .benchmarks.google_message3.UnusedEmptyMessage field8496 = 8; +} + +message Message8479 { + optional .benchmarks.google_message3.Message8475 field8497 = 1; + optional .benchmarks.google_message3.Message7966 field8498 = 2; + optional .benchmarks.google_message3.Message8476 field8499 = 3; + optional .benchmarks.google_message3.Message8476 field8500 = 4; + optional string field8501 = 6; + optional string field8502 = 7; + optional .benchmarks.google_message3.Message7966 field8503 = 8; + optional .benchmarks.google_message3.Message8455 field8504 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field8505 = 9; +} + +message Message10319 { + optional .benchmarks.google_message3.Enum10325 field10340 = 1; + optional int32 field10341 = 4; + optional int32 field10342 = 5; + optional bytes field10343 = 3; + optional string field10344 = 2; + optional string field10345 = 6; + optional string field10346 = 7; +} + +message Message4016 { + required int32 field4017 = 1; + required int32 field4018 = 2; + required int32 field4019 = 3; + required int32 field4020 = 4; +} + +message Message12669 { + optional .benchmarks.google_message3.Message12559 field12681 = 1; + optional float field12682 = 2; + optional bool field12683 = 3; + optional .benchmarks.google_message3.Enum12670 field12684 = 4; +} + +message Message12819 { + optional double field12834 = 1; + optional double field12835 = 2; + optional double field12836 = 3; + optional double field12837 = 4; + optional double field12838 = 5; + optional double field12839 = 6; +} + +message Message12820 { + optional int32 field12840 = 1; + optional int32 field12841 = 2; + optional int32 field12842 = 3; + optional int32 field12843 = 8; + optional int32 field12844 = 4; + optional int32 field12845 = 5; + optional int32 field12846 = 6; + optional int32 field12847 = 7; +} + +message Message12821 { + optional int32 field12848 = 1; + optional int32 field12849 = 2; + optional int32 field12850 = 3; + optional int32 field12851 = 4; + optional int32 field12852 = 5; +} + +message Message12818 { + optional uint64 field12829 = 1; + optional int32 field12830 = 2; + optional int32 field12831 = 3; + optional int32 field12832 = 5; + repeated .benchmarks.google_message3.Message12817 field12833 = 4; +} + +message Message16479 { + optional .benchmarks.google_message3.Message16480 field16484 = 1; + optional int32 field16485 = 5; + optional float field16486 = 2; + optional uint32 field16487 = 4; + optional bool field16488 = 3; + optional uint32 field16489 = 6; +} + +message Message16722 { + optional string field16752 = 1; + optional string field16753 = 2; + optional string field16754 = 3; + optional int32 field16755 = 5; + optional string field16756 = 4; +} + +message Message16724 { + optional int64 field16761 = 1; + optional float field16762 = 2; + optional int64 field16763 = 3; + optional int64 field16764 = 4; + optional bool field16765 = 5; + repeated string field16766 = 6; + repeated string field16767 = 7; + optional .benchmarks.google_message3.UnusedEmptyMessage field16768 = 8; + optional bool field16769 = 9; + optional uint32 field16770 = 10; + optional .benchmarks.google_message3.Enum16728 field16771 = 11; + repeated int32 field16772 = 12; + optional bool field16773 = 13; +} + +message Message17728 {} + +message Message24356 { + optional string field24559 = 1; + optional string field24560 = 2; + optional int32 field24561 = 14; + optional string field24562 = 3; + optional string field24563 = 4; + optional string field24564 = 5; + optional .benchmarks.google_message3.UnusedEnum field24565 = 13; + optional string field24566 = 6; + optional .benchmarks.google_message3.Enum24361 field24567 = 12; + optional string field24568 = 7; + optional string field24569 = 8; + optional string field24570 = 9; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24571 = 10; + repeated string field24572 = 11; + repeated string field24573 = 15; +} + +message Message24376 { + optional string field24589 = 1; + optional string field24590 = 2; + optional string field24591 = 3; + required .benchmarks.google_message3.Message24377 field24592 = 4; + optional .benchmarks.google_message3.Message24317 field24593 = 5; + optional string field24594 = 6; + optional .benchmarks.google_message3.Message24378 field24595 = 7; + repeated string field24596 = 8; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24597 = 14; + repeated string field24598 = 9; + repeated string field24599 = 10; + repeated string field24600 = 11; + optional string field24601 = 12; + repeated string field24602 = 13; +} + +message Message24366 { + optional string field24574 = 1; + optional string field24575 = 2; + optional string field24576 = 3; + optional int32 field24577 = 10; + optional string field24578 = 13; + optional string field24579 = 4; + optional string field24580 = 5; + optional .benchmarks.google_message3.UnusedEnum field24581 = 9; + optional string field24582 = 14; + optional .benchmarks.google_message3.UnusedEnum field24583 = 15; + optional string field24584 = 6; + optional string field24585 = 12; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24586 = 7; + repeated string field24587 = 8; + repeated string field24588 = 11; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_4.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_4.proto new file mode 100644 index 0000000..b304148 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_4.proto @@ -0,0 +1,514 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_5.proto"; +import "datasets/google_message3/benchmark_message3_6.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message24346 {} + +message Message24401 { + optional .benchmarks.google_message3.Message24400 field24679 = 1; +} + +message Message24402 { + optional .benchmarks.google_message3.Message24400 field24680 = 1; +} + +message Message24379 { + optional string field24603 = 1; + optional string field24604 = 2; + optional string field24605 = 3; + required .benchmarks.google_message3.Message24380 field24606 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field24607 = 5; + optional string field24608 = 6; + optional .benchmarks.google_message3.Message24381 field24609 = 7; + repeated string field24610 = 8; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24611 = 17; + repeated string field24612 = 9; + repeated string field24613 = 10; + repeated string field24614 = 11; + optional string field24615 = 14; + optional string field24616 = 12; + optional string field24617 = 16; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24618 = 13; + repeated string field24619 = 15; + repeated string field24620 = 18; +} + +message Message27358 { + optional int32 field27415 = 1; + optional int32 field27416 = 2; +} + +message Message34381 { + optional string field34398 = 1; + optional .benchmarks.google_message3.UnusedEmptyMessage field34399 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field34400 = 3; + optional .benchmarks.google_message3.UnusedEmptyMessage field34401 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field34402 = 5; + optional bool field34403 = 6; + optional bool field34404 = 7; + optional .benchmarks.google_message3.UnusedEmptyMessage field34405 = 8; + optional bool field34406 = 9; + optional .benchmarks.google_message3.UnusedEmptyMessage field34407 = 10; +} + +message Message34619 { + optional double field34641 = 1; + optional double field34642 = 2; + optional double field34643 = 3; + optional double field34644 = 4; + optional double field34645 = 11; + optional double field34646 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field34647 = 100; +} + +message Message730 { + optional string field897 = 19; + repeated string field898 = 27; + repeated string field899 = 28; + repeated string field900 = 21; + optional string field901 = 30; + repeated uint32 field902 = 20; + repeated uint32 field903 = 32; + repeated string field904 = 16; + repeated .benchmarks.google_message3.Message697 field905 = 6; + repeated .benchmarks.google_message3.Message704 field906 = 7; + repeated string field907 = 18; + repeated .benchmarks.google_message3.Message703 field908 = 8; + repeated string field909 = 9; + optional .benchmarks.google_message3.Message716 field910 = 10; + optional .benchmarks.google_message3.Message718 field911 = 11; + optional bool field912 = 14; + repeated .benchmarks.google_message3.Message715 field913 = 4; + repeated string field914 = 17; + repeated string field915 = 23; + repeated .benchmarks.google_message3.Message719 field916 = 24; + repeated .benchmarks.google_message3.Message728 field917 = 26; + repeated .benchmarks.google_message3.Message702 field918 = 35; + optional string field919 = 36; + repeated string field920 = 37; + optional int64 field921 = 38; + repeated .benchmarks.google_message3.UnusedEmptyMessage field922 = 39; + repeated .benchmarks.google_message3.UnusedEmptyMessage field923 = 1; + optional .benchmarks.google_message3.UnusedEmptyMessage field924 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field925 = 3; + optional .benchmarks.google_message3.UnusedEmptyMessage field926 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field927 = 13; + repeated string field928 = 22; + optional bytes field929 = 31; + extensions 25 to 25; + extensions 29 to 29; + extensions 34 to 34; + extensions 15 to 15; +} + +message Message33958 { + optional string field33977 = 1; + optional string field33978 = 9; + repeated group Message33959 = 2 { + required string field33982 = 3; + optional string field33983 = 4; + optional string field33984 = 5; + optional fixed64 field33985 = 8; + optional bool field33986 = 10; + optional .benchmarks.google_message3.Message0 field33987 = 6; + } + optional .benchmarks.google_message3.Enum33960 field33980 = 7; + extend .benchmarks.google_message3.Message0 { + optional .benchmarks.google_message3.Message33958 field33981 = 10747482; + } +} + +message Message6637 { + optional .benchmarks.google_message3.UnusedEmptyMessage field6670 = 2; + repeated .benchmarks.google_message3.UnusedEmptyMessage field6671 = 1; + optional int32 field6672 = 3; + repeated string field6673 = 4; + optional .benchmarks.google_message3.UnusedEmptyMessage field6674 = 5; +} + +message Message6643 { + optional .benchmarks.google_message3.UnusedEmptyMessage field6683 = 3; + optional .benchmarks.google_message3.UnusedEmptyMessage field6684 = 4; + optional double field6685 = 5; + optional double field6686 = 6; + optional int32 field6687 = 1; + optional int32 field6688 = 2; + optional double field6689 = 9; + optional bytes field6690 = 10; + optional int32 field6691 = 11; + optional bool field6692 = 12; + optional bool field6693 = 13; + optional .benchmarks.google_message3.Message6578 field6694 = 15; + optional .benchmarks.google_message3.UnusedEnum field6695 = 16; + optional int64 field6696 = 17; + repeated .benchmarks.google_message3.UnusedEmptyMessage field6697 = 22; + optional .benchmarks.google_message3.UnusedEmptyMessage field6698 = 19; + optional .benchmarks.google_message3.UnusedEmptyMessage field6699 = 20; + optional int32 field6700 = 21; +} + +message Message6126 { + required string field6152 = 1; + repeated .benchmarks.google_message3.UnusedEmptyMessage field6153 = 9; + optional int32 field6154 = 14; + optional bytes field6155 = 10; + optional .benchmarks.google_message3.Message6024 field6156 = 12; + optional int32 field6157 = 4; + optional string field6158 = 5; + optional int32 field6159 = 6; + repeated int32 field6160 = 2; + repeated int32 field6161 = 3; + repeated .benchmarks.google_message3.Message6052 field6162 = 7; + repeated .benchmarks.google_message3.UnusedEmptyMessage field6163 = 11; + optional .benchmarks.google_message3.Enum6065 field6164 = 15; + repeated .benchmarks.google_message3.UnusedEmptyMessage field6165 = 8; + optional bool field6166 = 13; + optional bool field6167 = 16; + optional bool field6168 = 18; + repeated .benchmarks.google_message3.Message6054 field6169 = 17; + optional int32 field6170 = 19; +} + +message Message13083 { + optional float field13096 = 1; + repeated group Message13084 = 2 { + required float field13107 = 3; + required int32 field13108 = 4; + optional float field13109 = 5; + repeated .benchmarks.google_message3.Enum13092 field13110 = 6; + } + optional float field13098 = 44; + optional float field13099 = 45; + optional uint64 field13100 = 46; + optional float field13101 = 47; + optional group Message13085 = 16 {} + repeated group Message13086 = 23 {} + repeated group Message13087 = 29 {} + optional .benchmarks.google_message3.UnusedEmptyMessage field13105 = 43; +} + +message Message13088 { + repeated group Message13089 = 1 { + required string field13139 = 2; + optional float field13140 = 3; + } + optional int64 field13136 = 4; + optional bool field13137 = 5; +} + +message Message10391 { + optional .benchmarks.google_message3.Enum10392 field10411 = 1; + optional .benchmarks.google_message3.UnusedEnum field10412 = 2; + optional int64 field10413 = 3; + optional string field10414 = 4; + optional string field10415 = 5; + optional bytes field10416 = 6; + optional bool field10417 = 8; + optional .benchmarks.google_message3.UnusedEmptyMessage field10418 = 9; + optional bool field10419 = 10; +} + +message Message11873 { + optional string field11876 = 1; + optional string field11877 = 4; + optional .benchmarks.google_message3.Message10573 field11878 = 5; + optional .benchmarks.google_message3.Message10582 field11879 = 6; + optional .benchmarks.google_message3.Message10824 field11880 = 7; + optional .benchmarks.google_message3.Message10773 field11881 = 12; + optional .benchmarks.google_message3.Message11866 field11882 = 8; + optional .benchmarks.google_message3.Message10818 field11883 = 13; + optional .benchmarks.google_message3.UnusedEmptyMessage field11884 = 16; + optional .benchmarks.google_message3.Message10155 field11885 = 11; + optional .benchmarks.google_message3.Message10469 field11886 = 14; + optional .benchmarks.google_message3.UnusedEmptyMessage field11887 = 15; + extensions 9 to 9; + extensions 10 to 10; +} + +message Message35506 { + optional int32 field35524 = 1; + optional string field35525 = 2; + optional .benchmarks.google_message3.Enum35507 field35526 = 3; + repeated .benchmarks.google_message3.UnusedEmptyMessage field35527 = 4; +} + +message Message13151 { + repeated .benchmarks.google_message3.Message13145 field13158 = 1; +} + +message Message18253 { + repeated group Message18254 = 1 { + required fixed64 field18362 = 2; + required double field18363 = 3; + } +} + +message Message16685 { + repeated .benchmarks.google_message3.Message16686 field16694 = 2; +} + +message Message16816 { + optional float field16826 = 1; + optional .benchmarks.google_message3.Enum16819 field16827 = 2; + optional float field16828 = 3; + repeated group Message16817 = 4 {} + optional bool field16830 = 7; + optional bool field16831 = 8; + repeated group Message16818 = 12 {} + optional string field16833 = 10; + optional bool field16834 = 13; + optional bool field16835 = 14; +} + +message Message13168 { + required int32 field13212 = 1; + optional fixed64 field13213 = 7; + optional bool field13214 = 8; + optional fixed64 field13215 = 10; + optional bool field13216 = 11; + optional .benchmarks.google_message3.Message12796 field13217 = 9; + required double field13218 = 2; + required bool field13219 = 3; + optional int32 field13220 = 4; + required bool field13221 = 5; + optional int32 field13222 = 6; +} + +message Message13167 { + required int32 field13199 = 1; + optional int32 field13200 = 2; + optional int32 field13201 = 3; + optional bool field13202 = 8; + optional fixed64 field13203 = 12; + optional bool field13204 = 13; + optional .benchmarks.google_message3.Message12796 field13205 = 11; + optional fixed64 field13206 = 9; + optional bool field13207 = 10; + repeated int32 field13208 = 4; + optional int32 field13209 = 5; + optional int32 field13210 = 6; + optional int32 field13211 = 7; +} + +message Message1374 { + required string field1375 = 1; + optional string field1376 = 2; +} + +message Message18943 {} + +message Message18944 {} + +message Message18856 { + optional string field18857 = 1; + optional string field18858 = 2; + optional bool field18859 = 31; + optional string field18860 = 26; + optional string field18861 = 3; + optional string field18862 = 4; + optional string field18863 = 5; + optional string field18864 = 17; + optional string field18865 = 6; + optional string field18866 = 7; + optional string field18867 = 8; + optional string field18868 = 9; + optional string field18869 = 10; + optional string field18870 = 11; + optional string field18871 = 21; + optional string field18872 = 18; + optional string field18873 = 19; + optional string field18874 = 20; + optional string field18875 = 22; + optional string field18876 = 23; + optional string field18877 = 24; + optional string field18878 = 25; + optional string field18879 = 12; + optional string field18880 = 13; + optional string field18881 = 29; + optional string field18882 = 30; + optional string field18883 = 15; + optional string field18884 = 16; + repeated string field18885 = 14; + optional string field18886 = 27; + optional string field18887 = 28; +} + +message Message3850 { + optional .benchmarks.google_message3.Enum3851 field3924 = 2; + optional bool field3925 = 12; + optional int32 field3926 = 4; + optional bool field3927 = 10; + optional bool field3928 = 13; + optional bool field3929 = 14; +} + +message Message6721 { + optional .benchmarks.google_message3.Message6722 field6744 = 1; + optional bool field6745 = 2; + optional bool field6746 = 3; + optional bool field6747 = 4; +} + +message Message6742 { + optional bool field6758 = 1; +} + +message Message6726 { + optional int64 field6752 = 1; + repeated .benchmarks.google_message3.Message6727 field6753 = 2; +} + +message Message6733 { + optional int64 field6754 = 1; + optional int64 field6755 = 2; + optional bool field6756 = 3; +} + +message Message6723 { + optional int64 field6748 = 1; + repeated .benchmarks.google_message3.Message6724 field6749 = 2; +} + +message Message6725 { + optional int32 field6750 = 1; + optional int32 field6751 = 2; +} + +message Message6734 { + repeated .benchmarks.google_message3.Message6735 field6757 = 1; +} + +message Message8184 { + optional .benchmarks.google_message3.Message7966 field8228 = 1; + optional bool field8229 = 2; + repeated .benchmarks.google_message3.Message8183 field8230 = 3; +} + +message Message8477 { + optional .benchmarks.google_message3.Message7966 field8486 = 1; + optional int64 field8487 = 2; + optional string field8488 = 3; +} + +message Message8454 { + optional .benchmarks.google_message3.Message8449 field8465 = 1; + optional int64 field8466 = 3; + optional int32 field8467 = 4; + optional bool field8468 = 5; + extend .benchmarks.google_message3.Message8301 { + optional .benchmarks.google_message3.Message8454 field8469 = 66; + } +} + +message Message8476 { + optional string field8483 = 1; + optional string field8484 = 2; + optional string field8485 = 3; +} + +message Message8455 { + optional .benchmarks.google_message3.Message8449 field8470 = 1; + repeated .benchmarks.google_message3.Message8456 field8471 = 2; + optional .benchmarks.google_message3.Message8457 field8472 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field8473 = 6; + extend .benchmarks.google_message3.Message8302 { + optional .benchmarks.google_message3.Message8455 field8474 = 66; + } +} + +message Message8475 { + optional string field8481 = 1; + optional int64 field8482 = 2; +} + +message Message12559 {} + +message Message12817 { + optional int32 field12826 = 1; + optional int32 field12827 = 2; + optional int32 field12828 = 3; +} + +message Message16480 { + optional .benchmarks.google_message3.Message13358 field16490 = 1; + optional .benchmarks.google_message3.Enum16042 field16491 = 2; + optional .benchmarks.google_message3.Message13912 field16492 = 3; + optional string field16493 = 4; + optional string field16494 = 5; + optional string field16495 = 6; + optional string field16496 = 7; + optional .benchmarks.google_message3.Message13358 field16497 = 8; + optional fixed32 field16498 = 9; +} + +message Message24317 { + optional string field24446 = 1; + optional .benchmarks.google_message3.Message24312 field24447 = 2; + repeated .benchmarks.google_message3.Message24315 field24448 = 3; + repeated .benchmarks.google_message3.Message24313 field24449 = 4; + repeated .benchmarks.google_message3.Message24316 field24450 = 5; + repeated .benchmarks.google_message3.UnusedEmptyMessage field24451 = 6; + optional .benchmarks.google_message3.UnusedEmptyMessage field24452 = 7; + repeated string field24453 = 8; + repeated string field24454 = 9; + repeated string field24455 = 10; + repeated string field24456 = 28; + optional string field24457 = 11; + optional string field24458 = 12; + optional string field24459 = 13; + optional string field24460 = 14; + repeated string field24461 = 15; + optional string field24462 = 16; + repeated string field24463 = 17; + repeated string field24464 = 18; + repeated string field24465 = 19; + repeated string field24466 = 20; + repeated string field24467 = 21; + repeated string field24468 = 22; + repeated string field24469 = 23; + repeated string field24470 = 24; + optional string field24471 = 25; + optional string field24472 = 26; + repeated string field24473 = 27; + optional bool field24474 = 40; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_5.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_5.proto new file mode 100644 index 0000000..e72d7ee --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_5.proto @@ -0,0 +1,496 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_6.proto"; +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message24377 {} + +message Message24378 {} + +message Message24400 { + optional int32 field24674 = 1; + optional int32 field24675 = 2; + optional int32 field24676 = 3; + optional int32 field24677 = 4; + optional int32 field24678 = 5; +} + +message Message24380 {} + +message Message24381 {} + +message Message719 { + repeated string field881 = 1; + repeated string field882 = 2; + repeated string field883 = 3; + optional .benchmarks.google_message3.Enum720 field884 = 4; +} + +message Message728 { + required string field887 = 1; + repeated string field888 = 2; + repeated .benchmarks.google_message3.Message703 field889 = 3; + repeated .benchmarks.google_message3.Message715 field890 = 4; + repeated string field891 = 5; + repeated string field892 = 6; + optional .benchmarks.google_message3.Message718 field893 = 7; + optional .benchmarks.google_message3.Message716 field894 = 8; + repeated string field895 = 9; + extensions 10 to 10; + extensions 11 to 11; + extensions 12 to 12; +} + +message Message704 { + optional string field800 = 1; + optional string field801 = 7; + optional string field802 = 2; + optional string field803 = 3; + optional string field804 = 4; + optional string field805 = 5; + optional .benchmarks.google_message3.UnusedEmptyMessage field806 = 6; +} + +message Message697 { + optional string field743 = 7; + repeated string field744 = 1; + repeated string field745 = 2; + repeated string field746 = 33; + repeated string field747 = 29; + repeated string field748 = 30; + repeated string field749 = 31; + repeated string field750 = 32; + repeated string field751 = 13; + repeated string field752 = 6; + repeated string field753 = 3; + repeated string field754 = 14; + repeated string field755 = 15; + repeated string field756 = 16; + repeated string field757 = 4; + repeated string field758 = 34; + repeated string field759 = 35; + repeated string field760 = 5; + repeated string field761 = 17; + repeated string field762 = 18; + repeated string field763 = 19; + optional bool field764 = 36; + repeated string field765 = 8; + repeated string field766 = 9; + optional string field767 = 27; + optional bool field768 = 25; + optional .benchmarks.google_message3.Message700 field769 = 10; + optional bool field770 = 11; + optional bool field771 = 24; + repeated string field772 = 12; + repeated string field773 = 20; + repeated string field774 = 21; + repeated string field775 = 22; + repeated .benchmarks.google_message3.Message699 field776 = 23; + repeated .benchmarks.google_message3.Message698 field777 = 37; + optional int64 field778 = 38; + extensions 28 to 28; + extensions 26 to 26; +} + +message Message0 { + option message_set_wire_format = true; + + extensions 4 to 2147483646; +} + +message Message6578 { + optional .benchmarks.google_message3.Enum6579 field6632 = 1; + optional .benchmarks.google_message3.Enum6588 field6633 = 2; +} + +message Message6024 { + optional .benchmarks.google_message3.Enum6025 field6048 = 1; + optional string field6049 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field6050 = 3; +} + +message Message6052 { + required string field6084 = 1; + required bytes field6085 = 2; +} + +message Message6054 { + required string field6089 = 1; + optional string field6090 = 2; +} + +message Message10573 { + repeated .benchmarks.google_message3.Message10576 field10580 = 1; + optional string field10581 = 2; + extensions 10000 to 536870911; +} + +message Message10824 { + required string field10825 = 1; + optional int32 field10826 = 2; +} + +message Message10582 { + required bool field10583 = 1; + required double field10584 = 2; + optional bool field10585 = 3; + optional double field10586 = 4; + optional double field10587 = 5; + optional bool field10588 = 6; +} + +message Message10155 { + required int32 field10195 = 1; + required int32 field10196 = 2; + optional .benchmarks.google_message3.Enum10157 field10197 = 59; + optional int32 field10198 = 18; + optional int32 field10199 = 19; + optional int32 field10200 = 21; + repeated group Message10156 = 50 { + optional .benchmarks.google_message3.Enum8862 field10266 = 51; + optional int32 field10267 = 52; + optional int32 field10268 = 53; + optional int32 field10269 = 54; + } + optional int32 field10202 = 3; + optional int32 field10203 = 4; + optional int32 field10204 = 5; + optional bool field10205 = 84; + optional bool field10206 = 33; + optional int32 field10207 = 75; + optional float field10208 = 26; + optional int32 field10209 = 27; + optional int32 field10210 = 49; + optional int32 field10211 = 10; + optional float field10212 = 78; + optional .benchmarks.google_message3.Message9151 field10213 = 91; + optional int32 field10214 = 11; + optional int32 field10215 = 12; + optional float field10216 = 41; + optional .benchmarks.google_message3.Message10154 field10217 = 61; + optional int32 field10218 = 23; + optional bytes field10219 = 24; + optional int32 field10220 = 65; + repeated bytes field10221 = 66; + optional int32 field10222 = 70; + optional bytes field10223 = 71; + repeated fixed64 field10224 = 73; + optional float field10225 = 29; + optional int32 field10226 = 30; + optional float field10227 = 31; + optional int32 field10228 = 32; + optional float field10229 = 34; + optional int32 field10230 = 35; + optional string field10231 = 22; + optional fixed64 field10232 = 13; + optional fixed64 field10233 = 20; + optional bool field10234 = 79; + repeated .benchmarks.google_message3.Enum10167 field10235 = 80 + [packed = true]; + optional int32 field10236 = 14; + optional int32 field10237 = 15; + optional int32 field10238 = 28; + repeated string field10239 = 16; + optional .benchmarks.google_message3.Message9182 field10240 = 17; + optional int32 field10241 = 63; + optional float field10242 = 64; + optional float field10243 = 37; + repeated float field10244 = 43; + optional int32 field10245 = 44; + optional .benchmarks.google_message3.Message9242 field10246 = 45; + optional .benchmarks.google_message3.UnusedEmptyMessage field10247 = 46; + optional .benchmarks.google_message3.UnusedEmptyMessage field10248 = 62; + optional .benchmarks.google_message3.Message8944 field10249 = 48; + optional .benchmarks.google_message3.UnusedEmptyMessage field10250 = 87; + optional int32 field10251 = 58; + optional int32 field10252 = 92; + optional .benchmarks.google_message3.Message9123 field10253 = 93; + optional .benchmarks.google_message3.Message9160 field10254 = 60; + optional .benchmarks.google_message3.Message8890 field10255 = 67; + optional string field10256 = 69; + optional int64 field10257 = 74; + optional float field10258 = 82; + optional float field10259 = 85; + optional float field10260 = 86; + optional int64 field10261 = 83; + optional string field10262 = 77; + optional bool field10263 = 88; + repeated .benchmarks.google_message3.Message9628 field10264 = 94; + extensions 57 to 57; + extensions 1000 to 536870911; +} + +message Message11866 { + required .benchmarks.google_message3.Message11014 field11868 = 1; + optional bool field11869 = 2; + optional double field11870 = 3; + optional double field11871 = 4; + repeated .benchmarks.google_message3.UnusedEmptyMessage field11872 = 5; +} + +message Message10469 { + optional string field10473 = 1; + optional float field10474 = 2; + optional int32 field10475 = 3; + optional int32 field10476 = 4; + optional int32 field10477 = 5; + optional bool field10478 = 6; + optional bool field10479 = 7; + optional int32 field10480 = 8; + optional float field10481 = 9; +} + +message Message10818 { + optional .benchmarks.google_message3.Message10800 field10819 = 1; + optional .benchmarks.google_message3.Message10801 field10820 = 2; +} + +message Message10773 { + optional bool field10774 = 9; + optional bool field10775 = 1; + optional bool field10776 = 23; + optional bool field10777 = 2; + optional bool field10778 = 3; + optional int32 field10779 = 4; + optional int32 field10780 = 5; + optional int32 field10781 = 6; + optional int32 field10782 = 7; + optional int32 field10783 = 8; + optional int32 field10784 = 10; + optional .benchmarks.google_message3.Message10749 field10785 = 11; + repeated .benchmarks.google_message3.UnusedEmptyMessage field10786 = 12; + optional bool field10787 = 13; + optional bool field10788 = 15; + optional bool field10789 = 16; + optional int32 field10790 = 17; + optional int32 field10791 = 18; + optional bool field10792 = 19; + optional bool field10793 = 20; + optional bool field10794 = 21; + optional .benchmarks.google_message3.UnusedEnum field10795 = 14; + optional .benchmarks.google_message3.UnusedEnum field10796 = 22; +} + +message Message13145 { + required .benchmarks.google_message3.Enum13146 field13155 = 1; + optional float field13156 = 2; + optional float field13157 = 3; + extensions 1000 to 536870911; +} + +message Message16686 {} + +message Message12796 { + repeated fixed64 field12800 = 1; + optional uint64 field12801 = 2; +} + +message Message6722 {} + +message Message6727 {} + +message Message6724 {} + +message Message6735 {} + +message Message8183 { + optional string field8226 = 1; + optional string field8227 = 2; +} + +message Message8301 { + optional string field8328 = 1; + optional .benchmarks.google_message3.Message7966 field8329 = 2; + optional string field8330 = 3; + optional string field8331 = 4; + repeated .benchmarks.google_message3.Message8290 field8332 = 5; + optional .benchmarks.google_message3.Message7966 field8333 = 6; + repeated .benchmarks.google_message3.Message8298 field8334 = 7; + optional .benchmarks.google_message3.Message8300 field8335 = 8; + optional int64 field8336 = 9; + optional .benchmarks.google_message3.UnusedEmptyMessage field8337 = 10; + optional .benchmarks.google_message3.Message7965 field8338 = 11; + extensions 64 to 536870911; +} + +message Message8456 {} + +message Message8302 { + optional string field8339 = 1; + optional .benchmarks.google_message3.Message7966 field8340 = 2; + optional string field8341 = 3; + optional string field8342 = 4; + optional string field8343 = 5; + optional string field8344 = 6; + optional string field8345 = 7; + optional int64 field8346 = 8; + optional int64 field8347 = 9; + repeated .benchmarks.google_message3.Message8290 field8348 = 10; + optional string field8349 = 11; + optional .benchmarks.google_message3.UnusedEmptyMessage field8350 = 12; + optional .benchmarks.google_message3.Message8291 field8351 = 13; + optional int64 field8352 = 14; + optional .benchmarks.google_message3.Message8296 field8353 = 15; + optional string field8354 = 16; + optional .benchmarks.google_message3.UnusedEmptyMessage field8355 = 17; + repeated int32 field8356 = 18; + repeated int32 field8357 = 19; + repeated .benchmarks.google_message3.UnusedEmptyMessage field8358 = 20; + optional .benchmarks.google_message3.Message7965 field8359 = 21; + extensions 64 to 536870911; +} + +message Message8457 {} + +message Message8449 { + optional string field8458 = 1; + optional bool field8459 = 2; + optional .benchmarks.google_message3.Enum8450 field8460 = 3; + repeated string field8461 = 4; + optional string field8462 = 5; + optional string field8463 = 6; + optional .benchmarks.google_message3.Message7966 field8464 = 7; +} + +message Message13358 { + required fixed64 field13359 = 1; + required fixed64 field13360 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field13361 = 3; +} + +message Message13912 { + required fixed32 field13913 = 1; + required fixed32 field13914 = 2; + optional .benchmarks.google_message3.UnusedEmptyMessage field13915 = 500; + optional .benchmarks.google_message3.UnusedEmptyMessage field13916 = 15; +} + +message Message24316 { + repeated string field24443 = 1; + repeated string field24444 = 2; + repeated string field24445 = 3; +} + +message Message24312 { + optional string field24421 = 1; + optional string field24422 = 2; + repeated string field24423 = 3; + repeated string field24424 = 4; + repeated string field24425 = 5; + repeated string field24426 = 6; +} + +message Message24313 { + optional string field24427 = 1; + optional string field24428 = 2; + repeated string field24429 = 3; + optional string field24430 = 4; + optional string field24431 = 5; + optional string field24432 = 6; + optional string field24433 = 7; + repeated string field24434 = 8; + optional string field24435 = 9; + repeated string field24436 = 10; +} + +message Message24315 { + required string field24440 = 1; + repeated string field24441 = 2; + repeated string field24442 = 3; +} + +message Message716 { + required string field872 = 1; + required int32 field873 = 2; + optional bool field874 = 3; + optional .benchmarks.google_message3.Message717 field875 = 4; +} + +message Message718 { + repeated string field878 = 1; + repeated string field879 = 2; + optional string field880 = 3; +} + +message Message703 { + required string field795 = 1; + repeated string field796 = 2; + repeated string field797 = 3; + optional string field798 = 4; + repeated string field799 = 5; +} + +message Message715 { + required string field859 = 1; + optional string field860 = 7; + repeated .benchmarks.google_message3.Message707 field861 = 2; + repeated .benchmarks.google_message3.Message708 field862 = 3; + repeated .benchmarks.google_message3.Message711 field863 = 4; + repeated .benchmarks.google_message3.Message712 field864 = 5; + repeated .benchmarks.google_message3.Message713 field865 = 6; + repeated .benchmarks.google_message3.Message714 field866 = 8; + repeated .benchmarks.google_message3.Message710 field867 = 9; + repeated .benchmarks.google_message3.Message709 field868 = 10; + repeated .benchmarks.google_message3.Message705 field869 = 11; + repeated .benchmarks.google_message3.Message702 field870 = 12; + repeated .benchmarks.google_message3.Message706 field871 = 13; +} + +message Message700 { + repeated string field789 = 1; + repeated string field790 = 2; +} + +message Message699 { + required string field787 = 1; + repeated string field788 = 2; +} + +message Message698 { + optional string field779 = 1; + optional string field780 = 2; + optional string field781 = 3; + optional string field782 = 4; + optional uint64 field783 = 5; + optional uint32 field784 = 6; + optional int64 field785 = 7; + repeated string field786 = 8; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_6.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_6.proto new file mode 100644 index 0000000..c766f7c --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_6.proto @@ -0,0 +1,483 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message3; + +import "datasets/google_message3/benchmark_message3_7.proto"; +import "datasets/google_message3/benchmark_message3_8.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message10576 {} + +message Message10154 { + optional bytes field10192 = 1; + optional int32 field10193 = 2; +} + +message Message8944 { + optional string field9045 = 2; + optional string field9046 = 3; + optional string field9047 = 23; + optional string field9048 = 52; + optional int32 field9049 = 53; + optional int32 field9050 = 54; + optional float field9051 = 55; + optional float field9052 = 56; + optional string field9053 = 57; + optional int64 field9054 = 1; + optional bool field9055 = 4; + optional int32 field9056 = 5; + optional int32 field9057 = 6; + optional int32 field9058 = 7; + optional float field9059 = 8; + optional float field9060 = 11; + optional float field9061 = 9; + optional float field9062 = 10; + optional float field9063 = 13; + optional bool field9064 = 14; + optional float field9065 = 70; + optional int32 field9066 = 71; + optional .benchmarks.google_message3.Enum8945 field9067 = 15; + optional int32 field9068 = 16; + optional int32 field9069 = 17; + optional float field9070 = 18; + optional float field9071 = 19; + optional int32 field9072 = 28; + optional int32 field9073 = 29; + optional float field9074 = 60; + optional float field9075 = 61; + optional int32 field9076 = 72; + optional int32 field9077 = 73; + optional .benchmarks.google_message3.Enum8951 field9078 = 62; + optional string field9079 = 20; + optional string field9080 = 21; + optional string field9081 = 22; + optional double field9082 = 31; + optional double field9083 = 32; + optional double field9084 = 33; + optional double field9085 = 36; + optional .benchmarks.google_message3.UnusedEnum field9086 = 37; + optional double field9087 = 38; + optional double field9088 = 39; + optional double field9089 = 63; + optional double field9090 = 64; + optional double field9091 = 65; + optional double field9092 = 34; + optional .benchmarks.google_message3.UnusedEnum field9093 = 35; + optional .benchmarks.google_message3.UnusedEnum field9094 = 66; + optional string field9095 = 40; + optional string field9096 = 41; + optional string field9097 = 42; + optional string field9098 = 43; + optional string field9099 = 44; + optional string field9100 = 45; + optional string field9101 = 46; + optional string field9102 = 47; + optional string field9103 = 48; + optional string field9104 = 49; + optional .benchmarks.google_message3.Message8939 field9105 = 100; + optional int64 field9106 = 101; +} + +message Message9182 { + optional string field9205 = 1; + optional string field9206 = 2; + optional float field9207 = 16; + optional int32 field9208 = 17; + optional int32 field9209 = 27; + optional int32 field9210 = 7; + optional int32 field9211 = 8; + optional float field9212 = 26; + optional float field9213 = 22; + optional bool field9214 = 28; + repeated .benchmarks.google_message3.UnusedEmptyMessage field9215 = 21; + repeated .benchmarks.google_message3.UnusedEmptyMessage field9216 = 25; + repeated .benchmarks.google_message3.Message9181 field9217 = 29; + optional bool field9218 = 18; + optional bool field9219 = 19; + optional bool field9220 = 20; + optional .benchmarks.google_message3.Message9164 field9221 = 30; + optional .benchmarks.google_message3.Message9165 field9222 = 31; + optional .benchmarks.google_message3.Message9166 field9223 = 32; + optional float field9224 = 33; + optional .benchmarks.google_message3.Message9151 field9225 = 34; + optional float field9226 = 35; + optional float field9227 = 36; + optional float field9228 = 37; + optional float field9229 = 38; + optional float field9230 = 39; + extensions 3 to 6; + extensions 9 to 15; + extensions 23 to 23; + extensions 24 to 24; + extensions 1000 to 536870911; +} + +message Message9160 { + optional int32 field9161 = 1; + optional bytes field9162 = 2; +} + +message Message9242 { + repeated .benchmarks.google_message3.Enum9243 field9327 = 1; +} + +message Message8890 { + repeated .benchmarks.google_message3.Message8888 field8916 = 1; +} + +message Message9123 { + optional float field9135 = 1; +} + +message Message9628 { + optional .benchmarks.google_message3.Message9627 field9673 = 1; + optional string field9674 = 2; + repeated int32 field9675 = 3; + optional int32 field9676 = 4; +} + +message Message11014 { + optional int32 field11780 = 40; + optional string field11781 = 46; + optional bool field11782 = 47; + optional .benchmarks.google_message3.Enum11107 field11783 = 1; + optional int32 field11784 = 2; + optional double field11785 = 4; + optional int32 field11786 = 5; + optional int32 field11787 = 6; + optional double field11788 = 7; + optional double field11789 = 8; + optional int64 field11790 = 9; + optional bool field11791 = 10; + optional int64 field11792 = 28; + optional bool field11793 = 37; + optional .benchmarks.google_message3.Enum11541 field11794 = 44; + optional double field11795 = 49; + optional double field11796 = 51; + optional int64 field11797 = 54; + optional int64 field11798 = 55; + optional .benchmarks.google_message3.UnusedEnum field11799 = 57; + optional .benchmarks.google_message3.Enum11468 field11800 = 58; + optional int32 field11801 = 59; + optional .benchmarks.google_message3.UnusedEnum field11802 = 60; + optional int32 field11803 = 61; + optional int32 field11804 = 62; + optional int32 field11805 = 69; + optional .benchmarks.google_message3.UnusedEmptyMessage field11806 = 68; + repeated .benchmarks.google_message3.Message11018 field11807 = 71; + optional bool field11808 = 50; + optional bool field11809 = 56; + optional bool field11810 = 66; + optional bool field11811 = 63; + optional bool field11812 = 64; + optional bool field11813 = 65; + optional bool field11814 = 67; + optional .benchmarks.google_message3.Enum11107 field11815 = 15; + optional int64 field11816 = 16; + optional double field11817 = 17; + optional int64 field11818 = 18; + optional int32 field11819 = 19; + optional int64 field11820 = 20; + optional int32 field11821 = 42; + optional int64 field11822 = 52; + optional int64 field11823 = 53; + optional int64 field11824 = 41; + optional double field11825 = 48; + repeated .benchmarks.google_message3.Message11020 field11826 = 70; + repeated .benchmarks.google_message3.UnusedEmptyMessage field11827 = 72; + optional double field11828 = 25; + optional string field11829 = 26; + optional int64 field11830 = 27; + optional int64 field11831 = 32; + optional uint64 field11832 = 33; + optional bool field11833 = 29; + optional bool field11834 = 34; + optional string field11835 = 30; + optional int32 field11836 = 3; + optional int32 field11837 = 31; + optional int32 field11838 = 73; + optional int32 field11839 = 35; + optional .benchmarks.google_message3.Enum11022 field11840 = 36; + optional .benchmarks.google_message3.Message11013 field11841 = 38; + optional double field11842 = 39; + optional int32 field11843 = 45; + optional bool field11844 = 74; +} + +message Message10801 { + optional .benchmarks.google_message3.Message10800 field10812 = 1; + repeated .benchmarks.google_message3.Message10802 field10813 = 2; + optional int32 field10814 = 3; +} + +message Message10749 { + repeated .benchmarks.google_message3.Message10748 field10754 = 1; +} + +message Message8298 { + optional .benchmarks.google_message3.Message7966 field8321 = 1; + optional int64 field8322 = 2; + optional string field8323 = 3; +} + +message Message8300 { + optional string field8326 = 1; + optional .benchmarks.google_message3.Message7966 field8327 = 2; +} + +message Message8291 { + optional string field8306 = 1; + optional int32 field8307 = 2; + optional string field8308 = 3; + optional string field8309 = 4; + optional .benchmarks.google_message3.Enum8292 field8310 = 5; +} + +message Message8296 { + optional .benchmarks.google_message3.Message7966 field8311 = 1; + optional string field8312 = 2; + optional .benchmarks.google_message3.Message7966 field8313 = 3; + optional int32 field8314 = 4; + optional int32 field8315 = 5; + optional string field8316 = 6; +} + +message Message7965 { + optional int32 field7967 = 1; + optional int32 field7968 = 2; +} + +message Message8290 { + optional string field8304 = 1; + optional string field8305 = 2; +} + +message Message717 { + repeated string field876 = 1; + optional double field877 = 2; +} + +message Message713 { + required .benchmarks.google_message3.Message708 field852 = 1; + repeated string field853 = 2; +} + +message Message705 { + required string field807 = 1; + optional string field808 = 2; + optional string field809 = 3; + optional bool field810 = 4; + optional string field811 = 5; + optional string field812 = 6; + repeated string field813 = 7; +} + +message Message709 { + repeated string field829 = 1; + repeated string field830 = 2; + repeated string field831 = 3; + repeated string field832 = 4; + repeated string field833 = 5; +} + +message Message702 { + optional string field793 = 1; + optional string field794 = 2; +} + +message Message714 { + optional string field854 = 1; + optional string field855 = 2; + optional string field856 = 3; + optional string field857 = 4; + optional uint32 field858 = 5; +} + +message Message710 { + repeated string field834 = 1; + optional string field835 = 2; + optional string field836 = 3; + repeated string field837 = 4; + repeated string field838 = 5; +} + +message Message706 { + repeated string field814 = 1; + optional string field815 = 2; + repeated string field816 = 3; + repeated string field817 = 4; +} + +message Message707 { + required string field818 = 1; + required string field819 = 2; + required string field820 = 3; + optional bool field821 = 4; + repeated string field822 = 5; +} + +message Message711 { + optional .benchmarks.google_message3.UnusedEmptyMessage field839 = 1; + repeated string field840 = 4; + repeated string field841 = 2; + repeated string field842 = 3; +} + +message Message712 { + repeated string field843 = 1; + required string field844 = 2; + optional string field845 = 3; + repeated string field846 = 4; + repeated string field847 = 5; + optional string field848 = 6; + repeated string field849 = 7; + optional string field850 = 8; + optional string field851 = 9; +} + +message Message8939 { + optional string field9010 = 1; + optional string field9011 = 2; + optional string field9012 = 3; + repeated string field9013 = 4; + optional string field9014 = 5; + repeated group Message8940 = 11 {} + optional int64 field9016 = 21; + optional int64 field9017 = 22; + optional int64 field9018 = 23; + optional group Message8941 = 31 { + optional string field9033 = 32; + optional string field9034 = 33; + optional string field9035 = 34; + optional string field9036 = 35; + optional string field9037 = 36; + optional string field9038 = 37; + } + optional .benchmarks.google_message3.Message8942 field9020 = 38; + repeated .benchmarks.google_message3.UnusedEmptyMessage field9021 = 39; + repeated string field9022 = 41; + optional string field9023 = 42; + optional string field9024 = 43; + optional string field9025 = 44; + optional string field9026 = 45; + optional string field9027 = 46; + optional string field9028 = 47; + optional .benchmarks.google_message3.UnusedEnum field9029 = 48; + optional .benchmarks.google_message3.UnusedEnum field9030 = 49; + optional group Message8943 = 51 { + optional string field9039 = 1; + optional string field9040 = 2; + optional string field9041 = 3; + optional string field9042 = 4; + optional string field9043 = 5; + optional string field9044 = 6; + } +} + +message Message9181 { + optional string field9204 = 1; +} + +message Message9164 { + optional int32 field9168 = 1; + optional int32 field9169 = 2; + optional int32 field9170 = 3; +} + +message Message9165 { + optional float field9171 = 1; + optional float field9172 = 2; +} + +message Message9166 { + optional float field9173 = 1; + optional int32 field9174 = 2; +} + +message Message9151 { + optional double field9152 = 1; + optional double field9153 = 2; + optional float field9154 = 3; + optional float field9155 = 4; + optional float field9156 = 5; + optional float field9157 = 6; + optional float field9158 = 7; + optional float field9159 = 8; +} + +message Message8888 { + optional int32 field8908 = 1; + optional .benchmarks.google_message3.Enum8900 field8909 = 4; + repeated int32 field8910 = 2 [packed = true]; + optional bytes field8911 = 3; +} + +message Message9627 { + required int32 field9668 = 1; + required int32 field9669 = 2; + required int32 field9670 = 3; + required int32 field9671 = 4; + optional float field9672 = 5; +} + +message Message11020 {} + +message Message11013 { + optional bytes field11757 = 19; + optional bytes field11758 = 1; + optional bytes field11759 = 2; + optional bytes field11760 = 3; + optional bytes field11761 = 4; + optional bytes field11762 = 5; + optional bytes field11763 = 6; + optional bytes field11764 = 7; + optional bytes field11765 = 8; + optional bytes field11766 = 9; + optional bytes field11767 = 10; + optional bytes field11768 = 11; + optional bytes field11769 = 12; + optional bytes field11770 = 13; + optional bytes field11771 = 14; + optional bytes field11772 = 15; + optional bytes field11773 = 16; + optional bytes field11774 = 17; + optional bytes field11775 = 18; + optional bytes field11776 = 20; + optional bytes field11777 = 21; + optional .benchmarks.google_message3.UnusedEmptyMessage field11778 = 23; + repeated .benchmarks.google_message3.Message11011 field11779 = 22; +} diff --git a/libs/protobuf/objectivec/Tests/unittest_mset.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_7.proto similarity index 62% rename from libs/protobuf/objectivec/Tests/unittest_mset.proto rename to libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_7.proto index 9ff070f..0f8f10c 100644 --- a/libs/protobuf/objectivec/Tests/unittest_mset.proto +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_7.proto @@ -30,36 +30,52 @@ syntax = "proto2"; -package objc.protobuf.tests.mset; +package benchmarks.google_message3; -option objc_class_prefix = "MSet"; +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; -// A message with message_set_wire_format. -message Message { - option message_set_wire_format = true; - extensions 4 to max; +message Message11018 {} + +message Message10800 { + optional string field10808 = 1; + optional int64 field10809 = 2; + optional bool field10810 = 3; + optional float field10811 = 4; } -message MessageExtension1 { - extend Message { - optional MessageExtension1 message_set_extension = 1545008; - } - optional int32 i = 15; - optional Message recursive = 16; - optional string test_aliasing = 17 [ctype = STRING_PIECE]; +message Message10802 {} + +message Message10748 { + optional string field10750 = 1; + optional int32 field10751 = 2; + optional int32 field10752 = 3; + optional int32 field10753 = 4; } -message MessageExtension2 { - extend Message { - optional MessageExtension2 message_set_extension = 1547769; - } - optional string str = 25; +message Message7966 { + optional string field7969 = 1; + optional bool field7970 = 2; } -// MessageSet wire format is equivalent to this. -message RawMessageSet { - repeated group Item = 1 { - required int32 type_id = 2; - required bytes message = 3; - } +message Message708 { + optional .benchmarks.google_message3.Message741 field823 = 1; + repeated string field824 = 6; + optional string field825 = 2; + optional string field826 = 3; + repeated string field827 = 4; + repeated string field828 = 5; +} + +message Message8942 {} + +message Message11011 { + required bytes field11752 = 1; + required bytes field11753 = 2; +} + +message UnusedEmptyMessage {} + +message Message741 { + repeated string field936 = 1; } diff --git a/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_8.proto b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_8.proto new file mode 100644 index 0000000..68fe8e9 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message3/benchmark_message3_8.proto @@ -0,0 +1,1925 @@ +// 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. + +syntax = "proto2"; + +package benchmarks.google_message3; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +enum Enum720 { + ENUM_VALUE721 = 1; + ENUM_VALUE722 = 2; +} + +enum Enum3476 { + ENUM_VALUE3477 = 0; + ENUM_VALUE3478 = 1; + ENUM_VALUE3479 = 2; + ENUM_VALUE3480 = 3; + ENUM_VALUE3481 = 4; + ENUM_VALUE3482 = 5; + ENUM_VALUE3483 = 6; + ENUM_VALUE3484 = 7; + ENUM_VALUE3485 = 8; + ENUM_VALUE3486 = 9; + ENUM_VALUE3487 = 10; + ENUM_VALUE3488 = 11; + ENUM_VALUE3489 = 12; + ENUM_VALUE3490 = 13; + ENUM_VALUE3491 = 14; + ENUM_VALUE3492 = 15; + ENUM_VALUE3493 = 16; + ENUM_VALUE3494 = 17; + ENUM_VALUE3495 = 18; + ENUM_VALUE3496 = 19; + ENUM_VALUE3497 = 20; + ENUM_VALUE3498 = 21; + ENUM_VALUE3499 = 22; + ENUM_VALUE3500 = 23; + ENUM_VALUE3501 = 24; + ENUM_VALUE3502 = 25; + ENUM_VALUE3503 = 26; + ENUM_VALUE3504 = 27; + ENUM_VALUE3505 = 28; + ENUM_VALUE3506 = 29; + ENUM_VALUE3507 = 30; + ENUM_VALUE3508 = 31; + ENUM_VALUE3509 = 32; + ENUM_VALUE3510 = 33; + ENUM_VALUE3511 = 34; + ENUM_VALUE3512 = 35; + ENUM_VALUE3513 = 36; + ENUM_VALUE3514 = 37; + ENUM_VALUE3515 = 38; + ENUM_VALUE3516 = 39; + ENUM_VALUE3517 = 40; + ENUM_VALUE3518 = 41; + ENUM_VALUE3519 = 42; + ENUM_VALUE3520 = 43; + ENUM_VALUE3521 = 44; + ENUM_VALUE3522 = 45; + ENUM_VALUE3523 = 46; + ENUM_VALUE3524 = 47; + ENUM_VALUE3525 = 48; + ENUM_VALUE3526 = 49; + ENUM_VALUE3527 = 50; + ENUM_VALUE3528 = 51; + ENUM_VALUE3529 = 52; + ENUM_VALUE3530 = 53; + ENUM_VALUE3531 = 54; + ENUM_VALUE3532 = 55; + ENUM_VALUE3533 = 56; + ENUM_VALUE3534 = 57; + ENUM_VALUE3535 = 58; + ENUM_VALUE3536 = 59; + ENUM_VALUE3537 = 60; + ENUM_VALUE3538 = 61; + ENUM_VALUE3539 = 62; + ENUM_VALUE3540 = 63; + ENUM_VALUE3541 = 64; + ENUM_VALUE3542 = 65; + ENUM_VALUE3543 = 66; + ENUM_VALUE3544 = 67; + ENUM_VALUE3545 = 68; + ENUM_VALUE3546 = 69; + ENUM_VALUE3547 = 70; + ENUM_VALUE3548 = 71; + ENUM_VALUE3549 = 72; + ENUM_VALUE3550 = 73; + ENUM_VALUE3551 = 74; + ENUM_VALUE3552 = 75; + ENUM_VALUE3553 = 76; + ENUM_VALUE3554 = 77; + ENUM_VALUE3555 = 78; + ENUM_VALUE3556 = 79; + ENUM_VALUE3557 = 80; + ENUM_VALUE3558 = 81; + ENUM_VALUE3559 = 82; + ENUM_VALUE3560 = 83; + ENUM_VALUE3561 = 84; + ENUM_VALUE3562 = 85; + ENUM_VALUE3563 = 86; + ENUM_VALUE3564 = 87; + ENUM_VALUE3565 = 88; + ENUM_VALUE3566 = 89; + ENUM_VALUE3567 = 90; + ENUM_VALUE3568 = 91; + ENUM_VALUE3569 = 92; + ENUM_VALUE3570 = 93; + ENUM_VALUE3571 = 94; + ENUM_VALUE3572 = 95; + ENUM_VALUE3573 = 96; + ENUM_VALUE3574 = 97; + ENUM_VALUE3575 = 98; + ENUM_VALUE3576 = 99; + ENUM_VALUE3577 = 100; + ENUM_VALUE3578 = 101; + ENUM_VALUE3579 = 102; + ENUM_VALUE3580 = 103; + ENUM_VALUE3581 = 104; + ENUM_VALUE3582 = 105; + ENUM_VALUE3583 = 106; + ENUM_VALUE3584 = 107; + ENUM_VALUE3585 = 108; + ENUM_VALUE3586 = 109; + ENUM_VALUE3587 = 110; + ENUM_VALUE3588 = 111; + ENUM_VALUE3589 = 112; + ENUM_VALUE3590 = 113; + ENUM_VALUE3591 = 114; + ENUM_VALUE3592 = 115; + ENUM_VALUE3593 = 116; + ENUM_VALUE3594 = 117; + ENUM_VALUE3595 = 118; + ENUM_VALUE3596 = 119; + ENUM_VALUE3597 = 120; + ENUM_VALUE3598 = 121; + ENUM_VALUE3599 = 122; + ENUM_VALUE3600 = 123; + ENUM_VALUE3601 = 124; + ENUM_VALUE3602 = 125; + ENUM_VALUE3603 = 126; + ENUM_VALUE3604 = 127; + ENUM_VALUE3605 = 128; + ENUM_VALUE3606 = 129; + ENUM_VALUE3607 = 130; + ENUM_VALUE3608 = 131; + ENUM_VALUE3609 = 132; + ENUM_VALUE3610 = 133; + ENUM_VALUE3611 = 134; + ENUM_VALUE3612 = 135; + ENUM_VALUE3613 = 136; + ENUM_VALUE3614 = 137; + ENUM_VALUE3615 = 138; + ENUM_VALUE3616 = 139; + ENUM_VALUE3617 = 140; + ENUM_VALUE3618 = 141; + ENUM_VALUE3619 = 142; + ENUM_VALUE3620 = 143; + ENUM_VALUE3621 = 144; + ENUM_VALUE3622 = 145; + ENUM_VALUE3623 = 146; + ENUM_VALUE3624 = 147; + ENUM_VALUE3625 = 148; + ENUM_VALUE3626 = 149; + ENUM_VALUE3627 = 150; + ENUM_VALUE3628 = 151; + ENUM_VALUE3629 = 152; + ENUM_VALUE3630 = 153; + ENUM_VALUE3631 = 154; + ENUM_VALUE3632 = 155; + ENUM_VALUE3633 = 156; + ENUM_VALUE3634 = 157; + ENUM_VALUE3635 = 158; + ENUM_VALUE3636 = 159; + ENUM_VALUE3637 = 160; + ENUM_VALUE3638 = 161; + ENUM_VALUE3639 = 162; + ENUM_VALUE3640 = 163; + ENUM_VALUE3641 = 164; + ENUM_VALUE3642 = 165; + ENUM_VALUE3643 = 166; + ENUM_VALUE3644 = 167; + ENUM_VALUE3645 = 168; + ENUM_VALUE3646 = 169; + ENUM_VALUE3647 = 170; + ENUM_VALUE3648 = 171; + ENUM_VALUE3649 = 172; + ENUM_VALUE3650 = 173; + ENUM_VALUE3651 = 174; + ENUM_VALUE3652 = 175; + ENUM_VALUE3653 = 176; + ENUM_VALUE3654 = 177; + ENUM_VALUE3655 = 178; + ENUM_VALUE3656 = 179; + ENUM_VALUE3657 = 180; + ENUM_VALUE3658 = 181; + ENUM_VALUE3659 = 182; + ENUM_VALUE3660 = 183; +} + +enum Enum3805 { + ENUM_VALUE3806 = 0; + ENUM_VALUE3807 = 1; + ENUM_VALUE3808 = 2; + ENUM_VALUE3809 = 3; + ENUM_VALUE3810 = 4; + ENUM_VALUE3811 = 5; + ENUM_VALUE3812 = 6; + ENUM_VALUE3813 = 7; + ENUM_VALUE3814 = 8; + ENUM_VALUE3815 = 9; + ENUM_VALUE3816 = 11; + ENUM_VALUE3817 = 10; +} + +enum Enum3783 { + ENUM_VALUE3784 = 0; + ENUM_VALUE3785 = 1; + ENUM_VALUE3786 = 2; + ENUM_VALUE3787 = 3; + ENUM_VALUE3788 = 4; + ENUM_VALUE3789 = 5; + ENUM_VALUE3790 = 6; + ENUM_VALUE3791 = 7; + ENUM_VALUE3792 = 8; + ENUM_VALUE3793 = 9; + ENUM_VALUE3794 = 10; + ENUM_VALUE3795 = 11; + ENUM_VALUE3796 = 12; + ENUM_VALUE3797 = 13; + ENUM_VALUE3798 = 14; + ENUM_VALUE3799 = 15; + ENUM_VALUE3800 = 16; + ENUM_VALUE3801 = 20; + ENUM_VALUE3802 = 21; + ENUM_VALUE3803 = 50; +} + +enum Enum3851 { + ENUM_VALUE3852 = 0; + ENUM_VALUE3853 = 1; + ENUM_VALUE3854 = 2; + ENUM_VALUE3855 = 3; + ENUM_VALUE3856 = 4; + ENUM_VALUE3857 = 5; + ENUM_VALUE3858 = 6; + ENUM_VALUE3859 = 7; + ENUM_VALUE3860 = 8; + ENUM_VALUE3861 = 9; + ENUM_VALUE3862 = 10; + ENUM_VALUE3863 = 11; + ENUM_VALUE3864 = 12; + ENUM_VALUE3865 = 13; + ENUM_VALUE3866 = 14; + ENUM_VALUE3867 = 15; + ENUM_VALUE3868 = 16; + ENUM_VALUE3869 = 17; +} + +enum UnusedEnum { + UNUSED_ENUM_VALUE1 = 0; + UNUSED_ENUM_VALUE2 = 1; +} + +enum Enum4146 { + ENUM_VALUE4147 = 0; + ENUM_VALUE4148 = 1; + ENUM_VALUE4149 = 2; + ENUM_VALUE4150 = 3; + ENUM_VALUE4151 = 4; +} + +enum Enum4160 { + ENUM_VALUE4161 = 0; + ENUM_VALUE4162 = 1; +} + +enum Enum4152 { + ENUM_VALUE4153 = 0; + ENUM_VALUE4154 = 1; + ENUM_VALUE4155 = 2; + ENUM_VALUE4156 = 3; + ENUM_VALUE4157 = 4; + ENUM_VALUE4158 = 5; + ENUM_VALUE4159 = 6; +} + +enum Enum6025 { + ENUM_VALUE6026 = 0; + ENUM_VALUE6027 = 1; + ENUM_VALUE6028 = 2; + ENUM_VALUE6029 = 3; + ENUM_VALUE6030 = 4; + ENUM_VALUE6031 = 5; + ENUM_VALUE6032 = 6; + ENUM_VALUE6033 = 7; + ENUM_VALUE6034 = 8; + ENUM_VALUE6035 = 9; + ENUM_VALUE6036 = 10; + ENUM_VALUE6037 = 11; + ENUM_VALUE6038 = 12; + ENUM_VALUE6039 = 13; + ENUM_VALUE6040 = 14; + ENUM_VALUE6041 = 15; + ENUM_VALUE6042 = 16; + ENUM_VALUE6043 = 17; + ENUM_VALUE6044 = 18; + ENUM_VALUE6045 = 19; + ENUM_VALUE6046 = 20; + ENUM_VALUE6047 = 21; +} + +enum Enum6065 { + ENUM_VALUE6066 = 0; + ENUM_VALUE6067 = 1; + ENUM_VALUE6068 = 2; + ENUM_VALUE6069 = 3; + ENUM_VALUE6070 = 4; + ENUM_VALUE6071 = 5; + ENUM_VALUE6072 = 6; + ENUM_VALUE6073 = 7; + ENUM_VALUE6074 = 8; + ENUM_VALUE6075 = 9; + ENUM_VALUE6076 = 10; + ENUM_VALUE6077 = 11; + ENUM_VALUE6078 = 12; + ENUM_VALUE6079 = 13; + ENUM_VALUE6080 = 14; +} + +enum Enum6579 { + ENUM_VALUE6580 = 0; + ENUM_VALUE6581 = 2; + ENUM_VALUE6582 = 3; + ENUM_VALUE6583 = 5; + ENUM_VALUE6584 = 10; + ENUM_VALUE6585 = 15; + ENUM_VALUE6586 = 25; + ENUM_VALUE6587 = 30; +} + +enum Enum6588 { + ENUM_VALUE6589 = 0; + ENUM_VALUE6590 = 1; + ENUM_VALUE6591 = 2; + ENUM_VALUE6592 = 3; + ENUM_VALUE6593 = 4; + ENUM_VALUE6594 = 5; + ENUM_VALUE6595 = 6; + ENUM_VALUE6596 = 7; + ENUM_VALUE6597 = 8; + ENUM_VALUE6598 = 9; + ENUM_VALUE6599 = 10; + ENUM_VALUE6600 = 11; + ENUM_VALUE6601 = 12; + ENUM_VALUE6602 = 13; + ENUM_VALUE6603 = 14; + ENUM_VALUE6604 = 15; + ENUM_VALUE6605 = 16; + ENUM_VALUE6606 = 17; + ENUM_VALUE6607 = 19; + ENUM_VALUE6608 = 20; + ENUM_VALUE6609 = 21; + ENUM_VALUE6610 = 22; + ENUM_VALUE6611 = 23; + ENUM_VALUE6612 = 24; + ENUM_VALUE6613 = 25; + ENUM_VALUE6614 = 26; + ENUM_VALUE6615 = 27; + ENUM_VALUE6616 = 28; + ENUM_VALUE6617 = 29; + ENUM_VALUE6618 = 30; + ENUM_VALUE6619 = 31; + ENUM_VALUE6620 = 32; + ENUM_VALUE6621 = 33; + ENUM_VALUE6622 = 34; +} + +enum Enum6769 { + ENUM_VALUE6770 = 0; + ENUM_VALUE6771 = 1; + ENUM_VALUE6772 = 2; +} + +enum Enum6774 { + ENUM_VALUE6775 = 0; + ENUM_VALUE6776 = 1; + ENUM_VALUE6777 = 2; + ENUM_VALUE6778 = 3; + ENUM_VALUE6779 = 4; + ENUM_VALUE6780 = 5; + ENUM_VALUE6781 = 6; +} + +enum Enum6782 { + ENUM_VALUE6783 = 0; + ENUM_VALUE6784 = 1; + ENUM_VALUE6785 = 2; + ENUM_VALUE6786 = 3; + ENUM_VALUE6787 = 4; + ENUM_VALUE6788 = 5; +} + +enum Enum6858 { + ENUM_VALUE6859 = 1; + ENUM_VALUE6860 = 2; + ENUM_VALUE6861 = 3; + ENUM_VALUE6862 = 4; +} + +enum Enum6815 { + ENUM_VALUE6816 = 0; + ENUM_VALUE6817 = 1; + ENUM_VALUE6818 = 2; + ENUM_VALUE6819 = 3; + ENUM_VALUE6820 = 4; + ENUM_VALUE6821 = 5; +} + +enum Enum6822 { + ENUM_VALUE6823 = 0; + ENUM_VALUE6824 = 1; + ENUM_VALUE6825 = 2; + ENUM_VALUE6826 = 3; +} + +enum Enum7654 { + ENUM_VALUE7655 = 1; + ENUM_VALUE7656 = 2; + ENUM_VALUE7657 = 3; +} + +enum Enum8292 { + ENUM_VALUE8293 = 0; + ENUM_VALUE8294 = 1; + ENUM_VALUE8295 = 2; +} + +enum Enum8450 { + ENUM_VALUE8451 = 0; + ENUM_VALUE8452 = 1; + ENUM_VALUE8453 = 2; +} + +enum Enum8900 { + ENUM_VALUE8901 = 0; + ENUM_VALUE8902 = 1; + ENUM_VALUE8903 = 2; + ENUM_VALUE8904 = 3; + ENUM_VALUE8905 = 4; +} + +enum Enum8945 { + ENUM_VALUE8946 = 0; + ENUM_VALUE8947 = 1; + ENUM_VALUE8948 = 2; + ENUM_VALUE8949 = 3; + ENUM_VALUE8950 = 4; +} + +enum Enum8951 { + ENUM_VALUE8952 = 1; + ENUM_VALUE8953 = 2; + ENUM_VALUE8954 = 3; + ENUM_VALUE8955 = 4; + ENUM_VALUE8956 = 5; + ENUM_VALUE8957 = 6; + ENUM_VALUE8958 = 7; + ENUM_VALUE8959 = 8; +} + +enum Enum9243 { + ENUM_VALUE9244 = -1; + ENUM_VALUE9245 = 0; + ENUM_VALUE9246 = 1; + ENUM_VALUE9247 = 2; + ENUM_VALUE9248 = 3; + ENUM_VALUE9249 = 4; + ENUM_VALUE9250 = 5; + ENUM_VALUE9251 = 6; + ENUM_VALUE9252 = 7; + ENUM_VALUE9253 = 8; + ENUM_VALUE9254 = 9; + ENUM_VALUE9255 = 10; + ENUM_VALUE9256 = 11; + ENUM_VALUE9257 = 12; + ENUM_VALUE9258 = 13; + ENUM_VALUE9259 = 14; + ENUM_VALUE9260 = 15; + ENUM_VALUE9261 = 16; + ENUM_VALUE9262 = 17; + ENUM_VALUE9263 = 71; + ENUM_VALUE9264 = 72; + ENUM_VALUE9265 = 73; + ENUM_VALUE9266 = 74; + ENUM_VALUE9267 = 18; + ENUM_VALUE9268 = 20; + ENUM_VALUE9269 = 21; + ENUM_VALUE9270 = 22; + ENUM_VALUE9271 = 23; + ENUM_VALUE9272 = 61; + ENUM_VALUE9273 = 62; + ENUM_VALUE9274 = 63; + ENUM_VALUE9275 = 64; + ENUM_VALUE9276 = 66; + ENUM_VALUE9277 = 67; + ENUM_VALUE9278 = 24; + ENUM_VALUE9279 = 25; + ENUM_VALUE9280 = 26; + ENUM_VALUE9281 = 27; + ENUM_VALUE9282 = 28; + ENUM_VALUE9283 = 29; + ENUM_VALUE9284 = 30; + ENUM_VALUE9285 = 31; + ENUM_VALUE9286 = 32; + ENUM_VALUE9287 = 33; + ENUM_VALUE9288 = 34; + ENUM_VALUE9289 = 35; + ENUM_VALUE9290 = 36; + ENUM_VALUE9291 = 37; + ENUM_VALUE9292 = 38; + ENUM_VALUE9293 = 39; + ENUM_VALUE9294 = 40; + ENUM_VALUE9295 = 41; + ENUM_VALUE9296 = 42; + ENUM_VALUE9297 = 43; + ENUM_VALUE9298 = 44; + ENUM_VALUE9299 = 45; + ENUM_VALUE9300 = 46; + ENUM_VALUE9301 = 47; + ENUM_VALUE9302 = 48; + ENUM_VALUE9303 = 49; + ENUM_VALUE9304 = 50; + ENUM_VALUE9305 = 51; + ENUM_VALUE9306 = 52; + ENUM_VALUE9307 = 53; + ENUM_VALUE9308 = 54; + ENUM_VALUE9309 = 55; + ENUM_VALUE9310 = 56; + ENUM_VALUE9311 = 57; + ENUM_VALUE9312 = 58; + ENUM_VALUE9313 = 59; + ENUM_VALUE9314 = 60; + ENUM_VALUE9315 = 68; + ENUM_VALUE9316 = 69; + ENUM_VALUE9317 = 70; + ENUM_VALUE9318 = 1000; + ENUM_VALUE9319 = 1001; + ENUM_VALUE9320 = 1002; + ENUM_VALUE9321 = 1003; + ENUM_VALUE9322 = 1004; + ENUM_VALUE9323 = 1005; + ENUM_VALUE9324 = 1006; + ENUM_VALUE9325 = 1007; + ENUM_VALUE9326 = 65; +} + +enum Enum10157 { + ENUM_VALUE10158 = 0; + ENUM_VALUE10159 = 1; + ENUM_VALUE10160 = 2; + ENUM_VALUE10161 = 3; + ENUM_VALUE10162 = 4; + ENUM_VALUE10163 = 5; + ENUM_VALUE10164 = 6; + ENUM_VALUE10165 = 7; + ENUM_VALUE10166 = 8; +} + +enum Enum10167 { + ENUM_VALUE10168 = 0; + ENUM_VALUE10169 = 1; + ENUM_VALUE10170 = 2; + ENUM_VALUE10171 = 3; + ENUM_VALUE10172 = 4; + ENUM_VALUE10173 = 5; + ENUM_VALUE10174 = 6; + ENUM_VALUE10175 = 7; + ENUM_VALUE10176 = 8; +} + +enum Enum8862 { + ENUM_VALUE8863 = 0; + ENUM_VALUE8864 = 1; + ENUM_VALUE8865 = 2; + ENUM_VALUE8866 = 3; + ENUM_VALUE8867 = 4; + ENUM_VALUE8868 = 5; + ENUM_VALUE8869 = 6; + ENUM_VALUE8870 = 7; + ENUM_VALUE8871 = 13; + ENUM_VALUE8872 = 14; + ENUM_VALUE8873 = 8; + ENUM_VALUE8874 = 9; + ENUM_VALUE8875 = 10; + ENUM_VALUE8876 = 11; + ENUM_VALUE8877 = 12; + ENUM_VALUE8878 = 15; +} + +enum Enum10325 { + ENUM_VALUE10326 = 0; + ENUM_VALUE10327 = 1; + ENUM_VALUE10328 = 2; + ENUM_VALUE10329 = 3; + ENUM_VALUE10330 = 4; + ENUM_VALUE10331 = 5; + ENUM_VALUE10332 = 6; + ENUM_VALUE10333 = 7; + ENUM_VALUE10334 = 8; +} + +enum Enum10335 { ENUM_VALUE10336 = 0; } + +enum Enum10337 { + ENUM_VALUE10338 = 0; + ENUM_VALUE10339 = 1; +} + +enum Enum10392 { + ENUM_VALUE10393 = 0; + ENUM_VALUE10394 = 1; + ENUM_VALUE10395 = 2; + ENUM_VALUE10396 = 3; + ENUM_VALUE10397 = 4; + ENUM_VALUE10398 = 5; + ENUM_VALUE10399 = 6; + ENUM_VALUE10400 = 7; + ENUM_VALUE10401 = 8; + ENUM_VALUE10402 = 15; + ENUM_VALUE10403 = 9; + ENUM_VALUE10404 = 10; + ENUM_VALUE10405 = 11; + ENUM_VALUE10406 = 12; + ENUM_VALUE10407 = 13; + ENUM_VALUE10408 = 14; + ENUM_VALUE10409 = 101; + ENUM_VALUE10410 = 102; +} + +enum Enum11107 { + ENUM_VALUE11108 = 0; + ENUM_VALUE11109 = 1; + ENUM_VALUE11110 = 2; + ENUM_VALUE11111 = 3; + ENUM_VALUE11112 = 4; + ENUM_VALUE11113 = 5; + ENUM_VALUE11114 = 6; + ENUM_VALUE11115 = 7; + ENUM_VALUE11116 = 8; + ENUM_VALUE11117 = 9; + ENUM_VALUE11118 = 10; + ENUM_VALUE11119 = 11; + ENUM_VALUE11120 = 12; + ENUM_VALUE11121 = 13; + ENUM_VALUE11122 = 14; + ENUM_VALUE11123 = 15; + ENUM_VALUE11124 = 16; + ENUM_VALUE11125 = 17; + ENUM_VALUE11126 = 18; + ENUM_VALUE11127 = 19; + ENUM_VALUE11128 = 20; + ENUM_VALUE11129 = 21; + ENUM_VALUE11130 = 22; + ENUM_VALUE11131 = 23; + ENUM_VALUE11132 = 24; + ENUM_VALUE11133 = 25; + ENUM_VALUE11134 = 26; + ENUM_VALUE11135 = 27; + ENUM_VALUE11136 = 28; + ENUM_VALUE11137 = 29; + ENUM_VALUE11138 = 30; + ENUM_VALUE11139 = 31; + ENUM_VALUE11140 = 32; + ENUM_VALUE11141 = 33; + ENUM_VALUE11142 = 34; + ENUM_VALUE11143 = 35; + ENUM_VALUE11144 = 36; + ENUM_VALUE11145 = 37; + ENUM_VALUE11146 = 38; + ENUM_VALUE11147 = 39; + ENUM_VALUE11148 = 40; + ENUM_VALUE11149 = 41; + ENUM_VALUE11150 = 42; + ENUM_VALUE11151 = 43; + ENUM_VALUE11152 = 44; + ENUM_VALUE11153 = 45; + ENUM_VALUE11154 = 46; + ENUM_VALUE11155 = 47; + ENUM_VALUE11156 = 48; + ENUM_VALUE11157 = 49; + ENUM_VALUE11158 = 50; + ENUM_VALUE11159 = 51; + ENUM_VALUE11160 = 52; + ENUM_VALUE11161 = 53; + ENUM_VALUE11162 = 54; + ENUM_VALUE11163 = 55; + ENUM_VALUE11164 = 56; + ENUM_VALUE11165 = 57; + ENUM_VALUE11166 = 58; + ENUM_VALUE11167 = 59; + ENUM_VALUE11168 = 60; + ENUM_VALUE11169 = 61; + ENUM_VALUE11170 = 62; + ENUM_VALUE11171 = 63; + ENUM_VALUE11172 = 64; + ENUM_VALUE11173 = 65; + ENUM_VALUE11174 = 66; + ENUM_VALUE11175 = 67; + ENUM_VALUE11176 = 68; + ENUM_VALUE11177 = 69; + ENUM_VALUE11178 = 70; + ENUM_VALUE11179 = 71; + ENUM_VALUE11180 = 72; + ENUM_VALUE11181 = 73; + ENUM_VALUE11182 = 74; + ENUM_VALUE11183 = 75; + ENUM_VALUE11184 = 76; + ENUM_VALUE11185 = 77; + ENUM_VALUE11186 = 78; + ENUM_VALUE11187 = 79; + ENUM_VALUE11188 = 80; + ENUM_VALUE11189 = 81; + ENUM_VALUE11190 = 82; + ENUM_VALUE11191 = 83; + ENUM_VALUE11192 = 84; + ENUM_VALUE11193 = 85; + ENUM_VALUE11194 = 86; + ENUM_VALUE11195 = 87; + ENUM_VALUE11196 = 88; + ENUM_VALUE11197 = 89; + ENUM_VALUE11198 = 90; + ENUM_VALUE11199 = 91; + ENUM_VALUE11200 = 92; + ENUM_VALUE11201 = 93; + ENUM_VALUE11202 = 94; + ENUM_VALUE11203 = 95; + ENUM_VALUE11204 = 96; + ENUM_VALUE11205 = 97; + ENUM_VALUE11206 = 98; + ENUM_VALUE11207 = 99; + ENUM_VALUE11208 = 100; + ENUM_VALUE11209 = 101; + ENUM_VALUE11210 = 102; + ENUM_VALUE11211 = 103; + ENUM_VALUE11212 = 104; + ENUM_VALUE11213 = 105; + ENUM_VALUE11214 = 106; + ENUM_VALUE11215 = 107; + ENUM_VALUE11216 = 108; + ENUM_VALUE11217 = 109; + ENUM_VALUE11218 = 110; + ENUM_VALUE11219 = 111; + ENUM_VALUE11220 = 112; + ENUM_VALUE11221 = 113; + ENUM_VALUE11222 = 114; + ENUM_VALUE11223 = 115; + ENUM_VALUE11224 = 116; + ENUM_VALUE11225 = 117; + ENUM_VALUE11226 = 118; + ENUM_VALUE11227 = 119; + ENUM_VALUE11228 = 120; + ENUM_VALUE11229 = 121; + ENUM_VALUE11230 = 122; + ENUM_VALUE11231 = 123; + ENUM_VALUE11232 = 124; + ENUM_VALUE11233 = 125; + ENUM_VALUE11234 = 126; + ENUM_VALUE11235 = 127; + ENUM_VALUE11236 = 128; + ENUM_VALUE11237 = 129; + ENUM_VALUE11238 = 130; + ENUM_VALUE11239 = 131; + ENUM_VALUE11240 = 132; + ENUM_VALUE11241 = 133; + ENUM_VALUE11242 = 134; + ENUM_VALUE11243 = 135; + ENUM_VALUE11244 = 136; + ENUM_VALUE11245 = 137; + ENUM_VALUE11246 = 138; + ENUM_VALUE11247 = 139; + ENUM_VALUE11248 = 140; + ENUM_VALUE11249 = 141; + ENUM_VALUE11250 = 142; + ENUM_VALUE11251 = 143; + ENUM_VALUE11252 = 144; + ENUM_VALUE11253 = 145; + ENUM_VALUE11254 = 146; + ENUM_VALUE11255 = 147; + ENUM_VALUE11256 = 148; + ENUM_VALUE11257 = 149; + ENUM_VALUE11258 = 150; + ENUM_VALUE11259 = 151; + ENUM_VALUE11260 = 152; + ENUM_VALUE11261 = 153; + ENUM_VALUE11262 = 154; + ENUM_VALUE11263 = 155; + ENUM_VALUE11264 = 156; + ENUM_VALUE11265 = 157; + ENUM_VALUE11266 = 158; + ENUM_VALUE11267 = 159; + ENUM_VALUE11268 = 160; + ENUM_VALUE11269 = 161; + ENUM_VALUE11270 = 163; + ENUM_VALUE11271 = 164; + ENUM_VALUE11272 = 165; + ENUM_VALUE11273 = 166; + ENUM_VALUE11274 = 167; + ENUM_VALUE11275 = 168; + ENUM_VALUE11276 = 169; + ENUM_VALUE11277 = 170; + ENUM_VALUE11278 = 171; + ENUM_VALUE11279 = 172; + ENUM_VALUE11280 = 173; + ENUM_VALUE11281 = 174; + ENUM_VALUE11282 = 175; + ENUM_VALUE11283 = 176; + ENUM_VALUE11284 = 177; + ENUM_VALUE11285 = 178; + ENUM_VALUE11286 = 179; + ENUM_VALUE11287 = 180; + ENUM_VALUE11288 = 181; + ENUM_VALUE11289 = 182; + ENUM_VALUE11290 = 183; + ENUM_VALUE11291 = 184; + ENUM_VALUE11292 = 185; + ENUM_VALUE11293 = 187; + ENUM_VALUE11294 = 188; + ENUM_VALUE11295 = 189; + ENUM_VALUE11296 = 190; + ENUM_VALUE11297 = 191; + ENUM_VALUE11298 = 192; + ENUM_VALUE11299 = 193; + ENUM_VALUE11300 = 194; + ENUM_VALUE11301 = 195; + ENUM_VALUE11302 = 196; + ENUM_VALUE11303 = 197; + ENUM_VALUE11304 = 198; + ENUM_VALUE11305 = 65535; + ENUM_VALUE11306 = 65536; + ENUM_VALUE11307 = 65537; + ENUM_VALUE11308 = 65538; + ENUM_VALUE11309 = 65539; + ENUM_VALUE11310 = 65540; + ENUM_VALUE11311 = 65541; + ENUM_VALUE11312 = 65542; + ENUM_VALUE11313 = 65543; + ENUM_VALUE11314 = 65544; + ENUM_VALUE11315 = 65545; + ENUM_VALUE11316 = 65546; + ENUM_VALUE11317 = 65547; + ENUM_VALUE11318 = 65548; + ENUM_VALUE11319 = 65549; + ENUM_VALUE11320 = 65550; + ENUM_VALUE11321 = 65551; + ENUM_VALUE11322 = 65552; + ENUM_VALUE11323 = 65553; + ENUM_VALUE11324 = 65554; + ENUM_VALUE11325 = 65555; + ENUM_VALUE11326 = 65556; + ENUM_VALUE11327 = 65557; + ENUM_VALUE11328 = 65558; + ENUM_VALUE11329 = 65559; + ENUM_VALUE11330 = 65560; + ENUM_VALUE11331 = 65561; + ENUM_VALUE11332 = 65562; + ENUM_VALUE11333 = 65563; + ENUM_VALUE11334 = 69632; + ENUM_VALUE11335 = 69633; + ENUM_VALUE11336 = 69634; + ENUM_VALUE11337 = 69635; + ENUM_VALUE11338 = 69636; + ENUM_VALUE11339 = 69637; + ENUM_VALUE11340 = 69638; + ENUM_VALUE11341 = 69639; + ENUM_VALUE11342 = 69640; + ENUM_VALUE11343 = 69641; + ENUM_VALUE11344 = 69642; + ENUM_VALUE11345 = 69643; + ENUM_VALUE11346 = 69644; + ENUM_VALUE11347 = 69645; + ENUM_VALUE11348 = 69646; + ENUM_VALUE11349 = 69647; + ENUM_VALUE11350 = 69648; + ENUM_VALUE11351 = 69649; + ENUM_VALUE11352 = 69650; + ENUM_VALUE11353 = 69651; + ENUM_VALUE11354 = 69652; + ENUM_VALUE11355 = 69653; + ENUM_VALUE11356 = 69654; + ENUM_VALUE11357 = 69655; + ENUM_VALUE11358 = 69656; + ENUM_VALUE11359 = 69657; + ENUM_VALUE11360 = 69658; + ENUM_VALUE11361 = 69659; + ENUM_VALUE11362 = 69660; + ENUM_VALUE11363 = 69661; + ENUM_VALUE11364 = 69662; + ENUM_VALUE11365 = 73728; + ENUM_VALUE11366 = 73729; + ENUM_VALUE11367 = 77824; + ENUM_VALUE11368 = 77825; + ENUM_VALUE11369 = 81920; + ENUM_VALUE11370 = 81921; + ENUM_VALUE11371 = 81922; + ENUM_VALUE11372 = 81923; + ENUM_VALUE11373 = 86016; + ENUM_VALUE11374 = 86017; + ENUM_VALUE11375 = 86018; + ENUM_VALUE11376 = 86019; + ENUM_VALUE11377 = 86020; + ENUM_VALUE11378 = 86021; + ENUM_VALUE11379 = 86022; + ENUM_VALUE11380 = 86023; + ENUM_VALUE11381 = 86024; + ENUM_VALUE11382 = 86025; + ENUM_VALUE11383 = 86026; + ENUM_VALUE11384 = 86027; + ENUM_VALUE11385 = 86028; + ENUM_VALUE11386 = 86029; + ENUM_VALUE11387 = 86030; + ENUM_VALUE11388 = 86031; + ENUM_VALUE11389 = 86032; + ENUM_VALUE11390 = 86033; + ENUM_VALUE11391 = 86034; + ENUM_VALUE11392 = 86035; + ENUM_VALUE11393 = 86036; + ENUM_VALUE11394 = 86037; + ENUM_VALUE11395 = 86038; + ENUM_VALUE11396 = 86039; + ENUM_VALUE11397 = 86040; + ENUM_VALUE11398 = 86041; + ENUM_VALUE11399 = 86042; + ENUM_VALUE11400 = 86043; + ENUM_VALUE11401 = 86044; + ENUM_VALUE11402 = 86045; + ENUM_VALUE11403 = 86046; + ENUM_VALUE11404 = 86047; + ENUM_VALUE11405 = 86048; + ENUM_VALUE11406 = 86049; + ENUM_VALUE11407 = 86050; + ENUM_VALUE11408 = 86051; + ENUM_VALUE11409 = 86052; + ENUM_VALUE11410 = 86053; + ENUM_VALUE11411 = 86054; + ENUM_VALUE11412 = 86055; + ENUM_VALUE11413 = 86056; + ENUM_VALUE11414 = 86057; + ENUM_VALUE11415 = 86058; + ENUM_VALUE11416 = 86059; + ENUM_VALUE11417 = 86060; + ENUM_VALUE11418 = 86061; + ENUM_VALUE11419 = 86062; + ENUM_VALUE11420 = 86063; + ENUM_VALUE11421 = 86064; + ENUM_VALUE11422 = 86065; + ENUM_VALUE11423 = 86066; + ENUM_VALUE11424 = 86067; + ENUM_VALUE11425 = 86068; + ENUM_VALUE11426 = 86069; + ENUM_VALUE11427 = 86070; + ENUM_VALUE11428 = 86071; + ENUM_VALUE11429 = 86072; + ENUM_VALUE11430 = 86073; + ENUM_VALUE11431 = 86074; + ENUM_VALUE11432 = 86077; + ENUM_VALUE11433 = 86078; + ENUM_VALUE11434 = 86079; + ENUM_VALUE11435 = 86080; + ENUM_VALUE11436 = 86081; + ENUM_VALUE11437 = 86082; + ENUM_VALUE11438 = 86083; + ENUM_VALUE11439 = 86084; + ENUM_VALUE11440 = 90112; + ENUM_VALUE11441 = 94208; + ENUM_VALUE11442 = 94209; + ENUM_VALUE11443 = 94210; + ENUM_VALUE11444 = 94211; + ENUM_VALUE11445 = 94212; + ENUM_VALUE11446 = 94213; + ENUM_VALUE11447 = 94214; + ENUM_VALUE11448 = 94215; + ENUM_VALUE11449 = 94216; + ENUM_VALUE11450 = 94217; + ENUM_VALUE11451 = 94218; + ENUM_VALUE11452 = 94219; + ENUM_VALUE11453 = 94220; + ENUM_VALUE11454 = 94221; + ENUM_VALUE11455 = 94222; + ENUM_VALUE11456 = 94223; + ENUM_VALUE11457 = 94224; + ENUM_VALUE11458 = 98304; + ENUM_VALUE11459 = 98305; + ENUM_VALUE11460 = 98306; + ENUM_VALUE11461 = 98307; + ENUM_VALUE11462 = 98308; + ENUM_VALUE11463 = 102400; + ENUM_VALUE11464 = 131072; + ENUM_VALUE11465 = 131073; + ENUM_VALUE11466 = 135168; + ENUM_VALUE11467 = 9439507; +} + +enum Enum11541 { + ENUM_VALUE11542 = -1; + ENUM_VALUE11543 = 0; + ENUM_VALUE11544 = 1; + ENUM_VALUE11545 = 2; + ENUM_VALUE11546 = 3; + ENUM_VALUE11547 = 4; + ENUM_VALUE11548 = 5; + ENUM_VALUE11549 = 6; + ENUM_VALUE11550 = 7; + ENUM_VALUE11551 = 8; + ENUM_VALUE11552 = 9; + ENUM_VALUE11553 = 10; + ENUM_VALUE11554 = 11; + ENUM_VALUE11555 = 12; + ENUM_VALUE11556 = 13; + ENUM_VALUE11557 = 14; + ENUM_VALUE11558 = 15; + ENUM_VALUE11559 = 16; + ENUM_VALUE11560 = 17; + ENUM_VALUE11561 = 18; + ENUM_VALUE11562 = 19; + ENUM_VALUE11563 = 20; + ENUM_VALUE11564 = 21; + ENUM_VALUE11565 = 22; + ENUM_VALUE11566 = 23; + ENUM_VALUE11567 = 24; + ENUM_VALUE11568 = 25; + ENUM_VALUE11569 = 26; + ENUM_VALUE11570 = 27; + ENUM_VALUE11571 = 28; + ENUM_VALUE11572 = 29; + ENUM_VALUE11573 = 30; + ENUM_VALUE11574 = 31; + ENUM_VALUE11575 = 32; + ENUM_VALUE11576 = 33; + ENUM_VALUE11577 = 34; + ENUM_VALUE11578 = 35; + ENUM_VALUE11579 = 36; + ENUM_VALUE11580 = 37; + ENUM_VALUE11581 = 38; + ENUM_VALUE11582 = 39; + ENUM_VALUE11583 = 40; + ENUM_VALUE11584 = 41; + ENUM_VALUE11585 = 42; + ENUM_VALUE11586 = 43; + ENUM_VALUE11587 = 44; + ENUM_VALUE11588 = 45; + ENUM_VALUE11589 = 46; + ENUM_VALUE11590 = 47; + ENUM_VALUE11591 = 48; + ENUM_VALUE11592 = 49; + ENUM_VALUE11593 = 50; + ENUM_VALUE11594 = 51; + ENUM_VALUE11595 = 52; + ENUM_VALUE11596 = 53; + ENUM_VALUE11597 = 54; + ENUM_VALUE11598 = 55; + ENUM_VALUE11599 = 56; + ENUM_VALUE11600 = 57; + ENUM_VALUE11601 = 58; + ENUM_VALUE11602 = 59; + ENUM_VALUE11603 = 60; + ENUM_VALUE11604 = 61; + ENUM_VALUE11605 = 62; + ENUM_VALUE11606 = 63; + ENUM_VALUE11607 = 64; + ENUM_VALUE11608 = 65; + ENUM_VALUE11609 = 66; + ENUM_VALUE11610 = 67; + ENUM_VALUE11611 = 68; + ENUM_VALUE11612 = 69; + ENUM_VALUE11613 = 70; + ENUM_VALUE11614 = 71; + ENUM_VALUE11615 = 72; + ENUM_VALUE11616 = 73; + ENUM_VALUE11617 = 74; + ENUM_VALUE11618 = 75; + ENUM_VALUE11619 = 76; + ENUM_VALUE11620 = 77; + ENUM_VALUE11621 = 78; + ENUM_VALUE11622 = 79; + ENUM_VALUE11623 = 80; + ENUM_VALUE11624 = 81; + ENUM_VALUE11625 = 82; + ENUM_VALUE11626 = 83; + ENUM_VALUE11627 = 84; + ENUM_VALUE11628 = 85; + ENUM_VALUE11629 = 86; + ENUM_VALUE11630 = 87; + ENUM_VALUE11631 = 88; + ENUM_VALUE11632 = 89; + ENUM_VALUE11633 = 90; + ENUM_VALUE11634 = 91; + ENUM_VALUE11635 = 92; + ENUM_VALUE11636 = 93; + ENUM_VALUE11637 = 94; + ENUM_VALUE11638 = 95; + ENUM_VALUE11639 = 96; + ENUM_VALUE11640 = 97; + ENUM_VALUE11641 = 98; + ENUM_VALUE11642 = 99; + ENUM_VALUE11643 = 100; + ENUM_VALUE11644 = 101; + ENUM_VALUE11645 = 102; + ENUM_VALUE11646 = 103; + ENUM_VALUE11647 = 104; + ENUM_VALUE11648 = 105; + ENUM_VALUE11649 = 106; + ENUM_VALUE11650 = 107; + ENUM_VALUE11651 = 108; + ENUM_VALUE11652 = 109; + ENUM_VALUE11653 = 110; + ENUM_VALUE11654 = 111; + ENUM_VALUE11655 = 112; + ENUM_VALUE11656 = 113; + ENUM_VALUE11657 = 114; + ENUM_VALUE11658 = 115; + ENUM_VALUE11659 = 116; + ENUM_VALUE11660 = 117; + ENUM_VALUE11661 = 118; + ENUM_VALUE11662 = 119; + ENUM_VALUE11663 = 120; + ENUM_VALUE11664 = 121; + ENUM_VALUE11665 = 122; + ENUM_VALUE11666 = 123; + ENUM_VALUE11667 = 124; + ENUM_VALUE11668 = 125; + ENUM_VALUE11669 = 126; + ENUM_VALUE11670 = 127; + ENUM_VALUE11671 = 128; + ENUM_VALUE11672 = 129; + ENUM_VALUE11673 = 130; + ENUM_VALUE11674 = 131; + ENUM_VALUE11675 = 132; + ENUM_VALUE11676 = 133; + ENUM_VALUE11677 = 134; + ENUM_VALUE11678 = 135; + ENUM_VALUE11679 = 136; + ENUM_VALUE11680 = 137; + ENUM_VALUE11681 = 138; + ENUM_VALUE11682 = 139; + ENUM_VALUE11683 = 140; + ENUM_VALUE11684 = 141; + ENUM_VALUE11685 = 142; + ENUM_VALUE11686 = 143; + ENUM_VALUE11687 = 144; + ENUM_VALUE11688 = 145; + ENUM_VALUE11689 = 146; + ENUM_VALUE11690 = 147; + ENUM_VALUE11691 = 148; + ENUM_VALUE11692 = 149; + ENUM_VALUE11693 = 150; + ENUM_VALUE11694 = 151; + ENUM_VALUE11695 = 152; + ENUM_VALUE11696 = 153; + ENUM_VALUE11697 = 154; + ENUM_VALUE11698 = 155; + ENUM_VALUE11699 = 156; + ENUM_VALUE11700 = 157; + ENUM_VALUE11701 = 158; + ENUM_VALUE11702 = 159; + ENUM_VALUE11703 = 160; + ENUM_VALUE11704 = 161; + ENUM_VALUE11705 = 162; + ENUM_VALUE11706 = 163; + ENUM_VALUE11707 = 164; + ENUM_VALUE11708 = 165; + ENUM_VALUE11709 = 166; + ENUM_VALUE11710 = 167; + ENUM_VALUE11711 = 168; + ENUM_VALUE11712 = 169; + ENUM_VALUE11713 = 170; + ENUM_VALUE11714 = 171; + ENUM_VALUE11715 = 172; + ENUM_VALUE11716 = 173; + ENUM_VALUE11717 = 174; + ENUM_VALUE11718 = 175; + ENUM_VALUE11719 = 176; + ENUM_VALUE11720 = 177; + ENUM_VALUE11721 = 178; + ENUM_VALUE11722 = 179; + ENUM_VALUE11723 = 180; + ENUM_VALUE11724 = 181; + ENUM_VALUE11725 = 182; + ENUM_VALUE11726 = 183; + ENUM_VALUE11727 = 184; + ENUM_VALUE11728 = 185; + ENUM_VALUE11729 = 186; + ENUM_VALUE11730 = 187; + ENUM_VALUE11731 = 188; + ENUM_VALUE11732 = 16777215; +} + +enum Enum11468 { + ENUM_VALUE11469 = -99; + ENUM_VALUE11470 = 0; + ENUM_VALUE11471 = 1; + ENUM_VALUE11472 = 2; + ENUM_VALUE11473 = 3; + ENUM_VALUE11474 = 4; + ENUM_VALUE11475 = 28; + ENUM_VALUE11476 = 22; + ENUM_VALUE11477 = 38; + ENUM_VALUE11478 = 512; + ENUM_VALUE11479 = 2048; + ENUM_VALUE11480 = 66; + ENUM_VALUE11481 = 578; + ENUM_VALUE11482 = 77; + ENUM_VALUE11483 = 88; + ENUM_VALUE11484 = 100; + ENUM_VALUE11485 = 110; + ENUM_VALUE11486 = 2158; + ENUM_VALUE11487 = 122; + ENUM_VALUE11488 = 2170; + ENUM_VALUE11489 = 144; + ENUM_VALUE11490 = 244; + ENUM_VALUE11491 = 2292; + ENUM_VALUE11492 = 44; +} + +enum Enum11022 { + ENUM_VALUE11023 = 0; + ENUM_VALUE11024 = 1; + ENUM_VALUE11025 = 2; + ENUM_VALUE11026 = 3; + ENUM_VALUE11027 = 4; + ENUM_VALUE11028 = 5; + ENUM_VALUE11029 = 6; + ENUM_VALUE11030 = 7; + ENUM_VALUE11031 = 8; + ENUM_VALUE11032 = 9; + ENUM_VALUE11033 = 10; + ENUM_VALUE11034 = 11; + ENUM_VALUE11035 = 12; + ENUM_VALUE11036 = 13; + ENUM_VALUE11037 = 14; + ENUM_VALUE11038 = 15; + ENUM_VALUE11039 = 16; + ENUM_VALUE11040 = 17; + ENUM_VALUE11041 = 18; + ENUM_VALUE11042 = 19; + ENUM_VALUE11043 = 20; + ENUM_VALUE11044 = 21; + ENUM_VALUE11045 = 22; + ENUM_VALUE11046 = 23; + ENUM_VALUE11047 = 24; + ENUM_VALUE11048 = 25; + ENUM_VALUE11049 = 26; + ENUM_VALUE11050 = 27; + ENUM_VALUE11051 = 28; + ENUM_VALUE11052 = 29; + ENUM_VALUE11053 = 30; + ENUM_VALUE11054 = 31; + ENUM_VALUE11055 = 32; + ENUM_VALUE11056 = 33; + ENUM_VALUE11057 = 34; + ENUM_VALUE11058 = 35; + ENUM_VALUE11059 = 36; + ENUM_VALUE11060 = 37; + ENUM_VALUE11061 = 38; + ENUM_VALUE11062 = 39; + ENUM_VALUE11063 = 40; + ENUM_VALUE11064 = 41; + ENUM_VALUE11065 = 42; + ENUM_VALUE11066 = 43; + ENUM_VALUE11067 = 44; + ENUM_VALUE11068 = 45; + ENUM_VALUE11069 = 46; + ENUM_VALUE11070 = 47; + ENUM_VALUE11071 = 48; + ENUM_VALUE11072 = 49; + ENUM_VALUE11073 = 50; + ENUM_VALUE11074 = 51; + ENUM_VALUE11075 = 52; + ENUM_VALUE11076 = 53; + ENUM_VALUE11077 = 54; + ENUM_VALUE11078 = 55; + ENUM_VALUE11079 = 56; + ENUM_VALUE11080 = 57; + ENUM_VALUE11081 = 58; + ENUM_VALUE11082 = 59; + ENUM_VALUE11083 = 60; + ENUM_VALUE11084 = 61; + ENUM_VALUE11085 = 62; + ENUM_VALUE11086 = 63; + ENUM_VALUE11087 = 64; + ENUM_VALUE11088 = 65; + ENUM_VALUE11089 = 66; + ENUM_VALUE11090 = 67; + ENUM_VALUE11091 = 68; + ENUM_VALUE11092 = 69; + ENUM_VALUE11093 = 70; + ENUM_VALUE11094 = 71; + ENUM_VALUE11095 = 72; + ENUM_VALUE11096 = 73; + ENUM_VALUE11097 = 74; + ENUM_VALUE11098 = 75; + ENUM_VALUE11099 = 76; + ENUM_VALUE11100 = 77; + ENUM_VALUE11101 = 78; + ENUM_VALUE11102 = 79; + ENUM_VALUE11103 = 80; + ENUM_VALUE11104 = 81; + ENUM_VALUE11105 = 82; + ENUM_VALUE11106 = 83; +} + +enum Enum12670 { + ENUM_VALUE12671 = 0; + ENUM_VALUE12672 = 1; + ENUM_VALUE12673 = 2; +} + +enum Enum12871 { + ENUM_VALUE12872 = 1; + ENUM_VALUE12873 = 2; + ENUM_VALUE12874 = 3; + ENUM_VALUE12875 = 4; + ENUM_VALUE12876 = 5; + ENUM_VALUE12877 = 6; +} + +enum Enum13092 { + ENUM_VALUE13093 = 1; + ENUM_VALUE13094 = 2; + ENUM_VALUE13095 = 3; +} + +enum Enum13146 { + ENUM_VALUE13147 = 0; + ENUM_VALUE13148 = 1; + ENUM_VALUE13149 = 2; + ENUM_VALUE13150 = 3; +} + +enum Enum16042 { + ENUM_VALUE16043 = 0; + ENUM_VALUE16044 = 1; + ENUM_VALUE16045 = 17; + ENUM_VALUE16046 = 273; + ENUM_VALUE16047 = 274; + ENUM_VALUE16048 = 4385; + ENUM_VALUE16049 = 4386; + ENUM_VALUE16050 = 4387; + ENUM_VALUE16051 = 4388; + ENUM_VALUE16052 = 4389; + ENUM_VALUE16053 = 4390; + ENUM_VALUE16054 = 4391; + ENUM_VALUE16055 = 4392; + ENUM_VALUE16056 = 4393; + ENUM_VALUE16057 = 276; + ENUM_VALUE16058 = 277; + ENUM_VALUE16059 = 18; + ENUM_VALUE16060 = 289; + ENUM_VALUE16061 = 291; + ENUM_VALUE16062 = 4657; + ENUM_VALUE16063 = 74513; + ENUM_VALUE16064 = 4658; + ENUM_VALUE16065 = 4659; + ENUM_VALUE16066 = 4660; + ENUM_VALUE16067 = 4661; + ENUM_VALUE16068 = 4662; + ENUM_VALUE16069 = 4663; + ENUM_VALUE16070 = 4664; + ENUM_VALUE16071 = 292; + ENUM_VALUE16072 = 4673; + ENUM_VALUE16073 = 4674; + ENUM_VALUE16074 = 293; + ENUM_VALUE16075 = 19; + ENUM_VALUE16076 = 20; + ENUM_VALUE16077 = 321; + ENUM_VALUE16078 = 5137; + ENUM_VALUE16079 = 5138; + ENUM_VALUE16080 = 5139; + ENUM_VALUE16081 = 5140; + ENUM_VALUE16082 = 5141; + ENUM_VALUE16083 = 5142; + ENUM_VALUE16084 = 82273; + ENUM_VALUE16085 = 82274; + ENUM_VALUE16086 = 82275; + ENUM_VALUE16087 = 82276; + ENUM_VALUE16088 = 82277; + ENUM_VALUE16089 = 82278; + ENUM_VALUE16090 = 5143; + ENUM_VALUE16091 = 5144; + ENUM_VALUE16092 = 5145; + ENUM_VALUE16093 = 5146; + ENUM_VALUE16094 = 82337; + ENUM_VALUE16095 = 5147; + ENUM_VALUE16096 = 5148; + ENUM_VALUE16097 = 322; + ENUM_VALUE16098 = 323; + ENUM_VALUE16099 = 324; + ENUM_VALUE16100 = 325; + ENUM_VALUE16101 = 326; + ENUM_VALUE16102 = 327; + ENUM_VALUE16103 = 328; + ENUM_VALUE16104 = 21; + ENUM_VALUE16105 = 337; + ENUM_VALUE16106 = 22; + ENUM_VALUE16107 = 23; + ENUM_VALUE16108 = 24; + ENUM_VALUE16109 = 2; + ENUM_VALUE16110 = 33; + ENUM_VALUE16111 = 34; + ENUM_VALUE16112 = 545; + ENUM_VALUE16113 = 8721; + ENUM_VALUE16114 = 8723; + ENUM_VALUE16115 = 8724; + ENUM_VALUE16116 = 546; + ENUM_VALUE16117 = 8739; + ENUM_VALUE16118 = 8740; + ENUM_VALUE16119 = 547; + ENUM_VALUE16120 = 548; + ENUM_VALUE16121 = 549; + ENUM_VALUE16122 = 550; + ENUM_VALUE16123 = 551; + ENUM_VALUE16124 = 552; + ENUM_VALUE16125 = 553; + ENUM_VALUE16126 = 35; + ENUM_VALUE16127 = 36; + ENUM_VALUE16128 = 37; + ENUM_VALUE16129 = 593; + ENUM_VALUE16130 = 594; + ENUM_VALUE16131 = 595; + ENUM_VALUE16132 = 596; + ENUM_VALUE16133 = 597; + ENUM_VALUE16134 = 38; + ENUM_VALUE16135 = 609; + ENUM_VALUE16136 = 610; + ENUM_VALUE16137 = 617; + ENUM_VALUE16138 = 614; + ENUM_VALUE16139 = 615; + ENUM_VALUE16140 = 616; + ENUM_VALUE16141 = 618; + ENUM_VALUE16142 = 620; + ENUM_VALUE16143 = 9937; + ENUM_VALUE16144 = 9938; + ENUM_VALUE16145 = 9939; + ENUM_VALUE16146 = 9940; + ENUM_VALUE16147 = 9941; + ENUM_VALUE16148 = 39; + ENUM_VALUE16149 = 40; + ENUM_VALUE16150 = 41; + ENUM_VALUE16151 = 42; + ENUM_VALUE16152 = 43; + ENUM_VALUE16153 = 44; + ENUM_VALUE16154 = 45; + ENUM_VALUE16155 = 11793; + ENUM_VALUE16156 = 3; + ENUM_VALUE16157 = 49; + ENUM_VALUE16158 = 50; + ENUM_VALUE16159 = 51; + ENUM_VALUE16160 = 817; + ENUM_VALUE16161 = 818; + ENUM_VALUE16162 = 819; + ENUM_VALUE16163 = 52; + ENUM_VALUE16164 = 833; + ENUM_VALUE16165 = 53; + ENUM_VALUE16166 = 54; + ENUM_VALUE16167 = 4; + ENUM_VALUE16168 = 1041; + ENUM_VALUE16169 = 16657; + ENUM_VALUE16170 = 16658; + ENUM_VALUE16171 = 16659; + ENUM_VALUE16172 = 16660; + ENUM_VALUE16173 = 16661; + ENUM_VALUE16174 = 1042; + ENUM_VALUE16175 = 16673; + ENUM_VALUE16176 = 1043; + ENUM_VALUE16177 = 16689; + ENUM_VALUE16178 = 16690; + ENUM_VALUE16179 = 16691; + ENUM_VALUE16180 = 16692; + ENUM_VALUE16181 = 16693; + ENUM_VALUE16182 = 16694; + ENUM_VALUE16183 = 16695; + ENUM_VALUE16184 = 1044; + ENUM_VALUE16185 = 16705; + ENUM_VALUE16186 = 16706; + ENUM_VALUE16187 = 16707; + ENUM_VALUE16188 = 16708; + ENUM_VALUE16189 = 16709; + ENUM_VALUE16190 = 16710; + ENUM_VALUE16191 = 16711; + ENUM_VALUE16192 = 16712; + ENUM_VALUE16193 = 16713; + ENUM_VALUE16194 = 1046; + ENUM_VALUE16195 = 16737; + ENUM_VALUE16196 = 1047; + ENUM_VALUE16197 = 16753; + ENUM_VALUE16198 = 268049; + ENUM_VALUE16199 = 268050; + ENUM_VALUE16200 = 268051; + ENUM_VALUE16201 = 268052; + ENUM_VALUE16202 = 1048; + ENUM_VALUE16203 = 16769; + ENUM_VALUE16204 = 16770; + ENUM_VALUE16205 = 16771; + ENUM_VALUE16206 = 16772; + ENUM_VALUE16207 = 16773; + ENUM_VALUE16208 = 1049; + ENUM_VALUE16209 = 1056; + ENUM_VALUE16210 = 1058; + ENUM_VALUE16211 = 1059; + ENUM_VALUE16212 = 1060; + ENUM_VALUE16213 = 1061; + ENUM_VALUE16214 = 5; + ENUM_VALUE16215 = 6; + ENUM_VALUE16216 = 97; + ENUM_VALUE16217 = 98; + ENUM_VALUE16218 = 99; + ENUM_VALUE16219 = 100; + ENUM_VALUE16220 = 101; + ENUM_VALUE16221 = 102; + ENUM_VALUE16222 = 103; + ENUM_VALUE16223 = 104; + ENUM_VALUE16224 = 105; + ENUM_VALUE16225 = 106; + ENUM_VALUE16226 = 108; + ENUM_VALUE16227 = 1729; + ENUM_VALUE16228 = 1730; + ENUM_VALUE16229 = 1731; + ENUM_VALUE16230 = 7; + ENUM_VALUE16231 = 8; + ENUM_VALUE16232 = 9; + ENUM_VALUE16233 = 10; + ENUM_VALUE16234 = 161; + ENUM_VALUE16235 = 2577; + ENUM_VALUE16236 = 41233; + ENUM_VALUE16237 = 41234; + ENUM_VALUE16238 = 2578; + ENUM_VALUE16239 = 2579; + ENUM_VALUE16240 = 41265; + ENUM_VALUE16241 = 2580; + ENUM_VALUE16242 = 2581; + ENUM_VALUE16243 = 41297; + ENUM_VALUE16244 = 41298; + ENUM_VALUE16245 = 41299; + ENUM_VALUE16246 = 41300; + ENUM_VALUE16247 = 2582; + ENUM_VALUE16248 = 2583; + ENUM_VALUE16249 = 2584; + ENUM_VALUE16250 = 162; + ENUM_VALUE16251 = 2593; + ENUM_VALUE16252 = 41489; + ENUM_VALUE16253 = 663825; + ENUM_VALUE16254 = 663826; + ENUM_VALUE16255 = 41490; + ENUM_VALUE16256 = 41491; + ENUM_VALUE16257 = 41492; + ENUM_VALUE16258 = 663873; + ENUM_VALUE16259 = 2594; + ENUM_VALUE16260 = 41505; + ENUM_VALUE16261 = 41506; + ENUM_VALUE16262 = 41507; + ENUM_VALUE16263 = 2595; + ENUM_VALUE16264 = 41521; + ENUM_VALUE16265 = 41522; + ENUM_VALUE16266 = 41523; + ENUM_VALUE16267 = 41524; + ENUM_VALUE16268 = 41525; + ENUM_VALUE16269 = 664401; + ENUM_VALUE16270 = 664402; + ENUM_VALUE16271 = 41526; + ENUM_VALUE16272 = 41527; + ENUM_VALUE16273 = 2596; + ENUM_VALUE16274 = 2597; + ENUM_VALUE16275 = 2598; + ENUM_VALUE16276 = 41569; + ENUM_VALUE16277 = 41570; + ENUM_VALUE16278 = 41571; + ENUM_VALUE16279 = 41572; + ENUM_VALUE16280 = 41573; + ENUM_VALUE16281 = 665169; + ENUM_VALUE16282 = 665170; + ENUM_VALUE16283 = 665171; + ENUM_VALUE16284 = 665172; + ENUM_VALUE16285 = 2599; + ENUM_VALUE16286 = 2600; + ENUM_VALUE16287 = 2601; + ENUM_VALUE16288 = 2603; + ENUM_VALUE16289 = 2604; + ENUM_VALUE16290 = 163; + ENUM_VALUE16291 = 2608; + ENUM_VALUE16292 = 2609; + ENUM_VALUE16293 = 2610; + ENUM_VALUE16294 = 2611; + ENUM_VALUE16295 = 2612; + ENUM_VALUE16296 = 164; + ENUM_VALUE16297 = 2625; + ENUM_VALUE16298 = 2626; + ENUM_VALUE16299 = 42017; + ENUM_VALUE16300 = 42018; + ENUM_VALUE16301 = 42019; + ENUM_VALUE16302 = 2627; + ENUM_VALUE16303 = 2628; + ENUM_VALUE16304 = 165; + ENUM_VALUE16305 = 2641; + ENUM_VALUE16306 = 42257; + ENUM_VALUE16307 = 42258; + ENUM_VALUE16308 = 2642; + ENUM_VALUE16309 = 2643; + ENUM_VALUE16310 = 2644; + ENUM_VALUE16311 = 2646; + ENUM_VALUE16312 = 2647; + ENUM_VALUE16313 = 42353; + ENUM_VALUE16314 = 2648; + ENUM_VALUE16315 = 2649; + ENUM_VALUE16316 = 2650; + ENUM_VALUE16317 = 2651; + ENUM_VALUE16318 = 2652; + ENUM_VALUE16319 = 2653; + ENUM_VALUE16320 = 2654; + ENUM_VALUE16321 = 42481; + ENUM_VALUE16322 = 42482; + ENUM_VALUE16323 = 42483; + ENUM_VALUE16324 = 166; + ENUM_VALUE16325 = 2657; + ENUM_VALUE16326 = 2658; + ENUM_VALUE16327 = 42529; + ENUM_VALUE16328 = 2659; + ENUM_VALUE16329 = 2660; + ENUM_VALUE16330 = 2661; + ENUM_VALUE16331 = 2662; + ENUM_VALUE16332 = 2663; + ENUM_VALUE16333 = 42609; + ENUM_VALUE16334 = 2664; + ENUM_VALUE16335 = 2665; + ENUM_VALUE16336 = 42753; + ENUM_VALUE16337 = 42754; + ENUM_VALUE16338 = 42755; + ENUM_VALUE16339 = 11; + ENUM_VALUE16340 = 177; + ENUM_VALUE16341 = 2833; + ENUM_VALUE16342 = 179; + ENUM_VALUE16343 = 180; + ENUM_VALUE16344 = 2881; + ENUM_VALUE16345 = 182; + ENUM_VALUE16346 = 183; + ENUM_VALUE16347 = 12; + ENUM_VALUE16348 = 3089; + ENUM_VALUE16349 = 194; + ENUM_VALUE16350 = 195; + ENUM_VALUE16351 = 196; + ENUM_VALUE16352 = 198; + ENUM_VALUE16353 = 3169; + ENUM_VALUE16354 = 199; + ENUM_VALUE16355 = 200; + ENUM_VALUE16356 = 208; + ENUM_VALUE16357 = 3329; + ENUM_VALUE16358 = 3330; + ENUM_VALUE16359 = 3331; + ENUM_VALUE16360 = 209; + ENUM_VALUE16361 = 210; + ENUM_VALUE16362 = 211; + ENUM_VALUE16363 = 3377; + ENUM_VALUE16364 = 3378; + ENUM_VALUE16365 = 3379; + ENUM_VALUE16366 = 3380; + ENUM_VALUE16367 = 3381; + ENUM_VALUE16368 = 865809; + ENUM_VALUE16369 = 865810; + ENUM_VALUE16370 = 865811; + ENUM_VALUE16371 = 865812; + ENUM_VALUE16372 = 865813; + ENUM_VALUE16373 = 865814; + ENUM_VALUE16374 = 865815; + ENUM_VALUE16375 = 865816; + ENUM_VALUE16376 = 865817; + ENUM_VALUE16377 = 865818; + ENUM_VALUE16378 = 865819; + ENUM_VALUE16379 = 865820; + ENUM_VALUE16380 = 865821; + ENUM_VALUE16381 = 865822; + ENUM_VALUE16382 = 865823; + ENUM_VALUE16383 = 865824; + ENUM_VALUE16384 = 865825; + ENUM_VALUE16385 = 865826; + ENUM_VALUE16386 = 865827; + ENUM_VALUE16387 = 865828; + ENUM_VALUE16388 = 865829; + ENUM_VALUE16389 = 212; + ENUM_VALUE16390 = 3393; + ENUM_VALUE16391 = 3394; + ENUM_VALUE16392 = 3395; + ENUM_VALUE16393 = 213; + ENUM_VALUE16394 = 214; + ENUM_VALUE16395 = 215; + ENUM_VALUE16396 = 3441; + ENUM_VALUE16397 = 3442; + ENUM_VALUE16398 = 216; + ENUM_VALUE16399 = 217; + ENUM_VALUE16400 = 3473; + ENUM_VALUE16401 = 3474; + ENUM_VALUE16402 = 3475; + ENUM_VALUE16403 = 254; + ENUM_VALUE16404 = 255; +} + +enum Enum16553 { + ENUM_VALUE16554 = 0; + ENUM_VALUE16555 = 1; + ENUM_VALUE16556 = 2; + ENUM_VALUE16557 = 3; + ENUM_VALUE16558 = 4; + ENUM_VALUE16559 = 5; + ENUM_VALUE16560 = 6; + ENUM_VALUE16561 = 7; + ENUM_VALUE16562 = 8; + ENUM_VALUE16563 = 9; +} + +enum Enum16728 { + ENUM_VALUE16729 = 1; + ENUM_VALUE16730 = 2; + ENUM_VALUE16731 = 3; +} + +enum Enum16732 { + ENUM_VALUE16733 = 1; + ENUM_VALUE16734 = 2; + ENUM_VALUE16735 = 3; + ENUM_VALUE16736 = 4; + ENUM_VALUE16737 = 5; +} + +enum Enum16738 { + ENUM_VALUE16739 = 1; + ENUM_VALUE16740 = 2; + ENUM_VALUE16741 = 3; + ENUM_VALUE16742 = 4; + ENUM_VALUE16743 = 5; + ENUM_VALUE16744 = 6; + ENUM_VALUE16745 = 7; +} + +enum Enum16698 { + ENUM_VALUE16699 = -1; + ENUM_VALUE16700 = 100; + ENUM_VALUE16701 = 2; + ENUM_VALUE16702 = 0; + ENUM_VALUE16703 = 1; + ENUM_VALUE16704 = 4; + ENUM_VALUE16705 = 11; + ENUM_VALUE16706 = 12; + ENUM_VALUE16707 = 3; + ENUM_VALUE16708 = 5; + ENUM_VALUE16709 = 6; + ENUM_VALUE16710 = 7; + ENUM_VALUE16711 = 8; + ENUM_VALUE16712 = 9; + ENUM_VALUE16713 = 10; + ENUM_VALUE16714 = 13; + ENUM_VALUE16715 = 14; + ENUM_VALUE16716 = 15; + ENUM_VALUE16717 = 16; + ENUM_VALUE16718 = 18; + ENUM_VALUE16719 = 17; + ENUM_VALUE16720 = 19; + ENUM_VALUE16721 = 20; +} + +enum Enum16819 { + ENUM_VALUE16820 = 0; + ENUM_VALUE16821 = 1; + ENUM_VALUE16822 = 2; + ENUM_VALUE16823 = 3; + ENUM_VALUE16824 = 4; + ENUM_VALUE16825 = 5; +} + +enum Enum16925 { + ENUM_VALUE16926 = 0; + ENUM_VALUE16927 = 1; + ENUM_VALUE16928 = 2; + ENUM_VALUE16929 = 3; + ENUM_VALUE16930 = 4; + ENUM_VALUE16931 = 5; + ENUM_VALUE16932 = 6; + ENUM_VALUE16933 = 7; + ENUM_VALUE16934 = 8; + ENUM_VALUE16935 = 9; + ENUM_VALUE16936 = 10; + ENUM_VALUE16937 = 11; + ENUM_VALUE16938 = 12; + ENUM_VALUE16939 = 13; +} + +enum Enum22854 { + ENUM_VALUE22855 = 0; + ENUM_VALUE22856 = 1; +} + +enum Enum24361 { + ENUM_VALUE24362 = 0; + ENUM_VALUE24363 = 1; + ENUM_VALUE24364 = 2; + ENUM_VALUE24365 = 3; +} + +enum Enum16891 { + ENUM_VALUE16892 = 0; + ENUM_VALUE16893 = 1; + ENUM_VALUE16894 = 2; + ENUM_VALUE16895 = 3; + ENUM_VALUE16896 = 4; + ENUM_VALUE16897 = 5; + ENUM_VALUE16898 = 6; + ENUM_VALUE16899 = 7; + ENUM_VALUE16900 = 8; + ENUM_VALUE16901 = 9; + ENUM_VALUE16902 = 10; + ENUM_VALUE16903 = 11; + ENUM_VALUE16904 = 12; + ENUM_VALUE16905 = 13; + ENUM_VALUE16906 = 14; + ENUM_VALUE16907 = 15; + ENUM_VALUE16908 = 16; + ENUM_VALUE16909 = 17; + ENUM_VALUE16910 = 18; + ENUM_VALUE16911 = 19; + ENUM_VALUE16912 = 20; + ENUM_VALUE16913 = 21; + ENUM_VALUE16914 = 22; + ENUM_VALUE16915 = 23; + ENUM_VALUE16916 = 24; + ENUM_VALUE16917 = 25; + ENUM_VALUE16918 = 26; + ENUM_VALUE16919 = 27; + ENUM_VALUE16920 = 28; + ENUM_VALUE16921 = 29; + ENUM_VALUE16922 = 30; + ENUM_VALUE16923 = 31; +} + +enum Enum27361 { + ENUM_VALUE27362 = 0; + ENUM_VALUE27363 = 1; + ENUM_VALUE27364 = 2; + ENUM_VALUE27365 = 3; + ENUM_VALUE27366 = 4; +} + +enum Enum33960 { + ENUM_VALUE33961 = 0; + ENUM_VALUE33962 = 1; + ENUM_VALUE33963 = 2; + ENUM_VALUE33964 = 3; + ENUM_VALUE33965 = 4; + ENUM_VALUE33966 = 5; + ENUM_VALUE33967 = 6; +} + +enum Enum34388 { ENUM_VALUE34389 = 1; } + +enum Enum35477 { + ENUM_VALUE35478 = 4; + ENUM_VALUE35479 = 3; + ENUM_VALUE35480 = 2; + ENUM_VALUE35481 = 1; + ENUM_VALUE35482 = 0; +} + +enum Enum35507 { + ENUM_VALUE35508 = 0; + ENUM_VALUE35509 = 1; + ENUM_VALUE35510 = 2; + ENUM_VALUE35511 = 3; + ENUM_VALUE35512 = 4; + ENUM_VALUE35513 = 5; + ENUM_VALUE35514 = 6; + ENUM_VALUE35515 = 7; + ENUM_VALUE35516 = 8; + ENUM_VALUE35517 = 9; +} + +enum Enum36860 { + ENUM_VALUE36861 = 0; + ENUM_VALUE36862 = 1; + ENUM_VALUE36863 = 2; + ENUM_VALUE36864 = 3; + ENUM_VALUE36865 = 4; + ENUM_VALUE36866 = 5; + ENUM_VALUE36867 = 6; + ENUM_VALUE36868 = 7; +} + +enum Enum36890 { + ENUM_VALUE36891 = 0; + ENUM_VALUE36892 = 1; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message4/BUILD.bazel b/libs/protobuf/benchmarks/datasets/google_message4/BUILD.bazel new file mode 100644 index 0000000..33de093 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message4/BUILD.bazel @@ -0,0 +1,53 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_proto//proto:defs.bzl", "proto_library") + +filegroup( + name = "datasets", + srcs = [], + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +proto_library( + name = "benchmark_message4_proto", + srcs = [ + "benchmark_message4.proto", + "benchmark_message4_1.proto", + "benchmark_message4_2.proto", + "benchmark_message4_3.proto", + ], + strip_import_prefix = "/benchmarks", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], +) + +cc_proto_library( + name = "benchmark_message4_cc_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) + +java_proto_library( + name = "benchmark_message4_java_proto", + visibility = [ + "//benchmarks/datasets:__pkg__", + ], + deps = [ + "benchmark_message4_proto", + ], +) + +pkg_files( + name = "dist_files", + srcs = glob(["*"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4.proto b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4.proto new file mode 100644 index 0000000..424ed10 --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4.proto @@ -0,0 +1,484 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message4; + +import "datasets/google_message4/benchmark_message4_1.proto"; +import "datasets/google_message4/benchmark_message4_2.proto"; +import "datasets/google_message4/benchmark_message4_3.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message GoogleMessage4 { + optional int32 field37503 = 1; + optional .benchmarks.google_message4.UnusedEmptyMessage field37504 = 2; + optional .benchmarks.google_message4.UnusedEmptyMessage field37505 = 3; + optional .benchmarks.google_message4.UnusedEmptyMessage field37506 = 4; + optional .benchmarks.google_message4.UnusedEmptyMessage field37507 = 5; + optional .benchmarks.google_message4.Message37489 field37508 = 6; + optional .benchmarks.google_message4.UnusedEmptyMessage field37509 = 7; + optional .benchmarks.google_message4.UnusedEmptyMessage field37510 = 8; + optional .benchmarks.google_message4.UnusedEmptyMessage field37511 = 9; + optional .benchmarks.google_message4.UnusedEmptyMessage field37512 = 10; + optional .benchmarks.google_message4.UnusedEmptyMessage field37513 = 11; + optional .benchmarks.google_message4.UnusedEmptyMessage field37514 = 12; + optional .benchmarks.google_message4.UnusedEmptyMessage field37515 = 13; + optional .benchmarks.google_message4.UnusedEmptyMessage field37516 = 14; + optional .benchmarks.google_message4.UnusedEmptyMessage field37517 = 15; + optional .benchmarks.google_message4.UnusedEmptyMessage field37518 = 16; +} + +message Message37489 { + optional .benchmarks.google_message4.Message2517 field37534 = 3; + optional .benchmarks.google_message4.Message7330 field37535 = 4; + optional .benchmarks.google_message4.Message8815 field37536 = 6; + optional .benchmarks.google_message4.Message8817 field37537 = 7; + optional .benchmarks.google_message4.Message8835 field37538 = 8; + optional .benchmarks.google_message4.Message8848 field37539 = 9; + optional .benchmarks.google_message4.Message8856 field37540 = 11; + optional .benchmarks.google_message4.Message12717 field37541 = 15; + optional .benchmarks.google_message4.Message12748 field37542 = 20; + optional .benchmarks.google_message4.Message7319 field37543 = 22; + optional .benchmarks.google_message4.Message12908 field37544 = 24; + optional .benchmarks.google_message4.Message12910 field37545 = 25; + optional .benchmarks.google_message4.Message12960 field37546 = 30; + optional .benchmarks.google_message4.Message176 field37547 = 33; + optional .benchmarks.google_message4.Message13000 field37548 = 34; + optional .benchmarks.google_message4.Message13035 field37549 = 35; + optional .benchmarks.google_message4.Message37331 field37550 = 36; + optional .benchmarks.google_message4.Message37329 field37551 = 37; + optional .benchmarks.google_message4.Message37327 field37552 = 38; + optional .benchmarks.google_message4.Message37333 field37553 = 39; + optional .benchmarks.google_message4.Message37335 field37554 = 40; +} + +message Message7319 { + optional .benchmarks.google_message4.UnusedEmptyMessage field7321 = 1; + optional .benchmarks.google_message4.UnusedEmptyMessage field7322 = 7; +} + +message Message12717 { + optional .benchmarks.google_message4.UnusedEmptyMessage field12719 = 1; + optional string field12720 = 2; + optional uint32 field12721 = 3; + optional .benchmarks.google_message4.Message11976 field12722 = 4; + repeated .benchmarks.google_message4.Message11948 field12723 = 5; + optional .benchmarks.google_message4.Message11947 field12724 = 6; + optional .benchmarks.google_message4.Message12687 field12725 = 7; + repeated .benchmarks.google_message4.Message11948 field12726 = 8; + optional int64 field12727 = 9; +} + +message Message37331 { + optional .benchmarks.google_message4.UnusedEmptyMessage field37367 = 4; + required .benchmarks.google_message4.Message37326 field37368 = 1; + required int64 field37369 = 2; + required bytes field37370 = 3; +} + +message Message8815 { + optional .benchmarks.google_message4.UnusedEmptyMessage field8819 = 1; + repeated .benchmarks.google_message4.Message8768 field8820 = 2; + optional bool field8821 = 3; +} + +message Message7330 { + optional .benchmarks.google_message4.UnusedEmptyMessage field7332 = 1; + optional .benchmarks.google_message4.Message3069 field7333 = 2; + optional .benchmarks.google_message4.Message7320 field7334 = 3; + optional .benchmarks.google_message4.UnusedEmptyMessage field7335 = 4; + optional bool field7336 = 5; + optional int64 field7337 = 6; +} + +message Message12960 { + optional .benchmarks.google_message4.UnusedEmptyMessage field12962 = 1; + optional .benchmarks.google_message4.Message12948 field12963 = 2; +} + +message Message176 { + required string field408 = 1; + optional int32 field409 = 4; + optional string field410 = 50; + optional int32 field411 = 2; + optional uint64 field412 = 47; + optional string field413 = 56; + optional int32 field414 = 24; + optional string field415 = 21; + optional bytes field416 = 3; + optional string field417 = 57; + optional int32 field418 = 51; + optional float field419 = 7; + optional bool field420 = 5; + optional bool field421 = 28; + optional int32 field422 = 6; + repeated int32 field423 = 40; + optional .benchmarks.google_message4.UnusedEmptyMessage field424 = 41; + optional bool field425 = 25; + optional uint64 field426 = 26; + optional int32 field427 = 38; + optional bytes field428 = 15; + optional bytes field429 = 55; + optional bytes field430 = 16; + optional bytes field431 = 23; + optional bool field432 = 33; + optional bytes field433 = 31; + optional bytes field434 = 32; + optional int32 field435 = 36; + optional uint64 field436 = 17; + optional int32 field437 = 45; + optional uint64 field438 = 18; + optional string field439 = 46; + optional .benchmarks.google_message4.UnusedEmptyMessage field440 = 64; + optional int32 field441 = 39; + optional uint64 field442 = 48; + optional bytes field443 = 19; + optional bytes field444 = 42; + optional bytes field445 = 43; + optional string field446 = 44; + optional string field447 = 49; + optional int64 field448 = 20; + optional bool field449 = 53; + optional .benchmarks.google_message4.UnusedEmptyMessage field450 = 54; + repeated .benchmarks.google_message4.UnusedEmptyMessage field451 = 22; + optional .benchmarks.google_message4.UnusedEnum field452 = 27; + optional int32 field453 = 29; + optional int32 field454 = 30; + optional .benchmarks.google_message4.UnusedEnum field455 = 37; + optional .benchmarks.google_message4.UnusedEnum field456 = 34; + optional int32 field457 = 35; + repeated group Message178 = 101 {} + optional bool field459 = 52; + optional uint64 field460 = 58; + optional uint64 field461 = 59; + optional .benchmarks.google_message4.UnusedEmptyMessage field462 = 60; + optional .benchmarks.google_message4.UnusedEmptyMessage field463 = 61; + optional .benchmarks.google_message4.UnusedEnum field464 = 62; + repeated string field465 = 63; + optional .benchmarks.google_message4.UnusedEmptyMessage field466 = 65; +} + +message Message8817 { + optional .benchmarks.google_message4.UnusedEmptyMessage field8825 = 1; + repeated .benchmarks.google_message4.Message8768 field8826 = 2; + optional string field8827 = 3; +} + +message Message8835 { + optional .benchmarks.google_message4.UnusedEmptyMessage field8837 = 1; + repeated string field8838 = 2; + optional .benchmarks.google_message4.UnusedEnum field8839 = 3; +} + +message Message37333 { + optional .benchmarks.google_message4.UnusedEmptyMessage field37372 = 3; + required .benchmarks.google_message4.Message37326 field37373 = 1; + optional uint64 field37374 = 2; +} + +message Message13000 { + optional int64 field13015 = 1; + repeated .benchmarks.google_message4.Message12979 field13016 = 2; +} + +message Message37335 { + optional .benchmarks.google_message4.UnusedEmptyMessage field37376 = 4; + required .benchmarks.google_message4.Message37326 field37377 = 1; + required .benchmarks.google_message4.Message37173 field37378 = 2; + optional uint64 field37379 = 3; +} + +message Message8848 { + optional .benchmarks.google_message4.UnusedEmptyMessage field8850 = 1; + optional string field8851 = 2; + optional bytes field8852 = 3; +} + +message Message13035 { + optional int64 field13058 = 1; + repeated int64 field13059 = 2; +} + +message Message8856 { + optional .benchmarks.google_message4.UnusedEmptyMessage field8858 = 1; + optional string field8859 = 2; +} + +message Message12908 { + optional .benchmarks.google_message4.UnusedEmptyMessage field12912 = 1; + optional string field12913 = 2; + optional .benchmarks.google_message4.Message12799 field12914 = 3; + optional int64 field12915 = 4; + optional .benchmarks.google_message4.Message3804 field12916 = 5; + optional .benchmarks.google_message4.Message12870 field12917 = 6; +} + +message Message12910 { + optional .benchmarks.google_message4.UnusedEmptyMessage field12920 = 1; + optional .benchmarks.google_message4.Message12818 field12921 = 2; + repeated .benchmarks.google_message4.Message12903 field12922 = 3; +} + +message Message37327 { + optional .benchmarks.google_message4.UnusedEmptyMessage field37347 = 11; + required .benchmarks.google_message4.Message37326 field37348 = 1; + optional bool field37349 = 2; + optional bool field37350 = 3; + optional bool field37351 = 4; + optional bool field37352 = 5; + optional bool field37353 = 6; + optional .benchmarks.google_message4.UnusedEmptyMessage field37354 = 7; + optional uint64 field37355 = 8; + optional bool field37356 = 9; + optional bool field37357 = 10; +} + +message Message37329 { + optional .benchmarks.google_message4.UnusedEmptyMessage field37359 = 6; + required .benchmarks.google_message4.Message37326 field37360 = 1; + required int64 field37361 = 2; + required int64 field37362 = 3; + optional bool field37363 = 4; +} + +message Message2517 { + optional .benchmarks.google_message4.UnusedEmptyMessage field2519 = 1; + optional .benchmarks.google_message4.Message2356 field2520 = 2; + optional .benchmarks.google_message4.Message0 field2521 = 3; + optional .benchmarks.google_message4.Message2463 field2522 = 4; + repeated .benchmarks.google_message4.Message971 field2523 = 5; +} + +message Message12748 { + optional .benchmarks.google_message4.UnusedEmptyMessage field12754 = 1; + optional string field12755 = 2; + optional string field12756 = 3; + optional .benchmarks.google_message4.Enum12735 field12757 = 4; +} + +message Message12687 { + repeated .benchmarks.google_message4.Message12686 field12701 = 1; +} + +message Message11948 { + optional string field11954 = 1; + repeated .benchmarks.google_message4.Message11949 field11955 = 2; + optional bool field11956 = 3; +} + +message Message11976 { + repeated .benchmarks.google_message4.Message11975 field12002 = 1; +} + +message Message7320 { + optional .benchmarks.google_message4.UnusedEmptyMessage field7323 = 1; + optional .benchmarks.google_message4.Message7287 field7324 = 8; +} + +message Message3069 { + optional .benchmarks.google_message4.Message3061 field3374 = 1; + optional bytes field3375 = 2; + repeated group Message3070 = 3 { + required .benchmarks.google_message4.Enum3071 field3378 = 4; + required bytes field3379 = 5; + } + extensions 10000 to 536870911; +} + +message Message12948 { + repeated .benchmarks.google_message4.Message12949 field12958 = 1; +} + +message Message8768 { + optional string field8782 = 1; + optional .benchmarks.google_message4.Message8572 field8783 = 2; + optional bool field8784 = 3; + repeated .benchmarks.google_message4.Message8774 field8785 = 4; + optional int64 field8786 = 5; + optional .benchmarks.google_message4.UnusedEmptyMessage field8787 = 6; + optional string field8788 = 7; +} + +message Message12979 { + required bytes field12981 = 1; + repeated string field12982 = 2; + optional .benchmarks.google_message4.UnusedEmptyMessage field12983 = 3; + optional int64 field12984 = 4; + optional string field12985 = 5; + optional int32 field12986 = 6; + optional .benchmarks.google_message4.UnusedEmptyMessage field12987 = 7; +} + +message Message37173 { + optional string field37252 = 1; + optional int64 field37253 = 2; + optional .benchmarks.google_message4.UnusedEnum field37254 = 4; + optional bool field37255 = 5; + optional bool field37256 = 6; + optional bool field37257 = 7; + optional string field37258 = 8; + optional string field37259 = 9; + optional uint32 field37260 = 10; + optional fixed32 field37261 = 11; + optional string field37262 = 12; + optional string field37263 = 13; + optional string field37264 = 14; + optional int32 field37265 = 15; + optional int64 field37266 = 16; + optional int64 field37267 = 17; + optional int32 field37268 = 18; + optional int32 field37269 = 19; + optional .benchmarks.google_message4.UnusedEmptyMessage field37270 = 20; + optional .benchmarks.google_message4.UnusedEmptyMessage field37271 = 21; + optional .benchmarks.google_message4.UnusedEmptyMessage field37272 = 22; + optional .benchmarks.google_message4.UnusedEmptyMessage field37273 = 23; + optional .benchmarks.google_message4.UnusedEmptyMessage field37274 = 24; + optional string field37275 = 25; + optional bool field37276 = 26; +} + +message Message12799 { + required string field12809 = 1; + repeated fixed64 field12810 = 2; + repeated .benchmarks.google_message4.Message12776 field12811 = 8; + repeated int32 field12812 = 4; + repeated .benchmarks.google_message4.Message12798 field12813 = 5; + required int32 field12814 = 3; + optional int32 field12815 = 6; + optional .benchmarks.google_message4.Message12797 field12816 = 7; +} + +message Message12870 { + required int32 field12879 = 1; + optional int32 field12880 = 7; + required int32 field12881 = 2; + optional uint64 field12882 = 3; + optional string field12883 = 2001; + optional fixed64 field12884 = 4; + repeated fixed64 field12885 = 14; + optional int32 field12886 = 9; + optional int64 field12887 = 18; + repeated .benchmarks.google_message4.Message12870 field12888 = 8; + optional int32 field12889 = 5; + optional uint64 field12890 = 6; + optional int32 field12891 = 10; + optional int32 field12892 = 11; + optional double field12893 = 12; + optional .benchmarks.google_message4.Message12825 field12894 = 13; + optional double field12895 = 15; + optional string field12896 = 16; + optional .benchmarks.google_message4.Enum12871 field12897 = 17; + optional int32 field12898 = 19; +} + +message Message3804 { + required int64 field3818 = 1; + required bool field3819 = 2; + repeated .benchmarks.google_message4.Enum3805 field3820 = 4; + optional int32 field3821 = 5; + optional bool field3822 = 6; + optional int64 field3823 = 7; + optional .benchmarks.google_message4.Enum3783 field3824 = 8; +} + +message Message12903 { + optional string field12905 = 1; + optional .benchmarks.google_message4.Message8587 field12906 = 2; + repeated .benchmarks.google_message4.Message8590 field12907 = 3; +} + +message Message37326 { + required string field37345 = 1; + optional string field37346 = 2; +} + +message Message2356 { + optional .benchmarks.google_message4.Message1374 field2368 = 121; + optional uint64 field2369 = 1; + optional int32 field2370 = 2; + optional int32 field2371 = 17; + required string field2372 = 3; + optional int32 field2373 = 7; + optional bytes field2374 = 8; + optional string field2375 = 4; + optional string field2376 = 101; + optional int32 field2377 = 102; + optional int32 field2378 = 103; + optional int32 field2379 = 104; + optional int32 field2380 = 113; + optional int32 field2381 = 114; + optional int32 field2382 = 115; + optional int32 field2383 = 117; + optional int32 field2384 = 118; + optional int32 field2385 = 119; + optional int32 field2386 = 105; + optional bytes field2387 = 5; + optional group Message2357 = 6 { + optional int64 field2399 = 9; + optional int32 field2400 = 10; + optional int32 field2401 = 11; + optional int32 field2402 = 12; + optional int32 field2403 = 13; + optional int32 field2404 = 116; + optional int32 field2405 = 106; + required bytes field2406 = 14; + optional int32 field2407 = 45; + optional int32 field2408 = 112; + optional bool field2409 = 122; + optional bytes field2410 = 124; + } + optional string field2389 = 120; + optional group Message2358 = 107 {} + repeated group Message2359 = 40 {} + optional int32 field2392 = 50; + optional .benchmarks.google_message4.UnusedEmptyMessage field2393 = 60; + optional .benchmarks.google_message4.UnusedEmptyMessage field2394 = 70; + optional .benchmarks.google_message4.UnusedEmptyMessage field2395 = 80; + optional .benchmarks.google_message4.UnusedEmptyMessage field2396 = 90; + optional string field2397 = 100; + optional string field2398 = 123; +} + +message Message0 { + option message_set_wire_format = true; + + extensions 4 to 2147483646; +} + +message Message971 { + optional string field972 = 1; + optional int32 field973 = 2; + optional bool field974 = 3; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_1.proto b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_1.proto new file mode 100644 index 0000000..c5deecd --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_1.proto @@ -0,0 +1,500 @@ +// 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. + +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package benchmarks.google_message4; + +import "datasets/google_message4/benchmark_message4_2.proto"; +import "datasets/google_message4/benchmark_message4_3.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message2463 { + repeated .benchmarks.google_message4.Message2462 field2498 = 1; +} + +message Message12686 { + optional string field12699 = 1; + optional .benchmarks.google_message4.Message12685 field12700 = 2; +} + +message Message11949 {} + +message Message11975 { + optional string field11992 = 1; + optional int32 field11993 = 2; + repeated .benchmarks.google_message4.Message10320 field11994 = 3; + optional .benchmarks.google_message4.Message11947 field11995 = 4; + optional .benchmarks.google_message4.Message11920 field11996 = 5; + optional bool field11997 = 6; + repeated string field11998 = 7; + optional float field11999 = 8; + repeated .benchmarks.google_message4.UnusedEnum field12000 = 9; + optional int32 field12001 = 11; +} + +message Message7287 { + optional .benchmarks.google_message4.Message6133 field7311 = 1; + optional .benchmarks.google_message4.UnusedEmptyMessage field7312 = 8; + optional string field7313 = 3; + optional .benchmarks.google_message4.Message6643 field7314 = 4; + optional .benchmarks.google_message4.Enum7288 field7315 = 5; + optional bytes field7316 = 6; + optional .benchmarks.google_message4.UnusedEmptyMessage field7317 = 7; + optional .benchmarks.google_message4.UnusedEmptyMessage field7318 = 9; +} + +message Message3061 { + optional string field3286 = 2; + optional int32 field3287 = 77; + optional string field3288 = 49; + required .benchmarks.google_message4.Message3046 field3289 = 3; + optional .benchmarks.google_message4.Message3046 field3290 = 58; + optional group Message3062 = 4 { + required int32 field3335 = 5; + optional int32 field3336 = 6; + optional int32 field3337 = 7; + } + optional .benchmarks.google_message4.Message3060 field3292 = 104; + optional int64 field3293 = 32; + optional int32 field3294 = 41; + optional group Message3063 = 13 { + required int32 field3338 = 14; + optional .benchmarks.google_message4.Enum2851 field3339 = 18; + optional int64 field3340 = 15; + optional int64 field3341 = 23; + } + optional .benchmarks.google_message4.Enum2834 field3296 = 94; + optional bool field3297 = 25; + optional bool field3298 = 50; + optional string field3299 = 89; + optional string field3300 = 91; + optional string field3301 = 105; + optional .benchmarks.google_message4.Message3050 field3302 = 53; + optional fixed64 field3303 = 51; + optional fixed64 field3304 = 106; + optional int32 field3305 = 60; + optional string field3306 = 44; + optional bytes field3307 = 81; + optional string field3308 = 70; + optional bytes field3309 = 45; + optional .benchmarks.google_message4.Enum2806 field3310 = 71; + optional int32 field3311 = 72; + optional bytes field3312 = 78; + optional int32 field3313 = 20; + repeated group Message3064 = 8 { + required .benchmarks.google_message4.Enum2602 field3342 = 9; + optional int32 field3343 = 92; + optional string field3344 = 10; + optional bytes field3345 = 11; + optional int32 field3346 = 12; + optional .benchmarks.google_message4.Message3060 field3347 = 98; + optional .benchmarks.google_message4.UnusedEmptyMessage field3348 = 82; + optional .benchmarks.google_message4.Message3050 field3349 = 80; + optional fixed64 field3350 = 52; + optional int32 field3351 = 33; + optional string field3352 = 42; + optional string field3353 = 69; + optional bytes field3354 = 43; + optional .benchmarks.google_message4.Enum2806 field3355 = 73; + optional int32 field3356 = 74; + optional int32 field3357 = 90; + optional bytes field3358 = 79; + optional int32 field3359 = 19; + optional .benchmarks.google_message4.Enum2834 field3360 = 95; + } + optional .benchmarks.google_message4.UnusedEmptyMessage field3315 = 39; + optional int32 field3316 = 76; + optional group Message3065 = 63 {} + optional .benchmarks.google_message4.Enum2806 field3318 = 54; + optional int32 field3319 = 46; + repeated string field3320 = 24; + optional fixed32 field3321 = 38; + optional bytes field3322 = 99; + optional fixed64 field3323 = 1; + optional fixed64 field3324 = 97; + repeated .benchmarks.google_message4.Message3040 field3325 = 16; + repeated .benchmarks.google_message4.Message3041 field3326 = 61; + optional group Message3066 = 21 { + optional int32 field3366 = 22; + optional int32 field3367 = 55; + optional int32 field3368 = 88; + optional int32 field3369 = 56; + optional int32 field3370 = 75; + optional int32 field3371 = 57; + optional .benchmarks.google_message4.UnusedEmptyMessage field3372 = 85; + optional .benchmarks.google_message4.UnusedEmptyMessage field3373 = 96; + } + optional .benchmarks.google_message4.UnusedEmptyMessage field3328 = 47; + optional .benchmarks.google_message4.UnusedEmptyMessage field3329 = 48; + optional fixed64 field3330 = 40; + optional .benchmarks.google_message4.UnusedEmptyMessage field3331 = 86; + optional .benchmarks.google_message4.UnusedEmptyMessage field3332 = 59; + optional int32 field3333 = 17; +} + +message Message12949 {} + +message Message8572 { + optional bytes field8647 = 1; + optional bytes field8648 = 3; + optional .benchmarks.google_message4.Message3886 field8649 = 4; + optional .benchmarks.google_message4.Message3919 field8650 = 57; + optional bool field8651 = 5; + optional int32 field8652 = 6; + optional int32 field8653 = 49; + optional .benchmarks.google_message4.Message7905 field8654 = 7; + optional int32 field8655 = 10; + optional .benchmarks.google_message4.UnusedEmptyMessage field8656 = 11; + optional bool field8657 = 35; + optional bytes field8658 = 12; + optional string field8659 = 14; + optional .benchmarks.google_message4.UnusedEmptyMessage field8660 = 13; + optional bytes field8661 = 15; + optional .benchmarks.google_message4.UnusedEmptyMessage field8662 = 17; + optional int32 field8663 = 18; + optional int32 field8664 = 19; + optional bool field8665 = 20; + optional .benchmarks.google_message4.Enum3476 field8666 = 31; + optional bool field8667 = 36; + optional .benchmarks.google_message4.UnusedEmptyMessage field8668 = 39; + optional bytes field8669 = 22; + optional int32 field8670 = 24; + optional .benchmarks.google_message4.Message3052 field8671 = 25; + optional bytes field8672 = 26; + optional bytes field8673 = 28; + optional int32 field8674 = 29; + optional bytes field8675 = 30; + optional bytes field8676 = 32; + optional string field8677 = 33; + optional int32 field8678 = 34; + optional int32 field8679 = 37; + optional double field8680 = 38; + optional double field8681 = 42; + optional .benchmarks.google_message4.Message3922 field8682 = 40; + optional .benchmarks.google_message4.UnusedEmptyMessage field8683 = 43; + optional int64 field8684 = 44; + optional .benchmarks.google_message4.Message7929 field8685 = 45; + optional uint64 field8686 = 46; + optional uint32 field8687 = 48; + optional .benchmarks.google_message4.Message7843 field8688 = 47; + optional .benchmarks.google_message4.Message7864 field8689 = 50; + optional .benchmarks.google_message4.UnusedEmptyMessage field8690 = 52; + optional bool field8691 = 58; + optional bool field8692 = 54; + optional string field8693 = 55; + optional .benchmarks.google_message4.UnusedEmptyMessage field8694 = 41; + optional .benchmarks.google_message4.UnusedEmptyMessage field8695 = 53; + optional .benchmarks.google_message4.Message8575 field8696 = 61; +} + +message Message8774 { + optional string field8810 = 1; + optional string field8811 = 2; + optional string field8812 = 3; + optional string field8813 = 4; + optional string field8814 = 5; +} + +message Message12776 { + optional string field12786 = 1; + optional fixed64 field12787 = 11; + optional int32 field12788 = 6; + optional int32 field12789 = 13; + optional int32 field12790 = 14; + optional int32 field12791 = 15; + optional int32 field12792 = 16; + optional .benchmarks.google_message4.UnusedEmptyMessage field12793 = 8; + optional .benchmarks.google_message4.Message12774 field12794 = 10; + optional .benchmarks.google_message4.UnusedEmptyMessage field12795 = 12; + extensions 2 to 2; + extensions 3 to 3; + extensions 4 to 4; + extensions 5 to 5; + extensions 7 to 7; + extensions 9 to 9; +} + +message Message12798 { + optional int32 field12805 = 1; + optional int32 field12806 = 2; + optional .benchmarks.google_message4.Message12774 field12807 = 6; + optional bool field12808 = 7; +} + +message Message12797 { + optional .benchmarks.google_message4.Message12796 field12802 = 1; + repeated .benchmarks.google_message4.Message12796 field12803 = 2; + optional string field12804 = 3; +} + +message Message12825 { + repeated .benchmarks.google_message4.Message12818 field12862 = 1; + optional int32 field12863 = 2; + optional .benchmarks.google_message4.Message12819 field12864 = 3; + optional .benchmarks.google_message4.Message12820 field12865 = 4; + optional int32 field12866 = 5; + repeated .benchmarks.google_message4.Message12821 field12867 = 6; + repeated .benchmarks.google_message4.UnusedEmptyMessage field12868 = 7; +} + +message Message8590 {} + +message Message8587 {} + +message Message1374 { + required string field1375 = 1; + optional string field1376 = 2; +} + +message Message2462 { + required bytes field2496 = 1; + required double field2497 = 2; +} + +message Message12685 { + repeated string field12692 = 1; + repeated string field12693 = 2; + optional int64 field12694 = 3; + optional uint32 field12695 = 4; + repeated string field12696 = 5; + optional string field12697 = 6; + optional string field12698 = 7; +} + +message Message10320 { + optional .benchmarks.google_message4.Enum10335 field10347 = 1; + repeated .benchmarks.google_message4.Message10319 field10348 = 2; + optional int32 field10349 = 3; + optional int32 field10350 = 4; + optional int32 field10351 = 5; + optional int32 field10352 = 6; + optional .benchmarks.google_message4.Enum10337 field10353 = 7; +} + +message Message11947 { + optional uint32 field11951 = 1; + optional bool field11952 = 2; + optional int32 field11953 = 3; +} + +message Message11920 { + optional .benchmarks.google_message4.Enum11901 field11945 = 1; + optional .benchmarks.google_message4.UnusedEnum field11946 = 2; +} + +message Message6643 { + optional .benchmarks.google_message4.UnusedEmptyMessage field6683 = 3; + optional .benchmarks.google_message4.UnusedEmptyMessage field6684 = 4; + optional double field6685 = 5; + optional double field6686 = 6; + optional int32 field6687 = 1; + optional int32 field6688 = 2; + optional double field6689 = 9; + optional bytes field6690 = 10; + optional int32 field6691 = 11; + optional bool field6692 = 12; + optional bool field6693 = 13; + optional .benchmarks.google_message4.Message6578 field6694 = 15; + optional .benchmarks.google_message4.UnusedEnum field6695 = 16; + optional int64 field6696 = 17; + repeated .benchmarks.google_message4.UnusedEmptyMessage field6697 = 22; + optional .benchmarks.google_message4.UnusedEmptyMessage field6698 = 19; + optional .benchmarks.google_message4.UnusedEmptyMessage field6699 = 20; + optional int32 field6700 = 21; +} + +message Message6133 { + optional .benchmarks.google_message4.Message4016 field6173 = 12; + optional double field6174 = 16; + required string field6175 = 1; + required string field6176 = 2; + required string field6177 = 3; + optional string field6178 = 4; + optional string field6179 = 8; + repeated .benchmarks.google_message4.Message6109 field6180 = 5; + repeated .benchmarks.google_message4.Message5908 field6181 = 13; + repeated .benchmarks.google_message4.Message6107 field6182 = 7; + repeated .benchmarks.google_message4.Message6126 field6183 = 9; + repeated .benchmarks.google_message4.Message6129 field6184 = 15; + optional int32 field6185 = 10; + optional int32 field6186 = 11; + optional .benchmarks.google_message4.Message4016 field6187 = 17; + optional double field6188 = 14; + optional double field6189 = 18; + optional string field6190 = 19; + optional string field6191 = 20; + repeated .benchmarks.google_message4.Message5881 field6192 = 21; +} + +message Message6109 { + optional string field6140 = 1; + required .benchmarks.google_message4.Enum6111 field6141 = 2; + optional int32 field6142 = 9; + optional string field6143 = 3; + repeated .benchmarks.google_message4.Message6110 field6144 = 4; + repeated int32 field6145 = 7; + repeated int32 field6146 = 8; + optional .benchmarks.google_message4.Message6133 field6147 = 10; + repeated int32 field6148 = 11; + optional string field6149 = 12; + optional string field6150 = 13; + optional bool field6151 = 14; + extensions 1000 to 536870911; +} + +message Message3046 { + required .benchmarks.google_message4.Enum2593 field3222 = 1; + optional int32 field3223 = 4; +} + +message Message3060 { + optional int64 field3283 = 1; + optional int64 field3284 = 2; + optional int64 field3285 = 3; +} + +message Message3041 { + optional string field3214 = 1; + optional int32 field3215 = 2; +} + +message Message3040 { + required fixed64 field3209 = 1; + repeated fixed64 field3210 = 4; + optional int32 field3211 = 5; + optional fixed64 field3212 = 2; + required string field3213 = 3; +} + +message Message3050 { + optional bytes field3245 = 5; + optional int32 field3246 = 2; + optional bytes field3247 = 6; + optional int32 field3248 = 4; + optional fixed32 field3249 = 1; + optional fixed32 field3250 = 3; +} + +message Message7905 { + optional int32 field7911 = 1; + optional bool field7912 = 2; + optional bytes field7913 = 3; + optional int32 field7914 = 4; + optional int32 field7915 = 5; + optional bytes field7916 = 6; + optional int32 field7917 = 7; +} + +message Message3886 { + repeated group Message3887 = 1 { + required string field3932 = 2; + optional string field3933 = 9; + optional .benchmarks.google_message4.Message3850 field3934 = 3; + optional bytes field3935 = 8; + } +} + +message Message7864 { + optional string field7866 = 1; + optional string field7867 = 2; + repeated .benchmarks.google_message4.Message7865 field7868 = 5; + repeated .benchmarks.google_message4.Message7865 field7869 = 6; + repeated .benchmarks.google_message4.Message7865 field7870 = 7; + repeated .benchmarks.google_message4.UnusedEmptyMessage field7871 = 8; +} + +message Message3922 { + optional uint64 field4012 = 1; +} + +message Message3052 { + repeated string field3254 = 1; + repeated string field3255 = 2; + repeated bytes field3256 = 3; + repeated string field3257 = 4; + optional bool field3258 = 5; + optional int32 field3259 = 6; + optional int32 field3260 = 7; + optional string field3261 = 8; + optional string field3262 = 9; +} + +message Message8575 {} + +message Message7843 { + optional bool field7844 = 5; + optional int32 field7845 = 1; + optional .benchmarks.google_message4.UnusedEmptyMessage field7846 = 22; + repeated int32 field7847 = 3; + repeated string field7848 = 11; + optional .benchmarks.google_message4.UnusedEnum field7849 = 15; + optional .benchmarks.google_message4.UnusedEmptyMessage field7850 = 6; + optional .benchmarks.google_message4.UnusedEmptyMessage field7851 = 14; + optional .benchmarks.google_message4.UnusedEmptyMessage field7852 = 10; + optional .benchmarks.google_message4.Message7511 field7853 = 13; + optional .benchmarks.google_message4.UnusedEmptyMessage field7854 = 16; + optional .benchmarks.google_message4.UnusedEmptyMessage field7855 = 17; + optional .benchmarks.google_message4.UnusedEmptyMessage field7856 = 19; + optional .benchmarks.google_message4.UnusedEmptyMessage field7857 = 18; + optional .benchmarks.google_message4.UnusedEnum field7858 = 20; + optional int32 field7859 = 2; +} + +message Message3919 { + repeated .benchmarks.google_message4.Message3920 field4009 = 1; +} + +message Message7929 { + optional int64 field7942 = 1; + optional int64 field7943 = 4; + optional int64 field7944 = 5; + optional int64 field7945 = 12; + optional int64 field7946 = 13; + optional int64 field7947 = 18; + optional int64 field7948 = 6; + optional int64 field7949 = 7; + repeated .benchmarks.google_message4.Message7919 field7950 = 8; + repeated .benchmarks.google_message4.UnusedEmptyMessage field7951 = 20; + repeated .benchmarks.google_message4.Message7920 field7952 = 14; + repeated .benchmarks.google_message4.Message7921 field7953 = 15; + repeated .benchmarks.google_message4.Message7928 field7954 = 17; + optional int64 field7955 = 19; + optional bool field7956 = 2; + optional int64 field7957 = 3; + optional int64 field7958 = 9; + repeated .benchmarks.google_message4.UnusedEmptyMessage field7959 = 10; + repeated bytes field7960 = 11; + optional int64 field7961 = 16; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_2.proto b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_2.proto new file mode 100644 index 0000000..0c4cdfd --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_2.proto @@ -0,0 +1,316 @@ +// 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. + +syntax = "proto2"; + +package benchmarks.google_message4; + +import "datasets/google_message4/benchmark_message4_3.proto"; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +message Message12774 { + optional uint32 field12777 = 1; + optional uint32 field12778 = 2; + optional uint32 field12779 = 3; + optional uint32 field12780 = 4; + optional uint32 field12781 = 5; + optional bool field12782 = 6; +} + +message Message12796 { + repeated fixed64 field12800 = 1; + optional uint64 field12801 = 2; +} + +message Message12821 { + optional int32 field12848 = 1; + optional int32 field12849 = 2; + optional int32 field12850 = 3; + optional int32 field12851 = 4; + optional int32 field12852 = 5; +} + +message Message12820 { + optional int32 field12840 = 1; + optional int32 field12841 = 2; + optional int32 field12842 = 3; + optional int32 field12843 = 8; + optional int32 field12844 = 4; + optional int32 field12845 = 5; + optional int32 field12846 = 6; + optional int32 field12847 = 7; +} + +message Message12819 { + optional double field12834 = 1; + optional double field12835 = 2; + optional double field12836 = 3; + optional double field12837 = 4; + optional double field12838 = 5; + optional double field12839 = 6; +} + +message Message12818 { + optional uint64 field12829 = 1; + optional int32 field12830 = 2; + optional int32 field12831 = 3; + optional int32 field12832 = 5; + repeated .benchmarks.google_message4.Message12817 field12833 = 4; +} + +message Message10319 { + optional .benchmarks.google_message4.Enum10325 field10340 = 1; + optional int32 field10341 = 4; + optional int32 field10342 = 5; + optional bytes field10343 = 3; + optional string field10344 = 2; + optional string field10345 = 6; + optional string field10346 = 7; +} + +message Message6578 { + optional .benchmarks.google_message4.Enum6579 field6632 = 1; + optional .benchmarks.google_message4.Enum6588 field6633 = 2; +} + +message Message6126 { + required string field6152 = 1; + repeated .benchmarks.google_message4.Message6127 field6153 = 9; + optional int32 field6154 = 14; + optional bytes field6155 = 10; + optional .benchmarks.google_message4.Message6024 field6156 = 12; + optional int32 field6157 = 4; + optional string field6158 = 5; + optional int32 field6159 = 6; + repeated int32 field6160 = 2; + repeated int32 field6161 = 3; + repeated .benchmarks.google_message4.Message6052 field6162 = 7; + repeated .benchmarks.google_message4.UnusedEmptyMessage field6163 = 11; + optional .benchmarks.google_message4.Enum6065 field6164 = 15; + repeated .benchmarks.google_message4.Message6127 field6165 = 8; + optional bool field6166 = 13; + optional bool field6167 = 16; + optional bool field6168 = 18; + repeated .benchmarks.google_message4.Message6054 field6169 = 17; + optional int32 field6170 = 19; +} + +message Message5881 { + required double field5897 = 1; + optional string field5898 = 5; + optional .benchmarks.google_message4.Message5861 field5899 = 2; + optional .benchmarks.google_message4.UnusedEmptyMessage field5900 = 3; + optional .benchmarks.google_message4.Message5867 field5901 = 4; + optional .benchmarks.google_message4.Message5880 field5902 = 6; +} + +message Message6110 {} + +message Message6107 { + optional .benchmarks.google_message4.Message4016 field6134 = 1; + optional int32 field6135 = 2; + optional string field6136 = 3; + repeated int32 field6137 = 4; + optional int32 field6138 = 5; + repeated .benchmarks.google_message4.Message6108 field6139 = 6; +} + +message Message6129 { + required .benchmarks.google_message4.Enum6130 field6171 = 1; + required string field6172 = 2; +} + +message Message5908 { + optional string field5971 = 1; + optional int32 field5972 = 2; + optional int32 field5973 = 3; + optional .benchmarks.google_message4.Enum5909 field5974 = 45; + optional .benchmarks.google_message4.Enum5912 field5975 = 4; + optional fixed32 field5976 = 50; + optional fixed32 field5977 = 5; + optional fixed32 field5978 = 6; + optional string field5979 = 7; + optional .benchmarks.google_message4.Enum5915 field5980 = 8; + optional .benchmarks.google_message4.Message5903 field5981 = 9; + optional .benchmarks.google_message4.Message5903 field5982 = 10; + optional .benchmarks.google_message4.Enum5920 field5983 = 11; + optional .benchmarks.google_message4.Enum5923 field5984 = 40; + optional .benchmarks.google_message4.Message5903 field5985 = 41; + optional .benchmarks.google_message4.Message5903 field5986 = 42; + optional .benchmarks.google_message4.Enum5928 field5987 = 47; + optional bool field5988 = 48; + repeated fixed32 field5989 = 49; + optional string field5990 = 12; + optional .benchmarks.google_message4.Message5903 field5991 = 13; + optional .benchmarks.google_message4.Message5903 field5992 = 14; + optional .benchmarks.google_message4.Message5903 field5993 = 15; + optional .benchmarks.google_message4.Message5903 field5994 = 16; + optional .benchmarks.google_message4.Message5903 field5995 = 32; + optional .benchmarks.google_message4.Message5903 field5996 = 33; + optional .benchmarks.google_message4.Message5903 field5997 = 34; + optional .benchmarks.google_message4.Message5903 field5998 = 35; + optional .benchmarks.google_message4.Enum5931 field5999 = 17; + optional .benchmarks.google_message4.Enum5935 field6000 = 18; + optional .benchmarks.google_message4.Enum5939 field6001 = 36; + optional .benchmarks.google_message4.Enum5939 field6002 = 37; + repeated int32 field6003 = 19; + optional uint32 field6004 = 20; + optional uint32 field6005 = 21; + optional uint32 field6006 = 22; + optional uint32 field6007 = 23; + optional .benchmarks.google_message4.Enum5946 field6008 = 24; + optional .benchmarks.google_message4.Enum5946 field6009 = 25; + optional .benchmarks.google_message4.Enum5946 field6010 = 26; + optional .benchmarks.google_message4.Enum5946 field6011 = 27; + optional fixed32 field6012 = 28; + optional fixed32 field6013 = 29; + optional fixed32 field6014 = 30; + optional fixed32 field6015 = 31; + optional int32 field6016 = 38; + optional float field6017 = 39; + optional .benchmarks.google_message4.Enum5957 field6018 = 43; + optional .benchmarks.google_message4.Message5907 field6019 = 44; + optional .benchmarks.google_message4.Enum5962 field6020 = 46; +} + +message Message3850 { + optional .benchmarks.google_message4.Enum3851 field3924 = 2; + optional bool field3925 = 12; + optional int32 field3926 = 4; + optional bool field3927 = 10; + optional bool field3928 = 13; + optional bool field3929 = 14; +} + +message Message7865 {} + +message Message7511 { + optional bool field7523 = 1; + optional .benchmarks.google_message4.Enum7512 field7524 = 2; + optional int32 field7525 = 3; + optional int32 field7526 = 4; + optional bool field7527 = 5; + optional int32 field7528 = 6; + optional int32 field7529 = 7; +} + +message Message3920 {} + +message Message7928 { + optional string field7940 = 1; + optional int64 field7941 = 2; +} + +message Message7921 { + optional int32 field7936 = 1; + optional int64 field7937 = 2; + optional float field7938 = 3; + optional .benchmarks.google_message4.Enum7922 field7939 = 4; +} + +message Message7920 { + optional int64 field7934 = 1; + optional int64 field7935 = 2; +} + +message Message7919 { + optional fixed64 field7931 = 1; + optional int64 field7932 = 2; + optional bytes field7933 = 3; +} + +message Message12817 { + optional int32 field12826 = 1; + optional int32 field12827 = 2; + optional int32 field12828 = 3; +} + +message Message6054 { + required string field6089 = 1; + optional string field6090 = 2; +} + +message Message6127 {} + +message Message6052 { + required string field6084 = 1; + required bytes field6085 = 2; +} + +message Message6024 { + optional .benchmarks.google_message4.Enum6025 field6048 = 1; + optional string field6049 = 2; + optional .benchmarks.google_message4.UnusedEmptyMessage field6050 = 3; +} + +message Message5861 { + required .benchmarks.google_message4.Enum5862 field5882 = 1; + required string field5883 = 2; + optional bool field5884 = 3; + optional string field5885 = 4; +} + +message Message5880 { + optional string field5896 = 1; +} + +message Message5867 { + optional .benchmarks.google_message4.Enum5868 field5890 = 1; + optional string field5891 = 2; + optional .benchmarks.google_message4.Enum5873 field5892 = 3; + optional int32 field5893 = 4; + optional .benchmarks.google_message4.UnusedEnum field5894 = 5; + optional bool field5895 = 6; +} + +message Message4016 { + required int32 field4017 = 1; + required int32 field4018 = 2; + required int32 field4019 = 3; + required int32 field4020 = 4; +} + +message Message6108 {} + +message Message5907 { + optional .benchmarks.google_message4.Message5903 field5967 = 1; + optional .benchmarks.google_message4.Message5903 field5968 = 2; + optional .benchmarks.google_message4.Message5903 field5969 = 3; + optional .benchmarks.google_message4.Message5903 field5970 = 4; +} + +message UnusedEmptyMessage {} + +message Message5903 { + required int32 field5965 = 1; + optional .benchmarks.google_message4.Enum5904 field5966 = 2; +} diff --git a/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_3.proto b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_3.proto new file mode 100644 index 0000000..42e254b --- /dev/null +++ b/libs/protobuf/benchmarks/datasets/google_message4/benchmark_message4_3.proto @@ -0,0 +1,779 @@ +// 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. + +syntax = "proto2"; + +package benchmarks.google_message4; + +option cc_enable_arenas = true; +option java_package = "com.google.protobuf.benchmarks"; + +enum UnusedEnum { + UNUSED_ENUM_VALUE1 = 0; + UNUSED_ENUM_VALUE2 = 1; +} + +enum Enum2593 { + ENUM_VALUE2594 = 0; + ENUM_VALUE2595 = 1; + ENUM_VALUE2596 = 2; + ENUM_VALUE2597 = 3; + ENUM_VALUE2598 = 4; + ENUM_VALUE2599 = 5; + ENUM_VALUE2600 = 6; + ENUM_VALUE2601 = 7; +} + +enum Enum2834 { + ENUM_VALUE2835 = 0; + ENUM_VALUE2836 = 1; + ENUM_VALUE2837 = 2; +} + +enum Enum2806 { + ENUM_VALUE2807 = 0; + ENUM_VALUE2808 = 1; + ENUM_VALUE2809 = 2; + ENUM_VALUE2810 = 3; + ENUM_VALUE2811 = 4; + ENUM_VALUE2812 = 5; + ENUM_VALUE2813 = 6; + ENUM_VALUE2814 = 7; + ENUM_VALUE2815 = 8; + ENUM_VALUE2816 = 9; + ENUM_VALUE2817 = 10; + ENUM_VALUE2818 = 11; + ENUM_VALUE2819 = 12; + ENUM_VALUE2820 = 13; + ENUM_VALUE2821 = 14; +} + +enum Enum2851 { + option allow_alias = true; + + ENUM_VALUE2852 = 0; + ENUM_VALUE2853 = 0; + ENUM_VALUE2854 = 1; + ENUM_VALUE2855 = 2; + ENUM_VALUE2856 = 3; + ENUM_VALUE2857 = 4; + ENUM_VALUE2858 = 5; + ENUM_VALUE2859 = 6; + ENUM_VALUE2860 = 7; + ENUM_VALUE2861 = 8; + ENUM_VALUE2862 = 9; + ENUM_VALUE2863 = 10; + ENUM_VALUE2864 = 11; + ENUM_VALUE2865 = 12; + ENUM_VALUE2866 = 13; + ENUM_VALUE2867 = 14; + ENUM_VALUE2868 = 15; + ENUM_VALUE2869 = 16; + ENUM_VALUE2870 = 17; + ENUM_VALUE2871 = 18; + ENUM_VALUE2872 = 19; + ENUM_VALUE2873 = 20; + ENUM_VALUE2874 = 21; + ENUM_VALUE2875 = 22; + ENUM_VALUE2876 = 23; + ENUM_VALUE2877 = 24; + ENUM_VALUE2878 = 25; + ENUM_VALUE2879 = 26; + ENUM_VALUE2880 = 27; + ENUM_VALUE2881 = 28; + ENUM_VALUE2882 = 29; + ENUM_VALUE2883 = 30; + ENUM_VALUE2884 = 31; + ENUM_VALUE2885 = 32; + ENUM_VALUE2886 = 33; + ENUM_VALUE2887 = 34; + ENUM_VALUE2888 = 35; + ENUM_VALUE2889 = 36; + ENUM_VALUE2890 = 37; + ENUM_VALUE2891 = 38; + ENUM_VALUE2892 = 39; + ENUM_VALUE2893 = 40; + ENUM_VALUE2894 = 41; + ENUM_VALUE2895 = 42; + ENUM_VALUE2896 = 43; + ENUM_VALUE2897 = 44; + ENUM_VALUE2898 = 45; + ENUM_VALUE2899 = 46; + ENUM_VALUE2900 = 47; + ENUM_VALUE2901 = 48; + ENUM_VALUE2902 = 49; + ENUM_VALUE2903 = 50; + ENUM_VALUE2904 = 51; + ENUM_VALUE2905 = 52; + ENUM_VALUE2906 = 53; + ENUM_VALUE2907 = 54; + ENUM_VALUE2908 = 55; + ENUM_VALUE2909 = 56; + ENUM_VALUE2910 = 57; + ENUM_VALUE2911 = 58; + ENUM_VALUE2912 = 59; + ENUM_VALUE2913 = 60; + ENUM_VALUE2914 = 61; + ENUM_VALUE2915 = 62; + ENUM_VALUE2916 = 63; + ENUM_VALUE2917 = 64; + ENUM_VALUE2918 = 65; + ENUM_VALUE2919 = 66; + ENUM_VALUE2920 = 67; + ENUM_VALUE2921 = 68; + ENUM_VALUE2922 = 69; + ENUM_VALUE2923 = 70; + ENUM_VALUE2924 = 71; + ENUM_VALUE2925 = 72; + ENUM_VALUE2926 = 73; + ENUM_VALUE2927 = 74; + ENUM_VALUE2928 = 75; + ENUM_VALUE2929 = 76; + ENUM_VALUE2930 = 77; + ENUM_VALUE2931 = 78; + ENUM_VALUE2932 = 79; + ENUM_VALUE2933 = 80; + ENUM_VALUE2934 = 81; + ENUM_VALUE2935 = 82; + ENUM_VALUE2936 = 83; + ENUM_VALUE2937 = 84; + ENUM_VALUE2938 = 85; + ENUM_VALUE2939 = 86; + ENUM_VALUE2940 = 87; + ENUM_VALUE2941 = 88; + ENUM_VALUE2942 = 89; + ENUM_VALUE2943 = 90; + ENUM_VALUE2944 = 91; + ENUM_VALUE2945 = 92; + ENUM_VALUE2946 = 93; + ENUM_VALUE2947 = 94; + ENUM_VALUE2948 = 95; + ENUM_VALUE2949 = 96; + ENUM_VALUE2950 = 97; + ENUM_VALUE2951 = 98; + ENUM_VALUE2952 = 99; + ENUM_VALUE2953 = 100; + ENUM_VALUE2954 = 101; + ENUM_VALUE2955 = 102; + ENUM_VALUE2956 = 103; + ENUM_VALUE2957 = 104; + ENUM_VALUE2958 = 105; + ENUM_VALUE2959 = 106; + ENUM_VALUE2960 = 107; + ENUM_VALUE2961 = 108; + ENUM_VALUE2962 = 109; + ENUM_VALUE2963 = 110; + ENUM_VALUE2964 = 111; + ENUM_VALUE2965 = 112; + ENUM_VALUE2966 = 113; + ENUM_VALUE2967 = 114; + ENUM_VALUE2968 = 115; + ENUM_VALUE2969 = 116; + ENUM_VALUE2970 = 117; + ENUM_VALUE2971 = 118; + ENUM_VALUE2972 = 119; +} + +enum Enum2602 { + ENUM_VALUE2603 = 0; + ENUM_VALUE2604 = 1; + ENUM_VALUE2605 = 2; + ENUM_VALUE2606 = 3; + ENUM_VALUE2607 = 4; + ENUM_VALUE2608 = 5; + ENUM_VALUE2609 = 6; + ENUM_VALUE2610 = 7; + ENUM_VALUE2611 = 8; + ENUM_VALUE2612 = 9; + ENUM_VALUE2613 = 10; + ENUM_VALUE2614 = 11; +} + +enum Enum3071 { + ENUM_VALUE3072 = 1; + ENUM_VALUE3073 = 2; + ENUM_VALUE3074 = 3; + ENUM_VALUE3075 = 4; + ENUM_VALUE3076 = 5; + ENUM_VALUE3077 = 6; + ENUM_VALUE3078 = 7; + ENUM_VALUE3079 = 8; + ENUM_VALUE3080 = 9; + ENUM_VALUE3081 = 10; + ENUM_VALUE3082 = 11; + ENUM_VALUE3083 = 12; + ENUM_VALUE3084 = 13; + ENUM_VALUE3085 = 14; + ENUM_VALUE3086 = 15; + ENUM_VALUE3087 = 16; + ENUM_VALUE3088 = 17; + ENUM_VALUE3089 = 18; + ENUM_VALUE3090 = 19; + ENUM_VALUE3091 = 20; + ENUM_VALUE3092 = 21; + ENUM_VALUE3093 = 22; + ENUM_VALUE3094 = 23; + ENUM_VALUE3095 = 24; + ENUM_VALUE3096 = 25; + ENUM_VALUE3097 = 26; + ENUM_VALUE3098 = 27; + ENUM_VALUE3099 = 28; +} + +enum Enum3805 { + ENUM_VALUE3806 = 0; + ENUM_VALUE3807 = 1; + ENUM_VALUE3808 = 2; + ENUM_VALUE3809 = 3; + ENUM_VALUE3810 = 4; + ENUM_VALUE3811 = 5; + ENUM_VALUE3812 = 6; + ENUM_VALUE3813 = 7; + ENUM_VALUE3814 = 8; + ENUM_VALUE3815 = 9; + ENUM_VALUE3816 = 11; + ENUM_VALUE3817 = 10; +} + +enum Enum3783 { + ENUM_VALUE3784 = 0; + ENUM_VALUE3785 = 1; + ENUM_VALUE3786 = 2; + ENUM_VALUE3787 = 3; + ENUM_VALUE3788 = 4; + ENUM_VALUE3789 = 5; + ENUM_VALUE3790 = 6; + ENUM_VALUE3791 = 7; + ENUM_VALUE3792 = 8; + ENUM_VALUE3793 = 9; + ENUM_VALUE3794 = 10; + ENUM_VALUE3795 = 11; + ENUM_VALUE3796 = 12; + ENUM_VALUE3797 = 13; + ENUM_VALUE3798 = 14; + ENUM_VALUE3799 = 15; + ENUM_VALUE3800 = 16; + ENUM_VALUE3801 = 20; + ENUM_VALUE3802 = 21; + ENUM_VALUE3803 = 50; +} + +enum Enum3851 { + ENUM_VALUE3852 = 0; + ENUM_VALUE3853 = 1; + ENUM_VALUE3854 = 2; + ENUM_VALUE3855 = 3; + ENUM_VALUE3856 = 4; + ENUM_VALUE3857 = 5; + ENUM_VALUE3858 = 6; + ENUM_VALUE3859 = 7; + ENUM_VALUE3860 = 8; + ENUM_VALUE3861 = 9; + ENUM_VALUE3862 = 10; + ENUM_VALUE3863 = 11; + ENUM_VALUE3864 = 12; + ENUM_VALUE3865 = 13; + ENUM_VALUE3866 = 14; + ENUM_VALUE3867 = 15; + ENUM_VALUE3868 = 16; + ENUM_VALUE3869 = 17; +} + +enum Enum5862 { + ENUM_VALUE5863 = 1; + ENUM_VALUE5864 = 2; + ENUM_VALUE5865 = 3; +} + +enum Enum5868 { + ENUM_VALUE5869 = 0; + ENUM_VALUE5870 = 1; + ENUM_VALUE5871 = 2; + ENUM_VALUE5872 = 3; +} + +enum Enum5873 { + ENUM_VALUE5874 = 0; + ENUM_VALUE5875 = 1; + ENUM_VALUE5876 = 2; +} + +enum Enum5904 { + ENUM_VALUE5905 = 0; + ENUM_VALUE5906 = 1; +} + +enum Enum5909 { + ENUM_VALUE5910 = 0; + ENUM_VALUE5911 = 1; +} + +enum Enum5912 { + ENUM_VALUE5913 = 0; + ENUM_VALUE5914 = 1; +} + +enum Enum5915 { + ENUM_VALUE5916 = 0; + ENUM_VALUE5917 = 1; + ENUM_VALUE5918 = 2; + ENUM_VALUE5919 = 3; +} + +enum Enum5920 { + ENUM_VALUE5921 = 0; + ENUM_VALUE5922 = 1; +} + +enum Enum5923 { + ENUM_VALUE5924 = 0; + ENUM_VALUE5925 = 1; + ENUM_VALUE5926 = 2; + ENUM_VALUE5927 = 3; +} + +enum Enum5928 { + ENUM_VALUE5929 = 0; + ENUM_VALUE5930 = 1; +} + +enum Enum5931 { + ENUM_VALUE5932 = 0; + ENUM_VALUE5933 = 1; + ENUM_VALUE5934 = 2; +} + +enum Enum5935 { + ENUM_VALUE5936 = 0; + ENUM_VALUE5937 = 1; + ENUM_VALUE5938 = 2; +} + +enum Enum5939 { + ENUM_VALUE5940 = 0; + ENUM_VALUE5941 = 1; + ENUM_VALUE5942 = 2; + ENUM_VALUE5943 = 3; + ENUM_VALUE5944 = 4; + ENUM_VALUE5945 = 5; +} + +enum Enum5946 { + ENUM_VALUE5947 = 0; + ENUM_VALUE5948 = 1; + ENUM_VALUE5949 = 2; + ENUM_VALUE5950 = 3; + ENUM_VALUE5951 = 4; + ENUM_VALUE5952 = 5; + ENUM_VALUE5953 = 6; + ENUM_VALUE5954 = 7; + ENUM_VALUE5955 = 8; + ENUM_VALUE5956 = 9; +} + +enum Enum5957 { + ENUM_VALUE5958 = 0; + ENUM_VALUE5959 = 1; + ENUM_VALUE5960 = 2; + ENUM_VALUE5961 = 3; +} + +enum Enum5962 { + ENUM_VALUE5963 = 0; + ENUM_VALUE5964 = 1; +} + +enum Enum6025 { + ENUM_VALUE6026 = 0; + ENUM_VALUE6027 = 1; + ENUM_VALUE6028 = 2; + ENUM_VALUE6029 = 3; + ENUM_VALUE6030 = 4; + ENUM_VALUE6031 = 5; + ENUM_VALUE6032 = 6; + ENUM_VALUE6033 = 7; + ENUM_VALUE6034 = 8; + ENUM_VALUE6035 = 9; + ENUM_VALUE6036 = 10; + ENUM_VALUE6037 = 11; + ENUM_VALUE6038 = 12; + ENUM_VALUE6039 = 13; + ENUM_VALUE6040 = 14; + ENUM_VALUE6041 = 15; + ENUM_VALUE6042 = 16; + ENUM_VALUE6043 = 17; + ENUM_VALUE6044 = 18; + ENUM_VALUE6045 = 19; + ENUM_VALUE6046 = 20; + ENUM_VALUE6047 = 21; +} + +enum Enum6111 { + ENUM_VALUE6112 = 1; + ENUM_VALUE6113 = 2; + ENUM_VALUE6114 = 3; + ENUM_VALUE6115 = 4; + ENUM_VALUE6116 = 5; + ENUM_VALUE6117 = 6; + ENUM_VALUE6118 = 7; + ENUM_VALUE6119 = 8; + ENUM_VALUE6120 = 9; + ENUM_VALUE6121 = 10; + ENUM_VALUE6122 = 11; + ENUM_VALUE6123 = 12; + ENUM_VALUE6124 = 13; + ENUM_VALUE6125 = 14; +} + +enum Enum6065 { + ENUM_VALUE6066 = 0; + ENUM_VALUE6067 = 1; + ENUM_VALUE6068 = 2; + ENUM_VALUE6069 = 3; + ENUM_VALUE6070 = 4; + ENUM_VALUE6071 = 5; + ENUM_VALUE6072 = 6; + ENUM_VALUE6073 = 7; + ENUM_VALUE6074 = 8; + ENUM_VALUE6075 = 9; + ENUM_VALUE6076 = 10; + ENUM_VALUE6077 = 11; + ENUM_VALUE6078 = 12; + ENUM_VALUE6079 = 13; + ENUM_VALUE6080 = 14; +} + +enum Enum6130 { + ENUM_VALUE6131 = 0; + ENUM_VALUE6132 = 1; +} + +enum Enum6579 { + ENUM_VALUE6580 = 0; + ENUM_VALUE6581 = 2; + ENUM_VALUE6582 = 3; + ENUM_VALUE6583 = 5; + ENUM_VALUE6584 = 10; + ENUM_VALUE6585 = 15; + ENUM_VALUE6586 = 25; + ENUM_VALUE6587 = 30; +} + +enum Enum6588 { + ENUM_VALUE6589 = 0; + ENUM_VALUE6590 = 1; + ENUM_VALUE6591 = 2; + ENUM_VALUE6592 = 3; + ENUM_VALUE6593 = 4; + ENUM_VALUE6594 = 5; + ENUM_VALUE6595 = 6; + ENUM_VALUE6596 = 7; + ENUM_VALUE6597 = 8; + ENUM_VALUE6598 = 9; + ENUM_VALUE6599 = 10; + ENUM_VALUE6600 = 11; + ENUM_VALUE6601 = 12; + ENUM_VALUE6602 = 13; + ENUM_VALUE6603 = 14; + ENUM_VALUE6604 = 15; + ENUM_VALUE6605 = 16; + ENUM_VALUE6606 = 17; + ENUM_VALUE6607 = 19; + ENUM_VALUE6608 = 20; + ENUM_VALUE6609 = 21; + ENUM_VALUE6610 = 22; + ENUM_VALUE6611 = 23; + ENUM_VALUE6612 = 24; + ENUM_VALUE6613 = 25; + ENUM_VALUE6614 = 26; + ENUM_VALUE6615 = 27; + ENUM_VALUE6616 = 28; + ENUM_VALUE6617 = 29; + ENUM_VALUE6618 = 30; + ENUM_VALUE6619 = 31; + ENUM_VALUE6620 = 32; + ENUM_VALUE6621 = 33; + ENUM_VALUE6622 = 34; +} + +enum Enum7288 { + ENUM_VALUE7289 = 0; + ENUM_VALUE7290 = 1; + ENUM_VALUE7291 = 2; + ENUM_VALUE7292 = 3; +} + +enum Enum7512 { + ENUM_VALUE7513 = 0; + ENUM_VALUE7514 = 1; + ENUM_VALUE7515 = 2; + ENUM_VALUE7516 = 3; + ENUM_VALUE7517 = 4; + ENUM_VALUE7518 = 5; + ENUM_VALUE7519 = 6; + ENUM_VALUE7520 = 7; +} + +enum Enum7922 { + ENUM_VALUE7923 = 1; + ENUM_VALUE7924 = 2; + ENUM_VALUE7925 = 3; + ENUM_VALUE7926 = 4; + ENUM_VALUE7927 = 5; +} + +enum Enum3476 { + ENUM_VALUE3477 = 0; + ENUM_VALUE3478 = 1; + ENUM_VALUE3479 = 2; + ENUM_VALUE3480 = 3; + ENUM_VALUE3481 = 4; + ENUM_VALUE3482 = 5; + ENUM_VALUE3483 = 6; + ENUM_VALUE3484 = 7; + ENUM_VALUE3485 = 8; + ENUM_VALUE3486 = 9; + ENUM_VALUE3487 = 10; + ENUM_VALUE3488 = 11; + ENUM_VALUE3489 = 12; + ENUM_VALUE3490 = 13; + ENUM_VALUE3491 = 14; + ENUM_VALUE3492 = 15; + ENUM_VALUE3493 = 16; + ENUM_VALUE3494 = 17; + ENUM_VALUE3495 = 18; + ENUM_VALUE3496 = 19; + ENUM_VALUE3497 = 20; + ENUM_VALUE3498 = 21; + ENUM_VALUE3499 = 22; + ENUM_VALUE3500 = 23; + ENUM_VALUE3501 = 24; + ENUM_VALUE3502 = 25; + ENUM_VALUE3503 = 26; + ENUM_VALUE3504 = 27; + ENUM_VALUE3505 = 28; + ENUM_VALUE3506 = 29; + ENUM_VALUE3507 = 30; + ENUM_VALUE3508 = 31; + ENUM_VALUE3509 = 32; + ENUM_VALUE3510 = 33; + ENUM_VALUE3511 = 34; + ENUM_VALUE3512 = 35; + ENUM_VALUE3513 = 36; + ENUM_VALUE3514 = 37; + ENUM_VALUE3515 = 38; + ENUM_VALUE3516 = 39; + ENUM_VALUE3517 = 40; + ENUM_VALUE3518 = 41; + ENUM_VALUE3519 = 42; + ENUM_VALUE3520 = 43; + ENUM_VALUE3521 = 44; + ENUM_VALUE3522 = 45; + ENUM_VALUE3523 = 46; + ENUM_VALUE3524 = 47; + ENUM_VALUE3525 = 48; + ENUM_VALUE3526 = 49; + ENUM_VALUE3527 = 50; + ENUM_VALUE3528 = 51; + ENUM_VALUE3529 = 52; + ENUM_VALUE3530 = 53; + ENUM_VALUE3531 = 54; + ENUM_VALUE3532 = 55; + ENUM_VALUE3533 = 56; + ENUM_VALUE3534 = 57; + ENUM_VALUE3535 = 58; + ENUM_VALUE3536 = 59; + ENUM_VALUE3537 = 60; + ENUM_VALUE3538 = 61; + ENUM_VALUE3539 = 62; + ENUM_VALUE3540 = 63; + ENUM_VALUE3541 = 64; + ENUM_VALUE3542 = 65; + ENUM_VALUE3543 = 66; + ENUM_VALUE3544 = 67; + ENUM_VALUE3545 = 68; + ENUM_VALUE3546 = 69; + ENUM_VALUE3547 = 70; + ENUM_VALUE3548 = 71; + ENUM_VALUE3549 = 72; + ENUM_VALUE3550 = 73; + ENUM_VALUE3551 = 74; + ENUM_VALUE3552 = 75; + ENUM_VALUE3553 = 76; + ENUM_VALUE3554 = 77; + ENUM_VALUE3555 = 78; + ENUM_VALUE3556 = 79; + ENUM_VALUE3557 = 80; + ENUM_VALUE3558 = 81; + ENUM_VALUE3559 = 82; + ENUM_VALUE3560 = 83; + ENUM_VALUE3561 = 84; + ENUM_VALUE3562 = 85; + ENUM_VALUE3563 = 86; + ENUM_VALUE3564 = 87; + ENUM_VALUE3565 = 88; + ENUM_VALUE3566 = 89; + ENUM_VALUE3567 = 90; + ENUM_VALUE3568 = 91; + ENUM_VALUE3569 = 92; + ENUM_VALUE3570 = 93; + ENUM_VALUE3571 = 94; + ENUM_VALUE3572 = 95; + ENUM_VALUE3573 = 96; + ENUM_VALUE3574 = 97; + ENUM_VALUE3575 = 98; + ENUM_VALUE3576 = 99; + ENUM_VALUE3577 = 100; + ENUM_VALUE3578 = 101; + ENUM_VALUE3579 = 102; + ENUM_VALUE3580 = 103; + ENUM_VALUE3581 = 104; + ENUM_VALUE3582 = 105; + ENUM_VALUE3583 = 106; + ENUM_VALUE3584 = 107; + ENUM_VALUE3585 = 108; + ENUM_VALUE3586 = 109; + ENUM_VALUE3587 = 110; + ENUM_VALUE3588 = 111; + ENUM_VALUE3589 = 112; + ENUM_VALUE3590 = 113; + ENUM_VALUE3591 = 114; + ENUM_VALUE3592 = 115; + ENUM_VALUE3593 = 116; + ENUM_VALUE3594 = 117; + ENUM_VALUE3595 = 118; + ENUM_VALUE3596 = 119; + ENUM_VALUE3597 = 120; + ENUM_VALUE3598 = 121; + ENUM_VALUE3599 = 122; + ENUM_VALUE3600 = 123; + ENUM_VALUE3601 = 124; + ENUM_VALUE3602 = 125; + ENUM_VALUE3603 = 126; + ENUM_VALUE3604 = 127; + ENUM_VALUE3605 = 128; + ENUM_VALUE3606 = 129; + ENUM_VALUE3607 = 130; + ENUM_VALUE3608 = 131; + ENUM_VALUE3609 = 132; + ENUM_VALUE3610 = 133; + ENUM_VALUE3611 = 134; + ENUM_VALUE3612 = 135; + ENUM_VALUE3613 = 136; + ENUM_VALUE3614 = 137; + ENUM_VALUE3615 = 138; + ENUM_VALUE3616 = 139; + ENUM_VALUE3617 = 140; + ENUM_VALUE3618 = 141; + ENUM_VALUE3619 = 142; + ENUM_VALUE3620 = 143; + ENUM_VALUE3621 = 144; + ENUM_VALUE3622 = 145; + ENUM_VALUE3623 = 146; + ENUM_VALUE3624 = 147; + ENUM_VALUE3625 = 148; + ENUM_VALUE3626 = 149; + ENUM_VALUE3627 = 150; + ENUM_VALUE3628 = 151; + ENUM_VALUE3629 = 152; + ENUM_VALUE3630 = 153; + ENUM_VALUE3631 = 154; + ENUM_VALUE3632 = 155; + ENUM_VALUE3633 = 156; + ENUM_VALUE3634 = 157; + ENUM_VALUE3635 = 158; + ENUM_VALUE3636 = 159; + ENUM_VALUE3637 = 160; + ENUM_VALUE3638 = 161; + ENUM_VALUE3639 = 162; + ENUM_VALUE3640 = 163; + ENUM_VALUE3641 = 164; + ENUM_VALUE3642 = 165; + ENUM_VALUE3643 = 166; + ENUM_VALUE3644 = 167; + ENUM_VALUE3645 = 168; + ENUM_VALUE3646 = 169; + ENUM_VALUE3647 = 170; + ENUM_VALUE3648 = 171; + ENUM_VALUE3649 = 172; + ENUM_VALUE3650 = 173; + ENUM_VALUE3651 = 174; + ENUM_VALUE3652 = 175; + ENUM_VALUE3653 = 176; + ENUM_VALUE3654 = 177; + ENUM_VALUE3655 = 178; + ENUM_VALUE3656 = 179; + ENUM_VALUE3657 = 180; + ENUM_VALUE3658 = 181; + ENUM_VALUE3659 = 182; + ENUM_VALUE3660 = 183; +} + +enum Enum10325 { + ENUM_VALUE10326 = 0; + ENUM_VALUE10327 = 1; + ENUM_VALUE10328 = 2; + ENUM_VALUE10329 = 3; + ENUM_VALUE10330 = 4; + ENUM_VALUE10331 = 5; + ENUM_VALUE10332 = 6; + ENUM_VALUE10333 = 7; + ENUM_VALUE10334 = 8; +} + +enum Enum10335 { ENUM_VALUE10336 = 0; } + +enum Enum10337 { + ENUM_VALUE10338 = 0; + ENUM_VALUE10339 = 1; +} + +enum Enum11901 { + ENUM_VALUE11902 = 0; + ENUM_VALUE11903 = 1; + ENUM_VALUE11904 = 2; + ENUM_VALUE11905 = 3; +} + +enum Enum12735 { + ENUM_VALUE12736 = 0; + ENUM_VALUE12737 = 1; + ENUM_VALUE12738 = 2; + ENUM_VALUE12739 = 3; +} + +enum Enum12871 { + ENUM_VALUE12872 = 1; + ENUM_VALUE12873 = 2; + ENUM_VALUE12874 = 3; + ENUM_VALUE12875 = 4; + ENUM_VALUE12876 = 5; + ENUM_VALUE12877 = 6; +} diff --git a/libs/protobuf/benchmarks/go/go_benchmark_test.go b/libs/protobuf/benchmarks/go/go_benchmark_test.go new file mode 100644 index 0000000..8c741b7 --- /dev/null +++ b/libs/protobuf/benchmarks/go/go_benchmark_test.go @@ -0,0 +1,124 @@ +package main + +import ( + benchmarkWrapper "../tmp" + googleMessage1Proto2 "../tmp/datasets/google_message1/proto2" + googleMessage1Proto3 "../tmp/datasets/google_message1/proto3" + googleMessage2 "../tmp/datasets/google_message2" + googleMessage3 "../tmp/datasets/google_message3" + googleMessage4 "../tmp/datasets/google_message4" + "flag" + "github.com/golang/protobuf/proto" + "io/ioutil" + "testing" +) + +// Data is returned by the Load function. +type Dataset struct { + name string + newMessage func() proto.Message + marshaled [][]byte + unmarshaled []proto.Message +} + +var datasets []Dataset + +// This is used to getDefaultInstance for a message type. +func generateNewMessageFunction(dataset benchmarkWrapper.BenchmarkDataset) func() proto.Message { + switch dataset.MessageName { + case "benchmarks.proto3.GoogleMessage1": + return func() proto.Message { return new(googleMessage1Proto3.GoogleMessage1) } + case "benchmarks.proto2.GoogleMessage1": + return func() proto.Message { return new(googleMessage1Proto2.GoogleMessage1) } + case "benchmarks.proto2.GoogleMessage2": + return func() proto.Message { return new(googleMessage2.GoogleMessage2) } + case "benchmarks.google_message3.GoogleMessage3": + return func() proto.Message { return new(googleMessage3.GoogleMessage3) } + case "benchmarks.google_message4.GoogleMessage4": + return func() proto.Message { return new(googleMessage4.GoogleMessage4) } + default: + panic("Unknown message type: " + dataset.MessageName) + } +} + +func init() { + flag.Parse() + for _, f := range flag.Args() { + // Load the benchmark. + b, err := ioutil.ReadFile(f) + if err != nil { + panic(err) + } + + // Parse the benchmark. + var dm benchmarkWrapper.BenchmarkDataset + if err := proto.Unmarshal(b, &dm); err != nil { + panic(err) + } + + // Determine the concrete protobuf message type to use. + var ds Dataset + ds.newMessage = generateNewMessageFunction(dm) + + // Unmarshal each test message. + for _, payload := range dm.Payload { + ds.marshaled = append(ds.marshaled, payload) + m := ds.newMessage() + if err := proto.Unmarshal(payload, m); err != nil { + panic(err) + } + ds.unmarshaled = append(ds.unmarshaled, m) + } + ds.name = f + + datasets = append(datasets, ds) + } +} + +func Benchmark(b *testing.B) { + for _, ds := range datasets { + b.Run(ds.name, func(b *testing.B) { + b.Run("Unmarshal", func(b *testing.B) { + for i := 0; i < b.N; i++ { + for j, payload := range ds.marshaled { + out := ds.newMessage() + if err := proto.Unmarshal(payload, out); err != nil { + b.Fatalf("can't unmarshal message %d %v", j, err) + } + } + } + }) + b.Run("Marshal", func(b *testing.B) { + for i := 0; i < b.N; i++ { + for j, m := range ds.unmarshaled { + if _, err := proto.Marshal(m); err != nil { + b.Fatalf("can't marshal message %d %+v: %v", j, m, err) + } + } + } + }) + b.Run("Size", func(b *testing.B) { + for i := 0; i < b.N; i++ { + for _, m := range ds.unmarshaled { + proto.Size(m) + } + } + }) + b.Run("Clone", func(b *testing.B) { + for i := 0; i < b.N; i++ { + for _, m := range ds.unmarshaled { + proto.Clone(m) + } + } + }) + b.Run("Merge", func(b *testing.B) { + for i := 0; i < b.N; i++ { + for _, m := range ds.unmarshaled { + out := ds.newMessage() + proto.Merge(out, m) + } + } + }) + }) + } +} diff --git a/libs/protobuf/benchmarks/google_size.proto b/libs/protobuf/benchmarks/google_size.proto new file mode 100644 index 0000000..d2d319f --- /dev/null +++ b/libs/protobuf/benchmarks/google_size.proto @@ -0,0 +1,138 @@ +syntax = "proto2"; + +package benchmarks; + +option java_outer_classname = "GoogleSize"; +option optimize_for = CODE_SIZE; + +message SizeMessage1 { + required string field1 = 1; + optional string field9 = 9; + optional string field18 = 18; + optional bool field80 = 80 [default=false]; + optional bool field81 = 81 [default=true]; + required int32 field2 = 2; + required int32 field3 = 3; + optional int32 field280 = 280; + optional int32 field6 = 6 [default=0]; + optional int64 field22 = 22; + optional string field4 = 4; + repeated fixed64 field5 = 5; + optional bool field59 = 59 [default=false]; + optional string field7 = 7; + optional int32 field16 = 16; + optional int32 field130 = 130 [default=0]; + optional bool field12 = 12 [default=true]; + optional bool field17 = 17 [default=true]; + optional bool field13 = 13 [default=true]; + optional bool field14 = 14 [default=true]; + optional int32 field104 = 104 [default=0]; + optional int32 field100 = 100 [default=0]; + optional int32 field101 = 101 [default=0]; + optional string field102 = 102; + optional string field103 = 103; + optional int32 field29 = 29 [default=0]; + optional bool field30 = 30 [default=false]; + optional int32 field60 = 60 [default=-1]; + optional int32 field271 = 271 [default=-1]; + optional int32 field272 = 272 [default=-1]; + optional int32 field150 = 150; + optional int32 field23 = 23 [default=0]; + optional bool field24 = 24 [default=false]; + optional int32 field25 = 25 [default=0]; + optional SizeMessage1SubMessage field15 = 15; + optional bool field78 = 78; + optional int32 field67 = 67 [default=0]; + optional int32 field68 = 68; + optional int32 field128 = 128 [default=0]; + optional string field129 = 129 [default="xxxxxxxxxxxxxxxxxxxxx"]; + optional int32 field131 = 131 [default=0]; +} + +message SizeMessage1SubMessage { + optional int32 field1 = 1 [default=0]; + optional int32 field2 = 2 [default=0]; + optional int32 field3 = 3 [default=0]; + optional string field15 = 15; + optional bool field12 = 12 [default=true]; + optional int64 field13 = 13; + optional int64 field14 = 14; + optional int32 field16 = 16; + optional int32 field19 = 19 [default=2]; + optional bool field20 = 20 [default=true]; + optional bool field28 = 28 [default=true]; + optional fixed64 field21 = 21; + optional int32 field22 = 22; + optional bool field23 = 23 [ default=false ]; + optional bool field206 = 206 [default=false]; + optional fixed32 field203 = 203; + optional int32 field204 = 204; + optional string field205 = 205; + optional uint64 field207 = 207; + optional uint64 field300 = 300; +} + +message SizeMessage2 { + optional string field1 = 1; + optional int64 field3 = 3; + optional int64 field4 = 4; + optional int64 field30 = 30; + optional bool field75 = 75 [default=false]; + optional string field6 = 6; + optional bytes field2 = 2; + optional int32 field21 = 21 [default=0]; + optional int32 field71 = 71; + optional float field25 = 25; + optional int32 field109 = 109 [default=0]; + optional int32 field210 = 210 [default=0]; + optional int32 field211 = 211 [default=0]; + optional int32 field212 = 212 [default=0]; + optional int32 field213 = 213 [default=0]; + optional int32 field216 = 216 [default=0]; + optional int32 field217 = 217 [default=0]; + optional int32 field218 = 218 [default=0]; + optional int32 field220 = 220 [default=0]; + optional int32 field221 = 221 [default=0]; + optional float field222 = 222 [default=0.0]; + optional int32 field63 = 63; + + repeated group Group1 = 10 { + required float field11 = 11; + optional float field26 = 26; + optional string field12 = 12; + optional string field13 = 13; + repeated string field14 = 14; + required uint64 field15 = 15; + optional int32 field5 = 5; + optional string field27 = 27; + optional int32 field28 = 28; + optional string field29 = 29; + optional string field16 = 16; + repeated string field22 = 22; + repeated int32 field73 = 73; + optional int32 field20 = 20 [default=0]; + optional string field24 = 24; + optional SizeMessage2GroupedMessage field31 = 31; + } + repeated string field128 = 128; + optional int64 field131 = 131; + repeated string field127 = 127; + optional int32 field129 = 129; + repeated int64 field130 = 130; + optional bool field205 = 205 [default=false]; + optional bool field206 = 206 [default=false]; +} + +message SizeMessage2GroupedMessage { + optional float field1 = 1; + optional float field2 = 2; + optional float field3 = 3 [default=0.0]; + optional bool field4 = 4; + optional bool field5 = 5; + optional bool field6 = 6 [default=true]; + optional bool field7 = 7 [default=false]; + optional float field8 = 8; + optional bool field9 = 9; + optional float field10 = 10; + optional int64 field11 = 11; +} diff --git a/libs/protobuf/benchmarks/java/pom.xml b/libs/protobuf/benchmarks/java/pom.xml new file mode 100644 index 0000000..c0dc940 --- /dev/null +++ b/libs/protobuf/benchmarks/java/pom.xml @@ -0,0 +1,98 @@ + + + + 4.0.0 + protobuf-java-benchmark + com.google.protobuf + 1.0.0 + Protocol Buffers [Benchmark] + The benchmark tools for Protobuf Java. + + + + com.google.protobuf + protobuf-java + ${protobuf.version} + jar + system + ${project.basedir}/lib/protobuf-java.jar + + + com.google.caliper + caliper + 1.0-beta-3 + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4.1 + + + + jar-with-dependencies + + + + + com.mkyong.core.utils.App + + + + + + make-assembly + + package + + single + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.5 + + + + true + com.google.protocolbuffers.ProtoBench + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + + jar-no-fork + + + + + + + + + diff --git a/libs/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java b/libs/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java new file mode 100644 index 0000000..ef30749 --- /dev/null +++ b/libs/protobuf/benchmarks/java/src/main/java/com/google/protobuf/ProtoCaliperBenchmark.java @@ -0,0 +1,208 @@ +package com.google.protobuf; + +import com.google.caliper.BeforeExperiment; +import com.google.caliper.Benchmark; +import com.google.caliper.Param; +import com.google.protobuf.benchmarks.Benchmarks.BenchmarkDataset; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.List; + +/** + * Basic benchmarks for Java protobuf parsing. + */ +public class ProtoCaliperBenchmark { + public enum BenchmarkMessageType { + GOOGLE_MESSAGE1_PROTO3 { + @Override + ExtensionRegistry getExtensionRegistry() { + return ExtensionRegistry.newInstance(); + } + @Override + Message getDefaultInstance() { + return com.google.protobuf.benchmarks.BenchmarkMessage1Proto3.GoogleMessage1 + .getDefaultInstance(); + } + }, + GOOGLE_MESSAGE1_PROTO2 { + @Override ExtensionRegistry getExtensionRegistry() { + return ExtensionRegistry.newInstance(); + } + @Override + Message getDefaultInstance() { + return com.google.protobuf.benchmarks.BenchmarkMessage1Proto2.GoogleMessage1 + .getDefaultInstance(); + } + }, + GOOGLE_MESSAGE2 { + @Override + ExtensionRegistry getExtensionRegistry() { + return ExtensionRegistry.newInstance(); + } + @Override + Message getDefaultInstance() { + return com.google.protobuf.benchmarks.BenchmarkMessage2.GoogleMessage2.getDefaultInstance(); + } + }, + GOOGLE_MESSAGE3 { + @Override + ExtensionRegistry getExtensionRegistry() { + ExtensionRegistry extensions = ExtensionRegistry.newInstance(); + com.google.protobuf.benchmarks.BenchmarkMessage38.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage37.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage36.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage35.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage34.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage33.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage32.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage31.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage3.registerAllExtensions(extensions); + return extensions; + } + @Override + Message getDefaultInstance() { + return com.google.protobuf.benchmarks.BenchmarkMessage3.GoogleMessage3.getDefaultInstance(); + } + }, + GOOGLE_MESSAGE4 { + @Override + ExtensionRegistry getExtensionRegistry() { + ExtensionRegistry extensions = ExtensionRegistry.newInstance(); + com.google.protobuf.benchmarks.BenchmarkMessage43.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage42.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage41.registerAllExtensions(extensions); + com.google.protobuf.benchmarks.BenchmarkMessage4.registerAllExtensions(extensions); + return extensions; + } + @Override + Message getDefaultInstance() { + return com.google.protobuf.benchmarks.BenchmarkMessage4.GoogleMessage4.getDefaultInstance(); + } + }; + + abstract ExtensionRegistry getExtensionRegistry(); + abstract Message getDefaultInstance(); + } + + private BenchmarkMessageType benchmarkMessageType; + @Param("") + private String dataFile; + + private byte[] inputData; + private BenchmarkDataset benchmarkDataset; + private Message defaultMessage; + private ExtensionRegistry extensions; + private List inputDataList; + private List inputStreamList; + private List inputStringList; + private List sampleMessageList; + + private BenchmarkMessageType getMessageType() throws IOException { + if (benchmarkDataset.getMessageName().equals("benchmarks.proto3.GoogleMessage1")) { + return BenchmarkMessageType.GOOGLE_MESSAGE1_PROTO3; + } else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage1")) { + return BenchmarkMessageType.GOOGLE_MESSAGE1_PROTO2; + } else if (benchmarkDataset.getMessageName().equals("benchmarks.proto2.GoogleMessage2")) { + return BenchmarkMessageType.GOOGLE_MESSAGE2; + } else if (benchmarkDataset.getMessageName(). + equals("benchmarks.google_message3.GoogleMessage3")) { + return BenchmarkMessageType.GOOGLE_MESSAGE3; + } else if (benchmarkDataset.getMessageName(). + equals("benchmarks.google_message4.GoogleMessage4")) { + return BenchmarkMessageType.GOOGLE_MESSAGE4; + } else { + throw new IllegalStateException("Invalid DataFile! There's no testing message named " + + benchmarkDataset.getMessageName()); + } + } + + @BeforeExperiment + void setUp() throws IOException { + if (!dataFile.equals("")) { + RandomAccessFile file = new RandomAccessFile(new File(dataFile), "r"); + inputData = new byte[(int) file.length()]; + file.readFully(inputData); + benchmarkDataset = BenchmarkDataset.parseFrom(inputData); + benchmarkMessageType = getMessageType(); + } else { + inputData = new byte[0]; + benchmarkDataset = BenchmarkDataset.parseFrom(inputData); + benchmarkMessageType = BenchmarkMessageType.GOOGLE_MESSAGE2; + } + defaultMessage = benchmarkMessageType.getDefaultInstance(); + extensions = benchmarkMessageType.getExtensionRegistry(); + inputDataList = new ArrayList(); + inputStreamList = new ArrayList(); + inputStringList = new ArrayList(); + sampleMessageList = new ArrayList(); + + for (int i = 0; i < benchmarkDataset.getPayloadCount(); i++) { + byte[] singleInputData = benchmarkDataset.getPayload(i).toByteArray(); + inputDataList.add(benchmarkDataset.getPayload(i).toByteArray()); + inputStreamList.add(new ByteArrayInputStream( + benchmarkDataset.getPayload(i).toByteArray())); + inputStringList.add(benchmarkDataset.getPayload(i)); + sampleMessageList.add( + defaultMessage.newBuilderForType().mergeFrom(singleInputData, extensions).build()); + } + } + + @SuppressWarnings("IgnoredPureGetter") + @Benchmark + void serializeToByteArray(int reps) throws IOException { + if (sampleMessageList.size() == 0) { + return; + } + for (int i = 0; i < reps; i++) { + for (int j = 0; j < sampleMessageList.size(); j++) { + sampleMessageList.get(j).toByteArray(); + } + } + } + + @Benchmark + void serializeToMemoryStream(int reps) throws IOException { + if (sampleMessageList.size() == 0) { + return; + } + for (int i = 0; i < reps; i++) { + for (int j = 0; j < sampleMessageList.size(); j++) { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + sampleMessageList.get(j).writeTo(output); + } + } + } + + @Benchmark + void deserializeFromByteArray(int reps) throws IOException { + if (inputDataList.size() == 0) { + return; + } + for (int i = 0; i < reps; i++) { + for (int j = 0; j < inputDataList.size(); j++) { + benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom( + inputDataList.get(j), extensions); + } + } + } + + @Benchmark + void deserializeFromMemoryStream(int reps) throws IOException { + if (inputStreamList.size() == 0) { + return; + } + for (int i = 0; i < reps; i++) { + for (int j = 0; j < inputStreamList.size(); j++) { + benchmarkMessageType.getDefaultInstance().getParserForType().parseFrom( + inputStreamList.get(j), extensions); + inputStreamList.get(j).reset(); + } + } + } +} + + diff --git a/libs/protobuf/benchmarks/js/benchmark_suite.js b/libs/protobuf/benchmarks/js/benchmark_suite.js new file mode 100644 index 0000000..c5c3e51 --- /dev/null +++ b/libs/protobuf/benchmarks/js/benchmark_suite.js @@ -0,0 +1,33 @@ +var benchmark = require("benchmark"); + +function newBenchmark(messageName, filename, language) { + var benches = []; + return { + suite: new benchmark.Suite(messageName + filename + language ) + .on("add", function(event) { + benches.push(event.target); + }) + .on("start", function() { + process.stdout.write( + "benchmarking message " + messageName + + " of dataset file " + filename + + "'s performance ..." + "\n\n"); + }) + .on("cycle", function(event) { + process.stdout.write(String(event.target) + "\n"); + }) + .on("complete", function() { + var getHz = function(bench) { + return 1 / (bench.stats.mean + bench.stats.moe); + } + benches.forEach(function(val, index) { + benches[index] = getHz(val); + }); + }), + benches: benches + } +} + +module.exports = { + newBenchmark: newBenchmark +} diff --git a/libs/protobuf/benchmarks/js/js_benchmark.js b/libs/protobuf/benchmarks/js/js_benchmark.js new file mode 100644 index 0000000..9ba4828 --- /dev/null +++ b/libs/protobuf/benchmarks/js/js_benchmark.js @@ -0,0 +1,82 @@ +require('./datasets/google_message1/proto2/benchmark_message1_proto2_pb.js'); +require('./datasets/google_message1/proto3/benchmark_message1_proto3_pb.js'); +require('./datasets/google_message2/benchmark_message2_pb.js'); +require('./datasets/google_message3/benchmark_message3_pb.js'); +require('./datasets/google_message4/benchmark_message4_pb.js'); +require('./benchmarks_pb.js'); + +var fs = require('fs'); +var benchmarkSuite = require("./benchmark_suite.js"); + + +function getNewPrototype(name) { + var message = eval("proto." + name); + if (typeof(message) == "undefined") { + throw "type " + name + " is undefined"; + } + return message; +} + +var results = []; +var json_file = ""; + +console.log("#####################################################"); +console.log("Js Benchmark: "); +process.argv.forEach(function(filename, index) { + if (index < 2) { + return; + } + if (filename.indexOf("--json_output") != -1) { + json_file = filename.replace(/^--json_output=/, ''); + return; + } + + var benchmarkDataset = + proto.benchmarks.BenchmarkDataset.deserializeBinary(fs.readFileSync(filename)); + var messageList = []; + var totalBytes = 0; + benchmarkDataset.getPayloadList().forEach(function(onePayload) { + var message = getNewPrototype(benchmarkDataset.getMessageName()); + messageList.push(message.deserializeBinary(onePayload)); + totalBytes += onePayload.length; + }); + + var scenarios = benchmarkSuite.newBenchmark( + benchmarkDataset.getMessageName(), filename, "js"); + scenarios.suite + .add("js deserialize", function() { + benchmarkDataset.getPayloadList().forEach(function(onePayload) { + var protoType = getNewPrototype(benchmarkDataset.getMessageName()); + protoType.deserializeBinary(onePayload); + }); + }) + .add("js serialize", function() { + var protoType = getNewPrototype(benchmarkDataset.getMessageName()); + messageList.forEach(function(message) { + message.serializeBinary(); + }); + }) + .run({"Async": false}); + + results.push({ + filename: filename, + benchmarks: { + protobufjs_decoding: scenarios.benches[0] * totalBytes / 1024 / 1024, + protobufjs_encoding: scenarios.benches[1] * totalBytes / 1024 / 1024 + } + }) + + console.log("Throughput for deserialize: " + + scenarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); + console.log("Throughput for serialize: " + + scenarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); + console.log(""); +}); +console.log("#####################################################"); + +if (json_file != "") { + fs.writeFile(json_file, JSON.stringify(results), (err) => { + if (err) throw err; + }); +} + diff --git a/libs/protobuf/benchmarks/php/PhpBenchmark.php b/libs/protobuf/benchmarks/php/PhpBenchmark.php new file mode 100644 index 0000000..d3db61d --- /dev/null +++ b/libs/protobuf/benchmarks/php/PhpBenchmark.php @@ -0,0 +1,170 @@ +getPayload(); + for ($i = $payloads->count() - 1; $i >= 0; $i--) { + (new $args[1]())->mergeFromString($payloads->offsetGet($i)); + } + } + + // $args: array of message + static function serialize(&$args) { + foreach ($args as &$temp_message) { + $temp_message->serializeToString(); + } + } +} + +class Benchmark +{ + private $benchmark_name; + private $args; + private $benchmark_time; + private $total_bytes; + private $coefficient; + + public function __construct($benchmark_name, $args, $total_bytes, + $benchmark_time = 5.0) { + $this->args = $args; + $this->benchmark_name = $benchmark_name; + $this->benchmark_time = $benchmark_time; + $this->total_bytes = $total_bytes; + $this->coefficient = pow (10, 0) / pow(2, 20); + } + + public function runBenchmark() { + $t = $this->runBenchmarkWithTimes(1); + $times = ceil($this->benchmark_time / $t); + return $this->total_bytes * $times / + ($times == 1 ? $t : $this->runBenchmarkWithTimes($times)) * + $this->coefficient; + } + + private function runBenchmarkWithTimes($times) { + $st = microtime(true); + for ($i = 0; $i < $times; $i++) { + call_user_func_array($this->benchmark_name, array(&$this->args)); + } + $en = microtime(true); + return $en - $st; + } +} + +function getMessageName(&$dataset) { + switch ($dataset->getMessageName()) { + case "benchmarks.proto3.GoogleMessage1": + return "\Benchmarks\Proto3\GoogleMessage1"; + case "benchmarks.proto2.GoogleMessage1": + return "\Benchmarks\Proto2\GoogleMessage1"; + case "benchmarks.proto2.GoogleMessage2": + return "\Benchmarks\Proto2\GoogleMessage2"; + case "benchmarks.google_message3.GoogleMessage3": + return "\Benchmarks\Google_message3\GoogleMessage3"; + case "benchmarks.google_message4.GoogleMessage4": + return "\Benchmarks\Google_message4\GoogleMessage4"; + default: + exit("Message " . $dataset->getMessageName() . " not found !"); + } +} + +function runBenchmark($file, $behavior_prefix) { + $datafile = fopen($file, "r") or die("Unable to open file " . $file); + $bytes = fread($datafile, filesize($file)); + $dataset = new BenchmarkDataset(NULL); + $dataset->mergeFromString($bytes); + $message_name = getMessageName($dataset); + $message_list = array(); + $total_bytes = 0; + $payloads = $dataset->getPayload(); + for ($i = $payloads->count() - 1; $i >= 0; $i--) { + $new_message = new $message_name(); + $new_message->mergeFromString($payloads->offsetGet($i)); + array_push($message_list, $new_message); + $total_bytes += strlen($payloads->offsetGet($i)); + } + + $parse_benchmark = new Benchmark( + "\Google\Protobuf\Benchmark\BenchmarkMethod::parse", + array($dataset, $message_name), $total_bytes); + $serialize_benchmark = new Benchmark( + "\Google\Protobuf\Benchmark\BenchmarkMethod::serialize", + $message_list, $total_bytes); + + return array( + "filename" => $file, + "benchmarks" => array( + $behavior_prefix . "_parse" => $parse_benchmark->runBenchmark(), + $behavior_prefix . "_serailize" => $serialize_benchmark->runBenchmark() + ), + "message_name" => $dataset->getMessageName() + ); +} + +// main +$json_output = false; +$results = array(); +$behavior_prefix = ""; + +foreach ($argv as $index => $arg) { + if ($index == 0) { + continue; + } + if ($arg == "--json") { + $json_output = true; + } else if (strpos($arg, "--behavior_prefix") == 0) { + $behavior_prefix = str_replace("--behavior_prefix=", "", $arg); + } +} + +foreach ($argv as $index => $arg) { + if ($index == 0) { + continue; + } + if (substr($arg, 0, 2) == "--") { + continue; + } else { + array_push($results, runBenchmark($arg, $behavior_prefix)); + } +} + +if ($json_output) { + print json_encode($results); +} else { + print "PHP protobuf benchmark result:\n\n"; + foreach ($results as $result) { + printf("result for test data file: %s\n", $result["filename"]); + foreach ($result["benchmarks"] as $benchmark => $throughput) { + printf(" Throughput for benchmark %s: %.2f MB/s\n", + $benchmark, $throughput); + } + } +} + +?> diff --git a/libs/protobuf/benchmarks/php/autoload.php b/libs/protobuf/benchmarks/php/autoload.php new file mode 100644 index 0000000..52a8741 --- /dev/null +++ b/libs/protobuf/benchmarks/php/autoload.php @@ -0,0 +1,25 @@ + 6 && arg.substring(arg.length - 6) == ".proto") { + protoFiles.push(arg); + } else if (arg.length > 15 && arg.substring(0, 15) == "--include_path=") { + prefix = arg.substring(15); + } else if (index >= 2) { + argv.push(arg); + } +}); +protoFiles.forEach(function(val) { + argv.push(prefix + "/" + val); +}); + +pbjs.main(argv, function(err, output){ + if (err) { + console.log(err); + } +}); + diff --git a/libs/protobuf/benchmarks/protobuf.js/protobufjs_benchmark.js b/libs/protobuf/benchmarks/protobuf.js/protobufjs_benchmark.js new file mode 100644 index 0000000..e062d1c --- /dev/null +++ b/libs/protobuf/benchmarks/protobuf.js/protobufjs_benchmark.js @@ -0,0 +1,66 @@ +var root = require("./generated_bundle_code.js"); +var fs = require('fs'); +var benchmark = require("./node_modules/benchmark"); +var benchmarkSuite = require("./benchmark_suite.js"); + + +function getNewPrototype(name) { + var message = eval("root." + name); + if (typeof(message) == "undefined") { + throw "type " + name + " is undefined"; + } + return message; +} + + +var results = []; + +console.log("#####################################################"); +console.log("ProtobufJs Benchmark: "); +process.argv.forEach(function(filename, index) { + if (index < 2) { + return; + } + var benchmarkDataset = + root.benchmarks.BenchmarkDataset.decode(fs.readFileSync(filename)); + var messageList = []; + var totalBytes = 0; + benchmarkDataset.payload.forEach(function(onePayload) { + var message = getNewPrototype(benchmarkDataset.messageName); + messageList.push(message.decode(onePayload)); + totalBytes += onePayload.length; + }); + + var scenarios = benchmarkSuite.newBenchmark( + benchmarkDataset.messageName, filename, "protobufjs"); + scenarios.suite + .add("protobuf.js static decoding", function() { + benchmarkDataset.payload.forEach(function(onePayload) { + var protoType = getNewPrototype(benchmarkDataset.messageName); + protoType.decode(onePayload); + }); + }) + .add("protobuf.js static encoding", function() { + var protoType = getNewPrototype(benchmarkDataset.messageName); + messageList.forEach(function(message) { + protoType.encode(message).finish(); + }); + }) + .run({"Async": false}); + + results.push({ + filename: filename, + benchmarks: { + protobufjs_decoding: scenarios.benches[0] * totalBytes, + protobufjs_encoding: scenarios.benches[1] * totalBytes + } + }) + + console.log("Throughput for decoding: " + + scenarios.benches[0] * totalBytes / 1024 / 1024 + "MB/s" ); + console.log("Throughput for encoding: " + + scenarios.benches[1] * totalBytes / 1024 / 1024 + "MB/s" ); + console.log(""); +}); +console.log("#####################################################"); + diff --git a/libs/protobuf/benchmarks/python/__init__.py b/libs/protobuf/benchmarks/python/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/libs/protobuf/benchmarks/python/py_benchmark.py b/libs/protobuf/benchmarks/python/py_benchmark.py new file mode 100644 index 0000000..60e377e --- /dev/null +++ b/libs/protobuf/benchmarks/python/py_benchmark.py @@ -0,0 +1,161 @@ +from __future__ import print_function +import sys +import os +import timeit +import math +import argparse +import fnmatch +import json + +parser = argparse.ArgumentParser(description="Python protobuf benchmark") +parser.add_argument("data_files", metavar="dataFile", nargs="+", + help="testing data files.") +parser.add_argument("--json", action="store_const", dest="json", + const="yes", default="no", + help="Whether to output json results") +parser.add_argument("--behavior_prefix", dest="behavior_prefix", + help="The output json format's behavior's name's prefix", + default="") +# BEGIN CPP GENERATED MESSAGE +parser.add_argument("--cpp_generated", action="store_const", + dest="cpp_generated", const="yes", default="no", + help="Whether to link generated code library") +# END CPP GENERATED MESSAGE +args = parser.parse_args() +# BEGIN CPP GENERATED MESSAGE +# CPP generated code must be linked before importing the generated Python code +# for the descriptor can be found in the pool +if args.cpp_generated != "no": + sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" ) + import libbenchmark_messages + sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" ) +# END CPP GENERATED MESSAGE + + +import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2 +import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2 +import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2 +import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2 +import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2 +import benchmarks_pb2 as benchmarks_pb2 + + +def run_one_test(filename): + data = open(filename, "rb").read() + benchmark_dataset = benchmarks_pb2.BenchmarkDataset() + benchmark_dataset.ParseFromString(data) + total_bytes = 0 + for payload in benchmark_dataset.payload: + total_bytes += len(payload) + benchmark_util = Benchmark(full_iteration=len(benchmark_dataset.payload), + module="py_benchmark", + setup_method="init", + total_bytes=total_bytes) + result={} + result["filename"] = filename + result["message_name"] = benchmark_dataset.message_name + result["benchmarks"] = {} + benchmark_util.set_test_method("parse_from_benchmark") + result["benchmarks"][args.behavior_prefix + "_parse_from_benchmark"] = \ + benchmark_util.run_benchmark(setup_method_args='"%s"' % (filename)) + benchmark_util.set_test_method("serialize_to_benchmark") + result["benchmarks"][args.behavior_prefix + "_serialize_to_benchmark"] = \ + benchmark_util.run_benchmark(setup_method_args='"%s"' % (filename)) + return result + + +def init(filename): + global benchmark_dataset, message_class, message_list, counter, total_bytes + message_list=[] + counter = 0 + total_bytes = 0 + data = open(filename, "rb").read() + benchmark_dataset = benchmarks_pb2.BenchmarkDataset() + benchmark_dataset.ParseFromString(data) + + if benchmark_dataset.message_name == "benchmarks.proto3.GoogleMessage1": + message_class = benchmark_message1_proto3_pb2.GoogleMessage1 + elif benchmark_dataset.message_name == "benchmarks.proto2.GoogleMessage1": + message_class = benchmark_message1_proto2_pb2.GoogleMessage1 + elif benchmark_dataset.message_name == "benchmarks.proto2.GoogleMessage2": + message_class = benchmark_message2_pb2.GoogleMessage2 + elif benchmark_dataset.message_name == "benchmarks.google_message3.GoogleMessage3": + message_class = benchmark_message3_pb2.GoogleMessage3 + elif benchmark_dataset.message_name == "benchmarks.google_message4.GoogleMessage4": + message_class = benchmark_message4_pb2.GoogleMessage4 + else: + raise IOError("Message %s not found!" % (benchmark_dataset.message_name)) + + for one_payload in benchmark_dataset.payload: + temp = message_class() + temp.ParseFromString(one_payload) + message_list.append(temp) + total_bytes += len(one_payload) + + +def parse_from_benchmark(): + global counter, message_class, benchmark_dataset + m = message_class().ParseFromString(benchmark_dataset.payload[counter % len(benchmark_dataset.payload)]) + counter = counter + 1 + + +def serialize_to_benchmark(): + global counter, message_list, message_class + s = message_list[counter % len(benchmark_dataset.payload)].SerializeToString() + counter = counter + 1 + + +class Benchmark: + def __init__(self, module=None, test_method=None, + setup_method=None, total_bytes=None, full_iteration = 1): + self.full_iteration = full_iteration + self.module = module + self.test_method = test_method + self.setup_method = setup_method + self.total_bytes = total_bytes + + def set_test_method(self, test_method): + self.test_method = test_method + + def full_setup_code(self, setup_method_args=''): + setup_code = "" + setup_code += "from %s import %s\n" % (self.module, self.test_method) + setup_code += "from %s import %s\n" % (self.module, self.setup_method) + setup_code += "%s(%s)\n" % (self.setup_method, setup_method_args) + return setup_code + + def dry_run(self, test_method_args='', setup_method_args=''): + return timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args), + setup=self.full_setup_code(setup_method_args), + number=self.full_iteration); + + def run_benchmark(self, test_method_args='', setup_method_args=''): + reps = self.full_iteration; + t = self.dry_run(test_method_args, setup_method_args); + if t < 3 : + reps = int(math.ceil(3 / t)) * self.full_iteration + if reps != self.full_iteration: + t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args), + setup=self.full_setup_code(setup_method_args), + number=reps); + return self.total_bytes * 1.0 / 2 ** 20 / (1.0 * t / reps * self.full_iteration) + + +if __name__ == "__main__": + results = [] + for file in args.data_files: + results.append(run_one_test(file)) + + if args.json != "no": + print(json.dumps(results)) + else: + for result in results: + print("Message %s of dataset file %s" % \ + (result["message_name"], result["filename"])) + print("Average throughput for parse_from_benchmark: %.2f MB/s" % \ + (result["benchmarks"][ \ + args.behavior_prefix + "_parse_from_benchmark"])) + print("Average throughput for serialize_to_benchmark: %.2f MB/s" % \ + (result["benchmarks"][ \ + args.behavior_prefix + "_serialize_to_benchmark"])) + print("") diff --git a/libs/protobuf/benchmarks/python/python_benchmark_messages.cc b/libs/protobuf/benchmarks/python/python_benchmark_messages.cc new file mode 100644 index 0000000..f6ddcf3 --- /dev/null +++ b/libs/protobuf/benchmarks/python/python_benchmark_messages.cc @@ -0,0 +1,31 @@ +#include + +#include "benchmarks.pb.h" +#include "datasets/google_message1/proto2/benchmark_message1_proto2.pb.h" +#include "datasets/google_message1/proto3/benchmark_message1_proto3.pb.h" +#include "datasets/google_message2/benchmark_message2.pb.h" +#include "datasets/google_message3/benchmark_message3.pb.h" +#include "datasets/google_message4/benchmark_message4.pb.h" + +static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, + "libbenchmark_messages", + "Benchmark messages Python module", + -1, + NULL, + NULL, + NULL, + NULL, + NULL}; + +extern "C" { +PyMODINIT_FUNC PyInit_libbenchmark_messages() { + benchmarks::BenchmarkDataset().descriptor(); + benchmarks::proto3::GoogleMessage1().descriptor(); + benchmarks::proto2::GoogleMessage1().descriptor(); + benchmarks::proto2::GoogleMessage2().descriptor(); + benchmarks::google_message3::GoogleMessage3().descriptor(); + benchmarks::google_message4::GoogleMessage4().descriptor(); + + return PyModule_Create(&_module); +} +} diff --git a/libs/protobuf/benchmarks/util/__init__.py b/libs/protobuf/benchmarks/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/libs/protobuf/benchmarks/util/big_query_utils.py b/libs/protobuf/benchmarks/util/big_query_utils.py new file mode 100755 index 0000000..aea55bb --- /dev/null +++ b/libs/protobuf/benchmarks/util/big_query_utils.py @@ -0,0 +1,189 @@ +#!/usr/bin/env python2.7 + +from __future__ import print_function +import argparse +import json +import uuid +import httplib2 + +from apiclient import discovery +from apiclient.errors import HttpError +from oauth2client.client import GoogleCredentials + +# 30 days in milliseconds +_EXPIRATION_MS = 30 * 24 * 60 * 60 * 1000 +NUM_RETRIES = 3 + + +def create_big_query(): + """Authenticates with cloud platform and gets a BiqQuery service object + """ + creds = GoogleCredentials.get_application_default() + return discovery.build( + 'bigquery', 'v2', credentials=creds, cache_discovery=False) + + +def create_dataset(biq_query, project_id, dataset_id): + is_success = True + body = { + 'datasetReference': { + 'projectId': project_id, + 'datasetId': dataset_id + } + } + + try: + dataset_req = biq_query.datasets().insert( + projectId=project_id, body=body) + dataset_req.execute(num_retries=NUM_RETRIES) + except HttpError as http_error: + if http_error.resp.status == 409: + print('Warning: The dataset %s already exists' % dataset_id) + else: + # Note: For more debugging info, print "http_error.content" + print('Error in creating dataset: %s. Err: %s' % (dataset_id, + http_error)) + is_success = False + return is_success + + +def create_table(big_query, project_id, dataset_id, table_id, table_schema, + description): + fields = [{ + 'name': field_name, + 'type': field_type, + 'description': field_description + } for (field_name, field_type, field_description) in table_schema] + return create_table2(big_query, project_id, dataset_id, table_id, fields, + description) + + +def create_partitioned_table(big_query, + project_id, + dataset_id, + table_id, + table_schema, + description, + partition_type='DAY', + expiration_ms=_EXPIRATION_MS): + """Creates a partitioned table. By default, a date-paritioned table is created with + each partition lasting 30 days after it was last modified. + """ + fields = [{ + 'name': field_name, + 'type': field_type, + 'description': field_description + } for (field_name, field_type, field_description) in table_schema] + return create_table2(big_query, project_id, dataset_id, table_id, fields, + description, partition_type, expiration_ms) + + +def create_table2(big_query, + project_id, + dataset_id, + table_id, + fields_schema, + description, + partition_type=None, + expiration_ms=None): + is_success = True + + body = { + 'description': description, + 'schema': { + 'fields': fields_schema + }, + 'tableReference': { + 'datasetId': dataset_id, + 'projectId': project_id, + 'tableId': table_id + } + } + + if partition_type and expiration_ms: + body["timePartitioning"] = { + "type": partition_type, + "expirationMs": expiration_ms + } + + try: + table_req = big_query.tables().insert( + projectId=project_id, datasetId=dataset_id, body=body) + res = table_req.execute(num_retries=NUM_RETRIES) + print('Successfully created %s "%s"' % (res['kind'], res['id'])) + except HttpError as http_error: + if http_error.resp.status == 409: + print('Warning: Table %s already exists' % table_id) + else: + print('Error in creating table: %s. Err: %s' % (table_id, + http_error)) + is_success = False + return is_success + + +def patch_table(big_query, project_id, dataset_id, table_id, fields_schema): + is_success = True + + body = { + 'schema': { + 'fields': fields_schema + }, + 'tableReference': { + 'datasetId': dataset_id, + 'projectId': project_id, + 'tableId': table_id + } + } + + try: + table_req = big_query.tables().patch( + projectId=project_id, + datasetId=dataset_id, + tableId=table_id, + body=body) + res = table_req.execute(num_retries=NUM_RETRIES) + print('Successfully patched %s "%s"' % (res['kind'], res['id'])) + except HttpError as http_error: + print('Error in creating table: %s. Err: %s' % (table_id, http_error)) + is_success = False + return is_success + + +def insert_rows(big_query, project_id, dataset_id, table_id, rows_list): + is_success = True + body = {'rows': rows_list} + try: + insert_req = big_query.tabledata().insertAll( + projectId=project_id, + datasetId=dataset_id, + tableId=table_id, + body=body) + res = insert_req.execute(num_retries=NUM_RETRIES) + if res.get('insertErrors', None): + print('Error inserting rows! Response: %s' % res) + is_success = False + except HttpError as http_error: + print('Error inserting rows to the table %s' % table_id) + is_success = False + + return is_success + + +def sync_query_job(big_query, project_id, query, timeout=5000): + query_data = {'query': query, 'timeoutMs': timeout} + query_job = None + try: + query_job = big_query.jobs().query( + projectId=project_id, + body=query_data).execute(num_retries=NUM_RETRIES) + except HttpError as http_error: + print('Query execute job failed with error: %s' % http_error) + print(http_error.content) + return query_job + + + # List of (column name, column type, description) tuples +def make_row(unique_row_id, row_values_dict): + """row_values_dict is a dictionary of column name and column value. + """ + return {'insertId': unique_row_id, 'json': row_values_dict} diff --git a/libs/protobuf/benchmarks/util/data_proto2_to_proto3_util.h b/libs/protobuf/benchmarks/util/data_proto2_to_proto3_util.h new file mode 100644 index 0000000..5eea850 --- /dev/null +++ b/libs/protobuf/benchmarks/util/data_proto2_to_proto3_util.h @@ -0,0 +1,64 @@ +#ifndef PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_ +#define PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_ + +#include "google/protobuf/message.h" +#include "google/protobuf/descriptor.h" + +using google::protobuf::FieldDescriptor; +using google::protobuf::Message; +using google::protobuf::Reflection; + +namespace google { +namespace protobuf { +namespace util { + +class DataStripper { + public: + void StripMessage(Message *message) { + std::vector set_fields; + const Reflection* reflection = message->GetReflection(); + reflection->ListFields(*message, &set_fields); + + for (size_t i = 0; i < set_fields.size(); i++) { + const FieldDescriptor* field = set_fields[i]; + if (ShouldBeClear(field)) { + reflection->ClearField(message, field); + continue; + } + if (field->type() == FieldDescriptor::TYPE_MESSAGE) { + if (field->is_repeated()) { + for (int j = 0; j < reflection->FieldSize(*message, field); j++) { + StripMessage(reflection->MutableRepeatedMessage(message, field, j)); + } + } else { + StripMessage(reflection->MutableMessage(message, field)); + } + } + } + + reflection->MutableUnknownFields(message)->Clear(); + } + private: + virtual bool ShouldBeClear(const FieldDescriptor *field) = 0; +}; + +class GogoDataStripper : public DataStripper { + private: + virtual bool ShouldBeClear(const FieldDescriptor *field) { + return field->type() == FieldDescriptor::TYPE_GROUP; + } +}; + +class Proto3DataStripper : public DataStripper { + private: + virtual bool ShouldBeClear(const FieldDescriptor *field) { + return field->type() == FieldDescriptor::TYPE_GROUP || + field->is_extension(); + } +}; + +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // PROTOBUF_BENCHMARKS_UTIL_DATA_PROTO2_TO_PROTO3_UTIL_H_ diff --git a/libs/protobuf/benchmarks/util/gogo_data_scrubber.cc b/libs/protobuf/benchmarks/util/gogo_data_scrubber.cc new file mode 100644 index 0000000..9ef57b0 --- /dev/null +++ b/libs/protobuf/benchmarks/util/gogo_data_scrubber.cc @@ -0,0 +1,74 @@ +#include "benchmarks.pb.h" +#include "datasets/google_message1/proto2/benchmark_message1_proto2.pb.h" +#include "datasets/google_message1/proto3/benchmark_message1_proto3.pb.h" +#include "datasets/google_message2/benchmark_message2.pb.h" +#include "datasets/google_message3/benchmark_message3.pb.h" +#include "datasets/google_message4/benchmark_message4.pb.h" +#include "data_proto2_to_proto3_util.h" + +#include + +using google::protobuf::util::GogoDataStripper; + +std::string ReadFile(const std::string& name) { + std::ifstream file(name.c_str()); + GOOGLE_CHECK(file.is_open()) << "Couldn't find file '" + << name + << "', please make sure you are running this command from the benchmarks" + << " directory.\n"; + return std::string((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); +} + +int main(int argc, char *argv[]) { + if (argc % 2 == 0 || argc == 1) { + std::cerr << "Usage: [input_files] [output_file_names] where " << + "input_files are one to one mapping to output_file_names." << + std::endl; + return 1; + } + + for (int i = argc / 2; i > 0; i--) { + const std::string &input_file = argv[i]; + const std::string &output_file = argv[i + argc / 2]; + + std::cerr << "Generating " << input_file + << " to " << output_file << std::endl; + benchmarks::BenchmarkDataset dataset; + Message* message; + std::string dataset_payload = ReadFile(input_file); + GOOGLE_CHECK(dataset.ParseFromString(dataset_payload)) + << "Can' t parse data file " << input_file; + + if (dataset.message_name() == "benchmarks.proto3.GoogleMessage1") { + message = new benchmarks::proto3::GoogleMessage1; + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage1") { + message = new benchmarks::proto2::GoogleMessage1; + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage2") { + message = new benchmarks::proto2::GoogleMessage2; + } else if (dataset.message_name() == + "benchmarks.google_message3.GoogleMessage3") { + message = new benchmarks::google_message3::GoogleMessage3; + } else if (dataset.message_name() == + "benchmarks.google_message4.GoogleMessage4") { + message = new benchmarks::google_message4::GoogleMessage4; + } else { + std::cerr << "Unknown message type: " << dataset.message_name(); + exit(1); + } + + for (int i = 0; i < dataset.payload_size(); i++) { + message->ParseFromString(dataset.payload(i)); + GogoDataStripper stripper; + stripper.StripMessage(message); + dataset.set_payload(i, message->SerializeAsString()); + } + + std::ofstream ofs(output_file); + ofs << dataset.SerializeAsString(); + ofs.close(); + } + + + return 0; +} diff --git a/libs/protobuf/benchmarks/util/proto3_data_stripper.cc b/libs/protobuf/benchmarks/util/proto3_data_stripper.cc new file mode 100644 index 0000000..3096c4c --- /dev/null +++ b/libs/protobuf/benchmarks/util/proto3_data_stripper.cc @@ -0,0 +1,74 @@ +#include "benchmarks.pb.h" +#include "datasets/google_message1/proto2/benchmark_message1_proto2.pb.h" +#include "datasets/google_message1/proto3/benchmark_message1_proto3.pb.h" +#include "datasets/google_message2/benchmark_message2.pb.h" +#include "datasets/google_message3/benchmark_message3.pb.h" +#include "datasets/google_message4/benchmark_message4.pb.h" +#include "data_proto2_to_proto3_util.h" + +#include + +using google::protobuf::util::Proto3DataStripper; + +std::string ReadFile(const std::string& name) { + std::ifstream file(name.c_str()); + GOOGLE_CHECK(file.is_open()) << "Couldn't find file '" + << name + << "', please make sure you are running this command from the benchmarks" + << " directory.\n"; + return std::string((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); +} + +int main(int argc, char *argv[]) { + if (argc % 2 == 0 || argc == 1) { + std::cerr << "Usage: [input_files] [output_file_names] where " << + "input_files are one to one mapping to output_file_names." << + std::endl; + return 1; + } + + for (int i = argc / 2; i > 0; i--) { + const std::string &input_file = argv[i]; + const std::string &output_file = argv[i + argc / 2]; + + std::cerr << "Generating " << input_file + << " to " << output_file << std::endl; + benchmarks::BenchmarkDataset dataset; + Message* message; + std::string dataset_payload = ReadFile(input_file); + GOOGLE_CHECK(dataset.ParseFromString(dataset_payload)) + << "Can' t parse data file " << input_file; + + if (dataset.message_name() == "benchmarks.proto3.GoogleMessage1") { + message = new benchmarks::proto3::GoogleMessage1; + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage1") { + message = new benchmarks::proto2::GoogleMessage1; + } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage2") { + message = new benchmarks::proto2::GoogleMessage2; + } else if (dataset.message_name() == + "benchmarks.google_message3.GoogleMessage3") { + message = new benchmarks::google_message3::GoogleMessage3; + } else if (dataset.message_name() == + "benchmarks.google_message4.GoogleMessage4") { + message = new benchmarks::google_message4::GoogleMessage4; + } else { + std::cerr << "Unknown message type: " << dataset.message_name(); + exit(1); + } + + for (int i = 0; i < dataset.payload_size(); i++) { + message->ParseFromString(dataset.payload(i)); + Proto3DataStripper stripper; + stripper.StripMessage(message); + dataset.set_payload(i, message->SerializeAsString()); + } + + std::ofstream ofs(output_file); + ofs << dataset.SerializeAsString(); + ofs.close(); + } + + + return 0; +} diff --git a/libs/protobuf/benchmarks/util/protoc-gen-gogoproto.cc b/libs/protobuf/benchmarks/util/protoc-gen-gogoproto.cc new file mode 100644 index 0000000..9c1b3d0 --- /dev/null +++ b/libs/protobuf/benchmarks/util/protoc-gen-gogoproto.cc @@ -0,0 +1,103 @@ +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "schema_proto2_to_proto3_util.h" + +#include "google/protobuf/compiler/plugin.h" + +using google::protobuf::FileDescriptorProto; +using google::protobuf::FileDescriptor; +using google::protobuf::DescriptorPool; +using google::protobuf::io::Printer; +using google::protobuf::util::SchemaGroupStripper; +using google::protobuf::util::EnumScrubber; + +namespace google { +namespace protobuf { +namespace compiler { + +namespace { + +string StripProto(string filename) { + if (filename.substr(filename.size() - 11) == ".protodevel") { + // .protodevel + return filename.substr(0, filename.size() - 11); + } else { + // .proto + return filename.substr(0, filename.size() - 6); + } +} + +DescriptorPool new_pool_; + +} // namespace + +class GoGoProtoGenerator : public CodeGenerator { + public: + virtual bool GenerateAll(const std::vector& files, + const string& parameter, + GeneratorContext* context, + string* error) const { + for (int i = 0; i < files.size(); i++) { + for (auto file : files) { + bool can_generate = + (new_pool_.FindFileByName(file->name()) == nullptr); + for (int j = 0; j < file->dependency_count(); j++) { + can_generate &= (new_pool_.FindFileByName( + file->dependency(j)->name()) != nullptr); + } + for (int j = 0; j < file->public_dependency_count(); j++) { + can_generate &= (new_pool_.FindFileByName( + file->public_dependency(j)->name()) != nullptr); + } + for (int j = 0; j < file->weak_dependency_count(); j++) { + can_generate &= (new_pool_.FindFileByName( + file->weak_dependency(j)->name()) != nullptr); + } + if (can_generate) { + Generate(file, parameter, context, error); + break; + } + } + } + + return true; + } + + virtual bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const { + FileDescriptorProto new_file; + file->CopyTo(&new_file); + SchemaGroupStripper::StripFile(file, &new_file); + + EnumScrubber enum_scrubber; + enum_scrubber.ScrubFile(&new_file); + + string filename = file->name(); + string basename = StripProto(filename); + + std::vector> option_pairs; + ParseGeneratorParameter(parameter, &option_pairs); + + std::unique_ptr output( + context->Open(basename + ".proto")); + string content = new_pool_.BuildFile(new_file)->DebugString(); + Printer printer(output.get(), '$'); + printer.WriteRaw(content.c_str(), content.size()); + + return true; + } +}; + +} // namespace compiler +} // namespace protobuf +} // namespace google + +int main(int argc, char* argv[]) { + google::protobuf::compiler::GoGoProtoGenerator generator; + return google::protobuf::compiler::PluginMain(argc, argv, &generator); +} diff --git a/libs/protobuf/benchmarks/util/protoc-gen-proto2_to_proto3.cc b/libs/protobuf/benchmarks/util/protoc-gen-proto2_to_proto3.cc new file mode 100644 index 0000000..d0a8902 --- /dev/null +++ b/libs/protobuf/benchmarks/util/protoc-gen-proto2_to_proto3.cc @@ -0,0 +1,115 @@ +#include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/io/zero_copy_stream.h" +#include "google/protobuf/io/printer.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" +#include "schema_proto2_to_proto3_util.h" + +#include "google/protobuf/compiler/plugin.h" + +using google::protobuf::FileDescriptorProto; +using google::protobuf::FileDescriptor; +using google::protobuf::DescriptorPool; +using google::protobuf::io::Printer; +using google::protobuf::util::SchemaGroupStripper; +using google::protobuf::util::EnumScrubber; +using google::protobuf::util::ExtensionStripper; +using google::protobuf::util::FieldScrubber; + +namespace google { +namespace protobuf { +namespace compiler { + +namespace { + +string StripProto(string filename) { + return filename.substr(0, filename.rfind(".proto")); +} + +DescriptorPool* GetPool() { + static DescriptorPool *pool = new DescriptorPool(); + return pool; +} + +} // namespace + +class Proto2ToProto3Generator final : public CodeGenerator { + public: + bool GenerateAll(const std::vector& files, + const string& parameter, + GeneratorContext* context, + string* error) const { + for (int i = 0; i < files.size(); i++) { + for (auto file : files) { + if (CanGenerate(file)) { + Generate(file, parameter, context, error); + break; + } + } + } + + return true; + } + + bool Generate(const FileDescriptor* file, + const string& parameter, + GeneratorContext* context, + string* error) const { + FileDescriptorProto new_file; + file->CopyTo(&new_file); + SchemaGroupStripper::StripFile(file, &new_file); + + EnumScrubber enum_scrubber; + enum_scrubber.ScrubFile(&new_file); + ExtensionStripper::StripFile(&new_file); + FieldScrubber::ScrubFile(&new_file); + new_file.set_syntax("proto3"); + + string filename = file->name(); + string basename = StripProto(filename); + + std::vector> option_pairs; + ParseGeneratorParameter(parameter, &option_pairs); + + std::unique_ptr output( + context->Open(basename + ".proto")); + string content = GetPool()->BuildFile(new_file)->DebugString(); + Printer printer(output.get(), '$'); + printer.WriteRaw(content.c_str(), content.size()); + + return true; + } + private: + bool CanGenerate(const FileDescriptor* file) const { + if (GetPool()->FindFileByName(file->name()) != nullptr) { + return false; + } + for (int j = 0; j < file->dependency_count(); j++) { + if (GetPool()->FindFileByName(file->dependency(j)->name()) == nullptr) { + return false; + } + } + for (int j = 0; j < file->public_dependency_count(); j++) { + if (GetPool()->FindFileByName( + file->public_dependency(j)->name()) == nullptr) { + return false; + } + } + for (int j = 0; j < file->weak_dependency_count(); j++) { + if (GetPool()->FindFileByName( + file->weak_dependency(j)->name()) == nullptr) { + return false; + } + } + return true; + } +}; + +} // namespace compiler +} // namespace protobuf +} // namespace google + +int main(int argc, char* argv[]) { + google::protobuf::compiler::Proto2ToProto3Generator generator; + return google::protobuf::compiler::PluginMain(argc, argv, &generator); +} diff --git a/libs/protobuf/benchmarks/util/result_parser.py b/libs/protobuf/benchmarks/util/result_parser.py new file mode 100644 index 0000000..d3251a8 --- /dev/null +++ b/libs/protobuf/benchmarks/util/result_parser.py @@ -0,0 +1,352 @@ +# This import depends on the automake rule protoc_middleman, please make sure +# protoc_middleman has been built before run this file. +import argparse +import json +import re +import os.path +# BEGIN OPENSOURCE +import sys +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) +# END OPENSOURCE +import tmp.benchmarks_pb2 as benchmarks_pb2 + +__file_size_map = {} + +def __get_data_size(filename): + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + "/../" + filename + if filename in __file_size_map: + return __file_size_map[filename] + benchmark_dataset = benchmarks_pb2.BenchmarkDataset() + benchmark_dataset.ParseFromString( + open(filename, "rb").read()) + size = 0 + count = 0 + for payload in benchmark_dataset.payload: + size += len(payload) + count += 1 + __file_size_map[filename] = (size, 1.0 * size / count) + return size, 1.0 * size / count + + +def __extract_file_name(file_name): + name_list = re.split(r"[/\.]", file_name) + short_file_name = "" + for name in name_list: + if name[:14] == "google_message": + short_file_name = name + return short_file_name + + +__results = [] + + +# CPP results example: +# [ +# "benchmarks": [ +# { +# "bytes_per_second": int, +# "cpu_time_ns": double, +# "iterations": int, +# "name: string, +# "real_time_ns: double, +# ... +# }, +# ... +# ], +# ... +# ] +def __parse_cpp_result(filename): + if filename == "": + return + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename + with open(filename, encoding="utf-8") as f: + results = json.loads(f.read()) + for benchmark in results["benchmarks"]: + data_filename = "".join( + re.split("(_parse_|_serialize)", benchmark["name"])[0]) + behavior = benchmark["name"][len(data_filename) + 1:] + if data_filename[:2] == "BM": + data_filename = data_filename[3:] + __results.append({ + "language": "cpp", + "dataFilename": data_filename, + "behavior": behavior, + "throughput": benchmark["bytes_per_second"] / 2.0 ** 20 + }) + + +# Synthetic benchmark results example: +# [ +# "benchmarks": [ +# { +# "cpu_time_ns": double, +# "iterations": int, +# "name: string, +# "real_time_ns: double, +# ... +# }, +# ... +# ], +# ... +# ] +def __parse_synthetic_result(filename): + if filename == "": + return + if filename[0] != "/": + filename = os.path.dirname(os.path.abspath(__file__)) + "/" + filename + with open(filename, encoding="utf-8") as f: + results = json.loads(f.read()) + for benchmark in results["benchmarks"]: + __results.append({ + "language": "cpp", + "dataFilename": "", + "behavior": "synthetic", + "throughput": 10.0**9 / benchmark["cpu_time_ns"] + }) + + +# Python results example: +# [ +# [ +# { +# "filename": string, +# "benchmarks": { +# behavior: results, +# ... +# }, +# }, +# ... +# ], #pure-python +# ... +# ] +def __parse_python_result(filename): + if filename == "": + return + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename + with open(filename, encoding="utf-8") as f: + results_list = json.loads(f.read()) + for results in results_list: + for result in results: + _, avg_size = __get_data_size(result["filename"]) + for behavior in result["benchmarks"]: + __results.append({ + "language": "python", + "dataFilename": __extract_file_name(result["filename"]), + "behavior": behavior, + "throughput": result["benchmarks"][behavior] + }) + + +# Java results example: +# [ +# { +# "id": string, +# "instrumentSpec": {...}, +# "measurements": [ +# { +# "weight": float, +# "value": { +# "magnitude": float, +# "unit": string +# }, +# ... +# }, +# ... +# ], +# "run": {...}, +# "scenario": { +# "benchmarkSpec": { +# "methodName": string, +# "parameters": { +# defined parameters in the benchmark: parameters value +# }, +# ... +# }, +# ... +# } +# +# }, +# ... +# ] +def __parse_java_result(filename): + if filename == "": + return + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename + with open(filename, encoding="utf-8") as f: + results = json.loads(f.read()) + for result in results: + total_weight = 0 + total_value = 0 + for measurement in result["measurements"]: + total_weight += measurement["weight"] + total_value += measurement["value"]["magnitude"] + avg_time = total_value * 1.0 / total_weight + total_size, _ = __get_data_size( + result["scenario"]["benchmarkSpec"]["parameters"]["dataFile"]) + __results.append({ + "language": "java", + "throughput": total_size / avg_time * 1e9 / 2 ** 20, + "behavior": result["scenario"]["benchmarkSpec"]["methodName"], + "dataFilename": __extract_file_name( + result["scenario"]["benchmarkSpec"]["parameters"]["dataFile"]) + }) + + +# Go benchmark results: +# +# goos: linux +# goarch: amd64 +# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Unmarshal-12 3000 705784 ns/op +# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Marshal-12 2000 634648 ns/op +# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Size-12 5000 244174 ns/op +# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Clone-12 300 4120954 ns/op +# Benchmark/.././datasets/google_message2/dataset.google_message2.pb/Merge-12 300 4108632 ns/op +# PASS +# ok _/usr/local/google/home/yilunchong/mygit/protobuf/benchmarks 124.173s +def __parse_go_result(filename): + if filename == "": + return + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename + with open(filename, encoding="utf-8") as f: + for line in f: + result_list = re.split(r"[\ \t]+", line) + if result_list[0][:9] != "Benchmark": + continue + first_slash_index = result_list[0].find('/') + last_slash_index = result_list[0].rfind('/') + full_filename = result_list[0][first_slash_index+1:last_slash_index] + total_bytes, _ = __get_data_size(full_filename) + behavior_with_suffix = result_list[0][last_slash_index+1:] + last_dash = behavior_with_suffix.rfind("-") + if last_dash == -1: + behavior = behavior_with_suffix + else: + behavior = behavior_with_suffix[:last_dash] + __results.append({ + "dataFilename": __extract_file_name(full_filename), + "throughput": total_bytes / float(result_list[2]) * 1e9 / 2 ** 20, + "behavior": behavior, + "language": "go" + }) + + +# Self built json results example: +# +# [ +# { +# "filename": string, +# "benchmarks": { +# behavior: results, +# ... +# }, +# }, +# ... +# ] +def __parse_custom_result(filename, language): + if filename == "": + return + if filename[0] != '/': + filename = os.path.dirname(os.path.abspath(__file__)) + '/' + filename + with open(filename, encoding="utf-8") as f: + results = json.loads(f.read()) + for result in results: + _, avg_size = __get_data_size(result["filename"]) + for behavior in result["benchmarks"]: + __results.append({ + "language": language, + "dataFilename": __extract_file_name(result["filename"]), + "behavior": behavior, + "throughput": result["benchmarks"][behavior] + }) + + +def __parse_js_result(filename, language): + return __parse_custom_result(filename, language) + +def __parse_php_result(filename, language): + return __parse_custom_result(filename, language) + + +def get_result_from_file(cpp_file="", + java_file="", + python_file="", + go_file="", + synthetic_file="", + node_file="", + php_c_file="", + php_file=""): + results = {} + if cpp_file != "": + __parse_cpp_result(cpp_file) + if java_file != "": + __parse_java_result(java_file) + if python_file != "": + __parse_python_result(python_file) + if go_file != "": + __parse_go_result(go_file) + if synthetic_file != "": + __parse_synthetic_result(synthetic_file) + if node_file != "": + __parse_js_result(node_file, "node") + if php_file != "": + __parse_php_result(php_file, "php") + if php_c_file != "": + __parse_php_result(php_c_file, "php") + + return __results + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "-cpp", + "--cpp_input_file", + help="The CPP benchmark result file's name", + default="") + parser.add_argument( + "-java", + "--java_input_file", + help="The Java benchmark result file's name", + default="") + parser.add_argument( + "-python", + "--python_input_file", + help="The Python benchmark result file's name", + default="") + parser.add_argument( + "-go", + "--go_input_file", + help="The golang benchmark result file's name", + default="") + parser.add_argument( + "-node", + "--node_input_file", + help="The node.js benchmark result file's name", + default="") + parser.add_argument( + "-php", + "--php_input_file", + help="The pure php benchmark result file's name", + default="") + parser.add_argument( + "-php_c", + "--php_c_input_file", + help="The php with c ext benchmark result file's name", + default="") + args = parser.parse_args() + + results = get_result_from_file( + cpp_file=args.cpp_input_file, + java_file=args.java_input_file, + python_file=args.python_input_file, + go_file=args.go_input_file, + node_file=args.node_input_file, + php_file=args.php_input_file, + php_c_file=args.php_c_input_file, + ) + print(json.dumps(results, indent=2)) diff --git a/libs/protobuf/benchmarks/util/result_uploader.py b/libs/protobuf/benchmarks/util/result_uploader.py new file mode 100644 index 0000000..2a35d96 --- /dev/null +++ b/libs/protobuf/benchmarks/util/result_uploader.py @@ -0,0 +1,107 @@ +from __future__ import print_function +from __future__ import absolute_import +import argparse +import os +import re +import copy +import uuid +import calendar +import time +import datetime + +from util import big_query_utils +from util import result_parser + +_PROJECT_ID = 'grpc-testing' +_DATASET = 'protobuf_benchmark_result' +_TABLE = 'opensource_result_v2' +_NOW = "%d%02d%02d" % (datetime.datetime.now().year, + datetime.datetime.now().month, + datetime.datetime.now().day) + +_INITIAL_TIME = calendar.timegm(time.gmtime()) + +def get_metadata(): + build_number = os.getenv('BUILD_NUMBER') + build_url = os.getenv('BUILD_URL') + job_name = os.getenv('JOB_NAME') + git_commit = os.getenv('GIT_COMMIT') + # actual commit is the actual head of PR that is getting tested + git_actual_commit = os.getenv('ghprbActualCommit') + + utc_timestamp = str(calendar.timegm(time.gmtime())) + metadata = {'created': utc_timestamp} + + if build_number: + metadata['buildNumber'] = build_number + if build_url: + metadata['buildUrl'] = build_url + if job_name: + metadata['jobName'] = job_name + if git_commit: + metadata['gitCommit'] = git_commit + if git_actual_commit: + metadata['gitActualCommit'] = git_actual_commit + + return metadata + + +def upload_result(result_list, metadata): + for result in result_list: + new_result = {} + new_result["metric"] = "throughput" + new_result["value"] = result["throughput"] + new_result["unit"] = "MB/s" + new_result["test"] = "protobuf_benchmark" + new_result["product_name"] = "protobuf" + labels_string = "" + for key in result: + labels_string += ",|%s:%s|" % (key, result[key]) + new_result["labels"] = labels_string[1:] + new_result["timestamp"] = _INITIAL_TIME + print(labels_string) + + bq = big_query_utils.create_big_query() + row = big_query_utils.make_row(str(uuid.uuid4()), new_result) + if not big_query_utils.insert_rows(bq, _PROJECT_ID, _DATASET, + _TABLE + "$" + _NOW, + [row]): + print('Error when uploading result', new_result) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("-cpp", "--cpp_input_file", + help="The CPP benchmark result file's name", + default="") + parser.add_argument("-java", "--java_input_file", + help="The Java benchmark result file's name", + default="") + parser.add_argument("-python", "--python_input_file", + help="The Python benchmark result file's name", + default="") + parser.add_argument("-go", "--go_input_file", + help="The golang benchmark result file's name", + default="") + parser.add_argument("-node", "--node_input_file", + help="The node.js benchmark result file's name", + default="") + parser.add_argument("-php", "--php_input_file", + help="The pure php benchmark result file's name", + default="") + parser.add_argument("-php_c", "--php_c_input_file", + help="The php with c ext benchmark result file's name", + default="") + args = parser.parse_args() + + metadata = get_metadata() + print("uploading results...") + upload_result(result_parser.get_result_from_file( + cpp_file=args.cpp_input_file, + java_file=args.java_input_file, + python_file=args.python_input_file, + go_file=args.go_input_file, + node_file=args.node_input_file, + php_file=args.php_input_file, + php_c_file=args.php_c_input_file, + ), metadata) diff --git a/libs/protobuf/benchmarks/util/schema_proto2_to_proto3_util.h b/libs/protobuf/benchmarks/util/schema_proto2_to_proto3_util.h new file mode 100644 index 0000000..0079f6f --- /dev/null +++ b/libs/protobuf/benchmarks/util/schema_proto2_to_proto3_util.h @@ -0,0 +1,194 @@ +#ifndef PROTOBUF_BENCHMARKS_UTIL_SCHEMA_PROTO2_TO_PROTO3_UTIL_H_ +#define PROTOBUF_BENCHMARKS_UTIL_SCHEMA_PROTO2_TO_PROTO3_UTIL_H_ + +#include "google/protobuf/message.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/descriptor.pb.h" + +#include +#include + +using google::protobuf::Descriptor; +using google::protobuf::DescriptorProto; +using google::protobuf::FileDescriptorProto; +using google::protobuf::FieldDescriptorProto; +using google::protobuf::Message; +using google::protobuf::EnumValueDescriptorProto; + +namespace google { +namespace protobuf { +namespace util { + +class SchemaGroupStripper { + + public: + static void StripFile(const FileDescriptor* old_file, + FileDescriptorProto *file) { + for (int i = file->mutable_message_type()->size() - 1; i >= 0; i--) { + if (IsMessageSet(old_file->message_type(i))) { + file->mutable_message_type()->DeleteSubrange(i, 1); + continue; + } + StripMessage(old_file->message_type(i), file->mutable_message_type(i)); + } + for (int i = file->mutable_extension()->size() - 1; i >= 0; i--) { + auto field = old_file->extension(i); + if (field->type() == FieldDescriptor::TYPE_GROUP || + IsMessageSet(field->message_type()) || + IsMessageSet(field->containing_type())) { + file->mutable_extension()->DeleteSubrange(i, 1); + } + } + } + + private: + static bool IsMessageSet(const Descriptor *descriptor) { + if (descriptor != nullptr + && descriptor->options().message_set_wire_format()) { + return true; + } + return false; + } + + static void StripMessage(const Descriptor *old_message, + DescriptorProto *new_message) { + for (int i = new_message->mutable_field()->size() - 1; i >= 0; i--) { + if (old_message->field(i)->type() == FieldDescriptor::TYPE_GROUP || + IsMessageSet(old_message->field(i)->message_type())) { + new_message->mutable_field()->DeleteSubrange(i, 1); + } + } + for (int i = new_message->mutable_extension()->size() - 1; i >= 0; i--) { + auto field_type_name = new_message->mutable_extension(i)->type_name(); + if (old_message->extension(i)->type() == FieldDescriptor::TYPE_GROUP || + IsMessageSet(old_message->extension(i)->containing_type()) || + IsMessageSet(old_message->extension(i)->message_type())) { + new_message->mutable_extension()->DeleteSubrange(i, 1); + } + } + for (int i = 0; i < new_message->mutable_nested_type()->size(); i++) { + StripMessage(old_message->nested_type(i), + new_message->mutable_nested_type(i)); + } + } + +}; + +class EnumScrubber { + + public: + EnumScrubber() + : total_added_(0) { + } + + void ScrubFile(FileDescriptorProto *file) { + for (int i = 0; i < file->enum_type_size(); i++) { + ScrubEnum(file->mutable_enum_type(i)); + } + for (int i = 0; i < file->mutable_message_type()->size(); i++) { + ScrubMessage(file->mutable_message_type(i)); + } + } + + private: + void ScrubEnum(EnumDescriptorProto *enum_type) { + if (enum_type->value(0).number() != 0) { + bool has_zero = false; + for (int j = 0; j < enum_type->value().size(); j++) { + if (enum_type->value(j).number() == 0) { + EnumValueDescriptorProto temp_enum_value; + temp_enum_value.CopyFrom(enum_type->value(j)); + enum_type->mutable_value(j)->CopyFrom(enum_type->value(0)); + enum_type->mutable_value(0)->CopyFrom(temp_enum_value); + has_zero = true; + break; + } + } + if (!has_zero) { + enum_type->mutable_value()->Add(); + for (int i = enum_type->mutable_value()->size() - 1; i > 0; i--) { + enum_type->mutable_value(i)->CopyFrom( + *enum_type->mutable_value(i - 1)); + } + enum_type->mutable_value(0)->set_number(0); + enum_type->mutable_value(0)->set_name("ADDED_ZERO_VALUE_" + + std::to_string(total_added_++)); + } + } + + } + + void ScrubMessage(DescriptorProto *message_type) { + for (int i = 0; i < message_type->mutable_enum_type()->size(); i++) { + ScrubEnum(message_type->mutable_enum_type(i)); + } + for (int i = 0; i < message_type->mutable_nested_type()->size(); i++) { + ScrubMessage(message_type->mutable_nested_type(i)); + } + } + + int total_added_; +}; + +class ExtensionStripper { + public: + static void StripFile(FileDescriptorProto *file) { + for (int i = 0; i < file->mutable_message_type()->size(); i++) { + StripMessage(file->mutable_message_type(i)); + } + file->mutable_extension()->Clear(); + } + private: + static void StripMessage(DescriptorProto *message_type) { + message_type->mutable_extension()->Clear(); + message_type->clear_extension_range(); + for (int i = 0; i < message_type->mutable_nested_type()->size(); i++) { + StripMessage(message_type->mutable_nested_type(i)); + } + } +}; + + +class FieldScrubber { + public: + static void ScrubFile(FileDescriptorProto *file) { + for (int i = 0; i < file->mutable_message_type()->size(); i++) { + ScrubMessage(file->mutable_message_type(i)); + } + for (int i = 0; i < file->mutable_extension()->size(); i++) { + file->mutable_extension(i)->clear_default_value(); + if (ShouldClearLabel(file->mutable_extension(i))) { + file->mutable_extension(i)->clear_label(); + } + } + } + private: + static bool ShouldClearLabel(const FieldDescriptorProto *field) { + return field->label() == FieldDescriptorProto::LABEL_REQUIRED; + } + + static void ScrubMessage(DescriptorProto *message_type) { + message_type->mutable_extension()->Clear(); + for (int i = 0; i < message_type->mutable_extension()->size(); i++) { + message_type->mutable_extension(i)->clear_default_value(); + if (ShouldClearLabel(message_type->mutable_extension(i))) { + message_type->mutable_extension(i)->clear_label(); + } + } + for (int i = 0; i < message_type->mutable_field()->size(); i++) { + message_type->mutable_field(i)->clear_default_value(); + if (ShouldClearLabel(message_type->mutable_field(i))) { + message_type->mutable_field(i)->clear_label(); + } + } + for (int i = 0; i < message_type->mutable_nested_type()->size(); i++) { + ScrubMessage(message_type->mutable_nested_type(i)); + } + } +}; + +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // PROTOBUF_BENCHMARKS_UTIL_SCHEMA_PROTO2_TO_PROTO3_UTIL_H_ diff --git a/libs/protobuf/build_defs/BUILD.bazel b/libs/protobuf/build_defs/BUILD.bazel index 4ac09c8..a5d831c 100644 --- a/libs/protobuf/build_defs/BUILD.bazel +++ b/libs/protobuf/build_defs/BUILD.bazel @@ -17,16 +17,6 @@ create_compiler_config_setting( value = "msvc-cl", ) -config_setting( - name = "aarch64", - values = {"cpu": "linux-aarch_64"}, -) - -config_setting( - name = "x86_64", - values = {"cpu": "linux-x86_64"}, -) - # Android NDK builds can specify different crosstool_top flags to choose which # STL they use for C++. We need these multiple variants to catch all of those # versions of crosstool_top and reliably detect Android. diff --git a/libs/protobuf/build_defs/arch_tests.bzl b/libs/protobuf/build_defs/arch_tests.bzl deleted file mode 100644 index 61fa00c..0000000 --- a/libs/protobuf/build_defs/arch_tests.bzl +++ /dev/null @@ -1,56 +0,0 @@ -"""Generated unittests to verify that a binary is built for the expected architecture.""" - -load("//build_defs:internal_shell.bzl", "inline_sh_test") - -def _arch_test_impl( - name, - platform, - file_platform, - bazel_binaries = [], - system_binaries = [], - **kwargs): - """Bazel rule to verify that a Bazel or system binary is built for the aarch64 architecture. - - Args: - name: the name of the test. - platform: a diagnostic name for this architecture. - file_platform: the expected output of `file`. - bazel_binaries: a set of binary targets to inspect. - system_binaries: a set of paths to system executables to inspect. - **kwargs: other keyword arguments that are passed to the test. - """ - - inline_sh_test( - name = name, - tools = bazel_binaries, - cmd = """ - for binary in "$(rootpaths %s) %s"; do - (file -L $$binary | grep -q "%s") \ - || (echo "Test binary is not an %s binary: "; file -L $$binary; exit 1) - done - """ % ( - " ".join(bazel_binaries), - " ".join(system_binaries), - file_platform, - platform, - ), - target_compatible_with = select({ - "//build_defs:" + platform: [], - "//conditions:default": ["@platforms//:incompatible"], - }), - **kwargs - ) - -def aarch64_test(**kwargs): - _arch_test_impl( - platform = "aarch64", - file_platform = "ELF 64-bit LSB executable, ARM aarch64", - **kwargs - ) - -def x86_64_test(**kwargs): - _arch_test_impl( - platform = "x86_64", - file_platform = "ELF 64-bit LSB executable, ARM x86_64", - **kwargs - ) diff --git a/libs/protobuf/build_defs/cpp_opts.bzl b/libs/protobuf/build_defs/cpp_opts.bzl index e0b031b..1d5594d 100644 --- a/libs/protobuf/build_defs/cpp_opts.bzl +++ b/libs/protobuf/build_defs/cpp_opts.bzl @@ -1,27 +1,27 @@ -"""C++ compile/link options for Protobuf libraries.""" +# C++ compile/link options for Protobuf. COPTS = select({ "//build_defs:config_msvc": [ - "/wd4065", # switch statement contains 'default' but no 'case' labels - "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data - "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' - "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data - "/wd4305", # 'identifier' : truncation from 'type1' to 'type2' - "/wd4307", # 'operator' : integral constant overflow - "/wd4309", # 'conversion' : truncation of constant value - "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) - "/wd4355", # 'this' : used in base member initializer list - "/wd4506", # no definition for inline function 'function' - "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning) - "/wd4996", # The compiler encountered a deprecated declaration. + "/wd4065", # switch statement contains 'default' but no 'case' labels + "/wd4244", # 'conversion' conversion from 'type1' to 'type2', possible loss of data + "/wd4251", # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' + "/wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data + "/wd4305", # 'identifier' : truncation from 'type1' to 'type2' + "/wd4307", # 'operator' : integral constant overflow + "/wd4309", # 'conversion' : truncation of constant value + "/wd4334", # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) + "/wd4355", # 'this' : used in base member initializer list + "/wd4506", # no definition for inline function 'function' + "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning) + "/wd4996", # The compiler encountered a deprecated declaration. ], "//conditions:default": [ "-DHAVE_ZLIB", "-Woverloaded-virtual", "-Wno-sign-compare", - "-Werror", ], }) + # Android and MSVC builds do not need to link in a separate pthread library. LINK_OPTS = select({ "//build_defs:config_android": [], diff --git a/libs/protobuf/build_defs/internal_shell.bzl b/libs/protobuf/build_defs/internal_shell.bzl deleted file mode 100644 index 670c4d5..0000000 --- a/libs/protobuf/build_defs/internal_shell.bzl +++ /dev/null @@ -1,93 +0,0 @@ -""" -Internal tools to migrate shell commands to Bazel as an intermediate step -to wider Bazelification. -""" - -def inline_sh_binary( - name, - srcs = [], - tools = [], - deps = [], - cmd = "", - testonly = None, - **kwargs): - """Bazel rule to wrap up an inline bash script in a binary. - - This is most useful as a stop-gap solution for migrating off Autotools. - These binaries are likely to be non-hermetic, with implicit system - dependencies. - - NOTE: the rule is only an internal workaround. The interface may change and - the rule may be removed when everything is properly "Bazelified". - - Args: - name: the name of the inline_sh_binary. - srcs: the files used directly by the script. - tools: the executable tools used directly by the script. Any target used - with rootpath/execpath/location must be declared here or in `srcs`. - deps: a list of dependency labels that are required to run this binary. - cmd: the inline sh command to run. - **kwargs: other keyword arguments that are passed to sh_binary. - testonly: common rule attribute (see: - https://bazel.build/reference/be/common-definitions#common-attributes) - """ - - native.genrule( - name = name + "_genrule", - srcs = srcs, - exec_tools = tools, - outs = [name + ".sh"], - cmd = "cat <<'EOF' >$(OUTS)\n#!/bin/bash -exu\n%s\nEOF\n" % cmd, - testonly = testonly, - visibility = ["//visibility:private"], - ) - - native.sh_binary( - name = name, - srcs = [name + "_genrule"], - data = srcs + tools + deps, - testonly = testonly, - **kwargs - ) - -def inline_sh_test( - name, - srcs = [], - tools = [], - deps = [], - cmd = "", - **kwargs): - """Bazel rule to wrap up an inline bash script in a test. - - This is most useful as a stop-gap solution for migrating off Autotools. - These tests are likely to be non-hermetic, with implicit system dependencies. - - NOTE: the rule is only an internal workaround. The interface may change and - the rule may be removed when everything is properly "Bazelified". - - Args: - name: the name of the inline_sh_binary. - srcs: the files used directly by the script. - tools: the executable tools used directly by the script. Any target used - with rootpath/execpath/location must be declared here or in `srcs`. - deps: a list of dependency labels that are required to run this binary. - cmd: the inline sh command to run. - **kwargs: other keyword arguments that are passed to sh_binary. - https://bazel.build/reference/be/common-definitions#common-attributes) - """ - - native.genrule( - name = name + "_genrule", - srcs = srcs, - exec_tools = tools, - outs = [name + ".sh"], - cmd = "cat <<'EOF' >$(OUTS)\n#!/bin/bash -exu\n%s\nEOF\n" % cmd, - visibility = ["//visibility:private"], - ) - - native.sh_test( - name = name, - srcs = [name + "_genrule"], - data = srcs + tools + deps, - **kwargs - ) diff --git a/libs/protobuf/build_files_updated_unittest.sh b/libs/protobuf/build_files_updated_unittest.sh new file mode 100755 index 0000000..87541c3 --- /dev/null +++ b/libs/protobuf/build_files_updated_unittest.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# This script verifies that BUILD files and cmake files are in sync with src/Makefile.am + +set -eo pipefail + +if [ "$(uname)" != "Linux" ]; then + echo "build_files_updated_unittest only supported on Linux. Skipping..." + exit 0 +fi + +# Keep in sync with files needed by update_file_lists.sh +generated_files=( + "BUILD" + "cmake/extract_includes.bat.in" + "cmake/libprotobuf-lite.cmake" + "cmake/libprotobuf.cmake" + "cmake/libprotoc.cmake" + "cmake/tests.cmake" + "src/Makefile.am" +) + +# If we're running in Bazel, use the Bazel-provided temp-dir. +if [ -n "${TEST_TMPDIR}" ]; then + # Env-var TEST_TMPDIR is set, assume that this is Bazel. + # Bazel may have opinions whether we are allowed to delete TEST_TMPDIR. + test_root="${TEST_TMPDIR}/build_files_updated_unittest" + mkdir "${test_root}" +else + # Seems like we're not executed by Bazel. + test_root=$(mktemp -d) +fi + +# From now on, fail if there are any unbound variables. +set -u + +# Remove artifacts after test is finished. +function cleanup { + rm -rf "${test_root}" +} +trap cleanup EXIT + +# Create golden dir and add snapshot of current state. +golden_dir="${test_root}/golden" +mkdir -p "${golden_dir}/cmake" "${golden_dir}/src" +for file in ${generated_files[@]}; do + cp "${file}" "${golden_dir}/${file}" +done + +# Create test dir, copy current state into it, and execute update script. +test_dir="${test_root}/test" +cp -R "${golden_dir}" "${test_dir}" + +cp "update_file_lists.sh" "${test_dir}/update_file_lists.sh" +chmod +x "${test_dir}/update_file_lists.sh" +cd "${test_root}/test" +bash "${test_dir}/update_file_lists.sh" + +# Test whether there are any differences +for file in ${generated_files[@]}; do + diff -du "${golden_dir}/${file}" "${test_dir}/${file}" +done diff --git a/libs/protobuf/cmake/README.md b/libs/protobuf/cmake/README.md index 396d495..ce3e680 100644 --- a/libs/protobuf/cmake/README.md +++ b/libs/protobuf/cmake/README.md @@ -1,21 +1,15 @@ -This directory contains *CMake* files that can be used to build protobuf. +This directory contains *CMake* files that can be used to build protobuf +with *MSVC* on *Windows*. You can build the project from *Command Prompt* +and using an *Visual Studio* IDE. -You need to have [CMake](http://www.cmake.org) and -[Git](http://git-scm.com) installed on your computer before proceeding. We -currently support CMake 3.5 and newer on both [Windows](#windows-builds) and -[Linux](#linux-builds). +You need to have [CMake](http://www.cmake.org), [Visual Studio](https://www.visualstudio.com) +and optionally [Git](http://git-scm.com) installed on your computer before proceeding. -Most of the instructions will be given using CMake's command-line interface, but -the same actions can be performed using appropriate GUI tools. +Most of the instructions will be given to the *Сommand Prompt*, but the same +actions can be performed using appropriate GUI tools. -# Windows Builds - -On Windows, you can build the project from *Command Prompt* and using an -*Visual Studio* IDE. You will also need to have -[Visual Studio](https://www.visualstudio.com) installed on your computer before -proceeding. - -## Environment Setup +Environment Setup +================= Open the appropriate *Command Prompt* from the *Start* menu. @@ -48,7 +42,8 @@ Optionally, you will want to download [ninja](https://ninja-build.org/) and add Good. Now you are ready to continue. -## Getting Sources +Getting Sources +=============== You can get the latest stable source packages from the release page: @@ -81,7 +76,8 @@ C:\Path\to\src\protobuf> git submodule update --init --recursive Good. Now you are ready for *CMake* configuration. -## CMake Configuration +CMake Configuration +=================== *CMake* supports a lot of different [generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html) @@ -89,6 +85,9 @@ for various native build systems. Of most interest to Windows programmers are the following: +* [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators). + This generates NMake Makefiles for Visual Studio. These work, but they are rather slow. + * [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) This generates a Visual Studio solution for the project. @@ -109,6 +108,16 @@ Create a temporary *build* folder and change your working directory to it: The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build a separate folder for each configuration. +To start using a *Release* configuration via the *NMmake* generator: + + C:\Path\to\build\protobuf>mkdir release & cd release + C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ + C:\Path\to\src\protobuf + +It will generate a *NMake* *Makefile* in the current directory. + To use *Debug* configuration using *Ninja*: C:\Path\to\build\protobuf>mkdir debug & cd debug @@ -128,7 +137,8 @@ The *Visual Studio* generator is multi-configuration: it will generate a single It will generate *Visual Studio* solution file *protobuf.sln* in current directory. -### Unit Tests +Unit Tests +---------- Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test). @@ -168,7 +178,8 @@ For example: -Dprotobuf_BUILD_TESTS=OFF ^ C:\Path\to\src\protobuf -## Compiling +Compiling +========= The standard way to compile a *CMake* project is `cmake --build `. @@ -179,6 +190,10 @@ Note that if your generator supports multiple configurations, you will probably You can also run directly the build tool you've configured: + C:\Path\to\build\protobuf\release>nmake + +or + C:\Path\to\build\protobuf\debug>ninja And wait for the compilation to finish. @@ -191,7 +206,8 @@ If you prefer to use the IDE: And wait for the compilation to finish. -## Testing +Testing +======= To run unit-tests, first you must compile protobuf as described above. Then run: @@ -243,7 +259,8 @@ Note that the tests must be run from the source folder. If all tests are passed, safely continue. -## Installing +Installing +========== To install protobuf to the *install* folder you've specified in the configuration step, you need to build the `install` target: @@ -251,6 +268,10 @@ To install protobuf to the *install* folder you've specified in the configuratio Or if you prefer: + C:\Path\to\build\protobuf\release>nmake install + +or + C:\Path\to\build\protobuf\debug>ninja install You can also build project *INSTALL* from Visual Studio solution. @@ -271,7 +292,8 @@ compiling a debug build of your application, you may need to link against a debug build of libprotobufd.lib with "d" postfix. Similarly, release builds should link against release libprotobuf.lib library. -## DLLs vs. static linking +DLLs vs. static linking +======================= Static linking is now the default for the Protocol Buffer libraries. Due to issues with Win32's use of a separate heap for each DLL, as well as binary @@ -296,7 +318,8 @@ recommend that you do NOT expose protocol buffer objects in your library's public interface, and that you statically link protocol buffers into your library. -## ZLib support +ZLib support +============ If you want to include GzipInputStream and GzipOutputStream (google/protobuf/io/gzip_stream.h) in libprotobuf, you will need to do a few @@ -346,7 +369,8 @@ If you already have ZLIB library and headers at some other location on your syst Build and testing protobuf as usual. -## Notes on Compiler Warnings +Notes on Compiler Warnings +========================== The following warnings have been disabled while building the protobuf libraries and compiler. You may have to disable some of them in your own project as @@ -373,23 +397,3 @@ unique, so there should be no problem with this, but MSVC prints warning nevertheless. So, we disable it. Unfortunately, this warning will also be produced when compiling code which merely uses protocol buffers, meaning you may have to disable it in your code too. - -# Linux Builds - -Building with CMake works very similarly on Linux. Instead of Visual Studio, -you will need to have gcc or clang installed to handle the C++ builds. CMake -will generate Makefiles by default, but can also be configured to use Ninja. To -build Protobuf, you will need to run (from the source directory): - - cmake . - cmake --build . --parallel 10 - -Protobuf can be tested and installed with CMake: - - ctest --verbose - sudo cmake --install . - -or directly with the generated Makefiles: - - make VERBOSE=1 test - sudo make install diff --git a/libs/protobuf/cmake/abseil-cpp.cmake b/libs/protobuf/cmake/abseil-cpp.cmake deleted file mode 100644 index c1c4c16..0000000 --- a/libs/protobuf/cmake/abseil-cpp.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# Setup our dependency on Abseil. - -set(ABSL_PROPAGATE_CXX_STD ON) - -if(TARGET absl::strings) - # If Abseil is included already, skip including it. - # (https://github.com/protocolbuffers/protobuf/issues/10435) -elseif(protobuf_ABSL_PROVIDER STREQUAL "module") - if(NOT ABSL_ROOT_DIR) - set(ABSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp) - endif() - if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt") - if(protobuf_INSTALL) - # When protobuf_INSTALL is enabled and Abseil will be built as a module, - # Abseil will be installed along with protobuf for convenience. - set(ABSL_ENABLE_INSTALL ON) - endif() - add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp) - else() - message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong") - endif() - if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE) - message(WARNING "protobuf_INSTALL will be forced to FALSE because protobuf_ABSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.") - set(protobuf_INSTALL FALSE) - endif() -elseif(protobuf_ABSL_PROVIDER STREQUAL "package") - # Use "CONFIG" as there is no built-in cmake module for absl. - find_package(absl REQUIRED CONFIG) -endif() -set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()") - -set(protobuf_ABSL_USED_TARGETS - absl::algorithm - absl::base - absl::bind_front - absl::bits - absl::cleanup - absl::cord - absl::core_headers - absl::debugging - absl::dynamic_annotations - absl::flags - absl::flat_hash_map - absl::flat_hash_set - absl::function_ref - absl::hash - absl::layout - absl::memory - absl::optional - absl::span - absl::status - absl::statusor - absl::strings - absl::synchronization - absl::time - absl::utility - absl::variant -) diff --git a/libs/protobuf/cmake/conformance.cmake b/libs/protobuf/cmake/conformance.cmake index 801d722..d6c435a 100644 --- a/libs/protobuf/cmake/conformance.cmake +++ b/libs/protobuf/cmake/conformance.cmake @@ -1,18 +1,6 @@ -if (NOT EXISTS "${protobuf_SOURCE_DIR}/third_party/jsoncpp/CMakeLists.txt") - message(FATAL_ERROR - "Cannot find third_party/jsoncpp directory that's needed to " - "build conformance tests. If you use git, make sure you have cloned " - "submodules:\n" - " git submodule update --init --recursive\n" - "If instead you want to skip them, run cmake with:\n" - " cmake -Dprotobuf_BUILD_CONFORMANCE=OFF\n") -endif() - add_custom_command( - OUTPUT - ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h - ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc + OUTPUT ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc DEPENDS ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto COMMAND ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/conformance/conformance.proto --proto_path=${protobuf_SOURCE_DIR}/conformance @@ -20,11 +8,8 @@ add_custom_command( ) add_custom_command( - OUTPUT - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc + OUTPUT ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc DEPENDS ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.proto COMMAND ${protobuf_PROTOC_EXE} ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.proto @@ -36,54 +21,29 @@ add_custom_command( add_executable(conformance_test_runner ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.cc ${protobuf_SOURCE_DIR}/conformance/binary_json_conformance_suite.h - ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc ${protobuf_SOURCE_DIR}/conformance/conformance_test.cc ${protobuf_SOURCE_DIR}/conformance/conformance_test_runner.cc - ${protobuf_SOURCE_DIR}/conformance/conformance_test_main.cc - ${protobuf_SOURCE_DIR}/conformance/text_format_conformance_suite.cc - ${protobuf_SOURCE_DIR}/conformance/text_format_conformance_suite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h + ${protobuf_SOURCE_DIR}/conformance/third_party/jsoncpp/json.h + ${protobuf_SOURCE_DIR}/conformance/third_party/jsoncpp/jsoncpp.cpp ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc ) add_executable(conformance_cpp - ${protobuf_SOURCE_DIR}/conformance/conformance.pb.h ${protobuf_SOURCE_DIR}/conformance/conformance.pb.cc ${protobuf_SOURCE_DIR}/conformance/conformance_cpp.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto2.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_messages_proto3.pb.cc ) target_include_directories( conformance_test_runner - PUBLIC ${protobuf_SOURCE_DIR} ${protobuf_SOURCE_DIR}/conformance) + PUBLIC ${protobuf_SOURCE_DIR}/conformance) target_include_directories( conformance_cpp - PUBLIC ${protobuf_SOURCE_DIR}) + PUBLIC ${protobuf_SOURCE_DIR}/conformance) -target_include_directories(conformance_test_runner PRIVATE ${ABSL_ROOT_DIR}) -target_include_directories(conformance_cpp PRIVATE ${ABSL_ROOT_DIR}) - -target_link_libraries(conformance_test_runner ${protobuf_LIB_PROTOBUF}) -target_link_libraries(conformance_test_runner ${protobuf_ABSL_USED_TARGETS}) -target_link_libraries(conformance_cpp ${protobuf_LIB_PROTOBUF}) -target_link_libraries(conformance_cpp ${protobuf_ABSL_USED_TARGETS}) - -add_test(NAME conformance_cpp_test - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/conformance_test_runner - --failure_list ${protobuf_SOURCE_DIR}/conformance/failure_list_cpp.txt - --text_format_failure_list ${protobuf_SOURCE_DIR}/conformance/text_format_failure_list_cpp.txt - --output_dir ${protobuf_TEST_XML_OUTDIR} - ${CMAKE_CURRENT_BINARY_DIR}/conformance_cpp - DEPENDS conformance_test_runner conformance_cpp) - -set(JSONCPP_WITH_TESTS OFF CACHE BOOL "Disable tests") -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/jsoncpp third_party/jsoncpp) -target_include_directories(conformance_test_runner PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/jsoncpp/include) -target_link_libraries(conformance_test_runner jsoncpp_lib) +target_link_libraries(conformance_test_runner libprotobuf) +target_link_libraries(conformance_cpp libprotobuf) diff --git a/libs/protobuf/cmake/examples.cmake b/libs/protobuf/cmake/examples.cmake index 07cfad2..3b83d2b 100644 --- a/libs/protobuf/cmake/examples.cmake +++ b/libs/protobuf/cmake/examples.cmake @@ -30,7 +30,7 @@ endfunction() # Add examples as an external project. # sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets. add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}") -add_dependencies(examples ${protobuf_LIB_PROTOBUF} ${protobuf_PROTOC_EXE}) +add_dependencies(examples libprotobuf protoc) option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF) mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST) @@ -42,7 +42,7 @@ if(protobuf_BUILD_EXAMPLES_MULTITEST) "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}" "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE" ) - add_dependencies(examples-legacy ${protobuf_LIB_PROTOBUF} ${protobuf_PROTOC_EXE}) + add_dependencies(examples-legacy libprotobuf protoc) #Build using the installed library. add_examples_build(examples-installed diff --git a/libs/protobuf/cmake/extract_includes.bat.in b/libs/protobuf/cmake/extract_includes.bat.in new file mode 100644 index 0000000..1292829 --- /dev/null +++ b/libs/protobuf/cmake/extract_includes.bat.in @@ -0,0 +1,144 @@ +mkdir include +mkdir include\google +mkdir include\google\protobuf +mkdir include\google\protobuf\compiler +mkdir include\google\protobuf\compiler\cpp +mkdir include\google\protobuf\compiler\csharp +mkdir include\google\protobuf\compiler\java +mkdir include\google\protobuf\compiler\objectivec +mkdir include\google\protobuf\compiler\php +mkdir include\google\protobuf\compiler\python +mkdir include\google\protobuf\compiler\ruby +mkdir include\google\protobuf\io +mkdir include\google\protobuf\stubs +mkdir include\google\protobuf\util +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.h" include\google\protobuf\any.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.pb.h" include\google\protobuf\any.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.pb.h" include\google\protobuf\api.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena.h" include\google\protobuf\arena.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena_impl.h" include\google\protobuf\arena_impl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenastring.h" include\google\protobuf\arenastring.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenaz_sampler.h" include\google\protobuf\arenaz_sampler.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h" include\google\protobuf\compiler\code_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h" include\google\protobuf\compiler\command_line_interface.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\file.h" include\google\protobuf\compiler\cpp\file.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h" include\google\protobuf\compiler\cpp\cpp_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\generator.h" include\google\protobuf\compiler\cpp\generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\helpers.h" include\google\protobuf\compiler\cpp\helpers.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\names.h" include\google\protobuf\compiler\cpp\names.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_doc_comment.h" include\google\protobuf\compiler\csharp\csharp_doc_comment.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h" include\google\protobuf\compiler\csharp\csharp_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h" include\google\protobuf\compiler\csharp\csharp_names.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_options.h" include\google\protobuf\compiler\csharp\csharp_options.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h" include\google\protobuf\compiler\importer.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\generator.h" include\google\protobuf\compiler\java\generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h" include\google\protobuf\compiler\java\java_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\kotlin_generator.h" include\google\protobuf\compiler\java\kotlin_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\names.h" include\google\protobuf\compiler\java\names.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h" include\google\protobuf\compiler\objectivec\objectivec_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_helpers.h" include\google\protobuf\compiler\objectivec\objectivec_helpers.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h" include\google\protobuf\compiler\parser.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\php\php_generator.h" include\google\protobuf\compiler\php\php_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h" include\google\protobuf\compiler\plugin.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h" include\google\protobuf\compiler\plugin.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\generator.h" include\google\protobuf\compiler\python\generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\pyi_generator.h" include\google\protobuf\compiler\python\pyi_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h" include\google\protobuf\compiler\python\python_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h" include\google\protobuf\compiler\ruby\ruby_generator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h" include\google\protobuf\descriptor.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h" include\google\protobuf\descriptor.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor_database.h" include\google\protobuf\descriptor_database.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.pb.h" include\google\protobuf\duration.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\dynamic_message.h" include\google\protobuf\dynamic_message.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.pb.h" include\google\protobuf\empty.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\endian.h" include\google\protobuf\endian.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\explicitly_constructed.h" include\google\protobuf\explicitly_constructed.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set.h" include\google\protobuf\extension_set.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set_inl.h" include\google\protobuf\extension_set_inl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_access_listener.h" include\google\protobuf\field_access_listener.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h" include\google\protobuf\field_mask.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h" include\google\protobuf\generated_enum_reflection.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h" include\google\protobuf\generated_enum_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_bases.h" include\google\protobuf\generated_message_bases.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h" include\google\protobuf\generated_message_reflection.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_tctable_decl.h" include\google\protobuf\generated_message_tctable_decl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_tctable_impl.h" include\google\protobuf\generated_message_tctable_impl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h" include\google\protobuf\generated_message_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\has_bits.h" include\google\protobuf\has_bits.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\implicit_weak_message.h" include\google\protobuf\implicit_weak_message.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\inlined_string_field.h" include\google\protobuf\inlined_string_field.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\coded_stream.h" include\google\protobuf\io\coded_stream.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\gzip_stream.h" include\google\protobuf\io\gzip_stream.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\io_win32.h" include\google\protobuf\io\io_win32.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\printer.h" include\google\protobuf\io\printer.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\strtod.h" include\google\protobuf\io\strtod.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\tokenizer.h" include\google\protobuf\io\tokenizer.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream.h" include\google\protobuf\io\zero_copy_stream.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl.h" include\google\protobuf\io\zero_copy_stream_impl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl_lite.h" include\google\protobuf\io\zero_copy_stream_impl_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map.h" include\google\protobuf\map.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry.h" include\google\protobuf\map_entry.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry_lite.h" include\google\protobuf\map_entry_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field.h" include\google\protobuf\map_field.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_inl.h" include\google\protobuf\map_field_inl.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_lite.h" include\google\protobuf\map_field_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h" include\google\protobuf\map_type_handler.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\google\protobuf\message.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata_lite.h" include\google\protobuf\metadata_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\parse_context.h" include\google\protobuf\parse_context.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port.h" include\google\protobuf\port.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_def.inc" include\google\protobuf\port_def.inc +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\port_undef.inc" include\google\protobuf\port_undef.inc +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h" include\google\protobuf\reflection.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h" include\google\protobuf\reflection_ops.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h" include\google\protobuf\repeated_field.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_ptr_field.h" include\google\protobuf\repeated_ptr_field.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h" include\google\protobuf\service.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h" include\google\protobuf\source_context.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h" include\google\protobuf\struct.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\bytestream.h" include\google\protobuf\stubs\bytestream.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\callback.h" include\google\protobuf\stubs\callback.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h" include\google\protobuf\stubs\casts.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h" include\google\protobuf\stubs\common.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h" include\google\protobuf\stubs\hash.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\logging.h" include\google\protobuf\stubs\logging.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\macros.h" include\google\protobuf\stubs\macros.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\map_util.h" include\google\protobuf\stubs\map_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\mutex.h" include\google\protobuf\stubs\mutex.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h" include\google\protobuf\stubs\once.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h" include\google\protobuf\stubs\platform_macros.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\port.h" include\google\protobuf\stubs\port.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h" include\google\protobuf\stubs\status.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h" include\google\protobuf\stubs\stl_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h" include\google\protobuf\stubs\stringpiece.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\strutil.h" include\google\protobuf\stubs\strutil.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h" include\google\protobuf\stubs\template_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" include\google\protobuf\text_format.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h" include\google\protobuf\timestamp.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h" include\google\protobuf\type.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h" include\google\protobuf\unknown_field_set.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\delimited_message_util.h" include\google\protobuf\util\delimited_message_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_comparator.h" include\google\protobuf\util\field_comparator.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_mask_util.h" include\google\protobuf\util\field_mask_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\json_util.h" include\google\protobuf\util\json_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\message_differencer.h" include\google\protobuf\util\message_differencer.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\time_util.h" include\google\protobuf\util\time_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver.h" include\google\protobuf\util\type_resolver.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver_util.h" include\google\protobuf\util\type_resolver_util.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format.h" include\google\protobuf\wire_format.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite.h" include\google\protobuf\wire_format_lite.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.pb.h" include\google\protobuf\wrappers.pb.h +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.proto" include\google\protobuf\any.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.proto" include\google\protobuf\api.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.proto" include\google\protobuf\compiler\plugin.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.proto" include\google\protobuf\descriptor.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.proto" include\google\protobuf\duration.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.proto" include\google\protobuf\empty.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.proto" include\google\protobuf\field_mask.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.proto" include\google\protobuf\source_context.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.proto" include\google\protobuf\struct.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.proto" include\google\protobuf\timestamp.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.proto" include\google\protobuf\type.proto +copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.proto" include\google\protobuf\wrappers.proto diff --git a/libs/protobuf/cmake/install.cmake b/libs/protobuf/cmake/install.cmake index 90230c5..825cb25 100644 --- a/libs/protobuf/cmake/install.cmake +++ b/libs/protobuf/cmake/install.cmake @@ -43,65 +43,106 @@ endif (protobuf_BUILD_PROTOC_BINARIES) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/protobuf.pc ${CMAKE_CURRENT_BINARY_DIR}/protobuf-lite.pc DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) -set(protobuf_HEADERS - ${libprotobuf_hdrs} - ${libprotoc_hdrs} - ${wkt_protos_files} - ${descriptor_proto_proto_srcs} - ${plugin_proto_proto_srcs} -) -foreach(_header ${protobuf_HEADERS}) - string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _header ${_header}) +file(STRINGS ${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in _extract_strings + REGEX "^copy") +foreach(_extract_string ${_extract_strings}) + string(REGEX REPLACE "^.* .+ include\\\\(.+)$" "\\1" + _header ${_extract_string}) + string(REPLACE "\\" "/" _header ${_header}) get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/src/${_header}" ABSOLUTE) get_filename_component(_extract_name ${_header} NAME) get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" DIRECTORY) - install(FILES "${_extract_from}" - DESTINATION "${_extract_to}" - COMPONENT protobuf-headers - RENAME "${_extract_name}") + if(EXISTS "${_extract_from}") + install(FILES "${_extract_from}" + DESTINATION "${_extract_to}" + COMPONENT protobuf-headers + RENAME "${_extract_name}") + else() + message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in " + "\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" " + "but there not exists. The file will not be installed.") + endif() +endforeach() + +# Internal function for parsing auto tools scripts +function(_protobuf_auto_list FILE_NAME VARIABLE) + file(STRINGS ${FILE_NAME} _strings) + set(_list) + foreach(_string ${_strings}) + set(_found) + string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}") + if(_found) + string(LENGTH "${_found}" _length) + string(SUBSTRING "${_string}" ${_length} -1 _draft_list) + foreach(_item ${_draft_list}) + string(STRIP "${_item}" _item) + list(APPEND _list "${_item}") + endforeach() + endif() + endforeach() + set(${VARIABLE} ${_list} PARENT_SCOPE) +endfunction() + +# Install well-known type proto files +_protobuf_auto_list("${protobuf_SOURCE_DIR}/src/Makefile.am" nobase_dist_proto_DATA) +foreach(_file ${nobase_dist_proto_DATA}) + get_filename_component(_file_from "${protobuf_SOURCE_DIR}/src/${_file}" ABSOLUTE) + get_filename_component(_file_name ${_file} NAME) + get_filename_component(_dir ${_file} DIRECTORY) + if(EXISTS "${_file_from}") + install(FILES "${_file_from}" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_dir}" + COMPONENT protobuf-protos + RENAME "${_file_name}") + else() + message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in " + "\"${protobuf_SOURCE_DIR}/src/Makefile.am\" as nobase_dist_proto_DATA " + "but there not exists. The file will not be installed.") + endif() endforeach() # Install configuration -set(_install_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") -set(_build_cmakedir_desc "Directory relative to CMAKE_CURRENT_BINARY_DIR for cmake configuration files") +set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files") set(_exampledir_desc "Directory relative to CMAKE_INSTALL_DATA to install examples") -set(_protobuf_subdir_desc "Subdirectory in which to install cmake configuration files") if(NOT MSVC) - set(protobuf_CMAKE_SUBDIR "cmake/protobuf" CACHE STRING "${_protobuf_subdir_desc}") - set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_install_cmakedir_desc}") + set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}") set(CMAKE_INSTALL_EXAMPLEDIR "${CMAKE_INSTALL_DATADIR}/protobuf/examples" CACHE STRING "${_exampledir_desc}") else() - set(protobuf_CMAKE_SUBDIR "cmake" CACHE STRING "${_protobuf_subdir_desc}") set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}") set(CMAKE_INSTALL_EXAMPLEDIR "examples" CACHE STRING "${_exampledir_desc}") endif() -set(CMAKE_BUILD_CMAKEDIR "${CMAKE_CURRENT_BINARY_DIR}/${protobuf_CMAKE_SUBDIR}" CACHE STRING "${_build_cmakedir_desc}") -mark_as_advanced(protobuf_CMAKE_SUBDIR) -mark_as_advanced(CMAKE_BUILD_CMAKEDIR) mark_as_advanced(CMAKE_INSTALL_CMAKEDIR) mark_as_advanced(CMAKE_INSTALL_EXAMPLEDIR) configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config.cmake.in - ${CMAKE_BUILD_CMAKEDIR}/protobuf-config.cmake @ONLY) + ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY) configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-config-version.cmake.in - ${CMAKE_BUILD_CMAKEDIR}/protobuf-config-version.cmake @ONLY) + ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY) configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-module.cmake.in - ${CMAKE_BUILD_CMAKEDIR}/protobuf-module.cmake @ONLY) + ${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY) configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-options.cmake - ${CMAKE_BUILD_CMAKEDIR}/protobuf-options.cmake @ONLY) -configure_file(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake - ${CMAKE_BUILD_CMAKEDIR}/protobuf-generate.cmake @ONLY) + ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY) # Allows the build directory to be used as a find directory. +if (protobuf_BUILD_PROTOC_BINARIES) + export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc + NAMESPACE protobuf:: + FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake + ) +else (protobuf_BUILD_PROTOC_BINARIES) + export(TARGETS libprotobuf-lite libprotobuf + NAMESPACE protobuf:: + FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake + ) +endif (protobuf_BUILD_PROTOC_BINARIES) + install(EXPORT protobuf-targets DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" NAMESPACE protobuf:: - COMPONENT protobuf-export -) + COMPONENT protobuf-export) -install(DIRECTORY ${CMAKE_BUILD_CMAKEDIR}/ +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" COMPONENT protobuf-export PATTERN protobuf-targets.cmake EXCLUDE diff --git a/libs/protobuf/cmake/libprotobuf-lite.cmake b/libs/protobuf/cmake/libprotobuf-lite.cmake index 0dc8457..83e9703 100644 --- a/libs/protobuf/cmake/libprotobuf-lite.cmake +++ b/libs/protobuf/cmake/libprotobuf-lite.cmake @@ -1,11 +1,93 @@ -# CMake definitions for libprotobuf_lite (the "lite" C++ protobuf runtime). +set(libprotobuf_lite_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/strtod.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc +) -include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) +set(libprotobuf_lite_includes + ${protobuf_SOURCE_DIR}/src/google/protobuf/any.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_inl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_decl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_impl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/has_bits.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/strtod.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_type_handler.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata_lite.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/port.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/casts.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/hash.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/macros.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/map_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mutex.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/once.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stl_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/template_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h +) add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC} - ${libprotobuf_lite_srcs} - ${libprotobuf_lite_hdrs} - ${protobuf_version_rc_file}) + ${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${protobuf_version_rc_file}) if(protobuf_HAVE_LD_VERSION_SCRIPT) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) target_link_options(libprotobuf-lite PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf-lite.map) @@ -23,7 +105,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") target_link_libraries(libprotobuf-lite PRIVATE log) endif() target_include_directories(libprotobuf-lite PUBLIC ${protobuf_SOURCE_DIR}/src) -target_link_libraries(libprotobuf-lite PUBLIC ${protobuf_ABSL_USED_TARGETS}) if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotobuf-lite PUBLIC PROTOBUF_USE_DLLS @@ -31,6 +112,7 @@ if(protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf-lite PROPERTIES VERSION ${protobuf_VERSION} + SOVERSION 32 OUTPUT_NAME ${LIB_PREFIX}protobuf-lite DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotobuf-lite ALIAS libprotobuf-lite) diff --git a/libs/protobuf/cmake/libprotobuf.cmake b/libs/protobuf/cmake/libprotobuf.cmake index 19d6030..07e4bcf 100644 --- a/libs/protobuf/cmake/libprotobuf.cmake +++ b/libs/protobuf/cmake/libprotobuf.cmake @@ -1,11 +1,106 @@ -# CMake definitions for libprotobuf (the "full" C++ protobuf runtime). +set(libprotobuf_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/any.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_heavy.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_full.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/gzip_stream.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/service.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/substitute.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/datapiece.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/default_value_objectwriter.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/error_listener.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/field_mask_utility.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/json_escaping.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/json_objectwriter.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/json_stream_parser.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/object_writer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/proto_writer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/protostream_objectsource.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/protostream_objectwriter.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/type_info.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/utility.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.cc +) -include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) +set(libprotobuf_includes + ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/field_access_listener.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_reflection.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/gzip_stream.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_inl.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/message.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_internal.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/service.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h +) add_library(libprotobuf ${protobuf_SHARED_OR_STATIC} - ${libprotobuf_srcs} - ${libprotobuf_hdrs} - ${protobuf_version_rc_file}) + ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${protobuf_version_rc_file}) if(protobuf_HAVE_LD_VERSION_SCRIPT) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) target_link_options(libprotobuf PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotobuf.map) @@ -26,7 +121,6 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android") target_link_libraries(libprotobuf PRIVATE log) endif() target_include_directories(libprotobuf PUBLIC ${protobuf_SOURCE_DIR}/src) -target_link_libraries(libprotobuf PUBLIC ${protobuf_ABSL_USED_TARGETS}) if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotobuf PUBLIC PROTOBUF_USE_DLLS @@ -34,6 +128,7 @@ if(protobuf_BUILD_SHARED_LIBS) endif() set_target_properties(libprotobuf PROPERTIES VERSION ${protobuf_VERSION} + SOVERSION 32 OUTPUT_NAME ${LIB_PREFIX}protobuf DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotobuf ALIAS libprotobuf) diff --git a/libs/protobuf/cmake/libprotoc.cmake b/libs/protobuf/cmake/libprotoc.cmake index 3be0df3..15a47e5 100644 --- a/libs/protobuf/cmake/libprotoc.cmake +++ b/libs/protobuf/cmake/libprotoc.cmake @@ -1,11 +1,117 @@ -# CMake definitions for libprotoc (the protobuf compiler library). +set(libprotoc_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/code_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/extension.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/helpers.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/map_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/padding_optimizer.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/parse_function_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/primitive_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/service.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/string_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_field_base.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_helpers.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_map_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_factory.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/helpers.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_extension.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/helpers.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/pyi_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/subprocess.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/zip_writer.cc +) -include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) +set(libprotoc_headers + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/code_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/cpp_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/file.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/helpers.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/names.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_doc_comment.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_names.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_options.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/java_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_helpers.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/pyi_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/python_generator.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.h +) add_library(libprotoc ${protobuf_SHARED_OR_STATIC} - ${libprotoc_srcs} - ${libprotoc_hdrs} - ${protobuf_version_rc_file}) + ${libprotoc_files} ${libprotoc_headers} ${protobuf_version_rc_file}) if(protobuf_HAVE_LD_VERSION_SCRIPT) if(${CMAKE_VERSION} VERSION_GREATER 3.13 OR ${CMAKE_VERSION} VERSION_EQUAL 3.13) target_link_options(libprotoc PRIVATE -Wl,--version-script=${protobuf_SOURCE_DIR}/src/libprotoc.map) @@ -16,7 +122,6 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT) LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map) endif() target_link_libraries(libprotoc PRIVATE libprotobuf) -target_link_libraries(libprotoc PUBLIC ${protobuf_ABSL_USED_TARGETS}) if(protobuf_BUILD_SHARED_LIBS) target_compile_definitions(libprotoc PUBLIC PROTOBUF_USE_DLLS @@ -25,6 +130,7 @@ endif() set_target_properties(libprotoc PROPERTIES COMPILE_DEFINITIONS LIBPROTOC_EXPORTS VERSION ${protobuf_VERSION} + SOVERSION 32 OUTPUT_NAME ${LIB_PREFIX}protoc DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}") add_library(protobuf::libprotoc ALIAS libprotoc) diff --git a/libs/protobuf/cmake/protobuf-config.cmake.in b/libs/protobuf/cmake/protobuf-config.cmake.in index 1a8d243..6166911 100644 --- a/libs/protobuf/cmake/protobuf-config.cmake.in +++ b/libs/protobuf/cmake/protobuf-config.cmake.in @@ -3,13 +3,165 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") # Depend packages @_protobuf_FIND_ZLIB@ -@_protobuf_FIND_ABSL@ # Imported targets include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") -# protobuf-generate function -include("${CMAKE_CURRENT_LIST_DIR}/protobuf-generate.cmake") +function(protobuf_generate) + include(CMakeParseArguments) + + set(_options APPEND_PATH) + set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS) + if(COMMAND target_sources) + list(APPEND _singleargs TARGET) + endif() + set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS PROTOC_OPTIONS) + + cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") + + if(NOT protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET) + message(SEND_ERROR "Error: protobuf_generate called without any targets or source files") + return() + endif() + + if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET) + message(SEND_ERROR "Error: protobuf_generate called without a target or output variable") + return() + endif() + + if(NOT protobuf_generate_LANGUAGE) + set(protobuf_generate_LANGUAGE cpp) + endif() + string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE) + + if(NOT protobuf_generate_PROTOC_OUT_DIR) + set(protobuf_generate_PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) + set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}") + endif() + + foreach(_option ${_dll_export_decl} ${protobuf_generate_PLUGIN_OPTIONS}) + # append comma - not using CMake lists and string replacement as users + # might have semicolons in options + if(_plugin_options) + set( _plugin_options "${_plugin_options},") + endif() + set(_plugin_options "${_plugin_options}${_option}") + endforeach() + + if(protobuf_generate_PLUGIN) + set(_plugin "--plugin=${protobuf_generate_PLUGIN}") + endif() + + if(NOT protobuf_generate_GENERATE_EXTENSIONS) + if(protobuf_generate_LANGUAGE STREQUAL cpp) + set(protobuf_generate_GENERATE_EXTENSIONS .pb.h .pb.cc) + elseif(protobuf_generate_LANGUAGE STREQUAL python) + set(protobuf_generate_GENERATE_EXTENSIONS _pb2.py) + else() + message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS") + return() + endif() + endif() + + if(protobuf_generate_TARGET) + get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES) + foreach(_file ${_source_list}) + if(_file MATCHES "proto$") + list(APPEND protobuf_generate_PROTOS ${_file}) + endif() + endforeach() + endif() + + if(NOT protobuf_generate_PROTOS) + message(SEND_ERROR "Error: protobuf_generate could not find any .proto files") + return() + endif() + + if(protobuf_generate_APPEND_PATH) + # Create an include path for each file specified + foreach(_file ${protobuf_generate_PROTOS}) + get_filename_component(_abs_file ${_file} ABSOLUTE) + get_filename_component(_abs_dir ${_abs_file} DIRECTORY) + list(FIND _protobuf_include_path ${_abs_dir} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${_abs_dir}) + endif() + endforeach() + endif() + + foreach(DIR ${protobuf_generate_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + + if(NOT _protobuf_include_path) + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + set(_generated_srcs_all) + foreach(_proto ${protobuf_generate_PROTOS}) + get_filename_component(_abs_file ${_proto} ABSOLUTE) + get_filename_component(_abs_dir ${_abs_file} DIRECTORY) + + get_filename_component(_file_full_name ${_proto} NAME) + string(FIND "${_file_full_name}" "." _file_last_ext_pos REVERSE) + string(SUBSTRING "${_file_full_name}" 0 ${_file_last_ext_pos} _basename) + + set(_suitable_include_found FALSE) + foreach(DIR ${_protobuf_include_path}) + if(NOT DIR STREQUAL "-I") + file(RELATIVE_PATH _rel_dir ${DIR} ${_abs_dir}) + string(FIND "${_rel_dir}" "../" _is_in_parent_folder) + if (NOT ${_is_in_parent_folder} EQUAL 0) + set(_suitable_include_found TRUE) + break() + endif() + endif() + endforeach() + + if(NOT _suitable_include_found) + message(SEND_ERROR "Error: protobuf_generate could not find any correct proto include directory.") + return() + endif() + + set(_generated_srcs) + foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS}) + list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_rel_dir}/${_basename}${_ext}") + endforeach() + list(APPEND _generated_srcs_all ${_generated_srcs}) + + set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}") + if(protobuf_generate_PROTOC_OPTIONS) + set(_comment "${_comment}, protoc-options: ${protobuf_generate_PROTOC_OPTIONS}") + endif() + if(_plugin_options) + set(_comment "${_comment}, plugin-options: ${_plugin_options}") + endif() + + add_custom_command( + OUTPUT ${_generated_srcs} + COMMAND protobuf::protoc + ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} + DEPENDS ${_abs_file} protobuf::protoc + COMMENT ${_comment} + VERBATIM ) + endforeach() + + set_source_files_properties(${_generated_srcs_all} PROPERTIES GENERATED TRUE) + if(protobuf_generate_OUT_VAR) + set(${protobuf_generate_OUT_VAR} ${_generated_srcs_all} PARENT_SCOPE) + endif() + if(protobuf_generate_TARGET) + target_sources(${protobuf_generate_TARGET} PRIVATE ${_generated_srcs_all}) + endif() + +endfunction() # CMake FindProtobuf module compatible file if(protobuf_MODULE_COMPATIBLE) diff --git a/libs/protobuf/cmake/protobuf-generate.cmake b/libs/protobuf/cmake/protobuf-generate.cmake deleted file mode 100644 index 10fd616..0000000 --- a/libs/protobuf/cmake/protobuf-generate.cmake +++ /dev/null @@ -1,155 +0,0 @@ -function(protobuf_generate) - include(CMakeParseArguments) - - set(_options APPEND_PATH) - set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR PLUGIN PLUGIN_OPTIONS DEPENDENCIES) - if(COMMAND target_sources) - list(APPEND _singleargs TARGET) - endif() - set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS PROTOC_OPTIONS) - - cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") - - if(NOT protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET) - message(SEND_ERROR "Error: protobuf_generate called without any targets or source files") - return() - endif() - - if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET) - message(SEND_ERROR "Error: protobuf_generate called without a target or output variable") - return() - endif() - - if(NOT protobuf_generate_LANGUAGE) - set(protobuf_generate_LANGUAGE cpp) - endif() - string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE) - - if(NOT protobuf_generate_PROTOC_OUT_DIR) - set(protobuf_generate_PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) - endif() - - if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) - set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}") - endif() - - foreach(_option ${_dll_export_decl} ${protobuf_generate_PLUGIN_OPTIONS}) - # append comma - not using CMake lists and string replacement as users - # might have semicolons in options - if(_plugin_options) - set( _plugin_options "${_plugin_options},") - endif() - set(_plugin_options "${_plugin_options}${_option}") - endforeach() - - if(protobuf_generate_PLUGIN) - set(_plugin "--plugin=${protobuf_generate_PLUGIN}") - endif() - - if(NOT protobuf_generate_GENERATE_EXTENSIONS) - if(protobuf_generate_LANGUAGE STREQUAL cpp) - set(protobuf_generate_GENERATE_EXTENSIONS .pb.h .pb.cc) - elseif(protobuf_generate_LANGUAGE STREQUAL python) - set(protobuf_generate_GENERATE_EXTENSIONS _pb2.py) - else() - message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS") - return() - endif() - endif() - - if(protobuf_generate_TARGET) - get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES) - foreach(_file ${_source_list}) - if(_file MATCHES "proto$") - list(APPEND protobuf_generate_PROTOS ${_file}) - endif() - endforeach() - endif() - - if(NOT protobuf_generate_PROTOS) - message(SEND_ERROR "Error: protobuf_generate could not find any .proto files") - return() - endif() - - if(protobuf_generate_APPEND_PATH) - # Create an include path for each file specified - foreach(_file ${protobuf_generate_PROTOS}) - get_filename_component(_abs_file ${_file} ABSOLUTE) - get_filename_component(_abs_dir ${_abs_file} DIRECTORY) - list(FIND _protobuf_include_path ${_abs_dir} _contains_already) - if(${_contains_already} EQUAL -1) - list(APPEND _protobuf_include_path -I ${_abs_dir}) - endif() - endforeach() - endif() - - foreach(DIR ${protobuf_generate_IMPORT_DIRS}) - get_filename_component(ABS_PATH ${DIR} ABSOLUTE) - list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) - if(${_contains_already} EQUAL -1) - list(APPEND _protobuf_include_path -I ${ABS_PATH}) - endif() - endforeach() - - if(NOT _protobuf_include_path) - set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) - endif() - - set(_generated_srcs_all) - foreach(_proto ${protobuf_generate_PROTOS}) - get_filename_component(_abs_file ${_proto} ABSOLUTE) - get_filename_component(_abs_dir ${_abs_file} DIRECTORY) - - get_filename_component(_file_full_name ${_proto} NAME) - string(FIND "${_file_full_name}" "." _file_last_ext_pos REVERSE) - string(SUBSTRING "${_file_full_name}" 0 ${_file_last_ext_pos} _basename) - - set(_suitable_include_found FALSE) - foreach(DIR ${_protobuf_include_path}) - if(NOT DIR STREQUAL "-I") - file(RELATIVE_PATH _rel_dir ${DIR} ${_abs_dir}) - string(FIND "${_rel_dir}" "../" _is_in_parent_folder) - if (NOT ${_is_in_parent_folder} EQUAL 0) - set(_suitable_include_found TRUE) - break() - endif() - endif() - endforeach() - - if(NOT _suitable_include_found) - message(SEND_ERROR "Error: protobuf_generate could not find any correct proto include directory.") - return() - endif() - - set(_generated_srcs) - foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS}) - list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_rel_dir}/${_basename}${_ext}") - endforeach() - list(APPEND _generated_srcs_all ${_generated_srcs}) - - set(_comment "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}") - if(protobuf_generate_PROTOC_OPTIONS) - set(_comment "${_comment}, protoc-options: ${protobuf_generate_PROTOC_OPTIONS}") - endif() - if(_plugin_options) - set(_comment "${_comment}, plugin-options: ${_plugin_options}") - endif() - - add_custom_command( - OUTPUT ${_generated_srcs} - COMMAND protobuf::protoc - ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} - DEPENDS ${_abs_file} protobuf::protoc ${protobuf_generate_DEPENDENCIES} - COMMENT ${_comment} - VERBATIM ) - endforeach() - - set_source_files_properties(${_generated_srcs_all} PROPERTIES GENERATED TRUE) - if(protobuf_generate_OUT_VAR) - set(${protobuf_generate_OUT_VAR} ${_generated_srcs_all} PARENT_SCOPE) - endif() - if(protobuf_generate_TARGET) - target_sources(${protobuf_generate_TARGET} PRIVATE ${_generated_srcs_all}) - endif() - -endfunction() diff --git a/libs/protobuf/cmake/protoc.cmake b/libs/protobuf/cmake/protoc.cmake index 385a7a3..472b642 100644 --- a/libs/protobuf/cmake/protoc.cmake +++ b/libs/protobuf/cmake/protoc.cmake @@ -6,7 +6,6 @@ add_executable(protoc ${protoc_files} ${protobuf_version_rc_file}) target_link_libraries(protoc libprotoc libprotobuf - ${protobuf_ABSL_USED_TARGETS} ) add_executable(protobuf::protoc ALIAS protoc) diff --git a/libs/protobuf/cmake/push_auto_update.sh b/libs/protobuf/cmake/push_auto_update.sh deleted file mode 100755 index abae4f4..0000000 --- a/libs/protobuf/cmake/push_auto_update.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -# This script updates the CMake file lists (i.e. src/file_lists.cmake), commits -# the resulting change, and pushes it. This does not do anything useful when -# run manually, but should be run by our GitHub action instead. - -set -ex - -# Exit early if the previous commit was made by the bot. This reduces the risk -# of a bug causing an infinite loop of auto-generated commits. -if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then - echo "Previous commit was authored by bot" - exit 0 -fi - -$(dirname -- "$0")/update_file_lists.sh - -# Try to determine the most recent pull request number. -title=$(git log -1 --pretty='%s') -pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') -pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') - -pr="" -if [ ! -z "$pr_from_merge" ]; then - pr="$pr_from_merge" -elif [ ! -z "$pr_from_squash" ]; then - pr="$pr_from_squash" -fi - -if [ ! -z "$pr" ]; then - commit_message="Auto-generate CMake file lists after PR #$pr" -else - # If we are unable to determine the pull request number, we fall back on this - # default commit message. Typically this should not occur, but could happen - # if a pull request was merged via a rebase. - commit_message="Auto-generate CMake file lists" -fi - -git add -A -git diff --staged --quiet || git commit -am "$commit_message" -git push diff --git a/libs/protobuf/cmake/tests.cmake b/libs/protobuf/cmake/tests.cmake index 530a66b..1905673 100644 --- a/libs/protobuf/cmake/tests.cmake +++ b/libs/protobuf/cmake/tests.cmake @@ -1,7 +1,6 @@ option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF) -option(protobuf_REMOVE_INSTALLED_HEADERS - "Remove local headers so that installed ones are used instead" OFF) +option(protobuf_TEST_XML_OUTDIR "Output directory for XML logs from tests." "") option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH "Using absolute test_plugin path in tests" ON) @@ -40,23 +39,65 @@ else() add_library(GTest::gmock_main ALIAS gmock_main) endif() -include(${protobuf_SOURCE_DIR}/src/file_lists.cmake) - set(lite_test_protos - ${protobuf_lite_test_protos_files} + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_unittest.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_lite.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public_lite.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite.proto ) set(tests_protos - ${protobuf_test_protos_files} - ${compiler_test_protos_files} - ${util_test_protos_files} + ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/test_large_enum_value.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_proto2_unittest.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_unittest.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_arena.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_custom_options.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_drop_unknown_fields.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_embed_optimize_for.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_empty.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_enormous_descriptor.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_enum.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite_imports_nonlite.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset_wire_format.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_field_presence.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_generic_services.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_optimize_for.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum2.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena_lite.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_lite.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_optional.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_well_known_types.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/anys.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/books.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/default_value.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/default_value_test.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/field_mask.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/maps.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/oneofs.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/proto3.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/struct.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/timestamp_duration.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/testdata/wrappers.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_format.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_format_proto3.proto + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer_unittest.proto ) macro(compile_proto_file filename) - string(REPLACE .proto .pb.h pb_hdr ${filename}) - string(REPLACE .proto .pb.cc pb_src ${filename}) + string(REPLACE .proto .pb.cc pb_file ${filename}) add_custom_command( - OUTPUT ${pb_hdr} ${pb_src} + OUTPUT ${pb_file} DEPENDS ${protobuf_PROTOC_EXE} ${filename} COMMAND ${protobuf_PROTOC_EXE} ${filename} --proto_path=${protobuf_SOURCE_DIR}/src @@ -68,41 +109,119 @@ endmacro(compile_proto_file) set(lite_test_proto_files) foreach(proto_file ${lite_test_protos}) compile_proto_file(${proto_file}) - set(lite_test_proto_files ${lite_test_proto_files} ${pb_src} ${pb_hdr}) + set(lite_test_proto_files ${lite_test_proto_files} ${pb_file}) endforeach(proto_file) set(tests_proto_files) foreach(proto_file ${tests_protos}) compile_proto_file(${proto_file}) - set(tests_proto_files ${tests_proto_files} ${pb_src} ${pb_hdr}) + set(tests_proto_files ${tests_proto_files} ${pb_file}) endforeach(proto_file) +set(common_lite_test_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_test_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_test_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.cc +) + add_library(protobuf-lite-test-common STATIC - ${lite_test_util_srcs} ${lite_test_proto_files}) -target_include_directories(protobuf-lite-test-common PRIVATE ${ABSL_ROOT_DIR}) -target_link_libraries(protobuf-lite-test-common - ${protobuf_LIB_PROTOBUF_LITE} ${protobuf_ABSL_USED_TARGETS} GTest::gmock) + ${common_lite_test_files} ${lite_test_proto_files}) +target_link_libraries(protobuf-lite-test-common libprotobuf-lite GTest::gmock) set(common_test_files - ${test_util_hdrs} - ${test_util_srcs} - ${common_test_hdrs} - ${common_test_srcs} + ${common_lite_test_files} + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.cc ) add_library(protobuf-test-common STATIC ${common_test_files} ${tests_proto_files}) -target_include_directories(protobuf-test-common PRIVATE ${ABSL_ROOT_DIR}) -target_link_libraries(protobuf-test-common - ${protobuf_LIB_PROTOBUF} ${protobuf_ABSL_USED_TARGETS} GTest::gmock) +target_link_libraries(protobuf-test-common libprotobuf GTest::gmock) set(tests_files - ${protobuf_test_files} - ${compiler_test_files} - ${annotation_test_util_srcs} - ${io_test_files} - ${util_test_files} - ${stubs_test_files} + ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_size_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/metadata_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/move_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/plugin_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/plugin_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/plugin_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/drop_unknown_fields_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_lite_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/message_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/message_unittest.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/no_field_presence_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/preserve_unknown_enum_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_arena_lite_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_arena_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_lite_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_lite_unittest.inc + ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field_reflection_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/int128_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/statusor_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringpiece_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/stringprintf_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/template_util_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/time_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/json_objectwriter_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/json_stream_parser_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/protostream_objectsource_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/internal/type_info_test_helper.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_util_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util_test.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/well_known_types_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.inc ) if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH) @@ -135,75 +254,41 @@ if (MSVC) /wd4146 # unary minus operator applied to unsigned type, result still unsigned ) endif() -target_link_libraries(tests protobuf-lite-test-common protobuf-test-common ${protobuf_LIB_PROTOC} ${protobuf_LIB_PROTOBUF} GTest::gmock_main) +target_link_libraries(tests protobuf-lite-test-common protobuf-test-common libprotoc libprotobuf GTest::gmock_main) set(test_plugin_files - ${test_plugin_files} - ${common_test_hdrs} - ${common_test_srcs} + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/test_plugin.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.h ) add_executable(test_plugin ${test_plugin_files}) -target_include_directories(test_plugin PRIVATE ${ABSL_ROOT_DIR}) -target_link_libraries(test_plugin - ${protobuf_LIB_PROTOC} - ${protobuf_LIB_PROTOBUF} - ${protobuf_ABSL_USED_TARGETS} - GTest::gmock -) +target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock) -add_executable(lite-test ${protobuf_lite_test_files}) -target_link_libraries(lite-test protobuf-lite-test-common ${protobuf_LIB_PROTOBUF_LITE} GTest::gmock_main) +set(lite_test_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc +) +add_executable(lite-test ${lite_test_files}) +target_link_libraries(lite-test protobuf-lite-test-common libprotobuf-lite GTest::gmock_main) add_test(NAME lite-test COMMAND lite-test ${protobuf_GTEST_ARGS}) +set(lite_arena_test_files + ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_arena_unittest.cc +) +add_executable(lite-arena-test ${lite_arena_test_files}) +target_link_libraries(lite-arena-test protobuf-lite-test-common libprotobuf-lite GTest::gmock_main) + +add_test(NAME lite-arena-test + COMMAND lite-arena-test ${protobuf_GTEST_ARGS}) + add_custom_target(check COMMAND tests - DEPENDS tests lite-test test_plugin + DEPENDS tests test_plugin WORKING_DIRECTORY ${protobuf_SOURCE_DIR}) add_test(NAME check - COMMAND tests ${protobuf_GTEST_ARGS}) - -# For test purposes, remove headers that should already be installed. This -# prevents accidental conflicts and also version skew (since local headers take -# precedence over installed headers). -add_custom_target(save-installed-headers) -add_custom_target(remove-installed-headers) -add_custom_target(restore-installed-headers) - -file(GLOB_RECURSE _local_hdrs - "${PROJECT_SOURCE_DIR}/src/*.h" - "${PROJECT_SOURCE_DIR}/src/*.inc") - -# Exclude the bootstrapping that are directly used by tests. -set(_exclude_hdrs - "${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h" - "${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.h") - -# Exclude test library headers. -list(APPEND _exclude_hdrs ${test_util_hdrs} ${lite_test_util_hdrs} ${common_test_hdrs} - ${compiler_test_utils_hdrs}) -foreach(_hdr ${_exclude_hdrs}) - list(REMOVE_ITEM _local_hdrs ${_hdr}) -endforeach() - -foreach(_hdr ${_local_hdrs}) - string(REPLACE "${protobuf_SOURCE_DIR}/src" "" _file ${_hdr}) - set(_tmp_file "${CMAKE_BINARY_DIR}/tmp-install-test/${_file}") - add_custom_command(TARGET remove-installed-headers PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E remove -f "${_hdr}") - add_custom_command(TARGET save-installed-headers PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy "${_hdr}" "${_tmp_file}" || true) - add_custom_command(TARGET restore-installed-headers PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E - copy "${_tmp_file}" "${_hdr}") -endforeach() - -add_dependencies(remove-installed-headers save-installed-headers) -if(protobuf_REMOVE_INSTALLED_HEADERS) - # Make sure we remove all the headers *before* any codegen occurs. - add_dependencies(${protobuf_PROTOC_EXE} remove-installed-headers) -endif() + COMMAND tests ${protobuf_GTEST_ARGS} + WORKING_DIRECTORY "${protobuf_SOURCE_DIR}") diff --git a/libs/protobuf/cmake/update_file_lists.sh b/libs/protobuf/cmake/update_file_lists.sh deleted file mode 100755 index a08bdf3..0000000 --- a/libs/protobuf/cmake/update_file_lists.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -u - -# This script generates file lists from Bazel for CMake. - -set -e - -bazel build //pkg:gen_src_file_lists -cp -v bazel-bin/pkg/src_file_lists.cmake src/file_lists.cmake diff --git a/libs/protobuf/configure.ac b/libs/protobuf/configure.ac new file mode 100644 index 0000000..7243fd3 --- /dev/null +++ b/libs/protobuf/configure.ac @@ -0,0 +1,247 @@ +## Process this file with autoconf to produce configure. +## In general, the safest way to proceed is to run ./autogen.sh + +AC_PREREQ(2.59) + +# Note: If you change the version, you must also update it in: +# * Protobuf.podspec +# * csharp/Google.Protobuf.Tools.nuspec +# * csharp/src/*/AssemblyInfo.cs +# * csharp/src/Google.Protobuf/Google.Protobuf.nuspec +# * java/*/pom.xml +# * python/google/protobuf/__init__.py +# * protoc-artifacts/pom.xml +# * src/google/protobuf/stubs/common.h +# * src/Makefile.am (Update -version-info for LDFLAGS if needed) +# +# In the SVN trunk, the version should always be the next anticipated release +# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed +# the size of one file name in the dist tarfile over the 99-char limit.) +AC_INIT([Protocol Buffers],[3.21.12],[protobuf@googlegroups.com],[protobuf]) + +AM_MAINTAINER_MODE([enable]) + +AC_CONFIG_SRCDIR(src/google/protobuf/message.cc) +# The config file is generated but not used by the source code, since we only +# need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are +# passed down in CXXFLAGS manually in src/Makefile.am +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)]) +case "$DIST_LANG" in + "") DIST_LANG=all ;; + all | cpp | csharp | java | python | javanano | objectivec | ruby | php) ;; + *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;; +esac +AC_SUBST(DIST_LANG) + +# autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily +# the best choice for libprotobuf. +AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"], + [CFLAGS=""]) +AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"], + [CXXFLAGS=""]) + +AC_CANONICAL_TARGET + +AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects]) + +# Silent rules enabled: the output is minimal but informative. +# In particular, the warnings from the compiler stick out very clearly. +# To see all logs, use the --disable-silent-rules on configure or via make V=1 +AM_SILENT_RULES([yes]) + +AC_ARG_WITH([zlib], + [AS_HELP_STRING([--with-zlib], + [include classes for streaming compressed data in and out @<:@default=check@:>@])], + [],[with_zlib=check]) + +AC_ARG_WITH([zlib-include], + [AS_HELP_STRING([--with-zlib-include=PATH], + [zlib include directory])], + [CPPFLAGS="-I$withval $CPPFLAGS"]) + +AC_ARG_WITH([zlib-lib], + [AS_HELP_STRING([--with-zlib-lib=PATH], + [zlib lib directory])], + [LDFLAGS="-L$withval $LDFLAGS"]) + +AC_ARG_WITH([protoc], + [AS_HELP_STRING([--with-protoc=COMMAND], + [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])], + [],[with_protoc=no]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_CXX +AC_PROG_CXX_FOR_BUILD +AC_LANG([C++]) +ACX_USE_SYSTEM_EXTENSIONS +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) +AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc +AS_CASE([$target_os], [darwin*], [AC_PROG_OBJC], [AM_CONDITIONAL([am__fastdepOBJC], [false])]) + +# test_util.cc takes forever to compile with GCC and optimization turned on. +AC_MSG_CHECKING([C++ compiler flags...]) +AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[ + AS_IF([test "$GCC" = "yes"],[ + PROTOBUF_OPT_FLAG="-O2" + CXXFLAGS="${CXXFLAGS} -g" + ]) + + # Protocol Buffers contains several checks that are intended to be used only + # for debugging and which might hurt performance. Most users are probably + # end users who don't want these checks, so add -DNDEBUG by default. + CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG" + + AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS]) +],[ + AC_MSG_RESULT([use user-supplied: $CXXFLAGS]) +]) + +AC_SUBST(PROTOBUF_OPT_FLAG) + +ACX_CHECK_SUNCC + +# Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd +# to the link +AC_PROG_LIBTOOL + +# Check whether the linker supports version scripts +AC_MSG_CHECKING([whether the linker supports version scripts]) +save_LDFLAGS=$LDFLAGS +LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" +cat > conftest.map < + #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204) + # error zlib version too old + #endif + ]], [])], [ + AC_MSG_RESULT([ok (1.2.0.4 or later)]) + + # Also need to add -lz to the linker flags and make sure this succeeds. + AC_SEARCH_LIBS([zlibVersion], [z], [ + AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.]) + HAVE_ZLIB=1 + ], [ + AS_IF([test "$with_zlib" != check], [ + AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found]) + ]) + ]) + ], [ + AS_IF([test "$with_zlib" = check], [ + AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)]) + ], [ + AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)]) + ]) + ]) +]) +AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1]) + +# Add -std=c++11 if necesssary. It is important for us to do this before the +# libatomic check below, since that also depends on C++11. +AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory]) + +dnl On some platforms, std::atomic needs a helper library +AC_MSG_CHECKING(whether -latomic is needed) +AC_LINK_IFELSE([AC_LANG_SOURCE([[ + #include + #include + std::atomic v; + int main() { + return v; + } +]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes) +AC_MSG_RESULT($STD_ATOMIC_NEED_LIBATOMIC) +if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then + LIBATOMIC_LIBS="-latomic" +fi +AC_SUBST([LIBATOMIC_LIBS]) + +AS_IF([test "$with_protoc" != "no"], [ + PROTOC=$with_protoc + AS_IF([test "$with_protoc" = "yes"], [ + # No argument given. Use system protoc. + PROTOC=protoc + ]) + AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [ + # Does not start with a slash, but contains a slash. So, it's a relative + # path (as opposed to an absolute path or an executable in $PATH). + # Since it will actually be executed from the src directory, prefix with + # the current directory. We also insert $ac_top_build_prefix in case this + # is a nested package and --with-protoc was actually given on the outer + # package's configure script. + PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC + ]) + AC_SUBST([PROTOC]) +]) +AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"]) + +AX_PTHREAD +AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"]) +# We still keep this for improving pbconfig.h for unsupported platforms. +AC_CXX_STL_HASH + +# Enable ObjC support for conformance directory on OS X. +OBJC_CONFORMANCE_TEST=0 +case "$target_os" in + darwin*) + OBJC_CONFORMANCE_TEST=1 + ;; +esac +AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1]) + +AC_MSG_CHECKING(whether -llog is needed) +ANDROID_TEST=no +case "$target_os" in + *android*) + ANDROID_TEST=yes + ;; +esac +AC_MSG_RESULT($ANDROID_TEST) +if test "x$ANDROID_TEST" = xyes; then + LIBLOG_LIBS="-llog" +fi +AC_SUBST([LIBLOG_LIBS]) + +# HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS, +# since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock +# too. +export CFLAGS +export CXXFLAGS +AC_CONFIG_SUBDIRS([third_party/googletest]) + +AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc]) +AC_OUTPUT diff --git a/libs/protobuf/conformance/BUILD.bazel b/libs/protobuf/conformance/BUILD.bazel index 7eb0602..7de2b8e 100644 --- a/libs/protobuf/conformance/BUILD.bazel +++ b/libs/protobuf/conformance/BUILD.bazel @@ -1,8 +1,6 @@ # Conformance testing for Protobuf. -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library") -load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library") -load("//build_defs:internal_shell.bzl", "inline_sh_binary") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library") load( "@rules_pkg//:mappings.bzl", "pkg_attributes", @@ -12,38 +10,21 @@ load( ) exports_files([ - "bazel_conformance_test_runner.sh", - "failure_list_cpp.txt", - "failure_list_csharp.txt", + "conformance_test_runner.sh", "failure_list_java.txt", "failure_list_java_lite.txt", - "failure_list_objc.txt", - "failure_list_php.txt", - "failure_list_php_c.txt", - "failure_list_python.txt", - "failure_list_python_cpp.txt", - "failure_list_ruby.txt", - "failure_list_jruby.txt", - "text_format_failure_list_cpp.txt", - "text_format_failure_list_csharp.txt", "text_format_failure_list_java.txt", "text_format_failure_list_java_lite.txt", - "text_format_failure_list_php.txt", - "text_format_failure_list_php_c.txt", - "text_format_failure_list_python.txt", - "text_format_failure_list_python_cpp.txt", - "text_format_failure_list_ruby.txt", - "text_format_failure_list_jruby.txt", ]) cc_proto_library( name = "test_messages_proto2_proto_cc", - deps = ["//src/google/protobuf:test_messages_proto2_proto"], + deps = ["//:test_messages_proto2_proto"], ) cc_proto_library( name = "test_messages_proto3_proto_cc", - deps = ["//src/google/protobuf:test_messages_proto3_proto"], + deps = ["//:test_messages_proto3_proto"], ) proto_library( @@ -53,18 +34,10 @@ proto_library( ) cc_proto_library( - name = "conformance_cc_proto", + name = "conformance_proto_cc", deps = [":conformance_proto"], ) -internal_csharp_proto_library( - name = "conformance_csharp_proto", - srcs = ["conformance.proto"], - visibility = [ - "//csharp:__subpackages__", - ], -) - java_proto_library( name = "conformance_java_proto", visibility = [ @@ -81,49 +54,11 @@ java_lite_proto_library( deps = [":conformance_proto"], ) -internal_objc_proto_library( - name = "conformance_objc_proto", - srcs = ["conformance.proto"], - visibility = [ - "//conformance:__pkg__", - "//objc:__pkg__", - ], -) - -internal_py_proto_library( - name = "conformance_py_proto", - srcs = ["conformance.proto"], - srcs_version = "PY2AND3", - visibility = [ - "//python:__subpackages__", - ], -) - -internal_php_proto_library( - name = "conformance_php_proto", - srcs = ["conformance.proto"], - outs = [ - "Conformance/ConformanceRequest.php", - "Conformance/ConformanceResponse.php", - "Conformance/FailureSet.php", - "Conformance/JspbEncodingConfig.php", - "Conformance/TestCategory.php", - "Conformance/WireFormat.php", - "GPBMetadata/Conformance.php", - ], - visibility = [ - "//conformance:__pkg__", - "//php:__pkg__", - ], -) - -internal_ruby_proto_library( - name = "conformance_ruby_proto", - srcs = ["conformance.proto"], - visibility = [ - "//conformance:__pkg__", - "//ruby:__pkg__", - ], +cc_library( + name = "jsoncpp", + srcs = ["third_party/jsoncpp/jsoncpp.cpp"], + hdrs = ["third_party/jsoncpp/json.h"], + includes = ["."], ) cc_library( @@ -136,11 +71,7 @@ cc_library( "conformance_test.h", ], includes = ["."], - deps = [ - ":conformance_cc_proto", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - ], + deps = [":conformance_proto_cc"], ) cc_library( @@ -149,10 +80,9 @@ cc_library( hdrs = ["binary_json_conformance_suite.h"], deps = [ ":conformance_test", - "@jsoncpp//:jsoncpp", + ":jsoncpp", ":test_messages_proto2_proto_cc", ":test_messages_proto3_proto_cc", - "@com_google_absl//absl/status", ], ) @@ -175,28 +105,11 @@ cc_binary( ":binary_json_conformance_suite", ":conformance_test", ":text_format_conformance_suite", - "@com_google_absl//absl/strings:str_format", - ], -) - -cc_binary( - name = "conformance_cpp", - testonly = 1, - srcs = ["conformance_cpp.cc"], - visibility = ["//src:__subpackages__"], - deps = [ - ":conformance_cc_proto", - "//:protobuf", - "//:test_messages_proto2_cc_proto", - "//:test_messages_proto3_cc_proto", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", ], ) java_binary( name = "conformance_java", - testonly = 1, srcs = ["ConformanceJava.java"], main_class = "ConformanceJava", visibility = [ @@ -213,7 +126,6 @@ java_binary( java_binary( name = "conformance_java_lite", - testonly = 1, srcs = ["ConformanceJavaLite.java"], main_class = "ConformanceJavaLite", visibility = [ @@ -228,119 +140,10 @@ java_binary( ], ) -py_binary( - name = "conformance_python", - testonly = 1, - srcs = ["conformance_python.py"], - imports = [ - "..", - "../python", - ], - srcs_version = "PY2AND3", - visibility = ["//python:__subpackages__"], - deps = [ - ":conformance_py_proto", - "//:protobuf_python", - "//python:test_messages_proto2_py_proto", - "//python:test_messages_proto3_py_proto", - ], -) - -inline_sh_binary( - name = "conformance_php", - testonly = 1, - srcs = [ - "autoload.php", - "conformance_php.php", - ], - cmd = """ - php -d include_path=conformance:src/google/protobuf \\ - -d auto_prepend_file=$(rootpath autoload.php) \\ - $(rootpath conformance_php.php) - """, - visibility = ["//php:__subpackages__"], - deps = [ - ":conformance_php_proto", - "//:test_messages_proto3_php_proto", - "//php:source_files", - ], -) - -inline_sh_binary( - name = "conformance_php_c", - testonly = 1, - srcs = [ - "conformance_php.php", - "//php:extension", - ], - cmd = """ - php -dextension=$(rootpath //php:extension) \\ - -d include_path=conformance:src/google/protobuf \\ - $(rootpath conformance_php.php) - """, - visibility = ["//php:__subpackages__"], - deps = [ - ":conformance_php_proto", - "//:test_messages_proto3_php_proto", - ], -) - -inline_sh_binary( - name = "conformance_csharp", - testonly = 1, - srcs = ["//csharp/src/Google.Protobuf.Conformance:conformance_dll"], - cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)", - visibility = ["//csharp:__subpackages__"], - deps = [ - "//csharp/src/Google.Protobuf.Conformance:conformance_runfiles", - ], -) - -objc_library( - name = "conformance_objc_lib", - testonly = 1, - non_arc_srcs = ["conformance_objc.m"], - # See https://github.com/bazelbuild/bazel/issues/12897. - tags = ["manual"], - deps = [ - ":conformance_objc_proto", - "//:test_messages_proto2_objc_proto", - "//:test_messages_proto3_objc_proto", - ], -) - -cc_binary( - name = "conformance_objc", - testonly = 1, - # See https://github.com/bazelbuild/bazel/issues/12897. - tags = ["manual"], - visibility = ["//objectivec:__subpackages__"], - deps = [":conformance_objc_lib"], -) - -inline_sh_binary( - name = "conformance_ruby", - testonly = 1, - srcs = ["conformance_ruby.rb"], - cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)", - visibility = ["//ruby:__subpackages__"], - deps = [ - ":conformance_ruby_proto", - "//:test_messages_proto2_ruby_proto", - "//:test_messages_proto3_ruby_proto", - "//:well_known_ruby_protos", - "//ruby:protobuf", - ], -) - -################################################################################ -# Distribution files -################################################################################ - filegroup( name = "all_files", srcs = glob(["**/*"]), - visibility = ["//src/google/protobuf/compiler/csharp:__pkg__"], + visibility = ["//:__pkg__"], ) pkg_files( @@ -349,10 +152,11 @@ pkg_files( ["**/*"], exclude = [ # Handled by dist_scripts: - "bazel_conformance_test_runner.sh", + "conformance_test_runner.sh", # The following are not in autotools dist: "autoload.php", + "conformance_nodejs.js", "failure_list_jruby.txt", "update_failure_list.py", ], @@ -361,10 +165,19 @@ pkg_files( visibility = ["//pkg:__pkg__"], ) +pkg_files( + name = "dist_scripts", + srcs = ["conformance_test_runner.sh"], + attributes = pkg_attributes(mode = "0555"), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + pkg_filegroup( name = "all_dist_files", srcs = [ ":dist_files", + ":dist_scripts", ], visibility = ["//pkg:__pkg__"], ) diff --git a/libs/protobuf/conformance/Makefile.am b/libs/protobuf/conformance/Makefile.am new file mode 100644 index 0000000..415412b --- /dev/null +++ b/libs/protobuf/conformance/Makefile.am @@ -0,0 +1,372 @@ +## Process this file with automake to produce Makefile.in + +conformance_protoc_inputs = \ + conformance.proto \ + $(top_srcdir)/src/google/protobuf/test_messages_proto3.proto + +# proto2 input files, should be separated with proto3, as we +# can't generate proto2 files for php. +conformance_proto2_protoc_inputs = \ + $(top_srcdir)/src/google/protobuf/test_messages_proto2.proto + +well_known_type_protoc_inputs = \ + $(top_srcdir)/src/google/protobuf/any.proto \ + $(top_srcdir)/src/google/protobuf/duration.proto \ + $(top_srcdir)/src/google/protobuf/field_mask.proto \ + $(top_srcdir)/src/google/protobuf/struct.proto \ + $(top_srcdir)/src/google/protobuf/timestamp.proto \ + $(top_srcdir)/src/google/protobuf/wrappers.proto + + +protoc_outputs = \ + conformance.pb.cc \ + conformance.pb.h + +other_language_protoc_outputs = \ + conformance_pb2.py \ + Conformance.pbobjc.h \ + Conformance.pbobjc.m \ + conformance_pb.js \ + conformance_pb.rb \ + com/google/protobuf/Any.java \ + com/google/protobuf/AnyOrBuilder.java \ + com/google/protobuf/AnyProto.java \ + com/google/protobuf/BoolValue.java \ + com/google/protobuf/BoolValueOrBuilder.java \ + com/google/protobuf/BytesValue.java \ + com/google/protobuf/BytesValueOrBuilder.java \ + com/google/protobuf/conformance/Conformance.java \ + com/google/protobuf/DoubleValue.java \ + com/google/protobuf/DoubleValueOrBuilder.java \ + com/google/protobuf/Duration.java \ + com/google/protobuf/DurationOrBuilder.java \ + com/google/protobuf/DurationProto.java \ + com/google/protobuf/FieldMask.java \ + com/google/protobuf/FieldMaskOrBuilder.java \ + com/google/protobuf/FieldMaskProto.java \ + com/google/protobuf/FloatValue.java \ + com/google/protobuf/FloatValueOrBuilder.java \ + com/google/protobuf/Int32Value.java \ + com/google/protobuf/Int32ValueOrBuilder.java \ + com/google/protobuf/Int64Value.java \ + com/google/protobuf/Int64ValueOrBuilder.java \ + com/google/protobuf/ListValue.java \ + com/google/protobuf/ListValueOrBuilder.java \ + com/google/protobuf/NullValue.java \ + com/google/protobuf/StringValue.java \ + com/google/protobuf/StringValueOrBuilder.java \ + com/google/protobuf/Struct.java \ + com/google/protobuf/StructOrBuilder.java \ + com/google/protobuf/StructProto.java \ + com/google/protobuf/Timestamp.java \ + com/google/protobuf/TimestampOrBuilder.java \ + com/google/protobuf/TimestampProto.java \ + com/google/protobuf/UInt32Value.java \ + com/google/protobuf/UInt32ValueOrBuilder.java \ + com/google/protobuf/UInt64Value.java \ + com/google/protobuf/UInt64ValueOrBuilder.java \ + com/google/protobuf/Value.java \ + com/google/protobuf/ValueOrBuilder.java \ + com/google/protobuf/WrappersProto.java \ + com/google/protobuf_test_messages/proto3/TestMessagesProto3.java \ + com/google/protobuf_test_messages/proto2/TestMessagesProto2.java \ + google/protobuf/any.pb.cc \ + google/protobuf/any.pb.h \ + google/protobuf/any.rb \ + google/protobuf/any_pb2.py \ + google/protobuf/duration.pb.cc \ + google/protobuf/duration.pb.h \ + google/protobuf/duration.rb \ + google/protobuf/duration_pb2.py \ + google/protobuf/field_mask.pb.cc \ + google/protobuf/field_mask.pb.h \ + google/protobuf/field_mask.rb \ + google/protobuf/field_mask_pb2.py \ + google/protobuf/struct.pb.cc \ + google/protobuf/struct.pb.h \ + google/protobuf/struct.rb \ + google/protobuf/struct_pb2.py \ + google/protobuf/TestMessagesProto2.pbobjc.h \ + google/protobuf/TestMessagesProto2.pbobjc.m \ + google/protobuf/TestMessagesProto3.pbobjc.h \ + google/protobuf/TestMessagesProto3.pbobjc.m \ + google/protobuf/test_messages_proto3.pb.cc \ + google/protobuf/test_messages_proto3.pb.h \ + google/protobuf/test_messages_proto2.pb.cc \ + google/protobuf/test_messages_proto2.pb.h \ + google/protobuf/test_messages_proto3_pb.rb \ + google/protobuf/test_messages_proto3_pb2.py \ + google/protobuf/test_messages_proto2_pb2.py \ + google/protobuf/timestamp.pb.cc \ + google/protobuf/timestamp.pb.h \ + google/protobuf/timestamp.rb \ + google/protobuf/timestamp_pb2.py \ + google/protobuf/wrappers.pb.cc \ + google/protobuf/wrappers.pb.h \ + google/protobuf/wrappers.rb \ + google/protobuf/wrappers_pb2.py \ + Conformance/ConformanceRequest.php \ + Conformance/ConformanceResponse.php \ + Conformance/FailureSet.php \ + Conformance/WireFormat.php \ + GPBMetadata/Conformance.php \ + GPBMetadata/Google/Protobuf/Any.php \ + GPBMetadata/Google/Protobuf/Duration.php \ + GPBMetadata/Google/Protobuf/FieldMask.php \ + GPBMetadata/Google/Protobuf/Struct.php \ + GPBMetadata/Google/Protobuf/TestMessagesProto3.php \ + GPBMetadata/Google/Protobuf/Timestamp.php \ + GPBMetadata/Google/Protobuf/Wrappers.php \ + Google/Protobuf/Any.php \ + Google/Protobuf/BoolValue.php \ + Google/Protobuf/BytesValue.php \ + Google/Protobuf/DoubleValue.php \ + Google/Protobuf/Duration.php \ + Google/Protobuf/FieldMask.php \ + Google/Protobuf/FloatValue.php \ + Google/Protobuf/Int32Value.php \ + Google/Protobuf/Int64Value.php \ + Google/Protobuf/ListValue.php \ + Google/Protobuf/NullValue.php \ + Google/Protobuf/StringValue.php \ + Google/Protobuf/Struct.php \ + Google/Protobuf/Timestamp.php \ + Google/Protobuf/UInt32Value.php \ + Google/Protobuf/UInt64Value.php \ + Google/Protobuf/Value.php \ + Protobuf_test_messages/Proto3/ForeignEnum.php \ + Protobuf_test_messages/Proto3/ForeignMessage.php \ + Protobuf_test_messages/Proto3/TestAllTypes_NestedEnum.php \ + Protobuf_test_messages/Proto3/TestAllTypes_NestedMessage.php \ + Protobuf_test_messages/Proto3/TestAllTypes.php + # lite/com/google/protobuf/Any.java \ + # lite/com/google/protobuf/AnyOrBuilder.java \ + # lite/com/google/protobuf/AnyProto.java \ + # lite/com/google/protobuf/BoolValue.java \ + # lite/com/google/protobuf/BoolValueOrBuilder.java \ + # lite/com/google/protobuf/BytesValue.java \ + # lite/com/google/protobuf/BytesValueOrBuilder.java \ + # lite/com/google/protobuf/conformance/Conformance.java \ + # lite/com/google/protobuf/DoubleValue.java \ + # lite/com/google/protobuf/DoubleValueOrBuilder.java \ + # lite/com/google/protobuf/Duration.java \ + # lite/com/google/protobuf/DurationOrBuilder.java \ + # lite/com/google/protobuf/DurationProto.java \ + # lite/com/google/protobuf/FieldMask.java \ + # lite/com/google/protobuf/FieldMaskOrBuilder.java \ + # lite/com/google/protobuf/FieldMaskProto.java \ + # lite/com/google/protobuf/FloatValue.java \ + # lite/com/google/protobuf/FloatValueOrBuilder.java \ + # lite/com/google/protobuf/Int32Value.java \ + # lite/com/google/protobuf/Int32ValueOrBuilder.java \ + # lite/com/google/protobuf/Int64Value.java \ + # lite/com/google/protobuf/Int64ValueOrBuilder.java \ + # lite/com/google/protobuf/ListValue.java \ + # lite/com/google/protobuf/ListValueOrBuilder.java \ + # lite/com/google/protobuf/NullValue.java \ + # lite/com/google/protobuf/StringValue.java \ + # lite/com/google/protobuf/StringValueOrBuilder.java \ + # lite/com/google/protobuf/Struct.java \ + # lite/com/google/protobuf/StructOrBuilder.java \ + # lite/com/google/protobuf/StructProto.java \ + # lite/com/google/protobuf/Timestamp.java \ + # lite/com/google/protobuf/TimestampOrBuilder.java \ + # lite/com/google/protobuf/TimestampProto.java \ + # lite/com/google/protobuf/UInt32Value.java \ + # lite/com/google/protobuf/UInt32ValueOrBuilder.java \ + # lite/com/google/protobuf/UInt64Value.java \ + # lite/com/google/protobuf/UInt64ValueOrBuilder.java \ + # lite/com/google/protobuf/Value.java \ + # lite/com/google/protobuf/ValueOrBuilder.java \ + # lite/com/google/protobuf/WrappersProto.java + +bin_PROGRAMS = conformance-test-runner conformance-cpp + +# All source files excepet C++/Objective-C ones should be explicitly listed +# here because the autoconf tools don't include files of other languages +# automatically. +EXTRA_DIST = \ + ConformanceJava.java \ + ConformanceJavaLite.java \ + README.md \ + conformance.proto \ + conformance_python.py \ + conformance_ruby.rb \ + conformance_php.php \ + failure_list_cpp.txt \ + failure_list_csharp.txt \ + failure_list_java.txt \ + failure_list_js.txt \ + failure_list_objc.txt \ + failure_list_python.txt \ + failure_list_python_cpp.txt \ + failure_list_python-post26.txt \ + failure_list_ruby.txt \ + failure_list_php.txt \ + failure_list_php_c.txt + +conformance_test_runner_LDADD = $(top_srcdir)/src/libprotobuf.la +conformance_test_runner_SOURCES = conformance_test.h conformance_test.cc \ + conformance_test_main.cc \ + binary_json_conformance_suite.h \ + binary_json_conformance_suite.cc \ + text_format_conformance_suite.h \ + text_format_conformance_suite.cc \ + conformance_test_runner.cc \ + third_party/jsoncpp/json.h \ + third_party/jsoncpp/jsoncpp.cpp +nodist_conformance_test_runner_SOURCES = conformance.pb.cc google/protobuf/test_messages_proto3.pb.cc google/protobuf/test_messages_proto2.pb.cc +conformance_test_runner_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir) +conformance_test_runner_CXXFLAGS = -std=c++11 +# Explicit deps because BUILT_SOURCES are only done before a "make all/check" +# so a direct "make test_cpp" could fail if parallel enough. +conformance_test_runner-conformance_test.$(OBJEXT): conformance.pb.h +conformance_test_runner-conformance_test_runner.$(OBJEXT): conformance.pb.h + +conformance_cpp_LDADD = $(top_srcdir)/src/libprotobuf.la +conformance_cpp_SOURCES = conformance_cpp.cc +nodist_conformance_cpp_SOURCES = conformance.pb.cc google/protobuf/test_messages_proto3.pb.cc google/protobuf/test_messages_proto2.pb.cc +conformance_cpp_CPPFLAGS = -I$(top_srcdir)/src +# Explicit dep because BUILT_SOURCES are only done before a "make all/check" +# so a direct "make test_cpp" could fail if parallel enough. +conformance_cpp-conformance_cpp.$(OBJEXT): conformance.pb.h + +if OBJC_CONFORMANCE_TEST + +bin_PROGRAMS += conformance-objc + +conformance_objc_SOURCES = conformance_objc.m ../objectivec/GPBProtocolBuffers.m +nodist_conformance_objc_SOURCES = Conformance.pbobjc.m google/protobuf/TestMessagesProto2.pbobjc.m google/protobuf/TestMessagesProto3.pbobjc.m +# On travis, the build fails without the isysroot because whatever system +# headers are being found don't include generics support for +# NSArray/NSDictionary, the only guess is their image at one time had an odd +# setup for Xcode and old frameworks are being found. +conformance_objc_CPPFLAGS = -I$(top_srcdir)/objectivec -isysroot `xcrun --sdk macosx --show-sdk-path` +conformance_objc_LDFLAGS = -framework Foundation +# Explicit dep because BUILT_SOURCES are only done before a "make all/check" +# so a direct "make test_objc" could fail if parallel enough. +conformance_objc-conformance_objc.$(OBJEXT): Conformance.pbobjc.h google/protobuf/TestMessagesProto2.pbobjc.h google/protobuf/TestMessagesProto3.pbobjc.h + +endif + +# JavaScript well-known types are expected to be in a directory called +# google-protobuf, because they are usually in the google-protobuf npm +# package. But we want to use the sources from our tree, so we recreate +# that directory structure here. +google-protobuf: + mkdir google-protobuf + +if USE_EXTERNAL_PROTOC + +# Some implementations include pre-generated versions of well-known types. +protoc_middleman: $(conformance_protoc_inputs) $(conformance_proto2_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf + $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. --php_out=. $(conformance_protoc_inputs) + $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. $(conformance_proto2_protoc_inputs) + $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. $(well_known_type_protoc_inputs) + ## $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) + touch protoc_middleman + +else + +# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is +# relative to srcdir, which may not be the same as the current directory when +# building out-of-tree. +protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(conformance_protoc_inputs) $(conformance_proto2_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd --php_out=$$oldpwd $(conformance_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd $(conformance_proto2_protoc_inputs) ) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd $(well_known_type_protoc_inputs) ) + ## @mkdir -p lite + ## oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) ) + touch protoc_middleman + +endif + +$(protoc_outputs): protoc_middleman + +$(other_language_protoc_outputs): protoc_middleman + +CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java javac_middleman_lite conformance-java-lite conformance-csharp conformance-php conformance-php-c $(other_language_protoc_outputs) + +MAINTAINERCLEANFILES = \ + Makefile.in + +javac_middleman: ConformanceJava.java protoc_middleman $(other_language_protoc_outputs) + jar=`ls ../java/util/target/*jar-with-dependencies.jar` && javac -classpath ../java/target/classes:$$jar ConformanceJava.java com/google/protobuf/conformance/Conformance.java com/google/protobuf_test_messages/proto3/TestMessagesProto3.java com/google/protobuf_test_messages/proto2/TestMessagesProto2.java + @touch javac_middleman + +conformance-java: javac_middleman + @echo "Writing shortcut script conformance-java..." + @echo '#! /bin/sh' > conformance-java + @jar=`ls ../java/util/target/*jar-with-dependencies.jar` && echo java -classpath .:../java/target/classes:$$jar ConformanceJava '$$@' >> conformance-java + @chmod +x conformance-java + +javac_middleman_lite: ConformanceJavaLite.java protoc_middleman $(other_language_protoc_outputs) + javac -classpath ../java/lite/target/classes:lite ConformanceJavaLite.java lite/com/google/protobuf/conformance/Conformance.java + @touch javac_middleman_lite + +conformance-java-lite: javac_middleman_lite + @echo "Writing shortcut script conformance-java-lite..." + @echo '#! /bin/sh' > conformance-java-lite + @echo java -classpath .:../java/lite/target/classes:lite ConformanceJavaLite '$$@' >> conformance-java-lite + @chmod +x conformance-java-lite + +# Currently the conformance code is alongside the rest of the C# +# source, as it's easier to maintain there. We assume we've already +# built that, so we just need a script to run it. +conformance-csharp: $(other_language_protoc_outputs) + @echo "Writing shortcut script conformance-csharp..." + @echo '#! /bin/sh' > conformance-csharp + @echo 'dotnet ../csharp/src/Google.Protobuf.Conformance/bin/Release/netcoreapp3.1/Google.Protobuf.Conformance.dll "$$@"' >> conformance-csharp + @chmod +x conformance-csharp + +conformance-php: + @echo "Writing shortcut script conformance-php..." + @echo '#! /bin/sh' > conformance-php + @echo 'php -d auto_prepend_file=autoload.php ./conformance_php.php' >> conformance-php + @chmod +x conformance-php + +conformance-php-c: + @echo "Writing shortcut script conformance-php-c..." + @echo '#! /bin/sh' > conformance-php-c + @echo 'php -dextension=../php/ext/google/protobuf/modules/protobuf.so ./conformance_php.php' >> conformance-php-c + @chmod +x conformance-php-c + +# Targets for actually running tests. +test_cpp: protoc_middleman conformance-test-runner conformance-cpp + ./conformance-test-runner --enforce_recommended --failure_list failure_list_cpp.txt --text_format_failure_list text_format_failure_list_cpp.txt ./conformance-cpp + +test_java: protoc_middleman conformance-test-runner conformance-java + ./conformance-test-runner --enforce_recommended --failure_list failure_list_java.txt --text_format_failure_list text_format_failure_list_java.txt ./conformance-java + +test_java_lite: protoc_middleman conformance-test-runner conformance-java-lite + ./conformance-test-runner --enforce_recommended ./conformance-java-lite + +test_csharp: protoc_middleman conformance-test-runner conformance-csharp + ./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt --text_format_failure_list text_format_failure_list_csharp.txt ./conformance-csharp + +test_ruby: protoc_middleman conformance-test-runner $(other_language_protoc_outputs) + RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb + +test_jruby: protoc_middleman conformance-test-runner $(other_language_protoc_outputs) + RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_jruby.txt --text_format_failure_list text_format_failure_list_jruby.txt ./conformance_ruby.rb + +test_php: protoc_middleman conformance-test-runner conformance-php $(other_language_protoc_outputs) + ./conformance-test-runner --enforce_recommended --failure_list failure_list_php.txt --text_format_failure_list text_format_failure_list_php.txt ./conformance-php + +test_php_c: protoc_middleman conformance-test-runner conformance-php-c $(other_language_protoc_outputs) + ./conformance-test-runner --enforce_recommended --failure_list failure_list_php_c.txt --text_format_failure_list text_format_failure_list_php.txt ./conformance-php-c + +# These depend on library paths being properly set up. The easiest way to +# run them is to just use "tox" from the python dir. +test_python: protoc_middleman conformance-test-runner + ./conformance-test-runner --enforce_recommended --failure_list failure_list_python.txt --text_format_failure_list text_format_failure_list_python.txt ./conformance_python.py + +test_python_cpp: protoc_middleman conformance-test-runner + ./conformance-test-runner --enforce_recommended --failure_list failure_list_python_cpp.txt --text_format_failure_list text_format_failure_list_python_cpp.txt ./conformance_python.py + +if OBJC_CONFORMANCE_TEST + +test_objc: protoc_middleman conformance-test-runner conformance-objc + ./conformance-test-runner --enforce_recommended --failure_list failure_list_objc.txt ./conformance-objc + +endif diff --git a/libs/protobuf/conformance/README.md b/libs/protobuf/conformance/README.md index 8569a6a..901d287 100644 --- a/libs/protobuf/conformance/README.md +++ b/libs/protobuf/conformance/README.md @@ -12,77 +12,44 @@ contains all of the tests themselves. Then separate programs written in whatever language you want to test communicate with the tester program over a pipe. -If you're not using Bazel to run these tests, make sure you build the C++ -tester code beforehand, e.g. from the base directory: +Before running any of these tests, make sure you run `make` in the base +directory to build `protoc`, since all the tests depend on it. - $ cmake . -Dprotobuf_BUILD_CONFORMANCE=ON && cmake --build . - -This will produce a `conformance_test_runner` binary that can be used to run -conformance tests on any executable. Pass it `--help` for more information. + $ make Running the tests for C++ ------------------------- To run the tests against the C++ implementation, run: - $ bazel test //src:conformance_test + $ cd conformance && make test_cpp -Or alternatively with CMake: +Running the tests for JavaScript (Node.js) +------------------------------------------ - $ ctest -R conformance_cpp_test +To run the JavaScript tests against Node.js, make sure you have "node" +on your path and then run: + + $ cd conformance && make test_nodejs + +Running the tests for Ruby (MRI) +-------------------------------- + +To run the Ruby tests against MRI, first build the C extension: + + $ cd ruby && rake + +Then run the tests like so: + + $ cd conformance && make test_ruby Running the tests for other languages ------------------------------------- -All of the languages in the Protobuf source tree are set up to run conformance -tests using similar patterns. You can either use Bazel to run the -`conformance_test` target defined in the language's root `BUILD.bazel` file, -or create an executable for a custom test and pass it to -`conformance_test_runner`. - -Note: CMake can be used to build the conformance test runner, but not any of -the conformance test executables outside C++. So if you aren't using Bazel -you'll need to create the executable you pass to `conformance_test_runner` via -some alternate build system. - -While we plan to model all our supported languages more completely in Bazel, -today some of them are a bit tricky to run. Below is a list of the commands -(and prerequisites) to run each language's conformance tests. - -Java: - - $ bazel test //java/core:conformance_test //java/lite:conformance_test - -Python: - - $ bazel test //python:conformance_test - -Python C++: - - $ bazel test //python:conformance_test_cpp --define=use_fast_cpp_protos=true - -C#: - - $ `which dotnet || echo "You must have dotnet installed!" - $ `bazel test //csharp:conformance_test \ - --action_env=DOTNET_CLI_TELEMETRY_OPTOUT=1 --test_env=DOTNET_CLI_HOME=~ \ - --action_env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 - -Objective-c (Mac only): - - $ `bazel test //objectivec:conformance_test --macos_minimum_os=10.9 - -Ruby: - - $ [[ $(ruby --version) == "ruby"* ]] || echo "Select a C Ruby!" - $ bazel test //ruby:conformance_test --define=ruby_platform=c \ - --action_env=PATH --action_env=GEM_PATH --action_env=GEM_HOME - -JRuby: - - $ [[ $(ruby --version) == "jruby"* ]] || echo "Switch to Java Ruby!" - $ bazel test //ruby:conformance_test_jruby --define=ruby_platform=java \ - --action_env=PATH --action_env=GEM_PATH --action_env=GEM_HOME +Most of the languages in the Protobuf source tree are set up to run +conformance tests. However some of them are more tricky to set up +properly. See `tests.sh` in the base of the repository to see how +Kokoro runs the tests. Testing other Protocol Buffer implementations --------------------------------------------- diff --git a/libs/protobuf/conformance/autoload.php b/libs/protobuf/conformance/autoload.php index 7f04cc0..0f49aec 100644 --- a/libs/protobuf/conformance/autoload.php +++ b/libs/protobuf/conformance/autoload.php @@ -7,7 +7,7 @@ define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\"); function protobuf_autoloader_impl($class, $prefix) { $length = strlen($prefix); if ((substr($class, 0, $length) === $prefix)) { - $path = 'php/src/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php'; + $path = '../php/src/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php'; include_once $path; } } diff --git a/libs/protobuf/conformance/binary_json_conformance_suite.cc b/libs/protobuf/conformance/binary_json_conformance_suite.cc index 7c30b83..9b1548d 100644 --- a/libs/protobuf/conformance/binary_json_conformance_suite.cc +++ b/libs/protobuf/conformance/binary_json_conformance_suite.cc @@ -30,17 +30,15 @@ #include "binary_json_conformance_suite.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/util/json_util.h" -#include "google/protobuf/util/type_resolver_util.h" -#include "absl/status/status.h" -#include "absl/strings/str_cat.h" -#include "json/json.h" -#include "conformance/conformance.pb.h" +#include +#include +#include +#include +#include "third_party/jsoncpp/json.h" #include "conformance_test.h" -#include "google/protobuf/test_messages_proto2.pb.h" -#include "google/protobuf/test_messages_proto3.pb.h" +#include +#include +#include namespace proto2_messages = protobuf_test_messages::proto2; @@ -61,10 +59,6 @@ namespace { static const char kTypeUrlPrefix[] = "type.googleapis.com"; -// The number of repetitions to use for performance tests. -// Corresponds approx to 500KB wireformat bytes. -static const size_t kPerformanceRepeatCount = 50000; - static string GetTypeUrl(const Descriptor* message) { return string(kTypeUrlPrefix) + "/" + message->full_name(); } @@ -360,7 +354,7 @@ bool BinaryAndJsonConformanceSuite::ParseJsonResponse( const ConformanceResponse& response, Message* test_message) { string binary_protobuf; - absl::Status status = + util::Status status = JsonToBinaryString(type_resolver_.get(), type_url_, response.json_payload(), &binary_protobuf); @@ -390,7 +384,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse( case ConformanceResponse::kProtobufPayload: { if (requested_output != conformance::PROTOBUF) { ReportFailure(test_name, level, request, response, - absl::StrCat("Test was asked for ", + StrCat("Test was asked for ", WireFormatToString(requested_output), " output but provided PROTOBUF instead.") .c_str()); @@ -409,7 +403,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse( case ConformanceResponse::kJsonPayload: { if (requested_output != conformance::JSON) { ReportFailure(test_name, level, request, response, - absl::StrCat("Test was asked for ", + StrCat("Test was asked for ", WireFormatToString(requested_output), " output but provided JSON instead.") .c_str()); @@ -446,7 +440,7 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForProtoWithProtoVersion ( const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = absl::StrCat( + string effective_test_name = StrCat( setting.ConformanceLevelToString(level), (is_proto3 ? ".Proto3" : ".Proto2"), ".ProtobufInput.", test_name); @@ -482,25 +476,6 @@ void BinaryAndJsonConformanceSuite::RunValidJsonTest( const string& test_name, ConformanceLevel level, const string& input_json, const string& equivalent_text_format) { TestAllTypesProto3 prototype; - RunValidJsonTestWithMessage(test_name, level, input_json, - equivalent_text_format, prototype); -} - -void BinaryAndJsonConformanceSuite::RunValidJsonTest( - const string& test_name, ConformanceLevel level, const string& input_json, - const string& equivalent_text_format, bool is_proto3) { - if (is_proto3) { - RunValidJsonTest(test_name, level, input_json, equivalent_text_format); - } else { - TestAllTypesProto2 prototype; - RunValidJsonTestWithMessage(test_name, level, input_json, - equivalent_text_format, prototype); - } -} - -void BinaryAndJsonConformanceSuite::RunValidJsonTestWithMessage( - const string& test_name, ConformanceLevel level, const string& input_json, - const string& equivalent_text_format, const Message& prototype) { ConformanceRequestSetting setting1( level, conformance::JSON, conformance::PROTOBUF, conformance::JSON_TEST, @@ -574,27 +549,6 @@ void BinaryAndJsonConformanceSuite::RunValidBinaryProtobufTest( RunValidBinaryInputTest(setting, expected_protobuf, true); } -void BinaryAndJsonConformanceSuite::RunBinaryPerformanceMergeMessageWithField( - const string& test_name, const string& field_proto, bool is_proto3) { - string message_tag = tag(27, WireFormatLite::WIRETYPE_LENGTH_DELIMITED); - string message_proto = cat(message_tag, delim(field_proto)); - - string proto; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - proto.append(message_proto); - } - - string multiple_repeated_field_proto; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - multiple_repeated_field_proto.append(field_proto); - } - string expected_proto = - cat(message_tag, delim(multiple_repeated_field_proto)); - - RunValidBinaryProtobufTest(test_name, RECOMMENDED, proto, expected_proto, - is_proto3); -} - void BinaryAndJsonConformanceSuite::RunValidProtobufTestWithMessage( const string& test_name, ConformanceLevel level, const Message *input, const string& equivalent_text_format, bool is_proto3) { @@ -617,7 +571,7 @@ void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; string effective_test_name = - absl::StrCat(setting.ConformanceLevelToString(level), + StrCat(setting.ConformanceLevelToString(level), is_proto3 ? ".Proto3.JsonInput." : ".Proto2.JsonInput.", test_name, ".Validator"); @@ -630,16 +584,16 @@ void BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator( if (response.result_case() != ConformanceResponse::kJsonPayload) { ReportFailure(effective_test_name, level, request, response, - absl::StrCat("Expected JSON payload but got type ", - response.result_case())); + "Expected JSON payload but got type %d.", + response.result_case()); return; } Json::Reader reader; Json::Value value; if (!reader.parse(response.json_payload(), value)) { ReportFailure(effective_test_name, level, request, response, - absl::StrCat("JSON payload cannot be parsed as valid JSON: ", - reader.getFormattedErrorMessages())); + "JSON payload cannot be parsed as valid JSON: %s", + reader.getFormattedErrorMessages().c_str()); return; } if (!validator(value)) { @@ -661,7 +615,7 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson( prototype, test_name, input_json); const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = absl::StrCat( + string effective_test_name = StrCat( setting.ConformanceLevelToString(level), ".Proto3.JsonInput.", test_name); RunTest(effective_test_name, request, &response); @@ -688,7 +642,7 @@ void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson( prototype, test_name, payload_message.SerializeAsString()); const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; - string effective_test_name = absl::StrCat( + string effective_test_name = StrCat( setting.ConformanceLevelToString(level), ".", test_name, ".JsonOutput"); RunTest(effective_test_name, request, &response); @@ -811,14 +765,13 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( : cat(tag(field->number(), wire_type), values[i].second); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest( - absl::StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED, + StrCat("ValidDataScalar", type_name, "[", i, "]"), REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest( - absl::StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), + StrCat("ValidDataScalarBinary", type_name, "[", i, "]"), RECOMMENDED, proto, expected_proto, is_proto3); } @@ -834,8 +787,7 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( cat(tag(field->number(), wire_type), values.back().second); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED, proto, text, is_proto3); @@ -896,15 +848,14 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(default_proto_packed_expected); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); // Ensures both packed and unpacked data can be parsed. RunValidProtobufTest( - absl::StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), + StrCat("ValidDataRepeated", type_name, ".UnpackedInput"), REQUIRED, default_proto_unpacked, text, is_proto3); RunValidProtobufTest( - absl::StrCat("ValidDataRepeated", type_name, ".PackedInput"), + StrCat("ValidDataRepeated", type_name, ".PackedInput"), REQUIRED, default_proto_packed, text, is_proto3); // proto2 should encode as unpacked by default and proto3 should encode as @@ -912,27 +863,27 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( string expected_proto = rep_field->is_packed() ? default_proto_packed_expected : default_proto_unpacked_expected; - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".UnpackedInput.DefaultOutput"), RECOMMENDED, default_proto_unpacked, expected_proto, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".PackedInput.DefaultOutput"), RECOMMENDED, default_proto_packed, expected_proto, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".UnpackedInput.PackedOutput"), RECOMMENDED, packed_proto_unpacked, packed_proto_expected, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".PackedInput.PackedOutput"), RECOMMENDED, packed_proto_packed, packed_proto_expected, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".UnpackedInput.UnpackedOutput"), RECOMMENDED, unpacked_proto_unpacked, unpacked_proto_expected, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataRepeated", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataRepeated", type_name, ".PackedInput.UnpackedOutput"), RECOMMENDED, unpacked_proto_packed, unpacked_proto_expected, is_proto3); @@ -946,10 +897,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForType( } std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); - RunValidProtobufTest(absl::StrCat("ValidDataRepeated", type_name), + RunValidProtobufTest(StrCat("ValidDataRepeated", type_name), REQUIRED, proto, text, is_proto3); } } @@ -1024,9 +974,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key1_data, value1_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); - RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, + string text = test_message->DebugString(); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, value_type_name, ".Default"), REQUIRED, proto, text, is_proto3); } @@ -1038,9 +987,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim("")); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); - RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, + string text = test_message->DebugString(); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, value_type_name, ".MissingDefault"), REQUIRED, proto, text, is_proto3); } @@ -1052,9 +1000,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key2_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); - RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, + string text = test_message->DebugString(); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, value_type_name, ".NonDefault"), REQUIRED, proto, text, is_proto3); } @@ -1066,9 +1013,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(value2_data, key2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); - RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, + string text = test_message->DebugString(); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, value_type_name, ".Unordered"), REQUIRED, proto, text, is_proto3); } @@ -1084,9 +1030,8 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( string proto = cat(proto1, proto2); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto2); - string text; - TextFormat::PrintToString(*test_message, &text); - RunValidProtobufTest(absl::StrCat("ValidDataMap", key_type_name, + string text = test_message->DebugString(); + RunValidProtobufTest(StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateKey"), REQUIRED, proto, text, is_proto3); } @@ -1098,10 +1043,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key1_data, key2_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest( - absl::StrCat("ValidDataMap", key_type_name, value_type_name, + StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateKeyInMapEntry"), REQUIRED, proto, text, is_proto3); } @@ -1113,10 +1057,9 @@ void BinaryAndJsonConformanceSuite::TestValidDataForMapType( delim(cat(key2_data, value1_data, value2_data))); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest( - absl::StrCat("ValidDataMap", key_type_name, value_type_name, + StrCat("ValidDataMap", key_type_name, value_type_name, ".DuplicateValueInMapEntry"), REQUIRED, proto, text, is_proto3); } @@ -1154,8 +1097,7 @@ void BinaryAndJsonConformanceSuite::TestOverwriteMessageValueMap() { string proto = cat(proto1, proto2); std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto2); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest("ValidDataMap.STRING.MESSAGE.MergeValue", REQUIRED, proto, text, is_proto3); } @@ -1180,14 +1122,13 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string proto = default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest( - absl::StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED, + StrCat("ValidDataOneof", type_name, ".DefaultValue"), REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest( - absl::StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"), + StrCat("ValidDataOneofBinary", type_name, ".DefaultValue"), RECOMMENDED, proto, proto, is_proto3); } @@ -1196,30 +1137,28 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( const string proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest( - absl::StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), + StrCat("ValidDataOneof", type_name, ".NonDefaultValue"), REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest( - absl::StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"), + StrCat("ValidDataOneofBinary", type_name, ".NonDefaultValue"), RECOMMENDED, proto, proto, is_proto3); } { // Tests oneof with multiple values of the same field. - const string proto = absl::StrCat(default_value, non_default_value); + const string proto = StrCat(default_value, non_default_value); const string expected_proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); - RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name, + RunValidProtobufTest(StrCat("ValidDataOneof", type_name, ".MultipleValuesForSameField"), REQUIRED, proto, text, is_proto3); - RunValidBinaryProtobufTest(absl::StrCat("ValidDataOneofBinary", type_name, + RunValidBinaryProtobufTest(StrCat("ValidDataOneofBinary", type_name, ".MultipleValuesForSameField"), RECOMMENDED, proto, expected_proto, is_proto3); } @@ -1236,18 +1175,17 @@ void BinaryAndJsonConformanceSuite::TestValidDataForOneofType( cat(tag(other_field->number(), other_wire_type), GetDefaultValue(other_type)); - const string proto = absl::StrCat(other_value, non_default_value); + const string proto = StrCat(other_value, non_default_value); const string expected_proto = non_default_value; std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); - RunValidProtobufTest(absl::StrCat("ValidDataOneof", type_name, + RunValidProtobufTest(StrCat("ValidDataOneof", type_name, ".MultipleValuesForDifferentField"), REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest( - absl::StrCat("ValidDataOneofBinary", type_name, + StrCat("ValidDataOneofBinary", type_name, ".MultipleValuesForDifferentField"), RECOMMENDED, proto, expected_proto, is_proto3); } @@ -1286,8 +1224,7 @@ void BinaryAndJsonConformanceSuite::TestMergeOneofMessage() { std::unique_ptr test_message = NewTestMessage(is_proto3); test_message->MergeFromString(expected_proto); - string text; - TextFormat::PrintToString(*test_message, &text); + string text = test_message->DebugString(); RunValidProtobufTest("ValidDataOneof.MESSAGE.Merge", REQUIRED, proto, text, is_proto3); RunValidBinaryProtobufTest("ValidDataOneofBinary.MESSAGE.Merge", @@ -1356,60 +1293,6 @@ void BinaryAndJsonConformanceSuite::TestUnknownMessage( message.SerializeAsString(), is_proto3); } -void BinaryAndJsonConformanceSuite:: - TestBinaryPerformanceForAlternatingUnknownFields() { - string unknown_field_1 = - cat(tag(UNKNOWN_FIELD, WireFormatLite::WIRETYPE_VARINT), varint(1234)); - string unknown_field_2 = cat( - tag(UNKNOWN_FIELD + 1, WireFormatLite::WIRETYPE_VARINT), varint(5678)); - for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) { - string proto; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - proto.append(unknown_field_1); - proto.append(unknown_field_2); - } - - RunValidBinaryProtobufTest( - "TestBinaryPerformanceForAlternatingUnknownFields", RECOMMENDED, proto, - is_proto3); - } -} - -void BinaryAndJsonConformanceSuite:: - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::Type type) { - const string type_name = - UpperCase(string(".") + FieldDescriptor::TypeName(type)); - for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) { - int field_number = - GetFieldForType(type, true, is_proto3, Packed::kFalse)->number(); - string rep_field_proto = cat( - tag(field_number, WireFormatLite::WireTypeForFieldType( - static_cast(type))), - GetNonDefaultValue(type)); - - RunBinaryPerformanceMergeMessageWithField( - "TestBinaryPerformanceMergeMessageWithRepeatedFieldForType" + type_name, - rep_field_proto, is_proto3); - } -} - -void BinaryAndJsonConformanceSuite:: - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::Type type) { - const string type_name = - UpperCase(string(".") + FieldDescriptor::TypeName(type)); - string unknown_field_proto = - cat(tag(UNKNOWN_FIELD, WireFormatLite::WireTypeForFieldType( - static_cast(type))), - GetNonDefaultValue(type)); - for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) { - RunBinaryPerformanceMergeMessageWithField( - "TestBinaryPerformanceMergeMessageWithUnknownFieldForType" + type_name, - unknown_field_proto, is_proto3); - } -} - void BinaryAndJsonConformanceSuite::RunSuiteImpl() { // Hack to get the list of test failures based on whether // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not. @@ -1429,324 +1312,232 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { kTypeUrlPrefix, DescriptorPool::generated_pool())); type_url_ = GetTypeUrl(TestAllTypesProto3::descriptor()); - if (!performance_) { - for (int i = 1; i <= FieldDescriptor::MAX_TYPE; i++) { - if (i == FieldDescriptor::TYPE_GROUP) continue; - TestPrematureEOFForType(static_cast(i)); - } - - TestIllegalTags(); - - int64 kInt64Min = -9223372036854775808ULL; - int64 kInt64Max = 9223372036854775807ULL; - uint64 kUint64Max = 18446744073709551615ULL; - int32 kInt32Max = 2147483647; - int32 kInt32Min = -2147483648; - uint32 kUint32Max = 4294967295UL; - - TestValidDataForType( - FieldDescriptor::TYPE_DOUBLE, - { - {dbl(0), dbl(0)}, - {dbl(0.1), dbl(0.1)}, - {dbl(1.7976931348623157e+308), dbl(1.7976931348623157e+308)}, - {dbl(2.22507385850720138309e-308), - dbl(2.22507385850720138309e-308)}, - }); - TestValidDataForType( - FieldDescriptor::TYPE_FLOAT, - { - {flt(0), flt(0)}, - {flt(0.1), flt(0.1)}, - {flt(1.00000075e-36), flt(1.00000075e-36)}, - {flt(3.402823e+38), flt(3.402823e+38)}, // 3.40282347e+38 - {flt(1.17549435e-38f), flt(1.17549435e-38)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_INT64, - { - {varint(0), varint(0)}, - {varint(12345), varint(12345)}, - {varint(kInt64Max), varint(kInt64Max)}, - {varint(kInt64Min), varint(kInt64Min)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_UINT64, - { - {varint(0), varint(0)}, - {varint(12345), varint(12345)}, - {varint(kUint64Max), varint(kUint64Max)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_INT32, - { - {varint(0), varint(0)}, - {varint(12345), varint(12345)}, - {longvarint(12345, 2), varint(12345)}, - {longvarint(12345, 7), varint(12345)}, - {varint(kInt32Max), varint(kInt32Max)}, - {varint(kInt32Min), varint(kInt32Min)}, - {varint(1LL << 33), varint(0)}, - {varint((1LL << 33) - 1), varint(-1)}, - {varint(kInt64Max), varint(-1)}, - {varint(kInt64Min + 1), varint(1)}, - }); - TestValidDataForType( - FieldDescriptor::TYPE_UINT32, - { - {varint(0), varint(0)}, - {varint(12345), varint(12345)}, - {longvarint(12345, 2), varint(12345)}, - {longvarint(12345, 7), varint(12345)}, - {varint(kUint32Max), varint(kUint32Max)}, // UINT32_MAX - {varint(1LL << 33), varint(0)}, - {varint((1LL << 33) + 1), varint(1)}, - {varint((1LL << 33) - 1), varint((1LL << 32) - 1)}, - {varint(kInt64Max), varint((1LL << 32) - 1)}, - {varint(kInt64Min + 1), varint(1)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_FIXED64, - { - {u64(0), u64(0)}, - {u64(12345), u64(12345)}, - {u64(kUint64Max), u64(kUint64Max)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_FIXED32, - { - {u32(0), u32(0)}, - {u32(12345), u32(12345)}, - {u32(kUint32Max), u32(kUint32Max)}, // UINT32_MAX - }); - TestValidDataForType(FieldDescriptor::TYPE_SFIXED64, - { - {u64(0), u64(0)}, - {u64(12345), u64(12345)}, - {u64(kInt64Max), u64(kInt64Max)}, - {u64(kInt64Min), u64(kInt64Min)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_SFIXED32, - { - {u32(0), u32(0)}, - {u32(12345), u32(12345)}, - {u32(kInt32Max), u32(kInt32Max)}, - {u32(kInt32Min), u32(kInt32Min)}, - }); - // Bools should be serialized as 0 for false and 1 for true. Parsers should - // also interpret any nonzero value as true. - TestValidDataForType(FieldDescriptor::TYPE_BOOL, - { - {varint(0), varint(0)}, - {varint(1), varint(1)}, - {varint(-1), varint(1)}, - {varint(12345678), varint(1)}, - {varint(1LL << 33), varint(1)}, - {varint(kInt64Max), varint(1)}, - {varint(kInt64Min), varint(1)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_SINT32, - { - {zz32(0), zz32(0)}, - {zz32(12345), zz32(12345)}, - {zz32(kInt32Max), zz32(kInt32Max)}, - {zz32(kInt32Min), zz32(kInt32Min)}, - {zz64(kInt32Max + 2LL), zz32(1)}, - }); - TestValidDataForType(FieldDescriptor::TYPE_SINT64, - { - {zz64(0), zz64(0)}, - {zz64(12345), zz64(12345)}, - {zz64(kInt64Max), zz64(kInt64Max)}, - {zz64(kInt64Min), zz64(kInt64Min)}, - }); - TestValidDataForType( - FieldDescriptor::TYPE_STRING, - { - {delim(""), delim("")}, - {delim("Hello world!"), delim("Hello world!")}, - {delim("\'\"\?\\\a\b\f\n\r\t\v"), - delim("\'\"\?\\\a\b\f\n\r\t\v")}, // escape - {delim("谷歌"), delim("谷歌")}, // Google in Chinese - {delim("\u8C37\u6B4C"), delim("谷歌")}, // unicode escape - {delim("\u8c37\u6b4c"), delim("谷歌")}, // lowercase unicode - {delim("\xF0\x9F\x98\x81"), delim("\xF0\x9F\x98\x81")}, // emoji: 😁 - }); - TestValidDataForType(FieldDescriptor::TYPE_BYTES, - { - {delim(""), delim("")}, - {delim("Hello world!"), delim("Hello world!")}, - {delim("\x01\x02"), delim("\x01\x02")}, - {delim("\xfb"), delim("\xfb")}, - }); - TestValidDataForType(FieldDescriptor::TYPE_ENUM, - { - {varint(0), varint(0)}, - {varint(1), varint(1)}, - {varint(2), varint(2)}, - {varint(-1), varint(-1)}, - {varint(kInt64Max), varint(-1)}, - {varint(kInt64Min + 1), varint(1)}, - }); - TestValidDataForRepeatedScalarMessage(); - TestValidDataForType( - FieldDescriptor::TYPE_MESSAGE, - { - {delim(""), delim("")}, - {delim(cat(tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234))), - delim(cat(tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234)))}, - }); - - TestValidDataForMapType(FieldDescriptor::TYPE_INT32, - FieldDescriptor::TYPE_INT32); - TestValidDataForMapType(FieldDescriptor::TYPE_INT64, - FieldDescriptor::TYPE_INT64); - TestValidDataForMapType(FieldDescriptor::TYPE_UINT32, - FieldDescriptor::TYPE_UINT32); - TestValidDataForMapType(FieldDescriptor::TYPE_UINT64, - FieldDescriptor::TYPE_UINT64); - TestValidDataForMapType(FieldDescriptor::TYPE_SINT32, - FieldDescriptor::TYPE_SINT32); - TestValidDataForMapType(FieldDescriptor::TYPE_SINT64, - FieldDescriptor::TYPE_SINT64); - TestValidDataForMapType(FieldDescriptor::TYPE_FIXED32, - FieldDescriptor::TYPE_FIXED32); - TestValidDataForMapType(FieldDescriptor::TYPE_FIXED64, - FieldDescriptor::TYPE_FIXED64); - TestValidDataForMapType(FieldDescriptor::TYPE_SFIXED32, - FieldDescriptor::TYPE_SFIXED32); - TestValidDataForMapType(FieldDescriptor::TYPE_SFIXED64, - FieldDescriptor::TYPE_SFIXED64); - TestValidDataForMapType(FieldDescriptor::TYPE_INT32, - FieldDescriptor::TYPE_FLOAT); - TestValidDataForMapType(FieldDescriptor::TYPE_INT32, - FieldDescriptor::TYPE_DOUBLE); - TestValidDataForMapType(FieldDescriptor::TYPE_BOOL, - FieldDescriptor::TYPE_BOOL); - TestValidDataForMapType(FieldDescriptor::TYPE_STRING, - FieldDescriptor::TYPE_STRING); - TestValidDataForMapType(FieldDescriptor::TYPE_STRING, - FieldDescriptor::TYPE_BYTES); - TestValidDataForMapType(FieldDescriptor::TYPE_STRING, - FieldDescriptor::TYPE_ENUM); - TestValidDataForMapType(FieldDescriptor::TYPE_STRING, - FieldDescriptor::TYPE_MESSAGE); - // Additional test to check overwriting message value map. - TestOverwriteMessageValueMap(); - - TestValidDataForOneofType(FieldDescriptor::TYPE_UINT32); - TestValidDataForOneofType(FieldDescriptor::TYPE_BOOL); - TestValidDataForOneofType(FieldDescriptor::TYPE_UINT64); - TestValidDataForOneofType(FieldDescriptor::TYPE_FLOAT); - TestValidDataForOneofType(FieldDescriptor::TYPE_DOUBLE); - TestValidDataForOneofType(FieldDescriptor::TYPE_STRING); - TestValidDataForOneofType(FieldDescriptor::TYPE_BYTES); - TestValidDataForOneofType(FieldDescriptor::TYPE_ENUM); - TestValidDataForOneofType(FieldDescriptor::TYPE_MESSAGE); - // Additional test to check merging oneof message. - TestMergeOneofMessage(); - - // TODO(haberman): - // TestValidDataForType(FieldDescriptor::TYPE_GROUP - - // Unknown fields. - { - TestAllTypesProto3 messageProto3; - TestAllTypesProto2 messageProto2; - // TODO(yilunchong): update this behavior when unknown field's behavior - // changed in open source. Also delete - // Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput - // from failure list of python_cpp python java - TestUnknownMessage(messageProto3, true); - TestUnknownMessage(messageProto2, false); - } - - RunJsonTests(); + for (int i = 1; i <= FieldDescriptor::MAX_TYPE; i++) { + if (i == FieldDescriptor::TYPE_GROUP) continue; + TestPrematureEOFForType(static_cast(i)); } - // Flag control performance tests to keep them internal and opt-in only - if (performance_) { - RunBinaryPerformanceTests(); - RunJsonPerformanceTests(); + + TestIllegalTags(); + + int64 kInt64Min = -9223372036854775808ULL; + int64 kInt64Max = 9223372036854775807ULL; + uint64 kUint64Max = 18446744073709551615ULL; + int32 kInt32Max = 2147483647; + int32 kInt32Min = -2147483648; + uint32 kUint32Max = 4294967295UL; + + TestValidDataForType( + FieldDescriptor::TYPE_DOUBLE, + { + {dbl(0), dbl(0)}, + {dbl(0.1), dbl(0.1)}, + {dbl(1.7976931348623157e+308), dbl(1.7976931348623157e+308)}, + {dbl(2.22507385850720138309e-308), dbl(2.22507385850720138309e-308)}, + }); + TestValidDataForType( + FieldDescriptor::TYPE_FLOAT, + { + {flt(0), flt(0)}, + {flt(0.1), flt(0.1)}, + {flt(1.00000075e-36), flt(1.00000075e-36)}, + {flt(3.402823e+38), flt(3.402823e+38)}, // 3.40282347e+38 + {flt(1.17549435e-38f), flt(1.17549435e-38)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_INT64, + { + {varint(0), varint(0)}, + {varint(12345), varint(12345)}, + {varint(kInt64Max), varint(kInt64Max)}, + {varint(kInt64Min), varint(kInt64Min)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_UINT64, + { + {varint(0), varint(0)}, + {varint(12345), varint(12345)}, + {varint(kUint64Max), varint(kUint64Max)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_INT32, + { + {varint(0), varint(0)}, + {varint(12345), varint(12345)}, + {longvarint(12345, 2), varint(12345)}, + {longvarint(12345, 7), varint(12345)}, + {varint(kInt32Max), varint(kInt32Max)}, + {varint(kInt32Min), varint(kInt32Min)}, + {varint(1LL << 33), varint(0)}, + {varint((1LL << 33) - 1), varint(-1)}, + {varint(kInt64Max), varint(-1)}, + {varint(kInt64Min + 1), varint(1)}, + }); + TestValidDataForType( + FieldDescriptor::TYPE_UINT32, + { + {varint(0), varint(0)}, + {varint(12345), varint(12345)}, + {longvarint(12345, 2), varint(12345)}, + {longvarint(12345, 7), varint(12345)}, + {varint(kUint32Max), varint(kUint32Max)}, // UINT32_MAX + {varint(1LL << 33), varint(0)}, + {varint((1LL << 33) + 1), varint(1)}, + {varint((1LL << 33) - 1), varint((1LL << 32) - 1)}, + {varint(kInt64Max), varint((1LL << 32) - 1)}, + {varint(kInt64Min + 1), varint(1)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_FIXED64, + { + {u64(0), u64(0)}, + {u64(12345), u64(12345)}, + {u64(kUint64Max), u64(kUint64Max)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_FIXED32, + { + {u32(0), u32(0)}, + {u32(12345), u32(12345)}, + {u32(kUint32Max), u32(kUint32Max)}, // UINT32_MAX + }); + TestValidDataForType(FieldDescriptor::TYPE_SFIXED64, + { + {u64(0), u64(0)}, + {u64(12345), u64(12345)}, + {u64(kInt64Max), u64(kInt64Max)}, + {u64(kInt64Min), u64(kInt64Min)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_SFIXED32, + { + {u32(0), u32(0)}, + {u32(12345), u32(12345)}, + {u32(kInt32Max), u32(kInt32Max)}, + {u32(kInt32Min), u32(kInt32Min)}, + }); + // Bools should be serialized as 0 for false and 1 for true. Parsers should + // also interpret any nonzero value as true. + TestValidDataForType(FieldDescriptor::TYPE_BOOL, + { + {varint(0), varint(0)}, + {varint(1), varint(1)}, + {varint(-1), varint(1)}, + {varint(12345678), varint(1)}, + {varint(1LL << 33), varint(1)}, + {varint(kInt64Max), varint(1)}, + {varint(kInt64Min), varint(1)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_SINT32, + { + {zz32(0), zz32(0)}, + {zz32(12345), zz32(12345)}, + {zz32(kInt32Max), zz32(kInt32Max)}, + {zz32(kInt32Min), zz32(kInt32Min)}, + {zz64(kInt32Max + 2LL), zz32(1)}, + }); + TestValidDataForType(FieldDescriptor::TYPE_SINT64, + { + {zz64(0), zz64(0)}, + {zz64(12345), zz64(12345)}, + {zz64(kInt64Max), zz64(kInt64Max)}, + {zz64(kInt64Min), zz64(kInt64Min)}, + }); + TestValidDataForType( + FieldDescriptor::TYPE_STRING, + { + {delim(""), delim("")}, + {delim("Hello world!"), delim("Hello world!")}, + {delim("\'\"\?\\\a\b\f\n\r\t\v"), + delim("\'\"\?\\\a\b\f\n\r\t\v")}, // escape + {delim("谷歌"), delim("谷歌")}, // Google in Chinese + {delim("\u8C37\u6B4C"), delim("谷歌")}, // unicode escape + {delim("\u8c37\u6b4c"), delim("谷歌")}, // lowercase unicode + {delim("\xF0\x9F\x98\x81"), delim("\xF0\x9F\x98\x81")}, // emoji: 😁 + }); + TestValidDataForType(FieldDescriptor::TYPE_BYTES, + { + {delim(""), delim("")}, + {delim("Hello world!"), delim("Hello world!")}, + {delim("\x01\x02"), delim("\x01\x02")}, + {delim("\xfb"), delim("\xfb")}, + }); + TestValidDataForType(FieldDescriptor::TYPE_ENUM, + { + {varint(0), varint(0)}, + {varint(1), varint(1)}, + {varint(2), varint(2)}, + {varint(-1), varint(-1)}, + {varint(kInt64Max), varint(-1)}, + {varint(kInt64Min + 1), varint(1)}, + }); + TestValidDataForRepeatedScalarMessage(); + TestValidDataForType( + FieldDescriptor::TYPE_MESSAGE, + { + {delim(""), delim("")}, + {delim(cat(tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234))), + delim(cat(tag(1, WireFormatLite::WIRETYPE_VARINT), varint(1234)))}, + }); + + TestValidDataForMapType(FieldDescriptor::TYPE_INT32, + FieldDescriptor::TYPE_INT32); + TestValidDataForMapType(FieldDescriptor::TYPE_INT64, + FieldDescriptor::TYPE_INT64); + TestValidDataForMapType(FieldDescriptor::TYPE_UINT32, + FieldDescriptor::TYPE_UINT32); + TestValidDataForMapType(FieldDescriptor::TYPE_UINT64, + FieldDescriptor::TYPE_UINT64); + TestValidDataForMapType(FieldDescriptor::TYPE_SINT32, + FieldDescriptor::TYPE_SINT32); + TestValidDataForMapType(FieldDescriptor::TYPE_SINT64, + FieldDescriptor::TYPE_SINT64); + TestValidDataForMapType(FieldDescriptor::TYPE_FIXED32, + FieldDescriptor::TYPE_FIXED32); + TestValidDataForMapType(FieldDescriptor::TYPE_FIXED64, + FieldDescriptor::TYPE_FIXED64); + TestValidDataForMapType(FieldDescriptor::TYPE_SFIXED32, + FieldDescriptor::TYPE_SFIXED32); + TestValidDataForMapType(FieldDescriptor::TYPE_SFIXED64, + FieldDescriptor::TYPE_SFIXED64); + TestValidDataForMapType(FieldDescriptor::TYPE_INT32, + FieldDescriptor::TYPE_FLOAT); + TestValidDataForMapType(FieldDescriptor::TYPE_INT32, + FieldDescriptor::TYPE_DOUBLE); + TestValidDataForMapType(FieldDescriptor::TYPE_BOOL, + FieldDescriptor::TYPE_BOOL); + TestValidDataForMapType(FieldDescriptor::TYPE_STRING, + FieldDescriptor::TYPE_STRING); + TestValidDataForMapType(FieldDescriptor::TYPE_STRING, + FieldDescriptor::TYPE_BYTES); + TestValidDataForMapType(FieldDescriptor::TYPE_STRING, + FieldDescriptor::TYPE_ENUM); + TestValidDataForMapType(FieldDescriptor::TYPE_STRING, + FieldDescriptor::TYPE_MESSAGE); + // Additional test to check overwriting message value map. + TestOverwriteMessageValueMap(); + + TestValidDataForOneofType(FieldDescriptor::TYPE_UINT32); + TestValidDataForOneofType(FieldDescriptor::TYPE_BOOL); + TestValidDataForOneofType(FieldDescriptor::TYPE_UINT64); + TestValidDataForOneofType(FieldDescriptor::TYPE_FLOAT); + TestValidDataForOneofType(FieldDescriptor::TYPE_DOUBLE); + TestValidDataForOneofType(FieldDescriptor::TYPE_STRING); + TestValidDataForOneofType(FieldDescriptor::TYPE_BYTES); + TestValidDataForOneofType(FieldDescriptor::TYPE_ENUM); + TestValidDataForOneofType(FieldDescriptor::TYPE_MESSAGE); + // Additional test to check merging oneof message. + TestMergeOneofMessage(); + + // TODO(haberman): + // TestValidDataForType(FieldDescriptor::TYPE_GROUP + + // Unknown fields. + { + TestAllTypesProto3 messageProto3; + TestAllTypesProto2 messageProto2; + // TODO(yilunchong): update this behavior when unknown field's behavior + // changed in open source. Also delete + // Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput + // from failure list of python_cpp python java + TestUnknownMessage(messageProto3, true); + TestUnknownMessage(messageProto2, false); } -} -void BinaryAndJsonConformanceSuite::RunBinaryPerformanceTests() { - TestBinaryPerformanceForAlternatingUnknownFields(); - - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_BOOL); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_DOUBLE); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_FLOAT); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_UINT32); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_UINT64); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_STRING); - TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_BYTES); - - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_BOOL); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_DOUBLE); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_FLOAT); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_UINT32); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_UINT64); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_STRING); - TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - FieldDescriptor::TYPE_BYTES); -} - -void BinaryAndJsonConformanceSuite::RunJsonPerformanceTests() { - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_BOOL, "true"); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_DOUBLE, "123"); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_FLOAT, "123"); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_UINT32, "123"); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_UINT64, "123"); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_STRING, "\"foo\""); - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::TYPE_BYTES, "\"foo\""); -} - -// This is currently considered valid input by some languages but not others -void BinaryAndJsonConformanceSuite:: - TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - FieldDescriptor::Type type, string field_value) { - const string type_name = - UpperCase(string(".") + FieldDescriptor::TypeName(type)); - for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) { - const FieldDescriptor* field = - GetFieldForType(type, true, is_proto3, Packed::kFalse); - string field_name = field->name(); - - string message_field = "\"" + field_name + "\": [" + field_value + "]"; - string recursive_message = - "\"recursive_message\": { " + message_field + "}"; - string input = "{"; - input.append(recursive_message); - for (size_t i = 1; i < kPerformanceRepeatCount; i++) { - input.append("," + recursive_message); - } - input.append("}"); - - string textproto_message_field = field_name + ": " + field_value; - string expected_textproto = "recursive_message { "; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - expected_textproto.append(textproto_message_field + " "); - } - expected_textproto.append("}"); - RunValidJsonTest( - "TestJsonPerformanceMergeMessageWithRepeatedFieldForType" + type_name, - RECOMMENDED, input, expected_textproto, is_proto3); - } + RunJsonTests(); } void BinaryAndJsonConformanceSuite::RunJsonTests() { @@ -2933,12 +2724,6 @@ void BinaryAndJsonConformanceSuite::RunJsonTestsForWrapperTypes() { "DurationNull", REQUIRED, R"({"optionalDuration": null})", ""); - RunValidJsonTest("DurationNegativeSeconds", REQUIRED, - R"({"optionalDuration": "-5s"})", - "optional_duration: {seconds: -5 nanos: 0}"); - RunValidJsonTest("DurationNegativeNanos", REQUIRED, - R"({"optionalDuration": "-0.5s"})", - "optional_duration: {seconds: 0 nanos: -500000000}"); ExpectParseFailureForJson( "DurationMissingS", REQUIRED, diff --git a/libs/protobuf/conformance/binary_json_conformance_suite.h b/libs/protobuf/conformance/binary_json_conformance_suite.h index e45a92f..280ff95 100644 --- a/libs/protobuf/conformance/binary_json_conformance_suite.h +++ b/libs/protobuf/conformance/binary_json_conformance_suite.h @@ -31,8 +31,7 @@ #ifndef CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H #define CONFORMANCE_BINARY_JSON_CONFORMANCE_SUITE_H -#include "google/protobuf/descriptor.h" -#include "json/json.h" +#include "third_party/jsoncpp/json.h" #include "conformance_test.h" namespace google { @@ -44,8 +43,6 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { private: void RunSuiteImpl() override; - void RunBinaryPerformanceTests(); - void RunJsonPerformanceTests(); void RunJsonTests(); void RunJsonTestsForFieldNameConvention(); void RunJsonTestsForNonRepeatedTypes(); @@ -59,15 +56,6 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { void RunValidJsonTest(const std::string& test_name, ConformanceLevel level, const std::string& input_json, const std::string& equivalent_text_format); - void RunValidJsonTest(const std::string& test_name, ConformanceLevel level, - const std::string& input_json, - const std::string& equivalent_text_format, - bool is_proto3); - void RunValidJsonTestWithMessage(const std::string& test_name, - ConformanceLevel level, - const std::string& input_json, - const std::string& equivalent_text_forma, - const Message& prototype); void RunValidJsonTestWithProtobufInput( const std::string& test_name, ConformanceLevel level, const protobuf_test_messages::proto3::TestAllTypesProto3& input, @@ -90,10 +78,6 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { const std::string& input_protobuf, const std::string& expected_protobuf, bool is_proto3); - void RunBinaryPerformanceMergeMessageWithField(const std::string& test_name, - const std::string& field_proto, - bool is_proto3); - void RunValidProtobufTestWithMessage( const std::string& test_name, ConformanceLevel level, const Message* input, const std::string& equivalent_text_format, @@ -146,13 +130,6 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite { void TestValidDataForOneofType(google::protobuf::FieldDescriptor::Type); void TestMergeOneofMessage(); void TestOverwriteMessageValueMap(); - void TestBinaryPerformanceForAlternatingUnknownFields(); - void TestBinaryPerformanceMergeMessageWithRepeatedFieldForType( - google::protobuf::FieldDescriptor::Type); - void TestBinaryPerformanceMergeMessageWithUnknownFieldForType( - google::protobuf::FieldDescriptor::Type); - void TestJsonPerformanceMergeMessageWithRepeatedFieldForType( - google::protobuf::FieldDescriptor::Type, std::string field_value); std::unique_ptr type_resolver_; std::string type_url_; diff --git a/libs/protobuf/conformance/conformance.proto b/libs/protobuf/conformance/conformance.proto index a213437..7248e98 100644 --- a/libs/protobuf/conformance/conformance.proto +++ b/libs/protobuf/conformance/conformance.proto @@ -29,11 +29,8 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. syntax = "proto3"; - package conformance; - option java_package = "com.google.protobuf.conformance"; -option objc_class_prefix = "Conformance"; // This defines the conformance testing protocol. This protocol exists between // the conformance test suite itself and the code being tested. For each test, @@ -72,8 +69,7 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; - // Test jspb wire format. Google internal only. Opensource testees just skip - // it. + // Test jspb wire format. Google internal only. Opensource testees just skip it. JSPB_TEST = 4; // Test text format. For cpp, java and python, testees can already deal with // this type. Testees of other languages can simply skip it. @@ -96,6 +92,10 @@ message ConformanceRequest { // The payload (whether protobuf of JSON) is always for a // protobuf_test_messages.proto3.TestAllTypes proto (as defined in // src/google/protobuf/proto3_test_messages.proto). + // + // TODO(haberman): if/when we expand the conformance tests to support proto2, + // we will want to include a field that lets the payload/response be a + // protobuf_test_messages.google.protobuf.TestAllTypes message instead. oneof payload { bytes protobuf_payload = 1; string json_payload = 2; @@ -113,8 +113,8 @@ message ConformanceRequest { string message_type = 4; // Each test is given a specific test category. Some category may need - // specific support in testee programs. Refer to the definition of - // TestCategory for more information. + // specific support in testee programs. Refer to the definition of TestCategory + // for more information. TestCategory test_category = 5; // Specify details for how to encode jspb. @@ -140,11 +140,6 @@ message ConformanceResponse { // this field. string serialize_error = 6; - // This should be set if the test program timed out. The string should - // provide more information about what the child process was doing when it - // was killed. - string timeout_error = 9; - // This should be set if some other error occurred. This will always // indicate that the test failed. The string can provide more information // about the failure. @@ -178,3 +173,4 @@ message JspbEncodingConfig { // Encode the value field of Any as jspb array if true, otherwise binary. bool use_jspb_array_any_format = 1; } + diff --git a/libs/protobuf/conformance/conformance_cpp.cc b/libs/protobuf/conformance/conformance_cpp.cc index eef8a40..5782789 100644 --- a/libs/protobuf/conformance/conformance_cpp.cc +++ b/libs/protobuf/conformance/conformance_cpp.cc @@ -32,175 +32,165 @@ #include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include "conformance.pb.h" +#include +#include +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/message.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/util/json_util.h" -#include "google/protobuf/util/type_resolver_util.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "conformance/conformance.pb.h" -#include "conformance/conformance.pb.h" -#include "google/protobuf/test_messages_proto2.pb.h" -#include "google/protobuf/test_messages_proto3.pb.h" -#include "google/protobuf/test_messages_proto3.pb.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/stubs/status_macros.h" +using conformance::ConformanceRequest; +using conformance::ConformanceResponse; +using google::protobuf::Descriptor; +using google::protobuf::DescriptorPool; +using google::protobuf::Message; +using google::protobuf::MessageFactory; +using google::protobuf::TextFormat; +using google::protobuf::util::BinaryToJsonString; +using google::protobuf::util::JsonParseOptions; +using google::protobuf::util::JsonToBinaryString; +using google::protobuf::util::NewTypeResolverForDescriptorPool; +using google::protobuf::util::TypeResolver; +using protobuf_test_messages::proto3::TestAllTypesProto3; +using protobuf_test_messages::proto2::TestAllTypesProto2; +using std::string; -// Must be included last. -#include "google/protobuf/port_def.inc" +static const char kTypeUrlPrefix[] = "type.googleapis.com"; + +const char* kFailures[] = { +}; + +static string GetTypeUrl(const Descriptor* message) { + return string(kTypeUrlPrefix) + "/" + message->full_name(); +} + +int test_count = 0; +bool verbose = false; +TypeResolver* type_resolver; +string* type_url; namespace google { namespace protobuf { -namespace { -using ::conformance::ConformanceRequest; -using ::conformance::ConformanceResponse; -using ::google::protobuf::util::BinaryToJsonString; -using ::google::protobuf::util::JsonParseOptions; -using ::google::protobuf::util::JsonToBinaryString; -using ::google::protobuf::util::NewTypeResolverForDescriptorPool; -using ::google::protobuf::util::TypeResolver; -using ::protobuf_test_messages::proto2::TestAllTypesProto2; -using ::protobuf_test_messages::proto3::TestAllTypesProto3; -absl::Status ReadFd(int fd, char* buf, size_t len) { +using util::Status; + +bool CheckedRead(int fd, void *buf, size_t len) { + size_t ofs = 0; while (len > 0) { - ssize_t bytes_read = read(fd, buf, len); + ssize_t bytes_read = read(fd, (char*)buf + ofs, len); - if (bytes_read == 0) { - return absl::DataLossError("unexpected EOF"); - } + if (bytes_read == 0) return false; if (bytes_read < 0) { - return absl::ErrnoToStatus(errno, "error reading from test runner"); + GOOGLE_LOG(FATAL) << "Error reading from test runner: " << strerror(errno); } len -= bytes_read; - buf += bytes_read; + ofs += bytes_read; } - return absl::OkStatus(); + + return true; } -absl::Status WriteFd(int fd, const void* buf, size_t len) { - if (static_cast(write(fd, buf, len)) != len) { - return absl::ErrnoToStatus(errno, "error reading to test runner"); +void CheckedWrite(int fd, const void *buf, size_t len) { + if (write(fd, buf, len) != len) { + GOOGLE_LOG(FATAL) << "Error writing to test runner: " << strerror(errno); } - return absl::OkStatus(); } -class Harness { - public: - Harness() { - google::protobuf::LinkMessageReflection(); - google::protobuf::LinkMessageReflection(); - - resolver_.reset(NewTypeResolverForDescriptorPool( - "type.googleapis.com", DescriptorPool::generated_pool())); - type_url_ = absl::StrCat("type.googleapis.com/", - TestAllTypesProto3::GetDescriptor()->full_name()); +void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { + Message *test_message; + google::protobuf::LinkMessageReflection(); + google::protobuf::LinkMessageReflection(); + const Descriptor *descriptor = DescriptorPool::generated_pool()->FindMessageTypeByName( + request.message_type()); + if (!descriptor) { + GOOGLE_LOG(FATAL) << "No such message type: " << request.message_type(); } - - absl::StatusOr RunTest( - const ConformanceRequest& request); - - // Returns Ok(true) if we're done processing requests. - absl::StatusOr ServeConformanceRequest(); - - private: - bool verbose_ = false; - std::unique_ptr resolver_; - std::string type_url_; -}; - -absl::StatusOr Harness::RunTest( - const ConformanceRequest& request) { - const Descriptor* descriptor = - DescriptorPool::generated_pool()->FindMessageTypeByName( - request.message_type()); - if (descriptor == nullptr) { - return absl::NotFoundError( - absl::StrCat("No such message type: ", request.message_type())); - } - - std::unique_ptr test_message( - MessageFactory::generated_factory()->GetPrototype(descriptor)->New()); - ConformanceResponse response; + test_message = MessageFactory::generated_factory()->GetPrototype(descriptor)->New(); switch (request.payload_case()) { case ConformanceRequest::kProtobufPayload: { if (!test_message->ParseFromString(request.protobuf_payload())) { - response.set_parse_error("parse error (no more details available)"); - return response; + // Getting parse details would involve something like: + // http://stackoverflow.com/questions/22121922/how-can-i-get-more-details-about-errors-generated-during-protobuf-parsing-c + response->set_parse_error("Parse error (no more details available)."); + return; } break; } case ConformanceRequest::kJsonPayload: { + string proto_binary; JsonParseOptions options; options.ignore_unknown_fields = (request.test_category() == - conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST); - - std::string proto_binary; - absl::Status status = - JsonToBinaryString(resolver_.get(), type_url_, request.json_payload(), + conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST); + util::Status status = + JsonToBinaryString(type_resolver, *type_url, request.json_payload(), &proto_binary, options); if (!status.ok()) { - response.set_parse_error( - absl::StrCat("parse error: ", status.message())); - return response; + response->set_parse_error(string("Parse error: ") + + std::string(status.message())); + return; } if (!test_message->ParseFromString(proto_binary)) { - response.set_runtime_error( - "parsing JSON generated invalid proto output"); - return response; + response->set_runtime_error( + "Parsing JSON generates invalid proto output."); + return; } - break; } case ConformanceRequest::kTextPayload: { - if (!TextFormat::ParseFromString(request.text_payload(), - test_message.get())) { - response.set_parse_error("parse error (no more details available)"); - return response; + if (!TextFormat::ParseFromString(request.text_payload(), test_message)) { + response->set_parse_error("Parse error"); + return; } break; } case ConformanceRequest::PAYLOAD_NOT_SET: - return absl::InvalidArgumentError("request didn't have payload"); + GOOGLE_LOG(FATAL) << "Request didn't have payload."; + break; default: - return absl::InvalidArgumentError( - absl::StrCat("unknown payload type", request.payload_case())); + GOOGLE_LOG(FATAL) << "unknown payload type: " << request.payload_case(); + break; + } + + conformance::FailureSet failures; + if (descriptor == failures.GetDescriptor()) { + for (const char* s : kFailures) failures.add_failure(s); + test_message = &failures; } switch (request.requested_output_format()) { case conformance::UNSPECIFIED: - return absl::InvalidArgumentError("unspecified output format"); + GOOGLE_LOG(FATAL) << "Unspecified output format"; + break; case conformance::PROTOBUF: { - GOOGLE_CHECK( - test_message->SerializeToString(response.mutable_protobuf_payload())); + GOOGLE_CHECK(test_message->SerializeToString( + response->mutable_protobuf_payload())); break; } case conformance::JSON: { - std::string proto_binary; + string proto_binary; GOOGLE_CHECK(test_message->SerializeToString(&proto_binary)); - absl::Status status = - BinaryToJsonString(resolver_.get(), type_url_, proto_binary, - response.mutable_json_payload()); + util::Status status = + BinaryToJsonString(type_resolver, *type_url, proto_binary, + response->mutable_json_payload()); if (!status.ok()) { - response.set_serialize_error(absl::StrCat( - "failed to serialize JSON output: ", status.message())); + response->set_serialize_error( + string("Failed to serialize JSON output: ") + + std::string(status.message())); + return; } break; } @@ -209,66 +199,70 @@ absl::StatusOr Harness::RunTest( TextFormat::Printer printer; printer.SetHideUnknownFields(!request.print_unknown_fields()); GOOGLE_CHECK(printer.PrintToString(*test_message, - response.mutable_text_payload())); + response->mutable_text_payload())); break; } default: - return absl::InvalidArgumentError(absl::StrCat( - "unknown output format", request.requested_output_format())); + GOOGLE_LOG(FATAL) << "Unknown output format: " + << request.requested_output_format(); } - - return response; } -absl::StatusOr Harness::ServeConformanceRequest() { - uint32_t in_len; - if (!ReadFd(STDIN_FILENO, reinterpret_cast(&in_len), sizeof(in_len)) - .ok()) { - // EOF means we're done. - return true; - } - - std::string serialized_input; - serialized_input.resize(in_len); - RETURN_IF_ERROR(ReadFd(STDIN_FILENO, &serialized_input[0], in_len)); - +bool DoTestIo() { + string serialized_input; + string serialized_output; ConformanceRequest request; - GOOGLE_CHECK(request.ParseFromString(serialized_input)); + ConformanceResponse response; + uint32_t bytes; - absl::StatusOr response = RunTest(request); - RETURN_IF_ERROR(response.status()); - - std::string serialized_output; - response->SerializeToString(&serialized_output); - - uint32_t out_len = static_cast(serialized_output.size()); - RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, &out_len, sizeof(out_len))); - RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, serialized_output.data(), out_len)); - - if (verbose_) { - GOOGLE_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString() - << ", response=" << response->ShortDebugString(); + if (!CheckedRead(STDIN_FILENO, &bytes, sizeof(uint32_t))) { + // EOF. + return false; } - return false; + + serialized_input.resize(bytes); + + if (!CheckedRead(STDIN_FILENO, (char*)serialized_input.c_str(), bytes)) { + GOOGLE_LOG(ERROR) << "Unexpected EOF on stdin. " << strerror(errno); + } + + if (!request.ParseFromString(serialized_input)) { + GOOGLE_LOG(FATAL) << "Parse of ConformanceRequest proto failed."; + return false; + } + + DoTest(request, &response); + + response.SerializeToString(&serialized_output); + + bytes = serialized_output.size(); + CheckedWrite(STDOUT_FILENO, &bytes, sizeof(uint32_t)); + CheckedWrite(STDOUT_FILENO, serialized_output.c_str(), bytes); + + if (verbose) { + fprintf(stderr, "conformance-cpp: request=%s, response=%s\n", + request.ShortDebugString().c_str(), + response.ShortDebugString().c_str()); + } + + test_count++; + + return true; } -} // namespace + } // namespace protobuf } // namespace google int main() { - google::protobuf::Harness harness; - int total_runs = 0; - while (true) { - auto is_done = harness.ServeConformanceRequest(); - if (!is_done.ok()) { - GOOGLE_LOG(FATAL) << is_done.status(); + type_resolver = NewTypeResolverForDescriptorPool( + kTypeUrlPrefix, DescriptorPool::generated_pool()); + type_url = new string(GetTypeUrl(TestAllTypesProto3::descriptor())); + while (1) { + if (!google::protobuf::DoTestIo()) { + fprintf(stderr, "conformance-cpp: received EOF from test runner " + "after %d tests, exiting\n", test_count); + return 0; } - if (*is_done) { - break; - } - total_runs++; } - GOOGLE_LOG(INFO) << "conformance-cpp: received EOF from test runner after " - << total_runs << " tests"; } diff --git a/libs/protobuf/conformance/conformance_nodejs.js b/libs/protobuf/conformance/conformance_nodejs.js new file mode 100755 index 0000000..275fac4 --- /dev/null +++ b/libs/protobuf/conformance/conformance_nodejs.js @@ -0,0 +1,189 @@ +#!/usr/bin/env node +// 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. + +var conformance = require('conformance_pb'); +var test_messages_proto3 = require('google/protobuf/test_messages_proto3_pb'); +var test_messages_proto2 = require('google/protobuf/test_messages_proto2_pb'); +var fs = require('fs'); + +var testCount = 0; + +function doTest(request) { + var testMessage; + var response = new conformance.ConformanceResponse(); + + try { + if (request.getRequestedOutputFormat() == conformance.WireFormat.JSON) { + response.setSkipped("JSON not supported."); + return response; + } + + if (request.getRequestedOutputFormat() == + conformance.WireFormat.TEXT_FORMAT) { + response.setSkipped('Text format is not supported as output format.'); + return response; + } + + switch (request.getPayloadCase()) { + case conformance.ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD: { + if (request.getMessageType() == "protobuf_test_messages.proto3.TestAllTypesProto3") { + try { + testMessage = test_messages_proto3.TestAllTypesProto3.deserializeBinary( + request.getProtobufPayload()); + } catch (err) { + response.setParseError(err.toString()); + return response; + } + } else if (request.getMessageType() == "protobuf_test_messages.proto2.TestAllTypesProto2"){ + try { + testMessage = test_messages_proto2.TestAllTypesProto2.deserializeBinary( + request.getProtobufPayload()); + } catch (err) { + response.setParseError(err.toString()); + return response; + } + } else { + throw "Protobuf request doesn\'t have specific payload type"; + } + } break; + + case conformance.ConformanceRequest.PayloadCase.JSON_PAYLOAD: + response.setSkipped("JSON not supported."); + return response; + + case conformance.ConformanceRequest.PayloadCase.TEXT_PAYLOAD: + response.setSkipped("Text format not supported."); + return response; + + case conformance.ConformanceRequest.PayloadCase.PAYLOAD_NOT_SET: + response.setRuntimeError("Request didn't have payload"); + return response; + } + + switch (request.getRequestedOutputFormat()) { + case conformance.WireFormat.UNSPECIFIED: + response.setRuntimeError("Unspecified output format"); + return response; + + case conformance.WireFormat.PROTOBUF: + response.setProtobufPayload(testMessage.serializeBinary()); + + case conformance.WireFormat.JSON: + response.setSkipped("JSON not supported."); + return response; + + default: + throw "Request didn't have requested output format"; + } + } catch (err) { + response.setRuntimeError(err.toString()); + } + + return response; +} + +function onEof(totalRead) { + if (totalRead == 0) { + return undefined; + } else { + throw "conformance_nodejs: premature EOF on stdin."; + } +} + +// Utility function to read a buffer of N bytes. +function readBuffer(bytes) { + var buf = new Buffer(bytes); + var totalRead = 0; + while (totalRead < bytes) { + var read = 0; + try { + read = fs.readSync(process.stdin.fd, buf, totalRead, bytes - totalRead); + } catch (e) { + if (e.code == 'EOF') { + return onEof(totalRead) + } else if (e.code == 'EAGAIN') { + } else { + throw "conformance_nodejs: Error reading from stdin." + e; + } + } + + totalRead += read; + } + + return buf; +} + +function writeBuffer(buffer) { + var totalWritten = 0; + while (totalWritten < buffer.length) { + totalWritten += fs.writeSync( + process.stdout.fd, buffer, totalWritten, buffer.length - totalWritten); + } +} + +// Returns true if the test ran successfully, false on legitimate EOF. +// If EOF is encountered in an unexpected place, raises IOError. +function doTestIo() { + var lengthBuf = readBuffer(4); + if (!lengthBuf) { + return false; + } + + var length = lengthBuf.readInt32LE(0); + var serializedRequest = readBuffer(length); + if (!serializedRequest) { + throw "conformance_nodejs: Failed to read request."; + } + + serializedRequest = new Uint8Array(serializedRequest); + var request = + conformance.ConformanceRequest.deserializeBinary(serializedRequest); + var response = doTest(request); + + var serializedResponse = response.serializeBinary(); + + lengthBuf = new Buffer(4); + lengthBuf.writeInt32LE(serializedResponse.length, 0); + writeBuffer(lengthBuf); + writeBuffer(new Buffer(serializedResponse)); + + testCount += 1 + + return true; +} + +while (true) { + if (!doTestIo()) { + console.error('conformance_nodejs: received EOF from test runner ' + + "after " + testCount + " tests, exiting") + break; + } +} diff --git a/libs/protobuf/conformance/conformance_objc.m b/libs/protobuf/conformance/conformance_objc.m index 77fae6a..ab751c8 100644 --- a/libs/protobuf/conformance/conformance_objc.m +++ b/libs/protobuf/conformance/conformance_objc.m @@ -56,7 +56,8 @@ static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes return nil; // EOF. } if (dataLen != numBytes) { - Die(@"Failed to read the request length (%d), only got: %@", numBytes, data); + Die(@"Failed to read the request length (%d), only got: %@", + numBytes, data); } return data; } @@ -75,9 +76,8 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { Class msgClass = nil; if ([request.messageType isEqual:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) { msgClass = [Proto3TestAllTypesProto3 class]; - } else if ([request.messageType - isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) { - msgClass = [Proto2TestAllTypesProto2 class]; + } else if ([request.messageType isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) { + msgClass = [TestAllTypesProto2 class]; } else { response.runtimeError = [NSString stringWithFormat:@"Protobuf request had an unknown message_type: %@", @@ -87,7 +87,8 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { NSError *error = nil; testMessage = [msgClass parseFromData:request.protobufPayload error:&error]; if (!testMessage) { - response.parseError = [NSString stringWithFormat:@"Parse error: %@", error]; + response.parseError = + [NSString stringWithFormat:@"Parse error: %@", error]; } break; } @@ -97,8 +98,9 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { break; case ConformanceRequest_Payload_OneOfCase_JspbPayload: - response.skipped = @"ConformanceRequest had a jspb_payload ConformanceRequest.payload;" - " those aren't supposed to happen with opensource."; + response.skipped = + @"ConformanceRequest had a jspb_payload ConformanceRequest.payload;" + " those aren't supposed to happen with opensource."; break; case ConformanceRequest_Payload_OneOfCase_TextPayload: @@ -108,31 +110,31 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { if (testMessage) { switch (request.requestedOutputFormat) { - case ConformanceWireFormat_GPBUnrecognizedEnumeratorValue: - case ConformanceWireFormat_Unspecified: + case WireFormat_GPBUnrecognizedEnumeratorValue: + case WireFormat_Unspecified: response.runtimeError = [NSString stringWithFormat:@"Unrecognized/unspecified output format: %@", request]; break; - case ConformanceWireFormat_Protobuf: + case WireFormat_Protobuf: response.protobufPayload = testMessage.data; if (!response.protobufPayload) { response.serializeError = - [NSString stringWithFormat:@"Failed to make data from: %@", testMessage]; + [NSString stringWithFormat:@"Failed to make data from: %@", testMessage]; } break; - case ConformanceWireFormat_Json: + case WireFormat_Json: response.skipped = @"ObjC doesn't support generating JSON"; break; - case ConformanceWireFormat_Jspb: + case WireFormat_Jspb: response.skipped = @"ConformanceRequest had a requested_output_format of JSPB WireFormat; that" - " isn't supposed to happen with opensource."; + " isn't supposed to happen with opensource."; break; - case ConformanceWireFormat_TextFormat: + case WireFormat_TextFormat: // ObjC only has partial objc generation, so don't attempt any tests that need // support. response.skipped = @"ObjC doesn't support generating TextFormat"; @@ -171,7 +173,8 @@ static BOOL DoTestIo(NSFileHandle *input, NSFileHandle *output) { } NSError *error = nil; - ConformanceRequest *request = [ConformanceRequest parseFromData:data error:&error]; + ConformanceRequest *request = [ConformanceRequest parseFromData:data + error:&error]; if (!request) { Die(@"Failed to parse the message data: %@", error); } diff --git a/libs/protobuf/conformance/conformance_php.php b/libs/protobuf/conformance/conformance_php.php index f250ebf..9eef0c5 100644 --- a/libs/protobuf/conformance/conformance_php.php +++ b/libs/protobuf/conformance/conformance_php.php @@ -14,7 +14,7 @@ require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php"); require_once("GPBMetadata/Conformance.php"); -require_once("GPBMetadata/TestMessagesProto3.php"); +require_once("GPBMetadata/Google/Protobuf/TestMessagesProto3.php"); use \Conformance\TestCategory; use \Conformance\WireFormat; @@ -113,7 +113,7 @@ function doTestIO() while(true){ if (!doTestIO()) { fprintf(STDERR, - "conformance_php: received EOF from test runner " . + "conformance_php: received EOF from test runner " + "after %d tests, exiting\n", $test_count); exit; } diff --git a/libs/protobuf/conformance/conformance_python.py b/libs/protobuf/conformance/conformance_python.py index cffadc9..37ee36e 100755 --- a/libs/protobuf/conformance/conformance_python.py +++ b/libs/protobuf/conformance/conformance_python.py @@ -42,7 +42,7 @@ from google.protobuf import message from google.protobuf import test_messages_proto3_pb2 from google.protobuf import test_messages_proto2_pb2 from google.protobuf import text_format -from conformance import conformance_pb2 +import conformance_pb2 sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0) diff --git a/libs/protobuf/conformance/conformance_test.cc b/libs/protobuf/conformance/conformance_test.cc index 00b309a..2c856f5 100644 --- a/libs/protobuf/conformance/conformance_test.cc +++ b/libs/protobuf/conformance/conformance_test.cc @@ -36,15 +36,13 @@ #include #include -#include "google/protobuf/message.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/util/field_comparator.h" -#include "google/protobuf/util/json_util.h" -#include "google/protobuf/util/message_differencer.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "conformance/conformance.pb.h" -#include "conformance/conformance.pb.h" +#include +#include +#include +#include +#include +#include +#include "conformance.pb.h" using conformance::ConformanceRequest; using conformance::ConformanceResponse; @@ -131,7 +129,7 @@ string ConformanceTestSuite::ConformanceRequestSetting:: prototype_message_.GetDescriptor()->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? "Proto3" : "Proto2"; - return absl::StrCat(ConformanceLevelToString(level_), ".", rname, ".", + return StrCat(ConformanceLevelToString(level_), ".", rname, ".", InputFormatString(input_format_), ".", test_name_, ".", OutputFormatString(output_format_)); } @@ -177,66 +175,12 @@ string ConformanceTestSuite::ConformanceRequestSetting:: return ""; } -void ConformanceTestSuite::TruncateDebugPayload(string* payload) { - if (payload != nullptr && payload->size() > 200) { - payload->resize(200); - payload->append("...(truncated)"); - } -} - -const ConformanceRequest ConformanceTestSuite::TruncateRequest( - const ConformanceRequest& request) { - ConformanceRequest debug_request(request); - switch (debug_request.payload_case()) { - case ConformanceRequest::kProtobufPayload: - TruncateDebugPayload(debug_request.mutable_protobuf_payload()); - break; - case ConformanceRequest::kJsonPayload: - TruncateDebugPayload(debug_request.mutable_json_payload()); - break; - case ConformanceRequest::kTextPayload: - TruncateDebugPayload(debug_request.mutable_text_payload()); - break; - case ConformanceRequest::kJspbPayload: - TruncateDebugPayload(debug_request.mutable_jspb_payload()); - break; - default: - // Do nothing. - break; - } - return debug_request; -} - -const ConformanceResponse ConformanceTestSuite::TruncateResponse( - const ConformanceResponse& response) { - ConformanceResponse debug_response(response); - switch (debug_response.result_case()) { - case ConformanceResponse::kProtobufPayload: - TruncateDebugPayload(debug_response.mutable_protobuf_payload()); - break; - case ConformanceResponse::kJsonPayload: - TruncateDebugPayload(debug_response.mutable_json_payload()); - break; - case ConformanceResponse::kTextPayload: - TruncateDebugPayload(debug_response.mutable_text_payload()); - break; - case ConformanceResponse::kJspbPayload: - TruncateDebugPayload(debug_response.mutable_jspb_payload()); - break; - default: - // Do nothing. - break; - } - return debug_response; -} - void ConformanceTestSuite::ReportSuccess(const string& test_name) { if (expected_to_fail_.erase(test_name) != 0) { - absl::StrAppendFormat( - &output_, - "ERROR: test %s is in the failure list, but test succeeded. " - "Remove it from the failure list.\n", - test_name); + StringAppendF(&output_, + "ERROR: test %s is in the failure list, but test succeeded. " + "Remove it from the failure list.\n", + test_name.c_str()); unexpected_succeeding_tests_.insert(test_name); } successes_++; @@ -246,30 +190,33 @@ void ConformanceTestSuite::ReportFailure(const string& test_name, ConformanceLevel level, const ConformanceRequest& request, const ConformanceResponse& response, - absl::string_view message) { + const char* fmt, ...) { if (expected_to_fail_.erase(test_name) == 1) { expected_failures_++; if (!verbose_) return; } else if (level == RECOMMENDED && !enforce_recommended_) { - absl::StrAppendFormat(&output_, "WARNING, test=%s: ", test_name); + StringAppendF(&output_, "WARNING, test=%s: ", test_name.c_str()); } else { - absl::StrAppendFormat(&output_, "ERROR, test=%s: ", test_name); + StringAppendF(&output_, "ERROR, test=%s: ", test_name.c_str()); unexpected_failing_tests_.insert(test_name); } - - absl::StrAppendFormat(&output_, "%s, request=%s, response=%s\n", message, - TruncateRequest(request).ShortDebugString(), - TruncateResponse(response).ShortDebugString()); + va_list args; + va_start(args, fmt); + StringAppendV(&output_, fmt, args); + va_end(args); + StringAppendF(&output_, " request=%s, response=%s\n", + request.ShortDebugString().c_str(), + response.ShortDebugString().c_str()); } void ConformanceTestSuite::ReportSkip(const string& test_name, const ConformanceRequest& request, const ConformanceResponse& response) { if (verbose_) { - absl::StrAppendFormat( - &output_, "SKIPPED, test=%s request=%s, response=%s\n", test_name, - request.ShortDebugString(), response.ShortDebugString()); + StringAppendF(&output_, "SKIPPED, test=%s request=%s, response=%s\n", + test_name.c_str(), request.ShortDebugString().c_str(), + response.ShortDebugString().c_str()); } skipped_.insert(test_name); } @@ -316,7 +263,6 @@ void ConformanceTestSuite::VerifyResponse( return; case ConformanceResponse::kParseError: - case ConformanceResponse::kTimeoutError: case ConformanceResponse::kRuntimeError: case ConformanceResponse::kSerializeError: ReportFailure(test_name, level, request, response, @@ -344,7 +290,7 @@ void ConformanceTestSuite::VerifyResponse( GOOGLE_DCHECK_EQ(response.result_case(), ConformanceResponse::kProtobufPayload); const string& protobuf_payload = response.protobuf_payload(); check = equivalent_wire_format == protobuf_payload; - differences = absl::StrCat("Expect: ", ToOctString(equivalent_wire_format), + differences = StrCat("Expect: ", ToOctString(equivalent_wire_format), ", but got: ", ToOctString(protobuf_payload)); } else { check = differencer.Compare(*reference_message, *test_message); @@ -355,10 +301,9 @@ void ConformanceTestSuite::VerifyResponse( ReportSuccess(test_name); } } else { - ReportFailure( - test_name, level, request, response, - absl::StrCat("Output was not equivalent to reference message: ", - differences)); + ReportFailure(test_name, level, request, response, + "Output was not equivalent to reference message: %s.", + differences.c_str()); } } @@ -381,10 +326,11 @@ void ConformanceTestSuite::RunTest(const string& test_name, } if (verbose_) { - absl::StrAppendFormat( - &output_, "conformance test: name=%s, request=%s, response=%s\n", - test_name, TruncateRequest(request).ShortDebugString(), - TruncateResponse(*response).ShortDebugString()); + StringAppendF(&output_, + "conformance test: name=%s, request=%s, response=%s\n", + test_name.c_str(), + request.ShortDebugString().c_str(), + response->ShortDebugString().c_str()); } } @@ -395,12 +341,13 @@ bool ConformanceTestSuite::CheckSetEmpty( if (set_to_check.empty()) { return true; } else { - absl::StrAppendFormat(&output_, "\n"); - absl::StrAppendFormat(&output_, "%s\n\n", msg); - for (absl::string_view v : set_to_check) { - absl::StrAppendFormat(&output_, " %s\n", v); + StringAppendF(&output_, "\n"); + StringAppendF(&output_, "%s\n\n", msg.c_str()); + for (std::set::const_iterator iter = set_to_check.begin(); + iter != set_to_check.end(); ++iter) { + StringAppendF(&output_, " %s\n", iter->c_str()); } - absl::StrAppendFormat(&output_, "\n"); + StringAppendF(&output_, "\n"); if (!write_to_file.empty()) { std::string full_filename; @@ -415,11 +362,13 @@ bool ConformanceTestSuite::CheckSetEmpty( } std::ofstream os(*filename); if (os) { - for (absl::string_view v : set_to_check) { - os << v << "\n"; + for (std::set::const_iterator iter = set_to_check.begin(); + iter != set_to_check.end(); ++iter) { + os << *iter << "\n"; } } else { - absl::StrAppendFormat(&output_, "Failed to open file: %s\n", *filename); + StringAppendF(&output_, "Failed to open file: %s\n", + filename->c_str()); } } @@ -503,12 +452,12 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, "features is not implemented)"); } - absl::StrAppendFormat(&output_, - "CONFORMANCE SUITE %s: %d successes, %zu skipped, " - "%d expected failures, %zu unexpected failures.\n", - ok ? "PASSED" : "FAILED", successes_, skipped_.size(), - expected_failures_, unexpected_failing_tests_.size()); - absl::StrAppendFormat(&output_, "\n"); + StringAppendF(&output_, + "CONFORMANCE SUITE %s: %d successes, %zu skipped, " + "%d expected failures, %zu unexpected failures.\n", + ok ? "PASSED" : "FAILED", successes_, skipped_.size(), + expected_failures_, unexpected_failing_tests_.size()); + StringAppendF(&output_, "\n"); output->assign(output_); diff --git a/libs/protobuf/conformance/conformance_test.h b/libs/protobuf/conformance/conformance_test.h index 527f054..83d94f8 100644 --- a/libs/protobuf/conformance/conformance_test.h +++ b/libs/protobuf/conformance/conformance_test.h @@ -42,10 +42,10 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/util/type_resolver.h" -#include "conformance/conformance.pb.h" +#include +#include +#include +#include "conformance.pb.h" namespace conformance { class ConformanceRequest; @@ -88,12 +88,10 @@ class ForkPipeRunner : public ConformanceTestRunner { const std::vector& suites); ForkPipeRunner(const std::string& executable, - const std::vector& executable_args, - bool performance) + const std::vector& executable_args) : child_pid_(-1), executable_(executable), - executable_args_(executable_args), - performance_(performance) {} + executable_args_(executable_args) {} explicit ForkPipeRunner(const std::string& executable) : child_pid_(-1), executable_(executable) {} @@ -116,7 +114,6 @@ class ForkPipeRunner : public ConformanceTestRunner { pid_t child_pid_; std::string executable_; const std::vector executable_args_; - bool performance_; std::string current_test_name_; }; @@ -151,12 +148,10 @@ class ConformanceTestSuite { public: ConformanceTestSuite() : verbose_(false), - performance_(false), enforce_recommended_(false), failure_list_flag_name_("--failure_list") {} virtual ~ConformanceTestSuite() {} - void SetPerformance(bool performance) { performance_ = performance; } void SetVerbose(bool verbose) { verbose_ = verbose; } // Whether to require the testee to pass RECOMMENDED tests. By default failing @@ -277,17 +272,11 @@ class ConformanceTestSuite { const conformance::ConformanceResponse& response, bool need_report_success, bool require_same_wire_format); - void TruncateDebugPayload(std::string* payload); - const conformance::ConformanceRequest TruncateRequest( - const conformance::ConformanceRequest& request); - const conformance::ConformanceResponse TruncateResponse( - const conformance::ConformanceResponse& response); - void ReportSuccess(const std::string& test_name); void ReportFailure(const std::string& test_name, ConformanceLevel level, const conformance::ConformanceRequest& request, const conformance::ConformanceResponse& response, - absl::string_view message); + const char* fmt, ...); void ReportSkip(const std::string& test_name, const conformance::ConformanceRequest& request, const conformance::ConformanceResponse& response); @@ -310,7 +299,6 @@ class ConformanceTestSuite { int successes_; int expected_failures_; bool verbose_; - bool performance_; bool enforce_recommended_; std::string output_; std::string output_dir_; diff --git a/libs/protobuf/conformance/conformance_test_runner.cc b/libs/protobuf/conformance/conformance_test_runner.cc index a60bdee..2aac35c 100644 --- a/libs/protobuf/conformance/conformance_test_runner.cc +++ b/libs/protobuf/conformance/conformance_test_runner.cc @@ -54,19 +54,16 @@ // 4. testee sends M bytes representing a ConformanceResponse proto #include -#include #include #include #include #include -#include #include -#include #include -#include "absl/strings/str_format.h" -#include "conformance/conformance.pb.h" +#include +#include "conformance.pb.h" #include "conformance_test.h" using conformance::ConformanceResponse; @@ -76,10 +73,10 @@ using std::vector; #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) -#define GOOGLE_CHECK_SYSCALL(call) \ - if (call < 0) { \ +#define GOOGLE_CHECK_SYSCALL(call) \ + if (call < 0) { \ perror(#call " " __FILE__ ":" TOSTRING(__LINE__)); \ - exit(1); \ + exit(1); \ } namespace google { @@ -96,7 +93,8 @@ void ParseFailureList(const char *filename, for (string line; getline(infile, line);) { // Remove whitespace. - line.erase(std::remove_if(line.begin(), line.end(), ::isspace), line.end()); + line.erase(std::remove_if(line.begin(), line.end(), ::isspace), + line.end()); // Remove comments. line = line.substr(0, line.find("#")); @@ -108,7 +106,8 @@ void ParseFailureList(const char *filename, } void UsageError() { - fprintf(stderr, "Usage: conformance-test-runner [options] \n"); + fprintf(stderr, + "Usage: conformance-test-runner [options] \n"); fprintf(stderr, "\n"); fprintf(stderr, "Options:\n"); fprintf(stderr, @@ -123,7 +122,8 @@ void UsageError() { " --text_format_failure_list Use to specify list \n"); fprintf(stderr, " of tests that are expected to \n"); - fprintf(stderr, " fail in the \n"); + fprintf(stderr, + " fail in the \n"); fprintf(stderr, " text_format_conformance_suite. \n"); fprintf(stderr, @@ -139,19 +139,22 @@ void UsageError() { " this flag if you want to be\n"); fprintf(stderr, " strictly conforming to protobuf\n"); - fprintf(stderr, " spec.\n"); + fprintf(stderr, + " spec.\n"); fprintf(stderr, " --output_dir Directory to write\n" " output files.\n"); exit(1); } -void ForkPipeRunner::RunTest(const std::string &test_name, - const std::string &request, - std::string *response) { +void ForkPipeRunner::RunTest( + const std::string& test_name, + const std::string& request, + std::string* response) { if (child_pid_ < 0) { SpawnTestProgram(); } + current_test_name_ = test_name; uint32_t len = request.size(); @@ -166,55 +169,44 @@ void ForkPipeRunner::RunTest(const std::string &test_name, waitpid(child_pid_, &status, WEXITED); string error_msg; - conformance::ConformanceResponse response_obj; if (WIFEXITED(status)) { - if (WEXITSTATUS(status) == 0) { - absl::StrAppendFormat(&error_msg, - "child timed out, killed by signal %d", - WTERMSIG(status)); - response_obj.set_timeout_error(error_msg); - } else { - absl::StrAppendFormat(&error_msg, "child exited, status=%d", - WEXITSTATUS(status)); - response_obj.set_runtime_error(error_msg); - } + StringAppendF(&error_msg, + "child exited, status=%d", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { - absl::StrAppendFormat(&error_msg, "child killed by signal %d", - WTERMSIG(status)); + StringAppendF(&error_msg, + "child killed by signal %d", WTERMSIG(status)); } GOOGLE_LOG(INFO) << error_msg; child_pid_ = -1; + conformance::ConformanceResponse response_obj; + response_obj.set_runtime_error(error_msg); response_obj.SerializeToString(response); return; } response->resize(len); - CheckedRead(read_fd_, (void *)response->c_str(), len); + CheckedRead(read_fd_, (void*)response->c_str(), len); } -int ForkPipeRunner::Run(int argc, char *argv[], - const std::vector &suites) { +int ForkPipeRunner::Run( + int argc, char *argv[], const std::vector& suites) { if (suites.empty()) { fprintf(stderr, "No test suites found.\n"); return EXIT_FAILURE; } bool all_ok = true; - for (ConformanceTestSuite *suite : suites) { + for (ConformanceTestSuite* suite : suites) { string program; std::vector program_args; string failure_list_filename; conformance::FailureSet failure_list; - bool performance = false; for (int arg = 1; arg < argc; ++arg) { if (strcmp(argv[arg], suite->GetFailureListFlagName().c_str()) == 0) { if (++arg == argc) UsageError(); failure_list_filename = argv[arg]; ParseFailureList(argv[arg], &failure_list); - } else if (strcmp(argv[arg], "--performance") == 0) { - performance = true; - suite->SetPerformance(true); } else if (strcmp(argv[arg], "--verbose") == 0) { suite->SetVerbose(true); } else if (strcmp(argv[arg], "--enforce_recommended") == 0) { @@ -224,7 +216,7 @@ int ForkPipeRunner::Run(int argc, char *argv[], suite->SetOutputDir(argv[arg]); } else if (argv[arg][0] == '-') { bool recognized_flag = false; - for (ConformanceTestSuite *suite : suites) { + for (ConformanceTestSuite* suite : suites) { if (strcmp(argv[arg], suite->GetFailureListFlagName().c_str()) == 0) { if (++arg == argc) UsageError(); recognized_flag = true; @@ -235,7 +227,7 @@ int ForkPipeRunner::Run(int argc, char *argv[], UsageError(); } } else { - program += argv[arg++]; + program += argv[arg]; while (arg < argc) { program_args.push_back(argv[arg]); arg++; @@ -243,11 +235,11 @@ int ForkPipeRunner::Run(int argc, char *argv[], } } - ForkPipeRunner runner(program, program_args, performance); + ForkPipeRunner runner(program, program_args); std::string output; - all_ok = all_ok && suite->RunSuite(&runner, &output, failure_list_filename, - &failure_list); + all_ok = all_ok && + suite->RunSuite(&runner, &output, failure_list_filename, &failure_list); fwrite(output.c_str(), 1, output.size(), stderr); } @@ -311,10 +303,8 @@ void ForkPipeRunner::SpawnTestProgram() { std::vector argv; argv.push_back(executable.get()); - GOOGLE_LOG(INFO) << argv[0]; for (size_t i = 0; i < executable_args_.size(); ++i) { argv.push_back(executable_args_[i].c_str()); - GOOGLE_LOG(INFO) << executable_args_[i]; } argv.push_back(nullptr); // Never returns. @@ -332,36 +322,8 @@ void ForkPipeRunner::CheckedWrite(int fd, const void *buf, size_t len) { bool ForkPipeRunner::TryRead(int fd, void *buf, size_t len) { size_t ofs = 0; while (len > 0) { - std::future future = std::async( - std::launch::async, - [](int fd, void *buf, size_t ofs, size_t len) { - return read(fd, (char *)buf + ofs, len); - }, - fd, buf, ofs, len); - std::future_status status; - if (performance_) { - status = future.wait_for(std::chrono::seconds(5)); - if (status == std::future_status::timeout) { - GOOGLE_LOG(ERROR) << current_test_name_ << ": timeout from test program"; - kill(child_pid_, SIGQUIT); - // TODO(sandyzhang): Only log in flag-guarded mode, since reading output - // from SIGQUIT is slow and verbose. - std::vector err; - err.resize(5000); - ssize_t err_bytes_read; - size_t err_ofs = 0; - do { - err_bytes_read = - read(fd, (void *)&err[err_ofs], err.size() - err_ofs); - err_ofs += err_bytes_read; - } while (err_bytes_read > 0 && err_ofs < err.size()); - GOOGLE_LOG(ERROR) << "child_pid_=" << child_pid_ << " SIGQUIT: \n" << &err[0]; - return false; - } - } else { - future.wait(); - } - ssize_t bytes_read = future.get(); + ssize_t bytes_read = read(fd, (char*)buf + ofs, len); + if (bytes_read == 0) { GOOGLE_LOG(ERROR) << current_test_name_ << ": unexpected EOF from test program"; return false; diff --git a/libs/protobuf/conformance/bazel_conformance_test_runner.sh b/libs/protobuf/conformance/conformance_test_runner.sh similarity index 81% rename from libs/protobuf/conformance/bazel_conformance_test_runner.sh rename to libs/protobuf/conformance/conformance_test_runner.sh index fcf4a48..3149f82 100755 --- a/libs/protobuf/conformance/bazel_conformance_test_runner.sh +++ b/libs/protobuf/conformance/conformance_test_runner.sh @@ -1,7 +1,4 @@ #!/bin/bash -# This is an internal file that should only be called from Bazel rules. For -# custom conformance tests outside of Bazel use CMAKE with -# -Dprotobuf_BUILD_CONFORMANCE=ON to build the test runner. set -x echo $@ @@ -47,13 +44,13 @@ conformance_test_runner=$(rlocation com_google_protobuf/conformance/conformance_ conformance_testee=$(rlocation $TESTEE) args=(--enforce_recommended) -failure_list=$(rlocation $FAILURE_LIST) || unset -if [ -n "$failure_list" ] ; then +failure_list=$(rlocation $FAILURE_LIST) +if [ "$failure_list" != "1" ] ; then args+=(--failure_list $failure_list) fi -text_format_failure_list=$(rlocation $TEXT_FORMAT_FAILURE_LIST) || unset -if [ -n "$text_format_failure_list" ]; then +text_format_failure_list=$(rlocation $TEXT_FORMAT_FAILURE_LIST) +if [ "$text_format_failure_list" != "1" ]; then args+=(--text_format_failure_list $text_format_failure_list) fi diff --git a/libs/protobuf/conformance/defs.bzl b/libs/protobuf/conformance/defs.bzl index 8daef86..905953a 100644 --- a/libs/protobuf/conformance/defs.bzl +++ b/libs/protobuf/conformance/defs.bzl @@ -1,24 +1,6 @@ -"""Starlark definitions for Protobuf conformance tests. +# PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE. -PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE. -""" - -def conformance_test( - name, - testee, - failure_list = None, - text_format_failure_list = None, - **kwargs): - """Conformance test runner. - - Args: - name: the name for the test. - testee: a conformance test client binary. - failure_list: a text file with known failures, one per line. - text_format_failure_list: a text file with known failures (one per line) - for the text format conformance suite. - **kwargs: common arguments to pass to sh_test. - """ +def conformance_test(name, testee, failure_list = None, text_format_failure_list = None): args = ["--testee %s" % _strip_bazel(testee)] failure_lists = [] if failure_list: @@ -30,7 +12,7 @@ def conformance_test( native.sh_test( name = name, - srcs = ["//conformance:bazel_conformance_test_runner.sh"], + srcs = ["//conformance:conformance_test_runner.sh"], data = [testee] + failure_lists + [ "//conformance:conformance_test_runner", ], @@ -38,8 +20,6 @@ def conformance_test( deps = [ "@bazel_tools//tools/bash/runfiles", ], - tags = ["conformance"], - **kwargs ) def _strip_bazel(testee): diff --git a/libs/protobuf/conformance/failure_list_cpp.txt b/libs/protobuf/conformance/failure_list_cpp.txt index a68602c..d55fa9f 100644 --- a/libs/protobuf/conformance/failure_list_cpp.txt +++ b/libs/protobuf/conformance/failure_list_cpp.txt @@ -12,6 +12,8 @@ Recommended.FieldMaskPathsDontRoundTrip.JsonOutput Recommended.FieldMaskTooManyUnderscore.JsonOutput Recommended.Proto3.JsonInput.BoolFieldDoubleQuotedFalse Recommended.Proto3.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput +Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Recommended.Proto3.JsonInput.FieldNameDuplicate Recommended.Proto3.JsonInput.FieldNameDuplicateDifferentCasing1 diff --git a/libs/protobuf/conformance/failure_list_js.txt b/libs/protobuf/conformance/failure_list_js.txt new file mode 100644 index 0000000..b7d36b6 --- /dev/null +++ b/libs/protobuf/conformance/failure_list_js.txt @@ -0,0 +1,162 @@ +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput +Recommended.Proto2.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.DefaultOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.UnpackedOutput.ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[4].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.ENUM[5].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.FIXED64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT32[7].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.INT64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SFIXED64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.SINT64[2].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT32[8].ProtobufOutput +Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT64[2].ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput +Required.Proto2.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput +Required.Proto2.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.ProtobufOutput +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput +Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].ProtobufOutput +Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].ProtobufOutput diff --git a/libs/protobuf/conformance/failure_list_php.txt b/libs/protobuf/conformance/failure_list_php.txt index 3232047..667f80c 100644 --- a/libs/protobuf/conformance/failure_list_php.txt +++ b/libs/protobuf/conformance/failure_list_php.txt @@ -8,8 +8,6 @@ Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter Recommended.Proto3.ProtobufInput.ValidDataOneofBinary.MESSAGE.Merge.ProtobufOutput Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator Required.Proto3.JsonInput.DoubleFieldTooSmall -Required.Proto3.JsonInput.DurationNegativeNanos.JsonOutput -Required.Proto3.JsonInput.DurationNegativeNanos.ProtobufOutput Required.Proto3.JsonInput.FloatFieldTooLarge Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.Int32FieldNotInteger diff --git a/libs/protobuf/conformance/text_format_conformance_suite.cc b/libs/protobuf/conformance/text_format_conformance_suite.cc index 81dde5f..460bc24 100644 --- a/libs/protobuf/conformance/text_format_conformance_suite.cc +++ b/libs/protobuf/conformance/text_format_conformance_suite.cc @@ -30,11 +30,11 @@ #include "text_format_conformance_suite.h" -#include "google/protobuf/any.pb.h" -#include "google/protobuf/text_format.h" +#include +#include #include "conformance_test.h" -#include "google/protobuf/test_messages_proto2.pb.h" -#include "google/protobuf/test_messages_proto3.pb.h" +#include +#include namespace proto2_messages = protobuf_test_messages::proto2; @@ -51,10 +51,6 @@ using std::string; namespace google { namespace protobuf { -// The number of repetitions to use for performance tests. -// Corresponds approx to 500KB wireformat bytes. -static const size_t kPerformanceRepeatCount = 50000; - TextFormatConformanceTestSuite::TextFormatConformanceTestSuite() { SetFailureListFlagName("--text_format_failure_list"); } @@ -89,9 +85,10 @@ bool TextFormatConformanceTestSuite::ParseResponse( case ConformanceResponse::kProtobufPayload: { if (requested_output != conformance::PROTOBUF) { ReportFailure(test_name, level, request, response, - absl::StrCat("Test was asked for ", + StrCat("Test was asked for ", WireFormatToString(requested_output), - " output but provided PROTOBUF instead.")); + " output but provided PROTOBUF instead.") + .c_str()); return false; } @@ -106,11 +103,11 @@ bool TextFormatConformanceTestSuite::ParseResponse( case ConformanceResponse::kTextPayload: { if (requested_output != conformance::TEXT_FORMAT) { - ReportFailure( - test_name, level, request, response, - absl::StrCat("Test was asked for ", - WireFormatToString(requested_output), - " output but provided TEXT_FORMAT instead.")); + ReportFailure(test_name, level, request, response, + StrCat("Test was asked for ", + WireFormatToString(requested_output), + " output but provided TEXT_FORMAT instead.") + .c_str()); return false; } @@ -144,7 +141,7 @@ void TextFormatConformanceTestSuite::ExpectParseFailure(const string& test_name, const ConformanceRequest& request = setting.GetRequest(); ConformanceResponse response; string effective_test_name = - absl::StrCat(setting.ConformanceLevelToString(level), + StrCat(setting.ConformanceLevelToString(level), ".Proto3.TextFormatInput.", test_name); RunTest(effective_test_name, request, &response); @@ -170,22 +167,6 @@ void TextFormatConformanceTestSuite::RunValidTextFormatTestProto2( RunValidTextFormatTestWithMessage(test_name, level, input_text, prototype); } -void TextFormatConformanceTestSuite::RunValidTextFormatTestWithExpected( - const string& test_name, ConformanceLevel level, const string& input_text, - const string& expected_text) { - TestAllTypesProto3 prototype; - RunValidTextFormatTestWithMessage(test_name, level, input_text, expected_text, - prototype); -} - -void TextFormatConformanceTestSuite::RunValidTextFormatTestProto2WithExpected( - const string& test_name, ConformanceLevel level, const string& input_text, - const string& expected_text) { - TestAllTypesProto2 prototype; - RunValidTextFormatTestWithMessage(test_name, level, input_text, expected_text, - prototype); -} - void TextFormatConformanceTestSuite::RunValidTextFormatTestWithMessage( const string& test_name, ConformanceLevel level, const string& input_text, const Message& prototype) { @@ -199,19 +180,6 @@ void TextFormatConformanceTestSuite::RunValidTextFormatTestWithMessage( RunValidInputTest(setting2, input_text); } -void TextFormatConformanceTestSuite::RunValidTextFormatTestWithMessage( - const string& test_name, ConformanceLevel level, const string& input_text, - const string& expected_text, const Message& prototype) { - ConformanceRequestSetting setting1( - level, conformance::TEXT_FORMAT, conformance::PROTOBUF, - conformance::TEXT_FORMAT_TEST, prototype, test_name, input_text); - RunValidInputTest(setting1, expected_text); - ConformanceRequestSetting setting2( - level, conformance::TEXT_FORMAT, conformance::TEXT_FORMAT, - conformance::TEXT_FORMAT_TEST, prototype, test_name, input_text); - RunValidInputTest(setting2, expected_text); -} - void TextFormatConformanceTestSuite::RunValidUnknownTextFormatTest( const string& test_name, const Message& message) { string serialized_input; @@ -234,324 +202,276 @@ void TextFormatConformanceTestSuite::RunValidUnknownTextFormatTest( } void TextFormatConformanceTestSuite::RunSuiteImpl() { - if (!performance_) { - RunValidTextFormatTest("HelloWorld", REQUIRED, - "optional_string: 'Hello, World!'"); - // Integer fields. - RunValidTextFormatTest("Int32FieldMaxValue", REQUIRED, - "optional_int32: 2147483647"); - RunValidTextFormatTest("Int32FieldMinValue", REQUIRED, - "optional_int32: -2147483648"); - RunValidTextFormatTest("Uint32FieldMaxValue", REQUIRED, - "optional_uint32: 4294967295"); - RunValidTextFormatTest("Int64FieldMaxValue", REQUIRED, - "optional_int64: 9223372036854775807"); - RunValidTextFormatTest("Int64FieldMinValue", REQUIRED, - "optional_int64: -9223372036854775808"); - RunValidTextFormatTest("Uint64FieldMaxValue", REQUIRED, - "optional_uint64: 18446744073709551615"); + RunValidTextFormatTest("HelloWorld", REQUIRED, + "optional_string: 'Hello, World!'"); + // Integer fields. + RunValidTextFormatTest("Int32FieldMaxValue", REQUIRED, + "optional_int32: 2147483647"); + RunValidTextFormatTest("Int32FieldMinValue", REQUIRED, + "optional_int32: -2147483648"); + RunValidTextFormatTest("Uint32FieldMaxValue", REQUIRED, + "optional_uint32: 4294967295"); + RunValidTextFormatTest("Int64FieldMaxValue", REQUIRED, + "optional_int64: 9223372036854775807"); + RunValidTextFormatTest("Int64FieldMinValue", REQUIRED, + "optional_int64: -9223372036854775808"); + RunValidTextFormatTest("Uint64FieldMaxValue", REQUIRED, + "optional_uint64: 18446744073709551615"); - // Parsers reject out-of-bound integer values. - ExpectParseFailure("Int32FieldTooLarge", REQUIRED, - "optional_int32: 2147483648"); - ExpectParseFailure("Int32FieldTooSmall", REQUIRED, - "optional_int32: -2147483649"); - ExpectParseFailure("Uint32FieldTooLarge", REQUIRED, - "optional_uint32: 4294967296"); - ExpectParseFailure("Int64FieldTooLarge", REQUIRED, - "optional_int64: 9223372036854775808"); - ExpectParseFailure("Int64FieldTooSmall", REQUIRED, - "optional_int64: -9223372036854775809"); - ExpectParseFailure("Uint64FieldTooLarge", REQUIRED, - "optional_uint64: 18446744073709551616"); + // Parsers reject out-of-bound integer values. + ExpectParseFailure("Int32FieldTooLarge", REQUIRED, + "optional_int32: 2147483648"); + ExpectParseFailure("Int32FieldTooSmall", REQUIRED, + "optional_int32: -2147483649"); + ExpectParseFailure("Uint32FieldTooLarge", REQUIRED, + "optional_uint32: 4294967296"); + ExpectParseFailure("Int64FieldTooLarge", REQUIRED, + "optional_int64: 9223372036854775808"); + ExpectParseFailure("Int64FieldTooSmall", REQUIRED, + "optional_int64: -9223372036854775809"); + ExpectParseFailure("Uint64FieldTooLarge", REQUIRED, + "optional_uint64: 18446744073709551616"); - // Floating point fields - RunValidTextFormatTest("FloatField", REQUIRED, "optional_float: 3.192837"); - RunValidTextFormatTest("FloatFieldWithVeryPreciseNumber", REQUIRED, - "optional_float: 3.123456789123456789"); - RunValidTextFormatTest("FloatFieldMaxValue", REQUIRED, - "optional_float: 3.4028235e+38"); - RunValidTextFormatTest("FloatFieldMinValue", REQUIRED, - "optional_float: 1.17549e-38"); - RunValidTextFormatTest("FloatFieldNaNValue", REQUIRED, - "optional_float: NaN"); - RunValidTextFormatTest("FloatFieldPosInfValue", REQUIRED, - "optional_float: inf"); - RunValidTextFormatTest("FloatFieldNegInfValue", REQUIRED, - "optional_float: -inf"); - RunValidTextFormatTest("FloatFieldWithInt32Max", REQUIRED, - "optional_float: 4294967296"); - RunValidTextFormatTest("FloatFieldLargerThanInt64", REQUIRED, - "optional_float: 9223372036854775808"); - RunValidTextFormatTest("FloatFieldTooLarge", REQUIRED, - "optional_float: 3.4028235e+39"); - RunValidTextFormatTest("FloatFieldTooSmall", REQUIRED, - "optional_float: 1.17549e-39"); - RunValidTextFormatTest("FloatFieldLargerThanUint64", REQUIRED, - "optional_float: 18446744073709551616"); + // Floating point fields + RunValidTextFormatTest("FloatField", REQUIRED, + "optional_float: 3.192837"); + RunValidTextFormatTest("FloatFieldWithVeryPreciseNumber", REQUIRED, + "optional_float: 3.123456789123456789"); + RunValidTextFormatTest("FloatFieldMaxValue", REQUIRED, + "optional_float: 3.4028235e+38"); + RunValidTextFormatTest("FloatFieldMinValue", REQUIRED, + "optional_float: 1.17549e-38"); + RunValidTextFormatTest("FloatFieldNaNValue", REQUIRED, + "optional_float: NaN"); + RunValidTextFormatTest("FloatFieldPosInfValue", REQUIRED, + "optional_float: inf"); + RunValidTextFormatTest("FloatFieldNegInfValue", REQUIRED, + "optional_float: -inf"); + RunValidTextFormatTest("FloatFieldWithInt32Max", REQUIRED, + "optional_float: 4294967296"); + RunValidTextFormatTest("FloatFieldLargerThanInt64", REQUIRED, + "optional_float: 9223372036854775808"); + RunValidTextFormatTest("FloatFieldTooLarge", REQUIRED, + "optional_float: 3.4028235e+39"); + RunValidTextFormatTest("FloatFieldTooSmall", REQUIRED, + "optional_float: 1.17549e-39"); + RunValidTextFormatTest("FloatFieldLargerThanUint64", REQUIRED, + "optional_float: 18446744073709551616"); - // String literals x {Strings, Bytes} - for (const auto& field_type : std::vector{"String", "Bytes"}) { - const std::string field_name = - field_type == "String" ? "optional_string" : "optional_bytes"; - RunValidTextFormatTest( - absl::StrCat("StringLiteralConcat", field_type), REQUIRED, - absl::StrCat(field_name, ": 'first' \"second\"\n'third'")); - RunValidTextFormatTest( - absl::StrCat("StringLiteralBasicEscapes", field_type), REQUIRED, - absl::StrCat(field_name, ": '\\a\\b\\f\\n\\r\\t\\v\\?\\\\\\'\\\"'")); - RunValidTextFormatTest( - absl::StrCat("StringLiteralOctalEscapes", field_type), REQUIRED, - absl::StrCat(field_name, ": '\\341\\210\\264'")); - RunValidTextFormatTest( - absl::StrCat("StringLiteralHexEscapes", field_type), REQUIRED, - absl::StrCat(field_name, ": '\\xe1\\x88\\xb4'")); - RunValidTextFormatTest( - absl::StrCat("StringLiteralShortUnicodeEscape", field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\u1234'")); - RunValidTextFormatTest( - absl::StrCat("StringLiteralLongUnicodeEscapes", field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\U00001234\\U00010437'")); - // String literals don't include line feeds. - ExpectParseFailure( - absl::StrCat("StringLiteralIncludesLF", field_type), REQUIRED, - absl::StrCat(field_name, ": 'first line\nsecond line'")); - // Unicode escapes don't include code points that lie beyond the planes - // (> 0x10ffff). - ExpectParseFailure( - absl::StrCat("StringLiteralLongUnicodeEscapeTooLarge", field_type), - REQUIRED, absl::StrCat(field_name, ": '\\U00110000'")); - // Unicode escapes don't include surrogates. - ExpectParseFailure( - absl::StrCat("StringLiteralShortUnicodeEscapeSurrogatePair", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\ud801\\udc37'")); - ExpectParseFailure( - absl::StrCat("StringLiteralShortUnicodeEscapeSurrogateFirstOnly", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\ud800'")); - ExpectParseFailure( - absl::StrCat("StringLiteralShortUnicodeEscapeSurrogateSecondOnly", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\udc00'")); - ExpectParseFailure( - absl::StrCat("StringLiteralLongUnicodeEscapeSurrogateFirstOnly", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d800'")); - ExpectParseFailure( - absl::StrCat("StringLiteralLongUnicodeEscapeSurrogateSecondOnly", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\U0000dc00'")); - ExpectParseFailure( - absl::StrCat("StringLiteralLongUnicodeEscapeSurrogatePair", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d801\\U00000dc37'")); - ExpectParseFailure( - absl::StrCat("StringLiteralUnicodeEscapeSurrogatePairLongShort", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\U0000d801\\udc37'")); - ExpectParseFailure( - absl::StrCat("StringLiteralUnicodeEscapeSurrogatePairShortLong", - field_type), - RECOMMENDED, absl::StrCat(field_name, ": '\\ud801\\U0000dc37'")); + // String literals x {Strings, Bytes} + for (const auto& field_type : std::vector{"String", "Bytes"}) { + const std::string field_name = + field_type == "String" ? "optional_string" : "optional_bytes"; + RunValidTextFormatTest( + StrCat("StringLiteralConcat", field_type), REQUIRED, + StrCat(field_name, ": 'first' \"second\"\n'third'")); + RunValidTextFormatTest( + StrCat("StringLiteralBasicEscapes", field_type), REQUIRED, + StrCat(field_name, ": '\\a\\b\\f\\n\\r\\t\\v\\?\\\\\\'\\\"'")); + RunValidTextFormatTest( + StrCat("StringLiteralOctalEscapes", field_type), REQUIRED, + StrCat(field_name, ": '\\341\\210\\264'")); + RunValidTextFormatTest(StrCat("StringLiteralHexEscapes", field_type), + REQUIRED, + StrCat(field_name, ": '\\xe1\\x88\\xb4'")); + RunValidTextFormatTest( + StrCat("StringLiteralShortUnicodeEscape", field_type), + RECOMMENDED, StrCat(field_name, ": '\\u1234'")); + RunValidTextFormatTest( + StrCat("StringLiteralLongUnicodeEscapes", field_type), + RECOMMENDED, StrCat(field_name, ": '\\U00001234\\U00010437'")); + // String literals don't include line feeds. + ExpectParseFailure(StrCat("StringLiteralIncludesLF", field_type), + REQUIRED, + StrCat(field_name, ": 'first line\nsecond line'")); + // Unicode escapes don't include code points that lie beyond the planes + // (> 0x10ffff). + ExpectParseFailure( + StrCat("StringLiteralLongUnicodeEscapeTooLarge", field_type), + REQUIRED, StrCat(field_name, ": '\\U00110000'")); + // Unicode escapes don't include surrogates. + ExpectParseFailure( + StrCat("StringLiteralShortUnicodeEscapeSurrogatePair", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\ud801\\udc37'")); + ExpectParseFailure( + StrCat("StringLiteralShortUnicodeEscapeSurrogateFirstOnly", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\ud800'")); + ExpectParseFailure( + StrCat("StringLiteralShortUnicodeEscapeSurrogateSecondOnly", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\udc00'")); + ExpectParseFailure( + StrCat("StringLiteralLongUnicodeEscapeSurrogateFirstOnly", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\U0000d800'")); + ExpectParseFailure( + StrCat("StringLiteralLongUnicodeEscapeSurrogateSecondOnly", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\U0000dc00'")); + ExpectParseFailure( + StrCat("StringLiteralLongUnicodeEscapeSurrogatePair", field_type), + RECOMMENDED, StrCat(field_name, ": '\\U0000d801\\U00000dc37'")); + ExpectParseFailure( + StrCat("StringLiteralUnicodeEscapeSurrogatePairLongShort", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\U0000d801\\udc37'")); + ExpectParseFailure( + StrCat("StringLiteralUnicodeEscapeSurrogatePairShortLong", + field_type), + RECOMMENDED, StrCat(field_name, ": '\\ud801\\U0000dc37'")); - // The following method depend on the type of field, as strings have extra - // validation. - const auto test_method = - field_type == "String" - ? &TextFormatConformanceTestSuite::ExpectParseFailure - : &TextFormatConformanceTestSuite::RunValidTextFormatTest; + // The following method depend on the type of field, as strings have extra + // validation. + const auto test_method = + field_type == "String" + ? &TextFormatConformanceTestSuite::ExpectParseFailure + : &TextFormatConformanceTestSuite::RunValidTextFormatTest; - // String fields reject invalid UTF-8 byte sequences; bytes fields don't. - (this->*test_method)(absl::StrCat(field_type, "FieldBadUTF8Octal"), - REQUIRED, absl::StrCat(field_name, ": '\\300'")); - (this->*test_method)(absl::StrCat(field_type, "FieldBadUTF8Hex"), - REQUIRED, absl::StrCat(field_name, ": '\\xc0'")); - } - - // Group fields - RunValidTextFormatTestProto2("GroupFieldNoColon", REQUIRED, - "Data { group_int32: 1 }"); - RunValidTextFormatTestProto2("GroupFieldWithColon", REQUIRED, - "Data: { group_int32: 1 }"); - RunValidTextFormatTestProto2("GroupFieldEmpty", REQUIRED, "Data {}"); - - // Unknown Fields - UnknownToTestAllTypes message; - // Unable to print unknown Fixed32/Fixed64 fields as if they are known. - // Fixed32/Fixed64 fields are not added in the tests. - message.set_optional_int32(123); - message.set_optional_string("hello"); - message.set_optional_bool(true); - RunValidUnknownTextFormatTest("ScalarUnknownFields", message); - - message.Clear(); - message.mutable_nested_message()->set_c(111); - RunValidUnknownTextFormatTest("MessageUnknownFields", message); - - message.Clear(); - message.mutable_optionalgroup()->set_a(321); - RunValidUnknownTextFormatTest("GroupUnknownFields", message); - - message.add_repeated_int32(1); - message.add_repeated_int32(2); - message.add_repeated_int32(3); - RunValidUnknownTextFormatTest("RepeatedUnknownFields", message); - - // Any fields - RunValidTextFormatTest("AnyField", REQUIRED, - R"( - optional_any: { - [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] { - optional_int32: 12345 - } - } - )"); - RunValidTextFormatTest("AnyFieldWithRawBytes", REQUIRED, - R"( - optional_any: { - type_url: "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3" - value: "\b\271`" - } - )"); - ExpectParseFailure("AnyFieldWithInvalidType", REQUIRED, - R"( - optional_any: { - [type.googleapis.com/unknown] { - optional_int32: 12345 - } - } - )"); - - // Map fields - TestAllTypesProto3 prototype; - (*prototype.mutable_map_string_string())["c"] = "value"; - (*prototype.mutable_map_string_string())["b"] = "value"; - (*prototype.mutable_map_string_string())["a"] = "value"; - RunValidTextFormatTestWithMessage("AlphabeticallySortedMapStringKeys", - REQUIRED, - R"( - map_string_string { - key: "a" - value: "value" - } - map_string_string { - key: "b" - value: "value" - } - map_string_string { - key: "c" - value: "value" - } - )", - prototype); - - prototype.Clear(); - (*prototype.mutable_map_int32_int32())[3] = 0; - (*prototype.mutable_map_int32_int32())[2] = 0; - (*prototype.mutable_map_int32_int32())[1] = 0; - RunValidTextFormatTestWithMessage("AlphabeticallySortedMapIntKeys", - REQUIRED, - R"( - map_int32_int32 { - key: 1 - value: 0 - } - map_int32_int32 { - key: 2 - value: 0 - } - map_int32_int32 { - key: 3 - value: 0 - } - )", - prototype); - - prototype.Clear(); - (*prototype.mutable_map_bool_bool())[true] = false; - (*prototype.mutable_map_bool_bool())[false] = false; - RunValidTextFormatTestWithMessage("AlphabeticallySortedMapBoolKeys", - REQUIRED, - R"( - map_bool_bool { - key: false - value: false - } - map_bool_bool { - key: true - value: false - } - )", - prototype); - - prototype.Clear(); - ConformanceRequestSetting setting_map( - REQUIRED, conformance::TEXT_FORMAT, conformance::PROTOBUF, - conformance::TEXT_FORMAT_TEST, prototype, "DuplicateMapKey", R"( - map_string_nested_message { - key: "duplicate" - value: { a: 123 } - } - map_string_nested_message { - key: "duplicate" - value: { corecursive: {} } - } - )"); - // The last-specified value will be retained in a parsed map - RunValidInputTest(setting_map, R"( - map_string_nested_message { - key: "duplicate" - value: { corecursive: {} } - } - )"); - } - // Flag control performance tests to keep them internal and opt-in only - if (performance_) { - RunTextFormatPerformanceTests(); - } -} - -void TextFormatConformanceTestSuite::RunTextFormatPerformanceTests() { - TestTextFormatPerformanceMergeMessageWithRepeatedField("Bool", - "repeated_bool: true"); - TestTextFormatPerformanceMergeMessageWithRepeatedField( - "Double", "repeated_double: 123"); - TestTextFormatPerformanceMergeMessageWithRepeatedField( - "Int32", "repeated_uint32: 123"); - TestTextFormatPerformanceMergeMessageWithRepeatedField( - "Int64", "repeated_uint64: 123"); - TestTextFormatPerformanceMergeMessageWithRepeatedField( - "String", R"(repeated_string: "foo")"); - TestTextFormatPerformanceMergeMessageWithRepeatedField( - "Bytes", R"(repeated_bytes: "foo")"); -} - -// This is currently considered valid input by some languages but not others -void TextFormatConformanceTestSuite:: - TestTextFormatPerformanceMergeMessageWithRepeatedField( - const string& test_type_name, const string& message_field) { - string recursive_message = "recursive_message { " + message_field + " }"; - - string input; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - input.append(recursive_message); + // String fields reject invalid UTF-8 byte sequences; bytes fields don't. + (this->*test_method)(StrCat(field_type, "FieldBadUTF8Octal"), + REQUIRED, StrCat(field_name, ": '\\300'")); + (this->*test_method)(StrCat(field_type, "FieldBadUTF8Hex"), REQUIRED, + StrCat(field_name, ": '\\xc0'")); } - string expected = "recursive_message { "; - for (size_t i = 0; i < kPerformanceRepeatCount; i++) { - expected.append(message_field + " "); - } - expected.append("}"); + // Group fields + RunValidTextFormatTestProto2("GroupFieldNoColon", REQUIRED, + "Data { group_int32: 1 }"); + RunValidTextFormatTestProto2("GroupFieldWithColon", REQUIRED, + "Data: { group_int32: 1 }"); + RunValidTextFormatTestProto2("GroupFieldEmpty", REQUIRED, + "Data {}"); - RunValidTextFormatTestProto2WithExpected( - "TestTextFormatPerformanceMergeMessageWithRepeatedField" + - test_type_name + "Proto2", - RECOMMENDED, input, expected); - RunValidTextFormatTestWithExpected( - "TestTextFormatPerformanceMergeMessageWithRepeatedField" + - test_type_name + "Proto3", - RECOMMENDED, input, expected); + + // Unknown Fields + UnknownToTestAllTypes message; + // Unable to print unknown Fixed32/Fixed64 fields as if they are known. + // Fixed32/Fixed64 fields are not added in the tests. + message.set_optional_int32(123); + message.set_optional_string("hello"); + message.set_optional_bool(true); + RunValidUnknownTextFormatTest("ScalarUnknownFields", message); + + message.Clear(); + message.mutable_nested_message()->set_c(111); + RunValidUnknownTextFormatTest("MessageUnknownFields", message); + + message.Clear(); + message.mutable_optionalgroup()->set_a(321); + RunValidUnknownTextFormatTest("GroupUnknownFields", message); + + message.add_repeated_int32(1); + message.add_repeated_int32(2); + message.add_repeated_int32(3); + RunValidUnknownTextFormatTest("RepeatedUnknownFields", message); + + // Any fields + RunValidTextFormatTest("AnyField", REQUIRED, + R"( + optional_any: { + [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] { + optional_int32: 12345 + } + } + )"); + RunValidTextFormatTest("AnyFieldWithRawBytes", REQUIRED, + R"( + optional_any: { + type_url: "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3" + value: "\b\271`" + } + )"); + ExpectParseFailure("AnyFieldWithInvalidType", REQUIRED, + R"( + optional_any: { + [type.googleapis.com/unknown] { + optional_int32: 12345 + } + } + )"); + + // Map fields + TestAllTypesProto3 prototype; + (*prototype.mutable_map_string_string())["c"] = "value"; + (*prototype.mutable_map_string_string())["b"] = "value"; + (*prototype.mutable_map_string_string())["a"] = "value"; + RunValidTextFormatTestWithMessage("AlphabeticallySortedMapStringKeys", + REQUIRED, + R"( + map_string_string { + key: "a" + value: "value" + } + map_string_string { + key: "b" + value: "value" + } + map_string_string { + key: "c" + value: "value" + } + )", + prototype); + + prototype.Clear(); + (*prototype.mutable_map_int32_int32())[3] = 0; + (*prototype.mutable_map_int32_int32())[2] = 0; + (*prototype.mutable_map_int32_int32())[1] = 0; + RunValidTextFormatTestWithMessage("AlphabeticallySortedMapIntKeys", REQUIRED, + R"( + map_int32_int32 { + key: 1 + value: 0 + } + map_int32_int32 { + key: 2 + value: 0 + } + map_int32_int32 { + key: 3 + value: 0 + } + )", + prototype); + + prototype.Clear(); + (*prototype.mutable_map_bool_bool())[true] = false; + (*prototype.mutable_map_bool_bool())[false] = false; + RunValidTextFormatTestWithMessage("AlphabeticallySortedMapBoolKeys", REQUIRED, + R"( + map_bool_bool { + key: false + value: false + } + map_bool_bool { + key: true + value: false + } + )", + prototype); + + prototype.Clear(); + ConformanceRequestSetting setting_map( + REQUIRED, conformance::TEXT_FORMAT, conformance::PROTOBUF, + conformance::TEXT_FORMAT_TEST, prototype, "DuplicateMapKey", R"( + map_string_nested_message { + key: "duplicate" + value: { a: 123 } + } + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); + // The last-specified value will be retained in a parsed map + RunValidInputTest(setting_map, R"( + map_string_nested_message { + key: "duplicate" + value: { corecursive: {} } + } + )"); } } // namespace protobuf diff --git a/libs/protobuf/conformance/text_format_conformance_suite.h b/libs/protobuf/conformance/text_format_conformance_suite.h index e594cac..e875f31 100644 --- a/libs/protobuf/conformance/text_format_conformance_suite.h +++ b/libs/protobuf/conformance/text_format_conformance_suite.h @@ -42,29 +42,15 @@ class TextFormatConformanceTestSuite : public ConformanceTestSuite { private: void RunSuiteImpl() override; - void RunTextFormatPerformanceTests(); void RunValidTextFormatTest(const std::string& test_name, ConformanceLevel level, const std::string& input); void RunValidTextFormatTestProto2(const std::string& test_name, ConformanceLevel level, const std::string& input); - void RunValidTextFormatTestWithExpected(const std::string& test_name, - ConformanceLevel level, - const std::string& input, - const std::string& expected); - void RunValidTextFormatTestProto2WithExpected(const std::string& test_name, - ConformanceLevel level, - const std::string& input, - const std::string& expected); void RunValidTextFormatTestWithMessage(const std::string& test_name, ConformanceLevel level, const std::string& input_text, const Message& prototype); - void RunValidTextFormatTestWithMessage(const std::string& test_name, - ConformanceLevel level, - const std::string& input_text, - const std::string& expected_text, - const Message& prototype); void RunValidUnknownTextFormatTest(const std::string& test_name, const Message& message); void ExpectParseFailure(const std::string& test_name, ConformanceLevel level, @@ -75,8 +61,6 @@ class TextFormatConformanceTestSuite : public ConformanceTestSuite { bool ParseResponse(const conformance::ConformanceResponse& response, const ConformanceRequestSetting& setting, Message* test_message) override; - void TestTextFormatPerformanceMergeMessageWithRepeatedField( - const std::string& test_type_name, const std::string& message_field); }; } // namespace protobuf diff --git a/libs/protobuf/conformance/third_party/jsoncpp/json.h b/libs/protobuf/conformance/third_party/jsoncpp/json.h new file mode 100644 index 0000000..373ec98 --- /dev/null +++ b/libs/protobuf/conformance/third_party/jsoncpp/json.h @@ -0,0 +1,2075 @@ +/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/). +/// It is intended to be used with #include "json/json.h" + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: LICENSE +// ////////////////////////////////////////////////////////////////////// + +/* +The JsonCpp library's source code, including accompanying documentation, +tests and demonstration applications, are licensed under the following +conditions... + +The author (Baptiste Lepilleur) explicitly disclaims copyright in all +jurisdictions which recognize such a disclaimer. In such jurisdictions, +this software is released into the Public Domain. + +In jurisdictions which do not recognize Public Domain property (e.g. Germany as of +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is +released under the terms of the MIT License (see below). + +In jurisdictions which recognize Public Domain property, the user of this +software may choose to accept it either as 1) Public Domain, 2) under the +conditions of the MIT License (see below), or 3) under the terms of dual +Public Domain/MIT License conditions described here, as they choose. + +The MIT License is about as close to Public Domain as a license can get, and is +described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + +The full text of the MIT License follows: + +======================================================================== +Copyright (c) 2007-2010 Baptiste Lepilleur + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, +modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +======================================================================== +(END LICENSE TEXT) + +The MIT license is compatible with both the GPL and commercial +software, affording one all of the rights of Public Domain with the +minor nuisance of being required to keep the above copyright notice +and license text in the source code. Note also that by accepting the +Public Domain "license" you can re-license your copy using whatever +license you like. + +*/ + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: LICENSE +// ////////////////////////////////////////////////////////////////////// + + + + + +#ifndef JSON_AMALGATED_H_INCLUDED +# define JSON_AMALGATED_H_INCLUDED +/// If defined, indicates that the source file is amalgated +/// to prevent private header inclusion. +#define JSON_IS_AMALGAMATION + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/version.h +// ////////////////////////////////////////////////////////////////////// + +// DO NOT EDIT. This file (and "version") is generated by CMake. +// Run CMake configure step to update it. +#ifndef JSON_VERSION_H_INCLUDED +# define JSON_VERSION_H_INCLUDED + +# define JSONCPP_VERSION_STRING "1.6.5" +# define JSONCPP_VERSION_MAJOR 1 +# define JSONCPP_VERSION_MINOR 6 +# define JSONCPP_VERSION_PATCH 5 +# define JSONCPP_VERSION_QUALIFIER +# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) + +#endif // JSON_VERSION_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/version.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/config.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef JSON_CONFIG_H_INCLUDED +#define JSON_CONFIG_H_INCLUDED + +/// If defined, indicates that json library is embedded in CppTL library. +//# define JSON_IN_CPPTL 1 + +/// If defined, indicates that json may leverage CppTL library +//# define JSON_USE_CPPTL 1 +/// If defined, indicates that cpptl vector based map should be used instead of +/// std::map +/// as Value container. +//# define JSON_USE_CPPTL_SMALLMAP 1 + +// If non-zero, the library uses exceptions to report bad input instead of C +// assertion macros. The default is to use exceptions. +#ifndef JSON_USE_EXCEPTION +#define JSON_USE_EXCEPTION 1 +#endif + +/// If defined, indicates that the source file is amalgated +/// to prevent private header inclusion. +/// Remarks: it is automatically defined in the generated amalgated header. +// #define JSON_IS_AMALGAMATION + +#ifdef JSON_IN_CPPTL +#include +#ifndef JSON_USE_CPPTL +#define JSON_USE_CPPTL 1 +#endif +#endif + +#ifdef JSON_IN_CPPTL +#define JSON_API CPPTL_API +#elif defined(JSON_DLL_BUILD) +#if defined(_MSC_VER) +#define JSON_API __declspec(dllexport) +#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING +#endif // if defined(_MSC_VER) +#elif defined(JSON_DLL) +#if defined(_MSC_VER) +#define JSON_API __declspec(dllimport) +#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING +#endif // if defined(_MSC_VER) +#endif // ifdef JSON_IN_CPPTL +#if !defined(JSON_API) +#define JSON_API +#endif + +// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for +// integer +// Storages, and 64 bits integer support is disabled. +// #define JSON_NO_INT64 1 + +#if defined(_MSC_VER) // MSVC +# if _MSC_VER <= 1200 // MSVC 6 + // Microsoft Visual Studio 6 only support conversion from __int64 to double + // (no conversion from unsigned __int64). +# define JSON_USE_INT64_DOUBLE_CONVERSION 1 + // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255' + // characters in the debug information) + // All projects I've ever seen with VS6 were using this globally (not bothering + // with pragma push/pop). +# pragma warning(disable : 4786) +# endif // MSVC 6 + +# if _MSC_VER >= 1500 // MSVC 2008 + /// Indicates that the following function is deprecated. +# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) +# endif + +#endif // defined(_MSC_VER) + + +#ifndef JSON_HAS_RVALUE_REFERENCES + +#if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010 +#define JSON_HAS_RVALUE_REFERENCES 1 +#endif // MSVC >= 2010 + +#ifdef __clang__ +#if __has_feature(cxx_rvalue_references) +#define JSON_HAS_RVALUE_REFERENCES 1 +#endif // has_feature + +#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) +#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L) +#define JSON_HAS_RVALUE_REFERENCES 1 +#endif // GXX_EXPERIMENTAL + +#endif // __clang__ || __GNUC__ + +#endif // not defined JSON_HAS_RVALUE_REFERENCES + +#ifndef JSON_HAS_RVALUE_REFERENCES +#define JSON_HAS_RVALUE_REFERENCES 0 +#endif + +#ifdef __clang__ +#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc) +# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) +# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message))) +# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) +# endif // GNUC version +#endif // __clang__ || __GNUC__ + +#if !defined(JSONCPP_DEPRECATED) +#define JSONCPP_DEPRECATED(message) +#endif // if !defined(JSONCPP_DEPRECATED) + +namespace Json { +typedef int Int; +typedef unsigned int UInt; +#if defined(JSON_NO_INT64) +typedef int LargestInt; +typedef unsigned int LargestUInt; +#undef JSON_HAS_INT64 +#else // if defined(JSON_NO_INT64) +// For Microsoft Visual use specific types as long long is not supported +#if defined(_MSC_VER) // Microsoft Visual Studio +typedef __int64 Int64; +typedef unsigned __int64 UInt64; +#else // if defined(_MSC_VER) // Other platforms, use long long +typedef long long int Int64; +typedef unsigned long long int UInt64; +#endif // if defined(_MSC_VER) +typedef Int64 LargestInt; +typedef UInt64 LargestUInt; +#define JSON_HAS_INT64 +#endif // if defined(JSON_NO_INT64) +} // end namespace Json + +#endif // JSON_CONFIG_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/config.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/forwards.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef JSON_FORWARDS_H_INCLUDED +#define JSON_FORWARDS_H_INCLUDED + +#if !defined(JSON_IS_AMALGAMATION) +#include "config.h" +#endif // if !defined(JSON_IS_AMALGAMATION) + +namespace Json { + +// writer.h +class FastWriter; +class StyledWriter; + +// reader.h +class Reader; + +// features.h +class Features; + +// value.h +typedef unsigned int ArrayIndex; +class StaticString; +class Path; +class PathArgument; +class Value; +class ValueIteratorBase; +class ValueIterator; +class ValueConstIterator; + +} // namespace Json + +#endif // JSON_FORWARDS_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/forwards.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/features.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef CPPTL_JSON_FEATURES_H_INCLUDED +#define CPPTL_JSON_FEATURES_H_INCLUDED + +#if !defined(JSON_IS_AMALGAMATION) +#include "forwards.h" +#endif // if !defined(JSON_IS_AMALGAMATION) + +namespace Json { + +/** \brief Configuration passed to reader and writer. + * This configuration object can be used to force the Reader or Writer + * to behave in a standard conforming way. + */ +class JSON_API Features { +public: + /** \brief A configuration that allows all features and assumes all strings + * are UTF-8. + * - C & C++ comments are allowed + * - Root object can be any JSON value + * - Assumes Value strings are encoded in UTF-8 + */ + static Features all(); + + /** \brief A configuration that is strictly compatible with the JSON + * specification. + * - Comments are forbidden. + * - Root object must be either an array or an object value. + * - Assumes Value strings are encoded in UTF-8 + */ + static Features strictMode(); + + /** \brief Initialize the configuration like JsonConfig::allFeatures; + */ + Features(); + + /// \c true if comments are allowed. Default: \c true. + bool allowComments_; + + /// \c true if root must be either an array or an object value. Default: \c + /// false. + bool strictRoot_; + + /// \c true if dropped null placeholders are allowed. Default: \c false. + bool allowDroppedNullPlaceholders_; + + /// \c true if numeric object key are allowed. Default: \c false. + bool allowNumericKeys_; +}; + +} // namespace Json + +#endif // CPPTL_JSON_FEATURES_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/features.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/value.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef CPPTL_JSON_H_INCLUDED +#define CPPTL_JSON_H_INCLUDED + +#if !defined(JSON_IS_AMALGAMATION) +#include "forwards.h" +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include + +#ifndef JSON_USE_CPPTL_SMALLMAP +#include +#else +#include +#endif +#ifdef JSON_USE_CPPTL +#include +#endif + +// Disable warning C4251: : needs to have dll-interface to +// be used by... +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(push) +#pragma warning(disable : 4251) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +/** \brief JSON (JavaScript Object Notation). + */ +namespace Json { + +/** Base class for all exceptions we throw. + * + * We use nothing but these internally. Of course, STL can throw others. + */ +class JSON_API Exception : public std::exception { +public: + Exception(std::string const& msg); + ~Exception() throw() override; + char const* what() const throw() override; +protected: + std::string msg_; +}; + +/** Exceptions which the user cannot easily avoid. + * + * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input + * + * \remark derived from Json::Exception + */ +class JSON_API RuntimeError : public Exception { +public: + RuntimeError(std::string const& msg); +}; + +/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. + * + * These are precondition-violations (user bugs) and internal errors (our bugs). + * + * \remark derived from Json::Exception + */ +class JSON_API LogicError : public Exception { +public: + LogicError(std::string const& msg); +}; + +/// used internally +void throwRuntimeError(std::string const& msg); +/// used internally +void throwLogicError(std::string const& msg); + +/** \brief Type of the value held by a Value object. + */ +enum ValueType { + nullValue = 0, ///< 'null' value + intValue, ///< signed integer value + uintValue, ///< unsigned integer value + realValue, ///< double value + stringValue, ///< UTF-8 string value + booleanValue, ///< bool value + arrayValue, ///< array value (ordered list) + objectValue ///< object value (collection of name/value pairs). +}; + +enum CommentPlacement { + commentBefore = 0, ///< a comment placed on the line before a value + commentAfterOnSameLine, ///< a comment just after a value on the same line + commentAfter, ///< a comment on the line after a value (only make sense for + /// root value) + numberOfCommentPlacement +}; + +//# ifdef JSON_USE_CPPTL +// typedef CppTL::AnyEnumerator EnumMemberNames; +// typedef CppTL::AnyEnumerator EnumValues; +//# endif + +/** \brief Lightweight wrapper to tag static string. + * + * Value constructor and objectValue member assignement takes advantage of the + * StaticString and avoid the cost of string duplication when storing the + * string or the member name. + * + * Example of usage: + * \code + * Json::Value aValue( StaticString("some text") ); + * Json::Value object; + * static const StaticString code("code"); + * object[code] = 1234; + * \endcode + */ +class JSON_API StaticString { +public: + explicit StaticString(const char* czstring) : c_str_(czstring) {} + + operator const char*() const { return c_str_; } + + const char* c_str() const { return c_str_; } + +private: + const char* c_str_; +}; + +/** \brief Represents a JSON value. + * + * This class is a discriminated union wrapper that can represents a: + * - signed integer [range: Value::minInt - Value::maxInt] + * - unsigned integer (range: 0 - Value::maxUInt) + * - double + * - UTF-8 string + * - boolean + * - 'null' + * - an ordered list of Value + * - collection of name/value pairs (javascript object) + * + * The type of the held value is represented by a #ValueType and + * can be obtained using type(). + * + * Values of an #objectValue or #arrayValue can be accessed using operator[]() + * methods. + * Non-const methods will automatically create the a #nullValue element + * if it does not exist. + * The sequence of an #arrayValue will be automatically resized and initialized + * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. + * + * The get() methods can be used to obtain default value in the case the + * required element does not exist. + * + * It is possible to iterate over the list of a #objectValue values using + * the getMemberNames() method. + * + * \note #Value string-length fit in size_t, but keys must be < 2^30. + * (The reason is an implementation detail.) A #CharReader will raise an + * exception if a bound is exceeded to avoid security holes in your app, + * but the Value API does *not* check bounds. That is the responsibility + * of the caller. + */ +class JSON_API Value { + friend class ValueIteratorBase; +public: + typedef std::vector Members; + typedef ValueIterator iterator; + typedef ValueConstIterator const_iterator; + typedef Json::UInt UInt; + typedef Json::Int Int; +#if defined(JSON_HAS_INT64) + typedef Json::UInt64 UInt64; + typedef Json::Int64 Int64; +#endif // defined(JSON_HAS_INT64) + typedef Json::LargestInt LargestInt; + typedef Json::LargestUInt LargestUInt; + typedef Json::ArrayIndex ArrayIndex; + + static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value(). + static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null + /// Minimum signed integer value that can be stored in a Json::Value. + static const LargestInt minLargestInt; + /// Maximum signed integer value that can be stored in a Json::Value. + static const LargestInt maxLargestInt; + /// Maximum unsigned integer value that can be stored in a Json::Value. + static const LargestUInt maxLargestUInt; + + /// Minimum signed int value that can be stored in a Json::Value. + static const Int minInt; + /// Maximum signed int value that can be stored in a Json::Value. + static const Int maxInt; + /// Maximum unsigned int value that can be stored in a Json::Value. + static const UInt maxUInt; + +#if defined(JSON_HAS_INT64) + /// Minimum signed 64 bits int value that can be stored in a Json::Value. + static const Int64 minInt64; + /// Maximum signed 64 bits int value that can be stored in a Json::Value. + static const Int64 maxInt64; + /// Maximum unsigned 64 bits int value that can be stored in a Json::Value. + static const UInt64 maxUInt64; +#endif // defined(JSON_HAS_INT64) + +private: +#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + class CZString { + public: + enum DuplicationPolicy { + noDuplication = 0, + duplicate, + duplicateOnCopy + }; + CZString(ArrayIndex index); + CZString(char const* str, unsigned length, DuplicationPolicy allocate); + CZString(CZString const& other); +#if JSON_HAS_RVALUE_REFERENCES + CZString(CZString&& other); +#endif + ~CZString(); + CZString& operator=(CZString other); + bool operator<(CZString const& other) const; + bool operator==(CZString const& other) const; + ArrayIndex index() const; + //const char* c_str() const; ///< \deprecated + char const* data() const; + unsigned length() const; + bool isStaticString() const; + + private: + void swap(CZString& other); + + struct StringStorage { + unsigned policy_: 2; + unsigned length_: 30; // 1GB max + }; + + char const* cstr_; // actually, a prefixed string, unless policy is noDup + union { + ArrayIndex index_; + StringStorage storage_; + }; + }; + +public: +#ifndef JSON_USE_CPPTL_SMALLMAP + typedef std::map ObjectValues; +#else + typedef CppTL::SmallMap ObjectValues; +#endif // ifndef JSON_USE_CPPTL_SMALLMAP +#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION + +public: + /** \brief Create a default Value of the given type. + + This is a very useful constructor. + To create an empty array, pass arrayValue. + To create an empty object, pass objectValue. + Another Value can then be set to this one by assignment. +This is useful since clear() and resize() will not alter types. + + Examples: +\code +Json::Value null_value; // null +Json::Value arr_value(Json::arrayValue); // [] +Json::Value obj_value(Json::objectValue); // {} +\endcode + */ + Value(ValueType type = nullValue); + Value(Int value); + Value(UInt value); +#if defined(JSON_HAS_INT64) + Value(Int64 value); + Value(UInt64 value); +#endif // if defined(JSON_HAS_INT64) + Value(double value); + Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) + Value(const char* begin, const char* end); ///< Copy all, incl zeroes. + /** \brief Constructs a value from a static string. + + * Like other value string constructor but do not duplicate the string for + * internal storage. The given string must remain alive after the call to this + * constructor. + * \note This works only for null-terminated strings. (We cannot change the + * size of this class, so we have nowhere to store the length, + * which might be computed later for various operations.) + * + * Example of usage: + * \code + * static StaticString foo("some text"); + * Json::Value aValue(foo); + * \endcode + */ + Value(const StaticString& value); + Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too. +#ifdef JSON_USE_CPPTL + Value(const CppTL::ConstString& value); +#endif + Value(bool value); + /// Deep copy. + Value(const Value& other); +#if JSON_HAS_RVALUE_REFERENCES + /// Move constructor + Value(Value&& other); +#endif + ~Value(); + + /// Deep copy, then swap(other). + /// \note Over-write existing comments. To preserve comments, use #swapPayload(). + Value& operator=(Value other); + /// Swap everything. + void swap(Value& other); + /// Swap values but leave comments and source offsets in place. + void swapPayload(Value& other); + + ValueType type() const; + + /// Compare payload only, not comments etc. + bool operator<(const Value& other) const; + bool operator<=(const Value& other) const; + bool operator>=(const Value& other) const; + bool operator>(const Value& other) const; + bool operator==(const Value& other) const; + bool operator!=(const Value& other) const; + int compare(const Value& other) const; + + const char* asCString() const; ///< Embedded zeroes could cause you trouble! + std::string asString() const; ///< Embedded zeroes are possible. + /** Get raw char* of string-value. + * \return false if !string. (Seg-fault if str or end are NULL.) + */ + bool getString( + char const** begin, char const** end) const; +#ifdef JSON_USE_CPPTL + CppTL::ConstString asConstString() const; +#endif + Int asInt() const; + UInt asUInt() const; +#if defined(JSON_HAS_INT64) + Int64 asInt64() const; + UInt64 asUInt64() const; +#endif // if defined(JSON_HAS_INT64) + LargestInt asLargestInt() const; + LargestUInt asLargestUInt() const; + float asFloat() const; + double asDouble() const; + bool asBool() const; + + bool isNull() const; + bool isBool() const; + bool isInt() const; + bool isInt64() const; + bool isUInt() const; + bool isUInt64() const; + bool isIntegral() const; + bool isDouble() const; + bool isNumeric() const; + bool isString() const; + bool isArray() const; + bool isObject() const; + + bool isConvertibleTo(ValueType other) const; + + /// Number of values in array or object + ArrayIndex size() const; + + /// \brief Return true if empty array, empty object, or null; + /// otherwise, false. + bool empty() const; + + /// Return isNull() + bool operator!() const; + + /// Remove all object members and array elements. + /// \pre type() is arrayValue, objectValue, or nullValue + /// \post type() is unchanged + void clear(); + + /// Resize the array to size elements. + /// New elements are initialized to null. + /// May only be called on nullValue or arrayValue. + /// \pre type() is arrayValue or nullValue + /// \post type() is arrayValue + void resize(ArrayIndex size); + + /// Access an array element (zero based index ). + /// If the array contains less than index element, then null value are + /// inserted + /// in the array so that its size is index+1. + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + Value& operator[](ArrayIndex index); + + /// Access an array element (zero based index ). + /// If the array contains less than index element, then null value are + /// inserted + /// in the array so that its size is index+1. + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + Value& operator[](int index); + + /// Access an array element (zero based index ) + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + const Value& operator[](ArrayIndex index) const; + + /// Access an array element (zero based index ) + /// (You may need to say 'value[0u]' to get your compiler to distinguish + /// this from the operator[] which takes a string.) + const Value& operator[](int index) const; + + /// If the array contains at least index+1 elements, returns the element + /// value, + /// otherwise returns defaultValue. + Value get(ArrayIndex index, const Value& defaultValue) const; + /// Return true if index < size(). + bool isValidIndex(ArrayIndex index) const; + /// \brief Append value to array at the end. + /// + /// Equivalent to jsonvalue[jsonvalue.size()] = value; + Value& append(const Value& value); + + /// Access an object value by name, create a null member if it does not exist. + /// \note Because of our implementation, keys are limited to 2^30 -1 chars. + /// Exceeding that will cause an exception. + Value& operator[](const char* key); + /// Access an object value by name, returns null if there is no member with + /// that name. + const Value& operator[](const char* key) const; + /// Access an object value by name, create a null member if it does not exist. + /// \param key may contain embedded nulls. + Value& operator[](const std::string& key); + /// Access an object value by name, returns null if there is no member with + /// that name. + /// \param key may contain embedded nulls. + const Value& operator[](const std::string& key) const; + /** \brief Access an object value by name, create a null member if it does not + exist. + + * If the object has no entry for that name, then the member name used to store + * the new entry is not duplicated. + * Example of use: + * \code + * Json::Value object; + * static const StaticString code("code"); + * object[code] = 1234; + * \endcode + */ + Value& operator[](const StaticString& key); +#ifdef JSON_USE_CPPTL + /// Access an object value by name, create a null member if it does not exist. + Value& operator[](const CppTL::ConstString& key); + /// Access an object value by name, returns null if there is no member with + /// that name. + const Value& operator[](const CppTL::ConstString& key) const; +#endif + /// Return the member named key if it exist, defaultValue otherwise. + /// \note deep copy + Value get(const char* key, const Value& defaultValue) const; + /// Return the member named key if it exist, defaultValue otherwise. + /// \note deep copy + /// \note key may contain embedded nulls. + Value get(const char* begin, const char* end, const Value& defaultValue) const; + /// Return the member named key if it exist, defaultValue otherwise. + /// \note deep copy + /// \param key may contain embedded nulls. + Value get(const std::string& key, const Value& defaultValue) const; +#ifdef JSON_USE_CPPTL + /// Return the member named key if it exist, defaultValue otherwise. + /// \note deep copy + Value get(const CppTL::ConstString& key, const Value& defaultValue) const; +#endif + /// Most general and efficient version of isMember()const, get()const, + /// and operator[]const + /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 + Value const* find(char const* begin, char const* end) const; + /// Most general and efficient version of object-mutators. + /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 + /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue. + Value const* demand(char const* begin, char const* end); + /// \brief Remove and return the named member. + /// + /// Do nothing if it did not exist. + /// \return the removed Value, or null. + /// \pre type() is objectValue or nullValue + /// \post type() is unchanged + /// \deprecated + Value removeMember(const char* key); + /// Same as removeMember(const char*) + /// \param key may contain embedded nulls. + /// \deprecated + Value removeMember(const std::string& key); + /// Same as removeMember(const char* begin, const char* end, Value* removed), + /// but 'key' is null-terminated. + bool removeMember(const char* key, Value* removed); + /** \brief Remove the named map member. + + Update 'removed' iff removed. + \param key may contain embedded nulls. + \return true iff removed (no exceptions) + */ + bool removeMember(std::string const& key, Value* removed); + /// Same as removeMember(std::string const& key, Value* removed) + bool removeMember(const char* begin, const char* end, Value* removed); + /** \brief Remove the indexed array element. + + O(n) expensive operations. + Update 'removed' iff removed. + \return true iff removed (no exceptions) + */ + bool removeIndex(ArrayIndex i, Value* removed); + + /// Return true if the object has a member named key. + /// \note 'key' must be null-terminated. + bool isMember(const char* key) const; + /// Return true if the object has a member named key. + /// \param key may contain embedded nulls. + bool isMember(const std::string& key) const; + /// Same as isMember(std::string const& key)const + bool isMember(const char* begin, const char* end) const; +#ifdef JSON_USE_CPPTL + /// Return true if the object has a member named key. + bool isMember(const CppTL::ConstString& key) const; +#endif + + /// \brief Return a list of the member names. + /// + /// If null, return an empty list. + /// \pre type() is objectValue or nullValue + /// \post if type() was nullValue, it remains nullValue + Members getMemberNames() const; + + //# ifdef JSON_USE_CPPTL + // EnumMemberNames enumMemberNames() const; + // EnumValues enumValues() const; + //# endif + + /// \deprecated Always pass len. + JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.") + void setComment(const char* comment, CommentPlacement placement); + /// Comments must be //... or /* ... */ + void setComment(const char* comment, size_t len, CommentPlacement placement); + /// Comments must be //... or /* ... */ + void setComment(const std::string& comment, CommentPlacement placement); + bool hasComment(CommentPlacement placement) const; + /// Include delimiters and embedded newlines. + std::string getComment(CommentPlacement placement) const; + + std::string toStyledString() const; + + const_iterator begin() const; + const_iterator end() const; + + iterator begin(); + iterator end(); + + // Accessors for the [start, limit) range of bytes within the JSON text from + // which this value was parsed, if any. + void setOffsetStart(size_t start); + void setOffsetLimit(size_t limit); + size_t getOffsetStart() const; + size_t getOffsetLimit() const; + +private: + void initBasic(ValueType type, bool allocated = false); + + Value& resolveReference(const char* key); + Value& resolveReference(const char* key, const char* end); + + struct CommentInfo { + CommentInfo(); + ~CommentInfo(); + + void setComment(const char* text, size_t len); + + char* comment_; + }; + + // struct MemberNamesTransform + //{ + // typedef const char *result_type; + // const char *operator()( const CZString &name ) const + // { + // return name.c_str(); + // } + //}; + + union ValueHolder { + LargestInt int_; + LargestUInt uint_; + double real_; + bool bool_; + char* string_; // actually ptr to unsigned, followed by str, unless !allocated_ + ObjectValues* map_; + } value_; + ValueType type_ : 8; + unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. + // If not allocated_, string_ must be null-terminated. + CommentInfo* comments_; + + // [start, limit) byte offsets in the source JSON text from which this Value + // was extracted. + size_t start_; + size_t limit_; +}; + +/** \brief Experimental and untested: represents an element of the "path" to + * access a node. + */ +class JSON_API PathArgument { +public: + friend class Path; + + PathArgument(); + PathArgument(ArrayIndex index); + PathArgument(const char* key); + PathArgument(const std::string& key); + +private: + enum Kind { + kindNone = 0, + kindIndex, + kindKey + }; + std::string key_; + ArrayIndex index_; + Kind kind_; +}; + +/** \brief Experimental and untested: represents a "path" to access a node. + * + * Syntax: + * - "." => root node + * - ".[n]" => elements at index 'n' of root node (an array value) + * - ".name" => member named 'name' of root node (an object value) + * - ".name1.name2.name3" + * - ".[0][1][2].name1[3]" + * - ".%" => member name is provided as parameter + * - ".[%]" => index is provided as parameter + */ +class JSON_API Path { +public: + Path(const std::string& path, + const PathArgument& a1 = PathArgument(), + const PathArgument& a2 = PathArgument(), + const PathArgument& a3 = PathArgument(), + const PathArgument& a4 = PathArgument(), + const PathArgument& a5 = PathArgument()); + + const Value& resolve(const Value& root) const; + Value resolve(const Value& root, const Value& defaultValue) const; + /// Creates the "path" to access the specified node and returns a reference on + /// the node. + Value& make(Value& root) const; + +private: + typedef std::vector InArgs; + typedef std::vector Args; + + void makePath(const std::string& path, const InArgs& in); + void addPathInArg(const std::string& path, + const InArgs& in, + InArgs::const_iterator& itInArg, + PathArgument::Kind kind); + void invalidPath(const std::string& path, int location); + + Args args_; +}; + +/** \brief base class for Value iterators. + * + */ +class JSON_API ValueIteratorBase { +public: + typedef std::bidirectional_iterator_tag iterator_category; + typedef unsigned int size_t; + typedef int difference_type; + typedef ValueIteratorBase SelfType; + + bool operator==(const SelfType& other) const { return isEqual(other); } + + bool operator!=(const SelfType& other) const { return !isEqual(other); } + + difference_type operator-(const SelfType& other) const { + return other.computeDistance(*this); + } + + /// Return either the index or the member name of the referenced value as a + /// Value. + Value key() const; + + /// Return the index of the referenced Value, or -1 if it is not an arrayValue. + UInt index() const; + + /// Return the member name of the referenced Value, or "" if it is not an + /// objectValue. + /// \note Avoid `c_str()` on result, as embedded zeroes are possible. + std::string name() const; + + /// Return the member name of the referenced Value. "" if it is not an + /// objectValue. + /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls. + JSONCPP_DEPRECATED("Use `key = name();` instead.") + char const* memberName() const; + /// Return the member name of the referenced Value, or NULL if it is not an + /// objectValue. + /// \note Better version than memberName(). Allows embedded nulls. + char const* memberName(char const** end) const; + +protected: + Value& deref() const; + + void increment(); + + void decrement(); + + difference_type computeDistance(const SelfType& other) const; + + bool isEqual(const SelfType& other) const; + + void copy(const SelfType& other); + +private: + Value::ObjectValues::iterator current_; + // Indicates that iterator is for a null value. + bool isNull_; + +public: + // For some reason, BORLAND needs these at the end, rather + // than earlier. No idea why. + ValueIteratorBase(); + explicit ValueIteratorBase(const Value::ObjectValues::iterator& current); +}; + +/** \brief const iterator for object and array value. + * + */ +class JSON_API ValueConstIterator : public ValueIteratorBase { + friend class Value; + +public: + typedef const Value value_type; + //typedef unsigned int size_t; + //typedef int difference_type; + typedef const Value& reference; + typedef const Value* pointer; + typedef ValueConstIterator SelfType; + + ValueConstIterator(); + ValueConstIterator(ValueIterator const& other); + +private: +/*! \internal Use by Value to create an iterator. + */ + explicit ValueConstIterator(const Value::ObjectValues::iterator& current); +public: + SelfType& operator=(const ValueIteratorBase& other); + + SelfType operator++(int) { + SelfType temp(*this); + ++*this; + return temp; + } + + SelfType operator--(int) { + SelfType temp(*this); + --*this; + return temp; + } + + SelfType& operator--() { + decrement(); + return *this; + } + + SelfType& operator++() { + increment(); + return *this; + } + + reference operator*() const { return deref(); } + + pointer operator->() const { return &deref(); } +}; + +/** \brief Iterator for object and array value. + */ +class JSON_API ValueIterator : public ValueIteratorBase { + friend class Value; + +public: + typedef Value value_type; + typedef unsigned int size_t; + typedef int difference_type; + typedef Value& reference; + typedef Value* pointer; + typedef ValueIterator SelfType; + + ValueIterator(); + explicit ValueIterator(const ValueConstIterator& other); + ValueIterator(const ValueIterator& other); + +private: +/*! \internal Use by Value to create an iterator. + */ + explicit ValueIterator(const Value::ObjectValues::iterator& current); +public: + SelfType& operator=(const SelfType& other); + + SelfType operator++(int) { + SelfType temp(*this); + ++*this; + return temp; + } + + SelfType operator--(int) { + SelfType temp(*this); + --*this; + return temp; + } + + SelfType& operator--() { + decrement(); + return *this; + } + + SelfType& operator++() { + increment(); + return *this; + } + + reference operator*() const { return deref(); } + + pointer operator->() const { return &deref(); } +}; + +} // namespace Json + + +namespace std { +/// Specialize std::swap() for Json::Value. +template<> +inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); } +} + + +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(pop) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +#endif // CPPTL_JSON_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/value.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/reader.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef CPPTL_JSON_READER_H_INCLUDED +#define CPPTL_JSON_READER_H_INCLUDED + +#if !defined(JSON_IS_AMALGAMATION) +#include "features.h" +#include "value.h" +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#include +#include + +// Disable warning C4251: : needs to have dll-interface to +// be used by... +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(push) +#pragma warning(disable : 4251) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +namespace Json { + +/** \brief Unserialize a JSON document into a + *Value. + * + * \deprecated Use CharReader and CharReaderBuilder. + */ +class JSON_API Reader { +public: + typedef char Char; + typedef const Char* Location; + + /** \brief An error tagged with where in the JSON text it was encountered. + * + * The offsets give the [start, limit) range of bytes within the text. Note + * that this is bytes, not codepoints. + * + */ + struct StructuredError { + size_t offset_start; + size_t offset_limit; + std::string message; + }; + + /** \brief Constructs a Reader allowing all features + * for parsing. + */ + Reader(); + + /** \brief Constructs a Reader allowing the specified feature set + * for parsing. + */ + Reader(const Features& features); + + /** \brief Read a Value from a JSON + * document. + * \param document UTF-8 encoded string containing the document to read. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param collectComments \c true to collect comment and allow writing them + * back during + * serialization, \c false to discard comments. + * This parameter is ignored if + * Features::allowComments_ + * is \c false. + * \return \c true if the document was successfully parsed, \c false if an + * error occurred. + */ + bool + parse(const std::string& document, Value& root, bool collectComments = true); + + /** \brief Read a Value from a JSON + document. + * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the + document to read. + * \param endDoc Pointer on the end of the UTF-8 encoded string of the + document to read. + * Must be >= beginDoc. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param collectComments \c true to collect comment and allow writing them + back during + * serialization, \c false to discard comments. + * This parameter is ignored if + Features::allowComments_ + * is \c false. + * \return \c true if the document was successfully parsed, \c false if an + error occurred. + */ + bool parse(const char* beginDoc, + const char* endDoc, + Value& root, + bool collectComments = true); + + /// \brief Parse from input stream. + /// \see Json::operator>>(std::istream&, Json::Value&). + bool parse(std::istream& is, Value& root, bool collectComments = true); + + /** \brief Returns a user friendly string that list errors in the parsed + * document. + * \return Formatted error message with the list of errors with their location + * in + * the parsed document. An empty string is returned if no error + * occurred + * during parsing. + * \deprecated Use getFormattedErrorMessages() instead (typo fix). + */ + JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.") + std::string getFormatedErrorMessages() const; + + /** \brief Returns a user friendly string that list errors in the parsed + * document. + * \return Formatted error message with the list of errors with their location + * in + * the parsed document. An empty string is returned if no error + * occurred + * during parsing. + */ + std::string getFormattedErrorMessages() const; + + /** \brief Returns a vector of structured errors encountered while parsing. + * \return A (possibly empty) vector of StructuredError objects. Currently + * only one error can be returned, but the caller should tolerate + * multiple + * errors. This can occur if the parser recovers from a non-fatal + * parse error and then encounters additional errors. + */ + std::vector getStructuredErrors() const; + + /** \brief Add a semantic error message. + * \param value JSON Value location associated with the error + * \param message The error message. + * \return \c true if the error was successfully added, \c false if the + * Value offset exceeds the document size. + */ + bool pushError(const Value& value, const std::string& message); + + /** \brief Add a semantic error message with extra context. + * \param value JSON Value location associated with the error + * \param message The error message. + * \param extra Additional JSON Value location to contextualize the error + * \return \c true if the error was successfully added, \c false if either + * Value offset exceeds the document size. + */ + bool pushError(const Value& value, const std::string& message, const Value& extra); + + /** \brief Return whether there are any errors. + * \return \c true if there are no errors to report \c false if + * errors have occurred. + */ + bool good() const; + +private: + enum TokenType { + tokenEndOfStream = 0, + tokenObjectBegin, + tokenObjectEnd, + tokenArrayBegin, + tokenArrayEnd, + tokenString, + tokenNumber, + tokenTrue, + tokenFalse, + tokenNull, + tokenArraySeparator, + tokenMemberSeparator, + tokenComment, + tokenError + }; + + class Token { + public: + TokenType type_; + Location start_; + Location end_; + }; + + class ErrorInfo { + public: + Token token_; + std::string message_; + Location extra_; + }; + + typedef std::deque Errors; + + bool readToken(Token& token); + void skipSpaces(); + bool match(Location pattern, int patternLength); + bool readComment(); + bool readCStyleComment(); + bool readCppStyleComment(); + bool readString(); + void readNumber(); + bool readValue(); + bool readObject(Token& token); + bool readArray(Token& token); + bool decodeNumber(Token& token); + bool decodeNumber(Token& token, Value& decoded); + bool decodeString(Token& token); + bool decodeString(Token& token, std::string& decoded); + bool decodeDouble(Token& token); + bool decodeDouble(Token& token, Value& decoded); + bool decodeUnicodeCodePoint(Token& token, + Location& current, + Location end, + unsigned int& unicode); + bool decodeUnicodeEscapeSequence(Token& token, + Location& current, + Location end, + unsigned int& unicode); + bool addError(const std::string& message, Token& token, Location extra = 0); + bool recoverFromError(TokenType skipUntilToken); + bool addErrorAndRecover(const std::string& message, + Token& token, + TokenType skipUntilToken); + void skipUntilSpace(); + Value& currentValue(); + Char getNextChar(); + void + getLocationLineAndColumn(Location location, int& line, int& column) const; + std::string getLocationLineAndColumn(Location location) const; + void addComment(Location begin, Location end, CommentPlacement placement); + void skipCommentTokens(Token& token); + + typedef std::stack Nodes; + Nodes nodes_; + Errors errors_; + std::string document_; + Location begin_; + Location end_; + Location current_; + Location lastValueEnd_; + Value* lastValue_; + std::string commentsBefore_; + Features features_; + bool collectComments_; +}; // Reader + +/** Interface for reading JSON from a char array. + */ +class JSON_API CharReader { +public: + virtual ~CharReader() {} + /** \brief Read a Value from a JSON + document. + * The document must be a UTF-8 encoded string containing the document to read. + * + * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the + document to read. + * \param endDoc Pointer on the end of the UTF-8 encoded string of the + document to read. + * Must be >= beginDoc. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param errs [out] Formatted error messages (if not NULL) + * a user friendly string that lists errors in the parsed + * document. + * \return \c true if the document was successfully parsed, \c false if an + error occurred. + */ + virtual bool parse( + char const* beginDoc, char const* endDoc, + Value* root, std::string* errs) = 0; + + class JSON_API Factory { + public: + virtual ~Factory() {} + /** \brief Allocate a CharReader via operator new(). + * \throw std::exception if something goes wrong (e.g. invalid settings) + */ + virtual CharReader* newCharReader() const = 0; + }; // Factory +}; // CharReader + +/** \brief Build a CharReader implementation. + +Usage: +\code + using namespace Json; + CharReaderBuilder builder; + builder["collectComments"] = false; + Value value; + std::string errs; + bool ok = parseFromStream(builder, std::cin, &value, &errs); +\endcode +*/ +class JSON_API CharReaderBuilder : public CharReader::Factory { +public: + // Note: We use a Json::Value so that we can add data-members to this class + // without a major version bump. + /** Configuration of this builder. + These are case-sensitive. + Available settings (case-sensitive): + - `"collectComments": false or true` + - true to collect comment and allow writing them + back during serialization, false to discard comments. + This parameter is ignored if allowComments is false. + - `"allowComments": false or true` + - true if comments are allowed. + - `"strictRoot": false or true` + - true if root must be either an array or an object value + - `"allowDroppedNullPlaceholders": false or true` + - true if dropped null placeholders are allowed. (See StreamWriterBuilder.) + - `"allowNumericKeys": false or true` + - true if numeric object keys are allowed. + - `"allowSingleQuotes": false or true` + - true if '' are allowed for strings (both keys and values) + - `"stackLimit": integer` + - Exceeding stackLimit (recursive depth of `readValue()`) will + cause an exception. + - This is a security issue (seg-faults caused by deeply nested JSON), + so the default is low. + - `"failIfExtra": false or true` + - If true, `parse()` returns false when extra non-whitespace trails + the JSON value in the input string. + - `"rejectDupKeys": false or true` + - If true, `parse()` returns false when a key is duplicated within an object. + - `"allowSpecialFloats": false or true` + - If true, special float values (NaNs and infinities) are allowed + and their values are lossfree restorable. + + You can examine 'settings_` yourself + to see the defaults. You can also write and read them just like any + JSON Value. + \sa setDefaults() + */ + Json::Value settings_; + + CharReaderBuilder(); + ~CharReaderBuilder() override; + + CharReader* newCharReader() const override; + + /** \return true if 'settings' are legal and consistent; + * otherwise, indicate bad settings via 'invalid'. + */ + bool validate(Json::Value* invalid) const; + + /** A simple way to update a specific setting. + */ + Value& operator[](std::string key); + + /** Called by ctor, but you can use this to reset settings_. + * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults + */ + static void setDefaults(Json::Value* settings); + /** Same as old Features::strictMode(). + * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode + */ + static void strictMode(Json::Value* settings); +}; + +/** Consume entire stream and use its begin/end. + * Someday we might have a real StreamReader, but for now this + * is convenient. + */ +bool JSON_API parseFromStream( + CharReader::Factory const&, + std::istream&, + Value* root, std::string* errs); + +/** \brief Read from 'sin' into 'root'. + + Always keep comments from the input JSON. + + This can be used to read a file into a particular sub-object. + For example: + \code + Json::Value root; + cin >> root["dir"]["file"]; + cout << root; + \endcode + Result: + \verbatim + { + "dir": { + "file": { + // The input stream JSON would be nested here. + } + } + } + \endverbatim + \throw std::exception on parse error. + \see Json::operator<<() +*/ +JSON_API std::istream& operator>>(std::istream&, Value&); + +} // namespace Json + +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(pop) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +#endif // CPPTL_JSON_READER_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/reader.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/writer.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef JSON_WRITER_H_INCLUDED +#define JSON_WRITER_H_INCLUDED + +#if !defined(JSON_IS_AMALGAMATION) +#include "value.h" +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include + +// Disable warning C4251: : needs to have dll-interface to +// be used by... +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(push) +#pragma warning(disable : 4251) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +namespace Json { + +class Value; + +/** + +Usage: +\code + using namespace Json; + void writeToStdout(StreamWriter::Factory const& factory, Value const& value) { + std::unique_ptr const writer( + factory.newStreamWriter()); + writer->write(value, &std::cout); + std::cout << std::endl; // add lf and flush + } +\endcode +*/ +class JSON_API StreamWriter { +protected: + std::ostream* sout_; // not owned; will not delete +public: + StreamWriter(); + virtual ~StreamWriter(); + /** Write Value into document as configured in sub-class. + Do not take ownership of sout, but maintain a reference during function. + \pre sout != NULL + \return zero on success (For now, we always return zero, so check the stream instead.) + \throw std::exception possibly, depending on configuration + */ + virtual int write(Value const& root, std::ostream* sout) = 0; + + /** \brief A simple abstract factory. + */ + class JSON_API Factory { + public: + virtual ~Factory(); + /** \brief Allocate a CharReader via operator new(). + * \throw std::exception if something goes wrong (e.g. invalid settings) + */ + virtual StreamWriter* newStreamWriter() const = 0; + }; // Factory +}; // StreamWriter + +/** \brief Write into stringstream, then return string, for convenience. + * A StreamWriter will be created from the factory, used, and then deleted. + */ +std::string JSON_API writeString(StreamWriter::Factory const& factory, Value const& root); + + +/** \brief Build a StreamWriter implementation. + +Usage: +\code + using namespace Json; + Value value = ...; + StreamWriterBuilder builder; + builder["commentStyle"] = "None"; + builder["indentation"] = " "; // or whatever you like + std::unique_ptr writer( + builder.newStreamWriter()); + writer->write(value, &std::cout); + std::cout << std::endl; // add lf and flush +\endcode +*/ +class JSON_API StreamWriterBuilder : public StreamWriter::Factory { +public: + // Note: We use a Json::Value so that we can add data-members to this class + // without a major version bump. + /** Configuration of this builder. + Available settings (case-sensitive): + - "commentStyle": "None" or "All" + - "indentation": "" + - "enableYAMLCompatibility": false or true + - slightly change the whitespace around colons + - "dropNullPlaceholders": false or true + - Drop the "null" string from the writer's output for nullValues. + Strictly speaking, this is not valid JSON. But when the output is being + fed to a browser's Javascript, it makes for smaller output and the + browser can handle the output just fine. + - "useSpecialFloats": false or true + - If true, outputs non-finite floating point values in the following way: + NaN values as "NaN", positive infinity as "Infinity", and negative infinity + as "-Infinity". + + You can examine 'settings_` yourself + to see the defaults. You can also write and read them just like any + JSON Value. + \sa setDefaults() + */ + Json::Value settings_; + + StreamWriterBuilder(); + ~StreamWriterBuilder() override; + + /** + * \throw std::exception if something goes wrong (e.g. invalid settings) + */ + StreamWriter* newStreamWriter() const override; + + /** \return true if 'settings' are legal and consistent; + * otherwise, indicate bad settings via 'invalid'. + */ + bool validate(Json::Value* invalid) const; + /** A simple way to update a specific setting. + */ + Value& operator[](std::string key); + + /** Called by ctor, but you can use this to reset settings_. + * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults + */ + static void setDefaults(Json::Value* settings); +}; + +/** \brief Abstract class for writers. + * \deprecated Use StreamWriter. (And really, this is an implementation detail.) + */ +class JSON_API Writer { +public: + virtual ~Writer(); + + virtual std::string write(const Value& root) = 0; +}; + +/** \brief Outputs a Value in JSON format + *without formatting (not human friendly). + * + * The JSON document is written in a single line. It is not intended for 'human' + *consumption, + * but may be useful to support feature such as RPC where bandwidth is limited. + * \sa Reader, Value + * \deprecated Use StreamWriterBuilder. + */ +class JSON_API FastWriter : public Writer { + +public: + FastWriter(); + ~FastWriter() override {} + + void enableYAMLCompatibility(); + + /** \brief Drop the "null" string from the writer's output for nullValues. + * Strictly speaking, this is not valid JSON. But when the output is being + * fed to a browser's Javascript, it makes for smaller output and the + * browser can handle the output just fine. + */ + void dropNullPlaceholders(); + + void omitEndingLineFeed(); + +public: // overridden from Writer + std::string write(const Value& root) override; + +private: + void writeValue(const Value& value); + + std::string document_; + bool yamlCompatiblityEnabled_; + bool dropNullPlaceholders_; + bool omitEndingLineFeed_; +}; + +/** \brief Writes a Value in JSON format in a + *human friendly way. + * + * The rules for line break and indent are as follow: + * - Object value: + * - if empty then print {} without indent and line break + * - if not empty the print '{', line break & indent, print one value per + *line + * and then unindent and line break and print '}'. + * - Array value: + * - if empty then print [] without indent and line break + * - if the array contains no object value, empty array or some other value + *types, + * and all the values fit on one lines, then print the array on a single + *line. + * - otherwise, it the values do not fit on one line, or the array contains + * object or non empty array, then print one value per line. + * + * If the Value have comments then they are outputted according to their + *#CommentPlacement. + * + * \sa Reader, Value, Value::setComment() + * \deprecated Use StreamWriterBuilder. + */ +class JSON_API StyledWriter : public Writer { +public: + StyledWriter(); + ~StyledWriter() override {} + +public: // overridden from Writer + /** \brief Serialize a Value in JSON format. + * \param root Value to serialize. + * \return String containing the JSON document that represents the root value. + */ + std::string write(const Value& root) override; + +private: + void writeValue(const Value& value); + void writeArrayValue(const Value& value); + bool isMultineArray(const Value& value); + void pushValue(const std::string& value); + void writeIndent(); + void writeWithIndent(const std::string& value); + void indent(); + void unindent(); + void writeCommentBeforeValue(const Value& root); + void writeCommentAfterValueOnSameLine(const Value& root); + bool hasCommentForValue(const Value& value); + static std::string normalizeEOL(const std::string& text); + + typedef std::vector ChildValues; + + ChildValues childValues_; + std::string document_; + std::string indentString_; + int rightMargin_; + int indentSize_; + bool addChildValues_; +}; + +/** \brief Writes a Value in JSON format in a + human friendly way, + to a stream rather than to a string. + * + * The rules for line break and indent are as follow: + * - Object value: + * - if empty then print {} without indent and line break + * - if not empty the print '{', line break & indent, print one value per + line + * and then unindent and line break and print '}'. + * - Array value: + * - if empty then print [] without indent and line break + * - if the array contains no object value, empty array or some other value + types, + * and all the values fit on one lines, then print the array on a single + line. + * - otherwise, it the values do not fit on one line, or the array contains + * object or non empty array, then print one value per line. + * + * If the Value have comments then they are outputted according to their + #CommentPlacement. + * + * \param indentation Each level will be indented by this amount extra. + * \sa Reader, Value, Value::setComment() + * \deprecated Use StreamWriterBuilder. + */ +class JSON_API StyledStreamWriter { +public: + StyledStreamWriter(std::string indentation = "\t"); + ~StyledStreamWriter() {} + +public: + /** \brief Serialize a Value in JSON format. + * \param out Stream to write to. (Can be ostringstream, e.g.) + * \param root Value to serialize. + * \note There is no point in deriving from Writer, since write() should not + * return a value. + */ + void write(std::ostream& out, const Value& root); + +private: + void writeValue(const Value& value); + void writeArrayValue(const Value& value); + bool isMultineArray(const Value& value); + void pushValue(const std::string& value); + void writeIndent(); + void writeWithIndent(const std::string& value); + void indent(); + void unindent(); + void writeCommentBeforeValue(const Value& root); + void writeCommentAfterValueOnSameLine(const Value& root); + bool hasCommentForValue(const Value& value); + static std::string normalizeEOL(const std::string& text); + + typedef std::vector ChildValues; + + ChildValues childValues_; + std::ostream* document_; + std::string indentString_; + int rightMargin_; + std::string indentation_; + bool addChildValues_ : 1; + bool indented_ : 1; +}; + +#if defined(JSON_HAS_INT64) +std::string JSON_API valueToString(Int value); +std::string JSON_API valueToString(UInt value); +#endif // if defined(JSON_HAS_INT64) +std::string JSON_API valueToString(LargestInt value); +std::string JSON_API valueToString(LargestUInt value); +std::string JSON_API valueToString(double value); +std::string JSON_API valueToString(bool value); +std::string JSON_API valueToQuotedString(const char* value); + +/// \brief Output using the StyledStreamWriter. +/// \see Json::operator>>() +JSON_API std::ostream& operator<<(std::ostream&, const Value& root); + +} // namespace Json + +#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +#pragma warning(pop) +#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) + +#endif // JSON_WRITER_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/writer.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: include/json/assertions.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED +#define CPPTL_JSON_ASSERTIONS_H_INCLUDED + +#include +#include + +#if !defined(JSON_IS_AMALGAMATION) +#include "config.h" +#endif // if !defined(JSON_IS_AMALGAMATION) + +/** It should not be possible for a maliciously designed file to + * cause an abort() or seg-fault, so these macros are used only + * for pre-condition violations and internal logic errors. + */ +#if JSON_USE_EXCEPTION + +// @todo <= add detail about condition in exception +# define JSON_ASSERT(condition) \ + {if (!(condition)) {Json::throwLogicError( "assert json failed" );}} + +# define JSON_FAIL_MESSAGE(message) \ + { \ + std::ostringstream oss; oss << message; \ + Json::throwLogicError(oss.str()); \ + abort(); \ + } + +#else // JSON_USE_EXCEPTION + +# define JSON_ASSERT(condition) assert(condition) + +// The call to assert() will show the failure message in debug builds. In +// release builds we abort, for a core-dump or debugger. +# define JSON_FAIL_MESSAGE(message) \ + { \ + std::ostringstream oss; oss << message; \ + assert(false && oss.str().c_str()); \ + abort(); \ + } + + +#endif + +#define JSON_ASSERT_MESSAGE(condition, message) \ + if (!(condition)) { \ + JSON_FAIL_MESSAGE(message); \ + } + +#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: include/json/assertions.h +// ////////////////////////////////////////////////////////////////////// + + + + + +#endif //ifndef JSON_AMALGATED_H_INCLUDED diff --git a/libs/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp b/libs/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp new file mode 100644 index 0000000..78919ea --- /dev/null +++ b/libs/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp @@ -0,0 +1,5192 @@ +/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/). +/// It is intended to be used with #include "json/json.h" + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: LICENSE +// ////////////////////////////////////////////////////////////////////// + +/* +The JsonCpp library's source code, including accompanying documentation, +tests and demonstration applications, are licensed under the following +conditions... + +The author (Baptiste Lepilleur) explicitly disclaims copyright in all +jurisdictions which recognize such a disclaimer. In such jurisdictions, +this software is released into the Public Domain. + +In jurisdictions which do not recognize Public Domain property (e.g. Germany as of +2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is +released under the terms of the MIT License (see below). + +In jurisdictions which recognize Public Domain property, the user of this +software may choose to accept it either as 1) Public Domain, 2) under the +conditions of the MIT License (see below), or 3) under the terms of dual +Public Domain/MIT License conditions described here, as they choose. + +The MIT License is about as close to Public Domain as a license can get, and is +described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + +The full text of the MIT License follows: + +======================================================================== +Copyright (c) 2007-2010 Baptiste Lepilleur + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, +modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +======================================================================== +(END LICENSE TEXT) + +The MIT license is compatible with both the GPL and commercial +software, affording one all of the rights of Public Domain with the +minor nuisance of being required to keep the above copyright notice +and license text in the source code. Note also that by accepting the +Public Domain "license" you can re-license your copy using whatever +license you like. + +*/ + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: LICENSE +// ////////////////////////////////////////////////////////////////////// + + + + + + +#include "third_party/jsoncpp/json.h" + +#ifndef JSON_IS_AMALGAMATION +#error "Compile with -I PATH_TO_JSON_DIRECTORY" +#endif + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: src/lib_json/json_tool.h +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED +#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED + +/* This header provides common string manipulation support, such as UTF-8, + * portable conversion from/to string... + * + * It is an internal header that must not be exposed. + */ + +namespace Json { + +/// Converts a unicode code-point to UTF-8. +static inline std::string codePointToUTF8(unsigned int cp) { + std::string result; + + // based on description from http://en.wikipedia.org/wiki/UTF-8 + + if (cp <= 0x7f) { + result.resize(1); + result[0] = static_cast(cp); + } else if (cp <= 0x7FF) { + result.resize(2); + result[1] = static_cast(0x80 | (0x3f & cp)); + result[0] = static_cast(0xC0 | (0x1f & (cp >> 6))); + } else if (cp <= 0xFFFF) { + result.resize(3); + result[2] = static_cast(0x80 | (0x3f & cp)); + result[1] = static_cast(0x80 | (0x3f & (cp >> 6))); + result[0] = static_cast(0xE0 | (0xf & (cp >> 12))); + } else if (cp <= 0x10FFFF) { + result.resize(4); + result[3] = static_cast(0x80 | (0x3f & cp)); + result[2] = static_cast(0x80 | (0x3f & (cp >> 6))); + result[1] = static_cast(0x80 | (0x3f & (cp >> 12))); + result[0] = static_cast(0xF0 | (0x7 & (cp >> 18))); + } + + return result; +} + +/// Returns true if ch is a control character (in range [1,31]). +static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; } + +enum { + /// Constant that specify the size of the buffer that must be passed to + /// uintToString. + uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1 +}; + +// Defines a char buffer for use with uintToString(). +typedef char UIntToStringBuffer[uintToStringBufferSize]; + +/** Converts an unsigned integer to string. + * @param value Unsigned integer to convert to string + * @param current Input/Output string buffer. + * Must have at least uintToStringBufferSize chars free. + */ +static inline void uintToString(LargestUInt value, char*& current) { + *--current = 0; + do { + *--current = static_cast(value % 10U + static_cast('0')); + value /= 10; + } while (value != 0); +} + +/** Change ',' to '.' everywhere in buffer. + * + * We had a sophisticated way, but it did not work in WinCE. + * @see https://github.com/open-source-parsers/jsoncpp/pull/9 + */ +static inline void fixNumericLocale(char* begin, char* end) { + while (begin < end) { + if (*begin == ',') { + *begin = '.'; + } + ++begin; + } +} + +} // namespace Json { + +#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: src/lib_json/json_tool.h +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: src/lib_json/json_reader.cpp +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2011 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#include "json_tool.h" +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(_MSC_VER) +#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above +#define snprintf sprintf_s +#elif _MSC_VER >= 1900 // VC++ 14.0 and above +#define snprintf std::snprintf +#else +#define snprintf _snprintf +#endif +#elif defined(__ANDROID__) || defined(__QNXNTO__) +#define snprintf snprintf +#elif __cplusplus >= 201103L +#define snprintf std::snprintf +#endif + +#if defined(__QNXNTO__) +#define sscanf std::sscanf +#endif + +#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0 +// Disable warning about strdup being deprecated. +#pragma warning(disable : 4996) +#endif + +static int const stackLimit_g = 1000; +static int stackDepth_g = 0; // see readValue() + +namespace Json { + +#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) +typedef std::unique_ptr CharReaderPtr; +#else +typedef std::auto_ptr CharReaderPtr; +#endif + +// Implementation of class Features +// //////////////////////////////// + +Features::Features() + : allowComments_(true), strictRoot_(false), + allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) {} + +Features Features::all() { return Features(); } + +Features Features::strictMode() { + Features features; + features.allowComments_ = false; + features.strictRoot_ = true; + features.allowDroppedNullPlaceholders_ = false; + features.allowNumericKeys_ = false; + return features; +} + +// Implementation of class Reader +// //////////////////////////////// + +static bool containsNewLine(Reader::Location begin, Reader::Location end) { + for (; begin < end; ++begin) + if (*begin == '\n' || *begin == '\r') + return true; + return false; +} + +// Class Reader +// ////////////////////////////////////////////////////////////////// + +Reader::Reader() + : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), + lastValue_(), commentsBefore_(), features_(Features::all()), + collectComments_() {} + +Reader::Reader(const Features& features) + : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), + lastValue_(), commentsBefore_(), features_(features), collectComments_() { +} + +bool +Reader::parse(const std::string& document, Value& root, bool collectComments) { + document_ = document; + const char* begin = document_.c_str(); + const char* end = begin + document_.length(); + return parse(begin, end, root, collectComments); +} + +bool Reader::parse(std::istream& sin, Value& root, bool collectComments) { + // std::istream_iterator begin(sin); + // std::istream_iterator end; + // Those would allow streamed input from a file, if parse() were a + // template function. + + // Since std::string is reference-counted, this at least does not + // create an extra copy. + std::string doc; + std::getline(sin, doc, (char)EOF); + return parse(doc, root, collectComments); +} + +bool Reader::parse(const char* beginDoc, + const char* endDoc, + Value& root, + bool collectComments) { + if (!features_.allowComments_) { + collectComments = false; + } + + begin_ = beginDoc; + end_ = endDoc; + collectComments_ = collectComments; + current_ = begin_; + lastValueEnd_ = 0; + lastValue_ = 0; + commentsBefore_ = ""; + errors_.clear(); + while (!nodes_.empty()) + nodes_.pop(); + nodes_.push(&root); + + stackDepth_g = 0; // Yes, this is bad coding, but options are limited. + bool successful = readValue(); + Token token; + skipCommentTokens(token); + if (collectComments_ && !commentsBefore_.empty()) + root.setComment(commentsBefore_, commentAfter); + if (features_.strictRoot_) { + if (!root.isArray() && !root.isObject()) { + // Set error location to start of doc, ideally should be first token found + // in doc + token.type_ = tokenError; + token.start_ = beginDoc; + token.end_ = endDoc; + addError( + "A valid JSON document must be either an array or an object value.", + token); + return false; + } + } + return successful; +} + +bool Reader::readValue() { + // This is a non-reentrant way to support a stackLimit. Terrible! + // But this deprecated class has a security problem: Bad input can + // cause a seg-fault. This seems like a fair, binary-compatible way + // to prevent the problem. + if (stackDepth_g >= stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue()."); + ++stackDepth_g; + + Token token; + skipCommentTokens(token); + bool successful = true; + + if (collectComments_ && !commentsBefore_.empty()) { + currentValue().setComment(commentsBefore_, commentBefore); + commentsBefore_ = ""; + } + + switch (token.type_) { + case tokenObjectBegin: + successful = readObject(token); + currentValue().setOffsetLimit(current_ - begin_); + break; + case tokenArrayBegin: + successful = readArray(token); + currentValue().setOffsetLimit(current_ - begin_); + break; + case tokenNumber: + successful = decodeNumber(token); + break; + case tokenString: + successful = decodeString(token); + break; + case tokenTrue: + { + Value v(true); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenFalse: + { + Value v(false); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenNull: + { + Value v; + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenArraySeparator: + case tokenObjectEnd: + case tokenArrayEnd: + if (features_.allowDroppedNullPlaceholders_) { + // "Un-read" the current token and mark the current value as a null + // token. + current_--; + Value v; + currentValue().swapPayload(v); + currentValue().setOffsetStart(current_ - begin_ - 1); + currentValue().setOffsetLimit(current_ - begin_); + break; + } // Else, fall through... + default: + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return addError("Syntax error: value, object or array expected.", token); + } + + if (collectComments_) { + lastValueEnd_ = current_; + lastValue_ = ¤tValue(); + } + + --stackDepth_g; + return successful; +} + +void Reader::skipCommentTokens(Token& token) { + if (features_.allowComments_) { + do { + readToken(token); + } while (token.type_ == tokenComment); + } else { + readToken(token); + } +} + +bool Reader::readToken(Token& token) { + skipSpaces(); + token.start_ = current_; + Char c = getNextChar(); + bool ok = true; + switch (c) { + case '{': + token.type_ = tokenObjectBegin; + break; + case '}': + token.type_ = tokenObjectEnd; + break; + case '[': + token.type_ = tokenArrayBegin; + break; + case ']': + token.type_ = tokenArrayEnd; + break; + case '"': + token.type_ = tokenString; + ok = readString(); + break; + case '/': + token.type_ = tokenComment; + ok = readComment(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + token.type_ = tokenNumber; + readNumber(); + break; + case 't': + token.type_ = tokenTrue; + ok = match("rue", 3); + break; + case 'f': + token.type_ = tokenFalse; + ok = match("alse", 4); + break; + case 'n': + token.type_ = tokenNull; + ok = match("ull", 3); + break; + case ',': + token.type_ = tokenArraySeparator; + break; + case ':': + token.type_ = tokenMemberSeparator; + break; + case 0: + token.type_ = tokenEndOfStream; + break; + default: + ok = false; + break; + } + if (!ok) + token.type_ = tokenError; + token.end_ = current_; + return true; +} + +void Reader::skipSpaces() { + while (current_ != end_) { + Char c = *current_; + if (c == ' ' || c == '\t' || c == '\r' || c == '\n') + ++current_; + else + break; + } +} + +bool Reader::match(Location pattern, int patternLength) { + if (end_ - current_ < patternLength) + return false; + int index = patternLength; + while (index--) + if (current_[index] != pattern[index]) + return false; + current_ += patternLength; + return true; +} + +bool Reader::readComment() { + Location commentBegin = current_ - 1; + Char c = getNextChar(); + bool successful = false; + if (c == '*') + successful = readCStyleComment(); + else if (c == '/') + successful = readCppStyleComment(); + if (!successful) + return false; + + if (collectComments_) { + CommentPlacement placement = commentBefore; + if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { + if (c != '*' || !containsNewLine(commentBegin, current_)) + placement = commentAfterOnSameLine; + } + + addComment(commentBegin, current_, placement); + } + return true; +} + +static std::string normalizeEOL(Reader::Location begin, Reader::Location end) { + std::string normalized; + normalized.reserve(end - begin); + Reader::Location current = begin; + while (current != end) { + char c = *current++; + if (c == '\r') { + if (current != end && *current == '\n') + // convert dos EOL + ++current; + // convert Mac EOL + normalized += '\n'; + } else { + normalized += c; + } + } + return normalized; +} + +void +Reader::addComment(Location begin, Location end, CommentPlacement placement) { + assert(collectComments_); + const std::string& normalized = normalizeEOL(begin, end); + if (placement == commentAfterOnSameLine) { + assert(lastValue_ != 0); + lastValue_->setComment(normalized, placement); + } else { + commentsBefore_ += normalized; + } +} + +bool Reader::readCStyleComment() { + while (current_ != end_) { + Char c = getNextChar(); + if (c == '*' && *current_ == '/') + break; + } + return getNextChar() == '/'; +} + +bool Reader::readCppStyleComment() { + while (current_ != end_) { + Char c = getNextChar(); + if (c == '\n') + break; + if (c == '\r') { + // Consume DOS EOL. It will be normalized in addComment. + if (current_ != end_ && *current_ == '\n') + getNextChar(); + // Break on Moc OS 9 EOL. + break; + } + } + return true; +} + +void Reader::readNumber() { + const char *p = current_; + char c = '0'; // stopgap for already consumed character + // integral part + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + // fractional part + if (c == '.') { + c = (current_ = p) < end_ ? *p++ : 0; + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + } + // exponential part + if (c == 'e' || c == 'E') { + c = (current_ = p) < end_ ? *p++ : 0; + if (c == '+' || c == '-') + c = (current_ = p) < end_ ? *p++ : 0; + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + } +} + +bool Reader::readString() { + Char c = 0; + while (current_ != end_) { + c = getNextChar(); + if (c == '\\') + getNextChar(); + else if (c == '"') + break; + } + return c == '"'; +} + +bool Reader::readObject(Token& tokenStart) { + Token tokenName; + std::string name; + Value init(objectValue); + currentValue().swapPayload(init); + currentValue().setOffsetStart(tokenStart.start_ - begin_); + while (readToken(tokenName)) { + bool initialTokenOk = true; + while (tokenName.type_ == tokenComment && initialTokenOk) + initialTokenOk = readToken(tokenName); + if (!initialTokenOk) + break; + if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object + return true; + name = ""; + if (tokenName.type_ == tokenString) { + if (!decodeString(tokenName, name)) + return recoverFromError(tokenObjectEnd); + } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { + Value numberName; + if (!decodeNumber(tokenName, numberName)) + return recoverFromError(tokenObjectEnd); + name = numberName.asString(); + } else { + break; + } + + Token colon; + if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { + return addErrorAndRecover( + "Missing ':' after object member name", colon, tokenObjectEnd); + } + Value& value = currentValue()[name]; + nodes_.push(&value); + bool ok = readValue(); + nodes_.pop(); + if (!ok) // error already set + return recoverFromError(tokenObjectEnd); + + Token comma; + if (!readToken(comma) || + (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && + comma.type_ != tokenComment)) { + return addErrorAndRecover( + "Missing ',' or '}' in object declaration", comma, tokenObjectEnd); + } + bool finalizeTokenOk = true; + while (comma.type_ == tokenComment && finalizeTokenOk) + finalizeTokenOk = readToken(comma); + if (comma.type_ == tokenObjectEnd) + return true; + } + return addErrorAndRecover( + "Missing '}' or object member name", tokenName, tokenObjectEnd); +} + +bool Reader::readArray(Token& tokenStart) { + Value init(arrayValue); + currentValue().swapPayload(init); + currentValue().setOffsetStart(tokenStart.start_ - begin_); + skipSpaces(); + if (*current_ == ']') // empty array + { + Token endArray; + readToken(endArray); + return true; + } + int index = 0; + for (;;) { + Value& value = currentValue()[index++]; + nodes_.push(&value); + bool ok = readValue(); + nodes_.pop(); + if (!ok) // error already set + return recoverFromError(tokenArrayEnd); + + Token token; + // Accept Comment after last item in the array. + ok = readToken(token); + while (token.type_ == tokenComment && ok) { + ok = readToken(token); + } + bool badTokenType = + (token.type_ != tokenArraySeparator && token.type_ != tokenArrayEnd); + if (!ok || badTokenType) { + return addErrorAndRecover( + "Missing ',' or ']' in array declaration", token, tokenArrayEnd); + } + if (token.type_ == tokenArrayEnd) + break; + } + return true; +} + +bool Reader::decodeNumber(Token& token) { + Value decoded; + if (!decodeNumber(token, decoded)) + return false; + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool Reader::decodeNumber(Token& token, Value& decoded) { + // Attempts to parse the number as an integer. If the number is + // larger than the maximum supported value of an integer then + // we decode the number as a double. + Location current = token.start_; + bool isNegative = *current == '-'; + if (isNegative) + ++current; + // TODO: Help the compiler do the div and mod at compile time or get rid of them. + Value::LargestUInt maxIntegerValue = + isNegative ? Value::LargestUInt(Value::maxLargestInt) + 1 + : Value::maxLargestUInt; + Value::LargestUInt threshold = maxIntegerValue / 10; + Value::LargestUInt value = 0; + while (current < token.end_) { + Char c = *current++; + if (c < '0' || c > '9') + return decodeDouble(token, decoded); + Value::UInt digit(c - '0'); + if (value >= threshold) { + // We've hit or exceeded the max value divided by 10 (rounded down). If + // a) we've only just touched the limit, b) this is the last digit, and + // c) it's small enough to fit in that rounding delta, we're okay. + // Otherwise treat this number as a double to avoid overflow. + if (value > threshold || current != token.end_ || + digit > maxIntegerValue % 10) { + return decodeDouble(token, decoded); + } + } + value = value * 10 + digit; + } + if (isNegative && value == maxIntegerValue) + decoded = Value::minLargestInt; + else if (isNegative) + decoded = -Value::LargestInt(value); + else if (value <= Value::LargestUInt(Value::maxInt)) + decoded = Value::LargestInt(value); + else + decoded = value; + return true; +} + +bool Reader::decodeDouble(Token& token) { + Value decoded; + if (!decodeDouble(token, decoded)) + return false; + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool Reader::decodeDouble(Token& token, Value& decoded) { + double value = 0; + std::string buffer(token.start_, token.end_); + std::istringstream is(buffer); + if (!(is >> value)) + return addError("'" + std::string(token.start_, token.end_) + + "' is not a number.", + token); + decoded = value; + return true; +} + +bool Reader::decodeString(Token& token) { + std::string decoded_string; + if (!decodeString(token, decoded_string)) + return false; + Value decoded(decoded_string); + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool Reader::decodeString(Token& token, std::string& decoded) { + decoded.reserve(token.end_ - token.start_ - 2); + Location current = token.start_ + 1; // skip '"' + Location end = token.end_ - 1; // do not include '"' + while (current != end) { + Char c = *current++; + if (c == '"') + break; + else if (c == '\\') { + if (current == end) + return addError("Empty escape sequence in string", token, current); + Char escape = *current++; + switch (escape) { + case '"': + decoded += '"'; + break; + case '/': + decoded += '/'; + break; + case '\\': + decoded += '\\'; + break; + case 'b': + decoded += '\b'; + break; + case 'f': + decoded += '\f'; + break; + case 'n': + decoded += '\n'; + break; + case 'r': + decoded += '\r'; + break; + case 't': + decoded += '\t'; + break; + case 'u': { + unsigned int unicode; + if (!decodeUnicodeCodePoint(token, current, end, unicode)) + return false; + decoded += codePointToUTF8(unicode); + } break; + default: + return addError("Bad escape sequence in string", token, current); + } + } else { + decoded += c; + } + } + return true; +} + +bool Reader::decodeUnicodeCodePoint(Token& token, + Location& current, + Location end, + unsigned int& unicode) { + + if (!decodeUnicodeEscapeSequence(token, current, end, unicode)) + return false; + if (unicode >= 0xD800 && unicode <= 0xDBFF) { + // surrogate pairs + if (end - current < 6) + return addError( + "additional six characters expected to parse unicode surrogate pair.", + token, + current); + unsigned int surrogatePair; + if (*(current++) == '\\' && *(current++) == 'u') { + if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) { + unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); + } else + return false; + } else + return addError("expecting another \\u token to begin the second half of " + "a unicode surrogate pair", + token, + current); + } + return true; +} + +bool Reader::decodeUnicodeEscapeSequence(Token& token, + Location& current, + Location end, + unsigned int& unicode) { + if (end - current < 4) + return addError( + "Bad unicode escape sequence in string: four digits expected.", + token, + current); + unicode = 0; + for (int index = 0; index < 4; ++index) { + Char c = *current++; + unicode *= 16; + if (c >= '0' && c <= '9') + unicode += c - '0'; + else if (c >= 'a' && c <= 'f') + unicode += c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + unicode += c - 'A' + 10; + else + return addError( + "Bad unicode escape sequence in string: hexadecimal digit expected.", + token, + current); + } + return true; +} + +bool +Reader::addError(const std::string& message, Token& token, Location extra) { + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = extra; + errors_.push_back(info); + return false; +} + +bool Reader::recoverFromError(TokenType skipUntilToken) { + int errorCount = int(errors_.size()); + Token skip; + for (;;) { + if (!readToken(skip)) + errors_.resize(errorCount); // discard errors caused by recovery + if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) + break; + } + errors_.resize(errorCount); + return false; +} + +bool Reader::addErrorAndRecover(const std::string& message, + Token& token, + TokenType skipUntilToken) { + addError(message, token); + return recoverFromError(skipUntilToken); +} + +Value& Reader::currentValue() { return *(nodes_.top()); } + +Reader::Char Reader::getNextChar() { + if (current_ == end_) + return 0; + return *current_++; +} + +void Reader::getLocationLineAndColumn(Location location, + int& line, + int& column) const { + Location current = begin_; + Location lastLineStart = current; + line = 0; + while (current < location && current != end_) { + Char c = *current++; + if (c == '\r') { + if (*current == '\n') + ++current; + lastLineStart = current; + ++line; + } else if (c == '\n') { + lastLineStart = current; + ++line; + } + } + // column & line start at 1 + column = int(location - lastLineStart) + 1; + ++line; +} + +std::string Reader::getLocationLineAndColumn(Location location) const { + int line, column; + getLocationLineAndColumn(location, line, column); + char buffer[18 + 16 + 16 + 1]; + snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); + return buffer; +} + +// Deprecated. Preserved for backward compatibility +std::string Reader::getFormatedErrorMessages() const { + return getFormattedErrorMessages(); +} + +std::string Reader::getFormattedErrorMessages() const { + std::string formattedMessage; + for (Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError) { + const ErrorInfo& error = *itError; + formattedMessage += + "* " + getLocationLineAndColumn(error.token_.start_) + "\n"; + formattedMessage += " " + error.message_ + "\n"; + if (error.extra_) + formattedMessage += + "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n"; + } + return formattedMessage; +} + +std::vector Reader::getStructuredErrors() const { + std::vector allErrors; + for (Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError) { + const ErrorInfo& error = *itError; + Reader::StructuredError structured; + structured.offset_start = error.token_.start_ - begin_; + structured.offset_limit = error.token_.end_ - begin_; + structured.message = error.message_; + allErrors.push_back(structured); + } + return allErrors; +} + +bool Reader::pushError(const Value& value, const std::string& message) { + size_t length = end_ - begin_; + if(value.getOffsetStart() > length + || value.getOffsetLimit() > length) + return false; + Token token; + token.type_ = tokenError; + token.start_ = begin_ + value.getOffsetStart(); + token.end_ = end_ + value.getOffsetLimit(); + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = 0; + errors_.push_back(info); + return true; +} + +bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) { + size_t length = end_ - begin_; + if(value.getOffsetStart() > length + || value.getOffsetLimit() > length + || extra.getOffsetLimit() > length) + return false; + Token token; + token.type_ = tokenError; + token.start_ = begin_ + value.getOffsetStart(); + token.end_ = begin_ + value.getOffsetLimit(); + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = begin_ + extra.getOffsetStart(); + errors_.push_back(info); + return true; +} + +bool Reader::good() const { + return !errors_.size(); +} + +// exact copy of Features +class OurFeatures { +public: + static OurFeatures all(); + bool allowComments_; + bool strictRoot_; + bool allowDroppedNullPlaceholders_; + bool allowNumericKeys_; + bool allowSingleQuotes_; + bool failIfExtra_; + bool rejectDupKeys_; + bool allowSpecialFloats_; + int stackLimit_; +}; // OurFeatures + +// exact copy of Implementation of class Features +// //////////////////////////////// + +OurFeatures OurFeatures::all() { return OurFeatures(); } + +// Implementation of class Reader +// //////////////////////////////// + +// exact copy of Reader, renamed to OurReader +class OurReader { +public: + typedef char Char; + typedef const Char* Location; + struct StructuredError { + size_t offset_start; + size_t offset_limit; + std::string message; + }; + + OurReader(OurFeatures const& features); + bool parse(const char* beginDoc, + const char* endDoc, + Value& root, + bool collectComments = true); + std::string getFormattedErrorMessages() const; + std::vector getStructuredErrors() const; + bool pushError(const Value& value, const std::string& message); + bool pushError(const Value& value, const std::string& message, const Value& extra); + bool good() const; + +private: + OurReader(OurReader const&); // no impl + void operator=(OurReader const&); // no impl + + enum TokenType { + tokenEndOfStream = 0, + tokenObjectBegin, + tokenObjectEnd, + tokenArrayBegin, + tokenArrayEnd, + tokenString, + tokenNumber, + tokenTrue, + tokenFalse, + tokenNull, + tokenNaN, + tokenPosInf, + tokenNegInf, + tokenArraySeparator, + tokenMemberSeparator, + tokenComment, + tokenError + }; + + class Token { + public: + TokenType type_; + Location start_; + Location end_; + }; + + class ErrorInfo { + public: + Token token_; + std::string message_; + Location extra_; + }; + + typedef std::deque Errors; + + bool readToken(Token& token); + void skipSpaces(); + bool match(Location pattern, int patternLength); + bool readComment(); + bool readCStyleComment(); + bool readCppStyleComment(); + bool readString(); + bool readStringSingleQuote(); + bool readNumber(bool checkInf); + bool readValue(); + bool readObject(Token& token); + bool readArray(Token& token); + bool decodeNumber(Token& token); + bool decodeNumber(Token& token, Value& decoded); + bool decodeString(Token& token); + bool decodeString(Token& token, std::string& decoded); + bool decodeDouble(Token& token); + bool decodeDouble(Token& token, Value& decoded); + bool decodeUnicodeCodePoint(Token& token, + Location& current, + Location end, + unsigned int& unicode); + bool decodeUnicodeEscapeSequence(Token& token, + Location& current, + Location end, + unsigned int& unicode); + bool addError(const std::string& message, Token& token, Location extra = 0); + bool recoverFromError(TokenType skipUntilToken); + bool addErrorAndRecover(const std::string& message, + Token& token, + TokenType skipUntilToken); + void skipUntilSpace(); + Value& currentValue(); + Char getNextChar(); + void + getLocationLineAndColumn(Location location, int& line, int& column) const; + std::string getLocationLineAndColumn(Location location) const; + void addComment(Location begin, Location end, CommentPlacement placement); + void skipCommentTokens(Token& token); + + typedef std::stack Nodes; + Nodes nodes_; + Errors errors_; + std::string document_; + Location begin_; + Location end_; + Location current_; + Location lastValueEnd_; + Value* lastValue_; + std::string commentsBefore_; + int stackDepth_; + + OurFeatures const features_; + bool collectComments_; +}; // OurReader + +// complete copy of Read impl, for OurReader + +OurReader::OurReader(OurFeatures const& features) + : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(), + lastValue_(), commentsBefore_(), + stackDepth_(0), + features_(features), collectComments_() { +} + +bool OurReader::parse(const char* beginDoc, + const char* endDoc, + Value& root, + bool collectComments) { + if (!features_.allowComments_) { + collectComments = false; + } + + begin_ = beginDoc; + end_ = endDoc; + collectComments_ = collectComments; + current_ = begin_; + lastValueEnd_ = 0; + lastValue_ = 0; + commentsBefore_ = ""; + errors_.clear(); + while (!nodes_.empty()) + nodes_.pop(); + nodes_.push(&root); + + stackDepth_ = 0; + bool successful = readValue(); + Token token; + skipCommentTokens(token); + if (features_.failIfExtra_) { + if (token.type_ != tokenError && token.type_ != tokenEndOfStream) { + addError("Extra non-whitespace after JSON value.", token); + return false; + } + } + if (collectComments_ && !commentsBefore_.empty()) + root.setComment(commentsBefore_, commentAfter); + if (features_.strictRoot_) { + if (!root.isArray() && !root.isObject()) { + // Set error location to start of doc, ideally should be first token found + // in doc + token.type_ = tokenError; + token.start_ = beginDoc; + token.end_ = endDoc; + addError( + "A valid JSON document must be either an array or an object value.", + token); + return false; + } + } + return successful; +} + +bool OurReader::readValue() { + if (stackDepth_ >= features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue()."); + ++stackDepth_; + Token token; + skipCommentTokens(token); + bool successful = true; + + if (collectComments_ && !commentsBefore_.empty()) { + currentValue().setComment(commentsBefore_, commentBefore); + commentsBefore_ = ""; + } + + switch (token.type_) { + case tokenObjectBegin: + successful = readObject(token); + currentValue().setOffsetLimit(current_ - begin_); + break; + case tokenArrayBegin: + successful = readArray(token); + currentValue().setOffsetLimit(current_ - begin_); + break; + case tokenNumber: + successful = decodeNumber(token); + break; + case tokenString: + successful = decodeString(token); + break; + case tokenTrue: + { + Value v(true); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenFalse: + { + Value v(false); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenNull: + { + Value v; + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenNaN: + { + Value v(std::numeric_limits::quiet_NaN()); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenPosInf: + { + Value v(std::numeric_limits::infinity()); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenNegInf: + { + Value v(-std::numeric_limits::infinity()); + currentValue().swapPayload(v); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + } + break; + case tokenArraySeparator: + case tokenObjectEnd: + case tokenArrayEnd: + if (features_.allowDroppedNullPlaceholders_) { + // "Un-read" the current token and mark the current value as a null + // token. + current_--; + Value v; + currentValue().swapPayload(v); + currentValue().setOffsetStart(current_ - begin_ - 1); + currentValue().setOffsetLimit(current_ - begin_); + break; + } // else, fall through ... + default: + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return addError("Syntax error: value, object or array expected.", token); + } + + if (collectComments_) { + lastValueEnd_ = current_; + lastValue_ = ¤tValue(); + } + + --stackDepth_; + return successful; +} + +void OurReader::skipCommentTokens(Token& token) { + if (features_.allowComments_) { + do { + readToken(token); + } while (token.type_ == tokenComment); + } else { + readToken(token); + } +} + +bool OurReader::readToken(Token& token) { + skipSpaces(); + token.start_ = current_; + Char c = getNextChar(); + bool ok = true; + switch (c) { + case '{': + token.type_ = tokenObjectBegin; + break; + case '}': + token.type_ = tokenObjectEnd; + break; + case '[': + token.type_ = tokenArrayBegin; + break; + case ']': + token.type_ = tokenArrayEnd; + break; + case '"': + token.type_ = tokenString; + ok = readString(); + break; + case '\'': + if (features_.allowSingleQuotes_) { + token.type_ = tokenString; + ok = readStringSingleQuote(); + break; + } // else continue + case '/': + token.type_ = tokenComment; + ok = readComment(); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + token.type_ = tokenNumber; + readNumber(false); + break; + case '-': + if (readNumber(true)) { + token.type_ = tokenNumber; + } else { + token.type_ = tokenNegInf; + ok = features_.allowSpecialFloats_ && match("nfinity", 7); + } + break; + case 't': + token.type_ = tokenTrue; + ok = match("rue", 3); + break; + case 'f': + token.type_ = tokenFalse; + ok = match("alse", 4); + break; + case 'n': + token.type_ = tokenNull; + ok = match("ull", 3); + break; + case 'N': + if (features_.allowSpecialFloats_) { + token.type_ = tokenNaN; + ok = match("aN", 2); + } else { + ok = false; + } + break; + case 'I': + if (features_.allowSpecialFloats_) { + token.type_ = tokenPosInf; + ok = match("nfinity", 7); + } else { + ok = false; + } + break; + case ',': + token.type_ = tokenArraySeparator; + break; + case ':': + token.type_ = tokenMemberSeparator; + break; + case 0: + token.type_ = tokenEndOfStream; + break; + default: + ok = false; + break; + } + if (!ok) + token.type_ = tokenError; + token.end_ = current_; + return true; +} + +void OurReader::skipSpaces() { + while (current_ != end_) { + Char c = *current_; + if (c == ' ' || c == '\t' || c == '\r' || c == '\n') + ++current_; + else + break; + } +} + +bool OurReader::match(Location pattern, int patternLength) { + if (end_ - current_ < patternLength) + return false; + int index = patternLength; + while (index--) + if (current_[index] != pattern[index]) + return false; + current_ += patternLength; + return true; +} + +bool OurReader::readComment() { + Location commentBegin = current_ - 1; + Char c = getNextChar(); + bool successful = false; + if (c == '*') + successful = readCStyleComment(); + else if (c == '/') + successful = readCppStyleComment(); + if (!successful) + return false; + + if (collectComments_) { + CommentPlacement placement = commentBefore; + if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) { + if (c != '*' || !containsNewLine(commentBegin, current_)) + placement = commentAfterOnSameLine; + } + + addComment(commentBegin, current_, placement); + } + return true; +} + +void +OurReader::addComment(Location begin, Location end, CommentPlacement placement) { + assert(collectComments_); + const std::string& normalized = normalizeEOL(begin, end); + if (placement == commentAfterOnSameLine) { + assert(lastValue_ != 0); + lastValue_->setComment(normalized, placement); + } else { + commentsBefore_ += normalized; + } +} + +bool OurReader::readCStyleComment() { + while (current_ != end_) { + Char c = getNextChar(); + if (c == '*' && *current_ == '/') + break; + } + return getNextChar() == '/'; +} + +bool OurReader::readCppStyleComment() { + while (current_ != end_) { + Char c = getNextChar(); + if (c == '\n') + break; + if (c == '\r') { + // Consume DOS EOL. It will be normalized in addComment. + if (current_ != end_ && *current_ == '\n') + getNextChar(); + // Break on Moc OS 9 EOL. + break; + } + } + return true; +} + +bool OurReader::readNumber(bool checkInf) { + const char *p = current_; + if (checkInf && p != end_ && *p == 'I') { + current_ = ++p; + return false; + } + char c = '0'; // stopgap for already consumed character + // integral part + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + // fractional part + if (c == '.') { + c = (current_ = p) < end_ ? *p++ : 0; + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + } + // exponential part + if (c == 'e' || c == 'E') { + c = (current_ = p) < end_ ? *p++ : 0; + if (c == '+' || c == '-') + c = (current_ = p) < end_ ? *p++ : 0; + while (c >= '0' && c <= '9') + c = (current_ = p) < end_ ? *p++ : 0; + } + return true; +} +bool OurReader::readString() { + Char c = 0; + while (current_ != end_) { + c = getNextChar(); + if (c == '\\') + getNextChar(); + else if (c == '"') + break; + } + return c == '"'; +} + + +bool OurReader::readStringSingleQuote() { + Char c = 0; + while (current_ != end_) { + c = getNextChar(); + if (c == '\\') + getNextChar(); + else if (c == '\'') + break; + } + return c == '\''; +} + +bool OurReader::readObject(Token& tokenStart) { + Token tokenName; + std::string name; + Value init(objectValue); + currentValue().swapPayload(init); + currentValue().setOffsetStart(tokenStart.start_ - begin_); + while (readToken(tokenName)) { + bool initialTokenOk = true; + while (tokenName.type_ == tokenComment && initialTokenOk) + initialTokenOk = readToken(tokenName); + if (!initialTokenOk) + break; + if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object + return true; + name = ""; + if (tokenName.type_ == tokenString) { + if (!decodeString(tokenName, name)) + return recoverFromError(tokenObjectEnd); + } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { + Value numberName; + if (!decodeNumber(tokenName, numberName)) + return recoverFromError(tokenObjectEnd); + name = numberName.asString(); + } else { + break; + } + + Token colon; + if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { + return addErrorAndRecover( + "Missing ':' after object member name", colon, tokenObjectEnd); + } + if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30"); + if (features_.rejectDupKeys_ && currentValue().isMember(name)) { + std::string msg = "Duplicate key: '" + name + "'"; + return addErrorAndRecover( + msg, tokenName, tokenObjectEnd); + } + Value& value = currentValue()[name]; + nodes_.push(&value); + bool ok = readValue(); + nodes_.pop(); + if (!ok) // error already set + return recoverFromError(tokenObjectEnd); + + Token comma; + if (!readToken(comma) || + (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && + comma.type_ != tokenComment)) { + return addErrorAndRecover( + "Missing ',' or '}' in object declaration", comma, tokenObjectEnd); + } + bool finalizeTokenOk = true; + while (comma.type_ == tokenComment && finalizeTokenOk) + finalizeTokenOk = readToken(comma); + if (comma.type_ == tokenObjectEnd) + return true; + } + return addErrorAndRecover( + "Missing '}' or object member name", tokenName, tokenObjectEnd); +} + +bool OurReader::readArray(Token& tokenStart) { + Value init(arrayValue); + currentValue().swapPayload(init); + currentValue().setOffsetStart(tokenStart.start_ - begin_); + skipSpaces(); + if (*current_ == ']') // empty array + { + Token endArray; + readToken(endArray); + return true; + } + int index = 0; + for (;;) { + Value& value = currentValue()[index++]; + nodes_.push(&value); + bool ok = readValue(); + nodes_.pop(); + if (!ok) // error already set + return recoverFromError(tokenArrayEnd); + + Token token; + // Accept Comment after last item in the array. + ok = readToken(token); + while (token.type_ == tokenComment && ok) { + ok = readToken(token); + } + bool badTokenType = + (token.type_ != tokenArraySeparator && token.type_ != tokenArrayEnd); + if (!ok || badTokenType) { + return addErrorAndRecover( + "Missing ',' or ']' in array declaration", token, tokenArrayEnd); + } + if (token.type_ == tokenArrayEnd) + break; + } + return true; +} + +bool OurReader::decodeNumber(Token& token) { + Value decoded; + if (!decodeNumber(token, decoded)) + return false; + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool OurReader::decodeNumber(Token& token, Value& decoded) { + // Attempts to parse the number as an integer. If the number is + // larger than the maximum supported value of an integer then + // we decode the number as a double. + Location current = token.start_; + bool isNegative = *current == '-'; + if (isNegative) + ++current; + // TODO: Help the compiler do the div and mod at compile time or get rid of them. + Value::LargestUInt maxIntegerValue = + isNegative ? Value::LargestUInt(-Value::minLargestInt) + : Value::maxLargestUInt; + Value::LargestUInt threshold = maxIntegerValue / 10; + Value::LargestUInt value = 0; + while (current < token.end_) { + Char c = *current++; + if (c < '0' || c > '9') + return decodeDouble(token, decoded); + Value::UInt digit(c - '0'); + if (value >= threshold) { + // We've hit or exceeded the max value divided by 10 (rounded down). If + // a) we've only just touched the limit, b) this is the last digit, and + // c) it's small enough to fit in that rounding delta, we're okay. + // Otherwise treat this number as a double to avoid overflow. + if (value > threshold || current != token.end_ || + digit > maxIntegerValue % 10) { + return decodeDouble(token, decoded); + } + } + value = value * 10 + digit; + } + if (isNegative) + decoded = -Value::LargestInt(value); + else if (value <= Value::LargestUInt(Value::maxInt)) + decoded = Value::LargestInt(value); + else + decoded = value; + return true; +} + +bool OurReader::decodeDouble(Token& token) { + Value decoded; + if (!decodeDouble(token, decoded)) + return false; + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool OurReader::decodeDouble(Token& token, Value& decoded) { + double value = 0; + const int bufferSize = 32; + int count; + int length = int(token.end_ - token.start_); + + // Sanity check to avoid buffer overflow exploits. + if (length < 0) { + return addError("Unable to parse token length", token); + } + + // Avoid using a string constant for the format control string given to + // sscanf, as this can cause hard to debug crashes on OS X. See here for more + // info: + // + // http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html + char format[] = "%lf"; + + if (length <= bufferSize) { + Char buffer[bufferSize + 1]; + memcpy(buffer, token.start_, length); + buffer[length] = 0; + count = sscanf(buffer, format, &value); + } else { + std::string buffer(token.start_, token.end_); + count = sscanf(buffer.c_str(), format, &value); + } + + if (count != 1) + return addError("'" + std::string(token.start_, token.end_) + + "' is not a number.", + token); + decoded = value; + return true; +} + +bool OurReader::decodeString(Token& token) { + std::string decoded_string; + if (!decodeString(token, decoded_string)) + return false; + Value decoded(decoded_string); + currentValue().swapPayload(decoded); + currentValue().setOffsetStart(token.start_ - begin_); + currentValue().setOffsetLimit(token.end_ - begin_); + return true; +} + +bool OurReader::decodeString(Token& token, std::string& decoded) { + decoded.reserve(token.end_ - token.start_ - 2); + Location current = token.start_ + 1; // skip '"' + Location end = token.end_ - 1; // do not include '"' + while (current != end) { + Char c = *current++; + if (c == '"') + break; + else if (c == '\\') { + if (current == end) + return addError("Empty escape sequence in string", token, current); + Char escape = *current++; + switch (escape) { + case '"': + decoded += '"'; + break; + case '/': + decoded += '/'; + break; + case '\\': + decoded += '\\'; + break; + case 'b': + decoded += '\b'; + break; + case 'f': + decoded += '\f'; + break; + case 'n': + decoded += '\n'; + break; + case 'r': + decoded += '\r'; + break; + case 't': + decoded += '\t'; + break; + case 'u': { + unsigned int unicode; + if (!decodeUnicodeCodePoint(token, current, end, unicode)) + return false; + decoded += codePointToUTF8(unicode); + } break; + default: + return addError("Bad escape sequence in string", token, current); + } + } else { + decoded += c; + } + } + return true; +} + +bool OurReader::decodeUnicodeCodePoint(Token& token, + Location& current, + Location end, + unsigned int& unicode) { + + if (!decodeUnicodeEscapeSequence(token, current, end, unicode)) + return false; + if (unicode >= 0xD800 && unicode <= 0xDBFF) { + // surrogate pairs + if (end - current < 6) + return addError( + "additional six characters expected to parse unicode surrogate pair.", + token, + current); + unsigned int surrogatePair; + if (*(current++) == '\\' && *(current++) == 'u') { + if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) { + unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); + } else + return false; + } else + return addError("expecting another \\u token to begin the second half of " + "a unicode surrogate pair", + token, + current); + } + return true; +} + +bool OurReader::decodeUnicodeEscapeSequence(Token& token, + Location& current, + Location end, + unsigned int& unicode) { + if (end - current < 4) + return addError( + "Bad unicode escape sequence in string: four digits expected.", + token, + current); + unicode = 0; + for (int index = 0; index < 4; ++index) { + Char c = *current++; + unicode *= 16; + if (c >= '0' && c <= '9') + unicode += c - '0'; + else if (c >= 'a' && c <= 'f') + unicode += c - 'a' + 10; + else if (c >= 'A' && c <= 'F') + unicode += c - 'A' + 10; + else + return addError( + "Bad unicode escape sequence in string: hexadecimal digit expected.", + token, + current); + } + return true; +} + +bool +OurReader::addError(const std::string& message, Token& token, Location extra) { + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = extra; + errors_.push_back(info); + return false; +} + +bool OurReader::recoverFromError(TokenType skipUntilToken) { + int errorCount = int(errors_.size()); + Token skip; + for (;;) { + if (!readToken(skip)) + errors_.resize(errorCount); // discard errors caused by recovery + if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream) + break; + } + errors_.resize(errorCount); + return false; +} + +bool OurReader::addErrorAndRecover(const std::string& message, + Token& token, + TokenType skipUntilToken) { + addError(message, token); + return recoverFromError(skipUntilToken); +} + +Value& OurReader::currentValue() { return *(nodes_.top()); } + +OurReader::Char OurReader::getNextChar() { + if (current_ == end_) + return 0; + return *current_++; +} + +void OurReader::getLocationLineAndColumn(Location location, + int& line, + int& column) const { + Location current = begin_; + Location lastLineStart = current; + line = 0; + while (current < location && current != end_) { + Char c = *current++; + if (c == '\r') { + if (*current == '\n') + ++current; + lastLineStart = current; + ++line; + } else if (c == '\n') { + lastLineStart = current; + ++line; + } + } + // column & line start at 1 + column = int(location - lastLineStart) + 1; + ++line; +} + +std::string OurReader::getLocationLineAndColumn(Location location) const { + int line, column; + getLocationLineAndColumn(location, line, column); + char buffer[18 + 16 + 16 + 1]; + snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); + return buffer; +} + +std::string OurReader::getFormattedErrorMessages() const { + std::string formattedMessage; + for (Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError) { + const ErrorInfo& error = *itError; + formattedMessage += + "* " + getLocationLineAndColumn(error.token_.start_) + "\n"; + formattedMessage += " " + error.message_ + "\n"; + if (error.extra_) + formattedMessage += + "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n"; + } + return formattedMessage; +} + +std::vector OurReader::getStructuredErrors() const { + std::vector allErrors; + for (Errors::const_iterator itError = errors_.begin(); + itError != errors_.end(); + ++itError) { + const ErrorInfo& error = *itError; + OurReader::StructuredError structured; + structured.offset_start = error.token_.start_ - begin_; + structured.offset_limit = error.token_.end_ - begin_; + structured.message = error.message_; + allErrors.push_back(structured); + } + return allErrors; +} + +bool OurReader::pushError(const Value& value, const std::string& message) { + size_t length = end_ - begin_; + if(value.getOffsetStart() > length + || value.getOffsetLimit() > length) + return false; + Token token; + token.type_ = tokenError; + token.start_ = begin_ + value.getOffsetStart(); + token.end_ = end_ + value.getOffsetLimit(); + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = 0; + errors_.push_back(info); + return true; +} + +bool OurReader::pushError(const Value& value, const std::string& message, const Value& extra) { + size_t length = end_ - begin_; + if(value.getOffsetStart() > length + || value.getOffsetLimit() > length + || extra.getOffsetLimit() > length) + return false; + Token token; + token.type_ = tokenError; + token.start_ = begin_ + value.getOffsetStart(); + token.end_ = begin_ + value.getOffsetLimit(); + ErrorInfo info; + info.token_ = token; + info.message_ = message; + info.extra_ = begin_ + extra.getOffsetStart(); + errors_.push_back(info); + return true; +} + +bool OurReader::good() const { + return !errors_.size(); +} + + +class OurCharReader : public CharReader { + bool const collectComments_; + OurReader reader_; +public: + OurCharReader( + bool collectComments, + OurFeatures const& features) + : collectComments_(collectComments) + , reader_(features) + {} + bool parse( + char const* beginDoc, char const* endDoc, + Value* root, std::string* errs) override { + bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_); + if (errs) { + *errs = reader_.getFormattedErrorMessages(); + } + return ok; + } +}; + +CharReaderBuilder::CharReaderBuilder() +{ + setDefaults(&settings_); +} +CharReaderBuilder::~CharReaderBuilder() +{} +CharReader* CharReaderBuilder::newCharReader() const +{ + bool collectComments = settings_["collectComments"].asBool(); + OurFeatures features = OurFeatures::all(); + features.allowComments_ = settings_["allowComments"].asBool(); + features.strictRoot_ = settings_["strictRoot"].asBool(); + features.allowDroppedNullPlaceholders_ = settings_["allowDroppedNullPlaceholders"].asBool(); + features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool(); + features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool(); + features.stackLimit_ = settings_["stackLimit"].asInt(); + features.failIfExtra_ = settings_["failIfExtra"].asBool(); + features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool(); + features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool(); + return new OurCharReader(collectComments, features); +} +static void getValidReaderKeys(std::set* valid_keys) +{ + valid_keys->clear(); + valid_keys->insert("collectComments"); + valid_keys->insert("allowComments"); + valid_keys->insert("strictRoot"); + valid_keys->insert("allowDroppedNullPlaceholders"); + valid_keys->insert("allowNumericKeys"); + valid_keys->insert("allowSingleQuotes"); + valid_keys->insert("stackLimit"); + valid_keys->insert("failIfExtra"); + valid_keys->insert("rejectDupKeys"); + valid_keys->insert("allowSpecialFloats"); +} +bool CharReaderBuilder::validate(Json::Value* invalid) const +{ + Json::Value my_invalid; + if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL + Json::Value& inv = *invalid; + std::set valid_keys; + getValidReaderKeys(&valid_keys); + Value::Members keys = settings_.getMemberNames(); + size_t n = keys.size(); + for (size_t i = 0; i < n; ++i) { + std::string const& key = keys[i]; + if (valid_keys.find(key) == valid_keys.end()) { + inv[key] = settings_[key]; + } + } + return 0u == inv.size(); +} +Value& CharReaderBuilder::operator[](std::string key) +{ + return settings_[key]; +} +// static +void CharReaderBuilder::strictMode(Json::Value* settings) +{ +//! [CharReaderBuilderStrictMode] + (*settings)["allowComments"] = false; + (*settings)["strictRoot"] = true; + (*settings)["allowDroppedNullPlaceholders"] = false; + (*settings)["allowNumericKeys"] = false; + (*settings)["allowSingleQuotes"] = false; + (*settings)["stackLimit"] = 1000; + (*settings)["failIfExtra"] = true; + (*settings)["rejectDupKeys"] = true; + (*settings)["allowSpecialFloats"] = false; +//! [CharReaderBuilderStrictMode] +} +// static +void CharReaderBuilder::setDefaults(Json::Value* settings) +{ +//! [CharReaderBuilderDefaults] + (*settings)["collectComments"] = true; + (*settings)["allowComments"] = true; + (*settings)["strictRoot"] = false; + (*settings)["allowDroppedNullPlaceholders"] = false; + (*settings)["allowNumericKeys"] = false; + (*settings)["allowSingleQuotes"] = false; + (*settings)["stackLimit"] = 1000; + (*settings)["failIfExtra"] = false; + (*settings)["rejectDupKeys"] = false; + (*settings)["allowSpecialFloats"] = false; +//! [CharReaderBuilderDefaults] +} + +////////////////////////////////// +// global functions + +bool parseFromStream( + CharReader::Factory const& fact, std::istream& sin, + Value* root, std::string* errs) +{ + std::ostringstream ssin; + ssin << sin.rdbuf(); + std::string doc = ssin.str(); + char const* begin = doc.data(); + char const* end = begin + doc.size(); + // Note that we do not actually need a null-terminator. + CharReaderPtr const reader(fact.newCharReader()); + return reader->parse(begin, end, root, errs); +} + +std::istream& operator>>(std::istream& sin, Value& root) { + CharReaderBuilder b; + std::string errs; + bool ok = parseFromStream(b, sin, &root, &errs); + if (!ok) { + fprintf(stderr, + "Error from reader: %s", + errs.c_str()); + + throwRuntimeError(errs); + } + return sin; +} + +} // namespace Json + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: src/lib_json/json_reader.cpp +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: src/lib_json/json_valueiterator.inl +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2007-2010 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +// included by json_value.cpp + +namespace Json { + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueIteratorBase +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueIteratorBase::ValueIteratorBase() + : current_(), isNull_(true) { +} + +ValueIteratorBase::ValueIteratorBase( + const Value::ObjectValues::iterator& current) + : current_(current), isNull_(false) {} + +Value& ValueIteratorBase::deref() const { + return current_->second; +} + +void ValueIteratorBase::increment() { + ++current_; +} + +void ValueIteratorBase::decrement() { + --current_; +} + +ValueIteratorBase::difference_type +ValueIteratorBase::computeDistance(const SelfType& other) const { +#ifdef JSON_USE_CPPTL_SMALLMAP + return other.current_ - current_; +#else + // Iterator for null value are initialized using the default + // constructor, which initialize current_ to the default + // std::map::iterator. As begin() and end() are two instance + // of the default std::map::iterator, they can not be compared. + // To allow this, we handle this comparison specifically. + if (isNull_ && other.isNull_) { + return 0; + } + + // Usage of std::distance is not portable (does not compile with Sun Studio 12 + // RogueWave STL, + // which is the one used by default). + // Using a portable hand-made version for non random iterator instead: + // return difference_type( std::distance( current_, other.current_ ) ); + difference_type myDistance = 0; + for (Value::ObjectValues::iterator it = current_; it != other.current_; + ++it) { + ++myDistance; + } + return myDistance; +#endif +} + +bool ValueIteratorBase::isEqual(const SelfType& other) const { + if (isNull_) { + return other.isNull_; + } + return current_ == other.current_; +} + +void ValueIteratorBase::copy(const SelfType& other) { + current_ = other.current_; + isNull_ = other.isNull_; +} + +Value ValueIteratorBase::key() const { + const Value::CZString czstring = (*current_).first; + if (czstring.data()) { + if (czstring.isStaticString()) + return Value(StaticString(czstring.data())); + return Value(czstring.data(), czstring.data() + czstring.length()); + } + return Value(czstring.index()); +} + +UInt ValueIteratorBase::index() const { + const Value::CZString czstring = (*current_).first; + if (!czstring.data()) + return czstring.index(); + return Value::UInt(-1); +} + +std::string ValueIteratorBase::name() const { + char const* keey; + char const* end; + keey = memberName(&end); + if (!keey) return std::string(); + return std::string(keey, end); +} + +char const* ValueIteratorBase::memberName() const { + const char* cname = (*current_).first.data(); + return cname ? cname : ""; +} + +char const* ValueIteratorBase::memberName(char const** end) const { + const char* cname = (*current_).first.data(); + if (!cname) { + *end = NULL; + return NULL; + } + *end = cname + (*current_).first.length(); + return cname; +} + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueConstIterator +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueConstIterator::ValueConstIterator() {} + +ValueConstIterator::ValueConstIterator( + const Value::ObjectValues::iterator& current) + : ValueIteratorBase(current) {} + +ValueConstIterator::ValueConstIterator(ValueIterator const& other) + : ValueIteratorBase(other) {} + +ValueConstIterator& ValueConstIterator:: +operator=(const ValueIteratorBase& other) { + copy(other); + return *this; +} + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class ValueIterator +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +ValueIterator::ValueIterator() {} + +ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current) + : ValueIteratorBase(current) {} + +ValueIterator::ValueIterator(const ValueConstIterator& other) + : ValueIteratorBase(other) { + throwRuntimeError("ConstIterator to Iterator should never be allowed."); +} + +ValueIterator::ValueIterator(const ValueIterator& other) + : ValueIteratorBase(other) {} + +ValueIterator& ValueIterator::operator=(const SelfType& other) { + copy(other); + return *this; +} + +} // namespace Json + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: src/lib_json/json_valueiterator.inl +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: src/lib_json/json_value.cpp +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2011 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#include +#include +#ifdef JSON_USE_CPPTL +#include +#endif +#include // size_t +#include // min() + +#define JSON_ASSERT_UNREACHABLE assert(false) + +namespace Json { + +// This is a walkaround to avoid the static initialization of Value::null. +// kNull must be word-aligned to avoid crashing on ARM. We use an alignment of +// 8 (instead of 4) as a bit of future-proofing. +#if defined(__ARMEL__) +#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) +#else +#define ALIGNAS(byte_alignment) +#endif +static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 }; +const unsigned char& kNullRef = kNull[0]; +const Value& Value::null = reinterpret_cast(kNullRef); +const Value& Value::nullRef = null; + +const Int Value::minInt = Int(~(UInt(-1) / 2)); +const Int Value::maxInt = Int(UInt(-1) / 2); +const UInt Value::maxUInt = UInt(-1); +#if defined(JSON_HAS_INT64) +const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2)); +const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2); +const UInt64 Value::maxUInt64 = UInt64(-1); +// The constant is hard-coded because some compiler have trouble +// converting Value::maxUInt64 to a double correctly (AIX/xlC). +// Assumes that UInt64 is a 64 bits integer. +static const double maxUInt64AsDouble = 18446744073709551615.0; +#endif // defined(JSON_HAS_INT64) +const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2)); +const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2); +const LargestUInt Value::maxLargestUInt = LargestUInt(-1); + +#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) +template +static inline bool InRange(double d, T min, U max) { + return d >= min && d <= max; +} +#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) +static inline double integerToDouble(Json::UInt64 value) { + return static_cast(Int64(value / 2)) * 2.0 + Int64(value & 1); +} + +template static inline double integerToDouble(T value) { + return static_cast(value); +} + +template +static inline bool InRange(double d, T min, U max) { + return d >= integerToDouble(min) && d <= integerToDouble(max); +} +#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + +/** Duplicates the specified string value. + * @param value Pointer to the string to duplicate. Must be zero-terminated if + * length is "unknown". + * @param length Length of the value. if equals to unknown, then it will be + * computed using strlen(value). + * @return Pointer on the duplicate instance of string. + */ +static inline char* duplicateStringValue(const char* value, + size_t length) { + // Avoid an integer overflow in the call to malloc below by limiting length + // to a sane value. + if (length >= (size_t)Value::maxInt) + length = Value::maxInt - 1; + + char* newString = static_cast(malloc(length + 1)); + if (newString == NULL) { + throwRuntimeError( + "in Json::Value::duplicateStringValue(): " + "Failed to allocate string value buffer"); + } + memcpy(newString, value, length); + newString[length] = 0; + return newString; +} + +/* Record the length as a prefix. + */ +static inline char* duplicateAndPrefixStringValue( + const char* value, + unsigned int length) +{ + // Avoid an integer overflow in the call to malloc below by limiting length + // to a sane value. + JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U, + "in Json::Value::duplicateAndPrefixStringValue(): " + "length too big for prefixing"); + unsigned actualLength = length + static_cast(sizeof(unsigned)) + 1U; + char* newString = static_cast(malloc(actualLength)); + if (newString == 0) { + throwRuntimeError( + "in Json::Value::duplicateAndPrefixStringValue(): " + "Failed to allocate string value buffer"); + } + *reinterpret_cast(newString) = length; + memcpy(newString + sizeof(unsigned), value, length); + newString[actualLength - 1U] = 0; // to avoid buffer over-run accidents by users later + return newString; +} +inline static void decodePrefixedString( + bool isPrefixed, char const* prefixed, + unsigned* length, char const** value) +{ + if (!isPrefixed) { + *length = static_cast(strlen(prefixed)); + *value = prefixed; + } else { + *length = *reinterpret_cast(prefixed); + *value = prefixed + sizeof(unsigned); + } +} +/** Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue(). + */ +static inline void releaseStringValue(char* value) { free(value); } + +} // namespace Json + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ValueInternals... +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +#if !defined(JSON_IS_AMALGAMATION) + +#include "json_valueiterator.inl" +#endif // if !defined(JSON_IS_AMALGAMATION) + +namespace Json { + +Exception::Exception(std::string const& msg) + : msg_(msg) +{} +Exception::~Exception() throw() +{} +char const* Exception::what() const throw() +{ + return msg_.c_str(); +} +RuntimeError::RuntimeError(std::string const& msg) + : Exception(msg) +{} +LogicError::LogicError(std::string const& msg) + : Exception(msg) +{} +void throwRuntimeError(std::string const& msg) +{ + throw RuntimeError(msg); +} +void throwLogicError(std::string const& msg) +{ + throw LogicError(msg); +} + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CommentInfo +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +Value::CommentInfo::CommentInfo() : comment_(0) {} + +Value::CommentInfo::~CommentInfo() { + if (comment_) + releaseStringValue(comment_); +} + +void Value::CommentInfo::setComment(const char* text, size_t len) { + if (comment_) { + releaseStringValue(comment_); + comment_ = 0; + } + JSON_ASSERT(text != 0); + JSON_ASSERT_MESSAGE( + text[0] == '\0' || text[0] == '/', + "in Json::Value::setComment(): Comments must start with /"); + // It seems that /**/ style comments are acceptable as well. + comment_ = duplicateStringValue(text, len); +} + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::CZString +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +// Notes: policy_ indicates if the string was allocated when +// a string is stored. + +Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {} + +Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate) + : cstr_(str) { + // allocate != duplicate + storage_.policy_ = allocate & 0x3; + storage_.length_ = ulength & 0x3FFFFFFF; +} + +Value::CZString::CZString(const CZString& other) + : cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0 + ? duplicateStringValue(other.cstr_, other.storage_.length_) + : other.cstr_) { + storage_.policy_ = (other.cstr_ + ? (static_cast(other.storage_.policy_) == noDuplication + ? noDuplication : duplicate) + : static_cast(other.storage_.policy_)); + storage_.length_ = other.storage_.length_; +} + +#if JSON_HAS_RVALUE_REFERENCES +Value::CZString::CZString(CZString&& other) + : cstr_(other.cstr_), index_(other.index_) { + other.cstr_ = nullptr; +} +#endif + +Value::CZString::~CZString() { + if (cstr_ && storage_.policy_ == duplicate) + releaseStringValue(const_cast(cstr_)); +} + +void Value::CZString::swap(CZString& other) { + std::swap(cstr_, other.cstr_); + std::swap(index_, other.index_); +} + +Value::CZString& Value::CZString::operator=(CZString other) { + swap(other); + return *this; +} + +bool Value::CZString::operator<(const CZString& other) const { + if (!cstr_) return index_ < other.index_; + //return strcmp(cstr_, other.cstr_) < 0; + // Assume both are strings. + unsigned this_len = this->storage_.length_; + unsigned other_len = other.storage_.length_; + unsigned min_len = std::min(this_len, other_len); + int comp = memcmp(this->cstr_, other.cstr_, min_len); + if (comp < 0) return true; + if (comp > 0) return false; + return (this_len < other_len); +} + +bool Value::CZString::operator==(const CZString& other) const { + if (!cstr_) return index_ == other.index_; + //return strcmp(cstr_, other.cstr_) == 0; + // Assume both are strings. + unsigned this_len = this->storage_.length_; + unsigned other_len = other.storage_.length_; + if (this_len != other_len) return false; + int comp = memcmp(this->cstr_, other.cstr_, this_len); + return comp == 0; +} + +ArrayIndex Value::CZString::index() const { return index_; } + +//const char* Value::CZString::c_str() const { return cstr_; } +const char* Value::CZString::data() const { return cstr_; } +unsigned Value::CZString::length() const { return storage_.length_; } +bool Value::CZString::isStaticString() const { return storage_.policy_ == noDuplication; } + +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// class Value::Value +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// +// ////////////////////////////////////////////////////////////////// + +/*! \internal Default constructor initialization must be equivalent to: + * memset( this, 0, sizeof(Value) ) + * This optimization is used in ValueInternalMap fast allocator. + */ +Value::Value(ValueType vtype) { + initBasic(vtype); + switch (vtype) { + case nullValue: + break; + case intValue: + case uintValue: + value_.int_ = 0; + break; + case realValue: + value_.real_ = 0.0; + break; + case stringValue: + value_.string_ = 0; + break; + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues(); + break; + case booleanValue: + value_.bool_ = false; + break; + default: + JSON_ASSERT_UNREACHABLE; + } +} + +Value::Value(Int value) { + initBasic(intValue); + value_.int_ = value; +} + +Value::Value(UInt value) { + initBasic(uintValue); + value_.uint_ = value; +} +#if defined(JSON_HAS_INT64) +Value::Value(Int64 value) { + initBasic(intValue); + value_.int_ = value; +} +Value::Value(UInt64 value) { + initBasic(uintValue); + value_.uint_ = value; +} +#endif // defined(JSON_HAS_INT64) + +Value::Value(double value) { + initBasic(realValue); + value_.real_ = value; +} + +Value::Value(const char* value) { + initBasic(stringValue, true); + value_.string_ = duplicateAndPrefixStringValue(value, static_cast(strlen(value))); +} + +Value::Value(const char* beginValue, const char* endValue) { + initBasic(stringValue, true); + value_.string_ = + duplicateAndPrefixStringValue(beginValue, static_cast(endValue - beginValue)); +} + +Value::Value(const std::string& value) { + initBasic(stringValue, true); + value_.string_ = + duplicateAndPrefixStringValue(value.data(), static_cast(value.length())); +} + +Value::Value(const StaticString& value) { + initBasic(stringValue); + value_.string_ = const_cast(value.c_str()); +} + +#ifdef JSON_USE_CPPTL +Value::Value(const CppTL::ConstString& value) { + initBasic(stringValue, true); + value_.string_ = duplicateAndPrefixStringValue(value, static_cast(value.length())); +} +#endif + +Value::Value(bool value) { + initBasic(booleanValue); + value_.bool_ = value; +} + +Value::Value(Value const& other) + : type_(other.type_), allocated_(false) + , + comments_(0), start_(other.start_), limit_(other.limit_) +{ + switch (type_) { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + value_ = other.value_; + break; + case stringValue: + if (other.value_.string_ && other.allocated_) { + unsigned len; + char const* str; + decodePrefixedString(other.allocated_, other.value_.string_, + &len, &str); + value_.string_ = duplicateAndPrefixStringValue(str, len); + allocated_ = true; + } else { + value_.string_ = other.value_.string_; + allocated_ = false; + } + break; + case arrayValue: + case objectValue: + value_.map_ = new ObjectValues(*other.value_.map_); + break; + default: + JSON_ASSERT_UNREACHABLE; + } + if (other.comments_) { + comments_ = new CommentInfo[numberOfCommentPlacement]; + for (int comment = 0; comment < numberOfCommentPlacement; ++comment) { + const CommentInfo& otherComment = other.comments_[comment]; + if (otherComment.comment_) + comments_[comment].setComment( + otherComment.comment_, strlen(otherComment.comment_)); + } + } +} + +#if JSON_HAS_RVALUE_REFERENCES +// Move constructor +Value::Value(Value&& other) { + initBasic(nullValue); + swap(other); +} +#endif + +Value::~Value() { + switch (type_) { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + break; + case stringValue: + if (allocated_) + releaseStringValue(value_.string_); + break; + case arrayValue: + case objectValue: + delete value_.map_; + break; + default: + JSON_ASSERT_UNREACHABLE; + } + + if (comments_) + delete[] comments_; +} + +Value& Value::operator=(Value other) { + swap(other); + return *this; +} + +void Value::swapPayload(Value& other) { + ValueType temp = type_; + type_ = other.type_; + other.type_ = temp; + std::swap(value_, other.value_); + int temp2 = allocated_; + allocated_ = other.allocated_; + other.allocated_ = temp2 & 0x1; +} + +void Value::swap(Value& other) { + swapPayload(other); + std::swap(comments_, other.comments_); + std::swap(start_, other.start_); + std::swap(limit_, other.limit_); +} + +ValueType Value::type() const { return type_; } + +int Value::compare(const Value& other) const { + if (*this < other) + return -1; + if (*this > other) + return 1; + return 0; +} + +bool Value::operator<(const Value& other) const { + int typeDelta = type_ - other.type_; + if (typeDelta) + return typeDelta < 0 ? true : false; + switch (type_) { + case nullValue: + return false; + case intValue: + return value_.int_ < other.value_.int_; + case uintValue: + return value_.uint_ < other.value_.uint_; + case realValue: + return value_.real_ < other.value_.real_; + case booleanValue: + return value_.bool_ < other.value_.bool_; + case stringValue: + { + if ((value_.string_ == 0) || (other.value_.string_ == 0)) { + if (other.value_.string_) return true; + else return false; + } + unsigned this_len; + unsigned other_len; + char const* this_str; + char const* other_str; + decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); + decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str); + unsigned min_len = std::min(this_len, other_len); + int comp = memcmp(this_str, other_str, min_len); + if (comp < 0) return true; + if (comp > 0) return false; + return (this_len < other_len); + } + case arrayValue: + case objectValue: { + int delta = int(value_.map_->size() - other.value_.map_->size()); + if (delta) + return delta < 0; + return (*value_.map_) < (*other.value_.map_); + } + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable +} + +bool Value::operator<=(const Value& other) const { return !(other < *this); } + +bool Value::operator>=(const Value& other) const { return !(*this < other); } + +bool Value::operator>(const Value& other) const { return other < *this; } + +bool Value::operator==(const Value& other) const { + // if ( type_ != other.type_ ) + // GCC 2.95.3 says: + // attempt to take address of bit-field structure member `Json::Value::type_' + // Beats me, but a temp solves the problem. + int temp = other.type_; + if (type_ != temp) + return false; + switch (type_) { + case nullValue: + return true; + case intValue: + return value_.int_ == other.value_.int_; + case uintValue: + return value_.uint_ == other.value_.uint_; + case realValue: + return value_.real_ == other.value_.real_; + case booleanValue: + return value_.bool_ == other.value_.bool_; + case stringValue: + { + if ((value_.string_ == 0) || (other.value_.string_ == 0)) { + return (value_.string_ == other.value_.string_); + } + unsigned this_len; + unsigned other_len; + char const* this_str; + char const* other_str; + decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); + decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str); + if (this_len != other_len) return false; + int comp = memcmp(this_str, other_str, this_len); + return comp == 0; + } + case arrayValue: + case objectValue: + return value_.map_->size() == other.value_.map_->size() && + (*value_.map_) == (*other.value_.map_); + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable +} + +bool Value::operator!=(const Value& other) const { return !(*this == other); } + +const char* Value::asCString() const { + JSON_ASSERT_MESSAGE(type_ == stringValue, + "in Json::Value::asCString(): requires stringValue"); + if (value_.string_ == 0) return 0; + unsigned this_len; + char const* this_str; + decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); + return this_str; +} + +bool Value::getString(char const** str, char const** cend) const { + if (type_ != stringValue) return false; + if (value_.string_ == 0) return false; + unsigned length; + decodePrefixedString(this->allocated_, this->value_.string_, &length, str); + *cend = *str + length; + return true; +} + +std::string Value::asString() const { + switch (type_) { + case nullValue: + return ""; + case stringValue: + { + if (value_.string_ == 0) return ""; + unsigned this_len; + char const* this_str; + decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str); + return std::string(this_str, this_len); + } + case booleanValue: + return value_.bool_ ? "true" : "false"; + case intValue: + return valueToString(value_.int_); + case uintValue: + return valueToString(value_.uint_); + case realValue: + return valueToString(value_.real_); + default: + JSON_FAIL_MESSAGE("Type is not convertible to string"); + } +} + +#ifdef JSON_USE_CPPTL +CppTL::ConstString Value::asConstString() const { + unsigned len; + char const* str; + decodePrefixedString(allocated_, value_.string_, + &len, &str); + return CppTL::ConstString(str, len); +} +#endif + +Value::Int Value::asInt() const { + switch (type_) { + case intValue: + JSON_ASSERT_MESSAGE(isInt(), "LargestInt out of Int range"); + return Int(value_.int_); + case uintValue: + JSON_ASSERT_MESSAGE(isInt(), "LargestUInt out of Int range"); + return Int(value_.uint_); + case realValue: + JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt, maxInt), + "double out of Int range"); + return Int(value_.real_); + case nullValue: + return 0; + case booleanValue: + return value_.bool_ ? 1 : 0; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to Int."); +} + +Value::UInt Value::asUInt() const { + switch (type_) { + case intValue: + JSON_ASSERT_MESSAGE(isUInt(), "LargestInt out of UInt range"); + return UInt(value_.int_); + case uintValue: + JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range"); + return UInt(value_.uint_); + case realValue: + JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt), + "double out of UInt range"); + return UInt(value_.real_); + case nullValue: + return 0; + case booleanValue: + return value_.bool_ ? 1 : 0; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to UInt."); +} + +#if defined(JSON_HAS_INT64) + +Value::Int64 Value::asInt64() const { + switch (type_) { + case intValue: + return Int64(value_.int_); + case uintValue: + JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range"); + return Int64(value_.uint_); + case realValue: + JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64), + "double out of Int64 range"); + return Int64(value_.real_); + case nullValue: + return 0; + case booleanValue: + return value_.bool_ ? 1 : 0; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to Int64."); +} + +Value::UInt64 Value::asUInt64() const { + switch (type_) { + case intValue: + JSON_ASSERT_MESSAGE(isUInt64(), "LargestInt out of UInt64 range"); + return UInt64(value_.int_); + case uintValue: + return UInt64(value_.uint_); + case realValue: + JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt64), + "double out of UInt64 range"); + return UInt64(value_.real_); + case nullValue: + return 0; + case booleanValue: + return value_.bool_ ? 1 : 0; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to UInt64."); +} +#endif // if defined(JSON_HAS_INT64) + +LargestInt Value::asLargestInt() const { +#if defined(JSON_NO_INT64) + return asInt(); +#else + return asInt64(); +#endif +} + +LargestUInt Value::asLargestUInt() const { +#if defined(JSON_NO_INT64) + return asUInt(); +#else + return asUInt64(); +#endif +} + +double Value::asDouble() const { + switch (type_) { + case intValue: + return static_cast(value_.int_); + case uintValue: +#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + return static_cast(value_.uint_); +#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + return integerToDouble(value_.uint_); +#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + case realValue: + return value_.real_; + case nullValue: + return 0.0; + case booleanValue: + return value_.bool_ ? 1.0 : 0.0; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to double."); +} + +float Value::asFloat() const { + switch (type_) { + case intValue: + return static_cast(value_.int_); + case uintValue: +#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + return static_cast(value_.uint_); +#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + return integerToDouble(value_.uint_); +#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) + case realValue: + return static_cast(value_.real_); + case nullValue: + return 0.0; + case booleanValue: + return value_.bool_ ? 1.0f : 0.0f; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to float."); +} + +bool Value::asBool() const { + switch (type_) { + case booleanValue: + return value_.bool_; + case nullValue: + return false; + case intValue: + return value_.int_ ? true : false; + case uintValue: + return value_.uint_ ? true : false; + case realValue: + // This is kind of strange. Not recommended. + return (value_.real_ != 0.0) ? true : false; + default: + break; + } + JSON_FAIL_MESSAGE("Value is not convertible to bool."); +} + +bool Value::isConvertibleTo(ValueType other) const { + switch (other) { + case nullValue: + return (isNumeric() && asDouble() == 0.0) || + (type_ == booleanValue && value_.bool_ == false) || + (type_ == stringValue && asString() == "") || + (type_ == arrayValue && value_.map_->size() == 0) || + (type_ == objectValue && value_.map_->size() == 0) || + type_ == nullValue; + case intValue: + return isInt() || + (type_ == realValue && InRange(value_.real_, minInt, maxInt)) || + type_ == booleanValue || type_ == nullValue; + case uintValue: + return isUInt() || + (type_ == realValue && InRange(value_.real_, 0, maxUInt)) || + type_ == booleanValue || type_ == nullValue; + case realValue: + return isNumeric() || type_ == booleanValue || type_ == nullValue; + case booleanValue: + return isNumeric() || type_ == booleanValue || type_ == nullValue; + case stringValue: + return isNumeric() || type_ == booleanValue || type_ == stringValue || + type_ == nullValue; + case arrayValue: + return type_ == arrayValue || type_ == nullValue; + case objectValue: + return type_ == objectValue || type_ == nullValue; + } + JSON_ASSERT_UNREACHABLE; + return false; +} + +/// Number of values in array or object +ArrayIndex Value::size() const { + switch (type_) { + case nullValue: + case intValue: + case uintValue: + case realValue: + case booleanValue: + case stringValue: + return 0; + case arrayValue: // size of the array is highest index + 1 + if (!value_.map_->empty()) { + ObjectValues::const_iterator itLast = value_.map_->end(); + --itLast; + return (*itLast).first.index() + 1; + } + return 0; + case objectValue: + return ArrayIndex(value_.map_->size()); + } + JSON_ASSERT_UNREACHABLE; + return 0; // unreachable; +} + +bool Value::empty() const { + if (isNull() || isArray() || isObject()) + return size() == 0u; + else + return false; +} + +bool Value::operator!() const { return isNull(); } + +void Value::clear() { + JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue || + type_ == objectValue, + "in Json::Value::clear(): requires complex value"); + start_ = 0; + limit_ = 0; + switch (type_) { + case arrayValue: + case objectValue: + value_.map_->clear(); + break; + default: + break; + } +} + +void Value::resize(ArrayIndex newSize) { + JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue, + "in Json::Value::resize(): requires arrayValue"); + if (type_ == nullValue) + *this = Value(arrayValue); + ArrayIndex oldSize = size(); + if (newSize == 0) + clear(); + else if (newSize > oldSize) + (*this)[newSize - 1]; + else { + for (ArrayIndex index = newSize; index < oldSize; ++index) { + value_.map_->erase(index); + } + assert(size() == newSize); + } +} + +Value& Value::operator[](ArrayIndex index) { + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == arrayValue, + "in Json::Value::operator[](ArrayIndex): requires arrayValue"); + if (type_ == nullValue) + *this = Value(arrayValue); + CZString key(index); + ObjectValues::iterator it = value_.map_->lower_bound(key); + if (it != value_.map_->end() && (*it).first == key) + return (*it).second; + + ObjectValues::value_type defaultValue(key, nullRef); + it = value_.map_->insert(it, defaultValue); + return (*it).second; +} + +Value& Value::operator[](int index) { + JSON_ASSERT_MESSAGE( + index >= 0, + "in Json::Value::operator[](int index): index cannot be negative"); + return (*this)[ArrayIndex(index)]; +} + +const Value& Value::operator[](ArrayIndex index) const { + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == arrayValue, + "in Json::Value::operator[](ArrayIndex)const: requires arrayValue"); + if (type_ == nullValue) + return nullRef; + CZString key(index); + ObjectValues::const_iterator it = value_.map_->find(key); + if (it == value_.map_->end()) + return nullRef; + return (*it).second; +} + +const Value& Value::operator[](int index) const { + JSON_ASSERT_MESSAGE( + index >= 0, + "in Json::Value::operator[](int index) const: index cannot be negative"); + return (*this)[ArrayIndex(index)]; +} + +void Value::initBasic(ValueType vtype, bool allocated) { + type_ = vtype; + allocated_ = allocated; + comments_ = 0; + start_ = 0; + limit_ = 0; +} + +// Access an object value by name, create a null member if it does not exist. +// @pre Type of '*this' is object or null. +// @param key is null-terminated. +Value& Value::resolveReference(const char* key) { + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == objectValue, + "in Json::Value::resolveReference(): requires objectValue"); + if (type_ == nullValue) + *this = Value(objectValue); + CZString actualKey( + key, static_cast(strlen(key)), CZString::noDuplication); // NOTE! + ObjectValues::iterator it = value_.map_->lower_bound(actualKey); + if (it != value_.map_->end() && (*it).first == actualKey) + return (*it).second; + + ObjectValues::value_type defaultValue(actualKey, nullRef); + it = value_.map_->insert(it, defaultValue); + Value& value = (*it).second; + return value; +} + +// @param key is not null-terminated. +Value& Value::resolveReference(char const* key, char const* cend) +{ + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == objectValue, + "in Json::Value::resolveReference(key, end): requires objectValue"); + if (type_ == nullValue) + *this = Value(objectValue); + CZString actualKey( + key, static_cast(cend-key), CZString::duplicateOnCopy); + ObjectValues::iterator it = value_.map_->lower_bound(actualKey); + if (it != value_.map_->end() && (*it).first == actualKey) + return (*it).second; + + ObjectValues::value_type defaultValue(actualKey, nullRef); + it = value_.map_->insert(it, defaultValue); + Value& value = (*it).second; + return value; +} + +Value Value::get(ArrayIndex index, const Value& defaultValue) const { + const Value* value = &((*this)[index]); + return value == &nullRef ? defaultValue : *value; +} + +bool Value::isValidIndex(ArrayIndex index) const { return index < size(); } + +Value const* Value::find(char const* key, char const* cend) const +{ + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == objectValue, + "in Json::Value::find(key, end, found): requires objectValue or nullValue"); + if (type_ == nullValue) return NULL; + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); + ObjectValues::const_iterator it = value_.map_->find(actualKey); + if (it == value_.map_->end()) return NULL; + return &(*it).second; +} +const Value& Value::operator[](const char* key) const +{ + Value const* found = find(key, key + strlen(key)); + if (!found) return nullRef; + return *found; +} +Value const& Value::operator[](std::string const& key) const +{ + Value const* found = find(key.data(), key.data() + key.length()); + if (!found) return nullRef; + return *found; +} + +Value& Value::operator[](const char* key) { + return resolveReference(key, key + strlen(key)); +} + +Value& Value::operator[](const std::string& key) { + return resolveReference(key.data(), key.data() + key.length()); +} + +Value& Value::operator[](const StaticString& key) { + return resolveReference(key.c_str()); +} + +#ifdef JSON_USE_CPPTL +Value& Value::operator[](const CppTL::ConstString& key) { + return resolveReference(key.c_str(), key.end_c_str()); +} +Value const& Value::operator[](CppTL::ConstString const& key) const +{ + Value const* found = find(key.c_str(), key.end_c_str()); + if (!found) return nullRef; + return *found; +} +#endif + +Value& Value::append(const Value& value) { return (*this)[size()] = value; } + +Value Value::get(char const* key, char const* cend, Value const& defaultValue) const +{ + Value const* found = find(key, cend); + return !found ? defaultValue : *found; +} +Value Value::get(char const* key, Value const& defaultValue) const +{ + return get(key, key + strlen(key), defaultValue); +} +Value Value::get(std::string const& key, Value const& defaultValue) const +{ + return get(key.data(), key.data() + key.length(), defaultValue); +} + + +bool Value::removeMember(const char* key, const char* cend, Value* removed) +{ + if (type_ != objectValue) { + return false; + } + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); + ObjectValues::iterator it = value_.map_->find(actualKey); + if (it == value_.map_->end()) + return false; + *removed = it->second; + value_.map_->erase(it); + return true; +} +bool Value::removeMember(const char* key, Value* removed) +{ + return removeMember(key, key + strlen(key), removed); +} +bool Value::removeMember(std::string const& key, Value* removed) +{ + return removeMember(key.data(), key.data() + key.length(), removed); +} +Value Value::removeMember(const char* key) +{ + JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue, + "in Json::Value::removeMember(): requires objectValue"); + if (type_ == nullValue) + return nullRef; + + Value removed; // null + removeMember(key, key + strlen(key), &removed); + return removed; // still null if removeMember() did nothing +} +Value Value::removeMember(const std::string& key) +{ + return removeMember(key.c_str()); +} + +bool Value::removeIndex(ArrayIndex index, Value* removed) { + if (type_ != arrayValue) { + return false; + } + CZString key(index); + ObjectValues::iterator it = value_.map_->find(key); + if (it == value_.map_->end()) { + return false; + } + *removed = it->second; + ArrayIndex oldSize = size(); + // shift left all items left, into the place of the "removed" + for (ArrayIndex i = index; i < (oldSize - 1); ++i){ + CZString keey(i); + (*value_.map_)[keey] = (*this)[i + 1]; + } + // erase the last one ("leftover") + CZString keyLast(oldSize - 1); + ObjectValues::iterator itLast = value_.map_->find(keyLast); + value_.map_->erase(itLast); + return true; +} + +#ifdef JSON_USE_CPPTL +Value Value::get(const CppTL::ConstString& key, + const Value& defaultValue) const { + return get(key.c_str(), key.end_c_str(), defaultValue); +} +#endif + +bool Value::isMember(char const* key, char const* cend) const +{ + Value const* value = find(key, cend); + return NULL != value; +} +bool Value::isMember(char const* key) const +{ + return isMember(key, key + strlen(key)); +} +bool Value::isMember(std::string const& key) const +{ + return isMember(key.data(), key.data() + key.length()); +} + +#ifdef JSON_USE_CPPTL +bool Value::isMember(const CppTL::ConstString& key) const { + return isMember(key.c_str(), key.end_c_str()); +} +#endif + +Value::Members Value::getMemberNames() const { + JSON_ASSERT_MESSAGE( + type_ == nullValue || type_ == objectValue, + "in Json::Value::getMemberNames(), value must be objectValue"); + if (type_ == nullValue) + return Value::Members(); + Members members; + members.reserve(value_.map_->size()); + ObjectValues::const_iterator it = value_.map_->begin(); + ObjectValues::const_iterator itEnd = value_.map_->end(); + for (; it != itEnd; ++it) { + members.push_back(std::string((*it).first.data(), + (*it).first.length())); + } + return members; +} +// +//# ifdef JSON_USE_CPPTL +// EnumMemberNames +// Value::enumMemberNames() const +//{ +// if ( type_ == objectValue ) +// { +// return CppTL::Enum::any( CppTL::Enum::transform( +// CppTL::Enum::keys( *(value_.map_), CppTL::Type() ), +// MemberNamesTransform() ) ); +// } +// return EnumMemberNames(); +//} +// +// +// EnumValues +// Value::enumValues() const +//{ +// if ( type_ == objectValue || type_ == arrayValue ) +// return CppTL::Enum::anyValues( *(value_.map_), +// CppTL::Type() ); +// return EnumValues(); +//} +// +//# endif + +static bool IsIntegral(double d) { + double integral_part; + return modf(d, &integral_part) == 0.0; +} + +bool Value::isNull() const { return type_ == nullValue; } + +bool Value::isBool() const { return type_ == booleanValue; } + +bool Value::isInt() const { + switch (type_) { + case intValue: + return value_.int_ >= minInt && value_.int_ <= maxInt; + case uintValue: + return value_.uint_ <= UInt(maxInt); + case realValue: + return value_.real_ >= minInt && value_.real_ <= maxInt && + IsIntegral(value_.real_); + default: + break; + } + return false; +} + +bool Value::isUInt() const { + switch (type_) { + case intValue: + return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); + case uintValue: + return value_.uint_ <= maxUInt; + case realValue: + return value_.real_ >= 0 && value_.real_ <= maxUInt && + IsIntegral(value_.real_); + default: + break; + } + return false; +} + +bool Value::isInt64() const { +#if defined(JSON_HAS_INT64) + switch (type_) { + case intValue: + return true; + case uintValue: + return value_.uint_ <= UInt64(maxInt64); + case realValue: + // Note that maxInt64 (= 2^63 - 1) is not exactly representable as a + // double, so double(maxInt64) will be rounded up to 2^63. Therefore we + // require the value to be strictly less than the limit. + return value_.real_ >= double(minInt64) && + value_.real_ < double(maxInt64) && IsIntegral(value_.real_); + default: + break; + } +#endif // JSON_HAS_INT64 + return false; +} + +bool Value::isUInt64() const { +#if defined(JSON_HAS_INT64) + switch (type_) { + case intValue: + return value_.int_ >= 0; + case uintValue: + return true; + case realValue: + // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a + // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we + // require the value to be strictly less than the limit. + return value_.real_ >= 0 && value_.real_ < maxUInt64AsDouble && + IsIntegral(value_.real_); + default: + break; + } +#endif // JSON_HAS_INT64 + return false; +} + +bool Value::isIntegral() const { +#if defined(JSON_HAS_INT64) + return isInt64() || isUInt64(); +#else + return isInt() || isUInt(); +#endif +} + +bool Value::isDouble() const { return type_ == realValue || isIntegral(); } + +bool Value::isNumeric() const { return isIntegral() || isDouble(); } + +bool Value::isString() const { return type_ == stringValue; } + +bool Value::isArray() const { return type_ == arrayValue; } + +bool Value::isObject() const { return type_ == objectValue; } + +void Value::setComment(const char* comment, size_t len, CommentPlacement placement) { + if (!comments_) + comments_ = new CommentInfo[numberOfCommentPlacement]; + if ((len > 0) && (comment[len-1] == '\n')) { + // Always discard trailing newline, to aid indentation. + len -= 1; + } + comments_[placement].setComment(comment, len); +} + +void Value::setComment(const char* comment, CommentPlacement placement) { + setComment(comment, strlen(comment), placement); +} + +void Value::setComment(const std::string& comment, CommentPlacement placement) { + setComment(comment.c_str(), comment.length(), placement); +} + +bool Value::hasComment(CommentPlacement placement) const { + return comments_ != 0 && comments_[placement].comment_ != 0; +} + +std::string Value::getComment(CommentPlacement placement) const { + if (hasComment(placement)) + return comments_[placement].comment_; + return ""; +} + +void Value::setOffsetStart(size_t start) { start_ = start; } + +void Value::setOffsetLimit(size_t limit) { limit_ = limit; } + +size_t Value::getOffsetStart() const { return start_; } + +size_t Value::getOffsetLimit() const { return limit_; } + +std::string Value::toStyledString() const { + StyledWriter writer; + return writer.write(*this); +} + +Value::const_iterator Value::begin() const { + switch (type_) { + case arrayValue: + case objectValue: + if (value_.map_) + return const_iterator(value_.map_->begin()); + break; + default: + break; + } + return const_iterator(); +} + +Value::const_iterator Value::end() const { + switch (type_) { + case arrayValue: + case objectValue: + if (value_.map_) + return const_iterator(value_.map_->end()); + break; + default: + break; + } + return const_iterator(); +} + +Value::iterator Value::begin() { + switch (type_) { + case arrayValue: + case objectValue: + if (value_.map_) + return iterator(value_.map_->begin()); + break; + default: + break; + } + return iterator(); +} + +Value::iterator Value::end() { + switch (type_) { + case arrayValue: + case objectValue: + if (value_.map_) + return iterator(value_.map_->end()); + break; + default: + break; + } + return iterator(); +} + +// class PathArgument +// ////////////////////////////////////////////////////////////////// + +PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {} + +PathArgument::PathArgument(ArrayIndex index) + : key_(), index_(index), kind_(kindIndex) {} + +PathArgument::PathArgument(const char* key) + : key_(key), index_(), kind_(kindKey) {} + +PathArgument::PathArgument(const std::string& key) + : key_(key.c_str()), index_(), kind_(kindKey) {} + +// class Path +// ////////////////////////////////////////////////////////////////// + +Path::Path(const std::string& path, + const PathArgument& a1, + const PathArgument& a2, + const PathArgument& a3, + const PathArgument& a4, + const PathArgument& a5) { + InArgs in; + in.push_back(&a1); + in.push_back(&a2); + in.push_back(&a3); + in.push_back(&a4); + in.push_back(&a5); + makePath(path, in); +} + +void Path::makePath(const std::string& path, const InArgs& in) { + const char* current = path.c_str(); + const char* end = current + path.length(); + InArgs::const_iterator itInArg = in.begin(); + while (current != end) { + if (*current == '[') { + ++current; + if (*current == '%') + addPathInArg(path, in, itInArg, PathArgument::kindIndex); + else { + ArrayIndex index = 0; + for (; current != end && *current >= '0' && *current <= '9'; ++current) + index = index * 10 + ArrayIndex(*current - '0'); + args_.push_back(index); + } + if (current == end || *current++ != ']') + invalidPath(path, int(current - path.c_str())); + } else if (*current == '%') { + addPathInArg(path, in, itInArg, PathArgument::kindKey); + ++current; + } else if (*current == '.') { + ++current; + } else { + const char* beginName = current; + while (current != end && !strchr("[.", *current)) + ++current; + args_.push_back(std::string(beginName, current)); + } + } +} + +void Path::addPathInArg(const std::string& /*path*/, + const InArgs& in, + InArgs::const_iterator& itInArg, + PathArgument::Kind kind) { + if (itInArg == in.end()) { + // Error: missing argument %d + } else if ((*itInArg)->kind_ != kind) { + // Error: bad argument type + } else { + args_.push_back(**itInArg); + } +} + +void Path::invalidPath(const std::string& /*path*/, int /*location*/) { + // Error: invalid path. +} + +const Value& Path::resolve(const Value& root) const { + const Value* node = &root; + for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) { + const PathArgument& arg = *it; + if (arg.kind_ == PathArgument::kindIndex) { + if (!node->isArray() || !node->isValidIndex(arg.index_)) { + // Error: unable to resolve path (array value expected at position... + } + node = &((*node)[arg.index_]); + } else if (arg.kind_ == PathArgument::kindKey) { + if (!node->isObject()) { + // Error: unable to resolve path (object value expected at position...) + } + node = &((*node)[arg.key_]); + if (node == &Value::nullRef) { + // Error: unable to resolve path (object has no member named '' at + // position...) + } + } + } + return *node; +} + +Value Path::resolve(const Value& root, const Value& defaultValue) const { + const Value* node = &root; + for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) { + const PathArgument& arg = *it; + if (arg.kind_ == PathArgument::kindIndex) { + if (!node->isArray() || !node->isValidIndex(arg.index_)) + return defaultValue; + node = &((*node)[arg.index_]); + } else if (arg.kind_ == PathArgument::kindKey) { + if (!node->isObject()) + return defaultValue; + node = &((*node)[arg.key_]); + if (node == &Value::nullRef) + return defaultValue; + } + } + return *node; +} + +Value& Path::make(Value& root) const { + Value* node = &root; + for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) { + const PathArgument& arg = *it; + if (arg.kind_ == PathArgument::kindIndex) { + if (!node->isArray()) { + // Error: node is not an array at position ... + } + node = &((*node)[arg.index_]); + } else if (arg.kind_ == PathArgument::kindKey) { + if (!node->isObject()) { + // Error: node is not an object at position... + } + node = &((*node)[arg.key_]); + } + } + return *node; +} + +} // namespace Json + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: src/lib_json/json_value.cpp +// ////////////////////////////////////////////////////////////////////// + + + + + + +// ////////////////////////////////////////////////////////////////////// +// Beginning of content of file: src/lib_json/json_writer.cpp +// ////////////////////////////////////////////////////////////////////// + +// Copyright 2011 Baptiste Lepilleur +// Distributed under MIT license, or public domain if desired and +// recognized in your jurisdiction. +// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE + +#if !defined(JSON_IS_AMALGAMATION) +#include +#include "json_tool.h" +#endif // if !defined(JSON_IS_AMALGAMATION) +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1800 // Between VC++ 6.0 and VC++ 11.0 +#include +#define isfinite _finite +#elif defined(__sun) && defined(__SVR4) //Solaris +#if !defined(isfinite) +#include +#define isfinite finite +#endif +#elif defined(_AIX) +#if !defined(isfinite) +#include +#define isfinite finite +#endif +#elif defined(__hpux) +#if !defined(isfinite) +#if defined(__ia64) && !defined(finite) +#define isfinite(x) ((sizeof(x) == sizeof(float) ? \ + _Isfinitef(x) : _IsFinite(x))) +#else +#include +#define isfinite finite +#endif +#endif +#else +#include +#if !(defined(__QNXNTO__)) // QNX already defines isfinite +#define isfinite std::isfinite +#endif +#endif + +#if defined(_MSC_VER) +#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above +#define snprintf sprintf_s +#elif _MSC_VER >= 1900 // VC++ 14.0 and above +#define snprintf std::snprintf +#else +#define snprintf _snprintf +#endif +#elif defined(__ANDROID__) || defined(__QNXNTO__) +#define snprintf snprintf +#elif __cplusplus >= 201103L +#define snprintf std::snprintf +#endif + +#if defined(__BORLANDC__) +#include +#define isfinite _finite +#define snprintf _snprintf +#endif + +#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0 +// Disable warning about strdup being deprecated. +#pragma warning(disable : 4996) +#endif + +namespace Json { + +#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) +typedef std::unique_ptr StreamWriterPtr; +#else +typedef std::auto_ptr StreamWriterPtr; +#endif + +static bool containsControlCharacter(const char* str) { + while (*str) { + if (isControlCharacter(*(str++))) + return true; + } + return false; +} + +static bool containsControlCharacter0(const char* str, unsigned len) { + char const* end = str + len; + while (end != str) { + if (isControlCharacter(*str) || 0==*str) + return true; + ++str; + } + return false; +} + +std::string valueToString(LargestInt value) { + UIntToStringBuffer buffer; + char* current = buffer + sizeof(buffer); + if (value == Value::minLargestInt) { + uintToString(LargestUInt(Value::maxLargestInt) + 1, current); + *--current = '-'; + } else if (value < 0) { + uintToString(LargestUInt(-value), current); + *--current = '-'; + } else { + uintToString(LargestUInt(value), current); + } + assert(current >= buffer); + return current; +} + +std::string valueToString(LargestUInt value) { + UIntToStringBuffer buffer; + char* current = buffer + sizeof(buffer); + uintToString(value, current); + assert(current >= buffer); + return current; +} + +#if defined(JSON_HAS_INT64) + +std::string valueToString(Int value) { + return valueToString(LargestInt(value)); +} + +std::string valueToString(UInt value) { + return valueToString(LargestUInt(value)); +} + +#endif // # if defined(JSON_HAS_INT64) + +std::string valueToString(double value, bool useSpecialFloats, unsigned int precision) { + // Allocate a buffer that is more than large enough to store the 16 digits of + // precision requested below. + char buffer[32]; + int len = -1; + + char formatString[6]; + sprintf(formatString, "%%.%dg", precision); + + // Print into the buffer. We need not request the alternative representation + // that always has a decimal point because JSON doesn't distinguish the + // concepts of reals and integers. + if (isfinite(value)) { + len = snprintf(buffer, sizeof(buffer), formatString, value); + } else { + // IEEE standard states that NaN values will not compare to themselves + if (value != value) { + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null"); + } else if (value < 0) { + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "-Infinity" : "-1e+9999"); + } else { + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999"); + } + // For those, we do not need to call fixNumLoc, but it is fast. + } + assert(len >= 0); + fixNumericLocale(buffer, buffer + len); + return buffer; +} + +std::string valueToString(double value) { return valueToString(value, false, 17); } + +std::string valueToString(bool value) { return value ? "true" : "false"; } + +std::string valueToQuotedString(const char* value) { + if (value == NULL) + return ""; + // Not sure how to handle unicode... + if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && + !containsControlCharacter(value)) + return std::string("\"") + value + "\""; + // We have to walk value and escape any special characters. + // Appending to std::string is not efficient, but this should be rare. + // (Note: forward slashes are *not* rare, but I am not escaping them.) + std::string::size_type maxsize = + strlen(value) * 2 + 3; // allescaped+quotes+NULL + std::string result; + result.reserve(maxsize); // to avoid lots of mallocs + result += "\""; + for (const char* c = value; *c != 0; ++c) { + switch (*c) { + case '\"': + result += "\\\""; + break; + case '\\': + result += "\\\\"; + break; + case '\b': + result += "\\b"; + break; + case '\f': + result += "\\f"; + break; + case '\n': + result += "\\n"; + break; + case '\r': + result += "\\r"; + break; + case '\t': + result += "\\t"; + break; + // case '/': + // Even though \/ is considered a legal escape in JSON, a bare + // slash is also legal, so I see no reason to escape it. + // (I hope I am not misunderstanding something. + // blep notes: actually escaping \/ may be useful in javascript to avoid (*c); + result += oss.str(); + } else { + result += *c; + } + break; + } + } + result += "\""; + return result; +} + +// https://github.com/upcaste/upcaste/blob/master/src/upcore/src/cstring/strnpbrk.cpp +static char const* strnpbrk(char const* s, char const* accept, size_t n) { + assert((s || !n) && accept); + + char const* const end = s + n; + for (char const* cur = s; cur < end; ++cur) { + int const c = *cur; + for (char const* a = accept; *a; ++a) { + if (*a == c) { + return cur; + } + } + } + return NULL; +} +static std::string valueToQuotedStringN(const char* value, unsigned length) { + if (value == NULL) + return ""; + // Not sure how to handle unicode... + if (strnpbrk(value, "\"\\\b\f\n\r\t", length) == NULL && + !containsControlCharacter0(value, length)) + return std::string("\"") + value + "\""; + // We have to walk value and escape any special characters. + // Appending to std::string is not efficient, but this should be rare. + // (Note: forward slashes are *not* rare, but I am not escaping them.) + std::string::size_type maxsize = + length * 2 + 3; // allescaped+quotes+NULL + std::string result; + result.reserve(maxsize); // to avoid lots of mallocs + result += "\""; + char const* end = value + length; + for (const char* c = value; c != end; ++c) { + switch (*c) { + case '\"': + result += "\\\""; + break; + case '\\': + result += "\\\\"; + break; + case '\b': + result += "\\b"; + break; + case '\f': + result += "\\f"; + break; + case '\n': + result += "\\n"; + break; + case '\r': + result += "\\r"; + break; + case '\t': + result += "\\t"; + break; + // case '/': + // Even though \/ is considered a legal escape in JSON, a bare + // slash is also legal, so I see no reason to escape it. + // (I hope I am not misunderstanding something.) + // blep notes: actually escaping \/ may be useful in javascript to avoid (*c); + result += oss.str(); + } else { + result += *c; + } + break; + } + } + result += "\""; + return result; +} + +// Class Writer +// ////////////////////////////////////////////////////////////////// +Writer::~Writer() {} + +// Class FastWriter +// ////////////////////////////////////////////////////////////////// + +FastWriter::FastWriter() + : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false), + omitEndingLineFeed_(false) {} + +void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; } + +void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } + +void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; } + +std::string FastWriter::write(const Value& root) { + document_ = ""; + writeValue(root); + if (!omitEndingLineFeed_) + document_ += "\n"; + return document_; +} + +void FastWriter::writeValue(const Value& value) { + switch (value.type()) { + case nullValue: + if (!dropNullPlaceholders_) + document_ += "null"; + break; + case intValue: + document_ += valueToString(value.asLargestInt()); + break; + case uintValue: + document_ += valueToString(value.asLargestUInt()); + break; + case realValue: + document_ += valueToString(value.asDouble()); + break; + case stringValue: + { + // Is NULL possible for value.string_? + char const* str; + char const* end; + bool ok = value.getString(&str, &end); + if (ok) document_ += valueToQuotedStringN(str, static_cast(end-str)); + break; + } + case booleanValue: + document_ += valueToString(value.asBool()); + break; + case arrayValue: { + document_ += '['; + int size = value.size(); + for (int index = 0; index < size; ++index) { + if (index > 0) + document_ += ','; + writeValue(value[index]); + } + document_ += ']'; + } break; + case objectValue: { + Value::Members members(value.getMemberNames()); + document_ += '{'; + for (Value::Members::iterator it = members.begin(); it != members.end(); + ++it) { + const std::string& name = *it; + if (it != members.begin()) + document_ += ','; + document_ += valueToQuotedStringN(name.data(), static_cast(name.length())); + document_ += yamlCompatiblityEnabled_ ? ": " : ":"; + writeValue(value[name]); + } + document_ += '}'; + } break; + } +} + +// Class StyledWriter +// ////////////////////////////////////////////////////////////////// + +StyledWriter::StyledWriter() + : rightMargin_(74), indentSize_(3), addChildValues_() {} + +std::string StyledWriter::write(const Value& root) { + document_ = ""; + addChildValues_ = false; + indentString_ = ""; + writeCommentBeforeValue(root); + writeValue(root); + writeCommentAfterValueOnSameLine(root); + document_ += "\n"; + return document_; +} + +void StyledWriter::writeValue(const Value& value) { + switch (value.type()) { + case nullValue: + pushValue("null"); + break; + case intValue: + pushValue(valueToString(value.asLargestInt())); + break; + case uintValue: + pushValue(valueToString(value.asLargestUInt())); + break; + case realValue: + pushValue(valueToString(value.asDouble())); + break; + case stringValue: + { + // Is NULL possible for value.string_? + char const* str; + char const* end; + bool ok = value.getString(&str, &end); + if (ok) pushValue(valueToQuotedStringN(str, static_cast(end-str))); + else pushValue(""); + break; + } + case booleanValue: + pushValue(valueToString(value.asBool())); + break; + case arrayValue: + writeArrayValue(value); + break; + case objectValue: { + Value::Members members(value.getMemberNames()); + if (members.empty()) + pushValue("{}"); + else { + writeWithIndent("{"); + indent(); + Value::Members::iterator it = members.begin(); + for (;;) { + const std::string& name = *it; + const Value& childValue = value[name]; + writeCommentBeforeValue(childValue); + writeWithIndent(valueToQuotedString(name.c_str())); + document_ += " : "; + writeValue(childValue); + if (++it == members.end()) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + document_ += ','; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("}"); + } + } break; + } +} + +void StyledWriter::writeArrayValue(const Value& value) { + unsigned size = value.size(); + if (size == 0) + pushValue("[]"); + else { + bool isArrayMultiLine = isMultineArray(value); + if (isArrayMultiLine) { + writeWithIndent("["); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index = 0; + for (;;) { + const Value& childValue = value[index]; + writeCommentBeforeValue(childValue); + if (hasChildValue) + writeWithIndent(childValues_[index]); + else { + writeIndent(); + writeValue(childValue); + } + if (++index == size) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + document_ += ','; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("]"); + } else // output on a single line + { + assert(childValues_.size() == size); + document_ += "[ "; + for (unsigned index = 0; index < size; ++index) { + if (index > 0) + document_ += ", "; + document_ += childValues_[index]; + } + document_ += " ]"; + } + } +} + +bool StyledWriter::isMultineArray(const Value& value) { + int size = value.size(); + bool isMultiLine = size * 3 >= rightMargin_; + childValues_.clear(); + for (int index = 0; index < size && !isMultiLine; ++index) { + const Value& childValue = value[index]; + isMultiLine = ((childValue.isArray() || childValue.isObject()) && + childValue.size() > 0); + } + if (!isMultiLine) // check if line length > max line length + { + childValues_.reserve(size); + addChildValues_ = true; + int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' + for (int index = 0; index < size; ++index) { + if (hasCommentForValue(value[index])) { + isMultiLine = true; + } + writeValue(value[index]); + lineLength += int(childValues_[index].length()); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + +void StyledWriter::pushValue(const std::string& value) { + if (addChildValues_) + childValues_.push_back(value); + else + document_ += value; +} + +void StyledWriter::writeIndent() { + if (!document_.empty()) { + char last = document_[document_.length() - 1]; + if (last == ' ') // already indented + return; + if (last != '\n') // Comments may add new-line + document_ += '\n'; + } + document_ += indentString_; +} + +void StyledWriter::writeWithIndent(const std::string& value) { + writeIndent(); + document_ += value; +} + +void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); } + +void StyledWriter::unindent() { + assert(int(indentString_.size()) >= indentSize_); + indentString_.resize(indentString_.size() - indentSize_); +} + +void StyledWriter::writeCommentBeforeValue(const Value& root) { + if (!root.hasComment(commentBefore)) + return; + + document_ += "\n"; + writeIndent(); + const std::string& comment = root.getComment(commentBefore); + std::string::const_iterator iter = comment.begin(); + while (iter != comment.end()) { + document_ += *iter; + if (*iter == '\n' && + (iter != comment.end() && *(iter + 1) == '/')) + writeIndent(); + ++iter; + } + + // Comments are stripped of trailing newlines, so add one here + document_ += "\n"; +} + +void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) { + if (root.hasComment(commentAfterOnSameLine)) + document_ += " " + root.getComment(commentAfterOnSameLine); + + if (root.hasComment(commentAfter)) { + document_ += "\n"; + document_ += root.getComment(commentAfter); + document_ += "\n"; + } +} + +bool StyledWriter::hasCommentForValue(const Value& value) { + return value.hasComment(commentBefore) || + value.hasComment(commentAfterOnSameLine) || + value.hasComment(commentAfter); +} + +// Class StyledStreamWriter +// ////////////////////////////////////////////////////////////////// + +StyledStreamWriter::StyledStreamWriter(std::string indentation) + : document_(NULL), rightMargin_(74), indentation_(indentation), + addChildValues_() {} + +void StyledStreamWriter::write(std::ostream& out, const Value& root) { + document_ = &out; + addChildValues_ = false; + indentString_ = ""; + indented_ = true; + writeCommentBeforeValue(root); + if (!indented_) writeIndent(); + indented_ = true; + writeValue(root); + writeCommentAfterValueOnSameLine(root); + *document_ << "\n"; + document_ = NULL; // Forget the stream, for safety. +} + +void StyledStreamWriter::writeValue(const Value& value) { + switch (value.type()) { + case nullValue: + pushValue("null"); + break; + case intValue: + pushValue(valueToString(value.asLargestInt())); + break; + case uintValue: + pushValue(valueToString(value.asLargestUInt())); + break; + case realValue: + pushValue(valueToString(value.asDouble())); + break; + case stringValue: + { + // Is NULL possible for value.string_? + char const* str; + char const* end; + bool ok = value.getString(&str, &end); + if (ok) pushValue(valueToQuotedStringN(str, static_cast(end-str))); + else pushValue(""); + break; + } + case booleanValue: + pushValue(valueToString(value.asBool())); + break; + case arrayValue: + writeArrayValue(value); + break; + case objectValue: { + Value::Members members(value.getMemberNames()); + if (members.empty()) + pushValue("{}"); + else { + writeWithIndent("{"); + indent(); + Value::Members::iterator it = members.begin(); + for (;;) { + const std::string& name = *it; + const Value& childValue = value[name]; + writeCommentBeforeValue(childValue); + writeWithIndent(valueToQuotedString(name.c_str())); + *document_ << " : "; + writeValue(childValue); + if (++it == members.end()) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("}"); + } + } break; + } +} + +void StyledStreamWriter::writeArrayValue(const Value& value) { + unsigned size = value.size(); + if (size == 0) + pushValue("[]"); + else { + bool isArrayMultiLine = isMultineArray(value); + if (isArrayMultiLine) { + writeWithIndent("["); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index = 0; + for (;;) { + const Value& childValue = value[index]; + writeCommentBeforeValue(childValue); + if (hasChildValue) + writeWithIndent(childValues_[index]); + else { + if (!indented_) writeIndent(); + indented_ = true; + writeValue(childValue); + indented_ = false; + } + if (++index == size) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + *document_ << ","; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("]"); + } else // output on a single line + { + assert(childValues_.size() == size); + *document_ << "[ "; + for (unsigned index = 0; index < size; ++index) { + if (index > 0) + *document_ << ", "; + *document_ << childValues_[index]; + } + *document_ << " ]"; + } + } +} + +bool StyledStreamWriter::isMultineArray(const Value& value) { + int size = value.size(); + bool isMultiLine = size * 3 >= rightMargin_; + childValues_.clear(); + for (int index = 0; index < size && !isMultiLine; ++index) { + const Value& childValue = value[index]; + isMultiLine = ((childValue.isArray() || childValue.isObject()) && + childValue.size() > 0); + } + if (!isMultiLine) // check if line length > max line length + { + childValues_.reserve(size); + addChildValues_ = true; + int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' + for (int index = 0; index < size; ++index) { + if (hasCommentForValue(value[index])) { + isMultiLine = true; + } + writeValue(value[index]); + lineLength += int(childValues_[index].length()); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + +void StyledStreamWriter::pushValue(const std::string& value) { + if (addChildValues_) + childValues_.push_back(value); + else + *document_ << value; +} + +void StyledStreamWriter::writeIndent() { + // blep intended this to look at the so-far-written string + // to determine whether we are already indented, but + // with a stream we cannot do that. So we rely on some saved state. + // The caller checks indented_. + *document_ << '\n' << indentString_; +} + +void StyledStreamWriter::writeWithIndent(const std::string& value) { + if (!indented_) writeIndent(); + *document_ << value; + indented_ = false; +} + +void StyledStreamWriter::indent() { indentString_ += indentation_; } + +void StyledStreamWriter::unindent() { + assert(indentString_.size() >= indentation_.size()); + indentString_.resize(indentString_.size() - indentation_.size()); +} + +void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { + if (!root.hasComment(commentBefore)) + return; + + if (!indented_) writeIndent(); + const std::string& comment = root.getComment(commentBefore); + std::string::const_iterator iter = comment.begin(); + while (iter != comment.end()) { + *document_ << *iter; + if (*iter == '\n' && + (iter != comment.end() && *(iter + 1) == '/')) + // writeIndent(); // would include newline + *document_ << indentString_; + ++iter; + } + indented_ = false; +} + +void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) { + if (root.hasComment(commentAfterOnSameLine)) + *document_ << ' ' << root.getComment(commentAfterOnSameLine); + + if (root.hasComment(commentAfter)) { + writeIndent(); + *document_ << root.getComment(commentAfter); + } + indented_ = false; +} + +bool StyledStreamWriter::hasCommentForValue(const Value& value) { + return value.hasComment(commentBefore) || + value.hasComment(commentAfterOnSameLine) || + value.hasComment(commentAfter); +} + +////////////////////////// +// BuiltStyledStreamWriter + +/// Scoped enums are not available until C++11. +struct CommentStyle { + /// Decide whether to write comments. + enum Enum { + None, ///< Drop all comments. + Most, ///< Recover odd behavior of previous versions (not implemented yet). + All ///< Keep all comments. + }; +}; + +struct BuiltStyledStreamWriter : public StreamWriter +{ + BuiltStyledStreamWriter( + std::string const& indentation, + CommentStyle::Enum cs, + std::string const& colonSymbol, + std::string const& nullSymbol, + std::string const& endingLineFeedSymbol, + bool useSpecialFloats, + unsigned int precision); + int write(Value const& root, std::ostream* sout) override; +private: + void writeValue(Value const& value); + void writeArrayValue(Value const& value); + bool isMultineArray(Value const& value); + void pushValue(std::string const& value); + void writeIndent(); + void writeWithIndent(std::string const& value); + void indent(); + void unindent(); + void writeCommentBeforeValue(Value const& root); + void writeCommentAfterValueOnSameLine(Value const& root); + static bool hasCommentForValue(const Value& value); + + typedef std::vector ChildValues; + + ChildValues childValues_; + std::string indentString_; + int rightMargin_; + std::string indentation_; + CommentStyle::Enum cs_; + std::string colonSymbol_; + std::string nullSymbol_; + std::string endingLineFeedSymbol_; + bool addChildValues_ : 1; + bool indented_ : 1; + bool useSpecialFloats_ : 1; + unsigned int precision_; +}; +BuiltStyledStreamWriter::BuiltStyledStreamWriter( + std::string const& indentation, + CommentStyle::Enum cs, + std::string const& colonSymbol, + std::string const& nullSymbol, + std::string const& endingLineFeedSymbol, + bool useSpecialFloats, + unsigned int precision) + : rightMargin_(74) + , indentation_(indentation) + , cs_(cs) + , colonSymbol_(colonSymbol) + , nullSymbol_(nullSymbol) + , endingLineFeedSymbol_(endingLineFeedSymbol) + , addChildValues_(false) + , indented_(false) + , useSpecialFloats_(useSpecialFloats) + , precision_(precision) +{ +} +int BuiltStyledStreamWriter::write(Value const& root, std::ostream* sout) +{ + sout_ = sout; + addChildValues_ = false; + indented_ = true; + indentString_ = ""; + writeCommentBeforeValue(root); + if (!indented_) writeIndent(); + indented_ = true; + writeValue(root); + writeCommentAfterValueOnSameLine(root); + *sout_ << endingLineFeedSymbol_; + sout_ = NULL; + return 0; +} +void BuiltStyledStreamWriter::writeValue(Value const& value) { + switch (value.type()) { + case nullValue: + pushValue(nullSymbol_); + break; + case intValue: + pushValue(valueToString(value.asLargestInt())); + break; + case uintValue: + pushValue(valueToString(value.asLargestUInt())); + break; + case realValue: + pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_)); + break; + case stringValue: + { + // Is NULL is possible for value.string_? + char const* str; + char const* end; + bool ok = value.getString(&str, &end); + if (ok) pushValue(valueToQuotedStringN(str, static_cast(end-str))); + else pushValue(""); + break; + } + case booleanValue: + pushValue(valueToString(value.asBool())); + break; + case arrayValue: + writeArrayValue(value); + break; + case objectValue: { + Value::Members members(value.getMemberNames()); + if (members.empty()) + pushValue("{}"); + else { + writeWithIndent("{"); + indent(); + Value::Members::iterator it = members.begin(); + for (;;) { + std::string const& name = *it; + Value const& childValue = value[name]; + writeCommentBeforeValue(childValue); + writeWithIndent(valueToQuotedStringN(name.data(), static_cast(name.length()))); + *sout_ << colonSymbol_; + writeValue(childValue); + if (++it == members.end()) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + *sout_ << ","; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("}"); + } + } break; + } +} + +void BuiltStyledStreamWriter::writeArrayValue(Value const& value) { + unsigned size = value.size(); + if (size == 0) + pushValue("[]"); + else { + bool isMultiLine = (cs_ == CommentStyle::All) || isMultineArray(value); + if (isMultiLine) { + writeWithIndent("["); + indent(); + bool hasChildValue = !childValues_.empty(); + unsigned index = 0; + for (;;) { + Value const& childValue = value[index]; + writeCommentBeforeValue(childValue); + if (hasChildValue) + writeWithIndent(childValues_[index]); + else { + if (!indented_) writeIndent(); + indented_ = true; + writeValue(childValue); + indented_ = false; + } + if (++index == size) { + writeCommentAfterValueOnSameLine(childValue); + break; + } + *sout_ << ","; + writeCommentAfterValueOnSameLine(childValue); + } + unindent(); + writeWithIndent("]"); + } else // output on a single line + { + assert(childValues_.size() == size); + *sout_ << "["; + if (!indentation_.empty()) *sout_ << " "; + for (unsigned index = 0; index < size; ++index) { + if (index > 0) + *sout_ << ", "; + *sout_ << childValues_[index]; + } + if (!indentation_.empty()) *sout_ << " "; + *sout_ << "]"; + } + } +} + +bool BuiltStyledStreamWriter::isMultineArray(Value const& value) { + int size = value.size(); + bool isMultiLine = size * 3 >= rightMargin_; + childValues_.clear(); + for (int index = 0; index < size && !isMultiLine; ++index) { + Value const& childValue = value[index]; + isMultiLine = ((childValue.isArray() || childValue.isObject()) && + childValue.size() > 0); + } + if (!isMultiLine) // check if line length > max line length + { + childValues_.reserve(size); + addChildValues_ = true; + int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' + for (int index = 0; index < size; ++index) { + if (hasCommentForValue(value[index])) { + isMultiLine = true; + } + writeValue(value[index]); + lineLength += int(childValues_[index].length()); + } + addChildValues_ = false; + isMultiLine = isMultiLine || lineLength >= rightMargin_; + } + return isMultiLine; +} + +void BuiltStyledStreamWriter::pushValue(std::string const& value) { + if (addChildValues_) + childValues_.push_back(value); + else + *sout_ << value; +} + +void BuiltStyledStreamWriter::writeIndent() { + // blep intended this to look at the so-far-written string + // to determine whether we are already indented, but + // with a stream we cannot do that. So we rely on some saved state. + // The caller checks indented_. + + if (!indentation_.empty()) { + // In this case, drop newlines too. + *sout_ << '\n' << indentString_; + } +} + +void BuiltStyledStreamWriter::writeWithIndent(std::string const& value) { + if (!indented_) writeIndent(); + *sout_ << value; + indented_ = false; +} + +void BuiltStyledStreamWriter::indent() { indentString_ += indentation_; } + +void BuiltStyledStreamWriter::unindent() { + assert(indentString_.size() >= indentation_.size()); + indentString_.resize(indentString_.size() - indentation_.size()); +} + +void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) { + if (cs_ == CommentStyle::None) return; + if (!root.hasComment(commentBefore)) + return; + + if (!indented_) writeIndent(); + const std::string& comment = root.getComment(commentBefore); + std::string::const_iterator iter = comment.begin(); + while (iter != comment.end()) { + *sout_ << *iter; + if (*iter == '\n' && + (iter != comment.end() && *(iter + 1) == '/')) + // writeIndent(); // would write extra newline + *sout_ << indentString_; + ++iter; + } + indented_ = false; +} + +void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root) { + if (cs_ == CommentStyle::None) return; + if (root.hasComment(commentAfterOnSameLine)) + *sout_ << " " + root.getComment(commentAfterOnSameLine); + + if (root.hasComment(commentAfter)) { + writeIndent(); + *sout_ << root.getComment(commentAfter); + } +} + +// static +bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) { + return value.hasComment(commentBefore) || + value.hasComment(commentAfterOnSameLine) || + value.hasComment(commentAfter); +} + +/////////////// +// StreamWriter + +StreamWriter::StreamWriter() + : sout_(NULL) +{ +} +StreamWriter::~StreamWriter() +{ +} +StreamWriter::Factory::~Factory() +{} +StreamWriterBuilder::StreamWriterBuilder() +{ + setDefaults(&settings_); +} +StreamWriterBuilder::~StreamWriterBuilder() +{} +StreamWriter* StreamWriterBuilder::newStreamWriter() const +{ + std::string indentation = settings_["indentation"].asString(); + std::string cs_str = settings_["commentStyle"].asString(); + bool eyc = settings_["enableYAMLCompatibility"].asBool(); + bool dnp = settings_["dropNullPlaceholders"].asBool(); + bool usf = settings_["useSpecialFloats"].asBool(); + unsigned int pre = settings_["precision"].asUInt(); + CommentStyle::Enum cs = CommentStyle::All; + if (cs_str == "All") { + cs = CommentStyle::All; + } else if (cs_str == "None") { + cs = CommentStyle::None; + } else { + throwRuntimeError("commentStyle must be 'All' or 'None'"); + } + std::string colonSymbol = " : "; + if (eyc) { + colonSymbol = ": "; + } else if (indentation.empty()) { + colonSymbol = ":"; + } + std::string nullSymbol = "null"; + if (dnp) { + nullSymbol = ""; + } + if (pre > 17) pre = 17; + std::string endingLineFeedSymbol = ""; + return new BuiltStyledStreamWriter( + indentation, cs, + colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre); +} +static void getValidWriterKeys(std::set* valid_keys) +{ + valid_keys->clear(); + valid_keys->insert("indentation"); + valid_keys->insert("commentStyle"); + valid_keys->insert("enableYAMLCompatibility"); + valid_keys->insert("dropNullPlaceholders"); + valid_keys->insert("useSpecialFloats"); + valid_keys->insert("precision"); +} +bool StreamWriterBuilder::validate(Json::Value* invalid) const +{ + Json::Value my_invalid; + if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL + Json::Value& inv = *invalid; + std::set valid_keys; + getValidWriterKeys(&valid_keys); + Value::Members keys = settings_.getMemberNames(); + size_t n = keys.size(); + for (size_t i = 0; i < n; ++i) { + std::string const& key = keys[i]; + if (valid_keys.find(key) == valid_keys.end()) { + inv[key] = settings_[key]; + } + } + return 0u == inv.size(); +} +Value& StreamWriterBuilder::operator[](std::string key) +{ + return settings_[key]; +} +// static +void StreamWriterBuilder::setDefaults(Json::Value* settings) +{ + //! [StreamWriterBuilderDefaults] + (*settings)["commentStyle"] = "All"; + (*settings)["indentation"] = "\t"; + (*settings)["enableYAMLCompatibility"] = false; + (*settings)["dropNullPlaceholders"] = false; + (*settings)["useSpecialFloats"] = false; + (*settings)["precision"] = 17; + //! [StreamWriterBuilderDefaults] +} + +std::string writeString(StreamWriter::Factory const& builder, Value const& root) { + std::ostringstream sout; + StreamWriterPtr const writer(builder.newStreamWriter()); + writer->write(root, &sout); + return sout.str(); +} + +std::ostream& operator<<(std::ostream& sout, Value const& root) { + StreamWriterBuilder builder; + StreamWriterPtr const writer(builder.newStreamWriter()); + writer->write(root, &sout); + return sout; +} + +} // namespace Json + +// ////////////////////////////////////////////////////////////////////// +// End of content of file: src/lib_json/json_writer.cpp +// ////////////////////////////////////////////////////////////////////// + + + + + diff --git a/libs/protobuf/csharp/.editorconfig b/libs/protobuf/csharp/.editorconfig index a2bf78c..5e2afd0 100644 --- a/libs/protobuf/csharp/.editorconfig +++ b/libs/protobuf/csharp/.editorconfig @@ -14,7 +14,4 @@ tab_width = 4 # New line preferences end_of_line = lf insert_final_newline = false -trim_trailing_whitespace = true - -[*.cs] -csharp_space_after_cast = true +trim_trailing_whitespace = true \ No newline at end of file diff --git a/libs/protobuf/csharp/.gitignore b/libs/protobuf/csharp/.gitignore index 62c9638..d0d7ae0 100644 --- a/libs/protobuf/csharp/.gitignore +++ b/libs/protobuf/csharp/.gitignore @@ -18,7 +18,6 @@ lib/NUnit # Untracked files # .vs -.cr *.user *.suo *.nupkg diff --git a/libs/protobuf/csharp/BUILD.bazel b/libs/protobuf/csharp/BUILD.bazel index 9f9e83a..2c15084 100644 --- a/libs/protobuf/csharp/BUILD.bazel +++ b/libs/protobuf/csharp/BUILD.bazel @@ -3,87 +3,14 @@ # See also code generation logic under /src/google/protobuf/compiler/csharp. load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//:protobuf.bzl", "internal_csharp_proto_library") -load("//build_defs:internal_shell.bzl", "inline_sh_test") -load("//conformance:defs.bzl", "conformance_test") -################################################################################ -# Tests -################################################################################ - -conformance_test( - name = "conformance_test", - failure_list = "//conformance:failure_list_csharp.txt", - testee = "//conformance:conformance_csharp", - text_format_failure_list = "//conformance:text_format_failure_list_csharp.txt", -) - -################################################################################ -# CSharp Runtime -################################################################################ - -filegroup( - name = "srcs", +pkg_files( + name = "dist_files", srcs = glob([ "keys/*", "protos/*", "src/**/*.cs*", # .cs and .csproj - ], exclude = [ - # Exclude generated files. - "src/*/obj/**/*" ]) + [ - "src/Directory.Build.props", - "src/Google.Protobuf.Test/testprotos.pb", - "src/Google.Protobuf.sln", - ], - visibility = [ - "//csharp:__subpackages__", - "//conformance:__subpackages__" - ], -) - -filegroup( - name = "wkt_cs_srcs", - srcs = [ - "src/Google.Protobuf/Reflection/Descriptor.cs", - "src/Google.Protobuf/WellKnownTypes/Any.cs", - "src/Google.Protobuf/WellKnownTypes/Api.cs", - "src/Google.Protobuf/WellKnownTypes/Duration.cs", - "src/Google.Protobuf/WellKnownTypes/Empty.cs", - "src/Google.Protobuf/WellKnownTypes/FieldMask.cs", - "src/Google.Protobuf/WellKnownTypes/SourceContext.cs", - "src/Google.Protobuf/WellKnownTypes/Struct.cs", - "src/Google.Protobuf/WellKnownTypes/Timestamp.cs", - "src/Google.Protobuf/WellKnownTypes/Type.cs", - "src/Google.Protobuf/WellKnownTypes/Wrappers.cs", - ], - visibility = ["//src/google/protobuf/compiler/csharp:__pkg__"], -) - -inline_sh_test( - name = "tests", - srcs = [ - ":srcs", - "src/Google.Protobuf.sln", - "//csharp/src/Google.Protobuf.Conformance:srcs", - ], - cmd = """ - pushd `dirname $(location src/Google.Protobuf.sln)`/.. - dotnet restore src/Google.Protobuf.sln - dotnet build -c Release src/Google.Protobuf.sln - dotnet test -c Release -f netcoreapp3.1 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj - popd - """, -) - -################################################################################ -# Distribution files -################################################################################ - -pkg_files( - name = "dist_files", - srcs = [ - ":srcs", ".editorconfig", ".gitignore", "BUILD.bazel", @@ -93,20 +20,15 @@ pkg_files( "NuGet.Config", "README.md", "build_packages.bat", - "build_release.sh", "build_tools.sh", "buildall.bat", "buildall.sh", "generate_protos.sh", "install_dotnet_sdk.ps1", - "//csharp/src/Google.Protobuf.Conformance:dist_files", + "src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto", + "src/Google.Protobuf.Test/testprotos.pb", + "src/Google.Protobuf.sln", ], strip_prefix = strip_prefix.from_root(""), visibility = ["//pkg:__pkg__"], ) - -sh_binary( - name = "release", - srcs = ["build_release.sh"], - args = ["$(location build_release.sh)"], -) diff --git a/libs/protobuf/csharp/Google.Protobuf.Tools.nuspec b/libs/protobuf/csharp/Google.Protobuf.Tools.nuspec index 64f78d0..d74008a 100644 --- a/libs/protobuf/csharp/Google.Protobuf.Tools.nuspec +++ b/libs/protobuf/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.21.8 + 3.21.12 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/libs/protobuf/csharp/README.md b/libs/protobuf/csharp/README.md index 02abb7c..9aab782 100644 --- a/libs/protobuf/csharp/README.md +++ b/libs/protobuf/csharp/README.md @@ -16,32 +16,36 @@ To generate C# files from your `.proto` files, invoke `protoc` with the Supported platforms =================== -The runtime library is built as a class library, supporting targets of: +The runtime library is built as a portable class library, supporting: -- .NET 4.5+ (`net45`) -- .NET Standard 1.1 and 2.0 (`netstandard1.1` and `netstandard2.0`) -- .NET 5+ (`net50`) +- .NET 4.5 +- Windows 8 +- Windows Phone Silverlight 8 +- Windows Phone 8.1 +- .NET Core You should be able to use Protocol Buffers in Visual Studio 2012 and all later versions. This includes all code generated by `protoc`, -which only uses features from C# 3 and earlier. When compiling generated -code with old compilers (before C# 7.2) you need to define the -`GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE` symbol in your project -so that the generated classes don't implement `IBufferMessage`, which uses -`ref struct` types. +which only uses features from C# 3 and earlier. Building ======== -Open the `src/Google.Protobuf.sln` solution in Visual Studio 2022 or +Open the `src/Google.Protobuf.sln` solution in Visual Studio 2017 or later. Although *users* of this project are only expected to have Visual Studio 2012 or later, *developers* of the library are required to -have Visual Studio 2022 or later, as the library uses C# 10 features -in its implementation and runs tests under .NET 6. These features -have no impact when using the compiled code - they're only relevant -when building the `Google.Protobuf` assembly. +have Visual Studio 2017 or later, as the library uses C# 6 features +in its implementation, as well as the new Visual Studio 2017 csproj +format. These features have no impact when using the compiled code - +they're only relevant when building the `Google.Protobuf` assembly. + +In order to run and debug the AddressBook example in the IDE, you must +install the optional component, ".Net Core 1.0 - 1.1 development tools +for Web" (as it's labelled in current versions of the VS2017 +installer), above and beyond the main .NET Core cross-platform +development feature. Testing ======= @@ -52,11 +56,20 @@ run using the Visual Studio Test Explorer or `dotnet test`. .NET 3.5 ======== -We don't support .NET 3.5. It *used* to be feasible to build this library -targeting .NET 3.5, but a number of changes requiring newer runtime/framework -features have been added over time. While it would no doubt be *possible* to -rework the current implementation to allow most of the functionality to be built -in .NET 3.5, this would create an undue maintenance burden. +We don't officially support .NET 3.5. However, there has been some effort +to make enabling .NET 3.5 support relatively painless in case you require it. +There's no guarantee that this will continue in the future, so rely on .NET +3.5 support at your peril. + +To enable .NET 3.5 support, you must edit the `TargetFrameworks` elements of +[src/Google.Protobuf/Google.Protobuf.csproj](src/Google.Protobuf/Google.Protobuf.csproj) +(and [src/Google.Protobuf.Test/Google.Protobuf.Test.csproj](src/Google.Protobuf.Test/Google.Protobuf.Test.csproj) +if you want to run the unit tests): + +Open the .csproj file in a text editor and simply add `net35` to the list of +target frameworks, noting that the `TargetFrameworks` element appears twice in +the file (once in the first `PropertyGroup` element, and again in the second +`PropertyGroup` element, i.e., the one with the conditional). History of C# protobufs ======================= @@ -68,9 +81,9 @@ and maintained by Google. All the development will be done in open, under this r The previous project differs from this project in a number of ways: -- The old code only supported proto2; the new code initially only supported +- The old code only supported proto2; the new code only supports proto3 (so no unknown fields, no required/optional distinction, no -extensions); since then proto2 support has been added +extensions) - The old code was based on immutable message types and builders for them - The old code did not support maps or `oneof` diff --git a/libs/protobuf/csharp/build_release.sh b/libs/protobuf/csharp/build_release.sh deleted file mode 100755 index 8a641b2..0000000 --- a/libs/protobuf/csharp/build_release.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -cd $(dirname $(readlink $BASH_SOURCE)) - -# Disable some unwanted dotnet options -set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true -set DOTNET_CLI_TELEMETRY_OPTOUT=true - -# Builds Google.Protobuf NuGet packages -dotnet restore -s /lib/csharp/ src/Google.Protobuf/Google.Protobuf.csproj -dotnet pack --no-restore -c Release src/Google.Protobuf.sln -p:ContinuousIntegrationBuild=true diff --git a/libs/protobuf/csharp/compatibility_tests/v3.0.0/BUILD.bazel b/libs/protobuf/csharp/compatibility_tests/v3.0.0/BUILD.bazel deleted file mode 100644 index 1f6c713..0000000 --- a/libs/protobuf/csharp/compatibility_tests/v3.0.0/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -load("//build_defs:internal_shell.bzl", "inline_sh_test") - -# Run csharp compatibility test between 3.0.0 and the current version. -inline_sh_test( - name = "tests", - srcs = ["test.sh"], - tools = ["//:protoc"], - deps = glob([ - "src/**/*.cs*", # .cs and .csproj - "protos/**/*.proto", - ]) + [ - "//csharp:srcs", - "//:well_known_protos", - ], - cmd = "$(location test.sh) 3.0.0 $(rootpath //:protoc)" -) diff --git a/libs/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/libs/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index a2d501a..0ecdf37 100644 --- a/libs/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/libs/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -6,7 +6,6 @@ ../../keys/Google.Protobuf.snk true False - 8.0 diff --git a/libs/protobuf/csharp/compatibility_tests/v3.0.0/test.sh b/libs/protobuf/csharp/compatibility_tests/v3.0.0/test.sh index 6323a6d..459c079 100755 --- a/libs/protobuf/csharp/compatibility_tests/v3.0.0/test.sh +++ b/libs/protobuf/csharp/compatibility_tests/v3.0.0/test.sh @@ -27,8 +27,6 @@ function run_test() { set -ex -PROTOC=$(realpath ${2:-../../../bazel-bin/protoc}) - # Change to the script's directory. cd $(dirname $0) @@ -47,7 +45,7 @@ OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OL echo "Running compatibility tests with $OLD_VERSION" # Check protoc -[ -f $PROTOC ] || { +[ -f ../../../src/protoc ] || { echo "[ERROR]: Please build protoc first." exit 1 } @@ -70,12 +68,12 @@ run_test "./old_protoc" "./old_protoc" # Test A.2: # proto set 1: use new version # proto set 2 which may import protos in set 1: use old version -run_test "$PROTOC" "./old_protoc" +run_test "../../../src/protoc" "./old_protoc" # Test A.3: # proto set 1: use old version # proto set 2 which may import protos in set 1: use new version -run_test "./old_protoc" "$PROTOC" +run_test "./old_protoc" "../../../src/protoc" rm old_protoc rm keys -r diff --git a/libs/protobuf/csharp/generate_protos.sh b/libs/protobuf/csharp/generate_protos.sh index cfd6082..b021de2 100755 --- a/libs/protobuf/csharp/generate_protos.sh +++ b/libs/protobuf/csharp/generate_protos.sh @@ -11,19 +11,17 @@ pushd $(dirname $0)/.. # Protocol buffer compiler to use. If the PROTOC variable is set, # use that. Otherwise, probe for expected locations under both # Windows and Unix. -PROTOC_LOCATIONS=( - "bazel-bin/protoc" - "solution/Debug/protoc.exe" - "cmake/build/Debug/protoc.exe" - "cmake/build/Release/protoc.exe" -) if [ -z "$PROTOC" ]; then - for protoc in "${PROTOC_LOCATIONS[@]}"; do - if [ -x "$protoc" ]; then - PROTOC="$protoc" - fi - done - if [ -z "$PROTOC" ]; then + # TODO(jonskeet): Use an array and a for loop instead? + if [ -x solution/Debug/protoc.exe ]; then + PROTOC=solution/Debug/protoc.exe + elif [ -x cmake/build/Debug/protoc.exe ]; then + PROTOC=cmake/build/Debug/protoc.exe + elif [ -x cmake/build/Release/protoc.exe ]; then + PROTOC=cmake/build/Release/protoc.exe + elif [ -x src/protoc ]; then + PROTOC=src/protoc + else echo "Unable to find protocol buffer compiler." exit 1 fi @@ -42,8 +40,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ src/google/protobuf/struct.proto \ src/google/protobuf/timestamp.proto \ src/google/protobuf/type.proto \ - src/google/protobuf/wrappers.proto \ - src/google/protobuf/compiler/plugin.proto + src/google/protobuf/wrappers.proto # Test protos # Note that this deliberately does *not* include old_extensions1.proto @@ -76,3 +73,17 @@ $PROTOC -Isrc -Icsharp/protos \ # AddressBook sample protos $PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \ examples/addressbook.proto + +$PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \ + conformance/conformance.proto + +# Benchmark protos +$PROTOC -Ibenchmarks \ + benchmarks/datasets/google_message1/proto3/*.proto \ + benchmarks/benchmarks.proto \ + --csharp_out=csharp/src/Google.Protobuf.Benchmarks + +# C# only benchmark protos +$PROTOC -Isrc -Icsharp/src/Google.Protobuf.Benchmarks \ + csharp/src/Google.Protobuf.Benchmarks/*.proto \ + --csharp_out=csharp/src/Google.Protobuf.Benchmarks diff --git a/libs/protobuf/csharp/protos/unittest_issues.proto b/libs/protobuf/csharp/protos/unittest_issues.proto index d5907bb..f46c20e 100644 --- a/libs/protobuf/csharp/protos/unittest_issues.proto +++ b/libs/protobuf/csharp/protos/unittest_issues.proto @@ -59,12 +59,10 @@ message NegativeEnumMessage { // Decorate fields with [deprecated=true] as [System.Obsolete] message DeprecatedChild { - option deprecated = true; } enum DeprecatedEnum { - option deprecated = true; - DEPRECATED_ZERO = 0 [deprecated = true]; + DEPRECATED_ZERO = 0; one = 1; } @@ -171,20 +169,4 @@ message OneofWithNoneName { string x = 1; string y = 2; } -} - -// Issue 8810 -message DisambiguateCommonMembers { - int32 disambiguate_common_members = 1; - int32 types = 2; - int32 descriptor = 3; - int32 equals = 4; - int32 to_string = 5; - int32 get_hash_code = 6; - int32 write_to = 7; - int32 clone = 8; - int32 calculate_size = 9; - int32 merge_from = 10; - int32 on_construction = 11; - int32 parser = 12; -} +} \ No newline at end of file diff --git a/libs/protobuf/csharp/src/AddressBook/AddPerson.cs b/libs/protobuf/csharp/src/AddressBook/AddPerson.cs index eb0ecb3..889d1d0 100644 --- a/libs/protobuf/csharp/src/AddressBook/AddPerson.cs +++ b/libs/protobuf/csharp/src/AddressBook/AddPerson.cs @@ -107,8 +107,10 @@ namespace Google.Protobuf.Examples.AddressBook if (File.Exists(args[0])) { - using Stream file = File.OpenRead(args[0]); - addressBook = AddressBook.Parser.ParseFrom(file); + using (Stream file = File.OpenRead(args[0])) + { + addressBook = AddressBook.Parser.ParseFrom(file); + } } else { diff --git a/libs/protobuf/csharp/src/Directory.Build.props b/libs/protobuf/csharp/src/Directory.Build.props deleted file mode 100644 index dd69462..0000000 --- a/libs/protobuf/csharp/src/Directory.Build.props +++ /dev/null @@ -1,7 +0,0 @@ - - - - 10.0 - - - diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs new file mode 100644 index 0000000..c075419 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs @@ -0,0 +1,89 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using Benchmarks; +using Google.Protobuf.Reflection; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// The configuration for a single serialization test, loaded from a dataset. + /// + public class BenchmarkDatasetConfig + { + private static readonly Dictionary parsersByMessageName = + typeof(GoogleMessageBenchmark).Assembly.GetTypes() + .Where(t => typeof(IMessage).IsAssignableFrom(t)) + .ToDictionary( + t => ((MessageDescriptor) t.GetProperty("Descriptor", BindingFlags.Static | BindingFlags.Public).GetValue(null)).FullName, + t => ((MessageParser) t.GetProperty("Parser", BindingFlags.Static | BindingFlags.Public).GetValue(null))); + + public MessageParser Parser { get; } + public List Payloads { get; } + public string Name { get; } + + public BenchmarkDatasetConfig(string resource, string shortName = null) + { + var data = LoadData(resource); + var dataset = BenchmarkDataset.Parser.ParseFrom(data); + + if (!parsersByMessageName.TryGetValue(dataset.MessageName, out var parser)) + { + throw new ArgumentException($"No parser for message {dataset.MessageName} in this assembly"); + } + Parser = parser; + Payloads = new List(dataset.Payload.Select(p => p.ToByteArray())); + Name = shortName ?? dataset.Name; + } + + private static byte[] LoadData(string resource) + { + using (var stream = typeof(GoogleMessageBenchmark).Assembly.GetManifestResourceStream($"Google.Protobuf.Benchmarks.{resource}")) + { + if (stream == null) + { + throw new ArgumentException($"Unable to load embedded resource {resource}"); + } + var copy = new MemoryStream(); + stream.CopyTo(copy); + return copy.ToArray(); + } + } + + public override string ToString() => Name; + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs new file mode 100644 index 0000000..fe21d0c --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs @@ -0,0 +1,2632 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: datasets/google_message1/proto3/benchmark_message1_proto3.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Benchmarks.Proto3 { + + /// Holder for reflection information generated from datasets/google_message1/proto3/benchmark_message1_proto3.proto + public static partial class BenchmarkMessage1Proto3Reflection { + + #region Descriptor + /// File descriptor for datasets/google_message1/proto3/benchmark_message1_proto3.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static BenchmarkMessage1Proto3Reflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Cj9kYXRhc2V0cy9nb29nbGVfbWVzc2FnZTEvcHJvdG8zL2JlbmNobWFya19t", + "ZXNzYWdlMV9wcm90bzMucHJvdG8SEWJlbmNobWFya3MucHJvdG8zIoMGCg5H", + "b29nbGVNZXNzYWdlMRIOCgZmaWVsZDEYASABKAkSDgoGZmllbGQ5GAkgASgJ", + "Eg8KB2ZpZWxkMTgYEiABKAkSDwoHZmllbGQ4MBhQIAEoCBIPCgdmaWVsZDgx", + "GFEgASgIEg4KBmZpZWxkMhgCIAEoBRIOCgZmaWVsZDMYAyABKAUSEQoIZmll", + "bGQyODAYmAIgASgFEg4KBmZpZWxkNhgGIAEoBRIPCgdmaWVsZDIyGBYgASgD", + "Eg4KBmZpZWxkNBgEIAEoCRIOCgZmaWVsZDUYBSADKAYSDwoHZmllbGQ1ORg7", + "IAEoCBIOCgZmaWVsZDcYByABKAkSDwoHZmllbGQxNhgQIAEoBRIRCghmaWVs", + "ZDEzMBiCASABKAUSDwoHZmllbGQxMhgMIAEoCBIPCgdmaWVsZDE3GBEgASgI", + "Eg8KB2ZpZWxkMTMYDSABKAgSDwoHZmllbGQxNBgOIAEoCBIQCghmaWVsZDEw", + "NBhoIAEoBRIQCghmaWVsZDEwMBhkIAEoBRIQCghmaWVsZDEwMRhlIAEoBRIQ", + "CghmaWVsZDEwMhhmIAEoCRIQCghmaWVsZDEwMxhnIAEoCRIPCgdmaWVsZDI5", + "GB0gASgFEg8KB2ZpZWxkMzAYHiABKAgSDwoHZmllbGQ2MBg8IAEoBRIRCghm", + "aWVsZDI3MRiPAiABKAUSEQoIZmllbGQyNzIYkAIgASgFEhEKCGZpZWxkMTUw", + "GJYBIAEoBRIPCgdmaWVsZDIzGBcgASgFEg8KB2ZpZWxkMjQYGCABKAgSDwoH", + "ZmllbGQyNRgZIAEoBRI8CgdmaWVsZDE1GA8gASgLMisuYmVuY2htYXJrcy5w", + "cm90bzMuR29vZ2xlTWVzc2FnZTFTdWJNZXNzYWdlEg8KB2ZpZWxkNzgYTiAB", + "KAgSDwoHZmllbGQ2NxhDIAEoBRIPCgdmaWVsZDY4GEQgASgFEhEKCGZpZWxk", + "MTI4GIABIAEoBRIRCghmaWVsZDEyORiBASABKAkSEQoIZmllbGQxMzEYgwEg", + "ASgFIvcCChhHb29nbGVNZXNzYWdlMVN1Yk1lc3NhZ2USDgoGZmllbGQxGAEg", + "ASgFEg4KBmZpZWxkMhgCIAEoBRIOCgZmaWVsZDMYAyABKAUSDwoHZmllbGQx", + "NRgPIAEoCRIPCgdmaWVsZDEyGAwgASgIEg8KB2ZpZWxkMTMYDSABKAMSDwoH", + "ZmllbGQxNBgOIAEoAxIPCgdmaWVsZDE2GBAgASgFEg8KB2ZpZWxkMTkYEyAB", + "KAUSDwoHZmllbGQyMBgUIAEoCBIPCgdmaWVsZDI4GBwgASgIEg8KB2ZpZWxk", + "MjEYFSABKAYSDwoHZmllbGQyMhgWIAEoBRIPCgdmaWVsZDIzGBcgASgIEhEK", + "CGZpZWxkMjA2GM4BIAEoCBIRCghmaWVsZDIwMxjLASABKAcSEQoIZmllbGQy", + "MDQYzAEgASgFEhEKCGZpZWxkMjA1GM0BIAEoCRIRCghmaWVsZDIwNxjPASAB", + "KAQSEQoIZmllbGQzMDAYrAIgASgEQiUKHmNvbS5nb29nbGUucHJvdG9idWYu", + "YmVuY2htYXJrc0gB+AEBYgZwcm90bzM=")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1), global::Benchmarks.Proto3.GoogleMessage1.Parser, new[]{ "Field1", "Field9", "Field18", "Field80", "Field81", "Field2", "Field3", "Field280", "Field6", "Field22", "Field4", "Field5", "Field59", "Field7", "Field16", "Field130", "Field12", "Field17", "Field13", "Field14", "Field104", "Field100", "Field101", "Field102", "Field103", "Field29", "Field30", "Field60", "Field271", "Field272", "Field150", "Field23", "Field24", "Field25", "Field15", "Field78", "Field67", "Field68", "Field128", "Field129", "Field131" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.Proto3.GoogleMessage1SubMessage), global::Benchmarks.Proto3.GoogleMessage1SubMessage.Parser, new[]{ "Field1", "Field2", "Field3", "Field15", "Field12", "Field13", "Field14", "Field16", "Field19", "Field20", "Field28", "Field21", "Field22", "Field23", "Field206", "Field203", "Field204", "Field205", "Field207", "Field300" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class GoogleMessage1 : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GoogleMessage1()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Benchmarks.Proto3.BenchmarkMessage1Proto3Reflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1(GoogleMessage1 other) : this() { + field1_ = other.field1_; + field9_ = other.field9_; + field18_ = other.field18_; + field80_ = other.field80_; + field81_ = other.field81_; + field2_ = other.field2_; + field3_ = other.field3_; + field280_ = other.field280_; + field6_ = other.field6_; + field22_ = other.field22_; + field4_ = other.field4_; + field5_ = other.field5_.Clone(); + field59_ = other.field59_; + field7_ = other.field7_; + field16_ = other.field16_; + field130_ = other.field130_; + field12_ = other.field12_; + field17_ = other.field17_; + field13_ = other.field13_; + field14_ = other.field14_; + field104_ = other.field104_; + field100_ = other.field100_; + field101_ = other.field101_; + field102_ = other.field102_; + field103_ = other.field103_; + field29_ = other.field29_; + field30_ = other.field30_; + field60_ = other.field60_; + field271_ = other.field271_; + field272_ = other.field272_; + field150_ = other.field150_; + field23_ = other.field23_; + field24_ = other.field24_; + field25_ = other.field25_; + field15_ = other.field15_ != null ? other.field15_.Clone() : null; + field78_ = other.field78_; + field67_ = other.field67_; + field68_ = other.field68_; + field128_ = other.field128_; + field129_ = other.field129_; + field131_ = other.field131_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1 Clone() { + return new GoogleMessage1(this); + } + + /// Field number for the "field1" field. + public const int Field1FieldNumber = 1; + private string field1_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field1 { + get { return field1_; } + set { + field1_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field9" field. + public const int Field9FieldNumber = 9; + private string field9_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field9 { + get { return field9_; } + set { + field9_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field18" field. + public const int Field18FieldNumber = 18; + private string field18_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field18 { + get { return field18_; } + set { + field18_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field80" field. + public const int Field80FieldNumber = 80; + private bool field80_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field80 { + get { return field80_; } + set { + field80_ = value; + } + } + + /// Field number for the "field81" field. + public const int Field81FieldNumber = 81; + private bool field81_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field81 { + get { return field81_; } + set { + field81_ = value; + } + } + + /// Field number for the "field2" field. + public const int Field2FieldNumber = 2; + private int field2_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field2 { + get { return field2_; } + set { + field2_ = value; + } + } + + /// Field number for the "field3" field. + public const int Field3FieldNumber = 3; + private int field3_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field3 { + get { return field3_; } + set { + field3_ = value; + } + } + + /// Field number for the "field280" field. + public const int Field280FieldNumber = 280; + private int field280_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field280 { + get { return field280_; } + set { + field280_ = value; + } + } + + /// Field number for the "field6" field. + public const int Field6FieldNumber = 6; + private int field6_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field6 { + get { return field6_; } + set { + field6_ = value; + } + } + + /// Field number for the "field22" field. + public const int Field22FieldNumber = 22; + private long field22_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Field22 { + get { return field22_; } + set { + field22_ = value; + } + } + + /// Field number for the "field4" field. + public const int Field4FieldNumber = 4; + private string field4_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field4 { + get { return field4_; } + set { + field4_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field5" field. + public const int Field5FieldNumber = 5; + private static readonly pb::FieldCodec _repeated_field5_codec + = pb::FieldCodec.ForFixed64(42); + private readonly pbc::RepeatedField field5_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField Field5 { + get { return field5_; } + } + + /// Field number for the "field59" field. + public const int Field59FieldNumber = 59; + private bool field59_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field59 { + get { return field59_; } + set { + field59_ = value; + } + } + + /// Field number for the "field7" field. + public const int Field7FieldNumber = 7; + private string field7_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field7 { + get { return field7_; } + set { + field7_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field16" field. + public const int Field16FieldNumber = 16; + private int field16_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field16 { + get { return field16_; } + set { + field16_ = value; + } + } + + /// Field number for the "field130" field. + public const int Field130FieldNumber = 130; + private int field130_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field130 { + get { return field130_; } + set { + field130_ = value; + } + } + + /// Field number for the "field12" field. + public const int Field12FieldNumber = 12; + private bool field12_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field12 { + get { return field12_; } + set { + field12_ = value; + } + } + + /// Field number for the "field17" field. + public const int Field17FieldNumber = 17; + private bool field17_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field17 { + get { return field17_; } + set { + field17_ = value; + } + } + + /// Field number for the "field13" field. + public const int Field13FieldNumber = 13; + private bool field13_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field13 { + get { return field13_; } + set { + field13_ = value; + } + } + + /// Field number for the "field14" field. + public const int Field14FieldNumber = 14; + private bool field14_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field14 { + get { return field14_; } + set { + field14_ = value; + } + } + + /// Field number for the "field104" field. + public const int Field104FieldNumber = 104; + private int field104_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field104 { + get { return field104_; } + set { + field104_ = value; + } + } + + /// Field number for the "field100" field. + public const int Field100FieldNumber = 100; + private int field100_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field100 { + get { return field100_; } + set { + field100_ = value; + } + } + + /// Field number for the "field101" field. + public const int Field101FieldNumber = 101; + private int field101_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field101 { + get { return field101_; } + set { + field101_ = value; + } + } + + /// Field number for the "field102" field. + public const int Field102FieldNumber = 102; + private string field102_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field102 { + get { return field102_; } + set { + field102_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field103" field. + public const int Field103FieldNumber = 103; + private string field103_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field103 { + get { return field103_; } + set { + field103_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field29" field. + public const int Field29FieldNumber = 29; + private int field29_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field29 { + get { return field29_; } + set { + field29_ = value; + } + } + + /// Field number for the "field30" field. + public const int Field30FieldNumber = 30; + private bool field30_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field30 { + get { return field30_; } + set { + field30_ = value; + } + } + + /// Field number for the "field60" field. + public const int Field60FieldNumber = 60; + private int field60_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field60 { + get { return field60_; } + set { + field60_ = value; + } + } + + /// Field number for the "field271" field. + public const int Field271FieldNumber = 271; + private int field271_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field271 { + get { return field271_; } + set { + field271_ = value; + } + } + + /// Field number for the "field272" field. + public const int Field272FieldNumber = 272; + private int field272_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field272 { + get { return field272_; } + set { + field272_ = value; + } + } + + /// Field number for the "field150" field. + public const int Field150FieldNumber = 150; + private int field150_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field150 { + get { return field150_; } + set { + field150_ = value; + } + } + + /// Field number for the "field23" field. + public const int Field23FieldNumber = 23; + private int field23_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field23 { + get { return field23_; } + set { + field23_ = value; + } + } + + /// Field number for the "field24" field. + public const int Field24FieldNumber = 24; + private bool field24_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field24 { + get { return field24_; } + set { + field24_ = value; + } + } + + /// Field number for the "field25" field. + public const int Field25FieldNumber = 25; + private int field25_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field25 { + get { return field25_; } + set { + field25_ = value; + } + } + + /// Field number for the "field15" field. + public const int Field15FieldNumber = 15; + private global::Benchmarks.Proto3.GoogleMessage1SubMessage field15_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public global::Benchmarks.Proto3.GoogleMessage1SubMessage Field15 { + get { return field15_; } + set { + field15_ = value; + } + } + + /// Field number for the "field78" field. + public const int Field78FieldNumber = 78; + private bool field78_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field78 { + get { return field78_; } + set { + field78_ = value; + } + } + + /// Field number for the "field67" field. + public const int Field67FieldNumber = 67; + private int field67_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field67 { + get { return field67_; } + set { + field67_ = value; + } + } + + /// Field number for the "field68" field. + public const int Field68FieldNumber = 68; + private int field68_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field68 { + get { return field68_; } + set { + field68_ = value; + } + } + + /// Field number for the "field128" field. + public const int Field128FieldNumber = 128; + private int field128_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field128 { + get { return field128_; } + set { + field128_ = value; + } + } + + /// Field number for the "field129" field. + public const int Field129FieldNumber = 129; + private string field129_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field129 { + get { return field129_; } + set { + field129_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field131" field. + public const int Field131FieldNumber = 131; + private int field131_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field131 { + get { return field131_; } + set { + field131_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as GoogleMessage1); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(GoogleMessage1 other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Field1 != other.Field1) return false; + if (Field9 != other.Field9) return false; + if (Field18 != other.Field18) return false; + if (Field80 != other.Field80) return false; + if (Field81 != other.Field81) return false; + if (Field2 != other.Field2) return false; + if (Field3 != other.Field3) return false; + if (Field280 != other.Field280) return false; + if (Field6 != other.Field6) return false; + if (Field22 != other.Field22) return false; + if (Field4 != other.Field4) return false; + if(!field5_.Equals(other.field5_)) return false; + if (Field59 != other.Field59) return false; + if (Field7 != other.Field7) return false; + if (Field16 != other.Field16) return false; + if (Field130 != other.Field130) return false; + if (Field12 != other.Field12) return false; + if (Field17 != other.Field17) return false; + if (Field13 != other.Field13) return false; + if (Field14 != other.Field14) return false; + if (Field104 != other.Field104) return false; + if (Field100 != other.Field100) return false; + if (Field101 != other.Field101) return false; + if (Field102 != other.Field102) return false; + if (Field103 != other.Field103) return false; + if (Field29 != other.Field29) return false; + if (Field30 != other.Field30) return false; + if (Field60 != other.Field60) return false; + if (Field271 != other.Field271) return false; + if (Field272 != other.Field272) return false; + if (Field150 != other.Field150) return false; + if (Field23 != other.Field23) return false; + if (Field24 != other.Field24) return false; + if (Field25 != other.Field25) return false; + if (!object.Equals(Field15, other.Field15)) return false; + if (Field78 != other.Field78) return false; + if (Field67 != other.Field67) return false; + if (Field68 != other.Field68) return false; + if (Field128 != other.Field128) return false; + if (Field129 != other.Field129) return false; + if (Field131 != other.Field131) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Field1.Length != 0) hash ^= Field1.GetHashCode(); + if (Field9.Length != 0) hash ^= Field9.GetHashCode(); + if (Field18.Length != 0) hash ^= Field18.GetHashCode(); + if (Field80 != false) hash ^= Field80.GetHashCode(); + if (Field81 != false) hash ^= Field81.GetHashCode(); + if (Field2 != 0) hash ^= Field2.GetHashCode(); + if (Field3 != 0) hash ^= Field3.GetHashCode(); + if (Field280 != 0) hash ^= Field280.GetHashCode(); + if (Field6 != 0) hash ^= Field6.GetHashCode(); + if (Field22 != 0L) hash ^= Field22.GetHashCode(); + if (Field4.Length != 0) hash ^= Field4.GetHashCode(); + hash ^= field5_.GetHashCode(); + if (Field59 != false) hash ^= Field59.GetHashCode(); + if (Field7.Length != 0) hash ^= Field7.GetHashCode(); + if (Field16 != 0) hash ^= Field16.GetHashCode(); + if (Field130 != 0) hash ^= Field130.GetHashCode(); + if (Field12 != false) hash ^= Field12.GetHashCode(); + if (Field17 != false) hash ^= Field17.GetHashCode(); + if (Field13 != false) hash ^= Field13.GetHashCode(); + if (Field14 != false) hash ^= Field14.GetHashCode(); + if (Field104 != 0) hash ^= Field104.GetHashCode(); + if (Field100 != 0) hash ^= Field100.GetHashCode(); + if (Field101 != 0) hash ^= Field101.GetHashCode(); + if (Field102.Length != 0) hash ^= Field102.GetHashCode(); + if (Field103.Length != 0) hash ^= Field103.GetHashCode(); + if (Field29 != 0) hash ^= Field29.GetHashCode(); + if (Field30 != false) hash ^= Field30.GetHashCode(); + if (Field60 != 0) hash ^= Field60.GetHashCode(); + if (Field271 != 0) hash ^= Field271.GetHashCode(); + if (Field272 != 0) hash ^= Field272.GetHashCode(); + if (Field150 != 0) hash ^= Field150.GetHashCode(); + if (Field23 != 0) hash ^= Field23.GetHashCode(); + if (Field24 != false) hash ^= Field24.GetHashCode(); + if (Field25 != 0) hash ^= Field25.GetHashCode(); + if (field15_ != null) hash ^= Field15.GetHashCode(); + if (Field78 != false) hash ^= Field78.GetHashCode(); + if (Field67 != 0) hash ^= Field67.GetHashCode(); + if (Field68 != 0) hash ^= Field68.GetHashCode(); + if (Field128 != 0) hash ^= Field128.GetHashCode(); + if (Field129.Length != 0) hash ^= Field129.GetHashCode(); + if (Field131 != 0) hash ^= Field131.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Field1.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field4.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Field4); + } + field5_.WriteTo(output, _repeated_field5_codec); + if (Field6 != 0) { + output.WriteRawTag(48); + output.WriteInt32(Field6); + } + if (Field7.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Field7); + } + if (Field9.Length != 0) { + output.WriteRawTag(74); + output.WriteString(Field9); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != false) { + output.WriteRawTag(104); + output.WriteBool(Field13); + } + if (Field14 != false) { + output.WriteRawTag(112); + output.WriteBool(Field14); + } + if (field15_ != null) { + output.WriteRawTag(122); + output.WriteMessage(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field17 != false) { + output.WriteRawTag(136, 1); + output.WriteBool(Field17); + } + if (Field18.Length != 0) { + output.WriteRawTag(146, 1); + output.WriteString(Field18); + } + if (Field22 != 0L) { + output.WriteRawTag(176, 1); + output.WriteInt64(Field22); + } + if (Field23 != 0) { + output.WriteRawTag(184, 1); + output.WriteInt32(Field23); + } + if (Field24 != false) { + output.WriteRawTag(192, 1); + output.WriteBool(Field24); + } + if (Field25 != 0) { + output.WriteRawTag(200, 1); + output.WriteInt32(Field25); + } + if (Field29 != 0) { + output.WriteRawTag(232, 1); + output.WriteInt32(Field29); + } + if (Field30 != false) { + output.WriteRawTag(240, 1); + output.WriteBool(Field30); + } + if (Field59 != false) { + output.WriteRawTag(216, 3); + output.WriteBool(Field59); + } + if (Field60 != 0) { + output.WriteRawTag(224, 3); + output.WriteInt32(Field60); + } + if (Field67 != 0) { + output.WriteRawTag(152, 4); + output.WriteInt32(Field67); + } + if (Field68 != 0) { + output.WriteRawTag(160, 4); + output.WriteInt32(Field68); + } + if (Field78 != false) { + output.WriteRawTag(240, 4); + output.WriteBool(Field78); + } + if (Field80 != false) { + output.WriteRawTag(128, 5); + output.WriteBool(Field80); + } + if (Field81 != false) { + output.WriteRawTag(136, 5); + output.WriteBool(Field81); + } + if (Field100 != 0) { + output.WriteRawTag(160, 6); + output.WriteInt32(Field100); + } + if (Field101 != 0) { + output.WriteRawTag(168, 6); + output.WriteInt32(Field101); + } + if (Field102.Length != 0) { + output.WriteRawTag(178, 6); + output.WriteString(Field102); + } + if (Field103.Length != 0) { + output.WriteRawTag(186, 6); + output.WriteString(Field103); + } + if (Field104 != 0) { + output.WriteRawTag(192, 6); + output.WriteInt32(Field104); + } + if (Field128 != 0) { + output.WriteRawTag(128, 8); + output.WriteInt32(Field128); + } + if (Field129.Length != 0) { + output.WriteRawTag(138, 8); + output.WriteString(Field129); + } + if (Field130 != 0) { + output.WriteRawTag(144, 8); + output.WriteInt32(Field130); + } + if (Field131 != 0) { + output.WriteRawTag(152, 8); + output.WriteInt32(Field131); + } + if (Field150 != 0) { + output.WriteRawTag(176, 9); + output.WriteInt32(Field150); + } + if (Field271 != 0) { + output.WriteRawTag(248, 16); + output.WriteInt32(Field271); + } + if (Field272 != 0) { + output.WriteRawTag(128, 17); + output.WriteInt32(Field272); + } + if (Field280 != 0) { + output.WriteRawTag(192, 17); + output.WriteInt32(Field280); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Field1.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field4.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Field4); + } + field5_.WriteTo(ref output, _repeated_field5_codec); + if (Field6 != 0) { + output.WriteRawTag(48); + output.WriteInt32(Field6); + } + if (Field7.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Field7); + } + if (Field9.Length != 0) { + output.WriteRawTag(74); + output.WriteString(Field9); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != false) { + output.WriteRawTag(104); + output.WriteBool(Field13); + } + if (Field14 != false) { + output.WriteRawTag(112); + output.WriteBool(Field14); + } + if (field15_ != null) { + output.WriteRawTag(122); + output.WriteMessage(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field17 != false) { + output.WriteRawTag(136, 1); + output.WriteBool(Field17); + } + if (Field18.Length != 0) { + output.WriteRawTag(146, 1); + output.WriteString(Field18); + } + if (Field22 != 0L) { + output.WriteRawTag(176, 1); + output.WriteInt64(Field22); + } + if (Field23 != 0) { + output.WriteRawTag(184, 1); + output.WriteInt32(Field23); + } + if (Field24 != false) { + output.WriteRawTag(192, 1); + output.WriteBool(Field24); + } + if (Field25 != 0) { + output.WriteRawTag(200, 1); + output.WriteInt32(Field25); + } + if (Field29 != 0) { + output.WriteRawTag(232, 1); + output.WriteInt32(Field29); + } + if (Field30 != false) { + output.WriteRawTag(240, 1); + output.WriteBool(Field30); + } + if (Field59 != false) { + output.WriteRawTag(216, 3); + output.WriteBool(Field59); + } + if (Field60 != 0) { + output.WriteRawTag(224, 3); + output.WriteInt32(Field60); + } + if (Field67 != 0) { + output.WriteRawTag(152, 4); + output.WriteInt32(Field67); + } + if (Field68 != 0) { + output.WriteRawTag(160, 4); + output.WriteInt32(Field68); + } + if (Field78 != false) { + output.WriteRawTag(240, 4); + output.WriteBool(Field78); + } + if (Field80 != false) { + output.WriteRawTag(128, 5); + output.WriteBool(Field80); + } + if (Field81 != false) { + output.WriteRawTag(136, 5); + output.WriteBool(Field81); + } + if (Field100 != 0) { + output.WriteRawTag(160, 6); + output.WriteInt32(Field100); + } + if (Field101 != 0) { + output.WriteRawTag(168, 6); + output.WriteInt32(Field101); + } + if (Field102.Length != 0) { + output.WriteRawTag(178, 6); + output.WriteString(Field102); + } + if (Field103.Length != 0) { + output.WriteRawTag(186, 6); + output.WriteString(Field103); + } + if (Field104 != 0) { + output.WriteRawTag(192, 6); + output.WriteInt32(Field104); + } + if (Field128 != 0) { + output.WriteRawTag(128, 8); + output.WriteInt32(Field128); + } + if (Field129.Length != 0) { + output.WriteRawTag(138, 8); + output.WriteString(Field129); + } + if (Field130 != 0) { + output.WriteRawTag(144, 8); + output.WriteInt32(Field130); + } + if (Field131 != 0) { + output.WriteRawTag(152, 8); + output.WriteInt32(Field131); + } + if (Field150 != 0) { + output.WriteRawTag(176, 9); + output.WriteInt32(Field150); + } + if (Field271 != 0) { + output.WriteRawTag(248, 16); + output.WriteInt32(Field271); + } + if (Field272 != 0) { + output.WriteRawTag(128, 17); + output.WriteInt32(Field272); + } + if (Field280 != 0) { + output.WriteRawTag(192, 17); + output.WriteInt32(Field280); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Field1.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Field1); + } + if (Field9.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Field9); + } + if (Field18.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(Field18); + } + if (Field80 != false) { + size += 2 + 1; + } + if (Field81 != false) { + size += 2 + 1; + } + if (Field2 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field2); + } + if (Field3 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field3); + } + if (Field280 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field280); + } + if (Field6 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field6); + } + if (Field22 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Field22); + } + if (Field4.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Field4); + } + size += field5_.CalculateSize(_repeated_field5_codec); + if (Field59 != false) { + size += 2 + 1; + } + if (Field7.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Field7); + } + if (Field16 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field16); + } + if (Field130 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field130); + } + if (Field12 != false) { + size += 1 + 1; + } + if (Field17 != false) { + size += 2 + 1; + } + if (Field13 != false) { + size += 1 + 1; + } + if (Field14 != false) { + size += 1 + 1; + } + if (Field104 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field104); + } + if (Field100 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field100); + } + if (Field101 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field101); + } + if (Field102.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(Field102); + } + if (Field103.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(Field103); + } + if (Field29 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field29); + } + if (Field30 != false) { + size += 2 + 1; + } + if (Field60 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field60); + } + if (Field271 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field271); + } + if (Field272 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field272); + } + if (Field150 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field150); + } + if (Field23 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field23); + } + if (Field24 != false) { + size += 2 + 1; + } + if (Field25 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field25); + } + if (field15_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Field15); + } + if (Field78 != false) { + size += 2 + 1; + } + if (Field67 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field67); + } + if (Field68 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field68); + } + if (Field128 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field128); + } + if (Field129.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(Field129); + } + if (Field131 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field131); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(GoogleMessage1 other) { + if (other == null) { + return; + } + if (other.Field1.Length != 0) { + Field1 = other.Field1; + } + if (other.Field9.Length != 0) { + Field9 = other.Field9; + } + if (other.Field18.Length != 0) { + Field18 = other.Field18; + } + if (other.Field80 != false) { + Field80 = other.Field80; + } + if (other.Field81 != false) { + Field81 = other.Field81; + } + if (other.Field2 != 0) { + Field2 = other.Field2; + } + if (other.Field3 != 0) { + Field3 = other.Field3; + } + if (other.Field280 != 0) { + Field280 = other.Field280; + } + if (other.Field6 != 0) { + Field6 = other.Field6; + } + if (other.Field22 != 0L) { + Field22 = other.Field22; + } + if (other.Field4.Length != 0) { + Field4 = other.Field4; + } + field5_.Add(other.field5_); + if (other.Field59 != false) { + Field59 = other.Field59; + } + if (other.Field7.Length != 0) { + Field7 = other.Field7; + } + if (other.Field16 != 0) { + Field16 = other.Field16; + } + if (other.Field130 != 0) { + Field130 = other.Field130; + } + if (other.Field12 != false) { + Field12 = other.Field12; + } + if (other.Field17 != false) { + Field17 = other.Field17; + } + if (other.Field13 != false) { + Field13 = other.Field13; + } + if (other.Field14 != false) { + Field14 = other.Field14; + } + if (other.Field104 != 0) { + Field104 = other.Field104; + } + if (other.Field100 != 0) { + Field100 = other.Field100; + } + if (other.Field101 != 0) { + Field101 = other.Field101; + } + if (other.Field102.Length != 0) { + Field102 = other.Field102; + } + if (other.Field103.Length != 0) { + Field103 = other.Field103; + } + if (other.Field29 != 0) { + Field29 = other.Field29; + } + if (other.Field30 != false) { + Field30 = other.Field30; + } + if (other.Field60 != 0) { + Field60 = other.Field60; + } + if (other.Field271 != 0) { + Field271 = other.Field271; + } + if (other.Field272 != 0) { + Field272 = other.Field272; + } + if (other.Field150 != 0) { + Field150 = other.Field150; + } + if (other.Field23 != 0) { + Field23 = other.Field23; + } + if (other.Field24 != false) { + Field24 = other.Field24; + } + if (other.Field25 != 0) { + Field25 = other.Field25; + } + if (other.field15_ != null) { + if (field15_ == null) { + Field15 = new global::Benchmarks.Proto3.GoogleMessage1SubMessage(); + } + Field15.MergeFrom(other.Field15); + } + if (other.Field78 != false) { + Field78 = other.Field78; + } + if (other.Field67 != 0) { + Field67 = other.Field67; + } + if (other.Field68 != 0) { + Field68 = other.Field68; + } + if (other.Field128 != 0) { + Field128 = other.Field128; + } + if (other.Field129.Length != 0) { + Field129 = other.Field129; + } + if (other.Field131 != 0) { + Field131 = other.Field131; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Field1 = input.ReadString(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 34: { + Field4 = input.ReadString(); + break; + } + case 42: + case 41: { + field5_.AddEntriesFrom(input, _repeated_field5_codec); + break; + } + case 48: { + Field6 = input.ReadInt32(); + break; + } + case 58: { + Field7 = input.ReadString(); + break; + } + case 74: { + Field9 = input.ReadString(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadBool(); + break; + } + case 112: { + Field14 = input.ReadBool(); + break; + } + case 122: { + if (field15_ == null) { + Field15 = new global::Benchmarks.Proto3.GoogleMessage1SubMessage(); + } + input.ReadMessage(Field15); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 136: { + Field17 = input.ReadBool(); + break; + } + case 146: { + Field18 = input.ReadString(); + break; + } + case 176: { + Field22 = input.ReadInt64(); + break; + } + case 184: { + Field23 = input.ReadInt32(); + break; + } + case 192: { + Field24 = input.ReadBool(); + break; + } + case 200: { + Field25 = input.ReadInt32(); + break; + } + case 232: { + Field29 = input.ReadInt32(); + break; + } + case 240: { + Field30 = input.ReadBool(); + break; + } + case 472: { + Field59 = input.ReadBool(); + break; + } + case 480: { + Field60 = input.ReadInt32(); + break; + } + case 536: { + Field67 = input.ReadInt32(); + break; + } + case 544: { + Field68 = input.ReadInt32(); + break; + } + case 624: { + Field78 = input.ReadBool(); + break; + } + case 640: { + Field80 = input.ReadBool(); + break; + } + case 648: { + Field81 = input.ReadBool(); + break; + } + case 800: { + Field100 = input.ReadInt32(); + break; + } + case 808: { + Field101 = input.ReadInt32(); + break; + } + case 818: { + Field102 = input.ReadString(); + break; + } + case 826: { + Field103 = input.ReadString(); + break; + } + case 832: { + Field104 = input.ReadInt32(); + break; + } + case 1024: { + Field128 = input.ReadInt32(); + break; + } + case 1034: { + Field129 = input.ReadString(); + break; + } + case 1040: { + Field130 = input.ReadInt32(); + break; + } + case 1048: { + Field131 = input.ReadInt32(); + break; + } + case 1200: { + Field150 = input.ReadInt32(); + break; + } + case 2168: { + Field271 = input.ReadInt32(); + break; + } + case 2176: { + Field272 = input.ReadInt32(); + break; + } + case 2240: { + Field280 = input.ReadInt32(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Field1 = input.ReadString(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 34: { + Field4 = input.ReadString(); + break; + } + case 42: + case 41: { + field5_.AddEntriesFrom(ref input, _repeated_field5_codec); + break; + } + case 48: { + Field6 = input.ReadInt32(); + break; + } + case 58: { + Field7 = input.ReadString(); + break; + } + case 74: { + Field9 = input.ReadString(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadBool(); + break; + } + case 112: { + Field14 = input.ReadBool(); + break; + } + case 122: { + if (field15_ == null) { + Field15 = new global::Benchmarks.Proto3.GoogleMessage1SubMessage(); + } + input.ReadMessage(Field15); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 136: { + Field17 = input.ReadBool(); + break; + } + case 146: { + Field18 = input.ReadString(); + break; + } + case 176: { + Field22 = input.ReadInt64(); + break; + } + case 184: { + Field23 = input.ReadInt32(); + break; + } + case 192: { + Field24 = input.ReadBool(); + break; + } + case 200: { + Field25 = input.ReadInt32(); + break; + } + case 232: { + Field29 = input.ReadInt32(); + break; + } + case 240: { + Field30 = input.ReadBool(); + break; + } + case 472: { + Field59 = input.ReadBool(); + break; + } + case 480: { + Field60 = input.ReadInt32(); + break; + } + case 536: { + Field67 = input.ReadInt32(); + break; + } + case 544: { + Field68 = input.ReadInt32(); + break; + } + case 624: { + Field78 = input.ReadBool(); + break; + } + case 640: { + Field80 = input.ReadBool(); + break; + } + case 648: { + Field81 = input.ReadBool(); + break; + } + case 800: { + Field100 = input.ReadInt32(); + break; + } + case 808: { + Field101 = input.ReadInt32(); + break; + } + case 818: { + Field102 = input.ReadString(); + break; + } + case 826: { + Field103 = input.ReadString(); + break; + } + case 832: { + Field104 = input.ReadInt32(); + break; + } + case 1024: { + Field128 = input.ReadInt32(); + break; + } + case 1034: { + Field129 = input.ReadString(); + break; + } + case 1040: { + Field130 = input.ReadInt32(); + break; + } + case 1048: { + Field131 = input.ReadInt32(); + break; + } + case 1200: { + Field150 = input.ReadInt32(); + break; + } + case 2168: { + Field271 = input.ReadInt32(); + break; + } + case 2176: { + Field272 = input.ReadInt32(); + break; + } + case 2240: { + Field280 = input.ReadInt32(); + break; + } + } + } + } + #endif + + } + + public sealed partial class GoogleMessage1SubMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GoogleMessage1SubMessage()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Benchmarks.Proto3.BenchmarkMessage1Proto3Reflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1SubMessage() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1SubMessage(GoogleMessage1SubMessage other) : this() { + field1_ = other.field1_; + field2_ = other.field2_; + field3_ = other.field3_; + field15_ = other.field15_; + field12_ = other.field12_; + field13_ = other.field13_; + field14_ = other.field14_; + field16_ = other.field16_; + field19_ = other.field19_; + field20_ = other.field20_; + field28_ = other.field28_; + field21_ = other.field21_; + field22_ = other.field22_; + field23_ = other.field23_; + field206_ = other.field206_; + field203_ = other.field203_; + field204_ = other.field204_; + field205_ = other.field205_; + field207_ = other.field207_; + field300_ = other.field300_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public GoogleMessage1SubMessage Clone() { + return new GoogleMessage1SubMessage(this); + } + + /// Field number for the "field1" field. + public const int Field1FieldNumber = 1; + private int field1_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field1 { + get { return field1_; } + set { + field1_ = value; + } + } + + /// Field number for the "field2" field. + public const int Field2FieldNumber = 2; + private int field2_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field2 { + get { return field2_; } + set { + field2_ = value; + } + } + + /// Field number for the "field3" field. + public const int Field3FieldNumber = 3; + private int field3_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field3 { + get { return field3_; } + set { + field3_ = value; + } + } + + /// Field number for the "field15" field. + public const int Field15FieldNumber = 15; + private string field15_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field15 { + get { return field15_; } + set { + field15_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field12" field. + public const int Field12FieldNumber = 12; + private bool field12_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field12 { + get { return field12_; } + set { + field12_ = value; + } + } + + /// Field number for the "field13" field. + public const int Field13FieldNumber = 13; + private long field13_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Field13 { + get { return field13_; } + set { + field13_ = value; + } + } + + /// Field number for the "field14" field. + public const int Field14FieldNumber = 14; + private long field14_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Field14 { + get { return field14_; } + set { + field14_ = value; + } + } + + /// Field number for the "field16" field. + public const int Field16FieldNumber = 16; + private int field16_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field16 { + get { return field16_; } + set { + field16_ = value; + } + } + + /// Field number for the "field19" field. + public const int Field19FieldNumber = 19; + private int field19_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field19 { + get { return field19_; } + set { + field19_ = value; + } + } + + /// Field number for the "field20" field. + public const int Field20FieldNumber = 20; + private bool field20_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field20 { + get { return field20_; } + set { + field20_ = value; + } + } + + /// Field number for the "field28" field. + public const int Field28FieldNumber = 28; + private bool field28_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field28 { + get { return field28_; } + set { + field28_ = value; + } + } + + /// Field number for the "field21" field. + public const int Field21FieldNumber = 21; + private ulong field21_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ulong Field21 { + get { return field21_; } + set { + field21_ = value; + } + } + + /// Field number for the "field22" field. + public const int Field22FieldNumber = 22; + private int field22_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field22 { + get { return field22_; } + set { + field22_ = value; + } + } + + /// Field number for the "field23" field. + public const int Field23FieldNumber = 23; + private bool field23_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field23 { + get { return field23_; } + set { + field23_ = value; + } + } + + /// Field number for the "field206" field. + public const int Field206FieldNumber = 206; + private bool field206_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Field206 { + get { return field206_; } + set { + field206_ = value; + } + } + + /// Field number for the "field203" field. + public const int Field203FieldNumber = 203; + private uint field203_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public uint Field203 { + get { return field203_; } + set { + field203_ = value; + } + } + + /// Field number for the "field204" field. + public const int Field204FieldNumber = 204; + private int field204_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int Field204 { + get { return field204_; } + set { + field204_ = value; + } + } + + /// Field number for the "field205" field. + public const int Field205FieldNumber = 205; + private string field205_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Field205 { + get { return field205_; } + set { + field205_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "field207" field. + public const int Field207FieldNumber = 207; + private ulong field207_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ulong Field207 { + get { return field207_; } + set { + field207_ = value; + } + } + + /// Field number for the "field300" field. + public const int Field300FieldNumber = 300; + private ulong field300_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ulong Field300 { + get { return field300_; } + set { + field300_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as GoogleMessage1SubMessage); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(GoogleMessage1SubMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Field1 != other.Field1) return false; + if (Field2 != other.Field2) return false; + if (Field3 != other.Field3) return false; + if (Field15 != other.Field15) return false; + if (Field12 != other.Field12) return false; + if (Field13 != other.Field13) return false; + if (Field14 != other.Field14) return false; + if (Field16 != other.Field16) return false; + if (Field19 != other.Field19) return false; + if (Field20 != other.Field20) return false; + if (Field28 != other.Field28) return false; + if (Field21 != other.Field21) return false; + if (Field22 != other.Field22) return false; + if (Field23 != other.Field23) return false; + if (Field206 != other.Field206) return false; + if (Field203 != other.Field203) return false; + if (Field204 != other.Field204) return false; + if (Field205 != other.Field205) return false; + if (Field207 != other.Field207) return false; + if (Field300 != other.Field300) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Field1 != 0) hash ^= Field1.GetHashCode(); + if (Field2 != 0) hash ^= Field2.GetHashCode(); + if (Field3 != 0) hash ^= Field3.GetHashCode(); + if (Field15.Length != 0) hash ^= Field15.GetHashCode(); + if (Field12 != false) hash ^= Field12.GetHashCode(); + if (Field13 != 0L) hash ^= Field13.GetHashCode(); + if (Field14 != 0L) hash ^= Field14.GetHashCode(); + if (Field16 != 0) hash ^= Field16.GetHashCode(); + if (Field19 != 0) hash ^= Field19.GetHashCode(); + if (Field20 != false) hash ^= Field20.GetHashCode(); + if (Field28 != false) hash ^= Field28.GetHashCode(); + if (Field21 != 0UL) hash ^= Field21.GetHashCode(); + if (Field22 != 0) hash ^= Field22.GetHashCode(); + if (Field23 != false) hash ^= Field23.GetHashCode(); + if (Field206 != false) hash ^= Field206.GetHashCode(); + if (Field203 != 0) hash ^= Field203.GetHashCode(); + if (Field204 != 0) hash ^= Field204.GetHashCode(); + if (Field205.Length != 0) hash ^= Field205.GetHashCode(); + if (Field207 != 0UL) hash ^= Field207.GetHashCode(); + if (Field300 != 0UL) hash ^= Field300.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Field1 != 0) { + output.WriteRawTag(8); + output.WriteInt32(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != 0L) { + output.WriteRawTag(104); + output.WriteInt64(Field13); + } + if (Field14 != 0L) { + output.WriteRawTag(112); + output.WriteInt64(Field14); + } + if (Field15.Length != 0) { + output.WriteRawTag(122); + output.WriteString(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field19 != 0) { + output.WriteRawTag(152, 1); + output.WriteInt32(Field19); + } + if (Field20 != false) { + output.WriteRawTag(160, 1); + output.WriteBool(Field20); + } + if (Field21 != 0UL) { + output.WriteRawTag(169, 1); + output.WriteFixed64(Field21); + } + if (Field22 != 0) { + output.WriteRawTag(176, 1); + output.WriteInt32(Field22); + } + if (Field23 != false) { + output.WriteRawTag(184, 1); + output.WriteBool(Field23); + } + if (Field28 != false) { + output.WriteRawTag(224, 1); + output.WriteBool(Field28); + } + if (Field203 != 0) { + output.WriteRawTag(221, 12); + output.WriteFixed32(Field203); + } + if (Field204 != 0) { + output.WriteRawTag(224, 12); + output.WriteInt32(Field204); + } + if (Field205.Length != 0) { + output.WriteRawTag(234, 12); + output.WriteString(Field205); + } + if (Field206 != false) { + output.WriteRawTag(240, 12); + output.WriteBool(Field206); + } + if (Field207 != 0UL) { + output.WriteRawTag(248, 12); + output.WriteUInt64(Field207); + } + if (Field300 != 0UL) { + output.WriteRawTag(224, 18); + output.WriteUInt64(Field300); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Field1 != 0) { + output.WriteRawTag(8); + output.WriteInt32(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != 0L) { + output.WriteRawTag(104); + output.WriteInt64(Field13); + } + if (Field14 != 0L) { + output.WriteRawTag(112); + output.WriteInt64(Field14); + } + if (Field15.Length != 0) { + output.WriteRawTag(122); + output.WriteString(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field19 != 0) { + output.WriteRawTag(152, 1); + output.WriteInt32(Field19); + } + if (Field20 != false) { + output.WriteRawTag(160, 1); + output.WriteBool(Field20); + } + if (Field21 != 0UL) { + output.WriteRawTag(169, 1); + output.WriteFixed64(Field21); + } + if (Field22 != 0) { + output.WriteRawTag(176, 1); + output.WriteInt32(Field22); + } + if (Field23 != false) { + output.WriteRawTag(184, 1); + output.WriteBool(Field23); + } + if (Field28 != false) { + output.WriteRawTag(224, 1); + output.WriteBool(Field28); + } + if (Field203 != 0) { + output.WriteRawTag(221, 12); + output.WriteFixed32(Field203); + } + if (Field204 != 0) { + output.WriteRawTag(224, 12); + output.WriteInt32(Field204); + } + if (Field205.Length != 0) { + output.WriteRawTag(234, 12); + output.WriteString(Field205); + } + if (Field206 != false) { + output.WriteRawTag(240, 12); + output.WriteBool(Field206); + } + if (Field207 != 0UL) { + output.WriteRawTag(248, 12); + output.WriteUInt64(Field207); + } + if (Field300 != 0UL) { + output.WriteRawTag(224, 18); + output.WriteUInt64(Field300); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Field1 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field1); + } + if (Field2 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field2); + } + if (Field3 != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Field3); + } + if (Field15.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Field15); + } + if (Field12 != false) { + size += 1 + 1; + } + if (Field13 != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Field13); + } + if (Field14 != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Field14); + } + if (Field16 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field16); + } + if (Field19 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field19); + } + if (Field20 != false) { + size += 2 + 1; + } + if (Field28 != false) { + size += 2 + 1; + } + if (Field21 != 0UL) { + size += 2 + 8; + } + if (Field22 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field22); + } + if (Field23 != false) { + size += 2 + 1; + } + if (Field206 != false) { + size += 2 + 1; + } + if (Field203 != 0) { + size += 2 + 4; + } + if (Field204 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field204); + } + if (Field205.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(Field205); + } + if (Field207 != 0UL) { + size += 2 + pb::CodedOutputStream.ComputeUInt64Size(Field207); + } + if (Field300 != 0UL) { + size += 2 + pb::CodedOutputStream.ComputeUInt64Size(Field300); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(GoogleMessage1SubMessage other) { + if (other == null) { + return; + } + if (other.Field1 != 0) { + Field1 = other.Field1; + } + if (other.Field2 != 0) { + Field2 = other.Field2; + } + if (other.Field3 != 0) { + Field3 = other.Field3; + } + if (other.Field15.Length != 0) { + Field15 = other.Field15; + } + if (other.Field12 != false) { + Field12 = other.Field12; + } + if (other.Field13 != 0L) { + Field13 = other.Field13; + } + if (other.Field14 != 0L) { + Field14 = other.Field14; + } + if (other.Field16 != 0) { + Field16 = other.Field16; + } + if (other.Field19 != 0) { + Field19 = other.Field19; + } + if (other.Field20 != false) { + Field20 = other.Field20; + } + if (other.Field28 != false) { + Field28 = other.Field28; + } + if (other.Field21 != 0UL) { + Field21 = other.Field21; + } + if (other.Field22 != 0) { + Field22 = other.Field22; + } + if (other.Field23 != false) { + Field23 = other.Field23; + } + if (other.Field206 != false) { + Field206 = other.Field206; + } + if (other.Field203 != 0) { + Field203 = other.Field203; + } + if (other.Field204 != 0) { + Field204 = other.Field204; + } + if (other.Field205.Length != 0) { + Field205 = other.Field205; + } + if (other.Field207 != 0UL) { + Field207 = other.Field207; + } + if (other.Field300 != 0UL) { + Field300 = other.Field300; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Field1 = input.ReadInt32(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadInt64(); + break; + } + case 112: { + Field14 = input.ReadInt64(); + break; + } + case 122: { + Field15 = input.ReadString(); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 152: { + Field19 = input.ReadInt32(); + break; + } + case 160: { + Field20 = input.ReadBool(); + break; + } + case 169: { + Field21 = input.ReadFixed64(); + break; + } + case 176: { + Field22 = input.ReadInt32(); + break; + } + case 184: { + Field23 = input.ReadBool(); + break; + } + case 224: { + Field28 = input.ReadBool(); + break; + } + case 1629: { + Field203 = input.ReadFixed32(); + break; + } + case 1632: { + Field204 = input.ReadInt32(); + break; + } + case 1642: { + Field205 = input.ReadString(); + break; + } + case 1648: { + Field206 = input.ReadBool(); + break; + } + case 1656: { + Field207 = input.ReadUInt64(); + break; + } + case 2400: { + Field300 = input.ReadUInt64(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Field1 = input.ReadInt32(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadInt64(); + break; + } + case 112: { + Field14 = input.ReadInt64(); + break; + } + case 122: { + Field15 = input.ReadString(); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 152: { + Field19 = input.ReadInt32(); + break; + } + case 160: { + Field20 = input.ReadBool(); + break; + } + case 169: { + Field21 = input.ReadFixed64(); + break; + } + case 176: { + Field22 = input.ReadInt32(); + break; + } + case 184: { + Field23 = input.ReadBool(); + break; + } + case 224: { + Field28 = input.ReadBool(); + break; + } + case 1629: { + Field203 = input.ReadFixed32(); + break; + } + case 1632: { + Field204 = input.ReadInt32(); + break; + } + case 1642: { + Field205 = input.ReadString(); + break; + } + case 1648: { + Field206 = input.ReadBool(); + break; + } + case 1656: { + Field207 = input.ReadUInt64(); + break; + } + case 2400: { + Field300 = input.ReadUInt64(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs new file mode 100644 index 0000000..a05802d --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs @@ -0,0 +1,325 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: benchmarks.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Benchmarks { + + /// Holder for reflection information generated from benchmarks.proto + public static partial class BenchmarksReflection { + + #region Descriptor + /// File descriptor for benchmarks.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static BenchmarksReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChBiZW5jaG1hcmtzLnByb3RvEgpiZW5jaG1hcmtzIkcKEEJlbmNobWFya0Rh", + "dGFzZXQSDAoEbmFtZRgBIAEoCRIUCgxtZXNzYWdlX25hbWUYAiABKAkSDwoH", + "cGF5bG9hZBgDIAMoDEIgCh5jb20uZ29vZ2xlLnByb3RvYnVmLmJlbmNobWFy", + "a3NiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Benchmarks.BenchmarkDataset), global::Benchmarks.BenchmarkDataset.Parser, new[]{ "Name", "MessageName", "Payload" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + public sealed partial class BenchmarkDataset : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BenchmarkDataset()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Benchmarks.BenchmarksReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public BenchmarkDataset() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public BenchmarkDataset(BenchmarkDataset other) : this() { + name_ = other.name_; + messageName_ = other.messageName_; + payload_ = other.payload_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public BenchmarkDataset Clone() { + return new BenchmarkDataset(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + /// + /// Name of the benchmark dataset. This should be unique across all datasets. + /// Should only contain word characters: [a-zA-Z0-9_] + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "message_name" field. + public const int MessageNameFieldNumber = 2; + private string messageName_ = ""; + /// + /// Fully-qualified name of the protobuf message for this dataset. + /// It will be one of the messages defined benchmark_messages_proto2.proto + /// or benchmark_messages_proto3.proto. + /// + /// Implementations that do not support reflection can implement this with + /// an explicit "if/else" chain that lists every known message defined + /// in those files. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string MessageName { + get { return messageName_; } + set { + messageName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "payload" field. + public const int PayloadFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_payload_codec + = pb::FieldCodec.ForBytes(26); + private readonly pbc::RepeatedField payload_ = new pbc::RepeatedField(); + /// + /// The payload(s) for this dataset. They should be parsed or serialized + /// in sequence, in a loop, ie. + /// + /// while (!benchmarkDone) { // Benchmark runner decides when to exit. + /// for (i = 0; i < benchmark.payload.length; i++) { + /// parse(benchmark.payload[i]) + /// } + /// } + /// + /// This is intended to let datasets include a variety of data to provide + /// potentially more realistic results than just parsing the same message + /// over and over. A single message parsed repeatedly could yield unusually + /// good branch prediction performance. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField Payload { + get { return payload_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as BenchmarkDataset); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(BenchmarkDataset other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (MessageName != other.MessageName) return false; + if(!payload_.Equals(other.payload_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (MessageName.Length != 0) hash ^= MessageName.GetHashCode(); + hash ^= payload_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (MessageName.Length != 0) { + output.WriteRawTag(18); + output.WriteString(MessageName); + } + payload_.WriteTo(output, _repeated_payload_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (MessageName.Length != 0) { + output.WriteRawTag(18); + output.WriteString(MessageName); + } + payload_.WriteTo(ref output, _repeated_payload_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (MessageName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(MessageName); + } + size += payload_.CalculateSize(_repeated_payload_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(BenchmarkDataset other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.MessageName.Length != 0) { + MessageName = other.MessageName; + } + payload_.Add(other.payload_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + MessageName = input.ReadString(); + break; + } + case 26: { + payload_.AddEntriesFrom(input, _repeated_payload_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + MessageName = input.ReadString(); + break; + } + case 26: { + payload_.AddEntriesFrom(ref input, _repeated_payload_codec); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_sink.cc b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ByteStringBenchmark.cs similarity index 57% rename from libs/protobuf/src/google/protobuf/io/zero_copy_sink.cc rename to libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ByteStringBenchmark.cs index 7045648..a755850 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_sink.cc +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ByteStringBenchmark.cs @@ -1,6 +1,7 @@ +#region Copyright notice and license // Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -27,42 +28,45 @@ // 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. +#endregion -#include "google/protobuf/io/zero_copy_sink.h" +using BenchmarkDotNet.Attributes; -#include -#include +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmarks using ByteString. + /// + [MemoryDiagnoser] + public class ByteStringBenchmark + { + private const int Zero = 0; + private const int Kilobyte = 1024; + private const int _128Kilobytes = 1024 * 128; + private const int Megabyte = 1024 * 1024; + private const int _10Megabytes = 1024 * 1024 * 10; -namespace google { -namespace protobuf { -namespace io { -namespace zc_sink_internal { -void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) { - while (!failed_ && len > 0) { - if (buffer_size_ == 0) { - int size; - if (!stream_->Next(&buffer_, &size)) { - // There isn't a way for ByteSink to report errors. - buffer_size_ = 0; - failed_ = true; - return; - } - buffer_size_ = static_cast(size); + byte[] byteBuffer; + + [GlobalSetup] + public void GlobalSetup() + { + byteBuffer = new byte[PayloadSize]; + } + + [Params(Zero, Kilobyte, _128Kilobytes, Megabyte, _10Megabytes)] + public int PayloadSize { get; set; } + + [Benchmark] + public ByteString CopyFrom() + { + return ByteString.CopyFrom(byteBuffer); + } + + [Benchmark] + public ByteString UnsafeWrap() + { + return UnsafeByteOperations.UnsafeWrap(byteBuffer); + } } - - auto to_write = std::min(len, buffer_size_); - memcpy(buffer_, bytes, to_write); - - buffer_ = static_cast(buffer_) + to_write; - buffer_size_ -= to_write; - - bytes += to_write; - len -= to_write; - - bytes_written_ += to_write; - } } -} // namespace zc_sink_internal -} // namespace io -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj new file mode 100644 index 0000000..fee5f65 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj @@ -0,0 +1,26 @@ + + + + Exe + net6.0 + ../../keys/Google.Protobuf.snk + true + False + pdbonly + true + + + + + + + + + + + + + + + + diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs new file mode 100644 index 0000000..40fb3ba --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs @@ -0,0 +1,124 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Attributes; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmark for serializing and deserializing of standard datasets that are also + /// measured by benchmarks in other languages. + /// Over time we may wish to test the various different approaches to serialization and deserialization separately. + /// See https://github.com/protocolbuffers/protobuf/blob/main/benchmarks/README.md + /// See https://github.com/protocolbuffers/protobuf/blob/main/docs/performance.md + /// + [MemoryDiagnoser] + public class GoogleMessageBenchmark + { + /// + /// All the datasets to be tested. Add more datasets to the array as they're available. + /// (When C# supports proto2, this will increase significantly.) + /// + public static BenchmarkDatasetConfig[] DatasetConfigurations => new[] + { + // short name is specified to make results table more readable + new BenchmarkDatasetConfig("dataset.google_message1_proto3.pb", "goog_msg1_proto3") + }; + + [ParamsSource(nameof(DatasetConfigurations))] + public BenchmarkDatasetConfig Dataset { get; set; } + + private MessageParser parser; + /// + /// Each data set can contain multiple messages in a single file. + /// Each "write" operation should write each message in turn, and each "parse" + /// operation should parse each message in turn. + /// + private List subTests; + + [GlobalSetup] + public void GlobalSetup() + { + parser = Dataset.Parser; + subTests = Dataset.Payloads.Select(p => new SubTest(p, parser.ParseFrom(p))).ToList(); + } + + [Benchmark] + public void WriteToStream() => subTests.ForEach(item => item.WriteToStream()); + + [Benchmark] + public void ToByteArray() => subTests.ForEach(item => item.ToByteArray()); + + [Benchmark] + public void ParseFromByteArray() => subTests.ForEach(item => item.ParseFromByteArray(parser)); + + [Benchmark] + public void ParseFromStream() => subTests.ForEach(item => item.ParseFromStream(parser)); + + private class SubTest + { + private readonly Stream destinationStream; + private readonly Stream sourceStream; + private readonly byte[] data; + private readonly IMessage message; + + public SubTest(byte[] data, IMessage message) + { + destinationStream = new MemoryStream(data.Length); + sourceStream = new MemoryStream(data); + this.data = data; + this.message = message; + } + + public void Reset() => destinationStream.Position = 0; + + public void WriteToStream() + { + destinationStream.Position = 0; + message.WriteTo(destinationStream); + } + + public void ToByteArray() => message.ToByteArray(); + + public void ParseFromByteArray(MessageParser parser) => parser.ParseFrom(data); + + public void ParseFromStream(MessageParser parser) + { + sourceStream.Position = 0; + parser.ParseFrom(sourceStream); + } + } + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs new file mode 100644 index 0000000..8e6710b --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs @@ -0,0 +1,258 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Buffers; +using Google.Protobuf.WellKnownTypes; +using Benchmarks.Proto3; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmark that tests parsing performance for various messages. + /// + [MemoryDiagnoser] + public class ParseMessagesBenchmark + { + const int MaxMessages = 100; + + SubTest manyWrapperFieldsTest = new SubTest(CreateManyWrapperFieldsMessage(), ManyWrapperFieldsMessage.Parser, () => new ManyWrapperFieldsMessage(), MaxMessages); + SubTest manyPrimitiveFieldsTest = new SubTest(CreateManyPrimitiveFieldsMessage(), ManyPrimitiveFieldsMessage.Parser, () => new ManyPrimitiveFieldsMessage(), MaxMessages); + SubTest repeatedFieldTest = new SubTest(CreateRepeatedFieldMessage(), GoogleMessage1.Parser, () => new GoogleMessage1(), MaxMessages); + SubTest emptyMessageTest = new SubTest(new Empty(), Empty.Parser, () => new Empty(), MaxMessages); + + public IEnumerable MessageCountValues => new[] { 10, 100 }; + + [GlobalSetup] + public void GlobalSetup() + { + } + + [Benchmark] + public IMessage ManyWrapperFieldsMessage_ParseFromByteArray() + { + return manyWrapperFieldsTest.ParseFromByteArray(); + } + + [Benchmark] + public IMessage ManyWrapperFieldsMessage_ParseFromReadOnlySequence() + { + return manyWrapperFieldsTest.ParseFromReadOnlySequence(); + } + + [Benchmark] + public IMessage ManyPrimitiveFieldsMessage_ParseFromByteArray() + { + return manyPrimitiveFieldsTest.ParseFromByteArray(); + } + + [Benchmark] + public IMessage ManyPrimitiveFieldsMessage_ParseFromReadOnlySequence() + { + return manyPrimitiveFieldsTest.ParseFromReadOnlySequence(); + } + + [Benchmark] + public IMessage RepeatedFieldMessage_ParseFromByteArray() + { + return repeatedFieldTest.ParseFromByteArray(); + } + + [Benchmark] + public IMessage RepeatedFieldMessage_ParseFromReadOnlySequence() + { + return repeatedFieldTest.ParseFromReadOnlySequence(); + } + + [Benchmark] + public IMessage EmptyMessage_ParseFromByteArray() + { + return emptyMessageTest.ParseFromByteArray(); + } + + [Benchmark] + public IMessage EmptyMessage_ParseFromReadOnlySequence() + { + return emptyMessageTest.ParseFromReadOnlySequence(); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyWrapperFieldsMessage_ParseDelimitedMessagesFromByteArray(int messageCount) + { + manyWrapperFieldsTest.ParseDelimitedMessagesFromByteArray(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyWrapperFieldsMessage_ParseDelimitedMessagesFromReadOnlySequence(int messageCount) + { + manyWrapperFieldsTest.ParseDelimitedMessagesFromReadOnlySequence(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyPrimitiveFieldsMessage_ParseDelimitedMessagesFromByteArray(int messageCount) + { + manyPrimitiveFieldsTest.ParseDelimitedMessagesFromByteArray(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyPrimitiveFieldsMessage_ParseDelimitedMessagesFromReadOnlySequence(int messageCount) + { + manyPrimitiveFieldsTest.ParseDelimitedMessagesFromReadOnlySequence(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void RepeatedFieldMessage_ParseDelimitedMessagesFromByteArray(int messageCount) + { + repeatedFieldTest.ParseDelimitedMessagesFromByteArray(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void RepeatedFieldMessage_ParseDelimitedMessagesFromReadOnlySequence(int messageCount) + { + repeatedFieldTest.ParseDelimitedMessagesFromReadOnlySequence(messageCount); + } + + public static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage() + { + // Example data match data of an internal benchmarks + return new ManyWrapperFieldsMessage() + { + Int64Field19 = 123, + Int64Field37 = 1000032, + Int64Field26 = 3453524500, + DoubleField79 = 1.2, + DoubleField25 = 234, + DoubleField9 = 123.3, + DoubleField28 = 23, + DoubleField7 = 234, + DoubleField50 = 2.45 + }; + } + + public static ManyPrimitiveFieldsMessage CreateManyPrimitiveFieldsMessage() + { + // Example data match data of an internal benchmarks + return new ManyPrimitiveFieldsMessage() + { + Int64Field19 = 123, + Int64Field37 = 1000032, + Int64Field26 = 3453524500, + DoubleField79 = 1.2, + DoubleField25 = 234, + DoubleField9 = 123.3, + DoubleField28 = 23, + DoubleField7 = 234, + DoubleField50 = 2.45 + }; + } + + public static GoogleMessage1 CreateRepeatedFieldMessage() + { + // Message with a repeated fixed length item collection + var message = new GoogleMessage1(); + for (ulong i = 0; i < 1000; i++) + { + message.Field5.Add(i); + } + return message; + } + + private class SubTest + { + private readonly IMessage message; + private readonly MessageParser parser; + private readonly Func factory; + private readonly byte[] data; + private readonly byte[] multipleMessagesData; + + private ReadOnlySequence dataSequence; + private ReadOnlySequence multipleMessagesDataSequence; + + public SubTest(IMessage message, MessageParser parser, Func factory, int maxMessageCount) + { + this.message = message; + this.parser = parser; + this.factory = factory; + this.data = message.ToByteArray(); + this.multipleMessagesData = CreateBufferWithMultipleMessages(message, maxMessageCount); + this.dataSequence = new ReadOnlySequence(this.data); + this.multipleMessagesDataSequence = new ReadOnlySequence(this.multipleMessagesData); + } + + public IMessage ParseFromByteArray() => parser.ParseFrom(data); + + public IMessage ParseFromReadOnlySequence() => parser.ParseFrom(dataSequence); + + public void ParseDelimitedMessagesFromByteArray(int messageCount) + { + var input = new CodedInputStream(multipleMessagesData); + for (int i = 0; i < messageCount; i++) + { + var msg = factory(); + input.ReadMessage(msg); + } + } + + public void ParseDelimitedMessagesFromReadOnlySequence(int messageCount) + { + ParseContext.Initialize(multipleMessagesDataSequence, out ParseContext ctx); + for (int i = 0; i < messageCount; i++) + { + var msg = factory(); + ctx.ReadMessage(msg); + } + } + + private static byte[] CreateBufferWithMultipleMessages(IMessage msg, int msgCount) + { + var ms = new MemoryStream(); + var cos = new CodedOutputStream(ms); + for (int i = 0; i < msgCount; i++) + { + cos.WriteMessage(msg); + } + cos.Flush(); + return ms.ToArray(); + } + } + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs new file mode 100644 index 0000000..6df1c87 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs @@ -0,0 +1,536 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Attributes; +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Buffers; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmarks throughput when parsing raw primitives. + /// + [MemoryDiagnoser] + public class ParseRawPrimitivesBenchmark + { + // key is the encodedSize of varint values + Dictionary varintInputBuffers; + + byte[] doubleInputBuffer; + byte[] floatInputBuffer; + byte[] fixedIntInputBuffer; + + // key is the encodedSize of string values + Dictionary stringInputBuffers; + Dictionary> stringInputBuffersSegmented; + + Random random = new Random(417384220); // random but deterministic seed + + public IEnumerable StringEncodedSizes => new[] { 1, 4, 10, 105, 10080 }; + public IEnumerable StringSegmentedEncodedSizes => new[] { 105, 10080 }; + + [GlobalSetup] + public void GlobalSetup() + { + // add some extra values that we won't read just to make sure we are far enough from the end of the buffer + // which allows the parser fastpath to always kick in. + const int paddingValueCount = 100; + + varintInputBuffers = new Dictionary(); + for (int encodedSize = 1; encodedSize <= 10; encodedSize++) + { + byte[] buffer = CreateBufferWithRandomVarints(random, BytesToParse / encodedSize, encodedSize, paddingValueCount); + varintInputBuffers.Add(encodedSize, buffer); + } + + doubleInputBuffer = CreateBufferWithRandomDoubles(random, BytesToParse / sizeof(double), paddingValueCount); + floatInputBuffer = CreateBufferWithRandomFloats(random, BytesToParse / sizeof(float), paddingValueCount); + fixedIntInputBuffer = CreateBufferWithRandomData(random, BytesToParse / sizeof(long), sizeof(long), paddingValueCount); + + stringInputBuffers = new Dictionary(); + foreach (var encodedSize in StringEncodedSizes) + { + byte[] buffer = CreateBufferWithStrings(BytesToParse / encodedSize, encodedSize, encodedSize < 10 ? 10 : 1 ); + stringInputBuffers.Add(encodedSize, buffer); + } + + stringInputBuffersSegmented = new Dictionary>(); + foreach (var encodedSize in StringSegmentedEncodedSizes) + { + byte[] buffer = CreateBufferWithStrings(BytesToParse / encodedSize, encodedSize, encodedSize < 10 ? 10 : 1); + stringInputBuffersSegmented.Add(encodedSize, ReadOnlySequenceFactory.CreateWithContent(buffer, segmentSize: 128, addEmptySegmentDelimiters: false)); + } + } + + // Total number of bytes that each benchmark will parse. + // Measuring the time taken to parse buffer of given size makes it easier to compare parsing speed for different + // types and makes it easy to calculate the througput (in MB/s) + // 10800 bytes is chosen because it is divisible by all possible encoded sizes for all primitive types {1..10} + [Params(10080)] + public int BytesToParse { get; set; } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + public int ParseRawVarint32_CodedInputStream(int encodedSize) + { + CodedInputStream cis = new CodedInputStream(varintInputBuffers[encodedSize]); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadInt32(); + } + return sum; + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + public int ParseRawVarint32_ParseContext(int encodedSize) + { + InitializeParseContext(varintInputBuffers[encodedSize], out ParseContext ctx); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadInt32(); + } + return sum; + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + [Arguments(6)] + [Arguments(7)] + [Arguments(8)] + [Arguments(9)] + [Arguments(10)] + public long ParseRawVarint64_CodedInputStream(int encodedSize) + { + CodedInputStream cis = new CodedInputStream(varintInputBuffers[encodedSize]); + long sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadInt64(); + } + return sum; + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + [Arguments(6)] + [Arguments(7)] + [Arguments(8)] + [Arguments(9)] + [Arguments(10)] + public long ParseRawVarint64_ParseContext(int encodedSize) + { + InitializeParseContext(varintInputBuffers[encodedSize], out ParseContext ctx); + long sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadInt64(); + } + return sum; + } + + [Benchmark] + public uint ParseFixed32_CodedInputStream() + { + const int encodedSize = sizeof(uint); + CodedInputStream cis = new CodedInputStream(fixedIntInputBuffer); + uint sum = 0; + for (uint i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadFixed32(); + } + return sum; + } + + [Benchmark] + public uint ParseFixed32_ParseContext() + { + const int encodedSize = sizeof(uint); + InitializeParseContext(fixedIntInputBuffer, out ParseContext ctx); + uint sum = 0; + for (uint i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadFixed32(); + } + return sum; + } + + [Benchmark] + public ulong ParseFixed64_CodedInputStream() + { + const int encodedSize = sizeof(ulong); + CodedInputStream cis = new CodedInputStream(fixedIntInputBuffer); + ulong sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadFixed64(); + } + return sum; + } + + [Benchmark] + public ulong ParseFixed64_ParseContext() + { + const int encodedSize = sizeof(ulong); + InitializeParseContext(fixedIntInputBuffer, out ParseContext ctx); + ulong sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadFixed64(); + } + return sum; + } + + [Benchmark] + public float ParseRawFloat_CodedInputStream() + { + const int encodedSize = sizeof(float); + CodedInputStream cis = new CodedInputStream(floatInputBuffer); + float sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadFloat(); + } + return sum; + } + + [Benchmark] + public float ParseRawFloat_ParseContext() + { + const int encodedSize = sizeof(float); + InitializeParseContext(floatInputBuffer, out ParseContext ctx); + float sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadFloat(); + } + return sum; + } + + [Benchmark] + public double ParseRawDouble_CodedInputStream() + { + const int encodedSize = sizeof(double); + CodedInputStream cis = new CodedInputStream(doubleInputBuffer); + double sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadDouble(); + } + return sum; + } + + [Benchmark] + public double ParseRawDouble_ParseContext() + { + const int encodedSize = sizeof(double); + InitializeParseContext(doubleInputBuffer, out ParseContext ctx); + double sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadDouble(); + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public int ParseString_CodedInputStream(int encodedSize) + { + CodedInputStream cis = new CodedInputStream(stringInputBuffers[encodedSize]); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadString().Length; + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public int ParseString_ParseContext(int encodedSize) + { + InitializeParseContext(stringInputBuffers[encodedSize], out ParseContext ctx); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadString().Length; + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringSegmentedEncodedSizes))] + public int ParseString_ParseContext_MultipleSegments(int encodedSize) + { + InitializeParseContext(stringInputBuffersSegmented[encodedSize], out ParseContext ctx); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadString().Length; + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public int ParseBytes_CodedInputStream(int encodedSize) + { + CodedInputStream cis = new CodedInputStream(stringInputBuffers[encodedSize]); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += cis.ReadBytes().Length; + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public int ParseBytes_ParseContext(int encodedSize) + { + InitializeParseContext(stringInputBuffers[encodedSize], out ParseContext ctx); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadBytes().Length; + } + return sum; + } + + [Benchmark] + [ArgumentsSource(nameof(StringSegmentedEncodedSizes))] + public int ParseBytes_ParseContext_MultipleSegments(int encodedSize) + { + InitializeParseContext(stringInputBuffersSegmented[encodedSize], out ParseContext ctx); + int sum = 0; + for (int i = 0; i < BytesToParse / encodedSize; i++) + { + sum += ctx.ReadBytes().Length; + } + return sum; + } + + private static void InitializeParseContext(byte[] buffer, out ParseContext ctx) + { + ParseContext.Initialize(new ReadOnlySequence(buffer), out ctx); + } + + private static void InitializeParseContext(ReadOnlySequence buffer, out ParseContext ctx) + { + ParseContext.Initialize(buffer, out ctx); + } + + private static byte[] CreateBufferWithRandomVarints(Random random, int valueCount, int encodedSize, int paddingValueCount) + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream cos = new CodedOutputStream(ms); + for (int i = 0; i < valueCount + paddingValueCount; i++) + { + cos.WriteUInt64(RandomUnsignedVarint(random, encodedSize, false)); + } + cos.Flush(); + var buffer = ms.ToArray(); + + if (buffer.Length != encodedSize * (valueCount + paddingValueCount)) + { + throw new InvalidOperationException($"Unexpected output buffer length {buffer.Length}"); + } + return buffer; + } + + private static byte[] CreateBufferWithRandomFloats(Random random, int valueCount, int paddingValueCount) + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream cos = new CodedOutputStream(ms); + for (int i = 0; i < valueCount + paddingValueCount; i++) + { + cos.WriteFloat((float)random.NextDouble()); + } + cos.Flush(); + var buffer = ms.ToArray(); + return buffer; + } + + private static byte[] CreateBufferWithRandomDoubles(Random random, int valueCount, int paddingValueCount) + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream cos = new CodedOutputStream(ms); + for (int i = 0; i < valueCount + paddingValueCount; i++) + { + cos.WriteDouble(random.NextDouble()); + } + cos.Flush(); + var buffer = ms.ToArray(); + return buffer; + } + + private static byte[] CreateBufferWithRandomData(Random random, int valueCount, int encodedSize, int paddingValueCount) + { + int bufferSize = (valueCount + paddingValueCount) * encodedSize; + byte[] buffer = new byte[bufferSize]; + random.NextBytes(buffer); + return buffer; + } + + /// + /// Generate a random value that will take exactly "encodedSize" bytes when varint-encoded. + /// + public static ulong RandomUnsignedVarint(Random random, int encodedSize, bool fitsIn32Bits) + { + Span randomBytesBuffer = stackalloc byte[8]; + + if (encodedSize < 1 || encodedSize > 10 || (fitsIn32Bits && encodedSize > 5)) + { + throw new ArgumentException("Illegal encodedSize value requested", nameof(encodedSize)); + } + const int bitsPerByte = 7; + + ulong result = 0; + while (true) + { + random.NextBytes(randomBytesBuffer); + ulong randomValue = BinaryPrimitives.ReadUInt64LittleEndian(randomBytesBuffer); + + // only use the number of random bits we need + ulong bitmask = encodedSize < 10 ? ((1UL << (encodedSize * bitsPerByte)) - 1) : ulong.MaxValue; + result = randomValue & bitmask; + + if (fitsIn32Bits) + { + // make sure the resulting value is representable by a uint. + result &= uint.MaxValue; + } + + if (encodedSize == 10) + { + // for 10-byte values the highest bit always needs to be set (7*9=63) + result |= ulong.MaxValue; + break; + } + + // some random values won't require the full "encodedSize" bytes, check that at least + // one of the top 7 bits is set. Retrying is fine since it only happens rarely + if (encodedSize == 1 || (result & (0x7FUL << ((encodedSize - 1) * bitsPerByte))) != 0) + { + break; + } + } + return result; + } + + private static byte[] CreateBufferWithStrings(int valueCount, int encodedSize, int paddingValueCount) + { + var str = CreateStringWithEncodedSize(encodedSize); + + MemoryStream ms = new MemoryStream(); + CodedOutputStream cos = new CodedOutputStream(ms); + for (int i = 0; i < valueCount + paddingValueCount; i++) + { + cos.WriteString(str); + } + cos.Flush(); + var buffer = ms.ToArray(); + + if (buffer.Length != encodedSize * (valueCount + paddingValueCount)) + { + throw new InvalidOperationException($"Unexpected output buffer length {buffer.Length}"); + } + return buffer; + } + + public static string CreateStringWithEncodedSize(int encodedSize) + { + var str = new string('a', encodedSize); + while (CodedOutputStream.ComputeStringSize(str) > encodedSize) + { + str = str.Substring(1); + } + + if (CodedOutputStream.ComputeStringSize(str) != encodedSize) + { + throw new InvalidOperationException($"Generated string with wrong encodedSize"); + } + return str; + } + + public static string CreateNonAsciiStringWithEncodedSize(int encodedSize) + { + if (encodedSize < 3) + { + throw new ArgumentException("Illegal encoded size for a string with non-ascii chars."); + } + var twoByteChar = '\u00DC'; // U-umlaut, UTF8 encoding has 2 bytes + var str = new string(twoByteChar, encodedSize / 2); + while (CodedOutputStream.ComputeStringSize(str) > encodedSize) + { + str = str.Substring(1); + } + + // add padding of ascii characters to reach the desired encoded size. + while (CodedOutputStream.ComputeStringSize(str) < encodedSize) + { + str += 'a'; + } + + // Note that for a few specific encodedSize values, it might be impossible to generate + // the string with the desired encodedSize using the algorithm above. For testing purposes, checking that + // the encoded size we got is actually correct is good enough. + if (CodedOutputStream.ComputeStringSize(str) != encodedSize) + { + throw new InvalidOperationException($"Generated string with wrong encodedSize"); + } + return str; + } + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Program.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Program.cs new file mode 100644 index 0000000..037752f --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/Program.cs @@ -0,0 +1,49 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Running; + +namespace Google.Protobuf.Benchmarks +{ + class Program + { + // typical usage: dotnet run -c Release -f netcoreapp3.1 + // (this can profile both .net core and .net framework; for some reason + // if you start from "-f net461", it goes horribly wrong) + public static void Main(string[] args) + { + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); + } + } + + +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs new file mode 100644 index 0000000..e2eb2e8 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs @@ -0,0 +1,9604 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: wrapper_benchmark_messages.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Google.Protobuf.Benchmarks { + + /// Holder for reflection information generated from wrapper_benchmark_messages.proto + public static partial class WrapperBenchmarkMessagesReflection { + + #region Descriptor + /// File descriptor for wrapper_benchmark_messages.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static WrapperBenchmarkMessagesReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "CiB3cmFwcGVyX2JlbmNobWFya19tZXNzYWdlcy5wcm90bxIaZ29vZ2xlLnBy", + "b3RvYnVmLmJlbmNobWFya3MaHmdvb2dsZS9wcm90b2J1Zi93cmFwcGVycy5w", + "cm90byLeLgoYTWFueVdyYXBwZXJGaWVsZHNNZXNzYWdlEjUKD2RvdWJsZV9m", + "aWVsZF85NRhfIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI0", + "Cg5kb3VibGVfZmllbGRfMRgBIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3Vi", + "bGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNzkYTyABKAsyHC5nb29nbGUucHJv", + "dG9idWYuRG91YmxlVmFsdWUSMgoNaW50NjRfZmllbGRfMhgCIAEoCzIbLmdv", + "b2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEjUKD2RvdWJsZV9maWVsZF85Nhhg", + "IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRIyCg1pbnQ2NF9m", + "aWVsZF8zGAMgASgLMhsuZ29vZ2xlLnByb3RvYnVmLkludDY0VmFsdWUSMgoN", + "aW50NjRfZmllbGRfNBgEIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZh", + "bHVlEjUKD2RvdWJsZV9maWVsZF85NxhhIAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNjUYQSABKAsyHC5nb29n", + "bGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzY2GEIg", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjQKDmRvdWJsZV9m", + "aWVsZF83GAcgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUK", + "D2RvdWJsZV9maWVsZF82Mhg+IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3Vi", + "bGVWYWx1ZRI2ChBkb3VibGVfZmllbGRfMTE4GHYgASgLMhwuZ29vZ2xlLnBy", + "b3RvYnVmLkRvdWJsZVZhbHVlEjYKEGRvdWJsZV9maWVsZF8xMTkYdyABKAsy", + "HC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxk", + "XzY3GEMgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjYKEGRv", + "dWJsZV9maWVsZF8xMjAYeCABKAsyHC5nb29nbGUucHJvdG9idWYuRG91Ymxl", + "VmFsdWUSNgoQZG91YmxlX2ZpZWxkXzEyMRh5IAEoCzIcLmdvb2dsZS5wcm90", + "b2J1Zi5Eb3VibGVWYWx1ZRI2ChBkb3VibGVfZmllbGRfMTIyGHogASgLMhwu", + "Z29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjYKEGRvdWJsZV9maWVsZF8x", + "MjMYeyABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNgoQZG91", + "YmxlX2ZpZWxkXzEyNBh8IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVW", + "YWx1ZRI0Cg5kb3VibGVfZmllbGRfOBgIIAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5Eb3VibGVWYWx1ZRI0Cg5kb3VibGVfZmllbGRfORgJIAEoCzIcLmdvb2ds", + "ZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfOTgYYiAB", + "KAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2Zp", + "ZWxkXzEwGAogASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUK", + "D2RvdWJsZV9maWVsZF8xMRgLIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3Vi", + "bGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfOTkYYyABKAsyHC5nb29nbGUucHJv", + "dG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzg0GFQgASgLMhwu", + "Z29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUKD2RvdWJsZV9maWVsZF8x", + "NBgOIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3Vi", + "bGVfZmllbGRfNzcYTSABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFs", + "dWUSNQoPZG91YmxlX2ZpZWxkXzE1GA8gASgLMhwuZ29vZ2xlLnByb3RvYnVm", + "LkRvdWJsZVZhbHVlEjMKDmludDY0X2ZpZWxkXzE5GBMgASgLMhsuZ29vZ2xl", + "LnByb3RvYnVmLkludDY0VmFsdWUSNAoPaW50NjRfZmllbGRfMTE1GHMgASgL", + "MhsuZ29vZ2xlLnByb3RvYnVmLkludDY0VmFsdWUSNgoQZG91YmxlX2ZpZWxk", + "XzExNhh0IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI0Cg9p", + "bnQ2NF9maWVsZF8xMTcYdSABKAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRW", + "YWx1ZRI1Cg9kb3VibGVfZmllbGRfMjAYFCABKAsyHC5nb29nbGUucHJvdG9i", + "dWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzIxGBUgASgLMhwuZ29v", + "Z2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUKD3N0cmluZ19maWVsZF83MxhJ", + "IAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5TdHJpbmdWYWx1ZRI1Cg9zdHJpbmdf", + "ZmllbGRfNzQYSiABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUS", + "NQoPZG91YmxlX2ZpZWxkXzIyGBYgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRv", + "dWJsZVZhbHVlEjUKD2RvdWJsZV9maWVsZF82ORhFIAEoCzIcLmdvb2dsZS5w", + "cm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNzAYRiABKAsy", + "HC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxk", + "XzcxGEcgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUKD2Rv", + "dWJsZV9maWVsZF83MhhIIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVW", + "YWx1ZRI1Cg9kb3VibGVfZmllbGRfMjUYGSABKAsyHC5nb29nbGUucHJvdG9i", + "dWYuRG91YmxlVmFsdWUSMwoOaW50NjRfZmllbGRfMjYYGiABKAsyGy5nb29n", + "bGUucHJvdG9idWYuSW50NjRWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNjgYRCAB", + "KAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2Zp", + "ZWxkXzI4GBwgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjYK", + "EGRvdWJsZV9maWVsZF8xMDYYaiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91", + "YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzI5GB0gASgLMhwuZ29vZ2xlLnBy", + "b3RvYnVmLkRvdWJsZVZhbHVlEjUKD2RvdWJsZV9maWVsZF8zMBgeIAEoCzIc", + "Lmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI2ChBkb3VibGVfZmllbGRf", + "MTAxGGUgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjYKEGRv", + "dWJsZV9maWVsZF8xMDIYZiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91Ymxl", + "VmFsdWUSNgoQZG91YmxlX2ZpZWxkXzEwMxhnIAEoCzIcLmdvb2dsZS5wcm90", + "b2J1Zi5Eb3VibGVWYWx1ZRI2ChBkb3VibGVfZmllbGRfMTA0GGggASgLMhwu", + "Z29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjYKEGRvdWJsZV9maWVsZF8x", + "MDUYaSABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91", + "YmxlX2ZpZWxkXzMxGB8gASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZh", + "bHVlEjMKDmludDY0X2ZpZWxkXzMyGCAgASgLMhsuZ29vZ2xlLnByb3RvYnVm", + "LkludDY0VmFsdWUSNQoPZG91YmxlX2ZpZWxkXzc1GEsgASgLMhwuZ29vZ2xl", + "LnByb3RvYnVmLkRvdWJsZVZhbHVlEjcKEGRvdWJsZV9maWVsZF8xMjkYgQEg", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEhUKDWVudW1fZmll", + "bGRfODAYUCABKAUSFQoNZW51bV9maWVsZF84MRhRIAEoBRIzCg5pbnQ2NF9m", + "aWVsZF84MhhSIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEhUK", + "DWVudW1fZmllbGRfODMYUyABKAUSMwoOaW50NjRfZmllbGRfODUYVSABKAsy", + "Gy5nb29nbGUucHJvdG9idWYuSW50NjRWYWx1ZRIzCg5pbnQ2NF9maWVsZF84", + "NhhWIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEjMKDmludDY0", + "X2ZpZWxkXzg3GFcgASgLMhsuZ29vZ2xlLnByb3RvYnVmLkludDY0VmFsdWUS", + "NAoPaW50NjRfZmllbGRfMTI1GH0gASgLMhsuZ29vZ2xlLnByb3RvYnVmLklu", + "dDY0VmFsdWUSMwoOaW50NjRfZmllbGRfMzcYJSABKAsyGy5nb29nbGUucHJv", + "dG9idWYuSW50NjRWYWx1ZRI1Cg9kb3VibGVfZmllbGRfMzgYJiABKAsyHC5n", + "b29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSMQoMaW50ZXJhY3Rpb25zGCcg", + "ASgLMhsuZ29vZ2xlLnByb3RvYnVmLkludDY0VmFsdWUSHgoWcmVwZWF0ZWRf", + "aW50X2ZpZWxkXzEwMBhkIAMoBRI1Cg9kb3VibGVfZmllbGRfNDAYKCABKAsy", + "HC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSMwoOaW50NjRfZmllbGRf", + "NDEYKSABKAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRWYWx1ZRI0Cg9pbnQ2", + "NF9maWVsZF8xMjYYfiABKAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRWYWx1", + "ZRI0Cg9pbnQ2NF9maWVsZF8xMjcYfyABKAsyGy5nb29nbGUucHJvdG9idWYu", + "SW50NjRWYWx1ZRI3ChBkb3VibGVfZmllbGRfMTI4GIABIAEoCzIcLmdvb2ds", + "ZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI2ChBkb3VibGVfZmllbGRfMTA5GG0g", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjQKD2ludDY0X2Zp", + "ZWxkXzExMBhuIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEjYK", + "EGRvdWJsZV9maWVsZF8xMTEYbyABKAsyHC5nb29nbGUucHJvdG9idWYuRG91", + "YmxlVmFsdWUSNAoPaW50NjRfZmllbGRfMTEyGHAgASgLMhsuZ29vZ2xlLnBy", + "b3RvYnVmLkludDY0VmFsdWUSNgoQZG91YmxlX2ZpZWxkXzExMxhxIAEoCzIc", + "Lmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI0Cg9pbnQ2NF9maWVsZF8x", + "MTQYciABKAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRWYWx1ZRI1Cg9kb3Vi", + "bGVfZmllbGRfNDIYKiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFs", + "dWUSMwoOaW50NjRfZmllbGRfNDMYKyABKAsyGy5nb29nbGUucHJvdG9idWYu", + "SW50NjRWYWx1ZRIzCg5pbnQ2NF9maWVsZF80NBgsIAEoCzIbLmdvb2dsZS5w", + "cm90b2J1Zi5JbnQ2NFZhbHVlEjUKD2RvdWJsZV9maWVsZF80NRgtIAEoCzIc", + "Lmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRf", + "NDYYLiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91", + "YmxlX2ZpZWxkXzc4GE4gASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZh", + "bHVlEjUKD2RvdWJsZV9maWVsZF84OBhYIAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNDcYLyABKAsyHC5nb29n", + "bGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzg5GFkg", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjUKD2RvdWJsZV9m", + "aWVsZF80OBgwIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1", + "Cg9kb3VibGVfZmllbGRfNDkYMSABKAsyHC5nb29nbGUucHJvdG9idWYuRG91", + "YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzUwGDIgASgLMhwuZ29vZ2xlLnBy", + "b3RvYnVmLkRvdWJsZVZhbHVlEjUKD2RvdWJsZV9maWVsZF85MBhaIAEoCzIc", + "Lmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRf", + "NTEYMyABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91", + "YmxlX2ZpZWxkXzkxGFsgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZh", + "bHVlEjUKD2RvdWJsZV9maWVsZF85MhhcIAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5Eb3VibGVWYWx1ZRI0Cg9pbnQ2NF9maWVsZF8xMDcYayABKAsyGy5nb29n", + "bGUucHJvdG9idWYuSW50NjRWYWx1ZRI1Cg9kb3VibGVfZmllbGRfOTMYXSAB", + "KAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNgoQZG91YmxlX2Zp", + "ZWxkXzEwOBhsIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1", + "Cg9kb3VibGVfZmllbGRfNTIYNCABKAsyHC5nb29nbGUucHJvdG9idWYuRG91", + "YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzUzGDUgASgLMhwuZ29vZ2xlLnBy", + "b3RvYnVmLkRvdWJsZVZhbHVlEjUKD2RvdWJsZV9maWVsZF85NBheIAEoCzIc", + "Lmdvb2dsZS5wcm90b2J1Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRf", + "NTQYNiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91", + "YmxlX2ZpZWxkXzU1GDcgASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZh", + "bHVlEjUKD2RvdWJsZV9maWVsZF81Nhg4IAEoCzIcLmdvb2dsZS5wcm90b2J1", + "Zi5Eb3VibGVWYWx1ZRI1Cg9kb3VibGVfZmllbGRfNTcYOSABKAsyHC5nb29n", + "bGUucHJvdG9idWYuRG91YmxlVmFsdWUSNQoPZG91YmxlX2ZpZWxkXzU4GDog", + "ASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVlEjMKDmludDY0X2Zp", + "ZWxkXzU5GDsgASgLMhsuZ29vZ2xlLnByb3RvYnVmLkludDY0VmFsdWUSMwoO", + "aW50NjRfZmllbGRfNjAYPCABKAsyGy5nb29nbGUucHJvdG9idWYuSW50NjRW", + "YWx1ZSLwFQoaTWFueVByaW1pdGl2ZUZpZWxkc01lc3NhZ2USFwoPZG91Ymxl", + "X2ZpZWxkXzk1GF8gASgBEhYKDmRvdWJsZV9maWVsZF8xGAEgASgBEhcKD2Rv", + "dWJsZV9maWVsZF83ORhPIAEoARIVCg1pbnQ2NF9maWVsZF8yGAIgASgDEhcK", + "D2RvdWJsZV9maWVsZF85NhhgIAEoARIVCg1pbnQ2NF9maWVsZF8zGAMgASgD", + "EhUKDWludDY0X2ZpZWxkXzQYBCABKAMSFwoPZG91YmxlX2ZpZWxkXzk3GGEg", + "ASgBEhcKD2RvdWJsZV9maWVsZF82NRhBIAEoARIXCg9kb3VibGVfZmllbGRf", + "NjYYQiABKAESFgoOZG91YmxlX2ZpZWxkXzcYByABKAESFwoPZG91YmxlX2Zp", + "ZWxkXzYyGD4gASgBEhgKEGRvdWJsZV9maWVsZF8xMTgYdiABKAESGAoQZG91", + "YmxlX2ZpZWxkXzExORh3IAEoARIXCg9kb3VibGVfZmllbGRfNjcYQyABKAES", + "GAoQZG91YmxlX2ZpZWxkXzEyMBh4IAEoARIYChBkb3VibGVfZmllbGRfMTIx", + "GHkgASgBEhgKEGRvdWJsZV9maWVsZF8xMjIYeiABKAESGAoQZG91YmxlX2Zp", + "ZWxkXzEyMxh7IAEoARIYChBkb3VibGVfZmllbGRfMTI0GHwgASgBEhYKDmRv", + "dWJsZV9maWVsZF84GAggASgBEhYKDmRvdWJsZV9maWVsZF85GAkgASgBEhcK", + "D2RvdWJsZV9maWVsZF85OBhiIAEoARIXCg9kb3VibGVfZmllbGRfMTAYCiAB", + "KAESFwoPZG91YmxlX2ZpZWxkXzExGAsgASgBEhcKD2RvdWJsZV9maWVsZF85", + "ORhjIAEoARIXCg9kb3VibGVfZmllbGRfODQYVCABKAESFwoPZG91YmxlX2Zp", + "ZWxkXzE0GA4gASgBEhcKD2RvdWJsZV9maWVsZF83NxhNIAEoARIXCg9kb3Vi", + "bGVfZmllbGRfMTUYDyABKAESFgoOaW50NjRfZmllbGRfMTkYEyABKAMSFwoP", + "aW50NjRfZmllbGRfMTE1GHMgASgDEhgKEGRvdWJsZV9maWVsZF8xMTYYdCAB", + "KAESFwoPaW50NjRfZmllbGRfMTE3GHUgASgDEhcKD2RvdWJsZV9maWVsZF8y", + "MBgUIAEoARIXCg9kb3VibGVfZmllbGRfMjEYFSABKAESFwoPc3RyaW5nX2Zp", + "ZWxkXzczGEkgASgJEhcKD3N0cmluZ19maWVsZF83NBhKIAEoCRIXCg9kb3Vi", + "bGVfZmllbGRfMjIYFiABKAESFwoPZG91YmxlX2ZpZWxkXzY5GEUgASgBEhcK", + "D2RvdWJsZV9maWVsZF83MBhGIAEoARIXCg9kb3VibGVfZmllbGRfNzEYRyAB", + "KAESFwoPZG91YmxlX2ZpZWxkXzcyGEggASgBEhcKD2RvdWJsZV9maWVsZF8y", + "NRgZIAEoARIWCg5pbnQ2NF9maWVsZF8yNhgaIAEoAxIXCg9kb3VibGVfZmll", + "bGRfNjgYRCABKAESFwoPZG91YmxlX2ZpZWxkXzI4GBwgASgBEhgKEGRvdWJs", + "ZV9maWVsZF8xMDYYaiABKAESFwoPZG91YmxlX2ZpZWxkXzI5GB0gASgBEhcK", + "D2RvdWJsZV9maWVsZF8zMBgeIAEoARIYChBkb3VibGVfZmllbGRfMTAxGGUg", + "ASgBEhgKEGRvdWJsZV9maWVsZF8xMDIYZiABKAESGAoQZG91YmxlX2ZpZWxk", + "XzEwMxhnIAEoARIYChBkb3VibGVfZmllbGRfMTA0GGggASgBEhgKEGRvdWJs", + "ZV9maWVsZF8xMDUYaSABKAESFwoPZG91YmxlX2ZpZWxkXzMxGB8gASgBEhYK", + "DmludDY0X2ZpZWxkXzMyGCAgASgDEhcKD2RvdWJsZV9maWVsZF83NRhLIAEo", + "ARIZChBkb3VibGVfZmllbGRfMTI5GIEBIAEoARIVCg1lbnVtX2ZpZWxkXzgw", + "GFAgASgFEhUKDWVudW1fZmllbGRfODEYUSABKAUSFgoOaW50NjRfZmllbGRf", + "ODIYUiABKAMSFQoNZW51bV9maWVsZF84MxhTIAEoBRIWCg5pbnQ2NF9maWVs", + "ZF84NRhVIAEoAxIWCg5pbnQ2NF9maWVsZF84NhhWIAEoAxIWCg5pbnQ2NF9m", + "aWVsZF84NxhXIAEoAxIXCg9pbnQ2NF9maWVsZF8xMjUYfSABKAMSFgoOaW50", + "NjRfZmllbGRfMzcYJSABKAMSFwoPZG91YmxlX2ZpZWxkXzM4GCYgASgBEhQK", + "DGludGVyYWN0aW9ucxgnIAEoAxIeChZyZXBlYXRlZF9pbnRfZmllbGRfMTAw", + "GGQgAygFEhcKD2RvdWJsZV9maWVsZF80MBgoIAEoARIWCg5pbnQ2NF9maWVs", + "ZF80MRgpIAEoAxIXCg9pbnQ2NF9maWVsZF8xMjYYfiABKAMSFwoPaW50NjRf", + "ZmllbGRfMTI3GH8gASgDEhkKEGRvdWJsZV9maWVsZF8xMjgYgAEgASgBEhgK", + "EGRvdWJsZV9maWVsZF8xMDkYbSABKAESFwoPaW50NjRfZmllbGRfMTEwGG4g", + "ASgDEhgKEGRvdWJsZV9maWVsZF8xMTEYbyABKAESFwoPaW50NjRfZmllbGRf", + "MTEyGHAgASgDEhgKEGRvdWJsZV9maWVsZF8xMTMYcSABKAESFwoPaW50NjRf", + "ZmllbGRfMTE0GHIgASgDEhcKD2RvdWJsZV9maWVsZF80MhgqIAEoARIWCg5p", + "bnQ2NF9maWVsZF80MxgrIAEoAxIWCg5pbnQ2NF9maWVsZF80NBgsIAEoAxIX", + "Cg9kb3VibGVfZmllbGRfNDUYLSABKAESFwoPZG91YmxlX2ZpZWxkXzQ2GC4g", + "ASgBEhcKD2RvdWJsZV9maWVsZF83OBhOIAEoARIXCg9kb3VibGVfZmllbGRf", + "ODgYWCABKAESFwoPZG91YmxlX2ZpZWxkXzQ3GC8gASgBEhcKD2RvdWJsZV9m", + "aWVsZF84ORhZIAEoARIXCg9kb3VibGVfZmllbGRfNDgYMCABKAESFwoPZG91", + "YmxlX2ZpZWxkXzQ5GDEgASgBEhcKD2RvdWJsZV9maWVsZF81MBgyIAEoARIX", + "Cg9kb3VibGVfZmllbGRfOTAYWiABKAESFwoPZG91YmxlX2ZpZWxkXzUxGDMg", + "ASgBEhcKD2RvdWJsZV9maWVsZF85MRhbIAEoARIXCg9kb3VibGVfZmllbGRf", + "OTIYXCABKAESFwoPaW50NjRfZmllbGRfMTA3GGsgASgDEhcKD2RvdWJsZV9m", + "aWVsZF85MxhdIAEoARIYChBkb3VibGVfZmllbGRfMTA4GGwgASgBEhcKD2Rv", + "dWJsZV9maWVsZF81Mhg0IAEoARIXCg9kb3VibGVfZmllbGRfNTMYNSABKAES", + "FwoPZG91YmxlX2ZpZWxkXzk0GF4gASgBEhcKD2RvdWJsZV9maWVsZF81NBg2", + "IAEoARIXCg9kb3VibGVfZmllbGRfNTUYNyABKAESFwoPZG91YmxlX2ZpZWxk", + "XzU2GDggASgBEhcKD2RvdWJsZV9maWVsZF81Nxg5IAEoARIXCg9kb3VibGVf", + "ZmllbGRfNTgYOiABKAESFgoOaW50NjRfZmllbGRfNTkYOyABKAMSFgoOaW50", + "NjRfZmllbGRfNjAYPCABKANiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Benchmarks.ManyWrapperFieldsMessage), global::Google.Protobuf.Benchmarks.ManyWrapperFieldsMessage.Parser, new[]{ "DoubleField95", "DoubleField1", "DoubleField79", "Int64Field2", "DoubleField96", "Int64Field3", "Int64Field4", "DoubleField97", "DoubleField65", "DoubleField66", "DoubleField7", "DoubleField62", "DoubleField118", "DoubleField119", "DoubleField67", "DoubleField120", "DoubleField121", "DoubleField122", "DoubleField123", "DoubleField124", "DoubleField8", "DoubleField9", "DoubleField98", "DoubleField10", "DoubleField11", "DoubleField99", "DoubleField84", "DoubleField14", "DoubleField77", "DoubleField15", "Int64Field19", "Int64Field115", "DoubleField116", "Int64Field117", "DoubleField20", "DoubleField21", "StringField73", "StringField74", "DoubleField22", "DoubleField69", "DoubleField70", "DoubleField71", "DoubleField72", "DoubleField25", "Int64Field26", "DoubleField68", "DoubleField28", "DoubleField106", "DoubleField29", "DoubleField30", "DoubleField101", "DoubleField102", "DoubleField103", "DoubleField104", "DoubleField105", "DoubleField31", "Int64Field32", "DoubleField75", "DoubleField129", "EnumField80", "EnumField81", "Int64Field82", "EnumField83", "Int64Field85", "Int64Field86", "Int64Field87", "Int64Field125", "Int64Field37", "DoubleField38", "Interactions", "RepeatedIntField100", "DoubleField40", "Int64Field41", "Int64Field126", "Int64Field127", "DoubleField128", "DoubleField109", "Int64Field110", "DoubleField111", "Int64Field112", "DoubleField113", "Int64Field114", "DoubleField42", "Int64Field43", "Int64Field44", "DoubleField45", "DoubleField46", "DoubleField78", "DoubleField88", "DoubleField47", "DoubleField89", "DoubleField48", "DoubleField49", "DoubleField50", "DoubleField90", "DoubleField51", "DoubleField91", "DoubleField92", "Int64Field107", "DoubleField93", "DoubleField108", "DoubleField52", "DoubleField53", "DoubleField94", "DoubleField54", "DoubleField55", "DoubleField56", "DoubleField57", "DoubleField58", "Int64Field59", "Int64Field60" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Benchmarks.ManyPrimitiveFieldsMessage), global::Google.Protobuf.Benchmarks.ManyPrimitiveFieldsMessage.Parser, new[]{ "DoubleField95", "DoubleField1", "DoubleField79", "Int64Field2", "DoubleField96", "Int64Field3", "Int64Field4", "DoubleField97", "DoubleField65", "DoubleField66", "DoubleField7", "DoubleField62", "DoubleField118", "DoubleField119", "DoubleField67", "DoubleField120", "DoubleField121", "DoubleField122", "DoubleField123", "DoubleField124", "DoubleField8", "DoubleField9", "DoubleField98", "DoubleField10", "DoubleField11", "DoubleField99", "DoubleField84", "DoubleField14", "DoubleField77", "DoubleField15", "Int64Field19", "Int64Field115", "DoubleField116", "Int64Field117", "DoubleField20", "DoubleField21", "StringField73", "StringField74", "DoubleField22", "DoubleField69", "DoubleField70", "DoubleField71", "DoubleField72", "DoubleField25", "Int64Field26", "DoubleField68", "DoubleField28", "DoubleField106", "DoubleField29", "DoubleField30", "DoubleField101", "DoubleField102", "DoubleField103", "DoubleField104", "DoubleField105", "DoubleField31", "Int64Field32", "DoubleField75", "DoubleField129", "EnumField80", "EnumField81", "Int64Field82", "EnumField83", "Int64Field85", "Int64Field86", "Int64Field87", "Int64Field125", "Int64Field37", "DoubleField38", "Interactions", "RepeatedIntField100", "DoubleField40", "Int64Field41", "Int64Field126", "Int64Field127", "DoubleField128", "DoubleField109", "Int64Field110", "DoubleField111", "Int64Field112", "DoubleField113", "Int64Field114", "DoubleField42", "Int64Field43", "Int64Field44", "DoubleField45", "DoubleField46", "DoubleField78", "DoubleField88", "DoubleField47", "DoubleField89", "DoubleField48", "DoubleField49", "DoubleField50", "DoubleField90", "DoubleField51", "DoubleField91", "DoubleField92", "Int64Field107", "DoubleField93", "DoubleField108", "DoubleField52", "DoubleField53", "DoubleField94", "DoubleField54", "DoubleField55", "DoubleField56", "DoubleField57", "DoubleField58", "Int64Field59", "Int64Field60" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + /// a message that has a large number of wrapper fields + /// obfuscated version of an internal message + /// + public sealed partial class ManyWrapperFieldsMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ManyWrapperFieldsMessage()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Benchmarks.WrapperBenchmarkMessagesReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyWrapperFieldsMessage() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyWrapperFieldsMessage(ManyWrapperFieldsMessage other) : this() { + DoubleField95 = other.DoubleField95; + DoubleField1 = other.DoubleField1; + DoubleField79 = other.DoubleField79; + Int64Field2 = other.Int64Field2; + DoubleField96 = other.DoubleField96; + Int64Field3 = other.Int64Field3; + Int64Field4 = other.Int64Field4; + DoubleField97 = other.DoubleField97; + DoubleField65 = other.DoubleField65; + DoubleField66 = other.DoubleField66; + DoubleField7 = other.DoubleField7; + DoubleField62 = other.DoubleField62; + DoubleField118 = other.DoubleField118; + DoubleField119 = other.DoubleField119; + DoubleField67 = other.DoubleField67; + DoubleField120 = other.DoubleField120; + DoubleField121 = other.DoubleField121; + DoubleField122 = other.DoubleField122; + DoubleField123 = other.DoubleField123; + DoubleField124 = other.DoubleField124; + DoubleField8 = other.DoubleField8; + DoubleField9 = other.DoubleField9; + DoubleField98 = other.DoubleField98; + DoubleField10 = other.DoubleField10; + DoubleField11 = other.DoubleField11; + DoubleField99 = other.DoubleField99; + DoubleField84 = other.DoubleField84; + DoubleField14 = other.DoubleField14; + DoubleField77 = other.DoubleField77; + DoubleField15 = other.DoubleField15; + Int64Field19 = other.Int64Field19; + Int64Field115 = other.Int64Field115; + DoubleField116 = other.DoubleField116; + Int64Field117 = other.Int64Field117; + DoubleField20 = other.DoubleField20; + DoubleField21 = other.DoubleField21; + StringField73 = other.StringField73; + StringField74 = other.StringField74; + DoubleField22 = other.DoubleField22; + DoubleField69 = other.DoubleField69; + DoubleField70 = other.DoubleField70; + DoubleField71 = other.DoubleField71; + DoubleField72 = other.DoubleField72; + DoubleField25 = other.DoubleField25; + Int64Field26 = other.Int64Field26; + DoubleField68 = other.DoubleField68; + DoubleField28 = other.DoubleField28; + DoubleField106 = other.DoubleField106; + DoubleField29 = other.DoubleField29; + DoubleField30 = other.DoubleField30; + DoubleField101 = other.DoubleField101; + DoubleField102 = other.DoubleField102; + DoubleField103 = other.DoubleField103; + DoubleField104 = other.DoubleField104; + DoubleField105 = other.DoubleField105; + DoubleField31 = other.DoubleField31; + Int64Field32 = other.Int64Field32; + DoubleField75 = other.DoubleField75; + DoubleField129 = other.DoubleField129; + enumField80_ = other.enumField80_; + enumField81_ = other.enumField81_; + Int64Field82 = other.Int64Field82; + enumField83_ = other.enumField83_; + Int64Field85 = other.Int64Field85; + Int64Field86 = other.Int64Field86; + Int64Field87 = other.Int64Field87; + Int64Field125 = other.Int64Field125; + Int64Field37 = other.Int64Field37; + DoubleField38 = other.DoubleField38; + Interactions = other.Interactions; + repeatedIntField100_ = other.repeatedIntField100_.Clone(); + DoubleField40 = other.DoubleField40; + Int64Field41 = other.Int64Field41; + Int64Field126 = other.Int64Field126; + Int64Field127 = other.Int64Field127; + DoubleField128 = other.DoubleField128; + DoubleField109 = other.DoubleField109; + Int64Field110 = other.Int64Field110; + DoubleField111 = other.DoubleField111; + Int64Field112 = other.Int64Field112; + DoubleField113 = other.DoubleField113; + Int64Field114 = other.Int64Field114; + DoubleField42 = other.DoubleField42; + Int64Field43 = other.Int64Field43; + Int64Field44 = other.Int64Field44; + DoubleField45 = other.DoubleField45; + DoubleField46 = other.DoubleField46; + DoubleField78 = other.DoubleField78; + DoubleField88 = other.DoubleField88; + DoubleField47 = other.DoubleField47; + DoubleField89 = other.DoubleField89; + DoubleField48 = other.DoubleField48; + DoubleField49 = other.DoubleField49; + DoubleField50 = other.DoubleField50; + DoubleField90 = other.DoubleField90; + DoubleField51 = other.DoubleField51; + DoubleField91 = other.DoubleField91; + DoubleField92 = other.DoubleField92; + Int64Field107 = other.Int64Field107; + DoubleField93 = other.DoubleField93; + DoubleField108 = other.DoubleField108; + DoubleField52 = other.DoubleField52; + DoubleField53 = other.DoubleField53; + DoubleField94 = other.DoubleField94; + DoubleField54 = other.DoubleField54; + DoubleField55 = other.DoubleField55; + DoubleField56 = other.DoubleField56; + DoubleField57 = other.DoubleField57; + DoubleField58 = other.DoubleField58; + Int64Field59 = other.Int64Field59; + Int64Field60 = other.Int64Field60; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyWrapperFieldsMessage Clone() { + return new ManyWrapperFieldsMessage(this); + } + + /// Field number for the "double_field_95" field. + public const int DoubleField95FieldNumber = 95; + private static readonly pb::FieldCodec _single_doubleField95_codec = pb::FieldCodec.ForStructWrapper(762); + private double? doubleField95_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField95 { + get { return doubleField95_; } + set { + doubleField95_ = value; + } + } + + + /// Field number for the "double_field_1" field. + public const int DoubleField1FieldNumber = 1; + private static readonly pb::FieldCodec _single_doubleField1_codec = pb::FieldCodec.ForStructWrapper(10); + private double? doubleField1_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField1 { + get { return doubleField1_; } + set { + doubleField1_ = value; + } + } + + + /// Field number for the "double_field_79" field. + public const int DoubleField79FieldNumber = 79; + private static readonly pb::FieldCodec _single_doubleField79_codec = pb::FieldCodec.ForStructWrapper(634); + private double? doubleField79_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField79 { + get { return doubleField79_; } + set { + doubleField79_ = value; + } + } + + + /// Field number for the "int64_field_2" field. + public const int Int64Field2FieldNumber = 2; + private static readonly pb::FieldCodec _single_int64Field2_codec = pb::FieldCodec.ForStructWrapper(18); + private long? int64Field2_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field2 { + get { return int64Field2_; } + set { + int64Field2_ = value; + } + } + + + /// Field number for the "double_field_96" field. + public const int DoubleField96FieldNumber = 96; + private static readonly pb::FieldCodec _single_doubleField96_codec = pb::FieldCodec.ForStructWrapper(770); + private double? doubleField96_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField96 { + get { return doubleField96_; } + set { + doubleField96_ = value; + } + } + + + /// Field number for the "int64_field_3" field. + public const int Int64Field3FieldNumber = 3; + private static readonly pb::FieldCodec _single_int64Field3_codec = pb::FieldCodec.ForStructWrapper(26); + private long? int64Field3_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field3 { + get { return int64Field3_; } + set { + int64Field3_ = value; + } + } + + + /// Field number for the "int64_field_4" field. + public const int Int64Field4FieldNumber = 4; + private static readonly pb::FieldCodec _single_int64Field4_codec = pb::FieldCodec.ForStructWrapper(34); + private long? int64Field4_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field4 { + get { return int64Field4_; } + set { + int64Field4_ = value; + } + } + + + /// Field number for the "double_field_97" field. + public const int DoubleField97FieldNumber = 97; + private static readonly pb::FieldCodec _single_doubleField97_codec = pb::FieldCodec.ForStructWrapper(778); + private double? doubleField97_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField97 { + get { return doubleField97_; } + set { + doubleField97_ = value; + } + } + + + /// Field number for the "double_field_65" field. + public const int DoubleField65FieldNumber = 65; + private static readonly pb::FieldCodec _single_doubleField65_codec = pb::FieldCodec.ForStructWrapper(522); + private double? doubleField65_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField65 { + get { return doubleField65_; } + set { + doubleField65_ = value; + } + } + + + /// Field number for the "double_field_66" field. + public const int DoubleField66FieldNumber = 66; + private static readonly pb::FieldCodec _single_doubleField66_codec = pb::FieldCodec.ForStructWrapper(530); + private double? doubleField66_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField66 { + get { return doubleField66_; } + set { + doubleField66_ = value; + } + } + + + /// Field number for the "double_field_7" field. + public const int DoubleField7FieldNumber = 7; + private static readonly pb::FieldCodec _single_doubleField7_codec = pb::FieldCodec.ForStructWrapper(58); + private double? doubleField7_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField7 { + get { return doubleField7_; } + set { + doubleField7_ = value; + } + } + + + /// Field number for the "double_field_62" field. + public const int DoubleField62FieldNumber = 62; + private static readonly pb::FieldCodec _single_doubleField62_codec = pb::FieldCodec.ForStructWrapper(498); + private double? doubleField62_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField62 { + get { return doubleField62_; } + set { + doubleField62_ = value; + } + } + + + /// Field number for the "double_field_118" field. + public const int DoubleField118FieldNumber = 118; + private static readonly pb::FieldCodec _single_doubleField118_codec = pb::FieldCodec.ForStructWrapper(946); + private double? doubleField118_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField118 { + get { return doubleField118_; } + set { + doubleField118_ = value; + } + } + + + /// Field number for the "double_field_119" field. + public const int DoubleField119FieldNumber = 119; + private static readonly pb::FieldCodec _single_doubleField119_codec = pb::FieldCodec.ForStructWrapper(954); + private double? doubleField119_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField119 { + get { return doubleField119_; } + set { + doubleField119_ = value; + } + } + + + /// Field number for the "double_field_67" field. + public const int DoubleField67FieldNumber = 67; + private static readonly pb::FieldCodec _single_doubleField67_codec = pb::FieldCodec.ForStructWrapper(538); + private double? doubleField67_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField67 { + get { return doubleField67_; } + set { + doubleField67_ = value; + } + } + + + /// Field number for the "double_field_120" field. + public const int DoubleField120FieldNumber = 120; + private static readonly pb::FieldCodec _single_doubleField120_codec = pb::FieldCodec.ForStructWrapper(962); + private double? doubleField120_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField120 { + get { return doubleField120_; } + set { + doubleField120_ = value; + } + } + + + /// Field number for the "double_field_121" field. + public const int DoubleField121FieldNumber = 121; + private static readonly pb::FieldCodec _single_doubleField121_codec = pb::FieldCodec.ForStructWrapper(970); + private double? doubleField121_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField121 { + get { return doubleField121_; } + set { + doubleField121_ = value; + } + } + + + /// Field number for the "double_field_122" field. + public const int DoubleField122FieldNumber = 122; + private static readonly pb::FieldCodec _single_doubleField122_codec = pb::FieldCodec.ForStructWrapper(978); + private double? doubleField122_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField122 { + get { return doubleField122_; } + set { + doubleField122_ = value; + } + } + + + /// Field number for the "double_field_123" field. + public const int DoubleField123FieldNumber = 123; + private static readonly pb::FieldCodec _single_doubleField123_codec = pb::FieldCodec.ForStructWrapper(986); + private double? doubleField123_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField123 { + get { return doubleField123_; } + set { + doubleField123_ = value; + } + } + + + /// Field number for the "double_field_124" field. + public const int DoubleField124FieldNumber = 124; + private static readonly pb::FieldCodec _single_doubleField124_codec = pb::FieldCodec.ForStructWrapper(994); + private double? doubleField124_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField124 { + get { return doubleField124_; } + set { + doubleField124_ = value; + } + } + + + /// Field number for the "double_field_8" field. + public const int DoubleField8FieldNumber = 8; + private static readonly pb::FieldCodec _single_doubleField8_codec = pb::FieldCodec.ForStructWrapper(66); + private double? doubleField8_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField8 { + get { return doubleField8_; } + set { + doubleField8_ = value; + } + } + + + /// Field number for the "double_field_9" field. + public const int DoubleField9FieldNumber = 9; + private static readonly pb::FieldCodec _single_doubleField9_codec = pb::FieldCodec.ForStructWrapper(74); + private double? doubleField9_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField9 { + get { return doubleField9_; } + set { + doubleField9_ = value; + } + } + + + /// Field number for the "double_field_98" field. + public const int DoubleField98FieldNumber = 98; + private static readonly pb::FieldCodec _single_doubleField98_codec = pb::FieldCodec.ForStructWrapper(786); + private double? doubleField98_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField98 { + get { return doubleField98_; } + set { + doubleField98_ = value; + } + } + + + /// Field number for the "double_field_10" field. + public const int DoubleField10FieldNumber = 10; + private static readonly pb::FieldCodec _single_doubleField10_codec = pb::FieldCodec.ForStructWrapper(82); + private double? doubleField10_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField10 { + get { return doubleField10_; } + set { + doubleField10_ = value; + } + } + + + /// Field number for the "double_field_11" field. + public const int DoubleField11FieldNumber = 11; + private static readonly pb::FieldCodec _single_doubleField11_codec = pb::FieldCodec.ForStructWrapper(90); + private double? doubleField11_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField11 { + get { return doubleField11_; } + set { + doubleField11_ = value; + } + } + + + /// Field number for the "double_field_99" field. + public const int DoubleField99FieldNumber = 99; + private static readonly pb::FieldCodec _single_doubleField99_codec = pb::FieldCodec.ForStructWrapper(794); + private double? doubleField99_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField99 { + get { return doubleField99_; } + set { + doubleField99_ = value; + } + } + + + /// Field number for the "double_field_84" field. + public const int DoubleField84FieldNumber = 84; + private static readonly pb::FieldCodec _single_doubleField84_codec = pb::FieldCodec.ForStructWrapper(674); + private double? doubleField84_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField84 { + get { return doubleField84_; } + set { + doubleField84_ = value; + } + } + + + /// Field number for the "double_field_14" field. + public const int DoubleField14FieldNumber = 14; + private static readonly pb::FieldCodec _single_doubleField14_codec = pb::FieldCodec.ForStructWrapper(114); + private double? doubleField14_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField14 { + get { return doubleField14_; } + set { + doubleField14_ = value; + } + } + + + /// Field number for the "double_field_77" field. + public const int DoubleField77FieldNumber = 77; + private static readonly pb::FieldCodec _single_doubleField77_codec = pb::FieldCodec.ForStructWrapper(618); + private double? doubleField77_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField77 { + get { return doubleField77_; } + set { + doubleField77_ = value; + } + } + + + /// Field number for the "double_field_15" field. + public const int DoubleField15FieldNumber = 15; + private static readonly pb::FieldCodec _single_doubleField15_codec = pb::FieldCodec.ForStructWrapper(122); + private double? doubleField15_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField15 { + get { return doubleField15_; } + set { + doubleField15_ = value; + } + } + + + /// Field number for the "int64_field_19" field. + public const int Int64Field19FieldNumber = 19; + private static readonly pb::FieldCodec _single_int64Field19_codec = pb::FieldCodec.ForStructWrapper(154); + private long? int64Field19_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field19 { + get { return int64Field19_; } + set { + int64Field19_ = value; + } + } + + + /// Field number for the "int64_field_115" field. + public const int Int64Field115FieldNumber = 115; + private static readonly pb::FieldCodec _single_int64Field115_codec = pb::FieldCodec.ForStructWrapper(922); + private long? int64Field115_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field115 { + get { return int64Field115_; } + set { + int64Field115_ = value; + } + } + + + /// Field number for the "double_field_116" field. + public const int DoubleField116FieldNumber = 116; + private static readonly pb::FieldCodec _single_doubleField116_codec = pb::FieldCodec.ForStructWrapper(930); + private double? doubleField116_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField116 { + get { return doubleField116_; } + set { + doubleField116_ = value; + } + } + + + /// Field number for the "int64_field_117" field. + public const int Int64Field117FieldNumber = 117; + private static readonly pb::FieldCodec _single_int64Field117_codec = pb::FieldCodec.ForStructWrapper(938); + private long? int64Field117_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field117 { + get { return int64Field117_; } + set { + int64Field117_ = value; + } + } + + + /// Field number for the "double_field_20" field. + public const int DoubleField20FieldNumber = 20; + private static readonly pb::FieldCodec _single_doubleField20_codec = pb::FieldCodec.ForStructWrapper(162); + private double? doubleField20_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField20 { + get { return doubleField20_; } + set { + doubleField20_ = value; + } + } + + + /// Field number for the "double_field_21" field. + public const int DoubleField21FieldNumber = 21; + private static readonly pb::FieldCodec _single_doubleField21_codec = pb::FieldCodec.ForStructWrapper(170); + private double? doubleField21_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField21 { + get { return doubleField21_; } + set { + doubleField21_ = value; + } + } + + + /// Field number for the "string_field_73" field. + public const int StringField73FieldNumber = 73; + private static readonly pb::FieldCodec _single_stringField73_codec = pb::FieldCodec.ForClassWrapper(586); + private string stringField73_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string StringField73 { + get { return stringField73_; } + set { + stringField73_ = value; + } + } + + + /// Field number for the "string_field_74" field. + public const int StringField74FieldNumber = 74; + private static readonly pb::FieldCodec _single_stringField74_codec = pb::FieldCodec.ForClassWrapper(594); + private string stringField74_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string StringField74 { + get { return stringField74_; } + set { + stringField74_ = value; + } + } + + + /// Field number for the "double_field_22" field. + public const int DoubleField22FieldNumber = 22; + private static readonly pb::FieldCodec _single_doubleField22_codec = pb::FieldCodec.ForStructWrapper(178); + private double? doubleField22_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField22 { + get { return doubleField22_; } + set { + doubleField22_ = value; + } + } + + + /// Field number for the "double_field_69" field. + public const int DoubleField69FieldNumber = 69; + private static readonly pb::FieldCodec _single_doubleField69_codec = pb::FieldCodec.ForStructWrapper(554); + private double? doubleField69_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField69 { + get { return doubleField69_; } + set { + doubleField69_ = value; + } + } + + + /// Field number for the "double_field_70" field. + public const int DoubleField70FieldNumber = 70; + private static readonly pb::FieldCodec _single_doubleField70_codec = pb::FieldCodec.ForStructWrapper(562); + private double? doubleField70_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField70 { + get { return doubleField70_; } + set { + doubleField70_ = value; + } + } + + + /// Field number for the "double_field_71" field. + public const int DoubleField71FieldNumber = 71; + private static readonly pb::FieldCodec _single_doubleField71_codec = pb::FieldCodec.ForStructWrapper(570); + private double? doubleField71_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField71 { + get { return doubleField71_; } + set { + doubleField71_ = value; + } + } + + + /// Field number for the "double_field_72" field. + public const int DoubleField72FieldNumber = 72; + private static readonly pb::FieldCodec _single_doubleField72_codec = pb::FieldCodec.ForStructWrapper(578); + private double? doubleField72_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField72 { + get { return doubleField72_; } + set { + doubleField72_ = value; + } + } + + + /// Field number for the "double_field_25" field. + public const int DoubleField25FieldNumber = 25; + private static readonly pb::FieldCodec _single_doubleField25_codec = pb::FieldCodec.ForStructWrapper(202); + private double? doubleField25_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField25 { + get { return doubleField25_; } + set { + doubleField25_ = value; + } + } + + + /// Field number for the "int64_field_26" field. + public const int Int64Field26FieldNumber = 26; + private static readonly pb::FieldCodec _single_int64Field26_codec = pb::FieldCodec.ForStructWrapper(210); + private long? int64Field26_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field26 { + get { return int64Field26_; } + set { + int64Field26_ = value; + } + } + + + /// Field number for the "double_field_68" field. + public const int DoubleField68FieldNumber = 68; + private static readonly pb::FieldCodec _single_doubleField68_codec = pb::FieldCodec.ForStructWrapper(546); + private double? doubleField68_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField68 { + get { return doubleField68_; } + set { + doubleField68_ = value; + } + } + + + /// Field number for the "double_field_28" field. + public const int DoubleField28FieldNumber = 28; + private static readonly pb::FieldCodec _single_doubleField28_codec = pb::FieldCodec.ForStructWrapper(226); + private double? doubleField28_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField28 { + get { return doubleField28_; } + set { + doubleField28_ = value; + } + } + + + /// Field number for the "double_field_106" field. + public const int DoubleField106FieldNumber = 106; + private static readonly pb::FieldCodec _single_doubleField106_codec = pb::FieldCodec.ForStructWrapper(850); + private double? doubleField106_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField106 { + get { return doubleField106_; } + set { + doubleField106_ = value; + } + } + + + /// Field number for the "double_field_29" field. + public const int DoubleField29FieldNumber = 29; + private static readonly pb::FieldCodec _single_doubleField29_codec = pb::FieldCodec.ForStructWrapper(234); + private double? doubleField29_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField29 { + get { return doubleField29_; } + set { + doubleField29_ = value; + } + } + + + /// Field number for the "double_field_30" field. + public const int DoubleField30FieldNumber = 30; + private static readonly pb::FieldCodec _single_doubleField30_codec = pb::FieldCodec.ForStructWrapper(242); + private double? doubleField30_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField30 { + get { return doubleField30_; } + set { + doubleField30_ = value; + } + } + + + /// Field number for the "double_field_101" field. + public const int DoubleField101FieldNumber = 101; + private static readonly pb::FieldCodec _single_doubleField101_codec = pb::FieldCodec.ForStructWrapper(810); + private double? doubleField101_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField101 { + get { return doubleField101_; } + set { + doubleField101_ = value; + } + } + + + /// Field number for the "double_field_102" field. + public const int DoubleField102FieldNumber = 102; + private static readonly pb::FieldCodec _single_doubleField102_codec = pb::FieldCodec.ForStructWrapper(818); + private double? doubleField102_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField102 { + get { return doubleField102_; } + set { + doubleField102_ = value; + } + } + + + /// Field number for the "double_field_103" field. + public const int DoubleField103FieldNumber = 103; + private static readonly pb::FieldCodec _single_doubleField103_codec = pb::FieldCodec.ForStructWrapper(826); + private double? doubleField103_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField103 { + get { return doubleField103_; } + set { + doubleField103_ = value; + } + } + + + /// Field number for the "double_field_104" field. + public const int DoubleField104FieldNumber = 104; + private static readonly pb::FieldCodec _single_doubleField104_codec = pb::FieldCodec.ForStructWrapper(834); + private double? doubleField104_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField104 { + get { return doubleField104_; } + set { + doubleField104_ = value; + } + } + + + /// Field number for the "double_field_105" field. + public const int DoubleField105FieldNumber = 105; + private static readonly pb::FieldCodec _single_doubleField105_codec = pb::FieldCodec.ForStructWrapper(842); + private double? doubleField105_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField105 { + get { return doubleField105_; } + set { + doubleField105_ = value; + } + } + + + /// Field number for the "double_field_31" field. + public const int DoubleField31FieldNumber = 31; + private static readonly pb::FieldCodec _single_doubleField31_codec = pb::FieldCodec.ForStructWrapper(250); + private double? doubleField31_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField31 { + get { return doubleField31_; } + set { + doubleField31_ = value; + } + } + + + /// Field number for the "int64_field_32" field. + public const int Int64Field32FieldNumber = 32; + private static readonly pb::FieldCodec _single_int64Field32_codec = pb::FieldCodec.ForStructWrapper(258); + private long? int64Field32_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field32 { + get { return int64Field32_; } + set { + int64Field32_ = value; + } + } + + + /// Field number for the "double_field_75" field. + public const int DoubleField75FieldNumber = 75; + private static readonly pb::FieldCodec _single_doubleField75_codec = pb::FieldCodec.ForStructWrapper(602); + private double? doubleField75_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField75 { + get { return doubleField75_; } + set { + doubleField75_ = value; + } + } + + + /// Field number for the "double_field_129" field. + public const int DoubleField129FieldNumber = 129; + private static readonly pb::FieldCodec _single_doubleField129_codec = pb::FieldCodec.ForStructWrapper(1034); + private double? doubleField129_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField129 { + get { return doubleField129_; } + set { + doubleField129_ = value; + } + } + + + /// Field number for the "enum_field_80" field. + public const int EnumField80FieldNumber = 80; + private int enumField80_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField80 { + get { return enumField80_; } + set { + enumField80_ = value; + } + } + + /// Field number for the "enum_field_81" field. + public const int EnumField81FieldNumber = 81; + private int enumField81_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField81 { + get { return enumField81_; } + set { + enumField81_ = value; + } + } + + /// Field number for the "int64_field_82" field. + public const int Int64Field82FieldNumber = 82; + private static readonly pb::FieldCodec _single_int64Field82_codec = pb::FieldCodec.ForStructWrapper(658); + private long? int64Field82_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field82 { + get { return int64Field82_; } + set { + int64Field82_ = value; + } + } + + + /// Field number for the "enum_field_83" field. + public const int EnumField83FieldNumber = 83; + private int enumField83_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField83 { + get { return enumField83_; } + set { + enumField83_ = value; + } + } + + /// Field number for the "int64_field_85" field. + public const int Int64Field85FieldNumber = 85; + private static readonly pb::FieldCodec _single_int64Field85_codec = pb::FieldCodec.ForStructWrapper(682); + private long? int64Field85_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field85 { + get { return int64Field85_; } + set { + int64Field85_ = value; + } + } + + + /// Field number for the "int64_field_86" field. + public const int Int64Field86FieldNumber = 86; + private static readonly pb::FieldCodec _single_int64Field86_codec = pb::FieldCodec.ForStructWrapper(690); + private long? int64Field86_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field86 { + get { return int64Field86_; } + set { + int64Field86_ = value; + } + } + + + /// Field number for the "int64_field_87" field. + public const int Int64Field87FieldNumber = 87; + private static readonly pb::FieldCodec _single_int64Field87_codec = pb::FieldCodec.ForStructWrapper(698); + private long? int64Field87_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field87 { + get { return int64Field87_; } + set { + int64Field87_ = value; + } + } + + + /// Field number for the "int64_field_125" field. + public const int Int64Field125FieldNumber = 125; + private static readonly pb::FieldCodec _single_int64Field125_codec = pb::FieldCodec.ForStructWrapper(1002); + private long? int64Field125_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field125 { + get { return int64Field125_; } + set { + int64Field125_ = value; + } + } + + + /// Field number for the "int64_field_37" field. + public const int Int64Field37FieldNumber = 37; + private static readonly pb::FieldCodec _single_int64Field37_codec = pb::FieldCodec.ForStructWrapper(298); + private long? int64Field37_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field37 { + get { return int64Field37_; } + set { + int64Field37_ = value; + } + } + + + /// Field number for the "double_field_38" field. + public const int DoubleField38FieldNumber = 38; + private static readonly pb::FieldCodec _single_doubleField38_codec = pb::FieldCodec.ForStructWrapper(306); + private double? doubleField38_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField38 { + get { return doubleField38_; } + set { + doubleField38_ = value; + } + } + + + /// Field number for the "interactions" field. + public const int InteractionsFieldNumber = 39; + private static readonly pb::FieldCodec _single_interactions_codec = pb::FieldCodec.ForStructWrapper(314); + private long? interactions_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Interactions { + get { return interactions_; } + set { + interactions_ = value; + } + } + + + /// Field number for the "repeated_int_field_100" field. + public const int RepeatedIntField100FieldNumber = 100; + private static readonly pb::FieldCodec _repeated_repeatedIntField100_codec + = pb::FieldCodec.ForInt32(802); + private readonly pbc::RepeatedField repeatedIntField100_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField RepeatedIntField100 { + get { return repeatedIntField100_; } + } + + /// Field number for the "double_field_40" field. + public const int DoubleField40FieldNumber = 40; + private static readonly pb::FieldCodec _single_doubleField40_codec = pb::FieldCodec.ForStructWrapper(322); + private double? doubleField40_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField40 { + get { return doubleField40_; } + set { + doubleField40_ = value; + } + } + + + /// Field number for the "int64_field_41" field. + public const int Int64Field41FieldNumber = 41; + private static readonly pb::FieldCodec _single_int64Field41_codec = pb::FieldCodec.ForStructWrapper(330); + private long? int64Field41_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field41 { + get { return int64Field41_; } + set { + int64Field41_ = value; + } + } + + + /// Field number for the "int64_field_126" field. + public const int Int64Field126FieldNumber = 126; + private static readonly pb::FieldCodec _single_int64Field126_codec = pb::FieldCodec.ForStructWrapper(1010); + private long? int64Field126_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field126 { + get { return int64Field126_; } + set { + int64Field126_ = value; + } + } + + + /// Field number for the "int64_field_127" field. + public const int Int64Field127FieldNumber = 127; + private static readonly pb::FieldCodec _single_int64Field127_codec = pb::FieldCodec.ForStructWrapper(1018); + private long? int64Field127_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field127 { + get { return int64Field127_; } + set { + int64Field127_ = value; + } + } + + + /// Field number for the "double_field_128" field. + public const int DoubleField128FieldNumber = 128; + private static readonly pb::FieldCodec _single_doubleField128_codec = pb::FieldCodec.ForStructWrapper(1026); + private double? doubleField128_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField128 { + get { return doubleField128_; } + set { + doubleField128_ = value; + } + } + + + /// Field number for the "double_field_109" field. + public const int DoubleField109FieldNumber = 109; + private static readonly pb::FieldCodec _single_doubleField109_codec = pb::FieldCodec.ForStructWrapper(874); + private double? doubleField109_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField109 { + get { return doubleField109_; } + set { + doubleField109_ = value; + } + } + + + /// Field number for the "int64_field_110" field. + public const int Int64Field110FieldNumber = 110; + private static readonly pb::FieldCodec _single_int64Field110_codec = pb::FieldCodec.ForStructWrapper(882); + private long? int64Field110_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field110 { + get { return int64Field110_; } + set { + int64Field110_ = value; + } + } + + + /// Field number for the "double_field_111" field. + public const int DoubleField111FieldNumber = 111; + private static readonly pb::FieldCodec _single_doubleField111_codec = pb::FieldCodec.ForStructWrapper(890); + private double? doubleField111_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField111 { + get { return doubleField111_; } + set { + doubleField111_ = value; + } + } + + + /// Field number for the "int64_field_112" field. + public const int Int64Field112FieldNumber = 112; + private static readonly pb::FieldCodec _single_int64Field112_codec = pb::FieldCodec.ForStructWrapper(898); + private long? int64Field112_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field112 { + get { return int64Field112_; } + set { + int64Field112_ = value; + } + } + + + /// Field number for the "double_field_113" field. + public const int DoubleField113FieldNumber = 113; + private static readonly pb::FieldCodec _single_doubleField113_codec = pb::FieldCodec.ForStructWrapper(906); + private double? doubleField113_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField113 { + get { return doubleField113_; } + set { + doubleField113_ = value; + } + } + + + /// Field number for the "int64_field_114" field. + public const int Int64Field114FieldNumber = 114; + private static readonly pb::FieldCodec _single_int64Field114_codec = pb::FieldCodec.ForStructWrapper(914); + private long? int64Field114_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field114 { + get { return int64Field114_; } + set { + int64Field114_ = value; + } + } + + + /// Field number for the "double_field_42" field. + public const int DoubleField42FieldNumber = 42; + private static readonly pb::FieldCodec _single_doubleField42_codec = pb::FieldCodec.ForStructWrapper(338); + private double? doubleField42_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField42 { + get { return doubleField42_; } + set { + doubleField42_ = value; + } + } + + + /// Field number for the "int64_field_43" field. + public const int Int64Field43FieldNumber = 43; + private static readonly pb::FieldCodec _single_int64Field43_codec = pb::FieldCodec.ForStructWrapper(346); + private long? int64Field43_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field43 { + get { return int64Field43_; } + set { + int64Field43_ = value; + } + } + + + /// Field number for the "int64_field_44" field. + public const int Int64Field44FieldNumber = 44; + private static readonly pb::FieldCodec _single_int64Field44_codec = pb::FieldCodec.ForStructWrapper(354); + private long? int64Field44_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field44 { + get { return int64Field44_; } + set { + int64Field44_ = value; + } + } + + + /// Field number for the "double_field_45" field. + public const int DoubleField45FieldNumber = 45; + private static readonly pb::FieldCodec _single_doubleField45_codec = pb::FieldCodec.ForStructWrapper(362); + private double? doubleField45_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField45 { + get { return doubleField45_; } + set { + doubleField45_ = value; + } + } + + + /// Field number for the "double_field_46" field. + public const int DoubleField46FieldNumber = 46; + private static readonly pb::FieldCodec _single_doubleField46_codec = pb::FieldCodec.ForStructWrapper(370); + private double? doubleField46_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField46 { + get { return doubleField46_; } + set { + doubleField46_ = value; + } + } + + + /// Field number for the "double_field_78" field. + public const int DoubleField78FieldNumber = 78; + private static readonly pb::FieldCodec _single_doubleField78_codec = pb::FieldCodec.ForStructWrapper(626); + private double? doubleField78_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField78 { + get { return doubleField78_; } + set { + doubleField78_ = value; + } + } + + + /// Field number for the "double_field_88" field. + public const int DoubleField88FieldNumber = 88; + private static readonly pb::FieldCodec _single_doubleField88_codec = pb::FieldCodec.ForStructWrapper(706); + private double? doubleField88_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField88 { + get { return doubleField88_; } + set { + doubleField88_ = value; + } + } + + + /// Field number for the "double_field_47" field. + public const int DoubleField47FieldNumber = 47; + private static readonly pb::FieldCodec _single_doubleField47_codec = pb::FieldCodec.ForStructWrapper(378); + private double? doubleField47_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField47 { + get { return doubleField47_; } + set { + doubleField47_ = value; + } + } + + + /// Field number for the "double_field_89" field. + public const int DoubleField89FieldNumber = 89; + private static readonly pb::FieldCodec _single_doubleField89_codec = pb::FieldCodec.ForStructWrapper(714); + private double? doubleField89_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField89 { + get { return doubleField89_; } + set { + doubleField89_ = value; + } + } + + + /// Field number for the "double_field_48" field. + public const int DoubleField48FieldNumber = 48; + private static readonly pb::FieldCodec _single_doubleField48_codec = pb::FieldCodec.ForStructWrapper(386); + private double? doubleField48_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField48 { + get { return doubleField48_; } + set { + doubleField48_ = value; + } + } + + + /// Field number for the "double_field_49" field. + public const int DoubleField49FieldNumber = 49; + private static readonly pb::FieldCodec _single_doubleField49_codec = pb::FieldCodec.ForStructWrapper(394); + private double? doubleField49_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField49 { + get { return doubleField49_; } + set { + doubleField49_ = value; + } + } + + + /// Field number for the "double_field_50" field. + public const int DoubleField50FieldNumber = 50; + private static readonly pb::FieldCodec _single_doubleField50_codec = pb::FieldCodec.ForStructWrapper(402); + private double? doubleField50_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField50 { + get { return doubleField50_; } + set { + doubleField50_ = value; + } + } + + + /// Field number for the "double_field_90" field. + public const int DoubleField90FieldNumber = 90; + private static readonly pb::FieldCodec _single_doubleField90_codec = pb::FieldCodec.ForStructWrapper(722); + private double? doubleField90_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField90 { + get { return doubleField90_; } + set { + doubleField90_ = value; + } + } + + + /// Field number for the "double_field_51" field. + public const int DoubleField51FieldNumber = 51; + private static readonly pb::FieldCodec _single_doubleField51_codec = pb::FieldCodec.ForStructWrapper(410); + private double? doubleField51_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField51 { + get { return doubleField51_; } + set { + doubleField51_ = value; + } + } + + + /// Field number for the "double_field_91" field. + public const int DoubleField91FieldNumber = 91; + private static readonly pb::FieldCodec _single_doubleField91_codec = pb::FieldCodec.ForStructWrapper(730); + private double? doubleField91_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField91 { + get { return doubleField91_; } + set { + doubleField91_ = value; + } + } + + + /// Field number for the "double_field_92" field. + public const int DoubleField92FieldNumber = 92; + private static readonly pb::FieldCodec _single_doubleField92_codec = pb::FieldCodec.ForStructWrapper(738); + private double? doubleField92_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField92 { + get { return doubleField92_; } + set { + doubleField92_ = value; + } + } + + + /// Field number for the "int64_field_107" field. + public const int Int64Field107FieldNumber = 107; + private static readonly pb::FieldCodec _single_int64Field107_codec = pb::FieldCodec.ForStructWrapper(858); + private long? int64Field107_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field107 { + get { return int64Field107_; } + set { + int64Field107_ = value; + } + } + + + /// Field number for the "double_field_93" field. + public const int DoubleField93FieldNumber = 93; + private static readonly pb::FieldCodec _single_doubleField93_codec = pb::FieldCodec.ForStructWrapper(746); + private double? doubleField93_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField93 { + get { return doubleField93_; } + set { + doubleField93_ = value; + } + } + + + /// Field number for the "double_field_108" field. + public const int DoubleField108FieldNumber = 108; + private static readonly pb::FieldCodec _single_doubleField108_codec = pb::FieldCodec.ForStructWrapper(866); + private double? doubleField108_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField108 { + get { return doubleField108_; } + set { + doubleField108_ = value; + } + } + + + /// Field number for the "double_field_52" field. + public const int DoubleField52FieldNumber = 52; + private static readonly pb::FieldCodec _single_doubleField52_codec = pb::FieldCodec.ForStructWrapper(418); + private double? doubleField52_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField52 { + get { return doubleField52_; } + set { + doubleField52_ = value; + } + } + + + /// Field number for the "double_field_53" field. + public const int DoubleField53FieldNumber = 53; + private static readonly pb::FieldCodec _single_doubleField53_codec = pb::FieldCodec.ForStructWrapper(426); + private double? doubleField53_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField53 { + get { return doubleField53_; } + set { + doubleField53_ = value; + } + } + + + /// Field number for the "double_field_94" field. + public const int DoubleField94FieldNumber = 94; + private static readonly pb::FieldCodec _single_doubleField94_codec = pb::FieldCodec.ForStructWrapper(754); + private double? doubleField94_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField94 { + get { return doubleField94_; } + set { + doubleField94_ = value; + } + } + + + /// Field number for the "double_field_54" field. + public const int DoubleField54FieldNumber = 54; + private static readonly pb::FieldCodec _single_doubleField54_codec = pb::FieldCodec.ForStructWrapper(434); + private double? doubleField54_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField54 { + get { return doubleField54_; } + set { + doubleField54_ = value; + } + } + + + /// Field number for the "double_field_55" field. + public const int DoubleField55FieldNumber = 55; + private static readonly pb::FieldCodec _single_doubleField55_codec = pb::FieldCodec.ForStructWrapper(442); + private double? doubleField55_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField55 { + get { return doubleField55_; } + set { + doubleField55_ = value; + } + } + + + /// Field number for the "double_field_56" field. + public const int DoubleField56FieldNumber = 56; + private static readonly pb::FieldCodec _single_doubleField56_codec = pb::FieldCodec.ForStructWrapper(450); + private double? doubleField56_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField56 { + get { return doubleField56_; } + set { + doubleField56_ = value; + } + } + + + /// Field number for the "double_field_57" field. + public const int DoubleField57FieldNumber = 57; + private static readonly pb::FieldCodec _single_doubleField57_codec = pb::FieldCodec.ForStructWrapper(458); + private double? doubleField57_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField57 { + get { return doubleField57_; } + set { + doubleField57_ = value; + } + } + + + /// Field number for the "double_field_58" field. + public const int DoubleField58FieldNumber = 58; + private static readonly pb::FieldCodec _single_doubleField58_codec = pb::FieldCodec.ForStructWrapper(466); + private double? doubleField58_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double? DoubleField58 { + get { return doubleField58_; } + set { + doubleField58_ = value; + } + } + + + /// Field number for the "int64_field_59" field. + public const int Int64Field59FieldNumber = 59; + private static readonly pb::FieldCodec _single_int64Field59_codec = pb::FieldCodec.ForStructWrapper(474); + private long? int64Field59_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field59 { + get { return int64Field59_; } + set { + int64Field59_ = value; + } + } + + + /// Field number for the "int64_field_60" field. + public const int Int64Field60FieldNumber = 60; + private static readonly pb::FieldCodec _single_int64Field60_codec = pb::FieldCodec.ForStructWrapper(482); + private long? int64Field60_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long? Int64Field60 { + get { return int64Field60_; } + set { + int64Field60_ = value; + } + } + + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as ManyWrapperFieldsMessage); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(ManyWrapperFieldsMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField95, other.DoubleField95)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField1, other.DoubleField1)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField79, other.DoubleField79)) return false; + if (Int64Field2 != other.Int64Field2) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField96, other.DoubleField96)) return false; + if (Int64Field3 != other.Int64Field3) return false; + if (Int64Field4 != other.Int64Field4) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField97, other.DoubleField97)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField65, other.DoubleField65)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField66, other.DoubleField66)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField7, other.DoubleField7)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField62, other.DoubleField62)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField118, other.DoubleField118)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField119, other.DoubleField119)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField67, other.DoubleField67)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField120, other.DoubleField120)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField121, other.DoubleField121)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField122, other.DoubleField122)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField123, other.DoubleField123)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField124, other.DoubleField124)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField8, other.DoubleField8)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField9, other.DoubleField9)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField98, other.DoubleField98)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField10, other.DoubleField10)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField11, other.DoubleField11)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField99, other.DoubleField99)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField84, other.DoubleField84)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField14, other.DoubleField14)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField77, other.DoubleField77)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField15, other.DoubleField15)) return false; + if (Int64Field19 != other.Int64Field19) return false; + if (Int64Field115 != other.Int64Field115) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField116, other.DoubleField116)) return false; + if (Int64Field117 != other.Int64Field117) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField20, other.DoubleField20)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField21, other.DoubleField21)) return false; + if (StringField73 != other.StringField73) return false; + if (StringField74 != other.StringField74) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField22, other.DoubleField22)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField69, other.DoubleField69)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField70, other.DoubleField70)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField71, other.DoubleField71)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField72, other.DoubleField72)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField25, other.DoubleField25)) return false; + if (Int64Field26 != other.Int64Field26) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField68, other.DoubleField68)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField28, other.DoubleField28)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField106, other.DoubleField106)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField29, other.DoubleField29)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField30, other.DoubleField30)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField101, other.DoubleField101)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField102, other.DoubleField102)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField103, other.DoubleField103)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField104, other.DoubleField104)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField105, other.DoubleField105)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField31, other.DoubleField31)) return false; + if (Int64Field32 != other.Int64Field32) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField75, other.DoubleField75)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField129, other.DoubleField129)) return false; + if (EnumField80 != other.EnumField80) return false; + if (EnumField81 != other.EnumField81) return false; + if (Int64Field82 != other.Int64Field82) return false; + if (EnumField83 != other.EnumField83) return false; + if (Int64Field85 != other.Int64Field85) return false; + if (Int64Field86 != other.Int64Field86) return false; + if (Int64Field87 != other.Int64Field87) return false; + if (Int64Field125 != other.Int64Field125) return false; + if (Int64Field37 != other.Int64Field37) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField38, other.DoubleField38)) return false; + if (Interactions != other.Interactions) return false; + if(!repeatedIntField100_.Equals(other.repeatedIntField100_)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField40, other.DoubleField40)) return false; + if (Int64Field41 != other.Int64Field41) return false; + if (Int64Field126 != other.Int64Field126) return false; + if (Int64Field127 != other.Int64Field127) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField128, other.DoubleField128)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField109, other.DoubleField109)) return false; + if (Int64Field110 != other.Int64Field110) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField111, other.DoubleField111)) return false; + if (Int64Field112 != other.Int64Field112) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField113, other.DoubleField113)) return false; + if (Int64Field114 != other.Int64Field114) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField42, other.DoubleField42)) return false; + if (Int64Field43 != other.Int64Field43) return false; + if (Int64Field44 != other.Int64Field44) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField45, other.DoubleField45)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField46, other.DoubleField46)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField78, other.DoubleField78)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField88, other.DoubleField88)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField47, other.DoubleField47)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField89, other.DoubleField89)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField48, other.DoubleField48)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField49, other.DoubleField49)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField50, other.DoubleField50)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField90, other.DoubleField90)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField51, other.DoubleField51)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField91, other.DoubleField91)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField92, other.DoubleField92)) return false; + if (Int64Field107 != other.Int64Field107) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField93, other.DoubleField93)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField108, other.DoubleField108)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField52, other.DoubleField52)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField53, other.DoubleField53)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField94, other.DoubleField94)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField54, other.DoubleField54)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField55, other.DoubleField55)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField56, other.DoubleField56)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField57, other.DoubleField57)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.Equals(DoubleField58, other.DoubleField58)) return false; + if (Int64Field59 != other.Int64Field59) return false; + if (Int64Field60 != other.Int64Field60) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (doubleField95_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField95); + if (doubleField1_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField1); + if (doubleField79_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField79); + if (int64Field2_ != null) hash ^= Int64Field2.GetHashCode(); + if (doubleField96_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField96); + if (int64Field3_ != null) hash ^= Int64Field3.GetHashCode(); + if (int64Field4_ != null) hash ^= Int64Field4.GetHashCode(); + if (doubleField97_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField97); + if (doubleField65_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField65); + if (doubleField66_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField66); + if (doubleField7_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField7); + if (doubleField62_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField62); + if (doubleField118_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField118); + if (doubleField119_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField119); + if (doubleField67_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField67); + if (doubleField120_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField120); + if (doubleField121_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField121); + if (doubleField122_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField122); + if (doubleField123_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField123); + if (doubleField124_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField124); + if (doubleField8_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField8); + if (doubleField9_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField9); + if (doubleField98_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField98); + if (doubleField10_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField10); + if (doubleField11_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField11); + if (doubleField99_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField99); + if (doubleField84_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField84); + if (doubleField14_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField14); + if (doubleField77_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField77); + if (doubleField15_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField15); + if (int64Field19_ != null) hash ^= Int64Field19.GetHashCode(); + if (int64Field115_ != null) hash ^= Int64Field115.GetHashCode(); + if (doubleField116_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField116); + if (int64Field117_ != null) hash ^= Int64Field117.GetHashCode(); + if (doubleField20_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField20); + if (doubleField21_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField21); + if (stringField73_ != null) hash ^= StringField73.GetHashCode(); + if (stringField74_ != null) hash ^= StringField74.GetHashCode(); + if (doubleField22_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField22); + if (doubleField69_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField69); + if (doubleField70_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField70); + if (doubleField71_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField71); + if (doubleField72_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField72); + if (doubleField25_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField25); + if (int64Field26_ != null) hash ^= Int64Field26.GetHashCode(); + if (doubleField68_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField68); + if (doubleField28_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField28); + if (doubleField106_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField106); + if (doubleField29_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField29); + if (doubleField30_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField30); + if (doubleField101_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField101); + if (doubleField102_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField102); + if (doubleField103_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField103); + if (doubleField104_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField104); + if (doubleField105_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField105); + if (doubleField31_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField31); + if (int64Field32_ != null) hash ^= Int64Field32.GetHashCode(); + if (doubleField75_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField75); + if (doubleField129_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField129); + if (EnumField80 != 0) hash ^= EnumField80.GetHashCode(); + if (EnumField81 != 0) hash ^= EnumField81.GetHashCode(); + if (int64Field82_ != null) hash ^= Int64Field82.GetHashCode(); + if (EnumField83 != 0) hash ^= EnumField83.GetHashCode(); + if (int64Field85_ != null) hash ^= Int64Field85.GetHashCode(); + if (int64Field86_ != null) hash ^= Int64Field86.GetHashCode(); + if (int64Field87_ != null) hash ^= Int64Field87.GetHashCode(); + if (int64Field125_ != null) hash ^= Int64Field125.GetHashCode(); + if (int64Field37_ != null) hash ^= Int64Field37.GetHashCode(); + if (doubleField38_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField38); + if (interactions_ != null) hash ^= Interactions.GetHashCode(); + hash ^= repeatedIntField100_.GetHashCode(); + if (doubleField40_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField40); + if (int64Field41_ != null) hash ^= Int64Field41.GetHashCode(); + if (int64Field126_ != null) hash ^= Int64Field126.GetHashCode(); + if (int64Field127_ != null) hash ^= Int64Field127.GetHashCode(); + if (doubleField128_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField128); + if (doubleField109_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField109); + if (int64Field110_ != null) hash ^= Int64Field110.GetHashCode(); + if (doubleField111_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField111); + if (int64Field112_ != null) hash ^= Int64Field112.GetHashCode(); + if (doubleField113_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField113); + if (int64Field114_ != null) hash ^= Int64Field114.GetHashCode(); + if (doubleField42_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField42); + if (int64Field43_ != null) hash ^= Int64Field43.GetHashCode(); + if (int64Field44_ != null) hash ^= Int64Field44.GetHashCode(); + if (doubleField45_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField45); + if (doubleField46_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField46); + if (doubleField78_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField78); + if (doubleField88_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField88); + if (doubleField47_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField47); + if (doubleField89_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField89); + if (doubleField48_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField48); + if (doubleField49_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField49); + if (doubleField50_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField50); + if (doubleField90_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField90); + if (doubleField51_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField51); + if (doubleField91_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField91); + if (doubleField92_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField92); + if (int64Field107_ != null) hash ^= Int64Field107.GetHashCode(); + if (doubleField93_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField93); + if (doubleField108_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField108); + if (doubleField52_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField52); + if (doubleField53_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField53); + if (doubleField94_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField94); + if (doubleField54_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField54); + if (doubleField55_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField55); + if (doubleField56_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField56); + if (doubleField57_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField57); + if (doubleField58_ != null) hash ^= pbc::ProtobufEqualityComparers.BitwiseNullableDoubleEqualityComparer.GetHashCode(DoubleField58); + if (int64Field59_ != null) hash ^= Int64Field59.GetHashCode(); + if (int64Field60_ != null) hash ^= Int64Field60.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (doubleField1_ != null) { + _single_doubleField1_codec.WriteTagAndValue(output, DoubleField1); + } + if (int64Field2_ != null) { + _single_int64Field2_codec.WriteTagAndValue(output, Int64Field2); + } + if (int64Field3_ != null) { + _single_int64Field3_codec.WriteTagAndValue(output, Int64Field3); + } + if (int64Field4_ != null) { + _single_int64Field4_codec.WriteTagAndValue(output, Int64Field4); + } + if (doubleField7_ != null) { + _single_doubleField7_codec.WriteTagAndValue(output, DoubleField7); + } + if (doubleField8_ != null) { + _single_doubleField8_codec.WriteTagAndValue(output, DoubleField8); + } + if (doubleField9_ != null) { + _single_doubleField9_codec.WriteTagAndValue(output, DoubleField9); + } + if (doubleField10_ != null) { + _single_doubleField10_codec.WriteTagAndValue(output, DoubleField10); + } + if (doubleField11_ != null) { + _single_doubleField11_codec.WriteTagAndValue(output, DoubleField11); + } + if (doubleField14_ != null) { + _single_doubleField14_codec.WriteTagAndValue(output, DoubleField14); + } + if (doubleField15_ != null) { + _single_doubleField15_codec.WriteTagAndValue(output, DoubleField15); + } + if (int64Field19_ != null) { + _single_int64Field19_codec.WriteTagAndValue(output, Int64Field19); + } + if (doubleField20_ != null) { + _single_doubleField20_codec.WriteTagAndValue(output, DoubleField20); + } + if (doubleField21_ != null) { + _single_doubleField21_codec.WriteTagAndValue(output, DoubleField21); + } + if (doubleField22_ != null) { + _single_doubleField22_codec.WriteTagAndValue(output, DoubleField22); + } + if (doubleField25_ != null) { + _single_doubleField25_codec.WriteTagAndValue(output, DoubleField25); + } + if (int64Field26_ != null) { + _single_int64Field26_codec.WriteTagAndValue(output, Int64Field26); + } + if (doubleField28_ != null) { + _single_doubleField28_codec.WriteTagAndValue(output, DoubleField28); + } + if (doubleField29_ != null) { + _single_doubleField29_codec.WriteTagAndValue(output, DoubleField29); + } + if (doubleField30_ != null) { + _single_doubleField30_codec.WriteTagAndValue(output, DoubleField30); + } + if (doubleField31_ != null) { + _single_doubleField31_codec.WriteTagAndValue(output, DoubleField31); + } + if (int64Field32_ != null) { + _single_int64Field32_codec.WriteTagAndValue(output, Int64Field32); + } + if (int64Field37_ != null) { + _single_int64Field37_codec.WriteTagAndValue(output, Int64Field37); + } + if (doubleField38_ != null) { + _single_doubleField38_codec.WriteTagAndValue(output, DoubleField38); + } + if (interactions_ != null) { + _single_interactions_codec.WriteTagAndValue(output, Interactions); + } + if (doubleField40_ != null) { + _single_doubleField40_codec.WriteTagAndValue(output, DoubleField40); + } + if (int64Field41_ != null) { + _single_int64Field41_codec.WriteTagAndValue(output, Int64Field41); + } + if (doubleField42_ != null) { + _single_doubleField42_codec.WriteTagAndValue(output, DoubleField42); + } + if (int64Field43_ != null) { + _single_int64Field43_codec.WriteTagAndValue(output, Int64Field43); + } + if (int64Field44_ != null) { + _single_int64Field44_codec.WriteTagAndValue(output, Int64Field44); + } + if (doubleField45_ != null) { + _single_doubleField45_codec.WriteTagAndValue(output, DoubleField45); + } + if (doubleField46_ != null) { + _single_doubleField46_codec.WriteTagAndValue(output, DoubleField46); + } + if (doubleField47_ != null) { + _single_doubleField47_codec.WriteTagAndValue(output, DoubleField47); + } + if (doubleField48_ != null) { + _single_doubleField48_codec.WriteTagAndValue(output, DoubleField48); + } + if (doubleField49_ != null) { + _single_doubleField49_codec.WriteTagAndValue(output, DoubleField49); + } + if (doubleField50_ != null) { + _single_doubleField50_codec.WriteTagAndValue(output, DoubleField50); + } + if (doubleField51_ != null) { + _single_doubleField51_codec.WriteTagAndValue(output, DoubleField51); + } + if (doubleField52_ != null) { + _single_doubleField52_codec.WriteTagAndValue(output, DoubleField52); + } + if (doubleField53_ != null) { + _single_doubleField53_codec.WriteTagAndValue(output, DoubleField53); + } + if (doubleField54_ != null) { + _single_doubleField54_codec.WriteTagAndValue(output, DoubleField54); + } + if (doubleField55_ != null) { + _single_doubleField55_codec.WriteTagAndValue(output, DoubleField55); + } + if (doubleField56_ != null) { + _single_doubleField56_codec.WriteTagAndValue(output, DoubleField56); + } + if (doubleField57_ != null) { + _single_doubleField57_codec.WriteTagAndValue(output, DoubleField57); + } + if (doubleField58_ != null) { + _single_doubleField58_codec.WriteTagAndValue(output, DoubleField58); + } + if (int64Field59_ != null) { + _single_int64Field59_codec.WriteTagAndValue(output, Int64Field59); + } + if (int64Field60_ != null) { + _single_int64Field60_codec.WriteTagAndValue(output, Int64Field60); + } + if (doubleField62_ != null) { + _single_doubleField62_codec.WriteTagAndValue(output, DoubleField62); + } + if (doubleField65_ != null) { + _single_doubleField65_codec.WriteTagAndValue(output, DoubleField65); + } + if (doubleField66_ != null) { + _single_doubleField66_codec.WriteTagAndValue(output, DoubleField66); + } + if (doubleField67_ != null) { + _single_doubleField67_codec.WriteTagAndValue(output, DoubleField67); + } + if (doubleField68_ != null) { + _single_doubleField68_codec.WriteTagAndValue(output, DoubleField68); + } + if (doubleField69_ != null) { + _single_doubleField69_codec.WriteTagAndValue(output, DoubleField69); + } + if (doubleField70_ != null) { + _single_doubleField70_codec.WriteTagAndValue(output, DoubleField70); + } + if (doubleField71_ != null) { + _single_doubleField71_codec.WriteTagAndValue(output, DoubleField71); + } + if (doubleField72_ != null) { + _single_doubleField72_codec.WriteTagAndValue(output, DoubleField72); + } + if (stringField73_ != null) { + _single_stringField73_codec.WriteTagAndValue(output, StringField73); + } + if (stringField74_ != null) { + _single_stringField74_codec.WriteTagAndValue(output, StringField74); + } + if (doubleField75_ != null) { + _single_doubleField75_codec.WriteTagAndValue(output, DoubleField75); + } + if (doubleField77_ != null) { + _single_doubleField77_codec.WriteTagAndValue(output, DoubleField77); + } + if (doubleField78_ != null) { + _single_doubleField78_codec.WriteTagAndValue(output, DoubleField78); + } + if (doubleField79_ != null) { + _single_doubleField79_codec.WriteTagAndValue(output, DoubleField79); + } + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); + } + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); + } + if (int64Field82_ != null) { + _single_int64Field82_codec.WriteTagAndValue(output, Int64Field82); + } + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); + } + if (doubleField84_ != null) { + _single_doubleField84_codec.WriteTagAndValue(output, DoubleField84); + } + if (int64Field85_ != null) { + _single_int64Field85_codec.WriteTagAndValue(output, Int64Field85); + } + if (int64Field86_ != null) { + _single_int64Field86_codec.WriteTagAndValue(output, Int64Field86); + } + if (int64Field87_ != null) { + _single_int64Field87_codec.WriteTagAndValue(output, Int64Field87); + } + if (doubleField88_ != null) { + _single_doubleField88_codec.WriteTagAndValue(output, DoubleField88); + } + if (doubleField89_ != null) { + _single_doubleField89_codec.WriteTagAndValue(output, DoubleField89); + } + if (doubleField90_ != null) { + _single_doubleField90_codec.WriteTagAndValue(output, DoubleField90); + } + if (doubleField91_ != null) { + _single_doubleField91_codec.WriteTagAndValue(output, DoubleField91); + } + if (doubleField92_ != null) { + _single_doubleField92_codec.WriteTagAndValue(output, DoubleField92); + } + if (doubleField93_ != null) { + _single_doubleField93_codec.WriteTagAndValue(output, DoubleField93); + } + if (doubleField94_ != null) { + _single_doubleField94_codec.WriteTagAndValue(output, DoubleField94); + } + if (doubleField95_ != null) { + _single_doubleField95_codec.WriteTagAndValue(output, DoubleField95); + } + if (doubleField96_ != null) { + _single_doubleField96_codec.WriteTagAndValue(output, DoubleField96); + } + if (doubleField97_ != null) { + _single_doubleField97_codec.WriteTagAndValue(output, DoubleField97); + } + if (doubleField98_ != null) { + _single_doubleField98_codec.WriteTagAndValue(output, DoubleField98); + } + if (doubleField99_ != null) { + _single_doubleField99_codec.WriteTagAndValue(output, DoubleField99); + } + repeatedIntField100_.WriteTo(output, _repeated_repeatedIntField100_codec); + if (doubleField101_ != null) { + _single_doubleField101_codec.WriteTagAndValue(output, DoubleField101); + } + if (doubleField102_ != null) { + _single_doubleField102_codec.WriteTagAndValue(output, DoubleField102); + } + if (doubleField103_ != null) { + _single_doubleField103_codec.WriteTagAndValue(output, DoubleField103); + } + if (doubleField104_ != null) { + _single_doubleField104_codec.WriteTagAndValue(output, DoubleField104); + } + if (doubleField105_ != null) { + _single_doubleField105_codec.WriteTagAndValue(output, DoubleField105); + } + if (doubleField106_ != null) { + _single_doubleField106_codec.WriteTagAndValue(output, DoubleField106); + } + if (int64Field107_ != null) { + _single_int64Field107_codec.WriteTagAndValue(output, Int64Field107); + } + if (doubleField108_ != null) { + _single_doubleField108_codec.WriteTagAndValue(output, DoubleField108); + } + if (doubleField109_ != null) { + _single_doubleField109_codec.WriteTagAndValue(output, DoubleField109); + } + if (int64Field110_ != null) { + _single_int64Field110_codec.WriteTagAndValue(output, Int64Field110); + } + if (doubleField111_ != null) { + _single_doubleField111_codec.WriteTagAndValue(output, DoubleField111); + } + if (int64Field112_ != null) { + _single_int64Field112_codec.WriteTagAndValue(output, Int64Field112); + } + if (doubleField113_ != null) { + _single_doubleField113_codec.WriteTagAndValue(output, DoubleField113); + } + if (int64Field114_ != null) { + _single_int64Field114_codec.WriteTagAndValue(output, Int64Field114); + } + if (int64Field115_ != null) { + _single_int64Field115_codec.WriteTagAndValue(output, Int64Field115); + } + if (doubleField116_ != null) { + _single_doubleField116_codec.WriteTagAndValue(output, DoubleField116); + } + if (int64Field117_ != null) { + _single_int64Field117_codec.WriteTagAndValue(output, Int64Field117); + } + if (doubleField118_ != null) { + _single_doubleField118_codec.WriteTagAndValue(output, DoubleField118); + } + if (doubleField119_ != null) { + _single_doubleField119_codec.WriteTagAndValue(output, DoubleField119); + } + if (doubleField120_ != null) { + _single_doubleField120_codec.WriteTagAndValue(output, DoubleField120); + } + if (doubleField121_ != null) { + _single_doubleField121_codec.WriteTagAndValue(output, DoubleField121); + } + if (doubleField122_ != null) { + _single_doubleField122_codec.WriteTagAndValue(output, DoubleField122); + } + if (doubleField123_ != null) { + _single_doubleField123_codec.WriteTagAndValue(output, DoubleField123); + } + if (doubleField124_ != null) { + _single_doubleField124_codec.WriteTagAndValue(output, DoubleField124); + } + if (int64Field125_ != null) { + _single_int64Field125_codec.WriteTagAndValue(output, Int64Field125); + } + if (int64Field126_ != null) { + _single_int64Field126_codec.WriteTagAndValue(output, Int64Field126); + } + if (int64Field127_ != null) { + _single_int64Field127_codec.WriteTagAndValue(output, Int64Field127); + } + if (doubleField128_ != null) { + _single_doubleField128_codec.WriteTagAndValue(output, DoubleField128); + } + if (doubleField129_ != null) { + _single_doubleField129_codec.WriteTagAndValue(output, DoubleField129); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (doubleField1_ != null) { + _single_doubleField1_codec.WriteTagAndValue(ref output, DoubleField1); + } + if (int64Field2_ != null) { + _single_int64Field2_codec.WriteTagAndValue(ref output, Int64Field2); + } + if (int64Field3_ != null) { + _single_int64Field3_codec.WriteTagAndValue(ref output, Int64Field3); + } + if (int64Field4_ != null) { + _single_int64Field4_codec.WriteTagAndValue(ref output, Int64Field4); + } + if (doubleField7_ != null) { + _single_doubleField7_codec.WriteTagAndValue(ref output, DoubleField7); + } + if (doubleField8_ != null) { + _single_doubleField8_codec.WriteTagAndValue(ref output, DoubleField8); + } + if (doubleField9_ != null) { + _single_doubleField9_codec.WriteTagAndValue(ref output, DoubleField9); + } + if (doubleField10_ != null) { + _single_doubleField10_codec.WriteTagAndValue(ref output, DoubleField10); + } + if (doubleField11_ != null) { + _single_doubleField11_codec.WriteTagAndValue(ref output, DoubleField11); + } + if (doubleField14_ != null) { + _single_doubleField14_codec.WriteTagAndValue(ref output, DoubleField14); + } + if (doubleField15_ != null) { + _single_doubleField15_codec.WriteTagAndValue(ref output, DoubleField15); + } + if (int64Field19_ != null) { + _single_int64Field19_codec.WriteTagAndValue(ref output, Int64Field19); + } + if (doubleField20_ != null) { + _single_doubleField20_codec.WriteTagAndValue(ref output, DoubleField20); + } + if (doubleField21_ != null) { + _single_doubleField21_codec.WriteTagAndValue(ref output, DoubleField21); + } + if (doubleField22_ != null) { + _single_doubleField22_codec.WriteTagAndValue(ref output, DoubleField22); + } + if (doubleField25_ != null) { + _single_doubleField25_codec.WriteTagAndValue(ref output, DoubleField25); + } + if (int64Field26_ != null) { + _single_int64Field26_codec.WriteTagAndValue(ref output, Int64Field26); + } + if (doubleField28_ != null) { + _single_doubleField28_codec.WriteTagAndValue(ref output, DoubleField28); + } + if (doubleField29_ != null) { + _single_doubleField29_codec.WriteTagAndValue(ref output, DoubleField29); + } + if (doubleField30_ != null) { + _single_doubleField30_codec.WriteTagAndValue(ref output, DoubleField30); + } + if (doubleField31_ != null) { + _single_doubleField31_codec.WriteTagAndValue(ref output, DoubleField31); + } + if (int64Field32_ != null) { + _single_int64Field32_codec.WriteTagAndValue(ref output, Int64Field32); + } + if (int64Field37_ != null) { + _single_int64Field37_codec.WriteTagAndValue(ref output, Int64Field37); + } + if (doubleField38_ != null) { + _single_doubleField38_codec.WriteTagAndValue(ref output, DoubleField38); + } + if (interactions_ != null) { + _single_interactions_codec.WriteTagAndValue(ref output, Interactions); + } + if (doubleField40_ != null) { + _single_doubleField40_codec.WriteTagAndValue(ref output, DoubleField40); + } + if (int64Field41_ != null) { + _single_int64Field41_codec.WriteTagAndValue(ref output, Int64Field41); + } + if (doubleField42_ != null) { + _single_doubleField42_codec.WriteTagAndValue(ref output, DoubleField42); + } + if (int64Field43_ != null) { + _single_int64Field43_codec.WriteTagAndValue(ref output, Int64Field43); + } + if (int64Field44_ != null) { + _single_int64Field44_codec.WriteTagAndValue(ref output, Int64Field44); + } + if (doubleField45_ != null) { + _single_doubleField45_codec.WriteTagAndValue(ref output, DoubleField45); + } + if (doubleField46_ != null) { + _single_doubleField46_codec.WriteTagAndValue(ref output, DoubleField46); + } + if (doubleField47_ != null) { + _single_doubleField47_codec.WriteTagAndValue(ref output, DoubleField47); + } + if (doubleField48_ != null) { + _single_doubleField48_codec.WriteTagAndValue(ref output, DoubleField48); + } + if (doubleField49_ != null) { + _single_doubleField49_codec.WriteTagAndValue(ref output, DoubleField49); + } + if (doubleField50_ != null) { + _single_doubleField50_codec.WriteTagAndValue(ref output, DoubleField50); + } + if (doubleField51_ != null) { + _single_doubleField51_codec.WriteTagAndValue(ref output, DoubleField51); + } + if (doubleField52_ != null) { + _single_doubleField52_codec.WriteTagAndValue(ref output, DoubleField52); + } + if (doubleField53_ != null) { + _single_doubleField53_codec.WriteTagAndValue(ref output, DoubleField53); + } + if (doubleField54_ != null) { + _single_doubleField54_codec.WriteTagAndValue(ref output, DoubleField54); + } + if (doubleField55_ != null) { + _single_doubleField55_codec.WriteTagAndValue(ref output, DoubleField55); + } + if (doubleField56_ != null) { + _single_doubleField56_codec.WriteTagAndValue(ref output, DoubleField56); + } + if (doubleField57_ != null) { + _single_doubleField57_codec.WriteTagAndValue(ref output, DoubleField57); + } + if (doubleField58_ != null) { + _single_doubleField58_codec.WriteTagAndValue(ref output, DoubleField58); + } + if (int64Field59_ != null) { + _single_int64Field59_codec.WriteTagAndValue(ref output, Int64Field59); + } + if (int64Field60_ != null) { + _single_int64Field60_codec.WriteTagAndValue(ref output, Int64Field60); + } + if (doubleField62_ != null) { + _single_doubleField62_codec.WriteTagAndValue(ref output, DoubleField62); + } + if (doubleField65_ != null) { + _single_doubleField65_codec.WriteTagAndValue(ref output, DoubleField65); + } + if (doubleField66_ != null) { + _single_doubleField66_codec.WriteTagAndValue(ref output, DoubleField66); + } + if (doubleField67_ != null) { + _single_doubleField67_codec.WriteTagAndValue(ref output, DoubleField67); + } + if (doubleField68_ != null) { + _single_doubleField68_codec.WriteTagAndValue(ref output, DoubleField68); + } + if (doubleField69_ != null) { + _single_doubleField69_codec.WriteTagAndValue(ref output, DoubleField69); + } + if (doubleField70_ != null) { + _single_doubleField70_codec.WriteTagAndValue(ref output, DoubleField70); + } + if (doubleField71_ != null) { + _single_doubleField71_codec.WriteTagAndValue(ref output, DoubleField71); + } + if (doubleField72_ != null) { + _single_doubleField72_codec.WriteTagAndValue(ref output, DoubleField72); + } + if (stringField73_ != null) { + _single_stringField73_codec.WriteTagAndValue(ref output, StringField73); + } + if (stringField74_ != null) { + _single_stringField74_codec.WriteTagAndValue(ref output, StringField74); + } + if (doubleField75_ != null) { + _single_doubleField75_codec.WriteTagAndValue(ref output, DoubleField75); + } + if (doubleField77_ != null) { + _single_doubleField77_codec.WriteTagAndValue(ref output, DoubleField77); + } + if (doubleField78_ != null) { + _single_doubleField78_codec.WriteTagAndValue(ref output, DoubleField78); + } + if (doubleField79_ != null) { + _single_doubleField79_codec.WriteTagAndValue(ref output, DoubleField79); + } + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); + } + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); + } + if (int64Field82_ != null) { + _single_int64Field82_codec.WriteTagAndValue(ref output, Int64Field82); + } + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); + } + if (doubleField84_ != null) { + _single_doubleField84_codec.WriteTagAndValue(ref output, DoubleField84); + } + if (int64Field85_ != null) { + _single_int64Field85_codec.WriteTagAndValue(ref output, Int64Field85); + } + if (int64Field86_ != null) { + _single_int64Field86_codec.WriteTagAndValue(ref output, Int64Field86); + } + if (int64Field87_ != null) { + _single_int64Field87_codec.WriteTagAndValue(ref output, Int64Field87); + } + if (doubleField88_ != null) { + _single_doubleField88_codec.WriteTagAndValue(ref output, DoubleField88); + } + if (doubleField89_ != null) { + _single_doubleField89_codec.WriteTagAndValue(ref output, DoubleField89); + } + if (doubleField90_ != null) { + _single_doubleField90_codec.WriteTagAndValue(ref output, DoubleField90); + } + if (doubleField91_ != null) { + _single_doubleField91_codec.WriteTagAndValue(ref output, DoubleField91); + } + if (doubleField92_ != null) { + _single_doubleField92_codec.WriteTagAndValue(ref output, DoubleField92); + } + if (doubleField93_ != null) { + _single_doubleField93_codec.WriteTagAndValue(ref output, DoubleField93); + } + if (doubleField94_ != null) { + _single_doubleField94_codec.WriteTagAndValue(ref output, DoubleField94); + } + if (doubleField95_ != null) { + _single_doubleField95_codec.WriteTagAndValue(ref output, DoubleField95); + } + if (doubleField96_ != null) { + _single_doubleField96_codec.WriteTagAndValue(ref output, DoubleField96); + } + if (doubleField97_ != null) { + _single_doubleField97_codec.WriteTagAndValue(ref output, DoubleField97); + } + if (doubleField98_ != null) { + _single_doubleField98_codec.WriteTagAndValue(ref output, DoubleField98); + } + if (doubleField99_ != null) { + _single_doubleField99_codec.WriteTagAndValue(ref output, DoubleField99); + } + repeatedIntField100_.WriteTo(ref output, _repeated_repeatedIntField100_codec); + if (doubleField101_ != null) { + _single_doubleField101_codec.WriteTagAndValue(ref output, DoubleField101); + } + if (doubleField102_ != null) { + _single_doubleField102_codec.WriteTagAndValue(ref output, DoubleField102); + } + if (doubleField103_ != null) { + _single_doubleField103_codec.WriteTagAndValue(ref output, DoubleField103); + } + if (doubleField104_ != null) { + _single_doubleField104_codec.WriteTagAndValue(ref output, DoubleField104); + } + if (doubleField105_ != null) { + _single_doubleField105_codec.WriteTagAndValue(ref output, DoubleField105); + } + if (doubleField106_ != null) { + _single_doubleField106_codec.WriteTagAndValue(ref output, DoubleField106); + } + if (int64Field107_ != null) { + _single_int64Field107_codec.WriteTagAndValue(ref output, Int64Field107); + } + if (doubleField108_ != null) { + _single_doubleField108_codec.WriteTagAndValue(ref output, DoubleField108); + } + if (doubleField109_ != null) { + _single_doubleField109_codec.WriteTagAndValue(ref output, DoubleField109); + } + if (int64Field110_ != null) { + _single_int64Field110_codec.WriteTagAndValue(ref output, Int64Field110); + } + if (doubleField111_ != null) { + _single_doubleField111_codec.WriteTagAndValue(ref output, DoubleField111); + } + if (int64Field112_ != null) { + _single_int64Field112_codec.WriteTagAndValue(ref output, Int64Field112); + } + if (doubleField113_ != null) { + _single_doubleField113_codec.WriteTagAndValue(ref output, DoubleField113); + } + if (int64Field114_ != null) { + _single_int64Field114_codec.WriteTagAndValue(ref output, Int64Field114); + } + if (int64Field115_ != null) { + _single_int64Field115_codec.WriteTagAndValue(ref output, Int64Field115); + } + if (doubleField116_ != null) { + _single_doubleField116_codec.WriteTagAndValue(ref output, DoubleField116); + } + if (int64Field117_ != null) { + _single_int64Field117_codec.WriteTagAndValue(ref output, Int64Field117); + } + if (doubleField118_ != null) { + _single_doubleField118_codec.WriteTagAndValue(ref output, DoubleField118); + } + if (doubleField119_ != null) { + _single_doubleField119_codec.WriteTagAndValue(ref output, DoubleField119); + } + if (doubleField120_ != null) { + _single_doubleField120_codec.WriteTagAndValue(ref output, DoubleField120); + } + if (doubleField121_ != null) { + _single_doubleField121_codec.WriteTagAndValue(ref output, DoubleField121); + } + if (doubleField122_ != null) { + _single_doubleField122_codec.WriteTagAndValue(ref output, DoubleField122); + } + if (doubleField123_ != null) { + _single_doubleField123_codec.WriteTagAndValue(ref output, DoubleField123); + } + if (doubleField124_ != null) { + _single_doubleField124_codec.WriteTagAndValue(ref output, DoubleField124); + } + if (int64Field125_ != null) { + _single_int64Field125_codec.WriteTagAndValue(ref output, Int64Field125); + } + if (int64Field126_ != null) { + _single_int64Field126_codec.WriteTagAndValue(ref output, Int64Field126); + } + if (int64Field127_ != null) { + _single_int64Field127_codec.WriteTagAndValue(ref output, Int64Field127); + } + if (doubleField128_ != null) { + _single_doubleField128_codec.WriteTagAndValue(ref output, DoubleField128); + } + if (doubleField129_ != null) { + _single_doubleField129_codec.WriteTagAndValue(ref output, DoubleField129); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (doubleField95_ != null) { + size += _single_doubleField95_codec.CalculateSizeWithTag(DoubleField95); + } + if (doubleField1_ != null) { + size += _single_doubleField1_codec.CalculateSizeWithTag(DoubleField1); + } + if (doubleField79_ != null) { + size += _single_doubleField79_codec.CalculateSizeWithTag(DoubleField79); + } + if (int64Field2_ != null) { + size += _single_int64Field2_codec.CalculateSizeWithTag(Int64Field2); + } + if (doubleField96_ != null) { + size += _single_doubleField96_codec.CalculateSizeWithTag(DoubleField96); + } + if (int64Field3_ != null) { + size += _single_int64Field3_codec.CalculateSizeWithTag(Int64Field3); + } + if (int64Field4_ != null) { + size += _single_int64Field4_codec.CalculateSizeWithTag(Int64Field4); + } + if (doubleField97_ != null) { + size += _single_doubleField97_codec.CalculateSizeWithTag(DoubleField97); + } + if (doubleField65_ != null) { + size += _single_doubleField65_codec.CalculateSizeWithTag(DoubleField65); + } + if (doubleField66_ != null) { + size += _single_doubleField66_codec.CalculateSizeWithTag(DoubleField66); + } + if (doubleField7_ != null) { + size += _single_doubleField7_codec.CalculateSizeWithTag(DoubleField7); + } + if (doubleField62_ != null) { + size += _single_doubleField62_codec.CalculateSizeWithTag(DoubleField62); + } + if (doubleField118_ != null) { + size += _single_doubleField118_codec.CalculateSizeWithTag(DoubleField118); + } + if (doubleField119_ != null) { + size += _single_doubleField119_codec.CalculateSizeWithTag(DoubleField119); + } + if (doubleField67_ != null) { + size += _single_doubleField67_codec.CalculateSizeWithTag(DoubleField67); + } + if (doubleField120_ != null) { + size += _single_doubleField120_codec.CalculateSizeWithTag(DoubleField120); + } + if (doubleField121_ != null) { + size += _single_doubleField121_codec.CalculateSizeWithTag(DoubleField121); + } + if (doubleField122_ != null) { + size += _single_doubleField122_codec.CalculateSizeWithTag(DoubleField122); + } + if (doubleField123_ != null) { + size += _single_doubleField123_codec.CalculateSizeWithTag(DoubleField123); + } + if (doubleField124_ != null) { + size += _single_doubleField124_codec.CalculateSizeWithTag(DoubleField124); + } + if (doubleField8_ != null) { + size += _single_doubleField8_codec.CalculateSizeWithTag(DoubleField8); + } + if (doubleField9_ != null) { + size += _single_doubleField9_codec.CalculateSizeWithTag(DoubleField9); + } + if (doubleField98_ != null) { + size += _single_doubleField98_codec.CalculateSizeWithTag(DoubleField98); + } + if (doubleField10_ != null) { + size += _single_doubleField10_codec.CalculateSizeWithTag(DoubleField10); + } + if (doubleField11_ != null) { + size += _single_doubleField11_codec.CalculateSizeWithTag(DoubleField11); + } + if (doubleField99_ != null) { + size += _single_doubleField99_codec.CalculateSizeWithTag(DoubleField99); + } + if (doubleField84_ != null) { + size += _single_doubleField84_codec.CalculateSizeWithTag(DoubleField84); + } + if (doubleField14_ != null) { + size += _single_doubleField14_codec.CalculateSizeWithTag(DoubleField14); + } + if (doubleField77_ != null) { + size += _single_doubleField77_codec.CalculateSizeWithTag(DoubleField77); + } + if (doubleField15_ != null) { + size += _single_doubleField15_codec.CalculateSizeWithTag(DoubleField15); + } + if (int64Field19_ != null) { + size += _single_int64Field19_codec.CalculateSizeWithTag(Int64Field19); + } + if (int64Field115_ != null) { + size += _single_int64Field115_codec.CalculateSizeWithTag(Int64Field115); + } + if (doubleField116_ != null) { + size += _single_doubleField116_codec.CalculateSizeWithTag(DoubleField116); + } + if (int64Field117_ != null) { + size += _single_int64Field117_codec.CalculateSizeWithTag(Int64Field117); + } + if (doubleField20_ != null) { + size += _single_doubleField20_codec.CalculateSizeWithTag(DoubleField20); + } + if (doubleField21_ != null) { + size += _single_doubleField21_codec.CalculateSizeWithTag(DoubleField21); + } + if (stringField73_ != null) { + size += _single_stringField73_codec.CalculateSizeWithTag(StringField73); + } + if (stringField74_ != null) { + size += _single_stringField74_codec.CalculateSizeWithTag(StringField74); + } + if (doubleField22_ != null) { + size += _single_doubleField22_codec.CalculateSizeWithTag(DoubleField22); + } + if (doubleField69_ != null) { + size += _single_doubleField69_codec.CalculateSizeWithTag(DoubleField69); + } + if (doubleField70_ != null) { + size += _single_doubleField70_codec.CalculateSizeWithTag(DoubleField70); + } + if (doubleField71_ != null) { + size += _single_doubleField71_codec.CalculateSizeWithTag(DoubleField71); + } + if (doubleField72_ != null) { + size += _single_doubleField72_codec.CalculateSizeWithTag(DoubleField72); + } + if (doubleField25_ != null) { + size += _single_doubleField25_codec.CalculateSizeWithTag(DoubleField25); + } + if (int64Field26_ != null) { + size += _single_int64Field26_codec.CalculateSizeWithTag(Int64Field26); + } + if (doubleField68_ != null) { + size += _single_doubleField68_codec.CalculateSizeWithTag(DoubleField68); + } + if (doubleField28_ != null) { + size += _single_doubleField28_codec.CalculateSizeWithTag(DoubleField28); + } + if (doubleField106_ != null) { + size += _single_doubleField106_codec.CalculateSizeWithTag(DoubleField106); + } + if (doubleField29_ != null) { + size += _single_doubleField29_codec.CalculateSizeWithTag(DoubleField29); + } + if (doubleField30_ != null) { + size += _single_doubleField30_codec.CalculateSizeWithTag(DoubleField30); + } + if (doubleField101_ != null) { + size += _single_doubleField101_codec.CalculateSizeWithTag(DoubleField101); + } + if (doubleField102_ != null) { + size += _single_doubleField102_codec.CalculateSizeWithTag(DoubleField102); + } + if (doubleField103_ != null) { + size += _single_doubleField103_codec.CalculateSizeWithTag(DoubleField103); + } + if (doubleField104_ != null) { + size += _single_doubleField104_codec.CalculateSizeWithTag(DoubleField104); + } + if (doubleField105_ != null) { + size += _single_doubleField105_codec.CalculateSizeWithTag(DoubleField105); + } + if (doubleField31_ != null) { + size += _single_doubleField31_codec.CalculateSizeWithTag(DoubleField31); + } + if (int64Field32_ != null) { + size += _single_int64Field32_codec.CalculateSizeWithTag(Int64Field32); + } + if (doubleField75_ != null) { + size += _single_doubleField75_codec.CalculateSizeWithTag(DoubleField75); + } + if (doubleField129_ != null) { + size += _single_doubleField129_codec.CalculateSizeWithTag(DoubleField129); + } + if (EnumField80 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField80); + } + if (EnumField81 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField81); + } + if (int64Field82_ != null) { + size += _single_int64Field82_codec.CalculateSizeWithTag(Int64Field82); + } + if (EnumField83 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField83); + } + if (int64Field85_ != null) { + size += _single_int64Field85_codec.CalculateSizeWithTag(Int64Field85); + } + if (int64Field86_ != null) { + size += _single_int64Field86_codec.CalculateSizeWithTag(Int64Field86); + } + if (int64Field87_ != null) { + size += _single_int64Field87_codec.CalculateSizeWithTag(Int64Field87); + } + if (int64Field125_ != null) { + size += _single_int64Field125_codec.CalculateSizeWithTag(Int64Field125); + } + if (int64Field37_ != null) { + size += _single_int64Field37_codec.CalculateSizeWithTag(Int64Field37); + } + if (doubleField38_ != null) { + size += _single_doubleField38_codec.CalculateSizeWithTag(DoubleField38); + } + if (interactions_ != null) { + size += _single_interactions_codec.CalculateSizeWithTag(Interactions); + } + size += repeatedIntField100_.CalculateSize(_repeated_repeatedIntField100_codec); + if (doubleField40_ != null) { + size += _single_doubleField40_codec.CalculateSizeWithTag(DoubleField40); + } + if (int64Field41_ != null) { + size += _single_int64Field41_codec.CalculateSizeWithTag(Int64Field41); + } + if (int64Field126_ != null) { + size += _single_int64Field126_codec.CalculateSizeWithTag(Int64Field126); + } + if (int64Field127_ != null) { + size += _single_int64Field127_codec.CalculateSizeWithTag(Int64Field127); + } + if (doubleField128_ != null) { + size += _single_doubleField128_codec.CalculateSizeWithTag(DoubleField128); + } + if (doubleField109_ != null) { + size += _single_doubleField109_codec.CalculateSizeWithTag(DoubleField109); + } + if (int64Field110_ != null) { + size += _single_int64Field110_codec.CalculateSizeWithTag(Int64Field110); + } + if (doubleField111_ != null) { + size += _single_doubleField111_codec.CalculateSizeWithTag(DoubleField111); + } + if (int64Field112_ != null) { + size += _single_int64Field112_codec.CalculateSizeWithTag(Int64Field112); + } + if (doubleField113_ != null) { + size += _single_doubleField113_codec.CalculateSizeWithTag(DoubleField113); + } + if (int64Field114_ != null) { + size += _single_int64Field114_codec.CalculateSizeWithTag(Int64Field114); + } + if (doubleField42_ != null) { + size += _single_doubleField42_codec.CalculateSizeWithTag(DoubleField42); + } + if (int64Field43_ != null) { + size += _single_int64Field43_codec.CalculateSizeWithTag(Int64Field43); + } + if (int64Field44_ != null) { + size += _single_int64Field44_codec.CalculateSizeWithTag(Int64Field44); + } + if (doubleField45_ != null) { + size += _single_doubleField45_codec.CalculateSizeWithTag(DoubleField45); + } + if (doubleField46_ != null) { + size += _single_doubleField46_codec.CalculateSizeWithTag(DoubleField46); + } + if (doubleField78_ != null) { + size += _single_doubleField78_codec.CalculateSizeWithTag(DoubleField78); + } + if (doubleField88_ != null) { + size += _single_doubleField88_codec.CalculateSizeWithTag(DoubleField88); + } + if (doubleField47_ != null) { + size += _single_doubleField47_codec.CalculateSizeWithTag(DoubleField47); + } + if (doubleField89_ != null) { + size += _single_doubleField89_codec.CalculateSizeWithTag(DoubleField89); + } + if (doubleField48_ != null) { + size += _single_doubleField48_codec.CalculateSizeWithTag(DoubleField48); + } + if (doubleField49_ != null) { + size += _single_doubleField49_codec.CalculateSizeWithTag(DoubleField49); + } + if (doubleField50_ != null) { + size += _single_doubleField50_codec.CalculateSizeWithTag(DoubleField50); + } + if (doubleField90_ != null) { + size += _single_doubleField90_codec.CalculateSizeWithTag(DoubleField90); + } + if (doubleField51_ != null) { + size += _single_doubleField51_codec.CalculateSizeWithTag(DoubleField51); + } + if (doubleField91_ != null) { + size += _single_doubleField91_codec.CalculateSizeWithTag(DoubleField91); + } + if (doubleField92_ != null) { + size += _single_doubleField92_codec.CalculateSizeWithTag(DoubleField92); + } + if (int64Field107_ != null) { + size += _single_int64Field107_codec.CalculateSizeWithTag(Int64Field107); + } + if (doubleField93_ != null) { + size += _single_doubleField93_codec.CalculateSizeWithTag(DoubleField93); + } + if (doubleField108_ != null) { + size += _single_doubleField108_codec.CalculateSizeWithTag(DoubleField108); + } + if (doubleField52_ != null) { + size += _single_doubleField52_codec.CalculateSizeWithTag(DoubleField52); + } + if (doubleField53_ != null) { + size += _single_doubleField53_codec.CalculateSizeWithTag(DoubleField53); + } + if (doubleField94_ != null) { + size += _single_doubleField94_codec.CalculateSizeWithTag(DoubleField94); + } + if (doubleField54_ != null) { + size += _single_doubleField54_codec.CalculateSizeWithTag(DoubleField54); + } + if (doubleField55_ != null) { + size += _single_doubleField55_codec.CalculateSizeWithTag(DoubleField55); + } + if (doubleField56_ != null) { + size += _single_doubleField56_codec.CalculateSizeWithTag(DoubleField56); + } + if (doubleField57_ != null) { + size += _single_doubleField57_codec.CalculateSizeWithTag(DoubleField57); + } + if (doubleField58_ != null) { + size += _single_doubleField58_codec.CalculateSizeWithTag(DoubleField58); + } + if (int64Field59_ != null) { + size += _single_int64Field59_codec.CalculateSizeWithTag(Int64Field59); + } + if (int64Field60_ != null) { + size += _single_int64Field60_codec.CalculateSizeWithTag(Int64Field60); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(ManyWrapperFieldsMessage other) { + if (other == null) { + return; + } + if (other.doubleField95_ != null) { + if (doubleField95_ == null || other.DoubleField95 != 0D) { + DoubleField95 = other.DoubleField95; + } + } + if (other.doubleField1_ != null) { + if (doubleField1_ == null || other.DoubleField1 != 0D) { + DoubleField1 = other.DoubleField1; + } + } + if (other.doubleField79_ != null) { + if (doubleField79_ == null || other.DoubleField79 != 0D) { + DoubleField79 = other.DoubleField79; + } + } + if (other.int64Field2_ != null) { + if (int64Field2_ == null || other.Int64Field2 != 0L) { + Int64Field2 = other.Int64Field2; + } + } + if (other.doubleField96_ != null) { + if (doubleField96_ == null || other.DoubleField96 != 0D) { + DoubleField96 = other.DoubleField96; + } + } + if (other.int64Field3_ != null) { + if (int64Field3_ == null || other.Int64Field3 != 0L) { + Int64Field3 = other.Int64Field3; + } + } + if (other.int64Field4_ != null) { + if (int64Field4_ == null || other.Int64Field4 != 0L) { + Int64Field4 = other.Int64Field4; + } + } + if (other.doubleField97_ != null) { + if (doubleField97_ == null || other.DoubleField97 != 0D) { + DoubleField97 = other.DoubleField97; + } + } + if (other.doubleField65_ != null) { + if (doubleField65_ == null || other.DoubleField65 != 0D) { + DoubleField65 = other.DoubleField65; + } + } + if (other.doubleField66_ != null) { + if (doubleField66_ == null || other.DoubleField66 != 0D) { + DoubleField66 = other.DoubleField66; + } + } + if (other.doubleField7_ != null) { + if (doubleField7_ == null || other.DoubleField7 != 0D) { + DoubleField7 = other.DoubleField7; + } + } + if (other.doubleField62_ != null) { + if (doubleField62_ == null || other.DoubleField62 != 0D) { + DoubleField62 = other.DoubleField62; + } + } + if (other.doubleField118_ != null) { + if (doubleField118_ == null || other.DoubleField118 != 0D) { + DoubleField118 = other.DoubleField118; + } + } + if (other.doubleField119_ != null) { + if (doubleField119_ == null || other.DoubleField119 != 0D) { + DoubleField119 = other.DoubleField119; + } + } + if (other.doubleField67_ != null) { + if (doubleField67_ == null || other.DoubleField67 != 0D) { + DoubleField67 = other.DoubleField67; + } + } + if (other.doubleField120_ != null) { + if (doubleField120_ == null || other.DoubleField120 != 0D) { + DoubleField120 = other.DoubleField120; + } + } + if (other.doubleField121_ != null) { + if (doubleField121_ == null || other.DoubleField121 != 0D) { + DoubleField121 = other.DoubleField121; + } + } + if (other.doubleField122_ != null) { + if (doubleField122_ == null || other.DoubleField122 != 0D) { + DoubleField122 = other.DoubleField122; + } + } + if (other.doubleField123_ != null) { + if (doubleField123_ == null || other.DoubleField123 != 0D) { + DoubleField123 = other.DoubleField123; + } + } + if (other.doubleField124_ != null) { + if (doubleField124_ == null || other.DoubleField124 != 0D) { + DoubleField124 = other.DoubleField124; + } + } + if (other.doubleField8_ != null) { + if (doubleField8_ == null || other.DoubleField8 != 0D) { + DoubleField8 = other.DoubleField8; + } + } + if (other.doubleField9_ != null) { + if (doubleField9_ == null || other.DoubleField9 != 0D) { + DoubleField9 = other.DoubleField9; + } + } + if (other.doubleField98_ != null) { + if (doubleField98_ == null || other.DoubleField98 != 0D) { + DoubleField98 = other.DoubleField98; + } + } + if (other.doubleField10_ != null) { + if (doubleField10_ == null || other.DoubleField10 != 0D) { + DoubleField10 = other.DoubleField10; + } + } + if (other.doubleField11_ != null) { + if (doubleField11_ == null || other.DoubleField11 != 0D) { + DoubleField11 = other.DoubleField11; + } + } + if (other.doubleField99_ != null) { + if (doubleField99_ == null || other.DoubleField99 != 0D) { + DoubleField99 = other.DoubleField99; + } + } + if (other.doubleField84_ != null) { + if (doubleField84_ == null || other.DoubleField84 != 0D) { + DoubleField84 = other.DoubleField84; + } + } + if (other.doubleField14_ != null) { + if (doubleField14_ == null || other.DoubleField14 != 0D) { + DoubleField14 = other.DoubleField14; + } + } + if (other.doubleField77_ != null) { + if (doubleField77_ == null || other.DoubleField77 != 0D) { + DoubleField77 = other.DoubleField77; + } + } + if (other.doubleField15_ != null) { + if (doubleField15_ == null || other.DoubleField15 != 0D) { + DoubleField15 = other.DoubleField15; + } + } + if (other.int64Field19_ != null) { + if (int64Field19_ == null || other.Int64Field19 != 0L) { + Int64Field19 = other.Int64Field19; + } + } + if (other.int64Field115_ != null) { + if (int64Field115_ == null || other.Int64Field115 != 0L) { + Int64Field115 = other.Int64Field115; + } + } + if (other.doubleField116_ != null) { + if (doubleField116_ == null || other.DoubleField116 != 0D) { + DoubleField116 = other.DoubleField116; + } + } + if (other.int64Field117_ != null) { + if (int64Field117_ == null || other.Int64Field117 != 0L) { + Int64Field117 = other.Int64Field117; + } + } + if (other.doubleField20_ != null) { + if (doubleField20_ == null || other.DoubleField20 != 0D) { + DoubleField20 = other.DoubleField20; + } + } + if (other.doubleField21_ != null) { + if (doubleField21_ == null || other.DoubleField21 != 0D) { + DoubleField21 = other.DoubleField21; + } + } + if (other.stringField73_ != null) { + if (stringField73_ == null || other.StringField73 != "") { + StringField73 = other.StringField73; + } + } + if (other.stringField74_ != null) { + if (stringField74_ == null || other.StringField74 != "") { + StringField74 = other.StringField74; + } + } + if (other.doubleField22_ != null) { + if (doubleField22_ == null || other.DoubleField22 != 0D) { + DoubleField22 = other.DoubleField22; + } + } + if (other.doubleField69_ != null) { + if (doubleField69_ == null || other.DoubleField69 != 0D) { + DoubleField69 = other.DoubleField69; + } + } + if (other.doubleField70_ != null) { + if (doubleField70_ == null || other.DoubleField70 != 0D) { + DoubleField70 = other.DoubleField70; + } + } + if (other.doubleField71_ != null) { + if (doubleField71_ == null || other.DoubleField71 != 0D) { + DoubleField71 = other.DoubleField71; + } + } + if (other.doubleField72_ != null) { + if (doubleField72_ == null || other.DoubleField72 != 0D) { + DoubleField72 = other.DoubleField72; + } + } + if (other.doubleField25_ != null) { + if (doubleField25_ == null || other.DoubleField25 != 0D) { + DoubleField25 = other.DoubleField25; + } + } + if (other.int64Field26_ != null) { + if (int64Field26_ == null || other.Int64Field26 != 0L) { + Int64Field26 = other.Int64Field26; + } + } + if (other.doubleField68_ != null) { + if (doubleField68_ == null || other.DoubleField68 != 0D) { + DoubleField68 = other.DoubleField68; + } + } + if (other.doubleField28_ != null) { + if (doubleField28_ == null || other.DoubleField28 != 0D) { + DoubleField28 = other.DoubleField28; + } + } + if (other.doubleField106_ != null) { + if (doubleField106_ == null || other.DoubleField106 != 0D) { + DoubleField106 = other.DoubleField106; + } + } + if (other.doubleField29_ != null) { + if (doubleField29_ == null || other.DoubleField29 != 0D) { + DoubleField29 = other.DoubleField29; + } + } + if (other.doubleField30_ != null) { + if (doubleField30_ == null || other.DoubleField30 != 0D) { + DoubleField30 = other.DoubleField30; + } + } + if (other.doubleField101_ != null) { + if (doubleField101_ == null || other.DoubleField101 != 0D) { + DoubleField101 = other.DoubleField101; + } + } + if (other.doubleField102_ != null) { + if (doubleField102_ == null || other.DoubleField102 != 0D) { + DoubleField102 = other.DoubleField102; + } + } + if (other.doubleField103_ != null) { + if (doubleField103_ == null || other.DoubleField103 != 0D) { + DoubleField103 = other.DoubleField103; + } + } + if (other.doubleField104_ != null) { + if (doubleField104_ == null || other.DoubleField104 != 0D) { + DoubleField104 = other.DoubleField104; + } + } + if (other.doubleField105_ != null) { + if (doubleField105_ == null || other.DoubleField105 != 0D) { + DoubleField105 = other.DoubleField105; + } + } + if (other.doubleField31_ != null) { + if (doubleField31_ == null || other.DoubleField31 != 0D) { + DoubleField31 = other.DoubleField31; + } + } + if (other.int64Field32_ != null) { + if (int64Field32_ == null || other.Int64Field32 != 0L) { + Int64Field32 = other.Int64Field32; + } + } + if (other.doubleField75_ != null) { + if (doubleField75_ == null || other.DoubleField75 != 0D) { + DoubleField75 = other.DoubleField75; + } + } + if (other.doubleField129_ != null) { + if (doubleField129_ == null || other.DoubleField129 != 0D) { + DoubleField129 = other.DoubleField129; + } + } + if (other.EnumField80 != 0) { + EnumField80 = other.EnumField80; + } + if (other.EnumField81 != 0) { + EnumField81 = other.EnumField81; + } + if (other.int64Field82_ != null) { + if (int64Field82_ == null || other.Int64Field82 != 0L) { + Int64Field82 = other.Int64Field82; + } + } + if (other.EnumField83 != 0) { + EnumField83 = other.EnumField83; + } + if (other.int64Field85_ != null) { + if (int64Field85_ == null || other.Int64Field85 != 0L) { + Int64Field85 = other.Int64Field85; + } + } + if (other.int64Field86_ != null) { + if (int64Field86_ == null || other.Int64Field86 != 0L) { + Int64Field86 = other.Int64Field86; + } + } + if (other.int64Field87_ != null) { + if (int64Field87_ == null || other.Int64Field87 != 0L) { + Int64Field87 = other.Int64Field87; + } + } + if (other.int64Field125_ != null) { + if (int64Field125_ == null || other.Int64Field125 != 0L) { + Int64Field125 = other.Int64Field125; + } + } + if (other.int64Field37_ != null) { + if (int64Field37_ == null || other.Int64Field37 != 0L) { + Int64Field37 = other.Int64Field37; + } + } + if (other.doubleField38_ != null) { + if (doubleField38_ == null || other.DoubleField38 != 0D) { + DoubleField38 = other.DoubleField38; + } + } + if (other.interactions_ != null) { + if (interactions_ == null || other.Interactions != 0L) { + Interactions = other.Interactions; + } + } + repeatedIntField100_.Add(other.repeatedIntField100_); + if (other.doubleField40_ != null) { + if (doubleField40_ == null || other.DoubleField40 != 0D) { + DoubleField40 = other.DoubleField40; + } + } + if (other.int64Field41_ != null) { + if (int64Field41_ == null || other.Int64Field41 != 0L) { + Int64Field41 = other.Int64Field41; + } + } + if (other.int64Field126_ != null) { + if (int64Field126_ == null || other.Int64Field126 != 0L) { + Int64Field126 = other.Int64Field126; + } + } + if (other.int64Field127_ != null) { + if (int64Field127_ == null || other.Int64Field127 != 0L) { + Int64Field127 = other.Int64Field127; + } + } + if (other.doubleField128_ != null) { + if (doubleField128_ == null || other.DoubleField128 != 0D) { + DoubleField128 = other.DoubleField128; + } + } + if (other.doubleField109_ != null) { + if (doubleField109_ == null || other.DoubleField109 != 0D) { + DoubleField109 = other.DoubleField109; + } + } + if (other.int64Field110_ != null) { + if (int64Field110_ == null || other.Int64Field110 != 0L) { + Int64Field110 = other.Int64Field110; + } + } + if (other.doubleField111_ != null) { + if (doubleField111_ == null || other.DoubleField111 != 0D) { + DoubleField111 = other.DoubleField111; + } + } + if (other.int64Field112_ != null) { + if (int64Field112_ == null || other.Int64Field112 != 0L) { + Int64Field112 = other.Int64Field112; + } + } + if (other.doubleField113_ != null) { + if (doubleField113_ == null || other.DoubleField113 != 0D) { + DoubleField113 = other.DoubleField113; + } + } + if (other.int64Field114_ != null) { + if (int64Field114_ == null || other.Int64Field114 != 0L) { + Int64Field114 = other.Int64Field114; + } + } + if (other.doubleField42_ != null) { + if (doubleField42_ == null || other.DoubleField42 != 0D) { + DoubleField42 = other.DoubleField42; + } + } + if (other.int64Field43_ != null) { + if (int64Field43_ == null || other.Int64Field43 != 0L) { + Int64Field43 = other.Int64Field43; + } + } + if (other.int64Field44_ != null) { + if (int64Field44_ == null || other.Int64Field44 != 0L) { + Int64Field44 = other.Int64Field44; + } + } + if (other.doubleField45_ != null) { + if (doubleField45_ == null || other.DoubleField45 != 0D) { + DoubleField45 = other.DoubleField45; + } + } + if (other.doubleField46_ != null) { + if (doubleField46_ == null || other.DoubleField46 != 0D) { + DoubleField46 = other.DoubleField46; + } + } + if (other.doubleField78_ != null) { + if (doubleField78_ == null || other.DoubleField78 != 0D) { + DoubleField78 = other.DoubleField78; + } + } + if (other.doubleField88_ != null) { + if (doubleField88_ == null || other.DoubleField88 != 0D) { + DoubleField88 = other.DoubleField88; + } + } + if (other.doubleField47_ != null) { + if (doubleField47_ == null || other.DoubleField47 != 0D) { + DoubleField47 = other.DoubleField47; + } + } + if (other.doubleField89_ != null) { + if (doubleField89_ == null || other.DoubleField89 != 0D) { + DoubleField89 = other.DoubleField89; + } + } + if (other.doubleField48_ != null) { + if (doubleField48_ == null || other.DoubleField48 != 0D) { + DoubleField48 = other.DoubleField48; + } + } + if (other.doubleField49_ != null) { + if (doubleField49_ == null || other.DoubleField49 != 0D) { + DoubleField49 = other.DoubleField49; + } + } + if (other.doubleField50_ != null) { + if (doubleField50_ == null || other.DoubleField50 != 0D) { + DoubleField50 = other.DoubleField50; + } + } + if (other.doubleField90_ != null) { + if (doubleField90_ == null || other.DoubleField90 != 0D) { + DoubleField90 = other.DoubleField90; + } + } + if (other.doubleField51_ != null) { + if (doubleField51_ == null || other.DoubleField51 != 0D) { + DoubleField51 = other.DoubleField51; + } + } + if (other.doubleField91_ != null) { + if (doubleField91_ == null || other.DoubleField91 != 0D) { + DoubleField91 = other.DoubleField91; + } + } + if (other.doubleField92_ != null) { + if (doubleField92_ == null || other.DoubleField92 != 0D) { + DoubleField92 = other.DoubleField92; + } + } + if (other.int64Field107_ != null) { + if (int64Field107_ == null || other.Int64Field107 != 0L) { + Int64Field107 = other.Int64Field107; + } + } + if (other.doubleField93_ != null) { + if (doubleField93_ == null || other.DoubleField93 != 0D) { + DoubleField93 = other.DoubleField93; + } + } + if (other.doubleField108_ != null) { + if (doubleField108_ == null || other.DoubleField108 != 0D) { + DoubleField108 = other.DoubleField108; + } + } + if (other.doubleField52_ != null) { + if (doubleField52_ == null || other.DoubleField52 != 0D) { + DoubleField52 = other.DoubleField52; + } + } + if (other.doubleField53_ != null) { + if (doubleField53_ == null || other.DoubleField53 != 0D) { + DoubleField53 = other.DoubleField53; + } + } + if (other.doubleField94_ != null) { + if (doubleField94_ == null || other.DoubleField94 != 0D) { + DoubleField94 = other.DoubleField94; + } + } + if (other.doubleField54_ != null) { + if (doubleField54_ == null || other.DoubleField54 != 0D) { + DoubleField54 = other.DoubleField54; + } + } + if (other.doubleField55_ != null) { + if (doubleField55_ == null || other.DoubleField55 != 0D) { + DoubleField55 = other.DoubleField55; + } + } + if (other.doubleField56_ != null) { + if (doubleField56_ == null || other.DoubleField56 != 0D) { + DoubleField56 = other.DoubleField56; + } + } + if (other.doubleField57_ != null) { + if (doubleField57_ == null || other.DoubleField57 != 0D) { + DoubleField57 = other.DoubleField57; + } + } + if (other.doubleField58_ != null) { + if (doubleField58_ == null || other.DoubleField58 != 0D) { + DoubleField58 = other.DoubleField58; + } + } + if (other.int64Field59_ != null) { + if (int64Field59_ == null || other.Int64Field59 != 0L) { + Int64Field59 = other.Int64Field59; + } + } + if (other.int64Field60_ != null) { + if (int64Field60_ == null || other.Int64Field60 != 0L) { + Int64Field60 = other.Int64Field60; + } + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + double? value = _single_doubleField1_codec.Read(input); + if (doubleField1_ == null || value != 0D) { + DoubleField1 = value; + } + break; + } + case 18: { + long? value = _single_int64Field2_codec.Read(input); + if (int64Field2_ == null || value != 0L) { + Int64Field2 = value; + } + break; + } + case 26: { + long? value = _single_int64Field3_codec.Read(input); + if (int64Field3_ == null || value != 0L) { + Int64Field3 = value; + } + break; + } + case 34: { + long? value = _single_int64Field4_codec.Read(input); + if (int64Field4_ == null || value != 0L) { + Int64Field4 = value; + } + break; + } + case 58: { + double? value = _single_doubleField7_codec.Read(input); + if (doubleField7_ == null || value != 0D) { + DoubleField7 = value; + } + break; + } + case 66: { + double? value = _single_doubleField8_codec.Read(input); + if (doubleField8_ == null || value != 0D) { + DoubleField8 = value; + } + break; + } + case 74: { + double? value = _single_doubleField9_codec.Read(input); + if (doubleField9_ == null || value != 0D) { + DoubleField9 = value; + } + break; + } + case 82: { + double? value = _single_doubleField10_codec.Read(input); + if (doubleField10_ == null || value != 0D) { + DoubleField10 = value; + } + break; + } + case 90: { + double? value = _single_doubleField11_codec.Read(input); + if (doubleField11_ == null || value != 0D) { + DoubleField11 = value; + } + break; + } + case 114: { + double? value = _single_doubleField14_codec.Read(input); + if (doubleField14_ == null || value != 0D) { + DoubleField14 = value; + } + break; + } + case 122: { + double? value = _single_doubleField15_codec.Read(input); + if (doubleField15_ == null || value != 0D) { + DoubleField15 = value; + } + break; + } + case 154: { + long? value = _single_int64Field19_codec.Read(input); + if (int64Field19_ == null || value != 0L) { + Int64Field19 = value; + } + break; + } + case 162: { + double? value = _single_doubleField20_codec.Read(input); + if (doubleField20_ == null || value != 0D) { + DoubleField20 = value; + } + break; + } + case 170: { + double? value = _single_doubleField21_codec.Read(input); + if (doubleField21_ == null || value != 0D) { + DoubleField21 = value; + } + break; + } + case 178: { + double? value = _single_doubleField22_codec.Read(input); + if (doubleField22_ == null || value != 0D) { + DoubleField22 = value; + } + break; + } + case 202: { + double? value = _single_doubleField25_codec.Read(input); + if (doubleField25_ == null || value != 0D) { + DoubleField25 = value; + } + break; + } + case 210: { + long? value = _single_int64Field26_codec.Read(input); + if (int64Field26_ == null || value != 0L) { + Int64Field26 = value; + } + break; + } + case 226: { + double? value = _single_doubleField28_codec.Read(input); + if (doubleField28_ == null || value != 0D) { + DoubleField28 = value; + } + break; + } + case 234: { + double? value = _single_doubleField29_codec.Read(input); + if (doubleField29_ == null || value != 0D) { + DoubleField29 = value; + } + break; + } + case 242: { + double? value = _single_doubleField30_codec.Read(input); + if (doubleField30_ == null || value != 0D) { + DoubleField30 = value; + } + break; + } + case 250: { + double? value = _single_doubleField31_codec.Read(input); + if (doubleField31_ == null || value != 0D) { + DoubleField31 = value; + } + break; + } + case 258: { + long? value = _single_int64Field32_codec.Read(input); + if (int64Field32_ == null || value != 0L) { + Int64Field32 = value; + } + break; + } + case 298: { + long? value = _single_int64Field37_codec.Read(input); + if (int64Field37_ == null || value != 0L) { + Int64Field37 = value; + } + break; + } + case 306: { + double? value = _single_doubleField38_codec.Read(input); + if (doubleField38_ == null || value != 0D) { + DoubleField38 = value; + } + break; + } + case 314: { + long? value = _single_interactions_codec.Read(input); + if (interactions_ == null || value != 0L) { + Interactions = value; + } + break; + } + case 322: { + double? value = _single_doubleField40_codec.Read(input); + if (doubleField40_ == null || value != 0D) { + DoubleField40 = value; + } + break; + } + case 330: { + long? value = _single_int64Field41_codec.Read(input); + if (int64Field41_ == null || value != 0L) { + Int64Field41 = value; + } + break; + } + case 338: { + double? value = _single_doubleField42_codec.Read(input); + if (doubleField42_ == null || value != 0D) { + DoubleField42 = value; + } + break; + } + case 346: { + long? value = _single_int64Field43_codec.Read(input); + if (int64Field43_ == null || value != 0L) { + Int64Field43 = value; + } + break; + } + case 354: { + long? value = _single_int64Field44_codec.Read(input); + if (int64Field44_ == null || value != 0L) { + Int64Field44 = value; + } + break; + } + case 362: { + double? value = _single_doubleField45_codec.Read(input); + if (doubleField45_ == null || value != 0D) { + DoubleField45 = value; + } + break; + } + case 370: { + double? value = _single_doubleField46_codec.Read(input); + if (doubleField46_ == null || value != 0D) { + DoubleField46 = value; + } + break; + } + case 378: { + double? value = _single_doubleField47_codec.Read(input); + if (doubleField47_ == null || value != 0D) { + DoubleField47 = value; + } + break; + } + case 386: { + double? value = _single_doubleField48_codec.Read(input); + if (doubleField48_ == null || value != 0D) { + DoubleField48 = value; + } + break; + } + case 394: { + double? value = _single_doubleField49_codec.Read(input); + if (doubleField49_ == null || value != 0D) { + DoubleField49 = value; + } + break; + } + case 402: { + double? value = _single_doubleField50_codec.Read(input); + if (doubleField50_ == null || value != 0D) { + DoubleField50 = value; + } + break; + } + case 410: { + double? value = _single_doubleField51_codec.Read(input); + if (doubleField51_ == null || value != 0D) { + DoubleField51 = value; + } + break; + } + case 418: { + double? value = _single_doubleField52_codec.Read(input); + if (doubleField52_ == null || value != 0D) { + DoubleField52 = value; + } + break; + } + case 426: { + double? value = _single_doubleField53_codec.Read(input); + if (doubleField53_ == null || value != 0D) { + DoubleField53 = value; + } + break; + } + case 434: { + double? value = _single_doubleField54_codec.Read(input); + if (doubleField54_ == null || value != 0D) { + DoubleField54 = value; + } + break; + } + case 442: { + double? value = _single_doubleField55_codec.Read(input); + if (doubleField55_ == null || value != 0D) { + DoubleField55 = value; + } + break; + } + case 450: { + double? value = _single_doubleField56_codec.Read(input); + if (doubleField56_ == null || value != 0D) { + DoubleField56 = value; + } + break; + } + case 458: { + double? value = _single_doubleField57_codec.Read(input); + if (doubleField57_ == null || value != 0D) { + DoubleField57 = value; + } + break; + } + case 466: { + double? value = _single_doubleField58_codec.Read(input); + if (doubleField58_ == null || value != 0D) { + DoubleField58 = value; + } + break; + } + case 474: { + long? value = _single_int64Field59_codec.Read(input); + if (int64Field59_ == null || value != 0L) { + Int64Field59 = value; + } + break; + } + case 482: { + long? value = _single_int64Field60_codec.Read(input); + if (int64Field60_ == null || value != 0L) { + Int64Field60 = value; + } + break; + } + case 498: { + double? value = _single_doubleField62_codec.Read(input); + if (doubleField62_ == null || value != 0D) { + DoubleField62 = value; + } + break; + } + case 522: { + double? value = _single_doubleField65_codec.Read(input); + if (doubleField65_ == null || value != 0D) { + DoubleField65 = value; + } + break; + } + case 530: { + double? value = _single_doubleField66_codec.Read(input); + if (doubleField66_ == null || value != 0D) { + DoubleField66 = value; + } + break; + } + case 538: { + double? value = _single_doubleField67_codec.Read(input); + if (doubleField67_ == null || value != 0D) { + DoubleField67 = value; + } + break; + } + case 546: { + double? value = _single_doubleField68_codec.Read(input); + if (doubleField68_ == null || value != 0D) { + DoubleField68 = value; + } + break; + } + case 554: { + double? value = _single_doubleField69_codec.Read(input); + if (doubleField69_ == null || value != 0D) { + DoubleField69 = value; + } + break; + } + case 562: { + double? value = _single_doubleField70_codec.Read(input); + if (doubleField70_ == null || value != 0D) { + DoubleField70 = value; + } + break; + } + case 570: { + double? value = _single_doubleField71_codec.Read(input); + if (doubleField71_ == null || value != 0D) { + DoubleField71 = value; + } + break; + } + case 578: { + double? value = _single_doubleField72_codec.Read(input); + if (doubleField72_ == null || value != 0D) { + DoubleField72 = value; + } + break; + } + case 586: { + string value = _single_stringField73_codec.Read(input); + if (stringField73_ == null || value != "") { + StringField73 = value; + } + break; + } + case 594: { + string value = _single_stringField74_codec.Read(input); + if (stringField74_ == null || value != "") { + StringField74 = value; + } + break; + } + case 602: { + double? value = _single_doubleField75_codec.Read(input); + if (doubleField75_ == null || value != 0D) { + DoubleField75 = value; + } + break; + } + case 618: { + double? value = _single_doubleField77_codec.Read(input); + if (doubleField77_ == null || value != 0D) { + DoubleField77 = value; + } + break; + } + case 626: { + double? value = _single_doubleField78_codec.Read(input); + if (doubleField78_ == null || value != 0D) { + DoubleField78 = value; + } + break; + } + case 634: { + double? value = _single_doubleField79_codec.Read(input); + if (doubleField79_ == null || value != 0D) { + DoubleField79 = value; + } + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 658: { + long? value = _single_int64Field82_codec.Read(input); + if (int64Field82_ == null || value != 0L) { + Int64Field82 = value; + } + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 674: { + double? value = _single_doubleField84_codec.Read(input); + if (doubleField84_ == null || value != 0D) { + DoubleField84 = value; + } + break; + } + case 682: { + long? value = _single_int64Field85_codec.Read(input); + if (int64Field85_ == null || value != 0L) { + Int64Field85 = value; + } + break; + } + case 690: { + long? value = _single_int64Field86_codec.Read(input); + if (int64Field86_ == null || value != 0L) { + Int64Field86 = value; + } + break; + } + case 698: { + long? value = _single_int64Field87_codec.Read(input); + if (int64Field87_ == null || value != 0L) { + Int64Field87 = value; + } + break; + } + case 706: { + double? value = _single_doubleField88_codec.Read(input); + if (doubleField88_ == null || value != 0D) { + DoubleField88 = value; + } + break; + } + case 714: { + double? value = _single_doubleField89_codec.Read(input); + if (doubleField89_ == null || value != 0D) { + DoubleField89 = value; + } + break; + } + case 722: { + double? value = _single_doubleField90_codec.Read(input); + if (doubleField90_ == null || value != 0D) { + DoubleField90 = value; + } + break; + } + case 730: { + double? value = _single_doubleField91_codec.Read(input); + if (doubleField91_ == null || value != 0D) { + DoubleField91 = value; + } + break; + } + case 738: { + double? value = _single_doubleField92_codec.Read(input); + if (doubleField92_ == null || value != 0D) { + DoubleField92 = value; + } + break; + } + case 746: { + double? value = _single_doubleField93_codec.Read(input); + if (doubleField93_ == null || value != 0D) { + DoubleField93 = value; + } + break; + } + case 754: { + double? value = _single_doubleField94_codec.Read(input); + if (doubleField94_ == null || value != 0D) { + DoubleField94 = value; + } + break; + } + case 762: { + double? value = _single_doubleField95_codec.Read(input); + if (doubleField95_ == null || value != 0D) { + DoubleField95 = value; + } + break; + } + case 770: { + double? value = _single_doubleField96_codec.Read(input); + if (doubleField96_ == null || value != 0D) { + DoubleField96 = value; + } + break; + } + case 778: { + double? value = _single_doubleField97_codec.Read(input); + if (doubleField97_ == null || value != 0D) { + DoubleField97 = value; + } + break; + } + case 786: { + double? value = _single_doubleField98_codec.Read(input); + if (doubleField98_ == null || value != 0D) { + DoubleField98 = value; + } + break; + } + case 794: { + double? value = _single_doubleField99_codec.Read(input); + if (doubleField99_ == null || value != 0D) { + DoubleField99 = value; + } + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(input, _repeated_repeatedIntField100_codec); + break; + } + case 810: { + double? value = _single_doubleField101_codec.Read(input); + if (doubleField101_ == null || value != 0D) { + DoubleField101 = value; + } + break; + } + case 818: { + double? value = _single_doubleField102_codec.Read(input); + if (doubleField102_ == null || value != 0D) { + DoubleField102 = value; + } + break; + } + case 826: { + double? value = _single_doubleField103_codec.Read(input); + if (doubleField103_ == null || value != 0D) { + DoubleField103 = value; + } + break; + } + case 834: { + double? value = _single_doubleField104_codec.Read(input); + if (doubleField104_ == null || value != 0D) { + DoubleField104 = value; + } + break; + } + case 842: { + double? value = _single_doubleField105_codec.Read(input); + if (doubleField105_ == null || value != 0D) { + DoubleField105 = value; + } + break; + } + case 850: { + double? value = _single_doubleField106_codec.Read(input); + if (doubleField106_ == null || value != 0D) { + DoubleField106 = value; + } + break; + } + case 858: { + long? value = _single_int64Field107_codec.Read(input); + if (int64Field107_ == null || value != 0L) { + Int64Field107 = value; + } + break; + } + case 866: { + double? value = _single_doubleField108_codec.Read(input); + if (doubleField108_ == null || value != 0D) { + DoubleField108 = value; + } + break; + } + case 874: { + double? value = _single_doubleField109_codec.Read(input); + if (doubleField109_ == null || value != 0D) { + DoubleField109 = value; + } + break; + } + case 882: { + long? value = _single_int64Field110_codec.Read(input); + if (int64Field110_ == null || value != 0L) { + Int64Field110 = value; + } + break; + } + case 890: { + double? value = _single_doubleField111_codec.Read(input); + if (doubleField111_ == null || value != 0D) { + DoubleField111 = value; + } + break; + } + case 898: { + long? value = _single_int64Field112_codec.Read(input); + if (int64Field112_ == null || value != 0L) { + Int64Field112 = value; + } + break; + } + case 906: { + double? value = _single_doubleField113_codec.Read(input); + if (doubleField113_ == null || value != 0D) { + DoubleField113 = value; + } + break; + } + case 914: { + long? value = _single_int64Field114_codec.Read(input); + if (int64Field114_ == null || value != 0L) { + Int64Field114 = value; + } + break; + } + case 922: { + long? value = _single_int64Field115_codec.Read(input); + if (int64Field115_ == null || value != 0L) { + Int64Field115 = value; + } + break; + } + case 930: { + double? value = _single_doubleField116_codec.Read(input); + if (doubleField116_ == null || value != 0D) { + DoubleField116 = value; + } + break; + } + case 938: { + long? value = _single_int64Field117_codec.Read(input); + if (int64Field117_ == null || value != 0L) { + Int64Field117 = value; + } + break; + } + case 946: { + double? value = _single_doubleField118_codec.Read(input); + if (doubleField118_ == null || value != 0D) { + DoubleField118 = value; + } + break; + } + case 954: { + double? value = _single_doubleField119_codec.Read(input); + if (doubleField119_ == null || value != 0D) { + DoubleField119 = value; + } + break; + } + case 962: { + double? value = _single_doubleField120_codec.Read(input); + if (doubleField120_ == null || value != 0D) { + DoubleField120 = value; + } + break; + } + case 970: { + double? value = _single_doubleField121_codec.Read(input); + if (doubleField121_ == null || value != 0D) { + DoubleField121 = value; + } + break; + } + case 978: { + double? value = _single_doubleField122_codec.Read(input); + if (doubleField122_ == null || value != 0D) { + DoubleField122 = value; + } + break; + } + case 986: { + double? value = _single_doubleField123_codec.Read(input); + if (doubleField123_ == null || value != 0D) { + DoubleField123 = value; + } + break; + } + case 994: { + double? value = _single_doubleField124_codec.Read(input); + if (doubleField124_ == null || value != 0D) { + DoubleField124 = value; + } + break; + } + case 1002: { + long? value = _single_int64Field125_codec.Read(input); + if (int64Field125_ == null || value != 0L) { + Int64Field125 = value; + } + break; + } + case 1010: { + long? value = _single_int64Field126_codec.Read(input); + if (int64Field126_ == null || value != 0L) { + Int64Field126 = value; + } + break; + } + case 1018: { + long? value = _single_int64Field127_codec.Read(input); + if (int64Field127_ == null || value != 0L) { + Int64Field127 = value; + } + break; + } + case 1026: { + double? value = _single_doubleField128_codec.Read(input); + if (doubleField128_ == null || value != 0D) { + DoubleField128 = value; + } + break; + } + case 1034: { + double? value = _single_doubleField129_codec.Read(input); + if (doubleField129_ == null || value != 0D) { + DoubleField129 = value; + } + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + double? value = _single_doubleField1_codec.Read(ref input); + if (doubleField1_ == null || value != 0D) { + DoubleField1 = value; + } + break; + } + case 18: { + long? value = _single_int64Field2_codec.Read(ref input); + if (int64Field2_ == null || value != 0L) { + Int64Field2 = value; + } + break; + } + case 26: { + long? value = _single_int64Field3_codec.Read(ref input); + if (int64Field3_ == null || value != 0L) { + Int64Field3 = value; + } + break; + } + case 34: { + long? value = _single_int64Field4_codec.Read(ref input); + if (int64Field4_ == null || value != 0L) { + Int64Field4 = value; + } + break; + } + case 58: { + double? value = _single_doubleField7_codec.Read(ref input); + if (doubleField7_ == null || value != 0D) { + DoubleField7 = value; + } + break; + } + case 66: { + double? value = _single_doubleField8_codec.Read(ref input); + if (doubleField8_ == null || value != 0D) { + DoubleField8 = value; + } + break; + } + case 74: { + double? value = _single_doubleField9_codec.Read(ref input); + if (doubleField9_ == null || value != 0D) { + DoubleField9 = value; + } + break; + } + case 82: { + double? value = _single_doubleField10_codec.Read(ref input); + if (doubleField10_ == null || value != 0D) { + DoubleField10 = value; + } + break; + } + case 90: { + double? value = _single_doubleField11_codec.Read(ref input); + if (doubleField11_ == null || value != 0D) { + DoubleField11 = value; + } + break; + } + case 114: { + double? value = _single_doubleField14_codec.Read(ref input); + if (doubleField14_ == null || value != 0D) { + DoubleField14 = value; + } + break; + } + case 122: { + double? value = _single_doubleField15_codec.Read(ref input); + if (doubleField15_ == null || value != 0D) { + DoubleField15 = value; + } + break; + } + case 154: { + long? value = _single_int64Field19_codec.Read(ref input); + if (int64Field19_ == null || value != 0L) { + Int64Field19 = value; + } + break; + } + case 162: { + double? value = _single_doubleField20_codec.Read(ref input); + if (doubleField20_ == null || value != 0D) { + DoubleField20 = value; + } + break; + } + case 170: { + double? value = _single_doubleField21_codec.Read(ref input); + if (doubleField21_ == null || value != 0D) { + DoubleField21 = value; + } + break; + } + case 178: { + double? value = _single_doubleField22_codec.Read(ref input); + if (doubleField22_ == null || value != 0D) { + DoubleField22 = value; + } + break; + } + case 202: { + double? value = _single_doubleField25_codec.Read(ref input); + if (doubleField25_ == null || value != 0D) { + DoubleField25 = value; + } + break; + } + case 210: { + long? value = _single_int64Field26_codec.Read(ref input); + if (int64Field26_ == null || value != 0L) { + Int64Field26 = value; + } + break; + } + case 226: { + double? value = _single_doubleField28_codec.Read(ref input); + if (doubleField28_ == null || value != 0D) { + DoubleField28 = value; + } + break; + } + case 234: { + double? value = _single_doubleField29_codec.Read(ref input); + if (doubleField29_ == null || value != 0D) { + DoubleField29 = value; + } + break; + } + case 242: { + double? value = _single_doubleField30_codec.Read(ref input); + if (doubleField30_ == null || value != 0D) { + DoubleField30 = value; + } + break; + } + case 250: { + double? value = _single_doubleField31_codec.Read(ref input); + if (doubleField31_ == null || value != 0D) { + DoubleField31 = value; + } + break; + } + case 258: { + long? value = _single_int64Field32_codec.Read(ref input); + if (int64Field32_ == null || value != 0L) { + Int64Field32 = value; + } + break; + } + case 298: { + long? value = _single_int64Field37_codec.Read(ref input); + if (int64Field37_ == null || value != 0L) { + Int64Field37 = value; + } + break; + } + case 306: { + double? value = _single_doubleField38_codec.Read(ref input); + if (doubleField38_ == null || value != 0D) { + DoubleField38 = value; + } + break; + } + case 314: { + long? value = _single_interactions_codec.Read(ref input); + if (interactions_ == null || value != 0L) { + Interactions = value; + } + break; + } + case 322: { + double? value = _single_doubleField40_codec.Read(ref input); + if (doubleField40_ == null || value != 0D) { + DoubleField40 = value; + } + break; + } + case 330: { + long? value = _single_int64Field41_codec.Read(ref input); + if (int64Field41_ == null || value != 0L) { + Int64Field41 = value; + } + break; + } + case 338: { + double? value = _single_doubleField42_codec.Read(ref input); + if (doubleField42_ == null || value != 0D) { + DoubleField42 = value; + } + break; + } + case 346: { + long? value = _single_int64Field43_codec.Read(ref input); + if (int64Field43_ == null || value != 0L) { + Int64Field43 = value; + } + break; + } + case 354: { + long? value = _single_int64Field44_codec.Read(ref input); + if (int64Field44_ == null || value != 0L) { + Int64Field44 = value; + } + break; + } + case 362: { + double? value = _single_doubleField45_codec.Read(ref input); + if (doubleField45_ == null || value != 0D) { + DoubleField45 = value; + } + break; + } + case 370: { + double? value = _single_doubleField46_codec.Read(ref input); + if (doubleField46_ == null || value != 0D) { + DoubleField46 = value; + } + break; + } + case 378: { + double? value = _single_doubleField47_codec.Read(ref input); + if (doubleField47_ == null || value != 0D) { + DoubleField47 = value; + } + break; + } + case 386: { + double? value = _single_doubleField48_codec.Read(ref input); + if (doubleField48_ == null || value != 0D) { + DoubleField48 = value; + } + break; + } + case 394: { + double? value = _single_doubleField49_codec.Read(ref input); + if (doubleField49_ == null || value != 0D) { + DoubleField49 = value; + } + break; + } + case 402: { + double? value = _single_doubleField50_codec.Read(ref input); + if (doubleField50_ == null || value != 0D) { + DoubleField50 = value; + } + break; + } + case 410: { + double? value = _single_doubleField51_codec.Read(ref input); + if (doubleField51_ == null || value != 0D) { + DoubleField51 = value; + } + break; + } + case 418: { + double? value = _single_doubleField52_codec.Read(ref input); + if (doubleField52_ == null || value != 0D) { + DoubleField52 = value; + } + break; + } + case 426: { + double? value = _single_doubleField53_codec.Read(ref input); + if (doubleField53_ == null || value != 0D) { + DoubleField53 = value; + } + break; + } + case 434: { + double? value = _single_doubleField54_codec.Read(ref input); + if (doubleField54_ == null || value != 0D) { + DoubleField54 = value; + } + break; + } + case 442: { + double? value = _single_doubleField55_codec.Read(ref input); + if (doubleField55_ == null || value != 0D) { + DoubleField55 = value; + } + break; + } + case 450: { + double? value = _single_doubleField56_codec.Read(ref input); + if (doubleField56_ == null || value != 0D) { + DoubleField56 = value; + } + break; + } + case 458: { + double? value = _single_doubleField57_codec.Read(ref input); + if (doubleField57_ == null || value != 0D) { + DoubleField57 = value; + } + break; + } + case 466: { + double? value = _single_doubleField58_codec.Read(ref input); + if (doubleField58_ == null || value != 0D) { + DoubleField58 = value; + } + break; + } + case 474: { + long? value = _single_int64Field59_codec.Read(ref input); + if (int64Field59_ == null || value != 0L) { + Int64Field59 = value; + } + break; + } + case 482: { + long? value = _single_int64Field60_codec.Read(ref input); + if (int64Field60_ == null || value != 0L) { + Int64Field60 = value; + } + break; + } + case 498: { + double? value = _single_doubleField62_codec.Read(ref input); + if (doubleField62_ == null || value != 0D) { + DoubleField62 = value; + } + break; + } + case 522: { + double? value = _single_doubleField65_codec.Read(ref input); + if (doubleField65_ == null || value != 0D) { + DoubleField65 = value; + } + break; + } + case 530: { + double? value = _single_doubleField66_codec.Read(ref input); + if (doubleField66_ == null || value != 0D) { + DoubleField66 = value; + } + break; + } + case 538: { + double? value = _single_doubleField67_codec.Read(ref input); + if (doubleField67_ == null || value != 0D) { + DoubleField67 = value; + } + break; + } + case 546: { + double? value = _single_doubleField68_codec.Read(ref input); + if (doubleField68_ == null || value != 0D) { + DoubleField68 = value; + } + break; + } + case 554: { + double? value = _single_doubleField69_codec.Read(ref input); + if (doubleField69_ == null || value != 0D) { + DoubleField69 = value; + } + break; + } + case 562: { + double? value = _single_doubleField70_codec.Read(ref input); + if (doubleField70_ == null || value != 0D) { + DoubleField70 = value; + } + break; + } + case 570: { + double? value = _single_doubleField71_codec.Read(ref input); + if (doubleField71_ == null || value != 0D) { + DoubleField71 = value; + } + break; + } + case 578: { + double? value = _single_doubleField72_codec.Read(ref input); + if (doubleField72_ == null || value != 0D) { + DoubleField72 = value; + } + break; + } + case 586: { + string value = _single_stringField73_codec.Read(ref input); + if (stringField73_ == null || value != "") { + StringField73 = value; + } + break; + } + case 594: { + string value = _single_stringField74_codec.Read(ref input); + if (stringField74_ == null || value != "") { + StringField74 = value; + } + break; + } + case 602: { + double? value = _single_doubleField75_codec.Read(ref input); + if (doubleField75_ == null || value != 0D) { + DoubleField75 = value; + } + break; + } + case 618: { + double? value = _single_doubleField77_codec.Read(ref input); + if (doubleField77_ == null || value != 0D) { + DoubleField77 = value; + } + break; + } + case 626: { + double? value = _single_doubleField78_codec.Read(ref input); + if (doubleField78_ == null || value != 0D) { + DoubleField78 = value; + } + break; + } + case 634: { + double? value = _single_doubleField79_codec.Read(ref input); + if (doubleField79_ == null || value != 0D) { + DoubleField79 = value; + } + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 658: { + long? value = _single_int64Field82_codec.Read(ref input); + if (int64Field82_ == null || value != 0L) { + Int64Field82 = value; + } + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 674: { + double? value = _single_doubleField84_codec.Read(ref input); + if (doubleField84_ == null || value != 0D) { + DoubleField84 = value; + } + break; + } + case 682: { + long? value = _single_int64Field85_codec.Read(ref input); + if (int64Field85_ == null || value != 0L) { + Int64Field85 = value; + } + break; + } + case 690: { + long? value = _single_int64Field86_codec.Read(ref input); + if (int64Field86_ == null || value != 0L) { + Int64Field86 = value; + } + break; + } + case 698: { + long? value = _single_int64Field87_codec.Read(ref input); + if (int64Field87_ == null || value != 0L) { + Int64Field87 = value; + } + break; + } + case 706: { + double? value = _single_doubleField88_codec.Read(ref input); + if (doubleField88_ == null || value != 0D) { + DoubleField88 = value; + } + break; + } + case 714: { + double? value = _single_doubleField89_codec.Read(ref input); + if (doubleField89_ == null || value != 0D) { + DoubleField89 = value; + } + break; + } + case 722: { + double? value = _single_doubleField90_codec.Read(ref input); + if (doubleField90_ == null || value != 0D) { + DoubleField90 = value; + } + break; + } + case 730: { + double? value = _single_doubleField91_codec.Read(ref input); + if (doubleField91_ == null || value != 0D) { + DoubleField91 = value; + } + break; + } + case 738: { + double? value = _single_doubleField92_codec.Read(ref input); + if (doubleField92_ == null || value != 0D) { + DoubleField92 = value; + } + break; + } + case 746: { + double? value = _single_doubleField93_codec.Read(ref input); + if (doubleField93_ == null || value != 0D) { + DoubleField93 = value; + } + break; + } + case 754: { + double? value = _single_doubleField94_codec.Read(ref input); + if (doubleField94_ == null || value != 0D) { + DoubleField94 = value; + } + break; + } + case 762: { + double? value = _single_doubleField95_codec.Read(ref input); + if (doubleField95_ == null || value != 0D) { + DoubleField95 = value; + } + break; + } + case 770: { + double? value = _single_doubleField96_codec.Read(ref input); + if (doubleField96_ == null || value != 0D) { + DoubleField96 = value; + } + break; + } + case 778: { + double? value = _single_doubleField97_codec.Read(ref input); + if (doubleField97_ == null || value != 0D) { + DoubleField97 = value; + } + break; + } + case 786: { + double? value = _single_doubleField98_codec.Read(ref input); + if (doubleField98_ == null || value != 0D) { + DoubleField98 = value; + } + break; + } + case 794: { + double? value = _single_doubleField99_codec.Read(ref input); + if (doubleField99_ == null || value != 0D) { + DoubleField99 = value; + } + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(ref input, _repeated_repeatedIntField100_codec); + break; + } + case 810: { + double? value = _single_doubleField101_codec.Read(ref input); + if (doubleField101_ == null || value != 0D) { + DoubleField101 = value; + } + break; + } + case 818: { + double? value = _single_doubleField102_codec.Read(ref input); + if (doubleField102_ == null || value != 0D) { + DoubleField102 = value; + } + break; + } + case 826: { + double? value = _single_doubleField103_codec.Read(ref input); + if (doubleField103_ == null || value != 0D) { + DoubleField103 = value; + } + break; + } + case 834: { + double? value = _single_doubleField104_codec.Read(ref input); + if (doubleField104_ == null || value != 0D) { + DoubleField104 = value; + } + break; + } + case 842: { + double? value = _single_doubleField105_codec.Read(ref input); + if (doubleField105_ == null || value != 0D) { + DoubleField105 = value; + } + break; + } + case 850: { + double? value = _single_doubleField106_codec.Read(ref input); + if (doubleField106_ == null || value != 0D) { + DoubleField106 = value; + } + break; + } + case 858: { + long? value = _single_int64Field107_codec.Read(ref input); + if (int64Field107_ == null || value != 0L) { + Int64Field107 = value; + } + break; + } + case 866: { + double? value = _single_doubleField108_codec.Read(ref input); + if (doubleField108_ == null || value != 0D) { + DoubleField108 = value; + } + break; + } + case 874: { + double? value = _single_doubleField109_codec.Read(ref input); + if (doubleField109_ == null || value != 0D) { + DoubleField109 = value; + } + break; + } + case 882: { + long? value = _single_int64Field110_codec.Read(ref input); + if (int64Field110_ == null || value != 0L) { + Int64Field110 = value; + } + break; + } + case 890: { + double? value = _single_doubleField111_codec.Read(ref input); + if (doubleField111_ == null || value != 0D) { + DoubleField111 = value; + } + break; + } + case 898: { + long? value = _single_int64Field112_codec.Read(ref input); + if (int64Field112_ == null || value != 0L) { + Int64Field112 = value; + } + break; + } + case 906: { + double? value = _single_doubleField113_codec.Read(ref input); + if (doubleField113_ == null || value != 0D) { + DoubleField113 = value; + } + break; + } + case 914: { + long? value = _single_int64Field114_codec.Read(ref input); + if (int64Field114_ == null || value != 0L) { + Int64Field114 = value; + } + break; + } + case 922: { + long? value = _single_int64Field115_codec.Read(ref input); + if (int64Field115_ == null || value != 0L) { + Int64Field115 = value; + } + break; + } + case 930: { + double? value = _single_doubleField116_codec.Read(ref input); + if (doubleField116_ == null || value != 0D) { + DoubleField116 = value; + } + break; + } + case 938: { + long? value = _single_int64Field117_codec.Read(ref input); + if (int64Field117_ == null || value != 0L) { + Int64Field117 = value; + } + break; + } + case 946: { + double? value = _single_doubleField118_codec.Read(ref input); + if (doubleField118_ == null || value != 0D) { + DoubleField118 = value; + } + break; + } + case 954: { + double? value = _single_doubleField119_codec.Read(ref input); + if (doubleField119_ == null || value != 0D) { + DoubleField119 = value; + } + break; + } + case 962: { + double? value = _single_doubleField120_codec.Read(ref input); + if (doubleField120_ == null || value != 0D) { + DoubleField120 = value; + } + break; + } + case 970: { + double? value = _single_doubleField121_codec.Read(ref input); + if (doubleField121_ == null || value != 0D) { + DoubleField121 = value; + } + break; + } + case 978: { + double? value = _single_doubleField122_codec.Read(ref input); + if (doubleField122_ == null || value != 0D) { + DoubleField122 = value; + } + break; + } + case 986: { + double? value = _single_doubleField123_codec.Read(ref input); + if (doubleField123_ == null || value != 0D) { + DoubleField123 = value; + } + break; + } + case 994: { + double? value = _single_doubleField124_codec.Read(ref input); + if (doubleField124_ == null || value != 0D) { + DoubleField124 = value; + } + break; + } + case 1002: { + long? value = _single_int64Field125_codec.Read(ref input); + if (int64Field125_ == null || value != 0L) { + Int64Field125 = value; + } + break; + } + case 1010: { + long? value = _single_int64Field126_codec.Read(ref input); + if (int64Field126_ == null || value != 0L) { + Int64Field126 = value; + } + break; + } + case 1018: { + long? value = _single_int64Field127_codec.Read(ref input); + if (int64Field127_ == null || value != 0L) { + Int64Field127 = value; + } + break; + } + case 1026: { + double? value = _single_doubleField128_codec.Read(ref input); + if (doubleField128_ == null || value != 0D) { + DoubleField128 = value; + } + break; + } + case 1034: { + double? value = _single_doubleField129_codec.Read(ref input); + if (doubleField129_ == null || value != 0D) { + DoubleField129 = value; + } + break; + } + } + } + } + #endif + + } + + /// + /// same as ManyWrapperFieldsMessages, but with primitive fields + /// for comparison. + /// + public sealed partial class ManyPrimitiveFieldsMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ManyPrimitiveFieldsMessage()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Benchmarks.WrapperBenchmarkMessagesReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyPrimitiveFieldsMessage() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyPrimitiveFieldsMessage(ManyPrimitiveFieldsMessage other) : this() { + doubleField95_ = other.doubleField95_; + doubleField1_ = other.doubleField1_; + doubleField79_ = other.doubleField79_; + int64Field2_ = other.int64Field2_; + doubleField96_ = other.doubleField96_; + int64Field3_ = other.int64Field3_; + int64Field4_ = other.int64Field4_; + doubleField97_ = other.doubleField97_; + doubleField65_ = other.doubleField65_; + doubleField66_ = other.doubleField66_; + doubleField7_ = other.doubleField7_; + doubleField62_ = other.doubleField62_; + doubleField118_ = other.doubleField118_; + doubleField119_ = other.doubleField119_; + doubleField67_ = other.doubleField67_; + doubleField120_ = other.doubleField120_; + doubleField121_ = other.doubleField121_; + doubleField122_ = other.doubleField122_; + doubleField123_ = other.doubleField123_; + doubleField124_ = other.doubleField124_; + doubleField8_ = other.doubleField8_; + doubleField9_ = other.doubleField9_; + doubleField98_ = other.doubleField98_; + doubleField10_ = other.doubleField10_; + doubleField11_ = other.doubleField11_; + doubleField99_ = other.doubleField99_; + doubleField84_ = other.doubleField84_; + doubleField14_ = other.doubleField14_; + doubleField77_ = other.doubleField77_; + doubleField15_ = other.doubleField15_; + int64Field19_ = other.int64Field19_; + int64Field115_ = other.int64Field115_; + doubleField116_ = other.doubleField116_; + int64Field117_ = other.int64Field117_; + doubleField20_ = other.doubleField20_; + doubleField21_ = other.doubleField21_; + stringField73_ = other.stringField73_; + stringField74_ = other.stringField74_; + doubleField22_ = other.doubleField22_; + doubleField69_ = other.doubleField69_; + doubleField70_ = other.doubleField70_; + doubleField71_ = other.doubleField71_; + doubleField72_ = other.doubleField72_; + doubleField25_ = other.doubleField25_; + int64Field26_ = other.int64Field26_; + doubleField68_ = other.doubleField68_; + doubleField28_ = other.doubleField28_; + doubleField106_ = other.doubleField106_; + doubleField29_ = other.doubleField29_; + doubleField30_ = other.doubleField30_; + doubleField101_ = other.doubleField101_; + doubleField102_ = other.doubleField102_; + doubleField103_ = other.doubleField103_; + doubleField104_ = other.doubleField104_; + doubleField105_ = other.doubleField105_; + doubleField31_ = other.doubleField31_; + int64Field32_ = other.int64Field32_; + doubleField75_ = other.doubleField75_; + doubleField129_ = other.doubleField129_; + enumField80_ = other.enumField80_; + enumField81_ = other.enumField81_; + int64Field82_ = other.int64Field82_; + enumField83_ = other.enumField83_; + int64Field85_ = other.int64Field85_; + int64Field86_ = other.int64Field86_; + int64Field87_ = other.int64Field87_; + int64Field125_ = other.int64Field125_; + int64Field37_ = other.int64Field37_; + doubleField38_ = other.doubleField38_; + interactions_ = other.interactions_; + repeatedIntField100_ = other.repeatedIntField100_.Clone(); + doubleField40_ = other.doubleField40_; + int64Field41_ = other.int64Field41_; + int64Field126_ = other.int64Field126_; + int64Field127_ = other.int64Field127_; + doubleField128_ = other.doubleField128_; + doubleField109_ = other.doubleField109_; + int64Field110_ = other.int64Field110_; + doubleField111_ = other.doubleField111_; + int64Field112_ = other.int64Field112_; + doubleField113_ = other.doubleField113_; + int64Field114_ = other.int64Field114_; + doubleField42_ = other.doubleField42_; + int64Field43_ = other.int64Field43_; + int64Field44_ = other.int64Field44_; + doubleField45_ = other.doubleField45_; + doubleField46_ = other.doubleField46_; + doubleField78_ = other.doubleField78_; + doubleField88_ = other.doubleField88_; + doubleField47_ = other.doubleField47_; + doubleField89_ = other.doubleField89_; + doubleField48_ = other.doubleField48_; + doubleField49_ = other.doubleField49_; + doubleField50_ = other.doubleField50_; + doubleField90_ = other.doubleField90_; + doubleField51_ = other.doubleField51_; + doubleField91_ = other.doubleField91_; + doubleField92_ = other.doubleField92_; + int64Field107_ = other.int64Field107_; + doubleField93_ = other.doubleField93_; + doubleField108_ = other.doubleField108_; + doubleField52_ = other.doubleField52_; + doubleField53_ = other.doubleField53_; + doubleField94_ = other.doubleField94_; + doubleField54_ = other.doubleField54_; + doubleField55_ = other.doubleField55_; + doubleField56_ = other.doubleField56_; + doubleField57_ = other.doubleField57_; + doubleField58_ = other.doubleField58_; + int64Field59_ = other.int64Field59_; + int64Field60_ = other.int64Field60_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ManyPrimitiveFieldsMessage Clone() { + return new ManyPrimitiveFieldsMessage(this); + } + + /// Field number for the "double_field_95" field. + public const int DoubleField95FieldNumber = 95; + private double doubleField95_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField95 { + get { return doubleField95_; } + set { + doubleField95_ = value; + } + } + + /// Field number for the "double_field_1" field. + public const int DoubleField1FieldNumber = 1; + private double doubleField1_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField1 { + get { return doubleField1_; } + set { + doubleField1_ = value; + } + } + + /// Field number for the "double_field_79" field. + public const int DoubleField79FieldNumber = 79; + private double doubleField79_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField79 { + get { return doubleField79_; } + set { + doubleField79_ = value; + } + } + + /// Field number for the "int64_field_2" field. + public const int Int64Field2FieldNumber = 2; + private long int64Field2_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field2 { + get { return int64Field2_; } + set { + int64Field2_ = value; + } + } + + /// Field number for the "double_field_96" field. + public const int DoubleField96FieldNumber = 96; + private double doubleField96_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField96 { + get { return doubleField96_; } + set { + doubleField96_ = value; + } + } + + /// Field number for the "int64_field_3" field. + public const int Int64Field3FieldNumber = 3; + private long int64Field3_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field3 { + get { return int64Field3_; } + set { + int64Field3_ = value; + } + } + + /// Field number for the "int64_field_4" field. + public const int Int64Field4FieldNumber = 4; + private long int64Field4_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field4 { + get { return int64Field4_; } + set { + int64Field4_ = value; + } + } + + /// Field number for the "double_field_97" field. + public const int DoubleField97FieldNumber = 97; + private double doubleField97_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField97 { + get { return doubleField97_; } + set { + doubleField97_ = value; + } + } + + /// Field number for the "double_field_65" field. + public const int DoubleField65FieldNumber = 65; + private double doubleField65_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField65 { + get { return doubleField65_; } + set { + doubleField65_ = value; + } + } + + /// Field number for the "double_field_66" field. + public const int DoubleField66FieldNumber = 66; + private double doubleField66_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField66 { + get { return doubleField66_; } + set { + doubleField66_ = value; + } + } + + /// Field number for the "double_field_7" field. + public const int DoubleField7FieldNumber = 7; + private double doubleField7_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField7 { + get { return doubleField7_; } + set { + doubleField7_ = value; + } + } + + /// Field number for the "double_field_62" field. + public const int DoubleField62FieldNumber = 62; + private double doubleField62_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField62 { + get { return doubleField62_; } + set { + doubleField62_ = value; + } + } + + /// Field number for the "double_field_118" field. + public const int DoubleField118FieldNumber = 118; + private double doubleField118_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField118 { + get { return doubleField118_; } + set { + doubleField118_ = value; + } + } + + /// Field number for the "double_field_119" field. + public const int DoubleField119FieldNumber = 119; + private double doubleField119_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField119 { + get { return doubleField119_; } + set { + doubleField119_ = value; + } + } + + /// Field number for the "double_field_67" field. + public const int DoubleField67FieldNumber = 67; + private double doubleField67_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField67 { + get { return doubleField67_; } + set { + doubleField67_ = value; + } + } + + /// Field number for the "double_field_120" field. + public const int DoubleField120FieldNumber = 120; + private double doubleField120_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField120 { + get { return doubleField120_; } + set { + doubleField120_ = value; + } + } + + /// Field number for the "double_field_121" field. + public const int DoubleField121FieldNumber = 121; + private double doubleField121_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField121 { + get { return doubleField121_; } + set { + doubleField121_ = value; + } + } + + /// Field number for the "double_field_122" field. + public const int DoubleField122FieldNumber = 122; + private double doubleField122_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField122 { + get { return doubleField122_; } + set { + doubleField122_ = value; + } + } + + /// Field number for the "double_field_123" field. + public const int DoubleField123FieldNumber = 123; + private double doubleField123_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField123 { + get { return doubleField123_; } + set { + doubleField123_ = value; + } + } + + /// Field number for the "double_field_124" field. + public const int DoubleField124FieldNumber = 124; + private double doubleField124_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField124 { + get { return doubleField124_; } + set { + doubleField124_ = value; + } + } + + /// Field number for the "double_field_8" field. + public const int DoubleField8FieldNumber = 8; + private double doubleField8_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField8 { + get { return doubleField8_; } + set { + doubleField8_ = value; + } + } + + /// Field number for the "double_field_9" field. + public const int DoubleField9FieldNumber = 9; + private double doubleField9_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField9 { + get { return doubleField9_; } + set { + doubleField9_ = value; + } + } + + /// Field number for the "double_field_98" field. + public const int DoubleField98FieldNumber = 98; + private double doubleField98_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField98 { + get { return doubleField98_; } + set { + doubleField98_ = value; + } + } + + /// Field number for the "double_field_10" field. + public const int DoubleField10FieldNumber = 10; + private double doubleField10_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField10 { + get { return doubleField10_; } + set { + doubleField10_ = value; + } + } + + /// Field number for the "double_field_11" field. + public const int DoubleField11FieldNumber = 11; + private double doubleField11_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField11 { + get { return doubleField11_; } + set { + doubleField11_ = value; + } + } + + /// Field number for the "double_field_99" field. + public const int DoubleField99FieldNumber = 99; + private double doubleField99_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField99 { + get { return doubleField99_; } + set { + doubleField99_ = value; + } + } + + /// Field number for the "double_field_84" field. + public const int DoubleField84FieldNumber = 84; + private double doubleField84_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField84 { + get { return doubleField84_; } + set { + doubleField84_ = value; + } + } + + /// Field number for the "double_field_14" field. + public const int DoubleField14FieldNumber = 14; + private double doubleField14_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField14 { + get { return doubleField14_; } + set { + doubleField14_ = value; + } + } + + /// Field number for the "double_field_77" field. + public const int DoubleField77FieldNumber = 77; + private double doubleField77_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField77 { + get { return doubleField77_; } + set { + doubleField77_ = value; + } + } + + /// Field number for the "double_field_15" field. + public const int DoubleField15FieldNumber = 15; + private double doubleField15_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField15 { + get { return doubleField15_; } + set { + doubleField15_ = value; + } + } + + /// Field number for the "int64_field_19" field. + public const int Int64Field19FieldNumber = 19; + private long int64Field19_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field19 { + get { return int64Field19_; } + set { + int64Field19_ = value; + } + } + + /// Field number for the "int64_field_115" field. + public const int Int64Field115FieldNumber = 115; + private long int64Field115_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field115 { + get { return int64Field115_; } + set { + int64Field115_ = value; + } + } + + /// Field number for the "double_field_116" field. + public const int DoubleField116FieldNumber = 116; + private double doubleField116_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField116 { + get { return doubleField116_; } + set { + doubleField116_ = value; + } + } + + /// Field number for the "int64_field_117" field. + public const int Int64Field117FieldNumber = 117; + private long int64Field117_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field117 { + get { return int64Field117_; } + set { + int64Field117_ = value; + } + } + + /// Field number for the "double_field_20" field. + public const int DoubleField20FieldNumber = 20; + private double doubleField20_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField20 { + get { return doubleField20_; } + set { + doubleField20_ = value; + } + } + + /// Field number for the "double_field_21" field. + public const int DoubleField21FieldNumber = 21; + private double doubleField21_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField21 { + get { return doubleField21_; } + set { + doubleField21_ = value; + } + } + + /// Field number for the "string_field_73" field. + public const int StringField73FieldNumber = 73; + private string stringField73_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string StringField73 { + get { return stringField73_; } + set { + stringField73_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "string_field_74" field. + public const int StringField74FieldNumber = 74; + private string stringField74_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string StringField74 { + get { return stringField74_; } + set { + stringField74_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "double_field_22" field. + public const int DoubleField22FieldNumber = 22; + private double doubleField22_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField22 { + get { return doubleField22_; } + set { + doubleField22_ = value; + } + } + + /// Field number for the "double_field_69" field. + public const int DoubleField69FieldNumber = 69; + private double doubleField69_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField69 { + get { return doubleField69_; } + set { + doubleField69_ = value; + } + } + + /// Field number for the "double_field_70" field. + public const int DoubleField70FieldNumber = 70; + private double doubleField70_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField70 { + get { return doubleField70_; } + set { + doubleField70_ = value; + } + } + + /// Field number for the "double_field_71" field. + public const int DoubleField71FieldNumber = 71; + private double doubleField71_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField71 { + get { return doubleField71_; } + set { + doubleField71_ = value; + } + } + + /// Field number for the "double_field_72" field. + public const int DoubleField72FieldNumber = 72; + private double doubleField72_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField72 { + get { return doubleField72_; } + set { + doubleField72_ = value; + } + } + + /// Field number for the "double_field_25" field. + public const int DoubleField25FieldNumber = 25; + private double doubleField25_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField25 { + get { return doubleField25_; } + set { + doubleField25_ = value; + } + } + + /// Field number for the "int64_field_26" field. + public const int Int64Field26FieldNumber = 26; + private long int64Field26_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field26 { + get { return int64Field26_; } + set { + int64Field26_ = value; + } + } + + /// Field number for the "double_field_68" field. + public const int DoubleField68FieldNumber = 68; + private double doubleField68_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField68 { + get { return doubleField68_; } + set { + doubleField68_ = value; + } + } + + /// Field number for the "double_field_28" field. + public const int DoubleField28FieldNumber = 28; + private double doubleField28_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField28 { + get { return doubleField28_; } + set { + doubleField28_ = value; + } + } + + /// Field number for the "double_field_106" field. + public const int DoubleField106FieldNumber = 106; + private double doubleField106_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField106 { + get { return doubleField106_; } + set { + doubleField106_ = value; + } + } + + /// Field number for the "double_field_29" field. + public const int DoubleField29FieldNumber = 29; + private double doubleField29_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField29 { + get { return doubleField29_; } + set { + doubleField29_ = value; + } + } + + /// Field number for the "double_field_30" field. + public const int DoubleField30FieldNumber = 30; + private double doubleField30_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField30 { + get { return doubleField30_; } + set { + doubleField30_ = value; + } + } + + /// Field number for the "double_field_101" field. + public const int DoubleField101FieldNumber = 101; + private double doubleField101_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField101 { + get { return doubleField101_; } + set { + doubleField101_ = value; + } + } + + /// Field number for the "double_field_102" field. + public const int DoubleField102FieldNumber = 102; + private double doubleField102_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField102 { + get { return doubleField102_; } + set { + doubleField102_ = value; + } + } + + /// Field number for the "double_field_103" field. + public const int DoubleField103FieldNumber = 103; + private double doubleField103_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField103 { + get { return doubleField103_; } + set { + doubleField103_ = value; + } + } + + /// Field number for the "double_field_104" field. + public const int DoubleField104FieldNumber = 104; + private double doubleField104_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField104 { + get { return doubleField104_; } + set { + doubleField104_ = value; + } + } + + /// Field number for the "double_field_105" field. + public const int DoubleField105FieldNumber = 105; + private double doubleField105_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField105 { + get { return doubleField105_; } + set { + doubleField105_ = value; + } + } + + /// Field number for the "double_field_31" field. + public const int DoubleField31FieldNumber = 31; + private double doubleField31_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField31 { + get { return doubleField31_; } + set { + doubleField31_ = value; + } + } + + /// Field number for the "int64_field_32" field. + public const int Int64Field32FieldNumber = 32; + private long int64Field32_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field32 { + get { return int64Field32_; } + set { + int64Field32_ = value; + } + } + + /// Field number for the "double_field_75" field. + public const int DoubleField75FieldNumber = 75; + private double doubleField75_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField75 { + get { return doubleField75_; } + set { + doubleField75_ = value; + } + } + + /// Field number for the "double_field_129" field. + public const int DoubleField129FieldNumber = 129; + private double doubleField129_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField129 { + get { return doubleField129_; } + set { + doubleField129_ = value; + } + } + + /// Field number for the "enum_field_80" field. + public const int EnumField80FieldNumber = 80; + private int enumField80_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField80 { + get { return enumField80_; } + set { + enumField80_ = value; + } + } + + /// Field number for the "enum_field_81" field. + public const int EnumField81FieldNumber = 81; + private int enumField81_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField81 { + get { return enumField81_; } + set { + enumField81_ = value; + } + } + + /// Field number for the "int64_field_82" field. + public const int Int64Field82FieldNumber = 82; + private long int64Field82_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field82 { + get { return int64Field82_; } + set { + int64Field82_ = value; + } + } + + /// Field number for the "enum_field_83" field. + public const int EnumField83FieldNumber = 83; + private int enumField83_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int EnumField83 { + get { return enumField83_; } + set { + enumField83_ = value; + } + } + + /// Field number for the "int64_field_85" field. + public const int Int64Field85FieldNumber = 85; + private long int64Field85_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field85 { + get { return int64Field85_; } + set { + int64Field85_ = value; + } + } + + /// Field number for the "int64_field_86" field. + public const int Int64Field86FieldNumber = 86; + private long int64Field86_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field86 { + get { return int64Field86_; } + set { + int64Field86_ = value; + } + } + + /// Field number for the "int64_field_87" field. + public const int Int64Field87FieldNumber = 87; + private long int64Field87_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field87 { + get { return int64Field87_; } + set { + int64Field87_ = value; + } + } + + /// Field number for the "int64_field_125" field. + public const int Int64Field125FieldNumber = 125; + private long int64Field125_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field125 { + get { return int64Field125_; } + set { + int64Field125_ = value; + } + } + + /// Field number for the "int64_field_37" field. + public const int Int64Field37FieldNumber = 37; + private long int64Field37_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field37 { + get { return int64Field37_; } + set { + int64Field37_ = value; + } + } + + /// Field number for the "double_field_38" field. + public const int DoubleField38FieldNumber = 38; + private double doubleField38_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField38 { + get { return doubleField38_; } + set { + doubleField38_ = value; + } + } + + /// Field number for the "interactions" field. + public const int InteractionsFieldNumber = 39; + private long interactions_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Interactions { + get { return interactions_; } + set { + interactions_ = value; + } + } + + /// Field number for the "repeated_int_field_100" field. + public const int RepeatedIntField100FieldNumber = 100; + private static readonly pb::FieldCodec _repeated_repeatedIntField100_codec + = pb::FieldCodec.ForInt32(802); + private readonly pbc::RepeatedField repeatedIntField100_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField RepeatedIntField100 { + get { return repeatedIntField100_; } + } + + /// Field number for the "double_field_40" field. + public const int DoubleField40FieldNumber = 40; + private double doubleField40_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField40 { + get { return doubleField40_; } + set { + doubleField40_ = value; + } + } + + /// Field number for the "int64_field_41" field. + public const int Int64Field41FieldNumber = 41; + private long int64Field41_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field41 { + get { return int64Field41_; } + set { + int64Field41_ = value; + } + } + + /// Field number for the "int64_field_126" field. + public const int Int64Field126FieldNumber = 126; + private long int64Field126_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field126 { + get { return int64Field126_; } + set { + int64Field126_ = value; + } + } + + /// Field number for the "int64_field_127" field. + public const int Int64Field127FieldNumber = 127; + private long int64Field127_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field127 { + get { return int64Field127_; } + set { + int64Field127_ = value; + } + } + + /// Field number for the "double_field_128" field. + public const int DoubleField128FieldNumber = 128; + private double doubleField128_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField128 { + get { return doubleField128_; } + set { + doubleField128_ = value; + } + } + + /// Field number for the "double_field_109" field. + public const int DoubleField109FieldNumber = 109; + private double doubleField109_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField109 { + get { return doubleField109_; } + set { + doubleField109_ = value; + } + } + + /// Field number for the "int64_field_110" field. + public const int Int64Field110FieldNumber = 110; + private long int64Field110_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field110 { + get { return int64Field110_; } + set { + int64Field110_ = value; + } + } + + /// Field number for the "double_field_111" field. + public const int DoubleField111FieldNumber = 111; + private double doubleField111_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField111 { + get { return doubleField111_; } + set { + doubleField111_ = value; + } + } + + /// Field number for the "int64_field_112" field. + public const int Int64Field112FieldNumber = 112; + private long int64Field112_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field112 { + get { return int64Field112_; } + set { + int64Field112_ = value; + } + } + + /// Field number for the "double_field_113" field. + public const int DoubleField113FieldNumber = 113; + private double doubleField113_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField113 { + get { return doubleField113_; } + set { + doubleField113_ = value; + } + } + + /// Field number for the "int64_field_114" field. + public const int Int64Field114FieldNumber = 114; + private long int64Field114_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field114 { + get { return int64Field114_; } + set { + int64Field114_ = value; + } + } + + /// Field number for the "double_field_42" field. + public const int DoubleField42FieldNumber = 42; + private double doubleField42_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField42 { + get { return doubleField42_; } + set { + doubleField42_ = value; + } + } + + /// Field number for the "int64_field_43" field. + public const int Int64Field43FieldNumber = 43; + private long int64Field43_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field43 { + get { return int64Field43_; } + set { + int64Field43_ = value; + } + } + + /// Field number for the "int64_field_44" field. + public const int Int64Field44FieldNumber = 44; + private long int64Field44_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field44 { + get { return int64Field44_; } + set { + int64Field44_ = value; + } + } + + /// Field number for the "double_field_45" field. + public const int DoubleField45FieldNumber = 45; + private double doubleField45_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField45 { + get { return doubleField45_; } + set { + doubleField45_ = value; + } + } + + /// Field number for the "double_field_46" field. + public const int DoubleField46FieldNumber = 46; + private double doubleField46_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField46 { + get { return doubleField46_; } + set { + doubleField46_ = value; + } + } + + /// Field number for the "double_field_78" field. + public const int DoubleField78FieldNumber = 78; + private double doubleField78_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField78 { + get { return doubleField78_; } + set { + doubleField78_ = value; + } + } + + /// Field number for the "double_field_88" field. + public const int DoubleField88FieldNumber = 88; + private double doubleField88_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField88 { + get { return doubleField88_; } + set { + doubleField88_ = value; + } + } + + /// Field number for the "double_field_47" field. + public const int DoubleField47FieldNumber = 47; + private double doubleField47_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField47 { + get { return doubleField47_; } + set { + doubleField47_ = value; + } + } + + /// Field number for the "double_field_89" field. + public const int DoubleField89FieldNumber = 89; + private double doubleField89_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField89 { + get { return doubleField89_; } + set { + doubleField89_ = value; + } + } + + /// Field number for the "double_field_48" field. + public const int DoubleField48FieldNumber = 48; + private double doubleField48_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField48 { + get { return doubleField48_; } + set { + doubleField48_ = value; + } + } + + /// Field number for the "double_field_49" field. + public const int DoubleField49FieldNumber = 49; + private double doubleField49_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField49 { + get { return doubleField49_; } + set { + doubleField49_ = value; + } + } + + /// Field number for the "double_field_50" field. + public const int DoubleField50FieldNumber = 50; + private double doubleField50_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField50 { + get { return doubleField50_; } + set { + doubleField50_ = value; + } + } + + /// Field number for the "double_field_90" field. + public const int DoubleField90FieldNumber = 90; + private double doubleField90_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField90 { + get { return doubleField90_; } + set { + doubleField90_ = value; + } + } + + /// Field number for the "double_field_51" field. + public const int DoubleField51FieldNumber = 51; + private double doubleField51_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField51 { + get { return doubleField51_; } + set { + doubleField51_ = value; + } + } + + /// Field number for the "double_field_91" field. + public const int DoubleField91FieldNumber = 91; + private double doubleField91_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField91 { + get { return doubleField91_; } + set { + doubleField91_ = value; + } + } + + /// Field number for the "double_field_92" field. + public const int DoubleField92FieldNumber = 92; + private double doubleField92_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField92 { + get { return doubleField92_; } + set { + doubleField92_ = value; + } + } + + /// Field number for the "int64_field_107" field. + public const int Int64Field107FieldNumber = 107; + private long int64Field107_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field107 { + get { return int64Field107_; } + set { + int64Field107_ = value; + } + } + + /// Field number for the "double_field_93" field. + public const int DoubleField93FieldNumber = 93; + private double doubleField93_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField93 { + get { return doubleField93_; } + set { + doubleField93_ = value; + } + } + + /// Field number for the "double_field_108" field. + public const int DoubleField108FieldNumber = 108; + private double doubleField108_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField108 { + get { return doubleField108_; } + set { + doubleField108_ = value; + } + } + + /// Field number for the "double_field_52" field. + public const int DoubleField52FieldNumber = 52; + private double doubleField52_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField52 { + get { return doubleField52_; } + set { + doubleField52_ = value; + } + } + + /// Field number for the "double_field_53" field. + public const int DoubleField53FieldNumber = 53; + private double doubleField53_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField53 { + get { return doubleField53_; } + set { + doubleField53_ = value; + } + } + + /// Field number for the "double_field_94" field. + public const int DoubleField94FieldNumber = 94; + private double doubleField94_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField94 { + get { return doubleField94_; } + set { + doubleField94_ = value; + } + } + + /// Field number for the "double_field_54" field. + public const int DoubleField54FieldNumber = 54; + private double doubleField54_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField54 { + get { return doubleField54_; } + set { + doubleField54_ = value; + } + } + + /// Field number for the "double_field_55" field. + public const int DoubleField55FieldNumber = 55; + private double doubleField55_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField55 { + get { return doubleField55_; } + set { + doubleField55_ = value; + } + } + + /// Field number for the "double_field_56" field. + public const int DoubleField56FieldNumber = 56; + private double doubleField56_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField56 { + get { return doubleField56_; } + set { + doubleField56_ = value; + } + } + + /// Field number for the "double_field_57" field. + public const int DoubleField57FieldNumber = 57; + private double doubleField57_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField57 { + get { return doubleField57_; } + set { + doubleField57_ = value; + } + } + + /// Field number for the "double_field_58" field. + public const int DoubleField58FieldNumber = 58; + private double doubleField58_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public double DoubleField58 { + get { return doubleField58_; } + set { + doubleField58_ = value; + } + } + + /// Field number for the "int64_field_59" field. + public const int Int64Field59FieldNumber = 59; + private long int64Field59_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field59 { + get { return int64Field59_; } + set { + int64Field59_ = value; + } + } + + /// Field number for the "int64_field_60" field. + public const int Int64Field60FieldNumber = 60; + private long int64Field60_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public long Int64Field60 { + get { return int64Field60_; } + set { + int64Field60_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as ManyPrimitiveFieldsMessage); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(ManyPrimitiveFieldsMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField95, other.DoubleField95)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField1, other.DoubleField1)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField79, other.DoubleField79)) return false; + if (Int64Field2 != other.Int64Field2) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField96, other.DoubleField96)) return false; + if (Int64Field3 != other.Int64Field3) return false; + if (Int64Field4 != other.Int64Field4) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField97, other.DoubleField97)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField65, other.DoubleField65)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField66, other.DoubleField66)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField7, other.DoubleField7)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField62, other.DoubleField62)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField118, other.DoubleField118)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField119, other.DoubleField119)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField67, other.DoubleField67)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField120, other.DoubleField120)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField121, other.DoubleField121)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField122, other.DoubleField122)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField123, other.DoubleField123)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField124, other.DoubleField124)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField8, other.DoubleField8)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField9, other.DoubleField9)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField98, other.DoubleField98)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField10, other.DoubleField10)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField11, other.DoubleField11)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField99, other.DoubleField99)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField84, other.DoubleField84)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField14, other.DoubleField14)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField77, other.DoubleField77)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField15, other.DoubleField15)) return false; + if (Int64Field19 != other.Int64Field19) return false; + if (Int64Field115 != other.Int64Field115) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField116, other.DoubleField116)) return false; + if (Int64Field117 != other.Int64Field117) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField20, other.DoubleField20)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField21, other.DoubleField21)) return false; + if (StringField73 != other.StringField73) return false; + if (StringField74 != other.StringField74) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField22, other.DoubleField22)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField69, other.DoubleField69)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField70, other.DoubleField70)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField71, other.DoubleField71)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField72, other.DoubleField72)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField25, other.DoubleField25)) return false; + if (Int64Field26 != other.Int64Field26) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField68, other.DoubleField68)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField28, other.DoubleField28)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField106, other.DoubleField106)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField29, other.DoubleField29)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField30, other.DoubleField30)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField101, other.DoubleField101)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField102, other.DoubleField102)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField103, other.DoubleField103)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField104, other.DoubleField104)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField105, other.DoubleField105)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField31, other.DoubleField31)) return false; + if (Int64Field32 != other.Int64Field32) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField75, other.DoubleField75)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField129, other.DoubleField129)) return false; + if (EnumField80 != other.EnumField80) return false; + if (EnumField81 != other.EnumField81) return false; + if (Int64Field82 != other.Int64Field82) return false; + if (EnumField83 != other.EnumField83) return false; + if (Int64Field85 != other.Int64Field85) return false; + if (Int64Field86 != other.Int64Field86) return false; + if (Int64Field87 != other.Int64Field87) return false; + if (Int64Field125 != other.Int64Field125) return false; + if (Int64Field37 != other.Int64Field37) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField38, other.DoubleField38)) return false; + if (Interactions != other.Interactions) return false; + if(!repeatedIntField100_.Equals(other.repeatedIntField100_)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField40, other.DoubleField40)) return false; + if (Int64Field41 != other.Int64Field41) return false; + if (Int64Field126 != other.Int64Field126) return false; + if (Int64Field127 != other.Int64Field127) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField128, other.DoubleField128)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField109, other.DoubleField109)) return false; + if (Int64Field110 != other.Int64Field110) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField111, other.DoubleField111)) return false; + if (Int64Field112 != other.Int64Field112) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField113, other.DoubleField113)) return false; + if (Int64Field114 != other.Int64Field114) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField42, other.DoubleField42)) return false; + if (Int64Field43 != other.Int64Field43) return false; + if (Int64Field44 != other.Int64Field44) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField45, other.DoubleField45)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField46, other.DoubleField46)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField78, other.DoubleField78)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField88, other.DoubleField88)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField47, other.DoubleField47)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField89, other.DoubleField89)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField48, other.DoubleField48)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField49, other.DoubleField49)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField50, other.DoubleField50)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField90, other.DoubleField90)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField51, other.DoubleField51)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField91, other.DoubleField91)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField92, other.DoubleField92)) return false; + if (Int64Field107 != other.Int64Field107) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField93, other.DoubleField93)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField108, other.DoubleField108)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField52, other.DoubleField52)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField53, other.DoubleField53)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField94, other.DoubleField94)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField54, other.DoubleField54)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField55, other.DoubleField55)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField56, other.DoubleField56)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField57, other.DoubleField57)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField58, other.DoubleField58)) return false; + if (Int64Field59 != other.Int64Field59) return false; + if (Int64Field60 != other.Int64Field60) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (DoubleField95 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField95); + if (DoubleField1 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField1); + if (DoubleField79 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField79); + if (Int64Field2 != 0L) hash ^= Int64Field2.GetHashCode(); + if (DoubleField96 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField96); + if (Int64Field3 != 0L) hash ^= Int64Field3.GetHashCode(); + if (Int64Field4 != 0L) hash ^= Int64Field4.GetHashCode(); + if (DoubleField97 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField97); + if (DoubleField65 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField65); + if (DoubleField66 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField66); + if (DoubleField7 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField7); + if (DoubleField62 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField62); + if (DoubleField118 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField118); + if (DoubleField119 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField119); + if (DoubleField67 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField67); + if (DoubleField120 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField120); + if (DoubleField121 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField121); + if (DoubleField122 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField122); + if (DoubleField123 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField123); + if (DoubleField124 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField124); + if (DoubleField8 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField8); + if (DoubleField9 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField9); + if (DoubleField98 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField98); + if (DoubleField10 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField10); + if (DoubleField11 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField11); + if (DoubleField99 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField99); + if (DoubleField84 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField84); + if (DoubleField14 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField14); + if (DoubleField77 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField77); + if (DoubleField15 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField15); + if (Int64Field19 != 0L) hash ^= Int64Field19.GetHashCode(); + if (Int64Field115 != 0L) hash ^= Int64Field115.GetHashCode(); + if (DoubleField116 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField116); + if (Int64Field117 != 0L) hash ^= Int64Field117.GetHashCode(); + if (DoubleField20 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField20); + if (DoubleField21 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField21); + if (StringField73.Length != 0) hash ^= StringField73.GetHashCode(); + if (StringField74.Length != 0) hash ^= StringField74.GetHashCode(); + if (DoubleField22 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField22); + if (DoubleField69 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField69); + if (DoubleField70 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField70); + if (DoubleField71 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField71); + if (DoubleField72 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField72); + if (DoubleField25 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField25); + if (Int64Field26 != 0L) hash ^= Int64Field26.GetHashCode(); + if (DoubleField68 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField68); + if (DoubleField28 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField28); + if (DoubleField106 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField106); + if (DoubleField29 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField29); + if (DoubleField30 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField30); + if (DoubleField101 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField101); + if (DoubleField102 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField102); + if (DoubleField103 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField103); + if (DoubleField104 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField104); + if (DoubleField105 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField105); + if (DoubleField31 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField31); + if (Int64Field32 != 0L) hash ^= Int64Field32.GetHashCode(); + if (DoubleField75 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField75); + if (DoubleField129 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField129); + if (EnumField80 != 0) hash ^= EnumField80.GetHashCode(); + if (EnumField81 != 0) hash ^= EnumField81.GetHashCode(); + if (Int64Field82 != 0L) hash ^= Int64Field82.GetHashCode(); + if (EnumField83 != 0) hash ^= EnumField83.GetHashCode(); + if (Int64Field85 != 0L) hash ^= Int64Field85.GetHashCode(); + if (Int64Field86 != 0L) hash ^= Int64Field86.GetHashCode(); + if (Int64Field87 != 0L) hash ^= Int64Field87.GetHashCode(); + if (Int64Field125 != 0L) hash ^= Int64Field125.GetHashCode(); + if (Int64Field37 != 0L) hash ^= Int64Field37.GetHashCode(); + if (DoubleField38 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField38); + if (Interactions != 0L) hash ^= Interactions.GetHashCode(); + hash ^= repeatedIntField100_.GetHashCode(); + if (DoubleField40 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField40); + if (Int64Field41 != 0L) hash ^= Int64Field41.GetHashCode(); + if (Int64Field126 != 0L) hash ^= Int64Field126.GetHashCode(); + if (Int64Field127 != 0L) hash ^= Int64Field127.GetHashCode(); + if (DoubleField128 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField128); + if (DoubleField109 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField109); + if (Int64Field110 != 0L) hash ^= Int64Field110.GetHashCode(); + if (DoubleField111 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField111); + if (Int64Field112 != 0L) hash ^= Int64Field112.GetHashCode(); + if (DoubleField113 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField113); + if (Int64Field114 != 0L) hash ^= Int64Field114.GetHashCode(); + if (DoubleField42 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField42); + if (Int64Field43 != 0L) hash ^= Int64Field43.GetHashCode(); + if (Int64Field44 != 0L) hash ^= Int64Field44.GetHashCode(); + if (DoubleField45 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField45); + if (DoubleField46 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField46); + if (DoubleField78 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField78); + if (DoubleField88 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField88); + if (DoubleField47 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField47); + if (DoubleField89 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField89); + if (DoubleField48 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField48); + if (DoubleField49 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField49); + if (DoubleField50 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField50); + if (DoubleField90 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField90); + if (DoubleField51 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField51); + if (DoubleField91 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField91); + if (DoubleField92 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField92); + if (Int64Field107 != 0L) hash ^= Int64Field107.GetHashCode(); + if (DoubleField93 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField93); + if (DoubleField108 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField108); + if (DoubleField52 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField52); + if (DoubleField53 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField53); + if (DoubleField94 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField94); + if (DoubleField54 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField54); + if (DoubleField55 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField55); + if (DoubleField56 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField56); + if (DoubleField57 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField57); + if (DoubleField58 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField58); + if (Int64Field59 != 0L) hash ^= Int64Field59.GetHashCode(); + if (Int64Field60 != 0L) hash ^= Int64Field60.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (DoubleField1 != 0D) { + output.WriteRawTag(9); + output.WriteDouble(DoubleField1); + } + if (Int64Field2 != 0L) { + output.WriteRawTag(16); + output.WriteInt64(Int64Field2); + } + if (Int64Field3 != 0L) { + output.WriteRawTag(24); + output.WriteInt64(Int64Field3); + } + if (Int64Field4 != 0L) { + output.WriteRawTag(32); + output.WriteInt64(Int64Field4); + } + if (DoubleField7 != 0D) { + output.WriteRawTag(57); + output.WriteDouble(DoubleField7); + } + if (DoubleField8 != 0D) { + output.WriteRawTag(65); + output.WriteDouble(DoubleField8); + } + if (DoubleField9 != 0D) { + output.WriteRawTag(73); + output.WriteDouble(DoubleField9); + } + if (DoubleField10 != 0D) { + output.WriteRawTag(81); + output.WriteDouble(DoubleField10); + } + if (DoubleField11 != 0D) { + output.WriteRawTag(89); + output.WriteDouble(DoubleField11); + } + if (DoubleField14 != 0D) { + output.WriteRawTag(113); + output.WriteDouble(DoubleField14); + } + if (DoubleField15 != 0D) { + output.WriteRawTag(121); + output.WriteDouble(DoubleField15); + } + if (Int64Field19 != 0L) { + output.WriteRawTag(152, 1); + output.WriteInt64(Int64Field19); + } + if (DoubleField20 != 0D) { + output.WriteRawTag(161, 1); + output.WriteDouble(DoubleField20); + } + if (DoubleField21 != 0D) { + output.WriteRawTag(169, 1); + output.WriteDouble(DoubleField21); + } + if (DoubleField22 != 0D) { + output.WriteRawTag(177, 1); + output.WriteDouble(DoubleField22); + } + if (DoubleField25 != 0D) { + output.WriteRawTag(201, 1); + output.WriteDouble(DoubleField25); + } + if (Int64Field26 != 0L) { + output.WriteRawTag(208, 1); + output.WriteInt64(Int64Field26); + } + if (DoubleField28 != 0D) { + output.WriteRawTag(225, 1); + output.WriteDouble(DoubleField28); + } + if (DoubleField29 != 0D) { + output.WriteRawTag(233, 1); + output.WriteDouble(DoubleField29); + } + if (DoubleField30 != 0D) { + output.WriteRawTag(241, 1); + output.WriteDouble(DoubleField30); + } + if (DoubleField31 != 0D) { + output.WriteRawTag(249, 1); + output.WriteDouble(DoubleField31); + } + if (Int64Field32 != 0L) { + output.WriteRawTag(128, 2); + output.WriteInt64(Int64Field32); + } + if (Int64Field37 != 0L) { + output.WriteRawTag(168, 2); + output.WriteInt64(Int64Field37); + } + if (DoubleField38 != 0D) { + output.WriteRawTag(177, 2); + output.WriteDouble(DoubleField38); + } + if (Interactions != 0L) { + output.WriteRawTag(184, 2); + output.WriteInt64(Interactions); + } + if (DoubleField40 != 0D) { + output.WriteRawTag(193, 2); + output.WriteDouble(DoubleField40); + } + if (Int64Field41 != 0L) { + output.WriteRawTag(200, 2); + output.WriteInt64(Int64Field41); + } + if (DoubleField42 != 0D) { + output.WriteRawTag(209, 2); + output.WriteDouble(DoubleField42); + } + if (Int64Field43 != 0L) { + output.WriteRawTag(216, 2); + output.WriteInt64(Int64Field43); + } + if (Int64Field44 != 0L) { + output.WriteRawTag(224, 2); + output.WriteInt64(Int64Field44); + } + if (DoubleField45 != 0D) { + output.WriteRawTag(233, 2); + output.WriteDouble(DoubleField45); + } + if (DoubleField46 != 0D) { + output.WriteRawTag(241, 2); + output.WriteDouble(DoubleField46); + } + if (DoubleField47 != 0D) { + output.WriteRawTag(249, 2); + output.WriteDouble(DoubleField47); + } + if (DoubleField48 != 0D) { + output.WriteRawTag(129, 3); + output.WriteDouble(DoubleField48); + } + if (DoubleField49 != 0D) { + output.WriteRawTag(137, 3); + output.WriteDouble(DoubleField49); + } + if (DoubleField50 != 0D) { + output.WriteRawTag(145, 3); + output.WriteDouble(DoubleField50); + } + if (DoubleField51 != 0D) { + output.WriteRawTag(153, 3); + output.WriteDouble(DoubleField51); + } + if (DoubleField52 != 0D) { + output.WriteRawTag(161, 3); + output.WriteDouble(DoubleField52); + } + if (DoubleField53 != 0D) { + output.WriteRawTag(169, 3); + output.WriteDouble(DoubleField53); + } + if (DoubleField54 != 0D) { + output.WriteRawTag(177, 3); + output.WriteDouble(DoubleField54); + } + if (DoubleField55 != 0D) { + output.WriteRawTag(185, 3); + output.WriteDouble(DoubleField55); + } + if (DoubleField56 != 0D) { + output.WriteRawTag(193, 3); + output.WriteDouble(DoubleField56); + } + if (DoubleField57 != 0D) { + output.WriteRawTag(201, 3); + output.WriteDouble(DoubleField57); + } + if (DoubleField58 != 0D) { + output.WriteRawTag(209, 3); + output.WriteDouble(DoubleField58); + } + if (Int64Field59 != 0L) { + output.WriteRawTag(216, 3); + output.WriteInt64(Int64Field59); + } + if (Int64Field60 != 0L) { + output.WriteRawTag(224, 3); + output.WriteInt64(Int64Field60); + } + if (DoubleField62 != 0D) { + output.WriteRawTag(241, 3); + output.WriteDouble(DoubleField62); + } + if (DoubleField65 != 0D) { + output.WriteRawTag(137, 4); + output.WriteDouble(DoubleField65); + } + if (DoubleField66 != 0D) { + output.WriteRawTag(145, 4); + output.WriteDouble(DoubleField66); + } + if (DoubleField67 != 0D) { + output.WriteRawTag(153, 4); + output.WriteDouble(DoubleField67); + } + if (DoubleField68 != 0D) { + output.WriteRawTag(161, 4); + output.WriteDouble(DoubleField68); + } + if (DoubleField69 != 0D) { + output.WriteRawTag(169, 4); + output.WriteDouble(DoubleField69); + } + if (DoubleField70 != 0D) { + output.WriteRawTag(177, 4); + output.WriteDouble(DoubleField70); + } + if (DoubleField71 != 0D) { + output.WriteRawTag(185, 4); + output.WriteDouble(DoubleField71); + } + if (DoubleField72 != 0D) { + output.WriteRawTag(193, 4); + output.WriteDouble(DoubleField72); + } + if (StringField73.Length != 0) { + output.WriteRawTag(202, 4); + output.WriteString(StringField73); + } + if (StringField74.Length != 0) { + output.WriteRawTag(210, 4); + output.WriteString(StringField74); + } + if (DoubleField75 != 0D) { + output.WriteRawTag(217, 4); + output.WriteDouble(DoubleField75); + } + if (DoubleField77 != 0D) { + output.WriteRawTag(233, 4); + output.WriteDouble(DoubleField77); + } + if (DoubleField78 != 0D) { + output.WriteRawTag(241, 4); + output.WriteDouble(DoubleField78); + } + if (DoubleField79 != 0D) { + output.WriteRawTag(249, 4); + output.WriteDouble(DoubleField79); + } + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); + } + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); + } + if (Int64Field82 != 0L) { + output.WriteRawTag(144, 5); + output.WriteInt64(Int64Field82); + } + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); + } + if (DoubleField84 != 0D) { + output.WriteRawTag(161, 5); + output.WriteDouble(DoubleField84); + } + if (Int64Field85 != 0L) { + output.WriteRawTag(168, 5); + output.WriteInt64(Int64Field85); + } + if (Int64Field86 != 0L) { + output.WriteRawTag(176, 5); + output.WriteInt64(Int64Field86); + } + if (Int64Field87 != 0L) { + output.WriteRawTag(184, 5); + output.WriteInt64(Int64Field87); + } + if (DoubleField88 != 0D) { + output.WriteRawTag(193, 5); + output.WriteDouble(DoubleField88); + } + if (DoubleField89 != 0D) { + output.WriteRawTag(201, 5); + output.WriteDouble(DoubleField89); + } + if (DoubleField90 != 0D) { + output.WriteRawTag(209, 5); + output.WriteDouble(DoubleField90); + } + if (DoubleField91 != 0D) { + output.WriteRawTag(217, 5); + output.WriteDouble(DoubleField91); + } + if (DoubleField92 != 0D) { + output.WriteRawTag(225, 5); + output.WriteDouble(DoubleField92); + } + if (DoubleField93 != 0D) { + output.WriteRawTag(233, 5); + output.WriteDouble(DoubleField93); + } + if (DoubleField94 != 0D) { + output.WriteRawTag(241, 5); + output.WriteDouble(DoubleField94); + } + if (DoubleField95 != 0D) { + output.WriteRawTag(249, 5); + output.WriteDouble(DoubleField95); + } + if (DoubleField96 != 0D) { + output.WriteRawTag(129, 6); + output.WriteDouble(DoubleField96); + } + if (DoubleField97 != 0D) { + output.WriteRawTag(137, 6); + output.WriteDouble(DoubleField97); + } + if (DoubleField98 != 0D) { + output.WriteRawTag(145, 6); + output.WriteDouble(DoubleField98); + } + if (DoubleField99 != 0D) { + output.WriteRawTag(153, 6); + output.WriteDouble(DoubleField99); + } + repeatedIntField100_.WriteTo(output, _repeated_repeatedIntField100_codec); + if (DoubleField101 != 0D) { + output.WriteRawTag(169, 6); + output.WriteDouble(DoubleField101); + } + if (DoubleField102 != 0D) { + output.WriteRawTag(177, 6); + output.WriteDouble(DoubleField102); + } + if (DoubleField103 != 0D) { + output.WriteRawTag(185, 6); + output.WriteDouble(DoubleField103); + } + if (DoubleField104 != 0D) { + output.WriteRawTag(193, 6); + output.WriteDouble(DoubleField104); + } + if (DoubleField105 != 0D) { + output.WriteRawTag(201, 6); + output.WriteDouble(DoubleField105); + } + if (DoubleField106 != 0D) { + output.WriteRawTag(209, 6); + output.WriteDouble(DoubleField106); + } + if (Int64Field107 != 0L) { + output.WriteRawTag(216, 6); + output.WriteInt64(Int64Field107); + } + if (DoubleField108 != 0D) { + output.WriteRawTag(225, 6); + output.WriteDouble(DoubleField108); + } + if (DoubleField109 != 0D) { + output.WriteRawTag(233, 6); + output.WriteDouble(DoubleField109); + } + if (Int64Field110 != 0L) { + output.WriteRawTag(240, 6); + output.WriteInt64(Int64Field110); + } + if (DoubleField111 != 0D) { + output.WriteRawTag(249, 6); + output.WriteDouble(DoubleField111); + } + if (Int64Field112 != 0L) { + output.WriteRawTag(128, 7); + output.WriteInt64(Int64Field112); + } + if (DoubleField113 != 0D) { + output.WriteRawTag(137, 7); + output.WriteDouble(DoubleField113); + } + if (Int64Field114 != 0L) { + output.WriteRawTag(144, 7); + output.WriteInt64(Int64Field114); + } + if (Int64Field115 != 0L) { + output.WriteRawTag(152, 7); + output.WriteInt64(Int64Field115); + } + if (DoubleField116 != 0D) { + output.WriteRawTag(161, 7); + output.WriteDouble(DoubleField116); + } + if (Int64Field117 != 0L) { + output.WriteRawTag(168, 7); + output.WriteInt64(Int64Field117); + } + if (DoubleField118 != 0D) { + output.WriteRawTag(177, 7); + output.WriteDouble(DoubleField118); + } + if (DoubleField119 != 0D) { + output.WriteRawTag(185, 7); + output.WriteDouble(DoubleField119); + } + if (DoubleField120 != 0D) { + output.WriteRawTag(193, 7); + output.WriteDouble(DoubleField120); + } + if (DoubleField121 != 0D) { + output.WriteRawTag(201, 7); + output.WriteDouble(DoubleField121); + } + if (DoubleField122 != 0D) { + output.WriteRawTag(209, 7); + output.WriteDouble(DoubleField122); + } + if (DoubleField123 != 0D) { + output.WriteRawTag(217, 7); + output.WriteDouble(DoubleField123); + } + if (DoubleField124 != 0D) { + output.WriteRawTag(225, 7); + output.WriteDouble(DoubleField124); + } + if (Int64Field125 != 0L) { + output.WriteRawTag(232, 7); + output.WriteInt64(Int64Field125); + } + if (Int64Field126 != 0L) { + output.WriteRawTag(240, 7); + output.WriteInt64(Int64Field126); + } + if (Int64Field127 != 0L) { + output.WriteRawTag(248, 7); + output.WriteInt64(Int64Field127); + } + if (DoubleField128 != 0D) { + output.WriteRawTag(129, 8); + output.WriteDouble(DoubleField128); + } + if (DoubleField129 != 0D) { + output.WriteRawTag(137, 8); + output.WriteDouble(DoubleField129); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (DoubleField1 != 0D) { + output.WriteRawTag(9); + output.WriteDouble(DoubleField1); + } + if (Int64Field2 != 0L) { + output.WriteRawTag(16); + output.WriteInt64(Int64Field2); + } + if (Int64Field3 != 0L) { + output.WriteRawTag(24); + output.WriteInt64(Int64Field3); + } + if (Int64Field4 != 0L) { + output.WriteRawTag(32); + output.WriteInt64(Int64Field4); + } + if (DoubleField7 != 0D) { + output.WriteRawTag(57); + output.WriteDouble(DoubleField7); + } + if (DoubleField8 != 0D) { + output.WriteRawTag(65); + output.WriteDouble(DoubleField8); + } + if (DoubleField9 != 0D) { + output.WriteRawTag(73); + output.WriteDouble(DoubleField9); + } + if (DoubleField10 != 0D) { + output.WriteRawTag(81); + output.WriteDouble(DoubleField10); + } + if (DoubleField11 != 0D) { + output.WriteRawTag(89); + output.WriteDouble(DoubleField11); + } + if (DoubleField14 != 0D) { + output.WriteRawTag(113); + output.WriteDouble(DoubleField14); + } + if (DoubleField15 != 0D) { + output.WriteRawTag(121); + output.WriteDouble(DoubleField15); + } + if (Int64Field19 != 0L) { + output.WriteRawTag(152, 1); + output.WriteInt64(Int64Field19); + } + if (DoubleField20 != 0D) { + output.WriteRawTag(161, 1); + output.WriteDouble(DoubleField20); + } + if (DoubleField21 != 0D) { + output.WriteRawTag(169, 1); + output.WriteDouble(DoubleField21); + } + if (DoubleField22 != 0D) { + output.WriteRawTag(177, 1); + output.WriteDouble(DoubleField22); + } + if (DoubleField25 != 0D) { + output.WriteRawTag(201, 1); + output.WriteDouble(DoubleField25); + } + if (Int64Field26 != 0L) { + output.WriteRawTag(208, 1); + output.WriteInt64(Int64Field26); + } + if (DoubleField28 != 0D) { + output.WriteRawTag(225, 1); + output.WriteDouble(DoubleField28); + } + if (DoubleField29 != 0D) { + output.WriteRawTag(233, 1); + output.WriteDouble(DoubleField29); + } + if (DoubleField30 != 0D) { + output.WriteRawTag(241, 1); + output.WriteDouble(DoubleField30); + } + if (DoubleField31 != 0D) { + output.WriteRawTag(249, 1); + output.WriteDouble(DoubleField31); + } + if (Int64Field32 != 0L) { + output.WriteRawTag(128, 2); + output.WriteInt64(Int64Field32); + } + if (Int64Field37 != 0L) { + output.WriteRawTag(168, 2); + output.WriteInt64(Int64Field37); + } + if (DoubleField38 != 0D) { + output.WriteRawTag(177, 2); + output.WriteDouble(DoubleField38); + } + if (Interactions != 0L) { + output.WriteRawTag(184, 2); + output.WriteInt64(Interactions); + } + if (DoubleField40 != 0D) { + output.WriteRawTag(193, 2); + output.WriteDouble(DoubleField40); + } + if (Int64Field41 != 0L) { + output.WriteRawTag(200, 2); + output.WriteInt64(Int64Field41); + } + if (DoubleField42 != 0D) { + output.WriteRawTag(209, 2); + output.WriteDouble(DoubleField42); + } + if (Int64Field43 != 0L) { + output.WriteRawTag(216, 2); + output.WriteInt64(Int64Field43); + } + if (Int64Field44 != 0L) { + output.WriteRawTag(224, 2); + output.WriteInt64(Int64Field44); + } + if (DoubleField45 != 0D) { + output.WriteRawTag(233, 2); + output.WriteDouble(DoubleField45); + } + if (DoubleField46 != 0D) { + output.WriteRawTag(241, 2); + output.WriteDouble(DoubleField46); + } + if (DoubleField47 != 0D) { + output.WriteRawTag(249, 2); + output.WriteDouble(DoubleField47); + } + if (DoubleField48 != 0D) { + output.WriteRawTag(129, 3); + output.WriteDouble(DoubleField48); + } + if (DoubleField49 != 0D) { + output.WriteRawTag(137, 3); + output.WriteDouble(DoubleField49); + } + if (DoubleField50 != 0D) { + output.WriteRawTag(145, 3); + output.WriteDouble(DoubleField50); + } + if (DoubleField51 != 0D) { + output.WriteRawTag(153, 3); + output.WriteDouble(DoubleField51); + } + if (DoubleField52 != 0D) { + output.WriteRawTag(161, 3); + output.WriteDouble(DoubleField52); + } + if (DoubleField53 != 0D) { + output.WriteRawTag(169, 3); + output.WriteDouble(DoubleField53); + } + if (DoubleField54 != 0D) { + output.WriteRawTag(177, 3); + output.WriteDouble(DoubleField54); + } + if (DoubleField55 != 0D) { + output.WriteRawTag(185, 3); + output.WriteDouble(DoubleField55); + } + if (DoubleField56 != 0D) { + output.WriteRawTag(193, 3); + output.WriteDouble(DoubleField56); + } + if (DoubleField57 != 0D) { + output.WriteRawTag(201, 3); + output.WriteDouble(DoubleField57); + } + if (DoubleField58 != 0D) { + output.WriteRawTag(209, 3); + output.WriteDouble(DoubleField58); + } + if (Int64Field59 != 0L) { + output.WriteRawTag(216, 3); + output.WriteInt64(Int64Field59); + } + if (Int64Field60 != 0L) { + output.WriteRawTag(224, 3); + output.WriteInt64(Int64Field60); + } + if (DoubleField62 != 0D) { + output.WriteRawTag(241, 3); + output.WriteDouble(DoubleField62); + } + if (DoubleField65 != 0D) { + output.WriteRawTag(137, 4); + output.WriteDouble(DoubleField65); + } + if (DoubleField66 != 0D) { + output.WriteRawTag(145, 4); + output.WriteDouble(DoubleField66); + } + if (DoubleField67 != 0D) { + output.WriteRawTag(153, 4); + output.WriteDouble(DoubleField67); + } + if (DoubleField68 != 0D) { + output.WriteRawTag(161, 4); + output.WriteDouble(DoubleField68); + } + if (DoubleField69 != 0D) { + output.WriteRawTag(169, 4); + output.WriteDouble(DoubleField69); + } + if (DoubleField70 != 0D) { + output.WriteRawTag(177, 4); + output.WriteDouble(DoubleField70); + } + if (DoubleField71 != 0D) { + output.WriteRawTag(185, 4); + output.WriteDouble(DoubleField71); + } + if (DoubleField72 != 0D) { + output.WriteRawTag(193, 4); + output.WriteDouble(DoubleField72); + } + if (StringField73.Length != 0) { + output.WriteRawTag(202, 4); + output.WriteString(StringField73); + } + if (StringField74.Length != 0) { + output.WriteRawTag(210, 4); + output.WriteString(StringField74); + } + if (DoubleField75 != 0D) { + output.WriteRawTag(217, 4); + output.WriteDouble(DoubleField75); + } + if (DoubleField77 != 0D) { + output.WriteRawTag(233, 4); + output.WriteDouble(DoubleField77); + } + if (DoubleField78 != 0D) { + output.WriteRawTag(241, 4); + output.WriteDouble(DoubleField78); + } + if (DoubleField79 != 0D) { + output.WriteRawTag(249, 4); + output.WriteDouble(DoubleField79); + } + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); + } + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); + } + if (Int64Field82 != 0L) { + output.WriteRawTag(144, 5); + output.WriteInt64(Int64Field82); + } + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); + } + if (DoubleField84 != 0D) { + output.WriteRawTag(161, 5); + output.WriteDouble(DoubleField84); + } + if (Int64Field85 != 0L) { + output.WriteRawTag(168, 5); + output.WriteInt64(Int64Field85); + } + if (Int64Field86 != 0L) { + output.WriteRawTag(176, 5); + output.WriteInt64(Int64Field86); + } + if (Int64Field87 != 0L) { + output.WriteRawTag(184, 5); + output.WriteInt64(Int64Field87); + } + if (DoubleField88 != 0D) { + output.WriteRawTag(193, 5); + output.WriteDouble(DoubleField88); + } + if (DoubleField89 != 0D) { + output.WriteRawTag(201, 5); + output.WriteDouble(DoubleField89); + } + if (DoubleField90 != 0D) { + output.WriteRawTag(209, 5); + output.WriteDouble(DoubleField90); + } + if (DoubleField91 != 0D) { + output.WriteRawTag(217, 5); + output.WriteDouble(DoubleField91); + } + if (DoubleField92 != 0D) { + output.WriteRawTag(225, 5); + output.WriteDouble(DoubleField92); + } + if (DoubleField93 != 0D) { + output.WriteRawTag(233, 5); + output.WriteDouble(DoubleField93); + } + if (DoubleField94 != 0D) { + output.WriteRawTag(241, 5); + output.WriteDouble(DoubleField94); + } + if (DoubleField95 != 0D) { + output.WriteRawTag(249, 5); + output.WriteDouble(DoubleField95); + } + if (DoubleField96 != 0D) { + output.WriteRawTag(129, 6); + output.WriteDouble(DoubleField96); + } + if (DoubleField97 != 0D) { + output.WriteRawTag(137, 6); + output.WriteDouble(DoubleField97); + } + if (DoubleField98 != 0D) { + output.WriteRawTag(145, 6); + output.WriteDouble(DoubleField98); + } + if (DoubleField99 != 0D) { + output.WriteRawTag(153, 6); + output.WriteDouble(DoubleField99); + } + repeatedIntField100_.WriteTo(ref output, _repeated_repeatedIntField100_codec); + if (DoubleField101 != 0D) { + output.WriteRawTag(169, 6); + output.WriteDouble(DoubleField101); + } + if (DoubleField102 != 0D) { + output.WriteRawTag(177, 6); + output.WriteDouble(DoubleField102); + } + if (DoubleField103 != 0D) { + output.WriteRawTag(185, 6); + output.WriteDouble(DoubleField103); + } + if (DoubleField104 != 0D) { + output.WriteRawTag(193, 6); + output.WriteDouble(DoubleField104); + } + if (DoubleField105 != 0D) { + output.WriteRawTag(201, 6); + output.WriteDouble(DoubleField105); + } + if (DoubleField106 != 0D) { + output.WriteRawTag(209, 6); + output.WriteDouble(DoubleField106); + } + if (Int64Field107 != 0L) { + output.WriteRawTag(216, 6); + output.WriteInt64(Int64Field107); + } + if (DoubleField108 != 0D) { + output.WriteRawTag(225, 6); + output.WriteDouble(DoubleField108); + } + if (DoubleField109 != 0D) { + output.WriteRawTag(233, 6); + output.WriteDouble(DoubleField109); + } + if (Int64Field110 != 0L) { + output.WriteRawTag(240, 6); + output.WriteInt64(Int64Field110); + } + if (DoubleField111 != 0D) { + output.WriteRawTag(249, 6); + output.WriteDouble(DoubleField111); + } + if (Int64Field112 != 0L) { + output.WriteRawTag(128, 7); + output.WriteInt64(Int64Field112); + } + if (DoubleField113 != 0D) { + output.WriteRawTag(137, 7); + output.WriteDouble(DoubleField113); + } + if (Int64Field114 != 0L) { + output.WriteRawTag(144, 7); + output.WriteInt64(Int64Field114); + } + if (Int64Field115 != 0L) { + output.WriteRawTag(152, 7); + output.WriteInt64(Int64Field115); + } + if (DoubleField116 != 0D) { + output.WriteRawTag(161, 7); + output.WriteDouble(DoubleField116); + } + if (Int64Field117 != 0L) { + output.WriteRawTag(168, 7); + output.WriteInt64(Int64Field117); + } + if (DoubleField118 != 0D) { + output.WriteRawTag(177, 7); + output.WriteDouble(DoubleField118); + } + if (DoubleField119 != 0D) { + output.WriteRawTag(185, 7); + output.WriteDouble(DoubleField119); + } + if (DoubleField120 != 0D) { + output.WriteRawTag(193, 7); + output.WriteDouble(DoubleField120); + } + if (DoubleField121 != 0D) { + output.WriteRawTag(201, 7); + output.WriteDouble(DoubleField121); + } + if (DoubleField122 != 0D) { + output.WriteRawTag(209, 7); + output.WriteDouble(DoubleField122); + } + if (DoubleField123 != 0D) { + output.WriteRawTag(217, 7); + output.WriteDouble(DoubleField123); + } + if (DoubleField124 != 0D) { + output.WriteRawTag(225, 7); + output.WriteDouble(DoubleField124); + } + if (Int64Field125 != 0L) { + output.WriteRawTag(232, 7); + output.WriteInt64(Int64Field125); + } + if (Int64Field126 != 0L) { + output.WriteRawTag(240, 7); + output.WriteInt64(Int64Field126); + } + if (Int64Field127 != 0L) { + output.WriteRawTag(248, 7); + output.WriteInt64(Int64Field127); + } + if (DoubleField128 != 0D) { + output.WriteRawTag(129, 8); + output.WriteDouble(DoubleField128); + } + if (DoubleField129 != 0D) { + output.WriteRawTag(137, 8); + output.WriteDouble(DoubleField129); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (DoubleField95 != 0D) { + size += 2 + 8; + } + if (DoubleField1 != 0D) { + size += 1 + 8; + } + if (DoubleField79 != 0D) { + size += 2 + 8; + } + if (Int64Field2 != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Int64Field2); + } + if (DoubleField96 != 0D) { + size += 2 + 8; + } + if (Int64Field3 != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Int64Field3); + } + if (Int64Field4 != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Int64Field4); + } + if (DoubleField97 != 0D) { + size += 2 + 8; + } + if (DoubleField65 != 0D) { + size += 2 + 8; + } + if (DoubleField66 != 0D) { + size += 2 + 8; + } + if (DoubleField7 != 0D) { + size += 1 + 8; + } + if (DoubleField62 != 0D) { + size += 2 + 8; + } + if (DoubleField118 != 0D) { + size += 2 + 8; + } + if (DoubleField119 != 0D) { + size += 2 + 8; + } + if (DoubleField67 != 0D) { + size += 2 + 8; + } + if (DoubleField120 != 0D) { + size += 2 + 8; + } + if (DoubleField121 != 0D) { + size += 2 + 8; + } + if (DoubleField122 != 0D) { + size += 2 + 8; + } + if (DoubleField123 != 0D) { + size += 2 + 8; + } + if (DoubleField124 != 0D) { + size += 2 + 8; + } + if (DoubleField8 != 0D) { + size += 1 + 8; + } + if (DoubleField9 != 0D) { + size += 1 + 8; + } + if (DoubleField98 != 0D) { + size += 2 + 8; + } + if (DoubleField10 != 0D) { + size += 1 + 8; + } + if (DoubleField11 != 0D) { + size += 1 + 8; + } + if (DoubleField99 != 0D) { + size += 2 + 8; + } + if (DoubleField84 != 0D) { + size += 2 + 8; + } + if (DoubleField14 != 0D) { + size += 1 + 8; + } + if (DoubleField77 != 0D) { + size += 2 + 8; + } + if (DoubleField15 != 0D) { + size += 1 + 8; + } + if (Int64Field19 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field19); + } + if (Int64Field115 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field115); + } + if (DoubleField116 != 0D) { + size += 2 + 8; + } + if (Int64Field117 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field117); + } + if (DoubleField20 != 0D) { + size += 2 + 8; + } + if (DoubleField21 != 0D) { + size += 2 + 8; + } + if (StringField73.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(StringField73); + } + if (StringField74.Length != 0) { + size += 2 + pb::CodedOutputStream.ComputeStringSize(StringField74); + } + if (DoubleField22 != 0D) { + size += 2 + 8; + } + if (DoubleField69 != 0D) { + size += 2 + 8; + } + if (DoubleField70 != 0D) { + size += 2 + 8; + } + if (DoubleField71 != 0D) { + size += 2 + 8; + } + if (DoubleField72 != 0D) { + size += 2 + 8; + } + if (DoubleField25 != 0D) { + size += 2 + 8; + } + if (Int64Field26 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field26); + } + if (DoubleField68 != 0D) { + size += 2 + 8; + } + if (DoubleField28 != 0D) { + size += 2 + 8; + } + if (DoubleField106 != 0D) { + size += 2 + 8; + } + if (DoubleField29 != 0D) { + size += 2 + 8; + } + if (DoubleField30 != 0D) { + size += 2 + 8; + } + if (DoubleField101 != 0D) { + size += 2 + 8; + } + if (DoubleField102 != 0D) { + size += 2 + 8; + } + if (DoubleField103 != 0D) { + size += 2 + 8; + } + if (DoubleField104 != 0D) { + size += 2 + 8; + } + if (DoubleField105 != 0D) { + size += 2 + 8; + } + if (DoubleField31 != 0D) { + size += 2 + 8; + } + if (Int64Field32 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field32); + } + if (DoubleField75 != 0D) { + size += 2 + 8; + } + if (DoubleField129 != 0D) { + size += 2 + 8; + } + if (EnumField80 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField80); + } + if (EnumField81 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField81); + } + if (Int64Field82 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field82); + } + if (EnumField83 != 0) { + size += 2 + pb::CodedOutputStream.ComputeInt32Size(EnumField83); + } + if (Int64Field85 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field85); + } + if (Int64Field86 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field86); + } + if (Int64Field87 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field87); + } + if (Int64Field125 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field125); + } + if (Int64Field37 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field37); + } + if (DoubleField38 != 0D) { + size += 2 + 8; + } + if (Interactions != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Interactions); + } + size += repeatedIntField100_.CalculateSize(_repeated_repeatedIntField100_codec); + if (DoubleField40 != 0D) { + size += 2 + 8; + } + if (Int64Field41 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field41); + } + if (Int64Field126 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field126); + } + if (Int64Field127 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field127); + } + if (DoubleField128 != 0D) { + size += 2 + 8; + } + if (DoubleField109 != 0D) { + size += 2 + 8; + } + if (Int64Field110 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field110); + } + if (DoubleField111 != 0D) { + size += 2 + 8; + } + if (Int64Field112 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field112); + } + if (DoubleField113 != 0D) { + size += 2 + 8; + } + if (Int64Field114 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field114); + } + if (DoubleField42 != 0D) { + size += 2 + 8; + } + if (Int64Field43 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field43); + } + if (Int64Field44 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field44); + } + if (DoubleField45 != 0D) { + size += 2 + 8; + } + if (DoubleField46 != 0D) { + size += 2 + 8; + } + if (DoubleField78 != 0D) { + size += 2 + 8; + } + if (DoubleField88 != 0D) { + size += 2 + 8; + } + if (DoubleField47 != 0D) { + size += 2 + 8; + } + if (DoubleField89 != 0D) { + size += 2 + 8; + } + if (DoubleField48 != 0D) { + size += 2 + 8; + } + if (DoubleField49 != 0D) { + size += 2 + 8; + } + if (DoubleField50 != 0D) { + size += 2 + 8; + } + if (DoubleField90 != 0D) { + size += 2 + 8; + } + if (DoubleField51 != 0D) { + size += 2 + 8; + } + if (DoubleField91 != 0D) { + size += 2 + 8; + } + if (DoubleField92 != 0D) { + size += 2 + 8; + } + if (Int64Field107 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field107); + } + if (DoubleField93 != 0D) { + size += 2 + 8; + } + if (DoubleField108 != 0D) { + size += 2 + 8; + } + if (DoubleField52 != 0D) { + size += 2 + 8; + } + if (DoubleField53 != 0D) { + size += 2 + 8; + } + if (DoubleField94 != 0D) { + size += 2 + 8; + } + if (DoubleField54 != 0D) { + size += 2 + 8; + } + if (DoubleField55 != 0D) { + size += 2 + 8; + } + if (DoubleField56 != 0D) { + size += 2 + 8; + } + if (DoubleField57 != 0D) { + size += 2 + 8; + } + if (DoubleField58 != 0D) { + size += 2 + 8; + } + if (Int64Field59 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field59); + } + if (Int64Field60 != 0L) { + size += 2 + pb::CodedOutputStream.ComputeInt64Size(Int64Field60); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(ManyPrimitiveFieldsMessage other) { + if (other == null) { + return; + } + if (other.DoubleField95 != 0D) { + DoubleField95 = other.DoubleField95; + } + if (other.DoubleField1 != 0D) { + DoubleField1 = other.DoubleField1; + } + if (other.DoubleField79 != 0D) { + DoubleField79 = other.DoubleField79; + } + if (other.Int64Field2 != 0L) { + Int64Field2 = other.Int64Field2; + } + if (other.DoubleField96 != 0D) { + DoubleField96 = other.DoubleField96; + } + if (other.Int64Field3 != 0L) { + Int64Field3 = other.Int64Field3; + } + if (other.Int64Field4 != 0L) { + Int64Field4 = other.Int64Field4; + } + if (other.DoubleField97 != 0D) { + DoubleField97 = other.DoubleField97; + } + if (other.DoubleField65 != 0D) { + DoubleField65 = other.DoubleField65; + } + if (other.DoubleField66 != 0D) { + DoubleField66 = other.DoubleField66; + } + if (other.DoubleField7 != 0D) { + DoubleField7 = other.DoubleField7; + } + if (other.DoubleField62 != 0D) { + DoubleField62 = other.DoubleField62; + } + if (other.DoubleField118 != 0D) { + DoubleField118 = other.DoubleField118; + } + if (other.DoubleField119 != 0D) { + DoubleField119 = other.DoubleField119; + } + if (other.DoubleField67 != 0D) { + DoubleField67 = other.DoubleField67; + } + if (other.DoubleField120 != 0D) { + DoubleField120 = other.DoubleField120; + } + if (other.DoubleField121 != 0D) { + DoubleField121 = other.DoubleField121; + } + if (other.DoubleField122 != 0D) { + DoubleField122 = other.DoubleField122; + } + if (other.DoubleField123 != 0D) { + DoubleField123 = other.DoubleField123; + } + if (other.DoubleField124 != 0D) { + DoubleField124 = other.DoubleField124; + } + if (other.DoubleField8 != 0D) { + DoubleField8 = other.DoubleField8; + } + if (other.DoubleField9 != 0D) { + DoubleField9 = other.DoubleField9; + } + if (other.DoubleField98 != 0D) { + DoubleField98 = other.DoubleField98; + } + if (other.DoubleField10 != 0D) { + DoubleField10 = other.DoubleField10; + } + if (other.DoubleField11 != 0D) { + DoubleField11 = other.DoubleField11; + } + if (other.DoubleField99 != 0D) { + DoubleField99 = other.DoubleField99; + } + if (other.DoubleField84 != 0D) { + DoubleField84 = other.DoubleField84; + } + if (other.DoubleField14 != 0D) { + DoubleField14 = other.DoubleField14; + } + if (other.DoubleField77 != 0D) { + DoubleField77 = other.DoubleField77; + } + if (other.DoubleField15 != 0D) { + DoubleField15 = other.DoubleField15; + } + if (other.Int64Field19 != 0L) { + Int64Field19 = other.Int64Field19; + } + if (other.Int64Field115 != 0L) { + Int64Field115 = other.Int64Field115; + } + if (other.DoubleField116 != 0D) { + DoubleField116 = other.DoubleField116; + } + if (other.Int64Field117 != 0L) { + Int64Field117 = other.Int64Field117; + } + if (other.DoubleField20 != 0D) { + DoubleField20 = other.DoubleField20; + } + if (other.DoubleField21 != 0D) { + DoubleField21 = other.DoubleField21; + } + if (other.StringField73.Length != 0) { + StringField73 = other.StringField73; + } + if (other.StringField74.Length != 0) { + StringField74 = other.StringField74; + } + if (other.DoubleField22 != 0D) { + DoubleField22 = other.DoubleField22; + } + if (other.DoubleField69 != 0D) { + DoubleField69 = other.DoubleField69; + } + if (other.DoubleField70 != 0D) { + DoubleField70 = other.DoubleField70; + } + if (other.DoubleField71 != 0D) { + DoubleField71 = other.DoubleField71; + } + if (other.DoubleField72 != 0D) { + DoubleField72 = other.DoubleField72; + } + if (other.DoubleField25 != 0D) { + DoubleField25 = other.DoubleField25; + } + if (other.Int64Field26 != 0L) { + Int64Field26 = other.Int64Field26; + } + if (other.DoubleField68 != 0D) { + DoubleField68 = other.DoubleField68; + } + if (other.DoubleField28 != 0D) { + DoubleField28 = other.DoubleField28; + } + if (other.DoubleField106 != 0D) { + DoubleField106 = other.DoubleField106; + } + if (other.DoubleField29 != 0D) { + DoubleField29 = other.DoubleField29; + } + if (other.DoubleField30 != 0D) { + DoubleField30 = other.DoubleField30; + } + if (other.DoubleField101 != 0D) { + DoubleField101 = other.DoubleField101; + } + if (other.DoubleField102 != 0D) { + DoubleField102 = other.DoubleField102; + } + if (other.DoubleField103 != 0D) { + DoubleField103 = other.DoubleField103; + } + if (other.DoubleField104 != 0D) { + DoubleField104 = other.DoubleField104; + } + if (other.DoubleField105 != 0D) { + DoubleField105 = other.DoubleField105; + } + if (other.DoubleField31 != 0D) { + DoubleField31 = other.DoubleField31; + } + if (other.Int64Field32 != 0L) { + Int64Field32 = other.Int64Field32; + } + if (other.DoubleField75 != 0D) { + DoubleField75 = other.DoubleField75; + } + if (other.DoubleField129 != 0D) { + DoubleField129 = other.DoubleField129; + } + if (other.EnumField80 != 0) { + EnumField80 = other.EnumField80; + } + if (other.EnumField81 != 0) { + EnumField81 = other.EnumField81; + } + if (other.Int64Field82 != 0L) { + Int64Field82 = other.Int64Field82; + } + if (other.EnumField83 != 0) { + EnumField83 = other.EnumField83; + } + if (other.Int64Field85 != 0L) { + Int64Field85 = other.Int64Field85; + } + if (other.Int64Field86 != 0L) { + Int64Field86 = other.Int64Field86; + } + if (other.Int64Field87 != 0L) { + Int64Field87 = other.Int64Field87; + } + if (other.Int64Field125 != 0L) { + Int64Field125 = other.Int64Field125; + } + if (other.Int64Field37 != 0L) { + Int64Field37 = other.Int64Field37; + } + if (other.DoubleField38 != 0D) { + DoubleField38 = other.DoubleField38; + } + if (other.Interactions != 0L) { + Interactions = other.Interactions; + } + repeatedIntField100_.Add(other.repeatedIntField100_); + if (other.DoubleField40 != 0D) { + DoubleField40 = other.DoubleField40; + } + if (other.Int64Field41 != 0L) { + Int64Field41 = other.Int64Field41; + } + if (other.Int64Field126 != 0L) { + Int64Field126 = other.Int64Field126; + } + if (other.Int64Field127 != 0L) { + Int64Field127 = other.Int64Field127; + } + if (other.DoubleField128 != 0D) { + DoubleField128 = other.DoubleField128; + } + if (other.DoubleField109 != 0D) { + DoubleField109 = other.DoubleField109; + } + if (other.Int64Field110 != 0L) { + Int64Field110 = other.Int64Field110; + } + if (other.DoubleField111 != 0D) { + DoubleField111 = other.DoubleField111; + } + if (other.Int64Field112 != 0L) { + Int64Field112 = other.Int64Field112; + } + if (other.DoubleField113 != 0D) { + DoubleField113 = other.DoubleField113; + } + if (other.Int64Field114 != 0L) { + Int64Field114 = other.Int64Field114; + } + if (other.DoubleField42 != 0D) { + DoubleField42 = other.DoubleField42; + } + if (other.Int64Field43 != 0L) { + Int64Field43 = other.Int64Field43; + } + if (other.Int64Field44 != 0L) { + Int64Field44 = other.Int64Field44; + } + if (other.DoubleField45 != 0D) { + DoubleField45 = other.DoubleField45; + } + if (other.DoubleField46 != 0D) { + DoubleField46 = other.DoubleField46; + } + if (other.DoubleField78 != 0D) { + DoubleField78 = other.DoubleField78; + } + if (other.DoubleField88 != 0D) { + DoubleField88 = other.DoubleField88; + } + if (other.DoubleField47 != 0D) { + DoubleField47 = other.DoubleField47; + } + if (other.DoubleField89 != 0D) { + DoubleField89 = other.DoubleField89; + } + if (other.DoubleField48 != 0D) { + DoubleField48 = other.DoubleField48; + } + if (other.DoubleField49 != 0D) { + DoubleField49 = other.DoubleField49; + } + if (other.DoubleField50 != 0D) { + DoubleField50 = other.DoubleField50; + } + if (other.DoubleField90 != 0D) { + DoubleField90 = other.DoubleField90; + } + if (other.DoubleField51 != 0D) { + DoubleField51 = other.DoubleField51; + } + if (other.DoubleField91 != 0D) { + DoubleField91 = other.DoubleField91; + } + if (other.DoubleField92 != 0D) { + DoubleField92 = other.DoubleField92; + } + if (other.Int64Field107 != 0L) { + Int64Field107 = other.Int64Field107; + } + if (other.DoubleField93 != 0D) { + DoubleField93 = other.DoubleField93; + } + if (other.DoubleField108 != 0D) { + DoubleField108 = other.DoubleField108; + } + if (other.DoubleField52 != 0D) { + DoubleField52 = other.DoubleField52; + } + if (other.DoubleField53 != 0D) { + DoubleField53 = other.DoubleField53; + } + if (other.DoubleField94 != 0D) { + DoubleField94 = other.DoubleField94; + } + if (other.DoubleField54 != 0D) { + DoubleField54 = other.DoubleField54; + } + if (other.DoubleField55 != 0D) { + DoubleField55 = other.DoubleField55; + } + if (other.DoubleField56 != 0D) { + DoubleField56 = other.DoubleField56; + } + if (other.DoubleField57 != 0D) { + DoubleField57 = other.DoubleField57; + } + if (other.DoubleField58 != 0D) { + DoubleField58 = other.DoubleField58; + } + if (other.Int64Field59 != 0L) { + Int64Field59 = other.Int64Field59; + } + if (other.Int64Field60 != 0L) { + Int64Field60 = other.Int64Field60; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 9: { + DoubleField1 = input.ReadDouble(); + break; + } + case 16: { + Int64Field2 = input.ReadInt64(); + break; + } + case 24: { + Int64Field3 = input.ReadInt64(); + break; + } + case 32: { + Int64Field4 = input.ReadInt64(); + break; + } + case 57: { + DoubleField7 = input.ReadDouble(); + break; + } + case 65: { + DoubleField8 = input.ReadDouble(); + break; + } + case 73: { + DoubleField9 = input.ReadDouble(); + break; + } + case 81: { + DoubleField10 = input.ReadDouble(); + break; + } + case 89: { + DoubleField11 = input.ReadDouble(); + break; + } + case 113: { + DoubleField14 = input.ReadDouble(); + break; + } + case 121: { + DoubleField15 = input.ReadDouble(); + break; + } + case 152: { + Int64Field19 = input.ReadInt64(); + break; + } + case 161: { + DoubleField20 = input.ReadDouble(); + break; + } + case 169: { + DoubleField21 = input.ReadDouble(); + break; + } + case 177: { + DoubleField22 = input.ReadDouble(); + break; + } + case 201: { + DoubleField25 = input.ReadDouble(); + break; + } + case 208: { + Int64Field26 = input.ReadInt64(); + break; + } + case 225: { + DoubleField28 = input.ReadDouble(); + break; + } + case 233: { + DoubleField29 = input.ReadDouble(); + break; + } + case 241: { + DoubleField30 = input.ReadDouble(); + break; + } + case 249: { + DoubleField31 = input.ReadDouble(); + break; + } + case 256: { + Int64Field32 = input.ReadInt64(); + break; + } + case 296: { + Int64Field37 = input.ReadInt64(); + break; + } + case 305: { + DoubleField38 = input.ReadDouble(); + break; + } + case 312: { + Interactions = input.ReadInt64(); + break; + } + case 321: { + DoubleField40 = input.ReadDouble(); + break; + } + case 328: { + Int64Field41 = input.ReadInt64(); + break; + } + case 337: { + DoubleField42 = input.ReadDouble(); + break; + } + case 344: { + Int64Field43 = input.ReadInt64(); + break; + } + case 352: { + Int64Field44 = input.ReadInt64(); + break; + } + case 361: { + DoubleField45 = input.ReadDouble(); + break; + } + case 369: { + DoubleField46 = input.ReadDouble(); + break; + } + case 377: { + DoubleField47 = input.ReadDouble(); + break; + } + case 385: { + DoubleField48 = input.ReadDouble(); + break; + } + case 393: { + DoubleField49 = input.ReadDouble(); + break; + } + case 401: { + DoubleField50 = input.ReadDouble(); + break; + } + case 409: { + DoubleField51 = input.ReadDouble(); + break; + } + case 417: { + DoubleField52 = input.ReadDouble(); + break; + } + case 425: { + DoubleField53 = input.ReadDouble(); + break; + } + case 433: { + DoubleField54 = input.ReadDouble(); + break; + } + case 441: { + DoubleField55 = input.ReadDouble(); + break; + } + case 449: { + DoubleField56 = input.ReadDouble(); + break; + } + case 457: { + DoubleField57 = input.ReadDouble(); + break; + } + case 465: { + DoubleField58 = input.ReadDouble(); + break; + } + case 472: { + Int64Field59 = input.ReadInt64(); + break; + } + case 480: { + Int64Field60 = input.ReadInt64(); + break; + } + case 497: { + DoubleField62 = input.ReadDouble(); + break; + } + case 521: { + DoubleField65 = input.ReadDouble(); + break; + } + case 529: { + DoubleField66 = input.ReadDouble(); + break; + } + case 537: { + DoubleField67 = input.ReadDouble(); + break; + } + case 545: { + DoubleField68 = input.ReadDouble(); + break; + } + case 553: { + DoubleField69 = input.ReadDouble(); + break; + } + case 561: { + DoubleField70 = input.ReadDouble(); + break; + } + case 569: { + DoubleField71 = input.ReadDouble(); + break; + } + case 577: { + DoubleField72 = input.ReadDouble(); + break; + } + case 586: { + StringField73 = input.ReadString(); + break; + } + case 594: { + StringField74 = input.ReadString(); + break; + } + case 601: { + DoubleField75 = input.ReadDouble(); + break; + } + case 617: { + DoubleField77 = input.ReadDouble(); + break; + } + case 625: { + DoubleField78 = input.ReadDouble(); + break; + } + case 633: { + DoubleField79 = input.ReadDouble(); + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 656: { + Int64Field82 = input.ReadInt64(); + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 673: { + DoubleField84 = input.ReadDouble(); + break; + } + case 680: { + Int64Field85 = input.ReadInt64(); + break; + } + case 688: { + Int64Field86 = input.ReadInt64(); + break; + } + case 696: { + Int64Field87 = input.ReadInt64(); + break; + } + case 705: { + DoubleField88 = input.ReadDouble(); + break; + } + case 713: { + DoubleField89 = input.ReadDouble(); + break; + } + case 721: { + DoubleField90 = input.ReadDouble(); + break; + } + case 729: { + DoubleField91 = input.ReadDouble(); + break; + } + case 737: { + DoubleField92 = input.ReadDouble(); + break; + } + case 745: { + DoubleField93 = input.ReadDouble(); + break; + } + case 753: { + DoubleField94 = input.ReadDouble(); + break; + } + case 761: { + DoubleField95 = input.ReadDouble(); + break; + } + case 769: { + DoubleField96 = input.ReadDouble(); + break; + } + case 777: { + DoubleField97 = input.ReadDouble(); + break; + } + case 785: { + DoubleField98 = input.ReadDouble(); + break; + } + case 793: { + DoubleField99 = input.ReadDouble(); + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(input, _repeated_repeatedIntField100_codec); + break; + } + case 809: { + DoubleField101 = input.ReadDouble(); + break; + } + case 817: { + DoubleField102 = input.ReadDouble(); + break; + } + case 825: { + DoubleField103 = input.ReadDouble(); + break; + } + case 833: { + DoubleField104 = input.ReadDouble(); + break; + } + case 841: { + DoubleField105 = input.ReadDouble(); + break; + } + case 849: { + DoubleField106 = input.ReadDouble(); + break; + } + case 856: { + Int64Field107 = input.ReadInt64(); + break; + } + case 865: { + DoubleField108 = input.ReadDouble(); + break; + } + case 873: { + DoubleField109 = input.ReadDouble(); + break; + } + case 880: { + Int64Field110 = input.ReadInt64(); + break; + } + case 889: { + DoubleField111 = input.ReadDouble(); + break; + } + case 896: { + Int64Field112 = input.ReadInt64(); + break; + } + case 905: { + DoubleField113 = input.ReadDouble(); + break; + } + case 912: { + Int64Field114 = input.ReadInt64(); + break; + } + case 920: { + Int64Field115 = input.ReadInt64(); + break; + } + case 929: { + DoubleField116 = input.ReadDouble(); + break; + } + case 936: { + Int64Field117 = input.ReadInt64(); + break; + } + case 945: { + DoubleField118 = input.ReadDouble(); + break; + } + case 953: { + DoubleField119 = input.ReadDouble(); + break; + } + case 961: { + DoubleField120 = input.ReadDouble(); + break; + } + case 969: { + DoubleField121 = input.ReadDouble(); + break; + } + case 977: { + DoubleField122 = input.ReadDouble(); + break; + } + case 985: { + DoubleField123 = input.ReadDouble(); + break; + } + case 993: { + DoubleField124 = input.ReadDouble(); + break; + } + case 1000: { + Int64Field125 = input.ReadInt64(); + break; + } + case 1008: { + Int64Field126 = input.ReadInt64(); + break; + } + case 1016: { + Int64Field127 = input.ReadInt64(); + break; + } + case 1025: { + DoubleField128 = input.ReadDouble(); + break; + } + case 1033: { + DoubleField129 = input.ReadDouble(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 9: { + DoubleField1 = input.ReadDouble(); + break; + } + case 16: { + Int64Field2 = input.ReadInt64(); + break; + } + case 24: { + Int64Field3 = input.ReadInt64(); + break; + } + case 32: { + Int64Field4 = input.ReadInt64(); + break; + } + case 57: { + DoubleField7 = input.ReadDouble(); + break; + } + case 65: { + DoubleField8 = input.ReadDouble(); + break; + } + case 73: { + DoubleField9 = input.ReadDouble(); + break; + } + case 81: { + DoubleField10 = input.ReadDouble(); + break; + } + case 89: { + DoubleField11 = input.ReadDouble(); + break; + } + case 113: { + DoubleField14 = input.ReadDouble(); + break; + } + case 121: { + DoubleField15 = input.ReadDouble(); + break; + } + case 152: { + Int64Field19 = input.ReadInt64(); + break; + } + case 161: { + DoubleField20 = input.ReadDouble(); + break; + } + case 169: { + DoubleField21 = input.ReadDouble(); + break; + } + case 177: { + DoubleField22 = input.ReadDouble(); + break; + } + case 201: { + DoubleField25 = input.ReadDouble(); + break; + } + case 208: { + Int64Field26 = input.ReadInt64(); + break; + } + case 225: { + DoubleField28 = input.ReadDouble(); + break; + } + case 233: { + DoubleField29 = input.ReadDouble(); + break; + } + case 241: { + DoubleField30 = input.ReadDouble(); + break; + } + case 249: { + DoubleField31 = input.ReadDouble(); + break; + } + case 256: { + Int64Field32 = input.ReadInt64(); + break; + } + case 296: { + Int64Field37 = input.ReadInt64(); + break; + } + case 305: { + DoubleField38 = input.ReadDouble(); + break; + } + case 312: { + Interactions = input.ReadInt64(); + break; + } + case 321: { + DoubleField40 = input.ReadDouble(); + break; + } + case 328: { + Int64Field41 = input.ReadInt64(); + break; + } + case 337: { + DoubleField42 = input.ReadDouble(); + break; + } + case 344: { + Int64Field43 = input.ReadInt64(); + break; + } + case 352: { + Int64Field44 = input.ReadInt64(); + break; + } + case 361: { + DoubleField45 = input.ReadDouble(); + break; + } + case 369: { + DoubleField46 = input.ReadDouble(); + break; + } + case 377: { + DoubleField47 = input.ReadDouble(); + break; + } + case 385: { + DoubleField48 = input.ReadDouble(); + break; + } + case 393: { + DoubleField49 = input.ReadDouble(); + break; + } + case 401: { + DoubleField50 = input.ReadDouble(); + break; + } + case 409: { + DoubleField51 = input.ReadDouble(); + break; + } + case 417: { + DoubleField52 = input.ReadDouble(); + break; + } + case 425: { + DoubleField53 = input.ReadDouble(); + break; + } + case 433: { + DoubleField54 = input.ReadDouble(); + break; + } + case 441: { + DoubleField55 = input.ReadDouble(); + break; + } + case 449: { + DoubleField56 = input.ReadDouble(); + break; + } + case 457: { + DoubleField57 = input.ReadDouble(); + break; + } + case 465: { + DoubleField58 = input.ReadDouble(); + break; + } + case 472: { + Int64Field59 = input.ReadInt64(); + break; + } + case 480: { + Int64Field60 = input.ReadInt64(); + break; + } + case 497: { + DoubleField62 = input.ReadDouble(); + break; + } + case 521: { + DoubleField65 = input.ReadDouble(); + break; + } + case 529: { + DoubleField66 = input.ReadDouble(); + break; + } + case 537: { + DoubleField67 = input.ReadDouble(); + break; + } + case 545: { + DoubleField68 = input.ReadDouble(); + break; + } + case 553: { + DoubleField69 = input.ReadDouble(); + break; + } + case 561: { + DoubleField70 = input.ReadDouble(); + break; + } + case 569: { + DoubleField71 = input.ReadDouble(); + break; + } + case 577: { + DoubleField72 = input.ReadDouble(); + break; + } + case 586: { + StringField73 = input.ReadString(); + break; + } + case 594: { + StringField74 = input.ReadString(); + break; + } + case 601: { + DoubleField75 = input.ReadDouble(); + break; + } + case 617: { + DoubleField77 = input.ReadDouble(); + break; + } + case 625: { + DoubleField78 = input.ReadDouble(); + break; + } + case 633: { + DoubleField79 = input.ReadDouble(); + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 656: { + Int64Field82 = input.ReadInt64(); + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 673: { + DoubleField84 = input.ReadDouble(); + break; + } + case 680: { + Int64Field85 = input.ReadInt64(); + break; + } + case 688: { + Int64Field86 = input.ReadInt64(); + break; + } + case 696: { + Int64Field87 = input.ReadInt64(); + break; + } + case 705: { + DoubleField88 = input.ReadDouble(); + break; + } + case 713: { + DoubleField89 = input.ReadDouble(); + break; + } + case 721: { + DoubleField90 = input.ReadDouble(); + break; + } + case 729: { + DoubleField91 = input.ReadDouble(); + break; + } + case 737: { + DoubleField92 = input.ReadDouble(); + break; + } + case 745: { + DoubleField93 = input.ReadDouble(); + break; + } + case 753: { + DoubleField94 = input.ReadDouble(); + break; + } + case 761: { + DoubleField95 = input.ReadDouble(); + break; + } + case 769: { + DoubleField96 = input.ReadDouble(); + break; + } + case 777: { + DoubleField97 = input.ReadDouble(); + break; + } + case 785: { + DoubleField98 = input.ReadDouble(); + break; + } + case 793: { + DoubleField99 = input.ReadDouble(); + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(ref input, _repeated_repeatedIntField100_codec); + break; + } + case 809: { + DoubleField101 = input.ReadDouble(); + break; + } + case 817: { + DoubleField102 = input.ReadDouble(); + break; + } + case 825: { + DoubleField103 = input.ReadDouble(); + break; + } + case 833: { + DoubleField104 = input.ReadDouble(); + break; + } + case 841: { + DoubleField105 = input.ReadDouble(); + break; + } + case 849: { + DoubleField106 = input.ReadDouble(); + break; + } + case 856: { + Int64Field107 = input.ReadInt64(); + break; + } + case 865: { + DoubleField108 = input.ReadDouble(); + break; + } + case 873: { + DoubleField109 = input.ReadDouble(); + break; + } + case 880: { + Int64Field110 = input.ReadInt64(); + break; + } + case 889: { + DoubleField111 = input.ReadDouble(); + break; + } + case 896: { + Int64Field112 = input.ReadInt64(); + break; + } + case 905: { + DoubleField113 = input.ReadDouble(); + break; + } + case 912: { + Int64Field114 = input.ReadInt64(); + break; + } + case 920: { + Int64Field115 = input.ReadInt64(); + break; + } + case 929: { + DoubleField116 = input.ReadDouble(); + break; + } + case 936: { + Int64Field117 = input.ReadInt64(); + break; + } + case 945: { + DoubleField118 = input.ReadDouble(); + break; + } + case 953: { + DoubleField119 = input.ReadDouble(); + break; + } + case 961: { + DoubleField120 = input.ReadDouble(); + break; + } + case 969: { + DoubleField121 = input.ReadDouble(); + break; + } + case 977: { + DoubleField122 = input.ReadDouble(); + break; + } + case 985: { + DoubleField123 = input.ReadDouble(); + break; + } + case 993: { + DoubleField124 = input.ReadDouble(); + break; + } + case 1000: { + Int64Field125 = input.ReadInt64(); + break; + } + case 1008: { + Int64Field126 = input.ReadInt64(); + break; + } + case 1016: { + Int64Field127 = input.ReadInt64(); + break; + } + case 1025: { + DoubleField128 = input.ReadDouble(); + break; + } + case 1033: { + DoubleField129 = input.ReadDouble(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs new file mode 100644 index 0000000..5a3bba7 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs @@ -0,0 +1,198 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Buffers; +using Google.Protobuf.WellKnownTypes; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmark that tests writing performance for various messages. + /// + [MemoryDiagnoser] + public class WriteMessagesBenchmark + { + const int MaxMessages = 100; + + SubTest manyWrapperFieldsTest = new SubTest(ParseMessagesBenchmark.CreateManyWrapperFieldsMessage(), MaxMessages); + SubTest manyPrimitiveFieldsTest = new SubTest(ParseMessagesBenchmark.CreateManyPrimitiveFieldsMessage(), MaxMessages); + SubTest emptyMessageTest = new SubTest(new Empty(), MaxMessages); + + public IEnumerable MessageCountValues => new[] { 10, 100 }; + + [GlobalSetup] + public void GlobalSetup() + { + } + + [Benchmark] + public byte[] ManyWrapperFieldsMessage_ToByteArray() + { + return manyWrapperFieldsTest.ToByteArray(); + } + + [Benchmark] + public byte[] ManyWrapperFieldsMessage_WriteToCodedOutputStream() + { + return manyWrapperFieldsTest.WriteToCodedOutputStream_PreAllocatedBuffer(); + } + + [Benchmark] + public byte[] ManyWrapperFieldsMessage_WriteToSpan() + { + return manyWrapperFieldsTest.WriteToSpan_PreAllocatedBuffer(); + } + + + [Benchmark] + public byte[] ManyPrimitiveFieldsMessage_ToByteArray() + { + return manyPrimitiveFieldsTest.ToByteArray(); + } + + [Benchmark] + public byte[] ManyPrimitiveFieldsMessage_WriteToCodedOutputStream() + { + return manyPrimitiveFieldsTest.WriteToCodedOutputStream_PreAllocatedBuffer(); + } + + [Benchmark] + public byte[] ManyPrimitiveFieldsMessage_WriteToSpan() + { + return manyPrimitiveFieldsTest.WriteToSpan_PreAllocatedBuffer(); + } + + [Benchmark] + public byte[] EmptyMessage_ToByteArray() + { + return emptyMessageTest.ToByteArray(); + } + + [Benchmark] + public byte[] EmptyMessage_WriteToCodedOutputStream() + { + return emptyMessageTest.WriteToCodedOutputStream_PreAllocatedBuffer(); + } + + [Benchmark] + public byte[] EmptyMessage_WriteToSpan() + { + return emptyMessageTest.WriteToSpan_PreAllocatedBuffer(); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyWrapperFieldsMessage_WriteDelimitedMessagesToCodedOutputStream(int messageCount) + { + manyWrapperFieldsTest.WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyWrapperFieldsMessage_WriteDelimitedMessagesToSpan(int messageCount) + { + manyWrapperFieldsTest.WriteDelimitedMessagesToSpan_PreAllocatedBuffer(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyPrimitiveFieldsMessage_WriteDelimitedMessagesToCodedOutputStream(int messageCount) + { + manyPrimitiveFieldsTest.WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(messageCount); + } + + [Benchmark] + [ArgumentsSource(nameof(MessageCountValues))] + public void ManyPrimitiveFieldsMessage_WriteDelimitedMessagesToSpan(int messageCount) + { + manyPrimitiveFieldsTest.WriteDelimitedMessagesToSpan_PreAllocatedBuffer(messageCount); + } + + private class SubTest + { + private readonly IMessage message; + private readonly byte[] outputBuffer; + private readonly byte[] multipleMessagesOutputBuffer; + + public SubTest(IMessage message, int maxMessageCount) + { + this.message = message; + + int messageSize = message.CalculateSize(); + this.outputBuffer = new byte[messageSize]; + this.multipleMessagesOutputBuffer = new byte[maxMessageCount * (messageSize + CodedOutputStream.ComputeLengthSize(messageSize))]; + } + + public byte[] ToByteArray() => message.ToByteArray(); + + public byte[] WriteToCodedOutputStream_PreAllocatedBuffer() + { + var cos = new CodedOutputStream(outputBuffer); // use pre-existing output buffer + message.WriteTo(cos); + return outputBuffer; + } + + public byte[] WriteToSpan_PreAllocatedBuffer() + { + var span = new Span(outputBuffer); // use pre-existing output buffer + message.WriteTo(span); + return outputBuffer; + } + + public byte[] WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(int messageCount) + { + var cos = new CodedOutputStream(multipleMessagesOutputBuffer); // use pre-existing output buffer + for (int i = 0; i < messageCount; i++) + { + cos.WriteMessage(message); + } + return multipleMessagesOutputBuffer; + } + + public byte[] WriteDelimitedMessagesToSpan_PreAllocatedBuffer(int messageCount) + { + var span = new Span(multipleMessagesOutputBuffer); // use pre-existing output buffer + WriteContext.Initialize(ref span, out WriteContext ctx); + for (int i = 0; i < messageCount; i++) + { + ctx.WriteMessage(message); + } + return multipleMessagesOutputBuffer; + } + } + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs new file mode 100644 index 0000000..66b6b4a --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs @@ -0,0 +1,519 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// 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. +#endregion + +using BenchmarkDotNet.Attributes; +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Buffers; +using System.Text; + +namespace Google.Protobuf.Benchmarks +{ + /// + /// Benchmarks throughput when writing raw primitives. + /// + [MemoryDiagnoser] + public class WriteRawPrimitivesBenchmark + { + // key is the encodedSize of varint values + Dictionary varint32Values; + Dictionary varint64Values; + + double[] doubleValues; + float[] floatValues; + + // key is the encodedSize of string values + Dictionary stringValues; + + // key is the encodedSize of string values + Dictionary nonAsciiStringValues; + + // key is the encodedSize of string values + Dictionary byteStringValues; + + // the buffer to which all the data will be written + byte[] outputBuffer; + + Random random = new Random(417384220); // random but deterministic seed + + public IEnumerable StringEncodedSizes => new[] { 1, 4, 10, 105, 10080 }; + + public IEnumerable NonAsciiStringEncodedSizes => new[] { 4, 10, 105, 10080 }; + + [GlobalSetup] + public void GlobalSetup() + { + outputBuffer = new byte[BytesToWrite]; + + varint32Values = new Dictionary(); + varint64Values = new Dictionary(); + for (int encodedSize = 1; encodedSize <= 10; encodedSize++) + { + if (encodedSize <= 5) + { + varint32Values.Add(encodedSize, CreateRandomVarints32(random, BytesToWrite / encodedSize, encodedSize)); + } + varint64Values.Add(encodedSize, CreateRandomVarints64(random, BytesToWrite / encodedSize, encodedSize)); + } + + doubleValues = CreateRandomDoubles(random, BytesToWrite / sizeof(double)); + floatValues = CreateRandomFloats(random, BytesToWrite / sizeof(float)); + + stringValues = new Dictionary(); + + byteStringValues = new Dictionary(); + foreach(var encodedSize in StringEncodedSizes) + { + stringValues.Add(encodedSize, CreateStrings(BytesToWrite / encodedSize, encodedSize)); + byteStringValues.Add(encodedSize, CreateByteStrings(BytesToWrite / encodedSize, encodedSize)); + } + + nonAsciiStringValues = new Dictionary(); + foreach(var encodedSize in NonAsciiStringEncodedSizes) + { + nonAsciiStringValues.Add(encodedSize, CreateNonAsciiStrings(BytesToWrite / encodedSize, encodedSize)); + } + } + + // Total number of bytes that each benchmark will write. + // Measuring the time taken to write buffer of given size makes it easier to compare parsing speed for different + // types and makes it easy to calculate the througput (in MB/s) + // 10800 bytes is chosen because it is divisible by all possible encoded sizes for all primitive types {1..10} + [Params(10080)] + public int BytesToWrite { get; set; } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + public void WriteRawVarint32_CodedOutputStream(int encodedSize) + { + var values = varint32Values[encodedSize]; + var cos = new CodedOutputStream(outputBuffer); + for (int i = 0; i < values.Length; i++) + { + cos.WriteRawVarint32(values[i]); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + public void WriteRawVarint32_WriteContext(int encodedSize) + { + var values = varint32Values[encodedSize]; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (int i = 0; i < values.Length; i++) + { + ctx.WriteUInt32(values[i]); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + [Arguments(6)] + [Arguments(7)] + [Arguments(8)] + [Arguments(9)] + [Arguments(10)] + public void WriteRawVarint64_CodedOutputStream(int encodedSize) + { + var values = varint64Values[encodedSize]; + var cos = new CodedOutputStream(outputBuffer); + for (int i = 0; i < values.Length; i++) + { + cos.WriteRawVarint64(values[i]); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + [Arguments(6)] + [Arguments(7)] + [Arguments(8)] + [Arguments(9)] + [Arguments(10)] + public void WriteRawVarint64_WriteContext(int encodedSize) + { + var values = varint64Values[encodedSize]; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (int i = 0; i < values.Length; i++) + { + ctx.WriteUInt64(values[i]); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteFixed32_CodedOutputStream() + { + const int encodedSize = sizeof(uint); + var cos = new CodedOutputStream(outputBuffer); + for (int i = 0; i < BytesToWrite / encodedSize; i++) + { + cos.WriteFixed32(12345); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteFixed32_WriteContext() + { + const int encodedSize = sizeof(uint); + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (uint i = 0; i < BytesToWrite / encodedSize; i++) + { + ctx.WriteFixed32(12345); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteFixed64_CodedOutputStream() + { + const int encodedSize = sizeof(ulong); + var cos = new CodedOutputStream(outputBuffer); + for(int i = 0; i < BytesToWrite / encodedSize; i++) + { + cos.WriteFixed64(123456789); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteFixed64_WriteContext() + { + const int encodedSize = sizeof(ulong); + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (uint i = 0; i < BytesToWrite / encodedSize; i++) + { + ctx.WriteFixed64(123456789); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawTag_OneByte_WriteContext() + { + const int encodedSize = 1; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (uint i = 0; i < BytesToWrite / encodedSize; i++) + { + ctx.WriteRawTag(16); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawTag_TwoBytes_WriteContext() + { + const int encodedSize = 2; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (uint i = 0; i < BytesToWrite / encodedSize; i++) + { + ctx.WriteRawTag(137, 6); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawTag_ThreeBytes_WriteContext() + { + const int encodedSize = 3; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + for (uint i = 0; i < BytesToWrite / encodedSize; i++) + { + ctx.WriteRawTag(160, 131, 1); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void Baseline_WriteContext() + { + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + ctx.state.position = outputBuffer.Length; + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawFloat_CodedOutputStream() + { + var cos = new CodedOutputStream(outputBuffer); + foreach (var value in floatValues) + { + cos.WriteFloat(value); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawFloat_WriteContext() + { + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + foreach (var value in floatValues) + { + ctx.WriteFloat(value); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawDouble_CodedOutputStream() + { + var cos = new CodedOutputStream(outputBuffer); + foreach (var value in doubleValues) + { + cos.WriteDouble(value); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + public void WriteRawDouble_WriteContext() + { + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + foreach (var value in doubleValues) + { + ctx.WriteDouble(value); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public void WriteString_CodedOutputStream(int encodedSize) + { + var values = stringValues[encodedSize]; + var cos = new CodedOutputStream(outputBuffer); + foreach (var value in values) + { + cos.WriteString(value); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public void WriteString_WriteContext(int encodedSize) + { + var values = stringValues[encodedSize]; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + foreach (var value in values) + { + ctx.WriteString(value); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(NonAsciiStringEncodedSizes))] + public void WriteNonAsciiString_CodedOutputStream(int encodedSize) + { + var values = nonAsciiStringValues[encodedSize]; + var cos = new CodedOutputStream(outputBuffer); + foreach (var value in values) + { + cos.WriteString(value); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(NonAsciiStringEncodedSizes))] + public void WriteNonAsciiString_WriteContext(int encodedSize) + { + var values = nonAsciiStringValues[encodedSize]; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + foreach (var value in values) + { + ctx.WriteString(value); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public void WriteBytes_CodedOutputStream(int encodedSize) + { + var values = byteStringValues[encodedSize]; + var cos = new CodedOutputStream(outputBuffer); + foreach (var value in values) + { + cos.WriteBytes(value); + } + cos.Flush(); + cos.CheckNoSpaceLeft(); + } + + [Benchmark] + [ArgumentsSource(nameof(StringEncodedSizes))] + public void WriteBytes_WriteContext(int encodedSize) + { + var values = byteStringValues[encodedSize]; + var span = new Span(outputBuffer); + WriteContext.Initialize(ref span, out WriteContext ctx); + foreach (var value in values) + { + ctx.WriteBytes(value); + } + ctx.Flush(); + ctx.CheckNoSpaceLeft(); + } + + private static uint[] CreateRandomVarints32(Random random, int valueCount, int encodedSize) + { + var result = new uint[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = (uint) ParseRawPrimitivesBenchmark.RandomUnsignedVarint(random, encodedSize, true); + } + return result; + } + + private static ulong[] CreateRandomVarints64(Random random, int valueCount, int encodedSize) + { + var result = new ulong[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = ParseRawPrimitivesBenchmark.RandomUnsignedVarint(random, encodedSize, false); + } + return result; + } + + private static float[] CreateRandomFloats(Random random, int valueCount) + { + var result = new float[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = (float)random.NextDouble(); + } + return result; + } + + private static double[] CreateRandomDoubles(Random random, int valueCount) + { + var result = new double[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = random.NextDouble(); + } + return result; + } + + private static string[] CreateStrings(int valueCount, int encodedSize) + { + var str = ParseRawPrimitivesBenchmark.CreateStringWithEncodedSize(encodedSize); + + var result = new string[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = str; + } + return result; + } + + private static string[] CreateNonAsciiStrings(int valueCount, int encodedSize) + { + var str = ParseRawPrimitivesBenchmark.CreateNonAsciiStringWithEncodedSize(encodedSize); + + var result = new string[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = str; + } + return result; + } + + private static ByteString[] CreateByteStrings(int valueCount, int encodedSize) + { + var str = ParseRawPrimitivesBenchmark.CreateStringWithEncodedSize(encodedSize); + + var result = new ByteString[valueCount]; + for (int i = 0; i < valueCount; i++) + { + result[i] = ByteString.CopyFrom(Encoding.UTF8.GetBytes(str)); + } + return result; + } + } +} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto new file mode 100644 index 0000000..6802c25 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto @@ -0,0 +1,237 @@ +syntax = "proto3"; + +package google.protobuf.benchmarks; + +import "google/protobuf/wrappers.proto"; + +// a message that has a large number of wrapper fields +// obfuscated version of an internal message +message ManyWrapperFieldsMessage { + google.protobuf.DoubleValue double_field_95 = 95; + google.protobuf.DoubleValue double_field_1 = 1; + google.protobuf.DoubleValue double_field_79 = 79; + google.protobuf.Int64Value int64_field_2 = 2; + google.protobuf.DoubleValue double_field_96 = 96; + google.protobuf.Int64Value int64_field_3 = 3; + google.protobuf.Int64Value int64_field_4 = 4; + google.protobuf.DoubleValue double_field_97 = 97; + google.protobuf.DoubleValue double_field_65 = 65; + google.protobuf.DoubleValue double_field_66 = 66; + google.protobuf.DoubleValue double_field_7 = 7; + google.protobuf.DoubleValue double_field_62 = 62; + google.protobuf.DoubleValue double_field_118 = 118; + google.protobuf.DoubleValue double_field_119 = 119; + google.protobuf.DoubleValue double_field_67 = 67; + google.protobuf.DoubleValue double_field_120 = 120; + google.protobuf.DoubleValue double_field_121 = 121; + google.protobuf.DoubleValue double_field_122 = 122; + google.protobuf.DoubleValue double_field_123 = 123; + google.protobuf.DoubleValue double_field_124 = 124; + google.protobuf.DoubleValue double_field_8 = 8; + google.protobuf.DoubleValue double_field_9 = 9; + google.protobuf.DoubleValue double_field_98 = 98; + google.protobuf.DoubleValue double_field_10 = 10; + google.protobuf.DoubleValue double_field_11 = 11; + google.protobuf.DoubleValue double_field_99 = 99; + google.protobuf.DoubleValue double_field_84 = 84; + google.protobuf.DoubleValue double_field_14 = 14; + google.protobuf.DoubleValue double_field_77 = 77; + google.protobuf.DoubleValue double_field_15 = 15; + google.protobuf.Int64Value int64_field_19 = 19; + google.protobuf.Int64Value int64_field_115 = 115; + google.protobuf.DoubleValue double_field_116 = 116; + google.protobuf.Int64Value int64_field_117 = 117; + google.protobuf.DoubleValue double_field_20 = 20; + google.protobuf.DoubleValue double_field_21 = 21; + google.protobuf.StringValue string_field_73 = 73; + google.protobuf.StringValue string_field_74 = 74; + google.protobuf.DoubleValue double_field_22 = 22; + google.protobuf.DoubleValue double_field_69 = 69; + google.protobuf.DoubleValue double_field_70 = 70; + google.protobuf.DoubleValue double_field_71 = 71; + google.protobuf.DoubleValue double_field_72 = 72; + google.protobuf.DoubleValue double_field_25 = 25; + google.protobuf.Int64Value int64_field_26 = 26; + google.protobuf.DoubleValue double_field_68 = 68; + google.protobuf.DoubleValue double_field_28 = 28; + google.protobuf.DoubleValue double_field_106 = 106; + google.protobuf.DoubleValue double_field_29 = 29; + google.protobuf.DoubleValue double_field_30 = 30; + google.protobuf.DoubleValue double_field_101 = 101; + google.protobuf.DoubleValue double_field_102 = 102; + google.protobuf.DoubleValue double_field_103 = 103; + google.protobuf.DoubleValue double_field_104 = 104; + google.protobuf.DoubleValue double_field_105 = 105; + google.protobuf.DoubleValue double_field_31 = 31; + google.protobuf.Int64Value int64_field_32 = 32; + google.protobuf.DoubleValue double_field_75 = 75; + google.protobuf.DoubleValue double_field_129 = 129; + int32 enum_field_80 = 80; + int32 enum_field_81 = 81; + google.protobuf.Int64Value int64_field_82 = 82; + int32 enum_field_83 = 83; + google.protobuf.Int64Value int64_field_85 = 85; + google.protobuf.Int64Value int64_field_86 = 86; + google.protobuf.Int64Value int64_field_87 = 87; + google.protobuf.Int64Value int64_field_125 = 125; + google.protobuf.Int64Value int64_field_37 = 37; + google.protobuf.DoubleValue double_field_38 = 38; + google.protobuf.Int64Value interactions = 39; + repeated int32 repeated_int_field_100 = 100; + google.protobuf.DoubleValue double_field_40 = 40; + google.protobuf.Int64Value int64_field_41 = 41; + google.protobuf.Int64Value int64_field_126 = 126; + google.protobuf.Int64Value int64_field_127 = 127; + google.protobuf.DoubleValue double_field_128 = 128; + google.protobuf.DoubleValue double_field_109 = 109; + google.protobuf.Int64Value int64_field_110 = 110; + google.protobuf.DoubleValue double_field_111 = 111; + google.protobuf.Int64Value int64_field_112 = 112; + google.protobuf.DoubleValue double_field_113 = 113; + google.protobuf.Int64Value int64_field_114 = 114; + google.protobuf.DoubleValue double_field_42 = 42; + google.protobuf.Int64Value int64_field_43 = 43; + google.protobuf.Int64Value int64_field_44 = 44; + google.protobuf.DoubleValue double_field_45 = 45; + google.protobuf.DoubleValue double_field_46 = 46; + google.protobuf.DoubleValue double_field_78 = 78; + google.protobuf.DoubleValue double_field_88 = 88; + google.protobuf.DoubleValue double_field_47 = 47; + google.protobuf.DoubleValue double_field_89 = 89; + google.protobuf.DoubleValue double_field_48 = 48; + google.protobuf.DoubleValue double_field_49 = 49; + google.protobuf.DoubleValue double_field_50 = 50; + google.protobuf.DoubleValue double_field_90 = 90; + google.protobuf.DoubleValue double_field_51 = 51; + google.protobuf.DoubleValue double_field_91 = 91; + google.protobuf.DoubleValue double_field_92 = 92; + google.protobuf.Int64Value int64_field_107 = 107; + google.protobuf.DoubleValue double_field_93 = 93; + google.protobuf.DoubleValue double_field_108 = 108; + google.protobuf.DoubleValue double_field_52 = 52; + google.protobuf.DoubleValue double_field_53 = 53; + google.protobuf.DoubleValue double_field_94 = 94; + google.protobuf.DoubleValue double_field_54 = 54; + google.protobuf.DoubleValue double_field_55 = 55; + google.protobuf.DoubleValue double_field_56 = 56; + google.protobuf.DoubleValue double_field_57 = 57; + google.protobuf.DoubleValue double_field_58 = 58; + google.protobuf.Int64Value int64_field_59 = 59; + google.protobuf.Int64Value int64_field_60 = 60; +} + +// same as ManyWrapperFieldsMessages, but with primitive fields +// for comparison. +message ManyPrimitiveFieldsMessage { + double double_field_95 = 95; + double double_field_1 = 1; + double double_field_79 = 79; + int64 int64_field_2 = 2; + double double_field_96 = 96; + int64 int64_field_3 = 3; + int64 int64_field_4 = 4; + double double_field_97 = 97; + double double_field_65 = 65; + double double_field_66 = 66; + double double_field_7 = 7; + double double_field_62 = 62; + double double_field_118 = 118; + double double_field_119 = 119; + double double_field_67 = 67; + double double_field_120 = 120; + double double_field_121 = 121; + double double_field_122 = 122; + double double_field_123 = 123; + double double_field_124 = 124; + double double_field_8 = 8; + double double_field_9 = 9; + double double_field_98 = 98; + double double_field_10 = 10; + double double_field_11 = 11; + double double_field_99 = 99; + double double_field_84 = 84; + double double_field_14 = 14; + double double_field_77 = 77; + double double_field_15 = 15; + int64 int64_field_19 = 19; + int64 int64_field_115 = 115; + double double_field_116 = 116; + int64 int64_field_117 = 117; + double double_field_20 = 20; + double double_field_21 = 21; + string string_field_73 = 73; + string string_field_74 = 74; + double double_field_22 = 22; + double double_field_69 = 69; + double double_field_70 = 70; + double double_field_71 = 71; + double double_field_72 = 72; + double double_field_25 = 25; + int64 int64_field_26 = 26; + double double_field_68 = 68; + double double_field_28 = 28; + double double_field_106 = 106; + double double_field_29 = 29; + double double_field_30 = 30; + double double_field_101 = 101; + double double_field_102 = 102; + double double_field_103 = 103; + double double_field_104 = 104; + double double_field_105 = 105; + double double_field_31 = 31; + int64 int64_field_32 = 32; + double double_field_75 = 75; + double double_field_129 = 129; + int32 enum_field_80 = 80; + int32 enum_field_81 = 81; + int64 int64_field_82 = 82; + int32 enum_field_83 = 83; + int64 int64_field_85 = 85; + int64 int64_field_86 = 86; + int64 int64_field_87 = 87; + int64 int64_field_125 = 125; + int64 int64_field_37 = 37; + double double_field_38 = 38; + int64 interactions = 39; + repeated int32 repeated_int_field_100 = 100; + double double_field_40 = 40; + int64 int64_field_41 = 41; + int64 int64_field_126 = 126; + int64 int64_field_127 = 127; + double double_field_128 = 128; + double double_field_109 = 109; + int64 int64_field_110 = 110; + double double_field_111 = 111; + int64 int64_field_112 = 112; + double double_field_113 = 113; + int64 int64_field_114 = 114; + double double_field_42 = 42; + int64 int64_field_43 = 43; + int64 int64_field_44 = 44; + double double_field_45 = 45; + double double_field_46 = 46; + double double_field_78 = 78; + double double_field_88 = 88; + double double_field_47 = 47; + double double_field_89 = 89; + double double_field_48 = 48; + double double_field_49 = 49; + double double_field_50 = 50; + double double_field_90 = 90; + double double_field_51 = 51; + double double_field_91 = 91; + double double_field_92 = 92; + int64 int64_field_107 = 107; + double double_field_93 = 93; + double double_field_108 = 108; + double double_field_52 = 52; + double double_field_53 = 53; + double double_field_94 = 94; + double double_field_54 = 54; + double double_field_55 = 55; + double double_field_56 = 56; + double double_field_57 = 57; + double double_field_58 = 58; + int64 int64_field_59 = 59; + int64 int64_field_60 = 60; +} \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Conformance/BUILD.bazel b/libs/protobuf/csharp/src/Google.Protobuf.Conformance/BUILD.bazel deleted file mode 100644 index 12ad0f7..0000000 --- a/libs/protobuf/csharp/src/Google.Protobuf.Conformance/BUILD.bazel +++ /dev/null @@ -1,97 +0,0 @@ -load("//build_defs:internal_shell.bzl", "inline_sh_binary") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") - -inline_sh_binary( - name = "build_conformance_test", - srcs = ["Google.Protobuf.Conformance.csproj"], - cmd = "dotnet build -c Release $(SRCS)", - visibility = ["//visibility:private"], -) - -CONFORMANCE_DEPS = [ - "Google.Protobuf.dll", - "Google.Protobuf.Conformance.deps.json", - "Google.Protobuf.Conformance.pdb", - "Google.Protobuf.Conformance.runtimeconfig.json", - "Google.Protobuf.Test.dll", - "Google.Protobuf.Test.TestProtos.dll", - "Microsoft.TestPlatform.CommunicationUtilities.dll", - "Microsoft.TestPlatform.CoreUtilities.dll", - "Microsoft.TestPlatform.CrossPlatEngine.dll", - "Microsoft.TestPlatform.PlatformAbstractions.dll", - "Microsoft.TestPlatform.Utilities.dll", - "Microsoft.VisualStudio.CodeCoverage.Shim.dll", - "Microsoft.VisualStudio.TestPlatform.Common.dll", - "Microsoft.VisualStudio.TestPlatform.ObjectModel.dll", - "NUnit3.TestAdapter.dll", - "Newtonsoft.Json.dll", - "NuGet.Frameworks.dll", - "nunit.engine.api.dll", - "nunit.engine.core.dll", - "nunit.engine.dll", - "nunit.framework.dll", - "testcentric.engine.metadata.dll", - "testhost.dll", -] - -filegroup( - name = "srcs", - srcs = [ - "Conformance.cs", - "Program.cs", - "Google.Protobuf.Conformance.csproj", - ], - visibility = [ - "//csharp:__subpackages__", - ], -) - -genrule( - name = "package_conformance_test", - srcs = [ - "Program.cs", - "Google.Protobuf.Conformance.csproj", - "//conformance:conformance_csharp_proto", - "//csharp:srcs", - ], - visibility = ["//visibility:private"], - tools = [":build_conformance_test"], - outs = CONFORMANCE_DEPS + ["Google.Protobuf.Conformance.dll"], - cmd = """ - SRCDIR=$$(dirname $(location :Program.cs)) - cp $(location //conformance:conformance_csharp_proto) $$SRCDIR - DOTNET_CLI_HOME=/tmp ./$(location :build_conformance_test) - cp -r $$SRCDIR/bin/Release/netcoreapp3.1/* $(RULEDIR) - """, -) - -filegroup( - name = "conformance_dll", - srcs = ["Google.Protobuf.Conformance.dll"], - data = [":package_conformance_test"], - visibility = ["//conformance:__subpackages__"], -) - -filegroup( - name = "conformance_runfiles", - srcs = CONFORMANCE_DEPS, - data = [":package_conformance_test"], - visibility = ["//conformance:__subpackages__"], -) - -################################################################################ -# Distribution files -################################################################################ - -pkg_files( - name = "dist_files", - srcs = [ - "BUILD.bazel", - "Google.Protobuf.Conformance.csproj", - "Conformance.cs", - "Program.cs", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//csharp:__pkg__"], -) - diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs b/libs/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs index 1c2e9ae..d721ecf 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs @@ -43,7 +43,7 @@ namespace Google.Protobuf.Conformance /// class Program { - private static void Main() + private static void Main(string[] args) { // This way we get the binary streams instead of readers/writers. var input = new BinaryReader(Console.OpenStandardInput()); @@ -100,22 +100,32 @@ namespace Google.Protobuf.Conformance return new ConformanceResponse { Skipped = "CSharp doesn't support skipping unknown fields in json parsing." }; } var parser = new JsonParser(new JsonParser.Settings(20, typeRegistry)); - message = request.MessageType switch + switch (request.MessageType) { - "protobuf_test_messages.proto3.TestAllTypesProto3" => parser.Parse(request.JsonPayload), - "protobuf_test_messages.proto2.TestAllTypesProto2" => parser.Parse(request.JsonPayload), - _ => throw new Exception($" Protobuf request doesn't have specific payload type ({request.MessageType})"), - }; + case "protobuf_test_messages.proto3.TestAllTypesProto3": + message = parser.Parse(request.JsonPayload); + break; + case "protobuf_test_messages.proto2.TestAllTypesProto2": + message = parser.Parse(request.JsonPayload); + break; + default: + throw new Exception($" Protobuf request doesn't have specific payload type ({request.MessageType})"); + } break; case ConformanceRequest.PayloadOneofCase.ProtobufPayload: - message = request.MessageType switch + switch (request.MessageType) { - "protobuf_test_messages.proto3.TestAllTypesProto3" => ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser.ParseFrom(request.ProtobufPayload), - "protobuf_test_messages.proto2.TestAllTypesProto2" => ProtobufTestMessages.Proto2.TestAllTypesProto2.Parser - .WithExtensionRegistry(proto2ExtensionRegistry) - .ParseFrom(request.ProtobufPayload), - _ => throw new Exception($" Protobuf request doesn't have specific payload type ({request.MessageType})"), - }; + case "protobuf_test_messages.proto3.TestAllTypesProto3": + message = ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser.ParseFrom(request.ProtobufPayload); + break; + case "protobuf_test_messages.proto2.TestAllTypesProto2": + message = ProtobufTestMessages.Proto2.TestAllTypesProto2.Parser + .WithExtensionRegistry(proto2ExtensionRegistry) + .ParseFrom(request.ProtobufPayload); + break; + default: + throw new Exception($" Protobuf request doesn't have specific payload type ({request.MessageType})"); + } break; case ConformanceRequest.PayloadOneofCase.TextPayload: return new ConformanceResponse { Skipped = "CSharp doesn't support text format" }; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj index 3d0ba71..8d9d64b 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj @@ -7,7 +7,7 @@ --> net462;netstandard1.1;netstandard2.0 - 10.0 + 3.0 ../../keys/Google.Protobuf.snk true False diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs index d3284a4..57e59a9 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs @@ -580,23 +580,23 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Int32_.MergeFrom(other.mapInt32Int32_); - mapInt64Int64_.MergeFrom(other.mapInt64Int64_); - mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); - mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); - mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); - mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); - mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); - mapInt32Float_.MergeFrom(other.mapInt32Float_); - mapInt32Double_.MergeFrom(other.mapInt32Double_); - mapBoolBool_.MergeFrom(other.mapBoolBool_); - mapStringString_.MergeFrom(other.mapStringString_); - mapInt32Bytes_.MergeFrom(other.mapInt32Bytes_); - mapInt32Enum_.MergeFrom(other.mapInt32Enum_); - mapInt32ForeignMessage_.MergeFrom(other.mapInt32ForeignMessage_); + mapInt32Int32_.Add(other.mapInt32Int32_); + mapInt64Int64_.Add(other.mapInt64Int64_); + mapUint32Uint32_.Add(other.mapUint32Uint32_); + mapUint64Uint64_.Add(other.mapUint64Uint64_); + mapSint32Sint32_.Add(other.mapSint32Sint32_); + mapSint64Sint64_.Add(other.mapSint64Sint64_); + mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); + mapInt32Float_.Add(other.mapInt32Float_); + mapInt32Double_.Add(other.mapInt32Double_); + mapBoolBool_.Add(other.mapBoolBool_); + mapStringString_.Add(other.mapStringString_); + mapInt32Bytes_.Add(other.mapInt32Bytes_); + mapInt32Enum_.Add(other.mapInt32Enum_); + mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1100,7 +1100,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Message_.MergeFrom(other.mapInt32Message_); + mapInt32Message_.Add(other.mapInt32Message_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1298,8 +1298,8 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - map1_.MergeFrom(other.map1_); - map2_.MergeFrom(other.map2_); + map1_.Add(other.map1_); + map2_.Add(other.map2_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -1723,21 +1723,21 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - mapInt32Int32_.MergeFrom(other.mapInt32Int32_); - mapInt64Int64_.MergeFrom(other.mapInt64Int64_); - mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); - mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); - mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); - mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); - mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); - mapInt32Float_.MergeFrom(other.mapInt32Float_); - mapInt32Double_.MergeFrom(other.mapInt32Double_); - mapBoolBool_.MergeFrom(other.mapBoolBool_); - mapInt32Enum_.MergeFrom(other.mapInt32Enum_); - mapInt32ForeignMessage_.MergeFrom(other.mapInt32ForeignMessage_); + mapInt32Int32_.Add(other.mapInt32Int32_); + mapInt64Int64_.Add(other.mapInt64Int64_); + mapUint32Uint32_.Add(other.mapUint32Uint32_); + mapUint64Uint64_.Add(other.mapUint64Uint64_); + mapSint32Sint32_.Add(other.mapSint32Sint32_); + mapSint64Sint64_.Add(other.mapSint64Sint64_); + mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); + mapInt32Float_.Add(other.mapInt32Float_); + mapInt32Double_.Add(other.mapInt32Double_); + mapBoolBool_.Add(other.mapBoolBool_); + mapInt32Enum_.Add(other.mapInt32Enum_); + mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -2031,7 +2031,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - type_.MergeFrom(other.type_); + type_.Add(other.type_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -2224,7 +2224,7 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - entry_.MergeFrom(other.entry_); + entry_.Add(other.entry_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs index bbfe2e0..35f2b8a 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs @@ -213,14 +213,12 @@ namespace ProtobufTestMessages.Proto2 { "dGlvbmFsX2Jvb2wY7gcgASgIEhcKDnJlcGVhdGVkX2ludDMyGPMHIAMoBRoa", "Cg1PcHRpb25hbEdyb3VwEgkKAWEYASABKAUiFgoUTnVsbEh5cG90aGVzaXNQ", "cm90bzIiLwoORW51bU9ubHlQcm90bzIiHQoEQm9vbBIKCgZrRmFsc2UQABIJ", - "CgVrVHJ1ZRABIh8KD09uZVN0cmluZ1Byb3RvMhIMCgRkYXRhGAEgASgJIkYK", - "EVByb3RvV2l0aEtleXdvcmRzEg4KBmlubGluZRgBIAEoBRIPCgdjb25jZXB0", - "GAIgASgJEhAKCHJlcXVpcmVzGAMgAygJKkYKEUZvcmVpZ25FbnVtUHJvdG8y", - "Eg8KC0ZPUkVJR05fRk9PEAASDwoLRk9SRUlHTl9CQVIQARIPCgtGT1JFSUdO", - "X0JBWhACOkoKD2V4dGVuc2lvbl9pbnQzMhIxLnByb3RvYnVmX3Rlc3RfbWVz", - "c2FnZXMucHJvdG8yLlRlc3RBbGxUeXBlc1Byb3RvMhh4IAEoBUI4Cihjb20u", - "Z29vZ2xlLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8ySAH4AQGiAgZQ", - "cm90bzI=")); + "CgVrVHJ1ZRABIh8KD09uZVN0cmluZ1Byb3RvMhIMCgRkYXRhGAEgASgJKkYK", + "EUZvcmVpZ25FbnVtUHJvdG8yEg8KC0ZPUkVJR05fRk9PEAASDwoLRk9SRUlH", + "Tl9CQVIQARIPCgtGT1JFSUdOX0JBWhACOkoKD2V4dGVuc2lvbl9pbnQzMhIx", + "LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8yLlRlc3RBbGxUeXBlc1By", + "b3RvMhh4IAEoBUIvCihjb20uZ29vZ2xlLnByb3RvYnVmX3Rlc3RfbWVzc2Fn", + "ZXMucHJvdG8ySAH4AQE=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ProtobufTestMessages.Proto2.ForeignEnumProto2), }, new pb::Extension[] { TestMessagesProto2Extensions.ExtensionInt32 }, new pbr::GeneratedClrTypeInfo[] { @@ -233,8 +231,7 @@ namespace ProtobufTestMessages.Proto2 { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.UnknownToTestAllTypes), global::ProtobufTestMessages.Proto2.UnknownToTestAllTypes.Parser, new[]{ "OptionalInt32", "OptionalString", "NestedMessage", "OptionalGroup", "OptionalBool", "RepeatedInt32" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.UnknownToTestAllTypes.Types.OptionalGroup), global::ProtobufTestMessages.Proto2.UnknownToTestAllTypes.Types.OptionalGroup.Parser, new[]{ "A" }, null, null, null, null)}), new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.NullHypothesisProto2), global::ProtobufTestMessages.Proto2.NullHypothesisProto2.Parser, null, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.EnumOnlyProto2), global::ProtobufTestMessages.Proto2.EnumOnlyProto2.Parser, null, null, new[]{ typeof(global::ProtobufTestMessages.Proto2.EnumOnlyProto2.Types.Bool) }, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.OneStringProto2), global::ProtobufTestMessages.Proto2.OneStringProto2.Parser, new[]{ "Data" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.ProtoWithKeywords), global::ProtobufTestMessages.Proto2.ProtoWithKeywords.Parser, new[]{ "Inline", "Concept", "Requires" }, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto2.OneStringProto2), global::ProtobufTestMessages.Proto2.OneStringProto2.Parser, new[]{ "Data" }, null, null, null, null) })); } #endregion @@ -4345,25 +4342,25 @@ namespace ProtobufTestMessages.Proto2 { unpackedDouble_.Add(other.unpackedDouble_); unpackedBool_.Add(other.unpackedBool_); unpackedNestedEnum_.Add(other.unpackedNestedEnum_); - mapInt32Int32_.MergeFrom(other.mapInt32Int32_); - mapInt64Int64_.MergeFrom(other.mapInt64Int64_); - mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); - mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); - mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); - mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); - mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); - mapInt32Float_.MergeFrom(other.mapInt32Float_); - mapInt32Double_.MergeFrom(other.mapInt32Double_); - mapBoolBool_.MergeFrom(other.mapBoolBool_); - mapStringString_.MergeFrom(other.mapStringString_); - mapStringBytes_.MergeFrom(other.mapStringBytes_); - mapStringNestedMessage_.MergeFrom(other.mapStringNestedMessage_); - mapStringForeignMessage_.MergeFrom(other.mapStringForeignMessage_); - mapStringNestedEnum_.MergeFrom(other.mapStringNestedEnum_); - mapStringForeignEnum_.MergeFrom(other.mapStringForeignEnum_); + mapInt32Int32_.Add(other.mapInt32Int32_); + mapInt64Int64_.Add(other.mapInt64Int64_); + mapUint32Uint32_.Add(other.mapUint32Uint32_); + mapUint64Uint64_.Add(other.mapUint64Uint64_); + mapSint32Sint32_.Add(other.mapSint32Sint32_); + mapSint64Sint64_.Add(other.mapSint64Sint64_); + mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); + mapInt32Float_.Add(other.mapInt32Float_); + mapInt32Double_.Add(other.mapInt32Double_); + mapBoolBool_.Add(other.mapBoolBool_); + mapStringString_.Add(other.mapStringString_); + mapStringBytes_.Add(other.mapStringBytes_); + mapStringNestedMessage_.Add(other.mapStringNestedMessage_); + mapStringForeignMessage_.Add(other.mapStringForeignMessage_); + mapStringNestedEnum_.Add(other.mapStringNestedEnum_); + mapStringForeignEnum_.Add(other.mapStringForeignEnum_); if (other.HasData) { if (!HasData) { Data = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.Data(); @@ -8303,289 +8300,6 @@ namespace ProtobufTestMessages.Proto2 { } - public sealed partial class ProtoWithKeywords : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ProtoWithKeywords()); - private pb::UnknownFieldSet _unknownFields; - private int _hasBits0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::ProtobufTestMessages.Proto2.TestMessagesProto2Reflection.Descriptor.MessageTypes[6]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoWithKeywords() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoWithKeywords(ProtoWithKeywords other) : this() { - _hasBits0 = other._hasBits0; - inline_ = other.inline_; - concept_ = other.concept_; - requires_ = other.requires_.Clone(); - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoWithKeywords Clone() { - return new ProtoWithKeywords(this); - } - - /// Field number for the "inline" field. - public const int InlineFieldNumber = 1; - private readonly static int InlineDefaultValue = 0; - - private int inline_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Inline { - get { if ((_hasBits0 & 1) != 0) { return inline_; } else { return InlineDefaultValue; } } - set { - _hasBits0 |= 1; - inline_ = value; - } - } - /// Gets whether the "inline" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasInline { - get { return (_hasBits0 & 1) != 0; } - } - /// Clears the value of the "inline" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearInline() { - _hasBits0 &= ~1; - } - - /// Field number for the "concept" field. - public const int ConceptFieldNumber = 2; - private readonly static string ConceptDefaultValue = ""; - - private string concept_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Concept { - get { return concept_ ?? ConceptDefaultValue; } - set { - concept_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "concept" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasConcept { - get { return concept_ != null; } - } - /// Clears the value of the "concept" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearConcept() { - concept_ = null; - } - - /// Field number for the "requires" field. - public const int RequiresFieldNumber = 3; - private static readonly pb::FieldCodec _repeated_requires_codec - = pb::FieldCodec.ForString(26); - private readonly pbc::RepeatedField requires_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField Requires { - get { return requires_; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as ProtoWithKeywords); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(ProtoWithKeywords other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (Inline != other.Inline) return false; - if (Concept != other.Concept) return false; - if(!requires_.Equals(other.requires_)) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (HasInline) hash ^= Inline.GetHashCode(); - if (HasConcept) hash ^= Concept.GetHashCode(); - hash ^= requires_.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (HasInline) { - output.WriteRawTag(8); - output.WriteInt32(Inline); - } - if (HasConcept) { - output.WriteRawTag(18); - output.WriteString(Concept); - } - requires_.WriteTo(output, _repeated_requires_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (HasInline) { - output.WriteRawTag(8); - output.WriteInt32(Inline); - } - if (HasConcept) { - output.WriteRawTag(18); - output.WriteString(Concept); - } - requires_.WriteTo(ref output, _repeated_requires_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (HasInline) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Inline); - } - if (HasConcept) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Concept); - } - size += requires_.CalculateSize(_repeated_requires_codec); - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(ProtoWithKeywords other) { - if (other == null) { - return; - } - if (other.HasInline) { - Inline = other.Inline; - } - if (other.HasConcept) { - Concept = other.Concept; - } - requires_.Add(other.requires_); - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 8: { - Inline = input.ReadInt32(); - break; - } - case 18: { - Concept = input.ReadString(); - break; - } - case 26: { - requires_.AddEntriesFrom(input, _repeated_requires_codec); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 8: { - Inline = input.ReadInt32(); - break; - } - case 18: { - Concept = input.ReadString(); - break; - } - case 26: { - requires_.AddEntriesFrom(ref input, _repeated_requires_codec); - break; - } - } - } - } - #endif - - } - #endregion } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs index 74e2a57..520216f 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs @@ -3753,25 +3753,25 @@ namespace ProtobufTestMessages.Proto3 { unpackedDouble_.Add(other.unpackedDouble_); unpackedBool_.Add(other.unpackedBool_); unpackedNestedEnum_.Add(other.unpackedNestedEnum_); - mapInt32Int32_.MergeFrom(other.mapInt32Int32_); - mapInt64Int64_.MergeFrom(other.mapInt64Int64_); - mapUint32Uint32_.MergeFrom(other.mapUint32Uint32_); - mapUint64Uint64_.MergeFrom(other.mapUint64Uint64_); - mapSint32Sint32_.MergeFrom(other.mapSint32Sint32_); - mapSint64Sint64_.MergeFrom(other.mapSint64Sint64_); - mapFixed32Fixed32_.MergeFrom(other.mapFixed32Fixed32_); - mapFixed64Fixed64_.MergeFrom(other.mapFixed64Fixed64_); - mapSfixed32Sfixed32_.MergeFrom(other.mapSfixed32Sfixed32_); - mapSfixed64Sfixed64_.MergeFrom(other.mapSfixed64Sfixed64_); - mapInt32Float_.MergeFrom(other.mapInt32Float_); - mapInt32Double_.MergeFrom(other.mapInt32Double_); - mapBoolBool_.MergeFrom(other.mapBoolBool_); - mapStringString_.MergeFrom(other.mapStringString_); - mapStringBytes_.MergeFrom(other.mapStringBytes_); - mapStringNestedMessage_.MergeFrom(other.mapStringNestedMessage_); - mapStringForeignMessage_.MergeFrom(other.mapStringForeignMessage_); - mapStringNestedEnum_.MergeFrom(other.mapStringNestedEnum_); - mapStringForeignEnum_.MergeFrom(other.mapStringForeignEnum_); + mapInt32Int32_.Add(other.mapInt32Int32_); + mapInt64Int64_.Add(other.mapInt64Int64_); + mapUint32Uint32_.Add(other.mapUint32Uint32_); + mapUint64Uint64_.Add(other.mapUint64Uint64_); + mapSint32Sint32_.Add(other.mapSint32Sint32_); + mapSint64Sint64_.Add(other.mapSint64Sint64_); + mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_); + mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_); + mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_); + mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_); + mapInt32Float_.Add(other.mapInt32Float_); + mapInt32Double_.Add(other.mapInt32Double_); + mapBoolBool_.Add(other.mapBoolBool_); + mapStringString_.Add(other.mapStringString_); + mapStringBytes_.Add(other.mapStringBytes_); + mapStringNestedMessage_.Add(other.mapStringNestedMessage_); + mapStringForeignMessage_.Add(other.mapStringForeignMessage_); + mapStringNestedEnum_.Add(other.mapStringNestedEnum_); + mapStringForeignEnum_.Add(other.mapStringForeignEnum_); if (other.optionalBoolWrapper_ != null) { if (optionalBoolWrapper_ == null || other.OptionalBoolWrapper != false) { OptionalBoolWrapper = other.OptionalBoolWrapper; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs index 7f1aca1..c1f43ce 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs @@ -24112,7 +24112,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { if (other == null) { return; } - foo_.MergeFrom(other.foo_); + foo_.Add(other.foo_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -30708,7 +30708,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { } OptionalGroup.MergeFrom(other.OptionalGroup); } - stringStringMap_.MergeFrom(other.stringStringMap_); + stringStringMap_.Add(other.stringStringMap_); switch (other.OneofFieldCase) { case OneofFieldOneofCase.OneofUint32: OneofUint32 = other.OneofUint32; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs index 3278517..3fe2dd6 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs @@ -30,44 +30,37 @@ namespace UnitTest.Issues.TestProtos { "EiwKBXZhbHVlGAEgASgOMh0udW5pdHRlc3RfaXNzdWVzLk5lZ2F0aXZlRW51", "bRIxCgZ2YWx1ZXMYAiADKA4yHS51bml0dGVzdF9pc3N1ZXMuTmVnYXRpdmVF", "bnVtQgIQABI4Cg1wYWNrZWRfdmFsdWVzGAMgAygOMh0udW5pdHRlc3RfaXNz", - "dWVzLk5lZ2F0aXZlRW51bUICEAEiFQoPRGVwcmVjYXRlZENoaWxkOgIYASK5", - "AgoXRGVwcmVjYXRlZEZpZWxkc01lc3NhZ2USGgoOUHJpbWl0aXZlVmFsdWUY", - "ASABKAVCAhgBEhoKDlByaW1pdGl2ZUFycmF5GAIgAygFQgIYARI6CgxNZXNz", - "YWdlVmFsdWUYAyABKAsyIC51bml0dGVzdF9pc3N1ZXMuRGVwcmVjYXRlZENo", - "aWxkQgIYARI6CgxNZXNzYWdlQXJyYXkYBCADKAsyIC51bml0dGVzdF9pc3N1", - "ZXMuRGVwcmVjYXRlZENoaWxkQgIYARI2CglFbnVtVmFsdWUYBSABKA4yHy51", - "bml0dGVzdF9pc3N1ZXMuRGVwcmVjYXRlZEVudW1CAhgBEjYKCUVudW1BcnJh", - "eRgGIAMoDjIfLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkRW51bUICGAEi", - "GQoJSXRlbUZpZWxkEgwKBGl0ZW0YASABKAUiRAoNUmVzZXJ2ZWROYW1lcxIN", - "CgV0eXBlcxgBIAEoBRISCgpkZXNjcmlwdG9yGAIgASgFGhAKDlNvbWVOZXN0", - "ZWRUeXBlIqABChVUZXN0SnNvbkZpZWxkT3JkZXJpbmcSEwoLcGxhaW5faW50", - "MzIYBCABKAUSEwoJbzFfc3RyaW5nGAIgASgJSAASEgoIbzFfaW50MzIYBSAB", - "KAVIABIUCgxwbGFpbl9zdHJpbmcYASABKAkSEgoIbzJfaW50MzIYBiABKAVI", - "ARITCglvMl9zdHJpbmcYAyABKAlIAUIECgJvMUIECgJvMiJLCgxUZXN0SnNv", - "bk5hbWUSDAoEbmFtZRgBIAEoCRIZCgtkZXNjcmlwdGlvbhgCIAEoCVIEZGVz", - "YxISCgRndWlkGAMgASgJUgRleGlkIn8KDE9uZW9mTWVyZ2luZxIOCgR0ZXh0", - "GAEgASgJSAASNgoGbmVzdGVkGAIgASgLMiQudW5pdHRlc3RfaXNzdWVzLk9u", - "ZW9mTWVyZ2luZy5OZXN0ZWRIABoeCgZOZXN0ZWQSCQoBeBgBIAEoBRIJCgF5", - "GAIgASgFQgcKBXZhbHVlImsKFk51bGxWYWx1ZU91dHNpZGVTdHJ1Y3QSFgoM", - "c3RyaW5nX3ZhbHVlGAEgASgJSAASMAoKbnVsbF92YWx1ZRgCIAEoDjIaLmdv", - "b2dsZS5wcm90b2J1Zi5OdWxsVmFsdWVIAEIHCgV2YWx1ZSJFChNOdWxsVmFs", - "dWVOb3RJbk9uZW9mEi4KCm51bGxfdmFsdWUYAiABKA4yGi5nb29nbGUucHJv", - "dG9idWYuTnVsbFZhbHVlImAKF01peGVkUmVndWxhckFuZE9wdGlvbmFsEhUK", - "DXJlZ3VsYXJfZmllbGQYASABKAkSGwoOb3B0aW9uYWxfZmllbGQYAiABKAlI", - "AIgBAUIRCg9fb3B0aW9uYWxfZmllbGQiOQoST25lb2ZXaXRoTm9uZUZpZWxk", - "EgsKAXgYASABKAlIABIOCgRub25lGAIgASgJSABCBgoEdGVzdCI1ChFPbmVv", - "ZldpdGhOb25lTmFtZRILCgF4GAEgASgJSAASCwoBeRgCIAEoCUgAQgYKBG5v", - "bmUikwIKGURpc2FtYmlndWF0ZUNvbW1vbk1lbWJlcnMSIwobZGlzYW1iaWd1", - "YXRlX2NvbW1vbl9tZW1iZXJzGAEgASgFEg0KBXR5cGVzGAIgASgFEhIKCmRl", - "c2NyaXB0b3IYAyABKAUSDgoGZXF1YWxzGAQgASgFEhEKCXRvX3N0cmluZxgF", - "IAEoBRIVCg1nZXRfaGFzaF9jb2RlGAYgASgFEhAKCHdyaXRlX3RvGAcgASgF", - "Eg0KBWNsb25lGAggASgFEhYKDmNhbGN1bGF0ZV9zaXplGAkgASgFEhIKCm1l", - "cmdlX2Zyb20YCiABKAUSFwoPb25fY29uc3RydWN0aW9uGAsgASgFEg4KBnBh", - "cnNlchgMIAEoBSpVCgxOZWdhdGl2ZUVudW0SFgoSTkVHQVRJVkVfRU5VTV9a", - "RVJPEAASFgoJRml2ZUJlbG93EPv//////////wESFQoITWludXNPbmUQ////", - "////////ASo2Cg5EZXByZWNhdGVkRW51bRIXCg9ERVBSRUNBVEVEX1pFUk8Q", - "ABoCCAESBwoDb25lEAEaAhgBQh2qAhpVbml0VGVzdC5Jc3N1ZXMuVGVzdFBy", - "b3Rvc2IGcHJvdG8z")); + "dWVzLk5lZ2F0aXZlRW51bUICEAEiEQoPRGVwcmVjYXRlZENoaWxkIrkCChdE", + "ZXByZWNhdGVkRmllbGRzTWVzc2FnZRIaCg5QcmltaXRpdmVWYWx1ZRgBIAEo", + "BUICGAESGgoOUHJpbWl0aXZlQXJyYXkYAiADKAVCAhgBEjoKDE1lc3NhZ2VW", + "YWx1ZRgDIAEoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRC", + "AhgBEjoKDE1lc3NhZ2VBcnJheRgEIAMoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5E", + "ZXByZWNhdGVkQ2hpbGRCAhgBEjYKCUVudW1WYWx1ZRgFIAEoDjIfLnVuaXR0", + "ZXN0X2lzc3Vlcy5EZXByZWNhdGVkRW51bUICGAESNgoJRW51bUFycmF5GAYg", + "AygOMh8udW5pdHRlc3RfaXNzdWVzLkRlcHJlY2F0ZWRFbnVtQgIYASIZCglJ", + "dGVtRmllbGQSDAoEaXRlbRgBIAEoBSJECg1SZXNlcnZlZE5hbWVzEg0KBXR5", + "cGVzGAEgASgFEhIKCmRlc2NyaXB0b3IYAiABKAUaEAoOU29tZU5lc3RlZFR5", + "cGUioAEKFVRlc3RKc29uRmllbGRPcmRlcmluZxITCgtwbGFpbl9pbnQzMhgE", + "IAEoBRITCglvMV9zdHJpbmcYAiABKAlIABISCghvMV9pbnQzMhgFIAEoBUgA", + "EhQKDHBsYWluX3N0cmluZxgBIAEoCRISCghvMl9pbnQzMhgGIAEoBUgBEhMK", + "CW8yX3N0cmluZxgDIAEoCUgBQgQKAm8xQgQKAm8yIksKDFRlc3RKc29uTmFt", + "ZRIMCgRuYW1lGAEgASgJEhkKC2Rlc2NyaXB0aW9uGAIgASgJUgRkZXNjEhIK", + "BGd1aWQYAyABKAlSBGV4aWQifwoMT25lb2ZNZXJnaW5nEg4KBHRleHQYASAB", + "KAlIABI2CgZuZXN0ZWQYAiABKAsyJC51bml0dGVzdF9pc3N1ZXMuT25lb2ZN", + "ZXJnaW5nLk5lc3RlZEgAGh4KBk5lc3RlZBIJCgF4GAEgASgFEgkKAXkYAiAB", + "KAVCBwoFdmFsdWUiawoWTnVsbFZhbHVlT3V0c2lkZVN0cnVjdBIWCgxzdHJp", + "bmdfdmFsdWUYASABKAlIABIwCgpudWxsX3ZhbHVlGAIgASgOMhouZ29vZ2xl", + "LnByb3RvYnVmLk51bGxWYWx1ZUgAQgcKBXZhbHVlIkUKE051bGxWYWx1ZU5v", + "dEluT25lb2YSLgoKbnVsbF92YWx1ZRgCIAEoDjIaLmdvb2dsZS5wcm90b2J1", + "Zi5OdWxsVmFsdWUiYAoXTWl4ZWRSZWd1bGFyQW5kT3B0aW9uYWwSFQoNcmVn", + "dWxhcl9maWVsZBgBIAEoCRIbCg5vcHRpb25hbF9maWVsZBgCIAEoCUgAiAEB", + "QhEKD19vcHRpb25hbF9maWVsZCI5ChJPbmVvZldpdGhOb25lRmllbGQSCwoB", + "eBgBIAEoCUgAEg4KBG5vbmUYAiABKAlIAEIGCgR0ZXN0IjUKEU9uZW9mV2l0", + "aE5vbmVOYW1lEgsKAXgYASABKAlIABILCgF5GAIgASgJSABCBgoEbm9uZSpV", + "CgxOZWdhdGl2ZUVudW0SFgoSTkVHQVRJVkVfRU5VTV9aRVJPEAASFgoJRml2", + "ZUJlbG93EPv//////////wESFQoITWludXNPbmUQ////////////ASouCg5E", + "ZXByZWNhdGVkRW51bRITCg9ERVBSRUNBVEVEX1pFUk8QABIHCgNvbmUQAUId", + "qgIaVW5pdFRlc3QuSXNzdWVzLlRlc3RQcm90b3NiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::UnitTest.Issues.TestProtos.NegativeEnum), typeof(global::UnitTest.Issues.TestProtos.DeprecatedEnum), }, null, new pbr::GeneratedClrTypeInfo[] { @@ -84,8 +77,7 @@ namespace UnitTest.Issues.TestProtos { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NullValueNotInOneof), global::UnitTest.Issues.TestProtos.NullValueNotInOneof.Parser, new[]{ "NullValue" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.MixedRegularAndOptional), global::UnitTest.Issues.TestProtos.MixedRegularAndOptional.Parser, new[]{ "RegularField", "OptionalField" }, new[]{ "OptionalField" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofWithNoneField), global::UnitTest.Issues.TestProtos.OneofWithNoneField.Parser, new[]{ "X", "None" }, new[]{ "Test" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofWithNoneName), global::UnitTest.Issues.TestProtos.OneofWithNoneName.Parser, new[]{ "X", "Y" }, new[]{ "None" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.DisambiguateCommonMembers), global::UnitTest.Issues.TestProtos.DisambiguateCommonMembers.Parser, new[]{ "DisambiguateCommonMembers_", "Types_", "Descriptor_", "Equals_", "ToString_", "GetHashCode_", "WriteTo_", "Clone_", "CalculateSize_", "MergeFrom_", "OnConstruction_", "Parser_" }, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofWithNoneName), global::UnitTest.Issues.TestProtos.OneofWithNoneName.Parser, new[]{ "X", "Y" }, new[]{ "None" }, null, null, null) })); } #endregion @@ -98,9 +90,7 @@ namespace UnitTest.Issues.TestProtos { [pbr::OriginalName("MinusOne")] MinusOne = -1, } - [global::System.ObsoleteAttribute] public enum DeprecatedEnum { - [global::System.ObsoleteAttribute] [pbr::OriginalName("DEPRECATED_ZERO")] DeprecatedZero = 0, [pbr::OriginalName("one")] One = 1, } @@ -829,7 +819,6 @@ namespace UnitTest.Issues.TestProtos { } - [global::System.ObsoleteAttribute] public sealed partial class DeprecatedChild : pb::IMessage #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE , pb::IBufferMessage @@ -4358,605 +4347,6 @@ namespace UnitTest.Issues.TestProtos { } - /// - /// Issue 8810 - /// - public sealed partial class DisambiguateCommonMembers : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DisambiguateCommonMembers()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[14]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public DisambiguateCommonMembers() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public DisambiguateCommonMembers(DisambiguateCommonMembers other) : this() { - disambiguateCommonMembers_ = other.disambiguateCommonMembers_; - types_ = other.types_; - descriptor_ = other.descriptor_; - equals_ = other.equals_; - toString_ = other.toString_; - getHashCode_ = other.getHashCode_; - writeTo_ = other.writeTo_; - clone_ = other.clone_; - calculateSize_ = other.calculateSize_; - mergeFrom_ = other.mergeFrom_; - onConstruction_ = other.onConstruction_; - parser_ = other.parser_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public DisambiguateCommonMembers Clone() { - return new DisambiguateCommonMembers(this); - } - - /// Field number for the "disambiguate_common_members" field. - public const int DisambiguateCommonMembers_FieldNumber = 1; - private int disambiguateCommonMembers_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int DisambiguateCommonMembers_ { - get { return disambiguateCommonMembers_; } - set { - disambiguateCommonMembers_ = value; - } - } - - /// Field number for the "types" field. - public const int Types_FieldNumber = 2; - private int types_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Types_ { - get { return types_; } - set { - types_ = value; - } - } - - /// Field number for the "descriptor" field. - public const int Descriptor_FieldNumber = 3; - private int descriptor_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Descriptor_ { - get { return descriptor_; } - set { - descriptor_ = value; - } - } - - /// Field number for the "equals" field. - public const int Equals_FieldNumber = 4; - private int equals_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Equals_ { - get { return equals_; } - set { - equals_ = value; - } - } - - /// Field number for the "to_string" field. - public const int ToString_FieldNumber = 5; - private int toString_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int ToString_ { - get { return toString_; } - set { - toString_ = value; - } - } - - /// Field number for the "get_hash_code" field. - public const int GetHashCode_FieldNumber = 6; - private int getHashCode_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int GetHashCode_ { - get { return getHashCode_; } - set { - getHashCode_ = value; - } - } - - /// Field number for the "write_to" field. - public const int WriteTo_FieldNumber = 7; - private int writeTo_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int WriteTo_ { - get { return writeTo_; } - set { - writeTo_ = value; - } - } - - /// Field number for the "clone" field. - public const int Clone_FieldNumber = 8; - private int clone_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Clone_ { - get { return clone_; } - set { - clone_ = value; - } - } - - /// Field number for the "calculate_size" field. - public const int CalculateSize_FieldNumber = 9; - private int calculateSize_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize_ { - get { return calculateSize_; } - set { - calculateSize_ = value; - } - } - - /// Field number for the "merge_from" field. - public const int MergeFrom_FieldNumber = 10; - private int mergeFrom_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int MergeFrom_ { - get { return mergeFrom_; } - set { - mergeFrom_ = value; - } - } - - /// Field number for the "on_construction" field. - public const int OnConstruction_FieldNumber = 11; - private int onConstruction_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int OnConstruction_ { - get { return onConstruction_; } - set { - onConstruction_ = value; - } - } - - /// Field number for the "parser" field. - public const int Parser_FieldNumber = 12; - private int parser_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Parser_ { - get { return parser_; } - set { - parser_ = value; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as DisambiguateCommonMembers); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(DisambiguateCommonMembers other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (DisambiguateCommonMembers_ != other.DisambiguateCommonMembers_) return false; - if (Types_ != other.Types_) return false; - if (Descriptor_ != other.Descriptor_) return false; - if (Equals_ != other.Equals_) return false; - if (ToString_ != other.ToString_) return false; - if (GetHashCode_ != other.GetHashCode_) return false; - if (WriteTo_ != other.WriteTo_) return false; - if (Clone_ != other.Clone_) return false; - if (CalculateSize_ != other.CalculateSize_) return false; - if (MergeFrom_ != other.MergeFrom_) return false; - if (OnConstruction_ != other.OnConstruction_) return false; - if (Parser_ != other.Parser_) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (DisambiguateCommonMembers_ != 0) hash ^= DisambiguateCommonMembers_.GetHashCode(); - if (Types_ != 0) hash ^= Types_.GetHashCode(); - if (Descriptor_ != 0) hash ^= Descriptor_.GetHashCode(); - if (Equals_ != 0) hash ^= Equals_.GetHashCode(); - if (ToString_ != 0) hash ^= ToString_.GetHashCode(); - if (GetHashCode_ != 0) hash ^= GetHashCode_.GetHashCode(); - if (WriteTo_ != 0) hash ^= WriteTo_.GetHashCode(); - if (Clone_ != 0) hash ^= Clone_.GetHashCode(); - if (CalculateSize_ != 0) hash ^= CalculateSize_.GetHashCode(); - if (MergeFrom_ != 0) hash ^= MergeFrom_.GetHashCode(); - if (OnConstruction_ != 0) hash ^= OnConstruction_.GetHashCode(); - if (Parser_ != 0) hash ^= Parser_.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (DisambiguateCommonMembers_ != 0) { - output.WriteRawTag(8); - output.WriteInt32(DisambiguateCommonMembers_); - } - if (Types_ != 0) { - output.WriteRawTag(16); - output.WriteInt32(Types_); - } - if (Descriptor_ != 0) { - output.WriteRawTag(24); - output.WriteInt32(Descriptor_); - } - if (Equals_ != 0) { - output.WriteRawTag(32); - output.WriteInt32(Equals_); - } - if (ToString_ != 0) { - output.WriteRawTag(40); - output.WriteInt32(ToString_); - } - if (GetHashCode_ != 0) { - output.WriteRawTag(48); - output.WriteInt32(GetHashCode_); - } - if (WriteTo_ != 0) { - output.WriteRawTag(56); - output.WriteInt32(WriteTo_); - } - if (Clone_ != 0) { - output.WriteRawTag(64); - output.WriteInt32(Clone_); - } - if (CalculateSize_ != 0) { - output.WriteRawTag(72); - output.WriteInt32(CalculateSize_); - } - if (MergeFrom_ != 0) { - output.WriteRawTag(80); - output.WriteInt32(MergeFrom_); - } - if (OnConstruction_ != 0) { - output.WriteRawTag(88); - output.WriteInt32(OnConstruction_); - } - if (Parser_ != 0) { - output.WriteRawTag(96); - output.WriteInt32(Parser_); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (DisambiguateCommonMembers_ != 0) { - output.WriteRawTag(8); - output.WriteInt32(DisambiguateCommonMembers_); - } - if (Types_ != 0) { - output.WriteRawTag(16); - output.WriteInt32(Types_); - } - if (Descriptor_ != 0) { - output.WriteRawTag(24); - output.WriteInt32(Descriptor_); - } - if (Equals_ != 0) { - output.WriteRawTag(32); - output.WriteInt32(Equals_); - } - if (ToString_ != 0) { - output.WriteRawTag(40); - output.WriteInt32(ToString_); - } - if (GetHashCode_ != 0) { - output.WriteRawTag(48); - output.WriteInt32(GetHashCode_); - } - if (WriteTo_ != 0) { - output.WriteRawTag(56); - output.WriteInt32(WriteTo_); - } - if (Clone_ != 0) { - output.WriteRawTag(64); - output.WriteInt32(Clone_); - } - if (CalculateSize_ != 0) { - output.WriteRawTag(72); - output.WriteInt32(CalculateSize_); - } - if (MergeFrom_ != 0) { - output.WriteRawTag(80); - output.WriteInt32(MergeFrom_); - } - if (OnConstruction_ != 0) { - output.WriteRawTag(88); - output.WriteInt32(OnConstruction_); - } - if (Parser_ != 0) { - output.WriteRawTag(96); - output.WriteInt32(Parser_); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (DisambiguateCommonMembers_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(DisambiguateCommonMembers_); - } - if (Types_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Types_); - } - if (Descriptor_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Descriptor_); - } - if (Equals_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Equals_); - } - if (ToString_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(ToString_); - } - if (GetHashCode_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(GetHashCode_); - } - if (WriteTo_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(WriteTo_); - } - if (Clone_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Clone_); - } - if (CalculateSize_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(CalculateSize_); - } - if (MergeFrom_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(MergeFrom_); - } - if (OnConstruction_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(OnConstruction_); - } - if (Parser_ != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Parser_); - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(DisambiguateCommonMembers other) { - if (other == null) { - return; - } - if (other.DisambiguateCommonMembers_ != 0) { - DisambiguateCommonMembers_ = other.DisambiguateCommonMembers_; - } - if (other.Types_ != 0) { - Types_ = other.Types_; - } - if (other.Descriptor_ != 0) { - Descriptor_ = other.Descriptor_; - } - if (other.Equals_ != 0) { - Equals_ = other.Equals_; - } - if (other.ToString_ != 0) { - ToString_ = other.ToString_; - } - if (other.GetHashCode_ != 0) { - GetHashCode_ = other.GetHashCode_; - } - if (other.WriteTo_ != 0) { - WriteTo_ = other.WriteTo_; - } - if (other.Clone_ != 0) { - Clone_ = other.Clone_; - } - if (other.CalculateSize_ != 0) { - CalculateSize_ = other.CalculateSize_; - } - if (other.MergeFrom_ != 0) { - MergeFrom_ = other.MergeFrom_; - } - if (other.OnConstruction_ != 0) { - OnConstruction_ = other.OnConstruction_; - } - if (other.Parser_ != 0) { - Parser_ = other.Parser_; - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 8: { - DisambiguateCommonMembers_ = input.ReadInt32(); - break; - } - case 16: { - Types_ = input.ReadInt32(); - break; - } - case 24: { - Descriptor_ = input.ReadInt32(); - break; - } - case 32: { - Equals_ = input.ReadInt32(); - break; - } - case 40: { - ToString_ = input.ReadInt32(); - break; - } - case 48: { - GetHashCode_ = input.ReadInt32(); - break; - } - case 56: { - WriteTo_ = input.ReadInt32(); - break; - } - case 64: { - Clone_ = input.ReadInt32(); - break; - } - case 72: { - CalculateSize_ = input.ReadInt32(); - break; - } - case 80: { - MergeFrom_ = input.ReadInt32(); - break; - } - case 88: { - OnConstruction_ = input.ReadInt32(); - break; - } - case 96: { - Parser_ = input.ReadInt32(); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 8: { - DisambiguateCommonMembers_ = input.ReadInt32(); - break; - } - case 16: { - Types_ = input.ReadInt32(); - break; - } - case 24: { - Descriptor_ = input.ReadInt32(); - break; - } - case 32: { - Equals_ = input.ReadInt32(); - break; - } - case 40: { - ToString_ = input.ReadInt32(); - break; - } - case 48: { - GetHashCode_ = input.ReadInt32(); - break; - } - case 56: { - WriteTo_ = input.ReadInt32(); - break; - } - case 64: { - Clone_ = input.ReadInt32(); - break; - } - case 72: { - CalculateSize_ = input.ReadInt32(); - break; - } - case 80: { - MergeFrom_ = input.ReadInt32(); - break; - } - case 88: { - OnConstruction_ = input.ReadInt32(); - break; - } - case 96: { - Parser_ = input.ReadInt32(); - break; - } - } - } - } - #endif - - } - #endregion } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs index 50b9046..3ec8d35 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs @@ -3258,24 +3258,24 @@ namespace Google.Protobuf.TestProtos { if (other == null) { return; } - anyField_.MergeFrom(other.anyField_); - apiField_.MergeFrom(other.apiField_); - durationField_.MergeFrom(other.durationField_); - emptyField_.MergeFrom(other.emptyField_); - fieldMaskField_.MergeFrom(other.fieldMaskField_); - sourceContextField_.MergeFrom(other.sourceContextField_); - structField_.MergeFrom(other.structField_); - timestampField_.MergeFrom(other.timestampField_); - typeField_.MergeFrom(other.typeField_); - doubleField_.MergeFrom(other.doubleField_); - floatField_.MergeFrom(other.floatField_); - int64Field_.MergeFrom(other.int64Field_); - uint64Field_.MergeFrom(other.uint64Field_); - int32Field_.MergeFrom(other.int32Field_); - uint32Field_.MergeFrom(other.uint32Field_); - boolField_.MergeFrom(other.boolField_); - stringField_.MergeFrom(other.stringField_); - bytesField_.MergeFrom(other.bytesField_); + anyField_.Add(other.anyField_); + apiField_.Add(other.apiField_); + durationField_.Add(other.durationField_); + emptyField_.Add(other.emptyField_); + fieldMaskField_.Add(other.fieldMaskField_); + sourceContextField_.Add(other.sourceContextField_); + structField_.Add(other.structField_); + timestampField_.Add(other.timestampField_); + typeField_.Add(other.typeField_); + doubleField_.Add(other.doubleField_); + floatField_.Add(other.floatField_); + int64Field_.Add(other.int64Field_); + uint64Field_.Add(other.uint64Field_); + int32Field_.Add(other.int32Field_); + uint32Field_.Add(other.uint32Field_); + boolField_.Add(other.boolField_); + stringField_.Add(other.stringField_); + bytesField_.Add(other.bytesField_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs index b757287..4876e09 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs @@ -41,7 +41,9 @@ using System.Buffers; using System.Runtime.InteropServices; using System.Threading; using System.Runtime.CompilerServices; +#if !NET35 using System.Threading.Tasks; +#endif namespace Google.Protobuf { @@ -70,7 +72,7 @@ namespace Google.Protobuf Assert.IsFalse(b1 != b1); Assert.IsFalse(b1 != b2); Assert.IsTrue(ByteString.Empty == ByteString.Empty); -#pragma warning restore 1718 +#pragma warning disable 1718 Assert.IsTrue(b1 != b3); Assert.IsTrue(b1 != b4); Assert.IsTrue(b1 != null); @@ -276,9 +278,12 @@ namespace Google.Protobuf Span s = stackalloc byte[data.Length]; data.CopyTo(s); - using var manager = new UnmanagedMemoryManager(s); - ByteString bs = ByteString.AttachBytes(manager.Memory); - Assert.AreEqual("Hello world", bs.ToString(Encoding.UTF8)); + using (UnmanagedMemoryManager manager = new UnmanagedMemoryManager(s)) + { + ByteString bs = ByteString.AttachBytes(manager.Memory); + + Assert.AreEqual("Hello world", bs.ToString(Encoding.UTF8)); + } } [Test] @@ -312,9 +317,12 @@ namespace Google.Protobuf Span s = stackalloc byte[data.Length]; data.CopyTo(s); - using var manager = new UnmanagedMemoryManager(s); - ByteString bs = ByteString.AttachBytes(manager.Memory); - Assert.AreEqual("SGVsbG8gd29ybGQ=", bs.ToBase64()); + using (UnmanagedMemoryManager manager = new UnmanagedMemoryManager(s)) + { + ByteString bs = ByteString.AttachBytes(manager.Memory); + + Assert.AreEqual("SGVsbG8gd29ybGQ=", bs.ToBase64()); + } } [Test] @@ -341,6 +349,7 @@ namespace Google.Protobuf Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}"); } +#if !NET35 [Test] public async Task FromStreamAsync_Seekable() { @@ -364,6 +373,7 @@ namespace Google.Protobuf ByteString expected = ByteString.CopyFrom(2, 3, 4); Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}"); } +#endif [Test] public void GetHashCode_Regression() diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index a48f3b1..b84a1b7 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -563,8 +563,8 @@ namespace Google.Protobuf int groupFieldNumber = Proto2.TestAllTypes.OptionalGroupFieldNumber; // write Proto2.TestAllTypes with "optional_group" set, but use wrong EndGroup closing tag - var ms = new MemoryStream(); - var output = new CodedOutputStream(ms); + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); output.WriteTag(WireFormat.MakeTag(groupFieldNumber, WireFormat.WireType.StartGroup)); output.WriteGroup(new Proto2.TestAllTypes.Types.OptionalGroup { A = 12345 }); // end group with different field number @@ -578,8 +578,8 @@ namespace Google.Protobuf [Test] public void ReadGroup_UnknownFields_WrongEndGroupTag() { - var ms = new MemoryStream(); - var output = new CodedOutputStream(ms); + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); output.WriteTag(WireFormat.MakeTag(14, WireFormat.WireType.StartGroup)); // end group with different field number output.WriteTag(WireFormat.MakeTag(15, WireFormat.WireType.EndGroup)); @@ -654,7 +654,7 @@ namespace Google.Protobuf output.Flush(); ms.Position = 0; - var input = new CodedInputStream(ms); + CodedInputStream input = new CodedInputStream(ms); Assert.AreEqual(tag, input.ReadTag()); Assert.Throws(() => input.ReadBytes()); @@ -694,24 +694,26 @@ namespace Google.Protobuf [Test] public void TestSlowPathAvoidance() { - using var ms = new MemoryStream(); - var output = new CodedOutputStream(ms); - output.WriteTag(1, WireFormat.WireType.LengthDelimited); - output.WriteBytes(ByteString.CopyFrom(new byte[100])); - output.WriteTag(2, WireFormat.WireType.LengthDelimited); - output.WriteBytes(ByteString.CopyFrom(new byte[100])); - output.Flush(); + using (var ms = new MemoryStream()) + { + CodedOutputStream output = new CodedOutputStream(ms); + output.WriteTag(1, WireFormat.WireType.LengthDelimited); + output.WriteBytes(ByteString.CopyFrom(new byte[100])); + output.WriteTag(2, WireFormat.WireType.LengthDelimited); + output.WriteBytes(ByteString.CopyFrom(new byte[100])); + output.Flush(); - ms.Position = 0; - CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0, false); + ms.Position = 0; + CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0, false); - uint tag = input.ReadTag(); - Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag)); - Assert.AreEqual(100, input.ReadBytes().Length); + uint tag = input.ReadTag(); + Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag)); + Assert.AreEqual(100, input.ReadBytes().Length); - tag = input.ReadTag(); - Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag)); - Assert.AreEqual(100, input.ReadBytes().Length); + tag = input.ReadTag(); + Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag)); + Assert.AreEqual(100, input.ReadBytes().Length); + } } [Test] @@ -925,11 +927,13 @@ namespace Google.Protobuf { byte[] serializedMessage = GenerateBigSerializedMessage(); // How many of these big messages do we need to take us near our 2GB limit? - int count = int.MaxValue / serializedMessage.Length; + int count = Int32.MaxValue / serializedMessage.Length; // Now make a MemoryStream that will fake a near-2GB stream of messages by returning // our big serialized message 'count' times. - using var stream = new RepeatingMemoryStream(serializedMessage, count); - Assert.DoesNotThrow(() => TestAllTypes.Parser.ParseFrom(stream)); + using (RepeatingMemoryStream stream = new RepeatingMemoryStream(serializedMessage, count)) + { + Assert.DoesNotThrow(()=>TestAllTypes.Parser.ParseFrom(stream)); + } } [Test] @@ -937,15 +941,17 @@ namespace Google.Protobuf { byte[] serializedMessage = GenerateBigSerializedMessage(); // How many of these big messages do we need to take us near our 2GB limit? - int count = int.MaxValue / serializedMessage.Length; + int count = Int32.MaxValue / serializedMessage.Length; // Now add one to take us over the 2GB limit count++; // Now make a MemoryStream that will fake a near-2GB stream of messages by returning // our big serialized message 'count' times. - using var stream = new RepeatingMemoryStream(serializedMessage, count); - Assert.Throws(() => TestAllTypes.Parser.ParseFrom(stream), - "Protocol message was too large. May be malicious. " + - "Use CodedInputStream.SetSizeLimit() to increase the size limit."); + using (RepeatingMemoryStream stream = new RepeatingMemoryStream(serializedMessage, count)) + { + Assert.Throws(() => TestAllTypes.Parser.ParseFrom(stream), + "Protocol message was too large. May be malicious. " + + "Use CodedInputStream.SetSizeLimit() to increase the size limit."); + } } /// A serialized big message diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 31090c4..13f83a2 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -94,12 +94,14 @@ namespace Google.Protobuf if ((value >> 32) == 0) { MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize); + CodedOutputStream output = + new CodedOutputStream(rawOutput, bufferSize); output.WriteRawVarint32((uint) value); output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new TestArrayBufferWriter { MaxGrowBy = bufferSize }; + var bufferWriter = new TestArrayBufferWriter(); + bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt32((uint) value); ctx.Flush(); @@ -113,7 +115,8 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new TestArrayBufferWriter { MaxGrowBy = bufferSize }; + var bufferWriter = new TestArrayBufferWriter(); + bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteUInt64(value); ctx.Flush(); @@ -187,7 +190,8 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new TestArrayBufferWriter { MaxGrowBy = bufferSize }; + var bufferWriter = new TestArrayBufferWriter(); + bufferWriter.MaxGrowBy = bufferSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed32(value); ctx.Flush(); @@ -224,7 +228,8 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(data, rawOutput.ToArray()); - var bufferWriter = new TestArrayBufferWriter { MaxGrowBy = blockSize }; + var bufferWriter = new TestArrayBufferWriter(); + bufferWriter.MaxGrowBy = blockSize; WriteContext.Initialize(bufferWriter, out WriteContext ctx); ctx.WriteFixed64(value); ctx.Flush(); @@ -265,7 +270,8 @@ namespace Google.Protobuf output.Flush(); Assert.AreEqual(rawBytes, rawOutput.ToArray()); - var bufferWriter = new TestArrayBufferWriter { MaxGrowBy = blockSize }; + var bufferWriter = new TestArrayBufferWriter(); + bufferWriter.MaxGrowBy = blockSize; message.WriteTo(bufferWriter); Assert.AreEqual(rawBytes, bufferWriter.WrittenSpan.ToArray()); } @@ -377,9 +383,7 @@ namespace Google.Protobuf { byte[] content = new byte[110]; for (int i = 0; i < content.Length; i++) - { content[i] = (byte)i; - } byte[] child = new byte[120]; { diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs index 401b70a..1f7b8a3 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs @@ -91,12 +91,10 @@ namespace Google.Protobuf.Collections [Test] public void AddPreservesInsertionOrder() { - var map = new MapField - { - { "a", "v1" }, - { "b", "v2" }, - { "c", "v3" } - }; + var map = new MapField(); + map.Add("a", "v1"); + map.Add("b", "v2"); + map.Add("c", "v3"); map.Remove("b"); map.Add("d", "v4"); CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys); @@ -106,17 +104,13 @@ namespace Google.Protobuf.Collections [Test] public void EqualityIsOrderInsensitive() { - var map1 = new MapField - { - { "a", "v1" }, - { "b", "v2" } - }; + var map1 = new MapField(); + map1.Add("a", "v1"); + map1.Add("b", "v2"); - var map2 = new MapField - { - { "b", "v2" }, - { "a", "v1" } - }; + var map2 = new MapField(); + map2.Add("b", "v2"); + map2.Add("a", "v1"); EqualityTester.AssertEquality(map1, map2); } @@ -124,17 +118,13 @@ namespace Google.Protobuf.Collections [Test] public void EqualityIsKeySensitive() { - var map1 = new MapField - { - { "first key", "v1" }, - { "second key", "v2" } - }; + var map1 = new MapField(); + map1.Add("first key", "v1"); + map1.Add("second key", "v2"); - var map2 = new MapField - { - { "third key", "v1" }, - { "fourth key", "v2" } - }; + var map2 = new MapField(); + map2.Add("third key", "v1"); + map2.Add("fourth key", "v2"); EqualityTester.AssertInequality(map1, map2); } @@ -153,17 +143,13 @@ namespace Google.Protobuf.Collections { // Note: Without some care, it's a little easier than one might // hope to see hash collisions, but only in some environments... - var map1 = new MapField - { - { "a", "first value" }, - { "b", "second value" } - }; + var map1 = new MapField(); + map1.Add("a", "first value"); + map1.Add("b", "second value"); - var map2 = new MapField - { - { "a", "third value" }, - { "b", "fourth value" } - }; + var map2 = new MapField(); + map2.Add("a", "third value"); + map2.Add("b", "fourth value"); EqualityTester.AssertInequality(map1, map2); } @@ -197,7 +183,8 @@ namespace Google.Protobuf.Collections [Test] public void Add_KeyAlreadyExists() { - var map = new MapField { { "foo", "bar" } }; + var map = new MapField(); + map.Add("foo", "bar"); Assert.Throws(() => map.Add("foo", "baz")); } @@ -224,7 +211,8 @@ namespace Google.Protobuf.Collections [Test] public void Remove_Key() { - var map = new MapField { { "foo", "bar" } }; + var map = new MapField(); + map.Add("foo", "bar"); Assert.AreEqual(1, map.Count); Assert.IsFalse(map.Remove("missing")); Assert.AreEqual(1, map.Count); @@ -236,7 +224,8 @@ namespace Google.Protobuf.Collections [Test] public void Remove_Pair() { - var map = new MapField { { "foo", "bar" } }; + var map = new MapField(); + map.Add("foo", "bar"); ICollection> collection = map; Assert.AreEqual(1, map.Count); Assert.IsFalse(collection.Remove(NewKeyValuePair("wrong key", "bar"))); @@ -251,7 +240,8 @@ namespace Google.Protobuf.Collections [Test] public void CopyTo_Pair() { - var map = new MapField { { "foo", "bar" } }; + var map = new MapField(); + map.Add("foo", "bar"); ICollection> collection = map; KeyValuePair[] array = new KeyValuePair[3]; collection.CopyTo(array, 1); @@ -280,7 +270,8 @@ namespace Google.Protobuf.Collections [Test] public void Indexer_Set() { - var map = new MapField { ["x"] = "y" }; + var map = new MapField(); + map["x"] = "y"; Assert.AreEqual("y", map["x"]); map["x"] = "z"; // This won't throw, unlike Add. Assert.AreEqual("z", map["x"]); @@ -366,10 +357,12 @@ namespace Google.Protobuf.Collections IDictionary dictionary = map; var array = new DictionaryEntry[3]; dictionary.CopyTo(array, 1); - CollectionAssert.AreEqual(new[] { default, new DictionaryEntry("x", "y"), default }, array); + CollectionAssert.AreEqual(new[] { default(DictionaryEntry), new DictionaryEntry("x", "y"), default(DictionaryEntry) }, + array); var objectArray = new object[3]; dictionary.CopyTo(objectArray, 1); - CollectionAssert.AreEqual(new object[] { null, new DictionaryEntry("x", "y"), null }, objectArray); + CollectionAssert.AreEqual(new object[] { null, new DictionaryEntry("x", "y"), null }, + objectArray); } [Test] @@ -587,7 +580,8 @@ namespace Google.Protobuf.Collections }; Assert.AreEqual("x", map[SampleNaNs.Regular]); Assert.AreEqual("y", map[SampleNaNs.SignallingFlipped]); - Assert.False(map.TryGetValue(SampleNaNs.PayloadFlipped, out _)); + string ignored; + Assert.False(map.TryGetValue(SampleNaNs.PayloadFlipped, out ignored)); } [Test] @@ -641,6 +635,7 @@ namespace Google.Protobuf.Collections Assert.IsTrue(input.IsAtEnd); } +#if !NET35 [Test] public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys() { @@ -654,6 +649,7 @@ namespace Google.Protobuf.Collections var map = new MapField { { "foo", "bar" }, { "x", "y" } }; CollectionAssert.AreEquivalent(((IDictionary)map).Values, ((IReadOnlyDictionary)map).Values); } +#endif private static KeyValuePair NewKeyValuePair(TKey key, TValue value) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 5a8977d..ff8f5cc 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -33,6 +33,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; @@ -58,7 +59,8 @@ namespace Google.Protobuf.Collections [Test] public void Add_SingleItem() { - var list = new RepeatedField { "foo" }; + var list = new RepeatedField(); + list.Add("foo"); Assert.AreEqual(1, list.Count); Assert.AreEqual("foo", list[0]); } @@ -66,7 +68,8 @@ namespace Google.Protobuf.Collections [Test] public void Add_Sequence() { - var list = new RepeatedField { new[] { "foo", "bar" } }; + var list = new RepeatedField(); + list.Add(new[] { "foo", "bar" }); Assert.AreEqual(2, list.Count); Assert.AreEqual("foo", list[0]); Assert.AreEqual("bar", list[1]); @@ -290,13 +293,15 @@ namespace Google.Protobuf.Collections public void Enumerator() { var list = new RepeatedField { "first", "second" }; - using var enumerator = list.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext()); - Assert.AreEqual("first", enumerator.Current); - Assert.IsTrue(enumerator.MoveNext()); - Assert.AreEqual("second", enumerator.Current); - Assert.IsFalse(enumerator.MoveNext()); - Assert.IsFalse(enumerator.MoveNext()); + using (var enumerator = list.GetEnumerator()) + { + Assert.IsTrue(enumerator.MoveNext()); + Assert.AreEqual("first", enumerator.Current); + Assert.IsTrue(enumerator.MoveNext()); + Assert.AreEqual("second", enumerator.Current); + Assert.IsFalse(enumerator.MoveNext()); + Assert.IsFalse(enumerator.MoveNext()); + } } [Test] @@ -888,17 +893,5 @@ namespace Google.Protobuf.Collections Assert.DoesNotThrow(() => list.Capacity = 0, "Can set Capacity to 0"); Assert.AreEqual(0, list.Capacity); } - - [Test] - public void Clear_CapacityUnaffected() - { - var list = new RepeatedField { 1 }; - Assert.AreEqual(1, list.Count); - Assert.AreEqual(8, list.Capacity); - - list.Clear(); - Assert.AreEqual(0, list.Count); - Assert.AreEqual(8, list.Capacity); - } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/WritingPrimitivesTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs similarity index 61% rename from libs/protobuf/csharp/src/Google.Protobuf.Test/WritingPrimitivesTest.cs rename to libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs index 069df34..48c0725 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/WritingPrimitivesTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs @@ -1,6 +1,6 @@ #region Copyright notice and license // Protocol Buffers - Google's data interchange format -// Copyright 2022 Google Inc. All rights reserved. +// Copyright 2015 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -30,32 +30,38 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using NUnit.Framework; +#if NET35 using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; +using NUnit.Framework; +using Google.Protobuf.Compatibility; -namespace Google.Protobuf.Test; - -internal class WritingPrimitivesTest +namespace Google.Protobuf.Test.Compatibility { - [Test] - public void WriteRawString_IllFormedUnicodeString() + public class StreamExtensionsTest { - // See https://codeblog.jonskeet.uk/2014/11/07/when-is-a-string-not-a-string/ - char c1 = '\u0058'; - char c2 = '\ud800'; - char c3 = '\u0059'; - string text = new string(new[] { c1, c2, c3 }); - Span buffer = new byte[10]; - WriteContext.Initialize(ref buffer, out var context); - WritingPrimitives.WriteString(ref context.buffer, ref context.state, text); + [Test] + public void CopyToNullArgument() + { + var memoryStream = new MemoryStream(); + Assert.Throws(() => memoryStream.CopyTo(null)); + } - // The high surrogate is written out in a "raw" form, surrounded by the ASCII - // characters. - byte[] expectedBytes = { 0x5, 0x58, 0xef, 0xbf, 0xbd, 0x59 }; - Assert.AreEqual(expectedBytes, buffer.Slice(0, context.state.position).ToArray()); + [Test] + public void CopyToTest() + { + byte[] bytesToStream = new byte[] { 0x31, 0x08, 0xFF, 0x00 }; + Stream source = new MemoryStream(bytesToStream); + Stream destination = new MemoryStream((int)source.Length); + source.CopyTo(destination); + destination.Seek(0, SeekOrigin.Begin); + + Assert.AreEqual(0x31, destination.ReadByte()); + Assert.AreEqual(0x08, destination.ReadByte()); + Assert.AreEqual(0xFF, destination.ReadByte()); + Assert.AreEqual(0x00, destination.ReadByte()); + Assert.AreEqual(-1, destination.ReadByte()); + } } } +#endif diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs index 040a2f1..5d86c20 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs @@ -29,12 +29,12 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - using NUnit.Framework; using System; using System.Collections.Generic; using System.Reflection; +#if !NET35 namespace Google.Protobuf.Compatibility { public class TypeExtensionsTest @@ -114,3 +114,4 @@ namespace Google.Protobuf.Compatibility } } } +#endif diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs index 6d31441..fd041e0 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs @@ -34,9 +34,7 @@ using System; using System.Reflection; using Google.Protobuf.TestProtos; using NUnit.Framework; -using UnitTest.Issues.TestProtos; -#pragma warning disable CS0612 // Type or member is obsolete namespace Google.Protobuf { public class DeprecatedMemberTest @@ -48,20 +46,10 @@ namespace Google.Protobuf } [Test] - public void TestDepreatedPrimitiveValue() => - AssertIsDeprecated(typeof(TestDeprecatedFields).GetProperty(nameof(TestDeprecatedFields.DeprecatedInt32))); + public void TestDepreatedPrimitiveValue() + { + AssertIsDeprecated(typeof(TestDeprecatedFields).GetProperty("DeprecatedInt32")); + } - [Test] - public void TestDeprecatedMessage() => - AssertIsDeprecated(typeof(DeprecatedChild)); - - [Test] - public void TestDeprecatedEnum() => - AssertIsDeprecated(typeof(DeprecatedEnum)); - - [Test] - public void TestDeprecatedEnumValue() => - AssertIsDeprecated(typeof(DeprecatedEnum).GetField(nameof(DeprecatedEnum.DeprecatedZero))); } } -#pragma warning restore CS0612 // Type or member is obsolete diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs index 23237d4..b2c24dd 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs @@ -1,35 +1,3 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2015 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. -#endregion - using System; using System.Collections; using Google.Protobuf.TestProtos.Proto2; @@ -104,7 +72,7 @@ namespace Google.Protobuf message.SetExtension(OptionalStringExtension, "abcd"); var input = new CodedInputStream(message.ToByteArray()); - input.ExtensionRegistry = new ExtensionRegistry { OptionalStringExtension }; + input.ExtensionRegistry = new ExtensionRegistry() { OptionalStringExtension }; input.ReadTag(); // TryMergeFieldFrom expects that a tag was just read and will inspect the LastTag value ExtensionSet extensionSet = null; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs index 4f2a562..7f36692 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs @@ -169,6 +169,7 @@ namespace Google.Protobuf // WriteTagAndValue ignores default values var stream = new MemoryStream(); CodedOutputStream codedOutput; +#if !NET35 codedOutput = new CodedOutputStream(stream); codec.WriteTagAndValue(codedOutput, codec.DefaultValue); codedOutput.Flush(); @@ -178,6 +179,7 @@ namespace Google.Protobuf { Assert.AreEqual(default(T), codec.DefaultValue); } +#endif // The plain ValueWriter/ValueReader delegates don't. if (codec.DefaultValue != null) // This part isn't appropriate for message types. diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs index 4c206e6..f71744a 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/FieldMaskTreeTest.cs @@ -30,6 +30,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System.Collections.Generic; using Google.Protobuf.Collections; using Google.Protobuf.TestProtos; using NUnit.Framework; @@ -431,89 +432,5 @@ namespace Google.Protobuf Assert.IsNotNull(destination.Payload); } - [Test] - public void MergeWrapperFieldsWithNonNullFieldsInSource() - { - // Instantiate a destination with wrapper-based field types. - var destination = new TestWellKnownTypes() - { - StringField = "Hello", - Int32Field = 12, - Int64Field = 24, - BoolField = true, - }; - - // Set up a targeted update. - var source = new TestWellKnownTypes() - { - StringField = "Hi", - Int64Field = 240 - }; - - Merge(new FieldMaskTree().AddFieldPath("string_field").AddFieldPath("int64_field"), - source, - destination, - new FieldMask.MergeOptions(), - false); - - // Make sure the targeted fields changed. - Assert.AreEqual("Hi", destination.StringField); - Assert.AreEqual(240, destination.Int64Field); - - // Prove that non-targeted fields stay intact... - Assert.AreEqual(12, destination.Int32Field); - Assert.IsTrue(destination.BoolField); - - // ...including default values which were not explicitly set in the destination object. - Assert.IsNull(destination.FloatField); - } - - [Test] - [TestCase(false, "Hello", 24)] - [TestCase(true, null, null)] - public void MergeWrapperFieldsWithNullFieldsInSource( - bool replaceMessageFields, - string expectedStringValue, - long? expectedInt64Value) - { - // Instantiate a destination with wrapper-based field types. - var destination = new TestWellKnownTypes() - { - StringField = "Hello", - Int32Field = 12, - Int64Field = 24, - BoolField = true, - }; - - // Set up a targeted update with null valued fields. - var source = new TestWellKnownTypes() - { - StringField = null, - Int64Field = null - }; - - Merge(new FieldMaskTree().AddFieldPath("string_field").AddFieldPath("int64_field"), - source, - destination, - new FieldMask.MergeOptions() - { - ReplaceMessageFields = replaceMessageFields - }, - false); - - // Make sure the targeted fields changed according to our expectations, depending on the value of ReplaceMessageFields. - // When ReplaceMessageFields is false, the null values are not applied to the destination, because, although wrapped types - // are semantically primitives, FieldMaskTree.Merge still treats them as message types in order to maintain consistency with other Protobuf - // libraries such as Java and C++. - Assert.AreEqual(expectedStringValue, destination.StringField); - Assert.AreEqual(expectedInt64Value, destination.Int64Field); - - // Prove that non-targeted fields stay intact... - Assert.AreEqual(12, destination.Int32Field); - Assert.IsTrue(destination.BoolField); - - // ...including default values which were not explicitly set in the destination object. - Assert.IsNull(destination.FloatField); - } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs index 9d03656..fa5f927 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs @@ -1,35 +1,3 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2015 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. -#endregion - using Google.Protobuf.TestProtos.Proto2; using Proto2 = Google.Protobuf.TestProtos.Proto2; using NUnit.Framework; @@ -419,9 +387,11 @@ namespace Google.Protobuf var message = new TestAllExtensions(); message.SetExtension(UnittestExtensions.OptionalBoolExtension, true); byte[] bytes = message.ToByteArray(); - using CodedInputStream input = new CodedInputStream(bytes); - var parsed = TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalBoolExtension }).ParseFrom(input); - Assert.AreEqual(message, parsed); + using (CodedInputStream input = new CodedInputStream(bytes)) + { + var parsed = TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalBoolExtension }).ParseFrom(input); + Assert.AreEqual(message, parsed); + } } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 17c5249..41a0b91 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -33,10 +33,12 @@ using System; using System.IO; using Google.Protobuf.TestProtos; +using Proto2 = Google.Protobuf.TestProtos.Proto2; using NUnit.Framework; +using System.Collections; +using System.Collections.Generic; using System.Linq; using Google.Protobuf.WellKnownTypes; -using Google.Protobuf.Collections; namespace Google.Protobuf { @@ -656,11 +658,9 @@ namespace Google.Protobuf [Test] public void OneofSerialization_NonDefaultValue() { - var message = new TestAllTypes - { - OneofString = "this would take a bit of space", - OneofUint32 = 10 - }; + var message = new TestAllTypes(); + message.OneofString = "this would take a bit of space"; + message.OneofUint32 = 10; var bytes = message.ToByteArray(); Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - no string! @@ -675,11 +675,9 @@ namespace Google.Protobuf [Test] public void OneofSerialization_DefaultValue() { - var message = new TestAllTypes - { - OneofString = "this would take a bit of space", - OneofUint32 = 0 // This is the default value for UInt32; normally wouldn't be serialized - }; + var message = new TestAllTypes(); + message.OneofString = "this would take a bit of space"; + message.OneofUint32 = 0; // This is the default value for UInt32; normally wouldn't be serialized var bytes = message.ToByteArray(); Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - it's still serialized @@ -748,6 +746,7 @@ namespace Google.Protobuf [Test] public void ExtraEndGroupThrows() { + var message = SampleMessages.CreateFullTestAllTypes(); var stream = new MemoryStream(); var output = new CodedOutputStream(stream); @@ -796,44 +795,5 @@ namespace Google.Protobuf EqualityTester.AssertInequality(message1, message2); EqualityTester.AssertEquality(message1, message3); } - - [Test] - [TestCase(false)] - [TestCase(true)] - public void MapFieldMerging(bool direct) - { - var message1 = new TestMap - { - MapStringString = - { - { "x1", "y1" }, - { "common", "message1" } - } - }; - var message2 = new TestMap - { - MapStringString = - { - { "x2", "y2" }, - { "common", "message2" } - } - }; - if (direct) - { - message1.MergeFrom(message2); - } - else - { - message1.MergeFrom(message2.ToByteArray()); - } - - var expected = new MapField - { - { "x1", "y1" }, - { "x2", "y2" }, - { "common", "message2" } - }; - Assert.AreEqual(expected, message1.MapStringString); - } } } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterSettingsTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterSettingsTest.cs deleted file mode 100644 index f7ea97c..0000000 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterSettingsTest.cs +++ /dev/null @@ -1,111 +0,0 @@ -#region Copyright notice and license - -// 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. - -#endregion - -using Google.Protobuf.Reflection; -using NUnit.Framework; - -// For WrapInQuotes - -namespace Google.Protobuf -{ - public class JsonFormatterSettingsTest - { - [Test] - public void WithIndentation() - { - var settings = JsonFormatter.Settings.Default.WithIndentation("\t"); - Assert.AreEqual("\t", settings.Indentation); - } - - [Test] - public void WithTypeRegistry() - { - var typeRegistry = TypeRegistry.Empty; - var settings = JsonFormatter.Settings.Default.WithTypeRegistry(typeRegistry); - Assert.AreEqual(typeRegistry, settings.TypeRegistry); - } - - [Test] - public void WithFormatDefaultValues() - { - var settingsWith = JsonFormatter.Settings.Default.WithFormatDefaultValues(true); - Assert.AreEqual(true, settingsWith.FormatDefaultValues); - - var settingsWithout = JsonFormatter.Settings.Default.WithFormatDefaultValues(false); - Assert.AreEqual(false, settingsWithout.FormatDefaultValues); - } - - [Test] - public void WithFormatEnumsAsIntegers() - { - var settingsWith = JsonFormatter.Settings.Default.WithFormatEnumsAsIntegers(true); - Assert.AreEqual(true, settingsWith.FormatEnumsAsIntegers); - - var settingsWithout = JsonFormatter.Settings.Default.WithFormatEnumsAsIntegers(false); - Assert.AreEqual(false, settingsWithout.FormatEnumsAsIntegers); - } - - [Test] - public void WithMethodsPreserveExistingSettings() - { - var typeRegistry = TypeRegistry.Empty; - var baseSettings = JsonFormatter.Settings.Default - .WithIndentation("\t") - .WithFormatDefaultValues(true) - .WithFormatEnumsAsIntegers(true) - .WithTypeRegistry(typeRegistry) - .WithPreserveProtoFieldNames(true); - - var settings1 = baseSettings.WithIndentation("\t"); - var settings2 = baseSettings.WithFormatDefaultValues(true); - var settings3 = baseSettings.WithFormatEnumsAsIntegers(true); - var settings4 = baseSettings.WithTypeRegistry(typeRegistry); - var settings5 = baseSettings.WithPreserveProtoFieldNames(true); - - AssertAreEqual(baseSettings, settings1); - AssertAreEqual(baseSettings, settings2); - AssertAreEqual(baseSettings, settings3); - AssertAreEqual(baseSettings, settings4); - AssertAreEqual(baseSettings, settings5); - } - - private static void AssertAreEqual(JsonFormatter.Settings settings, JsonFormatter.Settings other) - { - Assert.AreEqual(settings.Indentation, other.Indentation); - Assert.AreEqual(settings.FormatDefaultValues, other.FormatDefaultValues); - Assert.AreEqual(settings.FormatEnumsAsIntegers, other.FormatEnumsAsIntegers); - Assert.AreEqual(settings.TypeRegistry, other.TypeRegistry); - } - } -} diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs index f4dfde2..3a77990 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs @@ -168,7 +168,8 @@ namespace Google.Protobuf [Test] public void WithFormatDefaultValues_DoesNotAffectProto3OptionalFields() { - var message = new TestProto3Optional { OptionalInt32 = 0 }; + var message = new TestProto3Optional(); + message.OptionalInt32 = 0; var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true)); var json = formatter.Format(message); // The non-optional proto3 fields are formatted, as is the optional-but-specified field. @@ -178,7 +179,8 @@ namespace Google.Protobuf [Test] public void WithFormatDefaultValues_DoesNotAffectProto2Fields() { - var message = new TestProtos.Proto2.ForeignMessage { C = 0 }; + var message = new TestProtos.Proto2.ForeignMessage(); + message.C = 0; var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true)); var json = formatter.Format(message); // The specified field is formatted, but the non-specified field (d) is not. @@ -674,200 +676,6 @@ namespace Google.Protobuf AssertWriteValue(value, "[ 1, 2, 3 ]"); } - [Test] - public void WriteValueWithIndentation_EmptyMessage() - { - var value = new TestEmptyMessage(); - - AssertWriteValue(value, "{}", JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_NestedTestAllTypes() - { - var value = new NestedTestAllTypes - { - Payload = new TestAllTypes - { - SingleBool = true, - SingleInt32 = 100, - SingleString = "multiple fields", - RepeatedString = { "string1", "string2" }, - }, - Child = new NestedTestAllTypes - { - Payload = new TestAllTypes - { - SingleString = "single field", - }, - }, - RepeatedChild = - { - new NestedTestAllTypes { Payload = new TestAllTypes { SingleString = "child 1", RepeatedString = { "string" } } }, - new NestedTestAllTypes { Payload = new TestAllTypes { SingleString = "child 2" } }, - }, - }; - - const string expectedJson = @" -{ - 'child': { - 'payload': { - 'singleString': 'single field' - } - }, - 'payload': { - 'singleInt32': 100, - 'singleBool': true, - 'singleString': 'multiple fields', - 'repeatedString': [ - 'string1', - 'string2' - ] - }, - 'repeatedChild': [ - { - 'payload': { - 'singleString': 'child 1', - 'repeatedString': [ - 'string' - ] - } - }, - { - 'payload': { - 'singleString': 'child 2' - } - } - ] -}"; - AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_WellKnownTypes() - { - var value = new TestWellKnownTypes - { - StructField = new Struct - { - Fields = - { - { "string", Value.ForString("foo") }, - { "numbers", Value.ForList(Value.ForNumber(1), Value.ForNumber(2), Value.ForNumber(3)) }, - { "emptyList", Value.ForList() }, - { "emptyStruct", Value.ForStruct(new Struct()) }, - }, - }, - }; - - const string expectedJson = @" -{ - 'structField': { - 'string': 'foo', - 'numbers': [ - 1, - 2, - 3 - ], - 'emptyList': [], - 'emptyStruct': {} - } -}"; - AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_StructSingleField() - { - var value = new Struct { Fields = { { "structField1", Value.ForString("structFieldValue1") } } }; - - const string expectedJson = @" -{ - 'structField1': 'structFieldValue1' -}"; - AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_StructMultipleFields() - { - var value = new Struct - { - Fields = - { - { "structField1", Value.ForString("structFieldValue1") }, - { "structField2", Value.ForString("structFieldValue2") }, - { "structField3", Value.ForString("structFieldValue3") }, - }, - }; - - const string expectedJson = @" -{ - 'structField1': 'structFieldValue1', - 'structField2': 'structFieldValue2', - 'structField3': 'structFieldValue3' -}"; - AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void FormatWithIndentation_EmbeddedMessage() - { - var value = new TestAllTypes { SingleInt32 = 100, SingleInt64 = 3210987654321L }; - var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithIndentation()); - var valueJson = formatter.Format(value, indentationLevel: 1); - - var actualJson = $@" -{{ - ""data"": {valueJson} -}}"; - const string expectedJson = @" -{ - 'data': { - 'singleInt32': 100, - 'singleInt64': '3210987654321' - } -}"; - AssertJson(expectedJson, actualJson.Trim()); - } - - [Test] - public void WriteValueWithIndentation_Map() - { - var value = new TestMap - { - MapStringString = - { - { "key1", "value1" }, - { "key2", "value2" }, - }, - }; - - const string expectedJson = @" -{ - 'mapStringString': { - 'key1': 'value1', - 'key2': 'value2' - } -}"; - - AssertWriteValue(value, expectedJson, JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_List() - { - var value = new RepeatedField { 1, 2, 3 }; - AssertWriteValue(value, "[\n 1,\n 2,\n 3\n]", JsonFormatter.Settings.Default.WithIndentation()); - } - - [Test] - public void WriteValueWithIndentation_CustomIndentation() - { - var value = new RepeatedField { 1, 2, 3 }; - AssertWriteValue(value, "[\n\t1,\n\t2,\n\t3\n]", JsonFormatter.Settings.Default.WithIndentation("\t")); - } - [Test] public void Proto2_DefaultValuesWritten() { @@ -877,7 +685,7 @@ namespace Google.Protobuf private static void AssertWriteValue(object value, string expectedJson, JsonFormatter.Settings settings = null) { - var writer = new StringWriter { NewLine = "\n" }; + var writer = new StringWriter(); new JsonFormatter(settings ?? JsonFormatter.Settings.Default).WriteValue(writer, value); string actual = writer.ToString(); AssertJson(expectedJson, actual); @@ -885,17 +693,13 @@ namespace Google.Protobuf /// /// Checks that the actual JSON is the same as the expected JSON - but after replacing - /// all apostrophes in the expected JSON with double quotes, trimming leading whitespace and normalizing new lines. - /// This basically makes the tests easier to read. + /// all apostrophes in the expected JSON with double quotes. This basically makes the tests easier + /// to read. /// - /// - /// Line endings are normalized because indented JSON strings are generated with system-specific line endings, - /// while line endings in the test cases are hard-coded, but may be converted during source checkout, depending - /// on git settings, causing unpredictability in the test results otherwise. private static void AssertJson(string expectedJsonWithApostrophes, string actualJson) { - var expectedJson = expectedJsonWithApostrophes.Replace("'", "\"").Replace("\r\n", "\n").TrimStart(); - Assert.AreEqual(expectedJson, actualJson.Replace("\r\n", "\n")); + var expectedJson = expectedJsonWithApostrophes.Replace("'", "\""); + Assert.AreEqual(expectedJson, actualJson); } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index c03b326..eb8996e 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -576,10 +576,6 @@ namespace Google.Protobuf [TestCase("-3.402823e38", -3.402823e38f)] [TestCase("1.5e1", 15f)] [TestCase("15e-1", 1.5f)] - [TestCase("3.4028235e38", float.MaxValue)] - [TestCase("-3.4028235e38", float.MinValue)] - [TestCase("3.4028235e+38", float.MaxValue)] - [TestCase("-3.4028235e+38", float.MinValue)] public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue) { string json = "{ \"singleFloat\": " + jsonValue + "}"; @@ -588,10 +584,8 @@ namespace Google.Protobuf } [Test] - [TestCase("3.4028236e38", typeof(InvalidProtocolBufferException))] - [TestCase("-3.4028236e38", typeof(InvalidProtocolBufferException))] - [TestCase("3.4028236e+38", typeof(InvalidProtocolBufferException))] - [TestCase("-3.4028236e+38", typeof(InvalidProtocolBufferException))] + [TestCase("3.402824e38", typeof(InvalidProtocolBufferException))] + [TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))] [TestCase("1,0", typeof(InvalidJsonException))] [TestCase("1.0.0", typeof(InvalidJsonException))] [TestCase("+1", typeof(InvalidJsonException))] @@ -647,7 +641,7 @@ namespace Google.Protobuf [TestCase("9999-12-31T23:59:59.999999999Z", null)] public void Timestamp_Valid(string jsonValue, string expectedFormatted) { - expectedFormatted ??= jsonValue; + expectedFormatted = expectedFormatted ?? jsonValue; string json = WrapInQuotes(jsonValue); var parsed = Timestamp.Parser.ParseJson(json); Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString()); @@ -764,7 +758,7 @@ namespace Google.Protobuf [TestCase("-315576000000s", null)] public void Duration_Valid(string jsonValue, string expectedFormatted) { - expectedFormatted ??= jsonValue; + expectedFormatted = expectedFormatted ?? jsonValue; string json = WrapInQuotes(jsonValue); var parsed = Duration.Parser.ParseJson(json); Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString()); @@ -1072,26 +1066,25 @@ namespace Google.Protobuf ""mapStringNestedMessage"": null }"; - var message = new TestAllTypesProto3 - { - OptionalInt32 = 1, - OptionalInt64 = 1, - OptionalUint32 = 1, - OptionalUint64 = 1, - OptionalSint32 = 1, - OptionalSint64 = 1, - OptionalFixed32 = 1, - OptionalFixed64 = 1, - OptionalSfixed32 = 1, - OptionalSfixed64 = 1, - OptionalFloat = 1, - OptionalDouble = 1, - OptionalBool = true, - OptionalString = "1", - OptionalBytes = ByteString.CopyFrom(new byte[] { 1 }), - OptionalNestedEnum = TestAllTypesProto3.Types.NestedEnum.Bar, - OptionalNestedMessage = new TestAllTypesProto3.Types.NestedMessage() - }; + TestAllTypesProto3 message = new TestAllTypesProto3(); + + message.OptionalInt32 = 1; + message.OptionalInt64 = 1; + message.OptionalUint32 = 1; + message.OptionalUint64 = 1; + message.OptionalSint32 = 1; + message.OptionalSint64 = 1; + message.OptionalFixed32 = 1; + message.OptionalFixed64 = 1; + message.OptionalSfixed32 = 1; + message.OptionalSfixed64 = 1; + message.OptionalFloat = 1; + message.OptionalDouble = 1; + message.OptionalBool = true; + message.OptionalString = "1"; + message.OptionalBytes = ByteString.CopyFrom(new byte[] { 1 }); + message.OptionalNestedEnum = TestAllTypesProto3.Types.NestedEnum.Bar; + message.OptionalNestedMessage = new TestAllTypesProto3.Types.NestedMessage(); message.RepeatedInt32.Add(1); message.RepeatedInt64.Add(1); message.RepeatedUint32.Add(1); diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 06521dd..df43eff 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -29,7 +29,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - using NUnit.Framework; using System; using System.IO; @@ -127,7 +126,7 @@ namespace Google.Protobuf tokenizer.PushBack(token); Assert.AreEqual(0, tokenizer.ObjectDepth); // Read the same token again, and get back to depth 1 - _ = tokenizer.Next(); + token = tokenizer.Next(); Assert.AreEqual(1, tokenizer.ObjectDepth); // Now the same in reverse, with EndObject diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs index 01fca3e..22adcaa 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs @@ -29,12 +29,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - +using Google.Protobuf; +using Google.Protobuf.Reflection; using System.Buffers; -using pb = Google.Protobuf; -using pbr = Google.Protobuf.Reflection; +using pb = global::Google.Protobuf; +using pbr = global::Google.Protobuf.Reflection; using NUnit.Framework; using System.IO; +using System; using Google.Protobuf.Buffers; namespace Google.Protobuf diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs index f2eb762..05f1e36 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs @@ -136,7 +136,8 @@ namespace Google.Protobuf // test for different IBufferWriter.GetSpan() segment sizes for (int blockSize = 1; blockSize < 256; blockSize *= 2) { - var segmentedBufferWriter = new TestArrayBufferWriter { MaxGrowBy = blockSize }; + var segmentedBufferWriter = new TestArrayBufferWriter(); + segmentedBufferWriter.MaxGrowBy = blockSize; message.WriteTo(segmentedBufferWriter); Assert.AreEqual(bytes, segmentedBufferWriter.WrittenSpan.ToArray()); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs index b5b0b72..46a8c57 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs @@ -38,7 +38,7 @@ using UnitTest.Issues.TestProtos; namespace Google.Protobuf.Test { - public class Proto3OptionalTest + class Proto3OptionalTest { [Test] public void OptionalInt32FieldLifecycle() diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs index d4dfd18..f0248ac 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/ReadOnlySequenceFactory.cs @@ -33,6 +33,9 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace Google.Protobuf { @@ -47,7 +50,7 @@ namespace Google.Protobuf if (addEmptySegmentDelimiters) { - segments.Add(Array.Empty()); + segments.Add(new byte[0]); } var currentIndex = 0; @@ -62,7 +65,7 @@ namespace Google.Protobuf if (addEmptySegmentDelimiters) { - segments.Add(Array.Empty()); + segments.Add(new byte[0]); } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs index f3651df..9dca501 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/RefStructCompatibilityTest.cs @@ -77,42 +77,43 @@ namespace Google.Protobuf /// /// private void RunOldCsharpCompilerAndCheckSuccess(string args, string workingDirectory) - { - using var process = new Process(); - - // Get the path to the old C# 5 compiler from .NET framework. This approach is not 100% reliable, but works on most machines. - // Alternative way of getting the framework path is System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() - // but it only works with the net45 target. - var oldCsharpCompilerPath = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "Microsoft.NET", "Framework", "v4.0.30319", "csc.exe"); - process.StartInfo.FileName = oldCsharpCompilerPath; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.Arguments = args; - process.StartInfo.WorkingDirectory = workingDirectory; - - process.OutputDataReceived += (sender, e) => + { + using (var process = new Process()) { - if (e.Data != null) + // Get the path to the old C# 5 compiler from .NET framework. This approach is not 100% reliable, but works on most machines. + // Alternative way of getting the framework path is System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + // but it only works with the net45 target. + var oldCsharpCompilerPath = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "Microsoft.NET", "Framework", "v4.0.30319", "csc.exe"); + process.StartInfo.FileName = oldCsharpCompilerPath; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.Arguments = args; + process.StartInfo.WorkingDirectory = workingDirectory; + + process.OutputDataReceived += (sender, e) => { - Console.WriteLine(e.Data); - } - }; - process.ErrorDataReceived += (sender, e) => - { - if (e.Data != null) + if (e.Data != null) + { + Console.WriteLine(e.Data); + } + }; + process.ErrorDataReceived += (sender, e) => { - Console.WriteLine(e.Data); - } - }; + if (e.Data != null) + { + Console.WriteLine(e.Data); + } + }; - process.Start(); + process.Start(); - process.BeginErrorReadLine(); - process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); - process.WaitForExit(); - Assert.AreEqual(0, process.ExitCode); + process.WaitForExit(); + Assert.AreEqual(0, process.ExitCode); + } } } } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index 589c35c..68b9bd3 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -31,10 +31,13 @@ #endregion using Google.Protobuf.Reflection; +using Google.Protobuf.WellKnownTypes; using NUnit.Framework; using System; +using System.IO; using System.Linq; using UnitTest.Issues.TestProtos; +using static Google.Protobuf.WireFormat; using static UnitTest.Issues.TestProtos.ComplexOptionType2.Types; using static UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Extensions; using static UnitTest.Issues.TestProtos.DummyMessageContainingEnum.Types; @@ -62,7 +65,7 @@ namespace Google.Protobuf.Test.Reflection } else { - v = default; + v = default(E); return false; } }; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs index 03722d4..65c8b82 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -35,6 +35,7 @@ using NUnit.Framework; using ProtobufUnittest; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using UnitTest.Issues.TestProtos; diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs index eeb9f89..f3e5af2 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs @@ -30,8 +30,10 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; using System.IO; using Google.Protobuf.TestProtos; +using Proto2 = Google.Protobuf.TestProtos.Proto2; using NUnit.Framework; namespace Google.Protobuf @@ -125,7 +127,8 @@ namespace Google.Protobuf public void TestClone(IMessage message) { var emptyMessage = new TestEmptyMessage(); - TestEmptyMessage otherEmptyMessage = emptyMessage.Clone(); + var otherEmptyMessage = new TestEmptyMessage(); + otherEmptyMessage = emptyMessage.Clone(); Assert.AreEqual(emptyMessage.CalculateSize(), otherEmptyMessage.CalculateSize()); Assert.AreEqual(emptyMessage.ToByteArray(), otherEmptyMessage.ToByteArray()); @@ -166,13 +169,13 @@ namespace Google.Protobuf byte[] data = message.ToByteArray(); int fullSize = message.CalculateSize(); - void AssertEmpty(IMessage msg) + Action assertEmpty = msg => { Assert.AreEqual(0, msg.CalculateSize()); Assert.AreEqual(goldenEmptyMessage, msg); - } + }; - void AssertFull(IMessage msg) => Assert.AreEqual(fullSize, msg.CalculateSize()); + Action assertFull = msg => Assert.AreEqual(fullSize, msg.CalculateSize()); // Test the behavior of the parsers with and without discarding, both generic and non-generic. MessageParser retainingParser1 = TestEmptyMessage.Parser; @@ -181,28 +184,28 @@ namespace Google.Protobuf MessageParser discardingParser2 = retainingParser2.WithDiscardUnknownFields(true); // Test parse from byte[] - MessageParsingHelpers.AssertReadingMessage(retainingParser1, data, m => AssertFull(m)); - MessageParsingHelpers.AssertReadingMessage(retainingParser2, data, m => AssertFull(m)); - MessageParsingHelpers.AssertReadingMessage(discardingParser1, data, m => AssertEmpty(m)); - MessageParsingHelpers.AssertReadingMessage(discardingParser2, data, m => AssertEmpty(m)); + MessageParsingHelpers.AssertReadingMessage(retainingParser1, data, m => assertFull(m)); + MessageParsingHelpers.AssertReadingMessage(retainingParser2, data, m => assertFull(m)); + MessageParsingHelpers.AssertReadingMessage(discardingParser1, data, m => assertEmpty(m)); + MessageParsingHelpers.AssertReadingMessage(discardingParser2, data, m => assertEmpty(m)); // Test parse from byte[] with offset - AssertFull(retainingParser1.ParseFrom(data, 0, data.Length)); - AssertFull(retainingParser2.ParseFrom(data, 0, data.Length)); - AssertEmpty(discardingParser1.ParseFrom(data, 0, data.Length)); - AssertEmpty(discardingParser2.ParseFrom(data, 0, data.Length)); + assertFull(retainingParser1.ParseFrom(data, 0, data.Length)); + assertFull(retainingParser2.ParseFrom(data, 0, data.Length)); + assertEmpty(discardingParser1.ParseFrom(data, 0, data.Length)); + assertEmpty(discardingParser2.ParseFrom(data, 0, data.Length)); // Test parse from CodedInputStream - AssertFull(retainingParser1.ParseFrom(new CodedInputStream(data))); - AssertFull(retainingParser2.ParseFrom(new CodedInputStream(data))); - AssertEmpty(discardingParser1.ParseFrom(new CodedInputStream(data))); - AssertEmpty(discardingParser2.ParseFrom(new CodedInputStream(data))); + assertFull(retainingParser1.ParseFrom(new CodedInputStream(data))); + assertFull(retainingParser2.ParseFrom(new CodedInputStream(data))); + assertEmpty(discardingParser1.ParseFrom(new CodedInputStream(data))); + assertEmpty(discardingParser2.ParseFrom(new CodedInputStream(data))); // Test parse from Stream - AssertFull(retainingParser1.ParseFrom(new MemoryStream(data))); - AssertFull(retainingParser2.ParseFrom(new MemoryStream(data))); - AssertEmpty(discardingParser1.ParseFrom(new MemoryStream(data))); - AssertEmpty(discardingParser2.ParseFrom(new MemoryStream(data))); + assertFull(retainingParser1.ParseFrom(new MemoryStream(data))); + assertFull(retainingParser2.ParseFrom(new MemoryStream(data))); + assertEmpty(discardingParser1.ParseFrom(new MemoryStream(data))); + assertEmpty(discardingParser2.ParseFrom(new MemoryStream(data))); } [Test] diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs index 187e06a..c05cb08 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs @@ -30,11 +30,8 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using Google.Protobuf.Reflection; using Google.Protobuf.TestProtos; using NUnit.Framework; -using System.Linq; -using UnitTest.Issues.TestProtos; namespace Google.Protobuf.WellKnownTypes { @@ -126,6 +123,7 @@ namespace Google.Protobuf.WellKnownTypes [TestCase("foobar", "")] public void GetTypeName(string typeUrl, string expectedTypeName) { + var any = new Any { TypeUrl = typeUrl }; Assert.AreEqual(expectedTypeName, Any.GetTypeName(typeUrl)); } @@ -150,34 +148,10 @@ namespace Google.Protobuf.WellKnownTypes Assert.False(any.Is(TestOneof.Descriptor)); } - [Test] public void IsRightType() { var any = Any.Pack(SampleMessages.CreateFullTestAllTypes()); Assert.True(any.Is(TestAllTypes.Descriptor)); } - - [Test] - public void Unpack_TypeRegistry() - { - var messages = new IMessage[] - { - SampleMessages.CreateFullTestAllTypes(), - new TestWellKnownTypes { BoolField = true }, - new MoreString { Data = { "x" } }, - new MoreBytes { Data = ByteString.CopyFromUtf8("xyz") }, - new ReservedNames { Descriptor_ = 10 } - }; - var anyMessages = messages.Select(Any.Pack); - - // The type registry handles the first four of the packed messages, but not the final one. - var registry = TypeRegistry.FromFiles( - UnittestWellKnownTypesReflection.Descriptor, - UnittestProto3Reflection.Descriptor); - var unpacked = anyMessages.Select(any => any.Unpack(registry)).ToList(); - var expected = (IMessage[]) messages.Clone(); - expected[4] = null; - Assert.AreEqual(expected, unpacked); - } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs b/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs index 8124f0c..141faf8 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs @@ -128,38 +128,5 @@ namespace Google.Protobuf.WellKnownTypes var duration = new Duration { Seconds = 1, Nanos = -1 }; Assert.AreEqual("{ \"@warning\": \"Invalid Duration\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString()); } - - [Test] - public void Comparability() - { - Duration[] durationsInExpectedSortOrder = - { - null, - new Duration { Seconds = -10, Nanos = -10 }, - new Duration { Seconds = -10, Nanos = -1 }, - new Duration { Seconds = -1, Nanos = -10 }, - new Duration { Seconds = -1, Nanos = -1 }, - new Duration(), - new Duration { Seconds = 1, Nanos = 1 }, - new Duration { Seconds = 1, Nanos = 10 }, - new Duration { Seconds = 10, Nanos = 1 }, - new Duration { Seconds = 10, Nanos = 10 } - }; - - for (int i = 0; i < durationsInExpectedSortOrder.Length; i++) - { - var target = durationsInExpectedSortOrder[i]; - if (target is null) - { - continue; - } - for (int j = 0; j < durationsInExpectedSortOrder.Length; j++) - { - var expectedResult = Math.Sign(i - j); - var actualResult = target.CompareTo(durationsInExpectedSortOrder[j]); - Assert.AreEqual(expectedResult, actualResult); - } - } - } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/testprotos.pb b/libs/protobuf/csharp/src/Google.Protobuf.Test/testprotos.pb index 106ada8..83958c6 100644 Binary files a/libs/protobuf/csharp/src/Google.Protobuf.Test/testprotos.pb and b/libs/protobuf/csharp/src/Google.Protobuf.Test/testprotos.pb differ diff --git a/libs/protobuf/csharp/src/Google.Protobuf.sln b/libs/protobuf/csharp/src/Google.Protobuf.sln index b0bebec..b571e53 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.sln +++ b/libs/protobuf/csharp/src/Google.Protobuf.sln @@ -12,6 +12,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.Conformance EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{9695E08F-9829-497D-B95C-B38F28D48690}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Benchmarks", "Google.Protobuf.Benchmarks\Google.Protobuf.Benchmarks.csproj", "{D25E4804-4DEA-45AB-9F8C-BA4DBD8E5A07}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test.TestProtos", "Google.Protobuf.Test.TestProtos\Google.Protobuf.Test.TestProtos.csproj", "{ADF24BEB-A318-4530-8448-356B72B820EA}" EndProject Global @@ -40,6 +42,10 @@ Global {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.Build.0 = Debug|Any CPU {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.ActiveCfg = Release|Any CPU {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.Build.0 = Release|Any CPU + {D25E4804-4DEA-45AB-9F8C-BA4DBD8E5A07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D25E4804-4DEA-45AB-9F8C-BA4DBD8E5A07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D25E4804-4DEA-45AB-9F8C-BA4DBD8E5A07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D25E4804-4DEA-45AB-9F8C-BA4DBD8E5A07}.Release|Any CPU.Build.0 = Release|Any CPU {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ADF24BEB-A318-4530-8448-356B72B820EA}.Debug|Any CPU.Build.0 = Debug|Any CPU {ADF24BEB-A318-4530-8448-356B72B820EA}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ByteString.cs b/libs/protobuf/csharp/src/Google.Protobuf/ByteString.cs index b13b611..8c6eb5b 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ByteString.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ByteString.cs @@ -37,8 +37,13 @@ using System.IO; using System.Runtime.InteropServices; using System.Security; using System.Text; +#if !NET35 using System.Threading; using System.Threading.Tasks; +#endif +#if NET35 +using Google.Protobuf.Compatibility; +#endif namespace Google.Protobuf { @@ -181,6 +186,7 @@ namespace Google.Protobuf return AttachBytes(bytes); } +#if !NET35 /// /// Constructs a from data in the given stream, asynchronously. /// @@ -189,11 +195,12 @@ namespace Google.Protobuf /// The stream to copy into a ByteString. /// The cancellation token to use when reading from the stream, if any. /// A ByteString with content read from the given stream. - public static Task FromStreamAsync(Stream stream, CancellationToken cancellationToken = default) + public static Task FromStreamAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) { ProtoPreconditions.CheckNotNull(stream, nameof(stream)); return ByteStringAsync.FromStreamAsyncCore(stream, cancellationToken); } +#endif /// /// Constructs a from the given array. The contents @@ -340,7 +347,7 @@ namespace Google.Protobuf { return true; } - if (lhs is null || rhs is null) + if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) { return false; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ByteStringAsync.cs b/libs/protobuf/csharp/src/Google.Protobuf/ByteStringAsync.cs index 5aa92f0..3465cc6 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ByteStringAsync.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ByteStringAsync.cs @@ -43,6 +43,7 @@ namespace Google.Protobuf /// internal static class ByteStringAsync { +#if !NET35 internal static async Task FromStreamAsyncCore(Stream stream, CancellationToken cancellationToken) { int capacity = stream.CanSeek ? checked((int)(stream.Length - stream.Position)) : 0; @@ -58,5 +59,6 @@ namespace Google.Protobuf #endif return ByteString.AttachBytes(bytes); } +#endif } } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs b/libs/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs index aea546a..96ae84c 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -32,7 +32,10 @@ using Google.Protobuf.Collections; using System; +using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; namespace Google.Protobuf @@ -646,6 +649,21 @@ namespace Google.Protobuf } } + /// + /// Called when buffer is empty to read more bytes from the + /// input. If is true, RefillBuffer() guarantees that + /// either there will be at least one byte in the buffer when it returns + /// or it will throw an exception. If is false, + /// RefillBuffer() returns false if no more bytes were available. + /// + /// + /// + private bool RefillBuffer(bool mustSucceed) + { + var span = new ReadOnlySpan(buffer); + return state.segmentedBufferHelper.RefillBuffer(ref span, ref state, mustSucceed); + } + /// /// Reads a fixed size of bytes from the input. /// diff --git a/libs/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs b/libs/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs index 2a162c6..5b8cca1 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs @@ -30,9 +30,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using Google.Protobuf.Collections; using System; using System.IO; using System.Security; +using System.Text; namespace Google.Protobuf { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Collections/Lists.cs b/libs/protobuf/csharp/src/Google.Protobuf/Collections/Lists.cs index 9007709..860795c 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Collections/Lists.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Collections/Lists.cs @@ -31,6 +31,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Google.Protobuf.Collections { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs b/libs/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs index 09afb75..e5217f4 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -31,7 +31,9 @@ #endregion using Google.Protobuf.Compatibility; +using Google.Protobuf.Reflection; using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.IO; @@ -66,14 +68,18 @@ namespace Google.Protobuf.Collections /// in future versions. /// /// - public sealed class MapField : IDeepCloneable>, IDictionary, IEquatable>, IDictionary, IReadOnlyDictionary + public sealed class MapField : IDeepCloneable>, IDictionary, IEquatable>, IDictionary +#if !NET35 + , IReadOnlyDictionary +#endif { private static readonly EqualityComparer ValueEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); private static readonly EqualityComparer KeyEqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.) - private readonly Dictionary>> map = new(KeyEqualityComparer); - private readonly LinkedList> list = new(); + private readonly Dictionary>> map = + new Dictionary>>(KeyEqualityComparer); + private readonly LinkedList> list = new LinkedList>(); /// /// Creates a deep clone of this object. @@ -141,7 +147,8 @@ namespace Google.Protobuf.Collections public bool Remove(TKey key) { ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); - if (map.TryGetValue(key, out LinkedListNode> node)) + LinkedListNode> node; + if (map.TryGetValue(key, out node)) { map.Remove(key); node.List.Remove(node); @@ -163,14 +170,15 @@ namespace Google.Protobuf.Collections /// true if the map contains an element with the specified key; otherwise, false. public bool TryGetValue(TKey key, out TValue value) { - if (map.TryGetValue(key, out LinkedListNode> node)) + LinkedListNode> node; + if (map.TryGetValue(key, out node)) { value = node.Value.Value; return true; } else { - value = default; + value = default(TValue); return false; } } @@ -187,7 +195,8 @@ namespace Google.Protobuf.Collections get { ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key)); - if (TryGetValue(key, out TValue value)) + TValue value; + if (TryGetValue(key, out value)) { return value; } @@ -201,8 +210,9 @@ namespace Google.Protobuf.Collections { ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value)); } + LinkedListNode> node; var pair = new KeyValuePair(key, value); - if (map.TryGetValue(key, out LinkedListNode> node)) + if (map.TryGetValue(key, out node)) { node.Value = pair; } @@ -217,12 +227,12 @@ namespace Google.Protobuf.Collections /// /// Gets a collection containing the keys in the map. /// - public ICollection Keys => new MapView(this, pair => pair.Key, ContainsKey); + public ICollection Keys { get { return new MapView(this, pair => pair.Key, ContainsKey); } } /// /// Gets a collection containing the values in the map. /// - public ICollection Values => new MapView(this, pair => pair.Value, ContainsValue); + public ICollection Values { get { return new MapView(this, pair => pair.Value, ContainsValue); } } /// /// Adds the specified entries to the map. The keys and values are not automatically cloned. @@ -237,28 +247,16 @@ namespace Google.Protobuf.Collections } } - /// - /// Adds the specified entries to the map, replacing any existing entries with the same keys. - /// The keys and values are not automatically cloned. - /// - /// This method primarily exists to be called from MergeFrom methods in generated classes for messages. - /// The entries to add to the map. - public void MergeFrom(IDictionary entries) - { - ProtoPreconditions.CheckNotNull(entries, nameof(entries)); - foreach (var pair in entries) - { - this[pair.Key] = pair.Value; - } - } - /// /// Returns an enumerator that iterates through the collection. /// /// /// An enumerator that can be used to iterate through the collection. /// - public IEnumerator> GetEnumerator() => list.GetEnumerator(); + public IEnumerator> GetEnumerator() + { + return list.GetEnumerator(); + } /// /// Returns an enumerator that iterates through a collection. @@ -266,13 +264,19 @@ namespace Google.Protobuf.Collections /// /// An object that can be used to iterate through the collection. /// - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } /// /// Adds the specified item to the map. /// /// The item to add to the map. - void ICollection>.Add(KeyValuePair item) => Add(item.Key, item.Value); + void ICollection>.Add(KeyValuePair item) + { + Add(item.Key, item.Value); + } /// /// Removes all items from the map. @@ -288,16 +292,21 @@ namespace Google.Protobuf.Collections /// /// The key/value pair to find. /// - bool ICollection>.Contains(KeyValuePair item) => - TryGetValue(item.Key, out TValue value) && ValueEqualityComparer.Equals(item.Value, value); + bool ICollection>.Contains(KeyValuePair item) + { + TValue value; + return TryGetValue(item.Key, out value) && ValueEqualityComparer.Equals(item.Value, value); + } /// /// Copies the key/value pairs in this map to an array. /// /// The array to copy the entries into. /// The index of the array at which to start copying values. - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) => + void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) + { list.CopyTo(array, arrayIndex); + } /// /// Removes the specified key/value pair from the map. @@ -311,7 +320,8 @@ namespace Google.Protobuf.Collections { throw new ArgumentException("Key is null", nameof(item)); } - if (map.TryGetValue(item.Key, out LinkedListNode> node) && + LinkedListNode> node; + if (map.TryGetValue(item.Key, out node) && EqualityComparer.Default.Equals(item.Value, node.Value.Value)) { map.Remove(item.Key); @@ -327,12 +337,12 @@ namespace Google.Protobuf.Collections /// /// Gets the number of elements contained in the map. /// - public int Count => list.Count; + public int Count { get { return list.Count; } } /// /// Gets a value indicating whether the map is read-only. /// - public bool IsReadOnly => false; + public bool IsReadOnly { get { return false; } } /// /// Determines whether the specified , is equal to this instance. @@ -341,7 +351,10 @@ namespace Google.Protobuf.Collections /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object other) => Equals(other as MapField); + public override bool Equals(object other) + { + return Equals(other as MapField); + } /// /// Returns a hash code for this instance. @@ -386,7 +399,8 @@ namespace Google.Protobuf.Collections var valueComparer = ValueEqualityComparer; foreach (var pair in this) { - if (!other.TryGetValue(pair.Key, out TValue value)) + TValue value; + if (!other.TryGetValue(pair.Key, out value)) { return false; } @@ -518,20 +532,33 @@ namespace Google.Protobuf.Collections } #region IDictionary explicit interface implementation + void IDictionary.Add(object key, object value) + { + Add((TKey)key, (TValue)value); + } - void IDictionary.Add(object key, object value) => Add((TKey)key, (TValue)value); + bool IDictionary.Contains(object key) + { + if (!(key is TKey)) + { + return false; + } + return ContainsKey((TKey)key); + } - bool IDictionary.Contains(object key) => key is TKey k && ContainsKey(k); - - IDictionaryEnumerator IDictionary.GetEnumerator() => new DictionaryEnumerator(GetEnumerator()); + IDictionaryEnumerator IDictionary.GetEnumerator() + { + return new DictionaryEnumerator(GetEnumerator()); + } void IDictionary.Remove(object key) { ProtoPreconditions.CheckNotNull(key, nameof(key)); - if (key is TKey k) + if (!(key is TKey)) { - Remove(k); + return; } + Remove((TKey)key); } void ICollection.CopyTo(Array array, int index) @@ -541,27 +568,28 @@ namespace Google.Protobuf.Collections temp.CopyTo(array, index); } - bool IDictionary.IsFixedSize => false; + bool IDictionary.IsFixedSize { get { return false; } } - ICollection IDictionary.Keys => (ICollection)Keys; + ICollection IDictionary.Keys { get { return (ICollection)Keys; } } - ICollection IDictionary.Values => (ICollection)Values; + ICollection IDictionary.Values { get { return (ICollection)Values; } } - bool ICollection.IsSynchronized => false; + bool ICollection.IsSynchronized { get { return false; } } - object ICollection.SyncRoot => this; + object ICollection.SyncRoot { get { return this; } } object IDictionary.this[object key] { get { ProtoPreconditions.CheckNotNull(key, nameof(key)); - if (key is TKey k) + if (!(key is TKey)) { - TryGetValue(k, out TValue value); - return value; + return null; } - return null; + TValue value; + TryGetValue((TKey)key, out value); + return value; } set @@ -572,8 +600,11 @@ namespace Google.Protobuf.Collections #endregion #region IReadOnlyDictionary explicit interface implementation +#if !NET35 IEnumerable IReadOnlyDictionary.Keys => Keys; + IEnumerable IReadOnlyDictionary.Values => Values; +#endif #endregion private class DictionaryEnumerator : IDictionaryEnumerator @@ -585,14 +616,20 @@ namespace Google.Protobuf.Collections this.enumerator = enumerator; } - public bool MoveNext() => enumerator.MoveNext(); + public bool MoveNext() + { + return enumerator.MoveNext(); + } - public void Reset() => enumerator.Reset(); + public void Reset() + { + enumerator.Reset(); + } - public object Current => Entry; - public DictionaryEntry Entry => new DictionaryEntry(Key, Value); - public object Key => enumerator.Current.Key; - public object Value => enumerator.Current.Value; + public object Current { get { return Entry; } } + public DictionaryEntry Entry { get { return new DictionaryEntry(Key, Value); } } + public object Key { get { return enumerator.Current.Key; } } + public object Value { get { return enumerator.Current.Value; } } } /// @@ -651,19 +688,28 @@ namespace Google.Protobuf.Collections this.containsCheck = containsCheck; } - public int Count => parent.Count; + public int Count { get { return parent.Count; } } - public bool IsReadOnly => true; + public bool IsReadOnly { get { return true; } } - public bool IsSynchronized => false; + public bool IsSynchronized { get { return false; } } - public object SyncRoot => parent; + public object SyncRoot { get { return parent; } } - public void Add(T item) => throw new NotSupportedException(); + public void Add(T item) + { + throw new NotSupportedException(); + } - public void Clear() => throw new NotSupportedException(); + public void Clear() + { + throw new NotSupportedException(); + } - public bool Contains(T item) => containsCheck(item); + public bool Contains(T item) + { + return containsCheck(item); + } public void CopyTo(T[] array, int arrayIndex) { @@ -686,9 +732,15 @@ namespace Google.Protobuf.Collections return parent.list.Select(projection).GetEnumerator(); } - public bool Remove(T item) => throw new NotSupportedException(); + public bool Remove(T item) + { + throw new NotSupportedException(); + } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } public void CopyTo(Array array, int index) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs b/libs/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs new file mode 100644 index 0000000..28530a2 --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs @@ -0,0 +1,147 @@ +#region Copyright notice and license +// 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. +#endregion + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Google.Protobuf.Collections +{ + /// + /// Read-only wrapper around another dictionary. + /// + internal sealed class ReadOnlyDictionary : IDictionary + { + private readonly IDictionary wrapped; + + public ReadOnlyDictionary(IDictionary wrapped) + { + this.wrapped = wrapped; + } + + public void Add(TKey key, TValue value) + { + throw new InvalidOperationException(); + } + + public bool ContainsKey(TKey key) + { + return wrapped.ContainsKey(key); + } + + public ICollection Keys + { + get { return wrapped.Keys; } + } + + public bool Remove(TKey key) + { + throw new InvalidOperationException(); + } + + public bool TryGetValue(TKey key, out TValue value) + { + return wrapped.TryGetValue(key, out value); + } + + public ICollection Values + { + get { return wrapped.Values; } + } + + public TValue this[TKey key] + { + get { return wrapped[key]; } + set { throw new InvalidOperationException(); } + } + + public void Add(KeyValuePair item) + { + throw new InvalidOperationException(); + } + + public void Clear() + { + throw new InvalidOperationException(); + } + + public bool Contains(KeyValuePair item) + { + return wrapped.Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + wrapped.CopyTo(array, arrayIndex); + } + + public int Count + { + get { return wrapped.Count; } + } + + public bool IsReadOnly + { + get { return true; } + } + + public bool Remove(KeyValuePair item) + { + throw new InvalidOperationException(); + } + + public IEnumerator> GetEnumerator() + { + return wrapped.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable) wrapped).GetEnumerator(); + } + + public override bool Equals(object obj) + { + return wrapped.Equals(obj); + } + + public override int GetHashCode() + { + return wrapped.GetHashCode(); + } + + public override string ToString() + { + return wrapped.ToString(); + } + } +} \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/libs/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index 56117fd..9269c74 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -35,6 +35,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Security; +using System.Threading; namespace Google.Protobuf.Collections { @@ -47,7 +48,10 @@ namespace Google.Protobuf.Collections /// supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases. /// /// The element type of the repeated field. - public sealed class RepeatedField : IList, IList, IDeepCloneable>, IEquatable>, IReadOnlyList + public sealed class RepeatedField : IList, IList, IDeepCloneable>, IEquatable> +#if !NET35 + , IReadOnlyList +#endif { private static readonly EqualityComparer EqualityComparer = ProtobufEqualityComparers.GetEqualityComparer(); private static readonly T[] EmptyArray = new T[0]; @@ -73,7 +77,8 @@ namespace Google.Protobuf.Collections if (array != EmptyArray) { clone.array = (T[])array.Clone(); - if (clone.array is IDeepCloneable[] cloneableArray) + IDeepCloneable[] cloneableArray = clone.array as IDeepCloneable[]; + if (cloneableArray != null) { for (int i = 0; i < count; i++) { @@ -279,9 +284,8 @@ namespace Google.Protobuf.Collections } /// - /// Gets and sets the capacity of the RepeatedField's internal array. - /// When set, the internal array is reallocated to the given capacity. - /// The new value is less than . + /// Gets and sets the capacity of the RepeatedField's internal array. WHen set, the internal array is reallocated to the given capacity. + /// The new value is less than Count -or- when Count is less than 0. /// public int Capacity { @@ -339,10 +343,7 @@ namespace Google.Protobuf.Collections /// public void Clear() { - // Clear the content of the array (so that any objects it referred to can be garbage collected) - // but keep the capacity the same. This allows large repeated fields to be reused without - // array reallocation. - Array.Clear(array, 0, count); + array = EmptyArray; count = 0; } @@ -351,7 +352,10 @@ namespace Google.Protobuf.Collections /// /// The item to find. /// true if this collection contains the given item; false otherwise. - public bool Contains(T item) => IndexOf(item) != -1; + public bool Contains(T item) + { + return IndexOf(item) != -1; + } /// /// Copies this collection to the given array. @@ -377,7 +381,7 @@ namespace Google.Protobuf.Collections } Array.Copy(array, index + 1, array, index, count - index - 1); count--; - array[count] = default; + array[count] = default(T); return true; } @@ -401,7 +405,8 @@ namespace Google.Protobuf.Collections // Optimization 1: If the collection we're adding is already a RepeatedField, // we know the values are valid. - if (values is RepeatedField otherRepeatedField) + var otherRepeatedField = values as RepeatedField; + if (otherRepeatedField != null) { EnsureSize(count + otherRepeatedField.count); Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count); @@ -411,7 +416,8 @@ namespace Google.Protobuf.Collections // Optimization 2: The collection is an ICollection, so we can expand // just once and ask the collection to copy itself into the array. - if (values is ICollection collection) + var collection = values as ICollection; + if (collection != null) { var extraCount = collection.Count; // For reference types and nullable value types, we need to check that there are no nulls @@ -481,15 +487,21 @@ namespace Google.Protobuf.Collections /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object obj) => Equals(obj as RepeatedField); - + public override bool Equals(object obj) + { + return Equals(obj as RepeatedField); + } + /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to iterate through the collection. /// - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } /// /// Returns a hash code for this instance. @@ -514,7 +526,7 @@ namespace Google.Protobuf.Collections /// true if refers to an equal repeated field; false otherwise. public bool Equals(RepeatedField other) { - if (other is null) + if (ReferenceEquals(other, null)) { return false; } @@ -587,7 +599,7 @@ namespace Google.Protobuf.Collections } Array.Copy(array, index + 1, array, index, count - index - 1); count--; - array[count] = default; + array[count] = default(T); } /// @@ -633,7 +645,10 @@ namespace Google.Protobuf.Collections #region Explicit interface implementation for IList and ICollection. bool IList.IsFixedSize => false; - void ICollection.CopyTo(Array array, int index) => Array.Copy(this.array, 0, array, index, count); + void ICollection.CopyTo(Array array, int index) + { + Array.Copy(this.array, 0, array, index, count); + } bool ICollection.IsSynchronized => false; @@ -641,8 +656,8 @@ namespace Google.Protobuf.Collections object IList.this[int index] { - get => this[index]; - set => this[index] = (T)value; + get { return this[index]; } + set { this[index] = (T)value; } } int IList.Add(object value) @@ -651,18 +666,32 @@ namespace Google.Protobuf.Collections return count - 1; } - bool IList.Contains(object value) => (value is T t && Contains(t)); + bool IList.Contains(object value) + { + return (value is T && Contains((T)value)); + } - int IList.IndexOf(object value) => (value is T t) ? IndexOf(t) : -1; + int IList.IndexOf(object value) + { + if (!(value is T)) + { + return -1; + } + return IndexOf((T)value); + } - void IList.Insert(int index, object value) => Insert(index, (T) value); + void IList.Insert(int index, object value) + { + Insert(index, (T) value); + } void IList.Remove(object value) { - if (value is T t) + if (!(value is T)) { - Remove(t); + return; } + Remove((T)value); } #endregion } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/MethodInfoExtensions.cs b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/MethodInfoExtensions.cs new file mode 100644 index 0000000..7b946cb --- /dev/null +++ b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/MethodInfoExtensions.cs @@ -0,0 +1,47 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2017 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. +#endregion + +#if NET35 +using System; +using System.Reflection; + +namespace Google.Protobuf.Compatibility +{ + // .NET Core (at least netstandard1.0) doesn't have Delegate.CreateDelegate, and .NET 3.5 doesn't have + // MethodInfo.CreateDelegate. Proxy from one to the other on .NET 3.5... + internal static class MethodInfoExtensions + { + internal static Delegate CreateDelegate(this MethodInfo method, Type type) => + Delegate.CreateDelegate(type, method); + } +} +#endif diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs index 8a6fefa..95a02c7 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs @@ -47,7 +47,11 @@ namespace Google.Protobuf.Compatibility /// internal static MethodInfo GetGetMethod(this PropertyInfo target) { +#if NET35 + var method = target.GetGetMethod(); +#else var method = target.GetMethod; +#endif return method != null && method.IsPublic ? method : null; } @@ -57,7 +61,11 @@ namespace Google.Protobuf.Compatibility /// internal static MethodInfo GetSetMethod(this PropertyInfo target) { +#if NET35 + var method = target.GetSetMethod(); +#else var method = target.SetMethod; +#endif return method != null && method.IsPublic ? method : null; } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf.Test/ParsingPrimitivesTest.cs b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs similarity index 62% rename from libs/protobuf/csharp/src/Google.Protobuf.Test/ParsingPrimitivesTest.cs rename to libs/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs index 4d0aa9e..bf4bf22 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf.Test/ParsingPrimitivesTest.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs @@ -1,6 +1,6 @@ #region Copyright notice and license // Protocol Buffers - Google's data interchange format -// Copyright 2022 Google Inc. All rights reserved. +// Copyright 2015 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -30,34 +30,37 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using NUnit.Framework; +#if NET35 using System; -using System.Linq; +using System.IO; -namespace Google.Protobuf.Test; - -internal class ParsingPrimitivesTest +namespace Google.Protobuf.Compatibility { - // Note: test cases use integers rather than bytes as they're easier - // to specify in attributes. - - [Test] - [TestCase("\ufffd", 255)] - [TestCase("A\ufffd", 65, 255)] - [TestCase("A\ufffd\ufffdB", 65, 255, 255, 66)] - // Overlong form of "space" - [TestCase("\ufffd\ufffd", 0xc0, 0xa0)] - public void ReadRawString_NonUtf8(string expectedText, params int[] bytes) + /// + /// Extension methods for in order to provide + /// backwards compatibility with .NET 3.5 + /// + public static class StreamExtensions { - var context = CreateContext(bytes); - string text = ParsingPrimitives.ReadRawString(ref context.buffer, ref context.state, bytes.Length); - Assert.AreEqual(expectedText, text); - } + // 81920 seems to be the default buffer size used in .NET 4.5.1 + private const int BUFFER_SIZE = 81920; - private static ParseContext CreateContext(int[] bytes) - { - byte[] actualBytes = bytes.Select(b => (byte) b).ToArray(); - ParseContext.Initialize(actualBytes.AsSpan(), out var context); - return context; + /// + /// Write the contents of the current stream to the destination stream + /// + public static void CopyTo(this Stream source, Stream destination) + { + if (destination == null) + { + throw new ArgumentNullException(nameof(destination)); + } + + byte[] buffer = new byte[BUFFER_SIZE]; + int numBytesRead; + while ((numBytesRead = source.Read(buffer, 0, buffer.Length)) > 0) { + destination.Write(buffer, 0, numBytesRead); + } + } } } +#endif diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs index 5db5dca..b3acda2 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs @@ -34,6 +34,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; +#if !NET35 namespace Google.Protobuf.Compatibility { /// @@ -111,3 +112,4 @@ namespace Google.Protobuf.Compatibility } } } +#endif diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Compiler/Plugin.cs b/libs/protobuf/csharp/src/Google.Protobuf/Compiler/Plugin.cs deleted file mode 100644 index f3a6c17..0000000 --- a/libs/protobuf/csharp/src/Google.Protobuf/Compiler/Plugin.cs +++ /dev/null @@ -1,1490 +0,0 @@ -// -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/compiler/plugin.proto -// -#pragma warning disable 1591, 0612, 3021, 8981 -#region Designer generated code - -using pb = global::Google.Protobuf; -using pbc = global::Google.Protobuf.Collections; -using pbr = global::Google.Protobuf.Reflection; -using scg = global::System.Collections.Generic; -namespace Google.Protobuf.Compiler { - - /// Holder for reflection information generated from google/protobuf/compiler/plugin.proto - public static partial class PluginReflection { - - #region Descriptor - /// File descriptor for google/protobuf/compiler/plugin.proto - public static pbr::FileDescriptor Descriptor { - get { return descriptor; } - } - private static pbr::FileDescriptor descriptor; - - static PluginReflection() { - byte[] descriptorData = global::System.Convert.FromBase64String( - string.Concat( - "CiVnb29nbGUvcHJvdG9idWYvY29tcGlsZXIvcGx1Z2luLnByb3RvEhhnb29n", - "bGUucHJvdG9idWYuY29tcGlsZXIaIGdvb2dsZS9wcm90b2J1Zi9kZXNjcmlw", - "dG9yLnByb3RvIkYKB1ZlcnNpb24SDQoFbWFqb3IYASABKAUSDQoFbWlub3IY", - "AiABKAUSDQoFcGF0Y2gYAyABKAUSDgoGc3VmZml4GAQgASgJIroBChRDb2Rl", - "R2VuZXJhdG9yUmVxdWVzdBIYChBmaWxlX3RvX2dlbmVyYXRlGAEgAygJEhEK", - "CXBhcmFtZXRlchgCIAEoCRI4Cgpwcm90b19maWxlGA8gAygLMiQuZ29vZ2xl", - "LnByb3RvYnVmLkZpbGVEZXNjcmlwdG9yUHJvdG8SOwoQY29tcGlsZXJfdmVy", - "c2lvbhgDIAEoCzIhLmdvb2dsZS5wcm90b2J1Zi5jb21waWxlci5WZXJzaW9u", - "IsECChVDb2RlR2VuZXJhdG9yUmVzcG9uc2USDQoFZXJyb3IYASABKAkSGgoS", - "c3VwcG9ydGVkX2ZlYXR1cmVzGAIgASgEEkIKBGZpbGUYDyADKAsyNC5nb29n", - "bGUucHJvdG9idWYuY29tcGlsZXIuQ29kZUdlbmVyYXRvclJlc3BvbnNlLkZp", - "bGUafwoERmlsZRIMCgRuYW1lGAEgASgJEhcKD2luc2VydGlvbl9wb2ludBgC", - "IAEoCRIPCgdjb250ZW50GA8gASgJEj8KE2dlbmVyYXRlZF9jb2RlX2luZm8Y", - "ECABKAsyIi5nb29nbGUucHJvdG9idWYuR2VuZXJhdGVkQ29kZUluZm8iOAoH", - "RmVhdHVyZRIQCgxGRUFUVVJFX05PTkUQABIbChdGRUFUVVJFX1BST1RPM19P", - "UFRJT05BTBABQlcKHGNvbS5nb29nbGUucHJvdG9idWYuY29tcGlsZXJCDFBs", - "dWdpblByb3Rvc1opZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMv", - "cGx1Z2lucGI=")); - descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor, }, - new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Compiler.Version), global::Google.Protobuf.Compiler.Version.Parser, new[]{ "Major", "Minor", "Patch", "Suffix" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Compiler.CodeGeneratorRequest), global::Google.Protobuf.Compiler.CodeGeneratorRequest.Parser, new[]{ "FileToGenerate", "Parameter", "ProtoFile", "CompilerVersion" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Compiler.CodeGeneratorResponse), global::Google.Protobuf.Compiler.CodeGeneratorResponse.Parser, new[]{ "Error", "SupportedFeatures", "File" }, null, new[]{ typeof(global::Google.Protobuf.Compiler.CodeGeneratorResponse.Types.Feature) }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Compiler.CodeGeneratorResponse.Types.File), global::Google.Protobuf.Compiler.CodeGeneratorResponse.Types.File.Parser, new[]{ "Name", "InsertionPoint", "Content", "GeneratedCodeInfo" }, null, null, null, null)}) - })); - } - #endregion - - } - #region Messages - /// - /// The version number of protocol compiler. - /// - public sealed partial class Version : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Version()); - private pb::UnknownFieldSet _unknownFields; - private int _hasBits0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.Compiler.PluginReflection.Descriptor.MessageTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public Version() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public Version(Version other) : this() { - _hasBits0 = other._hasBits0; - major_ = other.major_; - minor_ = other.minor_; - patch_ = other.patch_; - suffix_ = other.suffix_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public Version Clone() { - return new Version(this); - } - - /// Field number for the "major" field. - public const int MajorFieldNumber = 1; - private readonly static int MajorDefaultValue = 0; - - private int major_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Major { - get { if ((_hasBits0 & 1) != 0) { return major_; } else { return MajorDefaultValue; } } - set { - _hasBits0 |= 1; - major_ = value; - } - } - /// Gets whether the "major" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasMajor { - get { return (_hasBits0 & 1) != 0; } - } - /// Clears the value of the "major" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearMajor() { - _hasBits0 &= ~1; - } - - /// Field number for the "minor" field. - public const int MinorFieldNumber = 2; - private readonly static int MinorDefaultValue = 0; - - private int minor_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Minor { - get { if ((_hasBits0 & 2) != 0) { return minor_; } else { return MinorDefaultValue; } } - set { - _hasBits0 |= 2; - minor_ = value; - } - } - /// Gets whether the "minor" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasMinor { - get { return (_hasBits0 & 2) != 0; } - } - /// Clears the value of the "minor" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearMinor() { - _hasBits0 &= ~2; - } - - /// Field number for the "patch" field. - public const int PatchFieldNumber = 3; - private readonly static int PatchDefaultValue = 0; - - private int patch_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int Patch { - get { if ((_hasBits0 & 4) != 0) { return patch_; } else { return PatchDefaultValue; } } - set { - _hasBits0 |= 4; - patch_ = value; - } - } - /// Gets whether the "patch" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasPatch { - get { return (_hasBits0 & 4) != 0; } - } - /// Clears the value of the "patch" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearPatch() { - _hasBits0 &= ~4; - } - - /// Field number for the "suffix" field. - public const int SuffixFieldNumber = 4; - private readonly static string SuffixDefaultValue = ""; - - private string suffix_; - /// - /// A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should - /// be empty for mainline stable releases. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Suffix { - get { return suffix_ ?? SuffixDefaultValue; } - set { - suffix_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "suffix" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasSuffix { - get { return suffix_ != null; } - } - /// Clears the value of the "suffix" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearSuffix() { - suffix_ = null; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as Version); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(Version other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (Major != other.Major) return false; - if (Minor != other.Minor) return false; - if (Patch != other.Patch) return false; - if (Suffix != other.Suffix) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (HasMajor) hash ^= Major.GetHashCode(); - if (HasMinor) hash ^= Minor.GetHashCode(); - if (HasPatch) hash ^= Patch.GetHashCode(); - if (HasSuffix) hash ^= Suffix.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (HasMajor) { - output.WriteRawTag(8); - output.WriteInt32(Major); - } - if (HasMinor) { - output.WriteRawTag(16); - output.WriteInt32(Minor); - } - if (HasPatch) { - output.WriteRawTag(24); - output.WriteInt32(Patch); - } - if (HasSuffix) { - output.WriteRawTag(34); - output.WriteString(Suffix); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (HasMajor) { - output.WriteRawTag(8); - output.WriteInt32(Major); - } - if (HasMinor) { - output.WriteRawTag(16); - output.WriteInt32(Minor); - } - if (HasPatch) { - output.WriteRawTag(24); - output.WriteInt32(Patch); - } - if (HasSuffix) { - output.WriteRawTag(34); - output.WriteString(Suffix); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (HasMajor) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Major); - } - if (HasMinor) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Minor); - } - if (HasPatch) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Patch); - } - if (HasSuffix) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Suffix); - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(Version other) { - if (other == null) { - return; - } - if (other.HasMajor) { - Major = other.Major; - } - if (other.HasMinor) { - Minor = other.Minor; - } - if (other.HasPatch) { - Patch = other.Patch; - } - if (other.HasSuffix) { - Suffix = other.Suffix; - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 8: { - Major = input.ReadInt32(); - break; - } - case 16: { - Minor = input.ReadInt32(); - break; - } - case 24: { - Patch = input.ReadInt32(); - break; - } - case 34: { - Suffix = input.ReadString(); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 8: { - Major = input.ReadInt32(); - break; - } - case 16: { - Minor = input.ReadInt32(); - break; - } - case 24: { - Patch = input.ReadInt32(); - break; - } - case 34: { - Suffix = input.ReadString(); - break; - } - } - } - } - #endif - - } - - /// - /// An encoded CodeGeneratorRequest is written to the plugin's stdin. - /// - public sealed partial class CodeGeneratorRequest : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CodeGeneratorRequest()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.Compiler.PluginReflection.Descriptor.MessageTypes[1]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorRequest() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorRequest(CodeGeneratorRequest other) : this() { - fileToGenerate_ = other.fileToGenerate_.Clone(); - parameter_ = other.parameter_; - protoFile_ = other.protoFile_.Clone(); - compilerVersion_ = other.compilerVersion_ != null ? other.compilerVersion_.Clone() : null; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorRequest Clone() { - return new CodeGeneratorRequest(this); - } - - /// Field number for the "file_to_generate" field. - public const int FileToGenerateFieldNumber = 1; - private static readonly pb::FieldCodec _repeated_fileToGenerate_codec - = pb::FieldCodec.ForString(10); - private readonly pbc::RepeatedField fileToGenerate_ = new pbc::RepeatedField(); - /// - /// The .proto files that were explicitly listed on the command-line. The - /// code generator should generate code only for these files. Each file's - /// descriptor will be included in proto_file, below. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField FileToGenerate { - get { return fileToGenerate_; } - } - - /// Field number for the "parameter" field. - public const int ParameterFieldNumber = 2; - private readonly static string ParameterDefaultValue = ""; - - private string parameter_; - /// - /// The generator parameter passed on the command-line. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Parameter { - get { return parameter_ ?? ParameterDefaultValue; } - set { - parameter_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "parameter" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasParameter { - get { return parameter_ != null; } - } - /// Clears the value of the "parameter" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearParameter() { - parameter_ = null; - } - - /// Field number for the "proto_file" field. - public const int ProtoFileFieldNumber = 15; - private static readonly pb::FieldCodec _repeated_protoFile_codec - = pb::FieldCodec.ForMessage(122, global::Google.Protobuf.Reflection.FileDescriptorProto.Parser); - private readonly pbc::RepeatedField protoFile_ = new pbc::RepeatedField(); - /// - /// FileDescriptorProtos for all files in files_to_generate and everything - /// they import. The files will appear in topological order, so each file - /// appears before any file that imports it. - /// - /// protoc guarantees that all proto_files will be written after - /// the fields above, even though this is not technically guaranteed by the - /// protobuf wire format. This theoretically could allow a plugin to stream - /// in the FileDescriptorProtos and handle them one by one rather than read - /// the entire set into memory at once. However, as of this writing, this - /// is not similarly optimized on protoc's end -- it will store all fields in - /// memory at once before sending them to the plugin. - /// - /// Type names of fields and extensions in the FileDescriptorProto are always - /// fully qualified. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField ProtoFile { - get { return protoFile_; } - } - - /// Field number for the "compiler_version" field. - public const int CompilerVersionFieldNumber = 3; - private global::Google.Protobuf.Compiler.Version compilerVersion_; - /// - /// The version number of protocol compiler. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public global::Google.Protobuf.Compiler.Version CompilerVersion { - get { return compilerVersion_; } - set { - compilerVersion_ = value; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as CodeGeneratorRequest); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(CodeGeneratorRequest other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if(!fileToGenerate_.Equals(other.fileToGenerate_)) return false; - if (Parameter != other.Parameter) return false; - if(!protoFile_.Equals(other.protoFile_)) return false; - if (!object.Equals(CompilerVersion, other.CompilerVersion)) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - hash ^= fileToGenerate_.GetHashCode(); - if (HasParameter) hash ^= Parameter.GetHashCode(); - hash ^= protoFile_.GetHashCode(); - if (compilerVersion_ != null) hash ^= CompilerVersion.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - fileToGenerate_.WriteTo(output, _repeated_fileToGenerate_codec); - if (HasParameter) { - output.WriteRawTag(18); - output.WriteString(Parameter); - } - if (compilerVersion_ != null) { - output.WriteRawTag(26); - output.WriteMessage(CompilerVersion); - } - protoFile_.WriteTo(output, _repeated_protoFile_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - fileToGenerate_.WriteTo(ref output, _repeated_fileToGenerate_codec); - if (HasParameter) { - output.WriteRawTag(18); - output.WriteString(Parameter); - } - if (compilerVersion_ != null) { - output.WriteRawTag(26); - output.WriteMessage(CompilerVersion); - } - protoFile_.WriteTo(ref output, _repeated_protoFile_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - size += fileToGenerate_.CalculateSize(_repeated_fileToGenerate_codec); - if (HasParameter) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Parameter); - } - size += protoFile_.CalculateSize(_repeated_protoFile_codec); - if (compilerVersion_ != null) { - size += 1 + pb::CodedOutputStream.ComputeMessageSize(CompilerVersion); - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(CodeGeneratorRequest other) { - if (other == null) { - return; - } - fileToGenerate_.Add(other.fileToGenerate_); - if (other.HasParameter) { - Parameter = other.Parameter; - } - protoFile_.Add(other.protoFile_); - if (other.compilerVersion_ != null) { - if (compilerVersion_ == null) { - CompilerVersion = new global::Google.Protobuf.Compiler.Version(); - } - CompilerVersion.MergeFrom(other.CompilerVersion); - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 10: { - fileToGenerate_.AddEntriesFrom(input, _repeated_fileToGenerate_codec); - break; - } - case 18: { - Parameter = input.ReadString(); - break; - } - case 26: { - if (compilerVersion_ == null) { - CompilerVersion = new global::Google.Protobuf.Compiler.Version(); - } - input.ReadMessage(CompilerVersion); - break; - } - case 122: { - protoFile_.AddEntriesFrom(input, _repeated_protoFile_codec); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 10: { - fileToGenerate_.AddEntriesFrom(ref input, _repeated_fileToGenerate_codec); - break; - } - case 18: { - Parameter = input.ReadString(); - break; - } - case 26: { - if (compilerVersion_ == null) { - CompilerVersion = new global::Google.Protobuf.Compiler.Version(); - } - input.ReadMessage(CompilerVersion); - break; - } - case 122: { - protoFile_.AddEntriesFrom(ref input, _repeated_protoFile_codec); - break; - } - } - } - } - #endif - - } - - /// - /// The plugin writes an encoded CodeGeneratorResponse to stdout. - /// - public sealed partial class CodeGeneratorResponse : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CodeGeneratorResponse()); - private pb::UnknownFieldSet _unknownFields; - private int _hasBits0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.Compiler.PluginReflection.Descriptor.MessageTypes[2]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorResponse() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorResponse(CodeGeneratorResponse other) : this() { - _hasBits0 = other._hasBits0; - error_ = other.error_; - supportedFeatures_ = other.supportedFeatures_; - file_ = other.file_.Clone(); - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public CodeGeneratorResponse Clone() { - return new CodeGeneratorResponse(this); - } - - /// Field number for the "error" field. - public const int ErrorFieldNumber = 1; - private readonly static string ErrorDefaultValue = ""; - - private string error_; - /// - /// Error message. If non-empty, code generation failed. The plugin process - /// should exit with status code zero even if it reports an error in this way. - /// - /// This should be used to indicate errors in .proto files which prevent the - /// code generator from generating correct code. Errors which indicate a - /// problem in protoc itself -- such as the input CodeGeneratorRequest being - /// unparseable -- should be reported by writing a message to stderr and - /// exiting with a non-zero status code. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Error { - get { return error_ ?? ErrorDefaultValue; } - set { - error_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "error" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasError { - get { return error_ != null; } - } - /// Clears the value of the "error" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearError() { - error_ = null; - } - - /// Field number for the "supported_features" field. - public const int SupportedFeaturesFieldNumber = 2; - private readonly static ulong SupportedFeaturesDefaultValue = 0UL; - - private ulong supportedFeatures_; - /// - /// A bitmask of supported features that the code generator supports. - /// This is a bitwise "or" of values from the Feature enum. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ulong SupportedFeatures { - get { if ((_hasBits0 & 1) != 0) { return supportedFeatures_; } else { return SupportedFeaturesDefaultValue; } } - set { - _hasBits0 |= 1; - supportedFeatures_ = value; - } - } - /// Gets whether the "supported_features" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasSupportedFeatures { - get { return (_hasBits0 & 1) != 0; } - } - /// Clears the value of the "supported_features" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearSupportedFeatures() { - _hasBits0 &= ~1; - } - - /// Field number for the "file" field. - public const int FileFieldNumber = 15; - private static readonly pb::FieldCodec _repeated_file_codec - = pb::FieldCodec.ForMessage(122, global::Google.Protobuf.Compiler.CodeGeneratorResponse.Types.File.Parser); - private readonly pbc::RepeatedField file_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField File { - get { return file_; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as CodeGeneratorResponse); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(CodeGeneratorResponse other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (Error != other.Error) return false; - if (SupportedFeatures != other.SupportedFeatures) return false; - if(!file_.Equals(other.file_)) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (HasError) hash ^= Error.GetHashCode(); - if (HasSupportedFeatures) hash ^= SupportedFeatures.GetHashCode(); - hash ^= file_.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (HasError) { - output.WriteRawTag(10); - output.WriteString(Error); - } - if (HasSupportedFeatures) { - output.WriteRawTag(16); - output.WriteUInt64(SupportedFeatures); - } - file_.WriteTo(output, _repeated_file_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (HasError) { - output.WriteRawTag(10); - output.WriteString(Error); - } - if (HasSupportedFeatures) { - output.WriteRawTag(16); - output.WriteUInt64(SupportedFeatures); - } - file_.WriteTo(ref output, _repeated_file_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (HasError) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Error); - } - if (HasSupportedFeatures) { - size += 1 + pb::CodedOutputStream.ComputeUInt64Size(SupportedFeatures); - } - size += file_.CalculateSize(_repeated_file_codec); - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(CodeGeneratorResponse other) { - if (other == null) { - return; - } - if (other.HasError) { - Error = other.Error; - } - if (other.HasSupportedFeatures) { - SupportedFeatures = other.SupportedFeatures; - } - file_.Add(other.file_); - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 10: { - Error = input.ReadString(); - break; - } - case 16: { - SupportedFeatures = input.ReadUInt64(); - break; - } - case 122: { - file_.AddEntriesFrom(input, _repeated_file_codec); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 10: { - Error = input.ReadString(); - break; - } - case 16: { - SupportedFeatures = input.ReadUInt64(); - break; - } - case 122: { - file_.AddEntriesFrom(ref input, _repeated_file_codec); - break; - } - } - } - } - #endif - - #region Nested types - /// Container for nested types declared in the CodeGeneratorResponse message type. - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static partial class Types { - /// - /// Sync with code_generator.h. - /// - public enum Feature { - [pbr::OriginalName("FEATURE_NONE")] None = 0, - [pbr::OriginalName("FEATURE_PROTO3_OPTIONAL")] Proto3Optional = 1, - } - - /// - /// Represents a single generated file. - /// - public sealed partial class File : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new File()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.Compiler.CodeGeneratorResponse.Descriptor.NestedTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public File() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public File(File other) : this() { - name_ = other.name_; - insertionPoint_ = other.insertionPoint_; - content_ = other.content_; - generatedCodeInfo_ = other.generatedCodeInfo_ != null ? other.generatedCodeInfo_.Clone() : null; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public File Clone() { - return new File(this); - } - - /// Field number for the "name" field. - public const int NameFieldNumber = 1; - private readonly static string NameDefaultValue = ""; - - private string name_; - /// - /// The file name, relative to the output directory. The name must not - /// contain "." or ".." components and must be relative, not be absolute (so, - /// the file cannot lie outside the output directory). "/" must be used as - /// the path separator, not "\". - /// - /// If the name is omitted, the content will be appended to the previous - /// file. This allows the generator to break large files into small chunks, - /// and allows the generated text to be streamed back to protoc so that large - /// files need not reside completely in memory at one time. Note that as of - /// this writing protoc does not optimize for this -- it will read the entire - /// CodeGeneratorResponse before writing files to disk. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Name { - get { return name_ ?? NameDefaultValue; } - set { - name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "name" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasName { - get { return name_ != null; } - } - /// Clears the value of the "name" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearName() { - name_ = null; - } - - /// Field number for the "insertion_point" field. - public const int InsertionPointFieldNumber = 2; - private readonly static string InsertionPointDefaultValue = ""; - - private string insertionPoint_; - /// - /// If non-empty, indicates that the named file should already exist, and the - /// content here is to be inserted into that file at a defined insertion - /// point. This feature allows a code generator to extend the output - /// produced by another code generator. The original generator may provide - /// insertion points by placing special annotations in the file that look - /// like: - /// @@protoc_insertion_point(NAME) - /// The annotation can have arbitrary text before and after it on the line, - /// which allows it to be placed in a comment. NAME should be replaced with - /// an identifier naming the point -- this is what other generators will use - /// as the insertion_point. Code inserted at this point will be placed - /// immediately above the line containing the insertion point (thus multiple - /// insertions to the same point will come out in the order they were added). - /// The double-@ is intended to make it unlikely that the generated code - /// could contain things that look like insertion points by accident. - /// - /// For example, the C++ code generator places the following line in the - /// .pb.h files that it generates: - /// // @@protoc_insertion_point(namespace_scope) - /// This line appears within the scope of the file's package namespace, but - /// outside of any particular class. Another plugin can then specify the - /// insertion_point "namespace_scope" to generate additional classes or - /// other declarations that should be placed in this scope. - /// - /// Note that if the line containing the insertion point begins with - /// whitespace, the same whitespace will be added to every line of the - /// inserted text. This is useful for languages like Python, where - /// indentation matters. In these languages, the insertion point comment - /// should be indented the same amount as any inserted code will need to be - /// in order to work correctly in that context. - /// - /// The code generator that generates the initial file and the one which - /// inserts into it must both run as part of a single invocation of protoc. - /// Code generators are executed in the order in which they appear on the - /// command line. - /// - /// If |insertion_point| is present, |name| must also be present. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string InsertionPoint { - get { return insertionPoint_ ?? InsertionPointDefaultValue; } - set { - insertionPoint_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "insertion_point" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasInsertionPoint { - get { return insertionPoint_ != null; } - } - /// Clears the value of the "insertion_point" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearInsertionPoint() { - insertionPoint_ = null; - } - - /// Field number for the "content" field. - public const int ContentFieldNumber = 15; - private readonly static string ContentDefaultValue = ""; - - private string content_; - /// - /// The file contents. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Content { - get { return content_ ?? ContentDefaultValue; } - set { - content_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "content" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasContent { - get { return content_ != null; } - } - /// Clears the value of the "content" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearContent() { - content_ = null; - } - - /// Field number for the "generated_code_info" field. - public const int GeneratedCodeInfoFieldNumber = 16; - private global::Google.Protobuf.Reflection.GeneratedCodeInfo generatedCodeInfo_; - /// - /// Information describing the file content being inserted. If an insertion - /// point is used, this information will be appropriately offset and inserted - /// into the code generation metadata for the generated files. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public global::Google.Protobuf.Reflection.GeneratedCodeInfo GeneratedCodeInfo { - get { return generatedCodeInfo_; } - set { - generatedCodeInfo_ = value; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as File); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(File other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (Name != other.Name) return false; - if (InsertionPoint != other.InsertionPoint) return false; - if (Content != other.Content) return false; - if (!object.Equals(GeneratedCodeInfo, other.GeneratedCodeInfo)) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (HasName) hash ^= Name.GetHashCode(); - if (HasInsertionPoint) hash ^= InsertionPoint.GetHashCode(); - if (HasContent) hash ^= Content.GetHashCode(); - if (generatedCodeInfo_ != null) hash ^= GeneratedCodeInfo.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (HasName) { - output.WriteRawTag(10); - output.WriteString(Name); - } - if (HasInsertionPoint) { - output.WriteRawTag(18); - output.WriteString(InsertionPoint); - } - if (HasContent) { - output.WriteRawTag(122); - output.WriteString(Content); - } - if (generatedCodeInfo_ != null) { - output.WriteRawTag(130, 1); - output.WriteMessage(GeneratedCodeInfo); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (HasName) { - output.WriteRawTag(10); - output.WriteString(Name); - } - if (HasInsertionPoint) { - output.WriteRawTag(18); - output.WriteString(InsertionPoint); - } - if (HasContent) { - output.WriteRawTag(122); - output.WriteString(Content); - } - if (generatedCodeInfo_ != null) { - output.WriteRawTag(130, 1); - output.WriteMessage(GeneratedCodeInfo); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (HasName) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); - } - if (HasInsertionPoint) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(InsertionPoint); - } - if (HasContent) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Content); - } - if (generatedCodeInfo_ != null) { - size += 2 + pb::CodedOutputStream.ComputeMessageSize(GeneratedCodeInfo); - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(File other) { - if (other == null) { - return; - } - if (other.HasName) { - Name = other.Name; - } - if (other.HasInsertionPoint) { - InsertionPoint = other.InsertionPoint; - } - if (other.HasContent) { - Content = other.Content; - } - if (other.generatedCodeInfo_ != null) { - if (generatedCodeInfo_ == null) { - GeneratedCodeInfo = new global::Google.Protobuf.Reflection.GeneratedCodeInfo(); - } - GeneratedCodeInfo.MergeFrom(other.GeneratedCodeInfo); - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 10: { - Name = input.ReadString(); - break; - } - case 18: { - InsertionPoint = input.ReadString(); - break; - } - case 122: { - Content = input.ReadString(); - break; - } - case 130: { - if (generatedCodeInfo_ == null) { - GeneratedCodeInfo = new global::Google.Protobuf.Reflection.GeneratedCodeInfo(); - } - input.ReadMessage(GeneratedCodeInfo); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 10: { - Name = input.ReadString(); - break; - } - case 18: { - InsertionPoint = input.ReadString(); - break; - } - case 122: { - Content = input.ReadString(); - break; - } - case 130: { - if (generatedCodeInfo_ == null) { - GeneratedCodeInfo = new global::Google.Protobuf.Reflection.GeneratedCodeInfo(); - } - input.ReadMessage(GeneratedCodeInfo); - break; - } - } - } - } - #endif - - } - - } - #endregion - - } - - #endregion - -} - -#endregion Designer generated code diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Extension.cs b/libs/protobuf/csharp/src/Google.Protobuf/Extension.cs index 2807260..d10a668 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Extension.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Extension.cs @@ -77,7 +77,7 @@ namespace Google.Protobuf this.codec = codec; } - internal TValue DefaultValue => codec != null ? codec.DefaultValue : default; + internal TValue DefaultValue => codec != null ? codec.DefaultValue : default(TValue); internal override Type TargetType => typeof(TTarget); diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionRegistry.cs b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionRegistry.cs index be381f0..e72314b 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionRegistry.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionRegistry.cs @@ -55,7 +55,7 @@ namespace Google.Protobuf internal static ExtensionComparer Instance = new ExtensionComparer(); } - private readonly IDictionary, Extension> extensions; + private IDictionary, Extension> extensions; /// /// Creates a new empty extension registry diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionSet.cs b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionSet.cs index aa1acbd..306e45e 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionSet.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionSet.cs @@ -61,7 +61,8 @@ namespace Google.Protobuf /// public static TValue Get(ref ExtensionSet set, Extension extension) where TTarget : IExtendableMessage { - if (TryGetValue(ref set, extension, out IExtensionValue value)) + IExtensionValue value; + if (TryGetValue(ref set, extension, out value)) { // The stored ExtensionValue can be a different type to what is being requested. // This happens when the same extension proto is compiled in different assemblies. @@ -97,7 +98,7 @@ namespace Google.Protobuf } } } - else + else { return extension.DefaultValue; } @@ -108,7 +109,8 @@ namespace Google.Protobuf /// public static RepeatedField Get(ref ExtensionSet set, RepeatedExtension extension) where TTarget : IExtendableMessage { - if (TryGetValue(ref set, extension, out IExtensionValue value)) + IExtensionValue value; + if (TryGetValue(ref set, extension, out value)) { if (value is RepeatedExtensionValue extensionValue) { @@ -130,7 +132,7 @@ namespace Google.Protobuf } } } - else + else { return null; } @@ -191,7 +193,8 @@ namespace Google.Protobuf /// public static bool Has(ref ExtensionSet set, Extension extension) where TTarget : IExtendableMessage { - return TryGetValue(ref set, extension, out IExtensionValue _); + IExtensionValue value; + return TryGetValue(ref set, extension, out value); } /// @@ -249,18 +252,20 @@ namespace Google.Protobuf /// public static bool TryMergeFieldFrom(ref ExtensionSet set, ref ParseContext ctx) where TTarget : IExtendableMessage { + Extension extension; int lastFieldNumber = WireFormat.GetTagFieldNumber(ctx.LastTag); - if (set != null && set.ValuesByNumber.TryGetValue(lastFieldNumber, out IExtensionValue extensionValue)) + IExtensionValue extensionValue; + if (set != null && set.ValuesByNumber.TryGetValue(lastFieldNumber, out extensionValue)) { extensionValue.MergeFrom(ref ctx); return true; } - else if (ctx.ExtensionRegistry != null && ctx.ExtensionRegistry.ContainsInputField(ctx.LastTag, typeof(TTarget), out Extension extension)) + else if (ctx.ExtensionRegistry != null && ctx.ExtensionRegistry.ContainsInputField(ctx.LastTag, typeof(TTarget), out extension)) { IExtensionValue value = extension.CreateValue(); value.MergeFrom(ref ctx); - set ??= new ExtensionSet(); + set = (set ?? new ExtensionSet()); set.ValuesByNumber.Add(extension.FieldNumber, value); return true; } @@ -285,7 +290,8 @@ namespace Google.Protobuf } foreach (var pair in second.ValuesByNumber) { - if (first.ValuesByNumber.TryGetValue(pair.Key, out IExtensionValue value)) + IExtensionValue value; + if (first.ValuesByNumber.TryGetValue(pair.Key, out value)) { value.MergeFrom(pair.Value); } @@ -359,7 +365,8 @@ namespace Google.Protobuf } foreach (var pair in ValuesByNumber) { - if (!otherSet.ValuesByNumber.TryGetValue(pair.Key, out IExtensionValue secondValue)) + IExtensionValue secondValue; + if (!otherSet.ValuesByNumber.TryGetValue(pair.Key, out secondValue)) { return false; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionValue.cs b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionValue.cs index 9637f1b..1329b2f 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ExtensionValue.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ExtensionValue.cs @@ -32,6 +32,7 @@ using Google.Protobuf.Collections; using System; +using System.Linq; namespace Google.Protobuf { @@ -49,7 +50,7 @@ namespace Google.Protobuf internal sealed class ExtensionValue : IExtensionValue { private T field; - private readonly FieldCodec codec; + private FieldCodec codec; internal ExtensionValue(FieldCodec codec) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs b/libs/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs index d3b0b71..ee6bd6a 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs @@ -31,6 +31,7 @@ #endregion using Google.Protobuf.Collections; +using Google.Protobuf.Compatibility; using Google.Protobuf.WellKnownTypes; using System; using System.Collections.Generic; @@ -50,105 +51,150 @@ namespace Google.Protobuf /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForString(uint tag) => ForString(tag, ""); + public static FieldCodec ForString(uint tag) + { + return FieldCodec.ForString(tag, ""); + } /// /// Retrieves a codec suitable for a bytes field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForBytes(uint tag) => ForBytes(tag, ByteString.Empty); + public static FieldCodec ForBytes(uint tag) + { + return FieldCodec.ForBytes(tag, ByteString.Empty); + } /// /// Retrieves a codec suitable for a bool field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForBool(uint tag) => ForBool(tag, false); + public static FieldCodec ForBool(uint tag) + { + return FieldCodec.ForBool(tag, false); + } /// /// Retrieves a codec suitable for an int32 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForInt32(uint tag) => ForInt32(tag, 0); + public static FieldCodec ForInt32(uint tag) + { + return FieldCodec.ForInt32(tag, 0); + } /// /// Retrieves a codec suitable for an sint32 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForSInt32(uint tag) => ForSInt32(tag, 0); + public static FieldCodec ForSInt32(uint tag) + { + return FieldCodec.ForSInt32(tag, 0); + } /// /// Retrieves a codec suitable for a fixed32 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForFixed32(uint tag) => ForFixed32(tag, 0); + public static FieldCodec ForFixed32(uint tag) + { + return FieldCodec.ForFixed32(tag, 0); + } /// /// Retrieves a codec suitable for an sfixed32 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForSFixed32(uint tag) => ForSFixed32(tag, 0); + public static FieldCodec ForSFixed32(uint tag) + { + return FieldCodec.ForSFixed32(tag, 0); + } /// /// Retrieves a codec suitable for a uint32 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForUInt32(uint tag) => ForUInt32(tag, 0); + public static FieldCodec ForUInt32(uint tag) + { + return FieldCodec.ForUInt32(tag, 0); + } /// /// Retrieves a codec suitable for an int64 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForInt64(uint tag) => ForInt64(tag, 0); + public static FieldCodec ForInt64(uint tag) + { + return FieldCodec.ForInt64(tag, 0); + } /// /// Retrieves a codec suitable for an sint64 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForSInt64(uint tag) => ForSInt64(tag, 0); + public static FieldCodec ForSInt64(uint tag) + { + return FieldCodec.ForSInt64(tag, 0); + } /// /// Retrieves a codec suitable for a fixed64 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForFixed64(uint tag) => ForFixed64(tag, 0); + public static FieldCodec ForFixed64(uint tag) + { + return FieldCodec.ForFixed64(tag, 0); + } /// /// Retrieves a codec suitable for an sfixed64 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForSFixed64(uint tag) => ForSFixed64(tag, 0); + public static FieldCodec ForSFixed64(uint tag) + { + return FieldCodec.ForSFixed64(tag, 0); + } /// /// Retrieves a codec suitable for a uint64 field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForUInt64(uint tag) => ForUInt64(tag, 0); + public static FieldCodec ForUInt64(uint tag) + { + return FieldCodec.ForUInt64(tag, 0); + } /// /// Retrieves a codec suitable for a float field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForFloat(uint tag) => ForFloat(tag, 0); + public static FieldCodec ForFloat(uint tag) + { + return FieldCodec.ForFloat(tag, 0); + } /// /// Retrieves a codec suitable for a double field with the given tag. /// /// The tag. /// A codec for the given tag. - public static FieldCodec ForDouble(uint tag) => ForDouble(tag, 0); + public static FieldCodec ForDouble(uint tag) + { + return FieldCodec.ForDouble(tag, 0); + } // Enums are tricky. We can probably use expression trees to build these delegates automatically, // but it's easy to generate the code for it. @@ -160,8 +206,10 @@ namespace Google.Protobuf /// A conversion function from to the enum type. /// A conversion function from the enum type to . /// A codec for the given tag. - public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32) => - ForEnum(tag, toInt32, fromInt32, default); + public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32) + { + return FieldCodec.ForEnum(tag, toInt32, fromInt32, default(T)); + } /// /// Retrieves a codec suitable for a string field with the given tag. @@ -517,7 +565,8 @@ namespace Google.Protobuf /// internal static FieldCodec GetCodec() { - if (!Codecs.TryGetValue(typeof(T), out object value)) + object value; + if (!Codecs.TryGetValue(typeof(T), out value)) { throw new InvalidOperationException("Invalid type argument requested for wrapper codec: " + typeof(T)); } @@ -526,7 +575,8 @@ namespace Google.Protobuf internal static ValueReader GetReader() where T : struct { - if (!Readers.TryGetValue(typeof(T), out object value)) + object value; + if (!Readers.TryGetValue(typeof(T), out value)) { throw new InvalidOperationException("Invalid type argument requested for wrapper reader: " + typeof(T)); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/FieldMaskTree.cs b/libs/protobuf/csharp/src/Google.Protobuf/FieldMaskTree.cs index 084374f..2297e7a 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/FieldMaskTree.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/FieldMaskTree.cs @@ -120,7 +120,8 @@ namespace Google.Protobuf return this; } - if (!node.Children.TryGetValue(part, out Node childNode)) + Node childNode; + if (!node.Children.TryGetValue(part, out childNode)) { createNewBranch = true; childNode = new Node(); @@ -332,24 +333,15 @@ namespace Google.Protobuf { if (sourceField != null) { - // Well-known wrapper types are represented as nullable primitive types, so we do not "merge" them. - // Instead, any non-null value just overwrites the previous value directly. - if (field.MessageType.IsWrapperType) + var sourceByteString = ((IMessage)sourceField).ToByteString(); + var destinationValue = (IMessage)field.Accessor.GetValue(destination); + if (destinationValue != null) { - field.Accessor.SetValue(destination, sourceField); + destinationValue.MergeFrom(sourceByteString); } else { - var sourceByteString = ((IMessage)sourceField).ToByteString(); - var destinationValue = (IMessage)field.Accessor.GetValue(destination); - if (destinationValue != null) - { - destinationValue.MergeFrom(sourceByteString); - } - else - { - field.Accessor.SetValue(destination, field.MessageType.Parser.ParseFrom(sourceByteString)); - } + field.Accessor.SetValue(destination, field.MessageType.Parser.ParseFrom(sourceByteString)); } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/libs/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 9828fc5..3c42b9e 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/libs/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -1,12 +1,12 @@ - C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.21.8 - 10.0 + 3.21.12 + + 7.2 Google Inc. netstandard1.1;netstandard2.0;net45;net50 true diff --git a/libs/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs b/libs/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs index 333838b..6a3dbd6 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs @@ -136,5 +136,5 @@ namespace Google.Protobuf { return new InvalidProtocolBufferException("Message was missing required fields"); } - } +} } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs b/libs/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs index 9cecb6a..16f7c5a 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -62,13 +62,9 @@ namespace Google.Protobuf internal const string AnyTypeUrlField = "@type"; internal const string AnyDiagnosticValueField = "@value"; internal const string AnyWellKnownTypeValueField = "value"; + private const string TypeUrlPrefix = "type.googleapis.com"; private const string NameValueSeparator = ": "; - private const string ValueSeparator = ", "; - private const string MultilineValueSeparator = ","; - private const char ObjectOpenBracket = '{'; - private const char ObjectCloseBracket = '}'; - private const char ListBracketOpen = '['; - private const char ListBracketClose = ']'; + private const string PropertySeparator = ", "; /// /// Returns a formatter using the default settings. @@ -145,26 +141,11 @@ namespace Google.Protobuf /// Formats the specified message as JSON. /// /// The message to format. - /// This method delegates to Format(IMessage, int) with indentationLevel = 0. /// The formatted message. - public string Format(IMessage message) => Format(message, indentationLevel: 0); - - /// - /// Formats the specified message as JSON. - /// - /// The message to format. - /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . E.g: - /// - /// var response = $@"{{ - /// ""data"": { Format(message, indentationLevel: 1) } - /// }}" - /// - /// The formatted message. - public string Format(IMessage message, int indentationLevel) + public string Format(IMessage message) { var writer = new StringWriter(); - Format(message, writer, indentationLevel); + Format(message, writer); return writer.ToString(); } @@ -173,29 +154,19 @@ namespace Google.Protobuf /// /// The message to format. /// The TextWriter to write the formatted message to. - /// This method delegates to Format(IMessage, TextWriter, int) with indentationLevel = 0. /// The formatted message. - public void Format(IMessage message, TextWriter writer) => Format(message, writer, indentationLevel: 0); - - /// - /// Formats the specified message as JSON. When is not null, start indenting at the specified . - /// - /// The message to format. - /// The TextWriter to write the formatted message to. - /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . - public void Format(IMessage message, TextWriter writer, int indentationLevel) + public void Format(IMessage message, TextWriter writer) { ProtoPreconditions.CheckNotNull(message, nameof(message)); ProtoPreconditions.CheckNotNull(writer, nameof(writer)); if (message.Descriptor.IsWellKnownType) { - WriteWellKnownTypeValue(writer, message.Descriptor, message, indentationLevel); + WriteWellKnownTypeValue(writer, message.Descriptor, message); } else { - WriteMessage(writer, message, indentationLevel); + WriteMessage(writer, message); } } @@ -222,7 +193,7 @@ namespace Google.Protobuf return diagnosticFormatter.Format(message); } - private void WriteMessage(TextWriter writer, IMessage message, int indentationLevel) + private void WriteMessage(TextWriter writer, IMessage message) { if (message == null) { @@ -231,19 +202,19 @@ namespace Google.Protobuf } if (DiagnosticOnly) { - if (message is ICustomDiagnosticMessage customDiagnosticMessage) + ICustomDiagnosticMessage customDiagnosticMessage = message as ICustomDiagnosticMessage; + if (customDiagnosticMessage != null) { writer.Write(customDiagnosticMessage.ToDiagnosticString()); return; } } - - WriteBracketOpen(writer, ObjectOpenBracket); - bool writtenFields = WriteMessageFields(writer, message, false, indentationLevel + 1); - WriteBracketClose(writer, ObjectCloseBracket, writtenFields, indentationLevel); + writer.Write("{ "); + bool writtenFields = WriteMessageFields(writer, message, false); + writer.Write(writtenFields ? " }" : "}"); } - private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten, int indentationLevel) + private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten) { var fields = message.Descriptor.Fields; bool first = !assumeFirstFieldWritten; @@ -257,8 +228,10 @@ namespace Google.Protobuf continue; } - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel); + if (!first) + { + writer.Write(PropertySeparator); + } if (settings.PreserveProtoFieldNames) { @@ -269,23 +242,13 @@ namespace Google.Protobuf WriteString(writer, accessor.Descriptor.JsonName); } writer.Write(NameValueSeparator); - WriteValue(writer, value, indentationLevel); + WriteValue(writer, value); first = false; } return !first; } - private void MaybeWriteValueSeparator(TextWriter writer, bool first) - { - if (first) - { - return; - } - - writer.Write(settings.Indentation == null ? ValueSeparator : MultilineValueSeparator); - } - /// /// Determines whether or not a field value should be serialized according to the field, /// its value in the message, and the settings of this formatter. @@ -357,20 +320,39 @@ namespace Google.Protobuf IList list = (IList) value; return list.Count == 0; } - return descriptor.FieldType switch + switch (descriptor.FieldType) { - FieldType.Bool => (bool) value == false, - FieldType.Bytes => (ByteString) value == ByteString.Empty, - FieldType.String => (string) value == "", - FieldType.Double => (double) value == 0.0, - FieldType.SInt32 or FieldType.Int32 or FieldType.SFixed32 or FieldType.Enum => (int) value == 0, - FieldType.Fixed32 or FieldType.UInt32 => (uint) value == 0, - FieldType.Fixed64 or FieldType.UInt64 => (ulong) value == 0, - FieldType.SFixed64 or FieldType.Int64 or FieldType.SInt64 => (long) value == 0, - FieldType.Float => (float) value == 0f, - FieldType.Message or FieldType.Group => value == null, - _ => throw new ArgumentException("Invalid field type"), - }; + case FieldType.Bool: + return (bool) value == false; + case FieldType.Bytes: + return (ByteString) value == ByteString.Empty; + case FieldType.String: + return (string) value == ""; + case FieldType.Double: + return (double) value == 0.0; + case FieldType.SInt32: + case FieldType.Int32: + case FieldType.SFixed32: + case FieldType.Enum: + return (int) value == 0; + case FieldType.Fixed32: + case FieldType.UInt32: + return (uint) value == 0; + case FieldType.Fixed64: + case FieldType.UInt64: + return (ulong) value == 0; + case FieldType.SFixed64: + case FieldType.Int64: + case FieldType.SInt64: + return (long) value == 0; + case FieldType.Float: + return (float) value == 0f; + case FieldType.Message: + case FieldType.Group: // Never expect to get this, but... + return value == null; + default: + throw new ArgumentException("Invalid field type"); + } } /// @@ -381,46 +363,34 @@ namespace Google.Protobuf /// /// The writer to write the value to. Must not be null. /// The value to write. May be null. - /// Delegates to WriteValue(TextWriter, object, int) with indentationLevel = 0. - public void WriteValue(TextWriter writer, object value) => WriteValue(writer, value, 0); - - /// - /// Writes a single value to the given writer as JSON. Only types understood by - /// Protocol Buffers can be written in this way. This method is only exposed for - /// advanced use cases; most users should be using - /// or . - /// - /// The writer to write the value to. Must not be null. - /// The value to write. May be null. - /// The current indentationLevel. Not used when is null. - public void WriteValue(TextWriter writer, object value, int indentationLevel) + public void WriteValue(TextWriter writer, object value) { if (value == null || value is NullValue) { WriteNull(writer); } - else if (value is bool b) + else if (value is bool) { - writer.Write(b ? "true" : "false"); + writer.Write((bool)value ? "true" : "false"); } - else if (value is ByteString byteString) + else if (value is ByteString) { // Nothing in Base64 needs escaping writer.Write('"'); - writer.Write(byteString.ToBase64()); + writer.Write(((ByteString)value).ToBase64()); writer.Write('"'); } - else if (value is string str) + else if (value is string) { - WriteString(writer, str); + WriteString(writer, (string)value); } - else if (value is IDictionary dictionary) + else if (value is IDictionary) { - WriteDictionary(writer, dictionary, indentationLevel); + WriteDictionary(writer, (IDictionary)value); } - else if (value is IList list) + else if (value is IList) { - WriteList(writer, list, indentationLevel); + WriteList(writer, (IList)value); } else if (value is int || value is uint) { @@ -467,9 +437,9 @@ namespace Google.Protobuf writer.Write(text); } } - else if (value is IMessage message) + else if (value is IMessage) { - Format(message, writer, indentationLevel); + Format((IMessage)value, writer); } else { @@ -483,7 +453,7 @@ namespace Google.Protobuf /// values are using the embedded well-known types, in order to allow for dynamic messages /// in the future. /// - private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value, int indentationLevel) + private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value) { // Currently, we can never actually get here, because null values are always handled by the caller. But if we *could*, // this would do the right thing. @@ -499,8 +469,9 @@ namespace Google.Protobuf // WriteValue will do the right thing.) if (descriptor.IsWrapperType) { - if (value is IMessage message) + if (value is IMessage) { + var message = (IMessage) value; value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.GetValue(message); } WriteValue(writer, value); @@ -523,26 +494,26 @@ namespace Google.Protobuf } if (descriptor.FullName == Struct.Descriptor.FullName) { - WriteStruct(writer, (IMessage)value, indentationLevel); + WriteStruct(writer, (IMessage)value); return; } if (descriptor.FullName == ListValue.Descriptor.FullName) { var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor; - WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value), indentationLevel); + WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value)); return; } if (descriptor.FullName == Value.Descriptor.FullName) { - WriteStructFieldValue(writer, (IMessage)value, indentationLevel); + WriteStructFieldValue(writer, (IMessage)value); return; } if (descriptor.FullName == Any.Descriptor.FullName) { - WriteAny(writer, (IMessage)value, indentationLevel); + WriteAny(writer, (IMessage)value); return; } - WriteMessage(writer, (IMessage)value, indentationLevel); + WriteMessage(writer, (IMessage)value); } private void WriteTimestamp(TextWriter writer, IMessage value) @@ -570,7 +541,7 @@ namespace Google.Protobuf writer.Write(FieldMask.ToJson(paths, DiagnosticOnly)); } - private void WriteAny(TextWriter writer, IMessage value, int indentationLevel) + private void WriteAny(TextWriter writer, IMessage value) { if (DiagnosticOnly) { @@ -587,23 +558,23 @@ namespace Google.Protobuf throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'"); } IMessage message = descriptor.Parser.ParseFrom(data); - WriteBracketOpen(writer, ObjectOpenBracket); + writer.Write("{ "); WriteString(writer, AnyTypeUrlField); writer.Write(NameValueSeparator); WriteString(writer, typeUrl); if (descriptor.IsWellKnownType) { - writer.Write(ValueSeparator); + writer.Write(PropertySeparator); WriteString(writer, AnyWellKnownTypeValueField); writer.Write(NameValueSeparator); - WriteWellKnownTypeValue(writer, descriptor, message, indentationLevel); + WriteWellKnownTypeValue(writer, descriptor, message); } else { - WriteMessageFields(writer, message, true, indentationLevel); + WriteMessageFields(writer, message, true); } - WriteBracketClose(writer, ObjectCloseBracket, true, indentationLevel); + writer.Write(" }"); } private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value) @@ -614,7 +585,7 @@ namespace Google.Protobuf WriteString(writer, AnyTypeUrlField); writer.Write(NameValueSeparator); WriteString(writer, typeUrl); - writer.Write(ValueSeparator); + writer.Write(PropertySeparator); WriteString(writer, AnyDiagnosticValueField); writer.Write(NameValueSeparator); writer.Write('"'); @@ -623,9 +594,9 @@ namespace Google.Protobuf writer.Write(" }"); } - private void WriteStruct(TextWriter writer, IMessage message, int indentationLevel) + private void WriteStruct(TextWriter writer, IMessage message) { - WriteBracketOpen(writer, ObjectOpenBracket); + writer.Write("{ "); IDictionary fields = (IDictionary) message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue(message); bool first = true; foreach (DictionaryEntry entry in fields) @@ -637,17 +608,19 @@ namespace Google.Protobuf throw new InvalidOperationException("Struct fields cannot have an empty key or a null value."); } - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); + if (!first) + { + writer.Write(PropertySeparator); + } WriteString(writer, key); writer.Write(NameValueSeparator); - WriteStructFieldValue(writer, value, indentationLevel + 1); + WriteStructFieldValue(writer, value); first = false; } - WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); + writer.Write(first ? "}" : " }"); } - private void WriteStructFieldValue(TextWriter writer, IMessage message, int indentationLevel) + private void WriteStructFieldValue(TextWriter writer, IMessage message) { var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message); if (specifiedField == null) @@ -668,7 +641,7 @@ namespace Google.Protobuf case Value.ListValueFieldNumber: // Structs and ListValues are nested messages, and already well-known types. var nestedMessage = (IMessage) specifiedField.Accessor.GetValue(message); - WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage, indentationLevel); + WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage); return; case Value.NullValueFieldNumber: WriteNull(writer); @@ -678,40 +651,43 @@ namespace Google.Protobuf } } - internal void WriteList(TextWriter writer, IList list, int indentationLevel = 0) + internal void WriteList(TextWriter writer, IList list) { - WriteBracketOpen(writer, ListBracketOpen); - + writer.Write("[ "); bool first = true; foreach (var value in list) { - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); - WriteValue(writer, value, indentationLevel + 1); + if (!first) + { + writer.Write(PropertySeparator); + } + WriteValue(writer, value); first = false; } - - WriteBracketClose(writer, ListBracketClose, !first, indentationLevel); + writer.Write(first ? "]" : " ]"); } - internal void WriteDictionary(TextWriter writer, IDictionary dictionary, int indentationLevel = 0) + internal void WriteDictionary(TextWriter writer, IDictionary dictionary) { - WriteBracketOpen(writer, ObjectOpenBracket); - + writer.Write("{ "); bool first = true; // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal. foreach (DictionaryEntry pair in dictionary) { + if (!first) + { + writer.Write(PropertySeparator); + } string keyText; - if (pair.Key is string s) + if (pair.Key is string) { - keyText = s; + keyText = (string) pair.Key; } - else if (pair.Key is bool b) + else if (pair.Key is bool) { - keyText = b ? "true" : "false"; + keyText = (bool) pair.Key ? "true" : "false"; } - else if (pair.Key is int || pair.Key is uint || pair.Key is long || pair.Key is ulong) + else if (pair.Key is int || pair.Key is uint | pair.Key is long || pair.Key is ulong) { keyText = ((IFormattable) pair.Key).ToString("d", CultureInfo.InvariantCulture); } @@ -723,16 +699,12 @@ namespace Google.Protobuf } throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType()); } - - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); WriteString(writer, keyText); writer.Write(NameValueSeparator); WriteValue(writer, pair.Value); first = false; } - - WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); + writer.Write(first ? "}" : " }"); } /// @@ -816,49 +788,6 @@ namespace Google.Protobuf writer.Write(Hex[(c >> 0) & 0xf]); } - private void WriteBracketOpen(TextWriter writer, char openChar) - { - writer.Write(openChar); - if (settings.Indentation == null) - { - writer.Write(' '); - } - } - - private void WriteBracketClose(TextWriter writer, char closeChar, bool hasFields, int indentationLevel) - { - if (hasFields) - { - if (settings.Indentation != null) - { - writer.WriteLine(); - WriteIndentation(writer, indentationLevel); - } - else - { - writer.Write(" "); - } - } - - writer.Write(closeChar); - } - - private void MaybeWriteValueWhitespace(TextWriter writer, int indentationLevel) - { - if (settings.Indentation != null) { - writer.WriteLine(); - WriteIndentation(writer, indentationLevel); - } - } - - private void WriteIndentation(TextWriter writer, int indentationLevel) - { - for (int i = 0; i < indentationLevel; i++) - { - writer.Write(settings.Indentation); - } - } - /// /// Settings controlling JSON formatting. /// @@ -899,10 +828,6 @@ namespace Google.Protobuf /// public bool PreserveProtoFieldNames { get; } - /// - /// Indentation string, used for formatting. Setting null disables indentation. - /// - public string Indentation { get; } /// /// Creates a new object with the specified formatting of default values @@ -930,54 +855,40 @@ namespace Google.Protobuf /// The to use when formatting messages. TypeRegistry.Empty will be used if it is null. /// true to format the enums as integers; false to format enums as enum names. /// true to preserve proto field names; false to convert them to lowerCamelCase. - /// The indentation string to use for multi-line formatting. null to disable multi-line format. private Settings(bool formatDefaultValues, TypeRegistry typeRegistry, bool formatEnumsAsIntegers, - bool preserveProtoFieldNames, - string indentation = null) + bool preserveProtoFieldNames) { FormatDefaultValues = formatDefaultValues; TypeRegistry = typeRegistry ?? TypeRegistry.Empty; FormatEnumsAsIntegers = formatEnumsAsIntegers; PreserveProtoFieldNames = preserveProtoFieldNames; - Indentation = indentation; } /// /// Creates a new object with the specified formatting of default values and the current settings. /// /// true if default values (0, empty strings etc) should be formatted; false otherwise. - public Settings WithFormatDefaultValues(bool formatDefaultValues) => new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); + public Settings WithFormatDefaultValues(bool formatDefaultValues) => new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames); /// /// Creates a new object with the specified type registry and the current settings. /// /// The to use when formatting messages. - public Settings WithTypeRegistry(TypeRegistry typeRegistry) => new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); + public Settings WithTypeRegistry(TypeRegistry typeRegistry) => new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames); /// /// Creates a new object with the specified enums formatting option and the current settings. /// /// true to format the enums as integers; false to format enums as enum names. - public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); + public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers, PreserveProtoFieldNames); /// /// Creates a new object with the specified field name formatting option and the current settings. /// /// true to preserve proto field names; false to convert them to lowerCamelCase. - public Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames) => new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, preserveProtoFieldNames, Indentation); - - /// - /// Creates a new object with the specified indentation and the current settings. - /// - /// The string to output for each level of indentation (nesting). The default is two spaces per level. Use null to disable indentation entirely. - /// A non-null value for will insert additional line-breaks to the JSON output. - /// Each line will contain either a single value, or braces. The default line-break is determined by , - /// which is "\n" on Unix platforms, and "\r\n" on Windows. If seems to produce empty lines, - /// you need to pass a that uses a "\n" newline. See . - /// - public Settings WithIndentation(string indentation = " ") => new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, indentation); + public Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames) => new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, preserveProtoFieldNames); } // Effectively a cache of mapping from enum values to the original name as specified in the proto file, @@ -1005,8 +916,9 @@ namespace Google.Protobuf } } + string originalName; // If this returns false, originalName will be null, which is what we want. - nameMapping.TryGetValue(value, out string originalName); + nameMapping.TryGetValue(value, out originalName); return originalName; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/JsonParser.cs b/libs/protobuf/csharp/src/Google.Protobuf/JsonParser.cs index 6cb98d6..cb5f5a8 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/JsonParser.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/JsonParser.cs @@ -70,7 +70,8 @@ namespace Google.Protobuf // TODO: Consider introducing a class containing parse state of the parser, tokenizer and depth. That would simplify these handlers // and the signatures of various methods. - private static readonly Dictionary> WellKnownTypeHandlers = new() + private static readonly Dictionary> + WellKnownTypeHandlers = new Dictionary> { { Timestamp.Descriptor.FullName, (parser, message, tokenizer) => MergeTimestamp(message, tokenizer.Next()) }, { Duration.Descriptor.FullName, (parser, message, tokenizer) => MergeDuration(message, tokenizer.Next()) }, @@ -155,7 +156,8 @@ namespace Google.Protobuf } if (message.Descriptor.IsWellKnownType) { - if (WellKnownTypeHandlers.TryGetValue(message.Descriptor.FullName, out Action handler)) + Action handler; + if (WellKnownTypeHandlers.TryGetValue(message.Descriptor.FullName, out handler)) { handler(this, message, tokenizer); return; @@ -185,7 +187,8 @@ namespace Google.Protobuf throw new InvalidOperationException("Unexpected token type " + token.Type); } string name = token.StringValue; - if (jsonFieldMap.TryGetValue(name, out FieldDescriptor field)) + FieldDescriptor field; + if (jsonFieldMap.TryGetValue(name, out field)) { if (field.ContainingOneof != null) { @@ -300,7 +303,11 @@ namespace Google.Protobuf } object key = ParseMapKey(keyField, token.StringValue); object value = ParseSingleValue(valueField, tokenizer); - dictionary[key] = value ?? throw new InvalidProtocolBufferException("Map values must not be null"); + if (value == null) + { + throw new InvalidProtocolBufferException("Map values must not be null"); + } + dictionary[key] = value; } } @@ -642,15 +649,19 @@ namespace Google.Protobuf { return float.NaN; } - float converted = (float) value; - // If the value is out of range of float, the cast representation will be infinite. - // If the original value was infinite as well, that's fine - we'll return the 32-bit - // version (with the correct sign). - if (float.IsInfinity(converted) && !double.IsInfinity(value)) + if (value > float.MaxValue || value < float.MinValue) { + if (double.IsPositiveInfinity(value)) + { + return float.PositiveInfinity; + } + if (double.IsNegativeInfinity(value)) + { + return float.NegativeInfinity; + } throw new InvalidProtocolBufferException($"Value out of range: {value}"); } - return converted; + return (float) value; case FieldType.Enum: CheckInteger(value); // Just return it as an int, and let the CLR convert it. @@ -842,7 +853,7 @@ namespace Google.Protobuf if (secondsToAdd < 0 && nanosToAdd > 0) { secondsToAdd++; - nanosToAdd -= Duration.NanosecondsPerSecond; + nanosToAdd = nanosToAdd - Duration.NanosecondsPerSecond; } if (secondsToAdd != 0 || nanosToAdd != 0) { @@ -1038,20 +1049,23 @@ namespace Google.Protobuf /// when unknown fields are encountered. /// /// true if unknown fields should be ignored when parsing; false to throw an exception. - public Settings WithIgnoreUnknownFields(bool ignoreUnknownFields) => new(RecursionLimit, TypeRegistry, ignoreUnknownFields); + public Settings WithIgnoreUnknownFields(bool ignoreUnknownFields) => + new Settings(RecursionLimit, TypeRegistry, ignoreUnknownFields); /// /// Creates a new object based on this one, but with the specified recursion limit. /// /// The new recursion limit. - public Settings WithRecursionLimit(int recursionLimit) => new(recursionLimit, TypeRegistry, IgnoreUnknownFields); + public Settings WithRecursionLimit(int recursionLimit) => + new Settings(recursionLimit, TypeRegistry, IgnoreUnknownFields); /// /// Creates a new object based on this one, but with the specified type registry. /// /// The new type registry. Must not be null. public Settings WithTypeRegistry(TypeRegistry typeRegistry) => - new(RecursionLimit, + new Settings( + RecursionLimit, ProtoPreconditions.CheckNotNull(typeRegistry, nameof(typeRegistry)), IgnoreUnknownFields); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/JsonToken.cs b/libs/protobuf/csharp/src/Google.Protobuf/JsonToken.cs index c23a25c..6c0138c 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/JsonToken.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/JsonToken.cs @@ -36,14 +36,24 @@ namespace Google.Protobuf { internal sealed class JsonToken : IEquatable { - internal static JsonToken Null { get; } = new JsonToken(TokenType.Null); - internal static JsonToken False { get; } = new JsonToken(TokenType.False); - internal static JsonToken True { get; } = new JsonToken(TokenType.True); - internal static JsonToken StartObject { get; } = new JsonToken(TokenType.StartObject); - internal static JsonToken EndObject { get; } = new JsonToken(TokenType.EndObject); - internal static JsonToken StartArray { get; } = new JsonToken(TokenType.StartArray); - internal static JsonToken EndArray { get; } = new JsonToken(TokenType.EndArray); - internal static JsonToken EndDocument { get; } = new JsonToken(TokenType.EndDocument); + // Tokens with no value can be reused. + private static readonly JsonToken _true = new JsonToken(TokenType.True); + private static readonly JsonToken _false = new JsonToken(TokenType.False); + private static readonly JsonToken _null = new JsonToken(TokenType.Null); + private static readonly JsonToken startObject = new JsonToken(TokenType.StartObject); + private static readonly JsonToken endObject = new JsonToken(TokenType.EndObject); + private static readonly JsonToken startArray = new JsonToken(TokenType.StartArray); + private static readonly JsonToken endArray = new JsonToken(TokenType.EndArray); + private static readonly JsonToken endDocument = new JsonToken(TokenType.EndDocument); + + internal static JsonToken Null { get { return _null; } } + internal static JsonToken False { get { return _false; } } + internal static JsonToken True { get { return _true; } } + internal static JsonToken StartObject{ get { return startObject; } } + internal static JsonToken EndObject { get { return endObject; } } + internal static JsonToken StartArray { get { return startArray; } } + internal static JsonToken EndArray { get { return endArray; } } + internal static JsonToken EndDocument { get { return endDocument; } } internal static JsonToken Name(string name) { @@ -84,9 +94,9 @@ namespace Google.Protobuf private readonly string stringValue; private readonly double numberValue; - internal TokenType Type => type; - internal string StringValue => stringValue; - internal double NumberValue => numberValue; + internal TokenType Type { get { return type; } } + internal string StringValue { get { return stringValue; } } + internal double NumberValue { get { return numberValue; } } private JsonToken(TokenType type, string stringValue = null, double numberValue = 0) { @@ -95,7 +105,10 @@ namespace Google.Protobuf this.numberValue = numberValue; } - public override bool Equals(object obj) => Equals(obj as JsonToken); + public override bool Equals(object obj) + { + return Equals(obj as JsonToken); + } public override int GetHashCode() { @@ -111,26 +124,38 @@ namespace Google.Protobuf public override string ToString() { - return type switch + switch (type) { - TokenType.Null => "null", - TokenType.True => "true", - TokenType.False => "false", - TokenType.Name => $"name ({stringValue})", - TokenType.StringValue => $"value ({stringValue})", - TokenType.Number => $"number ({numberValue})", - TokenType.StartObject => "start-object", - TokenType.EndObject => "end-object", - TokenType.StartArray => "start-array", - TokenType.EndArray => "end-array", - TokenType.EndDocument => "end-document", - _ => throw new InvalidOperationException($"Token is of unknown type {type}"), - }; + case TokenType.Null: + return "null"; + case TokenType.True: + return "true"; + case TokenType.False: + return "false"; + case TokenType.Name: + return "name (" + stringValue + ")"; + case TokenType.StringValue: + return "value (" + stringValue + ")"; + case TokenType.Number: + return "number (" + numberValue + ")"; + case TokenType.StartObject: + return "start-object"; + case TokenType.EndObject: + return "end-object"; + case TokenType.StartArray: + return "start-array"; + case TokenType.EndArray: + return "end-array"; + case TokenType.EndDocument: + return "end-document"; + default: + throw new InvalidOperationException("Token is of unknown type " + type); + } } public bool Equals(JsonToken other) { - if (other is null) + if (ReferenceEquals(other, null)) { return false; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs b/libs/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs index ed54734..13a12c0 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs @@ -29,7 +29,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - using System; using System.Collections.Generic; using System.Globalization; @@ -363,19 +362,29 @@ namespace Google.Protobuf private char ReadEscapedCharacter() { char c = reader.ReadOrFail("Unexpected end of text while reading character escape sequence"); - return c switch + switch (c) { - 'n' => '\n', - '\\' => '\\', - 'b' => '\b', - 'f' => '\f', - 'r' => '\r', - 't' => '\t', - '"' => '"', - '/' => '/', - 'u' => ReadUnicodeEscape(), - _ => throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int)c)), - }; + case 'n': + return '\n'; + case '\\': + return '\\'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'r': + return '\r'; + case 't': + return '\t'; + case '"': + return '"'; + case '/': + return '/'; + case 'u': + return ReadUnicodeEscape(); + default: + throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int) c)); + } } /// @@ -489,7 +498,8 @@ namespace Google.Protobuf throw reader.CreateException("Invalid numeric literal"); } builder.Append(first); - char? next = ConsumeDigits(builder, out int digitCount); + int digitCount; + char? next = ConsumeDigits(builder, out digitCount); if (first == '0' && digitCount != 0) { throw reader.CreateException("Invalid numeric literal: leading 0 for non-zero value."); @@ -500,7 +510,8 @@ namespace Google.Protobuf private char? ReadFrac(StringBuilder builder) { builder.Append('.'); // Already consumed this - char? next = ConsumeDigits(builder, out int digitCount); + int digitCount; + char? next = ConsumeDigits(builder, out digitCount); if (digitCount == 0) { throw reader.CreateException("Invalid numeric literal: fraction with no trailing digits"); @@ -524,7 +535,8 @@ namespace Google.Protobuf { reader.PushBack(next.Value); } - next = ConsumeDigits(builder, out int digitCount); + int digitCount; + next = ConsumeDigits(builder, out digitCount); if (digitCount == 0) { throw reader.CreateException("Invalid numeric literal: exponent without value"); @@ -579,13 +591,20 @@ namespace Google.Protobuf { containerStack.Pop(); var parent = containerStack.Peek(); - state = parent switch + switch (parent) { - ContainerType.Object => State.ObjectAfterProperty, - ContainerType.Array => State.ArrayAfterValue, - ContainerType.Document => State.ExpectedEndOfDocument, - _ => throw new InvalidOperationException("Unexpected container type: " + parent), - }; + case ContainerType.Object: + state = State.ObjectAfterProperty; + break; + case ContainerType.Array: + state = State.ArrayAfterValue; + break; + case ContainerType.Document: + state = State.ExpectedEndOfDocument; + break; + default: + throw new InvalidOperationException("Unexpected container type: " + parent); + } } private enum ContainerType diff --git a/libs/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs b/libs/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs index 46d5295..50ead9c 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs @@ -51,20 +51,34 @@ namespace Google.Protobuf bytesLeft = size; } - public override bool CanRead => true; - public override bool CanSeek => false; - public override bool CanWrite => false; + public override bool CanRead + { + get { return true; } + } + + public override bool CanSeek + { + get { return false; } + } + + public override bool CanWrite + { + get { return false; } + } public override void Flush() { } - public override long Length => throw new NotSupportedException(); + public override long Length + { + get { throw new NotSupportedException(); } + } public override long Position { - get => throw new NotSupportedException(); - set => throw new NotSupportedException(); + get { throw new NotSupportedException(); } + set { throw new NotSupportedException(); } } public override int Read(byte[] buffer, int offset, int count) @@ -78,10 +92,19 @@ namespace Google.Protobuf return 0; } - public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) + { + throw new NotSupportedException(); + } - public override void SetLength(long value) => throw new NotSupportedException(); + public override void SetLength(long value) + { + throw new NotSupportedException(); + } - public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); + public override void Write(byte[] buffer, int offset, int count) + { + throw new NotSupportedException(); + } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs b/libs/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs index 22d3a2f..c4b3f82 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs @@ -107,7 +107,7 @@ namespace Google.Protobuf /// The message data as a byte array. public static byte[] ToByteArray(this IMessage message) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(message, "message"); byte[] result = new byte[message.CalculateSize()]; CodedOutputStream output = new CodedOutputStream(result); message.WriteTo(output); @@ -122,8 +122,8 @@ namespace Google.Protobuf /// The stream to write to. public static void WriteTo(this IMessage message, Stream output) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(output, nameof(output)); + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(output, "output"); CodedOutputStream codedOutput = new CodedOutputStream(output); message.WriteTo(codedOutput); codedOutput.Flush(); @@ -136,8 +136,8 @@ namespace Google.Protobuf /// The output stream to write to. public static void WriteDelimitedTo(this IMessage message, Stream output) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(output, nameof(output)); + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(output, "output"); CodedOutputStream codedOutput = new CodedOutputStream(output); codedOutput.WriteLength(message.CalculateSize()); message.WriteTo(codedOutput); @@ -151,7 +151,7 @@ namespace Google.Protobuf /// The message data as a byte string. public static ByteString ToByteString(this IMessage message) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(message, "message"); return ByteString.AttachBytes(message.ToByteArray()); } @@ -251,34 +251,30 @@ namespace Google.Protobuf // Implementations allowing unknown fields to be discarded. internal static void MergeFrom(this IMessage message, byte[] data, bool discardUnknownFields, ExtensionRegistry registry) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(data, nameof(data)); - CodedInputStream input = new CodedInputStream(data) - { - DiscardUnknownFields = discardUnknownFields, - ExtensionRegistry = registry - }; + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = new CodedInputStream(data); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; message.MergeFrom(input); input.CheckReadEndOfStreamTag(); } internal static void MergeFrom(this IMessage message, byte[] data, int offset, int length, bool discardUnknownFields, ExtensionRegistry registry) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(data, nameof(data)); - CodedInputStream input = new CodedInputStream(data, offset, length) - { - DiscardUnknownFields = discardUnknownFields, - ExtensionRegistry = registry - }; + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); + CodedInputStream input = new CodedInputStream(data, offset, length); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; message.MergeFrom(input); input.CheckReadEndOfStreamTag(); } internal static void MergeFrom(this IMessage message, ByteString data, bool discardUnknownFields, ExtensionRegistry registry) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(data, nameof(data)); + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(data, "data"); CodedInputStream input = data.CreateCodedInput(); input.DiscardUnknownFields = discardUnknownFields; input.ExtensionRegistry = registry; @@ -288,13 +284,11 @@ namespace Google.Protobuf internal static void MergeFrom(this IMessage message, Stream input, bool discardUnknownFields, ExtensionRegistry registry) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(input, nameof(input)); - CodedInputStream codedInput = new CodedInputStream(input) - { - DiscardUnknownFields = discardUnknownFields, - ExtensionRegistry = registry - }; + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(input, "input"); + CodedInputStream codedInput = new CodedInputStream(input); + codedInput.DiscardUnknownFields = discardUnknownFields; + codedInput.ExtensionRegistry = registry; message.MergeFrom(codedInput); codedInput.CheckReadEndOfStreamTag(); } @@ -321,8 +315,8 @@ namespace Google.Protobuf internal static void MergeDelimitedFrom(this IMessage message, Stream input, bool discardUnknownFields, ExtensionRegistry registry) { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(input, nameof(input)); + ProtoPreconditions.CheckNotNull(message, "message"); + ProtoPreconditions.CheckNotNull(input, "input"); int size = (int) CodedInputStream.ReadRawVarint32(input); Stream limitedStream = new LimitedInputStream(input, size); MergeFrom(message, limitedStream, discardUnknownFields, registry); diff --git a/libs/protobuf/csharp/src/Google.Protobuf/MessageParser.cs b/libs/protobuf/csharp/src/Google.Protobuf/MessageParser.cs index 5710292..a10c908 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/MessageParser.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/MessageParser.cs @@ -43,8 +43,9 @@ namespace Google.Protobuf /// public class MessageParser { - private readonly Func factory; - private protected bool DiscardUnknownFields { get; } + private Func factory; + // TODO: When we use a C# 7.1 compiler, make this private protected. + internal bool DiscardUnknownFields { get; } internal ExtensionRegistry Extensions { get; } @@ -171,10 +172,6 @@ namespace Google.Protobuf /// /// Parses a message from the given JSON. /// - /// This method always uses the default JSON parser; it is not affected by . - /// To ignore unknown fields when parsing JSON, create a using a - /// with set to true and call directly. - /// /// The JSON to parse. /// The parsed message. /// The JSON does not comply with RFC 7159 @@ -207,9 +204,6 @@ namespace Google.Protobuf /// /// Creates a new message parser which optionally discards unknown fields when parsing. /// - /// Note that this does not affect the behavior of - /// at all. To ignore unknown fields when parsing JSON, create a using a - /// with set to true and call directly. /// Whether or not to discard unknown fields when parsing. /// A newly configured message parser. public MessageParser WithDiscardUnknownFields(bool discardUnknownFields) => diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ObjectIntPair.cs b/libs/protobuf/csharp/src/Google.Protobuf/ObjectIntPair.cs index 3270b49..b61fc68 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ObjectIntPair.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ObjectIntPair.cs @@ -23,7 +23,14 @@ namespace Google.Protobuf && number == other.number; } - public override bool Equals(object obj) => obj is ObjectIntPair pair && Equals(pair); + public override bool Equals(object obj) + { + if (obj is ObjectIntPair) + { + return Equals((ObjectIntPair)obj); + } + return false; + } public override int GetHashCode() { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ParseContext.cs b/libs/protobuf/csharp/src/Google.Protobuf/ParseContext.cs index 85ea567..7b278b5 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ParseContext.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ParseContext.cs @@ -32,8 +32,14 @@ using System; using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; +using System.Text; +using Google.Protobuf.Collections; namespace Google.Protobuf { @@ -47,7 +53,7 @@ namespace Google.Protobuf public ref struct ParseContext { internal const int DefaultRecursionLimit = 100; - internal const int DefaultSizeLimit = int.MaxValue; + internal const int DefaultSizeLimit = Int32.MaxValue; internal ReadOnlySpan buffer; internal ParserInternalState state; @@ -121,15 +127,14 @@ namespace Google.Protobuf /// Returns the last tag read, or 0 if no tags have been read or we've read beyond /// the end of the input. /// - internal uint LastTag => state.lastTag; + internal uint LastTag { get { return state.lastTag; } } /// /// Internal-only property; when set to true, unknown fields will be discarded while parsing. /// - internal bool DiscardUnknownFields - { - get => state.DiscardUnknownFields; - set => state.DiscardUnknownFields = value; + internal bool DiscardUnknownFields { + get { return state.DiscardUnknownFields; } + set { state.DiscardUnknownFields = value; } } /// @@ -137,8 +142,8 @@ namespace Google.Protobuf /// internal ExtensionRegistry ExtensionRegistry { - get => state.ExtensionRegistry; - set => state.ExtensionRegistry = value; + get { return state.ExtensionRegistry; } + set { state.ExtensionRegistry = value; } } /// @@ -151,85 +156,125 @@ namespace Google.Protobuf /// /// The next field tag, or 0 for end of input. (0 is never a valid tag.) [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint ReadTag() => ParsingPrimitives.ParseTag(ref buffer, ref state); + public uint ReadTag() + { + return ParsingPrimitives.ParseTag(ref buffer, ref state); + } /// /// Reads a double field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public double ReadDouble() => ParsingPrimitives.ParseDouble(ref buffer, ref state); + public double ReadDouble() + { + return ParsingPrimitives.ParseDouble(ref buffer, ref state); + } /// /// Reads a float field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public float ReadFloat() => ParsingPrimitives.ParseFloat(ref buffer, ref state); + public float ReadFloat() + { + return ParsingPrimitives.ParseFloat(ref buffer, ref state); + } /// /// Reads a uint64 field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ulong ReadUInt64() => ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + public ulong ReadUInt64() + { + return ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + } /// /// Reads an int64 field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public long ReadInt64() => (long)ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + public long ReadInt64() + { + return (long)ParsingPrimitives.ParseRawVarint64(ref buffer, ref state); + } /// /// Reads an int32 field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ReadInt32() => (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + public int ReadInt32() + { + return (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } /// /// Reads a fixed64 field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ulong ReadFixed64() => ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + public ulong ReadFixed64() + { + return ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + } /// /// Reads a fixed32 field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint ReadFixed32() => ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + public uint ReadFixed32() + { + return ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + } /// /// Reads a bool field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool ReadBool() => ParsingPrimitives.ParseRawVarint64(ref buffer, ref state) != 0; - + public bool ReadBool() + { + return ParsingPrimitives.ParseRawVarint64(ref buffer, ref state) != 0; + } /// /// Reads a string field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public string ReadString() => ParsingPrimitives.ReadString(ref buffer, ref state); + public string ReadString() + { + return ParsingPrimitives.ReadString(ref buffer, ref state); + } /// /// Reads an embedded message field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ReadMessage(IMessage message) => ParsingPrimitivesMessages.ReadMessage(ref this, message); + public void ReadMessage(IMessage message) + { + ParsingPrimitivesMessages.ReadMessage(ref this, message); + } /// /// Reads an embedded group field from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void ReadGroup(IMessage message) => ParsingPrimitivesMessages.ReadGroup(ref this, message); + public void ReadGroup(IMessage message) + { + ParsingPrimitivesMessages.ReadGroup(ref this, message); + } /// /// Reads a bytes field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ByteString ReadBytes() => ParsingPrimitives.ReadBytes(ref buffer, ref state); - + public ByteString ReadBytes() + { + return ParsingPrimitives.ReadBytes(ref buffer, ref state); + } /// /// Reads a uint32 field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public uint ReadUInt32() => ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + public uint ReadUInt32() + { + return ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } /// /// Reads an enum field value from the input. @@ -245,25 +290,37 @@ namespace Google.Protobuf /// Reads an sfixed32 field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ReadSFixed32() => (int)ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + public int ReadSFixed32() + { + return (int)ParsingPrimitives.ParseRawLittleEndian32(ref buffer, ref state); + } /// /// Reads an sfixed64 field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public long ReadSFixed64() => (long)ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + public long ReadSFixed64() + { + return (long)ParsingPrimitives.ParseRawLittleEndian64(ref buffer, ref state); + } /// /// Reads an sint32 field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ReadSInt32() => ParsingPrimitives.DecodeZigZag32(ParsingPrimitives.ParseRawVarint32(ref buffer, ref state)); + public int ReadSInt32() + { + return ParsingPrimitives.DecodeZigZag32(ParsingPrimitives.ParseRawVarint32(ref buffer, ref state)); + } /// /// Reads an sint64 field value from the input. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public long ReadSInt64() => ParsingPrimitives.DecodeZigZag64(ParsingPrimitives.ParseRawVarint64(ref buffer, ref state)); + public long ReadSInt64() + { + return ParsingPrimitives.DecodeZigZag64(ParsingPrimitives.ParseRawVarint64(ref buffer, ref state)); + } /// /// Reads a length for length-delimited data. @@ -273,7 +330,10 @@ namespace Google.Protobuf /// to make the calling code clearer. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public int ReadLength() => (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + public int ReadLength() + { + return (int)ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); + } internal void CopyStateTo(CodedInputStream input) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ParserInternalState.cs b/libs/protobuf/csharp/src/Google.Protobuf/ParserInternalState.cs index af7dd78..cb4f471 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ParserInternalState.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ParserInternalState.cs @@ -30,8 +30,20 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using Google.Protobuf.Collections; + namespace Google.Protobuf { + // warning: this is a mutable struct, so it needs to be only passed as a ref! internal struct ParserInternalState { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitives.cs b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitives.cs index 4321d26..e270ed8 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitives.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitives.cs @@ -34,10 +34,13 @@ using System; using System.Buffers; using System.Buffers.Binary; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; +using System.Text; +using Google.Protobuf.Collections; namespace Google.Protobuf { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs index 5e1babf..eabaf96 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesMessages.cs @@ -33,6 +33,8 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; using System.Security; using Google.Protobuf.Collections; diff --git a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesWrappers.cs b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesWrappers.cs index e874935..629ec32 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesWrappers.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/ParsingPrimitivesWrappers.cs @@ -31,7 +31,15 @@ #endregion using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; +using System.Text; +using Google.Protobuf.Collections; namespace Google.Protobuf { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/libs/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs index ae885f8..4328e2e 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs @@ -47,3 +47,10 @@ using System.Security; "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + "c5ae9cb6")] + +[assembly: InternalsVisibleTo("Google.Protobuf.Benchmarks, PublicKey=" + + "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" + + "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" + + "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" + + "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" + + "c5ae9cb6")] diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs index 2c5d2c8..f6fa152 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs @@ -31,6 +31,7 @@ #endregion using Google.Protobuf.Collections; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -225,21 +226,24 @@ namespace Google.Protobuf.Reflection { if (values == null) { - value = default; + value = default(T); return false; } - if (values.TryGetValue(field, out IExtensionValue extensionValue)) + IExtensionValue extensionValue; + if (values.TryGetValue(field, out extensionValue)) { - if (extensionValue is ExtensionValue single) + if (extensionValue is ExtensionValue) { + ExtensionValue single = extensionValue as ExtensionValue; ByteString bytes = single.GetValue().ToByteString(); value = new T(); value.MergeFrom(bytes); return true; } - else if (extensionValue is RepeatedExtensionValue repeated) + else if (extensionValue is RepeatedExtensionValue) { + RepeatedExtensionValue repeated = extensionValue as RepeatedExtensionValue; value = repeated.GetValue() .Select(v => v.ToByteString()) .Aggregate(new T(), (t, b) => @@ -260,19 +264,22 @@ namespace Google.Protobuf.Reflection { if (values == null) { - value = default; + value = default(T); return false; } - if (values.TryGetValue(field, out IExtensionValue extensionValue)) + IExtensionValue extensionValue; + if (values.TryGetValue(field, out extensionValue)) { - if (extensionValue is ExtensionValue single) + if (extensionValue is ExtensionValue) { + ExtensionValue single = extensionValue as ExtensionValue; value = single.GetValue(); return true; } - else if (extensionValue is RepeatedExtensionValue repeated) + else if (extensionValue is RepeatedExtensionValue) { + RepeatedExtensionValue repeated = extensionValue as RepeatedExtensionValue; if (repeated.GetValue().Count != 0) { RepeatedField repeatedField = repeated.GetValue(); @@ -310,7 +317,7 @@ namespace Google.Protobuf.Reflection } } - value = default; + value = default(T); return false; } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index e252372..1cb43c0 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -26,7 +26,7 @@ namespace Google.Protobuf.Reflection { string.Concat( "CiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bxIPZ29vZ2xlLnBy", "b3RvYnVmIkcKEUZpbGVEZXNjcmlwdG9yU2V0EjIKBGZpbGUYASADKAsyJC5n", - "b29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90byLsAwoTRmlsZURl", + "b29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90byLbAwoTRmlsZURl", "c2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEg8KB3BhY2thZ2UYAiABKAkS", "EgoKZGVwZW5kZW5jeRgDIAMoCRIZChFwdWJsaWNfZGVwZW5kZW5jeRgKIAMo", "BRIXCg93ZWFrX2RlcGVuZGVuY3kYCyADKAUSNgoMbWVzc2FnZV90eXBlGAQg", @@ -37,137 +37,134 @@ namespace Google.Protobuf.Reflection { "LnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvEi0KB29wdGlvbnMYCCAB", "KAsyHC5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMSOQoQc291cmNlX2Nv", "ZGVfaW5mbxgJIAEoCzIfLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5m", - "bxIOCgZzeW50YXgYDCABKAkSDwoHZWRpdGlvbhgNIAEoCSKpBQoPRGVzY3Jp", - "cHRvclByb3RvEgwKBG5hbWUYASABKAkSNAoFZmllbGQYAiADKAsyJS5nb29n", - "bGUucHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG8SOAoJZXh0ZW5zaW9u", - "GAYgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3Rv", - "EjUKC25lc3RlZF90eXBlGAMgAygLMiAuZ29vZ2xlLnByb3RvYnVmLkRlc2Ny", - "aXB0b3JQcm90bxI3CgllbnVtX3R5cGUYBCADKAsyJC5nb29nbGUucHJvdG9i", - "dWYuRW51bURlc2NyaXB0b3JQcm90bxJICg9leHRlbnNpb25fcmFuZ2UYBSAD", - "KAsyLy5nb29nbGUucHJvdG9idWYuRGVzY3JpcHRvclByb3RvLkV4dGVuc2lv", - "blJhbmdlEjkKCm9uZW9mX2RlY2wYCCADKAsyJS5nb29nbGUucHJvdG9idWYu", - "T25lb2ZEZXNjcmlwdG9yUHJvdG8SMAoHb3B0aW9ucxgHIAEoCzIfLmdvb2ds", - "ZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxJGCg5yZXNlcnZlZF9yYW5nZRgJ", - "IAMoCzIuLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG8uUmVzZXJ2", - "ZWRSYW5nZRIVCg1yZXNlcnZlZF9uYW1lGAogAygJGmUKDkV4dGVuc2lvblJh", - "bmdlEg0KBXN0YXJ0GAEgASgFEgsKA2VuZBgCIAEoBRI3CgdvcHRpb25zGAMg", - "ASgLMiYuZ29vZ2xlLnByb3RvYnVmLkV4dGVuc2lvblJhbmdlT3B0aW9ucxor", - "Cg1SZXNlcnZlZFJhbmdlEg0KBXN0YXJ0GAEgASgFEgsKA2VuZBgCIAEoBSJn", - "ChVFeHRlbnNpb25SYW5nZU9wdGlvbnMSQwoUdW5pbnRlcnByZXRlZF9vcHRp", - "b24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRp", - "b24qCQjoBxCAgICAAiLVBQoURmllbGREZXNjcmlwdG9yUHJvdG8SDAoEbmFt", - "ZRgBIAEoCRIOCgZudW1iZXIYAyABKAUSOgoFbGFiZWwYBCABKA4yKy5nb29n", - "bGUucHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG8uTGFiZWwSOAoEdHlw", - "ZRgFIAEoDjIqLmdvb2dsZS5wcm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90", - "by5UeXBlEhEKCXR5cGVfbmFtZRgGIAEoCRIQCghleHRlbmRlZRgCIAEoCRIV", - "Cg1kZWZhdWx0X3ZhbHVlGAcgASgJEhMKC29uZW9mX2luZGV4GAkgASgFEhEK", - "CWpzb25fbmFtZRgKIAEoCRIuCgdvcHRpb25zGAggASgLMh0uZ29vZ2xlLnBy", - "b3RvYnVmLkZpZWxkT3B0aW9ucxIXCg9wcm90bzNfb3B0aW9uYWwYESABKAgi", - "tgIKBFR5cGUSDwoLVFlQRV9ET1VCTEUQARIOCgpUWVBFX0ZMT0FUEAISDgoK", - "VFlQRV9JTlQ2NBADEg8KC1RZUEVfVUlOVDY0EAQSDgoKVFlQRV9JTlQzMhAF", - "EhAKDFRZUEVfRklYRUQ2NBAGEhAKDFRZUEVfRklYRUQzMhAHEg0KCVRZUEVf", - "Qk9PTBAIEg8KC1RZUEVfU1RSSU5HEAkSDgoKVFlQRV9HUk9VUBAKEhAKDFRZ", - "UEVfTUVTU0FHRRALEg4KClRZUEVfQllURVMQDBIPCgtUWVBFX1VJTlQzMhAN", - "Eg0KCVRZUEVfRU5VTRAOEhEKDVRZUEVfU0ZJWEVEMzIQDxIRCg1UWVBFX1NG", - "SVhFRDY0EBASDwoLVFlQRV9TSU5UMzIQERIPCgtUWVBFX1NJTlQ2NBASIkMK", - "BUxhYmVsEhIKDkxBQkVMX09QVElPTkFMEAESEgoOTEFCRUxfUkVRVUlSRUQQ", - "AhISCg5MQUJFTF9SRVBFQVRFRBADIlQKFE9uZW9mRGVzY3JpcHRvclByb3Rv", - "EgwKBG5hbWUYASABKAkSLgoHb3B0aW9ucxgCIAEoCzIdLmdvb2dsZS5wcm90", - "b2J1Zi5PbmVvZk9wdGlvbnMipAIKE0VudW1EZXNjcmlwdG9yUHJvdG8SDAoE", - "bmFtZRgBIAEoCRI4CgV2YWx1ZRgCIAMoCzIpLmdvb2dsZS5wcm90b2J1Zi5F", - "bnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8SLQoHb3B0aW9ucxgDIAEoCzIcLmdv", - "b2dsZS5wcm90b2J1Zi5FbnVtT3B0aW9ucxJOCg5yZXNlcnZlZF9yYW5nZRgE", - "IAMoCzI2Lmdvb2dsZS5wcm90b2J1Zi5FbnVtRGVzY3JpcHRvclByb3RvLkVu", - "dW1SZXNlcnZlZFJhbmdlEhUKDXJlc2VydmVkX25hbWUYBSADKAkaLwoRRW51", - "bVJlc2VydmVkUmFuZ2USDQoFc3RhcnQYASABKAUSCwoDZW5kGAIgASgFImwK", - "GEVudW1WYWx1ZURlc2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEg4KBm51", - "bWJlchgCIAEoBRIyCgdvcHRpb25zGAMgASgLMiEuZ29vZ2xlLnByb3RvYnVm", - "LkVudW1WYWx1ZU9wdGlvbnMikAEKFlNlcnZpY2VEZXNjcmlwdG9yUHJvdG8S", - "DAoEbmFtZRgBIAEoCRI2CgZtZXRob2QYAiADKAsyJi5nb29nbGUucHJvdG9i", - "dWYuTWV0aG9kRGVzY3JpcHRvclByb3RvEjAKB29wdGlvbnMYAyABKAsyHy5n", - "b29nbGUucHJvdG9idWYuU2VydmljZU9wdGlvbnMiwQEKFU1ldGhvZERlc2Ny", - "aXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEhIKCmlucHV0X3R5cGUYAiABKAkS", - "EwoLb3V0cHV0X3R5cGUYAyABKAkSLwoHb3B0aW9ucxgEIAEoCzIeLmdvb2ds", - "ZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zEh8KEGNsaWVudF9zdHJlYW1pbmcY", - "BSABKAg6BWZhbHNlEh8KEHNlcnZlcl9zdHJlYW1pbmcYBiABKAg6BWZhbHNl", - "IqUGCgtGaWxlT3B0aW9ucxIUCgxqYXZhX3BhY2thZ2UYASABKAkSHAoUamF2", - "YV9vdXRlcl9jbGFzc25hbWUYCCABKAkSIgoTamF2YV9tdWx0aXBsZV9maWxl", - "cxgKIAEoCDoFZmFsc2USKQodamF2YV9nZW5lcmF0ZV9lcXVhbHNfYW5kX2hh", - "c2gYFCABKAhCAhgBEiUKFmphdmFfc3RyaW5nX2NoZWNrX3V0ZjgYGyABKAg6", - "BWZhbHNlEkYKDG9wdGltaXplX2ZvchgJIAEoDjIpLmdvb2dsZS5wcm90b2J1", - "Zi5GaWxlT3B0aW9ucy5PcHRpbWl6ZU1vZGU6BVNQRUVEEhIKCmdvX3BhY2th", - "Z2UYCyABKAkSIgoTY2NfZ2VuZXJpY19zZXJ2aWNlcxgQIAEoCDoFZmFsc2US", - "JAoVamF2YV9nZW5lcmljX3NlcnZpY2VzGBEgASgIOgVmYWxzZRIiChNweV9n", - "ZW5lcmljX3NlcnZpY2VzGBIgASgIOgVmYWxzZRIjChRwaHBfZ2VuZXJpY19z", - "ZXJ2aWNlcxgqIAEoCDoFZmFsc2USGQoKZGVwcmVjYXRlZBgXIAEoCDoFZmFs", - "c2USHgoQY2NfZW5hYmxlX2FyZW5hcxgfIAEoCDoEdHJ1ZRIZChFvYmpjX2Ns", - "YXNzX3ByZWZpeBgkIAEoCRIYChBjc2hhcnBfbmFtZXNwYWNlGCUgASgJEhQK", - "DHN3aWZ0X3ByZWZpeBgnIAEoCRIYChBwaHBfY2xhc3NfcHJlZml4GCggASgJ", - "EhUKDXBocF9uYW1lc3BhY2UYKSABKAkSHgoWcGhwX21ldGFkYXRhX25hbWVz", - "cGFjZRgsIAEoCRIUCgxydWJ5X3BhY2thZ2UYLSABKAkSQwoUdW5pbnRlcnBy", - "ZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJw", - "cmV0ZWRPcHRpb24iOgoMT3B0aW1pemVNb2RlEgkKBVNQRUVEEAESDQoJQ09E", - "RV9TSVpFEAISEAoMTElURV9SVU5USU1FEAMqCQjoBxCAgICAAkoECCYQJyKE", - "AgoOTWVzc2FnZU9wdGlvbnMSJgoXbWVzc2FnZV9zZXRfd2lyZV9mb3JtYXQY", - "ASABKAg6BWZhbHNlEi4KH25vX3N0YW5kYXJkX2Rlc2NyaXB0b3JfYWNjZXNz", - "b3IYAiABKAg6BWZhbHNlEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEhEK", - "CW1hcF9lbnRyeRgHIAEoCBJDChR1bmludGVycHJldGVkX29wdGlvbhjnByAD", - "KAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbioJCOgH", - "EICAgIACSgQIBBAFSgQIBRAGSgQIBhAHSgQICBAJSgQICRAKIr4DCgxGaWVs", - "ZE9wdGlvbnMSOgoFY3R5cGUYASABKA4yIy5nb29nbGUucHJvdG9idWYuRmll", - "bGRPcHRpb25zLkNUeXBlOgZTVFJJTkcSDgoGcGFja2VkGAIgASgIEj8KBmpz", - "dHlwZRgGIAEoDjIkLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlvbnMuSlNU", - "eXBlOglKU19OT1JNQUwSEwoEbGF6eRgFIAEoCDoFZmFsc2USHgoPdW52ZXJp", - "ZmllZF9sYXp5GA8gASgIOgVmYWxzZRIZCgpkZXByZWNhdGVkGAMgASgIOgVm", - "YWxzZRITCgR3ZWFrGAogASgIOgVmYWxzZRJDChR1bmludGVycHJldGVkX29w", - "dGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9w", - "dGlvbiIvCgVDVHlwZRIKCgZTVFJJTkcQABIICgRDT1JEEAESEAoMU1RSSU5H", - "X1BJRUNFEAIiNQoGSlNUeXBlEg0KCUpTX05PUk1BTBAAEg0KCUpTX1NUUklO", - "RxABEg0KCUpTX05VTUJFUhACKgkI6AcQgICAgAJKBAgEEAUiXgoMT25lb2ZP", + "bxIOCgZzeW50YXgYDCABKAkiqQUKD0Rlc2NyaXB0b3JQcm90bxIMCgRuYW1l", + "GAEgASgJEjQKBWZpZWxkGAIgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxk", + "RGVzY3JpcHRvclByb3RvEjgKCWV4dGVuc2lvbhgGIAMoCzIlLmdvb2dsZS5w", + "cm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90bxI1CgtuZXN0ZWRfdHlwZRgD", + "IAMoCzIgLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG8SNwoJZW51", + "bV90eXBlGAQgAygLMiQuZ29vZ2xlLnByb3RvYnVmLkVudW1EZXNjcmlwdG9y", + "UHJvdG8SSAoPZXh0ZW5zaW9uX3JhbmdlGAUgAygLMi8uZ29vZ2xlLnByb3Rv", + "YnVmLkRlc2NyaXB0b3JQcm90by5FeHRlbnNpb25SYW5nZRI5CgpvbmVvZl9k", + "ZWNsGAggAygLMiUuZ29vZ2xlLnByb3RvYnVmLk9uZW9mRGVzY3JpcHRvclBy", + "b3RvEjAKB29wdGlvbnMYByABKAsyHy5nb29nbGUucHJvdG9idWYuTWVzc2Fn", + "ZU9wdGlvbnMSRgoOcmVzZXJ2ZWRfcmFuZ2UYCSADKAsyLi5nb29nbGUucHJv", + "dG9idWYuRGVzY3JpcHRvclByb3RvLlJlc2VydmVkUmFuZ2USFQoNcmVzZXJ2", + "ZWRfbmFtZRgKIAMoCRplCg5FeHRlbnNpb25SYW5nZRINCgVzdGFydBgBIAEo", + "BRILCgNlbmQYAiABKAUSNwoHb3B0aW9ucxgDIAEoCzImLmdvb2dsZS5wcm90", + "b2J1Zi5FeHRlbnNpb25SYW5nZU9wdGlvbnMaKwoNUmVzZXJ2ZWRSYW5nZRIN", + "CgVzdGFydBgBIAEoBRILCgNlbmQYAiABKAUiZwoVRXh0ZW5zaW9uUmFuZ2VP", "cHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2ds", - "ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIikwEK", - "C0VudW1PcHRpb25zEhMKC2FsbG93X2FsaWFzGAIgASgIEhkKCmRlcHJlY2F0", - "ZWQYAyABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo", - "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQ", - "gICAgAJKBAgFEAYifQoQRW51bVZhbHVlT3B0aW9ucxIZCgpkZXByZWNhdGVk", - "GAEgASgIOgVmYWxzZRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsy", - "JC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICA", - "gIACInsKDlNlcnZpY2VPcHRpb25zEhkKCmRlcHJlY2F0ZWQYISABKAg6BWZh", - "bHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5w", - "cm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIirQIKDU1l", - "dGhvZE9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFsc2USXwoRaWRl", - "bXBvdGVuY3lfbGV2ZWwYIiABKA4yLy5nb29nbGUucHJvdG9idWYuTWV0aG9k", - "T3B0aW9ucy5JZGVtcG90ZW5jeUxldmVsOhNJREVNUE9URU5DWV9VTktOT1dO", - "EkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90", - "b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIlAKEElkZW1wb3RlbmN5TGV2ZWwS", - "FwoTSURFTVBPVEVOQ1lfVU5LTk9XThAAEhMKD05PX1NJREVfRUZGRUNUUxAB", - "Eg4KCklERU1QT1RFTlQQAioJCOgHEICAgIACIp4CChNVbmludGVycHJldGVk", - "T3B0aW9uEjsKBG5hbWUYAiADKAsyLS5nb29nbGUucHJvdG9idWYuVW5pbnRl", - "cnByZXRlZE9wdGlvbi5OYW1lUGFydBIYChBpZGVudGlmaWVyX3ZhbHVlGAMg", - "ASgJEhoKEnBvc2l0aXZlX2ludF92YWx1ZRgEIAEoBBIaChJuZWdhdGl2ZV9p", - "bnRfdmFsdWUYBSABKAMSFAoMZG91YmxlX3ZhbHVlGAYgASgBEhQKDHN0cmlu", - "Z192YWx1ZRgHIAEoDBIXCg9hZ2dyZWdhdGVfdmFsdWUYCCABKAkaMwoITmFt", - "ZVBhcnQSEQoJbmFtZV9wYXJ0GAEgAigJEhQKDGlzX2V4dGVuc2lvbhgCIAIo", - "CCLVAQoOU291cmNlQ29kZUluZm8SOgoIbG9jYXRpb24YASADKAsyKC5nb29n", - "bGUucHJvdG9idWYuU291cmNlQ29kZUluZm8uTG9jYXRpb24ahgEKCExvY2F0", - "aW9uEhAKBHBhdGgYASADKAVCAhABEhAKBHNwYW4YAiADKAVCAhABEhgKEGxl", - "YWRpbmdfY29tbWVudHMYAyABKAkSGQoRdHJhaWxpbmdfY29tbWVudHMYBCAB", - "KAkSIQoZbGVhZGluZ19kZXRhY2hlZF9jb21tZW50cxgGIAMoCSKcAgoRR2Vu", - "ZXJhdGVkQ29kZUluZm8SQQoKYW5ub3RhdGlvbhgBIAMoCzItLmdvb2dsZS5w", - "cm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9uGsMBCgpBbm5v", - "dGF0aW9uEhAKBHBhdGgYASADKAVCAhABEhMKC3NvdXJjZV9maWxlGAIgASgJ", - "Eg0KBWJlZ2luGAMgASgFEgsKA2VuZBgEIAEoBRJICghzZW1hbnRpYxgFIAEo", - "DjI2Lmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0", - "aW9uLlNlbWFudGljIigKCFNlbWFudGljEggKBE5PTkUQABIHCgNTRVQQARIJ", - "CgVBTElBUxACQn4KE2NvbS5nb29nbGUucHJvdG9idWZCEERlc2NyaXB0b3JQ", - "cm90b3NIAVotZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMvZGVz", - "Y3JpcHRvcnBi+AEBogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rp", - "b24=")); + "ZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAIi1QUK", + "FEZpZWxkRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSDgoGbnVtYmVy", + "GAMgASgFEjoKBWxhYmVsGAQgASgOMisuZ29vZ2xlLnByb3RvYnVmLkZpZWxk", + "RGVzY3JpcHRvclByb3RvLkxhYmVsEjgKBHR5cGUYBSABKA4yKi5nb29nbGUu", + "cHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJvdG8uVHlwZRIRCgl0eXBlX25h", + "bWUYBiABKAkSEAoIZXh0ZW5kZWUYAiABKAkSFQoNZGVmYXVsdF92YWx1ZRgH", + "IAEoCRITCgtvbmVvZl9pbmRleBgJIAEoBRIRCglqc29uX25hbWUYCiABKAkS", + "LgoHb3B0aW9ucxgIIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlv", + "bnMSFwoPcHJvdG8zX29wdGlvbmFsGBEgASgIIrYCCgRUeXBlEg8KC1RZUEVf", + "RE9VQkxFEAESDgoKVFlQRV9GTE9BVBACEg4KClRZUEVfSU5UNjQQAxIPCgtU", + "WVBFX1VJTlQ2NBAEEg4KClRZUEVfSU5UMzIQBRIQCgxUWVBFX0ZJWEVENjQQ", + "BhIQCgxUWVBFX0ZJWEVEMzIQBxINCglUWVBFX0JPT0wQCBIPCgtUWVBFX1NU", + "UklORxAJEg4KClRZUEVfR1JPVVAQChIQCgxUWVBFX01FU1NBR0UQCxIOCgpU", + "WVBFX0JZVEVTEAwSDwoLVFlQRV9VSU5UMzIQDRINCglUWVBFX0VOVU0QDhIR", + "Cg1UWVBFX1NGSVhFRDMyEA8SEQoNVFlQRV9TRklYRUQ2NBAQEg8KC1RZUEVf", + "U0lOVDMyEBESDwoLVFlQRV9TSU5UNjQQEiJDCgVMYWJlbBISCg5MQUJFTF9P", + "UFRJT05BTBABEhIKDkxBQkVMX1JFUVVJUkVEEAISEgoOTEFCRUxfUkVQRUFU", + "RUQQAyJUChRPbmVvZkRlc2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEi4K", + "B29wdGlvbnMYAiABKAsyHS5nb29nbGUucHJvdG9idWYuT25lb2ZPcHRpb25z", + "IqQCChNFbnVtRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSOAoFdmFs", + "dWUYAiADKAsyKS5nb29nbGUucHJvdG9idWYuRW51bVZhbHVlRGVzY3JpcHRv", + "clByb3RvEi0KB29wdGlvbnMYAyABKAsyHC5nb29nbGUucHJvdG9idWYuRW51", + "bU9wdGlvbnMSTgoOcmVzZXJ2ZWRfcmFuZ2UYBCADKAsyNi5nb29nbGUucHJv", + "dG9idWYuRW51bURlc2NyaXB0b3JQcm90by5FbnVtUmVzZXJ2ZWRSYW5nZRIV", + "Cg1yZXNlcnZlZF9uYW1lGAUgAygJGi8KEUVudW1SZXNlcnZlZFJhbmdlEg0K", + "BXN0YXJ0GAEgASgFEgsKA2VuZBgCIAEoBSJsChhFbnVtVmFsdWVEZXNjcmlw", + "dG9yUHJvdG8SDAoEbmFtZRgBIAEoCRIOCgZudW1iZXIYAiABKAUSMgoHb3B0", + "aW9ucxgDIAEoCzIhLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVPcHRpb25z", + "IpABChZTZXJ2aWNlRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSNgoG", + "bWV0aG9kGAIgAygLMiYuZ29vZ2xlLnByb3RvYnVmLk1ldGhvZERlc2NyaXB0", + "b3JQcm90bxIwCgdvcHRpb25zGAMgASgLMh8uZ29vZ2xlLnByb3RvYnVmLlNl", + "cnZpY2VPcHRpb25zIsEBChVNZXRob2REZXNjcmlwdG9yUHJvdG8SDAoEbmFt", + "ZRgBIAEoCRISCgppbnB1dF90eXBlGAIgASgJEhMKC291dHB1dF90eXBlGAMg", + "ASgJEi8KB29wdGlvbnMYBCABKAsyHi5nb29nbGUucHJvdG9idWYuTWV0aG9k", + "T3B0aW9ucxIfChBjbGllbnRfc3RyZWFtaW5nGAUgASgIOgVmYWxzZRIfChBz", + "ZXJ2ZXJfc3RyZWFtaW5nGAYgASgIOgVmYWxzZSKlBgoLRmlsZU9wdGlvbnMS", + "FAoMamF2YV9wYWNrYWdlGAEgASgJEhwKFGphdmFfb3V0ZXJfY2xhc3NuYW1l", + "GAggASgJEiIKE2phdmFfbXVsdGlwbGVfZmlsZXMYCiABKAg6BWZhbHNlEikK", + "HWphdmFfZ2VuZXJhdGVfZXF1YWxzX2FuZF9oYXNoGBQgASgIQgIYARIlChZq", + "YXZhX3N0cmluZ19jaGVja191dGY4GBsgASgIOgVmYWxzZRJGCgxvcHRpbWl6", + "ZV9mb3IYCSABKA4yKS5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMuT3B0", + "aW1pemVNb2RlOgVTUEVFRBISCgpnb19wYWNrYWdlGAsgASgJEiIKE2NjX2dl", + "bmVyaWNfc2VydmljZXMYECABKAg6BWZhbHNlEiQKFWphdmFfZ2VuZXJpY19z", + "ZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoTcHlfZ2VuZXJpY19zZXJ2aWNlcxgS", + "IAEoCDoFZmFsc2USIwoUcGhwX2dlbmVyaWNfc2VydmljZXMYKiABKAg6BWZh", + "bHNlEhkKCmRlcHJlY2F0ZWQYFyABKAg6BWZhbHNlEh4KEGNjX2VuYWJsZV9h", + "cmVuYXMYHyABKAg6BHRydWUSGQoRb2JqY19jbGFzc19wcmVmaXgYJCABKAkS", + "GAoQY3NoYXJwX25hbWVzcGFjZRglIAEoCRIUCgxzd2lmdF9wcmVmaXgYJyAB", + "KAkSGAoQcGhwX2NsYXNzX3ByZWZpeBgoIAEoCRIVCg1waHBfbmFtZXNwYWNl", + "GCkgASgJEh4KFnBocF9tZXRhZGF0YV9uYW1lc3BhY2UYLCABKAkSFAoMcnVi", + "eV9wYWNrYWdlGC0gASgJEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMo", + "CzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIjoKDE9w", + "dGltaXplTW9kZRIJCgVTUEVFRBABEg0KCUNPREVfU0laRRACEhAKDExJVEVf", + "UlVOVElNRRADKgkI6AcQgICAgAJKBAgmECcihAIKDk1lc3NhZ2VPcHRpb25z", + "EiYKF21lc3NhZ2Vfc2V0X3dpcmVfZm9ybWF0GAEgASgIOgVmYWxzZRIuCh9u", + "b19zdGFuZGFyZF9kZXNjcmlwdG9yX2FjY2Vzc29yGAIgASgIOgVmYWxzZRIZ", + "CgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRIRCgltYXBfZW50cnkYByABKAgS", + "QwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3Rv", + "YnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAkoECAQQBUoECAUQ", + "BkoECAYQB0oECAgQCUoECAkQCiK+AwoMRmllbGRPcHRpb25zEjoKBWN0eXBl", + "GAEgASgOMiMuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5DVHlwZToG", + "U1RSSU5HEg4KBnBhY2tlZBgCIAEoCBI/CgZqc3R5cGUYBiABKA4yJC5nb29n", + "bGUucHJvdG9idWYuRmllbGRPcHRpb25zLkpTVHlwZToJSlNfTk9STUFMEhMK", + "BGxhenkYBSABKAg6BWZhbHNlEh4KD3VudmVyaWZpZWRfbGF6eRgPIAEoCDoF", + "ZmFsc2USGQoKZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USEwoEd2VhaxgKIAEo", + "CDoFZmFsc2USQwoUdW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29v", + "Z2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24iLwoFQ1R5cGUSCgoG", + "U1RSSU5HEAASCAoEQ09SRBABEhAKDFNUUklOR19QSUVDRRACIjUKBkpTVHlw", + "ZRINCglKU19OT1JNQUwQABINCglKU19TVFJJTkcQARINCglKU19OVU1CRVIQ", + "AioJCOgHEICAgIACSgQIBBAFIl4KDE9uZW9mT3B0aW9ucxJDChR1bmludGVy", + "cHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRl", + "cnByZXRlZE9wdGlvbioJCOgHEICAgIACIpMBCgtFbnVtT3B0aW9ucxITCgth", + "bGxvd19hbGlhcxgCIAEoCBIZCgpkZXByZWNhdGVkGAMgASgIOgVmYWxzZRJD", + "ChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9i", + "dWYuVW5pbnRlcnByZXRlZE9wdGlvbioJCOgHEICAgIACSgQIBRAGIn0KEEVu", + "dW1WYWx1ZU9wdGlvbnMSGQoKZGVwcmVjYXRlZBgBIAEoCDoFZmFsc2USQwoU", + "dW5pbnRlcnByZXRlZF9vcHRpb24Y5wcgAygLMiQuZ29vZ2xlLnByb3RvYnVm", + "LlVuaW50ZXJwcmV0ZWRPcHRpb24qCQjoBxCAgICAAiJ7Cg5TZXJ2aWNlT3B0", + "aW9ucxIZCgpkZXByZWNhdGVkGCEgASgIOgVmYWxzZRJDChR1bmludGVycHJl", + "dGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnBy", + "ZXRlZE9wdGlvbioJCOgHEICAgIACIq0CCg1NZXRob2RPcHRpb25zEhkKCmRl", + "cHJlY2F0ZWQYISABKAg6BWZhbHNlEl8KEWlkZW1wb3RlbmN5X2xldmVsGCIg", + "ASgOMi8uZ29vZ2xlLnByb3RvYnVmLk1ldGhvZE9wdGlvbnMuSWRlbXBvdGVu", + "Y3lMZXZlbDoTSURFTVBPVEVOQ1lfVU5LTk9XThJDChR1bmludGVycHJldGVk", + "X29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRl", + "ZE9wdGlvbiJQChBJZGVtcG90ZW5jeUxldmVsEhcKE0lERU1QT1RFTkNZX1VO", + "S05PV04QABITCg9OT19TSURFX0VGRkVDVFMQARIOCgpJREVNUE9URU5UEAIq", + "CQjoBxCAgICAAiKeAgoTVW5pbnRlcnByZXRlZE9wdGlvbhI7CgRuYW1lGAIg", + "AygLMi0uZ29vZ2xlLnByb3RvYnVmLlVuaW50ZXJwcmV0ZWRPcHRpb24uTmFt", + "ZVBhcnQSGAoQaWRlbnRpZmllcl92YWx1ZRgDIAEoCRIaChJwb3NpdGl2ZV9p", + "bnRfdmFsdWUYBCABKAQSGgoSbmVnYXRpdmVfaW50X3ZhbHVlGAUgASgDEhQK", + "DGRvdWJsZV92YWx1ZRgGIAEoARIUCgxzdHJpbmdfdmFsdWUYByABKAwSFwoP", + "YWdncmVnYXRlX3ZhbHVlGAggASgJGjMKCE5hbWVQYXJ0EhEKCW5hbWVfcGFy", + "dBgBIAIoCRIUCgxpc19leHRlbnNpb24YAiACKAgi1QEKDlNvdXJjZUNvZGVJ", + "bmZvEjoKCGxvY2F0aW9uGAEgAygLMiguZ29vZ2xlLnByb3RvYnVmLlNvdXJj", + "ZUNvZGVJbmZvLkxvY2F0aW9uGoYBCghMb2NhdGlvbhIQCgRwYXRoGAEgAygF", + "QgIQARIQCgRzcGFuGAIgAygFQgIQARIYChBsZWFkaW5nX2NvbW1lbnRzGAMg", + "ASgJEhkKEXRyYWlsaW5nX2NvbW1lbnRzGAQgASgJEiEKGWxlYWRpbmdfZGV0", + "YWNoZWRfY29tbWVudHMYBiADKAkipwEKEUdlbmVyYXRlZENvZGVJbmZvEkEK", + "CmFubm90YXRpb24YASADKAsyLS5nb29nbGUucHJvdG9idWYuR2VuZXJhdGVk", + "Q29kZUluZm8uQW5ub3RhdGlvbhpPCgpBbm5vdGF0aW9uEhAKBHBhdGgYASAD", + "KAVCAhABEhMKC3NvdXJjZV9maWxlGAIgASgJEg0KBWJlZ2luGAMgASgFEgsK", + "A2VuZBgEIAEoBUJ+ChNjb20uZ29vZ2xlLnByb3RvYnVmQhBEZXNjcmlwdG9y", + "UHJvdG9zSAFaLWdvb2dsZS5nb2xhbmcub3JnL3Byb3RvYnVmL3R5cGVzL2Rl", + "c2NyaXB0b3JwYvgBAaICA0dQQqoCGkdvb2dsZS5Qcm90b2J1Zi5SZWZsZWN0", + "aW9u")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileDescriptorSet), global::Google.Protobuf.Reflection.FileDescriptorSet.Parser, new[]{ "File" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileDescriptorProto), global::Google.Protobuf.Reflection.FileDescriptorProto.Parser, new[]{ "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax", "Edition" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileDescriptorProto), global::Google.Protobuf.Reflection.FileDescriptorProto.Parser, new[]{ "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto), global::Google.Protobuf.Reflection.DescriptorProto.Parser, new[]{ "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser, new[]{ "Start", "End", "Options" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser, new[]{ "Start", "End" }, null, null, null, null)}), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ExtensionRangeOptions), global::Google.Protobuf.Reflection.ExtensionRangeOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null, null), @@ -187,7 +184,7 @@ namespace Google.Protobuf.Reflection { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MethodOptions), global::Google.Protobuf.Reflection.MethodOptions.Parser, new[]{ "Deprecated", "IdempotencyLevel", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.UninterpretedOption), global::Google.Protobuf.Reflection.UninterpretedOption.Parser, new[]{ "Name", "IdentifierValue", "PositiveIntValue", "NegativeIntValue", "DoubleValue", "StringValue", "AggregateValue" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart), global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart.Parser, new[]{ "NamePart_", "IsExtension" }, null, null, null, null)}), new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.SourceCodeInfo), global::Google.Protobuf.Reflection.SourceCodeInfo.Parser, new[]{ "Location" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location), global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location.Parser, new[]{ "Path", "Span", "LeadingComments", "TrailingComments", "LeadingDetachedComments" }, null, null, null, null)}), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Parser, new[]{ "Annotation" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser, new[]{ "Path", "SourceFile", "Begin", "End", "Semantic" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic) }, null, null)}) + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Parser, new[]{ "Annotation" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser, new[]{ "Path", "SourceFile", "Begin", "End" }, null, null, null, null)}) })); } #endregion @@ -425,7 +422,6 @@ namespace Google.Protobuf.Reflection { options_ = other.options_ != null ? other.options_.Clone() : null; sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null; syntax_ = other.syntax_; - edition_ = other.edition_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -620,9 +616,7 @@ namespace Google.Protobuf.Reflection { private string syntax_; /// /// The syntax of the proto file. - /// The supported values are "proto2", "proto3", and "editions". - /// - /// If `edition` is present, this value must be "editions". + /// The supported values are "proto2" and "proto3". /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -645,35 +639,6 @@ namespace Google.Protobuf.Reflection { syntax_ = null; } - /// Field number for the "edition" field. - public const int EditionFieldNumber = 13; - private readonly static string EditionDefaultValue = ""; - - private string edition_; - /// - /// The edition of the proto file, which is an opaque string. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string Edition { - get { return edition_ ?? EditionDefaultValue; } - set { - edition_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - /// Gets whether the "edition" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasEdition { - get { return edition_ != null; } - } - /// Clears the value of the "edition" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearEdition() { - edition_ = null; - } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override bool Equals(object other) { @@ -701,7 +666,6 @@ namespace Google.Protobuf.Reflection { if (!object.Equals(Options, other.Options)) return false; if (!object.Equals(SourceCodeInfo, other.SourceCodeInfo)) return false; if (Syntax != other.Syntax) return false; - if (Edition != other.Edition) return false; return Equals(_unknownFields, other._unknownFields); } @@ -721,7 +685,6 @@ namespace Google.Protobuf.Reflection { if (options_ != null) hash ^= Options.GetHashCode(); if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode(); if (HasSyntax) hash ^= Syntax.GetHashCode(); - if (HasEdition) hash ^= Edition.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -767,10 +730,6 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(98); output.WriteString(Syntax); } - if (HasEdition) { - output.WriteRawTag(106); - output.WriteString(Edition); - } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -808,10 +767,6 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(98); output.WriteString(Syntax); } - if (HasEdition) { - output.WriteRawTag(106); - output.WriteString(Edition); - } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -844,9 +799,6 @@ namespace Google.Protobuf.Reflection { if (HasSyntax) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Syntax); } - if (HasEdition) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Edition); - } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -887,9 +839,6 @@ namespace Google.Protobuf.Reflection { if (other.HasSyntax) { Syntax = other.Syntax; } - if (other.HasEdition) { - Edition = other.Edition; - } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -961,10 +910,6 @@ namespace Google.Protobuf.Reflection { Syntax = input.ReadString(); break; } - case 106: { - Edition = input.ReadString(); - break; - } } } #endif @@ -1036,10 +981,6 @@ namespace Google.Protobuf.Reflection { Syntax = input.ReadString(); break; } - case 106: { - Edition = input.ReadString(); - break; - } } } } @@ -6641,10 +6582,6 @@ namespace Google.Protobuf.Reflection { private bool mapEntry_; /// - /// NOTE: Do not set the option in .proto files. Always use the maps syntax - /// instead. The option should only be implicitly set by the proto compiler - /// parser. - /// /// Whether the message is an automatically generated map entry type for the /// maps field. /// @@ -6662,6 +6599,10 @@ namespace Google.Protobuf.Reflection { /// use a native map in the target language to hold the keys and values. /// The reflection APIs in such implementations still need to work as /// if the field is a repeated message field. + /// + /// NOTE: Do not set the option in .proto files. Always use the maps syntax + /// instead. The option should only be implicitly set by the proto compiler + /// parser. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -7157,8 +7098,11 @@ namespace Google.Protobuf.Reflection { /// check its required fields, regardless of whether or not the message has /// been parsed. /// - /// As of May 2022, lazy verifies the contents of the byte stream during - /// parsing. An invalid byte stream will cause the overall parsing to fail. + /// As of 2021, lazy does no correctness checks on the byte stream during + /// parsing. This may lead to crashes if and when an invalid byte stream is + /// finally parsed upon access. + /// + /// TODO(b/211906113): Enable validation on lazy fields. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -10814,7 +10758,6 @@ namespace Google.Protobuf.Reflection { sourceFile_ = other.sourceFile_; begin_ = other.begin_; end_ = other.end_; - semantic_ = other.semantic_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -10906,7 +10849,7 @@ namespace Google.Protobuf.Reflection { private int end_; /// /// Identifies the ending offset in bytes in the generated code that - /// relates to the identified object. The end offset should be one past + /// relates to the identified offset. The end offset should be one past /// the last relevant byte (so the length of the text = end - begin). /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -10931,33 +10874,6 @@ namespace Google.Protobuf.Reflection { _hasBits0 &= ~2; } - /// Field number for the "semantic" field. - public const int SemanticFieldNumber = 5; - private readonly static global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic SemanticDefaultValue = global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic.None; - - private global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic semantic_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic Semantic { - get { if ((_hasBits0 & 4) != 0) { return semantic_; } else { return SemanticDefaultValue; } } - set { - _hasBits0 |= 4; - semantic_ = value; - } - } - /// Gets whether the "semantic" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasSemantic { - get { return (_hasBits0 & 4) != 0; } - } - /// Clears the value of the "semantic" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearSemantic() { - _hasBits0 &= ~4; - } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override bool Equals(object other) { @@ -10977,7 +10893,6 @@ namespace Google.Protobuf.Reflection { if (SourceFile != other.SourceFile) return false; if (Begin != other.Begin) return false; if (End != other.End) return false; - if (Semantic != other.Semantic) return false; return Equals(_unknownFields, other._unknownFields); } @@ -10989,7 +10904,6 @@ namespace Google.Protobuf.Reflection { if (HasSourceFile) hash ^= SourceFile.GetHashCode(); if (HasBegin) hash ^= Begin.GetHashCode(); if (HasEnd) hash ^= End.GetHashCode(); - if (HasSemantic) hash ^= Semantic.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -11021,10 +10935,6 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(32); output.WriteInt32(End); } - if (HasSemantic) { - output.WriteRawTag(40); - output.WriteEnum((int) Semantic); - } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -11048,10 +10958,6 @@ namespace Google.Protobuf.Reflection { output.WriteRawTag(32); output.WriteInt32(End); } - if (HasSemantic) { - output.WriteRawTag(40); - output.WriteEnum((int) Semantic); - } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -11072,9 +10978,6 @@ namespace Google.Protobuf.Reflection { if (HasEnd) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(End); } - if (HasSemantic) { - size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Semantic); - } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -11097,9 +11000,6 @@ namespace Google.Protobuf.Reflection { if (other.HasEnd) { End = other.End; } - if (other.HasSemantic) { - Semantic = other.Semantic; - } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -11132,10 +11032,6 @@ namespace Google.Protobuf.Reflection { End = input.ReadInt32(); break; } - case 40: { - Semantic = (global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic) input.ReadEnum(); - break; - } } } #endif @@ -11168,42 +11064,11 @@ namespace Google.Protobuf.Reflection { End = input.ReadInt32(); break; } - case 40: { - Semantic = (global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Types.Semantic) input.ReadEnum(); - break; - } } } } #endif - #region Nested types - /// Container for nested types declared in the Annotation message type. - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static partial class Types { - /// - /// Represents the identified object's effect on the element in the original - /// .proto file. - /// - public enum Semantic { - /// - /// There is no effect or the effect is indescribable. - /// - [pbr::OriginalName("NONE")] None = 0, - /// - /// The element is set or otherwise mutated. - /// - [pbr::OriginalName("SET")] Set = 1, - /// - /// An alias to the element is returned. - /// - [pbr::OriginalName("ALIAS")] Alias = 2, - } - - } - #endregion - } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs index 3c7fac2..b22048f 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorDeclaration.cs @@ -30,9 +30,11 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Text; using static Google.Protobuf.Reflection.SourceCodeInfo.Types; namespace Google.Protobuf.Reflection diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs index 5128ad9..93f2fa9 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs @@ -51,11 +51,12 @@ namespace Google.Protobuf.Reflection private readonly IDictionary, EnumValueDescriptor> enumValuesByNumber = new Dictionary, EnumValueDescriptor>(); - private readonly HashSet dependencies = new HashSet(); + private readonly HashSet dependencies; internal DescriptorPool(IEnumerable dependencyFiles) { - foreach (FileDescriptor dependencyFile in dependencyFiles) + dependencies = new HashSet(); + foreach (var dependencyFile in dependencyFiles) { dependencies.Add(dependencyFile); ImportPublicDependencies(dependencyFile); @@ -87,8 +88,10 @@ namespace Google.Protobuf.Reflection /// or null if the symbol doesn't exist or has the wrong type internal T FindSymbol(string fullName) where T : class { - descriptorsByName.TryGetValue(fullName, out IDescriptor result); - if (result is T descriptor) + IDescriptor result; + descriptorsByName.TryGetValue(fullName, out result); + T descriptor = result as T; + if (descriptor != null) { return descriptor; } @@ -128,9 +131,10 @@ namespace Google.Protobuf.Reflection name = fullName; } - if (descriptorsByName.TryGetValue(fullName, out IDescriptor old)) + IDescriptor old; + if (descriptorsByName.TryGetValue(fullName, out old)) { - if (old is not PackageDescriptor) + if (!(old is PackageDescriptor)) { throw new DescriptorValidationException(file, "\"" + name + @@ -149,9 +153,10 @@ namespace Google.Protobuf.Reflection internal void AddSymbol(IDescriptor descriptor) { ValidateSymbolName(descriptor); - string fullName = descriptor.FullName; + String fullName = descriptor.FullName; - if (descriptorsByName.TryGetValue(fullName, out IDescriptor old)) + IDescriptor old; + if (descriptorsByName.TryGetValue(fullName, out old)) { int dotPos = fullName.LastIndexOf('.'); string message; @@ -176,7 +181,8 @@ namespace Google.Protobuf.Reflection descriptorsByName[fullName] = descriptor; } - private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", FrameworkPortability.CompiledRegexWhereAvailable); + private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", + FrameworkPortability.CompiledRegexWhereAvailable); /// /// Verifies that the descriptor's name is valid (i.e. it contains @@ -185,7 +191,7 @@ namespace Google.Protobuf.Reflection /// private static void ValidateSymbolName(IDescriptor descriptor) { - if (descriptor.Name.Length == 0) + if (descriptor.Name == "") { throw new DescriptorValidationException(descriptor, "Missing name."); } @@ -202,13 +208,15 @@ namespace Google.Protobuf.Reflection /// internal FieldDescriptor FindFieldByNumber(MessageDescriptor messageDescriptor, int number) { - fieldsByNumber.TryGetValue(new ObjectIntPair(messageDescriptor, number), out FieldDescriptor ret); + FieldDescriptor ret; + fieldsByNumber.TryGetValue(new ObjectIntPair(messageDescriptor, number), out ret); return ret; } internal EnumValueDescriptor FindEnumValueByNumber(EnumDescriptor enumDescriptor, int number) { - enumValuesByNumber.TryGetValue(new ObjectIntPair(enumDescriptor, number), out EnumValueDescriptor ret); + EnumValueDescriptor ret; + enumValuesByNumber.TryGetValue(new ObjectIntPair(enumDescriptor, number), out ret); return ret; } @@ -221,7 +229,8 @@ namespace Google.Protobuf.Reflection { // for extensions, we use the extended type, otherwise we use the containing type ObjectIntPair key = new ObjectIntPair(field.Proto.HasExtendee ? field.ExtendeeType : field.ContainingType, field.FieldNumber); - if (fieldsByNumber.TryGetValue(key, out FieldDescriptor old)) + FieldDescriptor old; + if (fieldsByNumber.TryGetValue(key, out old)) { throw new DescriptorValidationException(field, "Field number " + field.FieldNumber + "has already been used in \"" + diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs index f48e8e1..143671d 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs @@ -40,16 +40,25 @@ namespace Google.Protobuf.Reflection /// public sealed class DescriptorValidationException : Exception { + private readonly String name; + private readonly string description; + /// /// The full name of the descriptor where the error occurred. /// - public string ProblemSymbolName { get; } + public String ProblemSymbolName + { + get { return name; } + } /// /// A human-readable description of the error. (The Message property /// is made up of the descriptor's name and this description.) /// - public string Description { get; } + public string Description + { + get { return description; } + } internal DescriptorValidationException(IDescriptor problemDescriptor, string description) : base(problemDescriptor.FullName + ": " + description) @@ -57,15 +66,15 @@ namespace Google.Protobuf.Reflection // Note that problemDescriptor may be partially uninitialized, so we // don't want to expose it directly to the user. So, we only provide // the name and the original proto. - ProblemSymbolName = problemDescriptor.FullName; - Description = description; + name = problemDescriptor.FullName; + this.description = description; } internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) : base(problemDescriptor.FullName + ": " + description, cause) { - ProblemSymbolName = problemDescriptor.FullName; - Description = description; + name = problemDescriptor.FullName; + this.description = description; } } } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index a14cc1d..3f2e1c4 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -41,12 +41,17 @@ namespace Google.Protobuf.Reflection /// public sealed class EnumDescriptor : DescriptorBase { + private readonly EnumDescriptorProto proto; + private readonly MessageDescriptor containingType; + private readonly IList values; + private readonly Type clrType; + internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType) : base(file, file.ComputeFullName(parent, proto.Name), index) { - Proto = proto; - ClrType = clrType; - ContainingType = parent; + this.proto = proto; + this.clrType = clrType; + containingType = parent; if (proto.Value.Count == 0) { @@ -55,13 +60,13 @@ namespace Google.Protobuf.Reflection throw new DescriptorValidationException(this, "Enums must contain at least one value."); } - Values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value, + values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value, (value, i) => new EnumValueDescriptor(value, file, this, i)); File.DescriptorPool.AddSymbol(this); } - internal EnumDescriptorProto Proto { get; } + internal EnumDescriptorProto Proto { get { return proto; } } /// /// Returns a clone of the underlying describing this enum. @@ -74,29 +79,39 @@ namespace Google.Protobuf.Reflection /// /// The brief name of the descriptor's target. /// - public override string Name => Proto.Name; + public override string Name { get { return proto.Name; } } - internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) => - fieldNumber switch + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) { - EnumDescriptorProto.ValueFieldNumber => (IReadOnlyList)Values, - _ => null, - }; + case EnumDescriptorProto.ValueFieldNumber: + return (IReadOnlyList) Values; + default: + return null; + } + } /// /// The CLR type for this enum. For generated code, this will be a CLR enum type. /// - public Type ClrType { get; } + public Type ClrType { get { return clrType; } } /// /// If this is a nested type, get the outer descriptor, otherwise null. /// - public MessageDescriptor ContainingType { get; } + public MessageDescriptor ContainingType + { + get { return containingType; } + } /// /// An unmodifiable list of defined value descriptors for this enum. /// - public IList Values { get; } + public IList Values + { + get { return values; } + } /// /// Finds an enum value by number. If multiple enum values have the diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 7a0cce0..50b26a4 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -40,17 +40,20 @@ namespace Google.Protobuf.Reflection /// public sealed class EnumValueDescriptor : DescriptorBase { + private readonly EnumDescriptor enumDescriptor; + private readonly EnumValueDescriptorProto proto; + internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file, EnumDescriptor parent, int index) : base(file, parent.FullName + "." + proto.Name, index) { - Proto = proto; - EnumDescriptor = parent; + this.proto = proto; + enumDescriptor = parent; file.DescriptorPool.AddSymbol(this); file.DescriptorPool.AddEnumValueByNumber(this); } - internal EnumValueDescriptorProto Proto { get; } + internal EnumValueDescriptorProto Proto { get { return proto; } } /// /// Returns a clone of the underlying describing this enum value. @@ -63,17 +66,17 @@ namespace Google.Protobuf.Reflection /// /// Returns the name of the enum value described by this object. /// - public override string Name => Proto.Name; + public override string Name { get { return proto.Name; } } /// /// Returns the number associated with this enum value. /// - public int Number => Proto.Number; + public int Number { get { return Proto.Number; } } /// /// Returns the enum descriptor that this value is part of. /// - public EnumDescriptor EnumDescriptor { get; } + public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } } /// /// The (possibly empty) set of custom options for this enum value. diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs index 1e10060..ca874f9 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs @@ -107,7 +107,8 @@ namespace Google.Protobuf.Reflection { descriptor.CrossLink(); - if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out IList list)) + IList list; + if (!declarationOrder.TryGetValue(descriptor.ExtendeeType, out list)) { list = new List(); declarationOrder.Add(descriptor.ExtendeeType, list); diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs index 156025d..85b7d39 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs @@ -42,14 +42,15 @@ namespace Google.Protobuf.Reflection internal abstract class FieldAccessorBase : IFieldAccessor { private readonly Func getValueDelegate; + private readonly FieldDescriptor descriptor; internal FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor) { - Descriptor = descriptor; + this.descriptor = descriptor; getValueDelegate = ReflectionUtil.CreateFuncIMessageObject(property.GetGetMethod()); } - public FieldDescriptor Descriptor { get; } + public FieldDescriptor Descriptor { get { return descriptor; } } public object GetValue(IMessage message) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index e4fd7d2..84ad49d 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -176,28 +176,47 @@ namespace Google.Protobuf.Reflection /// private static FieldType GetFieldTypeFromProtoType(FieldDescriptorProto.Types.Type type) { - return type switch + switch (type) { - FieldDescriptorProto.Types.Type.Double => FieldType.Double, - FieldDescriptorProto.Types.Type.Float => FieldType.Float, - FieldDescriptorProto.Types.Type.Int64 => FieldType.Int64, - FieldDescriptorProto.Types.Type.Uint64 => FieldType.UInt64, - FieldDescriptorProto.Types.Type.Int32 => FieldType.Int32, - FieldDescriptorProto.Types.Type.Fixed64 => FieldType.Fixed64, - FieldDescriptorProto.Types.Type.Fixed32 => FieldType.Fixed32, - FieldDescriptorProto.Types.Type.Bool => FieldType.Bool, - FieldDescriptorProto.Types.Type.String => FieldType.String, - FieldDescriptorProto.Types.Type.Group => FieldType.Group, - FieldDescriptorProto.Types.Type.Message => FieldType.Message, - FieldDescriptorProto.Types.Type.Bytes => FieldType.Bytes, - FieldDescriptorProto.Types.Type.Uint32 => FieldType.UInt32, - FieldDescriptorProto.Types.Type.Enum => FieldType.Enum, - FieldDescriptorProto.Types.Type.Sfixed32 => FieldType.SFixed32, - FieldDescriptorProto.Types.Type.Sfixed64 => FieldType.SFixed64, - FieldDescriptorProto.Types.Type.Sint32 => FieldType.SInt32, - FieldDescriptorProto.Types.Type.Sint64 => FieldType.SInt64, - _ => throw new ArgumentException("Invalid type specified"), - }; + case FieldDescriptorProto.Types.Type.Double: + return FieldType.Double; + case FieldDescriptorProto.Types.Type.Float: + return FieldType.Float; + case FieldDescriptorProto.Types.Type.Int64: + return FieldType.Int64; + case FieldDescriptorProto.Types.Type.Uint64: + return FieldType.UInt64; + case FieldDescriptorProto.Types.Type.Int32: + return FieldType.Int32; + case FieldDescriptorProto.Types.Type.Fixed64: + return FieldType.Fixed64; + case FieldDescriptorProto.Types.Type.Fixed32: + return FieldType.Fixed32; + case FieldDescriptorProto.Types.Type.Bool: + return FieldType.Bool; + case FieldDescriptorProto.Types.Type.String: + return FieldType.String; + case FieldDescriptorProto.Types.Type.Group: + return FieldType.Group; + case FieldDescriptorProto.Types.Type.Message: + return FieldType.Message; + case FieldDescriptorProto.Types.Type.Bytes: + return FieldType.Bytes; + case FieldDescriptorProto.Types.Type.Uint32: + return FieldType.UInt32; + case FieldDescriptorProto.Types.Type.Enum: + return FieldType.Enum; + case FieldDescriptorProto.Types.Type.Sfixed32: + return FieldType.SFixed32; + case FieldDescriptorProto.Types.Type.Sfixed64: + return FieldType.SFixed64; + case FieldDescriptorProto.Types.Type.Sint32: + return FieldType.SInt32; + case FieldDescriptorProto.Types.Type.Sint64: + return FieldType.SInt64; + default: + throw new ArgumentException("Invalid type specified"); + } } /// @@ -372,11 +391,11 @@ namespace Google.Protobuf.Reflection if (fieldType == FieldType.Message || fieldType == FieldType.Group) { - if (typeDescriptor is not MessageDescriptor m) + if (!(typeDescriptor is MessageDescriptor)) { throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a message type."); } - messageType = m; + messageType = (MessageDescriptor) typeDescriptor; if (Proto.HasDefaultValue) { @@ -385,11 +404,11 @@ namespace Google.Protobuf.Reflection } else if (fieldType == FieldType.Enum) { - if (typeDescriptor is not EnumDescriptor e) + if (!(typeDescriptor is EnumDescriptor)) { throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not an enum type."); } - enumType = e; + enumType = (EnumDescriptor) typeDescriptor; } else { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index cb711de..d7701da 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -35,6 +35,7 @@ using Google.Protobuf.WellKnownTypes; using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Threading; using static Google.Protobuf.Reflection.SourceCodeInfo.Types; @@ -172,18 +173,25 @@ namespace Google.Protobuf.Reflection return list[index]; } - private IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) => - fieldNumber switch + private IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) { - FileDescriptorProto.ServiceFieldNumber => (IReadOnlyList)Services, - FileDescriptorProto.MessageTypeFieldNumber => (IReadOnlyList)MessageTypes, - FileDescriptorProto.EnumTypeFieldNumber => (IReadOnlyList)EnumTypes, - _ => null, - }; + case FileDescriptorProto.ServiceFieldNumber: + return (IReadOnlyList) Services; + case FileDescriptorProto.MessageTypeFieldNumber: + return (IReadOnlyList) MessageTypes; + case FileDescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; + } + } internal DescriptorDeclaration GetDeclaration(IDescriptor descriptor) { - declarations.Value.TryGetValue(descriptor, out DescriptorDeclaration declaration); + DescriptorDeclaration declaration; + declarations.Value.TryGetValue(descriptor, out declaration); return declaration; } @@ -219,7 +227,8 @@ namespace Google.Protobuf.Reflection throw new DescriptorValidationException(@this, "Invalid public dependency index."); } string name = proto.Dependency[index]; - if (!nameToFileMap.TryGetValue(name, out FileDescriptor file)) + FileDescriptor file; + if (!nameToFileMap.TryGetValue(name, out file)) { if (!allowUnknownDependencies) { @@ -323,7 +332,7 @@ namespace Google.Protobuf.Reflection /// The unqualified type name to look for. /// The type of descriptor to look for /// The type's descriptor, or null if not found. - public T FindTypeByName(string name) + public T FindTypeByName(String name) where T : class, IDescriptor { // Don't allow looking up nested types. This will make optimization @@ -498,7 +507,8 @@ namespace Google.Protobuf.Reflection var dependencies = new List(); foreach (var dependencyName in proto.Dependency) { - if (!descriptorsByName.TryGetValue(dependencyName, out FileDescriptor dependency)) + FileDescriptor dependency; + if (!descriptorsByName.TryGetValue(dependencyName, out dependency)) { throw new ArgumentException($"Dependency missing: {dependencyName}"); } @@ -555,7 +565,7 @@ namespace Google.Protobuf.Reflection /// /// The file descriptor for descriptor.proto. /// - public static FileDescriptor DescriptorProtoFileDescriptor => DescriptorReflection.Descriptor; + public static FileDescriptor DescriptorProtoFileDescriptor { get { return DescriptorReflection.Descriptor; } } /// /// The (possibly empty) set of custom options for this file. diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs index dbf16c6..d0a495b 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs @@ -29,7 +29,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - using System; using System.Diagnostics.CodeAnalysis; @@ -58,7 +57,7 @@ namespace Google.Protobuf.Reflection /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. /// [DynamicallyAccessedMembers(MessageAccessibility)] - public Type ClrType { get; } + public Type ClrType { get; private set; } /// /// Irrelevant for file descriptors; the parser for message descriptors. diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index f2bb61c..40a6ff8 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -36,6 +36,10 @@ using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; +#if NET35 +// Needed for ReadOnlyDictionary, which does not exist in .NET 3.5 +using Google.Protobuf.Collections; +#endif namespace Google.Protobuf.Reflection { @@ -130,14 +134,20 @@ namespace Google.Protobuf.Reflection /// public override string Name => Proto.Name; - internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) => - fieldNumber switch + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) { - DescriptorProto.FieldFieldNumber => (IReadOnlyList)fieldsInDeclarationOrder, - DescriptorProto.NestedTypeFieldNumber => (IReadOnlyList)NestedTypes, - DescriptorProto.EnumTypeFieldNumber => (IReadOnlyList)EnumTypes, - _ => null, - }; + case DescriptorProto.FieldFieldNumber: + return (IReadOnlyList) fieldsInDeclarationOrder; + case DescriptorProto.NestedTypeFieldNumber: + return (IReadOnlyList) NestedTypes; + case DescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; + } + } internal DescriptorProto Proto { get; } @@ -266,7 +276,7 @@ namespace Google.Protobuf.Reflection /// /// The unqualified name of the field (e.g. "foo"). /// The field's descriptor, or null if not found. - public FieldDescriptor FindFieldByName(string name) => File.DescriptorPool.FindSymbol(FullName + "." + name); + public FieldDescriptor FindFieldByName(String name) => File.DescriptorPool.FindSymbol(FullName + "." + name); /// /// Finds a field by field number. diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index 4f0ea43..f5ecf2e 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -40,31 +40,35 @@ namespace Google.Protobuf.Reflection /// public sealed class MethodDescriptor : DescriptorBase { + private readonly MethodDescriptorProto proto; + private readonly ServiceDescriptor service; + private MessageDescriptor inputType; + private MessageDescriptor outputType; /// /// The service this method belongs to. /// - public ServiceDescriptor Service { get; } + public ServiceDescriptor Service { get { return service; } } /// /// The method's input type. /// - public MessageDescriptor InputType { get; private set; } + public MessageDescriptor InputType { get { return inputType; } } /// /// The method's input type. /// - public MessageDescriptor OutputType { get; private set; } + public MessageDescriptor OutputType { get { return outputType; } } /// /// Indicates if client streams multiple requests. /// - public bool IsClientStreaming => Proto.ClientStreaming; + public bool IsClientStreaming { get { return proto.ClientStreaming; } } /// /// Indicates if server streams multiple responses. /// - public bool IsServerStreaming => Proto.ServerStreaming; + public bool IsServerStreaming { get { return proto.ServerStreaming; } } /// /// The (possibly empty) set of custom options for this method. @@ -87,7 +91,7 @@ namespace Google.Protobuf.Reflection public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable c ? c.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -103,12 +107,12 @@ namespace Google.Protobuf.Reflection ServiceDescriptor parent, int index) : base(file, parent.FullName + "." + proto.Name, index) { - Proto = proto; - Service = parent; + this.proto = proto; + service = parent; file.DescriptorPool.AddSymbol(this); } - internal MethodDescriptorProto Proto { get; private set; } + internal MethodDescriptorProto Proto { get { return proto; } } /// /// Returns a clone of the underlying describing this method. @@ -121,23 +125,23 @@ namespace Google.Protobuf.Reflection /// /// The brief name of the descriptor's target. /// - public override string Name => Proto.Name; + public override string Name { get { return proto.Name; } } internal void CrossLink() { IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this); - if (lookup is not MessageDescriptor inpoutType) + if (!(lookup is MessageDescriptor)) { throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type."); } - InputType = inpoutType; + inputType = (MessageDescriptor) lookup; lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this); - if (lookup is not MessageDescriptor outputType) + if (!(lookup is MessageDescriptor)) { throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type."); } - OutputType = outputType; + outputType = (MessageDescriptor) lookup; } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs index 880716a..63f5228 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs @@ -60,5 +60,6 @@ namespace Google.Protobuf.Reflection Name = ProtoPreconditions.CheckNotNull(name, nameof(name)); PreferredAlias = true; } + } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs index 0b6de81..e547d83 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs @@ -39,15 +39,30 @@ namespace Google.Protobuf.Reflection /// internal sealed class PackageDescriptor : IDescriptor { + private readonly string name; + private readonly string fullName; + private readonly FileDescriptor file; + internal PackageDescriptor(string name, string fullName, FileDescriptor file) { - File = file; - FullName = fullName; - Name = name; + this.file = file; + this.fullName = fullName; + this.name = name; } - public string Name { get; } - public string FullName { get; } - public FileDescriptor File { get; } + public string Name + { + get { return name; } + } + + public string FullName + { + get { return fullName; } + } + + public FileDescriptor File + { + get { return file; } + } } } \ No newline at end of file diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs index 2a6afdb..73efcc2 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs @@ -221,18 +221,20 @@ namespace Google.Protobuf.Reflection public object GetExtension(IMessage message) { - if (message is not T1 extensionMessage) + if (!(message is T1)) { throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); } - if (extension is Extension ext13) + T1 extensionMessage = (T1)message; + + if (extension is Extension) { - return extensionMessage.GetExtension(ext13); + return extensionMessage.GetExtension(extension as Extension); } - else if (extension is RepeatedExtension repeatedExt13) + else if (extension is RepeatedExtension) { - return extensionMessage.GetOrInitializeExtension(repeatedExt13); + return extensionMessage.GetOrInitializeExtension(extension as RepeatedExtension); } else { @@ -242,14 +244,16 @@ namespace Google.Protobuf.Reflection public bool HasExtension(IMessage message) { - if (message is not T1 extensionMessage) + if (!(message is T1)) { throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); } - if (extension is Extension ext13) + T1 extensionMessage = (T1)message; + + if (extension is Extension) { - return extensionMessage.HasExtension(ext13); + return extensionMessage.HasExtension(extension as Extension); } else if (extension is RepeatedExtension) { @@ -263,14 +267,16 @@ namespace Google.Protobuf.Reflection public void SetExtension(IMessage message, object value) { - if (message is not T1 extensionMessage) + if (!(message is T1)) { throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); } - if (extension is Extension ext13) + T1 extensionMessage = (T1)message; + + if (extension is Extension) { - extensionMessage.SetExtension(ext13, (T3)value); + extensionMessage.SetExtension(extension as Extension, (T3)value); } else if (extension is RepeatedExtension) { @@ -284,18 +290,20 @@ namespace Google.Protobuf.Reflection public void ClearExtension(IMessage message) { - if (message is not T1 extensionMessage) + if (!(message is T1)) { throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); } - if (extension is Extension ext13) + T1 extensionMessage = (T1)message; + + if (extension is Extension) { - extensionMessage.ClearExtension(ext13); + extensionMessage.ClearExtension(extension as Extension); } - else if (extension is RepeatedExtension repeatedExt13) + else if (extension is RepeatedExtension) { - extensionMessage.GetExtension(repeatedExt13).Clear(); + extensionMessage.GetExtension(extension as RepeatedExtension).Clear(); } else { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs index 2073be3..afb4a69 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs @@ -60,5 +60,6 @@ namespace Google.Protobuf.Reflection { throw new InvalidOperationException("SetValue is not implemented for repeated fields"); } + } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index 55d812b..944ea11 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -33,6 +33,7 @@ using Google.Protobuf.Collections; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Google.Protobuf.Reflection { @@ -41,11 +42,14 @@ namespace Google.Protobuf.Reflection /// public sealed class ServiceDescriptor : DescriptorBase { + private readonly ServiceDescriptorProto proto; + private readonly IList methods; + internal ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index) : base(file, file.ComputeFullName(null, proto.Name), index) { - Proto = proto; - Methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method, + this.proto = proto; + methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method, (method, i) => new MethodDescriptor(method, file, this, i)); file.DescriptorPool.AddSymbol(this); @@ -54,16 +58,20 @@ namespace Google.Protobuf.Reflection /// /// The brief name of the descriptor's target. /// - public override string Name => Proto.Name; + public override string Name { get { return proto.Name; } } - internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) => - fieldNumber switch + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) { - ServiceDescriptorProto.MethodFieldNumber => (IReadOnlyList)Methods, - _ => null, - }; + case ServiceDescriptorProto.MethodFieldNumber: + return (IReadOnlyList) methods; + default: + return null; + } + } - internal ServiceDescriptorProto Proto { get; } + internal ServiceDescriptorProto Proto { get { return proto; } } /// /// Returns a clone of the underlying describing this service. @@ -76,15 +84,20 @@ namespace Google.Protobuf.Reflection /// /// An unmodifiable list of methods in this service. /// - public IList Methods { get; } + public IList Methods + { + get { return methods; } + } /// /// Finds a method by name. /// /// The unqualified name of the method (e.g. "Foo"). /// The method's descriptor, or null if not found. - public MethodDescriptor FindMethodByName(string name) => - File.DescriptorPool.FindSymbol(FullName + "." + name); + public MethodDescriptor FindMethodByName(String name) + { + return File.DescriptorPool.FindSymbol(FullName + "." + name); + } /// /// The (possibly empty) set of custom options for this service. @@ -121,7 +134,7 @@ namespace Google.Protobuf.Reflection internal void CrossLink() { - foreach (MethodDescriptor method in Methods) + foreach (MethodDescriptor method in methods) { method.CrossLink(); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs index 284effe..ac35e72 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs @@ -31,6 +31,7 @@ #endregion using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Reflection; using Google.Protobuf.Compatibility; @@ -107,7 +108,7 @@ namespace Google.Protobuf.Reflection // Primitive proto3 fields without the optional keyword, which aren't in oneofs. else { - hasDelegate = message => throw new InvalidOperationException("Presence is not implemented for this field"); + hasDelegate = message => { throw new InvalidOperationException("Presence is not implemented for this field"); }; // While presence isn't supported, clearing still is; it's just setting to a default value. object defaultValue = GetDefaultValue(descriptor); @@ -115,21 +116,42 @@ namespace Google.Protobuf.Reflection } } - private static object GetDefaultValue(FieldDescriptor descriptor) => - descriptor.FieldType switch + private static object GetDefaultValue(FieldDescriptor descriptor) + { + switch (descriptor.FieldType) { - FieldType.Bool => false, - FieldType.Bytes => ByteString.Empty, - FieldType.String => "", - FieldType.Double => 0.0, - FieldType.SInt32 or FieldType.Int32 or FieldType.SFixed32 or FieldType.Enum => 0, - FieldType.Fixed32 or FieldType.UInt32 => (uint)0, - FieldType.Fixed64 or FieldType.UInt64 => 0UL, - FieldType.SFixed64 or FieldType.Int64 or FieldType.SInt64 => 0L, - FieldType.Float => 0f, - FieldType.Message or FieldType.Group => null, - _ => throw new ArgumentException("Invalid field type"), - }; + case FieldType.Bool: + return false; + case FieldType.Bytes: + return ByteString.Empty; + case FieldType.String: + return ""; + case FieldType.Double: + return 0.0; + case FieldType.SInt32: + case FieldType.Int32: + case FieldType.SFixed32: + case FieldType.Enum: + return 0; + case FieldType.Fixed32: + case FieldType.UInt32: + return (uint)0; + case FieldType.Fixed64: + case FieldType.UInt64: + return 0UL; + case FieldType.SFixed64: + case FieldType.Int64: + case FieldType.SInt64: + return 0L; + case FieldType.Float: + return 0f; + case FieldType.Message: + case FieldType.Group: // Never expect to get this, but... + return null; + default: + throw new ArgumentException("Invalid field type"); + } + } public override void Clear(IMessage message) => clearDelegate(message); public override bool HasValue(IMessage message) => hasDelegate(message); diff --git a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs index 222bc7e..e94e3e6 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs @@ -29,7 +29,6 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion - using System.Collections.Generic; using System.Linq; @@ -61,8 +60,9 @@ namespace Google.Protobuf.Reflection /// if there is no such message descriptor. public MessageDescriptor Find(string fullName) { + MessageDescriptor ret; // Ignore the return value as ret will end up with the right value either way. - fullNameToMessageMap.TryGetValue(fullName, out MessageDescriptor ret); + fullNameToMessageMap.TryGetValue(fullName, out ret); return ret; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/UnknownField.cs b/libs/protobuf/csharp/src/Google.Protobuf/UnknownField.cs index abec108..4793a64 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/UnknownField.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/UnknownField.cs @@ -30,7 +30,9 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using Google.Protobuf.Collections; namespace Google.Protobuf @@ -71,12 +73,13 @@ namespace Google.Protobuf { return true; } - return other is UnknownField otherField - && Lists.Equals(varintList, otherField.varintList) - && Lists.Equals(fixed32List, otherField.fixed32List) - && Lists.Equals(fixed64List, otherField.fixed64List) - && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList) - && Lists.Equals(groupList, otherField.groupList); + UnknownField otherField = other as UnknownField; + return otherField != null + && Lists.Equals(varintList, otherField.varintList) + && Lists.Equals(fixed32List, otherField.fixed32List) + && Lists.Equals(fixed64List, otherField.fixed64List) + && Lists.Equals(lengthDelimitedList, otherField.lengthDelimitedList) + && Lists.Equals(groupList, otherField.groupList); } /// diff --git a/libs/protobuf/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/libs/protobuf/csharp/src/Google.Protobuf/UnknownFieldSet.cs index b97eb5e..9888dd1 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/UnknownFieldSet.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/UnknownFieldSet.cs @@ -32,7 +32,9 @@ using System; using System.Collections.Generic; +using System.IO; using System.Security; +using Google.Protobuf.Reflection; namespace Google.Protobuf { @@ -47,13 +49,14 @@ namespace Google.Protobuf /// public sealed partial class UnknownFieldSet { - private readonly IDictionary fields = new Dictionary(); + private readonly IDictionary fields; /// /// Creates a new UnknownFieldSet. /// internal UnknownFieldSet() { + this.fields = new Dictionary(); } /// @@ -122,7 +125,8 @@ namespace Google.Protobuf } foreach (KeyValuePair leftEntry in fields) { - if (!otherFields.TryGetValue(leftEntry.Key, out UnknownField rightValue)) + UnknownField rightValue; + if (!otherFields.TryGetValue(leftEntry.Key, out rightValue)) { return false; } @@ -166,7 +170,8 @@ namespace Google.Protobuf return null; } - if (fields.TryGetValue(number, out UnknownField existing)) + UnknownField existing; + if (fields.TryGetValue(number, out existing)) { return existing; } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs index 04b64ab..5e7b6d5 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs @@ -112,7 +112,7 @@ namespace Google.Protobuf.WellKnownTypes T target = new T(); if (GetTypeName(TypeUrl) != target.Descriptor.FullName) { - result = default; // Can't use null as there's no class constraint, but this always *will* be null in real usage. + result = default(T); // Can't use null as there's no class constraint, but this always *will* be null in real usage. return false; } target.MergeFrom(Value); @@ -120,26 +120,6 @@ namespace Google.Protobuf.WellKnownTypes return true; } - /// - /// Attempts to unpack the content of this Any message into one of the message types - /// in the given type registry, based on the type URL. - /// - /// The type registry to consult for messages. - /// The unpacked message, or null if no matching message was found. - public IMessage Unpack(TypeRegistry registry) - { - string typeName = GetTypeName(TypeUrl); - MessageDescriptor descriptor = registry.Find(typeName); - if (descriptor == null) - { - return null; - } - - var message = descriptor.Parser.CreateTemplate(); - message.MergeFrom(Value); - return message; - } - /// /// Packs the specified message into an Any message using a type URL prefix of "type.googleapis.com". /// diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs index cdf3c31..9a468fc 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs @@ -38,7 +38,7 @@ namespace Google.Protobuf.WellKnownTypes { // Manually-written partial class for the Duration well-known type, // providing a conversion to TimeSpan and convenience operators. - public partial class Duration : ICustomDiagnosticMessage, IComparable + public partial class Duration : ICustomDiagnosticMessage { /// /// The number of nanoseconds in a second. @@ -266,26 +266,5 @@ namespace Google.Protobuf.WellKnownTypes } } } - - - /// - /// Given another duration, returns 0 if the durations are equivalent, -1 if this duration is shorter than the other, and 1 otherwise. - /// - /// - /// This method expects that both durations are normalized; that is, that the values of - /// and are within the documented bounds. - /// If either value is not normalized, the results of this method are unspecified. - /// - /// The duration to compare with this object. - /// An integer indicating whether this duration is shorter or longer than . - public int CompareTo(Duration other) - { - return other == null ? 1 - : Seconds < other.Seconds ? -1 - : Seconds > other.Seconds ? 1 - : Nanos < other.Nanos ? -1 - : Nanos > other.Nanos ? 1 - : 0; - } } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs index dd00e2d..58a33cb 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs @@ -63,7 +63,12 @@ namespace Google.Protobuf.WellKnownTypes if (firstInvalid == null) { var writer = new StringWriter(); +#if NET35 + var query = paths.Select(JsonFormatter.ToJsonName); + JsonFormatter.WriteString(writer, string.Join(",", query.ToArray())); +#else JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToJsonName))); +#endif return writer.ToString(); } else diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs index aa25686..8c1eec5 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs @@ -212,7 +212,7 @@ namespace Google.Protobuf.WellKnownTypes { if (other == null) { return; } - fields_.MergeFrom(other.fields_); + fields_.Add(other.fields_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs index c52147f..2f5172f 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs @@ -59,8 +59,8 @@ namespace Google.Protobuf.WellKnownTypes /// The difference between the two specified timestamps. public static Duration operator -(Timestamp lhs, Timestamp rhs) { - ProtoPreconditions.CheckNotNull(lhs, nameof(lhs)); - ProtoPreconditions.CheckNotNull(rhs, nameof(rhs)); + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); checked { return Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); @@ -75,8 +75,8 @@ namespace Google.Protobuf.WellKnownTypes /// The result of adding the duration to the timestamp. public static Timestamp operator +(Timestamp lhs, Duration rhs) { - ProtoPreconditions.CheckNotNull(lhs, nameof(lhs)); - ProtoPreconditions.CheckNotNull(rhs, nameof(rhs)); + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); checked { return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos); @@ -91,8 +91,8 @@ namespace Google.Protobuf.WellKnownTypes /// The result of subtracting the duration from the timestamp. public static Timestamp operator -(Timestamp lhs, Duration rhs) { - ProtoPreconditions.CheckNotNull(lhs, nameof(lhs)); - ProtoPreconditions.CheckNotNull(rhs, nameof(rhs)); + ProtoPreconditions.CheckNotNull(lhs, "lhs"); + ProtoPreconditions.CheckNotNull(rhs, "rhs"); checked { return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos); @@ -308,7 +308,7 @@ namespace Google.Protobuf.WellKnownTypes /// true if the two timestamps refer to the same nanosecond public static bool operator ==(Timestamp a, Timestamp b) { - return ReferenceEquals(a, b) || (a is null ? (b is null) : a.Equals(b)); + return ReferenceEquals(a, b) || (ReferenceEquals(a, null) ? (ReferenceEquals(b, null) ? true : false) : a.Equals(b)); } /// diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs index a6846e7..d34b560 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs @@ -41,7 +41,7 @@ namespace Google.Protobuf.WellKnownTypes /// A newly-created Value message with the given value. public static Value ForString(string value) { - ProtoPreconditions.CheckNotNull(value, nameof(value)); + ProtoPreconditions.CheckNotNull(value, "value"); return new Value { StringValue = value }; } @@ -81,7 +81,7 @@ namespace Google.Protobuf.WellKnownTypes /// A newly-created Value message an initial list value. public static Value ForList(params Value[] values) { - ProtoPreconditions.CheckNotNull(values, nameof(values)); + ProtoPreconditions.CheckNotNull(values, "values"); return new Value { ListValue = new ListValue { Values = { values } } }; } @@ -92,7 +92,7 @@ namespace Google.Protobuf.WellKnownTypes /// A newly-created Value message an initial struct value. public static Value ForStruct(Struct value) { - ProtoPreconditions.CheckNotNull(value, nameof(value)); + ProtoPreconditions.CheckNotNull(value, "value"); return new Value { StructValue = value }; } } diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WriteBufferHelper.cs b/libs/protobuf/csharp/src/Google.Protobuf/WriteBufferHelper.cs index 9230aa6..f2a59bc 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WriteBufferHelper.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WriteBufferHelper.cs @@ -32,6 +32,7 @@ using System; using System.Buffers; +using System.IO; using System.Runtime.CompilerServices; using System.Security; diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WriteContext.cs b/libs/protobuf/csharp/src/Google.Protobuf/WriteContext.cs index 082c20e..e822e1d 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WriteContext.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WriteContext.cs @@ -32,8 +32,14 @@ using System; using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; +using System.Text; +using Google.Protobuf.Collections; namespace Google.Protobuf { @@ -95,112 +101,166 @@ namespace Google.Protobuf /// Writes a double field value, without a tag. /// /// The value to write - public void WriteDouble(double value) => WritingPrimitives.WriteDouble(ref buffer, ref state, value); + public void WriteDouble(double value) + { + WritingPrimitives.WriteDouble(ref buffer, ref state, value); + } /// /// Writes a float field value, without a tag. /// /// The value to write - public void WriteFloat(float value) => WritingPrimitives.WriteFloat(ref buffer, ref state, value); + public void WriteFloat(float value) + { + WritingPrimitives.WriteFloat(ref buffer, ref state, value); + } /// /// Writes a uint64 field value, without a tag. /// /// The value to write - public void WriteUInt64(ulong value) => WritingPrimitives.WriteUInt64(ref buffer, ref state, value); + public void WriteUInt64(ulong value) + { + WritingPrimitives.WriteUInt64(ref buffer, ref state, value); + } /// /// Writes an int64 field value, without a tag. /// /// The value to write - public void WriteInt64(long value) => WritingPrimitives.WriteInt64(ref buffer, ref state, value); + public void WriteInt64(long value) + { + WritingPrimitives.WriteInt64(ref buffer, ref state, value); + } /// /// Writes an int32 field value, without a tag. /// /// The value to write - public void WriteInt32(int value) => WritingPrimitives.WriteInt32(ref buffer, ref state, value); + public void WriteInt32(int value) + { + WritingPrimitives.WriteInt32(ref buffer, ref state, value); + } /// /// Writes a fixed64 field value, without a tag. /// /// The value to write - public void WriteFixed64(ulong value) => WritingPrimitives.WriteFixed64(ref buffer, ref state, value); + public void WriteFixed64(ulong value) + { + WritingPrimitives.WriteFixed64(ref buffer, ref state, value); + } /// /// Writes a fixed32 field value, without a tag. /// /// The value to write - public void WriteFixed32(uint value) => WritingPrimitives.WriteFixed32(ref buffer, ref state, value); + public void WriteFixed32(uint value) + { + WritingPrimitives.WriteFixed32(ref buffer, ref state, value); + } /// /// Writes a bool field value, without a tag. /// /// The value to write - public void WriteBool(bool value) => WritingPrimitives.WriteBool(ref buffer, ref state, value); + public void WriteBool(bool value) + { + WritingPrimitives.WriteBool(ref buffer, ref state, value); + } /// /// Writes a string field value, without a tag. /// The data is length-prefixed. /// /// The value to write - public void WriteString(string value) => WritingPrimitives.WriteString(ref buffer, ref state, value); + public void WriteString(string value) + { + WritingPrimitives.WriteString(ref buffer, ref state, value); + } /// /// Writes a message, without a tag. /// The data is length-prefixed. /// /// The value to write - public void WriteMessage(IMessage value) => WritingPrimitivesMessages.WriteMessage(ref this, value); + public void WriteMessage(IMessage value) + { + WritingPrimitivesMessages.WriteMessage(ref this, value); + } /// /// Writes a group, without a tag, to the stream. /// /// The value to write - public void WriteGroup(IMessage value) => WritingPrimitivesMessages.WriteGroup(ref this, value); + public void WriteGroup(IMessage value) + { + WritingPrimitivesMessages.WriteGroup(ref this, value); + } /// /// Write a byte string, without a tag, to the stream. /// The data is length-prefixed. /// /// The value to write - public void WriteBytes(ByteString value) => WritingPrimitives.WriteBytes(ref buffer, ref state, value); + public void WriteBytes(ByteString value) + { + WritingPrimitives.WriteBytes(ref buffer, ref state, value); + } /// /// Writes a uint32 value, without a tag. /// /// The value to write - public void WriteUInt32(uint value) => WritingPrimitives.WriteUInt32(ref buffer, ref state, value); + public void WriteUInt32(uint value) + { + WritingPrimitives.WriteUInt32(ref buffer, ref state, value); + } /// /// Writes an enum value, without a tag. /// /// The value to write - public void WriteEnum(int value) => WritingPrimitives.WriteEnum(ref buffer, ref state, value); + public void WriteEnum(int value) + { + WritingPrimitives.WriteEnum(ref buffer, ref state, value); + } /// /// Writes an sfixed32 value, without a tag. /// /// The value to write. - public void WriteSFixed32(int value) => WritingPrimitives.WriteSFixed32(ref buffer, ref state, value); + public void WriteSFixed32(int value) + { + WritingPrimitives.WriteSFixed32(ref buffer, ref state, value); + } /// /// Writes an sfixed64 value, without a tag. /// /// The value to write - public void WriteSFixed64(long value) => WritingPrimitives.WriteSFixed64(ref buffer, ref state, value); + public void WriteSFixed64(long value) + { + WritingPrimitives.WriteSFixed64(ref buffer, ref state, value); + } /// /// Writes an sint32 value, without a tag. /// /// The value to write - public void WriteSInt32(int value) => WritingPrimitives.WriteSInt32(ref buffer, ref state, value); + public void WriteSInt32(int value) + { + WritingPrimitives.WriteSInt32(ref buffer, ref state, value); + } /// /// Writes an sint64 value, without a tag. /// /// The value to write - public void WriteSInt64(long value) => WritingPrimitives.WriteSInt64(ref buffer, ref state, value); + public void WriteSInt64(long value) + { + WritingPrimitives.WriteSInt64(ref buffer, ref state, value); + } /// /// Writes a length (in bytes) for length-delimited data. @@ -209,33 +269,48 @@ namespace Google.Protobuf /// This method simply writes a rawint, but exists for clarity in calling code. /// /// Length value, in bytes. - public void WriteLength(int length) => WritingPrimitives.WriteLength(ref buffer, ref state, length); + public void WriteLength(int length) + { + WritingPrimitives.WriteLength(ref buffer, ref state, length); + } /// /// Encodes and writes a tag. /// /// The number of the field to write the tag for /// The wire format type of the tag to write - public void WriteTag(int fieldNumber, WireFormat.WireType type) => WritingPrimitives.WriteTag(ref buffer, ref state, fieldNumber, type); + public void WriteTag(int fieldNumber, WireFormat.WireType type) + { + WritingPrimitives.WriteTag(ref buffer, ref state, fieldNumber, type); + } /// /// Writes an already-encoded tag. /// /// The encoded tag - public void WriteTag(uint tag) => WritingPrimitives.WriteTag(ref buffer, ref state, tag); + public void WriteTag(uint tag) + { + WritingPrimitives.WriteTag(ref buffer, ref state, tag); + } /// /// Writes the given single-byte tag. /// /// The encoded tag - public void WriteRawTag(byte b1) => WritingPrimitives.WriteRawTag(ref buffer, ref state, b1); + public void WriteRawTag(byte b1) + { + WritingPrimitives.WriteRawTag(ref buffer, ref state, b1); + } /// /// Writes the given two-byte tag. /// /// The first byte of the encoded tag /// The second byte of the encoded tag - public void WriteRawTag(byte b1, byte b2) => WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2); + public void WriteRawTag(byte b1, byte b2) + { + WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2); + } /// /// Writes the given three-byte tag. @@ -243,7 +318,10 @@ namespace Google.Protobuf /// The first byte of the encoded tag /// The second byte of the encoded tag /// The third byte of the encoded tag - public void WriteRawTag(byte b1, byte b2, byte b3) => WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3); + public void WriteRawTag(byte b1, byte b2, byte b3) + { + WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3); + } /// /// Writes the given four-byte tag. @@ -252,7 +330,10 @@ namespace Google.Protobuf /// The second byte of the encoded tag /// The third byte of the encoded tag /// The fourth byte of the encoded tag - public void WriteRawTag(byte b1, byte b2, byte b3, byte b4) => WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4); + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4) + { + WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4); + } /// /// Writes the given five-byte tag. @@ -262,11 +343,20 @@ namespace Google.Protobuf /// The third byte of the encoded tag /// The fourth byte of the encoded tag /// The fifth byte of the encoded tag - public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5) => WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4, b5); + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5) + { + WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4, b5); + } - internal void Flush() => WriteBufferHelper.Flush(ref buffer, ref state); + internal void Flush() + { + WriteBufferHelper.Flush(ref buffer, ref state); + } - internal void CheckNoSpaceLeft() => WriteBufferHelper.CheckNoSpaceLeft(ref state); + internal void CheckNoSpaceLeft() + { + WriteBufferHelper.CheckNoSpaceLeft(ref state); + } internal void CopyStateTo(CodedOutputStream output) { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WriterInternalState.cs b/libs/protobuf/csharp/src/Google.Protobuf/WriterInternalState.cs index ea4515a..a779305 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WriterInternalState.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WriterInternalState.cs @@ -30,8 +30,20 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using Google.Protobuf.Collections; + namespace Google.Protobuf { + // warning: this is a mutable struct, so it needs to be only passed as a ref! internal struct WriterInternalState { diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitives.cs b/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitives.cs index cfba5c7..8beefc5 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitives.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitives.cs @@ -32,6 +32,7 @@ using System; using System.Buffers.Binary; +using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; #if GOOGLE_PROTOBUF_SIMD diff --git a/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs b/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs index 6e70ee2..cd2d437 100644 --- a/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs +++ b/libs/protobuf/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs @@ -30,7 +30,9 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices.ComTypes; using System.Security; namespace Google.Protobuf diff --git a/libs/protobuf/docs/cmake_protobuf_generate.md b/libs/protobuf/docs/cmake_protobuf_generate.md deleted file mode 100644 index d3e9110..0000000 --- a/libs/protobuf/docs/cmake_protobuf_generate.md +++ /dev/null @@ -1,135 +0,0 @@ -# How to use `protobuf_generate` - -This document explains how to use the function `protobuf_generate` which is provided by protobuf's CMake module. - -## Usage - -In the same directory that called `find_package(protobuf CONFIG)` and any of its subdirectories, the CMake function `protobuf_generate` is made available by -[`protobuf-generate.cmake`](../cmake/protobuf-generate.cmake). It can be used to automatically generate source files from `.proto` schema files at build time. - -### Basic example - -Let us see how `protobuf_generate` can be used to generate and compile the source files of a proto schema whenever an object target called `proto-objects` is built. - -Given the following directory structure: - -- `proto/helloworld/helloworld.proto` -- `CMakeLists.txt` - -where `helloworld.proto` is a protobuf schema file and `CMakeLists.txt` contains: - -```cmake -find_package(protobuf CONFIG REQUIRED) - -add_library(proto-objects OBJECT "${CMAKE_CURRENT_LIST_DIR}/proto/helloworld/helloworld.proto") - -target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf) - -set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") - -target_include_directories(proto-objects PUBLIC "$") - -protobuf_generate( - TARGET proto-objects - IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}/proto" - PROTOC_OUT_DIR "${PROTO_BINARY_DIR}") -``` - -Building the target `proto-objects` will generate the files: - -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.pb.h` -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.pb.cc` - -and (depending on the build system) output: - -```shell -[build] [1/2] Running cpp protocol buffer compiler on /proto/helloworld/helloworld.proto -[build] [2/2] Building CXX object /build/generated/helloworld/helloworld.pb.cc.o -``` - -### gRPC example - -`protobuf_generate` can also be customized to invoke plugins like gRPC's `grpc_cpp_plugin`. Given the same directory structure as in the [basic example](#basic-example) -and let `CMakeLists.txt` contain: - -```cmake -find_package(gRPC CONFIG REQUIRED) - -add_library(proto-objects OBJECT "${CMAKE_CURRENT_LIST_DIR}/proto/helloworld/helloworld.proto") - -target_link_libraries(proto-objects PUBLIC protobuf::libprotobuf gRPC::grpc++) - -set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") -set(PROTO_IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}/proto") - -target_include_directories(proto-objects PUBLIC "$") - -protobuf_generate( - TARGET proto-objects - IMPORT_DIRS ${PROTO_IMPORT_DIRS} - PROTOC_OUT_DIR "${PROTO_BINARY_DIR}") - -protobuf_generate( - TARGET proto-objects - LANGUAGE grpc - GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc - PLUGIN "protoc-gen-grpc=\$" - IMPORT_DIRS ${PROTO_IMPORT_DIRS} - PROTOC_OUT_DIR "${PROTO_BINARY_DIR}") -``` - -Then building `proto-objects` will generate and compile: - -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.pb.h` -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.pb.cc` -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.grpc.pb.h` -- `${CMAKE_CURRENT_BINARY_DIR}/generated/helloworld/helloworld.grpc.pb.cc` - -And `protoc` will automatically be re-run whenever the schema files change and `proto-objects` is built. - -### Note on unity builds - -Since protobuf's generated source files are unsuited for [jumbo/unity builds](https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html) it is recommended -to exclude them from such builds which can be achieved by adjusting their properties: - -```cmake -protobuf_generate( - OUT_VAR PROTO_GENERATED_FILES - ...) - -set_source_files_properties(${PROTO_GENERATED_FILES} PROPERTIES SKIP_UNITY_BUILD_INCLUSION on) -``` - -## How it works - -For each source file ending in `proto` of the argument provided to `TARGET` or each file provided through `PROTOS`, `protobuf_generate` will set up -a [add_custom_command](https://cmake.org/cmake/help/latest/command/add_custom_command.html) which depends on `protobuf::protoc` and the proto files. -It declares the generated source files as `OUTPUT` which means that any target that depends on them will automatically cause the custom command to execute -when it is brought up to date. The command itself is made up of the arguments for `protoc`, like the output directory, the schema files, the language to -generate for, the plugins to use, etc. - -## Reference - -Arguments accepted by `protobuf_generate`. - -Flag arguments: - -- `APPEND_PATH` — A flag that causes the base path of all proto schema files to be added to `IMPORT_DIRS`. - -Single-value arguments: - -- `LANGUAGE` — A single value: cpp or python. Determines what kind of source files are being generated. -- `OUT_VAR` — Name of a CMake variable that will be filled with the paths to the generated source files. -- `EXPORT_MACRO` — Name of a macro that is applied to all generated Protobuf message classes and extern variables. It can, for example, be used to declare DLL exports. -- `PROTOC_OUT_DIR` — Output directory of generated source files. Defaults to `CMAKE_CURRENT_BINARY_DIR`. -- `PLUGIN` — An optional plugin executable. This could, for example, be the path to `grpc_cpp_plugin`. -- `PLUGIN_OPTIONS` — Additional options provided to the plugin, such as `generate_mock_code=true` for the gRPC cpp plugin. -- `DEPENDENCIES` — Arguments forwarded to the `DEPENDS` of the underlying `add_custom_command` invocation. -- `TARGET` — CMake target that will have the generated files added as sources. - -Multi-value arguments: - -- `PROTOS` — List of proto schema files. If omitted, then every source file ending in *proto* of `TARGET` will be used. -- `IMPORT_DIRS` — A common parent directory for the schema files. For example, if the schema file is `proto/helloworld/helloworld.proto` and the import directory `proto/` then the generated files are `${PROTOC_OUT_DIR}/helloworld/helloworld.pb.h` and `${PROTOC_OUT_DIR}/helloworld/helloworld.pb.cc`. -- `GENERATE_EXTENSIONS` — If LANGUAGE is omitted then this must be set to the extensions that protoc generates. -- `PROTOC_OPTIONS` — Additional arguments that are forwarded to protoc. \ No newline at end of file diff --git a/libs/protobuf/docs/cpp_build_systems.md b/libs/protobuf/docs/cpp_build_systems.md deleted file mode 100644 index b7f827b..0000000 --- a/libs/protobuf/docs/cpp_build_systems.md +++ /dev/null @@ -1,338 +0,0 @@ -# How Protobuf supports multiple C++ build systems - -This document explains how the Protobuf project supports multiple C++ build -systems. - -## Background - -Protobuf primarily uses [Bazel](https://bazel.build) to build the Protobuf C++ -runtime and Protobuf compiler[^historical_sot]. However, there are several -different build systems in common use for C++, each one of which requires -essentially a complete copy of the same build definitions. - -[^historical_sot]: - On a historical note, prior to its [release as Open Source - Software](https://opensource.googleblog.com/2008/07/protocol-buffers-googles-data.html), - the Protobuf project was developed using Google's internal build system, which - was the predecessor to Bazel (the vast majority of Google's contributions - continue to be developed this way). The Open Source Protobuf project, however, - historically used Autoconf to build the C++ implementation. - Over time, other build systems (including Bazel) have been added, thanks in - large part to substantial contributions from the Open Source community. Since - the Protobuf project deals with multiple languages (all of which ultimately - rely upon C++, for the Protobuf compiler), Bazel is a natural choice for a - project-wide build system -- in fact, Bazel (and its predecessor, Blaze) - was designed in large part to support exactly this type of rich, - multi-language build. - -Currently, C++ Protobuf can be built with Bazel and CMake. Each of these build -systems has different semantics and structure, but share in common the list of -files needed to build the runtime and compiler. - -## Design - -### Extracting information from Bazel - -Bazel's Starlark API provides [aspects](https://bazel.build/rules/aspects) to -traverse the build graph, inspect build rules, define additional actions, and -expose information through -[providers](https://bazel.build/rules/rules#providers). For example, the -`cc_proto_library` rule uses an aspect to traverse the dependency graph of -`proto_library` rules, and dynamically attaches actions to generate C++ code -using the Protobuf compiler and compile using the C++ compiler. - -In order to support multiple build systems, the overall build structure is -defined once for each system, and expose frequently-changing metadata -from Bazel in a way that can be included from the build definition. Primarily, -this means exposing the list of source files in a way that can be included -in other build definitions. - -Two aspects are used to extract this information from the Bazel build -definitions: - -* `cc_file_list_aspect` extracts `srcs`, `hdrs`, and `textual_hdrs` from build - rules like `cc_library`. The sources are exposed through a provider named - `CcFileList`. -* `proto_file_list_aspect` extracts the `srcs` from a `proto_library`, and - also generates the expected filenames that would be generated by the - Protobuf compiler. This information is exposed through a provider named - `ProtoFileList`. - -On their own, these aspects have limited utility. However, they can be -instantiated by custom rules, so that an ordinary `BUILD.bazel` target can -produce outputs based on the information gleaned from these aspects. - -### (Aside) Distribution libraries - -Bazel's native `cc_library` rule is typically used on a "fine-grained" level, so -that, for example, lightweight unit tests can be written with narrow scope. -Although Bazel does build library artifacts (such as `.so` and `.a` files on -Linux), they correspond to `cc_library` rules. - -Since the entire "Protobuf library" includes many constituent `cc_library` -rules, a special rule, `cc_dist_library`, combines several fine-grained -libraries into a single, monolithic library. - -For the Protobuf project, these "distribution libraries" are intended to match -the granularity of the CMake-based builds. Since the Bazel-built -distribution library covers the rules with the source files needed by other -builds, the `cc_dist_library` rule invokes the `cc_file_list_aspect` on its -input libraries. The result is that a `cc_dist_library` rule not only produces -composite library artifacts, but also collect and provide the list of sources -that were inputs. - -For example: - -``` -$ cat cc_dist_library_example/BUILD.bazel -load("@rules_cc//cc:defs.bzl", "cc_library") -load("//pkg:cc_dist_library.bzl", "cc_dist_library") - -cc_library( - name = "a", - srcs = ["a.cc"], -) - -cc_library( - name = "b", - srcs = ["b.cc"], - deps = [":c"], -) - -# N.B.: not part of the cc_dist_library, even though it is in the deps of 'b': -cc_library( - name = "c", - srcs = ["c.cc"], -) - -cc_dist_library( - name = "lib", - deps = [ - ":a", - ":b", - ], - visibility = ["//visibility:public"], -) - -# Note: the output below has been formatted for clarity: -$ bazel cquery //cc_dist_library_example:lib \ - --output=starlark \ - --starlark:expr='providers(target)["//pkg:cc_dist_library.bzl%CcFileList"]' -struct( - hdrs = depset([]), - internal_hdrs = depset([]), - srcs = depset([ - , - , - ]), - textual_hdrs = depset([]), -) -``` - -The upshot is that the "coarse-grained" library can be defined by the Bazel -build, and then export the list of source files that are needed to reproduce the -library in a different build system. - -One major difference from most Bazel rule types is that the file list aspects do -not propagate. In other words, they only expose the immediate dependency's -sources, not transitive sources. This is for two reasons: - -1. Immediate dependencies are conceptually simple, while transitivity requires - substantially more thought. For example, if transitive dependencies were - considered, then some way would be needed to exclude dependencies that - should not be part of the final library (for example, a distribution library - for `//:protobuf` could be defined not to include all of - `//:protobuf_lite`). While dependency elision is an interesting design - problem, the protobuf library is small enough that directly listing - dependencies should not be problematic. -2. Dealing only with immediate dependencies gives finer-grained control over - what goes into the composite library. For example, a Starlark `select()` - could conditionally add fine-grained libraries to some builds, but not - others. - -Another subtlety for tests is due to Bazel internals. Internally, a slightly -different configuration is used when evaluating `cc_test` rules as compared to -`cc_dist_library`. If `cc_test` targets are included in a `cc_dist_library` -rule, and both are evaluated by Bazel, this can result in a build-time error: -the config used for the test contains additional options that tell Bazel how to -execute the test that the `cc_file_list_aspect` build config does not. Bazel -detects this as two conflicting actions generating the same outputs. (For -`cc_test` rules, the simplest workaround is to provide sources through a -`filegroup` or similar.) - -### File list generation - -Lists of input files are generated by Bazel in a format that can be imported to -other build systems. Currently only CMake-style files can be generated. - -The lists of files are derived from Bazel build targets. The sources can be: -* `cc_dist_library` rules (as described above) -* `proto_library` rules -* individual files -* `filegroup` rules -* `pkg_files` or `pkg_filegroup` rules from - https://github.com/bazelbuild/rules_pkg - -For example: - -``` -$ cat gen_file_lists_example/BUILD.bazel -load("@rules_proto//proto:defs.bzl", "proto_library") -load("//pkg:build_systems.bzl", "gen_cmake_file_lists") - -filegroup( - name = "doc_files", - srcs = [ - "README.md", - "englilsh_paper.md", - ], -) - -proto_library( - name = "message", - srcs = ["message.proto"], -) - -gen_cmake_file_lists( - name = "source_lists", - out = "source_lists.cmake", - src_libs = { - ":doc_files": "docs", - ":message": "buff", - "//cc_dist_library_example:c": "distlib", - }, -) - -$ bazel build gen_file_lists_example:source_lists -$ cat bazel-bin/gen_file_lists_example/source_lists.cmake -# Auto-generated by //gen_file_lists_example:source_lists -# -# This file contains lists of sources based on Bazel rules. It should -# be included from a hand-written CMake file that defines targets. -# -# Changes to this file will be overwritten based on Bazel definitions. - -if(${CMAKE_VERSION} VERSION_GREATER 3.10 OR ${CMAKE_VERSION} VERSION_EQUAL 3.10) - include_guard() -endif() - -# //gen_file_lists_example:doc_files -set(docs_files - gen_file_lists_example/README.md - gen_file_lists_example/englilsh_paper.md -) - -# //gen_file_lists_example:message -set(buff_proto_srcs - gen_file_lists_example/message.proto -) - -# //gen_file_lists_example:message -set(buff_srcs - gen_file_lists_example/message.proto.pb.cc -) - -# //gen_file_lists_example:message -set(buff_hdrs - gen_file_lists_example/message.proto.pb.h -) - -# //gen_file_lists_example:message -set(buff_files - gen_file_lists_example/message-descriptor-set.proto.bin -) - -# //cc_dist_library_example:c -set(distlib_srcs - cc_dist_library_example/a.cc - cc_dist_library_example/b.cc -) - -# //cc_dist_library_example:c -set(distlib_hdrs - -) -``` - -A hand-written CMake build rule could then use the generated file to define -libraries, such as: - -``` -include(source_lists.cmake) -add_library(distlib ${distlib_srcs} ${buff_srcs}) -``` - -### Protobuf usage - -The main C++ runtimes (lite and full) and the Protobuf compiler use their -corresponding `cc_dist_library` rules to generate file lists. For -`proto_library` targets, the file list generation can extract the source files -directly. For other targets, notably `cc_test` targets, the file list generators -use `filegroup` rules. - -In general, adding new targets to a non-Bazel build system in Protobuf (or -adding a new build system altogether) requires some one-time setup: - -1. The overall structure of the new build system has to be defined. It should - import lists of files and refer to them by variable, instead of listing - files directly. -2. (Only if the build system is new) A new rule type has to be added to - `//pkg:build_systems.bzl`. Most of the implementation is shared, but a - "fragment generator" is need to declare a file list variable, and the rule - type itself has to be defined and call the shared implementation. - -When files are added or deleted, or when the Protobuf Bazel structure is -changed, these changes may need to be reflected in the file list logic. These -are some example scenarios: - -* Files are added to (or removed from) the `srcs` of an existing `cc_library`: - no changes needed. If the `cc_library` is already part of a - `cc_dist_library`, then regenerating the source lists will reflect the - change. -* A `cc_library` is added: the new target may need to be added to the Protobuf - `cc_dist_library` targets, as appropriate. -* A `cc_library` is deleted: if a `cc_dist_library` depends upon the deleted - target, then a build-time error will result. The library needs to be removed - from the `cc_dist_library`. -* A `cc_test` is added or deleted: test sources are handled by `filegroup` - rules defined in the same package as the `cc_test` rule. The `filegroup`s - are usually given a name like `"test_srcs"`, and often use `glob()` to find - sources. This means that adding or removing a test may not require any extra - work, but this can be verified within the same package as the test rule. -* Test-only proto files are added: the `proto_library` might need to be added - to the file list map in `//pkg:BUILD.bazel`, and then the file added to - various build systems. However, most test-only protos are already exposed - through libraries like `//src/google/protobuf:test_protos`. - -If there are changes, then the regenerated file lists need to be copied back -into the repo. That way, the corresponding build systems can be used with a git -checkout, without needing to run Bazel first. - -### (Aside) Distribution archives - -A very similar set of rules is defined in `//pkg` to build source distribution -archives for releases. In addition to the full sources, Protobuf releases also -include source archives sliced by language, so that, for example, a Ruby-based -project can get just the sources needed to build the Ruby runtime. (The -per-language slices also include sources needed to build the protobuf compiler, -so they all effectively include the C++ runtime.) - -These archives are defined using rules from the -[rules_pkg](https://github.com/bazelbuild/rules_pkg) project. Although they are -similar to `cc_dist_library` and the file list generation rules, the goals are -different: the build system file lists described above only apply to C++, and -are organized according to what should or should not be included in different -parts of the build (e.g., no tests are included in the main library). On the -other hand, the distribution archives deal with languages other than C++, and -contain all the files that need to be distributed as part of a release (even for -C++, this is more than just the C++ sources). - -While it might be possible to use information from the `CcFileList` and -`ProtoFileList` providers to define the distribution files, additional files -(such as the various `BUILD.bazel` files) are also needed in the distribution -archive. The lists of distribution files can usually be generated by `glob()`, -anyhow, so sharing logic with the file list aspects may not be beneficial. - -Currently, all of the file lists are checked in. However, it would be possible -to build the file lists on-the-fly and include them in the distribution -archives, rather than checking them in. diff --git a/libs/protobuf/docs/implementing_proto3_presence.md b/libs/protobuf/docs/implementing_proto3_presence.md index 4abfbd5..7c3e213 100644 --- a/libs/protobuf/docs/implementing_proto3_presence.md +++ b/libs/protobuf/docs/implementing_proto3_presence.md @@ -131,11 +131,11 @@ These options are demonstrated below: ``` # One option: -$ protoc test.proto --cpp_out=. --experimental_allow_proto3_optional +$ ./src/protoc test.proto --cpp_out=. --experimental_allow_proto3_optional # Another option: $ cp test.proto test_proto3_optional.proto -$ protoc test_proto3_optional.proto --cpp_out=. +$ ./src/protoc test_proto3_optional.proto --cpp_out=. $ ``` @@ -152,7 +152,7 @@ If you now try to invoke your own code generator with the test proto, you will run into a different error: ``` -$ protoc test_proto3_optional.proto --my_codegen_out=. +$ ./src/protoc test_proto3_optional.proto --my_codegen_out=. test_proto3_optional.proto: is a proto3 file that contains optional fields, but code generator --my_codegen_out hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional. @@ -201,7 +201,7 @@ Once you have added this, you should now be able to successfully use your code generator to generate a file containing proto3 optional fields: ``` -$ protoc test_proto3_optional.proto --my_codegen_out=. +$ ./src/protoc test_proto3_optional.proto --my_codegen_out=. ``` ### Updating Your Code Generator diff --git a/libs/protobuf/docs/jvm_aot.md b/libs/protobuf/docs/jvm_aot.md index d9c1b6b..304c829 100644 --- a/libs/protobuf/docs/jvm_aot.md +++ b/libs/protobuf/docs/jvm_aot.md @@ -1,8 +1,8 @@ -# Ahead Of Time (AOT) compilation for the Java Virtual Machine (JVM) +# Ahead Of Time (AOT) compilation for the Java Virtual Machine (JVM)" Ahead Of Time (AOT) compilation build tools such as those provided by [GraalVM's `native-image`](https://www.graalvm.org/reference-manual/native-image/) can require some configuration when using protobuf. -Protobuf for the JVM uses reflection, and some of its target classes are not possible to determine in advance. -This situation is unlikely to change. +Protobuf for the JVM uses reflection and some of its target classes are not possible to determine in advance. +Historically, there were good reasons to use reflection based on APIs that were published effectively requiring them, and this situation is unlikely to change. [The Lite version of protobuf for the JVM](https://github.com/protocolbuffers/protobuf/blob/main/java/lite.md) avoids reflection and may be better suited for use with AOT compilation tooling. This Lite version was originally targeted for use on Android which has similar AOT compilation @@ -10,11 +10,9 @@ goals as GraalVM's native-image tool. ## GraalVM native-image -The GraalVM `native-image` tool can be configured with options for the -[Java Native Interface](https://www.graalvm.org/22.0/reference-manual/native-image/JNI/) (JNI), -http proxying, reflection, and other resources. While these -configuration options can be manually specified in JSON files, we recommend -that you exercise the application with +This section addresses GraalVM's `native-image` configuration specifically as this AOT compilation tool due to its popularity. The `native-image` tool can be configured +with respect to: the [Java Native Interface](https://en.wikipedia.org/wiki/Java_Native_Interface) (JNI), http proxying, reflection, and other resources. While these +considerations can be manually declared as JSON files, we recommend that a JVM application is exercised along with [the assisted configuration agent](https://www.graalvm.org/reference-manual/native-image/BuildConfiguration/#assisted-configuration-of-native-image-builds). The agent -will generate native-image.properties files that you add to the project's -META-INF/native-image/ directory. The Native Image builder uses configuration options provided in META-INF/native-image/ to construct native-image command line arguments. +will generate files that you can then subsequently point at when invoking `native-image`. We recommend that the generated files are retained with a project's source +code. diff --git a/libs/protobuf/docs/options.md b/libs/protobuf/docs/options.md index 87f7dca..b489288 100644 --- a/libs/protobuf/docs/options.md +++ b/libs/protobuf/docs/options.md @@ -320,31 +320,3 @@ with info about your project (name and website) so we can add an entry for you. 1. Protoc-gen-authz * Website: https://github.com/Neakxs/protoc-gen-authz * Extension: 1145 - -1. Protonium - * Website: https://github.com/zyp/protonium - * Extension: 1146 - -1. Protoc-gen-xo - * Website: https://github.com/xo/ecosystem - * Extension: 1147 - -1. Ballerina gRPC - * Website: https://github.com/ballerina-platform/module-ballerina-grpc - * Extension: 1148 - -1. Protoc-gen-referential-integrity - * Website: https://github.com/ComponentCorp/protoc-gen-referential-integrity - * Extension: 1149 - -1. Oclea Service Layer RPC - * Website: https://oclea.com/ - * Extension: 1150 - -1. mypy-protobuf - * Website: https://github.com/nipunn1313/mypy-protobuf - * Extension: 1151-1154 - -1. Pigweed protobuf compiler - * Website: https://pigweed.dev/pw_protobuf - * Extension: 1155 diff --git a/libs/protobuf/docs/performance.md b/libs/protobuf/docs/performance.md new file mode 100644 index 0000000..245fdf1 --- /dev/null +++ b/libs/protobuf/docs/performance.md @@ -0,0 +1,304 @@ +# Protobuf Performance +The following benchmark test results were produced on a workstation utilizing an Intel® Xeon® Processor E5-2630 with 32GB of RAM. + +This table contains the results of three separate languages: + +* **C++** - For C++, there are three parsing methods: + * **new** - This is for using a new operator for creating a message instance. + * **new arena** - This is for using arena for creating a new message instance. + * **reuse** - This is for reusing the same message instance for parsing. +* **Java** - For Java, there are three parsing/serialization methods: + * **byte[]** - This is for parsing from a Byte Array. + * **ByteString** - This is for parsing from a + com.google.protobuf.ByteString. + * **InputStream** - This is for parsing from an InputStream. +* **Python** - For Python, there are three types of Python protobuf for testing: + * **C++-generated-code** - This is for using C++ generated code of the + proto file as a dynamic linked library. + * **C++-reflection** - This is for using C++ reflection, for which there's no + generated code, but still using C++ protobuf library as a dynamic linked + library. + * **pure-Python** - This is for the pure version of Python, which does not link with + any C++ protobuf library. + +## Parsing performance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C++C++ with tcmallocjavapython
newnew arenareusenewnew arenareusebyte[]ByteStringInputStreamC++-generated-codeC++-reflectionpure-Python
google_message1_proto2368.717MB/s261.847MB/s799.403MB/s645.183MB/s441.023MB/s1.122GB/s425.437MB/s425.937MB/s251.018MB/s82.8314MB/s47.6763MB/s3.76299MB/s
google_message1_proto3294.517MB/s229.116MB/s469.982MB/s434.510MB/s394.701MB/s591.931MB/s357.597MB/s378.568MB/s221.676MB/s82.0498MB/s39.9467MB/s3.77751MB/s
google_message2277.242MB/s347.611MB/s793.67MB/s503.721MB/s596.333MB/s922.533MB/s416.778MB/s419.543MB/s367.145MB/s241.46MB/s71.5723MB/s2.73538MB/s
google_message3_1213.478MB/s291.58MB/s543.398MB/s539.704MB/s717.300MB/s927.333MB/s684.241MB/s704.47MB/s648.624MB/s209.036MB/s142.356MB/s15.3324MB/s
google_message3_2672.685MB/s802.767MB/s1.21505GB/s985.790MB/s1.136GB/s1.367GB/s1.54439GB/s1.60603GB/s1.33443GB/s573.835MB/s314.33MB/s15.0169MB/s
google_message3_3207.681MB/s140.591MB/s535.181MB/s369.743MB/s262.301MB/s556.644MB/s279.385MB/s304.853MB/s107.575MB/s32.248MB/s26.1431MB/s2.63541MB/s
google_message3_47.96091GB/s7.10024GB/s9.3013GB/s8.518GB/s8.171GB/s9.917GB/s5.78006GB/s5.85198GB/s4.62609GB/s2.49631GB/s2.35442GB/s802.061MB/s
google_message3_576.0072MB/s51.6769MB/s237.856MB/s178.495MB/s111.751MB/s329.569MB/s121.038MB/s132.866MB/s36.9197MB/s10.3962MB/s8.84659MB/s1.25203MB/s
google_message4331.46MB/s404.862MB/s427.99MB/s589.887MB/s720.367MB/s705.373MB/s606.228MB/s589.13MB/s530.692MB/s305.543MB/s174.834MB/s7.86485MB/s
+ +## Serialization performance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
C++C++ with tcmallocjavapython
byte[]ByteStringInputStreamC++-generated-codeC++-reflectionpure-Python
google_message1_proto21.39698GB/s1.701GB/s1.12915GB/s1.13589GB/s758.609MB/s260.911MB/s58.4815MB/s5.77824MB/s
google_message1_proto3959.305MB/s939.404MB/s1.15372GB/s1.07824GB/s802.337MB/s239.4MB/s33.6336MB/s5.80524MB/s
google_message21.27429GB/s1.402GB/s1.01039GB/s1022.99MB/s798.736MB/s996.755MB/s57.9601MB/s4.09246MB/s
google_message3_11.31916GB/s2.049GB/s991.496MB/s860.332MB/s662.88MB/s1.48625GB/s421.287MB/s18.002MB/s
google_message3_22.15676GB/s2.632GB/s2.14736GB/s2.08136GB/s1.55997GB/s2.39597GB/s326.777MB/s16.0527MB/s
google_message3_3650.456MB/s1.040GB/s593.52MB/s580.667MB/s346.839MB/s123.978MB/s35.893MB/s2.32834MB/s
google_message3_48.70154GB/s9.825GB/s5.88645GB/s5.93946GB/s2.44388GB/s5.9241GB/s4.05837GB/s876.87MB/s
google_message3_5246.33MB/s443.993MB/s283.278MB/s259.167MB/s206.37MB/s37.0285MB/s12.2228MB/s1.1979MB/s
google_message41.56674GB/s2.19601GB/s776.907MB/s770.707MB/s702.931MB/s1.49623GB/s205.116MB/s8.93428MB/s
+ +\* The cpp performance can be improved by using [tcmalloc](https://gperftools.github.io/gperftools/tcmalloc.html), please follow the (instruction)[https://github.com/protocolbuffers/protobuf/blob/main/benchmarks/README.md] to link with tcmalloc to get the faster result. diff --git a/libs/protobuf/docs/third_party.md b/libs/protobuf/docs/third_party.md index d9ff970..d8478e9 100644 --- a/libs/protobuf/docs/third_party.md +++ b/libs/protobuf/docs/third_party.md @@ -203,4 +203,3 @@ There are miscellaneous other things you may find useful as a Protocol Buffers d * [vim-protolint: A protobuf linter for Vim](https://github.com/yoheimuta/vim-protolint) * [super-linter: Protocol Buffer lint as GitHub Action](https://github.com/github/super-linter) * [protoc-gen-fieldmask - A plugin to generate static type fieldmask paths](https://github.com/idodod/protoc-gen-fieldmask) -* [protoc-gen-bq-schema - A protoc plugin to generate BigQuery schema files](https://github.com/GoogleCloudPlatform/protoc-gen-bq-schema) diff --git a/libs/protobuf/examples/.bazelrc b/libs/protobuf/examples/.bazelrc deleted file mode 100644 index 554440c..0000000 --- a/libs/protobuf/examples/.bazelrc +++ /dev/null @@ -1 +0,0 @@ -build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 diff --git a/libs/protobuf/examples/AddPerson.java b/libs/protobuf/examples/AddPerson.java index 83971ab..2f6a231 100644 --- a/libs/protobuf/examples/AddPerson.java +++ b/libs/protobuf/examples/AddPerson.java @@ -1,4 +1,4 @@ -// See README.md for information and build instructions. +// See README.txt for information and build instructions. import com.example.tutorial.protos.AddressBook; import com.example.tutorial.protos.Person; diff --git a/libs/protobuf/examples/ListPeople.java b/libs/protobuf/examples/ListPeople.java index d0e037a..ab07b79 100644 --- a/libs/protobuf/examples/ListPeople.java +++ b/libs/protobuf/examples/ListPeople.java @@ -1,4 +1,4 @@ -// See README.md for information and build instructions. +// See README.txt for information and build instructions. import com.example.tutorial.protos.AddressBook; import com.example.tutorial.protos.Person; diff --git a/libs/protobuf/examples/Makefile b/libs/protobuf/examples/Makefile index ef7a4ef..1c7ec8d 100644 --- a/libs/protobuf/examples/Makefile +++ b/libs/protobuf/examples/Makefile @@ -1,4 +1,4 @@ -# See README.md. +# See README.txt. .PHONY: all cpp java python clean @@ -13,14 +13,13 @@ python: add_person_python list_people_python clean: rm -f add_person_cpp list_people_cpp add_person_java list_people_java add_person_python list_people_python - rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/protos/*.class - rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/protos/*.java + rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class + rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java rm -f *.pyc rm -f go/tutorialpb/*.pb.go add_person_go list_people_go rm -f protoc_middleman_dart dart_tutorial/*.pb*.dart rmdir dart_tutorial 2>/dev/null || true rmdir tutorial 2>/dev/null || true - rmdir com/example/tutorial/protos 2>/dev/null || true rmdir com/example/tutorial 2>/dev/null || true rmdir com/example 2>/dev/null || true rmdir com 2>/dev/null || true @@ -41,11 +40,11 @@ protoc_middleman_dart: addressbook.proto add_person_cpp: add_person.cc protoc_middleman pkg-config --cflags protobuf # fails if protobuf is not installed - c++ -std=c++14 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` + c++ -std=c++11 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf` list_people_cpp: list_people.cc protoc_middleman pkg-config --cflags protobuf # fails if protobuf is not installed - c++ -std=c++14 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf` + c++ -std=c++11 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf` add_person_dart: add_person.dart protoc_middleman_dart @@ -64,7 +63,7 @@ list_people_gotest: go/tutorialpb/addressbook.pb.go cd go && go test ./cmd/list_people javac_middleman: AddPerson.java ListPeople.java protoc_middleman - javac -cp $$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/protos/*.java + javac -cp $$CLASSPATH AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java @touch javac_middleman add_person_java: javac_middleman diff --git a/libs/protobuf/examples/README.md b/libs/protobuf/examples/README.md index 64e6d90..a99883e 100644 --- a/libs/protobuf/examples/README.md +++ b/libs/protobuf/examples/README.md @@ -28,7 +28,7 @@ Then you can run the built binary: $ bazel-bin/add_person_cpp addressbook.data To use protobuf in your own bazel project, please follow instructions in the -[BUILD.bazel](BUILD.bazel) file and [WORKSPACE](WORKSPACE) file. +[BUILD](BUILD) file and [WORKSPACE](WORKSPACE) file. ## Build the example using make @@ -37,14 +37,14 @@ minimum requirement is to install protocol compiler (i.e., the protoc binary) and the protobuf runtime for the language you want to build. You can simply run "make" to build the example for all languages (except for -Go). However, since different languages have different installation requirements, +Go). However, since different language has different installation requirement, it will likely fail. It's better to follow individual instructions below to build only the language you are interested in. ### C++ You can follow instructions in [../src/README.md](../src/README.md) to install -protoc from source. +protoc and protobuf C++ runtime from source. Then run "make cpp" in this examples directory to build the C++ example. It will create two executables: add_person_cpp and list_people_cpp. These programs diff --git a/libs/protobuf/examples/WORKSPACE b/libs/protobuf/examples/WORKSPACE index e9811ef..3897572 100644 --- a/libs/protobuf/examples/WORKSPACE +++ b/libs/protobuf/examples/WORKSPACE @@ -10,11 +10,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # # http_archive( # name = "com_google_protobuf", -# sha256 = "c29d8b4b79389463c546f98b15aa4391d4ed7ec459340c47bffe15db63eb9126", -# strip_prefix = "protobuf-3.21.3", -# urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.21.3.tar.gz"], +# strip_prefix = "protobuf-main", +# urls = ["https://github.com/protocolbuffers/protobuf/archive/main.zip"], # ) - local_repository( name = "com_google_protobuf", path = "..", diff --git a/libs/protobuf/examples/add_person.cc b/libs/protobuf/examples/add_person.cc index d54d0f1..856e90b 100644 --- a/libs/protobuf/examples/add_person.cc +++ b/libs/protobuf/examples/add_person.cc @@ -1,4 +1,4 @@ -// See README.md for information and build instructions. +// See README.txt for information and build instructions. #include #include diff --git a/libs/protobuf/examples/add_person.py b/libs/protobuf/examples/add_person.py index aa53d58..aa0fbca 100755 --- a/libs/protobuf/examples/add_person.py +++ b/libs/protobuf/examples/add_person.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -# See README.md for information and build instructions. +# See README.txt for information and build instructions. import addressbook_pb2 import sys diff --git a/libs/protobuf/examples/addressbook.proto b/libs/protobuf/examples/addressbook.proto index 5f52698..1bff4ad 100644 --- a/libs/protobuf/examples/addressbook.proto +++ b/libs/protobuf/examples/addressbook.proto @@ -1,4 +1,4 @@ -// See README.md for information and build instructions. +// See README.txt for information and build instructions. // // Note: START and END tags are used in comments to define sections used in // tutorials. They are not part of the syntax for Protocol Buffers. diff --git a/libs/protobuf/examples/list_people.cc b/libs/protobuf/examples/list_people.cc index 6f0cf20..b309c59 100644 --- a/libs/protobuf/examples/list_people.cc +++ b/libs/protobuf/examples/list_people.cc @@ -1,4 +1,4 @@ -// See README.md for information and build instructions. +// See README.txt for information and build instructions. #include #include diff --git a/libs/protobuf/examples/list_people.py b/libs/protobuf/examples/list_people.py index 98a08ed..d2c294c 100755 --- a/libs/protobuf/examples/list_people.py +++ b/libs/protobuf/examples/list_people.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -# See README.md for information and build instructions. +# See README.txt for information and build instructions. from __future__ import print_function import addressbook_pb2 diff --git a/libs/protobuf/generate_descriptor_proto.sh b/libs/protobuf/generate_descriptor_proto.sh index 91c1217..dc03fee 100755 --- a/libs/protobuf/generate_descriptor_proto.sh +++ b/libs/protobuf/generate_descriptor_proto.sh @@ -7,7 +7,7 @@ # generate. # # HINT: Flags passed to generate_descriptor_proto.sh will be passed directly -# to bazel when building protoc. This is particularly useful for passing +# to make when building protoc. This is particularly useful for passing # -j4 to run 4 jobs simultaneously. if test ! -e src/google/protobuf/stubs/common.h; then @@ -62,12 +62,12 @@ do PROTOC=$BOOTSTRAP_PROTOC BOOTSTRAP_PROTOC="" else - bazel build $@ //:protoc + make -j$(nproc) $@ protoc if test $? -ne 0; then echo "Failed to build protoc." exit 1 fi - PROTOC="../bazel-bin/protoc" + PROTOC="./protoc" fi $PROTOC --cpp_out=dllexport_decl=PROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \ diff --git a/libs/protobuf/java/BUILD.bazel b/libs/protobuf/java/BUILD.bazel index 2c6582c..b3178c9 100644 --- a/libs/protobuf/java/BUILD.bazel +++ b/libs/protobuf/java/BUILD.bazel @@ -33,7 +33,6 @@ pkg_files( "bom/pom.xml", "lite.md", "pom.xml", - "protoc/pom.xml", ], strip_prefix = strip_prefix.from_root(""), visibility = ["//pkg:__pkg__"], diff --git a/libs/protobuf/java/README.md b/libs/protobuf/java/README.md index 798ce21..5df8114 100644 --- a/libs/protobuf/java/README.md +++ b/libs/protobuf/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.21.8 + 3.21.12 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.21.8 + 3.21.12 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.21.8' + implementation 'com.google.protobuf:protobuf-java:3.21.12' ``` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/libs/protobuf/java/bom/pom.xml b/libs/protobuf/java/bom/pom.xml index ebbad00..3181676 100644 --- a/libs/protobuf/java/bom/pom.xml +++ b/libs/protobuf/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.21.8 + 3.21.12 pom Protocol Buffers [BOM] diff --git a/libs/protobuf/java/core/BUILD.bazel b/libs/protobuf/java/core/BUILD.bazel index 5a5eed9..cfd53f4 100644 --- a/libs/protobuf/java/core/BUILD.bazel +++ b/libs/protobuf/java/core/BUILD.bazel @@ -191,7 +191,7 @@ java_export( maven_coordinates = "com.google.protobuf:protobuf-java:%s" % PROTOBUF_JAVA_VERSION, pom_template = "pom_template.xml", resources = [ - "//src/google/protobuf:descriptor_proto_srcs", + "//:built_in_runtime_protos", "//:well_known_type_protos", ], tags = ["manual"], @@ -242,9 +242,8 @@ proto_library( deps = [ "//:any_proto", "//:descriptor_proto", - "//:lite_test_protos", + "//:generic_test_protos", "//:wrappers_proto", - "//src/google/protobuf:generic_test_protos", ], ) @@ -253,15 +252,7 @@ java_proto_library( visibility = [ "//java:__subpackages__", ], - deps = ["//src/google/protobuf:generic_test_protos"], -) - -java_proto_library( - name = "lite_test_protos_java_proto", - visibility = [ - "//java:__subpackages__", - ], - deps = ["//:lite_test_protos"], + deps = ["//:generic_test_protos"], ) java_proto_library( @@ -280,7 +271,6 @@ java_library( ":core", ":generic_test_protos_java_proto", ":java_test_protos_java_proto", - ":lite_test_protos_java_proto", "@maven//:com_google_guava_guava", "@maven//:junit_junit", ], @@ -322,12 +312,11 @@ junit_tests( "src/test/java/com/google/protobuf/TestUtilLite.java", ], ), - data = ["//src/google/protobuf:testdata"], + data = ["//:testdata"], deps = [ ":core", ":generic_test_protos_java_proto", ":java_test_protos_java_proto", - ":lite_test_protos_java_proto", ":test_util", "@maven//:com_google_guava_guava", "@maven//:com_google_truth_truth", @@ -360,16 +349,7 @@ java_lite_proto_library( "//java/kotlin-lite:__pkg__", "//java/lite:__pkg__", ], - deps = ["//src/google/protobuf:generic_test_protos"], -) - -java_lite_proto_library( - name = "lite_test_protos_java_proto_lite", - visibility = [ - "//java/kotlin-lite:__pkg__", - "//java/lite:__pkg__", - ], - deps = ["//:lite_test_protos"], + deps = ["//:generic_test_protos"], ) java_lite_proto_library( @@ -404,7 +384,6 @@ java_library( ":generic_test_protos_java_proto_lite", ":java_test_protos_java_proto_lite", ":lite_runtime_only", - ":lite_test_protos_java_proto_lite", "@maven//:com_google_guava_guava", "@maven//:junit_junit", ], @@ -461,13 +440,12 @@ junit_tests( ["src/test/java/**/*.java"], exclude = LITE_TEST_EXCLUSIONS, ), - data = ["//src/google/protobuf:testdata"], + data = ["//:testdata"], test_prefix = "Lite", deps = [ ":generic_test_protos_java_proto_lite", ":java_test_protos_java_proto_lite", ":lite", - ":lite_test_protos_java_proto_lite", ":test_util_lite", "@maven//:com_google_truth_truth", "@maven//:junit_junit", diff --git a/libs/protobuf/java/core/pom.xml b/libs/protobuf/java/core/pom.xml index bedb61b..83b7351 100644 --- a/libs/protobuf/java/core/pom.xml +++ b/libs/protobuf/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 protobuf-java diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/BinaryWriter.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/BinaryWriter.java index 66cf51d..cf394e3 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/BinaryWriter.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/BinaryWriter.java @@ -209,7 +209,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeInt32List_Internal(int fieldNumber, List list, boolean packed) + private final void writeInt32List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); @@ -227,7 +227,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + private final void writeInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); @@ -255,7 +255,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFixed32List_Internal(int fieldNumber, List list, boolean packed) + private final void writeFixed32List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); @@ -273,7 +273,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFixed32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + private final void writeFixed32List_Internal(int fieldNumber, IntArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); @@ -307,7 +307,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeUInt64List_Internal(int fieldNumber, List list, boolean packed) + private final void writeUInt64List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); @@ -325,7 +325,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeUInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + private final void writeUInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); @@ -353,7 +353,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFixed64List_Internal(int fieldNumber, List list, boolean packed) + private final void writeFixed64List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); @@ -371,7 +371,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFixed64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + private final void writeFixed64List_Internal(int fieldNumber, LongArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); @@ -399,7 +399,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFloatList_Internal(int fieldNumber, List list, boolean packed) + private final void writeFloatList_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); @@ -417,7 +417,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeFloatList_Internal(int fieldNumber, FloatArrayList list, boolean packed) + private final void writeFloatList_Internal(int fieldNumber, FloatArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED32_SIZE)); @@ -445,7 +445,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeDoubleList_Internal(int fieldNumber, List list, boolean packed) + private final void writeDoubleList_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); @@ -463,7 +463,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeDoubleList_Internal(int fieldNumber, DoubleArrayList list, boolean packed) + private final void writeDoubleList_Internal(int fieldNumber, DoubleArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * FIXED64_SIZE)); @@ -497,7 +497,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeBoolList_Internal(int fieldNumber, List list, boolean packed) + private final void writeBoolList_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + list.size()); @@ -515,7 +515,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeBoolList_Internal(int fieldNumber, BooleanArrayList list, boolean packed) + private final void writeBoolList_Internal(int fieldNumber, BooleanArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + list.size()); @@ -572,7 +572,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeUInt32List_Internal(int fieldNumber, List list, boolean packed) + private final void writeUInt32List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); @@ -590,7 +590,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeUInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + private final void writeUInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); @@ -630,7 +630,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeSInt32List_Internal(int fieldNumber, List list, boolean packed) + private final void writeSInt32List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); @@ -648,7 +648,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeSInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) + private final void writeSInt32List_Internal(int fieldNumber, IntArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT32_SIZE)); @@ -759,7 +759,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeSInt64List_Internal(int fieldNumber, List list, boolean packed) + private final void writeSInt64List_Internal(int fieldNumber, List list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); @@ -777,7 +777,7 @@ abstract class BinaryWriter extends ByteOutput implements Writer { } } - private void writeSInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) + private final void writeSInt64List_Internal(int fieldNumber, LongArrayList list, boolean packed) throws IOException { if (packed) { requireSpace((MAX_VARINT32_SIZE * 2) + (list.size() * MAX_VARINT64_SIZE)); diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java index 1acbad0..480f85f 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java @@ -75,7 +75,6 @@ import java.util.NoSuchElementException; */ @CheckReturnValue public abstract class ByteString implements Iterable, Serializable { - private static final long serialVersionUID = 1L; /** * When two strings to be concatenated have a combined length shorter than this, we just copy @@ -386,7 +385,8 @@ public abstract class ByteString implements Iterable, Serializable { // String -> ByteString /** - * Returns a {@code ByteString} from a hexadecimal String. + * Returns a {@code ByteString} from a hexadecimal String. Alternative CharSequences should use + * {@link ByteStrings#decode(CharSequence, BaseEncoding)} * * @param hexString String of hexadecimal digits to create {@code ByteString} from. * @throws NumberFormatException if the hexString does not contain a parsable hex String. @@ -946,8 +946,6 @@ public abstract class ByteString implements Iterable, Serializable { /** Base class for leaf {@link ByteString}s (i.e. non-ropes). */ abstract static class LeafByteString extends ByteString { - private static final long serialVersionUID = 1L; - @Override protected final int getTreeDepth() { return 0; @@ -1132,6 +1130,13 @@ public abstract class ByteString implements Iterable, Serializable { return ByteString.copyFrom(flushedBuffers); } + /** Implement java.util.Arrays.copyOf() for jdk 1.5. */ + private byte[] copyArray(byte[] buffer, int length) { + byte[] result = new byte[length]; + System.arraycopy(buffer, 0, result, 0, Math.min(buffer.length, length)); + return result; + } + /** * Writes the complete contents of this byte array output stream to the specified output stream * argument. @@ -1146,7 +1151,7 @@ public abstract class ByteString implements Iterable, Serializable { synchronized (this) { // Copy the information we need into local variables so as to hold // the lock for as short a time as possible. - cachedFlushBuffers = flushedBuffers.toArray(new ByteString[0]); + cachedFlushBuffers = flushedBuffers.toArray(new ByteString[flushedBuffers.size()]); cachedBuffer = buffer; cachedBufferPos = bufferPos; } @@ -1154,7 +1159,7 @@ public abstract class ByteString implements Iterable, Serializable { byteString.writeTo(out); } - out.write(Arrays.copyOf(cachedBuffer, cachedBufferPos)); + out.write(copyArray(cachedBuffer, cachedBufferPos)); } /** @@ -1205,7 +1210,7 @@ public abstract class ByteString implements Iterable, Serializable { private void flushLastBuffer() { if (bufferPos < buffer.length) { if (bufferPos > 0) { - byte[] bufferCopy = Arrays.copyOf(buffer, bufferPos); + byte[] bufferCopy = copyArray(buffer, bufferPos); flushedBuffers.add(new LiteralByteString(bufferCopy)); } // We reuse this buffer for further writes. @@ -1606,6 +1611,7 @@ public abstract class ByteString implements Iterable, Serializable { // Keep this class private to avoid deadlocks in classloading across threads as ByteString's // static initializer loads LiteralByteString and another thread loads BoundedByteString. private static final class BoundedByteString extends LiteralByteString { + private final int bytesOffset; private final int bytesLength; diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java index d31f1ed..9e84432 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/CanIgnoreReturnValue.java @@ -31,6 +31,7 @@ package com.google.protobuf; import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.CLASS; import java.lang.annotation.Documented; @@ -44,6 +45,6 @@ import java.lang.annotation.Target; * annotated with {@code @CheckReturnValue} to exempt specific methods from the default. */ @Documented -@Target(METHOD) // TODO(kak): consider adding CONSTRUCTOR later if necessary +@Target({METHOD, TYPE}) @Retention(CLASS) @interface CanIgnoreReturnValue {} diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/CheckReturnValue.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/CheckReturnValue.java index 99abc32..38c83d8 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/CheckReturnValue.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/CheckReturnValue.java @@ -41,13 +41,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; /** - * Indicates that the return value of the annotated method must be used. An error is triggered when - * one of these methods is called but the result is not used. + * Indicates that the return value of the annotated method must be checked. An error is triggered + * when one of these methods is called but the result is not used. * *

{@code @CheckReturnValue} may be applied to a class or package to indicate that all methods in - * that class (including indirectly; that is, methods of inner classes within the annotated class) - * or package must have their return values used. For convenience, we provide an annotation, {@link - * CanIgnoreReturnValue}, to exempt specific methods or classes from this behavior. + * that class or package must have their return values checked. For convenience, we provide an + * annotation, {@link CanIgnoreReturnValue}, to exempt specific methods or classes from this + * behavior. */ @Documented @Target({METHOD, CONSTRUCTOR, TYPE, PACKAGE}) diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java index 91c9b19..a36195b 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -78,7 +78,6 @@ import java.util.logging.Logger; * * @author kenton@google.com Kenton Varda */ -@CheckReturnValue public final class Descriptors { private static final Logger logger = Logger.getLogger(Descriptors.class.getName()); private static final int[] EMPTY_INT_ARRAY = new int[0]; @@ -462,20 +461,21 @@ public final class Descriptors { } /** - * This method is to be called by generated code only. It updates the + * This method is to be called by generated code only. It is used to update the * FileDescriptorProto associated with the descriptor by parsing it again with the given * ExtensionRegistry. This is needed to recognize custom options. */ public static void internalUpdateFileDescriptor( - FileDescriptor descriptor, ExtensionRegistry registry) { + final FileDescriptor descriptor, final ExtensionRegistry registry) { ByteString bytes = descriptor.proto.toByteString(); + FileDescriptorProto proto; try { - FileDescriptorProto proto = FileDescriptorProto.parseFrom(bytes, registry); - descriptor.setProto(proto); + proto = FileDescriptorProto.parseFrom(bytes, registry); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException( "Failed to parse protocol buffer descriptor for generated code.", e); } + descriptor.setProto(proto); } /** @@ -1788,27 +1788,6 @@ public final class Descriptors { return Collections.unmodifiableList(Arrays.asList(values)); } - /** Determines if the given field number is reserved. */ - public boolean isReservedNumber(final int number) { - for (final EnumDescriptorProto.EnumReservedRange range : proto.getReservedRangeList()) { - if (range.getStart() <= number && number <= range.getEnd()) { - return true; - } - } - return false; - } - - /** Determines if the given field name is reserved. */ - public boolean isReservedName(final String name) { - checkNotNull(name); - for (final String reservedName : proto.getReservedNameList()) { - if (reservedName.equals(name)) { - return true; - } - } - return false; - } - /** * Find an enum value by name. * diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java index 4b2aa07..caa58e1 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java @@ -123,15 +123,16 @@ public class ExtensionRegistryLite { * ExtensionRegistry} (if the full (non-Lite) proto libraries are available). */ public static ExtensionRegistryLite getEmptyRegistry() { - if (!doFullRuntimeInheritanceCheck) { - return EMPTY_REGISTRY_LITE; - } ExtensionRegistryLite result = emptyRegistry; if (result == null) { synchronized (ExtensionRegistryLite.class) { result = emptyRegistry; if (result == null) { - result = emptyRegistry = ExtensionRegistryFactory.createEmpty(); + result = + emptyRegistry = + doFullRuntimeInheritanceCheck + ? ExtensionRegistryFactory.createEmpty() + : EMPTY_REGISTRY_LITE; } } } diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java index 9b294e3..b64f63b 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java @@ -728,10 +728,6 @@ final class FieldSet> { if (descriptor.isRepeated()) { final List valueList = (List) value; if (descriptor.isPacked()) { - if (valueList.isEmpty()) { - // The tag should not be written for empty packed fields. - return; - } output.writeTag(number, WireFormat.WIRETYPE_LENGTH_DELIMITED); // Compute the total data size so the length can be written. int dataSize = 0; @@ -897,13 +893,9 @@ final class FieldSet> { WireFormat.FieldType type = descriptor.getLiteType(); int number = descriptor.getNumber(); if (descriptor.isRepeated()) { - List valueList = (List) value; if (descriptor.isPacked()) { - if (valueList.isEmpty()) { - return 0; - } int dataSize = 0; - for (final Object element : valueList) { + for (final Object element : (List) value) { dataSize += computeElementSizeNoTag(type, element); } return dataSize @@ -911,7 +903,7 @@ final class FieldSet> { + CodedOutputStream.computeUInt32SizeNoTag(dataSize); } else { int size = 0; - for (final Object element : valueList) { + for (final Object element : (List) value) { size += computeElementSize(type, number, element); } return size; diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index 26cc5bb..de0ee11 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -36,6 +36,7 @@ import com.google.protobuf.Descriptors.EnumValueDescriptor; import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.OneofDescriptor; + import java.io.IOException; import java.io.InputStream; import java.io.ObjectStreamException; @@ -50,23 +51,25 @@ import java.util.Map; import java.util.TreeMap; /** - * All generated protocol message classes extend this class. This class implements most of the - * Message and Builder interfaces using Java reflection. Users can ignore this class and pretend - * that generated messages implement the Message interface directly. + * All generated protocol message classes extend this class. This class + * implements most of the Message and Builder interfaces using Java reflection. + * Users can ignore this class and pretend that generated messages implement + * the Message interface directly. * * @author kenton@google.com Kenton Varda */ -public abstract class GeneratedMessage extends AbstractMessage implements Serializable { +public abstract class GeneratedMessage extends AbstractMessage + implements Serializable { private static final long serialVersionUID = 1L; /** - * For testing. Allows a test to disable the optimization that avoids using field builders for - * nested messages until they are requested. By disabling this optimization, existing tests can be - * reused to test the field builders. + * For testing. Allows a test to disable the optimization that avoids using + * field builders for nested messages until they are requested. By disabling + * this optimization, existing tests can be reused to test the field builders. */ protected static boolean alwaysUseFieldBuilders = false; - /** For use by generated code only. */ + /** For use by generated code only. */ protected UnknownFieldSet unknownFields; protected GeneratedMessage() { @@ -79,22 +82,24 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public Parser getParserForType() { - throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + throw new UnsupportedOperationException( + "This is supposed to be overridden by subclasses."); } - /** - * For testing. Allows a test to disable the optimization that avoids using field builders for - * nested messages until they are requested. By disabling this optimization, existing tests can be - * reused to test the field builders. See {@link RepeatedFieldBuilder} and {@link - * SingleFieldBuilder}. - */ + /** + * For testing. Allows a test to disable the optimization that avoids using + * field builders for nested messages until they are requested. By disabling + * this optimization, existing tests can be reused to test the field builders. + * See {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder}. + */ static void enableAlwaysUseFieldBuildersForTesting() { alwaysUseFieldBuilders = true; } /** - * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the - * constructor because of bootstrapping trouble with DescriptorProtos. + * Get the FieldAccessorTable for this type. We can't have the message + * class pass this in to the constructor because of bootstrapping trouble + * with DescriptorProtos. */ protected abstract FieldAccessorTable internalGetFieldAccessorTable(); @@ -104,14 +109,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Internal helper to return a modifiable map containing all the fields. The returned Map is - * modifialbe so that the caller can add additional extension fields to implement {@link - * #getAllFields()}. + * Internal helper to return a modifiable map containing all the fields. + * The returned Map is modifialbe so that the caller can add additional + * extension fields to implement {@link #getAllFields()}. * * @param getBytesForString whether to generate ByteString for string fields */ - private Map getAllFieldsMutable(boolean getBytesForString) { - final TreeMap result = new TreeMap(); + private Map getAllFieldsMutable( + boolean getBytesForString) { + final TreeMap result = + new TreeMap(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -167,8 +174,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // Check that embedded messages are initialized. if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isRepeated()) { - @SuppressWarnings("unchecked") - final List messageList = (List) getField(field); + @SuppressWarnings("unchecked") final + List messageList = (List) getField(field); for (final Message element : messageList) { if (!element.isInitialized()) { return false; @@ -187,19 +194,23 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public Map getAllFields() { - return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ false)); + return Collections.unmodifiableMap( + getAllFieldsMutable(/* getBytesForString = */ false)); } /** - * Returns a collection of all the fields in this message which are set and their corresponding - * values. A singular ("required" or "optional") field is set iff hasField() returns true for that - * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values - * are exactly what would be returned by calling {@link #getFieldRaw(Descriptors.FieldDescriptor)} - * for each field. The map is guaranteed to be a sorted map, so iterating over it will return - * fields in order by field number. + * Returns a collection of all the fields in this message which are set + * and their corresponding values. A singular ("required" or "optional") + * field is set iff hasField() returns true for that field. A "repeated" + * field is set iff getRepeatedFieldCount() is greater than zero. The + * values are exactly what would be returned by calling + * {@link #getFieldRaw(Descriptors.FieldDescriptor)} for each field. The map + * is guaranteed to be a sorted map, so iterating over it will return fields + * in order by field number. */ Map getAllFieldsRaw() { - return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ true)); + return Collections.unmodifiableMap( + getAllFieldsMutable(/* getBytesForString = */ true)); } @Override @@ -223,11 +234,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Obtains the value of the given field, or the default value if it is not set. For primitive - * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the - * value is returned. For embedded message fields, the sub-message is returned. For repeated - * fields, a java.util.List is returned. For present string fields, a ByteString is returned - * representing the bytes that the field contains. + * Obtains the value of the given field, or the default value if it is + * not set. For primitive fields, the boxed primitive value is returned. + * For enum fields, the EnumValueDescriptor for the value is returned. For + * embedded message fields, the sub-message is returned. For repeated + * fields, a java.util.List is returned. For present string fields, a + * ByteString is returned representing the bytes that the field contains. */ Object getFieldRaw(final FieldDescriptor field) { return internalGetFieldAccessorTable().getField(field).getRaw(this); @@ -235,30 +247,31 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public int getRepeatedFieldCount(final FieldDescriptor field) { - return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + return internalGetFieldAccessorTable().getField(field) + .getRepeatedCount(this); } @Override public Object getRepeatedField(final FieldDescriptor field, final int index) { - return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + return internalGetFieldAccessorTable().getField(field) + .getRepeated(this, index); } @Override public UnknownFieldSet getUnknownFields() { - throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + throw new UnsupportedOperationException( + "This is supposed to be overridden by subclasses."); } /** * Called by subclasses to parse an unknown field. - * * @return {@code true} unless the tag is an end-group tag. */ protected boolean parseUnknownField( CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, - int tag) - throws IOException { + int tag) throws IOException { return unknownFields.mergeFieldFrom(tag, input); } @@ -271,8 +284,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static M parseWithIOException( - Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + protected static M parseWithIOException(Parser parser, InputStream input, + ExtensionRegistryLite extensions) throws IOException { try { return parser.parseFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -280,8 +293,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static M parseWithIOException( - Parser parser, CodedInputStream input) throws IOException { + protected static M parseWithIOException(Parser parser, + CodedInputStream input) throws IOException { try { return parser.parseFrom(input); } catch (InvalidProtocolBufferException e) { @@ -289,9 +302,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static M parseWithIOException( - Parser parser, CodedInputStream input, ExtensionRegistryLite extensions) - throws IOException { + protected static M parseWithIOException(Parser parser, + CodedInputStream input, ExtensionRegistryLite extensions) throws IOException { try { return parser.parseFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -299,8 +311,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static M parseDelimitedWithIOException( - Parser parser, InputStream input) throws IOException { + protected static M parseDelimitedWithIOException(Parser parser, + InputStream input) throws IOException { try { return parser.parseDelimitedFrom(input); } catch (InvalidProtocolBufferException e) { @@ -308,8 +320,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static M parseDelimitedWithIOException( - Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + protected static M parseDelimitedWithIOException(Parser parser, + InputStream input, ExtensionRegistryLite extensions) throws IOException { try { return parser.parseDelimitedFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -329,38 +341,46 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial return size; } - memoizedSize = MessageReflection.getSerializedSize(this, getAllFieldsRaw()); + memoizedSize = MessageReflection.getSerializedSize( + this, getAllFieldsRaw()); return memoizedSize; } - /** Used by parsing constructors in generated classes. */ + + + /** + * Used by parsing constructors in generated classes. + */ protected void makeExtensionsImmutable() { // Noop for messages without extensions. } /** - * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this interface to - * AbstractMessage in order to versioning GeneratedMessage but this move breaks binary - * compatibility for AppEngine. After AppEngine is fixed we can exclude this from google3. + * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this + * interface to AbstractMessage in order to versioning GeneratedMessage but + * this move breaks binary compatibility for AppEngine. After AppEngine is + * fixed we can exclude this from google3. */ protected interface BuilderParent extends AbstractMessage.BuilderParent {} - /** TODO(xiaofeng): remove this together with GeneratedMessage.BuilderParent. */ + /** + * TODO(xiaofeng): remove this together with GeneratedMessage.BuilderParent. + */ protected abstract Message.Builder newBuilderForType(BuilderParent parent); @Override protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { - return newBuilderForType( - new BuilderParent() { - @Override - public void markDirty() { - parent.markDirty(); - } - }); + return newBuilderForType(new BuilderParent() { + @Override + public void markDirty() { + parent.markDirty(); + } + }); } + @SuppressWarnings("unchecked") - public abstract static class Builder> + public abstract static class Builder > extends AbstractMessage.Builder { private BuilderParent builderParent; @@ -371,7 +391,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // to dispatch dirty invalidations. See GeneratedMessage.BuilderListener. private boolean isClean; - private UnknownFieldSet unknownFields = UnknownFieldSet.getDefaultInstance(); + private UnknownFieldSet unknownFields = + UnknownFieldSet.getDefaultInstance(); protected Builder() { this(null); @@ -386,7 +407,9 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial builderParent = null; } - /** Called by the subclass when a message is built. */ + /** + * Called by the subclass when a message is built. + */ protected void onBuilt() { if (builderParent != null) { markClean(); @@ -394,8 +417,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Called by the subclass or a builder to notify us that a message was built and may be cached - * and therefore invalidations are needed. + * Called by the subclass or a builder to notify us that a message was + * built and may be cached and therefore invalidations are needed. */ @Override protected void markClean() { @@ -413,14 +436,15 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public BuilderType clone() { - BuilderType builder = (BuilderType) getDefaultInstanceForType().newBuilderForType(); + BuilderType builder = + (BuilderType) getDefaultInstanceForType().newBuilderForType(); builder.mergeFrom(buildPartial()); return builder; } /** - * Called by the initialization and clear code paths to allow subclasses to reset any of their - * builtin fields back to the initial values. + * Called by the initialization and clear code paths to allow subclasses to + * reset any of their builtin fields back to the initial values. */ @Override public BuilderType clear() { @@ -430,8 +454,9 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the - * constructor because of bootstrapping trouble with DescriptorProtos. + * Get the FieldAccessorTable for this type. We can't have the message + * class pass this in to the constructor because of bootstrapping trouble + * with DescriptorProtos. */ protected abstract FieldAccessorTable internalGetFieldAccessorTable(); @@ -447,7 +472,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** Internal helper which returns a mutable map. */ private Map getAllFieldsMutable() { - final TreeMap result = new TreeMap(); + final TreeMap result = + new TreeMap(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -499,7 +525,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { - return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(this, index); + return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder( + this, index); } @Override @@ -549,18 +576,21 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public int getRepeatedFieldCount(final FieldDescriptor field) { - return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + return internalGetFieldAccessorTable().getField(field) + .getRepeatedCount(this); } @Override public Object getRepeatedField(final FieldDescriptor field, final int index) { - return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + return internalGetFieldAccessorTable().getField(field) + .getRepeated(this, index); } @Override public BuilderType setRepeatedField( final FieldDescriptor field, final int index, final Object value) { - internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); + internalGetFieldAccessorTable().getField(field) + .setRepeated(this, index, value); return (BuilderType) this; } @@ -578,9 +608,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public BuilderType mergeUnknownFields(final UnknownFieldSet unknownFields) { + public BuilderType mergeUnknownFields( + final UnknownFieldSet unknownFields) { this.unknownFields = - UnknownFieldSet.newBuilder(this.unknownFields).mergeFrom(unknownFields).build(); + UnknownFieldSet.newBuilder(this.unknownFields) + .mergeFrom(unknownFields) + .build(); onChanged(); return (BuilderType) this; } @@ -597,15 +630,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // Check that embedded messages are initialized. if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isRepeated()) { - @SuppressWarnings("unchecked") - final List messageList = (List) getField(field); + @SuppressWarnings("unchecked") final + List messageList = (List) getField(field); for (final Message element : messageList) { if (!element.isInitialized()) { return false; } } } else { - if (hasField(field) && !((Message) getField(field)).isInitialized()) { + if (hasField(field) && + !((Message) getField(field)).isInitialized()) { return false; } } @@ -621,21 +655,20 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Called by subclasses to parse an unknown field. - * * @return {@code true} unless the tag is an end-group tag. */ protected boolean parseUnknownField( final CodedInputStream input, final UnknownFieldSet.Builder unknownFields, final ExtensionRegistryLite extensionRegistry, - final int tag) - throws IOException { + final int tag) throws IOException { return unknownFields.mergeFieldFrom(tag, input); } /** - * Implementation of {@link BuilderParent} for giving to our children. This small inner class - * makes it so we don't publicly expose the BuilderParent methods. + * Implementation of {@link BuilderParent} for giving to our children. This + * small inner class makes it so we don't publicly expose the BuilderParent + * methods. */ private class BuilderParentImpl implements BuilderParent { @@ -647,7 +680,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Gets the {@link BuilderParent} for giving to our children. - * * @return The builder parent for our children. */ protected BuilderParent getParentForChildren() { @@ -658,8 +690,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Called when a the builder or one of its nested children has changed and any parent should be - * notified of its invalidation. + * Called when a the builder or one of its nested children has changed + * and any parent should be notified of its invalidation. */ protected final void onChanged() { if (isClean && builderParent != null) { @@ -671,19 +703,22 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Gets the map field with the given field number. This method should be overridden in the - * generated message class if the message contains map fields. + * Gets the map field with the given field number. This method should be + * overridden in the generated message class if the message contains map + * fields. * - *

Unlike other field types, reflection support for map fields can't be implemented based on - * generated public API because we need to access a map field as a list in reflection API but - * the generated API only allows us to access it as a map. This method returns the underlying - * map field directly and thus enables us to access the map field as a list. + * Unlike other field types, reflection support for map fields can't be + * implemented based on generated public API because we need to access a + * map field as a list in reflection API but the generated API only allows + * us to access it as a map. This method returns the underlying map field + * directly and thus enables us to access the map field as a list. */ @SuppressWarnings({"unused", "rawtypes"}) protected MapField internalGetMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } /** Like {@link #internalGetMapField} but return a mutable version. */ @@ -691,57 +726,76 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial protected MapField internalGetMutableMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } } // ================================================================= // Extensions-related stuff - public interface ExtendableMessageOrBuilder - extends MessageOrBuilder { + public interface ExtendableMessageOrBuilder< + MessageType extends ExtendableMessage> extends MessageOrBuilder { // Re-define for return type covariance. @Override Message getDefaultInstanceForType(); /** Check if a singular extension is present. */ - boolean hasExtension(ExtensionLite extension); + boolean hasExtension( + ExtensionLite extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount(ExtensionLite> extension); + int getExtensionCount( + ExtensionLite> extension); /** Get the value of an extension. */ - Type getExtension(ExtensionLite extension); + Type getExtension( + ExtensionLite extension); /** Get one element of a repeated extension. */ - Type getExtension(ExtensionLite> extension, int index); + Type getExtension( + ExtensionLite> extension, + int index); /** Check if a singular extension is present. */ - boolean hasExtension(Extension extension); + boolean hasExtension( + Extension extension); /** Check if a singular extension is present. */ - boolean hasExtension(GeneratedExtension extension); + boolean hasExtension( + GeneratedExtension extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount(Extension> extension); + int getExtensionCount( + Extension> extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount(GeneratedExtension> extension); + int getExtensionCount( + GeneratedExtension> extension); /** Get the value of an extension. */ - Type getExtension(Extension extension); + Type getExtension( + Extension extension); /** Get the value of an extension. */ - Type getExtension(GeneratedExtension extension); + Type getExtension( + GeneratedExtension extension); /** Get one element of a repeated extension. */ - Type getExtension(Extension> extension, int index); + Type getExtension( + Extension> extension, + int index); /** Get one element of a repeated extension. */ - Type getExtension(GeneratedExtension> extension, int index); + Type getExtension( + GeneratedExtension> extension, + int index); } /** - * Generated message classes for message types that contain extension ranges subclass this. + * Generated message classes for message types that contain extension ranges + * subclass this. * - *

This class implements type-safe accessors for extensions. They implement all the same - * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for - * extensions. The extensions are identified using instances of the class {@link - * GeneratedExtension}; the protocol compiler generates a static instance of this class for every - * extension in its input. Through the magic of generics, all is made type-safe. + *

This class implements type-safe accessors for extensions. They + * implement all the same operations that you can do with normal fields -- + * e.g. "has", "get", and "getCount" -- but for extensions. The extensions + * are identified using instances of the class {@link GeneratedExtension}; + * the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made + * type-safe. * *

For example, imagine you have the {@code .proto} file: * @@ -766,8 +820,10 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial * *

See also {@link ExtendableBuilder}. */ - public abstract static class ExtendableMessage - extends GeneratedMessage implements ExtendableMessageOrBuilder { + public abstract static class ExtendableMessage< + MessageType extends ExtendableMessage> + extends GeneratedMessage + implements ExtendableMessageOrBuilder { private static final long serialVersionUID = 1L; @@ -777,20 +833,22 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial this.extensions = FieldSet.newFieldSet(); } - protected ExtendableMessage(ExtendableBuilder builder) { + protected ExtendableMessage( + ExtendableBuilder builder) { super(builder); this.extensions = builder.buildExtensions(); } - private void verifyExtensionContainingType(final Extension extension) { - if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + private void verifyExtensionContainingType( + final Extension extension) { + if (extension.getDescriptor().getContainingType() != + getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( - "Extension is for type \"" - + extension.getDescriptor().getContainingType().getFullName() - + "\" which does not match message type \"" - + getDescriptorForType().getFullName() - + "\"."); + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + "\"."); } } @@ -828,10 +886,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial if (value == null) { if (descriptor.isRepeated()) { return (Type) Collections.emptyList(); - } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + } else if (descriptor.getJavaType() == + FieldDescriptor.JavaType.MESSAGE) { return (Type) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (Type) extension.fromReflectionType( + descriptor.getDefaultValue()); } } else { return (Type) extension.fromReflectionType(value); @@ -847,8 +907,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); - return (Type) - extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + return (Type) extension.singularFromReflectionType( + extensions.getRepeatedField(descriptor, index)); } /** Check if a singular extension is present. */ @@ -864,7 +924,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount(final Extension> extension) { + public final int getExtensionCount( + final Extension> extension) { return getExtensionCount((ExtensionLite>) extension); } /** Get the number of elements in a repeated extension. */ @@ -880,7 +941,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** Get the value of an extension. */ @Override - public final Type getExtension(final GeneratedExtension extension) { + public final Type getExtension( + final GeneratedExtension extension) { return getExtension((ExtensionLite) extension); } /** Get one element of a repeated extension. */ @@ -911,33 +973,33 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, - int tag) - throws IOException { + int tag) throws IOException { return MessageReflection.mergeFieldFrom( - input, - unknownFields, - extensionRegistry, - getDescriptorForType(), - new MessageReflection.ExtensionAdapter(extensions), - tag); + input, unknownFields, extensionRegistry, getDescriptorForType(), + new MessageReflection.ExtensionAdapter(extensions), tag); } - /** Used by parsing constructors in generated classes. */ + + /** + * Used by parsing constructors in generated classes. + */ @Override protected void makeExtensionsImmutable() { extensions.makeImmutable(); } /** - * Used by subclasses to serialize extensions. Extension ranges may be interleaved with field - * numbers, but we must write them in canonical (sorted by field number) order. ExtensionWriter - * helps us write individual ranges of extensions at once. + * Used by subclasses to serialize extensions. Extension ranges may be + * interleaved with field numbers, but we must write them in canonical + * (sorted by field number) order. ExtensionWriter helps us write + * individual ranges of extensions at once. */ protected class ExtensionWriter { // Imagine how much simpler this code would be if Java iterators had // a way to get the next element without advancing the iterator. - private final Iterator> iter = extensions.iterator(); + private final Iterator> iter = + extensions.iterator(); private Map.Entry next; private final boolean messageSetWireFormat; @@ -948,18 +1010,19 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial this.messageSetWireFormat = messageSetWireFormat; } - public void writeUntil(final int end, final CodedOutputStream output) throws IOException { + public void writeUntil(final int end, final CodedOutputStream output) + throws IOException { while (next != null && next.getKey().getNumber() < end) { FieldDescriptor descriptor = next.getKey(); - if (messageSetWireFormat - && descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE - && !descriptor.isRepeated()) { + if (messageSetWireFormat && descriptor.getLiteJavaType() == + WireFormat.JavaType.MESSAGE && + !descriptor.isRepeated()) { if (next instanceof LazyField.LazyEntry) { - output.writeRawMessageSetExtension( - descriptor.getNumber(), + output.writeRawMessageSetExtension(descriptor.getNumber(), ((LazyField.LazyEntry) next).getField().toByteString()); } else { - output.writeMessageSetExtension(descriptor.getNumber(), (Message) next.getValue()); + output.writeMessageSetExtension(descriptor.getNumber(), + (Message) next.getValue()); } } else { // TODO(xiangl): Taken care of following code, it may cause @@ -983,7 +1046,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial protected ExtensionWriter newExtensionWriter() { return new ExtensionWriter(false); } - protected ExtensionWriter newMessageSetExtensionWriter() { return new ExtensionWriter(true); } @@ -992,7 +1054,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial protected int extensionsSerializedSize() { return extensions.getSerializedSize(); } - protected int extensionsSerializedSizeAsMessageSet() { return extensions.getMessageSetSerializedSize(); } @@ -1064,7 +1125,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public Object getRepeatedField(final FieldDescriptor field, final int index) { + public Object getRepeatedField(final FieldDescriptor field, + final int index) { if (field.isExtension()) { verifyContainingType(field); return extensions.getRepeatedField(field, index); @@ -1075,19 +1137,23 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial private void verifyContainingType(final FieldDescriptor field) { if (field.getContainingType() != getDescriptorForType()) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } } } /** - * Generated message builders for message types that contain extension ranges subclass this. + * Generated message builders for message types that contain extension ranges + * subclass this. * - *

This class implements type-safe accessors for extensions. They implement all the same - * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for - * extensions. The extensions are identified using instances of the class {@link - * GeneratedExtension}; the protocol compiler generates a static instance of this class for every - * extension in its input. Through the magic of generics, all is made type-safe. + *

This class implements type-safe accessors for extensions. They + * implement all the same operations that you can do with normal fields -- + * e.g. "get", "set", and "add" -- but for extensions. The extensions are + * identified using instances of the class {@link GeneratedExtension}; the + * protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made + * type-safe. * *

For example, imagine you have the {@code .proto} file: * @@ -1116,15 +1182,17 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial */ @SuppressWarnings("unchecked") public abstract static class ExtendableBuilder< - MessageType extends ExtendableMessage, - BuilderType extends ExtendableBuilder> - extends Builder implements ExtendableMessageOrBuilder { + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends Builder + implements ExtendableMessageOrBuilder { private FieldSet extensions = FieldSet.emptySet(); protected ExtendableBuilder() {} - protected ExtendableBuilder(BuilderParent parent) { + protected ExtendableBuilder( + BuilderParent parent) { super(parent); } @@ -1153,15 +1221,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - private void verifyExtensionContainingType(final Extension extension) { - if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + private void verifyExtensionContainingType( + final Extension extension) { + if (extension.getDescriptor().getContainingType() != + getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( - "Extension is for type \"" - + extension.getDescriptor().getContainingType().getFullName() - + "\" which does not match message type \"" - + getDescriptorForType().getFullName() - + "\"."); + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + "\"."); } } @@ -1196,10 +1265,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial if (value == null) { if (descriptor.isRepeated()) { return (Type) Collections.emptyList(); - } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + } else if (descriptor.getJavaType() == + FieldDescriptor.JavaType.MESSAGE) { return (Type) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (Type) extension.fromReflectionType( + descriptor.getDefaultValue()); } } else { return (Type) extension.fromReflectionType(value); @@ -1214,13 +1285,14 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); - return (Type) - extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + return (Type) extension.singularFromReflectionType( + extensions.getRepeatedField(descriptor, index)); } /** Set the value of an extension. */ public final BuilderType setExtension( - final ExtensionLite extensionLite, final Type value) { + final ExtensionLite extensionLite, + final Type value) { Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); @@ -1234,27 +1306,30 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** Set the value of one element of a repeated extension. */ public final BuilderType setExtension( final ExtensionLite> extensionLite, - final int index, - final Type value) { + final int index, final Type value) { Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); - extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); + extensions.setRepeatedField( + descriptor, index, + extension.singularToReflectionType(value)); onChanged(); return (BuilderType) this; } /** Append a value to a repeated extension. */ public final BuilderType addExtension( - final ExtensionLite> extensionLite, final Type value) { + final ExtensionLite> extensionLite, + final Type value) { Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); - extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); + extensions.addRepeatedField( + descriptor, extension.singularToReflectionType(value)); onChanged(); return (BuilderType) this; } @@ -1284,7 +1359,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** Get the number of elements in a repeated extension. */ @Override - public final int getExtensionCount(final Extension> extension) { + public final int getExtensionCount( + final Extension> extension) { return getExtensionCount((ExtensionLite>) extension); } /** Get the number of elements in a repeated extension. */ @@ -1300,7 +1376,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** Get the value of an extension. */ @Override - public final Type getExtension(final GeneratedExtension extension) { + public final Type getExtension( + final GeneratedExtension extension) { return getExtension((ExtensionLite) extension); } /** Get the value of an extension. */ @@ -1327,14 +1404,14 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** Set the value of one element of a repeated extension. */ public final BuilderType setExtension( - final Extension> extension, final int index, final Type value) { + final Extension> extension, + final int index, final Type value) { return setExtension((ExtensionLite>) extension, index, value); } /** Set the value of one element of a repeated extension. */ public BuilderType setExtension( final GeneratedExtension> extension, - final int index, - final Type value) { + final int index, final Type value) { return setExtension((ExtensionLite>) extension, index, value); } /** Append a value to a repeated extension. */ @@ -1348,11 +1425,13 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial return addExtension((ExtensionLite>) extension, value); } /** Clear an extension. */ - public final BuilderType clearExtension(final Extension extension) { + public final BuilderType clearExtension( + final Extension extension) { return clearExtension((ExtensionLite) extension); } /** Clear an extension. */ - public BuilderType clearExtension(final GeneratedExtension extension) { + public BuilderType clearExtension( + final GeneratedExtension extension) { return clearExtension((ExtensionLite) extension); } @@ -1362,7 +1441,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Called by the build code path to create a copy of the extensions for building the message. + * Called by the build code path to create a copy of the extensions for + * building the message. */ private FieldSet buildExtensions() { extensions.makeImmutable(); @@ -1376,7 +1456,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Called by subclasses to parse an unknown field or an extension. - * * @return {@code true} unless the tag is an end-group tag. */ @Override @@ -1384,15 +1463,10 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial final CodedInputStream input, final UnknownFieldSet.Builder unknownFields, final ExtensionRegistryLite extensionRegistry, - final int tag) - throws IOException { + final int tag) throws IOException { return MessageReflection.mergeFieldFrom( - input, - unknownFields, - extensionRegistry, - getDescriptorForType(), - new MessageReflection.BuilderAdapter(this), - tag); + input, unknownFields, extensionRegistry, getDescriptorForType(), + new MessageReflection.BuilderAdapter(this), tag); } // --------------------------------------------------------------- @@ -1437,7 +1511,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public Object getRepeatedField(final FieldDescriptor field, final int index) { + public Object getRepeatedField(final FieldDescriptor field, + final int index) { if (field.isExtension()) { verifyContainingType(field); return extensions.getRepeatedField(field, index); @@ -1457,7 +1532,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public BuilderType setField(final FieldDescriptor field, final Object value) { + public BuilderType setField(final FieldDescriptor field, + final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1483,8 +1559,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public BuilderType setRepeatedField( - final FieldDescriptor field, final int index, final Object value) { + public BuilderType setRepeatedField(final FieldDescriptor field, + final int index, final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1497,7 +1573,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + public BuilderType addRepeatedField(final FieldDescriptor field, + final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1517,7 +1594,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial private void verifyContainingType(final FieldDescriptor field) { if (field.getContainingType() != getDescriptorForType()) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } } } @@ -1525,8 +1603,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // ----------------------------------------------------------------- /** - * Gets the descriptor for an extension. The implementation depends on whether the extension is - * scoped in the top level of a file or scoped in a Message. + * Gets the descriptor for an extension. The implementation depends on whether + * the extension is scoped in the top level of a file or scoped in a Message. */ static interface ExtensionDescriptorRetriever { FieldDescriptor getDescriptor(); @@ -1534,11 +1612,11 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** For use by generated code only. */ public static - GeneratedExtension newMessageScopedGeneratedExtension( - final Message scope, - final int descriptorIndex, - final Class singularType, - final Message defaultInstance) { + GeneratedExtension + newMessageScopedGeneratedExtension(final Message scope, + final int descriptorIndex, + final Class singularType, + final Message defaultInstance) { // For extensions scoped within a Message, we use the Message to resolve // the outer class's descriptor, from which the extension descriptor is // obtained. @@ -1556,21 +1634,22 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** For use by generated code only. */ public static - GeneratedExtension newFileScopedGeneratedExtension( - final Class singularType, final Message defaultInstance) { + GeneratedExtension + newFileScopedGeneratedExtension(final Class singularType, + final Message defaultInstance) { // For extensions scoped within a file, we rely on the outer class's // static initializer to call internalInit() on the extension when the // descriptor is available. return new GeneratedExtension( - null, // ExtensionDescriptorRetriever is initialized in internalInit(); + null, // ExtensionDescriptorRetriever is initialized in internalInit(); singularType, defaultInstance, Extension.ExtensionType.IMMUTABLE); } - private abstract static class CachedDescriptorRetriever implements ExtensionDescriptorRetriever { + private abstract static class CachedDescriptorRetriever + implements ExtensionDescriptorRetriever { private volatile FieldDescriptor descriptor; - protected abstract FieldDescriptor loadDescriptor(); @Override @@ -1589,16 +1668,15 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Used in proto1 generated code only. * - *

After enabling bridge, we can define proto2 extensions (the extended type is a proto2 - * mutable message) in a proto1 .proto file. For these extensions we should generate proto2 - * GeneratedExtensions. + * After enabling bridge, we can define proto2 extensions (the extended type + * is a proto2 mutable message) in a proto1 .proto file. For these extensions + * we should generate proto2 GeneratedExtensions. */ public static - GeneratedExtension newMessageScopedGeneratedExtension( - final Message scope, - final String name, - final Class singularType, - final Message defaultInstance) { + GeneratedExtension + newMessageScopedGeneratedExtension( + final Message scope, final String name, + final Class singularType, final Message defaultInstance) { // For extensions scoped within a Message, we use the Message to resolve // the outer class's descriptor, from which the extension descriptor is // obtained. @@ -1617,16 +1695,15 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Used in proto1 generated code only. * - *

After enabling bridge, we can define proto2 extensions (the extended type is a proto2 - * mutable message) in a proto1 .proto file. For these extensions we should generate proto2 - * GeneratedExtensions. + * After enabling bridge, we can define proto2 extensions (the extended type + * is a proto2 mutable message) in a proto1 .proto file. For these extensions + * we should generate proto2 GeneratedExtensions. */ public static - GeneratedExtension newFileScopedGeneratedExtension( - final Class singularType, - final Message defaultInstance, - final String descriptorOuterClass, - final String extensionName) { + GeneratedExtension + newFileScopedGeneratedExtension( + final Class singularType, final Message defaultInstance, + final String descriptorOuterClass, final String extensionName) { // For extensions scoped within a file, we load the descriptor outer // class and rely on it to get the FileDescriptor which then can be // used to obtain the extension's FieldDescriptor. @@ -1653,8 +1730,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Type used to represent generated extensions. The protocol compiler generates a static singleton - * instance of this class for each extension. + * Type used to represent generated extensions. The protocol compiler + * generates a static singleton instance of this class for each extension. * *

For example, imagine you have the {@code .proto} file: * @@ -1670,14 +1747,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial * } * * - *

Then, {@code MyProto.Foo.bar} has type {@code GeneratedExtension}. + *

Then, {@code MyProto.Foo.bar} has type + * {@code GeneratedExtension}. * - *

In general, users should ignore the details of this type, and simply use these static - * singletons as parameters to the extension accessors defined in {@link ExtendableMessage} and - * {@link ExtendableBuilder}. + *

In general, users should ignore the details of this type, and simply use + * these static singletons as parameters to the extension accessors defined + * in {@link ExtendableMessage} and {@link ExtendableBuilder}. */ - public static class GeneratedExtension - extends Extension { + public static class GeneratedExtension< + ContainingType extends Message, Type> extends + Extension { // TODO(kenton): Find ways to avoid using Java reflection within this // class. Also try to avoid suppressing unchecked warnings. @@ -1693,13 +1772,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // In the case of non-nested extensions, we initialize the // ExtensionDescriptorRetriever to null and rely on the outer class's static // initializer to call internalInit() after the descriptor has been parsed. - GeneratedExtension( - ExtensionDescriptorRetriever descriptorRetriever, + GeneratedExtension(ExtensionDescriptorRetriever descriptorRetriever, Class singularType, Message messageDefaultInstance, ExtensionType extensionType) { - if (Message.class.isAssignableFrom(singularType) - && !singularType.isInstance(messageDefaultInstance)) { + if (Message.class.isAssignableFrom(singularType) && + !singularType.isInstance(messageDefaultInstance)) { throw new IllegalArgumentException( "Bad messageDefaultInstance for " + singularType.getName()); } @@ -1708,8 +1786,10 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial this.messageDefaultInstance = messageDefaultInstance; if (ProtocolMessageEnum.class.isAssignableFrom(singularType)) { - this.enumValueOf = getMethodOrDie(singularType, "valueOf", EnumValueDescriptor.class); - this.enumGetValueDescriptor = getMethodOrDie(singularType, "getValueDescriptor"); + this.enumValueOf = getMethodOrDie(singularType, "valueOf", + EnumValueDescriptor.class); + this.enumGetValueDescriptor = + getMethodOrDie(singularType, "getValueDescriptor"); } else { this.enumValueOf = null; this.enumGetValueDescriptor = null; @@ -1741,14 +1821,15 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public FieldDescriptor getDescriptor() { if (descriptorRetriever == null) { - throw new IllegalStateException("getDescriptor() called before internalInit()"); + throw new IllegalStateException( + "getDescriptor() called before internalInit()"); } return descriptorRetriever.getDescriptor(); } /** - * If the extension is an embedded message or group, returns the default instance of the - * message. + * If the extension is an embedded message or group, returns the default + * instance of the message. */ @Override public Message getMessageDefaultInstance() { @@ -1761,17 +1842,18 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Convert from the type used by the reflection accessors to the type used by native accessors. - * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors - * use the generated enum type. + * Convert from the type used by the reflection accessors to the type used + * by native accessors. E.g., for enums, the reflection accessors use + * EnumValueDescriptors but the native accessors use the generated enum + * type. */ @Override @SuppressWarnings("unchecked") protected Object fromReflectionType(final Object value) { FieldDescriptor descriptor = getDescriptor(); if (descriptor.isRepeated()) { - if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE - || descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { + if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE || + descriptor.getJavaType() == FieldDescriptor.JavaType.ENUM) { // Must convert the whole list. final List result = new ArrayList(); for (final Object element : (List) value) { @@ -1787,8 +1869,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Like {@link #fromReflectionType(Object)}, but if the type is a repeated type, this converts a - * single element. + * Like {@link #fromReflectionType(Object)}, but if the type is a repeated + * type, this converts a single element. */ @Override protected Object singularFromReflectionType(final Object value) { @@ -1798,7 +1880,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial if (singularType.isInstance(value)) { return value; } else { - return messageDefaultInstance.newBuilderForType().mergeFrom((Message) value).build(); + return messageDefaultInstance.newBuilderForType() + .mergeFrom((Message) value).build(); } case ENUM: return invokeOrDie(enumValueOf, null, (EnumValueDescriptor) value); @@ -1808,9 +1891,10 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Convert from the type used by the native accessors to the type used by reflection accessors. - * E.g., for enums, the reflection accessors use EnumValueDescriptors but the native accessors - * use the generated enum type. + * Convert from the type used by the native accessors to the type used + * by reflection accessors. E.g., for enums, the reflection accessors use + * EnumValueDescriptors but the native accessors use the generated enum + * type. */ @Override @SuppressWarnings("unchecked") @@ -1833,8 +1917,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Like {@link #toReflectionType(Object)}, but if the type is a repeated type, this converts a - * single element. + * Like {@link #toReflectionType(Object)}, but if the type is a repeated + * type, this converts a single element. */ @Override protected Object singularToReflectionType(final Object value) { @@ -1871,7 +1955,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial if (getDescriptor().getJavaType() == FieldDescriptor.JavaType.MESSAGE) { return (Type) messageDefaultInstance; } - return (Type) singularFromReflectionType(getDescriptor().getDefaultValue()); + return (Type) singularFromReflectionType( + getDescriptor().getDefaultValue()); } } @@ -1885,8 +1970,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial return clazz.getMethod(name, params); } catch (NoSuchMethodException e) { throw new RuntimeException( - "Generated message class \"" + clazz.getName() + "\" missing method \"" + name + "\".", - e); + "Generated message class \"" + clazz.getName() + + "\" missing method \"" + name + "\".", e); } } @@ -1897,7 +1982,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial return method.invoke(object, params); } catch (IllegalAccessException e) { throw new RuntimeException( - "Couldn't use Java reflection to implement protocol message " + "reflection.", e); + "Couldn't use Java reflection to implement protocol message " + + "reflection.", e); } catch (InvocationTargetException e) { final Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { @@ -1906,42 +1992,45 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial throw (Error) cause; } else { throw new RuntimeException( - "Unexpected exception thrown by generated accessor method.", cause); + "Unexpected exception thrown by generated accessor method.", cause); } } } /** - * Gets the map field with the given field number. This method should be overridden in the - * generated message class if the message contains map fields. + * Gets the map field with the given field number. This method should be + * overridden in the generated message class if the message contains map + * fields. * - *

Unlike other field types, reflection support for map fields can't be implemented based on - * generated public API because we need to access a map field as a list in reflection API but the - * generated API only allows us to access it as a map. This method returns the underlying map - * field directly and thus enables us to access the map field as a list. + * Unlike other field types, reflection support for map fields can't be + * implemented based on generated public API because we need to access a + * map field as a list in reflection API but the generated API only allows + * us to access it as a map. This method returns the underlying map field + * directly and thus enables us to access the map field as a list. */ @SuppressWarnings({"rawtypes", "unused"}) protected MapField internalGetMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } /** - * Users should ignore this class. This class provides the implementation with access to the - * fields of a message object using Java reflection. + * Users should ignore this class. This class provides the implementation + * with access to the fields of a message object using Java reflection. */ public static final class FieldAccessorTable { /** - * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable - * should ever be constructed per class. + * Construct a FieldAccessorTable for a particular message class. Only + * one FieldAccessorTable should ever be constructed per class. * - * @param descriptor The type's descriptor. - * @param camelCaseNames The camelcase names of all fields in the message. These are used to - * derive the accessor method names. - * @param messageClass The message type. - * @param builderClass The builder type. + * @param descriptor The type's descriptor. + * @param camelCaseNames The camelcase names of all fields in the message. + * These are used to derive the accessor method names. + * @param messageClass The message type. + * @param builderClass The builder type. */ public FieldAccessorTable( final Descriptor descriptor, @@ -1953,10 +2042,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Construct a FieldAccessorTable for a particular message class without initializing - * FieldAccessors. + * Construct a FieldAccessorTable for a particular message class without + * initializing FieldAccessors. */ - public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) { + public FieldAccessorTable( + final Descriptor descriptor, + final String[] camelCaseNames) { this.descriptor = descriptor; this.camelCaseNames = camelCaseNames; fields = new FieldAccessor[descriptor.getFields().size()]; @@ -1972,19 +2063,16 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Ensures the field accessors are initialized. This method is thread-safe. * - * @param messageClass The message type. - * @param builderClass The builder type. + * @param messageClass The message type. + * @param builderClass The builder type. * @return this */ public FieldAccessorTable ensureFieldAccessorsInitialized( - Class messageClass, Class builderClass) { - if (initialized) { - return this; - } + Class messageClass, + Class builderClass) { + if (initialized) { return this; } synchronized (this) { - if (initialized) { - return this; - } + if (initialized) { return this; } int fieldsSize = fields.length; for (int i = 0; i < fieldsSize; i++) { FieldDescriptor field = descriptor.getFields().get(i); @@ -1996,63 +2084,45 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial if (field.isRepeated()) { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isMapField() && isMapFieldEnabled(field)) { - fields[i] = - new MapFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new MapFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } else { - fields[i] = - new RepeatedMessageFieldAccessor( - field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { - fields[i] = - new RepeatedEnumFieldAccessor( - field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } else { - fields[i] = - new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } } else { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - fields[i] = - new SingularMessageFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { - fields[i] = - new SingularEnumFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) { - fields[i] = - new SingularStringFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularStringFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else { - fields[i] = - new SingularFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } } } int oneofsSize = oneofs.length; for (int i = 0; i < oneofsSize; i++) { - oneofs[i] = - new OneofAccessor( - descriptor, camelCaseNames[i + fieldsSize], messageClass, builderClass); + oneofs[i] = new OneofAccessor( + descriptor, camelCaseNames[i + fieldsSize], + messageClass, builderClass); } initialized = true; camelCaseNames = null; @@ -2069,11 +2139,13 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** Get the FieldAccessor for a particular field. */ private FieldAccessor getField(final FieldDescriptor field) { if (field.getContainingType() != descriptor) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } else if (field.isExtension()) { // If this type had extensions, it would subclass ExtendableMessage, // which overrides the reflection interface to handle extensions. - throw new IllegalArgumentException("This type does not have extensions."); + throw new IllegalArgumentException( + "This type does not have extensions."); } return fields[field.getIndex()]; } @@ -2081,65 +2153,51 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** Get the OneofAccessor for a particular oneof. */ private OneofAccessor getOneof(final OneofDescriptor oneof) { if (oneof.getContainingType() != descriptor) { - throw new IllegalArgumentException("OneofDescriptor does not match message type."); + throw new IllegalArgumentException( + "OneofDescriptor does not match message type."); } return oneofs[oneof.getIndex()]; } /** - * Abstract interface that provides access to a single field. This is implemented differently - * depending on the field type and cardinality. + * Abstract interface that provides access to a single field. This is + * implemented differently depending on the field type and cardinality. */ private interface FieldAccessor { Object get(GeneratedMessage message); - Object get(GeneratedMessage.Builder builder); - Object getRaw(GeneratedMessage message); - Object getRaw(GeneratedMessage.Builder builder); - void set(Builder builder, Object value); - Object getRepeated(GeneratedMessage message, int index); - Object getRepeated(GeneratedMessage.Builder builder, int index); - Object getRepeatedRaw(GeneratedMessage message, int index); - Object getRepeatedRaw(GeneratedMessage.Builder builder, int index); - - void setRepeated(Builder builder, int index, Object value); - + void setRepeated(Builder builder, + int index, Object value); void addRepeated(Builder builder, Object value); - boolean has(GeneratedMessage message); - boolean has(GeneratedMessage.Builder builder); - int getRepeatedCount(GeneratedMessage message); - int getRepeatedCount(GeneratedMessage.Builder builder); - void clear(Builder builder); - Message.Builder newBuilder(); - Message.Builder getBuilder(GeneratedMessage.Builder builder); - - Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index); + Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, + int index); } /** OneofAccessor provides access to a single oneof. */ private static class OneofAccessor { OneofAccessor( - final Descriptor descriptor, - final String camelCaseName, + final Descriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { this.descriptor = descriptor; - caseMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); - caseMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); + caseMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Case"); + caseMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Case"); clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); } @@ -2191,32 +2249,27 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial private static class SingularFieldAccessor implements FieldAccessor { SingularFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { field = descriptor; isOneofField = descriptor.getContainingOneof() != null; - hasHasMethod = - supportFieldPresence(descriptor.getFile()) - || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); + hasHasMethod = supportFieldPresence(descriptor.getFile()) + || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE); getMethod = getMethodOrDie(messageClass, "get" + camelCaseName); getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName); type = getMethod.getReturnType(); setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type); - hasMethod = hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; + hasMethod = + hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null; hasMethodBuilder = hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null; clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); - caseMethod = - isOneofField - ? getMethodOrDie(messageClass, "get" + containingOneofCamelCaseName + "Case") - : null; - caseMethodBuilder = - isOneofField - ? getMethodOrDie(builderClass, "get" + containingOneofCamelCaseName + "Case") - : null; + caseMethod = isOneofField ? getMethodOrDie( + messageClass, "get" + containingOneofCamelCaseName + "Case") : null; + caseMethodBuilder = isOneofField ? getMethodOrDie( + builderClass, "get" + containingOneofCamelCaseName + "Case") : null; } // Note: We use Java reflection to call public methods rather than @@ -2247,59 +2300,52 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial public Object get(final GeneratedMessage message) { return invokeOrDie(getMethod, message); } - @Override public Object get(GeneratedMessage.Builder builder) { return invokeOrDie(getMethodBuilder, builder); } - @Override public Object getRaw(final GeneratedMessage message) { return get(message); } - @Override public Object getRaw(GeneratedMessage.Builder builder) { return get(builder); } - @Override public void set(final Builder builder, final Object value) { invokeOrDie(setMethod, builder, value); } - @Override public Object getRepeated(final GeneratedMessage message, final int index) { - throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + throw new UnsupportedOperationException( + "getRepeatedField() called on a singular field."); } - @Override public Object getRepeatedRaw(final GeneratedMessage message, final int index) { throw new UnsupportedOperationException( - "getRepeatedFieldRaw() called on a singular field."); + "getRepeatedFieldRaw() called on a singular field."); } - @Override public Object getRepeated(GeneratedMessage.Builder builder, int index) { - throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); + throw new UnsupportedOperationException( + "getRepeatedField() called on a singular field."); } - @Override public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) { throw new UnsupportedOperationException( - "getRepeatedFieldRaw() called on a singular field."); + "getRepeatedFieldRaw() called on a singular field."); } - @Override public void setRepeated(final Builder builder, final int index, final Object value) { - throw new UnsupportedOperationException("setRepeatedField() called on a singular field."); + throw new UnsupportedOperationException( + "setRepeatedField() called on a singular field."); } - @Override public void addRepeated(final Builder builder, final Object value) { - throw new UnsupportedOperationException("addRepeatedField() called on a singular field."); + throw new UnsupportedOperationException( + "addRepeatedField() called on a singular field."); } - @Override public boolean has(final GeneratedMessage message) { if (!hasHasMethod) { @@ -2310,7 +2356,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } return (Boolean) invokeOrDie(hasMethod, message); } - @Override public boolean has(GeneratedMessage.Builder builder) { if (!hasHasMethod) { @@ -2321,39 +2366,34 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } return (Boolean) invokeOrDie(hasMethodBuilder, builder); } - @Override public int getRepeatedCount(final GeneratedMessage message) { throw new UnsupportedOperationException( - "getRepeatedFieldSize() called on a singular field."); + "getRepeatedFieldSize() called on a singular field."); } - @Override public int getRepeatedCount(GeneratedMessage.Builder builder) { throw new UnsupportedOperationException( - "getRepeatedFieldSize() called on a singular field."); + "getRepeatedFieldSize() called on a singular field."); } - @Override public void clear(final Builder builder) { invokeOrDie(clearMethod, builder); } - @Override public Message.Builder newBuilder() { throw new UnsupportedOperationException( - "newBuilderForField() called on a non-Message type."); + "newBuilderForField() called on a non-Message type."); } - @Override public Message.Builder getBuilder(GeneratedMessage.Builder builder) { - throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + throw new UnsupportedOperationException( + "getFieldBuilder() called on a non-Message type."); } - @Override public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) { throw new UnsupportedOperationException( - "getRepeatedFieldBuilder() called on a non-Message type."); + "getRepeatedFieldBuilder() called on a non-Message type."); } } @@ -2370,20 +2410,27 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial protected final Method clearMethod; RepeatedFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { - getMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "List"); - getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "List"); - getRepeatedMethod = getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE); + getMethod = getMethodOrDie(messageClass, + "get" + camelCaseName + "List"); + getMethodBuilder = getMethodOrDie(builderClass, + "get" + camelCaseName + "List"); + getRepeatedMethod = + getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE); getRepeatedMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE); type = getRepeatedMethod.getReturnType(); - setRepeatedMethod = getMethodOrDie(builderClass, "set" + camelCaseName, Integer.TYPE, type); - addRepeatedMethod = getMethodOrDie(builderClass, "add" + camelCaseName, type); - getCountMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Count"); - getCountMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Count"); + setRepeatedMethod = + getMethodOrDie(builderClass, "set" + camelCaseName, + Integer.TYPE, type); + addRepeatedMethod = + getMethodOrDie(builderClass, "add" + camelCaseName, type); + getCountMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Count"); + getCountMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Count"); clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName); } @@ -2392,22 +2439,18 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial public Object get(final GeneratedMessage message) { return invokeOrDie(getMethod, message); } - @Override public Object get(GeneratedMessage.Builder builder) { return invokeOrDie(getMethodBuilder, builder); } - @Override public Object getRaw(final GeneratedMessage message) { return get(message); } - @Override public Object getRaw(GeneratedMessage.Builder builder) { return get(builder); } - @Override public void set(final Builder builder, final Object value) { // Add all the elements individually. This serves two purposes: @@ -2419,91 +2462,81 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial addRepeated(builder, element); } } - @Override public Object getRepeated(final GeneratedMessage message, final int index) { return invokeOrDie(getRepeatedMethod, message, index); } - @Override public Object getRepeated(GeneratedMessage.Builder builder, int index) { return invokeOrDie(getRepeatedMethodBuilder, builder, index); } - @Override public Object getRepeatedRaw(GeneratedMessage message, int index) { return getRepeated(message, index); } - @Override public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) { return getRepeated(builder, index); } - @Override public void setRepeated(final Builder builder, final int index, final Object value) { invokeOrDie(setRepeatedMethod, builder, index, value); } - @Override public void addRepeated(final Builder builder, final Object value) { invokeOrDie(addRepeatedMethod, builder, value); } - @Override public boolean has(final GeneratedMessage message) { - throw new UnsupportedOperationException("hasField() called on a repeated field."); + throw new UnsupportedOperationException( + "hasField() called on a repeated field."); } - @Override public boolean has(GeneratedMessage.Builder builder) { - throw new UnsupportedOperationException("hasField() called on a repeated field."); + throw new UnsupportedOperationException( + "hasField() called on a repeated field."); } - @Override public int getRepeatedCount(final GeneratedMessage message) { return (Integer) invokeOrDie(getCountMethod, message); } - @Override public int getRepeatedCount(GeneratedMessage.Builder builder) { return (Integer) invokeOrDie(getCountMethodBuilder, builder); } - @Override public void clear(final Builder builder) { invokeOrDie(clearMethod, builder); } - @Override public Message.Builder newBuilder() { throw new UnsupportedOperationException( - "newBuilderForField() called on a non-Message type."); + "newBuilderForField() called on a non-Message type."); } - @Override public Message.Builder getBuilder(GeneratedMessage.Builder builder) { - throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); + throw new UnsupportedOperationException( + "getFieldBuilder() called on a non-Message type."); } - @Override public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) { throw new UnsupportedOperationException( - "getRepeatedFieldBuilder() called on a non-Message type."); + "getRepeatedFieldBuilder() called on a non-Message type."); } } private static class MapFieldAccessor implements FieldAccessor { MapFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { field = descriptor; - Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); - MapField defaultMapField = - getMapField((GeneratedMessage) invokeOrDie(getDefaultInstanceMethod, null)); - mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); + Method getDefaultInstanceMethod = + getMethodOrDie(messageClass, "getDefaultInstance"); + MapField defaultMapField = getMapField( + (GeneratedMessage) invokeOrDie(getDefaultInstanceMethod, null)); + mapEntryMessageDefaultInstance = + defaultMapField.getMapEntryMessageDefaultInstance(); } private final FieldDescriptor field; @@ -2517,8 +2550,10 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial return (MapField) builder.internalGetMapField(field.getNumber()); } - private MapField getMutableMapField(GeneratedMessage.Builder builder) { - return (MapField) builder.internalGetMutableMapField(field.getNumber()); + private MapField getMutableMapField( + GeneratedMessage.Builder builder) { + return (MapField) builder.internalGetMutableMapField( + field.getNumber()); } @Override @@ -2591,12 +2626,14 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public boolean has(GeneratedMessage message) { - throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + throw new UnsupportedOperationException( + "hasField() is not supported for repeated fields."); } @Override public boolean has(Builder builder) { - throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + throw new UnsupportedOperationException( + "hasField() is not supported for repeated fields."); } @Override @@ -2621,21 +2658,23 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public com.google.protobuf.Message.Builder getBuilder(Builder builder) { - throw new UnsupportedOperationException("Nested builder not supported for map fields."); + throw new UnsupportedOperationException( + "Nested builder not supported for map fields."); } @Override public com.google.protobuf.Message.Builder getRepeatedBuilder(Builder builder, int index) { - throw new UnsupportedOperationException("Nested builder not supported for map fields."); + throw new UnsupportedOperationException( + "Nested builder not supported for map fields."); } } // --------------------------------------------------------------- - private static final class SingularEnumFieldAccessor extends SingularFieldAccessor { + private static final class SingularEnumFieldAccessor + extends SingularFieldAccessor { SingularEnumFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { @@ -2643,14 +2682,19 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial enumDescriptor = descriptor.getEnumType(); - valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); - getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + valueOfMethod = getMethodOrDie(type, "valueOf", + EnumValueDescriptor.class); + getValueDescriptorMethod = + getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { - getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); - getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); - setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); + getValueMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); + getValueMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); + setValueMethod = + getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); } } @@ -2685,25 +2729,28 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial @Override public void set(final Builder builder, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie(setValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + invokeOrDie(setValueMethod, builder, + ((EnumValueDescriptor) value).getNumber()); return; } super.set(builder, invokeOrDie(valueOfMethod, null, value)); } } - private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor { + private static final class RepeatedEnumFieldAccessor + extends RepeatedFieldAccessor { RepeatedEnumFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); enumDescriptor = descriptor.getEnumType(); - valueOfMethod = getMethodOrDie(type, "valueOf", EnumValueDescriptor.class); - getValueDescriptorMethod = getMethodOrDie(type, "getValueDescriptor"); + valueOfMethod = getMethodOrDie(type, "valueOf", + EnumValueDescriptor.class); + getValueDescriptorMethod = + getMethodOrDie(type, "getValueDescriptor"); supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { @@ -2717,7 +2764,6 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); } } - private EnumDescriptor enumDescriptor; private final Method valueOfMethod; @@ -2752,37 +2798,41 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } @Override - public Object getRepeated(final GeneratedMessage message, final int index) { + public Object getRepeated(final GeneratedMessage message, + final int index) { if (supportUnknownEnumValue) { int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index); return enumDescriptor.findValueByNumberCreatingIfUnknown(value); } - return invokeOrDie(getValueDescriptorMethod, super.getRepeated(message, index)); + return invokeOrDie(getValueDescriptorMethod, + super.getRepeated(message, index)); } - @Override - public Object getRepeated(final GeneratedMessage.Builder builder, final int index) { + public Object getRepeated(final GeneratedMessage.Builder builder, + final int index) { if (supportUnknownEnumValue) { int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index); return enumDescriptor.findValueByNumberCreatingIfUnknown(value); } - return invokeOrDie(getValueDescriptorMethod, super.getRepeated(builder, index)); + return invokeOrDie(getValueDescriptorMethod, + super.getRepeated(builder, index)); } - @Override - public void setRepeated(final Builder builder, final int index, final Object value) { + public void setRepeated(final Builder builder, + final int index, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie( - setRepeatedValueMethod, builder, index, ((EnumValueDescriptor) value).getNumber()); + invokeOrDie(setRepeatedValueMethod, builder, index, + ((EnumValueDescriptor) value).getNumber()); return; } - super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); + super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, + value)); } - @Override public void addRepeated(final Builder builder, final Object value) { if (supportUnknownEnumValue) { - invokeOrDie(addRepeatedValueMethod, builder, ((EnumValueDescriptor) value).getNumber()); + invokeOrDie(addRepeatedValueMethod, builder, + ((EnumValueDescriptor) value).getNumber()); return; } super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value)); @@ -2794,25 +2844,29 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial /** * Field accessor for string fields. * - *

This class makes getFooBytes() and setFooBytes() available for reflection API so that - * reflection based serialize/parse functions can access the raw bytes of the field to preserve - * non-UTF8 bytes in the string. + *

This class makes getFooBytes() and setFooBytes() available for + * reflection API so that reflection based serialize/parse functions can + * access the raw bytes of the field to preserve non-UTF8 bytes in the + * string. * - *

This ensures the serialize/parse round-trip safety, which is important for servers which - * forward messages. + *

This ensures the serialize/parse round-trip safety, which is important + * for servers which forward messages. */ - private static final class SingularStringFieldAccessor extends SingularFieldAccessor { + private static final class SingularStringFieldAccessor + extends SingularFieldAccessor { SingularStringFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { - super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); - getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes"); - getBytesMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Bytes"); - setBytesMethodBuilder = - getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class); + super(descriptor, camelCaseName, messageClass, builderClass, + containingOneofCamelCaseName); + getBytesMethod = getMethodOrDie(messageClass, + "get" + camelCaseName + "Bytes"); + getBytesMethodBuilder = getMethodOrDie(builderClass, + "get" + camelCaseName + "Bytes"); + setBytesMethodBuilder = getMethodOrDie(builderClass, + "set" + camelCaseName + "Bytes", ByteString.class); } private final Method getBytesMethod; @@ -2841,17 +2895,19 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // --------------------------------------------------------------- - private static final class SingularMessageFieldAccessor extends SingularFieldAccessor { + private static final class SingularMessageFieldAccessor + extends SingularFieldAccessor { SingularMessageFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { - super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + super(descriptor, camelCaseName, messageClass, builderClass, + containingOneofCamelCaseName); newBuilderMethod = getMethodOrDie(type, "newBuilder"); - getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); + getBuilderMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); } private final Method newBuilderMethod; @@ -2866,8 +2922,7 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // DynamicMessage -- we should accept it. In this case we can make // a copy of the message. return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) - .mergeFrom((Message) value) - .buildPartial(); + .mergeFrom((Message) value).buildPartial(); } } @@ -2875,29 +2930,27 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial public void set(final Builder builder, final Object value) { super.set(builder, coerceType(value)); } - @Override public Message.Builder newBuilder() { return (Message.Builder) invokeOrDie(newBuilderMethod, null); } - @Override public Message.Builder getBuilder(GeneratedMessage.Builder builder) { return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); } } - private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor { + private static final class RepeatedMessageFieldAccessor + extends RepeatedFieldAccessor { RepeatedMessageFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); newBuilderMethod = getMethodOrDie(type, "newBuilder"); - getBuilderMethodBuilder = - getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE); + getBuilderMethodBuilder = getMethodOrDie(builderClass, + "get" + camelCaseName + "Builder", Integer.TYPE); } private final Method newBuilderMethod; @@ -2912,39 +2965,36 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial // DynamicMessage -- we should accept it. In this case we can make // a copy of the message. return ((Message.Builder) invokeOrDie(newBuilderMethod, null)) - .mergeFrom((Message) value) - .build(); + .mergeFrom((Message) value).build(); } } @Override - public void setRepeated(final Builder builder, final int index, final Object value) { + public void setRepeated(final Builder builder, + final int index, final Object value) { super.setRepeated(builder, index, coerceType(value)); } - @Override public void addRepeated(final Builder builder, final Object value) { super.addRepeated(builder, coerceType(value)); } - @Override public Message.Builder newBuilder() { return (Message.Builder) invokeOrDie(newBuilderMethod, null); } - @Override public Message.Builder getRepeatedBuilder( final GeneratedMessage.Builder builder, final int index) { - return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); + return (Message.Builder) invokeOrDie( + getBuilderMethodBuilder, builder, index); } } } /** - * Replaces this object in the output stream with a serialized form. Part of Java's serialization - * magic. Generated sub-classes must override this method by calling {@code return - * super.writeReplace();} - * + * Replaces this object in the output stream with a serialized form. + * Part of Java's serialization magic. Generated sub-classes must override + * this method by calling {@code return super.writeReplace();} * @return a SerializedForm of this message */ protected Object writeReplace() throws ObjectStreamException { @@ -2952,10 +3002,12 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } /** - * Checks that the {@link Extension} is non-Lite and returns it as a {@link GeneratedExtension}. + * Checks that the {@link Extension} is non-Lite and returns it as a + * {@link GeneratedExtension}. */ private static , T> - Extension checkNotLite(ExtensionLite extension) { + Extension checkNotLite( + ExtensionLite extension) { if (extension.isLite()) { throw new IllegalArgumentException("Expected non-lite extension."); } @@ -2988,8 +3040,8 @@ public abstract class GeneratedMessage extends AbstractMessage implements Serial } } - protected static void writeStringNoTag(CodedOutputStream output, final Object value) - throws IOException { + protected static void writeStringNoTag( + CodedOutputStream output, final Object value) throws IOException { if (value instanceof String) { output.writeStringNoTag((String) value); } else { diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java index ac975b9..1ef2143 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java @@ -188,7 +188,7 @@ public abstract class GeneratedMessageLite< // any unnecessary intermediary allocations while reducing the generated code size. /** Lazily initializes unknown fields. */ - private void ensureUnknownFieldsInitialized() { + private final void ensureUnknownFieldsInitialized() { if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) { unknownFields = UnknownFieldSetLite.newInstance(); } @@ -295,16 +295,11 @@ public abstract class GeneratedMessageLite< * *

For use by generated code only. */ - protected abstract Object dynamicMethod( - MethodToInvoke method, - Object arg0, - Object arg1); + protected abstract Object dynamicMethod(MethodToInvoke method, Object arg0, Object arg1); /** Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding. */ @CanIgnoreReturnValue - protected Object dynamicMethod( - MethodToInvoke method, - Object arg0) { + protected Object dynamicMethod(MethodToInvoke method, Object arg0) { return dynamicMethod(method, arg0, null); } @@ -1355,11 +1350,11 @@ public abstract class GeneratedMessageLite< } @SuppressWarnings("unchecked") - Object fromFieldSetType(Object value) { + Object fromFieldSetType(final Object value) { if (descriptor.isRepeated()) { if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { - List result = new ArrayList<>(); - for (Object element : (List) value) { + final List result = new ArrayList<>(); + for (final Object element : (List) value) { result.add(singularFromFieldSetType(element)); } return result; @@ -1371,7 +1366,7 @@ public abstract class GeneratedMessageLite< } } - Object singularFromFieldSetType(Object value) { + Object singularFromFieldSetType(final Object value) { if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { return descriptor.enumTypeMap.findValueByNumber((Integer) value); } else { @@ -1379,11 +1374,12 @@ public abstract class GeneratedMessageLite< } } - Object toFieldSetType(Object value) { + @SuppressWarnings("unchecked") + Object toFieldSetType(final Object value) { if (descriptor.isRepeated()) { if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { - List result = new ArrayList<>(); - for (Object element : (List) value) { + final List result = new ArrayList<>(); + for (final Object element : (List) value) { result.add(singularToFieldSetType(element)); } return result; @@ -1395,7 +1391,7 @@ public abstract class GeneratedMessageLite< } } - Object singularToFieldSetType(Object value) { + Object singularToFieldSetType(final Object value) { if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) { return ((Internal.EnumLite) value).getNumber(); } else { diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java index 41ea0a1..355bf46 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java @@ -69,13 +69,15 @@ import java.util.Map; import java.util.TreeMap; /** - * All generated protocol message classes extend this class. This class implements most of the - * Message and Builder interfaces using Java reflection. Users can ignore this class and pretend - * that generated messages implement the Message interface directly. + * All generated protocol message classes extend this class. This class + * implements most of the Message and Builder interfaces using Java reflection. + * Users can ignore this class and pretend that generated messages implement + * the Message interface directly. * * @author kenton@google.com Kenton Varda */ -public abstract class GeneratedMessageV3 extends AbstractMessage implements Serializable { +public abstract class GeneratedMessageV3 extends AbstractMessage + implements Serializable { private static final long serialVersionUID = 1L; /** @@ -85,7 +87,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri */ protected static boolean alwaysUseFieldBuilders = false; - /** For use by generated code only. */ + /** For use by generated code only. */ protected UnknownFieldSet unknownFields; protected GeneratedMessageV3() { @@ -98,29 +100,31 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public Parser getParserForType() { - throw new UnsupportedOperationException("This is supposed to be overridden by subclasses."); + throw new UnsupportedOperationException( + "This is supposed to be overridden by subclasses."); } - /** - * @see #setAlwaysUseFieldBuildersForTesting(boolean) - */ + /** + * @see #setAlwaysUseFieldBuildersForTesting(boolean) + */ static void enableAlwaysUseFieldBuildersForTesting() { setAlwaysUseFieldBuildersForTesting(true); } /** - * For testing. Allows a test to disable/re-enable the optimization that avoids using field - * builders for nested messages until they are requested. By disabling this optimization, existing - * tests can be reused to test the field builders. See {@link RepeatedFieldBuilder} and {@link - * SingleFieldBuilder}. + * For testing. Allows a test to disable/re-enable the optimization that avoids + * using field builders for nested messages until they are requested. By disabling + * this optimization, existing tests can be reused to test the field builders. + * See {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder}. */ static void setAlwaysUseFieldBuildersForTesting(boolean useBuilders) { alwaysUseFieldBuilders = useBuilders; } /** - * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the - * constructor because of bootstrapping trouble with DescriptorProtos. + * Get the FieldAccessorTable for this type. We can't have the message + * class pass this in to the constructor because of bootstrapping trouble + * with DescriptorProtos. */ protected abstract FieldAccessorTable internalGetFieldAccessorTable(); @@ -149,14 +153,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Internal helper to return a modifiable map containing all the fields. The returned Map is - * modifiable so that the caller can add additional extension fields to implement {@link - * #getAllFields()}. + * Internal helper to return a modifiable map containing all the fields. + * The returned Map is modifiable so that the caller can add additional + * extension fields to implement {@link #getAllFields()}. * * @param getBytesForString whether to generate ByteString for string fields */ - private Map getAllFieldsMutable(boolean getBytesForString) { - final TreeMap result = new TreeMap(); + private Map getAllFieldsMutable( + boolean getBytesForString) { + final TreeMap result = + new TreeMap(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -212,8 +218,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // Check that embedded messages are initialized. if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isRepeated()) { - @SuppressWarnings("unchecked") - final List messageList = (List) getField(field); + @SuppressWarnings("unchecked") final + List messageList = (List) getField(field); for (final Message element : messageList) { if (!element.isInitialized()) { return false; @@ -232,19 +238,23 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public Map getAllFields() { - return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ false)); + return Collections.unmodifiableMap( + getAllFieldsMutable(/* getBytesForString = */ false)); } /** - * Returns a collection of all the fields in this message which are set and their corresponding - * values. A singular ("required" or "optional") field is set iff hasField() returns true for that - * field. A "repeated" field is set iff getRepeatedFieldCount() is greater than zero. The values - * are exactly what would be returned by calling {@link #getFieldRaw(Descriptors.FieldDescriptor)} - * for each field. The map is guaranteed to be a sorted map, so iterating over it will return - * fields in order by field number. + * Returns a collection of all the fields in this message which are set + * and their corresponding values. A singular ("required" or "optional") + * field is set iff hasField() returns true for that field. A "repeated" + * field is set iff getRepeatedFieldCount() is greater than zero. The + * values are exactly what would be returned by calling + * {@link #getFieldRaw(Descriptors.FieldDescriptor)} for each field. The map + * is guaranteed to be a sorted map, so iterating over it will return fields + * in order by field number. */ Map getAllFieldsRaw() { - return Collections.unmodifiableMap(getAllFieldsMutable(/* getBytesForString = */ true)); + return Collections.unmodifiableMap( + getAllFieldsMutable(/* getBytesForString = */ true)); } @Override @@ -268,11 +278,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Obtains the value of the given field, or the default value if it is not set. For primitive - * fields, the boxed primitive value is returned. For enum fields, the EnumValueDescriptor for the - * value is returned. For embedded message fields, the sub-message is returned. For repeated - * fields, a java.util.List is returned. For present string fields, a ByteString is returned - * representing the bytes that the field contains. + * Obtains the value of the given field, or the default value if it is + * not set. For primitive fields, the boxed primitive value is returned. + * For enum fields, the EnumValueDescriptor for the value is returned. For + * embedded message fields, the sub-message is returned. For repeated + * fields, a java.util.List is returned. For present string fields, a + * ByteString is returned representing the bytes that the field contains. */ Object getFieldRaw(final FieldDescriptor field) { return internalGetFieldAccessorTable().getField(field).getRaw(this); @@ -280,12 +291,14 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public int getRepeatedFieldCount(final FieldDescriptor field) { - return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + return internalGetFieldAccessorTable().getField(field) + .getRepeatedCount(this); } @Override public Object getRepeatedField(final FieldDescriptor field, final int index) { - return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + return internalGetFieldAccessorTable().getField(field) + .getRepeated(this, index); } @Override @@ -336,8 +349,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static M parseWithIOException( - Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + protected static M parseWithIOException(Parser parser, InputStream input, + ExtensionRegistryLite extensions) throws IOException { try { return parser.parseFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -345,8 +358,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static M parseWithIOException( - Parser parser, CodedInputStream input) throws IOException { + protected static M parseWithIOException(Parser parser, + CodedInputStream input) throws IOException { try { return parser.parseFrom(input); } catch (InvalidProtocolBufferException e) { @@ -354,9 +367,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static M parseWithIOException( - Parser parser, CodedInputStream input, ExtensionRegistryLite extensions) - throws IOException { + protected static M parseWithIOException(Parser parser, + CodedInputStream input, ExtensionRegistryLite extensions) throws IOException { try { return parser.parseFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -364,8 +376,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static M parseDelimitedWithIOException( - Parser parser, InputStream input) throws IOException { + protected static M parseDelimitedWithIOException(Parser parser, + InputStream input) throws IOException { try { return parser.parseDelimitedFrom(input); } catch (InvalidProtocolBufferException e) { @@ -373,8 +385,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static M parseDelimitedWithIOException( - Parser parser, InputStream input, ExtensionRegistryLite extensions) throws IOException { + protected static M parseDelimitedWithIOException(Parser parser, + InputStream input, ExtensionRegistryLite extensions) throws IOException { try { return parser.parseDelimitedFrom(input, extensions); } catch (InvalidProtocolBufferException e) { @@ -475,53 +487,63 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } + /** * This class is used to make a generated protected method inaccessible from user's code (e.g., * the {@link #newInstance} method below). When this class is used as a parameter's type in a - * generated protected method, the method is visible to user's code in the same package, but since - * the constructor of this class is private to protobuf runtime, user's code can't obtain an - * instance of this class and as such can't actually make a method call on the protected method. + * generated protected method, the method is visible to user's code in the same package, but + * since the constructor of this class is private to protobuf runtime, user's code can't obtain + * an instance of this class and as such can't actually make a method call on the protected + * method. */ protected static final class UnusedPrivateParameter { static final UnusedPrivateParameter INSTANCE = new UnusedPrivateParameter(); - private UnusedPrivateParameter() {} + private UnusedPrivateParameter() { + } } - /** Creates a new instance of this message type. Overridden in the generated code. */ + /** + * Creates a new instance of this message type. Overridden in the generated code. + */ @SuppressWarnings({"unused"}) protected Object newInstance(UnusedPrivateParameter unused) { throw new UnsupportedOperationException("This method must be overridden by the subclass."); } - /** Used by parsing constructors in generated classes. */ + /** + * Used by parsing constructors in generated classes. + */ protected void makeExtensionsImmutable() { // Noop for messages without extensions. } /** - * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this interface to - * AbstractMessage in order to versioning GeneratedMessageV3 but this move breaks binary - * compatibility for AppEngine. After AppEngine is fixed we can exclude this from google3. + * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this + * interface to AbstractMessage in order to versioning GeneratedMessageV3 but + * this move breaks binary compatibility for AppEngine. After AppEngine is + * fixed we can exclude this from google3. */ protected interface BuilderParent extends AbstractMessage.BuilderParent {} - /** TODO(xiaofeng): remove this together with GeneratedMessageV3.BuilderParent. */ + /** + * TODO(xiaofeng): remove this together with GeneratedMessageV3.BuilderParent. + */ protected abstract Message.Builder newBuilderForType(BuilderParent parent); @Override protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) { - return newBuilderForType( - new BuilderParent() { - @Override - public void markDirty() { - parent.markDirty(); - } - }); + return newBuilderForType(new BuilderParent() { + @Override + public void markDirty() { + parent.markDirty(); + } + }); } + @SuppressWarnings("unchecked") - public abstract static class Builder> + public abstract static class Builder > extends AbstractMessage.Builder { private BuilderParent builderParent; @@ -558,7 +580,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri builderParent = null; } - /** Called by the subclass when a message is built. */ + /** + * Called by the subclass when a message is built. + */ protected void onBuilt() { if (builderParent != null) { markClean(); @@ -566,8 +590,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Called by the subclass or a builder to notify us that a message was built and may be cached - * and therefore invalidations are needed. + * Called by the subclass or a builder to notify us that a message was + * built and may be cached and therefore invalidations are needed. */ @Override protected void markClean() { @@ -585,14 +609,15 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public BuilderType clone() { - BuilderType builder = (BuilderType) getDefaultInstanceForType().newBuilderForType(); + BuilderType builder = + (BuilderType) getDefaultInstanceForType().newBuilderForType(); builder.mergeFrom(buildPartial()); return builder; } /** - * Called by the initialization and clear code paths to allow subclasses to reset any of their - * builtin fields back to the initial values. + * Called by the initialization and clear code paths to allow subclasses to + * reset any of their builtin fields back to the initial values. */ @Override public BuilderType clear() { @@ -602,8 +627,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Get the FieldAccessorTable for this type. We can't have the message class pass this in to the - * constructor because of bootstrapping trouble with DescriptorProtos. + * Get the FieldAccessorTable for this type. We can't have the message + * class pass this in to the constructor because of bootstrapping trouble + * with DescriptorProtos. */ protected abstract FieldAccessorTable internalGetFieldAccessorTable(); @@ -619,7 +645,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Internal helper which returns a mutable map. */ private Map getAllFieldsMutable() { - final TreeMap result = new TreeMap(); + final TreeMap result = + new TreeMap(); final Descriptor descriptor = internalGetFieldAccessorTable().descriptor; final List fields = descriptor.getFields(); @@ -671,7 +698,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) { - return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(this, index); + return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder( + this, index); } @Override @@ -721,18 +749,21 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public int getRepeatedFieldCount(final FieldDescriptor field) { - return internalGetFieldAccessorTable().getField(field).getRepeatedCount(this); + return internalGetFieldAccessorTable().getField(field) + .getRepeatedCount(this); } @Override public Object getRepeatedField(final FieldDescriptor field, final int index) { - return internalGetFieldAccessorTable().getField(field).getRepeated(this, index); + return internalGetFieldAccessorTable().getField(field) + .getRepeated(this, index); } @Override public BuilderType setRepeatedField( final FieldDescriptor field, final int index, final Object value) { - internalGetFieldAccessorTable().getField(field).setRepeated(this, index, value); + internalGetFieldAccessorTable().getField(field) + .setRepeated(this, index, value); return (BuilderType) this; } @@ -754,7 +785,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * This method is obsolete, but we must retain it for compatibility with older generated code. + * This method is obsolete, but we must retain it for compatibility with + * older generated code. */ protected BuilderType setUnknownFieldsProto3(final UnknownFieldSet unknownFields) { return setUnknownFieldsInternal(unknownFields); @@ -777,6 +809,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri return (BuilderType) this; } + @Override public boolean isInitialized() { for (final FieldDescriptor field : getDescriptorForType().getFields()) { @@ -789,15 +822,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // Check that embedded messages are initialized. if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isRepeated()) { - @SuppressWarnings("unchecked") - final List messageList = (List) getField(field); + @SuppressWarnings("unchecked") final + List messageList = (List) getField(field); for (final Message element : messageList) { if (!element.isInitialized()) { return false; } } } else { - if (hasField(field) && !((Message) getField(field)).isInitialized()) { + if (hasField(field) && + !((Message) getField(field)).isInitialized()) { return false; } } @@ -855,8 +889,9 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Implementation of {@link BuilderParent} for giving to our children. This small inner class - * makes it so we don't publicly expose the BuilderParent methods. + * Implementation of {@link BuilderParent} for giving to our children. This + * small inner class makes it so we don't publicly expose the BuilderParent + * methods. */ private class BuilderParentImpl implements BuilderParent { @@ -868,7 +903,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** * Gets the {@link BuilderParent} for giving to our children. - * * @return The builder parent for our children. */ protected BuilderParent getParentForChildren() { @@ -879,8 +913,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Called when a the builder or one of its nested children has changed and any parent should be - * notified of its invalidation. + * Called when a the builder or one of its nested children has changed + * and any parent should be notified of its invalidation. */ protected final void onChanged() { if (isClean && builderParent != null) { @@ -892,19 +926,22 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Gets the map field with the given field number. This method should be overridden in the - * generated message class if the message contains map fields. + * Gets the map field with the given field number. This method should be + * overridden in the generated message class if the message contains map + * fields. * - *

Unlike other field types, reflection support for map fields can't be implemented based on - * generated public API because we need to access a map field as a list in reflection API but - * the generated API only allows us to access it as a map. This method returns the underlying - * map field directly and thus enables us to access the map field as a list. + * Unlike other field types, reflection support for map fields can't be + * implemented based on generated public API because we need to access a + * map field as a list in reflection API but the generated API only allows + * us to access it as a map. This method returns the underlying map field + * directly and thus enables us to access the map field as a list. */ @SuppressWarnings({"unused", "rawtypes"}) protected MapField internalGetMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } /** Like {@link #internalGetMapField} but return a mutable version. */ @@ -912,30 +949,36 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected MapField internalGetMutableMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } } // ================================================================= // Extensions-related stuff - public interface ExtendableMessageOrBuilder - extends MessageOrBuilder { + public interface ExtendableMessageOrBuilder< + MessageType extends ExtendableMessage> extends MessageOrBuilder { // Re-define for return type covariance. @Override Message getDefaultInstanceForType(); /** Check if a singular extension is present. */ - boolean hasExtension(ExtensionLite extension); + boolean hasExtension( + ExtensionLite extension); /** Get the number of elements in a repeated extension. */ - int getExtensionCount(ExtensionLite> extension); + int getExtensionCount( + ExtensionLite> extension); /** Get the value of an extension. */ - Type getExtension(ExtensionLite extension); + Type getExtension( + ExtensionLite extension); /** Get one element of a repeated extension. */ - Type getExtension(ExtensionLite> extension, int index); + Type getExtension( + ExtensionLite> extension, + int index); /** Check if a singular extension is present. */ boolean hasExtension( @@ -966,13 +1009,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Generated message classes for message types that contain extension ranges subclass this. + * Generated message classes for message types that contain extension ranges + * subclass this. * - *

This class implements type-safe accessors for extensions. They implement all the same - * operations that you can do with normal fields -- e.g. "has", "get", and "getCount" -- but for - * extensions. The extensions are identified using instances of the class {@link - * GeneratedExtension}; the protocol compiler generates a static instance of this class for every - * extension in its input. Through the magic of generics, all is made type-safe. + *

This class implements type-safe accessors for extensions. They + * implement all the same operations that you can do with normal fields -- + * e.g. "has", "get", and "getCount" -- but for extensions. The extensions + * are identified using instances of the class {@link GeneratedExtension}; + * the protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made + * type-safe. * *

For example, imagine you have the {@code .proto} file: * @@ -997,8 +1043,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri * *

See also {@link ExtendableBuilder}. */ - public abstract static class ExtendableMessage - extends GeneratedMessageV3 implements ExtendableMessageOrBuilder { + public abstract static class ExtendableMessage< + MessageType extends ExtendableMessage> + extends GeneratedMessageV3 + implements ExtendableMessageOrBuilder { private static final long serialVersionUID = 1L; @@ -1008,20 +1056,22 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri this.extensions = FieldSet.newFieldSet(); } - protected ExtendableMessage(ExtendableBuilder builder) { + protected ExtendableMessage( + ExtendableBuilder builder) { super(builder); this.extensions = builder.buildExtensions(); } - private void verifyExtensionContainingType(final Extension extension) { - if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + private void verifyExtensionContainingType( + final Extension extension) { + if (extension.getDescriptor().getContainingType() != + getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( - "Extension is for type \"" - + extension.getDescriptor().getContainingType().getFullName() - + "\" which does not match message type \"" - + getDescriptorForType().getFullName() - + "\"."); + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + "\"."); } } @@ -1059,10 +1109,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri if (value == null) { if (descriptor.isRepeated()) { return (Type) Collections.emptyList(); - } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + } else if (descriptor.getJavaType() == + FieldDescriptor.JavaType.MESSAGE) { return (Type) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (Type) extension.fromReflectionType( + descriptor.getDefaultValue()); } } else { return (Type) extension.fromReflectionType(value); @@ -1078,8 +1130,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri verifyExtensionContainingType(extension); FieldDescriptor descriptor = extension.getDescriptor(); - return (Type) - extension.singularFromReflectionType(extensions.getRepeatedField(descriptor, index)); + return (Type) extension.singularFromReflectionType( + extensions.getRepeatedField(descriptor, index)); } /** Check if a singular extension is present. */ @@ -1144,15 +1196,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, - int tag) - throws IOException { + int tag) throws IOException { return MessageReflection.mergeFieldFrom( - input, - input.shouldDiscardUnknownFields() ? null : unknownFields, - extensionRegistry, - getDescriptorForType(), - new MessageReflection.ExtensionAdapter(extensions), - tag); + input, input.shouldDiscardUnknownFields() ? null : unknownFields, extensionRegistry, + getDescriptorForType(), new MessageReflection.ExtensionAdapter(extensions), tag); } /** @@ -1164,28 +1211,31 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri CodedInputStream input, UnknownFieldSet.Builder unknownFields, ExtensionRegistryLite extensionRegistry, - int tag) - throws IOException { + int tag) throws IOException { return parseUnknownField(input, unknownFields, extensionRegistry, tag); } - /** Used by parsing constructors in generated classes. */ + /** + * Used by parsing constructors in generated classes. + */ @Override protected void makeExtensionsImmutable() { extensions.makeImmutable(); } /** - * Used by subclasses to serialize extensions. Extension ranges may be interleaved with field - * numbers, but we must write them in canonical (sorted by field number) order. ExtensionWriter - * helps us write individual ranges of extensions at once. + * Used by subclasses to serialize extensions. Extension ranges may be + * interleaved with field numbers, but we must write them in canonical + * (sorted by field number) order. ExtensionWriter helps us write + * individual ranges of extensions at once. */ protected class ExtensionWriter { // Imagine how much simpler this code would be if Java iterators had // a way to get the next element without advancing the iterator. - private final Iterator> iter = extensions.iterator(); + private final Iterator> iter = + extensions.iterator(); private Map.Entry next; private final boolean messageSetWireFormat; @@ -1196,18 +1246,19 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri this.messageSetWireFormat = messageSetWireFormat; } - public void writeUntil(final int end, final CodedOutputStream output) throws IOException { + public void writeUntil(final int end, final CodedOutputStream output) + throws IOException { while (next != null && next.getKey().getNumber() < end) { FieldDescriptor descriptor = next.getKey(); - if (messageSetWireFormat - && descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE - && !descriptor.isRepeated()) { + if (messageSetWireFormat && descriptor.getLiteJavaType() == + WireFormat.JavaType.MESSAGE && + !descriptor.isRepeated()) { if (next instanceof LazyField.LazyEntry) { - output.writeRawMessageSetExtension( - descriptor.getNumber(), + output.writeRawMessageSetExtension(descriptor.getNumber(), ((LazyField.LazyEntry) next).getField().toByteString()); } else { - output.writeMessageSetExtension(descriptor.getNumber(), (Message) next.getValue()); + output.writeMessageSetExtension(descriptor.getNumber(), + (Message) next.getValue()); } } else { // TODO(xiangl): Taken care of following code, it may cause @@ -1231,7 +1282,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected ExtensionWriter newExtensionWriter() { return new ExtensionWriter(false); } - protected ExtensionWriter newMessageSetExtensionWriter() { return new ExtensionWriter(true); } @@ -1240,7 +1290,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected int extensionsSerializedSize() { return extensions.getSerializedSize(); } - protected int extensionsSerializedSizeAsMessageSet() { return extensions.getMessageSetSerializedSize(); } @@ -1312,7 +1361,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Object getRepeatedField(final FieldDescriptor field, final int index) { + public Object getRepeatedField(final FieldDescriptor field, + final int index) { if (field.isExtension()) { verifyContainingType(field); return extensions.getRepeatedField(field, index); @@ -1323,19 +1373,23 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri private void verifyContainingType(final FieldDescriptor field) { if (field.getContainingType() != getDescriptorForType()) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } } } /** - * Generated message builders for message types that contain extension ranges subclass this. + * Generated message builders for message types that contain extension ranges + * subclass this. * - *

This class implements type-safe accessors for extensions. They implement all the same - * operations that you can do with normal fields -- e.g. "get", "set", and "add" -- but for - * extensions. The extensions are identified using instances of the class {@link - * GeneratedExtension}; the protocol compiler generates a static instance of this class for every - * extension in its input. Through the magic of generics, all is made type-safe. + *

This class implements type-safe accessors for extensions. They + * implement all the same operations that you can do with normal fields -- + * e.g. "get", "set", and "add" -- but for extensions. The extensions are + * identified using instances of the class {@link GeneratedExtension}; the + * protocol compiler generates a static instance of this class for every + * extension in its input. Through the magic of generics, all is made + * type-safe. * *

For example, imagine you have the {@code .proto} file: * @@ -1364,15 +1418,17 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri */ @SuppressWarnings("unchecked") public abstract static class ExtendableBuilder< - MessageType extends ExtendableMessage, - BuilderType extends ExtendableBuilder> - extends Builder implements ExtendableMessageOrBuilder { + MessageType extends ExtendableMessage, + BuilderType extends ExtendableBuilder> + extends Builder + implements ExtendableMessageOrBuilder { private FieldSet.Builder extensions; protected ExtendableBuilder() {} - protected ExtendableBuilder(BuilderParent parent) { + protected ExtendableBuilder( + BuilderParent parent) { super(parent); } @@ -1393,15 +1449,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - private void verifyExtensionContainingType(final Extension extension) { - if (extension.getDescriptor().getContainingType() != getDescriptorForType()) { + private void verifyExtensionContainingType( + final Extension extension) { + if (extension.getDescriptor().getContainingType() != + getDescriptorForType()) { // This can only happen if someone uses unchecked operations. throw new IllegalArgumentException( - "Extension is for type \"" - + extension.getDescriptor().getContainingType().getFullName() - + "\" which does not match message type \"" - + getDescriptorForType().getFullName() - + "\"."); + "Extension is for type \"" + + extension.getDescriptor().getContainingType().getFullName() + + "\" which does not match message type \"" + + getDescriptorForType().getFullName() + "\"."); } } @@ -1436,10 +1493,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri if (value == null) { if (descriptor.isRepeated()) { return (Type) Collections.emptyList(); - } else if (descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { + } else if (descriptor.getJavaType() == + FieldDescriptor.JavaType.MESSAGE) { return (Type) extension.getMessageDefaultInstance(); } else { - return (Type) extension.fromReflectionType(descriptor.getDefaultValue()); + return (Type) extension.fromReflectionType( + descriptor.getDefaultValue()); } } else { return (Type) extension.fromReflectionType(value); @@ -1463,7 +1522,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Set the value of an extension. */ public final BuilderType setExtension( - final ExtensionLite extensionLite, final Type value) { + final ExtensionLite extensionLite, + final Type value) { Extension extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); @@ -1477,27 +1537,30 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Set the value of one element of a repeated extension. */ public final BuilderType setExtension( final ExtensionLite> extensionLite, - final int index, - final Type value) { + final int index, final Type value) { Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); - extensions.setRepeatedField(descriptor, index, extension.singularToReflectionType(value)); + extensions.setRepeatedField( + descriptor, index, + extension.singularToReflectionType(value)); onChanged(); return (BuilderType) this; } /** Append a value to a repeated extension. */ public final BuilderType addExtension( - final ExtensionLite> extensionLite, final Type value) { + final ExtensionLite> extensionLite, + final Type value) { Extension> extension = checkNotLite(extensionLite); verifyExtensionContainingType(extension); ensureExtensionsIsMutable(); final FieldDescriptor descriptor = extension.getDescriptor(); - extensions.addRepeatedField(descriptor, extension.singularToReflectionType(value)); + extensions.addRepeatedField( + descriptor, extension.singularToReflectionType(value)); onChanged(); return (BuilderType) this; } @@ -1608,7 +1671,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Called by the build code path to create a copy of the extensions for building the message. + * Called by the build code path to create a copy of the extensions for + * building the message. */ private FieldSet buildExtensions() { return extensions == null @@ -1698,7 +1762,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Object getRepeatedField(final FieldDescriptor field, final int index) { + public Object getRepeatedField(final FieldDescriptor field, + final int index) { if (field.isExtension()) { verifyContainingType(field); if (extensions == null) { @@ -1747,7 +1812,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType setField(final FieldDescriptor field, final Object value) { + public BuilderType setField(final FieldDescriptor field, + final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1773,8 +1839,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType setRepeatedField( - final FieldDescriptor field, final int index, final Object value) { + public BuilderType setRepeatedField(final FieldDescriptor field, + final int index, final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1787,7 +1853,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) { + public BuilderType addRepeatedField(final FieldDescriptor field, + final Object value) { if (field.isExtension()) { verifyContainingType(field); ensureExtensionsIsMutable(); @@ -1832,7 +1899,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri private void verifyContainingType(final FieldDescriptor field) { if (field.getContainingType() != getDescriptorForType()) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } } } @@ -1840,8 +1908,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // ----------------------------------------------------------------- /** - * Gets the descriptor for an extension. The implementation depends on whether the extension is - * scoped in the top level of a file or scoped in a Message. + * Gets the descriptor for an extension. The implementation depends on whether + * the extension is scoped in the top level of a file or scoped in a Message. */ static interface ExtensionDescriptorRetriever { FieldDescriptor getDescriptor(); @@ -1858,8 +1926,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri return clazz.getMethod(name, params); } catch (NoSuchMethodException e) { throw new RuntimeException( - "Generated message class \"" + clazz.getName() + "\" missing method \"" + name + "\".", - e); + "Generated message class \"" + clazz.getName() + + "\" missing method \"" + name + "\".", e); } } @@ -1871,7 +1939,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri return method.invoke(object, params); } catch (IllegalAccessException e) { throw new RuntimeException( - "Couldn't use Java reflection to implement protocol message " + "reflection.", e); + "Couldn't use Java reflection to implement protocol message " + + "reflection.", e); } catch (InvocationTargetException e) { final Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { @@ -1880,7 +1949,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri throw (Error) cause; } else { throw new RuntimeException( - "Unexpected exception thrown by generated accessor method.", cause); + "Unexpected exception thrown by generated accessor method.", cause); } } } @@ -1898,24 +1967,25 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected MapField internalGetMapField(int fieldNumber) { // Note that we can't use descriptor names here because this method will // be called when descriptor is being initialized. - throw new RuntimeException("No map fields found in " + getClass().getName()); + throw new RuntimeException( + "No map fields found in " + getClass().getName()); } /** - * Users should ignore this class. This class provides the implementation with access to the - * fields of a message object using Java reflection. + * Users should ignore this class. This class provides the implementation + * with access to the fields of a message object using Java reflection. */ public static final class FieldAccessorTable { /** - * Construct a FieldAccessorTable for a particular message class. Only one FieldAccessorTable - * should ever be constructed per class. + * Construct a FieldAccessorTable for a particular message class. Only + * one FieldAccessorTable should ever be constructed per class. * - * @param descriptor The type's descriptor. - * @param camelCaseNames The camelcase names of all fields in the message. These are used to - * derive the accessor method names. - * @param messageClass The message type. - * @param builderClass The builder type. + * @param descriptor The type's descriptor. + * @param camelCaseNames The camelcase names of all fields in the message. + * These are used to derive the accessor method names. + * @param messageClass The message type. + * @param builderClass The builder type. */ public FieldAccessorTable( final Descriptor descriptor, @@ -1927,10 +1997,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } /** - * Construct a FieldAccessorTable for a particular message class without initializing - * FieldAccessors. + * Construct a FieldAccessorTable for a particular message class without + * initializing FieldAccessors. */ - public FieldAccessorTable(final Descriptor descriptor, final String[] camelCaseNames) { + public FieldAccessorTable( + final Descriptor descriptor, + final String[] camelCaseNames) { this.descriptor = descriptor; this.camelCaseNames = camelCaseNames; fields = new FieldAccessor[descriptor.getFields().size()]; @@ -1941,19 +2013,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** * Ensures the field accessors are initialized. This method is thread-safe. * - * @param messageClass The message type. - * @param builderClass The builder type. + * @param messageClass The message type. + * @param builderClass The builder type. * @return this */ public FieldAccessorTable ensureFieldAccessorsInitialized( - Class messageClass, Class builderClass) { - if (initialized) { - return this; - } + Class messageClass, + Class builderClass) { + if (initialized) { return this; } synchronized (this) { - if (initialized) { - return this; - } + if (initialized) { return this; } int fieldsSize = fields.length; for (int i = 0; i < fieldsSize; i++) { FieldDescriptor field = descriptor.getFields().get(i); @@ -1965,54 +2034,36 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri if (field.isRepeated()) { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { if (field.isMapField()) { - fields[i] = - new MapFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new MapFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } else { - fields[i] = - new RepeatedMessageFieldAccessor( - field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { - fields[i] = - new RepeatedEnumFieldAccessor( - field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } else { - fields[i] = - new RepeatedFieldAccessor(field, camelCaseNames[i], messageClass, builderClass); + fields[i] = new RepeatedFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass); } } else { if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - fields[i] = - new SingularMessageFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularMessageFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) { - fields[i] = - new SingularEnumFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularEnumFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) { - fields[i] = - new SingularStringFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularStringFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } else { - fields[i] = - new SingularFieldAccessor( - field, - camelCaseNames[i], - messageClass, - builderClass, - containingOneofCamelCaseName); + fields[i] = new SingularFieldAccessor( + field, camelCaseNames[i], messageClass, builderClass, + containingOneofCamelCaseName); } } } @@ -2038,11 +2089,13 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Get the FieldAccessor for a particular field. */ private FieldAccessor getField(final FieldDescriptor field) { if (field.getContainingType() != descriptor) { - throw new IllegalArgumentException("FieldDescriptor does not match message type."); + throw new IllegalArgumentException( + "FieldDescriptor does not match message type."); } else if (field.isExtension()) { // If this type had extensions, it would subclass ExtendableMessage, // which overrides the reflection interface to handle extensions. - throw new IllegalArgumentException("This type does not have extensions."); + throw new IllegalArgumentException( + "This type does not have extensions."); } return fields[field.getIndex()]; } @@ -2050,53 +2103,38 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** Get the OneofAccessor for a particular oneof. */ private OneofAccessor getOneof(final OneofDescriptor oneof) { if (oneof.getContainingType() != descriptor) { - throw new IllegalArgumentException("OneofDescriptor does not match message type."); + throw new IllegalArgumentException( + "OneofDescriptor does not match message type."); } return oneofs[oneof.getIndex()]; } /** - * Abstract interface that provides access to a single field. This is implemented differently - * depending on the field type and cardinality. + * Abstract interface that provides access to a single field. This is + * implemented differently depending on the field type and cardinality. */ private interface FieldAccessor { Object get(GeneratedMessageV3 message); - Object get(GeneratedMessageV3.Builder builder); - Object getRaw(GeneratedMessageV3 message); - Object getRaw(GeneratedMessageV3.Builder builder); - void set(Builder builder, Object value); - Object getRepeated(GeneratedMessageV3 message, int index); - Object getRepeated(GeneratedMessageV3.Builder builder, int index); - Object getRepeatedRaw(GeneratedMessageV3 message, int index); - Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index); - - void setRepeated(Builder builder, int index, Object value); - + void setRepeated(Builder builder, + int index, Object value); void addRepeated(Builder builder, Object value); - boolean has(GeneratedMessageV3 message); - boolean has(GeneratedMessageV3.Builder builder); - int getRepeatedCount(GeneratedMessageV3 message); - int getRepeatedCount(GeneratedMessageV3.Builder builder); - void clear(Builder builder); - Message.Builder newBuilder(); - Message.Builder getBuilder(GeneratedMessageV3.Builder builder); - - Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index); + Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, + int index); } /** OneofAccessor provides access to a single oneof. */ @@ -2324,59 +2362,48 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri public Object get(final GeneratedMessageV3 message) { return invoker.get(message); } - @Override public Object get(GeneratedMessageV3.Builder builder) { return invoker.get(builder); } - @Override public Object getRaw(final GeneratedMessageV3 message) { return get(message); } - @Override public Object getRaw(GeneratedMessageV3.Builder builder) { return get(builder); } - @Override public void set(final Builder builder, final Object value) { invoker.set(builder, value); } - @Override public Object getRepeated(final GeneratedMessageV3 message, final int index) { throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); } - @Override public Object getRepeatedRaw(final GeneratedMessageV3 message, final int index) { throw new UnsupportedOperationException( "getRepeatedFieldRaw() called on a singular field."); } - @Override public Object getRepeated(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException("getRepeatedField() called on a singular field."); } - @Override public Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException( "getRepeatedFieldRaw() called on a singular field."); } - @Override public void setRepeated(final Builder builder, final int index, final Object value) { throw new UnsupportedOperationException("setRepeatedField() called on a singular field."); } - @Override public void addRepeated(final Builder builder, final Object value) { throw new UnsupportedOperationException("addRepeatedField() called on a singular field."); } - @Override public boolean has(final GeneratedMessageV3 message) { if (!hasHasMethod) { @@ -2387,7 +2414,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } return invoker.has(message); } - @Override public boolean has(GeneratedMessageV3.Builder builder) { if (!hasHasMethod) { @@ -2398,35 +2424,29 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } return invoker.has(builder); } - @Override public int getRepeatedCount(final GeneratedMessageV3 message) { throw new UnsupportedOperationException( "getRepeatedFieldSize() called on a singular field."); } - @Override public int getRepeatedCount(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException( "getRepeatedFieldSize() called on a singular field."); } - @Override public void clear(final Builder builder) { invoker.clear(builder); } - @Override public Message.Builder newBuilder() { throw new UnsupportedOperationException( "newBuilderForField() called on a non-Message type."); } - @Override public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); } - @Override public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException( @@ -2497,7 +2517,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public Object getRepeated(final GeneratedMessageV3 message, final int index) { + public Object getRepeated( + final GeneratedMessageV3 message, final int index) { return invokeOrDie(getRepeatedMethod, message, index); } @@ -2514,7 +2535,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } @Override - public void addRepeated(final GeneratedMessageV3.Builder builder, final Object value) { + public void addRepeated( + final GeneratedMessageV3.Builder builder, final Object value) { // TODO(b/230609037): remove the unused variable Object unused = invokeOrDie(addRepeatedMethod, builder, value); } @@ -2540,8 +2562,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri protected final MethodInvoker invoker; RepeatedFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { ReflectionInvoker reflectionInvoker = @@ -2558,22 +2579,18 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri public Object get(final GeneratedMessageV3 message) { return invoker.get(message); } - @Override public Object get(GeneratedMessageV3.Builder builder) { return invoker.get(builder); } - @Override public Object getRaw(final GeneratedMessageV3 message) { return get(message); } - @Override public Object getRaw(GeneratedMessageV3.Builder builder) { return get(builder); } - @Override public void set(final Builder builder, final Object value) { // Add all the elements individually. This serves two purposes: @@ -2585,73 +2602,59 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri addRepeated(builder, element); } } - @Override public Object getRepeated(final GeneratedMessageV3 message, final int index) { return invoker.getRepeated(message, index); } - @Override public Object getRepeated(GeneratedMessageV3.Builder builder, int index) { return invoker.getRepeated(builder, index); } - @Override public Object getRepeatedRaw(GeneratedMessageV3 message, int index) { return getRepeated(message, index); } - @Override public Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index) { return getRepeated(builder, index); } - @Override public void setRepeated(final Builder builder, final int index, final Object value) { invoker.setRepeated(builder, index, value); } - @Override public void addRepeated(final Builder builder, final Object value) { invoker.addRepeated(builder, value); } - @Override public boolean has(final GeneratedMessageV3 message) { throw new UnsupportedOperationException("hasField() called on a repeated field."); } - @Override public boolean has(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException("hasField() called on a repeated field."); } - @Override public int getRepeatedCount(final GeneratedMessageV3 message) { return invoker.getRepeatedCount(message); } - @Override public int getRepeatedCount(GeneratedMessageV3.Builder builder) { return invoker.getRepeatedCount(builder); } - @Override public void clear(final Builder builder) { invoker.clear(builder); } - @Override public Message.Builder newBuilder() { throw new UnsupportedOperationException( "newBuilderForField() called on a non-Message type."); } - @Override public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { throw new UnsupportedOperationException("getFieldBuilder() called on a non-Message type."); } - @Override public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) { throw new UnsupportedOperationException( @@ -2661,15 +2664,16 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri private static class MapFieldAccessor implements FieldAccessor { MapFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { field = descriptor; - Method getDefaultInstanceMethod = getMethodOrDie(messageClass, "getDefaultInstance"); - MapField defaultMapField = - getMapField((GeneratedMessageV3) invokeOrDie(getDefaultInstanceMethod, null)); - mapEntryMessageDefaultInstance = defaultMapField.getMapEntryMessageDefaultInstance(); + Method getDefaultInstanceMethod = + getMethodOrDie(messageClass, "getDefaultInstance"); + MapField defaultMapField = getMapField( + (GeneratedMessageV3) invokeOrDie(getDefaultInstanceMethod, null)); + mapEntryMessageDefaultInstance = + defaultMapField.getMapEntryMessageDefaultInstance(); } private final FieldDescriptor field; @@ -2683,8 +2687,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri return (MapField) builder.internalGetMapField(field.getNumber()); } - private MapField getMutableMapField(GeneratedMessageV3.Builder builder) { - return (MapField) builder.internalGetMutableMapField(field.getNumber()); + private MapField getMutableMapField( + GeneratedMessageV3.Builder builder) { + return (MapField) builder.internalGetMutableMapField( + field.getNumber()); } private Message coerceType(Message value) { @@ -2771,12 +2777,14 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public boolean has(GeneratedMessageV3 message) { - throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + throw new UnsupportedOperationException( + "hasField() is not supported for repeated fields."); } @Override public boolean has(Builder builder) { - throw new UnsupportedOperationException("hasField() is not supported for repeated fields."); + throw new UnsupportedOperationException( + "hasField() is not supported for repeated fields."); } @Override @@ -2801,7 +2809,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri @Override public com.google.protobuf.Message.Builder getBuilder(Builder builder) { - throw new UnsupportedOperationException("Nested builder not supported for map fields."); + throw new UnsupportedOperationException( + "Nested builder not supported for map fields."); } @Override @@ -2812,10 +2821,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // --------------------------------------------------------------- - private static final class SingularEnumFieldAccessor extends SingularFieldAccessor { + private static final class SingularEnumFieldAccessor + extends SingularFieldAccessor { SingularEnumFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { @@ -2828,9 +2837,12 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue(); if (supportUnknownEnumValue) { - getValueMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); - getValueMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); - setValueMethod = getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); + getValueMethod = + getMethodOrDie(messageClass, "get" + camelCaseName + "Value"); + getValueMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Value"); + setValueMethod = + getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class); } } @@ -2874,10 +2886,10 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - private static final class RepeatedEnumFieldAccessor extends RepeatedFieldAccessor { + private static final class RepeatedEnumFieldAccessor + extends RepeatedFieldAccessor { RepeatedEnumFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); @@ -2899,7 +2911,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class); } } - private EnumDescriptor enumDescriptor; private final Method valueOfMethod; @@ -2965,7 +2976,6 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null, value)); } - @Override public void addRepeated(final Builder builder, final Object value) { if (supportUnknownEnumValue) { @@ -2984,25 +2994,29 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri /** * Field accessor for string fields. * - *

This class makes getFooBytes() and setFooBytes() available for reflection API so that - * reflection based serialize/parse functions can access the raw bytes of the field to preserve - * non-UTF8 bytes in the string. + *

This class makes getFooBytes() and setFooBytes() available for + * reflection API so that reflection based serialize/parse functions can + * access the raw bytes of the field to preserve non-UTF8 bytes in the + * string. * - *

This ensures the serialize/parse round-trip safety, which is important for servers which - * forward messages. + *

This ensures the serialize/parse round-trip safety, which is important + * for servers which forward messages. */ - private static final class SingularStringFieldAccessor extends SingularFieldAccessor { + private static final class SingularStringFieldAccessor + extends SingularFieldAccessor { SingularStringFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { - super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); - getBytesMethod = getMethodOrDie(messageClass, "get" + camelCaseName + "Bytes"); - getBytesMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Bytes"); - setBytesMethodBuilder = - getMethodOrDie(builderClass, "set" + camelCaseName + "Bytes", ByteString.class); + super(descriptor, camelCaseName, messageClass, builderClass, + containingOneofCamelCaseName); + getBytesMethod = getMethodOrDie(messageClass, + "get" + camelCaseName + "Bytes"); + getBytesMethodBuilder = getMethodOrDie(builderClass, + "get" + camelCaseName + "Bytes"); + setBytesMethodBuilder = getMethodOrDie(builderClass, + "set" + camelCaseName + "Bytes", ByteString.class); } private final Method getBytesMethod; @@ -3032,17 +3046,19 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri // --------------------------------------------------------------- - private static final class SingularMessageFieldAccessor extends SingularFieldAccessor { + private static final class SingularMessageFieldAccessor + extends SingularFieldAccessor { SingularMessageFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass, final String containingOneofCamelCaseName) { - super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName); + super(descriptor, camelCaseName, messageClass, builderClass, + containingOneofCamelCaseName); newBuilderMethod = getMethodOrDie(type, "newBuilder"); - getBuilderMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); + getBuilderMethodBuilder = + getMethodOrDie(builderClass, "get" + camelCaseName + "Builder"); } private final Method newBuilderMethod; @@ -3066,29 +3082,27 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri public void set(final Builder builder, final Object value) { super.set(builder, coerceType(value)); } - @Override public Message.Builder newBuilder() { return (Message.Builder) invokeOrDie(newBuilderMethod, null); } - @Override public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) { return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder); } } - private static final class RepeatedMessageFieldAccessor extends RepeatedFieldAccessor { + private static final class RepeatedMessageFieldAccessor + extends RepeatedFieldAccessor { RepeatedMessageFieldAccessor( - final FieldDescriptor descriptor, - final String camelCaseName, + final FieldDescriptor descriptor, final String camelCaseName, final Class messageClass, final Class builderClass) { super(descriptor, camelCaseName, messageClass, builderClass); newBuilderMethod = getMethodOrDie(type, "newBuilder"); - getBuilderMethodBuilder = - getMethodOrDie(builderClass, "get" + camelCaseName + "Builder", Integer.TYPE); + getBuilderMethodBuilder = getMethodOrDie(builderClass, + "get" + camelCaseName + "Builder", Integer.TYPE); } private final Method newBuilderMethod; @@ -3112,30 +3126,27 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri public void setRepeated(final Builder builder, final int index, final Object value) { super.setRepeated(builder, index, coerceType(value)); } - @Override public void addRepeated(final Builder builder, final Object value) { super.addRepeated(builder, coerceType(value)); } - @Override public Message.Builder newBuilder() { return (Message.Builder) invokeOrDie(newBuilderMethod, null); } - @Override public Message.Builder getRepeatedBuilder( final GeneratedMessageV3.Builder builder, final int index) { - return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder, index); + return (Message.Builder) invokeOrDie( + getBuilderMethodBuilder, builder, index); } } } /** - * Replaces this object in the output stream with a serialized form. Part of Java's serialization - * magic. Generated sub-classes must override this method by calling {@code return - * super.writeReplace();} - * + * Replaces this object in the output stream with a serialized form. + * Part of Java's serialization magic. Generated sub-classes must override + * this method by calling {@code return super.writeReplace();} * @return a SerializedForm of this message */ protected Object writeReplace() throws ObjectStreamException { @@ -3187,8 +3198,8 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } } - protected static void writeStringNoTag(CodedOutputStream output, final Object value) - throws IOException { + protected static void writeStringNoTag( + CodedOutputStream output, final Object value) throws IOException { if (value instanceof String) { output.writeStringNoTag((String) value); } else { @@ -3200,8 +3211,7 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri CodedOutputStream out, MapField field, MapEntry defaultEntry, - int fieldNumber) - throws IOException { + int fieldNumber) throws IOException { Map m = field.getMap(); if (!out.isSerializationDeterministic()) { serializeMapTo(out, m, defaultEntry, fieldNumber); @@ -3216,8 +3226,11 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } Arrays.sort(keys); for (int key : keys) { - out.writeMessage( - fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); } } @@ -3240,8 +3253,11 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri } Arrays.sort(keys); for (long key : keys) { - out.writeMessage( - fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); } } @@ -3263,8 +3279,11 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri keys = m.keySet().toArray(keys); Arrays.sort(keys); for (String key : keys) { - out.writeMessage( - fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); } } @@ -3291,23 +3310,28 @@ public abstract class GeneratedMessageV3 extends AbstractMessage implements Seri boolean key) throws IOException { if (m.containsKey(key)) { - out.writeMessage( - fieldNumber, defaultEntry.newBuilderForType().setKey(key).setValue(m.get(key)).build()); + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() + .setKey(key) + .setValue(m.get(key)) + .build()); } } /** Serialize the map using the iteration order. */ private static void serializeMapTo( - CodedOutputStream out, Map m, MapEntry defaultEntry, int fieldNumber) + CodedOutputStream out, + Map m, + MapEntry defaultEntry, + int fieldNumber) throws IOException { for (Map.Entry entry : m.entrySet()) { - out.writeMessage( - fieldNumber, - defaultEntry - .newBuilderForType() + out.writeMessage(fieldNumber, + defaultEntry.newBuilderForType() .setKey(entry.getKey()) .setValue(entry.getValue()) .build()); } } } + diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java index 0fb934f..b6bbcb1 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java @@ -600,7 +600,6 @@ public final class Internal { void addInt(int element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ - @CanIgnoreReturnValue int setInt(int index, int element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -621,7 +620,6 @@ public final class Internal { void addBoolean(boolean element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ - @CanIgnoreReturnValue boolean setBoolean(int index, boolean element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -642,7 +640,6 @@ public final class Internal { void addLong(long element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ - @CanIgnoreReturnValue long setLong(int index, long element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -663,7 +660,6 @@ public final class Internal { void addDouble(double element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ - @CanIgnoreReturnValue double setDouble(int index, double element); /** Returns a mutable clone of this list with the specified capacity. */ @@ -684,7 +680,6 @@ public final class Internal { void addFloat(float element); /** Like {@link #set(int, Object)} but more efficient in that it doesn't box the element. */ - @CanIgnoreReturnValue float setFloat(int index, float element); /** Returns a mutable clone of this list with the specified capacity. */ diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Message.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Message.java index f641739..3db1c77 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/Message.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/Message.java @@ -39,12 +39,11 @@ import java.util.Map; * *

See also {@link MessageLite}, which defines most of the methods that typical users care about. * {@link Message} adds methods that are not available in the "lite" runtime. The biggest added - * features are introspection and reflection; that is, getting descriptors for the message type and - * accessing the field values dynamically. + * features are introspection and reflection; that is, getting descriptors for the message type + * and accessing the field values dynamically. * * @author kenton@google.com Kenton Varda */ -@CheckReturnValue public interface Message extends MessageLite, MessageOrBuilder { // (From MessageLite, re-declared here only for return type covariance.) @@ -103,7 +102,6 @@ public interface Message extends MessageLite, MessageOrBuilder { // (From MessageLite.Builder, re-declared here only for return type // covariance.) @Override - @CanIgnoreReturnValue Builder clear(); /** @@ -123,7 +121,6 @@ public interface Message extends MessageLite, MessageOrBuilder { * *

This is equivalent to the {@code Message::MergeFrom} method in C++. */ - @CanIgnoreReturnValue Builder mergeFrom(Message other); // (From MessageLite.Builder, re-declared here only for return type @@ -138,11 +135,9 @@ public interface Message extends MessageLite, MessageOrBuilder { Builder clone(); @Override - @CanIgnoreReturnValue Builder mergeFrom(CodedInputStream input) throws IOException; @Override - @CanIgnoreReturnValue Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException; @@ -195,21 +190,18 @@ public interface Message extends MessageLite, MessageOrBuilder { * Sets a field to the given value. The value must be of the correct type for this field, that * is, the same type that {@link Message#getField(Descriptors.FieldDescriptor)} returns. */ - @CanIgnoreReturnValue Builder setField(Descriptors.FieldDescriptor field, Object value); /** * Clears the field. This is exactly equivalent to calling the generated "clear" accessor method * corresponding to the field. */ - @CanIgnoreReturnValue Builder clearField(Descriptors.FieldDescriptor field); /** * Clears the oneof. This is exactly equivalent to calling the generated "clear" accessor method * corresponding to the oneof. */ - @CanIgnoreReturnValue Builder clearOneof(Descriptors.OneofDescriptor oneof); /** @@ -220,7 +212,6 @@ public interface Message extends MessageLite, MessageOrBuilder { * @throws IllegalArgumentException if the field is not a repeated field, or {@code * field.getContainingType() != getDescriptorForType()}. */ - @CanIgnoreReturnValue Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value); /** @@ -229,15 +220,12 @@ public interface Message extends MessageLite, MessageOrBuilder { * @throws IllegalArgumentException if the field is not a repeated field, or {@code * field.getContainingType() != getDescriptorForType()} */ - @CanIgnoreReturnValue Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value); /** Set the {@link UnknownFieldSet} for this message. */ - @CanIgnoreReturnValue Builder setUnknownFields(UnknownFieldSet unknownFields); /** Merge some unknown fields into the {@link UnknownFieldSet} for this message. */ - @CanIgnoreReturnValue Builder mergeUnknownFields(UnknownFieldSet unknownFields); // --------------------------------------------------------------- @@ -246,38 +234,30 @@ public interface Message extends MessageLite, MessageOrBuilder { // (From MessageLite.Builder, re-declared here only for return type // covariance.) @Override - @CanIgnoreReturnValue Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @Override - @CanIgnoreReturnValue Builder mergeFrom(InputStream input) throws IOException; @Override - @CanIgnoreReturnValue Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException; diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java index d631469..f9b2f66 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java @@ -59,7 +59,6 @@ import java.io.OutputStream; * * @author kenton@google.com Kenton Varda */ -@CheckReturnValue public interface MessageLite extends MessageLiteOrBuilder { /** @@ -139,7 +138,6 @@ public interface MessageLite extends MessageLiteOrBuilder { /** Abstract interface implemented by Protocol Message builders. */ interface Builder extends MessageLiteOrBuilder, Cloneable { /** Resets all fields to their default values. */ - @CanIgnoreReturnValue Builder clear(); /** @@ -183,12 +181,11 @@ public interface MessageLite extends MessageLiteOrBuilder { *

Note: The caller should call {@link CodedInputStream#checkLastTagWas(int)} after calling * this to verify that the last tag seen was the appropriate end-group tag, or zero for EOF. * - * @throws InvalidProtocolBufferException the bytes read are not syntactically correct according - * to the protobuf wire format specification. The data is corrupt, incomplete, or was never - * a protobuf in the first place. + * @throws InvalidProtocolBufferException the bytes read are not syntactically correct + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @throws IOException an I/O error reading from the stream */ - @CanIgnoreReturnValue Builder mergeFrom(CodedInputStream input) throws IOException; /** @@ -196,12 +193,11 @@ public interface MessageLite extends MessageLiteOrBuilder { * that you want to be able to parse must be registered in {@code extensionRegistry}. Extensions * not in the registry will be treated as unknown fields. * - * @throws InvalidProtocolBufferException the bytes read are not syntactically correct according - * to the protobuf wire format specification. The data is corrupt, incomplete, or was never - * a protobuf in the first place. + * @throws InvalidProtocolBufferException the bytes read are not syntactically correct + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @throws IOException an I/O error reading from the stream */ - @CanIgnoreReturnValue Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException; @@ -213,11 +209,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException; /** @@ -225,11 +220,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @@ -238,11 +232,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException; /** @@ -250,11 +243,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException; /** @@ -262,11 +254,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @@ -275,11 +266,10 @@ public interface MessageLite extends MessageLiteOrBuilder { * is just a small wrapper around {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}. * * @throws InvalidProtocolBufferException the bytes in data are not syntactically correct - * according to the protobuf wire format specification. The data is corrupt, incomplete, or - * was never a protobuf in the first place. + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException; @@ -293,13 +283,12 @@ public interface MessageLite extends MessageLiteOrBuilder { * *

Despite usually reading the entire input, this does not close the stream. * - * @throws InvalidProtocolBufferException the bytes read are not syntactically correct according - * to the protobuf wire format specification. The data is corrupt, incomplete, or was never - * a protobuf in the first place. + * @throws InvalidProtocolBufferException the bytes read are not syntactically correct + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @throws IOException an I/O error reading from the stream * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(InputStream input) throws IOException; /** @@ -309,7 +298,6 @@ public interface MessageLite extends MessageLiteOrBuilder { * * @return this */ - @CanIgnoreReturnValue Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws IOException; @@ -329,7 +317,6 @@ public interface MessageLite extends MessageLiteOrBuilder { * *

This is equivalent to the {@code Message::MergeFrom} method in C++. */ - @CanIgnoreReturnValue Builder mergeFrom(MessageLite other); /** @@ -339,9 +326,9 @@ public interface MessageLite extends MessageLiteOrBuilder { * * @return true if successful, or false if the stream is at EOF when the method starts. Any * other error (including reaching EOF during parsing) causes an exception to be thrown. - * @throws InvalidProtocolBufferException the bytes read are not syntactically correct according - * to the protobuf wire format specification. The data is corrupt, incomplete, or was never - * a protobuf in the first place. + * @throws InvalidProtocolBufferException the bytes read are not syntactically correct + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @throws IOException an I/O error reading from the stream */ boolean mergeDelimitedFrom(InputStream input) throws IOException; @@ -351,9 +338,9 @@ public interface MessageLite extends MessageLiteOrBuilder { * * @return true if successful, or false if the stream is at EOF when the method starts. Any * other error (including reaching EOF during parsing) causes an exception to be thrown. - * @throws InvalidProtocolBufferException the bytes read are not syntactically correct according - * to the protobuf wire format specification. The data is corrupt, incomplete, or was never - * a protobuf in the first place. + * @throws InvalidProtocolBufferException the bytes read are not syntactically correct + * according to the protobuf wire format specification. The data is corrupt, incomplete, + * or was never a protobuf in the first place. * @throws IOException an I/O error reading from the stream */ boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java index 927b95f..7a5ef3e 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java @@ -36,7 +36,6 @@ package com.google.protobuf; * * @author jonp@google.com (Jon Perlow) */ -@CheckReturnValue public interface MessageLiteOrBuilder { /** * Get an instance of the type with no fields set. Because no fields are set, all getters for diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java index 2a4d867..0254df9 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java @@ -39,7 +39,6 @@ import java.util.Map; * * @author jonp@google.com (Jon Perlow) */ -@CheckReturnValue public interface MessageOrBuilder extends MessageLiteOrBuilder { // (From MessageLite, re-declared here only for return type covariance.) diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java index 757bc66..d56af6b 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java @@ -277,7 +277,6 @@ public class RepeatedFieldBuilder< * @param message the message to set * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilder setMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -299,7 +298,6 @@ public class RepeatedFieldBuilder< * @param message the message to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilder addMessage(MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -321,7 +319,6 @@ public class RepeatedFieldBuilder< * @param message the message to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilder addMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -341,7 +338,6 @@ public class RepeatedFieldBuilder< * @param values the messages to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilder addAllMessages( Iterable values) { for (final MType value : values) { diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java index 25b2123..f6acc77 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java @@ -277,7 +277,6 @@ public class RepeatedFieldBuilderV3< * @param message the message to set * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilderV3 setMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -299,7 +298,6 @@ public class RepeatedFieldBuilderV3< * @param message the message to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addMessage(MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -321,7 +319,6 @@ public class RepeatedFieldBuilderV3< * @param message the message to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addMessage(int index, MType message) { checkNotNull(message); ensureMutableMessageList(); @@ -341,7 +338,6 @@ public class RepeatedFieldBuilderV3< * @param values the messages to add * @return the builder */ - @CanIgnoreReturnValue public RepeatedFieldBuilderV3 addAllMessages( Iterable values) { for (final MType value : values) { diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java index ca25756..acdc1de 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java @@ -156,7 +156,6 @@ public class SingleFieldBuilder< * @param message the message to set * @return the builder */ - @CanIgnoreReturnValue public SingleFieldBuilder setMessage(MType message) { this.message = checkNotNull(message); if (builder != null) { @@ -173,7 +172,6 @@ public class SingleFieldBuilder< * @param value the value to merge from * @return the builder */ - @CanIgnoreReturnValue public SingleFieldBuilder mergeFrom(MType value) { if (builder == null && message == message.getDefaultInstanceForType()) { message = value; @@ -190,7 +188,6 @@ public class SingleFieldBuilder< * @return the builder */ @SuppressWarnings("unchecked") - @CanIgnoreReturnValue public SingleFieldBuilder clear() { message = (MType) diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java index c235495..a6c639c 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java @@ -156,7 +156,6 @@ public class SingleFieldBuilderV3< * @param message the message to set * @return the builder */ - @CanIgnoreReturnValue public SingleFieldBuilderV3 setMessage(MType message) { this.message = checkNotNull(message); if (builder != null) { @@ -173,7 +172,6 @@ public class SingleFieldBuilderV3< * @param value the value to merge from * @return the builder */ - @CanIgnoreReturnValue public SingleFieldBuilderV3 mergeFrom(MType value) { if (builder == null && message == message.getDefaultInstanceForType()) { message = value; @@ -190,7 +188,6 @@ public class SingleFieldBuilderV3< * @return the builder */ @SuppressWarnings("unchecked") - @CanIgnoreReturnValue public SingleFieldBuilderV3 clear() { message = (MType) @@ -202,6 +199,9 @@ public class SingleFieldBuilderV3< builder = null; } onChanged(); + // After clearing, parent is dirty, but this field builder is now clean and any changes should + // trickle up. + isClean = true; return this; } diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java index 9b3c356..a8af845 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java @@ -61,6 +61,7 @@ public final class TextFormat { private static final String DEBUG_STRING_SILENT_MARKER = "\t "; + /** * Outputs a textual representation of the Protocol Message supplied into the parameter output. * (This representation is the new version of the classic "ProtocolPrinter" output from the @@ -115,8 +116,8 @@ public final class TextFormat { /** * Generates a human readable form of this message, useful for debugging and other purposes, with - * no newline characters. This is just a trivial wrapper around {@link - * TextFormat.Printer#shortDebugString(MessageOrBuilder)}. + * no newline characters. This is just a trivial wrapper around + * {@link TextFormat.Printer#shortDebugString(MessageOrBuilder)}. */ public static String shortDebugString(final MessageOrBuilder message) { return printer().shortDebugString(message); @@ -458,7 +459,9 @@ public final class TextFormat { } } - /** An adapter class that can take a {@link MapEntry} and returns its key and entry. */ + /** + * An adapter class that can take a {@link MapEntry} and returns its key and entry. + */ private static class MapEntryAdapter implements Comparable { private Object entry; @@ -738,9 +741,9 @@ public final class TextFormat { // Groups must be serialized with their original capitalization. generator.print(field.getMessageType().getName()); } else { - generator.print(field.getName()); + generator.print(field.getName()); + } } - } if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { generator.print(" {"); @@ -950,7 +953,6 @@ public final class TextFormat { * the next token is parsed. */ private boolean containsSilentMarkerAfterCurrentToken = false; - private boolean containsSilentMarkerAfterPrevToken = false; /** Construct a tokenizer that parses tokens from the given text. */ @@ -1376,6 +1378,7 @@ public final class TextFormat { private ParseException floatParseException(final NumberFormatException e) { return parseException("Couldn't parse number: " + e.getMessage()); } + } /** Thrown when parsing an invalid text format message. */ @@ -1548,7 +1551,7 @@ public final class TextFormat { * the current token is part of the field value, so the silent marker is indicated by * containsSilentMarkerAfterPrevToken. */ - private void detectSilentMarker(Tokenizer tokenizer, String fieldName) { + private void detectSilentMarker(Tokenizer tokenizer) { } /** @@ -1625,8 +1628,8 @@ public final class TextFormat { * unknown field is encountered. If this is set, the parser will only log a warning. Allow * unknown fields will also allow unknown extensions. * - *

Use of this parameter is discouraged which may hide some errors (e.g. spelling error on - * field name). + *

Use of this parameter is discouraged which may hide some errors (e.g. + * spelling error on field name). */ public Builder setAllowUnknownFields(boolean allowUnknownFields) { this.allowUnknownFields = allowUnknownFields; @@ -1634,9 +1637,10 @@ public final class TextFormat { } /** - * Set whether this parser will allow unknown extensions. By default, an exception is thrown - * if unknown extension is encountered. If this is set true, the parser will only log a - * warning. Allow unknown extensions does not mean allow normal unknown fields. + * Set whether this parser will allow unknown extensions. By default, an + * exception is thrown if unknown extension is encountered. If this is set true, + * the parser will only log a warning. Allow unknown extensions does not mean + * allow normal unknown fields. */ public Builder setAllowUnknownExtensions(boolean allowUnknownExtensions) { this.allowUnknownExtensions = allowUnknownExtensions; @@ -1721,8 +1725,7 @@ public final class TextFormat { static final class UnknownField { static enum Type { - FIELD, - EXTENSION; + FIELD, EXTENSION; } final String message; @@ -1783,6 +1786,7 @@ public final class TextFormat { throws ParseException { final Tokenizer tokenizer = new Tokenizer(input); MessageReflection.BuilderAdapter target = new MessageReflection.BuilderAdapter(builder); + List unknownFields = new ArrayList(); while (!tokenizer.atEnd()) { @@ -1799,7 +1803,12 @@ public final class TextFormat { final MessageReflection.MergeTarget target, List unknownFields) throws ParseException { - mergeField(tokenizer, extensionRegistry, target, parseInfoTreeBuilder, unknownFields); + mergeField( + tokenizer, + extensionRegistry, + target, + parseInfoTreeBuilder, + unknownFields); } /** Parse a single field from {@code tokenizer} and merge it into {@code target}. */ @@ -1811,40 +1820,38 @@ public final class TextFormat { List unknownFields) throws ParseException { FieldDescriptor field = null; - String name; int startLine = tokenizer.getLine(); int startColumn = tokenizer.getColumn(); final Descriptor type = target.getDescriptorForType(); ExtensionRegistry.ExtensionInfo extension = null; if ("google.protobuf.Any".equals(type.getFullName()) && tokenizer.tryConsume("[")) { - mergeAnyFieldValue( - tokenizer, extensionRegistry, target, parseTreeBuilder, unknownFields, type); + mergeAnyFieldValue(tokenizer, extensionRegistry, target, parseTreeBuilder, unknownFields, + type); return; } if (tokenizer.tryConsume("[")) { // An extension. - StringBuilder nameBuilder = new StringBuilder(tokenizer.consumeIdentifier()); + final StringBuilder name = new StringBuilder(tokenizer.consumeIdentifier()); while (tokenizer.tryConsume(".")) { - nameBuilder.append('.'); - nameBuilder.append(tokenizer.consumeIdentifier()); + name.append('.'); + name.append(tokenizer.consumeIdentifier()); } - name = nameBuilder.toString(); - extension = target.findExtensionByName(extensionRegistry, name); + extension = target.findExtensionByName(extensionRegistry, name.toString()); if (extension == null) { - String message = - (tokenizer.getPreviousLine() + 1) - + ":" - + (tokenizer.getPreviousColumn() + 1) - + ":\t" - + type.getFullName() - + ".[" - + name - + "]"; - unknownFields.add(new UnknownField(message, UnknownField.Type.EXTENSION)); + String message = + (tokenizer.getPreviousLine() + 1) + + ":" + + (tokenizer.getPreviousColumn() + 1) + + ":\t" + + type.getFullName() + + ".[" + + name + + "]"; + unknownFields.add(new UnknownField(message, UnknownField.Type.EXTENSION)); } else { if (extension.descriptor.getContainingType() != type) { throw tokenizer.parseExceptionPreviousToken( @@ -1859,7 +1866,7 @@ public final class TextFormat { tokenizer.consume("]"); } else { - name = tokenizer.consumeIdentifier(); + final String name = tokenizer.consumeIdentifier(); field = type.findFieldByName(name); // Group names are expected to be capitalized as they appear in the @@ -1883,14 +1890,13 @@ public final class TextFormat { } if (field == null) { - String message = - (tokenizer.getPreviousLine() + 1) - + ":" - + (tokenizer.getPreviousColumn() + 1) - + ":\t" - + type.getFullName() - + "." - + name; + String message = (tokenizer.getPreviousLine() + 1) + + ":" + + (tokenizer.getPreviousColumn() + 1) + + ":\t" + + type.getFullName() + + "." + + name; unknownFields.add(new UnknownField(message, UnknownField.Type.FIELD)); } } @@ -1903,7 +1909,7 @@ public final class TextFormat { // start with "{" or "<" which indicates the beginning of a message body. // If there is no ":" or there is a "{" or "<" after ":", this field has // to be a message or the input is ill-formed. - detectSilentMarker(tokenizer, name); + detectSilentMarker(tokenizer); if (tokenizer.tryConsume(":") && !tokenizer.lookingAt("{") && !tokenizer.lookingAt("<")) { skipFieldValue(tokenizer); } else { @@ -1914,7 +1920,7 @@ public final class TextFormat { // Handle potential ':'. if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) { - detectSilentMarker(tokenizer, field.getFullName()); + detectSilentMarker(tokenizer); tokenizer.tryConsume(":"); // optional if (parseTreeBuilder != null) { TextFormatParseInfoTree.Builder childParseTreeBuilder = @@ -1938,7 +1944,7 @@ public final class TextFormat { unknownFields); } } else { - detectSilentMarker(tokenizer, field.getFullName()); + detectSilentMarker(tokenizer); tokenizer.consume(":"); // required consumeFieldValues( tokenizer, @@ -1961,29 +1967,6 @@ public final class TextFormat { } } - private String consumeFullTypeName(Tokenizer tokenizer) throws ParseException { - // If there is not a leading `[`, this is just a type name. - if (!tokenizer.tryConsume("[")) { - return tokenizer.consumeIdentifier(); - } - - // Otherwise, this is an extension or google.protobuf.Any type URL: we consume proto path - // elements until we've addressed the type. - String name = tokenizer.consumeIdentifier(); - while (tokenizer.tryConsume(".")) { - name += "." + tokenizer.consumeIdentifier(); - } - if (tokenizer.tryConsume("/")) { - name += "/" + tokenizer.consumeIdentifier(); - while (tokenizer.tryConsume(".")) { - name += "." + tokenizer.consumeIdentifier(); - } - } - tokenizer.consume("]"); - - return name; - } - /** * Parse a one or more field values from {@code tokenizer} and merge it into {@code builder}. */ @@ -2075,13 +2058,8 @@ public final class TextFormat { // (java_proto_library for any_java_proto depends on the protobuf_impl). Message anyBuilder = DynamicMessage.getDefaultInstance(field.getMessageType()); MessageReflection.MergeTarget anyField = target.newMergeTargetForField(field, anyBuilder); - mergeAnyFieldValue( - tokenizer, - extensionRegistry, - anyField, - parseTreeBuilder, - unknownFields, - field.getMessageType()); + mergeAnyFieldValue(tokenizer, extensionRegistry, anyField, parseTreeBuilder, + unknownFields, field.getMessageType()); value = anyField.finish(); tokenizer.consume(endToken); } else { @@ -2228,7 +2206,7 @@ public final class TextFormat { throw tokenizer.parseExceptionPreviousToken("Expected a valid type URL."); } } - detectSilentMarker(tokenizer, typeUrlBuilder.toString()); + detectSilentMarker(tokenizer); tokenizer.tryConsume(":"); final String anyEndToken; if (tokenizer.tryConsume("<")) { @@ -2266,7 +2244,15 @@ public final class TextFormat { /** Skips the next field including the field's name and value. */ private void skipField(Tokenizer tokenizer) throws ParseException { - String name = consumeFullTypeName(tokenizer); + if (tokenizer.tryConsume("[")) { + // Extension name. + do { + tokenizer.consumeIdentifier(); + } while (tokenizer.tryConsume(".")); + tokenizer.consume("]"); + } else { + tokenizer.consumeIdentifier(); + } // Try to guess the type of this field. // If this field is not a message, there should be a ":" between the @@ -2274,7 +2260,7 @@ public final class TextFormat { // start with "{" or "<" which indicates the beginning of a message body. // If there is no ":" or there is a "{" or "<" after ":", this field has // to be a message or the input is ill-formed. - detectSilentMarker(tokenizer, name); + detectSilentMarker(tokenizer); if (tokenizer.tryConsume(":") && !tokenizer.lookingAt("<") && !tokenizer.lookingAt("{")) { skipFieldValue(tokenizer); } else { @@ -2483,10 +2469,9 @@ public final class TextFormat { } Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(codepoint); if (unicodeBlock != null - && (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES) - || unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES) - || unicodeBlock.equals( - Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) { + && (unicodeBlock.equals(Character.UnicodeBlock.LOW_SURROGATES) + || unicodeBlock.equals(Character.UnicodeBlock.HIGH_SURROGATES) + || unicodeBlock.equals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES))) { throw new InvalidEscapeSequenceException( "Invalid escape sequence: '\\U" + input.substring(i, i + 8).toStringUtf8() diff --git a/libs/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java b/libs/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java index be6f97d..16521e1 100644 --- a/libs/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java +++ b/libs/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java @@ -43,7 +43,7 @@ import java.nio.ByteBuffer; * ByteString} can lead to unexpected and undesirable consequences in your application, and will * likely be difficult to debug. Proceed with caution! * - *

This can have a number of significant side effects that have spooky-action-at-a-distance-like + *

This can have a number of significant side affects that have spooky-action-at-a-distance-like * behavior. In particular, if the bytes value changes out from under a Protocol Buffer: * *

    diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java index 7988e7c..a88baca 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java @@ -61,7 +61,6 @@ import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; import protobuf_unittest.UnittestProto.TestJsonName; import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; import protobuf_unittest.UnittestProto.TestRequired; -import protobuf_unittest.UnittestProto.TestReservedEnumFields; import protobuf_unittest.UnittestProto.TestReservedFields; import protobuf_unittest.UnittestProto.TestService; import java.util.Collections; @@ -464,15 +463,15 @@ public class DescriptorsTest { /** Tests that parsing an unknown enum throws an exception */ @Test public void testParseUnknownEnum() { - FieldDescriptorProto.Builder field = - FieldDescriptorProto.newBuilder() - .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) - .setTypeName("UnknownEnum") - .setType(FieldDescriptorProto.Type.TYPE_ENUM) - .setName("bar") - .setNumber(1); - DescriptorProto.Builder messageType = - DescriptorProto.newBuilder().setName("Foo").addField(field); + FieldDescriptorProto.Builder field = FieldDescriptorProto.newBuilder() + .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL) + .setTypeName("UnknownEnum") + .setType(FieldDescriptorProto.Type.TYPE_ENUM) + .setName("bar") + .setNumber(1); + DescriptorProto.Builder messageType = DescriptorProto.newBuilder() + .setName("Foo") + .addField(field); FileDescriptorProto fooProto = FileDescriptorProto.newBuilder() .setName("foo.proto") @@ -487,6 +486,7 @@ public class DescriptorsTest { } } + /** * Tests the translate/crosslink for an example where a message field's name and type name are the * same. @@ -560,10 +560,8 @@ public class DescriptorsTest { Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[] {fooFile}); // Items in the FileDescriptor array can be in any order. - FileDescriptor unused1 = - Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {fooFile, barFile}); - FileDescriptor unused2 = - Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {barFile, fooFile}); + Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {fooFile, barFile}); + Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {barFile, fooFile}); } @Test @@ -625,8 +623,7 @@ public class DescriptorsTest { .setName("bar") .setNumber(1))) .build(); - FileDescriptor unused = - Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true); + Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true); } @Test @@ -660,8 +657,7 @@ public class DescriptorsTest { Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile}); try { - FileDescriptor unused = - Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile}); + Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile}); assertWithMessage("DescriptorValidationException expected").fail(); } catch (DescriptorValidationException e) { assertThat(e).hasMessageThat().contains("Bar"); @@ -699,8 +695,7 @@ public class DescriptorsTest { FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[0]); FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile}); - FileDescriptor unused = - Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile}); + Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile}); } /** Tests the translate/crosslink for an example with a more complex namespace referencing. */ @@ -797,20 +792,6 @@ public class DescriptorsTest { assertThat(d.isReservedName("baz")).isTrue(); } - @Test - public void testReservedEnumFields() { - EnumDescriptor d = TestReservedEnumFields.getDescriptor(); - assertThat(d.isReservedNumber(2)).isTrue(); - assertThat(d.isReservedNumber(8)).isFalse(); - assertThat(d.isReservedNumber(9)).isTrue(); - assertThat(d.isReservedNumber(10)).isTrue(); - assertThat(d.isReservedNumber(11)).isTrue(); - assertThat(d.isReservedNumber(12)).isFalse(); - assertThat(d.isReservedName("foo")).isFalse(); - assertThat(d.isReservedName("bar")).isTrue(); - assertThat(d.isReservedName("baz")).isTrue(); - } - @Test public void testToString() { assertThat( @@ -845,8 +826,7 @@ public class DescriptorsTest { .build()) .build()) .build(); - FileDescriptor unused = - Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]); + Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]); } @Test diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java index abe7caf..8e1abc0 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java @@ -44,7 +44,6 @@ import protobuf_unittest.UnittestProto.TestAllTypes; import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; import protobuf_unittest.UnittestProto.TestEmptyMessage; import protobuf_unittest.UnittestProto.TestPackedTypes; -import java.util.ArrayList; import org.junit.Test; import org.junit.function.ThrowingRunnable; import org.junit.runner.RunWith; @@ -231,19 +230,6 @@ public class DynamicMessageTest { assertThat(rawBytes).isEqualTo(TestUtil.getPackedSet().toByteString()); } - @Test - public void testDynamicMessagePackedEmptySerialization() throws Exception { - Message message = - DynamicMessage.newBuilder(TestPackedTypes.getDescriptor()) - .setField( - TestPackedTypes.getDescriptor() - .findFieldByNumber(TestPackedTypes.PACKED_INT64_FIELD_NUMBER), - new ArrayList()) - .build(); - - assertThat(message.toByteString()).isEqualTo(ByteString.EMPTY); - } - @Test public void testDynamicMessagePackedParsing() throws Exception { TestPackedTypes.Builder builder = TestPackedTypes.newBuilder(); diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java index 01c2f4b..55864af 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java @@ -1529,7 +1529,7 @@ public class GeneratedMessageTest { assertThat(builder.getFooInt()).isEqualTo(123); TestOneof2 message = builder.buildPartial(); assertThat(message.hasFooInt()).isTrue(); - assertThat(message.getFooInt()).isEqualTo(123); + assertThat(123).isEqualTo(message.getFooInt()); assertThat(builder.clearFooInt().hasFooInt()).isFalse(); TestOneof2 message2 = builder.build(); @@ -1943,7 +1943,7 @@ public class GeneratedMessageTest { @Test public void - extendableBuilder_extensionFieldContainingBuilder_setRepeatedFieldOverwritesElement() { + extendableBuilder_extensionFieldContainingBuilder_setRepeatedFieldOverwritesElement() { TestAllExtensions.Builder builder = TestAllExtensions.newBuilder(); builder.addRepeatedField(REPEATED_NESTED_MESSAGE_EXTENSION, NestedMessage.getDefaultInstance()); // Calling getRepeatedFieldBuilder and ignoring the returned Builder should have no diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java index 9ea7f93..1270ef0 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java @@ -30,13 +30,14 @@ package com.google.protobuf; -import junit.framework.TestCase; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.BarPrime; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Foo; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestOneofEquals; import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.TestRecursiveOneof; +import junit.framework.TestCase; + /** * Test generate equal and hash methods for the lite runtime. * @@ -119,6 +120,6 @@ public class LiteEqualsAndHashTest extends TestCase { public void testRecursiveHashcode() { // This tests that we don't infinite loop. - int unused = TestRecursiveOneof.getDefaultInstance().hashCode(); + TestRecursiveOneof.getDefaultInstance().hashCode(); } } diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java index 961c0b5..a3637f9 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java @@ -33,6 +33,7 @@ package com.google.protobuf; import static com.google.common.truth.Truth.assertThat; import protobuf_unittest.Engine; +import protobuf_unittest.TimingBelt; import protobuf_unittest.Vehicle; import protobuf_unittest.Wheel; import java.util.ArrayList; @@ -48,6 +49,27 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class NestedBuildersTest { + @Test + public void test3LayerPropagationWithIntermediateClear() { + Vehicle.Builder vehicleBuilder = Vehicle.newBuilder(); + vehicleBuilder.getEngineBuilder().getTimingBeltBuilder(); + + // This step detaches the TimingBelt.Builder (though it leaves a SingleFieldBuilder in place) + vehicleBuilder.getEngineBuilder().clear(); + + // These steps build the middle and top level messages, it used to leave the vestigial + // TimingBelt.Builder in a state where further changes didn't propagate anymore + Object unused = vehicleBuilder.getEngineBuilder().build(); + unused = vehicleBuilder.build(); + + TimingBelt expected = TimingBelt.newBuilder().setNumberOfTeeth(124).build(); + vehicleBuilder.getEngineBuilder().setTimingBelt(expected); + // Testing that b/254158939 is fixed. It used to be that the setTimingBelt call above didn't + // propagate a change notification and the call below would return a stale version of the timing + // belt. + assertThat(vehicleBuilder.getEngine().getTimingBelt()).isEqualTo(expected); + } + @Test public void testMessagesAndBuilders() { Vehicle.Builder vehicleBuilder = Vehicle.newBuilder(); diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java index 872eaf4..d2215b0 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java @@ -82,7 +82,7 @@ public class SingleFieldBuilderV3Test { assertThat(mockParent.getInvalidationCount()).isEqualTo(0); assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(1); assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(1); - TestAllTypes unused = builder.build(); + builder.build(); builder.getBuilder().setOptionalInt32(2); assertThat(builder.getBuilder().getOptionalInt32()).isEqualTo(2); assertThat(builder.getMessage().getOptionalInt32()).isEqualTo(2); diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java index bb73a6b..fdeccc2 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java @@ -34,7 +34,6 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; import static java.lang.Math.min; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -49,6 +48,52 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class SmallSortedMapTest { + // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it + // here for JDK 1.5 users. + private static class SimpleEntry implements Map.Entry { + private final K key; + private V value; + + SimpleEntry(K key, V value) { + this.key = key; + this.value = value; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return value; + } + + @Override + public V setValue(V value) { + V oldValue = this.value; + this.value = value; + return oldValue; + } + + private static boolean eq(Object o1, Object o2) { + return o1 == null ? o2 == null : o1.equals(o2); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Map.Entry)) { + return false; + } + Map.Entry e = (Map.Entry) o; + return eq(key, e.getKey()) && eq(value, e.getValue()); + } + + @Override + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); + } + } @Test public void testPutAndGetArrayEntriesOnly() { @@ -197,8 +242,8 @@ public class SmallSortedMapTest { } Set> entrySet = map.entrySet(); for (int i = 0; i < 6; i++) { - assertThat(entrySet).contains(new AbstractMap.SimpleEntry(i, i + 1)); - assertThat(entrySet).doesNotContain(new AbstractMap.SimpleEntry(i, i)); + assertThat(entrySet).contains(new SimpleEntry(i, i + 1)); + assertThat(entrySet).doesNotContain(new SimpleEntry(i, i)); } } @@ -207,7 +252,7 @@ public class SmallSortedMapTest { SmallSortedMap map = SmallSortedMap.newInstanceForTest(3); Set> entrySet = map.entrySet(); for (int i = 0; i < 6; i++) { - Map.Entry entry = new AbstractMap.SimpleEntry<>(i, i + 1); + Map.Entry entry = new SimpleEntry<>(i, i + 1); assertThat(entrySet.add(entry)).isTrue(); assertThat(entrySet.add(entry)).isFalse(); } @@ -227,7 +272,7 @@ public class SmallSortedMapTest { assertThat(map.put(i, i + 1)).isNull(); } for (int i = 0; i < 6; i++) { - Map.Entry entry = new AbstractMap.SimpleEntry<>(i, i + 1); + Map.Entry entry = new SimpleEntry<>(i, i + 1); assertThat(entrySet.remove(entry)).isTrue(); assertThat(entrySet.remove(entry)).isFalse(); } diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java index ad512a9..38d2471 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java @@ -49,7 +49,7 @@ public class TestBadIdentifiers extends TestCase { TestBadIdentifiersProto.Override.getDefaultInstance(); } - @SuppressWarnings({"IgnoredPureGetter", "CheckReturnValue"}) // TODO(b/221602772): Fix this + @SuppressWarnings("IgnoredPureGetter") // TODO(b/221602772): Fix this public void testGetDescriptor() { TestBadIdentifiersProto.getDescriptor(); TestBadIdentifiersProto.Descriptor.getDefaultInstance().getDescriptor(); diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java index 71a540a..46a4d17 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java @@ -235,7 +235,6 @@ import protobuf_unittest.UnittestProto.TestRequired; import protobuf_unittest.UnittestProto.TestUnpackedTypes; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Collections; @@ -3843,11 +3842,7 @@ public final class TestUtil { private static ByteString readBytesFromResource(String name) { try { - InputStream in = TestUtil.class.getResourceAsStream(name); - if (in == null) { // - throw new RuntimeException("Tests data file " + name + " is missing."); - } - return ByteString.readFrom(in); + return ByteString.readFrom(TestUtil.class.getResourceAsStream(name)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java index 1a76848..cde1776 100644 --- a/libs/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java +++ b/libs/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java @@ -67,7 +67,9 @@ import org.junit.function.ThrowingRunnable; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Test case for {@link TextFormat}. */ +/** + * Test case for {@link TextFormat}. + */ @RunWith(JUnit4.class) public class TextFormatTest { @@ -823,7 +825,6 @@ public class TextFormatTest { } } - @CanIgnoreReturnValue private TestAllTypes assertParseSuccessWithOverwriteForbidden(String text) throws TextFormat.ParseException { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); @@ -1449,18 +1450,6 @@ public class TextFormatTest { + "unknown_field3: 3\n"); } - @Test - public void testParseUnknownExtensionWithAnyMessage() throws Exception { - assertParseSuccessWithUnknownExtensions( - "[unknown_extension]: { " - + " any_value { " - + " [type.googleapis.com/protobuf_unittest.OneString] { " - + " data: 123 " - + " } " - + " } " - + "}"); - } - // See additional coverage in testOneofOverwriteForbidden and testMapOverwriteForbidden. @Test public void testParseNonRepeatedFields() throws Exception { @@ -1773,7 +1762,6 @@ public class TextFormatTest { } } - @SuppressWarnings("LenientFormatStringValidation") private void assertLocation( TextFormatParseInfoTree tree, final Descriptor descriptor, @@ -1787,7 +1775,6 @@ public class TextFormatTest { TextFormatParseLocation expected = TextFormatParseLocation.create(line, column); assertThat(location).isEqualTo(expected); } else if (line != -1 && column != -1) { - // Expected 0 args, but got 3. assertWithMessage( "Tree/descriptor/fieldname did not contain index %d, line %d column %d expected", index, line, column) diff --git a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto index fd479bb..4ec9688 100644 --- a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto +++ b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto @@ -31,10 +31,7 @@ syntax = "proto2"; -package map_for_proto2_lite_test; option java_outer_classname = "MapForProto2TestProto"; -option optimize_for = LITE_RUNTIME; -option java_package = "map_lite_test"; message TestMap { message MessageValue { @@ -128,3 +125,6 @@ message ReservedAsMapFieldWithEnumValue { // null is not a 'reserved word' per se but as a literal needs similar care map null = 10; } +package map_for_proto2_lite_test; +option java_package = "map_lite_test"; +option optimize_for = LITE_RUNTIME; diff --git a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto index 07933ed..319e32c 100644 --- a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto +++ b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto @@ -45,6 +45,11 @@ message Vehicle { message Engine { optional int32 cylinder = 1; optional int32 liters = 2; + optional TimingBelt timing_belt = 3; +} + +message TimingBelt { + optional int32 number_of_teeth = 1; } message Wheel { diff --git a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message.proto b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message.proto index dad00ed..86c48b0 100644 --- a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message.proto +++ b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message.proto @@ -36,6 +36,7 @@ package protobuf.experimental; option java_package = "com.google.protobuf.testing"; option java_outer_classname = "Proto2Testing"; + message Proto2SpecialFieldName { optional double regular_name = 1; optional int32 cached_size = 2; diff --git a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto index 57efc17..7dfd40e 100644 --- a/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto +++ b/libs/protobuf/java/core/src/test/proto/com/google/protobuf/proto2_message_lite.proto @@ -36,6 +36,7 @@ package protobuf.experimental.lite; option java_package = "com.google.protobuf.testing"; option java_outer_classname = "Proto2TestingLite"; + message Proto2MessageLite { enum TestEnum { diff --git a/libs/protobuf/java/internal/BUILD.bazel b/libs/protobuf/java/internal/BUILD.bazel index ff111e7..662dabd 100644 --- a/libs/protobuf/java/internal/BUILD.bazel +++ b/libs/protobuf/java/internal/BUILD.bazel @@ -1,24 +1,13 @@ -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") - package(default_visibility = ["//java:__subpackages__"]) +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + pkg_files( name = "dist_files", srcs = [ "BUILD.bazel", - "JavaVersionTest.java", "testing.bzl", ], strip_prefix = strip_prefix.from_root(""), visibility = ["//java:__pkg__"], ) - -java_test( - name = "java_version", - srcs = ["JavaVersionTest.java"], - test_class = "JavaVersionTest", - deps = [ - "@maven//:com_google_truth_truth", - "@maven//:junit_junit", - ], -) diff --git a/libs/protobuf/java/internal/JavaVersionTest.java b/libs/protobuf/java/internal/JavaVersionTest.java deleted file mode 100644 index eb004d5..0000000 --- a/libs/protobuf/java/internal/JavaVersionTest.java +++ /dev/null @@ -1,22 +0,0 @@ -// Test that Kokoro is using the expected version of Java. -import static com.google.common.truth.Truth.assertWithMessage; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class JavaVersionTest { - @Test - public void testJavaVersion() throws Exception { - String exp = System.getenv("KOKORO_JAVA_VERSION"); - if(exp == null || exp.isEmpty()) { - System.err.println("No kokoro java version found, skipping check"); - return; - } - String version = System.getProperty("java.version"); - assertWithMessage("Expected Python " + exp + " but found Python " + version) - .that(version.startsWith(exp)) - .isTrue(); - } -} diff --git a/libs/protobuf/java/internal/testing.bzl b/libs/protobuf/java/internal/testing.bzl index b2a781b..76e1e45 100644 --- a/libs/protobuf/java/internal/testing.bzl +++ b/libs/protobuf/java/internal/testing.bzl @@ -50,7 +50,7 @@ def junit_tests(name, srcs, data = [], deps = [], package_name = "com.google.pro if not test_name.endswith("Test") or test_name.startswith("Abstract"): continue if test_prefix: - test_name = "%s%s" % (test_prefix, test_name) + test_name = "%s%s" % (test_prefix, test_name) test_names = test_names + [test_name] suite_name = prefix + '_' + test_name _gen_suite( diff --git a/libs/protobuf/java/kotlin-lite/BUILD.bazel b/libs/protobuf/java/kotlin-lite/BUILD.bazel index 39f8b33..d3d9ddf 100644 --- a/libs/protobuf/java/kotlin-lite/BUILD.bazel +++ b/libs/protobuf/java/kotlin-lite/BUILD.bazel @@ -140,7 +140,7 @@ internal_gen_kt_protos( internal_gen_kt_protos( name = "gen_kotlin_unittest_lite", lite = True, - deps = ["//src/google/protobuf:lite_test_protos"], + deps = ["//:kt_unittest_lite"], ) kt_jvm_library( @@ -152,7 +152,6 @@ kt_jvm_library( deps = [ ":evil_names_proto2_java_proto_lite", "//java/core:generic_test_protos_java_proto_lite", - "//java/core:lite_test_protos_java_proto_lite", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", "//java/lite", @@ -162,7 +161,7 @@ kt_jvm_library( internal_gen_kt_protos( name = "gen_kotlin_proto3_unittest_lite", lite = True, - deps = ["//src/google/protobuf:kt_proto3_unittest_protos"], + deps = ["//:kt_proto3_unittest"], ) kt_jvm_library( @@ -176,7 +175,6 @@ kt_jvm_library( ":evil_names_proto3_java_proto_lite", ":multiple_files_proto3_java_proto_lite", "//java/core:generic_test_protos_java_proto_lite", - "//java/core:lite_test_protos_java_proto_lite", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", "//java/lite", diff --git a/libs/protobuf/java/kotlin-lite/pom.xml b/libs/protobuf/java/kotlin-lite/pom.xml index ace12aa..50dcc83 100644 --- a/libs/protobuf/java/kotlin-lite/pom.xml +++ b/libs/protobuf/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 protobuf-kotlin-lite diff --git a/libs/protobuf/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt b/libs/protobuf/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt index 50ebbd7..c343ccd 100644 --- a/libs/protobuf/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt +++ b/libs/protobuf/java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt @@ -46,6 +46,13 @@ import com.google.protobuf.UnittestLite.TestEmptyMessageLite import com.google.protobuf.UnittestLite.TestEmptyMessageWithExtensionsLite import com.google.protobuf.copy import com.google.protobuf.foreignMessageLite +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.EvilNamesProto2 +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.HardKeywordsAllTypesProto2 +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.Interface +import com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto2Kt +import com.google.protobuf.kotlin.generator.evilNamesProto2 +import com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto2 +import com.google.protobuf.kotlin.generator.interface_ import com.google.protobuf.optionalGroupExtensionLite import com.google.protobuf.repeatedGroupExtensionLite import com.google.protobuf.testAllExtensionsLite @@ -55,13 +62,6 @@ import com.google.protobuf.testEmptyMessageWithExtensionsLite import protobuf_unittest.MapLiteUnittest.MapEnumLite import protobuf_unittest.MapLiteUnittest.TestMapLite import protobuf_unittest.testMapLite -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.EvilNamesProto2 -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.HardKeywordsAllTypesProto2 -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.Interface -import `in`.com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto2Kt -import `in`.com.google.protobuf.kotlin.generator.evilNamesProto2 -import `in`.com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto2 -import `in`.com.google.protobuf.kotlin.generator.interface_ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @@ -178,7 +178,6 @@ class Proto2LiteTest { .isEqualTo(TestUtilLite.getAllLiteSetBuilder().build()) } - @Suppress("CheckResult") @Test fun testGetters() { testAllTypesLite { @@ -199,7 +198,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testDefaultGetters() { testAllTypesLite { @@ -210,7 +208,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testRepeatedGettersAndSetters() { testAllTypesLite { @@ -301,7 +298,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testHazzers() { testAllTypesLite { @@ -332,7 +328,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testClears() { testAllTypesLite { @@ -525,7 +520,6 @@ class Proto2LiteTest { .isEqualTo(TestUtilLite.getAllLiteExtensionsSet()) } - @Suppress("CheckResult") @Test fun testExtensionGetters() { testAllExtensionsLite { @@ -549,7 +543,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testRepeatedExtensionGettersAndSetters() { testAllExtensionsLite { @@ -639,7 +632,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testExtensionContains() { testAllExtensionsLite { @@ -671,7 +663,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testExtensionClears() { testAllExtensionsLite { @@ -760,7 +751,6 @@ class Proto2LiteTest { ) } - @Suppress("CheckResult") @Test fun testMapGettersAndSetters() { testMapLite { @@ -816,7 +806,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testMapRemove() { testMapLite { @@ -842,7 +831,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testMapClear() { testMapLite { @@ -889,6 +877,7 @@ class Proto2LiteTest { boolean = 1L sealed = "foo" interface_ = 1F + in_ = 1 object_ = "foo" cachedSize_ = "foo" serializedSize_ = true @@ -914,6 +903,7 @@ class Proto2LiteTest { .setBoolean(1L) .setSealed("foo") .setInterface(1F) + .setIn(1) .setObject("foo") .setCachedSize_("foo") .setSerializedSize_(true) @@ -924,13 +914,15 @@ class Proto2LiteTest { assertThat(interface_ {}).isEqualTo(Interface.newBuilder().build()) } - @Suppress("CheckResult") @Test fun testHardKeywordGettersAndSetters() { hardKeywordsAllTypesProto2 { as_ = 1 assertThat(as_).isEqualTo(1) + in_ = "foo" + assertThat(in_).isEqualTo("foo") + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO assertThat(break_).isEqualTo(HardKeywordsAllTypesProto2.NestedEnum.FOO) @@ -954,13 +946,15 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testHardKeywordHazzers() { hardKeywordsAllTypesProto2 { as_ = 1 assertThat(hasAs_()).isTrue() + in_ = "foo" + assertThat(hasIn_()).isTrue() + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO assertThat(hasBreak_()).isTrue() @@ -969,7 +963,6 @@ class Proto2LiteTest { } } - @Suppress("CheckResult") @Test fun testHardKeywordClears() { hardKeywordsAllTypesProto2 { @@ -977,6 +970,10 @@ class Proto2LiteTest { clearAs_() assertThat(hasAs_()).isFalse() + in_ = "foo" + clearIn_() + assertThat(hasIn_()).isFalse() + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO clearBreak_() assertThat(hasBreak_()).isFalse() diff --git a/libs/protobuf/java/kotlin/BUILD.bazel b/libs/protobuf/java/kotlin/BUILD.bazel index c809117..67fc6e0 100644 --- a/libs/protobuf/java/kotlin/BUILD.bazel +++ b/libs/protobuf/java/kotlin/BUILD.bazel @@ -25,7 +25,6 @@ kt_jvm_library( deps = [ ":only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/lite", - "@maven//:com_google_errorprone_error_prone_annotations", ], ) @@ -60,7 +59,7 @@ kt_jvm_export( maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_JAVA_VERSION, pom_template = "//java/kotlin:pom_template.xml", resources = [ - "//src/google/protobuf:descriptor_proto_srcs", + "//:built_in_runtime_protos", "//:well_known_type_protos", ], tags = ["manual"], @@ -225,7 +224,7 @@ internal_gen_kt_protos( internal_gen_kt_protos( name = "gen_kotlin_unittest", visibility = ["//java:__subpackages__"], - deps = ["//src/google/protobuf:kt_unittest_protos"], + deps = ["//:kt_unittest"], ) kt_jvm_library( @@ -241,13 +240,12 @@ kt_jvm_library( ":well_known_protos_kotlin", "//java/core", "//java/core:generic_test_protos_java_proto", - "//java/core:lite_test_protos_java_proto", ], ) internal_gen_kt_protos( name = "gen_kotlin_proto3_unittest", - deps = ["//src/google/protobuf:kt_proto3_unittest_protos"], + deps = ["//:kt_proto3_unittest"], ) kt_jvm_library( @@ -264,7 +262,6 @@ kt_jvm_library( ":shared_runtime", "//java/core", "//java/core:generic_test_protos_java_proto", - "//java/core:lite_test_protos_java_proto", ], ) diff --git a/libs/protobuf/java/kotlin/pom.xml b/libs/protobuf/java/kotlin/pom.xml index 27be007..9cc9ea0 100644 --- a/libs/protobuf/java/kotlin/pom.xml +++ b/libs/protobuf/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 protobuf-kotlin @@ -34,11 +34,6 @@ mockito-core test - - com.google.errorprone - error_prone_annotations - 2.5.1 - com.google.guava guava diff --git a/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt b/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt index 426b367..af797cc 100644 --- a/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt +++ b/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt @@ -33,6 +33,13 @@ package com.google.protobuf.kotlin import com.google.common.truth.Truth.assertThat import com.google.protobuf.TestUtil import com.google.protobuf.TestUtil.toBytes +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.EvilNamesProto2 +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.HardKeywordsAllTypesProto2 +import com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.Interface +import com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto2Kt +import com.google.protobuf.kotlin.generator.evilNamesProto2 +import com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto2 +import com.google.protobuf.kotlin.generator.interface_ import com.google.protobuf.test.UnittestImport.ImportEnum import com.google.protobuf.test.UnittestImport.ImportMessage import com.google.protobuf.test.UnittestImportPublic.PublicImportMessage @@ -60,13 +67,6 @@ import protobuf_unittest.testEmptyMessageWithExtensions import protobuf_unittest.testEnumMap import protobuf_unittest.testIntIntMap import protobuf_unittest.testMaps -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.EvilNamesProto2 -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.HardKeywordsAllTypesProto2 -import `in`.com.google.protobuf.kotlin.generator.EvilNamesProto2OuterClass.Interface -import `in`.com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto2Kt -import `in`.com.google.protobuf.kotlin.generator.evilNamesProto2 -import `in`.com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto2 -import `in`.com.google.protobuf.kotlin.generator.interface_ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @@ -183,7 +183,6 @@ class Proto2Test { .isEqualTo(TestUtil.getAllSetBuilder().build()) } - @Suppress("CheckResult") @Test fun testGetters() { testAllTypes { @@ -204,7 +203,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testDefaultGetters() { testAllTypes { @@ -215,7 +213,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testRepeatedGettersAndSetters() { testAllTypes { @@ -297,7 +294,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testHazzers() { testAllTypes { @@ -328,7 +324,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testClears() { testAllTypes { @@ -517,7 +512,6 @@ class Proto2Test { .isEqualTo(TestUtil.getAllExtensionsSet()) } - @Suppress("CheckResult") @Test fun testExtensionGetters() { testAllExtensions { @@ -540,7 +534,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testRepeatedExtensionGettersAndSetters() { testAllExtensions { @@ -621,7 +614,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testExtensionContains() { testAllExtensions { @@ -652,7 +644,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testExtensionClears() { testAllExtensions { @@ -734,7 +725,6 @@ class Proto2Test { ) } - @Suppress("CheckResult") @Test fun testMapGettersAndSetters() { val intMap = testIntIntMap { @@ -786,7 +776,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testMapRemove() { val intMap = testIntIntMap { @@ -814,7 +803,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testMapClear() { val intMap = testIntIntMap { @@ -863,6 +851,7 @@ class Proto2Test { boolean = 1L sealed = "foo" interface_ = 1F + in_ = 1 object_ = "foo" cachedSize_ = "foo" serializedSize_ = true @@ -888,6 +877,7 @@ class Proto2Test { .setBoolean(1L) .setSealed("foo") .setInterface(1F) + .setIn(1) .setObject("foo") .setCachedSize_("foo") .setSerializedSize_(true) @@ -898,13 +888,15 @@ class Proto2Test { assertThat(interface_ {}).isEqualTo(Interface.newBuilder().build()) } - @Suppress("CheckResult") @Test fun testHardKeywordGettersAndSetters() { hardKeywordsAllTypesProto2 { as_ = 1 assertThat(as_).isEqualTo(1) + in_ = "foo" + assertThat(in_).isEqualTo("foo") + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO assertThat(break_).isEqualTo(HardKeywordsAllTypesProto2.NestedEnum.FOO) @@ -928,13 +920,15 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testHardKeywordHazzers() { hardKeywordsAllTypesProto2 { as_ = 1 assertThat(hasAs_()).isTrue() + in_ = "foo" + assertThat(hasIn_()).isTrue() + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO assertThat(hasBreak_()).isTrue() @@ -943,7 +937,6 @@ class Proto2Test { } } - @Suppress("CheckResult") @Test fun testHardKeywordClears() { hardKeywordsAllTypesProto2 { @@ -951,6 +944,10 @@ class Proto2Test { clearAs_() assertThat(hasAs_()).isFalse() + in_ = "foo" + clearIn_() + assertThat(hasIn_()).isFalse() + break_ = HardKeywordsAllTypesProto2.NestedEnum.FOO clearBreak_() assertThat(hasBreak_()).isFalse() diff --git a/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt b/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt index 8ce0094..d6d0ab5 100644 --- a/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt +++ b/libs/protobuf/java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt @@ -31,13 +31,13 @@ package com.google.protobuf.kotlin import com.google.common.truth.Truth.assertThat -import com.google.protobuf.kotlin.generator.`in`.EvilNamesProto3OuterClass.Class -import com.google.protobuf.kotlin.generator.`in`.EvilNamesProto3OuterClass.EvilNamesProto3 -import com.google.protobuf.kotlin.generator.`in`.EvilNamesProto3OuterClass.HardKeywordsAllTypesProto3 -import com.google.protobuf.kotlin.generator.`in`.HardKeywordsAllTypesProto3Kt -import com.google.protobuf.kotlin.generator.`in`.class_ -import com.google.protobuf.kotlin.generator.`in`.evilNamesProto3 -import com.google.protobuf.kotlin.generator.`in`.hardKeywordsAllTypesProto3 +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.Class +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.EvilNamesProto3 +import com.google.protobuf.kotlin.generator.EvilNamesProto3OuterClass.HardKeywordsAllTypesProto3 +import com.google.protobuf.kotlin.generator.HardKeywordsAllTypesProto3Kt +import com.google.protobuf.kotlin.generator.class_ +import com.google.protobuf.kotlin.generator.evilNamesProto3 +import com.google.protobuf.kotlin.generator.hardKeywordsAllTypesProto3 import proto3_unittest.TestAllTypesKt import proto3_unittest.TestAllTypesKt.nestedMessage import proto3_unittest.UnittestProto3.TestAllTypes @@ -54,7 +54,6 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class Proto3Test { - @Suppress("CheckResult") @Test fun testGettersAndSetters() { testAllTypes { @@ -66,17 +65,11 @@ class Proto3Test { assertThat(optionalNestedMessage).isEqualTo(TestAllTypesKt.nestedMessage { bb = 118 }) optionalNestedEnum = NestedEnum.BAZ assertThat(optionalNestedEnum).isEqualTo(NestedEnum.BAZ) - assertThat(optionalNestedEnumValue).isEqualTo(3) - optionalNestedEnumValue = 1 - assertThat(optionalNestedEnumValue).isEqualTo(1) - assertThat(optionalNestedEnum).isEqualTo(NestedEnum.FOO) - oneofUint32 = 601 assertThat(oneofUint32).isEqualTo(601) } } - @Suppress("CheckResult") @Test fun testRepeatedGettersAndSetters() { testAllTypes { @@ -266,7 +259,6 @@ class Proto3Test { assertThat(class_ {}).isEqualTo(Class.newBuilder().build()) } - @Suppress("CheckResult") @Test fun testHardKeywordGettersAndSetters() { hardKeywordsAllTypesProto3 { @@ -299,7 +291,6 @@ class Proto3Test { } } - @Suppress("CheckResult") @Test fun testHardKeywordHazzers() { hardKeywordsAllTypesProto3 { @@ -317,7 +308,6 @@ class Proto3Test { } } - @Suppress("CheckResult") @Test fun testHardKeywordClears() { hardKeywordsAllTypesProto3 { diff --git a/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto2.proto b/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto2.proto index e5cdc7d..3735baf 100644 --- a/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto2.proto +++ b/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto2.proto @@ -33,7 +33,7 @@ syntax = "proto2"; package protobuf.kotlin.generator; -option java_package = "in.com.google.protobuf.kotlin.generator"; +option java_package = "com.google.protobuf.kotlin.generator"; message EvilNamesProto2 { optional bool initialized = 1; @@ -61,6 +61,7 @@ message EvilNamesProto2 { optional int64 boolean = 18; optional string sealed = 19; optional float interface = 20; + optional int32 in = 21; optional string object = 22; optional string cached_size = 23; optional bool serialized_size = 24; @@ -78,6 +79,7 @@ message HardKeywordsAllTypesProto2 { } optional int32 as = 1; + optional string in = 2; optional NestedEnum break = 3; map continue = 4; optional NestedMessage do = 5; diff --git a/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto b/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto index 9feb219..f6b06d3 100644 --- a/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto +++ b/libs/protobuf/java/kotlin/src/test/proto/com/google/protobuf/evil_names_proto3.proto @@ -33,7 +33,7 @@ syntax = "proto3"; package protobuf.kotlin.generator; -option java_package = "com.google.protobuf.kotlin.generator.in"; +option java_package = "com.google.protobuf.kotlin.generator"; message EvilNamesProto3 { bool initialized = 1; diff --git a/libs/protobuf/java/lite.md b/libs/protobuf/java/lite.md index 87b917a..ad92079 100644 --- a/libs/protobuf/java/lite.md +++ b/libs/protobuf/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.21.8 + 3.21.12 ``` diff --git a/libs/protobuf/java/lite/BUILD.bazel b/libs/protobuf/java/lite/BUILD.bazel index f84b5c5..9ae3c51 100644 --- a/libs/protobuf/java/lite/BUILD.bazel +++ b/libs/protobuf/java/lite/BUILD.bazel @@ -72,7 +72,6 @@ junit_tests( ":lite", "//java/core:generic_test_protos_java_proto_lite", "//java/core:java_test_protos_java_proto_lite", - "//java/core:lite_test_protos_java_proto_lite", "//java/core:test_util_lite", "@maven//:com_google_truth_truth", "@maven//:junit_junit", diff --git a/libs/protobuf/java/lite/pom.xml b/libs/protobuf/java/lite/pom.xml index 69bd30c..367cd7a 100644 --- a/libs/protobuf/java/lite/pom.xml +++ b/libs/protobuf/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 protobuf-javalite diff --git a/libs/protobuf/java/lite/src/test/java/com/google/protobuf/LiteTest.java b/libs/protobuf/java/lite/src/test/java/com/google/protobuf/LiteTest.java index ee21b37..801303b 100644 --- a/libs/protobuf/java/lite/src/test/java/com/google/protobuf/LiteTest.java +++ b/libs/protobuf/java/lite/src/test/java/com/google/protobuf/LiteTest.java @@ -51,7 +51,6 @@ import com.google.protobuf.UnittestLite.TestAllTypesLite.RepeatedGroup; import com.google.protobuf.UnittestLite.TestAllTypesLiteOrBuilder; import com.google.protobuf.UnittestLite.TestHugeFieldNumbersLite; import com.google.protobuf.UnittestLite.TestNestedExtensionLite; -import com.google.protobuf.testing.Proto3TestingLite.Proto3MessageLite; import map_lite_test.MapTestProto.TestMap; import map_lite_test.MapTestProto.TestMap.MessageValue; import protobuf_unittest.NestedExtensionLite; @@ -225,22 +224,6 @@ public class LiteTest { assertThat(((Byte) memo.get(message)).intValue()).isEqualTo(1); } - @Test - public void testProto3EnumListValueCopyOnWrite() { - Proto3MessageLite.Builder builder = Proto3MessageLite.newBuilder(); - - Proto3MessageLite message = builder.build(); - builder.addFieldEnumList30Value(Proto3MessageLite.TestEnum.ONE_VALUE); - assertThat(message.getFieldEnumList30List()).isEmpty(); - assertThat(builder.getFieldEnumList30List()).containsExactly(Proto3MessageLite.TestEnum.ONE); - assertThat(message.getFieldEnumList30List()).isEmpty(); - Proto3MessageLite messageAfterBuild = builder.build(); - builder.clearFieldEnumList30(); - assertThat(builder.getFieldEnumList30List()).isEmpty(); - assertThat(messageAfterBuild.getFieldEnumList30List()) - .containsExactly(Proto3MessageLite.TestEnum.ONE); - } - @Test public void testSanityCopyOnWrite() throws InvalidProtocolBufferException { // Since builders are implemented as a thin wrapper around a message diff --git a/libs/protobuf/java/pom.xml b/libs/protobuf/java/pom.xml index ad86282..863d07f 100644 --- a/libs/protobuf/java/pom.xml +++ b/libs/protobuf/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 pom Protocol Buffers [Parent] @@ -33,7 +33,7 @@ ${project.basedir}/../.. ${protobuf.basedir}/src - ${protobuf.basedir}/protoc + ${protobuf.source.dir}/protoc src/test/proto ${project.build.directory}/generated-sources ${project.build.directory}/generated-test-sources diff --git a/libs/protobuf/java/protoc/README.md b/libs/protobuf/java/protoc/README.md deleted file mode 100644 index a31ffbe..0000000 --- a/libs/protobuf/java/protoc/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Publish pre-compiled protoc artifacts -``protoc`` is the compiler for ``.proto`` files. It generates language bindings -for the messages and/or RPC services from ``.proto`` files. - -Because ``protoc`` is a native executable, the scripts under this directory -publish a ``protoc`` executable (a.k.a. artifact) to Maven repositories. The -artifact can be used by build automation tools so that users would not need to -compile and install ``protoc`` for their systems. - -If you would like us to publish protoc artifact for a new platform, please -open an issue to request it. - -## Maven Location -The published protoc artifacts are available on Maven here: - - https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/ - -## Versioning -The version of the ``protoc`` artifact must be the same as the version of the -Protobuf project. - -## Artifact name -The name of a published ``protoc`` artifact is in the following format: -``protoc---.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``. - -Note that artifacts for linux/macos also have the `.exe` suffix but they are -not windows binaries. - -## System requirement -Install [Apache Maven](http://maven.apache.org/) if you don't have it. - -The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and -Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project -for how to set up the build environment. - -## Tested build environments -We have successfully built artifacts on the following environments: -- Linux x86_32 and x86_64: - - Centos 6.9 (within Docker 1.6.1) - - Ubuntu 14.04.5 64-bit -- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit -- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5 diff --git a/libs/protobuf/java/protoc/pom.xml b/libs/protobuf/java/protoc/pom.xml deleted file mode 100644 index 9b61b98..0000000 --- a/libs/protobuf/java/protoc/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - 4.0.0 - - com.google - google - 5 - - com.google.protobuf - protoc - 3.21.6 - pom - Protobuf Compiler - - Protobuf Compiler (protoc) is a compiler for .proto files. It generates - language-specific code for Protobuf messages and RPC interfaces. - - 2008 - https://developers.google.com/protocol-buffers/ - - - BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause - repo - - - - https://github.com/protocolbuffers/protobuf - - scm:git:https://github.com/protocolbuffers/protobuf.git - - - diff --git a/libs/protobuf/java/util/pom.xml b/libs/protobuf/java/util/pom.xml index 1c0ee7b..c13df65 100644 --- a/libs/protobuf/java/util/pom.xml +++ b/libs/protobuf/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.21.8 + 3.21.12 protobuf-java-util diff --git a/libs/protobuf/java/util/pom_template.xml b/libs/protobuf/java/util/pom_template.xml index 13fe3ec..b20e62a 100644 --- a/libs/protobuf/java/util/pom_template.xml +++ b/libs/protobuf/java/util/pom_template.xml @@ -12,8 +12,7 @@ Protocol Buffers [Util] Utilities for Protocol Buffers - - {dependencies} - + + {dependencies} diff --git a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java index 55e3079..9f36494 100644 --- a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java +++ b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java @@ -101,8 +101,9 @@ public final class FieldMaskUtil { /** * Constructs a FieldMask for a list of field paths in a certain type. * - * @throws IllegalArgumentException if any of the field path is not valid + * @throws IllegalArgumentException if any of the field path is not valid. */ + // TODO(xiaofeng): Consider renaming fromStrings() public static FieldMask fromStringList(Class type, Iterable paths) { return fromStringList(Internal.getDefaultInstance(type).getDescriptorForType(), paths); } diff --git a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index 0b09fcc..95f3665 100644 --- a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -343,8 +343,7 @@ public final class Timestamps { public static Timestamp fromDate(Date date) { if (date instanceof java.sql.Timestamp) { java.sql.Timestamp sqlTimestamp = (java.sql.Timestamp) date; - long time = sqlTimestamp.getTime(); - long integralSeconds = (time < 0 && time % 1000 != 0) ? time / 1000L - 1 : time / 1000L ; // truncate the fractional seconds + long integralSeconds = sqlTimestamp.getTime() / 1000L; // truncate the fractional seconds return Timestamp.newBuilder() .setSeconds(integralSeconds) .setNanos(sqlTimestamp.getNanos()) diff --git a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Values.java b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Values.java index 370aafa..f03d70e 100644 --- a/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Values.java +++ b/libs/protobuf/java/util/src/main/java/com/google/protobuf/util/Values.java @@ -75,7 +75,10 @@ public final class Values { * element in the iterable. */ public static Value of(Iterable values) { - return Value.newBuilder().setListValue(ListValue.newBuilder().addAllValues(values)).build(); + Value.Builder valueBuilder = Value.newBuilder(); + ListValue.Builder listValue = valueBuilder.getListValueBuilder(); + listValue.addAllValues(values); + return valueBuilder.build(); } private Values() {} diff --git a/libs/protobuf/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java b/libs/protobuf/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java index 51f7a85..ea90a6b 100644 --- a/libs/protobuf/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java +++ b/libs/protobuf/java/util/src/test/java/com/google/protobuf/util/TimestampsTest.java @@ -475,20 +475,6 @@ public class TimestampsTest { Timestamp timestamp = Timestamps.fromDate(date); assertThat(Timestamps.toString(timestamp)).isEqualTo("1970-01-01T00:00:01.111Z"); } - - @Test - public void testFromSqlTimestamp_beforeEpoch() { - Date date = new java.sql.Timestamp(-1111); - Timestamp timestamp = Timestamps.fromDate(date); - assertThat(Timestamps.toString(timestamp)).isEqualTo("1969-12-31T23:59:58.889Z"); - } - - @Test - public void testFromSqlTimestamp_beforeEpochWholeSecond() { - Date date = new java.sql.Timestamp(-2000); - Timestamp timestamp = Timestamps.fromDate(date); - assertThat(Timestamps.toString(timestamp)).isEqualTo("1969-12-31T23:59:58Z"); - } @Test public void testTimeOperations() throws Exception { diff --git a/libs/protobuf/kokoro/common/caplog.sh b/libs/protobuf/kokoro/caplog.sh similarity index 98% rename from libs/protobuf/kokoro/common/caplog.sh rename to libs/protobuf/kokoro/caplog.sh index 33ee1ab..fe81949 100644 --- a/libs/protobuf/kokoro/common/caplog.sh +++ b/libs/protobuf/kokoro/caplog.sh @@ -19,7 +19,7 @@ # # Use the provided functions below as build/test fixtures, e.g.: # -# source kokoro/common/capture_logs.sh +# source kokoro/capture_logs.sh # caplog build/step1 # caplog tests/step2 # diff --git a/libs/protobuf/kokoro/common/bazel_flags.sh b/libs/protobuf/kokoro/common/bazel_flags.sh deleted file mode 100755 index 6a2777f..0000000 --- a/libs/protobuf/kokoro/common/bazel_flags.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Helper for setting up common bazel flags in Kokoro. -# -# This script prints extra flags to a bazel invocation when it is run from -# Kokoro. When the special environment variables are not present (e.g., if you -# run Kokoro build scripts locally), this script only flips some debug settings. -# -# Example of running directly: -# bazel test $(path/to/bazel_flags.sh) //... - -function bazel_flags::gen_invocation_id() { - # Create a new invocation ID and store in the artifacts dir. - local _invocation_id=$(uuidgen | tr A-Z a-z) - - # Put the new invocation ID at the start of the output IDs file. Some - # Google-internal tools only look at the first entry, so this ensures the most - # recent entry is first. - local _ids_file=${KOKORO_ARTIFACTS_DIR}/bazel_invocation_ids - local _temp_ids=$(mktemp) - echo ${_invocation_id} > ${_temp_ids} - [[ -e ${_ids_file} ]] && cat ${_ids_file} >> ${_temp_ids} - mv -f ${_temp_ids} ${_ids_file} - - echo -n ${_invocation_id} -} - -# Prints flags to use on Kokoro. -function bazel_flags::kokoro_flags() { - [[ -n ${KOKORO_JOB_NAME:-} ]] || return - - local -a _flags - _flags+=( - --invocation_id=$(bazel_flags::gen_invocation_id) - --remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/${KOKORO_JOB_NAME} - ) - if [[ -n ${KOKORO_BAZEL_AUTH_CREDENTIAL:-} ]]; then - _flags+=( --google_credentials=${KOKORO_BAZEL_AUTH_CREDENTIAL} ) - else - _flags+=( --google_default_credentials=true ) - fi - - echo "${_flags[@]}" -} - -echo "$(bazel_flags::kokoro_flags) --keep_going --test_output=errors" diff --git a/libs/protobuf/kokoro/common/cmake.sh b/libs/protobuf/kokoro/common/cmake.sh deleted file mode 100755 index 99be3be..0000000 --- a/libs/protobuf/kokoro/common/cmake.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# -# Build tests under CMake. -# -# This script is used from macos and linux builds. It runs cmake and ctest in -# the current directory. Any additional setup should be done before running this -# script. -# -# This script uses `caplog` to save logfiles. See caplog.sh for details. - -set -eu -o pipefail -: ${SCRIPT_ROOT:=$(cd $(dirname $0)/../..; pwd)} - -################################################################################ -# If you are using this script to run tests, you can set some environment -# variables to control behavior: -# -# By default, find the sources based on this script's path. -: ${SOURCE_DIR:=${SCRIPT_ROOT}} -# -# By default, put outputs under /cmake/build. -: ${BUILD_DIR:=${SOURCE_DIR}/cmake/build} -# -# CMAKE_BUILD_TYPE is supported in cmake 3.22+. If set, we pass the value of this -# variable explicitly for compatibility with older versions of cmake. See: -# https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html -# (N.B.: not to be confused with CMAKE_CONFIG_TYPE.) -if [[ -n ${CMAKE_BUILD_TYPE:-} ]]; then - CMAKE_BUILD_TYPE_FLAG="-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" -else - CMAKE_BUILD_TYPE_FLAG= -fi -# -# For several other CMake options, see docs here: -# https://cmake.org/cmake/help/latest/manual/cmake-env-variables.7.html -# -# Some variables you may want to override (see cmake docs for details): -# CMAKE_BUILD_PARALLEL_LEVEL -# CMAKE_CONFIG_TYPE (N.B.: not to be confused with CMAKE_BUILD_TYPE) -# CMAKE_GENERATOR -# CTEST_PARALLEL_LEVEL -################################################################################ - -echo "Building using..." -echo " Sources: ${SOURCE_DIR}" -echo " Build output: ${BUILD_DIR}" -if [[ ${SOURCE_DIR} != ${SCRIPT_ROOT} ]]; then - echo " Build scripts: ${SCRIPT_ROOT}" -fi -set -x -source ${SCRIPT_ROOT}/kokoro/common/caplog.sh - -# -# Configure under $BUILD_DIR: -# -mkdir -p "${BUILD_DIR}" - -( - cd "${BUILD_DIR}" - caplog 01_configure \ - cmake -S "${SOURCE_DIR}" \ - ${CMAKE_BUILD_TYPE_FLAG} \ - ${CAPLOG_CMAKE_ARGS:-} -) -if [[ -n ${CAPLOG_DIR:-} ]]; then - # Save configuration logs. - mkdir -p "${CAPLOG_DIR}/CMakeFiles" - cp "${BUILD_DIR}"/CMakeFiles/CMake*.log "${CAPLOG_DIR}/CMakeFiles" -fi - -# -# Build: -# -caplog 02_build \ - cmake --build "${BUILD_DIR}" - -# -# Run tests -# -( - cd "${BUILD_DIR}" - caplog 03_combined_testlog \ - ctest ${CAPLOG_CTEST_ARGS:-} -) diff --git a/libs/protobuf/kokoro/docs/publish-python.sh b/libs/protobuf/kokoro/docs/publish-python.sh index 9f88017..684afa6 100755 --- a/libs/protobuf/kokoro/docs/publish-python.sh +++ b/libs/protobuf/kokoro/docs/publish-python.sh @@ -14,9 +14,9 @@ sudo apt-get -y install software-properties-common sudo add-apt-repository universe sudo apt-get update sudo apt-get -y install unzip -wget https://github.com/protocolbuffers/protobuf/releases/download/v21.1/protoc-21.1-linux-x86_64.zip -unzip protoc-21.1-linux-x86_64.zip bin/protoc -mv bin/protoc ../protoc +wget https://github.com/protocolbuffers/protobuf/releases/download/v21.0-rc1/protoc-21.0-rc-1-linux-x86_64.zip +unzip protoc-21.0-rc-1-linux-x86_64.zip bin/protoc +mv bin/protoc ../src/protoc python3 -m venv venv source venv/bin/activate python setup.py install @@ -30,7 +30,7 @@ make html cd .. deactivate -python3 -m pip install protobuf==4.21.1 gcp-docuploader==0.6.3 +python3 -m pip install protobuf==4.21.0rc1 gcp-docuploader # install a json parser sudo apt-get -y install jq diff --git a/libs/protobuf/kokoro/linux/32-bit/Dockerfile b/libs/protobuf/kokoro/linux/32-bit/Dockerfile new file mode 100644 index 0000000..1278889 --- /dev/null +++ b/libs/protobuf/kokoro/linux/32-bit/Dockerfile @@ -0,0 +1,143 @@ +# This Dockerfile specifies the recipe for creating an image for the tests +# to run in. +# +# We install as many test dependencies here as we can, because these setup +# steps can be cached. They do *not* run every time we run the build. +# The Docker image is only rebuilt when the Dockerfile (ie. this file) +# changes. + +# Base Dockerfile for gRPC dev images +FROM 32bit/debian:latest + +# Apt source for php +RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main" | tee /etc/apt/sources.list.d/various-php.list && \ + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F4FCBB07 + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + unzip \ + # -- For python -- + python-setuptools \ + python-pip \ + python-dev \ + # -- For C++ benchmarks -- + cmake \ + # -- For PHP -- + php5.5 \ + php5.5-dev \ + php5.5-xml \ + php5.6 \ + php5.6-dev \ + php5.6-xml \ + php7.0 \ + php7.0-dev \ + php7.0-xml \ + phpunit \ + valgrind \ + libxml2-dev \ + && apt-get clean + +################## +# PHP dependencies. +RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror +RUN mv mirror php-5.5.38.tar.bz2 +RUN tar -xvf php-5.5.38.tar.bz2 +RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \ + make && make install && make clean && cd .. +RUN cd php-5.5.38 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.5 && \ + make && make install && make clean && cd .. + +RUN wget http://am1.php.net/get/php-5.6.30.tar.bz2/from/this/mirror +RUN mv mirror php-5.6.30.tar.bz2 +RUN tar -xvf php-5.6.30.tar.bz2 +RUN cd php-5.6.30 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts && \ + make && make install && cd .. +RUN cd php-5.6.30 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.6 && \ + make && make install && cd .. + +RUN wget http://am1.php.net/get/php-7.0.18.tar.bz2/from/this/mirror +RUN mv mirror php-7.0.18.tar.bz2 +RUN tar -xvf php-7.0.18.tar.bz2 +RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts && \ + make && make install && cd .. +RUN cd php-7.0.18 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 && \ + make && make install && cd .. + +RUN wget http://am1.php.net/get/php-7.1.4.tar.bz2/from/this/mirror +RUN mv mirror php-7.1.4.tar.bz2 +RUN tar -xvf php-7.1.4.tar.bz2 +RUN cd php-7.1.4 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts && \ + make && make install && cd .. +RUN cd php-7.1.4 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 && \ + make && make install && cd .. + +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN mv composer.phar /usr/bin/composer +RUN php -r "unlink('composer-setup.php');" +RUN composer config -g -- disable-tls true +RUN composer config -g -- secure-http false +RUN cd /tmp && \ + git clone https://github.com/google/protobuf.git && \ + cd protobuf/php && \ + git reset --hard 49b44bff2b6257a119f9c6a342d6151c736586b8 && \ + ln -sfn /usr/local/php-5.5/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-5.5/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-5.5/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.5 && \ + ln -sfn /usr/local/php-5.6/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-5.6/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-5.6/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-5.6 && \ + ln -sfn /usr/local/php-7.0/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-7.0/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-7.0/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.0 && \ + ln -sfn /usr/local/php-7.1/bin/php /usr/bin/php && \ + ln -sfn /usr/local/php-7.1/bin/php-config /usr/bin/php-config && \ + ln -sfn /usr/local/php-7.1/bin/phpize /usr/bin/phpize && \ + composer install && \ + mv vendor /usr/local/vendor-7.1 + +################## +# Python dependencies + +# These packages exist in apt-get, but their versions are too old, so we have +# to get updates from pip. + +RUN pip install pip --upgrade +RUN pip install virtualenv tox yattag + +################## +# Prepare ccache + +RUN ln -s /usr/bin/ccache /usr/local/bin/gcc +RUN ln -s /usr/bin/ccache /usr/local/bin/g++ +RUN ln -s /usr/bin/ccache /usr/local/bin/cc +RUN ln -s /usr/bin/ccache /usr/local/bin/c++ +RUN ln -s /usr/bin/ccache /usr/local/bin/clang +RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ + +# Define the default command. +CMD ["bash"] diff --git a/libs/protobuf/kokoro/linux/32-bit/build.sh b/libs/protobuf/kokoro/linux/32-bit/build.sh index 85dd81d..8c0a41e 100755 --- a/libs/protobuf/kokoro/linux/32-bit/build.sh +++ b/libs/protobuf/kokoro/linux/32-bit/build.sh @@ -4,20 +4,15 @@ # running the "pull request 32" project: # # This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. - -set -ex +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. # Change to repo root cd $(dirname $0)/../../.. -GIT_REPO_ROOT=$(pwd) -CONTAINER_IMAGE=gcr.io/protobuf-build/php/32bit@sha256:824cbdff02ee543eb69ee4b02c8c58cc7887f70f49e41725a35765d92a898b4f - -git submodule update --init --recursive - -docker run \ - "$@" \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - bash -l "/workspace/kokoro/linux/32-bit/test_php.sh" +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/php_32bit +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="php_all_32" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/32-bit/common.cfg b/libs/protobuf/kokoro/linux/32-bit/common.cfg deleted file mode 100644 index 28b66c0..0000000 --- a/libs/protobuf/kokoro/linux/32-bit/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/32-bit/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/32-bit/continuous.cfg b/libs/protobuf/kokoro/linux/32-bit/continuous.cfg index 8523c22..28b66c0 100644 --- a/libs/protobuf/kokoro/linux/32-bit/continuous.cfg +++ b/libs/protobuf/kokoro/linux/32-bit/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/32-bit/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/32-bit/presubmit.cfg b/libs/protobuf/kokoro/linux/32-bit/presubmit.cfg index 8523c22..28b66c0 100644 --- a/libs/protobuf/kokoro/linux/32-bit/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/32-bit/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/32-bit/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/32-bit/test_php.sh b/libs/protobuf/kokoro/linux/32-bit/test_php.sh deleted file mode 100644 index 746ed4c..0000000 --- a/libs/protobuf/kokoro/linux/32-bit/test_php.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -set -eux - -# Change to repo root -cd $(dirname $0)/../../.. - -use_php() { - VERSION=$1 - export PATH=/usr/local/php-${VERSION}/bin:$PATH -} - -build_php() { - use_php $1 - pushd php - rm -rf vendor - php -v - php -m - composer update - composer test - popd -} - -test_php_c() { - pushd php - rm -rf vendor - php -v - php -m - composer update - composer test_c - popd -} - -build_php_c() { - use_php $1 - test_php_c -} - -mkdir -p build -pushd build -cmake .. -cmake --build . -- -j20 -ctest --verbose --parallel 20 -export PROTOC=$(pwd)/protoc -popd - -build_php 7.0 -build_php 7.1 -build_php 7.4 -build_php_c 7.0 -build_php_c 7.1 -build_php_c 7.4 -build_php_c 7.1-zts -build_php_c 7.2-zts -build_php_c 7.5-zts - -# Cleanup after CMake build -rm -rf build diff --git a/libs/protobuf/kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh index f7c45f9..425cc90 100755 --- a/libs/protobuf/kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/cpp_crosscompile_and_run_tests_with_qemu_aarch64.sh @@ -5,9 +5,12 @@ set -ex +mkdir -p cmake/crossbuild_aarch64 +cd cmake/crossbuild_aarch64 + # the build commands are expected to run under dockcross docker image # where the CC, CXX and other toolchain variables already point to the crosscompiler -cmake . +cmake .. make -j8 # check that the resulting test binary is indeed an aarch64 ELF diff --git a/libs/protobuf/kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh index efaf40f..ba34fa7 100755 --- a/libs/protobuf/kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh @@ -13,11 +13,7 @@ else fi # Pin the dockcross image since newer versions of the image break the build -# We use an older version of dockcross image that has gcc4.9.4 because it was built -# before https://github.com/dockcross/dockcross/pull/449 -# Thanks to that, wheel build with this image aren't actually -# compliant with manylinux2014, but only with manylinux_2_24 -PINNED_DOCKCROSS_IMAGE_VERSION=dockcross/manylinux2014-aarch64:20200929-608e6ac +PINNED_DOCKCROSS_IMAGE_VERSION=dockcross/manylinux2014-aarch64:20210803-41e5c69 # running dockcross image without any arguments generates a wrapper # scripts that can be used to run commands under the dockcross image diff --git a/libs/protobuf/kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh index 7f07968..77942a4 100755 --- a/libs/protobuf/kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh @@ -4,5 +4,6 @@ set -ex -cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 -Dprotobuf_BUILD_TESTS=OFF . +./autogen.sh +CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64 make -j8 diff --git a/libs/protobuf/kokoro/linux/aarch64/python_crosscompile_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/python_crosscompile_aarch64.sh index a04c7e4..db2e776 100755 --- a/libs/protobuf/kokoro/linux/aarch64/python_crosscompile_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/python_crosscompile_aarch64.sh @@ -8,16 +8,13 @@ set -ex PYTHON="/opt/python/cp38-cp38/bin/python" -# Initialize any submodules. -git submodule update --init --recursive - -# Build protoc and libprotobuf -cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 -Dprotobuf_BUILD_TESTS=OFF . +./autogen.sh +CXXFLAGS="-fPIC -g -O2" ./configure --host=aarch64 make -j8 # create a simple shell wrapper that runs crosscompiled protoc under qemu echo '#!/bin/bash' >protoc_qemu_wrapper.sh -echo 'exec qemu-aarch64 "../protoc" "$@"' >>protoc_qemu_wrapper.sh +echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh chmod ugo+x protoc_qemu_wrapper.sh # PROTOC variable is by build_py step that runs under ./python directory diff --git a/libs/protobuf/kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh index 4c75ad8..5026d04 100755 --- a/libs/protobuf/kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/python_run_tests_with_qemu_aarch64.sh @@ -7,7 +7,7 @@ cd $(dirname $0)/../../.. cd python PYTHON="/opt/python/cp38-cp38/bin/python" -${PYTHON} -m pip install --user pytest auditwheel numpy +${PYTHON} -m pip install --user pytest auditwheel # check that we are really using aarch64 python (${PYTHON} -c 'import sysconfig; print(sysconfig.get_platform())' | grep -q "linux-aarch64") || (echo "Wrong python platform, needs to be aarch64 python."; exit 1) @@ -16,7 +16,7 @@ ${PYTHON} -m pip install --user pytest auditwheel numpy # we've built the python extension previously with --inplace option # so we can just discover all the unittests and run them directly under # the python/ directory. -LD_LIBRARY_PATH=. PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp ${PYTHON} -m pytest google/protobuf +LD_LIBRARY_PATH=../src/.libs PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp ${PYTHON} -m pytest google/protobuf # step 2: run auditwheel show to check that the wheel is manylinux2014 compatible. # auditwheel needs to run on wheel's target platform (or under an emulator) diff --git a/libs/protobuf/kokoro/linux/aarch64/test_ruby_aarch64.sh b/libs/protobuf/kokoro/linux/aarch64/test_ruby_aarch64.sh index e256e4e..91ee5f2 100755 --- a/libs/protobuf/kokoro/linux/aarch64/test_ruby_aarch64.sh +++ b/libs/protobuf/kokoro/linux/aarch64/test_ruby_aarch64.sh @@ -24,4 +24,4 @@ kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh ko # otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity, # we just run map the user's home to a throwaway temporary directory -docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "PROTOC=/work/protoc" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/ruby:2.7.3-buster kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh +docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/ruby:2.7.3-buster kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh \ No newline at end of file diff --git a/libs/protobuf/kokoro/linux/bazel.sh b/libs/protobuf/kokoro/linux/bazel.sh deleted file mode 100755 index 9f16569..0000000 --- a/libs/protobuf/kokoro/linux/bazel.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -set -ex - -if [[ -z "${CONTAINER_IMAGE}" ]]; then - CONTAINER_IMAGE=gcr.io/protobuf-build/bazel/linux@sha256:2bfd061284eff8234f2fcca16d71d43c69ccf3a22206628b54c204a6a9aac277 -fi - -cd $(dirname $0)/../.. -GIT_REPO_ROOT=`pwd` - -ENVS=() - -# Check for specific versions pinned to the docker image. In these cases we -# want to forward the environment variable to tests, so that they can verify -# that the correct version is being picked up by Bazel. -ENVS+=("--test_env=KOKORO_JAVA_VERSION") -ENVS+=("--test_env=KOKORO_PYTHON_VERSION") -ENVS+=("--test_env=KOKORO_RUBY_VERSION") - -if [ -n "$BAZEL_ENV" ]; then - for env in $BAZEL_ENV; do - ENVS+="--action_env=${env}" - done -fi - -function run { - local CONFIG=$1 - local BAZEL_CONFIG=$2 - - tmpfile=$(mktemp -u) - - rm -rf $GIT_REPO_ROOT/bazel-out $GIT_REPO_ROOT/bazel-bin - rm -rf $GIT_REPO_ROOT/logs - - docker run \ - --cidfile $tmpfile \ - --cap-add=SYS_PTRACE \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - test \ - $(${GIT_REPO_ROOT}/kokoro/common/bazel_flags.sh) \ - ${ENVS[@]} \ - $PLATFORM_CONFIG \ - $BAZEL_CONFIG \ - $BAZEL_EXTRA_FLAGS \ - $BAZEL_TARGETS - - # Save logs for Kokoro - docker cp \ - `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR/$CONFIG -} - -if [ -n "$BAZEL_CONFIGS" ]; then - for config in $BAZEL_CONFIGS; do - run $config "--config=$config" - done -else - run -fi diff --git a/libs/protobuf/kokoro/linux/bazel/build.sh b/libs/protobuf/kokoro/linux/bazel/build.sh new file mode 100755 index 0000000..a338a99 --- /dev/null +++ b/libs/protobuf/kokoro/linux/bazel/build.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Build file to set up and run tests +set -ex + +# Install Bazel 4.0.0. +use_bazel.sh 4.0.0 +bazel version + +# Print bazel testlogs to stdout when tests failed. +function print_test_logs { + # TODO(yannic): Only print logs of failing tests. + testlogs_dir=$(bazel info bazel-testlogs) + testlogs=$(find "${testlogs_dir}" -name "*.log") + for log in $testlogs; do + cat "${log}" + done +} + +# Change to repo root +cd $(dirname $0)/../../.. + +git submodule update --init --recursive + +# Disabled for now, re-enable if appropriate. +# //:build_files_updated_unittest \ + +trap print_test_logs EXIT +bazel test -k --copt=-Werror --host_copt=-Werror \ + //build_defs:all \ + //java:tests \ + //:protoc \ + //:protobuf \ + //:protobuf_python \ + //:protobuf_test +trap - EXIT + +pushd examples +bazel build //... +popd + +# Verify that we can build successfully from generated tar files. +./autogen.sh && ./configure && make -j$(nproc) dist +DIST=`ls *.tar.gz` +tar -xf $DIST +cd ${DIST//.tar.gz} +bazel build //:protobuf //:protobuf_java diff --git a/libs/protobuf/kokoro/linux/bazel/common.cfg b/libs/protobuf/kokoro/linux/bazel/common.cfg deleted file mode 100644 index 54447d9..0000000 --- a/libs/protobuf/kokoro/linux/bazel/common.cfg +++ /dev/null @@ -1,31 +0,0 @@ -# Default setup for the all of our Kokoro builds. - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/bazel/linux-san:b6bfa3bb505e83f062af0cb0ed23abf1e89b9edb" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//src/... @com_google_protobuf_examples//..." -} - -env_vars { - key: "BAZEL_CONFIGS" - value: "opt dbg asan kokoro-msan tsan ubsan" -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--distinct_host_configuration=false" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/bazel/continuous.cfg b/libs/protobuf/kokoro/linux/bazel/continuous.cfg index 8523c22..13cfef1 100644 --- a/libs/protobuf/kokoro/linux/bazel/continuous.cfg +++ b/libs/protobuf/kokoro/linux/bazel/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/bazel/build.sh" +timeout_mins: 15 diff --git a/libs/protobuf/kokoro/linux/bazel/presubmit.cfg b/libs/protobuf/kokoro/linux/bazel/presubmit.cfg index 8523c22..13cfef1 100644 --- a/libs/protobuf/kokoro/linux/bazel/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/bazel/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/bazel/build.sh" +timeout_mins: 15 diff --git a/libs/protobuf/kokoro/linux/bazel_distcheck/build.sh b/libs/protobuf/kokoro/linux/bazel_distcheck/build.sh new file mode 100755 index 0000000..4eb6e11 --- /dev/null +++ b/libs/protobuf/kokoro/linux/bazel_distcheck/build.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# Build file to set up and run tests using bazel-build dist archive +# +# Note that the builds use WORKSPACE to fetch external sources, not +# git submodules. + +set -eux + +BUILD_ONLY_TARGETS=( + //pkg:all + //:protoc + //:protobuf + //:protobuf_python +) + +TEST_TARGETS=( + //build_defs:all + //conformance:all + //java:tests + //:protobuf_test +) + +use_bazel.sh 5.0.0 || true +bazel version + +# Change to repo root +cd $(dirname $0)/../../.. + +# Construct temp directory for running the dist build. +# If you want to run locally and keep the build dir, create a directory +# and pass it in the DIST_WORK_ROOT env var. +if [[ -z ${DIST_WORK_ROOT:-} ]]; then + : ${DIST_WORK_ROOT:=$(mktemp -d)} + function dist_cleanup() { + rm -rf ${DIST_WORK_ROOT} + } + trap dist_cleanup EXIT +fi + +# Let Bazel share the distdir. +TMP_DISTDIR=${DIST_WORK_ROOT}/bazel-distdir +mkdir -p ${TMP_DISTDIR} + +# Build distribution archive +date +bazel fetch --distdir=${TMP_DISTDIR} //pkg:dist_all_tar +bazel build --distdir=${TMP_DISTDIR} //pkg:dist_all_tar +DIST_ARCHIVE=$(readlink $(bazel info bazel-bin)/pkg/dist_all_tar.tar.gz) +bazel shutdown + +# The `pkg_tar` rule emits a symlink based on the rule name. The actual +# file is named with the current version. +date +echo "Resolved archive path: ${DIST_ARCHIVE}" + +# Extract the dist archive. +date +DIST_WORKSPACE=${DIST_WORK_ROOT}/protobuf +mkdir -p ${DIST_WORKSPACE} +tar -C ${DIST_WORKSPACE} --strip-components=1 -axf ${DIST_ARCHIVE} + +# Perform build steps in the extracted dist sources. + +cd ${DIST_WORKSPACE} +FAILED=false + +date +bazel fetch --distdir=${TMP_DISTDIR} "${BUILD_ONLY_TARGETS[@]}" "${TEST_TARGETS[@]}" + +date +bazel build --distdir=${TMP_DISTDIR} -k \ + "${BUILD_ONLY_TARGETS[@]}" || FAILED=true + +date +bazel test --distdir=${TMP_DISTDIR} --test_output=errors -k \ + "${TEST_TARGETS[@]}" || FAILED=true + +date +cd examples +bazel build --distdir=${TMP_DISTDIR} //... || FAILED=true + +if ${FAILED}; then + echo FAILED + exit 1 +fi +echo PASS diff --git a/libs/protobuf/kokoro/linux/bazel_distcheck/continuous.cfg b/libs/protobuf/kokoro/linux/bazel_distcheck/continuous.cfg new file mode 100644 index 0000000..4ea8b21 --- /dev/null +++ b/libs/protobuf/kokoro/linux/bazel_distcheck/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/bazel_distcheck/build.sh" +timeout_mins: 15 diff --git a/libs/protobuf/kokoro/linux/bazel_distcheck/presubmit.cfg b/libs/protobuf/kokoro/linux/bazel_distcheck/presubmit.cfg new file mode 100644 index 0000000..4ea8b21 --- /dev/null +++ b/libs/protobuf/kokoro/linux/bazel_distcheck/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/bazel_distcheck/build.sh" +timeout_mins: 15 diff --git a/libs/protobuf/kokoro/linux/benchmark/build.sh b/libs/protobuf/kokoro/linux/benchmark/build.sh new file mode 100755 index 0000000..f470989 --- /dev/null +++ b/libs/protobuf/kokoro/linux/benchmark/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="benchmark" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/php_all/common.cfg b/libs/protobuf/kokoro/linux/benchmark/continuous.cfg similarity index 68% rename from libs/protobuf/kokoro/linux/php_all/common.cfg rename to libs/protobuf/kokoro/linux/benchmark/continuous.cfg index dfa8037..8cc8f96 100644 --- a/libs/protobuf/kokoro/linux/php_all/common.cfg +++ b/libs/protobuf/kokoro/linux/benchmark/continuous.cfg @@ -1,8 +1,8 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/linux/php_all/build.sh" -timeout_mins: 120 +build_file: "protobuf/kokoro/linux/benchmark/build.sh" +timeout_mins: 240 action { define_artifacts { diff --git a/libs/protobuf/kokoro/linux/benchmark/run.sh b/libs/protobuf/kokoro/linux/benchmark/run.sh new file mode 100755 index 0000000..963f779 --- /dev/null +++ b/libs/protobuf/kokoro/linux/benchmark/run.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Change to repo root +cd $(dirname $0)/../../.. + +set -ex + +export OUTPUT_DIR=testoutput +repo_root="$(pwd)" + +# TODO(jtattermusch): Add back support for benchmarking with tcmalloc for C++ and python. +# This feature was removed since it used to use tcmalloc from https://github.com/gperftools/gperftools.git +# which is very outdated. See https://github.com/protocolbuffers/protobuf/issues/8725. + +# download datasets for benchmark +pushd benchmarks +datasets=$(for file in $(find . -type f -name "dataset.*.pb" -not -path "./tmp/*"); do echo "$(pwd)/$file"; done | xargs) +echo $datasets +popd + +# build Python protobuf +./autogen.sh +./configure CXXFLAGS="-fPIC -O2" +make -j8 +pushd python +python3 -m venv env +source env/bin/activate +python3 setup.py build --cpp_implementation +pip3 install --install-option="--cpp_implementation" . +popd + +# build and run Python benchmark +# We do this before building protobuf C++ since C++ build +# will rewrite some libraries used by protobuf python. +pushd benchmarks +make python-pure-python-benchmark +make python-cpp-reflection-benchmark +make -j8 python-cpp-generated-code-benchmark +echo "[" > tmp/python_result.json +echo "benchmarking pure python..." +./python-pure-python-benchmark --json --behavior_prefix="pure-python-benchmark" $datasets >> tmp/python_result.json +echo "," >> "tmp/python_result.json" +echo "benchmarking python cpp reflection..." +env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-reflection-benchmark --json --behavior_prefix="cpp-reflection-benchmark" $datasets >> tmp/python_result.json +echo "," >> "tmp/python_result.json" +echo "benchmarking python cpp generated code..." +env LD_LIBRARY_PATH="${repo_root}/src/.libs" ./python-cpp-generated-code-benchmark --json --behavior_prefix="cpp-generated-code-benchmark" $datasets >> tmp/python_result.json +echo "]" >> "tmp/python_result.json" +popd + +# build CPP protobuf +./configure +make clean && make -j8 + +pushd java +mvn package -B -Dmaven.test.skip=true +popd + +pushd benchmarks + +# build and run C++ benchmark +# "make clean" deletes the contents of the tmp/ directory, so we move it elsewhere and then restore it once build is done. +# TODO(jtattermusch): find a less clumsy way of protecting python_result.json contents +mv tmp/python_result.json . && make clean && make -j8 cpp-benchmark && mv python_result.json tmp +echo "benchmarking cpp..." +env ./cpp-benchmark --benchmark_min_time=5.0 --benchmark_out_format=json --benchmark_out="tmp/cpp_result.json" $datasets + +# TODO(jtattermusch): add benchmarks for https://github.com/protocolbuffers/protobuf-go. +# The original benchmarks for https://github.com/golang/protobuf were removed +# because: +# * they were broken and haven't been producing results for a long time +# * the https://github.com/golang/protobuf implementation has been superseded by +# https://github.com/protocolbuffers/protobuf-go + +# build and run java benchmark (java 11 is required) +make java-benchmark +echo "benchmarking java..." +./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets + +# TODO(jtattermusch): re-enable JS benchmarks once https://github.com/protocolbuffers/protobuf/issues/8747 is fixed. +# build and run js benchmark +# make js-benchmark +# echo "benchmarking js..." +# ./js-benchmark $datasets --json_output=$(pwd)/tmp/node_result.json + +# TODO(jtattermusch): add php-c-benchmark. Currently its build is broken. + +# persist raw the results in the build job log (for better debuggability) +cat tmp/cpp_result.json +cat tmp/java_result.json +cat tmp/python_result.json + +# print the postprocessed results to the build job log +# TODO(jtattermusch): re-enable uploading results to bigquery (it is currently broken) +make python_add_init +env LD_LIBRARY_PATH="${repo_root}/src/.libs" python3 -m util.result_parser \ + -cpp="../tmp/cpp_result.json" -java="../tmp/java_result.json" -python="../tmp/python_result.json" +popd + diff --git a/libs/protobuf/kokoro/linux/build_and_run_docker.sh b/libs/protobuf/kokoro/linux/build_and_run_docker.sh new file mode 100755 index 0000000..cdbd6e2 --- /dev/null +++ b/libs/protobuf/kokoro/linux/build_and_run_docker.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Builds docker image and runs a command under it. +# This is a generic script that is configured with the following variables: +# +# DOCKERHUB_ORGANIZATION - The organization on docker hub storing the +# Dockerfile. +# DOCKERFILE_DIR - Directory in which Dockerfile file is located. +# DOCKER_RUN_SCRIPT - Script to run under docker (relative to protobuf repo root) +# OUTPUT_DIR - Directory that will be copied from inside docker after finishing. +# $@ - Extra args to pass to docker run + +set -ex + +cd $(dirname $0)/../.. +git_root=$(pwd) +cd - + +# Use image name based on Dockerfile sha1 +if [ -z "$DOCKERHUB_ORGANIZATION" ] +then + DOCKERHUB_ORGANIZATION=grpctesting/protobuf + DOCKER_IMAGE_NAME=${DOCKERHUB_ORGANIZATION}_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) +else + # TODO(teboring): Remove this when all tests have been migrated to separate + # docker images. + DOCKERFILE_PREFIX=$(basename $DOCKERFILE_DIR) + DOCKER_IMAGE_NAME=${DOCKERHUB_ORGANIZATION}/${DOCKERFILE_PREFIX}_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) +fi + +# Pull dockerimage from Dockerhub. This sometimes fails intermittently, so we +# keep trying until we succeed. +until docker pull $DOCKER_IMAGE_NAME; do sleep 10; done + +# Ensure existence of ccache directory +CCACHE_DIR=/tmp/protobuf-ccache +mkdir -p $CCACHE_DIR + +# Choose random name for docker container +CONTAINER_NAME="build_and_run_docker_$(uuidgen)" + +echo $git_root + +# Run command inside docker +docker run \ + "$@" \ + -e CCACHE_DIR=$CCACHE_DIR \ + -e KOKORO_BUILD_NUMBER=$KOKORO_BUILD_NUMBER \ + -e KOKORO_BUILD_ID=$KOKORO_BUILD_ID \ + -e EXTERNAL_GIT_ROOT="/var/local/kokoro/protobuf" \ + -e TEST_SET="$TEST_SET" \ + -v "$git_root:/var/local/kokoro/protobuf:ro" \ + -v $CCACHE_DIR:$CCACHE_DIR \ + -w /var/local/git/protobuf \ + --name=$CONTAINER_NAME \ + $DOCKER_IMAGE_NAME \ + bash -l "/var/local/kokoro/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true" + +# remove the container, possibly killing it first +docker rm -f $CONTAINER_NAME || true + +[ -z "$FAILED" ] || { + exit 1 +} diff --git a/libs/protobuf/kokoro/linux/cmake/build.sh b/libs/protobuf/kokoro/linux/cmake/build.sh deleted file mode 100755 index ee06d95..0000000 --- a/libs/protobuf/kokoro/linux/cmake/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests using CMake - -set -eux - -# Change to repo root -cd $(dirname $0)/../../.. -GIT_REPO_ROOT=`pwd` - -CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671 - -# Update git submodules -git submodule update --init --recursive - -tmpfile=$(mktemp -u) - -docker run \ - --cidfile $tmpfile \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON - -# Save logs for Kokoro -docker cp \ - `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR diff --git a/libs/protobuf/kokoro/linux/cmake/common.cfg b/libs/protobuf/kokoro/linux/cmake/common.cfg deleted file mode 100644 index f03bd39..0000000 --- a/libs/protobuf/kokoro/linux/cmake/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/cmake/build.sh" -timeout_mins: 1440 - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cmake/continuous.cfg b/libs/protobuf/kokoro/linux/cmake/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake/presubmit.cfg b/libs/protobuf/kokoro/linux/cmake/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_install/build.sh b/libs/protobuf/kokoro/linux/cmake_install/build.sh deleted file mode 100755 index 7fdf267..0000000 --- a/libs/protobuf/kokoro/linux/cmake_install/build.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# -# Build file to build, install, and test using CMake. - -set -eux - -# Change to repo root -cd $(dirname $0)/../../.. -GIT_REPO_ROOT=`pwd` - -CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671 - -# Update git submodules -git submodule update --init --recursive - -tmpfile=$(mktemp -u) - -docker run \ - --cidfile $tmpfile \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - "/install.sh && /test.sh \ - -Dprotobuf_REMOVE_INSTALLED_HEADERS=ON \ - -Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF \ - -Dprotobuf_BUILD_CONFORMANCE=ON" - - -# Save logs for Kokoro -docker cp \ - `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR diff --git a/libs/protobuf/kokoro/linux/cmake_install/common.cfg b/libs/protobuf/kokoro/linux/cmake_install/common.cfg deleted file mode 100644 index f1ae0b3..0000000 --- a/libs/protobuf/kokoro/linux/cmake_install/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/cmake_install/build.sh" -timeout_mins: 1440 - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cmake_install/continuous.cfg b/libs/protobuf/kokoro/linux/cmake_install/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_install/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_install/presubmit.cfg b/libs/protobuf/kokoro/linux/cmake_install/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_install/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_ninja/build.sh b/libs/protobuf/kokoro/linux/cmake_ninja/build.sh deleted file mode 100755 index 21cc01e..0000000 --- a/libs/protobuf/kokoro/linux/cmake_ninja/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests using CMake with the Ninja generator. - -set -eux - -# Change to repo root -cd $(dirname $0)/../../.. -GIT_REPO_ROOT=`pwd` - -CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671 - -# Update git submodules -git submodule update --init --recursive - -tmpfile=$(mktemp -u) - -docker run \ - --cidfile $tmpfile \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - /test.sh -G Ninja -Dprotobuf_BUILD_CONFORMANCE=ON - -# Save logs for Kokoro -docker cp \ - `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR diff --git a/libs/protobuf/kokoro/linux/cmake_ninja/common.cfg b/libs/protobuf/kokoro/linux/cmake_ninja/common.cfg deleted file mode 100644 index 144fc90..0000000 --- a/libs/protobuf/kokoro/linux/cmake_ninja/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/cmake_ninja/build.sh" -timeout_mins: 1440 - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cmake_ninja/continuous.cfg b/libs/protobuf/kokoro/linux/cmake_ninja/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_ninja/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_ninja/presubmit.cfg b/libs/protobuf/kokoro/linux/cmake_ninja/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_ninja/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_shared/build.sh b/libs/protobuf/kokoro/linux/cmake_shared/build.sh deleted file mode 100755 index 1fda3df..0000000 --- a/libs/protobuf/kokoro/linux/cmake_shared/build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests via CMake using shared libraries - -set -eux - -# Change to repo root -cd $(dirname $0)/../../.. -GIT_REPO_ROOT=`pwd` - -CONTAINER_IMAGE=gcr.io/protobuf-build/cmake/linux@sha256:79e6ed9d7f3f8e56167a3309a521e5b7e6a212bfb19855c65ee1cbb6f9099671 - -# Update git submodules -git submodule update --init --recursive - -tmpfile=$(mktemp -u) - -docker run \ - --cidfile $tmpfile \ - -v $GIT_REPO_ROOT:/workspace \ - $CONTAINER_IMAGE \ - /test.sh -Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_SHARED_LIBS=ON - -# Save logs for Kokoro -docker cp \ - `cat $tmpfile`:/workspace/logs $KOKORO_ARTIFACTS_DIR diff --git a/libs/protobuf/kokoro/linux/cmake_shared/common.cfg b/libs/protobuf/kokoro/linux/cmake_shared/common.cfg deleted file mode 100644 index f03bd39..0000000 --- a/libs/protobuf/kokoro/linux/cmake_shared/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/cmake/build.sh" -timeout_mins: 1440 - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cmake_shared/continuous.cfg b/libs/protobuf/kokoro/linux/cmake_shared/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_shared/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cmake_shared/presubmit.cfg b/libs/protobuf/kokoro/linux/cmake_shared/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/linux/cmake_shared/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/linux/cpp_aarch64/build.sh b/libs/protobuf/kokoro/linux/cpp_aarch64/build.sh new file mode 100755 index 0000000..a43ab1c --- /dev/null +++ b/libs/protobuf/kokoro/linux/cpp_aarch64/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "continuous" and "presubmit" jobs. + +set -ex + +# Change to repo root +cd $(dirname $0)/../../.. + +kokoro/linux/aarch64/test_cpp_aarch64.sh diff --git a/libs/protobuf/kokoro/linux/cpp_aarch64/common.cfg b/libs/protobuf/kokoro/linux/cpp_aarch64/common.cfg deleted file mode 100644 index f77f73b..0000000 --- a/libs/protobuf/kokoro/linux/cpp_aarch64/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/emulation/linux:aarch64-4e847d7a01c1792471b6dd985ab0bf2677332e6f" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//src/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cpp_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/cpp_aarch64/continuous.cfg index 8523c22..0f1be4a 100644 --- a/libs/protobuf/kokoro/linux/cpp_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/cpp_aarch64/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_aarch64/build.sh" +timeout_mins: 120 diff --git a/libs/protobuf/kokoro/linux/cpp_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/cpp_aarch64/presubmit.cfg index 8523c22..0f1be4a 100644 --- a/libs/protobuf/kokoro/linux/cpp_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/cpp_aarch64/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_aarch64/build.sh" +timeout_mins: 120 diff --git a/libs/protobuf/kokoro/linux/cpp_distcheck/build.sh b/libs/protobuf/kokoro/linux/cpp_distcheck/build.sh new file mode 100755 index 0000000..a28843e --- /dev/null +++ b/libs/protobuf/kokoro/linux/cpp_distcheck/build.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Build file to set up and run tests + +set -ex # exit immediately on error + +# Change to repo root +cd $(dirname $0)/../../.. + +./tests.sh cpp_distcheck + +# Run tests under release docker image. +DOCKER_IMAGE_NAME=protobuf/protoc_$(sha1sum protoc-artifacts/Dockerfile | cut -f1 -d " ") +until docker pull $DOCKER_IMAGE_NAME; do sleep 10; done + +docker run -v $(pwd):/var/local/protobuf --rm $DOCKER_IMAGE_NAME \ + bash -l /var/local/protobuf/tests.sh cpp || FAILED="true" + +# This directory is owned by root. We need to delete it, because otherwise +# Kokoro will attempt to rsync it and fail with a permission error. +rm -rf src/core + +if [ "$FAILED" = "true" ]; then + exit 1 +fi diff --git a/libs/protobuf/kokoro/windows/cmake_shared/common.cfg b/libs/protobuf/kokoro/linux/cpp_distcheck/continuous.cfg similarity index 63% rename from libs/protobuf/kokoro/windows/cmake_shared/common.cfg rename to libs/protobuf/kokoro/linux/cpp_distcheck/continuous.cfg index 0ba52e2..4289f6a 100644 --- a/libs/protobuf/kokoro/windows/cmake_shared/common.cfg +++ b/libs/protobuf/kokoro/linux/cpp_distcheck/continuous.cfg @@ -1,5 +1,5 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/windows/cmake_shared/build.bat" +build_file: "protobuf/kokoro/linux/cpp_distcheck/build.sh" timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/windows/cmake_install/common.cfg b/libs/protobuf/kokoro/linux/cpp_distcheck/presubmit.cfg similarity index 63% rename from libs/protobuf/kokoro/windows/cmake_install/common.cfg rename to libs/protobuf/kokoro/linux/cpp_distcheck/presubmit.cfg index 2efc0dc..4289f6a 100644 --- a/libs/protobuf/kokoro/windows/cmake_install/common.cfg +++ b/libs/protobuf/kokoro/linux/cpp_distcheck/presubmit.cfg @@ -1,5 +1,5 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/windows/cmake_install/build.bat" +build_file: "protobuf/kokoro/linux/cpp_distcheck/build.sh" timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/cpp_tcmalloc/build.sh b/libs/protobuf/kokoro/linux/cpp_tcmalloc/build.sh new file mode 100755 index 0000000..3c77b11 --- /dev/null +++ b/libs/protobuf/kokoro/linux/cpp_tcmalloc/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Build file to set up and run tests + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/cpp_tcmalloc +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="cpp_tcmalloc" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/cpp_tcmalloc/common.cfg b/libs/protobuf/kokoro/linux/cpp_tcmalloc/common.cfg deleted file mode 100644 index fb76204..0000000 --- a/libs/protobuf/kokoro/linux/cpp_tcmalloc/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 1440 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/tcmalloc/linux:64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//src/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/cpp_tcmalloc/continuous.cfg b/libs/protobuf/kokoro/linux/cpp_tcmalloc/continuous.cfg index 8523c22..46312a9 100644 --- a/libs/protobuf/kokoro/linux/cpp_tcmalloc/continuous.cfg +++ b/libs/protobuf/kokoro/linux/cpp_tcmalloc/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_tcmalloc/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/cpp_tcmalloc/presubmit.cfg b/libs/protobuf/kokoro/linux/cpp_tcmalloc/presubmit.cfg index 8523c22..46312a9 100644 --- a/libs/protobuf/kokoro/linux/cpp_tcmalloc/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/cpp_tcmalloc/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/cpp_tcmalloc/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/csharp/build.sh b/libs/protobuf/kokoro/linux/csharp/build.sh new file mode 100755 index 0000000..9a2eb48 --- /dev/null +++ b/libs/protobuf/kokoro/linux/csharp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/csharp +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="csharp" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/csharp/common.cfg b/libs/protobuf/kokoro/linux/csharp/common.cfg deleted file mode 100644 index 2332c00..0000000 --- a/libs/protobuf/kokoro/linux/csharp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 1440 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/csharp/linux:3.1.415-6.0.100-6bbe70439ba5b0404bb12662cebc0296909389fa" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//csharp/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--action_env=DOTNET_CLI_TELEMETRY_OPTOUT=1 " - "--test_env=DOTNET_CLI_HOME=/home/bazel" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/csharp/continuous.cfg b/libs/protobuf/kokoro/linux/csharp/continuous.cfg index 8523c22..3d17767 100644 --- a/libs/protobuf/kokoro/linux/csharp/continuous.cfg +++ b/libs/protobuf/kokoro/linux/csharp/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/csharp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/csharp/presubmit.cfg b/libs/protobuf/kokoro/linux/csharp/presubmit.cfg index 8523c22..3d17767 100644 --- a/libs/protobuf/kokoro/linux/csharp/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/csharp/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/csharp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/csharp_aarch64/common.cfg b/libs/protobuf/kokoro/linux/csharp_aarch64/common.cfg deleted file mode 100644 index df28ef3..0000000 --- a/libs/protobuf/kokoro/linux/csharp_aarch64/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/csharp_aarch64/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/csharp_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/csharp_aarch64/continuous.cfg index 8523c22..df28ef3 100644 --- a/libs/protobuf/kokoro/linux/csharp_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/csharp_aarch64/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/csharp_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/csharp_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/csharp_aarch64/presubmit.cfg index 8523c22..df28ef3 100644 --- a/libs/protobuf/kokoro/linux/csharp_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/csharp_aarch64/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/csharp_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/dist_install/build.sh b/libs/protobuf/kokoro/linux/dist_install/build.sh new file mode 100755 index 0000000..c456ee8 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dist_install/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Build file to set up and run tests + +set -ex # exit immediately on error + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="dist_install" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/dist_install/continuous.cfg b/libs/protobuf/kokoro/linux/dist_install/continuous.cfg new file mode 100644 index 0000000..b1e0b20 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dist_install/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/dist_install/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/dist_install/presubmit.cfg b/libs/protobuf/kokoro/linux/dist_install/presubmit.cfg new file mode 100644 index 0000000..b1e0b20 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dist_install/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/dist_install/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/linux/dockerfile/push_testing_images.sh b/libs/protobuf/kokoro/linux/dockerfile/push_testing_images.sh new file mode 100755 index 0000000..2d82bab --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/push_testing_images.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -ex + +cd $(dirname $0)/../../.. +git_root=$(pwd) +cd kokoro/linux/dockerfile + +DOCKERHUB_ORGANIZATION=protobuftesting + +for DOCKERFILE_DIR in test/* +do + # Generate image name based on Dockerfile checksum. That works well as long + # as can count on dockerfiles being written in a way that changing the logical + # contents of the docker image always changes the SHA (e.g. using "ADD file" + # cmd in the dockerfile in not ok as contents of the added file will not be + # reflected in the SHA). + DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) + + echo $DOCKER_IMAGE_NAME + # skip the image if it already exists in the repo + curl --silent -f -lSL https://registry.hub.docker.com/v2/repositories/${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME}/tags/latest > /dev/null \ + && continue + + docker build -t ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} ${DOCKERFILE_DIR} + + # "docker login" needs to be run in advance + docker push ${DOCKERHUB_ORGANIZATION}/${DOCKER_IMAGE_NAME} +done diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile new file mode 100644 index 0000000..0ce9982 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/cpp_tcmalloc/Dockerfile @@ -0,0 +1,29 @@ +FROM debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Install dependencies for TC malloc +RUN apt-get install -y \ + google-perftools \ + libgoogle-perftools4 \ + libgoogle-perftools-dev diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/csharp/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/csharp/Dockerfile new file mode 100644 index 0000000..c07fcbc --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/csharp/Dockerfile @@ -0,0 +1,41 @@ +FROM debian:buster + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean + +# Update ca-certificates to fix known buster + .NET 5 issue +# https://github.com/NuGet/Announcements/issues/49 +RUN apt-get update && apt-get install -y ca-certificates && apt-get clean + +# dotnet SDK prerequisites +RUN apt-get update && apt-get install -y libunwind8 libicu63 && apt-get clean + +# Install dotnet SDK via install script +RUN wget -q https://dot.net/v1/dotnet-install.sh && \ + chmod u+x dotnet-install.sh && \ + ./dotnet-install.sh --version 3.1.415 && \ + ./dotnet-install.sh --version 6.0.100 && \ + ln -s /root/.dotnet/dotnet /usr/local/bin + +RUN wget -q www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe + +ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE true diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/java_stretch/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/java_stretch/Dockerfile new file mode 100644 index 0000000..0716927 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/java_stretch/Dockerfile @@ -0,0 +1,39 @@ +# Despite the name of this image, we are no longer on stretch. +# We should consider renaming this image, and/or evaluating what +# software versions we actually need. +FROM debian:bullseye + +# Install dependencies. We start with the basic ones required to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + cmake \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + pkg-config \ + time \ + wget \ + # Java dependencies + maven \ + openjdk-11-jdk \ + openjdk-17-jdk \ + # Required for the gtest build. + python2 \ + # Python dependencies + python3-dev \ + python3-setuptools \ + python3-pip \ + python3-venv \ + && apt-get clean diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/php/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/php/Dockerfile new file mode 100644 index 0000000..4c9d69d --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/php/Dockerfile @@ -0,0 +1,255 @@ +FROM debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + re2c \ + sqlite3 \ + libsqlite3-dev \ + && apt-get clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + php5 \ + libcurl4-openssl-dev \ + libgmp-dev \ + libgmp3-dev \ + libssl-dev \ + libxml2-dev \ + unzip \ + zlib1g-dev \ + pkg-config \ + && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download php source code +RUN git clone https://github.com/php/php-src + +# php 5.6 +RUN cd php-src \ + && git checkout PHP-5.6.39 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6 \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-5.phar \ + && chmod +x phpunit \ + && mv phpunit /usr/local/php-5.6/bin + +# php 7.0 +RUN cd php-src \ + && git checkout PHP-7.0.33 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-6.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.0/bin \ + && mv phpunit /usr/local/php-7.0-zts/bin + +# php 7.1 +RUN cd php-src \ + && git checkout PHP-7.1.25 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.1/bin \ + && mv phpunit /usr/local/php-7.1-zts/bin + +# php 7.2 +RUN cd php-src \ + && git checkout PHP-7.2.13 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.2/bin \ + && mv phpunit /usr/local/php-7.2-zts/bin + +# php 7.3 +RUN cd php-src \ + && git checkout PHP-7.3.0 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.3/bin \ + && mv phpunit /usr/local/php-7.3-zts/bin + +# php 7.4 +RUN wget https://ftp.gnu.org/gnu/bison/bison-3.0.1.tar.gz -O /var/local/bison-3.0.1.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-3.0.1.tar.gz \ + && cd /var/local/bison-3.0.1 \ + && ./configure \ + && make \ + && make install + +RUN wget https://github.com/php/php-src/archive/php-7.4.0.tar.gz -O /var/local/php-7.4.0.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.4.0.tar.gz + +RUN cd /var/local/php-src-php-7.4.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --disable-mbregex \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.4 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.4.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --disable-mbregex \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.4-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-8.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.4/bin \ + && mv phpunit /usr/local/php-7.4-zts/bin + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + valgrind \ + && apt-get clean diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/php80/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/php80/Dockerfile new file mode 100644 index 0000000..5b382d0 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/php80/Dockerfile @@ -0,0 +1,124 @@ +FROM debian:stretch + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + re2c \ + sqlite3 \ + vim \ + libonig-dev \ + libsqlite3-dev \ + && apt-get clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + php \ + libcurl4-openssl-dev \ + libgmp-dev \ + libgmp3-dev \ + libssl-dev \ + libxml2-dev \ + unzip \ + zlib1g-dev \ + pkg-config \ + && apt-get clean + +# Install other dependencies +RUN ln -sf /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h +RUN wget https://ftp.gnu.org/gnu/bison/bison-3.0.1.tar.gz -O /var/local/bison-3.0.1.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-3.0.1.tar.gz \ + && cd /var/local/bison-3.0.1 \ + && ./configure \ + && make \ + && make install + +# Install composer +RUN curl -sS https://getcomposer.org/installer | php +RUN mv composer.phar /usr/local/bin/composer + +# Download php source code +RUN git clone https://github.com/php/php-src + +# php 8.0 +RUN cd php-src \ + && git checkout php-8.0.0 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.0 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.0-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-8.0/bin \ + && mv phpunit /usr/local/php-8.0-zts/bin + +# php 8.1 +RUN cd php-src \ + && git checkout php-8.1.2 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1 \ + && make \ + && make install \ + && make clean +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --enable-maintainer-zts \ + --with-gmp \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-8.1-zts \ + && make \ + && make install \ + && make clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + valgrind \ + && apt-get clean diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/php_32bit/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/php_32bit/Dockerfile new file mode 100644 index 0000000..2fd620e --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/php_32bit/Dockerfile @@ -0,0 +1,260 @@ +FROM i386/debian:jessie + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + re2c \ + sqlite3 \ + libsqlite3-dev \ + && apt-get clean + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + bison \ + php5 \ + libcurl4-openssl-dev \ + libssl-dev \ + libxml2-dev \ + unzip \ + zlib1g-dev \ + pkg-config \ + && apt-get clean + +# Install other dependencies +RUN wget http://ftp.gnu.org/gnu/bison/bison-2.6.4.tar.gz -O /var/local/bison-2.6.4.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-2.6.4.tar.gz \ + && cd /var/local/bison-2.6.4 \ + && ./configure \ + && make \ + && make install + +# Install composer +RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +RUN php composer-setup.php +RUN mv composer.phar /usr/bin/composer +RUN php -r "unlink('composer-setup.php');" + +# Download php source code +RUN git clone https://github.com/php/php-src + +# php 5.6 +RUN cd php-src \ + && git checkout PHP-5.6.39 \ + && ./buildconf --force +RUN cd php-src \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-5.6 \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-5.phar \ + && chmod +x phpunit \ + && mv phpunit /usr/local/php-5.6/bin + +# php 7.0 +RUN wget https://github.com/php/php-src/archive/php-7.0.33.tar.gz -O /var/local/php-7.0.33.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.0.33.tar.gz + +RUN cd /var/local/php-src-php-7.0.33 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.0.33 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.0-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-6.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.0/bin \ + && mv phpunit /usr/local/php-7.0-zts/bin + +# php 7.1 +RUN wget https://github.com/php/php-src/archive/php-7.1.25.tar.gz -O /var/local/php-7.1.25.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.1.25.tar.gz + +RUN cd /var/local/php-src-php-7.1.25 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.1.25 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.1-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.1/bin \ + && mv phpunit /usr/local/php-7.1-zts/bin + +# php 7.2 +RUN wget https://github.com/php/php-src/archive/php-7.2.13.tar.gz -O /var/local/php-7.2.13.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.2.13.tar.gz + +RUN cd /var/local/php-src-php-7.2.13 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.2.13 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.2-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.2/bin \ + && mv phpunit /usr/local/php-7.2-zts/bin + +# php 7.3 +RUN wget https://github.com/php/php-src/archive/php-7.3.0.tar.gz -O /var/local/php-7.3.0.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.3.0.tar.gz + +RUN cd /var/local/php-src-php-7.3.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.3.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.3-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-7.5.0.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.3/bin \ + && mv phpunit /usr/local/php-7.3-zts/bin + +# php 7.4 +RUN wget https://ftp.gnu.org/gnu/bison/bison-3.0.1.tar.gz -O /var/local/bison-3.0.1.tar.gz +RUN cd /var/local \ + && tar -zxvf bison-3.0.1.tar.gz \ + && cd /var/local/bison-3.0.1 \ + && ./configure \ + && make \ + && make install + +RUN wget https://github.com/php/php-src/archive/php-7.4.0.tar.gz -O /var/local/php-7.4.0.tar.gz + +RUN cd /var/local \ + && tar -zxvf php-7.4.0.tar.gz + +RUN cd /var/local/php-src-php-7.4.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-bcmath \ + --enable-mbstring \ + --disable-mbregex \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.4 \ + && make \ + && make install \ + && make clean +RUN cd /var/local/php-src-php-7.4.0 \ + && ./buildconf --force \ + && ./configure \ + --enable-maintainer-zts \ + --enable-mbstring \ + --disable-mbregex \ + --with-openssl \ + --with-zlib \ + --prefix=/usr/local/php-7.4-zts \ + && make \ + && make install \ + && make clean + +RUN wget -O phpunit https://phar.phpunit.de/phpunit-8.phar \ + && chmod +x phpunit \ + && cp phpunit /usr/local/php-7.4/bin \ + && mv phpunit /usr/local/php-7.4-zts/bin + +# Install php dependencies +RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ + valgrind \ + && apt-get clean diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/python310/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/python310/Dockerfile new file mode 100644 index 0000000..e16e93b --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/python310/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.10-buster + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python libraries. +RUN python -m pip install --no-cache-dir --upgrade \ + pip \ + setuptools \ + tox \ + wheel diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/python37/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/python37/Dockerfile new file mode 100644 index 0000000..ee108dd --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/python37/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.7-buster + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python libraries. +RUN python -m pip install --no-cache-dir --upgrade \ + pip \ + setuptools \ + tox \ + wheel diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/python38/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/python38/Dockerfile new file mode 100644 index 0000000..56efc9d --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/python38/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.8-buster + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python libraries. +RUN python -m pip install --no-cache-dir --upgrade \ + pip \ + setuptools \ + tox \ + wheel diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/python39/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/python39/Dockerfile new file mode 100644 index 0000000..ee7554d --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/python39/Dockerfile @@ -0,0 +1,31 @@ +FROM python:3.9-buster + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Python libraries. +RUN python -m pip install --no-cache-dir --upgrade \ + pip \ + setuptools \ + tox \ + wheel diff --git a/libs/protobuf/kokoro/linux/dockerfile/test/ruby/Dockerfile b/libs/protobuf/kokoro/linux/dockerfile/test/ruby/Dockerfile new file mode 100644 index 0000000..0e34fe5 --- /dev/null +++ b/libs/protobuf/kokoro/linux/dockerfile/test/ruby/Dockerfile @@ -0,0 +1,44 @@ +FROM debian:stretch + +# Install dependencies. We start with the basic ones require to build protoc +# and the C++ build +RUN apt-get update && apt-get install -y \ + autoconf \ + autotools-dev \ + build-essential \ + bzip2 \ + ccache \ + curl \ + gcc \ + git \ + libc6 \ + libc6-dbg \ + libc6-dev \ + libgtest-dev \ + libtool \ + make \ + parallel \ + time \ + wget \ + # Java dependencies + maven \ + openjdk-8-jdk \ + && apt-get clean + +# Install rvm +RUN gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys \ + 409B6B1796C275462A1703113804BB82D39DC0E3 \ + 7D2BAF1CF37B13E2069D6956105BD0E739499BDB +RUN \curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master + +RUN /bin/bash -l -c "rvm install 2.5.1" +RUN /bin/bash -l -c "rvm install 2.6.0" +RUN /bin/bash -l -c "rvm install 2.7.0" +RUN /bin/bash -l -c "rvm install 3.0.0" +RUN /bin/bash -l -c "rvm install 3.1.0" +RUN /bin/bash -l -c "rvm install jruby-9.2.20.1" +RUN /bin/bash -l -c "rvm install jruby-9.3.3.0" +RUN /bin/bash -l -c "rvm install jruby-9.3.4.0" + +RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" +RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" diff --git a/libs/protobuf/kokoro/linux/java_aarch64/build.sh b/libs/protobuf/kokoro/linux/java_aarch64/build.sh new file mode 100755 index 0000000..ed5ad53 --- /dev/null +++ b/libs/protobuf/kokoro/linux/java_aarch64/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "continuous" and "presubmit" jobs. + +set -ex + +# Change to repo root +cd $(dirname $0)/../../.. + +# Initialize any submodules. +git submodule update --init --recursive + +kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh + +kokoro/linux/aarch64/test_java_aarch64.sh diff --git a/libs/protobuf/kokoro/linux/java_aarch64/common.cfg b/libs/protobuf/kokoro/linux/java_aarch64/common.cfg deleted file mode 100644 index 75e3f0b..0000000 --- a/libs/protobuf/kokoro/linux/java_aarch64/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/emulation/linux:aarch64-4e847d7a01c1792471b6dd985ab0bf2677332e6f" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//java/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/java_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/java_aarch64/continuous.cfg index 8523c22..5db46d4 100644 --- a/libs/protobuf/kokoro/linux/java_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/java_aarch64/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/java_aarch64/presubmit.cfg index 8523c22..5db46d4 100644 --- a/libs/protobuf/kokoro/linux/java_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/java_aarch64/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_jdk11/build.sh b/libs/protobuf/kokoro/linux/java_jdk11/build.sh new file mode 100755 index 0000000..d73aa7c --- /dev/null +++ b/libs/protobuf/kokoro/linux/java_jdk11/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# fail on error +set -e + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +# The image of the Dockerfile sha1 is fetched from the organization +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="java_jdk11" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/java_jdk11/common.cfg b/libs/protobuf/kokoro/linux/java_jdk11/common.cfg deleted file mode 100644 index 3db5cd0..0000000 --- a/libs/protobuf/kokoro/linux/java_jdk11/common.cfg +++ /dev/null @@ -1,16 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "BAZEL_TARGETS" - value: "//java/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/java_jdk11/continuous.cfg b/libs/protobuf/kokoro/linux/java_jdk11/continuous.cfg index 8523c22..f8af54d 100644 --- a/libs/protobuf/kokoro/linux/java_jdk11/continuous.cfg +++ b/libs/protobuf/kokoro/linux/java_jdk11/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk11/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_jdk11/presubmit.cfg b/libs/protobuf/kokoro/linux/java_jdk11/presubmit.cfg index 8523c22..366048c 100644 --- a/libs/protobuf/kokoro/linux/java_jdk11/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/java_jdk11/presubmit.cfg @@ -1 +1,12 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running Linkage Monitor in Kokoro +# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk11/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_jdk17/build.sh b/libs/protobuf/kokoro/linux/java_jdk17/build.sh new file mode 100755 index 0000000..677245a --- /dev/null +++ b/libs/protobuf/kokoro/linux/java_jdk17/build.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Fail on error +set -e + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +# The image of the Dockerfile sha1 is fetched from the organization +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="java_jdk17" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/java_jdk17/common.cfg b/libs/protobuf/kokoro/linux/java_jdk17/common.cfg deleted file mode 100644 index cd31eda..0000000 --- a/libs/protobuf/kokoro/linux/java_jdk17/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/java/linux:17-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//java/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/java_jdk17/continuous.cfg b/libs/protobuf/kokoro/linux/java_jdk17/continuous.cfg index 8523c22..6bac25c 100644 --- a/libs/protobuf/kokoro/linux/java_jdk17/continuous.cfg +++ b/libs/protobuf/kokoro/linux/java_jdk17/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk17/build.sh" +timeout_mins: 60 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_jdk17/presubmit.cfg b/libs/protobuf/kokoro/linux/java_jdk17/presubmit.cfg index 8523c22..ee80517 100644 --- a/libs/protobuf/kokoro/linux/java_jdk17/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/java_jdk17/presubmit.cfg @@ -1 +1,12 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running Linkage Monitor in Kokoro +# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk17/build.sh" +timeout_mins: 60 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_linkage_monitor/build.sh b/libs/protobuf/kokoro/linux/java_linkage_monitor/build.sh index 7d4d7b7..c447453 100755 --- a/libs/protobuf/kokoro/linux/java_linkage_monitor/build.sh +++ b/libs/protobuf/kokoro/linux/java_linkage_monitor/build.sh @@ -4,24 +4,16 @@ # running the "pull request" project: # # This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. - -use_bazel.sh 4.2.2 +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. # Change to repo root cd $(dirname $0)/../../.. -bazel build //:protoc - -# The java build setup expects protoc in the root directory. -cp bazel-bin/protoc . - -cd java -# Installs the snapshot version locally -mvn -e -B -Dhttps.protocols=TLSv1.2 install -Dmaven.test.skip=true - -# Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility -JAR=linkage-monitor-latest-all-deps.jar -curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}" -# Fails if there's new linkage errors compared with baseline -java -jar $JAR com.google.cloud:libraries-bom +export DOCKERHUB_ORGANIZATION=protobuftesting +# The image of the Dockerfile sha1 is fetched from the organization +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="java_linkage_monitor" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/java_linkage_monitor/common.cfg b/libs/protobuf/kokoro/linux/java_linkage_monitor/common.cfg deleted file mode 100644 index c02a52f..0000000 --- a/libs/protobuf/kokoro/linux/java_linkage_monitor/common.cfg +++ /dev/null @@ -1,12 +0,0 @@ -# Config file for running Linkage Monitor in Kokoro -# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/java_linkage_monitor/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/java_linkage_monitor/continuous.cfg b/libs/protobuf/kokoro/linux/java_linkage_monitor/continuous.cfg index 8523c22..d0486cc 100644 --- a/libs/protobuf/kokoro/linux/java_linkage_monitor/continuous.cfg +++ b/libs/protobuf/kokoro/linux/java_linkage_monitor/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_linkage_monitor/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/java_linkage_monitor/presubmit.cfg b/libs/protobuf/kokoro/linux/java_linkage_monitor/presubmit.cfg index 8523c22..c02a52f 100644 --- a/libs/protobuf/kokoro/linux/java_linkage_monitor/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/java_linkage_monitor/presubmit.cfg @@ -1 +1,12 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running Linkage Monitor in Kokoro +# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_linkage_monitor/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/jruby92/build.sh b/libs/protobuf/kokoro/linux/jruby92/build.sh new file mode 100755 index 0000000..5820115 --- /dev/null +++ b/libs/protobuf/kokoro/linux/jruby92/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="jruby92" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/jruby92/common.cfg b/libs/protobuf/kokoro/linux/jruby92/common.cfg deleted file mode 100644 index 9db8f50..0000000 --- a/libs/protobuf/kokoro/linux/jruby92/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:jruby-9.2.20.1-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=java" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/jruby92/continuous.cfg b/libs/protobuf/kokoro/linux/jruby92/continuous.cfg index 8523c22..3339584 100644 --- a/libs/protobuf/kokoro/linux/jruby92/continuous.cfg +++ b/libs/protobuf/kokoro/linux/jruby92/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/jruby92/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/jruby92/presubmit.cfg b/libs/protobuf/kokoro/linux/jruby92/presubmit.cfg index 8523c22..3339584 100644 --- a/libs/protobuf/kokoro/linux/jruby92/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/jruby92/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/jruby92/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/jruby93/build.sh b/libs/protobuf/kokoro/linux/jruby93/build.sh new file mode 100755 index 0000000..24c54d0 --- /dev/null +++ b/libs/protobuf/kokoro/linux/jruby93/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="jruby93" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/jruby93/common.cfg b/libs/protobuf/kokoro/linux/jruby93/common.cfg deleted file mode 100644 index a5a9bd2..0000000 --- a/libs/protobuf/kokoro/linux/jruby93/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:jruby-9.3.4.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=java" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/jruby93/continuous.cfg b/libs/protobuf/kokoro/linux/jruby93/continuous.cfg index 8523c22..706d848 100644 --- a/libs/protobuf/kokoro/linux/jruby93/continuous.cfg +++ b/libs/protobuf/kokoro/linux/jruby93/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/jruby93/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/jruby93/presubmit.cfg b/libs/protobuf/kokoro/linux/jruby93/presubmit.cfg index 8523c22..706d848 100644 --- a/libs/protobuf/kokoro/linux/jruby93/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/jruby93/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/jruby93/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/make_test_output.py b/libs/protobuf/kokoro/linux/make_test_output.py new file mode 100644 index 0000000..9853685 --- /dev/null +++ b/libs/protobuf/kokoro/linux/make_test_output.py @@ -0,0 +1,94 @@ +"""Gathers output from test runs and create an XML file in JUnit format. + +The output files from the individual tests have been written in a directory +structure like: + + $DIR/joblog (output from "parallel --joblog joblog") + $DIR/logs/1/cpp/stdout + $DIR/logs/1/cpp/stderr + $DIR/logs/1/csharp/stdout + $DIR/logs/1/csharp/stderr + $DIR/logs/1/java_jdk7/stdout + $DIR/logs/1/java_jdk7/stderr + etc. + +This script bundles them into a single output XML file so Jenkins can show +detailed test results. It runs as the last step before the Jenkins build +finishes. +""" + +import os +import sys +from yattag import Doc +from collections import defaultdict + + +def readtests(basedir): + tests = defaultdict(dict) + + # Sample input (note: separators are tabs). + # + # Seq Host Starttime Runtime Send Receive Exitval Signal Command + # 1 : 1456263838.313 0.005 0 0 0 0 echo A + with open(basedir + "/joblog") as jobs: + firstline = next(jobs) + for line in jobs: + values = line.split("\t") + + name = values[8].split()[-1] + test = tests[name] + test["name"] = name + test["time"] = values[3] + + exitval = values[6] + if int(exitval): + # We don't have a more specific message. User should look at stderr. + test["failure"] = "TEST FAILURE" + else: + test["failure"] = False + + for testname in os.listdir(basedir + "/logs/1"): + test = tests[testname] + + with open(basedir + "/logs/1/" + testname + "/stdout") as f: + test["stdout"] = f.read() + + with open(basedir + "/logs/1/" + testname + "/stderr") as f: + test["stderr"] = f.read() + + # The cpp test is special since it doesn't run under parallel so doesn't show + # up in the job log. + tests["cpp"]["name"] = "cpp" + + with open(basedir + '/logs/1/cpp/build_time', 'r') as f: + tests["cpp"]["time"] = f.read().strip() + tests["cpp"]["failure"] = False + + ret = tests.values() + ret.sort(key=lambda x: x["name"]) + + return ret + + +def genxml(tests): + doc, tag, text = Doc().tagtext() + + with tag("testsuites"): + with tag("testsuite", name="Protobuf Tests"): + for test in tests: + with tag("testcase", name=test["name"], classname=test["name"], + time=test["time"]): + with tag("system-out"): + text(test["stdout"]) + with tag("system-err"): + text(test["stderr"]) + if test["failure"]: + with tag("failure"): + text(test["failure"]) + + return doc.getvalue() + + +sys.stderr.write("make_test_output.py: writing XML from directory: " + + sys.argv[1] + "\n") +print(genxml(readtests(sys.argv[1]))) diff --git a/libs/protobuf/kokoro/linux/php_aarch64/common.cfg b/libs/protobuf/kokoro/linux/php_aarch64/common.cfg deleted file mode 100644 index ff20682..0000000 --- a/libs/protobuf/kokoro/linux/php_aarch64/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/php_aarch64/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/php_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/php_aarch64/continuous.cfg index 8523c22..ff20682 100644 --- a/libs/protobuf/kokoro/linux/php_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/php_aarch64/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/php_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/php_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/php_aarch64/presubmit.cfg index 8523c22..ff20682 100644 --- a/libs/protobuf/kokoro/linux/php_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/php_aarch64/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/php_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/php_all/build.sh b/libs/protobuf/kokoro/linux/php_all/build.sh index bfad04c..cfcab00 100755 --- a/libs/protobuf/kokoro/linux/php_all/build.sh +++ b/libs/protobuf/kokoro/linux/php_all/build.sh @@ -8,16 +8,16 @@ set -ex # Change to repo base. cd $(dirname $0)/../../.. -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test_valgrind" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test_valgrind" -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.0.33-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test && composer test_c" -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.3.28-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test && composer test_c" -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.4.18-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test && composer test_c" -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test && composer test_c" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.0.33-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test && composer test_c" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.3.28-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test && composer test_c" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:7.4.18-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test && composer test_c" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test && composer test_c" # Run specialized memory leak & multirequest tests. -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test_c && tests/multirequest.sh && tests/memory_leak_test.sh" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test_c && tests/multirequest.sh && tests/memory_leak_test.sh" # Most of our tests use a debug build of PHP, but we do one build against an opt # php just in case that surfaces anything unexpected. -docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-fd99596d4c4c9b78f984ee667a9b26b91a28eb8d "composer test && composer test_c" +docker run $(test -t 0 && echo "-it") -v$PWD:/workspace gcr.io/protobuf-build/php/linux:8.0.5-14a06550010c0649bf69b6c9b803c1ca609bbb6d "composer test && composer test_c" diff --git a/libs/protobuf/kokoro/linux/php_all/continuous.cfg b/libs/protobuf/kokoro/linux/php_all/continuous.cfg index 8523c22..dfa8037 100644 --- a/libs/protobuf/kokoro/linux/php_all/continuous.cfg +++ b/libs/protobuf/kokoro/linux/php_all/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/php_all/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/php_all/presubmit.cfg b/libs/protobuf/kokoro/linux/php_all/presubmit.cfg index 8523c22..dfa8037 100644 --- a/libs/protobuf/kokoro/linux/php_all/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/php_all/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/php_all/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/pull_request_in_docker.sh b/libs/protobuf/kokoro/linux/pull_request_in_docker.sh new file mode 100755 index 0000000..a048c47 --- /dev/null +++ b/libs/protobuf/kokoro/linux/pull_request_in_docker.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# This is the script that runs inside Docker, once the image has been built, +# to execute all tests for the "pull request" project. + +WORKSPACE_BASE=`pwd` +MY_DIR="$(dirname "$0")" +TEST_SCRIPT=./tests.sh +BUILD_DIR=/tmp/protobuf + +set -e # exit immediately on error +set -x # display all commands + +# The protobuf repository is mounted into our Docker image, but read-only. +# We clone into a directory inside Docker (this is faster than cp). +rm -rf $BUILD_DIR +mkdir -p $BUILD_DIR +cd $BUILD_DIR +git clone /var/local/kokoro/protobuf +cd protobuf + +# Initialize any submodules: +git submodule update --init --recursive + +$TEST_SCRIPT $TEST_SET diff --git a/libs/protobuf/kokoro/linux/python310/build.sh b/libs/protobuf/kokoro/linux/python310/build.sh new file mode 100755 index 0000000..0d8a2c9 --- /dev/null +++ b/libs/protobuf/kokoro/linux/python310/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python310 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python310" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python310/common.cfg b/libs/protobuf/kokoro/linux/python310/common.cfg deleted file mode 100644 index 7e4a798..0000000 --- a/libs/protobuf/kokoro/linux/python310/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.10-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//python/... @upb//python/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python310/continuous.cfg b/libs/protobuf/kokoro/linux/python310/continuous.cfg index 8523c22..6ec74d8 100644 --- a/libs/protobuf/kokoro/linux/python310/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python310/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python310/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python310/presubmit.cfg b/libs/protobuf/kokoro/linux/python310/presubmit.cfg index 8523c22..6ec74d8 100644 --- a/libs/protobuf/kokoro/linux/python310/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python310/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python310/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python310_cpp/build.sh b/libs/protobuf/kokoro/linux/python310_cpp/build.sh new file mode 100755 index 0000000..2903a2d --- /dev/null +++ b/libs/protobuf/kokoro/linux/python310_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python310 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python310_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python310_cpp/common.cfg b/libs/protobuf/kokoro/linux/python310_cpp/common.cfg deleted file mode 100644 index 5b87fd6..0000000 --- a/libs/protobuf/kokoro/linux/python310_cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.10-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - # Note: upb tests don't work since the C++ extension takes precedence here. - value: "//python/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=use_fast_cpp_protos=true" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python310_cpp/continuous.cfg b/libs/protobuf/kokoro/linux/python310_cpp/continuous.cfg index 8523c22..7ec8441 100644 --- a/libs/protobuf/kokoro/linux/python310_cpp/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python310_cpp/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python310_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python310_cpp/presubmit.cfg b/libs/protobuf/kokoro/linux/python310_cpp/presubmit.cfg index 8523c22..7ec8441 100644 --- a/libs/protobuf/kokoro/linux/python310_cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python310_cpp/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python310_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python37/build.sh b/libs/protobuf/kokoro/linux/python37/build.sh new file mode 100755 index 0000000..2117a27 --- /dev/null +++ b/libs/protobuf/kokoro/linux/python37/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python37 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python37" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python37/common.cfg b/libs/protobuf/kokoro/linux/python37/common.cfg deleted file mode 100644 index 3ae100c..0000000 --- a/libs/protobuf/kokoro/linux/python37/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.7-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//python/... @upb//python/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python37/continuous.cfg b/libs/protobuf/kokoro/linux/python37/continuous.cfg index 8523c22..9fa20c1 100644 --- a/libs/protobuf/kokoro/linux/python37/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python37/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python37/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python37/presubmit.cfg b/libs/protobuf/kokoro/linux/python37/presubmit.cfg index 8523c22..9fa20c1 100644 --- a/libs/protobuf/kokoro/linux/python37/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python37/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python37/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python37_cpp/build.sh b/libs/protobuf/kokoro/linux/python37_cpp/build.sh new file mode 100755 index 0000000..3126b48 --- /dev/null +++ b/libs/protobuf/kokoro/linux/python37_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python37 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python37_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python37_cpp/common.cfg b/libs/protobuf/kokoro/linux/python37_cpp/common.cfg deleted file mode 100644 index ebef928..0000000 --- a/libs/protobuf/kokoro/linux/python37_cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.7-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - # Note: upb tests don't work since the C++ extension takes precedence here. - value: "//python/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=use_fast_cpp_protos=true" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python37_cpp/continuous.cfg b/libs/protobuf/kokoro/linux/python37_cpp/continuous.cfg index 8523c22..49c441f 100644 --- a/libs/protobuf/kokoro/linux/python37_cpp/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python37_cpp/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python37_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python37_cpp/presubmit.cfg b/libs/protobuf/kokoro/linux/python37_cpp/presubmit.cfg index 8523c22..49c441f 100644 --- a/libs/protobuf/kokoro/linux/python37_cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python37_cpp/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python37_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python38/build.sh b/libs/protobuf/kokoro/linux/python38/build.sh new file mode 100755 index 0000000..299c7ba --- /dev/null +++ b/libs/protobuf/kokoro/linux/python38/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python38 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python38" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python38/common.cfg b/libs/protobuf/kokoro/linux/python38/common.cfg deleted file mode 100644 index 7d9e7aa..0000000 --- a/libs/protobuf/kokoro/linux/python38/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.8-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//python/... @upb//python/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python38/continuous.cfg b/libs/protobuf/kokoro/linux/python38/continuous.cfg index 8523c22..76425d2 100644 --- a/libs/protobuf/kokoro/linux/python38/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python38/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python38/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python38/presubmit.cfg b/libs/protobuf/kokoro/linux/python38/presubmit.cfg index 8523c22..76425d2 100644 --- a/libs/protobuf/kokoro/linux/python38/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python38/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python38/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python38_cpp/build.sh b/libs/protobuf/kokoro/linux/python38_cpp/build.sh new file mode 100755 index 0000000..b43859b --- /dev/null +++ b/libs/protobuf/kokoro/linux/python38_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python38 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python38_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python38_cpp/common.cfg b/libs/protobuf/kokoro/linux/python38_cpp/common.cfg deleted file mode 100644 index decd466..0000000 --- a/libs/protobuf/kokoro/linux/python38_cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.8-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - # Note: upb tests don't work since the C++ extension takes precedence here. - value: "//python/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=use_fast_cpp_protos=true" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python38_cpp/continuous.cfg b/libs/protobuf/kokoro/linux/python38_cpp/continuous.cfg index 8523c22..1e8888c 100644 --- a/libs/protobuf/kokoro/linux/python38_cpp/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python38_cpp/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python38_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python38_cpp/presubmit.cfg b/libs/protobuf/kokoro/linux/python38_cpp/presubmit.cfg index 8523c22..1e8888c 100644 --- a/libs/protobuf/kokoro/linux/python38_cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python38_cpp/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python38_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python39/build.sh b/libs/protobuf/kokoro/linux/python39/build.sh new file mode 100755 index 0000000..497dc66 --- /dev/null +++ b/libs/protobuf/kokoro/linux/python39/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python39 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python39" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python39/common.cfg b/libs/protobuf/kokoro/linux/python39/common.cfg deleted file mode 100644 index 5133ab5..0000000 --- a/libs/protobuf/kokoro/linux/python39/common.cfg +++ /dev/null @@ -1,21 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.9-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//python/... @upb//python/..." -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python39/continuous.cfg b/libs/protobuf/kokoro/linux/python39/continuous.cfg index 8523c22..b03bc90 100644 --- a/libs/protobuf/kokoro/linux/python39/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python39/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python39/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python39/presubmit.cfg b/libs/protobuf/kokoro/linux/python39/presubmit.cfg index 8523c22..b03bc90 100644 --- a/libs/protobuf/kokoro/linux/python39/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python39/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python39/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python39_cpp/build.sh b/libs/protobuf/kokoro/linux/python39_cpp/build.sh new file mode 100755 index 0000000..f45d2ec --- /dev/null +++ b/libs/protobuf/kokoro/linux/python39_cpp/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python39 +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="python39_cpp" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/python39_cpp/common.cfg b/libs/protobuf/kokoro/linux/python39_cpp/common.cfg deleted file mode 100644 index 9797008..0000000 --- a/libs/protobuf/kokoro/linux/python39_cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/python/linux:3.9-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - # Note: upb tests don't work since the C++ extension takes precedence here. - value: "//python/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=use_fast_cpp_protos=true" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/python39_cpp/continuous.cfg b/libs/protobuf/kokoro/linux/python39_cpp/continuous.cfg index 8523c22..dd84fbe 100644 --- a/libs/protobuf/kokoro/linux/python39_cpp/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python39_cpp/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python39_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python39_cpp/presubmit.cfg b/libs/protobuf/kokoro/linux/python39_cpp/presubmit.cfg index 8523c22..dd84fbe 100644 --- a/libs/protobuf/kokoro/linux/python39_cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python39_cpp/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python39_cpp/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python_aarch64/common.cfg b/libs/protobuf/kokoro/linux/python_aarch64/common.cfg deleted file mode 100644 index dee4a47..0000000 --- a/libs/protobuf/kokoro/linux/python_aarch64/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python_aarch64/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/python_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/python_aarch64/continuous.cfg index 8523c22..dee4a47 100644 --- a/libs/protobuf/kokoro/linux/python_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/python_aarch64/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/python_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/python_aarch64/presubmit.cfg index 8523c22..dee4a47 100644 --- a/libs/protobuf/kokoro/linux/python_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/python_aarch64/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/python_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby25/build.sh b/libs/protobuf/kokoro/linux/ruby25/build.sh new file mode 100755 index 0000000..1e82ec5 --- /dev/null +++ b/libs/protobuf/kokoro/linux/ruby25/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="ruby25" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/ruby25/common.cfg b/libs/protobuf/kokoro/linux/ruby25/common.cfg deleted file mode 100644 index ec975cd..0000000 --- a/libs/protobuf/kokoro/linux/ruby25/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:ruby-2.5.1-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=c" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby25/continuous.cfg b/libs/protobuf/kokoro/linux/ruby25/continuous.cfg index 8523c22..dee2db0 100644 --- a/libs/protobuf/kokoro/linux/ruby25/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby25/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby25/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby25/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby25/presubmit.cfg index 8523c22..dee2db0 100644 --- a/libs/protobuf/kokoro/linux/ruby25/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby25/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby25/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby26/build.sh b/libs/protobuf/kokoro/linux/ruby26/build.sh new file mode 100755 index 0000000..72d2d45 --- /dev/null +++ b/libs/protobuf/kokoro/linux/ruby26/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="ruby26" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/ruby26/common.cfg b/libs/protobuf/kokoro/linux/ruby26/common.cfg deleted file mode 100644 index d09a405..0000000 --- a/libs/protobuf/kokoro/linux/ruby26/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:ruby-2.6.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=c" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby26/continuous.cfg b/libs/protobuf/kokoro/linux/ruby26/continuous.cfg index 8523c22..4779065 100644 --- a/libs/protobuf/kokoro/linux/ruby26/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby26/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby26/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby26/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby26/presubmit.cfg index 8523c22..4779065 100644 --- a/libs/protobuf/kokoro/linux/ruby26/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby26/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby26/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby27/build.sh b/libs/protobuf/kokoro/linux/ruby27/build.sh new file mode 100755 index 0000000..c38ee36 --- /dev/null +++ b/libs/protobuf/kokoro/linux/ruby27/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="ruby27" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/ruby27/common.cfg b/libs/protobuf/kokoro/linux/ruby27/common.cfg deleted file mode 100644 index 51afa75..0000000 --- a/libs/protobuf/kokoro/linux/ruby27/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:ruby-2.7.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=c" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby27/continuous.cfg b/libs/protobuf/kokoro/linux/ruby27/continuous.cfg index 8523c22..9cce8c9 100644 --- a/libs/protobuf/kokoro/linux/ruby27/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby27/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby27/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby27/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby27/presubmit.cfg index 8523c22..9cce8c9 100644 --- a/libs/protobuf/kokoro/linux/ruby27/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby27/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby27/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby30/build.sh b/libs/protobuf/kokoro/linux/ruby30/build.sh new file mode 100755 index 0000000..9e44575 --- /dev/null +++ b/libs/protobuf/kokoro/linux/ruby30/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="ruby30" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/ruby30/common.cfg b/libs/protobuf/kokoro/linux/ruby30/common.cfg deleted file mode 100644 index 338505e..0000000 --- a/libs/protobuf/kokoro/linux/ruby30/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:ruby-3.0.2-2f706fd1ab49f4e97af769388be486069b63efee" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=c" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby30/continuous.cfg b/libs/protobuf/kokoro/linux/ruby30/continuous.cfg index 8523c22..b03a335 100644 --- a/libs/protobuf/kokoro/linux/ruby30/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby30/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby30/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby30/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby30/presubmit.cfg index 8523c22..b03a335 100644 --- a/libs/protobuf/kokoro/linux/ruby30/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby30/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby30/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby31/build.sh b/libs/protobuf/kokoro/linux/ruby31/build.sh new file mode 100644 index 0000000..c22bdae --- /dev/null +++ b/libs/protobuf/kokoro/linux/ruby31/build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This is the top-level script we give to Kokoro as the entry point for +# running the "pull request" project: +# +# This script selects a specific Dockerfile (for building a Docker image) and +# a script to run inside that image. Then we delegate to the general +# build_and_run_docker.sh script. + +# Change to repo root +cd $(dirname $0)/../../.. + +export DOCKERHUB_ORGANIZATION=protobuftesting +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/ruby +export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh +export OUTPUT_DIR=testoutput +export TEST_SET="ruby31" +./kokoro/linux/build_and_run_docker.sh diff --git a/libs/protobuf/kokoro/linux/ruby31/common.cfg b/libs/protobuf/kokoro/linux/ruby31/common.cfg deleted file mode 100644 index 588fe13..0000000 --- a/libs/protobuf/kokoro/linux/ruby31/common.cfg +++ /dev/null @@ -1,26 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 120 - -env_vars { - key: "CONTAINER_IMAGE" - value: "gcr.io/protobuf-build/ruby/linux:ruby-3.1.0-64e8944e4f18d7d6c9649112a8a93be57e693cd8" -} - -env_vars { - key: "BAZEL_TARGETS" - value: "//ruby/..." -} - -env_vars { - key: "BAZEL_EXTRA_FLAGS" - value: "--define=ruby_platform=c" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby31/continuous.cfg b/libs/protobuf/kokoro/linux/ruby31/continuous.cfg index 8523c22..0477912 100644 --- a/libs/protobuf/kokoro/linux/ruby31/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby31/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby31/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby31/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby31/presubmit.cfg index 8523c22..0477912 100644 --- a/libs/protobuf/kokoro/linux/ruby31/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby31/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby31/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby_aarch64/common.cfg b/libs/protobuf/kokoro/linux/ruby_aarch64/common.cfg deleted file mode 100644 index ae82696..0000000 --- a/libs/protobuf/kokoro/linux/ruby_aarch64/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/ruby_aarch64/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/linux/ruby_aarch64/continuous.cfg b/libs/protobuf/kokoro/linux/ruby_aarch64/continuous.cfg index 8523c22..ae82696 100644 --- a/libs/protobuf/kokoro/linux/ruby_aarch64/continuous.cfg +++ b/libs/protobuf/kokoro/linux/ruby_aarch64/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/ruby_aarch64/presubmit.cfg b/libs/protobuf/kokoro/linux/ruby_aarch64/presubmit.cfg index 8523c22..ae82696 100644 --- a/libs/protobuf/kokoro/linux/ruby_aarch64/presubmit.cfg +++ b/libs/protobuf/kokoro/linux/ruby_aarch64/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/ruby_aarch64/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/linux/staleness/release.cfg b/libs/protobuf/kokoro/linux/staleness/release.cfg deleted file mode 100644 index d109c50..0000000 --- a/libs/protobuf/kokoro/linux/staleness/release.cfg +++ /dev/null @@ -1,18 +0,0 @@ -# We run our staleness tests as release-type jobs only. They are not really -# part of the release process, but the release job type allows us to run the -# tests on a schedule only (not presubmit or postsubmit). - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/bazel.sh" -timeout_mins: 15 - -env_vars { - key: "BAZEL_TARGETS" - value: "//src:cmake_lists_staleness_test" -} - -action { - define_artifacts { - regex: "**/sponge_log.*" - } -} diff --git a/libs/protobuf/kokoro/macos-next/cpp/build.sh b/libs/protobuf/kokoro/macos-next/cpp/build.sh index 451c850..490e990 100755 --- a/libs/protobuf/kokoro/macos-next/cpp/build.sh +++ b/libs/protobuf/kokoro/macos-next/cpp/build.sh @@ -9,21 +9,47 @@ if [[ -h /tmpfs ]] && [[ ${PWD} == /tmpfs/src ]]; then cd /Volumes/BuildData/tmpfs/src fi -# Default environment variables used by cmake build: -: ${CMAKE_CONFIG_TYPE:=Debug} -export CMAKE_CONFIG_TYPE -: ${CTEST_PARALLEL_LEVEL:=4} -export CTEST_PARALLEL_LEVEL +# These vars can be changed when running manually, e.g.: +# +# % BUILD_CONFIG=RelWithDebInfo path/to/build.sh -# Run from the project root directory. -cd $(dirname $0)/../../.. +# By default, build using Debug config. +: ${BUILD_CONFIG:=Debug} + +# By default, find the sources based on this script path. +: ${SOURCE_DIR:=$(cd $(dirname $0)/../../..; pwd)} + +# By default, put outputs under /cmake/build. +: ${BUILD_DIR:=${SOURCE_DIR}/cmake/build} + +source ${SOURCE_DIR}/kokoro/caplog.sh # # Update submodules # -git submodule update --init --recursive +git -C "${SOURCE_DIR}" submodule update --init --recursive # -# Run build +# Configure and build in a separate directory # -kokoro/common/cmake.sh +mkdir -p "${BUILD_DIR}" + +caplog 01_configure \ + cmake -S "${SOURCE_DIR}" -B "${BUILD_DIR}" ${CAPLOG_CMAKE_ARGS:-} + +if [[ -n ${CAPLOG_DIR:-} ]]; then + mkdir -p "${CAPLOG_DIR}/CMakeFiles" + cp "${BUILD_DIR}"/CMakeFiles/CMake*.log "${CAPLOG_DIR}/CMakeFiles" +fi + +caplog 02_build \ + cmake --build "${BUILD_DIR}" --config "${BUILD_CONFIG}" + +# +# Run tests +# +( + cd "${BUILD_DIR}" + caplog 03_combined_testlog \ + ctest -C "${BUILD_CONFIG}" -j4 ${CAPLOG_CTEST_ARGS:-} +) diff --git a/libs/protobuf/kokoro/macos-next/cpp/common.cfg b/libs/protobuf/kokoro/macos-next/cpp/common.cfg deleted file mode 100644 index 166caa5..0000000 --- a/libs/protobuf/kokoro/macos-next/cpp/common.cfg +++ /dev/null @@ -1,13 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos-next/cpp/build.sh" -timeout_mins: 1440 - -# Upload logs -action: { - define_artifacts: { - regex: "**/*sponge_log.log" - regex: "**/*sponge_log.xml" - } -} diff --git a/libs/protobuf/kokoro/macos-next/cpp/continuous.cfg b/libs/protobuf/kokoro/macos-next/cpp/continuous.cfg index 8523c22..166caa5 100644 --- a/libs/protobuf/kokoro/macos-next/cpp/continuous.cfg +++ b/libs/protobuf/kokoro/macos-next/cpp/continuous.cfg @@ -1 +1,13 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos-next/cpp/build.sh" +timeout_mins: 1440 + +# Upload logs +action: { + define_artifacts: { + regex: "**/*sponge_log.log" + regex: "**/*sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/macos-next/cpp/presubmit.cfg b/libs/protobuf/kokoro/macos-next/cpp/presubmit.cfg index 8523c22..166caa5 100644 --- a/libs/protobuf/kokoro/macos-next/cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/macos-next/cpp/presubmit.cfg @@ -1 +1,13 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos-next/cpp/build.sh" +timeout_mins: 1440 + +# Upload logs +action: { + define_artifacts: { + regex: "**/*sponge_log.log" + regex: "**/*sponge_log.xml" + } +} diff --git a/libs/protobuf/kokoro/macos/cpp/build.sh b/libs/protobuf/kokoro/macos/cpp/build.sh index 9c3b8aa..bae2ebb 100755 --- a/libs/protobuf/kokoro/macos/cpp/build.sh +++ b/libs/protobuf/kokoro/macos/cpp/build.sh @@ -2,16 +2,10 @@ # # Build file to set up and run tests -set -eux -set -o pipefail - -# Run from the project root directory. +# Change to repo root cd $(dirname $0)/../../.. # Prepare worker environment to run tests source kokoro/macos/prepare_build_macos_rc -# -# Run build -# -bazel test $(kokoro/common/bazel_flags.sh) //src/... +./tests.sh cpp diff --git a/libs/protobuf/kokoro/macos/cpp/common.cfg b/libs/protobuf/kokoro/macos/cpp/common.cfg deleted file mode 100644 index 2651551..0000000 --- a/libs/protobuf/kokoro/macos/cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/cpp/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/cpp/continuous.cfg b/libs/protobuf/kokoro/macos/cpp/continuous.cfg index 8523c22..4bea1cb 100644 --- a/libs/protobuf/kokoro/macos/cpp/continuous.cfg +++ b/libs/protobuf/kokoro/macos/cpp/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/cpp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/cpp/presubmit.cfg b/libs/protobuf/kokoro/macos/cpp/presubmit.cfg index 8523c22..4bea1cb 100644 --- a/libs/protobuf/kokoro/macos/cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/cpp/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/cpp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/cpp_distcheck/build.sh b/libs/protobuf/kokoro/macos/cpp_distcheck/build.sh new file mode 100755 index 0000000..d729b63 --- /dev/null +++ b/libs/protobuf/kokoro/macos/cpp_distcheck/build.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# Build file to set up and run tests + +# Change to repo root +cd $(dirname $0)/../../.. + +# Prepare worker environment to run tests +source kokoro/macos/prepare_build_macos_rc + +./tests.sh cpp_distcheck diff --git a/libs/protobuf/kokoro/macos/cpp_distcheck/continuous.cfg b/libs/protobuf/kokoro/macos/cpp_distcheck/continuous.cfg new file mode 100644 index 0000000..89441bc --- /dev/null +++ b/libs/protobuf/kokoro/macos/cpp_distcheck/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/cpp_distcheck/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/cpp_distcheck/presubmit.cfg b/libs/protobuf/kokoro/macos/cpp_distcheck/presubmit.cfg new file mode 100644 index 0000000..89441bc --- /dev/null +++ b/libs/protobuf/kokoro/macos/cpp_distcheck/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/cpp_distcheck/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_debug/build.sh b/libs/protobuf/kokoro/macos/objectivec_ios_debug/build.sh index 77b704f..1055d72 100755 --- a/libs/protobuf/kokoro/macos/objectivec_ios_debug/build.sh +++ b/libs/protobuf/kokoro/macos/objectivec_ios_debug/build.sh @@ -8,5 +8,4 @@ cd $(dirname $0)/../../.. # Prepare worker environment to run tests source kokoro/macos/prepare_build_macos_rc -objectivec/DevTools/full_mac_build.sh \ - --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance --skip-xcode-release +./tests.sh objectivec_ios_debug diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_debug/common.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_debug/common.cfg deleted file mode 100644 index b4ccc45..0000000 --- a/libs/protobuf/kokoro/macos/objectivec_ios_debug/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/objectivec_ios_debug/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_debug/continuous.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_debug/continuous.cfg index 8523c22..473d545 100644 --- a/libs/protobuf/kokoro/macos/objectivec_ios_debug/continuous.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_ios_debug/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_ios_debug/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_debug/presubmit.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_debug/presubmit.cfg index 8523c22..473d545 100644 --- a/libs/protobuf/kokoro/macos/objectivec_ios_debug/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_ios_debug/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_ios_debug/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_release/build.sh b/libs/protobuf/kokoro/macos/objectivec_ios_release/build.sh index adbc4f2..76ce3ba 100755 --- a/libs/protobuf/kokoro/macos/objectivec_ios_release/build.sh +++ b/libs/protobuf/kokoro/macos/objectivec_ios_release/build.sh @@ -8,5 +8,4 @@ cd $(dirname $0)/../../.. # Prepare worker environment to run tests source kokoro/macos/prepare_build_macos_rc -objectivec/DevTools/full_mac_build.sh \ - --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance --skip-xcode-debug +./tests.sh objectivec_ios_release diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_release/common.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_release/common.cfg deleted file mode 100644 index 3a6ac86..0000000 --- a/libs/protobuf/kokoro/macos/objectivec_ios_release/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/objectivec_ios_release/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_release/continuous.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_release/continuous.cfg index 8523c22..3cbfb68 100644 --- a/libs/protobuf/kokoro/macos/objectivec_ios_release/continuous.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_ios_release/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_ios_release/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_ios_release/presubmit.cfg b/libs/protobuf/kokoro/macos/objectivec_ios_release/presubmit.cfg index 8523c22..3cbfb68 100644 --- a/libs/protobuf/kokoro/macos/objectivec_ios_release/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_ios_release/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_ios_release/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_osx/build.sh b/libs/protobuf/kokoro/macos/objectivec_osx/build.sh index 7f5d561..000be27 100755 --- a/libs/protobuf/kokoro/macos/objectivec_osx/build.sh +++ b/libs/protobuf/kokoro/macos/objectivec_osx/build.sh @@ -8,5 +8,4 @@ cd $(dirname $0)/../../.. # Prepare worker environment to run tests source kokoro/macos/prepare_build_macos_rc -objectivec/DevTools/full_mac_build.sh \ - --core-only --skip-xcode-ios --skip-xcode-tvos +./tests.sh objectivec_osx diff --git a/libs/protobuf/kokoro/macos/objectivec_osx/common.cfg b/libs/protobuf/kokoro/macos/objectivec_osx/common.cfg deleted file mode 100644 index ee5c2db..0000000 --- a/libs/protobuf/kokoro/macos/objectivec_osx/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/objectivec_osx/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/objectivec_osx/continuous.cfg b/libs/protobuf/kokoro/macos/objectivec_osx/continuous.cfg index 8523c22..41bd46a 100644 --- a/libs/protobuf/kokoro/macos/objectivec_osx/continuous.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_osx/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_osx/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/objectivec_osx/presubmit.cfg b/libs/protobuf/kokoro/macos/objectivec_osx/presubmit.cfg index 8523c22..41bd46a 100644 --- a/libs/protobuf/kokoro/macos/objectivec_osx/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/objectivec_osx/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/objectivec_osx/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/php7.0_mac/build.sh b/libs/protobuf/kokoro/macos/php7.0_mac/build.sh new file mode 100755 index 0000000..c6717e0 --- /dev/null +++ b/libs/protobuf/kokoro/macos/php7.0_mac/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Build file to set up and run tests + +# Change to repo root +cd $(dirname $0)/../../.. + +# Prepare worker environment to run tests +source kokoro/macos/prepare_build_macos_rc + +# TODO(mkruskal) Re-enable this once we can get a working PHP 7.0 installed. +#./tests.sh php7.0_mac diff --git a/libs/protobuf/kokoro/windows/cmake/common.cfg b/libs/protobuf/kokoro/macos/php7.0_mac/continuous.cfg similarity index 65% rename from libs/protobuf/kokoro/windows/cmake/common.cfg rename to libs/protobuf/kokoro/macos/php7.0_mac/continuous.cfg index 37e89e0..c2c1811 100644 --- a/libs/protobuf/kokoro/windows/cmake/common.cfg +++ b/libs/protobuf/kokoro/macos/php7.0_mac/continuous.cfg @@ -1,5 +1,5 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/windows/cmake/build.bat" +build_file: "protobuf/kokoro/macos/php7.0_mac/build.sh" timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/windows/csharp/common.cfg b/libs/protobuf/kokoro/macos/php7.0_mac/presubmit.cfg similarity index 65% rename from libs/protobuf/kokoro/windows/csharp/common.cfg rename to libs/protobuf/kokoro/macos/php7.0_mac/presubmit.cfg index f586585..c2c1811 100644 --- a/libs/protobuf/kokoro/windows/csharp/common.cfg +++ b/libs/protobuf/kokoro/macos/php7.0_mac/presubmit.cfg @@ -1,5 +1,5 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/windows/csharp/build.bat" +build_file: "protobuf/kokoro/macos/php7.0_mac/build.sh" timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/php7.3_mac/build.sh b/libs/protobuf/kokoro/macos/php7.3_mac/build.sh new file mode 100755 index 0000000..2688ddb --- /dev/null +++ b/libs/protobuf/kokoro/macos/php7.3_mac/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# Build file to set up and run tests + +# Change to repo root +cd $(dirname $0)/../../.. + +# Prepare worker environment to run tests +source kokoro/macos/prepare_build_macos_rc + +# TODO(mkruskal) Re-enable this once we can get a working PHP 7.0 installed. +#./tests.sh php7.3_mac diff --git a/libs/protobuf/kokoro/macos/php7.3_mac/continuous.cfg b/libs/protobuf/kokoro/macos/php7.3_mac/continuous.cfg new file mode 100644 index 0000000..9a71745 --- /dev/null +++ b/libs/protobuf/kokoro/macos/php7.3_mac/continuous.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/php7.3_mac/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/php7.3_mac/presubmit.cfg b/libs/protobuf/kokoro/macos/php7.3_mac/presubmit.cfg new file mode 100644 index 0000000..9a71745 --- /dev/null +++ b/libs/protobuf/kokoro/macos/php7.3_mac/presubmit.cfg @@ -0,0 +1,5 @@ +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/php7.3_mac/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/php74/build.sh b/libs/protobuf/kokoro/macos/php74/build.sh deleted file mode 100755 index 2ad4eab..0000000 --- a/libs/protobuf/kokoro/macos/php74/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -source kokoro/macos/prepare_build_macos_rc - -# Install Dependencies -brew cleanup -brew install coreutils php@7.4 - -# Configure path -PHP_FOLDER=$(find $HOMEBREW_PREFIX -type d -regex ".*php.*/7.4.[0-9_.]*" | sort -n | tail -n 1) -test ! -z "$PHP_FOLDER" -export PATH="$PHP_FOLDER/bin:$PATH" - -# Test -kokoro/macos/test_php.sh diff --git a/libs/protobuf/kokoro/macos/php74/common.cfg b/libs/protobuf/kokoro/macos/php74/common.cfg deleted file mode 100644 index b9d5b82..0000000 --- a/libs/protobuf/kokoro/macos/php74/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/php74/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/php74/continuous.cfg b/libs/protobuf/kokoro/macos/php74/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/macos/php74/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/macos/php74/presubmit.cfg b/libs/protobuf/kokoro/macos/php74/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/macos/php74/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/macos/php80/build.sh b/libs/protobuf/kokoro/macos/php80/build.sh deleted file mode 100755 index e703ffc..0000000 --- a/libs/protobuf/kokoro/macos/php80/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# -# Build file to set up and run tests - -# Change to repo root -cd $(dirname $0)/../../.. - -# Prepare worker environment to run tests -source kokoro/macos/prepare_build_macos_rc - -# Install Dependencies -brew cleanup -brew install coreutils php@8.0 - -# Configure path -PHP_FOLDER=$(find $HOMEBREW_PREFIX -type d -regex ".*php.*/8.0.[0-9_.]*" | sort -n | tail -n 1) -test ! -z "$PHP_FOLDER" -export PATH="$PHP_FOLDER/bin:$PATH" - -# Test -kokoro/macos/test_php.sh diff --git a/libs/protobuf/kokoro/macos/php80/common.cfg b/libs/protobuf/kokoro/macos/php80/common.cfg deleted file mode 100644 index 294fd52..0000000 --- a/libs/protobuf/kokoro/macos/php80/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/php80/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/php80/continuous.cfg b/libs/protobuf/kokoro/macos/php80/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/macos/php80/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/macos/php80/presubmit.cfg b/libs/protobuf/kokoro/macos/php80/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/macos/php80/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/macos/prepare_build_macos_rc b/libs/protobuf/kokoro/macos/prepare_build_macos_rc index d8b1395..7a150c7 100755 --- a/libs/protobuf/kokoro/macos/prepare_build_macos_rc +++ b/libs/protobuf/kokoro/macos/prepare_build_macos_rc @@ -6,14 +6,38 @@ set -eux export HOMEBREW_PREFIX=$(brew --prefix) +## +# Remove any pre-existing protobuf installation. +brew uninstall protobuf + +## +# Select Xcode version + ## # Select Xcode version export DEVELOPER_DIR=/Applications/Xcode_14.app/Contents/Developer sudo xcode-select -s "${DEVELOPER_DIR}" ## -# Use Python 2 by default (for googletest) -pyenv global 2.7.18 +# Select C/C++ compilers + +export CC=gcc +export CXX=g++ + +## +# Install Python 2 by default + +eval "$(pyenv init -)" +pyenv install -v -s 2.7.18 && pyenv global 2.7.18 + +## +# Install Tox + +if [[ "${KOKORO_INSTALL_TOX:-}" == "yes" ]] ; then + pyenv install -v -s 3.7.13 + pyenv global 3.7.13 + sudo python -m pip install --upgrade pip 'tox==3.27.1' tox-pyenv +fi ## # Setup RVM @@ -23,19 +47,3 @@ if [[ "${KOKORO_INSTALL_RVM:-}" == "yes" ]] ; then git config --global --add safe.directory $HOMEBREW_PREFIX/Library/Taps/homebrew/homebrew-services sudo chown -R $(whoami) $HOME/.rvm/ fi - -# "Install" valgrind if it doesn't exist -## -if [ ! -x "$(command -v valgrind)" ]; then - echo "#! /bin/bash" > valgrind - chmod ug+x valgrind - sudo mv valgrind /usr/local/bin/valgrind -fi - -## -# Install Virtual Python Environment - -if [[ "${KOKORO_INSTALL_VENV:-}" == "yes" ]] ; then - python3 -m venv venv - source venv/bin/activate -fi diff --git a/libs/protobuf/kokoro/macos/python/build.sh b/libs/protobuf/kokoro/macos/python/build.sh index de3db88..388e24b 100755 --- a/libs/protobuf/kokoro/macos/python/build.sh +++ b/libs/protobuf/kokoro/macos/python/build.sh @@ -6,8 +6,7 @@ cd $(dirname $0)/../../.. # Prepare worker environment to run tests -KOKORO_INSTALL_VENV=yes +KOKORO_INSTALL_TOX=yes source kokoro/macos/prepare_build_macos_rc -bazel test //python/... @upb//python/... $(kokoro/common/bazel_flags.sh) \ - --macos_minimum_os=10.9 +./tests.sh python diff --git a/libs/protobuf/kokoro/macos/python/common.cfg b/libs/protobuf/kokoro/macos/python/common.cfg deleted file mode 100644 index dd9f8ac..0000000 --- a/libs/protobuf/kokoro/macos/python/common.cfg +++ /dev/null @@ -1,33 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/python/build.sh" -timeout_mins: 1440 - -action { - define_artifacts { - regex: "**/*" - } -} - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/python/continuous.cfg b/libs/protobuf/kokoro/macos/python/continuous.cfg index 8523c22..0fc8b50 100644 --- a/libs/protobuf/kokoro/macos/python/continuous.cfg +++ b/libs/protobuf/kokoro/macos/python/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/python/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/python/presubmit.cfg b/libs/protobuf/kokoro/macos/python/presubmit.cfg index 8523c22..0fc8b50 100644 --- a/libs/protobuf/kokoro/macos/python/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/python/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/python/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/python_cpp/build.sh b/libs/protobuf/kokoro/macos/python_cpp/build.sh index 8f94fcf..f86dd6f 100755 --- a/libs/protobuf/kokoro/macos/python_cpp/build.sh +++ b/libs/protobuf/kokoro/macos/python_cpp/build.sh @@ -6,8 +6,8 @@ cd $(dirname $0)/../../.. # Prepare worker environment to run tests -KOKORO_INSTALL_VENV=yes +KOKORO_INSTALL_TOX=yes source kokoro/macos/prepare_build_macos_rc +g++ --version -bazel test //python/... $(kokoro/common/bazel_flags.sh) \ - --macos_minimum_os=10.9 --define=use_fast_cpp_protos=true +./tests.sh python_cpp diff --git a/libs/protobuf/kokoro/macos/python_cpp/common.cfg b/libs/protobuf/kokoro/macos/python_cpp/common.cfg deleted file mode 100644 index 12270c5..0000000 --- a/libs/protobuf/kokoro/macos/python_cpp/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/python_cpp/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/python_cpp/continuous.cfg b/libs/protobuf/kokoro/macos/python_cpp/continuous.cfg index 8523c22..22f4a0e 100644 --- a/libs/protobuf/kokoro/macos/python_cpp/continuous.cfg +++ b/libs/protobuf/kokoro/macos/python_cpp/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/python_cpp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/python_cpp/presubmit.cfg b/libs/protobuf/kokoro/macos/python_cpp/presubmit.cfg index 8523c22..22f4a0e 100644 --- a/libs/protobuf/kokoro/macos/python_cpp/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/python_cpp/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/python_cpp/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby25/build.sh b/libs/protobuf/kokoro/macos/ruby25/build.sh index 81ce2c3..48c8940 100755 --- a/libs/protobuf/kokoro/macos/ruby25/build.sh +++ b/libs/protobuf/kokoro/macos/ruby25/build.sh @@ -9,5 +9,4 @@ cd $(dirname $0)/../../.. KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc -cd ruby -./travis-test.sh ruby-2.5.1 +./tests.sh ruby25 diff --git a/libs/protobuf/kokoro/macos/ruby25/common.cfg b/libs/protobuf/kokoro/macos/ruby25/common.cfg deleted file mode 100644 index ba17345..0000000 --- a/libs/protobuf/kokoro/macos/ruby25/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby25/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/ruby25/continuous.cfg b/libs/protobuf/kokoro/macos/ruby25/continuous.cfg index 8523c22..b3755e4 100644 --- a/libs/protobuf/kokoro/macos/ruby25/continuous.cfg +++ b/libs/protobuf/kokoro/macos/ruby25/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby25/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby25/presubmit.cfg b/libs/protobuf/kokoro/macos/ruby25/presubmit.cfg index 8523c22..b3755e4 100644 --- a/libs/protobuf/kokoro/macos/ruby25/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/ruby25/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby25/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby26/build.sh b/libs/protobuf/kokoro/macos/ruby26/build.sh index ee815b6..1b94fe1 100755 --- a/libs/protobuf/kokoro/macos/ruby26/build.sh +++ b/libs/protobuf/kokoro/macos/ruby26/build.sh @@ -9,5 +9,4 @@ cd $(dirname $0)/../../.. KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc -cd ruby -./travis-test.sh ruby-2.6.0 +./tests.sh ruby26 diff --git a/libs/protobuf/kokoro/macos/ruby26/common.cfg b/libs/protobuf/kokoro/macos/ruby26/common.cfg deleted file mode 100644 index deeaf51..0000000 --- a/libs/protobuf/kokoro/macos/ruby26/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby26/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/ruby26/continuous.cfg b/libs/protobuf/kokoro/macos/ruby26/continuous.cfg index 8523c22..688f63c 100644 --- a/libs/protobuf/kokoro/macos/ruby26/continuous.cfg +++ b/libs/protobuf/kokoro/macos/ruby26/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby26/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby26/presubmit.cfg b/libs/protobuf/kokoro/macos/ruby26/presubmit.cfg index 8523c22..688f63c 100644 --- a/libs/protobuf/kokoro/macos/ruby26/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/ruby26/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby26/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby27/build.sh b/libs/protobuf/kokoro/macos/ruby27/build.sh index ca6badb..baebdb7 100755 --- a/libs/protobuf/kokoro/macos/ruby27/build.sh +++ b/libs/protobuf/kokoro/macos/ruby27/build.sh @@ -9,5 +9,4 @@ cd $(dirname $0)/../../.. KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc -cd ruby -./travis-test.sh ruby-2.7.0 +./tests.sh ruby27 diff --git a/libs/protobuf/kokoro/macos/ruby27/common.cfg b/libs/protobuf/kokoro/macos/ruby27/common.cfg deleted file mode 100644 index 1451eb0..0000000 --- a/libs/protobuf/kokoro/macos/ruby27/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby27/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/ruby27/continuous.cfg b/libs/protobuf/kokoro/macos/ruby27/continuous.cfg index 8523c22..b10b455 100644 --- a/libs/protobuf/kokoro/macos/ruby27/continuous.cfg +++ b/libs/protobuf/kokoro/macos/ruby27/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby27/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby27/presubmit.cfg b/libs/protobuf/kokoro/macos/ruby27/presubmit.cfg index 8523c22..b10b455 100644 --- a/libs/protobuf/kokoro/macos/ruby27/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/ruby27/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby27/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby30/build.sh b/libs/protobuf/kokoro/macos/ruby30/build.sh index 01bdc47..b1e0641 100755 --- a/libs/protobuf/kokoro/macos/ruby30/build.sh +++ b/libs/protobuf/kokoro/macos/ruby30/build.sh @@ -9,5 +9,4 @@ cd $(dirname $0)/../../.. KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc -cd ruby -./travis-test.sh ruby-3.0.2 +./tests.sh ruby30 diff --git a/libs/protobuf/kokoro/macos/ruby30/common.cfg b/libs/protobuf/kokoro/macos/ruby30/common.cfg deleted file mode 100644 index 79dc7a5..0000000 --- a/libs/protobuf/kokoro/macos/ruby30/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby30/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/ruby30/continuous.cfg b/libs/protobuf/kokoro/macos/ruby30/continuous.cfg index 8523c22..d505117 100644 --- a/libs/protobuf/kokoro/macos/ruby30/continuous.cfg +++ b/libs/protobuf/kokoro/macos/ruby30/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby30/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby30/presubmit.cfg b/libs/protobuf/kokoro/macos/ruby30/presubmit.cfg index 8523c22..d505117 100644 --- a/libs/protobuf/kokoro/macos/ruby30/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/ruby30/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby30/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby31/build.sh b/libs/protobuf/kokoro/macos/ruby31/build.sh index 6e4beda..3cf61f6 100644 --- a/libs/protobuf/kokoro/macos/ruby31/build.sh +++ b/libs/protobuf/kokoro/macos/ruby31/build.sh @@ -12,5 +12,4 @@ export LC_ALL=en_US.UTF-8 KOKORO_INSTALL_RVM=yes source kokoro/macos/prepare_build_macos_rc -cd ruby -./travis-test.sh ruby-3.1.0 +./tests.sh ruby31 diff --git a/libs/protobuf/kokoro/macos/ruby31/common.cfg b/libs/protobuf/kokoro/macos/ruby31/common.cfg deleted file mode 100644 index e2d1d1b..0000000 --- a/libs/protobuf/kokoro/macos/ruby31/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/macos/ruby31/build.sh" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/macos/ruby31/continuous.cfg b/libs/protobuf/kokoro/macos/ruby31/continuous.cfg index 8523c22..19e16b3 100644 --- a/libs/protobuf/kokoro/macos/ruby31/continuous.cfg +++ b/libs/protobuf/kokoro/macos/ruby31/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby31/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/ruby31/presubmit.cfg b/libs/protobuf/kokoro/macos/ruby31/presubmit.cfg index 8523c22..19e16b3 100644 --- a/libs/protobuf/kokoro/macos/ruby31/presubmit.cfg +++ b/libs/protobuf/kokoro/macos/ruby31/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/macos/ruby31/build.sh" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/macos/test_php.sh b/libs/protobuf/kokoro/macos/test_php.sh deleted file mode 100755 index 74d88f6..0000000 --- a/libs/protobuf/kokoro/macos/test_php.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -eux - -pushd php -rm -rf vendor -php -v -php -m -composer update -composer test_c -popd - -git clean -fXd -bazel test $(kokoro/common/bazel_flags.sh) \ - --action_env=PATH --test_env=PATH \ - //php:conformance_test_c diff --git a/libs/protobuf/kokoro/release/collect_all_artifacts.sh b/libs/protobuf/kokoro/release/collect_all_artifacts.sh index 20c6d8d..6e0d152 100755 --- a/libs/protobuf/kokoro/release/collect_all_artifacts.sh +++ b/libs/protobuf/kokoro/release/collect_all_artifacts.sh @@ -40,8 +40,8 @@ mkdir -p protoc/linux_x86 mkdir -p protoc/linux_x64 # Because of maven unrelated reasonse the linux protoc binaries have a dummy .exe extension. # For the Google.Protobuf.Tools nuget, we don't want that exception, so we just remove it. -cp ${INPUT_ARTIFACTS_DIR}/kokoro/release/protoc/target/linux/x86_32/protoc.exe protoc/linux_x86/protoc -cp ${INPUT_ARTIFACTS_DIR}/kokoro/release/protoc/target/linux/x86_64/protoc.exe protoc/linux_x64/protoc +cp ${INPUT_ARTIFACTS_DIR}/protoc-artifacts/target/linux/x86_32/protoc.exe protoc/linux_x86/protoc +cp ${INPUT_ARTIFACTS_DIR}/protoc-artifacts/target/linux/x86_64/protoc.exe protoc/linux_x64/protoc mkdir -p protoc/macosx_x64 cp ${INPUT_ARTIFACTS_DIR}/build64/src/protoc protoc/macosx_x64/protoc diff --git a/libs/protobuf/kokoro/release/csharp/windows/common.cfg b/libs/protobuf/kokoro/release/csharp/windows/common.cfg deleted file mode 100644 index f508c65..0000000 --- a/libs/protobuf/kokoro/release/csharp/windows/common.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/release/csharp/windows/build_nuget.bat" -timeout_mins: 60 - -action { - define_artifacts { - regex: "**/*.nupkg" - } -} diff --git a/libs/protobuf/kokoro/release/csharp/windows/continuous.cfg b/libs/protobuf/kokoro/release/csharp/windows/continuous.cfg index 8523c22..f508c65 100644 --- a/libs/protobuf/kokoro/release/csharp/windows/continuous.cfg +++ b/libs/protobuf/kokoro/release/csharp/windows/continuous.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/release/csharp/windows/build_nuget.bat" +timeout_mins: 60 + +action { + define_artifacts { + regex: "**/*.nupkg" + } +} diff --git a/libs/protobuf/kokoro/release/csharp/windows/presubmit.cfg b/libs/protobuf/kokoro/release/csharp/windows/presubmit.cfg index 8523c22..f508c65 100644 --- a/libs/protobuf/kokoro/release/csharp/windows/presubmit.cfg +++ b/libs/protobuf/kokoro/release/csharp/windows/presubmit.cfg @@ -1 +1,11 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/release/csharp/windows/build_nuget.bat" +timeout_mins: 60 + +action { + define_artifacts { + regex: "**/*.nupkg" + } +} diff --git a/libs/protobuf/kokoro/release/protoc/linux/build.sh b/libs/protobuf/kokoro/release/protoc/linux/build.sh index a9d58b7..44a95aa 100755 --- a/libs/protobuf/kokoro/release/protoc/linux/build.sh +++ b/libs/protobuf/kokoro/release/protoc/linux/build.sh @@ -1,29 +1,44 @@ #!/bin/bash -# This is not the source of truth for release protoc executables, and will soon -# be deprecated. - -set -ex +set -x # Change to repo root. cd $(dirname $0)/../../../.. -GIT_REPO_ROOT=$(pwd) # Initialize any submodules. git submodule update --init --recursive +# Generate the configure script. +./autogen.sh + # Cross-build for aarch64, ppc64le and s390x. Note: we do these builds first to avoid # file permission issues. The Docker builds will create directories owned by # root, which causes problems if we try to add new artifacts to those # directories afterward. +sudo apt install -y g++-aarch64-linux-gnu +protoc-artifacts/build-protoc.sh linux aarch_64 protoc -kokoro/release/protoc/build-protoc.sh linux aarch_64 protoc +sudo apt install -y g++-powerpc64le-linux-gnu +protoc-artifacts/build-protoc.sh linux ppcle_64 protoc -kokoro/release/protoc/build-protoc.sh linux ppcle_64 protoc +sudo apt install -y g++-s390x-linux-gnu +protoc-artifacts/build-protoc.sh linux s390_64 protoc -kokoro/release/protoc/build-protoc.sh linux s390_64 protoc +# Use docker image to build linux artifacts. +DOCKER_IMAGE_NAME=protobuf/protoc_$(sha1sum protoc-artifacts/Dockerfile | cut -f1 -d " ") +docker pull $DOCKER_IMAGE_NAME -kokoro/release/protoc/build-protoc.sh linux x86_64 protoc +docker run -v $(pwd):/var/local/protobuf --rm $DOCKER_IMAGE_NAME \ + bash -l /var/local/protobuf/protoc-artifacts/build-protoc.sh \ + linux x86_64 protoc || { + echo "Failed to build protoc for linux + x86_64." + exit 1 +} -kokoro/release/protoc/build-protoc.sh linux x86_32 protoc +docker run -v $(pwd):/var/local/protobuf --rm $DOCKER_IMAGE_NAME \ + bash -l /var/local/protobuf/protoc-artifacts/build-protoc.sh \ + linux x86_32 protoc || { + echo "Failed to build protoc for linux + x86_32." + exit 1 +} diff --git a/libs/protobuf/kokoro/release/protoc/macos/build.sh b/libs/protobuf/kokoro/release/protoc/macos/build.sh index 2a31431..47c9bfa 100755 --- a/libs/protobuf/kokoro/release/protoc/macos/build.sh +++ b/libs/protobuf/kokoro/release/protoc/macos/build.sh @@ -4,9 +4,12 @@ set -ex CXXFLAGS_COMMON="-std=c++14 -DNDEBUG -mmacosx-version-min=10.9" cd github/protobuf +./autogen.sh -bazel build //:protoc --dynamic_mode=off -mkdir -p build64/src -cp bazel-bin/protoc build64/src/protoc -file bazel-bin/protoc -otool -L bazel-bin/protoc | grep dylib +mkdir build64 && cd build64 +export CXXFLAGS="$CXXFLAGS_COMMON -m64" +../configure --disable-shared +make -j4 +file src/protoc +otool -L src/protoc | grep dylib +cd .. diff --git a/libs/protobuf/kokoro/release/protoc/windows/build.bat b/libs/protobuf/kokoro/release/protoc/windows/build.bat index 50ad223..75ea546 100644 --- a/libs/protobuf/kokoro/release/protoc/windows/build.bat +++ b/libs/protobuf/kokoro/release/protoc/windows/build.bat @@ -1,13 +1,10 @@ -set generator32=Visual Studio 15 -set generator64=Visual Studio 15 Win64 +set PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% +set generator32=Visual Studio 14 +set generator64=Visual Studio 14 Win64 set vcplatform32=win32 set vcplatform64=x64 set configuration=Release -:: VS2017 is installed, but will not be selected by default. This command sets -:: up the environment so that CMake will find and use it: -call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 - echo Building protoc cd github\protobuf @@ -18,13 +15,13 @@ set ABSL_ROOT_DIR=%cd%\third_party\abseil-cpp mkdir build32 cd build32 -cmake -G "%generator32%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON .. +cmake -G "%generator32%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON ../cmake msbuild protobuf.sln /p:Platform=%vcplatform32% || goto error cd .. mkdir build64 cd build64 -cmake -G "%generator64%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON .. +cmake -G "%generator64%" -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_UNICODE=ON ../cmake msbuild protobuf.sln /p:Platform=%vcplatform64% || goto error cd .. diff --git a/libs/protobuf/kokoro/release/python/linux/build_artifacts.sh b/libs/protobuf/kokoro/release/python/linux/build_artifacts.sh new file mode 100755 index 0000000..9a3fc58 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/linux/build_artifacts.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +set -ex + +# change to repo root +pushd $(dirname $0)/../../../.. + +# Create stage dir +ORIGINAL_DIR=`pwd` +pushd .. +cp -R $ORIGINAL_DIR stage +export STAGE_DIR="`pwd`/stage" +popd + +export REPO_DIR=protobuf +export BUILD_VERSION=`grep -i "version" python/google/protobuf/__init__.py | grep -o "'.*'" | tr -d "'"` + +export BUILD_COMMIT=`git rev-parse HEAD` +export PLAT=x86_64 +export UNICODE_WIDTH=32 +export MACOSX_DEPLOYMENT_TARGET=10.9 + +rm -rf artifacts/ +rm -rf multibuild/ +mkdir artifacts +export ARTIFACT_DIR=$(pwd)/artifacts + +git clone https://github.com/matthew-brett/multibuild.git +# Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +# IMPORTANT: always pin multibuild at the same commit for: +# - linux/build_artifacts.sh +# - linux/build_artifacts.sh +# - windows/build_artifacts.bat +(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) +cp kokoro/release/python/linux/config.sh config.sh + +build_artifact_version() { + MB_PYTHON_VERSION=$1 + cp -R $STAGE_DIR $REPO_DIR + + source multibuild/common_utils.sh + source multibuild/travis_steps.sh + before_install + + clean_code $REPO_DIR $BUILD_COMMIT + + build_wheel $REPO_DIR/python $PLAT + + mv wheelhouse/* $ARTIFACT_DIR + + # Clean up env + rm -rf venv + sudo rm -rf $REPO_DIR +} + +build_x86_64_manylinux1_artifact_version() { + # Explicitly request building manylinux1 wheels, which is no longer the default. + # https://github.com/protocolbuffers/protobuf/issues/9180 + MB_ML_VER=1 + build_artifact_version $@ +} + +build_x86_64_manylinux2010_artifact_version() { + # Explicitly request building manylinux2010 wheels + MB_ML_VER=2010 + build_artifact_version $@ +} + +build_crosscompiled_aarch64_manylinux2014_artifact_version() { + # crosscompilation is only supported with the dockcross manylinux2014 image + DOCKER_IMAGE=dockcross/manylinux2014-aarch64:20210706-65bf2dd + MB_ML_VER=2014 + PLAT=aarch64 + + # TODO(jtatermusch): currently when crosscompiling, "auditwheel repair" will be disabled + # since auditwheel doesn't work for crosscomiled wheels. + build_artifact_version $@ +} + +build_x86_64_manylinux1_artifact_version 3.6 +build_x86_64_manylinux1_artifact_version 3.7 +build_x86_64_manylinux1_artifact_version 3.8 +build_x86_64_manylinux1_artifact_version 3.9 +build_x86_64_manylinux2010_artifact_version 3.10 + +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.7 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.8 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.9 +build_crosscompiled_aarch64_manylinux2014_artifact_version 3.10 diff --git a/libs/protobuf/kokoro/release/python/linux/config.sh b/libs/protobuf/kokoro/release/python/linux/config.sh new file mode 100644 index 0000000..8920495 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/linux/config.sh @@ -0,0 +1,93 @@ +# Define custom utilities +# Test for OSX with [ -n "$IS_OSX" ] + +function pre_build { + # Any stuff that you need to do before you start building the wheels + # Runs in the root directory of this repository. + pushd protobuf + + if [ "$PLAT" == "aarch64" ] + then + local configure_host_flag="--host=aarch64" + fi + + # Build protoc and libprotobuf + ./autogen.sh + CXXFLAGS="-fPIC -g -O2" ./configure $configure_host_flag + make -j8 + + if [ "$PLAT" == "aarch64" ] + then + # we are crosscompiling for aarch64 while running on x64 + # the simplest way for build_py command to be able to generate + # the protos is by running the protoc process under + # an emulator. That way we don't have to build a x64 version + # of protoc. The qemu-arm emulator is already included + # in the dockcross docker image. + # Running protoc under an emulator is fast as protoc doesn't + # really do much. + + # create a simple shell wrapper that runs crosscompiled protoc under qemu + echo '#!/bin/bash' >protoc_qemu_wrapper.sh + echo 'exec qemu-aarch64 "../src/protoc" "$@"' >>protoc_qemu_wrapper.sh + chmod ugo+x protoc_qemu_wrapper.sh + + # PROTOC variable is by build_py step that runs under ./python directory + export PROTOC=../protoc_qemu_wrapper.sh + fi + + # Generate python dependencies. + pushd python + python setup.py build_py + popd + + popd +} + +function bdist_wheel_cmd { + # Builds wheel with bdist_wheel, puts into wheelhouse + # + # It may sometimes be useful to use bdist_wheel for the wheel building + # process. For example, versioneer has problems with versions which are + # fixed with bdist_wheel: + # https://github.com/warner/python-versioneer/issues/121 + local abs_wheelhouse=$1 + + # Modify build version + pwd + ls + + if [ "$PLAT" == "aarch64" ] + then + # when crosscompiling for aarch64, --plat-name needs to be set explicitly + # to end up with correctly named wheel file + # the value should be manylinuxABC_ARCH and dockcross docker image + # conveniently provides the value in the AUDITWHEEL_PLAT env + local plat_name_flag="--plat-name=$AUDITWHEEL_PLAT" + + # override the value of EXT_SUFFIX to make sure the crosscompiled .so files in the wheel have the correct filename suffix + export PROTOCOL_BUFFERS_OVERRIDE_EXT_SUFFIX="$(python -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX").replace("-x86_64-linux-gnu.so", "-aarch64-linux-gnu.so"))')" + fi + + python setup.py bdist_wheel --cpp_implementation --compile_static_extension $plat_name_flag + cp dist/*.whl $abs_wheelhouse +} + +function build_wheel { + build_wheel_cmd "bdist_wheel_cmd" $@ +} + +function run_tests { + # Runs tests on installed distribution from an empty directory + python --version + python -c "from google.protobuf.pyext import _message;" +} + +if [ "$PLAT" == "aarch64" ] +then + # when crosscompiling for aarch64, override the default multibuild's repair_wheelhouse logic + # since "auditwheel repair" doesn't work for crosscompiled wheels + function repair_wheelhouse { + echo "Skipping repair_wheelhouse since auditwheel requires build architecture to match wheel architecture." + } +fi diff --git a/libs/protobuf/kokoro/release/python/linux/continuous.cfg b/libs/protobuf/kokoro/release/python/linux/continuous.cfg new file mode 100644 index 0000000..c0b9a01 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/linux/continuous.cfg @@ -0,0 +1,8 @@ +# Config file for running tests in Kokoro +build_file: "protobuf/kokoro/release/python/linux/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/python/linux/presubmit.cfg b/libs/protobuf/kokoro/release/python/linux/presubmit.cfg new file mode 100644 index 0000000..c0b9a01 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/linux/presubmit.cfg @@ -0,0 +1,8 @@ +# Config file for running tests in Kokoro +build_file: "protobuf/kokoro/release/python/linux/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/linux/common.cfg b/libs/protobuf/kokoro/release/python/linux/release.cfg similarity index 63% rename from libs/protobuf/kokoro/release/ruby/linux/common.cfg rename to libs/protobuf/kokoro/release/python/linux/release.cfg index dbc71b2..b31b3f1 100644 --- a/libs/protobuf/kokoro/release/ruby/linux/common.cfg +++ b/libs/protobuf/kokoro/release/python/linux/release.cfg @@ -1,5 +1,5 @@ # Configuration for Linux release builds -build_file: "protobuf/kokoro/release/ruby/linux/build_artifacts.sh" +build_file: "protobuf/kokoro/release/python/linux/build_artifacts.sh" action { define_artifacts { diff --git a/libs/protobuf/kokoro/release/python/macos/build_artifacts.sh b/libs/protobuf/kokoro/release/python/macos/build_artifacts.sh new file mode 100755 index 0000000..d79d2f6 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/macos/build_artifacts.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -ex + +# Remove any pre-existing protobuf installation. +brew uninstall -f protobuf + +# change to repo root +pushd $(dirname $0)/../../../.. + +# Create stage dir +ORIGINAL_DIR=`pwd` +pushd .. +cp -R $ORIGINAL_DIR stage +export STAGE_DIR="`pwd`/stage" +popd + +export REPO_DIR=protobuf +export BUILD_VERSION=`grep -i "version" python/google/protobuf/__init__.py | grep -o "'.*'" | tr -d "'"` +export BUILD_COMMIT=`git rev-parse HEAD` +export PLAT=x86_64 +export UNICODE_WIDTH=32 +export MACOSX_DEPLOYMENT_TARGET=10.9 +export TRAVIS_OS_NAME="osx" + +rm -rf artifacts/ +rm -rf multibuild/ +mkdir artifacts +export ARTIFACT_DIR=$(pwd)/artifacts + +git clone https://github.com/matthew-brett/multibuild.git +# Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +# silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +# IMPORTANT: always pin multibuild at the same commit for: +# - linux/build_artifacts.sh +# - linux/build_artifacts.sh +# - windows/build_artifacts.bat +(cd multibuild; git checkout b89bb903e94308be79abefa4f436bf123ebb1313) +cp kokoro/release/python/macos/config.sh config.sh + +OLD_PATH=$PATH + +build_artifact_version() { + MB_PYTHON_VERSION=$1 + + # Clean up env + rm -rf venv + sudo rm -rf $REPO_DIR + cp -R $STAGE_DIR $REPO_DIR + export PATH=$OLD_PATH + + source multibuild/common_utils.sh + source multibuild/travis_steps.sh + before_install + + clean_code $REPO_DIR $BUILD_COMMIT + + build_wheel $REPO_DIR/python $PLAT + + mv wheelhouse/* $ARTIFACT_DIR +} + +export MB_PYTHON_OSX_VER=10.9 +build_artifact_version 3.7 +build_artifact_version 3.8 +build_artifact_version 3.9 +build_artifact_version 3.10 diff --git a/libs/protobuf/kokoro/release/python/macos/config.sh b/libs/protobuf/kokoro/release/python/macos/config.sh new file mode 100644 index 0000000..74e6569 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/macos/config.sh @@ -0,0 +1,67 @@ +# Define custom utilities +# Test for OSX with [ -n "$IS_OSX" ] + +function remove_travis_ve_pip { + # Removing the system virtualenv or pip can be very problematic for + # macOS on Kokoro, so just leave them be. + :; +} + +function install_pip { + check_python + PIP_CMD="sudo $PYTHON_EXE -m pip${pip_args:+ $pip_args}" + $PIP_CMD install --upgrade pip +} + +function install_virtualenv { + check_python + check_pip + $PIP_CMD install --upgrade virtualenv + VIRTUALENV_CMD="$PYTHON_EXE -m virtualenv" +} + +function pre_build { + # Any stuff that you need to do before you start building the wheels + # Runs in the root directory of this repository. + pushd protobuf + + # Build protoc and protobuf libraries + bazel build //:protoc + export PROTOC=$PWD/bazel-bin/protoc + mkdir src/.libs + ln -s $PWD/bazel-bin/libprotobuf.a src/.libs/libprotobuf.a + ln -s $PWD/bazel-bin/libprotobuf_lite.a src/.libs/libprotobuf-lite.a + + # Generate python dependencies. + pushd python + python setup.py build_py + popd + + popd +} + +function bdist_wheel_cmd { + # Builds wheel with bdist_wheel, puts into wheelhouse + # + # It may sometimes be useful to use bdist_wheel for the wheel building + # process. For example, versioneer has problems with versions which are + # fixed with bdist_wheel: + # https://github.com/warner/python-versioneer/issues/121 + local abs_wheelhouse=$1 + + # Modify build version + pwd + ls + python setup.py bdist_wheel --cpp_implementation --compile_static_extension + cp dist/*.whl $abs_wheelhouse +} + +function build_wheel { + build_wheel_cmd "bdist_wheel_cmd" $@ +} + +function run_tests { + # Runs tests on installed distribution from an empty directory + python --version + python -c "from google.protobuf.pyext import _message;" +} diff --git a/libs/protobuf/kokoro/release/ruby/macos/common.cfg b/libs/protobuf/kokoro/release/python/macos/continuous.cfg similarity index 63% rename from libs/protobuf/kokoro/release/ruby/macos/common.cfg rename to libs/protobuf/kokoro/release/python/macos/continuous.cfg index cb1c08b..85cf81b 100644 --- a/libs/protobuf/kokoro/release/ruby/macos/common.cfg +++ b/libs/protobuf/kokoro/release/python/macos/continuous.cfg @@ -1,5 +1,5 @@ # Configuration for Mac OSX release builds -build_file: "protobuf/kokoro/release/ruby/macos/build_artifacts.sh" +build_file: "protobuf/kokoro/release/python/macos/build_artifacts.sh" action { define_artifacts { diff --git a/libs/protobuf/kokoro/release/python/macos/presubmit.cfg b/libs/protobuf/kokoro/release/python/macos/presubmit.cfg new file mode 100644 index 0000000..85cf81b --- /dev/null +++ b/libs/protobuf/kokoro/release/python/macos/presubmit.cfg @@ -0,0 +1,8 @@ +# Configuration for Mac OSX release builds +build_file: "protobuf/kokoro/release/python/macos/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/python/macos/release.cfg b/libs/protobuf/kokoro/release/python/macos/release.cfg new file mode 100644 index 0000000..85cf81b --- /dev/null +++ b/libs/protobuf/kokoro/release/python/macos/release.cfg @@ -0,0 +1,8 @@ +# Configuration for Mac OSX release builds +build_file: "protobuf/kokoro/release/python/macos/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/python/windows/build_artifacts.bat b/libs/protobuf/kokoro/release/python/windows/build_artifacts.bat new file mode 100644 index 0000000..121283a --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/build_artifacts.bat @@ -0,0 +1,88 @@ +REM Move scripts to root +set REPO_DIR_STAGE=%cd%\github\protobuf-stage +xcopy /S github\protobuf "%REPO_DIR_STAGE%\" +cd github\protobuf +copy kokoro\release\python\windows\build_single_artifact.bat build_single_artifact.bat + +REM Set environment variables +set PACKAGE_NAME=protobuf +set REPO_DIR=protobuf +set BUILD_DLL=OFF +set UNICODE=ON +set OTHER_TEST_DEP="setuptools==38.5.1" +set OLD_PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% + +REM Fetch multibuild +git clone https://github.com/matthew-brett/multibuild.git +REM Pin multibuild scripts at a known commit to avoid potentially unwanted future changes from +REM silently creeping in (see https://github.com/protocolbuffers/protobuf/issues/9180). +REM IMPORTANT: always pin multibuild at the same commit for: +REM - linux/build_artifacts.sh +REM - linux/build_artifacts.sh +REM - windows/build_artifacts.bat +cd multibuild +git checkout b89bb903e94308be79abefa4f436bf123ebb1313 +cd .. + +REM Install zlib +mkdir zlib +curl -L -o zlib.zip http://www.winimage.com/zLibDll/zlib123dll.zip +curl -L -o zlib-src.zip http://www.winimage.com/zLibDll/zlib123.zip +7z x zlib.zip -ozlib +7z x zlib-src.zip -ozlib\include +SET ZLIB_ROOT=%cd%\zlib +del /Q zlib.zip +del /Q zlib-src.zip + +REM Create directory for artifacts +SET ARTIFACT_DIR=%cd%\artifacts +mkdir %ARTIFACT_DIR% + +REM Build wheel + +SET PYTHON=C:\python37_32bit +SET PYTHON_VERSION=3.7 +SET PYTHON_ARCH=32 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python37 +SET PYTHON_VERSION=3.7 +SET PYTHON_ARCH=64 +CALL build_single_artifact.bat || goto :error + +powershell -File kokoro/release/python/windows/install_python_interpreters.ps1 + +SET PYTHON=C:\python38_32bit +SET PYTHON_VERSION=3.8 +SET PYTHON_ARCH=32 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python38 +SET PYTHON_VERSION=3.8 +SET PYTHON_ARCH=64 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python39_32bit +SET PYTHON_VERSION=3.9 +SET PYTHON_ARCH=32 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python39 +SET PYTHON_VERSION=3.9 +SET PYTHON_ARCH=64 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python310_32bit +SET PYTHON_VERSION=3.10 +SET PYTHON_ARCH=32 +CALL build_single_artifact.bat || goto :error + +SET PYTHON=C:\python310 +SET PYTHON_VERSION=3.10 +SET PYTHON_ARCH=64 +CALL build_single_artifact.bat || goto :error + +goto :EOF + +:error +exit /b %errorlevel% diff --git a/libs/protobuf/kokoro/release/python/windows/build_single_artifact.bat b/libs/protobuf/kokoro/release/python/windows/build_single_artifact.bat new file mode 100644 index 0000000..af2d265 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/build_single_artifact.bat @@ -0,0 +1,78 @@ +setlocal + +if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14 +if %PYTHON%==C:\python37_32bit set vcplatform=Win32 + +if %PYTHON%==C:\python37 set generator=Visual Studio 14 Win64 +if %PYTHON%==C:\python37 set vcplatform=x64 + +if %PYTHON%==C:\python38_32bit set generator=Visual Studio 14 +if %PYTHON%==C:\python38_32bit set vcplatform=Win32 + +if %PYTHON%==C:\python38 set generator=Visual Studio 14 Win64 +if %PYTHON%==C:\python38 set vcplatform=x64 + +if %PYTHON%==C:\python39_32bit set generator=Visual Studio 14 +if %PYTHON%==C:\python39_32bit set vcplatform=Win32 + +if %PYTHON%==C:\python39 set generator=Visual Studio 14 Win64 +if %PYTHON%==C:\python39 set vcplatform=x64 + +if %PYTHON%==C:\python310_32bit set generator=Visual Studio 14 +if %PYTHON%==C:\python310_32bit set vcplatform=Win32 + +if %PYTHON%==C:\python310 set generator=Visual Studio 14 Win64 +if %PYTHON%==C:\python310 set vcplatform=x64 + +REM Prepend newly installed Python to the PATH of this build (this cannot be +REM done from inside the powershell script as it would require to restart +REM the parent CMD process). +SET PATH=C:\Program Files\CMake\bin;%PYTHON%;%PYTHON%\Scripts;%OLD_PATH% +python -m pip install -U pip +pip install wheel + +REM Check that we have the expected version and architecture for Python +python --version +python -c "import struct; print(struct.calcsize('P') * 8)" + +rmdir /s/q %REPO_DIR% +xcopy /s %REPO_DIR_STAGE% "%REPO_DIR%\" + +REM Checkout release commit +cd %REPO_DIR% + +REM ====================== +REM Build Protobuf Library +REM ====================== + +mkdir src\.libs + +mkdir vcprojects +pushd vcprojects +cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=OFF ../cmake || goto :error +msbuild protobuf.sln /p:Platform=%vcplatform% /p:Configuration=Release || goto :error +dir /s /b +popd +copy vcprojects\Release\libprotobuf.lib src\.libs\libprotobuf.a +copy vcprojects\Release\libprotobuf-lite.lib src\.libs\libprotobuf-lite.a +SET PATH=%cd%\vcprojects\Release;%PATH% +dir vcprojects\Release + +REM ====================== +REM Build python library +REM ====================== + +cd python + +REM sed -i 's/\ extra_compile_args\ =\ \[\]/\ extra_compile_args\ =\ \[\'\/MT\'\]/g' setup.py + +python setup.py bdist_wheel --cpp_implementation --compile_static_extension +dir dist +copy dist\* %ARTIFACT_DIR% +dir %ARTIFACT_DIR% +cd ..\.. + +goto :EOF + +:error +exit /b %errorlevel% diff --git a/libs/protobuf/kokoro/release/python/windows/continuous.cfg b/libs/protobuf/kokoro/release/python/windows/continuous.cfg new file mode 100644 index 0000000..5261606 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/continuous.cfg @@ -0,0 +1,8 @@ +# Configuration for Windows protoc release builds +build_file: "protobuf/kokoro/release/python/windows/build_artifacts.bat" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/python/windows/install_python_interpreters.ps1 b/libs/protobuf/kokoro/release/python/windows/install_python_interpreters.ps1 new file mode 100644 index 0000000..3f8db95 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/install_python_interpreters.ps1 @@ -0,0 +1,114 @@ +#!/usr/bin/env powershell +# Install Python 3.8 for x64 and x86 in order to build wheels on Windows. +# Originally from grpc/tools/internal_ci/helper_scripts/install_python_interpreters.ps1 + +Set-StrictMode -Version 2 +$ErrorActionPreference = 'Stop' + +trap { + $ErrorActionPreference = "Continue" + Write-Error $_ + exit 1 +} + +# Avoid "Could not create SSL/TLS secure channel" +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +function Install-Python { + Param( + [string]$PythonVersion, + [string]$PythonInstaller, + [string]$PythonInstallPath, + [string]$PythonInstallerHash + ) + $PythonInstallerUrl = "https://www.python.org/ftp/python/$PythonVersion/$PythonInstaller.exe" + $PythonInstallerPath = "C:\tools\$PythonInstaller.exe" + + # Downloads installer + Write-Host "Downloading the Python installer: $PythonInstallerUrl => $PythonInstallerPath" + Invoke-WebRequest -Uri $PythonInstallerUrl -OutFile $PythonInstallerPath + + # Validates checksum + $HashFromDownload = Get-FileHash -Path $PythonInstallerPath -Algorithm MD5 + if ($HashFromDownload.Hash -ne $PythonInstallerHash) { + throw "Invalid Python installer: failed checksum!" + } + Write-Host "Python installer $PythonInstallerPath validated." + + # Installs Python + & $PythonInstallerPath /passive InstallAllUsers=1 PrependPath=1 Include_test=0 TargetDir=$PythonInstallPath + if (-Not $?) { + throw "The Python installation exited with error!" + } + + # NOTE(lidiz) Even if the install command finishes in the script, that + # doesn't mean the Python installation is finished. If using "ps" to check + # for running processes, you might see ongoing installers at this point. + # So, we needs this "hack" to reliably validate that the Python binary is + # functioning properly. + + # Wait for the installer process + Wait-Process -Name $PythonInstaller -Timeout 300 + Write-Host "Installation process exits normally." + + # Validate Python binary + $PythonBinary = "$PythonInstallPath\python.exe" + & $PythonBinary -c 'print(42)' + Write-Host "Python binary works properly." + + # Installs pip + & $PythonBinary -m ensurepip --user + + Write-Host "Python $PythonVersion installed by $PythonInstaller at $PythonInstallPath." +} + +# Python 3.8 +$Python38x86Config = @{ + PythonVersion = "3.8.0" + PythonInstaller = "python-3.8.0" + PythonInstallPath = "C:\python38_32bit" + PythonInstallerHash = "412a649d36626d33b8ca5593cf18318c" +} +Install-Python @Python38x86Config + +$Python38x64Config = @{ + PythonVersion = "3.8.0" + PythonInstaller = "python-3.8.0-amd64" + PythonInstallPath = "C:\python38" + PythonInstallerHash = "29ea87f24c32f5e924b7d63f8a08ee8d" +} +Install-Python @Python38x64Config + +# Python 3.9 +$Python39x86Config = @{ + PythonVersion = "3.9.0" + PythonInstaller = "python-3.9.0" + PythonInstallPath = "C:\python39_32bit" + PythonInstallerHash = "4a2812db8ab9f2e522c96c7728cfcccb" +} +Install-Python @Python39x86Config + +$Python39x64Config = @{ + PythonVersion = "3.9.0" + PythonInstaller = "python-3.9.0-amd64" + PythonInstallPath = "C:\python39" + PythonInstallerHash = "b61a33dc28f13b561452f3089c87eb63" +} +Install-Python @Python39x64Config + +# Python 3.10 +$Python310x86Config = @{ + PythonVersion = "3.10.0" + PythonInstaller = "python-3.10.0" + PythonInstallPath = "C:\python310_32bit" + PythonInstallerHash = "133aa48145032e341ad2a000cd3bff50" +} +Install-Python @Python310x86Config + +$Python310x64Config = @{ + PythonVersion = "3.10.0" + PythonInstaller = "python-3.10.0-amd64" + PythonInstallPath = "C:\python310" + PythonInstallerHash = "c3917c08a7fe85db7203da6dcaa99a70" +} +Install-Python @Python310x64Config diff --git a/libs/protobuf/kokoro/release/python/windows/presubmit.cfg b/libs/protobuf/kokoro/release/python/windows/presubmit.cfg new file mode 100644 index 0000000..5261606 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/presubmit.cfg @@ -0,0 +1,8 @@ +# Configuration for Windows protoc release builds +build_file: "protobuf/kokoro/release/python/windows/build_artifacts.bat" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/python/windows/release.cfg b/libs/protobuf/kokoro/release/python/windows/release.cfg new file mode 100644 index 0000000..5261606 --- /dev/null +++ b/libs/protobuf/kokoro/release/python/windows/release.cfg @@ -0,0 +1,8 @@ +# Configuration for Windows protoc release builds +build_file: "protobuf/kokoro/release/python/windows/build_artifacts.bat" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/linux/continuous.cfg b/libs/protobuf/kokoro/release/ruby/linux/continuous.cfg index 8523c22..dbc71b2 100644 --- a/libs/protobuf/kokoro/release/ruby/linux/continuous.cfg +++ b/libs/protobuf/kokoro/release/ruby/linux/continuous.cfg @@ -1 +1,8 @@ -# Keep this file empty! Use common.cfg instead. +# Configuration for Linux release builds +build_file: "protobuf/kokoro/release/ruby/linux/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/linux/presubmit.cfg b/libs/protobuf/kokoro/release/ruby/linux/presubmit.cfg index 8523c22..dbc71b2 100644 --- a/libs/protobuf/kokoro/release/ruby/linux/presubmit.cfg +++ b/libs/protobuf/kokoro/release/ruby/linux/presubmit.cfg @@ -1 +1,8 @@ -# Keep this file empty! Use common.cfg instead. +# Configuration for Linux release builds +build_file: "protobuf/kokoro/release/ruby/linux/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/linux/ruby/ruby_build.sh b/libs/protobuf/kokoro/release/ruby/linux/ruby/ruby_build.sh index 34a85ab..761b54f 100755 --- a/libs/protobuf/kokoro/release/ruby/linux/ruby/ruby_build.sh +++ b/libs/protobuf/kokoro/release/ruby/linux/ruby/ruby_build.sh @@ -5,13 +5,8 @@ set -ex # Build protoc use_bazel.sh 5.1.1 bazel build //:protoc - -# The java build setup expects protoc in the root directory. -cp bazel-bin/protoc . -export PROTOC=$PWD/protoc - -# Pull in dependencies. -git submodule update --init --recursive +cp bazel-bin/protoc src/protoc +export PROTOC=$PWD/src/protoc umask 0022 pushd ruby diff --git a/libs/protobuf/kokoro/release/ruby/macos/continuous.cfg b/libs/protobuf/kokoro/release/ruby/macos/continuous.cfg index 8523c22..cb1c08b 100644 --- a/libs/protobuf/kokoro/release/ruby/macos/continuous.cfg +++ b/libs/protobuf/kokoro/release/ruby/macos/continuous.cfg @@ -1 +1,8 @@ -# Keep this file empty! Use common.cfg instead. +# Configuration for Mac OSX release builds +build_file: "protobuf/kokoro/release/ruby/macos/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/macos/presubmit.cfg b/libs/protobuf/kokoro/release/ruby/macos/presubmit.cfg index 8523c22..cb1c08b 100644 --- a/libs/protobuf/kokoro/release/ruby/macos/presubmit.cfg +++ b/libs/protobuf/kokoro/release/ruby/macos/presubmit.cfg @@ -1 +1,8 @@ -# Keep this file empty! Use common.cfg instead. +# Configuration for Mac OSX release builds +build_file: "protobuf/kokoro/release/ruby/macos/build_artifacts.sh" + +action { + define_artifacts { + regex: "github/protobuf/artifacts/**" + } +} diff --git a/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build.sh b/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build.sh index d13c120..bbfc631 100755 --- a/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build.sh +++ b/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build.sh @@ -6,9 +6,6 @@ set -ex bazel build //:protoc export PROTOC=$PWD/bazel-bin/protoc -# Pull in dependencies. -git submodule update --init --recursive - umask 0022 pushd ruby bundle update && bundle exec rake gem:native diff --git a/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index 4002d6d..2906642 100755 --- a/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/libs/protobuf/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -8,9 +8,13 @@ sudo chown -R $(whoami) /Library/Ruby/ set +ex # rvm script is very verbose and exits with errorcode -# Fix permissions -sudo chown -R $(whoami) $HOME/.rvm/ -sudo chown -R $(whoami) /Library/Ruby/ +curl -sSL https://rvm.io/mpapis.asc | gpg --import - +curl -sSL https://rvm.io/pkuczynski.asc | gpg --import - + +# Old OpenSSL versions cannot handle the SSL certificate used by +# https://get.rvm.io, so as a workaround we download RVM directly from +# GitHub. See this issue for details: https://github.com/rvm/rvm/issues/5133 +curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s master --ruby source $HOME/.rvm/scripts/rvm set -e # rvm commands are very verbose diff --git a/libs/protobuf/kokoro/windows/bazel/build.bat b/libs/protobuf/kokoro/windows/bazel/build.bat deleted file mode 100644 index a783a07..0000000 --- a/libs/protobuf/kokoro/windows/bazel/build.bat +++ /dev/null @@ -1,41 +0,0 @@ -@rem enter repo root -cd /d %~dp0\..\..\.. - -call kokoro\windows\prepare_build_win64.bat || goto :error - -@rem Allow Bazel to create short paths. -fsutil 8dot3name set 0 - -@rem TODO(b/241475022) Use docker to guarantee better stability. - -@rem Reinstall Bazel due to corrupt installation in kokoro. -bazel version -choco install bazel -y -i --version 5.1.0 -bazel version - -@rem Set invocation ID so that bazel run is known to kokoro -uuidgen > %KOKORO_ARTIFACTS_DIR%\bazel_invocation_ids -SET /p BAZEL_INTERNAL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%\bazel_invocation_ids - -@rem Make paths as short as possible to avoid long path issues. -set BAZEL_STARTUP=--output_user_root=C:/tmp --windows_enable_symlinks -set BAZEL_FLAGS=--enable_runfiles --keep_going --test_output=errors ^ - --verbose_failures ^ - --invocation_id=%BAZEL_INTERNAL_INVOCATION_ID% ^ - --google_credentials=%KOKORO_BAZEL_AUTH_CREDENTIAL% ^ - --remote_cache=https://storage.googleapis.com/protobuf-bazel-cache/%KOKORO_JOB_NAME% - -@rem Build libraries first. -bazel %BAZEL_STARTUP% build //:protoc //:protobuf //:protobuf_lite %BAZEL_FLAGS% || goto :error - -@rem Run C++ tests. -@rem TODO(b/241484899) Enable conformance tests on windows. -bazel %BAZEL_STARTUP% test %BAZEL_FLAGS% ^ - --test_tag_filters=-conformance --build_tag_filters=-conformance ^ - //src/... @com_google_protobuf_examples//... || goto :error - -goto :EOF - -:error -echo Failed! -exit /b 1 diff --git a/libs/protobuf/kokoro/windows/bazel/common.cfg b/libs/protobuf/kokoro/windows/bazel/common.cfg deleted file mode 100644 index 52703cc..0000000 --- a/libs/protobuf/kokoro/windows/bazel/common.cfg +++ /dev/null @@ -1,27 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/windows/bazel/build.bat" -timeout_mins: 1440 - -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } - } -} -bazel_setting { - project_id: "protobuf-build" - bes_backend_address: "buildeventservice.googleapis.com" - foundry_backend_address: "remotebuildexecution.googleapis.com" - upsalite_frontend_address: "https://source.cloud.google.com" - local_execution: true - - # Need to be same as the fetch_keystore entry in the previous step. - auth_credential: { - keystore_config_id: 77103 - keyname: "kokoro_gcp_service" - } -} diff --git a/libs/protobuf/kokoro/windows/bazel/continuous.cfg b/libs/protobuf/kokoro/windows/bazel/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/bazel/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/bazel/presubmit.cfg b/libs/protobuf/kokoro/windows/bazel/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/bazel/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake/build.bat b/libs/protobuf/kokoro/windows/cmake/build.bat deleted file mode 100644 index d24e635..0000000 --- a/libs/protobuf/kokoro/windows/cmake/build.bat +++ /dev/null @@ -1,33 +0,0 @@ -@rem enter repo root -cd /d %~dp0\..\..\.. - -call kokoro\windows\prepare_build_win64.bat || goto :error - -@rem TODO(b/241475022) Use docker to guarantee better stability. -@rem TODO(b/241484899) Run conformance tests in windows. - -md build -md %KOKORO_ARTIFACTS_DIR%\logs - -cd build - -cmake .. ^ - -G "Visual Studio 15 2017" -A x64 ^ - -Dprotobuf_BUILD_EXAMPLES=ON ^ - -Dprotobuf_BUILD_CONFORMANCE=OFF ^ - -Dprotobuf_WITH_ZLIB=OFF ^ - -Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error - -cmake --build . || goto :error - -ctest --verbose -C Debug || goto :error - -goto :success - -:error -cd /d %~dp0\..\..\.. -echo Failed! -exit /b 1 - -:success -cd .. diff --git a/libs/protobuf/kokoro/windows/cmake/continuous.cfg b/libs/protobuf/kokoro/windows/cmake/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake/presubmit.cfg b/libs/protobuf/kokoro/windows/cmake/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake_install/build.bat b/libs/protobuf/kokoro/windows/cmake_install/build.bat deleted file mode 100644 index c5878de..0000000 --- a/libs/protobuf/kokoro/windows/cmake_install/build.bat +++ /dev/null @@ -1,45 +0,0 @@ -@rem enter repo root -cd /d %~dp0\..\..\.. - -call kokoro\windows\prepare_build_win64.bat || goto :error - -@rem TODO(b/241475022) Use docker to guarantee better stability. -@rem TODO(b/241484899) Run conformance tests in windows. - -md build -md %KOKORO_ARTIFACTS_DIR%\logs - -cd build - -@rem First install protobuf from source. -cmake .. ^ - -G "Visual Studio 15 2017" -A x64 ^ - -Dprotobuf_BUILD_CONFORMANCE=OFF ^ - -Dprotobuf_WITH_ZLIB=OFF || goto :error - -cmake --build . --target install || goto :error - -@rem Next run tests forcing the use of our installation. - -rm -rf * - -cmake .. ^ - -G "Visual Studio 15 2017" -A x64 ^ - -Dprotobuf_REMOVE_INSTALLED_HEADERS=ON ^ - -Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF ^ - -Dprotobuf_BUILD_CONFORMANCE=OFF ^ - -Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error - -cmake --build . --target ALL_BUILD || goto :error - -ctest --verbose -C Debug || goto :error - -goto :success - -:error -cd /d %~dp0\..\..\.. -echo Failed! -exit /b 1 - -:success -cd .. diff --git a/libs/protobuf/kokoro/windows/cmake_install/continuous.cfg b/libs/protobuf/kokoro/windows/cmake_install/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake_install/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake_install/presubmit.cfg b/libs/protobuf/kokoro/windows/cmake_install/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake_install/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake_shared/build.bat b/libs/protobuf/kokoro/windows/cmake_shared/build.bat deleted file mode 100644 index d4bb2b1..0000000 --- a/libs/protobuf/kokoro/windows/cmake_shared/build.bat +++ /dev/null @@ -1,33 +0,0 @@ -@rem enter repo root -cd /d %~dp0\..\..\.. - -call kokoro\windows\prepare_build_win64.bat || goto :error - -@rem TODO(b/241475022) Use docker to guarantee better stability. -@rem TODO(b/241484899) Run conformance tests in windows. - -md build -md %KOKORO_ARTIFACTS_DIR%\logs - -cd build - -cmake .. ^ - -G "Visual Studio 15 2017" -A x64 ^ - -Dprotobuf_BUILD_SHARED_LIBS=ON ^ - -Dprotobuf_BUILD_CONFORMANCE=OFF ^ - -Dprotobuf_WITH_ZLIB=OFF ^ - -Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error - -cmake --build . || goto :error - -ctest --verbose -C Debug || goto :error - -goto :success - -:error -cd /d %~dp0\..\..\.. -echo Failed! -exit /b 1 - -:success -cd .. diff --git a/libs/protobuf/kokoro/windows/cmake_shared/continuous.cfg b/libs/protobuf/kokoro/windows/cmake_shared/continuous.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake_shared/continuous.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/cmake_shared/presubmit.cfg b/libs/protobuf/kokoro/windows/cmake_shared/presubmit.cfg deleted file mode 100644 index 8523c22..0000000 --- a/libs/protobuf/kokoro/windows/cmake_shared/presubmit.cfg +++ /dev/null @@ -1 +0,0 @@ -# Keep this file empty! Use common.cfg instead. diff --git a/libs/protobuf/kokoro/windows/csharp/continuous.cfg b/libs/protobuf/kokoro/windows/csharp/continuous.cfg index 8523c22..f586585 100644 --- a/libs/protobuf/kokoro/windows/csharp/continuous.cfg +++ b/libs/protobuf/kokoro/windows/csharp/continuous.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/csharp/build.bat" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/windows/csharp/presubmit.cfg b/libs/protobuf/kokoro/windows/csharp/presubmit.cfg index 8523c22..f586585 100644 --- a/libs/protobuf/kokoro/windows/csharp/presubmit.cfg +++ b/libs/protobuf/kokoro/windows/csharp/presubmit.cfg @@ -1 +1,5 @@ -# Keep this file empty! Use common.cfg instead. +# Config file for running tests in Kokoro + +# Location of the build script in repository +build_file: "protobuf/kokoro/windows/csharp/build.bat" +timeout_mins: 1440 diff --git a/libs/protobuf/kokoro/windows/prepare_build_win64.bat b/libs/protobuf/kokoro/windows/prepare_build_win64.bat deleted file mode 100644 index d8eb2a2..0000000 --- a/libs/protobuf/kokoro/windows/prepare_build_win64.bat +++ /dev/null @@ -1,16 +0,0 @@ -@rem Update Chocolatey -choco upgrade -y --no-progress chocolatey -choco install -y --no-progress --pre cmake - -@rem Enable long paths. -Powershell.exe -Command "New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1 -PropertyType DWORD -Force" - -@rem Update git submodules. -git submodule update --init --recursive - -@rem Select Visual Studio 2017. -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 - -@rem Convert Windows line breaks to Unix line breaks -@rem This allows text-matching tests to pass -find . -type f -print0 | xargs -0 d2u diff --git a/libs/protobuf/m4/ac_system_extensions.m4 b/libs/protobuf/m4/ac_system_extensions.m4 new file mode 100644 index 0000000..1ca2eeb --- /dev/null +++ b/libs/protobuf/m4/ac_system_extensions.m4 @@ -0,0 +1,37 @@ +dnl Provide AC_USE_SYSTEM_EXTENSIONS for old autoconf machines. +AC_DEFUN([ACX_USE_SYSTEM_EXTENSIONS],[ + ifdef([AC_USE_SYSTEM_EXTENSIONS],[ + AC_USE_SYSTEM_EXTENSIONS + ],[ + AC_BEFORE([$0], [AC_COMPILE_IFELSE]) + AC_BEFORE([$0], [AC_RUN_IFELSE]) + + AC_REQUIRE([AC_GNU_SOURCE]) + AC_REQUIRE([AC_AIX]) + AC_REQUIRE([AC_MINIX]) + + AH_VERBATIM([__EXTENSIONS__], +[/* Enable extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif]) + AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], + [ac_cv_safe_to_define___extensions__], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([ +# define __EXTENSIONS__ 1 + AC_INCLUDES_DEFAULT])], + [ac_cv_safe_to_define___extensions__=yes], + [ac_cv_safe_to_define___extensions__=no])]) + test $ac_cv_safe_to_define___extensions__ = yes && + AC_DEFINE([__EXTENSIONS__]) + AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) + AC_DEFINE([_TANDEM_SOURCE]) + ]) +]) diff --git a/libs/protobuf/m4/acx_check_suncc.m4 b/libs/protobuf/m4/acx_check_suncc.m4 new file mode 100644 index 0000000..0a9a577 --- /dev/null +++ b/libs/protobuf/m4/acx_check_suncc.m4 @@ -0,0 +1,73 @@ +dnl Check for the presence of the Sun Studio compiler. +dnl If Sun Studio compiler is found, set appropriate flags. +dnl Additionally, Sun Studio doesn't default to 64-bit by itself, +dnl nor does it automatically look in standard Solaris places for +dnl 64-bit libs, so we must add those options and paths to the search +dnl paths. + +dnl TODO(kenton): This is pretty hacky. It sets CXXFLAGS, which the autoconf +dnl docs say should never be overridden except by the user. It also isn't +dnl cross-compile safe. We should fix these problems, but since I don't have +dnl Sun CC at my disposal for testing, someone else will have to do it. + +AC_DEFUN([ACX_CHECK_SUNCC],[ + + AC_LANG_PUSH([C++]) + AC_CHECK_DECL([__SUNPRO_CC], [SUNCC="yes"], [SUNCC="no"]) + AC_LANG_POP() + + + AC_ARG_ENABLE([64bit-solaris], + [AS_HELP_STRING([--disable-64bit-solaris], + [Build 64 bit binary on Solaris @<:@default=on@:>@])], + [ac_enable_64bit="$enableval"], + [ac_enable_64bit="yes"]) + + AS_IF([test "$SUNCC" = "yes" -a "x${ac_cv_env_CXXFLAGS_set}" = "x"],[ + dnl Sun Studio has a crashing bug with -xO4 in some cases. Keep this + dnl at -xO3 until a proper test to detect those crashes can be done. + CXXFLAGS="-g0 -xO3 -xlibmil -xdepend -xbuiltin -mt -template=no%extdef ${CXXFLAGS}" + ]) + + case $host_os in + *solaris*) + AC_CHECK_PROGS(ISAINFO, [isainfo], [no]) + AS_IF([test "x$ISAINFO" != "xno"], + [isainfo_b=`${ISAINFO} -b`], + [isainfo_b="x"]) + + AS_IF([test "$isainfo_b" != "x"],[ + + isainfo_k=`${ISAINFO} -k` + + AS_IF([test "x$ac_enable_64bit" = "xyes"],[ + + AS_IF([test "x$libdir" = "x\${exec_prefix}/lib"],[ + dnl The user hasn't overridden the default libdir, so we'll + dnl the dir suffix to match solaris 32/64-bit policy + libdir="${libdir}/${isainfo_k}" + ]) + + dnl This should just be set in CPPFLAGS and in LDFLAGS, but libtool + dnl does the wrong thing if you don't put it into CXXFLAGS. sigh. + dnl (It also needs it in CFLAGS, or it does a different wrong thing!) + CXXFLAGS="${CXXFLAGS} -m64" + ac_cv_env_CXXFLAGS_set=set + ac_cv_env_CXXFLAGS_value='-m64' + + CFLAGS="${CFLAGS} -m64" + ac_cv_env_CFLAGS_set=set + ac_cv_env_CFLAGS_value='-m64' + + AS_IF([test "$target_cpu" = "sparc" -a "x$SUNCC" = "xyes" ],[ + CXXFLAGS="-xmemalign=8s ${CXXFLAGS}" + ]) + ]) + ]) + ;; + esac + + AS_IF([test "$target_cpu" = "sparc" -a "x$SUNCC" = "xyes" ],[ + CXXFLAGS="-xregs=no%appl ${CXXFLAGS}" + ]) +]) diff --git a/libs/protobuf/m4/ax_cxx_compile_stdcxx.m4 b/libs/protobuf/m4/ax_cxx_compile_stdcxx.m4 new file mode 100644 index 0000000..d3288e2 --- /dev/null +++ b/libs/protobuf/m4/ax_cxx_compile_stdcxx.m4 @@ -0,0 +1,1001 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXX and +# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) +# or '14' (for the C++14 standard). +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik +# Copyright (c) 2012 Zack Weinberg +# Copyright (c) 2013 Roy Stogner +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov +# Copyright (c) 2015 Paul Norman +# Copyright (c) 2015 Moritz Klammler +# Copyright (c) 2016 Krzesimir Nowak +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AX_REQUIRE_DEFINED([AC_MSG_WARN]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"], + [$1], [14], [ax_cxx_compile_alternatives="14 1y"], + [$1], [17], [ax_cxx_compile_alternatives="17 1z"], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for alternative in ${ax_cxx_compile_alternatives}; do + switch="-std=gnu++${alternative}" + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + for alternative in ${ax_cxx_compile_alternatives}; do + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + if test x$ac_success = xyes; then + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + fi + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + AC_SUBST(HAVE_CXX$1) + m4_if([$1], [17], [AC_MSG_WARN([C++17 is not yet standardized, so the checks may change in incompatible ways anytime])]) +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 +) + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +#include + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + + namespace test_std_move_and_forward + { + struct message {}; + char foo(message&) { return '\0'; } + int foo(message&&) { return 0; } + + template + void check(Arg&& arg, RT rt) { + static_assert(sizeof(rt) == sizeof(foo(std::forward(arg))), ""); + } + void test() { + message a; + check(a, char()); + check(std::move(a), int()); + } + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_separators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same::value, ""); + static_assert(is_same::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) + + +dnl Tests for new features in C++17 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ + +// If the compiler admits that it is not ready for C++17, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus <= 201402L + +#error "This is not a C++17 compiler" + +#else + +#if defined(__clang__) + #define REALLY_CLANG +#else + #if defined(__GNUC__) + #define REALLY_GCC + #endif +#endif + +#include +#include +#include + +namespace cxx17 +{ + +#if !defined(REALLY_CLANG) + namespace test_constexpr_lambdas + { + + // TODO: test it with clang++ from git + + constexpr int foo = [](){return 42;}(); + + } +#endif // !defined(REALLY_CLANG) + + namespace test::nested_namespace::definitions + { + + } + + namespace test_fold_expression + { + + template + int multiply(Args... args) + { + return (args * ... * 1); + } + + template + bool all(Args... args) + { + return (args && ...); + } + + } + + namespace test_extended_static_assert + { + + static_assert (true); + + } + + namespace test_auto_brace_init_list + { + + auto foo = {5}; + auto bar {5}; + + static_assert(std::is_same, decltype(foo)>::value); + static_assert(std::is_same::value); + } + + namespace test_typename_in_template_template_parameter + { + + template typename X> struct D; + + } + + namespace test_fallthrough_nodiscard_maybe_unused_attributes + { + + int f1() + { + return 42; + } + + [[nodiscard]] int f2() + { + [[maybe_unused]] auto unused = f1(); + + switch (f1()) + { + case 17: + f1(); + [[fallthrough]]; + case 42: + f1(); + } + return f1(); + } + + } + + namespace test_extended_aggregate_initialization + { + + struct base1 + { + int b1, b2 = 42; + }; + + struct base2 + { + base2() { + b3 = 42; + } + int b3; + }; + + struct derived : base1, base2 + { + int d; + }; + + derived d1 {{1, 2}, {}, 4}; // full initialization + derived d2 {{}, {}, 4}; // value-initialized bases + + } + + namespace test_general_range_based_for_loop + { + + struct iter + { + int i; + + int& operator* () + { + return i; + } + + const int& operator* () const + { + return i; + } + + iter& operator++() + { + ++i; + return *this; + } + }; + + struct sentinel + { + int i; + }; + + bool operator== (const iter& i, const sentinel& s) + { + return i.i == s.i; + } + + bool operator!= (const iter& i, const sentinel& s) + { + return !(i == s); + } + + struct range + { + iter begin() const + { + return {0}; + } + + sentinel end() const + { + return {5}; + } + }; + + void f() + { + range r {}; + + for (auto i : r) + { + [[maybe_unused]] auto v = i; + } + } + + } + + namespace test_lambda_capture_asterisk_this_by_value + { + + struct t + { + int i; + int foo() + { + return [*this]() + { + return i; + }(); + } + }; + + } + + namespace test_enum_class_construction + { + + enum class byte : unsigned char + {}; + + byte foo {42}; + + } + + namespace test_constexpr_if + { + + template + int f () + { + if constexpr(cond) + { + return 13; + } + else + { + return 42; + } + } + + } + + namespace test_selection_statement_with_initializer + { + + int f() + { + return 13; + } + + int f2() + { + if (auto i = f(); i > 0) + { + return 3; + } + + switch (auto i = f(); i + 4) + { + case 17: + return 2; + + default: + return 1; + } + } + + } + +#if !defined(REALLY_CLANG) + namespace test_template_argument_deduction_for_class_templates + { + + // TODO: test it with clang++ from git + + template + struct pair + { + pair (T1 p1, T2 p2) + : m1 {p1}, + m2 {p2} + {} + + T1 m1; + T2 m2; + }; + + void f() + { + [[maybe_unused]] auto p = pair{13, 42u}; + } + + } +#endif // !defined(REALLY_CLANG) + + namespace test_non_type_auto_template_parameters + { + + template + struct B + {}; + + B<5> b1; + B<'a'> b2; + + } + +#if !defined(REALLY_CLANG) + namespace test_structured_bindings + { + + // TODO: test it with clang++ from git + + int arr[2] = { 1, 2 }; + std::pair pr = { 1, 2 }; + + auto f1() -> int(&)[2] + { + return arr; + } + + auto f2() -> std::pair& + { + return pr; + } + + struct S + { + int x1 : 2; + volatile double y1; + }; + + S f3() + { + return {}; + } + + auto [ x1, y1 ] = f1(); + auto& [ xr1, yr1 ] = f1(); + auto [ x2, y2 ] = f2(); + auto& [ xr2, yr2 ] = f2(); + const auto [ x3, y3 ] = f3(); + + } +#endif // !defined(REALLY_CLANG) + +#if !defined(REALLY_CLANG) + namespace test_exception_spec_type_system + { + + // TODO: test it with clang++ from git + + struct Good {}; + struct Bad {}; + + void g1() noexcept; + void g2(); + + template + Bad + f(T*, T*); + + template + Good + f(T1*, T2*); + + static_assert (std::is_same_v); + + } +#endif // !defined(REALLY_CLANG) + + namespace test_inline_variables + { + + template void f(T) + {} + + template inline T g(T) + { + return T{}; + } + + template<> inline void f<>(int) + {} + + template<> int g<>(int) + { + return 5; + } + + } + +} // namespace cxx17 + +#endif // __cplusplus <= 201402L + +]]) diff --git a/libs/protobuf/m4/ax_prog_cc_for_build.m4 b/libs/protobuf/m4/ax_prog_cc_for_build.m4 new file mode 100644 index 0000000..77fd346 --- /dev/null +++ b/libs/protobuf/m4/ax_prog_cc_for_build.m4 @@ -0,0 +1,125 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_CC_FOR_BUILD +# +# DESCRIPTION +# +# This macro searches for a C compiler that generates native executables, +# that is a C compiler that surely is not a cross-compiler. This can be +# useful if you have to generate source code at compile-time like for +# example GCC does. +# +# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything +# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD). +# The value of these variables can be overridden by the user by specifying +# a compiler with an environment variable (like you do for standard CC). +# +# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object +# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if +# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are +# substituted in the Makefile. +# +# LICENSE +# +# Copyright (c) 2008 Paolo Bonzini +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) +AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_CPP])dnl +AC_REQUIRE([AC_EXEEXT])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl + +dnl Use the standard macros, but make them use other variable names +dnl +pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl +pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl +pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl +pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl +pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl +pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl +pushdef([ac_cv_objext], ac_cv_build_objext)dnl +pushdef([ac_exeext], ac_build_exeext)dnl +pushdef([ac_objext], ac_build_objext)dnl +pushdef([CC], CC_FOR_BUILD)dnl +pushdef([CPP], CPP_FOR_BUILD)dnl +pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl +pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl +pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl +pushdef([host], build)dnl +pushdef([host_alias], build_alias)dnl +pushdef([host_cpu], build_cpu)dnl +pushdef([host_vendor], build_vendor)dnl +pushdef([host_os], build_os)dnl +pushdef([ac_cv_host], ac_cv_build)dnl +pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl +pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl +pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl +pushdef([ac_cv_host_os], ac_cv_build_os)dnl +pushdef([ac_cpp], ac_build_cpp)dnl +pushdef([ac_compile], ac_build_compile)dnl +pushdef([ac_link], ac_build_link)dnl + +save_cross_compiling=$cross_compiling +save_ac_tool_prefix=$ac_tool_prefix +cross_compiling=no +ac_tool_prefix= + +AC_PROG_CC +AC_PROG_CPP +AC_EXEEXT + +ac_tool_prefix=$save_ac_tool_prefix +cross_compiling=$save_cross_compiling + +dnl Restore the old definitions +dnl +popdef([ac_link])dnl +popdef([ac_compile])dnl +popdef([ac_cpp])dnl +popdef([ac_cv_host_os])dnl +popdef([ac_cv_host_vendor])dnl +popdef([ac_cv_host_cpu])dnl +popdef([ac_cv_host_alias])dnl +popdef([ac_cv_host])dnl +popdef([host_os])dnl +popdef([host_vendor])dnl +popdef([host_cpu])dnl +popdef([host_alias])dnl +popdef([host])dnl +popdef([LDFLAGS])dnl +popdef([CPPFLAGS])dnl +popdef([CFLAGS])dnl +popdef([CPP])dnl +popdef([CC])dnl +popdef([ac_objext])dnl +popdef([ac_exeext])dnl +popdef([ac_cv_objext])dnl +popdef([ac_cv_exeext])dnl +popdef([ac_cv_prog_cc_g])dnl +popdef([ac_cv_prog_cc_cross])dnl +popdef([ac_cv_prog_cc_works])dnl +popdef([ac_cv_prog_gcc])dnl +popdef([ac_cv_prog_CPP])dnl + +dnl Finally, set Makefile variables +dnl +BUILD_EXEEXT=$ac_build_exeext +BUILD_OBJEXT=$ac_build_objext +AC_SUBST(BUILD_EXEEXT)dnl +AC_SUBST(BUILD_OBJEXT)dnl +AC_SUBST([CFLAGS_FOR_BUILD])dnl +AC_SUBST([CPPFLAGS_FOR_BUILD])dnl +AC_SUBST([LDFLAGS_FOR_BUILD])dnl +]) diff --git a/libs/protobuf/m4/ax_prog_cxx_for_build.m4 b/libs/protobuf/m4/ax_prog_cxx_for_build.m4 new file mode 100644 index 0000000..8cc0f73 --- /dev/null +++ b/libs/protobuf/m4/ax_prog_cxx_for_build.m4 @@ -0,0 +1,110 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_cxx_for_build.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_CXX_FOR_BUILD +# +# DESCRIPTION +# +# This macro searches for a C++ compiler that generates native +# executables, that is a C++ compiler that surely is not a cross-compiler. +# This can be useful if you have to generate source code at compile-time +# like for example GCC does. +# +# The macro sets the CXX_FOR_BUILD and CXXCPP_FOR_BUILD macros to anything +# needed to compile or link (CXX_FOR_BUILD) and preprocess +# (CXXCPP_FOR_BUILD). The value of these variables can be overridden by +# the user by specifying a compiler with an environment variable (like you +# do for standard CXX). +# +# LICENSE +# +# Copyright (c) 2008 Paolo Bonzini +# Copyright (c) 2012 Avionic Design GmbH +# +# Based on the AX_PROG_CC_FOR_BUILD macro by Paolo Bonzini. +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + +AU_ALIAS([AC_PROG_CXX_FOR_BUILD], [AX_PROG_CXX_FOR_BUILD]) +AC_DEFUN([AX_PROG_CXX_FOR_BUILD], [dnl +AC_REQUIRE([AX_PROG_CC_FOR_BUILD])dnl +AC_REQUIRE([AC_PROG_CXX])dnl +AC_REQUIRE([AC_PROG_CXXCPP])dnl +AC_REQUIRE([AC_CANONICAL_HOST])dnl + +dnl Use the standard macros, but make them use other variable names +dnl +pushdef([ac_cv_prog_CXXCPP], ac_cv_build_prog_CXXCPP)dnl +pushdef([ac_cv_prog_gxx], ac_cv_build_prog_gxx)dnl +pushdef([ac_cv_prog_cxx_works], ac_cv_build_prog_cxx_works)dnl +pushdef([ac_cv_prog_cxx_cross], ac_cv_build_prog_cxx_cross)dnl +pushdef([ac_cv_prog_cxx_g], ac_cv_build_prog_cxx_g)dnl +pushdef([CXX], CXX_FOR_BUILD)dnl +pushdef([CXXCPP], CXXCPP_FOR_BUILD)dnl +pushdef([CXXFLAGS], CXXFLAGS_FOR_BUILD)dnl +pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl +pushdef([CXXCPPFLAGS], CXXCPPFLAGS_FOR_BUILD)dnl +pushdef([host], build)dnl +pushdef([host_alias], build_alias)dnl +pushdef([host_cpu], build_cpu)dnl +pushdef([host_vendor], build_vendor)dnl +pushdef([host_os], build_os)dnl +pushdef([ac_cv_host], ac_cv_build)dnl +pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl +pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl +pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl +pushdef([ac_cv_host_os], ac_cv_build_os)dnl +pushdef([ac_cxxcpp], ac_build_cxxcpp)dnl +pushdef([ac_compile], ac_build_compile)dnl +pushdef([ac_link], ac_build_link)dnl + +save_cross_compiling=$cross_compiling +save_ac_tool_prefix=$ac_tool_prefix +cross_compiling=no +ac_tool_prefix= + +AC_PROG_CXX +AC_PROG_CXXCPP + +ac_tool_prefix=$save_ac_tool_prefix +cross_compiling=$save_cross_compiling + +dnl Restore the old definitions +dnl +popdef([ac_link])dnl +popdef([ac_compile])dnl +popdef([ac_cxxcpp])dnl +popdef([ac_cv_host_os])dnl +popdef([ac_cv_host_vendor])dnl +popdef([ac_cv_host_cpu])dnl +popdef([ac_cv_host_alias])dnl +popdef([ac_cv_host])dnl +popdef([host_os])dnl +popdef([host_vendor])dnl +popdef([host_cpu])dnl +popdef([host_alias])dnl +popdef([host])dnl +popdef([CXXCPPFLAGS])dnl +popdef([CPPFLAGS])dnl +popdef([CXXFLAGS])dnl +popdef([CXXCPP])dnl +popdef([CXX])dnl +popdef([ac_cv_prog_cxx_g])dnl +popdef([ac_cv_prog_cxx_cross])dnl +popdef([ac_cv_prog_cxx_works])dnl +popdef([ac_cv_prog_gxx])dnl +popdef([ac_cv_prog_CXXCPP])dnl + +dnl Finally, set Makefile variables +dnl +AC_SUBST([CXXFLAGS_FOR_BUILD])dnl +AC_SUBST([CXXCPPFLAGS_FOR_BUILD])dnl +]) diff --git a/libs/protobuf/m4/ax_pthread.m4 b/libs/protobuf/m4/ax_pthread.m4 new file mode 100644 index 0000000..1598d07 --- /dev/null +++ b/libs/protobuf/m4/ax_pthread.m4 @@ -0,0 +1,507 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_pthread.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. It +# sets the PTHREAD_LIBS output variable to the threads library and linker +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler +# flags that are needed. (The user can also force certain compiler +# flags/libs to be tested by setting these environment variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). (This +# is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these flags, +# but also to link with them as well. For example, you might link with +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS +# +# If you are only building threaded programs, you may wish to use these +# variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant +# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the +# PTHREAD_PRIO_INHERIT symbol is defined when compiling with +# PTHREAD_CFLAGS. +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads library +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it +# is not found. If ACTION-IF-FOUND is not specified, the default action +# will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or if +# you have any other suggestions or comments. This macro was based on work +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by +# Alejandro Forero Cuervo to the autoconf macro repository. We are also +# grateful for the helpful feedback of numerous users. +# +# Updated for Autoconf 2.68 by Daniel Richard G. +# +# LICENSE +# +# Copyright (c) 2008 Steven G. Johnson +# Copyright (c) 2011 Daniel Richard G. +# Copyright (c) 2019 Marc Stevens +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 27 + +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) +AC_DEFUN([AX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_REQUIRE([AC_PROG_CC]) +AC_REQUIRE([AC_PROG_SED]) +AC_LANG_PUSH([C]) +ax_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on Tru64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then + ax_pthread_save_CC="$CC" + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) + AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) + AC_MSG_RESULT([$ax_pthread_ok]) + if test "x$ax_pthread_ok" = "xno"; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + CC="$ax_pthread_save_CC" + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items with a "," contain both +# C compiler flags (before ",") and linker flags (after ","). Other items +# starting with a "-" are C compiler flags, and remaining items are +# library names, except for "none" which indicates that we try without +# any flags at all, and "pthread-config" which is a program returning +# the flags for the Pth emulation library. + +ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 +# (Note: HP C rejects this with "bad form for `-t' option") +# -pthreads: Solaris/gcc (Note: HP C also rejects) +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads and +# -D_REENTRANT too), HP C (must be checked before -lpthread, which +# is present but should not be used directly; and before -mthreads, +# because the compiler interprets this as "-mt" + "-hreads") +# -mthreads: Mingw32/gcc, Lynx/gcc +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case $host_os in + + freebsd*) + + # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) + # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) + + ax_pthread_flags="-kthread lthread $ax_pthread_flags" + ;; + + hpux*) + + # From the cc(1) man page: "[-mt] Sets various -D flags to enable + # multi-threading and also sets -lpthread." + + ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" + ;; + + openedition*) + + # IBM z/OS requires a feature-test macro to be defined in order to + # enable POSIX threads at all, so give the user a hint if this is + # not set. (We don't define these ourselves, as they can affect + # other portions of the system API in unpredictable ways.) + + AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], + [ +# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) + AX_PTHREAD_ZOS_MISSING +# endif + ], + [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) + ;; + + solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (N.B.: The stubs are missing + # pthread_cleanup_push, or rather a function called by this macro, + # so we could check for that, but who knows whether they'll stub + # that too in a future libc.) So we'll check first for the + # standard Solaris way of linking pthreads (-mt -lpthread). + + ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags" + ;; +esac + +# Are we compiling with Clang? + +AC_CACHE_CHECK([whether $CC is Clang], + [ax_cv_PTHREAD_CLANG], + [ax_cv_PTHREAD_CLANG=no + # Note that Autoconf sets GCC=yes for Clang as well as GCC + if test "x$GCC" = "xyes"; then + AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], + [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ +# if defined(__clang__) && defined(__llvm__) + AX_PTHREAD_CC_IS_CLANG +# endif + ], + [ax_cv_PTHREAD_CLANG=yes]) + fi + ]) +ax_pthread_clang="$ax_cv_PTHREAD_CLANG" + + +# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) + +# Note that for GCC and Clang -pthread generally implies -lpthread, +# except when -nostdlib is passed. +# This is problematic using libtool to build C++ shared libraries with pthread: +# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460 +# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333 +# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555 +# To solve this, first try -pthread together with -lpthread for GCC + +AS_IF([test "x$GCC" = "xyes"], + [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"]) + +# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first + +AS_IF([test "x$ax_pthread_clang" = "xyes"], + [ax_pthread_flags="-pthread,-lpthread -pthread"]) + + +# The presence of a feature test macro requesting re-entrant function +# definitions is, on some systems, a strong hint that pthreads support is +# correctly enabled + +case $host_os in + darwin* | hpux* | linux* | osf* | solaris*) + ax_pthread_check_macro="_REENTRANT" + ;; + + aix*) + ax_pthread_check_macro="_THREAD_SAFE" + ;; + + *) + ax_pthread_check_macro="--" + ;; +esac +AS_IF([test "x$ax_pthread_check_macro" = "x--"], + [ax_pthread_check_cond=0], + [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) + + +if test "x$ax_pthread_ok" = "xno"; then +for ax_pthread_try_flag in $ax_pthread_flags; do + + case $ax_pthread_try_flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + *,*) + PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"` + PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"` + AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) + PTHREAD_CFLAGS="$ax_pthread_try_flag" + ;; + + pthread-config) + AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) + AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) + PTHREAD_LIBS="-l$ax_pthread_try_flag" + ;; + esac + + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include +# if $ax_pthread_check_cond +# error "$ax_pthread_check_macro must be defined" +# endif + static void *some_global = NULL; + static void routine(void *a) + { + /* To avoid any unused-parameter or + unused-but-set-parameter warning. */ + some_global = a; + } + static void *start_routine(void *a) { return a; }], + [pthread_t th; pthread_attr_t attr; + pthread_create(&th, 0, start_routine, 0); + pthread_join(th, 0); + pthread_attr_init(&attr); + pthread_cleanup_push(routine, 0); + pthread_cleanup_pop(0) /* ; */])], + [ax_pthread_ok=yes], + []) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + AC_MSG_RESULT([$ax_pthread_ok]) + AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + + +# Clang needs special handling, because older versions handle the -pthread +# option in a rather... idiosyncratic way + +if test "x$ax_pthread_clang" = "xyes"; then + + # Clang takes -pthread; it has never supported any other flag + + # (Note 1: This will need to be revisited if a system that Clang + # supports has POSIX threads in a separate library. This tends not + # to be the way of modern systems, but it's conceivable.) + + # (Note 2: On some systems, notably Darwin, -pthread is not needed + # to get POSIX threads support; the API is always present and + # active. We could reasonably leave PTHREAD_CFLAGS empty. But + # -pthread does define _REENTRANT, and while the Darwin headers + # ignore this macro, third-party headers might not.) + + # However, older versions of Clang make a point of warning the user + # that, in an invocation where only linking and no compilation is + # taking place, the -pthread option has no effect ("argument unused + # during compilation"). They expect -pthread to be passed in only + # when source code is being compiled. + # + # Problem is, this is at odds with the way Automake and most other + # C build frameworks function, which is that the same flags used in + # compilation (CFLAGS) are also used in linking. Many systems + # supported by AX_PTHREAD require exactly this for POSIX threads + # support, and in fact it is often not straightforward to specify a + # flag that is used only in the compilation phase and not in + # linking. Such a scenario is extremely rare in practice. + # + # Even though use of the -pthread flag in linking would only print + # a warning, this can be a nuisance for well-run software projects + # that build with -Werror. So if the active version of Clang has + # this misfeature, we search for an option to squash it. + + AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], + [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown + # Create an alternate version of $ac_link that compiles and + # links in two steps (.c -> .o, .o -> exe) instead of one + # (.c -> exe), because the warning occurs only in the second + # step + ax_pthread_save_ac_link="$ac_link" + ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' + ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` + ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" + ax_pthread_save_CFLAGS="$CFLAGS" + for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do + AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) + CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" + ac_link="$ax_pthread_save_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [ac_link="$ax_pthread_2step_ac_link" + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], + [break]) + ]) + done + ac_link="$ax_pthread_save_ac_link" + CFLAGS="$ax_pthread_save_CFLAGS" + AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) + ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" + ]) + + case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in + no | unknown) ;; + *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; + esac + +fi # $ax_pthread_clang = yes + + + +# Various other checks: +if test "x$ax_pthread_ok" = "xyes"; then + ax_pthread_save_CFLAGS="$CFLAGS" + ax_pthread_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_CACHE_CHECK([for joinable pthread attribute], + [ax_cv_PTHREAD_JOINABLE_ATTR], + [ax_cv_PTHREAD_JOINABLE_ATTR=unknown + for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], + [int attr = $ax_pthread_attr; return attr /* ; */])], + [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], + []) + done + ]) + AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ + test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ + test "x$ax_pthread_joinable_attr_defined" != "xyes"], + [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], + [$ax_cv_PTHREAD_JOINABLE_ATTR], + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + ax_pthread_joinable_attr_defined=yes + ]) + + AC_CACHE_CHECK([whether more special flags are required for pthreads], + [ax_cv_PTHREAD_SPECIAL_FLAGS], + [ax_cv_PTHREAD_SPECIAL_FLAGS=no + case $host_os in + solaris*) + ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" + ;; + esac + ]) + AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ + test "x$ax_pthread_special_flags_added" != "xyes"], + [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" + ax_pthread_special_flags_added=yes]) + + AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], + [ax_cv_PTHREAD_PRIO_INHERIT], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[int i = PTHREAD_PRIO_INHERIT; + return i;]])], + [ax_cv_PTHREAD_PRIO_INHERIT=yes], + [ax_cv_PTHREAD_PRIO_INHERIT=no]) + ]) + AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ + test "x$ax_pthread_prio_inherit_defined" != "xyes"], + [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) + ax_pthread_prio_inherit_defined=yes + ]) + + CFLAGS="$ax_pthread_save_CFLAGS" + LIBS="$ax_pthread_save_LIBS" + + # More AIX lossage: compile with *_r variant + if test "x$GCC" != "xyes"; then + case $host_os in + aix*) + AS_CASE(["x/$CC"], + [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], + [#handle absolute path differently from PATH based program lookup + AS_CASE(["x$CC"], + [x/*], + [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], + [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) + ;; + esac + fi +fi + +test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" + +AC_SUBST([PTHREAD_LIBS]) +AC_SUBST([PTHREAD_CFLAGS]) +AC_SUBST([PTHREAD_CC]) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test "x$ax_pthread_ok" = "xyes"; then + ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) + : +else + ax_pthread_ok=no + $2 +fi +AC_LANG_POP +])dnl AX_PTHREAD diff --git a/libs/protobuf/m4/stl_hash.m4 b/libs/protobuf/m4/stl_hash.m4 new file mode 100644 index 0000000..d7def1a --- /dev/null +++ b/libs/protobuf/m4/stl_hash.m4 @@ -0,0 +1,71 @@ +# We check two things: where the include file is for +# unordered_map/hash_map (we prefer the first form), and what +# namespace unordered/hash_map lives in within that include file. We +# include AC_TRY_COMPILE for all the combinations we've seen in the +# wild. We define HASH_MAP_H to the location of the header file, and +# HASH_NAMESPACE to the namespace the class (unordered_map or +# hash_map) is in. + +# This also checks if unordered map exists. +AC_DEFUN([AC_CXX_STL_HASH], + [ + AC_MSG_CHECKING(the location of hash_map) + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_cv_cxx_hash_map="" + # First try unordered_map, but not on gcc's before 4.2 -- I've + # seen unexplainable unordered_map bugs with -O2 on older gcc's. + AC_TRY_COMPILE([#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) + # error GCC too old for unordered_map + #endif + ], + [/* no program body necessary */], + [stl_hash_old_gcc=no], + [stl_hash_old_gcc=yes]) + for location in unordered_map tr1/unordered_map; do + for namespace in std std::tr1; do + if test -z "$ac_cv_cxx_hash_map" -a "$stl_hash_old_gcc" != yes; then + # Some older gcc's have a buggy tr1, so test a bit of code. + AC_TRY_COMPILE([#include <$location>], + [const ${namespace}::unordered_map t; + return t.find(5) == t.end();], + [ac_cv_cxx_hash_map="<$location>"; + ac_cv_cxx_hash_namespace="$namespace"; + ac_cv_cxx_hash_map_class="unordered_map";]) + fi + done + done + # Now try hash_map + for location in ext/hash_map hash_map; do + for namespace in __gnu_cxx "" std stdext; do + if test -z "$ac_cv_cxx_hash_map"; then + AC_TRY_COMPILE([#include <$location>], + [${namespace}::hash_map t], + [ac_cv_cxx_hash_map="<$location>"; + ac_cv_cxx_hash_namespace="$namespace"; + ac_cv_cxx_hash_map_class="hash_map";]) + fi + done + done + ac_cv_cxx_hash_set=`echo "$ac_cv_cxx_hash_map" | sed s/map/set/`; + ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`; + if test -n "$ac_cv_cxx_hash_map"; then + AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map]) + AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set]) + AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map, + [the location of or ]) + AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set, + [the location of or ]) + AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace, + [the namespace of hash_map/hash_set]) + AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class, + [the name of ]) + AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class, + [the name of ]) + AC_MSG_RESULT([$ac_cv_cxx_hash_map]) + else + AC_MSG_RESULT() + AC_MSG_WARN([could not find an STL hash_map]) + fi +]) + diff --git a/libs/protobuf/maven_install.json b/libs/protobuf/maven_install.json index efb3f03..9c5860a 100644 --- a/libs/protobuf/maven_install.json +++ b/libs/protobuf/maven_install.json @@ -1,251 +1,24 @@ { "dependency_tree": { "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", - "__INPUT_ARTIFACTS_HASH": -1875290602, - "__RESOLVED_ARTIFACTS_HASH": -1248440885, + "__INPUT_ARTIFACTS_HASH": -228414992, + "__RESOLVED_ARTIFACTS_HASH": -722345565, "conflict_resolution": { - "com.google.errorprone:error_prone_annotations:2.5.1": "com.google.errorprone:error_prone_annotations:2.11.0" + "com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.11.0", + "junit:junit:4.12": "junit:junit:4.13.2" }, "dependencies": [ { - "coord": "com.google.auto.value:auto-value-annotations:1.8.1", + "coord": "com.google.auto.value:auto-value-annotations:1.7.4", "dependencies": [], "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar", + "file": "v1/https/repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.7.4/auto-value-annotations-1.7.4.jar", "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar", - "https://repo.maven.apache.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" + "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.7.4/auto-value-annotations-1.7.4.jar", + "https://repo.maven.apache.org/maven2/com/google/auto/value/auto-value-annotations/1.7.4/auto-value-annotations-1.7.4.jar" ], - "sha256": "37ec09b47d7ed35a99d13927db5c86fc9071f620f943ead5d757144698310852", - "url": "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" - }, - { - "coord": "com.google.caliper:caliper-api:1.0-beta-3", - "dependencies": [ - "com.google.guava:guava:31.1-jre", - "joda-time:joda-time:2.10.10" - ], - "directDependencies": [ - "com.google.guava:guava:31.1-jre", - "joda-time:joda-time:2.10.10" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-api/1.0-beta-3/caliper-api-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-api/1.0-beta-3/caliper-api-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-api/1.0-beta-3/caliper-api-1.0-beta-3.jar" - ], - "sha256": "374f0c6c0c1f8784cb69d885e1dcbb7498c34ca20369e0597264568530642928", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-api/1.0-beta-3/caliper-api-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper-core:1.0-beta-3", - "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.code.gson:gson:2.8.9", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "com.squareup.okio:okio:1.6.0", - "javax.inject:javax.inject:1", - "joda-time:joda-time:2.10.10" - ], - "directDependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "joda-time:joda-time:2.10.10" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-core/1.0-beta-3/caliper-core-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-core/1.0-beta-3/caliper-core-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-core/1.0-beta-3/caliper-core-1.0-beta-3.jar" - ], - "sha256": "514deac8f8b09dd4262733e0a4406a333208c899dc7ea726b03600b9bb94f192", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-core/1.0-beta-3/caliper-core-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper-runner:1.0-beta-3", - "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.code.gson:gson:2.8.9", - "com.google.dagger:dagger-producers:2.22.1", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "com.squareup.okio:okio:1.6.0", - "javax.inject:javax.inject:1", - "joda-time:joda-time:2.10.10", - "org.checkerframework:checker-compat-qual:2.5.3" - ], - "directDependencies": [ - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.dagger:dagger-producers:2.22.1", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "joda-time:joda-time:2.10.10" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-runner/1.0-beta-3/caliper-runner-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-runner/1.0-beta-3/caliper-runner-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-runner/1.0-beta-3/caliper-runner-1.0-beta-3.jar" - ], - "sha256": "3ab58890aa01343361adedf859500d280f67813df0cedfcd165b169533b9b1fa", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-runner/1.0-beta-3/caliper-runner-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper-util:1.0-beta-3", - "dependencies": [ - "com.google.code.gson:gson:2.8.9", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "javax.inject:javax.inject:1", - "joda-time:joda-time:2.10.10" - ], - "directDependencies": [ - "com.google.code.gson:gson:2.8.9", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "joda-time:joda-time:2.10.10" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-util/1.0-beta-3/caliper-util-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-util/1.0-beta-3/caliper-util-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-util/1.0-beta-3/caliper-util-1.0-beta-3.jar" - ], - "sha256": "6e9af500c7020450dfdb5003d09501d512d395f431c54c7ee8f79e712463fe66", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-util/1.0-beta-3/caliper-util-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper-worker-jvm:1.0-beta-3", - "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.caliper:caliper-worker:1.0-beta-3", - "com.google.code.gson:gson:2.8.9", - "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "com.squareup.okio:okio:1.6.0", - "com.sun.jersey:jersey-client:1.19.4", - "com.sun.jersey:jersey-core:1.19.4", - "javax.annotation:javax.annotation-api:1.3.2", - "javax.inject:javax.inject:1", - "javax.ws.rs:jsr311-api:1.1.1", - "joda-time:joda-time:2.10.10", - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-commons:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm-util:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-worker:1.0-beta-3", - "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.sun.jersey:jersey-client:1.19.4" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-worker-jvm/1.0-beta-3/caliper-worker-jvm-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-worker-jvm/1.0-beta-3/caliper-worker-jvm-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-worker-jvm/1.0-beta-3/caliper-worker-jvm-1.0-beta-3.jar" - ], - "sha256": "e14e1ecfdf939c82abdb902105be41ff3f83c18cb968116232015f2662d065a4", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-worker-jvm/1.0-beta-3/caliper-worker-jvm-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper-worker:1.0-beta-3", - "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.code.gson:gson:2.8.9", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "com.squareup.okio:okio:1.6.0", - "javax.inject:javax.inject:1", - "joda-time:joda-time:2.10.10" - ], - "directDependencies": [ - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "joda-time:joda-time:2.10.10" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper-worker/1.0-beta-3/caliper-worker-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper-worker/1.0-beta-3/caliper-worker-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper-worker/1.0-beta-3/caliper-worker-1.0-beta-3.jar" - ], - "sha256": "315d8e51df1f60551645a0e3bf2c504d2c79762f688e6f728eb9d1d9cd9a491b", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper-worker/1.0-beta-3/caliper-worker-1.0-beta-3.jar" - }, - { - "coord": "com.google.caliper:caliper:1.0-beta-3", - "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", - "com.google.caliper:caliper-api:1.0-beta-3", - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-runner:1.0-beta-3", - "com.google.caliper:caliper-util:1.0-beta-3", - "com.google.caliper:caliper-worker-jvm:1.0-beta-3", - "com.google.caliper:caliper-worker:1.0-beta-3", - "com.google.code.gson:gson:2.8.9", - "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0", - "com.google.dagger:dagger-producers:2.22.1", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.squareup.okhttp:okhttp:2.7.5", - "com.squareup.okio:okio:1.6.0", - "com.sun.jersey:jersey-client:1.19.4", - "com.sun.jersey:jersey-core:1.19.4", - "javax.annotation:javax.annotation-api:1.3.2", - "javax.inject:javax.inject:1", - "javax.ws.rs:jsr311-api:1.1.1", - "joda-time:joda-time:2.10.10", - "org.checkerframework:checker-compat-qual:2.5.3", - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-commons:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm-util:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "com.google.caliper:caliper-core:1.0-beta-3", - "com.google.caliper:caliper-runner:1.0-beta-3", - "com.google.caliper:caliper-worker-jvm:1.0-beta-3", - "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0", - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "com.sun.jersey:jersey-client:1.19.4" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/caliper/caliper/1.0-beta-3/caliper-1.0-beta-3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/caliper/caliper/1.0-beta-3/caliper-1.0-beta-3.jar", - "https://repo.maven.apache.org/maven2/com/google/caliper/caliper/1.0-beta-3/caliper-1.0-beta-3.jar" - ], - "sha256": "d54e1bfdbe9359a79e175c217b8d472555cf20da9c5c0a18bdb1ea7db979ed8e", - "url": "https://repo1.maven.org/maven2/com/google/caliper/caliper/1.0-beta-3/caliper-1.0-beta-3.jar" + "sha256": "fedd59b0b4986c342f6ab2d182f2a4ee9fceb2c7e2d5bdc4dc764c92394a23d3", + "url": "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.7.4/auto-value-annotations-1.7.4.jar" }, { "coord": "com.google.code.findbugs:jsr305:3.0.2", @@ -271,72 +44,6 @@ "sha256": "d3999291855de495c94c743761b8ab5176cfeabe281a5ab0d8e8d45326fd703e", "url": "https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar" }, - { - "coord": "com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0", - "dependencies": [ - "com.google.guava:guava:31.1-jre", - "javax.annotation:javax.annotation-api:1.3.2", - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-commons:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm-util:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "com.google.guava:guava:31.1-jre", - "javax.annotation:javax.annotation-api:1.3.2", - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-commons:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm-util:7.2", - "org.ow2.asm:asm:9.0" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar", - "https://repo.maven.apache.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar" - ], - "sha256": "1ef5535a8bd41cf3072469f381b9ee6ab28275311a7499f53d6e52adf976fef0", - "url": "https://repo1.maven.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar" - }, - { - "coord": "com.google.dagger:dagger-producers:2.22.1", - "dependencies": [ - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "javax.inject:javax.inject:1", - "org.checkerframework:checker-compat-qual:2.5.3" - ], - "directDependencies": [ - "com.google.dagger:dagger:2.22.1", - "com.google.guava:guava:31.1-jre", - "javax.inject:javax.inject:1", - "org.checkerframework:checker-compat-qual:2.5.3" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/dagger/dagger-producers/2.22.1/dagger-producers-2.22.1.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/dagger/dagger-producers/2.22.1/dagger-producers-2.22.1.jar", - "https://repo.maven.apache.org/maven2/com/google/dagger/dagger-producers/2.22.1/dagger-producers-2.22.1.jar" - ], - "sha256": "f834a0082014213a68ff06a0f048d750178d02196c58b0b15beb367d32b97e35", - "url": "https://repo1.maven.org/maven2/com/google/dagger/dagger-producers/2.22.1/dagger-producers-2.22.1.jar" - }, - { - "coord": "com.google.dagger:dagger:2.22.1", - "dependencies": [ - "javax.inject:javax.inject:1" - ], - "directDependencies": [ - "javax.inject:javax.inject:1" - ], - "file": "v1/https/repo1.maven.org/maven2/com/google/dagger/dagger/2.22.1/dagger-2.22.1.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/google/dagger/dagger/2.22.1/dagger-2.22.1.jar", - "https://repo.maven.apache.org/maven2/com/google/dagger/dagger/2.22.1/dagger-2.22.1.jar" - ], - "sha256": "329d4340f24c4f5717af016c097e90668bfea2a5376e6aa9964b01cef3fd241a", - "url": "https://repo1.maven.org/maven2/com/google/dagger/dagger/2.22.1/dagger-2.22.1.jar" - }, { "coord": "com.google.errorprone:error_prone_annotations:2.11.0", "dependencies": [], @@ -443,7 +150,7 @@ { "coord": "com.google.truth:truth:1.1.2", "dependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", + "com.google.auto.value:auto-value-annotations:1.7.4", "com.google.errorprone:error_prone_annotations:2.11.0", "com.google.guava:guava:31.1-jre", "junit:junit:4.13.2", @@ -451,7 +158,7 @@ "org.ow2.asm:asm:9.0" ], "directDependencies": [ - "com.google.auto.value:auto-value-annotations:1.8.1", + "com.google.auto.value:auto-value-annotations:1.7.4", "com.google.errorprone:error_prone_annotations:2.11.0", "com.google.guava:guava:31.1-jre", "junit:junit:4.13.2", @@ -466,115 +173,6 @@ "sha256": "a85e03b8b6ae8780f060cfded9500a3d1b5f52808f99a2ea6da9c683313c7518", "url": "https://repo1.maven.org/maven2/com/google/truth/truth/1.1.2/truth-1.1.2.jar" }, - { - "coord": "com.squareup.okhttp:okhttp:2.7.5", - "dependencies": [ - "com.squareup.okio:okio:1.6.0" - ], - "directDependencies": [ - "com.squareup.okio:okio:1.6.0" - ], - "file": "v1/https/repo1.maven.org/maven2/com/squareup/okhttp/okhttp/2.7.5/okhttp-2.7.5.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/squareup/okhttp/okhttp/2.7.5/okhttp-2.7.5.jar", - "https://repo.maven.apache.org/maven2/com/squareup/okhttp/okhttp/2.7.5/okhttp-2.7.5.jar" - ], - "sha256": "88ac9fd1bb51f82bcc664cc1eb9c225c90dc4389d660231b4cc737bebfe7d0aa", - "url": "https://repo1.maven.org/maven2/com/squareup/okhttp/okhttp/2.7.5/okhttp-2.7.5.jar" - }, - { - "coord": "com.squareup.okio:okio:1.6.0", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/com/squareup/okio/okio/1.6.0/okio-1.6.0.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/squareup/okio/okio/1.6.0/okio-1.6.0.jar", - "https://repo.maven.apache.org/maven2/com/squareup/okio/okio/1.6.0/okio-1.6.0.jar" - ], - "sha256": "114bdc1f47338a68bcbc95abf2f5cdc72beeec91812f2fcd7b521c1937876266", - "url": "https://repo1.maven.org/maven2/com/squareup/okio/okio/1.6.0/okio-1.6.0.jar" - }, - { - "coord": "com.sun.jersey:jersey-client:1.19.4", - "dependencies": [ - "com.sun.jersey:jersey-core:1.19.4", - "javax.ws.rs:jsr311-api:1.1.1" - ], - "directDependencies": [ - "com.sun.jersey:jersey-core:1.19.4" - ], - "file": "v1/https/repo1.maven.org/maven2/com/sun/jersey/jersey-client/1.19.4/jersey-client-1.19.4.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/sun/jersey/jersey-client/1.19.4/jersey-client-1.19.4.jar", - "https://repo.maven.apache.org/maven2/com/sun/jersey/jersey-client/1.19.4/jersey-client-1.19.4.jar" - ], - "sha256": "639c825c5db580f8115bf49ffc893093526d2ed1079fbc929b6a5fbd0b2eda40", - "url": "https://repo1.maven.org/maven2/com/sun/jersey/jersey-client/1.19.4/jersey-client-1.19.4.jar" - }, - { - "coord": "com.sun.jersey:jersey-core:1.19.4", - "dependencies": [ - "javax.ws.rs:jsr311-api:1.1.1" - ], - "directDependencies": [ - "javax.ws.rs:jsr311-api:1.1.1" - ], - "file": "v1/https/repo1.maven.org/maven2/com/sun/jersey/jersey-core/1.19.4/jersey-core-1.19.4.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/com/sun/jersey/jersey-core/1.19.4/jersey-core-1.19.4.jar", - "https://repo.maven.apache.org/maven2/com/sun/jersey/jersey-core/1.19.4/jersey-core-1.19.4.jar" - ], - "sha256": "64b03198e0264849d0fc341857ebcc9c882b1909a2dc35a0972fe7d901b826e5", - "url": "https://repo1.maven.org/maven2/com/sun/jersey/jersey-core/1.19.4/jersey-core-1.19.4.jar" - }, - { - "coord": "javax.annotation:javax.annotation-api:1.3.2", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar", - "https://repo.maven.apache.org/maven2/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar" - ], - "sha256": "e04ba5195bcd555dc95650f7cc614d151e4bcd52d29a10b8aa2197f3ab89ab9b", - "url": "https://repo1.maven.org/maven2/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar" - }, - { - "coord": "javax.inject:javax.inject:1", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar", - "https://repo.maven.apache.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar" - ], - "sha256": "91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff", - "url": "https://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar" - }, - { - "coord": "javax.ws.rs:jsr311-api:1.1.1", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar", - "https://repo.maven.apache.org/maven2/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar" - ], - "sha256": "ab1534b73b5fa055808e6598a5e73b599ccda28c3159c3c0908977809422ee4a", - "url": "https://repo1.maven.org/maven2/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar" - }, - { - "coord": "joda-time:joda-time:2.10.10", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/joda-time/joda-time/2.10.10/joda-time-2.10.10.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/joda-time/joda-time/2.10.10/joda-time-2.10.10.jar", - "https://repo.maven.apache.org/maven2/joda-time/joda-time/2.10.10/joda-time-2.10.10.jar" - ], - "sha256": "dd8e7c92185a678d1b7b933f31209b6203c8ffa91e9880475a1be0346b9617e3", - "url": "https://repo1.maven.org/maven2/joda-time/joda-time/2.10.10/joda-time-2.10.10.jar" - }, { "coord": "junit:junit:4.13.2", "dependencies": [ @@ -615,18 +213,6 @@ "sha256": "d2e46555699e70361b5471a7e142f9c67855bba6907a285177ebd8ad973775d8", "url": "https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.12.7/byte-buddy-1.12.7.jar" }, - { - "coord": "org.checkerframework:checker-compat-qual:2.5.3", - "dependencies": [], - "directDependencies": [], - "file": "v1/https/repo1.maven.org/maven2/org/checkerframework/checker-compat-qual/2.5.3/checker-compat-qual-2.5.3.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/checkerframework/checker-compat-qual/2.5.3/checker-compat-qual-2.5.3.jar", - "https://repo.maven.apache.org/maven2/org/checkerframework/checker-compat-qual/2.5.3/checker-compat-qual-2.5.3.jar" - ], - "sha256": "d76b9afea61c7c082908023f0cbc1427fab9abd2df915c8b8a3e7a509bccbc6d", - "url": "https://repo1.maven.org/maven2/org/checkerframework/checker-compat-qual/2.5.3/checker-compat-qual-2.5.3.jar" - }, { "coord": "org.checkerframework:checker-qual:3.12.0", "dependencies": [], @@ -683,79 +269,6 @@ "sha256": "03d960bd5aef03c653eb000413ada15eb77cdd2b8e4448886edf5692805e35f3", "url": "https://repo1.maven.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar" }, - { - "coord": "org.ow2.asm:asm-analysis:7.2", - "dependencies": [ - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "org.ow2.asm:asm-tree:7.2" - ], - "file": "v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar", - "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar" - ], - "sha256": "be922aae60ff1ff1768e8e6544a38a7f92bd0a6d6b0b9791f94955d1bd453de2", - "url": "https://repo1.maven.org/maven2/org/ow2/asm/asm-analysis/7.2/asm-analysis-7.2.jar" - }, - { - "coord": "org.ow2.asm:asm-commons:7.2", - "dependencies": [ - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm:9.0" - ], - "file": "v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar", - "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar" - ], - "sha256": "0e86b8b179c5fb223d1a880a0ff4960b6978223984b94e62e71135f2d8ea3558", - "url": "https://repo1.maven.org/maven2/org/ow2/asm/asm-commons/7.2/asm-commons-7.2.jar" - }, - { - "coord": "org.ow2.asm:asm-tree:7.2", - "dependencies": [ - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "org.ow2.asm:asm:9.0" - ], - "file": "v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar", - "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar" - ], - "sha256": "c063f5a67fa03cdc9bd79fd1c2ea6816cc4a19473ecdfbd9e9153b408c6f2656", - "url": "https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/7.2/asm-tree-7.2.jar" - }, - { - "coord": "org.ow2.asm:asm-util:7.2", - "dependencies": [ - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm:9.0" - ], - "directDependencies": [ - "org.ow2.asm:asm-analysis:7.2", - "org.ow2.asm:asm-tree:7.2", - "org.ow2.asm:asm:9.0" - ], - "file": "v1/https/repo1.maven.org/maven2/org/ow2/asm/asm-util/7.2/asm-util-7.2.jar", - "mirror_urls": [ - "https://repo1.maven.org/maven2/org/ow2/asm/asm-util/7.2/asm-util-7.2.jar", - "https://repo.maven.apache.org/maven2/org/ow2/asm/asm-util/7.2/asm-util-7.2.jar" - ], - "sha256": "6e24913b021ffacfe8e7e053d6e0ccc731941148cfa078d4f1ed3d96904530f8", - "url": "https://repo1.maven.org/maven2/org/ow2/asm/asm-util/7.2/asm-util-7.2.jar" - }, { "coord": "org.ow2.asm:asm:9.0", "dependencies": [], diff --git a/libs/protobuf/objectivec/.clang-format b/libs/protobuf/objectivec/.clang-format index f6cb8ad..d3ff76b 100644 --- a/libs/protobuf/objectivec/.clang-format +++ b/libs/protobuf/objectivec/.clang-format @@ -1 +1,7 @@ BasedOnStyle: Google + +# Ignore pddm directives. +CommentPragmas: '^%' + +# Following the rest of the protobuf code. +ColumnLimit: 80 diff --git a/libs/protobuf/objectivec/BUILD.bazel b/libs/protobuf/objectivec/BUILD.bazel index 153894f..c18788f 100644 --- a/libs/protobuf/objectivec/BUILD.bazel +++ b/libs/protobuf/objectivec/BUILD.bazel @@ -1,6 +1,5 @@ load("@rules_cc//cc:defs.bzl", "objc_library") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//conformance:defs.bzl", "conformance_test") objc_library( name = "objectivec", @@ -91,20 +90,6 @@ objc_library( visibility = ["//visibility:public"], ) -################################################################################ -# Tests -################################################################################ - -conformance_test( - name = "conformance_test", - failure_list = "//conformance:failure_list_objc.txt", - testee = "//conformance:conformance_objc", -) - -################################################################################ -# Distribution files -################################################################################ - pkg_files( name = "dist_files", srcs = glob([ diff --git a/libs/protobuf/objectivec/DevTools/check_version_stamps.sh b/libs/protobuf/objectivec/DevTools/check_version_stamps.sh index 5972e35..a3524cb 100755 --- a/libs/protobuf/objectivec/DevTools/check_version_stamps.sh +++ b/libs/protobuf/objectivec/DevTools/check_version_stamps.sh @@ -16,7 +16,7 @@ die() { exit 1 } -readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/file.cc" +readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc" readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h" check_constant() { diff --git a/libs/protobuf/objectivec/DevTools/compile_testing_protos.sh b/libs/protobuf/objectivec/DevTools/compile_testing_protos.sh index fb8a853..69c32f9 100755 --- a/libs/protobuf/objectivec/DevTools/compile_testing_protos.sh +++ b/libs/protobuf/objectivec/DevTools/compile_testing_protos.sh @@ -25,16 +25,46 @@ case "${ACTION}" in ;; esac +# ----------------------------------------------------------------------------- +# Reusing a bunch of the protos from the protocolbuffers/protobuf tree, this +# can include some extras as there is no harm in ensuring work for C++ +# generation. + +CORE_PROTO_FILES=( + src/google/protobuf/any_test.proto + src/google/protobuf/unittest_arena.proto + src/google/protobuf/unittest_custom_options.proto + src/google/protobuf/unittest_enormous_descriptor.proto + src/google/protobuf/unittest_embed_optimize_for.proto + src/google/protobuf/unittest_empty.proto + src/google/protobuf/unittest_import.proto + src/google/protobuf/unittest_import_lite.proto + src/google/protobuf/unittest_lite.proto + src/google/protobuf/unittest_mset.proto + src/google/protobuf/unittest_mset_wire_format.proto + src/google/protobuf/unittest_no_generic_services.proto + src/google/protobuf/unittest_optimize_for.proto + src/google/protobuf/unittest.proto + src/google/protobuf/unittest_import_public.proto + src/google/protobuf/unittest_import_public_lite.proto + src/google/protobuf/unittest_drop_unknown_fields.proto + src/google/protobuf/unittest_preserve_unknown_enum.proto + src/google/protobuf/map_lite_unittest.proto + src/google/protobuf/map_proto2_unittest.proto + src/google/protobuf/map_unittest.proto + # The unittest_custom_options.proto extends the messages in descriptor.proto + # so we build it in to test extending in general. The library doesn't provide + # a descriptor as it doesn't use the classes/enums. + src/google/protobuf/descriptor.proto +) + # ----------------------------------------------------------------------------- # The objc unittest specific proto files. OBJC_TEST_PROTO_FILES=( - objectivec/Tests/any_test.proto - objectivec/Tests/map_proto2_unittest.proto - objectivec/Tests/map_unittest.proto objectivec/Tests/unittest_cycle.proto - objectivec/Tests/unittest_deprecated_file.proto objectivec/Tests/unittest_deprecated.proto + objectivec/Tests/unittest_deprecated_file.proto objectivec/Tests/unittest_extension_chain_a.proto objectivec/Tests/unittest_extension_chain_b.proto objectivec/Tests/unittest_extension_chain_c.proto @@ -42,30 +72,24 @@ OBJC_TEST_PROTO_FILES=( objectivec/Tests/unittest_extension_chain_e.proto objectivec/Tests/unittest_extension_chain_f.proto objectivec/Tests/unittest_extension_chain_g.proto - objectivec/Tests/unittest_import_public.proto - objectivec/Tests/unittest_import.proto - objectivec/Tests/unittest_mset.proto - objectivec/Tests/unittest_objc_options.proto - objectivec/Tests/unittest_objc_startup.proto objectivec/Tests/unittest_objc.proto - objectivec/Tests/unittest_preserve_unknown_enum.proto + objectivec/Tests/unittest_objc_startup.proto + objectivec/Tests/unittest_objc_options.proto objectivec/Tests/unittest_runtime_proto2.proto objectivec/Tests/unittest_runtime_proto3.proto - objectivec/Tests/unittest.proto ) OBJC_EXTENSIONS=( .pbobjc.h .pbobjc.m ) # ----------------------------------------------------------------------------- # Ensure the output dir exists -mkdir -p "${OUTPUT_DIR}" +mkdir -p "${OUTPUT_DIR}/google/protobuf" # ----------------------------------------------------------------------------- # Move to the top of the protobuf directories and ensure there is a protoc # binary to use. cd "${SRCROOT}/.." -readonly PROTOC="bazel-bin/protoc" -[[ -x "${PROTOC}" ]] || \ +[[ -x src/protoc ]] || \ die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)." # ----------------------------------------------------------------------------- @@ -73,7 +97,7 @@ RUN_PROTOC=no # Check to if all the output files exist (in case a new one got added). -for PROTO_FILE in "${OBJC_TEST_PROTO_FILES[@]}"; do +for PROTO_FILE in "${CORE_PROTO_FILES[@]}" "${OBJC_TEST_PROTO_FILES[@]}"; do DIR=${PROTO_FILE%/*} BASE_NAME=${PROTO_FILE##*/} # Drop the extension @@ -81,7 +105,7 @@ for PROTO_FILE in "${OBJC_TEST_PROTO_FILES[@]}"; do OBJC_NAME=$(echo "${BASE_NAME}" | awk -F _ '{for(i=1; i<=NF; i++) printf "%s", toupper(substr($i,1,1)) substr($i,2);}') for EXT in "${OBJC_EXTENSIONS[@]}"; do - if [[ ! -f "${OUTPUT_DIR}/${DIR}/${OBJC_NAME}${EXT}" ]]; then + if [[ ! -f "${OUTPUT_DIR}/google/protobuf/${OBJC_NAME}${EXT}" ]]; then RUN_PROTOC=yes fi done @@ -94,7 +118,9 @@ if [[ "${RUN_PROTOC}" != "yes" ]] ; then # (these patterns catch some extra stuff, but better to over sample than # under) readonly NewestInput=$(find \ - objectivec/Tests/*.proto "${PROTOC}" \ + src/google/protobuf/*.proto \ + objectivec/Tests/*.proto \ + src/.libs src/*.la src/protoc \ objectivec/DevTools/compile_testing_protos.sh \ -type f -print0 \ | xargs -0 stat -f "%m %N" \ @@ -124,13 +150,28 @@ find "${OUTPUT_DIR}" \ | xargs -0 rm -rf # ----------------------------------------------------------------------------- -# Generate the Objective C specific testing protos. +# Helper to invoke protoc +compile_protos() { + src/protoc \ + --objc_out="${OUTPUT_DIR}/google/protobuf" \ + --proto_path=src/google/protobuf/ \ + --proto_path=src \ + --experimental_allow_proto3_optional \ + "$@" +} -"${PROTOC}" \ - --objc_out="${OUTPUT_DIR}" \ - --objc_opt=expected_prefixes_path=objectivec/Tests/expected_prefixes.txt \ - --objc_opt=prefixes_must_be_registered=yes \ - --objc_opt=require_prefixes=yes \ - --proto_path=. \ - --proto_path=src \ +# ----------------------------------------------------------------------------- +# Generate most of the proto files that exist in the C++ src tree. + +# Note: there is overlap in package.Message names between some of the test +# files, so they can't be generated all at once. This works because the overlap +# isn't linked into a single binary. +for a_proto in "${CORE_PROTO_FILES[@]}" ; do + compile_protos "${a_proto}" +done + +# ----------------------------------------------------------------------------- +# Generate the Objective C specific testing protos. +compile_protos \ + --proto_path="objectivec/Tests" \ "${OBJC_TEST_PROTO_FILES[@]}" diff --git a/libs/protobuf/objectivec/DevTools/full_mac_build.sh b/libs/protobuf/objectivec/DevTools/full_mac_build.sh index afff93d..98b71a6 100755 --- a/libs/protobuf/objectivec/DevTools/full_mac_build.sh +++ b/libs/protobuf/objectivec/DevTools/full_mac_build.sh @@ -8,11 +8,6 @@ set -eu # Some base locations. readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") readonly ProtoRootDir="${ScriptDir}/../.." -readonly BazelFlags="--announce_rc --macos_minimum_os=10.9 \ - $(${ScriptDir}/../../kokoro/common/bazel_flags.sh)" - -# Invoke with BAZEL=bazelisk to use that instead. -readonly BazelBin="${BAZEL:=bazel}" printUsage() { NAME=$(basename "${0}") @@ -29,9 +24,13 @@ OPTIONS: Show this message -c, --clean Issue a clean before the normal build. + -a, --autogen + Start by rerunning autogen & configure. -r, --regenerate-descriptors Run generate_descriptor_proto.sh to regenerate all the checked in proto sources. + -j #, --jobs # + Force the number of parallel jobs (useful for debugging build issues). --core-only Skip some of the core protobuf build/checks to shorten the build time. --skip-xcode @@ -61,7 +60,25 @@ header() { echo "========================================================================" } -BAZEL=bazel +# Thanks to libtool, builds can fail in odd ways and since it eats some output +# it can be hard to spot, so force error output if make exits with a non zero. +wrapped_make() { + set +e # Don't stop if the command fails. + make $* + MAKE_EXIT_STATUS=$? + if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then + echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}" + exit ${MAKE_EXIT_STATUS} + fi + set -e +} + +NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu) +if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then + NUM_MAKE_JOBS=2 +fi + +DO_AUTOGEN=no DO_CLEAN=no REGEN_DESCRIPTORS=no CORE_ONLY=no @@ -81,9 +98,16 @@ while [[ $# != 0 ]]; do -c | --clean ) DO_CLEAN=yes ;; + -a | --autogen ) + DO_AUTOGEN=yes + ;; -r | --regenerate-descriptors ) REGEN_DESCRIPTORS=yes ;; + -j | --jobs ) + shift + NUM_MAKE_JOBS="${1}" + ;; --core-only ) CORE_ONLY=yes ;; @@ -130,9 +154,21 @@ done # Into the proto dir. cd "${ProtoRootDir}" +# if no Makefile, force the autogen. +if [[ ! -f Makefile ]] ; then + DO_AUTOGEN=yes +fi + +if [[ "${DO_AUTOGEN}" == "yes" ]] ; then + header "Running autogen & configure" + ./autogen.sh + ./configure \ + CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" +fi + if [[ "${DO_CLEAN}" == "yes" ]] ; then header "Cleaning" - "${BazelBin}" clean + wrapped_make clean if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then XCODEBUILD_CLEAN_BASE_IOS=( xcodebuild @@ -176,23 +212,26 @@ fi if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then header "Regenerating the descriptor sources." - ./generate_descriptor_proto.sh + ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}" fi if [[ "${CORE_ONLY}" == "yes" ]] ; then header "Building core Only" - "${BazelBin}" build //:protoc //:protobuf //:protobuf_lite $BazelFlags + wrapped_make -j "${NUM_MAKE_JOBS}" else header "Building" # Can't issue these together, when fully parallel, something sometimes chokes # at random. - "${BazelBin}" test //src/... $BazelFlags + wrapped_make -j "${NUM_MAKE_JOBS}" all + wrapped_make -j "${NUM_MAKE_JOBS}" check # Fire off the conformance tests also. - "${BazelBin}" test //objectivec:conformance_test $BazelFlags + cd conformance + wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp + cd .. fi # Ensure the WKT sources checked in are current. -BAZEL="${BazelBin}" objectivec/generate_well_known_types.sh --check-only $BazelFlags +objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}" header "Checking on the ObjC Runtime Code" # Some of the kokoro machines don't have python3 yet, so fall back to python if need be. @@ -225,11 +264,38 @@ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then # just pick a mix of OS Versions and 32/64 bit. # NOTE: Different Xcode have different simulated hardware/os support. case "${XCODE_VERSION}" in - [6-9].* | 1[0-2].* ) - echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2 + [6-8].* ) + echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2 + echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2 exit 11 ;; - 13.* | 14.*) + 9.[0-2]* ) + XCODEBUILD_TEST_BASE_IOS+=( + -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit + # 9.0-9.2 all seem to often fail running destinations in parallel + -disable-concurrent-testing + ) + ;; + 9.[3-4]* ) + XCODEBUILD_TEST_BASE_IOS+=( + # Xcode 9.3 chokes targeting iOS 8.x - http://www.openradar.me/39335367 + -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit + # 9.3 also seems to often fail running destinations in parallel + -disable-concurrent-testing + ) + ;; + 10.*) + XCODEBUILD_TEST_BASE_IOS+=( + -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit + # 10.x also seems to often fail running destinations in parallel (with + # 32bit one include at least) + -disable-concurrent-destination-testing + ) + ;; + 11.* | 12.* | 13.* | 14.*) # Dropped 32bit as Apple doesn't seem support the simulators either. XCODEBUILD_TEST_BASE_IOS+=( -destination "platform=iOS Simulator,name=iPhone 8,OS=latest" # 64bit @@ -266,8 +332,9 @@ if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then XCODEBUILD_TEST_BASE_OSX+=( -quiet ) fi case "${XCODE_VERSION}" in - [6-9].* | 1[0-2].* ) - echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2 + [6-8].* ) + echo "ERROR: The unittests include Swift code that is now Swift 4.0." 1>&2 + echo "ERROR: Xcode 9.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2 exit 11 ;; esac @@ -287,10 +354,15 @@ if [[ "${DO_XCODE_TVOS_TESTS}" == "yes" ]] ; then -scheme ProtocolBuffers ) case "${XCODE_VERSION}" in - [6-9].* | 1[0-2].* ) - echo "ERROR: Xcode 13.3.1 or higher is required." 1>&2 + [6-9].* ) + echo "ERROR: Xcode 10.0 or higher is required to build the test suite." 1>&2 exit 11 ;; + 10.* | 11.* | 12.*) + XCODEBUILD_TEST_BASE_TVOS+=( + -destination "platform=tvOS Simulator,name=Apple TV 4K,OS=latest" + ) + ;; 13.* | 14.*) XCODEBUILD_TEST_BASE_TVOS+=( -destination "platform=tvOS Simulator,name=Apple TV 4K (2nd generation),OS=latest" @@ -319,7 +391,9 @@ fi if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then header "Running ObjC Conformance Tests" - "${BazelBin}" test //objectivec:conformance_test $BazelFlags + cd conformance + wrapped_make -j "${NUM_MAKE_JOBS}" test_objc + cd .. fi echo "" diff --git a/libs/protobuf/objectivec/DevTools/pddm.py b/libs/protobuf/objectivec/DevTools/pddm.py index 11925b1..60ff089 100755 --- a/libs/protobuf/objectivec/DevTools/pddm.py +++ b/libs/protobuf/objectivec/DevTools/pddm.py @@ -485,13 +485,14 @@ class SourceFile(object): if self._macro_collection: # Always add a blank line, seems to read better. (If need be, add an # option to the EXPAND to indicate if this should be done.) - result.extend([_GENERATED_CODE_LINE, '']) + result.extend([_GENERATED_CODE_LINE, '// clang-format off', '']) macro = line[directive_len:].strip() try: expand_result = self._macro_collection.Expand(macro) # Since expansions are line oriented, strip trailing whitespace # from the lines. lines = [x.rstrip() for x in expand_result.split('\n')] + lines.append('// clang-format on') result.append('\n'.join(lines)) except PDDMError as e: raise PDDMError('%s\n...while expanding "%s" from the section' diff --git a/libs/protobuf/objectivec/DevTools/pddm_tests.py b/libs/protobuf/objectivec/DevTools/pddm_tests.py index 2d9c47f..d5b88c9 100755 --- a/libs/protobuf/objectivec/DevTools/pddm_tests.py +++ b/libs/protobuf/objectivec/DevTools/pddm_tests.py @@ -418,18 +418,24 @@ baz foo //%PDDM-EXPAND mumble(abc) // This block of code is generated, do not edit it directly. +// clang-format off abc: doAbc(int abc); +// clang-format on //%PDDM-EXPAND-END mumble(abc) bar //%PDDM-EXPAND mumble(def) // This block of code is generated, do not edit it directly. +// clang-format off def: doDef(int def); +// clang-format on //%PDDM-EXPAND mumble(ghi) // This block of code is generated, do not edit it directly. +// clang-format off ghi: doGhi(int ghi); +// clang-format on //%PDDM-EXPAND-END (2 expansions) baz //%PDDM-DEFINE mumble(a_) diff --git a/libs/protobuf/objectivec/GPBAny.pbobjc.h b/libs/protobuf/objectivec/GPBAny.pbobjc.h index 3edf349..7fb4129 100644 --- a/libs/protobuf/objectivec/GPBAny.pbobjc.h +++ b/libs/protobuf/objectivec/GPBAny.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/any.proto #import "GPBDescriptor.h" @@ -99,6 +98,7 @@ typedef GPB_ENUM(GPBAny_FieldNumber) { * in the type URL, for example "foo.bar.com/x/y.z" will yield type * name "y.z". * + * * JSON * * The JSON representation of an `Any` value uses the regular @@ -172,5 +172,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBAny.pbobjc.m b/libs/protobuf/objectivec/GPBAny.pbobjc.m index 7f62f11..7632c8c 100644 --- a/libs/protobuf/objectivec/GPBAny.pbobjc.m +++ b/libs/protobuf/objectivec/GPBAny.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/any.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -99,5 +98,3 @@ typedef struct GPBAny__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBApi.pbobjc.h b/libs/protobuf/objectivec/GPBApi.pbobjc.h index 11b5400..871e908 100644 --- a/libs/protobuf/objectivec/GPBApi.pbobjc.h +++ b/libs/protobuf/objectivec/GPBApi.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/api.proto #import "GPBDescriptor.h" @@ -75,12 +74,12 @@ GPB_FINAL @interface GPBApi : GPBMessage /** The methods of this interface, in unspecified order. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *methodsArray; -/** The number of items in @c methodsArray without causing the container to be created. */ +/** The number of items in @c methodsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger methodsArray_Count; /** Any metadata attached to the interface. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; /** @@ -116,7 +115,7 @@ GPB_FINAL @interface GPBApi : GPBMessage /** Included interfaces. See [Mixin][]. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *mixinsArray; -/** The number of items in @c mixinsArray without causing the container to be created. */ +/** The number of items in @c mixinsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger mixinsArray_Count; /** The source syntax of the service. */ @@ -170,7 +169,7 @@ GPB_FINAL @interface GPBMethod : GPBMessage /** Any metadata attached to the method. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; /** The source syntax of this method. */ @@ -297,5 +296,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBApi.pbobjc.m b/libs/protobuf/objectivec/GPBApi.pbobjc.m index 18c4c64..7f86a08 100644 --- a/libs/protobuf/objectivec/GPBApi.pbobjc.m +++ b/libs/protobuf/objectivec/GPBApi.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/api.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -353,5 +352,3 @@ typedef struct GPBMixin__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBArray.h b/libs/protobuf/objectivec/GPBArray.h index 4985dbe..5aea75c 100644 --- a/libs/protobuf/objectivec/GPBArray.h +++ b/libs/protobuf/objectivec/GPBArray.h @@ -34,11 +34,9 @@ NS_ASSUME_NONNULL_BEGIN -// Disable clang-format for the macros. -// clang-format off - //%PDDM-EXPAND DECLARE_ARRAYS() // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int32 @@ -137,8 +135,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -150,8 +147,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -311,8 +307,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -324,8 +319,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -485,8 +479,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -498,8 +491,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -659,8 +651,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -672,8 +663,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -833,8 +823,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -846,8 +835,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -1007,8 +995,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1020,8 +1007,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -1181,8 +1167,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1194,8 +1179,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -1386,8 +1370,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1399,8 +1382,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; // These methods bypass the validationFunc to provide access to values that were not // known at the time the binary was compiled. @@ -1422,8 +1404,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; +- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1435,8 +1416,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, - BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; // If value is not a valid enumerator as defined by validationFunc, these // methods will assert in debug, and will log in release and assign the value @@ -1556,6 +1536,7 @@ NS_ASSUME_NONNULL_BEGIN @end +// clang-format on //%PDDM-EXPAND-END DECLARE_ARRAYS() NS_ASSUME_NONNULL_END @@ -1800,8 +1781,7 @@ NS_ASSUME_NONNULL_END //% * **idx**: The index of the current value. //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ -//%- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, -//% BOOL *stop))block; +//%- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%/** //% * Enumerates the values on this array with the given block. @@ -1813,8 +1793,7 @@ NS_ASSUME_NONNULL_END //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ //%- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts -//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, -//% BOOL *stop))block; +//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%// If value is not a valid enumerator as defined by validationFunc, these //%// methods will assert in debug, and will log in release and assign the value @@ -1844,8 +1823,7 @@ NS_ASSUME_NONNULL_END //% * **idx**: The index of the current value. //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ -//%- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, -//% BOOL *stop))block; +//%- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%/** //% * Enumerates the values on this array with the given block. @@ -1857,8 +1835,7 @@ NS_ASSUME_NONNULL_END //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ //%- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts -//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, -//% BOOL *stop))block; +//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //%PDDM-DEFINE ARRAY_MUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME) //%/** @@ -1990,5 +1967,3 @@ NS_ASSUME_NONNULL_END //% //%// No validation applies to these methods. //% - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBArray.m b/libs/protobuf/objectivec/GPBArray.m index eba7d15..bb9a077 100644 --- a/libs/protobuf/objectivec/GPBArray.m +++ b/libs/protobuf/objectivec/GPBArray.m @@ -47,9 +47,6 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return (value != kGPBUnrecognizedEnumeratorValue); } -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE VALIDATE_RANGE(INDEX, COUNT) //% if (INDEX >= COUNT) { //% [NSException raise:NSRangeException @@ -197,12 +194,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { //% return result; //%} //% -//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void(NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { +//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { //% [self enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; //%} //% //%- (void)enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)opts -//% ACCESSOR_NAME$S usingBlock:(void(NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { +//% ACCESSOR_NAME$S usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { //% // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). //% BOOL stop = NO; //% if ((opts & NSEnumerationReverse) == 0) { @@ -295,8 +292,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { //% _values[idx2] = temp; //%} //% + //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int32, int32_t, %d) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int32 @@ -407,12 +406,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -543,8 +542,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt32, uint32_t, %u) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt32 @@ -655,12 +656,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -791,8 +792,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int64, int64_t, %lld) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int64 @@ -903,12 +906,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1039,8 +1042,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt64, uint64_t, %llu) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt64 @@ -1151,12 +1156,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1287,8 +1292,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Float, float, %f) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Float @@ -1399,12 +1406,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1535,8 +1542,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Double, double, %lf) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Double @@ -1647,12 +1656,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1783,8 +1792,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Bool, BOOL, %d) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool @@ -1895,12 +1906,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -2031,9 +2042,8 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { @end -//%PDDM-EXPAND-END (7 expansions) - // clang-format on +//%PDDM-EXPAND-END (7 expansions) #pragma mark - Enum @@ -2056,15 +2066,19 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return [[[self alloc] initWithValidationFunction:func] autorelease]; } -+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func rawValue:(int32_t)value { - return [[[self alloc] initWithValidationFunction:func rawValues:&value count:1] autorelease]; ++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func + rawValue:(int32_t)value { + return [[[self alloc] initWithValidationFunction:func + rawValues:&value + count:1] autorelease]; } + (instancetype)arrayWithValueArray:(GPBEnumArray *)array { - return [[(GPBEnumArray *)[self alloc] initWithValueArray:array] autorelease]; + return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease]; } -+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func capacity:(NSUInteger)count { ++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func + capacity:(NSUInteger)count { return [[[self alloc] initWithValidationFunction:func capacity:count] autorelease]; } @@ -2087,7 +2101,7 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t[])values + rawValues:(const int32_t [])values count:(NSUInteger)count { self = [self initWithValidationFunction:func]; if (self) { @@ -2099,16 +2113,17 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { _count = count; } else { [self release]; - [NSException - raise:NSMallocException - format:@"Failed to allocate %lu bytes", (unsigned long)(count * sizeof(int32_t))]; + [NSException raise:NSMallocException + format:@"Failed to allocate %lu bytes", + (unsigned long)(count * sizeof(int32_t))]; } } } return self; } -- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func capacity:(NSUInteger)count { +- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func + capacity:(NSUInteger)count { self = [self initWithValidationFunction:func]; if (self && count) { [self internalResizeToCapacity:count]; @@ -2117,16 +2132,15 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } - (instancetype)copyWithZone:(NSZone *)zone { - return [[GPBEnumArray allocWithZone:zone] initWithValidationFunction:_validationFunc - rawValues:_values - count:_count]; + return [[GPBEnumArray allocWithZone:zone] + initWithValidationFunction:_validationFunc + rawValues:_values + count:_count]; } -// Disable clang-format for the macros. -// clang-format off - //%PDDM-EXPAND ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d) // This block of code is generated, do not edit it directly. +// clang-format off - (void)dealloc { NSAssert(!_autocreator, @@ -2166,12 +2180,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateRawValuesWithBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateRawValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -2186,22 +2200,21 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } } } +// clang-format on //%PDDM-EXPAND-END ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d) -// clang-format on - - (int32_t)valueAtIndex:(NSUInteger)index { - // clang-format off //%PDDM-EXPAND VALIDATE_RANGE(index, _count) // This block of code is generated, do not edit it directly. +// clang-format off if (index >= _count) { [NSException raise:NSRangeException format:@"Index (%lu) beyond bounds (%lu)", (unsigned long)index, (unsigned long)_count]; } +// clang-format on //%PDDM-EXPAND-END VALIDATE_RANGE(index, _count) - // clang-format on int32_t result = _values[index]; if (!_validationFunc(result)) { result = kGPBUnrecognizedEnumeratorValue; @@ -2210,28 +2223,26 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } - (int32_t)rawValueAtIndex:(NSUInteger)index { - // clang-format off //%PDDM-EXPAND VALIDATE_RANGE(index, _count) // This block of code is generated, do not edit it directly. +// clang-format off if (index >= _count) { [NSException raise:NSRangeException format:@"Index (%lu) beyond bounds (%lu)", (unsigned long)index, (unsigned long)_count]; } +// clang-format on //%PDDM-EXPAND-END VALIDATE_RANGE(index, _count) - // clang-format on return _values[index]; } -- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop)) - block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop)) - block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; GPBEnumValidationFunc func = _validationFunc; @@ -2260,10 +2271,9 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } } -// clang-format off - //%PDDM-EXPAND ARRAY_MUTABLE_CORE(Enum, int32_t, Raw, %d) // This block of code is generated, do not edit it directly. +// clang-format off - (void)internalResizeToCapacity:(NSUInteger)newCapacity { _values = reallocf(_values, newCapacity * sizeof(int32_t)); @@ -2369,8 +2379,10 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { _values[idx2] = temp; } +// clang-format on //%PDDM-EXPAND MUTATION_METHODS(Enum, int32_t, , EnumValidationList, EnumValidationOne) // This block of code is generated, do not edit it directly. +// clang-format off - (void)addValue:(int32_t)value { [self addValues:&value count:1]; @@ -2437,6 +2449,7 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } _values[index] = value; } +// clang-format on //%PDDM-EXPAND-END (2 expansions) //%PDDM-DEFINE MUTATION_HOOK_EnumValidationList() @@ -2457,8 +2470,6 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { //% } //% -// clang-format on - @end #pragma mark - NSArray Subclass @@ -2468,7 +2479,8 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } - (void)dealloc { - NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@", + NSAssert(!_autocreator, + @"%@: Autocreator must be cleared before release, autocreator: %@", [self class], _autocreator); [_array release]; [super dealloc]; @@ -2544,17 +2556,17 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { } - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state - objects:(id __unsafe_unretained[])buffer + objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len { return [_array countByEnumeratingWithState:state objects:buffer count:len]; } -- (void)enumerateObjectsUsingBlock:(void(NS_NOESCAPE ^)(id obj, NSUInteger idx, BOOL *stop))block { +- (void)enumerateObjectsUsingBlock:(void (NS_NOESCAPE ^)(id obj, NSUInteger idx, BOOL *stop))block { [_array enumerateObjectsUsingBlock:block]; } - (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(id obj, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(id obj, NSUInteger idx, BOOL *stop))block { [_array enumerateObjectsWithOptions:opts usingBlock:block]; } diff --git a/libs/protobuf/objectivec/GPBArray_PackagePrivate.h b/libs/protobuf/objectivec/GPBArray_PackagePrivate.h index 35a4538..07eab89 100644 --- a/libs/protobuf/objectivec/GPBArray_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBArray_PackagePrivate.h @@ -54,6 +54,7 @@ //%PDDM-EXPAND DECLARE_ARRAY_EXTRAS() // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int32 @@ -119,6 +120,7 @@ } @end +// clang-format on //%PDDM-EXPAND-END DECLARE_ARRAY_EXTRAS() #pragma mark - NSArray Subclass diff --git a/libs/protobuf/objectivec/GPBBootstrap.h b/libs/protobuf/objectivec/GPBBootstrap.h index 4fbcbab..ea5986b 100644 --- a/libs/protobuf/objectivec/GPBBootstrap.h +++ b/libs/protobuf/objectivec/GPBBootstrap.h @@ -42,7 +42,7 @@ // Used in the generated code to give sizes to enums. int32_t was chosen based // on the fact that Protocol Buffers enums are limited to this range. #if !__has_feature(objc_fixed_enum) -#error All supported Xcode versions should support objc_fixed_enum. + #error All supported Xcode versions should support objc_fixed_enum. #endif // If the headers are imported into Objective-C++, we can run into an issue @@ -52,11 +52,9 @@ // providing a local definition. The default case has to use NS_ENUM for the // magic that is Swift bridging of enums. #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L) -#define GPB_ENUM(X) \ - enum X : int32_t X; \ - enum X : int32_t + #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t #else -#define GPB_ENUM(X) NS_ENUM(int32_t, X) + #define GPB_ENUM(X) NS_ENUM(int32_t, X) #endif /** @@ -140,6 +138,7 @@ // - Gets changed when support for the older generated code is dropped. #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001 + // This is a legacy constant now frozen in time for old generated code. If // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then // this should also change to break code compiled with an old runtime that diff --git a/libs/protobuf/objectivec/GPBCodedInputStream.h b/libs/protobuf/objectivec/GPBCodedInputStream.h index cbfaaf1..1886ccf 100644 --- a/libs/protobuf/objectivec/GPBCodedInputStream.h +++ b/libs/protobuf/objectivec/GPBCodedInputStream.h @@ -30,9 +30,8 @@ #import -#import "GPBExtensionRegistry.h" - @class GPBMessage; +@class GPBExtensionRegistry; NS_ASSUME_NONNULL_BEGIN @@ -185,7 +184,7 @@ CF_EXTERN_C_END * extensions for message. **/ - (void)readMessage:(GPBMessage *)message - extensionRegistry:(nullable id)extensionRegistry; + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; /** * Reads and discards a single field, given its tag value. diff --git a/libs/protobuf/objectivec/GPBCodedInputStream.m b/libs/protobuf/objectivec/GPBCodedInputStream.m index ad5c75e..c459391 100644 --- a/libs/protobuf/objectivec/GPBCodedInputStream.m +++ b/libs/protobuf/objectivec/GPBCodedInputStream.m @@ -36,7 +36,8 @@ #import "GPBUtilities_PackagePrivate.h" #import "GPBWireFormat.h" -NSString *const GPBCodedInputStreamException = GPBNSStringifySymbol(GPBCodedInputStreamException); +NSString *const GPBCodedInputStreamException = + GPBNSStringifySymbol(GPBCodedInputStreamException); NSString *const GPBCodedInputStreamUnderlyingErrorKey = GPBNSStringifySymbol(GPBCodedInputStreamUnderlyingErrorKey); @@ -54,14 +55,16 @@ static const NSUInteger kDefaultRecursionLimit = 100; static void RaiseException(NSInteger code, NSString *reason) { NSDictionary *errorInfo = nil; if ([reason length]) { - errorInfo = @{GPBErrorReasonKey : reason}; + errorInfo = @{ GPBErrorReasonKey: reason }; } NSError *error = [NSError errorWithDomain:GPBCodedInputStreamErrorDomain code:code userInfo:errorInfo]; - NSDictionary *exceptionInfo = @{GPBCodedInputStreamUnderlyingErrorKey : error}; - [[NSException exceptionWithName:GPBCodedInputStreamException reason:reason + NSDictionary *exceptionInfo = + @{ GPBCodedInputStreamUnderlyingErrorKey: error }; + [[NSException exceptionWithName:GPBCodedInputStreamException + reason:reason userInfo:exceptionInfo] raise]; } @@ -102,7 +105,7 @@ static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) { static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) { CheckSize(state, sizeof(int64_t)); // Not using OSReadLittleInt64 because it has undocumented dependency - // on reads being aligned. + // on reads being aligned. int64_t value; memcpy(&value, state->bytes + state->bufferPos, sizeof(int64_t)); value = OSSwapLittleToHostInt64(value); @@ -212,7 +215,8 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) { state->lastTag = ReadRawVarint32(state); // Tags have to include a valid wireformat. if (!GPBWireFormatIsValidTag(state->lastTag)) { - RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Invalid wireformat in tag."); + RaiseException(GPBCodedInputStreamErrorInvalidTag, + @"Invalid wireformat in tag."); } // Zero is not a valid field number. if (GPBWireFormatGetTagFieldNumber(state->lastTag) == 0) { @@ -222,7 +226,8 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) { return state->lastTag; } -NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state) { +NSString *GPBCodedInputStreamReadRetainedString( + GPBCodedInputStreamState *state) { int32_t size = ReadRawVarint32(state); NSString *result; if (size == 0) { @@ -249,24 +254,28 @@ NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) { int32_t size = ReadRawVarint32(state); if (size < 0) return nil; CheckSize(state, size); - NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos length:size]; + NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos + length:size]; state->bufferPos += size; return result; } -NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) { +NSData *GPBCodedInputStreamReadRetainedBytesNoCopy( + GPBCodedInputStreamState *state) { int32_t size = ReadRawVarint32(state); if (size < 0) return nil; CheckSize(state, size); // Cast is safe because freeWhenDone is NO. - NSData *result = [[NSData alloc] initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos) - length:size - freeWhenDone:NO]; + NSData *result = [[NSData alloc] + initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos) + length:size + freeWhenDone:NO]; state->bufferPos += size; return result; } -size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit) { +size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, + size_t byteLimit) { byteLimit += state->bufferPos; size_t oldLimit = state->currentLimit; if (byteLimit > oldLimit) { @@ -276,7 +285,8 @@ size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byte return oldLimit; } -void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit) { +void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, + size_t oldLimit) { state->currentLimit = oldLimit; } @@ -285,10 +295,12 @@ size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) { } BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) { - return (state->bufferPos == state->bufferSize) || (state->bufferPos == state->currentLimit); + return (state->bufferPos == state->bufferSize) || + (state->bufferPos == state->currentLimit); } -void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value) { +void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, + int32_t value) { if (state->lastTag != value) { RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read"); } @@ -348,8 +360,8 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t case GPBWireFormatStartGroup: [self skipMessage]; GPBCodedInputStreamCheckLastTagWas( - &state_, - GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), GPBWireFormatEndGroup)); + &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), + GPBWireFormatEndGroup)); return YES; case GPBWireFormatEndGroup: return NO; @@ -422,26 +434,27 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t - (void)readGroup:(int32_t)fieldNumber message:(GPBMessage *)message - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { CheckRecursionLimit(&state_); ++state_.recursionDepth; [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; - GPBCodedInputStreamCheckLastTagWas(&state_, - GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); + GPBCodedInputStreamCheckLastTagWas( + &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); --state_.recursionDepth; } -- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message { +- (void)readUnknownGroup:(int32_t)fieldNumber + message:(GPBUnknownFieldSet *)message { CheckRecursionLimit(&state_); ++state_.recursionDepth; [message mergeFromCodedInputStream:self]; - GPBCodedInputStreamCheckLastTagWas(&state_, - GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); + GPBCodedInputStreamCheckLastTagWas( + &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); --state_.recursionDepth; } - (void)readMessage:(GPBMessage *)message - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { CheckRecursionLimit(&state_); int32_t length = ReadRawVarint32(&state_); size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); @@ -453,14 +466,15 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t } - (void)readMapEntry:(id)mapDictionary - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry field:(GPBFieldDescriptor *)field parentMessage:(GPBMessage *)parentMessage { CheckRecursionLimit(&state_); int32_t length = ReadRawVarint32(&state_); size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); ++state_.recursionDepth; - GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, parentMessage); + GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, + parentMessage); GPBCodedInputStreamCheckLastTagWas(&state_, 0); --state_.recursionDepth; GPBCodedInputStreamPopLimit(&state_, oldLimit); diff --git a/libs/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h b/libs/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h index 2dfc902..43ec6e7 100644 --- a/libs/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h @@ -61,15 +61,16 @@ typedef struct GPBCodedInputStreamState { // support for older data. - (void)readGroup:(int32_t)fieldNumber message:(GPBMessage *)message - extensionRegistry:(id)extensionRegistry; + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; // Reads a group field value from the stream and merges it into the given // UnknownFieldSet. -- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message; +- (void)readUnknownGroup:(int32_t)fieldNumber + message:(GPBUnknownFieldSet *)message; // Reads a map entry. - (void)readMapEntry:(id)mapDictionary - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry field:(GPBFieldDescriptor *)field parentMessage:(GPBMessage *)parentMessage; @end @@ -96,13 +97,16 @@ NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state) __attribute((ns_returns_retained)); NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) __attribute((ns_returns_retained)); -NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) - __attribute((ns_returns_retained)); +NSData *GPBCodedInputStreamReadRetainedBytesNoCopy( + GPBCodedInputStreamState *state) __attribute((ns_returns_retained)); -size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit); -void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit); +size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, + size_t byteLimit); +void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, + size_t oldLimit); size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state); BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state); -void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value); +void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, + int32_t value); CF_EXTERN_C_END diff --git a/libs/protobuf/objectivec/GPBCodedOutputStream.h b/libs/protobuf/objectivec/GPBCodedOutputStream.h index 304a24e..5dde974 100644 --- a/libs/protobuf/objectivec/GPBCodedOutputStream.h +++ b/libs/protobuf/objectivec/GPBCodedOutputStream.h @@ -171,13 +171,13 @@ extern NSString *const GPBCodedOutputStreamException_WriteFailed; * @param offset The offset into the blob to start writing out. * @param length The number of bytes from the blob to write out. **/ -- (void)writeRawPtr:(const void *)data offset:(size_t)offset length:(size_t)length; - -// Disable clang-format for the macros. -// clang-format off +- (void)writeRawPtr:(const void *)data + offset:(size_t)offset + length:(size_t)length; //%PDDM-EXPAND _WRITE_DECLS() // This block of code is generated, do not edit it directly. +// clang-format off /** * Write a double for the given field number. @@ -631,9 +631,8 @@ extern NSString *const GPBCodedOutputStreamException_WriteFailed; - (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(GPBUnknownFieldSet *)value; -//%PDDM-EXPAND-END _WRITE_DECLS() - // clang-format on +//%PDDM-EXPAND-END _WRITE_DECLS() /** Write a MessageSet extension field to the stream. For historical reasons, @@ -657,9 +656,6 @@ reasons, the wire format differs from normal fields. NS_ASSUME_NONNULL_END -// Disable clang-format for the macros. -// clang-format off - // Write methods for types that can be in packed arrays. //%PDDM-DEFINE _WRITE_PACKABLE_DECLS(NAME, ARRAY_TYPE, TYPE) //%/** @@ -759,5 +755,3 @@ NS_ASSUME_NONNULL_END //%_WRITE_UNPACKABLE_DECLS(Bytes, NSData) //%_WRITE_GROUP_DECLS(Group, GPBMessage) //%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBCodedOutputStream.m b/libs/protobuf/objectivec/GPBCodedOutputStream.m index c21e7d2..4e2a514 100644 --- a/libs/protobuf/objectivec/GPBCodedOutputStream.m +++ b/libs/protobuf/objectivec/GPBCodedOutputStream.m @@ -67,7 +67,8 @@ static void GPBRefreshBuffer(GPBOutputBufferState *state) { [NSException raise:GPBCodedOutputStreamException_OutOfSpace format:@""]; } if (state->position != 0) { - NSInteger written = [state->output write:state->bytes maxLength:state->position]; + NSInteger written = + [state->output write:state->bytes maxLength:state->position]; if (written != (NSInteger)state->position) { [NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""]; } @@ -117,24 +118,27 @@ static void GPBWriteInt32NoTag(GPBOutputBufferState *state, int32_t value) { } } -static void GPBWriteUInt32(GPBOutputBufferState *state, int32_t fieldNumber, uint32_t value) { +static void GPBWriteUInt32(GPBOutputBufferState *state, int32_t fieldNumber, + uint32_t value) { GPBWriteTagWithFormat(state, fieldNumber, GPBWireFormatVarint); GPBWriteRawVarint32(state, value); } -static void GPBWriteTagWithFormat(GPBOutputBufferState *state, uint32_t fieldNumber, - GPBWireFormat format) { +static void GPBWriteTagWithFormat(GPBOutputBufferState *state, + uint32_t fieldNumber, GPBWireFormat format) { GPBWriteRawVarint32(state, GPBWireFormatMakeTag(fieldNumber, format)); } -static void GPBWriteRawLittleEndian32(GPBOutputBufferState *state, int32_t value) { +static void GPBWriteRawLittleEndian32(GPBOutputBufferState *state, + int32_t value) { GPBWriteRawByte(state, (value)&0xFF); GPBWriteRawByte(state, (value >> 8) & 0xFF); GPBWriteRawByte(state, (value >> 16) & 0xFF); GPBWriteRawByte(state, (value >> 24) & 0xFF); } -static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value) { +static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, + int64_t value) { GPBWriteRawByte(state, (int32_t)(value)&0xFF); GPBWriteRawByte(state, (int32_t)(value >> 8) & 0xFF); GPBWriteRawByte(state, (int32_t)(value >> 16) & 0xFF); @@ -166,7 +170,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value // This initializer isn't exposed, but it is the designated initializer. // Setting OutputStream and NSData is to control the buffering behavior/size // of the work, but that is more obvious via the bufferSize: version. -- (instancetype)initWithOutputStream:(NSOutputStream *)output data:(NSMutableData *)data { +- (instancetype)initWithOutputStream:(NSOutputStream *)output + data:(NSMutableData *)data { if ((self = [super init])) { buffer_ = [data retain]; state_.bytes = [data mutableBytes]; @@ -179,7 +184,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value + (instancetype)streamWithOutputStream:(NSOutputStream *)output { NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE]; - return [[[self alloc] initWithOutputStream:output data:data] autorelease]; + return [[[self alloc] initWithOutputStream:output + data:data] autorelease]; } + (instancetype)streamWithData:(NSMutableData *)data { @@ -271,7 +277,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value return; } - const char *quickString = CFStringGetCStringPtr((CFStringRef)value, kCFStringEncodingUTF8); + const char *quickString = + CFStringGetCStringPtr((CFStringRef)value, kCFStringEncodingUTF8); // Fast path: Most strings are short, if the buffer already has space, // add to it directly. @@ -293,8 +300,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value remainingRange:NULL]; } if (result) { - NSAssert2((usedBufferLength == length), @"Our UTF8 calc was wrong? %tu vs %zd", - usedBufferLength, length); + NSAssert2((usedBufferLength == length), + @"Our UTF8 calc was wrong? %tu vs %zd", usedBufferLength, + length); state_.position += usedBufferLength; return; } @@ -303,8 +311,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } else { // Slow path: just get it as data and write it out. NSData *utf8Data = [value dataUsingEncoding:NSUTF8StringEncoding]; - NSAssert2(([utf8Data length] == length), @"Strings UTF8 length was wrong? %tu vs %zd", - [utf8Data length], length); + NSAssert2(([utf8Data length] == length), + @"Strings UTF8 length was wrong? %tu vs %zd", [utf8Data length], + length); [self writeRawData:utf8Data]; } } @@ -324,12 +333,14 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value [self writeGroupNoTag:fieldNumber value:value]; } -- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber value:(const GPBUnknownFieldSet *)value { +- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber + value:(const GPBUnknownFieldSet *)value { [value writeToCodedOutputStream:self]; GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup); } -- (void)writeUnknownGroup:(int32_t)fieldNumber value:(GPBUnknownFieldSet *)value { +- (void)writeUnknownGroup:(int32_t)fieldNumber + value:(GPBUnknownFieldSet *)value { GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup); [self writeUnknownGroupNoTag:fieldNumber value:value]; } @@ -407,8 +418,6 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value)); } -// clang-format off - //%PDDM-DEFINE WRITE_PACKABLE_DEFNS(NAME, ARRAY_TYPE, TYPE, ACCESSOR_NAME) //%- (void)write##NAME##Array:(int32_t)fieldNumber //% NAME$S values:(GPB##ARRAY_TYPE##Array *)values @@ -416,16 +425,19 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value //% if (tag != 0) { //% if (values.count == 0) return; //% __block size_t dataSize = 0; -//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, __unused NSUInteger idx,__unused BOOL *stop) { +//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { +//%#pragma unused(idx, stop) //% dataSize += GPBCompute##NAME##SizeNoTag(value); //% }]; //% GPBWriteRawVarint32(&state_, tag); //% GPBWriteRawVarint32(&state_, (int32_t)dataSize); -//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { +//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { +//%#pragma unused(idx, stop) //% [self write##NAME##NoTag:value]; //% }]; //% } else { -//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { +//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { +//%#pragma unused(idx, stop) //% [self write##NAME:fieldNumber value:value]; //% }]; //% } @@ -440,6 +452,7 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value //% //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Double, Double, double, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeDoubleArray:(int32_t)fieldNumber values:(GPBDoubleArray *)values @@ -447,23 +460,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(double value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeDoubleSizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(double value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeDoubleNoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(double value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeDouble:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Float, Float, float, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeFloatArray:(int32_t)fieldNumber values:(GPBFloatArray *)values @@ -471,23 +489,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(float value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeFloatSizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(float value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFloatNoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(float value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFloat:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt64, UInt64, uint64_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeUInt64Array:(int32_t)fieldNumber values:(GPBUInt64Array *)values @@ -495,23 +518,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeUInt64SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeUInt64NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeUInt64:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int64, Int64, int64_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeInt64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values @@ -519,23 +547,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeInt64SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeInt64NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeInt64:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int32, Int32, int32_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeInt32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values @@ -543,23 +576,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeInt32SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeInt32NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeInt32:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt32, UInt32, uint32_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeUInt32Array:(int32_t)fieldNumber values:(GPBUInt32Array *)values @@ -567,23 +605,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeUInt32SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeUInt32NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeUInt32:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed64, UInt64, uint64_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeFixed64Array:(int32_t)fieldNumber values:(GPBUInt64Array *)values @@ -591,23 +634,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeFixed64SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFixed64NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFixed64:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed32, UInt32, uint32_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeFixed32Array:(int32_t)fieldNumber values:(GPBUInt32Array *)values @@ -615,23 +663,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeFixed32SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFixed32NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeFixed32:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt32, Int32, int32_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeSInt32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values @@ -639,23 +692,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeSInt32SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSInt32NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSInt32:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt64, Int64, int64_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeSInt64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values @@ -663,23 +721,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeSInt64SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSInt64NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSInt64:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed64, Int64, int64_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeSFixed64Array:(int32_t)fieldNumber values:(GPBInt64Array *)values @@ -687,23 +750,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeSFixed64SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSFixed64NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSFixed64:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed32, Int32, int32_t, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeSFixed32Array:(int32_t)fieldNumber values:(GPBInt32Array *)values @@ -711,23 +779,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeSFixed32SizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSFixed32NoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeSFixed32:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Bool, Bool, BOOL, ) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeBoolArray:(int32_t)fieldNumber values:(GPBBoolArray *)values @@ -735,23 +808,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateValuesWithBlock:^(BOOL value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeBoolSizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateValuesWithBlock:^(BOOL value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeBoolNoTag:value]; }]; } else { - [values enumerateValuesWithBlock:^(BOOL value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeBool:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Enum, Enum, int32_t, Raw) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeEnumArray:(int32_t)fieldNumber values:(GPBEnumArray *)values @@ -759,23 +837,28 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value if (tag != 0) { if (values.count == 0) return; __block size_t dataSize = 0; - [values enumerateRawValuesWithBlock:^(int32_t value, __unused NSUInteger idx,__unused BOOL *stop) { + [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) dataSize += GPBComputeEnumSizeNoTag(value); }]; GPBWriteRawVarint32(&state_, tag); GPBWriteRawVarint32(&state_, (int32_t)dataSize); - [values enumerateRawValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeEnumNoTag:value]; }]; } else { - [values enumerateRawValuesWithBlock:^(int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [self writeEnum:fieldNumber value:value]; }]; } } +// clang-format on //%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(String, NSString) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeStringArray:(int32_t)fieldNumber values:(NSArray *)values { for (NSString *value in values) { @@ -783,8 +866,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } +// clang-format on //%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Message, GPBMessage) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray *)values { for (GPBMessage *value in values) { @@ -792,8 +877,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } +// clang-format on //%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Bytes, NSData) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray *)values { for (NSData *value in values) { @@ -801,8 +888,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } +// clang-format on //%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Group, GPBMessage) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values { for (GPBMessage *value in values) { @@ -810,8 +899,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } +// clang-format on //%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet) // This block of code is generated, do not edit it directly. +// clang-format off - (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values { for (GPBUnknownFieldSet *value in values) { @@ -819,22 +910,26 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value } } +// clang-format on //%PDDM-EXPAND-END (19 expansions) -// clang-format on - -- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value { - GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup); +- (void)writeMessageSetExtension:(int32_t)fieldNumber + value:(GPBMessage *)value { + GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, + GPBWireFormatStartGroup); GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber); [self writeMessage:GPBWireFormatMessageSetMessage value:value]; - GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatEndGroup); + GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, + GPBWireFormatEndGroup); } - (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value { - GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatStartGroup); + GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, + GPBWireFormatStartGroup); GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber); [self writeBytes:GPBWireFormatMessageSetMessage value:value]; - GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, GPBWireFormatEndGroup); + GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem, + GPBWireFormatEndGroup); } - (void)flush { @@ -851,7 +946,9 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value [self writeRawPtr:[data bytes] offset:0 length:[data length]]; } -- (void)writeRawPtr:(const void *)value offset:(size_t)offset length:(size_t)length { +- (void)writeRawPtr:(const void *)value + offset:(size_t)offset + length:(size_t)length { if (value == nil || length == 0) { return; } @@ -866,7 +963,8 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value // Write extends past current buffer. Fill the rest of this buffer and // flush. size_t bytesWritten = bufferBytesLeft; - memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, bytesWritten); + memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, + bytesWritten); offset += bytesWritten; length -= bytesWritten; state_.position = bufferLength; @@ -919,13 +1017,23 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state, int64_t value @end -size_t GPBComputeDoubleSizeNoTag(__unused Float64 value) { return LITTLE_ENDIAN_64_SIZE; } +size_t GPBComputeDoubleSizeNoTag(Float64 value) { +#pragma unused(value) + return LITTLE_ENDIAN_64_SIZE; +} -size_t GPBComputeFloatSizeNoTag(__unused Float32 value) { return LITTLE_ENDIAN_32_SIZE; } +size_t GPBComputeFloatSizeNoTag(Float32 value) { +#pragma unused(value) + return LITTLE_ENDIAN_32_SIZE; +} -size_t GPBComputeUInt64SizeNoTag(uint64_t value) { return GPBComputeRawVarint64Size(value); } +size_t GPBComputeUInt64SizeNoTag(uint64_t value) { + return GPBComputeRawVarint64Size(value); +} -size_t GPBComputeInt64SizeNoTag(int64_t value) { return GPBComputeRawVarint64Size(value); } +size_t GPBComputeInt64SizeNoTag(int64_t value) { + return GPBComputeRawVarint64Size(value); +} size_t GPBComputeInt32SizeNoTag(int32_t value) { if (value >= 0) { @@ -940,20 +1048,33 @@ size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) { return GPBComputeInt32SizeNoTag((int32_t)value); } -size_t GPBComputeFixed64SizeNoTag(__unused uint64_t value) { return LITTLE_ENDIAN_64_SIZE; } +size_t GPBComputeFixed64SizeNoTag(uint64_t value) { +#pragma unused(value) + return LITTLE_ENDIAN_64_SIZE; +} -size_t GPBComputeFixed32SizeNoTag(__unused uint32_t value) { return LITTLE_ENDIAN_32_SIZE; } +size_t GPBComputeFixed32SizeNoTag(uint32_t value) { +#pragma unused(value) + return LITTLE_ENDIAN_32_SIZE; +} -size_t GPBComputeBoolSizeNoTag(__unused BOOL value) { return 1; } +size_t GPBComputeBoolSizeNoTag(BOOL value) { +#pragma unused(value) + return 1; +} size_t GPBComputeStringSizeNoTag(NSString *value) { NSUInteger length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; return GPBComputeRawVarint32SizeForInteger(length) + length; } -size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { return [value serializedSize]; } +size_t GPBComputeGroupSizeNoTag(GPBMessage *value) { + return [value serializedSize]; +} -size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { return value.serializedSize; } +size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) { + return value.serializedSize; +} size_t GPBComputeMessageSizeNoTag(GPBMessage *value) { size_t size = [value serializedSize]; @@ -965,13 +1086,23 @@ size_t GPBComputeBytesSizeNoTag(NSData *value) { return GPBComputeRawVarint32SizeForInteger(valueLength) + valueLength; } -size_t GPBComputeUInt32SizeNoTag(int32_t value) { return GPBComputeRawVarint32Size(value); } +size_t GPBComputeUInt32SizeNoTag(int32_t value) { + return GPBComputeRawVarint32Size(value); +} -size_t GPBComputeEnumSizeNoTag(int32_t value) { return GPBComputeInt32SizeNoTag(value); } +size_t GPBComputeEnumSizeNoTag(int32_t value) { + return GPBComputeInt32SizeNoTag(value); +} -size_t GPBComputeSFixed32SizeNoTag(__unused int32_t value) { return LITTLE_ENDIAN_32_SIZE; } +size_t GPBComputeSFixed32SizeNoTag(int32_t value) { +#pragma unused(value) + return LITTLE_ENDIAN_32_SIZE; +} -size_t GPBComputeSFixed64SizeNoTag(__unused int64_t value) { return LITTLE_ENDIAN_64_SIZE; } +size_t GPBComputeSFixed64SizeNoTag(int64_t value) { +#pragma unused(value) + return LITTLE_ENDIAN_64_SIZE; +} size_t GPBComputeSInt32SizeNoTag(int32_t value) { return GPBComputeRawVarint32Size(GPBEncodeZigZag32(value)); @@ -1021,8 +1152,10 @@ size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) { return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value); } -size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) { - return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeUnknownGroupSizeNoTag(value); +size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, + GPBUnknownFieldSet *value) { + return GPBComputeTagSize(fieldNumber) * 2 + + GPBComputeUnknownGroupSizeNoTag(value); } size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) { @@ -1054,23 +1187,27 @@ size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) { } size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) { - return GPBComputeTagSize(fieldNumber) + GPBComputeRawVarint64Size(GPBEncodeZigZag64(value)); + return GPBComputeTagSize(fieldNumber) + + GPBComputeRawVarint64Size(GPBEncodeZigZag64(value)); } -size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value) { +size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, + GPBMessage *value) { return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 + GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) + GPBComputeMessageSize(GPBWireFormatMessageSetMessage, value); } -size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value) { +size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, + NSData *value) { return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 + GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) + GPBComputeBytesSize(GPBWireFormatMessageSetMessage, value); } size_t GPBComputeTagSize(int32_t fieldNumber) { - return GPBComputeRawVarint32Size(GPBWireFormatMakeTag(fieldNumber, GPBWireFormatVarint)); + return GPBComputeRawVarint32Size( + GPBWireFormatMakeTag(fieldNumber, GPBWireFormatVarint)); } size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) { diff --git a/libs/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h b/libs/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h index 98e2d95..2e7bb4c 100644 --- a/libs/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h @@ -34,27 +34,46 @@ NS_ASSUME_NONNULL_BEGIN CF_EXTERN_C_BEGIN -size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) __attribute__((const)); -size_t GPBComputeFloatSize(int32_t fieldNumber, float value) __attribute__((const)); -size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) __attribute__((const)); -size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) __attribute__((const)); -size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) __attribute__((const)); -size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) __attribute__((const)); -size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) __attribute__((const)); -size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) __attribute__((const)); -size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) __attribute__((const)); -size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); -size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, GPBUnknownFieldSet *value) +size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) + __attribute__((const)); +size_t GPBComputeFloatSize(int32_t fieldNumber, float value) + __attribute__((const)); +size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) + __attribute__((const)); +size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) + __attribute__((const)); +size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) + __attribute__((const)); +size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) + __attribute__((const)); +size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) + __attribute__((const)); +size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) + __attribute__((const)); +size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) + __attribute__((const)); +size_t GPBComputeUnknownGroupSize(int32_t fieldNumber, + GPBUnknownFieldSet *value) + __attribute__((const)); +size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) + __attribute__((const)); +size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) + __attribute__((const)); +size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) + __attribute__((const)); +size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) + __attribute__((const)); +size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) + __attribute__((const)); +size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) __attribute__((const)); -size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) __attribute__((const)); -size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) __attribute__((const)); -size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) __attribute__((const)); -size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) __attribute__((const)); -size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) __attribute__((const)); -size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) __attribute__((const)); -size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) __attribute__((const)); size_t GPBComputeTagSize(int32_t fieldNumber) __attribute__((const)); -size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) __attribute__((const)); +size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) + __attribute__((const)); size_t GPBComputeDoubleSizeNoTag(double value) __attribute__((const)); size_t GPBComputeFloatSizeNoTag(float value) __attribute__((const)); @@ -66,7 +85,8 @@ size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const)); size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const)); size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const)); size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const)); -size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) __attribute__((const)); +size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) + __attribute__((const)); size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const)); size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const)); size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const)); @@ -83,7 +103,8 @@ size_t GPBComputeRawVarint32Size(int32_t value) __attribute__((const)); size_t GPBComputeRawVarint64Size(int64_t value) __attribute__((const)); // Note that this will calculate the size of 64 bit values truncated to 32. -size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) __attribute__((const)); +size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) + __attribute__((const)); // Compute the number of bytes that would be needed to encode a // MessageSet extension to the stream. For historical reasons, @@ -97,7 +118,8 @@ size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value) size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value) __attribute__((const)); -size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) __attribute__((const)); +size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) + __attribute__((const)); CF_EXTERN_C_END diff --git a/libs/protobuf/objectivec/GPBDescriptor.h b/libs/protobuf/objectivec/GPBDescriptor.h index 750eaee..fd66b0e 100644 --- a/libs/protobuf/objectivec/GPBDescriptor.h +++ b/libs/protobuf/objectivec/GPBDescriptor.h @@ -62,14 +62,14 @@ typedef NS_ENUM(uint8_t, GPBFieldType) { /** * Describes a proto message. **/ -@interface GPBDescriptor : NSObject +@interface GPBDescriptor : NSObject /** Name of the message. */ @property(nonatomic, readonly, copy) NSString *name; /** Fields declared in the message. */ -@property(nonatomic, readonly, strong, nullable) NSArray *fields; +@property(nonatomic, readonly, strong, nullable) NSArray *fields; /** Oneofs declared in the message. */ -@property(nonatomic, readonly, strong, nullable) NSArray *oneofs; +@property(nonatomic, readonly, strong, nullable) NSArray *oneofs; /** Extension range declared for the message. */ @property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges; /** Number of extension ranges declared for the message. */ @@ -139,7 +139,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) { /** Name of the oneof field. */ @property(nonatomic, readonly) NSString *name; /** Fields declared in the oneof. */ -@property(nonatomic, readonly) NSArray *fields; +@property(nonatomic, readonly) NSArray *fields; /** * Gets the field for the given number. @@ -293,7 +293,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) { /** * Describes a proto extension. **/ -@interface GPBExtensionDescriptor : NSObject +@interface GPBExtensionDescriptor : NSObject /** Field number under which the extension is stored. */ @property(nonatomic, readonly) uint32_t fieldNumber; /** The containing message class, i.e. the class extended by this extension. */ diff --git a/libs/protobuf/objectivec/GPBDescriptor.m b/libs/protobuf/objectivec/GPBDescriptor.m index 316ce76..c29b955 100644 --- a/libs/protobuf/objectivec/GPBDescriptor.m +++ b/libs/protobuf/objectivec/GPBDescriptor.m @@ -32,9 +32,9 @@ #import -#import "GPBMessage_PackagePrivate.h" #import "GPBUtilities_PackagePrivate.h" #import "GPBWireFormat.h" +#import "GPBMessage_PackagePrivate.h" // Direct access is use for speed, to avoid even internally declaring things // read/write, etc. The warning is enabled in the project to ensure code calling @@ -48,15 +48,16 @@ static const char kParentClassValueKey = 0; static const char kClassNameSuffixKey = 0; // Utility function to generate selectors on the fly. -static SEL SelFromStrings(const char *prefix, const char *middle, const char *suffix, - BOOL takesArg) { +static SEL SelFromStrings(const char *prefix, const char *middle, + const char *suffix, BOOL takesArg) { if (prefix == NULL && suffix == NULL && !takesArg) { return sel_getUid(middle); } const size_t prefixLen = prefix != NULL ? strlen(prefix) : 0; const size_t middleLen = strlen(middle); const size_t suffixLen = suffix != NULL ? strlen(suffix) : 0; - size_t totalLen = prefixLen + middleLen + suffixLen + 1; // include space for null on end. + size_t totalLen = + prefixLen + middleLen + suffixLen + 1; // include space for null on end. if (takesArg) { totalLen += 1; } @@ -81,10 +82,12 @@ static SEL SelFromStrings(const char *prefix, const char *middle, const char *su return result; } -static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageFields) +static NSArray *NewFieldsArrayForHasIndex(int hasIndex, + NSArray *allMessageFields) __attribute__((ns_returns_retained)); -static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageFields) { +static NSArray *NewFieldsArrayForHasIndex(int hasIndex, + NSArray *allMessageFields) { NSMutableArray *result = [[NSMutableArray alloc] init]; for (GPBFieldDescriptor *fieldDesc in allMessageFields) { if (fieldDesc->description_->hasIndex == hasIndex) { @@ -108,21 +111,25 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField @synthesize file = file_; @synthesize wireFormat = wireFormat_; -+ (instancetype)allocDescriptorForClass:(Class)messageClass - rootClass:(Class)rootClass - file:(GPBFileDescriptor *)file - fields:(void *)fieldDescriptions - fieldCount:(uint32_t)fieldCount - storageSize:(uint32_t)storageSize - flags:(GPBDescriptorInitializationFlags)flags { ++ (instancetype) + allocDescriptorForClass:(Class)messageClass + rootClass:(Class)rootClass + file:(GPBFileDescriptor *)file + fields:(void *)fieldDescriptions + fieldCount:(uint32_t)fieldCount + storageSize:(uint32_t)storageSize + flags:(GPBDescriptorInitializationFlags)flags { // The rootClass is no longer used, but it is passed in to ensure it // was started up during initialization also. (void)rootClass; NSMutableArray *fields = nil; GPBFileSyntax syntax = file.syntax; - BOOL fieldsIncludeDefault = (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0; - BOOL usesClassRefs = (flags & GPBDescriptorInitializationFlag_UsesClassRefs) != 0; - BOOL proto3OptionalKnown = (flags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) != 0; + BOOL fieldsIncludeDefault = + (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0; + BOOL usesClassRefs = + (flags & GPBDescriptorInitializationFlag_UsesClassRefs) != 0; + BOOL proto3OptionalKnown = + (flags & GPBDescriptorInitializationFlag_Proto3OptionalKnown) != 0; void *desc; for (uint32_t i = 0; i < fieldCount; ++i) { @@ -186,9 +193,10 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField for (uint32_t i = 0, hasIndex = firstHasIndex; i < count; ++i, --hasIndex) { const char *name = oneofNames[i]; NSArray *fieldsForOneof = NewFieldsArrayForHasIndex(hasIndex, fields_); - NSCAssert(fieldsForOneof.count > 0, @"No fields for this oneof? (%s:%d)", name, hasIndex); - GPBOneofDescriptor *oneofDescriptor = [[GPBOneofDescriptor alloc] initWithName:name - fields:fieldsForOneof]; + NSCAssert(fieldsForOneof.count > 0, + @"No fields for this oneof? (%s:%d)", name, hasIndex); + GPBOneofDescriptor *oneofDescriptor = + [[GPBOneofDescriptor alloc] initWithName:name fields:fieldsForOneof]; [oneofs addObject:oneofDescriptor]; [oneofDescriptor release]; [fieldsForOneof release]; @@ -202,7 +210,8 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField NSValue *extraInfoValue = [NSValue valueWithPointer:extraTextFormatInfo]; for (GPBFieldDescriptor *fieldDescriptor in fields_) { if (fieldDescriptor->description_->flags & GPBFieldTextFormatNameCustom) { - objc_setAssociatedObject(fieldDescriptor, &kTextFormatExtraValueKey, extraInfoValue, + objc_setAssociatedObject(fieldDescriptor, &kTextFormatExtraValueKey, + extraInfoValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } } @@ -215,7 +224,9 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField } - (void)setupContainingMessageClass:(Class)messageClass { - objc_setAssociatedObject(self, &kParentClassValueKey, messageClass, OBJC_ASSOCIATION_ASSIGN); + objc_setAssociatedObject(self, &kParentClassValueKey, + messageClass, + OBJC_ASSOCIATION_ASSIGN); } - (void)setupContainingMessageClassName:(const char *)msgClassName { @@ -229,7 +240,9 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField - (void)setupMessageClassNameSuffix:(NSString *)suffix { if (suffix.length) { - objc_setAssociatedObject(self, &kClassNameSuffixKey, suffix, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject(self, &kClassNameSuffixKey, + suffix, + OBJC_ASSOCIATION_RETAIN_NONATOMIC); } } @@ -247,7 +260,9 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField GPBFileDescriptor *file = self.file; NSString *objcPrefix = file.objcPrefix; if (objcPrefix && ![className hasPrefix:objcPrefix]) { - NSAssert(0, @"Class didn't have correct prefix? (%@ - %@)", className, objcPrefix); + NSAssert(0, + @"Class didn't have correct prefix? (%@ - %@)", + className, objcPrefix); return nil; } GPBDescriptor *parent = self.containingType; @@ -259,16 +274,19 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField NSString *suffix = objc_getAssociatedObject(parent, &kClassNameSuffixKey); if (suffix) { if (![parentClassName hasSuffix:suffix]) { - NSAssert(0, @"ParentMessage class didn't have correct suffix? (%@ - %@)", className, - suffix); + NSAssert(0, + @"ParentMessage class didn't have correct suffix? (%@ - %@)", + className, suffix); return nil; } - parentClassName = [parentClassName substringToIndex:(parentClassName.length - suffix.length)]; + parentClassName = + [parentClassName substringToIndex:(parentClassName.length - suffix.length)]; } NSString *parentPrefix = [parentClassName stringByAppendingString:@"_"]; if (![className hasPrefix:parentPrefix]) { - NSAssert(0, @"Class didn't have the correct parent name prefix? (%@ - %@)", parentPrefix, - className); + NSAssert(0, + @"Class didn't have the correct parent name prefix? (%@ - %@)", + parentPrefix, className); return nil; } name = [className substringFromIndex:parentPrefix.length]; @@ -280,7 +298,9 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField NSString *suffix = objc_getAssociatedObject(self, &kClassNameSuffixKey); if (suffix) { if (![name hasSuffix:suffix]) { - NSAssert(0, @"Message class didn't have correct suffix? (%@ - %@)", name, suffix); + NSAssert(0, + @"Message class didn't have correct suffix? (%@ - %@)", + name, suffix); return nil; } name = [name substringToIndex:(name.length - suffix.length)]; @@ -296,7 +316,8 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField return result; } -- (id)copyWithZone:(__unused NSZone *)zone { +- (id)copyWithZone:(NSZone *)zone { +#pragma unused(zone) return [self retain]; } @@ -351,7 +372,8 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField return self; } -- (instancetype)initWithPackage:(NSString *)package syntax:(GPBFileSyntax)syntax { +- (instancetype)initWithPackage:(NSString *)package + syntax:(GPBFileSyntax)syntax { self = [super init]; if (self) { package_ = [package copy]; @@ -392,7 +414,7 @@ static NSArray *NewFieldsArrayForHasIndex(int hasIndex, NSArray *allMessageField } - (NSString *)name { - return (NSString *_Nonnull)@(name_); + return (NSString * _Nonnull)@(name_); } - (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber { @@ -422,17 +444,19 @@ uint32_t GPBFieldTag(GPBFieldDescriptor *self) { // Maps are repeated messages on the wire. format = GPBWireFormatForType(GPBDataTypeMessage, NO); } else { - format = - GPBWireFormatForType(description->dataType, ((description->flags & GPBFieldPacked) != 0)); + format = GPBWireFormatForType(description->dataType, + ((description->flags & GPBFieldPacked) != 0)); } return GPBWireFormatMakeTag(description->number, format); } uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { GPBMessageFieldDescription *description = self->description_; - NSCAssert((description->flags & GPBFieldRepeated) != 0, @"Only valid on repeated fields"); + NSCAssert((description->flags & GPBFieldRepeated) != 0, + @"Only valid on repeated fields"); GPBWireFormat format = - GPBWireFormatForType(description->dataType, ((description->flags & GPBFieldPacked) == 0)); + GPBWireFormatForType(description->dataType, + ((description->flags & GPBFieldPacked) == 0)); return GPBWireFormatMakeTag(description->number, format); } @@ -492,8 +516,10 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { // - not repeated/map // - not in a oneof (negative has index) // - not a message (the flag doesn't make sense for messages) - BOOL clearOnZero = ((syntax == GPBFileSyntaxProto3) && !isMapOrArray && - (coreDesc->hasIndex >= 0) && !isMessage); + BOOL clearOnZero = ((syntax == GPBFileSyntaxProto3) && + !isMapOrArray && + (coreDesc->hasIndex >= 0) && + !isMessage); if (clearOnZero) { coreDesc->flags |= GPBFieldClearHasIvarOnZero; } @@ -508,7 +534,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { // It is a single field; it gets has/setHas selectors if... // - not in a oneof (negative has index) // - not clearing on zero - if ((coreDesc->hasIndex >= 0) && ((coreDesc->flags & GPBFieldClearHasIvarOnZero) == 0)) { + if ((coreDesc->hasIndex >= 0) && + ((coreDesc->flags & GPBFieldClearHasIvarOnZero) == 0)) { hasOrCountSel_ = SelFromStrings("has", coreDesc->name, NULL, NO); setHasSel_ = SelFromStrings("setHas", coreDesc->name, NULL, YES); } @@ -529,9 +556,11 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } } else if (dataType == GPBDataTypeEnum) { if ((coreDesc->flags & GPBFieldHasEnumDescriptor) != 0) { - enumHandling_.enumDescriptor_ = coreDesc->dataTypeSpecific.enumDescFunc(); + enumHandling_.enumDescriptor_ = + coreDesc->dataTypeSpecific.enumDescFunc(); } else { - enumHandling_.enumVerifier_ = coreDesc->dataTypeSpecific.enumVerifier; + enumHandling_.enumVerifier_ = + coreDesc->dataTypeSpecific.enumVerifier; } } @@ -547,7 +576,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { memcpy(&length, bytes, sizeof(length)); length = ntohl(length); bytes += sizeof(length); - defaultValue_.valueData = [[NSData alloc] initWithBytes:bytes length:length]; + defaultValue_.valueData = + [[NSData alloc] initWithBytes:bytes length:length]; } } } @@ -556,7 +586,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (void)dealloc { - if (description_->dataType == GPBDataTypeBytes && !(description_->flags & GPBFieldRepeated)) { + if (description_->dataType == GPBDataTypeBytes && + !(description_->flags & GPBFieldRepeated)) { [defaultValue_.valueData release]; } [super dealloc]; @@ -575,7 +606,7 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (NSString *)name { - return (NSString *_Nonnull)@(description_->name); + return (NSString * _Nonnull)@(description_->name); } - (BOOL)isRequired { @@ -635,7 +666,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (BOOL)isValidEnumValue:(int32_t)value { - NSAssert(description_->dataType == GPBDataTypeEnum, @"Field Must be of type GPBDataTypeEnum"); + NSAssert(description_->dataType == GPBDataTypeEnum, + @"Field Must be of type GPBDataTypeEnum"); if (description_->flags & GPBFieldHasEnumDescriptor) { return enumHandling_.enumDescriptor_.enumVerifier(value); } else { @@ -671,17 +703,19 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { - (NSString *)textFormatName { if ((description_->flags & GPBFieldTextFormatNameCustom) != 0) { - NSValue *extraInfoValue = objc_getAssociatedObject(self, &kTextFormatExtraValueKey); + NSValue *extraInfoValue = + objc_getAssociatedObject(self, &kTextFormatExtraValueKey); // Support can be left out at generation time. if (!extraInfoValue) { return nil; } const uint8_t *extraTextFormatInfo = [extraInfoValue pointerValue]; - return GPBDecodeTextFormatName(extraTextFormatInfo, GPBFieldNumber(self), self.name); + return GPBDecodeTextFormatName(extraTextFormatInfo, GPBFieldNumber(self), + self.name); } // The logic here has to match SetCommonFieldVariables() from - // objectivec/field.cc in the proto compiler. + // objectivec_field.cc in the proto compiler. NSString *name = self.name; NSUInteger len = [name length]; @@ -692,7 +726,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } // Remove "Array" from the end for repeated fields. - if (((description_->flags & GPBFieldRepeated) != 0) && [name hasSuffix:@"Array"]) { + if (((description_->flags & GPBFieldRepeated) != 0) && + [name hasSuffix:@"Array"]) { name = [name substringToIndex:(len - 5)]; len = [name length]; } @@ -704,8 +739,9 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { if (firstChar >= 'a' && firstChar <= 'z') { NSString *firstCharString = [NSString stringWithFormat:@"%C", (unichar)(firstChar - 'a' + 'A')]; - NSString *result = [name stringByReplacingCharactersInRange:NSMakeRange(0, 1) - withString:firstCharString]; + NSString *result = + [name stringByReplacingCharactersInRange:NSMakeRange(0, 1) + withString:firstCharString]; return result; } return name; @@ -748,11 +784,12 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { @synthesize name = name_; @synthesize enumVerifier = enumVerifier_; -+ (instancetype)allocDescriptorForName:(NSString *)name - valueNames:(const char *)valueNames - values:(const int32_t *)values - count:(uint32_t)valueCount - enumVerifier:(GPBEnumValidationFunc)enumVerifier { ++ (instancetype) + allocDescriptorForName:(NSString *)name + valueNames:(const char *)valueNames + values:(const int32_t *)values + count:(uint32_t)valueCount + enumVerifier:(GPBEnumValidationFunc)enumVerifier { GPBEnumDescriptor *descriptor = [[self alloc] initWithName:name valueNames:valueNames values:values @@ -761,12 +798,13 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { return descriptor; } -+ (instancetype)allocDescriptorForName:(NSString *)name - valueNames:(const char *)valueNames - values:(const int32_t *)values - count:(uint32_t)valueCount - enumVerifier:(GPBEnumValidationFunc)enumVerifier - extraTextFormatInfo:(const char *)extraTextFormatInfo { ++ (instancetype) + allocDescriptorForName:(NSString *)name + valueNames:(const char *)valueNames + values:(const int32_t *)values + count:(uint32_t)valueCount + enumVerifier:(GPBEnumValidationFunc)enumVerifier + extraTextFormatInfo:(const char *)extraTextFormatInfo { // Call the common case. GPBEnumDescriptor *descriptor = [self allocDescriptorForName:name valueNames:valueNames @@ -854,26 +892,27 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (BOOL)getValue:(int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName { - if (nameOffsets_ == NULL) [self calcValueNameOffsets]; - if (nameOffsets_ == NULL) return NO; + if (nameOffsets_ == NULL) [self calcValueNameOffsets]; + if (nameOffsets_ == NULL) return NO; - for (uint32_t i = 0; i < valueCount_; ++i) { - NSString *valueTextFormatName = [self getEnumTextFormatNameForIndex:i]; - if ([valueTextFormatName isEqual:textFormatName]) { - if (outValue) { - *outValue = values_[i]; - } - return YES; + for (uint32_t i = 0; i < valueCount_; ++i) { + NSString *valueTextFormatName = [self getEnumTextFormatNameForIndex:i]; + if ([valueTextFormatName isEqual:textFormatName]) { + if (outValue) { + *outValue = values_[i]; + } + return YES; + } } - } - return NO; + return NO; } - (NSString *)textFormatNameForValue:(int32_t)number { // Find the EnumValue descriptor and its index. BOOL foundIt = NO; uint32_t valueDescriptorIndex; - for (valueDescriptorIndex = 0; valueDescriptorIndex < valueCount_; ++valueDescriptorIndex) { + for (valueDescriptorIndex = 0; valueDescriptorIndex < valueCount_; + ++valueDescriptorIndex) { if (values_[valueDescriptorIndex] == number) { foundIt = YES; break; @@ -916,9 +955,10 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { // See if it is in the map of special format handling. if (extraTextFormatInfo_) { - result = GPBDecodeTextFormatName(extraTextFormatInfo_, (int32_t)index, shortName); + result = GPBDecodeTextFormatName(extraTextFormatInfo_, + (int32_t)index, shortName); } - // Logic here needs to match what objectivec/enum.cc does in the proto + // Logic here needs to match what objectivec_enum.cc does in the proto // compiler. if (result == nil) { NSUInteger len = [shortName length]; @@ -965,14 +1005,16 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { GPBDataType type = description_->dataType; if (type == GPBDataTypeBytes) { // Data stored as a length prefixed c-string in descriptor records. - const uint8_t *bytes = (const uint8_t *)description_->defaultValue.valueData; + const uint8_t *bytes = + (const uint8_t *)description_->defaultValue.valueData; if (bytes) { uint32_t length; memcpy(&length, bytes, sizeof(length)); // The length is stored in network byte order. length = ntohl(length); bytes += sizeof(length); - defaultValue_.valueData = [[NSData alloc] initWithBytes:bytes length:length]; + defaultValue_.valueData = + [[NSData alloc] initWithBytes:bytes length:length]; } } else if (type == GPBDataTypeMessage || type == GPBDataTypeGroup) { // The default is looked up in -defaultValue instead since extensions @@ -990,19 +1032,21 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (void)dealloc { - if ((description_->dataType == GPBDataTypeBytes) && !GPBExtensionIsRepeated(description_)) { + if ((description_->dataType == GPBDataTypeBytes) && + !GPBExtensionIsRepeated(description_)) { [defaultValue_.valueData release]; } [super dealloc]; } -- (instancetype)copyWithZone:(__unused NSZone *)zone { +- (instancetype)copyWithZone:(NSZone *)zone { +#pragma unused(zone) // Immutable. return [self retain]; } - (NSString *)singletonName { - return (NSString *_Nonnull)@(description_->singletonName); + return (NSString * _Nonnull)@(description_->singletonName); } - (const char *)singletonNameC { @@ -1018,12 +1062,15 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { } - (GPBWireFormat)wireType { - return GPBWireFormatForType(description_->dataType, GPBExtensionIsPacked(description_)); + return GPBWireFormatForType(description_->dataType, + GPBExtensionIsPacked(description_)); } - (GPBWireFormat)alternateWireType { - NSAssert(GPBExtensionIsRepeated(description_), @"Only valid on repeated extensions"); - return GPBWireFormatForType(description_->dataType, !GPBExtensionIsPacked(description_)); + NSAssert(GPBExtensionIsRepeated(description_), + @"Only valid on repeated extensions"); + return GPBWireFormatForType(description_->dataType, + !GPBExtensionIsPacked(description_)); } - (BOOL)isRepeated { @@ -1079,7 +1126,8 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { return @(defaultValue_.valueUInt64); case GPBDataTypeBytes: // Like message fields, the default is zero length data. - return (defaultValue_.valueData ? defaultValue_.valueData : GPBEmptyNSData()); + return (defaultValue_.valueData ? defaultValue_.valueData + : GPBEmptyNSData()); case GPBDataTypeString: // Like message fields, the default is zero length string. return (defaultValue_.valueString ? defaultValue_.valueString : @""); diff --git a/libs/protobuf/objectivec/GPBDescriptor_PackagePrivate.h b/libs/protobuf/objectivec/GPBDescriptor_PackagePrivate.h index 4774d4e..408f8d4 100644 --- a/libs/protobuf/objectivec/GPBDescriptor_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBDescriptor_PackagePrivate.h @@ -37,12 +37,12 @@ // Describes attributes of the field. typedef NS_OPTIONS(uint16_t, GPBFieldFlags) { - GPBFieldNone = 0, + GPBFieldNone = 0, // These map to standard protobuf concepts. - GPBFieldRequired = 1 << 0, - GPBFieldRepeated = 1 << 1, - GPBFieldPacked = 1 << 2, - GPBFieldOptional = 1 << 3, + GPBFieldRequired = 1 << 0, + GPBFieldRepeated = 1 << 1, + GPBFieldPacked = 1 << 2, + GPBFieldOptional = 1 << 3, GPBFieldHasDefaultValue = 1 << 4, // Indicate that the field should "clear" when set to zero value. This is the @@ -60,19 +60,19 @@ typedef NS_OPTIONS(uint16_t, GPBFieldFlags) { // These bits are used to mark the field as a map and what the key // type is. - GPBFieldMapKeyMask = 0xF << 8, - GPBFieldMapKeyInt32 = 1 << 8, - GPBFieldMapKeyInt64 = 2 << 8, - GPBFieldMapKeyUInt32 = 3 << 8, - GPBFieldMapKeyUInt64 = 4 << 8, - GPBFieldMapKeySInt32 = 5 << 8, - GPBFieldMapKeySInt64 = 6 << 8, - GPBFieldMapKeyFixed32 = 7 << 8, - GPBFieldMapKeyFixed64 = 8 << 8, - GPBFieldMapKeySFixed32 = 9 << 8, + GPBFieldMapKeyMask = 0xF << 8, + GPBFieldMapKeyInt32 = 1 << 8, + GPBFieldMapKeyInt64 = 2 << 8, + GPBFieldMapKeyUInt32 = 3 << 8, + GPBFieldMapKeyUInt64 = 4 << 8, + GPBFieldMapKeySInt32 = 5 << 8, + GPBFieldMapKeySInt64 = 6 << 8, + GPBFieldMapKeyFixed32 = 7 << 8, + GPBFieldMapKeyFixed64 = 8 << 8, + GPBFieldMapKeySFixed32 = 9 << 8, GPBFieldMapKeySFixed64 = 10 << 8, - GPBFieldMapKeyBool = 11 << 8, - GPBFieldMapKeyString = 12 << 8, + GPBFieldMapKeyBool = 11 << 8, + GPBFieldMapKeyString = 12 << 8, }; // NOTE: The structures defined here have their members ordered to minimize @@ -88,7 +88,7 @@ typedef struct GPBMessageFieldDescription { // kept around right now for backwards compatibility. // clazz is used iff GPBDescriptorInitializationFlag_UsesClassRefs is set. char *className; // Name of the class of the message. - Class clazz; // Class of the message. + Class clazz; // Class of the message. // For enums only: If EnumDescriptors are compiled in, it will be that, // otherwise it will be the verifier. GPBEnumDescriptorFunc enumDescFunc; @@ -120,10 +120,10 @@ typedef struct GPBMessageFieldDescriptionWithDefault { // Describes attributes of the extension. typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) { - GPBExtensionNone = 0, + GPBExtensionNone = 0, // These map to standard protobuf concepts. - GPBExtensionRepeated = 1 << 0, - GPBExtensionPacked = 1 << 1, + GPBExtensionRepeated = 1 << 0, + GPBExtensionPacked = 1 << 1, GPBExtensionSetWireFormat = 1 << 2, }; @@ -132,10 +132,10 @@ typedef struct GPBExtensionDescription { GPBGenericValue defaultValue; const char *singletonName; // Before 3.12, `extendedClass` was just a `const char *`. Thanks to nested - // initialization - // (https://en.cppreference.com/w/c/language/struct_initialization#Nested_initialization) old - // generated code with `.extendedClass = GPBStringifySymbol(Something)` still works; and the - // current generator can use `extendedClass.clazz`, to pass a Class reference. + // initialization (https://en.cppreference.com/w/c/language/struct_initialization#Nested_initialization) + // old generated code with `.extendedClass = GPBStringifySymbol(Something)` + // still works; and the current generator can use `extendedClass.clazz`, to + // pass a Class reference. union { const char *name; Class clazz; @@ -150,9 +150,9 @@ typedef struct GPBExtensionDescription { union { const char *messageOrGroupClassName; union { - const char *name; - Class clazz; - } messageOrGroupClass; + const char *name; + Class clazz; + } messageOrGroupClass; }; GPBEnumDescriptorFunc enumDescriptorFunc; int32_t fieldNumber; @@ -161,14 +161,14 @@ typedef struct GPBExtensionDescription { } GPBExtensionDescription; typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { - GPBDescriptorInitializationFlag_None = 0, + GPBDescriptorInitializationFlag_None = 0, GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0, - GPBDescriptorInitializationFlag_WireFormat = 1 << 1, + GPBDescriptorInitializationFlag_WireFormat = 1 << 1, // This is used as a stopgap as we move from using class names to class // references. The runtime needs to support both until we allow a // breaking change in the runtime. - GPBDescriptorInitializationFlag_UsesClassRefs = 1 << 2, + GPBDescriptorInitializationFlag_UsesClassRefs = 1 << 2, // This flag is used to indicate that the generated sources already contain // the `GPBFieldClearHasIvarOnZero` flag and it doesn't have to be computed @@ -185,13 +185,14 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { } // fieldDescriptions have to be long lived, they are held as raw pointers. -+ (instancetype)allocDescriptorForClass:(Class)messageClass - rootClass:(Class)rootClass - file:(GPBFileDescriptor *)file - fields:(void *)fieldDescriptions - fieldCount:(uint32_t)fieldCount - storageSize:(uint32_t)storageSize - flags:(GPBDescriptorInitializationFlags)flags; ++ (instancetype) + allocDescriptorForClass:(Class)messageClass + rootClass:(Class)rootClass + file:(GPBFileDescriptor *)file + fields:(void *)fieldDescriptions + fieldCount:(uint32_t)fieldCount + storageSize:(uint32_t)storageSize + flags:(GPBDescriptorInitializationFlags)flags; - (instancetype)initWithClass:(Class)messageClass file:(GPBFileDescriptor *)file @@ -219,7 +220,8 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { - (instancetype)initWithPackage:(NSString *)package objcPrefix:(NSString *)objcPrefix syntax:(GPBFileSyntax)syntax; -- (instancetype)initWithPackage:(NSString *)package syntax:(GPBFileSyntax)syntax; +- (instancetype)initWithPackage:(NSString *)package + syntax:(GPBFileSyntax)syntax; @end @interface GPBOneofDescriptor () { @@ -256,17 +258,19 @@ typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { @interface GPBEnumDescriptor () // valueNames, values and extraTextFormatInfo have to be long lived, they are // held as raw pointers. -+ (instancetype)allocDescriptorForName:(NSString *)name - valueNames:(const char *)valueNames - values:(const int32_t *)values - count:(uint32_t)valueCount - enumVerifier:(GPBEnumValidationFunc)enumVerifier; -+ (instancetype)allocDescriptorForName:(NSString *)name - valueNames:(const char *)valueNames - values:(const int32_t *)values - count:(uint32_t)valueCount - enumVerifier:(GPBEnumValidationFunc)enumVerifier - extraTextFormatInfo:(const char *)extraTextFormatInfo; ++ (instancetype) + allocDescriptorForName:(NSString *)name + valueNames:(const char *)valueNames + values:(const int32_t *)values + count:(uint32_t)valueCount + enumVerifier:(GPBEnumValidationFunc)enumVerifier; ++ (instancetype) + allocDescriptorForName:(NSString *)name + valueNames:(const char *)valueNames + values:(const int32_t *)values + count:(uint32_t)valueCount + enumVerifier:(GPBEnumValidationFunc)enumVerifier + extraTextFormatInfo:(const char *)extraTextFormatInfo; - (instancetype)initWithName:(NSString *)name valueNames:(const char *)valueNames @@ -305,7 +309,8 @@ CF_EXTERN_C_BEGIN #pragma clang diagnostic ignored "-Wdirect-ivar-access" GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) { - return (field->description_->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0; + return (field->description_->flags & + (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0; } GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) { @@ -348,13 +353,22 @@ GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) { // Helper for compile time assets. #ifndef GPBInternalCompileAssert -#define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg) -#endif // GPBInternalCompileAssert + #if __has_feature(c_static_assert) || __has_extension(c_static_assert) + #define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg) + #else + // Pre-Xcode 7 support. + #define GPBInternalCompileAssertSymbolInner(line, msg) GPBInternalCompileAssert ## line ## __ ## msg + #define GPBInternalCompileAssertSymbol(line, msg) GPBInternalCompileAssertSymbolInner(line, msg) + #define GPBInternalCompileAssert(test, msg) \ + typedef char GPBInternalCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ] + #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert) +#endif // GPBInternalCompileAssert // Sanity check that there isn't padding between the field description // structures with and without a default. GPBInternalCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) == - (sizeof(GPBGenericValue) + sizeof(GPBMessageFieldDescription)), + (sizeof(GPBGenericValue) + + sizeof(GPBMessageFieldDescription)), DescriptionsWithDefault_different_size_than_expected); CF_EXTERN_C_END diff --git a/libs/protobuf/objectivec/GPBDictionary.h b/libs/protobuf/objectivec/GPBDictionary.h index 90440e3..28d880d 100644 --- a/libs/protobuf/objectivec/GPBDictionary.h +++ b/libs/protobuf/objectivec/GPBDictionary.h @@ -43,11 +43,9 @@ NS_ASSUME_NONNULL_BEGIN -// Disable clang-format for the macros. -// clang-format off - //%PDDM-EXPAND DECLARE_DICTIONARIES() // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt32 -> UInt32 @@ -5481,6 +5479,7 @@ NS_ASSUME_NONNULL_BEGIN @end +// clang-format on //%PDDM-EXPAND-END DECLARE_DICTIONARIES() NS_ASSUME_NONNULL_END @@ -5771,5 +5770,3 @@ NS_ASSUME_NONNULL_END //% **/ //%- (void)setRawValue:(VALUE_TYPE)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key; //% - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBDictionary.m b/libs/protobuf/objectivec/GPBDictionary.m index 1d71307..187a970 100644 --- a/libs/protobuf/objectivec/GPBDictionary.m +++ b/libs/protobuf/objectivec/GPBDictionary.m @@ -51,6 +51,18 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdirect-ivar-access" +// Used to include code only visible to specific versions of the static +// analyzer. Useful for wrapping code that only exists to silence the analyzer. +// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, +// END_APPLE_BUILD_VERSION using: +// xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ +// Example usage: +// #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif +#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \ + (defined(__clang_analyzer__) && \ + (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ + __apple_build_version__ <= END_APPLE_BUILD_VERSION)) + enum { kMapKeyFieldNumber = 1, kMapValueFieldNumber = 2, @@ -61,9 +73,6 @@ static BOOL DictDefault_IsValidValue(int32_t value) { return (value != kGPBUnrecognizedEnumeratorValue); } -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2) //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) { //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { @@ -113,13 +122,15 @@ static BOOL DictDefault_IsValidValue(int32_t value) { //%} //% //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP) -//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) { +//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) { //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); +//% #pragma unused(dataType) // For when asserts are off in release. //% return GPBCompute##VALUE_NAME##Size(fieldNum, value); //%} //% -//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) { +//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) { //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); +//% #pragma unused(dataType) // For when asserts are off in release. //% [stream write##VALUE_NAME##:fieldNum value:value]; //%} //% @@ -136,6 +147,7 @@ static BOOL DictDefault_IsValidValue(int32_t value) { //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes) //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS() // This block of code is generated, do not edit it directly. +// clang-format off static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) { if (dataType == GPBDataTypeInt32) { @@ -229,53 +241,63 @@ static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, u } } -static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) { +static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. return GPBComputeBoolSize(fieldNum, value); } -static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) { +static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. [stream writeBool:fieldNum value:value]; } -static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) { +static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. return GPBComputeEnumSize(fieldNum, value); } -static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) { +static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. [stream writeEnum:fieldNum value:value]; } -static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, __unused GPBDataType dataType) { +static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. return GPBComputeFloatSize(fieldNum, value); } -static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, __unused GPBDataType dataType) { +static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. [stream writeFloat:fieldNum value:value]; } -static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, __unused GPBDataType dataType) { +static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. return GPBComputeDoubleSize(fieldNum, value); } -static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, __unused GPBDataType dataType) { +static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. [stream writeDouble:fieldNum value:value]; } -static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) { +static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. return GPBComputeStringSize(fieldNum, value); } -static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) { +static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) { NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); + #pragma unused(dataType) // For when asserts are off in release. [stream writeString:fieldNum value:value]; } @@ -304,9 +326,8 @@ static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_ } } -//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS() - // clang-format on +//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS() size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { GPBDataType mapValueType = GPBGetFieldDataType(field); @@ -325,7 +346,8 @@ size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescri } void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream, - NSDictionary *dict, GPBFieldDescriptor *field) { + NSDictionary *dict, + GPBFieldDescriptor *field) { NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); GPBDataType mapValueType = GPBGetFieldDataType(field); uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); @@ -346,10 +368,10 @@ void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream } } -BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, - __unused GPBFieldDescriptor *field) { +BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type"); + #pragma unused(field) // For when asserts are off in release. GPBMessage *msg; NSEnumerator *objects = [dict objectEnumerator]; while ((msg = [objects nextObject])) { @@ -361,8 +383,11 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, } // Note: if the type is an object, it the retain pass back to the caller. -static void ReadValue(GPBCodedInputStream *stream, GPBGenericValue *valueToFill, GPBDataType type, - id registry, GPBFieldDescriptor *field) { +static void ReadValue(GPBCodedInputStream *stream, + GPBGenericValue *valueToFill, + GPBDataType type, + GPBExtensionRegistry *registry, + GPBFieldDescriptor *field) { switch (type) { case GPBDataTypeBool: valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_); @@ -427,8 +452,10 @@ static void ReadValue(GPBCodedInputStream *stream, GPBGenericValue *valueToFill, } } -void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, - id registry, GPBFieldDescriptor *field, +void GPBDictionaryReadEntry(id mapDictionary, + GPBCodedInputStream *stream, + GPBExtensionRegistry *registry, + GPBFieldDescriptor *field, GPBMessage *parentMessage) { GPBDataType keyDataType = field.mapKeyDataType; GPBDataType valueDataType = GPBGetFieldDataType(field); @@ -442,7 +469,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } GPBCodedInputStreamState *state = &stream->state_; - uint32_t keyTag = GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO)); + uint32_t keyTag = + GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO)); uint32_t valueTag = GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO)); @@ -457,7 +485,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, // zero signals EOF / limit reached break; } else { // Unknown - if (![stream skipField:tag]) { + if (![stream skipField:tag]){ hitError = YES; break; } @@ -497,8 +525,22 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) { +#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) + // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can + // be raised as needed for new Xcodes. + // + // This is only needed on a "shallow" analyze; on a "deep" analyze, the + // existing code path gets this correct. In shallow, the analyzer decides + // GPBDataTypeIsObject(valueDataType) is both false and true on a single + // path through this function, allowing nil to be used for the + // setObject:forKey:. + if (value.valueString == nil) { + value.valueString = [@"" retain]; + } +#endif // mapDictionary is an NSMutableDictionary - [(NSMutableDictionary *)mapDictionary setObject:value.valueString forKey:key.valueString]; + [(NSMutableDictionary *)mapDictionary setObject:value.valueString + forKey:key.valueString]; } else { if (valueDataType == GPBDataTypeEnum) { if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) || @@ -528,9 +570,6 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, // Macros for the common basic cases. // -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE) //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD) //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id) @@ -588,7 +627,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //% return self; //%} //% -//%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +//%- (instancetype)initWithCapacity:(NSUInteger)numItems { +//% #pragma unused(numItems) //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; //%} //% @@ -653,7 +693,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //%} //% //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func -//% capacity:(__unused NSUInteger)numItems { +//% capacity:(NSUInteger)numItems { +//% #pragma unused(numItems) //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; //%} //% @@ -819,7 +860,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //%} //% //%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { -//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, __unused BOOL *stop) { +//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) { +//% #pragma unused(stop) //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR)); //% }]; //%} @@ -873,7 +915,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //% //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) //% -//%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +//%- (instancetype)initWithCapacity:(NSUInteger)numItems { +//% #pragma unused(numItems) //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; //%} //% @@ -1386,6 +1429,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt32 -> UInt32 @@ -1423,7 +1467,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -1529,7 +1574,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]); }]; } @@ -1604,7 +1650,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -1710,7 +1757,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]); }]; } @@ -1785,7 +1833,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -1891,7 +1940,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]); }]; } @@ -1966,7 +2016,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -2072,7 +2123,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]); }]; } @@ -2147,7 +2199,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -2253,7 +2306,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, __unused BOOL *stop) { + [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")); }]; } @@ -2328,7 +2382,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -2434,7 +2489,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, __unused BOOL *stop) { + [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); }]; } @@ -2509,7 +2565,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -2615,7 +2672,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, __unused BOOL *stop) { + [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); }]; } @@ -2703,7 +2761,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } @@ -2821,7 +2880,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], @(value)); }]; } @@ -2944,7 +3004,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -3074,7 +3135,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, __unused BOOL *stop) { + [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%u", key], object); }]; } @@ -3114,8 +3176,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int32 -> UInt32 @@ -3153,7 +3217,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -3259,7 +3324,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]); }]; } @@ -3334,7 +3400,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -3440,7 +3507,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]); }]; } @@ -3515,7 +3583,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -3621,7 +3690,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]); }]; } @@ -3696,7 +3766,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -3802,7 +3873,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]); }]; } @@ -3877,7 +3949,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -3983,7 +4056,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, __unused BOOL *stop) { + [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")); }]; } @@ -4058,7 +4132,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -4164,7 +4239,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, __unused BOOL *stop) { + [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); }]; } @@ -4239,7 +4315,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -4345,7 +4422,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, __unused BOOL *stop) { + [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); }]; } @@ -4433,7 +4511,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } @@ -4551,7 +4630,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], @(value)); }]; } @@ -4674,7 +4754,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -4804,7 +4885,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, __unused BOOL *stop) { + [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%d", key], object); }]; } @@ -4844,8 +4926,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt64 -> UInt32 @@ -4883,7 +4967,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -4989,7 +5074,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]); }]; } @@ -5064,7 +5150,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -5170,7 +5257,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]); }]; } @@ -5245,7 +5333,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -5351,7 +5440,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]); }]; } @@ -5426,7 +5516,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -5532,7 +5623,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]); }]; } @@ -5607,7 +5699,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -5713,7 +5806,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, __unused BOOL *stop) { + [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false")); }]; } @@ -5788,7 +5882,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -5894,7 +5989,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, __unused BOOL *stop) { + [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); }]; } @@ -5969,7 +6065,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -6075,7 +6172,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, __unused BOOL *stop) { + [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); }]; } @@ -6163,7 +6261,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } @@ -6281,7 +6380,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], @(value)); }]; } @@ -6404,7 +6504,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -6534,7 +6635,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, __unused BOOL *stop) { + [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%llu", key], object); }]; } @@ -6574,8 +6676,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int64 -> UInt32 @@ -6613,7 +6717,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -6719,7 +6824,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]); }]; } @@ -6794,7 +6900,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -6900,7 +7007,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]); }]; } @@ -6975,7 +7083,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -7081,7 +7190,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]); }]; } @@ -7156,7 +7266,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -7262,7 +7373,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]); }]; } @@ -7337,7 +7449,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -7443,7 +7556,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, __unused BOOL *stop) { + [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false")); }]; } @@ -7518,7 +7632,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -7624,7 +7739,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, __unused BOOL *stop) { + [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); }]; } @@ -7699,7 +7815,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -7805,7 +7922,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, __unused BOOL *stop) { + [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); }]; } @@ -7893,7 +8011,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } @@ -8011,7 +8130,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], @(value)); }]; } @@ -8134,7 +8254,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -8264,7 +8385,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, __unused BOOL *stop) { + [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) { + #pragma unused(stop) block([NSString stringWithFormat:@"%lld", key], object); }]; } @@ -8304,8 +8426,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - String -> UInt32 @@ -8347,7 +8471,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -8453,7 +8578,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%u", value]); }]; } @@ -8536,7 +8662,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -8642,7 +8769,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%d", value]); }]; } @@ -8725,7 +8853,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -8831,7 +8960,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, __unused BOOL *stop) { + [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%llu", value]); }]; } @@ -8914,7 +9044,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -9020,7 +9151,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, __unused BOOL *stop) { + [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%lld", value]); }]; } @@ -9103,7 +9235,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -9209,7 +9342,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, __unused BOOL *stop) { + [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) { + #pragma unused(stop) block(key, (value ? @"true" : @"false")); }]; } @@ -9292,7 +9426,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -9398,7 +9533,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, __unused BOOL *stop) { + [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); }]; } @@ -9481,7 +9617,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -9587,7 +9724,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, __unused BOOL *stop) { + [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) { + #pragma unused(stop) block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); }]; } @@ -9683,7 +9821,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } @@ -9801,7 +9940,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { - [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) { + [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) { + #pragma unused(stop) block(key, @(value)); }]; } @@ -9892,11 +10032,13 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND-END (5 expansions) //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> UInt32 @@ -9939,7 +10081,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt32s:NULL forKeys:NULL count:0]; } @@ -10103,8 +10246,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Int32 @@ -10147,7 +10292,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt32s:NULL forKeys:NULL count:0]; } @@ -10311,8 +10457,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> UInt64 @@ -10355,7 +10503,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithUInt64s:NULL forKeys:NULL count:0]; } @@ -10519,8 +10668,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Int64 @@ -10563,7 +10714,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithInt64s:NULL forKeys:NULL count:0]; } @@ -10727,8 +10879,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Bool @@ -10771,7 +10925,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithBools:NULL forKeys:NULL count:0]; } @@ -10935,8 +11090,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Float @@ -10979,7 +11136,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithFloats:NULL forKeys:NULL count:0]; } @@ -11143,8 +11301,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Double @@ -11187,7 +11347,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithDoubles:NULL forKeys:NULL count:0]; } @@ -11351,8 +11512,10 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end +// clang-format on //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Object @@ -11394,7 +11557,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return self; } -- (instancetype)initWithCapacity:(__unused NSUInteger)numItems { +- (instancetype)initWithCapacity:(NSUInteger)numItems { + #pragma unused(numItems) return [self initWithObjects:NULL forKeys:NULL count:0]; } @@ -11580,9 +11744,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, @end -//%PDDM-EXPAND-END (8 expansions) - // clang-format on +//%PDDM-EXPAND-END (8 expansions) #pragma mark - Bool -> Enum @@ -11604,8 +11767,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - rawValues:(const int32_t[])rawValues - forKeys:(const BOOL[])keys + rawValues:(const int32_t [])rawValues + forKeys:(const BOOL [])keys count:(NSUInteger)count { self = [super init]; if (self) { @@ -11638,13 +11801,15 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func - capacity:(__unused NSUInteger)numItems { + capacity:(NSUInteger)numItems { +#pragma unused(numItems) return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; } #if !defined(NS_BLOCK_ASSERTIONS) - (void)dealloc { - NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@", + NSAssert(!_autocreator, + @"%@: Autocreator must be cleared before release, autocreator: %@", [self class], _autocreator); [super dealloc]; } @@ -11693,7 +11858,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); } -- (BOOL)getEnum:(int32_t *)value forKey:(BOOL)key { +- (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key { int idx = (key ? 1 : 0); if (_valueSet[idx]) { if (value) { @@ -11708,7 +11873,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return NO; } -- (BOOL)getRawValue:(int32_t *)rawValue forKey:(BOOL)key { +- (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key { int idx = (key ? 1 : 0); if (_valueSet[idx]) { if (rawValue) { @@ -11719,8 +11884,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return NO; } -- (void)enumerateKeysAndRawValuesUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t value, - BOOL *stop))block { +- (void)enumerateKeysAndRawValuesUsingBlock: + (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block { BOOL stop = NO; if (_valueSet[0]) { block(NO, _values[0], &stop); @@ -11730,8 +11895,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } } -- (void)enumerateKeysAndEnumsUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t rawValue, - BOOL *stop))block { +- (void)enumerateKeysAndEnumsUsingBlock: + (void (NS_NOESCAPE ^)(BOOL key, int32_t rawValue, BOOL *stop))block { BOOL stop = NO; GPBEnumValidationFunc func = _validationFunc; int32_t validatedValue; @@ -11751,10 +11916,9 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } } -// clang-format off - //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) // This block of code is generated, do not edit it directly. +// clang-format off - (NSData *)serializedDataForUnknownValue:(int32_t)value forKey:(GPBGenericValue *)key @@ -11769,9 +11933,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, return data; } -//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) - // clang-format on +//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { GPBDataType valueDataType = GPBGetFieldDataType(field); @@ -11809,7 +11972,7 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } } -- (void)enumerateForTextFormat:(void(NS_NOESCAPE ^)(id keyObj, id valueObj))block { +- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { if (_valueSet[0]) { block(@"false", @(_values[0])); } @@ -11818,7 +11981,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } } -- (void)setGPBGenericValue:(GPBGenericValue *)value forGPBGenericValueKey:(GPBGenericValue *)key { +- (void)setGPBGenericValue:(GPBGenericValue *)value + forGPBGenericValueKey:(GPBGenericValue *)key { int idx = (key->valueBool ? 1 : 0); _values[idx] = value->valueInt32; _valueSet[idx] = YES; @@ -11841,7 +12005,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, - (void)setEnum:(int32_t)value forKey:(BOOL)key { if (!_validationFunc(value)) { [NSException raise:NSInvalidArgumentException - format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)", value]; + format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)", + value]; } int idx = (key ? 1 : 0); _values[idx] = value; @@ -11878,7 +12043,8 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } - (void)dealloc { - NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@", + NSAssert(!_autocreator, + @"%@: Autocreator must be cleared before release, autocreator: %@", [self class], _autocreator); [_dictionary release]; [super dealloc]; @@ -11886,12 +12052,14 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, #pragma mark Required NSDictionary overrides -- (instancetype)initWithObjects:(const id[])objects - forKeys:(const id[])keys +- (instancetype)initWithObjects:(const id [])objects + forKeys:(const id [])keys count:(NSUInteger)count { self = [super init]; if (self) { - _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects forKeys:keys count:count]; + _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects + forKeys:keys + count:count]; } return self; } @@ -11964,12 +12132,16 @@ void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, } } -- (void)enumerateKeysAndObjectsUsingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block { +- (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key, + id obj, + BOOL *stop))block { [_dictionary enumerateKeysAndObjectsUsingBlock:block]; } - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts - usingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(id key, + id obj, + BOOL *stop))block { [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; } diff --git a/libs/protobuf/objectivec/GPBDictionary_PackagePrivate.h b/libs/protobuf/objectivec/GPBDictionary_PackagePrivate.h index 3735fa5..15e4283 100644 --- a/libs/protobuf/objectivec/GPBDictionary_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBDictionary_PackagePrivate.h @@ -34,20 +34,18 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; -@protocol GPBExtensionRegistry; +@class GPBExtensionRegistry; @class GPBFieldDescriptor; @protocol GPBDictionaryInternalsProtocol - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field; - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream asField:(GPBFieldDescriptor *)field; -- (void)setGPBGenericValue:(GPBGenericValue *)value forGPBGenericValueKey:(GPBGenericValue *)key; +- (void)setGPBGenericValue:(GPBGenericValue *)value + forGPBGenericValueKey:(GPBGenericValue *)key; - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block; @end -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME) //%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME) //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object) @@ -84,6 +82,7 @@ //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBUInt32UInt32Dictionary () { @package @@ -145,8 +144,10 @@ __attribute__((ns_returns_retained)); @end +// clang-format on //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBInt32UInt32Dictionary () { @package @@ -208,8 +209,10 @@ __attribute__((ns_returns_retained)); @end +// clang-format on //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBUInt64UInt32Dictionary () { @package @@ -271,8 +274,10 @@ __attribute__((ns_returns_retained)); @end +// clang-format on //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBInt64UInt32Dictionary () { @package @@ -334,8 +339,10 @@ __attribute__((ns_returns_retained)); @end +// clang-format on //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBBoolUInt32Dictionary () { @package @@ -397,8 +404,10 @@ __attribute__((ns_returns_retained)); @end +// clang-format on //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String) // This block of code is generated, do not edit it directly. +// clang-format off @interface GPBStringUInt32Dictionary () { @package @@ -451,14 +460,13 @@ keyDataType:(GPBDataType)keyDataType; @end -//%PDDM-EXPAND-END (6 expansions) - // clang-format on +//%PDDM-EXPAND-END (6 expansions) #pragma mark - NSDictionary Subclass @interface GPBAutocreatedDictionary : NSMutableDictionary { - @package + @package GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator; } @end @@ -469,20 +477,24 @@ CF_EXTERN_C_BEGIN // Helper to compute size when an NSDictionary is used for the map instead // of a custom type. -size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field); +size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, + GPBFieldDescriptor *field); // Helper to write out when an NSDictionary is used for the map instead // of a custom type. -void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream, - NSDictionary *dict, GPBFieldDescriptor *field); +void GPBDictionaryWriteToStreamInternalHelper( + GPBCodedOutputStream *outputStream, NSDictionary *dict, + GPBFieldDescriptor *field); // Helper to check message initialization when an NSDictionary is used for // the map instead of a custom type. -BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field); +BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, + GPBFieldDescriptor *field); // Helper to read a map instead. void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream, - id registry, GPBFieldDescriptor *field, + GPBExtensionRegistry *registry, + GPBFieldDescriptor *field, GPBMessage *parentMessage); CF_EXTERN_C_END diff --git a/libs/protobuf/objectivec/GPBDuration.pbobjc.h b/libs/protobuf/objectivec/GPBDuration.pbobjc.h index 7fb2658..d6236b0 100644 --- a/libs/protobuf/objectivec/GPBDuration.pbobjc.h +++ b/libs/protobuf/objectivec/GPBDuration.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/duration.proto #import "GPBDescriptor.h" @@ -132,5 +131,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBDuration.pbobjc.m b/libs/protobuf/objectivec/GPBDuration.pbobjc.m index 06f5bc3..11ba5e5 100644 --- a/libs/protobuf/objectivec/GPBDuration.pbobjc.m +++ b/libs/protobuf/objectivec/GPBDuration.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/duration.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -94,5 +93,3 @@ typedef struct GPBDuration__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBEmpty.pbobjc.h b/libs/protobuf/objectivec/GPBEmpty.pbobjc.h index 1c840eb..5878223 100644 --- a/libs/protobuf/objectivec/GPBEmpty.pbobjc.h +++ b/libs/protobuf/objectivec/GPBEmpty.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/empty.proto #import "GPBDescriptor.h" @@ -59,5 +58,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBEmpty.pbobjc.m b/libs/protobuf/objectivec/GPBEmpty.pbobjc.m index 2360c36..8aefddb 100644 --- a/libs/protobuf/objectivec/GPBEmpty.pbobjc.m +++ b/libs/protobuf/objectivec/GPBEmpty.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/empty.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -70,5 +69,3 @@ typedef struct GPBEmpty__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBExtensionInternals.h b/libs/protobuf/objectivec/GPBExtensionInternals.h index af2aba6..2b980ae 100644 --- a/libs/protobuf/objectivec/GPBExtensionInternals.h +++ b/libs/protobuf/objectivec/GPBExtensionInternals.h @@ -34,14 +34,17 @@ @class GPBCodedInputStream; @class GPBCodedOutputStream; -@protocol GPBExtensionRegistry; +@class GPBExtensionRegistry; -void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL isPackedOnStream, +void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, + BOOL isPackedOnStream, GPBCodedInputStream *input, - id extensionRegistry, + GPBExtensionRegistry *extensionRegistry, GPBMessage *message); -size_t GPBComputeExtensionSerializedSizeIncludingTag(GPBExtensionDescriptor *extension, id value); +size_t GPBComputeExtensionSerializedSizeIncludingTag( + GPBExtensionDescriptor *extension, id value); -void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension, id value, +void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension, + id value, GPBCodedOutputStream *output); diff --git a/libs/protobuf/objectivec/GPBExtensionInternals.m b/libs/protobuf/objectivec/GPBExtensionInternals.m index dbfa100..bacec57 100644 --- a/libs/protobuf/objectivec/GPBExtensionInternals.m +++ b/libs/protobuf/objectivec/GPBExtensionInternals.m @@ -40,7 +40,7 @@ static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, GPBCodedInputStream *input, - id extensionRegistry, + GPBExtensionRegistry *extensionRegistry, GPBMessage *existingValue) __attribute__((ns_returns_retained)); @@ -65,11 +65,11 @@ GPB_INLINE size_t DataTypeSize(GPBDataType dataType) { } static size_t ComputePBSerializedSizeNoTagOfObject(GPBDataType dataType, id object) { -#define FIELD_CASE(TYPE, ACCESSOR) \ - case GPBDataType##TYPE: \ +#define FIELD_CASE(TYPE, ACCESSOR) \ + case GPBDataType##TYPE: \ return GPBCompute##TYPE##SizeNoTag([(NSNumber *)object ACCESSOR]); -#define FIELD_CASE2(TYPE) \ - case GPBDataType##TYPE: \ +#define FIELD_CASE2(TYPE) \ + case GPBDataType##TYPE: \ return GPBCompute##TYPE##SizeNoTag(object); switch (dataType) { FIELD_CASE(Bool, boolValue) @@ -95,13 +95,14 @@ static size_t ComputePBSerializedSizeNoTagOfObject(GPBDataType dataType, id obje #undef FIELD_CASE2 } -static size_t ComputeSerializedSizeIncludingTagOfObject(GPBExtensionDescription *description, - id object) { -#define FIELD_CASE(TYPE, ACCESSOR) \ - case GPBDataType##TYPE: \ - return GPBCompute##TYPE##Size(description->fieldNumber, [(NSNumber *)object ACCESSOR]); -#define FIELD_CASE2(TYPE) \ - case GPBDataType##TYPE: \ +static size_t ComputeSerializedSizeIncludingTagOfObject( + GPBExtensionDescription *description, id object) { +#define FIELD_CASE(TYPE, ACCESSOR) \ + case GPBDataType##TYPE: \ + return GPBCompute##TYPE##Size(description->fieldNumber, \ + [(NSNumber *)object ACCESSOR]); +#define FIELD_CASE2(TYPE) \ + case GPBDataType##TYPE: \ return GPBCompute##TYPE##Size(description->fieldNumber, object); switch (description->dataType) { FIELD_CASE(Bool, boolValue) @@ -123,7 +124,8 @@ static size_t ComputeSerializedSizeIncludingTagOfObject(GPBExtensionDescription FIELD_CASE2(Group) case GPBDataTypeMessage: if (GPBExtensionIsWireFormat(description)) { - return GPBComputeMessageSetExtensionSize(description->fieldNumber, object); + return GPBComputeMessageSetExtensionSize(description->fieldNumber, + object); } else { return GPBComputeMessageSize(description->fieldNumber, object); } @@ -132,8 +134,8 @@ static size_t ComputeSerializedSizeIncludingTagOfObject(GPBExtensionDescription #undef FIELD_CASE2 } -static size_t ComputeSerializedSizeIncludingTagOfArray(GPBExtensionDescription *description, - NSArray *values) { +static size_t ComputeSerializedSizeIncludingTagOfArray( + GPBExtensionDescription *description, NSArray *values) { if (GPBExtensionIsPacked(description)) { size_t size = 0; size_t typeSize = DataTypeSize(description->dataType); @@ -141,7 +143,8 @@ static size_t ComputeSerializedSizeIncludingTagOfArray(GPBExtensionDescription * size = values.count * typeSize; } else { for (id value in values) { - size += ComputePBSerializedSizeNoTagOfObject(description->dataType, value); + size += + ComputePBSerializedSizeNoTagOfObject(description->dataType, value); } } return size + GPBComputeTagSize(description->fieldNumber) + @@ -155,12 +158,13 @@ static size_t ComputeSerializedSizeIncludingTagOfArray(GPBExtensionDescription * } } -static void WriteObjectIncludingTagToCodedOutputStream(id object, - GPBExtensionDescription *description, - GPBCodedOutputStream *output) { -#define FIELD_CASE(TYPE, ACCESSOR) \ - case GPBDataType##TYPE: \ - [output write##TYPE:description->fieldNumber value:[(NSNumber *)object ACCESSOR]]; \ +static void WriteObjectIncludingTagToCodedOutputStream( + id object, GPBExtensionDescription *description, + GPBCodedOutputStream *output) { +#define FIELD_CASE(TYPE, ACCESSOR) \ + case GPBDataType##TYPE: \ + [output write##TYPE:description->fieldNumber \ + value:[(NSNumber *)object ACCESSOR]]; \ return; #define FIELD_CASE2(TYPE) \ case GPBDataType##TYPE: \ @@ -196,8 +200,9 @@ static void WriteObjectIncludingTagToCodedOutputStream(id object, #undef FIELD_CASE2 } -static void WriteObjectNoTagToCodedOutputStream(id object, GPBExtensionDescription *description, - GPBCodedOutputStream *output) { +static void WriteObjectNoTagToCodedOutputStream( + id object, GPBExtensionDescription *description, + GPBCodedOutputStream *output) { #define FIELD_CASE(TYPE, ACCESSOR) \ case GPBDataType##TYPE: \ [output write##TYPE##NoTag:[(NSNumber *)object ACCESSOR]]; \ @@ -232,18 +237,20 @@ static void WriteObjectNoTagToCodedOutputStream(id object, GPBExtensionDescripti #undef FIELD_CASE2 } -static void WriteArrayIncludingTagsToCodedOutputStream(NSArray *values, - GPBExtensionDescription *description, - GPBCodedOutputStream *output) { +static void WriteArrayIncludingTagsToCodedOutputStream( + NSArray *values, GPBExtensionDescription *description, + GPBCodedOutputStream *output) { if (GPBExtensionIsPacked(description)) { - [output writeTag:description->fieldNumber format:GPBWireFormatLengthDelimited]; + [output writeTag:description->fieldNumber + format:GPBWireFormatLengthDelimited]; size_t dataSize = 0; size_t typeSize = DataTypeSize(description->dataType); if (typeSize != 0) { dataSize = values.count * typeSize; } else { for (id value in values) { - dataSize += ComputePBSerializedSizeNoTagOfObject(description->dataType, value); + dataSize += + ComputePBSerializedSizeNoTagOfObject(description->dataType, value); } } [output writeRawVarintSizeTAs32:dataSize]; @@ -263,18 +270,23 @@ static void WriteArrayIncludingTagsToCodedOutputStream(NSArray *values, #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdirect-ivar-access" -void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL isPackedOnStream, +void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, + BOOL isPackedOnStream, GPBCodedInputStream *input, - id extensionRegistry, + GPBExtensionRegistry *extensionRegistry, GPBMessage *message) { GPBExtensionDescription *description = extension->description_; GPBCodedInputStreamState *state = &input->state_; if (isPackedOnStream) { - NSCAssert(GPBExtensionIsRepeated(description), @"How was it packed if it isn't repeated?"); + NSCAssert(GPBExtensionIsRepeated(description), + @"How was it packed if it isn't repeated?"); int32_t length = GPBCodedInputStreamReadInt32(state); size_t limit = GPBCodedInputStreamPushLimit(state, length); while (GPBCodedInputStreamBytesUntilLimit(state) > 0) { - id value = NewSingleValueFromInputStream(extension, input, extensionRegistry, nil); + id value = NewSingleValueFromInputStream(extension, + input, + extensionRegistry, + nil); [message addExtension:extension value:value]; [value release]; } @@ -285,7 +297,10 @@ void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL is if (!isRepeated && GPBDataTypeIsMessage(description->dataType)) { existingValue = [message getExistingExtension:extension]; } - id value = NewSingleValueFromInputStream(extension, input, extensionRegistry, existingValue); + id value = NewSingleValueFromInputStream(extension, + input, + extensionRegistry, + existingValue); if (isRepeated) { [message addExtension:extension value:value]; } else { @@ -295,7 +310,8 @@ void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension, BOOL is } } -void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension, id value, +void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension, + id value, GPBCodedOutputStream *output) { GPBExtensionDescription *description = extension->description_; if (GPBExtensionIsRepeated(description)) { @@ -305,7 +321,8 @@ void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension, id } } -size_t GPBComputeExtensionSerializedSizeIncludingTag(GPBExtensionDescriptor *extension, id value) { +size_t GPBComputeExtensionSerializedSizeIncludingTag( + GPBExtensionDescriptor *extension, id value) { GPBExtensionDescription *description = extension->description_; if (GPBExtensionIsRepeated(description)) { return ComputeSerializedSizeIncludingTagOfArray(description, value); @@ -317,43 +334,27 @@ size_t GPBComputeExtensionSerializedSizeIncludingTag(GPBExtensionDescriptor *ext // Note that this returns a retained value intentionally. static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, GPBCodedInputStream *input, - id extensionRegistry, + GPBExtensionRegistry *extensionRegistry, GPBMessage *existingValue) { GPBExtensionDescription *description = extension->description_; GPBCodedInputStreamState *state = &input->state_; switch (description->dataType) { - case GPBDataTypeBool: - return [[NSNumber alloc] initWithBool:GPBCodedInputStreamReadBool(state)]; - case GPBDataTypeFixed32: - return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadFixed32(state)]; - case GPBDataTypeSFixed32: - return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSFixed32(state)]; - case GPBDataTypeFloat: - return [[NSNumber alloc] initWithFloat:GPBCodedInputStreamReadFloat(state)]; - case GPBDataTypeFixed64: - return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadFixed64(state)]; - case GPBDataTypeSFixed64: - return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSFixed64(state)]; - case GPBDataTypeDouble: - return [[NSNumber alloc] initWithDouble:GPBCodedInputStreamReadDouble(state)]; - case GPBDataTypeInt32: - return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadInt32(state)]; - case GPBDataTypeInt64: - return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadInt64(state)]; - case GPBDataTypeSInt32: - return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSInt32(state)]; - case GPBDataTypeSInt64: - return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSInt64(state)]; - case GPBDataTypeUInt32: - return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadUInt32(state)]; - case GPBDataTypeUInt64: - return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadUInt64(state)]; - case GPBDataTypeBytes: - return GPBCodedInputStreamReadRetainedBytes(state); - case GPBDataTypeString: - return GPBCodedInputStreamReadRetainedString(state); - case GPBDataTypeEnum: - return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadEnum(state)]; + case GPBDataTypeBool: return [[NSNumber alloc] initWithBool:GPBCodedInputStreamReadBool(state)]; + case GPBDataTypeFixed32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadFixed32(state)]; + case GPBDataTypeSFixed32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSFixed32(state)]; + case GPBDataTypeFloat: return [[NSNumber alloc] initWithFloat:GPBCodedInputStreamReadFloat(state)]; + case GPBDataTypeFixed64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadFixed64(state)]; + case GPBDataTypeSFixed64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSFixed64(state)]; + case GPBDataTypeDouble: return [[NSNumber alloc] initWithDouble:GPBCodedInputStreamReadDouble(state)]; + case GPBDataTypeInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadInt32(state)]; + case GPBDataTypeInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadInt64(state)]; + case GPBDataTypeSInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSInt32(state)]; + case GPBDataTypeSInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSInt64(state)]; + case GPBDataTypeUInt32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadUInt32(state)]; + case GPBDataTypeUInt64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadUInt64(state)]; + case GPBDataTypeBytes: return GPBCodedInputStreamReadRetainedBytes(state); + case GPBDataTypeString: return GPBCodedInputStreamReadRetainedString(state); + case GPBDataTypeEnum: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadEnum(state)]; case GPBDataTypeGroup: case GPBDataTypeMessage: { GPBMessage *message; @@ -366,14 +367,15 @@ static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension, if (description->dataType == GPBDataTypeGroup) { [input readGroup:description->fieldNumber - message:message + message:message extensionRegistry:extensionRegistry]; } else { // description->dataType == GPBDataTypeMessage if (GPBExtensionIsWireFormat(description)) { // For MessageSet fields the message length will have already been // read. - [message mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; + [message mergeFromCodedInputStream:input + extensionRegistry:extensionRegistry]; } else { [input readMessage:message extensionRegistry:extensionRegistry]; } diff --git a/libs/protobuf/objectivec/GPBExtensionRegistry.h b/libs/protobuf/objectivec/GPBExtensionRegistry.h index 2c1270b..d79632d 100644 --- a/libs/protobuf/objectivec/GPBExtensionRegistry.h +++ b/libs/protobuf/objectivec/GPBExtensionRegistry.h @@ -41,24 +41,6 @@ NS_ASSUME_NONNULL_BEGIN * GPBExtensionRegistry in which you have registered any extensions that you * want to be able to parse. Otherwise, those extensions will just be treated * like unknown fields. - **/ -@protocol GPBExtensionRegistry - -/** - * Looks for the extension registered for the given field number on a given - * GPBDescriptor. - * - * @param descriptor The descriptor to look for a registered extension on. - * @param fieldNumber The field number of the extension to look for. - * - * @return The registered GPBExtensionDescriptor or nil if none was found. - **/ -- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor - fieldNumber:(NSInteger)fieldNumber; -@end - -/** - * A concrete implementation of `GPBExtensionRegistry`. * * The *Root classes provide `+extensionRegistry` for the extensions defined * in a given file *and* all files it imports. You can also create a @@ -72,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError]; * ``` **/ -@interface GPBExtensionRegistry : NSObject +@interface GPBExtensionRegistry : NSObject /** * Adds the given GPBExtensionDescriptor to this registry. @@ -88,6 +70,18 @@ NS_ASSUME_NONNULL_BEGIN **/ - (void)addExtensions:(GPBExtensionRegistry *)registry; +/** + * Looks for the extension registered for the given field number on a given + * GPBDescriptor. + * + * @param descriptor The descriptor to look for a registered extension on. + * @param fieldNumber The field number of the extension to look for. + * + * @return The registered GPBExtensionDescriptor or nil if none was found. + **/ +- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor + fieldNumber:(NSInteger)fieldNumber; + @end NS_ASSUME_NONNULL_END diff --git a/libs/protobuf/objectivec/GPBExtensionRegistry.m b/libs/protobuf/objectivec/GPBExtensionRegistry.m index 04f1bca..e3ff7c4 100644 --- a/libs/protobuf/objectivec/GPBExtensionRegistry.m +++ b/libs/protobuf/objectivec/GPBExtensionRegistry.m @@ -40,8 +40,8 @@ - (instancetype)init { if ((self = [super init])) { // The keys are ObjC classes, so straight up ptr comparisons are fine. - mutableClassMap_ = - CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks); + mutableClassMap_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, + &kCFTypeDictionaryValueCallBacks); } return self; } @@ -69,13 +69,13 @@ } Class containingMessageClass = extension.containingMessageClass; - CFMutableDictionaryRef extensionMap = - (CFMutableDictionaryRef)CFDictionaryGetValue(mutableClassMap_, containingMessageClass); + CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) + CFDictionaryGetValue(mutableClassMap_, containingMessageClass); if (extensionMap == nil) { // Use a custom dictionary here because the keys are numbers and conversion // back and forth from NSNumber isn't worth the cost. - extensionMap = - CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks); + extensionMap = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, + &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(mutableClassMap_, containingMessageClass, extensionMap); CFRelease(extensionMap); } @@ -87,11 +87,13 @@ - (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor fieldNumber:(NSInteger)fieldNumber { Class messageClass = descriptor.messageClass; - CFMutableDictionaryRef extensionMap = - (CFMutableDictionaryRef)CFDictionaryGetValue(mutableClassMap_, messageClass); + CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) + CFDictionaryGetValue(mutableClassMap_, messageClass); ssize_t key = fieldNumber; GPBExtensionDescriptor *result = - (extensionMap ? CFDictionaryGetValue(extensionMap, (const void *)key) : nil); + (extensionMap + ? CFDictionaryGetValue(extensionMap, (const void *)key) + : nil); return result; } @@ -105,8 +107,8 @@ static void CopySubDictionary(const void *key, const void *value, void *context) Class containingMessageClass = key; CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value; - CFMutableDictionaryRef extensionMap = - (CFMutableDictionaryRef)CFDictionaryGetValue(mutableClassMap, containingMessageClass); + CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef) + CFDictionaryGetValue(mutableClassMap, containingMessageClass); if (extensionMap == nil) { extensionMap = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, otherExtensionMap); CFDictionarySetValue(mutableClassMap, containingMessageClass, extensionMap); diff --git a/libs/protobuf/objectivec/GPBFieldMask.pbobjc.h b/libs/protobuf/objectivec/GPBFieldMask.pbobjc.h index 5d4f59c..c4667b4 100644 --- a/libs/protobuf/objectivec/GPBFieldMask.pbobjc.h +++ b/libs/protobuf/objectivec/GPBFieldMask.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/field_mask.proto #import "GPBDescriptor.h" @@ -248,7 +247,7 @@ GPB_FINAL @interface GPBFieldMask : GPBMessage /** The set of field mask paths. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *pathsArray; -/** The number of items in @c pathsArray without causing the container to be created. */ +/** The number of items in @c pathsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger pathsArray_Count; @end @@ -260,5 +259,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBFieldMask.pbobjc.m b/libs/protobuf/objectivec/GPBFieldMask.pbobjc.m index acb202d..ab25d3f 100644 --- a/libs/protobuf/objectivec/GPBFieldMask.pbobjc.m +++ b/libs/protobuf/objectivec/GPBFieldMask.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/field_mask.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -83,5 +82,3 @@ typedef struct GPBFieldMask__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBMessage.h b/libs/protobuf/objectivec/GPBMessage.h index 76602b1..01253a4 100644 --- a/libs/protobuf/objectivec/GPBMessage.h +++ b/libs/protobuf/objectivec/GPBMessage.h @@ -31,12 +31,12 @@ #import #import "GPBBootstrap.h" -#import "GPBExtensionRegistry.h" @class GPBDescriptor; @class GPBCodedInputStream; @class GPBCodedOutputStream; @class GPBExtensionDescriptor; +@class GPBExtensionRegistry; @class GPBFieldDescriptor; @class GPBUnknownFieldSet; @@ -80,7 +80,7 @@ CF_EXTERN_C_END * @c +parseFromData:extensionRegistry:error: to provide an extension * registry. **/ -@interface GPBMessage : NSObject +@interface GPBMessage : NSObject // If you add an instance method/property to this class that may conflict with // fields declared in protos, you need to update objective_helpers.cc. The main @@ -147,7 +147,7 @@ CF_EXTERN_C_END * @return A new instance of the generated class. **/ + (nullable instancetype)parseFromData:(NSData *)data - extensionRegistry:(nullable id)extensionRegistry + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; /** @@ -171,7 +171,7 @@ CF_EXTERN_C_END **/ + (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable id)extensionRegistry + (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; /** @@ -196,7 +196,7 @@ CF_EXTERN_C_END **/ + (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable id)extensionRegistry + (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; /** @@ -239,7 +239,7 @@ CF_EXTERN_C_END * @return An initialized instance of the generated class. **/ - (nullable instancetype)initWithData:(NSData *)data - extensionRegistry:(nullable id)extensionRegistry + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; /** @@ -264,7 +264,7 @@ CF_EXTERN_C_END **/ - (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (nullable id)extensionRegistry + (nullable GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr; /** @@ -278,7 +278,7 @@ CF_EXTERN_C_END * unsuccessful. **/ - (void)mergeFromData:(NSData *)data - extensionRegistry:(nullable id)extensionRegistry; + extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; /** * Merges the fields from another message (of the same type) into this @@ -427,7 +427,8 @@ CF_EXTERN_C_END * @param extension The extension descriptor under which to set the value. * @param value The value to be set as the extension. **/ -- (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)value; +- (void)setExtension:(GPBExtensionDescriptor *)extension + value:(nullable id)value; /** * Adds the given value to the extension for this message. This only applies @@ -448,7 +449,9 @@ CF_EXTERN_C_END * @param index The index of the extension to be replaced. * @param value The value to be replaced in the repeated extension. **/ -- (void)setExtension:(GPBExtensionDescriptor *)extension index:(NSUInteger)index value:(id)value; +- (void)setExtension:(GPBExtensionDescriptor *)extension + index:(NSUInteger)index + value:(id)value; /** * Clears the given extension for this message. diff --git a/libs/protobuf/objectivec/GPBMessage.m b/libs/protobuf/objectivec/GPBMessage.m index 1d26392..ee94dee 100644 --- a/libs/protobuf/objectivec/GPBMessage.m +++ b/libs/protobuf/objectivec/GPBMessage.m @@ -30,9 +30,8 @@ #import "GPBMessage_PackagePrivate.h" -#import #import -#import +#import #import #import "GPBArray_PackagePrivate.h" @@ -52,7 +51,8 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdirect-ivar-access" -NSString *const GPBMessageErrorDomain = GPBNSStringifySymbol(GPBMessageErrorDomain); +NSString *const GPBMessageErrorDomain = + GPBNSStringifySymbol(GPBMessageErrorDomain); NSString *const GPBErrorReasonKey = @"Reason"; @@ -71,7 +71,8 @@ static NSString *const kGPBDataCoderKey = @"GPBData"; @package GPBUnknownFieldSet *unknownFields_; NSMutableDictionary *extensionMap_; - // Readonly access to autocreatedExtensionMap_ is protected via readOnlyLock_. + // Readonly access to autocreatedExtensionMap_ is protected via + // readOnlySemaphore_. NSMutableDictionary *autocreatedExtensionMap_; // If the object was autocreated, we remember the creator so that if we get @@ -80,38 +81,43 @@ static NSString *const kGPBDataCoderKey = @"GPBData"; GPBFieldDescriptor *autocreatorField_; GPBExtensionDescriptor *autocreatorExtension_; - // Messages can only be mutated from one thread. But some *readonly* operations modify internal - // state because they autocreate things. The autocreatedExtensionMap_ is one such structure. - // Access during readonly operations is protected via this lock. - // - // Long ago, this was an OSSpinLock, but then it came to light that there were issues for that on - // iOS: + // Message can only be mutated from one thread. But some *readonly* operations + // modify internal state because they autocreate things. The + // autocreatedExtensionMap_ is one such structure. Access during readonly + // operations is protected via this semaphore. + // NOTE: OSSpinLock may seem like a good fit here but Apple engineers have + // pointed out that they are vulnerable to live locking on iOS in cases of + // priority inversion: // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html - // It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues. - // The minOS versions are now high enough that os_unfair_lock can be used, and should provide - // all the support we need. For more information in the concurrency/locking space see: - // https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057 - // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html - // https://developer.apple.com/videos/play/wwdc2017/706/ - os_unfair_lock readOnlyLock_; + // Use of readOnlySemaphore_ must be prefaced by a call to + // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows + // readOnlySemaphore_ to be only created when actually needed. + _Atomic(dispatch_semaphore_t) readOnlySemaphore_; } @end -static id CreateArrayForField(GPBFieldDescriptor *field, GPBMessage *autocreator) +static id CreateArrayForField(GPBFieldDescriptor *field, + GPBMessage *autocreator) __attribute__((ns_returns_retained)); -static id GetOrCreateArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); +static id GetOrCreateArrayIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field); static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); -static id CreateMapForField(GPBFieldDescriptor *field, GPBMessage *autocreator) +static id CreateMapForField(GPBFieldDescriptor *field, + GPBMessage *autocreator) __attribute__((ns_returns_retained)); -static id GetOrCreateMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); +static id GetOrCreateMapIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field); static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); -static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, NSZone *zone) +static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, + NSZone *zone) __attribute__((ns_returns_retained)); #ifdef DEBUG static NSError *MessageError(NSInteger code, NSDictionary *userInfo) { - return [NSError errorWithDomain:GPBMessageErrorDomain code:code userInfo:userInfo]; + return [NSError errorWithDomain:GPBMessageErrorDomain + code:code + userInfo:userInfo]; } #endif @@ -127,7 +133,7 @@ static NSError *ErrorFromException(NSException *exception) { NSString *reason = exception.reason; NSDictionary *userInfo = nil; if ([reason length]) { - userInfo = @{GPBErrorReasonKey : reason}; + userInfo = @{ GPBErrorReasonKey : reason }; } error = [NSError errorWithDomain:GPBMessageErrorDomain @@ -137,20 +143,24 @@ static NSError *ErrorFromException(NSException *exception) { return error; } -static void CheckExtension(GPBMessage *self, GPBExtensionDescriptor *extension) { +static void CheckExtension(GPBMessage *self, + GPBExtensionDescriptor *extension) { if (![self isKindOfClass:extension.containingMessageClass]) { - [NSException raise:NSInvalidArgumentException - format:@"Extension %@ used on wrong class (%@ instead of %@)", - extension.singletonName, [self class], extension.containingMessageClass]; + [NSException + raise:NSInvalidArgumentException + format:@"Extension %@ used on wrong class (%@ instead of %@)", + extension.singletonName, + [self class], extension.containingMessageClass]; } } -static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, NSZone *zone) { +static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, + NSZone *zone) { if (extensionMap.count == 0) { return nil; } - NSMutableDictionary *result = - [[NSMutableDictionary allocWithZone:zone] initWithCapacity:extensionMap.count]; + NSMutableDictionary *result = [[NSMutableDictionary allocWithZone:zone] + initWithCapacity:extensionMap.count]; for (GPBExtensionDescriptor *extension in extensionMap) { id value = [extensionMap objectForKey:extension]; @@ -158,7 +168,8 @@ static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, NSZone if (extension.repeated) { if (isMessageExtension) { - NSMutableArray *list = [[NSMutableArray alloc] initWithCapacity:[value count]]; + NSMutableArray *list = + [[NSMutableArray alloc] initWithCapacity:[value count]]; for (GPBMessage *listValue in value) { GPBMessage *copiedValue = [listValue copyWithZone:zone]; [list addObject:copiedValue]; @@ -185,7 +196,8 @@ static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, NSZone return result; } -static id CreateArrayForField(GPBFieldDescriptor *field, GPBMessage *autocreator) { +static id CreateArrayForField(GPBFieldDescriptor *field, + GPBMessage *autocreator) { id result; GPBDataType fieldDataType = GPBGetFieldDataType(field); switch (fieldDataType) { @@ -218,7 +230,8 @@ static id CreateArrayForField(GPBFieldDescriptor *field, GPBMessage *autocreator break; case GPBDataTypeEnum: - result = [[GPBEnumArray alloc] initWithValidationFunction:field.enumDescriptor.enumVerifier]; + result = [[GPBEnumArray alloc] + initWithValidationFunction:field.enumDescriptor.enumVerifier]; break; case GPBDataTypeBytes: @@ -236,7 +249,7 @@ static id CreateArrayForField(GPBFieldDescriptor *field, GPBMessage *autocreator if (autocreator) { if (GPBDataTypeIsObject(fieldDataType)) { GPBAutocreatedArray *autoArray = result; - autoArray->_autocreator = autocreator; + autoArray->_autocreator = autocreator; } else { GPBInt32Array *gpbArray = result; gpbArray->_autocreator = autocreator; @@ -246,7 +259,8 @@ static id CreateArrayForField(GPBFieldDescriptor *field, GPBMessage *autocreator return result; } -static id CreateMapForField(GPBFieldDescriptor *field, GPBMessage *autocreator) { +static id CreateMapForField(GPBFieldDescriptor *field, + GPBMessage *autocreator) { id result; GPBDataType keyDataType = field.mapKeyDataType; GPBDataType valueDataType = GPBGetFieldDataType(field); @@ -531,9 +545,10 @@ static id CreateMapForField(GPBFieldDescriptor *field, GPBMessage *autocreator) } if (autocreator) { - if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) { + if ((keyDataType == GPBDataTypeString) && + GPBDataTypeIsObject(valueDataType)) { GPBAutocreatedDictionary *autoDict = result; - autoDict->_autocreator = autocreator; + autoDict->_autocreator = autocreator; } else { GPBInt32Int32Dictionary *gpbDict = result; gpbDict->_autocreator = autocreator; @@ -555,7 +570,8 @@ static id CreateMapForField(GPBFieldDescriptor *field, GPBMessage *autocreator) // repeated/map field parsed into the autorelease pool which is both a memory // and performance hit. -static id GetOrCreateArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { +static id GetOrCreateArrayIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field) { id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field); if (!array) { // No lock needed, this is called from places expecting to mutate @@ -595,7 +611,8 @@ static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { return expected; } -static id GetOrCreateMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { +static id GetOrCreateMapIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field) { id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field); if (!dict) { // No lock needed, this is called from places expecting to mutate @@ -624,7 +641,8 @@ static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { } // Some other thread set it, release the one created and return what got set. - if ((field.mapKeyDataType == GPBDataTypeString) && GPBFieldDataTypeIsObject(field)) { + if ((field.mapKeyDataType == GPBDataTypeString) && + GPBFieldDataTypeIsObject(field)) { GPBAutocreatedDictionary *autoDict = autocreated; autoDict->_autocreator = nil; } else { @@ -637,7 +655,8 @@ static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { #endif // !defined(__clang_analyzer__) -GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, GPBMessage *autocreator, +GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, + GPBMessage *autocreator, GPBFieldDescriptor *field) { GPBMessage *message = [[msgClass alloc] init]; message->autocreator_ = autocreator; @@ -645,12 +664,13 @@ GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, GPBMessage *autocrea return message; } -static GPBMessage *CreateMessageWithAutocreatorForExtension(Class msgClass, GPBMessage *autocreator, - GPBExtensionDescriptor *extension) +static GPBMessage *CreateMessageWithAutocreatorForExtension( + Class msgClass, GPBMessage *autocreator, GPBExtensionDescriptor *extension) __attribute__((ns_returns_retained)); -static GPBMessage *CreateMessageWithAutocreatorForExtension(Class msgClass, GPBMessage *autocreator, - GPBExtensionDescriptor *extension) { +static GPBMessage *CreateMessageWithAutocreatorForExtension( + Class msgClass, GPBMessage *autocreator, + GPBExtensionDescriptor *extension) { GPBMessage *message = [[msgClass alloc] init]; message->autocreator_ = autocreator; message->autocreatorExtension_ = [extension retain]; @@ -669,7 +689,8 @@ void GPBBecomeVisibleToAutocreator(GPBMessage *self) { // This will recursively make all parent messages visible until it reaches a // super-creator that's visible. if (self->autocreatorField_) { - GPBSetObjectIvarWithFieldPrivate(self->autocreator_, self->autocreatorField_, self); + GPBSetObjectIvarWithFieldPrivate(self->autocreator_, + self->autocreatorField_, self); } else { [self->autocreator_ setExtension:self->autocreatorExtension_ value:self]; } @@ -705,7 +726,8 @@ void GPBAutocreatedDictionaryModified(GPBMessage *self, id dictionary) { if (field.fieldType == GPBFieldTypeMap) { id curDict = GPBGetObjectIvarWithFieldNoAutocreate(self, field); if (curDict == dictionary) { - if ((field.mapKeyDataType == GPBDataTypeString) && GPBFieldDataTypeIsObject(field)) { + if ((field.mapKeyDataType == GPBDataTypeString) && + GPBFieldDataTypeIsObject(field)) { GPBAutocreatedDictionary *autoDict = dictionary; autoDict->_autocreator = nil; } else { @@ -729,15 +751,18 @@ void GPBClearMessageAutocreator(GPBMessage *self) { // Either the autocreator must have its "has" flag set to YES, or it must be // NO and not equal to ourselves. BOOL autocreatorHas = - (self->autocreatorField_ ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_) - : [self->autocreator_ hasExtension:self->autocreatorExtension_]); + (self->autocreatorField_ + ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_) + : [self->autocreator_ hasExtension:self->autocreatorExtension_]); GPBMessage *autocreatorFieldValue = (self->autocreatorField_ - ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_, self->autocreatorField_) + ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_, + self->autocreatorField_) : [self->autocreator_->autocreatedExtensionMap_ objectForKey:self->autocreatorExtension_]); NSCAssert(autocreatorHas || autocreatorFieldValue != self, - @"Cannot clear autocreator because it still refers to self, self: %@.", self); + @"Cannot clear autocreator because it still refers to self, self: %@.", + self); #endif // DEBUG && !defined(NS_BLOCK_ASSERTIONS) @@ -748,6 +773,31 @@ void GPBClearMessageAutocreator(GPBMessage *self) { self->autocreatorExtension_ = nil; } +// Call this before using the readOnlySemaphore_. This ensures it is created only once. +void GPBPrepareReadOnlySemaphore(GPBMessage *self) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdirect-ivar-access" + + // Create the semaphore on demand (rather than init) as developers might not cause them + // to be needed, and the heap usage can add up. The atomic swap is used to avoid needing + // another lock around creating it. + if (self->readOnlySemaphore_ == nil) { + dispatch_semaphore_t worker = dispatch_semaphore_create(1); + dispatch_semaphore_t expected = nil; + if (!atomic_compare_exchange_strong(&self->readOnlySemaphore_, &expected, worker)) { + dispatch_release(worker); + } +#if defined(__clang_analyzer__) + // The Xcode 9.2 (and 9.3 beta) static analyzer thinks worker is leaked + // (doesn't seem to know about atomic_compare_exchange_strong); so just + // for the analyzer, let it think worker is also released in this case. + else { dispatch_release(worker); } +#endif + } + +#pragma clang diagnostic pop +} + static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (!self->unknownFields_) { self->unknownFields_ = [[GPBUnknownFieldSet alloc] init]; @@ -798,8 +848,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (!descriptor) { // Use a dummy file that marks it as proto2 syntax so when used generically // it supports unknowns/etc. - fileDescriptor = [[GPBFileDescriptor alloc] initWithPackage:@"internal" - syntax:GPBFileSyntaxProto2]; + fileDescriptor = + [[GPBFileDescriptor alloc] initWithPackage:@"internal" + syntax:GPBFileSyntaxProto2]; descriptor = [GPBDescriptor allocDescriptorForClass:[GPBMessage class] rootClass:Nil @@ -818,9 +869,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { - (instancetype)init { if ((self = [super init])) { - messageStorage_ = - (GPBMessage_StoragePtr)(((uint8_t *)self) + class_getInstanceSize([self class])); - readOnlyLock_ = OS_UNFAIR_LOCK_INIT; + messageStorage_ = (GPBMessage_StoragePtr)( + ((uint8_t *)self) + class_getInstanceSize([self class])); } return self; @@ -831,7 +881,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (instancetype)initWithData:(NSData *)data - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr { if ((self = [self init])) { @try { @@ -839,7 +889,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (errorPtr) { *errorPtr = nil; } - } @catch (NSException *exception) { + } + @catch (NSException *exception) { [self release]; self = nil; if (errorPtr) { @@ -860,7 +911,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry + extensionRegistry: + (GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr { if ((self = [self init])) { @try { @@ -868,7 +920,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (errorPtr) { *errorPtr = nil; } - } @catch (NSException *exception) { + } + @catch (NSException *exception) { [self release]; self = nil; if (errorPtr) { @@ -891,6 +944,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { - (void)dealloc { [self internalClear:NO]; NSCAssert(!autocreator_, @"Autocreator was not cleared before dealloc."); + if (readOnlySemaphore_) { + dispatch_release(readOnlySemaphore_); + } [super dealloc]; } @@ -923,11 +979,13 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { if (field.mapKeyDataType == GPBDataTypeString) { // Map is an NSDictionary. NSDictionary *existingDict = value; - NSMutableDictionary *newDict = - [[NSMutableDictionary alloc] initWithCapacity:existingDict.count]; + NSMutableDictionary *newDict = [[NSMutableDictionary alloc] + initWithCapacity:existingDict.count]; newValue = newDict; - [existingDict enumerateKeysAndObjectsUsingBlock:^(NSString *key, GPBMessage *msg, - __unused BOOL *stop) { + [existingDict enumerateKeysAndObjectsUsingBlock:^(NSString *key, + GPBMessage *msg, + BOOL *stop) { +#pragma unused(stop) GPBMessage *copiedMsg = [msg copyWithZone:zone]; [newDict setObject:copiedMsg forKey:key]; [copiedMsg release]; @@ -950,7 +1008,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { newValue = [value copyWithZone:zone]; } } else { - if ((field.mapKeyDataType == GPBDataTypeString) && GPBFieldDataTypeIsObject(field)) { + if ((field.mapKeyDataType == GPBDataTypeString) && + GPBFieldDataTypeIsObject(field)) { // NSDictionary newValue = [value mutableCopyWithZone:zone]; } else { @@ -982,7 +1041,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { id *typePtr = (id *)&storage[field->description_->offset]; *typePtr = NULL; } - } else if (GPBFieldDataTypeIsObject(field) && GPBGetHasIvarField(self, field)) { + } else if (GPBFieldDataTypeIsObject(field) && + GPBGetHasIvarField(self, field)) { // A set string/data value (message picked off above), copy it. id value = GPBGetObjectIvarWithFieldNoAutocreate(self, field); id newValue = [value copyWithZone:zone]; @@ -1033,7 +1093,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } } } else { - if ((field.mapKeyDataType == GPBDataTypeString) && GPBFieldDataTypeIsObject(field)) { + if ((field.mapKeyDataType == GPBDataTypeString) && + GPBFieldDataTypeIsObject(field)) { if ([arrayOrMap isKindOfClass:[GPBAutocreatedDictionary class]]) { GPBAutocreatedDictionary *autoDict = arrayOrMap; if (autoDict->_autocreator == self) { @@ -1054,7 +1115,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { GPBClearAutocreatedMessageIvarWithField(self, field); GPBMessage *value = GPBGetObjectIvarWithFieldNoAutocreate(self, field); [value release]; - } else if (GPBFieldDataTypeIsObject(field) && GPBGetHasIvarField(self, field)) { + } else if (GPBFieldDataTypeIsObject(field) && + GPBGetHasIvarField(self, field)) { id value = GPBGetObjectIvarWithField(self, field); [value release]; } @@ -1106,7 +1168,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { return NO; } } else { - NSAssert(field.isOptional, @"%@: Single message field %@ not required or optional?", + NSAssert(field.isOptional, + @"%@: Single message field %@ not required or optional?", [self class], field.name); if (GPBGetHasIvarField(self, field)) { GPBMessage *message = GPBGetMessageMessageField(self, field); @@ -1124,13 +1187,15 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } } else { // fieldType == GPBFieldTypeMap if (field.mapKeyDataType == GPBDataTypeString) { - NSDictionary *map = GPBGetObjectIvarWithFieldNoAutocreate(self, field); + NSDictionary *map = + GPBGetObjectIvarWithFieldNoAutocreate(self, field); if (map && !GPBDictionaryIsInitializedInternalHelper(map, field)) { return NO; } } else { // Real type is GPB*ObjectDictionary, exact type doesn't matter. - GPBInt32ObjectDictionary *map = GPBGetObjectIvarWithFieldNoAutocreate(self, field); + GPBInt32ObjectDictionary *map = + GPBGetObjectIvarWithFieldNoAutocreate(self, field); if (map && ![map isInitialized]) { return NO; } @@ -1141,7 +1206,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { __block BOOL result = YES; [extensionMap_ - enumerateKeysAndObjectsUsingBlock:^(GPBExtensionDescriptor *extension, id obj, BOOL *stop) { + enumerateKeysAndObjectsUsingBlock:^(GPBExtensionDescriptor *extension, + id obj, + BOOL *stop) { if (GPBExtensionIsMessage(extension)) { if (extension.isRepeated) { for (GPBMessage *msg in obj) { @@ -1174,15 +1241,18 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } #endif NSMutableData *data = [NSMutableData dataWithLength:[self serializedSize]]; - GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithData:data]; + GPBCodedOutputStream *stream = + [[GPBCodedOutputStream alloc] initWithData:data]; @try { [self writeToCodedOutputStream:stream]; - } @catch (NSException *exception) { + } + @catch (NSException *exception) { // This really shouldn't happen. The only way writeToCodedOutputStream: // could throw is if something in the library has a bug and the // serializedSize was wrong. #ifdef DEBUG - NSLog(@"%@: Internal exception while building message data: %@", [self class], exception); + NSLog(@"%@: Internal exception while building message data: %@", + [self class], exception); #endif data = nil; } @@ -1193,17 +1263,20 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { - (NSData *)delimitedData { size_t serializedSize = [self serializedSize]; size_t varintSize = GPBComputeRawVarint32SizeForInteger(serializedSize); - NSMutableData *data = [NSMutableData dataWithLength:(serializedSize + varintSize)]; - GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithData:data]; + NSMutableData *data = + [NSMutableData dataWithLength:(serializedSize + varintSize)]; + GPBCodedOutputStream *stream = + [[GPBCodedOutputStream alloc] initWithData:data]; @try { [self writeDelimitedToCodedOutputStream:stream]; - } @catch (NSException *exception) { + } + @catch (NSException *exception) { // This really shouldn't happen. The only way writeToCodedOutputStream: // could throw is if something in the library has a bug and the // serializedSize was wrong. #ifdef DEBUG - NSLog(@"%@: Internal exception while building message delimitedData: %@", [self class], - exception); + NSLog(@"%@: Internal exception while building message delimitedData: %@", + [self class], exception); #endif // If it happens, truncate. data.length = 0; @@ -1213,7 +1286,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (void)writeToOutputStream:(NSOutputStream *)output { - GPBCodedOutputStream *stream = [[GPBCodedOutputStream alloc] initWithOutputStream:output]; + GPBCodedOutputStream *stream = + [[GPBCodedOutputStream alloc] initWithOutputStream:output]; [self writeToCodedOutputStream:stream]; [stream release]; } @@ -1248,7 +1322,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (void)writeDelimitedToOutputStream:(NSOutputStream *)output { - GPBCodedOutputStream *codedOutput = [[GPBCodedOutputStream alloc] initWithOutputStream:output]; + GPBCodedOutputStream *codedOutput = + [[GPBCodedOutputStream alloc] initWithOutputStream:output]; [self writeDelimitedToCodedOutputStream:codedOutput]; [codedOutput release]; } @@ -1258,7 +1333,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { [self writeToCodedOutputStream:output]; } -- (void)writeField:(GPBFieldDescriptor *)field toCodedOutputStream:(GPBCodedOutputStream *)output { +- (void)writeField:(GPBFieldDescriptor *)field + toCodedOutputStream:(GPBCodedOutputStream *)output { GPBFieldType fieldType = field.fieldType; if (fieldType == GPBFieldTypeSingle) { BOOL has = GPBGetHasIvarField(self, field); @@ -1268,9 +1344,6 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } uint32_t fieldNumber = GPBFieldNumber(field); - switch (GPBGetFieldDataType(field)) { - // clang-format off - //%PDDM-DEFINE FIELD_CASE(TYPE, REAL_TYPE) //%FIELD_CASE_FULL(TYPE, REAL_TYPE, REAL_TYPE) //%PDDM-DEFINE FIELD_CASE_FULL(TYPE, REAL_TYPE, ARRAY_TYPE) @@ -1313,8 +1386,12 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { //% } //% break; //% + + switch (GPBGetFieldDataType(field)) { + //%PDDM-EXPAND FIELD_CASE(Bool, Bool) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeBool: if (fieldType == GPBFieldTypeRepeated) { @@ -1333,8 +1410,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Fixed32, UInt32) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeFixed32: if (fieldType == GPBFieldTypeRepeated) { @@ -1353,8 +1432,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(SFixed32, Int32) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeSFixed32: if (fieldType == GPBFieldTypeRepeated) { @@ -1373,8 +1454,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Float, Float) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeFloat: if (fieldType == GPBFieldTypeRepeated) { @@ -1393,8 +1476,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Fixed64, UInt64) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeFixed64: if (fieldType == GPBFieldTypeRepeated) { @@ -1413,8 +1498,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(SFixed64, Int64) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeSFixed64: if (fieldType == GPBFieldTypeRepeated) { @@ -1433,8 +1520,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Double, Double) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeDouble: if (fieldType == GPBFieldTypeRepeated) { @@ -1453,8 +1542,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Int32, Int32) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeInt32: if (fieldType == GPBFieldTypeRepeated) { @@ -1473,8 +1564,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(Int64, Int64) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeInt64: if (fieldType == GPBFieldTypeRepeated) { @@ -1493,8 +1586,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(SInt32, Int32) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeSInt32: if (fieldType == GPBFieldTypeRepeated) { @@ -1513,8 +1608,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(SInt64, Int64) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeSInt64: if (fieldType == GPBFieldTypeRepeated) { @@ -1533,8 +1630,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(UInt32, UInt32) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeUInt32: if (fieldType == GPBFieldTypeRepeated) { @@ -1553,8 +1652,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE(UInt64, UInt64) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeUInt64: if (fieldType == GPBFieldTypeRepeated) { @@ -1573,8 +1674,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE_FULL(Enum, Int32, Enum) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeEnum: if (fieldType == GPBFieldTypeRepeated) { @@ -1593,8 +1696,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE2(Bytes) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeBytes: if (fieldType == GPBFieldTypeRepeated) { @@ -1617,8 +1722,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE2(String) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeString: if (fieldType == GPBFieldTypeRepeated) { @@ -1641,8 +1748,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE2(Message) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeMessage: if (fieldType == GPBFieldTypeRepeated) { @@ -1665,8 +1774,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND FIELD_CASE2(Group) // This block of code is generated, do not edit it directly. +// clang-format off case GPBDataTypeGroup: if (fieldType == GPBFieldTypeRepeated) { @@ -1689,9 +1800,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } break; +// clang-format on //%PDDM-EXPAND-END (18 expansions) - -// clang-format off } } @@ -1714,7 +1824,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } // Check for an autocreated value. - os_unfair_lock_lock(&readOnlyLock_); + GPBPrepareReadOnlySemaphore(self); + dispatch_semaphore_wait(readOnlySemaphore_, DISPATCH_TIME_FOREVER); value = [autocreatedExtensionMap_ objectForKey:extension]; if (!value) { // Auto create the message extensions to match normal fields. @@ -1731,7 +1842,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { [value release]; } - os_unfair_lock_unlock(&readOnlyLock_); + dispatch_semaphore_signal(readOnlySemaphore_); return value; } @@ -1862,7 +1973,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { #pragma mark - mergeFrom - (void)mergeFromData:(NSData *)data - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data]; [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; [input checkLastTagWas:0]; @@ -1872,7 +1983,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { #pragma mark - mergeDelimitedFrom - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { GPBCodedInputStreamState *state = &input->state_; if (GPBCodedInputStreamIsAtEnd(state)) { return; @@ -1892,7 +2003,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } + (instancetype)parseFromData:(NSData *)data - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr { return [[[self alloc] initWithData:data extensionRegistry:extensionRegistry @@ -1900,7 +2011,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } + (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr { return [[[self alloc] initWithCodedInputStream:input @@ -1912,7 +2023,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { + (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input extensionRegistry: - (id)extensionRegistry + (GPBExtensionRegistry *)extensionRegistry error:(NSError **)errorPtr { GPBMessage *message = [[[self alloc] init] autorelease]; @try { @@ -1954,7 +2065,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (void)parseMessageSet:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { uint32_t typeId = 0; NSData *rawBytes = nil; GPBExtensionDescriptor *extension = nil; @@ -2006,7 +2117,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { } - (BOOL)parseUnknownField:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry tag:(uint32_t)tag { GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag); int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag); @@ -2059,7 +2170,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { static void MergeSingleFieldFromCodedInputStream( GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, - GPBCodedInputStream *input, idextensionRegistry) { + GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { GPBDataType fieldDataType = GPBGetFieldDataType(field); switch (fieldDataType) { #define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \ @@ -2195,7 +2306,7 @@ static void MergeRepeatedPackedFieldFromCodedInputStream( static void MergeRepeatedNotPackedFieldFromCodedInputStream( GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax, - GPBCodedInputStream *input, idextensionRegistry) { + GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) { GPBCodedInputStreamState *state = &input->state_; id genericArray = GetOrCreateArrayIvarWithField(self, field); switch (GPBGetFieldDataType(field)) { @@ -2260,7 +2371,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( } - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry { + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { GPBDescriptor *descriptor = [self descriptor]; GPBFileSyntax syntax = descriptor.file.syntax; GPBCodedInputStreamState *state = &input->state_; @@ -2880,7 +2991,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( #define CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ARRAY_ACCESSOR_NAME) \ case GPBDataType##NAME: { \ GPB##ARRAY_TYPE##Array *array = genericArray; \ - [array enumerate##ARRAY_ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { \ + [array enumerate##ARRAY_ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { \ + _Pragma("unused(idx, stop)"); \ dataSize += GPBCompute##NAME##SizeNoTag(value); \ }]; \ break; \ diff --git a/libs/protobuf/objectivec/GPBMessage_PackagePrivate.h b/libs/protobuf/objectivec/GPBMessage_PackagePrivate.h index 70b47a5..ca10983 100644 --- a/libs/protobuf/objectivec/GPBMessage_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBMessage_PackagePrivate.h @@ -78,12 +78,13 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; // or zero for EOF. // NOTE: This will throw if there is an error while parsing. - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry; + extensionRegistry:(GPBExtensionRegistry *)extensionRegistry; // Parses the next delimited message of this type from the input and merges it // with this message. - (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input - extensionRegistry:(id)extensionRegistry; + extensionRegistry: + (GPBExtensionRegistry *)extensionRegistry; - (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data; @@ -91,12 +92,14 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr; CF_EXTERN_C_BEGIN + // Call this before using the readOnlySemaphore_. This ensures it is created only once. void GPBPrepareReadOnlySemaphore(GPBMessage *self); // Returns a new instance that was automatically created by |autocreator| for // its field |field|. -GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, GPBMessage *autocreator, +GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass, + GPBMessage *autocreator, GPBFieldDescriptor *field) __attribute__((ns_returns_retained)); diff --git a/libs/protobuf/objectivec/GPBProtocolBuffers.h b/libs/protobuf/objectivec/GPBProtocolBuffers.h index e5f4713..619c082 100644 --- a/libs/protobuf/objectivec/GPBProtocolBuffers.h +++ b/libs/protobuf/objectivec/GPBProtocolBuffers.h @@ -28,9 +28,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// clang-format off #import "GPBBootstrap.h" -// clang-format on #import "GPBArray.h" #import "GPBCodedInputStream.h" diff --git a/libs/protobuf/objectivec/GPBProtocolBuffers.m b/libs/protobuf/objectivec/GPBProtocolBuffers.m index c2833c5..0545ae9 100644 --- a/libs/protobuf/objectivec/GPBProtocolBuffers.m +++ b/libs/protobuf/objectivec/GPBProtocolBuffers.m @@ -31,6 +31,7 @@ // If you want to build protocol buffers in your own project without adding the // project dependency, you can just add this file. + // This warning seems to treat code differently when it is #imported than when // it is inline in the file. GPBDictionary.m compiles cleanly in other targets, // but when #imported here it triggers a bunch of warnings that don't make diff --git a/libs/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h b/libs/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h index 804a68a..04dde62 100644 --- a/libs/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h +++ b/libs/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h @@ -31,9 +31,7 @@ // This header is meant to only be used by the generated source, it should not // be included in code using protocol buffers. -// clang-format off #import "GPBBootstrap.h" -// clang-format on #import "GPBDescriptor_PackagePrivate.h" #import "GPBExtensionInternals.h" diff --git a/libs/protobuf/objectivec/GPBRootObject.m b/libs/protobuf/objectivec/GPBRootObject.m index b546959..bad2f9a 100644 --- a/libs/protobuf/objectivec/GPBRootObject.m +++ b/libs/protobuf/objectivec/GPBRootObject.m @@ -31,7 +31,6 @@ #import "GPBRootObject_PackagePrivate.h" #import -#import #import @@ -74,19 +73,26 @@ static uint32_t jenkins_one_at_a_time_hash(const char *key) { // to worry about deallocation. All of the items are added to it at // startup, and so the keys don't need to be retained/released. // Keys are NULL terminated char *. -static const void *GPBRootExtensionKeyRetain(__unused CFAllocatorRef allocator, const void *value) { +static const void *GPBRootExtensionKeyRetain(CFAllocatorRef allocator, + const void *value) { +#pragma unused(allocator) return value; } -static void GPBRootExtensionKeyRelease(__unused CFAllocatorRef allocator, - __unused const void *value) {} +static void GPBRootExtensionKeyRelease(CFAllocatorRef allocator, + const void *value) { +#pragma unused(allocator) +#pragma unused(value) +} static CFStringRef GPBRootExtensionCopyKeyDescription(const void *value) { const char *key = (const char *)value; - return CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); + return CFStringCreateWithCString(kCFAllocatorDefault, key, + kCFStringEncodingUTF8); } -static Boolean GPBRootExtensionKeyEqual(const void *value1, const void *value2) { +static Boolean GPBRootExtensionKeyEqual(const void *value1, + const void *value2) { const char *key1 = (const char *)value1; const char *key2 = (const char *)value2; return strcmp(key1, key2) == 0; @@ -97,34 +103,31 @@ static CFHashCode GPBRootExtensionKeyHash(const void *value) { return jenkins_one_at_a_time_hash(key); } -// Long ago, this was an OSSpinLock, but then it came to light that there were issues for that on -// iOS: +// NOTE: OSSpinLock may seem like a good fit here but Apple engineers have +// pointed out that they are vulnerable to live locking on iOS in cases of +// priority inversion: // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html -// It was changed to a dispatch_semaphore_t, but that has potential for priority inversion issues. -// The minOS versions are now high enough that os_unfair_lock can be used, and should provide -// all the support we need. For more information in the concurrency/locking space see: -// https://gist.github.com/tclementdev/6af616354912b0347cdf6db159c37057 -// https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html -// https://developer.apple.com/videos/play/wwdc2017/706/ -static os_unfair_lock gExtensionSingletonDictionaryLock = OS_UNFAIR_LOCK_INIT; +static dispatch_semaphore_t gExtensionSingletonDictionarySemaphore; static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL; static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL; + (void)initialize { // Ensure the global is started up. if (!gExtensionSingletonDictionary) { + gExtensionSingletonDictionarySemaphore = dispatch_semaphore_create(1); CFDictionaryKeyCallBacks keyCallBacks = { - // See description above for reason for using custom dictionary. - 0, - GPBRootExtensionKeyRetain, - GPBRootExtensionKeyRelease, - GPBRootExtensionCopyKeyDescription, - GPBRootExtensionKeyEqual, - GPBRootExtensionKeyHash, + // See description above for reason for using custom dictionary. + 0, + GPBRootExtensionKeyRetain, + GPBRootExtensionKeyRelease, + GPBRootExtensionCopyKeyDescription, + GPBRootExtensionKeyEqual, + GPBRootExtensionKeyHash, }; - gExtensionSingletonDictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &keyCallBacks, - &kCFTypeDictionaryValueCallBacks); + gExtensionSingletonDictionary = + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &keyCallBacks, + &kCFTypeDictionaryValueCallBacks); gDefaultExtensionRegistry = [[GPBExtensionRegistry alloc] init]; } @@ -144,9 +147,10 @@ static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL; + (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field { const char *key = [field singletonNameC]; - os_unfair_lock_lock(&gExtensionSingletonDictionaryLock); + dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore, + DISPATCH_TIME_FOREVER); CFDictionarySetValue(gExtensionSingletonDictionary, key, field); - os_unfair_lock_unlock(&gExtensionSingletonDictionaryLock); + dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore); } static id ExtensionForName(id self, SEL _cmd) { @@ -178,20 +182,21 @@ static id ExtensionForName(id self, SEL _cmd) { key[classNameLen + 1 + selNameLen] = '\0'; // NOTE: Even though this method is called from another C function, - // gExtensionSingletonDictionaryLock and gExtensionSingletonDictionary + // gExtensionSingletonDictionarySemaphore and gExtensionSingletonDictionary // will always be initialized. This is because this call flow is just to // lookup the Extension, meaning the code is calling an Extension class // message on a Message or Root class. This guarantees that the class was // initialized and Message classes ensure their Root was also initialized. NSAssert(gExtensionSingletonDictionary, @"Startup order broken!"); - os_unfair_lock_lock(&gExtensionSingletonDictionaryLock); + dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore, + DISPATCH_TIME_FOREVER); id extension = (id)CFDictionaryGetValue(gExtensionSingletonDictionary, key); // We can't remove the key from the dictionary here (as an optimization), // two threads could have gone into +resolveClassMethod: for the same method, // and ended up here; there's no way to ensure both return YES without letting // both try to wire in the method. - os_unfair_lock_unlock(&gExtensionSingletonDictionaryLock); + dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore); return extension; } @@ -207,9 +212,11 @@ BOOL GPBResolveExtensionClassMethod(Class self, SEL sel) { // file. id extension = ExtensionForName(self, sel); if (extension != nil) { - const char *encoding = GPBMessageEncodingForSelector(@selector(getClassValue), NO); + const char *encoding = + GPBMessageEncodingForSelector(@selector(getClassValue), NO); Class metaClass = objc_getMetaClass(class_getName(self)); - IMP imp = imp_implementationWithBlock(^(__unused id obj) { + IMP imp = imp_implementationWithBlock(^(id obj) { +#pragma unused(obj) return extension; }); BOOL methodAdded = class_addMethod(metaClass, sel, imp, encoding); @@ -227,6 +234,7 @@ BOOL GPBResolveExtensionClassMethod(Class self, SEL sel) { return NO; } + + (BOOL)resolveClassMethod:(SEL)sel { if (GPBResolveExtensionClassMethod(self, sel)) { return YES; diff --git a/libs/protobuf/objectivec/GPBSourceContext.pbobjc.h b/libs/protobuf/objectivec/GPBSourceContext.pbobjc.h index 8433882..b17fec0 100644 --- a/libs/protobuf/objectivec/GPBSourceContext.pbobjc.h +++ b/libs/protobuf/objectivec/GPBSourceContext.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/source_context.proto #import "GPBDescriptor.h" @@ -64,5 +63,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBSourceContext.pbobjc.m b/libs/protobuf/objectivec/GPBSourceContext.pbobjc.m index 7f035e7..376d442 100644 --- a/libs/protobuf/objectivec/GPBSourceContext.pbobjc.m +++ b/libs/protobuf/objectivec/GPBSourceContext.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/source_context.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -83,5 +82,3 @@ typedef struct GPBSourceContext__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBStruct.pbobjc.h b/libs/protobuf/objectivec/GPBStruct.pbobjc.h index 4035f51..dd6ab28 100644 --- a/libs/protobuf/objectivec/GPBStruct.pbobjc.h +++ b/libs/protobuf/objectivec/GPBStruct.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/struct.proto #import "GPBDescriptor.h" @@ -88,7 +87,7 @@ GPB_FINAL @interface GPBStruct : GPBMessage /** Unordered map of dynamically typed values. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary *fields; -/** The number of items in @c fields without causing the container to be created. */ +/** The number of items in @c fields without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger fields_Count; @end @@ -179,7 +178,7 @@ GPB_FINAL @interface GPBListValue : GPBMessage /** Repeated field of dynamically typed values. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *valuesArray; -/** The number of items in @c valuesArray without causing the container to be created. */ +/** The number of items in @c valuesArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger valuesArray_Count; @end @@ -191,5 +190,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBStruct.pbobjc.m b/libs/protobuf/objectivec/GPBStruct.pbobjc.m index b6ee9c1..726cfb8 100644 --- a/libs/protobuf/objectivec/GPBStruct.pbobjc.m +++ b/libs/protobuf/objectivec/GPBStruct.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/struct.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -296,5 +295,3 @@ typedef struct GPBListValue__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBTimestamp.pbobjc.h b/libs/protobuf/objectivec/GPBTimestamp.pbobjc.h index ebed8c8..8203383 100644 --- a/libs/protobuf/objectivec/GPBTimestamp.pbobjc.h +++ b/libs/protobuf/objectivec/GPBTimestamp.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/timestamp.proto #import "GPBDescriptor.h" @@ -95,6 +94,7 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) * .setNanos((int) ((millis % 1000) * 1000000)).build(); * + * * Example 5: Compute Timestamp from Java `Instant.now()`. * * Instant now = Instant.now(); @@ -103,6 +103,7 @@ typedef GPB_ENUM(GPBTimestamp_FieldNumber) { * Timestamp.newBuilder().setSeconds(now.getEpochSecond()) * .setNanos(now.getNano()).build(); * + * * Example 6: Compute Timestamp from current time in Python. * * timestamp = Timestamp() @@ -161,5 +162,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBTimestamp.pbobjc.m b/libs/protobuf/objectivec/GPBTimestamp.pbobjc.m index 7d2276c..72d348f 100644 --- a/libs/protobuf/objectivec/GPBTimestamp.pbobjc.m +++ b/libs/protobuf/objectivec/GPBTimestamp.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/timestamp.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -94,5 +93,3 @@ typedef struct GPBTimestamp__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBType.pbobjc.h b/libs/protobuf/objectivec/GPBType.pbobjc.h index b102ab4..b023050 100644 --- a/libs/protobuf/objectivec/GPBType.pbobjc.h +++ b/libs/protobuf/objectivec/GPBType.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/type.proto #import "GPBDescriptor.h" @@ -196,17 +195,17 @@ GPB_FINAL @interface GPBType : GPBMessage /** The list of fields. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *fieldsArray; -/** The number of items in @c fieldsArray without causing the container to be created. */ +/** The number of items in @c fieldsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger fieldsArray_Count; /** The list of types appearing in `oneof` definitions in this type. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *oneofsArray; -/** The number of items in @c oneofsArray without causing the container to be created. */ +/** The number of items in @c oneofsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger oneofsArray_Count; /** The protocol buffer options. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; /** The source context. */ @@ -280,7 +279,7 @@ GPB_FINAL @interface GPBField : GPBMessage /** The protocol buffer options. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; /** The field JSON name. */ @@ -335,12 +334,12 @@ GPB_FINAL @interface GPBEnum : GPBMessage /** Enum value definitions. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *enumvalueArray; -/** The number of items in @c enumvalueArray without causing the container to be created. */ +/** The number of items in @c enumvalueArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger enumvalueArray_Count; /** Protocol buffer options. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; /** The source context. */ @@ -386,7 +385,7 @@ GPB_FINAL @interface GPBEnumValue : GPBMessage /** Protocol buffer options. */ @property(nonatomic, readwrite, strong, null_resettable) NSMutableArray *optionsArray; -/** The number of items in @c optionsArray without causing the container to be created. */ +/** The number of items in @c optionsArray without causing the array to be created. */ @property(nonatomic, readonly) NSUInteger optionsArray_Count; @end @@ -431,5 +430,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBType.pbobjc.m b/libs/protobuf/objectivec/GPBType.pbobjc.m index 60f7c08..f5fc1ef 100644 --- a/libs/protobuf/objectivec/GPBType.pbobjc.m +++ b/libs/protobuf/objectivec/GPBType.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/type.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -708,5 +707,3 @@ typedef struct GPBOption__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBUnknownField.h b/libs/protobuf/objectivec/GPBUnknownField.h index a188990..5b96023 100644 --- a/libs/protobuf/objectivec/GPBUnknownField.h +++ b/libs/protobuf/objectivec/GPBUnknownField.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN * Store an unknown field. These are used in conjunction with * GPBUnknownFieldSet. **/ -@interface GPBUnknownField : NSObject +@interface GPBUnknownField : NSObject /** Initialize a field with the given number. */ - (instancetype)initWithNumber:(int32_t)number; @@ -58,10 +58,10 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List; /** An array of data values for this field. */ -@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList; +@property(nonatomic, readonly, strong) NSArray *lengthDelimitedList; /** An array of groups of values for this field. */ -@property(nonatomic, readonly, strong) NSArray *groupList; +@property(nonatomic, readonly, strong) NSArray *groupList; /** * Add a value to the varintList. diff --git a/libs/protobuf/objectivec/GPBUnknownField.m b/libs/protobuf/objectivec/GPBUnknownField.m index 62cfb22..7fa8cad 100644 --- a/libs/protobuf/objectivec/GPBUnknownField.m +++ b/libs/protobuf/objectivec/GPBUnknownField.m @@ -40,8 +40,8 @@ GPBUInt64Array *mutableVarintList_; GPBUInt32Array *mutableFixed32List_; GPBUInt64Array *mutableFixed64List_; - NSMutableArray *mutableLengthDelimitedList_; - NSMutableArray *mutableGroupList_; + NSMutableArray *mutableLengthDelimitedList_; + NSMutableArray *mutableGroupList_; } @synthesize number = number_; @@ -75,14 +75,16 @@ #pragma clang diagnostic ignored "-Wdirect-ivar-access" - (id)copyWithZone:(NSZone *)zone { - GPBUnknownField *result = [[GPBUnknownField allocWithZone:zone] initWithNumber:number_]; + GPBUnknownField *result = + [[GPBUnknownField allocWithZone:zone] initWithNumber:number_]; result->mutableFixed32List_ = [mutableFixed32List_ copyWithZone:zone]; result->mutableFixed64List_ = [mutableFixed64List_ copyWithZone:zone]; - result->mutableLengthDelimitedList_ = [mutableLengthDelimitedList_ mutableCopyWithZone:zone]; + result->mutableLengthDelimitedList_ = + [mutableLengthDelimitedList_ mutableCopyWithZone:zone]; result->mutableVarintList_ = [mutableVarintList_ copyWithZone:zone]; if (mutableGroupList_.count) { - result->mutableGroupList_ = - [[NSMutableArray allocWithZone:zone] initWithCapacity:mutableGroupList_.count]; + result->mutableGroupList_ = [[NSMutableArray allocWithZone:zone] + initWithCapacity:mutableGroupList_.count]; for (GPBUnknownFieldSet *group in mutableGroupList_) { GPBUnknownFieldSet *copied = [group copyWithZone:zone]; [result->mutableGroupList_ addObject:copied]; @@ -97,21 +99,26 @@ if (![object isKindOfClass:[GPBUnknownField class]]) return NO; GPBUnknownField *field = (GPBUnknownField *)object; if (number_ != field->number_) return NO; - BOOL equalVarint = (mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) || - [mutableVarintList_ isEqual:field->mutableVarintList_]; + BOOL equalVarint = + (mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) || + [mutableVarintList_ isEqual:field->mutableVarintList_]; if (!equalVarint) return NO; - BOOL equalFixed32 = (mutableFixed32List_.count == 0 && field->mutableFixed32List_.count == 0) || + BOOL equalFixed32 = (mutableFixed32List_.count == 0 && + field->mutableFixed32List_.count == 0) || [mutableFixed32List_ isEqual:field->mutableFixed32List_]; if (!equalFixed32) return NO; - BOOL equalFixed64 = (mutableFixed64List_.count == 0 && field->mutableFixed64List_.count == 0) || + BOOL equalFixed64 = (mutableFixed64List_.count == 0 && + field->mutableFixed64List_.count == 0) || [mutableFixed64List_ isEqual:field->mutableFixed64List_]; if (!equalFixed64) return NO; BOOL equalLDList = - (mutableLengthDelimitedList_.count == 0 && field->mutableLengthDelimitedList_.count == 0) || + (mutableLengthDelimitedList_.count == 0 && + field->mutableLengthDelimitedList_.count == 0) || [mutableLengthDelimitedList_ isEqual:field->mutableLengthDelimitedList_]; if (!equalLDList) return NO; - BOOL equalGroupList = (mutableGroupList_.count == 0 && field->mutableGroupList_.count == 0) || - [mutableGroupList_ isEqual:field->mutableGroupList_]; + BOOL equalGroupList = + (mutableGroupList_.count == 0 && field->mutableGroupList_.count == 0) || + [mutableGroupList_ isEqual:field->mutableGroupList_]; if (!equalGroupList) return NO; return YES; } @@ -154,17 +161,20 @@ __block size_t result = 0; int32_t number = number_; [mutableVarintList_ - enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) result += GPBComputeUInt64Size(number, value); }]; [mutableFixed32List_ - enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) result += GPBComputeFixed32Size(number, value); }]; [mutableFixed64List_ - enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) result += GPBComputeFixed64Size(number, value); }]; @@ -195,19 +205,23 @@ - (NSString *)description { NSMutableString *description = - [NSMutableString stringWithFormat:@"<%@ %p>: Field: %d {\n", [self class], self, number_]; + [NSMutableString stringWithFormat:@"<%@ %p>: Field: %d {\n", + [self class], self, number_]; [mutableVarintList_ - enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [description appendFormat:@"\t%llu\n", value]; }]; [mutableFixed32List_ - enumerateValuesWithBlock:^(uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [description appendFormat:@"\t%u\n", value]; }]; [mutableFixed64List_ - enumerateValuesWithBlock:^(uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { +#pragma unused(idx, stop) [description appendFormat:@"\t%llu\n", value]; }]; @@ -255,14 +269,16 @@ if (mutableLengthDelimitedList_ == nil) { mutableLengthDelimitedList_ = [otherLengthDelimitedList mutableCopy]; } else { - [mutableLengthDelimitedList_ addObjectsFromArray:otherLengthDelimitedList]; + [mutableLengthDelimitedList_ + addObjectsFromArray:otherLengthDelimitedList]; } } NSArray *otherGroupList = other.groupList; if (otherGroupList.count > 0) { if (mutableGroupList_ == nil) { - mutableGroupList_ = [[NSMutableArray alloc] initWithCapacity:otherGroupList.count]; + mutableGroupList_ = + [[NSMutableArray alloc] initWithCapacity:otherGroupList.count]; } // Make our own mutable copies. for (GPBUnknownFieldSet *group in otherGroupList) { @@ -283,7 +299,8 @@ - (void)addFixed32:(uint32_t)value { if (mutableFixed32List_ == nil) { - mutableFixed32List_ = [[GPBUInt32Array alloc] initWithValues:&value count:1]; + mutableFixed32List_ = + [[GPBUInt32Array alloc] initWithValues:&value count:1]; } else { [mutableFixed32List_ addValue:value]; } @@ -291,7 +308,8 @@ - (void)addFixed64:(uint64_t)value { if (mutableFixed64List_ == nil) { - mutableFixed64List_ = [[GPBUInt64Array alloc] initWithValues:&value count:1]; + mutableFixed64List_ = + [[GPBUInt64Array alloc] initWithValues:&value count:1]; } else { [mutableFixed64List_ addValue:value]; } @@ -299,7 +317,8 @@ - (void)addLengthDelimited:(NSData *)value { if (mutableLengthDelimitedList_ == nil) { - mutableLengthDelimitedList_ = [[NSMutableArray alloc] initWithObjects:&value count:1]; + mutableLengthDelimitedList_ = + [[NSMutableArray alloc] initWithObjects:&value count:1]; } else { [mutableLengthDelimitedList_ addObject:value]; } diff --git a/libs/protobuf/objectivec/GPBUnknownFieldSet.h b/libs/protobuf/objectivec/GPBUnknownFieldSet.h index aed5b52..1b5f24f 100644 --- a/libs/protobuf/objectivec/GPBUnknownFieldSet.h +++ b/libs/protobuf/objectivec/GPBUnknownFieldSet.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN * applies for files declared with the "proto2" syntax. Files declared with the * "proto3" syntax discard the unknown values. **/ -@interface GPBUnknownFieldSet : NSObject +@interface GPBUnknownFieldSet : NSObject /** * Tests to see if the given field number has a value. diff --git a/libs/protobuf/objectivec/GPBUnknownFieldSet.m b/libs/protobuf/objectivec/GPBUnknownFieldSet.m index dcd4b44..a7335f0 100644 --- a/libs/protobuf/objectivec/GPBUnknownFieldSet.m +++ b/libs/protobuf/objectivec/GPBUnknownFieldSet.m @@ -40,7 +40,8 @@ static void checkNumber(int32_t number) { if (number == 0) { - [NSException raise:NSInvalidArgumentException format:@"Zero is not a valid field number."]; + [NSException raise:NSInvalidArgumentException + format:@"Zero is not a valid field number."]; } } @@ -49,7 +50,8 @@ static void checkNumber(int32_t number) { CFMutableDictionaryRef fields_; } -static void CopyWorker(__unused const void *key, const void *value, void *context) { +static void CopyWorker(const void *key, const void *value, void *context) { +#pragma unused(key) GPBUnknownField *field = value; GPBUnknownFieldSet *result = context; @@ -109,7 +111,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex - (GPBUnknownField *)getField:(int32_t)number { ssize_t key = number; - GPBUnknownField *result = fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil; + GPBUnknownField *result = + fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil; return result; } @@ -122,7 +125,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex size_t count = CFDictionaryGetCount(fields_); ssize_t keys[count]; GPBUnknownField *values[count]; - CFDictionaryGetKeysAndValues(fields_, (const void **)keys, (const void **)values); + CFDictionaryGetKeysAndValues(fields_, (const void **)keys, + (const void **)values); struct GPBFieldPair { ssize_t key; GPBUnknownField *value; @@ -131,11 +135,12 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex pairs[i].key = keys[i]; pairs[i].value = values[i]; }; - qsort_b(pairs, count, sizeof(struct GPBFieldPair), ^(const void *first, const void *second) { - const struct GPBFieldPair *a = first; - const struct GPBFieldPair *b = second; - return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1); - }); + qsort_b(pairs, count, sizeof(struct GPBFieldPair), + ^(const void *first, const void *second) { + const struct GPBFieldPair *a = first; + const struct GPBFieldPair *b = second; + return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1); + }); for (size_t i = 0; i < count; ++i) { values[i] = pairs[i].value; }; @@ -149,7 +154,8 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex size_t count = CFDictionaryGetCount(fields_); ssize_t keys[count]; GPBUnknownField *values[count]; - CFDictionaryGetKeysAndValues(fields_, (const void **)keys, (const void **)values); + CFDictionaryGetKeysAndValues(fields_, (const void **)keys, + (const void **)values); if (count > 1) { struct GPBFieldPair { ssize_t key; @@ -160,11 +166,12 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex pairs[i].key = keys[i]; pairs[i].value = values[i]; }; - qsort_b(pairs, count, sizeof(struct GPBFieldPair), ^(const void *first, const void *second) { - const struct GPBFieldPair *a = first; - const struct GPBFieldPair *b = second; - return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1); - }); + qsort_b(pairs, count, sizeof(struct GPBFieldPair), + ^(const void *first, const void *second) { + const struct GPBFieldPair *a = first; + const struct GPBFieldPair *b = second; + return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1); + }); for (size_t i = 0; i < count; ++i) { GPBUnknownField *value = pairs[i].value; [value writeToOutput:output]; @@ -175,16 +182,17 @@ static void CopyWorker(__unused const void *key, const void *value, void *contex } - (NSString *)description { - NSMutableString *description = - [NSMutableString stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self]; + NSMutableString *description = [NSMutableString + stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self]; NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" "); [description appendString:textFormat]; [description appendString:@"}"]; return description; } -static void GPBUnknownFieldSetSerializedSize(__unused const void *key, const void *value, +static void GPBUnknownFieldSetSerializedSize(const void *key, const void *value, void *context) { +#pragma unused(key) GPBUnknownField *field = value; size_t *result = context; *result += [field serializedSize]; @@ -193,13 +201,16 @@ static void GPBUnknownFieldSetSerializedSize(__unused const void *key, const voi - (size_t)serializedSize { size_t result = 0; if (fields_) { - CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize, &result); + CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize, + &result); } return result; } -static void GPBUnknownFieldSetWriteAsMessageSetTo(__unused const void *key, const void *value, +static void GPBUnknownFieldSetWriteAsMessageSetTo(const void *key, + const void *value, void *context) { +#pragma unused(key) GPBUnknownField *field = value; GPBCodedOutputStream *output = context; [field writeAsMessageSetExtensionToOutput:output]; @@ -207,12 +218,15 @@ static void GPBUnknownFieldSetWriteAsMessageSetTo(__unused const void *key, cons - (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output { if (fields_) { - CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo, output); + CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo, + output); } } -static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *key, - const void *value, void *context) { +static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key, + const void *value, + void *context) { +#pragma unused(key) GPBUnknownField *field = value; size_t *result = context; *result += [field serializedSizeAsMessageSetExtension]; @@ -221,14 +235,16 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke - (size_t)serializedSizeAsMessageSet { size_t result = 0; if (fields_) { - CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result); + CFDictionaryApplyFunction( + fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result); } return result; } - (NSData *)data { NSMutableData *data = [NSMutableData dataWithLength:self.serializedSize]; - GPBCodedOutputStream *output = [[GPBCodedOutputStream alloc] initWithData:data]; + GPBCodedOutputStream *output = + [[GPBCodedOutputStream alloc] initWithData:data]; [self writeToCodedOutputStream:output]; [output release]; return data; @@ -244,8 +260,8 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke if (!fields_) { // Use a custom dictionary here because the keys are numbers and conversion // back and forth from NSNumber isn't worth the cost. - fields_ = - CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks); + fields_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, + &kCFTypeDictionaryValueCallBacks); } ssize_t key = number; CFDictionarySetValue(fields_, (const void *)key, field); @@ -253,7 +269,8 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke - (GPBUnknownField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create { ssize_t key = number; - GPBUnknownField *existing = fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil; + GPBUnknownField *existing = + fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil; if (!existing && create) { existing = [[GPBUnknownField alloc] initWithNumber:number]; // This retains existing. @@ -263,8 +280,10 @@ static void GPBUnknownFieldSetSerializedSizeAsMessageSet(__unused const void *ke return existing; } -static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const void *value, +static void GPBUnknownFieldSetMergeUnknownFields(const void *key, + const void *value, void *context) { +#pragma unused(key) GPBUnknownField *field = value; GPBUnknownFieldSet *self = context; @@ -285,7 +304,8 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const - (void)mergeUnknownFields:(GPBUnknownFieldSet *)other { if (other && other->fields_) { - CFDictionaryApplyFunction(other->fields_, GPBUnknownFieldSetMergeUnknownFields, self); + CFDictionaryApplyFunction(other->fields_, + GPBUnknownFieldSetMergeUnknownFields, self); } } @@ -342,7 +362,8 @@ static void GPBUnknownFieldSetMergeUnknownFields(__unused const void *key, const } - (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData { - [[self mutableFieldForNumber:number create:YES] addLengthDelimited:messageData]; + [[self mutableFieldForNumber:number create:YES] + addLengthDelimited:messageData]; } - (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data { diff --git a/libs/protobuf/objectivec/GPBUtilities.h b/libs/protobuf/objectivec/GPBUtilities.h index e49ada5..75759b2 100644 --- a/libs/protobuf/objectivec/GPBUtilities.h +++ b/libs/protobuf/objectivec/GPBUtilities.h @@ -50,7 +50,8 @@ NS_ASSUME_NONNULL_BEGIN * * @return An NSString with the TextFormat of the message. **/ -NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *__nullable lineIndent); +NSString *GPBTextFormatForMessage(GPBMessage *message, + NSString * __nullable lineIndent); /** * Generates a string that should be a valid "TextFormat" for the C++ version @@ -62,8 +63,8 @@ NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *__nullable line * * @return An NSString with the TextFormat of the unknown field set. **/ -NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *__nullable unknownSet, - NSString *__nullable lineIndent); +NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet, + NSString * __nullable lineIndent); /** * Checks if the given field number is set on a message. @@ -101,11 +102,9 @@ void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field); **/ void GPBClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof); -// Disable clang-format for the macros. -// clang-format off - //%PDDM-EXPAND GPB_ACCESSORS() // This block of code is generated, do not edit it directly. +// clang-format off // @@ -396,9 +395,8 @@ void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary); -//%PDDM-EXPAND-END GPB_ACCESSORS() - // clang-format on +//%PDDM-EXPAND-END GPB_ACCESSORS() /** * Returns an empty NSData to assign to byte fields when you wish to assign them @@ -415,8 +413,6 @@ NS_ASSUME_NONNULL_END CF_EXTERN_C_END -// Disable clang-format for the macros. -// clang-format off //%PDDM-DEFINE GPB_ACCESSORS() //% @@ -553,5 +549,3 @@ CF_EXTERN_C_END //% **/ //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value); //% - -// clang-format on diff --git a/libs/protobuf/objectivec/GPBUtilities.m b/libs/protobuf/objectivec/GPBUtilities.m index 5c8ee04..b72d0e2 100644 --- a/libs/protobuf/objectivec/GPBUtilities.m +++ b/libs/protobuf/objectivec/GPBUtilities.m @@ -45,24 +45,28 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdirect-ivar-access" -static void AppendTextFormatForMessage(GPBMessage *message, NSMutableString *toStr, +static void AppendTextFormatForMessage(GPBMessage *message, + NSMutableString *toStr, NSString *lineIndent); // Are two datatypes the same basic type representation (ex Int32 and SInt32). // Marked unused because currently only called from asserts/debug. -static BOOL DataTypesEquivalent(GPBDataType type1, GPBDataType type2) __attribute__((unused)); +static BOOL DataTypesEquivalent(GPBDataType type1, + GPBDataType type2) __attribute__ ((unused)); // Basic type representation for a type (ex: for SInt32 it is Int32). // Marked unused because currently only called from asserts/debug. -static GPBDataType BaseDataType(GPBDataType type) __attribute__((unused)); +static GPBDataType BaseDataType(GPBDataType type) __attribute__ ((unused)); // String name for a data type. // Marked unused because currently only called from asserts/debug. -static NSString *TypeToString(GPBDataType dataType) __attribute__((unused)); +static NSString *TypeToString(GPBDataType dataType) __attribute__ ((unused)); // Helper for clearing oneofs. -static void GPBMaybeClearOneofPrivate(GPBMessage *self, GPBOneofDescriptor *oneof, - int32_t oneofHasIndex, uint32_t fieldNumberNotToClear); +static void GPBMaybeClearOneofPrivate(GPBMessage *self, + GPBOneofDescriptor *oneof, + int32_t oneofHasIndex, + uint32_t fieldNumberNotToClear); NSData *GPBEmptyNSData(void) { static dispatch_once_t onceToken; @@ -114,53 +118,52 @@ void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) { id rawFieldMap = GPBGetObjectIvarWithFieldNoAutocreate(msg, field); switch (field.mapKeyDataType) { case GPBDataTypeBool: - [(GPBBoolObjectDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused BOOL key, id _Nonnull object, - __unused BOOL *_Nonnull stop) { - [todo addObject:object]; - }]; + [(GPBBoolObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + BOOL key, id _Nonnull object, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:object]; + }]; break; case GPBDataTypeFixed32: case GPBDataTypeUInt32: - [(GPBUInt32ObjectDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused uint32_t key, id _Nonnull object, - __unused BOOL *_Nonnull stop) { - [todo addObject:object]; - }]; + [(GPBUInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + uint32_t key, id _Nonnull object, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:object]; + }]; break; case GPBDataTypeInt32: case GPBDataTypeSFixed32: case GPBDataTypeSInt32: - [(GPBInt32ObjectDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused int32_t key, id _Nonnull object, - __unused BOOL *_Nonnull stop) { - [todo addObject:object]; - }]; + [(GPBInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + int32_t key, id _Nonnull object, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:object]; + }]; break; case GPBDataTypeFixed64: case GPBDataTypeUInt64: - [(GPBUInt64ObjectDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused uint64_t key, id _Nonnull object, - __unused BOOL *_Nonnull stop) { - [todo addObject:object]; - }]; + [(GPBUInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + uint64_t key, id _Nonnull object, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:object]; + }]; break; case GPBDataTypeInt64: case GPBDataTypeSFixed64: case GPBDataTypeSInt64: - [(GPBInt64ObjectDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused int64_t key, id _Nonnull object, - __unused BOOL *_Nonnull stop) { - [todo addObject:object]; - }]; + [(GPBInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + int64_t key, id _Nonnull object, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:object]; + }]; break; case GPBDataTypeString: - [(NSDictionary *)rawFieldMap - enumerateKeysAndObjectsUsingBlock:^(__unused NSString *_Nonnull key, - GPBMessage *_Nonnull obj, - __unused BOOL *_Nonnull stop) { - [todo addObject:obj]; - }]; + [(NSDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^( + NSString * _Nonnull key, GPBMessage * _Nonnull obj, BOOL * _Nonnull stop) { + #pragma unused(key, stop) + [todo addObject:obj]; + }]; break; case GPBDataTypeFloat: case GPBDataTypeDouble: @@ -172,8 +175,8 @@ void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) { } break; } // switch(field.mapKeyDataType) - } // switch(field.fieldType) - } // for(fields) + } // switch(field.fieldType) + } // for(fields) // Handle any extensions holding messages. for (GPBExtensionDescriptor *extension in [msg extensionsCurrentlySet]) { @@ -192,6 +195,7 @@ void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) { } // while(todo.count) } + // -- About Version Checks -- // There's actually 3 places these checks all come into play: // 1. When the generated source is compile into .o files, the header check @@ -224,7 +228,8 @@ void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) { format:@"Proto generation source compiled against runtime" @" version %d, but this version of the runtime only" @" supports back to %d!", - objcRuntimeVersion, GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION]; + objcRuntimeVersion, + GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION]; } } @@ -283,16 +288,18 @@ void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field) { } void GPBClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof) { -#if defined(DEBUG) && DEBUG - NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof, - @"OneofDescriptor %@ doesn't appear to be for %@ messages.", oneof.name, [self class]); -#endif + #if defined(DEBUG) && DEBUG + NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof, + @"OneofDescriptor %@ doesn't appear to be for %@ messages.", + oneof.name, [self class]); + #endif GPBFieldDescriptor *firstField = oneof->fields_[0]; GPBMaybeClearOneofPrivate(self, oneof, firstField->description_->hasIndex, 0); } BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) { - NSCAssert(self->messageStorage_ != NULL, @"%@: All messages should have storage (from init)", + NSCAssert(self->messageStorage_ != NULL, + @"%@: All messages should have storage (from init)", [self class]); if (idx < 0) { NSCAssert(fieldNumber != 0, @"Invalid field number."); @@ -302,18 +309,21 @@ BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) { NSCAssert(idx != GPBNoHasBit, @"Invalid has bit."); uint32_t byteIndex = idx / 32; uint32_t bitMask = (1U << (idx % 32)); - BOOL hasIvar = (self->messageStorage_->_has_storage_[byteIndex] & bitMask) ? YES : NO; + BOOL hasIvar = + (self->messageStorage_->_has_storage_[byteIndex] & bitMask) ? YES : NO; return hasIvar; } } uint32_t GPBGetHasOneof(GPBMessage *self, int32_t idx) { - NSCAssert(idx < 0, @"%@: invalid index (%d) for oneof.", [self class], idx); + NSCAssert(idx < 0, @"%@: invalid index (%d) for oneof.", + [self class], idx); uint32_t result = self->messageStorage_->_has_storage_[-idx]; return result; } -void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, BOOL value) { +void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, + BOOL value) { if (idx < 0) { NSCAssert(fieldNumber != 0, @"Invalid field number."); uint32_t *has_storage = self->messageStorage_->_has_storage_; @@ -331,8 +341,10 @@ void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, BOOL val } } -static void GPBMaybeClearOneofPrivate(GPBMessage *self, GPBOneofDescriptor *oneof, - int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) { +static void GPBMaybeClearOneofPrivate(GPBMessage *self, + GPBOneofDescriptor *oneof, + int32_t oneofHasIndex, + uint32_t fieldNumberNotToClear) { uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex); if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) { // Do nothing/nothing set in the oneof. @@ -342,8 +354,9 @@ static void GPBMaybeClearOneofPrivate(GPBMessage *self, GPBOneofDescriptor *oneo // Like GPBClearMessageField(), free the memory if an objecttype is set, // pod types don't need to do anything. GPBFieldDescriptor *fieldSet = [oneof fieldWithNumber:fieldNumberSet]; - NSCAssert(fieldSet, @"%@: oneof set to something (%u) not in the oneof?", [self class], - fieldNumberSet); + NSCAssert(fieldSet, + @"%@: oneof set to something (%u) not in the oneof?", + [self class], fieldNumberSet); if (fieldSet && GPBFieldStoresObject(fieldSet)) { uint8_t *storage = (uint8_t *)self->messageStorage_; id *typePtr = (id *)&storage[fieldSet->description_->offset]; @@ -358,8 +371,6 @@ static void GPBMaybeClearOneofPrivate(GPBMessage *self, GPBOneofDescriptor *oneo #pragma mark - IVar accessors -// clang-format off - //%PDDM-DEFINE IVAR_POD_ACCESSORS_DEFN(NAME, TYPE) //%TYPE GPBGetMessage##NAME##Field(GPBMessage *self, //% TYPE$S NAME$S GPBFieldDescriptor *field) { @@ -490,12 +501,11 @@ static void GPBMaybeClearOneofPrivate(GPBMessage *self, GPBOneofDescriptor *oneo //%} //% -// clang-format on - // Object types are handled slightly differently, they need to be released // and retained. -void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) { +void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field) { if (GPBGetHasIvarField(self, field)) { return; } @@ -508,12 +518,14 @@ void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, GPBFieldDescripto } // This exists only for bridging some aliased types, nothing else should use it. -static void GPBSetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field, id value) { +static void GPBSetObjectIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field, id value) { if (self == nil || field == nil) return; GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value retain]); } -static void GPBSetCopyObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field, id value); +static void GPBSetCopyObjectIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field, id value); // GPBSetCopyObjectIvarWithField is blocked from the analyzer because it flags // a leak for the -copy even though GPBSetRetainedObjectIvarWithFieldPrivate @@ -521,19 +533,23 @@ static void GPBSetCopyObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor * // with the -retain in GPBSetObjectIvarWithField. #if !defined(__clang_analyzer__) // This exists only for bridging some aliased types, nothing else should use it. -static void GPBSetCopyObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field, id value) { +static void GPBSetCopyObjectIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field, id value) { if (self == nil || field == nil) return; GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value copy]); } #endif // !defined(__clang_analyzer__) -void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, id value) { +void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, id value) { GPBSetRetainedObjectIvarWithFieldPrivate(self, field, [value retain]); } -void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, +void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, id value) { - NSCAssert(self->messageStorage_ != NULL, @"%@: All messages should have storage (from init)", + NSCAssert(self->messageStorage_ != NULL, + @"%@: All messages should have storage (from init)", [self class]); #if defined(__clang_analyzer__) if (self->messageStorage_ == NULL) return; @@ -542,7 +558,8 @@ void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescript BOOL isMapOrArray = GPBFieldIsMapOrArray(field); BOOL fieldIsMessage = GPBDataTypeIsMessage(fieldType); #if defined(DEBUG) && DEBUG - if (value == nil && !isMapOrArray && !fieldIsMessage && field.hasDefaultValue) { + if (value == nil && !isMapOrArray && !fieldIsMessage && + field.hasDefaultValue) { // Setting a message to nil is an obvious way to "clear" the value // as there is no way to set a non-empty default value for messages. // @@ -563,8 +580,8 @@ void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescript @"empty, or call '%@.%@ = NO' to reset it to it's default value of " @"'%@'. Defaulting to resetting default value.", className, propName, className, propName, - (fieldType == GPBDataTypeString) ? @"@\"\"" : @"GPBEmptyNSData()", className, hasSel, - field.defaultValue.valueString); + (fieldType == GPBDataTypeString) ? @"@\"\"" : @"GPBEmptyNSData()", + className, hasSel, field.defaultValue.valueString); // Note: valueString, depending on the type, it could easily be // valueData/valueMessage. } @@ -581,7 +598,8 @@ void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescript BOOL setHasValue = (value != nil); // If the field should clear on a "zero" value, then check if the string/data // was zero length, and clear instead. - if (((fieldDesc->flags & GPBFieldClearHasIvarOnZero) != 0) && ([value length] == 0)) { + if (((fieldDesc->flags & GPBFieldClearHasIvarOnZero) != 0) && + ([value length] == 0)) { setHasValue = NO; // The value passed in was retained, it must be released since we // aren't saving anything in the field. @@ -615,9 +633,10 @@ void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescript gpbArray->_autocreator = nil; } } - } else { // GPBFieldTypeMap + } else { // GPBFieldTypeMap // If the old map was autocreated by us, then clear it. - if ((field.mapKeyDataType == GPBDataTypeString) && GPBDataTypeIsObject(fieldType)) { + if ((field.mapKeyDataType == GPBDataTypeString) && + GPBDataTypeIsObject(fieldType)) { if ([oldValue isKindOfClass:[GPBAutocreatedDictionary class]]) { GPBAutocreatedDictionary *autoDict = oldValue; if (autoDict->_autocreator == self) { @@ -645,7 +664,8 @@ void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescript GPBBecomeVisibleToAutocreator(self); } -id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, GPBFieldDescriptor *field) { +id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, + GPBFieldDescriptor *field) { if (self->messageStorage_ == nil) { return nil; } @@ -656,68 +676,80 @@ id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, GPBFieldDescriptor *f // Only exists for public api, no core code should use this. int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field) { -#if defined(DEBUG) && DEBUG - NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, - @"FieldDescriptor %@ doesn't appear to be for %@ messages.", field.name, [self class]); - NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum, - @"Attempting to get value of type Enum from field %@ " - @"of %@ which is of type %@.", - [self class], field.name, TypeToString(GPBGetFieldDataType(field))); -#endif + #if defined(DEBUG) && DEBUG + NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, + @"FieldDescriptor %@ doesn't appear to be for %@ messages.", + field.name, [self class]); + NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum, + @"Attempting to get value of type Enum from field %@ " + @"of %@ which is of type %@.", + [self class], field.name, + TypeToString(GPBGetFieldDataType(field))); + #endif int32_t result = GPBGetMessageInt32Field(self, field); // If this is presevering unknown enums, make sure the value is valid before // returning it. GPBFileSyntax syntax = [self descriptor].file.syntax; - if (GPBHasPreservingUnknownEnumSemantics(syntax) && ![field isValidEnumValue:result]) { + if (GPBHasPreservingUnknownEnumSemantics(syntax) && + ![field isValidEnumValue:result]) { result = kGPBUnrecognizedEnumeratorValue; } return result; } // Only exists for public api, no core code should use this. -void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value) { -#if defined(DEBUG) && DEBUG - NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, - @"FieldDescriptor %@ doesn't appear to be for %@ messages.", field.name, [self class]); - NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum, - @"Attempting to set field %@ of %@ which is of type %@ with " - @"value of type Enum.", - [self class], field.name, TypeToString(GPBGetFieldDataType(field))); -#endif +void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, + int32_t value) { + #if defined(DEBUG) && DEBUG + NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, + @"FieldDescriptor %@ doesn't appear to be for %@ messages.", + field.name, [self class]); + NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeEnum, + @"Attempting to set field %@ of %@ which is of type %@ with " + @"value of type Enum.", + [self class], field.name, + TypeToString(GPBGetFieldDataType(field))); + #endif GPBSetEnumIvarWithFieldPrivate(self, field, value); } -void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, int32_t value) { +void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, int32_t value) { // Don't allow in unknown values. Proto3 can use the Raw method. if (![field isValidEnumValue:value]) { [NSException raise:NSInvalidArgumentException - format:@"%@.%@: Attempt to set an unknown enum value (%d)", [self class], - field.name, value]; + format:@"%@.%@: Attempt to set an unknown enum value (%d)", + [self class], field.name, value]; } GPBSetInt32IvarWithFieldPrivate(self, field, value); } // Only exists for public api, no core code should use this. -int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field) { +int32_t GPBGetMessageRawEnumField(GPBMessage *self, + GPBFieldDescriptor *field) { int32_t result = GPBGetMessageInt32Field(self, field); return result; } // Only exists for public api, no core code should use this. -void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value) { +void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, + int32_t value) { GPBSetInt32IvarWithFieldPrivate(self, field, value); } -BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field) { +BOOL GPBGetMessageBoolField(GPBMessage *self, + GPBFieldDescriptor *field) { #if defined(DEBUG) && DEBUG NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, - @"FieldDescriptor %@ doesn't appear to be for %@ messages.", field.name, [self class]); + @"FieldDescriptor %@ doesn't appear to be for %@ messages.", + field.name, [self class]); NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool), @"Attempting to get value of type bool from field %@ " @"of %@ which is of type %@.", - [self class], field.name, TypeToString(GPBGetFieldDataType(field))); + [self class], field.name, + TypeToString(GPBGetFieldDataType(field))); #endif if (GPBGetHasIvarField(self, field)) { // Bools are stored in the has bits to avoid needing explicit space in the @@ -732,20 +764,26 @@ BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field) { } // Only exists for public api, no core code should use this. -void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value) { +void GPBSetMessageBoolField(GPBMessage *self, + GPBFieldDescriptor *field, + BOOL value) { if (self == nil || field == nil) return; -#if defined(DEBUG) && DEBUG - NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, - @"FieldDescriptor %@ doesn't appear to be for %@ messages.", field.name, [self class]); - NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool), - @"Attempting to set field %@ of %@ which is of type %@ with " - @"value of type bool.", - [self class], field.name, TypeToString(GPBGetFieldDataType(field))); -#endif + #if defined(DEBUG) && DEBUG + NSCAssert([[self descriptor] fieldWithNumber:field.number] == field, + @"FieldDescriptor %@ doesn't appear to be for %@ messages.", + field.name, [self class]); + NSCAssert(DataTypesEquivalent(GPBGetFieldDataType(field), GPBDataTypeBool), + @"Attempting to set field %@ of %@ which is of type %@ with " + @"value of type bool.", + [self class], field.name, + TypeToString(GPBGetFieldDataType(field))); + #endif GPBSetBoolIvarWithFieldPrivate(self, field, value); } -void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, BOOL value) { +void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, + BOOL value) { GPBMessageFieldDescription *fieldDesc = field->description_; GPBOneofDescriptor *oneof = field->containingOneof_; if (oneof) { @@ -760,15 +798,15 @@ void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, // If the value is zero, then we only count the field as "set" if the field // shouldn't auto clear on zero. - BOOL hasValue = ((value != (BOOL)0) || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0)); + BOOL hasValue = ((value != (BOOL)0) + || ((fieldDesc->flags & GPBFieldClearHasIvarOnZero) == 0)); GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, hasValue); GPBBecomeVisibleToAutocreator(self); } -// clang-format off - //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int32, int32_t) // This block of code is generated, do not edit it directly. +// clang-format off int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field) { @@ -838,8 +876,10 @@ void GPBSetInt32IvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt32, uint32_t) // This block of code is generated, do not edit it directly. +// clang-format off uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field) { @@ -909,8 +949,10 @@ void GPBSetUInt32IvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int64, int64_t) // This block of code is generated, do not edit it directly. +// clang-format off int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field) { @@ -980,8 +1022,10 @@ void GPBSetInt64IvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt64, uint64_t) // This block of code is generated, do not edit it directly. +// clang-format off uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field) { @@ -1051,8 +1095,10 @@ void GPBSetUInt64IvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Float, float) // This block of code is generated, do not edit it directly. +// clang-format off float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field) { @@ -1122,8 +1168,10 @@ void GPBSetFloatIvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Double, double) // This block of code is generated, do not edit it directly. +// clang-format off double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field) { @@ -1193,12 +1241,14 @@ void GPBSetDoubleIvarWithFieldPrivate(GPBMessage *self, GPBBecomeVisibleToAutocreator(self); } +// clang-format on //%PDDM-EXPAND-END (6 expansions) // Aliases are function calls that are virtually the same. //%PDDM-EXPAND IVAR_ALIAS_DEFN_COPY_OBJECT(String, NSString) // This block of code is generated, do not edit it directly. +// clang-format off // Only exists for public api, no core code should use this. NSString *GPBGetMessageStringField(GPBMessage *self, @@ -1229,8 +1279,10 @@ void GPBSetMessageStringField(GPBMessage *self, GPBSetCopyObjectIvarWithField(self, field, (id)value); } +// clang-format on //%PDDM-EXPAND IVAR_ALIAS_DEFN_COPY_OBJECT(Bytes, NSData) // This block of code is generated, do not edit it directly. +// clang-format off // Only exists for public api, no core code should use this. NSData *GPBGetMessageBytesField(GPBMessage *self, @@ -1261,8 +1313,10 @@ void GPBSetMessageBytesField(GPBMessage *self, GPBSetCopyObjectIvarWithField(self, field, (id)value); } +// clang-format on //%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Message, GPBMessage) // This block of code is generated, do not edit it directly. +// clang-format off // Only exists for public api, no core code should use this. GPBMessage *GPBGetMessageMessageField(GPBMessage *self, @@ -1293,8 +1347,10 @@ void GPBSetMessageMessageField(GPBMessage *self, GPBSetObjectIvarWithField(self, field, (id)value); } +// clang-format on //%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Group, GPBMessage) // This block of code is generated, do not edit it directly. +// clang-format off // Only exists for public api, no core code should use this. GPBMessage *GPBGetMessageGroupField(GPBMessage *self, @@ -1325,9 +1381,8 @@ void GPBSetMessageGroupField(GPBMessage *self, GPBSetObjectIvarWithField(self, field, (id)value); } -//%PDDM-EXPAND-END (4 expansions) - // clang-format on +//%PDDM-EXPAND-END (4 expansions) // GPBGetMessageRepeatedField is defined in GPBMessage.m @@ -1336,7 +1391,8 @@ void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id #if defined(DEBUG) && DEBUG if (field.fieldType != GPBFieldTypeRepeated) { [NSException raise:NSInvalidArgumentException - format:@"%@.%@ is not a repeated field.", [self class], field.name]; + format:@"%@.%@ is not a repeated field.", + [self class], field.name]; } Class expectedClass = Nil; switch (GPBGetFieldDataType(field)) { @@ -1379,8 +1435,8 @@ void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id } if (array && ![array isKindOfClass:expectedClass]) { [NSException raise:NSInvalidArgumentException - format:@"%@.%@: Expected %@ object, got %@.", [self class], field.name, - expectedClass, [array class]]; + format:@"%@.%@: Expected %@ object, got %@.", + [self class], field.name, expectedClass, [array class]]; } #endif GPBSetObjectIvarWithField(self, field, array); @@ -1412,7 +1468,7 @@ static GPBDataType BaseDataType(GPBDataType type) { case GPBDataTypeBytes: case GPBDataTypeString: return type; - } + } } static BOOL DataTypesEquivalent(GPBDataType type1, GPBDataType type2) { @@ -1454,11 +1510,13 @@ static NSString *TypeToString(GPBDataType dataType) { // GPBGetMessageMapField is defined in GPBMessage.m // Only exists for public api, no core code should use this. -void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary) { +void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, + id dictionary) { #if defined(DEBUG) && DEBUG if (field.fieldType != GPBFieldTypeMap) { [NSException raise:NSInvalidArgumentException - format:@"%@.%@ is not a map<> field.", [self class], field.name]; + format:@"%@.%@ is not a map<> field.", + [self class], field.name]; } if (dictionary) { GPBDataType keyDataType = field.mapKeyDataType; @@ -1469,17 +1527,20 @@ void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dicti keyStr = @"String"; } Class expectedClass = Nil; - if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) { + if ((keyDataType == GPBDataTypeString) && + GPBDataTypeIsObject(valueDataType)) { expectedClass = [NSMutableDictionary class]; } else { - NSString *className = [NSString stringWithFormat:@"GPB%@%@Dictionary", keyStr, valueStr]; + NSString *className = + [NSString stringWithFormat:@"GPB%@%@Dictionary", keyStr, valueStr]; expectedClass = NSClassFromString(className); NSCAssert(expectedClass, @"Missing a class (%@)?", expectedClass); } if (![dictionary isKindOfClass:expectedClass]) { [NSException raise:NSInvalidArgumentException - format:@"%@.%@: Expected %@ object, got %@.", [self class], field.name, - expectedClass, [dictionary class]]; + format:@"%@.%@: Expected %@ object, got %@.", + [self class], field.name, expectedClass, + [dictionary class]]; } } #endif @@ -1489,12 +1550,13 @@ void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dicti #pragma mark - Misc Dynamic Runtime Utils const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel) { - Protocol *protocol = objc_getProtocol(GPBStringifySymbol(GPBMessageSignatureProtocol)); + Protocol *protocol = + objc_getProtocol(GPBStringifySymbol(GPBMessageSignatureProtocol)); NSCAssert(protocol, @"Missing GPBMessageSignatureProtocol"); struct objc_method_description description = protocol_getMethodDescription(protocol, selector, NO, instanceSel); - NSCAssert(description.name != Nil && description.types != nil, @"Missing method for selector %@", - NSStringFromSelector(selector)); + NSCAssert(description.name != Nil && description.types != nil, + @"Missing method for selector %@", NSStringFromSelector(selector)); return description.types; } @@ -1506,30 +1568,19 @@ static void AppendStringEscaped(NSString *toPrint, NSMutableString *destStr) { for (NSUInteger i = 0; i < len; ++i) { unichar aChar = [toPrint characterAtIndex:i]; switch (aChar) { - case '\n': - [destStr appendString:@"\\n"]; - break; - case '\r': - [destStr appendString:@"\\r"]; - break; - case '\t': - [destStr appendString:@"\\t"]; - break; - case '\"': - [destStr appendString:@"\\\""]; - break; - case '\'': - [destStr appendString:@"\\\'"]; - break; - case '\\': - [destStr appendString:@"\\\\"]; - break; + case '\n': [destStr appendString:@"\\n"]; break; + case '\r': [destStr appendString:@"\\r"]; break; + case '\t': [destStr appendString:@"\\t"]; break; + case '\"': [destStr appendString:@"\\\""]; break; + case '\'': [destStr appendString:@"\\\'"]; break; + case '\\': [destStr appendString:@"\\\\"]; break; default: // This differs slightly from the C++ code in that the C++ doesn't // generate UTF8; it looks at the string in UTF8, but escapes every // byte > 0x7E. if (aChar < 0x20) { - [destStr appendFormat:@"\\%d%d%d", (aChar / 64), ((aChar % 64) / 8), (aChar % 8)]; + [destStr appendFormat:@"\\%d%d%d", + (aChar / 64), ((aChar % 64) / 8), (aChar % 8)]; } else { [destStr appendFormat:@"%C", aChar]; } @@ -1545,24 +1596,12 @@ static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) { [destStr appendString:@"\""]; for (const char *srcEnd = src + srcLen; src < srcEnd; src++) { switch (*src) { - case '\n': - [destStr appendString:@"\\n"]; - break; - case '\r': - [destStr appendString:@"\\r"]; - break; - case '\t': - [destStr appendString:@"\\t"]; - break; - case '\"': - [destStr appendString:@"\\\""]; - break; - case '\'': - [destStr appendString:@"\\\'"]; - break; - case '\\': - [destStr appendString:@"\\\\"]; - break; + case '\n': [destStr appendString:@"\\n"]; break; + case '\r': [destStr appendString:@"\\r"]; break; + case '\t': [destStr appendString:@"\\t"]; break; + case '\"': [destStr appendString:@"\\\""]; break; + case '\'': [destStr appendString:@"\\\'"]; break; + case '\\': [destStr appendString:@"\\\\"]; break; default: if (isprint(*src)) { [destStr appendFormat:@"%c", *src]; @@ -1578,28 +1617,31 @@ static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) { [destStr appendString:@"\""]; } -static void AppendTextFormatForMapMessageField(id map, GPBFieldDescriptor *field, - NSMutableString *toStr, NSString *lineIndent, - NSString *fieldName, NSString *lineEnding) { +static void AppendTextFormatForMapMessageField( + id map, GPBFieldDescriptor *field, NSMutableString *toStr, + NSString *lineIndent, NSString *fieldName, NSString *lineEnding) { GPBDataType keyDataType = field.mapKeyDataType; GPBDataType valueDataType = GPBGetFieldDataType(field); BOOL isMessageValue = GPBDataTypeIsMessage(valueDataType); NSString *msgStartFirst = [NSString stringWithFormat:@"%@%@ {%@\n", lineIndent, fieldName, lineEnding]; - NSString *msgStart = [NSString stringWithFormat:@"%@%@ {\n", lineIndent, fieldName]; + NSString *msgStart = + [NSString stringWithFormat:@"%@%@ {\n", lineIndent, fieldName]; NSString *msgEnd = [NSString stringWithFormat:@"%@}\n", lineIndent]; NSString *keyLine = [NSString stringWithFormat:@"%@ key: ", lineIndent]; - NSString *valueLine = - [NSString stringWithFormat:@"%@ value%s ", lineIndent, (isMessageValue ? "" : ":")]; + NSString *valueLine = [NSString stringWithFormat:@"%@ value%s ", lineIndent, + (isMessageValue ? "" : ":")]; __block BOOL isFirst = YES; - if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) { + if ((keyDataType == GPBDataTypeString) && + GPBDataTypeIsObject(valueDataType)) { // map is an NSDictionary. NSDictionary *dict = map; - [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) { + #pragma unused(stop) [toStr appendString:(isFirst ? msgStartFirst : msgStart)]; isFirst = NO; @@ -1699,8 +1741,10 @@ static void AppendTextFormatForMapMessageField(id map, GPBFieldDescriptor *field } } -static void AppendTextFormatForMessageField(GPBMessage *message, GPBFieldDescriptor *field, - NSMutableString *toStr, NSString *lineIndent) { +static void AppendTextFormatForMessageField(GPBMessage *message, + GPBFieldDescriptor *field, + NSMutableString *toStr, + NSString *lineIndent) { id arrayOrMap; NSUInteger count; GPBFieldType fieldType = field.fieldType; @@ -1748,7 +1792,8 @@ static void AppendTextFormatForMessageField(GPBMessage *message, GPBFieldDescrip } if (fieldType == GPBFieldTypeMap) { - AppendTextFormatForMapMessageField(arrayOrMap, field, toStr, lineIndent, fieldName, lineEnding); + AppendTextFormatForMapMessageField(arrayOrMap, field, toStr, lineIndent, + fieldName, lineEnding); return; } @@ -1759,7 +1804,8 @@ static void AppendTextFormatForMessageField(GPBMessage *message, GPBFieldDescrip BOOL isMessageField = GPBDataTypeIsMessage(fieldDataType); for (NSUInteger j = 0; j < count; ++j) { // Start the line. - [toStr appendFormat:@"%@%@%s ", lineIndent, fieldName, (isMessageField ? "" : ":")]; + [toStr appendFormat:@"%@%@%s ", lineIndent, fieldName, + (isMessageField ? "" : ":")]; // The value. switch (fieldDataType) { @@ -1825,8 +1871,9 @@ static void AppendTextFormatForMessageField(GPBMessage *message, GPBFieldDescrip case GPBDataTypeGroup: case GPBDataTypeMessage: { - GPBMessage *v = (isRepeated ? [(NSArray *)array objectAtIndex:j] - : GPBGetObjectIvarWithField(message, field)); + GPBMessage *v = + (isRepeated ? [(NSArray *)array objectAtIndex:j] + : GPBGetObjectIvarWithField(message, field)); [toStr appendFormat:@"{%@\n", lineEnding]; NSString *subIndent = [lineIndent stringByAppendingString:@" "]; AppendTextFormatForMessage(v, toStr, subIndent); @@ -1843,9 +1890,11 @@ static void AppendTextFormatForMessageField(GPBMessage *message, GPBFieldDescrip } // for(count) } -static void AppendTextFormatForMessageExtensionRange(GPBMessage *message, NSArray *activeExtensions, +static void AppendTextFormatForMessageExtensionRange(GPBMessage *message, + NSArray *activeExtensions, GPBExtensionRange range, - NSMutableString *toStr, NSString *lineIndent) { + NSMutableString *toStr, + NSString *lineIndent) { uint32_t start = range.start; uint32_t end = range.end; for (GPBExtensionDescriptor *extension in activeExtensions) { @@ -1914,7 +1963,8 @@ static void AppendTextFormatForMessageExtensionRange(GPBMessage *message, NSArra #undef FIELD_CASE case GPBDataTypeBool: - [toStr appendString:([(NSNumber *)curValue boolValue] ? @"true" : @"false")]; + [toStr appendString:([(NSNumber *)curValue boolValue] ? @"true" + : @"false")]; break; case GPBDataTypeString: @@ -1945,29 +1995,32 @@ static void AppendTextFormatForMessageExtensionRange(GPBMessage *message, NSArra } // for..in(activeExtensions) } -static void AppendTextFormatForMessage(GPBMessage *message, NSMutableString *toStr, +static void AppendTextFormatForMessage(GPBMessage *message, + NSMutableString *toStr, NSString *lineIndent) { GPBDescriptor *descriptor = [message descriptor]; NSArray *fieldsArray = descriptor->fields_; NSUInteger fieldCount = fieldsArray.count; const GPBExtensionRange *extensionRanges = descriptor.extensionRanges; NSUInteger extensionRangesCount = descriptor.extensionRangesCount; - NSArray *activeExtensions = - [[message extensionsCurrentlySet] sortedArrayUsingSelector:@selector(compareByFieldNumber:)]; + NSArray *activeExtensions = [[message extensionsCurrentlySet] + sortedArrayUsingSelector:@selector(compareByFieldNumber:)]; for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) { if (i == fieldCount) { - AppendTextFormatForMessageExtensionRange(message, activeExtensions, extensionRanges[j++], - toStr, lineIndent); + AppendTextFormatForMessageExtensionRange( + message, activeExtensions, extensionRanges[j++], toStr, lineIndent); } else if (j == extensionRangesCount || GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) { - AppendTextFormatForMessageField(message, fieldsArray[i++], toStr, lineIndent); + AppendTextFormatForMessageField(message, fieldsArray[i++], toStr, + lineIndent); } else { - AppendTextFormatForMessageExtensionRange(message, activeExtensions, extensionRanges[j++], - toStr, lineIndent); + AppendTextFormatForMessageExtensionRange( + message, activeExtensions, extensionRanges[j++], toStr, lineIndent); } } - NSString *unknownFieldsStr = GPBTextFormatForUnknownFieldSet(message.unknownFields, lineIndent); + NSString *unknownFieldsStr = + GPBTextFormatForUnknownFieldSet(message.unknownFields, lineIndent); if ([unknownFieldsStr length] > 0) { [toStr appendFormat:@"%@# --- Unknown fields ---\n", lineIndent]; [toStr appendString:unknownFieldsStr]; @@ -1983,7 +2036,8 @@ NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent) { return buildString; } -NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet, NSString *lineIndent) { +NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet, + NSString *lineIndent) { if (unknownSet == nil) return @""; if (lineIndent == nil) lineIndent = @""; @@ -1991,15 +2045,17 @@ NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet, NSStri for (GPBUnknownField *field in [unknownSet sortedFields]) { int32_t fieldNumber = [field number]; -#define PRINT_LOOP(PROPNAME, CTYPE, FORMAT) \ - [field.PROPNAME \ - enumerateValuesWithBlock:^(CTYPE value, __unused NSUInteger idx, __unused BOOL * stop) { \ - [result appendFormat:@"%@%d: " FORMAT "\n", lineIndent, fieldNumber, value]; \ +#define PRINT_LOOP(PROPNAME, CTYPE, FORMAT) \ + [field.PROPNAME \ + enumerateValuesWithBlock:^(CTYPE value, NSUInteger idx, BOOL * stop) { \ + _Pragma("unused(idx, stop)"); \ + [result \ + appendFormat:@"%@%d: " #FORMAT "\n", lineIndent, fieldNumber, value]; \ }]; - PRINT_LOOP(varintList, uint64_t, "%llu"); - PRINT_LOOP(fixed32List, uint32_t, "0x%X"); - PRINT_LOOP(fixed64List, uint64_t, "0x%llX"); + PRINT_LOOP(varintList, uint64_t, %llu); + PRINT_LOOP(fixed32List, uint32_t, 0x%X); + PRINT_LOOP(fixed64List, uint64_t, 0x%llX); #undef PRINT_LOOP @@ -2014,7 +2070,8 @@ NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet, NSStri for (GPBUnknownFieldSet *subUnknownSet in field.groupList) { [result appendFormat:@"%@%d: {\n", lineIndent, fieldNumber]; NSString *subIndent = [lineIndent stringByAppendingString:@" "]; - NSString *subUnknownSetStr = GPBTextFormatForUnknownFieldSet(subUnknownSet, subIndent); + NSString *subUnknownSetStr = + GPBTextFormatForUnknownFieldSet(subUnknownSet, subIndent); [result appendString:subUnknownSetStr]; [result appendFormat:@"%@}\n", lineIndent]; } @@ -2057,7 +2114,8 @@ static int32_t ReadRawVarint32FromData(const uint8_t **data) { return result; } } - [NSException raise:NSParseErrorException format:@"Unable to read varint32"]; + [NSException raise:NSParseErrorException + format:@"Unable to read varint32"]; } } } @@ -2065,7 +2123,8 @@ static int32_t ReadRawVarint32FromData(const uint8_t **data) { return result; } -NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, NSString *inputStr) { +NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, + NSString *inputStr) { // decodData form: // varint32: num entries // for each entry: @@ -2123,14 +2182,15 @@ NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, NSStri return result; } - NSMutableString *result = [NSMutableString stringWithCapacity:[inputStr length]]; + NSMutableString *result = + [NSMutableString stringWithCapacity:[inputStr length]]; - const uint8_t kAddUnderscore = 0b10000000; - const uint8_t kOpMask = 0b01100000; + const uint8_t kAddUnderscore = 0b10000000; + const uint8_t kOpMask = 0b01100000; // const uint8_t kOpAsIs = 0b00000000; - const uint8_t kOpFirstUpper = 0b01000000; - const uint8_t kOpFirstLower = 0b00100000; - const uint8_t kOpAllUpper = 0b01100000; + const uint8_t kOpFirstUpper = 0b01000000; + const uint8_t kOpFirstLower = 0b00100000; + const uint8_t kOpAllUpper = 0b01100000; const uint8_t kSegmentLenMask = 0b00011111; NSInteger i = 0; @@ -2173,21 +2233,26 @@ NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, NSStri #pragma mark Legacy methods old generated code calls // Shim from the older generated code into the runtime. -void GPBSetInt32IvarWithFieldInternal(GPBMessage *self, GPBFieldDescriptor *field, int32_t value, - __unused GPBFileSyntax syntax) { +void GPBSetInt32IvarWithFieldInternal(GPBMessage *self, + GPBFieldDescriptor *field, + int32_t value, + GPBFileSyntax syntax) { +#pragma unused(syntax) GPBSetMessageInt32Field(self, field, value); } -void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, int32_t oneofHasIndex, - __unused uint32_t fieldNumberNotToClear) { -#if defined(DEBUG) && DEBUG - NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof, - @"OneofDescriptor %@ doesn't appear to be for %@ messages.", oneof.name, [self class]); - GPBFieldDescriptor *firstField __unused = oneof->fields_[0]; - NSCAssert(firstField->description_->hasIndex == oneofHasIndex, - @"Internal error, oneofHasIndex (%d) doesn't match (%d).", - firstField->description_->hasIndex, oneofHasIndex); -#endif +void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, + int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) { +#pragma unused(fieldNumberNotToClear) + #if defined(DEBUG) && DEBUG + NSCAssert([[self descriptor] oneofWithName:oneof.name] == oneof, + @"OneofDescriptor %@ doesn't appear to be for %@ messages.", + oneof.name, [self class]); + GPBFieldDescriptor *firstField = oneof->fields_[0]; + NSCAssert(firstField->description_->hasIndex == oneofHasIndex, + @"Internal error, oneofHasIndex (%d) doesn't match (%d).", + firstField->description_->hasIndex, oneofHasIndex); + #endif GPBMaybeClearOneofPrivate(self, oneof, oneofHasIndex, 0); } diff --git a/libs/protobuf/objectivec/GPBUtilities_PackagePrivate.h b/libs/protobuf/objectivec/GPBUtilities_PackagePrivate.h index f04ed83..3d3d734 100644 --- a/libs/protobuf/objectivec/GPBUtilities_PackagePrivate.h +++ b/libs/protobuf/objectivec/GPBUtilities_PackagePrivate.h @@ -40,15 +40,17 @@ #define GPBStringify(S) #S #define GPBStringifySymbol(S) GPBStringify(S) -#define GPBNSStringify(S) @ #S +#define GPBNSStringify(S) @#S #define GPBNSStringifySymbol(S) GPBNSStringify(S) // Macros for generating a Class from a class name. These are used in // the generated GPB descriptor classes wherever an Objective C class // reference is needed for a generated class. #define GPBObjCClassSymbol(name) OBJC_CLASS_$_##name -#define GPBObjCClass(name) ((__bridge Class) & (GPBObjCClassSymbol(name))) -#define GPBObjCClassDeclaration(name) extern const GPBObjcClass_t GPBObjCClassSymbol(name) +#define GPBObjCClass(name) \ + ((__bridge Class)&(GPBObjCClassSymbol(name))) +#define GPBObjCClassDeclaration(name) \ + extern const GPBObjcClass_t GPBObjCClassSymbol(name) // Constant to internally mark when there is no has bit. #define GPBNoHasBit INT32_MAX @@ -118,7 +120,7 @@ GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) { // negative values must be sign-extended to 64 bits to be varint encoded, // thus always taking 10 bytes on the wire.) GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) { - return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(n)&1)); + return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(n) & 1)); } // Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers @@ -126,7 +128,7 @@ GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) { // negative values must be sign-extended to 64 bits to be varint encoded, // thus always taking 10 bytes on the wire.) GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) { - return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n)&1)); + return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n) & 1)); } // Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers @@ -195,84 +197,102 @@ GPB_INLINE BOOL GPBFieldStoresObject(GPBFieldDescriptor *field) { } BOOL GPBGetHasIvar(GPBMessage *self, int32_t index, uint32_t fieldNumber); -void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, BOOL value); +void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber, + BOOL value); uint32_t GPBGetHasOneof(GPBMessage *self, int32_t index); -GPB_INLINE BOOL GPBGetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field) { +GPB_INLINE BOOL +GPBGetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field) { GPBMessageFieldDescription *fieldDesc = field->description_; return GPBGetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number); } #pragma clang diagnostic pop -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE) //%void GPBSet##NAME##IvarWithFieldPrivate(GPBMessage *self, //% NAME$S GPBFieldDescriptor *field, //% NAME$S TYPE value); //%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetBoolIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, BOOL value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(Int32, int32_t) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetInt32IvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt32, uint32_t) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetUInt32IvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(Int64, int64_t) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetInt64IvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, int64_t value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt64, uint64_t) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetUInt64IvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(Float, float) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetFloatIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, float value); +// clang-format on //%PDDM-EXPAND GPB_IVAR_SET_DECL(Double, double) // This block of code is generated, do not edit it directly. +// clang-format off void GPBSetDoubleIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, double value); +// clang-format on //%PDDM-EXPAND-END (7 expansions) -// clang-format on - -void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, int32_t value); +void GPBSetEnumIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, + int32_t value); id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); -void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, id value); -void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, GPBFieldDescriptor *field, - id __attribute__((ns_consumed)) value); +void GPBSetObjectIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, id value); +void GPBSetRetainedObjectIvarWithFieldPrivate(GPBMessage *self, + GPBFieldDescriptor *field, + id __attribute__((ns_consumed)) + value); // GPBGetObjectIvarWithField will automatically create the field (message) if // it doesn't exist. GPBGetObjectIvarWithFieldNoAutocreate will return nil. -id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, GPBFieldDescriptor *field); +id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self, + GPBFieldDescriptor *field); // Clears and releases the autocreated message ivar, if it's autocreated. If // it's not set as autocreated, this method does nothing. -void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); +void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self, + GPBFieldDescriptor *field); // Returns an Objective C encoding for |selector|. |instanceSel| should be // YES if it's an instance selector (as opposed to a class selector). @@ -282,13 +302,17 @@ const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel); // Helper for text format name encoding. // decodeData is the data describing the special decodes. // key and inputString are the input that needs decoding. -NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, NSString *inputString); +NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, + NSString *inputString); + // Shims from the older generated code into the runtime. -void GPBSetInt32IvarWithFieldInternal(GPBMessage *self, GPBFieldDescriptor *field, int32_t value, +void GPBSetInt32IvarWithFieldInternal(GPBMessage *self, + GPBFieldDescriptor *field, + int32_t value, GPBFileSyntax syntax); -void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, int32_t oneofHasIndex, - uint32_t fieldNumberNotToClear); +void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, + int32_t oneofHasIndex, uint32_t fieldNumberNotToClear); // A series of selectors that are used solely to get @encoding values // for them by the dynamic protobuf runtime code. See diff --git a/libs/protobuf/objectivec/GPBWellKnownTypes.h b/libs/protobuf/objectivec/GPBWellKnownTypes.h index 765ad24..80d9db0 100644 --- a/libs/protobuf/objectivec/GPBWellKnownTypes.h +++ b/libs/protobuf/objectivec/GPBWellKnownTypes.h @@ -141,7 +141,8 @@ typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) { * * @return A newly configured GPBAny with the given message, or nil on failure. */ -+ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message error:(NSError **)errorPtr; ++ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message + error:(NSError **)errorPtr; /** * Convenience method to create a GPBAny containing the serialized message. @@ -167,7 +168,8 @@ typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) { * * @return A newly configured GPBAny with the given message, or nil on failure. */ -- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message error:(NSError **)errorPtr; +- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message + error:(NSError **)errorPtr; /** * Initializes a GPBAny to contain the serialized message. @@ -193,7 +195,8 @@ typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) { * * @return Whether the packing was successful or not. */ -- (BOOL)packWithMessage:(nonnull GPBMessage *)message error:(NSError **)errorPtr; +- (BOOL)packWithMessage:(nonnull GPBMessage *)message + error:(NSError **)errorPtr; /** * Packs the serialized message into this GPBAny. @@ -222,7 +225,8 @@ typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) { * @return An instance of the given class populated with the contained data, or * nil on failure. */ -- (nullable GPBMessage *)unpackMessageClass:(Class)messageClass error:(NSError **)errorPtr; +- (nullable GPBMessage *)unpackMessageClass:(Class)messageClass + error:(NSError **)errorPtr; @end diff --git a/libs/protobuf/objectivec/GPBWellKnownTypes.m b/libs/protobuf/objectivec/GPBWellKnownTypes.m index 90e82d3..2808afe 100644 --- a/libs/protobuf/objectivec/GPBWellKnownTypes.m +++ b/libs/protobuf/objectivec/GPBWellKnownTypes.m @@ -36,15 +36,18 @@ #import "GPBUtilities_PackagePrivate.h" -NSString *const GPBWellKnownTypesErrorDomain = GPBNSStringifySymbol(GPBWellKnownTypesErrorDomain); +NSString *const GPBWellKnownTypesErrorDomain = + GPBNSStringifySymbol(GPBWellKnownTypesErrorDomain); static NSString *kTypePrefixGoogleApisCom = @"type.googleapis.com/"; -static NSTimeInterval TimeIntervalFromSecondsAndNanos(int64_t seconds, int32_t nanos) { +static NSTimeInterval TimeIntervalFromSecondsAndNanos(int64_t seconds, + int32_t nanos) { return seconds + (NSTimeInterval)nanos / 1e9; } -static int32_t SecondsAndNanosFromTimeInterval(NSTimeInterval time, int64_t *outSeconds, +static int32_t SecondsAndNanosFromTimeInterval(NSTimeInterval time, + int64_t *outSeconds, BOOL nanosMustBePositive) { NSTimeInterval seconds; NSTimeInterval nanos = modf(time, &seconds); @@ -76,7 +79,8 @@ static NSString *BuildTypeURL(NSString *typeURLPrefix, NSString *fullName) { static NSString *ParseTypeFromURL(NSString *typeURLString) { NSRange range = [typeURLString rangeOfString:@"/" options:NSBackwardsSearch]; - if ((range.location == NSNotFound) || (NSMaxRange(range) == typeURLString.length)) { + if ((range.location == NSNotFound) || + (NSMaxRange(range) == typeURLString.length)) { return nil; } NSString *result = [typeURLString substringFromIndex:range.location + 1]; @@ -94,7 +98,8 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 { if ((self = [super init])) { int64_t seconds; - int32_t nanos = SecondsAndNanosFromTimeInterval(timeIntervalSince1970, &seconds, YES); + int32_t nanos = SecondsAndNanosFromTimeInterval( + timeIntervalSince1970, &seconds, YES); self.seconds = seconds; self.nanos = nanos; } @@ -115,7 +120,8 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { - (void)setTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 { int64_t seconds; - int32_t nanos = SecondsAndNanosFromTimeInterval(timeIntervalSince1970, &seconds, YES); + int32_t nanos = + SecondsAndNanosFromTimeInterval(timeIntervalSince1970, &seconds, YES); self.seconds = seconds; self.nanos = nanos; } @@ -129,7 +135,8 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { - (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval { if ((self = [super init])) { int64_t seconds; - int32_t nanos = SecondsAndNanosFromTimeInterval(timeInterval, &seconds, NO); + int32_t nanos = SecondsAndNanosFromTimeInterval( + timeInterval, &seconds, NO); self.seconds = seconds; self.nanos = nanos; } @@ -146,7 +153,8 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { - (void)setTimeInterval:(NSTimeInterval)timeInterval { int64_t seconds; - int32_t nanos = SecondsAndNanosFromTimeInterval(timeInterval, &seconds, NO); + int32_t nanos = + SecondsAndNanosFromTimeInterval(timeInterval, &seconds, NO); self.seconds = seconds; self.nanos = nanos; } @@ -165,19 +173,26 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { @implementation GPBAny (GBPWellKnownTypes) -+ (instancetype)anyWithMessage:(GPBMessage *)message error:(NSError **)errorPtr { - return [self anyWithMessage:message typeURLPrefix:kTypePrefixGoogleApisCom error:errorPtr]; ++ (instancetype)anyWithMessage:(GPBMessage *)message + error:(NSError **)errorPtr { + return [self anyWithMessage:message + typeURLPrefix:kTypePrefixGoogleApisCom + error:errorPtr]; } + (instancetype)anyWithMessage:(GPBMessage *)message typeURLPrefix:(NSString *)typeURLPrefix error:(NSError **)errorPtr { - return [[[self alloc] initWithMessage:message typeURLPrefix:typeURLPrefix + return [[[self alloc] initWithMessage:message + typeURLPrefix:typeURLPrefix error:errorPtr] autorelease]; } -- (instancetype)initWithMessage:(GPBMessage *)message error:(NSError **)errorPtr { - return [self initWithMessage:message typeURLPrefix:kTypePrefixGoogleApisCom error:errorPtr]; +- (instancetype)initWithMessage:(GPBMessage *)message + error:(NSError **)errorPtr { + return [self initWithMessage:message + typeURLPrefix:kTypePrefixGoogleApisCom + error:errorPtr]; } - (instancetype)initWithMessage:(GPBMessage *)message @@ -185,7 +200,9 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { error:(NSError **)errorPtr { self = [self init]; if (self) { - if (![self packWithMessage:message typeURLPrefix:typeURLPrefix error:errorPtr]) { + if (![self packWithMessage:message + typeURLPrefix:typeURLPrefix + error:errorPtr]) { [self release]; self = nil; } @@ -193,8 +210,11 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { return self; } -- (BOOL)packWithMessage:(GPBMessage *)message error:(NSError **)errorPtr { - return [self packWithMessage:message typeURLPrefix:kTypePrefixGoogleApisCom error:errorPtr]; +- (BOOL)packWithMessage:(GPBMessage *)message + error:(NSError **)errorPtr { + return [self packWithMessage:message + typeURLPrefix:kTypePrefixGoogleApisCom + error:errorPtr]; } - (BOOL)packWithMessage:(GPBMessage *)message @@ -203,9 +223,10 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { NSString *fullName = [message descriptor].fullName; if (fullName.length == 0) { if (errorPtr) { - *errorPtr = [NSError errorWithDomain:GPBWellKnownTypesErrorDomain - code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL - userInfo:nil]; + *errorPtr = + [NSError errorWithDomain:GPBWellKnownTypesErrorDomain + code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL + userInfo:nil]; } return NO; } @@ -217,13 +238,15 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { return YES; } -- (GPBMessage *)unpackMessageClass:(Class)messageClass error:(NSError **)errorPtr { +- (GPBMessage *)unpackMessageClass:(Class)messageClass + error:(NSError **)errorPtr { NSString *fullName = [messageClass descriptor].fullName; if (fullName.length == 0) { if (errorPtr) { - *errorPtr = [NSError errorWithDomain:GPBWellKnownTypesErrorDomain - code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL - userInfo:nil]; + *errorPtr = + [NSError errorWithDomain:GPBWellKnownTypesErrorDomain + code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL + userInfo:nil]; } return nil; } @@ -231,9 +254,10 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { NSString *expectedFullName = ParseTypeFromURL(self.typeURL); if ((expectedFullName == nil) || ![expectedFullName isEqual:fullName]) { if (errorPtr) { - *errorPtr = [NSError errorWithDomain:GPBWellKnownTypesErrorDomain - code:GPBWellKnownTypesErrorCodeTypeURLMismatch - userInfo:nil]; + *errorPtr = + [NSError errorWithDomain:GPBWellKnownTypesErrorDomain + code:GPBWellKnownTypesErrorCodeTypeURLMismatch + userInfo:nil]; } return nil; } @@ -241,7 +265,8 @@ static NSString *ParseTypeFromURL(NSString *typeURLString) { // Any is proto3, which means no extensions, so this assumes anything put // within an any also won't need extensions. A second helper could be added // if needed. - return [messageClass parseFromData:self.value error:errorPtr]; + return [messageClass parseFromData:self.value + error:errorPtr]; } @end diff --git a/libs/protobuf/objectivec/GPBWrappers.pbobjc.h b/libs/protobuf/objectivec/GPBWrappers.pbobjc.h index 94e69ad..e6741ae 100644 --- a/libs/protobuf/objectivec/GPBWrappers.pbobjc.h +++ b/libs/protobuf/objectivec/GPBWrappers.pbobjc.h @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/wrappers.proto #import "GPBDescriptor.h" @@ -206,5 +205,3 @@ CF_EXTERN_C_END #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clange-format on diff --git a/libs/protobuf/objectivec/GPBWrappers.pbobjc.m b/libs/protobuf/objectivec/GPBWrappers.pbobjc.m index 879579c..b02a071 100644 --- a/libs/protobuf/objectivec/GPBWrappers.pbobjc.m +++ b/libs/protobuf/objectivec/GPBWrappers.pbobjc.m @@ -1,5 +1,4 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! -// clang-format off // source: google/protobuf/wrappers.proto #import "GPBProtocolBuffers_RuntimeSupport.h" @@ -442,5 +441,3 @@ typedef struct GPBBytesValue__storage_ { #pragma clang diagnostic pop // @@protoc_insertion_point(global_scope) - -// clang-format on diff --git a/libs/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/libs/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj index 5f3ffa0..365fdc3 100644 --- a/libs/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj +++ b/libs/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 47; objects = { /* Begin PBXBuildFile section */ @@ -26,7 +26,7 @@ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; }; 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; }; - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */; }; + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; }; 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; }; 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; }; 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; }; @@ -61,6 +61,8 @@ F40EE4BF206BF8B90071091A /* GPBCompileTest21.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE486206BF8AF0071091A /* GPBCompileTest21.m */; }; F40EE4C0206BF8B90071091A /* GPBCompileTest22.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE48A206BF8B00071091A /* GPBCompileTest22.m */; }; F40EE4C1206BF8B90071091A /* GPBCompileTest23.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE487206BF8B00071091A /* GPBCompileTest23.m */; }; + F40EE50B206C06640071091A /* GPBCompileTest24.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE508206C06440071091A /* GPBCompileTest24.m */; }; + F40EE50C206C06640071091A /* GPBCompileTest25.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE507206C06440071091A /* GPBCompileTest25.m */; }; F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; }; F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */; }; F4353D231ABB1537005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D211ABB1537005A6198 /* GPBDictionary.m */; }; @@ -139,7 +141,7 @@ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = ""; }; 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; }; 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = ""; }; - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStreamTests.m; sourceTree = ""; }; + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = ""; }; 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = ""; }; 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = ""; }; 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = ""; }; @@ -159,11 +161,21 @@ 8B42494D1A92A16600BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = ""; }; 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = ""; }; 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = ""; }; + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = ""; }; + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = ""; }; + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = ""; }; + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = ""; }; + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = ""; }; + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = ""; }; 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = ""; }; 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = ""; }; 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = ""; }; + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = ""; }; 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = ""; }; + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = ""; }; 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = ""; }; 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = ""; }; 8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = ""; }; @@ -193,6 +205,8 @@ F40EE491206BF8B10071091A /* GPBCompileTest03.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest03.m; sourceTree = ""; }; F40EE492206BF8B10071091A /* GPBCompileTest06.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest06.m; sourceTree = ""; }; F40EE493206BF8B20071091A /* GPBCompileTest11.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest11.m; sourceTree = ""; }; + F40EE507206C06440071091A /* GPBCompileTest25.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest25.m; sourceTree = ""; }; + F40EE508206C06440071091A /* GPBCompileTest24.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest24.m; sourceTree = ""; }; F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = ""; }; F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = ""; }; F4353D201ABB1537005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = ""; }; @@ -215,23 +229,6 @@ F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = ""; }; F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = ""; }; F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = ""; }; - F44FEABE28B5465900EC57B3 /* unittest_deprecated_file.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated_file.proto; sourceTree = ""; }; - F44FEABF28B5465900EC57B3 /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_mset.proto; sourceTree = ""; }; - F44FEAC028B5465900EC57B3 /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import.proto; sourceTree = ""; }; - F44FEAC228B5465900EC57B3 /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest.proto; sourceTree = ""; }; - F44FEAC428B5465900EC57B3 /* unittest_preserve_unknown_enum.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_preserve_unknown_enum.proto; sourceTree = ""; }; - F44FEAC528B5465900EC57B3 /* any_test.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = any_test.proto; sourceTree = ""; }; - F44FEAC628B5465900EC57B3 /* unittest_import_public.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import_public.proto; sourceTree = ""; }; - F44FEAC728B5465900EC57B3 /* map_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_unittest.proto; sourceTree = ""; }; - F44FEAC828B5465900EC57B3 /* unittest_extension_chain_g.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_g.proto; sourceTree = ""; }; - F44FEAC928B5465900EC57B3 /* unittest_extension_chain_e.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_e.proto; sourceTree = ""; }; - F44FEACA28B5465900EC57B3 /* unittest_extension_chain_d.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_d.proto; sourceTree = ""; }; - F44FEACB28B5465900EC57B3 /* unittest_extension_chain_a.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_a.proto; sourceTree = ""; }; - F44FEACC28B5465900EC57B3 /* unittest_extension_chain_c.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_c.proto; sourceTree = ""; }; - F44FEACD28B5465900EC57B3 /* unittest_deprecated.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated.proto; sourceTree = ""; }; - F44FEACE28B5465A00EC57B3 /* unittest_extension_chain_b.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_b.proto; sourceTree = ""; }; - F44FEACF28B5465A00EC57B3 /* map_proto2_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_proto2_unittest.proto; sourceTree = ""; }; - F44FEAD028B5465A00EC57B3 /* unittest_extension_chain_f.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_f.proto; sourceTree = ""; }; F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = ""; }; F4584D7E1ECCB38900803AB6 /* GPBExtensionRegistryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionRegistryTest.m; sourceTree = ""; }; F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = ""; }; @@ -445,13 +442,12 @@ 7461B6940F94FDDD00A0C422 /* Tests */ = { isa = PBXGroup; children = ( - F44FEAC528B5465900EC57B3 /* any_test.proto */, 8B210CCD159383D60032D72D /* golden_message */, 8B210CCF159386920032D72D /* golden_packed_fields_message */, 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */, F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */, 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */, - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */, + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */, F40EE488206BF8B00071091A /* GPBCompileTest01.m */, F40EE481206BF8AE0071091A /* GPBCompileTest02.m */, F40EE491206BF8B10071091A /* GPBCompileTest03.m */, @@ -475,6 +471,8 @@ F40EE486206BF8AF0071091A /* GPBCompileTest21.m */, F40EE48A206BF8B00071091A /* GPBCompileTest22.m */, F40EE487206BF8B00071091A /* GPBCompileTest23.m */, + F40EE508206C06440071091A /* GPBCompileTest24.m */, + F40EE507206C06440071091A /* GPBCompileTest25.m */, 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */, F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */, F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */, @@ -487,9 +485,9 @@ F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */, F4584D7E1ECCB38900803AB6 /* GPBExtensionRegistryTest.m */, 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */, - 8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */, F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */, F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */, + 8BFF9D1923AD582200E63E32 /* GPBMessageTests+ClassNames.m */, F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */, F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */, F41C175C1833D3310064ED4D /* GPBPerfTests.m */, @@ -502,31 +500,25 @@ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */, 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */, 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */, - F44FEACF28B5465A00EC57B3 /* map_proto2_unittest.proto */, - F44FEAC728B5465900EC57B3 /* map_unittest.proto */, F4F53F89219CC4F2001EABF4 /* text_format_extensions_unittest_data.txt */, F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */, F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */, + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */, F4AC9E1D1A8BEB3500BD6E83 /* unittest_cycle.proto */, - F44FEABE28B5465900EC57B3 /* unittest_deprecated_file.proto */, - F44FEACD28B5465900EC57B3 /* unittest_deprecated.proto */, - F44FEACB28B5465900EC57B3 /* unittest_extension_chain_a.proto */, - F44FEACE28B5465A00EC57B3 /* unittest_extension_chain_b.proto */, - F44FEACC28B5465900EC57B3 /* unittest_extension_chain_c.proto */, - F44FEACA28B5465900EC57B3 /* unittest_extension_chain_d.proto */, - F44FEAC928B5465900EC57B3 /* unittest_extension_chain_e.proto */, - F44FEAD028B5465A00EC57B3 /* unittest_extension_chain_f.proto */, - F44FEAC828B5465900EC57B3 /* unittest_extension_chain_g.proto */, - F44FEAC628B5465900EC57B3 /* unittest_import_public.proto */, - F44FEAC028B5465900EC57B3 /* unittest_import.proto */, - F44FEABF28B5465900EC57B3 /* unittest_mset.proto */, + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */, + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */, + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */, + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */, + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */, + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */, + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */, 8B35468421A616F6000BD30D /* unittest_objc_options.proto */, F4CF31701B162ED800BD9B06 /* unittest_objc_startup.proto */, 8B09AAF614B663A7007B4184 /* unittest_objc.proto */, - F44FEAC428B5465900EC57B3 /* unittest_preserve_unknown_enum.proto */, + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */, F4487C781AADFB3100531423 /* unittest_runtime_proto2.proto */, F4487C791AADFB3200531423 /* unittest_runtime_proto3.proto */, - F44FEAC228B5465900EC57B3 /* unittest.proto */, + 8B7E6A7E14893DBC00F8884A /* unittest.proto */, 8B4248B91A8C256900BC1EC6 /* UnitTests-Bridging-Header.h */, 7401C1A90F950347006D8281 /* UnitTests-Info.plist */, ); @@ -663,7 +655,7 @@ }; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_OSX" */; - compatibilityVersion = "Xcode 13.0"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -752,6 +744,7 @@ buildActionMask = 2147483647; files = ( 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */, + F40EE50B206C06640071091A /* GPBCompileTest24.m in Sources */, F40EE4BE206BF8B90071091A /* GPBCompileTest20.m in Sources */, F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */, F40EE4B4206BF8B90071091A /* GPBCompileTest10.m in Sources */, @@ -760,7 +753,7 @@ F40EE4B2206BF8B90071091A /* GPBCompileTest08.m in Sources */, F40EE4BB206BF8B90071091A /* GPBCompileTest17.m in Sources */, F4353D391AC06F10005A6198 /* GPBDictionaryTests+UInt64.m in Sources */, - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */, + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */, F40EE4C1206BF8B90071091A /* GPBCompileTest23.m in Sources */, 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */, F4B51B1E1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */, @@ -779,6 +772,7 @@ F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */, F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */, 8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */, + F40EE50C206C06640071091A /* GPBCompileTest25.m in Sources */, F4584D821ECCB52A00803AB6 /* GPBExtensionRegistryTest.m in Sources */, 8BFF9D1A23AD582300E63E32 /* GPBMessageTests+ClassNames.m in Sources */, 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */, @@ -857,21 +851,14 @@ CLANG_ENABLE_OBJC_WEAK = YES; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = UnitTests; SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -888,20 +875,13 @@ CLANG_ENABLE_OBJC_WEAK = YES; COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - "@loader_path/../Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}"; PRODUCT_NAME = UnitTests; SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h"; SWIFT_VERSION = 4.0; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -966,7 +946,7 @@ GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; GENERATE_PROFILING_CODE = NO; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; @@ -1035,11 +1015,10 @@ GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; GENERATE_PROFILING_CODE = NO; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.9; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; USE_HEADERMAP = NO; WARNING_CFLAGS = ( "-Wdocumentation-unknown-command", diff --git a/libs/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/libs/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj index 4b4f083..03e0580 100644 --- a/libs/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj +++ b/libs/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 47; objects = { /* Begin PBXBuildFile section */ @@ -27,7 +27,7 @@ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; }; 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; }; 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; }; - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */; }; + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; }; 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; }; 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; }; 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; }; @@ -61,6 +61,8 @@ F40EE504206BF91E0071091A /* GPBCompileTest21.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CB206BF9170071091A /* GPBCompileTest21.m */; }; F40EE505206BF91E0071091A /* GPBCompileTest22.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CF206BF9170071091A /* GPBCompileTest22.m */; }; F40EE506206BF91E0071091A /* GPBCompileTest23.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CC206BF9170071091A /* GPBCompileTest23.m */; }; + F40EE511206C068D0071091A /* GPBCompileTest24.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE50E206C06880071091A /* GPBCompileTest24.m */; }; + F40EE512206C068D0071091A /* GPBCompileTest25.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE50D206C06880071091A /* GPBCompileTest25.m */; }; F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; }; F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */; }; F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D251ABB156F005A6198 /* GPBDictionary.m */; }; @@ -140,7 +142,7 @@ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = ""; }; 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; }; 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = ""; }; - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStreamTests.m; sourceTree = ""; }; + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = ""; }; 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = ""; }; 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = ""; }; 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = ""; }; @@ -160,13 +162,23 @@ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = ""; }; 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = ""; }; 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = ""; }; + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = ""; }; + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = ""; }; + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = ""; }; + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = ""; }; + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = ""; }; + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = ""; }; 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = ""; }; 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = ""; }; 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = ""; }; 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 8B9A5E9F1831913D00A9D33B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = ""; }; 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = ""; }; + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = ""; }; 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = ""; }; 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = ""; }; 8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = ""; }; @@ -194,6 +206,8 @@ F40EE4D6206BF9190071091A /* GPBCompileTest03.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest03.m; sourceTree = ""; }; F40EE4D7206BF9190071091A /* GPBCompileTest06.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest06.m; sourceTree = ""; }; F40EE4D8206BF9190071091A /* GPBCompileTest11.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest11.m; sourceTree = ""; }; + F40EE50D206C06880071091A /* GPBCompileTest25.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest25.m; sourceTree = ""; }; + F40EE50E206C06880071091A /* GPBCompileTest24.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest24.m; sourceTree = ""; }; F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = ""; }; F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = ""; }; F4353D241ABB156F005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = ""; }; @@ -218,23 +232,6 @@ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = ""; }; F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = ""; }; F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = ""; }; - F44FEAD128B546E200EC57B3 /* unittest_preserve_unknown_enum.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_preserve_unknown_enum.proto; sourceTree = ""; }; - F44FEAD228B546E200EC57B3 /* map_proto2_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_proto2_unittest.proto; sourceTree = ""; }; - F44FEAD328B546E200EC57B3 /* map_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_unittest.proto; sourceTree = ""; }; - F44FEAD428B546E200EC57B3 /* unittest_extension_chain_a.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_a.proto; sourceTree = ""; }; - F44FEAD528B546E300EC57B3 /* unittest_extension_chain_d.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_d.proto; sourceTree = ""; }; - F44FEAD628B546E300EC57B3 /* unittest_deprecated.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated.proto; sourceTree = ""; }; - F44FEAD728B546E300EC57B3 /* any_test.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = any_test.proto; sourceTree = ""; }; - F44FEAD828B546E300EC57B3 /* unittest_extension_chain_b.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_b.proto; sourceTree = ""; }; - F44FEADB28B546E300EC57B3 /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import.proto; sourceTree = ""; }; - F44FEADC28B546E300EC57B3 /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_mset.proto; sourceTree = ""; }; - F44FEADD28B546E300EC57B3 /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest.proto; sourceTree = ""; }; - F44FEADE28B546E300EC57B3 /* unittest_extension_chain_f.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_f.proto; sourceTree = ""; }; - F44FEADF28B546E300EC57B3 /* unittest_deprecated_file.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated_file.proto; sourceTree = ""; }; - F44FEAE028B546E300EC57B3 /* unittest_import_public.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import_public.proto; sourceTree = ""; }; - F44FEAE128B546E300EC57B3 /* unittest_extension_chain_g.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_g.proto; sourceTree = ""; }; - F44FEAE228B546E300EC57B3 /* unittest_extension_chain_c.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_c.proto; sourceTree = ""; }; - F44FEAE328B546E300EC57B3 /* unittest_extension_chain_e.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_e.proto; sourceTree = ""; }; F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = ""; }; F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPBExtensionRegistryTest.m; path = Tests/GPBExtensionRegistryTest.m; sourceTree = SOURCE_ROOT; }; F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = ""; }; @@ -451,13 +448,12 @@ 7461B6940F94FDDD00A0C422 /* Tests */ = { isa = PBXGroup; children = ( - F44FEAD728B546E300EC57B3 /* any_test.proto */, 8B210CCD159383D60032D72D /* golden_message */, 8B210CCF159386920032D72D /* golden_packed_fields_message */, 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */, F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */, 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */, - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */, + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */, F40EE4CD206BF9170071091A /* GPBCompileTest01.m */, F40EE4C6206BF9170071091A /* GPBCompileTest02.m */, F40EE4D6206BF9190071091A /* GPBCompileTest03.m */, @@ -481,6 +477,8 @@ F40EE4CB206BF9170071091A /* GPBCompileTest21.m */, F40EE4CF206BF9170071091A /* GPBCompileTest22.m */, F40EE4CC206BF9170071091A /* GPBCompileTest23.m */, + F40EE50E206C06880071091A /* GPBCompileTest24.m */, + F40EE50D206C06880071091A /* GPBCompileTest25.m */, 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */, F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */, F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */, @@ -493,9 +491,9 @@ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */, F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */, 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */, - 8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */, F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */, F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */, + 8BFF9D1B23AD593B00E63E32 /* GPBMessageTests+ClassNames.m */, F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */, F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */, F41C175C1833D3310064ED4D /* GPBPerfTests.m */, @@ -508,31 +506,25 @@ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */, 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */, 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */, - F44FEAD228B546E200EC57B3 /* map_proto2_unittest.proto */, - F44FEAD328B546E200EC57B3 /* map_unittest.proto */, F4F53F8B219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt */, F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */, F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */, + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */, F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */, - F44FEADF28B546E300EC57B3 /* unittest_deprecated_file.proto */, - F44FEAD628B546E300EC57B3 /* unittest_deprecated.proto */, - F44FEAD428B546E200EC57B3 /* unittest_extension_chain_a.proto */, - F44FEAD828B546E300EC57B3 /* unittest_extension_chain_b.proto */, - F44FEAE228B546E300EC57B3 /* unittest_extension_chain_c.proto */, - F44FEAD528B546E300EC57B3 /* unittest_extension_chain_d.proto */, - F44FEAE328B546E300EC57B3 /* unittest_extension_chain_e.proto */, - F44FEADE28B546E300EC57B3 /* unittest_extension_chain_f.proto */, - F44FEAE128B546E300EC57B3 /* unittest_extension_chain_g.proto */, - F44FEAE028B546E300EC57B3 /* unittest_import_public.proto */, - F44FEADB28B546E300EC57B3 /* unittest_import.proto */, - F44FEADC28B546E300EC57B3 /* unittest_mset.proto */, + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */, + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */, + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */, + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */, + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */, + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */, + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */, 8B35468621A61EB2000BD30D /* unittest_objc_options.proto */, F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */, 8B09AAF614B663A7007B4184 /* unittest_objc.proto */, - F44FEAD128B546E200EC57B3 /* unittest_preserve_unknown_enum.proto */, + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */, F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */, F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */, - F44FEADD28B546E300EC57B3 /* unittest.proto */, + 8B7E6A7E14893DBC00F8884A /* unittest.proto */, 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */, 7401C1A90F950347006D8281 /* UnitTests-Info.plist */, ); @@ -670,7 +662,7 @@ }; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_iOS" */; - compatibilityVersion = "Xcode 13.0"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -759,6 +751,7 @@ buildActionMask = 2147483647; files = ( 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */, + F40EE511206C068D0071091A /* GPBCompileTest24.m in Sources */, F40EE503206BF91E0071091A /* GPBCompileTest20.m in Sources */, F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */, F40EE4F9206BF91E0071091A /* GPBCompileTest10.m in Sources */, @@ -767,7 +760,7 @@ F40EE4F7206BF91E0071091A /* GPBCompileTest08.m in Sources */, F40EE500206BF91E0071091A /* GPBCompileTest17.m in Sources */, F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */, - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */, + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */, F40EE506206BF91E0071091A /* GPBCompileTest23.m in Sources */, 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */, F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */, @@ -786,6 +779,7 @@ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */, F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */, 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */, + F40EE512206C068D0071091A /* GPBCompileTest25.m in Sources */, F4584D831ECCB53600803AB6 /* GPBExtensionRegistryTest.m in Sources */, 8BFF9D1C23AD593C00E63E32 /* GPBMessageTests+ClassNames.m in Sources */, 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */, @@ -869,11 +863,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/usr/lib\"", @@ -884,10 +874,7 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -907,11 +894,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/usr/lib\"", @@ -921,10 +904,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h"; SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = "1,2"; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -990,7 +970,7 @@ GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; GENERATE_PROFILING_CODE = NO; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; @@ -1059,11 +1039,10 @@ GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; GENERATE_PROFILING_CODE = NO; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; WARNING_CFLAGS = ( "-Wdocumentation-unknown-command", "-Wundef", diff --git a/libs/protobuf/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj b/libs/protobuf/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj index 3b535ba..c7a8d85 100644 --- a/libs/protobuf/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj +++ b/libs/protobuf/objectivec/ProtocolBuffers_tvOS.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 55; + objectVersion = 47; objects = { /* Begin PBXBuildFile section */ @@ -27,7 +27,7 @@ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; }; 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; }; 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; }; - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */; }; + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; }; 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; }; 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; }; 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; }; @@ -61,6 +61,8 @@ F40EE504206BF91E0071091A /* GPBCompileTest21.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CB206BF9170071091A /* GPBCompileTest21.m */; }; F40EE505206BF91E0071091A /* GPBCompileTest22.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CF206BF9170071091A /* GPBCompileTest22.m */; }; F40EE506206BF91E0071091A /* GPBCompileTest23.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE4CC206BF9170071091A /* GPBCompileTest23.m */; }; + F40EE511206C068D0071091A /* GPBCompileTest24.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE50E206C06880071091A /* GPBCompileTest24.m */; }; + F40EE512206C068D0071091A /* GPBCompileTest25.m in Sources */ = {isa = PBXBuildFile; fileRef = F40EE50D206C06880071091A /* GPBCompileTest25.m */; }; F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; }; F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */; }; F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D251ABB156F005A6198 /* GPBDictionary.m */; }; @@ -140,7 +142,7 @@ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = ""; }; 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; }; 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = ""; }; - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStreamTests.m; sourceTree = ""; }; + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = ""; }; 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = ""; }; 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = ""; }; 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = ""; }; @@ -160,13 +162,23 @@ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = ""; }; 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = ""; }; 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = ""; }; + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = ""; }; + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = ""; }; + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = ""; }; + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = ""; }; + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = ""; }; + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = ""; }; + 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = ""; }; 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = ""; }; 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = ""; }; 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = ""; }; 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 8B9A5E9F1831913D00A9D33B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = ""; }; 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = ""; }; + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = ""; }; 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = ""; }; 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = ""; }; 8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+ClassNames.m"; sourceTree = ""; }; @@ -194,6 +206,8 @@ F40EE4D6206BF9190071091A /* GPBCompileTest03.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest03.m; sourceTree = ""; }; F40EE4D7206BF9190071091A /* GPBCompileTest06.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest06.m; sourceTree = ""; }; F40EE4D8206BF9190071091A /* GPBCompileTest11.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest11.m; sourceTree = ""; }; + F40EE50D206C06880071091A /* GPBCompileTest25.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest25.m; sourceTree = ""; }; + F40EE50E206C06880071091A /* GPBCompileTest24.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCompileTest24.m; sourceTree = ""; }; F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = ""; }; F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = ""; }; F4353D241ABB156F005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = ""; }; @@ -218,23 +232,6 @@ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = ""; }; F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = ""; }; F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = ""; }; - F44FEAE528B5471300EC57B3 /* unittest_extension_chain_a.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_a.proto; sourceTree = ""; }; - F44FEAE728B5471300EC57B3 /* unittest_extension_chain_c.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_c.proto; sourceTree = ""; }; - F44FEAE828B5471300EC57B3 /* unittest_extension_chain_g.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_g.proto; sourceTree = ""; }; - F44FEAE928B5471300EC57B3 /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import.proto; sourceTree = ""; }; - F44FEAEA28B5471300EC57B3 /* unittest_deprecated_file.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated_file.proto; sourceTree = ""; }; - F44FEAEB28B5471300EC57B3 /* unittest_import_public.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_import_public.proto; sourceTree = ""; }; - F44FEAEC28B5471300EC57B3 /* unittest_extension_chain_f.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_f.proto; sourceTree = ""; }; - F44FEAED28B5471300EC57B3 /* unittest_deprecated.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_deprecated.proto; sourceTree = ""; }; - F44FEAEE28B5471300EC57B3 /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest.proto; sourceTree = ""; }; - F44FEAEF28B5471300EC57B3 /* any_test.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = any_test.proto; sourceTree = ""; }; - F44FEAF028B5471300EC57B3 /* unittest_extension_chain_b.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_b.proto; sourceTree = ""; }; - F44FEAF128B5471300EC57B3 /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_mset.proto; sourceTree = ""; }; - F44FEAF228B5471300EC57B3 /* unittest_preserve_unknown_enum.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_preserve_unknown_enum.proto; sourceTree = ""; }; - F44FEAF328B5471300EC57B3 /* unittest_extension_chain_d.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_d.proto; sourceTree = ""; }; - F44FEAF428B5471300EC57B3 /* unittest_extension_chain_e.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = unittest_extension_chain_e.proto; sourceTree = ""; }; - F44FEAF528B5472700EC57B3 /* map_proto2_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_proto2_unittest.proto; sourceTree = ""; }; - F44FEAF628B5472700EC57B3 /* map_unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = map_unittest.proto; sourceTree = ""; }; F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = ""; }; F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GPBExtensionRegistryTest.m; path = Tests/GPBExtensionRegistryTest.m; sourceTree = SOURCE_ROOT; }; F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = ""; }; @@ -451,13 +448,12 @@ 7461B6940F94FDDD00A0C422 /* Tests */ = { isa = PBXGroup; children = ( - F44FEAEF28B5471300EC57B3 /* any_test.proto */, 8B210CCD159383D60032D72D /* golden_message */, 8B210CCF159386920032D72D /* golden_packed_fields_message */, 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */, F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */, 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */, - 7461B69D0F94FDF800A0C422 /* GPBCodedOutputStreamTests.m */, + 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */, F40EE4CD206BF9170071091A /* GPBCompileTest01.m */, F40EE4C6206BF9170071091A /* GPBCompileTest02.m */, F40EE4D6206BF9190071091A /* GPBCompileTest03.m */, @@ -481,6 +477,8 @@ F40EE4CB206BF9170071091A /* GPBCompileTest21.m */, F40EE4CF206BF9170071091A /* GPBCompileTest22.m */, F40EE4CC206BF9170071091A /* GPBCompileTest23.m */, + F40EE50E206C06880071091A /* GPBCompileTest24.m */, + F40EE50D206C06880071091A /* GPBCompileTest25.m */, 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */, F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */, F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */, @@ -493,9 +491,9 @@ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */, F4584D801ECCB39E00803AB6 /* GPBExtensionRegistryTest.m */, 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */, - 8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */, F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */, F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */, + 8BFF9D1D23AD599400E63E32 /* GPBMessageTests+ClassNames.m */, F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */, F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */, F41C175C1833D3310064ED4D /* GPBPerfTests.m */, @@ -508,31 +506,25 @@ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */, 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */, 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */, - F44FEAF528B5472700EC57B3 /* map_proto2_unittest.proto */, - F44FEAF628B5472700EC57B3 /* map_unittest.proto */, F4F53F8B219CC5DF001EABF4 /* text_format_extensions_unittest_data.txt */, F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */, F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */, + 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */, F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */, - F44FEAEA28B5471300EC57B3 /* unittest_deprecated_file.proto */, - F44FEAED28B5471300EC57B3 /* unittest_deprecated.proto */, - F44FEAE528B5471300EC57B3 /* unittest_extension_chain_a.proto */, - F44FEAF028B5471300EC57B3 /* unittest_extension_chain_b.proto */, - F44FEAE728B5471300EC57B3 /* unittest_extension_chain_c.proto */, - F44FEAF328B5471300EC57B3 /* unittest_extension_chain_d.proto */, - F44FEAF428B5471300EC57B3 /* unittest_extension_chain_e.proto */, - F44FEAEC28B5471300EC57B3 /* unittest_extension_chain_f.proto */, - F44FEAE828B5471300EC57B3 /* unittest_extension_chain_g.proto */, - F44FEAEB28B5471300EC57B3 /* unittest_import_public.proto */, - F44FEAE928B5471300EC57B3 /* unittest_import.proto */, - F44FEAF128B5471300EC57B3 /* unittest_mset.proto */, + 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */, + 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */, + 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */, + 8B7E6A7814893DBB00F8884A /* unittest_import.proto */, + 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */, + 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */, + 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */, 8B35468621A61EB2000BD30D /* unittest_objc_options.proto */, F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */, 8B09AAF614B663A7007B4184 /* unittest_objc.proto */, - F44FEAF228B5471300EC57B3 /* unittest_preserve_unknown_enum.proto */, + 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */, F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */, F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */, - F44FEAEE28B5471300EC57B3 /* unittest.proto */, + 8B7E6A7E14893DBC00F8884A /* unittest.proto */, 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */, 7401C1A90F950347006D8281 /* UnitTests-Info.plist */, ); @@ -670,7 +662,7 @@ }; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_tvOS" */; - compatibilityVersion = "Xcode 13.0"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -759,6 +751,7 @@ buildActionMask = 2147483647; files = ( 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */, + F40EE511206C068D0071091A /* GPBCompileTest24.m in Sources */, F40EE503206BF91E0071091A /* GPBCompileTest20.m in Sources */, F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */, F40EE4F9206BF91E0071091A /* GPBCompileTest10.m in Sources */, @@ -767,7 +760,7 @@ F40EE4F7206BF91E0071091A /* GPBCompileTest08.m in Sources */, F40EE500206BF91E0071091A /* GPBCompileTest17.m in Sources */, F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */, - 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOutputStreamTests.m in Sources */, + 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */, F40EE506206BF91E0071091A /* GPBCompileTest23.m in Sources */, 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */, F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */, @@ -786,6 +779,7 @@ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */, F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */, 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */, + F40EE512206C068D0071091A /* GPBCompileTest25.m in Sources */, F4584D831ECCB53600803AB6 /* GPBExtensionRegistryTest.m in Sources */, 8BFF9D1E23AD599400E63E32 /* GPBMessageTests+ClassNames.m in Sources */, 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */, @@ -865,11 +859,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/usr/lib\"", @@ -879,10 +869,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.0; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -902,11 +889,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/UnitTests-Info.plist"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", "\"$(DEVELOPER_DIR)/usr/lib\"", @@ -915,10 +898,7 @@ PRODUCT_NAME = UnitTests; SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h"; SWIFT_VERSION = 4.0; - USER_HEADER_SEARCH_PATHS = ( - "${PROJECT_DERIVED_FILE_DIR}/protos", - "$(SRCROOT)", - ); + USER_HEADER_SEARCH_PATHS = "${PROJECT_DERIVED_FILE_DIR}/protos $(SRCROOT)"; WARNING_CFLAGS = ( "$(inherited)", "-Wno-documentation-unknown-command", @@ -987,7 +967,7 @@ ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = appletvos; - TVOS_DEPLOYMENT_TARGET = 12.0; + TVOS_DEPLOYMENT_TARGET = 9.0; WARNING_CFLAGS = ( "-Wdocumentation-unknown-command", "-Wundef", @@ -1055,9 +1035,8 @@ GENERATE_PROFILING_CODE = NO; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = appletvos; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - TVOS_DEPLOYMENT_TARGET = 12.0; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + TVOS_DEPLOYMENT_TARGET = 9.0; WARNING_CFLAGS = ( "-Wdocumentation-unknown-command", "-Wundef", diff --git a/libs/protobuf/objectivec/README.md b/libs/protobuf/objectivec/README.md index 95f561c..a0fcd19 100644 --- a/libs/protobuf/objectivec/README.md +++ b/libs/protobuf/objectivec/README.md @@ -11,7 +11,7 @@ Requirements The Objective C implementation requires: - Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X). -- Xcode 13.3.1 (or later). +- Xcode 10.3 (or later). - The library code does *not* use ARC (for performance reasons), but it all can be called from ARC code. @@ -25,7 +25,7 @@ to build the compiler and run the runtime tests, you can use: $ objectivec/DevTools/full_mac_build.sh -This will generate the `protoc` binary. +This will generate the `src/protoc` binary. Building -------- @@ -200,13 +200,12 @@ supported keys are: entry can be made as "no_package:PATH=prefix", where PATH is the path for the .proto file. - * `use_package_as_prefix`, `package_as_prefix_forced_prefix` and - `proto_package_prefix_exceptions_path`: The `value` for - `use_package_as_prefix` can be `yes` or `no`, and indicates if a prefix - should be derived from the proto package for all the symbols for files that - don't have the `objc_class_prefix` file option (mentioned above). This helps - ensure the symbols are more unique and means there is less chance of ObjC - class name collisions. + * `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The + `value` for `use_package_as_prefix` can be `yes` or `no`, and indicates + if a prefix should be derived from the proto package for all the symbols + for files that don't have the `objc_class_prefix` file option (mentioned + above). This helps ensure the symbols are more unique and means there is + less chance of ObjC class name collisions. To help in migrating code to using this support, `proto_package_prefix_exceptions_path` can be used to provide the path @@ -214,16 +213,10 @@ supported keys are: if prefixed with `#`). These package won't get the derived prefix, allowing migrations to the behavior one proto package at a time across a code base. - `package_as_prefix_forced_prefix` can be used to provide a value that will - be used before all prefixes derived from the packages to help group all of - these types with a common prefix. Thus it only makes sense to use it when - `use_package_as_prefix` is also enabled. For example, setting this to - "XYZ\_" and generating a file with the package "something" defining - "MyMessage", would have Objective-C class be `XYZ_Something_MyMessage`. - `use_package_as_prefix` currently defaults to `no` (existing behavior), but - that could change in the future as it helps avoid collisions when more - protos get added to the build. Note that this would be a breaking change. + in the future (as a breaking change), that is likely to change since it + helps prepare folks before they end up using a lot of protos and getting a + lot of collisions. * `headers_use_forward_declarations`: The `value` for this can be `yes` or `no`, and indicates if the generated headers use forward declarations for diff --git a/libs/protobuf/objectivec/Tests/GPBARCUnittestProtos.m b/libs/protobuf/objectivec/Tests/GPBARCUnittestProtos.m index fa23692..29f6ccf 100644 --- a/libs/protobuf/objectivec/Tests/GPBARCUnittestProtos.m +++ b/libs/protobuf/objectivec/Tests/GPBARCUnittestProtos.m @@ -34,16 +34,30 @@ // Makes sure all the generated headers compile with ARC on. -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestCycle.pbobjc.h" -#import "objectivec/Tests/UnittestDeprecated.pbobjc.h" -#import "objectivec/Tests/UnittestDeprecatedFile.pbobjc.h" -#import "objectivec/Tests/UnittestImport.pbobjc.h" -#import "objectivec/Tests/UnittestImportPublic.pbobjc.h" -#import "objectivec/Tests/UnittestMset.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" -#import "objectivec/Tests/UnittestObjcOptions.pbobjc.h" -#import "objectivec/Tests/UnittestObjcStartup.pbobjc.h" -#import "objectivec/Tests/UnittestPreserveUnknownEnum.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.h" +// The unittest_custom_options.proto extends the messages in descriptor.proto +// so we build it in to test extending in general. The library doesn't provide +// a descriptor as it doesn't use the classes/enums. +#import "google/protobuf/Descriptor.pbobjc.h" + +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestCustomOptions.pbobjc.h" +#import "google/protobuf/UnittestCycle.pbobjc.h" +#import "google/protobuf/UnittestDeprecated.pbobjc.h" +#import "google/protobuf/UnittestDeprecatedFile.pbobjc.h" +#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h" +#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.h" +#import "google/protobuf/UnittestEmpty.pbobjc.h" +#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.h" +#import "google/protobuf/UnittestImport.pbobjc.h" +#import "google/protobuf/UnittestImportLite.pbobjc.h" +#import "google/protobuf/UnittestImportPublic.pbobjc.h" +#import "google/protobuf/UnittestImportPublicLite.pbobjc.h" +#import "google/protobuf/UnittestLite.pbobjc.h" +#import "google/protobuf/UnittestMset.pbobjc.h" +#import "google/protobuf/UnittestNoGenericServices.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" +#import "google/protobuf/UnittestObjcStartup.pbobjc.h" +#import "google/protobuf/UnittestOptimizeFor.pbobjc.h" +#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" diff --git a/libs/protobuf/objectivec/Tests/GPBArrayTests.m b/libs/protobuf/objectivec/Tests/GPBArrayTests.m index efb512e..9b004bc 100644 --- a/libs/protobuf/objectivec/Tests/GPBArrayTests.m +++ b/libs/protobuf/objectivec/Tests/GPBArrayTests.m @@ -40,7 +40,8 @@ @interface GPBEnumArray (TestingTweak) + (instancetype)arrayWithValue:(int32_t)value; + (instancetype)arrayWithCapacity:(NSUInteger)count; -- (instancetype)initWithValues:(const int32_t[])values count:(NSUInteger)count; +- (instancetype)initWithValues:(const int32_t [])values + count:(NSUInteger)count; @end static BOOL TestingEnum_IsValidValue(int32_t value) { @@ -76,16 +77,16 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { return [[[self alloc] initWithValidationFunction:TestingEnum_IsValidValue capacity:count] autorelease]; } -- (instancetype)initWithValues:(const int32_t[])values count:(NSUInteger)count { - return [self initWithValidationFunction:TestingEnum_IsValidValue rawValues:values count:count]; +- (instancetype)initWithValues:(const int32_t [])values + count:(NSUInteger)count { + return [self initWithValidationFunction:TestingEnum_IsValidValue + rawValues:values + count:count]; } @end #pragma mark - PDDM Macros -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE ARRAY_TESTS(NAME, TYPE, VAL1, VAL2, VAL3, VAL4) //%ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, ) //%PDDM-DEFINE ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, HELPER) @@ -101,11 +102,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { //% XCTAssertNotNil(array); //% XCTAssertEqual(array.count, 0U); //% XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); -//% [array enumerateValuesWithBlock:^(__unused TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { +//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { +//% #pragma unused(value, idx, stop) //% XCTFail(@"Shouldn't get here!"); //% }]; //% [array enumerateValuesWithOptions:NSEnumerationReverse -//% usingBlock:^(__unused TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { +//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { +//% #pragma unused(value, idx, stop) //% XCTFail(@"Shouldn't get here!"); //% }]; //% [array release]; @@ -430,6 +433,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { //% //%PDDM-EXPAND ARRAY_TESTS(Int32, int32_t, 1, 2, 3, 4) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int32 @@ -443,11 +447,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -770,8 +776,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(UInt32, uint32_t, 11U, 12U, 13U, 14U) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt32 @@ -785,11 +793,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused uint32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -1112,8 +1122,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(Int64, int64_t, 31LL, 32LL, 33LL, 34LL) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Int64 @@ -1127,11 +1139,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused int64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -1454,8 +1468,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(UInt64, uint64_t, 41ULL, 42ULL, 43ULL, 44ULL) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - UInt64 @@ -1469,11 +1485,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused uint64_t value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -1796,8 +1814,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(Float, float, 51.f, 52.f, 53.f, 54.f) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Float @@ -1811,11 +1831,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused float value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused float value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(float value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -2138,8 +2160,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(Double, double, 61., 62., 63., 64.) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Double @@ -2153,11 +2177,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused double value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused double value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(double value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -2480,8 +2506,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS(Bool, BOOL, TRUE, TRUE, FALSE, FALSE) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool @@ -2495,11 +2523,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused BOOL value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused BOOL value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -2822,8 +2852,10 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end +// clang-format on //%PDDM-EXPAND ARRAY_TESTS2(Enum, int32_t, 71, 72, 73, 74, Raw) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Enum @@ -2837,11 +2869,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException); - [array enumerateValuesWithBlock:^(__unused int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array enumerateValuesWithOptions:NSEnumerationReverse - usingBlock:^(__unused int32_t value, __unused NSUInteger idx, __unused BOOL *stop) { + usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { + #pragma unused(value, idx, stop) XCTFail(@"Shouldn't get here!"); }]; [array release]; @@ -3164,9 +3198,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @end -//%PDDM-EXPAND-END (8 expansions) - // clang-format on +//%PDDM-EXPAND-END (8 expansions) #pragma mark - Non macro-based Enum tests @@ -3178,13 +3211,15 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { @implementation GPBEnumArrayCustomTests - (void)testRawBasics { - static const int32_t kValues[] = {71, 272, 73, 374}; - static const int32_t kValuesFiltered[] = {71, kGPBUnrecognizedEnumeratorValue, 73, - kGPBUnrecognizedEnumeratorValue}; + static const int32_t kValues[] = { 71, 272, 73, 374 }; + static const int32_t kValuesFiltered[] = { + 71, kGPBUnrecognizedEnumeratorValue, 73, kGPBUnrecognizedEnumeratorValue + }; XCTAssertEqual(GPBARRAYSIZE(kValues), GPBARRAYSIZE(kValuesFiltered)); - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); XCTAssertEqual(array.count, 4U); GPBEnumValidationFunc func = TestingEnum_IsValidValue; @@ -3213,19 +3248,19 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { idx2 = 0; [array enumerateRawValuesWithOptions:NSEnumerationReverse usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { - XCTAssertEqual(idx, (3 - idx2)); - XCTAssertEqual(value, kValues[idx]); - XCTAssertNotEqual(stop, NULL); - ++idx2; - }]; + XCTAssertEqual(idx, (3 - idx2)); + XCTAssertEqual(value, kValues[idx]); + XCTAssertNotEqual(stop, NULL); + ++idx2; + }]; idx2 = 0; [array enumerateValuesWithOptions:NSEnumerationReverse usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { - XCTAssertEqual(idx, (3 - idx2)); - XCTAssertEqual(value, kValuesFiltered[idx]); - XCTAssertNotEqual(stop, NULL); - ++idx2; - }]; + XCTAssertEqual(idx, (3 - idx2)); + XCTAssertEqual(value, kValuesFiltered[idx]); + XCTAssertNotEqual(stop, NULL); + ++idx2; + }]; // Stopping the enumeration. idx2 = 0; [array enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { @@ -3240,35 +3275,38 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { idx2 = 0; [array enumerateRawValuesWithOptions:NSEnumerationReverse usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) { - XCTAssertEqual(idx, (3 - idx2)); - XCTAssertEqual(value, kValues[idx]); - XCTAssertNotEqual(stop, NULL); - if (idx2 == 1) *stop = YES; - XCTAssertNotEqual(idx, 1U); - XCTAssertNotEqual(idx, 0U); - ++idx2; - }]; + XCTAssertEqual(idx, (3 - idx2)); + XCTAssertEqual(value, kValues[idx]); + XCTAssertNotEqual(stop, NULL); + if (idx2 == 1) *stop = YES; + XCTAssertNotEqual(idx, 1U); + XCTAssertNotEqual(idx, 0U); + ++idx2; + }]; [array release]; } - (void)testEquality { - const int32_t kValues1[] = {71, 72, 173}; // With unknown value - const int32_t kValues2[] = {71, 74, 173}; // With unknown value - const int32_t kValues3[] = {71, 72, 173, 74}; // With unknown value - GPBEnumArray *array1 = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues1 - count:GPBARRAYSIZE(kValues1)]; + const int32_t kValues1[] = { 71, 72, 173 }; // With unknown value + const int32_t kValues2[] = { 71, 74, 173 }; // With unknown value + const int32_t kValues3[] = { 71, 72, 173, 74 }; // With unknown value + GPBEnumArray *array1 = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues1 + count:GPBARRAYSIZE(kValues1)]; XCTAssertNotNil(array1); GPBEnumArray *array1prime = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue2 rawValues:kValues1 count:GPBARRAYSIZE(kValues1)]; XCTAssertNotNil(array1prime); - GPBEnumArray *array2 = [[GPBEnumArray alloc] initWithValues:kValues2 - count:GPBARRAYSIZE(kValues2)]; + GPBEnumArray *array2 = + [[GPBEnumArray alloc] initWithValues:kValues2 + count:GPBARRAYSIZE(kValues2)]; XCTAssertNotNil(array2); - GPBEnumArray *array3 = [[GPBEnumArray alloc] initWithValues:kValues3 - count:GPBARRAYSIZE(kValues3)]; + GPBEnumArray *array3 = + [[GPBEnumArray alloc] initWithValues:kValues3 + count:GPBARRAYSIZE(kValues3)]; XCTAssertNotNil(array3); // 1/1Prime should be different objects, but equal. @@ -3291,11 +3329,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { } - (void)testCopy { - const int32_t kValues[] = {71, 72}; - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValues:kValues count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 72 }; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); - [array addRawValue:1000]; // Unknown + [array addRawValue:1000]; // Unknown XCTAssertEqual(array.count, 3U); XCTAssertEqual([array rawValueAtIndex:0], 71); XCTAssertEqual([array rawValueAtIndex:1], 72); @@ -3320,10 +3360,11 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { } - (void)testArrayFromArray { - const int32_t kValues[] = {71, 172, 173, 74}; // Unknowns - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknowns + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); GPBEnumArray *array2 = [GPBEnumArray arrayWithValueArray:array]; @@ -3337,34 +3378,38 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { } - (void)testUnknownAdds { - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue]; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue]; XCTAssertNotNil(array); - XCTAssertThrowsSpecificNamed([array addValue:172], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array addValue:172], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 0U); - const int32_t kValues1[] = {172, 173}; // Unknown - XCTAssertThrowsSpecificNamed([array addValues:kValues1 count:GPBARRAYSIZE(kValues1)], NSException, - NSInvalidArgumentException); + const int32_t kValues1[] = { 172, 173 }; // Unknown + XCTAssertThrowsSpecificNamed([array addValues:kValues1 count:GPBARRAYSIZE(kValues1)], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 0U); [array release]; } - (void)testRawAdds { - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue]; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue]; XCTAssertNotNil(array); XCTAssertEqual(array.count, 0U); [array addRawValue:71]; // Valid XCTAssertEqual(array.count, 1U); - const int32_t kValues1[] = {172, 173}; // Unknown + const int32_t kValues1[] = { 172, 173 }; // Unknown [array addRawValues:kValues1 count:GPBARRAYSIZE(kValues1)]; XCTAssertEqual(array.count, 3U); - const int32_t kValues2[] = {74, 71}; - GPBEnumArray *array2 = [[GPBEnumArray alloc] initWithValues:kValues2 - count:GPBARRAYSIZE(kValues2)]; + const int32_t kValues2[] = { 74, 71 }; + GPBEnumArray *array2 = + [[GPBEnumArray alloc] initWithValues:kValues2 + count:GPBARRAYSIZE(kValues2)]; XCTAssertNotNil(array2); [array addRawValuesFromArray:array2]; XCTAssertEqual(array.count, 5U); @@ -3380,35 +3425,37 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { } - (void)testUnknownInserts { - const int32_t kValues[] = {71, 72, 73}; - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 72, 73 }; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); XCTAssertEqual(array.count, 3U); // First - XCTAssertThrowsSpecificNamed([array insertValue:174 atIndex:0], NSException, - NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array insertValue:174 atIndex:0], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 3U); // Middle - XCTAssertThrowsSpecificNamed([array insertValue:274 atIndex:1], NSException, - NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array insertValue:274 atIndex:1], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 3U); // End - XCTAssertThrowsSpecificNamed([array insertValue:374 atIndex:3], NSException, - NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array insertValue:374 atIndex:3], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 3U); [array release]; } - (void)testRawInsert { - const int32_t kValues[] = {71, 72, 73}; - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 72, 73 }; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); XCTAssertEqual(array.count, 3U); @@ -3425,7 +3472,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertEqual(array.count, 6U); // Too far. - XCTAssertThrowsSpecificNamed([array insertRawValue:74 atIndex:7], NSException, NSRangeException); + XCTAssertThrowsSpecificNamed([array insertRawValue:74 atIndex:7], + NSException, NSRangeException); XCTAssertEqual([array rawValueAtIndex:0], 174); XCTAssertEqual([array valueAtIndex:0], kGPBUnrecognizedEnumeratorValue); @@ -3440,16 +3488,17 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { } - (void)testUnknownInplaceMutation { - const int32_t kValues[] = {71, 72, 73, 74}; - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 72, 73, 74 }; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); - XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:1 withValue:172], NSException, - NSInvalidArgumentException); - XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:3 withValue:274], NSException, - NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:1 withValue:172], + NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:3 withValue:274], + NSException, NSInvalidArgumentException); XCTAssertEqual(array.count, 4U); XCTAssertEqual([array valueAtIndex:0], 71); XCTAssertEqual([array valueAtIndex:1], 72); @@ -3458,11 +3507,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { [array release]; } + - (void)testRawInplaceMutation { - const int32_t kValues[] = {71, 72, 73, 74}; - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue - rawValues:kValues - count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 72, 73, 74 }; + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue + rawValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); [array replaceValueAtIndex:1 withRawValue:172]; // Unknown @@ -3475,14 +3526,16 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertEqual([array rawValueAtIndex:3], 274); XCTAssertEqual([array valueAtIndex:3], kGPBUnrecognizedEnumeratorValue); - XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withRawValue:74], NSException, - NSRangeException); + XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withRawValue:74], + NSException, NSRangeException); [array release]; } - (void)testRawInternalResizing { - const int32_t kValues[] = {71, 172, 173, 74}; // Unknown - GPBEnumArray *array = [[GPBEnumArray alloc] initWithValues:kValues count:GPBARRAYSIZE(kValues)]; + const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknown + GPBEnumArray *array = + [[GPBEnumArray alloc] initWithValues:kValues + count:GPBARRAYSIZE(kValues)]; XCTAssertNotNil(array); // Add/remove to trigger the intneral buffer to grow/shrink. @@ -3558,13 +3611,13 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init]; NSArray *cpy = [array copy]; - XCTAssertTrue(cpy != array); // Ptr compare + XCTAssertTrue(cpy != array); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSArray class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy.count, (NSUInteger)0); NSArray *cpy2 = [array copy]; - XCTAssertTrue(cpy2 != array); // Ptr compare + XCTAssertTrue(cpy2 != array); // Ptr compare // Can't compare cpy and cpy2 because NSArray has a singleton empty // array it uses, so the ptrs are the same. XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]); @@ -3580,14 +3633,14 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init]; NSMutableArray *cpy = [array mutableCopy]; - XCTAssertTrue(cpy != array); // Ptr compare + XCTAssertTrue(cpy != array); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSMutableArray class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy.count, (NSUInteger)0); NSMutableArray *cpy2 = [array mutableCopy]; - XCTAssertTrue(cpy2 != array); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != array); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSMutableArray class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy2.count, (NSUInteger)0); @@ -3603,7 +3656,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { [array addObject:@"bar"]; NSArray *cpy = [array copy]; - XCTAssertTrue(cpy != array); // Ptr compare + XCTAssertTrue(cpy != array); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSArray class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy.count, (NSUInteger)2); @@ -3611,8 +3664,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertEqualObjects(cpy[1], @"bar"); NSArray *cpy2 = [array copy]; - XCTAssertTrue(cpy2 != array); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != array); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy2.count, (NSUInteger)2); @@ -3630,7 +3683,7 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { [array addObject:@"bar"]; NSMutableArray *cpy = [array mutableCopy]; - XCTAssertTrue(cpy != array); // Ptr compare + XCTAssertTrue(cpy != array); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSArray class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy.count, (NSUInteger)2); @@ -3638,8 +3691,8 @@ static BOOL TestingEnum_IsValidValue2(int32_t value) { XCTAssertEqualObjects(cpy[1], @"bar"); NSMutableArray *cpy2 = [array mutableCopy]; - XCTAssertTrue(cpy2 != array); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != array); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(cpy2.count, (NSUInteger)2); diff --git a/libs/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m b/libs/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m index 0504062..6cd5a1f 100644 --- a/libs/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m +++ b/libs/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m @@ -34,7 +34,7 @@ #import "GPBCodedOutputStream.h" #import "GPBUnknownFieldSet_PackagePrivate.h" #import "GPBUtilities_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" @interface CodedInputStreamTests : GPBTestCase @end @@ -82,10 +82,8 @@ [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x7FFFFFFF]; [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x80000000]; - [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) - value:0x7FFFFFFFFFFFFFFFL]; - [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) - value:0x8000000000000000L]; + [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) value:0x7FFFFFFFFFFFFFFFL]; + [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) value:0x8000000000000000L]; } - (void)assertReadVarint:(NSData*)data value:(int64_t)value { @@ -203,25 +201,30 @@ value:(0x22 << 0) | (0x22 << 7) | (0x22 << 14) | (0x74 << 21)]; // 2961488830 [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b) - value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x0bLL << 28)]; + value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | + (0x04 << 21) | (0x0bLL << 28)]; // 64-bit // 7256456126 [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b) - value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x1bLL << 28)]; + value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | + (0x04 << 21) | (0x1bLL << 28)]; // 41256202580718336 [self assertReadVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49) - value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | (0x43LL << 28) | - (0x49LL << 35) | (0x24LL << 42) | (0x49LL << 49)]; + value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | + (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) | + (0x24LL << 42) | (0x49LL << 49)]; // 11964378330978735131 - [self assertReadVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01) - value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | (0x3bLL << 28) | - (0x56LL << 35) | (0x00LL << 42) | (0x05LL << 49) | (0x26LL << 56) | - (0x01ULL << 63)]; + [self + assertReadVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, + 0xa6, 0x01) + value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | + (0x3bLL << 28) | (0x56LL << 35) | (0x00LL << 42) | + (0x05LL << 49) | (0x26LL << 56) | (0x01ULL << 63)]; // Failures - [self assertReadVarintFailure:bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x00)]; + [self assertReadVarintFailure:bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x00)]; [self assertReadVarintFailure:bytes(0x80)]; } @@ -265,12 +268,16 @@ } - (void)testReadLittleEndian { - [self assertReadLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12) value:0x12345678]; - [self assertReadLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a) value:0x9abcdef0]; + [self assertReadLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12) + value:0x12345678]; + [self assertReadLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a) + value:0x9abcdef0]; - [self assertReadLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12) + [self assertReadLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, + 0x12) value:0x123456789abcdef0LL]; - [self assertReadLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a) + [self assertReadLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, + 0x9a) value:0x9abcdef012345678LL]; } @@ -280,7 +287,8 @@ NSData* rawBytes = message.data; XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); - TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL]; + TestAllTypes* message2 = + [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL]; [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; } @@ -292,7 +300,8 @@ // skipField() to skip each field on the other. Expect the same tags. GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes]; GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes]; - GPBUnknownFieldSet* unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet* unknownFields = + [[[GPBUnknownFieldSet alloc] init] autorelease]; while (YES) { int32_t tag = [input1 readTag]; @@ -320,9 +329,10 @@ // Serialize and parse it. Make sure to parse from an InputStream, not // directly from a ByteString, so that CodedInputStream uses buffered // reading. - NSData* messageData = message.data; + NSData *messageData = message.data; XCTAssertNotNil(messageData); - GPBCodedInputStream* stream = [GPBCodedInputStream streamWithData:messageData]; + GPBCodedInputStream* stream = + [GPBCodedInputStream streamWithData:messageData]; TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream extensionRegistry:nil error:NULL]; @@ -340,7 +350,8 @@ - (void)testReadMaliciouslyLargeBlob { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; int32_t tag = GPBWireFormatMakeTag(1, GPBWireFormatLengthDelimited); [output writeRawVarint32:tag]; @@ -349,7 +360,8 @@ [output writeRawData:[NSData dataWithBytes:bytes length:32]]; [output flush]; - NSData* data = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* data = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]]; XCTAssertEqual(tag, [input readTag]); @@ -358,21 +370,23 @@ } - (void)testReadEmptyString { - NSData* data = bytes(0x00); + NSData *data = bytes(0x00); GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; XCTAssertEqualObjects(@"", [input readString]); } - (void)testInvalidGroupEndTagThrows { - NSData* data = bytes(0x0B, 0x1A, 0x02, 0x4B, 0x50, 0x14); + NSData *data = bytes(0x0B, 0x1A, 0x02, 0x4B, 0x50, 0x14); GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; - XCTAssertThrowsSpecificNamed([input skipMessage], NSException, GPBCodedInputStreamException, + XCTAssertThrowsSpecificNamed([input skipMessage], + NSException, + GPBCodedInputStreamException, @"should throw a GPBCodedInputStreamException exception "); } - (void)testBytesWithNegativeSize { - NSData* data = bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F); - GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; + NSData *data = bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F); + GPBCodedInputStream *input = [GPBCodedInputStream streamWithData:data]; XCTAssertNil([input readBytes]); } @@ -382,10 +396,11 @@ // again, it will help validate that class' handing of bad utf8. - (void)testReadMalformedString { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; - int32_t tag = - GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString, GPBWireFormatLengthDelimited); + int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString, + GPBWireFormatLengthDelimited); [output writeRawVarint32:tag]; [output writeRawVarint32:5]; // Create an invalid utf-8 byte array. @@ -393,9 +408,10 @@ [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]]; [output flush]; - NSData* data = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData *data = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; - NSError* error = nil; + NSError *error = nil; TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input extensionRegistry:nil error:&error]; @@ -409,25 +425,27 @@ // correctly. (Again, this is inpart in case a custom string class is ever // used again.) const char* strs[] = { - "\xEF\xBB\xBF String with BOM", - "String with \xEF\xBB\xBF in middle", - "String with end bom \xEF\xBB\xBF", - "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart - "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM", + "\xEF\xBB\xBF String with BOM", + "String with \xEF\xBB\xBF in middle", + "String with end bom \xEF\xBB\xBF", + "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart + "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM", }; for (size_t i = 0; i < GPBARRAYSIZE(strs); ++i) { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; - int32_t tag = - GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString, GPBWireFormatLengthDelimited); + int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString, + GPBWireFormatLengthDelimited); [output writeRawVarint32:tag]; size_t length = strlen(strs[i]); [output writeRawVarint32:(int32_t)length]; [output writeRawData:[NSData dataWithBytes:strs[i] length:length]]; [output flush]; - NSData* data = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* data = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input extensionRegistry:nil diff --git a/libs/protobuf/objectivec/Tests/GPBCodedOutputStreamTests.m b/libs/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m similarity index 70% rename from libs/protobuf/objectivec/Tests/GPBCodedOutputStreamTests.m rename to libs/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m index a619cae..a9934ac 100644 --- a/libs/protobuf/objectivec/Tests/GPBCodedOutputStreamTests.m +++ b/libs/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m @@ -30,23 +30,26 @@ #import "GPBTestUtilities.h" -#import "GPBCodedInputStream.h" #import "GPBCodedOutputStream_PackagePrivate.h" +#import "GPBCodedInputStream.h" #import "GPBUtilities_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" @interface GPBCodedOutputStream (InternalMethods) // Declared in the .m file, expose for testing. -- (instancetype)initWithOutputStream:(NSOutputStream*)output data:(NSMutableData*)data; +- (instancetype)initWithOutputStream:(NSOutputStream *)output + data:(NSMutableData *)data; @end @interface GPBCodedOutputStream (Helper) -+ (instancetype)streamWithOutputStream:(NSOutputStream*)output bufferSize:(size_t)bufferSize; ++ (instancetype)streamWithOutputStream:(NSOutputStream *)output + bufferSize:(size_t)bufferSize; @end @implementation GPBCodedOutputStream (Helper) -+ (instancetype)streamWithOutputStream:(NSOutputStream*)output bufferSize:(size_t)bufferSize { - NSMutableData* data = [NSMutableData dataWithLength:bufferSize]; ++ (instancetype)streamWithOutputStream:(NSOutputStream *)output + bufferSize:(size_t)bufferSize { + NSMutableData *data = [NSMutableData dataWithLength:bufferSize]; return [[[self alloc] initWithOutputStream:output data:data] autorelease]; } @end @@ -78,17 +81,20 @@ - (void)assertWriteLittleEndian32:(NSData*)data value:(int32_t)value { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; [output writeRawLittleEndian32:(int32_t)value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); // Try different block sizes. for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { rawOutput = [NSOutputStream outputStreamToMemory]; - output = [GPBCodedOutputStream streamWithOutputStream:rawOutput bufferSize:blockSize]; + output = [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [output writeRawLittleEndian32:(int32_t)value]; [output flush]; @@ -99,17 +105,20 @@ - (void)assertWriteLittleEndian64:(NSData*)data value:(int64_t)value { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; [output writeRawLittleEndian64:value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); // Try different block sizes. for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { rawOutput = [NSOutputStream outputStreamToMemory]; - output = [GPBCodedOutputStream streamWithOutputStream:rawOutput bufferSize:blockSize]; + output = [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [output writeRawLittleEndian64:value]; [output flush]; @@ -122,24 +131,29 @@ // Only do 32-bit write if the value fits in 32 bits. if (GPBLogicalRightShift64(value, 32) == 0) { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; [output writeRawVarint32:(int32_t)value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); // Also try computing size. - XCTAssertEqual(GPBComputeRawVarint32Size((int32_t)value), (size_t)data.length); + XCTAssertEqual(GPBComputeRawVarint32Size((int32_t)value), + (size_t)data.length); } { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; [output writeRawVarint64:value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); // Also try computing size. @@ -151,45 +165,52 @@ // Only do 32-bit write if the value fits in 32 bits. if (GPBLogicalRightShift64(value, 32) == 0) { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput - bufferSize:blockSize]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [output writeRawVarint32:(int32_t)value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); } { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput - bufferSize:blockSize]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [output writeRawVarint64:value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual); } } } - (void)assertWriteStringNoTag:(NSData*)data - value:(NSString*)value - context:(NSString*)contextMessage { + value:(NSString *)value + context:(NSString *)contextMessage { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput]; [output writeStringNoTag:value]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(data, actual, @"%@", contextMessage); // Try different block sizes. for (int blockSize = 1; blockSize <= 16; blockSize *= 2) { rawOutput = [NSOutputStream outputStreamToMemory]; - output = [GPBCodedOutputStream streamWithOutputStream:rawOutput bufferSize:blockSize]; + output = [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [output writeStringNoTag:value]; [output flush]; @@ -222,41 +243,51 @@ // 1887747006 (no sign bit) [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x07) - value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x07LL << 28)]; + value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | + (0x04 << 21) | (0x07LL << 28)]; // 2961488830 (sign bit) [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b) - value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x0bLL << 28)]; + value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | + (0x04 << 21) | (0x0bLL << 28)]; } - (void)testWriteVarint6 { // 64-bit // 7256456126 [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b) - value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x1bLL << 28)]; + value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | + (0x04 << 21) | (0x1bLL << 28)]; } - (void)testWriteVarint7 { // 41256202580718336 [self assertWriteVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49) - value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | (0x43LL << 28) | - (0x49LL << 35) | (0x24LL << 42) | (0x49LL << 49)]; + value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | + (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) | + (0x24LL << 42) | (0x49LL << 49)]; } - (void)testWriteVarint8 { // 11964378330978735131 - [self assertWriteVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01) - value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | (0x3bLL << 28) | - (0x56LL << 35) | (0x00LL << 42) | (0x05LL << 49) | (0x26LL << 56) | + [self assertWriteVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, + 0xa6, 0x01) + value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | + (0x42 << 21) | (0x3bLL << 28) | (0x56LL << 35) | + (0x00LL << 42) | (0x05LL << 49) | (0x26LL << 56) | (0x01ULL << 63)]; } - (void)testWriteLittleEndian { - [self assertWriteLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12) value:0x12345678]; - [self assertWriteLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a) value:0x9abcdef0]; + [self assertWriteLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12) + value:0x12345678]; + [self assertWriteLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a) + value:0x9abcdef0]; - [self assertWriteLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12) + [self assertWriteLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, + 0x34, 0x12) value:0x123456789abcdef0LL]; - [self assertWriteLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a) + [self assertWriteLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, + 0xbc, 0x9a) value:0x9abcdef012345678LL]; } @@ -274,12 +305,18 @@ XCTAssertEqual(1ULL, GPBEncodeZigZag64(-1)); XCTAssertEqual(2ULL, GPBEncodeZigZag64(1)); XCTAssertEqual(3ULL, GPBEncodeZigZag64(-2)); - XCTAssertEqual(0x000000007FFFFFFEULL, GPBEncodeZigZag64(0x000000003FFFFFFFLL)); - XCTAssertEqual(0x000000007FFFFFFFULL, GPBEncodeZigZag64(0xFFFFFFFFC0000000LL)); - XCTAssertEqual(0x00000000FFFFFFFEULL, GPBEncodeZigZag64(0x000000007FFFFFFFLL)); - XCTAssertEqual(0x00000000FFFFFFFFULL, GPBEncodeZigZag64(0xFFFFFFFF80000000LL)); - XCTAssertEqual(0xFFFFFFFFFFFFFFFEULL, GPBEncodeZigZag64(0x7FFFFFFFFFFFFFFFLL)); - XCTAssertEqual(0xFFFFFFFFFFFFFFFFULL, GPBEncodeZigZag64(0x8000000000000000LL)); + XCTAssertEqual(0x000000007FFFFFFEULL, + GPBEncodeZigZag64(0x000000003FFFFFFFLL)); + XCTAssertEqual(0x000000007FFFFFFFULL, + GPBEncodeZigZag64(0xFFFFFFFFC0000000LL)); + XCTAssertEqual(0x00000000FFFFFFFEULL, + GPBEncodeZigZag64(0x000000007FFFFFFFLL)); + XCTAssertEqual(0x00000000FFFFFFFFULL, + GPBEncodeZigZag64(0xFFFFFFFF80000000LL)); + XCTAssertEqual(0xFFFFFFFFFFFFFFFEULL, + GPBEncodeZigZag64(0x7FFFFFFFFFFFFFFFLL)); + XCTAssertEqual(0xFFFFFFFFFFFFFFFFULL, + GPBEncodeZigZag64(0x8000000000000000LL)); // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1) // were chosen semi-randomly via keyboard bashing. @@ -295,8 +332,10 @@ XCTAssertEqual(14927ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(14927))); XCTAssertEqual(-3612ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-3612))); - XCTAssertEqual(856912304801416ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(856912304801416LL))); - XCTAssertEqual(-75123905439571256ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-75123905439571256LL))); + XCTAssertEqual(856912304801416ULL, + GPBEncodeZigZag64(GPBDecodeZigZag64(856912304801416LL))); + XCTAssertEqual(-75123905439571256ULL, + GPBEncodeZigZag64(GPBDecodeZigZag64(-75123905439571256LL))); } - (void)testWriteWholeMessage { @@ -305,18 +344,21 @@ TestAllTypes* message = [self allSetRepeatedCount:2]; NSData* rawBytes = message.data; - NSData* goldenData = [self getDataFileNamed:@"golden_message" dataToWrite:rawBytes]; + NSData* goldenData = + [self getDataFileNamed:@"golden_message" dataToWrite:rawBytes]; XCTAssertEqualObjects(rawBytes, goldenData); // Try different block sizes. for (int blockSize = 1; blockSize < 256; blockSize *= 2) { NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* output = [GPBCodedOutputStream streamWithOutputStream:rawOutput - bufferSize:blockSize]; + GPBCodedOutputStream* output = + [GPBCodedOutputStream streamWithOutputStream:rawOutput + bufferSize:blockSize]; [message writeToCodedOutputStream:output]; [output flush]; - NSData* actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; + NSData* actual = + [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; XCTAssertEqualObjects(rawBytes, actual); } @@ -324,7 +366,8 @@ // that was generated with 2. TestAllExtensions* extensions = [self allExtensionsSetRepeatedCount:2]; rawBytes = extensions.data; - goldenData = [self getDataFileNamed:@"golden_packed_fields_message" dataToWrite:rawBytes]; + goldenData = [self getDataFileNamed:@"golden_packed_fields_message" + dataToWrite:rawBytes]; XCTAssertEqualObjects(rawBytes, goldenData); } @@ -337,10 +380,11 @@ char zeroTest[] = "\0Test\0String"; // Note: there is a \0 at the end of this since it is a c-string. - NSString* asNSString = [[NSString alloc] initWithBytes:zeroTest + NSString *asNSString = [[NSString alloc] initWithBytes:zeroTest length:sizeof(zeroTest) encoding:NSUTF8StringEncoding]; - const char* cString = CFStringGetCStringPtr((CFStringRef)asNSString, kCFStringEncodingUTF8); + const char *cString = + CFStringGetCStringPtr((CFStringRef)asNSString, kCFStringEncodingUTF8); XCTAssertTrue(cString != NULL); // Again, if the above assert fails, then it means NSString no longer exposes // the raw utf8 storage of a string created from utf8 input, so the code using @@ -348,7 +392,8 @@ // a different code path); but the optimizations for when // CFStringGetCStringPtr does work could possibly go away. - XCTAssertEqual(sizeof(zeroTest), [asNSString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqual(sizeof(zeroTest), + [asNSString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]); XCTAssertTrue(0 == memcmp(cString, zeroTest, sizeof(zeroTest))); [asNSString release]; } @@ -360,25 +405,25 @@ // strings built via the NSString apis. So this round trips them to ensure // they are acting as expected. - NSArray* strs = @[ + NSArray *strs = @[ @"\0at start", @"in\0middle", @"at end\0", ]; int i = 0; - for (NSString* str in strs) { - NSData* asUTF8 = [str dataUsingEncoding:NSUTF8StringEncoding]; - NSMutableData* expected = [NSMutableData data]; + for (NSString *str in strs) { + NSData *asUTF8 = [str dataUsingEncoding:NSUTF8StringEncoding]; + NSMutableData *expected = [NSMutableData data]; uint8_t lengthByte = (uint8_t)asUTF8.length; [expected appendBytes:&lengthByte length:1]; [expected appendData:asUTF8]; - NSString* context = [NSString stringWithFormat:@"Loop %d - Literal", i]; + NSString *context = [NSString stringWithFormat:@"Loop %d - Literal", i]; [self assertWriteStringNoTag:expected value:str context:context]; // Force a new string to be built which gets a different class from the // NSString class cluster than the literal did. - NSString* str2 = [NSString stringWithFormat:@"%@", str]; + NSString *str2 = [NSString stringWithFormat:@"%@", str]; context = [NSString stringWithFormat:@"Loop %d - Built", i]; [self assertWriteStringNoTag:expected value:str2 context:context]; @@ -387,11 +432,11 @@ } - (void)testThatItThrowsWhenWriteRawPtrFails { - NSOutputStream* output = [NSOutputStream outputStreamToMemory]; - GPBCodedOutputStream* codedOutput = + NSOutputStream *output = [NSOutputStream outputStreamToMemory]; + GPBCodedOutputStream *codedOutput = [GPBCodedOutputStream streamWithOutputStream:output bufferSize:0]; // Skip buffering. [output close]; // Close the output stream to force failure on write. - const char* cString = "raw"; + const char *cString = "raw"; XCTAssertThrowsSpecificNamed([codedOutput writeRawPtr:cString offset:0 length:strlen(cString)], NSException, GPBCodedOutputStreamException_WriteFailed); } diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest01.m b/libs/protobuf/objectivec/Tests/GPBCompileTest01.m index c8a6e6b..c8bc433 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest01.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest01.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBArray.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_1 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest02.m b/libs/protobuf/objectivec/Tests/GPBCompileTest02.m index 77e4589..c44e201 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest02.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest02.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBCodedInputStream.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_2 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest03.m b/libs/protobuf/objectivec/Tests/GPBCompileTest03.m index f4945a7..41994f9 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest03.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest03.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBCodedOutputStream.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_3 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest04.m b/libs/protobuf/objectivec/Tests/GPBCompileTest04.m index da69c1d..c31498f 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest04.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest04.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBDescriptor.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_4 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest05.m b/libs/protobuf/objectivec/Tests/GPBCompileTest05.m index e4665ea..adb7225 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest05.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest05.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBDictionary.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_5 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest06.m b/libs/protobuf/objectivec/Tests/GPBCompileTest06.m index c197b56..b7505b0 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest06.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest06.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBExtensionRegistry.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_6 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest07.m b/libs/protobuf/objectivec/Tests/GPBCompileTest07.m index 83f7a8f..939bb70 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest07.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest07.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBMessage.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_7 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest08.m b/libs/protobuf/objectivec/Tests/GPBCompileTest08.m index 48246f8..a84f38c 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest08.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest08.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBRootObject.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_8 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest09.m b/libs/protobuf/objectivec/Tests/GPBCompileTest09.m index d1d8cdf..f8ccb4a 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest09.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest09.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBUnknownField.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_9 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest10.m b/libs/protobuf/objectivec/Tests/GPBCompileTest10.m index 31f610d..d831867 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest10.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest10.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBUnknownFieldSet.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_10 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest11.m b/libs/protobuf/objectivec/Tests/GPBCompileTest11.m index 2f51ec9..9f2c6b1 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest11.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest11.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBUtilities.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_11 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest12.m b/libs/protobuf/objectivec/Tests/GPBCompileTest12.m index 9892bcf..3aa29b3 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest12.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest12.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBWellKnownTypes.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_12 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest13.m b/libs/protobuf/objectivec/Tests/GPBCompileTest13.m index d5168ae..fef2af5 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest13.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest13.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBWireFormat.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_13 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest14.m b/libs/protobuf/objectivec/Tests/GPBCompileTest14.m index cd59f6f..1e64b71 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest14.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest14.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBAny.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_14 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest15.m b/libs/protobuf/objectivec/Tests/GPBCompileTest15.m index ad9a3f8..2eaedb2 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest15.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest15.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBApi.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_15 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest16.m b/libs/protobuf/objectivec/Tests/GPBCompileTest16.m index c5b532e..25af89e 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest16.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest16.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBDuration.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_16 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest17.m b/libs/protobuf/objectivec/Tests/GPBCompileTest17.m index 02988e6..c719ad3 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest17.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest17.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBEmpty.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_17 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest18.m b/libs/protobuf/objectivec/Tests/GPBCompileTest18.m index a652c61..a02b259 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest18.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest18.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBFieldMask.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_18 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest19.m b/libs/protobuf/objectivec/Tests/GPBCompileTest19.m index 7ea31a8..b447284 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest19.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest19.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBSourceContext.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_19 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest20.m b/libs/protobuf/objectivec/Tests/GPBCompileTest20.m index d79ceea..120ef55 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest20.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest20.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBStruct.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_20 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest21.m b/libs/protobuf/objectivec/Tests/GPBCompileTest21.m index 0a273da..766d890 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest21.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest21.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBTimestamp.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_21 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest22.m b/libs/protobuf/objectivec/Tests/GPBCompileTest22.m index 05cd01c..6d0955b 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest22.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest22.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBType.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_22 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest23.m b/libs/protobuf/objectivec/Tests/GPBCompileTest23.m index ec29f3a..22f2db6 100644 --- a/libs/protobuf/objectivec/Tests/GPBCompileTest23.m +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest23.m @@ -28,11 +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. + // This is a test including a single public header to ensure things build. // It helps test that imports are complete/ordered correctly. #import "GPBWrappers.pbobjc.h" + // Something in the body of this file so the compiler/linker won't complain // about an empty .o file. __attribute__((visibility("default"))) char dummy_symbol_23 = 0; diff --git a/libs/protobuf/objectivec/Tests/unittest_import.proto b/libs/protobuf/objectivec/Tests/GPBCompileTest24.m similarity index 77% rename from libs/protobuf/objectivec/Tests/unittest_import.proto rename to libs/protobuf/objectivec/Tests/GPBCompileTest24.m index 8b8996f..c81ea73 100644 --- a/libs/protobuf/objectivec/Tests/unittest_import.proto +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest24.m @@ -28,31 +28,15 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// A proto file which is imported by unittest.proto to test importing. -syntax = "proto2"; +// This is a test including a single header to ensure things build. This +// is NOT a public header of the library, but uses a file that defines +// proto2 syntax messages that are extendable, so it can need more things +// that the proto3 syntax WKTs bundled with the library. -package objc.protobuf.tests.import; - -// Test public import -import public "objectivec/Tests/unittest_import_public.proto"; - -option objc_class_prefix = "Import"; - -message Message { - optional int32 d = 1; -} - -enum Enum { - IMPORT_FOO = 7; - IMPORT_BAR = 8; - IMPORT_BAZ = 9; -} +#import "google/protobuf/Descriptor.pbobjc.h" -// To use an enum in a map, it must has the first value as 0. -enum EnumForMap { - UNKNOWN = 0; - FOO = 1; - BAR = 2; -} +// Something in the body of this file so the compiler/linker won't complain +// about an empty .o file. +__attribute__((visibility("default"))) char dummy_symbol_24 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBCompileTest25.m b/libs/protobuf/objectivec/Tests/GPBCompileTest25.m new file mode 100644 index 0000000..7a482b5 --- /dev/null +++ b/libs/protobuf/objectivec/Tests/GPBCompileTest25.m @@ -0,0 +1,42 @@ +// 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 is a test including a single header to ensure things build. This +// is NOT a public header of the library, but uses a file that defines +// extensions to proto2 syntax messages, so it can need more things +// that the proto3 syntax WKTs bundled with the library. + +#import "google/protobuf/UnittestCustomOptions.pbobjc.h" + + +// Something in the body of this file so the compiler/linker won't complain +// about an empty .o file. +__attribute__((visibility("default"))) char dummy_symbol_25 = 0; diff --git a/libs/protobuf/objectivec/Tests/GPBConcurrencyTests.m b/libs/protobuf/objectivec/Tests/GPBConcurrencyTests.m index 4ea62f9..daf75e7 100644 --- a/libs/protobuf/objectivec/Tests/GPBConcurrencyTests.m +++ b/libs/protobuf/objectivec/Tests/GPBConcurrencyTests.m @@ -30,8 +30,8 @@ #import "GPBTestUtilities.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" static const int kNumThreads = 100; static const int kNumMessages = 100; @@ -49,7 +49,8 @@ static const int kNumMessages = 100; - (NSArray *)createThreadsWithSelector:(SEL)selector object:(id)object { NSMutableArray *array = [NSMutableArray array]; for (NSUInteger i = 0; i < kNumThreads; i++) { - NSThread *thread = [[NSThread alloc] initWithTarget:self selector:selector object:object]; + NSThread *thread = + [[NSThread alloc] initWithTarget:self selector:selector object:object]; [array addObject:thread]; [thread release]; } @@ -87,8 +88,9 @@ static const int kNumMessages = 100; - (void)testConcurrentReadOfUnsetMessageField { NSArray *messages = [self createMessagesWithType:[TestAllTypes class]]; - NSArray *threads = [self createThreadsWithSelector:@selector(readForeignMessage:) - object:messages]; + NSArray *threads = + [self createThreadsWithSelector:@selector(readForeignMessage:) + object:messages]; [self startThreads:threads]; [self joinThreads:threads]; for (TestAllTypes *message in messages) { @@ -106,7 +108,9 @@ static const int kNumMessages = 100; - (void)testConcurrentReadOfUnsetRepeatedIntField { NSArray *messages = [self createMessagesWithType:[TestAllTypes class]]; - NSArray *threads = [self createThreadsWithSelector:@selector(readRepeatedInt32:) object:messages]; + NSArray *threads = + [self createThreadsWithSelector:@selector(readRepeatedInt32:) + object:messages]; [self startThreads:threads]; [self joinThreads:threads]; for (TestAllTypes *message in messages) { @@ -124,8 +128,9 @@ static const int kNumMessages = 100; - (void)testConcurrentReadOfUnsetRepeatedStringField { NSArray *messages = [self createMessagesWithType:[TestAllTypes class]]; - NSArray *threads = [self createThreadsWithSelector:@selector(readRepeatedString:) - object:messages]; + NSArray *threads = + [self createThreadsWithSelector:@selector(readRepeatedString:) + object:messages]; [self startThreads:threads]; [self joinThreads:threads]; for (TestAllTypes *message in messages) { @@ -142,8 +147,11 @@ static const int kNumMessages = 100; } - (void)testConcurrentReadOfUnsetInt32Int32MapField { - NSArray *messages = [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]]; - NSArray *threads = [self createThreadsWithSelector:@selector(readInt32Int32Map:) object:messages]; + NSArray *messages = + [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]]; + NSArray *threads = + [self createThreadsWithSelector:@selector(readInt32Int32Map:) + object:messages]; [self startThreads:threads]; [self joinThreads:threads]; for (TestRecursiveMessageWithRepeatedField *message in messages) { @@ -160,9 +168,11 @@ static const int kNumMessages = 100; } - (void)testConcurrentReadOfUnsetStringStringMapField { - NSArray *messages = [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]]; - NSArray *threads = [self createThreadsWithSelector:@selector(readStringStringMap:) - object:messages]; + NSArray *messages = + [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]]; + NSArray *threads = + [self createThreadsWithSelector:@selector(readStringStringMap:) + object:messages]; [self startThreads:threads]; [self joinThreads:threads]; for (TestRecursiveMessageWithRepeatedField *message in messages) { @@ -186,7 +196,8 @@ static const int kNumMessages = 100; NSArray *threads = [self createThreadsWithSelector:sel object:messages]; [self startThreads:threads]; [self joinThreads:threads]; - GPBExtensionDescriptor *extension = [UnittestRoot optionalForeignMessageExtension]; + GPBExtensionDescriptor *extension = + [UnittestRoot optionalForeignMessageExtension]; for (TestAllExtensions *message in messages) { XCTAssertFalse([message hasExtension:extension]); } diff --git a/libs/protobuf/objectivec/Tests/GPBDescriptorTests.m b/libs/protobuf/objectivec/Tests/GPBDescriptorTests.m index e528be4..b1ff544 100644 --- a/libs/protobuf/objectivec/Tests/GPBDescriptorTests.m +++ b/libs/protobuf/objectivec/Tests/GPBDescriptorTests.m @@ -33,9 +33,9 @@ #import #import "GPBDescriptor_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" -#import "objectivec/Tests/UnittestObjcOptions.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" +#import "google/protobuf/Descriptor.pbobjc.h" @interface DescriptorTests : GPBTestCase @end @@ -52,36 +52,37 @@ - (void)testDescriptor_fullName { GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor]; - XCTAssertEqualObjects(testAllTypesDesc.fullName, @"objc.protobuf.tests.TestAllTypes"); + XCTAssertEqualObjects(testAllTypesDesc.fullName, @"protobuf_unittest.TestAllTypes"); GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor]; - XCTAssertEqualObjects(nestedMessageDesc.fullName, - @"objc.protobuf.tests.TestAllTypes.NestedMessage"); + XCTAssertEqualObjects(nestedMessageDesc.fullName, @"protobuf_unittest.TestAllTypes.NestedMessage"); // Prefixes removed. - GPBDescriptor *descDesc = [GPBTESTPrefixedParentMessage descriptor]; - XCTAssertEqualObjects(descDesc.fullName, @"objc.protobuf.tests.options.PrefixedParentMessage"); - GPBDescriptor *descExtRngDesc = [GPBTESTPrefixedParentMessage_Child descriptor]; - XCTAssertEqualObjects(descExtRngDesc.fullName, - @"objc.protobuf.tests.options.PrefixedParentMessage.Child"); + GPBDescriptor *descDesc = [GPBDescriptorProto descriptor]; + XCTAssertEqualObjects(descDesc.fullName, @"google.protobuf.DescriptorProto"); + GPBDescriptor *descExtRngDesc = [GPBDescriptorProto_ExtensionRange descriptor]; + XCTAssertEqualObjects(descExtRngDesc.fullName, @"google.protobuf.DescriptorProto.ExtensionRange"); // Things that get "_Class" added. GPBDescriptor *pointDesc = [Point_Class descriptor]; - XCTAssertEqualObjects(pointDesc.fullName, @"objc.protobuf.tests.Point"); + XCTAssertEqualObjects(pointDesc.fullName, @"protobuf_unittest.Point"); GPBDescriptor *pointRectDesc = [Point_Rect descriptor]; - XCTAssertEqualObjects(pointRectDesc.fullName, @"objc.protobuf.tests.Point.Rect"); + XCTAssertEqualObjects(pointRectDesc.fullName, @"protobuf_unittest.Point.Rect"); } - (void)testFieldDescriptor { GPBDescriptor *descriptor = [TestAllTypes descriptor]; // Nested Enum - GPBFieldDescriptor *fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedEnum"]; + GPBFieldDescriptor *fieldDescriptorWithName = + [descriptor fieldWithName:@"optionalNestedEnum"]; XCTAssertNotNil(fieldDescriptorWithName); - GPBFieldDescriptor *fieldDescriptorWithNumber = [descriptor fieldWithNumber:21]; + GPBFieldDescriptor *fieldDescriptorWithNumber = + [descriptor fieldWithNumber:21]; XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); - XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, @"TestAllTypes_NestedEnum"); + XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, + @"TestAllTypes_NestedEnum"); XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number); XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum); @@ -92,7 +93,8 @@ XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); - XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, @"ForeignEnum"); + XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, + @"ForeignEnum"); XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number); XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum); @@ -103,7 +105,8 @@ XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); - XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, @"ImportEnum"); + XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, + @"ImportEnum"); XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number); XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum); @@ -118,7 +121,8 @@ XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage); // Foreign Message - fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignMessage"]; + fieldDescriptorWithName = + [descriptor fieldWithName:@"optionalForeignMessage"]; XCTAssertNotNil(fieldDescriptorWithName); fieldDescriptorWithNumber = [descriptor fieldWithNumber:19]; XCTAssertNotNil(fieldDescriptorWithNumber); @@ -148,18 +152,22 @@ NSString *enumName = [descriptor enumNameForValue:1]; XCTAssertNotNil(enumName); int32_t value; - XCTAssertTrue([descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Foo"]); - XCTAssertTrue([descriptor getValue:NULL forEnumName:@"TestAllTypes_NestedEnum_Foo"]); + XCTAssertTrue( + [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Foo"]); + XCTAssertTrue( + [descriptor getValue:NULL forEnumName:@"TestAllTypes_NestedEnum_Foo"]); XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo); enumName = [descriptor enumNameForValue:2]; XCTAssertNotNil(enumName); - XCTAssertTrue([descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]); + XCTAssertTrue( + [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]); XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar); enumName = [descriptor enumNameForValue:3]; XCTAssertNotNil(enumName); - XCTAssertTrue([descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]); + XCTAssertTrue( + [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]); XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz); // TextFormat @@ -174,8 +182,10 @@ XCTAssertNil(enumName); XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]); XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]); - XCTAssertFalse([descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); - XCTAssertFalse([descriptor getValue:NULL forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); + XCTAssertFalse([descriptor getValue:&value + forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); + XCTAssertFalse([descriptor getValue:NULL + forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); XCTAssertFalse([descriptor getValue:NULL forEnumTextFormatName:@"Unknown"]); XCTAssertFalse([descriptor getValue:&value forEnumTextFormatName:@"Unknown"]); } @@ -184,13 +194,17 @@ GPBEnumDescriptor *descriptor = TestAllTypes_NestedEnum_EnumDescriptor(); XCTAssertEqual(descriptor.enumNameCount, 4U); - XCTAssertEqualObjects([descriptor getEnumNameForIndex:0], @"TestAllTypes_NestedEnum_Foo"); + XCTAssertEqualObjects([descriptor getEnumNameForIndex:0], + @"TestAllTypes_NestedEnum_Foo"); XCTAssertEqualObjects([descriptor getEnumTextFormatNameForIndex:0], @"FOO"); - XCTAssertEqualObjects([descriptor getEnumNameForIndex:1], @"TestAllTypes_NestedEnum_Bar"); + XCTAssertEqualObjects([descriptor getEnumNameForIndex:1], + @"TestAllTypes_NestedEnum_Bar"); XCTAssertEqualObjects([descriptor getEnumTextFormatNameForIndex:1], @"BAR"); - XCTAssertEqualObjects([descriptor getEnumNameForIndex:2], @"TestAllTypes_NestedEnum_Baz"); + XCTAssertEqualObjects([descriptor getEnumNameForIndex:2], + @"TestAllTypes_NestedEnum_Baz"); XCTAssertEqualObjects([descriptor getEnumTextFormatNameForIndex:2], @"BAZ"); - XCTAssertEqualObjects([descriptor getEnumNameForIndex:3], @"TestAllTypes_NestedEnum_Neg"); + XCTAssertEqualObjects([descriptor getEnumNameForIndex:3], + @"TestAllTypes_NestedEnum_Neg"); XCTAssertEqualObjects([descriptor getEnumTextFormatNameForIndex:3], @"NEG"); } @@ -272,7 +286,8 @@ - (void)testEnumValueValidator { GPBDescriptor *descriptor = [TestAllTypes descriptor]; - GPBFieldDescriptor *fieldDescriptor = [descriptor fieldWithName:@"optionalNestedEnum"]; + GPBFieldDescriptor *fieldDescriptor = + [descriptor fieldWithName:@"optionalNestedEnum"]; // Valid values XCTAssertTrue([fieldDescriptor isValidEnumValue:1]); @@ -310,10 +325,12 @@ // Pointer comparisons against lookups from message. - XCTAssertEqual([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_FooString], fooStringField); + XCTAssertEqual([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_FooString], + fooStringField); XCTAssertEqual([oneofFoo fieldWithName:@"fooString"], fooStringField); - XCTAssertEqual([oneofBar fieldWithNumber:TestOneof2_FieldNumber_BarString], barStringField); + XCTAssertEqual([oneofBar fieldWithNumber:TestOneof2_FieldNumber_BarString], + barStringField); XCTAssertEqual([oneofBar fieldWithName:@"barString"], barStringField); // Unknown oneof not found. @@ -337,7 +354,8 @@ // (pointer comparisons) XCTAssertEqual(fooStringField.containingOneof, oneofFoo); XCTAssertEqual(barStringField.containingOneof, oneofBar); - GPBFieldDescriptor *bazString = [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString]; + GPBFieldDescriptor *bazString = + [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString]; XCTAssertNotNil(bazString); XCTAssertNil(bazString.containingOneof); } diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m index 37f7eb3..4c02144 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m @@ -34,10 +34,7 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. @@ -45,6 +42,7 @@ //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> UInt32 @@ -58,7 +56,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:YES]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused BOOL aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -124,7 +123,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused BOOL aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -346,8 +346,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Int32 @@ -361,7 +363,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:YES]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused BOOL aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -427,7 +430,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused BOOL aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -649,8 +653,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> UInt64 @@ -664,7 +670,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:YES]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused BOOL aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -730,7 +737,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused BOOL aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -952,8 +960,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Int64 @@ -967,7 +977,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:YES]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused BOOL aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1033,7 +1044,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused BOOL aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1255,8 +1267,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Bool @@ -1270,7 +1284,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:YES]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused BOOL aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1336,7 +1351,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused BOOL aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1558,8 +1574,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Float @@ -1573,7 +1591,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:YES]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused BOOL aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1639,7 +1658,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused BOOL aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1861,8 +1881,10 @@ @end +// clang-format on //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.) // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Double @@ -1876,7 +1898,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:YES]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused BOOL aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1942,7 +1965,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused BOOL aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2164,8 +2188,10 @@ @end +// clang-format on //%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def") // This block of code is generated, do not edit it directly. +// clang-format off #pragma mark - Bool -> Object @@ -2179,7 +2205,8 @@ XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:YES]); - [dict enumerateKeysAndObjectsUsingBlock:^(__unused BOOL aKey, __unused NSString* aObject, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2237,7 +2264,8 @@ // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(__unused BOOL aKey, __unused NSString* aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject) if (idx == 0) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2432,6 +2460,7 @@ @end +// clang-format on //%PDDM-EXPAND-END (8 expansions) diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m index f08e213..8dafaac 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m @@ -34,10 +34,7 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. @@ -45,6 +42,7 @@ //%PDDM-EXPAND TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14) // This block of code is generated, do not edit it directly. +// clang-format off // To let the testing macros work, add some extra methods to simplify things. @interface GPBInt32EnumDictionary (TestingTweak) @@ -89,7 +87,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:11]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused int32_t aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -159,7 +158,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused int32_t aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -448,7 +448,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:11]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused int32_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -518,7 +519,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused int32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -807,7 +809,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:11]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused int32_t aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -877,7 +880,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused int32_t aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1166,7 +1170,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:11]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused int32_t aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1236,7 +1241,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused int32_t aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1525,7 +1531,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:11]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused int32_t aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1595,7 +1602,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused int32_t aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1884,7 +1892,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:11]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused int32_t aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1954,7 +1963,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused int32_t aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2243,7 +2253,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:11]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused int32_t aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2313,7 +2324,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused int32_t aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2602,7 +2614,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getEnum:NULL forKey:11]); - [dict enumerateKeysAndEnumsUsingBlock:^(__unused int32_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2672,7 +2685,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndEnumsUsingBlock:^(__unused int32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3029,7 +3043,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndRawValuesUsingBlock:^(__unused int32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndRawValuesUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3378,7 +3393,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:11]); - [dict enumerateKeysAndObjectsUsingBlock:^(__unused int32_t aKey, __unused NSString* aObject, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -3438,7 +3454,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(__unused int32_t aKey, __unused NSString* aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3656,5 +3673,6 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14) diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m index c052e1c..a603356 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m @@ -34,10 +34,7 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. @@ -45,6 +42,7 @@ //%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) // This block of code is generated, do not edit it directly. +// clang-format off // To let the testing macros work, add some extra methods to simplify things. @interface GPBInt64EnumDictionary (TestingTweak) @@ -89,7 +87,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:21LL]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused int64_t aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -159,7 +158,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused int64_t aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -448,7 +448,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:21LL]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused int64_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -518,7 +519,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused int64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -807,7 +809,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:21LL]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused int64_t aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -877,7 +880,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused int64_t aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1166,7 +1170,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:21LL]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused int64_t aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1236,7 +1241,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused int64_t aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1525,7 +1531,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:21LL]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused int64_t aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1595,7 +1602,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused int64_t aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1884,7 +1892,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:21LL]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused int64_t aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1954,7 +1963,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused int64_t aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2243,7 +2253,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:21LL]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused int64_t aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2313,7 +2324,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused int64_t aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2602,7 +2614,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getEnum:NULL forKey:21LL]); - [dict enumerateKeysAndEnumsUsingBlock:^(__unused int64_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2672,7 +2685,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndEnumsUsingBlock:^(__unused int64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3029,7 +3043,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndRawValuesUsingBlock:^(__unused int64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndRawValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3378,7 +3393,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:21LL]); - [dict enumerateKeysAndObjectsUsingBlock:^(__unused int64_t aKey, __unused NSString* aObject, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -3438,7 +3454,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(__unused int64_t aKey, __unused NSString* aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3656,5 +3673,6 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL) diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+String.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+String.m index 6c5d7b3..8ad1cea 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+String.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+String.m @@ -34,17 +34,15 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm -//%PDDM-EXPAND TESTS_FOR_POD_VALUES(String,NSString,*,Objects,@"foo",@"bar",@"baz",@"mumble") +//%PDDM-EXPAND TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble") // This block of code is generated, do not edit it directly. +// clang-format off // To let the testing macros work, add some extra methods to simplify things. @interface GPBStringEnumDictionary (TestingTweak) @@ -89,7 +87,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:@"foo"]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused NSString *aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -159,7 +158,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused NSString *aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -448,7 +448,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:@"foo"]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused NSString *aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -518,7 +519,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused NSString *aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -807,7 +809,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:@"foo"]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused NSString *aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -877,7 +880,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused NSString *aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1166,7 +1170,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:@"foo"]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused NSString *aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1236,7 +1241,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused NSString *aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1525,7 +1531,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:@"foo"]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused NSString *aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1595,7 +1602,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused NSString *aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1884,7 +1892,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:@"foo"]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused NSString *aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1954,7 +1963,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused NSString *aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2243,7 +2253,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:@"foo"]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused NSString *aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2313,7 +2324,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused NSString *aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2602,7 +2614,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]); - [dict enumerateKeysAndEnumsUsingBlock:^(__unused NSString *aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2672,7 +2685,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndEnumsUsingBlock:^(__unused NSString *aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3029,7 +3043,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndRawValuesUsingBlock:^(__unused NSString *aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndRawValuesUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3366,4 +3381,6 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @end -//%PDDM-EXPAND-END TESTS_FOR_POD_VALUES(String,NSString,*,Objects,@"foo",@"bar",@"baz",@"mumble") +// clang-format on +//%PDDM-EXPAND-END TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble") + diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m index 854d49b..f607538 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m @@ -34,10 +34,7 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. @@ -45,6 +42,7 @@ //%PDDM-EXPAND TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U) // This block of code is generated, do not edit it directly. +// clang-format off // To let the testing macros work, add some extra methods to simplify things. @interface GPBUInt32EnumDictionary (TestingTweak) @@ -89,7 +87,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:1U]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused uint32_t aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -159,7 +158,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused uint32_t aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -448,7 +448,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:1U]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused uint32_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -518,7 +519,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused uint32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -807,7 +809,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:1U]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused uint32_t aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -877,7 +880,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused uint32_t aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1166,7 +1170,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:1U]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused uint32_t aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1236,7 +1241,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused uint32_t aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1525,7 +1531,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:1U]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused uint32_t aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1595,7 +1602,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused uint32_t aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1884,7 +1892,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:1U]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused uint32_t aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1954,7 +1963,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused uint32_t aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2243,7 +2253,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:1U]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused uint32_t aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2313,7 +2324,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused uint32_t aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2602,7 +2614,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getEnum:NULL forKey:1U]); - [dict enumerateKeysAndEnumsUsingBlock:^(__unused uint32_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2672,7 +2685,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndEnumsUsingBlock:^(__unused uint32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3029,7 +3043,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndRawValuesUsingBlock:^(__unused uint32_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndRawValuesUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3378,7 +3393,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:1U]); - [dict enumerateKeysAndObjectsUsingBlock:^(__unused uint32_t aKey, __unused NSString* aObject, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -3438,7 +3454,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(__unused uint32_t aKey, __unused NSString* aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3656,5 +3673,6 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U) diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m index fe7d4fc..b5dd91e 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m @@ -34,10 +34,7 @@ #import "GPBDictionary.h" #import "GPBTestUtilities.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" - -// Disable clang-format for the macros. -// clang-format off +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" // Pull in the macros (using an external file because expanding all tests // in a single file makes a file that is failing to work with within Xcode. @@ -45,6 +42,7 @@ //%PDDM-EXPAND TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL) // This block of code is generated, do not edit it directly. +// clang-format off // To let the testing macros work, add some extra methods to simplify things. @interface GPBUInt64EnumDictionary (TestingTweak) @@ -89,7 +87,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt32:NULL forKey:31ULL]); - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused uint64_t aKey, __unused uint32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -159,7 +158,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt32sUsingBlock:^(__unused uint64_t aKey, __unused uint32_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -448,7 +448,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt32:NULL forKey:31ULL]); - [dict enumerateKeysAndInt32sUsingBlock:^(__unused uint64_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -518,7 +519,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt32sUsingBlock:^(__unused uint64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -807,7 +809,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getUInt64:NULL forKey:31ULL]); - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused uint64_t aKey, __unused uint64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -877,7 +880,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndUInt64sUsingBlock:^(__unused uint64_t aKey, __unused uint64_t aValue, BOOL *stop) { + [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1166,7 +1170,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getInt64:NULL forKey:31ULL]); - [dict enumerateKeysAndInt64sUsingBlock:^(__unused uint64_t aKey, __unused int64_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1236,7 +1241,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndInt64sUsingBlock:^(__unused uint64_t aKey, __unused int64_t aValue, BOOL *stop) { + [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1525,7 +1531,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getBool:NULL forKey:31ULL]); - [dict enumerateKeysAndBoolsUsingBlock:^(__unused uint64_t aKey, __unused BOOL aValue, __unused BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1595,7 +1602,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndBoolsUsingBlock:^(__unused uint64_t aKey, __unused BOOL aValue, BOOL *stop) { + [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -1884,7 +1892,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getFloat:NULL forKey:31ULL]); - [dict enumerateKeysAndFloatsUsingBlock:^(__unused uint64_t aKey, __unused float aValue, __unused BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -1954,7 +1963,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndFloatsUsingBlock:^(__unused uint64_t aKey, __unused float aValue, BOOL *stop) { + [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2243,7 +2253,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getDouble:NULL forKey:31ULL]); - [dict enumerateKeysAndDoublesUsingBlock:^(__unused uint64_t aKey, __unused double aValue, __unused BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2313,7 +2324,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndDoublesUsingBlock:^(__unused uint64_t aKey, __unused double aValue, BOOL *stop) { + [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -2602,7 +2614,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertFalse([dict getEnum:NULL forKey:31ULL]); - [dict enumerateKeysAndEnumsUsingBlock:^(__unused uint64_t aKey, __unused int32_t aValue, __unused BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -2672,7 +2685,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndEnumsUsingBlock:^(__unused uint64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3029,7 +3043,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndRawValuesUsingBlock:^(__unused uint64_t aKey, __unused int32_t aValue, BOOL *stop) { + [dict enumerateKeysAndRawValuesUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) { + #pragma unused(aKey, aValue) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3378,7 +3393,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { XCTAssertNotNil(dict); XCTAssertEqual(dict.count, 0U); XCTAssertNil([dict objectForKey:31ULL]); - [dict enumerateKeysAndObjectsUsingBlock:^(__unused uint64_t aKey, __unused NSString* aObject, __unused BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject, stop) XCTFail(@"Shouldn't get here!"); }]; [dict release]; @@ -3438,7 +3454,8 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { // Stopping the enumeration. idx = 0; - [dict enumerateKeysAndObjectsUsingBlock:^(__unused uint64_t aKey, __unused NSString* aObject, BOOL *stop) { + [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) { + #pragma unused(aKey, aObject) if (idx == 1) *stop = YES; XCTAssertNotEqual(idx, 2U); ++idx; @@ -3656,4 +3673,5 @@ static BOOL TestingEnum_IsValidValue(int32_t value) { @end +// clang-format on //%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL) diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests.m b/libs/protobuf/objectivec/Tests/GPBDictionaryTests.m index e5670d8..52b4b32 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests.m +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests.m @@ -56,17 +56,17 @@ XCTAssertTrue([dict isEqual:@{}]); XCTAssertTrue([dict isEqualToDictionary:@{}]); - XCTAssertFalse([dict isEqual:@{@"foo" : @"bar"}]); - XCTAssertFalse([dict isEqualToDictionary:@{@"foo" : @"bar"}]); + XCTAssertFalse([dict isEqual:@{ @"foo" : @"bar" }]); + XCTAssertFalse([dict isEqualToDictionary:@{ @"foo" : @"bar" }]); [dict setObject:@"bar" forKey:@"foo"]; XCTAssertFalse([dict isEqual:@{}]); XCTAssertFalse([dict isEqualToDictionary:@{}]); - XCTAssertTrue([dict isEqual:@{@"foo" : @"bar"}]); - XCTAssertTrue([dict isEqualToDictionary:@{@"foo" : @"bar"}]); - XCTAssertFalse([dict isEqual:@{@"bar" : @"baz"}]); - XCTAssertFalse([dict isEqualToDictionary:@{@"bar" : @"baz"}]); + XCTAssertTrue([dict isEqual:@{ @"foo" : @"bar" }]); + XCTAssertTrue([dict isEqualToDictionary:@{ @"foo" : @"bar" }]); + XCTAssertFalse([dict isEqual:@{ @"bar" : @"baz" }]); + XCTAssertFalse([dict isEqualToDictionary:@{ @"bar" : @"baz" }]); GPBAutocreatedDictionary *dict2 = [[GPBAutocreatedDictionary alloc] init]; @@ -90,14 +90,14 @@ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init]; NSDictionary *cpy = [dict copy]; - XCTAssertTrue(cpy != dict); // Ptr compare + XCTAssertTrue(cpy != dict); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy.count, (NSUInteger)0); NSDictionary *cpy2 = [dict copy]; - XCTAssertTrue(cpy2 != dict); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != dict); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy2.count, (NSUInteger)0); @@ -111,14 +111,14 @@ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init]; NSMutableDictionary *cpy = [dict mutableCopy]; - XCTAssertTrue(cpy != dict); // Ptr compare + XCTAssertTrue(cpy != dict); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy.count, (NSUInteger)0); NSMutableDictionary *cpy2 = [dict mutableCopy]; - XCTAssertTrue(cpy2 != dict); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != dict); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy2.count, (NSUInteger)0); @@ -134,7 +134,7 @@ dict[@"baz"] = @"mumble"; NSDictionary *cpy = [dict copy]; - XCTAssertTrue(cpy != dict); // Ptr compare + XCTAssertTrue(cpy != dict); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy.count, (NSUInteger)2); @@ -142,8 +142,8 @@ XCTAssertEqualObjects(cpy[@"baz"], @"mumble"); NSDictionary *cpy2 = [dict copy]; - XCTAssertTrue(cpy2 != dict); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != dict); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy2.count, (NSUInteger)2); @@ -161,7 +161,7 @@ dict[@"baz"] = @"mumble"; NSMutableDictionary *cpy = [dict mutableCopy]; - XCTAssertTrue(cpy != dict); // Ptr compare + XCTAssertTrue(cpy != dict); // Ptr compare XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]); XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy.count, (NSUInteger)2); @@ -169,8 +169,8 @@ XCTAssertEqualObjects(cpy[@"baz"], @"mumble"); NSMutableDictionary *cpy2 = [dict mutableCopy]; - XCTAssertTrue(cpy2 != dict); // Ptr compare - XCTAssertTrue(cpy2 != cpy); // Ptr compare + XCTAssertTrue(cpy2 != dict); // Ptr compare + XCTAssertTrue(cpy2 != cpy); // Ptr compare XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]); XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(cpy2.count, (NSUInteger)2); diff --git a/libs/protobuf/objectivec/Tests/GPBDictionaryTests.pddm b/libs/protobuf/objectivec/Tests/GPBDictionaryTests.pddm index 11c08ec..17f12c2 100644 --- a/libs/protobuf/objectivec/Tests/GPBDictionaryTests.pddm +++ b/libs/protobuf/objectivec/Tests/GPBDictionaryTests.pddm @@ -70,7 +70,8 @@ //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 0U); //%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1) -//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(__unused KEY_TYPE KisP##aKey, __unused VALUE_TYPE a##VNAME$u, __unused BOOL *stop) { +//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) { +//% #pragma unused(aKey, a##VNAME$u, stop) //% XCTFail(@"Shouldn't get here!"); //% }]; //% [dict release]; @@ -130,7 +131,8 @@ //% //% // Stopping the enumeration. //% idx = 0; -//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(__unused KEY_TYPE KisP##aKey, __unused VALUE_TYPE a##VNAME$u, BOOL *stop) { +//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) { +//% #pragma unused(aKey, a##VNAME$u) //% if (idx == 1) *stop = YES; //% XCTAssertNotEqual(idx, 2U); //% ++idx; @@ -423,7 +425,8 @@ //% //% // Stopping the enumeration. //% idx = 0; -//% [dict enumerateKeysAndRawValuesUsingBlock:^(__unused KEY_TYPE KisP##aKey, __unused VALUE_TYPE aValue, BOOL *stop) { +//% [dict enumerateKeysAndRawValuesUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) { +//% #pragma unused(aKey, aValue) //% if (idx == 1) *stop = YES; //% XCTAssertNotEqual(idx, 2U); //% ++idx; @@ -787,7 +790,8 @@ //% XCTAssertNotNil(dict); //% XCTAssertEqual(dict.count, 0U); //%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1) -//% [dict enumerateKeysAnd##VALUE_NAME##sUsingBlock:^(__unused KEY_TYPE KisP##aKey, __unused VALUE_TYPE a##VNAME$u##, __unused BOOL *stop) { +//% [dict enumerateKeysAnd##VALUE_NAME##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) { +//% #pragma unused(aKey, a##VNAME$u##, stop) //% XCTFail(@"Shouldn't get here!"); //% }]; //% [dict release]; @@ -845,7 +849,8 @@ //% //% // Stopping the enumeration. //% idx = 0; -//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(__unused KEY_TYPE KisP##aKey, __unused VALUE_TYPE a##VNAME$u##, BOOL *stop) { +//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) { +//% #pragma unused(aKey, a##VNAME$u) //% if (idx == 0) *stop = YES; //% XCTAssertNotEqual(idx, 2U); //% ++idx; diff --git a/libs/protobuf/objectivec/Tests/GPBExtensionRegistryTest.m b/libs/protobuf/objectivec/Tests/GPBExtensionRegistryTest.m index bdd237b..b116882 100644 --- a/libs/protobuf/objectivec/Tests/GPBExtensionRegistryTest.m +++ b/libs/protobuf/objectivec/Tests/GPBExtensionRegistryTest.m @@ -31,7 +31,7 @@ #import "GPBTestUtilities.h" #import "GPBExtensionRegistry.h" -#import "objectivec/Tests/Unittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" @interface GPBExtensionRegistryTest : GPBTestCase @end @@ -42,17 +42,20 @@ GPBExtensionRegistry *reg = [[[GPBExtensionRegistry alloc] init] autorelease]; XCTAssertNotNil(reg); - XCTAssertNil([reg extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1]); - XCTAssertNil([reg extensionForDescriptor:[TestAllTypes descriptor] fieldNumber:1]); + XCTAssertNil([reg extensionForDescriptor:[TestAllExtensions descriptor] + fieldNumber:1]); + XCTAssertNil([reg extensionForDescriptor:[TestAllTypes descriptor] + fieldNumber:1]); [reg addExtension:[UnittestRoot optionalInt32Extension]]; [reg addExtension:[UnittestRoot packedInt64Extension]]; XCTAssertTrue([reg extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1] == - [UnittestRoot optionalInt32Extension]); // ptr equality - XCTAssertNil([reg extensionForDescriptor:[TestAllTypes descriptor] fieldNumber:1]); + [UnittestRoot optionalInt32Extension]); // ptr equality + XCTAssertNil([reg extensionForDescriptor:[TestAllTypes descriptor] + fieldNumber:1]); XCTAssertTrue([reg extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:91] == - [UnittestRoot packedInt64Extension]); // ptr equality + [UnittestRoot packedInt64Extension]); // ptr equality } - (void)testCopy { @@ -63,9 +66,9 @@ XCTAssertNotNil(reg2); XCTAssertTrue([reg1 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1] == - [UnittestRoot optionalInt32Extension]); // ptr equality + [UnittestRoot optionalInt32Extension]); // ptr equality XCTAssertTrue([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1] == - [UnittestRoot optionalInt32Extension]); // ptr equality + [UnittestRoot optionalInt32Extension]); // ptr equality // Message class that had registered extension(s) at the -copy time. @@ -73,11 +76,11 @@ [reg2 addExtension:[UnittestRoot optionalStringExtension]]; XCTAssertTrue([reg1 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:13] == - [UnittestRoot optionalBoolExtension]); // ptr equality + [UnittestRoot optionalBoolExtension]); // ptr equality XCTAssertNil([reg1 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:14]); XCTAssertNil([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:13]); XCTAssertTrue([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:14] == - [UnittestRoot optionalStringExtension]); // ptr equality + [UnittestRoot optionalStringExtension]); // ptr equality // Message class that did not have any registered extensions at the -copy time. @@ -85,11 +88,12 @@ [reg2 addExtension:[UnittestRoot packedSint32Extension]]; XCTAssertTrue([reg1 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:91] == - [UnittestRoot packedInt64Extension]); // ptr equality + [UnittestRoot packedInt64Extension]); // ptr equality XCTAssertNil([reg1 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:94]); XCTAssertNil([reg2 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:91]); XCTAssertTrue([reg2 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:94] == - [UnittestRoot packedSint32Extension]); // ptr equality + [UnittestRoot packedSint32Extension]); // ptr equality + } - (void)testAddExtensions { @@ -98,12 +102,13 @@ GPBExtensionRegistry *reg2 = [[[GPBExtensionRegistry alloc] init] autorelease]; - XCTAssertNil([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1]); + XCTAssertNil([reg2 extensionForDescriptor:[TestAllExtensions descriptor] + fieldNumber:1]); [reg2 addExtensions:reg1]; XCTAssertTrue([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:1] == - [UnittestRoot optionalInt32Extension]); // ptr equality + [UnittestRoot optionalInt32Extension]); // ptr equality // Confirm adding to the first doesn't add to the second. @@ -111,9 +116,9 @@ [reg1 addExtension:[UnittestRoot packedInt64Extension]]; XCTAssertTrue([reg1 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:13] == - [UnittestRoot optionalBoolExtension]); // ptr equality + [UnittestRoot optionalBoolExtension]); // ptr equality XCTAssertTrue([reg1 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:91] == - [UnittestRoot packedInt64Extension]); // ptr equality + [UnittestRoot packedInt64Extension]); // ptr equality XCTAssertNil([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:13]); XCTAssertNil([reg2 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:91]); @@ -125,9 +130,9 @@ XCTAssertNil([reg1 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:14]); XCTAssertNil([reg1 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:94]); XCTAssertTrue([reg2 extensionForDescriptor:[TestAllExtensions descriptor] fieldNumber:14] == - [UnittestRoot optionalStringExtension]); // ptr equality + [UnittestRoot optionalStringExtension]); // ptr equality XCTAssertTrue([reg2 extensionForDescriptor:[TestPackedExtensions descriptor] fieldNumber:94] == - [UnittestRoot packedSint32Extension]); // ptr equality + [UnittestRoot packedSint32Extension]); // ptr equality } @end diff --git a/libs/protobuf/objectivec/Tests/GPBMessageTests+ClassNames.m b/libs/protobuf/objectivec/Tests/GPBMessageTests+ClassNames.m index 1b656d0..b5a5c51 100644 --- a/libs/protobuf/objectivec/Tests/GPBMessageTests+ClassNames.m +++ b/libs/protobuf/objectivec/Tests/GPBMessageTests+ClassNames.m @@ -62,15 +62,15 @@ typedef struct MessageLackingClazz_storage_ { static GPBDescriptor *descriptor = nil; if (!descriptor) { static GPBMessageFieldDescription fields[] = { - { - .name = "foo", - .dataTypeSpecific.className = "NSString", - .number = 1, - .hasIndex = 0, - .offset = (uint32_t)offsetof(MessageLackingClazz_storage_, foo), - .flags = (GPBFieldFlags)(GPBFieldOptional), - .dataType = GPBDataTypeMessage, - }, + { + .name = "foo", + .dataTypeSpecific.className = "NSString", + .number = 1, + .hasIndex = 0, + .offset = (uint32_t)offsetof(MessageLackingClazz_storage_, foo), + .flags = (GPBFieldFlags)(GPBFieldOptional), + .dataType = GPBDataTypeMessage, + }, }; GPBFileDescriptor *desc = [[[GPBFileDescriptor alloc] initWithPackage:@"test" @@ -78,14 +78,14 @@ typedef struct MessageLackingClazz_storage_ { syntax:GPBFileSyntaxProto3] autorelease]; // GPBDescriptorInitializationFlag_UsesClassRefs intentionally not set here - descriptor = [GPBDescriptor - allocDescriptorForClass:[MessageLackingClazz class] - rootClass:[MessageLackingClazzRoot class] - file:desc - fields:fields - fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) - storageSize:sizeof(MessageLackingClazz_storage_) - flags:GPBDescriptorInitializationFlag_None]; + descriptor = + [GPBDescriptor allocDescriptorForClass:[MessageLackingClazz class] + rootClass:[MessageLackingClazzRoot class] + file:desc + fields:fields + fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) + storageSize:sizeof(MessageLackingClazz_storage_) + flags:GPBDescriptorInitializationFlag_None]; [descriptor setupContainingMessageClassName:"MessageLackingClazz"]; } return descriptor; @@ -94,24 +94,24 @@ typedef struct MessageLackingClazz_storage_ { @implementation MessageLackingClazzRoot -+ (GPBExtensionRegistry *)extensionRegistry { ++ (GPBExtensionRegistry*)extensionRegistry { // This is called by +initialize so there is no need to worry // about thread safety and initialization of registry. - static GPBExtensionRegistry *registry = nil; + static GPBExtensionRegistry* registry = nil; if (!registry) { registry = [[GPBExtensionRegistry alloc] init]; static GPBExtensionDescription descriptions[] = { - { - .defaultValue.valueMessage = NULL, - .singletonName = "MessageLackingClazzRoot_ext1", - .extendedClass.name = "MessageLackingClazz", - .messageOrGroupClass.name = "MessageLackingClazz", - .enumDescriptorFunc = NULL, - .fieldNumber = 1, - .dataType = GPBDataTypeMessage, - // GPBExtensionUsesClazz Intentionally not set - .options = 0, - }, + { + .defaultValue.valueMessage = NULL, + .singletonName = "MessageLackingClazzRoot_ext1", + .extendedClass.name = "MessageLackingClazz", + .messageOrGroupClass.name = "MessageLackingClazz", + .enumDescriptorFunc = NULL, + .fieldNumber = 1, + .dataType = GPBDataTypeMessage, + // GPBExtensionUsesClazz Intentionally not set + .options = 0, + }, }; for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) { // Intentionall using `-initWithExtensionDescription:` and not ` diff --git a/libs/protobuf/objectivec/Tests/GPBMessageTests+Merge.m b/libs/protobuf/objectivec/Tests/GPBMessageTests+Merge.m index a853419..f895542 100644 --- a/libs/protobuf/objectivec/Tests/GPBMessageTests+Merge.m +++ b/libs/protobuf/objectivec/Tests/GPBMessageTests+Merge.m @@ -34,11 +34,11 @@ #import "GPBMessage.h" -#import "objectivec/Tests/MapUnittest.pbobjc.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestPreserveUnknownEnum.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.h" +#import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" @interface MessageMergeTests : GPBTestCase @end @@ -197,8 +197,9 @@ // Known value. src.e = UnknownEnumsMyEnum_Bar; - src.repeatedEArray = [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue - rawValue:UnknownEnumsMyEnum_Bar]; + src.repeatedEArray = + [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue + rawValue:UnknownEnumsMyEnum_Bar]; src.repeatedPackedEArray = [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue rawValue:UnknownEnumsMyEnum_Bar]; @@ -210,7 +211,8 @@ XCTAssertEqual(dst.repeatedEArray.count, 1U); XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar); XCTAssertEqual(dst.repeatedPackedEArray.count, 1U); - XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar); + XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], + UnknownEnumsMyEnum_Bar); XCTAssertEqual(dst.oneofE1, UnknownEnumsMyEnum_Bar); // Unknown value. @@ -218,8 +220,9 @@ const int32_t kUnknownValue = 666; SetUnknownEnumsMyMessage_E_RawValue(src, kUnknownValue); - src.repeatedEArray = [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue - rawValue:kUnknownValue]; + src.repeatedEArray = + [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue + rawValue:kUnknownValue]; src.repeatedPackedEArray = [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue rawValue:kUnknownValue]; @@ -235,11 +238,13 @@ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); XCTAssertEqual([dst.repeatedEArray rawValueAtIndex:1], kUnknownValue); XCTAssertEqual(dst.repeatedPackedEArray.count, 2U); - XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar); + XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0], + UnknownEnumsMyEnum_Bar); XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:1], UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); XCTAssertEqual([dst.repeatedPackedEArray rawValueAtIndex:1], kUnknownValue); - XCTAssertEqual(dst.oneofE1, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); + XCTAssertEqual(dst.oneofE1, + UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(dst), kUnknownValue); } @@ -253,9 +258,6 @@ dst.oneofEnum = Message2_Enum_Bar; - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE MERGE2_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT) //% src.oneof##SET_NAME = SET_VALUE; //% [dst mergeFrom:src]; @@ -265,6 +267,7 @@ //% //%PDDM-EXPAND MERGE2_TEST(Int32, 10, Enum, Message2_Enum_Baz) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofInt32 = 10; [dst mergeFrom:src]; @@ -272,8 +275,10 @@ XCTAssertEqual(dst.oneofInt32, 10); XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Int64, 11, Int32, 100) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofInt64 = 11; [dst mergeFrom:src]; @@ -281,8 +286,10 @@ XCTAssertEqual(dst.oneofInt64, 11); XCTAssertEqual(dst.oneofInt32, 100); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Uint32, 12U, Int64, 101) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofUint32 = 12U; [dst mergeFrom:src]; @@ -290,8 +297,10 @@ XCTAssertEqual(dst.oneofUint32, 12U); XCTAssertEqual(dst.oneofInt64, 101); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Uint64, 13U, Uint32, 102U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofUint64 = 13U; [dst mergeFrom:src]; @@ -299,8 +308,10 @@ XCTAssertEqual(dst.oneofUint64, 13U); XCTAssertEqual(dst.oneofUint32, 102U); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Sint32, 14, Uint64, 103U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSint32 = 14; [dst mergeFrom:src]; @@ -308,8 +319,10 @@ XCTAssertEqual(dst.oneofSint32, 14); XCTAssertEqual(dst.oneofUint64, 103U); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Sint64, 15, Sint32, 104) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSint64 = 15; [dst mergeFrom:src]; @@ -317,8 +330,10 @@ XCTAssertEqual(dst.oneofSint64, 15); XCTAssertEqual(dst.oneofSint32, 104); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Fixed32, 16U, Sint64, 105) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFixed32 = 16U; [dst mergeFrom:src]; @@ -326,8 +341,10 @@ XCTAssertEqual(dst.oneofFixed32, 16U); XCTAssertEqual(dst.oneofSint64, 105); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Fixed64, 17U, Fixed32, 106U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFixed64 = 17U; [dst mergeFrom:src]; @@ -335,8 +352,10 @@ XCTAssertEqual(dst.oneofFixed64, 17U); XCTAssertEqual(dst.oneofFixed32, 106U); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Sfixed32, 18, Fixed64, 107U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSfixed32 = 18; [dst mergeFrom:src]; @@ -344,8 +363,10 @@ XCTAssertEqual(dst.oneofSfixed32, 18); XCTAssertEqual(dst.oneofFixed64, 107U); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Sfixed64, 19, Sfixed32, 108) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSfixed64 = 19; [dst mergeFrom:src]; @@ -353,8 +374,10 @@ XCTAssertEqual(dst.oneofSfixed64, 19); XCTAssertEqual(dst.oneofSfixed32, 108); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Float, 20.0f, Sfixed64, 109) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFloat = 20.0f; [dst mergeFrom:src]; @@ -362,8 +385,10 @@ XCTAssertEqual(dst.oneofFloat, 20.0f); XCTAssertEqual(dst.oneofSfixed64, 109); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Double, 21.0, Float, 110.0f) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofDouble = 21.0; [dst mergeFrom:src]; @@ -371,8 +396,10 @@ XCTAssertEqual(dst.oneofDouble, 21.0); XCTAssertEqual(dst.oneofFloat, 110.0f); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Bool, NO, Double, 111.0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofBool = NO; [dst mergeFrom:src]; @@ -380,8 +407,10 @@ XCTAssertEqual(dst.oneofBool, NO); XCTAssertEqual(dst.oneofDouble, 111.0); +// clang-format on //%PDDM-EXPAND MERGE2_TEST(Enum, Message2_Enum_Bar, Bool, YES) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofEnum = Message2_Enum_Bar; [dst mergeFrom:src]; @@ -389,10 +418,9 @@ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Bar); XCTAssertEqual(dst.oneofBool, YES); +// clang-format on //%PDDM-EXPAND-END (14 expansions) - // clang-format on - NSString *oneofStringDefault = @"string"; NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding]; @@ -405,7 +433,8 @@ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding]; [dst mergeFrom:src]; XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBytes); - XCTAssertEqualObjects(dst.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqualObjects(dst.oneofBytes, + [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); XCTAssertEqualObjects(dst.oneofString, oneofStringDefault); Message2_OneofGroup *group = [Message2_OneofGroup message]; @@ -477,9 +506,6 @@ dst.oneofEnum = Message3_Enum_Bar; - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE MERGE3_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT) //% src.oneof##SET_NAME = SET_VALUE; //% [dst mergeFrom:src]; @@ -489,6 +515,7 @@ //% //%PDDM-EXPAND MERGE3_TEST(Int32, 10, Enum, Message3_Enum_Foo) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofInt32 = 10; [dst mergeFrom:src]; @@ -496,8 +523,10 @@ XCTAssertEqual(dst.oneofInt32, 10); XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Int64, 11, Int32, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofInt64 = 11; [dst mergeFrom:src]; @@ -505,8 +534,10 @@ XCTAssertEqual(dst.oneofInt64, 11); XCTAssertEqual(dst.oneofInt32, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Uint32, 12U, Int64, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofUint32 = 12U; [dst mergeFrom:src]; @@ -514,8 +545,10 @@ XCTAssertEqual(dst.oneofUint32, 12U); XCTAssertEqual(dst.oneofInt64, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Uint64, 13U, Uint32, 0U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofUint64 = 13U; [dst mergeFrom:src]; @@ -523,8 +556,10 @@ XCTAssertEqual(dst.oneofUint64, 13U); XCTAssertEqual(dst.oneofUint32, 0U); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Sint32, 14, Uint64, 0U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSint32 = 14; [dst mergeFrom:src]; @@ -532,8 +567,10 @@ XCTAssertEqual(dst.oneofSint32, 14); XCTAssertEqual(dst.oneofUint64, 0U); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Sint64, 15, Sint32, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSint64 = 15; [dst mergeFrom:src]; @@ -541,8 +578,10 @@ XCTAssertEqual(dst.oneofSint64, 15); XCTAssertEqual(dst.oneofSint32, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Fixed32, 16U, Sint64, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFixed32 = 16U; [dst mergeFrom:src]; @@ -550,8 +589,10 @@ XCTAssertEqual(dst.oneofFixed32, 16U); XCTAssertEqual(dst.oneofSint64, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Fixed64, 17U, Fixed32, 0U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFixed64 = 17U; [dst mergeFrom:src]; @@ -559,8 +600,10 @@ XCTAssertEqual(dst.oneofFixed64, 17U); XCTAssertEqual(dst.oneofFixed32, 0U); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Sfixed32, 18, Fixed64, 0U) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSfixed32 = 18; [dst mergeFrom:src]; @@ -568,8 +611,10 @@ XCTAssertEqual(dst.oneofSfixed32, 18); XCTAssertEqual(dst.oneofFixed64, 0U); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Sfixed64, 19, Sfixed32, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofSfixed64 = 19; [dst mergeFrom:src]; @@ -577,8 +622,10 @@ XCTAssertEqual(dst.oneofSfixed64, 19); XCTAssertEqual(dst.oneofSfixed32, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Float, 20.0f, Sfixed64, 0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofFloat = 20.0f; [dst mergeFrom:src]; @@ -586,8 +633,10 @@ XCTAssertEqual(dst.oneofFloat, 20.0f); XCTAssertEqual(dst.oneofSfixed64, 0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Double, 21.0, Float, 0.0f) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofDouble = 21.0; [dst mergeFrom:src]; @@ -595,8 +644,10 @@ XCTAssertEqual(dst.oneofDouble, 21.0); XCTAssertEqual(dst.oneofFloat, 0.0f); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Bool, YES, Double, 0.0) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofBool = YES; [dst mergeFrom:src]; @@ -604,8 +655,10 @@ XCTAssertEqual(dst.oneofBool, YES); XCTAssertEqual(dst.oneofDouble, 0.0); +// clang-format on //%PDDM-EXPAND MERGE3_TEST(Enum, Message3_Enum_Bar, Bool, NO) // This block of code is generated, do not edit it directly. +// clang-format off src.oneofEnum = Message3_Enum_Bar; [dst mergeFrom:src]; @@ -613,10 +666,9 @@ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Bar); XCTAssertEqual(dst.oneofBool, NO); +// clang-format on //%PDDM-EXPAND-END (14 expansions) - // clang-format on - NSString *oneofStringDefault = @""; NSData *oneofBytesDefault = [NSData data]; @@ -629,9 +681,11 @@ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding]; [dst mergeFrom:src]; XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBytes); - XCTAssertEqualObjects(dst.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqualObjects(dst.oneofBytes, + [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); XCTAssertEqualObjects(dst.oneofString, oneofStringDefault); + Message3 *subMessage = [Message3 message]; subMessage.optionalInt32 = 777; src.oneofMessage = subMessage; diff --git a/libs/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m b/libs/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m index 3bcfae0..baad082 100644 --- a/libs/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m +++ b/libs/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m @@ -34,12 +34,12 @@ #import "GPBMessage.h" -#import "objectivec/Tests/MapUnittest.pbobjc.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestCycle.pbobjc.h" -#import "objectivec/Tests/UnittestObjcStartup.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.h" +#import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestCycle.pbobjc.h" +#import "google/protobuf/UnittestObjcStartup.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" @interface MessageRuntimeTests : GPBTestCase @end @@ -98,10 +98,14 @@ for (NSString *name in names) { // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasOptional%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasOptional%@:", name]); - XCTAssertTrue([Message2 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertTrue([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasOptional%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasOptional%@:", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertTrue([Message2 instancesRespondToSelector:setHasSel], @"field: %@", + name); } // Repeated fields @@ -110,24 +114,33 @@ for (NSString *name in names) { // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasRepeated%@Array", name]); - SEL setHasSel = - NSSelectorFromString([NSString stringWithFormat:@"setHasRepeated%@Array:", name]); - XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasRepeated%@Array", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasRepeated%@Array:", name]); + XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], + @"field: %@", name); // build the selector, i.e. - repeatedInt32Array_Count - SEL countSel = NSSelectorFromString([NSString stringWithFormat:@"repeated%@Array_Count", name]); - XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", name); + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"repeated%@Array_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); } // OneOf fields - no has*/setHas* for (NSString *name in names) { // build the selector, i.e. - hasOneofInt32/setHasOneofInt32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasOneof%@:", name]); - XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = + NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasOneof%@:", name]); + XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], + @"field: %@", name); } // map<> fields @@ -135,23 +148,44 @@ // - *Count NSArray *mapNames = @[ - @"Int32Int32", @"Int64Int64", @"Uint32Uint32", @"Uint64Uint64", - @"Sint32Sint32", @"Sint64Sint64", @"Fixed32Fixed32", @"Fixed64Fixed64", - @"Sfixed32Sfixed32", @"Sfixed64Sfixed64", @"Int32Float", @"Int32Double", - @"BoolBool", @"StringString", @"StringBytes", @"StringMessage", - @"Int32Bytes", @"Int32Enum", @"Int32Message", + @"Int32Int32", + @"Int64Int64", + @"Uint32Uint32", + @"Uint64Uint64", + @"Sint32Sint32", + @"Sint64Sint64", + @"Fixed32Fixed32", + @"Fixed64Fixed64", + @"Sfixed32Sfixed32", + @"Sfixed64Sfixed64", + @"Int32Float", + @"Int32Double", + @"BoolBool", + @"StringString", + @"StringBytes", + @"StringMessage", + @"Int32Bytes", + @"Int32Enum", + @"Int32Message", ]; for (NSString *name in mapNames) { // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasMap%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasMap%@:", name]); - XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasMap%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasMap%@:", name]); + XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], + @"field: %@", name); // build the selector, i.e. - mapInt32Int32Count - SEL countSel = NSSelectorFromString([NSString stringWithFormat:@"map%@_Count", name]); - XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", name); + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"map%@_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); } + } - (void)testProto3HasMethodSupport { @@ -183,15 +217,21 @@ for (NSString *name in names) { // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasOptional%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasOptional%@:", name]); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasOptional%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasOptional%@:", name]); if ([name isEqual:@"Message"]) { // Sub messages/groups are the exception. - XCTAssertTrue([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertTrue([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + XCTAssertTrue([Message3 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertTrue([Message3 instancesRespondToSelector:setHasSel], + @"field: %@", name); } else { - XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], + @"field: %@", name); } } @@ -201,24 +241,33 @@ for (NSString *name in names) { // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasRepeated%@Array", name]); - SEL setHasSel = - NSSelectorFromString([NSString stringWithFormat:@"setHasRepeated%@Array:", name]); - XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasRepeated%@Array", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasRepeated%@Array:", name]); + XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], + @"field: %@", name); // build the selector, i.e. - repeatedInt32Array_Count - SEL countSel = NSSelectorFromString([NSString stringWithFormat:@"repeated%@Array_Count", name]); - XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@", name); + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"repeated%@Array_Count", name]); + XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@", + name); } // OneOf fields - no has*/setHas* for (NSString *name in names) { // build the selector, i.e. - hasOneofInt32/setHasOneofInt32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasOneof%@:", name]); - XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = + NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasOneof%@:", name]); + XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], + @"field: %@", name); } // Single Optional fields @@ -228,10 +277,14 @@ for (NSString *name in names) { // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasOptional%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasOptional%@:", name]); - XCTAssertTrue([Message3Optional instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertTrue([Message3Optional instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasOptional%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasOptional%@:", name]); + XCTAssertTrue([Message3Optional instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertTrue([Message3Optional instancesRespondToSelector:setHasSel], + @"field: %@", name); } // map<> fields @@ -239,22 +292,42 @@ // - *Count NSArray *mapNames = @[ - @"Int32Int32", @"Int64Int64", @"Uint32Uint32", @"Uint64Uint64", - @"Sint32Sint32", @"Sint64Sint64", @"Fixed32Fixed32", @"Fixed64Fixed64", - @"Sfixed32Sfixed32", @"Sfixed64Sfixed64", @"Int32Float", @"Int32Double", - @"BoolBool", @"StringString", @"StringBytes", @"StringMessage", - @"Int32Bytes", @"Int32Enum", @"Int32Message", + @"Int32Int32", + @"Int64Int64", + @"Uint32Uint32", + @"Uint64Uint64", + @"Sint32Sint32", + @"Sint64Sint64", + @"Fixed32Fixed32", + @"Fixed64Fixed64", + @"Sfixed32Sfixed32", + @"Sfixed64Sfixed64", + @"Int32Float", + @"Int32Double", + @"BoolBool", + @"StringString", + @"StringBytes", + @"StringMessage", + @"Int32Bytes", + @"Int32Enum", + @"Int32Message", ]; for (NSString *name in mapNames) { // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32: - SEL hasSel = NSSelectorFromString([NSString stringWithFormat:@"hasMap%@", name]); - SEL setHasSel = NSSelectorFromString([NSString stringWithFormat:@"setHasMap%@:", name]); - XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); - XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasMap%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasMap%@:", name]); + XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], + @"field: %@", name); // build the selector, i.e. - mapInt32Int32Count - SEL countSel = NSSelectorFromString([NSString stringWithFormat:@"map%@_Count", name]); - XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@", name); + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"map%@_Count", name]); + XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@", + name); } } @@ -264,9 +337,6 @@ // being true. // - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE PROTO2_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE) //% { // optional##FIELD :: NON_ZERO_VALUE //% Message2 *msg = [[Message2 alloc] init]; @@ -329,6 +399,7 @@ //%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message2 message]) //%PDDM-EXPAND PROTO2_TEST_HAS_FIELDS() // This block of code is generated, do not edit it directly. +// clang-format off { // optionalInt32 :: 1 Message2 *msg = [[Message2 alloc] init]; @@ -682,9 +753,8 @@ [msg release]; } +// clang-format on //%PDDM-EXPAND-END PROTO2_TEST_HAS_FIELDS() - - // clang-format on } - (void)testProto3SingleFieldHasBehavior { @@ -693,9 +763,6 @@ // being true. When set to the default, shouldn't be true. // - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE PROTO3_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE) //% { // optional##FIELD //% Message3 *msg = [[Message3 alloc] init]; @@ -748,6 +815,7 @@ //%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message3 message]) //%PDDM-EXPAND PROTO3_TEST_HAS_FIELDS() // This block of code is generated, do not edit it directly. +// clang-format off { // optionalInt32 Message3 *msg = [[Message3 alloc] init]; @@ -947,9 +1015,8 @@ [msg release]; } +// clang-format on //%PDDM-EXPAND-END PROTO3_TEST_HAS_FIELDS() - - // clang-format on } - (void)testProto3SingleOptionalFieldHasBehavior { @@ -957,9 +1024,6 @@ // Setting to any value including the default (0) should result in true. // - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE PROTO3_TEST_OPTIONAL_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE) //% { // optional##FIELD //% Message3Optional *msg = [[Message3Optional alloc] init]; @@ -996,6 +1060,7 @@ //%PROTO3_TEST_OPTIONAL_HAS_FIELD(Enum, Message3Optional_Enum_Bar, Message3Optional_Enum_Foo) //%PDDM-EXPAND PROTO3_TEST_OPTIONAL_HAS_FIELDS() // This block of code is generated, do not edit it directly. +// clang-format off { // optionalInt32 Message3Optional *msg = [[Message3Optional alloc] init]; @@ -1193,9 +1258,8 @@ [msg release]; } +// clang-format on //%PDDM-EXPAND-END PROTO3_TEST_OPTIONAL_HAS_FIELDS() - - // clang-format on } - (void)testAccessingProto2UnknownEnumValues { @@ -1204,11 +1268,13 @@ // Set it to something non zero, try and confirm it doesn't change. msg.optionalEnum = Message2_Enum_Bar; - XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException, + NSInvalidArgumentException); XCTAssertEqual(msg.optionalEnum, Message2_Enum_Bar); msg.oneofEnum = Message2_Enum_Bar; - XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException, + NSInvalidArgumentException); XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar); [msg release]; @@ -1220,17 +1286,20 @@ // Set it to something non zero, try and confirm it doesn't change. msg.optionalEnum = Message3_Enum_Bar; - XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException, + NSInvalidArgumentException); XCTAssertEqual(msg.optionalEnum, Message3_Enum_Bar); msg.oneofEnum = Message3_Enum_Bar; - XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException, + NSInvalidArgumentException); XCTAssertEqual(msg.oneofEnum, Message3_Enum_Bar); // Set via raw api to confirm it works. SetMessage3_OptionalEnum_RawValue(msg, 666); - XCTAssertEqual(msg.optionalEnum, Message3_Enum_GPBUnrecognizedEnumeratorValue); + XCTAssertEqual(msg.optionalEnum, + Message3_Enum_GPBUnrecognizedEnumeratorValue); XCTAssertEqual(Message3_OptionalEnum_RawValue(msg), 666); SetMessage3_OneofEnum_RawValue(msg, 666); @@ -1594,7 +1663,8 @@ XCTAssertEqual(msg.oneofDouble, 111.0); XCTAssertEqual(msg.oneofBool, YES); XCTAssertEqualObjects(msg.oneofString, oneofStringDefault); - XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqualObjects(msg.oneofBytes, + [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); XCTAssertNotNil(msg.oneofGroup); XCTAssertNotNil(msg.oneofMessage); XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz); @@ -1677,15 +1747,24 @@ msg = [[Message2 alloc] init]; int32_t values[] = { - Message2_O_OneOfCase_OneofInt32, Message2_O_OneOfCase_OneofInt64, - Message2_O_OneOfCase_OneofUint32, Message2_O_OneOfCase_OneofUint64, - Message2_O_OneOfCase_OneofSint32, Message2_O_OneOfCase_OneofSint64, - Message2_O_OneOfCase_OneofFixed32, Message2_O_OneOfCase_OneofFixed64, - Message2_O_OneOfCase_OneofSfixed32, Message2_O_OneOfCase_OneofSfixed64, - Message2_O_OneOfCase_OneofFloat, Message2_O_OneOfCase_OneofDouble, - Message2_O_OneOfCase_OneofBool, Message2_O_OneOfCase_OneofString, - Message2_O_OneOfCase_OneofBytes, Message2_O_OneOfCase_OneofGroup, - Message2_O_OneOfCase_OneofMessage, Message2_O_OneOfCase_OneofEnum, + Message2_O_OneOfCase_OneofInt32, + Message2_O_OneOfCase_OneofInt64, + Message2_O_OneOfCase_OneofUint32, + Message2_O_OneOfCase_OneofUint64, + Message2_O_OneOfCase_OneofSint32, + Message2_O_OneOfCase_OneofSint64, + Message2_O_OneOfCase_OneofFixed32, + Message2_O_OneOfCase_OneofFixed64, + Message2_O_OneOfCase_OneofSfixed32, + Message2_O_OneOfCase_OneofSfixed64, + Message2_O_OneOfCase_OneofFloat, + Message2_O_OneOfCase_OneofDouble, + Message2_O_OneOfCase_OneofBool, + Message2_O_OneOfCase_OneofString, + Message2_O_OneOfCase_OneofBytes, + Message2_O_OneOfCase_OneofGroup, + Message2_O_OneOfCase_OneofMessage, + Message2_O_OneOfCase_OneofEnum, }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { @@ -1753,7 +1832,8 @@ // No need to check the value was set, the above tests did that. Message2_ClearOOneOfCase(msg); // Nothing in the case. - XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase, "Loop: %zd", i); + XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase, + "Loop: %zd", i); // Confirm everything is back to defaults after a clear. XCTAssertEqual(msg.oneofInt32, 100, "Loop: %zd", i); XCTAssertEqual(msg.oneofInt64, 101, "Loop: %zd", i); @@ -2121,7 +2201,8 @@ XCTAssertEqual(msg.oneofDouble, 0.0); XCTAssertEqual(msg.oneofBool, NO); XCTAssertEqualObjects(msg.oneofString, oneofStringDefault); - XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); + XCTAssertEqualObjects(msg.oneofBytes, + [@"bar" dataUsingEncoding:NSUTF8StringEncoding]); XCTAssertNotNil(msg.oneofMessage); XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo); XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes); @@ -2176,15 +2257,23 @@ msg = [[Message3 alloc] init]; int32_t values[] = { - Message3_O_OneOfCase_OneofInt32, Message3_O_OneOfCase_OneofInt64, - Message3_O_OneOfCase_OneofUint32, Message3_O_OneOfCase_OneofUint64, - Message3_O_OneOfCase_OneofSint32, Message3_O_OneOfCase_OneofSint64, - Message3_O_OneOfCase_OneofFixed32, Message3_O_OneOfCase_OneofFixed64, - Message3_O_OneOfCase_OneofSfixed32, Message3_O_OneOfCase_OneofSfixed64, - Message3_O_OneOfCase_OneofFloat, Message3_O_OneOfCase_OneofDouble, - Message3_O_OneOfCase_OneofBool, Message3_O_OneOfCase_OneofString, - Message3_O_OneOfCase_OneofBytes, Message3_O_OneOfCase_OneofMessage, - Message3_O_OneOfCase_OneofEnum, + Message3_O_OneOfCase_OneofInt32, + Message3_O_OneOfCase_OneofInt64, + Message3_O_OneOfCase_OneofUint32, + Message3_O_OneOfCase_OneofUint64, + Message3_O_OneOfCase_OneofSint32, + Message3_O_OneOfCase_OneofSint64, + Message3_O_OneOfCase_OneofFixed32, + Message3_O_OneOfCase_OneofFixed64, + Message3_O_OneOfCase_OneofSfixed32, + Message3_O_OneOfCase_OneofSfixed64, + Message3_O_OneOfCase_OneofFloat, + Message3_O_OneOfCase_OneofDouble, + Message3_O_OneOfCase_OneofBool, + Message3_O_OneOfCase_OneofString, + Message3_O_OneOfCase_OneofBytes, + Message3_O_OneOfCase_OneofMessage, + Message3_O_OneOfCase_OneofEnum, }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { @@ -2249,7 +2338,8 @@ // No need to check the value was set, the above tests did that. Message3_ClearOOneOfCase(msg); // Nothing in the case. - XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase, "Loop: %zd", i); + XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase, + "Loop: %zd", i); // Confirm everything is back to defaults after a clear. XCTAssertEqual(msg.oneofInt32, 0, "Loop: %zd", i); XCTAssertEqual(msg.oneofInt64, 0, "Loop: %zd", i); @@ -2276,6 +2366,7 @@ } - (void)testProto2OneofSetToDefault { + // proto3 doesn't normally write out zero (default) fields, but if they are // in a oneof it does. proto2 doesn't have this special behavior, but we // still confirm setting to the explicit default does set the case to be @@ -2287,24 +2378,24 @@ Message2 *msg = [[Message2 alloc] init]; int32_t values[] = { - Message2_O_OneOfCase_OneofInt32, - Message2_O_OneOfCase_OneofInt64, - Message2_O_OneOfCase_OneofUint32, - Message2_O_OneOfCase_OneofUint64, - Message2_O_OneOfCase_OneofSint32, - Message2_O_OneOfCase_OneofSint64, - Message2_O_OneOfCase_OneofFixed32, - Message2_O_OneOfCase_OneofFixed64, - Message2_O_OneOfCase_OneofSfixed32, - Message2_O_OneOfCase_OneofSfixed64, - Message2_O_OneOfCase_OneofFloat, - Message2_O_OneOfCase_OneofDouble, - Message2_O_OneOfCase_OneofBool, - Message2_O_OneOfCase_OneofString, - Message2_O_OneOfCase_OneofBytes, - // Skip group - // Skip message - Message2_O_OneOfCase_OneofEnum, + Message2_O_OneOfCase_OneofInt32, + Message2_O_OneOfCase_OneofInt64, + Message2_O_OneOfCase_OneofUint32, + Message2_O_OneOfCase_OneofUint64, + Message2_O_OneOfCase_OneofSint32, + Message2_O_OneOfCase_OneofSint64, + Message2_O_OneOfCase_OneofFixed32, + Message2_O_OneOfCase_OneofFixed64, + Message2_O_OneOfCase_OneofSfixed32, + Message2_O_OneOfCase_OneofSfixed64, + Message2_O_OneOfCase_OneofFloat, + Message2_O_OneOfCase_OneofDouble, + Message2_O_OneOfCase_OneofBool, + Message2_O_OneOfCase_OneofString, + Message2_O_OneOfCase_OneofBytes, + // Skip group + // Skip message + Message2_O_OneOfCase_OneofEnum, }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { @@ -2405,6 +2496,7 @@ } - (void)testProto3OneofSetToZero { + // Normally setting a proto3 field to the zero value should result in it being // reset/cleared. But in a oneof, it still gets recorded so it can go out // over the wire and the other side can see what was set in the oneof. @@ -2415,15 +2507,23 @@ Message3 *msg = [[Message3 alloc] init]; int32_t values[] = { - Message3_O_OneOfCase_OneofInt32, Message3_O_OneOfCase_OneofInt64, - Message3_O_OneOfCase_OneofUint32, Message3_O_OneOfCase_OneofUint64, - Message3_O_OneOfCase_OneofSint32, Message3_O_OneOfCase_OneofSint64, - Message3_O_OneOfCase_OneofFixed32, Message3_O_OneOfCase_OneofFixed64, - Message3_O_OneOfCase_OneofSfixed32, Message3_O_OneOfCase_OneofSfixed64, - Message3_O_OneOfCase_OneofFloat, Message3_O_OneOfCase_OneofDouble, - Message3_O_OneOfCase_OneofBool, Message3_O_OneOfCase_OneofString, - Message3_O_OneOfCase_OneofBytes, Message3_O_OneOfCase_OneofMessage, - Message3_O_OneOfCase_OneofEnum, + Message3_O_OneOfCase_OneofInt32, + Message3_O_OneOfCase_OneofInt64, + Message3_O_OneOfCase_OneofUint32, + Message3_O_OneOfCase_OneofUint64, + Message3_O_OneOfCase_OneofSint32, + Message3_O_OneOfCase_OneofSint64, + Message3_O_OneOfCase_OneofFixed32, + Message3_O_OneOfCase_OneofFixed64, + Message3_O_OneOfCase_OneofSfixed32, + Message3_O_OneOfCase_OneofSfixed64, + Message3_O_OneOfCase_OneofFloat, + Message3_O_OneOfCase_OneofDouble, + Message3_O_OneOfCase_OneofBool, + Message3_O_OneOfCase_OneofString, + Message3_O_OneOfCase_OneofBytes, + Message3_O_OneOfCase_OneofMessage, + Message3_O_OneOfCase_OneofEnum, }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { @@ -2554,19 +2654,27 @@ XCTAssertNotEqual(msg1.repeatedStringArray, msg2.repeatedStringArray); XCTAssertNotEqual(msg1.repeatedBytesArray, msg2.repeatedBytesArray); XCTAssertNotEqual(msg1.repeatedGroupArray, msg2.repeatedGroupArray); - XCTAssertNotEqual(msg1.repeatedNestedMessageArray, msg2.repeatedNestedMessageArray); - XCTAssertNotEqual(msg1.repeatedForeignMessageArray, msg2.repeatedForeignMessageArray); - XCTAssertNotEqual(msg1.repeatedImportMessageArray, msg2.repeatedImportMessageArray); + XCTAssertNotEqual(msg1.repeatedNestedMessageArray, + msg2.repeatedNestedMessageArray); + XCTAssertNotEqual(msg1.repeatedForeignMessageArray, + msg2.repeatedForeignMessageArray); + XCTAssertNotEqual(msg1.repeatedImportMessageArray, + msg2.repeatedImportMessageArray); XCTAssertNotEqual(msg1.repeatedNestedEnumArray, msg2.repeatedNestedEnumArray); - XCTAssertNotEqual(msg1.repeatedForeignEnumArray, msg2.repeatedForeignEnumArray); + XCTAssertNotEqual(msg1.repeatedForeignEnumArray, + msg2.repeatedForeignEnumArray); XCTAssertNotEqual(msg1.repeatedImportEnumArray, msg2.repeatedImportEnumArray); - XCTAssertNotEqual(msg1.repeatedStringPieceArray, msg2.repeatedStringPieceArray); + XCTAssertNotEqual(msg1.repeatedStringPieceArray, + msg2.repeatedStringPieceArray); XCTAssertNotEqual(msg1.repeatedCordArray, msg2.repeatedCordArray); for (int i = 0; i < repeatCount; i++) { - XCTAssertNotEqual(msg1.repeatedNestedMessageArray[i], msg2.repeatedNestedMessageArray[i]); - XCTAssertNotEqual(msg1.repeatedForeignMessageArray[i], msg2.repeatedForeignMessageArray[i]); - XCTAssertNotEqual(msg1.repeatedImportMessageArray[i], msg2.repeatedImportMessageArray[i]); + XCTAssertNotEqual(msg1.repeatedNestedMessageArray[i], + msg2.repeatedNestedMessageArray[i]); + XCTAssertNotEqual(msg1.repeatedForeignMessageArray[i], + msg2.repeatedForeignMessageArray[i]); + XCTAssertNotEqual(msg1.repeatedImportMessageArray[i], + msg2.repeatedImportMessageArray[i]); } } @@ -2600,7 +2708,8 @@ // Ensure the messages are unique per map. [msg1.mapInt32ForeignMessage - enumerateKeysAndObjectsUsingBlock:^(int32_t key, id value, __unused BOOL *stop) { + enumerateKeysAndObjectsUsingBlock:^(int32_t key, id value, BOOL *stop) { +#pragma unused(stop) ForeignMessage *subMsg2 = [msg2.mapInt32ForeignMessage objectForKey:key]; XCTAssertNotEqual(value, subMsg2); // Ptr compare, new object. }]; @@ -2611,7 +2720,7 @@ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"]; XCTAssertNotNil(fieldDescriptor); NSMutableArray *fieldArray = GPBGetMessageRepeatedField(message, fieldDescriptor); - XCTAssertNotNil(fieldArray); // Should have autocreated. + XCTAssertNotNil(fieldArray); // Should have autocreated. XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer } @@ -2631,7 +2740,7 @@ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"]; XCTAssertNotNil(fieldDescriptor); NSMutableDictionary *fieldMap = GPBGetMessageMapField(message, fieldDescriptor); - XCTAssertNotNil(fieldMap); // Should have autocreated. + XCTAssertNotNil(fieldMap); // Should have autocreated. XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer } diff --git a/libs/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m b/libs/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m index 3c2381c..bb63ec3 100644 --- a/libs/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m +++ b/libs/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m @@ -34,12 +34,13 @@ #import "GPBMessage.h" -#import "objectivec/Tests/MapProto2Unittest.pbobjc.h" -#import "objectivec/Tests/MapUnittest.pbobjc.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestPreserveUnknownEnum.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.h" +#import "google/protobuf/MapProto2Unittest.pbobjc.h" +#import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h" +#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" @interface MessageSerializationTests : GPBTestCase @end @@ -113,9 +114,6 @@ // Proto3 optionals should be just like proto2, zero values also get serialized. // - // Disable clang-format for the macros. - // clang-format off - //%PDDM-DEFINE PROTO3_TEST_SERIALIZE_OPTIONAL_FIELD(FIELD, ZERO_VALUE, EXPECTED_LEN) //% { // optional##FIELD //% Message3Optional *msg = [[Message3Optional alloc] init]; @@ -156,6 +154,7 @@ //%PROTO3_TEST_SERIALIZE_OPTIONAL_FIELD(Enum, Message3Optional_Enum_Foo, 3) //%PDDM-EXPAND PROTO3_TEST_SERIALIZE_OPTIONAL_FIELDS() // This block of code is generated, do not edit it directly. +// clang-format off { // optionalInt32 Message3Optional *msg = [[Message3Optional alloc] init]; @@ -417,17 +416,17 @@ [msg release]; } +// clang-format on //%PDDM-EXPAND-END PROTO3_TEST_SERIALIZE_OPTIONAL_FIELDS() - - // clang-format on } - (void)testProto2UnknownEnumToUnknownField { Message3 *orig = [[Message3 alloc] init]; orig.optionalEnum = Message3_Enum_Extra3; - orig.repeatedEnumArray = [GPBEnumArray arrayWithValidationFunction:Message3_Enum_IsValidValue - rawValue:Message3_Enum_Extra3]; + orig.repeatedEnumArray = + [GPBEnumArray arrayWithValidationFunction:Message3_Enum_IsValidValue + rawValue:Message3_Enum_Extra3]; orig.oneofEnum = Message3_Enum_Extra3; NSData *data = [orig data]; @@ -446,12 +445,15 @@ XCTAssertEqual([unknownFields countOfFields], 3U); XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OptionalEnum]); - XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_RepeatedEnumArray]); + XCTAssertTrue( + [unknownFields hasField:Message2_FieldNumber_RepeatedEnumArray]); XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OneofEnum]); - GPBUnknownField *field = [unknownFields getField:Message2_FieldNumber_OptionalEnum]; + GPBUnknownField *field = + [unknownFields getField:Message2_FieldNumber_OptionalEnum]; XCTAssertEqual(field.varintList.count, 1U); - XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); + XCTAssertEqual([field.varintList valueAtIndex:0], + (uint64_t)Message3_Enum_Extra3); field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray]; XCTAssertEqual(field.varintList.count, 1U); @@ -459,32 +461,36 @@ field = [unknownFields getField:Message2_FieldNumber_OneofEnum]; XCTAssertEqual(field.varintList.count, 1U); - XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); + XCTAssertEqual([field.varintList valueAtIndex:0], + (uint64_t)Message3_Enum_Extra3); [msg release]; [orig release]; } - (void)testProto3UnknownEnumPreserving { - UnknownEnumsMyMessagePlusExtra *orig = [UnknownEnumsMyMessagePlusExtra message]; + UnknownEnumsMyMessagePlusExtra *orig = + [UnknownEnumsMyMessagePlusExtra message]; orig.e = UnknownEnumsMyEnumPlusExtra_EExtra; - orig.repeatedEArray = - [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue - rawValue:UnknownEnumsMyEnumPlusExtra_EExtra]; - orig.repeatedPackedEArray = - [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue - rawValue:UnknownEnumsMyEnumPlusExtra_EExtra]; + orig.repeatedEArray = [GPBEnumArray + arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue + rawValue:UnknownEnumsMyEnumPlusExtra_EExtra]; + orig.repeatedPackedEArray = [GPBEnumArray + arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue + rawValue:UnknownEnumsMyEnumPlusExtra_EExtra]; orig.oneofE1 = UnknownEnumsMyEnumPlusExtra_EExtra; // Everything should be there via raw values. NSData *data = [orig data]; XCTAssertNotNil(data); - UnknownEnumsMyMessage *msg = [UnknownEnumsMyMessage parseFromData:data error:NULL]; + UnknownEnumsMyMessage *msg = + [UnknownEnumsMyMessage parseFromData:data error:NULL]; XCTAssertEqual(msg.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); - XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg), UnknownEnumsMyEnumPlusExtra_EExtra); + XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg), + UnknownEnumsMyEnumPlusExtra_EExtra); XCTAssertEqual(msg.repeatedEArray.count, 1U); XCTAssertEqual([msg.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); @@ -495,8 +501,10 @@ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); XCTAssertEqual([msg.repeatedPackedEArray rawValueAtIndex:0], (UnknownEnumsMyEnum)UnknownEnumsMyEnumPlusExtra_EExtra); - XCTAssertEqual(msg.oneofE1, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); - XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(msg), UnknownEnumsMyEnumPlusExtra_EExtra); + XCTAssertEqual(msg.oneofE1, + UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue); + XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(msg), + UnknownEnumsMyEnumPlusExtra_EExtra); // Everything should go out and come back. @@ -505,15 +513,14 @@ XCTAssertEqual(orig.e, UnknownEnumsMyEnumPlusExtra_EExtra); XCTAssertEqual(orig.repeatedEArray.count, 1U); - XCTAssertEqual([orig.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnumPlusExtra_EExtra); + XCTAssertEqual([orig.repeatedEArray valueAtIndex:0], + UnknownEnumsMyEnumPlusExtra_EExtra); XCTAssertEqual(orig.repeatedPackedEArray.count, 1U); - XCTAssertEqual([orig.repeatedPackedEArray valueAtIndex:0], UnknownEnumsMyEnumPlusExtra_EExtra); + XCTAssertEqual([orig.repeatedPackedEArray valueAtIndex:0], + UnknownEnumsMyEnumPlusExtra_EExtra); XCTAssertEqual(orig.oneofE1, UnknownEnumsMyEnumPlusExtra_EExtra); } -// Disable clang-format for the macros. -// clang-format off - //%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF(MESSAGE, FIELD, VALUE) //%TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, ) //%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, EQ_SUFFIX) @@ -577,6 +584,7 @@ //% //%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(2, NO) // This block of code is generated, do not edit it directly. +// clang-format off - (void)testProto2RoundTripOneof { @@ -807,8 +815,10 @@ [subMessage release]; } +// clang-format on //%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(3, YES) // This block of code is generated, do not edit it directly. +// clang-format off - (void)testProto3RoundTripOneof { @@ -1025,9 +1035,8 @@ [subMessage release]; } -//%PDDM-EXPAND-END (2 expansions) - // clang-format on +//%PDDM-EXPAND-END (2 expansions) - (void)testPackedUnpackedMessageParsing { // packed is optional, a repeated field should parse when packed or unpacked. @@ -1045,13 +1054,15 @@ @"Data should differ (packed vs unpacked) use"); NSError *error = nil; - TestPackedTypes *packedParse = [TestPackedTypes parseFromData:unpackedData error:&error]; + TestPackedTypes *packedParse = + [TestPackedTypes parseFromData:unpackedData error:&error]; XCTAssertNotNil(packedParse); XCTAssertNil(error); XCTAssertEqualObjects(packedParse, packedOrig); error = nil; - TestUnpackedTypes *unpackedParsed = [TestUnpackedTypes parseFromData:packedData error:&error]; + TestUnpackedTypes *unpackedParsed = + [TestUnpackedTypes parseFromData:packedData error:&error]; XCTAssertNotNil(unpackedParsed); XCTAssertNil(error); XCTAssertEqualObjects(unpackedParsed, unpackedOrig); @@ -1108,7 +1119,8 @@ XCTAssertEqualObjects(fieldsData, extsData); NSError *error = nil; - TestPackedTypes *fieldsParse = [TestPackedTypes parseFromData:extsData error:&error]; + TestPackedTypes *fieldsParse = + [TestPackedTypes parseFromData:extsData error:&error]; XCTAssertNotNil(fieldsParse); XCTAssertNil(error); XCTAssertEqualObjects(fieldsParse, fieldsOrig); @@ -1138,7 +1150,8 @@ XCTAssertNotNil(extsData); XCTAssertEqualObjects(fieldsData, extsData); - TestUnpackedTypes *fieldsParse = [TestUnpackedTypes parseFromData:extsData error:NULL]; + TestUnpackedTypes *fieldsParse = + [TestUnpackedTypes parseFromData:extsData error:NULL]; XCTAssertNotNil(fieldsParse); XCTAssertEqualObjects(fieldsParse, fieldsOrig); @@ -1151,9 +1164,11 @@ } - (void)testErrorSubsectionInvalidLimit { - NSData *data = DataFromCStr("\x0A\x08\x0A\x07\x12\x04\x72\x02\x4B\x50\x12\x04\x72\x02\x4B\x50"); + NSData *data = DataFromCStr( + "\x0A\x08\x0A\x07\x12\x04\x72\x02\x4B\x50\x12\x04\x72\x02\x4B\x50"); NSError *error = nil; - NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data error:&error]; + NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data + error:&error]; XCTAssertNil(msg); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain); @@ -1163,7 +1178,8 @@ - (void)testErrorSubsectionLimitReached { NSData *data = DataFromCStr("\x0A\x06\x12\x03\x72\x02\x4B\x50"); NSError *error = nil; - NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data error:&error]; + NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data + error:&error]; XCTAssertNil(msg); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain); @@ -1193,7 +1209,8 @@ - (void)testErrorInvalidSize { NSData *data = DataFromCStr("\x72\x03\x4B\x50"); NSError *error = nil; - NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data error:&error]; + NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data + error:&error]; XCTAssertNil(msg); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain); @@ -1203,7 +1220,8 @@ - (void)testErrorInvalidTag { NSData *data = DataFromCStr("\x0F"); NSError *error = nil; - NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data error:&error]; + NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data + error:&error]; XCTAssertNil(msg); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain); @@ -1213,7 +1231,12 @@ - (void)testZeroFieldNum { // These are ConformanceTestSuite::TestIllegalTags. - const char *tests[] = {"\1DEADBEEF", "\2\1\1", "\3\4", "\5DEAD"}; + const char *tests[] = { + "\1DEADBEEF", + "\2\1\1", + "\3\4", + "\5DEAD" + }; for (size_t i = 0; i < GPBARRAYSIZE(tests); ++i) { NSData *data = DataFromCStr(tests[i]); @@ -1241,25 +1264,27 @@ } - (void)testErrorRecursionDepthReached { - NSData *data = DataFromCStr("\x0A\xF2\x01\x0A\xEF\x01\x0A\xEC\x01\x0A\xE9\x01\x0A\xE6\x01" - "\x0A\xE3\x01\x0A\xE0\x01\x0A\xDD\x01\x0A\xDA\x01\x0A\xD7\x01" - "\x0A\xD4\x01\x0A\xD1\x01\x0A\xCE\x01\x0A\xCB\x01\x0A\xC8\x01" - "\x0A\xC5\x01\x0A\xC2\x01\x0A\xBF\x01\x0A\xBC\x01\x0A\xB9\x01" - "\x0A\xB6\x01\x0A\xB3\x01\x0A\xB0\x01\x0A\xAD\x01\x0A\xAA\x01" - "\x0A\xA7\x01\x0A\xA4\x01\x0A\xA1\x01\x0A\x9E\x01\x0A\x9B\x01" - "\x0A\x98\x01\x0A\x95\x01\x0A\x92\x01\x0A\x8F\x01\x0A\x8C\x01" - "\x0A\x89\x01\x0A\x86\x01\x0A\x83\x01\x0A\x80\x01\x0A\x7E" - "\x0A\x7C\x0A\x7A\x0A\x78\x0A\x76\x0A\x74\x0A\x72\x0A\x70" - "\x0A\x6E\x0A\x6C\x0A\x6A\x0A\x68\x0A\x66\x0A\x64\x0A\x62" - "\x0A\x60\x0A\x5E\x0A\x5C\x0A\x5A\x0A\x58\x0A\x56\x0A\x54" - "\x0A\x52\x0A\x50\x0A\x4E\x0A\x4C\x0A\x4A\x0A\x48\x0A\x46" - "\x0A\x44\x0A\x42\x0A\x40\x0A\x3E\x0A\x3C\x0A\x3A\x0A\x38" - "\x0A\x36\x0A\x34\x0A\x32\x0A\x30\x0A\x2E\x0A\x2C\x0A\x2A" - "\x0A\x28\x0A\x26\x0A\x24\x0A\x22\x0A\x20\x0A\x1E\x0A\x1C" - "\x0A\x1A\x0A\x18\x0A\x16\x0A\x14\x0A\x12\x0A\x10\x0A\x0E" - "\x0A\x0C\x0A\x0A\x0A\x08\x0A\x06\x12\x04\x72\x02\x4B\x50"); + NSData *data = DataFromCStr( + "\x0A\xF2\x01\x0A\xEF\x01\x0A\xEC\x01\x0A\xE9\x01\x0A\xE6\x01" + "\x0A\xE3\x01\x0A\xE0\x01\x0A\xDD\x01\x0A\xDA\x01\x0A\xD7\x01" + "\x0A\xD4\x01\x0A\xD1\x01\x0A\xCE\x01\x0A\xCB\x01\x0A\xC8\x01" + "\x0A\xC5\x01\x0A\xC2\x01\x0A\xBF\x01\x0A\xBC\x01\x0A\xB9\x01" + "\x0A\xB6\x01\x0A\xB3\x01\x0A\xB0\x01\x0A\xAD\x01\x0A\xAA\x01" + "\x0A\xA7\x01\x0A\xA4\x01\x0A\xA1\x01\x0A\x9E\x01\x0A\x9B\x01" + "\x0A\x98\x01\x0A\x95\x01\x0A\x92\x01\x0A\x8F\x01\x0A\x8C\x01" + "\x0A\x89\x01\x0A\x86\x01\x0A\x83\x01\x0A\x80\x01\x0A\x7E" + "\x0A\x7C\x0A\x7A\x0A\x78\x0A\x76\x0A\x74\x0A\x72\x0A\x70" + "\x0A\x6E\x0A\x6C\x0A\x6A\x0A\x68\x0A\x66\x0A\x64\x0A\x62" + "\x0A\x60\x0A\x5E\x0A\x5C\x0A\x5A\x0A\x58\x0A\x56\x0A\x54" + "\x0A\x52\x0A\x50\x0A\x4E\x0A\x4C\x0A\x4A\x0A\x48\x0A\x46" + "\x0A\x44\x0A\x42\x0A\x40\x0A\x3E\x0A\x3C\x0A\x3A\x0A\x38" + "\x0A\x36\x0A\x34\x0A\x32\x0A\x30\x0A\x2E\x0A\x2C\x0A\x2A" + "\x0A\x28\x0A\x26\x0A\x24\x0A\x22\x0A\x20\x0A\x1E\x0A\x1C" + "\x0A\x1A\x0A\x18\x0A\x16\x0A\x14\x0A\x12\x0A\x10\x0A\x0E" + "\x0A\x0C\x0A\x0A\x0A\x08\x0A\x06\x12\x04\x72\x02\x4B\x50"); NSError *error = nil; - NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data error:&error]; + NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data + error:&error]; XCTAssertNil(msg); XCTAssertNotNil(error); XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain); @@ -1270,7 +1295,9 @@ NSData *data = DataFromCStr("\xFF\xFF\xFF\xFF\x0F"); GPBCodedInputStream *input = [GPBCodedInputStream streamWithData:data]; NSError *error; - [GPBMessage parseDelimitedFromCodedInputStream:input extensionRegistry:nil error:&error]; + [GPBMessage parseDelimitedFromCodedInputStream:input + extensionRegistry:nil + error:&error]; XCTAssertNil(error); } @@ -1406,8 +1433,10 @@ initWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue] autorelease]; orig.unknownMapField = [[[GPBInt32EnumDictionary alloc] initWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue] autorelease]; - [orig.knownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumFoo forKey:0]; - [orig.unknownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumExtra forKey:0]; + [orig.knownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumFoo + forKey:0]; + [orig.unknownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumExtra + forKey:0]; NSData *data = [orig data]; XCTAssertNotNil(data); @@ -1419,7 +1448,8 @@ XCTAssertEqual(msg1.unknownFields.countOfFields, 1U); data = [msg1 data]; - TestEnumMapPlusExtra *msg2 = [TestEnumMapPlusExtra parseFromData:data error:NULL]; + TestEnumMapPlusExtra *msg2 = + [TestEnumMapPlusExtra parseFromData:data error:NULL]; val = -1; XCTAssertEqual(msg2.knownMapField.count, 1U); XCTAssertTrue([msg2.knownMapField getEnum:&val forKey:0]); diff --git a/libs/protobuf/objectivec/Tests/GPBMessageTests.m b/libs/protobuf/objectivec/Tests/GPBMessageTests.m index 7d4cf79..b2c75ba 100644 --- a/libs/protobuf/objectivec/Tests/GPBMessageTests.m +++ b/libs/protobuf/objectivec/Tests/GPBMessageTests.m @@ -36,12 +36,12 @@ #import "GPBDescriptor.h" #import "GPBDictionary_PackagePrivate.h" #import "GPBMessage_PackagePrivate.h" -#import "GPBUnknownFieldSet_PackagePrivate.h" #import "GPBUnknownField_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestImport.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" -#import "objectivec/Tests/UnittestObjcOptions.pbobjc.h" +#import "GPBUnknownFieldSet_PackagePrivate.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" +#import "google/protobuf/UnittestObjcOptions.pbobjc.h" +#import "google/protobuf/UnittestImport.pbobjc.h" // Helper class to test KVO. @interface GPBKVOTestObserver : NSObject { @@ -49,7 +49,7 @@ NSString *keyPath_; } -@property(nonatomic) BOOL didObserve; +@property (nonatomic) BOOL didObserve; - (id)initWithObservee:(id)observee keyPath:(NSString *)keyPath; @end @@ -74,9 +74,13 @@ } - (void)observeValueForKeyPath:(NSString *)keyPath - ofObject:(__unused id)object - change:(__unused NSDictionary *)change - context:(__unused void *)context { + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context +{ +#pragma unused(object) +#pragma unused(change) +#pragma unused(context) if ([keyPath isEqualToString:keyPath_]) { self.didObserve = YES; } @@ -152,9 +156,12 @@ [message setExtension:[UnittestRoot optionalStringExtension] value:@"foo"]; ForeignMessage *foreignMessage = [ForeignMessage message]; foreignMessage.c = 4; - [message setExtension:[UnittestRoot optionalForeignMessageExtension] value:foreignMessage]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; + [message setExtension:[UnittestRoot optionalForeignMessageExtension] + value:foreignMessage]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nestedMessage]; return message; } @@ -163,10 +170,13 @@ [message setExtension:[UnittestRoot optionalInt64Extension] value:@6]; [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"]; ForeignMessage *foreignMessage = [ForeignMessage message]; - [message setExtension:[UnittestRoot optionalForeignMessageExtension] value:foreignMessage]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + [message setExtension:[UnittestRoot optionalForeignMessageExtension] + value:foreignMessage]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; nestedMessage.bb = 7; - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nestedMessage]; return message; } @@ -177,10 +187,13 @@ [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"]; ForeignMessage *foreignMessage = [ForeignMessage message]; foreignMessage.c = 4; - [message setExtension:[UnittestRoot optionalForeignMessageExtension] value:foreignMessage]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + [message setExtension:[UnittestRoot optionalForeignMessageExtension] + value:foreignMessage]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; nestedMessage.bb = 7; - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nestedMessage]; return message; } @@ -198,9 +211,11 @@ result = [[self.mergeDestinationWithoutForeignMessageIvar copy] autorelease]; [result mergeFrom:self.mergeSource]; resultData = [result data]; - mergeResultData = [self.mergeResultForDestinationWithoutForeignMessageIvar data]; + mergeResultData = + [self.mergeResultForDestinationWithoutForeignMessageIvar data]; XCTAssertEqualObjects(resultData, mergeResultData); - XCTAssertEqualObjects(result, self.mergeResultForDestinationWithoutForeignMessageIvar); + XCTAssertEqualObjects( + result, self.mergeResultForDestinationWithoutForeignMessageIvar); // Test when destination is empty. // The result must is same as the source. @@ -224,7 +239,8 @@ result = [self mergeExtensionsDestination]; NSData *data = [[self mergeExtensionsSource] data]; XCTAssertNotNil(data); - [result mergeFromData:data extensionRegistry:[UnittestRoot extensionRegistry]]; + [result mergeFromData:data + extensionRegistry:[UnittestRoot extensionRegistry]]; resultData = [result data]; XCTAssertEqualObjects(resultData, mergeResultData); XCTAssertEqualObjects(result, [self mergeExtensionsResult]); @@ -290,13 +306,16 @@ [message setExtension:[TestRequired single] value:[TestRequired message]]; XCTAssertFalse(message.initialized); - [message setExtension:[TestRequired single] value:self.testRequiredInitialized]; + [message setExtension:[TestRequired single] + value:self.testRequiredInitialized]; XCTAssertTrue(message.initialized); [message addExtension:[TestRequired multi] value:[TestRequired message]]; XCTAssertFalse(message.initialized); - [message setExtension:[TestRequired multi] index:0 value:self.testRequiredInitialized]; + [message setExtension:[TestRequired multi] + index:0 + value:self.testRequiredInitialized]; XCTAssertTrue(message.initialized); } @@ -348,7 +367,8 @@ - (void)testParseUninitialized { NSError *error = nil; - TestRequired *msg = [TestRequired parseFromData:GPBEmptyNSData() error:&error]; + TestRequired *msg = + [TestRequired parseFromData:GPBEmptyNSData() error:&error]; // In DEBUG, the parse will fail, but in non DEBUG, it passes because // the check isn't done (for speed). #ifdef DEBUG @@ -368,7 +388,8 @@ - (void)testCoding { GPBMessage *original = [self mergeResult]; - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:original]; + NSData *data = + [NSKeyedArchiver archivedDataWithRootObject:original]; id unarchivedObject = [NSKeyedUnarchiver unarchiveObjectWithData:data]; XCTAssertEqualObjects(unarchivedObject, original); @@ -390,7 +411,8 @@ NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; [unarchiver setRequiresSecureCoding:YES]; - id unarchivedObject = [unarchiver decodeObjectOfClass:[GPBMessage class] forKey:key]; + id unarchivedObject = [unarchiver decodeObjectOfClass:[GPBMessage class] + forKey:key]; [unarchiver finishDecoding]; XCTAssertEqualObjects(unarchivedObject, original); @@ -463,7 +485,9 @@ - (void)testKVOBasic { TestAllTypes *message = [TestAllTypes message]; GPBKVOTestObserver *observer = - [[[GPBKVOTestObserver alloc] initWithObservee:message keyPath:@"optionalString"] autorelease]; + [[[GPBKVOTestObserver alloc] initWithObservee:message + keyPath:@"optionalString"] + autorelease]; XCTAssertFalse(observer.didObserve); message.defaultString = @"Hello"; XCTAssertFalse(observer.didObserve); @@ -475,10 +499,12 @@ TestAllTypes *message = [TestAllTypes message]; GPBKVOTestObserver *autocreateObserver = [[[GPBKVOTestObserver alloc] initWithObservee:message - keyPath:@"optionalImportMessage"] autorelease]; - GPBKVOTestObserver *innerFieldObserver = - [[[GPBKVOTestObserver alloc] initWithObservee:message - keyPath:@"optionalImportMessage.d"] autorelease]; + keyPath:@"optionalImportMessage"] + autorelease]; + GPBKVOTestObserver *innerFieldObserver = + [[[GPBKVOTestObserver alloc] initWithObservee:message + keyPath:@"optionalImportMessage.d"] + autorelease]; XCTAssertFalse(autocreateObserver.didObserve); XCTAssertFalse(innerFieldObserver.didObserve); @@ -510,8 +536,10 @@ TestAllTypes *message = [TestAllTypes message]; [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount]; - GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; - GPBUnknownField *field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; + GPBUnknownFieldSet *unknownFields = + [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownField *field = + [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field addVarint:2]; [unknownFields addField:field]; field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; @@ -539,7 +567,8 @@ TestAllTypes *message = [TestAllTypes message]; GPBDescriptor *descriptor = [[message class] descriptor]; XCTAssertNotNil(descriptor); - GPBFieldDescriptor *fieldDescriptor = [descriptor fieldWithName:@"defaultInt32"]; + GPBFieldDescriptor *fieldDescriptor = + [descriptor fieldWithName:@"defaultInt32"]; XCTAssertNotNil(fieldDescriptor); GPBGenericValue defaultValue = [fieldDescriptor defaultValue]; [message setDefaultInt32:defaultValue.valueInt32]; @@ -650,7 +679,8 @@ TestAllTypes *message = [TestAllTypes message]; [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount]; [self modifyRepeatedFields:message]; - [self assertRepeatedFieldsModified:message repeatedCount:kGPBDefaultRepeatCount]; + [self assertRepeatedFieldsModified:message + repeatedCount:kGPBDefaultRepeatCount]; } - (void)testClear { @@ -682,16 +712,19 @@ GPBMessage *message2 = [TestAllExtensions message]; [message2 addExtension:[UnittestRoot repeatedInt32Extension] value:@1]; - XCTAssertEqual([[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count], - (NSUInteger)1); + XCTAssertEqual( + [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count], + (NSUInteger)1); [message2 clearExtension:[UnittestRoot repeatedInt32Extension]]; - XCTAssertEqual([[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count], - (NSUInteger)0); + XCTAssertEqual( + [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count], + (NSUInteger)0); // Clearing an unset extension field shouldn't make the target message // visible. GPBMessage *message3 = [TestAllExtensions message]; - GPBMessage *extension_msg = [message3 getExtension:[UnittestObjcRoot recursiveExtension]]; + GPBMessage *extension_msg = + [message3 getExtension:[UnittestObjcRoot recursiveExtension]]; XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]); [extension_msg clearExtension:[UnittestRoot optionalInt32Extension]]; XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]); @@ -712,11 +745,15 @@ // They should auto create something when fetched. TestAllTypes_OptionalGroup *optionalGroup = [message.optionalGroup retain]; - TestAllTypes_NestedMessage *optionalNestedMessage = [message.optionalNestedMessage retain]; - ForeignMessage *optionalForeignMessage = [message.optionalForeignMessage retain]; + TestAllTypes_NestedMessage *optionalNestedMessage = + [message.optionalNestedMessage retain]; + ForeignMessage *optionalForeignMessage = + [message.optionalForeignMessage retain]; ImportMessage *optionalImportMessage = [message.optionalImportMessage retain]; - PublicImportMessage *optionalPublicImportMessage = [message.optionalPublicImportMessage retain]; - TestAllTypes_NestedMessage *optionalLazyMessage = [message.optionalLazyMessage retain]; + PublicImportMessage *optionalPublicImportMessage = + [message.optionalPublicImportMessage retain]; + TestAllTypes_NestedMessage *optionalLazyMessage = + [message.optionalLazyMessage retain]; XCTAssertNotNil(optionalGroup); XCTAssertNotNil(optionalNestedMessage); @@ -742,7 +779,8 @@ XCTAssertEqual(message.optionalNestedMessage, optionalNestedMessage); XCTAssertEqual(message.optionalForeignMessage, optionalForeignMessage); XCTAssertEqual(message.optionalImportMessage, optionalImportMessage); - XCTAssertEqual(message.optionalPublicImportMessage, optionalPublicImportMessage); + XCTAssertEqual(message.optionalPublicImportMessage, + optionalPublicImportMessage); XCTAssertEqual(message.optionalLazyMessage, optionalLazyMessage); // And the default objects for a second message should be distinct (again, @@ -755,7 +793,8 @@ XCTAssertNotEqual(message2.optionalNestedMessage, optionalNestedMessage); XCTAssertNotEqual(message2.optionalForeignMessage, optionalForeignMessage); XCTAssertNotEqual(message2.optionalImportMessage, optionalImportMessage); - XCTAssertNotEqual(message2.optionalPublicImportMessage, optionalPublicImportMessage); + XCTAssertNotEqual(message2.optionalPublicImportMessage, + optionalPublicImportMessage); XCTAssertNotEqual(message2.optionalLazyMessage, optionalLazyMessage); // Setting the values to nil will clear the has flag, and on next access you @@ -780,7 +819,8 @@ XCTAssertNotEqual(message.optionalNestedMessage, optionalNestedMessage); XCTAssertNotEqual(message.optionalForeignMessage, optionalForeignMessage); XCTAssertNotEqual(message.optionalImportMessage, optionalImportMessage); - XCTAssertNotEqual(message.optionalPublicImportMessage, optionalPublicImportMessage); + XCTAssertNotEqual(message.optionalPublicImportMessage, + optionalPublicImportMessage); XCTAssertNotEqual(message.optionalLazyMessage, optionalLazyMessage); [optionalGroup release]; @@ -813,7 +853,8 @@ XCTAssertFalse([message2 hasOptionalNestedMessage]); // Intentionally doing a pointer comparison. - XCTAssertNotEqual(message.optionalNestedMessage, message2.optionalNestedMessage); + XCTAssertNotEqual(message.optionalNestedMessage, + message2.optionalNestedMessage); } - (void)testClearAutocreatedSubmessage { @@ -839,9 +880,10 @@ ForeignMessage *subMessage; @autoreleasepool { TestAllTypes *message2 = [TestAllTypes message]; - subMessage = message2.optionalForeignMessage; // Autocreated + subMessage = message2.optionalForeignMessage; // Autocreated message.optionalForeignMessage = subMessage; - XCTAssertTrue(GPBWasMessageAutocreatedBy(message.optionalForeignMessage, message2)); + XCTAssertTrue(GPBWasMessageAutocreatedBy(message.optionalForeignMessage, + message2)); } // Should be the same object, and should still be live. @@ -977,7 +1019,8 @@ // Setting autocreated submessage to another value should cause the old one to // lose its creator. TestAllTypes *message = [TestAllTypes message]; - TestAllTypes_NestedMessage *nestedMessage = [message.optionalNestedMessage retain]; + TestAllTypes_NestedMessage *nestedMessage = + [message.optionalNestedMessage retain]; message.optionalNestedMessage = [TestAllTypes_NestedMessage message]; XCTAssertTrue([message hasOptionalNestedMessage]); @@ -996,7 +1039,8 @@ XCTAssertNil(message.optionalNestedMessage.unknownFields); XCTAssertFalse([message hasOptionalNestedMessage]); - GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *unknownFields = + [[[GPBUnknownFieldSet alloc] init] autorelease]; message.optionalNestedMessage.unknownFields = unknownFields; XCTAssertTrue([message hasOptionalNestedMessage]); @@ -1045,8 +1089,10 @@ - (void)testDefaultingArrays { // Basic tests for default creation of arrays in a message. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; - TestRecursiveMessageWithRepeatedField *message2 = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message2 = + [TestRecursiveMessageWithRepeatedField message]; // Simply accessing the array should not make any fields visible. XCTAssertNotNil(message.a.a.iArray); @@ -1113,9 +1159,11 @@ XCTAssertNotNil(message.repeatedStringArray); TestAllTypes *message4 = [[message3 copy] autorelease]; XCTAssertNotEqual(message3.repeatedInt32Array, message4.repeatedInt32Array); - XCTAssertEqualObjects(message3.repeatedInt32Array, message4.repeatedInt32Array); + XCTAssertEqualObjects(message3.repeatedInt32Array, + message4.repeatedInt32Array); XCTAssertNotEqual(message3.repeatedStringArray, message4.repeatedStringArray); - XCTAssertEqualObjects(message3.repeatedStringArray, message4.repeatedStringArray); + XCTAssertEqualObjects(message3.repeatedStringArray, + message4.repeatedStringArray); } - (void)testAutocreatedArrayRetain { @@ -1128,13 +1176,18 @@ message.repeatedStringArray = message2.repeatedStringArray; // Pointer conparision XCTAssertEqual(message.repeatedInt32Array->_autocreator, message2); - XCTAssertTrue([message.repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]); - XCTAssertEqual(((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator, message2); + XCTAssertTrue([message.repeatedStringArray + isKindOfClass:[GPBAutocreatedArray class]]); + XCTAssertEqual( + ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator, + message2); } XCTAssertNil(message.repeatedInt32Array->_autocreator); - XCTAssertTrue([message.repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]); - XCTAssertNil(((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator); + XCTAssertTrue( + [message.repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]); + XCTAssertNil( + ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator); } - (void)testSetNilAutocreatedArray { @@ -1192,7 +1245,8 @@ XCTAssertNotNil(message.a); XCTAssertNotNil(message.a.strArray); XCTAssertFalse([message hasA]); - GPBAutocreatedArray *strArray = (GPBAutocreatedArray *)[message.a.strArray retain]; + GPBAutocreatedArray *strArray = + (GPBAutocreatedArray *)[message.a.strArray retain]; XCTAssertTrue([strArray isKindOfClass:[GPBAutocreatedArray class]]); XCTAssertEqual(strArray->_autocreator, message.a); // Pointer comparison message.a.strArray = [NSMutableArray arrayWithObject:@"foo"]; @@ -1232,7 +1286,8 @@ - (void)testAutocreatedArrayRemoveAllValues { // Calling removeAllValues on autocreated array should not cause it to be // visible. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; [message.a.iArray removeAll]; XCTAssertFalse([message hasA]); [message.a.strArray removeAllObjects]; @@ -1241,8 +1296,10 @@ - (void)testDefaultingMaps { // Basic tests for default creation of maps in a message. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; - TestRecursiveMessageWithRepeatedField *message2 = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message2 = + [TestRecursiveMessageWithRepeatedField message]; // Simply accessing the map should not make any fields visible. XCTAssertNotNil(message.a.a.iToI); @@ -1292,23 +1349,28 @@ - (void)testAutocreatedMapCopy { // Copy should not copy autocreated maps. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; XCTAssertNotNil(message.strToStr); XCTAssertNotNil(message.iToI); - TestRecursiveMessageWithRepeatedField *message2 = [[message copy] autorelease]; + TestRecursiveMessageWithRepeatedField *message2 = + [[message copy] autorelease]; // Pointer conparisions. XCTAssertNotEqual(message.strToStr, message2.strToStr); XCTAssertNotEqual(message.iToI, message2.iToI); // Mutable copy should copy empty arrays that were explicitly set (end up // with different objects that are equal). - TestRecursiveMessageWithRepeatedField *message3 = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message3 = + [TestRecursiveMessageWithRepeatedField message]; message3.iToI = [[[GPBInt32Int32Dictionary alloc] init] autorelease]; [message3.iToI setInt32:10 forKey:20]; - message3.strToStr = [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"123"]; + message3.strToStr = + [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"123"]; XCTAssertNotNil(message.iToI); XCTAssertNotNil(message.iToI); - TestRecursiveMessageWithRepeatedField *message4 = [[message3 copy] autorelease]; + TestRecursiveMessageWithRepeatedField *message4 = + [[message3 copy] autorelease]; XCTAssertNotEqual(message3.iToI, message4.iToI); XCTAssertEqualObjects(message3.iToI, message4.iToI); XCTAssertNotEqual(message3.strToStr, message4.strToStr); @@ -1317,7 +1379,8 @@ - (void)testAutocreatedMapRetain { // Should be able to retain autocreated map while the creator is dealloced. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; @autoreleasepool { TestRecursiveMessageWithRepeatedField *message2 = @@ -1326,20 +1389,27 @@ message.strToStr = message2.strToStr; // Pointer conparision XCTAssertEqual(message.iToI->_autocreator, message2); - XCTAssertTrue([message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]); - XCTAssertEqual(((GPBAutocreatedDictionary *)message.strToStr)->_autocreator, message2); + XCTAssertTrue([message.strToStr + isKindOfClass:[GPBAutocreatedDictionary class]]); + XCTAssertEqual( + ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator, + message2); } XCTAssertNil(message.iToI->_autocreator); - XCTAssertTrue([message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]); - XCTAssertNil(((GPBAutocreatedDictionary *)message.strToStr)->_autocreator); + XCTAssertTrue( + [message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]); + XCTAssertNil( + ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator); } - (void)testSetNilAutocreatedMap { // Setting map to nil should cause it to lose its delegate. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; GPBInt32Int32Dictionary *iToI = [message.iToI retain]; - GPBAutocreatedDictionary *strToStr = (GPBAutocreatedDictionary *)[message.strToStr retain]; + GPBAutocreatedDictionary *strToStr = + (GPBAutocreatedDictionary *)[message.strToStr retain]; XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(iToI->_autocreator, message); XCTAssertEqual(strToStr->_autocreator, message); @@ -1356,13 +1426,15 @@ // an autocreated one or a straight NSDictionary. // The real test here is that nothing crashes while doing the work. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; message.strToStr[@"foo"] = @"bar"; XCTAssertEqual(message.strToStr_Count, (NSUInteger)1); message.strToStr = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"bar", @"key1", @"baz", @"key2", nil]; XCTAssertEqual(message.strToStr_Count, (NSUInteger)2); - message.strToStr = [NSMutableDictionary dictionaryWithObject:@"baz" forKey:@"mumble"]; + message.strToStr = + [NSMutableDictionary dictionaryWithObject:@"baz" forKey:@"mumble"]; XCTAssertEqual(message.strToStr_Count, (NSUInteger)1); } @@ -1391,10 +1463,12 @@ XCTAssertNotNil(message.a); XCTAssertNotNil(message.a.strToStr); XCTAssertFalse([message hasA]); - GPBAutocreatedDictionary *strToStr = (GPBAutocreatedDictionary *)[message.a.strToStr retain]; + GPBAutocreatedDictionary *strToStr = + (GPBAutocreatedDictionary *)[message.a.strToStr retain]; XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]); XCTAssertEqual(strToStr->_autocreator, message.a); // Pointer comparison - message.a.strToStr = [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"def"]; + message.a.strToStr = + [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"def"]; XCTAssertTrue([message hasA]); XCTAssertNotEqual(message.a.strToStr, strToStr); // Pointer comparison XCTAssertNil(strToStr->_autocreator); @@ -1430,7 +1504,8 @@ - (void)testAutocreatedMapRemoveAllValues { // Calling removeAll on autocreated map should not cause it to be visible. - TestRecursiveMessageWithRepeatedField *message = [TestRecursiveMessageWithRepeatedField message]; + TestRecursiveMessageWithRepeatedField *message = + [TestRecursiveMessageWithRepeatedField message]; [message.a.iToI removeAll]; XCTAssertFalse([message hasA]); [message.a.strToStr removeAllObjects]; @@ -1447,7 +1522,8 @@ TestAllExtensions *message = [TestAllExtensions message]; [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount]; [self modifyRepeatedExtensions:message]; - [self assertRepeatedExtensionsModified:message repeatedCount:kGPBDefaultRepeatCount]; + [self assertRepeatedExtensionsModified:message + repeatedCount:kGPBDefaultRepeatCount]; } - (void)testExtensionDefaults { @@ -1488,11 +1564,16 @@ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]); XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalLazyMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalImportMessageExtension]]); + XCTAssertFalse([message + hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]); // They should auto create something when fetched. @@ -1504,8 +1585,8 @@ [message getExtension:[UnittestRoot optionalForeignMessageExtension]]; ImportMessage *optionalImportMessage = [message getExtension:[UnittestRoot optionalImportMessageExtension]]; - PublicImportMessage *optionalPublicImportMessage = - [message getExtension:[UnittestRoot optionalPublicImportMessageExtension]]; + PublicImportMessage *optionalPublicImportMessage = [message + getExtension:[UnittestRoot optionalPublicImportMessageExtension]]; TestAllTypes_NestedMessage *optionalLazyMessage = [message getExtension:[UnittestRoot optionalLazyMessageExtension]]; @@ -1530,17 +1611,23 @@ // And they set that value back in to the message since the value created was // mutable (so a second fetch should give the same object). - XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]], optionalGroup); - XCTAssertEqual([message getExtension:[UnittestRoot optionalNestedMessageExtension]], - optionalNestedMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalForeignMessageExtension]], - optionalForeignMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalImportMessageExtension]], - optionalImportMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalPublicImportMessageExtension]], - optionalPublicImportMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalLazyMessageExtension]], - optionalLazyMessage); + XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]], + optionalGroup); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalNestedMessageExtension]], + optionalNestedMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalForeignMessageExtension]], + optionalForeignMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalImportMessageExtension]], + optionalImportMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalPublicImportMessageExtension]], + optionalPublicImportMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalLazyMessageExtension]], + optionalLazyMessage); // And the default objects for a second message should be distinct (again, // since they are mutable, each needs their own copy). @@ -1548,47 +1635,70 @@ TestAllExtensions *message2 = [TestAllExtensions message]; // Intentionally doing a pointer comparison. - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalGroupExtension]], optionalGroup); - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalNestedMessageExtension]], - optionalNestedMessage); - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalForeignMessageExtension]], - optionalForeignMessage); - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalImportMessageExtension]], - optionalImportMessage); - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalPublicImportMessageExtension]], - optionalPublicImportMessage); - XCTAssertNotEqual([message2 getExtension:[UnittestRoot optionalLazyMessageExtension]], - optionalLazyMessage); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalGroupExtension]], + optionalGroup); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalNestedMessageExtension]], + optionalNestedMessage); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalForeignMessageExtension]], + optionalForeignMessage); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalImportMessageExtension]], + optionalImportMessage); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalPublicImportMessageExtension]], + optionalPublicImportMessage); + XCTAssertNotEqual( + [message2 getExtension:[UnittestRoot optionalLazyMessageExtension]], + optionalLazyMessage); // Clear values, and on next access you get back new submessages. [message setExtension:[UnittestRoot optionalGroupExtension] value:nil]; [message setExtension:[UnittestRoot optionalGroupExtension] value:nil]; - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nil]; - [message setExtension:[UnittestRoot optionalForeignMessageExtension] value:nil]; - [message setExtension:[UnittestRoot optionalImportMessageExtension] value:nil]; - [message setExtension:[UnittestRoot optionalPublicImportMessageExtension] value:nil]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nil]; + [message setExtension:[UnittestRoot optionalForeignMessageExtension] + value:nil]; + [message setExtension:[UnittestRoot optionalImportMessageExtension] + value:nil]; + [message setExtension:[UnittestRoot optionalPublicImportMessageExtension] + value:nil]; [message setExtension:[UnittestRoot optionalLazyMessageExtension] value:nil]; XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]); XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]); - XCTAssertFalse([message hasExtension:[UnittestRoot optionalLazyMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalImportMessageExtension]]); + XCTAssertFalse([message + hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]); + XCTAssertFalse( + [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]); - XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]], optionalGroup); - XCTAssertEqual([message getExtension:[UnittestRoot optionalNestedMessageExtension]], - optionalNestedMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalForeignMessageExtension]], - optionalForeignMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalImportMessageExtension]], - optionalImportMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalPublicImportMessageExtension]], - optionalPublicImportMessage); - XCTAssertEqual([message getExtension:[UnittestRoot optionalLazyMessageExtension]], - optionalLazyMessage); + XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]], + optionalGroup); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalNestedMessageExtension]], + optionalNestedMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalForeignMessageExtension]], + optionalForeignMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalImportMessageExtension]], + optionalImportMessage); + XCTAssertEqual( + [message + getExtension:[UnittestRoot optionalPublicImportMessageExtension]], + optionalPublicImportMessage); + XCTAssertEqual( + [message getExtension:[UnittestRoot optionalLazyMessageExtension]], + optionalLazyMessage); } - (void)testMultiplePointersToAutocreatedExtension { @@ -1598,11 +1708,13 @@ TestAllExtensions *message2 = [TestAllExtensions message]; GPBExtensionDescriptor *extension = [UnittestRoot optionalGroupExtension]; [message setExtension:extension value:[message2 getExtension:extension]]; - XCTAssertEqual([message getExtension:extension], [message2 getExtension:extension]); + XCTAssertEqual([message getExtension:extension], + [message2 getExtension:extension]); XCTAssertFalse([message2 hasExtension:extension]); XCTAssertTrue([message hasExtension:extension]); - TestAllTypes_OptionalGroup *extensionValue = [message2 getExtension:extension]; + TestAllTypes_OptionalGroup *extensionValue = + [message2 getExtension:extension]; extensionValue.a = 1; XCTAssertTrue([message2 hasExtension:extension]); XCTAssertTrue([message hasExtension:extension]); @@ -1611,10 +1723,12 @@ - (void)testCopyWithAutocreatedExtension { // Mutable copy shouldn't copy autocreated extensions. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *optionalGroupExtension = + [UnittestRoot optionalGroupExtension]; GPBExtensionDescriptor *optionalNestedMessageExtesion = [UnittestRoot optionalNestedMessageExtension]; - TestAllTypes_OptionalGroup *optionalGroup = [message getExtension:optionalGroupExtension]; + TestAllTypes_OptionalGroup *optionalGroup = + [message getExtension:optionalGroupExtension]; optionalGroup.a = 42; XCTAssertNotNil(optionalGroup); XCTAssertNotNil([message getExtension:optionalNestedMessageExtesion]); @@ -1641,11 +1755,13 @@ - (void)testClearMessageAutocreatedExtension { // Call clear should cause it to recreate its autocreated extensions. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *optionalGroupExtension = + [UnittestRoot optionalGroupExtension]; TestAllTypes_OptionalGroup *optionalGroup = [[message getExtension:optionalGroupExtension] retain]; [message clear]; - TestAllTypes_OptionalGroup *optionalGroupNew = [message getExtension:optionalGroupExtension]; + TestAllTypes_OptionalGroup *optionalGroupNew = + [message getExtension:optionalGroupExtension]; // Intentionally doing a pointer comparison. XCTAssertNotEqual(optionalGroup, optionalGroupNew); @@ -1656,37 +1772,42 @@ // Should be able to retain autocreated extension while the creator is // dealloced. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *optionalGroupExtension = + [UnittestRoot optionalGroupExtension]; @autoreleasepool { TestAllExtensions *message2 = [TestAllExtensions message]; [message setExtension:optionalGroupExtension value:[message2 getExtension:optionalGroupExtension]]; - XCTAssertTrue( - GPBWasMessageAutocreatedBy([message getExtension:optionalGroupExtension], message2)); + XCTAssertTrue(GPBWasMessageAutocreatedBy( + [message getExtension:optionalGroupExtension], message2)); } - XCTAssertFalse( - GPBWasMessageAutocreatedBy([message getExtension:optionalGroupExtension], message)); + XCTAssertFalse(GPBWasMessageAutocreatedBy( + [message getExtension:optionalGroupExtension], message)); } - (void)testClearAutocreatedExtension { // Clearing autocreated extension should NOT cause it to lose its creator. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *optionalGroupExtension = + [UnittestRoot optionalGroupExtension]; TestAllTypes_OptionalGroup *optionalGroup = [[message getExtension:optionalGroupExtension] retain]; [message clearExtension:optionalGroupExtension]; - TestAllTypes_OptionalGroup *optionalGroupNew = [message getExtension:optionalGroupExtension]; + TestAllTypes_OptionalGroup *optionalGroupNew = + [message getExtension:optionalGroupExtension]; XCTAssertEqual(optionalGroup, optionalGroupNew); XCTAssertFalse([message hasExtension:optionalGroupExtension]); [optionalGroup release]; // Clearing autocreated extension should not cause its creator to become // visible - GPBExtensionDescriptor *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension]; - TestAllExtensions *message_lvl3 = [message_lvl2 getExtension:recursiveExtension]; + TestAllExtensions *message_lvl3 = + [message_lvl2 getExtension:recursiveExtension]; [message_lvl3 clearExtension:recursiveExtension]; XCTAssertFalse([message hasExtension:recursiveExtension]); } @@ -1695,10 +1816,13 @@ // Setting an extension should cause the extension to appear to its creator. // Test this several levels deep. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension]; - TestAllExtensions *message_lvl3 = [message_lvl2 getExtension:recursiveExtension]; - TestAllExtensions *message_lvl4 = [message_lvl3 getExtension:recursiveExtension]; + TestAllExtensions *message_lvl3 = + [message_lvl2 getExtension:recursiveExtension]; + TestAllExtensions *message_lvl4 = + [message_lvl3 getExtension:recursiveExtension]; XCTAssertFalse([message hasExtension:recursiveExtension]); XCTAssertFalse([message_lvl2 hasExtension:recursiveExtension]); XCTAssertFalse([message_lvl3 hasExtension:recursiveExtension]); @@ -1716,15 +1840,18 @@ - (void)testSetAutocreatedExtensionToSelf { // Setting extension to itself should cause it to become visible. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *optionalGroupExtension = + [UnittestRoot optionalGroupExtension]; XCTAssertNotNil([message getExtension:optionalGroupExtension]); XCTAssertFalse([message hasExtension:optionalGroupExtension]); - [message setExtension:optionalGroupExtension value:[message getExtension:optionalGroupExtension]]; + [message setExtension:optionalGroupExtension + value:[message getExtension:optionalGroupExtension]]; XCTAssertTrue([message hasExtension:optionalGroupExtension]); } - (void)testAutocreatedExtensionMemoryLeaks { - GPBExtensionDescriptor *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; // Test for memory leaks with autocreated extensions. TestAllExtensions *message; @@ -1736,7 +1863,8 @@ message_lvl2 = [[message getExtension:recursiveExtension] retain]; message_lvl3 = [[message_lvl2 getExtension:recursiveExtension] retain]; message_lvl4 = [[message_lvl3 getExtension:recursiveExtension] retain]; - [message_lvl2 setExtension:[UnittestRoot optionalInt32Extension] value:@(1)]; + [message_lvl2 setExtension:[UnittestRoot optionalInt32Extension] + value:@(1)]; } XCTAssertEqual(message.retainCount, (NSUInteger)1); @@ -1756,7 +1884,8 @@ } - (void)testSetExtensionWithAutocreatedValue { - GPBExtensionDescriptor *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message; @autoreleasepool { @@ -1766,7 +1895,8 @@ // This statements checks that the extension value isn't accidentally // dealloced when removing it from the autocreated map. - [message setExtension:recursiveExtension value:[message getExtension:recursiveExtension]]; + [message setExtension:recursiveExtension + value:[message getExtension:recursiveExtension]]; XCTAssertTrue([message hasExtension:recursiveExtension]); [message release]; } @@ -1779,22 +1909,26 @@ } - (void)testGenerateAndParseUnknownMessage { - GPBUnknownFieldSet *unknowns = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *unknowns = + [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns mergeVarintField:123 value:456]; GPBMessage *message = [GPBMessage message]; [message setUnknownFields:unknowns]; NSData *data = [message data]; - GPBMessage *message2 = [GPBMessage parseFromData:data extensionRegistry:nil error:NULL]; + GPBMessage *message2 = + [GPBMessage parseFromData:data extensionRegistry:nil error:NULL]; XCTAssertEqualObjects(message, message2); } - (void)testDelimitedWriteAndParseMultipleMessages { - GPBUnknownFieldSet *unknowns1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *unknowns1 = + [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns1 mergeVarintField:123 value:456]; GPBMessage *message1 = [GPBMessage message]; [message1 setUnknownFields:unknowns1]; - GPBUnknownFieldSet *unknowns2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *unknowns2 = + [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknowns2 mergeVarintField:789 value:987]; [unknowns2 mergeVarintField:654 value:321]; GPBMessage *message2 = [GPBMessage message]; @@ -1803,7 +1937,8 @@ NSMutableData *delimitedData = [NSMutableData data]; [delimitedData appendData:[message1 delimitedData]]; [delimitedData appendData:[message2 delimitedData]]; - GPBCodedInputStream *input = [GPBCodedInputStream streamWithData:delimitedData]; + GPBCodedInputStream *input = + [GPBCodedInputStream streamWithData:delimitedData]; GPBMessage *message3 = [GPBMessage parseDelimitedFromCodedInputStream:input extensionRegistry:nil error:NULL]; @@ -1835,7 +1970,8 @@ } - (void)testEnumDescriptorFromExtensionDescriptor { - GPBExtensionDescriptor *extDescriptor = [UnittestRoot optionalForeignEnumExtension]; + GPBExtensionDescriptor *extDescriptor = + [UnittestRoot optionalForeignEnumExtension]; XCTAssertEqual(extDescriptor.dataType, GPBDataTypeEnum); GPBEnumDescriptor *enumDescriptor = extDescriptor.enumDescriptor; GPBEnumDescriptor *expectedDescriptor = ForeignEnum_EnumDescriptor(); @@ -1843,8 +1979,8 @@ } - (void)testPropertyNaming { - // names.cc has some special handing to get proper all caps for a few cases to - // meet objc developer expectations. + // objectivec_helpers.cc has some special handing to get proper all caps + // for a few cases to meet objc developer expectations. // // This "test" confirms that the expected names are generated, otherwise the // test itself will fail to compile. @@ -1861,7 +1997,7 @@ } - (void)testEnumNaming { - // names.cc has some interesting cases to deal with in + // objectivec_helpers.cc has some interesting cases to deal with in // EnumValueName/EnumValueShortName. Confirm that things generated as // expected. @@ -1942,7 +2078,8 @@ // Repeated field (shouldn't ever be an issue since developer has to use the // right GPBArray methods themselves). - msg.mumbleArray = [GPBEnumArray arrayWithValidationFunction:EnumTestMsg_MyEnum_IsValidValue]; + msg.mumbleArray = [GPBEnumArray + arrayWithValidationFunction:EnumTestMsg_MyEnum_IsValidValue]; [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Zero]; [msg.mumbleArray addValue:EnumTestMsg_MyEnum_One]; [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Two]; @@ -1958,16 +2095,20 @@ XCTAssertNotNil(data); msgPrime = [EnumTestMsg parseFromData:data error:NULL]; XCTAssertEqualObjects(msgPrime, msg); - XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0], EnumTestMsg_MyEnum_Zero); + XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0], + EnumTestMsg_MyEnum_Zero); XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:1], EnumTestMsg_MyEnum_One); XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:2], EnumTestMsg_MyEnum_Two); - XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:3], EnumTestMsg_MyEnum_NegOne); - XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:4], EnumTestMsg_MyEnum_NegTwo); + XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:3], + EnumTestMsg_MyEnum_NegOne); + XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:4], + EnumTestMsg_MyEnum_NegTwo); } - (void)testReservedWordNaming { - // names.cc has some special handing to make sure that some "reserved" objc - // names get renamed in a way so they don't conflict. + // objectivec_helpers.cc has some special handing to make sure that + // some "reserved" objc names get renamed in a way so they + // don't conflict. // // This "test" confirms that the expected names are generated, // otherwise the test itself will fail to compile. @@ -2059,12 +2200,12 @@ msg1.boolField32 = YES; msg2.boolField32 = YES; - XCTAssertTrue(msg1 != msg2); // Different pointers. + XCTAssertTrue(msg1 != msg2); // Different pointers. XCTAssertEqual([msg1 hash], [msg2 hash]); XCTAssertEqualObjects(msg1, msg2); BoolOnlyMessage *msg1Prime = [[msg1 copy] autorelease]; - XCTAssertTrue(msg1Prime != msg1); // Different pointers. + XCTAssertTrue(msg1Prime != msg1); // Different pointers. XCTAssertEqual([msg1 hash], [msg1Prime hash]); XCTAssertEqualObjects(msg1, msg1Prime); @@ -2111,26 +2252,24 @@ TestMessageOfMaps *msg2 = [[msg copy] autorelease]; XCTAssertNotNil(msg2); XCTAssertEqualObjects(msg2, msg); - XCTAssertTrue(msg2 != msg); // ptr compare - XCTAssertTrue(msg.strToStr != msg2.strToStr); // ptr compare - XCTAssertTrue(msg.intToStr != msg2.intToStr); // ptr compare - XCTAssertTrue(msg.intToInt != msg2.intToInt); // ptr compare - XCTAssertTrue(msg.strToBool != msg2.strToBool); // ptr compare - XCTAssertTrue(msg.boolToStr != msg2.boolToStr); // ptr compare + XCTAssertTrue(msg2 != msg); // ptr compare + XCTAssertTrue(msg.strToStr != msg2.strToStr); // ptr compare + XCTAssertTrue(msg.intToStr != msg2.intToStr); // ptr compare + XCTAssertTrue(msg.intToInt != msg2.intToInt); // ptr compare + XCTAssertTrue(msg.strToBool != msg2.strToBool); // ptr compare + XCTAssertTrue(msg.boolToStr != msg2.boolToStr); // ptr compare XCTAssertTrue(msg.boolToBool != msg2.boolToBool); // ptr compare - XCTAssertTrue(msg.intToBool != msg2.intToBool); // ptr compare - XCTAssertTrue(msg.boolToInt != msg2.boolToInt); // ptr compare - XCTAssertTrue(msg.strToMsg != msg2.strToMsg); // ptr compare - XCTAssertTrue(msg.intToMsg != msg2.intToMsg); // ptr compare - XCTAssertTrue(msg.boolToMsg != msg2.boolToMsg); // ptr compare + XCTAssertTrue(msg.intToBool != msg2.intToBool); // ptr compare + XCTAssertTrue(msg.boolToInt != msg2.boolToInt); // ptr compare + XCTAssertTrue(msg.strToMsg != msg2.strToMsg); // ptr compare + XCTAssertTrue(msg.intToMsg != msg2.intToMsg); // ptr compare + XCTAssertTrue(msg.boolToMsg != msg2.boolToMsg); // ptr compare XCTAssertTrue(msg.strToMsg[@"baz"] != msg2.strToMsg[@"baz"]); // ptr compare XCTAssertEqualObjects(msg.strToMsg[@"baz"], msg2.strToMsg[@"baz"]); - XCTAssertTrue([msg.intToMsg objectForKey:222] != - [msg2.intToMsg objectForKey:222]); // ptr compare + XCTAssertTrue([msg.intToMsg objectForKey:222] != [msg2.intToMsg objectForKey:222]); // ptr compare XCTAssertEqualObjects([msg.intToMsg objectForKey:222], [msg2.intToMsg objectForKey:222]); - XCTAssertTrue([msg.boolToMsg objectForKey:YES] != - [msg2.boolToMsg objectForKey:YES]); // ptr compare + XCTAssertTrue([msg.boolToMsg objectForKey:YES] != [msg2.boolToMsg objectForKey:YES]); // ptr compare XCTAssertEqualObjects([msg.boolToMsg objectForKey:YES], [msg2.boolToMsg objectForKey:YES]); } diff --git a/libs/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm b/libs/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm index a89bb47..fb67495 100644 --- a/libs/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm +++ b/libs/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm @@ -28,8 +28,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #import "GPBTestUtilities.h" + // // This is just a compile test (here to make sure things never regress). // @@ -41,19 +43,20 @@ // The "well know types" should have cross file enums needing imports. #import "GPBProtocolBuffers.h" // Some of the tests explicitly use cross file enums also. -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestImport.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestImport.pbobjc.h" // Sanity check the conditions of the test within the Xcode project. #if !__cplusplus -#error This isn't compiled as Objective C++? + #error This isn't compiled as Objective C++? #elif __cplusplus >= 201103L -// If this trips, it means the Xcode default might have change (or someone -// edited the testing project) and it might be time to revisit the GPB_ENUM -// define in GPBBootstrap.h. -#warning Did the Xcode default for C++ spec change? + // If this trips, it means the Xcode default might have change (or someone + // edited the testing project) and it might be time to revisit the GPB_ENUM + // define in GPBBootstrap.h. + #warning Did the Xcode default for C++ spec change? #endif + // Dummy XCTest. @interface GPBObjectiveCPlusPlusTests : GPBTestCase @end diff --git a/libs/protobuf/objectivec/Tests/GPBPerfTests.m b/libs/protobuf/objectivec/Tests/GPBPerfTests.m index 7c1cbc5..8dd0ffc 100644 --- a/libs/protobuf/objectivec/Tests/GPBPerfTests.m +++ b/libs/protobuf/objectivec/Tests/GPBPerfTests.m @@ -29,9 +29,9 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import "GPBTestUtilities.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestImport.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestImport.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" // // This file really just uses the unittests framework as a testbed to @@ -69,9 +69,9 @@ static const uint32_t kRepeatedCount = 100; // lock across threads when parsing different instances. The Serial version of the test should run // around ~2 times slower than the Parallel version since it's parsing the protos in the same // thread. - TestAllTypes* allTypesMessage = [TestAllTypes message]; + TestAllTypes *allTypesMessage = [TestAllTypes message]; [self setAllFields:allTypesMessage repeatedCount:2]; - NSData* allTypesData = allTypesMessage.data; + NSData *allTypesData = allTypesMessage.data; [self measureBlock:^{ for (int i = 0; i < 500; ++i) { @@ -86,9 +86,9 @@ static const uint32_t kRepeatedCount = 100; // not lock across threads when parsing different instances. The Serial version of the test should // run around ~2 times slower than the Parallel version since it's parsing the protos in the same // thread. - TestAllTypes* allTypesMessage = [TestAllTypes message]; + TestAllTypes *allTypesMessage = [TestAllTypes message]; [self setAllFields:allTypesMessage repeatedCount:2]; - NSData* allTypesData = allTypesMessage.data; + NSData *allTypesData = allTypesMessage.data; dispatch_queue_t concurrentQueue = dispatch_queue_create("perfQueue", DISPATCH_QUEUE_CONCURRENT); @@ -104,9 +104,7 @@ static const uint32_t kRepeatedCount = 100; [TestAllTypes parseFromData:allTypesData error:NULL]; }); - dispatch_group_notify(group, concurrentQueue, - ^{ - }); + dispatch_group_notify(group, concurrentQueue, ^{}); dispatch_release(group); } @@ -120,9 +118,9 @@ static const uint32_t kRepeatedCount = 100; // lock across threads when parsing different instances when using extensions. The Serial version // of the test should run around ~2 times slower than the Parallel version since it's parsing the // protos in the same thread. - TestAllExtensions* allExtensionsMessage = [TestAllExtensions message]; + TestAllExtensions *allExtensionsMessage = [TestAllExtensions message]; [self setAllExtensions:allExtensionsMessage repeatedCount:2]; - NSData* allExtensionsData = allExtensionsMessage.data; + NSData *allExtensionsData = allExtensionsMessage.data; [self measureBlock:^{ for (int i = 0; i < 500; ++i) { @@ -141,9 +139,9 @@ static const uint32_t kRepeatedCount = 100; // not lock across threads when parsing different instances when using extensions. The Serial // version of the test should run around ~2 times slower than the Parallel version since it's // parsing the protos in the same thread. - TestAllExtensions* allExtensionsMessage = [TestAllExtensions message]; + TestAllExtensions *allExtensionsMessage = [TestAllExtensions message]; [self setAllExtensions:allExtensionsMessage repeatedCount:2]; - NSData* allExtensionsData = allExtensionsMessage.data; + NSData *allExtensionsData = allExtensionsMessage.data; dispatch_queue_t concurrentQueue = dispatch_queue_create("perfQueue", DISPATCH_QUEUE_CONCURRENT); @@ -163,9 +161,7 @@ static const uint32_t kRepeatedCount = 100; error:NULL]; }); - dispatch_group_notify(group, concurrentQueue, - ^{ - }); + dispatch_group_notify(group, concurrentQueue, ^{}); dispatch_release(group); } @@ -181,7 +177,8 @@ static const uint32_t kRepeatedCount = 100; [self setAllExtensions:message repeatedCount:kRepeatedCount]; NSData* rawBytes = [message data]; [message release]; - TestAllExtensions* message2 = [[TestAllExtensions alloc] initWithData:rawBytes error:NULL]; + TestAllExtensions* message2 = + [[TestAllExtensions alloc] initWithData:rawBytes error:NULL]; [message2 release]; } }]; @@ -207,8 +204,8 @@ static const uint32_t kRepeatedCount = 100; [self setPackedExtensions:message repeatedCount:kRepeatedCount]; NSData* rawBytes = [message data]; [message release]; - TestPackedExtensions* message2 = [[TestPackedExtensions alloc] initWithData:rawBytes - error:NULL]; + TestPackedExtensions* message2 = + [[TestPackedExtensions alloc] initWithData:rawBytes error:NULL]; [message2 release]; } }]; diff --git a/libs/protobuf/objectivec/Tests/GPBTestUtilities.h b/libs/protobuf/objectivec/Tests/GPBTestUtilities.h index bebd557..780184b 100644 --- a/libs/protobuf/objectivec/Tests/GPBTestUtilities.h +++ b/libs/protobuf/objectivec/Tests/GPBTestUtilities.h @@ -48,6 +48,7 @@ static inline NSData *DataFromCStr(const char *str) { #define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0])))) #endif // GPBARRAYSIZE + // The number of repetitions of any repeated objects inside of test messages. extern const uint32_t kGPBDefaultRepeatCount; @@ -55,11 +56,16 @@ extern const uint32_t kGPBDefaultRepeatCount; - (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count; - (void)clearAllFields:(TestAllTypes *)message; -- (void)setAllExtensions:(TestAllExtensions *)message repeatedCount:(uint32_t)count; -- (void)setPackedFields:(TestPackedTypes *)message repeatedCount:(uint32_t)count; -- (void)setUnpackedFields:(TestUnpackedTypes *)message repeatedCount:(uint32_t)count; -- (void)setPackedExtensions:(TestPackedExtensions *)message repeatedCount:(uint32_t)count; -- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message repeatedCount:(uint32_t)count; +- (void)setAllExtensions:(TestAllExtensions *)message + repeatedCount:(uint32_t)count; +- (void)setPackedFields:(TestPackedTypes *)message + repeatedCount:(uint32_t)count; +- (void)setUnpackedFields:(TestUnpackedTypes *)message + repeatedCount:(uint32_t)count; +- (void)setPackedExtensions:(TestPackedExtensions *)message + repeatedCount:(uint32_t)count; +- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message + repeatedCount:(uint32_t)count; - (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count; - (TestAllTypes *)allSetRepeatedCount:(uint32_t)count; @@ -67,14 +73,20 @@ extern const uint32_t kGPBDefaultRepeatCount; - (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count; - (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count; -- (void)assertAllFieldsSet:(TestAllTypes *)message repeatedCount:(uint32_t)count; -- (void)assertAllExtensionsSet:(TestAllExtensions *)message repeatedCount:(uint32_t)count; -- (void)assertRepeatedFieldsModified:(TestAllTypes *)message repeatedCount:(uint32_t)count; -- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message repeatedCount:(uint32_t)count; +- (void)assertAllFieldsSet:(TestAllTypes *)message + repeatedCount:(uint32_t)count; +- (void)assertAllExtensionsSet:(TestAllExtensions *)message + repeatedCount:(uint32_t)count; +- (void)assertRepeatedFieldsModified:(TestAllTypes *)message + repeatedCount:(uint32_t)count; +- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message + repeatedCount:(uint32_t)count; - (void)assertExtensionsClear:(TestAllExtensions *)message; - (void)assertClear:(TestAllTypes *)message; -- (void)assertPackedFieldsSet:(TestPackedTypes *)message repeatedCount:(uint32_t)count; -- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message repeatedCount:(uint32_t)count; +- (void)assertPackedFieldsSet:(TestPackedTypes *)message + repeatedCount:(uint32_t)count; +- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message + repeatedCount:(uint32_t)count; - (void)modifyRepeatedExtensions:(TestAllExtensions *)message; - (void)modifyRepeatedFields:(TestAllTypes *)message; @@ -84,7 +96,8 @@ extern const uint32_t kGPBDefaultRepeatCount; - (NSData *)getDataFileNamed:(NSString *)name dataToWrite:(NSData *)dataToWrite; - (void)assertAllFieldsKVCMatch:(TestAllTypes *)message; -- (void)setAllFieldsViaKVC:(TestAllTypes *)message repeatedCount:(uint32_t)count; +- (void)setAllFieldsViaKVC:(TestAllTypes *)message + repeatedCount:(uint32_t)count; - (void)assertClearKVC:(TestAllTypes *)message; @end diff --git a/libs/protobuf/objectivec/Tests/GPBTestUtilities.m b/libs/protobuf/objectivec/Tests/GPBTestUtilities.m index 37bd5d7..48d75e7 100644 --- a/libs/protobuf/objectivec/Tests/GPBTestUtilities.m +++ b/libs/protobuf/objectivec/Tests/GPBTestUtilities.m @@ -30,9 +30,9 @@ #import "GPBTestUtilities.h" -#import "objectivec/Tests/MapUnittest.pbobjc.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestImport.pbobjc.h" +#import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestImport.pbobjc.h" const uint32_t kGPBDefaultRepeatCount = 2; @@ -66,7 +66,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; // Return data for name. Optionally (based on #if setting) write out dataToWrite // to replace that data. Useful for setting golden masters. -- (NSData *)getDataFileNamed:(NSString *)name dataToWrite:(NSData *)dataToWrite { +- (NSData *)getDataFileNamed:(NSString *)name + dataToWrite:(NSData *)dataToWrite { NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSString *path = [bundle pathForResource:[name stringByDeletingPathExtension] ofType:[name pathExtension]]; @@ -92,30 +93,63 @@ const uint32_t kGPBDefaultRepeatCount = 2; // ------------------------------------------------------------------- - (void)modifyRepeatedExtensions:(TestAllExtensions *)message { - [message setExtension:[UnittestRoot repeatedInt32Extension] index:1 value:@501]; - [message setExtension:[UnittestRoot repeatedInt64Extension] index:1 value:@502]; - [message setExtension:[UnittestRoot repeatedUint32Extension] index:1 value:@503]; - [message setExtension:[UnittestRoot repeatedUint64Extension] index:1 value:@504]; - [message setExtension:[UnittestRoot repeatedSint32Extension] index:1 value:@505]; - [message setExtension:[UnittestRoot repeatedSint64Extension] index:1 value:@506]; - [message setExtension:[UnittestRoot repeatedFixed32Extension] index:1 value:@507]; - [message setExtension:[UnittestRoot repeatedFixed64Extension] index:1 value:@508]; - [message setExtension:[UnittestRoot repeatedSfixed32Extension] index:1 value:@509]; - [message setExtension:[UnittestRoot repeatedSfixed64Extension] index:1 value:@510]; - [message setExtension:[UnittestRoot repeatedFloatExtension] index:1 value:@511.0f]; - [message setExtension:[UnittestRoot repeatedDoubleExtension] index:1 value:@512.0]; - [message setExtension:[UnittestRoot repeatedBoolExtension] index:1 value:@YES]; - [message setExtension:[UnittestRoot repeatedStringExtension] index:1 value:@"515"]; + [message setExtension:[UnittestRoot repeatedInt32Extension] + index:1 + value:@501]; + [message setExtension:[UnittestRoot repeatedInt64Extension] + index:1 + value:@502]; + [message setExtension:[UnittestRoot repeatedUint32Extension] + index:1 + value:@503]; + [message setExtension:[UnittestRoot repeatedUint64Extension] + index:1 + value:@504]; + [message setExtension:[UnittestRoot repeatedSint32Extension] + index:1 + value:@505]; + [message setExtension:[UnittestRoot repeatedSint64Extension] + index:1 + value:@506]; + [message setExtension:[UnittestRoot repeatedFixed32Extension] + index:1 + value:@507]; + [message setExtension:[UnittestRoot repeatedFixed64Extension] + index:1 + value:@508]; + [message setExtension:[UnittestRoot repeatedSfixed32Extension] + index:1 + value:@509]; + [message setExtension:[UnittestRoot repeatedSfixed64Extension] + index:1 + value:@510]; + [message setExtension:[UnittestRoot repeatedFloatExtension] + index:1 + value:@511.0f]; + [message setExtension:[UnittestRoot repeatedDoubleExtension] + index:1 + value:@512.0]; + [message setExtension:[UnittestRoot repeatedBoolExtension] + index:1 + value:@YES]; + [message setExtension:[UnittestRoot repeatedStringExtension] + index:1 + value:@"515"]; [message setExtension:[UnittestRoot repeatedBytesExtension] index:1 value:[NSData gpbtu_dataWithUint32:516]]; RepeatedGroup_extension *repeatedGroup = [RepeatedGroup_extension message]; [repeatedGroup setA:517]; - [message setExtension:[UnittestRoot repeatedGroupExtension] index:1 value:repeatedGroup]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + [message setExtension:[UnittestRoot repeatedGroupExtension] + index:1 + value:repeatedGroup]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; [nestedMessage setBb:518]; - [message setExtension:[UnittestRoot repeatedNestedMessageExtension] index:1 value:nestedMessage]; + [message setExtension:[UnittestRoot repeatedNestedMessageExtension] + index:1 + value:nestedMessage]; ForeignMessage *foreignMessage = [ForeignMessage message]; [foreignMessage setC:519]; [message setExtension:[UnittestRoot repeatedForeignMessageExtension] @@ -123,7 +157,9 @@ const uint32_t kGPBDefaultRepeatCount = 2; value:foreignMessage]; ImportMessage *importMessage = [ImportMessage message]; [importMessage setD:520]; - [message setExtension:[UnittestRoot repeatedImportMessageExtension] index:1 value:importMessage]; + [message setExtension:[UnittestRoot repeatedImportMessageExtension] + index:1 + value:importMessage]; [message setExtension:[UnittestRoot repeatedNestedEnumExtension] index:1 @@ -135,11 +171,16 @@ const uint32_t kGPBDefaultRepeatCount = 2; index:1 value:@(ImportEnum_ImportFoo)]; - [message setExtension:[UnittestRoot repeatedStringPieceExtension] index:1 value:@"524"]; - [message setExtension:[UnittestRoot repeatedCordExtension] index:1 value:@"525"]; + [message setExtension:[UnittestRoot repeatedStringPieceExtension] + index:1 + value:@"524"]; + [message setExtension:[UnittestRoot repeatedCordExtension] + index:1 + value:@"525"]; } -- (void)assertAllExtensionsSet:(TestAllExtensions *)message repeatedCount:(uint32_t)count { +- (void)assertAllExtensionsSet:(TestAllExtensions *)message + repeatedCount:(uint32_t)count { XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]); XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt64Extension]]); XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint32Extension]]); @@ -197,44 +238,29 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]); XCTAssertEqual(101, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]); - XCTAssertEqual(102LL, - [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); - XCTAssertEqual(103U, - [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); - XCTAssertEqual(104ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] - unsignedLongLongValue]); + XCTAssertEqual(102LL, [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); + XCTAssertEqual(103U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); + XCTAssertEqual(104ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]); XCTAssertEqual(105, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]); - XCTAssertEqual(106LL, - [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); - XCTAssertEqual(107U, - [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); - XCTAssertEqual(108ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] - unsignedLongLongValue]); + XCTAssertEqual(106LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); + XCTAssertEqual(107U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); + XCTAssertEqual(108ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]); XCTAssertEqual(109, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]); - XCTAssertEqual(110LL, - [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); - XCTAssertEqualWithAccuracy( - 111.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 112.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); + XCTAssertEqual(110LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); + XCTAssertEqualWithAccuracy(111.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); + XCTAssertEqualWithAccuracy(112.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); XCTAssertTrue([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]); XCTAssertEqualObjects(@"115", [message getExtension:[UnittestRoot optionalStringExtension]]); - XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], - [message getExtension:[UnittestRoot optionalBytesExtension]]); + XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], [message getExtension:[UnittestRoot optionalBytesExtension]]); - XCTAssertEqual(117, [(TestAllTypes_OptionalGroup *)[message - getExtension:[UnittestRoot optionalGroupExtension]] a]); - XCTAssertEqual(118, [(TestAllTypes_NestedMessage *)[message - getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); + XCTAssertEqual(117, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]); + XCTAssertEqual(118, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); XCTAssertEqual(119, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]); XCTAssertEqual(120, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]); - XCTAssertEqual(TestAllTypes_NestedEnum_Baz, - [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); - XCTAssertEqual(ForeignEnum_ForeignBaz, - [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); - XCTAssertEqual(ImportEnum_ImportBaz, - [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); + XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); + XCTAssertEqual(ForeignEnum_ForeignBaz, [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); + XCTAssertEqual(ImportEnum_ImportBaz, [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); XCTAssertEqualObjects(@"124", [message getExtension:[UnittestRoot optionalStringPieceExtension]]); XCTAssertEqualObjects(@"125", [message getExtension:[UnittestRoot optionalCordExtension]]); @@ -258,12 +284,9 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]); @@ -310,20 +333,18 @@ const uint32_t kGPBDefaultRepeatCount = 2; [data release]; extension = [message getExtension:[UnittestRoot repeatedGroupExtension]]; - XCTAssertEqual((int)(217 + i * 100), [(TestAllTypes_OptionalGroup *)extension[i] a]); + XCTAssertEqual((int)(217 + i * 100), [(TestAllTypes_OptionalGroup*)extension[i] a]); extension = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; - XCTAssertEqual((int)(218 + i * 100), [(TestAllTypes_NestedMessage *)extension[i] bb]); + XCTAssertEqual((int)(218 + i * 100), [(TestAllTypes_NestedMessage*)extension[i] bb]); extension = [message getExtension:[UnittestRoot repeatedForeignMessageExtension]]; XCTAssertEqual((int)(219 + i * 100), [extension[i] c]); extension = [message getExtension:[UnittestRoot repeatedImportMessageExtension]]; XCTAssertEqual((int)(220 + i * 100), [extension[i] d]); extension = [message getExtension:[UnittestRoot repeatedNestedEnumExtension]]; - XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, - [extension[i] intValue]); + XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [extension[i] intValue]); extension = [message getExtension:[UnittestRoot repeatedForeignEnumExtension]]; - XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, - [extension[i] intValue]); + XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [extension[i] intValue]); extension = [message getExtension:[UnittestRoot repeatedImportEnumExtension]]; XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [extension[i] intValue]); @@ -364,37 +385,24 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]); XCTAssertEqual(401, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]); - XCTAssertEqual(402LL, - [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); - XCTAssertEqual(403U, - [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); - XCTAssertEqual( - 404ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); + XCTAssertEqual(402LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); + XCTAssertEqual(403U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); + XCTAssertEqual(404ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); XCTAssertEqual(405, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]); - XCTAssertEqual(406LL, - [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); - XCTAssertEqual(407U, - [[message getExtension:[UnittestRoot defaultFixed32Extension]] unsignedIntValue]); - XCTAssertEqual(408ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] - unsignedLongLongValue]); + XCTAssertEqual(406LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); + XCTAssertEqual(407U, [[message getExtension:[UnittestRoot defaultFixed32Extension]] unsignedIntValue]); + XCTAssertEqual(408ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]); XCTAssertEqual(409, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]); - XCTAssertEqual(410LL, - [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); - XCTAssertEqualWithAccuracy( - 411.0f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 412.0, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); + XCTAssertEqual(410LL,[[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); + XCTAssertEqualWithAccuracy(411.0f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); + XCTAssertEqualWithAccuracy(412.0, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); XCTAssertFalse([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]); XCTAssertEqualObjects(@"415", [message getExtension:[UnittestRoot defaultStringExtension]]); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], - [message getExtension:[UnittestRoot defaultBytesExtension]]); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], [message getExtension:[UnittestRoot defaultBytesExtension]]); - XCTAssertEqual(TestAllTypes_NestedEnum_Foo, - [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); - XCTAssertEqual(ForeignEnum_ForeignFoo, - [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); - XCTAssertEqual(ImportEnum_ImportFoo, - [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); + XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); + XCTAssertEqual(ForeignEnum_ForeignFoo, [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); + XCTAssertEqual(ImportEnum_ImportFoo, [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); XCTAssertEqualObjects(@"424", [message getExtension:[UnittestRoot defaultStringPieceExtension]]); XCTAssertEqualObjects(@"425", [message getExtension:[UnittestRoot defaultCordExtension]]); @@ -422,12 +430,9 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); - XCTAssertEqual(count, - [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); + XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]); @@ -435,37 +440,24 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]); - XCTAssertEqual(201, [[message getExtension:[UnittestRoot repeatedInt32Extension]][0] intValue]); - XCTAssertEqual(202LL, - [[message getExtension:[UnittestRoot repeatedInt64Extension]][0] longLongValue]); - XCTAssertEqual( - 203U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][0] unsignedIntValue]); - XCTAssertEqual(204ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][0] - unsignedLongLongValue]); + XCTAssertEqual(201,[[message getExtension:[UnittestRoot repeatedInt32Extension]][0] intValue]); + XCTAssertEqual(202LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][0] longLongValue]); + XCTAssertEqual(203U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][0] unsignedIntValue]); + XCTAssertEqual(204ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][0] unsignedLongLongValue]); XCTAssertEqual(205, [[message getExtension:[UnittestRoot repeatedSint32Extension]][0] intValue]); - XCTAssertEqual(206LL, - [[message getExtension:[UnittestRoot repeatedSint64Extension]][0] longLongValue]); - XCTAssertEqual( - 207U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][0] unsignedIntValue]); - XCTAssertEqual(208ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][0] - unsignedLongLongValue]); - XCTAssertEqual(209, - [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][0] intValue]); - XCTAssertEqual( - 210LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][0] longLongValue]); - XCTAssertEqualWithAccuracy( - 211.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][0] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 212.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][0] doubleValue], 0.01); + XCTAssertEqual(206LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][0] longLongValue]); + XCTAssertEqual(207U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][0] unsignedIntValue]); + XCTAssertEqual(208ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][0] unsignedLongLongValue]); + XCTAssertEqual(209, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][0] intValue]); + XCTAssertEqual(210LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][0] longLongValue]); + XCTAssertEqualWithAccuracy(211.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][0] floatValue], 0.01); + XCTAssertEqualWithAccuracy(212.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][0] doubleValue], 0.01); XCTAssertFalse([[message getExtension:[UnittestRoot repeatedBoolExtension]][0] boolValue]); XCTAssertEqualObjects(@"215", [message getExtension:[UnittestRoot repeatedStringExtension]][0]); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], - [message getExtension:[UnittestRoot repeatedBytesExtension]][0]); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], [message getExtension:[UnittestRoot repeatedBytesExtension]][0]); - XCTAssertEqual(217, [(TestAllTypes_OptionalGroup *)[message - getExtension:[UnittestRoot repeatedGroupExtension]][0] a]); - XCTAssertEqual(218, [(TestAllTypes_NestedMessage *)[message - getExtension:[UnittestRoot repeatedNestedMessageExtension]][0] bb]); + XCTAssertEqual(217, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][0] a]); + XCTAssertEqual(218, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][0] bb]); XCTAssertEqual(219, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][0] c]); XCTAssertEqual(220, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][0] d]); @@ -476,42 +468,28 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(ImportEnum_ImportBaz, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][0] intValue]); - XCTAssertEqualObjects(@"224", - [message getExtension:[UnittestRoot repeatedStringPieceExtension]][0]); + XCTAssertEqualObjects(@"224", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][0]); XCTAssertEqualObjects(@"225", [message getExtension:[UnittestRoot repeatedCordExtension]][0]); // Actually verify the second (modified) elements now. XCTAssertEqual(501, [[message getExtension:[UnittestRoot repeatedInt32Extension]][1] intValue]); - XCTAssertEqual(502LL, - [[message getExtension:[UnittestRoot repeatedInt64Extension]][1] longLongValue]); - XCTAssertEqual( - 503U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][1] unsignedIntValue]); - XCTAssertEqual(504ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][1] - unsignedLongLongValue]); + XCTAssertEqual(502LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][1] longLongValue]); + XCTAssertEqual(503U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][1] unsignedIntValue]); + XCTAssertEqual(504ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][1] unsignedLongLongValue]); XCTAssertEqual(505, [[message getExtension:[UnittestRoot repeatedSint32Extension]][1] intValue]); - XCTAssertEqual(506LL, - [[message getExtension:[UnittestRoot repeatedSint64Extension]][1] longLongValue]); - XCTAssertEqual( - 507U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][1] unsignedIntValue]); - XCTAssertEqual(508ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][1] - unsignedLongLongValue]); - XCTAssertEqual(509, - [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][1] intValue]); - XCTAssertEqual( - 510LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][1] longLongValue]); - XCTAssertEqualWithAccuracy( - 511.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][1] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 512.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][1] doubleValue], 0.01); + XCTAssertEqual(506LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][1] longLongValue]); + XCTAssertEqual(507U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][1] unsignedIntValue]); + XCTAssertEqual(508ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][1] unsignedLongLongValue]); + XCTAssertEqual(509, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][1] intValue]); + XCTAssertEqual(510LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][1] longLongValue]); + XCTAssertEqualWithAccuracy(511.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][1] floatValue], 0.01); + XCTAssertEqualWithAccuracy(512.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][1] doubleValue], 0.01); XCTAssertTrue([[message getExtension:[UnittestRoot repeatedBoolExtension]][1] boolValue]); XCTAssertEqualObjects(@"515", [message getExtension:[UnittestRoot repeatedStringExtension]][1]); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], - [message getExtension:[UnittestRoot repeatedBytesExtension]][1]); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], [message getExtension:[UnittestRoot repeatedBytesExtension]][1]); - XCTAssertEqual(517, [(TestAllTypes_OptionalGroup *)[message - getExtension:[UnittestRoot repeatedGroupExtension]][1] a]); - XCTAssertEqual(518, [(TestAllTypes_NestedMessage *)[message - getExtension:[UnittestRoot repeatedNestedMessageExtension]][1] bb]); + XCTAssertEqual(517, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][1] a]); + XCTAssertEqual(518, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][1] bb]); XCTAssertEqual(519, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][1] c]); XCTAssertEqual(520, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][1] d]); @@ -522,14 +500,14 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(ImportEnum_ImportFoo, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][1] intValue]); - XCTAssertEqualObjects(@"524", - [message getExtension:[UnittestRoot repeatedStringPieceExtension]][1]); + XCTAssertEqualObjects(@"524", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][1]); XCTAssertEqualObjects(@"525", [message getExtension:[UnittestRoot repeatedCordExtension]][1]); } // ------------------------------------------------------------------- -- (void)assertAllFieldsSet:(TestAllTypes *)message repeatedCount:(uint32_t)count { +- (void)assertAllFieldsSet:(TestAllTypes *)message + repeatedCount:(uint32_t)count { XCTAssertTrue(message.hasOptionalInt32); XCTAssertTrue(message.hasOptionalInt64); XCTAssertTrue(message.hasOptionalUint32); @@ -577,7 +555,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualWithAccuracy(112.0, message.optionalDouble, 0.1); XCTAssertTrue(message.optionalBool); XCTAssertEqualObjects(@"115", message.optionalString); - XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], message.optionalBytes); + XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], + message.optionalBytes); XCTAssertEqual(117, message.optionalGroup.a); XCTAssertEqual(118, message.optionalNestedMessage.bb); @@ -648,19 +627,28 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, message.repeatedCordArray_Count); for (uint32_t i = 0; i < count; ++i) { - XCTAssertEqual((int)(201 + i * 100), [message.repeatedInt32Array valueAtIndex:i]); + XCTAssertEqual((int)(201 + i * 100), + [message.repeatedInt32Array valueAtIndex:i]); XCTAssertEqual(202 + i * 100, [message.repeatedInt64Array valueAtIndex:i]); XCTAssertEqual(203 + i * 100, [message.repeatedUint32Array valueAtIndex:i]); XCTAssertEqual(204 + i * 100, [message.repeatedUint64Array valueAtIndex:i]); - XCTAssertEqual((int)(205 + i * 100), [message.repeatedSint32Array valueAtIndex:i]); + XCTAssertEqual((int)(205 + i * 100), + [message.repeatedSint32Array valueAtIndex:i]); XCTAssertEqual(206 + i * 100, [message.repeatedSint64Array valueAtIndex:i]); - XCTAssertEqual(207 + i * 100, [message.repeatedFixed32Array valueAtIndex:i]); - XCTAssertEqual(208 + i * 100, [message.repeatedFixed64Array valueAtIndex:i]); - XCTAssertEqual((int)(209 + i * 100), [message.repeatedSfixed32Array valueAtIndex:i]); - XCTAssertEqual(210 + i * 100, [message.repeatedSfixed64Array valueAtIndex:i]); - XCTAssertEqualWithAccuracy(211 + i * 100, [message.repeatedFloatArray valueAtIndex:i], 0.1); - XCTAssertEqualWithAccuracy(212 + i * 100, [message.repeatedDoubleArray valueAtIndex:i], 0.1); - XCTAssertEqual((i % 2) ? YES : NO, [message.repeatedBoolArray valueAtIndex:i]); + XCTAssertEqual(207 + i * 100, + [message.repeatedFixed32Array valueAtIndex:i]); + XCTAssertEqual(208 + i * 100, + [message.repeatedFixed64Array valueAtIndex:i]); + XCTAssertEqual((int)(209 + i * 100), + [message.repeatedSfixed32Array valueAtIndex:i]); + XCTAssertEqual(210 + i * 100, + [message.repeatedSfixed64Array valueAtIndex:i]); + XCTAssertEqualWithAccuracy( + 211 + i * 100, [message.repeatedFloatArray valueAtIndex:i], 0.1); + XCTAssertEqualWithAccuracy( + 212 + i * 100, [message.repeatedDoubleArray valueAtIndex:i], 0.1); + XCTAssertEqual((i % 2) ? YES : NO, + [message.repeatedBoolArray valueAtIndex:i]); NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; XCTAssertEqualObjects(string, message.repeatedStringArray[i]); @@ -670,21 +658,14 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(data, message.repeatedBytesArray[i]); [data release]; - XCTAssertEqual((int)(217 + i * 100), - ((TestAllTypes_RepeatedGroup *)message.repeatedGroupArray[i]).a); - XCTAssertEqual((int)(218 + i * 100), - ((TestAllTypes_NestedMessage *)message.repeatedNestedMessageArray[i]).bb); - XCTAssertEqual((int)(219 + i * 100), - ((ForeignMessage *)message.repeatedForeignMessageArray[i]).c); - XCTAssertEqual((int)(220 + i * 100), - ((ImportMessage *)message.repeatedImportMessageArray[i]).d); + XCTAssertEqual((int)(217 + i * 100), ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[i]).a); + XCTAssertEqual((int)(218 + i * 100), ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[i]).bb); + XCTAssertEqual((int)(219 + i * 100), ((ForeignMessage*)message.repeatedForeignMessageArray[i]).c); + XCTAssertEqual((int)(220 + i * 100), ((ImportMessage*)message.repeatedImportMessageArray[i]).d); - XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, - [message.repeatedNestedEnumArray valueAtIndex:i]); - XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, - [message.repeatedForeignEnumArray valueAtIndex:i]); - XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, - [message.repeatedImportEnumArray valueAtIndex:i]); + XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:i]); + XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:i]); + XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:i]); string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; XCTAssertEqualObjects(string, message.repeatedStringPieceArray[i]); @@ -734,7 +715,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualWithAccuracy(412.0, message.defaultDouble, 0.1); XCTAssertFalse(message.defaultBool); XCTAssertEqualObjects(@"415", message.defaultString); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], message.defaultBytes); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], + message.defaultBytes); XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.defaultNestedEnum); XCTAssertEqual(ForeignEnum_ForeignFoo, message.defaultForeignEnum); @@ -764,7 +746,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message]; [allTypes setA:117]; [message setOptionalGroup:allTypes]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; [nestedMessage setBb:118]; [message setOptionalNestedMessage:nestedMessage]; ForeignMessage *foreignMessage = [ForeignMessage message]; @@ -805,7 +788,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.repeatedBytesArray addObject:data]; [data release]; - TestAllTypes_RepeatedGroup *testAll = [[TestAllTypes_RepeatedGroup alloc] init]; + TestAllTypes_RepeatedGroup *testAll = + [[TestAllTypes_RepeatedGroup alloc] init]; [testAll setA:217 + i * 100]; [message.repeatedGroupArray addObject:testAll]; [testAll release]; @@ -825,13 +809,10 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.repeatedImportMessageArray addObject:importMessage]; [importMessage release]; - [message.repeatedNestedEnumArray - addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz]; + [message.repeatedNestedEnumArray addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz]; - [message.repeatedForeignEnumArray - addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; - [message.repeatedImportEnumArray - addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz]; + [message.repeatedForeignEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; + [message.repeatedImportEnumArray addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz]; string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; [message.repeatedStringPieceArray addObject:string]; @@ -952,7 +933,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; message.hasDefaultCord = NO; } -- (void)setAllExtensions:(TestAllExtensions *)message repeatedCount:(uint32_t)count { +- (void)setAllExtensions:(TestAllExtensions *)message + repeatedCount:(uint32_t)count { [message setExtension:[UnittestRoot optionalInt32Extension] value:@101]; [message setExtension:[UnittestRoot optionalInt64Extension] value:@102L]; [message setExtension:[UnittestRoot optionalUint32Extension] value:@103]; @@ -972,40 +954,60 @@ const uint32_t kGPBDefaultRepeatCount = 2; OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message]; [optionalGroup setA:117]; - [message setExtension:[UnittestRoot optionalGroupExtension] value:optionalGroup]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + [message setExtension:[UnittestRoot optionalGroupExtension] + value:optionalGroup]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; [nestedMessage setBb:118]; - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nestedMessage]; ForeignMessage *foreignMessage = [ForeignMessage message]; [foreignMessage setC:119]; - [message setExtension:[UnittestRoot optionalForeignMessageExtension] value:foreignMessage]; + [message setExtension:[UnittestRoot optionalForeignMessageExtension] + value:foreignMessage]; ImportMessage *importMessage = [ImportMessage message]; [importMessage setD:120]; - [message setExtension:[UnittestRoot optionalImportMessageExtension] value:importMessage]; + [message setExtension:[UnittestRoot optionalImportMessageExtension] + value:importMessage]; [message setExtension:[UnittestRoot optionalNestedEnumExtension] value:@(TestAllTypes_NestedEnum_Baz)]; [message setExtension:[UnittestRoot optionalForeignEnumExtension] value:@(ForeignEnum_ForeignBaz)]; - [message setExtension:[UnittestRoot optionalImportEnumExtension] value:@(ImportEnum_ImportBaz)]; + [message setExtension:[UnittestRoot optionalImportEnumExtension] + value:@(ImportEnum_ImportBaz)]; - [message setExtension:[UnittestRoot optionalStringPieceExtension] value:@"124"]; + [message setExtension:[UnittestRoot optionalStringPieceExtension] + value:@"124"]; [message setExtension:[UnittestRoot optionalCordExtension] value:@"125"]; for (uint32_t i = 0; i < count; ++i) { - [message addExtension:[UnittestRoot repeatedInt32Extension] value:@(201 + i * 100)]; - [message addExtension:[UnittestRoot repeatedInt64Extension] value:@(202 + i * 100)]; - [message addExtension:[UnittestRoot repeatedUint32Extension] value:@(203 + i * 100)]; - [message addExtension:[UnittestRoot repeatedUint64Extension] value:@(204 + i * 100)]; - [message addExtension:[UnittestRoot repeatedSint32Extension] value:@(205 + i * 100)]; - [message addExtension:[UnittestRoot repeatedSint64Extension] value:@(206 + i * 100)]; - [message addExtension:[UnittestRoot repeatedFixed32Extension] value:@(207 + i * 100)]; - [message addExtension:[UnittestRoot repeatedFixed64Extension] value:@(208 + i * 100)]; - [message addExtension:[UnittestRoot repeatedSfixed32Extension] value:@(209 + i * 100)]; - [message addExtension:[UnittestRoot repeatedSfixed64Extension] value:@(210 + i * 100)]; - [message addExtension:[UnittestRoot repeatedFloatExtension] value:@(211 + i * 100)]; - [message addExtension:[UnittestRoot repeatedDoubleExtension] value:@(212 + i * 100)]; - [message addExtension:[UnittestRoot repeatedBoolExtension] value:@((i % 2) ? YES : NO)]; + [message addExtension:[UnittestRoot repeatedInt32Extension] + value:@(201 + i * 100)]; + [message addExtension:[UnittestRoot repeatedInt64Extension] + value:@(202 + i * 100)]; + [message addExtension:[UnittestRoot repeatedUint32Extension] + value:@(203 + i * 100)]; + [message addExtension:[UnittestRoot repeatedUint64Extension] + value:@(204 + i * 100)]; + [message addExtension:[UnittestRoot repeatedSint32Extension] + value:@(205 + i * 100)]; + [message addExtension:[UnittestRoot repeatedSint64Extension] + value:@(206 + i * 100)]; + [message addExtension:[UnittestRoot repeatedFixed32Extension] + value:@(207 + i * 100)]; + [message addExtension:[UnittestRoot repeatedFixed64Extension] + value:@(208 + i * 100)]; + [message addExtension:[UnittestRoot repeatedSfixed32Extension] + value:@(209 + i * 100)]; + [message addExtension:[UnittestRoot repeatedSfixed64Extension] + value:@(210 + i * 100)]; + [message addExtension:[UnittestRoot repeatedFloatExtension] + value:@(211 + i * 100)]; + [message addExtension:[UnittestRoot repeatedDoubleExtension] + value:@(212 + i * 100)]; + [message addExtension:[UnittestRoot repeatedBoolExtension] + value:@((i % 2) ? YES : NO)]; NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; [message addExtension:[UnittestRoot repeatedStringExtension] value:string]; [string release]; @@ -1013,31 +1015,40 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message addExtension:[UnittestRoot repeatedBytesExtension] value:data]; [data release]; - RepeatedGroup_extension *repeatedGroup = [[RepeatedGroup_extension alloc] init]; + RepeatedGroup_extension *repeatedGroup = + [[RepeatedGroup_extension alloc] init]; [repeatedGroup setA:217 + i * 100]; - [message addExtension:[UnittestRoot repeatedGroupExtension] value:repeatedGroup]; + [message addExtension:[UnittestRoot repeatedGroupExtension] + value:repeatedGroup]; [repeatedGroup release]; nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; [nestedMessage setBb:218 + i * 100]; - [message addExtension:[UnittestRoot repeatedNestedMessageExtension] value:nestedMessage]; + [message addExtension:[UnittestRoot repeatedNestedMessageExtension] + value:nestedMessage]; [nestedMessage release]; foreignMessage = [[ForeignMessage alloc] init]; [foreignMessage setC:219 + i * 100]; - [message addExtension:[UnittestRoot repeatedForeignMessageExtension] value:foreignMessage]; + [message addExtension:[UnittestRoot repeatedForeignMessageExtension] + value:foreignMessage]; [foreignMessage release]; importMessage = [[ImportMessage alloc] init]; [importMessage setD:220 + i * 100]; - [message addExtension:[UnittestRoot repeatedImportMessageExtension] value:importMessage]; + [message addExtension:[UnittestRoot repeatedImportMessageExtension] + value:importMessage]; [importMessage release]; [message addExtension:[UnittestRoot repeatedNestedEnumExtension] - value:@((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz)]; + value:@((i % 2) ? TestAllTypes_NestedEnum_Bar + : TestAllTypes_NestedEnum_Baz)]; [message addExtension:[UnittestRoot repeatedForeignEnumExtension] - value:@((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz)]; - [message addExtension:[UnittestRoot repeatedImportEnumExtension] - value:@((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz)]; + value:@((i % 2) ? ForeignEnum_ForeignBar + : ForeignEnum_ForeignBaz)]; + [message + addExtension:[UnittestRoot repeatedImportEnumExtension] + value:@((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz)]; string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; - [message addExtension:[UnittestRoot repeatedStringPieceExtension] value:string]; + [message addExtension:[UnittestRoot repeatedStringPieceExtension] + value:string]; [string release]; string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; @@ -1066,10 +1077,13 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message setExtension:[UnittestRoot defaultNestedEnumExtension] value:@(TestAllTypes_NestedEnum_Foo)]; - [message setExtension:[UnittestRoot defaultForeignEnumExtension] value:@(ForeignEnum_ForeignFoo)]; - [message setExtension:[UnittestRoot defaultImportEnumExtension] value:@(ImportEnum_ImportFoo)]; + [message setExtension:[UnittestRoot defaultForeignEnumExtension] + value:@(ForeignEnum_ForeignFoo)]; + [message setExtension:[UnittestRoot defaultImportEnumExtension] + value:@(ImportEnum_ImportFoo)]; - [message setExtension:[UnittestRoot defaultStringPieceExtension] value:@"424"]; + [message setExtension:[UnittestRoot defaultStringPieceExtension] + value:@"424"]; [message setExtension:[UnittestRoot defaultCordExtension] value:@"425"]; } @@ -1099,8 +1113,9 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.mapInt32Bytes setObject:data forKey:113 + i * 100]; [data release]; - [message.mapInt32Enum setEnum:(i % 2) ? MapEnum_MapEnumBar : MapEnum_MapEnumBaz - forKey:114 + i * 100]; + [message.mapInt32Enum + setEnum:(i % 2) ? MapEnum_MapEnumBar : MapEnum_MapEnumBaz + forKey:114 + i * 100]; ForeignMessage *subMsg = [[ForeignMessage alloc] init]; subMsg.c = i + 1; @@ -1361,7 +1376,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualWithAccuracy(52e3, message.defaultDouble, 0.1); XCTAssertTrue(message.defaultBool); XCTAssertEqualObjects(@"hello", message.defaultString); - XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], message.defaultBytes); + XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], + message.defaultBytes); XCTAssertEqual(TestAllTypes_NestedEnum_Bar, message.defaultNestedEnum); XCTAssertEqual(ForeignEnum_ForeignBar, message.defaultForeignEnum); @@ -1403,29 +1419,20 @@ const uint32_t kGPBDefaultRepeatCount = 2; // Optional fields without defaults are set to zero or something like it. XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]); - XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); - XCTAssertEqual(0U, - [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); - XCTAssertEqual( - 0ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]); + XCTAssertEqual(0LL,[[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); + XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); + XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]); XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]); - XCTAssertEqual(0LL, - [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); - XCTAssertEqual(0U, - [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); - XCTAssertEqual( - 0ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]); + XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); + XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); + XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]); XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]); - XCTAssertEqual(0LL, - [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); - XCTAssertEqualWithAccuracy( - 0.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 0.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); + XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); + XCTAssertEqualWithAccuracy(0.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); + XCTAssertEqualWithAccuracy(0.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); XCTAssertFalse([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]); XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringExtension]]); - XCTAssertEqualObjects(GPBEmptyNSData(), - [message getExtension:[UnittestRoot optionalBytesExtension]]); + XCTAssertEqualObjects(GPBEmptyNSData(), [message getExtension:[UnittestRoot optionalBytesExtension]]); // Embedded messages should also be clear. @@ -1434,20 +1441,18 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertFalse([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]); XCTAssertFalse([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]); - XCTAssertEqual(0, [(TestAllTypes_OptionalGroup *)[message - getExtension:[UnittestRoot optionalGroupExtension]] a]); - XCTAssertEqual(0, [(TestAllTypes_NestedMessage *)[message - getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); + XCTAssertEqual(0, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]); + XCTAssertEqual(0, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]); XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]); // Enums without defaults are set to the first value in the enum. XCTAssertEqual(TestAllTypes_NestedEnum_Foo, - [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); XCTAssertEqual(ForeignEnum_ForeignFoo, - [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); XCTAssertEqual(ImportEnum_ImportFoo, - [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringPieceExtension]]); XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalCordExtension]]); @@ -1505,36 +1510,28 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertFalse([message hasExtension:[UnittestRoot defaultCordExtension]]); // Fields with defaults have their default values (duh). - XCTAssertEqual(41, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]); - XCTAssertEqual(42LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); - XCTAssertEqual(43U, - [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); - XCTAssertEqual( - 44ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); + XCTAssertEqual( 41, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]); + XCTAssertEqual( 42LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); + XCTAssertEqual( 43U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); + XCTAssertEqual( 44ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); XCTAssertEqual(-45, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]); - XCTAssertEqual(46LL, - [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); - XCTAssertEqual(47, [[message getExtension:[UnittestRoot defaultFixed32Extension]] intValue]); - XCTAssertEqual( - 48ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]); - XCTAssertEqual(49, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]); - XCTAssertEqual(-50LL, - [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); - XCTAssertEqualWithAccuracy( - 51.5f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); - XCTAssertEqualWithAccuracy( - 52e3, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); + XCTAssertEqual( 46LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); + XCTAssertEqual( 47, [[message getExtension:[UnittestRoot defaultFixed32Extension]] intValue]); + XCTAssertEqual( 48ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]); + XCTAssertEqual( 49, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]); + XCTAssertEqual(-50LL, [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); + XCTAssertEqualWithAccuracy( 51.5f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); + XCTAssertEqualWithAccuracy( 52e3, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); XCTAssertTrue([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]); XCTAssertEqualObjects(@"hello", [message getExtension:[UnittestRoot defaultStringExtension]]); - XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], - [message getExtension:[UnittestRoot defaultBytesExtension]]); + XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], [message getExtension:[UnittestRoot defaultBytesExtension]]); XCTAssertEqual(TestAllTypes_NestedEnum_Bar, - [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); XCTAssertEqual(ForeignEnum_ForeignBar, - [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); XCTAssertEqual(ImportEnum_ImportBar, - [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); + [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); XCTAssertEqualObjects(@"abc", [message getExtension:[UnittestRoot defaultStringPieceExtension]]); XCTAssertEqualObjects(@"123", [message getExtension:[UnittestRoot defaultCordExtension]]); @@ -1560,24 +1557,29 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.repeatedBytesArray replaceObjectAtIndex:1 withObject:data]; [data release]; - TestAllTypes_RepeatedGroup *testAll = [[TestAllTypes_RepeatedGroup alloc] init]; + TestAllTypes_RepeatedGroup *testAll = + [[TestAllTypes_RepeatedGroup alloc] init]; [testAll setA:517]; [message.repeatedGroupArray replaceObjectAtIndex:1 withObject:testAll]; [testAll release]; - TestAllTypes_NestedMessage *nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; + TestAllTypes_NestedMessage *nestedMessage = + [[TestAllTypes_NestedMessage alloc] init]; [nestedMessage setBb:518]; - [message.repeatedNestedMessageArray replaceObjectAtIndex:1 withObject:nestedMessage]; + [message.repeatedNestedMessageArray replaceObjectAtIndex:1 + withObject:nestedMessage]; [nestedMessage release]; ForeignMessage *foreignMessage = [[ForeignMessage alloc] init]; [foreignMessage setC:519]; - [message.repeatedForeignMessageArray replaceObjectAtIndex:1 withObject:foreignMessage]; + [message.repeatedForeignMessageArray replaceObjectAtIndex:1 + withObject:foreignMessage]; [foreignMessage release]; ImportMessage *importMessage = [[ImportMessage alloc] init]; [importMessage setD:520]; - [message.repeatedImportMessageArray replaceObjectAtIndex:1 withObject:importMessage]; + [message.repeatedImportMessageArray replaceObjectAtIndex:1 + withObject:importMessage]; [importMessage release]; [message.repeatedNestedEnumArray replaceValueAtIndex:1 withValue:TestAllTypes_NestedEnum_Foo]; @@ -1588,7 +1590,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.repeatedCordArray replaceObjectAtIndex:1 withObject:@"525"]; } -- (void)assertRepeatedFieldsModified:(TestAllTypes *)message repeatedCount:(uint32_t)count { +- (void)assertRepeatedFieldsModified:(TestAllTypes *)message + repeatedCount:(uint32_t)count { // ModifyRepeatedFields only sets the second repeated element of each // field. In addition to verifying this, we also verify that the first // element and size were *not* modified. @@ -1661,12 +1664,13 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualWithAccuracy(212.0, [message.repeatedDoubleArray valueAtIndex:0], 0.01); XCTAssertFalse([message.repeatedBoolArray valueAtIndex:0]); XCTAssertEqualObjects(@"215", message.repeatedStringArray[0]); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], message.repeatedBytesArray[0]); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], + message.repeatedBytesArray[0]); - XCTAssertEqual(217, ((TestAllTypes_RepeatedGroup *)message.repeatedGroupArray[0]).a); - XCTAssertEqual(218, ((TestAllTypes_NestedMessage *)message.repeatedNestedMessageArray[0]).bb); - XCTAssertEqual(219, ((ForeignMessage *)message.repeatedForeignMessageArray[0]).c); - XCTAssertEqual(220, ((ImportMessage *)message.repeatedImportMessageArray[0]).d); + XCTAssertEqual(217, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[0]).a); + XCTAssertEqual(218, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[0]).bb); + XCTAssertEqual(219, ((ForeignMessage*)message.repeatedForeignMessageArray[0]).c); + XCTAssertEqual(220, ((ImportMessage*)message.repeatedImportMessageArray[0]).d); XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:0]); XCTAssertEqual(ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:0]); @@ -1690,12 +1694,13 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualWithAccuracy(512.0, [message.repeatedDoubleArray valueAtIndex:1], 0.01); XCTAssertTrue([message.repeatedBoolArray valueAtIndex:1]); XCTAssertEqualObjects(@"515", message.repeatedStringArray[1]); - XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], message.repeatedBytesArray[1]); + XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], + message.repeatedBytesArray[1]); - XCTAssertEqual(517, ((TestAllTypes_RepeatedGroup *)message.repeatedGroupArray[1]).a); - XCTAssertEqual(518, ((TestAllTypes_NestedMessage *)message.repeatedNestedMessageArray[1]).bb); - XCTAssertEqual(519, ((ForeignMessage *)message.repeatedForeignMessageArray[1]).c); - XCTAssertEqual(520, ((ImportMessage *)message.repeatedImportMessageArray[1]).d); + XCTAssertEqual(517, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[1]).a); + XCTAssertEqual(518, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[1]).bb); + XCTAssertEqual(519, ((ForeignMessage*)message.repeatedForeignMessageArray[1]).c); + XCTAssertEqual(520, ((ImportMessage*)message.repeatedImportMessageArray[1]).d); XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [message.repeatedNestedEnumArray valueAtIndex:1]); XCTAssertEqual(ForeignEnum_ForeignFoo, [message.repeatedForeignEnumArray valueAtIndex:1]); @@ -1705,7 +1710,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(@"525", message.repeatedCordArray[1]); } -- (void)setPackedFields:(TestPackedTypes *)message repeatedCount:(uint32_t)count { +- (void)setPackedFields:(TestPackedTypes *)message + repeatedCount:(uint32_t)count { // Must match -setUnpackedFields:repeatedCount: // Must match -setPackedExtensions:repeatedCount: // Must match -setUnpackedExtensions:repeatedCount: @@ -1749,11 +1755,13 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.packedBoolArray addValue:(i % 2) ? YES : NO]; } for (uint32_t i = 0; i < count; ++i) { - [message.packedEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; + [message.packedEnumArray + addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; } } -- (void)setUnpackedFields:(TestUnpackedTypes *)message repeatedCount:(uint32_t)count { +- (void)setUnpackedFields:(TestUnpackedTypes *)message + repeatedCount:(uint32_t)count { // Must match -setPackedFields:repeatedCount: // Must match -setPackedExtensions:repeatedCount: // Must match -setUnpackedExtensions:repeatedCount: @@ -1797,11 +1805,13 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message.unpackedBoolArray addValue:(i % 2) ? YES : NO]; } for (uint32_t i = 0; i < count; ++i) { - [message.unpackedEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; + [message.unpackedEnumArray + addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; } } -- (void)assertPackedFieldsSet:(TestPackedTypes *)message repeatedCount:(uint32_t)count { +- (void)assertPackedFieldsSet:(TestPackedTypes *)message + repeatedCount:(uint32_t)count { XCTAssertEqual(count, message.packedInt32Array.count); XCTAssertEqual(count, message.packedInt64Array.count); XCTAssertEqual(count, message.packedUint32Array.count); @@ -1817,71 +1827,108 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, message.packedBoolArray.count); XCTAssertEqual(count, message.packedEnumArray.count); for (uint32_t i = 0; i < count; ++i) { - XCTAssertEqual((int)(601 + i * 100), [message.packedInt32Array valueAtIndex:i]); + XCTAssertEqual((int)(601 + i * 100), + [message.packedInt32Array valueAtIndex:i]); XCTAssertEqual(602 + i * 100, [message.packedInt64Array valueAtIndex:i]); XCTAssertEqual(603 + i * 100, [message.packedUint32Array valueAtIndex:i]); XCTAssertEqual(604 + i * 100, [message.packedUint64Array valueAtIndex:i]); - XCTAssertEqual((int)(605 + i * 100), [message.packedSint32Array valueAtIndex:i]); + XCTAssertEqual((int)(605 + i * 100), + [message.packedSint32Array valueAtIndex:i]); XCTAssertEqual(606 + i * 100, [message.packedSint64Array valueAtIndex:i]); XCTAssertEqual(607 + i * 100, [message.packedFixed32Array valueAtIndex:i]); XCTAssertEqual(608 + i * 100, [message.packedFixed64Array valueAtIndex:i]); - XCTAssertEqual((int)(609 + i * 100), [message.packedSfixed32Array valueAtIndex:i]); + XCTAssertEqual((int)(609 + i * 100), + [message.packedSfixed32Array valueAtIndex:i]); XCTAssertEqual(610 + i * 100, [message.packedSfixed64Array valueAtIndex:i]); - XCTAssertEqualWithAccuracy(611 + i * 100, [message.packedFloatArray valueAtIndex:i], 0.01); - XCTAssertEqualWithAccuracy(612 + i * 100, [message.packedDoubleArray valueAtIndex:i], 0.01); - XCTAssertEqual((i % 2) ? YES : NO, [message.packedBoolArray valueAtIndex:i]); + XCTAssertEqualWithAccuracy(611 + i * 100, + [message.packedFloatArray valueAtIndex:i], 0.01); + XCTAssertEqualWithAccuracy( + 612 + i * 100, [message.packedDoubleArray valueAtIndex:i], 0.01); + XCTAssertEqual((i % 2) ? YES : NO, + [message.packedBoolArray valueAtIndex:i]); XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [message.packedEnumArray valueAtIndex:i]); } } -- (void)setPackedExtensions:(TestPackedExtensions *)message repeatedCount:(uint32_t)count { +- (void)setPackedExtensions:(TestPackedExtensions *)message + repeatedCount:(uint32_t)count { // Must match -setPackedFields:repeatedCount: // Must match -setUnpackedFields:repeatedCount: // Must match -setUnpackedExtensions:repeatedCount: for (uint32_t i = 0; i < count; i++) { - [message addExtension:[UnittestRoot packedInt32Extension] value:@(601 + i * 100)]; - [message addExtension:[UnittestRoot packedInt64Extension] value:@(602 + i * 100)]; - [message addExtension:[UnittestRoot packedUint32Extension] value:@(603 + i * 100)]; - [message addExtension:[UnittestRoot packedUint64Extension] value:@(604 + i * 100)]; - [message addExtension:[UnittestRoot packedSint32Extension] value:@(605 + i * 100)]; - [message addExtension:[UnittestRoot packedSint64Extension] value:@(606 + i * 100)]; - [message addExtension:[UnittestRoot packedFixed32Extension] value:@(607 + i * 100)]; - [message addExtension:[UnittestRoot packedFixed64Extension] value:@(608 + i * 100)]; - [message addExtension:[UnittestRoot packedSfixed32Extension] value:@(609 + i * 100)]; - [message addExtension:[UnittestRoot packedSfixed64Extension] value:@(610 + i * 100)]; - [message addExtension:[UnittestRoot packedFloatExtension] value:@(611 + i * 100)]; - [message addExtension:[UnittestRoot packedDoubleExtension] value:@(612 + i * 100)]; - [message addExtension:[UnittestRoot packedBoolExtension] value:@((i % 2) ? YES : NO)]; + [message addExtension:[UnittestRoot packedInt32Extension] + value:@(601 + i * 100)]; + [message addExtension:[UnittestRoot packedInt64Extension] + value:@(602 + i * 100)]; + [message addExtension:[UnittestRoot packedUint32Extension] + value:@(603 + i * 100)]; + [message addExtension:[UnittestRoot packedUint64Extension] + value:@(604 + i * 100)]; + [message addExtension:[UnittestRoot packedSint32Extension] + value:@(605 + i * 100)]; + [message addExtension:[UnittestRoot packedSint64Extension] + value:@(606 + i * 100)]; + [message addExtension:[UnittestRoot packedFixed32Extension] + value:@(607 + i * 100)]; + [message addExtension:[UnittestRoot packedFixed64Extension] + value:@(608 + i * 100)]; + [message addExtension:[UnittestRoot packedSfixed32Extension] + value:@(609 + i * 100)]; + [message addExtension:[UnittestRoot packedSfixed64Extension] + value:@(610 + i * 100)]; + [message addExtension:[UnittestRoot packedFloatExtension] + value:@(611 + i * 100)]; + [message addExtension:[UnittestRoot packedDoubleExtension] + value:@(612 + i * 100)]; + [message addExtension:[UnittestRoot packedBoolExtension] + value:@((i % 2) ? YES : NO)]; [message addExtension:[UnittestRoot packedEnumExtension] - value:@((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz)]; + value:@((i % 2) ? ForeignEnum_ForeignBar + : ForeignEnum_ForeignBaz)]; } } -- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message repeatedCount:(uint32_t)count { +- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message + repeatedCount:(uint32_t)count { // Must match -setPackedFields:repeatedCount: // Must match -setUnpackedFields:repeatedCount: // Must match -setPackedExtensions:repeatedCount: for (uint32_t i = 0; i < count; i++) { - [message addExtension:[UnittestRoot unpackedInt32Extension] value:@(601 + i * 100)]; - [message addExtension:[UnittestRoot unpackedInt64Extension] value:@(602 + i * 100)]; - [message addExtension:[UnittestRoot unpackedUint32Extension] value:@(603 + i * 100)]; - [message addExtension:[UnittestRoot unpackedUint64Extension] value:@(604 + i * 100)]; - [message addExtension:[UnittestRoot unpackedSint32Extension] value:@(605 + i * 100)]; - [message addExtension:[UnittestRoot unpackedSint64Extension] value:@(606 + i * 100)]; - [message addExtension:[UnittestRoot unpackedFixed32Extension] value:@(607 + i * 100)]; - [message addExtension:[UnittestRoot unpackedFixed64Extension] value:@(608 + i * 100)]; - [message addExtension:[UnittestRoot unpackedSfixed32Extension] value:@(609 + i * 100)]; - [message addExtension:[UnittestRoot unpackedSfixed64Extension] value:@(610 + i * 100)]; - [message addExtension:[UnittestRoot unpackedFloatExtension] value:@(611 + i * 100)]; - [message addExtension:[UnittestRoot unpackedDoubleExtension] value:@(612 + i * 100)]; - [message addExtension:[UnittestRoot unpackedBoolExtension] value:@((i % 2) ? YES : NO)]; + [message addExtension:[UnittestRoot unpackedInt32Extension] + value:@(601 + i * 100)]; + [message addExtension:[UnittestRoot unpackedInt64Extension] + value:@(602 + i * 100)]; + [message addExtension:[UnittestRoot unpackedUint32Extension] + value:@(603 + i * 100)]; + [message addExtension:[UnittestRoot unpackedUint64Extension] + value:@(604 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSint32Extension] + value:@(605 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSint64Extension] + value:@(606 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFixed32Extension] + value:@(607 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFixed64Extension] + value:@(608 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSfixed32Extension] + value:@(609 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSfixed64Extension] + value:@(610 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFloatExtension] + value:@(611 + i * 100)]; + [message addExtension:[UnittestRoot unpackedDoubleExtension] + value:@(612 + i * 100)]; + [message addExtension:[UnittestRoot unpackedBoolExtension] + value:@((i % 2) ? YES : NO)]; [message addExtension:[UnittestRoot unpackedEnumExtension] - value:@((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz)]; + value:@((i % 2) ? ForeignEnum_ForeignBar + : ForeignEnum_ForeignBaz)]; } } -- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message repeatedCount:(uint32_t)count { +- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message + repeatedCount:(uint32_t)count{ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt32Extension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt64Extension]] count]); XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint32Extension]] count]); @@ -1969,24 +2016,20 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @YES); XCTAssertNotNil(message.optionalNestedMessage); XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.hasBb"], @YES); - XCTAssertEqualObjects(@(message.optionalNestedMessage.bb), - [message valueForKeyPath:@"optionalNestedMessage.bb"]); + XCTAssertEqualObjects(@(message.optionalNestedMessage.bb), [message valueForKeyPath:@"optionalNestedMessage.bb"]); XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], @YES); XCTAssertNotNil(message.optionalForeignMessage); XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.hasC"], @YES); - XCTAssertEqualObjects(@(message.optionalForeignMessage.c), - [message valueForKeyPath:@"optionalForeignMessage.c"]); + XCTAssertEqualObjects(@(message.optionalForeignMessage.c), [message valueForKeyPath:@"optionalForeignMessage.c"]); XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @YES); XCTAssertNotNil(message.optionalForeignMessage); XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], @YES); - XCTAssertEqualObjects(@(message.optionalImportMessage.d), - [message valueForKeyPath:@"optionalImportMessage.d"]); + XCTAssertEqualObjects(@(message.optionalImportMessage.d), [message valueForKeyPath:@"optionalImportMessage.d"]); XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @YES); XCTAssertEqualObjects(@(message.optionalNestedEnum), [message valueForKey:@"optionalNestedEnum"]); XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @YES); - XCTAssertEqualObjects(@(message.optionalForeignEnum), - [message valueForKey:@"optionalForeignEnum"]); + XCTAssertEqualObjects(@(message.optionalForeignEnum), [message valueForKey:@"optionalForeignEnum"]); XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @YES); XCTAssertEqualObjects(@(message.optionalImportEnum), [message valueForKey:@"optionalImportEnum"]); @@ -2005,14 +2048,10 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(message.repeatedUint64Array, [message valueForKey:@"repeatedUint64Array"]); XCTAssertEqualObjects(message.repeatedSint32Array, [message valueForKey:@"repeatedSint32Array"]); XCTAssertEqualObjects(message.repeatedSint64Array, [message valueForKey:@"repeatedSint64Array"]); - XCTAssertEqualObjects(message.repeatedFixed32Array, - [message valueForKey:@"repeatedFixed32Array"]); - XCTAssertEqualObjects(message.repeatedFixed64Array, - [message valueForKey:@"repeatedFixed64Array"]); - XCTAssertEqualObjects(message.repeatedSfixed32Array, - [message valueForKey:@"repeatedSfixed32Array"]); - XCTAssertEqualObjects(message.repeatedSfixed64Array, - [message valueForKey:@"repeatedSfixed64Array"]); + XCTAssertEqualObjects(message.repeatedFixed32Array, [message valueForKey:@"repeatedFixed32Array"]); + XCTAssertEqualObjects(message.repeatedFixed64Array, [message valueForKey:@"repeatedFixed64Array"]); + XCTAssertEqualObjects(message.repeatedSfixed32Array, [message valueForKey:@"repeatedSfixed32Array"]); + XCTAssertEqualObjects(message.repeatedSfixed64Array, [message valueForKey:@"repeatedSfixed64Array"]); XCTAssertEqualObjects(message.repeatedFloatArray, [message valueForKey:@"repeatedFloatArray"]); XCTAssertEqualObjects(message.repeatedDoubleArray, [message valueForKey:@"repeatedDoubleArray"]); XCTAssertEqualObjects(message.repeatedBoolArray, [message valueForKey:@"repeatedBoolArray"]); @@ -2020,75 +2059,44 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(message.repeatedBytesArray, [message valueForKey:@"repeatedBytesArray"]); XCTAssertEqualObjects(message.repeatedGroupArray, [message valueForKey:@"repeatedGroupArray"]); - XCTAssertEqualObjects(message.repeatedNestedMessageArray, - [message valueForKey:@"repeatedNestedMessageArray"]); - XCTAssertEqualObjects(message.repeatedForeignMessageArray, - [message valueForKey:@"repeatedForeignMessageArray"]); - XCTAssertEqualObjects(message.repeatedImportMessageArray, - [message valueForKey:@"repeatedImportMessageArray"]); + XCTAssertEqualObjects(message.repeatedNestedMessageArray, [message valueForKey:@"repeatedNestedMessageArray"]); + XCTAssertEqualObjects(message.repeatedForeignMessageArray, [message valueForKey:@"repeatedForeignMessageArray"]); + XCTAssertEqualObjects(message.repeatedImportMessageArray, [message valueForKey:@"repeatedImportMessageArray"]); - XCTAssertEqualObjects(message.repeatedNestedEnumArray, - [message valueForKey:@"repeatedNestedEnumArray"]); - XCTAssertEqualObjects(message.repeatedForeignEnumArray, - [message valueForKey:@"repeatedForeignEnumArray"]); - XCTAssertEqualObjects(message.repeatedImportEnumArray, - [message valueForKey:@"repeatedImportEnumArray"]); + XCTAssertEqualObjects(message.repeatedNestedEnumArray, [message valueForKey:@"repeatedNestedEnumArray"]); + XCTAssertEqualObjects(message.repeatedForeignEnumArray, [message valueForKey:@"repeatedForeignEnumArray"]); + XCTAssertEqualObjects(message.repeatedImportEnumArray, [message valueForKey:@"repeatedImportEnumArray"]); - XCTAssertEqualObjects(message.repeatedStringPieceArray, - [message valueForKey:@"repeatedStringPieceArray"]); + XCTAssertEqualObjects(message.repeatedStringPieceArray, [message valueForKey:@"repeatedStringPieceArray"]); XCTAssertEqualObjects(message.repeatedCordArray, [message valueForKey:@"repeatedCordArray"]); - XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), - [message valueForKey:@"repeatedInt32Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), - [message valueForKey:@"repeatedInt64Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), - [message valueForKey:@"repeatedUint32Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), - [message valueForKey:@"repeatedUint64Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), - [message valueForKey:@"repeatedSint32Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), - [message valueForKey:@"repeatedSint64Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), - [message valueForKey:@"repeatedFixed32Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), - [message valueForKey:@"repeatedFixed64Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), - [message valueForKey:@"repeatedSfixed32Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), - [message valueForKey:@"repeatedSfixed64Array_Count"]); - XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), - [message valueForKey:@"repeatedFloatArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), - [message valueForKey:@"repeatedDoubleArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), - [message valueForKey:@"repeatedBoolArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedStringArray_Count), - [message valueForKey:@"repeatedStringArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), - [message valueForKey:@"repeatedBytesArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), [message valueForKey:@"repeatedInt32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), [message valueForKey:@"repeatedInt64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), [message valueForKey:@"repeatedUint32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), [message valueForKey:@"repeatedUint64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), [message valueForKey:@"repeatedSint32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), [message valueForKey:@"repeatedSint64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), [message valueForKey:@"repeatedFixed32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), [message valueForKey:@"repeatedFixed64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), [message valueForKey:@"repeatedSfixed32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), [message valueForKey:@"repeatedSfixed64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), [message valueForKey:@"repeatedFloatArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), [message valueForKey:@"repeatedDoubleArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), [message valueForKey:@"repeatedBoolArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedStringArray_Count), [message valueForKey:@"repeatedStringArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), [message valueForKey:@"repeatedBytesArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), - [message valueForKey:@"repeatedGroupArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), - [message valueForKey:@"repeatedNestedMessageArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), - [message valueForKey:@"repeatedForeignMessageArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), - [message valueForKey:@"repeatedImportMessageArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), [message valueForKey:@"repeatedGroupArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), [message valueForKey:@"repeatedNestedMessageArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), [message valueForKey:@"repeatedForeignMessageArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), [message valueForKey:@"repeatedImportMessageArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), - [message valueForKey:@"repeatedNestedEnumArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), - [message valueForKey:@"repeatedForeignEnumArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), - [message valueForKey:@"repeatedImportEnumArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), [message valueForKey:@"repeatedNestedEnumArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), [message valueForKey:@"repeatedForeignEnumArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), [message valueForKey:@"repeatedImportEnumArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), - [message valueForKey:@"repeatedStringPieceArray_Count"]); - XCTAssertEqualObjects(@(message.repeatedCordArray_Count), - [message valueForKey:@"repeatedCordArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), [message valueForKey:@"repeatedStringPieceArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedCordArray_Count), [message valueForKey:@"repeatedCordArray_Count"]); // ----------------------------------------------------------------- @@ -2136,7 +2144,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(message.defaultCord, [message valueForKey:@"defaultCord"]); } -- (void)setAllFieldsViaKVC:(TestAllTypes *)message repeatedCount:(uint32_t)count { +- (void)setAllFieldsViaKVC:(TestAllTypes *)message + repeatedCount:(uint32_t)count { [message setValue:@101 forKey:@"optionalInt32"]; [message setValue:@102 forKey:@"optionalInt64"]; [message setValue:@103 forKey:@"optionalUint32"]; @@ -2151,12 +2160,14 @@ const uint32_t kGPBDefaultRepeatCount = 2; [message setValue:@112 forKey:@"optionalDouble"]; [message setValue:@YES forKey:@"optionalBool"]; [message setValue:@"115" forKey:@"optionalString"]; - [message setValue:[NSData gpbtu_dataWithEmbeddedNulls] forKey:@"optionalBytes"]; + [message setValue:[NSData gpbtu_dataWithEmbeddedNulls] + forKey:@"optionalBytes"]; TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message]; [allTypes setValue:@117 forKey:@"a"]; [message setValue:allTypes forKey:@"optionalGroup"]; - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; [nestedMessage setValue:@118 forKey:@"bb"]; [message setValue:nestedMessage forKey:@"optionalNestedMessage"]; ForeignMessage *foreignMessage = [ForeignMessage message]; @@ -2166,7 +2177,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; [importMessage setValue:@120 forKey:@"d"]; [message setValue:importMessage forKey:@"optionalImportMessage"]; - [message setValue:@(TestAllTypes_NestedEnum_Baz) forKey:@"optionalNestedEnum"]; + [message setValue:@(TestAllTypes_NestedEnum_Baz) + forKey:@"optionalNestedEnum"]; [message setValue:@(ForeignEnum_ForeignBaz) forKey:@"optionalForeignEnum"]; [message setValue:@(ImportEnum_ImportBaz) forKey:@"optionalImportEnum"]; @@ -2287,7 +2299,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; array = [[NSMutableArray alloc] initWithCapacity:count]; for (uint32_t i = 0; i < count; ++i) { - TestAllTypes_RepeatedGroup *testAll = [[TestAllTypes_RepeatedGroup alloc] init]; + TestAllTypes_RepeatedGroup *testAll = + [[TestAllTypes_RepeatedGroup alloc] init]; [testAll setA:217 + i * 100]; [array addObject:testAll]; [testAll release]; @@ -2326,22 +2339,26 @@ const uint32_t kGPBDefaultRepeatCount = 2; [array release]; { - GPBEnumArray *scratch = - [GPBEnumArray arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue]; + GPBEnumArray *scratch = [GPBEnumArray + arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue]; for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz]; + [scratch addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar + : TestAllTypes_NestedEnum_Baz]; } [message setValue:scratch forKey:@"repeatedNestedEnumArray"]; } { - GPBEnumArray *scratch = [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue]; + GPBEnumArray *scratch = + [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue]; for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; + [scratch + addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; } [message setValue:scratch forKey:@"repeatedForeignEnumArray"]; } { - GPBEnumArray *scratch = [GPBEnumArray arrayWithValidationFunction:ImportEnum_IsValidValue]; + GPBEnumArray *scratch = + [GPBEnumArray arrayWithValidationFunction:ImportEnum_IsValidValue]; for (uint32_t i = 0; i < count; ++i) { [scratch addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz]; } @@ -2411,7 +2428,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @NO); XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @NO); - XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], @NO); + XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], + @NO); XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @NO); XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @NO); @@ -2436,7 +2454,8 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects([message valueForKey:@"optionalDouble"], @0); XCTAssertEqualObjects([message valueForKey:@"optionalBool"], @NO); XCTAssertEqualObjects([message valueForKey:@"optionalString"], @""); - XCTAssertEqualObjects([message valueForKey:@"optionalBytes"], GPBEmptyNSData()); + XCTAssertEqualObjects([message valueForKey:@"optionalBytes"], + GPBEmptyNSData()); // Embedded messages should also be exist, but be clear. XCTAssertNotNil([message valueForKeyPath:@"optionalGroup"]); @@ -2444,20 +2463,28 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertNotNil([message valueForKeyPath:@"optionalForeignMessage"]); XCTAssertNotNil([message valueForKeyPath:@"optionalImportMessage"]); XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @NO); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.hasBb"], @NO); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.hasC"], @NO); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], @NO); + XCTAssertEqualObjects( + [message valueForKeyPath:@"optionalNestedMessage.hasBb"], @NO); + XCTAssertEqualObjects( + [message valueForKeyPath:@"optionalForeignMessage.hasC"], @NO); + XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], + @NO); XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.a"], @0); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.bb"], @0); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.c"], @0); - XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.d"], @0); + XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.bb"], + @0); + XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.c"], + @0); + XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.d"], + @0); // Enums without defaults are set to the first value in the enum. XCTAssertEqualObjects([message valueForKey:@"optionalNestedEnum"], @(TestAllTypes_NestedEnum_Foo)); - XCTAssertEqualObjects([message valueForKey:@"optionalForeignEnum"], @(ForeignEnum_ForeignFoo)); - XCTAssertEqualObjects([message valueForKey:@"optionalImportEnum"], @(ImportEnum_ImportFoo)); + XCTAssertEqualObjects([message valueForKey:@"optionalForeignEnum"], + @(ForeignEnum_ForeignFoo)); + XCTAssertEqualObjects([message valueForKey:@"optionalImportEnum"], + @(ImportEnum_ImportFoo)); XCTAssertEqualObjects([message valueForKey:@"optionalStringPiece"], @""); XCTAssertEqualObjects([message valueForKey:@"optionalCord"], @""); @@ -2505,9 +2532,12 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects([message valueForKey:@"defaultBytes"], [NSData gpbtu_dataWithCString:"world"]); - XCTAssertEqualObjects([message valueForKey:@"defaultNestedEnum"], @(TestAllTypes_NestedEnum_Bar)); - XCTAssertEqualObjects([message valueForKey:@"defaultForeignEnum"], @(ForeignEnum_ForeignBar)); - XCTAssertEqualObjects([message valueForKey:@"defaultImportEnum"], @(ImportEnum_ImportBar)); + XCTAssertEqualObjects([message valueForKey:@"defaultNestedEnum"], + @(TestAllTypes_NestedEnum_Bar)); + XCTAssertEqualObjects([message valueForKey:@"defaultForeignEnum"], + @(ForeignEnum_ForeignBar)); + XCTAssertEqualObjects([message valueForKey:@"defaultImportEnum"], + @(ImportEnum_ImportBar)); XCTAssertEqualObjects([message valueForKey:@"defaultStringPiece"], @"abc"); XCTAssertEqualObjects([message valueForKey:@"defaultCord"], @"123"); diff --git a/libs/protobuf/objectivec/Tests/GPBUnittestProtos.m b/libs/protobuf/objectivec/Tests/GPBUnittestProtos.m index 6208e12..1c6eddf 100644 --- a/libs/protobuf/objectivec/Tests/GPBUnittestProtos.m +++ b/libs/protobuf/objectivec/Tests/GPBUnittestProtos.m @@ -31,27 +31,43 @@ // Collects all the compiled protos into one file and compiles them to make sure // the compiler is generating valid code. -#import "objectivec/Tests/AnyTest.pbobjc.m" -#import "objectivec/Tests/MapProto2Unittest.pbobjc.m" -#import "objectivec/Tests/MapUnittest.pbobjc.m" -#import "objectivec/Tests/Unittest.pbobjc.m" -#import "objectivec/Tests/UnittestCycle.pbobjc.m" -#import "objectivec/Tests/UnittestDeprecated.pbobjc.m" -#import "objectivec/Tests/UnittestDeprecatedFile.pbobjc.m" -#import "objectivec/Tests/UnittestImport.pbobjc.m" -#import "objectivec/Tests/UnittestImportPublic.pbobjc.m" -#import "objectivec/Tests/UnittestMset.pbobjc.m" -#import "objectivec/Tests/UnittestObjc.pbobjc.m" -#import "objectivec/Tests/UnittestObjcOptions.pbobjc.m" -#import "objectivec/Tests/UnittestObjcStartup.pbobjc.m" -#import "objectivec/Tests/UnittestPreserveUnknownEnum.pbobjc.m" -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.m" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.m" +// The unittest_custom_options.proto extends the messages in descriptor.proto +// so we build it in to test extending in general. The library doesn't provide +// a descriptor as it doesn't use the classes/enums. +#import "google/protobuf/Descriptor.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainA.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainB.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainC.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainD.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainE.pbobjc.m" +#import "google/protobuf/AnyTest.pbobjc.m" +#import "google/protobuf/MapProto2Unittest.pbobjc.m" +#import "google/protobuf/MapUnittest.pbobjc.m" +#import "google/protobuf/Unittest.pbobjc.m" +#import "google/protobuf/UnittestArena.pbobjc.m" +#import "google/protobuf/UnittestCustomOptions.pbobjc.m" +#import "google/protobuf/UnittestCycle.pbobjc.m" +#import "google/protobuf/UnittestDeprecated.pbobjc.m" +#import "google/protobuf/UnittestDeprecatedFile.pbobjc.m" +#import "google/protobuf/UnittestDropUnknownFields.pbobjc.m" +#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.m" +#import "google/protobuf/UnittestEmpty.pbobjc.m" +#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.m" +#import "google/protobuf/UnittestImport.pbobjc.m" +#import "google/protobuf/UnittestImportLite.pbobjc.m" +#import "google/protobuf/UnittestImportPublic.pbobjc.m" +#import "google/protobuf/UnittestImportPublicLite.pbobjc.m" +#import "google/protobuf/UnittestLite.pbobjc.m" +#import "google/protobuf/UnittestMset.pbobjc.m" +#import "google/protobuf/UnittestMsetWireFormat.pbobjc.m" +#import "google/protobuf/UnittestNoGenericServices.pbobjc.m" +#import "google/protobuf/UnittestObjc.pbobjc.m" +#import "google/protobuf/UnittestObjcStartup.pbobjc.m" +#import "google/protobuf/UnittestOptimizeFor.pbobjc.m" +#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.m" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.m" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.m" + +#import "google/protobuf/UnittestExtensionChainA.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainB.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainC.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainD.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainE.pbobjc.m" // See GPBUnittestProtos2.m for for "UnittestExtensionChainF.pbobjc.m" -#import "objectivec/Tests/UnittestExtensionChainG.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainG.pbobjc.m" diff --git a/libs/protobuf/objectivec/Tests/GPBUnittestProtos2.m b/libs/protobuf/objectivec/Tests/GPBUnittestProtos2.m index 498d85a..ef9f070 100644 --- a/libs/protobuf/objectivec/Tests/GPBUnittestProtos2.m +++ b/libs/protobuf/objectivec/Tests/GPBUnittestProtos2.m @@ -31,4 +31,4 @@ // This one file in the chain tests is compiled by itself to ensure if was // generated with the extra #imports needed to pull in the indirect Root class // used in its Root registry. -#import "objectivec/Tests/UnittestExtensionChainF.pbobjc.m" +#import "google/protobuf/UnittestExtensionChainF.pbobjc.m" diff --git a/libs/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m b/libs/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m index b98f52e..5fa60b2 100644 --- a/libs/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m +++ b/libs/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m @@ -30,9 +30,9 @@ #import "GPBTestUtilities.h" -#import "GPBUnknownFieldSet_PackagePrivate.h" #import "GPBUnknownField_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" +#import "GPBUnknownFieldSet_PackagePrivate.h" +#import "google/protobuf/Unittest.pbobjc.h" @interface GPBUnknownFieldSet (GPBUnknownFieldSetTest) - (void)getTags:(int32_t*)tags; @@ -61,7 +61,7 @@ } - (void)testInvalidFieldNumber { - GPBUnknownFieldSet* set = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *set = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:0] autorelease]; XCTAssertThrowsSpecificNamed([set addField:field], NSException, NSInvalidArgumentException); } @@ -69,10 +69,10 @@ - (void)testEqualityAndHash { // Empty - GPBUnknownFieldSet* set1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *set1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; XCTAssertTrue([set1 isEqual:set1]); XCTAssertFalse([set1 isEqual:@"foo"]); - GPBUnknownFieldSet* set2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *set2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; XCTAssertEqualObjects(set1, set2); XCTAssertEqual([set1 hash], [set2 hash]); @@ -126,11 +126,11 @@ // Group - GPBUnknownFieldSet* group1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup1 = [[[GPBUnknownField alloc] initWithNumber:10] autorelease]; [fieldGroup1 addVarint:1]; [group1 addField:fieldGroup1]; - GPBUnknownFieldSet* group2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup2 = [[[GPBUnknownField alloc] initWithNumber:10] autorelease]; [fieldGroup2 addVarint:1]; [group2 addField:fieldGroup2]; @@ -153,9 +153,10 @@ // numbers as allFieldsData except that each field is some other wire // type. - (NSData*)getBizarroData { - GPBUnknownFieldSet* bizarroFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet* bizarroFields = + [[[GPBUnknownFieldSet alloc] init] autorelease]; NSUInteger count = [unknownFields_ countOfFields]; - int32_t* tags = malloc(count * sizeof(int32_t)); + int32_t *tags = malloc(count * sizeof(int32_t)); if (!tags) { XCTFail(@"Failed to make scratch buffer for testing"); return [NSData data]; @@ -167,17 +168,20 @@ GPBUnknownField* field = [unknownFields_ getField:tag]; if (field.varintList.count == 0) { // Original field is not a varint, so use a varint. - GPBUnknownField* varintField = [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; + GPBUnknownField* varintField = + [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; [varintField addVarint:1]; [bizarroFields addField:varintField]; } else { // Original field *is* a varint, so use something else. - GPBUnknownField* fixed32Field = [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; + GPBUnknownField* fixed32Field = + [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; [fixed32Field addFixed32:1]; [bizarroFields addField:fixed32Field]; } } - } @finally { + } + @finally { free(tags); } @@ -216,7 +220,7 @@ [field addLengthDelimited:DataFromCStr("data1")]; [set1 addField:field]; - GPBUnknownFieldSet* group1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup1 = [[[GPBUnknownField alloc] initWithNumber:200] autorelease]; [fieldGroup1 addVarint:100]; [group1 addField:fieldGroup1]; @@ -242,7 +246,7 @@ [field addLengthDelimited:DataFromCStr("data2")]; [set2 addField:field]; - GPBUnknownFieldSet* group2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup2 = [[[GPBUnknownField alloc] initWithNumber:201] autorelease]; [fieldGroup2 addVarint:99]; [group2 addField:fieldGroup2]; @@ -276,11 +280,11 @@ [field addLengthDelimited:DataFromCStr("data2")]; [set3 addField:field]; - GPBUnknownFieldSet* group3a = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group3a = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup3a1 = [[[GPBUnknownField alloc] initWithNumber:200] autorelease]; [fieldGroup3a1 addVarint:100]; [group3a addField:fieldGroup3a1]; - GPBUnknownFieldSet* group3b = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group3b = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup3b2 = [[[GPBUnknownField alloc] initWithNumber:201] autorelease]; [fieldGroup3b2 addVarint:99]; [group3b addField:fieldGroup3b2]; @@ -310,7 +314,7 @@ } - (void)testClearMessage { - TestEmptyMessage* message = [TestEmptyMessage message]; + TestEmptyMessage *message = [TestEmptyMessage message]; [message mergeFrom:emptyMessage_]; [message clear]; XCTAssertEqual(message.serializedSize, (size_t)0); @@ -318,8 +322,9 @@ - (void)testParseKnownAndUnknown { // Test mixing known and unknown fields when parsing. - GPBUnknownFieldSet* fields = [[unknownFields_ copy] autorelease]; - GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:123456] autorelease]; + GPBUnknownFieldSet *fields = [[unknownFields_ copy] autorelease]; + GPBUnknownField *field = + [[[GPBUnknownField alloc] initWithNumber:123456] autorelease]; [field addVarint:654321]; [fields addField:field]; @@ -339,8 +344,10 @@ // when parsing. NSData* bizarroData = [self getBizarroData]; - TestAllTypes* allTypesMessage = [TestAllTypes parseFromData:bizarroData error:NULL]; - TestEmptyMessage* emptyMessage = [TestEmptyMessage parseFromData:bizarroData error:NULL]; + TestAllTypes* allTypesMessage = + [TestAllTypes parseFromData:bizarroData error:NULL]; + TestEmptyMessage* emptyMessage = + [TestEmptyMessage parseFromData:bizarroData error:NULL]; // All fields should have been interpreted as unknown, so the debug strings // should be the same. @@ -354,7 +361,8 @@ TestEmptyMessageWithExtensions* message = [TestEmptyMessageWithExtensions parseFromData:allFieldsData_ error:NULL]; - XCTAssertEqual(unknownFields_.countOfFields, message.unknownFields.countOfFields); + XCTAssertEqual(unknownFields_.countOfFields, + message.unknownFields.countOfFields); XCTAssertEqualObjects(allFieldsData_, message.data); } @@ -363,9 +371,10 @@ // when parsing extensions. NSData* bizarroData = [self getBizarroData]; - TestAllExtensions* allExtensionsMessage = [TestAllExtensions parseFromData:bizarroData - error:NULL]; - TestEmptyMessage* emptyMessage = [TestEmptyMessage parseFromData:bizarroData error:NULL]; + TestAllExtensions* allExtensionsMessage = + [TestAllExtensions parseFromData:bizarroData error:NULL]; + TestEmptyMessage* emptyMessage = + [TestEmptyMessage parseFromData:bizarroData error:NULL]; // All fields should have been interpreted as unknown, so the debug strings // should be the same. @@ -456,7 +465,7 @@ // Group - GPBUnknownFieldSet* group = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *group = [[[GPBUnknownFieldSet alloc] init] autorelease]; GPBUnknownField* fieldGroup = [[[GPBUnknownField alloc] initWithNumber:100] autorelease]; [fieldGroup addVarint:100]; [group addField:fieldGroup]; diff --git a/libs/protobuf/objectivec/Tests/GPBUtilitiesTests.m b/libs/protobuf/objectivec/Tests/GPBUtilitiesTests.m index b4d52ad..f4a09de 100644 --- a/libs/protobuf/objectivec/Tests/GPBUtilitiesTests.m +++ b/libs/protobuf/objectivec/Tests/GPBUtilitiesTests.m @@ -41,9 +41,9 @@ #import "GPBMessage.h" #import "GPBUnknownField_PackagePrivate.h" -#import "objectivec/Tests/MapUnittest.pbobjc.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestObjc.pbobjc.h" +#import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestObjc.pbobjc.h" @interface UtilitiesTests : GPBTestCase @end @@ -62,7 +62,6 @@ - (void)testGPBDecodeTextFormatName { uint8_t decodeData[] = { - // clang-format off 0x6, // An inlined string (first to make sure the leading null is handled // correctly, and with a key of zero to check that). @@ -81,7 +80,6 @@ // underscore, lower + 30 (01 op), as is + 30 (00 op), as is + 13 (00 op), // underscore, as is + 3 (00 op) 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0, - // clang-format on }; NSString *inputStr = @"abcdefghIJ"; @@ -106,12 +104,10 @@ // An inlined string (and key of zero). XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 0, inputStr), @"zbcdefghIJ"); - // clang-format off // Long name so multiple decode ops are needed. inputStr = @"longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000"; XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 1000, inputStr), @"long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000"); - // clang-format on } - (void)testTextFormat { @@ -125,8 +121,10 @@ NSString *fileName = @"text_format_unittest_data.txt"; NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding]; - NSData *expectedData = [self getDataFileNamed:fileName dataToWrite:resultData]; - NSString *expected = [[NSString alloc] initWithData:expectedData encoding:NSUTF8StringEncoding]; + NSData *expectedData = + [self getDataFileNamed:fileName dataToWrite:resultData]; + NSString *expected = [[NSString alloc] initWithData:expectedData + encoding:NSUTF8StringEncoding]; XCTAssertEqualObjects(expected, result); [expected release]; } @@ -143,14 +141,12 @@ message.subEnum = self_autorelease_RetainCount; message.new_p.copy_p = @"foo"; - // clang-format off NSString *expected = @"_cmd: true\n" @"isProxy: true\n" @"SubEnum: retainCount\n" @"New {\n" @" copy: \"foo\"\n" @"}\n"; - // clang-format on NSString *result = GPBTextFormatForMessage(message, nil); XCTAssertEqualObjects(expected, result); } @@ -165,8 +161,10 @@ NSString *fileName = @"text_format_map_unittest_data.txt"; NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding]; - NSData *expectedData = [self getDataFileNamed:fileName dataToWrite:resultData]; - NSString *expected = [[NSString alloc] initWithData:expectedData encoding:NSUTF8StringEncoding]; + NSData *expectedData = + [self getDataFileNamed:fileName dataToWrite:resultData]; + NSString *expected = [[NSString alloc] initWithData:expectedData + encoding:NSUTF8StringEncoding]; XCTAssertEqualObjects(expected, result); [expected release]; } @@ -185,8 +183,10 @@ // of the bracketed extension name. NSString *fileName = @"text_format_extensions_unittest_data.txt"; NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding]; - NSData *expectedData = [self getDataFileNamed:fileName dataToWrite:resultData]; - NSString *expected = [[NSString alloc] initWithData:expectedData encoding:NSUTF8StringEncoding]; + NSData *expectedData = + [self getDataFileNamed:fileName dataToWrite:resultData]; + NSString *expected = [[NSString alloc] initWithData:expectedData + encoding:NSUTF8StringEncoding]; XCTAssertEqualObjects(expected, result); [expected release]; } @@ -195,7 +195,7 @@ TestAllTypes *message = [TestAllTypes message]; NSDictionary *repeatedFieldValues = @{ - @"repeatedStringArray" : [@[ @"foo", @"bar" ] mutableCopy], + @"repeatedStringArray" : [@[@"foo", @"bar"] mutableCopy], @"repeatedBoolArray" : [GPBBoolArray arrayWithValue:YES], @"repeatedInt32Array" : [GPBInt32Array arrayWithValue:14], @"repeatedInt64Array" : [GPBInt64Array arrayWithValue:15], @@ -208,19 +208,23 @@ rawValue:TestAllTypes_NestedEnum_Foo], }; for (NSString *fieldName in repeatedFieldValues) { - GPBFieldDescriptor *field = [message.descriptor fieldWithName:fieldName]; + GPBFieldDescriptor *field = + [message.descriptor fieldWithName:fieldName]; XCTAssertNotNil(field, @"No field with name: %@", fieldName); id expectedValues = repeatedFieldValues[fieldName]; GPBSetMessageRepeatedField(message, field, expectedValues); - XCTAssertEqualObjects(expectedValues, [message valueForKeyPath:fieldName]); + XCTAssertEqualObjects(expectedValues, + [message valueForKeyPath:fieldName]); } } // Helper to make an unknown field set with something in it. static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { - GPBUnknownFieldSet *result = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet *result = + [[[GPBUnknownFieldSet alloc] init] autorelease]; - GPBUnknownField *field = [[[GPBUnknownField alloc] initWithNumber:num] autorelease]; + GPBUnknownField *field = + [[[GPBUnknownField alloc] initWithNumber:num] autorelease]; [field addVarint:num]; [result addField:field]; @@ -242,26 +246,32 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message]; optionalGroup.a = 123; optionalGroup.unknownFields = UnknownFieldsSetHelper(779); - [message setExtension:[UnittestRoot optionalGroupExtension] value:optionalGroup]; + [message setExtension:[UnittestRoot optionalGroupExtension] + value:optionalGroup]; // Message - TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; + TestAllTypes_NestedMessage *nestedMessage = + [TestAllTypes_NestedMessage message]; nestedMessage.bb = 456; nestedMessage.unknownFields = UnknownFieldsSetHelper(778); - [message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; + [message setExtension:[UnittestRoot optionalNestedMessageExtension] + value:nestedMessage]; // Repeated Group - RepeatedGroup_extension *repeatedGroup = [[RepeatedGroup_extension alloc] init]; + RepeatedGroup_extension *repeatedGroup = + [[RepeatedGroup_extension alloc] init]; repeatedGroup.a = 567; repeatedGroup.unknownFields = UnknownFieldsSetHelper(780); - [message addExtension:[UnittestRoot repeatedGroupExtension] value:repeatedGroup]; + [message addExtension:[UnittestRoot repeatedGroupExtension] + value:repeatedGroup]; [repeatedGroup release]; // Repeated Message nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; nestedMessage.bb = 678; nestedMessage.unknownFields = UnknownFieldsSetHelper(781); - [message addExtension:[UnittestRoot repeatedNestedMessageExtension] value:nestedMessage]; + [message addExtension:[UnittestRoot repeatedNestedMessageExtension] + value:nestedMessage]; [nestedMessage release]; } @@ -301,8 +311,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { { XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]); - NSArray *repeatedNestedMessages = - [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; + NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1); TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject; XCTAssertNotNil(repeatedNestedMessage); @@ -349,14 +358,14 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { { XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]); - NSArray *repeatedNestedMessages = - [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; + NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1); TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject; XCTAssertNotNil(repeatedNestedMessage); XCTAssertEqual(repeatedNestedMessage.bb, 678); XCTAssertNil(repeatedNestedMessage.unknownFields); } + } - (void)testDropMessageUnknownFieldsRecursively_Maps { @@ -405,6 +414,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { XCTAssertNotNil(foreignMessage); XCTAssertNil(foreignMessage.unknownFields); } + } @end diff --git a/libs/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m b/libs/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m index e6ee20a..592d5af 100644 --- a/libs/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m +++ b/libs/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m @@ -33,7 +33,7 @@ #import #import "GPBTestUtilities.h" -#import "objectivec/Tests/AnyTest.pbobjc.h" +#import "google/protobuf/AnyTest.pbobjc.h" // Nanosecond time accuracy static const NSTimeInterval kTimeAccuracy = 1e-9; @@ -46,7 +46,8 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; - (void)testTimeStamp { // Test negative and positive values. NSTimeInterval values[] = { - -428027599.483999967, -1234567.0, -0.5, 0, 0.75, 54321.0, 2468086, 483999967}; + -428027599.483999967, -1234567.0, -0.5, 0, 0.75, 54321.0, 2468086,483999967 + }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { NSTimeInterval value = values[i]; @@ -54,24 +55,30 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; NSDate *date = [NSDate dateWithTimeIntervalSince1970:value]; GPBTimestamp *timeStamp = [[GPBTimestamp alloc] initWithDate:date]; - XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, @"Offset %f - Date: %@", (double)value, date); - XCTAssertLessThan(timeStamp.nanos, 1e9, @"Offset %f - Date: %@", (double)value, date); + XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, + @"Offset %f - Date: %@", (double)value, date); + XCTAssertLessThan(timeStamp.nanos, 1e9, + @"Offset %f - Date: %@", (double)value, date); // Comparing timeIntervals instead of directly comparing dates because date // equality requires the time intervals to be exactly the same, and the // timeintervals go through a bit of floating point error as they are // converted back and forth from the internal representation. - XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, kTimeAccuracy, + XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, + kTimeAccuracy, @"Offset %f - Date: %@", (double)value, date); [timeStamp release]; // Test Creation - timeIntervalSince1970. timeStamp = [[GPBTimestamp alloc] initWithTimeIntervalSince1970:value]; - XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, @"Offset %f - Date: %@", (double)value, date); - XCTAssertLessThan(timeStamp.nanos, 1e9, @"Offset %f - Date: %@", (double)value, date); + XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, + @"Offset %f - Date: %@", (double)value, date); + XCTAssertLessThan(timeStamp.nanos, 1e9, + @"Offset %f - Date: %@", (double)value, date); - XCTAssertEqualWithAccuracy(value, timeStamp.timeIntervalSince1970, kTimeAccuracy, + XCTAssertEqualWithAccuracy(value, timeStamp.timeIntervalSince1970, + kTimeAccuracy, @"Offset %f - Date: %@", (double)value, date); [timeStamp release]; @@ -79,10 +86,13 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; timeStamp = [[GPBTimestamp alloc] init]; timeStamp.date = date; - XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, @"Offset %f - Date: %@", (double)value, date); - XCTAssertLessThan(timeStamp.nanos, 1e9, @"Offset %f - Date: %@", (double)value, date); + XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, + @"Offset %f - Date: %@", (double)value, date); + XCTAssertLessThan(timeStamp.nanos, 1e9, + @"Offset %f - Date: %@", (double)value, date); - XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, kTimeAccuracy, + XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, + kTimeAccuracy, @"Offset %f - Date: %@", (double)value, date); [timeStamp release]; @@ -90,10 +100,13 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; timeStamp = [[GPBTimestamp alloc] init]; timeStamp.timeIntervalSince1970 = value; - XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, @"Offset %f - Date: %@", (double)value, date); - XCTAssertLessThan(timeStamp.nanos, 1e9, @"Offset %f - Date: %@", (double)value, date); + XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0, + @"Offset %f - Date: %@", (double)value, date); + XCTAssertLessThan(timeStamp.nanos, 1e9, + @"Offset %f - Date: %@", (double)value, date); - XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, kTimeAccuracy, + XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970, + kTimeAccuracy, @"Offset %f - Date: %@", (double)value, date); [timeStamp release]; @@ -102,45 +115,55 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; - (void)testDuration { // Test negative and positive values. - NSTimeInterval values[] = {-1000.0001, -500.0, -0.5, 0, 0.75, 1000.0, 2000.0002}; + NSTimeInterval values[] = { -1000.0001, -500.0, -0.5, 0, 0.75, 1000.0, 2000.0002 }; for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) { NSTimeInterval value = values[i]; // Test Creation. - GPBDuration *duration = [[GPBDuration alloc] initWithTimeInterval:value]; - XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy, @"For interval %f", - (double)value); + GPBDuration *duration = + [[GPBDuration alloc] initWithTimeInterval:value]; + XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy, + @"For interval %f", (double)value); if (value > 0) { - XCTAssertGreaterThanOrEqual(duration.seconds, 0, @"For interval %f", (double)value); - XCTAssertGreaterThanOrEqual(duration.nanos, 0, @"For interval %f", (double)value); + XCTAssertGreaterThanOrEqual(duration.seconds, 0, + @"For interval %f", (double)value); + XCTAssertGreaterThanOrEqual(duration.nanos, 0, + @"For interval %f", (double)value); } else { - XCTAssertLessThanOrEqual(duration.seconds, 0, @"For interval %f", (double)value); - XCTAssertLessThanOrEqual(duration.nanos, 0, @"For interval %f", (double)value); + XCTAssertLessThanOrEqual(duration.seconds, 0, + @"For interval %f", (double)value); + XCTAssertLessThanOrEqual(duration.nanos, 0, + @"For interval %f", (double)value); } [duration release]; // Test Mutation. duration = [[GPBDuration alloc] init]; duration.timeInterval = value; - XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy, @"For interval %f", - (double)value); + XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy, + @"For interval %f", (double)value); if (value > 0) { - XCTAssertGreaterThanOrEqual(duration.seconds, 0, @"For interval %f", (double)value); - XCTAssertGreaterThanOrEqual(duration.nanos, 0, @"For interval %f", (double)value); + XCTAssertGreaterThanOrEqual(duration.seconds, 0, + @"For interval %f", (double)value); + XCTAssertGreaterThanOrEqual(duration.nanos, 0, + @"For interval %f", (double)value); } else { - XCTAssertLessThanOrEqual(duration.seconds, 0, @"For interval %f", (double)value); - XCTAssertLessThanOrEqual(duration.nanos, 0, @"For interval %f", (double)value); + XCTAssertLessThanOrEqual(duration.seconds, 0, + @"For interval %f", (double)value); + XCTAssertLessThanOrEqual(duration.nanos, 0, + @"For interval %f", (double)value); } [duration release]; } } - (void)testAnyHelpers { + // Set and extract covers most of the code. - AnyTestMessage *subMessage = [AnyTestMessage message]; + TestAny *subMessage = [TestAny message]; subMessage.int32Value = 12345; - AnyTestMessage *message = [AnyTestMessage message]; + TestAny *message = [TestAny message]; NSError *err = nil; message.anyValue = [GPBAny anyWithMessage:subMessage error:&err]; XCTAssertNil(err); @@ -148,13 +171,14 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; NSData *data = message.data; XCTAssertNotNil(data); - AnyTestMessage *message2 = [AnyTestMessage parseFromData:data error:&err]; + TestAny *message2 = [TestAny parseFromData:data error:&err]; XCTAssertNil(err); XCTAssertNotNil(message2); XCTAssertTrue(message2.hasAnyValue); - AnyTestMessage *subMessage2 = - (AnyTestMessage *)[message.anyValue unpackMessageClass:[AnyTestMessage class] error:&err]; + TestAny *subMessage2 = + (TestAny *)[message.anyValue unpackMessageClass:[TestAny class] + error:&err]; XCTAssertNil(err); XCTAssertNotNil(subMessage2); XCTAssertEqual(subMessage2.int32Value, 12345); @@ -165,22 +189,25 @@ static const NSTimeInterval kTimeAccuracy = 1e-9; NSData *data2 = message.data; XCTAssertEqualObjects(data2, data); - AnyTestMessage *subMessage3 = - (AnyTestMessage *)[message.anyValue unpackMessageClass:[AnyTestMessage class] error:NULL]; + TestAny *subMessage3 = + (TestAny *)[message.anyValue unpackMessageClass:[TestAny class] + error:NULL]; XCTAssertNotNil(subMessage3); XCTAssertEqualObjects(subMessage2, subMessage3); // Try to extract wrong type. GPBTimestamp *wrongMessage = - (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class] error:&err]; + (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class] + error:&err]; XCTAssertNotNil(err); XCTAssertNil(wrongMessage); XCTAssertEqualObjects(err.domain, GPBWellKnownTypesErrorDomain); XCTAssertEqual(err.code, GPBWellKnownTypesErrorCodeTypeURLMismatch); - wrongMessage = (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class] - error:NULL]; + wrongMessage = + (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class] + error:NULL]; XCTAssertNil(wrongMessage); } diff --git a/libs/protobuf/objectivec/Tests/GPBWireFormatTests.m b/libs/protobuf/objectivec/Tests/GPBWireFormatTests.m index 64456bc..dbeab21 100644 --- a/libs/protobuf/objectivec/Tests/GPBWireFormatTests.m +++ b/libs/protobuf/objectivec/Tests/GPBWireFormatTests.m @@ -33,8 +33,9 @@ #import "GPBCodedInputStream.h" #import "GPBMessage_PackagePrivate.h" #import "GPBUnknownField_PackagePrivate.h" -#import "objectivec/Tests/Unittest.pbobjc.h" -#import "objectivec/Tests/UnittestMset.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestMset.pbobjc.h" +#import "google/protobuf/UnittestMsetWireFormat.pbobjc.h" @interface WireFormatTests : GPBTestCase @end @@ -54,13 +55,15 @@ } - (void)testSerializationPacked { - TestPackedTypes* message = [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; + TestPackedTypes* message = + [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; NSData* rawBytes = message.data; [self assertFieldsInOrder:rawBytes]; XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); - TestPackedTypes* message2 = [TestPackedTypes parseFromData:rawBytes error:NULL]; + TestPackedTypes* message2 = + [TestPackedTypes parseFromData:rawBytes error:NULL]; [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; } @@ -70,7 +73,8 @@ // so if we serealize a TestAllExtensions then parse it as TestAllTypes // it should work. - TestAllExtensions* message = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; + TestAllExtensions* message = + [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; NSData* rawBytes = message.data; [self assertFieldsInOrder:rawBytes]; XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length); @@ -83,11 +87,13 @@ - (void)testSerializePackedExtensions { // TestPackedTypes and TestPackedExtensions should have compatible wire // formats; check that they serialize to the same string. - TestPackedExtensions* message = [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; + TestPackedExtensions* message = + [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; NSData* rawBytes = message.data; [self assertFieldsInOrder:rawBytes]; - TestPackedTypes* message2 = [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; + TestPackedTypes* message2 = + [self packedSetRepeatedCount:kGPBDefaultRepeatCount]; NSData* rawBytes2 = message2.data; XCTAssertEqualObjects(rawBytes, rawBytes2); @@ -111,6 +117,7 @@ [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; } + - (void)testExtensionsSerializedSize { size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize; size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize; @@ -119,7 +126,8 @@ - (void)testParsePackedExtensions { // Ensure that packed extensions can be properly parsed. - TestPackedExtensions* message = [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; + TestPackedExtensions* message = + [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount]; NSData* rawBytes = message.data; [self assertFieldsInOrder:rawBytes]; @@ -129,74 +137,79 @@ extensionRegistry:registry error:NULL]; - [self assertPackedExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount]; + [self assertPackedExtensionsSet:message2 + repeatedCount:kGPBDefaultRepeatCount]; } const int kUnknownTypeId = 1550055; - (void)testSerializeMessageSet { - // Set up a MSetMessage with two known messages and an unknown one. - MSetMessage* message_set = [MSetMessage message]; - [[message_set getExtension:[MSetMessageExtension1 messageSetExtension]] setI:123]; - [[message_set getExtension:[MSetMessageExtension2 messageSetExtension]] setStr:@"foo"]; + // Set up a TestMessageSet with two known messages and an unknown one. + TestMessageSet* message_set = [TestMessageSet message]; + [[message_set getExtension:[TestMessageSetExtension1 messageSetExtension]] + setI:123]; + [[message_set getExtension:[TestMessageSetExtension2 messageSetExtension]] + setStr:@"foo"]; GPBUnknownField* unknownField = [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease]; [unknownField addLengthDelimited:[NSData dataWithBytes:"bar" length:3]]; - GPBUnknownFieldSet* unknownFieldSet = [[[GPBUnknownFieldSet alloc] init] autorelease]; + GPBUnknownFieldSet* unknownFieldSet = + [[[GPBUnknownFieldSet alloc] init] autorelease]; [unknownFieldSet addField:unknownField]; [message_set setUnknownFields:unknownFieldSet]; NSData* data = [message_set data]; - // Parse back using MSetRawMessageSet and check the contents. - MSetRawMessageSet* raw = [MSetRawMessageSet parseFromData:data error:NULL]; + // Parse back using RawMessageSet and check the contents. + RawMessageSet* raw = [RawMessageSet parseFromData:data error:NULL]; XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0); XCTAssertEqual(raw.itemArray.count, (NSUInteger)3); XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId], - [MSetMessageExtension1 messageSetExtension].fieldNumber); + [TestMessageSetExtension1 messageSetExtension].fieldNumber); XCTAssertEqual((uint32_t)[raw.itemArray[1] typeId], - [MSetMessageExtension2 messageSetExtension].fieldNumber); + [TestMessageSetExtension2 messageSetExtension].fieldNumber); XCTAssertEqual([raw.itemArray[2] typeId], kUnknownTypeId); - MSetMessageExtension1* message1 = - [MSetMessageExtension1 parseFromData:[((MSetRawMessageSet_Item*)raw.itemArray[0]) message] - error:NULL]; + TestMessageSetExtension1* message1 = + [TestMessageSetExtension1 parseFromData:[((RawMessageSet_Item*)raw.itemArray[0]) message] + error:NULL]; XCTAssertEqual(message1.i, 123); - MSetMessageExtension2* message2 = - [MSetMessageExtension2 parseFromData:[((MSetRawMessageSet_Item*)raw.itemArray[1]) message] - error:NULL]; + TestMessageSetExtension2* message2 = + [TestMessageSetExtension2 parseFromData:[((RawMessageSet_Item*)raw.itemArray[1]) message] + error:NULL]; XCTAssertEqualObjects(message2.str, @"foo"); - XCTAssertEqualObjects([raw.itemArray[2] message], [NSData dataWithBytes:"bar" length:3]); + XCTAssertEqualObjects([raw.itemArray[2] message], + [NSData dataWithBytes:"bar" length:3]); } - (void)testParseMessageSet { - // Set up a MSetRawMessageSet with two known messages and an unknown one. - MSetRawMessageSet* raw = [MSetRawMessageSet message]; + // Set up a RawMessageSet with two known messages and an unknown one. + RawMessageSet* raw = [RawMessageSet message]; { - MSetRawMessageSet_Item* item = [MSetRawMessageSet_Item message]; - item.typeId = [MSetMessageExtension1 messageSetExtension].fieldNumber; - MSetMessageExtension1* message = [MSetMessageExtension1 message]; + RawMessageSet_Item* item = [RawMessageSet_Item message]; + item.typeId = [TestMessageSetExtension1 messageSetExtension].fieldNumber; + TestMessageSetExtension1* message = [TestMessageSetExtension1 message]; message.i = 123; item.message = [message data]; [raw.itemArray addObject:item]; } { - MSetRawMessageSet_Item* item = [MSetRawMessageSet_Item message]; - item.typeId = [MSetMessageExtension2 messageSetExtension].fieldNumber; - MSetMessageExtension2* message = [MSetMessageExtension2 message]; + RawMessageSet_Item* item = [RawMessageSet_Item message]; + item.typeId = [TestMessageSetExtension2 messageSetExtension].fieldNumber; + TestMessageSetExtension2* message = [TestMessageSetExtension2 message]; message.str = @"foo"; item.message = [message data]; [raw.itemArray addObject:item]; } { - MSetRawMessageSet_Item* item = [MSetRawMessageSet_Item message]; + RawMessageSet_Item* item = [RawMessageSet_Item message]; item.typeId = kUnknownTypeId; item.message = [NSData dataWithBytes:"bar" length:3]; [raw.itemArray addObject:item]; @@ -204,20 +217,27 @@ const int kUnknownTypeId = 1550055; NSData* data = [raw data]; - // Parse as a MSetMessage and check the contents. - MSetMessage* messageSet = [MSetMessage parseFromData:data - extensionRegistry:[MSetUnittestMsetRoot extensionRegistry] - error:NULL]; + // Parse as a TestMessageSet and check the contents. + TestMessageSet* messageSet = + [TestMessageSet parseFromData:data + extensionRegistry:[UnittestMsetRoot extensionRegistry] + error:NULL]; - XCTAssertEqual([[messageSet getExtension:[MSetMessageExtension1 messageSetExtension]] i], 123); - XCTAssertEqualObjects([[messageSet getExtension:[MSetMessageExtension2 messageSetExtension]] str], - @"foo"); + XCTAssertEqual( + [[messageSet + getExtension:[TestMessageSetExtension1 messageSetExtension]] i], + 123); + XCTAssertEqualObjects( + [[messageSet + getExtension:[TestMessageSetExtension2 messageSetExtension]] str], + @"foo"); XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1); GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId]; XCTAssertNotNil(unknownField); XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1); - XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], [NSData dataWithBytes:"bar" length:3]); + XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], + [NSData dataWithBytes:"bar" length:3]); } - (void)assertFieldsInOrder:(NSData*)data { diff --git a/libs/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h b/libs/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h index 6d3d9ec..46292fc 100644 --- a/libs/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h +++ b/libs/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h @@ -1,7 +1,6 @@ // -// Use this file to import your target's public headers that you would like to -// expose to Swift. +// Use this file to import your target's public headers that you would like to expose to Swift. // -#import "objectivec/Tests/UnittestRuntimeProto2.pbobjc.h" -#import "objectivec/Tests/UnittestRuntimeProto3.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" +#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" diff --git a/libs/protobuf/objectivec/Tests/expected_prefixes.txt b/libs/protobuf/objectivec/Tests/expected_prefixes.txt deleted file mode 100644 index 1665ab1..0000000 --- a/libs/protobuf/objectivec/Tests/expected_prefixes.txt +++ /dev/null @@ -1,12 +0,0 @@ -objc.protobuf.tests = "" # Explicit empty prefix -objc.protobuf.tests.any = Any -objc.protobuf.tests.chain = Chain -objc.protobuf.tests.cycle = Cycle -objc.protobuf.tests.deprecated = Dep -objc.protobuf.tests.deprecated_file = FileDep -objc.protobuf.tests.import = Import -objc.protobuf.tests.mset = MSet -objc.protobuf.tests.options = GPBTEST -objc.protobuf.tests.proto3_preserve_unknown_enum = UnknownEnums -objc.protobuf.tests.public_import = PublicImport -objc.protobuf.tests.startup = TestObjCStartup diff --git a/libs/protobuf/objectivec/Tests/map_unittest.proto b/libs/protobuf/objectivec/Tests/map_unittest.proto deleted file mode 100644 index ba41439..0000000 --- a/libs/protobuf/objectivec/Tests/map_unittest.proto +++ /dev/null @@ -1,123 +0,0 @@ -// 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. - -syntax = "proto3"; - -import "objectivec/Tests/unittest.proto"; - -package objc.protobuf.tests; - -// Explicit empty prefix, tests some validations code paths also. -option objc_class_prefix = ""; - -// Tests maps. -message TestMap { - map map_int32_int32 = 1; - map map_int64_int64 = 2; - map map_uint32_uint32 = 3; - map map_uint64_uint64 = 4; - map map_sint32_sint32 = 5; - map map_sint64_sint64 = 6; - map map_fixed32_fixed32 = 7; - map map_fixed64_fixed64 = 8; - map map_sfixed32_sfixed32 = 9; - map map_sfixed64_sfixed64 = 10; - map map_int32_float = 11; - map map_int32_double = 12; - map map_bool_bool = 13; - map map_string_string = 14; - map map_int32_bytes = 15; - map map_int32_enum = 16; - map map_int32_foreign_message = 17; - map map_string_foreign_message = 18; - map map_int32_all_types = 19; -} - -message TestMapSubmessage { - TestMap test_map = 1; -} - -message TestMessageMap { - map map_int32_message = 1; -} - -// Two map fields share the same entry default instance. -message TestSameTypeMap { - map map1 = 1; - map map2 = 2; -} - - -enum MapEnum { - MAP_ENUM_FOO = 0; - MAP_ENUM_BAR = 1; - MAP_ENUM_BAZ = 2; -} - -// Test embedded message with required fields -message TestRequiredMessageMap { - map map_field = 1; -} - -message TestArenaMap { - map map_int32_int32 = 1; - map map_int64_int64 = 2; - map map_uint32_uint32 = 3; - map map_uint64_uint64 = 4; - map map_sint32_sint32 = 5; - map map_sint64_sint64 = 6; - map map_fixed32_fixed32 = 7; - map map_fixed64_fixed64 = 8; - map map_sfixed32_sfixed32 = 9; - map map_sfixed64_sfixed64 = 10; - map map_int32_float = 11; - map map_int32_double = 12; - map map_bool_bool = 13; - map map_string_string = 14; - map map_int32_bytes = 15; - map map_int32_enum = 16; - map map_int32_foreign_message = 17; -} - -// Previously, message containing enum called Type cannot be used as value of -// map field. -message MessageContainingEnumCalledType { - enum Type { TYPE_FOO = 0; } - map type = 1; -} - -// Previously, message cannot contain map field called "entry". -message MessageContainingMapCalledEntry { - map entry = 1; -} - -message TestRecursiveMapMessage { - map a = 1; -} diff --git a/libs/protobuf/objectivec/Tests/unittest.proto b/libs/protobuf/objectivec/Tests/unittest.proto deleted file mode 100644 index 31353b4..0000000 --- a/libs/protobuf/objectivec/Tests/unittest.proto +++ /dev/null @@ -1,1536 +0,0 @@ -// 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. - -// LINT: ALLOW_GROUPS, LEGACY_NAMES - -syntax = "proto2"; - -import "objectivec/Tests/unittest_import.proto"; - -// Explicit empty prefix, tests some validations code paths also. -option objc_class_prefix = ""; - -package objc.protobuf.tests; - -// This proto includes every type of field in both singular and repeated -// forms. -message TestAllTypes { - message NestedMessage { - // 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. - optional int32 bb = 1; - } - - enum NestedEnum { - FOO = 1; - BAR = 2; - BAZ = 3; - NEG = -1; // Intentionally negative. - } - - // Singular - optional int32 optional_int32 = 1; - optional int64 optional_int64 = 2; - optional uint32 optional_uint32 = 3; - optional uint64 optional_uint64 = 4; - optional sint32 optional_sint32 = 5; - optional sint64 optional_sint64 = 6; - optional fixed32 optional_fixed32 = 7; - optional fixed64 optional_fixed64 = 8; - optional sfixed32 optional_sfixed32 = 9; - optional sfixed64 optional_sfixed64 = 10; - optional float optional_float = 11; - optional double optional_double = 12; - optional bool optional_bool = 13; - optional string optional_string = 14; - optional bytes optional_bytes = 15; - - optional group OptionalGroup = 16 { - optional int32 a = 17; - } - - optional NestedMessage optional_nested_message = 18; - optional ForeignMessage optional_foreign_message = 19; - optional objc.protobuf.tests.import.Message optional_import_message = 20; - - optional NestedEnum optional_nested_enum = 21; - optional ForeignEnum optional_foreign_enum = 22; - optional objc.protobuf.tests.import.Enum optional_import_enum = 23; - - optional string optional_string_piece = 24 [ctype=STRING_PIECE]; - optional string optional_cord = 25 [ctype=CORD]; - - // Defined in unittest_import_public.proto - optional objc.protobuf.tests.public_import.Message - optional_public_import_message = 26; - - optional NestedMessage optional_lazy_message = 27 [lazy=true]; - optional NestedMessage optional_unverified_lazy_message = 28 [unverified_lazy=true]; - - // Repeated - repeated int32 repeated_int32 = 31; - repeated int64 repeated_int64 = 32; - repeated uint32 repeated_uint32 = 33; - repeated uint64 repeated_uint64 = 34; - repeated sint32 repeated_sint32 = 35; - repeated sint64 repeated_sint64 = 36; - repeated fixed32 repeated_fixed32 = 37; - repeated fixed64 repeated_fixed64 = 38; - repeated sfixed32 repeated_sfixed32 = 39; - repeated sfixed64 repeated_sfixed64 = 40; - repeated float repeated_float = 41; - repeated double repeated_double = 42; - repeated bool repeated_bool = 43; - repeated string repeated_string = 44; - repeated bytes repeated_bytes = 45; - - repeated group RepeatedGroup = 46 { - optional int32 a = 47; - } - - repeated NestedMessage repeated_nested_message = 48; - repeated ForeignMessage repeated_foreign_message = 49; - repeated objc.protobuf.tests.import.Message repeated_import_message = 50; - - repeated NestedEnum repeated_nested_enum = 51; - repeated ForeignEnum repeated_foreign_enum = 52; - repeated objc.protobuf.tests.import.Enum 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]; - - // Singular with defaults - optional int32 default_int32 = 61 [default = 41 ]; - optional int64 default_int64 = 62 [default = 42 ]; - optional uint32 default_uint32 = 63 [default = 43 ]; - optional uint64 default_uint64 = 64 [default = 44 ]; - optional sint32 default_sint32 = 65 [default = -45 ]; - optional sint64 default_sint64 = 66 [default = 46 ]; - optional fixed32 default_fixed32 = 67 [default = 47 ]; - optional fixed64 default_fixed64 = 68 [default = 48 ]; - optional sfixed32 default_sfixed32 = 69 [default = 49 ]; - optional sfixed64 default_sfixed64 = 70 [default = -50 ]; - optional float default_float = 71 [default = 51.5 ]; - optional double default_double = 72 [default = 52e3 ]; - optional bool default_bool = 73 [default = true ]; - optional string default_string = 74 [default = "hello"]; - optional bytes default_bytes = 75 [default = "world"]; - - optional NestedEnum default_nested_enum = 81 [default = BAR ]; - optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; - optional objc.protobuf.tests.import.Enum - default_import_enum = 83 [default = IMPORT_BAR]; - - optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; - optional string default_cord = 85 [ctype=CORD,default="123"]; - - // For oneof test - oneof oneof_field { - uint32 oneof_uint32 = 111; - NestedMessage oneof_nested_message = 112; - string oneof_string = 113; - bytes oneof_bytes = 114; - } -} - -// This proto includes a recursively nested message. -message NestedTestAllTypes { - optional NestedTestAllTypes child = 1; - optional TestAllTypes payload = 2; - repeated NestedTestAllTypes repeated_child = 3; - optional NestedTestAllTypes lazy_child = 4 [lazy=true]; - optional TestAllTypes eager_child = 5 [lazy=false]; -} - -message TestDeprecatedFields { - optional int32 deprecated_int32 = 1 [deprecated=true]; - oneof oneof_fields { - int32 deprecated_int32_in_oneof = 2 [deprecated=true]; - } -} - -message TestDeprecatedMessage { - option deprecated = true; -} - -// Define these after TestAllTypes to make sure the compiler can handle -// that. -message ForeignMessage { - optional int32 c = 1; - optional int32 d = 2; -} - -enum ForeignEnum { - FOREIGN_FOO = 4; - FOREIGN_BAR = 5; - FOREIGN_BAZ = 6; -} - -message TestReservedFields { - reserved 2, 15, 9 to 11; - reserved "bar", "baz"; -} - -enum TestReservedEnumFields { - UNKNOWN = 0; - reserved 2, 15, 9 to 11; - reserved "bar", "baz"; -} - -message TestAllExtensions { - extensions 1 to max; -} - -extend TestAllExtensions { - // Singular - optional int32 optional_int32_extension = 1; - optional int64 optional_int64_extension = 2; - optional uint32 optional_uint32_extension = 3; - optional uint64 optional_uint64_extension = 4; - optional sint32 optional_sint32_extension = 5; - optional sint64 optional_sint64_extension = 6; - optional fixed32 optional_fixed32_extension = 7; - optional fixed64 optional_fixed64_extension = 8; - optional sfixed32 optional_sfixed32_extension = 9; - optional sfixed64 optional_sfixed64_extension = 10; - optional float optional_float_extension = 11; - optional double optional_double_extension = 12; - optional bool optional_bool_extension = 13; - optional string optional_string_extension = 14; - optional bytes optional_bytes_extension = 15; - - optional group OptionalGroup_extension = 16 { - optional int32 a = 17; - } - - optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; - optional ForeignMessage optional_foreign_message_extension = 19; - optional objc.protobuf.tests.import.Message - optional_import_message_extension = 20; - - optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; - optional ForeignEnum optional_foreign_enum_extension = 22; - optional objc.protobuf.tests.import.Enum - optional_import_enum_extension = 23; - - optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; - optional string optional_cord_extension = 25 [ctype=CORD]; - - optional objc.protobuf.tests.public_import.Message - optional_public_import_message_extension = 26; - - optional TestAllTypes.NestedMessage - optional_lazy_message_extension = 27 [lazy=true]; - optional TestAllTypes.NestedMessage - optional_unverified_lazy_message_extension = 28 [unverified_lazy=true]; - - // Repeated - repeated int32 repeated_int32_extension = 31; - repeated int64 repeated_int64_extension = 32; - repeated uint32 repeated_uint32_extension = 33; - repeated uint64 repeated_uint64_extension = 34; - repeated sint32 repeated_sint32_extension = 35; - repeated sint64 repeated_sint64_extension = 36; - repeated fixed32 repeated_fixed32_extension = 37; - repeated fixed64 repeated_fixed64_extension = 38; - repeated sfixed32 repeated_sfixed32_extension = 39; - repeated sfixed64 repeated_sfixed64_extension = 40; - repeated float repeated_float_extension = 41; - repeated double repeated_double_extension = 42; - repeated bool repeated_bool_extension = 43; - repeated string repeated_string_extension = 44; - repeated bytes repeated_bytes_extension = 45; - - repeated group RepeatedGroup_extension = 46 { - optional int32 a = 47; - } - - repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; - repeated ForeignMessage repeated_foreign_message_extension = 49; - repeated objc.protobuf.tests.import.Message - repeated_import_message_extension = 50; - - repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; - repeated ForeignEnum repeated_foreign_enum_extension = 52; - repeated objc.protobuf.tests.import.Enum - repeated_import_enum_extension = 53; - - repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; - repeated string repeated_cord_extension = 55 [ctype=CORD]; - - repeated TestAllTypes.NestedMessage - repeated_lazy_message_extension = 57 [lazy=true]; - - // Singular with defaults - optional int32 default_int32_extension = 61 [default = 41 ]; - optional int64 default_int64_extension = 62 [default = 42 ]; - optional uint32 default_uint32_extension = 63 [default = 43 ]; - optional uint64 default_uint64_extension = 64 [default = 44 ]; - optional sint32 default_sint32_extension = 65 [default = -45 ]; - optional sint64 default_sint64_extension = 66 [default = 46 ]; - optional fixed32 default_fixed32_extension = 67 [default = 47 ]; - optional fixed64 default_fixed64_extension = 68 [default = 48 ]; - optional sfixed32 default_sfixed32_extension = 69 [default = 49 ]; - optional sfixed64 default_sfixed64_extension = 70 [default = -50 ]; - optional float default_float_extension = 71 [default = 51.5 ]; - optional double default_double_extension = 72 [default = 52e3 ]; - optional bool default_bool_extension = 73 [default = true ]; - optional string default_string_extension = 74 [default = "hello"]; - optional bytes default_bytes_extension = 75 [default = "world"]; - - optional TestAllTypes.NestedEnum - default_nested_enum_extension = 81 [default = BAR]; - optional ForeignEnum - default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; - optional objc.protobuf.tests.import.Enum - default_import_enum_extension = 83 [default = IMPORT_BAR]; - - optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, - default="abc"]; - optional string default_cord_extension = 85 [ctype=CORD, default="123"]; - - // For oneof test - optional uint32 oneof_uint32_extension = 111; - optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112; - optional string oneof_string_extension = 113; - optional bytes oneof_bytes_extension = 114; -} - -message TestMixedFieldsAndExtensions { - optional int32 a = 1; - repeated fixed32 b = 3; - extensions 2, 4; - extend TestMixedFieldsAndExtensions { - optional int32 c = 2; - repeated fixed32 d = 4; - } -} - -message TestGroup { - optional group OptionalGroup = 16 { - optional int32 a = 17; - } - optional ForeignEnum optional_foreign_enum = 22; -} - -message TestGroupExtension { - extensions 1 to max; -} - -message TestNestedExtension { - extend TestAllExtensions { - // Check for bug where string extensions declared in tested scope did not - // compile. - optional string test = 1002 [default="test"]; - // Used to test if generated extension name is correct when there are - // underscores. - optional string nested_string_extension = 1003; - } - - extend TestGroupExtension { - optional group OptionalGroup_extension = 16 { - optional int32 a = 17; - } - optional ForeignEnum optional_foreign_enum_extension = 22; - } -} - -message TestChildExtension { - optional string a = 1; - optional string b = 2; - optional TestAllExtensions optional_extension = 3; -} - -// Emulates wireformat data of TestChildExtension with dynamic extension -// (DynamicExtension). -message TestChildExtensionData { - message NestedTestAllExtensionsData { - message NestedDynamicExtensions { - optional int32 a = 1; - optional int32 b = 2; - } - optional NestedDynamicExtensions dynamic = 409707008; - } - optional string a = 1; - optional string b = 2; - optional NestedTestAllExtensionsData optional_extension = 3; -} - -message TestNestedChildExtension { - optional int32 a = 1; - optional TestChildExtension child = 2; -} - -// Emulates wireformat data of TestNestedChildExtension with dynamic extension -// (DynamicExtension). -message TestNestedChildExtensionData { - optional int32 a = 1; - optional TestChildExtensionData child = 2; -} - -// We have separate messages for testing required fields because it's -// annoying to have to fill in required fields in TestProto in order to -// do anything with it. Note that we don't need to test every type of -// required filed because the code output is basically identical to -// optional fields for all types. -message TestRequired { - required int32 a = 1; - optional int32 dummy2 = 2; - required int32 b = 3; - - extend TestAllExtensions { - optional TestRequired single = 1000; - repeated TestRequired multi = 1001; - } - - // Pad the field count to 32 so that we can test that IsInitialized() - // properly checks multiple elements of has_bits_. - optional int32 dummy4 = 4; - optional int32 dummy5 = 5; - optional int32 dummy6 = 6; - optional int32 dummy7 = 7; - optional int32 dummy8 = 8; - optional int32 dummy9 = 9; - optional int32 dummy10 = 10; - optional int32 dummy11 = 11; - optional int32 dummy12 = 12; - optional int32 dummy13 = 13; - optional int32 dummy14 = 14; - optional int32 dummy15 = 15; - optional int32 dummy16 = 16; - optional int32 dummy17 = 17; - optional int32 dummy18 = 18; - optional int32 dummy19 = 19; - optional int32 dummy20 = 20; - optional int32 dummy21 = 21; - optional int32 dummy22 = 22; - optional int32 dummy23 = 23; - optional int32 dummy24 = 24; - optional int32 dummy25 = 25; - optional int32 dummy26 = 26; - optional int32 dummy27 = 27; - optional int32 dummy28 = 28; - optional int32 dummy29 = 29; - optional int32 dummy30 = 30; - optional int32 dummy31 = 31; - optional int32 dummy32 = 32; - - required int32 c = 33; - - // Add an optional child message to make this non-trivial for go/pdlazy. - optional ForeignMessage optional_foreign = 34; -} - -message TestRequiredForeign { - optional TestRequired optional_message = 1; - repeated TestRequired repeated_message = 2; - optional int32 dummy = 3; - - // Missing required fields must not affect verification of child messages. - optional NestedTestAllTypes optional_lazy_message = 4 [lazy = true]; -} - -message TestRequiredMessage { - optional TestRequired optional_message = 1; - repeated TestRequired repeated_message = 2; - required TestRequired required_message = 3; -} - -message TestNestedRequiredForeign { - optional TestNestedRequiredForeign child = 1; - optional TestRequiredForeign payload = 2; - optional int32 dummy = 3; -} - -// Test that we can use NestedMessage from outside TestAllTypes. -message TestForeignNested { - optional TestAllTypes.NestedMessage foreign_nested = 1; -} - -// TestEmptyMessage is used to test unknown field support. -message TestEmptyMessage { -} - -// Like above, but declare all field numbers as potential extensions. No -// actual extensions should ever be defined for this type. -message TestEmptyMessageWithExtensions { - extensions 1 to max; -} - -// Needed for a Python test. -message TestPickleNestedMessage { - message NestedMessage { - optional int32 bb = 1; - message NestedNestedMessage { - optional int32 cc = 1; - } - } -} - -message TestMultipleExtensionRanges { - extensions 42; - extensions 4143 to 4243; - extensions 65536 to max; -} - -// 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. - optional int32 a = 1; - optional int32 bb = 268435455; -} - -message TestRecursiveMessage { - optional TestRecursiveMessage a = 1; - optional int32 i = 2; -} - -// Test that mutual recursion works. -message TestMutualRecursionA { - message SubMessage { - optional TestMutualRecursionB b = 1; - } - optional TestMutualRecursionB bb = 1; - optional group SubGroup = 2 { - optional SubMessage sub_message = 3; // Needed because of bug in javatest - optional TestAllTypes not_in_this_scc = 4; - } -} - -message TestMutualRecursionB { - optional TestMutualRecursionA a = 1; - optional int32 optional_int32 = 2; -} - -message TestIsInitialized { - message SubMessage { - optional group SubGroup = 1 { - required int32 i = 2; - } - } - optional SubMessage sub_message = 1; -} - -// Test that groups have disjoint field numbers from their siblings and -// parents. This is NOT possible in proto1; only google.protobuf. When attempting -// to compile with proto1, this will emit an error; so we only include it -// in objc.protobuf.tests_proto. -message TestDupFieldNumber { // NO_PROTO1 - optional int32 a = 1; // NO_PROTO1 - optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 - optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 -} // NO_PROTO1 - -// Additional messages for testing lazy fields. -message TestEagerMessage { - optional TestAllTypes sub_message = 1 [lazy=false]; -} -message TestLazyMessage { - optional TestAllTypes sub_message = 1 [lazy=true]; -} -message TestEagerMaybeLazy { - message NestedMessage { - optional TestPackedTypes packed = 1; - } - optional TestAllTypes message_foo = 1; - optional TestAllTypes message_bar = 2; - optional NestedMessage message_baz = 3; -} -// Needed for a Python test. -message TestNestedMessageHasBits { - message NestedMessage { - repeated int32 nestedmessage_repeated_int32 = 1; - repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2; - } - optional NestedMessage optional_nested_message = 1; -} - - -// Test an enum that has multiple values with the same number. -enum TestEnumWithDupValue { - option allow_alias = true; - - FOO1 = 1; - BAR1 = 2; - BAZ = 3; - FOO2 = 1; - BAR2 = 2; -} - -// Test an enum with large, unordered values. -enum TestSparseEnum { - SPARSE_A = 123; - SPARSE_B = 62374; - SPARSE_C = 12589234; - SPARSE_D = -15; - SPARSE_E = -53452; - SPARSE_F = 0; - SPARSE_G = 2; -} - -// Test message with CamelCase field names. This violates Protocol Buffer -// standard style. -message TestCamelCaseFieldNames { - optional int32 PrimitiveField = 1; - optional string StringField = 2; - optional ForeignEnum EnumField = 3; - optional ForeignMessage MessageField = 4; - optional string StringPieceField = 5 [ctype=STRING_PIECE]; - optional string CordField = 6 [ctype=CORD]; - - repeated int32 RepeatedPrimitiveField = 7; - repeated string RepeatedStringField = 8; - repeated ForeignEnum RepeatedEnumField = 9; - repeated ForeignMessage RepeatedMessageField = 10; - repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE]; - repeated string RepeatedCordField = 12 [ctype=CORD]; -} - - -// We list fields out of order, to ensure that we're using field number and not -// field index to determine serialization order. -message TestFieldOrderings { - optional string my_string = 11; - extensions 2 to 10; - optional int64 my_int = 1; - extensions 12 to 100; - optional float my_float = 101; - message NestedMessage { - optional 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. - optional int32 bb = 1; - } - - optional NestedMessage optional_nested_message = 200; -} - -extend TestFieldOrderings { - optional string my_extension_string = 50; - optional int32 my_extension_int = 5; -} - -message TestExtensionOrderings1 { - extend TestFieldOrderings { - optional TestExtensionOrderings1 test_ext_orderings1 = 13; - } - optional string my_string = 1; -} - -message TestExtensionOrderings2 { - extend TestFieldOrderings { - optional TestExtensionOrderings2 test_ext_orderings2 = 12; - } - message TestExtensionOrderings3 { - extend TestFieldOrderings { - optional TestExtensionOrderings3 test_ext_orderings3 = 14; - } - optional string my_string = 1; - } - optional string my_string = 1; -} - -message TestExtremeDefaultValues { - optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; - optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF]; - optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF]; - optional int32 small_int32 = 4 [default = -0x7FFFFFFF]; - optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF]; - optional int32 really_small_int32 = 21 [default = -0x80000000]; - optional int64 really_small_int64 = 22 [default = -0x8000000000000000]; - - // The default value here is UTF-8 for "\u1234". (We could also just type - // the UTF-8 text directly into this text file rather than escape it, but - // lots of people use editors that would be confused by this.) - optional string utf8_string = 6 [default = "\341\210\264"]; - - // Tests for single-precision floating-point values. - optional float zero_float = 7 [default = 0]; - optional float one_float = 8 [default = 1]; - optional float small_float = 9 [default = 1.5]; - optional float negative_one_float = 10 [default = -1]; - optional float negative_float = 11 [default = -1.5]; - // Using exponents - optional float large_float = 12 [default = 2E8]; - optional float small_negative_float = 13 [default = -8e-28]; - - // Text for nonfinite floating-point values. - optional double inf_double = 14 [default = inf]; - optional double neg_inf_double = 15 [default = -inf]; - optional double nan_double = 16 [default = nan]; - optional float inf_float = 17 [default = inf]; - optional float neg_inf_float = 18 [default = -inf]; - optional float nan_float = 19 [default = nan]; - - // Tests for C++ trigraphs. - // Trigraphs should be escaped in C++ generated files, but they should not be - // escaped for other languages. - // Note that in .proto file, "\?" is a valid way to escape ? in string - // literals. - optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"]; - - // String defaults containing the character '\000' - optional string string_with_zero = 23 [default = "hel\000lo"]; - optional bytes bytes_with_zero = 24 [default = "wor\000ld"]; - optional string string_piece_with_zero = 25 [ctype=STRING_PIECE, - default="ab\000c"]; - optional string cord_with_zero = 26 [ctype=CORD, - default="12\0003"]; - optional string replacement_string = 27 [default="${unknown}"]; -} - -message SparseEnumMessage { - optional TestSparseEnum sparse_enum = 1; -} - -// Test String and Bytes: string is for valid UTF-8 strings -message OneString { - optional string data = 1; -} - -message MoreString { - repeated string data = 1; -} - -message OneBytes { - optional bytes data = 1; -} - -message MoreBytes { - repeated bytes data = 1; -} - -message ManyOptionalString { - optional string str1 = 1; - optional string str2 = 2; - optional string str3 = 3; - optional string str4 = 4; - optional string str5 = 5; - optional string str6 = 6; - optional string str7 = 7; - optional string str8 = 8; - optional string str9 = 9; - optional string str10 = 10; - optional string str11 = 11; - optional string str12 = 12; - optional string str13 = 13; - optional string str14 = 14; - optional string str15 = 15; - optional string str16 = 16; - optional string str17 = 17; - optional string str18 = 18; - optional string str19 = 19; - optional string str20 = 20; - optional string str21 = 21; - optional string str22 = 22; - optional string str23 = 23; - optional string str24 = 24; - optional string str25 = 25; - optional string str26 = 26; - optional string str27 = 27; - optional string str28 = 28; - optional string str29 = 29; - optional string str30 = 30; - optional string str31 = 31; - optional string str32 = 32; -} - -// Test int32, uint32, int64, uint64, and bool are all compatible -message Int32Message { - optional int32 data = 1; -} - -message Uint32Message { - optional uint32 data = 1; -} - -message Int64Message { - optional int64 data = 1; -} - -message Uint64Message { - optional uint64 data = 1; -} - -message BoolMessage { - optional bool data = 1; -} - -// Test oneofs. -message TestOneof { - oneof foo { - int32 foo_int = 1; - string foo_string = 2; - TestAllTypes foo_message = 3; - group FooGroup = 4 { - optional int32 a = 5; - optional string b = 6; - } - } -} - -message TestOneofBackwardsCompatible { - optional int32 foo_int = 1; - optional string foo_string = 2; - optional TestAllTypes foo_message = 3; - optional group FooGroup = 4 { - optional int32 a = 5; - optional string b = 6; - } -} - -message TestOneof2 { - oneof foo { - int32 foo_int = 1; - string foo_string = 2; - string foo_cord = 3 [ctype=CORD]; - string foo_string_piece = 4 [ctype=STRING_PIECE]; - bytes foo_bytes = 5; - NestedEnum foo_enum = 6; - NestedMessage foo_message = 7; - group FooGroup = 8 { - optional int32 a = 9; - optional string b = 10; - } - NestedMessage foo_lazy_message = 11 [lazy=true]; - } - - oneof bar { - int32 bar_int = 12 [default = 5]; - string bar_string = 13 [default = "STRING"]; - string bar_cord = 14 [ctype=CORD, default = "CORD"]; - string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; - bytes bar_bytes = 16 [default = "BYTES"]; - NestedEnum bar_enum = 17 [default = BAR]; - string bar_string_with_empty_default = 20 [default = ""]; - string bar_cord_with_empty_default = 21 [ctype=CORD, default = ""]; - string bar_string_piece_with_empty_default = 22 [ctype=STRING_PIECE, default = ""]; - bytes bar_bytes_with_empty_default = 23 [default = ""]; - } - - optional int32 baz_int = 18; - optional string baz_string = 19 [default = "BAZ"]; - - message NestedMessage { - optional int64 moo_int = 1; - repeated int32 corge_int = 2; - } - - enum NestedEnum { - FOO = 1; - BAR = 2; - BAZ = 3; - } -} - -message TestRequiredOneof { - oneof foo { - int32 foo_int = 1; - string foo_string = 2; - NestedMessage foo_message = 3; - } - message NestedMessage { - required double required_double = 1; - } -} - - -// Test messages for packed fields - -message TestPackedTypes { - repeated int32 packed_int32 = 90 [packed = true]; - repeated int64 packed_int64 = 91 [packed = true]; - repeated uint32 packed_uint32 = 92 [packed = true]; - repeated uint64 packed_uint64 = 93 [packed = true]; - repeated sint32 packed_sint32 = 94 [packed = true]; - repeated sint64 packed_sint64 = 95 [packed = true]; - repeated fixed32 packed_fixed32 = 96 [packed = true]; - repeated fixed64 packed_fixed64 = 97 [packed = true]; - repeated sfixed32 packed_sfixed32 = 98 [packed = true]; - repeated sfixed64 packed_sfixed64 = 99 [packed = true]; - repeated float packed_float = 100 [packed = true]; - repeated double packed_double = 101 [packed = true]; - repeated bool packed_bool = 102 [packed = true]; - 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. -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]; -} - -message TestPackedExtensions { - extensions 1 to max; -} - -extend TestPackedExtensions { - repeated int32 packed_int32_extension = 90 [packed = true]; - repeated int64 packed_int64_extension = 91 [packed = true]; - repeated uint32 packed_uint32_extension = 92 [packed = true]; - repeated uint64 packed_uint64_extension = 93 [packed = true]; - repeated sint32 packed_sint32_extension = 94 [packed = true]; - repeated sint64 packed_sint64_extension = 95 [packed = true]; - repeated fixed32 packed_fixed32_extension = 96 [packed = true]; - repeated fixed64 packed_fixed64_extension = 97 [packed = true]; - repeated sfixed32 packed_sfixed32_extension = 98 [packed = true]; - repeated sfixed64 packed_sfixed64_extension = 99 [packed = true]; - repeated float packed_float_extension = 100 [packed = true]; - repeated double packed_double_extension = 101 [packed = true]; - repeated bool packed_bool_extension = 102 [packed = true]; - repeated ForeignEnum packed_enum_extension = 103 [packed = true]; -} - -message TestUnpackedExtensions { - extensions 1 to max; -} - -extend TestUnpackedExtensions { - repeated int32 unpacked_int32_extension = 90 [packed = false]; - repeated int64 unpacked_int64_extension = 91 [packed = false]; - repeated uint32 unpacked_uint32_extension = 92 [packed = false]; - repeated uint64 unpacked_uint64_extension = 93 [packed = false]; - repeated sint32 unpacked_sint32_extension = 94 [packed = false]; - repeated sint64 unpacked_sint64_extension = 95 [packed = false]; - repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; - repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; - repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; - repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; - repeated float unpacked_float_extension = 100 [packed = false]; - repeated double unpacked_double_extension = 101 [packed = false]; - repeated bool unpacked_bool_extension = 102 [packed = false]; - repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; -} - -// Used by ExtensionSetTest/DynamicExtensions. The test actually builds -// a set of extensions to TestAllExtensions dynamically, based on the fields -// of this message type. -message TestDynamicExtensions { - enum DynamicEnumType { - DYNAMIC_FOO = 2200; - DYNAMIC_BAR = 2201; - DYNAMIC_BAZ = 2202; - } - message DynamicMessageType { - optional int32 dynamic_field = 2100; - } - - optional fixed32 scalar_extension = 2000; - optional ForeignEnum enum_extension = 2001; - optional DynamicEnumType dynamic_enum_extension = 2002; - - optional ForeignMessage message_extension = 2003; - optional DynamicMessageType dynamic_message_extension = 2004; - - repeated string repeated_extension = 2005; - repeated sint32 packed_extension = 2006 [packed = true]; -} - -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; -} - -// Test that if an optional or required message/group field appears multiple -// times in the input, they need to be merged. -message TestParsingMerge { - // RepeatedFieldsGenerator defines matching field types as TestParsingMerge, - // except that all fields are repeated. In the tests, we will serialize the - // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge. - // Repeated fields in RepeatedFieldsGenerator are expected to be merged into - // the corresponding required/optional fields in TestParsingMerge. - message RepeatedFieldsGenerator { - repeated TestAllTypes field1 = 1; - repeated TestAllTypes field2 = 2; - repeated TestAllTypes field3 = 3; - repeated group Group1 = 10 { - optional TestAllTypes field1 = 11; - } - repeated group Group2 = 20 { - optional TestAllTypes field1 = 21; - } - repeated TestAllTypes ext1 = 1000; - repeated TestAllTypes ext2 = 1001; - } - required TestAllTypes required_all_types = 1; - optional TestAllTypes optional_all_types = 2; - repeated TestAllTypes repeated_all_types = 3; - optional group OptionalGroup = 10 { - optional TestAllTypes optional_group_all_types = 11; - } - repeated group RepeatedGroup = 20 { - optional TestAllTypes repeated_group_all_types = 21; - } - extensions 1000 to max; - extend TestParsingMerge { - optional TestAllTypes optional_ext = 1000; - repeated TestAllTypes repeated_ext = 1001; - } -} - -// Test that the correct exception is thrown by parseFrom in a corner case -// involving merging, extensions, and required fields. -message TestMergeException { - optional TestAllExtensions all_extensions = 1; -} - -message TestCommentInjectionMessage { - // */ <- This should not close the generated doc comment - optional string a = 1 [default="*/ <- Neither should this."]; -} - -// Used to check that the c++ code generator re-orders messages to reduce -// padding. -message TestMessageSize { - optional bool m1 = 1; - optional int64 m2 = 2; - optional bool m3 = 3; - optional string m4 = 4; - optional int32 m5 = 5; - optional int64 m6 = 6; -} - - -// 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); -} - - -message BarRequest {} -message BarResponse {} - -message TestJsonName { - optional int32 field_name1 = 1; - optional int32 fieldName2 = 2; - optional int32 FieldName3 = 3; - optional int32 _field_name4 = 4; - optional int32 FIELD_NAME5 = 5; - optional int32 field_name6 = 6 [json_name = "@type"]; - optional int32 fieldname7 = 7; -} - -message TestHugeFieldNumbers { - optional int32 optional_int32 = 536870000; - optional int32 fixed_32 = 536870001; - repeated int32 repeated_int32 = 536870002 [packed = false]; - repeated int32 packed_int32 = 536870003 [packed = true]; - - optional ForeignEnum optional_enum = 536870004; - optional string optional_string = 536870005; - optional bytes optional_bytes = 536870006; - optional ForeignMessage optional_message = 536870007; - - optional group OptionalGroup = 536870008 { - optional int32 group_a = 536870009; - } - - map string_string_map = 536870010; - - oneof oneof_field { - uint32 oneof_uint32 = 536870011; - TestAllTypes oneof_test_all_types = 536870012; - string oneof_string = 536870013; - bytes oneof_bytes = 536870014; - } - - extensions 536860000 to 536869999; -} - -extend TestHugeFieldNumbers { - optional TestAllTypes test_all_types = 536860000; -} - -message TestExtensionInsideTable { - optional int32 field1 = 1; - optional int32 field2 = 2; - optional int32 field3 = 3; - optional int32 field4 = 4; - extensions 5 to 5; - optional int32 field6 = 6; - optional int32 field7 = 7; - optional int32 field8 = 8; - optional int32 field9 = 9; - optional int32 field10 = 10; -} - -extend TestExtensionInsideTable { - optional int32 test_extension_inside_table_extension = 5; -} - -// NOTE(b/202996544): Intentionally nested to mirror go/glep. -message TestNestedGroupExtensionOuter { - optional group Layer1OptionalGroup = 1 { - repeated group Layer2RepeatedGroup = 2 { - extensions 3 - // NOTE: extension metadata is not supported due to targets such as - // `//third_party/protobuf_legacy_opensource/src:shell_scripts_test`, - // eee https://screenshot.googleplex.com/Axz2QD8nxjdpyFF - //[metadata = { - // NOTE: can't write type there due to some clever build gen code at - // http://google3/net/proto2/internal/BUILD;l=1247;rcl=411090862 - // type: "objc.protobuf.tests.TestNestedGroupExtensionInnerExtension", - // name: "inner", - // }] - ; - optional string another_field = 6; - } - repeated group Layer2AnotherOptionalRepeatedGroup = 4 { - optional string but_why_tho = 5; - } - } -} - -message TestNestedGroupExtensionInnerExtension { - optional string inner_name= 1; -} - -extend TestNestedGroupExtensionOuter.Layer1OptionalGroup.Layer2RepeatedGroup { - optional TestNestedGroupExtensionInnerExtension inner = 3; -} - -enum VeryLargeEnum { - ENUM_LABEL_DEFAULT = 0; - ENUM_LABEL_1 = 1; - ENUM_LABEL_2 = 2; - ENUM_LABEL_3 = 3; - ENUM_LABEL_4 = 4; - ENUM_LABEL_5 = 5; - ENUM_LABEL_6 = 6; - ENUM_LABEL_7 = 7; - ENUM_LABEL_8 = 8; - ENUM_LABEL_9 = 9; - ENUM_LABEL_10 = 10; - ENUM_LABEL_11 = 11; - ENUM_LABEL_12 = 12; - ENUM_LABEL_13 = 13; - ENUM_LABEL_14 = 14; - ENUM_LABEL_15 = 15; - ENUM_LABEL_16 = 16; - ENUM_LABEL_17 = 17; - ENUM_LABEL_18 = 18; - ENUM_LABEL_19 = 19; - ENUM_LABEL_20 = 20; - ENUM_LABEL_21 = 21; - ENUM_LABEL_22 = 22; - ENUM_LABEL_23 = 23; - ENUM_LABEL_24 = 24; - ENUM_LABEL_25 = 25; - ENUM_LABEL_26 = 26; - ENUM_LABEL_27 = 27; - ENUM_LABEL_28 = 28; - ENUM_LABEL_29 = 29; - ENUM_LABEL_30 = 30; - ENUM_LABEL_31 = 31; - ENUM_LABEL_32 = 32; - ENUM_LABEL_33 = 33; - ENUM_LABEL_34 = 34; - ENUM_LABEL_35 = 35; - ENUM_LABEL_36 = 36; - ENUM_LABEL_37 = 37; - ENUM_LABEL_38 = 38; - ENUM_LABEL_39 = 39; - ENUM_LABEL_40 = 40; - ENUM_LABEL_41 = 41; - ENUM_LABEL_42 = 42; - ENUM_LABEL_43 = 43; - ENUM_LABEL_44 = 44; - ENUM_LABEL_45 = 45; - ENUM_LABEL_46 = 46; - ENUM_LABEL_47 = 47; - ENUM_LABEL_48 = 48; - ENUM_LABEL_49 = 49; - ENUM_LABEL_50 = 50; - ENUM_LABEL_51 = 51; - ENUM_LABEL_52 = 52; - ENUM_LABEL_53 = 53; - ENUM_LABEL_54 = 54; - ENUM_LABEL_55 = 55; - ENUM_LABEL_56 = 56; - ENUM_LABEL_57 = 57; - ENUM_LABEL_58 = 58; - ENUM_LABEL_59 = 59; - ENUM_LABEL_60 = 60; - ENUM_LABEL_61 = 61; - ENUM_LABEL_62 = 62; - ENUM_LABEL_63 = 63; - ENUM_LABEL_64 = 64; - ENUM_LABEL_65 = 65; - ENUM_LABEL_66 = 66; - ENUM_LABEL_67 = 67; - ENUM_LABEL_68 = 68; - ENUM_LABEL_69 = 69; - ENUM_LABEL_70 = 70; - ENUM_LABEL_71 = 71; - ENUM_LABEL_72 = 72; - ENUM_LABEL_73 = 73; - ENUM_LABEL_74 = 74; - ENUM_LABEL_75 = 75; - ENUM_LABEL_76 = 76; - ENUM_LABEL_77 = 77; - ENUM_LABEL_78 = 78; - ENUM_LABEL_79 = 79; - ENUM_LABEL_80 = 80; - ENUM_LABEL_81 = 81; - ENUM_LABEL_82 = 82; - ENUM_LABEL_83 = 83; - ENUM_LABEL_84 = 84; - ENUM_LABEL_85 = 85; - ENUM_LABEL_86 = 86; - ENUM_LABEL_87 = 87; - ENUM_LABEL_88 = 88; - ENUM_LABEL_89 = 89; - ENUM_LABEL_90 = 90; - ENUM_LABEL_91 = 91; - ENUM_LABEL_92 = 92; - ENUM_LABEL_93 = 93; - ENUM_LABEL_94 = 94; - ENUM_LABEL_95 = 95; - ENUM_LABEL_96 = 96; - ENUM_LABEL_97 = 97; - ENUM_LABEL_98 = 98; - ENUM_LABEL_99 = 99; - ENUM_LABEL_100 = 100; -}; - -message TestExtensionRangeSerialize { - optional int32 foo_one = 1; - - extensions 2 to 2; - extensions 3 to 4; - - optional int32 foo_two = 6; - optional int32 foo_three = 7; - - extensions 9 to 10; - - optional int32 foo_four = 13; - - extensions 15 to 15; - extensions 17 to 17; - extensions 19 to 19; - - extend TestExtensionRangeSerialize { - optional int32 bar_one = 2; - optional int32 bar_two = 4; - - optional int32 bar_three = 10; - - optional int32 bar_four = 15; - optional int32 bar_five = 19; - } -} - -message TestVerifyInt32Simple { - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; -} - -message TestVerifyInt32 { - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyMostlyInt32 { - optional int64 optional_int64_30 = 30; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_3 = 3; - optional int32 optional_int32_4 = 4; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyMostlyInt32BigFieldNumber { - optional int64 optional_int64_30 = 30; - optional int32 optional_int32_300 = 300; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_3 = 3; - optional int32 optional_int32_4 = 4; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyUint32Simple { - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; -} - -message TestVerifyUint32 { - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyOneUint32 { - optional uint32 optional_uint32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyOneInt32BigFieldNumber { - optional int32 optional_int32_65 = 65; - - optional int64 optional_int64_1 = 1; - optional int64 optional_int64_2 = 2; - optional int64 optional_int64_63 = 63; - optional int64 optional_int64_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyInt32BigFieldNumber { - optional int32 optional_int32_1000 = 1000; - optional int32 optional_int32_65 = 65; - - optional int32 optional_int32_1 = 1; - optional int32 optional_int32_2 = 2; - optional int32 optional_int32_63 = 63; - optional int32 optional_int32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyUint32BigFieldNumber { - optional uint32 optional_uint32_1000 = 1000; - optional uint32 optional_uint32_65 = 65; - - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional TestAllTypes optional_all_types = 9; - repeated TestAllTypes repeated_all_types = 10; -} - -message TestVerifyBigFieldNumberUint32 { - message Nested { - optional uint32 optional_uint32_5000 = 5000; - optional uint32 optional_uint32_1000 = 1000; - optional uint32 optional_uint32_66 = 66; - optional uint32 optional_uint32_65 = 65; - - optional uint32 optional_uint32_1 = 1; - optional uint32 optional_uint32_2 = 2; - optional uint32 optional_uint32_63 = 63; - optional uint32 optional_uint32_64 = 64; - - optional Nested optional_nested = 9; - repeated Nested repeated_nested = 10; - } - optional Nested optional_nested = 1; -} - - -// This message contains different kind of enums to exercise the different -// parsers in table-driven. -message EnumParseTester { - enum SeqSmall0 { - SEQ_SMALL_0_DEFAULT = 0; - SEQ_SMALL_0_1 = 1; - SEQ_SMALL_0_2 = 2; - }; - optional SeqSmall0 optional_seq_small_0_lowfield = 1; - optional SeqSmall0 optional_seq_small_0_midfield = 1001; - optional SeqSmall0 optional_seq_small_0_hifield = 1000001; - repeated SeqSmall0 repeated_seq_small_0_lowfield = 2; - repeated SeqSmall0 repeated_seq_small_0_midfield = 1002; - repeated SeqSmall0 repeated_seq_small_0_hifield = 1000002; - repeated SeqSmall0 packed_seq_small_0_lowfield = 3 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_midfield = 1003 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_hifield = 1000003 [packed = true]; - - enum SeqSmall1 { - SEQ_SMALL_1_DEFAULT = 1; - SEQ_SMALL_1_2 = 2; - SEQ_SMALL_1_3 = 3; - }; - optional SeqSmall1 optional_seq_small_1_lowfield = 4; - optional SeqSmall1 optional_seq_small_1_midfield = 1004; - optional SeqSmall1 optional_seq_small_1_hifield = 1000004; - repeated SeqSmall1 repeated_seq_small_1_lowfield = 5; - repeated SeqSmall1 repeated_seq_small_1_midfield = 1005; - repeated SeqSmall1 repeated_seq_small_1_hifield = 1000005; - repeated SeqSmall1 packed_seq_small_1_lowfield = 6 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_midfield = 1006 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_hifield = 1000006 [packed = true]; - - enum SeqLarge { - SEQ_LARGE_DEFAULT = -1; - SEQ_LARGE_0 = 0; - SEQ_LARGE_1 = 1; - SEQ_LARGE_2 = 2; - SEQ_LARGE_3 = 3; - SEQ_LARGE_4 = 4; - SEQ_LARGE_5 = 5; - SEQ_LARGE_6 = 6; - SEQ_LARGE_7 = 7; - SEQ_LARGE_8 = 8; - SEQ_LARGE_9 = 9; - SEQ_LARGE_10 = 10; - SEQ_LARGE_11 = 11; - SEQ_LARGE_12 = 12; - SEQ_LARGE_13 = 13; - SEQ_LARGE_14 = 14; - SEQ_LARGE_15 = 15; - SEQ_LARGE_16 = 16; - SEQ_LARGE_17 = 17; - SEQ_LARGE_18 = 18; - SEQ_LARGE_19 = 19; - SEQ_LARGE_20 = 20; - SEQ_LARGE_21 = 21; - SEQ_LARGE_22 = 22; - SEQ_LARGE_23 = 23; - SEQ_LARGE_24 = 24; - SEQ_LARGE_25 = 25; - SEQ_LARGE_26 = 26; - SEQ_LARGE_27 = 27; - SEQ_LARGE_28 = 28; - SEQ_LARGE_29 = 29; - SEQ_LARGE_30 = 30; - SEQ_LARGE_31 = 31; - SEQ_LARGE_32 = 32; - SEQ_LARGE_33 = 33; - }; - optional SeqLarge optional_seq_large_lowfield = 7; - optional SeqLarge optional_seq_large_midfield = 1007; - optional SeqLarge optional_seq_large_hifield = 1000007; - repeated SeqLarge repeated_seq_large_lowfield = 8; - repeated SeqLarge repeated_seq_large_midfield = 1008; - repeated SeqLarge repeated_seq_large_hifield = 1000008; - repeated SeqLarge packed_seq_large_lowfield = 9 [packed = true]; - repeated SeqLarge packed_seq_large_midfield = 1009 [packed = true]; - repeated SeqLarge packed_seq_large_hifield = 1000009 [packed = true]; - - enum Arbitrary { - ARBITRARY_DEFAULT = -123123; - ARBITRARY_1 = -123; - ARBITRARY_2 = 213; - ARBITRARY_3 = 213213; - ARBITRARY_MIN = -2147483648; - ARBITRARY_MAX = 2147483647; - }; - optional Arbitrary optional_arbitrary_lowfield = 10; - optional Arbitrary optional_arbitrary_midfield = 1010; - optional Arbitrary optional_arbitrary_hifield = 1000010; - repeated Arbitrary repeated_arbitrary_lowfield = 11; - repeated Arbitrary repeated_arbitrary_midfield = 1011; - repeated Arbitrary repeated_arbitrary_hifield = 1000011; - repeated Arbitrary packed_arbitrary_lowfield = 12 [packed = true]; - repeated Arbitrary packed_arbitrary_midfield = 1012 [packed = true]; - repeated Arbitrary packed_arbitrary_hifield = 1000012 [packed = true]; - - // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; -}; - -// This message contains different kind of bool fields to exercise the different -// parsers in table-drived. -message BoolParseTester { - optional bool optional_bool_lowfield = 1; - optional bool optional_bool_midfield = 1001; - optional bool optional_bool_hifield = 1000001; - repeated bool repeated_bool_lowfield = 2; - repeated bool repeated_bool_midfield = 1002; - repeated bool repeated_bool_hifield = 1000002; - repeated bool packed_bool_lowfield = 3 [packed = true]; - repeated bool packed_bool_midfield = 1003 [packed = true]; - repeated bool packed_bool_hifield = 1000003 [packed = true]; - - // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; -}; - diff --git a/libs/protobuf/objectivec/Tests/unittest_cycle.proto b/libs/protobuf/objectivec/Tests/unittest_cycle.proto index 91e33ce..afc1b0f 100644 --- a/libs/protobuf/objectivec/Tests/unittest_cycle.proto +++ b/libs/protobuf/objectivec/Tests/unittest_cycle.proto @@ -29,9 +29,7 @@ syntax = "proto2"; -package objc.protobuf.tests.cycle; - -option objc_class_prefix = "Cycle"; +package protobuf_unittest; // Cycles in the Message graph can cause problems for message class // initialization order. @@ -39,20 +37,20 @@ option objc_class_prefix = "Cycle"; // You can't make a object graph that spans files, so this can only be done // within a single proto file. -message Foo { - optional Foo a_foo = 1; - optional Bar a_bar = 2; - optional Baz a_baz = 3; +message CycleFoo { + optional CycleFoo a_foo = 1; + optional CycleBar a_bar = 2; + optional CycleBaz a_baz = 3; } -message Bar { - optional Bar a_bar = 1; - optional Baz a_baz = 2; - optional Foo a_foo = 3; +message CycleBar { + optional CycleBar a_bar = 1; + optional CycleBaz a_baz = 2; + optional CycleFoo a_foo = 3; } -message Baz { - optional Baz a_baz = 1; - optional Foo a_foo = 2; - optional Bar a_bar = 3; +message CycleBaz { + optional CycleBaz a_baz = 1; + optional CycleFoo a_foo = 2; + optional CycleBar a_bar = 3; } diff --git a/libs/protobuf/objectivec/Tests/unittest_deprecated.proto b/libs/protobuf/objectivec/Tests/unittest_deprecated.proto index aa06a06..96a52bb 100644 --- a/libs/protobuf/objectivec/Tests/unittest_deprecated.proto +++ b/libs/protobuf/objectivec/Tests/unittest_deprecated.proto @@ -29,7 +29,7 @@ syntax = "proto2"; -package objc.protobuf.tests.deprecated; +package protobuf_deprecated; option objc_class_prefix = "Dep"; // diff --git a/libs/protobuf/objectivec/Tests/unittest_deprecated_file.proto b/libs/protobuf/objectivec/Tests/unittest_deprecated_file.proto index b32b4b4..ef92e7d 100644 --- a/libs/protobuf/objectivec/Tests/unittest_deprecated_file.proto +++ b/libs/protobuf/objectivec/Tests/unittest_deprecated_file.proto @@ -29,7 +29,7 @@ syntax = "proto2"; -package objc.protobuf.tests.deprecated_file; +package protobuf_deprecated_file; option objc_class_prefix = "FileDep"; // diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_a.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_a.proto index 2e09a40..6a227eb 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_a.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_a.proto @@ -29,25 +29,23 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest.proto"; +import "google/protobuf/unittest.proto"; -import "objectivec/Tests/unittest_extension_chain_b.proto"; -import "objectivec/Tests/unittest_extension_chain_c.proto"; -import "objectivec/Tests/unittest_extension_chain_d.proto"; - -option objc_class_prefix = "Chain"; +import "unittest_extension_chain_b.proto"; +import "unittest_extension_chain_c.proto"; +import "unittest_extension_chain_d.proto"; // The Root for this file should end up adding the local extension and merging // in the extensions from D's Root (unittest and C will come via D's). -message AMessage { - optional BMessage b = 1; - optional CMessage c = 2; - optional DMessage d = 3; +message ChainAMessage { + optional ChainBMessage b = 1; + optional ChainCMessage c = 2; + optional ChainDMessage d = 3; } -extend objc.protobuf.tests.TestAllExtensions { +extend TestAllExtensions { optional int32 chain_a_extension = 10001; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_b.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_b.proto index 5cf7ea3..0da7ed3 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_b.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_b.proto @@ -29,21 +29,19 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest.proto"; +import "google/protobuf/unittest.proto"; -import "objectivec/Tests/unittest_extension_chain_c.proto"; - -option objc_class_prefix = "Chain"; +import "unittest_extension_chain_c.proto"; // The Root for this file should end up adding the local extension and merging // in the extensions from C's Root (unittest will come via C's). -message BMessage { - optional CMessage c = 1; +message ChainBMessage { + optional ChainCMessage c = 1; } -extend objc.protobuf.tests.TestAllExtensions { +extend TestAllExtensions { optional int32 chain_b_extension = 10002; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_c.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_c.proto index b07b288..c702900 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_c.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_c.proto @@ -29,19 +29,17 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest.proto"; - -option objc_class_prefix = "Chain"; +import "google/protobuf/unittest.proto"; // The Root for this file should end up adding the local extension and merging // in the extensions from unittest.proto's Root. -message CMessage { +message ChainCMessage { optional int32 my_field = 1; } -extend objc.protobuf.tests.TestAllExtensions { +extend TestAllExtensions { optional int32 chain_c_extension = 10003; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_d.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_d.proto index 44d9ee8..f9abe3b 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_d.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_d.proto @@ -29,23 +29,21 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest.proto"; +import "google/protobuf/unittest.proto"; -import "objectivec/Tests/unittest_extension_chain_b.proto"; -import "objectivec/Tests/unittest_extension_chain_c.proto"; - -option objc_class_prefix = "Chain"; +import "unittest_extension_chain_b.proto"; +import "unittest_extension_chain_c.proto"; // The root should end up needing to merge B (C will be merged into B, so it // doesn't need to be directly merged). -message DMessage { - optional BMessage b = 1; - optional CMessage c = 2; +message ChainDMessage { + optional ChainBMessage b = 1; + optional ChainCMessage c = 2; } -extend objc.protobuf.tests.TestAllExtensions { +extend TestAllExtensions { optional int32 chain_d_extension = 10004; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_e.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_e.proto index 9c7cea8..fe11663 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_e.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_e.proto @@ -29,14 +29,12 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest.proto"; - -option objc_class_prefix = "Chain"; +import "google/protobuf/unittest.proto"; // The Root for this file should end up just merging in unittest's Root. -message EMessage { +message ChainEMessage { optional TestAllTypes my_field = 1; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_f.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_f.proto index 33fcaf9..096598d 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_f.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_f.proto @@ -29,11 +29,9 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest_extension_chain_g.proto"; - -option objc_class_prefix = "Chain"; +import "unittest_extension_chain_g.proto"; // The Root for this file should just be merging in the extensions from C's // Root (because G doesn't define anything itself). @@ -41,6 +39,6 @@ option objc_class_prefix = "Chain"; // The generated source will also have to directly import C's .h file so it can // compile the reference to C's Root class. -message FMessage { - optional GMessage g = 1; +message ChainFMessage { + optional ChainGMessage g = 1; } diff --git a/libs/protobuf/objectivec/Tests/unittest_extension_chain_g.proto b/libs/protobuf/objectivec/Tests/unittest_extension_chain_g.proto index 9044e46..aee827b 100644 --- a/libs/protobuf/objectivec/Tests/unittest_extension_chain_g.proto +++ b/libs/protobuf/objectivec/Tests/unittest_extension_chain_g.proto @@ -29,15 +29,13 @@ syntax = "proto2"; -package objc.protobuf.tests.chain; +package protobuf_unittest; -import "objectivec/Tests/unittest_extension_chain_c.proto"; - -option objc_class_prefix = "Chain"; +import "unittest_extension_chain_c.proto"; // The Root for this file should just be merging in the extensions from C's // Root. -message GMessage { - optional CMessage c = 1; +message ChainGMessage { + optional ChainCMessage c = 1; } diff --git a/libs/protobuf/objectivec/Tests/unittest_objc.proto b/libs/protobuf/objectivec/Tests/unittest_objc.proto index c7e4034..91c2139 100644 --- a/libs/protobuf/objectivec/Tests/unittest_objc.proto +++ b/libs/protobuf/objectivec/Tests/unittest_objc.proto @@ -30,12 +30,9 @@ syntax = "proto2"; import "google/protobuf/any.proto"; -import "objectivec/Tests/unittest.proto"; +import "google/protobuf/unittest.proto"; -package objc.protobuf.tests; - -// Explicit empty prefix, tests some validations code paths also. -option objc_class_prefix = ""; +package protobuf_unittest; // Used to check that Headerdocs and appledoc work correctly. If these comments // are not handled correctly, Xcode will fail to build the tests. @@ -239,7 +236,8 @@ extend self { repeated sint32 byref = 3004 [packed = true]; } -// Test handing of fields that start with init*. +// Test handing of fields that start with init* since Xcode 5's ARC support +// doesn't like messages that look like initializers but aren't. message ObjCInitFoo { optional string init_val = 11; optional int32 init_size = 12; diff --git a/libs/protobuf/objectivec/Tests/unittest_objc_options.proto b/libs/protobuf/objectivec/Tests/unittest_objc_options.proto index 7d3f677..6129b85 100644 --- a/libs/protobuf/objectivec/Tests/unittest_objc_options.proto +++ b/libs/protobuf/objectivec/Tests/unittest_objc_options.proto @@ -30,8 +30,7 @@ syntax = "proto2"; -package objc.protobuf.tests.options; - +package protobuf_objc_unittest; option objc_class_prefix = "GPBTEST"; // Verify that enum types and values get the prefix. @@ -60,9 +59,3 @@ message GPBTESTshouldGetAPrefixMessage { // Verify that classes named the same as prefixes are prefixed. message GPBTEST { } - -// Tests that lookup deals with prefix. -message PrefixedParentMessage { - message Child { - } -} diff --git a/libs/protobuf/objectivec/Tests/unittest_objc_startup.proto b/libs/protobuf/objectivec/Tests/unittest_objc_startup.proto index f2bf9d5..aee7bd5 100644 --- a/libs/protobuf/objectivec/Tests/unittest_objc_startup.proto +++ b/libs/protobuf/objectivec/Tests/unittest_objc_startup.proto @@ -30,21 +30,20 @@ syntax = "proto2"; -package objc.protobuf.tests.startup; -option objc_class_prefix = "TestObjCStartup"; +package protobuf_objc_unittest; -message Message { +message TestObjCStartupMessage { extensions 1 to max; } -extend Message { +extend TestObjCStartupMessage { // Singular optional int32 optional_int32_extension = 1; repeated int32 repeated_int32_extension = 2; } -message Nested { - extend Message { +message TestObjCStartupNested { + extend TestObjCStartupMessage { optional string nested_string_extension = 3; } } diff --git a/libs/protobuf/objectivec/Tests/unittest_runtime_proto2.proto b/libs/protobuf/objectivec/Tests/unittest_runtime_proto2.proto index 12c2b1c..ed83502 100644 --- a/libs/protobuf/objectivec/Tests/unittest_runtime_proto2.proto +++ b/libs/protobuf/objectivec/Tests/unittest_runtime_proto2.proto @@ -29,10 +29,7 @@ syntax = "proto2"; -// Explicit empty prefix, tests some validations code paths also. -package objc.protobuf.tests; - -option objc_class_prefix = ""; +package protobuf_unittest; message Message2 { enum Enum { diff --git a/libs/protobuf/objectivec/Tests/unittest_runtime_proto3.proto b/libs/protobuf/objectivec/Tests/unittest_runtime_proto3.proto index d6d4380..c2ee5fb 100644 --- a/libs/protobuf/objectivec/Tests/unittest_runtime_proto3.proto +++ b/libs/protobuf/objectivec/Tests/unittest_runtime_proto3.proto @@ -29,10 +29,7 @@ syntax = "proto3"; -// Explicit empty prefix, tests some validations code paths also. -package objc.protobuf.tests; - -option objc_class_prefix = ""; +package protobuf_unittest; message Message3 { enum Enum { diff --git a/libs/protobuf/objectivec/generate_well_known_types.sh b/libs/protobuf/objectivec/generate_well_known_types.sh index 0fb9f4c..1b9de6e 100755 --- a/libs/protobuf/objectivec/generate_well_known_types.sh +++ b/libs/protobuf/objectivec/generate_well_known_types.sh @@ -3,15 +3,16 @@ # Run this script to regenerate *.pbobjc.{h,m} for the well known types after # the protocol compiler changes. +# HINT: Flags passed to generate_well_known_types.sh will be passed directly +# to make when building protoc. This is particularly useful for passing +# -j4 to run 4 jobs simultaneously. + set -eu readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")") readonly ObjCDir="${ScriptDir}" readonly ProtoRootDir="${ObjCDir}/.." -# Invoke with BAZEL=bazelisk to use that instead. -readonly BazelBin="${BAZEL:=bazel}" - # Flag for continuous integration to check that everything is current. CHECK_ONLY=0 if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then @@ -29,10 +30,18 @@ __EOF__ exit 1 fi -# Make sure the compiler is current. -"${BazelBin}" build $@ //:protoc +if [[ ! -e src/Makefile ]]; then + cat >&2 << __EOF__ +Could not find src/Makefile. You must run ./configure (and perhaps +./autogen.sh) first. +__EOF__ + exit 1 +fi +# Make sure the compiler is current. cd src +make $@ protoc + declare -a RUNTIME_PROTO_FILES=( \ google/protobuf/any.proto \ google/protobuf/api.proto \ @@ -50,7 +59,7 @@ declare -a OBJC_EXTENSIONS=( .pbobjc.h .pbobjc.m ) # Generate to a temp directory to see if they match. TMP_DIR=$(mktemp -d) trap "rm -rf ${TMP_DIR}" EXIT -${ProtoRootDir}/bazel-bin/protoc --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]} +./protoc --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]} DID_COPY=0 for PROTO_FILE in "${RUNTIME_PROTO_FILES[@]}"; do @@ -64,7 +73,6 @@ for PROTO_FILE in "${RUNTIME_PROTO_FILES[@]}"; do if ! diff "${ObjCDir}/GPB${OBJC_NAME}${EXT}" "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}" > /dev/null 2>&1 ; then if [[ "${CHECK_ONLY}" == 1 ]] ; then echo "ERROR: The WKTs need to be regenerated! Run $0" - diff -u "${ObjCDir}/GPB${OBJC_NAME}${EXT}" "${TMP_DIR}/${DIR}/${OBJC_NAME}${EXT}" exit 1 fi diff --git a/libs/protobuf/php/BUILD.bazel b/libs/protobuf/php/BUILD.bazel index ac33702..7fededa 100644 --- a/libs/protobuf/php/BUILD.bazel +++ b/libs/protobuf/php/BUILD.bazel @@ -2,127 +2,22 @@ # # See also code generation logic under /src/google/protobuf/compiler/php. -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@upb//cmake:build_defs.bzl", "staleness_test") -load("//build_defs:internal_shell.bzl", "inline_sh_binary") -load("//conformance:defs.bzl", "conformance_test") - -filegroup( - name = "source_files", - visibility = [ - "//conformance:__pkg__", - "//php:__pkg__", - ], - srcs = glob([ - "ext/google/protobuf/*.h", - "ext/google/protobuf/*.c", - "src/GPBMetadata/Google/Protobuf/**/*.php", - "src/Google/Protobuf/**/*.php", - ]) + [ - "composer.json", - "ext/google/protobuf/wkt.inc", - "ext/google/protobuf/config.m4", - "ext/google/protobuf/package.xml", - ], -) - -################################################################################ -# PHP Extension -################################################################################ - -inline_sh_binary( - name = "build_extension", - cmd = """ - mkdir -p php/ext/google/protobuf/third_party/utf8_range - cp external/utf8_range/* php/ext/google/protobuf/third_party/utf8_range - - pushd php/ext/google/protobuf - phpize - ./configure --with-php-config=$$(which php-config) - make - popd - """, -) - -genrule( - name = "extension", - srcs = [ - ":source_files", - "@utf8_range//:utf8_range_srcs", - ], - tools = [":build_extension"], - outs = ["protobuf.so"], - cmd = """ - ./$(execpath :build_extension) $@ - cp php/ext/google/protobuf/modules/protobuf.so $(OUTS) - """, - visibility = ["//visibility:public"], -) - -################################################################################ -# Tests -################################################################################ - -conformance_test( - name = "conformance_test", - failure_list = "//conformance:failure_list_php.txt", - testee = "//conformance:conformance_php", - text_format_failure_list = "//conformance:text_format_failure_list_php.txt", - target_compatible_with = select({ - "@platforms//os:osx": ["@platforms//:incompatible"], - "//conditions:default": [], - }), -) - -conformance_test( - name = "conformance_test_c", - failure_list = "//conformance:failure_list_php_c.txt", - testee = "//conformance:conformance_php_c", - text_format_failure_list = "//conformance:text_format_failure_list_php.txt", - target_compatible_with = select({ - "@platforms//os:osx": [], - "//conditions:default": ["@platforms//:incompatible"], - }), -) - -genrule( - name = "copy_php_amalgamation_h", - srcs = ["@upb//:php-upb.h"], - outs = ["generated-in/ext/google/protobuf/php-upb.h"], - cmd = "cp $< $@", -) - -genrule( - name = "copy_php_amalgamation_c", - srcs = ["@upb//:php-upb.c"], - outs = ["generated-in/ext/google/protobuf/php-upb.c"], - cmd = "cp $< $@", -) - -staleness_test( - name = "test_amalgamation_staleness", - outs = [ - "ext/google/protobuf/php-upb.h", - "ext/google/protobuf/php-upb.c", - ], - generated_pattern = "generated-in/%s", -) - -################################################################################ -# Distribution files -################################################################################ +load("@rules_pkg//:pkg.bzl", "pkg_tar") +load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix") +load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION") pkg_files( name = "dist_files", srcs = glob([ "ext/google/protobuf/**/*", + "src/GPBMetadata/Google/Protobuf/**/*.php", + "src/Google/Protobuf/**/*.php", "tests/*.php", "tests/*.sh", "tests/generated_previous/**/*.php", "tests/proto/**/*.proto", "tests/proto_previous/*.proto", ]) + [ - ":source_files", "BUILD.bazel", "README.md", "REFCOUNTING.md", @@ -137,3 +32,76 @@ pkg_files( strip_prefix = strip_prefix.from_pkg(""), visibility = ["//pkg:__pkg__"], ) + +################################################################################ +# PECL .tgz Release +################################################################################ + +pkg_files( + name = "php_ext_source_files", + srcs = glob([ + "ext/google/protobuf/*.h", + "ext/google/protobuf/*.c", + ]) + [ + "//:LICENSE", + "ext/google/protobuf/config.m4", + "ext/google/protobuf/wkt.inc", + ], +) + +pkg_files( + name = "utf8_range_files", + srcs = [ + "//third_party/utf8_range:utf8_range_srcs", + "//third_party/utf8_range:LICENSE", + + ], + prefix = "third_party/utf8_range", +) + +pkg_filegroup( + name = "pecl_release_files", + srcs = [ + ":php_ext_source_files", + ":utf8_range_files", + ], + prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION, +) + +# PECL .tgz without package.xml +pkg_tar( + name = "release_without_package", + extension = "tgz", + srcs = [ + ":pecl_release_files", + ], + out = "release_without_package.tgz", +) + +# Generate PECL package.xml +genrule( + name = "generate_package_xml", + srcs = [ + ":release_without_package", + "ext/google/protobuf/template_package.xml", + ], + outs = ["package.xml"], + cmd = " ".join([ + "$(location ext/google/protobuf/generate_package_xml.sh)", + "$(location ext/google/protobuf/template_package.xml)", + PROTOBUF_PHP_VERSION, + "$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')", + "$(location package.xml)" + ]), + tools = ["ext/google/protobuf/generate_package_xml.sh"], +) + +pkg_tar( + name = "release", + extension = "tgz", + srcs = [ + ":pecl_release_files", + ":generate_package_xml", + ], + out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION, +) \ No newline at end of file diff --git a/libs/protobuf/php/README.md b/libs/protobuf/php/README.md index f4e420e..c4292cf 100644 --- a/libs/protobuf/php/README.md +++ b/libs/protobuf/php/README.md @@ -26,6 +26,8 @@ To use PHP runtime library requires: #### Prerequirements To install the c extension, the following tools are needed: +* autoconf +* automake * libtool * make * gcc @@ -34,7 +36,7 @@ To install the c extension, the following tools are needed: On Ubuntu, you can install them with: ``` -sudo apt-get install -y php-pear php-dev libtool make gcc +sudo apt-get install -y php-pear php5-dev autoconf automake libtool make gcc ``` On other platforms, please use the corresponding package managing tool to install them before proceeding. @@ -65,8 +67,6 @@ sudo pecl install protobuf-{VERSION} Simply add "google/protobuf" to the 'require' section of composer.json in your project. -To use the pure PHP implementation, you need to install bcmath. - ### Protoc Once the extension or package is installed, if you wish to generate PHP code @@ -98,18 +98,24 @@ Known Issues ## Development +### Docker Image + +We provide a docker image for php development, which is also used in our automatic tests: +``` +docker run --security-opt seccomp=unconfined -it protobuftesting/php_8dbe419c6df1a8b3af0ae3a267c112efb436b45c +``` + ### Test Native PHP ``` -# Install Dependencies (Linux) -apt-get install bazel composer php-dev - # Download protobuf git clone https://github.com/protocolbuffers/protobuf.git cd protobuf # Build protoc -bazel build :protoc +./autogen.sh +./configure +make -j4 # Test native php cd php diff --git a/libs/protobuf/php/composer.json b/libs/protobuf/php/composer.json index 0e498fc..436142f 100644 --- a/libs/protobuf/php/composer.json +++ b/libs/protobuf/php/composer.json @@ -30,8 +30,5 @@ "test_valgrind": "./generate_test_protos.sh && ./tests/compile_extension.sh && ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0 valgrind --leak-check=full --error-exitcode=1 php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests", "test": "./generate_test_protos.sh && vendor/bin/phpunit tests", "aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit tests" - }, - "config": { - "process-timeout": 1200 } } diff --git a/libs/protobuf/php/ext/google/protobuf/generate_package_xml.sh b/libs/protobuf/php/ext/google/protobuf/generate_package_xml.sh new file mode 100755 index 0000000..3228785 --- /dev/null +++ b/libs/protobuf/php/ext/google/protobuf/generate_package_xml.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +template_package_xml=$1 +release_version=$2 +release_files=$3 +out=$4 + +date=$(date +%Y-%m-%d) +time=$(date +%H:%M:%S) + +php_version_array=(${release_version//RC/ }) +api_version=${php_version_array[0]} +if [ ${#php_version_array[@]} -eq 2 ]; then + rc=${php_version_array[1]} + stability='beta' +else + stability='stable' +fi + +files="\\n" +for file in ${release_files//,/ }; do + name=$(echo $file | grep .*[^/]\$ | sed -e "s;protobuf-${release_version}/;;") + if [ ! -z $name ]; then + if [[ $name =~ LICENSE$ ]]; then + role='doc' + else + role='src' + fi + files+=" \\n" + fi +done + +cat $template_package_xml | +sed -e "s;TEMPLATE_DATE;${date};" | +sed -e "s;TEMPLATE_TIME;${time};" | +sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" | +sed -e "s;TEMPLATE_PHP_API;${api_version};" | +sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" | +sed -e "s;TEMPLATE_FILES;${files};" > $out \ No newline at end of file diff --git a/libs/protobuf/php/ext/google/protobuf/message.c b/libs/protobuf/php/ext/google/protobuf/message.c index 0c90705..55f4f4d 100644 --- a/libs/protobuf/php/ext/google/protobuf/message.c +++ b/libs/protobuf/php/ext/google/protobuf/message.c @@ -601,7 +601,7 @@ PHP_METHOD(Message, __construct) { // // However, if the user created their own class derived from Message, this // will trigger an infinite construction loop and blow the stack. We - // store this `ce` in a global variable to break the cycle (see the check in + // temporarily clear create_object to break this loop (see check in // NameMap_GetMessage()). NameMap_EnterConstructor(ce); desc = Descriptor_GetFromClassEntry(ce); @@ -646,25 +646,6 @@ PHP_METHOD(Message, clear) { upb_Message_Clear(intern->msg, intern->desc->msgdef); } -static bool Message_checkEncodeStatus(upb_EncodeStatus status) { - switch (status) { - case kUpb_EncodeStatus_Ok: - return true; - case kUpb_EncodeStatus_OutOfMemory: - zend_throw_exception_ex(NULL, 0, "Out of memory"); - return false; - case kUpb_EncodeStatus_MaxDepthExceeded: - zend_throw_exception_ex(NULL, 0, "Max nesting exceeded"); - return false; - case kUpb_EncodeStatus_MissingRequired: - zend_throw_exception_ex(NULL, 0, "Missing required field"); - return false; - default: - zend_throw_exception_ex(NULL, 0, "Unknown error encoding"); - return false; - } -} - /** * Message::mergeFrom() * @@ -692,9 +673,14 @@ PHP_METHOD(Message, mergeFrom) { // zend_parse_parameters(). PBPHP_ASSERT(from->desc == intern->desc); - // TODO(haberman): use a temp arena for this. - upb_EncodeStatus status = upb_Encode(from->msg, l, 0, arena, &pb, &size); - if (!Message_checkEncodeStatus(status)) return; + // TODO(haberman): use a temp arena for this once we can make upb_decode() + // copy strings. + pb = upb_Encode(from->msg, l, 0, arena, &size); + + if (!pb) { + zend_throw_exception_ex(NULL, 0, "Max nesting exceeded"); + return; + } ok = upb_Decode(pb, size, intern->msg, l, NULL, 0, arena) == kUpb_DecodeStatus_Ok; @@ -744,9 +730,7 @@ PHP_METHOD(Message, serializeToString) { char *data; size_t size; - upb_EncodeStatus status = - upb_Encode(intern->msg, l, 0, tmp_arena, &data, &size); - if (!Message_checkEncodeStatus(status)) return; + data = upb_Encode(intern->msg, l, 0, tmp_arena, &size); if (!data) { zend_throw_exception_ex(NULL, 0, "Error occurred during serialization"); @@ -1248,12 +1232,8 @@ PHP_METHOD(google_protobuf_Any, pack) { msg = (Message*)Z_OBJ_P(val); // Serialize and set value. - char* pb; - upb_EncodeStatus status = - upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->desc->msgdef), 0, - arena, &pb, &value.size); - if (!Message_checkEncodeStatus(status)) return; - value.data = pb; + value.data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->desc->msgdef), + 0, arena, &value.size); Message_setval(intern, "value", StringVal(value)); // Set type url: type_url_prefix + fully_qualified_name diff --git a/libs/protobuf/php/ext/google/protobuf/package.xml b/libs/protobuf/php/ext/google/protobuf/package.xml deleted file mode 100644 index 462b405..0000000 --- a/libs/protobuf/php/ext/google/protobuf/package.xml +++ /dev/null @@ -1,1453 +0,0 @@ - - - protobuf - pecl.php.net - Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. - https://developers.google.com/protocol-buffers/ - - Protobuf Team - protobufpackages - protobuf-packages@google.com - yes - - 2022-10-13 - - - 3.21.8 - 3.21.8 - - - stable - stable - - BSD-3-Clause - - * See github.com/protocolbuffers/protobuf/releases for release notes. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 7.0.0 - - - 1.4.0 - - - - protobuf - - - - - 3.1.0a1 - 3.1.0a1 - - - alpha - alpha - - 2016-09-23 - - BSD-3-Clause - -First alpha release - - - - - 3.2.0a1 - 3.2.0a1 - - - alpha - alpha - - 2017-01-13 - - BSD-3-Clause - -Second alpha release. - - - - - 3.3.0 - 3.3.0 - - - stable - stable - - 2017-04-28 - - BSD-3-Clause - -GA release. - - - - - 3.3.1 - 3.3.0 - - - stable - stable - - 2017-05-08 - - BSD-3-Clause - -GA release. - - - - - 3.3.2 - 3.3.0 - - - stable - stable - - 2017-06-21 - - BSD-3-Clause - -GA release. - - - - - 3.4.0 - 3.4.0 - - - stable - stable - - 2017-08-16 - - BSD-3-Clause - -GA release. - - - - - 3.4.1 - 3.4.1 - - - stable - stable - - 2017-09-14 - - BSD-3-Clause - -GA release. - - - - - 3.5.0 - 3.5.0 - - - stable - stable - - 2017-11-15 - - BSD-3-Clause - -GA release. - - - - - 3.5.0.1 - 3.5.0.1 - - - stable - stable - - 2017-12-06 - - BSD-3-Clause - -GA release. - - - - - 3.5.1 - 3.5.1 - - - stable - stable - - 2017-12-11 - - BSD-3-Clause - -GA release. - - - - - 3.5.2 - 3.5.2 - - - stable - stable - - 2018-03-06 - - BSD-3-Clause - -G A release. - - - - - 3.6.0 - 3.6.0 - - - stable - stable - - 2018-06-06 - - BSD-3-Clause - -G A release. - - - - - 3.6.1 - 3.6.1 - - - stable - stable - - 2018-08-03 - - BSD-3-Clause - -G A release. - - - - - 3.7.0RC2 - 3.7.0 - - - stable - stable - - 2019-02-1 - - BSD-3-Clause - GA release. - - - - 3.7.0RC3 - 3.7.0 - - - beta - beta - - 2019-02-22 - - BSD-3-Clause - GA release. - - - - 3.7.0 - 3.7.0 - - - stable - stable - - 2019-02-28 - - BSD-3-Clause - GA release. - - - - 3.7.1 - 3.7.1 - - - stable - stable - - 2019-03-25 - - BSD-3-Clause - GA release. - - - - 3.8.0RC1 - 3.8.0 - - - beta - beta - - 2019-04-23 - - BSD-3-Clause - GA release. - - - - 3.8.0 - 3.8.0 - - - stable - stable - - 2019-05-21 - - BSD-3-Clause - GA release. - - - - 3.9.0RC1 - 3.9.0 - - - beta - beta - - 2019-06-17 - - BSD-3-Clause - GA release. - - - - 3.9.0 - 3.9.0 - - - stable - stable - - 2019-07-10 - - BSD-3-Clause - GA release. - - - - 3.9.1 - 3.9.1 - - - stable - stable - - 2019-08-02 - - BSD-3-Clause - GA release. - - - - 3.10.0RC1 - 3.10.0 - - - beta - beta - - 2019-09-04 - - BSD-3-Clause - GA release. - - - - 3.10.0RC1 - 3.10.0 - - - beta - beta - - 2019-09-05 - - BSD-3-Clause - GA release. - - - - 3.10.0 - 3.10.0 - - - stable - stable - - 2019-09-12 - - BSD-3-Clause - GA release. - - - - 3.11.0RC1 - 3.11.0 - - - beta - beta - - 2019-11-15 - - BSD-3-Clause - GA release. - - - - 3.11.0RC2 - 3.11.0 - - - beta - beta - - 2019-11-21 - - BSD-3-Clause - GA release. - - - - 3.11.0 - 3.11.0 - - - stable - stable - - 2019-11-25 - - BSD-3-Clause - GA release. - - - - 3.11.1 - 3.11.1 - - - stable - stable - - 2019-12-02 - - BSD-3-Clause - GA release. - - - - 3.11.2 - 3.11.2 - - - stable - stable - - 2019-12-10 - - BSD-3-Clause - GA release. - - - - 3.11.3 - 3.11.3 - - - stable - stable - - 2020-01-28 - - BSD-3-Clause - GA release. - - - - 3.11.4 - 3.11.4 - - - stable - stable - - 2020-02-12 - - BSD-3-Clause - GA release. - - - - 3.12.0RC1 - 3.12.0 - - - beta - beta - - 2020-04-30 - - BSD-3-Clause - GA release. - - - - 3.12.0RC2 - 3.12.0 - - - beta - beta - - 2020-05-12 - - BSD-3-Clause - GA release. - - - - 3.12.0 - 3.12.0 - - - stable - stable - - 2020-05-15 - - BSD-3-Clause - GA release. - - - - 3.12.1 - 3.12.1 - - - stable - stable - - 2020-05-20 - - BSD-3-Clause - GA release. - - - - 3.12.2 - 3.12.2 - - - stable - stable - - 2020-05-26 - - BSD-3-Clause - GA release. - - - - 3.12.3 - 3.12.3 - - - stable - stable - - 2020-06-01 - - BSD-3-Clause - GA release. - - - - 3.13.0RC1 - 3.13.0 - - - beta - beta - - 2020-08-05 - - BSD-3-Clause - GA release. - - - - 3.13.0RC2 - 3.13.0 - - - beta - beta - - 2020-08-05 - - BSD-3-Clause - GA release. - - - - 3.13.0RC3 - 3.13.0 - - - beta - beta - - 2020-08-12 - - BSD-3-Clause - GA release. - - - - 3.13.0 - 3.13.0 - - - stable - stable - - 2020-08-14 - - BSD-3-Clause - GA release. - - - - 3.13.0.1 - 3.13.0.1 - - - stable - stable - - 2020-10-08 - - BSD-3-Clause - GA release. - - - - 3.14.0RC1 - 3.14.0 - - - beta - beta - - 2020-11-05 - - BSD-3-Clause - - - - - - 3.14.0RC2 - 3.14.0 - - - beta - beta - - 2020-11-10 - - BSD-3-Clause - - - - - - 3.14.0RC3 - 3.14.0 - - - beta - beta - - 2020-11-11 - - BSD-3-Clause - - - - - - 3.14.0 - 3.14.0 - - - stable - stable - - 2020-11-12 - - BSD-3-Clause - - - - - - 3.15.0RC1 - 3.15.0 - - - beta - beta - - 2021-02-05 - - BSD-3-Clause - - - - - - 3.15.0RC2 - 3.15.0 - - - beta - beta - - 2021-02-17 - - BSD-3-Clause - - - - - - 3.15.0 - 3.15.0 - - - stable - stable - - 2021-02-18 - - BSD-3-Clause - - - - - - 3.15.1 - 3.15.1 - - - stable - stable - - 2021-02-19 - - BSD-3-Clause - - - - - - 3.15.2 - 3.15.2 - - - stable - stable - - 2021-02-23 - - BSD-3-Clause - - - - - - 3.15.3 - 3.15.3 - - - stable - stable - - 2021-02-24 - - BSD-3-Clause - - - - - - 3.15.4 - 3.15.4 - - - stable - stable - - 2021-03-02 - - BSD-3-Clause - - - - - - 3.15.5 - 3.15.5 - - - stable - stable - - 2021-03-04 - - BSD-3-Clause - - - - - - 3.15.6 - 3.15.6 - - - stable - stable - - 2021-03-10 - - BSD-3-Clause - - - - - - 3.15.7 - 3.15.7 - - - stable - stable - - 2021-04-02 - - BSD-3-Clause - - - - - - 3.16.0RC1 - 3.16.0 - - - beta - beta - - 2021-04-02 - - BSD-3-Clause - - - - - - 3.16.0RC2 - 3.16.0 - - - beta - beta - - 2021-05-03 - - BSD-3-Clause - - - - - - 3.16.0 - 3.16.0 - - - stable - stable - - 2021-05-05 - - BSD-3-Clause - - - - - - 3.17.0RC1 - 3.17.0 - - - beta - beta - - 2021-05-06 - - BSD-3-Clause - - - - - - 3.17.0RC2 - 3.17.0 - - - beta - beta - - 2021-05-07 - - BSD-3-Clause - - - - - - 3.17.0 - 3.17.0 - - - stable - stable - - 2021-05-11 - - BSD-3-Clause - - - - - - 3.17.1 - 3.17.1 - - - stable - stable - - 2021-05-19 - - BSD-3-Clause - - * Fixed PHP memory leaks and arginfo errors. (#8614) - * Fixed JSON parser to allow multiple values from the same oneof as long as - all but one are null. - - - - - 3.17.2 - 3.17.2 - - - stable - stable - - 2021-05-25 - - BSD-3-Clause - - - - - - 3.17.3 - 3.17.3 - - - stable - stable - - 2021-06-04 - - BSD-3-Clause - - - - - - 3.18.0RC1 - 3.18.0 - - - beta - beta - - 2021-08-18 - - BSD-3-Clause - - - - - - 3.18.0RC2 - 3.18.0 - - - beta - beta - - 2021-08-27 - - BSD-3-Clause - - - - - - 3.18.0 - 3.18.0 - - - stable - stable - - 2021-09-13 - - BSD-3-Clause - - - - - - 3.18.1 - 3.18.1 - - - stable - stable - - 2021-10-04 - - BSD-3-Clause - - - - - - 3.19.0RC1 - 3.19.0 - - - beta - beta - - 2021-10-15 - - BSD-3-Clause - - - - - - 3.19.0RC2 - 3.19.0 - - - beta - beta - - 2021-10-18 - - BSD-3-Clause - - - - - - 3.19.0 - 3.19.0 - - - stable - stable - - 2021-10-19 - - BSD-3-Clause - - - - - - 3.19.1 - 3.19.1 - - - stable - stable - - 2021-10-28 - - BSD-3-Clause - - - - - - 3.19.2 - 3.19.2 - - - stable - stable - - 2022-01-05 - - BSD-3-Clause - - - - - - 3.19.3 - 3.19.3 - - - stable - stable - - 2022-01-11 - - BSD-3-Clause - - - - - - 3.19.4 - 3.19.4 - - - stable - stable - - 2022-01-28 - - 3-Clause BSD License - - - - - - 3.20.0RC1 - 3.20.0 - - - beta - beta - - 2022-03-04 - - BSD-3-Clause - - - - - - 3.20.0RC2 - 3.20.0 - - - beta - beta - - 2022-03-15 - - BSD-3-Clause - - - - - - 3.20.0 - 3.20.0 - - - stable - stable - - 2022-03-25 - - BSD-3-Clause - - - - - - 3.20.1RC1 - 3.20.1 - - - beta - beta - - 2022-04-05 - - BSD-3-Clause - - - - - - 3.20.1 - 3.20.1 - - - stable - stable - - 2022-04-20 - - BSD-3-Clause - - - - - - 3.21.0RC1 - 3.21.0 - - - beta - beta - - 2022-05-10 - - BSD-3-Clause - - - - - - 3.21.0RC2 - 3.21.0 - - - beta - beta - - 2022-05-19 - - BSD-3-Clause - - - - - - 3.21.0 - 3.21.0 - - - stable - stable - - 2022-05-25 - - BSD-3-Clause - - - - - - 3.21.1 - 3.21.1 - - - stable - stable - - 2022-05-27 - - BSD-3-Clause - - - - - - 3.21.2 - 3.21.2 - - - stable - stable - - 2022-06-23 - - BSD-3-Clause - - - - - - 3.21.3 - 3.21.3 - - - stable - stable - - 2022-07-21 - - BSD-3-Clause - - - - - - 3.21.4 - 3.21.4 - - - stable - stable - - 2022-07-25 - - BSD-3-Clause - - - - - - 3.21.5 - 3.21.5 - - - stable - stable - - 2022-08-09 - - BSD-3-Clause - - - - - - 3.21.6 - 3.21.6 - - - stable - stable - - 2022-09-13 - - BSD-3-Clause - - - - - - 3.21.7 - 3.21.7 - - - stable - stable - - 2022-09-29 - - BSD-3-Clause - - - - - - 3.21.8 - 3.21.8 - - - stable - stable - - 2022-10-13 - - BSD-3-Clause - - - - - diff --git a/libs/protobuf/php/ext/google/protobuf/php-upb.c b/libs/protobuf/php/ext/google/protobuf/php-upb.c index 0116c27..7ccb946 100644 --- a/libs/protobuf/php/ext/google/protobuf/php-upb.c +++ b/libs/protobuf/php/ext/google/protobuf/php-upb.c @@ -1,5 +1,31 @@ /* Amalgamated source file */ #include "php-upb.h" +/* + * Copyright (c) 2009-2021, Google LLC + * All rights reserved. + * + * 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 LLC 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 Google LLC 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 is where we define macros used across upb. @@ -30,20 +56,8 @@ #error upb requires C99 or C++11 or MSVC >= 2015. #endif -// Portable check for GCC minimum version: -// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define UPB_GNUC_MIN(x, y) \ - (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) -#else -#define UPB_GNUC_MIN(x, y) 0 -#endif - -#include -#include -#include -#include #include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -82,16 +96,16 @@ #define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) -/* Hints to the compiler about likely/unlikely branches. */ +// Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) -#define UPB_LIKELY(x) __builtin_expect((x),1) -#define UPB_UNLIKELY(x) __builtin_expect((x),0) +#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) +#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) #else #define UPB_LIKELY(x) (x) #define UPB_UNLIKELY(x) (x) #endif -/* Macros for function attributes on compilers that support them. */ +// Macros for function attributes on compilers that support them. #ifdef __GNUC__ #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) #define UPB_NOINLINE __attribute__((noinline)) @@ -114,8 +128,7 @@ #define UPB_UNUSED(var) (void)var -/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. - */ +// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. #ifdef NDEBUG #ifdef __GNUC__ #define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable() @@ -217,11 +230,7 @@ #undef UPB_FASTTABLE_SUPPORTED -/* ASAN poisoning (for arena). - * If using UPB from an interpreted language like Ruby, a build of the - * interpreter compiled with ASAN enabled must be used in order to get sane and - * expected behavior. - */ +/* ASAN poisoning (for arena) *************************************************/ #if defined(__SANITIZE_ADDRESS__) #define UPB_ASAN 1 @@ -253,127 +262,10 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0 #endif -#if defined(__cplusplus) -#if defined(__clang__) || UPB_GNUC_MIN(6, 0) -// https://gcc.gnu.org/gcc-6/changes.html -#if __cplusplus >= 201402L -#define UPB_DEPRECATED [[deprecated]] -#else -#define UPB_DEPRECATED __attribute__((deprecated)) -#endif -#else -#define UPB_DEPRECATED -#endif -#else -#define UPB_DEPRECATED -#endif - +/** upb/collections.c ************************************************************/ #include -// Must be last. - -bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { - size_t new_capacity = UPB_MAX(arr->capacity, 4); - int elem_size_lg2 = arr->data & 7; - size_t old_bytes = arr->capacity << elem_size_lg2; - size_t new_bytes; - void* ptr = _upb_array_ptr(arr); - - /* Log2 ceiling of size. */ - while (new_capacity < min_capacity) new_capacity *= 2; - - new_bytes = new_capacity << elem_size_lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - - if (!ptr) { - return false; - } - - arr->data = _upb_tag_arrptr(ptr, elem_size_lg2); - arr->capacity = new_capacity; - return true; -} - -static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2, - upb_Arena* arena) { - upb_Array* arr = *arr_ptr; - if (!arr) { - arr = _upb_Array_New(arena, 4, elem_size_lg2); - if (!arr) return NULL; - *arr_ptr = arr; - } - return arr; -} - -void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, - int elem_size_lg2, upb_Arena* arena) { - upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); - return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr) - : NULL; -} - -bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, - int elem_size_lg2, upb_Arena* arena) { - upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); - if (!arr) return false; - - size_t elems = arr->size; - - if (!_upb_Array_Resize(arr, elems + 1, arena)) { - return false; - } - - char* data = _upb_array_ptr(arr); - memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2); - return true; -} - - -// Must be last. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; -} - -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; - - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } - - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } - - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; -} - - -#include - - -// Must be last. /* Strings/bytes are special-cased in maps. */ static char _upb_CTypeo_mapsize[12] = { @@ -391,6 +283,90 @@ static char _upb_CTypeo_mapsize[12] = { 0, /* kUpb_CType_Bytes */ }; +static const char _upb_CTypeo_sizelg2[12] = { + 0, + 0, /* kUpb_CType_Bool */ + 2, /* kUpb_CType_Float */ + 2, /* kUpb_CType_Int32 */ + 2, /* kUpb_CType_UInt32 */ + 2, /* kUpb_CType_Enum */ + UPB_SIZE(2, 3), /* kUpb_CType_Message */ + 3, /* kUpb_CType_Double */ + 3, /* kUpb_CType_Int64 */ + 3, /* kUpb_CType_UInt64 */ + UPB_SIZE(3, 4), /* kUpb_CType_String */ + UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ +}; + +/** upb_Array *****************************************************************/ + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); +} + +size_t upb_Array_Size(const upb_Array* arr) { return arr->len; } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + if (!upb_Array_Resize(arr, arr->len + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->len - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(i <= arr->len); + UPB_ASSERT(count + arr->len >= count); + size_t oldsize = arr->len; + if (!upb_Array_Resize(arr, arr->len + count, arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->len + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->len); + upb_Array_Move(arr, i, end, arr->len - end); + arr->len -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + return _upb_Array_Resize(arr, size, arena); +} + +/** upb_Map *******************************************************************/ + upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { return _upb_Map_New(a, _upb_CTypeo_mapsize[key_type], _upb_CTypeo_mapsize[value_type]); @@ -448,7 +424,8 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { /* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue * value); */ -/* This file was generated by upbc (the upb compiler) from the input + +/** bazel-out/k8-fastbuild/bin/external/com_google_protobuf/google/protobuf/descriptor.upb.c ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: * * google/protobuf/descriptor.proto @@ -460,29 +437,29 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { - {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FileDescriptorProto_msginit}, }; static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { +const upb_MiniTable google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FileOptions_msg_init}, - {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_ServiceDescriptorProto_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_FileOptions_msginit}, + {.submsg = &google_protobuf_SourceCodeInfo_msginit}, }; -static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { +static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[12] = { {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(20, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, @@ -495,24 +472,23 @@ static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] {10, UPB_SIZE(48, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, {11, UPB_SIZE(52, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, + UPB_SIZE(64, 128), 12, kUpb_ExtMode_NonExtendable, 12, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_MessageOptions_msg_init}, - {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_MessageOptions_msginit}, + {.submsg = &google_protobuf_OneofDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msginit}, }; static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { @@ -528,14 +504,14 @@ static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { {10, UPB_SIZE(44, 88), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], UPB_SIZE(48, 96), 10, kUpb_ExtMode_NonExtendable, 10, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { - {.submsg = &google_protobuf_ExtensionRangeOptions_msg_init}, + {.submsg = &google_protobuf_ExtensionRangeOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { @@ -544,7 +520,7 @@ static const upb_MiniTable_Field google_protobuf_DescriptorProto_ExtensionRange_ {3, UPB_SIZE(12, 16), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], UPB_SIZE(16, 24), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, @@ -555,30 +531,30 @@ static const upb_MiniTable_Field google_protobuf_DescriptorProto_ReservedRange__ {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], UPB_SIZE(16, 16), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ExtensionRangeOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_ExtensionRangeOptions__fields[1] = { {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init = { +const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FieldDescriptorProto_submsgs[3] = { - {.subenum = &google_protobuf_FieldDescriptorProto_Label_enum_init}, - {.subenum = &google_protobuf_FieldDescriptorProto_Type_enum_init}, - {.submsg = &google_protobuf_FieldOptions_msg_init}, + {.subenum = &google_protobuf_FieldDescriptorProto_Label_enuminit}, + {.subenum = &google_protobuf_FieldDescriptorProto_Type_enuminit}, + {.submsg = &google_protobuf_FieldOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_FieldDescriptorProto__fields[11] = { @@ -595,14 +571,14 @@ static const upb_MiniTable_Field google_protobuf_FieldDescriptorProto__fields[11 {17, UPB_SIZE(20, 20), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], UPB_SIZE(72, 112), 11, kUpb_ExtMode_NonExtendable, 10, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_OneofDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_OneofOptions_msg_init}, + {.submsg = &google_protobuf_OneofOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_OneofDescriptorProto__fields[2] = { @@ -610,16 +586,16 @@ static const upb_MiniTable_Field google_protobuf_OneofDescriptorProto__fields[2] {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], UPB_SIZE(16, 32), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumDescriptorProto_submsgs[3] = { - {.submsg = &google_protobuf_EnumValueDescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumOptions_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init}, + {.submsg = &google_protobuf_EnumValueDescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumOptions_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto__fields[5] = { @@ -630,7 +606,7 @@ static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto__fields[5] {5, UPB_SIZE(24, 48), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], UPB_SIZE(32, 56), 5, kUpb_ExtMode_NonExtendable, 5, 255, 0, @@ -641,14 +617,14 @@ static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto_EnumReserve {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], UPB_SIZE(16, 16), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumValueDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_EnumValueOptions_msg_init}, + {.submsg = &google_protobuf_EnumValueOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumValueDescriptorProto__fields[3] = { @@ -657,15 +633,15 @@ static const upb_MiniTable_Field google_protobuf_EnumValueDescriptorProto__field {3, UPB_SIZE(16, 24), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ServiceDescriptorProto_submsgs[2] = { - {.submsg = &google_protobuf_MethodDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceOptions_msg_init}, + {.submsg = &google_protobuf_MethodDescriptorProto_msginit}, + {.submsg = &google_protobuf_ServiceOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_ServiceDescriptorProto__fields[3] = { @@ -674,14 +650,14 @@ static const upb_MiniTable_Field google_protobuf_ServiceDescriptorProto__fields[ {3, UPB_SIZE(16, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], UPB_SIZE(24, 40), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MethodDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_MethodOptions_msg_init}, + {.submsg = &google_protobuf_MethodOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_MethodDescriptorProto__fields[6] = { @@ -693,15 +669,15 @@ static const upb_MiniTable_Field google_protobuf_MethodDescriptorProto__fields[6 {6, UPB_SIZE(2, 2), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], UPB_SIZE(32, 64), 6, kUpb_ExtMode_NonExtendable, 6, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FileOptions_submsgs[2] = { - {.subenum = &google_protobuf_FileOptions_OptimizeMode_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_FileOptions_OptimizeMode_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { @@ -728,14 +704,14 @@ static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { {999, UPB_SIZE(100, 184), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileOptions_msg_init = { +const upb_MiniTable google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], UPB_SIZE(104, 192), 21, kUpb_ExtMode_Extendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MessageOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { @@ -746,16 +722,16 @@ static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MessageOptions_msg_init = { +const upb_MiniTable google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], UPB_SIZE(16, 16), 5, kUpb_ExtMode_Extendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FieldOptions_submsgs[3] = { - {.subenum = &google_protobuf_FieldOptions_CType_enum_init}, - {.subenum = &google_protobuf_FieldOptions_JSType_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_FieldOptions_CType_enuminit}, + {.subenum = &google_protobuf_FieldOptions_JSType_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[8] = { @@ -769,28 +745,28 @@ static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[8] = { {999, UPB_SIZE(20, 24), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FieldOptions_msg_init = { +const upb_MiniTable google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], UPB_SIZE(24, 32), 8, kUpb_ExtMode_Extendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_OneofOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_OneofOptions__fields[1] = { {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_OneofOptions_msg_init = { +const upb_MiniTable google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumOptions__fields[3] = { @@ -799,14 +775,14 @@ static const upb_MiniTable_Field google_protobuf_EnumOptions__fields[3] = { {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumOptions_msg_init = { +const upb_MiniTable google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], UPB_SIZE(8, 16), 3, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumValueOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumValueOptions__fields[2] = { @@ -814,14 +790,14 @@ static const upb_MiniTable_Field google_protobuf_EnumValueOptions__fields[2] = { {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumValueOptions_msg_init = { +const upb_MiniTable google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], UPB_SIZE(8, 16), 2, kUpb_ExtMode_Extendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ServiceOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_ServiceOptions__fields[2] = { @@ -829,15 +805,15 @@ static const upb_MiniTable_Field google_protobuf_ServiceOptions__fields[2] = { {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ServiceOptions_msg_init = { +const upb_MiniTable google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], UPB_SIZE(8, 16), 2, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MethodOptions_submsgs[2] = { - {.subenum = &google_protobuf_MethodOptions_IdempotencyLevel_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_MethodOptions_IdempotencyLevel_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_MethodOptions__fields[3] = { @@ -846,14 +822,14 @@ static const upb_MiniTable_Field google_protobuf_MethodOptions__fields[3] = { {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MethodOptions_msg_init = { +const upb_MiniTable google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], UPB_SIZE(16, 16), 3, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_UninterpretedOption_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_NamePart_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_NamePart_msginit}, }; static const upb_MiniTable_Field google_protobuf_UninterpretedOption__fields[7] = { @@ -866,7 +842,7 @@ static const upb_MiniTable_Field google_protobuf_UninterpretedOption__fields[7] {8, UPB_SIZE(24, 48), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_UninterpretedOption_msg_init = { +const upb_MiniTable google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], UPB_SIZE(56, 88), 7, kUpb_ExtMode_NonExtendable, 0, 255, 0, @@ -877,21 +853,21 @@ static const upb_MiniTable_Field google_protobuf_UninterpretedOption_NamePart__f {2, UPB_SIZE(1, 1), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msg_init = { +const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], UPB_SIZE(16, 24), 2, kUpb_ExtMode_NonExtendable, 2, 255, 2, }; static const upb_MiniTable_Sub google_protobuf_SourceCodeInfo_submsgs[1] = { - {.submsg = &google_protobuf_SourceCodeInfo_Location_msg_init}, + {.submsg = &google_protobuf_SourceCodeInfo_Location_msginit}, }; static const upb_MiniTable_Field google_protobuf_SourceCodeInfo__fields[1] = { {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init = { +const upb_MiniTable google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, @@ -905,145 +881,112 @@ static const upb_MiniTable_Field google_protobuf_SourceCodeInfo_Location__fields {6, UPB_SIZE(28, 56), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init = { +const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], UPB_SIZE(32, 64), 5, kUpb_ExtMode_NonExtendable, 4, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_submsgs[1] = { - {.submsg = &google_protobuf_GeneratedCodeInfo_Annotation_msg_init}, + {.submsg = &google_protobuf_GeneratedCodeInfo_Annotation_msginit}, }; static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo__fields[1] = { {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init = { +const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, }; -static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_Annotation_submsgs[1] = { - {.subenum = &google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init}, -}; - -static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[5] = { - {1, UPB_SIZE(16, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { + {1, UPB_SIZE(12, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(4, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {4, UPB_SIZE(8, 8), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(12, 12), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init = { - &google_protobuf_GeneratedCodeInfo_Annotation_submsgs[0], +const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit = { + NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(32, 40), 5, kUpb_ExtMode_NonExtendable, 5, 255, 0, + UPB_SIZE(24, 40), 4, kUpb_ExtMode_NonExtendable, 4, 255, 0, }; static const upb_MiniTable *messages_layout[27] = { - &google_protobuf_FileDescriptorSet_msg_init, - &google_protobuf_FileDescriptorProto_msg_init, - &google_protobuf_DescriptorProto_msg_init, - &google_protobuf_DescriptorProto_ExtensionRange_msg_init, - &google_protobuf_DescriptorProto_ReservedRange_msg_init, - &google_protobuf_ExtensionRangeOptions_msg_init, - &google_protobuf_FieldDescriptorProto_msg_init, - &google_protobuf_OneofDescriptorProto_msg_init, - &google_protobuf_EnumDescriptorProto_msg_init, - &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, - &google_protobuf_EnumValueDescriptorProto_msg_init, - &google_protobuf_ServiceDescriptorProto_msg_init, - &google_protobuf_MethodDescriptorProto_msg_init, - &google_protobuf_FileOptions_msg_init, - &google_protobuf_MessageOptions_msg_init, - &google_protobuf_FieldOptions_msg_init, - &google_protobuf_OneofOptions_msg_init, - &google_protobuf_EnumOptions_msg_init, - &google_protobuf_EnumValueOptions_msg_init, - &google_protobuf_ServiceOptions_msg_init, - &google_protobuf_MethodOptions_msg_init, - &google_protobuf_UninterpretedOption_msg_init, - &google_protobuf_UninterpretedOption_NamePart_msg_init, - &google_protobuf_SourceCodeInfo_msg_init, - &google_protobuf_SourceCodeInfo_Location_msg_init, - &google_protobuf_GeneratedCodeInfo_msg_init, - &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, + &google_protobuf_FileDescriptorSet_msginit, + &google_protobuf_FileDescriptorProto_msginit, + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_DescriptorProto_ExtensionRange_msginit, + &google_protobuf_DescriptorProto_ReservedRange_msginit, + &google_protobuf_ExtensionRangeOptions_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_OneofDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, + &google_protobuf_EnumValueDescriptorProto_msginit, + &google_protobuf_ServiceDescriptorProto_msginit, + &google_protobuf_MethodDescriptorProto_msginit, + &google_protobuf_FileOptions_msginit, + &google_protobuf_MessageOptions_msginit, + &google_protobuf_FieldOptions_msginit, + &google_protobuf_OneofOptions_msginit, + &google_protobuf_EnumOptions_msginit, + &google_protobuf_EnumValueOptions_msginit, + &google_protobuf_ServiceOptions_msginit, + &google_protobuf_MethodOptions_msginit, + &google_protobuf_UninterpretedOption_msginit, + &google_protobuf_UninterpretedOption_NamePart_msginit, + &google_protobuf_SourceCodeInfo_msginit, + &google_protobuf_SourceCodeInfo_Location_msginit, + &google_protobuf_GeneratedCodeInfo_msginit, + &google_protobuf_GeneratedCodeInfo_Annotation_msginit, }; -const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit = { + NULL, + 0x7fffeULL, 0, - { - 0x7fffe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit = { + NULL, + 0xeULL, 0, - { - 0xe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit = { + NULL, + 0xeULL, 0, - { - 0xe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -static const upb_MiniTable_Enum *enums_layout[7] = { - &google_protobuf_FieldDescriptorProto_Type_enum_init, - &google_protobuf_FieldDescriptorProto_Label_enum_init, - &google_protobuf_FileOptions_OptimizeMode_enum_init, - &google_protobuf_FieldOptions_CType_enum_init, - &google_protobuf_FieldOptions_JSType_enum_init, - &google_protobuf_MethodOptions_IdempotencyLevel_enum_init, - &google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init, +static const upb_MiniTable_Enum *enums_layout[6] = { + &google_protobuf_FieldDescriptorProto_Type_enuminit, + &google_protobuf_FieldDescriptorProto_Label_enuminit, + &google_protobuf_FileOptions_OptimizeMode_enuminit, + &google_protobuf_FieldOptions_CType_enuminit, + &google_protobuf_FieldOptions_JSType_enuminit, + &google_protobuf_MethodOptions_IdempotencyLevel_enuminit, }; const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { @@ -1051,12 +994,13 @@ const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { enums_layout, NULL, 27, - 7, + 6, 0, }; -/* This file was generated by upbc (the upb compiler) from the input + +/** bazel-out/k8-fastbuild/bin/external/com_google_protobuf/google/protobuf/descriptor.upbdefs.c ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: * * google/protobuf/descriptor.proto @@ -1065,12 +1009,12 @@ const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { * regenerated. */ -static const char descriptor[7820] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', +static const char descriptor[7667] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n', '\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', -'\004', 'f', 'i', 'l', 'e', '\"', '\376', '\004', '\n', '\023', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', +'\004', 'f', 'i', 'l', 'e', '\"', '\344', '\004', '\n', '\023', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\030', '\n', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '\036', '\n', '\n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\003', ' ', '\003', '(', '\t', 'R', '\n', 'd', 'e', 'p', @@ -1094,290 +1038,284 @@ static const char descriptor[7820] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', ' 's', 'o', 'u', 'r', 'c', 'e', '_', 'c', 'o', 'd', 'e', '_', 'i', 'n', 'f', 'o', '\030', '\t', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', 'R', '\016', 's', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', '\026', '\n', '\006', -'s', 'y', 'n', 't', 'a', 'x', '\030', '\014', ' ', '\001', '(', '\t', 'R', '\006', 's', 'y', 'n', 't', 'a', 'x', '\022', '\030', '\n', '\007', 'e', -'d', 'i', 't', 'i', 'o', 'n', '\030', '\r', ' ', '\001', '(', '\t', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\"', '\271', '\006', '\n', -'\017', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', -'\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ';', '\n', '\005', 'f', 'i', 'e', 'l', 'd', '\030', '\002', ' ', '\003', '(', -'\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', -'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'f', 'i', 'e', 'l', 'd', '\022', 'C', '\n', -'\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\006', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', -'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', -'P', 'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', 'A', '\n', '\013', 'n', 'e', 's', 't', 'e', -'d', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', -'t', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\n', 'n', 'e', -'s', 't', 'e', 'd', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', -'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', -'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', -'\022', 'X', '\n', '\017', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\005', ' ', '\003', '(', '\013', -'2', '/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', -'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'R', -'\016', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', 'D', '\n', '\n', 'o', 'n', 'e', 'o', 'f', '_', -'d', 'e', 'c', 'l', '\030', '\010', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', -'\t', 'o', 'n', 'e', 'o', 'f', 'D', 'e', 'c', 'l', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\007', ' ', '\001', -'(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 's', 's', -'a', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'U', '\n', '\016', 'r', 'e', -'s', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\t', ' ', '\003', '(', '\013', '2', '.', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', -'t', 'o', '.', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', -'d', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\n', -' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', 'z', '\n', '\016', 'E', 'x', 't', -'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', -'\005', 'R', '\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', -'d', '\022', '@', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\032', '7', '\n', '\r', 'R', 'e', 's', 'e', -'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', -'\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', -'|', '\n', '\025', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', -'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', -'\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', -'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', -'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', -'\"', '\301', '\006', '\n', '\024', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', -'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', -'u', 'm', 'b', 'e', 'r', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', 'A', '\n', '\005', 'l', 'a', -'b', 'e', 'l', '\030', '\004', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'L', -'a', 'b', 'e', 'l', 'R', '\005', 'l', 'a', 'b', 'e', 'l', '\022', '>', '\n', '\004', 't', 'y', 'p', 'e', '\030', '\005', ' ', '\001', '(', '\016', -'2', '*', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'T', 'y', 'p', 'e', 'R', '\004', 't', 'y', 'p', 'e', -'\022', '\033', '\n', '\t', 't', 'y', 'p', 'e', '_', 'n', 'a', 'm', 'e', '\030', '\006', ' ', '\001', '(', '\t', 'R', '\010', 't', 'y', 'p', 'e', -'N', 'a', 'm', 'e', '\022', '\032', '\n', '\010', 'e', 'x', 't', 'e', 'n', 'd', 'e', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\010', 'e', -'x', 't', 'e', 'n', 'd', 'e', 'e', '\022', '#', '\n', '\r', 'd', 'e', 'f', 'a', 'u', 'l', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', -'\007', ' ', '\001', '(', '\t', 'R', '\014', 'd', 'e', 'f', 'a', 'u', 'l', 't', 'V', 'a', 'l', 'u', 'e', '\022', '\037', '\n', '\013', 'o', 'n', -'e', 'o', 'f', '_', 'i', 'n', 'd', 'e', 'x', '\030', '\t', ' ', '\001', '(', '\005', 'R', '\n', 'o', 'n', 'e', 'o', 'f', 'I', 'n', 'd', -'e', 'x', '\022', '\033', '\n', '\t', 'j', 's', 'o', 'n', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', '\001', '(', '\t', 'R', '\010', 'j', 's', -'o', 'n', 'N', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\010', ' ', '\001', '(', '\013', '2', '\035', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', -'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '\'', '\n', '\017', 'p', 'r', 'o', 't', 'o', '3', '_', 'o', -'p', 't', 'i', 'o', 'n', 'a', 'l', '\030', '\021', ' ', '\001', '(', '\010', 'R', '\016', 'p', 'r', 'o', 't', 'o', '3', 'O', 'p', 't', 'i', -'o', 'n', 'a', 'l', '\"', '\266', '\002', '\n', '\004', 'T', 'y', 'p', 'e', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'D', 'O', 'U', -'B', 'L', 'E', '\020', '\001', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'F', 'L', 'O', 'A', 'T', '\020', '\002', '\022', '\016', '\n', '\n', -'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '6', '4', '\020', '\003', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', -'6', '4', '\020', '\004', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '3', '2', '\020', '\005', '\022', '\020', '\n', '\014', 'T', -'Y', 'P', 'E', '_', 'F', 'I', 'X', 'E', 'D', '6', '4', '\020', '\006', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'X', -'E', 'D', '3', '2', '\020', '\007', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'B', 'O', 'O', 'L', '\020', '\010', '\022', '\017', '\n', '\013', -'T', 'Y', 'P', 'E', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\t', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'G', 'R', 'O', -'U', 'P', '\020', '\n', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\013', '\022', '\016', '\n', -'\n', 'T', 'Y', 'P', 'E', '_', 'B', 'Y', 'T', 'E', 'S', '\020', '\014', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', -'T', '3', '2', '\020', '\r', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\016', '\022', '\021', '\n', '\r', 'T', -'Y', 'P', 'E', '_', 'S', 'F', 'I', 'X', 'E', 'D', '3', '2', '\020', '\017', '\022', '\021', '\n', '\r', 'T', 'Y', 'P', 'E', '_', 'S', 'F', -'I', 'X', 'E', 'D', '6', '4', '\020', '\020', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '3', '2', '\020', '\021', -'\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '6', '4', '\020', '\022', '\"', 'C', '\n', '\005', 'L', 'a', 'b', 'e', -'l', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', 'O', 'P', 'T', 'I', 'O', 'N', 'A', 'L', '\020', '\001', '\022', '\022', '\n', '\016', -'L', 'A', 'B', 'E', 'L', '_', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\002', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', -'_', 'R', 'E', 'P', 'E', 'A', 'T', 'E', 'D', '\020', '\003', '\"', 'c', '\n', '\024', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', -'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', -'\004', 'n', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\035', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', -'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\343', '\002', '\n', '\023', 'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', -'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', -'R', '\004', 'n', 'a', 'm', 'e', '\022', '?', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', ')', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\022', '6', '\n', '\007', -'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', -'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', -'n', 's', '\022', ']', '\n', '\016', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\004', ' ', '\003', '(', -'\013', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', -'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', -'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', -'\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\005', ' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', -'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', ';', '\n', '\021', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', -'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', 's', 't', 'a', -'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '\203', '\001', '\n', '\030', -'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', +'s', 'y', 'n', 't', 'a', 'x', '\030', '\014', ' ', '\001', '(', '\t', 'R', '\006', 's', 'y', 'n', 't', 'a', 'x', '\"', '\271', '\006', '\n', '\017', +'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', +' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ';', '\n', '\005', 'f', 'i', 'e', 'l', 'd', '\030', '\002', ' ', '\003', '(', '\013', +'2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', +'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'f', 'i', 'e', 'l', 'd', '\022', 'C', '\n', '\t', +'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\006', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', +'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', +'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', 'A', '\n', '\013', 'n', 'e', 's', 't', 'e', 'd', +'_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', +'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\n', 'n', 'e', 's', +'t', 'e', 'd', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', '(', +'\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', +'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022', +'X', '\n', '\017', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\005', ' ', '\003', '(', '\013', '2', +'/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', +'t', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'R', '\016', +'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', 'D', '\n', '\n', 'o', 'n', 'e', 'o', 'f', '_', 'd', +'e', 'c', 'l', '\030', '\010', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\t', +'o', 'n', 'e', 'o', 'f', 'D', 'e', 'c', 'l', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\007', ' ', '\001', '(', +'\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 's', 's', 'a', +'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'U', '\n', '\016', 'r', 'e', 's', +'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\t', ' ', '\003', '(', '\013', '2', '.', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', +'o', '.', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', +'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', +'\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', 'z', '\n', '\016', 'E', 'x', 't', 'e', +'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', +'R', '\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', +'\022', '@', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', +'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\032', '7', '\n', '\r', 'R', 'e', 's', 'e', 'r', +'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', +'s', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '|', +'\n', '\025', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X', +'\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', +' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', +'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', +'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', +'\301', '\006', '\n', '\024', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u', -'m', 'b', 'e', 'r', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', ';', '\n', '\007', 'o', 'p', 't', -'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '!', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', -'i', 'o', 'n', 's', '\"', '\247', '\001', '\n', '\026', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', -'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', -'e', '\022', '>', '\n', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\030', '\002', ' ', '\003', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', -'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', -'s', '\030', '\003', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', -'.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', -'\211', '\002', '\n', '\025', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', -'\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\035', '\n', '\n', 'i', -'n', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\t', 'i', 'n', 'p', 'u', 't', 'T', 'y', 'p', -'e', '\022', '\037', '\n', '\013', 'o', 'u', 't', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\n', 'o', -'u', 't', 'p', 'u', 't', 'T', 'y', 'p', 'e', '\022', '8', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\004', ' ', '\001', '(', -'\013', '2', '\036', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', -'d', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '0', '\n', '\020', 'c', 'l', 'i', 'e', -'n', 't', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', -'e', 'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\221', '\t', '\n', '\013', 'F', 'i', 'l', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', -'\001', ' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', -'a', '_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', -'j', 'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', 'C', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\022', '5', '\n', '\023', 'j', 'a', 'v', -'a', '_', 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', '_', 'f', 'i', 'l', 'e', 's', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', -'a', 'l', 's', 'e', 'R', '\021', 'j', 'a', 'v', 'a', 'M', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'F', 'i', 'l', 'e', 's', '\022', 'D', -'\n', '\035', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'e', 'q', 'u', 'a', 'l', 's', '_', 'a', 'n', -'d', '_', 'h', 'a', 's', 'h', '\030', '\024', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\031', 'j', 'a', 'v', 'a', 'G', 'e', 'n', -'e', 'r', 'a', 't', 'e', 'E', 'q', 'u', 'a', 'l', 's', 'A', 'n', 'd', 'H', 'a', 's', 'h', '\022', ':', '\n', '\026', 'j', 'a', 'v', -'a', '_', 's', 't', 'r', 'i', 'n', 'g', '_', 'c', 'h', 'e', 'c', 'k', '_', 'u', 't', 'f', '8', '\030', '\033', ' ', '\001', '(', '\010', -':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'S', 't', 'r', 'i', 'n', 'g', 'C', 'h', 'e', 'c', 'k', 'U', -'t', 'f', '8', '\022', 'S', '\n', '\014', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', '_', 'f', 'o', 'r', '\030', '\t', ' ', '\001', '(', '\016', -'2', ')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'O', 'p', -'t', 'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', ':', '\005', 'S', 'P', 'E', 'E', 'D', -'R', '\013', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'F', 'o', 'r', '\022', '\035', '\n', '\n', 'g', 'o', '_', 'p', 'a', 'c', 'k', 'a', -'g', 'e', '\030', '\013', ' ', '\001', '(', '\t', 'R', '\t', 'g', 'o', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '5', '\n', '\023', 'c', 'c', -'_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', -'f', 'a', 'l', 's', 'e', 'R', '\021', 'c', 'c', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', -'9', '\n', '\025', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', -'\021', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', -'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', -'r', 'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', -'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', -'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', -'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', -'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', -'e', 'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', -'e', 'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', -'f', 'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', -'x', '\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', -'(', '\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', -'i', 'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', -'e', 'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', -'(', ' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', -'p', 'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', -'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', -'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', -'a', 't', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', -'a', 'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', 'X', '\n', -'\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', -'\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', -'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', -'o', 'd', 'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', -'Z', 'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', -'\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\343', '\002', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', -'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', -'i', 'r', 'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', -'m', 'e', 's', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', -'o', '_', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', -'e', 's', 's', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', -'n', 'd', 'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', -'\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', -'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', -'\030', '\007', ' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', -'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', -'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', -'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', -'\010', '\005', '\020', '\006', 'J', '\004', '\010', '\006', '\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\222', '\004', -'\n', '\014', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', -' ', '\001', '(', '\016', '2', '#', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', -'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', -'\005', 'c', 't', 'y', 'p', 'e', '\022', '\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', -'a', 'c', 'k', 'e', 'd', '\022', 'G', '\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', -'n', 's', '.', 'J', 'S', 'T', 'y', 'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', -'y', 'p', 'e', '\022', '\031', '\n', '\004', 'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', -'\004', 'l', 'a', 'z', 'y', '\022', '.', '\n', '\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', -'\017', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', -'a', 'z', 'y', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', -'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', -'\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', 'X', '\n', '\024', 'u', 'n', -'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', -'2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', -'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', -'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', -'I', 'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', -'_', 'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', -'N', 'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', -'\n', '\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', -'\004', '\010', '\004', '\020', '\005', '\"', 's', '\n', '\014', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X', '\n', '\024', +'m', 'b', 'e', 'r', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', 'A', '\n', '\005', 'l', 'a', 'b', +'e', 'l', '\030', '\004', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'L', 'a', +'b', 'e', 'l', 'R', '\005', 'l', 'a', 'b', 'e', 'l', '\022', '>', '\n', '\004', 't', 'y', 'p', 'e', '\030', '\005', ' ', '\001', '(', '\016', '2', +'*', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', +'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'T', 'y', 'p', 'e', 'R', '\004', 't', 'y', 'p', 'e', '\022', +'\033', '\n', '\t', 't', 'y', 'p', 'e', '_', 'n', 'a', 'm', 'e', '\030', '\006', ' ', '\001', '(', '\t', 'R', '\010', 't', 'y', 'p', 'e', 'N', +'a', 'm', 'e', '\022', '\032', '\n', '\010', 'e', 'x', 't', 'e', 'n', 'd', 'e', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\010', 'e', 'x', +'t', 'e', 'n', 'd', 'e', 'e', '\022', '#', '\n', '\r', 'd', 'e', 'f', 'a', 'u', 'l', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', +' ', '\001', '(', '\t', 'R', '\014', 'd', 'e', 'f', 'a', 'u', 'l', 't', 'V', 'a', 'l', 'u', 'e', '\022', '\037', '\n', '\013', 'o', 'n', 'e', +'o', 'f', '_', 'i', 'n', 'd', 'e', 'x', '\030', '\t', ' ', '\001', '(', '\005', 'R', '\n', 'o', 'n', 'e', 'o', 'f', 'I', 'n', 'd', 'e', +'x', '\022', '\033', '\n', '\t', 'j', 's', 'o', 'n', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', '\001', '(', '\t', 'R', '\010', 'j', 's', 'o', +'n', 'N', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\010', ' ', '\001', '(', '\013', '2', '\035', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', +'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '\'', '\n', '\017', 'p', 'r', 'o', 't', 'o', '3', '_', 'o', 'p', +'t', 'i', 'o', 'n', 'a', 'l', '\030', '\021', ' ', '\001', '(', '\010', 'R', '\016', 'p', 'r', 'o', 't', 'o', '3', 'O', 'p', 't', 'i', 'o', +'n', 'a', 'l', '\"', '\266', '\002', '\n', '\004', 'T', 'y', 'p', 'e', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'D', 'O', 'U', 'B', +'L', 'E', '\020', '\001', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'F', 'L', 'O', 'A', 'T', '\020', '\002', '\022', '\016', '\n', '\n', 'T', +'Y', 'P', 'E', '_', 'I', 'N', 'T', '6', '4', '\020', '\003', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', '6', +'4', '\020', '\004', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '3', '2', '\020', '\005', '\022', '\020', '\n', '\014', 'T', 'Y', +'P', 'E', '_', 'F', 'I', 'X', 'E', 'D', '6', '4', '\020', '\006', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'X', 'E', +'D', '3', '2', '\020', '\007', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'B', 'O', 'O', 'L', '\020', '\010', '\022', '\017', '\n', '\013', 'T', +'Y', 'P', 'E', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\t', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'G', 'R', 'O', 'U', +'P', '\020', '\n', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\013', '\022', '\016', '\n', '\n', +'T', 'Y', 'P', 'E', '_', 'B', 'Y', 'T', 'E', 'S', '\020', '\014', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', +'3', '2', '\020', '\r', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\016', '\022', '\021', '\n', '\r', 'T', 'Y', +'P', 'E', '_', 'S', 'F', 'I', 'X', 'E', 'D', '3', '2', '\020', '\017', '\022', '\021', '\n', '\r', 'T', 'Y', 'P', 'E', '_', 'S', 'F', 'I', +'X', 'E', 'D', '6', '4', '\020', '\020', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '3', '2', '\020', '\021', '\022', +'\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '6', '4', '\020', '\022', '\"', 'C', '\n', '\005', 'L', 'a', 'b', 'e', 'l', +'\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', 'O', 'P', 'T', 'I', 'O', 'N', 'A', 'L', '\020', '\001', '\022', '\022', '\n', '\016', 'L', +'A', 'B', 'E', 'L', '_', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\002', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', +'R', 'E', 'P', 'E', 'A', 'T', 'E', 'D', '\020', '\003', '\"', 'c', '\n', '\024', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', +'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', +'n', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\035', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', +'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\343', '\002', '\n', '\023', 'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', 'r', +'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', +'\004', 'n', 'a', 'm', 'e', '\022', '?', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', ')', '.', 'g', 'o', +'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', +'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\022', '6', '\n', '\007', 'o', +'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', +'t', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', +'s', '\022', ']', '\n', '\016', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\004', ' ', '\003', '(', '\013', +'2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', 'e', +'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', +'d', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', +'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\005', ' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', +'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', ';', '\n', '\021', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', +'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', 's', 't', 'a', 'r', +'t', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '\203', '\001', '\n', '\030', 'E', +'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', +'\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u', 'm', +'b', 'e', 'r', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', ';', '\n', '\007', 'o', 'p', 't', 'i', +'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '!', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', +'o', 'n', 's', '\"', '\247', '\001', '\n', '\026', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', +'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', +'\022', '>', '\n', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\030', '\002', ' ', '\003', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', +'r', 'P', 'r', 'o', 't', 'o', 'R', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', +'\030', '\003', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', +'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\211', +'\002', '\n', '\025', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', +'\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\035', '\n', '\n', 'i', 'n', +'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\t', 'i', 'n', 'p', 'u', 't', 'T', 'y', 'p', 'e', +'\022', '\037', '\n', '\013', 'o', 'u', 't', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\n', 'o', 'u', +'t', 'p', 'u', 't', 'T', 'y', 'p', 'e', '\022', '8', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\004', ' ', '\001', '(', '\013', +'2', '\036', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', +'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '0', '\n', '\020', 'c', 'l', 'i', 'e', 'n', +'t', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', 'e', +'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\221', '\t', '\n', '\013', 'F', 'i', 'l', 'e', +'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\001', +' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', 'a', +'_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', 'j', +'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', 'C', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\022', '5', '\n', '\023', 'j', 'a', 'v', 'a', +'_', 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', '_', 'f', 'i', 'l', 'e', 's', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', +'l', 's', 'e', 'R', '\021', 'j', 'a', 'v', 'a', 'M', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'F', 'i', 'l', 'e', 's', '\022', 'D', '\n', +'\035', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'e', 'q', 'u', 'a', 'l', 's', '_', 'a', 'n', 'd', +'_', 'h', 'a', 's', 'h', '\030', '\024', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\031', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', +'r', 'a', 't', 'e', 'E', 'q', 'u', 'a', 'l', 's', 'A', 'n', 'd', 'H', 'a', 's', 'h', '\022', ':', '\n', '\026', 'j', 'a', 'v', 'a', +'_', 's', 't', 'r', 'i', 'n', 'g', '_', 'c', 'h', 'e', 'c', 'k', '_', 'u', 't', 'f', '8', '\030', '\033', ' ', '\001', '(', '\010', ':', +'\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'S', 't', 'r', 'i', 'n', 'g', 'C', 'h', 'e', 'c', 'k', 'U', 't', +'f', '8', '\022', 'S', '\n', '\014', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', '_', 'f', 'o', 'r', '\030', '\t', ' ', '\001', '(', '\016', '2', +')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'O', 'p', 't', +'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', ':', '\005', 'S', 'P', 'E', 'E', 'D', 'R', +'\013', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'F', 'o', 'r', '\022', '\035', '\n', '\n', 'g', 'o', '_', 'p', 'a', 'c', 'k', 'a', 'g', +'e', '\030', '\013', ' ', '\001', '(', '\t', 'R', '\t', 'g', 'o', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '5', '\n', '\023', 'c', 'c', '_', +'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', 'f', +'a', 'l', 's', 'e', 'R', '\021', 'c', 'c', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '9', +'\n', '\025', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\021', +' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', +'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', +'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', 'n', +'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', 'r', +'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e', +'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', +'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', 'e', +'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', 'e', +'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', +'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', +'\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', '(', +'\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', 'i', +'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', 'e', +'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '(', +' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', 'p', +'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', 'a', +'m', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', 'n', +'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', 'a', +'t', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', 'a', +'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', -'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\300', '\001', -'\n', '\013', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', -'i', 'a', 's', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', +'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', +'d', 'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', 'Z', +'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', '\350', +'\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\343', '\002', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', 'e', +'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', 'i', +'r', 'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', 'm', +'e', 's', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', 'o', +'_', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', 'e', +'s', 's', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', 'n', +'d', 'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', '\n', +'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', +'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', '\030', +'\007', ' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', +'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', +'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', +'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', '\010', +'\005', '\020', '\006', 'J', '\004', '\010', '\006', '\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\222', '\004', '\n', +'\014', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', ' ', +'\001', '(', '\016', '2', '#', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', +'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', '\005', +'c', 't', 'y', 'p', 'e', '\022', '\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', 'a', +'c', 'k', 'e', 'd', '\022', 'G', '\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', 'o', +'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', +'s', '.', 'J', 'S', 'T', 'y', 'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', 'y', +'p', 'e', '\022', '\031', '\n', '\004', 'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', +'l', 'a', 'z', 'y', '\022', '.', '\n', '\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', '\017', +' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', 'a', +'z', 'y', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', +'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', '\030', +'\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', 'X', '\n', '\024', 'u', 'n', 'i', +'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', +'$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', +'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', +'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', 'I', +'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', '_', +'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'N', +'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', '\n', +'\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', +'\010', '\004', '\020', '\005', '\"', 's', '\n', '\014', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X', '\n', '\024', 'u', +'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', +'\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', +'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', +'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\300', '\001', '\n', +'\013', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', 'i', +'a', 's', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', +'d', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', +'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', +'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', +'\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\236', '\001', '\n', '\020', 'E', 'n', 'u', 'm', +'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', +'d', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', +'d', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', +'\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', +'.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', +'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', +'\200', '\002', '\"', '\234', '\001', '\n', '\016', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', +'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', -'*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\236', '\001', '\n', '\020', 'E', 'n', 'u', -'m', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', -'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', -'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', -'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', -'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', -'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', -'\200', '\200', '\002', '\"', '\234', '\001', '\n', '\016', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', -'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', -'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', -'t', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', -'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', -'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\340', '\002', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', -'t', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', -':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', -'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', -'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', -'o', 'n', 's', '.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', -'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', -'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', -'d', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', -'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', -'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', -'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', '\n', '\023', 'I', 'D', -'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', 'N', 'O', -'_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', 'E', 'M', 'P', 'O', -'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', '\023', 'U', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', 'a', 'm', 'e', '\030', -'\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', -'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', 'm', 'e', 'P', 'a', -'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', '_', 'v', 'a', -'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 'V', 'a', 'l', 'u', -'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\004', -' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', -'\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', ' ', '\001', '(', '\003', -'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 'd', 'o', 'u', -'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', 'l', 'e', 'V', 'a', -'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', ' ', '\001', '(', '\014', -'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', -'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', 'V', -'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', 'a', 'm', 'e', '_', -'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '!', '\n', '\014', 'i', -'s', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', 'E', 'x', 't', 'e', -'n', 's', 'i', 'o', 'n', '\"', '\247', '\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', -'D', '\n', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', -'.', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', -'o', 'c', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', -'R', '\004', 'p', 'a', 't', 'h', '\022', '\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', -'\004', 's', 'p', 'a', 'n', '\022', ')', '\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', -'\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', -'\n', '\021', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', -'R', '\020', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', -'d', 'i', 'n', 'g', '_', 'd', 'e', 't', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', -'\003', '(', '\t', 'R', '\027', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', -'n', 't', 's', '\"', '\320', '\002', '\n', '\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', -'\022', 'M', '\n', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', -'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', -'d', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', -'t', 'i', 'o', 'n', '\032', '\353', '\001', '\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', -'t', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', -'r', 'c', 'e', '_', 'f', 'i', 'l', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', -'e', '\022', '\024', '\n', '\005', 'b', 'e', 'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', -'\n', '\003', 'e', 'n', 'd', '\030', '\004', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\022', 'R', '\n', '\010', 's', 'e', 'm', 'a', 'n', -'t', 'i', 'c', '\030', '\005', ' ', '\001', '(', '\016', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', -'t', 'a', 't', 'i', 'o', 'n', '.', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', -'\"', '(', '\n', '\010', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', -'\003', 'S', 'E', 'T', '\020', '\001', '\022', '\t', '\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', -'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', -'.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', -'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', -'.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', +'*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\340', '\002', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', +'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', +'\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', 'e', +'m', 'p', 'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', 'o', +'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', +'n', 's', '.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', 'M', +'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', 'e', +'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', +'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', +'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', 'P', +'\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', '\n', '\023', 'I', 'D', 'E', +'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', 'N', 'O', '_', +'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', 'E', 'M', 'P', 'O', 'T', +'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', '\023', 'U', 'n', 'i', 'n', +'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\002', +' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', +'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', 'm', 'e', 'P', 'a', 'r', +'t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', '_', 'v', 'a', 'l', +'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 'V', 'a', 'l', 'u', 'e', +'\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\004', ' ', +'\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', '\022', +'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', ' ', '\001', '(', '\003', 'R', +'\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 'd', 'o', 'u', 'b', +'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', 'l', 'e', 'V', 'a', 'l', +'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', ' ', '\001', '(', '\014', 'R', +'\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', +'_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', 'V', 'a', +'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', 'a', 'm', 'e', '_', 'p', +'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '!', '\n', '\014', 'i', 's', +'_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', 'E', 'x', 't', 'e', 'n', +'s', 'i', 'o', 'n', '\"', '\247', '\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'D', +'\n', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', +'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', 'o', +'c', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', +'\004', 'p', 'a', 't', 'h', '\022', '\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', +'s', 'p', 'a', 'n', '\022', ')', '\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', +'\003', ' ', '\001', '(', '\t', 'R', '\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', '\n', +'\021', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', 'R', +'\020', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', 'd', +'i', 'n', 'g', '_', 'd', 'e', 't', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', '\003', +'(', '\t', 'R', '\027', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', 'n', +'t', 's', '\"', '\321', '\001', '\n', '\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', +'M', '\n', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', +'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', +'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', +'i', 'o', 'n', '\032', 'm', '\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', +'\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', 'r', 'c', +'e', '_', 'f', 'i', 'l', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', 'e', '\022', +'\024', '\n', '\005', 'b', 'e', 'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', '\n', '\003', +'e', 'n', 'd', '\030', '\004', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', 'g', 'o', 'o', +'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', +'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', '.', 'o', 'r', +'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', +'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', '.', 'P', 'r', +'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', }; static _upb_DefPool_Init *deps[1] = { @@ -1388,73 +1326,10 @@ _upb_DefPool_Init google_protobuf_descriptor_proto_upbdefinit = { deps, &google_protobuf_descriptor_proto_upb_file_layout, "google/protobuf/descriptor.proto", - UPB_STRINGVIEW_INIT(descriptor, 7820) + UPB_STRINGVIEW_INIT(descriptor, 7667) }; - - -// Must be last. - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */ -}; - -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); -} - -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; -} - -bool _upb_extreg_add(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, size_t count) { - char buf[EXTREG_KEY_SIZE]; - const upb_MiniTable_Extension** start = e; - const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - // TODO: we should gracefully handle the case where this already exists. - // Right now we're only checking for out of memory. - const upb_MiniTable_Extension* ext = *e; - extreg_key(buf, ext->extendee, ext->field.number); - if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(ext), r->arena)) { - goto failure; - } - } - return true; - -failure: - /* Back out the entries previously added. */ - for (end = e, e = start; e < end; e++) { - const upb_MiniTable_Extension* ext = *e; - extreg_key(buf, ext->extendee, ext->field.number); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); - } - return false; -} - -const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, - const upb_MiniTable* l, - uint32_t num) { - char buf[EXTREG_KEY_SIZE]; - upb_value v; - extreg_key(buf, l, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); - } else { - return NULL; - } -} - +/** upb/decode_fast.c ************************************************************/ // Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. // Also the table size grows by 2x. // @@ -1467,7 +1342,7 @@ const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, -// Must be last. +/* Must be last. */ #if UPB_FASTTABLE @@ -1483,7 +1358,7 @@ const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, /* Uncomment either of these for debugging purposes. */ \ /* fprintf(stderr, m); */ \ /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); + return fastdecode_generic(d, ptr, msg, table, hasbits, 0); typedef enum { CARD_s = 0, /* Singular (optional, non-repeated) */ @@ -1496,10 +1371,12 @@ UPB_NOINLINE static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { int overrun = data; int status; - ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status); - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, status); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); + if (ptr == NULL) { + return fastdecode_err(d, status); + } + data = fastdecode_loadtag(ptr); + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE @@ -1511,7 +1388,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { *(uint32_t*)msg |= hasbits; // Sync hasbits. const upb_MiniTable* l = decode_totablep(table); return UPB_UNLIKELY(l->required_count) - ? _upb_Decoder_CheckRequired(d, ptr, msg, l) + ? decode_checkrequired(d, ptr, msg, l) : ptr; } else { data = overrun; @@ -1520,8 +1397,8 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { } // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); + data = fastdecode_loadtag(ptr); + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE @@ -1600,9 +1477,9 @@ static const char* fastdecode_delimited(upb_Decoder* d, const char* ptr, // Corrupt wire format: invalid limit. return NULL; } - int delta = _upb_Decoder_PushLimit(d, ptr, len); + int delta = decode_pushlimit(d, ptr, len); ptr = func(d, ptr, ctx); - _upb_Decoder_PopLimit(d, ptr, delta); + decode_poplimit(d, ptr, delta); } else { // Fast case: Sub-message is <128 bytes and fits in the current buffer. // This means we can preserve limit/limit_ptr verbatim. @@ -1642,14 +1519,14 @@ UPB_FORCEINLINE static void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr, int valbytes) { if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_size = farr->arr->capacity; + size_t old_size = farr->arr->size; size_t old_bytes = old_size * valbytes; size_t new_size = old_size * 2; size_t new_bytes = new_size * valbytes; char* old_ptr = _upb_array_ptr(farr->arr); char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - farr->arr->capacity = new_size; + farr->arr->size = new_size; farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2); dst = (void*)(new_ptr + (old_size * valbytes)); farr->end = (void*)(new_ptr + (new_size * valbytes)); @@ -1669,7 +1546,7 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { UPB_FORCEINLINE static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { - farr->arr->size = + farr->arr->len = (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } @@ -1682,8 +1559,8 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, fastdecode_nextret ret; dst = (char*)dst + valbytes; - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (UPB_LIKELY(!decode_isdone(d, ptr))) { + ret.tag = fastdecode_loadtag(*ptr); if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { ret.next = FD_NEXT_SAMEFIELD; } else { @@ -1738,9 +1615,9 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, farr->arr = *arr_p; } begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->capacity * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->size * valbytes); + farr->end = begin + (farr->arr->size * valbytes); + *data = fastdecode_loadtag(ptr); + return begin + (farr->arr->len * valbytes); } default: UPB_UNREACHABLE(); @@ -1826,7 +1703,7 @@ done: \ ptr += tagbytes; \ ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + if (ptr == NULL) return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ val = fastdecode_munge(val, valbytes, zigzag); \ memcpy(dst, &val, valbytes); \ \ @@ -1839,7 +1716,7 @@ done: goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -1861,7 +1738,7 @@ static const char* fastdecode_topackedvarint(upb_Decoder* d, const char* ptr, void* dst = data->dst; uint64_t val; - while (!_upb_Decoder_IsDone(d, &ptr)) { + while (!decode_isdone(d, &ptr)) { dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); ptr = fastdecode_varint64(ptr, &val); if (ptr == NULL) return NULL; @@ -1890,7 +1767,7 @@ static const char* fastdecode_topackedvarint(upb_Decoder* d, const char* ptr, ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ \ if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); @@ -1985,7 +1862,7 @@ TAGBYTES(p) goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -2006,7 +1883,7 @@ TAGBYTES(p) \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr) || \ (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ @@ -2017,7 +1894,7 @@ TAGBYTES(p) if (UPB_LIKELY(!arr)) { \ *arr_p = arr = _upb_Array_New(&d->arena, elems, elem_size_lg2); \ if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ } else { \ _upb_Array_Resize(arr, elems, &d->arena); \ @@ -2025,7 +1902,7 @@ TAGBYTES(p) \ char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ - arr->size = elems; \ + arr->len = elems; \ \ ptr += size; \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); @@ -2083,8 +1960,8 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data) { upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + if (!decode_verifyutf8_inl(dst->data, dst->size)) { + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); } UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } @@ -2098,7 +1975,7 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr))) { \ dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ if (d->options & kUpb_DecodeOption_AliasString) { \ @@ -2107,7 +1984,7 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, } else { \ char* data = upb_Arena_Malloc(&d->arena, size); \ if (!data) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + return fastdecode_err(d, kUpb_DecodeStatus_OutOfMemory); \ } \ memcpy(data, ptr, size); \ dst->data = data; \ @@ -2198,9 +2075,8 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += size; \ \ if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ } \ fastdecode_nextret ret = fastdecode_nextrepeated( \ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ @@ -2210,7 +2086,7 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -2277,9 +2153,8 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += size; \ \ if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ } \ fastdecode_nextret ret = fastdecode_nextrepeated( \ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ @@ -2292,12 +2167,12 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, /* data also. */ \ fastdecode_commitarr(dst, &farr, sizeof(upb_StringView)); \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ } \ goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -2392,7 +2267,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, } \ \ if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + return fastdecode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); \ } \ \ upb_Message** dst; \ @@ -2429,7 +2304,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ \ if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ if (card == CARD_r) { \ @@ -2442,7 +2317,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, case FD_NEXT_OTHERFIELD: \ d->depth++; \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ d->depth++; \ return ptr; \ @@ -2481,17 +2356,19 @@ TAGBYTES(r) #endif /* UPB_FASTTABLE */ +/** upb/json_decode.c ************************************************************/ #include #include #include #include #include +#include #include #include -// Must be last. +/* Special header, must be included last. */ typedef struct { const char *ptr, *end; @@ -2828,20 +2705,44 @@ static uint32_t jsondec_codepoint(jsondec* d) { /* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ static size_t jsondec_unicode(jsondec* d, char* out) { uint32_t cp = jsondec_codepoint(d); - if (upb_Unicode_IsHigh(cp)) { + if (cp >= 0xd800 && cp <= 0xdbff) { /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ + uint32_t high = cp; + uint32_t low; jsondec_parselit(d, "\\u"); - uint32_t low = jsondec_codepoint(d); - if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); - cp = upb_Unicode_FromPair(cp, low); - } else if (upb_Unicode_IsLow(cp)) { + low = jsondec_codepoint(d); + if (low < 0xdc00 || low > 0xdfff) { + jsondec_err(d, "Invalid low surrogate"); + } + cp = (high & 0x3ff) << 10; + cp |= (low & 0x3ff); + cp += 0x10000; + } else if (cp >= 0xdc00 && cp <= 0xdfff) { jsondec_err(d, "Unpaired low surrogate"); } /* Write to UTF-8 */ - int bytes = upb_Unicode_ToUTF8(cp, out); - if (bytes == 0) jsondec_err(d, "Invalid codepoint"); - return bytes; + if (cp <= 0x7f) { + out[0] = cp; + return 1; + } else if (cp <= 0x07FF) { + out[0] = ((cp >> 6) & 0x1F) | 0xC0; + out[1] = ((cp >> 0) & 0x3F) | 0x80; + return 2; + } else if (cp <= 0xFFFF) { + out[0] = ((cp >> 12) & 0x0F) | 0xE0; + out[1] = ((cp >> 6) & 0x3F) | 0x80; + out[2] = ((cp >> 0) & 0x3F) | 0x80; + return 3; + } else if (cp < 0x10FFFF) { + out[0] = ((cp >> 18) & 0x07) | 0xF0; + out[1] = ((cp >> 12) & 0x3f) | 0x80; + out[2] = ((cp >> 6) & 0x3f) | 0x80; + out[3] = ((cp >> 0) & 0x3f) | 0x80; + return 4; + } else { + jsondec_err(d, "Invalid codepoint"); + } } static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { @@ -2887,7 +2788,7 @@ static upb_StringView jsondec_string(jsondec* d) { if (*d->ptr == 'u') { d->ptr++; if (buf_end - end < 4) { - /* Allow space for maximum-sized codepoint (4 bytes). */ + /* Allow space for maximum-sized code point (4 bytes). */ jsondec_resize(d, &buf, &end, &buf_end); } end += jsondec_unicode(d, end); @@ -3060,19 +2961,44 @@ static size_t jsondec_base64(jsondec* d, upb_StringView str) { /* Low-level integer parsing **************************************************/ +/* We use these hand-written routines instead of strto[u]l() because the "long + * long" variants aren't in c89. Also our version allows setting a ptr limit. */ + static const char* jsondec_buftouint64(jsondec* d, const char* ptr, const char* end, uint64_t* val) { - const char* out = upb_BufToUint64(ptr, end, val); - if (!out) jsondec_err(d, "Integer overflow"); - return out; + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + jsondec_err(d, "Integer overflow"); + } + u64 *= 10; + u64 += ch; + ptr++; + } + + *val = u64; + return ptr; } static const char* jsondec_buftoint64(jsondec* d, const char* ptr, - const char* end, int64_t* val, - bool* is_neg) { - const char* out = upb_BufToInt64(ptr, end, val, is_neg); - if (!out) jsondec_err(d, "Integer overflow"); - return out; + const char* end, int64_t* val) { + bool neg = false; + uint64_t u64; + + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } + + ptr = jsondec_buftouint64(d, ptr, end, &u64); + if (u64 > (uint64_t)INT64_MAX + neg) { + jsondec_err(d, "Integer overflow"); + } + + *val = neg ? -u64 : u64; + return ptr; } static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { @@ -3087,7 +3013,7 @@ static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { const char* end = str.data + str.size; int64_t ret; - if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { + if (jsondec_buftoint64(d, str.data, end, &ret) != end) { jsondec_err(d, "Non-number characters in quoted integer"); } return ret; @@ -3194,11 +3120,11 @@ static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { } if (upb_FieldDef_CType(f) == kUpb_CType_Float) { - float f = val.double_val; - if (val.double_val != INFINITY && val.double_val != -INFINITY) { - if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); + if (val.double_val != INFINITY && val.double_val != -INFINITY && + (val.double_val > FLT_MAX || val.double_val < -FLT_MAX)) { + jsondec_err(d, "Float out of range"); } - val.float_val = f; + val.float_val = val.double_val; } return val; @@ -3556,10 +3482,9 @@ static void jsondec_duration(jsondec* d, upb_Message* msg, const char* ptr = str.data; const char* end = ptr + str.size; const int64_t max = (uint64_t)3652500 * 86400; - bool neg = false; /* "3.000000001s", "3s", etc. */ - ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); + ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val); nanos.int32_val = jsondec_nanos(d, &ptr, end); if (end - ptr != 1 || *ptr != 's') { @@ -3570,7 +3495,7 @@ static void jsondec_duration(jsondec* d, upb_Message* msg, jsondec_err(d, "Duration out of range"); } - if (neg) { + if (seconds.int64_val < 0) { nanos.int32_val = -nanos.int32_val; } @@ -3834,11 +3759,8 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { jsondec_objend(d); - upb_EncodeStatus status = - upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, - (char**)&encoded.str_val.data, &encoded.str_val.size); - // TODO(b/235839510): We should fail gracefully here on a bad return status. - UPB_ASSERT(status == kUpb_EncodeStatus_Ok); + encoded.str_val.data = upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, + d->arena, &encoded.str_val.size); upb_Message_Set(msg, value_f, encoded, d->arena); } @@ -3914,17 +3836,19 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, return true; } +/** upb/json_encode.c ************************************************************/ #include #include #include #include +#include #include #include #include -// Must be last. +/* Must be last. */ typedef struct { char *buf, *ptr, *end; @@ -4071,27 +3995,17 @@ static void jsonenc_duration(jsonenc* e, const upb_Message* msg, const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val; int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val; - bool negative = false; if (seconds > 315576000000 || seconds < -315576000000 || - (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { + (seconds < 0) != (nanos < 0)) { jsonenc_err(e, "bad duration"); } - if (seconds < 0) { - negative = true; - seconds = -seconds; - } if (nanos < 0) { - negative = true; nanos = -nanos; } - jsonenc_putstr(e, "\""); - if (negative) { - jsonenc_putstr(e, "-"); - } - jsonenc_printf(e, "%" PRId64, seconds); + jsonenc_printf(e, "\"%" PRId64, seconds); jsonenc_nanos(e, nanos); jsonenc_putstr(e, "s\""); } @@ -4102,10 +4016,7 @@ static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { jsonenc_putstr(e, "null"); } else { - const upb_EnumValueDef* ev = - (e->options & upb_JsonEncode_FormatEnumsAsIntegers) - ? NULL - : upb_EnumDef_FindValueByNumber(e_def, val); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val); if (ev) { jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); @@ -4671,6 +4582,7 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, return jsonenc_nullz(&e, size); } +/** upb/mini_table.c ************************************************************/ #include #include @@ -4958,9 +4870,6 @@ char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, uint32_t delta = val - in->state.enum_state.last_written_value; if (delta >= 5 && in->state.enum_state.present_values_mask) { ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } delta -= 5; } @@ -5029,13 +4938,6 @@ typedef struct { upb_LayoutItemVector vec; upb_Arena* arena; upb_Status* status; - - // When building enums. - upb_MiniTable_Enum* enum_table; - uint32_t enum_value_count; - uint32_t enum_data_count; - uint32_t enum_data_capacity; - jmp_buf err; } upb_MtDecoder; @@ -5077,6 +4979,7 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, char ch = first_ch; while (1) { uint32_t bits = upb_FromBase92(ch) - upb_FromBase92(min); + UPB_ASSERT(shift < 32); val |= bits << shift; if (ptr == d->end || *ptr < min || max < *ptr) { *out_val = val; @@ -5084,7 +4987,6 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, } ch = *ptr++; shift += bits_per_char; - if (shift >= 32) upb_MtDecoder_ErrorFormat(d, "Overlong varint"); } } @@ -5179,15 +5081,11 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, field->mode |= kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift; field->offset = kNoPresence; } else { - if (type >= sizeof(kUpb_EncodedToFieldRep)) { - upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); - UPB_UNREACHABLE(); - } field->mode = kUpb_FieldMode_Scalar; field->mode |= kUpb_EncodedToFieldRep[type] << kUpb_FieldRep_Shift; field->offset = kHasbitPresence; } - if (type >= sizeof(kUpb_EncodedToType)) { + if (type >= 18) { upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); UPB_UNREACHABLE(); } @@ -5381,10 +5279,9 @@ static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, uint32_t sub_count) { upb_MtDecoder_CheckOutOfMemory(d, d->table->subs); } -static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, - size_t len, void* fields, - size_t field_size, uint16_t* field_count, - uint32_t* sub_count) { +static void upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, size_t len, + void* fields, size_t field_size, + uint16_t* field_count, uint32_t* sub_count) { uint64_t msg_modifiers = 0; uint32_t last_field_number = 0; upb_MiniTable_Field* last_field = NULL; @@ -5395,10 +5292,6 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, while (ptr < d->end) { char ch = *ptr++; if (ch <= kUpb_EncodedValue_MaxField) { - if (!d->table && last_field) { - // For extensions, consume only a single field and then return. - return --ptr; - } upb_MiniTable_Field* field = fields; *field_count += 1; fields = (char*)fields + field_size; @@ -5435,8 +5328,6 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, if (need_dense_below) { d->table->dense_below = d->table->field_count; } - - return ptr; } static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, @@ -5533,13 +5424,7 @@ size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); size_t ret = UPB_ALIGN_UP(d->table->size, align); - static const size_t max = UINT16_MAX; - size_t new_size = ret + size; - if (new_size > max) { - upb_MtDecoder_ErrorFormat( - d, "Message size exceeded maximum size of %zu bytes", max); - } - d->table->size = new_size; + d->table->size = ret + size; return ret; } @@ -5631,7 +5516,7 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, done: *buf = decoder.vec.data; - *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); + *buf_size = decoder.vec.capacity / sizeof(*decoder.vec.data); return decoder.table; } @@ -5692,67 +5577,41 @@ upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, return ret; } -static size_t upb_MiniTable_EnumSize(size_t count) { - return sizeof(upb_MiniTable_Enum) + count * sizeof(uint32_t); -} - -static upb_MiniTable_Enum* _upb_MiniTable_AddEnumDataMember(upb_MtDecoder* d, - uint32_t val) { - if (d->enum_data_count == d->enum_data_capacity) { - size_t old_sz = upb_MiniTable_EnumSize(d->enum_data_capacity); - d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); - size_t new_sz = upb_MiniTable_EnumSize(d->enum_data_capacity); - d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); - upb_MtDecoder_CheckOutOfMemory(d, d->enum_table); +static bool upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, + upb_MiniTable_Enum* table, + uint32_t val, upb_Arena* arena) { + if (val < 64) { + table->mask |= 1ULL << val; + return true; } - d->enum_table->data[d->enum_data_count++] = val; - return d->enum_table; -} -static void upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, uint32_t val) { - upb_MiniTable_Enum* table = d->enum_table; - d->enum_value_count++; - if (table->value_count || (val > 512 && d->enum_value_count < val / 32)) { - if (table->value_count == 0) { - assert(d->enum_data_count == table->mask_limit / 32); - } - table = _upb_MiniTable_AddEnumDataMember(d, val); - table->value_count++; - } else { - uint32_t new_mask_limit = ((val / 32) + 1) * 32; - while (table->mask_limit < new_mask_limit) { - table = _upb_MiniTable_AddEnumDataMember(d, 0); - table->mask_limit += 32; - } - table->data[val / 32] |= 1ULL << (val % 32); - } + int32_t* values = (void*)table->values; + values = upb_Arena_Realloc(arena, values, table->value_count * 4, + (table->value_count + 1) * 4); + upb_MtDecoder_CheckOutOfMemory(d, values); + values[table->value_count++] = (int32_t)val; + table->values = values; + return true; } upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, upb_Arena* arena, upb_Status* status) { upb_MtDecoder d = { - .enum_table = upb_Arena_Malloc(arena, upb_MiniTable_EnumSize(2)), - .enum_value_count = 0, - .enum_data_count = 0, - .enum_data_capacity = 1, .status = status, .end = UPB_PTRADD(data, len), - .arena = arena, }; if (UPB_SETJMP(d.err)) { return NULL; } - upb_MtDecoder_CheckOutOfMemory(&d, d.enum_table); + upb_MiniTable_Enum* table = upb_Arena_Malloc(arena, sizeof(*table)); + upb_MtDecoder_CheckOutOfMemory(&d, table); - // Guarantee at least 64 bits of mask without checking mask size. - d.enum_table->mask_limit = 64; - d.enum_table = _upb_MiniTable_AddEnumDataMember(&d, 0); - d.enum_table = _upb_MiniTable_AddEnumDataMember(&d, 0); - - d.enum_table->value_count = 0; + table->mask = 0; + table->value_count = 0; + table->values = NULL; const char* ptr = data; uint32_t base = 0; @@ -5762,7 +5621,11 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, if (ch <= kUpb_EncodedValue_MaxEnumMask) { uint32_t mask = upb_FromBase92(ch); for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTable_BuildEnumValue(&d, base); + if (mask & 1) { + if (!upb_MiniTable_BuildEnumValue(&d, table, base, arena)) { + return NULL; + } + } } } else if (kUpb_EncodedValue_MinSkip <= ch && ch <= kUpb_EncodedValue_MaxSkip) { @@ -5777,14 +5640,12 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, } } - return d.enum_table; + return table; } -const char* upb_MiniTable_BuildExtension(const char* data, size_t len, - upb_MiniTable_Extension* ext, - const upb_MiniTable* extendee, - upb_MiniTable_Sub sub, - upb_Status* status) { +bool upb_MiniTable_BuildExtension(const char* data, size_t len, + upb_MiniTable_Extension* ext, + upb_MiniTable_Sub sub, upb_Status* status) { upb_MtDecoder decoder = { .arena = NULL, .status = status, @@ -5792,32 +5653,14 @@ const char* upb_MiniTable_BuildExtension(const char* data, size_t len, }; if (UPB_SETJMP(decoder.err)) { - return NULL; + return false; } uint16_t count = 0; - const char* ret = - upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL); - if (!ret || count != 1) return NULL; - - upb_MiniTable_Field* f = &ext->field; - - f->mode |= kUpb_LabelFlags_IsExtension; - f->offset = 0; - f->presence = 0; - - if (extendee->ext & kUpb_ExtMode_IsMessageSet) { - // Extensions of MessageSet must be messages. - if (!upb_IsSubMessage(f)) return NULL; - - // Extensions of MessageSet must be non-repeating. - if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL; - } - - ext->extendee = extendee; - ext->sub = sub; - - return ret; + upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL); + ext->field.mode |= kUpb_LabelFlags_IsExtension; + ext->field.offset = 0; + return true; } upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, @@ -5854,11 +5697,21 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, table_sub->subenum = sub; } +/** upb/def.c ************************************************************/ +#include +#include +#include +#include #include -// Must be last. +/* Must be last. */ + +typedef struct { + size_t len; + char str[1]; /* Null-terminated string data follows. */ +} str_t; /* The upb core does not generally have a concept of default instances. However * for descriptor options we make an exception since the max size is known and @@ -5867,9 +5720,282 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, * * We have to allocate an extra pointer for upb's internal metadata. */ static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; +static const char* opt_default = &opt_default_buf[sizeof(void*)]; -const char* _upb_DefBuilder_FullToShort(const char* fullname) { +struct upb_FieldDef { + const google_protobuf_FieldOptions* opts; + const upb_FileDef* file; + const upb_MessageDef* msgdef; + const char* full_name; + const char* json_name; + union { + int64_t sint; + uint64_t uint; + double dbl; + float flt; + bool boolean; + str_t* str; + } defaultval; + union { + const upb_OneofDef* oneof; + const upb_MessageDef* extension_scope; + } scope; + union { + const upb_MessageDef* msgdef; + const upb_EnumDef* enumdef; + const google_protobuf_FieldDescriptorProto* unresolved; + } sub; + uint32_t number_; + uint16_t index_; + uint16_t layout_index; /* Index into msgdef->layout->fields or file->exts */ + bool has_default; + bool is_extension_; + bool packed_; + bool proto3_optional_; + bool has_json_name_; + upb_FieldType type_; + upb_Label label_; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_ExtensionRange { + const google_protobuf_ExtensionRangeOptions* opts; + int32_t start; + int32_t end; +}; + +struct upb_MessageDef { + const google_protobuf_MessageOptions* opts; + const upb_MiniTable* layout; + const upb_FileDef* file; + const upb_MessageDef* containing_type; + const char* full_name; + + /* Tables for looking up fields by number and name. */ + upb_inttable itof; + upb_strtable ntof; + + /* All nested defs. + * MEM: We could save some space here by putting nested defs in a contiguous + * region and calculating counts from offsets or vice-versa. */ + const upb_FieldDef* fields; + const upb_OneofDef* oneofs; + const upb_ExtensionRange* ext_ranges; + const upb_StringView* res_names; + const upb_MessageDef* nested_msgs; + const upb_MessageReservedRange* res_ranges; + const upb_EnumDef* nested_enums; + const upb_FieldDef* nested_exts; + int field_count; + int real_oneof_count; + int oneof_count; + int ext_range_count; + int res_range_count; + int res_name_count; + int nested_msg_count; + int nested_enum_count; + int nested_ext_count; + bool in_message_set; + upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_EnumDef { + const google_protobuf_EnumOptions* opts; + const upb_MiniTable_Enum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_EnumValueDef { + const google_protobuf_EnumValueOptions* opts; + const upb_EnumDef* parent; + const char* full_name; + int32_t number; +}; + +struct upb_OneofDef { + const google_protobuf_OneofOptions* opts; + const upb_MessageDef* parent; + const char* full_name; + int field_count; + bool synthetic; + const upb_FieldDef** fields; + upb_strtable ntof; + upb_inttable itof; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_FileDef { + const google_protobuf_FileOptions* opts; + const char* name; + const char* package; + + const upb_FileDef** deps; + const int32_t* public_deps; + const int32_t* weak_deps; + const upb_MessageDef* top_lvl_msgs; + const upb_EnumDef* top_lvl_enums; + const upb_FieldDef* top_lvl_exts; + const upb_ServiceDef* services; + const upb_MiniTable_Extension** ext_layouts; + const upb_DefPool* symtab; + + int dep_count; + int public_dep_count; + int weak_dep_count; + int top_lvl_msg_count; + int top_lvl_enum_count; + int top_lvl_ext_count; + int service_count; + int ext_count; /* All exts in the file. */ + upb_Syntax syntax; +}; + +struct upb_MethodDef { + const google_protobuf_MethodOptions* opts; + upb_ServiceDef* service; + const char* full_name; + const upb_MessageDef* input_type; + const upb_MessageDef* output_type; + int index; + bool client_streaming; + bool server_streaming; +}; + +struct upb_ServiceDef { + const google_protobuf_ServiceOptions* opts; + const upb_FileDef* file; + const char* full_name; + upb_MethodDef* methods; + int method_count; + int index; +}; + +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; /* full_name -> packed def ptr */ + upb_strtable files; /* file_name -> upb_FileDef* */ + upb_inttable exts; /* upb_MiniTable_Extension* -> upb_FieldDef* */ + upb_ExtensionRegistry* extreg; + size_t bytes_loaded; +}; + +/* Inside a symtab we store tagged pointers to specific def types. */ +typedef enum { + UPB_DEFTYPE_MASK = 7, + + /* Only inside symtab table. */ + UPB_DEFTYPE_EXT = 0, + UPB_DEFTYPE_MSG = 1, + UPB_DEFTYPE_ENUM = 2, + UPB_DEFTYPE_ENUMVAL = 3, + UPB_DEFTYPE_SERVICE = 4, + + /* Only inside message table. */ + UPB_DEFTYPE_FIELD = 0, + UPB_DEFTYPE_ONEOF = 1, + UPB_DEFTYPE_FIELD_JSONNAME = 2, + + /* Only inside file table. */ + UPB_DEFTYPE_FILE = 0, + UPB_DEFTYPE_LAYOUT = 1 +} upb_deftype_t; + +#define FIELD_TYPE_UNSPECIFIED 0 + +struct upb_MessageReservedRange { + int32_t start; + int32_t end; +}; + +struct symtab_addctx { + upb_DefPool* symtab; + upb_FileDef* file; /* File we are building. */ + upb_Arena* arena; /* Allocate defs here. */ + upb_Arena* tmp_arena; /* For temporary allocations. */ + const upb_MiniTable_File* layout; /* NULL if we should build layouts. */ + int enum_count; /* Count of enums built so far. */ + int msg_count; /* Count of messages built so far. */ + int ext_count; /* Count of extensions built so far. */ + upb_Status* status; /* Record errors here. */ + jmp_buf err; /* longjmp() on error. */ +}; + +static upb_deftype_t deftype(upb_value v) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; +} + +static const void* unpack_def(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; +} + +static upb_value pack_def(const void* ptr, upb_deftype_t type) { + // Our 3-bit pointer tagging requires all pointers to be multiples of 8. + // The arena will always yield 8-byte-aligned addresses, however we put + // the defs into arrays. For each element in the array to be 8-byte-aligned, + // the sizes of each def type must also be a multiple of 8. + // + // If any of these asserts fail, we need to add or remove padding on 32-bit + // machines (64-bit machines will have 8-byte alignment already due to + // pointers, which all of these structs have). + UPB_ASSERT((sizeof(upb_FieldDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_MessageDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_EnumDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_EnumValueDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_ServiceDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_OneofDef) & UPB_DEFTYPE_MASK) == 0); + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); +} + +/* isalpha() etc. from are locale-dependent, which we don't want. */ +static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { + return c >= low && c <= high; +} + +static char upb_ascii_lower(char ch) { + // Per ASCII this will lower-case a letter. If the result is a letter, the + // input was definitely a letter. If the output is not a letter, this may + // have transformed the character unpredictably. + return ch | 0x20; +} + +static bool upb_isletter(char c) { + char lower = upb_ascii_lower(c); + return upb_isbetween(lower, 'a', 'z') || c == '_'; +} + +static bool upb_isalphanum(char c) { + return upb_isletter(c) || upb_isbetween(c, '0', '9'); +} + +static const char* shortdefname(const char* fullname) { const char* p; if (fullname == NULL) { @@ -5883,40 +6009,1607 @@ const char* _upb_DefBuilder_FullToShort(const char* fullname) { } } -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } +/* All submessage fields are lower than all other fields. + * Secondly, fields are increasing in order. */ +uint32_t field_rank(const upb_FieldDef* f) { + uint32_t ret = upb_FieldDef_Number(f); + const uint32_t high_bit = 1 << 30; + UPB_ASSERT(ret < high_bit); + if (!upb_FieldDef_IsSubMessage(f)) ret |= high_bit; + return ret; +} -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { +int cmp_fields(const void* p1, const void* p2) { + const upb_FieldDef* f1 = *(upb_FieldDef* const*)p1; + const upb_FieldDef* f2 = *(upb_FieldDef* const*)p2; + return field_rank(f1) - field_rank(f2); +} + +static void upb_Status_setoom(upb_Status* status) { + upb_Status_SetErrorMessage(status, "out of memory"); +} + +static void assign_msg_wellknowntype(upb_MessageDef* m) { + const char* name = upb_MessageDef_FullName(m); + if (name == NULL) { + m->well_known_type = kUpb_WellKnown_Unspecified; + return; + } + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = kUpb_WellKnown_Any; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = kUpb_WellKnown_FieldMask; + } else if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = kUpb_WellKnown_Duration; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = kUpb_WellKnown_Timestamp; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = kUpb_WellKnown_DoubleValue; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = kUpb_WellKnown_FloatValue; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = kUpb_WellKnown_Int64Value; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = kUpb_WellKnown_UInt64Value; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = kUpb_WellKnown_Int32Value; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = kUpb_WellKnown_UInt32Value; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = kUpb_WellKnown_BoolValue; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = kUpb_WellKnown_StringValue; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = kUpb_WellKnown_BytesValue; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = kUpb_WellKnown_Value; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = kUpb_WellKnown_ListValue; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = kUpb_WellKnown_Struct; + } else { + m->well_known_type = kUpb_WellKnown_Unspecified; + } +} + +/* upb_EnumDef ****************************************************************/ + +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; +} + +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)opt_default; +} + +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } + +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return shortdefname(e->full_name); +} + +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } + +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; +} + +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; +} + +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; +} + +/* upb_EnumReservedRange ******************************************************/ + +struct upb_EnumReservedRange { + int32_t start; + int32_t end; +}; + +upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, + int i) { + return (upb_EnumReservedRange*)&r[i]; +} + +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { + return r->start; +} +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { + return r->end; +} + +UPB_NORETURN UPB_NOINLINE UPB_PRINTF(2, 3) static void symtab_errf( + symtab_addctx* ctx, const char* fmt, ...) { va_list argp; va_start(argp, fmt); upb_Status_VSetErrorFormat(ctx->status, fmt, argp); va_end(argp); - _upb_DefBuilder_FailJmp(ctx); + UPB_LONGJMP(ctx->err, 1); } -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); +upb_EnumReservedRange* _upb_EnumReservedRanges_New( + symtab_addctx* ctx, int n, + const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, + const upb_EnumDef* e) { + upb_EnumReservedRange* r = + upb_Arena_Malloc(ctx->arena, sizeof(upb_EnumReservedRange) * n); + + for (int i = 0; i < n; i++) { + const int32_t start = + google_protobuf_EnumDescriptorProto_EnumReservedRange_start(protos[i]); + const int32_t end = + google_protobuf_EnumDescriptorProto_EnumReservedRange_end(protos[i]); + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + + // Note: Not a typo! Unlike extension ranges and message reserved ranges, + // the end value of an enum reserved range is *inclusive*! + if (end < start) { + symtab_errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", + (int)start, (int)end, upb_EnumDef_FullName(e)); + } + + r[i].start = start; + r[i].end = end; + } + + return r; } -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); +} + +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; +} + +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; +} + +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } + +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* def, const char* name, size_t len) { + upb_value v; + return upb_strtable_lookup2(&def->ntoi, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} + +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* def, + int32_t num) { + upb_value v; + return upb_inttable_lookup(&def->iton, num, &v) ? upb_value_getconstptr(v) + : NULL; +} + +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { + // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect + // this to be faster (especially for small numbers). + return upb_MiniTable_Enum_CheckValue(e->layout, num); +} + +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->value_count); + return &e->values[i]; +} + +/* upb_EnumValueDef ***********************************************************/ + +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e) { + return e->opts; +} + +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e) { + return e->opts != (void*)opt_default; +} + +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* ev) { + return ev->parent; +} + +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* ev) { + return ev->full_name; +} + +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* ev) { + return shortdefname(ev->full_name); +} + +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* ev) { + return ev->number; +} + +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* ev) { + // Compute index in our parent's array. + return ev - ev->parent->values; +} + +/* upb_ExtensionRange + * ***************************************************************/ + +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r) { + return r->opts; +} + +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { + return r->opts != (void*)opt_default; +} + +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* e) { + return e->start; +} + +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* e) { return e->end; } + +/* upb_FieldDef ***************************************************************/ + +const google_protobuf_FieldOptions* upb_FieldDef_Options( + const upb_FieldDef* f) { + return f->opts; +} + +bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { + return f->opts != (void*)opt_default; +} + +const char* upb_FieldDef_FullName(const upb_FieldDef* f) { + return f->full_name; +} + +upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { + switch (f->type_) { + case kUpb_FieldType_Double: + return kUpb_CType_Double; + case kUpb_FieldType_Float: + return kUpb_CType_Float; + case kUpb_FieldType_Int64: + case kUpb_FieldType_SInt64: + case kUpb_FieldType_SFixed64: + return kUpb_CType_Int64; + case kUpb_FieldType_Int32: + case kUpb_FieldType_SFixed32: + case kUpb_FieldType_SInt32: + return kUpb_CType_Int32; + case kUpb_FieldType_UInt64: + case kUpb_FieldType_Fixed64: + return kUpb_CType_UInt64; + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Fixed32: + return kUpb_CType_UInt32; + case kUpb_FieldType_Enum: + return kUpb_CType_Enum; + case kUpb_FieldType_Bool: + return kUpb_CType_Bool; + case kUpb_FieldType_String: + return kUpb_CType_String; + case kUpb_FieldType_Bytes: + return kUpb_CType_Bytes; + case kUpb_FieldType_Group: + case kUpb_FieldType_Message: + return kUpb_CType_Message; + } + UPB_UNREACHABLE(); +} + +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } + +uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } + +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } + +uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } + +bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { + return f->is_extension_; +} + +bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->packed_; } + +const char* upb_FieldDef_Name(const upb_FieldDef* f) { + return shortdefname(f->full_name); +} + +const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { + return f->json_name; +} + +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { + return f->has_json_name_; +} + +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } + +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { + return f->msgdef; +} + +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { + return f->is_extension_ ? f->scope.extension_scope : NULL; +} + +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { + return f->is_extension_ ? NULL : f->scope.oneof; +} + +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { + const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); + if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; + return oneof; +} + +upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { + UPB_ASSERT(!upb_FieldDef_IsSubMessage(f)); + upb_MessageValue ret; + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return (upb_MessageValue){.bool_val = f->defaultval.boolean}; + case kUpb_CType_Int64: + return (upb_MessageValue){.int64_val = f->defaultval.sint}; + case kUpb_CType_UInt64: + return (upb_MessageValue){.uint64_val = f->defaultval.uint}; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; + case kUpb_CType_UInt32: + return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; + case kUpb_CType_Float: + return (upb_MessageValue){.float_val = f->defaultval.flt}; + case kUpb_CType_Double: + return (upb_MessageValue){.double_val = f->defaultval.dbl}; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + str_t* str = f->defaultval.str; + if (str) { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = str->str, .size = str->len}}; + } else { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = NULL, .size = 0}}; + } + } + default: + UPB_UNREACHABLE(); + } + + return ret; +} + +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; +} + +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; +} + +const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f) { + UPB_ASSERT(!upb_FieldDef_IsExtension(f)); + return &f->msgdef->layout->fields[f->layout_index]; +} + +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_IsExtension(f)); + return f->file->ext_layouts[f->layout_index]; +} + +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { + return f->proto3_optional_; +} + +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message; +} + +bool upb_FieldDef_IsString(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_String || + upb_FieldDef_CType(f) == kUpb_CType_Bytes; +} + +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Repeated; +} + +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { + return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +} + +bool upb_FieldDef_IsMap(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && + upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); +} + +bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } + +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { + return upb_FieldDef_IsSubMessage(f) || + upb_FieldDef_CType(f) == kUpb_CType_Enum; +} + +bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { + if (upb_FieldDef_IsRepeated(f)) return false; + return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_ContainingOneof(f) || + f->file->syntax == kUpb_Syntax_Proto2; +} + +static bool between(int32_t x, int32_t low, int32_t high) { + return x >= low && x <= high; +} + +bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } +bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } +bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } + +bool upb_FieldDef_checkdescriptortype(int32_t type) { + return between(type, 1, 18); +} + +/* upb_MessageDef + * *****************************************************************/ + +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m) { + return m->opts; +} + +bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { + return m->opts != (void*)opt_default; +} + +const char* upb_MessageDef_FullName(const upb_MessageDef* m) { + return m->full_name; +} + +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { + return m->file; +} + +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { + return m->containing_type; +} + +const char* upb_MessageDef_Name(const upb_MessageDef* m) { + return shortdefname(m->full_name); +} + +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { + return m->file->syntax; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i) { + upb_value val; + return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) + : NULL; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + return unpack_def(val, UPB_DEFTYPE_FIELD); +} + +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + return unpack_def(val, UPB_DEFTYPE_ONEOF); +} + +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** out_f, + const upb_OneofDef** out_o) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return false; + } + + const upb_FieldDef* f = unpack_def(val, UPB_DEFTYPE_FIELD); + const upb_OneofDef* o = unpack_def(val, UPB_DEFTYPE_ONEOF); + if (out_f) *out_f = f; + if (out_o) *out_o = o; + return f || o; /* False if this was a JSON name. */ +} + +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + const upb_FieldDef* f; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + f = unpack_def(val, UPB_DEFTYPE_FIELD); + if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME); + + return f; +} + +int upb_MessageDef_numfields(const upb_MessageDef* m) { return m->field_count; } + +int upb_MessageDef_numoneofs(const upb_MessageDef* m) { return m->oneof_count; } + +int upb_MessageDef_numrealoneofs(const upb_MessageDef* m) { + return m->real_oneof_count; +} + +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { + return m->ext_range_count; +} + +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { + return m->res_range_count; +} + +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { + return m->res_name_count; +} + +int upb_MessageDef_FieldCount(const upb_MessageDef* m) { + return m->field_count; +} + +int upb_MessageDef_OneofCount(const upb_MessageDef* m) { + return m->oneof_count; +} + +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { + return m->nested_msg_count; +} + +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { + return m->nested_enum_count; +} + +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { + return m->nested_ext_count; +} + +int upb_MessageDef_realoneofcount(const upb_MessageDef* m) { + return m->real_oneof_count; +} + +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { + return m->layout; +} + +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->ext_range_count); + return &m->ext_ranges[i]; +} + +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i) { + return (upb_MessageReservedRange*)&r[i]; +} + +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_range_count); + return _upb_MessageReservedRange_At(m->res_ranges, i); +} + +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_name_count); + return m->res_names[i]; +} + +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { + return r->start; +} +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { + return r->end; +} + +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + symtab_addctx* ctx, int n, + const google_protobuf_DescriptorProto_ReservedRange* const* protos, + const upb_MessageDef* m) { + upb_MessageReservedRange* r = + upb_Arena_Malloc(ctx->arena, sizeof(upb_MessageReservedRange) * n); + + for (int i = 0; i < n; i++) { + const int32_t start = google_protobuf_DescriptorProto_ReservedRange_start(protos[i]); + const int32_t end = google_protobuf_DescriptorProto_ReservedRange_end(protos[i]); + const int32_t max = kUpb_MaxFieldNumber + 1; + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + symtab_errf(ctx, + "Reserved range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, upb_MessageDef_FullName(m)); + } + + r[i].start = start; + r[i].end = end; + } + + return r; +} + +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->field_count); + return &m->fields[i]; +} + +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->oneof_count); + return &m->oneofs[i]; +} + +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_msg_count); + return &m->nested_msgs[i]; +} + +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->nested_enum_count); + return &m->nested_enums[i]; +} + +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_ext_count); + return &m->nested_exts[i]; +} + +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { + return m->well_known_type; +} + +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options( + const upb_OneofDef* o) { + return o->opts; +} + +bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { + return o->opts != (void*)opt_default; +} + +const char* upb_OneofDef_Name(const upb_OneofDef* o) { + return shortdefname(o->full_name); +} + +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { + return o->parent; +} + +int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } + +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { + UPB_ASSERT(i < o->field_count); + return o->fields[i]; +} + +int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } + +uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { + // Compute index in our parent's array. + return o - o->parent->oneofs; +} + +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } + +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length) { + upb_value val; + return upb_strtable_lookup2(&o->ntof, name, length, &val) + ? upb_value_getptr(val) + : NULL; +} + +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num) { + upb_value val; + return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) + : NULL; +} + +/* upb_FileDef ****************************************************************/ + +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { + return f->opts; +} + +bool upb_FileDef_HasOptions(const upb_FileDef* f) { + return f->opts != (void*)opt_default; +} + +const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } + +const char* upb_FileDef_Package(const upb_FileDef* f) { + return f->package ? f->package : ""; +} + +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } + +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { + return f->top_lvl_msg_count; +} + +int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } + +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { + return f->public_dep_count; +} + +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { + return f->weak_dep_count; +} + +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { + return f->public_deps; +} + +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { + return f->weak_deps; +} + +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { + return f->top_lvl_enum_count; +} + +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { + return f->top_lvl_ext_count; +} + +int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } + +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->dep_count); + return f->deps[i]; +} + +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->public_deps[i]]; +} + +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->weak_deps[i]]; +} + +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); + return &f->top_lvl_msgs[i]; +} + +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); + return &f->top_lvl_enums[i]; +} + +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); + return &f->top_lvl_exts[i]; +} + +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->service_count); + return &f->services[i]; +} + +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } + +/* upb_MethodDef **************************************************************/ + +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m) { + return m->opts; +} + +bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { + return m->opts != (void*)opt_default; +} + +const char* upb_MethodDef_FullName(const upb_MethodDef* m) { + return m->full_name; +} + +int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } + +const char* upb_MethodDef_Name(const upb_MethodDef* m) { + return shortdefname(m->full_name); +} + +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { + return m->service; +} + +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { + return m->input_type; +} + +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { + return m->output_type; +} + +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { + return m->client_streaming; +} + +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { + return m->server_streaming; +} + +/* upb_ServiceDef *************************************************************/ + +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s) { + return s->opts; +} + +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { + return s->opts != (void*)opt_default; +} + +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { + return s->full_name; +} + +const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { + return shortdefname(s->full_name); +} + +int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } + +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { + return s->file; +} + +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { + return s->method_count; +} + +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { + return i < 0 || i >= s->method_count ? NULL : &s->methods[i]; +} + +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name) { + for (int i = 0; i < s->method_count; i++) { + if (strcmp(name, upb_MethodDef_Name(&s->methods[i])) == 0) { + return &s->methods[i]; + } + } + return NULL; +} + +/* upb_DefPool ****************************************************************/ + +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s); +} + +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + + if (!s) { + return NULL; + } + + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; + + if (!upb_strtable_init(&s->syms, 32, s->arena) || + !upb_strtable_init(&s->files, 4, s->arena) || + !upb_inttable_init(&s->exts, s->arena)) { + goto err; + } + + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; + return s; + +err: + upb_Arena_Free(s->arena); + upb_gfree(s); + return NULL; +} + +static const void* symtab_lookup(const upb_DefPool* s, const char* sym, + upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup(&s->syms, sym, &v) ? unpack_def(v, type) : NULL; +} + +static const void* symtab_lookup2(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup2(&s->syms, sym, size, &v) ? unpack_def(v, type) + : NULL; +} + +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_MSG); +} + +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return symtab_lookup2(s, sym, len, UPB_DEFTYPE_MSG); +} + +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUM); +} + +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUMVAL); +} + +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; +} + +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + + switch (deftype(v)) { + case UPB_DEFTYPE_FIELD: + return unpack_def(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return m->in_message_set ? &m->nested_exts[0] : NULL; + } + default: + break; + } + + return NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} + +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return symtab_lookup(s, name, UPB_DEFTYPE_SERVICE); +} + +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return symtab_lookup2(s, name, size, UPB_DEFTYPE_SERVICE); +} + +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO(haberman): non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (deftype(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = unpack_def(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); + } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); + } + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = unpack_def(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = unpack_def(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); + } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = unpack_def(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); + } + default: + UPB_UNREACHABLE(); + } + } + + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } + + return NULL; +} + +/* Code to build defs from descriptor protos. *********************************/ + +/* There is a question of how much validation to do here. It will be difficult + * to perfectly match the amount of validation performed by proto2. But since + * this code is used to directly build defs from Ruby (for example) we do need + * to validate important constraints like uniqueness of names and numbers. */ + +#define CHK_OOM(x) \ + if (!(x)) { \ + symtab_oomerr(ctx); \ + } + +UPB_NORETURN UPB_NOINLINE static void symtab_oomerr(symtab_addctx* ctx) { + upb_Status_setoom(ctx->status); + UPB_LONGJMP(ctx->err, 1); +} + +void* symtab_alloc(symtab_addctx* ctx, size_t bytes) { + if (bytes == 0) return NULL; + void* ret = upb_Arena_Malloc(ctx->arena, bytes); + if (!ret) symtab_oomerr(ctx); + return ret; +} + +// We want to copy the options verbatim into the destination options proto. +// We use serialize+parse as our deep copy. +#define SET_OPTIONS(target, desc_type, options_type, proto) \ + if (google_protobuf_##desc_type##_has_options(proto)) { \ + size_t size; \ + char* pb = google_protobuf_##options_type##_serialize( \ + google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ + CHK_OOM(pb); \ + target = google_protobuf_##options_type##_parse(pb, size, ctx->arena); \ + CHK_OOM(target); \ + } else { \ + target = (const google_protobuf_##options_type*)opt_default; \ + } + +static void check_ident(symtab_addctx* ctx, upb_StringView name, bool full) { + const char* str = name.data; + size_t len = name.size; + bool start = true; + size_t i; + for (i = 0; i < len; i++) { + char c = str[i]; + if (c == '.') { + if (start || !full) { + symtab_errf(ctx, "invalid name: unexpected '.' (%.*s)", (int)len, str); + } + start = true; + } else if (start) { + if (!upb_isletter(c)) { + symtab_errf( + ctx, + "invalid name: path components must start with a letter (%.*s)", + (int)len, str); + } + start = false; + } else { + if (!upb_isalphanum(c)) { + symtab_errf(ctx, "invalid name: non-alphanumeric character (%.*s)", + (int)len, str); + } + } + } + if (start) { + symtab_errf(ctx, "invalid name: empty part (%.*s)", (int)len, str); + } +} + +static size_t div_round_up(size_t n, size_t d) { return (n + d - 1) / d; } + +static size_t upb_MessageValue_sizeof(upb_CType type) { + switch (type) { + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return 8; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Float: + return 4; + case kUpb_CType_Bool: + return 1; + case kUpb_CType_Message: + return sizeof(void*); + case kUpb_CType_Bytes: + case kUpb_CType_String: + return sizeof(upb_StringView); + } + UPB_UNREACHABLE(); +} + +static uint8_t upb_msg_fielddefsize(const upb_FieldDef* f) { + if (upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f))) { + upb_MapEntry ent; + UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v)); + return sizeof(ent.k); + } else if (upb_FieldDef_IsRepeated(f)) { + return sizeof(void*); + } else { + return upb_MessageValue_sizeof(upb_FieldDef_CType(f)); + } +} + +static uint32_t upb_MiniTable_place(symtab_addctx* ctx, upb_MiniTable* l, + size_t size, const upb_MessageDef* m) { + size_t ofs = UPB_ALIGN_UP(l->size, size); + size_t next = ofs + size; + + if (next > UINT16_MAX) { + symtab_errf(ctx, "size of message %s exceeded max size of %zu bytes", + upb_MessageDef_FullName(m), (size_t)UINT16_MAX); + } + + l->size = next; + return ofs; +} + +static int field_number_cmp(const void* p1, const void* p2) { + const upb_MiniTable_Field* f1 = p1; + const upb_MiniTable_Field* f2 = p2; + return f1->number - f2->number; +} + +static void assign_layout_indices(const upb_MessageDef* m, upb_MiniTable* l, + upb_MiniTable_Field* fields) { + int i; + int n = upb_MessageDef_numfields(m); + int dense_below = 0; + for (i = 0; i < n; i++) { + upb_FieldDef* f = + (upb_FieldDef*)upb_MessageDef_FindFieldByNumber(m, fields[i].number); + UPB_ASSERT(f); + f->layout_index = i; + if (i < UINT8_MAX && fields[i].number == i + 1 && + (i == 0 || fields[i - 1].number == i)) { + dense_below = i + 1; + } + } + l->dense_below = dense_below; +} + +static uint8_t map_descriptortype(const upb_FieldDef* f) { + uint8_t type = upb_FieldDef_Type(f); + /* See TableDescriptorType() in upbc/generator.cc for details and + * rationale of these exceptions. */ + if (type == kUpb_FieldType_String && f->file->syntax == kUpb_Syntax_Proto2) { + return kUpb_FieldType_Bytes; + } else if (type == kUpb_FieldType_Enum && + (f->sub.enumdef->file->syntax == kUpb_Syntax_Proto3 || + UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 || + // TODO(https://github.com/protocolbuffers/upb/issues/541): + // fix map enum values to check for unknown enum values and put + // them in the unknown field set. + upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)))) { + return kUpb_FieldType_Int32; + } + return type; +} + +static void fill_fieldlayout(upb_MiniTable_Field* field, + const upb_FieldDef* f) { + field->number = upb_FieldDef_Number(f); + field->descriptortype = map_descriptortype(f); + + if (upb_FieldDef_IsMap(f)) { + field->mode = + kUpb_FieldMode_Map | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift); + } else if (upb_FieldDef_IsRepeated(f)) { + field->mode = + kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift); + } else { + /* Maps descriptor type -> elem_size_lg2. */ + static const uint8_t sizes[] = { + -1, /* invalid descriptor type */ + kUpb_FieldRep_8Byte, /* DOUBLE */ + kUpb_FieldRep_4Byte, /* FLOAT */ + kUpb_FieldRep_8Byte, /* INT64 */ + kUpb_FieldRep_8Byte, /* UINT64 */ + kUpb_FieldRep_4Byte, /* INT32 */ + kUpb_FieldRep_8Byte, /* FIXED64 */ + kUpb_FieldRep_4Byte, /* FIXED32 */ + kUpb_FieldRep_1Byte, /* BOOL */ + kUpb_FieldRep_StringView, /* STRING */ + kUpb_FieldRep_Pointer, /* GROUP */ + kUpb_FieldRep_Pointer, /* MESSAGE */ + kUpb_FieldRep_StringView, /* BYTES */ + kUpb_FieldRep_4Byte, /* UINT32 */ + kUpb_FieldRep_4Byte, /* ENUM */ + kUpb_FieldRep_4Byte, /* SFIXED32 */ + kUpb_FieldRep_8Byte, /* SFIXED64 */ + kUpb_FieldRep_4Byte, /* SINT32 */ + kUpb_FieldRep_8Byte, /* SINT64 */ + }; + field->mode = kUpb_FieldMode_Scalar | + (sizes[field->descriptortype] << kUpb_FieldRep_Shift); + } + + if (upb_FieldDef_IsPacked(f)) { + field->mode |= kUpb_LabelFlags_IsPacked; + } + + if (upb_FieldDef_IsExtension(f)) { + field->mode |= kUpb_LabelFlags_IsExtension; + } +} + +/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc. + * It computes a dynamic layout for all of the fields in |m|. */ +static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) { + upb_MiniTable* l = (upb_MiniTable*)m->layout; + size_t field_count = upb_MessageDef_numfields(m); + size_t sublayout_count = 0; + upb_MiniTable_Sub* subs; + upb_MiniTable_Field* fields; + + memset(l, 0, sizeof(*l) + sizeof(_upb_FastTable_Entry)); + + /* Count sub-messages. */ + for (size_t i = 0; i < field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + if (upb_FieldDef_IsSubMessage(f)) { + sublayout_count++; + } + if (upb_FieldDef_CType(f) == kUpb_CType_Enum && + f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) { + sublayout_count++; + } + } + + fields = symtab_alloc(ctx, field_count * sizeof(*fields)); + subs = symtab_alloc(ctx, sublayout_count * sizeof(*subs)); + + l->field_count = upb_MessageDef_numfields(m); + l->fields = fields; + l->subs = subs; + l->table_mask = 0; + l->required_count = 0; + + if (upb_MessageDef_ExtensionRangeCount(m) > 0) { + if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + l->ext = kUpb_ExtMode_IsMessageSet; + } else { + l->ext = kUpb_ExtMode_Extendable; + } + } else { + l->ext = kUpb_ExtMode_NonExtendable; + } + + /* TODO(haberman): initialize fast tables so that reflection-based parsing + * can get the same speeds as linked-in types. */ + l->fasttable[0].field_parser = &fastdecode_generic; + l->fasttable[0].field_data = 0; + + if (upb_MessageDef_IsMapEntry(m)) { + /* TODO(haberman): refactor this method so this special case is more + * elegant. */ + const upb_FieldDef* key = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* val = upb_MessageDef_FindFieldByNumber(m, 2); + if (key == NULL || val == NULL) { + symtab_errf(ctx, "Malformed map entry from message: %s", + upb_MessageDef_FullName(m)); + } + fields[0].number = 1; + fields[1].number = 2; + fields[0].mode = kUpb_FieldMode_Scalar; + fields[1].mode = kUpb_FieldMode_Scalar; + fields[0].presence = 0; + fields[1].presence = 0; + fields[0].descriptortype = map_descriptortype(key); + fields[1].descriptortype = map_descriptortype(val); + fields[0].offset = 0; + fields[1].offset = sizeof(upb_StringView); + fields[1].submsg_index = 0; + + if (upb_FieldDef_CType(val) == kUpb_CType_Message) { + subs[0].submsg = upb_FieldDef_MessageSubDef(val)->layout; + } + + upb_FieldDef* fielddefs = (upb_FieldDef*)&m->fields[0]; + UPB_ASSERT(fielddefs[0].number_ == 1); + UPB_ASSERT(fielddefs[1].number_ == 2); + fielddefs[0].layout_index = 0; + fielddefs[1].layout_index = 1; + + l->field_count = 2; + l->size = 2 * sizeof(upb_StringView); + l->size = UPB_ALIGN_UP(l->size, 8); + l->dense_below = 2; + return; + } + + /* Allocate data offsets in three stages: + * + * 1. hasbits. + * 2. regular fields. + * 3. oneof fields. + * + * OPT: There is a lot of room for optimization here to minimize the size. + */ + + /* Assign hasbits for required fields first. */ + size_t hasbit = 0; + + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + field->presence = ++hasbit; + if (hasbit >= 63) { + symtab_errf(ctx, "Message with >=63 required fields: %s", + upb_MessageDef_FullName(m)); + } + l->required_count++; + } + } + + /* Allocate hasbits and set basic field attributes. */ + sublayout_count = 0; + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; + + fill_fieldlayout(field, f); + + if (field->descriptortype == kUpb_FieldType_Message || + field->descriptortype == kUpb_FieldType_Group) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout; + } else if (field->descriptortype == kUpb_FieldType_Enum) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout; + UPB_ASSERT(subs[field->submsg_index].subenum); + } + + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + /* Hasbit was already assigned. */ + } else if (upb_FieldDef_HasPresence(f) && + !upb_FieldDef_RealContainingOneof(f)) { + /* We don't use hasbit 0, so that 0 can indicate "no presence" in the + * table. This wastes one hasbit, but we don't worry about it for now. */ + field->presence = ++hasbit; + } else { + field->presence = 0; + } + } + + /* Account for space used by hasbits. */ + l->size = hasbit ? div_round_up(hasbit + 1, 8) : 0; + + /* Allocate non-oneof fields. */ + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + size_t field_size = upb_msg_fielddefsize(f); + size_t index = upb_FieldDef_Index(f); + + if (upb_FieldDef_RealContainingOneof(f)) { + /* Oneofs are handled separately below. */ + continue; + } + + fields[index].offset = upb_MiniTable_place(ctx, l, field_size, m); + } + + /* Allocate oneof fields. Each oneof field consists of a uint32 for the case + * and space for the actual data. */ + for (int i = 0; i < m->oneof_count; i++) { + const upb_OneofDef* o = &m->oneofs[i]; + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + size_t field_size = 0; + uint32_t case_offset; + uint32_t data_offset; + + if (upb_OneofDef_IsSynthetic(o)) continue; + + if (o->field_count == 0) { + symtab_errf(ctx, "Oneof must have at least one field (%s)", o->full_name); + } + + /* Calculate field size: the max of all field sizes. */ + for (int j = 0; j < o->field_count; j++) { + const upb_FieldDef* f = o->fields[j]; + field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); + } + + /* Align and allocate case offset. */ + case_offset = upb_MiniTable_place(ctx, l, case_size, m); + data_offset = upb_MiniTable_place(ctx, l, field_size, m); + + for (int i = 0; i < o->field_count; i++) { + const upb_FieldDef* f = o->fields[i]; + fields[upb_FieldDef_Index(f)].offset = data_offset; + fields[upb_FieldDef_Index(f)].presence = ~case_offset; + } + } + + /* Size of the entire structure should be a multiple of its greatest + * alignment. TODO: track overall alignment for real? */ + l->size = UPB_ALIGN_UP(l->size, 8); + + /* Sort fields by number. */ + if (fields) { + qsort(fields, upb_MessageDef_numfields(m), sizeof(*fields), + field_number_cmp); + } + assign_layout_indices(m, l, fields); +} + +static char* strviewdup(symtab_addctx* ctx, upb_StringView view) { + char* ret = upb_strdup2(view.data, view.size, ctx->arena); + CHK_OOM(ret); + return ret; +} + +static bool streql2(const char* a, size_t n, const char* b) { + return n == strlen(b) && memcmp(a, b, n) == 0; +} + +static bool streql_view(upb_StringView view, const char* b) { + return streql2(view.data, view.size, b); +} + +static const char* makefullname(symtab_addctx* ctx, const char* prefix, + upb_StringView name) { if (prefix) { - // ret = prefix + '.' + name; + /* ret = prefix + '.' + name; */ size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); + char* ret = symtab_alloc(ctx, n + name.size + 2); strcpy(ret, prefix); ret[n] = '.'; memcpy(&ret[n + 1], name.data, name.size); ret[n + 1 + name.size] = '\0'; return ret; } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; + return strviewdup(ctx, name); } } +static void finalize_oneofs(symtab_addctx* ctx, upb_MessageDef* m) { + int i; + int synthetic_count = 0; + upb_OneofDef* mutable_oneofs = (upb_OneofDef*)m->oneofs; + + for (i = 0; i < m->oneof_count; i++) { + upb_OneofDef* o = &mutable_oneofs[i]; + + if (o->synthetic && o->field_count != 1) { + symtab_errf(ctx, "Synthetic oneofs must have one field, not %d: %s", + o->field_count, upb_OneofDef_Name(o)); + } + + if (o->synthetic) { + synthetic_count++; + } else if (synthetic_count != 0) { + symtab_errf(ctx, "Synthetic oneofs must be after all other oneofs: %s", + upb_OneofDef_Name(o)); + } + + o->fields = symtab_alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); + o->field_count = 0; + } + + for (i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); + if (o) { + o->fields[o->field_count++] = f; + } + } + + m->real_oneof_count = m->oneof_count - synthetic_count; +} + +size_t getjsonname(const char* name, char* buf, size_t len) { + size_t src, dst = 0; + bool ucase_next = false; + +#define WRITE(byte) \ + ++dst; \ + if (dst < len) \ + buf[dst - 1] = byte; \ + else if (dst == len) \ + buf[dst - 1] = '\0' + + if (!name) { + WRITE('\0'); + return 0; + } + + /* Implement the transformation as described in the spec: + * 1. upper case all letters after an underscore. + * 2. remove all underscores. + */ + for (src = 0; name[src]; src++) { + if (name[src] == '_') { + ucase_next = true; + continue; + } + + if (ucase_next) { + WRITE(toupper(name[src])); + ucase_next = false; + } else { + WRITE(name[src]); + } + } + + WRITE('\0'); + return dst; + +#undef WRITE +} + +static char* makejsonname(symtab_addctx* ctx, const char* name) { + size_t size = getjsonname(name, NULL, 0); + char* json_name = symtab_alloc(ctx, size); + getjsonname(name, json_name, size); + return json_name; +} + +/* Adds a symbol |v| to the symtab, which must be a def pointer previously + * packed with pack_def(). The def's pointer to upb_FileDef* must be set before + * adding, so we know which entries to remove if building this file fails. */ +static void symtab_add(symtab_addctx* ctx, const char* name, upb_value v) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup(&ctx->symtab->syms, name, NULL)) { + symtab_errf(ctx, "duplicate symbol '%s'", name); + } + size_t len = strlen(name); + CHK_OOM(upb_strtable_insert(&ctx->symtab->syms, name, len, v, + ctx->symtab->arena)); +} + static bool remove_component(char* base, size_t* len) { if (*len == 0) return false; @@ -5931,16 +7624,19 @@ static bool remove_component(char* base, size_t* len) { return true; } -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { +/* Given a symbol and the base symbol inside which it is defined, find the + * symbol's definition in t. */ +static const void* symtab_resolveany(symtab_addctx* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + const upb_strtable* t = &ctx->symtab->syms; if (sym.size == 0) goto notfound; upb_value v; if (sym.data[0] == '.') { /* Symbols starting with '.' are absolute, so we do a single lookup. * Slice to omit the leading '.' */ - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { + if (!upb_strtable_lookup2(t, sym.data + 1, sym.size - 1, &v)) { goto notfound; } } else { @@ -5956,7 +7652,7 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, } memcpy(p, sym.data, sym.size); p += sym.size; - if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { + if (upb_strtable_lookup2(t, tmp, p - tmp, &v)) { break; } if (!remove_component(tmp, &baselen)) { @@ -5967,58 +7663,78 @@ const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, free(tmp); } - *type = _upb_DefType_Type(v); - return _upb_DefType_Unpack(v, *type); + *type = deftype(v); + return unpack_def(v, *type); notfound: - _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(sym)); + symtab_errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(sym)); } -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type) { +static const void* symtab_resolve(symtab_addctx* ctx, const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t type) { upb_deftype_t found_type; const void* ret = - _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); + symtab_resolveany(ctx, from_name_dbg, base, sym, &found_type); if (ret && found_type != type) { - _upb_DefBuilder_Errf(ctx, - "type mismatch when resolving %s: couldn't find " - "name " UPB_STRINGVIEW_FORMAT " with type=%d", - from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); + symtab_errf(ctx, + "type mismatch when resolving %s: couldn't find " + "name " UPB_STRINGVIEW_FORMAT " with type=%d", + from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); } return ret; } -// Per ASCII this will lower-case a letter. If the result is a letter, the -// input was definitely a letter. If the output is not a letter, this may -// have transformed the character unpredictably. -static char upb_ascii_lower(char ch) { return ch | 0x20; } +static void create_oneofdef( + symtab_addctx* ctx, upb_MessageDef* m, + const google_protobuf_OneofDescriptorProto* oneof_proto, + const upb_OneofDef* _o) { + upb_OneofDef* o = (upb_OneofDef*)_o; + upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); + upb_value v; -// isalpha() etc. from are locale-dependent, which we don't want. -static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { - return low <= c && c <= high; + o->parent = m; + o->full_name = makefullname(ctx, m->full_name, name); + o->field_count = 0; + o->synthetic = false; + + SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + + upb_value existing_v; + if (upb_strtable_lookup2(&m->ntof, name.data, name.size, &existing_v)) { + symtab_errf(ctx, "duplicate oneof name (%s)", o->full_name); + } + + v = pack_def(o, UPB_DEFTYPE_ONEOF); + CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, v, ctx->arena)); + + CHK_OOM(upb_inttable_init(&o->itof, ctx->arena)); + CHK_OOM(upb_strtable_init(&o->ntof, 4, ctx->arena)); } -static bool upb_isletter(char c) { - char lower = upb_ascii_lower(c); - return upb_isbetween(lower, 'a', 'z') || c == '_'; +static str_t* newstr(symtab_addctx* ctx, const char* data, size_t len) { + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); + CHK_OOM(ret); + ret->len = len; + if (len) memcpy(ret->str, data, len); + ret->str[len] = '\0'; + return ret; } -static bool upb_isalphanum(char c) { - return upb_isletter(c) || upb_isbetween(c, '0', '9'); -} - -static bool TryGetChar(const char** src, const char* end, char* ch) { +static bool upb_DefPool_TryGetChar(const char** src, const char* end, + char* ch) { if (*src == end) return false; *ch = **src; *src += 1; return true; } -static char TryGetHexDigit(const char** src, const char* end) { +static char upb_DefPool_TryGetHexDigit(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { char ch; - if (!TryGetChar(src, end, &ch)) return -1; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; if ('0' <= ch && ch <= '9') { return ch - '0'; } @@ -6030,31 +7746,31 @@ static char TryGetHexDigit(const char** src, const char* end) { return -1; } -static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char hex_digit = TryGetHexDigit(src, end); +static char upb_DefPool_ParseHexEscape(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { + char hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end); if (hex_digit < 0) { - _upb_DefBuilder_Errf( - ctx, "\\x cannot be followed by non-hex digit in field '%s' default", - upb_FieldDef_FullName(f)); + symtab_errf(ctx, + "\\x cannot be followed by non-hex digit in field '%s' default", + upb_FieldDef_FullName(f)); return 0; } unsigned int ret = hex_digit; - while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { + while ((hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end)) >= 0) { ret = (ret << 4) | hex_digit; } if (ret > 0xff) { - _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", - upb_FieldDef_FullName(f)); + symtab_errf(ctx, "Value of hex escape in field %s exceeds 8 bits", + upb_FieldDef_FullName(f)); return 0; } return ret; } -static char TryGetOctalDigit(const char** src, const char* end) { +char upb_DefPool_TryGetOctalDigit(const char** src, const char* end) { char ch; - if (!TryGetChar(src, end, &ch)) return -1; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; if ('0' <= ch && ch <= '7') { return ch - '0'; } @@ -6062,25 +7778,25 @@ static char TryGetOctalDigit(const char** src, const char* end) { return -1; } -static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { +static char upb_DefPool_ParseOctalEscape(symtab_addctx* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { char ch = 0; for (int i = 0; i < 3; i++) { char digit; - if ((digit = TryGetOctalDigit(src, end)) >= 0) { + if ((digit = upb_DefPool_TryGetOctalDigit(src, end)) >= 0) { ch = (ch << 3) | digit; } } return ch; } -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end) { +static char upb_DefPool_ParseEscape(symtab_addctx* ctx, const upb_FieldDef* f, + const char** src, const char* end) { char ch; - if (!TryGetChar(src, end, &ch)) { - _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", - upb_FieldDef_FullName(f)); + if (!upb_DefPool_TryGetChar(src, end, &ch)) { + symtab_errf(ctx, "unterminated escape sequence in field %s", + upb_FieldDef_FullName(f)); return 0; } switch (ch) { @@ -6108,7 +7824,7 @@ char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, return '\?'; case 'x': case 'X': - return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); + return upb_DefPool_ParseHexEscape(ctx, f, src, end); case '0': case '1': case '2': @@ -6118,262 +7834,1076 @@ char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, case '6': case '7': *src -= 1; - return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); + return upb_DefPool_ParseOctalEscape(ctx, f, src, end); } - _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); + symtab_errf(ctx, "Unknown escape sequence: \\%c", ch); } -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full) { - const char* str = name.data; - const size_t len = name.size; - bool start = true; - for (size_t i = 0; i < len; i++) { - const char c = str[i]; - if (c == '.') { - if (start || !full) { - _upb_DefBuilder_Errf( - ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = true; - } else if (start) { - if (!upb_isletter(c)) { - _upb_DefBuilder_Errf(ctx, - "invalid name: path components must start with a " - "letter (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = false; - } else if (!upb_isalphanum(c)) { - _upb_DefBuilder_Errf( - ctx, - "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT - ")", - UPB_STRINGVIEW_ARGS(name)); +static str_t* unescape(symtab_addctx* ctx, const upb_FieldDef* f, + const char* data, size_t len) { + // Size here is an upper bound; escape sequences could ultimately shrink it. + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); + char* dst = &ret->str[0]; + const char* src = data; + const char* end = data + len; + + while (src < end) { + if (*src == '\\') { + src++; + *dst++ = upb_DefPool_ParseEscape(ctx, f, &src, end); + } else { + *dst++ = *src++; } } - if (start) { - _upb_DefBuilder_Errf(ctx, - "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - // We should never reach this point. - UPB_ASSERT(false); + ret->len = dst - &ret->str[0]; + return ret; } +static void parse_default(symtab_addctx* ctx, const char* str, size_t len, + upb_FieldDef* f) { + char* end; + char nullz[64]; + errno = 0; - -// Must be last. - -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTable_Extension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; - -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); -} - -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; - - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; - - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; - - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; -} - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, - upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); -} - -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; - } - return true; -} - -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { - upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; -} - -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); -} - -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { - return s->extreg; -} - -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; -} - -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; -} - -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); -} - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); -} - -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); -} - -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); -} - -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; - - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; - } + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + case kUpb_CType_Double: + case kUpb_CType_Float: + /* Standard C number parsing functions expect null-terminated strings. */ + if (len >= sizeof(nullz) - 1) { + symtab_errf(ctx, "Default too long: %.*s", (int)len, str); + } + memcpy(nullz, str, len); + nullz[len] = '\0'; + str = nullz; + break; default: break; } - return NULL; + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: { + long val = strtol(str, &end, 0); + if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_Enum: { + const upb_EnumDef* e = f->sub.enumdef; + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str, len); + if (!ev) { + goto invalid; + } + f->defaultval.sint = ev->number; + break; + } + case kUpb_CType_Int64: { + long long val = strtoll(str, &end, 0); + if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_UInt32: { + unsigned long val = strtoul(str, &end, 0); + if (val > UINT32_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_UInt64: { + unsigned long long val = strtoull(str, &end, 0); + if (val > UINT64_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_Double: { + double val = strtod(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.dbl = val; + break; + } + case kUpb_CType_Float: { + float val = strtof(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.flt = val; + break; + } + case kUpb_CType_Bool: { + if (streql2(str, len, "false")) { + f->defaultval.boolean = false; + } else if (streql2(str, len, "true")) { + f->defaultval.boolean = true; + } else { + goto invalid; + } + break; + } + case kUpb_CType_String: + f->defaultval.str = newstr(ctx, str, len); + break; + case kUpb_CType_Bytes: + f->defaultval.str = unescape(ctx, f, str, len); + break; + case kUpb_CType_Message: + /* Should not have a default value. */ + symtab_errf(ctx, "Message should not have a default (%s)", + upb_FieldDef_FullName(f)); + } + + return; + +invalid: + symtab_errf(ctx, "Invalid default '%.*s' for field %s of type %d", (int)len, + str, upb_FieldDef_FullName(f), (int)upb_FieldDef_Type(f)); } -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +static void set_default_default(symtab_addctx* ctx, upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + f->defaultval.sint = 0; + break; + case kUpb_CType_UInt64: + case kUpb_CType_UInt32: + f->defaultval.uint = 0; + break; + case kUpb_CType_Double: + case kUpb_CType_Float: + f->defaultval.dbl = 0; + break; + case kUpb_CType_String: + case kUpb_CType_Bytes: + f->defaultval.str = newstr(ctx, NULL, 0); + break; + case kUpb_CType_Bool: + f->defaultval.boolean = false; + break; + case kUpb_CType_Enum: + f->defaultval.sint = f->sub.enumdef->values[0].number; + case kUpb_CType_Message: + break; + } } -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} +static void create_fielddef( + symtab_addctx* ctx, const char* prefix, upb_MessageDef* m, + const google_protobuf_FieldDescriptorProto* field_proto, + const upb_FieldDef* _f, bool is_extension) { + upb_FieldDef* f = (upb_FieldDef*)_f; + upb_StringView name; + const char* full_name; + const char* json_name; + const char* shortname; + int32_t field_number; -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} + f->file = ctx->file; /* Must happen prior to symtab_add(). */ -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO(haberman): non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } + if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { + symtab_errf(ctx, "field has no name"); + } + + name = google_protobuf_FieldDescriptorProto_name(field_proto); + check_ident(ctx, name, false); + full_name = makefullname(ctx, prefix, name); + shortname = shortdefname(full_name); + + if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) { + json_name = strviewdup( + ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto)); + f->has_json_name_ = true; + } else { + json_name = makejsonname(ctx, shortname); + f->has_json_name_ = false; + } + + field_number = google_protobuf_FieldDescriptorProto_number(field_proto); + + f->full_name = full_name; + f->json_name = json_name; + f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); + f->number_ = field_number; + f->scope.oneof = NULL; + f->proto3_optional_ = + google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); + + bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); + bool has_type_name = + google_protobuf_FieldDescriptorProto_has_type_name(field_proto); + + f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); + + if (has_type) { + switch (f->type_) { + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + case kUpb_FieldType_Enum: + if (!has_type_name) { + symtab_errf(ctx, "field of type %d requires type name (%s)", + (int)f->type_, full_name); + } + break; default: - UPB_UNREACHABLE(); + if (has_type_name) { + symtab_errf(ctx, "invalid type for field with type_name set (%s, %d)", + full_name, (int)f->type_); + } } + } else if (has_type_name) { + f->type_ = + FIELD_TYPE_UNSPECIFIED; // We'll fill this in in resolve_fielddef(). } - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); + if (!is_extension) { + /* direct message field. */ + upb_value v, field_v, json_v, existing_v; + size_t json_size; + + if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { + symtab_errf(ctx, "invalid field number (%u)", field_number); + } + + f->index_ = f - m->fields; + f->msgdef = m; + f->is_extension_ = false; + + field_v = pack_def(f, UPB_DEFTYPE_FIELD); + json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME); + v = upb_value_constptr(f); + json_size = strlen(json_name); + + if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { + symtab_errf(ctx, "duplicate field name (%s)", shortname); + } + + CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, field_v, + ctx->arena)); + + if (strcmp(shortname, json_name) != 0) { + if (upb_strtable_lookup(&m->ntof, json_name, &v)) { + symtab_errf(ctx, "duplicate json_name (%s)", json_name); + } else { + CHK_OOM(upb_strtable_insert(&m->ntof, json_name, json_size, json_v, + ctx->arena)); } } + + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { + symtab_errf(ctx, "duplicate field number (%u)", field_number); + } + + CHK_OOM(upb_inttable_insert(&m->itof, field_number, v, ctx->arena)); + + if (ctx->layout) { + const upb_MiniTable_Field* fields = m->layout->fields; + int count = m->layout->field_count; + bool found = false; + for (int i = 0; i < count; i++) { + if (fields[i].number == field_number) { + f->layout_index = i; + found = true; + break; + } + } + UPB_ASSERT(found); + } + } else { + /* extension field. */ + f->is_extension_ = true; + f->scope.extension_scope = m; + symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_EXT)); + f->layout_index = ctx->ext_count++; + if (ctx->layout) { + UPB_ASSERT(ctx->file->ext_layouts[f->layout_index]->field.number == + field_number); + } } - return NULL; + if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { + symtab_errf(ctx, "invalid type for field %s (%d)", f->full_name, f->type_); + } + + if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { + symtab_errf(ctx, "invalid label for field %s (%d)", f->full_name, + f->label_); + } + + /* We can't resolve the subdef or (in the case of extensions) the containing + * message yet, because it may not have been defined yet. We stash a pointer + * to the field_proto until later when we can properly resolve it. */ + f->sub.unresolved = field_proto; + + if (f->label_ == kUpb_Label_Required && + f->file->syntax == kUpb_Syntax_Proto3) { + symtab_errf(ctx, "proto3 fields cannot be required (%s)", f->full_name); + } + + if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { + uint32_t oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); + upb_OneofDef* oneof; + upb_value v = upb_value_constptr(f); + + if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { + symtab_errf(ctx, "fields in oneof must have OPTIONAL label (%s)", + f->full_name); + } + + if (!m) { + symtab_errf(ctx, "oneof_index provided for extension field (%s)", + f->full_name); + } + + if (oneof_index >= m->oneof_count) { + symtab_errf(ctx, "oneof_index out of range (%s)", f->full_name); + } + + oneof = (upb_OneofDef*)&m->oneofs[oneof_index]; + f->scope.oneof = oneof; + + oneof->field_count++; + if (f->proto3_optional_) { + oneof->synthetic = true; + } + CHK_OOM(upb_inttable_insert(&oneof->itof, f->number_, v, ctx->arena)); + CHK_OOM( + upb_strtable_insert(&oneof->ntof, name.data, name.size, v, ctx->arena)); + } else { + if (f->proto3_optional_ && !is_extension) { + symtab_errf(ctx, "field with proto3_optional was not in a oneof (%s)", + f->full_name); + } + } + + SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + + if (google_protobuf_FieldOptions_has_packed(f->opts)) { + f->packed_ = google_protobuf_FieldOptions_packed(f->opts); + } else { + /* Repeated fields default to packed for proto3 only. */ + f->packed_ = upb_FieldDef_IsPrimitive(f) && + f->label_ == kUpb_Label_Repeated && + f->file->syntax == kUpb_Syntax_Proto3; + } +} + +static void create_service( + symtab_addctx* ctx, const google_protobuf_ServiceDescriptorProto* svc_proto, + const upb_ServiceDef* _s) { + upb_ServiceDef* s = (upb_ServiceDef*)_s; + upb_StringView name; + const google_protobuf_MethodDescriptorProto* const* methods; + size_t i, n; + + s->file = ctx->file; /* Must happen prior to symtab_add. */ + + name = google_protobuf_ServiceDescriptorProto_name(svc_proto); + check_ident(ctx, name, false); + s->full_name = makefullname(ctx, ctx->file->package, name); + symtab_add(ctx, s->full_name, pack_def(s, UPB_DEFTYPE_SERVICE)); + + methods = google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); + + s->method_count = n; + s->methods = symtab_alloc(ctx, sizeof(*s->methods) * n); + + SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, svc_proto); + + for (i = 0; i < n; i++) { + const google_protobuf_MethodDescriptorProto* method_proto = methods[i]; + upb_MethodDef* m = (upb_MethodDef*)&s->methods[i]; + upb_StringView name = + google_protobuf_MethodDescriptorProto_name(method_proto); + + m->service = s; + m->full_name = makefullname(ctx, s->full_name, name); + m->index = i; + m->client_streaming = + google_protobuf_MethodDescriptorProto_client_streaming(method_proto); + m->server_streaming = + google_protobuf_MethodDescriptorProto_server_streaming(method_proto); + m->input_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_input_type(method_proto), + UPB_DEFTYPE_MSG); + m->output_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_output_type(method_proto), + UPB_DEFTYPE_MSG); + + SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, method_proto); + } +} + +static int count_bits_debug(uint64_t x) { + // For assertions only, speed does not matter. + int n = 0; + while (x) { + if (x & 1) n++; + x >>= 1; + } + return n; +} + +static int compare_int32(const void* a_ptr, const void* b_ptr) { + int32_t a = *(int32_t*)a_ptr; + int32_t b = *(int32_t*)b_ptr; + return a < b ? -1 : (a == b ? 0 : 1); +} + +upb_MiniTable_Enum* create_enumlayout(symtab_addctx* ctx, + const upb_EnumDef* e) { + int n = 0; + uint64_t mask = 0; + + for (int i = 0; i < e->value_count; i++) { + uint32_t val = (uint32_t)e->values[i].number; + if (val < 64) { + mask |= 1ULL << val; + } else { + n++; + } + } + + int32_t* values = symtab_alloc(ctx, sizeof(*values) * n); + + if (n) { + int32_t* p = values; + + // Add values outside the bitmask range to the list, as described in the + // comments for upb_MiniTable_Enum. + for (int i = 0; i < e->value_count; i++) { + int32_t val = e->values[i].number; + if ((uint32_t)val >= 64) { + *p++ = val; + } + } + UPB_ASSERT(p == values + n); + } + + // Enums can have duplicate values; we must sort+uniq them. + if (values) qsort(values, n, sizeof(*values), &compare_int32); + + int dst = 0; + for (int i = 0; i < n; dst++) { + int32_t val = values[i]; + while (i < n && values[i] == val) i++; // Skip duplicates. + values[dst] = val; + } + n = dst; + + UPB_ASSERT(upb_inttable_count(&e->iton) == n + count_bits_debug(mask)); + + upb_MiniTable_Enum* layout = symtab_alloc(ctx, sizeof(*layout)); + layout->value_count = n; + layout->mask = mask; + layout->values = values; + + return layout; +} + +static void create_enumvaldef( + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumValueDescriptorProto* val_proto, upb_EnumDef* e, + int i) { + upb_EnumValueDef* val = (upb_EnumValueDef*)&e->values[i]; + upb_StringView name = + google_protobuf_EnumValueDescriptorProto_name(val_proto); + upb_value v = upb_value_constptr(val); + + val->parent = e; /* Must happen prior to symtab_add(). */ + val->full_name = makefullname(ctx, prefix, name); + val->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); + symtab_add(ctx, val->full_name, pack_def(val, UPB_DEFTYPE_ENUMVAL)); + + SET_OPTIONS(val->opts, EnumValueDescriptorProto, EnumValueOptions, val_proto); + + if (i == 0 && e->file->syntax == kUpb_Syntax_Proto3 && val->number != 0) { + symtab_errf(ctx, "for proto3, the first enum value must be zero (%s)", + e->full_name); + } + + CHK_OOM(upb_strtable_insert(&e->ntoi, name.data, name.size, v, ctx->arena)); + + // Multiple enumerators can have the same number, first one wins. + if (!upb_inttable_lookup(&e->iton, val->number, NULL)) { + CHK_OOM(upb_inttable_insert(&e->iton, val->number, v, ctx->arena)); + } +} + +static upb_StringView* _upb_EnumReservedNames_New( + symtab_addctx* ctx, int n, const upb_StringView* protos) { + upb_StringView* sv = + upb_Arena_Malloc(ctx->arena, sizeof(upb_StringView) * n); + for (size_t i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, ctx->arena); + sv[i].size = protos[i].size; + } + return sv; +} + +static void create_enumdef( + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumDescriptorProto* enum_proto, + const upb_MessageDef* containing_type, const upb_EnumDef* _e) { + upb_EnumDef* e = (upb_EnumDef*)_e; + ; + const google_protobuf_EnumValueDescriptorProto* const* values; + const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* res_ranges; + const upb_StringView* res_names; + upb_StringView name; + size_t i, n, n_res_range, n_res_name; + + e->file = ctx->file; /* Must happen prior to symtab_add() */ + e->containing_type = containing_type; + + name = google_protobuf_EnumDescriptorProto_name(enum_proto); + check_ident(ctx, name, false); + + e->full_name = makefullname(ctx, prefix, name); + symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM)); + + values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n); + CHK_OOM(upb_strtable_init(&e->ntoi, n, ctx->arena)); + CHK_OOM(upb_inttable_init(&e->iton, ctx->arena)); + + e->defaultval = 0; + e->value_count = n; + e->values = symtab_alloc(ctx, sizeof(*e->values) * n); + + if (n == 0) { + symtab_errf(ctx, "enums must contain at least one value (%s)", + e->full_name); + } + + res_ranges = + google_protobuf_EnumDescriptorProto_reserved_range(enum_proto, &n_res_range); + e->res_range_count = n_res_range; + e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); + + res_names = google_protobuf_EnumDescriptorProto_reserved_name(enum_proto, &n_res_name); + e->res_name_count = n_res_name; + e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); + + SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + + for (i = 0; i < n; i++) { + create_enumvaldef(ctx, prefix, values[i], e, i); + } + + upb_inttable_compact(&e->iton, ctx->arena); + + if (e->file->syntax == kUpb_Syntax_Proto2) { + if (ctx->layout) { + UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); + e->layout = ctx->layout->enums[ctx->enum_count++]; + UPB_ASSERT(upb_inttable_count(&e->iton) == + e->layout->value_count + count_bits_debug(e->layout->mask)); + } else { + e->layout = create_enumlayout(ctx, e); + } + } else { + e->layout = NULL; + } +} + +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m); + +static upb_StringView* _upb_ReservedNames_New(symtab_addctx* ctx, int n, + const upb_StringView* protos) { + upb_StringView* sv = upb_Arena_Malloc(ctx->arena, sizeof(upb_StringView) * n); + for (size_t i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, ctx->arena); + sv[i].size = protos[i].size; + } + return sv; +} + +static void create_msgdef(symtab_addctx* ctx, const char* prefix, + const google_protobuf_DescriptorProto* msg_proto, + const upb_MessageDef* containing_type, + const upb_MessageDef* _m) { + upb_MessageDef* m = (upb_MessageDef*)_m; + const google_protobuf_OneofDescriptorProto* const* oneofs; + const google_protobuf_FieldDescriptorProto* const* fields; + const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; + + const google_protobuf_DescriptorProto_ReservedRange* const* res_ranges; + const upb_StringView* res_names; + size_t i, n_oneof, n_field, n_ext_range; + size_t n_res_range, n_res_name; + upb_StringView name; + + m->file = ctx->file; /* Must happen prior to symtab_add(). */ + m->containing_type = containing_type; + + name = google_protobuf_DescriptorProto_name(msg_proto); + check_ident(ctx, name, false); + + m->full_name = makefullname(ctx, prefix, name); + symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG)); + + oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); + fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); + ext_ranges = + google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); + res_ranges = google_protobuf_DescriptorProto_reserved_range(msg_proto, &n_res_range); + res_names = google_protobuf_DescriptorProto_reserved_name(msg_proto, &n_res_name); + + CHK_OOM(upb_inttable_init(&m->itof, ctx->arena)); + CHK_OOM(upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena)); + + if (ctx->layout) { + /* create_fielddef() below depends on this being set. */ + UPB_ASSERT(ctx->msg_count < ctx->layout->msg_count); + m->layout = ctx->layout->msgs[ctx->msg_count++]; + UPB_ASSERT(n_field == m->layout->field_count); + } else { + /* Allocate now (to allow cross-linking), populate later. */ + m->layout = + symtab_alloc(ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); + } + + SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + + m->oneof_count = n_oneof; + m->oneofs = symtab_alloc(ctx, sizeof(*m->oneofs) * n_oneof); + for (i = 0; i < n_oneof; i++) { + create_oneofdef(ctx, m, oneofs[i], &m->oneofs[i]); + } + + m->field_count = n_field; + m->fields = symtab_alloc(ctx, sizeof(*m->fields) * n_field); + for (i = 0; i < n_field; i++) { + create_fielddef(ctx, m->full_name, m, fields[i], &m->fields[i], + /* is_extension= */ false); + } + + m->ext_range_count = n_ext_range; + m->ext_ranges = symtab_alloc(ctx, sizeof(*m->ext_ranges) * n_ext_range); + for (i = 0; i < n_ext_range; i++) { + const google_protobuf_DescriptorProto_ExtensionRange* r = ext_ranges[i]; + upb_ExtensionRange* r_def = (upb_ExtensionRange*)&m->ext_ranges[i]; + int32_t start = google_protobuf_DescriptorProto_ExtensionRange_start(r); + int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(r); + int32_t max = + google_protobuf_MessageOptions_message_set_wire_format(m->opts) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + symtab_errf(ctx, "Extension range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, m->full_name); + } + + r_def->start = start; + r_def->end = end; + SET_OPTIONS(r_def->opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, r); + } + + m->res_range_count = n_res_range; + m->res_ranges = + _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + + m->res_name_count = n_res_name; + m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); + + finalize_oneofs(ctx, m); + assign_msg_wellknowntype(m); + upb_inttable_compact(&m->itof, ctx->arena); + msgdef_create_nested(ctx, msg_proto, m); +} + +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m) { + size_t n; + + const google_protobuf_EnumDescriptorProto* const* enums = + google_protobuf_DescriptorProto_enum_type(msg_proto, &n); + m->nested_enum_count = n; + m->nested_enums = symtab_alloc(ctx, sizeof(*m->nested_enums) * n); + for (size_t i = 0; i < n; i++) { + m->nested_enum_count = i + 1; + create_enumdef(ctx, m->full_name, enums[i], m, &m->nested_enums[i]); + } + + const google_protobuf_FieldDescriptorProto* const* exts = + google_protobuf_DescriptorProto_extension(msg_proto, &n); + m->nested_ext_count = n; + m->nested_exts = symtab_alloc(ctx, sizeof(*m->nested_exts) * n); + for (size_t i = 0; i < n; i++) { + create_fielddef(ctx, m->full_name, m, exts[i], &m->nested_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&m->nested_exts[i])->index_ = i; + } + + const google_protobuf_DescriptorProto* const* msgs = + google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + m->nested_msg_count = n; + m->nested_msgs = symtab_alloc(ctx, sizeof(*m->nested_msgs) * n); + for (size_t i = 0; i < n; i++) { + create_msgdef(ctx, m->full_name, msgs[i], m, &m->nested_msgs[i]); + } +} + +static void resolve_subdef(symtab_addctx* ctx, const char* prefix, + upb_FieldDef* f) { + const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; + upb_StringView name = + google_protobuf_FieldDescriptorProto_type_name(field_proto); + bool has_name = + google_protobuf_FieldDescriptorProto_has_type_name(field_proto); + switch ((int)f->type_) { + case FIELD_TYPE_UNSPECIFIED: { + // Type was not specified and must be inferred. + UPB_ASSERT(has_name); + upb_deftype_t type; + const void* def = + symtab_resolveany(ctx, f->full_name, prefix, name, &type); + switch (type) { + case UPB_DEFTYPE_ENUM: + f->sub.enumdef = def; + f->type_ = kUpb_FieldType_Enum; + break; + case UPB_DEFTYPE_MSG: + f->sub.msgdef = def; + f->type_ = kUpb_FieldType_Message; // It appears there is no way of + // this being a group. + break; + default: + symtab_errf(ctx, "Couldn't resolve type name for field %s", + f->full_name); + } + } + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + UPB_ASSERT(has_name); + f->sub.msgdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + break; + case kUpb_FieldType_Enum: + UPB_ASSERT(has_name); + f->sub.enumdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_ENUM); + break; + default: + // No resolution necessary. + break; + } +} + +static void resolve_extension( + symtab_addctx* ctx, const char* prefix, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { + if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { + symtab_errf(ctx, "extension for field '%s' had no extendee", f->full_name); + } + + upb_StringView name = + google_protobuf_FieldDescriptorProto_extendee(field_proto); + const upb_MessageDef* m = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + f->msgdef = m; + + bool found = false; + + for (int i = 0, n = m->ext_range_count; i < n; i++) { + const upb_ExtensionRange* r = &m->ext_ranges[i]; + if (r->start <= f->number_ && f->number_ < r->end) { + found = true; + break; + } + } + + if (!found) { + symtab_errf(ctx, + "field number %u in extension %s has no extension range in " + "message %s", + (unsigned)f->number_, f->full_name, f->msgdef->full_name); + } + + const upb_MiniTable_Extension* ext = ctx->file->ext_layouts[f->layout_index]; + if (ctx->layout) { + UPB_ASSERT(upb_FieldDef_Number(f) == ext->field.number); + } else { + upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext; + fill_fieldlayout(&mut_ext->field, f); + mut_ext->field.presence = 0; + mut_ext->field.offset = 0; + mut_ext->field.submsg_index = 0; + mut_ext->extendee = f->msgdef->layout; + mut_ext->sub.submsg = f->sub.msgdef->layout; + } + + CHK_OOM(upb_inttable_insert(&ctx->symtab->exts, (uintptr_t)ext, + upb_value_constptr(f), ctx->arena)); +} + +static void resolve_default( + symtab_addctx* ctx, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { + // Have to delay resolving of the default value until now because of the enum + // case, since enum defaults are specified with a label. + if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { + upb_StringView defaultval = + google_protobuf_FieldDescriptorProto_default_value(field_proto); + + if (f->file->syntax == kUpb_Syntax_Proto3) { + symtab_errf(ctx, "proto3 fields cannot have explicit defaults (%s)", + f->full_name); + } + + if (upb_FieldDef_IsSubMessage(f)) { + symtab_errf(ctx, "message fields cannot have explicit defaults (%s)", + f->full_name); + } + + parse_default(ctx, defaultval.data, defaultval.size, f); + f->has_default = true; + } else { + set_default_default(ctx, f); + f->has_default = false; + } +} + +static void resolve_fielddef(symtab_addctx* ctx, const char* prefix, + upb_FieldDef* f) { + // We have to stash this away since resolve_subdef() may overwrite it. + const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; + + resolve_subdef(ctx, prefix, f); + resolve_default(ctx, f, field_proto); + + if (f->is_extension_) { + resolve_extension(ctx, prefix, f, field_proto); + } +} + +static void resolve_msgdef(symtab_addctx* ctx, upb_MessageDef* m) { + for (int i = 0; i < m->field_count; i++) { + resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->fields[i]); + } + + m->in_message_set = false; + for (int i = 0; i < m->nested_ext_count; i++) { + upb_FieldDef* ext = (upb_FieldDef*)&m->nested_exts[i]; + resolve_fielddef(ctx, m->full_name, ext); + if (ext->type_ == kUpb_FieldType_Message && + ext->label_ == kUpb_Label_Optional && ext->sub.msgdef == m && + google_protobuf_MessageOptions_message_set_wire_format( + ext->msgdef->opts)) { + m->in_message_set = true; + } + } + + if (!ctx->layout) make_layout(ctx, m); + + for (int i = 0; i < m->nested_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&m->nested_msgs[i]); + } +} + +static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { + size_t n; + google_protobuf_DescriptorProto_extension(msg_proto, &n); + int ext_count = n; + + const google_protobuf_DescriptorProto* const* nested_msgs = + google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(nested_msgs[i]); + } + + return ext_count; +} + +static void build_filedef( + symtab_addctx* ctx, upb_FileDef* file, + const google_protobuf_FileDescriptorProto* file_proto) { + const google_protobuf_DescriptorProto* const* msgs; + const google_protobuf_EnumDescriptorProto* const* enums; + const google_protobuf_FieldDescriptorProto* const* exts; + const google_protobuf_ServiceDescriptorProto* const* services; + const upb_StringView* strs; + const int32_t* public_deps; + const int32_t* weak_deps; + size_t i, n; + + file->symtab = ctx->symtab; + + /* Count all extensions in the file, to build a flat array of layouts. */ + google_protobuf_FileDescriptorProto_extension(file_proto, &n); + int ext_count = n; + msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + for (int i = 0; i < n; i++) { + ext_count += count_exts_in_msg(msgs[i]); + } + file->ext_count = ext_count; + + if (ctx->layout) { + /* We are using the ext layouts that were passed in. */ + file->ext_layouts = ctx->layout->exts; + if (ctx->layout->ext_count != file->ext_count) { + symtab_errf(ctx, "Extension count did not match layout (%d vs %d)", + ctx->layout->ext_count, file->ext_count); + } + } else { + /* We are building ext layouts from scratch. */ + file->ext_layouts = + symtab_alloc(ctx, sizeof(*file->ext_layouts) * file->ext_count); + upb_MiniTable_Extension* ext = + symtab_alloc(ctx, sizeof(*ext) * file->ext_count); + for (int i = 0; i < file->ext_count; i++) { + file->ext_layouts[i] = &ext[i]; + } + } + + if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) { + symtab_errf(ctx, "File has no name"); + } + + file->name = + strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); + + upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); + if (package.size) { + check_ident(ctx, package, true); + file->package = strviewdup(ctx, package); + } else { + file->package = NULL; + } + + if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { + upb_StringView syntax = + google_protobuf_FileDescriptorProto_syntax(file_proto); + + if (streql_view(syntax, "proto2")) { + file->syntax = kUpb_Syntax_Proto2; + } else if (streql_view(syntax, "proto3")) { + file->syntax = kUpb_Syntax_Proto3; + } else { + symtab_errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(syntax)); + } + } else { + file->syntax = kUpb_Syntax_Proto2; + } + + /* Read options. */ + SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + + /* Verify dependencies. */ + strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); + file->dep_count = n; + file->deps = symtab_alloc(ctx, sizeof(*file->deps) * n); + + for (i = 0; i < n; i++) { + upb_StringView str = strs[i]; + file->deps[i] = + upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); + if (!file->deps[i]) { + symtab_errf(ctx, + "Depends on file '" UPB_STRINGVIEW_FORMAT + "', but it has not been loaded", + UPB_STRINGVIEW_ARGS(str)); + } + } + + public_deps = + google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); + file->public_dep_count = n; + file->public_deps = symtab_alloc(ctx, sizeof(*file->public_deps) * n); + int32_t* mutable_public_deps = (int32_t*)file->public_deps; + for (i = 0; i < n; i++) { + if (public_deps[i] >= file->dep_count) { + symtab_errf(ctx, "public_dep %d is out of range", (int)public_deps[i]); + } + mutable_public_deps[i] = public_deps[i]; + } + + weak_deps = + google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); + file->weak_dep_count = n; + file->weak_deps = symtab_alloc(ctx, sizeof(*file->weak_deps) * n); + int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; + for (i = 0; i < n; i++) { + if (weak_deps[i] >= file->dep_count) { + symtab_errf(ctx, "weak_dep %d is out of range", (int)weak_deps[i]); + } + mutable_weak_deps[i] = weak_deps[i]; + } + + /* Create enums. */ + enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); + file->top_lvl_enum_count = n; + file->top_lvl_enums = symtab_alloc(ctx, sizeof(*file->top_lvl_enums) * n); + for (i = 0; i < n; i++) { + create_enumdef(ctx, file->package, enums[i], NULL, &file->top_lvl_enums[i]); + } + + /* Create extensions. */ + exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); + file->top_lvl_ext_count = n; + file->top_lvl_exts = symtab_alloc(ctx, sizeof(*file->top_lvl_exts) * n); + for (i = 0; i < n; i++) { + create_fielddef(ctx, file->package, NULL, exts[i], &file->top_lvl_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&file->top_lvl_exts[i])->index_ = i; + } + + /* Create messages. */ + msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); + file->top_lvl_msg_count = n; + file->top_lvl_msgs = symtab_alloc(ctx, sizeof(*file->top_lvl_msgs) * n); + for (i = 0; i < n; i++) { + create_msgdef(ctx, file->package, msgs[i], NULL, &file->top_lvl_msgs[i]); + } + + /* Create services. */ + services = google_protobuf_FileDescriptorProto_service(file_proto, &n); + file->service_count = n; + file->services = symtab_alloc(ctx, sizeof(*file->services) * n); + for (i = 0; i < n; i++) { + create_service(ctx, services[i], &file->services[i]); + ((upb_ServiceDef*)&file->services[i])->index = i; + } + + /* Now that all names are in the table, build layouts and resolve refs. */ + for (i = 0; i < (size_t)file->top_lvl_ext_count; i++) { + resolve_fielddef(ctx, file->package, (upb_FieldDef*)&file->top_lvl_exts[i]); + } + + for (i = 0; i < (size_t)file->top_lvl_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&file->top_lvl_msgs[i]); + } + + if (file->ext_count) { + CHK_OOM(_upb_extreg_add(ctx->symtab->extreg, file->ext_layouts, + file->ext_count)); + } } static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { @@ -6382,22 +8912,22 @@ static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { upb_value val; while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { + switch (deftype(val)) { case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); + f = upb_FieldDef_File(unpack_def(val, UPB_DEFTYPE_EXT)); break; case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); + f = upb_MessageDef_File(unpack_def(val, UPB_DEFTYPE_MSG)); break; case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); + f = upb_EnumDef_File(unpack_def(val, UPB_DEFTYPE_ENUM)); break; case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); + f = upb_EnumDef_File( + upb_EnumValueDef_Enum(unpack_def(val, UPB_DEFTYPE_ENUMVAL))); break; case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); + f = upb_ServiceDef_File(unpack_def(val, UPB_DEFTYPE_SERVICE)); break; default: UPB_UNREACHABLE(); @@ -6410,55 +8940,61 @@ static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { static const upb_FileDef* _upb_DefPool_AddFile( upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, const upb_MiniTable_File* layout, upb_Status* status) { - const upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); + symtab_addctx ctx; + upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); + upb_value v; - if (name.size == 0) { - upb_Status_SetErrorFormat(status, - "missing name in google_protobuf_FileDescriptorProto"); - return NULL; - } - - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + if (unpack_def(v, UPB_DEFTYPE_FILE)) { + upb_Status_SetErrorFormat(status, "duplicate file name (%.*s)", UPB_STRINGVIEW_ARGS(name)); return NULL; } + const upb_MiniTable_File* registered = unpack_def(v, UPB_DEFTYPE_LAYOUT); + UPB_ASSERT(registered); + if (layout && layout != registered) { + upb_Status_SetErrorFormat( + status, "tried to build with a different layout (filename=%.*s)", + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + layout = registered; } - upb_DefBuilder ctx = { - .symtab = s, - .layout = layout, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; + ctx.symtab = s; + ctx.layout = layout; + ctx.msg_count = 0; + ctx.enum_count = 0; + ctx.ext_count = 0; + ctx.status = status; + ctx.file = NULL; + ctx.arena = upb_Arena_New(); + ctx.tmp_arena = upb_Arena_New(); - if (UPB_SETJMP(ctx.err)) { + if (!ctx.arena || !ctx.tmp_arena) { + if (ctx.arena) upb_Arena_Free(ctx.arena); + if (ctx.tmp_arena) upb_Arena_Free(ctx.tmp_arena); + upb_Status_setoom(status); + return NULL; + } + + if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { UPB_ASSERT(!upb_Status_IsOk(status)); if (ctx.file) { remove_filedef(s, ctx.file); ctx.file = NULL; } - } else if (!ctx.arena || !ctx.tmp_arena) { - _upb_DefBuilder_OomErr(&ctx); } else { - _upb_FileDef_Create(&ctx, file_proto); + ctx.file = symtab_alloc(&ctx, sizeof(*ctx.file)); + build_filedef(&ctx, ctx.file, file_proto); upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(ctx.file), ctx.arena); + pack_def(ctx.file, UPB_DEFTYPE_FILE), ctx.arena); UPB_ASSERT(upb_Status_IsOk(status)); upb_Arena_Fuse(s->arena, ctx.arena); } - if (ctx.arena) upb_Arena_Free(ctx.arena); - if (ctx.tmp_arena) upb_Arena_Free(ctx.tmp_arena); + upb_Arena_Free(ctx.arena); + upb_Arena_Free(ctx.tmp_arena); return ctx.file; } @@ -6545,6 +9081,14 @@ const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, return ext ? _upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } +bool _upb_DefPool_registerlayout(upb_DefPool* s, const char* filename, + const upb_MiniTable_File* file) { + if (upb_DefPool_FindFileByName(s, filename)) return false; + upb_value v = pack_def(file, UPB_DEFTYPE_LAYOUT); + return upb_strtable_insert(&s->files, filename, strlen(filename), v, + s->arena); +} + const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( const upb_DefPool* s) { return s->extreg; @@ -6575,1678 +9119,13 @@ const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, return exts; } -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} - - -// Must be last. - -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; -} - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); -} - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; -} - - -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; - - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } - - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; - } - - return true; -} - - -#include - - -// Must be last. - -struct upb_EnumDef { - const google_protobuf_EnumOptions* opts; - const upb_MiniTable_Enum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - int value_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -// TODO: Maybe implement this on top of a ZCOS instead? -void _upb_EnumDef_Debug(const upb_EnumDef* e) { - fprintf(stderr, "enum %s (%p) {\n", e->full_name, e); - fprintf(stderr, " value_count: %d\n", e->value_count); - fprintf(stderr, " default: %d\n", e->defaultval); - fprintf(stderr, " is_sorted: %d\n", e->is_sorted); - fprintf(stderr, "}\n"); -} - -const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; -} - -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; -} - -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); -} - -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} - -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; -} - -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } - -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name) { - return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size) { - upb_value v; - return upb_strtable_lookup2(&e->ntoi, name, size, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num) { - upb_value v; - return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) - : NULL; -} - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { - // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect - // this to be faster (especially for small numbers). - return upb_MiniTable_Enum_CheckValue(e->layout, num); -} - -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->value_count); - return _upb_EnumValueDef_At(e->values, i); -} - -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_EnumValueDef** sorted = NULL; - if (!e->is_sorted) { - sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); - if (!sorted) return false; - } - - upb_MtDataEncoder_StartEnum(&s.e); - - // Duplicate values are allowed but we only encode each value once. - uint32_t previous = 0; - - for (size_t i = 0; i < e->value_count; i++) { - const uint32_t current = - upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); - if (i != 0 && previous == current) continue; - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); - previous = current; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); - - // There will always be room for this '\0' in the encoder buffer because - // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). - UPB_ASSERT(s.ptr < s.buf + s.bufsize); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static upb_MiniTable_Enum* create_enumlayout(upb_DefBuilder* ctx, - const upb_EnumDef* e) { - upb_StringView sv; - bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); - if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); - - upb_Status status; - upb_MiniTable_Enum* layout = - upb_MiniTable_BuildEnum(sv.data, sv.size, ctx->arena, &status); - if (!layout) - _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); - return layout; -} - -static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumDescriptorProto* enum_proto, - upb_EnumDef* e) { - const google_protobuf_EnumValueDescriptorProto* const* values; - upb_StringView name; - size_t n; - - // Must happen before _upb_DefBuilder_Add() - e->file = _upb_DefBuilder_File(ctx); - - name = google_protobuf_EnumDescriptorProto_name(enum_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - - e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, e->full_name, - _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - - values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n); - - bool ok = upb_strtable_init(&e->ntoi, n, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&e->iton, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - e->defaultval = 0; - e->value_count = n; - e->values = _upb_EnumValueDefs_New(ctx, prefix, n, values, e, &e->is_sorted); - - if (n == 0) { - _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", - e->full_name); - } - - UBP_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - - upb_inttable_compact(&e->iton, ctx->arena); - - if (upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2) { - if (ctx->layout) { - UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); - e->layout = ctx->layout->enums[ctx->enum_count++]; - } else { - e->layout = create_enumlayout(ctx, e); - } - } else { - e->layout = NULL; - } -} - -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); - - // If a containing type is defined then get the full name from that. - // Otherwise use the package name from the file def. - const char* name = containing_type ? upb_MessageDef_FullName(containing_type) - : _upb_FileDef_RawPackage(ctx->file); - - upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); - for (size_t i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], &e[i]); - e[i].containing_type = containing_type; - } - return e; -} - - - -// Must be last. - -struct upb_EnumValueDef { - const google_protobuf_EnumValueOptions* opts; - const upb_EnumDef* parent; - const char* full_name; - int32_t number; -}; - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { - return (upb_EnumValueDef*)&v[i]; -} - -static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; - const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; - return (v1 < v2) ? -1 : (v1 > v2); -} - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_EnumValueDef** out = - (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_EnumValueDef*)&v[i]; - } - qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); - - return (const upb_EnumValueDef**)out; -} - -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v) { - return v->opts; -} - -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { - return v->opts != (void*)kUpbDefOptDefault; -} - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { - return v->parent; -} - -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { - return v->full_name; -} - -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { - return _upb_DefBuilder_FullToShort(v->full_name); -} - -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { - // Compute index in our parent's array. - return v - upb_EnumDef_Value(v->parent, 0); -} - -static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumValueDescriptorProto* val_proto, - upb_EnumDef* e, upb_EnumValueDef* v) { - upb_StringView name = google_protobuf_EnumValueDescriptorProto_name(val_proto); - - v->parent = e; // Must happen prior to _upb_DefBuilder_Add() - v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); - _upb_DefBuilder_Add(ctx, v->full_name, - _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - - UBP_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - - upb_EnumValueDef* v = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - - *is_sorted = true; - uint32_t previous = 0; - for (size_t i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], e, &v[i]); - - const uint32_t current = v[i].number; - if (previous > current) *is_sorted = false; - previous = current; - } - - if (upb_FileDef_Syntax(ctx->file) == kUpb_Syntax_Proto3 && n > 0 && - v[0].number != 0) { - _upb_DefBuilder_Errf(ctx, - "for proto3, the first enum value must be zero (%s)", - upb_EnumDef_FullName(e)); - } - - return v; -} - - - -// Must be last. - -struct upb_ExtensionRange { - const google_protobuf_ExtensionRangeOptions* opts; - int32_t start; - int32_t end; -}; - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { - return (upb_ExtensionRange*)&r[i]; -} - -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r) { - return r->opts; -} - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { - return r->opts != (void*)kUpbDefOptDefault; -} - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { - return r->start; -} - -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } - -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const upb_MessageDef* m) { - upb_ExtensionRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); - - for (int i = 0; i < n; i++) { - const int32_t start = - google_protobuf_DescriptorProto_ExtensionRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(protos[i]); - const int32_t max = - google_protobuf_MessageOptions_message_set_wire_format(upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; - - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Extension range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } - - r[i].start = start; - r[i].end = end; - UBP_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); - } - - return r; -} - - -#include -#include - - -// Must be last. - -#define UPB_FIELD_TYPE_UNSPECIFIED 0 - -typedef struct { - size_t len; - char str[1]; // Null-terminated string data follows. -} str_t; - -struct upb_FieldDef { - const google_protobuf_FieldOptions* opts; - const upb_FileDef* file; - const upb_MessageDef* msgdef; - const char* full_name; - const char* json_name; - union { - int64_t sint; - uint64_t uint; - double dbl; - float flt; - bool boolean; - str_t* str; - } defaultval; - union { - const upb_OneofDef* oneof; - const upb_MessageDef* extension_scope; - } scope; - union { - const upb_MessageDef* msgdef; - const upb_EnumDef* enumdef; - const google_protobuf_FieldDescriptorProto* unresolved; - } sub; - uint32_t number_; - uint16_t index_; - uint16_t layout_index; // Index into msgdef->layout->fields or file->exts - bool has_default; - bool is_extension_; - bool is_packed_; - bool proto3_optional_; - bool has_json_name_; - upb_FieldType type_; - upb_Label label_; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { - return (upb_FieldDef*)&f[i]; -} - -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f) { - return f->opts; -} - -bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_FieldDef_FullName(const upb_FieldDef* f) { - return f->full_name; -} - -upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { - switch (f->type_) { - case kUpb_FieldType_Double: - return kUpb_CType_Double; - case kUpb_FieldType_Float: - return kUpb_CType_Float; - case kUpb_FieldType_Int64: - case kUpb_FieldType_SInt64: - case kUpb_FieldType_SFixed64: - return kUpb_CType_Int64; - case kUpb_FieldType_Int32: - case kUpb_FieldType_SFixed32: - case kUpb_FieldType_SInt32: - return kUpb_CType_Int32; - case kUpb_FieldType_UInt64: - case kUpb_FieldType_Fixed64: - return kUpb_CType_UInt64; - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Fixed32: - return kUpb_CType_UInt32; - case kUpb_FieldType_Enum: - return kUpb_CType_Enum; - case kUpb_FieldType_Bool: - return kUpb_CType_Bool; - case kUpb_FieldType_String: - return kUpb_CType_String; - case kUpb_FieldType_Bytes: - return kUpb_CType_Bytes; - case kUpb_FieldType_Group: - case kUpb_FieldType_Message: - return kUpb_CType_Message; - } - UPB_UNREACHABLE(); -} - -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; } - -uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } - -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; } - -uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } - -bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { - return f->is_extension_; -} - -bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->is_packed_; } - -const char* upb_FieldDef_Name(const upb_FieldDef* f) { - return _upb_DefBuilder_FullToShort(f->full_name); -} - -const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { - return f->json_name; -} - -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { - return f->has_json_name_; -} - -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } - -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { - return f->msgdef; -} - -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { - return f->is_extension_ ? f->scope.extension_scope : NULL; -} - -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { - return f->is_extension_ ? NULL : f->scope.oneof; -} - -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { - const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); - if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; - return oneof; -} - -upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { - UPB_ASSERT(!upb_FieldDef_IsSubMessage(f)); - upb_MessageValue ret; - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return (upb_MessageValue){.bool_val = f->defaultval.boolean}; - case kUpb_CType_Int64: - return (upb_MessageValue){.int64_val = f->defaultval.sint}; - case kUpb_CType_UInt64: - return (upb_MessageValue){.uint64_val = f->defaultval.uint}; - case kUpb_CType_Enum: - case kUpb_CType_Int32: - return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; - case kUpb_CType_UInt32: - return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; - case kUpb_CType_Float: - return (upb_MessageValue){.float_val = f->defaultval.flt}; - case kUpb_CType_Double: - return (upb_MessageValue){.double_val = f->defaultval.dbl}; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - str_t* str = f->defaultval.str; - if (str) { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = str->str, .size = str->len}}; - } else { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = NULL, .size = 0}}; - } - } - default: - UPB_UNREACHABLE(); - } - - return ret; -} - -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; -} - -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; -} - -const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f) { - UPB_ASSERT(!upb_FieldDef_IsExtension(f)); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); - return &layout->fields[f->layout_index]; -} - -const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_IsExtension(f)); - const upb_FileDef* file = upb_FieldDef_File(f); - return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); -} - -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; - if (f->type_ != kUpb_FieldType_Enum) return false; - - // TODO(https://github.com/protocolbuffers/upb/issues/541): - // fix map enum values to check for unknown enum values and put - // them in the unknown field set. - if (upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f))) { - return false; - } - - // TODO: Maybe make is_proto2 a bool at creation? - const upb_FileDef* file = upb_EnumDef_File(f->sub.enumdef); - return upb_FileDef_Syntax(file) == kUpb_Syntax_Proto2; -} - -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { - return f->proto3_optional_; -} - -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } - -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { - uint64_t out = f->is_packed_ ? kUpb_FieldModifier_IsPacked : 0; - - switch (f->label_) { - case kUpb_Label_Optional: - if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - break; - case kUpb_Label_Repeated: - out |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_Label_Required: - out |= kUpb_FieldModifier_IsRequired; - break; - } - - if (_upb_FieldDef_IsClosedEnum(f)) { - out |= kUpb_FieldModifier_IsClosedEnum; - } - return out; -} - -bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } - -bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { - if (upb_FieldDef_IsRepeated(f)) return false; - const upb_FileDef* file = upb_FieldDef_File(f); - return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_ContainingOneof(f) || - upb_FileDef_Syntax(file) == kUpb_Syntax_Proto2; -} - -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) || - upb_FieldDef_CType(f) == kUpb_CType_Enum; -} - -bool upb_FieldDef_IsMap(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && - upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); -} - -bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Optional; -} - -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { - return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); -} - -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Repeated; -} - -bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Required; -} - -bool upb_FieldDef_IsString(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_String || - upb_FieldDef_CType(f) == kUpb_CType_Bytes; -} - -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message; -} - -static bool between(int32_t x, int32_t low, int32_t high) { - return x >= low && x <= high; -} - -bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } -bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } -bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } - -bool upb_FieldDef_checkdescriptortype(int32_t type) { - return between(type, 1, 18); -} - -static bool streql2(const char* a, size_t n, const char* b) { - return n == strlen(b) && memcmp(a, b, n) == 0; -} - -// Implement the transformation as described in the spec: -// 1. upper case all letters after an underscore. -// 2. remove all underscores. -static char* make_json_name(const char* name, size_t size, upb_Arena* a) { - char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' - if (out == NULL) return NULL; - - bool ucase_next = false; - char* des = out; - for (size_t i = 0; i < size; i++) { - if (name[i] == '_') { - ucase_next = true; - } else { - *des++ = ucase_next ? toupper(name[i]) : name[i]; - ucase_next = false; - } - } - *des++ = '\0'; - return out; -} - -static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - if (!ret) _upb_DefBuilder_OomErr(ctx); - ret->len = len; - if (len) memcpy(ret->str, data, len); - ret->str[len] = '\0'; - return ret; -} - -static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char* data, size_t len) { - // Size here is an upper bound; escape sequences could ultimately shrink it. - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - char* dst = &ret->str[0]; - const char* src = data; - const char* end = data + len; - - while (src < end) { - if (*src == '\\') { - src++; - *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); - } else { - *dst++ = *src++; - } - } - - ret->len = dst - &ret->str[0]; - return ret; -} - -static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, - upb_FieldDef* f) { - char* end; - char nullz[64]; - errno = 0; - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - case kUpb_CType_Double: - case kUpb_CType_Float: - /* Standard C number parsing functions expect null-terminated strings. */ - if (len >= sizeof(nullz) - 1) { - _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); - } - memcpy(nullz, str, len); - nullz[len] = '\0'; - str = nullz; - break; - default: - break; - } - - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: { - long val = strtol(str, &end, 0); - if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_Enum: { - const upb_EnumDef* e = f->sub.enumdef; - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str, len); - if (!ev) { - goto invalid; - } - f->defaultval.sint = upb_EnumValueDef_Number(ev); - break; - } - case kUpb_CType_Int64: { - long long val = strtoll(str, &end, 0); - if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_UInt32: { - unsigned long val = strtoul(str, &end, 0); - if (val > UINT32_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_UInt64: { - unsigned long long val = strtoull(str, &end, 0); - if (val > UINT64_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_Double: { - double val = strtod(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.dbl = val; - break; - } - case kUpb_CType_Float: { - float val = strtof(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.flt = val; - break; - } - case kUpb_CType_Bool: { - if (streql2(str, len, "false")) { - f->defaultval.boolean = false; - } else if (streql2(str, len, "true")) { - f->defaultval.boolean = true; - } else { - goto invalid; - } - break; - } - case kUpb_CType_String: - f->defaultval.str = newstr(ctx, str, len); - break; - case kUpb_CType_Bytes: - f->defaultval.str = unescape(ctx, f, str, len); - break; - case kUpb_CType_Message: - /* Should not have a default value. */ - _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", - upb_FieldDef_FullName(f)); - } - - return; - -invalid: - _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", - (int)len, str, upb_FieldDef_FullName(f), - (int)upb_FieldDef_Type(f)); -} - -static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - f->defaultval.sint = 0; - break; - case kUpb_CType_UInt64: - case kUpb_CType_UInt32: - f->defaultval.uint = 0; - break; - case kUpb_CType_Double: - case kUpb_CType_Float: - f->defaultval.dbl = 0; - break; - case kUpb_CType_String: - case kUpb_CType_Bytes: - f->defaultval.str = newstr(ctx, NULL, 0); - break; - case kUpb_CType_Bool: - f->defaultval.boolean = false; - break; - case kUpb_CType_Enum: { - const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); - f->defaultval.sint = upb_EnumValueDef_Number(v); - } - case kUpb_CType_Message: - break; - } -} - -static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - // Must happen before _upb_DefBuilder_Add() - f->file = _upb_DefBuilder_File(ctx); - - if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } - - const upb_StringView name = google_protobuf_FieldDescriptorProto_name(field_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - - f->has_json_name_ = google_protobuf_FieldDescriptorProto_has_json_name(field_proto); - if (f->has_json_name_) { - const upb_StringView sv = - google_protobuf_FieldDescriptorProto_json_name(field_proto); - f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); - } else { - f->json_name = make_json_name(name.data, name.size, ctx->arena); - } - if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); - f->number_ = google_protobuf_FieldDescriptorProto_number(field_proto); - f->proto3_optional_ = - google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); - f->msgdef = m; - f->scope.oneof = NULL; - - const bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); - const bool has_type_name = - google_protobuf_FieldDescriptorProto_has_type_name(field_proto); - - f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); - - if (has_type) { - switch (f->type_) { - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - case kUpb_FieldType_Enum: - if (!has_type_name) { - _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", - (int)f->type_, f->full_name); - } - break; - default: - if (has_type_name) { - _upb_DefBuilder_Errf( - ctx, "invalid type for field with type_name set (%s, %d)", - f->full_name, (int)f->type_); - } - } - } else if (has_type_name) { - f->type_ = - UPB_FIELD_TYPE_UNSPECIFIED; // We'll fill this in in resolve_fielddef() - } - - if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { - _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, - f->type_); - } - - if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { - _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, - f->label_); - } - - /* We can't resolve the subdef or (in the case of extensions) the containing - * message yet, because it may not have been defined yet. We stash a pointer - * to the field_proto until later when we can properly resolve it. */ - f->sub.unresolved = field_proto; - - if (f->label_ == kUpb_Label_Required && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - uint32_t oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); - - if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { - _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", - f->full_name); - } - - if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); - } - - if (oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); - } - - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); - f->scope.oneof = oneof; - - bool ok = _upb_OneofDef_Insert(oneof, f, name.data, name.size, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } - - UBP_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); - - if (google_protobuf_FieldOptions_has_packed(f->opts)) { - f->is_packed_ = google_protobuf_FieldOptions_packed(f->opts); - } else { - // Repeated fields default to packed for proto3 only. - f->is_packed_ = upb_FieldDef_IsPrimitive(f) && - f->label_ == kUpb_Label_Repeated && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3; - } -} - -static void _upb_FieldDef_CreateExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); - f->is_extension_ = true; - - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", - f->full_name); - } - - f->scope.extension_scope = m; - _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); - f->layout_index = ctx->ext_count++; - - if (ctx->layout) { - UPB_ASSERT(_upb_FieldDef_ExtensionMiniTable(f)->field.number == f->number_); - } -} - -static void _upb_FieldDef_CreateNotExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); - f->is_extension_ = false; - - if (!google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - if (f->proto3_optional_) { - _upb_DefBuilder_Errf( - ctx, - "non-extension field (%s) with proto3_optional was not in a oneof", - f->full_name); - } - } - - _upb_MessageDef_InsertField(ctx, m, f); - - if (!ctx->layout) return; - - const upb_MiniTable* mt = upb_MessageDef_MiniTable(m); - const upb_MiniTable_Field* fields = mt->fields; - for (int i = 0; i < mt->field_count; i++) { - if (fields[i].number == f->number_) { - f->layout_index = i; - return; - } - } - - UPB_ASSERT(false); // It should be impossible to reach this point. -} - -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); - - // If we are creating extensions then is_sorted will be NULL. - // If we are not creating extensions then is_sorted will be non-NULL. - if (is_sorted) { - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateNotExt(ctx, prefix, protos[i], m, f); - f->index_ = i; - if (!ctx->layout) f->layout_index = i; - - const uint32_t current = f->number_; - if (previous > current) *is_sorted = false; - previous = current; - } - } else { - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateExt(ctx, prefix, protos[i], m, f); - f->index_ = i; - } - } - - return defs; -} - -static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; - upb_StringView name = - google_protobuf_FieldDescriptorProto_type_name(field_proto); - bool has_name = - google_protobuf_FieldDescriptorProto_has_type_name(field_proto); - switch ((int)f->type_) { - case UPB_FIELD_TYPE_UNSPECIFIED: { - // Type was not specified and must be inferred. - UPB_ASSERT(has_name); - upb_deftype_t type; - const void* def = - _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); - switch (type) { - case UPB_DEFTYPE_ENUM: - f->sub.enumdef = def; - f->type_ = kUpb_FieldType_Enum; - break; - case UPB_DEFTYPE_MSG: - f->sub.msgdef = def; - f->type_ = kUpb_FieldType_Message; // It appears there is no way of - // this being a group. - break; - default: - _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", - f->full_name); - } - } - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - UPB_ASSERT(has_name); - f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_MSG); - break; - case kUpb_FieldType_Enum: - UPB_ASSERT(has_name); - f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_ENUM); - break; - default: - // No resolution necessary. - break; - } -} - -static int _upb_FieldDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; - const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; - return (v1 < v2) ? -1 : (v1 > v2); -} - -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_FieldDef*)&f[i]; - } - qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); - - for (int i = 0; i < n; i++) { - out[i]->layout_index = i; - } - return (const upb_FieldDef**)out; -} - -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out) { - UPB_ASSERT(f->is_extension_); - - upb_DescState s; - _upb_DescState_Init(&s); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartMessage(&s.e, s.ptr, 0); - - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, f->type_, number, modifiers); - - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { - if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { - _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", - f->full_name); - } - - upb_StringView name = google_protobuf_FieldDescriptorProto_extendee(field_proto); - const upb_MessageDef* m = - _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); - f->msgdef = m; - - if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { - _upb_DefBuilder_Errf( - ctx, - "field number %u in extension %s has no extension range in message %s", - (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); - } - - const upb_MiniTable_Extension* ext = _upb_FieldDef_ExtensionMiniTable(f); - - if (ctx->layout) { - UPB_ASSERT(upb_FieldDef_Number(f) == ext->field.number); - } else { - upb_StringView desc; - if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { - _upb_DefBuilder_OomErr(ctx); - } - - upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext; - upb_MiniTable_Sub sub; - sub.submsg = NULL; - sub.subenum = NULL; - bool ok2 = upb_MiniTable_BuildExtension(desc.data, desc.size, mut_ext, - upb_MessageDef_MiniTable(m), sub, - ctx->status); - if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); - - assert(mut_ext->field.number == f->number_); - mut_ext->extendee = upb_MessageDef_MiniTable(m); - if (upb_FieldDef_IsSubMessage(f)) { - mut_ext->sub.submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - } else if (mut_ext->field.descriptortype == kUpb_FieldType_Enum) { - mut_ext->sub.subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - } - } - - bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { - // Have to delay resolving of the default value until now because of the enum - // case, since enum defaults are specified with a label. - if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { - upb_StringView defaultval = - google_protobuf_FieldDescriptorProto_default_value(field_proto); - - if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, - "proto3 fields cannot have explicit defaults (%s)", - f->full_name); - } - - if (upb_FieldDef_IsSubMessage(f)) { - _upb_DefBuilder_Errf(ctx, - "message fields cannot have explicit defaults (%s)", - f->full_name); - } - - parse_default(ctx, defaultval.data, defaultval.size, f); - f->has_default = true; - } else { - set_default_default(ctx, f); - f->has_default = false; - } -} - -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - // We have to stash this away since resolve_subdef() may overwrite it. - const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; - - resolve_subdef(ctx, prefix, f); - resolve_default(ctx, f, field_proto); - - if (f->is_extension_) { - resolve_extension(ctx, prefix, f, field_proto); - } -} - - - -// Must be last. - -struct upb_FileDef { - const google_protobuf_FileOptions* opts; - const char* name; - const char* package; - - const upb_FileDef** deps; - const int32_t* public_deps; - const int32_t* weak_deps; - const upb_MessageDef* top_lvl_msgs; - const upb_EnumDef* top_lvl_enums; - const upb_FieldDef* top_lvl_exts; - const upb_ServiceDef* services; - const upb_MiniTable_Extension** ext_layouts; - const upb_DefPool* symtab; - - int dep_count; - int public_dep_count; - int weak_dep_count; - int top_lvl_msg_count; - int top_lvl_enum_count; - int top_lvl_ext_count; - int service_count; - int ext_count; // All exts in the file. - upb_Syntax syntax; -}; - -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { - return f->opts; -} - -bool upb_FileDef_HasOptions(const upb_FileDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } - -const char* upb_FileDef_Package(const upb_FileDef* f) { - return f->package ? f->package : ""; -} - -const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } - -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } - -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { - return f->top_lvl_msg_count; -} - -int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } - -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { - return f->public_dep_count; -} - -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { - return f->weak_dep_count; -} - -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { - return f->public_deps; -} - -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { - return f->weak_deps; -} - -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { - return f->top_lvl_enum_count; -} - -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { - return f->top_lvl_ext_count; -} - -int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->dep_count); - return f->deps[i]; -} - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->public_deps[i]]; -} - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->weak_deps[i]]; -} - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); - return _upb_MessageDef_At(f->top_lvl_msgs, i); -} - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); - return _upb_EnumDef_At(f->top_lvl_enums, i); -} - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); - return _upb_FieldDef_At(f->top_lvl_exts, i); -} - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->service_count); - return _upb_ServiceDef_At(f->services, i); -} - -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } - -const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i) { - return f->ext_layouts[i]; -} - -static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { - char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -static bool streql_view(upb_StringView view, const char* b) { - return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; -} - -static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { - size_t n; - google_protobuf_DescriptorProto_extension(msg_proto, &n); - int ext_count = n; - - const google_protobuf_DescriptorProto* const* nested_msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(nested_msgs[i]); - } - - return ext_count; -} - -// Allocate and initialize one file def, and add it to the context object. -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto) { - upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); - ctx->file = file; - - const google_protobuf_DescriptorProto* const* msgs; - const google_protobuf_EnumDescriptorProto* const* enums; - const google_protobuf_FieldDescriptorProto* const* exts; - const google_protobuf_ServiceDescriptorProto* const* services; - const upb_StringView* strs; - const int32_t* public_deps; - const int32_t* weak_deps; - size_t n; - - file->symtab = ctx->symtab; - - // Count all extensions in the file, to build a flat array of layouts. - google_protobuf_FileDescriptorProto_extension(file_proto, &n); - int ext_count = n; - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); - for (int i = 0; i < n; i++) { - ext_count += count_exts_in_msg(msgs[i]); - } - file->ext_count = ext_count; - - if (ctx->layout) { - // We are using the ext layouts that were passed in. - file->ext_layouts = ctx->layout->exts; - if (ctx->layout->ext_count != file->ext_count) { - _upb_DefBuilder_Errf(ctx, - "Extension count did not match layout (%d vs %d)", - ctx->layout->ext_count, file->ext_count); - } - } else { - // We are building ext layouts from scratch. - file->ext_layouts = _upb_DefBuilder_Alloc( - ctx, sizeof(*file->ext_layouts) * file->ext_count); - upb_MiniTable_Extension* ext = - _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); - for (int i = 0; i < file->ext_count; i++) { - file->ext_layouts[i] = &ext[i]; - } - } - - if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) { - _upb_DefBuilder_Errf(ctx, "File has no name"); - } - - file->name = strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); - - upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); - if (package.size) { - _upb_DefBuilder_CheckIdentFull(ctx, package); - file->package = strviewdup(ctx, package); - } else { - file->package = NULL; - } - - if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { - upb_StringView syntax = google_protobuf_FileDescriptorProto_syntax(file_proto); - - if (streql_view(syntax, "proto2")) { - file->syntax = kUpb_Syntax_Proto2; - } else if (streql_view(syntax, "proto3")) { - file->syntax = kUpb_Syntax_Proto3; - } else { - _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(syntax)); - } - } else { - file->syntax = kUpb_Syntax_Proto2; - } - - // Read options. - UBP_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - - // Verify dependencies. - strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); - file->dep_count = n; - file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); - - for (size_t i = 0; i < n; i++) { - upb_StringView str = strs[i]; - file->deps[i] = - upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); - if (!file->deps[i]) { - _upb_DefBuilder_Errf(ctx, - "Depends on file '" UPB_STRINGVIEW_FORMAT - "', but it has not been loaded", - UPB_STRINGVIEW_ARGS(str)); - } - } - - public_deps = google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); - file->public_dep_count = n; - file->public_deps = - _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); - int32_t* mutable_public_deps = (int32_t*)file->public_deps; - for (size_t i = 0; i < n; i++) { - if (public_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", - (int)public_deps[i]); - } - mutable_public_deps[i] = public_deps[i]; - } - - weak_deps = google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); - file->weak_dep_count = n; - file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); - int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; - for (size_t i = 0; i < n; i++) { - if (weak_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", - (int)weak_deps[i]); - } - mutable_weak_deps[i] = weak_deps[i]; - } - - // Create enums. - enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); - file->top_lvl_enum_count = n; - file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); - - // Create extensions. - exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); - file->top_lvl_ext_count = n; - file->top_lvl_exts = - _upb_FieldDefs_New(ctx, n, exts, file->package, NULL, NULL); - - // Create messages. - msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); - file->top_lvl_msg_count = n; - file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); - - // Create services. - services = google_protobuf_FileDescriptorProto_service(file_proto, &n); - file->service_count = n; - file->services = _upb_ServiceDefs_New(ctx, n, services); - - // Now that all names are in the table, build layouts and resolve refs. - - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_Resolve(ctx, m); - } - - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_Resolve(ctx, file->package, f); - } - - if (!ctx->layout) { - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_LinkMiniTable(ctx, m); - } - } - - if (file->ext_count) { - bool ok = _upb_extreg_add(_upb_DefPool_ExtReg(ctx->symtab), - file->ext_layouts, file->ext_count); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } -} +#undef CHK_OOM +/** upb/reflection.c ************************************************************/ #include -// Must be last. - static size_t get_field_size(const upb_MiniTable_Field* f) { static unsigned char sizes[] = { 0, /* 0 */ @@ -8272,6 +9151,9 @@ static size_t get_field_size(const upb_MiniTable_Field* f) { return upb_IsRepeatedOrMap(f) ? sizeof(void*) : sizes[f->descriptortype]; } +/** upb_Message + * *******************************************************************/ + upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a) { return _upb_Message_New(upb_MessageDef_MiniTable(m), a); } @@ -8388,14 +9270,6 @@ bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f, memcpy(&ext->data, &val, sizeof(val)); } else { const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); - - // Building reflection should always cause all sub-message types to be - // linked, but double-check here just for extra assurance. - UPB_ASSERT(!upb_FieldDef_IsSubMessage(f) || - upb_MessageDef_MiniTable(upb_FieldDef_ContainingType(f)) - ->subs[field->submsg_index] - .submsg); - char* mem = UPB_PTR_AT(msg, field->offset, char); memcpy(mem, &val, get_field_size(field)); if (field->presence > 0) { @@ -8541,950 +9415,2188 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, return _upb_Message_DiscardUnknown(msg, m, maxdepth); } +/** upb/decode.c ************************************************************/ + +#include +#include -// Must be last. +/* Must be last. */ -struct upb_MessageDef { - const google_protobuf_MessageOptions* opts; - const upb_MiniTable* layout; - const upb_FileDef* file; - const upb_MessageDef* containing_type; - const char* full_name; - - // Tables for looking up fields by number and name. - upb_inttable itof; - upb_strtable ntof; - - /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contiguous - * region and calculating counts from offsets or vice-versa. */ - const upb_FieldDef* fields; - const upb_OneofDef* oneofs; - const upb_ExtensionRange* ext_ranges; - const upb_MessageDef* nested_msgs; - const upb_EnumDef* nested_enums; - const upb_FieldDef* nested_exts; - int field_count; - int real_oneof_count; - int oneof_count; - int ext_range_count; - int nested_msg_count; - int nested_enum_count; - int nested_ext_count; - bool in_message_set; - bool is_sorted; - upb_WellKnown well_known_type; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif +/* Maps descriptor type -> elem_size_lg2. */ +static const uint8_t desctype_to_elem_size_lg2[] = { + -1, /* invalid descriptor type */ + 3, /* DOUBLE */ + 2, /* FLOAT */ + 3, /* INT64 */ + 3, /* UINT64 */ + 2, /* INT32 */ + 3, /* FIXED64 */ + 2, /* FIXED32 */ + 0, /* BOOL */ + UPB_SIZE(3, 4), /* STRING */ + UPB_SIZE(2, 3), /* GROUP */ + UPB_SIZE(2, 3), /* MESSAGE */ + UPB_SIZE(3, 4), /* BYTES */ + 2, /* UINT32 */ + 2, /* ENUM */ + 2, /* SFIXED32 */ + 3, /* SFIXED64 */ + 2, /* SINT32 */ + 3, /* SINT64 */ }; -static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = upb_MessageDef_FullName(m); - if (name == NULL) { - m->well_known_type = kUpb_WellKnown_Unspecified; +/* Maps descriptor type -> upb map size. */ +static const uint8_t desctype_to_mapsize[] = { + -1, /* invalid descriptor type */ + 8, /* DOUBLE */ + 4, /* FLOAT */ + 8, /* INT64 */ + 8, /* UINT64 */ + 4, /* INT32 */ + 8, /* FIXED64 */ + 4, /* FIXED32 */ + 1, /* BOOL */ + UPB_MAPTYPE_STRING, /* STRING */ + sizeof(void*), /* GROUP */ + sizeof(void*), /* MESSAGE */ + UPB_MAPTYPE_STRING, /* BYTES */ + 4, /* UINT32 */ + 4, /* ENUM */ + 4, /* SFIXED32 */ + 8, /* SFIXED64 */ + 4, /* SINT32 */ + 8, /* SINT64 */ +}; + +static const unsigned FIXED32_OK_MASK = (1 << kUpb_FieldType_Float) | + (1 << kUpb_FieldType_Fixed32) | + (1 << kUpb_FieldType_SFixed32); + +static const unsigned FIXED64_OK_MASK = (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Fixed64) | + (1 << kUpb_FieldType_SFixed64); + +/* Three fake field types for MessageSet. */ +#define TYPE_MSGSET_ITEM 19 +#define TYPE_COUNT 19 + +/* Op: an action to be performed for a wire-type/field-type combination. */ +#define OP_UNKNOWN -1 /* Unknown field. */ +#define OP_MSGSET_ITEM -2 +#define OP_SCALAR_LG2(n) (n) /* n in [0, 2, 3] => op in [0, 2, 3] */ +#define OP_ENUM 1 +#define OP_STRING 4 +#define OP_BYTES 5 +#define OP_SUBMSG 6 +/* Scalar fields use only ops above. Repeated fields can use any op. */ +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ +#define OP_PACKED_ENUM 13 + +static const int8_t varint_ops[] = { + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ + OP_SCALAR_LG2(3), /* INT64 */ + OP_SCALAR_LG2(3), /* UINT64 */ + OP_SCALAR_LG2(2), /* INT32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ + OP_SCALAR_LG2(0), /* BOOL */ + OP_UNKNOWN, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_UNKNOWN, /* MESSAGE */ + OP_UNKNOWN, /* BYTES */ + OP_SCALAR_LG2(2), /* UINT32 */ + OP_ENUM, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ + OP_SCALAR_LG2(2), /* SINT32 */ + OP_SCALAR_LG2(3), /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ +}; + +static const int8_t delim_ops[] = { + /* For non-repeated field type. */ + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ + OP_UNKNOWN, /* INT64 */ + OP_UNKNOWN, /* UINT64 */ + OP_UNKNOWN, /* INT32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ + OP_UNKNOWN, /* BOOL */ + OP_STRING, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_SUBMSG, /* MESSAGE */ + OP_BYTES, /* BYTES */ + OP_UNKNOWN, /* UINT32 */ + OP_UNKNOWN, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ + OP_UNKNOWN, /* SINT32 */ + OP_UNKNOWN, /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ + /* For repeated field type. */ + OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */ + OP_FIXPCK_LG2(2), /* REPEATED FLOAT */ + OP_VARPCK_LG2(3), /* REPEATED INT64 */ + OP_VARPCK_LG2(3), /* REPEATED UINT64 */ + OP_VARPCK_LG2(2), /* REPEATED INT32 */ + OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */ + OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */ + OP_VARPCK_LG2(0), /* REPEATED BOOL */ + OP_STRING, /* REPEATED STRING */ + OP_SUBMSG, /* REPEATED GROUP */ + OP_SUBMSG, /* REPEATED MESSAGE */ + OP_BYTES, /* REPEATED BYTES */ + OP_VARPCK_LG2(2), /* REPEATED UINT32 */ + OP_PACKED_ENUM, /* REPEATED ENUM */ + OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */ + OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */ + OP_VARPCK_LG2(2), /* REPEATED SINT32 */ + OP_VARPCK_LG2(3), /* REPEATED SINT64 */ + /* Omitting MSGSET_*, because we never emit a repeated msgset type */ +}; + +typedef union { + bool bool_val; + uint32_t uint32_val; + uint64_t uint64_val; + uint32_t size; +} wireval; + +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout); + +UPB_NORETURN static void* decode_err(upb_Decoder* d, upb_DecodeStatus status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); +} + +const char* fastdecode_err(upb_Decoder* d, int status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); + return NULL; +} +static void decode_verifyutf8(upb_Decoder* d, const char* buf, int len) { + if (!decode_verifyutf8_inl(buf, len)) + decode_err(d, kUpb_DecodeStatus_BadUtf8); +} + +static bool decode_reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { + bool need_realloc = arr->size - arr->len < elem; + if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + return need_realloc; +} + +typedef struct { + const char* ptr; + uint64_t val; +} decode_vret; + +UPB_NOINLINE +static decode_vret decode_longvarint64(const char* ptr, uint64_t val) { + decode_vret ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } + } + return ret; +} + +UPB_FORCEINLINE +static const char* decode_varint64(upb_Decoder* d, const char* ptr, + uint64_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + decode_vret res = decode_longvarint64(ptr, byte); + if (!res.ptr) return decode_err(d, kUpb_DecodeStatus_Malformed); + *val = res.val; + return res.ptr; + } +} + +UPB_FORCEINLINE +static const char* decode_tag(upb_Decoder* d, const char* ptr, uint32_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + const char* start = ptr; + decode_vret res = decode_longvarint64(ptr, byte); + if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + *val = res.val; + return res.ptr; + } +} + +UPB_FORCEINLINE +static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, + uint32_t* size) { + uint64_t size64; + ptr = decode_varint64(d, ptr, &size64); + if (size64 >= INT32_MAX || ptr - d->end + (int)size64 > d->limit) { + decode_err(d, kUpb_DecodeStatus_Malformed); + } + *size = size64; + return ptr; +} + +static void decode_munge_int32(wireval* val) { + if (!_upb_IsLittleEndian()) { + /* The next stage will memcpy(dst, &val, 4) */ + val->uint32_val = val->uint64_val; + } +} + +static void decode_munge(int type, wireval* val) { + switch (type) { + case kUpb_FieldType_Bool: + val->bool_val = val->uint64_val != 0; + break; + case kUpb_FieldType_SInt32: { + uint32_t n = val->uint64_val; + val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); + break; + } + case kUpb_FieldType_SInt64: { + uint64_t n = val->uint64_val; + val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); + break; + } + case kUpb_FieldType_Int32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Enum: + decode_munge_int32(val); + break; + } +} + +static upb_Message* decode_newsubmsg(upb_Decoder* d, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; + upb_Message* msg = _upb_Message_New_inl(subl, &d->arena); + if (!msg) decode_err(d, kUpb_DecodeStatus_OutOfMemory); + return msg; +} + +UPB_NOINLINE +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, + int overrun) { + int status; + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); + if (ptr == NULL) { + return decode_err(d, status); + } + return ptr; +} + +static const char* decode_readstr(upb_Decoder* d, const char* ptr, int size, + upb_StringView* str) { + if (d->options & kUpb_DecodeOption_AliasString) { + str->data = ptr; + } else { + char* data = upb_Arena_Malloc(&d->arena, size); + if (!data) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + memcpy(data, ptr, size); + str->data = data; + } + str->size = size; + return ptr + size; +} + +UPB_FORCEINLINE +static const char* decode_tosubmsg2(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, int size) { + int saved_delta = decode_pushlimit(d, ptr, size); + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != DECODE_NOGROUP) + return decode_err(d, kUpb_DecodeStatus_Malformed); + decode_poplimit(d, ptr, saved_delta); + d->depth++; + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_tosubmsg(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, int size) { + return decode_tosubmsg2(d, ptr, submsg, subs[field->submsg_index].submsg, + size); +} + +UPB_FORCEINLINE +static const char* decode_group(upb_Decoder* d, const char* ptr, + upb_Message* submsg, const upb_MiniTable* subl, + uint32_t number) { + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); + if (decode_isdone(d, &ptr)) { + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != number) return decode_err(d, kUpb_DecodeStatus_Malformed); + d->end_group = DECODE_NOGROUP; + d->depth++; + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_togroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; + return decode_group(d, ptr, submsg, subl, field->number); +} + +static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + *(ptr++) = byte; + } while (val); + return ptr; +} + +static void upb_Decode_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, + uint32_t val1, uint32_t val2) { + char buf[20]; + char* end = buf; + end = upb_Decoder_EncodeVarint32(val1, end); + end = upb_Decoder_EncodeVarint32(val2, end); + + if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } +} + +UPB_NOINLINE +static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, + uint32_t v) { + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if ((uint32_t)e->values[i] == v) return true; + } + + // Unrecognized enum goes into unknown fields. + // For packed fields the tag could be arbitrarily far in the past, so we + // just re-encode the tag and value here. + uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; + upb_Message* unknown_msg = + field->mode & kUpb_LabelFlags_IsExtension ? d->unknown_msg : msg; + upb_Decode_AddUnknownVarints(d, unknown_msg, tag, v); + return false; +} + +UPB_FORCEINLINE +static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, wireval* val) { + uint32_t v = val->uint32_val; + + if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true; + + return decode_checkenum_slow(d, ptr, msg, e, field, v); +} + +UPB_NOINLINE +static const char* decode_enum_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + if (!decode_checkenum(d, ptr, msg, e, field, val)) return ptr; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + arr->len++; + memcpy(mem, val, 4); + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_fixed_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int mask = (1 << lg2) - 1; + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { + // Length isn't a round multiple of elem size. + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + decode_reserve(d, arr, count); + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + arr->len += count; + // Note: if/when the decoder supports multi-buffer input, we will need to + // handle buffer seams here. + if (_upb_IsLittleEndian()) { + memcpy(mem, ptr, val->size); + ptr += val->size; + } else { + const char* end = ptr + val->size; + char* dst = mem; + while (ptr < end) { + if (lg2 == 2) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + memcpy(dst, &val, sizeof(val)); + } else { + UPB_ASSERT(lg2 == 3); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + memcpy(dst, &val, sizeof(val)); + } + ptr += 1 << lg2; + dst += 1 << lg2; + } + } + + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_varint_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int scale = 1 << lg2; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge(field->descriptortype, &elem); + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + } + arr->len++; + memcpy(out, &elem, scale); + out += scale; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +UPB_NOINLINE +static const char* decode_enum_packed(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge_int32(&elem); + if (!decode_checkenum(d, ptr, msg, e, field, &elem)) { + continue; + } + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + } + arr->len++; + memcpy(out, &elem, 4); + out += 4; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +static const char* decode_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val, int op) { + upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array* arr = *arrp; + void* mem; + + if (arr) { + decode_reserve(d, arr, 1); + } else { + size_t lg2 = desctype_to_elem_size_lg2[field->descriptortype]; + arr = _upb_Array_New(&d->arena, 4, lg2); + if (!arr) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + *arrp = arr; + } + + switch (op) { + case OP_SCALAR_LG2(0): + case OP_SCALAR_LG2(2): + case OP_SCALAR_LG2(3): + /* Append scalar value. */ + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void); + arr->len++; + memcpy(mem, val, 1 << op); + return ptr; + case OP_STRING: + decode_verifyutf8(d, ptr, val->size); + /* Fallthrough. */ + case OP_BYTES: { + /* Append bytes. */ + upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->len; + arr->len++; + return decode_readstr(d, ptr, val->size, str); + } + case OP_SUBMSG: { + /* Append submessage / group. */ + upb_Message* submsg = decode_newsubmsg(d, subs, field); + *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void*), upb_Message*) = + submsg; + arr->len++; + if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) { + return decode_togroup(d, ptr, submsg, subs, field); + } else { + return decode_tosubmsg(d, ptr, submsg, subs, field, val->size); + } + } + case OP_FIXPCK_LG2(2): + case OP_FIXPCK_LG2(3): + return decode_fixed_packed(d, ptr, arr, val, field, + op - OP_FIXPCK_LG2(0)); + case OP_VARPCK_LG2(0): + case OP_VARPCK_LG2(2): + case OP_VARPCK_LG2(3): + return decode_varint_packed(d, ptr, arr, val, field, + op - OP_VARPCK_LG2(0)); + case OP_ENUM: + return decode_enum_toarray(d, ptr, msg, arr, subs, field, val); + case OP_PACKED_ENUM: + return decode_enum_packed(d, ptr, msg, arr, subs, field, val); + default: + UPB_UNREACHABLE(); + } +} + +static const char* decode_tomap(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map* map = *map_p; + upb_MapEntry ent; + const upb_MiniTable* entry = subs[field->submsg_index].submsg; + + if (!map) { + /* Lazily create map. */ + const upb_MiniTable_Field* key_field = &entry->fields[0]; + const upb_MiniTable_Field* val_field = &entry->fields[1]; + char key_size = desctype_to_mapsize[key_field->descriptortype]; + char val_size = desctype_to_mapsize[val_field->descriptortype]; + UPB_ASSERT(key_field->offset == 0); + UPB_ASSERT(val_field->offset == sizeof(upb_StringView)); + map = _upb_Map_New(&d->arena, key_size, val_size); + *map_p = map; + } + + /* Parse map entry. */ + memset(&ent, 0, sizeof(ent)); + + if (entry->fields[1].descriptortype == kUpb_FieldType_Message || + entry->fields[1].descriptortype == kUpb_FieldType_Group) { + /* Create proactively to handle the case where it doesn't appear. */ + ent.v.val = + upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); + } + + const char* start = ptr; + ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size); + // check if ent had any unknown fields + size_t size; + upb_Message_GetUnknown(&ent.k, &size); + if (size != 0) { + uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited; + upb_Decode_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start)); + if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } else { + if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size, + &d->arena) == _kUpb_MapInsertStatus_OutOfMemory) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } + return ptr; +} + +static const char* decode_tomsg(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, wireval* val, + int op) { + void* mem = UPB_PTR_AT(msg, field->offset, void); + int type = field->descriptortype; + + if (UPB_UNLIKELY(op == OP_ENUM) && + !decode_checkenum(d, ptr, msg, subs[field->submsg_index].subenum, field, + val)) { + return ptr; + } + + /* Set presence if necessary. */ + if (field->presence > 0) { + _upb_sethas_field(msg, field); + } else if (field->presence < 0) { + /* Oneof case */ + uint32_t* oneof_case = _upb_oneofcase_field(msg, field); + if (op == OP_SUBMSG && *oneof_case != field->number) { + memset(mem, 0, sizeof(void*)); + } + *oneof_case = field->number; + } + + /* Store into message. */ + switch (op) { + case OP_SUBMSG: { + upb_Message** submsgp = mem; + upb_Message* submsg = *submsgp; + if (!submsg) { + submsg = decode_newsubmsg(d, subs, field); + *submsgp = submsg; + } + if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { + ptr = decode_togroup(d, ptr, submsg, subs, field); + } else { + ptr = decode_tosubmsg(d, ptr, submsg, subs, field, val->size); + } + break; + } + case OP_STRING: + decode_verifyutf8(d, ptr, val->size); + /* Fallthrough. */ + case OP_BYTES: + return decode_readstr(d, ptr, val->size, mem); + case OP_SCALAR_LG2(3): + memcpy(mem, val, 8); + break; + case OP_ENUM: + case OP_SCALAR_LG2(2): + memcpy(mem, val, 4); + break; + case OP_SCALAR_LG2(0): + memcpy(mem, val, 1); + break; + default: + UPB_UNREACHABLE(); + } + + return ptr; +} + +UPB_NOINLINE +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l) { + assert(l->required_count); + if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { + return ptr; + } + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(l) & ~msg_head) { + d->missing_required = true; + } + return ptr; +} + +UPB_FORCEINLINE +static bool decode_tryfastdispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, + const upb_MiniTable* layout) { +#if UPB_FASTTABLE + if (layout && layout->table_mask != (unsigned char)-1) { + uint16_t tag = fastdecode_loadtag(*ptr); + intptr_t table = decode_totable(layout); + *ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag); + return true; + } +#endif + return false; +} + +static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, + uint32_t tag) { + int field_number = tag >> 3; + int wire_type = tag & 7; + switch (wire_type) { + case kUpb_WireType_Varint: { + uint64_t val; + return decode_varint64(d, ptr, &val); + } + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_Delimited: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + return ptr + size; + } + case kUpb_WireType_StartGroup: + return decode_group(d, ptr, NULL, NULL, field_number); + default: + decode_err(d, kUpb_DecodeStatus_Malformed); + } +} + +enum { + kStartItemTag = ((1 << 3) | kUpb_WireType_StartGroup), + kEndItemTag = ((1 << 3) | kUpb_WireType_EndGroup), + kTypeIdTag = ((2 << 3) | kUpb_WireType_Varint), + kMessageTag = ((3 << 3) | kUpb_WireType_Delimited), +}; + +static void upb_Decoder_AddKnownMessageSetItem( + upb_Decoder* d, upb_Message* msg, const upb_MiniTable_Extension* item_mt, + const char* data, uint32_t size) { + upb_Message_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); + if (UPB_UNLIKELY(!ext)) decode_err(d, kUpb_DecodeStatus_OutOfMemory); + upb_Message* submsg = decode_newsubmsg(d, &ext->ext->sub, &ext->ext->field); + upb_DecodeStatus status = upb_Decode(data, size, submsg, item_mt->sub.submsg, + d->extreg, d->options, &d->arena); + memcpy(&ext->data, &submsg, sizeof(submsg)); + if (status != kUpb_DecodeStatus_Ok) decode_err(d, status); +} + +static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, + upb_Message* msg, + uint32_t type_id, + const char* message_data, + uint32_t message_size) { + char buf[60]; + char* ptr = buf; + ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); + ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); + ptr = upb_Decoder_EncodeVarint32(type_id, ptr); + ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); + ptr = upb_Decoder_EncodeVarint32(message_size, ptr); + char* split = ptr; + + ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); + char* end = ptr; + + if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) || + !_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) || + !_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } +} + +static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, + const upb_MiniTable* layout, + uint32_t type_id, const char* data, + uint32_t size) { + const upb_MiniTable_Extension* item_mt = + _upb_extreg_get(d->extreg, layout, type_id); + if (item_mt) { + upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + } else { + upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + } +} + +static const char* upb_Decoder_DecodeMessageSetItem( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + uint32_t type_id = 0; + upb_StringView preserved = {NULL, 0}; + typedef enum { + kUpb_HaveId = 1 << 0, + kUpb_HavePayload = 1 << 1, + } StateMask; + StateMask state_mask = 0; + while (!decode_isdone(d, &ptr)) { + uint32_t tag; + ptr = decode_tag(d, ptr, &tag); + switch (tag) { + case kEndItemTag: + return ptr; + case kTypeIdTag: { + uint64_t tmp; + ptr = decode_varint64(d, ptr, &tmp); + if (state_mask & kUpb_HaveId) break; // Ignore dup. + state_mask |= kUpb_HaveId; + type_id = tmp; + if (state_mask & kUpb_HavePayload) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, + preserved.size); + } + break; + } + case kMessageTag: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + const char* data = ptr; + ptr += size; + if (state_mask & kUpb_HavePayload) break; // Ignore dup. + state_mask |= kUpb_HavePayload; + if (state_mask & kUpb_HaveId) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); + } else { + // Out of order, we must preserve the payload. + preserved.data = data; + preserved.size = size; + } + break; + } + default: + // We do not preserve unexpected fields inside a message set item. + ptr = upb_Decoder_SkipField(d, ptr, tag); + break; + } + } + decode_err(d, kUpb_DecodeStatus_Malformed); +} + +static const upb_MiniTable_Field* decode_findfield(upb_Decoder* d, + const upb_MiniTable* l, + uint32_t field_number, + int* last_field_index) { + static upb_MiniTable_Field none = {0, 0, 0, 0, 0, 0}; + if (l == NULL) return &none; + + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < l->dense_below) { + /* Fastest case: index into dense fields. */ + goto found; + } + + if (l->dense_below < l->field_count) { + /* Linear search non-dense fields. Resume scanning from last_field_index + * since fields are usually in order. */ + int last = *last_field_index; + for (idx = last; idx < l->field_count; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + + for (idx = l->dense_below; idx < last; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + } + + if (d->extreg) { + switch (l->ext) { + case kUpb_ExtMode_Extendable: { + const upb_MiniTable_Extension* ext = + _upb_extreg_get(d->extreg, l, field_number); + if (ext) return &ext->field; + break; + } + case kUpb_ExtMode_IsMessageSet: + if (field_number == _UPB_MSGSET_ITEM) { + static upb_MiniTable_Field item = {0, 0, 0, 0, TYPE_MSGSET_ITEM, 0}; + return &item; + } + break; + } + } + + return &none; /* Unknown field. */ + +found: + UPB_ASSERT(l->fields[idx].number == field_number); + *last_field_index = idx; + return &l->fields[idx]; +} + +UPB_FORCEINLINE +static const char* decode_wireval(upb_Decoder* d, const char* ptr, + const upb_MiniTable_Field* field, + int wire_type, wireval* val, int* op) { + switch (wire_type) { + case kUpb_WireType_Varint: + ptr = decode_varint64(d, ptr, &val->uint64_val); + *op = varint_ops[field->descriptortype]; + decode_munge(field->descriptortype, val); + return ptr; + case kUpb_WireType_32Bit: + memcpy(&val->uint32_val, ptr, 4); + val->uint32_val = _upb_BigEndian_Swap32(val->uint32_val); + *op = OP_SCALAR_LG2(2); + if (((1 << field->descriptortype) & FIXED32_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 4; + case kUpb_WireType_64Bit: + memcpy(&val->uint64_val, ptr, 8); + val->uint64_val = _upb_BigEndian_Swap64(val->uint64_val); + *op = OP_SCALAR_LG2(3); + if (((1 << field->descriptortype) & FIXED64_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 8; + case kUpb_WireType_Delimited: { + int ndx = field->descriptortype; + if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += TYPE_COUNT; + ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); + *op = delim_ops[ndx]; + return ptr; + } + case kUpb_WireType_StartGroup: + val->uint32_val = field->number; + if (field->descriptortype == kUpb_FieldType_Group) { + *op = OP_SUBMSG; + } else if (field->descriptortype == TYPE_MSGSET_ITEM) { + *op = OP_MSGSET_ITEM; + } else { + *op = OP_UNKNOWN; + } + return ptr; + default: + break; + } + return decode_err(d, kUpb_DecodeStatus_Malformed); +} + +UPB_FORCEINLINE +static const char* decode_known(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable* layout, + const upb_MiniTable_Field* field, int op, + wireval* val) { + const upb_MiniTable_Sub* subs = layout->subs; + uint8_t mode = field->mode; + + if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { + const upb_MiniTable_Extension* ext_layout = + (const upb_MiniTable_Extension*)field; + upb_Message_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); + if (UPB_UNLIKELY(!ext)) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + d->unknown_msg = msg; + msg = &ext->data; + subs = &ext->ext->sub; + } + + switch (mode & kUpb_FieldMode_Mask) { + case kUpb_FieldMode_Array: + return decode_toarray(d, ptr, msg, subs, field, val, op); + case kUpb_FieldMode_Map: + return decode_tomap(d, ptr, msg, subs, field, val); + case kUpb_FieldMode_Scalar: + return decode_tomsg(d, ptr, msg, subs, field, val, op); + default: + UPB_UNREACHABLE(); + } +} + +static const char* decode_reverse_skip_varint(const char* ptr, uint32_t val) { + uint32_t seen = 0; + do { + ptr--; + seen <<= 7; + seen |= *ptr & 0x7f; + } while (seen != val); + return ptr; +} + +static const char* decode_unknown(upb_Decoder* d, const char* ptr, + upb_Message* msg, int field_number, + int wire_type, wireval val) { + if (field_number == 0) return decode_err(d, kUpb_DecodeStatus_Malformed); + + // Since unknown fields are the uncommon case, we do a little extra work here + // to walk backwards through the buffer to find the field start. This frees + // up a register in the fast paths (when the field is known), which leads to + // significant speedups in benchmarks. + const char* start = ptr; + + if (wire_type == kUpb_WireType_Delimited) ptr += val.size; + if (msg) { + switch (wire_type) { + case kUpb_WireType_Varint: + case kUpb_WireType_Delimited: + start--; + while (start[-1] & 0x80) start--; + break; + case kUpb_WireType_32Bit: + start -= 4; + break; + case kUpb_WireType_64Bit: + start -= 8; + break; + default: + break; + } + + assert(start == d->debug_valstart); + uint32_t tag = ((uint32_t)field_number << 3) | wire_type; + start = decode_reverse_skip_varint(start, tag); + assert(start == d->debug_tagstart); + + if (wire_type == kUpb_WireType_StartGroup) { + d->unknown = start; + d->unknown_msg = msg; + ptr = decode_group(d, ptr, NULL, NULL, field_number); + start = d->unknown; + d->unknown = NULL; + } + if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { + return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } else if (wire_type == kUpb_WireType_StartGroup) { + ptr = decode_group(d, ptr, NULL, NULL, field_number); + } + return ptr; +} + +UPB_NOINLINE +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + int last_field_index = 0; + +#if UPB_FASTTABLE + // The first time we want to skip fast dispatch, because we may have just been + // invoked by the fast parser to handle a case that it bailed on. + if (!decode_isdone(d, &ptr)) goto nofast; +#endif + + while (!decode_isdone(d, &ptr)) { + uint32_t tag; + const upb_MiniTable_Field* field; + int field_number; + int wire_type; + wireval val; + int op; + + if (decode_tryfastdispatch(d, &ptr, msg, layout)) break; + +#if UPB_FASTTABLE + nofast: +#endif + +#ifndef NDEBUG + d->debug_tagstart = ptr; +#endif + + UPB_ASSERT(ptr < d->limit_ptr); + ptr = decode_tag(d, ptr, &tag); + field_number = tag >> 3; + wire_type = tag & 7; + +#ifndef NDEBUG + d->debug_valstart = ptr; +#endif + + if (wire_type == kUpb_WireType_EndGroup) { + d->end_group = field_number; + return ptr; + } + + field = decode_findfield(d, layout, field_number, &last_field_index); + ptr = decode_wireval(d, ptr, field, wire_type, &val, &op); + + if (op >= 0) { + ptr = decode_known(d, ptr, msg, layout, field, op, &val); + } else { + switch (op) { + case OP_UNKNOWN: + ptr = decode_unknown(d, ptr, msg, field_number, wire_type, val); + break; + case OP_MSGSET_ITEM: + ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); + break; + } + } + } + + return UPB_UNLIKELY(layout && layout->required_count) + ? decode_checkrequired(d, ptr, msg, layout) + : ptr; +} + +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + (void)data; + *(uint32_t*)msg |= hasbits; + return decode_msg(d, ptr, msg, decode_totablep(table)); +} + +static upb_DecodeStatus decode_top(struct upb_Decoder* d, const char* buf, + void* msg, const upb_MiniTable* l) { + if (!decode_tryfastdispatch(d, &buf, msg, l)) { + decode_msg(d, buf, msg, l); + } + if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; + if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; + return kUpb_DecodeStatus_Ok; +} + +upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena) { + upb_Decoder state; + unsigned depth = (unsigned)options >> 16; + + if (size <= 16) { + memset(&state.patch, 0, 32); + if (size) memcpy(&state.patch, buf, size); + buf = state.patch; + state.end = buf + size; + state.limit = 0; + options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf. + } else { + state.end = buf + size - 16; + state.limit = 16; + } + + state.extreg = extreg; + state.limit_ptr = state.end; + state.unknown = NULL; + state.depth = depth ? depth : 64; + state.end_group = DECODE_NOGROUP; + state.options = (uint16_t)options; + state.missing_required = false; + state.arena.head = arena->head; + state.arena.last_size = arena->last_size; + state.arena.cleanup_metadata = arena->cleanup_metadata; + state.arena.parent = arena; + + upb_DecodeStatus status = UPB_SETJMP(state.err); + if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) { + status = decode_top(&state, buf, msg, l); + } + + arena->head.ptr = state.arena.head.ptr; + arena->head.end = state.arena.head.end; + arena->cleanup_metadata = state.arena.cleanup_metadata; + return status; +} + +#undef OP_UNKNOWN +#undef OP_SKIP +#undef OP_SCALAR_LG2 +#undef OP_FIXPCK_LG2 +#undef OP_VARPCK_LG2 +#undef OP_STRING +#undef OP_BYTES +#undef OP_SUBMSG + +/** upb/encode.c ************************************************************/ +/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ + + +#include +#include + + +/* Must be last. */ + +#define UPB_PB_VARINT_MAX_LEN 10 + +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; +} + +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); +} + +typedef struct { + jmp_buf err; + upb_alloc* alloc; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; + +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; +} + +UPB_NORETURN static void encode_err(upb_encstate* e) { UPB_LONGJMP(e->err, 1); } + +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); + + if (!new_buf) encode_err(e); + + /* We want previous data at the end, realloc() put it at the beginning. */ + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); + } + + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + + e->ptr -= bytes; +} + +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ +UPB_FORCEINLINE +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); return; } - if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = kUpb_WellKnown_Any; - } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = kUpb_WellKnown_FieldMask; - } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = kUpb_WellKnown_Duration; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = kUpb_WellKnown_Timestamp; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = kUpb_WellKnown_DoubleValue; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = kUpb_WellKnown_FloatValue; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = kUpb_WellKnown_Int64Value; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = kUpb_WellKnown_UInt64Value; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = kUpb_WellKnown_Int32Value; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = kUpb_WellKnown_UInt32Value; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = kUpb_WellKnown_BoolValue; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = kUpb_WellKnown_StringValue; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = kUpb_WellKnown_BytesValue; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = kUpb_WellKnown_Value; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = kUpb_WellKnown_ListValue; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = kUpb_WellKnown_Struct; + + e->ptr -= bytes; +} + +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); +} + +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = _upb_BigEndian_Swap64(val); + encode_bytes(e, &val, sizeof(uint64_t)); +} + +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = _upb_BigEndian_Swap32(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} + +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; + + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; +} + +UPB_FORCEINLINE +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; } else { - m->well_known_type = kUpb_WellKnown_Unspecified; + encode_longvarint(e, val); } } -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { - return (upb_MessageDef*)&m[i]; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { - for (int i = 0; i < m->ext_range_count; i++) { - const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); - if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { - return true; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); +} + +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); +} + +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->len * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; + + if (tag || !_upb_IsLittleEndian()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + encode_bytes(e, &val, elem_size); + } + + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; } + } else { + encode_bytes(e, data, bytes); + } +} + +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); + +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const char* field_mem = _field_mem; + int wire_type; + +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } + + switch (f->descriptortype) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; + } + case kUpb_FieldType_Group: { + size_t size; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (submsg == NULL) { + return; + } + if (--e->depth == 0) encode_err(e); + encode_tag(e, f->number, kUpb_WireType_EndGroup); + encode_message(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; + } + case kUpb_FieldType_Message: { + size_t size; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (submsg == NULL) { + return; + } + if (--e->depth == 0) encode_err(e); + encode_message(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; + } + default: + UPB_UNREACHABLE(); + } +#undef CASE + + encode_tag(e, f->number, wire_type); +} + +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + bool packed = f->mode & kUpb_LabelFlags_IsPacked; + size_t pre_len = e->limit - e->ptr; + + if (arr == NULL || arr->len == 0) { + return; + } + +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->len; \ + uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; + +#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) + + switch (f->descriptortype) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->len; + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (--e->depth == 0) encode_err(e); + do { + size_t size; + ptr--; + encode_tag(e, f->number, kUpb_WireType_EndGroup); + encode_message(e, *ptr, subm, &size); + encode_tag(e, f->number, kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (--e->depth == 0) encode_err(e); + do { + size_t size; + ptr--; + encode_message(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } + } +#undef VARINT_CASE + + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } +} + +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTable_Field* key_field = &layout->fields[0]; + const upb_MiniTable_Field* val_field = &layout->fields[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->v, layout->subs, val_field); + encode_scalar(e, &ent->k, layout->subs, key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); +} + +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_MiniTable* layout = subs[f->submsg_index].submsg; + UPB_ASSERT(layout->field_count == 2); + + if (map == NULL) return; + + if (e->options & kUpb_Encode_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map, + &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->number, layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + upb_strtable_iter i; + upb_strtable_begin(&i, &map->table); + for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { + upb_StringView key = upb_strtable_iter_key(&i); + const upb_value val = upb_strtable_iter_value(&i); + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.k, map->key_size); + _upb_map_fromvalue(val, &ent.v, map->val_size); + encode_mapentry(e, f->number, layout, &ent); + } + } +} + +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + if (f->presence == 0) { + /* Proto3 presence or map/array. */ + const void* mem = UPB_PTR_AT(msg, f->offset, void); + switch (f->mode >> kUpb_FieldRep_Shift) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } +#if UINTPTR_MAX == 0xffffffff + case kUpb_FieldRep_Pointer: +#endif + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } +#if UINTPTR_MAX != 0xffffffff + case kUpb_FieldRep_Pointer: +#endif + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + /* Proto2 presence: hasbit. */ + return _upb_hasbit_field(msg, f); + } else { + /* Field is in a oneof. */ + return _upb_getoneofcase_field(msg, f) == f->number; + } +} + +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + switch (upb_FieldMode_Get(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + break; + default: + UPB_UNREACHABLE(); + } +} + +/* message MessageSet { + * repeated group Item = 1 { + * required int32 type_id = 2; + * required string message = 3; + * } + * } */ +static void encode_msgset_item(upb_encstate* e, + const upb_Message_Extension* ext) { + size_t size; + encode_tag(e, 1, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size); + encode_varint(e, size); + encode_tag(e, 3, kUpb_WireType_Delimited); + encode_varint(e, ext->ext->field.number); + encode_tag(e, 2, kUpb_WireType_Varint); + encode_tag(e, 1, kUpb_WireType_StartGroup); +} + +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; + + if ((e->options & kUpb_Encode_CheckRequired) && m->required_count) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(m) & ~msg_head) { + encode_err(e); + } + } + + if ((e->options & kUpb_Encode_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); + + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } + } + + if (m->ext != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + if (ext_count) { + const upb_Message_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + if (UPB_UNLIKELY(m->ext == kUpb_ExtMode_IsMessageSet)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field); + } + } + } + } + + if (m->field_count) { + const upb_MiniTable_Field* f = &m->fields[m->field_count]; + const upb_MiniTable_Field* first = &m->fields[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->subs, f)) { + encode_field(e, msg, m->subs, f); + } + } + } + + *size = (e->limit - e->ptr) - pre_len; +} + +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; + + e.alloc = upb_Arena_Alloc(arena); + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : 64; + e.options = options; + _upb_mapsorter_init(&e.sorter); + char* ret = NULL; + + if (UPB_SETJMP(e.err)) { + *size = 0; + ret = NULL; + } else { + encode_message(&e, msg, l, size); + *size = e.limit - e.ptr; + if (*size == 0) { + static char ch; + ret = &ch; + } else { + UPB_ASSERT(e.ptr); + ret = e.ptr; + } + } + + _upb_mapsorter_destroy(&e.sorter); + return ret; +} + +/** upb/msg.c ************************************************************/ + + +/** upb_Message ***************************************************************/ + +static const size_t overhead = sizeof(upb_Message_InternalData); + +static const upb_Message_Internal* upb_Message_Getinternal_const( + const upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} + +upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) { + return _upb_Message_New_inl(l, a); +} + +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { + void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); + memset(mem, 0, upb_msg_sizeof(l)); +} + +static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena) { + if (!realloc_internal(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; +} + +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = overhead; + } +} + +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; + } +} + +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(upb_Message_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* e) { + size_t n; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); + + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const upb_Message_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(upb_Message_Extension); + } +} + +upb_Message_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(upb_Message_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_Message_Extension)); + ext->ext = e; + return ext; +} + +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + _upb_Message_Getexts(msg, &count); + return count; +} + +/** upb_Array *****************************************************************/ + +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena) { + size_t new_size = UPB_MAX(arr->size, 4); + int elem_size_lg2 = arr->data & 7; + size_t old_bytes = arr->size << elem_size_lg2; + size_t new_bytes; + void* ptr = _upb_array_ptr(arr); + + /* Log2 ceiling of size. */ + while (new_size < min_size) new_size *= 2; + + new_bytes = new_size << elem_size_lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + + if (!ptr) { + return false; + } + + arr->data = _upb_tag_arrptr(ptr, elem_size_lg2); + arr->size = new_size; + return true; +} + +static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2, + upb_Arena* arena) { + upb_Array* arr = *arr_ptr; + if (!arr) { + arr = _upb_Array_New(arena, 4, elem_size_lg2); + if (!arr) return NULL; + *arr_ptr = arr; + } + return arr; +} + +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); + return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr) + : NULL; +} + +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); + if (!arr) return false; + + size_t elems = arr->len; + + if (!_upb_Array_Resize(arr, elems + 1, arena)) { + return false; + } + + char* data = _upb_array_ptr(arr); + memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2); + return true; +} + +/** upb_Map *******************************************************************/ + +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); + + if (!map) { + return NULL; + } + + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; + + return map; +} + +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); +} + +#define UPB_COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1)) + +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return UPB_COMPARE_INTEGERS(a.size, b.size); +} + +#undef UPB_COMPARE_INTEGERS + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + map_size; + + /* Grow s->entries if necessary. */ + if (sorted->end > s->cap) { + s->cap = _upb_Log2CeilingSize(sorted->end); + s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); + if (!s->entries) return false; + } + + s->size = sorted->end; + + /* Copy non-empty entries from the table to s->entries. */ + upb_tabent const** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; + } + } + UPB_ASSERT(dst == &s->entries[sorted->end]); + + /* Sort entries according to the key type. */ + + int (*compar)(const void*, const void*); + + switch (key_type) { + case kUpb_FieldType_Int64: + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_SInt64: + compar = _upb_mapsorter_cmpi64; + break; + case kUpb_FieldType_UInt64: + case kUpb_FieldType_Fixed64: + compar = _upb_mapsorter_cmpu64; + break; + case kUpb_FieldType_Int32: + case kUpb_FieldType_SInt32: + case kUpb_FieldType_SFixed32: + case kUpb_FieldType_Enum: + compar = _upb_mapsorter_cmpi32; + break; + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Fixed32: + compar = _upb_mapsorter_cmpu32; + break; + case kUpb_FieldType_Bool: + compar = _upb_mapsorter_cmpbool; + break; + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: + compar = _upb_mapsorter_cmpstr; + break; + default: + UPB_UNREACHABLE(); + } + + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), compar); + return true; +} + +/** upb_ExtensionRegistry *****************************************************/ + +struct upb_ExtensionRegistry { + upb_Arena* arena; + upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */ +}; + +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) + +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +} + +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} + +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count) { + char buf[EXTREG_KEY_SIZE]; + const upb_MiniTable_Extension** start = e; + const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); + upb_value v; + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + goto failure; + } + if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(ext), r->arena)) { + goto failure; + } + } + return true; + +failure: + /* Back out the entries previously added. */ + for (end = e, e = start; e < end; e++) { + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); } return false; } -const google_protobuf_MessageOptions* upb_MessageDef_Options( - const upb_MessageDef* m) { - return m->opts; -} - -bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_MessageDef_FullName(const upb_MessageDef* m) { - return m->full_name; -} - -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { - return m->file; -} - -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { - return m->containing_type; -} - -const char* upb_MessageDef_Name(const upb_MessageDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { - return upb_FileDef_Syntax(m->file); -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i) { - upb_value val; - return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) - : NULL; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); -} - -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, - upb_value v, upb_Arena* a) { - return upb_strtable_insert(&m->ntof, name, len, v, a); -} - -bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t len, - const upb_FieldDef** out_f, - const upb_OneofDef** out_o) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { - return false; - } - - const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); - if (out_f) *out_f = f; - if (out_o) *out_o = o; - return f || o; /* False if this was a JSON name. */ -} - -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - const upb_FieldDef* f; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - if (!f) f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD_JSONNAME); - - return f; -} - -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { - return m->ext_range_count; -} - -int upb_MessageDef_FieldCount(const upb_MessageDef* m) { - return m->field_count; -} - -int upb_MessageDef_OneofCount(const upb_MessageDef* m) { - return m->oneof_count; -} - -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { - return m->nested_msg_count; -} - -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { - return m->nested_enum_count; -} - -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { - return m->nested_ext_count; -} - -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { - return m->layout; -} - -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->ext_range_count); - return _upb_ExtensionRange_At(m->ext_ranges, i); -} - -const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->field_count); - return _upb_FieldDef_At(m->fields, i); -} - -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->oneof_count); - return _upb_OneofDef_At(m->oneofs, i); -} - -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_msg_count); - return &m->nested_msgs[i]; -} - -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->nested_enum_count); - return _upb_EnumDef_At(m->nested_enums, i); -} - -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_ext_count); - return _upb_FieldDef_At(m->nested_exts, i); -} - -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { - return m->well_known_type; -} - -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { - return m->in_message_set; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); -} - -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); -} - -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(m)); -} - -static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { - return upb_MiniTable_BuildMessageSet(kUpb_MiniTablePlatform_Native, - ctx->arena); - } - - if (upb_MessageDef_IsMapEntry(m)) { - if (m->field_count != 2) { - _upb_DefBuilder_Errf(ctx, "invalid map (%s)", m->full_name); - } - - const upb_FieldDef* f0 = upb_MessageDef_Field(m, 0); - const upb_FieldDef* f1 = upb_MessageDef_Field(m, 1); - const upb_FieldType t0 = upb_FieldDef_Type(f0); - const upb_FieldType t1 = upb_FieldDef_Type(f1); - - const bool is_proto3_enum = - (t1 == kUpb_FieldType_Enum) && !_upb_FieldDef_IsClosedEnum(f1); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f0) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f1) == 1); - - return upb_MiniTable_BuildMapEntry( - t0, t1, is_proto3_enum, kUpb_MiniTablePlatform_Native, ctx->arena); - } - - upb_StringView desc; - bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); - size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( - desc.data, desc.size, kUpb_MiniTablePlatform_Native, ctx->arena, - scratch_data, scratch_size, ctx->status); - if (!ret) _upb_DefBuilder_FailJmp(ctx); - return ret; -} - -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), f); - } - - if (!ctx->layout) { - m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); - if (!m->layout) _upb_DefBuilder_OomErr(ctx); - } - - m->in_message_set = false; - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), ext); - if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && - upb_FieldDef_Label(ext) == kUpb_Label_Optional && - upb_FieldDef_MessageSubDef(ext) == m && - google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { - m->in_message_set = true; - } - } - - for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { - upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_Resolve(ctx, n); - } -} - -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f) { - const int32_t field_number = upb_FieldDef_Number(f); - - if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { - _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); - } - - const char* json_name = upb_FieldDef_JsonName(f); - const char* shortname = upb_FieldDef_Name(f); - const size_t shortnamelen = strlen(shortname); - - upb_value v = upb_value_constptr(f); - - upb_value existing_v; - if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); - } - - const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); - bool ok = - _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - if (strcmp(shortname, json_name) != 0) { - if (upb_strtable_lookup(&m->ntof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); - } - - const size_t json_size = strlen(json_name); - const upb_value json_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD_JSONNAME); - ok = _upb_MessageDef_Insert(m, json_name, json_size, json_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } - - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); - } - - ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); - - UPB_ASSERT(layout_index < m->field_count); - upb_MiniTable_Field* mt_f = - (upb_MiniTable_Field*)&m->layout->fields[layout_index]; - if (sub_m) { - if (!mt->subs) { - _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); - } - UPB_ASSERT(mt_f); - UPB_ASSERT(sub_m->layout); - upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - upb_MiniTable_SetSubEnum(mt, mt_f, _upb_EnumDef_MiniTable(sub_e)); - } - } - - for (int i = 0; i < m->nested_msg_count; i++) { - _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); - } -} - -static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { - uint64_t out = 0; - if (upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3) { - out |= kUpb_MessageModifier_ValidateUtf8; - out |= kUpb_MessageModifier_DefaultIsPacked; - } - if (m->ext_range_count) { - out |= kUpb_MessageModifier_IsExtendable; - } - return out; -} - -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_FieldDef** sorted = NULL; - if (!m->is_sorted) { - sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = - upb_MtDataEncoder_StartMessage(&s.e, s.ptr, _upb_MessageDef_Modifiers(m)); - - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); - const upb_FieldType type = upb_FieldDef_Type(f); - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, type, number, modifiers); - } - - for (int i = 0; i < m->oneof_count; i++) { - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartOneof(&s.e, s.ptr); - - const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); - const int field_count = upb_OneofDef_FieldCount(o); - for (int j = 0; j < field_count; j++) { - const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutOneofField(&s.e, s.ptr, number); - } - } - - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_DescriptorProto* msg_proto, - const upb_MessageDef* containing_type, - upb_MessageDef* m) { - const google_protobuf_OneofDescriptorProto* const* oneofs; - const google_protobuf_FieldDescriptorProto* const* fields; - const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; - size_t n_oneof, n_field, n_ext_range, n_enum, n_ext, n_msg; - upb_StringView name; - - // Must happen before _upb_DefBuilder_Add() - m->file = _upb_DefBuilder_File(ctx); - - m->containing_type = containing_type; - m->is_sorted = true; - - name = google_protobuf_DescriptorProto_name(msg_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - - m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); - - oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); - fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); - ext_ranges = google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); - - bool ok = upb_inttable_init(&m->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - if (ctx->layout) { - /* create_fielddef() below depends on this being set. */ - UPB_ASSERT(ctx->msg_count < ctx->layout->msg_count); - m->layout = ctx->layout->msgs[ctx->msg_count++]; - UPB_ASSERT(n_field == m->layout->field_count); +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, l, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); } else { - /* Allocate now (to allow cross-linking), populate later. */ - m->layout = _upb_DefBuilder_Alloc( - ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); + return NULL; } - - UBP_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); - - m->field_count = n_field; - m->fields = - _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); - - m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); - - const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); - m->real_oneof_count = m->oneof_count - synthetic_count; - - assign_msg_wellknowntype(m); - upb_inttable_compact(&m->itof, ctx->arena); - - const google_protobuf_EnumDescriptorProto* const* enums = - google_protobuf_DescriptorProto_enum_type(msg_proto, &n_enum); - m->nested_enum_count = n_enum; - m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); - - const google_protobuf_FieldDescriptorProto* const* exts = - google_protobuf_DescriptorProto_extension(msg_proto, &n_ext); - m->nested_ext_count = n_ext; - m->nested_exts = _upb_FieldDefs_New(ctx, n_ext, exts, m->full_name, m, NULL); - - const google_protobuf_DescriptorProto* const* msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n_msg); - m->nested_msg_count = n_msg; - m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); -} - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); - - const char* name = containing_type ? containing_type->full_name - : _upb_FileDef_RawPackage(ctx->file); - - upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); - for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], containing_type, &m[i]); - } - return m; -} - - - -// Must be last. - -struct upb_MethodDef { - const google_protobuf_MethodOptions* opts; - upb_ServiceDef* service; - const char* full_name; - const upb_MessageDef* input_type; - const upb_MessageDef* output_type; - int index; - bool client_streaming; - bool server_streaming; -}; - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { - return (upb_MethodDef*)&m[i]; -} - -const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { - return m->service; -} - -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m) { - return m->opts; -} - -bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_MethodDef_FullName(const upb_MethodDef* m) { - return m->full_name; -} - -const char* upb_MethodDef_Name(const upb_MethodDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } - -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { - return m->input_type; -} - -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { - return m->output_type; -} - -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { - return m->client_streaming; -} - -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { - return m->server_streaming; -} - -static void create_method(upb_DefBuilder* ctx, - const google_protobuf_MethodDescriptorProto* method_proto, - upb_ServiceDef* s, upb_MethodDef* m) { - upb_StringView name = google_protobuf_MethodDescriptorProto_name(method_proto); - - m->service = s; - m->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); - m->client_streaming = - google_protobuf_MethodDescriptorProto_client_streaming(method_proto); - m->server_streaming = - google_protobuf_MethodDescriptorProto_server_streaming(method_proto); - m->input_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_input_type(method_proto), UPB_DEFTYPE_MSG); - m->output_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_output_type(method_proto), UPB_DEFTYPE_MSG); - - UBP_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); -} - -// Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s) { - upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); - for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], s, &m[i]); - m[i].index = i; - } - return m; -} - - -#include -#include -#include - - -// Must be last. - -struct upb_OneofDef { - const google_protobuf_OneofOptions* opts; - const upb_MessageDef* parent; - const char* full_name; - int field_count; - bool synthetic; - const upb_FieldDef** fields; - upb_strtable ntof; // lookup a field by name - upb_inttable itof; // lookup a field by number (index) -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { - return (upb_OneofDef*)&o[i]; -} - -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o) { - return o->opts; -} - -bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { - return o->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_OneofDef_FullName(const upb_OneofDef* o) { - return o->full_name; -} - -const char* upb_OneofDef_Name(const upb_OneofDef* o) { - return _upb_DefBuilder_FullToShort(o->full_name); -} - -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { - return o->parent; -} - -int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } - -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; -} - -int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - -uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { - // Compute index in our parent's array. - return o - upb_MessageDef_Oneof(o->parent, 0); -} - -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } - -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, size, &val) - ? upb_value_getptr(val) - : NULL; -} - -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name) { - return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); -} - -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; -} - -bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, - const char* name, size_t size, upb_Arena* a) { - o->field_count++; - if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - - const int number = upb_FieldDef_Number(f); - const upb_value v = upb_value_constptr(f); - return upb_inttable_insert(&o->itof, number, v, a) && - upb_strtable_insert(&o->ntof, name, size, v, a); -} - -// Returns the synthetic count. -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { - int synthetic_count = 0; - - for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { - upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - - if (o->synthetic && o->field_count != 1) { - _upb_DefBuilder_Errf(ctx, - "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_OneofDef_Name(o)); - } - - if (o->synthetic) { - synthetic_count++; - } else if (synthetic_count != 0) { - _upb_DefBuilder_Errf( - ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_OneofDef_Name(o)); - } - - o->fields = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); - o->field_count = 0; - } - - for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); - if (o) { - o->fields[o->field_count++] = f; - } - } - - return synthetic_count; -} - -static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const google_protobuf_OneofDescriptorProto* oneof_proto, - const upb_OneofDef* _o) { - upb_OneofDef* o = (upb_OneofDef*)_o; - upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); - - o->parent = m; - o->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); - o->field_count = 0; - o->synthetic = false; - - UBP_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); - } - - upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); - bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&o->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&o->ntof, 4, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - - upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); - for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], &o[i]); - } - return o; -} - - - -// Must be last. - -struct upb_ServiceDef { - const google_protobuf_ServiceOptions* opts; - const upb_FileDef* file; - const char* full_name; - upb_MethodDef* methods; - int method_count; - int index; -}; - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { - return (upb_ServiceDef*)&s[index]; -} - -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s) { - return s->opts; -} - -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { - return s->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { - return s->full_name; -} - -const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { - return _upb_DefBuilder_FullToShort(s->full_name); -} - -int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } - -const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { - return s->file; -} - -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { - return s->method_count; -} - -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { - return (i < 0 || i >= s->method_count) ? NULL - : _upb_MethodDef_At(s->methods, i); -} - -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name) { - for (int i = 0; i < s->method_count; i++) { - const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); - if (strcmp(name, upb_MethodDef_Name(m)) == 0) { - return m; - } - } - return NULL; -} - -static void create_service(upb_DefBuilder* ctx, - const google_protobuf_ServiceDescriptorProto* svc_proto, - upb_ServiceDef* s) { - upb_StringView name; - size_t n; - - // Must happen before _upb_DefBuilder_Add() - s->file = _upb_DefBuilder_File(ctx); - - name = google_protobuf_ServiceDescriptorProto_name(svc_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - const char* package = _upb_FileDef_RawPackage(s->file); - s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); - _upb_DefBuilder_Add(ctx, s->full_name, - _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); - - const google_protobuf_MethodDescriptorProto* const* methods = - google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); - s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - - UBP_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); -} - -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos) { - _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); - - upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); - for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], &s[i]); - s[i].index = i; - } - return s; } +/** upb/table.c ************************************************************/ /* * upb_table Implementation * * Implementation is heavily inspired by Lua's ltable.c. */ - #include -// Must be last. + +/* Must be last. */ #define UPB_MAXARRSIZE 16 /* 64k. */ @@ -10373,39 +12485,66 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter* i1, i1->array_part == i2->array_part; } +/** upb/upb.c ************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + // Must be last. -int upb_Unicode_ToUTF8(uint32_t cp, char* out) { - if (cp <= 0x7f) { - out[0] = cp; - return 1; - } - if (cp <= 0x07ff) { - out[0] = (cp >> 6) | 0xc0; - out[1] = (cp & 0x3f) | 0x80; - return 2; - } - if (cp <= 0xffff) { - out[0] = (cp >> 12) | 0xe0; - out[1] = ((cp >> 6) & 0x3f) | 0x80; - out[2] = (cp & 0x3f) | 0x80; - return 3; - } - if (cp <= 0x10ffff) { - out[0] = (cp >> 18) | 0xf0; - out[1] = ((cp >> 12) & 0x3f) | 0x80; - out[2] = ((cp >> 6) & 0x3f) | 0x80; - out[3] = (cp & 0x3f) | 0x80; - return 4; - } - return 0; +/* upb_Status *****************************************************************/ + +void upb_Status_Clear(upb_Status* status) { + if (!status) return; + status->ok = true; + status->msg[0] = '\0'; } +bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } -#include +const char* upb_Status_ErrorMessage(const upb_Status* status) { + return status->msg; +} -// Must be last. +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { + if (!status) return; + status->ok = false; + strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + upb_Status_VSetErrorFormat(status, fmt, args); + va_end(args); +} + +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + if (!status) return; + status->ok = false; + vsnprintf(status->msg, sizeof(status->msg), fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + size_t len; + if (!status) return; + status->ok = false; + len = strlen(status->msg); + vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +/* upb_alloc ******************************************************************/ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size) { @@ -10419,11 +12558,6 @@ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, } } -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; - - -// Must be last. - static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { return (uint32_t*)(cleanup_metadata & ~0x1); } @@ -10437,6 +12571,10 @@ static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, return (uintptr_t)cleanup | has_initial_block; } +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; + +/* upb_Arena ******************************************************************/ + struct mem_block { struct mem_block* next; uint32_t size; @@ -10463,24 +12601,6 @@ static upb_Arena* arena_findroot(upb_Arena* a) { return a; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = arena_findroot(arena); - size_t memsize = 0; - - mem_block* block = arena->freelist; - - while (block) { - memsize += sizeof(mem_block) + block->size; - block = block->next; - } - - return memsize; -} - -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { - return arena_findroot(arena)->refcount; -} - static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, size_t size) { mem_block* block = ptr; @@ -10525,7 +12645,7 @@ static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, /* Public Arena API ***********************************************************/ -static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { +upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; upb_Arena* a; @@ -10580,7 +12700,6 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { a->head.ptr = mem; a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); a->freelist = NULL; - a->freelist_tail = NULL; a->cleanup_metadata = upb_cleanup_metadata(NULL, true); return a; @@ -10667,2268 +12786,6 @@ bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { return true; } - -#include - -// Must be last. - -static const char _upb_CTypeo_sizelg2[12] = { - 0, - 0, /* kUpb_CType_Bool */ - 2, /* kUpb_CType_Float */ - 2, /* kUpb_CType_Int32 */ - 2, /* kUpb_CType_UInt32 */ - 2, /* kUpb_CType_Enum */ - UPB_SIZE(2, 3), /* kUpb_CType_Message */ - 3, /* kUpb_CType_Double */ - 3, /* kUpb_CType_Int64 */ - 3, /* kUpb_CType_UInt64 */ - UPB_SIZE(3, 4), /* kUpb_CType_String */ - UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ -}; - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); -} - -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - if (!upb_Array_Resize(arr, arr->size + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->size - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - size_t oldsize = arr->size; - if (!upb_Array_Resize(arr, arr->size + count, arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - return _upb_Array_Resize(arr, size, arena); -} - - -#include - - -// Must be last. - -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; - -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, - - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - kUpb_DecodeOp_Enum = 1, - - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, - - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; - -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; - -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); - -UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, - upb_DecodeStatus status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); -} - -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); - return NULL; -} -static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { - if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); - } -} - -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->capacity - arr->size < elem; - if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; -} - -typedef struct { - const char* ptr; - uint64_t val; -} _upb_DecodeLongVarintReturn; - -UPB_NOINLINE -static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( - const char* ptr, uint64_t val) { - _upb_DecodeLongVarintReturn ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; - } - } - return ret; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, - uint64_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - *val = res.val; - return res.ptr; - } -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, - uint32_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - const char* start = ptr; - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *val = res.val; - return res.ptr; - } -} - -UPB_FORCEINLINE -static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { - uint64_t size64; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); - if (size64 >= INT32_MAX || ptr - d->end + (int)size64 > d->limit) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *size = size64; - return ptr; -} - -static void _upb_Decoder_MungeInt32(wireval* val) { - if (!_upb_IsLittleEndian()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; - } -} - -static void _upb_Decoder_Munge(int type, wireval* val) { - switch (type) { - case kUpb_FieldType_Bool: - val->bool_val = val->uint64_val != 0; - break; - case kUpb_FieldType_SInt32: { - uint32_t n = val->uint64_val; - val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_FieldType_SInt64: { - uint64_t n = val->uint64_val; - val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); - break; - } - case kUpb_FieldType_Int32: - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Enum: - _upb_Decoder_MungeInt32(val); - break; - } -} - -static upb_Message* _upb_Decoder_NewSubMessage( - upb_Decoder* d, const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field) { - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - upb_Message* msg = _upb_Message_New_inl(subl, &d->arena); - if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return msg; -} - -UPB_NOINLINE -const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr, - int overrun) { - int status; - ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status); - if (ptr == NULL) _upb_Decoder_ErrorJmp(d, status); - return ptr; -} - -static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, - int size, upb_StringView* str) { - if (d->options & kUpb_DecodeOption_AliasString) { - str->data = ptr; - } else { - char* data = upb_Arena_Malloc(&d->arena, size); - if (!data) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - memcpy(data, ptr, size); - str->data = data; - } - str->size = size; - return ptr + size; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, - const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { - if (--d->depth < 0) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); - } - ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); - d->depth++; - if (d->end_group != expected_end_group) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) { - int saved_delta = _upb_Decoder_PushLimit(d, ptr, size); - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); - _upb_Decoder_PopLimit(d, ptr, saved_delta); - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { - if (_upb_Decoder_IsDone(d, &ptr)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); - d->end_group = DECODE_NOGROUP; - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, - const char* ptr, - uint32_t number) { - return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownGroup( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) { - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number); -} - -static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - *(ptr++) = byte; - } while (val); - return ptr; -} - -static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, - uint32_t val1, uint32_t val2) { - char buf[20]; - char* end = buf; - end = upb_Decoder_EncodeVarint32(val1, end); - end = upb_Decoder_EncodeVarint32(val2, end); - - if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } -} - -UPB_NOINLINE -static bool _upb_Decoder_CheckEnumSlow(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Enum* e, - const upb_MiniTable_Field* field, - uint32_t v) { - if (_upb_MiniTable_CheckEnumValueSlow(e, v)) return true; - - // Unrecognized enum goes into unknown fields. - // For packed fields the tag could be arbitrarily far in the past, so we - // just re-encode the tag and value here. - uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; - upb_Message* unknown_msg = - field->mode & kUpb_LabelFlags_IsExtension ? d->unknown_msg : msg; - _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); - return false; -} - -UPB_FORCEINLINE -static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Enum* e, - const upb_MiniTable_Field* field, - wireval* val) { - uint32_t v = val->uint32_val; - - _kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, v); - if (UPB_LIKELY(status == _kUpb_FastEnumCheck_ValueIsInEnum)) return true; - return _upb_Decoder_CheckEnumSlow(d, ptr, msg, e, field, v); -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumArray( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val) { - const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - arr->size++; - memcpy(mem, val, 4); - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeFixedPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTable_Field* field, int lg2) { - int mask = (1 << lg2) - 1; - size_t count = val->size >> lg2; - if ((val->size & mask) != 0) { - // Length isn't a round multiple of elem size. - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - arr->size += count; - // Note: if/when the decoder supports multi-buffer input, we will need to - // handle buffer seams here. - if (_upb_IsLittleEndian()) { - memcpy(mem, ptr, val->size); - ptr += val->size; - } else { - const char* end = ptr + val->size; - char* dst = mem; - while (ptr < end) { - if (lg2 == 2) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - memcpy(dst, &val, sizeof(val)); - } else { - UPB_ASSERT(lg2 == 3); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - memcpy(dst, &val, sizeof(val)); - } - ptr += 1 << lg2; - dst += 1 << lg2; - } - } - - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarintPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTable_Field* field, int lg2) { - int scale = 1 << lg2; - int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_Munge(field->descriptortype, &elem); - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - } - arr->size++; - memcpy(out, &elem, scale); - out += scale; - } - _upb_Decoder_PopLimit(d, ptr, saved_limit); - return ptr; -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumPacked( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val) { - const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; - int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_MungeInt32(&elem); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { - continue; - } - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - } - arr->size++; - memcpy(out, &elem, 4); - out += 4; - } - _upb_Decoder_PopLimit(d, ptr, saved_limit); - return ptr; -} - -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTable_Field* field) { - /* Maps descriptor type -> elem_size_lg2. */ - static const uint8_t kElemSizeLg2[] = { - [0] = -1, // invalid descriptor type - [kUpb_FieldType_Double] = 3, - [kUpb_FieldType_Float] = 2, - [kUpb_FieldType_Int64] = 3, - [kUpb_FieldType_UInt64] = 3, - [kUpb_FieldType_Int32] = 2, - [kUpb_FieldType_Fixed64] = 3, - [kUpb_FieldType_Fixed32] = 2, - [kUpb_FieldType_Bool] = 0, - [kUpb_FieldType_String] = UPB_SIZE(3, 4), - [kUpb_FieldType_Group] = UPB_SIZE(2, 3), - [kUpb_FieldType_Message] = UPB_SIZE(2, 3), - [kUpb_FieldType_Bytes] = UPB_SIZE(3, 4), - [kUpb_FieldType_UInt32] = 2, - [kUpb_FieldType_Enum] = 2, - [kUpb_FieldType_SFixed32] = 2, - [kUpb_FieldType_SFixed64] = 3, - [kUpb_FieldType_SInt32] = 2, - [kUpb_FieldType_SInt64] = 3, - }; - - size_t lg2 = kElemSizeLg2[field->descriptortype]; - upb_Array* ret = _upb_Array_New(&d->arena, 4, lg2); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field, - wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); - upb_Array* arr = *arrp; - void* mem; - - if (arr) { - _upb_Decoder_Reserve(d, arr, 1); - } else { - arr = _upb_Decoder_CreateArray(d, field); - *arrp = arr; - } - - switch (op) { - case kUpb_DecodeOp_Scalar1Byte: - case kUpb_DecodeOp_Scalar4Byte: - case kUpb_DecodeOp_Scalar8Byte: - /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << op, void); - arr->size++; - memcpy(mem, val, 1 << op); - return ptr; - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: { - /* Append bytes. */ - upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size; - arr->size++; - return _upb_Decoder_ReadString(d, ptr, val->size, str); - } - case kUpb_DecodeOp_SubMessage: { - /* Append submessage / group. */ - upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field); - *UPB_PTR_AT(_upb_array_ptr(arr), arr->size * sizeof(void*), - upb_Message*) = submsg; - arr->size++; - if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) { - return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - } - case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): - return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, - op - OP_FIXPCK_LG2(0)); - case OP_VARPCK_LG2(0): - case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): - return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, - op - OP_VARPCK_LG2(0)); - case kUpb_DecodeOp_Enum: - return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); - case kUpb_DecodeOp_PackedEnum: - return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); - default: - UPB_UNREACHABLE(); - } -} - -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ - static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ - [kUpb_FieldType_Double] = 8, - [kUpb_FieldType_Float] = 4, - [kUpb_FieldType_Int64] = 8, - [kUpb_FieldType_UInt64] = 8, - [kUpb_FieldType_Int32] = 4, - [kUpb_FieldType_Fixed64] = 8, - [kUpb_FieldType_Fixed32] = 4, - [kUpb_FieldType_Bool] = 1, - [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_Group] = sizeof(void*), - [kUpb_FieldType_Message] = sizeof(void*), - [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_UInt32] = 4, - [kUpb_FieldType_Enum] = 4, - [kUpb_FieldType_SFixed32] = 4, - [kUpb_FieldType_SFixed64] = 8, - [kUpb_FieldType_SInt32] = 4, - [kUpb_FieldType_SInt64] = 8, - }; - - const upb_MiniTable_Field* key_field = &entry->fields[0]; - const upb_MiniTable_Field* val_field = &entry->fields[1]; - char key_size = kSizeInMap[key_field->descriptortype]; - char val_size = kSizeInMap[val_field->descriptortype]; - UPB_ASSERT(key_field->offset == 0); - UPB_ASSERT(val_field->offset == sizeof(upb_StringView)); - upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field, - wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); - upb_Map* map = *map_p; - upb_MapEntry ent; - const upb_MiniTable* entry = subs[field->submsg_index].submsg; - - if (!map) { - map = _upb_Decoder_CreateMap(d, entry); - *map_p = map; - } - - /* Parse map entry. */ - memset(&ent, 0, sizeof(ent)); - - if (entry->fields[1].descriptortype == kUpb_FieldType_Message || - entry->fields[1].descriptortype == kUpb_FieldType_Group) { - /* Create proactively to handle the case where it doesn't appear. */ - ent.v.val = - upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); - } - - const char* start = ptr; - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, &ent.k, subs, field, val->size); - // check if ent had any unknown fields - size_t size; - upb_Message_GetUnknown(&ent.k, &size); - if (size != 0) { - uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited; - _upb_Decoder_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start)); - if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else { - if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size, - &d->arena) == _kUpb_MapInsertStatus_OutOfMemory) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } - return ptr; -} - -static const char* _upb_Decoder_DecodeToSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->offset, void); - int type = field->descriptortype; - - if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && - !_upb_Decoder_CheckEnum(d, ptr, msg, subs[field->submsg_index].subenum, - field, val)) { - return ptr; - } - - /* Set presence if necessary. */ - if (field->presence > 0) { - _upb_sethas_field(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ - uint32_t* oneof_case = _upb_oneofcase_field(msg, field); - if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->number) { - memset(mem, 0, sizeof(void*)); - } - *oneof_case = field->number; - } - - /* Store into message. */ - switch (op) { - case kUpb_DecodeOp_SubMessage: { - upb_Message** submsgp = mem; - upb_Message* submsg = *submsgp; - if (!submsg) { - submsg = _upb_Decoder_NewSubMessage(d, subs, field); - *submsgp = submsg; - } - if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { - ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - break; - } - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: - return _upb_Decoder_ReadString(d, ptr, val->size, mem); - case kUpb_DecodeOp_Scalar8Byte: - memcpy(mem, val, 8); - break; - case kUpb_DecodeOp_Enum: - case kUpb_DecodeOp_Scalar4Byte: - memcpy(mem, val, 4); - break; - case kUpb_DecodeOp_Scalar1Byte: - memcpy(mem, val, 1); - break; - default: - UPB_UNREACHABLE(); - } - - return ptr; -} - -UPB_NOINLINE -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* l) { - assert(l->required_count); - if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { - return ptr; - } - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (upb_MiniTable_requiredmask(l) & ~msg_head) { - d->missing_required = true; - } - return ptr; -} - -UPB_FORCEINLINE -static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* layout) { -#if UPB_FASTTABLE - if (layout && layout->table_mask != (unsigned char)-1) { - uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); - intptr_t table = decode_totable(layout); - *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); - return true; - } -#endif - return false; -} - -static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, - uint32_t tag) { - int field_number = tag >> 3; - int wire_type = tag & 7; - switch (wire_type) { - case kUpb_WireType_Varint: { - uint64_t val; - return _upb_Decoder_DecodeVarint(d, ptr, &val); - } - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_Delimited: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - return ptr + size; - } - case kUpb_WireType_StartGroup: - return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - default: - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } -} - -enum { - kStartItemTag = ((1 << 3) | kUpb_WireType_StartGroup), - kEndItemTag = ((1 << 3) | kUpb_WireType_EndGroup), - kTypeIdTag = ((2 << 3) | kUpb_WireType_Varint), - kMessageTag = ((3 << 3) | kUpb_WireType_Delimited), -}; - -static void upb_Decoder_AddKnownMessageSetItem( - upb_Decoder* d, upb_Message* msg, const upb_MiniTable_Extension* item_mt, - const char* data, uint32_t size) { - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - upb_Message* submsg = - _upb_Decoder_NewSubMessage(d, &ext->ext->sub, &ext->ext->field); - upb_DecodeStatus status = upb_Decode(data, size, submsg, item_mt->sub.submsg, - d->extreg, d->options, &d->arena); - memcpy(&ext->data, &submsg, sizeof(submsg)); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); -} - -static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, - upb_Message* msg, - uint32_t type_id, - const char* message_data, - uint32_t message_size) { - char buf[60]; - char* ptr = buf; - ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); - ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); - ptr = upb_Decoder_EncodeVarint32(type_id, ptr); - ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); - ptr = upb_Decoder_EncodeVarint32(message_size, ptr); - char* split = ptr; - - ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); - char* end = ptr; - - if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) || - !_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) || - !_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } -} - -static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* layout, - uint32_t type_id, const char* data, - uint32_t size) { - const upb_MiniTable_Extension* item_mt = - _upb_extreg_get(d->extreg, layout, type_id); - if (item_mt) { - upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); - } else { - upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); - } -} - -static const char* upb_Decoder_DecodeMessageSetItem( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout) { - uint32_t type_id = 0; - upb_StringView preserved = {NULL, 0}; - typedef enum { - kUpb_HaveId = 1 << 0, - kUpb_HavePayload = 1 << 1, - } StateMask; - StateMask state_mask = 0; - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - switch (tag) { - case kEndItemTag: - return ptr; - case kTypeIdTag: { - uint64_t tmp; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); - if (state_mask & kUpb_HaveId) break; // Ignore dup. - state_mask |= kUpb_HaveId; - type_id = tmp; - if (state_mask & kUpb_HavePayload) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, - preserved.size); - } - break; - } - case kMessageTag: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - const char* data = ptr; - ptr += size; - if (state_mask & kUpb_HavePayload) break; // Ignore dup. - state_mask |= kUpb_HavePayload; - if (state_mask & kUpb_HaveId) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); - } else { - // Out of order, we must preserve the payload. - preserved.data = data; - preserved.size = size; - } - break; - } - default: - // We do not preserve unexpected fields inside a message set item. - ptr = upb_Decoder_SkipField(d, ptr, tag); - break; - } - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} - -static const upb_MiniTable_Field* _upb_Decoder_FindField( - upb_Decoder* d, const upb_MiniTable* l, uint32_t field_number, - int* last_field_index) { - static upb_MiniTable_Field none = { - 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - if (l == NULL) return &none; - - size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < l->dense_below) { - /* Fastest case: index into dense fields. */ - goto found; - } - - if (l->dense_below < l->field_count) { - /* Linear search non-dense fields. Resume scanning from last_field_index - * since fields are usually in order. */ - int last = *last_field_index; - for (idx = last; idx < l->field_count; idx++) { - if (l->fields[idx].number == field_number) { - goto found; - } - } - - for (idx = l->dense_below; idx < last; idx++) { - if (l->fields[idx].number == field_number) { - goto found; - } - } - } - - if (d->extreg) { - switch (l->ext) { - case kUpb_ExtMode_Extendable: { - const upb_MiniTable_Extension* ext = - _upb_extreg_get(d->extreg, l, field_number); - if (ext) return &ext->field; - break; - } - case kUpb_ExtMode_IsMessageSet: - if (field_number == _UPB_MSGSET_ITEM) { - static upb_MiniTable_Field item = { - 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; - return &item; - } - break; - } - } - - return &none; /* Unknown field. */ - -found: - UPB_ASSERT(l->fields[idx].number == field_number); - *last_field_index = idx; - return &l->fields[idx]; -} - -int _upb_Decoder_GetVarintOp(const upb_MiniTable_Field* field) { - static const int8_t kVarintOps[] = { - [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, - [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - }; - - return kVarintOps[field->descriptortype]; -} - -int _upb_Decoder_GetDelimitedOp(const upb_MiniTable* mt, - const upb_MiniTable_Field* field) { - enum { kRepeatedBase = 19 }; - - static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ - [kUpb_FakeFieldType_FieldNotFound] = - kUpb_DecodeOp_UnknownField, // Field not found. - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ - [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), - [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, - [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), - // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a - // repeated msgset type - }; - - int ndx = field->descriptortype; - if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += kRepeatedBase; - int op = kDelimitedOps[ndx]; - - // If sub-message is not linked, treat as unknown. - if (op == kUpb_DecodeOp_SubMessage && - !(field->mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTable_Sub* sub = &mt->subs[field->submsg_index]; - if (!sub->submsg) { - op = kUpb_DecodeOp_UnknownField; - } - } - - return op; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeWireValue( - upb_Decoder* d, const char* ptr, const upb_MiniTable* mt, - const upb_MiniTable_Field* field, int wire_type, wireval* val, int* op) { - static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | - (1 << kUpb_FieldType_Fixed32) | - (1 << kUpb_FieldType_SFixed32); - - static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Fixed64) | - (1 << kUpb_FieldType_SFixed64); - - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); - *op = _upb_Decoder_GetVarintOp(field); - _upb_Decoder_Munge(field->descriptortype, val); - return ptr; - case kUpb_WireType_32Bit: - memcpy(&val->uint32_val, ptr, 4); - val->uint32_val = _upb_BigEndian_Swap32(val->uint32_val); - *op = kUpb_DecodeOp_Scalar4Byte; - if (((1 << field->descriptortype) & kFixed32OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr + 4; - case kUpb_WireType_64Bit: - memcpy(&val->uint64_val, ptr, 8); - val->uint64_val = _upb_BigEndian_Swap64(val->uint64_val); - *op = kUpb_DecodeOp_Scalar8Byte; - if (((1 << field->descriptortype) & kFixed64OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr + 8; - case kUpb_WireType_Delimited: - ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); - *op = _upb_Decoder_GetDelimitedOp(mt, field); - return ptr; - case kUpb_WireType_StartGroup: - val->uint32_val = field->number; - if (field->descriptortype == kUpb_FieldType_Group) { - *op = kUpb_DecodeOp_SubMessage; - } else if (field->descriptortype == kUpb_FakeFieldType_MessageSetItem) { - *op = kUpb_DecodeOp_MessageSetItem; - } else { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr; - default: - break; - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout, const upb_MiniTable_Field* field, int op, - wireval* val) { - const upb_MiniTable_Sub* subs = layout->subs; - uint8_t mode = field->mode; - - if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTable_Extension* ext_layout = - (const upb_MiniTable_Extension*)field; - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown_msg = msg; - msg = &ext->data; - subs = &ext->ext->sub; - } - - switch (mode & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Array: - return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); - case kUpb_FieldMode_Map: - return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); - case kUpb_FieldMode_Scalar: - return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); - default: - UPB_UNREACHABLE(); - } -} - -static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, - uint32_t val) { - uint32_t seen = 0; - do { - ptr--; - seen <<= 7; - seen |= *ptr & 0x7f; - } while (seen != val); - return ptr; -} - -static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, - const char* ptr, - upb_Message* msg, - int field_number, - int wire_type, wireval val) { - if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - - // Since unknown fields are the uncommon case, we do a little extra work here - // to walk backwards through the buffer to find the field start. This frees - // up a register in the fast paths (when the field is known), which leads to - // significant speedups in benchmarks. - const char* start = ptr; - - if (wire_type == kUpb_WireType_Delimited) ptr += val.size; - if (msg) { - switch (wire_type) { - case kUpb_WireType_Varint: - case kUpb_WireType_Delimited: - start--; - while (start[-1] & 0x80) start--; - break; - case kUpb_WireType_32Bit: - start -= 4; - break; - case kUpb_WireType_64Bit: - start -= 8; - break; - default: - break; - } - - assert(start == d->debug_valstart); - uint32_t tag = ((uint32_t)field_number << 3) | wire_type; - start = _upb_Decoder_ReverseSkipVarint(start, tag); - assert(start == d->debug_tagstart); - - if (wire_type == kUpb_WireType_StartGroup) { - d->unknown = start; - d->unknown_msg = msg; - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - start = d->unknown; - d->unknown = NULL; - } - if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else if (wire_type == kUpb_WireType_StartGroup) { - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - } - return ptr; -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout) { - int last_field_index = 0; - -#if UPB_FASTTABLE - // The first time we want to skip fast dispatch, because we may have just been - // invoked by the fast parser to handle a case that it bailed on. - if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; -#endif - - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - const upb_MiniTable_Field* field; - int field_number; - int wire_type; - wireval val; - int op; - - if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; - -#if UPB_FASTTABLE - nofast: -#endif - -#ifndef NDEBUG - d->debug_tagstart = ptr; -#endif - - UPB_ASSERT(ptr < d->limit_ptr); - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - field_number = tag >> 3; - wire_type = tag & 7; - -#ifndef NDEBUG - d->debug_valstart = ptr; -#endif - - if (wire_type == kUpb_WireType_EndGroup) { - d->end_group = field_number; - return ptr; - } - - field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); - ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, - &op); - - if (op >= 0) { - ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); - } else { - switch (op) { - case kUpb_DecodeOp_UnknownField: - ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, - wire_type, val); - break; - case kUpb_DecodeOp_MessageSetItem: - ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); - break; - } - } - } - - return UPB_UNLIKELY(layout && layout->required_count) - ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) - : ptr; -} - -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - (void)data; - *(uint32_t*)msg |= hasbits; - return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); -} - -static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, - const char* buf, void* msg, - const upb_MiniTable* l) { - if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { - _upb_Decoder_DecodeMessage(d, buf, msg, l); - } - if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; - if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; - return kUpb_DecodeStatus_Ok; -} - -upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, - const upb_MiniTable* l, - const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena) { - upb_Decoder state; - unsigned depth = (unsigned)options >> 16; - - if (size <= 16) { - memset(&state.patch, 0, 32); - if (size) memcpy(&state.patch, buf, size); - buf = state.patch; - state.end = buf + size; - state.limit = 0; - options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf. - } else { - state.end = buf + size - 16; - state.limit = 16; - } - - state.extreg = extreg; - state.limit_ptr = state.end; - state.unknown = NULL; - state.depth = depth ? depth : 64; - state.end_group = DECODE_NOGROUP; - state.options = (uint16_t)options; - state.missing_required = false; - state.arena.head = arena->head; - state.arena.last_size = arena->last_size; - state.arena.cleanup_metadata = arena->cleanup_metadata; - state.arena.parent = arena; - - upb_DecodeStatus status = UPB_SETJMP(state.err); - if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) { - status = _upb_Decoder_DecodeTop(&state, buf, msg, l); - } - - arena->head.ptr = state.arena.head.ptr; - arena->head.end = state.arena.head.end; - arena->cleanup_metadata = state.arena.cleanup_metadata; - return status; -} - -#undef OP_FIXPCK_LG2 -#undef OP_VARPCK_LG2 - -/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ - - -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} - -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); -} - -typedef struct { - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; - -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; - } - return ret; -} - -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_LONGJMP(e->err, s); -} - -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - - // We want previous data at the end, realloc() put it at the beginning. - // TODO(salo): This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); - } - - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - - e->ptr -= bytes; -} - -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ -UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; - } - - e->ptr -= bytes; -} - -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); -} - -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} - -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} - -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; -} - -UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; - } else { - encode_longvarint(e, val); - } -} - -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); -} - -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->size * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; - - if (tag || !_upb_IsLittleEndian()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, elem_size); - } - - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } - } else { - encode_bytes(e, data, bytes); - } -} - -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); - -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const char* field_mem = _field_mem; - int wire_type; - -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } - - switch (f->descriptortype) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - void* submsg = *(void**)field_mem; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (submsg == NULL) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->number, kUpb_WireType_EndGroup); - encode_message(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; - } - case kUpb_FieldType_Message: { - size_t size; - void* submsg = *(void**)field_mem; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (submsg == NULL) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_message(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; - } - default: - UPB_UNREACHABLE(); - } -#undef CASE - - encode_tag(e, f->number, wire_type); -} - -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); - bool packed = f->mode & kUpb_LabelFlags_IsPacked; - size_t pre_len = e->limit - e->ptr; - - if (arr == NULL || arr->size == 0) { - return; - } - -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->size; \ - uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; - -#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) - - switch (f->descriptortype) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->size; - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const void* const* start = _upb_array_constptr(arr); - const void* const* ptr = start + arr->size; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->number, kUpb_WireType_EndGroup); - encode_message(e, *ptr, subm, &size); - encode_tag(e, f->number, kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const void* const* start = _upb_array_constptr(arr); - const void* const* ptr = start + arr->size; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_message(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; - } - } -#undef VARINT_CASE - - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } -} - -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTable_Field* key_field = &layout->fields[0]; - const upb_MiniTable_Field* val_field = &layout->fields[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->v, layout->subs, val_field); - encode_scalar(e, &ent->k, layout->subs, key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); -} - -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); - const upb_MiniTable* layout = subs[f->submsg_index].submsg; - UPB_ASSERT(layout->field_count == 2); - - if (map == NULL) return; - - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map, - &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->number, layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - upb_strtable_iter i; - upb_strtable_begin(&i, &map->table); - for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { - upb_StringView key = upb_strtable_iter_key(&i); - const upb_value val = upb_strtable_iter_value(&i); - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.k, map->key_size); - _upb_map_fromvalue(val, &ent.v, map->val_size); - encode_mapentry(e, f->number, layout, &ent); - } - } -} - -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - if (f->presence == 0) { - /* Proto3 presence or map/array. */ - const void* mem = UPB_PTR_AT(msg, f->offset, void); - switch (f->mode >> kUpb_FieldRep_Shift) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } -#if UINTPTR_MAX == 0xffffffff - case kUpb_FieldRep_Pointer: -#endif - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } -#if UINTPTR_MAX != 0xffffffff - case kUpb_FieldRep_Pointer: -#endif - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); - } - } else if (f->presence > 0) { - /* Proto2 presence: hasbit. */ - return _upb_hasbit_field(msg, f); - } else { - /* Field is in a oneof. */ - return _upb_getoneofcase_field(msg, f) == f->number; - } -} - -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field) { - switch (upb_FieldMode_Get(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); - break; - default: - UPB_UNREACHABLE(); - } -} - -/* message MessageSet { - * repeated group Item = 1 { - * required int32 type_id = 2; - * required string message = 3; - * } - * } */ -static void encode_msgset_item(upb_encstate* e, - const upb_Message_Extension* ext) { - size_t size; - encode_tag(e, 1, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size); - encode_varint(e, size); - encode_tag(e, 3, kUpb_WireType_Delimited); - encode_varint(e, ext->ext->field.number); - encode_tag(e, 2, kUpb_WireType_Varint); - encode_tag(e, 1, kUpb_WireType_StartGroup); -} - -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; - - if ((e->options & kUpb_EncodeOption_CheckRequired) && m->required_count) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (upb_MiniTable_requiredmask(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } - - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); - - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } - - if (m->ext != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); - if (ext_count) { - const upb_Message_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - if (UPB_UNLIKELY(m->ext == kUpb_ExtMode_IsMessageSet)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field); - } - } - } - } - - if (m->field_count) { - const upb_MiniTable_Field* f = &m->fields[m->field_count]; - const upb_MiniTable_Field* first = &m->fields[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->subs, f)) { - encode_field(e, msg, m->subs, f); - } - } - } - - *size = (e->limit - e->ptr) - pre_len; -} - -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; - - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : 64; - e.options = options; - _upb_mapsorter_init(&e.sorter); - - upb_EncodeStatus status = UPB_SETJMP(e.err); - - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (status == kUpb_EncodeStatus_Ok) { - encode_message(&e, msg, l, size); - *size = e.limit - e.ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(e.ptr); - *buf = e.ptr; - } - } else { - *buf = NULL; - *size = 0; - } - - _upb_mapsorter_destroy(&e.sorter); - return status; -} - - -// Must be last. - -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); -} - -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; -} - -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + map_size; - - // Grow s->entries if necessary. - if (sorted->end > s->cap) { - s->cap = _upb_Log2CeilingSize(sorted->end); - s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); - if (!s->entries) return false; - } - - s->size = sorted->end; - - // Copy non-empty entries from the table to s->entries. - upb_tabent const** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; - } - } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} - - -#include - - -// Must be last. - -/** upb_Message ***************************************************************/ - -static const size_t overhead = sizeof(upb_Message_InternalData); - -static const upb_Message_Internal* upb_Message_Getinternal_const( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) { - return _upb_Message_New_inl(l, a); -} - -void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { - void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); - memset(mem, 0, upb_msg_sizeof(l)); -} - -static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - /* No internal data, allocate from scratch. */ - size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - /* Internal data is too small, reallocate. */ - size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - /* Need to move extension data to the end. */ - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - -bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena) { - if (!realloc_internal(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; -} - -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = overhead; - } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *len = in->internal->unknown_end - overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTable_Extension* e) { - size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - - /* For now we use linear search exclusively to find extensions. If this - * becomes an issue due to messages with lots of extensions, we can introduce - * a table of some sort. */ - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -void _upb_Message_Clearext(upb_Message* msg, - const upb_MiniTable_Extension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); - } -} - -upb_Message_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); - ext->ext = e; - return ext; -} - -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - _upb_Message_Getexts(msg, &count); - return count; -} - -/** upb_Map *******************************************************************/ - -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - - if (!map) { - return NULL; - } - - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; - - return map; -} - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; - - -#include -#include -#include -#include -#include -#include - -// Must be last. - -void upb_Status_Clear(upb_Status* status) { - if (!status) return; - status->ok = true; - status->msg[0] = '\0'; -} - -bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - -const char* upb_Status_ErrorMessage(const upb_Status* status) { - return status->msg; -} - -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { - if (!status) return; - status->ok = false; - strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(status, fmt, args); - va_end(args); -} - -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - if (!status) return; - status->ok = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - size_t len; - if (!status) return; - status->ok = false; - len = strlen(status->msg); - vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -#include -#include -#include - - -// Must be last. - /* Miscellaneous utilities ****************************************************/ static void upb_FixLocale(char* p) { @@ -12962,6 +12819,7 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { upb_FixLocale(buf); } +/** upb/port_undef.inc ************************************************************/ /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE @@ -12998,5 +12856,3 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { #undef UPB_UNPOISON_MEMORY_REGION #undef UPB_ASAN #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 -#undef UPB_DEPRECATED -#undef UPB_GNUC_MIN diff --git a/libs/protobuf/php/ext/google/protobuf/php-upb.h b/libs/protobuf/php/ext/google/protobuf/php-upb.h index 4287479..8291daa 100644 --- a/libs/protobuf/php/ext/google/protobuf/php-upb.h +++ b/libs/protobuf/php/ext/google/protobuf/php-upb.h @@ -1,4 +1,30 @@ /* Amalgamated source file */ +/* + * Copyright (c) 2009-2021, Google LLC + * All rights reserved. + * + * 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 LLC 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 Google LLC 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 is where we define macros used across upb. @@ -29,20 +55,8 @@ #error upb requires C99 or C++11 or MSVC >= 2015. #endif -// Portable check for GCC minimum version: -// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define UPB_GNUC_MIN(x, y) \ - (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) -#else -#define UPB_GNUC_MIN(x, y) 0 -#endif - -#include -#include -#include -#include #include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -81,16 +95,16 @@ #define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) -/* Hints to the compiler about likely/unlikely branches. */ +// Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) -#define UPB_LIKELY(x) __builtin_expect((x),1) -#define UPB_UNLIKELY(x) __builtin_expect((x),0) +#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) +#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) #else #define UPB_LIKELY(x) (x) #define UPB_UNLIKELY(x) (x) #endif -/* Macros for function attributes on compilers that support them. */ +// Macros for function attributes on compilers that support them. #ifdef __GNUC__ #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) #define UPB_NOINLINE __attribute__((noinline)) @@ -113,8 +127,7 @@ #define UPB_UNUSED(var) (void)var -/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. - */ +// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. #ifdef NDEBUG #ifdef __GNUC__ #define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable() @@ -216,11 +229,7 @@ #undef UPB_FASTTABLE_SUPPORTED -/* ASAN poisoning (for arena). - * If using UPB from an interpreted language like Ruby, a build of the - * interpreter compiled with ASAN enabled must be used in order to get sane and - * expected behavior. - */ +/* ASAN poisoning (for arena) *************************************************/ #if defined(__SANITIZE_ADDRESS__) #define UPB_ASAN 1 @@ -252,35 +261,40 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0 #endif -#if defined(__cplusplus) -#if defined(__clang__) || UPB_GNUC_MIN(6, 0) -// https://gcc.gnu.org/gcc-6/changes.html -#if __cplusplus >= 201402L -#define UPB_DEPRECATED [[deprecated]] -#else -#define UPB_DEPRECATED __attribute__((deprecated)) -#endif -#else -#define UPB_DEPRECATED -#endif -#else -#define UPB_DEPRECATED -#endif +/** upb/collections.h ************************************************************/ +#ifndef UPB_COLLECTIONS_H_ +#define UPB_COLLECTIONS_H_ -#ifndef UPB_INTERNAL_ARRAY_H_ -#define UPB_INTERNAL_ARRAY_H_ +/** google/protobuf/descriptor.upb.h ************************************************************//* This file was generated by upbc (the upb compiler) from the input + * file: + * + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ +#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ + + +/** upb/msg_internal.h ************************************************************/ +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ + +#ifndef UPB_MSG_INT_H_ +#define UPB_MSG_INT_H_ + +#include +#include #include -#ifndef UPB_ARRAY_H_ -#define UPB_ARRAY_H_ - - -#ifndef UPB_MESSAGE_VALUE_H_ -#define UPB_MESSAGE_VALUE_H_ - - +/** upb/msg.h ************************************************************/ /* * Public APIs for message operations that do not require descriptors. * These functions can be used even in build that does not want to depend on @@ -292,37 +306,97 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #ifndef UPB_MSG_H_ #define UPB_MSG_H_ +#include -#ifndef UPB_ARENA_H_ -#define UPB_ARENA_H_ +/** upb/upb.h ************************************************************/ +/* + * This file contains shared definitions that are widely used across upb. + */ + +#ifndef UPB_H_ +#define UPB_H_ + +#include +#include +#include +#include +#include #include -#ifndef UPB_ALLOC_H_ -#define UPB_ALLOC_H_ - -// Must be last. - #ifdef __cplusplus extern "C" { #endif -typedef struct upb_alloc upb_alloc; +/* upb_Status *****************************************************************/ -/* A combined `malloc()`/`free()` function. - * If `size` is 0 then the function acts like `free()`, otherwise it acts like - * `realloc()`. Only `oldsize` bytes from a previous allocation are - * preserved. */ -typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size); +#define _kUpb_Status_MaxMessage 127 + +typedef struct { + bool ok; + char msg[_kUpb_Status_MaxMessage]; /* Error message; NULL-terminated. */ +} upb_Status; + +const char* upb_Status_ErrorMessage(const upb_Status* status); +bool upb_Status_IsOk(const upb_Status* status); + +/* These are no-op if |status| is NULL. */ +void upb_Status_Clear(upb_Status* status); +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) + UPB_PRINTF(2, 3); +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); + +/** upb_StringView ************************************************************/ + +typedef struct { + const char* data; + size_t size; +} upb_StringView; + +UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, + size_t size) { + upb_StringView ret; + ret.data = data; + ret.size = size; + return ret; +} + +UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { + return upb_StringView_FromDataAndSize(data, strlen(data)); +} + +UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { + return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; +} + +#define UPB_STRINGVIEW_INIT(ptr, len) \ + { ptr, len } + +#define UPB_STRINGVIEW_FORMAT "%.*s" +#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data + +/** upb_alloc *****************************************************************/ /* A upb_alloc is a possibly-stateful allocator object. * * It could either be an arena allocator (which doesn't require individual - * `free()` calls) or a regular `malloc()` (which does). The client must - * therefore free memory unless it knows that the allocator is an arena - * allocator. */ + * free() calls) or a regular malloc() (which does). The client must therefore + * free memory unless it knows that the allocator is an arena allocator. */ + +struct upb_alloc; +typedef struct upb_alloc upb_alloc; + +/* A malloc()/free() function. + * If "size" is 0 then the function acts like free(), otherwise it acts like + * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */ +typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size); + struct upb_alloc { upb_alloc_func* func; }; @@ -339,7 +413,7 @@ UPB_INLINE void* upb_realloc(upb_alloc* alloc, void* ptr, size_t oldsize, } UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { - UPB_ASSERT(alloc); + assert(alloc); alloc->func(alloc, ptr, 0, 0); } @@ -362,18 +436,7 @@ UPB_INLINE void* upb_grealloc(void* ptr, size_t oldsize, size_t size) { UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ALLOC_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/* upb_Arena ******************************************************************/ /* upb_Arena is a specific allocator implementation that uses arena allocation. * The user provides an allocator that will be used to allocate the underlying @@ -389,6 +452,7 @@ extern "C" { typedef void upb_CleanupFunc(void* ud); +struct upb_Arena; typedef struct upb_Arena upb_Arena; typedef struct { @@ -408,8 +472,6 @@ void upb_Arena_Free(upb_Arena* a); bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func); bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size); -size_t upb_Arena_SpaceAllocated(upb_Arena* arena); -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena); UPB_INLINE upb_alloc* upb_Arena_Alloc(upb_Arena* a) { return (upb_alloc*)a; } @@ -495,153 +557,6 @@ UPB_INLINE upb_Arena* upb_Arena_New(void) { return upb_Arena_Init(NULL, 0, &upb_alloc_global); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ARENA_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void upb_Message; - -/* For users these are opaque. They can be obtained from - * upb_MessageDef_MiniTable() but users cannot access any of the members. */ -typedef struct upb_MiniTable upb_MiniTable; - -/* Adds unknown data (serialized protobuf data) to the given message. The data - * is copied into the message instance. */ -void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena); - -/* Returns a reference to the message's unknown data. */ -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); - -/* Returns the number of extensions present in this message. */ -size_t upb_Message_ExtensionCount(const upb_Message* msg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MSG_INT_H_ */ - -#ifndef UPB_STRING_VIEW_H_ -#define UPB_STRING_VIEW_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char* data; - size_t size; -} upb_StringView; - -UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, - size_t size) { - upb_StringView ret; - ret.data = data; - ret.size = size; - return ret; -} - -UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { - return upb_StringView_FromDataAndSize(data, strlen(data)); -} - -UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { - return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; -} - -#define UPB_STRINGVIEW_INIT(ptr, len) \ - { ptr, len } - -#define UPB_STRINGVIEW_FORMAT "%.*s" -#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_STRING_VIEW_H_ */ - -/* - * This file contains shared definitions that are widely used across upb. - */ - -#ifndef UPB_H_ -#define UPB_H_ - -#include -#include -#include -#include -#include -#include - -// TODO(b/232091617): Remove these and fix everything that breaks as a result. - -#ifndef UPB_STATUS_H_ -#define UPB_STATUS_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -#define _kUpb_Status_MaxMessage 127 - -typedef struct { - bool ok; - char msg[_kUpb_Status_MaxMessage]; /* Error message; NULL-terminated. */ -} upb_Status; - -const char* upb_Status_ErrorMessage(const upb_Status* status); -bool upb_Status_IsOk(const upb_Status* status); - -/* These are no-op if |status| is NULL. */ -void upb_Status_Clear(upb_Status* status); -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) - UPB_PRINTF(2, 3); -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_STATUS_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// These types appear in circular references so we need to forward-declare them. -// There is no obviously good place for this so let's just put it here. -typedef struct upb_Array upb_Array; -typedef struct upb_Map upb_Map; - /* Constants ******************************************************************/ /* A list of types as they are encoded on-the-wire. */ @@ -697,11 +612,9 @@ typedef enum { kUpb_FieldType_SFixed32 = 15, kUpb_FieldType_SFixed64 = 16, kUpb_FieldType_SInt32 = 17, - kUpb_FieldType_SInt64 = 18, + kUpb_FieldType_SInt64 = 18 } upb_FieldType; -#define kUpb_FieldType_SizeOf 19 - #define kUpb_Map_Begin ((size_t)-1) UPB_INLINE bool _upb_IsLittleEndian(void) { @@ -740,400 +653,38 @@ UPB_INLINE int _upb_Log2Ceiling(int x) { UPB_INLINE int _upb_Log2CeilingSize(int x) { return 1 << _upb_Log2Ceiling(x); } + #ifdef __cplusplus } /* extern "C" */ #endif - #endif /* UPB_H_ */ -// Must be last. - #ifdef __cplusplus extern "C" { #endif -// Definitions common to both upb_Array and upb_Map. +/** upb_Message ***************************************************************/ -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const upb_Array* array_val; - const upb_Map* map_val; - const upb_Message* msg_val; - upb_StringView str_val; -} upb_MessageValue; +typedef void upb_Message; -typedef union { - upb_Array* array; - upb_Map* map; - upb_Message* msg; -} upb_MutableMessageValue; +/* For users these are opaque. They can be obtained from + * upb_MessageDef_MiniTable() but users cannot access any of the members. */ +struct upb_MiniTable; +typedef struct upb_MiniTable upb_MiniTable; -#ifdef __cplusplus -} /* extern "C" */ -#endif +/* Adds unknown data (serialized protobuf data) to the given message. The data + * is copied into the message instance. */ +void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena); +/* Returns a reference to the message's unknown data. */ +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); -#endif /* UPB_MESSAGE_VALUE_H_ */ +/* Returns the number of extensions present in this message. */ +size_t upb_Message_ExtensionCount(const upb_Message* msg); -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Creates a new array on the given arena that holds elements of this type. */ -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -/* Returns the number of elements in the array. */ -size_t upb_Array_Size(const upb_Array* arr); - -/* Returns the given element, which must be within the array's current size. */ -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -/* Sets the given element, which must be within the array's current size. */ -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -/* Appends an element to the array. Returns false on allocation failure. */ -bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena); - -/* Moves elements within the array using memmove(). Like memmove(), the source - * and destination elements may be overlapping. */ -void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -/* Inserts one or more empty elements into the array. Existing elements are - * shifted right. The new elements have undefined state and must be set with - * `upb_Array_Set()`. - * REQUIRES: `i <= upb_Array_Size(arr)` */ -bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); - -/* Deletes one or more elements from the array. Existing elements are shifted - * left. - * REQUIRES: `i + count <= upb_Array_Size(arr)` */ -void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -/* Changes the size of a vector. New elements are initialized to empty/0. - * Returns false on allocation failure. */ -bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ARRAY_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Our internal representation for repeated fields. */ -struct upb_Array { - uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ - size_t size; /* The number of elements in the array. */ - size_t capacity; /* Allocated storage. Measured in elements. */ -}; - -UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { - UPB_ASSERT((arr->data & 7) <= 4); - return (void*)(arr->data & ~(uintptr_t)7); -} - -UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 <= 4); - return (uintptr_t)ptr | elem_size_lg2; -} - -UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { - return (void*)_upb_array_constptr(arr); -} - -UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 <= 4); - UPB_ASSERT(((uintptr_t)ptr & 7) == 0); - return (uintptr_t)ptr | (unsigned)elem_size_lg2; -} - -UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_capacity, - int elem_size_lg2) { - const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = arr_size + (init_capacity << elem_size_lg2); - upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); - if (!arr) return NULL; - arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); - arr->size = 0; - arr->capacity = init_capacity; - return arr; -} - -/* Resizes the capacity of the array to be at least min_size. */ -bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); - -/* Fallback functions for when the accessors require a resize. */ -void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, - int elem_size_lg2, upb_Arena* arena); -bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, - int elem_size_lg2, upb_Arena* arena); - -UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, - upb_Arena* arena) { - if (arr->capacity < size) return _upb_array_realloc(arr, size, arena); - return true; -} - -UPB_INLINE bool _upb_Array_Resize(upb_Array* arr, size_t size, - upb_Arena* arena) { - if (!_upb_array_reserve(arr, size, arena)) return false; - arr->size = size; - return true; -} - -UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { - *UPB_PTR_AT(msg, ofs, upb_Array*) = NULL; -} - -UPB_INLINE const void* _upb_array_accessor(const void* msg, size_t ofs, - size_t* size) { - const upb_Array* arr = *UPB_PTR_AT(msg, ofs, const upb_Array*); - if (arr) { - if (size) *size = arr->size; - return _upb_array_constptr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE void* _upb_array_mutable_accessor(void* msg, size_t ofs, - size_t* size) { - upb_Array* arr = *UPB_PTR_AT(msg, ofs, upb_Array*); - if (arr) { - if (size) *size = arr->size; - return _upb_array_ptr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE void* _upb_Array_Resize_accessor2(void* msg, size_t ofs, size_t size, - int elem_size_lg2, - upb_Arena* arena) { - upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); - upb_Array* arr = *arr_ptr; - if (!arr || arr->capacity < size) { - return _upb_Array_Resize_fallback(arr_ptr, size, elem_size_lg2, arena); - } - arr->size = size; - return _upb_array_ptr(arr); -} - -UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, - int elem_size_lg2, - const void* value, - upb_Arena* arena) { - upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); - size_t elem_size = 1 << elem_size_lg2; - upb_Array* arr = *arr_ptr; - void* ptr; - if (!arr || arr->size == arr->capacity) { - return _upb_Array_Append_fallback(arr_ptr, value, elem_size_lg2, arena); - } - ptr = _upb_array_ptr(arr); - memcpy(UPB_PTR_AT(ptr, arr->size * elem_size, char), value, elem_size); - arr->size++; - return true; -} - -/* Used by old generated code, remove once all code has been regenerated. */ -UPB_INLINE int _upb_sizelg2(upb_CType type) { - switch (type) { - case kUpb_CType_Bool: - return 0; - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - return 2; - case kUpb_CType_Message: - return UPB_SIZE(2, 3); - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return 3; - case kUpb_CType_String: - case kUpb_CType_Bytes: - return UPB_SIZE(3, 4); - } - UPB_UNREACHABLE(); -} - -UPB_INLINE void* _upb_Array_Resize_accessor(void* msg, size_t ofs, size_t size, - upb_CType type, upb_Arena* arena) { - return _upb_Array_Resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); -} - -UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, - size_t elem_size, upb_CType type, - const void* value, - upb_Arena* arena) { - (void)elem_size; - return _upb_Array_Append_accessor2(msg, ofs, _upb_sizelg2(type), value, - arena); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ARRAY_H_ */ - -#ifndef UPB_INTERNAL_ATOI_H_ -#define UPB_INTERNAL_ATOI_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// We use these hand-written routines instead of strto[u]l() because the "long -// long" variants aren't in c89. Also our version allows setting a ptr limit. -// Return the new position of the pointer after parsing the int, or NULL on -// integer overflow. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ATOI_H_ */ - -#ifndef UPB_MAP_H_ -#define UPB_MAP_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Creates a new map on the given arena with the given key/value size. */ -upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type); - -/* Returns the number of entries in the map. */ -size_t upb_Map_Size(const upb_Map* map); - -/* Stores a value for the given key into |*val| (or the zero value if the key is - * not present). Returns whether the key was present. The |val| pointer may be - * NULL, in which case the function tests whether the given key is present. */ -bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -/* Removes all entries in the map. */ -void upb_Map_Clear(upb_Map* map); - -typedef enum { - // LINT.IfChange - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, - // LINT.ThenChange(//depot/google3/third_party/upb/upb/msg_internal.h) -} upb_MapInsertStatus; - -/* Sets the given key to the given value, returning whether the key was inserted - * or replaced. If the key was inserted, then any existing iterators will be - * invalidated. */ -upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena); - -/* Sets the given key to the given value. Returns false if memory allocation - * failed. If the key is newly inserted, then any existing iterators will be - * invalidated. */ -UPB_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} - -/* Deletes this key from the table. Returns true if the key was present. */ -bool upb_Map_Delete(upb_Map* map, upb_MessageValue key); - -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * - * // If mutating is desired. - * upb_MapIterator_SetValue(map, iter, value2); - * } - */ - -/* Advances to the next entry. Returns false if no more entries are present. */ -bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); - -/* Returns true if the iterator still points to a valid entry, or false if the - * iterator is past the last element. It is an error to call this function with - * kUpb_Map_Begin (you must call next() at least once first). */ -bool upb_MapIterator_Done(const upb_Map* map, size_t iter); - -/* Returns the key and value for this entry of the map. */ -upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); - -/* Sets the value for this entry. The iterator must not be done, and the - * iterator must not have been initialized const. */ -void upb_MapIterator_SetValue(upb_Map* map, size_t iter, - upb_MessageValue value); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MAP_H_ */ - -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ - -#ifndef UPB_MSG_INT_H_ -#define UPB_MSG_INT_H_ - -#include -#include - - -#ifndef UPB_EXTENSION_REGISTRY_H_ -#define UPB_EXTENSION_REGISTRY_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/** upb_ExtensionRegistry *****************************************************/ /* Extension registry: a dynamic data structure that stores a map of: * (upb_MiniTable, number) -> extension info @@ -1169,37 +720,20 @@ extern "C" { * reflection do not need to populate a upb_ExtensionRegistry directly. */ +struct upb_ExtensionRegistry; typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; -// Creates a upb_ExtensionRegistry in the given arena. -// The arena must outlive any use of the extreg. +/* Creates a upb_ExtensionRegistry in the given arena. The arena must outlive + * any use of the extreg. */ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -typedef struct upb_MiniTable upb_MiniTable; -typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; - -// Adds the given extension info for message type |l| and field number |num| -// into the registry. Returns false if this message type and field number were -// already in the map, or if memory allocation fails. -bool _upb_extreg_add(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, size_t count); - -// Looks up the extension (if any) defined for message type |l| and field -// number |num|. If an extension was found, copies the field info into |*ext| -// and returns true. Otherwise returns false. -const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, - const upb_MiniTable* l, - uint32_t num); - #ifdef __cplusplus } /* extern "C" */ #endif +#endif /* UPB_MSG_INT_H_ */ -#endif /* UPB_EXTENSION_REGISTRY_H_ */ - +/** upb/table_internal.h ************************************************************/ /* * upb_table * @@ -1219,9 +753,10 @@ const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, * mode, we check this on insert and lookup. */ -#ifndef UPB_INTERNAL_TABLE_H_ -#define UPB_INTERNAL_TABLE_H_ +#ifndef UPB_TABLE_H_ +#define UPB_TABLE_H_ +#include #include @@ -1387,8 +922,8 @@ UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { void upb_strtable_clear(upb_strtable* t); /* Inserts the given key into the hashtable with the given value. The key must - * not already exist in the hash table. For strtables, the key is not required - * to be NULL-terminated, and the table will make an internal copy of the key. + * not already exist in the hash table. For string tables, the key must be + * NULL-terminated, and the table will make an internal copy of the key. * Inttables must not insert a value of UINTPTR_MAX. * * If a table resize was required but memory allocation failed, false is @@ -1553,9 +1088,9 @@ uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); #endif -#endif /* UPB_INTERNAL_TABLE_H_ */ +#endif /* UPB_TABLE_H_ */ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -1573,9 +1108,6 @@ UPB_INLINE uint64_t _upb_UInt64_FromULL(unsigned long long v) { return (uint64_t)v; } -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; - /** upb_MiniTable *************************************************************/ /* upb_MiniTable represents the memory layout of a given upb_MessageDef. The @@ -1648,47 +1180,11 @@ typedef struct { } _upb_FastTable_Entry; typedef struct { - uint32_t mask_limit; // Limit enum value that can be tested with mask. - uint32_t value_count; // Number of values after the bitfield. - uint32_t data[]; // Bitmask + enumerated values follow. + const int32_t* values; // List of values <0 or >63 + uint64_t mask; // Bits are set for acceptable value 0 <= x < 64 + int value_count; } upb_MiniTable_Enum; -typedef enum { - _kUpb_FastEnumCheck_ValueIsInEnum = 0, - _kUpb_FastEnumCheck_ValueIsNotInEnum = 1, - _kUpb_FastEnumCheck_CannotCheckFast = 2, -} _kUpb_FastEnumCheck_Status; - -UPB_INLINE _kUpb_FastEnumCheck_Status -_upb_MiniTable_CheckEnumValueFast(const upb_MiniTable_Enum* e, uint32_t val) { - if (UPB_UNLIKELY(val >= 64)) return _kUpb_FastEnumCheck_CannotCheckFast; - uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32); - return (mask & (1ULL << val)) ? _kUpb_FastEnumCheck_ValueIsInEnum - : _kUpb_FastEnumCheck_ValueIsNotInEnum; -} - -UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTable_Enum* e, - uint32_t val) { - if (val < e->mask_limit) return e->data[val / 32] & (1ULL << (val % 32)); - // OPT: binary search long lists? - const uint32_t* start = &e->data[e->mask_limit / 32]; - const uint32_t* limit = &e->data[(e->mask_limit / 32) + e->value_count]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e, - uint32_t val) { - _kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, val); - if (UPB_UNLIKELY(status == _kUpb_FastEnumCheck_CannotCheckFast)) { - return _upb_MiniTable_CheckEnumValueSlow(e, val); - } - return status == _kUpb_FastEnumCheck_ValueIsInEnum ? true : false; -} - typedef union { const struct upb_MiniTable* submsg; const upb_MiniTable_Enum* subenum; @@ -1737,13 +1233,11 @@ struct upb_MiniTable { _upb_FastTable_Entry fasttable[]; }; -typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; - -struct upb_MiniTable_Extension { +typedef struct { upb_MiniTable_Field field; const upb_MiniTable* extendee; upb_MiniTable_Sub sub; /* NULL unless submessage or proto2 enum */ -}; +} upb_MiniTable_Extension; typedef struct { const upb_MiniTable** msgs; @@ -1766,6 +1260,21 @@ UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable* l) { return ((1ULL << n) - 1) << 1; } +/** upb_ExtensionRegistry *****************************************************/ + +/* Adds the given extension info for message type |l| and field number |num| + * into the registry. Returns false if this message type and field number were + * already in the map, or if memory allocation fails. */ +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count); + +/* Looks up the extension (if any) defined for message type |l| and field + * number |num|. If an extension was found, copies the field info into |*ext| + * and returns true. Otherwise returns false. */ +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num); + /** upb_Message ***************************************************************/ /* Internal members of a upb_Message that track unknown fields and/or @@ -1943,18 +1452,174 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_Message* msg, size_t ofs) { return *UPB_PTR_AT(msg, ofs, const upb_Message*) != NULL; } +/** upb_Array *****************************************************************/ + +/* Our internal representation for repeated fields. */ +typedef struct { + uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ + size_t len; /* Measured in elements. */ + size_t size; /* Measured in elements. */ + uint64_t junk; +} upb_Array; + +UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { + UPB_ASSERT((arr->data & 7) <= 4); + return (void*)(arr->data & ~(uintptr_t)7); +} + +UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 <= 4); + return (uintptr_t)ptr | elem_size_lg2; +} + +UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { + return (void*)_upb_array_constptr(arr); +} + +UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 <= 4); + UPB_ASSERT(((uintptr_t)ptr & 7) == 0); + return (uintptr_t)ptr | (unsigned)elem_size_lg2; +} + +UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_size, + int elem_size_lg2) { + const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = arr_size + (init_size << elem_size_lg2); + upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); + if (!arr) return NULL; + arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); + arr->len = 0; + arr->size = init_size; + return arr; +} + +/* Resizes the capacity of the array to be at least min_size. */ +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); + +/* Fallback functions for when the accessors require a resize. */ +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena); +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena); + +UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, + upb_Arena* arena) { + if (arr->size < size) return _upb_array_realloc(arr, size, arena); + return true; +} + +UPB_INLINE bool _upb_Array_Resize(upb_Array* arr, size_t size, + upb_Arena* arena) { + if (!_upb_array_reserve(arr, size, arena)) return false; + arr->len = size; + return true; +} + +UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { + *UPB_PTR_AT(msg, ofs, upb_Array*) = NULL; +} + +UPB_INLINE const void* _upb_array_accessor(const void* msg, size_t ofs, + size_t* size) { + const upb_Array* arr = *UPB_PTR_AT(msg, ofs, const upb_Array*); + if (arr) { + if (size) *size = arr->len; + return _upb_array_constptr(arr); + } else { + if (size) *size = 0; + return NULL; + } +} + +UPB_INLINE void* _upb_array_mutable_accessor(void* msg, size_t ofs, + size_t* size) { + upb_Array* arr = *UPB_PTR_AT(msg, ofs, upb_Array*); + if (arr) { + if (size) *size = arr->len; + return _upb_array_ptr(arr); + } else { + if (size) *size = 0; + return NULL; + } +} + +UPB_INLINE void* _upb_Array_Resize_accessor2(void* msg, size_t ofs, size_t size, + int elem_size_lg2, + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); + upb_Array* arr = *arr_ptr; + if (!arr || arr->size < size) { + return _upb_Array_Resize_fallback(arr_ptr, size, elem_size_lg2, arena); + } + arr->len = size; + return _upb_array_ptr(arr); +} + +UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, + int elem_size_lg2, + const void* value, + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); + size_t elem_size = 1 << elem_size_lg2; + upb_Array* arr = *arr_ptr; + void* ptr; + if (!arr || arr->len == arr->size) { + return _upb_Array_Append_fallback(arr_ptr, value, elem_size_lg2, arena); + } + ptr = _upb_array_ptr(arr); + memcpy(UPB_PTR_AT(ptr, arr->len * elem_size, char), value, elem_size); + arr->len++; + return true; +} + +/* Used by old generated code, remove once all code has been regenerated. */ +UPB_INLINE int _upb_sizelg2(upb_CType type) { + switch (type) { + case kUpb_CType_Bool: + return 0; + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + return 2; + case kUpb_CType_Message: + return UPB_SIZE(2, 3); + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return 3; + case kUpb_CType_String: + case kUpb_CType_Bytes: + return UPB_SIZE(3, 4); + } + UPB_UNREACHABLE(); +} +UPB_INLINE void* _upb_Array_Resize_accessor(void* msg, size_t ofs, size_t size, + upb_CType type, upb_Arena* arena) { + return _upb_Array_Resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); +} +UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, + size_t elem_size, upb_CType type, + const void* value, + upb_Arena* arena) { + (void)elem_size; + return _upb_Array_Append_accessor2(msg, ofs, _upb_sizelg2(type), value, + arena); +} + /** upb_Map *******************************************************************/ /* Right now we use strmaps for everything. We'll likely want to use * integer-specific maps for integer-keyed maps.*/ -struct upb_Map { +typedef struct { /* Size of key and val, based on the map type. Strings are represented as '0' * because they must be handled specially. */ char key_size; char val_size; upb_strtable table; -}; +} upb_Map; /* Map entries aren't actually stored, they are only used during parsing. For * parsing, it helps a lot if all map entry messages have the same layout. @@ -2053,7 +1718,7 @@ typedef enum { _kUpb_MapInsertStatus_Inserted = 0, _kUpb_MapInsertStatus_Replaced = 1, _kUpb_MapInsertStatus_OutOfMemory = 2, - // LINT.ThenChange(//depot/google3/third_party/upb/upb/map.h) + // LINT.ThenChange(//depot/google3/third_party/upb/upb/collections.h) } _upb_MapInsertStatus; UPB_INLINE _upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, @@ -2161,24 +1826,61 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, } } +/** _upb_mapsorter ************************************************************/ + +/* _upb_mapsorter sorts maps and provides ordered iteration over the entries. + * Since maps can be recursive (map values can be messages which contain other + * maps). _upb_mapsorter can contain a stack of maps. */ + +typedef struct { + upb_tabent const** entries; + int size; + int cap; +} _upb_mapsorter; + +typedef struct { + int start; + int pos; + int end; +} _upb_sortedmap; + +UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { + s->entries = NULL; + s->size = 0; + s->cap = 0; +} + +UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { + if (s->entries) free(s->entries); +} + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted); + +UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, + _upb_sortedmap* sorted) { + s->size = sorted->start; +} + +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, + _upb_sortedmap* sorted, upb_MapEntry* ent) { + if (sorted->pos == sorted->end) return false; + const upb_tabent* tabent = s->entries[sorted->pos++]; + upb_StringView key = upb_tabstrview(tabent->key); + _upb_map_fromkey(key, &ent->k, map->key_size); + upb_value val = {tabent->val.val}; + _upb_map_fromvalue(val, &ent->v, map->val_size); + return true; +} + #ifdef __cplusplus } /* extern "C" */ #endif #endif /* UPB_MSG_INT_H_ */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ - +/** upb/decode.h ************************************************************/ /* * upb_decode: parsing into a upb_Message using a upb_MiniTable. */ @@ -2187,7 +1889,7 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #define UPB_DECODE_H_ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -2244,6 +1946,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #endif /* UPB_DECODE_H_ */ +/** upb/decode_fast.h ************************************************************/ // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. // @@ -2282,20 +1985,13 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #define UPB_DECODE_FAST_H_ -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - struct upb_Decoder; // The fallback, generic parsing function that can handle any field type. // This just uses the regular (non-fast) parser to parse a single field. -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data); +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); #define UPB_PARSE_PARAMS \ struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ @@ -2375,22 +2071,18 @@ TAGBYTES(r) #undef UPB_PARSE_PARAMS -#ifdef __cplusplus -} /* extern "C" */ -#endif - - #endif /* UPB_DECODE_FAST_H_ */ +/** upb/encode.h ************************************************************/ /* - * upb_Encode: parsing from a upb_Message using a upb_MiniTable. + * upb_Encode: parsing into a upb_Message using a upb_MiniTable. */ #ifndef UPB_ENCODE_H_ #define UPB_ENCODE_H_ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -2403,35 +2095,25 @@ enum { * * If your proto contains maps, the encoder will need to malloc()/free() * memory during encode. */ - kUpb_EncodeOption_Deterministic = 1, + kUpb_Encode_Deterministic = 1, /* When set, unknown fields are not printed. */ - kUpb_EncodeOption_SkipUnknown = 2, + kUpb_Encode_SkipUnknown = 2, /* When set, the encode will fail if any required fields are missing. */ - kUpb_EncodeOption_CheckRequired = 4, + kUpb_Encode_CheckRequired = 4, }; #define UPB_ENCODE_MAXDEPTH(depth) ((depth) << 16) -typedef enum { - kUpb_EncodeStatus_Ok = 0, - kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_EncodeStatus_MaxDepthExceeded = 2, // Exceeded UPB_ENCODE_MAXDEPTH +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size); - // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. - kUpb_EncodeStatus_MissingRequired = 3, -} upb_EncodeStatus; - -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size); #ifdef __cplusplus } /* extern "C" */ #endif - #endif /* UPB_ENCODE_H_ */ @@ -2439,6 +2121,33 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, extern "C" { #endif +struct google_protobuf_FileDescriptorSet; +struct google_protobuf_FileDescriptorProto; +struct google_protobuf_DescriptorProto; +struct google_protobuf_DescriptorProto_ExtensionRange; +struct google_protobuf_DescriptorProto_ReservedRange; +struct google_protobuf_ExtensionRangeOptions; +struct google_protobuf_FieldDescriptorProto; +struct google_protobuf_OneofDescriptorProto; +struct google_protobuf_EnumDescriptorProto; +struct google_protobuf_EnumDescriptorProto_EnumReservedRange; +struct google_protobuf_EnumValueDescriptorProto; +struct google_protobuf_ServiceDescriptorProto; +struct google_protobuf_MethodDescriptorProto; +struct google_protobuf_FileOptions; +struct google_protobuf_MessageOptions; +struct google_protobuf_FieldOptions; +struct google_protobuf_OneofOptions; +struct google_protobuf_EnumOptions; +struct google_protobuf_EnumValueOptions; +struct google_protobuf_ServiceOptions; +struct google_protobuf_MethodOptions; +struct google_protobuf_UninterpretedOption; +struct google_protobuf_UninterpretedOption_NamePart; +struct google_protobuf_SourceCodeInfo; +struct google_protobuf_SourceCodeInfo_Location; +struct google_protobuf_GeneratedCodeInfo; +struct google_protobuf_GeneratedCodeInfo_Annotation; typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; @@ -2466,33 +2175,33 @@ typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; -extern const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init; -extern const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msg_init; -extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init; -extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init; -extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_FileOptions_msg_init; -extern const upb_MiniTable google_protobuf_MessageOptions_msg_init; -extern const upb_MiniTable google_protobuf_FieldOptions_msg_init; -extern const upb_MiniTable google_protobuf_OneofOptions_msg_init; -extern const upb_MiniTable google_protobuf_EnumOptions_msg_init; -extern const upb_MiniTable google_protobuf_EnumValueOptions_msg_init; -extern const upb_MiniTable google_protobuf_ServiceOptions_msg_init; -extern const upb_MiniTable google_protobuf_MethodOptions_msg_init; -extern const upb_MiniTable google_protobuf_UninterpretedOption_msg_init; -extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msg_init; -extern const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init; -extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init; -extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init; -extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init; +extern const upb_MiniTable google_protobuf_FileDescriptorSet_msginit; +extern const upb_MiniTable google_protobuf_FileDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit; +extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; +extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_FileOptions_msginit; +extern const upb_MiniTable google_protobuf_MessageOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldOptions_msginit; +extern const upb_MiniTable google_protobuf_OneofOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumValueOptions_msginit; +extern const upb_MiniTable google_protobuf_ServiceOptions_msginit; +extern const upb_MiniTable google_protobuf_MethodOptions_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit; typedef enum { google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, @@ -2539,12 +2248,6 @@ typedef enum { google_protobuf_FileOptions_LITE_RUNTIME = 3 } google_protobuf_FileOptions_OptimizeMode; -typedef enum { - google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0, - google_protobuf_GeneratedCodeInfo_Annotation_SET = 1, - google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2 -} google_protobuf_GeneratedCodeInfo_Annotation_Semantic; - typedef enum { google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, @@ -2552,23 +2255,22 @@ typedef enum { } google_protobuf_MethodOptions_IdempotencyLevel; -extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enum_init; -extern const upb_MiniTable_Enum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init; -extern const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enum_init; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit; +extern const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit; /* google.protobuf.FileDescriptorSet */ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google_protobuf_FileDescriptorSet_msg_init, arena); + return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google_protobuf_FileDescriptorSet_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2578,22 +2280,18 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorSet_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorSet_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -2612,7 +2310,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS return (google_protobuf_FileDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { - struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msg_init, arena); + struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2621,12 +2319,12 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr /* google.protobuf.FileDescriptorProto */ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msg_init, arena); + return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2636,22 +2334,18 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -2720,7 +2414,6 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(const google_protobuf_FileDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const google_protobuf_FileOptions*); @@ -2730,7 +2423,6 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const g } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(const google_protobuf_FileDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const upb_Message*) = NULL; - _upb_clearhas(msg, 4); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const google_protobuf_SourceCodeInfo*); @@ -2757,16 +2449,6 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(const google_pr UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 112), upb_StringView); } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { - return _upb_hasbit(msg, 6); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); - _upb_clearhas(msg, 6); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView); -} UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); @@ -2792,7 +2474,7 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2804,7 +2486,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2816,7 +2498,7 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 64), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msg_init, arena); + struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 64), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2828,7 +2510,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2840,7 +2522,7 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msg_init, arena); + sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_options(msg, sub); } @@ -2853,7 +2535,7 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); if (sub == NULL) { - sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msg_init, arena); + sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); } @@ -2881,20 +2563,16 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_F _upb_sethas(msg, 5); *UPB_PTR_AT(msg, UPB_SIZE(56, 112), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { - _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView) = value; -} /* google.protobuf.DescriptorProto */ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); + return (google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2904,22 +2582,18 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -2981,7 +2655,6 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobu } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(const google_protobuf_DescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_MessageOptions*); @@ -3022,7 +2695,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3034,7 +2707,7 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_res return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3046,7 +2719,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3058,7 +2731,7 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msg_init, arena); + struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3070,7 +2743,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3082,7 +2755,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_Desc UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msg_init, arena); + sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_set_options(msg, sub); } @@ -3095,7 +2768,7 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msg_init, arena); + struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3107,7 +2780,7 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msg_init, arena); + struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(40, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3125,12 +2798,12 @@ UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobu /* google.protobuf.DescriptorProto.ExtensionRange */ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msg_init, arena); + return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3140,22 +2813,18 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { return _upb_hasbit(msg, 1); @@ -3182,7 +2851,6 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); @@ -3203,7 +2871,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(googl UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msg_init, arena); + sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); } @@ -3213,12 +2881,12 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_Descrip /* google.protobuf.DescriptorProto.ReservedRange */ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msg_init, arena); + return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3228,22 +2896,18 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { return _upb_hasbit(msg, 1); @@ -3278,12 +2942,12 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro /* google.protobuf.ExtensionRangeOptions */ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msg_init, arena); + return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); } UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3293,22 +2957,18 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -3327,7 +2987,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3336,12 +2996,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension /* google.protobuf.FieldDescriptorProto */ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); + return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3351,22 +3011,18 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -3443,7 +3099,6 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(const google_protobuf_FieldDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const upb_Message*) = NULL; - _upb_clearhas(msg, 8); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const google_protobuf_FieldOptions*); @@ -3514,7 +3169,7 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msg_init, arena); + sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FieldDescriptorProto_set_options(msg, sub); } @@ -3536,12 +3191,12 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_ /* google.protobuf.OneofDescriptorProto */ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msg_init, arena); + return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3551,22 +3206,18 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -3583,7 +3234,6 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(const google_protobuf_OneofDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); @@ -3600,7 +3250,7 @@ UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msg_init, arena); + sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); if (!sub) return NULL; google_protobuf_OneofDescriptorProto_set_options(msg, sub); } @@ -3610,12 +3260,12 @@ UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorP /* google.protobuf.EnumDescriptorProto */ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); + return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3625,22 +3275,18 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -3666,7 +3312,6 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(const google_protobuf_EnumDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_EnumOptions*); @@ -3698,7 +3343,7 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msg_init, arena); + struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3710,7 +3355,7 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msg_init, arena); + sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumDescriptorProto_set_options(msg, sub); } @@ -3723,7 +3368,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, arena); + struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3741,12 +3386,12 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_pro /* google.protobuf.EnumDescriptorProto.EnumReservedRange */ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3756,22 +3401,18 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { return _upb_hasbit(msg, 1); @@ -3806,12 +3447,12 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go /* google.protobuf.EnumValueDescriptorProto */ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msg_init, arena); + return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3821,22 +3462,18 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -3863,7 +3500,6 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const googl } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(const google_protobuf_EnumValueDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); @@ -3884,7 +3520,7 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_prot UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msg_init, arena); + sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); } @@ -3894,12 +3530,12 @@ UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDes /* google.protobuf.ServiceDescriptorProto */ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msg_init, arena); + return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3909,22 +3545,18 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -3950,7 +3582,6 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_ } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(const google_protobuf_ServiceDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_ServiceOptions*); @@ -3967,7 +3598,7 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msg_init, arena); + struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3979,7 +3610,7 @@ UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protob UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msg_init, arena); + sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); if (!sub) return NULL; google_protobuf_ServiceDescriptorProto_set_options(msg, sub); } @@ -3989,12 +3620,12 @@ UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescrip /* google.protobuf.MethodDescriptorProto */ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msg_init, arena); + return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4004,22 +3635,18 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 1); @@ -4056,7 +3683,6 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_p } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(const google_protobuf_MethodDescriptorProto* msg) { *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const upb_Message*) = NULL; - _upb_clearhas(msg, 4); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); @@ -4101,7 +3727,7 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobu UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msg_init, arena); + sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); if (!sub) return NULL; google_protobuf_MethodDescriptorProto_set_options(msg, sub); } @@ -4119,12 +3745,12 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(googl /* google.protobuf.FileOptions */ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Arena* arena) { - return (google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msg_init, arena); + return (google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); } UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4134,22 +3760,18 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 1); @@ -4448,7 +4070,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_res return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(100, 184), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(100, 184), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4457,12 +4079,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio /* google.protobuf.MessageOptions */ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(upb_Arena* arena) { - return (google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msg_init, arena); + return (google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); } UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4472,22 +4094,18 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MessageOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MessageOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { return _upb_hasbit(msg, 1); @@ -4562,7 +4180,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4571,12 +4189,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp /* google.protobuf.FieldOptions */ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msg_init, arena); + return (google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); } UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4586,22 +4204,18 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { return _upb_hasbit(msg, 1); @@ -4718,7 +4332,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4727,12 +4341,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti /* google.protobuf.OneofOptions */ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Arena* arena) { - return (google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msg_init, arena); + return (google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); } UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4742,22 +4356,18 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -4776,7 +4386,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4785,12 +4395,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti /* google.protobuf.EnumOptions */ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msg_init, arena); + return (google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4800,22 +4410,18 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { return _upb_hasbit(msg, 1); @@ -4862,7 +4468,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4871,12 +4477,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio /* google.protobuf.EnumValueOptions */ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msg_init, arena); + return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4886,22 +4492,18 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { return _upb_hasbit(msg, 1); @@ -4934,7 +4536,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4943,12 +4545,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue /* google.protobuf.ServiceOptions */ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(upb_Arena* arena) { - return (google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msg_init, arena); + return (google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); } UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4958,22 +4560,18 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { return _upb_hasbit(msg, 1); @@ -5006,7 +4604,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5015,12 +4613,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp /* google.protobuf.MethodOptions */ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_Arena* arena) { - return (google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msg_init, arena); + return (google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); } UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5030,22 +4628,18 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { return _upb_hasbit(msg, 1); @@ -5092,7 +4686,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5101,12 +4695,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt /* google.protobuf.UninterpretedOption */ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5116,22 +4710,18 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); @@ -5210,7 +4800,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte return (google_protobuf_UninterpretedOption_NamePart**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msg_init, arena); + struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5243,12 +4833,12 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_p /* google.protobuf.UninterpretedOption.NamePart */ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msg_init, arena); + return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5258,22 +4848,18 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { return _upb_hasbit(msg, 1); @@ -5308,12 +4894,12 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go /* google.protobuf.SourceCodeInfo */ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msg_init, arena); + return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5323,22 +4909,18 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -5357,7 +4939,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI return (google_protobuf_SourceCodeInfo_Location**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { - struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msg_init, arena); + struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5366,12 +4948,12 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc /* google.protobuf.SourceCodeInfo.Location */ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msg_init, arena); + return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5381,22 +4963,18 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, options, arena, len); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(const google_protobuf_SourceCodeInfo_Location* msg) { _upb_array_detach(msg, UPB_SIZE(4, 8)); @@ -5476,12 +5054,12 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_com /* google.protobuf.GeneratedCodeInfo */ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_msg_init, arena); + return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5491,22 +5069,18 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -5525,7 +5099,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msg_init, arena); + struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5534,12 +5108,12 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_ /* google.protobuf.GeneratedCodeInfo.Annotation */ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msg_init, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5549,38 +5123,34 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, options, arena, len); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 16)); + _upb_array_detach(msg, UPB_SIZE(12, 16)); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(16, 16), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(12, 16), len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 2); @@ -5602,29 +5172,19 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(const goo UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return _upb_hasbit(msg, 4); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t) = 0; - _upb_clearhas(msg, 4); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t); -} UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 16), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 16), len); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 16), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 16), len, 2, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 16), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 16), 2, &val, arena); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 2); @@ -5634,10 +5194,6 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot _upb_sethas(msg, 3); *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { - _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(12, 12), int32_t) = value; -} extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout; @@ -5652,549 +5208,355 @@ extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ -#ifndef UPB_REFLECTION_DEF_H_ -#define UPB_REFLECTION_DEF_H_ +#ifdef __cplusplus +extern "C" { +#endif + +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const upb_Map* map_val; + const upb_Message* msg_val; + const upb_Array* array_val; + upb_StringView str_val; +} upb_MessageValue; + +typedef union { + upb_Map* map; + upb_Message* msg; + upb_Array* array; +} upb_MutableMessageValue; + +/** upb_Array *****************************************************************/ + +/* Creates a new array on the given arena that holds elements of this type. */ +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); + +/* Returns the size of the array. */ +size_t upb_Array_Size(const upb_Array* arr); + +/* Returns the given element, which must be within the array's current size. */ +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); + +/* Sets the given element, which must be within the array's current size. */ +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); + +/* Appends an element to the array. Returns false on allocation failure. */ +bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena); + +/* Moves elements within the array using memmove(). Like memmove(), the source + * and destination elements may be overlapping. */ +void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); + +/* Inserts one or more empty elements into the array. Existing elements are + * shifted right. The new elements have undefined state and must be set with + * `upb_Array_Set()`. + * REQUIRES: `i <= upb_Array_Size(arr)` */ +bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); + +/* Deletes one or more elements from the array. Existing elements are shifted + * left. + * REQUIRES: `i + count <= upb_Array_Size(arr)` */ +void upb_Array_Delete(upb_Array* array, size_t i, size_t count); + +/* Changes the size of a vector. New elements are initialized to empty/0. + * Returns false on allocation failure. */ +bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); + +/** upb_Map *******************************************************************/ + +/* Creates a new map on the given arena with the given key/value size. */ +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type); + +/* Returns the number of entries in the map. */ +size_t upb_Map_Size(const upb_Map* map); + +/* Stores a value for the given key into |*val| (or the zero value if the key is + * not present). Returns whether the key was present. The |val| pointer may be + * NULL, in which case the function tests whether the given key is present. */ +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +/* Removes all entries in the map. */ +void upb_Map_Clear(upb_Map* map); + +typedef enum { + // LINT.IfChange + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, + // LINT.ThenChange(//depot/google3/third_party/upb/upb/msg_internal.h) +} upb_MapInsertStatus; + +/* Sets the given key to the given value, returning whether the key was inserted + * or replaced. If the key was inserted, then any existing iterators will be + * invalidated. */ +upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena); + +/* Sets the given key to the given value. Returns false if memory allocation + * failed. If the key is newly inserted, then any existing iterators will be + * invalidated. */ +UPB_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + return upb_Map_Insert(map, key, val, arena) != + kUpb_MapInsertStatus_OutOfMemory; +} + +/* Deletes this key from the table. Returns true if the key was present. */ +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key); + +/* Map iteration: + * + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); + * + * // If mutating is desired. + * upb_MapIterator_SetValue(map, iter, value2); + * } + */ + +/* Advances to the next entry. Returns false if no more entries are present. */ +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); + +/* Returns true if the iterator still points to a valid entry, or false if the + * iterator is past the last element. It is an error to call this function with + * kUpb_Map_Begin (you must call next() at least once first). */ +bool upb_MapIterator_Done(const upb_Map* map, size_t iter); + +/* Returns the key and value for this entry of the map. */ +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); + +/* Sets the value for this entry. The iterator must not be done, and the + * iterator must not have been initialized const. */ +void upb_MapIterator_SetValue(upb_Map* map, size_t iter, + upb_MessageValue value); + +#ifdef __cplusplus +} /* extern "C" */ +#endif -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +#endif /* UPB_COLLECTIONS_H_ */ -#ifndef UPB_REFLECTION_DEF_POOL_H_ -#define UPB_REFLECTION_DEF_POOL_H_ +/** upb/def.h ************************************************************/ +#ifndef UPB_DEF_H_ +#define UPB_DEF_H_ -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +/* Must be last. */ -// Declarations common to all public def types. - -#ifndef UPB_REFLECTION_COMMON_H_ -#define UPB_REFLECTION_COMMON_H_ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +struct upb_EnumDef; +typedef struct upb_EnumDef upb_EnumDef; +struct upb_EnumValueDef; +typedef struct upb_EnumValueDef upb_EnumValueDef; +struct upb_ExtensionRange; +typedef struct upb_ExtensionRange upb_ExtensionRange; +struct upb_FieldDef; +typedef struct upb_FieldDef upb_FieldDef; +struct upb_FileDef; +typedef struct upb_FileDef upb_FileDef; +struct upb_MethodDef; +typedef struct upb_MethodDef upb_MethodDef; +struct upb_MessageDef; +typedef struct upb_MessageDef upb_MessageDef; +struct upb_OneofDef; +typedef struct upb_OneofDef upb_OneofDef; +struct upb_ServiceDef; +typedef struct upb_ServiceDef upb_ServiceDef; +struct upb_streamdef; +typedef struct upb_streamdef upb_streamdef; +struct upb_DefPool; +typedef struct upb_DefPool upb_DefPool; +typedef struct upb_EnumReservedRange upb_EnumReservedRange; +typedef struct upb_MessageReservedRange upb_MessageReservedRange; +typedef struct symtab_addctx symtab_addctx; typedef enum { kUpb_Syntax_Proto2 = 2, kUpb_Syntax_Proto3 = 3 } upb_Syntax; -// Forward declarations for circular references. -typedef struct upb_DefPool upb_DefPool; -typedef struct upb_EnumDef upb_EnumDef; -typedef struct upb_EnumValueDef upb_EnumValueDef; -typedef struct upb_ExtensionRange upb_ExtensionRange; -typedef struct upb_FieldDef upb_FieldDef; -typedef struct upb_FileDef upb_FileDef; -typedef struct upb_MessageDef upb_MessageDef; -typedef struct upb_MethodDef upb_MethodDef; -typedef struct upb_OneofDef upb_OneofDef; -typedef struct upb_ServiceDef upb_ServiceDef; - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -typedef struct upb_DefBuilder upb_DefBuilder; - -#endif /* UPB_REFLECTION_COMMON_H_ */ - -#ifndef UPB_REFLECTION_DEF_TYPE_H_ -#define UPB_REFLECTION_DEF_TYPE_H_ - - -// Must be last. - -// Inside a symtab we store tagged pointers to specific def types. -typedef enum { - UPB_DEFTYPE_MASK = 7, - - // Only inside symtab table. - UPB_DEFTYPE_EXT = 0, - UPB_DEFTYPE_MSG = 1, - UPB_DEFTYPE_ENUM = 2, - UPB_DEFTYPE_ENUMVAL = 3, - UPB_DEFTYPE_SERVICE = 4, - - // Only inside message table. - UPB_DEFTYPE_FIELD = 0, - UPB_DEFTYPE_ONEOF = 1, - UPB_DEFTYPE_FIELD_JSONNAME = 2, -} upb_deftype_t; - -#ifdef __cplusplus -extern "C" { -#endif - -// Our 3-bit pointer tagging requires all pointers to be multiples of 8. -// The arena will always yield 8-byte-aligned addresses, however we put -// the defs into arrays. For each element in the array to be 8-byte-aligned, -// the sizes of each def type must also be a multiple of 8. -// -// If any of these asserts fail, we need to add or remove padding on 32-bit -// machines (64-bit machines will have 8-byte alignment already due to -// pointers, which all of these structs have). -UPB_INLINE void _upb_DefType_CheckPadding(size_t size) { - UPB_ASSERT((size & UPB_DEFTYPE_MASK) == 0); -} - -upb_deftype_t _upb_DefType_Type(upb_value v); - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type); - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_TYPE_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -void upb_DefPool_Free(upb_DefPool* s); - -upb_DefPool* upb_DefPool_New(void); - -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym); - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len); - -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym); - -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym); - -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name); - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len); - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym); - -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name); - -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name); - -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status); - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum); - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s); - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); -const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTable_Extension* ext); - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, - upb_FieldDef* f); -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status); -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v); - -void** _upb_DefPool_ScratchData(const upb_DefPool* s); -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); - -// For generated code only: loads a generated descriptor. -typedef struct _upb_DefPool_Init { - struct _upb_DefPool_Init** deps; // Dependencies of this file. - const upb_MiniTable_File* layout; - const char* filename; - upb_StringView descriptor; // Serialized descriptor. -} _upb_DefPool_Init; - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); - -// Should only be directly called by tests. This variant lets us suppress -// the use of compiled-in tables, forcing a rebuild of the tables at runtime. -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_POOL_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_DEF_H_ -#define UPB_REFLECTION_ENUM_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); -int32_t upb_EnumDef_Default(const upb_EnumDef* e); -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name); -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size); -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num); -const char* upb_EnumDef_FullName(const upb_EnumDef* e); -bool upb_EnumDef_HasOptions(const upb_EnumDef* e); - -// Creates a mini descriptor string for an enum, returns true on success. -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out); - -const char* upb_EnumDef_Name(const upb_EnumDef* e); -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); -int upb_EnumDef_ValueCount(const upb_EnumDef* e); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i); -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); -const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); - -// Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_H_ -#define UPB_REFLECTION_ENUM_VALUE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v); -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v); -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v); -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v); -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, - bool* is_sorted); - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_EXTENSION_RANGE_H_ -#define UPB_REFLECTION_EXTENSION_RANGE_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); - -// Allocate and initialize an array of |n| extension ranges owned by |m|. -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_EXTENSION_RANGE_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FIELD_DEF_H_ -#define UPB_REFLECTION_FIELD_DEF_H_ - - -// Must be last. - -// Maximum field number allowed for FieldDefs. -// This is an inherent limit of the protobuf wire format. -#define kUpb_MaxFieldNumber ((1 << 29) - 1) - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f); -upb_CType upb_FieldDef_CType(const upb_FieldDef* f); -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); -const char* upb_FieldDef_FullName(const upb_FieldDef* f); -bool upb_FieldDef_HasDefault(const upb_FieldDef* f); -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); -bool upb_FieldDef_HasOptions(const upb_FieldDef* f); -bool upb_FieldDef_HasPresence(const upb_FieldDef* f); -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); -uint32_t upb_FieldDef_Index(const upb_FieldDef* f); -bool upb_FieldDef_IsExtension(const upb_FieldDef* f); -bool upb_FieldDef_IsMap(const upb_FieldDef* f); -bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool upb_FieldDef_IsPacked(const upb_FieldDef* f); -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); -bool upb_FieldDef_IsRequired(const upb_FieldDef* f); -bool upb_FieldDef_IsString(const upb_FieldDef* f); -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); -const char* upb_FieldDef_JsonName(const upb_FieldDef* f); -upb_Label upb_FieldDef_Label(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); - -// Creates a mini descriptor string for a field, returns true on success. -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out); - -const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f); -const char* upb_FieldDef_Name(const upb_FieldDef* f); -uint32_t upb_FieldDef_Number(const upb_FieldDef* f); -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); - -const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f); -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f); - -// Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); - -// Allocate and return a list of pointers to the |n| field defs in |ff|, -// sorted by field number. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FIELD_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FILE_DEF_H_ -#define UPB_REFLECTION_FILE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); -int upb_FileDef_DependencyCount(const upb_FileDef* f); -bool upb_FileDef_HasOptions(const upb_FileDef* f); -const char* upb_FileDef_Name(const upb_FileDef* f); -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); -const char* upb_FileDef_Package(const upb_FileDef* f); -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); -int upb_FileDef_ServiceCount(const upb_FileDef* f); - -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f); - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i); -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); - -// upb_FileDef_Package() returns "" if f->package is NULL, this does not. -const char* _upb_FileDef_RawPackage(const upb_FileDef* f); - -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FILE_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_DEF_H_ -#define UPB_REFLECTION_MESSAGE_DEF_H_ - - -// Must be last. - -// Well-known field tag numbers for map-entry messages. -#define kUpb_MapEntry_KeyFieldNumber 1 -#define kUpb_MapEntry_ValueFieldNumber 2 - -// Well-known field tag numbers for Any messages. -#define kUpb_Any_TypeFieldNumber 1 -#define kUpb_Any_ValueFieldNumber 2 - -// Well-known field tag numbers for duration messages. -#define kUpb_Duration_SecondsFieldNumber 1 -#define kUpb_Duration_NanosFieldNumber 2 - -// Well-known field tag numbers for timestamp messages. -#define kUpb_Timestamp_SecondsFieldNumber 1 -#define kUpb_Timestamp_NanosFieldNumber 2 - -// All the different kind of well known type messages. For simplicity of check, -// number wrappers and string wrappers are grouped together. Make sure the -// order and number of these groups are not changed. +/* All the different kind of well known type messages. For simplicity of check, + * number wrappers and string wrappers are grouped together. Make sure the + * order and merber of these groups are not changed. + */ typedef enum { kUpb_WellKnown_Unspecified, kUpb_WellKnown_Any, kUpb_WellKnown_FieldMask, kUpb_WellKnown_Duration, kUpb_WellKnown_Timestamp, - - // number wrappers + /* number wrappers */ kUpb_WellKnown_DoubleValue, kUpb_WellKnown_FloatValue, kUpb_WellKnown_Int64Value, kUpb_WellKnown_UInt64Value, kUpb_WellKnown_Int32Value, kUpb_WellKnown_UInt32Value, - - // string wrappers + /* string wrappers */ kUpb_WellKnown_StringValue, kUpb_WellKnown_BytesValue, kUpb_WellKnown_BoolValue, kUpb_WellKnown_Value, kUpb_WellKnown_ListValue, - kUpb_WellKnown_Struct, + kUpb_WellKnown_Struct } upb_WellKnown; -#ifdef __cplusplus -extern "C" { -#endif +/* upb_FieldDef ***************************************************************/ +/* Maximum field number allowed for FieldDefs. This is an inherent limit of the + * protobuf wire format. */ +#define kUpb_MaxFieldNumber ((1 << 29) - 1) + +const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); +bool upb_FieldDef_HasOptions(const upb_FieldDef* f); +const char* upb_FieldDef_FullName(const upb_FieldDef* f); +upb_CType upb_FieldDef_CType(const upb_FieldDef* f); +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); +upb_Label upb_FieldDef_Label(const upb_FieldDef* f); +uint32_t upb_FieldDef_Number(const upb_FieldDef* f); +const char* upb_FieldDef_Name(const upb_FieldDef* f); +const char* upb_FieldDef_JsonName(const upb_FieldDef* f); +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); +bool upb_FieldDef_IsExtension(const upb_FieldDef* f); +bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); +uint32_t upb_FieldDef_Index(const upb_FieldDef* f); +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); +bool upb_FieldDef_IsString(const upb_FieldDef* f); +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); +bool upb_FieldDef_IsMap(const upb_FieldDef* f); +bool upb_FieldDef_HasDefault(const upb_FieldDef* f); +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); +bool upb_FieldDef_HasPresence(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); +const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f); +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); + +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); +bool upb_OneofDef_HasOptions(const upb_OneofDef* o); +const char* upb_OneofDef_Name(const upb_OneofDef* o); +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o); +uint32_t upb_OneofDef_Index(const upb_OneofDef* o); +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); +int upb_OneofDef_FieldCount(const upb_OneofDef* o); +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); + +/* Oneof lookups: + * - ntof: look up a field by name. + * - ntofz: look up a field by name (as a null-terminated string). + * - itof: look up a field by number. */ +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length); +UPB_INLINE const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, + const char* name) { + return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); +} +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num); + +/* upb_MessageDef *************************************************************/ + +/* Well-known field tag numbers for map-entry messages. */ +#define kUpb_MapEntry_KeyFieldNumber 1 +#define kUpb_MapEntry_ValueFieldNumber 2 + +/* Well-known field tag numbers for Any messages. */ +#define kUpb_Any_TypeFieldNumber 1 +#define kUpb_Any_ValueFieldNumber 2 + +/* Well-known field tag numbers for duration messages. */ +#define kUpb_Duration_SecondsFieldNumber 1 +#define kUpb_Duration_NanosFieldNumber 2 + +/* Well-known field tag numbers for timestamp messages. */ +#define kUpb_Timestamp_SecondsFieldNumber 1 +#define kUpb_Timestamp_NanosFieldNumber 2 + +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m); +bool upb_MessageDef_HasOptions(const upb_MessageDef* m); +const char* upb_MessageDef_FullName(const upb_MessageDef* m); +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m); - +const char* upb_MessageDef_Name(const upb_MessageDef* m); +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); +int upb_MessageDef_FieldCount(const upb_MessageDef* m); +int upb_MessageDef_OneofCount(const upb_MessageDef* m); const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, int i); -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); - const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i); -int upb_MessageDef_FieldCount(const upb_MessageDef* m); +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i); +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); - -// Returns a field by either JSON name or regular proto name. -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( +UPB_INLINE const upb_OneofDef* upb_MessageDef_FindOneofByName( const upb_MessageDef* m, const char* name) { - return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); + return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); } -// Lookup of either field or oneof by name. Returns whether either was found. -// If the return is true, then the found def will be set, and the non-found -// one set to NULL. +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindFieldByName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +} + +UPB_INLINE bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { + return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); +} + +UPB_INLINE bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { + return google_protobuf_MessageOptions_message_set_wire_format( + upb_MessageDef_Options(m)); +} + +/* Nested entities. */ +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i); +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i); + +/* Lookup of either field or oneof by name. Returns whether either was found. + * If the return is true, then the found def will be set, and the non-found + * one set to NULL. */ bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t size, + const char* name, size_t len, const upb_FieldDef** f, const upb_OneofDef** o); + UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, const char* name, const upb_FieldDef** f, @@ -6202,200 +5564,199 @@ UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, return upb_MessageDef_FindByNameWithSize(m, name, strlen(name), f, o); } -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name); -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i); -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name); -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -const char* upb_MessageDef_FullName(const upb_MessageDef* m); -bool upb_MessageDef_HasOptions(const upb_MessageDef* m); -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m); -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m); +/* Returns a field by either JSON name or regular proto name. */ +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); +} -// Creates a mini descriptor string for a message, returns true on success. -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out); +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); -const char* upb_MessageDef_Name(const upb_MessageDef* m); +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i); +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m); -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i); -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i); +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); +/* upb_ExtensionRange *********************************************************/ -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); -int upb_MessageDef_OneofCount(const upb_MessageDef* m); +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r); +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m); -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); +/* upb_EnumDef ****************************************************************/ -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); +bool upb_EnumDef_HasOptions(const upb_EnumDef* e); +const char* upb_EnumDef_FullName(const upb_EnumDef* e); +const char* upb_EnumDef_Name(const upb_EnumDef* e); +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); +int32_t upb_EnumDef_Default(const upb_EnumDef* e); +int upb_EnumDef_ValueCount(const upb_EnumDef* e); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i); -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m); -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t size, - upb_value v, upb_Arena* a); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f); -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m); -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* e, const char* name, size_t len); +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, + int32_t num); +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const upb_MessageDef* containing_type); +// Convenience wrapper. +UPB_INLINE const upb_EnumValueDef* upb_EnumDef_FindValueByName( + const upb_EnumDef* e, const char* name) { + return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); +} -#ifdef __cplusplus -} /* extern "C" */ -#endif +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i); +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e); -#endif /* UPB_REFLECTION_MESSAGE_DEF_H_ */ +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r); +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r); -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +/* upb_EnumValueDef ***********************************************************/ -#ifndef UPB_REFLECTION_METHOD_DEF_H_ -#define UPB_REFLECTION_METHOD_DEF_H_ +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e); +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* e); +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* e); +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* e); +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* e); +/* upb_FileDef ****************************************************************/ -// Must be last. +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); +bool upb_FileDef_HasOptions(const upb_FileDef* f); +const char* upb_FileDef_Name(const upb_FileDef* f); +const char* upb_FileDef_Package(const upb_FileDef* f); +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f); +int upb_FileDef_DependencyCount(const upb_FileDef* f); +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); +int upb_FileDef_ServiceCount(const upb_FileDef* f); +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); -#ifdef __cplusplus -extern "C" { -#endif +/* upb_MethodDef **************************************************************/ -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); -const char* upb_MethodDef_FullName(const upb_MethodDef* m); +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m); bool upb_MethodDef_HasOptions(const upb_MethodDef* m); +const char* upb_MethodDef_FullName(const upb_MethodDef* m); int upb_MethodDef_Index(const upb_MethodDef* m); -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m); -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_METHOD_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ONEOF_DEF_H_ -#define UPB_REFLECTION_ONEOF_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o); -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); -int upb_OneofDef_FieldCount(const upb_OneofDef* o); -const char* upb_OneofDef_FullName(const upb_OneofDef* o); -bool upb_OneofDef_HasOptions(const upb_OneofDef* o); -uint32_t upb_OneofDef_Index(const upb_OneofDef* o); -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name); -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size); -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num); -const char* upb_OneofDef_Name(const upb_OneofDef* o); -int upb_OneofDef_numfields(const upb_OneofDef* o); -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, - const char* name, size_t size, upb_Arena* a); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ONEOF_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_SERVICE_DEF_H_ -#define UPB_REFLECTION_SERVICE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/* upb_ServiceDef *************************************************************/ +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s); +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); +const char* upb_ServiceDef_Name(const upb_ServiceDef* s); +int upb_ServiceDef_Index(const upb_ServiceDef* s); const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s); +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, const char* name); -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); -int upb_ServiceDef_Index(const upb_ServiceDef* s); -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); -const char* upb_ServiceDef_Name(const upb_ServiceDef* s); -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s); -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +/* upb_DefPool ****************************************************************/ -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); +upb_DefPool* upb_DefPool_New(void); +void upb_DefPool_Free(upb_DefPool* s); +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym); +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym); +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size); +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name); +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len); +const upb_FileDef* upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file, + upb_Status* status); +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); +const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum); +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s); +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count); + +/* For generated code only: loads a generated descriptor. */ +typedef struct _upb_DefPool_Init { + struct _upb_DefPool_Init** deps; /* Dependencies of this file. */ + const upb_MiniTable_File* layout; + const char* filename; + upb_StringView descriptor; /* Serialized descriptor. */ +} _upb_DefPool_Init; + +// Should only be directly called by tests. This variant lets us suppress +// the use of compiled-in tables, forcing a rebuild of the tables at runtime. +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable); + +UPB_INLINE bool _upb_DefPool_LoadDefInit(upb_DefPool* s, + const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); +} -// Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos); #ifdef __cplusplus } /* extern "C" */ -#endif +#endif /* __cplusplus */ +#endif /* UPB_DEF_H_ */ -#endif /* UPB_REFLECTION_SERVICE_DEF_H_ */ - -#endif /* UPB_REFLECTION_DEF_H_ */ -/* This file was generated by upbc (the upb compiler) from the input +/** google/protobuf/descriptor.upbdefs.h ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: * * google/protobuf/descriptor.proto @@ -6556,25 +5917,25 @@ UPB_INLINE const upb_MessageDef *google_protobuf_GeneratedCodeInfo_Annotation_ge #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPBDEFS_H_ */ +/** upb/decode_internal.h ************************************************************/ /* * Internal implementation details of the decoder that are shared between * decode.c and decode_fast.c. */ -#ifndef UPB_INTERNAL_DECODE_H_ -#define UPB_INTERNAL_DECODE_H_ +#ifndef UPB_DECODE_INT_H_ +#define UPB_DECODE_INT_H_ + +#include + +#include "third_party/utf8_range/utf8_range.h" + +/** upb/upb_internal.h ************************************************************/ +#ifndef UPB_INT_H_ +#define UPB_INT_H_ -#ifndef UPB_INTERNAL_ARENA_H_ -#define UPB_INTERNAL_ARENA_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - +struct mem_block; typedef struct mem_block mem_block; struct upb_Arena { @@ -6599,16 +5960,19 @@ struct upb_Arena { mem_block *freelist, *freelist_tail; }; -#ifdef __cplusplus -} /* extern "C" */ -#endif +// Encodes a float or double that is round-trippable, but as short as possible. +// These routines are not fully optimal (not guaranteed to be shortest), but are +// short-ish and match the implementation that has been used in protobuf since +// the beginning. +// +// The given buffer size must be at least kUpb_RoundTripBufferSize. +enum { kUpb_RoundTripBufferSize = 32 }; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); +#endif /* UPB_INT_H_ */ -#endif /* UPB_INTERNAL_ARENA_H_ */ - -#include "third_party/utf8_range/utf8_range.h" - -// Must be last. +/* Must be last. */ #define DECODE_NOGROUP (uint32_t) - 1 @@ -6641,12 +6005,12 @@ typedef struct upb_Decoder { * of our optimizations. That is also why we must declare it in a separate file, * otherwise the compiler will see that it calls longjmp() and deduce that it is * noreturn. */ -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); +const char* fastdecode_err(upb_Decoder* d, int status); extern const uint8_t upb_utf8_offsets[]; UPB_INLINE -bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { +bool decode_verifyutf8_inl(const char* ptr, int len) { const char* end = ptr + len; // Check 8 bytes at a time for any non-ASCII char. @@ -6669,9 +6033,9 @@ non_ascii: return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; } -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* l); +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l); /* x86-64 pointers always have the high 16 bits matching. So we can shift * left 8 and right 8 without loss of information. */ @@ -6684,8 +6048,8 @@ UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { } UPB_INLINE -const char* _upb_Decoder_IsDoneFallbackInline(upb_Decoder* d, const char* ptr, - int overrun, int* status) { +const char* decode_isdonefallback_inl(upb_Decoder* d, const char* ptr, + int overrun, int* status) { if (overrun < d->limit) { /* Need to copy remaining data into patch buffer. */ UPB_ASSERT(overrun < 16); @@ -6712,27 +6076,26 @@ const char* _upb_Decoder_IsDoneFallbackInline(upb_Decoder* d, const char* ptr, } } -const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr, - int overrun); +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, int overrun); UPB_INLINE -bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { +bool decode_isdone(upb_Decoder* d, const char** ptr) { int overrun = *ptr - d->end; if (UPB_LIKELY(*ptr < d->limit_ptr)) { return false; } else if (UPB_LIKELY(overrun == d->limit)) { return true; } else { - *ptr = _upb_Decoder_IsDoneFallback(d, *ptr, overrun); + *ptr = decode_isdonefallback(d, *ptr, overrun); return false; } } #if UPB_FASTTABLE UPB_INLINE -const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { +const char* fastdecode_tagdispatch(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t tag) { const upb_MiniTable* table_p = decode_totablep(table); uint8_t mask = table; uint64_t data; @@ -6745,45 +6108,43 @@ const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, } #endif -UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { +UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) { uint16_t tag; memcpy(&tag, ptr, 2); return tag; } -UPB_INLINE void _upb_Decoder_CheckLimit(upb_Decoder* d) { +UPB_INLINE void decode_checklimit(upb_Decoder* d) { UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit)); } -UPB_INLINE int _upb_Decoder_PushLimit(upb_Decoder* d, const char* ptr, - int size) { +UPB_INLINE int decode_pushlimit(upb_Decoder* d, const char* ptr, int size) { int limit = size + (int)(ptr - d->end); int delta = d->limit - limit; - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); d->limit = limit; d->limit_ptr = d->end + UPB_MIN(0, limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); return delta; } -UPB_INLINE void _upb_Decoder_PopLimit(upb_Decoder* d, const char* ptr, - int saved_delta) { +UPB_INLINE void decode_poplimit(upb_Decoder* d, const char* ptr, + int saved_delta) { UPB_ASSERT(ptr - d->end == d->limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); d->limit += saved_delta; d->limit_ptr = d->end + UPB_MIN(0, d->limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); } -#endif /* UPB_INTERNAL_DECODE_H_ */ +#endif /* UPB_DECODE_INT_H_ */ -#ifndef UPB_JSON_DECODE_H_ -#define UPB_JSON_DECODE_H_ +/** upb/json_decode.h ************************************************************/ +#ifndef UPB_JSONDECODE_H_ +#define UPB_JSONDECODE_H_ -// Must be last. - #ifdef __cplusplus extern "C" { #endif @@ -6798,63 +6159,12 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, } /* extern "C" */ #endif - #endif /* UPB_JSONDECODE_H_ */ -#ifndef UPB_INTERNAL_UNICODE_H_ -#define UPB_INTERNAL_UNICODE_H_ +/** upb/reflection.h ************************************************************/ +#ifndef UPB_REFLECTION_H_ +#define UPB_REFLECTION_H_ -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns true iff a codepoint is the value for a high surrogate. -UPB_INLINE bool upb_Unicode_IsHigh(uint32_t cp) { - return (cp >= 0xd800 && cp <= 0xdbff); -} - -// Returns true iff a codepoint is the value for a low surrogate. -UPB_INLINE bool upb_Unicode_IsLow(uint32_t cp) { - return (cp >= 0xdc00 && cp <= 0xdfff); -} - -// Returns the high 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToHigh(uint32_t cp) { - return (cp >> 10) + 0xd7c0; -} - -// Returns the low 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToLow(uint32_t cp) { - return (cp & 0x3ff) | 0xdc00; -} - -// Returns the 32-bit value corresponding to a pair of 16-bit surrogates. -// Does not sanity-check the input. -UPB_INLINE uint32_t upb_Unicode_FromPair(uint32_t high, uint32_t low) { - return ((high & 0x3ff) << 10) + (low & 0x3ff) + 0x10000; -} - -// Outputs a codepoint as UTF8. -// Returns the number of bytes written (1-4 on success, 0 on error). -// Does not sanity-check the input. Specifically does not check for surrogates. -int upb_Unicode_ToUTF8(uint32_t cp, char* out); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_UNICODE_H_ */ - -#ifndef UPB_REFLECTION_MESSAGE_H_ -#define UPB_REFLECTION_MESSAGE_H_ - - -// Must be last. #ifdef __cplusplus extern "C" { @@ -6862,6 +6172,9 @@ extern "C" { upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f); +/** upb_Message + * *******************************************************************/ + /* Creates a new message of the given type in the given arena. */ upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a); @@ -6924,28 +6237,24 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, #endif -#endif /* UPB_REFLECTION_MESSAGE_H_ */ +#endif /* UPB_REFLECTION_H_ */ -#ifndef UPB_JSON_ENCODE_H_ -#define UPB_JSON_ENCODE_H_ +/** upb/json_encode.h ************************************************************/ +#ifndef UPB_JSONENCODE_H_ +#define UPB_JSONENCODE_H_ -// Must be last. - #ifdef __cplusplus extern "C" { #endif enum { /* When set, emits 0/default values. TODO(haberman): proto3 only? */ - upb_JsonEncode_EmitDefaults = 1 << 0, + upb_JsonEncode_EmitDefaults = 1, - /* When set, use normal (snake_case) field names instead of JSON (camelCase) + /* When set, use normal (snake_caes) field names instead of JSON (camelCase) names. */ - upb_JsonEncode_UseProtoNames = 1 << 1, - - /* When set, emits enums as their integer values instead of as their names. */ - upb_JsonEncode_FormatEnumsAsIntegers = 1 << 2 + upb_JsonEncode_UseProtoNames = 2 }; /* Encodes the given |msg| to JSON format. The message's reflection is given in @@ -6964,35 +6273,9 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, } /* extern "C" */ #endif - #endif /* UPB_JSONENCODE_H_ */ -#ifndef UPB_INTERNAL_ENCODE_H_ -#define UPB_INTERNAL_ENCODE_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes a float or double that is round-trippable, but as short as possible. -// These routines are not fully optimal (not guaranteed to be shortest), but are -// short-ish and match the implementation that has been used in protobuf since -// the beginning. -// -// The given buffer size must be at least kUpb_RoundTripBufferSize. -enum { kUpb_RoundTripBufferSize = 32 }; -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ENCODE_H_ */ - +/** upb/internal/vsnprintf_compat.h ************************************************************/ #ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ #define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ @@ -7017,6 +6300,7 @@ UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, #endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +/** upb/mini_table.h ************************************************************/ #ifndef UPB_MINI_TABLE_H_ #define UPB_MINI_TABLE_H_ @@ -7035,9 +6319,16 @@ UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( return mini_table->subs[field->submsg_index].submsg; } -UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) { - return mini_table->subs[field->submsg_index].subenum; +UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e, + int32_t val) { + uint32_t uval = (uint32_t)val; + if (uval < 64) return e->mask & (1ULL << uval); + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if (e->values[i] == val) return true; + } + return false; } /** upb_MtDataEncoder *********************************************************/ @@ -7076,8 +6367,7 @@ typedef struct { // char buf[256]; // char* ptr = buf; // e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr); // // Fields *must* be in field number order. // ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); // ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); @@ -7125,27 +6415,15 @@ typedef enum { upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, upb_MiniTablePlatform platform, upb_Arena* arena, upb_Status* status); - -// Links a sub-message field to a MiniTable for that sub-message. If a -// sub-message field is not linked, it will be treated as an unknown field -// during parsing, and setting the field will not be allowed. It is possible -// to link the message field later, at which point it will no longer be treated -// as unknown. However there is no synchronization for this operation, which -// means parallel mutation requires external synchronization. void upb_MiniTable_SetSubMessage(upb_MiniTable* table, upb_MiniTable_Field* field, const upb_MiniTable* sub); - -// Links an enum field to a MiniTable for that enum. All enum fields must -// be linked prior to parsing. void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, const upb_MiniTable_Enum* sub); -const char* upb_MiniTable_BuildExtension(const char* data, size_t len, - upb_MiniTable_Extension* ext, - const upb_MiniTable* extendee, - upb_MiniTable_Sub sub, - upb_Status* status); +bool upb_MiniTable_BuildExtension(const char* data, size_t len, + upb_MiniTable_Extension* ext, + upb_MiniTable_Sub sub, upb_Status* status); // Special-case functions for MessageSet layout and map entries. upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, @@ -7183,246 +6461,7 @@ bool upb_IsTypePackable(upb_FieldType type); #endif /* UPB_MINI_TABLE_H_ */ -#ifndef UPB_REFLECTION_DEF_BUILDER_H_ -#define UPB_REFLECTION_DEF_BUILDER_H_ - - -// Must be last. - -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define UBP_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (google_protobuf_##desc_type##_has_options(proto)) { \ - size_t size; \ - char* pb = google_protobuf_##options_type##_serialize( \ - google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = \ - google_protobuf_##options_type##_parse(pb, size, _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const google_protobuf_##options_type*)kUpbDefOptDefault; \ - } - -#ifdef __cplusplus -extern "C" { -#endif - -struct upb_DefBuilder { - upb_DefPool* symtab; - upb_FileDef* file; // File we are building. - upb_Arena* arena; // Allocate defs here. - upb_Arena* tmp_arena; // For temporary allocations. - upb_Status* status; // Record errors here. - const upb_MiniTable_File* layout; // NULL if we should build layouts. - int enum_count; // Count of enums built so far. - int msg_count; // Count of messages built so far. - int ext_count; // Count of extensions built so far. - jmp_buf err; // longjmp() on error. -}; - -extern const char* kUpbDefOptDefault; - -// ctx->status has already been set elsewhere so just fail/longjmp() -UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx); - -UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, - ...) UPB_PRINTF(2, 3); -UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx); - -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name); - -// Given a symbol and the base symbol inside which it is defined, -// find the symbol's definition. -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type); - -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type); - -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end); - -const char* _upb_DefBuilder_FullToShort(const char* fullname); - -UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) { - if (bytes == 0) return NULL; - void* ret = upb_Arena_Malloc(ctx->arena, bytes); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -// Adds a symbol |v| to the symtab, which must be a def pointer previously -// packed with pack_def(). The def's pointer to upb_FileDef* must be set before -// adding, so we know which entries to remove if building this file fails. -UPB_INLINE void _upb_DefBuilder_Add(upb_DefBuilder* ctx, const char* name, - upb_value v) { - upb_StringView sym = {.data = name, .size = strlen(name)}; - bool ok = _upb_DefPool_InsertSym(ctx->symtab, sym, v, ctx->status); - if (!ok) _upb_DefBuilder_FailJmp(ctx); -} - -UPB_INLINE upb_Arena* _upb_DefBuilder_Arena(const upb_DefBuilder* ctx) { - return ctx->arena; -} - -UPB_INLINE upb_FileDef* _upb_DefBuilder_File(const upb_DefBuilder* ctx) { - return ctx->file; -} - -// This version of CheckIdent() is only called by other, faster versions after -// they detect a parsing error. -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full); - -// Verify a relative identifier string. The loop is branchless for speed. -UPB_INLINE void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); - - good &= is_alpha | is_numer; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); -} - -// Verify a full identifier string. This is slightly more complicated than -// verifying a relative identifier string because we must track '.' chars. -UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - bool start = true; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & !start; - const bool is_dot = (c == '.') & !start; - - good &= is_alpha | is_numer | is_dot; - start = is_dot; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_BUILDER_H_ */ - -#ifndef UPB_REFLECTION_DESC_STATE_H_ -#define UPB_REFLECTION_DESC_STATE_H_ - - -// Must be last. - -// Manages the storage for mini descriptor strings as they are being encoded. -// TODO(b/234740652): Move some of this state directly into the encoder, maybe. -typedef struct { - upb_MtDataEncoder e; - size_t bufsize; - char* buf; - char* ptr; -} upb_DescState; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void _upb_DescState_Init(upb_DescState* d) { - d->bufsize = kUpb_MtDataEncoder_MinSize * 2; - d->buf = NULL; - d->ptr = NULL; -} - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DESC_STATE_H_ */ - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -#ifndef UPB_MAP_SORTER_H_ -#define UPB_MAP_SORTER_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// _upb_mapsorter sorts maps and provides ordered iteration over the entries. -// Since maps can be recursive (map values can be messages which contain other -// maps), _upb_mapsorter can contain a stack of maps. - -typedef struct { - upb_tabent const** entries; - int size; - int cap; -} _upb_mapsorter; - -typedef struct { - int start; - int pos; - int end; -} _upb_sortedmap; - -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { - s->entries = NULL; - s->size = 0; - s->cap = 0; -} - -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { - if (s->entries) free(s->entries); -} - -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, - _upb_sortedmap* sorted, upb_MapEntry* ent) { - if (sorted->pos == sorted->end) return false; - const upb_tabent* tabent = s->entries[sorted->pos++]; - upb_StringView key = upb_tabstrview(tabent->key); - _upb_map_fromkey(key, &ent->k, map->key_size); - upb_value val = {tabent->val.val}; - _upb_map_fromvalue(val, &ent->v, map->val_size); - return true; -} - -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, - _upb_sortedmap* sorted) { - s->size = sorted->start; -} - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MAP_SORTER_H_ */ - +/** upb/port_undef.inc ************************************************************/ /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE @@ -7459,5 +6498,3 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, #undef UPB_UNPOISON_MEMORY_REGION #undef UPB_ASAN #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 -#undef UPB_DEPRECATED -#undef UPB_GNUC_MIN diff --git a/libs/protobuf/php/ext/google/protobuf/protobuf.h b/libs/protobuf/php/ext/google/protobuf/protobuf.h index 14bd16c..efbd45e 100644 --- a/libs/protobuf/php/ext/google/protobuf/protobuf.h +++ b/libs/protobuf/php/ext/google/protobuf/protobuf.h @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.21.8" +#define PHP_PROTOBUF_VERSION "3.21.12" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/libs/protobuf/php/ext/google/protobuf/template_package.xml b/libs/protobuf/php/ext/google/protobuf/template_package.xml new file mode 100644 index 0000000..c6d2619 --- /dev/null +++ b/libs/protobuf/php/ext/google/protobuf/template_package.xml @@ -0,0 +1,42 @@ + + + protobuf + pecl.php.net + Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. + https://developers.google.com/protocol-buffers/ + + Protobuf Team + protobufpackages + protobuf-packages@google.com + yes + + TEMPLATE_DATE + + + TEMPLATE_PHP_RELEASE + TEMPLATE_PHP_API + + + TEMPLATE_PHP_STABILITY + TEMPLATE_PHP_STABILITY + + BSD-3-Clause + + * See github.com/protocolbuffers/protobuf/releases for release notes. + + + TEMPLATE_FILES + + + + + 7.0.0 + + + 1.4.0 + + + + protobuf + + \ No newline at end of file diff --git a/libs/protobuf/php/generate_descriptor_protos.sh b/libs/protobuf/php/generate_descriptor_protos.sh index 0e5be35..9feaa96 100755 --- a/libs/protobuf/php/generate_descriptor_protos.sh +++ b/libs/protobuf/php/generate_descriptor_protos.sh @@ -5,14 +5,6 @@ set -e -if [[ -z "${PROTOC}" ]]; then - PROTOC=$(realpath protoc) -fi -if [ ! -f $PROTOC ]; then - bazel build -c opt //:protoc - PROTOC=$(realpath bazel-bin/protoc) -fi - if test ! -e src/google/protobuf/stubs/common.h; then cat >&2 << __EOF__ Could not find source code. Make sure you are running this script from the @@ -22,8 +14,8 @@ __EOF__ fi pushd src -$PROTOC --php_out=internal:../php/src google/protobuf/descriptor.proto -$PROTOC --php_out=internal_generate_c_wkt:../php/src \ +./protoc --php_out=internal:../php/src google/protobuf/descriptor.proto +./protoc --php_out=internal_generate_c_wkt:../php/src \ google/protobuf/any.proto \ google/protobuf/api.proto \ google/protobuf/duration.proto \ diff --git a/libs/protobuf/php/generate_test_protos.sh b/libs/protobuf/php/generate_test_protos.sh index 6d06f95..8607499 100755 --- a/libs/protobuf/php/generate_test_protos.sh +++ b/libs/protobuf/php/generate_test_protos.sh @@ -2,17 +2,19 @@ set -ex -cd `dirname $0`/.. +cd `dirname $0` -if [[ -z "${PROTOC}" ]]; then - PROTOC=$(pwd)/protoc -fi -if [ ! -f $PROTOC ]; then - bazel build -c opt //:protoc - PROTOC=$(pwd)/bazel-bin/protoc +if ../src/protoc --help > /dev/null; then + PROTOC=src/protoc +else + # Bazel seems to be creating a problematic symlink in + # _build/out/external/com_google_protobuf, so we remove the _build directory + # before building protoc. + (cd .. && bazel build -c opt :protoc) + PROTOC=bazel-bin/protoc fi -if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then +if [[ -d tmp && -z $(find tests/proto ../$PROTOC -newer tmp) ]]; then # Generated protos are already present and up to date, so we can skip protoc. # # Protoc is very fast, but sometimes it is not available (like if we haven't @@ -21,9 +23,10 @@ if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then exit 0 fi -rm -rf php/tmp -mkdir -p php/tmp +rm -rf tmp +mkdir -p tmp +cd .. find php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests if [ "$1" = "--aggregate_metadata" ]; then diff --git a/libs/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/libs/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php index d26f517..d71def9 100644 --- a/libs/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php +++ b/libs/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php @@ -31,7 +31,6 @@ class Descriptor ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FileOptions') ->optional('source_code_info', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.SourceCodeInfo') ->optional('syntax', \Google\Protobuf\Internal\GPBType::STRING, 12) - ->optional('edition', \Google\Protobuf\Internal\GPBType::STRING, 13) ->finalizeToPool(); $pool->addMessage('google.protobuf.internal.DescriptorProto', \Google\Protobuf\Internal\DescriptorProto::class) diff --git a/libs/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php b/libs/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php index ea32e7f..665cb06 100644 --- a/libs/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php +++ b/libs/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php @@ -74,8 +74,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * As of May 2022, lazy verifies the contents of the byte stream during - * parsing. An invalid byte stream will cause the overall parsing to fail. + * As of 2021, lazy does no correctness checks on the byte stream during + * parsing. This may lead to crashes if and when an invalid byte stream is + * finally parsed upon access. + * TODO(b/211906113): Enable validation on lazy fields. * * Generated from protobuf field optional bool lazy = 5 [default = false]; */ @@ -163,8 +165,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * As of May 2022, lazy verifies the contents of the byte stream during - * parsing. An invalid byte stream will cause the overall parsing to fail. + * As of 2021, lazy does no correctness checks on the byte stream during + * parsing. This may lead to crashes if and when an invalid byte stream is + * finally parsed upon access. + * TODO(b/211906113): Enable validation on lazy fields. * @type bool $unverified_lazy * unverified_lazy does no correctness checks on the byte stream. This should * only be used where lazy with verification is prohibitive for performance @@ -350,8 +354,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * As of May 2022, lazy verifies the contents of the byte stream during - * parsing. An invalid byte stream will cause the overall parsing to fail. + * As of 2021, lazy does no correctness checks on the byte stream during + * parsing. This may lead to crashes if and when an invalid byte stream is + * finally parsed upon access. + * TODO(b/211906113): Enable validation on lazy fields. * * Generated from protobuf field optional bool lazy = 5 [default = false]; * @return bool @@ -396,8 +402,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message * implementation must either *always* check its required fields, or *never* * check its required fields, regardless of whether or not the message has * been parsed. - * As of May 2022, lazy verifies the contents of the byte stream during - * parsing. An invalid byte stream will cause the overall parsing to fail. + * As of 2021, lazy does no correctness checks on the byte stream during + * parsing. This may lead to crashes if and when an invalid byte stream is + * finally parsed upon access. + * TODO(b/211906113): Enable validation on lazy fields. * * Generated from protobuf field optional bool lazy = 5 [default = false]; * @param bool $var diff --git a/libs/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/libs/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php index d4c7f6b..5ba7db6 100644 --- a/libs/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php +++ b/libs/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php @@ -81,18 +81,11 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message protected $source_code_info = null; /** * The syntax of the proto file. - * The supported values are "proto2", "proto3", and "editions". - * If `edition` is present, this value must be "editions". + * The supported values are "proto2" and "proto3". * * Generated from protobuf field optional string syntax = 12; */ protected $syntax = null; - /** - * The edition of the proto file, which is an opaque string. - * - * Generated from protobuf field optional string edition = 13; - */ - protected $edition = null; /** * Constructor. @@ -124,10 +117,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message * development tools. * @type string $syntax * The syntax of the proto file. - * The supported values are "proto2", "proto3", and "editions". - * If `edition` is present, this value must be "editions". - * @type string $edition - * The edition of the proto file, which is an opaque string. + * The supported values are "proto2" and "proto3". * } */ public function __construct($data = NULL) { @@ -455,8 +445,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message /** * The syntax of the proto file. - * The supported values are "proto2", "proto3", and "editions". - * If `edition` is present, this value must be "editions". + * The supported values are "proto2" and "proto3". * * Generated from protobuf field optional string syntax = 12; * @return string @@ -478,8 +467,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message /** * The syntax of the proto file. - * The supported values are "proto2", "proto3", and "editions". - * If `edition` is present, this value must be "editions". + * The supported values are "proto2" and "proto3". * * Generated from protobuf field optional string syntax = 12; * @param string $var @@ -493,41 +481,5 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message return $this; } - /** - * The edition of the proto file, which is an opaque string. - * - * Generated from protobuf field optional string edition = 13; - * @return string - */ - public function getEdition() - { - return isset($this->edition) ? $this->edition : ''; - } - - public function hasEdition() - { - return isset($this->edition); - } - - public function clearEdition() - { - unset($this->edition); - } - - /** - * The edition of the proto file, which is an opaque string. - * - * Generated from protobuf field optional string edition = 13; - * @param string $var - * @return $this - */ - public function setEdition($var) - { - GPBUtil::checkString($var, True); - $this->edition = $var; - - return $this; - } - } diff --git a/libs/protobuf/php/src/Google/Protobuf/Internal/Message.php b/libs/protobuf/php/src/Google/Protobuf/Internal/Message.php index f412b41..1d1fbf2 100644 --- a/libs/protobuf/php/src/Google/Protobuf/Internal/Message.php +++ b/libs/protobuf/php/src/Google/Protobuf/Internal/Message.php @@ -54,7 +54,6 @@ use Google\Protobuf\NullValue; * or extend this class or its child classes by their own. See the comment of * specific functions for more details. */ -#[\AllowDynamicProperties] class Message { @@ -1981,12 +1980,8 @@ class Message $size += 9; $size += $value_msg->jsonByteSize(); } else { - $value_size = $value_msg->jsonByteSize(); - // size === 2 it's empty message {} which is not serialized inside any - if ($value_size !== 2) { - // Size for value. +1 for comma, -2 for "{}". - $size += $value_size -1; - } + // Size for value. +1 for comma, -2 for "{}". + $size += $value_msg->jsonByteSize() -1; } } elseif (get_class($this) === 'Google\Protobuf\FieldMask') { $field_mask = GPBUtil::formatFieldMask($this); diff --git a/libs/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php b/libs/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php index 96e6f52..5c61580 100644 --- a/libs/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php +++ b/libs/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php @@ -53,9 +53,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message */ protected $deprecated = null; /** - * NOTE: Do not set the option in .proto files. Always use the maps syntax - * instead. The option should only be implicitly set by the proto compiler - * parser. * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: @@ -71,6 +68,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * use a native map in the target language to hold the keys and values. * The reflection APIs in such implementations still need to work as * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. * * Generated from protobuf field optional bool map_entry = 7; */ @@ -114,9 +114,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * for the message, or it will be completely ignored; in the very least, * this is a formalization for deprecating messages. * @type bool $map_entry - * NOTE: Do not set the option in .proto files. Always use the maps syntax - * instead. The option should only be implicitly set by the proto compiler - * parser. * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: @@ -132,6 +129,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * use a native map in the target language to hold the keys and values. * The reflection APIs in such implementations still need to work as * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. * @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option * The parser stores options it doesn't recognize here. See above. * } @@ -288,9 +288,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * NOTE: Do not set the option in .proto files. Always use the maps syntax - * instead. The option should only be implicitly set by the proto compiler - * parser. * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: @@ -306,6 +303,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * use a native map in the target language to hold the keys and values. * The reflection APIs in such implementations still need to work as * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. * * Generated from protobuf field optional bool map_entry = 7; * @return bool @@ -326,9 +326,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message } /** - * NOTE: Do not set the option in .proto files. Always use the maps syntax - * instead. The option should only be implicitly set by the proto compiler - * parser. * Whether the message is an automatically generated map entry type for the * maps field. * For maps fields: @@ -344,6 +341,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message * use a native map in the target language to hold the keys and values. * The reflection APIs in such implementations still need to work as * if the field is a repeated message field. + * NOTE: Do not set the option in .proto files. Always use the maps syntax + * instead. The option should only be implicitly set by the proto compiler + * parser. * * Generated from protobuf field optional bool map_entry = 7; * @param bool $var diff --git a/libs/protobuf/php/tests/EncodeDecodeTest.php b/libs/protobuf/php/tests/EncodeDecodeTest.php index 70748e1..33d8da1 100644 --- a/libs/protobuf/php/tests/EncodeDecodeTest.php +++ b/libs/protobuf/php/tests/EncodeDecodeTest.php @@ -5,7 +5,6 @@ require_once('test_util.php'); use Google\Protobuf\RepeatedField; use Google\Protobuf\GPBType; -use Foo\EmptyAnySerialization; use Foo\TestInt32Value; use Foo\TestInt64Value; use Foo\TestUInt32Value; @@ -1514,22 +1513,4 @@ class EncodeDecodeTest extends TestBase [TestStringValue::class, "a", "\"a\"", "", "\"\""], ]; } - - public function testEmptyAnySerialization() - { - $m = new EmptyAnySerialization(); - - $any = new Any(); - $any->pack($m); - - $data = $any->serializeToJsonString(); - $this->assertEquals('{"@type":"type.googleapis.com/foo.EmptyAnySerialization"}', $data); - - $any = new Any(); - $any->mergeFromJsonString($data); - - $m = $any->unpack(); - $this->assertInstanceOf(EmptyAnySerialization::class, $m); - $this->assertEquals('', $m->getA()); - } } diff --git a/libs/protobuf/php/tests/PhpImplementationTest.php b/libs/protobuf/php/tests/PhpImplementationTest.php index 38c628d..7187315 100644 --- a/libs/protobuf/php/tests/PhpImplementationTest.php +++ b/libs/protobuf/php/tests/PhpImplementationTest.php @@ -275,13 +275,13 @@ class PhpImplementationTest extends TestBase $this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode64(0x3FFFFFFF)); $this->assertSame( 0x7FFFFFFF, - GPBWire::zigZagEncode64(-1073741824)); // 0xFFFFFFFFC0000000 + GPBWire::zigZagEncode64(0xFFFFFFFFC0000000)); $this->assertSame( 0xFFFFFFFE, GPBWire::zigZagEncode64(0x7FFFFFFF)); $this->assertSame( 0xFFFFFFFF, - GPBWire::zigZagEncode64(-2147483648)); // 0xFFFFFFFF80000000 + GPBWire::zigZagEncode64(0xFFFFFFFF80000000)); $this->assertSame( -2, // 0xFFFFFFFFFFFFFFFE GPBWire::zigZagEncode64(0x7FFFFFFFFFFFFFFF)); diff --git a/libs/protobuf/php/tests/compatibility_test.sh b/libs/protobuf/php/tests/compatibility_test.sh new file mode 100755 index 0000000..7e44cce --- /dev/null +++ b/libs/protobuf/php/tests/compatibility_test.sh @@ -0,0 +1,152 @@ +#!/bin/bash + +function generate_proto() { + PROTOC1=$1 + PROTOC2=$2 + + rm -rf generated + mkdir generated + + $PROTOC1 --php_out=generated proto/test_include.proto + $PROTOC2 --php_out=generated \ + -I../../src -I. \ + proto/empty/echo.proto \ + proto/test.proto \ + proto/test_no_namespace.proto \ + proto/test_prefix.proto \ + proto/test_php_namespace.proto \ + proto/test_empty_php_namespace.proto \ + proto/test_reserved_enum_lower.proto \ + proto/test_reserved_enum_upper.proto \ + proto/test_reserved_enum_value_lower.proto \ + proto/test_reserved_enum_value_upper.proto \ + proto/test_reserved_message_lower.proto \ + proto/test_reserved_message_upper.proto \ + proto/test_service.proto \ + proto/test_service_namespace.proto \ + proto/test_wrapper_type_setters.proto \ + proto/test_descriptors.proto + + pushd ../../src + $PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto + popd +} + +# Remove tests to expect error. These were added to API tests by mistake. +function remove_error_test() { + local TEMPFILE=`tempfile` + cat $1 | \ + awk -v file=`basename $1` -v dir=`basename $(dirname $1)` ' + BEGIN { + show = 1 + } + /@expectedException PHPUnit_Framework_Error/ { show = 0; next; } + / *\*\// { print; next; } + / *}/ { + if (!show) { + show = 1; + next; + } + } + show { print } + ' > $TEMPFILE + cp $TEMPFILE $1 +} + +set -ex + +# Change to the script's directory. +cd $(dirname $0) + +OLD_VERSION=$1 +OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe + +# Extract the latest protobuf version number. +VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"` + +echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION" + +# Check protoc +[ -f ../../src/protoc ] || { + echo "[ERROR]: Please build protoc first." + exit 1 +} + +# Download old test. +rm -rf protobuf +git clone https://github.com/protocolbuffers/protobuf.git +pushd protobuf +git checkout v$OLD_VERSION +popd + +# Build and copy the new runtime +pushd ../ext/google/protobuf +make clean || true +phpize && ./configure && make +popd + +rm -rf protobuf/php/ext +rm -rf protobuf/php/src +cp -r ../ext protobuf/php/ext/ +cp -r ../src protobuf/php/src/ + +# Download old version protoc compiler (for linux) +wget $OLD_VERSION_PROTOC -O old_protoc +chmod +x old_protoc + +NEW_PROTOC=`pwd`/../../src/protoc +OLD_PROTOC=`pwd`/old_protoc +cd protobuf/php +composer install + +# Remove implementation detail tests. +# TODO(teboring): Temporarily disable encode_decode_test.php. In 3.13.0-rc1, +# repeated primitive field encoding is changed to packed, which is a bug fix. +# However, this fails the compatibility test which hard coded old encoding. +# Will re-enable the test after making a release. After the version bump, the +# compatibility test will use the updated test code. +tests=( array_test.php generated_class_test.php map_field_test.php well_known_test.php ) +sed -i.bak '/php_implementation_test.php/d' phpunit.xml +sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml +sed -i.bak '/encode_decode_test.php/d' phpunit.xml +sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh +sed -i.bak 's/generated_service_test.php//g' tests/test.sh +sed -i.bak 's/encode_decode_test.php//g' tests/test.sh +sed -i.bak '/memory_leak_test.php/d' tests/test.sh +sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php +sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php +for t in "${tests[@]}" +do + remove_error_test tests/$t +done + +cd tests + +# Test A.1: +# proto set 1: use old version +# proto set 2 which may import protos in set 1: use old version +generate_proto $OLD_PROTOC $OLD_PROTOC +./test.sh +pushd .. +./vendor/bin/phpunit +popd + +# Test A.2: +# proto set 1: use new version +# proto set 2 which may import protos in set 1: use old version +generate_proto $NEW_PROTOC $OLD_PROTOC +./test.sh +pushd .. +./vendor/bin/phpunit +popd + +# Test A.3: +# proto set 1: use old version +# proto set 2 which may import protos in set 1: use new version +generate_proto $OLD_PROTOC $NEW_PROTOC +./test.sh +pushd .. +./vendor/bin/phpunit +popd diff --git a/libs/protobuf/php/tests/compile_extension.sh b/libs/protobuf/php/tests/compile_extension.sh index a645ed6..3261917 100755 --- a/libs/protobuf/php/tests/compile_extension.sh +++ b/libs/protobuf/php/tests/compile_extension.sh @@ -1,18 +1,15 @@ #!/bin/bash -set -ex +set -e cd $(dirname $0)/.. -# Pull in dependencies. -git submodule update --init --recursive - # utf8_range has to live in the base third_party directory. # We copy it into the ext/google/protobuf directory for the build # (and for the release to PECL). rm -rf ext/google/protobuf/third_party mkdir -p ext/google/protobuf/third_party/utf8_range -cp -r ../third_party/utf8_range/* ext/google/protobuf/third_party/utf8_range +cp ../third_party/utf8_range/* ext/google/protobuf/third_party/utf8_range echo "Copied utf8_range from ../third_party -> ext/google/protobuf/third_party" diff --git a/libs/protobuf/php/tests/proto/test.proto b/libs/protobuf/php/tests/proto/test.proto index 4217800..421292a 100644 --- a/libs/protobuf/php/tests/proto/test.proto +++ b/libs/protobuf/php/tests/proto/test.proto @@ -168,10 +168,6 @@ message ARRAY { int32 a = 1; } -message EmptyAnySerialization { - string a = 1; -} - message TestPackedMessage { repeated int32 repeated_int32 = 90 [packed = true]; repeated int64 repeated_int64 = 91 [packed = true]; diff --git a/libs/protobuf/pkg/BUILD.bazel b/libs/protobuf/pkg/BUILD.bazel index b1784f6..ecce255 100644 --- a/libs/protobuf/pkg/BUILD.bazel +++ b/libs/protobuf/pkg/BUILD.bazel @@ -7,7 +7,7 @@ load( "strip_prefix", ) load("//:protobuf_release.bzl", "package_naming") -load(":build_systems.bzl", "gen_file_lists") +load(":build_systems.bzl", "gen_automake_file_lists", "gen_file_lists") load(":cc_dist_library.bzl", "cc_dist_library") package_naming( @@ -17,8 +17,17 @@ package_naming( pkg_files( name = "wkt_protos_files", srcs = [ - "//:well_known_type_protos", - "//src/google/protobuf:descriptor_proto_srcs", + "//:src/google/protobuf/any.proto", + "//:src/google/protobuf/api.proto", + "//:src/google/protobuf/descriptor.proto", + "//:src/google/protobuf/duration.proto", + "//:src/google/protobuf/empty.proto", + "//:src/google/protobuf/field_mask.proto", + "//:src/google/protobuf/source_context.proto", + "//:src/google/protobuf/struct.proto", + "//:src/google/protobuf/timestamp.proto", + "//:src/google/protobuf/type.proto", + "//:src/google/protobuf/wrappers.proto", ], prefix = "include/google/protobuf", visibility = ["//visibility:private"], @@ -26,9 +35,7 @@ pkg_files( pkg_files( name = "compiler_plugin_protos_files", - srcs = [ - "//src/google/protobuf/compiler:compiler_plugin_protos_files", - ], + srcs = ["//:src/google/protobuf/compiler/plugin.proto"], prefix = "include/google/protobuf/compiler", visibility = ["//visibility:private"], ) @@ -88,10 +95,10 @@ pkg_filegroup( srcs = [ ":dist_files", "//:common_dist_files", + "//:cpp_dist_files", # to build protoc + "//benchmarks:all_dist_files", "//build_defs:dist_files", "//conformance:all_dist_files", - "//src:all_dist_files", - "//third_party/utf8_range:dist_files", "@com_google_protobuf_examples//:dist_files", ], ) @@ -100,7 +107,7 @@ pkg_filegroup( name = "cpp_srcs", srcs = [ ":dist_common", - "//src:all_dist_files", + "//:cpp_dist_files", ], ) @@ -222,7 +229,7 @@ pkg_filegroup( name = "python_srcs", srcs = [ ":dist_common", - "//python:dist_files", + "//:python_dist_files", ], ) @@ -304,31 +311,30 @@ gen_file_lists( testonly = 1, out_stem = "src_file_lists", src_libs = { - # {[source rule]: [name in generated file]} - # Libraries: - ":protobuf": "libprotobuf", - ":protobuf_lite": "libprotobuf_lite", - ":protoc": "libprotoc", - # Protos: - "//src/google/protobuf:well_known_type_protos": "wkt_protos", - "//src/google/protobuf:descriptor_proto": "descriptor_proto", - "//src/google/protobuf/compiler:plugin_proto": "plugin_proto", - # Test libraries: - ":common_test": "common_test", - ":lite_test_util": "lite_test_util", - ":test_util": "test_util", - # Tests and test-only protos: - "//src/google/protobuf:full_test_srcs": "protobuf_test", - "//src/google/protobuf:test_proto_srcs": "protobuf_test_protos", - "//src/google/protobuf:lite_test_srcs": "protobuf_lite_test", - "//src/google/protobuf:lite_test_proto_srcs": "protobuf_lite_test_protos", - "//src/google/protobuf/compiler:test_srcs": "compiler_test", - "//src/google/protobuf/compiler:test_proto_srcs": "compiler_test_protos", - "//src/google/protobuf/compiler:test_plugin_srcs": "test_plugin", - "//src/google/protobuf/io:test_srcs": "io_test", - "//src/google/protobuf/util:test_srcs": "util_test", - "//src/google/protobuf/util:test_proto_srcs": "util_test_protos", - "//src/google/protobuf/stubs:test_srcs": "stubs_test", + # source rule: name in generated file + "//:protobuf": "libprotobuf", + "//:protoc_lib": "libprotoc", + "//:protobuf_lite": "libprotobuf_lite", + }, +) + +gen_automake_file_lists( + name = "gen_automake_extra_dist_lists", + testonly = 1, + out = "extra_dist_file_lists.am", + src_libs = { + # source rule: name in generated file + "//:common_dist_files": "dist_common", + "//conformance:dist_files": "dist_conformance", + "//benchmarks:all_dist_files": "dist_benchmark", + "@com_google_protobuf_examples//:dist_files": "dist_example", + "//:csharp_dist_files": "dist_csharp", + "//csharp:dist_files": "dist_csharp2", + "//:objectivec_dist_files": "dist_objectivec", + "//objectivec:dist_files": "dist_objectivec2", + "//php:dist_files": "dist_php", + "//:python_dist_files": "dist_python", + "//ruby:dist_files": "dist_ruby", }, ) @@ -342,17 +348,8 @@ cc_dist_library( "//build_defs:config_msvc": [], "//conditions:default": ["-lpthread"], }), - tags = ["manual"], deps = [ - "//src/google/protobuf:arena", - "//src/google/protobuf:arena_align", - "//src/google/protobuf:arena_allocation_policy", - "//src/google/protobuf:arena_cleanup", - "//src/google/protobuf:arena_config", - "//src/google/protobuf:protobuf_lite", - "//src/google/protobuf/io", - "//src/google/protobuf/io:io_win32", - "//src/google/protobuf/stubs:lite", + "//:protobuf_lite", ], ) @@ -365,99 +362,12 @@ cc_dist_library( "-lpthread", ], }), - tags = ["manual"], deps = [ - "//src/google/protobuf:wkt_cc_proto", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf:arena", - "//src/google/protobuf:arena_align", - "//src/google/protobuf:arena_allocation_policy", - "//src/google/protobuf:arena_cleanup", - "//src/google/protobuf:arena_config", - "//src/google/protobuf:protobuf_lite", - "//src/google/protobuf:port_def", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/io", - "//src/google/protobuf/io:gzip_stream", - "//src/google/protobuf/io:io_win32", - "//src/google/protobuf/io:printer", - "//src/google/protobuf/io:tokenizer", - "//src/google/protobuf/io:zero_copy_sink", - "//src/google/protobuf/json", - "//src/google/protobuf/json:descriptor_traits", - "//src/google/protobuf/json:lexer", - "//src/google/protobuf/json:message_path", - "//src/google/protobuf/json:parser", - "//src/google/protobuf/json:unparser", - "//src/google/protobuf/json:untyped_message", - "//src/google/protobuf/json:writer", - "//src/google/protobuf/json:zero_copy_buffered_stream", - "//src/google/protobuf/stubs", - "//src/google/protobuf/stubs:lite", - "//src/google/protobuf/util:delimited_message_util", - "//src/google/protobuf/util:differencer", - "//src/google/protobuf/util:field_mask_util", - "//src/google/protobuf/util:json_util", - "//src/google/protobuf/util:time_util", - "//src/google/protobuf/util:type_resolver_util", + "//:protobuf", + "//:protobuf_lite", ], ) -cc_dist_library( - name = "protoc", - tags = ["manual"], - deps = [ - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/compiler/cpp", - "//src/google/protobuf/compiler/cpp:names", - "//src/google/protobuf/compiler/cpp:names_internal", - "//src/google/protobuf/compiler/csharp", - "//src/google/protobuf/compiler/csharp:names", - "//src/google/protobuf/compiler/java", - "//src/google/protobuf/compiler/java:names", - "//src/google/protobuf/compiler/java:names_internal", - "//src/google/protobuf/compiler/objectivec", - "//src/google/protobuf/compiler/objectivec:line_consumer", - "//src/google/protobuf/compiler/objectivec:names", - "//src/google/protobuf/compiler/objectivec:names_internal", - "//src/google/protobuf/compiler/php", - "//src/google/protobuf/compiler/php:names", - "//src/google/protobuf/compiler/python", - "//src/google/protobuf/compiler/ruby", - ], -) - -cc_dist_library( - name = "lite_test_util", - testonly = 1, - tags = ["manual"], - deps = ["//src/google/protobuf:lite_test_util"], -) - -cc_dist_library( - name = "test_util", - testonly = 1, - tags = ["manual"], - deps = [ - "//src/google/protobuf:test_util", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/compiler:annotation_test_util", - "//src/google/protobuf/compiler/cpp:unittest_lib", - ], -) - -cc_dist_library( - name = "common_test", - testonly = 1, - tags = ["manual"], - deps = [ - "//src/google/protobuf/testing", - "//src/google/protobuf/compiler:mock_code_generator", - ], -) - - ################################################################################ # Distribution sources ################################################################################ diff --git a/libs/protobuf/pkg/build_systems.bzl b/libs/protobuf/pkg/build_systems.bzl index ce6d429..753d285 100644 --- a/libs/protobuf/pkg/build_systems.bzl +++ b/libs/protobuf/pkg/build_systems.bzl @@ -1,7 +1,6 @@ # Starlark utilities for working with other build systems load("@rules_pkg//:providers.bzl", "PackageFilegroupInfo", "PackageFilesInfo") -load(":cc_dist_library.bzl", "CcFileList") ################################################################################ # Macro to create CMake and Automake source lists. @@ -14,18 +13,39 @@ def gen_file_lists(name, out_stem, **kwargs): source_prefix = "${protobuf_SOURCE_DIR}/", **kwargs ) + gen_automake_file_lists( + name = name + "_automake", + out = out_stem + ".am", + source_prefix = "$(top_srcdir)/", + **kwargs + ) native.filegroup( name = name, srcs = [ out_stem + ".cmake", + out_stem + ".am", ], - visibility = ["//src:__pkg__"], ) ################################################################################ # Aspect that extracts srcs, hdrs, etc. ################################################################################ +CcFileList = provider( + doc = "List of files to be built into a library.", + fields = { + # As a rule of thumb, `hdrs` and `textual_hdrs` are the files that + # would be installed along with a prebuilt library. + "hdrs": "public header files, including those used by generated code", + "textual_hdrs": "files which are included but are not self-contained", + + # The `internal_hdrs` are header files which appear in `srcs`. + # These are only used when compiling the library. + "internal_hdrs": "internal header files (only used to build .cc files)", + "srcs": "source files", + }, +) + ProtoFileList = provider( doc = "List of proto files and generated code to be built into a library.", fields = { @@ -45,11 +65,56 @@ def _flatten_target_files(targets): files.append(tfile) return files +def _combine_cc_file_lists(file_lists): + hdrs = {} + textual_hdrs = {} + internal_hdrs = {} + srcs = {} + for file_list in file_lists: + hdrs.update({f: 1 for f in file_list.hdrs}) + textual_hdrs.update({f: 1 for f in file_list.textual_hdrs}) + internal_hdrs.update({f: 1 for f in file_list.internal_hdrs}) + srcs.update({f: 1 for f in file_list.srcs}) + return CcFileList( + hdrs = sorted(hdrs.keys()), + textual_hdrs = sorted(textual_hdrs.keys()), + internal_hdrs = sorted(internal_hdrs.keys()), + srcs = sorted(srcs.keys()), + ) + def _file_list_aspect_impl(target, ctx): # We're going to reach directly into the attrs on the traversed rule. rule_attr = ctx.rule.attr providers = [] + # Extract sources from a `cc_library` (or similar): + if CcInfo in target: + # CcInfo is a proxy for what we expect this rule to look like. + # However, some deps may expose `CcInfo` without having `srcs`, + # `hdrs`, etc., so we use `getattr` to handle that gracefully. + + internal_hdrs = [] + srcs = [] + + # Filter `srcs` so it only contains source files. Headers will go + # into `internal_headers`. + for src in _flatten_target_files(getattr(rule_attr, "srcs", [])): + if src.extension.lower() in ["c", "cc", "cpp", "cxx"]: + srcs.append(src) + else: + internal_hdrs.append(src) + + providers.append(CcFileList( + hdrs = _flatten_target_files(getattr(rule_attr, "hdrs", [])), + textual_hdrs = _flatten_target_files(getattr( + rule_attr, + "textual_hdrs", + [], + )), + internal_hdrs = internal_hdrs, + srcs = srcs, + )) + # Extract sources from a `proto_library`: if ProtoInfo in target: proto_srcs = [] @@ -113,7 +178,7 @@ Output is CcFileList and/or ProtoFileList. Example: # fragment generator function. ################################################################################ -def _create_file_list_impl(ctx, fragment_generator): +def _create_file_list_impl(fragment_generator): # `fragment_generator` is a function like: # def fn(originating_rule: Label, # varname: str, @@ -126,98 +191,92 @@ def _create_file_list_impl(ctx, fragment_generator): # When dealing with `File` objects, the `short_path` is used to strip # the output prefix for generated files. - out = ctx.outputs.out + def _impl(ctx): + out = ctx.outputs.out - fragments = [] - for srcrule, libname in ctx.attr.src_libs.items(): - if CcFileList in srcrule: - cc_file_list = srcrule[CcFileList] + fragments = [] + for srcrule, libname in ctx.attr.src_libs.items(): + if CcFileList in srcrule: + cc_file_list = srcrule[CcFileList] + fragments.extend([ + fragment_generator( + srcrule.label, + libname + "_srcs", + ctx.attr.source_prefix, + [f.short_path for f in cc_file_list.srcs], + ), + fragment_generator( + srcrule.label, + libname + "_hdrs", + ctx.attr.source_prefix, + [f.short_path for f in (cc_file_list.hdrs + + cc_file_list.textual_hdrs)], + ), + ]) - # Turn depsets of files into sorted lists. - srcs = sorted(cc_file_list.srcs.to_list()) - hdrs = sorted( - depset(transitive = [ - cc_file_list.textual_hdrs, - cc_file_list.hdrs, - ]).to_list(), - ) + if ProtoFileList in srcrule: + proto_file_list = srcrule[ProtoFileList] + fragments.extend([ + fragment_generator( + srcrule.label, + libname + "_proto_srcs", + ctx.attr.source_prefix, + [f.short_path for f in proto_file_list.proto_srcs], + ), + fragment_generator( + srcrule.label, + libname + "_srcs", + ctx.attr.source_prefix, + proto_file_list.srcs, + ), + fragment_generator( + srcrule.label, + libname + "_hdrs", + ctx.attr.source_prefix, + proto_file_list.hdrs, + ), + ]) - fragments.extend([ - fragment_generator( - srcrule.label, - libname + "_srcs", - ctx.attr.source_prefix, - [f.short_path for f in srcs], - ), - fragment_generator( - srcrule.label, - libname + "_hdrs", - ctx.attr.source_prefix, - [f.short_path for f in hdrs], - ), - ]) + files = {} - if ProtoFileList in srcrule: - proto_file_list = srcrule[ProtoFileList] - fragments.extend([ - fragment_generator( - srcrule.label, - libname + "_proto_srcs", - ctx.attr.source_prefix, - [f.short_path for f in proto_file_list.proto_srcs], - ), - fragment_generator( - srcrule.label, - libname + "_srcs", - ctx.attr.source_prefix, - proto_file_list.srcs, - ), - fragment_generator( - srcrule.label, - libname + "_hdrs", - ctx.attr.source_prefix, - proto_file_list.hdrs, - ), - ]) + if PackageFilegroupInfo in srcrule: + for pkg_files_info, origin in srcrule[PackageFilegroupInfo].pkg_files: + # keys are the destination path: + files.update(pkg_files_info.dest_src_map) - files = {} + if PackageFilesInfo in srcrule: + # keys are the destination: + files.update(srcrule[PackageFilesInfo].dest_src_map) - if PackageFilegroupInfo in srcrule: - for pkg_files_info, origin in srcrule[PackageFilegroupInfo].pkg_files: - # keys are the destination path: - files.update(pkg_files_info.dest_src_map) + if files == {} and DefaultInfo in srcrule and CcInfo not in srcrule: + # This could be an individual file or filegroup. + # We explicitly ignore rules with CcInfo, since their + # output artifacts are libraries or binaries. + files.update( + { + f.short_path: 1 + for f in srcrule[DefaultInfo].files.to_list() + }, + ) - if PackageFilesInfo in srcrule: - # keys are the destination: - files.update(srcrule[PackageFilesInfo].dest_src_map) + if files: + fragments.append( + fragment_generator( + srcrule.label, + libname + "_files", + ctx.attr.source_prefix, + sorted(files.keys()), + ), + ) - if files == {} and DefaultInfo in srcrule and CcFileList not in srcrule: - # This could be an individual file or filegroup. - # We explicitly ignore rules with CcInfo, since their - # output artifacts are libraries or binaries. - files.update( - { - f.short_path: 1 - for f in srcrule[DefaultInfo].files.to_list() - }, - ) + ctx.actions.write( + output = out, + content = (ctx.attr._header % ctx.label) + "\n".join(fragments), + ) - if files: - fragments.append( - fragment_generator( - srcrule.label, - libname + "_files", - ctx.attr.source_prefix, - sorted(files.keys()), - ), - ) + return [DefaultInfo(files = depset([out]))] - ctx.actions.write( - output = out, - content = (ctx.attr._header % ctx.label) + "\n".join(fragments), - ) - - return [DefaultInfo(files = depset([out]))] + return _impl # Common rule attrs for rules that use `_create_file_list_impl`: # (note that `_header` is also required) @@ -284,9 +343,6 @@ def _cmake_var_fragment(owner, varname, prefix, entries): entries = "\n".join([" %s%s" % (prefix, f) for f in entries]), ) -def _cmake_file_list_impl(ctx): - _create_file_list_impl(ctx, _cmake_var_fragment) - gen_cmake_file_lists = rule( doc = """ Generates a CMake-syntax file with lists of files. @@ -305,7 +361,7 @@ For proto_library, the following are generated: {libname}_hdrs: contains syntesized paths for generated C++ headers. """, - implementation = _cmake_file_list_impl, + implementation = _create_file_list_impl(_cmake_var_fragment), attrs = dict( _source_list_common_attrs, _header = attr.string( @@ -325,3 +381,72 @@ endif() ), ), ) + +################################################################################ +# Automake source lists generation +################################################################################ + +def _automake_var_fragment(owner, varname, prefix, entries): + """Returns a single variable assignment fragment (Automake syntax). + + Args: + owner: Label, the rule that owns these srcs. + varname: str, the var name to set. + prefix: str, prefix to prepend to each of `entries`. + entries: [str], the entries in the list. + + Returns: + A string. + """ + if len(entries) == 0: + # A backslash followed by a blank line is illegal. We still want + # to emit the variable, though. + return "# {owner}\n{varname} =\n".format( + owner = owner, + varname = varname, + ) + fragment = ( + "# {owner}\n" + + "{varname} = \\\n" + + "{entries}" + ).format( + owner = owner, + varname = varname, + entries = " \\\n".join([" %s%s" % (prefix, f) for f in entries]), + ) + return fragment.rstrip("\\ ") + "\n" + +gen_automake_file_lists = rule( + doc = """ +Generates an Automake-syntax file with lists of files. + +The generated file defines variables with lists of files from `srcs`. The +intent is for these files to be included from a non-generated Makefile.am +file which actually defines the libraries based on these lists. + +For C++ rules, the following are generated: + {libname}_srcs: contains srcs. + {libname}_hdrs: contains hdrs and textual_hdrs. + +For proto_library, the following are generated: + {libname}_proto_srcs: contains the srcs from the `proto_library` rule. + {libname}_srcs: contains syntesized paths for generated C++ sources. + {libname}_hdrs: contains syntesized paths for generated C++ headers. + +""", + implementation = _create_file_list_impl(_automake_var_fragment), + attrs = dict( + _source_list_common_attrs.items(), + _header = attr.string( + default = """\ +# Auto-generated by %s +# +# This file contains lists of sources based on Bazel rules. It should +# be included from a hand-written Makefile.am that defines targets. +# +# Changes to this file will be overwritten based on Bazel definitions. + +""", + ), + ), +) diff --git a/libs/protobuf/pkg/cc_dist_library.bzl b/libs/protobuf/pkg/cc_dist_library.bzl index 383979e..654fb73 100644 --- a/libs/protobuf/pkg/cc_dist_library.bzl +++ b/libs/protobuf/pkg/cc_dist_library.bzl @@ -3,32 +3,12 @@ load("@rules_cc//cc:action_names.bzl", cc_action_names = "ACTION_NAMES") load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain") -################################################################################ -# Archive/linking support -################################################################################ - -def _collect_linker_input_objects(dep_label, cc_info, objs, pic_objs): - """Accumulate .o and .pic.o files into `objs` and `pic_objs`.""" - link_ctx = cc_info.linking_context - if link_ctx == None: - return - - linker_inputs = link_ctx.linker_inputs.to_list() - for link_input in linker_inputs: - if link_input.owner != dep_label: - # This is a transitive dep: skip it. - continue - - for lib in link_input.libraries: - objs.extend(lib.objects or []) - pic_objs.extend(lib.pic_objects or []) - # Creates an action to build the `output_file` static library (archive) # using `object_files`. def _create_archive_action( ctx, feature_configuration, - cc_toolchain_info, + cc_toolchain, output_file, object_files): # Based on Bazel's src/main/starlark/builtins_bzl/common/cc/cc_import.bzl: @@ -36,7 +16,7 @@ def _create_archive_action( # Build the command line and add args for all of the input files: archiver_variables = cc_common.create_link_variables( feature_configuration = feature_configuration, - cc_toolchain = cc_toolchain_info, + cc_toolchain = cc_toolchain, output_file = output_file.path, is_using_linker = False, ) @@ -68,23 +48,80 @@ def _create_archive_action( inputs = depset( direct = object_files, transitive = [ - cc_toolchain_info.all_files, + cc_toolchain.all_files, ], ), - use_default_shell_env = False, + use_default_shell_env = True, outputs = [output_file], mnemonic = "CppArchiveDist", ) -def _create_dso_link_action( - ctx, - feature_configuration, - cc_toolchain_info, - object_files, - pic_object_files): +# Implementation for cc_dist_library rule. +def _cc_dist_library_impl(ctx): + cc_toolchain_info = find_cc_toolchain(ctx) + if cc_toolchain_info.ar_executable == None: + return [] + + feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain_info, + ) + + # Collect the set of object files from the immediate deps. + + objs = [] + pic_objs = [] + for dep in ctx.attr.deps: + if CcInfo not in dep: + continue + + link_ctx = dep[CcInfo].linking_context + if link_ctx == None: + continue + + linker_inputs = link_ctx.linker_inputs.to_list() + for link_input in linker_inputs: + if link_input.owner != dep.label: + # This is a transitive dep: skip it. + continue + + for lib in link_input.libraries: + objs.extend(lib.objects or []) + pic_objs.extend(lib.pic_objects or []) + + # For static libraries, build separately with and without pic. + + stemname = "lib" + ctx.label.name + outputs = [] + + if len(objs) > 0: + archive_out = ctx.actions.declare_file(stemname + ".a") + _create_archive_action( + ctx, + feature_configuration, + cc_toolchain_info, + archive_out, + objs, + ) + outputs.append(archive_out) + + if len(pic_objs) > 0: + pic_archive_out = ctx.actions.declare_file(stemname + ".pic.a") + _create_archive_action( + ctx, + feature_configuration, + cc_toolchain_info, + pic_archive_out, + pic_objs, + ) + outputs.append(pic_archive_out) + + # For dynamic libraries, use the `cc_common.link` command to ensure + # everything gets built correctly according to toolchain definitions. + compilation_outputs = cc_common.create_compilation_outputs( - objects = depset(object_files), - pic_objects = depset(pic_object_files), + objects = depset(objs), + pic_objects = depset(pic_objs), ) link_output = cc_common.link( actions = ctx.actions, @@ -97,8 +134,6 @@ def _create_dso_link_action( ) library_to_link = link_output.library_to_link - outputs = [] - # Note: library_to_link.dynamic_library and interface_library are often # symlinks in the solib directory. For DefaultInfo, prefer reporting # the resolved artifact paths. @@ -112,207 +147,6 @@ def _create_dso_link_action( elif library_to_link.interface_library != None: outputs.append(library_to_link.interface_library) - return outputs - -################################################################################ -# Source file/header support -################################################################################ - -CcFileList = provider( - doc = "List of files to be built into a library.", - fields = { - # As a rule of thumb, `hdrs` and `textual_hdrs` are the files that - # would be installed along with a prebuilt library. - "hdrs": "public header files, including those used by generated code", - "textual_hdrs": "files which are included but are not self-contained", - - # The `internal_hdrs` are header files which appear in `srcs`. - # These are only used when compiling the library. - "internal_hdrs": "internal header files (only used to build .cc files)", - "srcs": "source files", - }, -) - -def _flatten_target_files(targets): - return depset(transitive = [target.files for target in targets]) - - files = [] - for target in targets: - files.extend(target.files.to_list()) - return files - -def _cc_file_list_aspect_impl(target, ctx): - # Extract sources from a `cc_library` (or similar): - if CcInfo not in target: - return [] - - # We're going to reach directly into the attrs on the traversed rule. - rule_attr = ctx.rule.attr - - # CcInfo is a proxy for what we expect this rule to look like. - # However, some deps may expose `CcInfo` without having `srcs`, - # `hdrs`, etc., so we use `getattr` to handle that gracefully. - - internal_hdrs = [] - srcs = [] - - # Filter `srcs` so it only contains source files. Headers will go - # into `internal_headers`. - for src in _flatten_target_files(getattr(rule_attr, "srcs", [])).to_list(): - if src.extension.lower() in ["c", "cc", "cpp", "cxx"]: - srcs.append(src) - else: - internal_hdrs.append(src) - - return [CcFileList( - hdrs = _flatten_target_files(getattr(rule_attr, "hdrs", depset())), - textual_hdrs = _flatten_target_files(getattr( - rule_attr, - "textual_hdrs", - depset(), - )), - internal_hdrs = depset(internal_hdrs), - srcs = depset(srcs), - )] - -cc_file_list_aspect = aspect( - doc = """ -Aspect to provide the list of sources and headers from a rule. - -Output is CcFileList. Example: - - cc_library( - name = "foo", - srcs = [ - "foo.cc", - "foo_internal.h", - ], - hdrs = ["foo.h"], - textual_hdrs = ["foo_inl.inc"], - ) - # produces: - # CcFileList( - # hdrs = depset([File("foo.h")]), - # textual_hdrs = depset([File("foo_inl.inc")]), - # internal_hdrs = depset([File("foo_internal.h")]), - # srcs = depset([File("foo.cc")]), - # ) -""", - implementation = _cc_file_list_aspect_impl, -) - -################################################################################ -# Rule impl -################################################################################ - -def _collect_inputs(deps): - """Collects files from a list of immediate deps. - - This rule collects source files and linker inputs for C++ deps. Only - these immediate deps are considered, not transitive deps. - - The return value is a struct with object files (linker inputs), - partitioned by PIC and non-pic, and the rules' source and header files: - - struct( - objects = ..., # non-PIC object files - pic_objects = ..., # PIC objects - cc_file_list = ..., # a CcFileList - ) - - Args: - deps: Iterable of immediate deps. These will be treated as the "inputs," - but not the transitive deps. - - Returns: - A struct with linker inputs, source files, and header files. - """ - - objs = [] - pic_objs = [] - - # The returned CcFileList will contain depsets of the deps' file lists. - # These lists hold `depset()`s from each of `deps`. - srcs = [] - hdrs = [] - internal_hdrs = [] - textual_hdrs = [] - - for dep in deps: - if CcInfo in dep: - _collect_linker_input_objects( - dep.label, - dep[CcInfo], - objs, - pic_objs, - ) - - if CcFileList in dep: - cfl = dep[CcFileList] - srcs.append(cfl.srcs) - hdrs.append(cfl.hdrs) - internal_hdrs.append(cfl.internal_hdrs) - textual_hdrs.append(cfl.textual_hdrs) - - return struct( - objects = objs, - pic_objects = pic_objs, - cc_file_list = CcFileList( - srcs = depset(transitive = srcs), - hdrs = depset(transitive = hdrs), - internal_hdrs = depset(transitive = internal_hdrs), - textual_hdrs = depset(transitive = textual_hdrs), - ), - ) - -# Implementation for cc_dist_library rule. -def _cc_dist_library_impl(ctx): - cc_toolchain_info = find_cc_toolchain(ctx) - - feature_configuration = cc_common.configure_features( - ctx = ctx, - cc_toolchain = cc_toolchain_info, - ) - - inputs = _collect_inputs(ctx.attr.deps) - - # For static libraries, build separately with and without pic. - - stemname = "lib" + ctx.label.name - outputs = [] - - if len(inputs.objects) > 0: - archive_out = ctx.actions.declare_file(stemname + ".a") - _create_archive_action( - ctx, - feature_configuration, - cc_toolchain_info, - archive_out, - inputs.objects, - ) - outputs.append(archive_out) - - if len(inputs.pic_objects) > 0: - pic_archive_out = ctx.actions.declare_file(stemname + ".pic.a") - _create_archive_action( - ctx, - feature_configuration, - cc_toolchain_info, - pic_archive_out, - inputs.pic_objects, - ) - outputs.append(pic_archive_out) - - # For dynamic libraries, use the `cc_common.link` command to ensure - # everything gets built correctly according to toolchain definitions. - outputs.extend(_create_dso_link_action( - ctx, - feature_configuration, - cc_toolchain_info, - inputs.objects, - inputs.pic_objects, - )) - # We could expose the libraries for use from cc rules: # # linking_context = cc_common.create_linking_context( @@ -335,7 +169,6 @@ def _cc_dist_library_impl(ctx): return [ DefaultInfo(files = depset(outputs)), - inputs.cc_file_list, ] cc_dist_library = rule( @@ -381,7 +214,6 @@ Example: "Only these targets' compilation outputs will be " + "included (i.e., the transitive dependencies are not " + "included in the output)."), - aspects = [cc_file_list_aspect], ), "linkopts": attr.string_list( doc = ("Add these flags to the C++ linker command when creating " + diff --git a/libs/protobuf/post_process_dist.sh b/libs/protobuf/post_process_dist.sh new file mode 100755 index 0000000..2630f97 --- /dev/null +++ b/libs/protobuf/post_process_dist.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +# This script takes the result of "make dist" and: +# 1) Unpacks it. +# 2) Ensures all contents are user-writable. Some version control systems +# keep code read-only until you explicitly ask to edit it, and the normal +# "make dist" process does not correct for this, so the result is that +# the entire dist is still marked read-only when unpacked, which is +# annoying. So, we fix it. +# 3) Convert MSVC project files to MSVC 2005, so that anyone who has version +# 2005 *or* 2008 can open them. (In version control, we keep things in +# MSVC 2008 format since that's what we use in development.) +# 4) Uses the result to create .tar.gz, .tar.bz2, and .zip versions and +# deposits them in the "dist" directory. In the .zip version, all +# non-testdata .txt files are converted to Windows-style line endings. +# 5) Cleans up after itself. + +if [ "$1" == "" ]; then + echo "USAGE: $0 DISTFILE" >&2 + exit 1 +fi + +if [ ! -e $1 ]; then + echo $1": File not found." >&2 + exit 1 +fi + +set -ex + +LANGUAGES="cpp csharp java objectivec python ruby php all" +BASENAME=`basename $1 .tar.gz` +VERSION=${BASENAME:9} + +# Create a directory called "dist", copy the tarball there and unpack it. +mkdir dist +cp $1 dist +cd dist +tar zxvf $BASENAME.tar.gz +rm $BASENAME.tar.gz + +# Set the entire contents to be user-writable. +chmod -R u+w $BASENAME +cd $BASENAME + +for LANG in $LANGUAGES; do + # Build the dist again in .tar.gz + ./configure DIST_LANG=$LANG + make dist-gzip + mv $BASENAME.tar.gz ../protobuf-$LANG-$VERSION.tar.gz +done + +# Convert all text files to use DOS-style line endings, then build a .zip +# distribution. +todos *.txt */*.txt + +for LANG in $LANGUAGES; do + # Build the dist again in .zip + ./configure DIST_LANG=$LANG + make dist-zip + mv $BASENAME.zip ../protobuf-$LANG-$VERSION.zip +done + +cd .. +rm -rf $BASENAME diff --git a/libs/protobuf/protobuf-lite.pc.in b/libs/protobuf/protobuf-lite.pc.in new file mode 100644 index 0000000..f92e4ad --- /dev/null +++ b/libs/protobuf/protobuf-lite.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Protocol Buffers +Description: Google's Data Interchange Format +Version: @VERSION@ +Libs: -L${libdir} -lprotobuf-lite +Cflags: -I${includedir} +Conflicts: protobuf diff --git a/libs/protobuf/protobuf.bzl b/libs/protobuf/protobuf.bzl index f638f39..c5b8dab 100644 --- a/libs/protobuf/protobuf.bzl +++ b/libs/protobuf/protobuf.bzl @@ -1,7 +1,7 @@ load("@bazel_skylib//lib:versions.bzl", "versions") -load("@rules_cc//cc:defs.bzl", "objc_library") +load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_proto//proto:defs.bzl", "ProtoInfo") -load("@rules_python//python:defs.bzl", "py_library") +load("@rules_python//python:defs.bzl", "py_library", "py_test") def _GetPath(ctx, path): if ctx.label.workspace_root: @@ -37,24 +37,20 @@ def _SourceDir(ctx): return _GetPath(ctx, ctx.attr.includes[0]) return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0]) -def _ObjcBase(srcs): - return [ - "".join([token.capitalize() for token in src[:-len(".proto")].split("_")]) - for src in srcs - ] +def _CcHdrs(srcs, use_grpc_plugin = False): + ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + return ret -def _ObjcHdrs(srcs): - return [src + ".pbobjc.h" for src in _ObjcBase(srcs)] +def _CcSrcs(srcs, use_grpc_plugin = False): + ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs] + if use_grpc_plugin: + ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs] + return ret -def _ObjcSrcs(srcs): - return [src + ".pbobjc.m" for src in _ObjcBase(srcs)] - -def _ObjcOuts(srcs, out_type): - if out_type == "hdrs": - return _ObjcHdrs(srcs) - if out_type == "srcs": - return _ObjcSrcs(srcs) - return _ObjcHdrs(srcs) + _ObjcSrcs(srcs) +def _CcOuts(srcs, use_grpc_plugin = False): + return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin) def _PyOuts(srcs, use_grpc_plugin = False): ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs] @@ -62,29 +58,29 @@ def _PyOuts(srcs, use_grpc_plugin = False): ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs] return ret -def _RubyOuts(srcs): - return [s[:-len(".proto")] + "_pb.rb" for s in srcs] +def _RelativeOutputPath(path, include, dest = ""): + if include == None: + return path -def _CsharpOuts(srcs): - return [ - "".join([token.capitalize() for token in src[:-len(".proto")].split("_")]) + ".cs" - for src in srcs - ] + if not path.startswith(include): + fail("Include path %s isn't part of the path %s." % (include, path)) -ProtoGenInfo = provider( - fields = ["srcs", "import_flags", "deps"], -) + if include and include[-1] != "/": + include = include + "/" + if dest and dest[-1] != "/": + dest = dest + "/" + + path = path[len(include):] + return dest + path def _proto_gen_impl(ctx): """General implementation for generating protos""" srcs = ctx.files.srcs - langs = ctx.attr.langs or [] - out_type = ctx.attr.out_type - deps = depset(direct = ctx.files.srcs) + deps = depset(direct=ctx.files.srcs) source_dir = _SourceDir(ctx) gen_dir = _GenDir(ctx).rstrip("/") import_flags = [] - + if source_dir: has_sources = any([src.is_source for src in srcs]) if has_sources: @@ -96,38 +92,27 @@ def _proto_gen_impl(ctx): if has_generated: import_flags += ["-I" + gen_dir] - if ctx.attr.includes: - for include in ctx.attr.includes: - import_flags += ["-I" + _GetPath(ctx, include)] - - import_flags = depset(direct = import_flags) + import_flags = depset(direct=import_flags) for dep in ctx.attr.deps: - dep_proto = dep[ProtoGenInfo] - if type(dep_proto.import_flags) == "list": - import_flags = depset( - transitive = [import_flags], - direct = dep_proto.import_flags, - ) + if type(dep.proto.import_flags) == "list": + import_flags = depset(transitive=[import_flags], direct=dep.proto.import_flags) else: - import_flags = depset( - transitive = [import_flags, dep_proto.import_flags], - ) - if type(dep_proto.deps) == "list": - deps = depset(transitive = [deps], direct = dep_proto.deps) + import_flags = depset(transitive=[import_flags, dep.proto.import_flags]) + if type(dep.proto.deps) == "list": + deps = depset(transitive=[deps], direct=dep.proto.deps) else: - deps = depset(transitive = [deps, dep_proto.deps]) + deps = depset(transitive=[deps, dep.proto.deps]) - if not langs and not ctx.executable.plugin: - return [ - ProtoGenInfo( + if not ctx.attr.gen_cc and not ctx.attr.gen_py and not ctx.executable.plugin: + return struct( + proto = struct( srcs = srcs, import_flags = import_flags, deps = deps, ), - ] + ) - generated_files = [] for src in srcs: args = [] @@ -138,28 +123,17 @@ def _proto_gen_impl(ctx): path = f.replace("-I", "") import_flags_real.append("-I$(realpath -s %s)" % path) + outs = [] use_grpc_plugin = (ctx.attr.plugin_language == "grpc" and ctx.attr.plugin) path_tpl = "$(realpath %s)" if in_gen_dir else "%s" + if ctx.attr.gen_cc: + args += [("--cpp_out=" + path_tpl) % gen_dir] + outs.extend(_CcOuts([src.basename], use_grpc_plugin = use_grpc_plugin)) + if ctx.attr.gen_py: + args += [("--python_out=" + path_tpl) % gen_dir] + outs.extend(_PyOuts([src.basename], use_grpc_plugin = use_grpc_plugin)) - outs = [] - for lang in langs: - if lang == "csharp": - outs.extend(_CsharpOuts([src.basename])) - elif lang == "objc": - outs.extend(_ObjcOuts([src.basename], out_type = out_type)) - elif lang == "python": - outs.extend(_PyOuts([src.basename], use_grpc_plugin = use_grpc_plugin)) - elif lang == "ruby": - outs.extend(_RubyOuts([src.basename])) - - # Otherwise, rely on user-supplied outs. - args += [("--%s_out=" + path_tpl) % (lang, gen_dir)] - - if ctx.attr.outs: - outs.extend(ctx.attr.outs) outs = [ctx.actions.declare_file(out, sibling = src) for out in outs] - generated_files.extend(outs) - inputs = [src] + deps.to_list() tools = [ctx.executable.protoc] if ctx.executable.plugin: @@ -212,15 +186,39 @@ def _proto_gen_impl(ctx): use_default_shell_env = True, ) - return [ - ProtoGenInfo( + return struct( + proto = struct( srcs = srcs, import_flags = import_flags, deps = deps, ), - DefaultInfo(files = depset(generated_files)), - ] + ) +proto_gen = rule( + attrs = { + "srcs": attr.label_list(allow_files = True), + "deps": attr.label_list(providers = ["proto"]), + "includes": attr.string_list(), + "protoc": attr.label( + cfg = "exec", + executable = True, + allow_single_file = True, + mandatory = True, + ), + "plugin": attr.label( + cfg = "exec", + allow_files = True, + executable = True, + ), + "plugin_language": attr.string(), + "plugin_options": attr.string_list(), + "gen_cc": attr.bool(), + "gen_py": attr.bool(), + "outs": attr.output_list(), + }, + output_to_genfiles = True, + implementation = _proto_gen_impl, +) """Generates codes from Protocol Buffers definitions. This rule helps you to implement Skylark macros specific to the target @@ -237,40 +235,103 @@ Args: compiler. plugin_language: the language of the generated sources plugin_options: a list of options to be passed to the plugin - langs: generates sources in addition to the ones from the plugin for each - specified language. + gen_cc: generates C++ sources in addition to the ones from the plugin. + gen_py: generates Python sources in addition to the ones from the plugin. outs: a list of labels of the expected outputs from the protocol compiler. - out_type: only generated a single type of source file for languages that have - split sources (e.g. *.h and *.cc in C++) """ -_proto_gen = rule( + +def _adapt_proto_library_impl(ctx): + deps = [dep[ProtoInfo] for dep in ctx.attr.deps] + + srcs = [src for dep in deps for src in dep.direct_sources] + return struct( + proto = struct( + srcs = srcs, + import_flags = ["-I{}".format(path) for dep in deps for path in dep.transitive_proto_path.to_list()], + deps = srcs, + ), + ) + +adapt_proto_library = rule( + implementation = _adapt_proto_library_impl, attrs = { - "srcs": attr.label_list(allow_files = True), - "deps": attr.label_list(providers = [ProtoGenInfo]), - "includes": attr.string_list(), - "protoc": attr.label( - cfg = "exec", - executable = True, - allow_single_file = True, + "deps": attr.label_list( mandatory = True, - ), - "plugin": attr.label( - cfg = "exec", - allow_files = True, - executable = True, - ), - "plugin_language": attr.string(), - "plugin_options": attr.string_list(), - "langs": attr.string_list(), - "outs": attr.string_list(), - "out_type": attr.string( - default = "all", + providers = [ProtoInfo], ), }, - output_to_genfiles = True, - implementation = _proto_gen_impl, + doc = "Adapts `proto_library` from `@rules_proto` to be used with `{cc,py}_proto_library` from this file.", ) +def cc_proto_library( + name, + srcs = [], + deps = [], + cc_libs = [], + include = None, + protoc = "@com_google_protobuf//:protoc", + use_grpc_plugin = False, + default_runtime = "@com_google_protobuf//:protobuf", + **kargs): + """Bazel rule to create a C++ protobuf library from proto source files + + NOTE: the rule is only an internal workaround to generate protos. The + interface may change and the rule may be removed when bazel has introduced + the native rule. + + Args: + name: the name of the cc_proto_library. + srcs: the .proto files of the cc_proto_library. + deps: a list of dependency labels; must be cc_proto_library. + cc_libs: a list of other cc_library targets depended by the generated + cc_library. + include: a string indicating the include path of the .proto files. + protoc: the label of the protocol compiler to generate the sources. + use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin + when processing the proto files. + default_runtime: the implicitly default runtime which will be depended on by + the generated cc_library target. + **kargs: other keyword arguments that are passed to cc_library. + """ + + includes = [] + if include != None: + includes = [include] + + grpc_cpp_plugin = None + if use_grpc_plugin: + grpc_cpp_plugin = "//external:grpc_cpp_plugin" + + gen_srcs = _CcSrcs(srcs, use_grpc_plugin) + gen_hdrs = _CcHdrs(srcs, use_grpc_plugin) + outs = gen_srcs + gen_hdrs + + proto_gen( + name = name + "_genproto", + srcs = srcs, + deps = [s + "_genproto" for s in deps], + includes = includes, + protoc = protoc, + plugin = grpc_cpp_plugin, + plugin_language = "grpc", + gen_cc = 1, + outs = outs, + visibility = ["//visibility:public"], + ) + + if default_runtime and not default_runtime in cc_libs: + cc_libs = cc_libs + [default_runtime] + if use_grpc_plugin: + cc_libs = cc_libs + ["//external:grpc_lib"] + cc_library( + name = name, + srcs = gen_srcs, + hdrs = gen_hdrs, + deps = cc_libs + deps, + includes = includes, + **kargs + ) + def _internal_gen_well_known_protos_java_impl(ctx): args = ctx.actions.args() @@ -395,97 +456,42 @@ internal_gen_kt_protos = rule( }, ) -def internal_objc_proto_library( - name, - srcs = [], - deps = [], - outs = [], - proto_deps = [], - includes = ["."], - default_runtime = "@com_google_protobuf//:protobuf_objc", - protoc = "@com_google_protobuf//:protoc", - testonly = None, - visibility = ["//visibility:public"], - **kwargs): - """Bazel rule to create a Objective-C protobuf library from proto source - files - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. + +def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs): + """Macro to copy files to a different directory and then create a filegroup. + + This is used by the //:protobuf_python py_proto_library target to work around + an issue caused by Python source files that are part of the same Python + package being in separate directories. Args: - name: the name of the objc_proto_library. - srcs: the .proto files to compile. - deps: a list of dependency labels; must be objc_proto_library. - outs: a list of expected output files. - proto_deps: a list of proto file dependencies that don't have a - objc_proto_library rule. - include: a string indicating the include path of the .proto files. - default_runtime: the Objective-C Protobuf runtime - protoc: the label of the protocol compiler to generate the sources. - testonly: common rule attribute (see: - https://bazel.build/reference/be/common-definitions#common-attributes) - visibility: the visibility of the generated files. - **kwargs: other keyword arguments that are passed to py_library. - + srcs: The source files to copy and add to the filegroup. + strip_prefix: Path to the root of the files to copy. + dest: The directory to copy the source files into. + **kwargs: extra arguments that will be passesd to the filegroup. """ - full_deps = [d + "_genproto" for d in deps] + outs = [_RelativeOutputPath(s, strip_prefix, dest) for s in srcs] - if proto_deps: - _proto_gen( - name = name + "_deps_genproto", - testonly = testonly, - srcs = proto_deps, - protoc = protoc, - includes = includes, - ) - full_deps.append(":%s_deps_genproto" % name) - - # Note: we need to run the protoc build twice to get separate targets for - # the generated header and the source files. - _proto_gen( - name = name + "_genproto_hdrs", + native.genrule( + name = name + "_genrule", srcs = srcs, - deps = full_deps, - langs = ["objc"], - out_type = "hdrs", - includes = includes, - protoc = protoc, - testonly = testonly, - visibility = visibility, - tags = ["manual"], + outs = outs, + cmd_bash = " && ".join( + ["cp $(location %s) $(location %s)" % + (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]), + cmd_bat = " && ".join( + ["@copy /Y $(location %s) $(location %s) >NUL" % + (s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs]), ) - _proto_gen( - name = name + "_genproto", - srcs = srcs, - deps = full_deps, - langs = ["objc"], - out_type = "srcs", - includes = includes, - protoc = protoc, - testonly = testonly, - visibility = visibility, - tags = ["manual"], - ) - - objc_library( + native.filegroup( name = name, - hdrs = [name + "_genproto_hdrs"], - non_arc_srcs = [name + "_genproto"], - deps = [default_runtime], - includes = includes, - testonly = testonly, - visibility = visibility, - # Don't auto-expand these targets until target_compatible_with - # works. See https://github.com/bazelbuild/bazel/issues/12897. - tags = ["manual"], - target_compatible_with = ["@platforms//os:osx"], + srcs = outs, **kwargs ) -def internal_py_proto_library( +def py_proto_library( name, srcs = [], deps = [], @@ -495,7 +501,6 @@ def internal_py_proto_library( default_runtime = "@com_google_protobuf//:protobuf_python", protoc = "@com_google_protobuf//:protoc", use_grpc_plugin = False, - testonly = None, **kargs): """Bazel rule to create a Python protobuf library from proto source files @@ -517,11 +522,11 @@ def internal_py_proto_library( protoc: the label of the protocol compiler to generate the sources. use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin when processing the proto files. - testonly: common rule attribute (see: - https://bazel.build/reference/be/common-definitions#common-attributes) **kargs: other keyword arguments that are passed to py_library. """ + outs = _PyOuts(srcs, use_grpc_plugin) + includes = [] if include != None: includes = [include] @@ -533,14 +538,14 @@ def internal_py_proto_library( # is not explicitly listed in py_libs. Instead, host system is assumed to # have grpc installed. - _proto_gen( + proto_gen( name = name + "_genproto", - testonly = testonly, srcs = srcs, deps = [s + "_genproto" for s in deps], includes = includes, protoc = protoc, - langs = ["python"], + gen_py = 1, + outs = outs, visibility = ["//visibility:public"], plugin = grpc_python_plugin, plugin_language = "grpc", @@ -550,158 +555,33 @@ def internal_py_proto_library( py_libs = py_libs + [default_runtime] py_library( name = name, - testonly = testonly, - srcs = [name + "_genproto"] + py_extra_srcs, + srcs = outs + py_extra_srcs, deps = py_libs + deps, imports = includes, **kargs ) -def py_proto_library( - *args, - **kwargs): - """Deprecated alias for use before Bazel 5.3. - - Args: - *args: the name of the py_proto_library. - **kwargs: other keyword arguments that are passed to py_library. - - Deprecated: - This is provided for backwards compatibility only. Bazel 5.3 will - introduce support for py_proto_library, which should be used instead. - """ - internal_py_proto_library(*args, **kwargs) - -def _source_proto_library( +def internal_protobuf_py_tests( name, - srcs = [], - deps = [], - proto_deps = [], - outs = [], - lang = None, - includes = ["."], - protoc = "@com_google_protobuf//:protoc", - testonly = None, - visibility = ["//visibility:public"], - **kwargs): - """Bazel rule to create generated protobuf code from proto source files for - languages not well supported by Bazel yet. This will output the generated - code as-is without any compilation. This is most useful for interpreted - languages that don't require it. - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. + modules = [], + **kargs): + """Bazel rules to create batch tests for protobuf internal. Args: - name: the name of the unsupported_proto_library. - srcs: the .proto files to compile. Note, that for languages where out - needs to be provided, only a single source file is allowed. - deps: a list of dependency labels; must be unsupported_proto_library. - proto_deps: a list of proto file dependencies that don't have a - unsupported_proto_library rule. - lang: the language to (optionally) generate code for. - outs: a list of expected output files. This is only required for - languages where we can't predict the outputs. - includes: strings indicating the include path of the .proto files. - protoc: the label of the protocol compiler to generate the sources. - testonly: common rule attribute (see: - https://bazel.build/reference/be/common-definitions#common-attributes) - visibility: the visibility of the generated files. - **kwargs: other keyword arguments that are passed to py_library. + name: the name of the rule. + modules: a list of modules for tests. The macro will create a py_test for + each of the parameter with the source "google/protobuf/%s.py" + kargs: extra parameters that will be passed into the py_test. """ - if outs and len(srcs) != 1: - fail("Custom outputs only allowed for single proto targets.") - - langs = [] - if lang != None: - langs = [lang] - - full_deps = [d + "_genproto" for d in deps] - - if proto_deps: - _proto_gen( - name = name + "_deps_genproto", - testonly = testonly, - srcs = proto_deps, - protoc = protoc, - includes = includes, + for m in modules: + s = "python/google/protobuf/internal/%s.py" % m + py_test( + name = "py_%s" % m, + srcs = [s], + main = s, + **kargs ) - full_deps.append(":%s_deps_genproto" % name) - - _proto_gen( - name = name + "_genproto", - srcs = srcs, - deps = full_deps, - langs = langs, - outs = outs, - includes = includes, - protoc = protoc, - testonly = testonly, - visibility = visibility, - ) - - native.filegroup( - name = name, - srcs = [":%s_genproto" % name], - testonly = testonly, - visibility = visibility, - **kwargs - ) - -def internal_csharp_proto_library(**kwargs): - """Bazel rule to create a C# protobuf library from proto source files - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. - - Args: - **kwargs: arguments that are passed to unsupported_proto_library. - - """ - - _source_proto_library( - lang = "csharp", - **kwargs - ) - -def internal_php_proto_library(**kwargs): - """Bazel rule to create a PHP protobuf library from proto source files - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. - - Args: - **kwargs: arguments that are passed to unsupported_proto_library. - - """ - if not kwargs.get("outs"): - fail("Unable to predict the outputs for php_proto_library. Please specify them via `outs`.") - - _source_proto_library( - lang = "php", - **kwargs - ) - -def internal_ruby_proto_library(**kwargs): - """Bazel rule to create a Ruby protobuf library from proto source files - - NOTE: the rule is only an internal workaround to generate protos. The - interface may change and the rule may be removed when bazel has introduced - the native rule. - - Args: - **kwargs: arguments that are passed to unsupported_proto_library. - - """ - - _source_proto_library( - lang = "ruby", - **kwargs - ) def check_protobuf_required_bazel_version(): """For WORKSPACE files, to check the installed version of bazel. diff --git a/libs/protobuf/protobuf.pc.in b/libs/protobuf/protobuf.pc.in new file mode 100644 index 0000000..e9bef5d --- /dev/null +++ b/libs/protobuf/protobuf.pc.in @@ -0,0 +1,13 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: Protocol Buffers +Description: Google's Data Interchange Format +Version: @VERSION@ +Libs: -L${libdir} -lprotobuf +Libs.private: @LIBS@ + +Cflags: -I${includedir} +Conflicts: protobuf-lite diff --git a/libs/protobuf/protobuf_deps.bzl b/libs/protobuf/protobuf_deps.bzl index 9c69567..0949ef3 100644 --- a/libs/protobuf/protobuf_deps.bzl +++ b/libs/protobuf/protobuf_deps.bzl @@ -3,10 +3,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") PROTOBUF_MAVEN_ARTIFACTS = [ - "com.google.caliper:caliper:1.0-beta-3", "com.google.code.findbugs:jsr305:3.0.2", "com.google.code.gson:gson:2.8.9", - "com.google.errorprone:error_prone_annotations:2.5.1", + "com.google.errorprone:error_prone_annotations:2.3.2", "com.google.j2objc:j2objc-annotations:1.3", "com.google.guava:guava:31.1-jre", "com.google.guava:guava-testlib:31.1-jre", @@ -29,11 +28,11 @@ def protobuf_deps(): if not native.existing_rule("bazel_skylib"): http_archive( name = "bazel_skylib", + sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", ], - sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728", ) if not native.existing_rule("com_google_absl"): @@ -41,8 +40,8 @@ def protobuf_deps(): _github_archive( name = "com_google_absl", repo = "https://github.com/abseil/abseil-cpp", - commit = "273292d1cfc0a94a65082ee350509af1d113344d", - sha256 = "6764f226bd6e2d8ab9fe2f3cab5f45fb1a4a15c04b58b87ba7fa87456054f98b", + commit = "215105818dfde3174fe799600bb0f3cae233d0bf", + sha256 = "b4e20d9e752a75c10636675691b1e9c2698e0764cb404987d0ffa77223041c19", ) if not native.existing_rule("zlib"): @@ -57,23 +56,6 @@ def protobuf_deps(): ], ) - if not native.existing_rule("jsoncpp"): - http_archive( - name = "jsoncpp", - build_file = "@com_google_protobuf//:third_party/jsoncpp.BUILD", - sha256 = "e34a628a8142643b976c7233ef381457efad79468c67cb1ae0b83a33d7493999", - strip_prefix = "jsoncpp-1.9.4", - urls = ["https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.4.tar.gz"], - ) - - if not native.existing_rule("utf8_range"): - _github_archive( - name = "utf8_range", - repo = "https://github.com/protocolbuffers/utf8_range", - commit = "45fbf543fec00020a08650791a37575319a3ea1d", - sha256 = "dd93db062025f563068abaa224549e9d341434b5851e959c7853dfa263c96416", - ) - if not native.existing_rule("rules_cc"): _github_archive( name = "rules_cc", @@ -127,14 +109,14 @@ def protobuf_deps(): if not native.existing_rule("io_bazel_rules_kotlin"): http_archive( name = "io_bazel_rules_kotlin", - urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.7.0-RC-1/rules_kotlin_release.tgz"], - sha256 = "68b910730026921814d3a504ccbe9adaac9938983d940e626523e6e4ecfb0355", + urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.5.0-beta-4/rules_kotlin_release.tgz"], + sha256 = "6cbd4e5768bdfae1598662e40272729ec9ece8b7bded8f0d2c81c8ff96dc139d", ) if not native.existing_rule("upb"): _github_archive( name = "upb", repo = "https://github.com/protocolbuffers/upb", - commit = "9e2d7f02da5440bfb0dfb069f61baa278aa2fbf6", - sha256 = "9eb13368a136af314855e1497838cf3124846b6a73a7e7c882455a52b8c04662", + commit = "20b542a767139732548f7b8cf28c4c928cdcb07b", + sha256 = "c77158955326f9e9a0cf8481c118b8ad5c34df99e5db3af27f3d1662d8bedef7", ) diff --git a/libs/protobuf/protobuf_version.bzl b/libs/protobuf/protobuf_version.bzl index cc6cf85..4ac031c 100644 --- a/libs/protobuf/protobuf_version.bzl +++ b/libs/protobuf/protobuf_version.bzl @@ -1,3 +1,4 @@ -PROTOC_VERSION = "21.8" -PROTOBUF_JAVA_VERSION = "3.21.8" -PROTOBUF_PYTHON_VERSION = "4.21.8" +PROTOC_VERSION = "21.12" +PROTOBUF_JAVA_VERSION = "3.21.12" +PROTOBUF_PYTHON_VERSION = "4.21.12" +PROTOBUF_PHP_VERSION = "3.21.12" diff --git a/libs/protobuf/protoc-artifacts/Dockerfile b/libs/protobuf/protoc-artifacts/Dockerfile new file mode 100644 index 0000000..278bc74 --- /dev/null +++ b/libs/protobuf/protoc-artifacts/Dockerfile @@ -0,0 +1,55 @@ +FROM centos:6.9 + +RUN yum install -y git \ + tar \ + wget \ + make \ + autoconf \ + curl-devel \ + unzip \ + automake \ + libtool \ + glibc-static.i686 \ + glibc-devel \ + glibc-devel.i686 \ + && \ + yum clean all + +# Install Java 8 +RUN wget -q --no-cookies --no-check-certificate \ + --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \ + "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz" \ + -O - | tar xz -C /var/local +ENV JAVA_HOME /var/local/jdk1.8.0_131 +ENV PATH $JAVA_HOME/bin:$PATH + +# Install Maven +RUN wget -q http://apache.cs.utah.edu/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -O - | \ + tar xz -C /var/local +ENV PATH /var/local/apache-maven-3.3.9/bin:$PATH + +# Install GCC 4.8 to support -static-libstdc++ +RUN wget http://people.centos.org/tru/devtools-2/devtools-2.repo -P /etc/yum.repos.d && \ + bash -c 'echo "enabled=1" >> /etc/yum.repos.d/devtools-2.repo' && \ + bash -c "sed -e 's/\$basearch/i386/g' /etc/yum.repos.d/devtools-2.repo > /etc/yum.repos.d/devtools-i386-2.repo" && \ + sed -e 's/testing-/testing-i386-/g' -i /etc/yum.repos.d/devtools-i386-2.repo && \ + rpm --rebuilddb + +RUN yum install -y devtoolset-2-gcc \ + devtoolset-2-gcc-c++ \ + devtoolset-2-binutils \ + devtoolset-2-libstdc++-devel \ + devtoolset-2-libatomic-devel \ + libatomic \ + devtoolset-2-gcc.i686 \ + devtoolset-2-gcc-c++.i686 \ + devtoolset-2-binutils.i686 \ + devtoolset-2-libstdc++-devel.i686 \ + devtoolset-2-libatomic-devel.i686 \ + libatomic.i686 && \ + yum clean all + +COPY scl-enable-devtoolset.sh /var/local/ + +# Start in devtoolset environment that uses GCC 4.7 +ENTRYPOINT ["/var/local/scl-enable-devtoolset.sh"] diff --git a/libs/protobuf/protoc-artifacts/README.md b/libs/protobuf/protoc-artifacts/README.md new file mode 100644 index 0000000..8fc3669 --- /dev/null +++ b/libs/protobuf/protoc-artifacts/README.md @@ -0,0 +1,161 @@ +# Build scripts that publish pre-compiled protoc artifacts +``protoc`` is the compiler for ``.proto`` files. It generates language bindings +for the messages and/or RPC services from ``.proto`` files. + +Because ``protoc`` is a native executable, the scripts under this directory +build and publish a ``protoc`` executable (a.k.a. artifact) to Maven +repositories. The artifact can be used by build automation tools so that users +would not need to compile and install ``protoc`` for their systems. + +If you would like us to publish protoc artifact for a new platform, please send +us a pull request to add support for the new platform. You would need to change +the following files: + +* [build-protoc.sh](build-protoc.sh): script to cross-build the protoc for your + platform. +* [pom.xml](pom.xml): script to upload artifacts to maven. +* [build-zip.sh](build-zip.sh): script to package published maven artifacts in + our release page. + +## Maven Location +The published protoc artifacts are available on Maven here: + + https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/ + +## Versioning +The version of the ``protoc`` artifact must be the same as the version of the +Protobuf project. + +## Artifact name +The name of a published ``protoc`` artifact is in the following format: +``protoc---.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``. + +Note that artifacts for linux/macos also have the `.exe` suffix but they are +not windows binaries. + +## System requirement +Install [Apache Maven](http://maven.apache.org/) if you don't have it. + +The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and +Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project +for how to set up the build environment. + +## Building from a freshly checked-out source + +If you just checked out the Protobuf source from github, you need to +generate the configure script. + +Under the protobuf project directory: + + +``` +$ ./autogen.sh +``` + +### Build the artifact for each platform + +Run the build-protoc.sh script under this protoc-artifacts directory to build the protoc +artifact for each platform. For example: + +``` +$ cd protoc-artifacts +$ ./build-protoc.sh linux x86_64 protoc +``` + +The above command will produce a `target/linux/x86_64/protoc` binary under the +protoc-artifacts directory. + +For a list of supported platforms, see the comments in the build-protoc.sh +script. We only use this script to build artifacts on Ubuntu and MacOS (both +with x86_64, and do cross-compilation for other platforms. + +### Tips for building for Linux +We build on Centos 6.9 to provide a good compatibility for not very new +systems. We have provided a ``Dockerfile`` under this directory to build the +environment. It has been tested with Docker 1.6.1. + +To build a image: + +``` +$ docker build -t protoc-artifacts . +``` + +To run the image: + +``` +$ docker run -it --rm=true protoc-artifacts bash +``` + +To checkout protobuf (run within the container): + +``` +$ # Replace v3.5.1 with the version you want +$ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp +``` + +### Windows build +We no longer use scripts in this directory to build windows artifacts. Instead, +we use Visual Studio 2015 to build our windows release artifacts. See our +[kokoro windows build scripts here](../kokoro/release/protoc/windows/build.bat). + +To upload windows artifacts, copy the built binaries into this directory and +put it into the target/windows/(x86_64|x86_32) directory the same way as the +artifacts for other platforms. That will allow the maven script to find and +upload the artifacts to maven. + +## To push artifacts to Maven Central +Before you can upload artifacts to Maven Central repository, make sure you have +read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to +configure GPG and Sonatype account. + +Before you do the deployment, make sure you have built the protoc artifacts for +every supported platform and put them under the target directory. Example +target directory layout: + + + pom.xml + + target + + linux + + x86_64 + protoc.exe + + x86_32 + protoc.exe + + aarch_64 + protoc.exe + + ppcle_64 + protoc.exe + + s390_64 + protoc.exe + + osx + + x86_64 + protoc.exe + + x86_32 + protoc.exe + + windows + + x86_64 + protoc.exe + + x86_32 + protoc.exe + +You will need to build the artifacts on multiple machines and gather them +together into one place. + +Use the following command to deploy artifacts for the host platform to a +staging repository. + +``` +$ mvn deploy -P release +``` + +It creates a new staging repository. Go to +https://oss.sonatype.org/#stagingRepositories and find the repository, usually +in the name like ``comgoogle-123``. Verify that the staging repository has all +the binaries, close and release this repository. + + +## Tested build environments +We have successfully built artifacts on the following environments: +- Linux x86_32 and x86_64: + - Centos 6.9 (within Docker 1.6.1) + - Ubuntu 14.04.5 64-bit +- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit +- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5 diff --git a/libs/protobuf/kokoro/release/protoc/build-protoc.sh b/libs/protobuf/protoc-artifacts/build-protoc.sh similarity index 73% rename from libs/protobuf/kokoro/release/protoc/build-protoc.sh rename to libs/protobuf/protoc-artifacts/build-protoc.sh index c0785ee..4602842 100755 --- a/libs/protobuf/kokoro/release/protoc/build-protoc.sh +++ b/libs/protobuf/protoc-artifacts/build-protoc.sh @@ -19,20 +19,28 @@ # macos osx x86_64 # mingw windows x86_32 # mingw windows x86_64 +# +# Before running this script, make sure you have generated the configure script +# in the parent directory (i.e., run ./autogen.sh there). OS=$1 ARCH=$2 -BAZEL_TARGET=$3 +MAKE_TARGET=$3 if [[ $# < 3 ]]; then echo "Not enough arguments provided." exit 1 fi -if [[ $BAZEL_TARGET != protoc ]]; then - echo "Target ""$BAZEL_TARGET"" invalid." +case $MAKE_TARGET in + protoc-gen-javalite) + ;; + protoc) + ;; + *) + echo "Target ""$MAKE_TARGET"" invalid." exit 1 -fi +esac # Under Cygwin, bash doesn't have these in PATH when called from Maven which # runs in Windows version of Java. @@ -138,22 +146,22 @@ checkDependencies () host_machine="$(uname -m)"; dump_cmd='ldd '"$1" if [[ "$ARCH" == x86_32 ]]; then - white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux\.so\.2" + white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2" elif [[ "$ARCH" == x86_64 ]]; then - white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux-x86-64\.so\.2" + white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2" elif [[ "$ARCH" == s390_64 ]]; then if [[ $host_machine != s390x ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi - white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|libz\.so\.1\|ld64\.so\.1" + white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libz\.so\.1\|ld64\.so\.1" elif [[ "$ARCH" == ppcle_64 ]]; then if [[ $host_machine != ppc64le ]];then dump_cmd='objdump -p '"$1"' | grep NEEDED' fi - white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|libz\.so\.1\|ld64\.so\.2" + white_list="linux-vdso64\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libz\.so\.1\|ld64\.so\.2" elif [[ "$ARCH" == aarch_64 ]]; then dump_cmd='objdump -p '"$1"' | grep NEEDED' - white_list="libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|libgcc_s\.so\.1\|libstdc++\.so\.6\|ld-linux-aarch64\.so\.1" + white_list="libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-aarch64\.so\.1" fi elif [[ "$OS" == osx ]]; then dump_cmd='otool -L '"$1"' | fgrep dylib' @@ -177,14 +185,19 @@ checkDependencies () } ############################################################################ -echo "Building protoc, OS=$OS ARCH=$ARCH TARGET=$BAZEL_TARGET" +echo "Building protoc, OS=$OS ARCH=$ARCH TARGET=$MAKE_TARGET" -BAZEL_ARGS=("--dynamic_mode=off" "--compilation_mode=opt" "--copt=-g0" "--copt=-fpic") +CONFIGURE_ARGS="--disable-shared" if [[ "$OS" == windows ]]; then - BAZEL_TARGET="${BAZEL_TARGET}.exe" + MAKE_TARGET="${MAKE_TARGET}.exe" fi +# Override the default value set in configure.ac that has '-g' which produces +# huge binary. +CXXFLAGS="-DNDEBUG" +LDFLAGS="" + if [[ "$(uname)" == CYGWIN* ]]; then assertEq "$OS" windows $LINENO # Use mingw32 compilers because executables produced by Cygwin compiler @@ -204,13 +217,28 @@ elif [[ "$(uname)" == MINGW64* ]]; then assertEq "$ARCH" x86_64 $LINENO elif [[ "$(uname)" == Linux* ]]; then if [[ "$OS" == linux ]]; then - BAZEL_ARGS+=("--config=linux-$ARCH") + if [[ "$ARCH" == x86_64 ]]; then + CXXFLAGS="$CXXFLAGS -m64" + elif [[ "$ARCH" == x86_32 ]]; then + CXXFLAGS="$CXXFLAGS -m32" + elif [[ "$ARCH" == aarch_64 ]]; then + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=aarch64-linux-gnu" + elif [[ "$ARCH" == ppcle_64 ]]; then + CXXFLAGS="$CXXFLAGS -m64" + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=powerpc64le-linux-gnu" + elif [[ "$ARCH" == s390_64 ]]; then + CXXFLAGS="$CXXFLAGS -m64" + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=s390x-linux-gnu" + else + fail "Unsupported arch: $ARCH" + fi elif [[ "$OS" == windows ]]; then # Cross-compilation for Windows + CONFIGURE_ARGS="$CONFIGURE_ARGS" if [[ "$ARCH" == x86_64 ]]; then - BAZEL_ARGS+=("--config=win64") + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32" elif [[ "$ARCH" == x86_32 ]]; then - BAZEL_ARGS+=("--config=win32") + CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-w64-mingw32" else fail "Unsupported arch: $ARCH" fi @@ -220,24 +248,43 @@ elif [[ "$(uname)" == Linux* ]]; then elif [[ "$(uname)" == Darwin* ]]; then assertEq "$OS" osx $LINENO # Make the binary compatible with OSX 10.7 and later - BAZEL_ARGS+=("--config=osx-$ARCH" "--macos_minimum_os=10.7") + CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.7" + if [[ "$ARCH" == x86_64 ]]; then + CXXFLAGS="$CXXFLAGS -m64" + elif [[ "$ARCH" == x86_32 ]]; then + CXXFLAGS="$CXXFLAGS -m32" + else + fail "Unsupported arch: $ARCH" + fi else fail "Unsupported system: $(uname)" fi +# Statically link libgcc and libstdc++. +# -s to produce stripped binary. +if [[ "$OS" == windows ]]; then + # Also static link libpthread required by mingw64 + LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -s" +elif [[ "$OS" != osx ]]; then + # And they don't work under Mac. + LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -s" +fi + +export CXXFLAGS LDFLAGS + # Nested double quotes are unintuitive, but it works. cd "$(dirname "$0")" WORKING_DIR="$(pwd)" -TARGET_FILE="target/$OS/$ARCH/$BAZEL_TARGET.exe" -DOCKER_IMAGE=gcr.io/protobuf-build/bazel/linux@sha256:2bfd061284eff8234f2fcca16d71d43c69ccf3a22206628b54c204a6a9aac277 +BUILD_DIR="build/$OS/$ARCH" +TARGET_FILE="target/$OS/$ARCH/$MAKE_TARGET.exe" -tmpfile=$(mktemp -u) && -docker run --cidfile $tmpfile -v $WORKING_DIR/../../..:/workspace $DOCKER_IMAGE \ - build //:$BAZEL_TARGET "${BAZEL_ARGS[@]}" && -mkdir -p $(dirname $TARGET_FILE) && -docker cp \ - `cat $tmpfile`:/workspace/bazel-bin/$BAZEL_TARGET $TARGET_FILE || exit 1 +mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" && + ../../../../configure $CONFIGURE_ARGS && + cd src && make $MAKE_TARGET -j8 && + cd "$WORKING_DIR" && mkdir -p $(dirname $TARGET_FILE) && + cp $BUILD_DIR/src/$MAKE_TARGET $TARGET_FILE || + exit 1 if [[ "$OS" == osx ]]; then # Since Mac linker doesn't accept "-s", we need to run strip diff --git a/libs/protobuf/protoc-artifacts/build-zip.sh b/libs/protobuf/protoc-artifacts/build-zip.sh new file mode 100755 index 0000000..1d97725 --- /dev/null +++ b/libs/protobuf/protoc-artifacts/build-zip.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +if [ $# -ne 2 ]; then + cat < + +TARGET: protoc | protoc-gen-javalite + +Example: + $ $0 protoc 3.0.0 + $ $0 protoc-gen-javalite 3.0.0 + +This script will download pre-built protoc or protoc plugin binaries from maven +repository and create .zip packages suitable to be included in the github +release page. If the target is protoc, well-known type .proto files will also be +included. Each invocation will create 8 zip packages: + dist/--win32.zip + dist/--win64.zip + dist/--osx-aarch_64.zip + dist/--osx-x86_64.zip + dist/--linux-x86_32.zip + dist/--linux-x86_64.zip + dist/--linux-aarch_64.zip + dist/--linux-ppcle_64.zip + dist/--linux-s390_64.zip +EOF + exit 1 +fi + +TARGET=$1 +VERSION_NUMBER=$2 + +# pairs. +declare -a FILE_NAMES=( \ + win32.zip windows-x86_32.exe \ + win64.zip windows-x86_64.exe \ + osx-aarch_64.zip osx-aarch_64.exe \ + osx-x86_64.zip osx-x86_64.exe \ + linux-x86_32.zip linux-x86_32.exe \ + linux-x86_64.zip linux-x86_64.exe \ + linux-aarch_64.zip linux-aarch_64.exe \ + linux-ppcle_64.zip linux-ppcle_64.exe \ + linux-s390_64.zip linux-s390_64.exe \ +) + +# List of all well-known types to be included. +declare -a WELL_KNOWN_TYPES=( \ + google/protobuf/descriptor.proto \ + google/protobuf/any.proto \ + google/protobuf/api.proto \ + google/protobuf/duration.proto \ + google/protobuf/empty.proto \ + google/protobuf/field_mask.proto \ + google/protobuf/source_context.proto \ + google/protobuf/struct.proto \ + google/protobuf/timestamp.proto \ + google/protobuf/type.proto \ + google/protobuf/wrappers.proto \ + google/protobuf/compiler/plugin.proto \ +) + +set -e + +# A temporary working directory to put all files. +DIR=$(mktemp -d) + +# Copy over well-known types. +mkdir -p ${DIR}/include/google/protobuf/compiler +for PROTO in ${WELL_KNOWN_TYPES[@]}; do + cp -f ../src/${PROTO} ${DIR}/include/${PROTO} +done + +# Create a readme file. +cat < ${DIR}/readme.txt +Protocol Buffers - Google's data interchange format +Copyright 2008 Google Inc. +https://developers.google.com/protocol-buffers/ + +This package contains a precompiled binary version of the protocol buffer +compiler (protoc). This binary is intended for users who want to use Protocol +Buffers in languages other than C++ but do not want to compile protoc +themselves. To install, simply place this binary somewhere in your PATH. + +If you intend to use the included well known types then don't forget to +copy the contents of the 'include' directory somewhere as well, for example +into '/usr/local/include/'. + +Please refer to our official github site for more installation instructions: + https://github.com/protocolbuffers/protobuf +EOF + +mkdir -p dist +mkdir -p ${DIR}/bin +# Create a zip file for each binary. +for((i=0;i<${#FILE_NAMES[@]};i+=2));do + ZIP_NAME=${FILE_NAMES[$i]} + if [ ${ZIP_NAME:0:3} = "win" ]; then + BINARY="$TARGET.exe" + else + BINARY="$TARGET" + fi + BINARY_NAME=${FILE_NAMES[$(($i+1))]} + BINARY_URL=https://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME} + if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then + echo "[ERROR] Failed to download ${BINARY_URL}" >&2 + echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2 + continue + fi + TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME} + pushd $DIR &> /dev/null + chmod +x bin/$BINARY + if [ "$TARGET" = "protoc" ]; then + zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null + else + zip -r ${TARGET_ZIP_FILE} bin &> /dev/null + fi + rm bin/$BINARY + popd &> /dev/null + echo "[INFO] Successfully created ${TARGET_ZIP_FILE}" +done diff --git a/libs/protobuf/protoc-artifacts/pom.xml b/libs/protobuf/protoc-artifacts/pom.xml new file mode 100644 index 0000000..9d4c7f2 --- /dev/null +++ b/libs/protobuf/protoc-artifacts/pom.xml @@ -0,0 +1,144 @@ + + + 4.0.0 + + com.google + google + 1 + + com.google.protobuf + protoc + 3.21.12 + pom + Protobuf Compiler + + Protobuf Compiler (protoc) is a compiler for .proto files. It generates + language-specific code for Protobuf messages and RPC interfaces. + + 2008 + https://developers.google.com/protocol-buffers/ + + + BSD-3-Clause + https://opensource.org/licenses/BSD-3-Clause + repo + + + + https://github.com/protocolbuffers/protobuf + + scm:git:https://github.com/protocolbuffers/protobuf.git + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + attach-artifacts + package + + attach-artifact + + + + + ${basedir}/target/linux/x86_64/protoc.exe + linux-x86_64 + exe + + + ${basedir}/target/linux/x86_32/protoc.exe + linux-x86_32 + exe + + + ${basedir}/target/windows/x86_64/protoc.exe + windows-x86_64 + exe + + + ${basedir}/target/windows/x86_32/protoc.exe + windows-x86_32 + exe + + + ${basedir}/target/osx/x86_64/protoc.exe + osx-x86_64 + exe + + + ${basedir}/target/osx/aarch_64/protoc.exe + osx-aarch_64 + exe + + + ${basedir}/target/linux/aarch_64/protoc.exe + linux-aarch_64 + exe + + + ${basedir}/target/linux/ppcle_64/protoc.exe + linux-ppcle_64 + exe + + + ${basedir}/target/linux/s390_64/protoc.exe + linux-s390_64 + exe + + + + + + + + + + + release + + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.3 + true + + sonatype-nexus-staging + https://oss.sonatype.org/ + true + false + ${staging.repository} + + + + + + + diff --git a/libs/protobuf/protoc-artifacts/scl-enable-devtoolset.sh b/libs/protobuf/protoc-artifacts/scl-enable-devtoolset.sh new file mode 100755 index 0000000..3089558 --- /dev/null +++ b/libs/protobuf/protoc-artifacts/scl-enable-devtoolset.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -eu -o pipefail + +quote() { + local arg + for arg in "$@"; do + printf "'" + printf "%s" "$arg" | sed -e "s/'/'\\\\''/g" + printf "' " + done +} + +exec scl enable devtoolset-2 "$(quote "$@")" diff --git a/libs/protobuf/python/.repo-metadata.json b/libs/protobuf/python/.repo-metadata.json deleted file mode 100644 index c8d71a8..0000000 --- a/libs/protobuf/python/.repo-metadata.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "protobuf", - "name_pretty": "Protocol Buffers", - "product_documentation": "https://developers.google.com/protocol-buffers ", - "client_documentation": "https://developers.google.com/protocol-buffers/docs/pythontutorial", - "issue_tracker": "https://github.com/protocolbuffers/protobuf/issues", - "release_level": "ga", - "language": "python", - "repo": "protocolbuffers/protobuf ", - "distribution_name": "protobuf" -} diff --git a/libs/protobuf/python/BUILD.bazel b/libs/protobuf/python/BUILD.bazel deleted file mode 100644 index 56d8c8a..0000000 --- a/libs/protobuf/python/BUILD.bazel +++ /dev/null @@ -1,471 +0,0 @@ -# Protobuf Python runtime -# -# See also code generation logic under /src/google/protobuf/compiler/python. -# -# Most users should depend upon public aliases in the root: -# //:protobuf_python -# //:well_known_types_py_pb2 - -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_python//python:defs.bzl", "py_library") -load("@pip_deps//:requirements.bzl", "requirement") -load("//:protobuf.bzl", "internal_py_proto_library") -load("//build_defs:cpp_opts.bzl", "COPTS") -load("//conformance:defs.bzl", "conformance_test") -load(":internal.bzl", "internal_copy_files") - -py_library( - name = "protobuf_python", - data = select({ - "//conditions:default": [], - ":use_fast_cpp_protos": [ - ":google/protobuf/internal/_api_implementation.so", - ":google/protobuf/pyext/_message.so", - ], - }), - visibility = ["//:__pkg__"], - deps = [ - ":python_srcs", - ":well_known_types_py_pb2", - ], -) - -config_setting( - name = "use_fast_cpp_protos", - values = { - "define": "use_fast_cpp_protos=true", - }, -) - -internal_py_proto_library( - name = "well_known_types_py_pb2", - srcs = [":copied_wkt_proto_files"], - include = ".", - default_runtime = "", - protoc = "//:protoc", - srcs_version = "PY2AND3", - visibility = [ - "//:__pkg__", - "@upb//:__subpackages__", - ], -) - -internal_copy_files( - name = "copied_wkt_proto_files", - srcs = [ - "//:well_known_type_protos", - "//src/google/protobuf:descriptor_proto_srcs", - ], - strip_prefix = "src", -) - -cc_binary( - name = "google/protobuf/internal/_api_implementation.so", - srcs = ["google/protobuf/internal/api_implementation.cc"], - copts = COPTS + [ - "-DPYTHON_PROTO2_CPP_IMPL_V2", - ], - linkshared = 1, - linkstatic = 1, - tags = [ - # Exclude this target from wildcard expansion (//...) because it may - # not even be buildable. It will be built if it is needed according - # to :use_fast_cpp_protos. - # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes - "manual", - ], - deps = select({ - "//conditions:default": [], - ":use_fast_cpp_protos": ["//external:python_headers"], - }), -) - -config_setting( - name = "allow_oversize_protos", - values = { - "define": "allow_oversize_protos=true", - }, -) - -cc_binary( - name = "google/protobuf/pyext/_message.so", - srcs = glob([ - "google/protobuf/pyext/*.cc", - "google/protobuf/pyext/*.h", - ]), - copts = COPTS + [ - "-DGOOGLE_PROTOBUF_HAS_ONEOF=1", - ] + select({ - "//conditions:default": [], - ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"], - }), - includes = ["."], - linkshared = 1, - linkstatic = 1, - tags = [ - # Exclude this target from wildcard expansion (//...) because it may - # not even be buildable. It will be built if it is needed according - # to :use_fast_cpp_protos. - # https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes - "manual", - ], - deps = [ - ":proto_api", - "//:protobuf", - ] + select({ - "//conditions:default": [], - ":use_fast_cpp_protos": ["//external:python_headers"], - }), -) - -py_library( - name = "python_srcs", - srcs = glob( - [ - "google/protobuf/**/*.py", - ], - exclude = [ - "google/protobuf/internal/*_test.py", - "google/protobuf/internal/test_util.py", - "google/protobuf/internal/import_test_package/__init__.py", - ], - ), - imports = ["python"], - srcs_version = "PY2AND3", - visibility = [ - "//:__pkg__", - "@upb//:__subpackages__", - ], -) - -py_library( - name = "python_test_srcs", - srcs = glob([ - "google/protobuf/internal/*_test.py", - ]) + [ - "google/protobuf/internal/test_util.py", - "google/protobuf/internal/import_test_package/__init__.py", - ], - imports = ["python"], - srcs_version = "PY3", - visibility = [ - "//:__pkg__", - "@upb//:__subpackages__", - ], -) - -################################################################################ -# Tests -################################################################################ - -internal_copy_files( - name = "copied_test_proto_files", - testonly = 1, - srcs = [ - "//:test_proto_srcs", - "//src/google/protobuf/util:test_proto_srcs", - ], - strip_prefix = "src", -) - -internal_copy_files( - name = "copied_test_messages_proto2_files", - testonly = 1, - srcs = [ - "//src/google/protobuf:test_messages_proto2.proto", - ], - strip_prefix = "src", -) - -internal_copy_files( - name = "copied_test_messages_proto3_files", - testonly = 1, - srcs = [ - "//src/google/protobuf:test_messages_proto3.proto", - ], - strip_prefix = "src", -) - -internal_py_proto_library( - name = "python_common_test_protos", - testonly = 1, - srcs = [":copied_test_proto_files"], - include = ".", - default_runtime = "", - protoc = "//:protoc", - srcs_version = "PY2AND3", - visibility = ["//:__pkg__"], - deps = [":well_known_types_py_pb2"], -) - -internal_py_proto_library( - name = "python_specific_test_protos", - testonly = 1, - srcs = glob([ - "google/protobuf/internal/*.proto", - "google/protobuf/internal/import_test_package/*.proto", - ]), - include = ".", - default_runtime = ":protobuf_python", - protoc = "//:protoc", - srcs_version = "PY2AND3", - visibility = ["//:__pkg__"], - deps = [":python_common_test_protos"], -) - -internal_py_proto_library( - name = "test_messages_proto2_py_proto", - testonly = 1, - srcs = [":copied_test_messages_proto2_files"], - include = ".", - default_runtime = "//:protobuf_python", - protoc = "//:protoc", - visibility = [ - "//conformance:__pkg__", - "//python:__subpackages__", - ], -) - -internal_py_proto_library( - name = "test_messages_proto3_py_proto", - testonly = 1, - srcs = [":copied_test_messages_proto3_files"], - include = ".", - default_runtime = "//:protobuf_python", - protoc = "//:protoc", - visibility = [ - "//conformance:__pkg__", - "//python:__subpackages__", - ], - deps = [":well_known_types_py_pb2"], -) - -py_library( - name = "python_test_lib", - testonly = 1, - srcs = [ - "google/protobuf/internal/import_test_package/__init__.py", - "google/protobuf/internal/test_util.py", - ], - imports = ["python"], - srcs_version = "PY2AND3", - deps = [ - ":protobuf_python", - ":python_common_test_protos", - ":python_specific_test_protos", - ], -) - -py_test( - name = "descriptor_database_test", - srcs = ["google/protobuf/internal/descriptor_database_test.py"], - deps = [":python_test_lib"], -) - -py_test( - name = "descriptor_pool_test", - srcs = ["google/protobuf/internal/descriptor_pool_test.py"], - deps = [":python_test_lib"], -) - -py_test( - name = "descriptor_test", - srcs = ["google/protobuf/internal/descriptor_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "field_mask_test", - srcs = ["google/protobuf/internal/field_mask_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "generator_test", - srcs = ["google/protobuf/internal/generator_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "import_test", - srcs = ["google/protobuf/internal/import_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "json_format_test", - srcs = ["google/protobuf/internal/json_format_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "keywords_test", - srcs = ["google/protobuf/internal/keywords_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "message_factory_test", - srcs = ["google/protobuf/internal/message_factory_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "message_test", - srcs = ["google/protobuf/internal/message_test.py"], - data = glob(["testdata/golden_pickle_*"]) + [ - "//src/google/protobuf:testdata", - ], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "numpy_test", - srcs = ["google/protobuf/internal/numpy_test.py"], - imports = ["."], - deps = [ - ":python_test_lib", - requirement("numpy"), - ], -) - -py_test( - name = "proto_builder_test", - srcs = ["google/protobuf/internal/proto_builder_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "reflection_test", - srcs = ["google/protobuf/internal/reflection_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "service_reflection_test", - srcs = ["google/protobuf/internal/service_reflection_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "symbol_database_test", - srcs = ["google/protobuf/internal/symbol_database_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "text_encoding_test", - srcs = ["google/protobuf/internal/text_encoding_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "text_format_test", - srcs = ["google/protobuf/internal/text_format_test.py"], - data = ["//src/google/protobuf:testdata"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "unknown_fields_test", - srcs = ["google/protobuf/internal/unknown_fields_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "well_known_types_test", - srcs = ["google/protobuf/internal/well_known_types_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -py_test( - name = "wire_format_test", - srcs = ["google/protobuf/internal/wire_format_test.py"], - imports = ["."], - deps = [":python_test_lib"], -) - -cc_library( - name = "proto_api", - hdrs = ["google/protobuf/proto_api.h"], - visibility = ["//visibility:public"], - deps = [ - "//external:python_headers", - ], -) - -py_test( - name = "python_version", - srcs = ["python_version.py"], -) - -conformance_test( - name = "conformance_test", - env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"}, - failure_list = "//conformance:failure_list_python.txt", - target_compatible_with = select({ - ":use_fast_cpp_protos": ["@platforms//:incompatible"], - "//conditions:default": [], - }), - testee = "//conformance:conformance_python", - text_format_failure_list = "//conformance:text_format_failure_list_python.txt", -) - -# Note: this requires --define=use_fast_cpp_protos=true -conformance_test( - name = "conformance_test_cpp", - env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"}, - failure_list = "//conformance:failure_list_python.txt", - target_compatible_with = select({ - ":use_fast_cpp_protos": [], - "//conditions:default": ["@platforms//:incompatible"], - }), - testee = "//conformance:conformance_python", - text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt", -) - -################################################################################ -# Distribution files -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob([ - "google/**/*.proto", - "google/**/*.py", - "google/protobuf/internal/*.cc", - "google/protobuf/pyext/*.cc", - "google/protobuf/pyext/*.h", - ]) + [ - "BUILD.bazel", - "MANIFEST.in", - "README.md", - "google/protobuf/proto_api.h", - "google/protobuf/pyext/README", - "google/protobuf/python_protobuf.h", - "internal.bzl", - "python_version.py", - "release.sh", - "setup.cfg", - "setup.py", - "tox.ini", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/python/README.md b/libs/protobuf/python/README.md index 6549fb6..27f22c8 100644 --- a/libs/protobuf/python/README.md +++ b/libs/protobuf/python/README.md @@ -30,33 +30,33 @@ Installation $ python -V -2) Make sure you have Bazel 0.5.4 or later (or CMake 3.5 or later). - -3) If you do not have setuptools installed, note that it will be +2) If you do not have setuptools installed, note that it will be downloaded and installed automatically as soon as you run `setup.py`. If you would rather install it manually, you may do so by following - the instructions on [this page](https://packaging.python.org/en/latest/tutorials/installing-packages/). + the instructions on [this page](https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages). -4) Build the C++ code, or install a binary distribution of `protoc`. If +3) Build the C++ code, or install a binary distribution of `protoc`. If you install a binary distribution, make sure that it is the same version as this package. If in doubt, run: $ protoc --version -5) Build and run the tests: +4) Build and run the tests: $ python setup.py build $ python setup.py test To build, test, and use the C++ implementation, you must first compile - `libprotobuf.so` using either [Bazel](../README.md) or [CMake](../src/README.md): + `libprotobuf.so`: + + $ (cd .. && make) On OS X: If you are running a Homebrew-provided Python, you must make sure another version of protobuf is not already installed, as Homebrew's Python will - search `/usr/local/lib` for `libprotobuf.so` before it searches the compiled - binaries. + search `/usr/local/lib` for `libprotobuf.so` before it searches + `../src/.libs`. You can either unlink Homebrew's protobuf or install the `libprotobuf` you built earlier: @@ -65,18 +65,18 @@ Installation or - $ (cd .. && cmake . && make install) + $ (cd .. && make install) On other *nix: You must make `libprotobuf.so` dynamically available. You can either install libprotobuf you built earlier, or set `LD_LIBRARY_PATH`: - $ (cd .. && cmake . && make -j20 install) + $ export LD_LIBRARY_PATH=../src/.libs or - $ export LD_LIBRARY_PATH=../bazel-bin + $ (cd .. && make install) To build the C++ implementation run: @@ -98,7 +98,7 @@ Installation We do not know if or when it might be fixed. We also do not know how likely it is that this bug will affect users in practice. -6) Install: +5) Install: $ python setup.py install diff --git a/libs/protobuf/python/docs/google/protobuf.rst b/libs/protobuf/python/docs/google/protobuf.rst index 6c472e1..b26102e 100644 --- a/libs/protobuf/python/docs/google/protobuf.rst +++ b/libs/protobuf/python/docs/google/protobuf.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/any_pb2.rst b/libs/protobuf/python/docs/google/protobuf/any_pb2.rst index 9fca2d2..b6f47ef 100644 --- a/libs/protobuf/python/docs/google/protobuf/any_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/any_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/descriptor.rst b/libs/protobuf/python/docs/google/protobuf/descriptor.rst index 5a8a264..29b0774 100644 --- a/libs/protobuf/python/docs/google/protobuf/descriptor.rst +++ b/libs/protobuf/python/docs/google/protobuf/descriptor.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/descriptor_database.rst b/libs/protobuf/python/docs/google/protobuf/descriptor_database.rst index 660fc41..1b8b390 100644 --- a/libs/protobuf/python/docs/google/protobuf/descriptor_database.rst +++ b/libs/protobuf/python/docs/google/protobuf/descriptor_database.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/descriptor_pb2.rst b/libs/protobuf/python/docs/google/protobuf/descriptor_pb2.rst index 9f20f49..94eec35 100644 --- a/libs/protobuf/python/docs/google/protobuf/descriptor_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/descriptor_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/descriptor_pool.rst b/libs/protobuf/python/docs/google/protobuf/descriptor_pool.rst index aa8de30..c2ee33e 100644 --- a/libs/protobuf/python/docs/google/protobuf/descriptor_pool.rst +++ b/libs/protobuf/python/docs/google/protobuf/descriptor_pool.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/duration_pb2.rst b/libs/protobuf/python/docs/google/protobuf/duration_pb2.rst index 9e9a032..4233e3c 100644 --- a/libs/protobuf/python/docs/google/protobuf/duration_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/duration_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/empty_pb2.rst b/libs/protobuf/python/docs/google/protobuf/empty_pb2.rst index f117553..c386a4c 100644 --- a/libs/protobuf/python/docs/google/protobuf/empty_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/empty_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/field_mask_pb2.rst b/libs/protobuf/python/docs/google/protobuf/field_mask_pb2.rst index 1c11f46..d9d8070 100644 --- a/libs/protobuf/python/docs/google/protobuf/field_mask_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/field_mask_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/internal/containers.rst b/libs/protobuf/python/docs/google/protobuf/internal/containers.rst index 67009bc..c3b8e59 100644 --- a/libs/protobuf/python/docs/google/protobuf/internal/containers.rst +++ b/libs/protobuf/python/docs/google/protobuf/internal/containers.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/json_format.rst b/libs/protobuf/python/docs/google/protobuf/json_format.rst index 71023fc..eb3b0c5 100644 --- a/libs/protobuf/python/docs/google/protobuf/json_format.rst +++ b/libs/protobuf/python/docs/google/protobuf/json_format.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/message.rst b/libs/protobuf/python/docs/google/protobuf/message.rst index c33561f..a204248 100644 --- a/libs/protobuf/python/docs/google/protobuf/message.rst +++ b/libs/protobuf/python/docs/google/protobuf/message.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/message_factory.rst b/libs/protobuf/python/docs/google/protobuf/message_factory.rst index 19f6623..93183cc 100644 --- a/libs/protobuf/python/docs/google/protobuf/message_factory.rst +++ b/libs/protobuf/python/docs/google/protobuf/message_factory.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/proto_builder.rst b/libs/protobuf/python/docs/google/protobuf/proto_builder.rst index 718f612..36243a2 100644 --- a/libs/protobuf/python/docs/google/protobuf/proto_builder.rst +++ b/libs/protobuf/python/docs/google/protobuf/proto_builder.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/reflection.rst b/libs/protobuf/python/docs/google/protobuf/reflection.rst index c806834..d177fc0 100644 --- a/libs/protobuf/python/docs/google/protobuf/reflection.rst +++ b/libs/protobuf/python/docs/google/protobuf/reflection.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/service.rst b/libs/protobuf/python/docs/google/protobuf/service.rst index ddc427f..6d71f81 100644 --- a/libs/protobuf/python/docs/google/protobuf/service.rst +++ b/libs/protobuf/python/docs/google/protobuf/service.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/service_reflection.rst b/libs/protobuf/python/docs/google/protobuf/service_reflection.rst index f088c17..30f30dd 100644 --- a/libs/protobuf/python/docs/google/protobuf/service_reflection.rst +++ b/libs/protobuf/python/docs/google/protobuf/service_reflection.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/struct_pb2.rst b/libs/protobuf/python/docs/google/protobuf/struct_pb2.rst index 7b25487..9179eed 100644 --- a/libs/protobuf/python/docs/google/protobuf/struct_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/struct_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/symbol_database.rst b/libs/protobuf/python/docs/google/protobuf/symbol_database.rst index 99a8c10..6ea7352 100644 --- a/libs/protobuf/python/docs/google/protobuf/symbol_database.rst +++ b/libs/protobuf/python/docs/google/protobuf/symbol_database.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/text_encoding.rst b/libs/protobuf/python/docs/google/protobuf/text_encoding.rst index 5a070e5..a2eb959 100644 --- a/libs/protobuf/python/docs/google/protobuf/text_encoding.rst +++ b/libs/protobuf/python/docs/google/protobuf/text_encoding.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/text_format.rst b/libs/protobuf/python/docs/google/protobuf/text_format.rst index 5c2c346..686b8fc 100644 --- a/libs/protobuf/python/docs/google/protobuf/text_format.rst +++ b/libs/protobuf/python/docs/google/protobuf/text_format.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/timestamp_pb2.rst b/libs/protobuf/python/docs/google/protobuf/timestamp_pb2.rst index 62e4708..540df83 100644 --- a/libs/protobuf/python/docs/google/protobuf/timestamp_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/timestamp_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/type_pb2.rst b/libs/protobuf/python/docs/google/protobuf/type_pb2.rst index cbd4150..e9b19d7 100644 --- a/libs/protobuf/python/docs/google/protobuf/type_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/type_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/google/protobuf/unknown_fields.rst b/libs/protobuf/python/docs/google/protobuf/unknown_fields.rst deleted file mode 100644 index 7ba283d..0000000 --- a/libs/protobuf/python/docs/google/protobuf/unknown_fields.rst +++ /dev/null @@ -1,21 +0,0 @@ -.. DO NOT EDIT, generated by generate_docs.py. - -.. ifconfig:: build_env == 'readthedocs' - - .. warning:: - - You are reading the documentation for the `latest committed changes - `_ of - the `Protocol Buffers package for Python - `_. - Some features may not yet be released. Read the documentation for the - latest released package at `googleapis.dev - `_. - -google.protobuf.unknown_fields -============================== - -.. automodule:: google.protobuf.unknown_fields - :members: - :inherited-members: - :undoc-members: diff --git a/libs/protobuf/python/docs/google/protobuf/wrappers_pb2.rst b/libs/protobuf/python/docs/google/protobuf/wrappers_pb2.rst index 64f9cbb..8f29aa7 100644 --- a/libs/protobuf/python/docs/google/protobuf/wrappers_pb2.rst +++ b/libs/protobuf/python/docs/google/protobuf/wrappers_pb2.rst @@ -5,7 +5,7 @@ .. warning:: You are reading the documentation for the `latest committed changes - `_ of + `_ of the `Protocol Buffers package for Python `_. Some features may not yet be released. Read the documentation for the diff --git a/libs/protobuf/python/docs/index.rst b/libs/protobuf/python/docs/index.rst index 544b18e..5535b39 100644 --- a/libs/protobuf/python/docs/index.rst +++ b/libs/protobuf/python/docs/index.rst @@ -52,7 +52,6 @@ Modules and Packages google/protobuf/text_format google/protobuf/timestamp_pb2 google/protobuf/type_pb2 - google/protobuf/unknown_fields google/protobuf/wrappers_pb2 .. END REFTOC. diff --git a/libs/protobuf/python/google/protobuf/__init__.py b/libs/protobuf/python/google/protobuf/__init__.py index 6b0df47..e7555ee 100644 --- a/libs/protobuf/python/google/protobuf/__init__.py +++ b/libs/protobuf/python/google/protobuf/__init__.py @@ -30,4 +30,4 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '4.21.8' +__version__ = '4.21.12' diff --git a/libs/protobuf/python/google/protobuf/descriptor.py b/libs/protobuf/python/google/protobuf/descriptor.py index 997f6db..f5a0caa 100644 --- a/libs/protobuf/python/google/protobuf/descriptor.py +++ b/libs/protobuf/python/google/protobuf/descriptor.py @@ -873,14 +873,11 @@ class ServiceDescriptor(_NestedDescriptorBase): Args: name (str): Name of the method. - Returns: - MethodDescriptor: The descriptor for the requested method. - - Raises: - KeyError: if the method cannot be found in the service. + MethodDescriptor or None: the descriptor for the requested method, if + found. """ - return self.methods_by_name[name] + return self.methods_by_name.get(name, None) def CopyToProto(self, proto): """Copies this to a descriptor_pb2.ServiceDescriptorProto. @@ -1021,7 +1018,13 @@ class FileDescriptor(DescriptorBase): # FileDescriptor() is called from various places, not only from generated # files, to register dynamic proto files and messages. # pylint: disable=g-explicit-bool-comparison - if serialized_pb: + if serialized_pb == b'': + # Cpp generated code must be linked in if serialized_pb is '' + try: + return _message.default_pool.FindFileByName(name) + except KeyError: + raise RuntimeError('Please link in cpp generated lib for %s' % (name)) + elif serialized_pb: return _message.default_pool.AddSerializedFile(serialized_pb) else: return super(FileDescriptor, cls).__new__(cls) diff --git a/libs/protobuf/python/google/protobuf/descriptor_pool.py b/libs/protobuf/python/google/protobuf/descriptor_pool.py index dccac5e..911372a 100644 --- a/libs/protobuf/python/google/protobuf/descriptor_pool.py +++ b/libs/protobuf/python/google/protobuf/descriptor_pool.py @@ -144,6 +144,9 @@ class DescriptorPool(object): self._service_descriptors = {} self._file_descriptors = {} self._toplevel_extensions = {} + # TODO(jieluo): Remove _file_desc_by_toplevel_extension after + # maybe year 2020 for compatibility issue (with 3.4.1 only). + self._file_desc_by_toplevel_extension = {} self._top_enum_values = {} # We store extensions in two two-level mappings: The first key is the # descriptor of the message being extended, the second key is the extension @@ -217,7 +220,7 @@ class DescriptorPool(object): file_desc.serialized_pb = serialized_file_desc_proto return file_desc - # Add Descriptor to descriptor pool is deprecated. Please use Add() + # Add Descriptor to descriptor pool is dreprecated. Please use Add() # or AddSerializedFile() to add a FileDescriptorProto instead. @_Deprecated def AddDescriptor(self, desc): @@ -242,7 +245,7 @@ class DescriptorPool(object): self._descriptors[desc.full_name] = desc self._AddFileDescriptor(desc.file) - # Add EnumDescriptor to descriptor pool is deprecated. Please use Add() + # Add EnumDescriptor to descriptor pool is dreprecated. Please use Add() # or AddSerializedFile() to add a FileDescriptorProto instead. @_Deprecated def AddEnumDescriptor(self, enum_desc): @@ -283,7 +286,7 @@ class DescriptorPool(object): self._top_enum_values[full_name] = enum_value self._AddFileDescriptor(enum_desc.file) - # Add ServiceDescriptor to descriptor pool is deprecated. Please use Add() + # Add ServiceDescriptor to descriptor pool is dreprecated. Please use Add() # or AddSerializedFile() to add a FileDescriptorProto instead. @_Deprecated def AddServiceDescriptor(self, service_desc): @@ -304,7 +307,7 @@ class DescriptorPool(object): service_desc.file.name) self._service_descriptors[service_desc.full_name] = service_desc - # Add ExtensionDescriptor to descriptor pool is deprecated. Please use Add() + # Add ExtensionDescriptor to descriptor pool is dreprecated. Please use Add() # or AddSerializedFile() to add a FileDescriptorProto instead. @_Deprecated def AddExtensionDescriptor(self, extension): @@ -328,8 +331,6 @@ class DescriptorPool(object): raise TypeError('Expected an extension descriptor.') if extension.extension_scope is None: - self._CheckConflictRegister( - extension, extension.full_name, extension.file.name) self._toplevel_extensions[extension.full_name] = extension try: @@ -371,6 +372,12 @@ class DescriptorPool(object): """ self._AddFileDescriptor(file_desc) + # TODO(jieluo): This is a temporary solution for FieldDescriptor.file. + # FieldDescriptor.file is added in code gen. Remove this solution after + # maybe 2020 for compatibility reason (with 3.4.1 only). + for extension in file_desc.extensions_by_name.values(): + self._file_desc_by_toplevel_extension[ + extension.full_name] = file_desc def _AddFileDescriptor(self, file_desc): """Adds a FileDescriptor to the pool, non-recursively. @@ -476,7 +483,7 @@ class DescriptorPool(object): pass try: - return self._toplevel_extensions[symbol].file + return self._file_desc_by_toplevel_extension[symbol] except KeyError: pass @@ -785,6 +792,8 @@ class DescriptorPool(object): file_descriptor.package, scope) file_descriptor.extensions_by_name[extension_desc.name] = ( extension_desc) + self._file_desc_by_toplevel_extension[extension_desc.full_name] = ( + file_descriptor) for desc_proto in file_proto.message_type: self._SetAllFieldTypes(file_proto.package, desc_proto, scope) diff --git a/libs/protobuf/python/google/protobuf/internal/api_implementation.py b/libs/protobuf/python/google/protobuf/internal/api_implementation.py index 3b81f27..7458648 100644 --- a/libs/protobuf/python/google/protobuf/internal/api_implementation.py +++ b/libs/protobuf/python/google/protobuf/internal/api_implementation.py @@ -151,6 +151,12 @@ def Type(): return _implementation_type +def _SetType(implementation_type): + """Never use! Only for protobuf benchmark.""" + global _implementation_type + _implementation_type = implementation_type + + # See comment on 'Type' above. # TODO(jieluo): Remove the API, it returns a constant. b/228102101 def Version(): diff --git a/libs/protobuf/python/google/protobuf/internal/descriptor_pool_test.py b/libs/protobuf/python/google/protobuf/internal/descriptor_pool_test.py index 2916453..9e451b4 100644 --- a/libs/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +++ b/libs/protobuf/python/google/protobuf/internal/descriptor_pool_test.py @@ -33,6 +33,7 @@ __author__ = 'matthewtoia@google.com (Matt Toia)' import copy +import os import unittest import warnings @@ -414,19 +415,6 @@ class DescriptorPoolTestBase(object): field = file_json.message_types_by_name['class'].fields_by_name['int_field'] self.assertEqual(field.json_name, 'json_int') - def testAddSerializedFileTwice(self): - if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() != 'python': - # Cpp extension cannot call Add on a DescriptorPool - # that uses a DescriptorDatabase. - # TODO(jieluo): Fix python and cpp extension diff. - return - self.pool = descriptor_pool.DescriptorPool() - file1_first = self.pool.AddSerializedFile( - self.factory_test1_fd.SerializeToString()) - file1_again = self.pool.AddSerializedFile( - self.factory_test1_fd.SerializeToString()) - self.assertIs(file1_first, file1_again) def testEnumDefaultValue(self): """Test the default value of enums which don't start at zero.""" diff --git a/libs/protobuf/python/google/protobuf/internal/descriptor_test.py b/libs/protobuf/python/google/protobuf/internal/descriptor_test.py index 3af2bdc..6a8532c 100644 --- a/libs/protobuf/python/google/protobuf/internal/descriptor_test.py +++ b/libs/protobuf/python/google/protobuf/internal/descriptor_test.py @@ -118,30 +118,6 @@ class DescriptorTest(unittest.TestCase): def GetDescriptorPool(self): return symbol_database.Default().pool - def testMissingPackage(self): - file_proto = descriptor_pb2.FileDescriptorProto( - name='some/filename/some.proto') - serialized = file_proto.SerializeToString() - pool = descriptor_pool.DescriptorPool() - file_descriptor = pool.AddSerializedFile(serialized) - self.assertEqual('', file_descriptor.package) - - def testEmptyPackage(self): - file_proto = descriptor_pb2.FileDescriptorProto( - name='some/filename/some.proto', package='') - serialized = file_proto.SerializeToString() - pool = descriptor_pool.DescriptorPool() - file_descriptor = pool.AddSerializedFile(serialized) - self.assertEqual('', file_descriptor.package) - - def testFindMethodByName(self): - service_descriptor = (unittest_custom_options_pb2. - TestServiceWithCustomOptions.DESCRIPTOR) - method_descriptor = service_descriptor.FindMethodByName('Foo') - self.assertEqual(method_descriptor.name, 'Foo') - with self.assertRaises(KeyError): - service_descriptor.FindMethodByName('MethodDoesNotExist') - def testEnumValueName(self): self.assertEqual(self.my_message.EnumValueName('ForeignEnum', 4), 'FOREIGN_FOO') @@ -619,12 +595,6 @@ class GeneratedDescriptorTest(unittest.TestCase): def CheckDescriptorMapping(self, mapping): # Verifies that a property like 'messageDescriptor.fields' has all the # properties of an immutable abc.Mapping. - iterated_keys = [] - for key in mapping: - iterated_keys.append(key) - self.assertEqual(len(iterated_keys), len(mapping)) - self.assertEqual(set(iterated_keys), set(mapping.keys())) - self.assertNotEqual( mapping, unittest_pb2.TestAllExtensions.DESCRIPTOR.fields_by_name) self.assertNotEqual(mapping, {}) @@ -641,15 +611,10 @@ class GeneratedDescriptorTest(unittest.TestCase): with self.assertRaises(TypeError): mapping.get() # TODO(jieluo): Fix python and cpp extension diff. - if api_implementation.Type() == 'cpp': - self.assertEqual(None, mapping.get([])) - else: + if api_implementation.Type() == 'python': self.assertRaises(TypeError, mapping.get, []) - with self.assertRaises(TypeError): - if [] in mapping: - pass - with self.assertRaises(TypeError): - _ = mapping[[]] + else: + self.assertEqual(None, mapping.get([])) # keys(), iterkeys() &co item = (next(iter(mapping.keys())), next(iter(mapping.values()))) self.assertEqual(item, next(iter(mapping.items()))) @@ -661,12 +626,10 @@ class GeneratedDescriptorTest(unittest.TestCase): self.assertRaises(KeyError, mapping.__getitem__, 'key_error') self.assertRaises(KeyError, mapping.__getitem__, len(mapping) + 1) # TODO(jieluo): Add __repr__ support for DescriptorMapping. - if api_implementation.Type() == 'cpp': - self.assertEqual(str(mapping)[0], '<') - else: - print(str(dict(mapping.items()))[:100]) - print(str(mapping)[:100]) + if api_implementation.Type() == 'python': self.assertEqual(len(str(dict(mapping.items()))), len(str(mapping))) + else: + self.assertEqual(str(mapping)[0], '<') def testDescriptor(self): message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR diff --git a/libs/protobuf/python/google/protobuf/internal/field_mask.py b/libs/protobuf/python/google/protobuf/internal/field_mask.py deleted file mode 100644 index 4897699..0000000 --- a/libs/protobuf/python/google/protobuf/internal/field_mask.py +++ /dev/null @@ -1,333 +0,0 @@ -# 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. - -"""Contains FieldMask class.""" - -from google.protobuf.descriptor import FieldDescriptor - - -class FieldMask(object): - """Class for FieldMask message type.""" - - __slots__ = () - - def ToJsonString(self): - """Converts FieldMask to string according to proto3 JSON spec.""" - camelcase_paths = [] - for path in self.paths: - camelcase_paths.append(_SnakeCaseToCamelCase(path)) - return ','.join(camelcase_paths) - - def FromJsonString(self, value): - """Converts string to FieldMask according to proto3 JSON spec.""" - if not isinstance(value, str): - raise ValueError('FieldMask JSON value not a string: {!r}'.format(value)) - self.Clear() - if value: - for path in value.split(','): - self.paths.append(_CamelCaseToSnakeCase(path)) - - def IsValidForDescriptor(self, message_descriptor): - """Checks whether the FieldMask is valid for Message Descriptor.""" - for path in self.paths: - if not _IsValidPath(message_descriptor, path): - return False - return True - - def AllFieldsFromDescriptor(self, message_descriptor): - """Gets all direct fields of Message Descriptor to FieldMask.""" - self.Clear() - for field in message_descriptor.fields: - self.paths.append(field.name) - - def CanonicalFormFromMask(self, mask): - """Converts a FieldMask to the canonical form. - - Removes paths that are covered by another path. For example, - "foo.bar" is covered by "foo" and will be removed if "foo" - is also in the FieldMask. Then sorts all paths in alphabetical order. - - Args: - mask: The original FieldMask to be converted. - """ - tree = _FieldMaskTree(mask) - tree.ToFieldMask(self) - - def Union(self, mask1, mask2): - """Merges mask1 and mask2 into this FieldMask.""" - _CheckFieldMaskMessage(mask1) - _CheckFieldMaskMessage(mask2) - tree = _FieldMaskTree(mask1) - tree.MergeFromFieldMask(mask2) - tree.ToFieldMask(self) - - def Intersect(self, mask1, mask2): - """Intersects mask1 and mask2 into this FieldMask.""" - _CheckFieldMaskMessage(mask1) - _CheckFieldMaskMessage(mask2) - tree = _FieldMaskTree(mask1) - intersection = _FieldMaskTree() - for path in mask2.paths: - tree.IntersectPath(path, intersection) - intersection.ToFieldMask(self) - - def MergeMessage( - self, source, destination, - replace_message_field=False, replace_repeated_field=False): - """Merges fields specified in FieldMask from source to destination. - - Args: - source: Source message. - destination: The destination message to be merged into. - replace_message_field: Replace message field if True. Merge message - field if False. - replace_repeated_field: Replace repeated field if True. Append - elements of repeated field if False. - """ - tree = _FieldMaskTree(self) - tree.MergeMessage( - source, destination, replace_message_field, replace_repeated_field) - - -def _IsValidPath(message_descriptor, path): - """Checks whether the path is valid for Message Descriptor.""" - parts = path.split('.') - last = parts.pop() - for name in parts: - field = message_descriptor.fields_by_name.get(name) - if (field is None or - field.label == FieldDescriptor.LABEL_REPEATED or - field.type != FieldDescriptor.TYPE_MESSAGE): - return False - message_descriptor = field.message_type - return last in message_descriptor.fields_by_name - - -def _CheckFieldMaskMessage(message): - """Raises ValueError if message is not a FieldMask.""" - message_descriptor = message.DESCRIPTOR - if (message_descriptor.name != 'FieldMask' or - message_descriptor.file.name != 'google/protobuf/field_mask.proto'): - raise ValueError('Message {0} is not a FieldMask.'.format( - message_descriptor.full_name)) - - -def _SnakeCaseToCamelCase(path_name): - """Converts a path name from snake_case to camelCase.""" - result = [] - after_underscore = False - for c in path_name: - if c.isupper(): - raise ValueError( - 'Fail to print FieldMask to Json string: Path name ' - '{0} must not contain uppercase letters.'.format(path_name)) - if after_underscore: - if c.islower(): - result.append(c.upper()) - after_underscore = False - else: - raise ValueError( - 'Fail to print FieldMask to Json string: The ' - 'character after a "_" must be a lowercase letter ' - 'in path name {0}.'.format(path_name)) - elif c == '_': - after_underscore = True - else: - result += c - - if after_underscore: - raise ValueError('Fail to print FieldMask to Json string: Trailing "_" ' - 'in path name {0}.'.format(path_name)) - return ''.join(result) - - -def _CamelCaseToSnakeCase(path_name): - """Converts a field name from camelCase to snake_case.""" - result = [] - for c in path_name: - if c == '_': - raise ValueError('Fail to parse FieldMask: Path name ' - '{0} must not contain "_"s.'.format(path_name)) - if c.isupper(): - result += '_' - result += c.lower() - else: - result += c - return ''.join(result) - - -class _FieldMaskTree(object): - """Represents a FieldMask in a tree structure. - - For example, given a FieldMask "foo.bar,foo.baz,bar.baz", - the FieldMaskTree will be: - [_root] -+- foo -+- bar - | | - | +- baz - | - +- bar --- baz - In the tree, each leaf node represents a field path. - """ - - __slots__ = ('_root',) - - def __init__(self, field_mask=None): - """Initializes the tree by FieldMask.""" - self._root = {} - if field_mask: - self.MergeFromFieldMask(field_mask) - - def MergeFromFieldMask(self, field_mask): - """Merges a FieldMask to the tree.""" - for path in field_mask.paths: - self.AddPath(path) - - def AddPath(self, path): - """Adds a field path into the tree. - - If the field path to add is a sub-path of an existing field path - in the tree (i.e., a leaf node), it means the tree already matches - the given path so nothing will be added to the tree. If the path - matches an existing non-leaf node in the tree, that non-leaf node - will be turned into a leaf node with all its children removed because - the path matches all the node's children. Otherwise, a new path will - be added. - - Args: - path: The field path to add. - """ - node = self._root - for name in path.split('.'): - if name not in node: - node[name] = {} - elif not node[name]: - # Pre-existing empty node implies we already have this entire tree. - return - node = node[name] - # Remove any sub-trees we might have had. - node.clear() - - def ToFieldMask(self, field_mask): - """Converts the tree to a FieldMask.""" - field_mask.Clear() - _AddFieldPaths(self._root, '', field_mask) - - def IntersectPath(self, path, intersection): - """Calculates the intersection part of a field path with this tree. - - Args: - path: The field path to calculates. - intersection: The out tree to record the intersection part. - """ - node = self._root - for name in path.split('.'): - if name not in node: - return - elif not node[name]: - intersection.AddPath(path) - return - node = node[name] - intersection.AddLeafNodes(path, node) - - def AddLeafNodes(self, prefix, node): - """Adds leaf nodes begin with prefix to this tree.""" - if not node: - self.AddPath(prefix) - for name in node: - child_path = prefix + '.' + name - self.AddLeafNodes(child_path, node[name]) - - def MergeMessage( - self, source, destination, - replace_message, replace_repeated): - """Merge all fields specified by this tree from source to destination.""" - _MergeMessage( - self._root, source, destination, replace_message, replace_repeated) - - -def _StrConvert(value): - """Converts value to str if it is not.""" - # This file is imported by c extension and some methods like ClearField - # requires string for the field name. py2/py3 has different text - # type and may use unicode. - if not isinstance(value, str): - return value.encode('utf-8') - return value - - -def _MergeMessage( - node, source, destination, replace_message, replace_repeated): - """Merge all fields specified by a sub-tree from source to destination.""" - source_descriptor = source.DESCRIPTOR - for name in node: - child = node[name] - field = source_descriptor.fields_by_name[name] - if field is None: - raise ValueError('Error: Can\'t find field {0} in message {1}.'.format( - name, source_descriptor.full_name)) - if child: - # Sub-paths are only allowed for singular message fields. - if (field.label == FieldDescriptor.LABEL_REPEATED or - field.cpp_type != FieldDescriptor.CPPTYPE_MESSAGE): - raise ValueError('Error: Field {0} in message {1} is not a singular ' - 'message field and cannot have sub-fields.'.format( - name, source_descriptor.full_name)) - if source.HasField(name): - _MergeMessage( - child, getattr(source, name), getattr(destination, name), - replace_message, replace_repeated) - continue - if field.label == FieldDescriptor.LABEL_REPEATED: - if replace_repeated: - destination.ClearField(_StrConvert(name)) - repeated_source = getattr(source, name) - repeated_destination = getattr(destination, name) - repeated_destination.MergeFrom(repeated_source) - else: - if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE: - if replace_message: - destination.ClearField(_StrConvert(name)) - if source.HasField(name): - getattr(destination, name).MergeFrom(getattr(source, name)) - else: - setattr(destination, name, getattr(source, name)) - - -def _AddFieldPaths(node, prefix, field_mask): - """Adds the field paths descended from node to field_mask.""" - if not node and prefix: - field_mask.paths.append(prefix) - return - for name in sorted(node): - if prefix: - child_path = prefix + '.' + name - else: - child_path = name - _AddFieldPaths(node[name], child_path, field_mask) diff --git a/libs/protobuf/python/google/protobuf/internal/field_mask_test.py b/libs/protobuf/python/google/protobuf/internal/field_mask_test.py deleted file mode 100644 index 8266418..0000000 --- a/libs/protobuf/python/google/protobuf/internal/field_mask_test.py +++ /dev/null @@ -1,400 +0,0 @@ -# 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. - -"""Test for google.protobuf.internal.well_known_types.""" - -import unittest - -from google.protobuf import field_mask_pb2 -from google.protobuf import map_unittest_pb2 -from google.protobuf import unittest_pb2 -from google.protobuf.internal import field_mask -from google.protobuf.internal import test_util -from google.protobuf import descriptor - - -class FieldMaskTest(unittest.TestCase): - - def testStringFormat(self): - mask = field_mask_pb2.FieldMask() - self.assertEqual('', mask.ToJsonString()) - mask.paths.append('foo') - self.assertEqual('foo', mask.ToJsonString()) - mask.paths.append('bar') - self.assertEqual('foo,bar', mask.ToJsonString()) - - mask.FromJsonString('') - self.assertEqual('', mask.ToJsonString()) - mask.FromJsonString('foo') - self.assertEqual(['foo'], mask.paths) - mask.FromJsonString('foo,bar') - self.assertEqual(['foo', 'bar'], mask.paths) - - # Test camel case - mask.Clear() - mask.paths.append('foo_bar') - self.assertEqual('fooBar', mask.ToJsonString()) - mask.paths.append('bar_quz') - self.assertEqual('fooBar,barQuz', mask.ToJsonString()) - - mask.FromJsonString('') - self.assertEqual('', mask.ToJsonString()) - self.assertEqual([], mask.paths) - mask.FromJsonString('fooBar') - self.assertEqual(['foo_bar'], mask.paths) - mask.FromJsonString('fooBar,barQuz') - self.assertEqual(['foo_bar', 'bar_quz'], mask.paths) - - def testDescriptorToFieldMask(self): - mask = field_mask_pb2.FieldMask() - msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR - mask.AllFieldsFromDescriptor(msg_descriptor) - self.assertEqual(76, len(mask.paths)) - self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) - for field in msg_descriptor.fields: - self.assertTrue(field.name in mask.paths) - - def testIsValidForDescriptor(self): - msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR - # Empty mask - mask = field_mask_pb2.FieldMask() - self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) - # All fields from descriptor - mask.AllFieldsFromDescriptor(msg_descriptor) - self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) - # Child under optional message - mask.paths.append('optional_nested_message.bb') - self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) - # Repeated field is only allowed in the last position of path - mask.paths.append('repeated_nested_message.bb') - self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) - # Invalid top level field - mask = field_mask_pb2.FieldMask() - mask.paths.append('xxx') - self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) - # Invalid field in root - mask = field_mask_pb2.FieldMask() - mask.paths.append('xxx.zzz') - self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) - # Invalid field in internal node - mask = field_mask_pb2.FieldMask() - mask.paths.append('optional_nested_message.xxx.zzz') - self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) - # Invalid field in leaf - mask = field_mask_pb2.FieldMask() - mask.paths.append('optional_nested_message.xxx') - self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) - - def testCanonicalFrom(self): - mask = field_mask_pb2.FieldMask() - out_mask = field_mask_pb2.FieldMask() - # Paths will be sorted. - mask.FromJsonString('baz.quz,bar,foo') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('bar,baz.quz,foo', out_mask.ToJsonString()) - # Duplicated paths will be removed. - mask.FromJsonString('foo,bar,foo') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('bar,foo', out_mask.ToJsonString()) - # Sub-paths of other paths will be removed. - mask.FromJsonString('foo.b1,bar.b1,foo.b2,bar') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('bar,foo.b1,foo.b2', out_mask.ToJsonString()) - - # Test more deeply nested cases. - mask.FromJsonString( - 'foo.bar.baz1,foo.bar.baz2.quz,foo.bar.baz2') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('foo.bar.baz1,foo.bar.baz2', - out_mask.ToJsonString()) - mask.FromJsonString( - 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('foo.bar.baz1,foo.bar.baz2', - out_mask.ToJsonString()) - mask.FromJsonString( - 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo.bar') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('foo.bar', out_mask.ToJsonString()) - mask.FromJsonString( - 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo') - out_mask.CanonicalFormFromMask(mask) - self.assertEqual('foo', out_mask.ToJsonString()) - - def testUnion(self): - mask1 = field_mask_pb2.FieldMask() - mask2 = field_mask_pb2.FieldMask() - out_mask = field_mask_pb2.FieldMask() - mask1.FromJsonString('foo,baz') - mask2.FromJsonString('bar,quz') - out_mask.Union(mask1, mask2) - self.assertEqual('bar,baz,foo,quz', out_mask.ToJsonString()) - # Overlap with duplicated paths. - mask1.FromJsonString('foo,baz.bb') - mask2.FromJsonString('baz.bb,quz') - out_mask.Union(mask1, mask2) - self.assertEqual('baz.bb,foo,quz', out_mask.ToJsonString()) - # Overlap with paths covering some other paths. - mask1.FromJsonString('foo.bar.baz,quz') - mask2.FromJsonString('foo.bar,bar') - out_mask.Union(mask1, mask2) - self.assertEqual('bar,foo.bar,quz', out_mask.ToJsonString()) - src = unittest_pb2.TestAllTypes() - with self.assertRaises(ValueError): - out_mask.Union(src, mask2) - - def testIntersect(self): - mask1 = field_mask_pb2.FieldMask() - mask2 = field_mask_pb2.FieldMask() - out_mask = field_mask_pb2.FieldMask() - # Test cases without overlapping. - mask1.FromJsonString('foo,baz') - mask2.FromJsonString('bar,quz') - out_mask.Intersect(mask1, mask2) - self.assertEqual('', out_mask.ToJsonString()) - self.assertEqual(len(out_mask.paths), 0) - self.assertEqual(out_mask.paths, []) - # Overlap with duplicated paths. - mask1.FromJsonString('foo,baz.bb') - mask2.FromJsonString('baz.bb,quz') - out_mask.Intersect(mask1, mask2) - self.assertEqual('baz.bb', out_mask.ToJsonString()) - # Overlap with paths covering some other paths. - mask1.FromJsonString('foo.bar.baz,quz') - mask2.FromJsonString('foo.bar,bar') - out_mask.Intersect(mask1, mask2) - self.assertEqual('foo.bar.baz', out_mask.ToJsonString()) - mask1.FromJsonString('foo.bar,bar') - mask2.FromJsonString('foo.bar.baz,quz') - out_mask.Intersect(mask1, mask2) - self.assertEqual('foo.bar.baz', out_mask.ToJsonString()) - # Intersect '' with '' - mask1.Clear() - mask2.Clear() - mask1.paths.append('') - mask2.paths.append('') - self.assertEqual(mask1.paths, ['']) - self.assertEqual('', mask1.ToJsonString()) - out_mask.Intersect(mask1, mask2) - self.assertEqual(out_mask.paths, []) - - def testMergeMessageWithoutMapFields(self): - # Test merge one field. - src = unittest_pb2.TestAllTypes() - test_util.SetAllFields(src) - for field in src.DESCRIPTOR.fields: - if field.containing_oneof: - continue - field_name = field.name - dst = unittest_pb2.TestAllTypes() - # Only set one path to mask. - mask = field_mask_pb2.FieldMask() - mask.paths.append(field_name) - mask.MergeMessage(src, dst) - # The expected result message. - msg = unittest_pb2.TestAllTypes() - if field.label == descriptor.FieldDescriptor.LABEL_REPEATED: - repeated_src = getattr(src, field_name) - repeated_msg = getattr(msg, field_name) - if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: - for item in repeated_src: - repeated_msg.add().CopyFrom(item) - else: - repeated_msg.extend(repeated_src) - elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: - getattr(msg, field_name).CopyFrom(getattr(src, field_name)) - else: - setattr(msg, field_name, getattr(src, field_name)) - # Only field specified in mask is merged. - self.assertEqual(msg, dst) - - # Test merge nested fields. - nested_src = unittest_pb2.NestedTestAllTypes() - nested_dst = unittest_pb2.NestedTestAllTypes() - nested_src.child.payload.optional_int32 = 1234 - nested_src.child.child.payload.optional_int32 = 5678 - mask = field_mask_pb2.FieldMask() - mask.FromJsonString('child.payload') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(1234, nested_dst.child.payload.optional_int32) - self.assertEqual(0, nested_dst.child.child.payload.optional_int32) - - mask.FromJsonString('child.child.payload') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(1234, nested_dst.child.payload.optional_int32) - self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) - - nested_dst.Clear() - mask.FromJsonString('child.child.payload') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(0, nested_dst.child.payload.optional_int32) - self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) - - nested_dst.Clear() - mask.FromJsonString('child') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(1234, nested_dst.child.payload.optional_int32) - self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) - - # Test MergeOptions. - nested_dst.Clear() - nested_dst.child.payload.optional_int64 = 4321 - # Message fields will be merged by default. - mask.FromJsonString('child.payload') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(1234, nested_dst.child.payload.optional_int32) - self.assertEqual(4321, nested_dst.child.payload.optional_int64) - # Change the behavior to replace message fields. - mask.FromJsonString('child.payload') - mask.MergeMessage(nested_src, nested_dst, True, False) - self.assertEqual(1234, nested_dst.child.payload.optional_int32) - self.assertEqual(0, nested_dst.child.payload.optional_int64) - - # By default, fields missing in source are not cleared in destination. - nested_dst.payload.optional_int32 = 1234 - self.assertTrue(nested_dst.HasField('payload')) - mask.FromJsonString('payload') - mask.MergeMessage(nested_src, nested_dst) - self.assertTrue(nested_dst.HasField('payload')) - # But they are cleared when replacing message fields. - nested_dst.Clear() - nested_dst.payload.optional_int32 = 1234 - mask.FromJsonString('payload') - mask.MergeMessage(nested_src, nested_dst, True, False) - self.assertFalse(nested_dst.HasField('payload')) - - nested_src.payload.repeated_int32.append(1234) - nested_dst.payload.repeated_int32.append(5678) - # Repeated fields will be appended by default. - mask.FromJsonString('payload.repeatedInt32') - mask.MergeMessage(nested_src, nested_dst) - self.assertEqual(2, len(nested_dst.payload.repeated_int32)) - self.assertEqual(5678, nested_dst.payload.repeated_int32[0]) - self.assertEqual(1234, nested_dst.payload.repeated_int32[1]) - # Change the behavior to replace repeated fields. - mask.FromJsonString('payload.repeatedInt32') - mask.MergeMessage(nested_src, nested_dst, False, True) - self.assertEqual(1, len(nested_dst.payload.repeated_int32)) - self.assertEqual(1234, nested_dst.payload.repeated_int32[0]) - - # Test Merge oneof field. - new_msg = unittest_pb2.TestOneof2() - dst = unittest_pb2.TestOneof2() - dst.foo_message.moo_int = 1 - mask = field_mask_pb2.FieldMask() - mask.FromJsonString('fooMessage,fooLazyMessage.mooInt') - mask.MergeMessage(new_msg, dst) - self.assertTrue(dst.HasField('foo_message')) - self.assertFalse(dst.HasField('foo_lazy_message')) - - def testMergeMessageWithMapField(self): - empty_map = map_unittest_pb2.TestRecursiveMapMessage() - src_level_2 = map_unittest_pb2.TestRecursiveMapMessage() - src_level_2.a['src level 2'].CopyFrom(empty_map) - src = map_unittest_pb2.TestRecursiveMapMessage() - src.a['common key'].CopyFrom(src_level_2) - src.a['src level 1'].CopyFrom(src_level_2) - - dst_level_2 = map_unittest_pb2.TestRecursiveMapMessage() - dst_level_2.a['dst level 2'].CopyFrom(empty_map) - dst = map_unittest_pb2.TestRecursiveMapMessage() - dst.a['common key'].CopyFrom(dst_level_2) - dst.a['dst level 1'].CopyFrom(empty_map) - - mask = field_mask_pb2.FieldMask() - mask.FromJsonString('a') - mask.MergeMessage(src, dst) - - # map from dst is replaced with map from src. - self.assertEqual(dst.a['common key'], src_level_2) - self.assertEqual(dst.a['src level 1'], src_level_2) - self.assertEqual(dst.a['dst level 1'], empty_map) - - def testMergeErrors(self): - src = unittest_pb2.TestAllTypes() - dst = unittest_pb2.TestAllTypes() - mask = field_mask_pb2.FieldMask() - test_util.SetAllFields(src) - mask.FromJsonString('optionalInt32.field') - with self.assertRaises(ValueError) as e: - mask.MergeMessage(src, dst) - self.assertEqual('Error: Field optional_int32 in message ' - 'protobuf_unittest.TestAllTypes is not a singular ' - 'message field and cannot have sub-fields.', - str(e.exception)) - - def testSnakeCaseToCamelCase(self): - self.assertEqual('fooBar', - field_mask._SnakeCaseToCamelCase('foo_bar')) - self.assertEqual('FooBar', - field_mask._SnakeCaseToCamelCase('_foo_bar')) - self.assertEqual('foo3Bar', - field_mask._SnakeCaseToCamelCase('foo3_bar')) - - # No uppercase letter is allowed. - self.assertRaisesRegex( - ValueError, - 'Fail to print FieldMask to Json string: Path name Foo must ' - 'not contain uppercase letters.', - field_mask._SnakeCaseToCamelCase, 'Foo') - # Any character after a "_" must be a lowercase letter. - # 1. "_" cannot be followed by another "_". - # 2. "_" cannot be followed by a digit. - # 3. "_" cannot appear as the last character. - self.assertRaisesRegex( - ValueError, - 'Fail to print FieldMask to Json string: The character after a ' - '"_" must be a lowercase letter in path name foo__bar.', - field_mask._SnakeCaseToCamelCase, 'foo__bar') - self.assertRaisesRegex( - ValueError, - 'Fail to print FieldMask to Json string: The character after a ' - '"_" must be a lowercase letter in path name foo_3bar.', - field_mask._SnakeCaseToCamelCase, 'foo_3bar') - self.assertRaisesRegex( - ValueError, - 'Fail to print FieldMask to Json string: Trailing "_" in path ' - 'name foo_bar_.', field_mask._SnakeCaseToCamelCase, 'foo_bar_') - - def testCamelCaseToSnakeCase(self): - self.assertEqual('foo_bar', - field_mask._CamelCaseToSnakeCase('fooBar')) - self.assertEqual('_foo_bar', - field_mask._CamelCaseToSnakeCase('FooBar')) - self.assertEqual('foo3_bar', - field_mask._CamelCaseToSnakeCase('foo3Bar')) - self.assertRaisesRegex( - ValueError, - 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.', - field_mask._CamelCaseToSnakeCase, 'foo_bar') - - -if __name__ == '__main__': - unittest.main() diff --git a/libs/protobuf/python/google/protobuf/internal/message_factory_test.py b/libs/protobuf/python/google/protobuf/internal/message_factory_test.py index 3ab3b8e..efba619 100644 --- a/libs/protobuf/python/google/protobuf/internal/message_factory_test.py +++ b/libs/protobuf/python/google/protobuf/internal/message_factory_test.py @@ -118,16 +118,6 @@ class MessageFactoryTest(unittest.TestCase): 'google.protobuf.python.internal.Factory2Message')) self.assertTrue(hasattr(cls, 'additional_field')) - def testGetExistingPrototype(self): - factory = message_factory.MessageFactory() - # Get Existing Prototype should not create a new class. - cls = factory.GetPrototype( - descriptor=factory_test2_pb2.Factory2Message.DESCRIPTOR) - msg = factory_test2_pb2.Factory2Message() - self.assertIsInstance(msg, cls) - self.assertIsInstance(msg.factory_1_message, - factory_test1_pb2.Factory1Message) - def testGetMessages(self): # performed twice because multiple calls with the same input must be allowed for _ in range(2): diff --git a/libs/protobuf/python/google/protobuf/internal/message_test.py b/libs/protobuf/python/google/protobuf/internal/message_test.py index 3c604dd..40abfe4 100644 --- a/libs/protobuf/python/google/protobuf/internal/message_test.py +++ b/libs/protobuf/python/google/protobuf/internal/message_test.py @@ -34,6 +34,10 @@ Note that the golden messages exercise every known field type, thus this test ends up exercising and verifying nearly all of the parsing and serialization code in the whole library. + +TODO(kenton): Merge with wire_format_test? It doesn't make a whole lot of +sense to call this a test of the "message" module, which only declares an +abstract interface. """ __author__ = 'gps@google.com (Gregory P. Smith)' @@ -472,12 +476,6 @@ class MessageTest(unittest.TestCase): '}\n') self.assertEqual(sub_msg.bb, 1) - def testAssignRepeatedField(self, message_module): - msg = message_module.NestedTestAllTypes() - msg.payload.repeated_int32[:] = [1, 2, 3, 4] - self.assertEqual(4, len(msg.payload.repeated_int32)) - self.assertEqual([1, 2, 3, 4], msg.payload.repeated_int32) - def testMergeFromRepeatedField(self, message_module): msg = message_module.TestAllTypes() msg.repeated_int32.append(1) @@ -889,7 +887,6 @@ class MessageTest(unittest.TestCase): def testOneofClearField(self, message_module): m = message_module.TestAllTypes() - m.ClearField('oneof_field') m.oneof_uint32 = 11 m.ClearField('oneof_field') if message_module is unittest_pb2: @@ -1769,19 +1766,6 @@ class Proto3Test(unittest.TestCase): with self.assertRaises(TypeError): 123 in msg.map_string_string - def testScalarMapComparison(self): - msg1 = map_unittest_pb2.TestMap() - msg2 = map_unittest_pb2.TestMap() - - self.assertEqual(msg1.map_int32_int32, msg2.map_int32_int32) - - def testMessageMapComparison(self): - msg1 = map_unittest_pb2.TestMap() - msg2 = map_unittest_pb2.TestMap() - - self.assertEqual(msg1.map_int32_foreign_message, - msg2.map_int32_foreign_message) - def testMapGet(self): # Need to test that get() properly returns the default, even though the dict # has defaultdict-like semantics. @@ -2469,26 +2453,6 @@ class Proto3Test(unittest.TestCase): with self.assertRaises(ValueError): unittest_proto3_arena_pb2.TestAllTypes(optional_string=u'\ud801\ud801') - def testCrashNullAA(self): - self.assertEqual( - unittest_proto3_arena_pb2.TestAllTypes.NestedMessage(), - unittest_proto3_arena_pb2.TestAllTypes.NestedMessage()) - - def testCrashNullAB(self): - self.assertEqual( - unittest_proto3_arena_pb2.TestAllTypes.NestedMessage(), - unittest_proto3_arena_pb2.TestAllTypes().optional_nested_message) - - def testCrashNullBA(self): - self.assertEqual( - unittest_proto3_arena_pb2.TestAllTypes().optional_nested_message, - unittest_proto3_arena_pb2.TestAllTypes.NestedMessage()) - - def testCrashNullBB(self): - self.assertEqual( - unittest_proto3_arena_pb2.TestAllTypes().optional_nested_message, - unittest_proto3_arena_pb2.TestAllTypes().optional_nested_message) - diff --git a/libs/protobuf/python/google/protobuf/internal/missing_enum_values.proto b/libs/protobuf/python/google/protobuf/internal/missing_enum_values.proto index 96de1e4..37baca7 100644 --- a/libs/protobuf/python/google/protobuf/internal/missing_enum_values.proto +++ b/libs/protobuf/python/google/protobuf/internal/missing_enum_values.proto @@ -30,6 +30,7 @@ syntax = "proto2"; + package google.protobuf.python.internal; message TestEnumValues { @@ -52,3 +53,4 @@ message TestMissingEnumValues { message JustString { required string dummy = 1; } + diff --git a/libs/protobuf/python/google/protobuf/internal/numpy_test.py b/libs/protobuf/python/google/protobuf/internal/numpy_test.py deleted file mode 100644 index 3817578..0000000 --- a/libs/protobuf/python/google/protobuf/internal/numpy_test.py +++ /dev/null @@ -1,215 +0,0 @@ -# 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. - -"""Test use of numpy types with repeated and non-repeated scalar fields.""" - -import unittest - -import numpy as np - -from google.protobuf import unittest_pb2 -from google.protobuf.internal import testing_refleaks - -message = unittest_pb2.TestAllTypes() -np_float_scalar = np.float64(0.0) -np_1_float_array = np.zeros(shape=(1,), dtype=np.float64) -np_2_float_array = np.zeros(shape=(2,), dtype=np.float64) -np_11_float_array = np.zeros(shape=(1, 1), dtype=np.float64) -np_22_float_array = np.zeros(shape=(2, 2), dtype=np.float64) - -np_int_scalar = np.int64(0) -np_1_int_array = np.zeros(shape=(1,), dtype=np.int64) -np_2_int_array = np.zeros(shape=(2,), dtype=np.int64) -np_11_int_array = np.zeros(shape=(1, 1), dtype=np.int64) -np_22_int_array = np.zeros(shape=(2, 2), dtype=np.int64) - -np_uint_scalar = np.uint64(0) -np_1_uint_array = np.zeros(shape=(1,), dtype=np.uint64) -np_2_uint_array = np.zeros(shape=(2,), dtype=np.uint64) -np_11_uint_array = np.zeros(shape=(1, 1), dtype=np.uint64) -np_22_uint_array = np.zeros(shape=(2, 2), dtype=np.uint64) - -np_bool_scalar = np.bool_(False) -np_1_bool_array = np.zeros(shape=(1,), dtype=np.bool_) -np_2_bool_array = np.zeros(shape=(2,), dtype=np.bool_) -np_11_bool_array = np.zeros(shape=(1, 1), dtype=np.bool_) -np_22_bool_array = np.zeros(shape=(2, 2), dtype=np.bool_) - - -@testing_refleaks.TestCase -class NumpyIntProtoTest(unittest.TestCase): - - # Assigning dim 1 ndarray of ints to repeated field should pass - def testNumpyDim1IntArrayToRepeated_IsValid(self): - message.repeated_int64[:] = np_1_int_array - message.repeated_int64[:] = np_2_int_array - - message.repeated_uint64[:] = np_1_uint_array - message.repeated_uint64[:] = np_2_uint_array - - # Assigning dim 2 ndarray of ints to repeated field should fail - def testNumpyDim2IntArrayToRepeated_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.repeated_int64[:] = np_11_int_array - with self.assertRaises(TypeError): - message.repeated_int64[:] = np_22_int_array - - with self.assertRaises(TypeError): - message.repeated_uint64[:] = np_11_uint_array - with self.assertRaises(TypeError): - message.repeated_uint64[:] = np_22_uint_array - - # Assigning any ndarray of floats to repeated int field should fail - def testNumpyFloatArrayToRepeated_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.repeated_int64[:] = np_1_float_array - with self.assertRaises(TypeError): - message.repeated_int64[:] = np_11_float_array - with self.assertRaises(TypeError): - message.repeated_int64[:] = np_22_float_array - - # Assigning any np int to scalar field should pass - def testNumpyIntScalarToScalar_IsValid(self): - message.optional_int64 = np_int_scalar - message.optional_uint64 = np_uint_scalar - - # Assigning any ndarray of ints to scalar field should fail - def testNumpyIntArrayToScalar_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.optional_int64 = np_1_int_array - with self.assertRaises(TypeError): - message.optional_int64 = np_11_int_array - with self.assertRaises(TypeError): - message.optional_int64 = np_22_int_array - - with self.assertRaises(TypeError): - message.optional_uint64 = np_1_uint_array - with self.assertRaises(TypeError): - message.optional_uint64 = np_11_uint_array - with self.assertRaises(TypeError): - message.optional_uint64 = np_22_uint_array - - # Assigning any ndarray of floats to scalar field should fail - def testNumpyFloatArrayToScalar_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.optional_int64 = np_1_float_array - with self.assertRaises(TypeError): - message.optional_int64 = np_11_float_array - with self.assertRaises(TypeError): - message.optional_int64 = np_22_float_array - - -@testing_refleaks.TestCase -class NumpyFloatProtoTest(unittest.TestCase): - - # Assigning dim 1 ndarray of floats to repeated field should pass - def testNumpyDim1FloatArrayToRepeated_IsValid(self): - message.repeated_float[:] = np_1_float_array - message.repeated_float[:] = np_2_float_array - - # Assigning dim 2 ndarray of floats to repeated field should fail - def testNumpyDim2FloatArrayToRepeated_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.repeated_float[:] = np_11_float_array - with self.assertRaises(TypeError): - message.repeated_float[:] = np_22_float_array - - # Assigning any np float to scalar field should pass - def testNumpyFloatScalarToScalar_IsValid(self): - message.optional_float = np_float_scalar - - # Assigning any ndarray of float to scalar field should fail - def testNumpyFloatArrayToScalar_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.optional_float = np_1_float_array - with self.assertRaises(TypeError): - message.optional_float = np_11_float_array - with self.assertRaises(TypeError): - message.optional_float = np_22_float_array - - -@testing_refleaks.TestCase -class NumpyBoolProtoTest(unittest.TestCase): - - # Assigning dim 1 ndarray of bool to repeated field should pass - def testNumpyDim1BoolArrayToRepeated_IsValid(self): - message.repeated_bool[:] = np_1_bool_array - message.repeated_bool[:] = np_2_bool_array - - # Assigning dim 2 ndarray of bool to repeated field should fail - def testNumpyDim2BoolArrayToRepeated_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.repeated_bool[:] = np_11_bool_array - with self.assertRaises(TypeError): - message.repeated_bool[:] = np_22_bool_array - - # Assigning any np bool to scalar field should pass - def testNumpyBoolScalarToScalar_IsValid(self): - message.optional_bool = np_bool_scalar - - # Assigning any ndarray of bool to scalar field should fail - def testNumpyBoolArrayToScalar_RaisesTypeError(self): - with self.assertRaises(TypeError): - message.optional_bool = np_1_bool_array - with self.assertRaises(TypeError): - message.optional_bool = np_11_bool_array - with self.assertRaises(TypeError): - message.optional_bool = np_22_bool_array - - -@testing_refleaks.TestCase -class NumpyProtoIndexingTest(unittest.TestCase): - - def testNumpyIntScalarIndexing_Passes(self): - data = unittest_pb2.TestAllTypes(repeated_int64=[0, 1, 2]) - self.assertEqual(0, data.repeated_int64[np.int64(0)]) - - def testNumpyNegative1IntScalarIndexing_Passes(self): - data = unittest_pb2.TestAllTypes(repeated_int64=[0, 1, 2]) - self.assertEqual(2, data.repeated_int64[np.int64(-1)]) - - def testNumpyFloatScalarIndexing_Fails(self): - data = unittest_pb2.TestAllTypes(repeated_int64=[0, 1, 2]) - with self.assertRaises(TypeError): - _ = data.repeated_int64[np.float64(0.0)] - - def testNumpyIntArrayIndexing_Fails(self): - data = unittest_pb2.TestAllTypes(repeated_int64=[0, 1, 2]) - with self.assertRaises(TypeError): - _ = data.repeated_int64[np.array([0])] - with self.assertRaises(TypeError): - _ = data.repeated_int64[np.ndarray((1,), buffer=np.array([0]), dtype=int)] - with self.assertRaises(TypeError): - _ = data.repeated_int64[np.ndarray((1, 1), - buffer=np.array([0]), - dtype=int)] - -if __name__ == '__main__': - unittest.main() diff --git a/libs/protobuf/python/google/protobuf/internal/python_protobuf.cc b/libs/protobuf/python/google/protobuf/internal/python_protobuf.cc index 95c6d2b..26e3a8b 100644 --- a/libs/protobuf/python/google/protobuf/internal/python_protobuf.cc +++ b/libs/protobuf/python/google/protobuf/internal/python_protobuf.cc @@ -30,7 +30,7 @@ // Author: qrczak@google.com (Marcin Kowalczyk) -#include "google/protobuf/python/python_protobuf.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/internal/text_format_test.py b/libs/protobuf/python/google/protobuf/internal/text_format_test.py index 996ef65..18b784e 100644 --- a/libs/protobuf/python/google/protobuf/internal/text_format_test.py +++ b/libs/protobuf/python/google/protobuf/internal/text_format_test.py @@ -1598,47 +1598,6 @@ class Proto2Tests(TextFormatBase): self.assertEqual(23, message.message_set.Extensions[ext1].i) self.assertEqual('foo', message.message_set.Extensions[ext2].str) - # Handle Any messages inside unknown extensions. - message = any_test_pb2.TestAny() - text = ('any_value {\n' - ' [type.googleapis.com/google.protobuf.internal.TestAny] {\n' - ' [unknown_extension] {\n' - ' str: "string"\n' - ' any_value {\n' - ' [type.googleapis.com/protobuf_unittest.OneString] {\n' - ' data: "string"\n' - ' }\n' - ' }\n' - ' }\n' - ' }\n' - '}\n' - 'int32_value: 123') - text_format.Parse(text, message, allow_unknown_extension=True) - self.assertEqual(123, message.int32_value) - - # Fail if invalid Any message type url inside unknown extensions. - message = any_test_pb2.TestAny() - text = ('any_value {\n' - ' [type.googleapis.com.invalid/google.protobuf.internal.TestAny] {\n' - ' [unknown_extension] {\n' - ' str: "string"\n' - ' any_value {\n' - ' [type.googleapis.com/protobuf_unittest.OneString] {\n' - ' data: "string"\n' - ' }\n' - ' }\n' - ' }\n' - ' }\n' - '}\n' - 'int32_value: 123') - self.assertRaisesRegex( - text_format.ParseError, - '[type.googleapis.com.invalid/google.protobuf.internal.TestAny]', - text_format.Parse, - text, - message, - allow_unknown_extension=True) - def testParseBadIdentifier(self): message = unittest_pb2.TestAllTypes() text = ('optional_nested_message { "bb": 1 }') @@ -2484,6 +2443,5 @@ class OptionalColonMessageToStringTest(unittest.TestCase): self.assertEqual('repeated_int32: [1]\n', output) - if __name__ == '__main__': unittest.main() diff --git a/libs/protobuf/python/google/protobuf/internal/well_known_types.py b/libs/protobuf/python/google/protobuf/internal/well_known_types.py index e340f90..8881d75 100644 --- a/libs/protobuf/python/google/protobuf/internal/well_known_types.py +++ b/libs/protobuf/python/google/protobuf/internal/well_known_types.py @@ -44,9 +44,7 @@ import calendar import collections.abc import datetime -from google.protobuf.internal import field_mask - -FieldMask = field_mask.FieldMask +from google.protobuf.descriptor import FieldDescriptor _TIMESTAMPFOMAT = '%Y-%m-%dT%H:%M:%S' _NANOS_PER_SECOND = 1000000000 @@ -432,6 +430,306 @@ def _RoundTowardZero(value, divider): return result +class FieldMask(object): + """Class for FieldMask message type.""" + + __slots__ = () + + def ToJsonString(self): + """Converts FieldMask to string according to proto3 JSON spec.""" + camelcase_paths = [] + for path in self.paths: + camelcase_paths.append(_SnakeCaseToCamelCase(path)) + return ','.join(camelcase_paths) + + def FromJsonString(self, value): + """Converts string to FieldMask according to proto3 JSON spec.""" + if not isinstance(value, str): + raise ValueError('FieldMask JSON value not a string: {!r}'.format(value)) + self.Clear() + if value: + for path in value.split(','): + self.paths.append(_CamelCaseToSnakeCase(path)) + + def IsValidForDescriptor(self, message_descriptor): + """Checks whether the FieldMask is valid for Message Descriptor.""" + for path in self.paths: + if not _IsValidPath(message_descriptor, path): + return False + return True + + def AllFieldsFromDescriptor(self, message_descriptor): + """Gets all direct fields of Message Descriptor to FieldMask.""" + self.Clear() + for field in message_descriptor.fields: + self.paths.append(field.name) + + def CanonicalFormFromMask(self, mask): + """Converts a FieldMask to the canonical form. + + Removes paths that are covered by another path. For example, + "foo.bar" is covered by "foo" and will be removed if "foo" + is also in the FieldMask. Then sorts all paths in alphabetical order. + + Args: + mask: The original FieldMask to be converted. + """ + tree = _FieldMaskTree(mask) + tree.ToFieldMask(self) + + def Union(self, mask1, mask2): + """Merges mask1 and mask2 into this FieldMask.""" + _CheckFieldMaskMessage(mask1) + _CheckFieldMaskMessage(mask2) + tree = _FieldMaskTree(mask1) + tree.MergeFromFieldMask(mask2) + tree.ToFieldMask(self) + + def Intersect(self, mask1, mask2): + """Intersects mask1 and mask2 into this FieldMask.""" + _CheckFieldMaskMessage(mask1) + _CheckFieldMaskMessage(mask2) + tree = _FieldMaskTree(mask1) + intersection = _FieldMaskTree() + for path in mask2.paths: + tree.IntersectPath(path, intersection) + intersection.ToFieldMask(self) + + def MergeMessage( + self, source, destination, + replace_message_field=False, replace_repeated_field=False): + """Merges fields specified in FieldMask from source to destination. + + Args: + source: Source message. + destination: The destination message to be merged into. + replace_message_field: Replace message field if True. Merge message + field if False. + replace_repeated_field: Replace repeated field if True. Append + elements of repeated field if False. + """ + tree = _FieldMaskTree(self) + tree.MergeMessage( + source, destination, replace_message_field, replace_repeated_field) + + +def _IsValidPath(message_descriptor, path): + """Checks whether the path is valid for Message Descriptor.""" + parts = path.split('.') + last = parts.pop() + for name in parts: + field = message_descriptor.fields_by_name.get(name) + if (field is None or + field.label == FieldDescriptor.LABEL_REPEATED or + field.type != FieldDescriptor.TYPE_MESSAGE): + return False + message_descriptor = field.message_type + return last in message_descriptor.fields_by_name + + +def _CheckFieldMaskMessage(message): + """Raises ValueError if message is not a FieldMask.""" + message_descriptor = message.DESCRIPTOR + if (message_descriptor.name != 'FieldMask' or + message_descriptor.file.name != 'google/protobuf/field_mask.proto'): + raise ValueError('Message {0} is not a FieldMask.'.format( + message_descriptor.full_name)) + + +def _SnakeCaseToCamelCase(path_name): + """Converts a path name from snake_case to camelCase.""" + result = [] + after_underscore = False + for c in path_name: + if c.isupper(): + raise ValueError( + 'Fail to print FieldMask to Json string: Path name ' + '{0} must not contain uppercase letters.'.format(path_name)) + if after_underscore: + if c.islower(): + result.append(c.upper()) + after_underscore = False + else: + raise ValueError( + 'Fail to print FieldMask to Json string: The ' + 'character after a "_" must be a lowercase letter ' + 'in path name {0}.'.format(path_name)) + elif c == '_': + after_underscore = True + else: + result += c + + if after_underscore: + raise ValueError('Fail to print FieldMask to Json string: Trailing "_" ' + 'in path name {0}.'.format(path_name)) + return ''.join(result) + + +def _CamelCaseToSnakeCase(path_name): + """Converts a field name from camelCase to snake_case.""" + result = [] + for c in path_name: + if c == '_': + raise ValueError('Fail to parse FieldMask: Path name ' + '{0} must not contain "_"s.'.format(path_name)) + if c.isupper(): + result += '_' + result += c.lower() + else: + result += c + return ''.join(result) + + +class _FieldMaskTree(object): + """Represents a FieldMask in a tree structure. + + For example, given a FieldMask "foo.bar,foo.baz,bar.baz", + the FieldMaskTree will be: + [_root] -+- foo -+- bar + | | + | +- baz + | + +- bar --- baz + In the tree, each leaf node represents a field path. + """ + + __slots__ = ('_root',) + + def __init__(self, field_mask=None): + """Initializes the tree by FieldMask.""" + self._root = {} + if field_mask: + self.MergeFromFieldMask(field_mask) + + def MergeFromFieldMask(self, field_mask): + """Merges a FieldMask to the tree.""" + for path in field_mask.paths: + self.AddPath(path) + + def AddPath(self, path): + """Adds a field path into the tree. + + If the field path to add is a sub-path of an existing field path + in the tree (i.e., a leaf node), it means the tree already matches + the given path so nothing will be added to the tree. If the path + matches an existing non-leaf node in the tree, that non-leaf node + will be turned into a leaf node with all its children removed because + the path matches all the node's children. Otherwise, a new path will + be added. + + Args: + path: The field path to add. + """ + node = self._root + for name in path.split('.'): + if name not in node: + node[name] = {} + elif not node[name]: + # Pre-existing empty node implies we already have this entire tree. + return + node = node[name] + # Remove any sub-trees we might have had. + node.clear() + + def ToFieldMask(self, field_mask): + """Converts the tree to a FieldMask.""" + field_mask.Clear() + _AddFieldPaths(self._root, '', field_mask) + + def IntersectPath(self, path, intersection): + """Calculates the intersection part of a field path with this tree. + + Args: + path: The field path to calculates. + intersection: The out tree to record the intersection part. + """ + node = self._root + for name in path.split('.'): + if name not in node: + return + elif not node[name]: + intersection.AddPath(path) + return + node = node[name] + intersection.AddLeafNodes(path, node) + + def AddLeafNodes(self, prefix, node): + """Adds leaf nodes begin with prefix to this tree.""" + if not node: + self.AddPath(prefix) + for name in node: + child_path = prefix + '.' + name + self.AddLeafNodes(child_path, node[name]) + + def MergeMessage( + self, source, destination, + replace_message, replace_repeated): + """Merge all fields specified by this tree from source to destination.""" + _MergeMessage( + self._root, source, destination, replace_message, replace_repeated) + + +def _StrConvert(value): + """Converts value to str if it is not.""" + # This file is imported by c extension and some methods like ClearField + # requires string for the field name. py2/py3 has different text + # type and may use unicode. + if not isinstance(value, str): + return value.encode('utf-8') + return value + + +def _MergeMessage( + node, source, destination, replace_message, replace_repeated): + """Merge all fields specified by a sub-tree from source to destination.""" + source_descriptor = source.DESCRIPTOR + for name in node: + child = node[name] + field = source_descriptor.fields_by_name[name] + if field is None: + raise ValueError('Error: Can\'t find field {0} in message {1}.'.format( + name, source_descriptor.full_name)) + if child: + # Sub-paths are only allowed for singular message fields. + if (field.label == FieldDescriptor.LABEL_REPEATED or + field.cpp_type != FieldDescriptor.CPPTYPE_MESSAGE): + raise ValueError('Error: Field {0} in message {1} is not a singular ' + 'message field and cannot have sub-fields.'.format( + name, source_descriptor.full_name)) + if source.HasField(name): + _MergeMessage( + child, getattr(source, name), getattr(destination, name), + replace_message, replace_repeated) + continue + if field.label == FieldDescriptor.LABEL_REPEATED: + if replace_repeated: + destination.ClearField(_StrConvert(name)) + repeated_source = getattr(source, name) + repeated_destination = getattr(destination, name) + repeated_destination.MergeFrom(repeated_source) + else: + if field.cpp_type == FieldDescriptor.CPPTYPE_MESSAGE: + if replace_message: + destination.ClearField(_StrConvert(name)) + if source.HasField(name): + getattr(destination, name).MergeFrom(getattr(source, name)) + else: + setattr(destination, name, getattr(source, name)) + + +def _AddFieldPaths(node, prefix, field_mask): + """Adds the field paths descended from node to field_mask.""" + if not node and prefix: + field_mask.paths.append(prefix) + return + for name in sorted(node): + if prefix: + child_path = prefix + '.' + name + else: + child_path = name + _AddFieldPaths(node[name], child_path, field_mask) + + def _SetStructValue(struct_value, value): if value is None: struct_value.null_value = 0 diff --git a/libs/protobuf/python/google/protobuf/internal/well_known_types_test.py b/libs/protobuf/python/google/protobuf/internal/well_known_types_test.py index 601ae41..a32459a 100644 --- a/libs/protobuf/python/google/protobuf/internal/well_known_types_test.py +++ b/libs/protobuf/python/google/protobuf/internal/well_known_types_test.py @@ -38,11 +38,15 @@ import unittest from google.protobuf import any_pb2 from google.protobuf import duration_pb2 +from google.protobuf import field_mask_pb2 from google.protobuf import struct_pb2 from google.protobuf import timestamp_pb2 +from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 from google.protobuf.internal import any_test_pb2 +from google.protobuf.internal import test_util from google.protobuf.internal import well_known_types +from google.protobuf import descriptor from google.protobuf import text_format from google.protobuf.internal import _parameterized @@ -386,6 +390,362 @@ class TimeUtilTest(TimeUtilTestBase): message.ToJsonString) +class FieldMaskTest(unittest.TestCase): + + def testStringFormat(self): + mask = field_mask_pb2.FieldMask() + self.assertEqual('', mask.ToJsonString()) + mask.paths.append('foo') + self.assertEqual('foo', mask.ToJsonString()) + mask.paths.append('bar') + self.assertEqual('foo,bar', mask.ToJsonString()) + + mask.FromJsonString('') + self.assertEqual('', mask.ToJsonString()) + mask.FromJsonString('foo') + self.assertEqual(['foo'], mask.paths) + mask.FromJsonString('foo,bar') + self.assertEqual(['foo', 'bar'], mask.paths) + + # Test camel case + mask.Clear() + mask.paths.append('foo_bar') + self.assertEqual('fooBar', mask.ToJsonString()) + mask.paths.append('bar_quz') + self.assertEqual('fooBar,barQuz', mask.ToJsonString()) + + mask.FromJsonString('') + self.assertEqual('', mask.ToJsonString()) + self.assertEqual([], mask.paths) + mask.FromJsonString('fooBar') + self.assertEqual(['foo_bar'], mask.paths) + mask.FromJsonString('fooBar,barQuz') + self.assertEqual(['foo_bar', 'bar_quz'], mask.paths) + + def testDescriptorToFieldMask(self): + mask = field_mask_pb2.FieldMask() + msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR + mask.AllFieldsFromDescriptor(msg_descriptor) + self.assertEqual(76, len(mask.paths)) + self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) + for field in msg_descriptor.fields: + self.assertTrue(field.name in mask.paths) + + def testIsValidForDescriptor(self): + msg_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR + # Empty mask + mask = field_mask_pb2.FieldMask() + self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) + # All fields from descriptor + mask.AllFieldsFromDescriptor(msg_descriptor) + self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) + # Child under optional message + mask.paths.append('optional_nested_message.bb') + self.assertTrue(mask.IsValidForDescriptor(msg_descriptor)) + # Repeated field is only allowed in the last position of path + mask.paths.append('repeated_nested_message.bb') + self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) + # Invalid top level field + mask = field_mask_pb2.FieldMask() + mask.paths.append('xxx') + self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) + # Invalid field in root + mask = field_mask_pb2.FieldMask() + mask.paths.append('xxx.zzz') + self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) + # Invalid field in internal node + mask = field_mask_pb2.FieldMask() + mask.paths.append('optional_nested_message.xxx.zzz') + self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) + # Invalid field in leaf + mask = field_mask_pb2.FieldMask() + mask.paths.append('optional_nested_message.xxx') + self.assertFalse(mask.IsValidForDescriptor(msg_descriptor)) + + def testCanonicalFrom(self): + mask = field_mask_pb2.FieldMask() + out_mask = field_mask_pb2.FieldMask() + # Paths will be sorted. + mask.FromJsonString('baz.quz,bar,foo') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('bar,baz.quz,foo', out_mask.ToJsonString()) + # Duplicated paths will be removed. + mask.FromJsonString('foo,bar,foo') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('bar,foo', out_mask.ToJsonString()) + # Sub-paths of other paths will be removed. + mask.FromJsonString('foo.b1,bar.b1,foo.b2,bar') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('bar,foo.b1,foo.b2', out_mask.ToJsonString()) + + # Test more deeply nested cases. + mask.FromJsonString( + 'foo.bar.baz1,foo.bar.baz2.quz,foo.bar.baz2') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('foo.bar.baz1,foo.bar.baz2', + out_mask.ToJsonString()) + mask.FromJsonString( + 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('foo.bar.baz1,foo.bar.baz2', + out_mask.ToJsonString()) + mask.FromJsonString( + 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo.bar') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('foo.bar', out_mask.ToJsonString()) + mask.FromJsonString( + 'foo.bar.baz1,foo.bar.baz2,foo.bar.baz2.quz,foo') + out_mask.CanonicalFormFromMask(mask) + self.assertEqual('foo', out_mask.ToJsonString()) + + def testUnion(self): + mask1 = field_mask_pb2.FieldMask() + mask2 = field_mask_pb2.FieldMask() + out_mask = field_mask_pb2.FieldMask() + mask1.FromJsonString('foo,baz') + mask2.FromJsonString('bar,quz') + out_mask.Union(mask1, mask2) + self.assertEqual('bar,baz,foo,quz', out_mask.ToJsonString()) + # Overlap with duplicated paths. + mask1.FromJsonString('foo,baz.bb') + mask2.FromJsonString('baz.bb,quz') + out_mask.Union(mask1, mask2) + self.assertEqual('baz.bb,foo,quz', out_mask.ToJsonString()) + # Overlap with paths covering some other paths. + mask1.FromJsonString('foo.bar.baz,quz') + mask2.FromJsonString('foo.bar,bar') + out_mask.Union(mask1, mask2) + self.assertEqual('bar,foo.bar,quz', out_mask.ToJsonString()) + src = unittest_pb2.TestAllTypes() + with self.assertRaises(ValueError): + out_mask.Union(src, mask2) + + def testIntersect(self): + mask1 = field_mask_pb2.FieldMask() + mask2 = field_mask_pb2.FieldMask() + out_mask = field_mask_pb2.FieldMask() + # Test cases without overlapping. + mask1.FromJsonString('foo,baz') + mask2.FromJsonString('bar,quz') + out_mask.Intersect(mask1, mask2) + self.assertEqual('', out_mask.ToJsonString()) + self.assertEqual(len(out_mask.paths), 0) + self.assertEqual(out_mask.paths, []) + # Overlap with duplicated paths. + mask1.FromJsonString('foo,baz.bb') + mask2.FromJsonString('baz.bb,quz') + out_mask.Intersect(mask1, mask2) + self.assertEqual('baz.bb', out_mask.ToJsonString()) + # Overlap with paths covering some other paths. + mask1.FromJsonString('foo.bar.baz,quz') + mask2.FromJsonString('foo.bar,bar') + out_mask.Intersect(mask1, mask2) + self.assertEqual('foo.bar.baz', out_mask.ToJsonString()) + mask1.FromJsonString('foo.bar,bar') + mask2.FromJsonString('foo.bar.baz,quz') + out_mask.Intersect(mask1, mask2) + self.assertEqual('foo.bar.baz', out_mask.ToJsonString()) + # Intersect '' with '' + mask1.Clear() + mask2.Clear() + mask1.paths.append('') + mask2.paths.append('') + self.assertEqual(mask1.paths, ['']) + self.assertEqual('', mask1.ToJsonString()) + out_mask.Intersect(mask1, mask2) + self.assertEqual(out_mask.paths, []) + + def testMergeMessageWithoutMapFields(self): + # Test merge one field. + src = unittest_pb2.TestAllTypes() + test_util.SetAllFields(src) + for field in src.DESCRIPTOR.fields: + if field.containing_oneof: + continue + field_name = field.name + dst = unittest_pb2.TestAllTypes() + # Only set one path to mask. + mask = field_mask_pb2.FieldMask() + mask.paths.append(field_name) + mask.MergeMessage(src, dst) + # The expected result message. + msg = unittest_pb2.TestAllTypes() + if field.label == descriptor.FieldDescriptor.LABEL_REPEATED: + repeated_src = getattr(src, field_name) + repeated_msg = getattr(msg, field_name) + if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: + for item in repeated_src: + repeated_msg.add().CopyFrom(item) + else: + repeated_msg.extend(repeated_src) + elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: + getattr(msg, field_name).CopyFrom(getattr(src, field_name)) + else: + setattr(msg, field_name, getattr(src, field_name)) + # Only field specified in mask is merged. + self.assertEqual(msg, dst) + + # Test merge nested fields. + nested_src = unittest_pb2.NestedTestAllTypes() + nested_dst = unittest_pb2.NestedTestAllTypes() + nested_src.child.payload.optional_int32 = 1234 + nested_src.child.child.payload.optional_int32 = 5678 + mask = field_mask_pb2.FieldMask() + mask.FromJsonString('child.payload') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(1234, nested_dst.child.payload.optional_int32) + self.assertEqual(0, nested_dst.child.child.payload.optional_int32) + + mask.FromJsonString('child.child.payload') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(1234, nested_dst.child.payload.optional_int32) + self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) + + nested_dst.Clear() + mask.FromJsonString('child.child.payload') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(0, nested_dst.child.payload.optional_int32) + self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) + + nested_dst.Clear() + mask.FromJsonString('child') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(1234, nested_dst.child.payload.optional_int32) + self.assertEqual(5678, nested_dst.child.child.payload.optional_int32) + + # Test MergeOptions. + nested_dst.Clear() + nested_dst.child.payload.optional_int64 = 4321 + # Message fields will be merged by default. + mask.FromJsonString('child.payload') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(1234, nested_dst.child.payload.optional_int32) + self.assertEqual(4321, nested_dst.child.payload.optional_int64) + # Change the behavior to replace message fields. + mask.FromJsonString('child.payload') + mask.MergeMessage(nested_src, nested_dst, True, False) + self.assertEqual(1234, nested_dst.child.payload.optional_int32) + self.assertEqual(0, nested_dst.child.payload.optional_int64) + + # By default, fields missing in source are not cleared in destination. + nested_dst.payload.optional_int32 = 1234 + self.assertTrue(nested_dst.HasField('payload')) + mask.FromJsonString('payload') + mask.MergeMessage(nested_src, nested_dst) + self.assertTrue(nested_dst.HasField('payload')) + # But they are cleared when replacing message fields. + nested_dst.Clear() + nested_dst.payload.optional_int32 = 1234 + mask.FromJsonString('payload') + mask.MergeMessage(nested_src, nested_dst, True, False) + self.assertFalse(nested_dst.HasField('payload')) + + nested_src.payload.repeated_int32.append(1234) + nested_dst.payload.repeated_int32.append(5678) + # Repeated fields will be appended by default. + mask.FromJsonString('payload.repeatedInt32') + mask.MergeMessage(nested_src, nested_dst) + self.assertEqual(2, len(nested_dst.payload.repeated_int32)) + self.assertEqual(5678, nested_dst.payload.repeated_int32[0]) + self.assertEqual(1234, nested_dst.payload.repeated_int32[1]) + # Change the behavior to replace repeated fields. + mask.FromJsonString('payload.repeatedInt32') + mask.MergeMessage(nested_src, nested_dst, False, True) + self.assertEqual(1, len(nested_dst.payload.repeated_int32)) + self.assertEqual(1234, nested_dst.payload.repeated_int32[0]) + + # Test Merge oneof field. + new_msg = unittest_pb2.TestOneof2() + dst = unittest_pb2.TestOneof2() + dst.foo_message.moo_int = 1 + mask = field_mask_pb2.FieldMask() + mask.FromJsonString('fooMessage,fooLazyMessage.mooInt') + mask.MergeMessage(new_msg, dst) + self.assertTrue(dst.HasField('foo_message')) + self.assertFalse(dst.HasField('foo_lazy_message')) + + def testMergeMessageWithMapField(self): + empty_map = map_unittest_pb2.TestRecursiveMapMessage() + src_level_2 = map_unittest_pb2.TestRecursiveMapMessage() + src_level_2.a['src level 2'].CopyFrom(empty_map) + src = map_unittest_pb2.TestRecursiveMapMessage() + src.a['common key'].CopyFrom(src_level_2) + src.a['src level 1'].CopyFrom(src_level_2) + + dst_level_2 = map_unittest_pb2.TestRecursiveMapMessage() + dst_level_2.a['dst level 2'].CopyFrom(empty_map) + dst = map_unittest_pb2.TestRecursiveMapMessage() + dst.a['common key'].CopyFrom(dst_level_2) + dst.a['dst level 1'].CopyFrom(empty_map) + + mask = field_mask_pb2.FieldMask() + mask.FromJsonString('a') + mask.MergeMessage(src, dst) + + # map from dst is replaced with map from src. + self.assertEqual(dst.a['common key'], src_level_2) + self.assertEqual(dst.a['src level 1'], src_level_2) + self.assertEqual(dst.a['dst level 1'], empty_map) + + def testMergeErrors(self): + src = unittest_pb2.TestAllTypes() + dst = unittest_pb2.TestAllTypes() + mask = field_mask_pb2.FieldMask() + test_util.SetAllFields(src) + mask.FromJsonString('optionalInt32.field') + with self.assertRaises(ValueError) as e: + mask.MergeMessage(src, dst) + self.assertEqual('Error: Field optional_int32 in message ' + 'protobuf_unittest.TestAllTypes is not a singular ' + 'message field and cannot have sub-fields.', + str(e.exception)) + + def testSnakeCaseToCamelCase(self): + self.assertEqual('fooBar', + well_known_types._SnakeCaseToCamelCase('foo_bar')) + self.assertEqual('FooBar', + well_known_types._SnakeCaseToCamelCase('_foo_bar')) + self.assertEqual('foo3Bar', + well_known_types._SnakeCaseToCamelCase('foo3_bar')) + + # No uppercase letter is allowed. + self.assertRaisesRegex( + ValueError, + 'Fail to print FieldMask to Json string: Path name Foo must ' + 'not contain uppercase letters.', + well_known_types._SnakeCaseToCamelCase, 'Foo') + # Any character after a "_" must be a lowercase letter. + # 1. "_" cannot be followed by another "_". + # 2. "_" cannot be followed by a digit. + # 3. "_" cannot appear as the last character. + self.assertRaisesRegex( + ValueError, + 'Fail to print FieldMask to Json string: The character after a ' + '"_" must be a lowercase letter in path name foo__bar.', + well_known_types._SnakeCaseToCamelCase, 'foo__bar') + self.assertRaisesRegex( + ValueError, + 'Fail to print FieldMask to Json string: The character after a ' + '"_" must be a lowercase letter in path name foo_3bar.', + well_known_types._SnakeCaseToCamelCase, 'foo_3bar') + self.assertRaisesRegex( + ValueError, + 'Fail to print FieldMask to Json string: Trailing "_" in path ' + 'name foo_bar_.', well_known_types._SnakeCaseToCamelCase, 'foo_bar_') + + def testCamelCaseToSnakeCase(self): + self.assertEqual('foo_bar', + well_known_types._CamelCaseToSnakeCase('fooBar')) + self.assertEqual('_foo_bar', + well_known_types._CamelCaseToSnakeCase('FooBar')) + self.assertEqual('foo3_bar', + well_known_types._CamelCaseToSnakeCase('foo3Bar')) + self.assertRaisesRegex( + ValueError, + 'Fail to parse FieldMask: Path name foo_bar must not contain "_"s.', + well_known_types._CamelCaseToSnakeCase, 'foo_bar') + + class StructTest(unittest.TestCase): def testStruct(self): diff --git a/libs/protobuf/python/google/protobuf/json_format.py b/libs/protobuf/python/google/protobuf/json_format.py index f35a432..5024ed8 100644 --- a/libs/protobuf/python/google/protobuf/json_format.py +++ b/libs/protobuf/python/google/protobuf/json_format.py @@ -109,8 +109,7 @@ def MessageToJson( names as defined in the .proto file. If False, convert the field names to lowerCamelCase. indent: The JSON object will be pretty-printed with this indent level. - An indent level of 0 or negative will only insert newlines. If the - indent level is None, no newlines will be inserted. + An indent level of 0 or negative will only insert newlines. sort_keys: If True, then the output will be sorted by field names. use_integers_for_enums: If true, print integers instead of enum names. descriptor_pool: A Descriptor Pool for resolving types. If None use the diff --git a/libs/protobuf/python/google/protobuf/message.py b/libs/protobuf/python/google/protobuf/message.py index 0fe6a4f..76c6802 100644 --- a/libs/protobuf/python/google/protobuf/message.py +++ b/libs/protobuf/python/google/protobuf/message.py @@ -74,8 +74,7 @@ class Message(object): __slots__ = [] - #: The :class:`google.protobuf.Descriptor` - # for this message type. + #: The :class:`google.protobuf.descriptor.Descriptor` for this message type. DESCRIPTOR = None def __deepcopy__(self, memo=None): diff --git a/libs/protobuf/python/google/protobuf/message_factory.py b/libs/protobuf/python/google/protobuf/message_factory.py index ce5b5a7..8d65204 100644 --- a/libs/protobuf/python/google/protobuf/message_factory.py +++ b/libs/protobuf/python/google/protobuf/message_factory.py @@ -60,6 +60,9 @@ class MessageFactory(object): """Initializes a new factory.""" self.pool = pool or descriptor_pool.DescriptorPool() + # local cache of all classes built from protobuf descriptors + self._classes = {} + def GetPrototype(self, descriptor): """Obtains a proto2 message class based on the passed in descriptor. @@ -72,11 +75,14 @@ class MessageFactory(object): Returns: A class describing the passed in descriptor. """ - concrete_class = getattr(descriptor, '_concrete_class', None) - if concrete_class: - return concrete_class - result_class = self.CreatePrototype(descriptor) - return result_class + if descriptor not in self._classes: + result_class = self.CreatePrototype(descriptor) + # The assignment to _classes is redundant for the base implementation, but + # might avoid confusion in cases where CreatePrototype gets overridden and + # does not call the base implementation. + self._classes[descriptor] = result_class + return result_class + return self._classes[descriptor] def CreatePrototype(self, descriptor): """Builds a proto2 message class based on the passed in descriptor. @@ -101,11 +107,16 @@ class MessageFactory(object): '__module__': None, }) result_class._FACTORY = self # pylint: disable=protected-access + # Assign in _classes before doing recursive calls to avoid infinite + # recursion. + self._classes[descriptor] = result_class for field in descriptor.fields: if field.message_type: self.GetPrototype(field.message_type) for extension in result_class.DESCRIPTOR.extensions: - extended_class = self.GetPrototype(extension.containing_type) + if extension.containing_type not in self._classes: + self.GetPrototype(extension.containing_type) + extended_class = self._classes[extension.containing_type] extended_class.RegisterExtension(extension) if extension.message_type: self.GetPrototype(extension.message_type) @@ -141,7 +152,9 @@ class MessageFactory(object): # an error if they were different. for extension in file_desc.extensions_by_name.values(): - extended_class = self.GetPrototype(extension.containing_type) + if extension.containing_type not in self._classes: + self.GetPrototype(extension.containing_type) + extended_class = self._classes[extension.containing_type] extended_class.RegisterExtension(extension) if extension.message_type: self.GetPrototype(extension.message_type) diff --git a/libs/protobuf/python/google/protobuf/proto_api.h b/libs/protobuf/python/google/protobuf/proto_api.h index 4e910e0..9969a91 100644 --- a/libs/protobuf/python/google/protobuf/proto_api.h +++ b/libs/protobuf/python/google/protobuf/proto_api.h @@ -48,8 +48,8 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/descriptor_database.h" -#include "google/protobuf/message.h" +#include +#include namespace google { namespace protobuf { @@ -133,7 +133,8 @@ struct PyProto_API { }; inline const char* PyProtoAPICapsuleName() { - static const char kCapsuleName[] = "google.protobuf.pyext._message.proto_API"; + static const char kCapsuleName[] = + "google.protobuf.pyext._message.proto_API"; return kCapsuleName; } diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor.cc b/libs/protobuf/python/google/protobuf/pyext/descriptor.cc index fc97b0f..1625312 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor.cc +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor.cc @@ -30,7 +30,7 @@ // Author: petar@google.com (Petar Petrov) -#include "google/protobuf/pyext/descriptor.h" +#include #define PY_SSIZE_T_CLEAN #include @@ -40,15 +40,15 @@ #include #include -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/pyext/descriptor_containers.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/coded_stream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ @@ -58,37 +58,6 @@ : 0) \ : PyBytes_AsStringAndSize(ob, (charpp), (sizep))) -#if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION) -static PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) -{ - Py_INCREF(frame->f_code); - return frame->f_code; -} - -static PyFrameObject* PyFrame_GetBack(PyFrameObject *frame) -{ - Py_XINCREF(frame->f_back); - return frame->f_back; -} -#endif - -#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION) -static PyObject* PyFrame_GetLocals(PyFrameObject *frame) -{ - if (PyFrame_FastToLocalsWithError(frame) < 0) { - return NULL; - } - Py_INCREF(frame->f_locals); - return frame->f_locals; -} - -static PyObject* PyFrame_GetGlobals(PyFrameObject *frame) -{ - Py_INCREF(frame->f_globals); - return frame->f_globals; -} -#endif - namespace google { namespace protobuf { namespace python { @@ -127,66 +96,48 @@ bool _CalledFromGeneratedFile(int stacklevel) { // This check is not critical and is somewhat difficult to implement correctly // in PyPy. PyFrameObject* frame = PyEval_GetFrame(); - PyCodeObject* frame_code = nullptr; - PyObject* frame_globals = nullptr; - PyObject* frame_locals = nullptr; - bool result = false; - if (frame == nullptr) { - goto exit; + return false; } - Py_INCREF(frame); while (stacklevel-- > 0) { - PyFrameObject* next_frame = PyFrame_GetBack(frame); - Py_DECREF(frame); - frame = next_frame; + frame = frame->f_back; if (frame == nullptr) { - goto exit; + return false; } } - frame_code = PyFrame_GetCode(frame); - if (frame_code->co_filename == nullptr) { - goto exit; + if (frame->f_code->co_filename == nullptr) { + return false; } char* filename; Py_ssize_t filename_size; - if (PyString_AsStringAndSize(frame_code->co_filename, + if (PyString_AsStringAndSize(frame->f_code->co_filename, &filename, &filename_size) < 0) { // filename is not a string. PyErr_Clear(); - goto exit; + return false; } if ((filename_size < 3) || (strcmp(&filename[filename_size - 3], ".py") != 0)) { // Cython's stack does not have .py file name and is not at global module // scope. - result = true; - goto exit; + return true; } if (filename_size < 7) { // filename is too short. - goto exit; + return false; } if (strcmp(&filename[filename_size - 7], "_pb2.py") != 0) { // Filename is not ending with _pb2. - goto exit; + return false; } - frame_globals = PyFrame_GetGlobals(frame); - frame_locals = PyFrame_GetLocals(frame); - if (frame_globals != frame_locals) { + if (frame->f_globals != frame->f_locals) { // Not at global module scope - goto exit; + return false; } #endif - result = true; -exit: - Py_XDECREF(frame_globals); - Py_XDECREF(frame_locals); - Py_XDECREF(frame_code); - Py_XDECREF(frame); - return result; + return true; } // If the calling code is not a _pb2.py file, raise AttributeError. @@ -539,12 +490,6 @@ static PyObject* GetConcreteClass(PyBaseDescriptor* self, void *closure) { GetDescriptorPool_FromPool( _GetDescriptor(self)->file()->pool())->py_message_factory, _GetDescriptor(self))); - - if (concrete_class == nullptr) { - PyErr_Clear(); - return nullptr; - } - Py_XINCREF(concrete_class); return concrete_class->AsPyObject(); } @@ -1796,8 +1741,7 @@ static PyObject* FindMethodByName(PyBaseDescriptor *self, PyObject* arg) { } const MethodDescriptor* method_descriptor = - _GetDescriptor(self)->FindMethodByName( - absl::string_view(name, name_size)); + _GetDescriptor(self)->FindMethodByName(StringParam(name, name_size)); if (method_descriptor == nullptr) { PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name); return nullptr; diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor.h b/libs/protobuf/python/google/protobuf/pyext/descriptor.h index 8559c66..d97e2f8 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor.h +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor.h @@ -36,12 +36,15 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { namespace python { +// Should match the type of ConstStringParam. +using StringParam = std::string; + extern PyTypeObject PyMessageDescriptor_Type; extern PyTypeObject PyFieldDescriptor_Type; extern PyTypeObject PyEnumDescriptor_Type; diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor_containers.cc b/libs/protobuf/python/google/protobuf/pyext/descriptor_containers.cc index f38fdc7..a87155b 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor_containers.cc +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor_containers.cc @@ -49,21 +49,14 @@ // because the Python API is based on C, and does not play well with C++ // inheritance. -// clang-format off #define PY_SSIZE_T_CLEAN -// This inclusion must appear before all the others. #include -#include - -#include "google/protobuf/pyext/descriptor_containers.h" -// clang-format on - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "absl/strings/string_view.h" +#include +#include +#include +#include +#include #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ @@ -82,9 +75,9 @@ struct PyContainer; typedef int (*CountMethod)(PyContainer* self); typedef const void* (*GetByIndexMethod)(PyContainer* self, int index); typedef const void* (*GetByNameMethod)(PyContainer* self, - absl::string_view name); + ConstStringParam name); typedef const void* (*GetByCamelcaseNameMethod)(PyContainer* self, - absl::string_view name); + ConstStringParam name); typedef const void* (*GetByNumberMethod)(PyContainer* self, int index); typedef PyObject* (*NewObjectFromItemMethod)(const void* descriptor); typedef const std::string& (*GetItemNameMethod)(const void* descriptor); @@ -182,8 +175,8 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) { } return false; } - *item = self->container_def->get_by_name_fn( - self, absl::string_view(name, name_size)); + *item = self->container_def->get_by_name_fn(self, + StringParam(name, name_size)); return true; } case PyContainer::KIND_BYCAMELCASENAME: { @@ -199,7 +192,7 @@ static bool _GetItemByKey(PyContainer* self, PyObject* key, const void** item) { return false; } *item = self->container_def->get_by_camelcase_name_fn( - self, absl::string_view(camelcase_name, name_size)); + self, StringParam(camelcase_name, name_size)); return true; } case PyContainer::KIND_BYNUMBER: { @@ -965,12 +958,12 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->field_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindFieldByName(name); } static const void* GetByCamelcaseName(PyContainer* self, - absl::string_view name) { + ConstStringParam name) { return GetDescriptor(self)->FindFieldByCamelcaseName(name); } @@ -1035,7 +1028,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->nested_type_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindNestedTypeByName(name); } @@ -1087,7 +1080,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->enum_type_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindEnumTypeByName(name); } @@ -1150,7 +1143,7 @@ static int Count(PyContainer* self) { return count; } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindEnumValueByName(name); } @@ -1201,7 +1194,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->extension_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindExtensionByName(name); } @@ -1253,7 +1246,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->oneof_decl_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindOneofByName(name); } @@ -1311,7 +1304,7 @@ static const void* GetByIndex(PyContainer* self, int index) { return GetDescriptor(self)->value(index); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindValueByName(name); } @@ -1415,7 +1408,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->method_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindMethodByName(name); } @@ -1469,7 +1462,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->message_type_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindMessageTypeByName(name); } @@ -1509,7 +1502,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->enum_type_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindEnumTypeByName(name); } @@ -1549,7 +1542,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->extension_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindExtensionByName(name); } @@ -1589,7 +1582,7 @@ static int Count(PyContainer* self) { return GetDescriptor(self)->service_count(); } -static const void* GetByName(PyContainer* self, absl::string_view name) { +static const void* GetByName(PyContainer* self, ConstStringParam name) { return GetDescriptor(self)->FindServiceByName(name); } diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor_database.cc b/libs/protobuf/python/google/protobuf/pyext/descriptor_database.cc index e547306..f87f23d 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor_database.cc +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor_database.cc @@ -31,17 +31,15 @@ // This file defines a C++ DescriptorDatabase, which wraps a Python Database // and delegate all its operations to Python methods. -#include "google/protobuf/pyext/descriptor_database.h" +#include #include -#include -#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor_database.h b/libs/protobuf/python/google/protobuf/pyext/descriptor_database.h index 108a858..5621a22 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor_database.h +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor_database.h @@ -34,10 +34,7 @@ #define PY_SSIZE_T_CLEAN #include -#include -#include - -#include "google/protobuf/descriptor_database.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.cc b/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.cc index db14ae6..2f39281 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.cc +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.cc @@ -30,22 +30,19 @@ // Implements the DescriptorPool, which collects all descriptors. -#include #include -#include -#include #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_database.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "absl/strings/string_view.h" +#include +#include +#include +#include +#include +#include +#include +#include #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ @@ -249,7 +246,7 @@ static PyObject* FindMessageByName(PyObject* self, PyObject* arg) { const Descriptor* message_descriptor = reinterpret_cast(self)->pool->FindMessageTypeByName( - absl::string_view(name, name_size)); + StringParam(name, name_size)); if (message_descriptor == nullptr) { return SetErrorFromCollector( @@ -273,7 +270,7 @@ static PyObject* FindFileByName(PyObject* self, PyObject* arg) { PyDescriptorPool* py_pool = reinterpret_cast(self); const FileDescriptor* file_descriptor = - py_pool->pool->FindFileByName(absl::string_view(name, name_size)); + py_pool->pool->FindFileByName(StringParam(name, name_size)); if (file_descriptor == nullptr) { return SetErrorFromCollector(py_pool->error_collector, name, "file"); @@ -289,7 +286,7 @@ PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* arg) { } const FieldDescriptor* field_descriptor = - self->pool->FindFieldByName(absl::string_view(name, name_size)); + self->pool->FindFieldByName(StringParam(name, name_size)); if (field_descriptor == nullptr) { return SetErrorFromCollector(self->error_collector, name, "field"); } @@ -310,7 +307,7 @@ PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg) { } const FieldDescriptor* field_descriptor = - self->pool->FindExtensionByName(absl::string_view(name, name_size)); + self->pool->FindExtensionByName(StringParam(name, name_size)); if (field_descriptor == nullptr) { return SetErrorFromCollector(self->error_collector, name, "extension field"); @@ -332,7 +329,7 @@ PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg) { } const EnumDescriptor* enum_descriptor = - self->pool->FindEnumTypeByName(absl::string_view(name, name_size)); + self->pool->FindEnumTypeByName(StringParam(name, name_size)); if (enum_descriptor == nullptr) { return SetErrorFromCollector(self->error_collector, name, "enum"); } @@ -353,7 +350,7 @@ PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg) { } const OneofDescriptor* oneof_descriptor = - self->pool->FindOneofByName(absl::string_view(name, name_size)); + self->pool->FindOneofByName(StringParam(name, name_size)); if (oneof_descriptor == nullptr) { return SetErrorFromCollector(self->error_collector, name, "oneof"); } @@ -375,7 +372,7 @@ static PyObject* FindServiceByName(PyObject* self, PyObject* arg) { const ServiceDescriptor* service_descriptor = reinterpret_cast(self)->pool->FindServiceByName( - absl::string_view(name, name_size)); + StringParam(name, name_size)); if (service_descriptor == nullptr) { return SetErrorFromCollector( reinterpret_cast(self)->error_collector, name, @@ -395,7 +392,7 @@ static PyObject* FindMethodByName(PyObject* self, PyObject* arg) { const MethodDescriptor* method_descriptor = reinterpret_cast(self)->pool->FindMethodByName( - absl::string_view(name, name_size)); + StringParam(name, name_size)); if (method_descriptor == nullptr) { return SetErrorFromCollector( reinterpret_cast(self)->error_collector, name, @@ -415,7 +412,7 @@ static PyObject* FindFileContainingSymbol(PyObject* self, PyObject* arg) { const FileDescriptor* file_descriptor = reinterpret_cast(self)->pool->FindFileContainingSymbol( - absl::string_view(name, name_size)); + StringParam(name, name_size)); if (file_descriptor == nullptr) { return SetErrorFromCollector( reinterpret_cast(self)->error_collector, name, diff --git a/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.h b/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.h index 851cf31..5d3c3a9 100644 --- a/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.h +++ b/libs/protobuf/python/google/protobuf/pyext/descriptor_pool.h @@ -35,7 +35,7 @@ #include #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/extension_dict.cc b/libs/protobuf/python/google/protobuf/pyext/extension_dict.cc index 806af4f..66703da 100644 --- a/libs/protobuf/python/google/protobuf/pyext/extension_dict.cc +++ b/libs/protobuf/python/google/protobuf/pyext/extension_dict.cc @@ -31,25 +31,23 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include "google/protobuf/pyext/extension_dict.h" +#include #include #include -#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/repeated_composite_container.h" -#include "google/protobuf/pyext/repeated_scalar_container.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "absl/strings/string_view.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ @@ -127,9 +125,8 @@ static void DeallocExtensionIterator(PyObject* _self) { ExtensionIterator* self = reinterpret_cast(_self); self->fields.clear(); Py_XDECREF(self->extension_dict); - freefunc tp_free = Py_TYPE(_self)->tp_free; self->~ExtensionIterator(); - (*tp_free)(_self); + Py_TYPE(_self)->tp_free(_self); } PyObject* subscript(ExtensionDict* self, PyObject* key) { @@ -241,11 +238,11 @@ PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) { PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool; const FieldDescriptor* message_extension = - pool->pool->FindExtensionByName(absl::string_view(name, name_size)); + pool->pool->FindExtensionByName(StringParam(name, name_size)); if (message_extension == nullptr) { // Is is the name of a message set extension? const Descriptor* message_descriptor = - pool->pool->FindMessageTypeByName(absl::string_view(name, name_size)); + pool->pool->FindMessageTypeByName(StringParam(name, name_size)); if (message_descriptor && message_descriptor->extension_count() > 0) { const FieldDescriptor* extension = message_descriptor->extension(0); if (extension->is_extension() && diff --git a/libs/protobuf/python/google/protobuf/pyext/extension_dict.h b/libs/protobuf/python/google/protobuf/pyext/extension_dict.h index c5c2875..86d2451 100644 --- a/libs/protobuf/python/google/protobuf/pyext/extension_dict.h +++ b/libs/protobuf/python/google/protobuf/pyext/extension_dict.h @@ -37,7 +37,7 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/pyext/message.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/field.cc b/libs/protobuf/python/google/protobuf/pyext/field.cc index daa95d0..0d3b0b9 100644 --- a/libs/protobuf/python/google/protobuf/pyext/field.cc +++ b/libs/protobuf/python/google/protobuf/pyext/field.cc @@ -28,11 +28,11 @@ // (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/pyext/field.h" +#include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/message.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/map_container.cc b/libs/protobuf/python/google/protobuf/pyext/map_container.cc index 76c4d88..e8a6888 100644 --- a/libs/protobuf/python/google/protobuf/pyext/map_container.cc +++ b/libs/protobuf/python/google/protobuf/pyext/map_container.cc @@ -30,21 +30,21 @@ // Author: haberman@google.com (Josh Haberman) -#include "google/protobuf/pyext/map_container.h" +#include #include #include -#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/map.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/message.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/repeated_composite_container.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/map_container.h b/libs/protobuf/python/google/protobuf/pyext/map_container.h index d90d3a5..af334d2 100644 --- a/libs/protobuf/python/google/protobuf/pyext/map_container.h +++ b/libs/protobuf/python/google/protobuf/pyext/map_container.h @@ -36,9 +36,9 @@ #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" -#include "google/protobuf/pyext/message.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/message.cc b/libs/protobuf/python/google/protobuf/pyext/message.cc index ebad6b4..2c4a957 100644 --- a/libs/protobuf/python/google/protobuf/pyext/message.cc +++ b/libs/protobuf/python/google/protobuf/pyext/message.cc @@ -31,18 +31,17 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include "google/protobuf/pyext/message.h" +#include #include // A Python header file. #include #include #include -#include #include #include -#include "absl/strings/match.h" +#include #ifndef PyVarObject_HEAD_INIT #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size, @@ -50,34 +49,33 @@ #ifndef Py_TYPE #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #endif -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/extension_dict.h" -#include "google/protobuf/pyext/field.h" -#include "google/protobuf/pyext/map_container.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/repeated_composite_container.h" -#include "google/protobuf/pyext/repeated_scalar_container.h" -#include "google/protobuf/pyext/safe_numerics.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "google/protobuf/pyext/unknown_field_set.h" -#include "google/protobuf/pyext/unknown_fields.h" -#include "google/protobuf/util/message_differencer.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/strtod.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on #define PyString_AsString(ob) \ @@ -90,9 +88,6 @@ : 0) \ : PyBytes_AsStringAndSize(ob, (charpp), (sizep))) -#define PROTOBUF_PYTHON_PUBLIC "google.protobuf" -#define PROTOBUF_PYTHON_INTERNAL "google.protobuf.internal" - namespace google { namespace protobuf { namespace python { @@ -251,8 +246,8 @@ static PyObject* New(PyTypeObject* type, PyObject* args, PyObject* kwargs) { ScopedPyObjectPtr new_args; if (WKT_classes == nullptr) { - ScopedPyObjectPtr well_known_types( - PyImport_ImportModule(PROTOBUF_PYTHON_INTERNAL ".well_known_types")); + ScopedPyObjectPtr well_known_types(PyImport_ImportModule( + "google.protobuf.internal.well_known_types")); GOOGLE_DCHECK(well_known_types != nullptr); WKT_classes = PyObject_GetAttrString(well_known_types.get(), "WKTBASES"); @@ -410,7 +405,7 @@ static PyObject* GetClassAttribute(CMessageClass *self, PyObject* name) { Py_ssize_t attr_size; static const char kSuffix[] = "_FIELD_NUMBER"; if (PyString_AsStringAndSize(name, &attr, &attr_size) >= 0 && - absl::EndsWith(absl::string_view(attr, attr_size), kSuffix)) { + HasSuffixString(StringPiece(attr, attr_size), kSuffix)) { std::string field_name(attr, attr_size - sizeof(kSuffix) + 1); LowerString(&field_name); @@ -915,7 +910,7 @@ static PyObject* GetIntegerEnumValue(const FieldDescriptor& descriptor, return nullptr; } const EnumValueDescriptor* enum_value_descriptor = - enum_descriptor->FindValueByName(absl::string_view(enum_label, size)); + enum_descriptor->FindValueByName(StringParam(enum_label, size)); if (enum_value_descriptor == nullptr) { PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", enum_label); return nullptr; @@ -1342,7 +1337,7 @@ int HasFieldByDescriptor(CMessage* self, } const FieldDescriptor* FindFieldWithOneofs(const Message* message, - absl::string_view field_name, + ConstStringParam field_name, bool* in_oneof) { *in_oneof = false; const Descriptor* descriptor = message->GetDescriptor(); @@ -1391,8 +1386,8 @@ PyObject* HasField(CMessage* self, PyObject* arg) { Message* message = self->message; bool is_in_oneof; - const FieldDescriptor* field_descriptor = FindFieldWithOneofs( - message, absl::string_view(field_name, size), &is_in_oneof); + const FieldDescriptor* field_descriptor = + FindFieldWithOneofs(message, StringParam(field_name, size), &is_in_oneof); if (field_descriptor == nullptr) { if (!is_in_oneof) { PyErr_Format(PyExc_ValueError, "Protocol message %s has no field %s.", @@ -1576,7 +1571,7 @@ PyObject* ClearField(CMessage* self, PyObject* arg) { AssureWritable(self); bool is_in_oneof; const FieldDescriptor* field_descriptor = FindFieldWithOneofs( - self->message, absl::string_view(field_name, field_size), &is_in_oneof); + self->message, StringParam(field_name, field_size), &is_in_oneof); if (field_descriptor == nullptr) { if (is_in_oneof) { // We gave the name of a oneof, and none of its fields are set. @@ -1886,7 +1881,7 @@ static PyObject* MergeFromString(CMessage* self, PyObject* arg) { const char* ptr; internal::ParseContext ctx( depth, false, &ptr, - absl::string_view(static_cast(data.buf), data.len)); + StringPiece(static_cast(data.buf), data.len)); PyBuffer_Release(&data); ctx.data().pool = factory->pool->pool; ctx.data().factory = factory->message_factory; @@ -1978,7 +1973,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) { if (PyString_AsStringAndSize(arg, &name_data, &name_size) < 0) return nullptr; const OneofDescriptor* oneof_desc = self->message->GetDescriptor()->FindOneofByName( - absl::string_view(name_data, name_size)); + StringParam(name_data, name_size)); if (oneof_desc == nullptr) { PyErr_Format(PyExc_ValueError, "Protocol message has no oneof \"%s\" field.", name_data); @@ -2377,7 +2372,7 @@ PyObject* DeepCopy(CMessage* self, PyObject* arg) { PyObject* ToUnicode(CMessage* self) { // Lazy import to prevent circular dependencies ScopedPyObjectPtr text_format( - PyImport_ImportModule(PROTOBUF_PYTHON_PUBLIC ".text_format")); + PyImport_ImportModule("google.protobuf.text_format")); if (text_format == nullptr) { return nullptr; } @@ -2678,22 +2673,22 @@ CMessage* CMessage::BuildSubMessageFromPointer( if (!this->child_submessages) { this->child_submessages = new CMessage::SubMessagesMap(); } - auto it = this->child_submessages->find(sub_message); - if (it != this->child_submessages->end()) { - Py_INCREF(it->second); - return it->second; - } + CMessage* cmsg = FindPtrOrNull( + *this->child_submessages, sub_message); + if (cmsg) { + Py_INCREF(cmsg); + } else { + cmsg = cmessage::NewEmptyMessage(message_class); - CMessage* cmsg = cmessage::NewEmptyMessage(message_class); - - if (cmsg == nullptr) { - return nullptr; + if (cmsg == nullptr) { + return nullptr; + } + cmsg->message = sub_message; + Py_INCREF(this); + cmsg->parent = this; + cmsg->parent_field_descriptor = field_descriptor; + cmessage::SetSubmessage(this, cmsg); } - cmsg->message = sub_message; - Py_INCREF(this); - cmsg->parent = this; - cmsg->parent_field_descriptor = field_descriptor; - cmessage::SetSubmessage(this, cmsg); return cmsg; } @@ -2701,10 +2696,11 @@ CMessage* CMessage::MaybeReleaseSubMessage(Message* sub_message) { if (!this->child_submessages) { return nullptr; } - auto it = this->child_submessages->find(sub_message); - if (it == this->child_submessages->end()) return nullptr; - CMessage* released = it->second; - + CMessage* released = FindPtrOrNull( + *this->child_submessages, sub_message); + if (!released) { + return nullptr; + } // The target message will now own its content. Py_CLEAR(released->parent); released->parent_field_descriptor = nullptr; @@ -3038,8 +3034,8 @@ bool InitProto2MessageModule(PyObject *m) { PyModule_AddObject(m, "MethodDescriptor", reinterpret_cast(&PyMethodDescriptor_Type)); - PyObject* enum_type_wrapper = - PyImport_ImportModule(PROTOBUF_PYTHON_INTERNAL ".enum_type_wrapper"); + PyObject* enum_type_wrapper = PyImport_ImportModule( + "google.protobuf.internal.enum_type_wrapper"); if (enum_type_wrapper == nullptr) { return false; } @@ -3047,8 +3043,8 @@ bool InitProto2MessageModule(PyObject *m) { PyObject_GetAttrString(enum_type_wrapper, "EnumTypeWrapper"); Py_DECREF(enum_type_wrapper); - PyObject* message_module = - PyImport_ImportModule(PROTOBUF_PYTHON_PUBLIC ".message"); + PyObject* message_module = PyImport_ImportModule( + "google.protobuf.message"); if (message_module == nullptr) { return false; } diff --git a/libs/protobuf/python/google/protobuf/pyext/message.h b/libs/protobuf/python/google/protobuf/pyext/message.h index 1b0172f..b17daa5 100644 --- a/libs/protobuf/python/google/protobuf/pyext/message.h +++ b/libs/protobuf/python/google/protobuf/pyext/message.h @@ -42,7 +42,7 @@ #include #include -#include "google/protobuf/stubs/common.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/message_factory.cc b/libs/protobuf/python/google/protobuf/pyext/message_factory.cc index 27aa5e4..bc44dd4 100644 --- a/libs/protobuf/python/google/protobuf/pyext/message_factory.cc +++ b/libs/protobuf/python/google/protobuf/pyext/message_factory.cc @@ -29,16 +29,15 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include #define PyString_AsStringAndSize(ob, charpp, sizep) \ (PyUnicode_Check(ob) \ diff --git a/libs/protobuf/python/google/protobuf/pyext/message_factory.h b/libs/protobuf/python/google/protobuf/pyext/message_factory.h index 1d911a8..7dfe425 100644 --- a/libs/protobuf/python/google/protobuf/pyext/message_factory.h +++ b/libs/protobuf/python/google/protobuf/pyext/message_factory.h @@ -35,8 +35,8 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/message_module.cc b/libs/protobuf/python/google/protobuf/pyext/message_module.cc index f469206..2d3c1d2 100644 --- a/libs/protobuf/python/google/protobuf/pyext/message_module.cc +++ b/libs/protobuf/python/google/protobuf/pyext/message_module.cc @@ -31,12 +31,12 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/message_lite.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/proto_api.h" +#include +#include +#include +#include +#include +#include namespace { diff --git a/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc b/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc index a191670..0b63f82 100644 --- a/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +++ b/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc @@ -31,21 +31,22 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include "google/protobuf/pyext/repeated_composite_container.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/message_factory.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.h b/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.h index 8964374..6fa6e17 100644 --- a/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +++ b/libs/protobuf/python/google/protobuf/pyext/repeated_composite_container.h @@ -37,7 +37,7 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/pyext/message.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc b/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc index 57746dc..f4a8df2 100644 --- a/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -31,21 +31,20 @@ // Author: anuraag@google.com (Anuraag Agrawal) // Author: tibell@google.com (Johan Tibell) -#include "google/protobuf/pyext/repeated_scalar_container.h" +#include #include #include -#include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/pyext/descriptor.h" -#include "google/protobuf/pyext/descriptor_pool.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #define PyString_AsString(ob) \ (PyUnicode_Check(ob) ? PyUnicode_AsUTF8(ob) : PyBytes_AsString(ob)) diff --git a/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h b/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h index 0189886..67423ab 100644 --- a/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +++ b/libs/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h @@ -37,8 +37,8 @@ #define PY_SSIZE_T_CLEAN #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/pyext/message.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/safe_numerics.h b/libs/protobuf/python/google/protobuf/pyext/safe_numerics.h index 0d4dd25..93ae640 100644 --- a/libs/protobuf/python/google/protobuf/pyext/safe_numerics.h +++ b/libs/protobuf/python/google/protobuf/pyext/safe_numerics.h @@ -34,8 +34,8 @@ #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h b/libs/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h index d39a4d1..ad3fa94 100644 --- a/libs/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +++ b/libs/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h @@ -33,6 +33,8 @@ #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__ #define GOOGLE_PROTOBUF_PYTHON_CPP_SCOPED_PYOBJECT_PTR_H__ +#include + #define PY_SSIZE_T_CLEAN #include namespace google { @@ -48,8 +50,6 @@ class ScopedPythonPtr { // The reference count of the specified py_object is not incremented. explicit ScopedPythonPtr(PyObjectStruct* py_object = nullptr) : ptr_(py_object) {} - ScopedPythonPtr(const ScopedPythonPtr&) = delete; - ScopedPythonPtr& operator=(const ScopedPythonPtr&) = delete; // If a PyObject is owned, decrement its reference count. ~ScopedPythonPtr() { Py_XDECREF(ptr_); } @@ -89,6 +89,8 @@ class ScopedPythonPtr { private: PyObjectStruct* ptr_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedPythonPtr); }; typedef ScopedPythonPtr ScopedPyObjectPtr; diff --git a/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.cc b/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.cc index 5cc48e7..42f9bbc 100644 --- a/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.cc +++ b/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.cc @@ -28,7 +28,7 @@ // (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/pyext/unknown_field_set.h" +#include #define PY_SSIZE_T_CLEAN #include @@ -36,11 +36,11 @@ #include #include -#include "google/protobuf/message.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.h b/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.h index 92a889d..3fa764d 100644 --- a/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.h +++ b/libs/protobuf/python/google/protobuf/pyext/unknown_field_set.h @@ -37,7 +37,7 @@ #include #include -#include "google/protobuf/pyext/message.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/unknown_fields.cc b/libs/protobuf/python/google/protobuf/pyext/unknown_fields.cc index 9f27f26..dcd63b2 100644 --- a/libs/protobuf/python/google/protobuf/pyext/unknown_fields.cc +++ b/libs/protobuf/python/google/protobuf/pyext/unknown_fields.cc @@ -28,18 +28,18 @@ // (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/pyext/unknown_fields.h" +#include #define PY_SSIZE_T_CLEAN #include #include #include -#include "google/protobuf/message.h" -#include "google/protobuf/pyext/message.h" -#include "google/protobuf/pyext/scoped_pyobject_ptr.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/pyext/unknown_fields.h b/libs/protobuf/python/google/protobuf/pyext/unknown_fields.h index 81ee1a9..e7b0b35 100644 --- a/libs/protobuf/python/google/protobuf/pyext/unknown_fields.h +++ b/libs/protobuf/python/google/protobuf/pyext/unknown_fields.h @@ -37,7 +37,7 @@ #include #include -#include "google/protobuf/pyext/message.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/python/google/protobuf/symbol_database.py b/libs/protobuf/python/google/protobuf/symbol_database.py index ed5fce3..fdcf8cf 100644 --- a/libs/protobuf/python/google/protobuf/symbol_database.py +++ b/libs/protobuf/python/google/protobuf/symbol_database.py @@ -66,9 +66,6 @@ from google.protobuf import message_factory class SymbolDatabase(message_factory.MessageFactory): """A database of Python generated symbols.""" - # local cache of registered classes. - _classes = {} - def RegisterMessage(self, message): """Registers the given message type in the local database. diff --git a/libs/protobuf/python/google/protobuf/text_encoding.py b/libs/protobuf/python/google/protobuf/text_encoding.py index 1955b6a..759cf11 100644 --- a/libs/protobuf/python/google/protobuf/text_encoding.py +++ b/libs/protobuf/python/google/protobuf/text_encoding.py @@ -53,7 +53,8 @@ for byte, string in _cescape_chr_to_symbol_map.items(): del byte, string -def CEscape(text, as_utf8) -> str: +def CEscape(text, as_utf8): + # type: (...) -> str """Escape a bytes string for use in an text protocol buffer. Args: @@ -82,7 +83,8 @@ def CEscape(text, as_utf8) -> str: _CUNESCAPE_HEX = re.compile(r'(\\+)x([0-9a-fA-F])(?![0-9a-fA-F])') -def CUnescape(text: str) -> bytes: +def CUnescape(text): + # type: (str) -> bytes """Unescape a text string with C-style escape sequences to UTF-8 bytes. Args: diff --git a/libs/protobuf/python/google/protobuf/text_format.py b/libs/protobuf/python/google/protobuf/text_format.py index cab7cb7..a6d8bcf 100644 --- a/libs/protobuf/python/google/protobuf/text_format.py +++ b/libs/protobuf/python/google/protobuf/text_format.py @@ -67,7 +67,6 @@ _FLOAT_INFINITY = re.compile('-?inf(?:inity)?f?$', re.IGNORECASE) _FLOAT_NAN = re.compile('nanf?$', re.IGNORECASE) _QUOTES = frozenset(("'", '"')) _ANY_FULL_TYPE_NAME = 'google.protobuf.Any' -_DEBUG_STRING_SILENT_MARKER = '\t ' class Error(Exception): @@ -126,7 +125,8 @@ def MessageToString( indent=0, message_formatter=None, print_unknown_fields=False, - force_colon=False) -> str: + force_colon=False): + # type: (...) -> str """Convert protobuf message to text format. Double values can be formatted compactly with 15 digits of @@ -191,7 +191,8 @@ def MessageToString( return result -def MessageToBytes(message, **kwargs) -> bytes: +def MessageToBytes(message, **kwargs): + # type: (...) -> bytes """Convert protobuf message to encoded text format. See MessageToString.""" text = MessageToString(message, **kwargs) if isinstance(text, bytes): @@ -557,7 +558,7 @@ class _Printer(object): # For groups, use the capitalized name. out.write(field.message_type.name) else: - out.write(field.name) + out.write(field.name) if (self.force_colon or field.cpp_type != descriptor.FieldDescriptor.CPPTYPE_MESSAGE): @@ -855,15 +856,10 @@ class _Parser(object): ParseError: On text parsing problems. """ # Tokenize expects native str lines. - try: - str_lines = ( - line if isinstance(line, str) else line.decode('utf-8') - for line in lines) - except UnicodeDecodeError as e: - raise self._StringParseError(e) + str_lines = ( + line if isinstance(line, str) else line.decode('utf-8') + for line in lines) tokenizer = Tokenizer(str_lines) - if message: - self.root_type = message.DESCRIPTOR.full_name while not tokenizer.AtEnd(): self._MergeField(tokenizer, message) @@ -883,8 +879,6 @@ class _Parser(object): type_url_prefix, packed_type_name = self._ConsumeAnyTypeUrl(tokenizer) tokenizer.Consume(']') tokenizer.TryConsume(':') - self._DetectSilentMarker(tokenizer, - type_url_prefix + '/' + packed_type_name) if tokenizer.TryConsume('<'): expanded_any_end_token = '>' else: @@ -923,6 +917,8 @@ class _Parser(object): # pylint: disable=protected-access field = message.Extensions._FindExtensionByName(name) # pylint: enable=protected-access + + if not field: if self.allow_unknown_extension: field = None @@ -982,11 +978,9 @@ class _Parser(object): if field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_MESSAGE: tokenizer.TryConsume(':') - self._DetectSilentMarker(tokenizer, field.full_name) merger = self._MergeMessageField else: tokenizer.Consume(':') - self._DetectSilentMarker(tokenizer, field.full_name) merger = self._MergeScalarField if (field.label == descriptor.FieldDescriptor.LABEL_REPEATED and @@ -1004,19 +998,13 @@ class _Parser(object): else: # Proto field is unknown. assert (self.allow_unknown_extension or self.allow_unknown_field) - self._SkipFieldContents(tokenizer, name) + _SkipFieldContents(tokenizer) # For historical reasons, fields may optionally be separated by commas or # semicolons. if not tokenizer.TryConsume(','): tokenizer.TryConsume(';') - def _LogSilentMarker(self, field_name): - pass - - def _DetectSilentMarker(self, tokenizer, field_name): - if tokenizer.contains_silent_marker_before_current_token: - self._LogSilentMarker(field_name) def _ConsumeAnyTypeUrl(self, tokenizer): """Consumes a google.protobuf.Any type URL and returns the type name.""" @@ -1172,111 +1160,105 @@ class _Parser(object): else: setattr(message, field.name, value) - def _SkipFieldContents(self, tokenizer, field_name): - """Skips over contents (value or message) of a field. - Args: - tokenizer: A tokenizer to parse the field name and values. - field_name: The field name currently being parsed. - """ - # 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 - # start with "{" or "<" which indicates the beginning of a message body. - # If there is no ":" or there is a "{" or "<" after ":", this field has - # to be a message or the input is ill-formed. - if tokenizer.TryConsume( - ':') and not tokenizer.LookingAt('{') and not tokenizer.LookingAt('<'): - self._DetectSilentMarker(tokenizer, field_name) - if tokenizer.LookingAt('['): - self._SkipRepeatedFieldValue(tokenizer) - else: - self._SkipFieldValue(tokenizer) +def _SkipFieldContents(tokenizer): + """Skips over contents (value or message) of a field. + + Args: + tokenizer: A tokenizer to parse the field name and values. + """ + # 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 + # start with "{" or "<" which indicates the beginning of a message body. + # If there is no ":" or there is a "{" or "<" after ":", this field has + # to be a message or the input is ill-formed. + if tokenizer.TryConsume( + ':') and not tokenizer.LookingAt('{') and not tokenizer.LookingAt('<'): + if tokenizer.LookingAt('['): + _SkipRepeatedFieldValue(tokenizer) else: - self._DetectSilentMarker(tokenizer, field_name) - self._SkipFieldMessage(tokenizer) + _SkipFieldValue(tokenizer) + else: + _SkipFieldMessage(tokenizer) - def _SkipField(self, tokenizer): - """Skips over a complete field (name and value/message). - Args: - tokenizer: A tokenizer to parse the field name and values. - """ - field_name = '' - if tokenizer.TryConsume('['): - # Consume extension or google.protobuf.Any type URL - field_name += '[' + tokenizer.ConsumeIdentifier() - num_identifiers = 1 - while tokenizer.TryConsume('.'): - field_name += '.' + tokenizer.ConsumeIdentifier() - num_identifiers += 1 - # This is possibly a type URL for an Any message. - if num_identifiers == 3 and tokenizer.TryConsume('/'): - field_name += '/' + tokenizer.ConsumeIdentifier() - while tokenizer.TryConsume('.'): - field_name += '.' + tokenizer.ConsumeIdentifier() - tokenizer.Consume(']') - field_name += ']' - else: - field_name += tokenizer.ConsumeIdentifierOrNumber() +def _SkipField(tokenizer): + """Skips over a complete field (name and value/message). - self._SkipFieldContents(tokenizer, field_name) - - # For historical reasons, fields may optionally be separated by commas or - # semicolons. - if not tokenizer.TryConsume(','): - tokenizer.TryConsume(';') - - def _SkipFieldMessage(self, tokenizer): - """Skips over a field message. - - Args: - tokenizer: A tokenizer to parse the field name and values. - """ - if tokenizer.TryConsume('<'): - delimiter = '>' - else: - tokenizer.Consume('{') - delimiter = '}' - - while not tokenizer.LookingAt('>') and not tokenizer.LookingAt('}'): - self._SkipField(tokenizer) - - tokenizer.Consume(delimiter) - - def _SkipFieldValue(self, tokenizer): - """Skips over a field value. - - Args: - tokenizer: A tokenizer to parse the field name and values. - - Raises: - ParseError: In case an invalid field value is found. - """ - # String/bytes tokens can come in multiple adjacent string literals. - # If we can consume one, consume as many as we can. - if tokenizer.TryConsumeByteString(): - while tokenizer.TryConsumeByteString(): - pass - return - - if (not tokenizer.TryConsumeIdentifier() and - not _TryConsumeInt64(tokenizer) and not _TryConsumeUint64(tokenizer) and - not tokenizer.TryConsumeFloat()): - raise ParseError('Invalid field value: ' + tokenizer.token) - - def _SkipRepeatedFieldValue(self, tokenizer): - """Skips over a repeated field value. - - Args: - tokenizer: A tokenizer to parse the field value. - """ - tokenizer.Consume('[') - if not tokenizer.LookingAt(']'): - self._SkipFieldValue(tokenizer) - while tokenizer.TryConsume(','): - self._SkipFieldValue(tokenizer) + Args: + tokenizer: A tokenizer to parse the field name and values. + """ + if tokenizer.TryConsume('['): + # Consume extension name. + tokenizer.ConsumeIdentifier() + while tokenizer.TryConsume('.'): + tokenizer.ConsumeIdentifier() tokenizer.Consume(']') + else: + tokenizer.ConsumeIdentifierOrNumber() + + _SkipFieldContents(tokenizer) + + # For historical reasons, fields may optionally be separated by commas or + # semicolons. + if not tokenizer.TryConsume(','): + tokenizer.TryConsume(';') + + +def _SkipFieldMessage(tokenizer): + """Skips over a field message. + + Args: + tokenizer: A tokenizer to parse the field name and values. + """ + + if tokenizer.TryConsume('<'): + delimiter = '>' + else: + tokenizer.Consume('{') + delimiter = '}' + + while not tokenizer.LookingAt('>') and not tokenizer.LookingAt('}'): + _SkipField(tokenizer) + + tokenizer.Consume(delimiter) + + +def _SkipFieldValue(tokenizer): + """Skips over a field value. + + Args: + tokenizer: A tokenizer to parse the field name and values. + + Raises: + ParseError: In case an invalid field value is found. + """ + # String/bytes tokens can come in multiple adjacent string literals. + # If we can consume one, consume as many as we can. + if tokenizer.TryConsumeByteString(): + while tokenizer.TryConsumeByteString(): + pass + return + + if (not tokenizer.TryConsumeIdentifier() and + not _TryConsumeInt64(tokenizer) and not _TryConsumeUint64(tokenizer) and + not tokenizer.TryConsumeFloat()): + raise ParseError('Invalid field value: ' + tokenizer.token) + + +def _SkipRepeatedFieldValue(tokenizer): + """Skips over a repeated field value. + + Args: + tokenizer: A tokenizer to parse the field value. + """ + tokenizer.Consume('[') + if not tokenizer.LookingAt(']'): + _SkipFieldValue(tokenizer) + while tokenizer.TryConsume(','): + _SkipFieldValue(tokenizer) + tokenizer.Consume(']') class Tokenizer(object): @@ -1317,8 +1299,6 @@ class Tokenizer(object): self._skip_comments = skip_comments self._whitespace_pattern = (skip_comments and self._WHITESPACE_OR_COMMENT or self._WHITESPACE) - self.contains_silent_marker_before_current_token = False - self._SkipWhitespace() self.NextToken() @@ -1351,8 +1331,6 @@ class Tokenizer(object): match = self._whitespace_pattern.match(self._current_line, self._column) if not match: break - self.contains_silent_marker_before_current_token = match.group(0) == ( - ' ' + _DEBUG_STRING_SILENT_MARKER) length = len(match.group(0)) self._column += length @@ -1605,7 +1583,6 @@ class Tokenizer(object): """Reads the next meaningful token.""" self._previous_line = self._line self._previous_column = self._column - self.contains_silent_marker_before_current_token = False self._column += len(self.token) self._SkipWhitespace() diff --git a/libs/protobuf/python/internal.bzl b/libs/protobuf/python/internal.bzl deleted file mode 100644 index e9bcb27..0000000 --- a/libs/protobuf/python/internal.bzl +++ /dev/null @@ -1,108 +0,0 @@ -# Internal helpers for building the Python protobuf runtime. - -def _internal_copy_files_impl(ctx): - strip_prefix = ctx.attr.strip_prefix - if strip_prefix[-1] != "/": - strip_prefix += "/" - - src_dests = [] - for src in ctx.files.srcs: - if src.short_path[:len(strip_prefix)] != strip_prefix: - fail("Source does not start with %s: %s" % - (strip_prefix, src.short_path)) - dest = ctx.actions.declare_file(src.short_path[len(strip_prefix):]) - src_dests.append([src, dest]) - - if ctx.attr.is_windows: - bat_file = ctx.actions.declare_file(ctx.label.name + "_copy.bat") - ctx.actions.write( - output = bat_file, - content = "\r\n".join([ - '@copy /Y "{}" "{}" >NUL'.format( - src.path.replace("/", "\\"), - dest.path.replace("/", "\\"), - ) - for src, dest in src_dests - ]) + "\r\n", - ) - ctx.actions.run( - inputs = ctx.files.srcs, - tools = [bat_file], - outputs = [dest for src, dest in src_dests], - executable = "cmd.exe", - arguments = ["/C", bat_file.path.replace("/", "\\")], - mnemonic = "InternalCopyFile", - progress_message = "Copying files", - use_default_shell_env = True, - ) - - else: - sh_file = ctx.actions.declare_file(ctx.label.name + "_copy.sh") - ctx.actions.write( - output = sh_file, - content = "\n".join([ - 'cp -f "{}" "{}"'.format(src.path, dest.path) - for src, dest in src_dests - ]), - ) - ctx.actions.run( - inputs = ctx.files.srcs, - tools = [sh_file], - outputs = [dest for src, dest in src_dests], - executable = "bash", - arguments = [sh_file.path], - mnemonic = "InternalCopyFile", - progress_message = "Copying files", - use_default_shell_env = True, - ) - - return [ - DefaultInfo(files = depset([dest for src, dest in src_dests])), - ] - -internal_copy_files_impl = rule( - doc = """ -Implementation for internal_copy_files macro. - -This rule implements file copying, including a compatibility mode for Windows. -""", - implementation = _internal_copy_files_impl, - attrs = { - "srcs": attr.label_list(allow_files = True, providers = [DefaultInfo]), - "strip_prefix": attr.string(), - "is_windows": attr.bool(), - }, -) - -def internal_copy_files(name, srcs, strip_prefix, **kwargs): - """Copies common proto files to the python tree. - - In order for Python imports to work, generated proto interfaces under - the google.protobuf package need to be in the same directory as other - source files. This rule copies the .proto files themselves, e.g. with - strip_prefix = 'src', 'src/google/protobuf/blah.proto' could be copied - to '/google/protobuf/blah.proto'. - - (An alternative might be to implement a separate rule to generate - Python code in a different location for the sources. However, this - would be strange behavior that doesn't match any other language's proto - library generation.) - - Args: - name: the name for the rule. - srcs: the sources. - strip_prefix: the prefix to remove from each of the paths in 'srcs'. The - remainder will be used to construct the output path. - **kwargs: common rule arguments. - - """ - internal_copy_files_impl( - name = name, - srcs = srcs, - strip_prefix = strip_prefix, - is_windows = select({ - "@bazel_tools//src/conditions:host_windows": True, - "//conditions:default": False, - }), - **kwargs - ) diff --git a/libs/protobuf/python/mox.py b/libs/protobuf/python/mox.py new file mode 100755 index 0000000..9dd8ac7 --- /dev/null +++ b/libs/protobuf/python/mox.py @@ -0,0 +1,1401 @@ +#!/usr/bin/python2.4 +# +# Copyright 2008 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file is used for testing. The original is at: +# http://code.google.com/p/pymox/ + +"""Mox, an object-mocking framework for Python. + +Mox works in the record-replay-verify paradigm. When you first create +a mock object, it is in record mode. You then programmatically set +the expected behavior of the mock object (what methods are to be +called on it, with what parameters, what they should return, and in +what order). + +Once you have set up the expected mock behavior, you put it in replay +mode. Now the mock responds to method calls just as you told it to. +If an unexpected method (or an expected method with unexpected +parameters) is called, then an exception will be raised. + +Once you are done interacting with the mock, you need to verify that +all the expected interactions occurred. (Maybe your code exited +prematurely without calling some cleanup method!) The verify phase +ensures that every expected method was called; otherwise, an exception +will be raised. + +Suggested usage / workflow: + + # Create Mox factory + my_mox = Mox() + + # Create a mock data access object + mock_dao = my_mox.CreateMock(DAOClass) + + # Set up expected behavior + mock_dao.RetrievePersonWithIdentifier('1').AndReturn(person) + mock_dao.DeletePerson(person) + + # Put mocks in replay mode + my_mox.ReplayAll() + + # Inject mock object and run test + controller.SetDao(mock_dao) + controller.DeletePersonById('1') + + # Verify all methods were called as expected + my_mox.VerifyAll() +""" + +from collections import deque +import re +import types +import unittest + +import stubout + +class Error(AssertionError): + """Base exception for this module.""" + + pass + + +class ExpectedMethodCallsError(Error): + """Raised when Verify() is called before all expected methods have been called + """ + + def __init__(self, expected_methods): + """Init exception. + + Args: + # expected_methods: A sequence of MockMethod objects that should have been + # called. + expected_methods: [MockMethod] + + Raises: + ValueError: if expected_methods contains no methods. + """ + + if not expected_methods: + raise ValueError("There must be at least one expected method") + Error.__init__(self) + self._expected_methods = expected_methods + + def __str__(self): + calls = "\n".join(["%3d. %s" % (i, m) + for i, m in enumerate(self._expected_methods)]) + return "Verify: Expected methods never called:\n%s" % (calls,) + + +class UnexpectedMethodCallError(Error): + """Raised when an unexpected method is called. + + This can occur if a method is called with incorrect parameters, or out of the + specified order. + """ + + def __init__(self, unexpected_method, expected): + """Init exception. + + Args: + # unexpected_method: MockMethod that was called but was not at the head of + # the expected_method queue. + # expected: MockMethod or UnorderedGroup the method should have + # been in. + unexpected_method: MockMethod + expected: MockMethod or UnorderedGroup + """ + + Error.__init__(self) + self._unexpected_method = unexpected_method + self._expected = expected + + def __str__(self): + return "Unexpected method call: %s. Expecting: %s" % \ + (self._unexpected_method, self._expected) + + +class UnknownMethodCallError(Error): + """Raised if an unknown method is requested of the mock object.""" + + def __init__(self, unknown_method_name): + """Init exception. + + Args: + # unknown_method_name: Method call that is not part of the mocked class's + # public interface. + unknown_method_name: str + """ + + Error.__init__(self) + self._unknown_method_name = unknown_method_name + + def __str__(self): + return "Method called is not a member of the object: %s" % \ + self._unknown_method_name + + +class Mox(object): + """Mox: a factory for creating mock objects.""" + + # A list of types that should be stubbed out with MockObjects (as + # opposed to MockAnythings). + _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType, + types.ObjectType, types.TypeType] + + def __init__(self): + """Initialize a new Mox.""" + + self._mock_objects = [] + self.stubs = stubout.StubOutForTesting() + + def CreateMock(self, class_to_mock): + """Create a new mock object. + + Args: + # class_to_mock: the class to be mocked + class_to_mock: class + + Returns: + MockObject that can be used as the class_to_mock would be. + """ + + new_mock = MockObject(class_to_mock) + self._mock_objects.append(new_mock) + return new_mock + + def CreateMockAnything(self): + """Create a mock that will accept any method calls. + + This does not enforce an interface. + """ + + new_mock = MockAnything() + self._mock_objects.append(new_mock) + return new_mock + + def ReplayAll(self): + """Set all mock objects to replay mode.""" + + for mock_obj in self._mock_objects: + mock_obj._Replay() + + + def VerifyAll(self): + """Call verify on all mock objects created.""" + + for mock_obj in self._mock_objects: + mock_obj._Verify() + + def ResetAll(self): + """Call reset on all mock objects. This does not unset stubs.""" + + for mock_obj in self._mock_objects: + mock_obj._Reset() + + def StubOutWithMock(self, obj, attr_name, use_mock_anything=False): + """Replace a method, attribute, etc. with a Mock. + + This will replace a class or module with a MockObject, and everything else + (method, function, etc) with a MockAnything. This can be overridden to + always use a MockAnything by setting use_mock_anything to True. + + Args: + obj: A Python object (class, module, instance, callable). + attr_name: str. The name of the attribute to replace with a mock. + use_mock_anything: bool. True if a MockAnything should be used regardless + of the type of attribute. + """ + + attr_to_replace = getattr(obj, attr_name) + if type(attr_to_replace) in self._USE_MOCK_OBJECT and not use_mock_anything: + stub = self.CreateMock(attr_to_replace) + else: + stub = self.CreateMockAnything() + + self.stubs.Set(obj, attr_name, stub) + + def UnsetStubs(self): + """Restore stubs to their original state.""" + + self.stubs.UnsetAll() + +def Replay(*args): + """Put mocks into Replay mode. + + Args: + # args is any number of mocks to put into replay mode. + """ + + for mock in args: + mock._Replay() + + +def Verify(*args): + """Verify mocks. + + Args: + # args is any number of mocks to be verified. + """ + + for mock in args: + mock._Verify() + + +def Reset(*args): + """Reset mocks. + + Args: + # args is any number of mocks to be reset. + """ + + for mock in args: + mock._Reset() + + +class MockAnything: + """A mock that can be used to mock anything. + + This is helpful for mocking classes that do not provide a public interface. + """ + + def __init__(self): + """ """ + self._Reset() + + def __getattr__(self, method_name): + """Intercept method calls on this object. + + A new MockMethod is returned that is aware of the MockAnything's + state (record or replay). The call will be recorded or replayed + by the MockMethod's __call__. + + Args: + # method name: the name of the method being called. + method_name: str + + Returns: + A new MockMethod aware of MockAnything's state (record or replay). + """ + + return self._CreateMockMethod(method_name) + + def _CreateMockMethod(self, method_name): + """Create a new mock method call and return it. + + Args: + # method name: the name of the method being called. + method_name: str + + Returns: + A new MockMethod aware of MockAnything's state (record or replay). + """ + + return MockMethod(method_name, self._expected_calls_queue, + self._replay_mode) + + def __nonzero__(self): + """Return 1 for nonzero so the mock can be used as a conditional.""" + + return 1 + + def __eq__(self, rhs): + """Provide custom logic to compare objects.""" + + return (isinstance(rhs, MockAnything) and + self._replay_mode == rhs._replay_mode and + self._expected_calls_queue == rhs._expected_calls_queue) + + def __ne__(self, rhs): + """Provide custom logic to compare objects.""" + + return not self == rhs + + def _Replay(self): + """Start replaying expected method calls.""" + + self._replay_mode = True + + def _Verify(self): + """Verify that all of the expected calls have been made. + + Raises: + ExpectedMethodCallsError: if there are still more method calls in the + expected queue. + """ + + # If the list of expected calls is not empty, raise an exception + if self._expected_calls_queue: + # The last MultipleTimesGroup is not popped from the queue. + if (len(self._expected_calls_queue) == 1 and + isinstance(self._expected_calls_queue[0], MultipleTimesGroup) and + self._expected_calls_queue[0].IsSatisfied()): + pass + else: + raise ExpectedMethodCallsError(self._expected_calls_queue) + + def _Reset(self): + """Reset the state of this mock to record mode with an empty queue.""" + + # Maintain a list of method calls we are expecting + self._expected_calls_queue = deque() + + # Make sure we are in setup mode, not replay mode + self._replay_mode = False + + +class MockObject(MockAnything, object): + """A mock object that simulates the public/protected interface of a class.""" + + def __init__(self, class_to_mock): + """Initialize a mock object. + + This determines the methods and properties of the class and stores them. + + Args: + # class_to_mock: class to be mocked + class_to_mock: class + """ + + # This is used to hack around the mixin/inheritance of MockAnything, which + # is not a proper object (it can be anything. :-) + MockAnything.__dict__['__init__'](self) + + # Get a list of all the public and special methods we should mock. + self._known_methods = set() + self._known_vars = set() + self._class_to_mock = class_to_mock + for method in dir(class_to_mock): + if callable(getattr(class_to_mock, method)): + self._known_methods.add(method) + else: + self._known_vars.add(method) + + def __getattr__(self, name): + """Intercept attribute request on this object. + + If the attribute is a public class variable, it will be returned and not + recorded as a call. + + If the attribute is not a variable, it is handled like a method + call. The method name is checked against the set of mockable + methods, and a new MockMethod is returned that is aware of the + MockObject's state (record or replay). The call will be recorded + or replayed by the MockMethod's __call__. + + Args: + # name: the name of the attribute being requested. + name: str + + Returns: + Either a class variable or a new MockMethod that is aware of the state + of the mock (record or replay). + + Raises: + UnknownMethodCallError if the MockObject does not mock the requested + method. + """ + + if name in self._known_vars: + return getattr(self._class_to_mock, name) + + if name in self._known_methods: + return self._CreateMockMethod(name) + + raise UnknownMethodCallError(name) + + def __eq__(self, rhs): + """Provide custom logic to compare objects.""" + + return (isinstance(rhs, MockObject) and + self._class_to_mock == rhs._class_to_mock and + self._replay_mode == rhs._replay_mode and + self._expected_calls_queue == rhs._expected_calls_queue) + + def __setitem__(self, key, value): + """Provide custom logic for mocking classes that support item assignment. + + Args: + key: Key to set the value for. + value: Value to set. + + Returns: + Expected return value in replay mode. A MockMethod object for the + __setitem__ method that has already been called if not in replay mode. + + Raises: + TypeError if the underlying class does not support item assignment. + UnexpectedMethodCallError if the object does not expect the call to + __setitem__. + + """ + setitem = self._class_to_mock.__dict__.get('__setitem__', None) + + # Verify the class supports item assignment. + if setitem is None: + raise TypeError('object does not support item assignment') + + # If we are in replay mode then simply call the mock __setitem__ method. + if self._replay_mode: + return MockMethod('__setitem__', self._expected_calls_queue, + self._replay_mode)(key, value) + + + # Otherwise, create a mock method __setitem__. + return self._CreateMockMethod('__setitem__')(key, value) + + def __getitem__(self, key): + """Provide custom logic for mocking classes that are subscriptable. + + Args: + key: Key to return the value for. + + Returns: + Expected return value in replay mode. A MockMethod object for the + __getitem__ method that has already been called if not in replay mode. + + Raises: + TypeError if the underlying class is not subscriptable. + UnexpectedMethodCallError if the object does not expect the call to + __setitem__. + + """ + getitem = self._class_to_mock.__dict__.get('__getitem__', None) + + # Verify the class supports item assignment. + if getitem is None: + raise TypeError('unsubscriptable object') + + # If we are in replay mode then simply call the mock __getitem__ method. + if self._replay_mode: + return MockMethod('__getitem__', self._expected_calls_queue, + self._replay_mode)(key) + + + # Otherwise, create a mock method __getitem__. + return self._CreateMockMethod('__getitem__')(key) + + def __call__(self, *params, **named_params): + """Provide custom logic for mocking classes that are callable.""" + + # Verify the class we are mocking is callable + callable = self._class_to_mock.__dict__.get('__call__', None) + if callable is None: + raise TypeError('Not callable') + + # Because the call is happening directly on this object instead of a method, + # the call on the mock method is made right here + mock_method = self._CreateMockMethod('__call__') + return mock_method(*params, **named_params) + + @property + def __class__(self): + """Return the class that is being mocked.""" + + return self._class_to_mock + + +class MockMethod(object): + """Callable mock method. + + A MockMethod should act exactly like the method it mocks, accepting parameters + and returning a value, or throwing an exception (as specified). When this + method is called, it can optionally verify whether the called method (name and + signature) matches the expected method. + """ + + def __init__(self, method_name, call_queue, replay_mode): + """Construct a new mock method. + + Args: + # method_name: the name of the method + # call_queue: deque of calls, verify this call against the head, or add + # this call to the queue. + # replay_mode: False if we are recording, True if we are verifying calls + # against the call queue. + method_name: str + call_queue: list or deque + replay_mode: bool + """ + + self._name = method_name + self._call_queue = call_queue + if not isinstance(call_queue, deque): + self._call_queue = deque(self._call_queue) + self._replay_mode = replay_mode + + self._params = None + self._named_params = None + self._return_value = None + self._exception = None + self._side_effects = None + + def __call__(self, *params, **named_params): + """Log parameters and return the specified return value. + + If the Mock(Anything/Object) associated with this call is in record mode, + this MockMethod will be pushed onto the expected call queue. If the mock + is in replay mode, this will pop a MockMethod off the top of the queue and + verify this call is equal to the expected call. + + Raises: + UnexpectedMethodCall if this call is supposed to match an expected method + call and it does not. + """ + + self._params = params + self._named_params = named_params + + if not self._replay_mode: + self._call_queue.append(self) + return self + + expected_method = self._VerifyMethodCall() + + if expected_method._side_effects: + expected_method._side_effects(*params, **named_params) + + if expected_method._exception: + raise expected_method._exception + + return expected_method._return_value + + def __getattr__(self, name): + """Raise an AttributeError with a helpful message.""" + + raise AttributeError('MockMethod has no attribute "%s". ' + 'Did you remember to put your mocks in replay mode?' % name) + + def _PopNextMethod(self): + """Pop the next method from our call queue.""" + try: + return self._call_queue.popleft() + except IndexError: + raise UnexpectedMethodCallError(self, None) + + def _VerifyMethodCall(self): + """Verify the called method is expected. + + This can be an ordered method, or part of an unordered set. + + Returns: + The expected mock method. + + Raises: + UnexpectedMethodCall if the method called was not expected. + """ + + expected = self._PopNextMethod() + + # Loop here, because we might have a MethodGroup followed by another + # group. + while isinstance(expected, MethodGroup): + expected, method = expected.MethodCalled(self) + if method is not None: + return method + + # This is a mock method, so just check equality. + if expected != self: + raise UnexpectedMethodCallError(self, expected) + + return expected + + def __str__(self): + params = ', '.join( + [repr(p) for p in self._params or []] + + ['%s=%r' % x for x in sorted((self._named_params or {}).items())]) + desc = "%s(%s) -> %r" % (self._name, params, self._return_value) + return desc + + def __eq__(self, rhs): + """Test whether this MockMethod is equivalent to another MockMethod. + + Args: + # rhs: the right hand side of the test + rhs: MockMethod + """ + + return (isinstance(rhs, MockMethod) and + self._name == rhs._name and + self._params == rhs._params and + self._named_params == rhs._named_params) + + def __ne__(self, rhs): + """Test whether this MockMethod is not equivalent to another MockMethod. + + Args: + # rhs: the right hand side of the test + rhs: MockMethod + """ + + return not self == rhs + + def GetPossibleGroup(self): + """Returns a possible group from the end of the call queue or None if no + other methods are on the stack. + """ + + # Remove this method from the tail of the queue so we can add it to a group. + this_method = self._call_queue.pop() + assert this_method == self + + # Determine if the tail of the queue is a group, or just a regular ordered + # mock method. + group = None + try: + group = self._call_queue[-1] + except IndexError: + pass + + return group + + def _CheckAndCreateNewGroup(self, group_name, group_class): + """Checks if the last method (a possible group) is an instance of our + group_class. Adds the current method to this group or creates a new one. + + Args: + + group_name: the name of the group. + group_class: the class used to create instance of this new group + """ + group = self.GetPossibleGroup() + + # If this is a group, and it is the correct group, add the method. + if isinstance(group, group_class) and group.group_name() == group_name: + group.AddMethod(self) + return self + + # Create a new group and add the method. + new_group = group_class(group_name) + new_group.AddMethod(self) + self._call_queue.append(new_group) + return self + + def InAnyOrder(self, group_name="default"): + """Move this method into a group of unordered calls. + + A group of unordered calls must be defined together, and must be executed + in full before the next expected method can be called. There can be + multiple groups that are expected serially, if they are given + different group names. The same group name can be reused if there is a + standard method call, or a group with a different name, spliced between + usages. + + Args: + group_name: the name of the unordered group. + + Returns: + self + """ + return self._CheckAndCreateNewGroup(group_name, UnorderedGroup) + + def MultipleTimes(self, group_name="default"): + """Move this method into group of calls which may be called multiple times. + + A group of repeating calls must be defined together, and must be executed in + full before the next expected method can be called. + + Args: + group_name: the name of the unordered group. + + Returns: + self + """ + return self._CheckAndCreateNewGroup(group_name, MultipleTimesGroup) + + def AndReturn(self, return_value): + """Set the value to return when this method is called. + + Args: + # return_value can be anything. + """ + + self._return_value = return_value + return return_value + + def AndRaise(self, exception): + """Set the exception to raise when this method is called. + + Args: + # exception: the exception to raise when this method is called. + exception: Exception + """ + + self._exception = exception + + def WithSideEffects(self, side_effects): + """Set the side effects that are simulated when this method is called. + + Args: + side_effects: A callable which modifies the parameters or other relevant + state which a given test case depends on. + + Returns: + Self for chaining with AndReturn and AndRaise. + """ + self._side_effects = side_effects + return self + +class Comparator: + """Base class for all Mox comparators. + + A Comparator can be used as a parameter to a mocked method when the exact + value is not known. For example, the code you are testing might build up a + long SQL string that is passed to your mock DAO. You're only interested that + the IN clause contains the proper primary keys, so you can set your mock + up as follows: + + mock_dao.RunQuery(StrContains('IN (1, 2, 4, 5)')).AndReturn(mock_result) + + Now whatever query is passed in must contain the string 'IN (1, 2, 4, 5)'. + + A Comparator may replace one or more parameters, for example: + # return at most 10 rows + mock_dao.RunQuery(StrContains('SELECT'), 10) + + or + + # Return some non-deterministic number of rows + mock_dao.RunQuery(StrContains('SELECT'), IsA(int)) + """ + + def equals(self, rhs): + """Special equals method that all comparators must implement. + + Args: + rhs: any python object + """ + + raise NotImplementedError('method must be implemented by a subclass.') + + def __eq__(self, rhs): + return self.equals(rhs) + + def __ne__(self, rhs): + return not self.equals(rhs) + + +class IsA(Comparator): + """This class wraps a basic Python type or class. It is used to verify + that a parameter is of the given type or class. + + Example: + mock_dao.Connect(IsA(DbConnectInfo)) + """ + + def __init__(self, class_name): + """Initialize IsA + + Args: + class_name: basic python type or a class + """ + + self._class_name = class_name + + def equals(self, rhs): + """Check to see if the RHS is an instance of class_name. + + Args: + # rhs: the right hand side of the test + rhs: object + + Returns: + bool + """ + + try: + return isinstance(rhs, self._class_name) + except TypeError: + # Check raw types if there was a type error. This is helpful for + # things like cStringIO.StringIO. + return type(rhs) == type(self._class_name) + + def __repr__(self): + return str(self._class_name) + +class IsAlmost(Comparator): + """Comparison class used to check whether a parameter is nearly equal + to a given value. Generally useful for floating point numbers. + + Example mock_dao.SetTimeout((IsAlmost(3.9))) + """ + + def __init__(self, float_value, places=7): + """Initialize IsAlmost. + + Args: + float_value: The value for making the comparison. + places: The number of decimal places to round to. + """ + + self._float_value = float_value + self._places = places + + def equals(self, rhs): + """Check to see if RHS is almost equal to float_value + + Args: + rhs: the value to compare to float_value + + Returns: + bool + """ + + try: + return round(rhs-self._float_value, self._places) == 0 + except TypeError: + # This is probably because either float_value or rhs is not a number. + return False + + def __repr__(self): + return str(self._float_value) + +class StrContains(Comparator): + """Comparison class used to check whether a substring exists in a + string parameter. This can be useful in mocking a database with SQL + passed in as a string parameter, for example. + + Example: + mock_dao.RunQuery(StrContains('IN (1, 2, 4, 5)')).AndReturn(mock_result) + """ + + def __init__(self, search_string): + """Initialize. + + Args: + # search_string: the string you are searching for + search_string: str + """ + + self._search_string = search_string + + def equals(self, rhs): + """Check to see if the search_string is contained in the rhs string. + + Args: + # rhs: the right hand side of the test + rhs: object + + Returns: + bool + """ + + try: + return rhs.find(self._search_string) > -1 + except Exception: + return False + + def __repr__(self): + return '' % self._search_string + + +class Regex(Comparator): + """Checks if a string matches a regular expression. + + This uses a given regular expression to determine equality. + """ + + def __init__(self, pattern, flags=0): + """Initialize. + + Args: + # pattern is the regular expression to search for + pattern: str + # flags passed to re.compile function as the second argument + flags: int + """ + + self.regex = re.compile(pattern, flags=flags) + + def equals(self, rhs): + """Check to see if rhs matches regular expression pattern. + + Returns: + bool + """ + + return self.regex.search(rhs) is not None + + def __repr__(self): + s = '' % self._key + + +class ContainsKeyValue(Comparator): + """Checks whether a key/value pair is in a dict parameter. + + Example: + mock_dao.UpdateUsers(ContainsKeyValue('stevepm', stevepm_user_info)) + """ + + def __init__(self, key, value): + """Initialize. + + Args: + # key: a key in a dict + # value: the corresponding value + """ + + self._key = key + self._value = value + + def equals(self, rhs): + """Check whether the given key/value pair is in the rhs dict. + + Returns: + bool + """ + + try: + return rhs[self._key] == self._value + except Exception: + return False + + def __repr__(self): + return '' % (self._key, self._value) + + +class SameElementsAs(Comparator): + """Checks whether iterables contain the same elements (ignoring order). + + Example: + mock_dao.ProcessUsers(SameElementsAs('stevepm', 'salomaki')) + """ + + def __init__(self, expected_seq): + """Initialize. + + Args: + expected_seq: a sequence + """ + + self._expected_seq = expected_seq + + def equals(self, actual_seq): + """Check to see whether actual_seq has same elements as expected_seq. + + Args: + actual_seq: sequence + + Returns: + bool + """ + + try: + expected = dict([(element, None) for element in self._expected_seq]) + actual = dict([(element, None) for element in actual_seq]) + except TypeError: + # Fall back to slower list-compare if any of the objects are unhashable. + expected = list(self._expected_seq) + actual = list(actual_seq) + expected.sort() + actual.sort() + return expected == actual + + def __repr__(self): + return '' % self._expected_seq + + +class And(Comparator): + """Evaluates one or more Comparators on RHS and returns an AND of the results. + """ + + def __init__(self, *args): + """Initialize. + + Args: + *args: One or more Comparator + """ + + self._comparators = args + + def equals(self, rhs): + """Checks whether all Comparators are equal to rhs. + + Args: + # rhs: can be anything + + Returns: + bool + """ + + for comparator in self._comparators: + if not comparator.equals(rhs): + return False + + return True + + def __repr__(self): + return '' % str(self._comparators) + + +class Or(Comparator): + """Evaluates one or more Comparators on RHS and returns an OR of the results. + """ + + def __init__(self, *args): + """Initialize. + + Args: + *args: One or more Mox comparators + """ + + self._comparators = args + + def equals(self, rhs): + """Checks whether any Comparator is equal to rhs. + + Args: + # rhs: can be anything + + Returns: + bool + """ + + for comparator in self._comparators: + if comparator.equals(rhs): + return True + + return False + + def __repr__(self): + return '' % str(self._comparators) + + +class Func(Comparator): + """Call a function that should verify the parameter passed in is correct. + + You may need the ability to perform more advanced operations on the parameter + in order to validate it. You can use this to have a callable validate any + parameter. The callable should return either True or False. + + + Example: + + def myParamValidator(param): + # Advanced logic here + return True + + mock_dao.DoSomething(Func(myParamValidator), true) + """ + + def __init__(self, func): + """Initialize. + + Args: + func: callable that takes one parameter and returns a bool + """ + + self._func = func + + def equals(self, rhs): + """Test whether rhs passes the function test. + + rhs is passed into func. + + Args: + rhs: any python object + + Returns: + the result of func(rhs) + """ + + return self._func(rhs) + + def __repr__(self): + return str(self._func) + + +class IgnoreArg(Comparator): + """Ignore an argument. + + This can be used when we don't care about an argument of a method call. + + Example: + # Check if CastMagic is called with 3 as first arg and 'disappear' as third. + mymock.CastMagic(3, IgnoreArg(), 'disappear') + """ + + def equals(self, unused_rhs): + """Ignores arguments and returns True. + + Args: + unused_rhs: any python object + + Returns: + always returns True + """ + + return True + + def __repr__(self): + return '' + + +class MethodGroup(object): + """Base class containing common behaviour for MethodGroups.""" + + def __init__(self, group_name): + self._group_name = group_name + + def group_name(self): + return self._group_name + + def __str__(self): + return '<%s "%s">' % (self.__class__.__name__, self._group_name) + + def AddMethod(self, mock_method): + raise NotImplementedError + + def MethodCalled(self, mock_method): + raise NotImplementedError + + def IsSatisfied(self): + raise NotImplementedError + +class UnorderedGroup(MethodGroup): + """UnorderedGroup holds a set of method calls that may occur in any order. + + This construct is helpful for non-deterministic events, such as iterating + over the keys of a dict. + """ + + def __init__(self, group_name): + super(UnorderedGroup, self).__init__(group_name) + self._methods = [] + + def AddMethod(self, mock_method): + """Add a method to this group. + + Args: + mock_method: A mock method to be added to this group. + """ + + self._methods.append(mock_method) + + def MethodCalled(self, mock_method): + """Remove a method call from the group. + + If the method is not in the set, an UnexpectedMethodCallError will be + raised. + + Args: + mock_method: a mock method that should be equal to a method in the group. + + Returns: + The mock method from the group + + Raises: + UnexpectedMethodCallError if the mock_method was not in the group. + """ + + # Check to see if this method exists, and if so, remove it from the set + # and return it. + for method in self._methods: + if method == mock_method: + # Remove the called mock_method instead of the method in the group. + # The called method will match any comparators when equality is checked + # during removal. The method in the group could pass a comparator to + # another comparator during the equality check. + self._methods.remove(mock_method) + + # If this group is not empty, put it back at the head of the queue. + if not self.IsSatisfied(): + mock_method._call_queue.appendleft(self) + + return self, method + + raise UnexpectedMethodCallError(mock_method, self) + + def IsSatisfied(self): + """Return True if there are not any methods in this group.""" + + return len(self._methods) == 0 + + +class MultipleTimesGroup(MethodGroup): + """MultipleTimesGroup holds methods that may be called any number of times. + + Note: Each method must be called at least once. + + This is helpful, if you don't know or care how many times a method is called. + """ + + def __init__(self, group_name): + super(MultipleTimesGroup, self).__init__(group_name) + self._methods = set() + self._methods_called = set() + + def AddMethod(self, mock_method): + """Add a method to this group. + + Args: + mock_method: A mock method to be added to this group. + """ + + self._methods.add(mock_method) + + def MethodCalled(self, mock_method): + """Remove a method call from the group. + + If the method is not in the set, an UnexpectedMethodCallError will be + raised. + + Args: + mock_method: a mock method that should be equal to a method in the group. + + Returns: + The mock method from the group + + Raises: + UnexpectedMethodCallError if the mock_method was not in the group. + """ + + # Check to see if this method exists, and if so add it to the set of + # called methods. + + for method in self._methods: + if method == mock_method: + self._methods_called.add(mock_method) + # Always put this group back on top of the queue, because we don't know + # when we are done. + mock_method._call_queue.appendleft(self) + return self, method + + if self.IsSatisfied(): + next_method = mock_method._PopNextMethod(); + return next_method, None + else: + raise UnexpectedMethodCallError(mock_method, self) + + def IsSatisfied(self): + """Return True if all methods in this group are called at least once.""" + # NOTE(psycho): We can't use the simple set difference here because we want + # to match different parameters which are considered the same e.g. IsA(str) + # and some string. This solution is O(n^2) but n should be small. + tmp = self._methods.copy() + for called in self._methods_called: + for expected in tmp: + if called == expected: + tmp.remove(expected) + if not tmp: + return True + break + return False + + +class MoxMetaTestBase(type): + """Metaclass to add mox cleanup and verification to every test. + + As the mox unit testing class is being constructed (MoxTestBase or a + subclass), this metaclass will modify all test functions to call the + CleanUpMox method of the test class after they finish. This means that + unstubbing and verifying will happen for every test with no additional code, + and any failures will result in test failures as opposed to errors. + """ + + def __init__(cls, name, bases, d): + type.__init__(cls, name, bases, d) + + # also get all the attributes from the base classes to account + # for a case when test class is not the immediate child of MoxTestBase + for base in bases: + for attr_name in dir(base): + d[attr_name] = getattr(base, attr_name) + + for func_name, func in d.items(): + if func_name.startswith('test') and callable(func): + setattr(cls, func_name, MoxMetaTestBase.CleanUpTest(cls, func)) + + @staticmethod + def CleanUpTest(cls, func): + """Adds Mox cleanup code to any MoxTestBase method. + + Always unsets stubs after a test. Will verify all mocks for tests that + otherwise pass. + + Args: + cls: MoxTestBase or subclass; the class whose test method we are altering. + func: method; the method of the MoxTestBase test class we wish to alter. + + Returns: + The modified method. + """ + def new_method(self, *args, **kwargs): + mox_obj = getattr(self, 'mox', None) + cleanup_mox = False + if mox_obj and isinstance(mox_obj, Mox): + cleanup_mox = True + try: + func(self, *args, **kwargs) + finally: + if cleanup_mox: + mox_obj.UnsetStubs() + if cleanup_mox: + mox_obj.VerifyAll() + new_method.__name__ = func.__name__ + new_method.__doc__ = func.__doc__ + new_method.__module__ = func.__module__ + return new_method + + +class MoxTestBase(unittest.TestCase): + """Convenience test class to make stubbing easier. + + Sets up a "mox" attribute which is an instance of Mox - any mox tests will + want this. Also automatically unsets any stubs and verifies that all mock + methods have been called at the end of each test, eliminating boilerplate + code. + """ + + __metaclass__ = MoxMetaTestBase + + def setUp(self): + self.mox = Mox() diff --git a/libs/protobuf/python/python_version.py b/libs/protobuf/python/python_version.py deleted file mode 100644 index 5bf8d21..0000000 --- a/libs/protobuf/python/python_version.py +++ /dev/null @@ -1,52 +0,0 @@ -# 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. -"""Test that Kokoro is using the expected version of python.""" - -import os -import sys -import unittest - - -class PythonVersionTest(unittest.TestCase): - - def testPython3(self): - """Test that we can import nested import public messages.""" - - exp = os.getenv('KOKORO_PYTHON_VERSION', '') - if not exp: - print('No kokoro python version found, skipping check', file=sys.stderr) - return - self.assertTrue( - sys.version.startswith(exp), - 'Expected Python %s but found Python %s' % (exp, sys.version)) - - -if __name__ == '__main__': - unittest.main() diff --git a/libs/protobuf/python/requirements.txt b/libs/protobuf/python/requirements.txt deleted file mode 100644 index 296d654..0000000 --- a/libs/protobuf/python/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -numpy \ No newline at end of file diff --git a/libs/protobuf/python/setup.py b/libs/protobuf/python/setup.py index 7a55359..cbb9a59 100755 --- a/libs/protobuf/python/setup.py +++ b/libs/protobuf/python/setup.py @@ -29,14 +29,10 @@ from distutils.spawn import find_executable # Find the Protocol Compiler. if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): protoc = os.environ['PROTOC'] -elif os.path.exists('../bazel-bin/protoc'): - protoc = '../bazel-bin/protoc' -elif os.path.exists('../bazel-bin/protoc.exe'): - protoc = '../bazel-bin/protoc.exe' -elif os.path.exists('protoc'): - protoc = '../protoc' -elif os.path.exists('protoc.exe'): - protoc = '../protoc.exe' +elif os.path.exists('../src/protoc'): + protoc = '../src/protoc' +elif os.path.exists('../src/protoc.exe'): + protoc = '../src/protoc.exe' elif os.path.exists('../vsprojects/Debug/protoc.exe'): protoc = '../vsprojects/Debug/protoc.exe' elif os.path.exists('../vsprojects/Release/protoc.exe'): @@ -207,13 +203,13 @@ class BuildExtCmd(_build_ext): class TestConformanceCmd(_build_py): - target = '//python:conformance_test' + target = 'test_python' def run(self): # Python 2.6 dodges these extra failures. os.environ['CONFORMANCE_PYTHON_EXTRA_FAILURES'] = ( '--failure_list failure_list_python-post26.txt') - cmd = 'bazel test %s' % (TestConformanceCmd.target,) + cmd = 'cd ../conformance && make %s' % (TestConformanceCmd.target) subprocess.check_call(cmd, shell=True) @@ -224,59 +220,6 @@ def GetOptionFromArgv(option_str): return False -def _GetFlagValues(flag_long, flag_short): - """Searches sys.argv for distutils-style flags and yields values.""" - - expect_value = flag_long.endswith('=') - flag_res = [re.compile(r'--?%s(=(.*))?' % - (flag_long[:-1] if expect_value else flag_long))] - if flag_short: - flag_res.append(re.compile(r'-%s(.*)?' % (flag_short,))) - - flag_match = None - for arg in sys.argv: - # If the last arg was like '-O', check if this is the library we want. - if flag_match is not None: - yield arg - flag_match = None - continue - - for flag_re in flag_res: - m = flag_re.match(arg) - if m is None: - continue - if not expect_value: - yield arg - continue - groups = m.groups() - # Check for matches: - # --long-name=foo => ('=foo', 'foo') - # -Xfoo => ('foo') - # N.B.: if the flag is like '--long-name=', then there is a value - # (the empty string). - if groups[0] or groups[-1]: - yield groups[-1] - continue - flag_match = m - - return False - - -def HasStaticLibprotobufOpt(): - """Returns true if there is a --link-objects arg for libprotobuf.""" - - lib_re = re.compile(r'(.*[/\\])?(lib)?protobuf([.]pic)?[.](a|lib)') - for value in _GetFlagValues('link-objects=', 'O'): - if lib_re.match(value): - return True - return False - - -def HasLibraryDirsOpt(): - """Returns true if there is a --library-dirs arg.""" - return any(_GetFlagValues('library-dirs=', 'L')) - - if __name__ == '__main__': ext_module_list = [] warnings_as_errors = '--warnings_as_errors' @@ -284,37 +227,14 @@ if __name__ == '__main__': # Link libprotobuf.a and libprotobuf-lite.a statically with the # extension. Note that those libraries have to be compiled with # -fPIC for this to work. - compile_static_ext = HasStaticLibprotobufOpt() - if GetOptionFromArgv('--compile_static_extension'): - # FUTURE: add a warning and deprecate --compile_static_extension. - compile_static_ext = True + compile_static_ext = GetOptionFromArgv('--compile_static_extension') + libraries = ['protobuf'] extra_objects = None if compile_static_ext: libraries = None - library_dirs = None - if not HasStaticLibprotobufOpt(): - if os.path.exists('../bazel-bin/src/google/protobuf/libprotobuf.a'): - extra_objects = ['../bazel-bin/src/google/protobuf/libprotobuf.a'] - else: - extra_objects = ['../libprotobuf.a'] - # Repeat all of these enough times to eliminate order-dependence. - extra_objects += list( - glob.iglob('../third_party/abseil-cpp/absl/**/*.a')) - extra_objects += list( - glob.iglob('../third_party/abseil-cpp/absl/**/*.a')) - extra_objects += list( - glob.iglob('../third_party/abseil-cpp/absl/**/*.a')) - else: - libraries = ['protobuf'] - if HasLibraryDirsOpt(): - library_dirs = None - elif os.path.exists('../bazel-bin/src/google/protobuf/libprotobuf.a'): - library_dirs = ['../bazel-bin/src/google/protobuf'] - else: - library_dirs = ['..'] - - TestConformanceCmd.target = ('//python:conformance_test_cpp ' - '--define=use_fast_cpp_protos=true') + extra_objects = ['../src/.libs/libprotobuf.a', + '../src/.libs/libprotobuf-lite.a'] + TestConformanceCmd.target = 'test_python_cpp' extra_compile_args = [] @@ -339,7 +259,7 @@ if __name__ == '__main__': extra_compile_args.append('-Wno-invalid-offsetof') extra_compile_args.append('-Wno-sign-compare') extra_compile_args.append('-Wno-unused-variable') - extra_compile_args.append('-std=c++14') + extra_compile_args.append('-std=c++11') if sys.platform == 'darwin': extra_compile_args.append('-Wno-shorten-64-to-32') @@ -381,11 +301,11 @@ if __name__ == '__main__': Extension( 'google.protobuf.pyext._message', glob.glob('google/protobuf/pyext/*.cc'), - include_dirs=['.', '../src', '../third_party/abseil-cpp'], + include_dirs=['.', '../src'], libraries=libraries, extra_objects=extra_objects, extra_link_args=message_extra_link_args, - library_dirs=library_dirs, + library_dirs=['../src/.libs'], extra_compile_args=extra_compile_args, ), Extension( diff --git a/libs/protobuf/python/stubout.py b/libs/protobuf/python/stubout.py new file mode 100755 index 0000000..ba39104 --- /dev/null +++ b/libs/protobuf/python/stubout.py @@ -0,0 +1,143 @@ +#!/usr/bin/python2.4 +# +# Copyright 2008 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file is used for testing. The original is at: +# http://code.google.com/p/pymox/ + +import inspect + + +class StubOutForTesting: + """Sample Usage: + You want os.path.exists() to always return true during testing. + + stubs = StubOutForTesting() + stubs.Set(os.path, 'exists', lambda x: 1) + ... + stubs.UnsetAll() + + The above changes os.path.exists into a lambda that returns 1. Once + the ... part of the code finishes, the UnsetAll() looks up the old value + of os.path.exists and restores it. + + """ + def __init__(self): + self.cache = [] + self.stubs = [] + + def __del__(self): + self.SmartUnsetAll() + self.UnsetAll() + + def SmartSet(self, obj, attr_name, new_attr): + """Replace obj.attr_name with new_attr. This method is smart and works + at the module, class, and instance level while preserving proper + inheritance. It will not stub out C types however unless that has been + explicitly allowed by the type. + + This method supports the case where attr_name is a staticmethod or a + classmethod of obj. + + Notes: + - If obj is an instance, then it is its class that will actually be + stubbed. Note that the method Set() does not do that: if obj is + an instance, it (and not its class) will be stubbed. + - The stubbing is using the builtin getattr and setattr. So, the __get__ + and __set__ will be called when stubbing (TODO: A better idea would + probably be to manipulate obj.__dict__ instead of getattr() and + setattr()). + + Raises AttributeError if the attribute cannot be found. + """ + if (inspect.ismodule(obj) or + (not inspect.isclass(obj) and obj.__dict__.has_key(attr_name))): + orig_obj = obj + orig_attr = getattr(obj, attr_name) + + else: + if not inspect.isclass(obj): + mro = list(inspect.getmro(obj.__class__)) + else: + mro = list(inspect.getmro(obj)) + + mro.reverse() + + orig_attr = None + + for cls in mro: + try: + orig_obj = cls + orig_attr = getattr(obj, attr_name) + except AttributeError: + continue + + if orig_attr is None: + raise AttributeError("Attribute not found.") + + # Calling getattr() on a staticmethod transforms it to a 'normal' function. + # We need to ensure that we put it back as a staticmethod. + old_attribute = obj.__dict__.get(attr_name) + if old_attribute is not None and isinstance(old_attribute, staticmethod): + orig_attr = staticmethod(orig_attr) + + self.stubs.append((orig_obj, attr_name, orig_attr)) + setattr(orig_obj, attr_name, new_attr) + + def SmartUnsetAll(self): + """Reverses all the SmartSet() calls, restoring things to their original + definition. Its okay to call SmartUnsetAll() repeatedly, as later calls + have no effect if no SmartSet() calls have been made. + + """ + self.stubs.reverse() + + for args in self.stubs: + setattr(*args) + + self.stubs = [] + + def Set(self, parent, child_name, new_child): + """Replace child_name's old definition with new_child, in the context + of the given parent. The parent could be a module when the child is a + function at module scope. Or the parent could be a class when a class' + method is being replaced. The named child is set to new_child, while + the prior definition is saved away for later, when UnsetAll() is called. + + This method supports the case where child_name is a staticmethod or a + classmethod of parent. + """ + old_child = getattr(parent, child_name) + + old_attribute = parent.__dict__.get(child_name) + if old_attribute is not None and isinstance(old_attribute, staticmethod): + old_child = staticmethod(old_child) + + self.cache.append((parent, old_child, child_name)) + setattr(parent, child_name, new_child) + + def UnsetAll(self): + """Reverses all the Set() calls, restoring things to their original + definition. Its okay to call UnsetAll() repeatedly, as later calls have + no effect if no Set() calls have been made. + + """ + # Undo calls to Set() in reverse order, in case Set() was called on the + # same arguments repeatedly (want the original call to be last one undone) + self.cache.reverse() + + for (parent, old_child, child_name) in self.cache: + setattr(parent, child_name, old_child) + self.cache = [] diff --git a/libs/protobuf/python/tox.ini b/libs/protobuf/python/tox.ini index 346ce21..b923a4a 100644 --- a/libs/protobuf/python/tox.ini +++ b/libs/protobuf/python/tox.ini @@ -5,10 +5,10 @@ envlist = [testenv] usedevelop=true passenv = - CC PYTHONPATH KOKORO_BUILD_ID KOKORO_BUILD_NUMBER + CC KOKORO_BUILD_ID KOKORO_BUILD_NUMBER setenv = - cpp: LD_LIBRARY_PATH={toxinidir}/../bazel-bin/src/google - cpp: DYLD_LIBRARY_PATH={toxinidir}/../bazel-bin/src/google + cpp: LD_LIBRARY_PATH={toxinidir}/../src/.libs + cpp: DYLD_LIBRARY_PATH={toxinidir}/../src/.libs cpp: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp python: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python commands = diff --git a/libs/protobuf/ruby/BUILD.bazel b/libs/protobuf/ruby/BUILD.bazel index d4114b5..fe336e5 100644 --- a/libs/protobuf/ruby/BUILD.bazel +++ b/libs/protobuf/ruby/BUILD.bazel @@ -3,204 +3,30 @@ # See also code generation logic under /src/google/protobuf/compiler/ruby. load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@upb//cmake:build_defs.bzl", "staleness_test") -load("//build_defs:internal_shell.bzl", "inline_sh_test") -load("//conformance:defs.bzl", "conformance_test") -load("//:protobuf.bzl", "internal_ruby_proto_library") -load(":internal.bzl", "internal_ruby_extension") - -################################################################################ -# Ruby Runtime -################################################################################ - -config_setting( - name = "java_ruby", - values = {"define": "ruby_platform=java"}, -) - -config_setting( - name = "c_ruby", - values = {"define": "ruby_platform=c"}, -) - -filegroup( - name = "srcs", - srcs = glob([ - "lib/**/*.rb", - "src/**/*.proto", - ]) + [ - "Gemfile", - "Rakefile", - "google-protobuf.gemspec", - "pom.xml", - ], -) - -internal_ruby_extension( - name = "protobuf_c_mac", - extension = "lib/google/protobuf_c.bundle", - deps = glob(["ext/google/protobuf_c/*"]), - target_compatible_with = select({ - ":java_ruby": ["@platforms//:incompatible"], - "//conditions:default": ["@platforms//os:osx"], - }), -) - -internal_ruby_extension( - name = "protobuf_c", - extension = "lib/google/protobuf_c.so", - deps = glob(["ext/google/protobuf_c/*"]), - target_compatible_with = select({ - ":java_ruby": ["@platforms//:incompatible"], - "@platforms//os:osx": ["@platforms//:incompatible"], - "//conditions:default": [], - }), -) - -internal_ruby_extension( - name = "protobuf_java", - extension = "lib/google/protobuf_java.jar", - deps = glob(["src/**/*.java"]), - target_compatible_with = select({ - ":java_ruby": [], - "//conditions:default": ["@platforms//:incompatible"], - }), -) - -filegroup( - name = "protobuf", - srcs = [ - ":srcs", - "@utf8_range//:utf8_range_srcs", - ] + select({ - ":java_ruby": [":protobuf_java"], - "@bazel_tools//src/conditions:darwin": [":protobuf_c_mac"], - "//conditions:default": [":protobuf_c"], - }), - visibility = [ - "//conformance:__subpackages__", - "//ruby:__subpackages__", - ], -) - -################################################################################ -# Tests -################################################################################ - -filegroup( - name = "tests", - srcs = glob(["tests/*.rb"]), -) - -filegroup( - name = "test_protos", - srcs = glob(["tests/*.proto"]), -) - -internal_ruby_proto_library( - name = "test_ruby_protos", - srcs = [":test_protos"], - proto_deps = ["//:well_known_protos"], - includes = [".", "src", "ruby/tests"], -) - -inline_sh_test( - name = "test", - srcs = [ - "Rakefile", - ], - deps = [ - ":protobuf", - ":test_ruby_protos", - ":tests", - "//:well_known_ruby_protos", - ], - cmd = """ - pushd `dirname $(location Rakefile)` - RUBYLIB=../src:tests:. BAZEL=true rake test - popd - """, -) - -inline_sh_test( - name = "gc_test", - srcs = [ - "Rakefile", - ], - deps = [ - ":protobuf", - ":test_ruby_protos", - ":tests", - "//:well_known_ruby_protos", - ], - cmd = """ - pushd `dirname $(location Rakefile)` - RUBYLIB=../src:tests:. BAZEL=true rake gc_test - popd - """, -) - -conformance_test( - name = "conformance_test", - failure_list = "//conformance:failure_list_ruby.txt", - testee = "//conformance:conformance_ruby", - text_format_failure_list = "//conformance:text_format_failure_list_ruby.txt", - target_compatible_with = select({ - ":java_ruby": ["@platforms//:incompatible"], - "//conditions:default": [], - }), -) - -conformance_test( - name = "conformance_test_jruby", - failure_list = "//conformance:failure_list_jruby.txt", - testee = "//conformance:conformance_ruby", - text_format_failure_list = "//conformance:text_format_failure_list_jruby.txt", - target_compatible_with = select({ - ":java_ruby": [], - "//conditions:default": ["@platforms//:incompatible"], - }), -) - -genrule( - name = "copy_ruby_amalgamation_h", - srcs = ["@upb//:ruby-upb.h"], - outs = ["generated-in/ext/google/protobuf_c/ruby-upb.h"], - cmd = "cp $< $@", -) - -genrule( - name = "copy_ruby_amalgamation_c", - srcs = ["@upb//:ruby-upb.c"], - outs = ["generated-in/ext/google/protobuf_c/ruby-upb.c"], - cmd = "cp $< $@", -) - -staleness_test( - name = "test_amalgamation_staleness", - outs = [ - "ext/google/protobuf_c/ruby-upb.h", - "ext/google/protobuf_c/ruby-upb.c", - ], - generated_pattern = "generated-in/%s", -) - -################################################################################ -# Distribution files -################################################################################ pkg_files( name = "dist_files", srcs = glob([ + "compatibility_tests/v3.0.0/**/*", + "ext/google/protobuf_c/*", + "src/main/java/com/google/protobuf/jruby/*.java", "tests/*.proto", "tests/*.rb", ]) + [ - ":srcs", ".gitignore", "BUILD.bazel", - "internal.bzl", "Gemfile", "README.md", + "Rakefile", + "google-protobuf.gemspec", + "lib/google/protobuf.rb", + "lib/google/protobuf/descriptor_dsl.rb", + "lib/google/protobuf/message_exts.rb", + "lib/google/protobuf/repeated_field.rb", + "lib/google/protobuf/well_known_types.rb", + "pom.xml", + "src/main/java/google/ProtobufJavaService.java", + "src/main/sentinel.proto", "travis-test.sh", ], strip_prefix = strip_prefix.from_root(""), diff --git a/libs/protobuf/ruby/README.md b/libs/protobuf/ruby/README.md index be8d6bc..42a1ffa 100644 --- a/libs/protobuf/ruby/README.md +++ b/libs/protobuf/ruby/README.md @@ -9,7 +9,7 @@ install protoc as well to have Ruby code generation functionality. Installation from Gem --------------------- -In Gemfile (Please check which version of Protocol Buffers you need: [RubyGems](https://rubygems.org/gems/google-protobuf)): +In Gemfile (Please check a version of Protocol Buffers you needed [RubyGems](https://rubygems.org/gems/google-protobuf)): gem 'google-protobuf' diff --git a/libs/protobuf/ruby/Rakefile b/libs/protobuf/ruby/Rakefile index e6b774c..d8ac763 100644 --- a/libs/protobuf/ruby/Rakefile +++ b/libs/protobuf/ruby/Rakefile @@ -39,8 +39,8 @@ proto2_protos = %w[ if !ENV['PROTOC'].nil? protoc_command = ENV['PROTOC'] -elsif system('../bazel-bin/protoc --version') - protoc_command = '../bazel-bin/protoc' +elsif system('../src/protoc --version') + protoc_command = '../src/protoc' else protoc_command = 'protoc' end @@ -49,7 +49,7 @@ genproto_output = [] # We won't have access to .. from within docker, but the proto files # will be there, thanks to the :genproto rule dependency for gem:native. -unless ENV['IN_DOCKER'] == 'true' or ENV['BAZEL'] == 'true' +unless ENV['IN_DOCKER'] == 'true' well_known_protos.each do |proto_file| input_file = "../src/" + proto_file output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb") @@ -84,16 +84,12 @@ if RUBY_PLATFORM == "java" else unless ENV['IN_DOCKER'] == 'true' # We need utf8_range in-tree. - if ENV['BAZEL'] == 'true' - utf8_root = '../external/utf8_range' - else - utf8_root = '../third_party/utf8_range' - end FileUtils.mkdir_p("ext/google/protobuf_c/third_party/utf8_range") - FileUtils.cp(utf8_root+"/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range") - FileUtils.cp(utf8_root+"/naive.c", "ext/google/protobuf_c/third_party/utf8_range") - FileUtils.cp(utf8_root+"/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range") - FileUtils.cp(utf8_root+"/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/utf8_range.h", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/naive.c", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/range2-neon.c", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/range2-sse.c", "ext/google/protobuf_c/third_party/utf8_range") + FileUtils.cp("../third_party/utf8_range/LICENSE", "ext/google/protobuf_c/third_party/utf8_range") end Rake::ExtensionTask.new("protobuf_c", spec) do |ext| @@ -157,15 +153,13 @@ end Gem::PackageTask.new(spec) do |pkg| end -# Skip build/genproto in Bazel builds, where we expect this to -# be done already. -Rake::TestTask.new(:test => ENV['BAZEL'] == 'true' ? [] : [:build, :genproto]) do |t| +Rake::TestTask.new(:test => [:build, :genproto]) do |t| t.test_files = FileList["tests/*.rb"].exclude("tests/gc_test.rb", "tests/common_tests.rb") end # gc_test needs to be split out to ensure the generated file hasn't been # imported by other tests. -Rake::TestTask.new(:gc_test => ENV['BAZEL'] == 'true' ? [] : :build) do |t| +Rake::TestTask.new(:gc_test => :build) do |t| t.test_files = FileList["tests/gc_test.rb"] end diff --git a/libs/protobuf/ruby/compatibility_tests/v3.0.0/BUILD.bazel b/libs/protobuf/ruby/compatibility_tests/v3.0.0/BUILD.bazel deleted file mode 100644 index b5fcede..0000000 --- a/libs/protobuf/ruby/compatibility_tests/v3.0.0/BUILD.bazel +++ /dev/null @@ -1,56 +0,0 @@ -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:internal_shell.bzl", "inline_sh_test") -load("//:protobuf.bzl", "internal_ruby_proto_library") - -filegroup( - name = "tests", - srcs = glob(["tests/*.rb"]), -) - -filegroup( - name = "test_protos", - srcs = glob(["tests/*.proto"]), -) - -internal_ruby_proto_library( - name = "test_ruby_protos", - srcs = [":test_protos"], - includes = ["."], -) - -inline_sh_test( - name = "test", - srcs = [ - "Rakefile", - ], - deps = [ - ":test_ruby_protos", - ":tests", - "//:well_known_ruby_protos", - "//ruby:protobuf", - ], - cmd = """ - pushd `dirname $(location Rakefile)` - RUBYLIB=.:tests:../../lib:../../../src BAZEL=true rake test - popd - """, -) - -################################################################################ -# Distribution files -############################################################################ - -pkg_files( - name = "dist_files", - srcs = glob([ - "**/*.rb", - "**/*.proto" - ]) + [ - "BUILD.bazel", - "Rakefile", - "README.md", - "test.sh", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile b/libs/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile index f72bed2..19a4ba1 100644 --- a/libs/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile +++ b/libs/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile @@ -2,17 +2,14 @@ require "rake/testtask" # Proto for tests. genproto_output = [] +genproto_output << "tests/generated_code.rb" +genproto_output << "tests/test_import.rb" +file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| + sh "./protoc --ruby_out=. tests/generated_code.proto" +end -unless ENV['BAZEL'] == 'true' - genproto_output << "tests/generated_code.rb" - genproto_output << "tests/test_import.rb" - file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| - sh "./protoc --ruby_out=. tests/generated_code.proto" - end - - file "tests/test_import.rb" => "tests/test_import.proto" do |file_task| - sh "./protoc --ruby_out=. tests/test_import.proto" - end +file "tests/test_import.rb" => "tests/test_import.proto" do |file_task| + sh "./protoc --ruby_out=. tests/test_import.proto" end task :genproto => genproto_output diff --git a/libs/protobuf/ruby/ext/google/protobuf_c/extconf.rb b/libs/protobuf/ruby/ext/google/protobuf_c/extconf.rb index 5cc4533..8bc96ae 100755 --- a/libs/protobuf/ruby/ext/google/protobuf_c/extconf.rb +++ b/libs/protobuf/ruby/ext/google/protobuf_c/extconf.rb @@ -25,4 +25,4 @@ $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c", "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c", "naive.c", "range2-neon.c", "range2-sse.c"] -create_makefile(ext_name, Dir.pwd+"/../../../../ext/google/protobuf_c") +create_makefile(ext_name) diff --git a/libs/protobuf/ruby/ext/google/protobuf_c/message.c b/libs/protobuf/ruby/ext/google/protobuf_c/message.c index 6295136..fd83dc1 100644 --- a/libs/protobuf/ruby/ext/google/protobuf_c/message.c +++ b/libs/protobuf/ruby/ext/google/protobuf_c/message.c @@ -37,7 +37,6 @@ #include "repeated_field.h" static VALUE cParseError = Qnil; -static VALUE cAbstractMessage = Qnil; static ID descriptor_instancevar_interned; static VALUE initialize_rb_class_with_no_args(VALUE klass) { @@ -696,20 +695,15 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2, if (m1 == m2) return true; size_t size1, size2; - int encode_opts = - kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + int encode_opts = kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic; upb_Arena* arena_tmp = upb_Arena_New(); const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); // Compare deterministically serialized payloads with no unknown fields. - char* data1; - char* data2; - upb_EncodeStatus status1 = - upb_Encode(m1, layout, encode_opts, arena_tmp, &data1, &size1); - upb_EncodeStatus status2 = - upb_Encode(m2, layout, encode_opts, arena_tmp, &data2, &size2); + char* data1 = upb_Encode(m1, layout, encode_opts, arena_tmp, &size1); + char* data2 = upb_Encode(m2, layout, encode_opts, arena_tmp, &size2); - if (status1 == kUpb_EncodeStatus_Ok && status2 == kUpb_EncodeStatus_Ok) { + if (data1 && data2) { bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); upb_Arena_Free(arena_tmp); return ret; @@ -741,16 +735,15 @@ static VALUE Message_eq(VALUE _self, VALUE _other) { uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m, uint64_t seed) { upb_Arena* arena = upb_Arena_New(); - char* data; + const char* data; size_t size; // Hash a deterministically serialized payloads with no unknown fields. - upb_EncodeStatus status = upb_Encode( - msg, upb_MessageDef_MiniTable(m), - kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic, arena, - &data, &size); + data = upb_Encode(msg, upb_MessageDef_MiniTable(m), + kUpb_Encode_SkipUnknown | kUpb_Encode_Deterministic, arena, + &size); - if (status == kUpb_EncodeStatus_Ok) { + if (data) { uint64_t ret = _upb_Hash(data, size, seed); upb_Arena_Free(arena); return ret; @@ -976,8 +969,7 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) { rb_raise(rb_eArgError, "Expected hash arguments."); } - VALUE depth = - rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit"))); + VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit"))); if (depth != Qnil && TYPE(depth) == T_FIXNUM) { options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth)); @@ -991,10 +983,9 @@ static VALUE Message_decode(int argc, VALUE* argv, VALUE klass) { VALUE msg_rb = initialize_rb_class_with_no_args(klass); Message* msg = ruby_to_Message(msg_rb); - upb_DecodeStatus status = - upb_Decode(RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg, - upb_MessageDef_MiniTable(msg->msgdef), NULL, options, - Arena_get(msg->arena)); + upb_DecodeStatus status = upb_Decode( + RSTRING_PTR(data), RSTRING_LEN(data), (upb_Message*)msg->msg, + upb_MessageDef_MiniTable(msg->msgdef), NULL, options, Arena_get(msg->arena)); if (status != kUpb_DecodeStatus_Ok) { rb_raise(cParseError, "Error occurred during parsing"); @@ -1078,7 +1069,7 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) { Message* msg = ruby_to_Message(argv[0]); int options = 0; - char* data; + const char* data; size_t size; if (CLASS_OF(argv[0]) != klass) { @@ -1094,21 +1085,19 @@ static VALUE Message_encode(int argc, VALUE* argv, VALUE klass) { if (TYPE(hash_args) != T_HASH) { rb_raise(rb_eArgError, "Expected hash arguments."); } - VALUE depth = - rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit"))); + VALUE depth = rb_hash_lookup(hash_args, ID2SYM(rb_intern("recursion_limit"))); if (depth != Qnil && TYPE(depth) == T_FIXNUM) { options |= UPB_DECODE_MAXDEPTH(FIX2INT(depth)); } } - upb_Arena* arena = upb_Arena_New(); + upb_Arena *arena = upb_Arena_New(); - upb_EncodeStatus status = - upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), options, - arena, &data, &size); + data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->msgdef), + options, arena, &size); - if (status == kUpb_EncodeStatus_Ok) { + if (data) { VALUE ret = rb_str_new(data, size); rb_enc_associate(ret, rb_ascii8bit_encoding()); upb_Arena_Free(arena); @@ -1146,8 +1135,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { if (argc == 2) { VALUE hash_args = argv[1]; if (TYPE(hash_args) != T_HASH) { - if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1, - rb_str_new2("to_h")))) { + if (RTEST(rb_funcall(hash_args, rb_intern("respond_to?"), 1, rb_str_new2("to_h")))) { hash_args = rb_funcall(hash_args, rb_intern("to_h"), 0); } else { rb_raise(rb_eArgError, "Expected hash arguments."); @@ -1213,8 +1201,36 @@ VALUE build_class_from_descriptor(VALUE descriptor) { klass = rb_define_class_id( // Docs say this parameter is ignored. User will assign return value to // their own toplevel constant class name. - rb_intern("Message"), cAbstractMessage); + rb_intern("Message"), rb_cObject); rb_ivar_set(klass, descriptor_instancevar_interned, descriptor); + rb_define_alloc_func(klass, Message_alloc); + rb_require("google/protobuf/message_exts"); + rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts")); + rb_extend_object( + klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods")); + + rb_define_method(klass, "method_missing", Message_method_missing, -1); + rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing, + -1); + rb_define_method(klass, "initialize", Message_initialize, -1); + rb_define_method(klass, "dup", Message_dup, 0); + // Also define #clone so that we don't inherit Object#clone. + rb_define_method(klass, "clone", Message_dup, 0); + rb_define_method(klass, "==", Message_eq, 1); + rb_define_method(klass, "eql?", Message_eq, 1); + rb_define_method(klass, "freeze", Message_freeze, 0); + rb_define_method(klass, "hash", Message_hash, 0); + rb_define_method(klass, "to_h", Message_to_h, 0); + rb_define_method(klass, "inspect", Message_inspect, 0); + rb_define_method(klass, "to_s", Message_inspect, 0); + rb_define_method(klass, "[]", Message_index, 1); + rb_define_method(klass, "[]=", Message_index_set, 2); + rb_define_singleton_method(klass, "decode", Message_decode, -1); + rb_define_singleton_method(klass, "encode", Message_encode, -1); + rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); + rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); + rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); + return klass; } @@ -1274,7 +1290,9 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { int n = upb_EnumDef_ValueCount(e); for (int i = 0; i < n; i++) { const upb_EnumValueDef* ev = upb_EnumDef_Value(e, i); - char* name = strdup(upb_EnumValueDef_Name(ev)); + upb_Arena* arena = upb_Arena_New(); + const char* src_name = upb_EnumValueDef_Name(ev); + char* name = upb_strdup2(src_name, strlen(src_name), arena); int32_t value = upb_EnumValueDef_Number(ev); if (name[0] < 'A' || name[0] > 'Z') { if (name[0] >= 'a' && name[0] <= 'z') { @@ -1287,7 +1305,7 @@ VALUE build_module_from_enumdesc(VALUE _enumdesc) { } } rb_define_const(mod, name, INT2NUM(value)); - free(name); + upb_Arena_Free(arena); } rb_define_singleton_method(mod, "lookup", enum_lookup, 1); @@ -1306,13 +1324,11 @@ upb_Message* Message_deep_copy(const upb_Message* msg, const upb_MessageDef* m, const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); size_t size; + char* data = upb_Encode(msg, layout, 0, tmp_arena, &size); upb_Message* new_msg = upb_Message_New(m, arena); - char* data; - if (upb_Encode(msg, layout, 0, tmp_arena, &data, &size) != - kUpb_EncodeStatus_Ok || - upb_Decode(data, size, new_msg, layout, NULL, 0, arena) != - kUpb_DecodeStatus_Ok) { + if (!data || upb_Decode(data, size, new_msg, layout, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { upb_Arena_Free(tmp_arena); rb_raise(cParseError, "Error occurred copying proto"); } @@ -1383,42 +1399,11 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m, return self->msg; } -static void Message_define_class(VALUE klass) { - rb_define_alloc_func(klass, Message_alloc); - - rb_require("google/protobuf/message_exts"); - rb_define_method(klass, "method_missing", Message_method_missing, -1); - rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing, - -1); - rb_define_method(klass, "initialize", Message_initialize, -1); - rb_define_method(klass, "dup", Message_dup, 0); - // Also define #clone so that we don't inherit Object#clone. - rb_define_method(klass, "clone", Message_dup, 0); - rb_define_method(klass, "==", Message_eq, 1); - rb_define_method(klass, "eql?", Message_eq, 1); - rb_define_method(klass, "freeze", Message_freeze, 0); - rb_define_method(klass, "hash", Message_hash, 0); - rb_define_method(klass, "to_h", Message_to_h, 0); - rb_define_method(klass, "inspect", Message_inspect, 0); - rb_define_method(klass, "to_s", Message_inspect, 0); - rb_define_method(klass, "[]", Message_index, 1); - rb_define_method(klass, "[]=", Message_index_set, 2); - rb_define_singleton_method(klass, "decode", Message_decode, -1); - rb_define_singleton_method(klass, "encode", Message_encode, -1); - rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1); - rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1); - rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0); -} - void Message_register(VALUE protobuf) { cParseError = rb_const_get(protobuf, rb_intern("ParseError")); - cAbstractMessage = - rb_define_class_under(protobuf, "AbstractMessage", rb_cObject); - Message_define_class(cAbstractMessage); - rb_gc_register_address(&cAbstractMessage); // Ruby-interned string: "descriptor". We use this identifier to store an // instance variable on message classes we create in order to link them back // to their descriptors. - descriptor_instancevar_interned = rb_intern("@descriptor"); + descriptor_instancevar_interned = rb_intern("descriptor"); } diff --git a/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.c b/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.c old mode 100644 new mode 100755 index 3be0900..3d3c35b --- a/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.c @@ -1,5 +1,31 @@ /* Amalgamated source file */ #include "ruby-upb.h" +/* + * Copyright (c) 2009-2021, Google LLC + * All rights reserved. + * + * 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 LLC 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 Google LLC 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 is where we define macros used across upb. @@ -25,25 +51,13 @@ */ #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - (defined(__cplusplus) && __cplusplus >= 201402L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) || \ (defined(_MSC_VER) && _MSC_VER >= 1900)) -#error upb requires C99 or C++14 or MSVC >= 2015. +#error upb requires C99 or C++11 or MSVC >= 2015. #endif -// Portable check for GCC minimum version: -// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define UPB_GNUC_MIN(x, y) \ - (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) -#else -#define UPB_GNUC_MIN(x, y) 0 -#endif - -#include -#include -#include -#include #include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -82,16 +96,16 @@ #define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) -/* Hints to the compiler about likely/unlikely branches. */ +// Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) -#define UPB_LIKELY(x) __builtin_expect((x),1) -#define UPB_UNLIKELY(x) __builtin_expect((x),0) +#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) +#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) #else #define UPB_LIKELY(x) (x) #define UPB_UNLIKELY(x) (x) #endif -/* Macros for function attributes on compilers that support them. */ +// Macros for function attributes on compilers that support them. #ifdef __GNUC__ #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) #define UPB_NOINLINE __attribute__((noinline)) @@ -114,8 +128,7 @@ #define UPB_UNUSED(var) (void)var -/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. - */ +// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. #ifdef NDEBUG #ifdef __GNUC__ #define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable() @@ -217,11 +230,7 @@ #undef UPB_FASTTABLE_SUPPORTED -/* ASAN poisoning (for arena). - * If using UPB from an interpreted language like Ruby, a build of the - * interpreter compiled with ASAN enabled must be used in order to get sane and - * expected behavior. - */ +/* ASAN poisoning (for arena) *************************************************/ #if defined(__SANITIZE_ADDRESS__) #define UPB_ASAN 1 @@ -253,127 +262,10 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0 #endif -#if defined(__cplusplus) -#if defined(__clang__) || UPB_GNUC_MIN(6, 0) -// https://gcc.gnu.org/gcc-6/changes.html -#if __cplusplus >= 201402L -#define UPB_DEPRECATED [[deprecated]] -#else -#define UPB_DEPRECATED __attribute__((deprecated)) -#endif -#else -#define UPB_DEPRECATED -#endif -#else -#define UPB_DEPRECATED -#endif - +/** upb/collections.c ************************************************************/ #include -// Must be last. - -bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { - size_t new_capacity = UPB_MAX(arr->capacity, 4); - int elem_size_lg2 = arr->data & 7; - size_t old_bytes = arr->capacity << elem_size_lg2; - size_t new_bytes; - void* ptr = _upb_array_ptr(arr); - - /* Log2 ceiling of size. */ - while (new_capacity < min_capacity) new_capacity *= 2; - - new_bytes = new_capacity << elem_size_lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - - if (!ptr) { - return false; - } - - arr->data = _upb_tag_arrptr(ptr, elem_size_lg2); - arr->capacity = new_capacity; - return true; -} - -static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2, - upb_Arena* arena) { - upb_Array* arr = *arr_ptr; - if (!arr) { - arr = _upb_Array_New(arena, 4, elem_size_lg2); - if (!arr) return NULL; - *arr_ptr = arr; - } - return arr; -} - -void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, - int elem_size_lg2, upb_Arena* arena) { - upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); - return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr) - : NULL; -} - -bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, - int elem_size_lg2, upb_Arena* arena) { - upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); - if (!arr) return false; - - size_t elems = arr->size; - - if (!_upb_Array_Resize(arr, elems + 1, arena)) { - return false; - } - - char* data = _upb_array_ptr(arr); - memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2); - return true; -} - - -// Must be last. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; -} - -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; - - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } - - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } - - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; -} - - -#include - - -// Must be last. /* Strings/bytes are special-cased in maps. */ static char _upb_CTypeo_mapsize[12] = { @@ -391,6 +283,90 @@ static char _upb_CTypeo_mapsize[12] = { 0, /* kUpb_CType_Bytes */ }; +static const char _upb_CTypeo_sizelg2[12] = { + 0, + 0, /* kUpb_CType_Bool */ + 2, /* kUpb_CType_Float */ + 2, /* kUpb_CType_Int32 */ + 2, /* kUpb_CType_UInt32 */ + 2, /* kUpb_CType_Enum */ + UPB_SIZE(2, 3), /* kUpb_CType_Message */ + 3, /* kUpb_CType_Double */ + 3, /* kUpb_CType_Int64 */ + 3, /* kUpb_CType_UInt64 */ + UPB_SIZE(3, 4), /* kUpb_CType_String */ + UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ +}; + +/** upb_Array *****************************************************************/ + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); +} + +size_t upb_Array_Size(const upb_Array* arr) { return arr->len; } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + UPB_ASSERT(i < arr->len); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + if (!upb_Array_Resize(arr, arr->len + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->len - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + char* data = _upb_array_ptr(arr); + int lg2 = arr->data & 7; + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(i <= arr->len); + UPB_ASSERT(count + arr->len >= count); + size_t oldsize = arr->len; + if (!upb_Array_Resize(arr, arr->len + count, arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->len + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->len); + upb_Array_Move(arr, i, end, arr->len - end); + arr->len -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + return _upb_Array_Resize(arr, size, arena); +} + +/** upb_Map *******************************************************************/ + upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { return _upb_Map_New(a, _upb_CTypeo_mapsize[key_type], _upb_CTypeo_mapsize[value_type]); @@ -448,7 +424,8 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { /* void upb_MapIterator_SetValue(upb_Map *map, size_t iter, upb_MessageValue * value); */ -/* This file was generated by upbc (the upb compiler) from the input + +/** bazel-out/k8-fastbuild/bin/external/com_google_protobuf/google/protobuf/descriptor.upb.c ************************************************************//* This file was generated by upbc (the upb compiler) from the input * file: * * google/protobuf/descriptor.proto @@ -460,91 +437,90 @@ upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { static const upb_MiniTable_Sub google_protobuf_FileDescriptorSet_submsgs[1] = { - {.submsg = &google_protobuf_FileDescriptorProto_msg_init}, + {.submsg = &google_protobuf_FileDescriptorProto_msginit}, }; static const upb_MiniTable_Field google_protobuf_FileDescriptorSet__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init = { +const upb_MiniTable google_protobuf_FileDescriptorSet_msginit = { &google_protobuf_FileDescriptorSet_submsgs[0], &google_protobuf_FileDescriptorSet__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FileDescriptorProto_submsgs[6] = { - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_FileOptions_msg_init}, - {.submsg = &google_protobuf_SourceCodeInfo_msg_init}, + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_ServiceDescriptorProto_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_FileOptions_msginit}, + {.submsg = &google_protobuf_SourceCodeInfo_msginit}, }; -static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[13] = { - {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(48, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(4, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(8, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(12, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(16, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(20, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(24, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(28, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(32, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(36, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {13, UPB_SIZE(64, 128), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static const upb_MiniTable_Field google_protobuf_FileDescriptorProto__fields[12] = { + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(20, 40), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(24, 48), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(28, 56), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(32, 64), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(36, 72), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(40, 80), UPB_SIZE(3, 3), 4, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(44, 88), UPB_SIZE(4, 4), 5, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(48, 96), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(52, 104), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {12, UPB_SIZE(56, 112), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_FileDescriptorProto_msginit = { &google_protobuf_FileDescriptorProto_submsgs[0], &google_protobuf_FileDescriptorProto__fields[0], - UPB_SIZE(72, 144), 13, kUpb_ExtMode_NonExtendable, 13, 255, 0, + UPB_SIZE(64, 128), 12, kUpb_ExtMode_NonExtendable, 12, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_DescriptorProto_submsgs[8] = { - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msg_init}, - {.submsg = &google_protobuf_FieldDescriptorProto_msg_init}, - {.submsg = &google_protobuf_MessageOptions_msg_init}, - {.submsg = &google_protobuf_OneofDescriptorProto_msg_init}, - {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msg_init}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ExtensionRange_msginit}, + {.submsg = &google_protobuf_FieldDescriptorProto_msginit}, + {.submsg = &google_protobuf_MessageOptions_msginit}, + {.submsg = &google_protobuf_OneofDescriptorProto_msginit}, + {.submsg = &google_protobuf_DescriptorProto_ReservedRange_msginit}, }; static const upb_MiniTable_Field google_protobuf_DescriptorProto__fields[10] = { - {1, UPB_SIZE(40, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 32), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(12, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(16, 48), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(20, 56), UPB_SIZE(0, 0), 4, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(24, 64), UPB_SIZE(2, 2), 5, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(28, 72), UPB_SIZE(0, 0), 6, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(32, 80), UPB_SIZE(0, 0), 7, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(36, 88), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 32), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(20, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(24, 48), UPB_SIZE(0, 0), 3, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(28, 56), UPB_SIZE(0, 0), 4, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(32, 64), UPB_SIZE(2, 2), 5, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(36, 72), UPB_SIZE(0, 0), 6, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(40, 80), UPB_SIZE(0, 0), 7, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(44, 88), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_msginit = { &google_protobuf_DescriptorProto_submsgs[0], &google_protobuf_DescriptorProto__fields[0], UPB_SIZE(48, 96), 10, kUpb_ExtMode_NonExtendable, 10, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = { - {.submsg = &google_protobuf_ExtensionRangeOptions_msg_init}, + {.submsg = &google_protobuf_ExtensionRangeOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = { {1, UPB_SIZE(4, 4), UPB_SIZE(1, 1), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(12, 16), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 16), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit = { &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0], &google_protobuf_DescriptorProto_ExtensionRange__fields[0], UPB_SIZE(16, 24), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, @@ -555,82 +531,82 @@ static const upb_MiniTable_Field google_protobuf_DescriptorProto_ReservedRange__ {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msg_init = { +const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit = { NULL, &google_protobuf_DescriptorProto_ReservedRange__fields[0], UPB_SIZE(16, 16), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ExtensionRangeOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_ExtensionRangeOptions__fields[1] = { - {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init = { +const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit = { &google_protobuf_ExtensionRangeOptions_submsgs[0], &google_protobuf_ExtensionRangeOptions__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FieldDescriptorProto_submsgs[3] = { - {.subenum = &google_protobuf_FieldDescriptorProto_Label_enum_init}, - {.subenum = &google_protobuf_FieldDescriptorProto_Type_enum_init}, - {.submsg = &google_protobuf_FieldOptions_msg_init}, + {.subenum = &google_protobuf_FieldDescriptorProto_Label_enuminit}, + {.subenum = &google_protobuf_FieldDescriptorProto_Type_enuminit}, + {.submsg = &google_protobuf_FieldOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_FieldDescriptorProto__fields[11] = { - {1, UPB_SIZE(28, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(36, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(24, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(32, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(4, 4), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {4, UPB_SIZE(8, 8), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {5, UPB_SIZE(12, 12), UPB_SIZE(5, 5), 1, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(44, 56), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(52, 72), UPB_SIZE(7, 7), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(16, 88), UPB_SIZE(8, 8), 2, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {9, UPB_SIZE(20, 16), UPB_SIZE(9, 9), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {10, UPB_SIZE(60, 96), UPB_SIZE(10, 10), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {17, UPB_SIZE(24, 20), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(40, 56), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(48, 72), UPB_SIZE(7, 7), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(56, 88), UPB_SIZE(8, 8), 2, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {9, UPB_SIZE(16, 16), UPB_SIZE(9, 9), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {10, UPB_SIZE(60, 96), UPB_SIZE(10, 10), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {17, UPB_SIZE(20, 20), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit = { &google_protobuf_FieldDescriptorProto_submsgs[0], &google_protobuf_FieldDescriptorProto__fields[0], UPB_SIZE(72, 112), 11, kUpb_ExtMode_NonExtendable, 10, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_OneofDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_OneofOptions_msg_init}, + {.submsg = &google_protobuf_OneofOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_OneofDescriptorProto__fields[2] = { - {1, UPB_SIZE(8, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(4, 24), UPB_SIZE(2, 2), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit = { &google_protobuf_OneofDescriptorProto_submsgs[0], &google_protobuf_OneofDescriptorProto__fields[0], UPB_SIZE(16, 32), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumDescriptorProto_submsgs[3] = { - {.submsg = &google_protobuf_EnumValueDescriptorProto_msg_init}, - {.submsg = &google_protobuf_EnumOptions_msg_init}, - {.submsg = &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init}, + {.submsg = &google_protobuf_EnumValueDescriptorProto_msginit}, + {.submsg = &google_protobuf_EnumOptions_msginit}, + {.submsg = &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto__fields[5] = { - {1, UPB_SIZE(20, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(12, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(16, 48), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(20, 40), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(24, 48), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit = { &google_protobuf_EnumDescriptorProto_submsgs[0], &google_protobuf_EnumDescriptorProto__fields[0], UPB_SIZE(32, 56), 5, kUpb_ExtMode_NonExtendable, 5, 255, 0, @@ -641,75 +617,75 @@ static const upb_MiniTable_Field google_protobuf_EnumDescriptorProto_EnumReserve {2, UPB_SIZE(8, 8), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init = { +const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = { NULL, &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0], UPB_SIZE(16, 16), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumValueDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_EnumValueOptions_msg_init}, + {.submsg = &google_protobuf_EnumValueOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumValueDescriptorProto__fields[3] = { - {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(8, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(4, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 24), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 24), UPB_SIZE(3, 3), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit = { &google_protobuf_EnumValueDescriptorProto_submsgs[0], &google_protobuf_EnumValueDescriptorProto__fields[0], UPB_SIZE(24, 32), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ServiceDescriptorProto_submsgs[2] = { - {.submsg = &google_protobuf_MethodDescriptorProto_msg_init}, - {.submsg = &google_protobuf_ServiceOptions_msg_init}, + {.submsg = &google_protobuf_MethodDescriptorProto_msginit}, + {.submsg = &google_protobuf_ServiceOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_ServiceDescriptorProto__fields[3] = { - {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(4, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(16, 32), UPB_SIZE(2, 2), 1, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit = { &google_protobuf_ServiceDescriptorProto_submsgs[0], &google_protobuf_ServiceDescriptorProto__fields[0], UPB_SIZE(24, 40), 3, kUpb_ExtMode_NonExtendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MethodDescriptorProto_submsgs[1] = { - {.submsg = &google_protobuf_MethodOptions_msg_init}, + {.submsg = &google_protobuf_MethodOptions_msginit}, }; static const upb_MiniTable_Field google_protobuf_MethodDescriptorProto__fields[6] = { - {1, UPB_SIZE(12, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(20, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(28, 40), UPB_SIZE(3, 3), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(4, 56), UPB_SIZE(4, 4), 0, 11, kUpb_FieldMode_Scalar | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(8, 1), UPB_SIZE(5, 5), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(9, 2), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(12, 24), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(20, 40), UPB_SIZE(3, 3), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(28, 56), UPB_SIZE(4, 4), 0, 11, kUpb_FieldMode_Scalar | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(1, 1), UPB_SIZE(5, 5), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(2, 2), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init = { +const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit = { &google_protobuf_MethodDescriptorProto_submsgs[0], &google_protobuf_MethodDescriptorProto__fields[0], - UPB_SIZE(40, 64), 6, kUpb_ExtMode_NonExtendable, 6, 255, 0, + UPB_SIZE(32, 64), 6, kUpb_ExtMode_NonExtendable, 6, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FileOptions_submsgs[2] = { - {.subenum = &google_protobuf_FileOptions_OptimizeMode_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_FileOptions_OptimizeMode_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { - {1, UPB_SIZE(24, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(32, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(28, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {9, UPB_SIZE(4, 4), UPB_SIZE(3, 3), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, UPB_SIZE(8, 8), UPB_SIZE(4, 4), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(40, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(36, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {16, UPB_SIZE(9, 9), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {17, UPB_SIZE(10, 10), UPB_SIZE(7, 7), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {18, UPB_SIZE(11, 11), UPB_SIZE(8, 8), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, @@ -717,25 +693,25 @@ static const upb_MiniTable_Field google_protobuf_FileOptions__fields[21] = { {23, UPB_SIZE(13, 13), UPB_SIZE(10, 10), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {27, UPB_SIZE(14, 14), UPB_SIZE(11, 11), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {31, UPB_SIZE(15, 15), UPB_SIZE(12, 12), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(48, 72), UPB_SIZE(13, 13), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(56, 88), UPB_SIZE(14, 14), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(64, 104), UPB_SIZE(15, 15), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(72, 120), UPB_SIZE(16, 16), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(80, 136), UPB_SIZE(17, 17), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {36, UPB_SIZE(44, 72), UPB_SIZE(13, 13), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {37, UPB_SIZE(52, 88), UPB_SIZE(14, 14), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {39, UPB_SIZE(60, 104), UPB_SIZE(15, 15), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {40, UPB_SIZE(68, 120), UPB_SIZE(16, 16), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {41, UPB_SIZE(76, 136), UPB_SIZE(17, 17), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {42, UPB_SIZE(16, 16), UPB_SIZE(18, 18), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(88, 152), UPB_SIZE(19, 19), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(96, 168), UPB_SIZE(20, 20), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 184), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {44, UPB_SIZE(84, 152), UPB_SIZE(19, 19), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {45, UPB_SIZE(92, 168), UPB_SIZE(20, 20), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(100, 184), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FileOptions_msg_init = { +const upb_MiniTable google_protobuf_FileOptions_msginit = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], UPB_SIZE(104, 192), 21, kUpb_ExtMode_Extendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MessageOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { @@ -743,19 +719,19 @@ static const upb_MiniTable_Field google_protobuf_MessageOptions__fields[5] = { {2, UPB_SIZE(2, 2), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(3, 3), UPB_SIZE(3, 3), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {7, UPB_SIZE(4, 4), UPB_SIZE(4, 4), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MessageOptions_msg_init = { +const upb_MiniTable google_protobuf_MessageOptions_msginit = { &google_protobuf_MessageOptions_submsgs[0], &google_protobuf_MessageOptions__fields[0], UPB_SIZE(16, 16), 5, kUpb_ExtMode_Extendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_FieldOptions_submsgs[3] = { - {.subenum = &google_protobuf_FieldOptions_CType_enum_init}, - {.subenum = &google_protobuf_FieldOptions_JSType_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_FieldOptions_CType_enuminit}, + {.subenum = &google_protobuf_FieldOptions_JSType_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[8] = { @@ -766,284 +742,251 @@ static const upb_MiniTable_Field google_protobuf_FieldOptions__fields[8] = { {6, UPB_SIZE(12, 12), UPB_SIZE(5, 5), 1, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, UPB_SIZE(16, 16), UPB_SIZE(6, 6), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {15, UPB_SIZE(17, 17), UPB_SIZE(7, 7), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(20, 24), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 24), UPB_SIZE(0, 0), 2, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_FieldOptions_msg_init = { +const upb_MiniTable google_protobuf_FieldOptions_msginit = { &google_protobuf_FieldOptions_submsgs[0], &google_protobuf_FieldOptions__fields[0], UPB_SIZE(24, 32), 8, kUpb_ExtMode_Extendable, 3, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_OneofOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_OneofOptions__fields[1] = { - {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_OneofOptions_msg_init = { +const upb_MiniTable google_protobuf_OneofOptions_msginit = { &google_protobuf_OneofOptions_submsgs[0], &google_protobuf_OneofOptions__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumOptions__fields[3] = { {2, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {3, UPB_SIZE(2, 2), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumOptions_msg_init = { +const upb_MiniTable google_protobuf_EnumOptions_msginit = { &google_protobuf_EnumOptions_submsgs[0], &google_protobuf_EnumOptions__fields[0], UPB_SIZE(8, 16), 3, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_EnumValueOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_EnumValueOptions__fields[2] = { {1, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_EnumValueOptions_msg_init = { +const upb_MiniTable google_protobuf_EnumValueOptions_msginit = { &google_protobuf_EnumValueOptions_submsgs[0], &google_protobuf_EnumValueOptions__fields[0], UPB_SIZE(8, 16), 2, kUpb_ExtMode_Extendable, 1, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_ServiceOptions_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_ServiceOptions__fields[2] = { {33, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_ServiceOptions_msg_init = { +const upb_MiniTable google_protobuf_ServiceOptions_msginit = { &google_protobuf_ServiceOptions_submsgs[0], &google_protobuf_ServiceOptions__fields[0], UPB_SIZE(8, 16), 2, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_MethodOptions_submsgs[2] = { - {.subenum = &google_protobuf_MethodOptions_IdempotencyLevel_enum_init}, - {.submsg = &google_protobuf_UninterpretedOption_msg_init}, + {.subenum = &google_protobuf_MethodOptions_IdempotencyLevel_enuminit}, + {.submsg = &google_protobuf_UninterpretedOption_msginit}, }; static const upb_MiniTable_Field google_protobuf_MethodOptions__fields[3] = { {33, UPB_SIZE(1, 1), UPB_SIZE(1, 1), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {34, UPB_SIZE(4, 4), UPB_SIZE(2, 2), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(8, 8), UPB_SIZE(0, 0), 1, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_MethodOptions_msg_init = { +const upb_MiniTable google_protobuf_MethodOptions_msginit = { &google_protobuf_MethodOptions_submsgs[0], &google_protobuf_MethodOptions__fields[0], UPB_SIZE(16, 16), 3, kUpb_ExtMode_Extendable, 0, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_UninterpretedOption_submsgs[1] = { - {.submsg = &google_protobuf_UninterpretedOption_NamePart_msg_init}, + {.submsg = &google_protobuf_UninterpretedOption_NamePart_msginit}, }; static const upb_MiniTable_Field google_protobuf_UninterpretedOption__fields[7] = { - {2, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 16), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(16, 32), UPB_SIZE(2, 2), kUpb_NoSub, 4, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(24, 40), UPB_SIZE(3, 3), kUpb_NoSub, 3, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(32, 48), UPB_SIZE(4, 4), kUpb_NoSub, 1, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, - {7, UPB_SIZE(40, 56), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(48, 72), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(4, 8), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(8, 16), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(32, 64), UPB_SIZE(2, 2), kUpb_NoSub, 4, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {5, UPB_SIZE(40, 72), UPB_SIZE(3, 3), kUpb_NoSub, 3, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(48, 80), UPB_SIZE(4, 4), kUpb_NoSub, 1, kUpb_FieldMode_Scalar | (kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}, + {7, UPB_SIZE(16, 32), UPB_SIZE(5, 5), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, UPB_SIZE(24, 48), UPB_SIZE(6, 6), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_UninterpretedOption_msg_init = { +const upb_MiniTable google_protobuf_UninterpretedOption_msginit = { &google_protobuf_UninterpretedOption_submsgs[0], &google_protobuf_UninterpretedOption__fields[0], UPB_SIZE(56, 88), 7, kUpb_ExtMode_NonExtendable, 0, 255, 0, }; static const upb_MiniTable_Field google_protobuf_UninterpretedOption_NamePart__fields[2] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {2, UPB_SIZE(1, 1), UPB_SIZE(2, 2), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msg_init = { +const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit = { NULL, &google_protobuf_UninterpretedOption_NamePart__fields[0], UPB_SIZE(16, 24), 2, kUpb_ExtMode_NonExtendable, 2, 255, 2, }; static const upb_MiniTable_Sub google_protobuf_SourceCodeInfo_submsgs[1] = { - {.submsg = &google_protobuf_SourceCodeInfo_Location_msg_init}, + {.submsg = &google_protobuf_SourceCodeInfo_Location_msginit}, }; static const upb_MiniTable_Field google_protobuf_SourceCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init = { +const upb_MiniTable google_protobuf_SourceCodeInfo_msginit = { &google_protobuf_SourceCodeInfo_submsgs[0], &google_protobuf_SourceCodeInfo__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, }; static const upb_MiniTable_Field google_protobuf_SourceCodeInfo_Location__fields[5] = { - {1, UPB_SIZE(4, 8), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(8, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(16, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(24, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {6, UPB_SIZE(12, 56), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | kUpb_LabelFlags_IsAlternate | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(4, 8), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(8, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(12, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(20, 40), UPB_SIZE(2, 2), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {6, UPB_SIZE(28, 56), UPB_SIZE(0, 0), kUpb_NoSub, 12, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init = { +const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit = { NULL, &google_protobuf_SourceCodeInfo_Location__fields[0], UPB_SIZE(32, 64), 5, kUpb_ExtMode_NonExtendable, 4, 255, 0, }; static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_submsgs[1] = { - {.submsg = &google_protobuf_GeneratedCodeInfo_Annotation_msg_init}, + {.submsg = &google_protobuf_GeneratedCodeInfo_Annotation_msginit}, }; static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo__fields[1] = { - {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, }; -const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init = { +const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit = { &google_protobuf_GeneratedCodeInfo_submsgs[0], &google_protobuf_GeneratedCodeInfo__fields[0], UPB_SIZE(8, 8), 1, kUpb_ExtMode_NonExtendable, 1, 255, 0, }; -static const upb_MiniTable_Sub google_protobuf_GeneratedCodeInfo_Annotation_submsgs[1] = { - {.subenum = &google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init}, +static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = { + {1, UPB_SIZE(12, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)}, + {2, UPB_SIZE(16, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {3, UPB_SIZE(4, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, + {4, UPB_SIZE(8, 8), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, }; -static const upb_MiniTable_Field google_protobuf_GeneratedCodeInfo_Annotation__fields[5] = { - {1, UPB_SIZE(4, 16), UPB_SIZE(0, 0), kUpb_NoSub, 5, kUpb_FieldMode_Array | kUpb_LabelFlags_IsPacked | (UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {2, UPB_SIZE(20, 24), UPB_SIZE(1, 1), kUpb_NoSub, 12, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsAlternate | (kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {3, UPB_SIZE(8, 4), UPB_SIZE(2, 2), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {4, UPB_SIZE(12, 8), UPB_SIZE(3, 3), kUpb_NoSub, 5, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, - {5, UPB_SIZE(16, 12), UPB_SIZE(4, 4), 0, 14, kUpb_FieldMode_Scalar | (kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, -}; - -const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init = { - &google_protobuf_GeneratedCodeInfo_Annotation_submsgs[0], +const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit = { + NULL, &google_protobuf_GeneratedCodeInfo_Annotation__fields[0], - UPB_SIZE(32, 40), 5, kUpb_ExtMode_NonExtendable, 5, 255, 0, + UPB_SIZE(24, 40), 4, kUpb_ExtMode_NonExtendable, 4, 255, 0, }; static const upb_MiniTable *messages_layout[27] = { - &google_protobuf_FileDescriptorSet_msg_init, - &google_protobuf_FileDescriptorProto_msg_init, - &google_protobuf_DescriptorProto_msg_init, - &google_protobuf_DescriptorProto_ExtensionRange_msg_init, - &google_protobuf_DescriptorProto_ReservedRange_msg_init, - &google_protobuf_ExtensionRangeOptions_msg_init, - &google_protobuf_FieldDescriptorProto_msg_init, - &google_protobuf_OneofDescriptorProto_msg_init, - &google_protobuf_EnumDescriptorProto_msg_init, - &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, - &google_protobuf_EnumValueDescriptorProto_msg_init, - &google_protobuf_ServiceDescriptorProto_msg_init, - &google_protobuf_MethodDescriptorProto_msg_init, - &google_protobuf_FileOptions_msg_init, - &google_protobuf_MessageOptions_msg_init, - &google_protobuf_FieldOptions_msg_init, - &google_protobuf_OneofOptions_msg_init, - &google_protobuf_EnumOptions_msg_init, - &google_protobuf_EnumValueOptions_msg_init, - &google_protobuf_ServiceOptions_msg_init, - &google_protobuf_MethodOptions_msg_init, - &google_protobuf_UninterpretedOption_msg_init, - &google_protobuf_UninterpretedOption_NamePart_msg_init, - &google_protobuf_SourceCodeInfo_msg_init, - &google_protobuf_SourceCodeInfo_Location_msg_init, - &google_protobuf_GeneratedCodeInfo_msg_init, - &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, + &google_protobuf_FileDescriptorSet_msginit, + &google_protobuf_FileDescriptorProto_msginit, + &google_protobuf_DescriptorProto_msginit, + &google_protobuf_DescriptorProto_ExtensionRange_msginit, + &google_protobuf_DescriptorProto_ReservedRange_msginit, + &google_protobuf_ExtensionRangeOptions_msginit, + &google_protobuf_FieldDescriptorProto_msginit, + &google_protobuf_OneofDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_msginit, + &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, + &google_protobuf_EnumValueDescriptorProto_msginit, + &google_protobuf_ServiceDescriptorProto_msginit, + &google_protobuf_MethodDescriptorProto_msginit, + &google_protobuf_FileOptions_msginit, + &google_protobuf_MessageOptions_msginit, + &google_protobuf_FieldOptions_msginit, + &google_protobuf_OneofOptions_msginit, + &google_protobuf_EnumOptions_msginit, + &google_protobuf_EnumValueOptions_msginit, + &google_protobuf_ServiceOptions_msginit, + &google_protobuf_MethodOptions_msginit, + &google_protobuf_UninterpretedOption_msginit, + &google_protobuf_UninterpretedOption_NamePart_msginit, + &google_protobuf_SourceCodeInfo_msginit, + &google_protobuf_SourceCodeInfo_Location_msginit, + &google_protobuf_GeneratedCodeInfo_msginit, + &google_protobuf_GeneratedCodeInfo_Annotation_msginit, }; -const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit = { + NULL, + 0x7fffeULL, 0, - { - 0x7fffe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit = { + NULL, + 0xeULL, 0, - { - 0xe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit = { + NULL, + 0xeULL, 0, - { - 0xe, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enum_init = { - 64, +const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit = { + NULL, + 0x7ULL, 0, - { - 0x7, - 0x0, - }, }; -const upb_MiniTable_Enum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init = { - 64, - 0, - { - 0x7, - 0x0, - }, -}; - -static const upb_MiniTable_Enum *enums_layout[7] = { - &google_protobuf_FieldDescriptorProto_Type_enum_init, - &google_protobuf_FieldDescriptorProto_Label_enum_init, - &google_protobuf_FileOptions_OptimizeMode_enum_init, - &google_protobuf_FieldOptions_CType_enum_init, - &google_protobuf_FieldOptions_JSType_enum_init, - &google_protobuf_MethodOptions_IdempotencyLevel_enum_init, - &google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init, +static const upb_MiniTable_Enum *enums_layout[6] = { + &google_protobuf_FieldDescriptorProto_Type_enuminit, + &google_protobuf_FieldDescriptorProto_Label_enuminit, + &google_protobuf_FileOptions_OptimizeMode_enuminit, + &google_protobuf_FieldOptions_CType_enuminit, + &google_protobuf_FieldOptions_JSType_enuminit, + &google_protobuf_MethodOptions_IdempotencyLevel_enuminit, }; const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { @@ -1051,76 +994,13 @@ const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout = { enums_layout, NULL, 27, - 7, + 6, 0, }; - - -// Must be last. - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */ -}; - -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); -} - -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; -} - -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, - size_t count) { - char buf[EXTREG_KEY_SIZE]; - const upb_MiniTable_Extension** start = e; - const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - // TODO: we should gracefully handle the case where this already exists. - // Right now we're only checking for out of memory. - const upb_MiniTable_Extension* ext = *e; - extreg_key(buf, ext->extendee, ext->field.number); - if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(ext), r->arena)) { - goto failure; - } - } - return true; - -failure: - /* Back out the entries previously added. */ - for (end = e, e = start; e < end; e++) { - const upb_MiniTable_Extension* ext = *e; - extreg_key(buf, ext->extendee, ext->field.number); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); - } - return false; -} - -const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - char buf[EXTREG_KEY_SIZE]; - upb_value v; - extreg_key(buf, t, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); - } else { - return NULL; - } -} - +/** upb/decode_fast.c ************************************************************/ // Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. // Also the table size grows by 2x. // @@ -1133,7 +1013,7 @@ const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( -// Must be last. +/* Must be last. */ #if UPB_FASTTABLE @@ -1149,7 +1029,7 @@ const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( /* Uncomment either of these for debugging purposes. */ \ /* fprintf(stderr, m); */ \ /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); + return fastdecode_generic(d, ptr, msg, table, hasbits, 0); typedef enum { CARD_s = 0, /* Singular (optional, non-repeated) */ @@ -1162,10 +1042,12 @@ UPB_NOINLINE static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { int overrun = data; int status; - ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status); - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, status); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); + if (ptr == NULL) { + return fastdecode_err(d, status); + } + data = fastdecode_loadtag(ptr); + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE @@ -1177,7 +1059,7 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { *(uint32_t*)msg |= hasbits; // Sync hasbits. const upb_MiniTable* l = decode_totablep(table); return UPB_UNLIKELY(l->required_count) - ? _upb_Decoder_CheckRequired(d, ptr, msg, l) + ? decode_checkrequired(d, ptr, msg, l) : ptr; } else { data = overrun; @@ -1186,8 +1068,8 @@ static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { } // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); + data = fastdecode_loadtag(ptr); + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE @@ -1266,9 +1148,9 @@ static const char* fastdecode_delimited(upb_Decoder* d, const char* ptr, // Corrupt wire format: invalid limit. return NULL; } - int delta = _upb_Decoder_PushLimit(d, ptr, len); + int delta = decode_pushlimit(d, ptr, len); ptr = func(d, ptr, ctx); - _upb_Decoder_PopLimit(d, ptr, delta); + decode_poplimit(d, ptr, delta); } else { // Fast case: Sub-message is <128 bytes and fits in the current buffer. // This means we can preserve limit/limit_ptr verbatim. @@ -1308,14 +1190,14 @@ UPB_FORCEINLINE static void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr, int valbytes) { if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_size = farr->arr->capacity; + size_t old_size = farr->arr->size; size_t old_bytes = old_size * valbytes; size_t new_size = old_size * 2; size_t new_bytes = new_size * valbytes; char* old_ptr = _upb_array_ptr(farr->arr); char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - farr->arr->capacity = new_size; + farr->arr->size = new_size; farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2); dst = (void*)(new_ptr + (old_size * valbytes)); farr->end = (void*)(new_ptr + (new_size * valbytes)); @@ -1335,7 +1217,7 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { UPB_FORCEINLINE static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { - farr->arr->size = + farr->arr->len = (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } @@ -1348,8 +1230,8 @@ static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, fastdecode_nextret ret; dst = (char*)dst + valbytes; - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (UPB_LIKELY(!decode_isdone(d, ptr))) { + ret.tag = fastdecode_loadtag(*ptr); if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { ret.next = FD_NEXT_SAMEFIELD; } else { @@ -1404,9 +1286,9 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, farr->arr = *arr_p; } begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->capacity * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->size * valbytes); + farr->end = begin + (farr->arr->size * valbytes); + *data = fastdecode_loadtag(ptr); + return begin + (farr->arr->len * valbytes); } default: UPB_UNREACHABLE(); @@ -1492,7 +1374,7 @@ done: \ ptr += tagbytes; \ ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + if (ptr == NULL) return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ val = fastdecode_munge(val, valbytes, zigzag); \ memcpy(dst, &val, valbytes); \ \ @@ -1505,7 +1387,7 @@ done: goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -1527,7 +1409,7 @@ static const char* fastdecode_topackedvarint(upb_Decoder* d, const char* ptr, void* dst = data->dst; uint64_t val; - while (!_upb_Decoder_IsDone(d, &ptr)) { + while (!decode_isdone(d, &ptr)) { dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); ptr = fastdecode_varint64(ptr, &val); if (ptr == NULL) return NULL; @@ -1556,7 +1438,7 @@ static const char* fastdecode_topackedvarint(upb_Decoder* d, const char* ptr, ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ \ if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); @@ -1651,7 +1533,7 @@ TAGBYTES(p) goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -1672,7 +1554,7 @@ TAGBYTES(p) \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr) || \ (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ @@ -1683,7 +1565,7 @@ TAGBYTES(p) if (UPB_LIKELY(!arr)) { \ *arr_p = arr = _upb_Array_New(&d->arena, elems, elem_size_lg2); \ if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ } else { \ _upb_Array_Resize(arr, elems, &d->arena); \ @@ -1691,7 +1573,7 @@ TAGBYTES(p) \ char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ - arr->size = elems; \ + arr->len = elems; \ \ ptr += size; \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); @@ -1749,8 +1631,8 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data) { upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + if (!decode_verifyutf8_inl(dst->data, dst->size)) { + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); } UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } @@ -1764,7 +1646,7 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, \ if (UPB_UNLIKELY(fastdecode_boundscheck(ptr, size, d->limit_ptr))) { \ dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ if (d->options & kUpb_DecodeOption_AliasString) { \ @@ -1773,7 +1655,7 @@ static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, } else { \ char* data = upb_Arena_Malloc(&d->arena, size); \ if (!data) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + return fastdecode_err(d, kUpb_DecodeStatus_OutOfMemory); \ } \ memcpy(data, ptr, size); \ dst->data = data; \ @@ -1864,9 +1746,8 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += size; \ \ if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ } \ fastdecode_nextret ret = fastdecode_nextrepeated( \ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ @@ -1876,7 +1757,7 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -1943,9 +1824,8 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += size; \ \ if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + if (validate_utf8 && !decode_verifyutf8_inl(dst->data, dst->size)) { \ + return fastdecode_err(d, kUpb_DecodeStatus_BadUtf8); \ } \ fastdecode_nextret ret = fastdecode_nextrepeated( \ d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ @@ -1958,12 +1838,12 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, /* data also. */ \ fastdecode_commitarr(dst, &farr, sizeof(upb_StringView)); \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ } \ goto again; \ case FD_NEXT_OTHERFIELD: \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ return ptr; \ } \ @@ -2058,7 +1938,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, } \ \ if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + return fastdecode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); \ } \ \ upb_Message** dst; \ @@ -2095,7 +1975,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ \ if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + return fastdecode_err(d, kUpb_DecodeStatus_Malformed); \ } \ \ if (card == CARD_r) { \ @@ -2108,7 +1988,7 @@ static const char* fastdecode_tosubmsg(upb_Decoder* d, const char* ptr, case FD_NEXT_OTHERFIELD: \ d->depth++; \ data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + UPB_MUSTTAIL return fastdecode_tagdispatch(UPB_PARSE_ARGS); \ case FD_NEXT_ATLIMIT: \ d->depth++; \ return ptr; \ @@ -2147,17 +2027,19 @@ TAGBYTES(r) #endif /* UPB_FASTTABLE */ +/** upb/json_decode.c ************************************************************/ #include #include #include #include #include +#include #include #include -// Must be last. +/* Special header, must be included last. */ typedef struct { const char *ptr, *end; @@ -2494,20 +2376,44 @@ static uint32_t jsondec_codepoint(jsondec* d) { /* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ static size_t jsondec_unicode(jsondec* d, char* out) { uint32_t cp = jsondec_codepoint(d); - if (upb_Unicode_IsHigh(cp)) { + if (cp >= 0xd800 && cp <= 0xdbff) { /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ + uint32_t high = cp; + uint32_t low; jsondec_parselit(d, "\\u"); - uint32_t low = jsondec_codepoint(d); - if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); - cp = upb_Unicode_FromPair(cp, low); - } else if (upb_Unicode_IsLow(cp)) { + low = jsondec_codepoint(d); + if (low < 0xdc00 || low > 0xdfff) { + jsondec_err(d, "Invalid low surrogate"); + } + cp = (high & 0x3ff) << 10; + cp |= (low & 0x3ff); + cp += 0x10000; + } else if (cp >= 0xdc00 && cp <= 0xdfff) { jsondec_err(d, "Unpaired low surrogate"); } /* Write to UTF-8 */ - int bytes = upb_Unicode_ToUTF8(cp, out); - if (bytes == 0) jsondec_err(d, "Invalid codepoint"); - return bytes; + if (cp <= 0x7f) { + out[0] = cp; + return 1; + } else if (cp <= 0x07FF) { + out[0] = ((cp >> 6) & 0x1F) | 0xC0; + out[1] = ((cp >> 0) & 0x3F) | 0x80; + return 2; + } else if (cp <= 0xFFFF) { + out[0] = ((cp >> 12) & 0x0F) | 0xE0; + out[1] = ((cp >> 6) & 0x3F) | 0x80; + out[2] = ((cp >> 0) & 0x3F) | 0x80; + return 3; + } else if (cp < 0x10FFFF) { + out[0] = ((cp >> 18) & 0x07) | 0xF0; + out[1] = ((cp >> 12) & 0x3f) | 0x80; + out[2] = ((cp >> 6) & 0x3f) | 0x80; + out[3] = ((cp >> 0) & 0x3f) | 0x80; + return 4; + } else { + jsondec_err(d, "Invalid codepoint"); + } } static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { @@ -2553,7 +2459,7 @@ static upb_StringView jsondec_string(jsondec* d) { if (*d->ptr == 'u') { d->ptr++; if (buf_end - end < 4) { - /* Allow space for maximum-sized codepoint (4 bytes). */ + /* Allow space for maximum-sized code point (4 bytes). */ jsondec_resize(d, &buf, &end, &buf_end); } end += jsondec_unicode(d, end); @@ -2726,19 +2632,44 @@ static size_t jsondec_base64(jsondec* d, upb_StringView str) { /* Low-level integer parsing **************************************************/ +/* We use these hand-written routines instead of strto[u]l() because the "long + * long" variants aren't in c89. Also our version allows setting a ptr limit. */ + static const char* jsondec_buftouint64(jsondec* d, const char* ptr, const char* end, uint64_t* val) { - const char* out = upb_BufToUint64(ptr, end, val); - if (!out) jsondec_err(d, "Integer overflow"); - return out; + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + jsondec_err(d, "Integer overflow"); + } + u64 *= 10; + u64 += ch; + ptr++; + } + + *val = u64; + return ptr; } static const char* jsondec_buftoint64(jsondec* d, const char* ptr, - const char* end, int64_t* val, - bool* is_neg) { - const char* out = upb_BufToInt64(ptr, end, val, is_neg); - if (!out) jsondec_err(d, "Integer overflow"); - return out; + const char* end, int64_t* val) { + bool neg = false; + uint64_t u64; + + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } + + ptr = jsondec_buftouint64(d, ptr, end, &u64); + if (u64 > (uint64_t)INT64_MAX + neg) { + jsondec_err(d, "Integer overflow"); + } + + *val = neg ? -u64 : u64; + return ptr; } static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { @@ -2753,7 +2684,7 @@ static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { const char* end = str.data + str.size; int64_t ret; - if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { + if (jsondec_buftoint64(d, str.data, end, &ret) != end) { jsondec_err(d, "Non-number characters in quoted integer"); } return ret; @@ -2860,11 +2791,11 @@ static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { } if (upb_FieldDef_CType(f) == kUpb_CType_Float) { - float f = val.double_val; - if (val.double_val != INFINITY && val.double_val != -INFINITY) { - if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); + if (val.double_val != INFINITY && val.double_val != -INFINITY && + (val.double_val > FLT_MAX || val.double_val < -FLT_MAX)) { + jsondec_err(d, "Float out of range"); } - val.float_val = f; + val.float_val = val.double_val; } return val; @@ -2987,8 +2918,7 @@ static void jsondec_tomsg(jsondec* d, upb_Message* msg, static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); - upb_Message* msg = upb_Message_New(layout, d->arena); + upb_Message* msg = upb_Message_New(m, d->arena); upb_MessageValue val; jsondec_tomsg(d, msg, m); @@ -3223,10 +3153,9 @@ static void jsondec_duration(jsondec* d, upb_Message* msg, const char* ptr = str.data; const char* end = ptr + str.size; const int64_t max = (uint64_t)3652500 * 86400; - bool neg = false; /* "3.000000001s", "3s", etc. */ - ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); + ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val); nanos.int32_val = jsondec_nanos(d, &ptr, end); if (end - ptr != 1 || *ptr != 's') { @@ -3237,7 +3166,7 @@ static void jsondec_duration(jsondec* d, upb_Message* msg, jsondec_err(d, "Duration out of range"); } - if (neg) { + if (seconds.int64_val < 0) { nanos.int32_val = -nanos.int32_val; } @@ -3250,12 +3179,11 @@ static void jsondec_listvalue(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + upb_Message* value_msg = upb_Message_New(value_m, d->arena); upb_MessageValue value; value.msg_val = value_msg; upb_Array_Append(values, value, d->arena); @@ -3270,13 +3198,12 @@ static void jsondec_struct(jsondec* d, upb_Message* msg, const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; jsondec_objstart(d); while (jsondec_objnext(d)) { upb_MessageValue key, value; - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + upb_Message* value_msg = upb_Message_New(value_m, d->arena); key.str_val = jsondec_string(d); value.msg_val = value_msg; upb_Map_Set(fields, key, value, d->arena); @@ -3478,8 +3405,7 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { jsondec_err(d, "Any object didn't contain a '@type' field"); } - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - any_msg = upb_Message_New(any_layout, d->arena); + any_msg = upb_Message_New(any_m, d->arena); if (pre_type_data) { size_t len = pre_type_end - pre_type_data + 1; @@ -3504,11 +3430,8 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { jsondec_objend(d); - upb_EncodeStatus status = - upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, - (char**)&encoded.str_val.data, &encoded.str_val.size); - // TODO(b/235839510): We should fail gracefully here on a bad return status. - UPB_ASSERT(status == kUpb_EncodeStatus_Ok); + encoded.str_val.data = upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, + d->arena, &encoded.str_val.size); upb_Message_Set(msg, value_f, encoded, d->arena); } @@ -3584,17 +3507,19 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, return true; } +/** upb/json_encode.c ************************************************************/ #include #include #include #include +#include #include #include #include -// Must be last. +/* Must be last. */ typedef struct { char *buf, *ptr, *end; @@ -3741,27 +3666,17 @@ static void jsonenc_duration(jsonenc* e, const upb_Message* msg, const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); int64_t seconds = upb_Message_Get(msg, seconds_f).int64_val; int32_t nanos = upb_Message_Get(msg, nanos_f).int32_val; - bool negative = false; if (seconds > 315576000000 || seconds < -315576000000 || - (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { + (seconds < 0) != (nanos < 0)) { jsonenc_err(e, "bad duration"); } - if (seconds < 0) { - negative = true; - seconds = -seconds; - } if (nanos < 0) { - negative = true; nanos = -nanos; } - jsonenc_putstr(e, "\""); - if (negative) { - jsonenc_putstr(e, "-"); - } - jsonenc_printf(e, "%" PRId64, seconds); + jsonenc_printf(e, "\"%" PRId64, seconds); jsonenc_nanos(e, nanos); jsonenc_putstr(e, "s\""); } @@ -3772,10 +3687,7 @@ static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { jsonenc_putstr(e, "null"); } else { - const upb_EnumValueDef* ev = - (e->options & upb_JsonEncode_FormatEnumsAsIntegers) - ? NULL - : upb_EnumDef_FindValueByNumber(e_def, val); + const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e_def, val); if (ev) { jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); @@ -3951,7 +3863,7 @@ static void jsonenc_any(jsonenc* e, const upb_Message* msg, const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); upb_Arena* arena = jsonenc_arena(e); - upb_Message* any = upb_Message_New(any_layout, arena); + upb_Message* any = upb_Message_New(any_m, arena); if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { @@ -4341,6 +4253,7 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, return jsonenc_nullz(&e, size); } +/** upb/mini_table.c ************************************************************/ #include #include @@ -4361,19 +4274,19 @@ typedef enum { kUpb_EncodedType_Int64 = 9, kUpb_EncodedType_UInt64 = 10, kUpb_EncodedType_SInt64 = 11, - kUpb_EncodedType_OpenEnum = 12, + kUpb_EncodedType_Enum = 12, kUpb_EncodedType_Bool = 13, kUpb_EncodedType_Bytes = 14, kUpb_EncodedType_String = 15, kUpb_EncodedType_Group = 16, kUpb_EncodedType_Message = 17, - kUpb_EncodedType_ClosedEnum = 18, kUpb_EncodedType_RepeatedBase = 20, } upb_EncodedType; typedef enum { kUpb_EncodedFieldModifier_FlipPacked = 1 << 0, + kUpb_EncodedFieldModifier_IsClosedEnum = 1 << 1, // upb only. kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2, kUpb_EncodedFieldModifier_IsRequired = 1 << 3, @@ -4381,7 +4294,7 @@ typedef enum { enum { kUpb_EncodedValue_MinField = ' ', - kUpb_EncodedValue_MaxField = 'I', + kUpb_EncodedValue_MaxField = 'K', kUpb_EncodedValue_MinModifier = 'L', kUpb_EncodedValue_MaxModifier = '[', kUpb_EncodedValue_End = '^', @@ -4394,12 +4307,6 @@ enum { kUpb_EncodedValue_MaxEnumMask = 'A', }; -enum { - kUpb_EncodedVersion_EnumV1 = '!', - kUpb_EncodedVersion_ExtensionV1 = '#', - kUpb_EncodedVersion_MessageV1 = '$', -}; - char upb_ToBase92(int8_t ch) { static const char kUpb_ToBase92[] = { ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', @@ -4473,19 +4380,14 @@ static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( return ret; } -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); if (ptr == e->end) return NULL; - *ptr++ = ch; + *ptr++ = upb_ToBase92(ch); return ptr; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, upb_ToBase92(ch)); -} - static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, uint32_t val, int min, int max) { int shift = _upb_Log2Ceiling(upb_FromBase92(max) - upb_FromBase92(min) + 1); @@ -4510,30 +4412,12 @@ char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, return ptr; } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; - - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); -} - char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, uint64_t msg_mod) { upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); in->state.msg_state.msg_modifiers = msg_mod; in->state.msg_state.last_field_num = 0; in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); } @@ -4554,7 +4438,7 @@ char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, [kUpb_FieldType_Message] = kUpb_EncodedType_Message, [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_Enum] = kUpb_EncodedType_Enum, [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, @@ -4576,11 +4460,12 @@ char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, uint32_t encoded_modifiers = 0; // Put field type. - int encoded_type = kUpb_TypeToEncoded[type]; - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; + if (type == kUpb_FieldType_Enum && + !(field_mod & kUpb_FieldModifier_IsClosedEnum)) { + type = kUpb_FieldType_Int32; } + + int encoded_type = kUpb_TypeToEncoded[type]; if (field_mod & kUpb_FieldModifier_IsRepeated) { // Repeated fields shift the type number up (unlike other modifiers which // are bit flags). @@ -4633,12 +4518,10 @@ char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, return ptr; } -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); +void upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, NULL); in->state.enum_state.present_values_mask = 0; in->state.enum_state.last_written_value = 0; - - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); } static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, @@ -4658,9 +4541,6 @@ char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, uint32_t delta = val - in->state.enum_state.last_written_value; if (delta >= 5 && in->state.enum_state.present_values_mask) { ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } delta -= 5; } @@ -4693,19 +4573,6 @@ const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( return NULL; } -upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field) { - if (field->mode & kUpb_LabelFlags_IsAlternate) { - if (field->descriptortype == kUpb_FieldType_Int32) { - return kUpb_FieldType_Enum; - } else if (field->descriptortype == kUpb_FieldType_Bytes) { - return kUpb_FieldType_String; - } else { - UPB_ASSERT(false); - } - } - return field->descriptortype; -} - /** Data decoder **************************************************************/ // Note: we sort by this number when calculating layout order. @@ -4742,13 +4609,6 @@ typedef struct { upb_LayoutItemVector vec; upb_Arena* arena; upb_Status* status; - - // When building enums. - upb_MiniTable_Enum* enum_table; - uint32_t enum_value_count; - uint32_t enum_data_count; - uint32_t enum_data_capacity; - jmp_buf err; } upb_MtDecoder; @@ -4790,6 +4650,7 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, char ch = first_ch; while (1) { uint32_t bits = upb_FromBase92(ch) - upb_FromBase92(min); + UPB_ASSERT(shift < 32); val |= bits << shift; if (ptr == d->end || *ptr < min || max < *ptr) { *out_val = val; @@ -4797,7 +4658,6 @@ static const char* upb_MiniTable_DecodeBase92Varint(upb_MtDecoder* d, } ch = *ptr++; shift += bits_per_char; - if (shift >= 32) upb_MtDecoder_ErrorFormat(d, "Overlong varint"); } } @@ -4811,7 +4671,6 @@ static bool upb_MiniTable_HasSub(upb_MiniTable_Field* field, case kUpb_FieldType_String: if (!(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { field->descriptortype = kUpb_FieldType_Bytes; - field->mode |= kUpb_LabelFlags_IsAlternate; } return false; default: @@ -4826,16 +4685,8 @@ static bool upb_MtDecoder_FieldIsPackable(upb_MiniTable_Field* field) { static void upb_MiniTable_SetTypeAndSub(upb_MiniTable_Field* field, upb_FieldType type, uint32_t* sub_count, - uint64_t msg_modifiers, - bool is_proto3_enum) { + uint64_t msg_modifiers) { field->descriptortype = type; - - if (is_proto3_enum) { - UPB_ASSERT(field->descriptortype == kUpb_FieldType_Enum); - field->descriptortype = kUpb_FieldType_Int32; - field->mode |= kUpb_LabelFlags_IsAlternate; - } - if (upb_MiniTable_HasSub(field, msg_modifiers)) { field->submsg_index = sub_count ? (*sub_count)++ : 0; } else { @@ -4862,14 +4713,15 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, + [kUpb_EncodedType_Group] = kUpb_FieldRep_Pointer, + [kUpb_EncodedType_Message] = kUpb_FieldRep_Pointer, [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Enum] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, }; static const char kUpb_EncodedToType[] = { @@ -4886,42 +4738,30 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, [kUpb_EncodedType_Message] = kUpb_FieldType_Message, [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, + [kUpb_EncodedType_Enum] = kUpb_FieldType_Enum, [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, }; - char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit - ? kUpb_FieldRep_4Byte - : kUpb_FieldRep_8Byte; - int8_t type = upb_FromBase92(ch); if (ch >= upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { type -= kUpb_EncodedType_RepeatedBase; field->mode = kUpb_FieldMode_Array; - field->mode |= pointer_rep << kUpb_FieldRep_Shift; + field->mode |= kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift; field->offset = kNoPresence; } else { field->mode = kUpb_FieldMode_Scalar; + field->mode |= kUpb_EncodedToFieldRep[type] << kUpb_FieldRep_Shift; field->offset = kHasbitPresence; - if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { - field->mode |= pointer_rep << kUpb_FieldRep_Shift; - } else if (type >= sizeof(kUpb_EncodedToFieldRep)) { - upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); - UPB_UNREACHABLE(); - } else { - field->mode |= kUpb_EncodedToFieldRep[type] << kUpb_FieldRep_Shift; - } } - if (type >= sizeof(kUpb_EncodedToType)) { + if (type >= 18) { upb_MtDecoder_ErrorFormat(d, "Invalid field type: %d", (int)type); UPB_UNREACHABLE(); } upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_count, - msg_modifiers, type == kUpb_EncodedType_OpenEnum); + msg_modifiers); } static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, @@ -4989,15 +4829,13 @@ static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, upb_MiniTablePlatform platform) { static const uint8_t kRepToSize32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_Pointer] = 4, [kUpb_FieldRep_StringView] = 8, [kUpb_FieldRep_8Byte] = 8, }; static const uint8_t kRepToSize64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 16, + [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_Pointer] = 8, [kUpb_FieldRep_StringView] = 16, [kUpb_FieldRep_8Byte] = 8, }; UPB_ASSERT(sizeof(upb_StringView) == @@ -5009,15 +4847,13 @@ size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, upb_MiniTablePlatform platform) { static const uint8_t kRepToAlign32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 4, + [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_Pointer] = 4, [kUpb_FieldRep_StringView] = 4, [kUpb_FieldRep_8Byte] = 8, }; static const uint8_t kRepToAlign64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_1Byte] = 1, [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_Pointer] = 8, [kUpb_FieldRep_StringView] = 8, [kUpb_FieldRep_8Byte] = 8, }; UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == @@ -5110,16 +4946,13 @@ static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, uint32_t sub_count) { size_t subs_bytes = sizeof(*d->table->subs) * sub_count; - void* subs = upb_Arena_Malloc(d->arena, subs_bytes); - memset(subs, 0, subs_bytes); - d->table->subs = subs; + d->table->subs = upb_Arena_Malloc(d->arena, subs_bytes); upb_MtDecoder_CheckOutOfMemory(d, d->table->subs); } -static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, - size_t len, void* fields, - size_t field_size, uint16_t* field_count, - uint32_t* sub_count) { +static void upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, size_t len, + void* fields, size_t field_size, + uint16_t* field_count, uint32_t* sub_count) { uint64_t msg_modifiers = 0; uint32_t last_field_number = 0; upb_MiniTable_Field* last_field = NULL; @@ -5130,10 +4963,6 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, while (ptr < d->end) { char ch = *ptr++; if (ch <= kUpb_EncodedValue_MaxField) { - if (!d->table && last_field) { - // For extensions, consume only a single field and then return. - return --ptr; - } upb_MiniTable_Field* field = fields; *field_count += 1; fields = (char*)fields + field_size; @@ -5164,17 +4993,12 @@ static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, kUpb_EncodedValue_MaxSkip, &skip); last_field_number += skip; last_field_number--; // Next field seen will increment. - } else { - upb_MtDecoder_ErrorFormat(d, "Invalid char: %c", ch); - UPB_UNREACHABLE(); } } if (need_dense_below) { d->table->dense_below = d->table->field_count; } - - return ptr; } static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, @@ -5271,13 +5095,7 @@ size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); size_t ret = UPB_ALIGN_UP(d->table->size, align); - static const size_t max = UINT16_MAX; - size_t new_size = ret + size; - if (new_size > max) { - upb_MtDecoder_ErrorFormat( - d, "Message size exceeded maximum size of %zu bytes", max); - } - d->table->size = new_size; + d->table->size = ret + size; return ret; } @@ -5353,16 +5171,6 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, goto done; } - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_MessageV1) { - upb_MtDecoder_ErrorFormat(&decoder, "Invalid message version: %c", *data); - UPB_UNREACHABLE(); - } - data++; - len--; - } - upb_MtDecoder_CheckOutOfMemory(&decoder, decoder.table); decoder.table->size = 0; @@ -5379,7 +5187,7 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, done: *buf = decoder.vec.data; - *buf_size = decoder.vec.capacity * sizeof(*decoder.vec.data); + *buf_size = decoder.vec.capacity / sizeof(*decoder.vec.data); return decoder.table; } @@ -5407,12 +5215,9 @@ upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, if (!ret || !fields) return NULL; upb_MiniTable_Sub* subs = NULL; - if (value_is_proto3_enum) { - UPB_ASSERT(value_type == kUpb_FieldType_Enum); - // No sub needed. - } else if (value_type == kUpb_FieldType_Message || - value_type == kUpb_FieldType_Group || - value_type == kUpb_FieldType_Enum) { + if (value_is_proto3_enum) value_type = kUpb_FieldType_Int32; + if (value_type == kUpb_FieldType_Message || + value_type == kUpb_FieldType_Group || value_type == kUpb_FieldType_Enum) { subs = upb_Arena_Malloc(arena, sizeof(*subs)); if (!subs) return NULL; } @@ -5429,9 +5234,8 @@ upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, fields[0].offset = 0; fields[1].offset = field_size; - upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0, false); - upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0, - value_is_proto3_enum); + upb_MiniTable_SetTypeAndSub(&fields[0], key_type, NULL, 0); + upb_MiniTable_SetTypeAndSub(&fields[1], value_type, NULL, 0); ret->size = UPB_ALIGN_UP(2 * field_size, 8); ret->field_count = 2; @@ -5444,90 +5248,60 @@ upb_MiniTable* upb_MiniTable_BuildMapEntry(upb_FieldType key_type, return ret; } -static size_t upb_MiniTable_EnumSize(size_t count) { - return sizeof(upb_MiniTable_Enum) + count * sizeof(uint32_t); -} - -static upb_MiniTable_Enum* _upb_MiniTable_AddEnumDataMember(upb_MtDecoder* d, - uint32_t val) { - if (d->enum_data_count == d->enum_data_capacity) { - size_t old_sz = upb_MiniTable_EnumSize(d->enum_data_capacity); - d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); - size_t new_sz = upb_MiniTable_EnumSize(d->enum_data_capacity); - d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); - upb_MtDecoder_CheckOutOfMemory(d, d->enum_table); +static bool upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, + upb_MiniTable_Enum* table, + uint32_t val, upb_Arena* arena) { + if (val < 64) { + table->mask |= 1ULL << val; + return true; } - d->enum_table->data[d->enum_data_count++] = val; - return d->enum_table; -} -static void upb_MiniTable_BuildEnumValue(upb_MtDecoder* d, uint32_t val) { - upb_MiniTable_Enum* table = d->enum_table; - d->enum_value_count++; - if (table->value_count || (val > 512 && d->enum_value_count < val / 32)) { - if (table->value_count == 0) { - assert(d->enum_data_count == table->mask_limit / 32); - } - table = _upb_MiniTable_AddEnumDataMember(d, val); - table->value_count++; - } else { - uint32_t new_mask_limit = ((val / 32) + 1) * 32; - while (table->mask_limit < new_mask_limit) { - table = _upb_MiniTable_AddEnumDataMember(d, 0); - table->mask_limit += 32; - } - table->data[val / 32] |= 1ULL << (val % 32); - } + int32_t* values = (void*)table->values; + values = upb_Arena_Realloc(arena, values, table->value_count * 4, + (table->value_count + 1) * 4); + upb_MtDecoder_CheckOutOfMemory(d, values); + values[table->value_count++] = (int32_t)val; + table->values = values; + return true; } upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, upb_Arena* arena, upb_Status* status) { - upb_MtDecoder decoder = { - .enum_table = upb_Arena_Malloc(arena, upb_MiniTable_EnumSize(2)), - .enum_value_count = 0, - .enum_data_count = 0, - .enum_data_capacity = 1, + upb_MtDecoder d = { .status = status, .end = UPB_PTRADD(data, len), - .arena = arena, }; - if (UPB_SETJMP(decoder.err)) return NULL; - - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_EnumV1) { - upb_MtDecoder_ErrorFormat(&decoder, "Invalid enum version: %c", *data); - UPB_UNREACHABLE(); - } - data++; - len--; + if (UPB_SETJMP(d.err)) { + return NULL; } - upb_MtDecoder_CheckOutOfMemory(&decoder, decoder.enum_table); + upb_MiniTable_Enum* table = upb_Arena_Malloc(arena, sizeof(*table)); + upb_MtDecoder_CheckOutOfMemory(&d, table); - // Guarantee at least 64 bits of mask without checking mask size. - decoder.enum_table->mask_limit = 64; - decoder.enum_table = _upb_MiniTable_AddEnumDataMember(&decoder, 0); - decoder.enum_table = _upb_MiniTable_AddEnumDataMember(&decoder, 0); - - decoder.enum_table->value_count = 0; + table->mask = 0; + table->value_count = 0; + table->values = NULL; const char* ptr = data; uint32_t base = 0; - while (ptr < decoder.end) { + while (ptr < d.end) { char ch = *ptr++; if (ch <= kUpb_EncodedValue_MaxEnumMask) { uint32_t mask = upb_FromBase92(ch); for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTable_BuildEnumValue(&decoder, base); + if (mask & 1) { + if (!upb_MiniTable_BuildEnumValue(&d, table, base, arena)) { + return NULL; + } + } } } else if (kUpb_EncodedValue_MinSkip <= ch && ch <= kUpb_EncodedValue_MaxSkip) { uint32_t skip; - ptr = upb_MiniTable_DecodeBase92Varint(&decoder, ptr, ch, + ptr = upb_MiniTable_DecodeBase92Varint(&d, ptr, ch, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip, &skip); base += skip; @@ -5537,55 +5311,27 @@ upb_MiniTable_Enum* upb_MiniTable_BuildEnum(const char* data, size_t len, } } - return decoder.enum_table; + return table; } -const char* upb_MiniTable_BuildExtension(const char* data, size_t len, - upb_MiniTable_Extension* ext, - const upb_MiniTable* extendee, - upb_MiniTable_Sub sub, - upb_Status* status) { +bool upb_MiniTable_BuildExtension(const char* data, size_t len, + upb_MiniTable_Extension* ext, + upb_MiniTable_Sub sub, upb_Status* status) { upb_MtDecoder decoder = { .arena = NULL, .status = status, .table = NULL, }; - if (UPB_SETJMP(decoder.err)) return NULL; - - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_ExtensionV1) { - upb_MtDecoder_ErrorFormat(&decoder, "Invalid ext version: %c", *data); - UPB_UNREACHABLE(); - } - data++; - len--; + if (UPB_SETJMP(decoder.err)) { + return false; } uint16_t count = 0; - const char* ret = - upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL); - if (!ret || count != 1) return NULL; - - upb_MiniTable_Field* f = &ext->field; - - f->mode |= kUpb_LabelFlags_IsExtension; - f->offset = 0; - f->presence = 0; - - if (extendee->ext & kUpb_ExtMode_IsMessageSet) { - // Extensions of MessageSet must be messages. - if (!upb_IsSubMessage(f)) return NULL; - - // Extensions of MessageSet must be non-repeating. - if ((f->mode & kUpb_FieldMode_Mask) == kUpb_FieldMode_Array) return NULL; - } - - ext->extendee = extendee; - ext->sub = sub; - - return ret; + upb_MtDecoder_Parse(&decoder, data, len, ext, sizeof(*ext), &count, NULL); + ext->field.mode |= kUpb_LabelFlags_IsExtension; + ext->field.offset = 0; + return true; } upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, @@ -5606,7 +5352,8 @@ void upb_MiniTable_SetSubMessage(upb_MiniTable* table, (uintptr_t)field < (uintptr_t)(table->fields + table->field_count)); if (sub->ext & kUpb_ExtMode_IsMapEntry) { - field->mode = (field->mode & ~kUpb_FieldMode_Mask) | kUpb_FieldMode_Map; + field->mode = + (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift) | kUpb_FieldMode_Map; } upb_MiniTable_Sub* table_sub = (void*)&table->subs[field->submsg_index]; table_sub->submsg = sub; @@ -5621,10 +5368,21 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, table_sub->subenum = sub; } +/** upb/def.c ************************************************************/ + +#include +#include +#include +#include #include -// Must be last. +/* Must be last. */ + +typedef struct { + size_t len; + char str[1]; /* Null-terminated string data follows. */ +} str_t; /* The upb core does not generally have a concept of default instances. However * for descriptor options we make an exception since the max size is known and @@ -5633,1185 +5391,7 @@ void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, * * We have to allocate an extra pointer for upb's internal metadata. */ static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; - -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; - - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } -} - -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } - -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(ctx->status, fmt, argp); - va_end(argp); - _upb_DefBuilder_FailJmp(ctx); -} - -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); -} - -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { - if (prefix) { - // ret = prefix + '.' + name; - size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); - strcpy(ret, prefix); - ret[n] = '.'; - memcpy(&ret[n + 1], name.data, name.size); - ret[n + 1 + name.size] = '\0'; - return ret; - } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; - } -} - -static bool remove_component(char* base, size_t* len) { - if (*len == 0) return false; - - for (size_t i = *len - 1; i > 0; i--) { - if (base[i] == '.') { - *len = i; - return true; - } - } - - *len = 0; - return true; -} - -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { - if (sym.size == 0) goto notfound; - upb_value v; - if (sym.data[0] == '.') { - /* Symbols starting with '.' are absolute, so we do a single lookup. - * Slice to omit the leading '.' */ - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { - goto notfound; - } - } else { - /* Remove components from base until we find an entry or run out. */ - size_t baselen = base ? strlen(base) : 0; - char* tmp = malloc(sym.size + baselen + 1); - while (1) { - char* p = tmp; - if (baselen) { - memcpy(p, base, baselen); - p[baselen] = '.'; - p += baselen + 1; - } - memcpy(p, sym.data, sym.size); - p += sym.size; - if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { - break; - } - if (!remove_component(tmp, &baselen)) { - free(tmp); - goto notfound; - } - } - free(tmp); - } - - *type = _upb_DefType_Type(v); - return _upb_DefType_Unpack(v, *type); - -notfound: - _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(sym)); -} - -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type) { - upb_deftype_t found_type; - const void* ret = - _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); - if (ret && found_type != type) { - _upb_DefBuilder_Errf(ctx, - "type mismatch when resolving %s: couldn't find " - "name " UPB_STRINGVIEW_FORMAT " with type=%d", - from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); - } - return ret; -} - -// Per ASCII this will lower-case a letter. If the result is a letter, the -// input was definitely a letter. If the output is not a letter, this may -// have transformed the character unpredictably. -static char upb_ascii_lower(char ch) { return ch | 0x20; } - -// isalpha() etc. from are locale-dependent, which we don't want. -static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { - return low <= c && c <= high; -} - -static bool upb_isletter(char c) { - char lower = upb_ascii_lower(c); - return upb_isbetween(lower, 'a', 'z') || c == '_'; -} - -static bool upb_isalphanum(char c) { - return upb_isletter(c) || upb_isbetween(c, '0', '9'); -} - -static bool TryGetChar(const char** src, const char* end, char* ch) { - if (*src == end) return false; - *ch = **src; - *src += 1; - return true; -} - -static char TryGetHexDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '9') { - return ch - '0'; - } - ch = upb_ascii_lower(ch); - if ('a' <= ch && ch <= 'f') { - return ch - 'a' + 0xa; - } - *src -= 1; // Char wasn't actually a hex digit. - return -1; -} - -static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char hex_digit = TryGetHexDigit(src, end); - if (hex_digit < 0) { - _upb_DefBuilder_Errf( - ctx, "\\x cannot be followed by non-hex digit in field '%s' default", - upb_FieldDef_FullName(f)); - return 0; - } - unsigned int ret = hex_digit; - while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { - ret = (ret << 4) | hex_digit; - } - if (ret > 0xff) { - _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", - upb_FieldDef_FullName(f)); - return 0; - } - return ret; -} - -static char TryGetOctalDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '7') { - return ch - '0'; - } - *src -= 1; // Char wasn't actually an octal digit. - return -1; -} - -static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char ch = 0; - for (int i = 0; i < 3; i++) { - char digit; - if ((digit = TryGetOctalDigit(src, end)) >= 0) { - ch = (ch << 3) | digit; - } - } - return ch; -} - -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) { - _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", - upb_FieldDef_FullName(f)); - return 0; - } - switch (ch) { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '\\': - return '\\'; - case '\'': - return '\''; - case '\"': - return '\"'; - case '?': - return '\?'; - case 'x': - case 'X': - return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - *src -= 1; - return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); - } - _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); -} - -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full) { - const char* str = name.data; - const size_t len = name.size; - bool start = true; - for (size_t i = 0; i < len; i++) { - const char c = str[i]; - if (c == '.') { - if (start || !full) { - _upb_DefBuilder_Errf( - ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = true; - } else if (start) { - if (!upb_isletter(c)) { - _upb_DefBuilder_Errf(ctx, - "invalid name: path components must start with a " - "letter (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = false; - } else if (!upb_isalphanum(c)) { - _upb_DefBuilder_Errf( - ctx, - "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT - ")", - UPB_STRINGVIEW_ARGS(name)); - } - } - if (start) { - _upb_DefBuilder_Errf(ctx, - "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - - // We should never reach this point. - UPB_ASSERT(false); -} - - -// Must be last. - -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTable_Extension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; - -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); -} - -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; - - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; - - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; - - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; -} - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, - upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); -} - -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; - } - return true; -} - -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { - upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; -} - -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); -} - -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { - return s->extreg; -} - -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; -} - -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; -} - -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); -} - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); -} - -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); -} - -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); -} - -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; - - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; - } - default: - break; - } - - return NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); -} - -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} - -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO(haberman): non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); - } - } - - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); - } - } - } - - return NULL; -} - -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } - - if (f == file) upb_strtable_removeiter(&s->syms, &iter); - } -} - -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - const upb_MiniTable_File* layout, upb_Status* status) { - const upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); - - if (name.size == 0) { - upb_Status_SetErrorFormat(status, - "missing name in google_protobuf_FileDescriptorProto"); - return NULL; - } - - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } - } - - upb_DefBuilder ctx = { - .symtab = s, - .layout = layout, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; - - if (UPB_SETJMP(ctx.err)) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (ctx.file) { - remove_filedef(s, ctx.file); - ctx.file = NULL; - } - } else if (!ctx.arena || !ctx.tmp_arena) { - _upb_DefBuilder_OomErr(&ctx); - } else { - _upb_FileDef_Create(&ctx, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(ctx.file), ctx.arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, ctx.arena); - } - - if (ctx.arena) upb_Arena_Free(ctx.arena); - if (ctx.tmp_arena) upb_Arena_Free(ctx.tmp_arena); - return ctx.file; -} - -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); -} - -/* Include here since we want most of this file to be stdio-free. */ -#include - -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - google_protobuf_FileDescriptorProto* file; - upb_Arena* arena; - upb_Status status; - - upb_Status_Clear(&status); - - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } - - arena = upb_Arena_New(); - - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } - - file = google_protobuf_FileDescriptorProto_parse_ex( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; - - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } - - const upb_MiniTable_File* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } - - upb_Arena_Free(arena); - return true; - -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; -} - -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; -} - -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTable_Extension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTable_Extension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; -} - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = malloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; - } - *count = n; - return exts; -} - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} - - -// Must be last. - -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; -} - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); -} - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; -} - - -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; - - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } - - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; - } - - return true; -} - -#include - - -// Must be last. - -struct upb_EnumDef { - const google_protobuf_EnumOptions* opts; - const upb_MiniTable_Enum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - int value_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -// TODO: Maybe implement this on top of a ZCOS instead? -void _upb_EnumDef_Debug(const upb_EnumDef* e) { - fprintf(stderr, "enum %s (%p) {\n", e->full_name, e); - fprintf(stderr, " value_count: %d\n", e->value_count); - fprintf(stderr, " default: %d\n", e->defaultval); - fprintf(stderr, " is_sorted: %d\n", e->is_sorted); - fprintf(stderr, "}\n"); -} - -const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; -} - -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; -} - -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); -} - -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} - -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; -} - -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } - -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name) { - return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size) { - upb_value v; - return upb_strtable_lookup2(&e->ntoi, name, size, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num) { - upb_value v; - return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) - : NULL; -} - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { - // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect - // this to be faster (especially for small numbers). - return upb_MiniTable_Enum_CheckValue(e->layout, num); -} - -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->value_count); - return _upb_EnumValueDef_At(e->values, i); -} - -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; - return upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2; -} - -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_EnumValueDef** sorted = NULL; - if (!e->is_sorted) { - sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - - // Duplicate values are allowed but we only encode each value once. - uint32_t previous = 0; - - for (size_t i = 0; i < e->value_count; i++) { - const uint32_t current = - upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); - if (i != 0 && previous == current) continue; - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); - previous = current; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); - - // There will always be room for this '\0' in the encoder buffer because - // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). - UPB_ASSERT(s.ptr < s.buf + s.bufsize); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static upb_MiniTable_Enum* create_enumlayout(upb_DefBuilder* ctx, - const upb_EnumDef* e) { - upb_StringView sv; - bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); - if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); - - upb_Status status; - upb_MiniTable_Enum* layout = - upb_MiniTable_BuildEnum(sv.data, sv.size, ctx->arena, &status); - if (!layout) - _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); - return layout; -} - -static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumDescriptorProto* enum_proto, - upb_EnumDef* e) { - const google_protobuf_EnumValueDescriptorProto* const* values; - upb_StringView name; - size_t n; - - // Must happen before _upb_DefBuilder_Add() - e->file = _upb_DefBuilder_File(ctx); - - name = google_protobuf_EnumDescriptorProto_name(enum_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - - e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, e->full_name, - _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - - values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n); - - bool ok = upb_strtable_init(&e->ntoi, n, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&e->iton, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - e->defaultval = 0; - e->value_count = n; - e->values = _upb_EnumValueDefs_New(ctx, prefix, n, values, e, &e->is_sorted); - - if (n == 0) { - _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", - e->full_name); - } - - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - - upb_inttable_compact(&e->iton, ctx->arena); - - if (upb_FileDef_Syntax(e->file) == kUpb_Syntax_Proto2) { - if (ctx->layout) { - UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); - e->layout = ctx->layout->enums[ctx->enum_count++]; - } else { - e->layout = create_enumlayout(ctx, e); - } - } else { - e->layout = NULL; - } -} - -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); - - // If a containing type is defined then get the full name from that. - // Otherwise use the package name from the file def. - const char* name = containing_type ? upb_MessageDef_FullName(containing_type) - : _upb_FileDef_RawPackage(ctx->file); - - upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); - for (size_t i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], &e[i]); - e[i].containing_type = containing_type; - } - return e; -} - - -// Must be last. - -struct upb_EnumValueDef { - const google_protobuf_EnumValueOptions* opts; - const upb_EnumDef* parent; - const char* full_name; - int32_t number; -}; - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { - return (upb_EnumValueDef*)&v[i]; -} - -static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; - const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; - return (v1 < v2) ? -1 : (v1 > v2); -} - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_EnumValueDef** out = - (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_EnumValueDef*)&v[i]; - } - qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); - - return (const upb_EnumValueDef**)out; -} - -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v) { - return v->opts; -} - -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { - return v->opts != (void*)kUpbDefOptDefault; -} - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { - return v->parent; -} - -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { - return v->full_name; -} - -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { - return _upb_DefBuilder_FullToShort(v->full_name); -} - -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { - // Compute index in our parent's array. - return v - upb_EnumDef_Value(v->parent, 0); -} - -static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_EnumValueDescriptorProto* val_proto, - upb_EnumDef* e, upb_EnumValueDef* v) { - upb_StringView name = google_protobuf_EnumValueDescriptorProto_name(val_proto); - - v->parent = e; // Must happen prior to _upb_DefBuilder_Add() - v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); - _upb_DefBuilder_Add(ctx, v->full_name, - _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - - upb_EnumValueDef* v = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - - *is_sorted = true; - uint32_t previous = 0; - for (size_t i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], e, &v[i]); - - const uint32_t current = v[i].number; - if (previous > current) *is_sorted = false; - previous = current; - } - - if (upb_FileDef_Syntax(ctx->file) == kUpb_Syntax_Proto3 && n > 0 && - v[0].number != 0) { - _upb_DefBuilder_Errf(ctx, - "for proto3, the first enum value must be zero (%s)", - upb_EnumDef_FullName(e)); - } - - return v; -} - - -// Must be last. - -struct upb_ExtensionRange { - const google_protobuf_ExtensionRangeOptions* opts; - int32_t start; - int32_t end; -}; - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { - return (upb_ExtensionRange*)&r[i]; -} - -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r) { - return r->opts; -} - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { - return r->opts != (void*)kUpbDefOptDefault; -} - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { - return r->start; -} - -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } - -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const upb_MessageDef* m) { - upb_ExtensionRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); - - for (int i = 0; i < n; i++) { - const int32_t start = - google_protobuf_DescriptorProto_ExtensionRange_start(protos[i]); - const int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(protos[i]); - const int32_t max = - google_protobuf_MessageOptions_message_set_wire_format(upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; - - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Extension range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } - - r[i].start = start; - r[i].end = end; - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); - } - - return r; -} - -#include -#include - - -// Must be last. - -#define UPB_FIELD_TYPE_UNSPECIFIED 0 - -typedef struct { - size_t len; - char str[1]; // Null-terminated string data follows. -} str_t; +static const char* opt_default = &opt_default_buf[sizeof(void*)]; struct upb_FieldDef { const google_protobuf_FieldOptions* opts; @@ -6838,10 +5418,10 @@ struct upb_FieldDef { } sub; uint32_t number_; uint16_t index_; - uint16_t layout_index; // Index into msgdef->layout->fields or file->exts + uint16_t layout_index; /* Index into msgdef->layout->fields or file->exts */ bool has_default; bool is_extension_; - bool is_packed_; + bool packed_; bool proto3_optional_; bool has_json_name_; upb_FieldType type_; @@ -6851,16 +5431,510 @@ struct upb_FieldDef { #endif }; -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { - return (upb_FieldDef*)&f[i]; +struct upb_ExtensionRange { + const google_protobuf_ExtensionRangeOptions* opts; + int32_t start; + int32_t end; +}; + +struct upb_MessageDef { + const google_protobuf_MessageOptions* opts; + const upb_MiniTable* layout; + const upb_FileDef* file; + const upb_MessageDef* containing_type; + const char* full_name; + + /* Tables for looking up fields by number and name. */ + upb_inttable itof; + upb_strtable ntof; + + /* All nested defs. + * MEM: We could save some space here by putting nested defs in a contiguous + * region and calculating counts from offsets or vice-versa. */ + const upb_FieldDef* fields; + const upb_OneofDef* oneofs; + const upb_ExtensionRange* ext_ranges; + const upb_StringView* res_names; + const upb_MessageDef* nested_msgs; + const upb_MessageReservedRange* res_ranges; + const upb_EnumDef* nested_enums; + const upb_FieldDef* nested_exts; + int field_count; + int real_oneof_count; + int oneof_count; + int ext_range_count; + int res_range_count; + int res_name_count; + int nested_msg_count; + int nested_enum_count; + int nested_ext_count; + bool in_message_set; + upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_EnumDef { + const google_protobuf_EnumOptions* opts; + const upb_MiniTable_Enum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_EnumValueDef { + const google_protobuf_EnumValueOptions* opts; + const upb_EnumDef* parent; + const char* full_name; + int32_t number; +}; + +struct upb_OneofDef { + const google_protobuf_OneofOptions* opts; + const upb_MessageDef* parent; + const char* full_name; + int field_count; + bool synthetic; + const upb_FieldDef** fields; + upb_strtable ntof; + upb_inttable itof; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +struct upb_FileDef { + const google_protobuf_FileOptions* opts; + const char* name; + const char* package; + + const upb_FileDef** deps; + const int32_t* public_deps; + const int32_t* weak_deps; + const upb_MessageDef* top_lvl_msgs; + const upb_EnumDef* top_lvl_enums; + const upb_FieldDef* top_lvl_exts; + const upb_ServiceDef* services; + const upb_MiniTable_Extension** ext_layouts; + const upb_DefPool* symtab; + + int dep_count; + int public_dep_count; + int weak_dep_count; + int top_lvl_msg_count; + int top_lvl_enum_count; + int top_lvl_ext_count; + int service_count; + int ext_count; /* All exts in the file. */ + upb_Syntax syntax; +}; + +struct upb_MethodDef { + const google_protobuf_MethodOptions* opts; + upb_ServiceDef* service; + const char* full_name; + const upb_MessageDef* input_type; + const upb_MessageDef* output_type; + int index; + bool client_streaming; + bool server_streaming; +}; + +struct upb_ServiceDef { + const google_protobuf_ServiceOptions* opts; + const upb_FileDef* file; + const char* full_name; + upb_MethodDef* methods; + int method_count; + int index; +}; + +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; /* full_name -> packed def ptr */ + upb_strtable files; /* file_name -> upb_FileDef* */ + upb_inttable exts; /* upb_MiniTable_Extension* -> upb_FieldDef* */ + upb_ExtensionRegistry* extreg; + size_t bytes_loaded; +}; + +/* Inside a symtab we store tagged pointers to specific def types. */ +typedef enum { + UPB_DEFTYPE_MASK = 7, + + /* Only inside symtab table. */ + UPB_DEFTYPE_EXT = 0, + UPB_DEFTYPE_MSG = 1, + UPB_DEFTYPE_ENUM = 2, + UPB_DEFTYPE_ENUMVAL = 3, + UPB_DEFTYPE_SERVICE = 4, + + /* Only inside message table. */ + UPB_DEFTYPE_FIELD = 0, + UPB_DEFTYPE_ONEOF = 1, + UPB_DEFTYPE_FIELD_JSONNAME = 2, + + /* Only inside file table. */ + UPB_DEFTYPE_FILE = 0, + UPB_DEFTYPE_LAYOUT = 1 +} upb_deftype_t; + +#define FIELD_TYPE_UNSPECIFIED 0 + +struct upb_MessageReservedRange { + int32_t start; + int32_t end; +}; + +struct symtab_addctx { + upb_DefPool* symtab; + upb_FileDef* file; /* File we are building. */ + upb_Arena* arena; /* Allocate defs here. */ + upb_Arena* tmp_arena; /* For temporary allocations. */ + const upb_MiniTable_File* layout; /* NULL if we should build layouts. */ + int enum_count; /* Count of enums built so far. */ + int msg_count; /* Count of messages built so far. */ + int ext_count; /* Count of extensions built so far. */ + upb_Status* status; /* Record errors here. */ + jmp_buf err; /* longjmp() on error. */ +}; + +static upb_deftype_t deftype(upb_value v) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; } -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f) { +static const void* unpack_def(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; +} + +static upb_value pack_def(const void* ptr, upb_deftype_t type) { + // Our 3-bit pointer tagging requires all pointers to be multiples of 8. + // The arena will always yield 8-byte-aligned addresses, however we put + // the defs into arrays. For each element in the array to be 8-byte-aligned, + // the sizes of each def type must also be a multiple of 8. + // + // If any of these asserts fail, we need to add or remove padding on 32-bit + // machines (64-bit machines will have 8-byte alignment already due to + // pointers, which all of these structs have). + UPB_ASSERT((sizeof(upb_FieldDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_MessageDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_EnumDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_EnumValueDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_ServiceDef) & UPB_DEFTYPE_MASK) == 0); + UPB_ASSERT((sizeof(upb_OneofDef) & UPB_DEFTYPE_MASK) == 0); + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); +} + +/* isalpha() etc. from are locale-dependent, which we don't want. */ +static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { + return c >= low && c <= high; +} + +static char upb_ascii_lower(char ch) { + // Per ASCII this will lower-case a letter. If the result is a letter, the + // input was definitely a letter. If the output is not a letter, this may + // have transformed the character unpredictably. + return ch | 0x20; +} + +static bool upb_isletter(char c) { + char lower = upb_ascii_lower(c); + return upb_isbetween(lower, 'a', 'z') || c == '_'; +} + +static bool upb_isalphanum(char c) { + return upb_isletter(c) || upb_isbetween(c, '0', '9'); +} + +static const char* shortdefname(const char* fullname) { + const char* p; + + if (fullname == NULL) { + return NULL; + } else if ((p = strrchr(fullname, '.')) == NULL) { + /* No '.' in the name, return the full string. */ + return fullname; + } else { + /* Return one past the last '.'. */ + return p + 1; + } +} + +/* All submessage fields are lower than all other fields. + * Secondly, fields are increasing in order. */ +uint32_t field_rank(const upb_FieldDef* f) { + uint32_t ret = upb_FieldDef_Number(f); + const uint32_t high_bit = 1 << 30; + UPB_ASSERT(ret < high_bit); + if (!upb_FieldDef_IsSubMessage(f)) ret |= high_bit; + return ret; +} + +int cmp_fields(const void* p1, const void* p2) { + const upb_FieldDef* f1 = *(upb_FieldDef* const*)p1; + const upb_FieldDef* f2 = *(upb_FieldDef* const*)p2; + return field_rank(f1) - field_rank(f2); +} + +static void upb_Status_setoom(upb_Status* status) { + upb_Status_SetErrorMessage(status, "out of memory"); +} + +static void assign_msg_wellknowntype(upb_MessageDef* m) { + const char* name = upb_MessageDef_FullName(m); + if (name == NULL) { + m->well_known_type = kUpb_WellKnown_Unspecified; + return; + } + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = kUpb_WellKnown_Any; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = kUpb_WellKnown_FieldMask; + } else if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = kUpb_WellKnown_Duration; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = kUpb_WellKnown_Timestamp; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = kUpb_WellKnown_DoubleValue; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = kUpb_WellKnown_FloatValue; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = kUpb_WellKnown_Int64Value; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = kUpb_WellKnown_UInt64Value; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = kUpb_WellKnown_Int32Value; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = kUpb_WellKnown_UInt32Value; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = kUpb_WellKnown_BoolValue; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = kUpb_WellKnown_StringValue; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = kUpb_WellKnown_BytesValue; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = kUpb_WellKnown_Value; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = kUpb_WellKnown_ListValue; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = kUpb_WellKnown_Struct; + } else { + m->well_known_type = kUpb_WellKnown_Unspecified; + } +} + +/* upb_EnumDef ****************************************************************/ + +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; +} + +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)opt_default; +} + +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } + +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return shortdefname(e->full_name); +} + +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } + +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; +} + +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; +} + +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; +} + +/* upb_EnumReservedRange ******************************************************/ + +struct upb_EnumReservedRange { + int32_t start; + int32_t end; +}; + +upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, + int i) { + return (upb_EnumReservedRange*)&r[i]; +} + +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { + return r->start; +} +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { + return r->end; +} + +UPB_NORETURN UPB_NOINLINE UPB_PRINTF(2, 3) static void symtab_errf( + symtab_addctx* ctx, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(ctx->status, fmt, argp); + va_end(argp); + UPB_LONGJMP(ctx->err, 1); +} + +upb_EnumReservedRange* _upb_EnumReservedRanges_New( + symtab_addctx* ctx, int n, + const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* protos, + const upb_EnumDef* e) { + upb_EnumReservedRange* r = + upb_Arena_Malloc(ctx->arena, sizeof(upb_EnumReservedRange) * n); + + for (int i = 0; i < n; i++) { + const int32_t start = + google_protobuf_EnumDescriptorProto_EnumReservedRange_start(protos[i]); + const int32_t end = + google_protobuf_EnumDescriptorProto_EnumReservedRange_end(protos[i]); + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + + // Note: Not a typo! Unlike extension ranges and message reserved ranges, + // the end value of an enum reserved range is *inclusive*! + if (end < start) { + symtab_errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", + (int)start, (int)end, upb_EnumDef_FullName(e)); + } + + r[i].start = start; + r[i].end = end; + } + + return r; +} + +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); +} + +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; +} + +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; +} + +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } + +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* def, const char* name, size_t len) { + upb_value v; + return upb_strtable_lookup2(&def->ntoi, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} + +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* def, + int32_t num) { + upb_value v; + return upb_inttable_lookup(&def->iton, num, &v) ? upb_value_getconstptr(v) + : NULL; +} + +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { + // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect + // this to be faster (especially for small numbers). + return upb_MiniTable_Enum_CheckValue(e->layout, num); +} + +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->value_count); + return &e->values[i]; +} + +/* upb_EnumValueDef ***********************************************************/ + +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e) { + return e->opts; +} + +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e) { + return e->opts != (void*)opt_default; +} + +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* ev) { + return ev->parent; +} + +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* ev) { + return ev->full_name; +} + +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* ev) { + return shortdefname(ev->full_name); +} + +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* ev) { + return ev->number; +} + +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* ev) { + // Compute index in our parent's array. + return ev - ev->parent->values; +} + +/* upb_ExtensionRange + * ***************************************************************/ + +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r) { + return r->opts; +} + +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { + return r->opts != (void*)opt_default; +} + +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* e) { + return e->start; +} + +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* e) { return e->end; } + +/* upb_FieldDef ***************************************************************/ + +const google_protobuf_FieldOptions* upb_FieldDef_Options( + const upb_FieldDef* f) { return f->opts; } bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { - return f->opts != (void*)kUpbDefOptDefault; + return f->opts != (void*)opt_default; } const char* upb_FieldDef_FullName(const upb_FieldDef* f) { @@ -6914,10 +5988,10 @@ bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension_; } -bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->is_packed_; } +bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { return f->packed_; } const char* upb_FieldDef_Name(const upb_FieldDef* f) { - return _upb_DefBuilder_FullToShort(f->full_name); + return shortdefname(f->full_name); } const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { @@ -6996,88 +6070,21 @@ const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f) { UPB_ASSERT(!upb_FieldDef_IsExtension(f)); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); - return &layout->fields[f->layout_index]; + return &f->msgdef->layout->fields[f->layout_index]; } const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( const upb_FieldDef* f) { UPB_ASSERT(upb_FieldDef_IsExtension(f)); - const upb_FileDef* file = upb_FieldDef_File(f); - return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); -} - -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; - if (f->type_ != kUpb_FieldType_Enum) return false; - - // TODO: Maybe make is_proto2 a bool at creation? - const upb_FileDef* file = upb_EnumDef_File(f->sub.enumdef); - return upb_FileDef_Syntax(file) == kUpb_Syntax_Proto2; + return f->file->ext_layouts[f->layout_index]; } bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { return f->proto3_optional_; } -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } - -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { - uint64_t out = f->is_packed_ ? kUpb_FieldModifier_IsPacked : 0; - - switch (f->label_) { - case kUpb_Label_Optional: - if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } - break; - case kUpb_Label_Repeated: - out |= kUpb_FieldModifier_IsRepeated; - break; - case kUpb_Label_Required: - out |= kUpb_FieldModifier_IsRequired; - break; - } - - if (_upb_FieldDef_IsClosedEnum(f)) { - out |= kUpb_FieldModifier_IsClosedEnum; - } - return out; -} - -bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } - -bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { - if (upb_FieldDef_IsRepeated(f)) return false; - const upb_FileDef* file = upb_FieldDef_File(f); - return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_ContainingOneof(f) || - upb_FileDef_Syntax(file) == kUpb_Syntax_Proto2; -} - -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) || - upb_FieldDef_CType(f) == kUpb_CType_Enum; -} - -bool upb_FieldDef_IsMap(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && - upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); -} - -bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Optional; -} - -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { - return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); -} - -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Repeated; -} - -bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Required; +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message; } bool upb_FieldDef_IsString(const upb_FieldDef* f) { @@ -7085,8 +6092,30 @@ bool upb_FieldDef_IsString(const upb_FieldDef* f) { upb_FieldDef_CType(f) == kUpb_CType_Bytes; } -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message; +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Repeated; +} + +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { + return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +} + +bool upb_FieldDef_IsMap(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && + upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); +} + +bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } + +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { + return upb_FieldDef_IsSubMessage(f) || + upb_FieldDef_CType(f) == kUpb_CType_Enum; +} + +bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { + if (upb_FieldDef_IsRepeated(f)) return false; + return upb_FieldDef_IsSubMessage(f) || upb_FieldDef_ContainingOneof(f) || + f->file->syntax == kUpb_Syntax_Proto2; } static bool between(int32_t x, int32_t low, int32_t high) { @@ -7101,44 +6130,1390 @@ bool upb_FieldDef_checkdescriptortype(int32_t type) { return between(type, 1, 18); } +/* upb_MessageDef + * *****************************************************************/ + +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m) { + return m->opts; +} + +bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { + return m->opts != (void*)opt_default; +} + +const char* upb_MessageDef_FullName(const upb_MessageDef* m) { + return m->full_name; +} + +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { + return m->file; +} + +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { + return m->containing_type; +} + +const char* upb_MessageDef_Name(const upb_MessageDef* m) { + return shortdefname(m->full_name); +} + +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { + return m->file->syntax; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i) { + upb_value val; + return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) + : NULL; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + return unpack_def(val, UPB_DEFTYPE_FIELD); +} + +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + return unpack_def(val, UPB_DEFTYPE_ONEOF); +} + +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** out_f, + const upb_OneofDef** out_o) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return false; + } + + const upb_FieldDef* f = unpack_def(val, UPB_DEFTYPE_FIELD); + const upb_OneofDef* o = unpack_def(val, UPB_DEFTYPE_ONEOF); + if (out_f) *out_f = f; + if (out_o) *out_o = o; + return f || o; /* False if this was a JSON name. */ +} + +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len) { + upb_value val; + const upb_FieldDef* f; + + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return NULL; + } + + f = unpack_def(val, UPB_DEFTYPE_FIELD); + if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME); + + return f; +} + +int upb_MessageDef_numfields(const upb_MessageDef* m) { return m->field_count; } + +int upb_MessageDef_numoneofs(const upb_MessageDef* m) { return m->oneof_count; } + +int upb_MessageDef_numrealoneofs(const upb_MessageDef* m) { + return m->real_oneof_count; +} + +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { + return m->ext_range_count; +} + +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { + return m->res_range_count; +} + +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { + return m->res_name_count; +} + +int upb_MessageDef_FieldCount(const upb_MessageDef* m) { + return m->field_count; +} + +int upb_MessageDef_OneofCount(const upb_MessageDef* m) { + return m->oneof_count; +} + +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { + return m->nested_msg_count; +} + +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { + return m->nested_enum_count; +} + +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { + return m->nested_ext_count; +} + +int upb_MessageDef_realoneofcount(const upb_MessageDef* m) { + return m->real_oneof_count; +} + +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { + return m->layout; +} + +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->ext_range_count); + return &m->ext_ranges[i]; +} + +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i) { + return (upb_MessageReservedRange*)&r[i]; +} + +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_range_count); + return _upb_MessageReservedRange_At(m->res_ranges, i); +} + +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_name_count); + return m->res_names[i]; +} + +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { + return r->start; +} +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { + return r->end; +} + +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + symtab_addctx* ctx, int n, + const google_protobuf_DescriptorProto_ReservedRange* const* protos, + const upb_MessageDef* m) { + upb_MessageReservedRange* r = + upb_Arena_Malloc(ctx->arena, sizeof(upb_MessageReservedRange) * n); + + for (int i = 0; i < n; i++) { + const int32_t start = google_protobuf_DescriptorProto_ReservedRange_start(protos[i]); + const int32_t end = google_protobuf_DescriptorProto_ReservedRange_end(protos[i]); + const int32_t max = kUpb_MaxFieldNumber + 1; + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + symtab_errf(ctx, + "Reserved range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, upb_MessageDef_FullName(m)); + } + + r[i].start = start; + r[i].end = end; + } + + return r; +} + +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->field_count); + return &m->fields[i]; +} + +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->oneof_count); + return &m->oneofs[i]; +} + +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_msg_count); + return &m->nested_msgs[i]; +} + +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->nested_enum_count); + return &m->nested_enums[i]; +} + +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_ext_count); + return &m->nested_exts[i]; +} + +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { + return m->well_known_type; +} + +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options( + const upb_OneofDef* o) { + return o->opts; +} + +bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { + return o->opts != (void*)opt_default; +} + +const char* upb_OneofDef_Name(const upb_OneofDef* o) { + return shortdefname(o->full_name); +} + +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { + return o->parent; +} + +int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } + +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { + UPB_ASSERT(i < o->field_count); + return o->fields[i]; +} + +int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } + +uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { + // Compute index in our parent's array. + return o - o->parent->oneofs; +} + +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } + +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length) { + upb_value val; + return upb_strtable_lookup2(&o->ntof, name, length, &val) + ? upb_value_getptr(val) + : NULL; +} + +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num) { + upb_value val; + return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) + : NULL; +} + +/* upb_FileDef ****************************************************************/ + +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { + return f->opts; +} + +bool upb_FileDef_HasOptions(const upb_FileDef* f) { + return f->opts != (void*)opt_default; +} + +const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } + +const char* upb_FileDef_Package(const upb_FileDef* f) { + return f->package ? f->package : ""; +} + +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } + +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { + return f->top_lvl_msg_count; +} + +int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } + +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { + return f->public_dep_count; +} + +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { + return f->weak_dep_count; +} + +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { + return f->public_deps; +} + +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { + return f->weak_deps; +} + +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { + return f->top_lvl_enum_count; +} + +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { + return f->top_lvl_ext_count; +} + +int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } + +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->dep_count); + return f->deps[i]; +} + +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->public_deps[i]]; +} + +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->weak_deps[i]]; +} + +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); + return &f->top_lvl_msgs[i]; +} + +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); + return &f->top_lvl_enums[i]; +} + +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); + return &f->top_lvl_exts[i]; +} + +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->service_count); + return &f->services[i]; +} + +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } + +/* upb_MethodDef **************************************************************/ + +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m) { + return m->opts; +} + +bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { + return m->opts != (void*)opt_default; +} + +const char* upb_MethodDef_FullName(const upb_MethodDef* m) { + return m->full_name; +} + +int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } + +const char* upb_MethodDef_Name(const upb_MethodDef* m) { + return shortdefname(m->full_name); +} + +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { + return m->service; +} + +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { + return m->input_type; +} + +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { + return m->output_type; +} + +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { + return m->client_streaming; +} + +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { + return m->server_streaming; +} + +/* upb_ServiceDef *************************************************************/ + +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s) { + return s->opts; +} + +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { + return s->opts != (void*)opt_default; +} + +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { + return s->full_name; +} + +const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { + return shortdefname(s->full_name); +} + +int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } + +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { + return s->file; +} + +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { + return s->method_count; +} + +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { + return i < 0 || i >= s->method_count ? NULL : &s->methods[i]; +} + +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name) { + for (int i = 0; i < s->method_count; i++) { + if (strcmp(name, upb_MethodDef_Name(&s->methods[i])) == 0) { + return &s->methods[i]; + } + } + return NULL; +} + +/* upb_DefPool ****************************************************************/ + +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s); +} + +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + + if (!s) { + return NULL; + } + + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; + + if (!upb_strtable_init(&s->syms, 32, s->arena) || + !upb_strtable_init(&s->files, 4, s->arena) || + !upb_inttable_init(&s->exts, s->arena)) { + goto err; + } + + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; + return s; + +err: + upb_Arena_Free(s->arena); + upb_gfree(s); + return NULL; +} + +static const void* symtab_lookup(const upb_DefPool* s, const char* sym, + upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup(&s->syms, sym, &v) ? unpack_def(v, type) : NULL; +} + +static const void* symtab_lookup2(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup2(&s->syms, sym, size, &v) ? unpack_def(v, type) + : NULL; +} + +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_MSG); +} + +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return symtab_lookup2(s, sym, len, UPB_DEFTYPE_MSG); +} + +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUM); +} + +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return symtab_lookup(s, sym, UPB_DEFTYPE_ENUMVAL); +} + +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; +} + +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? unpack_def(v, UPB_DEFTYPE_FILE) + : NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + + switch (deftype(v)) { + case UPB_DEFTYPE_FIELD: + return unpack_def(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return m->in_message_set ? &m->nested_exts[0] : NULL; + } + default: + break; + } + + return NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} + +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return symtab_lookup(s, name, UPB_DEFTYPE_SERVICE); +} + +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return symtab_lookup2(s, name, size, UPB_DEFTYPE_SERVICE); +} + +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO(haberman): non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (deftype(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = unpack_def(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); + } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = unpack_def(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); + } + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = unpack_def(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = unpack_def(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); + } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = unpack_def(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); + } + default: + UPB_UNREACHABLE(); + } + } + + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } + + return NULL; +} + +/* Code to build defs from descriptor protos. *********************************/ + +/* There is a question of how much validation to do here. It will be difficult + * to perfectly match the amount of validation performed by proto2. But since + * this code is used to directly build defs from Ruby (for example) we do need + * to validate important constraints like uniqueness of names and numbers. */ + +#define CHK_OOM(x) \ + if (!(x)) { \ + symtab_oomerr(ctx); \ + } + +UPB_NORETURN UPB_NOINLINE static void symtab_oomerr(symtab_addctx* ctx) { + upb_Status_setoom(ctx->status); + UPB_LONGJMP(ctx->err, 1); +} + +void* symtab_alloc(symtab_addctx* ctx, size_t bytes) { + if (bytes == 0) return NULL; + void* ret = upb_Arena_Malloc(ctx->arena, bytes); + if (!ret) symtab_oomerr(ctx); + return ret; +} + +// We want to copy the options verbatim into the destination options proto. +// We use serialize+parse as our deep copy. +#define SET_OPTIONS(target, desc_type, options_type, proto) \ + if (google_protobuf_##desc_type##_has_options(proto)) { \ + size_t size; \ + char* pb = google_protobuf_##options_type##_serialize( \ + google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ + CHK_OOM(pb); \ + target = google_protobuf_##options_type##_parse(pb, size, ctx->arena); \ + CHK_OOM(target); \ + } else { \ + target = (const google_protobuf_##options_type*)opt_default; \ + } + +static void check_ident(symtab_addctx* ctx, upb_StringView name, bool full) { + const char* str = name.data; + size_t len = name.size; + bool start = true; + size_t i; + for (i = 0; i < len; i++) { + char c = str[i]; + if (c == '.') { + if (start || !full) { + symtab_errf(ctx, "invalid name: unexpected '.' (%.*s)", (int)len, str); + } + start = true; + } else if (start) { + if (!upb_isletter(c)) { + symtab_errf( + ctx, + "invalid name: path components must start with a letter (%.*s)", + (int)len, str); + } + start = false; + } else { + if (!upb_isalphanum(c)) { + symtab_errf(ctx, "invalid name: non-alphanumeric character (%.*s)", + (int)len, str); + } + } + } + if (start) { + symtab_errf(ctx, "invalid name: empty part (%.*s)", (int)len, str); + } +} + +static size_t div_round_up(size_t n, size_t d) { return (n + d - 1) / d; } + +static size_t upb_MessageValue_sizeof(upb_CType type) { + switch (type) { + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return 8; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Float: + return 4; + case kUpb_CType_Bool: + return 1; + case kUpb_CType_Message: + return sizeof(void*); + case kUpb_CType_Bytes: + case kUpb_CType_String: + return sizeof(upb_StringView); + } + UPB_UNREACHABLE(); +} + +static uint8_t upb_msg_fielddefsize(const upb_FieldDef* f) { + if (upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f))) { + upb_MapEntry ent; + UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v)); + return sizeof(ent.k); + } else if (upb_FieldDef_IsRepeated(f)) { + return sizeof(void*); + } else { + return upb_MessageValue_sizeof(upb_FieldDef_CType(f)); + } +} + +static uint32_t upb_MiniTable_place(symtab_addctx* ctx, upb_MiniTable* l, + size_t size, const upb_MessageDef* m) { + size_t ofs = UPB_ALIGN_UP(l->size, size); + size_t next = ofs + size; + + if (next > UINT16_MAX) { + symtab_errf(ctx, "size of message %s exceeded max size of %zu bytes", + upb_MessageDef_FullName(m), (size_t)UINT16_MAX); + } + + l->size = next; + return ofs; +} + +static int field_number_cmp(const void* p1, const void* p2) { + const upb_MiniTable_Field* f1 = p1; + const upb_MiniTable_Field* f2 = p2; + return f1->number - f2->number; +} + +static void assign_layout_indices(const upb_MessageDef* m, upb_MiniTable* l, + upb_MiniTable_Field* fields) { + int i; + int n = upb_MessageDef_numfields(m); + int dense_below = 0; + for (i = 0; i < n; i++) { + upb_FieldDef* f = + (upb_FieldDef*)upb_MessageDef_FindFieldByNumber(m, fields[i].number); + UPB_ASSERT(f); + f->layout_index = i; + if (i < UINT8_MAX && fields[i].number == i + 1 && + (i == 0 || fields[i - 1].number == i)) { + dense_below = i + 1; + } + } + l->dense_below = dense_below; +} + +static uint8_t map_descriptortype(const upb_FieldDef* f) { + uint8_t type = upb_FieldDef_Type(f); + /* See TableDescriptorType() in upbc/generator.cc for details and + * rationale of these exceptions. */ + if (type == kUpb_FieldType_String && f->file->syntax == kUpb_Syntax_Proto2) { + return kUpb_FieldType_Bytes; + } else if (type == kUpb_FieldType_Enum && + (f->sub.enumdef->file->syntax == kUpb_Syntax_Proto3 || + UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 || + // TODO(https://github.com/protocolbuffers/upb/issues/541): + // fix map enum values to check for unknown enum values and put + // them in the unknown field set. + upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)))) { + return kUpb_FieldType_Int32; + } + return type; +} + +static void fill_fieldlayout(upb_MiniTable_Field* field, + const upb_FieldDef* f) { + field->number = upb_FieldDef_Number(f); + field->descriptortype = map_descriptortype(f); + + if (upb_FieldDef_IsMap(f)) { + field->mode = + kUpb_FieldMode_Map | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift); + } else if (upb_FieldDef_IsRepeated(f)) { + field->mode = + kUpb_FieldMode_Array | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift); + } else { + /* Maps descriptor type -> elem_size_lg2. */ + static const uint8_t sizes[] = { + -1, /* invalid descriptor type */ + kUpb_FieldRep_8Byte, /* DOUBLE */ + kUpb_FieldRep_4Byte, /* FLOAT */ + kUpb_FieldRep_8Byte, /* INT64 */ + kUpb_FieldRep_8Byte, /* UINT64 */ + kUpb_FieldRep_4Byte, /* INT32 */ + kUpb_FieldRep_8Byte, /* FIXED64 */ + kUpb_FieldRep_4Byte, /* FIXED32 */ + kUpb_FieldRep_1Byte, /* BOOL */ + kUpb_FieldRep_StringView, /* STRING */ + kUpb_FieldRep_Pointer, /* GROUP */ + kUpb_FieldRep_Pointer, /* MESSAGE */ + kUpb_FieldRep_StringView, /* BYTES */ + kUpb_FieldRep_4Byte, /* UINT32 */ + kUpb_FieldRep_4Byte, /* ENUM */ + kUpb_FieldRep_4Byte, /* SFIXED32 */ + kUpb_FieldRep_8Byte, /* SFIXED64 */ + kUpb_FieldRep_4Byte, /* SINT32 */ + kUpb_FieldRep_8Byte, /* SINT64 */ + }; + field->mode = kUpb_FieldMode_Scalar | + (sizes[field->descriptortype] << kUpb_FieldRep_Shift); + } + + if (upb_FieldDef_IsPacked(f)) { + field->mode |= kUpb_LabelFlags_IsPacked; + } + + if (upb_FieldDef_IsExtension(f)) { + field->mode |= kUpb_LabelFlags_IsExtension; + } +} + +/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc. + * It computes a dynamic layout for all of the fields in |m|. */ +static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) { + upb_MiniTable* l = (upb_MiniTable*)m->layout; + size_t field_count = upb_MessageDef_numfields(m); + size_t sublayout_count = 0; + upb_MiniTable_Sub* subs; + upb_MiniTable_Field* fields; + + memset(l, 0, sizeof(*l) + sizeof(_upb_FastTable_Entry)); + + /* Count sub-messages. */ + for (size_t i = 0; i < field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + if (upb_FieldDef_IsSubMessage(f)) { + sublayout_count++; + } + if (upb_FieldDef_CType(f) == kUpb_CType_Enum && + f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) { + sublayout_count++; + } + } + + fields = symtab_alloc(ctx, field_count * sizeof(*fields)); + subs = symtab_alloc(ctx, sublayout_count * sizeof(*subs)); + + l->field_count = upb_MessageDef_numfields(m); + l->fields = fields; + l->subs = subs; + l->table_mask = 0; + l->required_count = 0; + + if (upb_MessageDef_ExtensionRangeCount(m) > 0) { + if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { + l->ext = kUpb_ExtMode_IsMessageSet; + } else { + l->ext = kUpb_ExtMode_Extendable; + } + } else { + l->ext = kUpb_ExtMode_NonExtendable; + } + + /* TODO(haberman): initialize fast tables so that reflection-based parsing + * can get the same speeds as linked-in types. */ + l->fasttable[0].field_parser = &fastdecode_generic; + l->fasttable[0].field_data = 0; + + if (upb_MessageDef_IsMapEntry(m)) { + /* TODO(haberman): refactor this method so this special case is more + * elegant. */ + const upb_FieldDef* key = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* val = upb_MessageDef_FindFieldByNumber(m, 2); + if (key == NULL || val == NULL) { + symtab_errf(ctx, "Malformed map entry from message: %s", + upb_MessageDef_FullName(m)); + } + fields[0].number = 1; + fields[1].number = 2; + fields[0].mode = kUpb_FieldMode_Scalar; + fields[1].mode = kUpb_FieldMode_Scalar; + fields[0].presence = 0; + fields[1].presence = 0; + fields[0].descriptortype = map_descriptortype(key); + fields[1].descriptortype = map_descriptortype(val); + fields[0].offset = 0; + fields[1].offset = sizeof(upb_StringView); + fields[1].submsg_index = 0; + + if (upb_FieldDef_CType(val) == kUpb_CType_Message) { + subs[0].submsg = upb_FieldDef_MessageSubDef(val)->layout; + } + + upb_FieldDef* fielddefs = (upb_FieldDef*)&m->fields[0]; + UPB_ASSERT(fielddefs[0].number_ == 1); + UPB_ASSERT(fielddefs[1].number_ == 2); + fielddefs[0].layout_index = 0; + fielddefs[1].layout_index = 1; + + l->field_count = 2; + l->size = 2 * sizeof(upb_StringView); + l->size = UPB_ALIGN_UP(l->size, 8); + l->dense_below = 2; + return; + } + + /* Allocate data offsets in three stages: + * + * 1. hasbits. + * 2. regular fields. + * 3. oneof fields. + * + * OPT: There is a lot of room for optimization here to minimize the size. + */ + + /* Assign hasbits for required fields first. */ + size_t hasbit = 0; + + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + field->presence = ++hasbit; + if (hasbit >= 63) { + symtab_errf(ctx, "Message with >=63 required fields: %s", + upb_MessageDef_FullName(m)); + } + l->required_count++; + } + } + + /* Allocate hasbits and set basic field attributes. */ + sublayout_count = 0; + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_MiniTable_Field* field = &fields[upb_FieldDef_Index(f)]; + + fill_fieldlayout(field, f); + + if (field->descriptortype == kUpb_FieldType_Message || + field->descriptortype == kUpb_FieldType_Group) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout; + } else if (field->descriptortype == kUpb_FieldType_Enum) { + field->submsg_index = sublayout_count++; + subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout; + UPB_ASSERT(subs[field->submsg_index].subenum); + } + + if (upb_FieldDef_Label(f) == kUpb_Label_Required) { + /* Hasbit was already assigned. */ + } else if (upb_FieldDef_HasPresence(f) && + !upb_FieldDef_RealContainingOneof(f)) { + /* We don't use hasbit 0, so that 0 can indicate "no presence" in the + * table. This wastes one hasbit, but we don't worry about it for now. */ + field->presence = ++hasbit; + } else { + field->presence = 0; + } + } + + /* Account for space used by hasbits. */ + l->size = hasbit ? div_round_up(hasbit + 1, 8) : 0; + + /* Allocate non-oneof fields. */ + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + size_t field_size = upb_msg_fielddefsize(f); + size_t index = upb_FieldDef_Index(f); + + if (upb_FieldDef_RealContainingOneof(f)) { + /* Oneofs are handled separately below. */ + continue; + } + + fields[index].offset = upb_MiniTable_place(ctx, l, field_size, m); + } + + /* Allocate oneof fields. Each oneof field consists of a uint32 for the case + * and space for the actual data. */ + for (int i = 0; i < m->oneof_count; i++) { + const upb_OneofDef* o = &m->oneofs[i]; + size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */ + size_t field_size = 0; + uint32_t case_offset; + uint32_t data_offset; + + if (upb_OneofDef_IsSynthetic(o)) continue; + + if (o->field_count == 0) { + symtab_errf(ctx, "Oneof must have at least one field (%s)", o->full_name); + } + + /* Calculate field size: the max of all field sizes. */ + for (int j = 0; j < o->field_count; j++) { + const upb_FieldDef* f = o->fields[j]; + field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f)); + } + + /* Align and allocate case offset. */ + case_offset = upb_MiniTable_place(ctx, l, case_size, m); + data_offset = upb_MiniTable_place(ctx, l, field_size, m); + + for (int i = 0; i < o->field_count; i++) { + const upb_FieldDef* f = o->fields[i]; + fields[upb_FieldDef_Index(f)].offset = data_offset; + fields[upb_FieldDef_Index(f)].presence = ~case_offset; + } + } + + /* Size of the entire structure should be a multiple of its greatest + * alignment. TODO: track overall alignment for real? */ + l->size = UPB_ALIGN_UP(l->size, 8); + + /* Sort fields by number. */ + if (fields) { + qsort(fields, upb_MessageDef_numfields(m), sizeof(*fields), + field_number_cmp); + } + assign_layout_indices(m, l, fields); +} + +static char* strviewdup(symtab_addctx* ctx, upb_StringView view) { + char* ret = upb_strdup2(view.data, view.size, ctx->arena); + CHK_OOM(ret); + return ret; +} + static bool streql2(const char* a, size_t n, const char* b) { return n == strlen(b) && memcmp(a, b, n) == 0; } -// Implement the transformation as described in the spec: -// 1. upper case all letters after an underscore. -// 2. remove all underscores. -static char* make_json_name(const char* name, size_t size, upb_Arena* a) { - char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' - if (out == NULL) return NULL; - - bool ucase_next = false; - char* des = out; - for (size_t i = 0; i < size; i++) { - if (name[i] == '_') { - ucase_next = true; - } else { - *des++ = ucase_next ? toupper(name[i]) : name[i]; - ucase_next = false; - } - } - *des++ = '\0'; - return out; +static bool streql_view(upb_StringView view, const char* b) { + return streql2(view.data, view.size, b); } -static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - if (!ret) _upb_DefBuilder_OomErr(ctx); +static const char* makefullname(symtab_addctx* ctx, const char* prefix, + upb_StringView name) { + if (prefix) { + /* ret = prefix + '.' + name; */ + size_t n = strlen(prefix); + char* ret = symtab_alloc(ctx, n + name.size + 2); + strcpy(ret, prefix); + ret[n] = '.'; + memcpy(&ret[n + 1], name.data, name.size); + ret[n + 1 + name.size] = '\0'; + return ret; + } else { + return strviewdup(ctx, name); + } +} + +static void finalize_oneofs(symtab_addctx* ctx, upb_MessageDef* m) { + int i; + int synthetic_count = 0; + upb_OneofDef* mutable_oneofs = (upb_OneofDef*)m->oneofs; + + for (i = 0; i < m->oneof_count; i++) { + upb_OneofDef* o = &mutable_oneofs[i]; + + if (o->synthetic && o->field_count != 1) { + symtab_errf(ctx, "Synthetic oneofs must have one field, not %d: %s", + o->field_count, upb_OneofDef_Name(o)); + } + + if (o->synthetic) { + synthetic_count++; + } else if (synthetic_count != 0) { + symtab_errf(ctx, "Synthetic oneofs must be after all other oneofs: %s", + upb_OneofDef_Name(o)); + } + + o->fields = symtab_alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); + o->field_count = 0; + } + + for (i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = &m->fields[i]; + upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); + if (o) { + o->fields[o->field_count++] = f; + } + } + + m->real_oneof_count = m->oneof_count - synthetic_count; +} + +size_t getjsonname(const char* name, char* buf, size_t len) { + size_t src, dst = 0; + bool ucase_next = false; + +#define WRITE(byte) \ + ++dst; \ + if (dst < len) \ + buf[dst - 1] = byte; \ + else if (dst == len) \ + buf[dst - 1] = '\0' + + if (!name) { + WRITE('\0'); + return 0; + } + + /* Implement the transformation as described in the spec: + * 1. upper case all letters after an underscore. + * 2. remove all underscores. + */ + for (src = 0; name[src]; src++) { + if (name[src] == '_') { + ucase_next = true; + continue; + } + + if (ucase_next) { + WRITE(toupper(name[src])); + ucase_next = false; + } else { + WRITE(name[src]); + } + } + + WRITE('\0'); + return dst; + +#undef WRITE +} + +static char* makejsonname(symtab_addctx* ctx, const char* name) { + size_t size = getjsonname(name, NULL, 0); + char* json_name = symtab_alloc(ctx, size); + getjsonname(name, json_name, size); + return json_name; +} + +/* Adds a symbol |v| to the symtab, which must be a def pointer previously + * packed with pack_def(). The def's pointer to upb_FileDef* must be set before + * adding, so we know which entries to remove if building this file fails. */ +static void symtab_add(symtab_addctx* ctx, const char* name, upb_value v) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup(&ctx->symtab->syms, name, NULL)) { + symtab_errf(ctx, "duplicate symbol '%s'", name); + } + size_t len = strlen(name); + CHK_OOM(upb_strtable_insert(&ctx->symtab->syms, name, len, v, + ctx->symtab->arena)); +} + +static bool remove_component(char* base, size_t* len) { + if (*len == 0) return false; + + for (size_t i = *len - 1; i > 0; i--) { + if (base[i] == '.') { + *len = i; + return true; + } + } + + *len = 0; + return true; +} + +/* Given a symbol and the base symbol inside which it is defined, find the + * symbol's definition in t. */ +static const void* symtab_resolveany(symtab_addctx* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + const upb_strtable* t = &ctx->symtab->syms; + if (sym.size == 0) goto notfound; + upb_value v; + if (sym.data[0] == '.') { + /* Symbols starting with '.' are absolute, so we do a single lookup. + * Slice to omit the leading '.' */ + if (!upb_strtable_lookup2(t, sym.data + 1, sym.size - 1, &v)) { + goto notfound; + } + } else { + /* Remove components from base until we find an entry or run out. */ + size_t baselen = base ? strlen(base) : 0; + char* tmp = malloc(sym.size + baselen + 1); + while (1) { + char* p = tmp; + if (baselen) { + memcpy(p, base, baselen); + p[baselen] = '.'; + p += baselen + 1; + } + memcpy(p, sym.data, sym.size); + p += sym.size; + if (upb_strtable_lookup2(t, tmp, p - tmp, &v)) { + break; + } + if (!remove_component(tmp, &baselen)) { + free(tmp); + goto notfound; + } + } + free(tmp); + } + + *type = deftype(v); + return unpack_def(v, *type); + +notfound: + symtab_errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(sym)); +} + +static const void* symtab_resolve(symtab_addctx* ctx, const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t type) { + upb_deftype_t found_type; + const void* ret = + symtab_resolveany(ctx, from_name_dbg, base, sym, &found_type); + if (ret && found_type != type) { + symtab_errf(ctx, + "type mismatch when resolving %s: couldn't find " + "name " UPB_STRINGVIEW_FORMAT " with type=%d", + from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); + } + return ret; +} + +static void create_oneofdef( + symtab_addctx* ctx, upb_MessageDef* m, + const google_protobuf_OneofDescriptorProto* oneof_proto, + const upb_OneofDef* _o) { + upb_OneofDef* o = (upb_OneofDef*)_o; + upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); + upb_value v; + + o->parent = m; + o->full_name = makefullname(ctx, m->full_name, name); + o->field_count = 0; + o->synthetic = false; + + SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + + upb_value existing_v; + if (upb_strtable_lookup2(&m->ntof, name.data, name.size, &existing_v)) { + symtab_errf(ctx, "duplicate oneof name (%s)", o->full_name); + } + + v = pack_def(o, UPB_DEFTYPE_ONEOF); + CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, v, ctx->arena)); + + CHK_OOM(upb_inttable_init(&o->itof, ctx->arena)); + CHK_OOM(upb_strtable_init(&o->ntof, 4, ctx->arena)); +} + +static str_t* newstr(symtab_addctx* ctx, const char* data, size_t len) { + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); + CHK_OOM(ret); ret->len = len; if (len) memcpy(ret->str, data, len); ret->str[len] = '\0'; return ret; } -static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, +static bool upb_DefPool_TryGetChar(const char** src, const char* end, + char* ch) { + if (*src == end) return false; + *ch = **src; + *src += 1; + return true; +} + +static char upb_DefPool_TryGetHexDigit(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '9') { + return ch - '0'; + } + ch = upb_ascii_lower(ch); + if ('a' <= ch && ch <= 'f') { + return ch - 'a' + 0xa; + } + *src -= 1; // Char wasn't actually a hex digit. + return -1; +} + +static char upb_DefPool_ParseHexEscape(symtab_addctx* ctx, + const upb_FieldDef* f, const char** src, + const char* end) { + char hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end); + if (hex_digit < 0) { + symtab_errf(ctx, + "\\x cannot be followed by non-hex digit in field '%s' default", + upb_FieldDef_FullName(f)); + return 0; + } + unsigned int ret = hex_digit; + while ((hex_digit = upb_DefPool_TryGetHexDigit(ctx, f, src, end)) >= 0) { + ret = (ret << 4) | hex_digit; + } + if (ret > 0xff) { + symtab_errf(ctx, "Value of hex escape in field %s exceeds 8 bits", + upb_FieldDef_FullName(f)); + return 0; + } + return ret; +} + +char upb_DefPool_TryGetOctalDigit(const char** src, const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '7') { + return ch - '0'; + } + *src -= 1; // Char wasn't actually an octal digit. + return -1; +} + +static char upb_DefPool_ParseOctalEscape(symtab_addctx* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + char ch = 0; + for (int i = 0; i < 3; i++) { + char digit; + if ((digit = upb_DefPool_TryGetOctalDigit(src, end)) >= 0) { + ch = (ch << 3) | digit; + } + } + return ch; +} + +static char upb_DefPool_ParseEscape(symtab_addctx* ctx, const upb_FieldDef* f, + const char** src, const char* end) { + char ch; + if (!upb_DefPool_TryGetChar(src, end, &ch)) { + symtab_errf(ctx, "unterminated escape sequence in field %s", + upb_FieldDef_FullName(f)); + return 0; + } + switch (ch) { + case 'a': + return '\a'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'v': + return '\v'; + case '\\': + return '\\'; + case '\'': + return '\''; + case '\"': + return '\"'; + case '?': + return '\?'; + case 'x': + case 'X': + return upb_DefPool_ParseHexEscape(ctx, f, src, end); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + *src -= 1; + return upb_DefPool_ParseOctalEscape(ctx, f, src, end); + } + symtab_errf(ctx, "Unknown escape sequence: \\%c", ch); +} + +static str_t* unescape(symtab_addctx* ctx, const upb_FieldDef* f, const char* data, size_t len) { // Size here is an upper bound; escape sequences could ultimately shrink it. - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); + str_t* ret = symtab_alloc(ctx, sizeof(*ret) + len); char* dst = &ret->str[0]; const char* src = data; const char* end = data + len; @@ -7146,7 +7521,7 @@ static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, while (src < end) { if (*src == '\\') { src++; - *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); + *dst++ = upb_DefPool_ParseEscape(ctx, f, &src, end); } else { *dst++ = *src++; } @@ -7156,7 +7531,7 @@ static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, return ret; } -static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, +static void parse_default(symtab_addctx* ctx, const char* str, size_t len, upb_FieldDef* f) { char* end; char nullz[64]; @@ -7171,7 +7546,7 @@ static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, case kUpb_CType_Float: /* Standard C number parsing functions expect null-terminated strings. */ if (len >= sizeof(nullz) - 1) { - _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); + symtab_errf(ctx, "Default too long: %.*s", (int)len, str); } memcpy(nullz, str, len); nullz[len] = '\0'; @@ -7197,7 +7572,7 @@ static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, if (!ev) { goto invalid; } - f->defaultval.sint = upb_EnumValueDef_Number(ev); + f->defaultval.sint = ev->number; break; } case kUpb_CType_Int64: { @@ -7258,19 +7633,18 @@ static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, break; case kUpb_CType_Message: /* Should not have a default value. */ - _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", - upb_FieldDef_FullName(f)); + symtab_errf(ctx, "Message should not have a default (%s)", + upb_FieldDef_FullName(f)); } return; invalid: - _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", - (int)len, str, upb_FieldDef_FullName(f), - (int)upb_FieldDef_Type(f)); + symtab_errf(ctx, "Invalid default '%.*s' for field %s of type %d", (int)len, + str, upb_FieldDef_FullName(f), (int)upb_FieldDef_Type(f)); } -static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { +static void set_default_default(symtab_addctx* ctx, upb_FieldDef* f) { switch (upb_FieldDef_CType(f)) { case kUpb_CType_Int32: case kUpb_CType_Int64: @@ -7291,48 +7665,56 @@ static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { case kUpb_CType_Bool: f->defaultval.boolean = false; break; - case kUpb_CType_Enum: { - const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); - f->defaultval.sint = upb_EnumValueDef_Number(v); - } + case kUpb_CType_Enum: + f->defaultval.sint = f->sub.enumdef->values[0].number; case kUpb_CType_Message: break; } } -static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - // Must happen before _upb_DefBuilder_Add() - f->file = _upb_DefBuilder_File(ctx); +static void create_fielddef( + symtab_addctx* ctx, const char* prefix, upb_MessageDef* m, + const google_protobuf_FieldDescriptorProto* field_proto, + const upb_FieldDef* _f, bool is_extension) { + upb_FieldDef* f = (upb_FieldDef*)_f; + upb_StringView name; + const char* full_name; + const char* json_name; + const char* shortname; + int32_t field_number; + + f->file = ctx->file; /* Must happen prior to symtab_add(). */ if (!google_protobuf_FieldDescriptorProto_has_name(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); + symtab_errf(ctx, "field has no name"); } - const upb_StringView name = google_protobuf_FieldDescriptorProto_name(field_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); + name = google_protobuf_FieldDescriptorProto_name(field_proto); + check_ident(ctx, name, false); + full_name = makefullname(ctx, prefix, name); + shortname = shortdefname(full_name); - f->has_json_name_ = google_protobuf_FieldDescriptorProto_has_json_name(field_proto); - if (f->has_json_name_) { - const upb_StringView sv = - google_protobuf_FieldDescriptorProto_json_name(field_proto); - f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); + if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) { + json_name = strviewdup( + ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto)); + f->has_json_name_ = true; } else { - f->json_name = make_json_name(name.data, name.size, ctx->arena); + json_name = makejsonname(ctx, shortname); + f->has_json_name_ = false; } - if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + field_number = google_protobuf_FieldDescriptorProto_number(field_proto); + + f->full_name = full_name; + f->json_name = json_name; f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto); - f->number_ = google_protobuf_FieldDescriptorProto_number(field_proto); + f->number_ = field_number; + f->scope.oneof = NULL; f->proto3_optional_ = google_protobuf_FieldDescriptorProto_proto3_optional(field_proto); - f->msgdef = m; - f->scope.oneof = NULL; - const bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); - const bool has_type_name = + bool has_type = google_protobuf_FieldDescriptorProto_has_type(field_proto); + bool has_type_name = google_protobuf_FieldDescriptorProto_has_type_name(field_proto); f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto); @@ -7343,30 +7725,93 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, case kUpb_FieldType_Group: case kUpb_FieldType_Enum: if (!has_type_name) { - _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", - (int)f->type_, f->full_name); + symtab_errf(ctx, "field of type %d requires type name (%s)", + (int)f->type_, full_name); } break; default: if (has_type_name) { - _upb_DefBuilder_Errf( - ctx, "invalid type for field with type_name set (%s, %d)", - f->full_name, (int)f->type_); + symtab_errf(ctx, "invalid type for field with type_name set (%s, %d)", + full_name, (int)f->type_); } } } else if (has_type_name) { f->type_ = - UPB_FIELD_TYPE_UNSPECIFIED; // We'll fill this in in resolve_fielddef() + FIELD_TYPE_UNSPECIFIED; // We'll fill this in in resolve_fielddef(). + } + + if (!is_extension) { + /* direct message field. */ + upb_value v, field_v, json_v, existing_v; + size_t json_size; + + if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { + symtab_errf(ctx, "invalid field number (%u)", field_number); + } + + f->index_ = f - m->fields; + f->msgdef = m; + f->is_extension_ = false; + + field_v = pack_def(f, UPB_DEFTYPE_FIELD); + json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME); + v = upb_value_constptr(f); + json_size = strlen(json_name); + + if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { + symtab_errf(ctx, "duplicate field name (%s)", shortname); + } + + CHK_OOM(upb_strtable_insert(&m->ntof, name.data, name.size, field_v, + ctx->arena)); + + if (strcmp(shortname, json_name) != 0) { + if (upb_strtable_lookup(&m->ntof, json_name, &v)) { + symtab_errf(ctx, "duplicate json_name (%s)", json_name); + } else { + CHK_OOM(upb_strtable_insert(&m->ntof, json_name, json_size, json_v, + ctx->arena)); + } + } + + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { + symtab_errf(ctx, "duplicate field number (%u)", field_number); + } + + CHK_OOM(upb_inttable_insert(&m->itof, field_number, v, ctx->arena)); + + if (ctx->layout) { + const upb_MiniTable_Field* fields = m->layout->fields; + int count = m->layout->field_count; + bool found = false; + for (int i = 0; i < count; i++) { + if (fields[i].number == field_number) { + f->layout_index = i; + found = true; + break; + } + } + UPB_ASSERT(found); + } + } else { + /* extension field. */ + f->is_extension_ = true; + f->scope.extension_scope = m; + symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_EXT)); + f->layout_index = ctx->ext_count++; + if (ctx->layout) { + UPB_ASSERT(ctx->file->ext_layouts[f->layout_index]->field.number == + field_number); + } } if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { - _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, - f->type_); + symtab_errf(ctx, "invalid type for field %s (%d)", f->full_name, f->type_); } if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { - _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, - f->label_); + symtab_errf(ctx, "invalid label for field %s (%d)", f->full_name, + f->label_); } /* We can't resolve the subdef or (in the case of extensions) the containing @@ -7375,136 +7820,427 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, f->sub.unresolved = field_proto; if (f->label_ == kUpb_Label_Required && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); + f->file->syntax == kUpb_Syntax_Proto3) { + symtab_errf(ctx, "proto3 fields cannot be required (%s)", f->full_name); } if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { uint32_t oneof_index = google_protobuf_FieldDescriptorProto_oneof_index(field_proto); + upb_OneofDef* oneof; + upb_value v = upb_value_constptr(f); if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { - _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", - f->full_name); + symtab_errf(ctx, "fields in oneof must have OPTIONAL label (%s)", + f->full_name); } if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); + symtab_errf(ctx, "oneof_index provided for extension field (%s)", + f->full_name); } - if (oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); + if (oneof_index >= m->oneof_count) { + symtab_errf(ctx, "oneof_index out of range (%s)", f->full_name); } - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); + oneof = (upb_OneofDef*)&m->oneofs[oneof_index]; f->scope.oneof = oneof; - bool ok = _upb_OneofDef_Insert(oneof, f, name.data, name.size, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + oneof->field_count++; + if (f->proto3_optional_) { + oneof->synthetic = true; + } + CHK_OOM(upb_inttable_insert(&oneof->itof, f->number_, v, ctx->arena)); + CHK_OOM( + upb_strtable_insert(&oneof->ntof, name.data, name.size, v, ctx->arena)); + } else { + if (f->proto3_optional_ && !is_extension) { + symtab_errf(ctx, "field with proto3_optional was not in a oneof (%s)", + f->full_name); + } } - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); + SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); if (google_protobuf_FieldOptions_has_packed(f->opts)) { - f->is_packed_ = google_protobuf_FieldOptions_packed(f->opts); + f->packed_ = google_protobuf_FieldOptions_packed(f->opts); } else { - // Repeated fields default to packed for proto3 only. - f->is_packed_ = upb_FieldDef_IsPrimitive(f) && - f->label_ == kUpb_Label_Repeated && - upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3; + /* Repeated fields default to packed for proto3 only. */ + f->packed_ = upb_FieldDef_IsPrimitive(f) && + f->label_ == kUpb_Label_Repeated && + f->file->syntax == kUpb_Syntax_Proto3; } } -static void _upb_FieldDef_CreateExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); - f->is_extension_ = true; +static void create_service( + symtab_addctx* ctx, const google_protobuf_ServiceDescriptorProto* svc_proto, + const upb_ServiceDef* _s) { + upb_ServiceDef* s = (upb_ServiceDef*)_s; + upb_StringView name; + const google_protobuf_MethodDescriptorProto* const* methods; + size_t i, n; - if (google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", - f->full_name); + s->file = ctx->file; /* Must happen prior to symtab_add. */ + + name = google_protobuf_ServiceDescriptorProto_name(svc_proto); + check_ident(ctx, name, false); + s->full_name = makefullname(ctx, ctx->file->package, name); + symtab_add(ctx, s->full_name, pack_def(s, UPB_DEFTYPE_SERVICE)); + + methods = google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); + + s->method_count = n; + s->methods = symtab_alloc(ctx, sizeof(*s->methods) * n); + + SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, svc_proto); + + for (i = 0; i < n; i++) { + const google_protobuf_MethodDescriptorProto* method_proto = methods[i]; + upb_MethodDef* m = (upb_MethodDef*)&s->methods[i]; + upb_StringView name = + google_protobuf_MethodDescriptorProto_name(method_proto); + + m->service = s; + m->full_name = makefullname(ctx, s->full_name, name); + m->index = i; + m->client_streaming = + google_protobuf_MethodDescriptorProto_client_streaming(method_proto); + m->server_streaming = + google_protobuf_MethodDescriptorProto_server_streaming(method_proto); + m->input_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_input_type(method_proto), + UPB_DEFTYPE_MSG); + m->output_type = symtab_resolve( + ctx, m->full_name, m->full_name, + google_protobuf_MethodDescriptorProto_output_type(method_proto), + UPB_DEFTYPE_MSG); + + SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, method_proto); + } +} + +static int count_bits_debug(uint64_t x) { + // For assertions only, speed does not matter. + int n = 0; + while (x) { + if (x & 1) n++; + x >>= 1; + } + return n; +} + +static int compare_int32(const void* a_ptr, const void* b_ptr) { + int32_t a = *(int32_t*)a_ptr; + int32_t b = *(int32_t*)b_ptr; + return a < b ? -1 : (a == b ? 0 : 1); +} + +upb_MiniTable_Enum* create_enumlayout(symtab_addctx* ctx, + const upb_EnumDef* e) { + int n = 0; + uint64_t mask = 0; + + for (int i = 0; i < e->value_count; i++) { + uint32_t val = (uint32_t)e->values[i].number; + if (val < 64) { + mask |= 1ULL << val; + } else { + n++; + } } - f->scope.extension_scope = m; - _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); - f->layout_index = ctx->ext_count++; + int32_t* values = symtab_alloc(ctx, sizeof(*values) * n); + + if (n) { + int32_t* p = values; + + // Add values outside the bitmask range to the list, as described in the + // comments for upb_MiniTable_Enum. + for (int i = 0; i < e->value_count; i++) { + int32_t val = e->values[i].number; + if ((uint32_t)val >= 64) { + *p++ = val; + } + } + UPB_ASSERT(p == values + n); + } + + // Enums can have duplicate values; we must sort+uniq them. + if (values) qsort(values, n, sizeof(*values), &compare_int32); + + int dst = 0; + for (int i = 0; i < n; dst++) { + int32_t val = values[i]; + while (i < n && values[i] == val) i++; // Skip duplicates. + values[dst] = val; + } + n = dst; + + UPB_ASSERT(upb_inttable_count(&e->iton) == n + count_bits_debug(mask)); + + upb_MiniTable_Enum* layout = symtab_alloc(ctx, sizeof(*layout)); + layout->value_count = n; + layout->mask = mask; + layout->values = values; + + return layout; +} + +static void create_enumvaldef( + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumValueDescriptorProto* val_proto, upb_EnumDef* e, + int i) { + upb_EnumValueDef* val = (upb_EnumValueDef*)&e->values[i]; + upb_StringView name = + google_protobuf_EnumValueDescriptorProto_name(val_proto); + upb_value v = upb_value_constptr(val); + + val->parent = e; /* Must happen prior to symtab_add(). */ + val->full_name = makefullname(ctx, prefix, name); + val->number = google_protobuf_EnumValueDescriptorProto_number(val_proto); + symtab_add(ctx, val->full_name, pack_def(val, UPB_DEFTYPE_ENUMVAL)); + + SET_OPTIONS(val->opts, EnumValueDescriptorProto, EnumValueOptions, val_proto); + + if (i == 0 && e->file->syntax == kUpb_Syntax_Proto3 && val->number != 0) { + symtab_errf(ctx, "for proto3, the first enum value must be zero (%s)", + e->full_name); + } + + CHK_OOM(upb_strtable_insert(&e->ntoi, name.data, name.size, v, ctx->arena)); + + // Multiple enumerators can have the same number, first one wins. + if (!upb_inttable_lookup(&e->iton, val->number, NULL)) { + CHK_OOM(upb_inttable_insert(&e->iton, val->number, v, ctx->arena)); + } +} + +static upb_StringView* _upb_EnumReservedNames_New( + symtab_addctx* ctx, int n, const upb_StringView* protos) { + upb_StringView* sv = + upb_Arena_Malloc(ctx->arena, sizeof(upb_StringView) * n); + for (size_t i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, ctx->arena); + sv[i].size = protos[i].size; + } + return sv; +} + +static void create_enumdef( + symtab_addctx* ctx, const char* prefix, + const google_protobuf_EnumDescriptorProto* enum_proto, + const upb_MessageDef* containing_type, const upb_EnumDef* _e) { + upb_EnumDef* e = (upb_EnumDef*)_e; + ; + const google_protobuf_EnumValueDescriptorProto* const* values; + const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* res_ranges; + const upb_StringView* res_names; + upb_StringView name; + size_t i, n, n_res_range, n_res_name; + + e->file = ctx->file; /* Must happen prior to symtab_add() */ + e->containing_type = containing_type; + + name = google_protobuf_EnumDescriptorProto_name(enum_proto); + check_ident(ctx, name, false); + + e->full_name = makefullname(ctx, prefix, name); + symtab_add(ctx, e->full_name, pack_def(e, UPB_DEFTYPE_ENUM)); + + values = google_protobuf_EnumDescriptorProto_value(enum_proto, &n); + CHK_OOM(upb_strtable_init(&e->ntoi, n, ctx->arena)); + CHK_OOM(upb_inttable_init(&e->iton, ctx->arena)); + + e->defaultval = 0; + e->value_count = n; + e->values = symtab_alloc(ctx, sizeof(*e->values) * n); + + if (n == 0) { + symtab_errf(ctx, "enums must contain at least one value (%s)", + e->full_name); + } + + res_ranges = + google_protobuf_EnumDescriptorProto_reserved_range(enum_proto, &n_res_range); + e->res_range_count = n_res_range; + e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); + + res_names = google_protobuf_EnumDescriptorProto_reserved_name(enum_proto, &n_res_name); + e->res_name_count = n_res_name; + e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); + + SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + + for (i = 0; i < n; i++) { + create_enumvaldef(ctx, prefix, values[i], e, i); + } + + upb_inttable_compact(&e->iton, ctx->arena); + + if (e->file->syntax == kUpb_Syntax_Proto2) { + if (ctx->layout) { + UPB_ASSERT(ctx->enum_count < ctx->layout->enum_count); + e->layout = ctx->layout->enums[ctx->enum_count++]; + UPB_ASSERT(upb_inttable_count(&e->iton) == + e->layout->value_count + count_bits_debug(e->layout->mask)); + } else { + e->layout = create_enumlayout(ctx, e); + } + } else { + e->layout = NULL; + } +} + +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m); + +static upb_StringView* _upb_ReservedNames_New(symtab_addctx* ctx, int n, + const upb_StringView* protos) { + upb_StringView* sv = upb_Arena_Malloc(ctx->arena, sizeof(upb_StringView) * n); + for (size_t i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, ctx->arena); + sv[i].size = protos[i].size; + } + return sv; +} + +static void create_msgdef(symtab_addctx* ctx, const char* prefix, + const google_protobuf_DescriptorProto* msg_proto, + const upb_MessageDef* containing_type, + const upb_MessageDef* _m) { + upb_MessageDef* m = (upb_MessageDef*)_m; + const google_protobuf_OneofDescriptorProto* const* oneofs; + const google_protobuf_FieldDescriptorProto* const* fields; + const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; + + const google_protobuf_DescriptorProto_ReservedRange* const* res_ranges; + const upb_StringView* res_names; + size_t i, n_oneof, n_field, n_ext_range; + size_t n_res_range, n_res_name; + upb_StringView name; + + m->file = ctx->file; /* Must happen prior to symtab_add(). */ + m->containing_type = containing_type; + + name = google_protobuf_DescriptorProto_name(msg_proto); + check_ident(ctx, name, false); + + m->full_name = makefullname(ctx, prefix, name); + symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG)); + + oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); + fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); + ext_ranges = + google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); + res_ranges = google_protobuf_DescriptorProto_reserved_range(msg_proto, &n_res_range); + res_names = google_protobuf_DescriptorProto_reserved_name(msg_proto, &n_res_name); + + CHK_OOM(upb_inttable_init(&m->itof, ctx->arena)); + CHK_OOM(upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena)); if (ctx->layout) { - UPB_ASSERT(_upb_FieldDef_ExtensionMiniTable(f)->field.number == f->number_); - } -} - -static void _upb_FieldDef_CreateNotExt( - upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_FieldDescriptorProto* field_proto, upb_MessageDef* m, - upb_FieldDef* f) { - _upb_FieldDef_Create(ctx, prefix, field_proto, m, f); - f->is_extension_ = false; - - if (!google_protobuf_FieldDescriptorProto_has_oneof_index(field_proto)) { - if (f->proto3_optional_) { - _upb_DefBuilder_Errf( - ctx, - "non-extension field (%s) with proto3_optional was not in a oneof", - f->full_name); - } - } - - _upb_MessageDef_InsertField(ctx, m, f); - - if (!ctx->layout) return; - - const upb_MiniTable* mt = upb_MessageDef_MiniTable(m); - const upb_MiniTable_Field* fields = mt->fields; - for (int i = 0; i < mt->field_count; i++) { - if (fields[i].number == f->number_) { - f->layout_index = i; - return; - } - } - - UPB_ASSERT(false); // It should be impossible to reach this point. -} - -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); - - // If we are creating extensions then is_sorted will be NULL. - // If we are not creating extensions then is_sorted will be non-NULL. - if (is_sorted) { - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateNotExt(ctx, prefix, protos[i], m, f); - f->index_ = i; - if (!ctx->layout) f->layout_index = i; - - const uint32_t current = f->number_; - if (previous > current) *is_sorted = false; - previous = current; - } + /* create_fielddef() below depends on this being set. */ + UPB_ASSERT(ctx->msg_count < ctx->layout->msg_count); + m->layout = ctx->layout->msgs[ctx->msg_count++]; + UPB_ASSERT(n_field == m->layout->field_count); } else { - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; - - _upb_FieldDef_CreateExt(ctx, prefix, protos[i], m, f); - f->index_ = i; - } + /* Allocate now (to allow cross-linking), populate later. */ + m->layout = + symtab_alloc(ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); } - return defs; + SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + + m->oneof_count = n_oneof; + m->oneofs = symtab_alloc(ctx, sizeof(*m->oneofs) * n_oneof); + for (i = 0; i < n_oneof; i++) { + create_oneofdef(ctx, m, oneofs[i], &m->oneofs[i]); + } + + m->field_count = n_field; + m->fields = symtab_alloc(ctx, sizeof(*m->fields) * n_field); + for (i = 0; i < n_field; i++) { + create_fielddef(ctx, m->full_name, m, fields[i], &m->fields[i], + /* is_extension= */ false); + } + + m->ext_range_count = n_ext_range; + m->ext_ranges = symtab_alloc(ctx, sizeof(*m->ext_ranges) * n_ext_range); + for (i = 0; i < n_ext_range; i++) { + const google_protobuf_DescriptorProto_ExtensionRange* r = ext_ranges[i]; + upb_ExtensionRange* r_def = (upb_ExtensionRange*)&m->ext_ranges[i]; + int32_t start = google_protobuf_DescriptorProto_ExtensionRange_start(r); + int32_t end = google_protobuf_DescriptorProto_ExtensionRange_end(r); + int32_t max = + google_protobuf_MessageOptions_message_set_wire_format(m->opts) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; + + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + symtab_errf(ctx, "Extension range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, m->full_name); + } + + r_def->start = start; + r_def->end = end; + SET_OPTIONS(r_def->opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, r); + } + + m->res_range_count = n_res_range; + m->res_ranges = + _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + + m->res_name_count = n_res_name; + m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); + + finalize_oneofs(ctx, m); + assign_msg_wellknowntype(m); + upb_inttable_compact(&m->itof, ctx->arena); + msgdef_create_nested(ctx, msg_proto, m); } -static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, +static void msgdef_create_nested( + symtab_addctx* ctx, const google_protobuf_DescriptorProto* msg_proto, + upb_MessageDef* m) { + size_t n; + + const google_protobuf_EnumDescriptorProto* const* enums = + google_protobuf_DescriptorProto_enum_type(msg_proto, &n); + m->nested_enum_count = n; + m->nested_enums = symtab_alloc(ctx, sizeof(*m->nested_enums) * n); + for (size_t i = 0; i < n; i++) { + m->nested_enum_count = i + 1; + create_enumdef(ctx, m->full_name, enums[i], m, &m->nested_enums[i]); + } + + const google_protobuf_FieldDescriptorProto* const* exts = + google_protobuf_DescriptorProto_extension(msg_proto, &n); + m->nested_ext_count = n; + m->nested_exts = symtab_alloc(ctx, sizeof(*m->nested_exts) * n); + for (size_t i = 0; i < n; i++) { + create_fielddef(ctx, m->full_name, m, exts[i], &m->nested_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&m->nested_exts[i])->index_ = i; + } + + const google_protobuf_DescriptorProto* const* msgs = + google_protobuf_DescriptorProto_nested_type(msg_proto, &n); + m->nested_msg_count = n; + m->nested_msgs = symtab_alloc(ctx, sizeof(*m->nested_msgs) * n); + for (size_t i = 0; i < n; i++) { + create_msgdef(ctx, m->full_name, msgs[i], m, &m->nested_msgs[i]); + } +} + +static void resolve_subdef(symtab_addctx* ctx, const char* prefix, upb_FieldDef* f) { const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; upb_StringView name = @@ -7512,12 +8248,12 @@ static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, bool has_name = google_protobuf_FieldDescriptorProto_has_type_name(field_proto); switch ((int)f->type_) { - case UPB_FIELD_TYPE_UNSPECIFIED: { + case FIELD_TYPE_UNSPECIFIED: { // Type was not specified and must be inferred. UPB_ASSERT(has_name); upb_deftype_t type; const void* def = - _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); + symtab_resolveany(ctx, f->full_name, prefix, name, &type); switch (type) { case UPB_DEFTYPE_ENUM: f->sub.enumdef = def; @@ -7529,20 +8265,20 @@ static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, // this being a group. break; default: - _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", - f->full_name); + symtab_errf(ctx, "Couldn't resolve type name for field %s", + f->full_name); } } case kUpb_FieldType_Message: case kUpb_FieldType_Group: UPB_ASSERT(has_name); - f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_MSG); + f->sub.msgdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); break; case kUpb_FieldType_Enum: UPB_ASSERT(has_name); - f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_ENUM); + f->sub.enumdef = + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_ENUM); break; default: // No resolution necessary. @@ -7550,114 +8286,70 @@ static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, } } -static int _upb_FieldDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; - const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; - return (v1 < v2) ? -1 : (v1 > v2); -} - -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; - - for (int i = 0; i < n; i++) { - out[i] = (upb_FieldDef*)&f[i]; - } - qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); - - for (int i = 0; i < n; i++) { - out[i]->layout_index = i; - } - return (const upb_FieldDef**)out; -} - -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out) { - UPB_ASSERT(f->is_extension_); - - upb_DescState s; - _upb_DescState_Init(&s); - - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, - modifiers); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { +static void resolve_extension( + symtab_addctx* ctx, const char* prefix, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { if (!google_protobuf_FieldDescriptorProto_has_extendee(field_proto)) { - _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", - f->full_name); + symtab_errf(ctx, "extension for field '%s' had no extendee", f->full_name); } - upb_StringView name = google_protobuf_FieldDescriptorProto_extendee(field_proto); + upb_StringView name = + google_protobuf_FieldDescriptorProto_extendee(field_proto); const upb_MessageDef* m = - _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + symtab_resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); f->msgdef = m; - if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { - _upb_DefBuilder_Errf( - ctx, - "field number %u in extension %s has no extension range in message %s", - (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); + bool found = false; + + for (int i = 0, n = m->ext_range_count; i < n; i++) { + const upb_ExtensionRange* r = &m->ext_ranges[i]; + if (r->start <= f->number_ && f->number_ < r->end) { + found = true; + break; + } } - const upb_MiniTable_Extension* ext = _upb_FieldDef_ExtensionMiniTable(f); + if (!found) { + symtab_errf(ctx, + "field number %u in extension %s has no extension range in " + "message %s", + (unsigned)f->number_, f->full_name, f->msgdef->full_name); + } + const upb_MiniTable_Extension* ext = ctx->file->ext_layouts[f->layout_index]; if (ctx->layout) { UPB_ASSERT(upb_FieldDef_Number(f) == ext->field.number); } else { - upb_StringView desc; - if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { - _upb_DefBuilder_OomErr(ctx); - } - upb_MiniTable_Extension* mut_ext = (upb_MiniTable_Extension*)ext; - upb_MiniTable_Sub sub = {NULL}; - if (upb_FieldDef_IsSubMessage(f)) { - sub.submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - sub.subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - } - bool ok2 = upb_MiniTable_BuildExtension(desc.data, desc.size, mut_ext, - upb_MessageDef_MiniTable(m), sub, - ctx->status); - if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); + fill_fieldlayout(&mut_ext->field, f); + mut_ext->field.presence = 0; + mut_ext->field.offset = 0; + mut_ext->field.submsg_index = 0; + mut_ext->extendee = f->msgdef->layout; + mut_ext->sub.submsg = f->sub.msgdef->layout; } - bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); - if (!ok) _upb_DefBuilder_OomErr(ctx); + CHK_OOM(upb_inttable_insert(&ctx->symtab->exts, (uintptr_t)ext, + upb_value_constptr(f), ctx->arena)); } -static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const google_protobuf_FieldDescriptorProto* field_proto) { +static void resolve_default( + symtab_addctx* ctx, upb_FieldDef* f, + const google_protobuf_FieldDescriptorProto* field_proto) { // Have to delay resolving of the default value until now because of the enum // case, since enum defaults are specified with a label. if (google_protobuf_FieldDescriptorProto_has_default_value(field_proto)) { upb_StringView defaultval = google_protobuf_FieldDescriptorProto_default_value(field_proto); - if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, - "proto3 fields cannot have explicit defaults (%s)", - f->full_name); + if (f->file->syntax == kUpb_Syntax_Proto3) { + symtab_errf(ctx, "proto3 fields cannot have explicit defaults (%s)", + f->full_name); } if (upb_FieldDef_IsSubMessage(f)) { - _upb_DefBuilder_Errf(ctx, - "message fields cannot have explicit defaults (%s)", - f->full_name); + symtab_errf(ctx, "message fields cannot have explicit defaults (%s)", + f->full_name); } parse_default(ctx, defaultval.data, defaultval.size, f); @@ -7668,8 +8360,8 @@ static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, } } -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { +static void resolve_fielddef(symtab_addctx* ctx, const char* prefix, + upb_FieldDef* f) { // We have to stash this away since resolve_subdef() may overwrite it. const google_protobuf_FieldDescriptorProto* field_proto = f->sub.unresolved; @@ -7681,135 +8373,28 @@ void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, } } +static void resolve_msgdef(symtab_addctx* ctx, upb_MessageDef* m) { + for (int i = 0; i < m->field_count; i++) { + resolve_fielddef(ctx, m->full_name, (upb_FieldDef*)&m->fields[i]); + } -// Must be last. + m->in_message_set = false; + for (int i = 0; i < m->nested_ext_count; i++) { + upb_FieldDef* ext = (upb_FieldDef*)&m->nested_exts[i]; + resolve_fielddef(ctx, m->full_name, ext); + if (ext->type_ == kUpb_FieldType_Message && + ext->label_ == kUpb_Label_Optional && ext->sub.msgdef == m && + google_protobuf_MessageOptions_message_set_wire_format( + ext->msgdef->opts)) { + m->in_message_set = true; + } + } -struct upb_FileDef { - const google_protobuf_FileOptions* opts; - const char* name; - const char* package; + if (!ctx->layout) make_layout(ctx, m); - const upb_FileDef** deps; - const int32_t* public_deps; - const int32_t* weak_deps; - const upb_MessageDef* top_lvl_msgs; - const upb_EnumDef* top_lvl_enums; - const upb_FieldDef* top_lvl_exts; - const upb_ServiceDef* services; - const upb_MiniTable_Extension** ext_layouts; - const upb_DefPool* symtab; - - int dep_count; - int public_dep_count; - int weak_dep_count; - int top_lvl_msg_count; - int top_lvl_enum_count; - int top_lvl_ext_count; - int service_count; - int ext_count; // All exts in the file. - upb_Syntax syntax; -}; - -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f) { - return f->opts; -} - -bool upb_FileDef_HasOptions(const upb_FileDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } - -const char* upb_FileDef_Package(const upb_FileDef* f) { - return f->package ? f->package : ""; -} - -const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } - -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } - -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { - return f->top_lvl_msg_count; -} - -int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } - -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { - return f->public_dep_count; -} - -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { - return f->weak_dep_count; -} - -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { - return f->public_deps; -} - -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { - return f->weak_deps; -} - -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { - return f->top_lvl_enum_count; -} - -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { - return f->top_lvl_ext_count; -} - -int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->dep_count); - return f->deps[i]; -} - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->public_deps[i]]; -} - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->weak_deps[i]]; -} - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); - return _upb_MessageDef_At(f->top_lvl_msgs, i); -} - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); - return _upb_EnumDef_At(f->top_lvl_enums, i); -} - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); - return _upb_FieldDef_At(f->top_lvl_exts, i); -} - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->service_count); - return _upb_ServiceDef_At(f->services, i); -} - -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } - -const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i) { - return f->ext_layouts[i]; -} - -static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { - char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -static bool streql_view(upb_StringView view, const char* b) { - return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; + for (int i = 0; i < m->nested_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&m->nested_msgs[i]); + } } static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { @@ -7826,12 +8411,9 @@ static int count_exts_in_msg(const google_protobuf_DescriptorProto* msg_proto) { return ext_count; } -// Allocate and initialize one file def, and add it to the context object. -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto) { - upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); - ctx->file = file; - +static void build_filedef( + symtab_addctx* ctx, upb_FileDef* file, + const google_protobuf_FileDescriptorProto* file_proto) { const google_protobuf_DescriptorProto* const* msgs; const google_protobuf_EnumDescriptorProto* const* enums; const google_protobuf_FieldDescriptorProto* const* exts; @@ -7839,11 +8421,11 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, const upb_StringView* strs; const int32_t* public_deps; const int32_t* weak_deps; - size_t n; + size_t i, n; file->symtab = ctx->symtab; - // Count all extensions in the file, to build a flat array of layouts. + /* Count all extensions in the file, to build a flat array of layouts. */ google_protobuf_FileDescriptorProto_extension(file_proto, &n); int ext_count = n; msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); @@ -7853,151 +8435,368 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, file->ext_count = ext_count; if (ctx->layout) { - // We are using the ext layouts that were passed in. + /* We are using the ext layouts that were passed in. */ file->ext_layouts = ctx->layout->exts; if (ctx->layout->ext_count != file->ext_count) { - _upb_DefBuilder_Errf(ctx, - "Extension count did not match layout (%d vs %d)", - ctx->layout->ext_count, file->ext_count); + symtab_errf(ctx, "Extension count did not match layout (%d vs %d)", + ctx->layout->ext_count, file->ext_count); } } else { - // We are building ext layouts from scratch. - file->ext_layouts = _upb_DefBuilder_Alloc( - ctx, sizeof(*file->ext_layouts) * file->ext_count); + /* We are building ext layouts from scratch. */ + file->ext_layouts = + symtab_alloc(ctx, sizeof(*file->ext_layouts) * file->ext_count); upb_MiniTable_Extension* ext = - _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); + symtab_alloc(ctx, sizeof(*ext) * file->ext_count); for (int i = 0; i < file->ext_count; i++) { file->ext_layouts[i] = &ext[i]; } } if (!google_protobuf_FileDescriptorProto_has_name(file_proto)) { - _upb_DefBuilder_Errf(ctx, "File has no name"); + symtab_errf(ctx, "File has no name"); } - file->name = strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); + file->name = + strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto)); upb_StringView package = google_protobuf_FileDescriptorProto_package(file_proto); if (package.size) { - _upb_DefBuilder_CheckIdentFull(ctx, package); + check_ident(ctx, package, true); file->package = strviewdup(ctx, package); } else { file->package = NULL; } if (google_protobuf_FileDescriptorProto_has_syntax(file_proto)) { - upb_StringView syntax = google_protobuf_FileDescriptorProto_syntax(file_proto); + upb_StringView syntax = + google_protobuf_FileDescriptorProto_syntax(file_proto); if (streql_view(syntax, "proto2")) { file->syntax = kUpb_Syntax_Proto2; } else if (streql_view(syntax, "proto3")) { file->syntax = kUpb_Syntax_Proto3; } else { - _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(syntax)); + symtab_errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(syntax)); } } else { file->syntax = kUpb_Syntax_Proto2; } - // Read options. - UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); + /* Read options. */ + SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - // Verify dependencies. + /* Verify dependencies. */ strs = google_protobuf_FileDescriptorProto_dependency(file_proto, &n); file->dep_count = n; - file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); + file->deps = symtab_alloc(ctx, sizeof(*file->deps) * n); - for (size_t i = 0; i < n; i++) { + for (i = 0; i < n; i++) { upb_StringView str = strs[i]; file->deps[i] = upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); if (!file->deps[i]) { - _upb_DefBuilder_Errf(ctx, - "Depends on file '" UPB_STRINGVIEW_FORMAT - "', but it has not been loaded", - UPB_STRINGVIEW_ARGS(str)); + symtab_errf(ctx, + "Depends on file '" UPB_STRINGVIEW_FORMAT + "', but it has not been loaded", + UPB_STRINGVIEW_ARGS(str)); } } - public_deps = google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); + public_deps = + google_protobuf_FileDescriptorProto_public_dependency(file_proto, &n); file->public_dep_count = n; - file->public_deps = - _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); + file->public_deps = symtab_alloc(ctx, sizeof(*file->public_deps) * n); int32_t* mutable_public_deps = (int32_t*)file->public_deps; - for (size_t i = 0; i < n; i++) { + for (i = 0; i < n; i++) { if (public_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", - (int)public_deps[i]); + symtab_errf(ctx, "public_dep %d is out of range", (int)public_deps[i]); } mutable_public_deps[i] = public_deps[i]; } - weak_deps = google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); + weak_deps = + google_protobuf_FileDescriptorProto_weak_dependency(file_proto, &n); file->weak_dep_count = n; - file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); + file->weak_deps = symtab_alloc(ctx, sizeof(*file->weak_deps) * n); int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; - for (size_t i = 0; i < n; i++) { + for (i = 0; i < n; i++) { if (weak_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", - (int)weak_deps[i]); + symtab_errf(ctx, "weak_dep %d is out of range", (int)weak_deps[i]); } mutable_weak_deps[i] = weak_deps[i]; } - // Create enums. + /* Create enums. */ enums = google_protobuf_FileDescriptorProto_enum_type(file_proto, &n); file->top_lvl_enum_count = n; - file->top_lvl_enums = _upb_EnumDefs_New(ctx, n, enums, NULL); + file->top_lvl_enums = symtab_alloc(ctx, sizeof(*file->top_lvl_enums) * n); + for (i = 0; i < n; i++) { + create_enumdef(ctx, file->package, enums[i], NULL, &file->top_lvl_enums[i]); + } - // Create extensions. + /* Create extensions. */ exts = google_protobuf_FileDescriptorProto_extension(file_proto, &n); file->top_lvl_ext_count = n; - file->top_lvl_exts = - _upb_FieldDefs_New(ctx, n, exts, file->package, NULL, NULL); + file->top_lvl_exts = symtab_alloc(ctx, sizeof(*file->top_lvl_exts) * n); + for (i = 0; i < n; i++) { + create_fielddef(ctx, file->package, NULL, exts[i], &file->top_lvl_exts[i], + /* is_extension= */ true); + ((upb_FieldDef*)&file->top_lvl_exts[i])->index_ = i; + } - // Create messages. + /* Create messages. */ msgs = google_protobuf_FileDescriptorProto_message_type(file_proto, &n); file->top_lvl_msg_count = n; - file->top_lvl_msgs = _upb_MessageDefs_New(ctx, n, msgs, NULL); + file->top_lvl_msgs = symtab_alloc(ctx, sizeof(*file->top_lvl_msgs) * n); + for (i = 0; i < n; i++) { + create_msgdef(ctx, file->package, msgs[i], NULL, &file->top_lvl_msgs[i]); + } - // Create services. + /* Create services. */ services = google_protobuf_FileDescriptorProto_service(file_proto, &n); file->service_count = n; - file->services = _upb_ServiceDefs_New(ctx, n, services); - - // Now that all names are in the table, build layouts and resolve refs. - - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_Resolve(ctx, m); + file->services = symtab_alloc(ctx, sizeof(*file->services) * n); + for (i = 0; i < n; i++) { + create_service(ctx, services[i], &file->services[i]); + ((upb_ServiceDef*)&file->services[i])->index = i; } - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_Resolve(ctx, file->package, f); + /* Now that all names are in the table, build layouts and resolve refs. */ + for (i = 0; i < (size_t)file->top_lvl_ext_count; i++) { + resolve_fielddef(ctx, file->package, (upb_FieldDef*)&file->top_lvl_exts[i]); } - if (!ctx->layout) { - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_LinkMiniTable(ctx, m); - } + for (i = 0; i < (size_t)file->top_lvl_msg_count; i++) { + resolve_msgdef(ctx, (upb_MessageDef*)&file->top_lvl_msgs[i]); } if (file->ext_count) { - bool ok = upb_ExtensionRegistry_AddArray( - _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); - if (!ok) _upb_DefBuilder_OomErr(ctx); + CHK_OOM(_upb_extreg_add(ctx->symtab->extreg, file->ext_layouts, + file->ext_count)); } } +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (deftype(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(unpack_def(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(unpack_def(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(unpack_def(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File( + upb_EnumValueDef_Enum(unpack_def(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(unpack_def(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } + + if (f == file) upb_strtable_removeiter(&s->syms, &iter); + } +} + +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, + const upb_MiniTable_File* layout, upb_Status* status) { + symtab_addctx ctx; + upb_StringView name = google_protobuf_FileDescriptorProto_name(file_proto); + upb_value v; + + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + if (unpack_def(v, UPB_DEFTYPE_FILE)) { + upb_Status_SetErrorFormat(status, "duplicate file name (%.*s)", + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + const upb_MiniTable_File* registered = unpack_def(v, UPB_DEFTYPE_LAYOUT); + UPB_ASSERT(registered); + if (layout && layout != registered) { + upb_Status_SetErrorFormat( + status, "tried to build with a different layout (filename=%.*s)", + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + layout = registered; + } + + ctx.symtab = s; + ctx.layout = layout; + ctx.msg_count = 0; + ctx.enum_count = 0; + ctx.ext_count = 0; + ctx.status = status; + ctx.file = NULL; + ctx.arena = upb_Arena_New(); + ctx.tmp_arena = upb_Arena_New(); + + if (!ctx.arena || !ctx.tmp_arena) { + if (ctx.arena) upb_Arena_Free(ctx.arena); + if (ctx.tmp_arena) upb_Arena_Free(ctx.tmp_arena); + upb_Status_setoom(status); + return NULL; + } + + if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { + UPB_ASSERT(!upb_Status_IsOk(status)); + if (ctx.file) { + remove_filedef(s, ctx.file); + ctx.file = NULL; + } + } else { + ctx.file = symtab_alloc(&ctx, sizeof(*ctx.file)); + build_filedef(&ctx, ctx.file, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + pack_def(ctx.file, UPB_DEFTYPE_FILE), ctx.arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, ctx.arena); + } + + upb_Arena_Free(ctx.arena); + upb_Arena_Free(ctx.tmp_arena); + return ctx.file; +} + +const upb_FileDef* upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); +} + +/* Include here since we want most of this file to be stdio-free. */ +#include + +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable) { + /* Since this function should never fail (it would indicate a bug in upb) we + * print errors to stderr instead of returning error status to the user. */ + _upb_DefPool_Init** deps = init->deps; + google_protobuf_FileDescriptorProto* file; + upb_Arena* arena; + upb_Status status; + + upb_Status_Clear(&status); + + if (upb_DefPool_FindFileByName(s, init->filename)) { + return true; + } + + arena = upb_Arena_New(); + + for (; *deps; deps++) { + if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; + } + + file = google_protobuf_FileDescriptorProto_parse_ex( + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); + s->bytes_loaded += init->descriptor.size; + + if (!file) { + upb_Status_SetErrorFormat( + &status, + "Failed to parse compiled-in descriptor for file '%s'. This should " + "never happen.", + init->filename); + goto err; + } + + const upb_MiniTable_File* mt = rebuild_minitable ? NULL : init->layout; + if (!_upb_DefPool_AddFile(s, file, mt, &status)) { + goto err; + } + + upb_Arena_Free(arena); + return true; + +err: + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); + return false; +} + +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { + return s->bytes_loaded; +} + +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext) { + upb_value v; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* l = upb_MessageDef_MiniTable(m); + const upb_MiniTable_Extension* ext = _upb_extreg_get(s->extreg, l, fieldnum); + return ext ? _upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; +} + +bool _upb_DefPool_registerlayout(upb_DefPool* s, const char* filename, + const upb_MiniTable_File* file) { + if (upb_DefPool_FindFileByName(s, filename)) return false; + upb_value v = pack_def(file, UPB_DEFTYPE_LAYOUT); + return upb_strtable_insert(&s->files, filename, strlen(filename), v, + s->arena); +} + +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { + return s->extreg; +} + +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; + } + const upb_FieldDef** exts = malloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next2(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; +} + +#undef CHK_OOM + +/** upb/reflection.c ************************************************************/ #include -// Must be last. - static size_t get_field_size(const upb_MiniTable_Field* f) { static unsigned char sizes[] = { 0, /* 0 */ @@ -8023,6 +8822,13 @@ static size_t get_field_size(const upb_MiniTable_Field* f) { return upb_IsRepeatedOrMap(f) ? sizeof(void*) : sizes[f->descriptortype]; } +/** upb_Message + * *******************************************************************/ + +upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a) { + return _upb_Message_New(upb_MessageDef_MiniTable(m), a); +} + static bool in_oneof(const upb_MiniTable_Field* field) { return field->presence < 0; } @@ -8117,8 +8923,7 @@ make: ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); } else { UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); + ret.msg = upb_Message_New(upb_FieldDef_MessageSubDef(f), a); } val.array_val = ret.array; @@ -8136,14 +8941,6 @@ bool upb_Message_Set(upb_Message* msg, const upb_FieldDef* f, memcpy(&ext->data, &val, sizeof(val)); } else { const upb_MiniTable_Field* field = upb_FieldDef_MiniTable(f); - - // Building reflection should always cause all sub-message types to be - // linked, but double-check here just for extra assurance. - UPB_ASSERT(!upb_FieldDef_IsSubMessage(f) || - upb_MessageDef_MiniTable(upb_FieldDef_ContainingType(f)) - ->subs[field->submsg_index] - .submsg); - char* mem = UPB_PTR_AT(msg, field->offset, char); memcpy(mem, &val, get_field_size(field)); if (field->presence > 0) { @@ -8224,7 +9021,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); - *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); + *out_f = _upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); *iter = i; return true; } @@ -8289,955 +9086,2188 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, return _upb_Message_DiscardUnknown(msg, m, maxdepth); } +/** upb/decode.c ************************************************************/ -// Must be last. +#include +#include -struct upb_MessageDef { - const google_protobuf_MessageOptions* opts; - const upb_MiniTable* layout; - const upb_FileDef* file; - const upb_MessageDef* containing_type; - const char* full_name; - // Tables for looking up fields by number and name. - upb_inttable itof; - upb_strtable ntof; +/* Must be last. */ - /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contiguous - * region and calculating counts from offsets or vice-versa. */ - const upb_FieldDef* fields; - const upb_OneofDef* oneofs; - const upb_ExtensionRange* ext_ranges; - const upb_MessageDef* nested_msgs; - const upb_EnumDef* nested_enums; - const upb_FieldDef* nested_exts; - int field_count; - int real_oneof_count; - int oneof_count; - int ext_range_count; - int nested_msg_count; - int nested_enum_count; - int nested_ext_count; - bool in_message_set; - bool is_sorted; - upb_WellKnown well_known_type; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif +/* Maps descriptor type -> elem_size_lg2. */ +static const uint8_t desctype_to_elem_size_lg2[] = { + -1, /* invalid descriptor type */ + 3, /* DOUBLE */ + 2, /* FLOAT */ + 3, /* INT64 */ + 3, /* UINT64 */ + 2, /* INT32 */ + 3, /* FIXED64 */ + 2, /* FIXED32 */ + 0, /* BOOL */ + UPB_SIZE(3, 4), /* STRING */ + UPB_SIZE(2, 3), /* GROUP */ + UPB_SIZE(2, 3), /* MESSAGE */ + UPB_SIZE(3, 4), /* BYTES */ + 2, /* UINT32 */ + 2, /* ENUM */ + 2, /* SFIXED32 */ + 3, /* SFIXED64 */ + 2, /* SINT32 */ + 3, /* SINT64 */ }; -static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = upb_MessageDef_FullName(m); - if (name == NULL) { - m->well_known_type = kUpb_WellKnown_Unspecified; +/* Maps descriptor type -> upb map size. */ +static const uint8_t desctype_to_mapsize[] = { + -1, /* invalid descriptor type */ + 8, /* DOUBLE */ + 4, /* FLOAT */ + 8, /* INT64 */ + 8, /* UINT64 */ + 4, /* INT32 */ + 8, /* FIXED64 */ + 4, /* FIXED32 */ + 1, /* BOOL */ + UPB_MAPTYPE_STRING, /* STRING */ + sizeof(void*), /* GROUP */ + sizeof(void*), /* MESSAGE */ + UPB_MAPTYPE_STRING, /* BYTES */ + 4, /* UINT32 */ + 4, /* ENUM */ + 4, /* SFIXED32 */ + 8, /* SFIXED64 */ + 4, /* SINT32 */ + 8, /* SINT64 */ +}; + +static const unsigned FIXED32_OK_MASK = (1 << kUpb_FieldType_Float) | + (1 << kUpb_FieldType_Fixed32) | + (1 << kUpb_FieldType_SFixed32); + +static const unsigned FIXED64_OK_MASK = (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Fixed64) | + (1 << kUpb_FieldType_SFixed64); + +/* Three fake field types for MessageSet. */ +#define TYPE_MSGSET_ITEM 19 +#define TYPE_COUNT 19 + +/* Op: an action to be performed for a wire-type/field-type combination. */ +#define OP_UNKNOWN -1 /* Unknown field. */ +#define OP_MSGSET_ITEM -2 +#define OP_SCALAR_LG2(n) (n) /* n in [0, 2, 3] => op in [0, 2, 3] */ +#define OP_ENUM 1 +#define OP_STRING 4 +#define OP_BYTES 5 +#define OP_SUBMSG 6 +/* Scalar fields use only ops above. Repeated fields can use any op. */ +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ +#define OP_PACKED_ENUM 13 + +static const int8_t varint_ops[] = { + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ + OP_SCALAR_LG2(3), /* INT64 */ + OP_SCALAR_LG2(3), /* UINT64 */ + OP_SCALAR_LG2(2), /* INT32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ + OP_SCALAR_LG2(0), /* BOOL */ + OP_UNKNOWN, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_UNKNOWN, /* MESSAGE */ + OP_UNKNOWN, /* BYTES */ + OP_SCALAR_LG2(2), /* UINT32 */ + OP_ENUM, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ + OP_SCALAR_LG2(2), /* SINT32 */ + OP_SCALAR_LG2(3), /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ +}; + +static const int8_t delim_ops[] = { + /* For non-repeated field type. */ + OP_UNKNOWN, /* field not found */ + OP_UNKNOWN, /* DOUBLE */ + OP_UNKNOWN, /* FLOAT */ + OP_UNKNOWN, /* INT64 */ + OP_UNKNOWN, /* UINT64 */ + OP_UNKNOWN, /* INT32 */ + OP_UNKNOWN, /* FIXED64 */ + OP_UNKNOWN, /* FIXED32 */ + OP_UNKNOWN, /* BOOL */ + OP_STRING, /* STRING */ + OP_UNKNOWN, /* GROUP */ + OP_SUBMSG, /* MESSAGE */ + OP_BYTES, /* BYTES */ + OP_UNKNOWN, /* UINT32 */ + OP_UNKNOWN, /* ENUM */ + OP_UNKNOWN, /* SFIXED32 */ + OP_UNKNOWN, /* SFIXED64 */ + OP_UNKNOWN, /* SINT32 */ + OP_UNKNOWN, /* SINT64 */ + OP_UNKNOWN, /* MSGSET_ITEM */ + /* For repeated field type. */ + OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */ + OP_FIXPCK_LG2(2), /* REPEATED FLOAT */ + OP_VARPCK_LG2(3), /* REPEATED INT64 */ + OP_VARPCK_LG2(3), /* REPEATED UINT64 */ + OP_VARPCK_LG2(2), /* REPEATED INT32 */ + OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */ + OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */ + OP_VARPCK_LG2(0), /* REPEATED BOOL */ + OP_STRING, /* REPEATED STRING */ + OP_SUBMSG, /* REPEATED GROUP */ + OP_SUBMSG, /* REPEATED MESSAGE */ + OP_BYTES, /* REPEATED BYTES */ + OP_VARPCK_LG2(2), /* REPEATED UINT32 */ + OP_PACKED_ENUM, /* REPEATED ENUM */ + OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */ + OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */ + OP_VARPCK_LG2(2), /* REPEATED SINT32 */ + OP_VARPCK_LG2(3), /* REPEATED SINT64 */ + /* Omitting MSGSET_*, because we never emit a repeated msgset type */ +}; + +typedef union { + bool bool_val; + uint32_t uint32_val; + uint64_t uint64_val; + uint32_t size; +} wireval; + +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout); + +UPB_NORETURN static void* decode_err(upb_Decoder* d, upb_DecodeStatus status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); +} + +const char* fastdecode_err(upb_Decoder* d, int status) { + assert(status != kUpb_DecodeStatus_Ok); + UPB_LONGJMP(d->err, status); + return NULL; +} +static void decode_verifyutf8(upb_Decoder* d, const char* buf, int len) { + if (!decode_verifyutf8_inl(buf, len)) + decode_err(d, kUpb_DecodeStatus_BadUtf8); +} + +static bool decode_reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { + bool need_realloc = arr->size - arr->len < elem; + if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + return need_realloc; +} + +typedef struct { + const char* ptr; + uint64_t val; +} decode_vret; + +UPB_NOINLINE +static decode_vret decode_longvarint64(const char* ptr, uint64_t val) { + decode_vret ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } + } + return ret; +} + +UPB_FORCEINLINE +static const char* decode_varint64(upb_Decoder* d, const char* ptr, + uint64_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + decode_vret res = decode_longvarint64(ptr, byte); + if (!res.ptr) return decode_err(d, kUpb_DecodeStatus_Malformed); + *val = res.val; + return res.ptr; + } +} + +UPB_FORCEINLINE +static const char* decode_tag(upb_Decoder* d, const char* ptr, uint32_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + const char* start = ptr; + decode_vret res = decode_longvarint64(ptr, byte); + if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + *val = res.val; + return res.ptr; + } +} + +UPB_FORCEINLINE +static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, + uint32_t* size) { + uint64_t size64; + ptr = decode_varint64(d, ptr, &size64); + if (size64 >= INT32_MAX || ptr - d->end + (int)size64 > d->limit) { + decode_err(d, kUpb_DecodeStatus_Malformed); + } + *size = size64; + return ptr; +} + +static void decode_munge_int32(wireval* val) { + if (!_upb_IsLittleEndian()) { + /* The next stage will memcpy(dst, &val, 4) */ + val->uint32_val = val->uint64_val; + } +} + +static void decode_munge(int type, wireval* val) { + switch (type) { + case kUpb_FieldType_Bool: + val->bool_val = val->uint64_val != 0; + break; + case kUpb_FieldType_SInt32: { + uint32_t n = val->uint64_val; + val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); + break; + } + case kUpb_FieldType_SInt64: { + uint64_t n = val->uint64_val; + val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); + break; + } + case kUpb_FieldType_Int32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Enum: + decode_munge_int32(val); + break; + } +} + +static upb_Message* decode_newsubmsg(upb_Decoder* d, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; + upb_Message* msg = _upb_Message_New_inl(subl, &d->arena); + if (!msg) decode_err(d, kUpb_DecodeStatus_OutOfMemory); + return msg; +} + +UPB_NOINLINE +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, + int overrun) { + int status; + ptr = decode_isdonefallback_inl(d, ptr, overrun, &status); + if (ptr == NULL) { + return decode_err(d, status); + } + return ptr; +} + +static const char* decode_readstr(upb_Decoder* d, const char* ptr, int size, + upb_StringView* str) { + if (d->options & kUpb_DecodeOption_AliasString) { + str->data = ptr; + } else { + char* data = upb_Arena_Malloc(&d->arena, size); + if (!data) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + memcpy(data, ptr, size); + str->data = data; + } + str->size = size; + return ptr + size; +} + +UPB_FORCEINLINE +static const char* decode_tosubmsg2(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, int size) { + int saved_delta = decode_pushlimit(d, ptr, size); + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != DECODE_NOGROUP) + return decode_err(d, kUpb_DecodeStatus_Malformed); + decode_poplimit(d, ptr, saved_delta); + d->depth++; + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_tosubmsg(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, int size) { + return decode_tosubmsg2(d, ptr, submsg, subs[field->submsg_index].submsg, + size); +} + +UPB_FORCEINLINE +static const char* decode_group(upb_Decoder* d, const char* ptr, + upb_Message* submsg, const upb_MiniTable* subl, + uint32_t number) { + if (--d->depth < 0) return decode_err(d, kUpb_DecodeStatus_MaxDepthExceeded); + if (decode_isdone(d, &ptr)) { + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + ptr = decode_msg(d, ptr, submsg, subl); + if (d->end_group != number) return decode_err(d, kUpb_DecodeStatus_Malformed); + d->end_group = DECODE_NOGROUP; + d->depth++; + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_togroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + const upb_MiniTable* subl = subs[field->submsg_index].submsg; + return decode_group(d, ptr, submsg, subl, field->number); +} + +static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + *(ptr++) = byte; + } while (val); + return ptr; +} + +static void upb_Decode_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, + uint32_t val1, uint32_t val2) { + char buf[20]; + char* end = buf; + end = upb_Decoder_EncodeVarint32(val1, end); + end = upb_Decoder_EncodeVarint32(val2, end); + + if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } +} + +UPB_NOINLINE +static bool decode_checkenum_slow(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, + uint32_t v) { + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if ((uint32_t)e->values[i] == v) return true; + } + + // Unrecognized enum goes into unknown fields. + // For packed fields the tag could be arbitrarily far in the past, so we + // just re-encode the tag and value here. + uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; + upb_Message* unknown_msg = + field->mode & kUpb_LabelFlags_IsExtension ? d->unknown_msg : msg; + upb_Decode_AddUnknownVarints(d, unknown_msg, tag, v); + return false; +} + +UPB_FORCEINLINE +static bool decode_checkenum(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable_Enum* e, + const upb_MiniTable_Field* field, wireval* val) { + uint32_t v = val->uint32_val; + + if (UPB_LIKELY(v < 64) && UPB_LIKELY(((1ULL << v) & e->mask))) return true; + + return decode_checkenum_slow(d, ptr, msg, e, field, v); +} + +UPB_NOINLINE +static const char* decode_enum_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + if (!decode_checkenum(d, ptr, msg, e, field, val)) return ptr; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + arr->len++; + memcpy(mem, val, 4); + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_fixed_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int mask = (1 << lg2) - 1; + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { + // Length isn't a round multiple of elem size. + return decode_err(d, kUpb_DecodeStatus_Malformed); + } + decode_reserve(d, arr, count); + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + arr->len += count; + // Note: if/when the decoder supports multi-buffer input, we will need to + // handle buffer seams here. + if (_upb_IsLittleEndian()) { + memcpy(mem, ptr, val->size); + ptr += val->size; + } else { + const char* end = ptr + val->size; + char* dst = mem; + while (ptr < end) { + if (lg2 == 2) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + memcpy(dst, &val, sizeof(val)); + } else { + UPB_ASSERT(lg2 == 3); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + memcpy(dst, &val, sizeof(val)); + } + ptr += 1 << lg2; + dst += 1 << lg2; + } + } + + return ptr; +} + +UPB_FORCEINLINE +static const char* decode_varint_packed(upb_Decoder* d, const char* ptr, + upb_Array* arr, wireval* val, + const upb_MiniTable_Field* field, + int lg2) { + int scale = 1 << lg2; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge(field->descriptortype, &elem); + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void); + } + arr->len++; + memcpy(out, &elem, scale); + out += scale; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +UPB_NOINLINE +static const char* decode_enum_packed(upb_Decoder* d, const char* ptr, + upb_Message* msg, upb_Array* arr, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; + int saved_limit = decode_pushlimit(d, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + while (!decode_isdone(d, &ptr)) { + wireval elem; + ptr = decode_varint64(d, ptr, &elem.uint64_val); + decode_munge_int32(&elem); + if (!decode_checkenum(d, ptr, msg, e, field, &elem)) { + continue; + } + if (decode_reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len * 4, void); + } + arr->len++; + memcpy(out, &elem, 4); + out += 4; + } + decode_poplimit(d, ptr, saved_limit); + return ptr; +} + +static const char* decode_toarray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val, int op) { + upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array* arr = *arrp; + void* mem; + + if (arr) { + decode_reserve(d, arr, 1); + } else { + size_t lg2 = desctype_to_elem_size_lg2[field->descriptortype]; + arr = _upb_Array_New(&d->arena, 4, lg2); + if (!arr) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + *arrp = arr; + } + + switch (op) { + case OP_SCALAR_LG2(0): + case OP_SCALAR_LG2(2): + case OP_SCALAR_LG2(3): + /* Append scalar value. */ + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void); + arr->len++; + memcpy(mem, val, 1 << op); + return ptr; + case OP_STRING: + decode_verifyutf8(d, ptr, val->size); + /* Fallthrough. */ + case OP_BYTES: { + /* Append bytes. */ + upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->len; + arr->len++; + return decode_readstr(d, ptr, val->size, str); + } + case OP_SUBMSG: { + /* Append submessage / group. */ + upb_Message* submsg = decode_newsubmsg(d, subs, field); + *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void*), upb_Message*) = + submsg; + arr->len++; + if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) { + return decode_togroup(d, ptr, submsg, subs, field); + } else { + return decode_tosubmsg(d, ptr, submsg, subs, field, val->size); + } + } + case OP_FIXPCK_LG2(2): + case OP_FIXPCK_LG2(3): + return decode_fixed_packed(d, ptr, arr, val, field, + op - OP_FIXPCK_LG2(0)); + case OP_VARPCK_LG2(0): + case OP_VARPCK_LG2(2): + case OP_VARPCK_LG2(3): + return decode_varint_packed(d, ptr, arr, val, field, + op - OP_VARPCK_LG2(0)); + case OP_ENUM: + return decode_enum_toarray(d, ptr, msg, arr, subs, field, val); + case OP_PACKED_ENUM: + return decode_enum_packed(d, ptr, msg, arr, subs, field, val); + default: + UPB_UNREACHABLE(); + } +} + +static const char* decode_tomap(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, + wireval* val) { + upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map* map = *map_p; + upb_MapEntry ent; + const upb_MiniTable* entry = subs[field->submsg_index].submsg; + + if (!map) { + /* Lazily create map. */ + const upb_MiniTable_Field* key_field = &entry->fields[0]; + const upb_MiniTable_Field* val_field = &entry->fields[1]; + char key_size = desctype_to_mapsize[key_field->descriptortype]; + char val_size = desctype_to_mapsize[val_field->descriptortype]; + UPB_ASSERT(key_field->offset == 0); + UPB_ASSERT(val_field->offset == sizeof(upb_StringView)); + map = _upb_Map_New(&d->arena, key_size, val_size); + *map_p = map; + } + + /* Parse map entry. */ + memset(&ent, 0, sizeof(ent)); + + if (entry->fields[1].descriptortype == kUpb_FieldType_Message || + entry->fields[1].descriptortype == kUpb_FieldType_Group) { + /* Create proactively to handle the case where it doesn't appear. */ + ent.v.val = + upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); + } + + const char* start = ptr; + ptr = decode_tosubmsg(d, ptr, &ent.k, subs, field, val->size); + // check if ent had any unknown fields + size_t size; + upb_Message_GetUnknown(&ent.k, &size); + if (size != 0) { + uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited; + upb_Decode_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start)); + if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } else { + if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size, + &d->arena) == _kUpb_MapInsertStatus_OutOfMemory) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } + return ptr; +} + +static const char* decode_tomsg(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field, wireval* val, + int op) { + void* mem = UPB_PTR_AT(msg, field->offset, void); + int type = field->descriptortype; + + if (UPB_UNLIKELY(op == OP_ENUM) && + !decode_checkenum(d, ptr, msg, subs[field->submsg_index].subenum, field, + val)) { + return ptr; + } + + /* Set presence if necessary. */ + if (field->presence > 0) { + _upb_sethas_field(msg, field); + } else if (field->presence < 0) { + /* Oneof case */ + uint32_t* oneof_case = _upb_oneofcase_field(msg, field); + if (op == OP_SUBMSG && *oneof_case != field->number) { + memset(mem, 0, sizeof(void*)); + } + *oneof_case = field->number; + } + + /* Store into message. */ + switch (op) { + case OP_SUBMSG: { + upb_Message** submsgp = mem; + upb_Message* submsg = *submsgp; + if (!submsg) { + submsg = decode_newsubmsg(d, subs, field); + *submsgp = submsg; + } + if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { + ptr = decode_togroup(d, ptr, submsg, subs, field); + } else { + ptr = decode_tosubmsg(d, ptr, submsg, subs, field, val->size); + } + break; + } + case OP_STRING: + decode_verifyutf8(d, ptr, val->size); + /* Fallthrough. */ + case OP_BYTES: + return decode_readstr(d, ptr, val->size, mem); + case OP_SCALAR_LG2(3): + memcpy(mem, val, 8); + break; + case OP_ENUM: + case OP_SCALAR_LG2(2): + memcpy(mem, val, 4); + break; + case OP_SCALAR_LG2(0): + memcpy(mem, val, 1); + break; + default: + UPB_UNREACHABLE(); + } + + return ptr; +} + +UPB_NOINLINE +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l) { + assert(l->required_count); + if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { + return ptr; + } + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(l) & ~msg_head) { + d->missing_required = true; + } + return ptr; +} + +UPB_FORCEINLINE +static bool decode_tryfastdispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, + const upb_MiniTable* layout) { +#if UPB_FASTTABLE + if (layout && layout->table_mask != (unsigned char)-1) { + uint16_t tag = fastdecode_loadtag(*ptr); + intptr_t table = decode_totable(layout); + *ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag); + return true; + } +#endif + return false; +} + +static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, + uint32_t tag) { + int field_number = tag >> 3; + int wire_type = tag & 7; + switch (wire_type) { + case kUpb_WireType_Varint: { + uint64_t val; + return decode_varint64(d, ptr, &val); + } + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_Delimited: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + return ptr + size; + } + case kUpb_WireType_StartGroup: + return decode_group(d, ptr, NULL, NULL, field_number); + default: + decode_err(d, kUpb_DecodeStatus_Malformed); + } +} + +enum { + kStartItemTag = ((1 << 3) | kUpb_WireType_StartGroup), + kEndItemTag = ((1 << 3) | kUpb_WireType_EndGroup), + kTypeIdTag = ((2 << 3) | kUpb_WireType_Varint), + kMessageTag = ((3 << 3) | kUpb_WireType_Delimited), +}; + +static void upb_Decoder_AddKnownMessageSetItem( + upb_Decoder* d, upb_Message* msg, const upb_MiniTable_Extension* item_mt, + const char* data, uint32_t size) { + upb_Message_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); + if (UPB_UNLIKELY(!ext)) decode_err(d, kUpb_DecodeStatus_OutOfMemory); + upb_Message* submsg = decode_newsubmsg(d, &ext->ext->sub, &ext->ext->field); + upb_DecodeStatus status = upb_Decode(data, size, submsg, item_mt->sub.submsg, + d->extreg, d->options, &d->arena); + memcpy(&ext->data, &submsg, sizeof(submsg)); + if (status != kUpb_DecodeStatus_Ok) decode_err(d, status); +} + +static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, + upb_Message* msg, + uint32_t type_id, + const char* message_data, + uint32_t message_size) { + char buf[60]; + char* ptr = buf; + ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); + ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); + ptr = upb_Decoder_EncodeVarint32(type_id, ptr); + ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); + ptr = upb_Decoder_EncodeVarint32(message_size, ptr); + char* split = ptr; + + ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); + char* end = ptr; + + if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) || + !_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) || + !_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) { + decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } +} + +static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, + const upb_MiniTable* layout, + uint32_t type_id, const char* data, + uint32_t size) { + const upb_MiniTable_Extension* item_mt = + _upb_extreg_get(d->extreg, layout, type_id); + if (item_mt) { + upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + } else { + upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + } +} + +static const char* upb_Decoder_DecodeMessageSetItem( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + uint32_t type_id = 0; + upb_StringView preserved = {NULL, 0}; + typedef enum { + kUpb_HaveId = 1 << 0, + kUpb_HavePayload = 1 << 1, + } StateMask; + StateMask state_mask = 0; + while (!decode_isdone(d, &ptr)) { + uint32_t tag; + ptr = decode_tag(d, ptr, &tag); + switch (tag) { + case kEndItemTag: + return ptr; + case kTypeIdTag: { + uint64_t tmp; + ptr = decode_varint64(d, ptr, &tmp); + if (state_mask & kUpb_HaveId) break; // Ignore dup. + state_mask |= kUpb_HaveId; + type_id = tmp; + if (state_mask & kUpb_HavePayload) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, + preserved.size); + } + break; + } + case kMessageTag: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + const char* data = ptr; + ptr += size; + if (state_mask & kUpb_HavePayload) break; // Ignore dup. + state_mask |= kUpb_HavePayload; + if (state_mask & kUpb_HaveId) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); + } else { + // Out of order, we must preserve the payload. + preserved.data = data; + preserved.size = size; + } + break; + } + default: + // We do not preserve unexpected fields inside a message set item. + ptr = upb_Decoder_SkipField(d, ptr, tag); + break; + } + } + decode_err(d, kUpb_DecodeStatus_Malformed); +} + +static const upb_MiniTable_Field* decode_findfield(upb_Decoder* d, + const upb_MiniTable* l, + uint32_t field_number, + int* last_field_index) { + static upb_MiniTable_Field none = {0, 0, 0, 0, 0, 0}; + if (l == NULL) return &none; + + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < l->dense_below) { + /* Fastest case: index into dense fields. */ + goto found; + } + + if (l->dense_below < l->field_count) { + /* Linear search non-dense fields. Resume scanning from last_field_index + * since fields are usually in order. */ + int last = *last_field_index; + for (idx = last; idx < l->field_count; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + + for (idx = l->dense_below; idx < last; idx++) { + if (l->fields[idx].number == field_number) { + goto found; + } + } + } + + if (d->extreg) { + switch (l->ext) { + case kUpb_ExtMode_Extendable: { + const upb_MiniTable_Extension* ext = + _upb_extreg_get(d->extreg, l, field_number); + if (ext) return &ext->field; + break; + } + case kUpb_ExtMode_IsMessageSet: + if (field_number == _UPB_MSGSET_ITEM) { + static upb_MiniTable_Field item = {0, 0, 0, 0, TYPE_MSGSET_ITEM, 0}; + return &item; + } + break; + } + } + + return &none; /* Unknown field. */ + +found: + UPB_ASSERT(l->fields[idx].number == field_number); + *last_field_index = idx; + return &l->fields[idx]; +} + +UPB_FORCEINLINE +static const char* decode_wireval(upb_Decoder* d, const char* ptr, + const upb_MiniTable_Field* field, + int wire_type, wireval* val, int* op) { + switch (wire_type) { + case kUpb_WireType_Varint: + ptr = decode_varint64(d, ptr, &val->uint64_val); + *op = varint_ops[field->descriptortype]; + decode_munge(field->descriptortype, val); + return ptr; + case kUpb_WireType_32Bit: + memcpy(&val->uint32_val, ptr, 4); + val->uint32_val = _upb_BigEndian_Swap32(val->uint32_val); + *op = OP_SCALAR_LG2(2); + if (((1 << field->descriptortype) & FIXED32_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 4; + case kUpb_WireType_64Bit: + memcpy(&val->uint64_val, ptr, 8); + val->uint64_val = _upb_BigEndian_Swap64(val->uint64_val); + *op = OP_SCALAR_LG2(3); + if (((1 << field->descriptortype) & FIXED64_OK_MASK) == 0) { + *op = OP_UNKNOWN; + } + return ptr + 8; + case kUpb_WireType_Delimited: { + int ndx = field->descriptortype; + if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += TYPE_COUNT; + ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); + *op = delim_ops[ndx]; + return ptr; + } + case kUpb_WireType_StartGroup: + val->uint32_val = field->number; + if (field->descriptortype == kUpb_FieldType_Group) { + *op = OP_SUBMSG; + } else if (field->descriptortype == TYPE_MSGSET_ITEM) { + *op = OP_MSGSET_ITEM; + } else { + *op = OP_UNKNOWN; + } + return ptr; + default: + break; + } + return decode_err(d, kUpb_DecodeStatus_Malformed); +} + +UPB_FORCEINLINE +static const char* decode_known(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTable* layout, + const upb_MiniTable_Field* field, int op, + wireval* val) { + const upb_MiniTable_Sub* subs = layout->subs; + uint8_t mode = field->mode; + + if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { + const upb_MiniTable_Extension* ext_layout = + (const upb_MiniTable_Extension*)field; + upb_Message_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); + if (UPB_UNLIKELY(!ext)) return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + d->unknown_msg = msg; + msg = &ext->data; + subs = &ext->ext->sub; + } + + switch (mode & kUpb_FieldMode_Mask) { + case kUpb_FieldMode_Array: + return decode_toarray(d, ptr, msg, subs, field, val, op); + case kUpb_FieldMode_Map: + return decode_tomap(d, ptr, msg, subs, field, val); + case kUpb_FieldMode_Scalar: + return decode_tomsg(d, ptr, msg, subs, field, val, op); + default: + UPB_UNREACHABLE(); + } +} + +static const char* decode_reverse_skip_varint(const char* ptr, uint32_t val) { + uint32_t seen = 0; + do { + ptr--; + seen <<= 7; + seen |= *ptr & 0x7f; + } while (seen != val); + return ptr; +} + +static const char* decode_unknown(upb_Decoder* d, const char* ptr, + upb_Message* msg, int field_number, + int wire_type, wireval val) { + if (field_number == 0) return decode_err(d, kUpb_DecodeStatus_Malformed); + + // Since unknown fields are the uncommon case, we do a little extra work here + // to walk backwards through the buffer to find the field start. This frees + // up a register in the fast paths (when the field is known), which leads to + // significant speedups in benchmarks. + const char* start = ptr; + + if (wire_type == kUpb_WireType_Delimited) ptr += val.size; + if (msg) { + switch (wire_type) { + case kUpb_WireType_Varint: + case kUpb_WireType_Delimited: + start--; + while (start[-1] & 0x80) start--; + break; + case kUpb_WireType_32Bit: + start -= 4; + break; + case kUpb_WireType_64Bit: + start -= 8; + break; + default: + break; + } + + assert(start == d->debug_valstart); + uint32_t tag = ((uint32_t)field_number << 3) | wire_type; + start = decode_reverse_skip_varint(start, tag); + assert(start == d->debug_tagstart); + + if (wire_type == kUpb_WireType_StartGroup) { + d->unknown = start; + d->unknown_msg = msg; + ptr = decode_group(d, ptr, NULL, NULL, field_number); + start = d->unknown; + d->unknown = NULL; + } + if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { + return decode_err(d, kUpb_DecodeStatus_OutOfMemory); + } + } else if (wire_type == kUpb_WireType_StartGroup) { + ptr = decode_group(d, ptr, NULL, NULL, field_number); + } + return ptr; +} + +UPB_NOINLINE +static const char* decode_msg(upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + int last_field_index = 0; + +#if UPB_FASTTABLE + // The first time we want to skip fast dispatch, because we may have just been + // invoked by the fast parser to handle a case that it bailed on. + if (!decode_isdone(d, &ptr)) goto nofast; +#endif + + while (!decode_isdone(d, &ptr)) { + uint32_t tag; + const upb_MiniTable_Field* field; + int field_number; + int wire_type; + wireval val; + int op; + + if (decode_tryfastdispatch(d, &ptr, msg, layout)) break; + +#if UPB_FASTTABLE + nofast: +#endif + +#ifndef NDEBUG + d->debug_tagstart = ptr; +#endif + + UPB_ASSERT(ptr < d->limit_ptr); + ptr = decode_tag(d, ptr, &tag); + field_number = tag >> 3; + wire_type = tag & 7; + +#ifndef NDEBUG + d->debug_valstart = ptr; +#endif + + if (wire_type == kUpb_WireType_EndGroup) { + d->end_group = field_number; + return ptr; + } + + field = decode_findfield(d, layout, field_number, &last_field_index); + ptr = decode_wireval(d, ptr, field, wire_type, &val, &op); + + if (op >= 0) { + ptr = decode_known(d, ptr, msg, layout, field, op, &val); + } else { + switch (op) { + case OP_UNKNOWN: + ptr = decode_unknown(d, ptr, msg, field_number, wire_type, val); + break; + case OP_MSGSET_ITEM: + ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); + break; + } + } + } + + return UPB_UNLIKELY(layout && layout->required_count) + ? decode_checkrequired(d, ptr, msg, layout) + : ptr; +} + +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + (void)data; + *(uint32_t*)msg |= hasbits; + return decode_msg(d, ptr, msg, decode_totablep(table)); +} + +static upb_DecodeStatus decode_top(struct upb_Decoder* d, const char* buf, + void* msg, const upb_MiniTable* l) { + if (!decode_tryfastdispatch(d, &buf, msg, l)) { + decode_msg(d, buf, msg, l); + } + if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; + if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; + return kUpb_DecodeStatus_Ok; +} + +upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena) { + upb_Decoder state; + unsigned depth = (unsigned)options >> 16; + + if (size <= 16) { + memset(&state.patch, 0, 32); + if (size) memcpy(&state.patch, buf, size); + buf = state.patch; + state.end = buf + size; + state.limit = 0; + options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf. + } else { + state.end = buf + size - 16; + state.limit = 16; + } + + state.extreg = extreg; + state.limit_ptr = state.end; + state.unknown = NULL; + state.depth = depth ? depth : 64; + state.end_group = DECODE_NOGROUP; + state.options = (uint16_t)options; + state.missing_required = false; + state.arena.head = arena->head; + state.arena.last_size = arena->last_size; + state.arena.cleanup_metadata = arena->cleanup_metadata; + state.arena.parent = arena; + + upb_DecodeStatus status = UPB_SETJMP(state.err); + if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) { + status = decode_top(&state, buf, msg, l); + } + + arena->head.ptr = state.arena.head.ptr; + arena->head.end = state.arena.head.end; + arena->cleanup_metadata = state.arena.cleanup_metadata; + return status; +} + +#undef OP_UNKNOWN +#undef OP_SKIP +#undef OP_SCALAR_LG2 +#undef OP_FIXPCK_LG2 +#undef OP_VARPCK_LG2 +#undef OP_STRING +#undef OP_BYTES +#undef OP_SUBMSG + +/** upb/encode.c ************************************************************/ +/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ + + +#include +#include + + +/* Must be last. */ + +#define UPB_PB_VARINT_MAX_LEN 10 + +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; +} + +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); +} + +typedef struct { + jmp_buf err; + upb_alloc* alloc; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; + +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; +} + +UPB_NORETURN static void encode_err(upb_encstate* e) { UPB_LONGJMP(e->err, 1); } + +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size); + + if (!new_buf) encode_err(e); + + /* We want previous data at the end, realloc() put it at the beginning. */ + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); + } + + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + + e->ptr -= bytes; +} + +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ +UPB_FORCEINLINE +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); return; } - if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = kUpb_WellKnown_Any; - } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = kUpb_WellKnown_FieldMask; - } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = kUpb_WellKnown_Duration; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = kUpb_WellKnown_Timestamp; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = kUpb_WellKnown_DoubleValue; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = kUpb_WellKnown_FloatValue; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = kUpb_WellKnown_Int64Value; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = kUpb_WellKnown_UInt64Value; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = kUpb_WellKnown_Int32Value; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = kUpb_WellKnown_UInt32Value; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = kUpb_WellKnown_BoolValue; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = kUpb_WellKnown_StringValue; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = kUpb_WellKnown_BytesValue; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = kUpb_WellKnown_Value; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = kUpb_WellKnown_ListValue; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = kUpb_WellKnown_Struct; + + e->ptr -= bytes; +} + +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); +} + +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = _upb_BigEndian_Swap64(val); + encode_bytes(e, &val, sizeof(uint64_t)); +} + +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = _upb_BigEndian_Swap32(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} + +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; + + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; +} + +UPB_FORCEINLINE +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; } else { - m->well_known_type = kUpb_WellKnown_Unspecified; + encode_longvarint(e, val); } } -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { - return (upb_MessageDef*)&m[i]; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { - for (int i = 0; i < m->ext_range_count; i++) { - const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); - if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { - return true; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); +} + +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); +} + +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->len * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; + + if (tag || !_upb_IsLittleEndian()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap32(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = _upb_BigEndian_Swap64(val); + encode_bytes(e, &val, elem_size); + } + + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; } + } else { + encode_bytes(e, data, bytes); + } +} + +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); + +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const char* field_mem = _field_mem; + int wire_type; + +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } + + switch (f->descriptortype) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; + } + case kUpb_FieldType_Group: { + size_t size; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (submsg == NULL) { + return; + } + if (--e->depth == 0) encode_err(e); + encode_tag(e, f->number, kUpb_WireType_EndGroup); + encode_message(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; + } + case kUpb_FieldType_Message: { + size_t size; + void* submsg = *(void**)field_mem; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (submsg == NULL) { + return; + } + if (--e->depth == 0) encode_err(e); + encode_message(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; + } + default: + UPB_UNREACHABLE(); + } +#undef CASE + + encode_tag(e, f->number, wire_type); +} + +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + bool packed = f->mode & kUpb_LabelFlags_IsPacked; + size_t pre_len = e->limit - e->ptr; + + if (arr == NULL || arr->len == 0) { + return; + } + +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->len; \ + uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; + +#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) + + switch (f->descriptortype) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->len; + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (--e->depth == 0) encode_err(e); + do { + size_t size; + ptr--; + encode_tag(e, f->number, kUpb_WireType_EndGroup); + encode_message(e, *ptr, subm, &size); + encode_tag(e, f->number, kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const void* const* start = _upb_array_constptr(arr); + const void* const* ptr = start + arr->len; + const upb_MiniTable* subm = subs[f->submsg_index].submsg; + if (--e->depth == 0) encode_err(e); + do { + size_t size; + ptr--; + encode_message(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } + } +#undef VARINT_CASE + + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->number, kUpb_WireType_Delimited); + } +} + +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTable_Field* key_field = &layout->fields[0]; + const upb_MiniTable_Field* val_field = &layout->fields[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->v, layout->subs, val_field); + encode_scalar(e, &ent->k, layout->subs, key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); +} + +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_MiniTable* layout = subs[f->submsg_index].submsg; + UPB_ASSERT(layout->field_count == 2); + + if (map == NULL) return; + + if (e->options & kUpb_Encode_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map, + &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->number, layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + upb_strtable_iter i; + upb_strtable_begin(&i, &map->table); + for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { + upb_StringView key = upb_strtable_iter_key(&i); + const upb_value val = upb_strtable_iter_value(&i); + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.k, map->key_size); + _upb_map_fromvalue(val, &ent.v, map->val_size); + encode_mapentry(e, f->number, layout, &ent); + } + } +} + +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* f) { + if (f->presence == 0) { + /* Proto3 presence or map/array. */ + const void* mem = UPB_PTR_AT(msg, f->offset, void); + switch (f->mode >> kUpb_FieldRep_Shift) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } +#if UINTPTR_MAX == 0xffffffff + case kUpb_FieldRep_Pointer: +#endif + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } +#if UINTPTR_MAX != 0xffffffff + case kUpb_FieldRep_Pointer: +#endif + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + /* Proto2 presence: hasbit. */ + return _upb_hasbit_field(msg, f); + } else { + /* Field is in a oneof. */ + return _upb_getoneofcase_field(msg, f) == f->number; + } +} + +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable_Sub* subs, + const upb_MiniTable_Field* field) { + switch (upb_FieldMode_Get(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + break; + default: + UPB_UNREACHABLE(); + } +} + +/* message MessageSet { + * repeated group Item = 1 { + * required int32 type_id = 2; + * required string message = 3; + * } + * } */ +static void encode_msgset_item(upb_encstate* e, + const upb_Message_Extension* ext) { + size_t size; + encode_tag(e, 1, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size); + encode_varint(e, size); + encode_tag(e, 3, kUpb_WireType_Delimited); + encode_varint(e, ext->ext->field.number); + encode_tag(e, 2, kUpb_WireType_Varint); + encode_tag(e, 1, kUpb_WireType_StartGroup); +} + +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; + + if ((e->options & kUpb_Encode_CheckRequired) && m->required_count) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = _upb_BigEndian_Swap64(msg_head); + if (upb_MiniTable_requiredmask(m) & ~msg_head) { + encode_err(e); + } + } + + if ((e->options & kUpb_Encode_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); + + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } + } + + if (m->ext != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + if (ext_count) { + const upb_Message_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + if (UPB_UNLIKELY(m->ext == kUpb_ExtMode_IsMessageSet)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field); + } + } + } + } + + if (m->field_count) { + const upb_MiniTable_Field* f = &m->fields[m->field_count]; + const upb_MiniTable_Field* first = &m->fields[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->subs, f)) { + encode_field(e, msg, m->subs, f); + } + } + } + + *size = (e->limit - e->ptr) - pre_len; +} + +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; + + e.alloc = upb_Arena_Alloc(arena); + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : 64; + e.options = options; + _upb_mapsorter_init(&e.sorter); + char* ret = NULL; + + if (UPB_SETJMP(e.err)) { + *size = 0; + ret = NULL; + } else { + encode_message(&e, msg, l, size); + *size = e.limit - e.ptr; + if (*size == 0) { + static char ch; + ret = &ch; + } else { + UPB_ASSERT(e.ptr); + ret = e.ptr; + } + } + + _upb_mapsorter_destroy(&e.sorter); + return ret; +} + +/** upb/msg.c ************************************************************/ + + +/** upb_Message ***************************************************************/ + +static const size_t overhead = sizeof(upb_Message_InternalData); + +static const upb_Message_Internal* upb_Message_Getinternal_const( + const upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} + +upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a) { + return _upb_Message_New_inl(l, a); +} + +void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { + void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); + memset(mem, 0, upb_msg_sizeof(l)); +} + +static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + /* No internal data, allocate from scratch. */ + size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + /* Internal data is too small, reallocate. */ + size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + /* Need to move extension data to the end. */ + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + +bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena) { + if (!realloc_internal(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; +} + +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = overhead; + } +} + +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *len = in->internal->unknown_end - overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; + } +} + +const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(upb_Message_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +const upb_Message_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTable_Extension* e) { + size_t n; + const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); + + /* For now we use linear search exclusively to find extensions. If this + * becomes an issue due to messages with lots of extensions, we can introduce + * a table of some sort. */ + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const upb_Message_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(upb_Message_Extension); + } +} + +upb_Message_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { + upb_Message_Extension* ext = + (upb_Message_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(upb_Message_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(upb_Message_Extension)); + ext->ext = e; + return ext; +} + +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + _upb_Message_Getexts(msg, &count); + return count; +} + +/** upb_Array *****************************************************************/ + +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena) { + size_t new_size = UPB_MAX(arr->size, 4); + int elem_size_lg2 = arr->data & 7; + size_t old_bytes = arr->size << elem_size_lg2; + size_t new_bytes; + void* ptr = _upb_array_ptr(arr); + + /* Log2 ceiling of size. */ + while (new_size < min_size) new_size *= 2; + + new_bytes = new_size << elem_size_lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + + if (!ptr) { + return false; + } + + arr->data = _upb_tag_arrptr(ptr, elem_size_lg2); + arr->size = new_size; + return true; +} + +static upb_Array* getorcreate_array(upb_Array** arr_ptr, int elem_size_lg2, + upb_Arena* arena) { + upb_Array* arr = *arr_ptr; + if (!arr) { + arr = _upb_Array_New(arena, 4, elem_size_lg2); + if (!arr) return NULL; + *arr_ptr = arr; + } + return arr; +} + +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); + return arr && _upb_Array_Resize(arr, size, arena) ? _upb_array_ptr(arr) + : NULL; +} + +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena) { + upb_Array* arr = getorcreate_array(arr_ptr, elem_size_lg2, arena); + if (!arr) return false; + + size_t elems = arr->len; + + if (!_upb_Array_Resize(arr, elems + 1, arena)) { + return false; + } + + char* data = _upb_array_ptr(arr); + memcpy(data + (elems << elem_size_lg2), value, 1 << elem_size_lg2); + return true; +} + +/** upb_Map *******************************************************************/ + +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); + + if (!map) { + return NULL; + } + + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; + + return map; +} + +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); +} + +#define UPB_COMPARE_INTEGERS(a, b) ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1)) + +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return UPB_COMPARE_INTEGERS(a, b); +} + +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return UPB_COMPARE_INTEGERS(a.size, b.size); +} + +#undef UPB_COMPARE_INTEGERS + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + map_size; + + /* Grow s->entries if necessary. */ + if (sorted->end > s->cap) { + s->cap = _upb_Log2CeilingSize(sorted->end); + s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); + if (!s->entries) return false; + } + + s->size = sorted->end; + + /* Copy non-empty entries from the table to s->entries. */ + upb_tabent const** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; + } + } + UPB_ASSERT(dst == &s->entries[sorted->end]); + + /* Sort entries according to the key type. */ + + int (*compar)(const void*, const void*); + + switch (key_type) { + case kUpb_FieldType_Int64: + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_SInt64: + compar = _upb_mapsorter_cmpi64; + break; + case kUpb_FieldType_UInt64: + case kUpb_FieldType_Fixed64: + compar = _upb_mapsorter_cmpu64; + break; + case kUpb_FieldType_Int32: + case kUpb_FieldType_SInt32: + case kUpb_FieldType_SFixed32: + case kUpb_FieldType_Enum: + compar = _upb_mapsorter_cmpi32; + break; + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Fixed32: + compar = _upb_mapsorter_cmpu32; + break; + case kUpb_FieldType_Bool: + compar = _upb_mapsorter_cmpbool; + break; + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: + compar = _upb_mapsorter_cmpstr; + break; + default: + UPB_UNREACHABLE(); + } + + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), compar); + return true; +} + +/** upb_ExtensionRegistry *****************************************************/ + +struct upb_ExtensionRegistry { + upb_Arena* arena; + upb_strtable exts; /* Key is upb_MiniTable* concatenated with fieldnum. */ +}; + +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) + +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +} + +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} + +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count) { + char buf[EXTREG_KEY_SIZE]; + const upb_MiniTable_Extension** start = e; + const upb_MiniTable_Extension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); + upb_value v; + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + goto failure; + } + if (!upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(ext), r->arena)) { + goto failure; + } + } + return true; + +failure: + /* Back out the entries previously added. */ + for (end = e, e = start; e < end; e++) { + const upb_MiniTable_Extension* ext = *e; + extreg_key(buf, ext->extendee, ext->field.number); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); } return false; } -const google_protobuf_MessageOptions* upb_MessageDef_Options( - const upb_MessageDef* m) { - return m->opts; -} - -bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_MessageDef_FullName(const upb_MessageDef* m) { - return m->full_name; -} - -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { - return m->file; -} - -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { - return m->containing_type; -} - -const char* upb_MessageDef_Name(const upb_MessageDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { - return upb_FileDef_Syntax(m->file); -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i) { - upb_value val; - return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) - : NULL; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); -} - -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, - upb_value v, upb_Arena* a) { - return upb_strtable_insert(&m->ntof, name, len, v, a); -} - -bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t len, - const upb_FieldDef** out_f, - const upb_OneofDef** out_o) { - upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { - return false; - } - - const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); - if (out_f) *out_f = f; - if (out_o) *out_o = o; - return f || o; /* False if this was a JSON name. */ -} - -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - const upb_FieldDef* f; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } - - f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - if (!f) f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD_JSONNAME); - - return f; -} - -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { - return m->ext_range_count; -} - -int upb_MessageDef_FieldCount(const upb_MessageDef* m) { - return m->field_count; -} - -int upb_MessageDef_OneofCount(const upb_MessageDef* m) { - return m->oneof_count; -} - -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { - return m->nested_msg_count; -} - -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { - return m->nested_enum_count; -} - -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { - return m->nested_ext_count; -} - -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { - return m->layout; -} - -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->ext_range_count); - return _upb_ExtensionRange_At(m->ext_ranges, i); -} - -const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->field_count); - return _upb_FieldDef_At(m->fields, i); -} - -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->oneof_count); - return _upb_OneofDef_At(m->oneofs, i); -} - -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_msg_count); - return &m->nested_msgs[i]; -} - -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->nested_enum_count); - return _upb_EnumDef_At(m->nested_enums, i); -} - -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_ext_count); - return _upb_FieldDef_At(m->nested_exts, i); -} - -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { - return m->well_known_type; -} - -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { - return m->in_message_set; -} - -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); -} - -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); -} - -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); -} - -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(m)); -} - -static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - if (google_protobuf_MessageOptions_message_set_wire_format(m->opts)) { - return upb_MiniTable_BuildMessageSet(kUpb_MiniTablePlatform_Native, - ctx->arena); - } - - if (upb_MessageDef_IsMapEntry(m)) { - if (m->field_count != 2) { - _upb_DefBuilder_Errf(ctx, "invalid map (%s)", m->full_name); - } - - const upb_FieldDef* f0 = upb_MessageDef_Field(m, 0); - const upb_FieldDef* f1 = upb_MessageDef_Field(m, 1); - const upb_FieldType t0 = upb_FieldDef_Type(f0); - const upb_FieldType t1 = upb_FieldDef_Type(f1); - - const bool is_proto3_enum = - (t1 == kUpb_FieldType_Enum) && !_upb_FieldDef_IsClosedEnum(f1); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f0) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(f1) == 1); - - return upb_MiniTable_BuildMapEntry( - t0, t1, is_proto3_enum, kUpb_MiniTablePlatform_Native, ctx->arena); - } - - upb_StringView desc; - bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); - size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( - desc.data, desc.size, kUpb_MiniTablePlatform_Native, ctx->arena, - scratch_data, scratch_size, ctx->status); - if (!ret) _upb_DefBuilder_FailJmp(ctx); - return ret; -} - -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), f); - } - - if (!ctx->layout) { - m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); - if (!m->layout) _upb_DefBuilder_OomErr(ctx); - } - -#ifndef NDEBUG - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MiniTable_Field* mt_f = - &m->layout->fields[_upb_FieldDef_LayoutIndex(f)]; - UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); - } -#endif - - m->in_message_set = false; - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, upb_MessageDef_FullName(m), ext); - if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && - upb_FieldDef_Label(ext) == kUpb_Label_Optional && - upb_FieldDef_MessageSubDef(ext) == m && - google_protobuf_MessageOptions_message_set_wire_format( - upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { - m->in_message_set = true; - } - } - - for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { - upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_Resolve(ctx, n); - } -} - -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f) { - const int32_t field_number = upb_FieldDef_Number(f); - - if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { - _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); - } - - const char* json_name = upb_FieldDef_JsonName(f); - const char* shortname = upb_FieldDef_Name(f); - const size_t shortnamelen = strlen(shortname); - - upb_value v = upb_value_constptr(f); - - upb_value existing_v; - if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); - } - - const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); - bool ok = - _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - if (strcmp(shortname, json_name) != 0) { - if (upb_strtable_lookup(&m->ntof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); - } - - const size_t json_size = strlen(json_name); - const upb_value json_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD_JSONNAME); - ok = _upb_MessageDef_Insert(m, json_name, json_size, json_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } - - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); - } - - ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); - - UPB_ASSERT(layout_index < m->field_count); - upb_MiniTable_Field* mt_f = - (upb_MiniTable_Field*)&m->layout->fields[layout_index]; - if (sub_m) { - if (!mt->subs) { - _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); - } - UPB_ASSERT(mt_f); - UPB_ASSERT(sub_m->layout); - upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - upb_MiniTable_SetSubEnum(mt, mt_f, _upb_EnumDef_MiniTable(sub_e)); - } - } - - for (int i = 0; i < m->nested_msg_count; i++) { - _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); - } -} - -static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { - uint64_t out = 0; - if (upb_FileDef_Syntax(m->file) == kUpb_Syntax_Proto3) { - out |= kUpb_MessageModifier_ValidateUtf8; - out |= kUpb_MessageModifier_DefaultIsPacked; - } - if (m->ext_range_count) { - out |= kUpb_MessageModifier_IsExtendable; - } - return out; -} - -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_FieldDef** sorted = NULL; - if (!m->is_sorted) { - sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = - upb_MtDataEncoder_StartMessage(&s.e, s.ptr, _upb_MessageDef_Modifiers(m)); - - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); - const upb_FieldType type = upb_FieldDef_Type(f); - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutField(&s.e, s.ptr, type, number, modifiers); - } - - for (int i = 0; i < m->oneof_count; i++) { - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartOneof(&s.e, s.ptr); - - const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); - const int field_count = upb_OneofDef_FieldCount(o); - for (int j = 0; j < field_count; j++) { - const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutOneofField(&s.e, s.ptr, number); - } - } - - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} - -static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const google_protobuf_DescriptorProto* msg_proto, - const upb_MessageDef* containing_type, - upb_MessageDef* m) { - const google_protobuf_OneofDescriptorProto* const* oneofs; - const google_protobuf_FieldDescriptorProto* const* fields; - const google_protobuf_DescriptorProto_ExtensionRange* const* ext_ranges; - size_t n_oneof, n_field, n_ext_range, n_enum, n_ext, n_msg; - upb_StringView name; - - // Must happen before _upb_DefBuilder_Add() - m->file = _upb_DefBuilder_File(ctx); - - m->containing_type = containing_type; - m->is_sorted = true; - - name = google_protobuf_DescriptorProto_name(msg_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - - m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); - - oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n_oneof); - fields = google_protobuf_DescriptorProto_field(msg_proto, &n_field); - ext_ranges = google_protobuf_DescriptorProto_extension_range(msg_proto, &n_ext_range); - - bool ok = upb_inttable_init(&m->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - if (ctx->layout) { - /* create_fielddef() below depends on this being set. */ - UPB_ASSERT(ctx->msg_count < ctx->layout->msg_count); - m->layout = ctx->layout->msgs[ctx->msg_count++]; - UPB_ASSERT(n_field == m->layout->field_count); +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, l, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); } else { - /* Allocate now (to allow cross-linking), populate later. */ - m->layout = _upb_DefBuilder_Alloc( - ctx, sizeof(*m->layout) + sizeof(_upb_FastTable_Entry)); + return NULL; } - - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m); - - m->field_count = n_field; - m->fields = - _upb_FieldDefs_New(ctx, n_field, fields, m->full_name, m, &m->is_sorted); - - m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, m); - - const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); - m->real_oneof_count = m->oneof_count - synthetic_count; - - assign_msg_wellknowntype(m); - upb_inttable_compact(&m->itof, ctx->arena); - - const google_protobuf_EnumDescriptorProto* const* enums = - google_protobuf_DescriptorProto_enum_type(msg_proto, &n_enum); - m->nested_enum_count = n_enum; - m->nested_enums = _upb_EnumDefs_New(ctx, n_enum, enums, m); - - const google_protobuf_FieldDescriptorProto* const* exts = - google_protobuf_DescriptorProto_extension(msg_proto, &n_ext); - m->nested_ext_count = n_ext; - m->nested_exts = _upb_FieldDefs_New(ctx, n_ext, exts, m->full_name, m, NULL); - - const google_protobuf_DescriptorProto* const* msgs = - google_protobuf_DescriptorProto_nested_type(msg_proto, &n_msg); - m->nested_msg_count = n_msg; - m->nested_msgs = _upb_MessageDefs_New(ctx, n_msg, msgs, m); -} - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); - - const char* name = containing_type ? containing_type->full_name - : _upb_FileDef_RawPackage(ctx->file); - - upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); - for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], containing_type, &m[i]); - } - return m; -} - - -// Must be last. - -struct upb_MethodDef { - const google_protobuf_MethodOptions* opts; - upb_ServiceDef* service; - const char* full_name; - const upb_MessageDef* input_type; - const upb_MessageDef* output_type; - int index; - bool client_streaming; - bool server_streaming; -}; - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { - return (upb_MethodDef*)&m[i]; -} - -const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { - return m->service; -} - -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m) { - return m->opts; -} - -bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { - return m->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_MethodDef_FullName(const upb_MethodDef* m) { - return m->full_name; -} - -const char* upb_MethodDef_Name(const upb_MethodDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); -} - -int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } - -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { - return m->input_type; -} - -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { - return m->output_type; -} - -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { - return m->client_streaming; -} - -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { - return m->server_streaming; -} - -static void create_method(upb_DefBuilder* ctx, - const google_protobuf_MethodDescriptorProto* method_proto, - upb_ServiceDef* s, upb_MethodDef* m) { - upb_StringView name = google_protobuf_MethodDescriptorProto_name(method_proto); - - m->service = s; - m->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); - m->client_streaming = - google_protobuf_MethodDescriptorProto_client_streaming(method_proto); - m->server_streaming = - google_protobuf_MethodDescriptorProto_server_streaming(method_proto); - m->input_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_input_type(method_proto), UPB_DEFTYPE_MSG); - m->output_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - google_protobuf_MethodDescriptorProto_output_type(method_proto), UPB_DEFTYPE_MSG); - - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); -} - -// Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s) { - upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); - for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], s, &m[i]); - m[i].index = i; - } - return m; -} - -#include -#include -#include - - -// Must be last. - -struct upb_OneofDef { - const google_protobuf_OneofOptions* opts; - const upb_MessageDef* parent; - const char* full_name; - int field_count; - bool synthetic; - const upb_FieldDef** fields; - upb_strtable ntof; // lookup a field by name - upb_inttable itof; // lookup a field by number (index) -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { - return (upb_OneofDef*)&o[i]; -} - -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o) { - return o->opts; -} - -bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { - return o->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_OneofDef_FullName(const upb_OneofDef* o) { - return o->full_name; -} - -const char* upb_OneofDef_Name(const upb_OneofDef* o) { - return _upb_DefBuilder_FullToShort(o->full_name); -} - -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { - return o->parent; -} - -int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } - -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; -} - -int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - -uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { - // Compute index in our parent's array. - return o - upb_MessageDef_Oneof(o->parent, 0); -} - -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } - -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, size, &val) - ? upb_value_getptr(val) - : NULL; -} - -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name) { - return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); -} - -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; -} - -bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, - const char* name, size_t size, upb_Arena* a) { - o->field_count++; - if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - - const int number = upb_FieldDef_Number(f); - const upb_value v = upb_value_constptr(f); - return upb_inttable_insert(&o->itof, number, v, a) && - upb_strtable_insert(&o->ntof, name, size, v, a); -} - -// Returns the synthetic count. -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { - int synthetic_count = 0; - - for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { - upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - - if (o->synthetic && o->field_count != 1) { - _upb_DefBuilder_Errf(ctx, - "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_OneofDef_Name(o)); - } - - if (o->synthetic) { - synthetic_count++; - } else if (synthetic_count != 0) { - _upb_DefBuilder_Errf( - ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_OneofDef_Name(o)); - } - - o->fields = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); - o->field_count = 0; - } - - for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); - if (o) { - o->fields[o->field_count++] = f; - } - } - - return synthetic_count; -} - -static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const google_protobuf_OneofDescriptorProto* oneof_proto, - const upb_OneofDef* _o) { - upb_OneofDef* o = (upb_OneofDef*)_o; - upb_StringView name = google_protobuf_OneofDescriptorProto_name(oneof_proto); - - o->parent = m; - o->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); - o->field_count = 0; - o->synthetic = false; - - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); - } - - upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); - bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&o->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_strtable_init(&o->ntof, 4, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} - -// Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - - upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); - for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], &o[i]); - } - return o; -} - - -// Must be last. - -struct upb_ServiceDef { - const google_protobuf_ServiceOptions* opts; - const upb_FileDef* file; - const char* full_name; - upb_MethodDef* methods; - int method_count; - int index; -}; - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { - return (upb_ServiceDef*)&s[index]; -} - -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s) { - return s->opts; -} - -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { - return s->opts != (void*)kUpbDefOptDefault; -} - -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { - return s->full_name; -} - -const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { - return _upb_DefBuilder_FullToShort(s->full_name); -} - -int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } - -const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { - return s->file; -} - -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { - return s->method_count; -} - -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { - return (i < 0 || i >= s->method_count) ? NULL - : _upb_MethodDef_At(s->methods, i); -} - -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name) { - for (int i = 0; i < s->method_count; i++) { - const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); - if (strcmp(name, upb_MethodDef_Name(m)) == 0) { - return m; - } - } - return NULL; -} - -static void create_service(upb_DefBuilder* ctx, - const google_protobuf_ServiceDescriptorProto* svc_proto, - upb_ServiceDef* s) { - upb_StringView name; - size_t n; - - // Must happen before _upb_DefBuilder_Add() - s->file = _upb_DefBuilder_File(ctx); - - name = google_protobuf_ServiceDescriptorProto_name(svc_proto); - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - const char* package = _upb_FileDef_RawPackage(s->file); - s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); - _upb_DefBuilder_Add(ctx, s->full_name, - _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); - - const google_protobuf_MethodDescriptorProto* const* methods = - google_protobuf_ServiceDescriptorProto_method(svc_proto, &n); - s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s); - - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); -} - -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos) { - _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); - - upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); - for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], &s[i]); - s[i].index = i; - } - return s; } +/** upb/table.c ************************************************************/ /* * upb_table Implementation * * Implementation is heavily inspired by Lua's ltable.c. */ - #include -// Must be last. + +/* Must be last. */ #define UPB_MAXARRSIZE 16 /* 64k. */ @@ -10126,39 +12156,66 @@ bool upb_inttable_iter_isequal(const upb_inttable_iter* i1, i1->array_part == i2->array_part; } +/** upb/upb.c ************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + // Must be last. -int upb_Unicode_ToUTF8(uint32_t cp, char* out) { - if (cp <= 0x7f) { - out[0] = cp; - return 1; - } - if (cp <= 0x07ff) { - out[0] = (cp >> 6) | 0xc0; - out[1] = (cp & 0x3f) | 0x80; - return 2; - } - if (cp <= 0xffff) { - out[0] = (cp >> 12) | 0xe0; - out[1] = ((cp >> 6) & 0x3f) | 0x80; - out[2] = (cp & 0x3f) | 0x80; - return 3; - } - if (cp <= 0x10ffff) { - out[0] = (cp >> 18) | 0xf0; - out[1] = ((cp >> 12) & 0x3f) | 0x80; - out[2] = ((cp >> 6) & 0x3f) | 0x80; - out[3] = (cp & 0x3f) | 0x80; - return 4; - } - return 0; +/* upb_Status *****************************************************************/ + +void upb_Status_Clear(upb_Status* status) { + if (!status) return; + status->ok = true; + status->msg[0] = '\0'; } +bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } -#include +const char* upb_Status_ErrorMessage(const upb_Status* status) { + return status->msg; +} -// Must be last. +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { + if (!status) return; + status->ok = false; + strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + upb_Status_VSetErrorFormat(status, fmt, args); + va_end(args); +} + +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + if (!status) return; + status->ok = false; + vsnprintf(status->msg, sizeof(status->msg), fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) { + size_t len; + if (!status) return; + status->ok = false; + len = strlen(status->msg); + vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); + status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; +} + +/* upb_alloc ******************************************************************/ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, size_t size) { @@ -10172,11 +12229,6 @@ static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, } } -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; - - -// Must be last. - static uint32_t* upb_cleanup_pointer(uintptr_t cleanup_metadata) { return (uint32_t*)(cleanup_metadata & ~0x1); } @@ -10190,6 +12242,10 @@ static uintptr_t upb_cleanup_metadata(uint32_t* cleanup, return (uintptr_t)cleanup | has_initial_block; } +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; + +/* upb_Arena ******************************************************************/ + struct mem_block { struct mem_block* next; uint32_t size; @@ -10216,24 +12272,6 @@ static upb_Arena* arena_findroot(upb_Arena* a) { return a; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = arena_findroot(arena); - size_t memsize = 0; - - mem_block* block = arena->freelist; - - while (block) { - memsize += sizeof(mem_block) + block->size; - block = block->next; - } - - return memsize; -} - -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena) { - return arena_findroot(arena)->refcount; -} - static void upb_Arena_addblock(upb_Arena* a, upb_Arena* root, void* ptr, size_t size) { mem_block* block = ptr; @@ -10278,7 +12316,7 @@ static void* upb_Arena_doalloc(upb_alloc* alloc, void* ptr, size_t oldsize, /* Public Arena API ***********************************************************/ -static upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { +upb_Arena* arena_initslow(void* mem, size_t n, upb_alloc* alloc) { const size_t first_block_overhead = sizeof(upb_Arena) + memblock_reserve; upb_Arena* a; @@ -10333,7 +12371,6 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { a->head.ptr = mem; a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); a->freelist = NULL; - a->freelist_tail = NULL; a->cleanup_metadata = upb_cleanup_metadata(NULL, true); return a; @@ -10420,2284 +12457,6 @@ bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { return true; } - -#include - -// Must be last. - -static const char _upb_CTypeo_sizelg2[12] = { - 0, - 0, /* kUpb_CType_Bool */ - 2, /* kUpb_CType_Float */ - 2, /* kUpb_CType_Int32 */ - 2, /* kUpb_CType_UInt32 */ - 2, /* kUpb_CType_Enum */ - UPB_SIZE(2, 3), /* kUpb_CType_Message */ - 3, /* kUpb_CType_Double */ - 3, /* kUpb_CType_Int64 */ - 3, /* kUpb_CType_UInt64 */ - UPB_SIZE(3, 4), /* kUpb_CType_String */ - UPB_SIZE(3, 4), /* kUpb_CType_Bytes */ -}; - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return _upb_Array_New(a, 4, _upb_CTypeo_sizelg2[type]); -} - -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - UPB_ASSERT(i < arr->size); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - if (!upb_Array_Resize(arr, arr->size + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->size - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - char* data = _upb_array_ptr(arr); - int lg2 = arr->data & 7; - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - size_t oldsize = arr->size; - if (!upb_Array_Resize(arr, arr->size + count, arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - return _upb_Array_Resize(arr, size, arena); -} - - -#include - - -// Must be last. - -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; - -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, - - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - kUpb_DecodeOp_Enum = 1, - - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, - - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; - -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; - -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); - -UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, - upb_DecodeStatus status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); -} - -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { - assert(status != kUpb_DecodeStatus_Ok); - UPB_LONGJMP(d->err, status); - return NULL; -} -static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { - if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); - } -} - -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->capacity - arr->size < elem; - if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; -} - -typedef struct { - const char* ptr; - uint64_t val; -} _upb_DecodeLongVarintReturn; - -UPB_NOINLINE -static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( - const char* ptr, uint64_t val) { - _upb_DecodeLongVarintReturn ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; - } - } - return ret; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, - uint64_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - *val = res.val; - return res.ptr; - } -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, - uint32_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - const char* start = ptr; - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *val = res.val; - return res.ptr; - } -} - -UPB_FORCEINLINE -static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { - uint64_t size64; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); - if (size64 >= INT32_MAX || ptr - d->end + (int)size64 > d->limit) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *size = size64; - return ptr; -} - -static void _upb_Decoder_MungeInt32(wireval* val) { - if (!_upb_IsLittleEndian()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; - } -} - -static void _upb_Decoder_Munge(int type, wireval* val) { - switch (type) { - case kUpb_FieldType_Bool: - val->bool_val = val->uint64_val != 0; - break; - case kUpb_FieldType_SInt32: { - uint32_t n = val->uint64_val; - val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_FieldType_SInt64: { - uint64_t n = val->uint64_val; - val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); - break; - } - case kUpb_FieldType_Int32: - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Enum: - _upb_Decoder_MungeInt32(val); - break; - } -} - -static upb_Message* _upb_Decoder_NewSubMessage( - upb_Decoder* d, const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field) { - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - UPB_ASSERT(subl); - upb_Message* msg = _upb_Message_New(subl, &d->arena); - if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return msg; -} - -UPB_NOINLINE -const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr, - int overrun) { - int status; - ptr = _upb_Decoder_IsDoneFallbackInline(d, ptr, overrun, &status); - if (ptr == NULL) _upb_Decoder_ErrorJmp(d, status); - return ptr; -} - -static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, - int size, upb_StringView* str) { - if (d->options & kUpb_DecodeOption_AliasString) { - str->data = ptr; - } else { - char* data = upb_Arena_Malloc(&d->arena, size); - if (!data) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - memcpy(data, ptr, size); - str->data = data; - } - str->size = size; - return ptr + size; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, - const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { - if (--d->depth < 0) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); - } - ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); - d->depth++; - if (d->end_group != expected_end_group) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, int size) { - int saved_delta = _upb_Decoder_PushLimit(d, ptr, size); - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - UPB_ASSERT(subl); - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); - _upb_Decoder_PopLimit(d, ptr, saved_delta); - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { - if (_upb_Decoder_IsDone(d, &ptr)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); - d->end_group = DECODE_NOGROUP; - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, - const char* ptr, - uint32_t number) { - return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownGroup( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field) { - const upb_MiniTable* subl = subs[field->submsg_index].submsg; - UPB_ASSERT(subl); - return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, field->number); -} - -static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - *(ptr++) = byte; - } while (val); - return ptr; -} - -static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, - uint32_t val1, uint32_t val2) { - char buf[20]; - char* end = buf; - end = upb_Decoder_EncodeVarint32(val1, end); - end = upb_Decoder_EncodeVarint32(val2, end); - - if (!_upb_Message_AddUnknown(msg, buf, end - buf, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } -} - -UPB_NOINLINE -static bool _upb_Decoder_CheckEnumSlow(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Enum* e, - const upb_MiniTable_Field* field, - uint32_t v) { - if (_upb_MiniTable_CheckEnumValueSlow(e, v)) return true; - - // Unrecognized enum goes into unknown fields. - // For packed fields the tag could be arbitrarily far in the past, so we - // just re-encode the tag and value here. - uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Varint; - upb_Message* unknown_msg = - field->mode & kUpb_LabelFlags_IsExtension ? d->unknown_msg : msg; - _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); - return false; -} - -UPB_FORCEINLINE -static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Enum* e, - const upb_MiniTable_Field* field, - wireval* val) { - uint32_t v = val->uint32_val; - - _kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, v); - if (UPB_LIKELY(status == _kUpb_FastEnumCheck_ValueIsInEnum)) return true; - return _upb_Decoder_CheckEnumSlow(d, ptr, msg, e, field, v); -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumArray( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val) { - const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - arr->size++; - memcpy(mem, val, 4); - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeFixedPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTable_Field* field, int lg2) { - int mask = (1 << lg2) - 1; - size_t count = val->size >> lg2; - if ((val->size & mask) != 0) { - // Length isn't a round multiple of elem size. - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - arr->size += count; - // Note: if/when the decoder supports multi-buffer input, we will need to - // handle buffer seams here. - if (_upb_IsLittleEndian()) { - memcpy(mem, ptr, val->size); - ptr += val->size; - } else { - const char* end = ptr + val->size; - char* dst = mem; - while (ptr < end) { - if (lg2 == 2) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - memcpy(dst, &val, sizeof(val)); - } else { - UPB_ASSERT(lg2 == 3); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - memcpy(dst, &val, sizeof(val)); - } - ptr += 1 << lg2; - dst += 1 << lg2; - } - } - - return ptr; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarintPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTable_Field* field, int lg2) { - int scale = 1 << lg2; - int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_Munge(field->descriptortype, &elem); - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - } - arr->size++; - memcpy(out, &elem, scale); - out += scale; - } - _upb_Decoder_PopLimit(d, ptr, saved_limit); - return ptr; -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumPacked( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val) { - const upb_MiniTable_Enum* e = subs[field->submsg_index].subenum; - int saved_limit = _upb_Decoder_PushLimit(d, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_MungeInt32(&elem); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { - continue; - } - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - } - arr->size++; - memcpy(out, &elem, 4); - out += 4; - } - _upb_Decoder_PopLimit(d, ptr, saved_limit); - return ptr; -} - -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTable_Field* field) { - /* Maps descriptor type -> elem_size_lg2. */ - static const uint8_t kElemSizeLg2[] = { - [0] = -1, // invalid descriptor type - [kUpb_FieldType_Double] = 3, - [kUpb_FieldType_Float] = 2, - [kUpb_FieldType_Int64] = 3, - [kUpb_FieldType_UInt64] = 3, - [kUpb_FieldType_Int32] = 2, - [kUpb_FieldType_Fixed64] = 3, - [kUpb_FieldType_Fixed32] = 2, - [kUpb_FieldType_Bool] = 0, - [kUpb_FieldType_String] = UPB_SIZE(3, 4), - [kUpb_FieldType_Group] = UPB_SIZE(2, 3), - [kUpb_FieldType_Message] = UPB_SIZE(2, 3), - [kUpb_FieldType_Bytes] = UPB_SIZE(3, 4), - [kUpb_FieldType_UInt32] = 2, - [kUpb_FieldType_Enum] = 2, - [kUpb_FieldType_SFixed32] = 2, - [kUpb_FieldType_SFixed64] = 3, - [kUpb_FieldType_SInt32] = 2, - [kUpb_FieldType_SInt64] = 3, - }; - - size_t lg2 = kElemSizeLg2[field->descriptortype]; - upb_Array* ret = _upb_Array_New(&d->arena, 4, lg2); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field, - wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); - upb_Array* arr = *arrp; - void* mem; - - if (arr) { - _upb_Decoder_Reserve(d, arr, 1); - } else { - arr = _upb_Decoder_CreateArray(d, field); - *arrp = arr; - } - - switch (op) { - case kUpb_DecodeOp_Scalar1Byte: - case kUpb_DecodeOp_Scalar4Byte: - case kUpb_DecodeOp_Scalar8Byte: - /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << op, void); - arr->size++; - memcpy(mem, val, 1 << op); - return ptr; - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: { - /* Append bytes. */ - upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size; - arr->size++; - return _upb_Decoder_ReadString(d, ptr, val->size, str); - } - case kUpb_DecodeOp_SubMessage: { - /* Append submessage / group. */ - upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field); - *UPB_PTR_AT(_upb_array_ptr(arr), arr->size * sizeof(void*), - upb_Message*) = submsg; - arr->size++; - if (UPB_UNLIKELY(field->descriptortype == kUpb_FieldType_Group)) { - return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - } - case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): - return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, - op - OP_FIXPCK_LG2(0)); - case OP_VARPCK_LG2(0): - case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): - return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, - op - OP_VARPCK_LG2(0)); - case kUpb_DecodeOp_Enum: - return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); - case kUpb_DecodeOp_PackedEnum: - return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); - default: - UPB_UNREACHABLE(); - } -} - -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ - static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ - [kUpb_FieldType_Double] = 8, - [kUpb_FieldType_Float] = 4, - [kUpb_FieldType_Int64] = 8, - [kUpb_FieldType_UInt64] = 8, - [kUpb_FieldType_Int32] = 4, - [kUpb_FieldType_Fixed64] = 8, - [kUpb_FieldType_Fixed32] = 4, - [kUpb_FieldType_Bool] = 1, - [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_Group] = sizeof(void*), - [kUpb_FieldType_Message] = sizeof(void*), - [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_UInt32] = 4, - [kUpb_FieldType_Enum] = 4, - [kUpb_FieldType_SFixed32] = 4, - [kUpb_FieldType_SFixed64] = 8, - [kUpb_FieldType_SInt32] = 4, - [kUpb_FieldType_SInt64] = 8, - }; - - const upb_MiniTable_Field* key_field = &entry->fields[0]; - const upb_MiniTable_Field* val_field = &entry->fields[1]; - char key_size = kSizeInMap[key_field->descriptortype]; - char val_size = kSizeInMap[val_field->descriptortype]; - UPB_ASSERT(key_field->offset == 0); - UPB_ASSERT(val_field->offset == sizeof(upb_StringView)); - upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; -} - -static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field, - wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); - upb_Map* map = *map_p; - upb_MapEntry ent; - const upb_MiniTable* entry = subs[field->submsg_index].submsg; - - if (!map) { - map = _upb_Decoder_CreateMap(d, entry); - *map_p = map; - } - - /* Parse map entry. */ - memset(&ent, 0, sizeof(ent)); - - if (entry->fields[1].descriptortype == kUpb_FieldType_Message || - entry->fields[1].descriptortype == kUpb_FieldType_Group) { - /* Create proactively to handle the case where it doesn't appear. */ - ent.v.val = - upb_value_ptr(_upb_Message_New(entry->subs[0].submsg, &d->arena)); - } - - const char* start = ptr; - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, &ent.k, subs, field, val->size); - // check if ent had any unknown fields - size_t size; - upb_Message_GetUnknown(&ent.k, &size); - if (size != 0) { - uint32_t tag = ((uint32_t)field->number << 3) | kUpb_WireType_Delimited; - _upb_Decoder_AddUnknownVarints(d, msg, tag, (uint32_t)(ptr - start)); - if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else { - if (_upb_Map_Insert(map, &ent.k, map->key_size, &ent.v, map->val_size, - &d->arena) == _kUpb_MapInsertStatus_OutOfMemory) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } - return ptr; -} - -static const char* _upb_Decoder_DecodeToSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable_Sub* subs, const upb_MiniTable_Field* field, - wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->offset, void); - int type = field->descriptortype; - - if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && - !_upb_Decoder_CheckEnum(d, ptr, msg, subs[field->submsg_index].subenum, - field, val)) { - return ptr; - } - - /* Set presence if necessary. */ - if (field->presence > 0) { - _upb_sethas_field(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ - uint32_t* oneof_case = _upb_oneofcase_field(msg, field); - if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->number) { - memset(mem, 0, sizeof(void*)); - } - *oneof_case = field->number; - } - - /* Store into message. */ - switch (op) { - case kUpb_DecodeOp_SubMessage: { - upb_Message** submsgp = mem; - upb_Message* submsg = *submsgp; - if (!submsg) { - submsg = _upb_Decoder_NewSubMessage(d, subs, field); - *submsgp = submsg; - } - if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { - ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - break; - } - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: - return _upb_Decoder_ReadString(d, ptr, val->size, mem); - case kUpb_DecodeOp_Scalar8Byte: - memcpy(mem, val, 8); - break; - case kUpb_DecodeOp_Enum: - case kUpb_DecodeOp_Scalar4Byte: - memcpy(mem, val, 4); - break; - case kUpb_DecodeOp_Scalar1Byte: - memcpy(mem, val, 1); - break; - default: - UPB_UNREACHABLE(); - } - - return ptr; -} - -UPB_NOINLINE -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* l) { - assert(l->required_count); - if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { - return ptr; - } - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (upb_MiniTable_requiredmask(l) & ~msg_head) { - d->missing_required = true; - } - return ptr; -} - -UPB_FORCEINLINE -static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* layout) { -#if UPB_FASTTABLE - if (layout && layout->table_mask != (unsigned char)-1) { - uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); - intptr_t table = decode_totable(layout); - *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); - return true; - } -#endif - return false; -} - -static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, - uint32_t tag) { - int field_number = tag >> 3; - int wire_type = tag & 7; - switch (wire_type) { - case kUpb_WireType_Varint: { - uint64_t val; - return _upb_Decoder_DecodeVarint(d, ptr, &val); - } - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_Delimited: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - return ptr + size; - } - case kUpb_WireType_StartGroup: - return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - default: - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } -} - -enum { - kStartItemTag = ((1 << 3) | kUpb_WireType_StartGroup), - kEndItemTag = ((1 << 3) | kUpb_WireType_EndGroup), - kTypeIdTag = ((2 << 3) | kUpb_WireType_Varint), - kMessageTag = ((3 << 3) | kUpb_WireType_Delimited), -}; - -static void upb_Decoder_AddKnownMessageSetItem( - upb_Decoder* d, upb_Message* msg, const upb_MiniTable_Extension* item_mt, - const char* data, uint32_t size) { - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - upb_Message* submsg = - _upb_Decoder_NewSubMessage(d, &ext->ext->sub, &ext->ext->field); - upb_DecodeStatus status = upb_Decode(data, size, submsg, item_mt->sub.submsg, - d->extreg, d->options, &d->arena); - memcpy(&ext->data, &submsg, sizeof(submsg)); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); -} - -static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, - upb_Message* msg, - uint32_t type_id, - const char* message_data, - uint32_t message_size) { - char buf[60]; - char* ptr = buf; - ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); - ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); - ptr = upb_Decoder_EncodeVarint32(type_id, ptr); - ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); - ptr = upb_Decoder_EncodeVarint32(message_size, ptr); - char* split = ptr; - - ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); - char* end = ptr; - - if (!_upb_Message_AddUnknown(msg, buf, split - buf, &d->arena) || - !_upb_Message_AddUnknown(msg, message_data, message_size, &d->arena) || - !_upb_Message_AddUnknown(msg, split, end - split, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } -} - -static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* t, - uint32_t type_id, const char* data, - uint32_t size) { - const upb_MiniTable_Extension* item_mt = - upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); - if (item_mt) { - upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); - } else { - upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); - } -} - -static const char* upb_Decoder_DecodeMessageSetItem( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout) { - uint32_t type_id = 0; - upb_StringView preserved = {NULL, 0}; - typedef enum { - kUpb_HaveId = 1 << 0, - kUpb_HavePayload = 1 << 1, - } StateMask; - StateMask state_mask = 0; - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - switch (tag) { - case kEndItemTag: - return ptr; - case kTypeIdTag: { - uint64_t tmp; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); - if (state_mask & kUpb_HaveId) break; // Ignore dup. - state_mask |= kUpb_HaveId; - type_id = tmp; - if (state_mask & kUpb_HavePayload) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, - preserved.size); - } - break; - } - case kMessageTag: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - const char* data = ptr; - ptr += size; - if (state_mask & kUpb_HavePayload) break; // Ignore dup. - state_mask |= kUpb_HavePayload; - if (state_mask & kUpb_HaveId) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); - } else { - // Out of order, we must preserve the payload. - preserved.data = data; - preserved.size = size; - } - break; - } - default: - // We do not preserve unexpected fields inside a message set item. - ptr = upb_Decoder_SkipField(d, ptr, tag); - break; - } - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} - -static const upb_MiniTable_Field* _upb_Decoder_FindField( - upb_Decoder* d, const upb_MiniTable* t, uint32_t field_number, - int* last_field_index) { - static upb_MiniTable_Field none = { - 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - if (t == NULL) return &none; - - size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < t->dense_below) { - /* Fastest case: index into dense fields. */ - goto found; - } - - if (t->dense_below < t->field_count) { - /* Linear search non-dense fields. Resume scanning from last_field_index - * since fields are usually in order. */ - int last = *last_field_index; - for (idx = last; idx < t->field_count; idx++) { - if (t->fields[idx].number == field_number) { - goto found; - } - } - - for (idx = t->dense_below; idx < last; idx++) { - if (t->fields[idx].number == field_number) { - goto found; - } - } - } - - if (d->extreg) { - switch (t->ext) { - case kUpb_ExtMode_Extendable: { - const upb_MiniTable_Extension* ext = - upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); - if (ext) return &ext->field; - break; - } - case kUpb_ExtMode_IsMessageSet: - if (field_number == _UPB_MSGSET_ITEM) { - static upb_MiniTable_Field item = { - 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; - return &item; - } - break; - } - } - - return &none; /* Unknown field. */ - -found: - UPB_ASSERT(t->fields[idx].number == field_number); - *last_field_index = idx; - return &t->fields[idx]; -} - -int _upb_Decoder_GetVarintOp(const upb_MiniTable_Field* field) { - static const int8_t kVarintOps[] = { - [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, - [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - }; - - return kVarintOps[field->descriptortype]; -} - -int _upb_Decoder_GetDelimitedOp(const upb_MiniTable* mt, - const upb_MiniTable_Field* field) { - enum { kRepeatedBase = 19 }; - - static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ - [kUpb_FakeFieldType_FieldNotFound] = - kUpb_DecodeOp_UnknownField, // Field not found. - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ - [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), - [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, - [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), - // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a - // repeated msgset type - }; - - int ndx = field->descriptortype; - if (upb_FieldMode_Get(field) == kUpb_FieldMode_Array) ndx += kRepeatedBase; - int op = kDelimitedOps[ndx]; - - // If sub-message is not linked, treat as unknown. - if (op == kUpb_DecodeOp_SubMessage && - !(field->mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTable_Sub* sub = &mt->subs[field->submsg_index]; - if (!sub->submsg) { - op = kUpb_DecodeOp_UnknownField; - } - } - - return op; -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeWireValue( - upb_Decoder* d, const char* ptr, const upb_MiniTable* mt, - const upb_MiniTable_Field* field, int wire_type, wireval* val, int* op) { - static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | - (1 << kUpb_FieldType_Fixed32) | - (1 << kUpb_FieldType_SFixed32); - - static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Fixed64) | - (1 << kUpb_FieldType_SFixed64); - - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); - *op = _upb_Decoder_GetVarintOp(field); - _upb_Decoder_Munge(field->descriptortype, val); - return ptr; - case kUpb_WireType_32Bit: - memcpy(&val->uint32_val, ptr, 4); - val->uint32_val = _upb_BigEndian_Swap32(val->uint32_val); - *op = kUpb_DecodeOp_Scalar4Byte; - if (((1 << field->descriptortype) & kFixed32OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr + 4; - case kUpb_WireType_64Bit: - memcpy(&val->uint64_val, ptr, 8); - val->uint64_val = _upb_BigEndian_Swap64(val->uint64_val); - *op = kUpb_DecodeOp_Scalar8Byte; - if (((1 << field->descriptortype) & kFixed64OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr + 8; - case kUpb_WireType_Delimited: - ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); - *op = _upb_Decoder_GetDelimitedOp(mt, field); - return ptr; - case kUpb_WireType_StartGroup: - val->uint32_val = field->number; - if (field->descriptortype == kUpb_FieldType_Group) { - *op = kUpb_DecodeOp_SubMessage; - } else if (field->descriptortype == kUpb_FakeFieldType_MessageSetItem) { - *op = kUpb_DecodeOp_MessageSetItem; - } else { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr; - default: - break; - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} - -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout, const upb_MiniTable_Field* field, int op, - wireval* val) { - const upb_MiniTable_Sub* subs = layout->subs; - uint8_t mode = field->mode; - - if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTable_Extension* ext_layout = - (const upb_MiniTable_Extension*)field; - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown_msg = msg; - msg = &ext->data; - subs = &ext->ext->sub; - } - - switch (mode & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Array: - return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); - case kUpb_FieldMode_Map: - return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); - case kUpb_FieldMode_Scalar: - return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); - default: - UPB_UNREACHABLE(); - } -} - -static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, - uint32_t val) { - uint32_t seen = 0; - do { - ptr--; - seen <<= 7; - seen |= *ptr & 0x7f; - } while (seen != val); - return ptr; -} - -static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, - const char* ptr, - upb_Message* msg, - int field_number, - int wire_type, wireval val) { - if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - - // Since unknown fields are the uncommon case, we do a little extra work here - // to walk backwards through the buffer to find the field start. This frees - // up a register in the fast paths (when the field is known), which leads to - // significant speedups in benchmarks. - const char* start = ptr; - - if (wire_type == kUpb_WireType_Delimited) ptr += val.size; - if (msg) { - switch (wire_type) { - case kUpb_WireType_Varint: - case kUpb_WireType_Delimited: - start--; - while (start[-1] & 0x80) start--; - break; - case kUpb_WireType_32Bit: - start -= 4; - break; - case kUpb_WireType_64Bit: - start -= 8; - break; - default: - break; - } - - assert(start == d->debug_valstart); - uint32_t tag = ((uint32_t)field_number << 3) | wire_type; - start = _upb_Decoder_ReverseSkipVarint(start, tag); - assert(start == d->debug_tagstart); - - if (wire_type == kUpb_WireType_StartGroup) { - d->unknown = start; - d->unknown_msg = msg; - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - start = d->unknown; - d->unknown = NULL; - } - if (!_upb_Message_AddUnknown(msg, start, ptr - start, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else if (wire_type == kUpb_WireType_StartGroup) { - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - } - return ptr; -} - -UPB_NOINLINE -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout) { - int last_field_index = 0; - -#if UPB_FASTTABLE - // The first time we want to skip fast dispatch, because we may have just been - // invoked by the fast parser to handle a case that it bailed on. - if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; -#endif - - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - const upb_MiniTable_Field* field; - int field_number; - int wire_type; - wireval val; - int op; - - if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; - -#if UPB_FASTTABLE - nofast: -#endif - -#ifndef NDEBUG - d->debug_tagstart = ptr; -#endif - - UPB_ASSERT(ptr < d->limit_ptr); - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - field_number = tag >> 3; - wire_type = tag & 7; - -#ifndef NDEBUG - d->debug_valstart = ptr; -#endif - - if (wire_type == kUpb_WireType_EndGroup) { - d->end_group = field_number; - return ptr; - } - - field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); - ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, - &op); - - if (op >= 0) { - ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); - } else { - switch (op) { - case kUpb_DecodeOp_UnknownField: - ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, - wire_type, val); - break; - case kUpb_DecodeOp_MessageSetItem: - ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); - break; - } - } - } - - return UPB_UNLIKELY(layout && layout->required_count) - ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) - : ptr; -} - -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - (void)data; - *(uint32_t*)msg |= hasbits; - return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); -} - -static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, - const char* buf, void* msg, - const upb_MiniTable* l) { - if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { - _upb_Decoder_DecodeMessage(d, buf, msg, l); - } - if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; - if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; - return kUpb_DecodeStatus_Ok; -} - -upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, - const upb_MiniTable* l, - const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena) { - upb_Decoder state; - unsigned depth = (unsigned)options >> 16; - - if (size <= 16) { - memset(&state.patch, 0, 32); - if (size) memcpy(&state.patch, buf, size); - buf = state.patch; - state.end = buf + size; - state.limit = 0; - options &= ~kUpb_DecodeOption_AliasString; // Can't alias patch buf. - } else { - state.end = buf + size - 16; - state.limit = 16; - } - - state.extreg = extreg; - state.limit_ptr = state.end; - state.unknown = NULL; - state.depth = depth ? depth : 64; - state.end_group = DECODE_NOGROUP; - state.options = (uint16_t)options; - state.missing_required = false; - state.arena.head = arena->head; - state.arena.last_size = arena->last_size; - state.arena.cleanup_metadata = arena->cleanup_metadata; - state.arena.parent = arena; - - upb_DecodeStatus status = UPB_SETJMP(state.err); - if (UPB_LIKELY(status == kUpb_DecodeStatus_Ok)) { - status = _upb_Decoder_DecodeTop(&state, buf, msg, l); - } - - arena->head.ptr = state.arena.head.ptr; - arena->head.end = state.arena.head.end; - arena->cleanup_metadata = state.arena.cleanup_metadata; - return status; -} - -#undef OP_FIXPCK_LG2 -#undef OP_VARPCK_LG2 - -/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */ - - -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} - -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); -} - -typedef struct { - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; - -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; - } - return ret; -} - -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_LONGJMP(e->err, s); -} - -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - - // We want previous data at the end, realloc() put it at the beginning. - // TODO(salo): This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); - } - - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - - e->ptr -= bytes; -} - -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ -UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; - } - - e->ptr -= bytes; -} - -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); -} - -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} - -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} - -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; -} - -UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; - } else { - encode_longvarint(e, val); - } -} - -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); -} - -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->size * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; - - if (tag || !_upb_IsLittleEndian()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, elem_size); - } - - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } - } else { - encode_bytes(e, data, bytes); - } -} - -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); - -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const char* field_mem = _field_mem; - int wire_type; - -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } - - switch (f->descriptortype) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - void* submsg = *(void**)field_mem; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (submsg == NULL) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->number, kUpb_WireType_EndGroup); - encode_message(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; - } - case kUpb_FieldType_Message: { - size_t size; - void* submsg = *(void**)field_mem; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (submsg == NULL) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_message(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; - } - default: - UPB_UNREACHABLE(); - } -#undef CASE - - encode_tag(e, f->number, wire_type); -} - -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); - bool packed = f->mode & kUpb_LabelFlags_IsPacked; - size_t pre_len = e->limit - e->ptr; - - if (arr == NULL || arr->size == 0) { - return; - } - -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->size; \ - uint32_t tag = packed ? 0 : (f->number << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; - -#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type)) - - switch (f->descriptortype) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->size; - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const void* const* start = _upb_array_constptr(arr); - const void* const* ptr = start + arr->size; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->number, kUpb_WireType_EndGroup); - encode_message(e, *ptr, subm, &size); - encode_tag(e, f->number, kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const void* const* start = _upb_array_constptr(arr); - const void* const* ptr = start + arr->size; - const upb_MiniTable* subm = subs[f->submsg_index].submsg; - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_message(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; - } - } -#undef VARINT_CASE - - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->number, kUpb_WireType_Delimited); - } -} - -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTable_Field* key_field = &layout->fields[0]; - const upb_MiniTable_Field* val_field = &layout->fields[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->v, layout->subs, val_field); - encode_scalar(e, &ent->k, layout->subs, key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); -} - -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); - const upb_MiniTable* layout = subs[f->submsg_index].submsg; - UPB_ASSERT(layout->field_count == 2); - - if (map == NULL) return; - - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap(&e->sorter, layout->fields[0].descriptortype, map, - &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->number, layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - upb_strtable_iter i; - upb_strtable_begin(&i, &map->table); - for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { - upb_StringView key = upb_strtable_iter_key(&i); - const upb_value val = upb_strtable_iter_value(&i); - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.k, map->key_size); - _upb_map_fromvalue(val, &ent.v, map->val_size); - encode_mapentry(e, f->number, layout, &ent); - } - } -} - -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* f) { - if (f->presence == 0) { - /* Proto3 presence or map/array. */ - const void* mem = UPB_PTR_AT(msg, f->offset, void); - switch (f->mode >> kUpb_FieldRep_Shift) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); - } - } else if (f->presence > 0) { - /* Proto2 presence: hasbit. */ - return _upb_hasbit_field(msg, f); - } else { - /* Field is in a oneof. */ - return _upb_getoneofcase_field(msg, f) == f->number; - } -} - -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable_Sub* subs, - const upb_MiniTable_Field* field) { - switch (upb_FieldMode_Get(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); - break; - default: - UPB_UNREACHABLE(); - } -} - -/* message MessageSet { - * repeated group Item = 1 { - * required int32 type_id = 2; - * required string message = 3; - * } - * } */ -static void encode_msgset_item(upb_encstate* e, - const upb_Message_Extension* ext) { - size_t size; - encode_tag(e, 1, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, ext->ext->sub.submsg, &size); - encode_varint(e, size); - encode_tag(e, 3, kUpb_WireType_Delimited); - encode_varint(e, ext->ext->field.number); - encode_tag(e, 2, kUpb_WireType_Varint); - encode_tag(e, 1, kUpb_WireType_StartGroup); -} - -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; - - if ((e->options & kUpb_EncodeOption_CheckRequired) && m->required_count) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (upb_MiniTable_requiredmask(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } - - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); - - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } - - if (m->ext != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); - if (ext_count) { - const upb_Message_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - if (UPB_UNLIKELY(m->ext == kUpb_ExtMode_IsMessageSet)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, &ext->data, &ext->ext->sub, &ext->ext->field); - } - } - } - } - - if (m->field_count) { - const upb_MiniTable_Field* f = &m->fields[m->field_count]; - const upb_MiniTable_Field* first = &m->fields[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->subs, f)) { - encode_field(e, msg, m->subs, f); - } - } - } - - *size = (e->limit - e->ptr) - pre_len; -} - -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; - - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : 64; - e.options = options; - _upb_mapsorter_init(&e.sorter); - - upb_EncodeStatus status = UPB_SETJMP(e.err); - - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (status == kUpb_EncodeStatus_Ok) { - encode_message(&e, msg, l, size); - *size = e.limit - e.ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(e.ptr); - *buf = e.ptr; - } - } else { - *buf = NULL; - *size = 0; - } - - _upb_mapsorter_destroy(&e.sorter); - return status; -} - - -// Must be last. - -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); -} - -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; -} - -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; -} - -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + map_size; - - // Grow s->entries if necessary. - if (sorted->end > s->cap) { - s->cap = _upb_Log2CeilingSize(sorted->end); - s->entries = realloc(s->entries, s->cap * sizeof(*s->entries)); - if (!s->entries) return false; - } - - s->size = sorted->end; - - // Copy non-empty entries from the table to s->entries. - upb_tabent const** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; - } - } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} - - -#include - - -// Must be last. - -/** upb_Message ***************************************************************/ - -static const size_t overhead = sizeof(upb_Message_InternalData); - -static const upb_Message_Internal* upb_Message_Getinternal_const( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -upb_Message* upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - return _upb_Message_New(mini_table, arena); -} - -void _upb_Message_Clear(upb_Message* msg, const upb_MiniTable* l) { - void* mem = UPB_PTR_AT(msg, -sizeof(upb_Message_Internal), char); - memset(mem, 0, upb_msg_sizeof(l)); -} - -static bool realloc_internal(upb_Message* msg, size_t need, upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - /* No internal data, allocate from scratch. */ - size_t size = UPB_MAX(128, _upb_Log2CeilingSize(need + overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - /* Internal data is too small, reallocate. */ - size_t new_size = _upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - /* Need to move extension data to the end. */ - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - -bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena) { - if (!realloc_internal(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; -} - -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = overhead; - } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *len = in->internal->unknown_end - overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; - } -} - -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); - } - in->internal->unknown_end -= len; -} - -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal_const(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTable_Extension* e) { - size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); - - /* For now we use linear search exclusively to find extensions. If this - * becomes an issue due to messages with lots of extensions, we can introduce - * a table of some sort. */ - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -void _upb_Message_Clearext(upb_Message* msg, - const upb_MiniTable_Extension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); - } -} - -upb_Message_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTable_Extension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!realloc_internal(msg, sizeof(upb_Message_Extension), arena)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); - ext->ext = e; - return ext; -} - -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - _upb_Message_Getexts(msg, &count); - return count; -} - -/** upb_Map *******************************************************************/ - -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - - if (!map) { - return NULL; - } - - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; - - return map; -} - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; - - -#include -#include -#include -#include -#include -#include - -// Must be last. - -void upb_Status_Clear(upb_Status* status) { - if (!status) return; - status->ok = true; - status->msg[0] = '\0'; -} - -bool upb_Status_IsOk(const upb_Status* status) { return status->ok; } - -const char* upb_Status_ErrorMessage(const upb_Status* status) { - return status->msg; -} - -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg) { - if (!status) return; - status->ok = false; - strncpy(status->msg, msg, _kUpb_Status_MaxMessage - 1); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - upb_Status_VSetErrorFormat(status, fmt, args); - va_end(args); -} - -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - if (!status) return; - status->ok = false; - vsnprintf(status->msg, sizeof(status->msg), fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) { - size_t len; - if (!status) return; - status->ok = false; - len = strlen(status->msg); - vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args); - status->msg[_kUpb_Status_MaxMessage - 1] = '\0'; -} - -#include -#include -#include - - -// Must be last. - /* Miscellaneous utilities ****************************************************/ static void upb_FixLocale(char* p) { @@ -12731,6 +12490,7 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { upb_FixLocale(buf); } +/** upb/port_undef.inc ************************************************************/ /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE @@ -12767,5 +12527,3 @@ void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { #undef UPB_UNPOISON_MEMORY_REGION #undef UPB_ASAN #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 -#undef UPB_DEPRECATED -#undef UPB_GNUC_MIN diff --git a/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.h b/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.h index b9572d3..54865a1 100755 --- a/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/libs/protobuf/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1,6 +1,32 @@ // Ruby is still using proto3 enum semantics for proto2 #define UPB_DISABLE_PROTO2_ENUM_CHECKING /* Amalgamated source file */ +/* + * Copyright (c) 2009-2021, Google LLC + * All rights reserved. + * + * 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 LLC 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 Google LLC 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 is where we define macros used across upb. @@ -26,25 +52,13 @@ */ #if !((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ - (defined(__cplusplus) && __cplusplus >= 201402L) || \ + (defined(__cplusplus) && __cplusplus >= 201103L) || \ (defined(_MSC_VER) && _MSC_VER >= 1900)) -#error upb requires C99 or C++14 or MSVC >= 2015. +#error upb requires C99 or C++11 or MSVC >= 2015. #endif -// Portable check for GCC minimum version: -// https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html -#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -#define UPB_GNUC_MIN(x, y) \ - (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) -#else -#define UPB_GNUC_MIN(x, y) 0 -#endif - -#include -#include -#include -#include #include +#include #if UINTPTR_MAX == 0xffffffff #define UPB_SIZE(size32, size64) size32 @@ -83,16 +97,16 @@ #define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN) #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) -/* Hints to the compiler about likely/unlikely branches. */ +// Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) -#define UPB_LIKELY(x) __builtin_expect((x),1) -#define UPB_UNLIKELY(x) __builtin_expect((x),0) +#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) +#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) #else #define UPB_LIKELY(x) (x) #define UPB_UNLIKELY(x) (x) #endif -/* Macros for function attributes on compilers that support them. */ +// Macros for function attributes on compilers that support them. #ifdef __GNUC__ #define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) #define UPB_NOINLINE __attribute__((noinline)) @@ -115,8 +129,7 @@ #define UPB_UNUSED(var) (void)var -/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. - */ +// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. #ifdef NDEBUG #ifdef __GNUC__ #define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable() @@ -218,11 +231,7 @@ #undef UPB_FASTTABLE_SUPPORTED -/* ASAN poisoning (for arena). - * If using UPB from an interpreted language like Ruby, a build of the - * interpreter compiled with ASAN enabled must be used in order to get sane and - * expected behavior. - */ +/* ASAN poisoning (for arena) *************************************************/ #if defined(__SANITIZE_ADDRESS__) #define UPB_ASAN 1 @@ -254,35 +263,40 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0 #endif -#if defined(__cplusplus) -#if defined(__clang__) || UPB_GNUC_MIN(6, 0) -// https://gcc.gnu.org/gcc-6/changes.html -#if __cplusplus >= 201402L -#define UPB_DEPRECATED [[deprecated]] -#else -#define UPB_DEPRECATED __attribute__((deprecated)) -#endif -#else -#define UPB_DEPRECATED -#endif -#else -#define UPB_DEPRECATED -#endif +/** upb/collections.h ************************************************************/ +#ifndef UPB_COLLECTIONS_H_ +#define UPB_COLLECTIONS_H_ -#ifndef UPB_INTERNAL_ARRAY_H_ -#define UPB_INTERNAL_ARRAY_H_ +/** google/protobuf/descriptor.upb.h ************************************************************//* This file was generated by upbc (the upb compiler) from the input + * file: + * + * google/protobuf/descriptor.proto + * + * Do not edit -- your changes will be discarded when the file is + * regenerated. */ + +#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ +#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ + + +/** upb/msg_internal.h ************************************************************/ +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ + +#ifndef UPB_MSG_INT_H_ +#define UPB_MSG_INT_H_ + +#include +#include #include -#ifndef UPB_ARRAY_H_ -#define UPB_ARRAY_H_ - - -#ifndef UPB_MESSAGE_VALUE_H_ -#define UPB_MESSAGE_VALUE_H_ - - +/** upb/msg.h ************************************************************/ /* * Public APIs for message operations that do not require descriptors. * These functions can be used even in build that does not want to depend on @@ -294,37 +308,97 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #ifndef UPB_MSG_H_ #define UPB_MSG_H_ +#include -#ifndef UPB_ARENA_H_ -#define UPB_ARENA_H_ +/** upb/upb.h ************************************************************/ +/* + * This file contains shared definitions that are widely used across upb. + */ + +#ifndef UPB_H_ +#define UPB_H_ + +#include +#include +#include +#include +#include #include -#ifndef UPB_ALLOC_H_ -#define UPB_ALLOC_H_ - -// Must be last. - #ifdef __cplusplus extern "C" { #endif -typedef struct upb_alloc upb_alloc; +/* upb_Status *****************************************************************/ -/* A combined `malloc()`/`free()` function. - * If `size` is 0 then the function acts like `free()`, otherwise it acts like - * `realloc()`. Only `oldsize` bytes from a previous allocation are - * preserved. */ -typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size); +#define _kUpb_Status_MaxMessage 127 + +typedef struct { + bool ok; + char msg[_kUpb_Status_MaxMessage]; /* Error message; NULL-terminated. */ +} upb_Status; + +const char* upb_Status_ErrorMessage(const upb_Status* status); +bool upb_Status_IsOk(const upb_Status* status); + +/* These are no-op if |status| is NULL. */ +void upb_Status_Clear(upb_Status* status); +void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); +void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) + UPB_PRINTF(2, 3); +void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); +void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, + va_list args) UPB_PRINTF(2, 0); + +/** upb_StringView ************************************************************/ + +typedef struct { + const char* data; + size_t size; +} upb_StringView; + +UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, + size_t size) { + upb_StringView ret; + ret.data = data; + ret.size = size; + return ret; +} + +UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { + return upb_StringView_FromDataAndSize(data, strlen(data)); +} + +UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { + return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; +} + +#define UPB_STRINGVIEW_INIT(ptr, len) \ + { ptr, len } + +#define UPB_STRINGVIEW_FORMAT "%.*s" +#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data + +/** upb_alloc *****************************************************************/ /* A upb_alloc is a possibly-stateful allocator object. * * It could either be an arena allocator (which doesn't require individual - * `free()` calls) or a regular `malloc()` (which does). The client must - * therefore free memory unless it knows that the allocator is an arena - * allocator. */ + * free() calls) or a regular malloc() (which does). The client must therefore + * free memory unless it knows that the allocator is an arena allocator. */ + +struct upb_alloc; +typedef struct upb_alloc upb_alloc; + +/* A malloc()/free() function. + * If "size" is 0 then the function acts like free(), otherwise it acts like + * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */ +typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size); + struct upb_alloc { upb_alloc_func* func; }; @@ -341,7 +415,7 @@ UPB_INLINE void* upb_realloc(upb_alloc* alloc, void* ptr, size_t oldsize, } UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) { - UPB_ASSERT(alloc); + assert(alloc); alloc->func(alloc, ptr, 0, 0); } @@ -364,18 +438,7 @@ UPB_INLINE void* upb_grealloc(void* ptr, size_t oldsize, size_t size) { UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ALLOC_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/* upb_Arena ******************************************************************/ /* upb_Arena is a specific allocator implementation that uses arena allocation. * The user provides an allocator that will be used to allocate the underlying @@ -391,6 +454,7 @@ extern "C" { typedef void upb_CleanupFunc(void* ud); +struct upb_Arena; typedef struct upb_Arena upb_Arena; typedef struct { @@ -410,8 +474,6 @@ void upb_Arena_Free(upb_Arena* a); bool upb_Arena_AddCleanup(upb_Arena* a, void* ud, upb_CleanupFunc* func); bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); void* _upb_Arena_SlowMalloc(upb_Arena* a, size_t size); -size_t upb_Arena_SpaceAllocated(upb_Arena* arena); -uint32_t upb_Arena_DebugRefCount(upb_Arena* arena); UPB_INLINE upb_alloc* upb_Arena_Alloc(upb_Arena* a) { return (upb_alloc*)a; } @@ -497,159 +559,6 @@ UPB_INLINE upb_Arena* upb_Arena_New(void) { return upb_Arena_Init(NULL, 0, &upb_alloc_global); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ARENA_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void upb_Message; - -/* For users these are opaque. They can be obtained from - * upb_MessageDef_MiniTable() but users cannot access any of the members. */ -typedef struct upb_MiniTable upb_MiniTable; - -/* Creates a new message with the given mini_table on the given arena. */ -upb_Message* upb_Message_New(const upb_MiniTable* mini_table, upb_Arena* arena); - -/* Adds unknown data (serialized protobuf data) to the given message. The data - * is copied into the message instance. */ -void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, - upb_Arena* arena); - -/* Returns a reference to the message's unknown data. */ -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); - -/* Removes partial unknown data from message. */ -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); - -/* Returns the number of extensions present in this message. */ -size_t upb_Message_ExtensionCount(const upb_Message* msg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MSG_INT_H_ */ - -#ifndef UPB_STRING_VIEW_H_ -#define UPB_STRING_VIEW_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char* data; - size_t size; -} upb_StringView; - -UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data, - size_t size) { - upb_StringView ret; - ret.data = data; - ret.size = size; - return ret; -} - -UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) { - return upb_StringView_FromDataAndSize(data, strlen(data)); -} - -UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { - return a.size == b.size && memcmp(a.data, b.data, a.size) == 0; -} - -#define UPB_STRINGVIEW_INIT(ptr, len) \ - { ptr, len } - -#define UPB_STRINGVIEW_FORMAT "%.*s" -#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_STRING_VIEW_H_ */ - -/* - * This file contains shared definitions that are widely used across upb. - */ - -#ifndef UPB_H_ -#define UPB_H_ - -#include -#include -#include -#include -#include -#include - -// TODO(b/232091617): Remove these and fix everything that breaks as a result. - -#ifndef UPB_STATUS_H_ -#define UPB_STATUS_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -#define _kUpb_Status_MaxMessage 127 - -typedef struct { - bool ok; - char msg[_kUpb_Status_MaxMessage]; /* Error message; NULL-terminated. */ -} upb_Status; - -const char* upb_Status_ErrorMessage(const upb_Status* status); -bool upb_Status_IsOk(const upb_Status* status); - -/* These are no-op if |status| is NULL. */ -void upb_Status_Clear(upb_Status* status); -void upb_Status_SetErrorMessage(upb_Status* status, const char* msg); -void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...) - UPB_PRINTF(2, 3); -void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); -void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, - va_list args) UPB_PRINTF(2, 0); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_STATUS_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// These types appear in circular references so we need to forward-declare them. -// There is no obviously good place for this so let's just put it here. -typedef struct upb_Array upb_Array; -typedef struct upb_Map upb_Map; - /* Constants ******************************************************************/ /* A list of types as they are encoded on-the-wire. */ @@ -705,11 +614,9 @@ typedef enum { kUpb_FieldType_SFixed32 = 15, kUpb_FieldType_SFixed64 = 16, kUpb_FieldType_SInt32 = 17, - kUpb_FieldType_SInt64 = 18, + kUpb_FieldType_SInt64 = 18 } upb_FieldType; -#define kUpb_FieldType_SizeOf 19 - #define kUpb_Map_Begin ((size_t)-1) UPB_INLINE bool _upb_IsLittleEndian(void) { @@ -748,400 +655,38 @@ UPB_INLINE int _upb_Log2Ceiling(int x) { UPB_INLINE int _upb_Log2CeilingSize(int x) { return 1 << _upb_Log2Ceiling(x); } + #ifdef __cplusplus } /* extern "C" */ #endif - #endif /* UPB_H_ */ -// Must be last. - #ifdef __cplusplus extern "C" { #endif -// Definitions common to both upb_Array and upb_Map. +/** upb_Message ***************************************************************/ -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const upb_Array* array_val; - const upb_Map* map_val; - const upb_Message* msg_val; - upb_StringView str_val; -} upb_MessageValue; +typedef void upb_Message; -typedef union { - upb_Array* array; - upb_Map* map; - upb_Message* msg; -} upb_MutableMessageValue; +/* For users these are opaque. They can be obtained from + * upb_MessageDef_MiniTable() but users cannot access any of the members. */ +struct upb_MiniTable; +typedef struct upb_MiniTable upb_MiniTable; -#ifdef __cplusplus -} /* extern "C" */ -#endif +/* Adds unknown data (serialized protobuf data) to the given message. The data + * is copied into the message instance. */ +void upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, + upb_Arena* arena); +/* Returns a reference to the message's unknown data. */ +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); -#endif /* UPB_MESSAGE_VALUE_H_ */ +/* Returns the number of extensions present in this message. */ +size_t upb_Message_ExtensionCount(const upb_Message* msg); -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Creates a new array on the given arena that holds elements of this type. */ -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -/* Returns the number of elements in the array. */ -size_t upb_Array_Size(const upb_Array* arr); - -/* Returns the given element, which must be within the array's current size. */ -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -/* Sets the given element, which must be within the array's current size. */ -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -/* Appends an element to the array. Returns false on allocation failure. */ -bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena); - -/* Moves elements within the array using memmove(). Like memmove(), the source - * and destination elements may be overlapping. */ -void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -/* Inserts one or more empty elements into the array. Existing elements are - * shifted right. The new elements have undefined state and must be set with - * `upb_Array_Set()`. - * REQUIRES: `i <= upb_Array_Size(arr)` */ -bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); - -/* Deletes one or more elements from the array. Existing elements are shifted - * left. - * REQUIRES: `i + count <= upb_Array_Size(arr)` */ -void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -/* Changes the size of a vector. New elements are initialized to empty/0. - * Returns false on allocation failure. */ -bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_ARRAY_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Our internal representation for repeated fields. */ -struct upb_Array { - uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ - size_t size; /* The number of elements in the array. */ - size_t capacity; /* Allocated storage. Measured in elements. */ -}; - -UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { - UPB_ASSERT((arr->data & 7) <= 4); - return (void*)(arr->data & ~(uintptr_t)7); -} - -UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 <= 4); - return (uintptr_t)ptr | elem_size_lg2; -} - -UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { - return (void*)_upb_array_constptr(arr); -} - -UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 <= 4); - UPB_ASSERT(((uintptr_t)ptr & 7) == 0); - return (uintptr_t)ptr | (unsigned)elem_size_lg2; -} - -UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_capacity, - int elem_size_lg2) { - const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = arr_size + (init_capacity << elem_size_lg2); - upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); - if (!arr) return NULL; - arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); - arr->size = 0; - arr->capacity = init_capacity; - return arr; -} - -/* Resizes the capacity of the array to be at least min_size. */ -bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); - -/* Fallback functions for when the accessors require a resize. */ -void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, - int elem_size_lg2, upb_Arena* arena); -bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, - int elem_size_lg2, upb_Arena* arena); - -UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, - upb_Arena* arena) { - if (arr->capacity < size) return _upb_array_realloc(arr, size, arena); - return true; -} - -UPB_INLINE bool _upb_Array_Resize(upb_Array* arr, size_t size, - upb_Arena* arena) { - if (!_upb_array_reserve(arr, size, arena)) return false; - arr->size = size; - return true; -} - -UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { - *UPB_PTR_AT(msg, ofs, upb_Array*) = NULL; -} - -UPB_INLINE const void* _upb_array_accessor(const void* msg, size_t ofs, - size_t* size) { - const upb_Array* arr = *UPB_PTR_AT(msg, ofs, const upb_Array*); - if (arr) { - if (size) *size = arr->size; - return _upb_array_constptr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE void* _upb_array_mutable_accessor(void* msg, size_t ofs, - size_t* size) { - upb_Array* arr = *UPB_PTR_AT(msg, ofs, upb_Array*); - if (arr) { - if (size) *size = arr->size; - return _upb_array_ptr(arr); - } else { - if (size) *size = 0; - return NULL; - } -} - -UPB_INLINE void* _upb_Array_Resize_accessor2(void* msg, size_t ofs, size_t size, - int elem_size_lg2, - upb_Arena* arena) { - upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); - upb_Array* arr = *arr_ptr; - if (!arr || arr->capacity < size) { - return _upb_Array_Resize_fallback(arr_ptr, size, elem_size_lg2, arena); - } - arr->size = size; - return _upb_array_ptr(arr); -} - -UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, - int elem_size_lg2, - const void* value, - upb_Arena* arena) { - upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); - size_t elem_size = 1 << elem_size_lg2; - upb_Array* arr = *arr_ptr; - void* ptr; - if (!arr || arr->size == arr->capacity) { - return _upb_Array_Append_fallback(arr_ptr, value, elem_size_lg2, arena); - } - ptr = _upb_array_ptr(arr); - memcpy(UPB_PTR_AT(ptr, arr->size * elem_size, char), value, elem_size); - arr->size++; - return true; -} - -/* Used by old generated code, remove once all code has been regenerated. */ -UPB_INLINE int _upb_sizelg2(upb_CType type) { - switch (type) { - case kUpb_CType_Bool: - return 0; - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - return 2; - case kUpb_CType_Message: - return UPB_SIZE(2, 3); - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return 3; - case kUpb_CType_String: - case kUpb_CType_Bytes: - return UPB_SIZE(3, 4); - } - UPB_UNREACHABLE(); -} - -UPB_INLINE void* _upb_Array_Resize_accessor(void* msg, size_t ofs, size_t size, - upb_CType type, upb_Arena* arena) { - return _upb_Array_Resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); -} - -UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, - size_t elem_size, upb_CType type, - const void* value, - upb_Arena* arena) { - (void)elem_size; - return _upb_Array_Append_accessor2(msg, ofs, _upb_sizelg2(type), value, - arena); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ARRAY_H_ */ - -#ifndef UPB_INTERNAL_ATOI_H_ -#define UPB_INTERNAL_ATOI_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// We use these hand-written routines instead of strto[u]l() because the "long -// long" variants aren't in c89. Also our version allows setting a ptr limit. -// Return the new position of the pointer after parsing the int, or NULL on -// integer overflow. - -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val); -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ATOI_H_ */ - -#ifndef UPB_MAP_H_ -#define UPB_MAP_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -/* Creates a new map on the given arena with the given key/value size. */ -upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type); - -/* Returns the number of entries in the map. */ -size_t upb_Map_Size(const upb_Map* map); - -/* Stores a value for the given key into |*val| (or the zero value if the key is - * not present). Returns whether the key was present. The |val| pointer may be - * NULL, in which case the function tests whether the given key is present. */ -bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); - -/* Removes all entries in the map. */ -void upb_Map_Clear(upb_Map* map); - -typedef enum { - // LINT.IfChange - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, - // LINT.ThenChange(//depot/google3/third_party/upb/upb/msg_internal.h) -} upb_MapInsertStatus; - -/* Sets the given key to the given value, returning whether the key was inserted - * or replaced. If the key was inserted, then any existing iterators will be - * invalidated. */ -upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena); - -/* Sets the given key to the given value. Returns false if memory allocation - * failed. If the key is newly inserted, then any existing iterators will be - * invalidated. */ -UPB_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} - -/* Deletes this key from the table. Returns true if the key was present. */ -bool upb_Map_Delete(upb_Map* map, upb_MessageValue key); - -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * - * // If mutating is desired. - * upb_MapIterator_SetValue(map, iter, value2); - * } - */ - -/* Advances to the next entry. Returns false if no more entries are present. */ -bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); - -/* Returns true if the iterator still points to a valid entry, or false if the - * iterator is past the last element. It is an error to call this function with - * kUpb_Map_Begin (you must call next() at least once first). */ -bool upb_MapIterator_Done(const upb_Map* map, size_t iter); - -/* Returns the key and value for this entry of the map. */ -upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); - -/* Sets the value for this entry. The iterator must not be done, and the - * iterator must not have been initialized const. */ -void upb_MapIterator_SetValue(upb_Map* map, size_t iter, - upb_MessageValue value); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MAP_H_ */ - -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ - -#ifndef UPB_MSG_INT_H_ -#define UPB_MSG_INT_H_ - -#include -#include - - -#ifndef UPB_EXTENSION_REGISTRY_H_ -#define UPB_EXTENSION_REGISTRY_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/** upb_ExtensionRegistry *****************************************************/ /* Extension registry: a dynamic data structure that stores a map of: * (upb_MiniTable, number) -> extension info @@ -1177,32 +722,20 @@ extern "C" { * reflection do not need to populate a upb_ExtensionRegistry directly. */ +struct upb_ExtensionRegistry; typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; -typedef struct upb_MiniTable_Extension upb_MiniTable_Extension; -// Creates a upb_ExtensionRegistry in the given arena. -// The arena must outlive any use of the extreg. +/* Creates a upb_ExtensionRegistry in the given arena. The arena must outlive + * any use of the extreg. */ upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); -// Adds the given extension info for the array |e| of size |count| into the -// registry. If there are any errors, the entire array is backed out. -// The extensions must outlive the registry. -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTable_Extension** e, - size_t count); - -// Looks up the extension (if any) defined for message type |t| and field -// number |num|. Returns the extension if found, otherwise NULL. -const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num); - #ifdef __cplusplus } /* extern "C" */ #endif +#endif /* UPB_MSG_INT_H_ */ -#endif /* UPB_EXTENSION_REGISTRY_H_ */ - +/** upb/table_internal.h ************************************************************/ /* * upb_table * @@ -1222,9 +755,10 @@ const upb_MiniTable_Extension* upb_ExtensionRegistry_Lookup( * mode, we check this on insert and lookup. */ -#ifndef UPB_INTERNAL_TABLE_H_ -#define UPB_INTERNAL_TABLE_H_ +#ifndef UPB_TABLE_H_ +#define UPB_TABLE_H_ +#include #include @@ -1390,8 +924,8 @@ UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { void upb_strtable_clear(upb_strtable* t); /* Inserts the given key into the hashtable with the given value. The key must - * not already exist in the hash table. For strtables, the key is not required - * to be NULL-terminated, and the table will make an internal copy of the key. + * not already exist in the hash table. For string tables, the key must be + * NULL-terminated, and the table will make an internal copy of the key. * Inttables must not insert a value of UINTPTR_MAX. * * If a table resize was required but memory allocation failed, false is @@ -1556,9 +1090,9 @@ uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); #endif -#endif /* UPB_INTERNAL_TABLE_H_ */ +#endif /* UPB_TABLE_H_ */ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -1576,9 +1110,6 @@ UPB_INLINE uint64_t _upb_UInt64_FromULL(unsigned long long v) { return (uint64_t)v; } -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; - /** upb_MiniTable *************************************************************/ /* upb_MiniTable represents the memory layout of a given upb_MessageDef. The @@ -1610,12 +1141,6 @@ typedef enum { typedef enum { kUpb_LabelFlags_IsPacked = 4, kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, } upb_LabelFlags; // Note: we sort by this number when calculating layout order. @@ -1623,9 +1148,10 @@ typedef enum { kUpb_FieldRep_1Byte = 0, kUpb_FieldRep_4Byte = 1, kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, + kUpb_FieldRep_Pointer = 3, + kUpb_FieldRep_8Byte = 4, - kUpb_FieldRep_Shift = 6, // Bit offset of the rep in upb_MiniTable_Field.mode + kUpb_FieldRep_Shift = 5, // Bit offset of the rep in upb_MiniTable_Field.mode kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, } upb_FieldRep; @@ -1656,47 +1182,11 @@ typedef struct { } _upb_FastTable_Entry; typedef struct { - uint32_t mask_limit; // Limit enum value that can be tested with mask. - uint32_t value_count; // Number of values after the bitfield. - uint32_t data[]; // Bitmask + enumerated values follow. + const int32_t* values; // List of values <0 or >63 + uint64_t mask; // Bits are set for acceptable value 0 <= x < 64 + int value_count; } upb_MiniTable_Enum; -typedef enum { - _kUpb_FastEnumCheck_ValueIsInEnum = 0, - _kUpb_FastEnumCheck_ValueIsNotInEnum = 1, - _kUpb_FastEnumCheck_CannotCheckFast = 2, -} _kUpb_FastEnumCheck_Status; - -UPB_INLINE _kUpb_FastEnumCheck_Status -_upb_MiniTable_CheckEnumValueFast(const upb_MiniTable_Enum* e, uint32_t val) { - if (UPB_UNLIKELY(val >= 64)) return _kUpb_FastEnumCheck_CannotCheckFast; - uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32); - return (mask & (1ULL << val)) ? _kUpb_FastEnumCheck_ValueIsInEnum - : _kUpb_FastEnumCheck_ValueIsNotInEnum; -} - -UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTable_Enum* e, - uint32_t val) { - if (val < e->mask_limit) return e->data[val / 32] & (1ULL << (val % 32)); - // OPT: binary search long lists? - const uint32_t* start = &e->data[e->mask_limit / 32]; - const uint32_t* limit = &e->data[(e->mask_limit / 32) + e->value_count]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e, - uint32_t val) { - _kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, val); - if (UPB_UNLIKELY(status == _kUpb_FastEnumCheck_CannotCheckFast)) { - return _upb_MiniTable_CheckEnumValueSlow(e, val); - } - return status == _kUpb_FastEnumCheck_ValueIsInEnum ? true : false; -} - typedef union { const struct upb_MiniTable* submsg; const upb_MiniTable_Enum* subenum; @@ -1745,11 +1235,11 @@ struct upb_MiniTable { _upb_FastTable_Entry fasttable[]; }; -struct upb_MiniTable_Extension { +typedef struct { upb_MiniTable_Field field; const upb_MiniTable* extendee; upb_MiniTable_Sub sub; /* NULL unless submessage or proto2 enum */ -}; +} upb_MiniTable_Extension; typedef struct { const upb_MiniTable** msgs; @@ -1772,6 +1262,21 @@ UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable* l) { return ((1ULL << n) - 1) << 1; } +/** upb_ExtensionRegistry *****************************************************/ + +/* Adds the given extension info for message type |l| and field number |num| + * into the registry. Returns false if this message type and field number were + * already in the map, or if memory allocation fails. */ +bool _upb_extreg_add(upb_ExtensionRegistry* r, + const upb_MiniTable_Extension** e, size_t count); + +/* Looks up the extension (if any) defined for message type |l| and field + * number |num|. If an extension was found, copies the field info into |*ext| + * and returns true. Otherwise returns false. */ +const upb_MiniTable_Extension* _upb_extreg_get(const upb_ExtensionRegistry* r, + const upb_MiniTable* l, + uint32_t num); + /** upb_Message ***************************************************************/ /* Internal members of a upb_Message that track unknown fields and/or @@ -1815,17 +1320,20 @@ UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* l) { return l->size + sizeof(upb_Message_Internal); } -/* Inline version upb_Message_New(), for internal use */ -UPB_INLINE upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); +UPB_INLINE upb_Message* _upb_Message_New_inl(const upb_MiniTable* l, + upb_Arena* a) { + size_t size = upb_msg_sizeof(l); + void* mem = upb_Arena_Malloc(a, size + sizeof(upb_Message_Internal)); + upb_Message* msg; if (UPB_UNLIKELY(!mem)) return NULL; - upb_Message* msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); + msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); memset(mem, 0, size); return msg; } +/* Creates a new messages with the given layout on the given arena. */ +upb_Message* _upb_Message_New(const upb_MiniTable* l, upb_Arena* a); + UPB_INLINE upb_Message_Internal* upb_Message_Getinternal(upb_Message* msg) { ptrdiff_t size = sizeof(upb_Message_Internal); return (upb_Message_Internal*)((char*)msg - size); @@ -1880,6 +1388,9 @@ const upb_Message_Extension* _upb_Message_Getext( void _upb_Message_Clearext(upb_Message* msg, const upb_MiniTable_Extension* ext); +void _upb_Message_Clearext(upb_Message* msg, + const upb_MiniTable_Extension* ext); + /** Hasbit access *************************************************************/ UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) { @@ -1943,18 +1454,174 @@ UPB_INLINE bool _upb_has_submsg_nohasbit(const upb_Message* msg, size_t ofs) { return *UPB_PTR_AT(msg, ofs, const upb_Message*) != NULL; } +/** upb_Array *****************************************************************/ + +/* Our internal representation for repeated fields. */ +typedef struct { + uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */ + size_t len; /* Measured in elements. */ + size_t size; /* Measured in elements. */ + uint64_t junk; +} upb_Array; + +UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { + UPB_ASSERT((arr->data & 7) <= 4); + return (void*)(arr->data & ~(uintptr_t)7); +} + +UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 <= 4); + return (uintptr_t)ptr | elem_size_lg2; +} + +UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { + return (void*)_upb_array_constptr(arr); +} + +UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 <= 4); + UPB_ASSERT(((uintptr_t)ptr & 7) == 0); + return (uintptr_t)ptr | (unsigned)elem_size_lg2; +} + +UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_size, + int elem_size_lg2) { + const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = arr_size + (init_size << elem_size_lg2); + upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); + if (!arr) return NULL; + arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); + arr->len = 0; + arr->size = init_size; + return arr; +} + +/* Resizes the capacity of the array to be at least min_size. */ +bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); + +/* Fallback functions for when the accessors require a resize. */ +void* _upb_Array_Resize_fallback(upb_Array** arr_ptr, size_t size, + int elem_size_lg2, upb_Arena* arena); +bool _upb_Array_Append_fallback(upb_Array** arr_ptr, const void* value, + int elem_size_lg2, upb_Arena* arena); + +UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, + upb_Arena* arena) { + if (arr->size < size) return _upb_array_realloc(arr, size, arena); + return true; +} + +UPB_INLINE bool _upb_Array_Resize(upb_Array* arr, size_t size, + upb_Arena* arena) { + if (!_upb_array_reserve(arr, size, arena)) return false; + arr->len = size; + return true; +} + +UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { + *UPB_PTR_AT(msg, ofs, upb_Array*) = NULL; +} + +UPB_INLINE const void* _upb_array_accessor(const void* msg, size_t ofs, + size_t* size) { + const upb_Array* arr = *UPB_PTR_AT(msg, ofs, const upb_Array*); + if (arr) { + if (size) *size = arr->len; + return _upb_array_constptr(arr); + } else { + if (size) *size = 0; + return NULL; + } +} + +UPB_INLINE void* _upb_array_mutable_accessor(void* msg, size_t ofs, + size_t* size) { + upb_Array* arr = *UPB_PTR_AT(msg, ofs, upb_Array*); + if (arr) { + if (size) *size = arr->len; + return _upb_array_ptr(arr); + } else { + if (size) *size = 0; + return NULL; + } +} + +UPB_INLINE void* _upb_Array_Resize_accessor2(void* msg, size_t ofs, size_t size, + int elem_size_lg2, + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); + upb_Array* arr = *arr_ptr; + if (!arr || arr->size < size) { + return _upb_Array_Resize_fallback(arr_ptr, size, elem_size_lg2, arena); + } + arr->len = size; + return _upb_array_ptr(arr); +} + +UPB_INLINE bool _upb_Array_Append_accessor2(void* msg, size_t ofs, + int elem_size_lg2, + const void* value, + upb_Arena* arena) { + upb_Array** arr_ptr = UPB_PTR_AT(msg, ofs, upb_Array*); + size_t elem_size = 1 << elem_size_lg2; + upb_Array* arr = *arr_ptr; + void* ptr; + if (!arr || arr->len == arr->size) { + return _upb_Array_Append_fallback(arr_ptr, value, elem_size_lg2, arena); + } + ptr = _upb_array_ptr(arr); + memcpy(UPB_PTR_AT(ptr, arr->len * elem_size, char), value, elem_size); + arr->len++; + return true; +} + +/* Used by old generated code, remove once all code has been regenerated. */ +UPB_INLINE int _upb_sizelg2(upb_CType type) { + switch (type) { + case kUpb_CType_Bool: + return 0; + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + return 2; + case kUpb_CType_Message: + return UPB_SIZE(2, 3); + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return 3; + case kUpb_CType_String: + case kUpb_CType_Bytes: + return UPB_SIZE(3, 4); + } + UPB_UNREACHABLE(); +} +UPB_INLINE void* _upb_Array_Resize_accessor(void* msg, size_t ofs, size_t size, + upb_CType type, upb_Arena* arena) { + return _upb_Array_Resize_accessor2(msg, ofs, size, _upb_sizelg2(type), arena); +} +UPB_INLINE bool _upb_Array_Append_accessor(void* msg, size_t ofs, + size_t elem_size, upb_CType type, + const void* value, + upb_Arena* arena) { + (void)elem_size; + return _upb_Array_Append_accessor2(msg, ofs, _upb_sizelg2(type), value, + arena); +} + /** upb_Map *******************************************************************/ /* Right now we use strmaps for everything. We'll likely want to use * integer-specific maps for integer-keyed maps.*/ -struct upb_Map { +typedef struct { /* Size of key and val, based on the map type. Strings are represented as '0' * because they must be handled specially. */ char key_size; char val_size; upb_strtable table; -}; +} upb_Map; /* Map entries aren't actually stored, they are only used during parsing. For * parsing, it helps a lot if all map entry messages have the same layout. @@ -2053,7 +1720,7 @@ typedef enum { _kUpb_MapInsertStatus_Inserted = 0, _kUpb_MapInsertStatus_Replaced = 1, _kUpb_MapInsertStatus_OutOfMemory = 2, - // LINT.ThenChange(//depot/google3/third_party/upb/upb/map.h) + // LINT.ThenChange(//depot/google3/third_party/upb/upb/collections.h) } _upb_MapInsertStatus; UPB_INLINE _upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, @@ -2161,24 +1828,61 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, } } +/** _upb_mapsorter ************************************************************/ + +/* _upb_mapsorter sorts maps and provides ordered iteration over the entries. + * Since maps can be recursive (map values can be messages which contain other + * maps). _upb_mapsorter can contain a stack of maps. */ + +typedef struct { + upb_tabent const** entries; + int size; + int cap; +} _upb_mapsorter; + +typedef struct { + int start; + int pos; + int end; +} _upb_sortedmap; + +UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { + s->entries = NULL; + s->size = 0; + s->cap = 0; +} + +UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { + if (s->entries) free(s->entries); +} + +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted); + +UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, + _upb_sortedmap* sorted) { + s->size = sorted->start; +} + +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, + _upb_sortedmap* sorted, upb_MapEntry* ent) { + if (sorted->pos == sorted->end) return false; + const upb_tabent* tabent = s->entries[sorted->pos++]; + upb_StringView key = upb_tabstrview(tabent->key); + _upb_map_fromkey(key, &ent->k, map->key_size); + upb_value val = {tabent->val.val}; + _upb_map_fromvalue(val, &ent->v, map->val_size); + return true; +} + #ifdef __cplusplus } /* extern "C" */ #endif #endif /* UPB_MSG_INT_H_ */ -/* This file was generated by upbc (the upb compiler) from the input - * file: - * - * google/protobuf/descriptor.proto - * - * Do not edit -- your changes will be discarded when the file is - * regenerated. */ - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ -#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ - +/** upb/decode.h ************************************************************/ /* * upb_decode: parsing into a upb_Message using a upb_MiniTable. */ @@ -2187,7 +1891,7 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #define UPB_DECODE_H_ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -2244,6 +1948,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #endif /* UPB_DECODE_H_ */ +/** upb/decode_fast.h ************************************************************/ // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. // @@ -2282,20 +1987,13 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #define UPB_DECODE_FAST_H_ -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - struct upb_Decoder; // The fallback, generic parsing function that can handle any field type. // This just uses the regular (non-fast) parser to parse a single field. -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data); +const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); #define UPB_PARSE_PARAMS \ struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ @@ -2375,22 +2073,18 @@ TAGBYTES(r) #undef UPB_PARSE_PARAMS -#ifdef __cplusplus -} /* extern "C" */ -#endif - - #endif /* UPB_DECODE_FAST_H_ */ +/** upb/encode.h ************************************************************/ /* - * upb_Encode: parsing from a upb_Message using a upb_MiniTable. + * upb_Encode: parsing into a upb_Message using a upb_MiniTable. */ #ifndef UPB_ENCODE_H_ #define UPB_ENCODE_H_ -// Must be last. +/* Must be last. */ #ifdef __cplusplus extern "C" { @@ -2403,35 +2097,25 @@ enum { * * If your proto contains maps, the encoder will need to malloc()/free() * memory during encode. */ - kUpb_EncodeOption_Deterministic = 1, + kUpb_Encode_Deterministic = 1, /* When set, unknown fields are not printed. */ - kUpb_EncodeOption_SkipUnknown = 2, + kUpb_Encode_SkipUnknown = 2, /* When set, the encode will fail if any required fields are missing. */ - kUpb_EncodeOption_CheckRequired = 4, + kUpb_Encode_CheckRequired = 4, }; #define UPB_ENCODE_MAXDEPTH(depth) ((depth) << 16) -typedef enum { - kUpb_EncodeStatus_Ok = 0, - kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_EncodeStatus_MaxDepthExceeded = 2, // Exceeded UPB_ENCODE_MAXDEPTH +char* upb_Encode(const void* msg, const upb_MiniTable* l, int options, + upb_Arena* arena, size_t* size); - // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. - kUpb_EncodeStatus_MissingRequired = 3, -} upb_EncodeStatus; - -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size); #ifdef __cplusplus } /* extern "C" */ #endif - #endif /* UPB_ENCODE_H_ */ @@ -2439,6 +2123,33 @@ upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, extern "C" { #endif +struct google_protobuf_FileDescriptorSet; +struct google_protobuf_FileDescriptorProto; +struct google_protobuf_DescriptorProto; +struct google_protobuf_DescriptorProto_ExtensionRange; +struct google_protobuf_DescriptorProto_ReservedRange; +struct google_protobuf_ExtensionRangeOptions; +struct google_protobuf_FieldDescriptorProto; +struct google_protobuf_OneofDescriptorProto; +struct google_protobuf_EnumDescriptorProto; +struct google_protobuf_EnumDescriptorProto_EnumReservedRange; +struct google_protobuf_EnumValueDescriptorProto; +struct google_protobuf_ServiceDescriptorProto; +struct google_protobuf_MethodDescriptorProto; +struct google_protobuf_FileOptions; +struct google_protobuf_MessageOptions; +struct google_protobuf_FieldOptions; +struct google_protobuf_OneofOptions; +struct google_protobuf_EnumOptions; +struct google_protobuf_EnumValueOptions; +struct google_protobuf_ServiceOptions; +struct google_protobuf_MethodOptions; +struct google_protobuf_UninterpretedOption; +struct google_protobuf_UninterpretedOption_NamePart; +struct google_protobuf_SourceCodeInfo; +struct google_protobuf_SourceCodeInfo_Location; +struct google_protobuf_GeneratedCodeInfo; +struct google_protobuf_GeneratedCodeInfo_Annotation; typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; @@ -2466,33 +2177,33 @@ typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; -extern const upb_MiniTable google_protobuf_FileDescriptorSet_msg_init; -extern const upb_MiniTable google_protobuf_FileDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msg_init; -extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msg_init; -extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msg_init; -extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init; -extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msg_init; -extern const upb_MiniTable google_protobuf_FileOptions_msg_init; -extern const upb_MiniTable google_protobuf_MessageOptions_msg_init; -extern const upb_MiniTable google_protobuf_FieldOptions_msg_init; -extern const upb_MiniTable google_protobuf_OneofOptions_msg_init; -extern const upb_MiniTable google_protobuf_EnumOptions_msg_init; -extern const upb_MiniTable google_protobuf_EnumValueOptions_msg_init; -extern const upb_MiniTable google_protobuf_ServiceOptions_msg_init; -extern const upb_MiniTable google_protobuf_MethodOptions_msg_init; -extern const upb_MiniTable google_protobuf_UninterpretedOption_msg_init; -extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msg_init; -extern const upb_MiniTable google_protobuf_SourceCodeInfo_msg_init; -extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init; -extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init; -extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init; +extern const upb_MiniTable google_protobuf_FileDescriptorSet_msginit; +extern const upb_MiniTable google_protobuf_FileDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ExtensionRange_msginit; +extern const upb_MiniTable google_protobuf_DescriptorProto_ReservedRange_msginit; +extern const upb_MiniTable google_protobuf_ExtensionRangeOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_OneofDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit; +extern const upb_MiniTable google_protobuf_EnumValueDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_ServiceDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_MethodDescriptorProto_msginit; +extern const upb_MiniTable google_protobuf_FileOptions_msginit; +extern const upb_MiniTable google_protobuf_MessageOptions_msginit; +extern const upb_MiniTable google_protobuf_FieldOptions_msginit; +extern const upb_MiniTable google_protobuf_OneofOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumOptions_msginit; +extern const upb_MiniTable google_protobuf_EnumValueOptions_msginit; +extern const upb_MiniTable google_protobuf_ServiceOptions_msginit; +extern const upb_MiniTable google_protobuf_MethodOptions_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_msginit; +extern const upb_MiniTable google_protobuf_UninterpretedOption_NamePart_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msginit; +extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msginit; typedef enum { google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, @@ -2539,12 +2250,6 @@ typedef enum { google_protobuf_FileOptions_LITE_RUNTIME = 3 } google_protobuf_FileOptions_OptimizeMode; -typedef enum { - google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0, - google_protobuf_GeneratedCodeInfo_Annotation_SET = 1, - google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2 -} google_protobuf_GeneratedCodeInfo_Annotation_Semantic; - typedef enum { google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0, google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1, @@ -2552,23 +2257,22 @@ typedef enum { } google_protobuf_MethodOptions_IdempotencyLevel; -extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enum_init; -extern const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enum_init; -extern const upb_MiniTable_Enum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init; -extern const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enum_init; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Label_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldDescriptorProto_Type_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_CType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FieldOptions_JSType_enuminit; +extern const upb_MiniTable_Enum google_protobuf_FileOptions_OptimizeMode_enuminit; +extern const upb_MiniTable_Enum google_protobuf_MethodOptions_IdempotencyLevel_enuminit; /* google.protobuf.FileDescriptorSet */ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google_protobuf_FileDescriptorSet_msg_init, arena); + return (google_protobuf_FileDescriptorSet*)_upb_Message_New(&google_protobuf_FileDescriptorSet_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2578,22 +2282,18 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorSet_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorSet_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorSet_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorSet_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -2612,7 +2312,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS return (google_protobuf_FileDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { - struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msg_init, arena); + struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -2621,12 +2321,12 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr /* google.protobuf.FileDescriptorProto */ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msg_init, arena); + return (google_protobuf_FileDescriptorProto*)_upb_Message_New(&google_protobuf_FileDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2636,116 +2336,110 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(4, 40)); + _upb_array_detach(msg, UPB_SIZE(20, 40)); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(4, 40), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 48)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(8, 48)); + _upb_array_detach(msg, UPB_SIZE(24, 48)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(8, 48), len); + return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 56)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 56)); + _upb_array_detach(msg, UPB_SIZE(28, 56)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 56), len); + return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 64)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 64)); + _upb_array_detach(msg, UPB_SIZE(32, 64)); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 64), len); + return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 72)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 72)); + _upb_array_detach(msg, UPB_SIZE(36, 72)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 72), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 80), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); + *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 80), const google_protobuf_FileOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 80), const google_protobuf_FileOptions*); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(28, 88), const upb_Message*) = NULL; - _upb_clearhas(msg, 4); + *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(28, 88), const google_protobuf_SourceCodeInfo*); + return *UPB_PTR_AT(msg, UPB_SIZE(44, 88), const google_protobuf_SourceCodeInfo*); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(32, 96)); + _upb_array_detach(msg, UPB_SIZE(48, 96)); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(32, 96), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(36, 104)); + _upb_array_detach(msg, UPB_SIZE(52, 104)); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(36, 104), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { return _upb_hasbit(msg, 5); @@ -2757,90 +2451,80 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(const google_pr UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(56, 112), upb_StringView); } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { - return _upb_hasbit(msg, 6); -} -UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(const google_protobuf_FileDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); - _upb_clearhas(msg, 6); -} -UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView); -} UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(48, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 40), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 40), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 40), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(3, 4), &val, arena); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 48), len); + return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 48), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 48), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 56), len); + return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 56), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 56), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 64), len); + return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len); } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 64), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_ServiceDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 64), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 64), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 64), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 72), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 72), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 72), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(24, 80), google_protobuf_FileOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 80), google_protobuf_FileOptions*) = value; } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msg_init, arena); + sub = (struct google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_options(msg, sub); } @@ -2848,53 +2532,49 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(28, 88), google_protobuf_SourceCodeInfo*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(44, 88), google_protobuf_SourceCodeInfo*) = value; } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); if (sub == NULL) { - sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msg_init, arena); + sub = (struct google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); if (!sub) return NULL; google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub); } return sub; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 96), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 96), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(48, 96), len, 2, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 96), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(48, 96), 2, &val, arena); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 104), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len); } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 104), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(52, 104), len, 2, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 104), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(52, 104), 2, &val, arena); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 5); *UPB_PTR_AT(msg, UPB_SIZE(56, 112), upb_StringView) = value; } -UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { - _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(64, 128), upb_StringView) = value; -} /* google.protobuf.DescriptorProto */ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); + return (google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2904,233 +2584,228 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(const google_protobuf_DescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(4, 24)); + _upb_array_detach(msg, UPB_SIZE(12, 24)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 32)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(8, 32)); + _upb_array_detach(msg, UPB_SIZE(16, 32)); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(8, 32), len); + return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 40)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 40)); + _upb_array_detach(msg, UPB_SIZE(20, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 40), len); + return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 48)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 48)); + _upb_array_detach(msg, UPB_SIZE(24, 48)); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(16, 48), len); + return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 56)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 56)); + _upb_array_detach(msg, UPB_SIZE(28, 56)); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 56), len); + return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(const google_protobuf_DescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 64), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); + *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 64), const google_protobuf_MessageOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_MessageOptions*); } UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 72)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(28, 72)); + _upb_array_detach(msg, UPB_SIZE(36, 72)); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(28, 72), len); + return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 80)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(32, 80)); + _upb_array_detach(msg, UPB_SIZE(40, 80)); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(32, 80), len); + return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(const google_protobuf_DescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(36, 88)); + _upb_array_detach(msg, UPB_SIZE(44, 88)); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(36, 88), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); } UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(40, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 32), len); + return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len); } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 32), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 32), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 32), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google_protobuf_DescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 32), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 40), len); + return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 40), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 40), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 48), len); + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 48), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 48), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 56), len); + return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 56), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_FieldDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 56), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(24, 64), google_protobuf_MessageOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_MessageOptions*) = value; } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msg_init, arena); + sub = (struct google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_set_options(msg, sub); } return sub; } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 72), len); + return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len); } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 72), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_OneofDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 72), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 72), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 72), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* len) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 80), len); + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(32, 80), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_DescriptorProto_ReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(40, 80), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(32, 80), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(40, 80), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 88), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len); } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(36, 88), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(44, 88), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(36, 88), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(44, 88), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.DescriptorProto.ExtensionRange */ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msg_init, arena); + return (google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3140,22 +2815,18 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ExtensionRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ExtensionRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { return _upb_hasbit(msg, 1); @@ -3182,7 +2853,6 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); @@ -3203,7 +2873,7 @@ UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(googl UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msg_init, arena); + sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); if (!sub) return NULL; google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub); } @@ -3213,12 +2883,12 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_Descrip /* google.protobuf.DescriptorProto.ReservedRange */ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_new(upb_Arena* arena) { - return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msg_init, arena); + return (google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena); } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3228,22 +2898,18 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_DescriptorProto_ReservedRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_DescriptorProto_ReservedRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { return _upb_hasbit(msg, 1); @@ -3278,12 +2944,12 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro /* google.protobuf.ExtensionRangeOptions */ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_new(upb_Arena* arena) { - return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msg_init, arena); + return (google_protobuf_ExtensionRangeOptions*)_upb_Message_New(&google_protobuf_ExtensionRangeOptions_msginit, arena); } UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3293,22 +2959,18 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ExtensionRangeOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -3327,7 +2989,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -3336,12 +2998,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension /* google.protobuf.FieldDescriptorProto */ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msg_init, arena); + return (google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google_protobuf_FieldDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3351,42 +3013,38 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FieldDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 3); @@ -3422,41 +3080,40 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 6); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 7); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 7); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 8); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 88), const upb_Message*) = NULL; - _upb_clearhas(msg, 8); + *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 88), const google_protobuf_FieldOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), const google_protobuf_FieldOptions*); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 9); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = 0; _upb_clearhas(msg, 9); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { return _upb_hasbit(msg, 10); @@ -3472,20 +3129,20 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const g return _upb_hasbit(msg, 11); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = 0; _upb_clearhas(msg, 11); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(28, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 3); @@ -3501,20 +3158,20 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 7); - *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { _upb_sethas(msg, 8); - *UPB_PTR_AT(msg, UPB_SIZE(16, 88), google_protobuf_FieldOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(56, 88), google_protobuf_FieldOptions*) = value; } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msg_init, arena); + sub = (struct google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); if (!sub) return NULL; google_protobuf_FieldDescriptorProto_set_options(msg, sub); } @@ -3522,7 +3179,7 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 9); - *UPB_PTR_AT(msg, UPB_SIZE(20, 16), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value; } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 10); @@ -3530,18 +3187,18 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protob } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { _upb_sethas(msg, 11); - *UPB_PTR_AT(msg, UPB_SIZE(24, 20), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value; } /* google.protobuf.OneofDescriptorProto */ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msg_init, arena); + return (google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google_protobuf_OneofDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3551,56 +3208,51 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_OneofDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(const google_protobuf_OneofDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(const google_protobuf_OneofDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 24), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 24), const google_protobuf_OneofOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(4, 24), google_protobuf_OneofOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = value; } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msg_init, arena); + sub = (struct google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); if (!sub) return NULL; google_protobuf_OneofDescriptorProto_set_options(msg, sub); } @@ -3610,12 +3262,12 @@ UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorP /* google.protobuf.EnumDescriptorProto */ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msg_init, arena); + return (google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3625,128 +3277,123 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(const google_protobuf_EnumDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(4, 24)); + _upb_array_detach(msg, UPB_SIZE(12, 24)); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); + return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(const google_protobuf_EnumDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const google_protobuf_EnumOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_EnumOptions*); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 40)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 40)); + _upb_array_detach(msg, UPB_SIZE(20, 40)); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(12, 40), len); + return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(16, 48)); + _upb_array_detach(msg, UPB_SIZE(24, 48)); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(16, 48), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(20, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); + return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumValueDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(8, 32), google_protobuf_EnumOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), google_protobuf_EnumOptions*) = value; } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msg_init, arena); + sub = (struct google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumDescriptorProto_set_options(msg, sub); } return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 40), len); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 40), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 40), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 40), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 40), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 48), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len); } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(16, 48), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(24, 48), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(16, 48), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(24, 48), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.EnumDescriptorProto.EnumReservedRange */ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_Arena* arena) { - return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena); } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3756,22 +3403,18 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { return _upb_hasbit(msg, 1); @@ -3806,12 +3449,12 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go /* google.protobuf.EnumValueDescriptorProto */ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msg_init, arena); + return (google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google_protobuf_EnumValueDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3821,32 +3464,28 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(const google_protobuf_EnumValueDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView); } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { return _upb_hasbit(msg, 2); @@ -3862,16 +3501,15 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const googl return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(const google_protobuf_EnumValueDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 24), const upb_Message*) = NULL; - _upb_clearhas(msg, 3); + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 24), const google_protobuf_EnumValueOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { _upb_sethas(msg, 2); @@ -3879,12 +3517,12 @@ UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_proto } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(8, 24), google_protobuf_EnumValueOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = value; } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msg_init, arena); + sub = (struct google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); if (!sub) return NULL; google_protobuf_EnumValueDescriptorProto_set_options(msg, sub); } @@ -3894,12 +3532,12 @@ UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDes /* google.protobuf.ServiceDescriptorProto */ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msg_init, arena); + return (google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google_protobuf_ServiceDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3909,77 +3547,72 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(const google_protobuf_ServiceDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 24)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(12, 24)); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(const google_protobuf_ServiceDescriptorProto* msg) { - _upb_array_detach(msg, UPB_SIZE(4, 24)); + _upb_array_detach(msg, UPB_SIZE(12, 24)); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* len) { - return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(4, 24), len); + return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(const google_protobuf_ServiceDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const upb_Message*) = NULL; - _upb_clearhas(msg, 2); + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 32), const google_protobuf_ServiceOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), const google_protobuf_ServiceOptions*); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* len) { - return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 24), len); + return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 24), len); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 24), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_MethodDescriptorProto**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { - struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 24), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(8, 32), google_protobuf_ServiceOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), google_protobuf_ServiceOptions*) = value; } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msg_init, arena); + sub = (struct google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); if (!sub) return NULL; google_protobuf_ServiceDescriptorProto_set_options(msg, sub); } @@ -3989,12 +3622,12 @@ UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescrip /* google.protobuf.MethodDescriptorProto */ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_new(upb_Arena* arena) { - return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msg_init, arena); + return (google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google_protobuf_MethodDescriptorProto_msginit, arena); } UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4004,104 +3637,99 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MethodDescriptorProto_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodDescriptorProto_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 3); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(4, 56), const upb_Message*) = NULL; - _upb_clearhas(msg, 4); + *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const upb_Message*) = NULL; } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(4, 56), const google_protobuf_MethodOptions*); + return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = 0; _upb_clearhas(msg, 5); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = 0; _upb_clearhas(msg, 6); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool); + return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(4, 56), google_protobuf_MethodOptions*) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value; } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); if (sub == NULL) { - sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msg_init, arena); + sub = (struct google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); if (!sub) return NULL; google_protobuf_MethodDescriptorProto_set_options(msg, sub); } @@ -4109,22 +3737,22 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(8, 1), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value; } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(9, 2), bool) = value; + *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value; } /* google.protobuf.FileOptions */ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Arena* arena) { - return (google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msg_init, arena); + return (google_protobuf_FileOptions*)_upb_Message_New(&google_protobuf_FileOptions_msginit, arena); } UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4134,42 +3762,38 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FileOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FileOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FileOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 3); @@ -4195,11 +3819,11 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 5); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 6); @@ -4275,51 +3899,51 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p return _upb_hasbit(msg, 13); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 13); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 14); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 14); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 15); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 15); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 16); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 16); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 17); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 17); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 18); @@ -4335,39 +3959,39 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo return _upb_hasbit(msg, 19); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 19); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { return _upb_hasbit(msg, 20); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(const google_protobuf_FileOptions* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 20); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView); } UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 184)); + return _upb_has_submsg_nohasbit(msg, UPB_SIZE(100, 184)); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(const google_protobuf_FileOptions* msg) { - _upb_array_detach(msg, UPB_SIZE(20, 184)); + _upb_array_detach(msg, UPB_SIZE(100, 184)); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* len) { - return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 184), len); + return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(100, 184), len); } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(24, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(32, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(28, 40), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { _upb_sethas(msg, 3); @@ -4379,7 +4003,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(36, 56), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 6); @@ -4411,23 +4035,23 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 13); - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(44, 72), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 14); - *UPB_PTR_AT(msg, UPB_SIZE(56, 88), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(52, 88), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 15); - *UPB_PTR_AT(msg, UPB_SIZE(64, 104), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(60, 104), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 16); - *UPB_PTR_AT(msg, UPB_SIZE(72, 120), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(68, 120), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 17); - *UPB_PTR_AT(msg, UPB_SIZE(80, 136), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(76, 136), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { _upb_sethas(msg, 18); @@ -4435,21 +4059,21 @@ UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_prot } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 19); - *UPB_PTR_AT(msg, UPB_SIZE(88, 152), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(84, 152), upb_StringView) = value; } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { _upb_sethas(msg, 20); - *UPB_PTR_AT(msg, UPB_SIZE(96, 168), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(92, 168), upb_StringView) = value; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* len) { - return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 184), len); + return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(100, 184), len); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t len, upb_Arena* arena) { - return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 184), len, UPB_SIZE(2, 3), arena); + return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(100, 184), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); - bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 184), UPB_SIZE(2, 3), &sub, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); + bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(100, 184), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; } @@ -4457,12 +4081,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio /* google.protobuf.MessageOptions */ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(upb_Arena* arena) { - return (google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msg_init, arena); + return (google_protobuf_MessageOptions*)_upb_Message_New(&google_protobuf_MessageOptions_msginit, arena); } UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4472,22 +4096,18 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MessageOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MessageOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MessageOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MessageOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { return _upb_hasbit(msg, 1); @@ -4562,7 +4182,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4571,12 +4191,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp /* google.protobuf.FieldOptions */ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Arena* arena) { - return (google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msg_init, arena); + return (google_protobuf_FieldOptions*)_upb_Message_New(&google_protobuf_FieldOptions_msginit, arena); } UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4586,22 +4206,18 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_FieldOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_FieldOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_FieldOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { return _upb_hasbit(msg, 1); @@ -4718,7 +4334,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(20, 24), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(20, 24), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4727,12 +4343,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti /* google.protobuf.OneofOptions */ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Arena* arena) { - return (google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msg_init, arena); + return (google_protobuf_OneofOptions*)_upb_Message_New(&google_protobuf_OneofOptions_msginit, arena); } UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4742,22 +4358,18 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_OneofOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_OneofOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_OneofOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -4776,7 +4388,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4785,12 +4397,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti /* google.protobuf.EnumOptions */ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msg_init, arena); + return (google_protobuf_EnumOptions*)_upb_Message_New(&google_protobuf_EnumOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4800,22 +4412,18 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { return _upb_hasbit(msg, 1); @@ -4862,7 +4470,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4871,12 +4479,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio /* google.protobuf.EnumValueOptions */ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_new(upb_Arena* arena) { - return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msg_init, arena); + return (google_protobuf_EnumValueOptions*)_upb_Message_New(&google_protobuf_EnumValueOptions_msginit, arena); } UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4886,22 +4494,18 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_EnumValueOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_EnumValueOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_EnumValueOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { return _upb_hasbit(msg, 1); @@ -4934,7 +4538,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -4943,12 +4547,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue /* google.protobuf.ServiceOptions */ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(upb_Arena* arena) { - return (google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msg_init, arena); + return (google_protobuf_ServiceOptions*)_upb_Message_New(&google_protobuf_ServiceOptions_msginit, arena); } UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4958,22 +4562,18 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_ServiceOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_ServiceOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_ServiceOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { return _upb_hasbit(msg, 1); @@ -5006,7 +4606,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5015,12 +4615,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp /* google.protobuf.MethodOptions */ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_Arena* arena) { - return (google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msg_init, arena); + return (google_protobuf_MethodOptions*)_upb_Message_New(&google_protobuf_MethodOptions_msginit, arena); } UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5030,22 +4630,18 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_MethodOptions_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodOptions_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_MethodOptions_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_MethodOptions_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { return _upb_hasbit(msg, 1); @@ -5092,7 +4688,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r return (google_protobuf_UninterpretedOption**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(8, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(8, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5101,12 +4697,12 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt /* google.protobuf.UninterpretedOption */ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msg_init, arena); + return (google_protobuf_UninterpretedOption*)_upb_Message_New(&google_protobuf_UninterpretedOption_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5116,22 +4712,18 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); @@ -5156,51 +4748,51 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t) = 0; _upb_clearhas(msg, 2); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t); + return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t) = 0; _upb_clearhas(msg, 3); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t); + return *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 4); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double) = 0; _upb_clearhas(msg, 4); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double); + return *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 5); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 5); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView); } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { return _upb_hasbit(msg, 6); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 6); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* len) { @@ -5210,7 +4802,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte return (google_protobuf_UninterpretedOption_NamePart**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 8), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { - struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msg_init, arena); + struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 8), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5221,34 +4813,34 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(16, 32), uint64_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(32, 64), uint64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(24, 40), int64_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(40, 72), int64_t) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(32, 48), double) = value; + *UPB_PTR_AT(msg, UPB_SIZE(48, 80), double) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 5); - *UPB_PTR_AT(msg, UPB_SIZE(40, 56), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 32), upb_StringView) = value; } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { _upb_sethas(msg, 6); - *UPB_PTR_AT(msg, UPB_SIZE(48, 72), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(24, 48), upb_StringView) = value; } /* google.protobuf.UninterpretedOption.NamePart */ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_new(upb_Arena* arena) { - return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msg_init, arena); + return (google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google_protobuf_UninterpretedOption_NamePart_msginit, arena); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5258,22 +4850,18 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_UninterpretedOption_NamePart_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_UninterpretedOption_NamePart_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { return _upb_hasbit(msg, 1); @@ -5308,12 +4896,12 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go /* google.protobuf.SourceCodeInfo */ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msg_init, arena); + return (google_protobuf_SourceCodeInfo*)_upb_Message_New(&google_protobuf_SourceCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5323,22 +4911,18 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -5357,7 +4941,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI return (google_protobuf_SourceCodeInfo_Location**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { - struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msg_init, arena); + struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5366,12 +4950,12 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc /* google.protobuf.SourceCodeInfo.Location */ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_new(upb_Arena* arena) { - return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msg_init, arena); + return (google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google_protobuf_SourceCodeInfo_Location_msginit, arena); } UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5381,22 +4965,18 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_SourceCodeInfo_Location_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_SourceCodeInfo_Location_msginit, options, arena, len); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(const google_protobuf_SourceCodeInfo_Location* msg) { _upb_array_detach(msg, UPB_SIZE(4, 8)); @@ -5414,27 +4994,27 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 2); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - _upb_array_detach(msg, UPB_SIZE(12, 56)); + _upb_array_detach(msg, UPB_SIZE(28, 56)); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { - return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(12, 56), len); + return (upb_StringView const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { @@ -5457,31 +5037,31 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(24, 40), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_StringView) = value; } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* len) { - return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 56), len); + return (upb_StringView*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t len, upb_Arena* arena) { - return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 56), len, UPB_SIZE(3, 4), arena); + return (upb_StringView*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(28, 56), len, UPB_SIZE(3, 4), arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 56), UPB_SIZE(3, 4), &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(28, 56), UPB_SIZE(3, 4), &val, arena); } /* google.protobuf.GeneratedCodeInfo */ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_msg_init, arena); + return (google_protobuf_GeneratedCodeInfo*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5491,22 +5071,18 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, options, arena, len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); @@ -5525,7 +5101,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_Array_Resize_accessor2(msg, UPB_SIZE(0, 0), len, UPB_SIZE(2, 3), arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { - struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msg_init, arena); + struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); bool ok = _upb_Array_Append_accessor2(msg, UPB_SIZE(0, 0), UPB_SIZE(2, 3), &sub, arena); if (!ok) return NULL; return sub; @@ -5534,12 +5110,12 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_ /* google.protobuf.GeneratedCodeInfo.Annotation */ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_new(upb_Arena* arena) { - return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msg_init, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena); } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5549,94 +5125,76 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, extreg, options, arena) != + if (upb_Decode(buf, size, ret, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, extreg, options, arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, 0, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, 0, arena, len); } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { - char* ptr; - (void)upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msg_init, options, arena, &ptr, len); - return ptr; + return upb_Encode(msg, &google_protobuf_GeneratedCodeInfo_Annotation_msginit, options, arena, len); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - _upb_array_detach(msg, UPB_SIZE(4, 16)); + _upb_array_detach(msg, UPB_SIZE(12, 16)); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(4, 16), len); + return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(12, 16), len); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 1); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = upb_StringView_FromDataAndSize(NULL, 0); _upb_clearhas(msg, 1); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView); + return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 2); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = 0; _upb_clearhas(msg, 2); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { return _upb_hasbit(msg, 3); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t) = 0; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = 0; _upb_clearhas(msg, 3); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t); -} -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return _upb_hasbit(msg, 4); -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t) = 0; - _upb_clearhas(msg, 4); -} -UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - return *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t); + return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* len) { - return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 16), len); + return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(12, 16), len); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t len, upb_Arena* arena) { - return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(4, 16), len, 2, arena); + return (int32_t*)_upb_Array_Resize_accessor2(msg, UPB_SIZE(12, 16), len, 2, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { - return _upb_Array_Append_accessor2(msg, UPB_SIZE(4, 16), 2, &val, arena); + return _upb_Array_Append_accessor2(msg, UPB_SIZE(12, 16), 2, &val, arena); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { _upb_sethas(msg, 1); - *UPB_PTR_AT(msg, UPB_SIZE(20, 24), upb_StringView) = value; + *UPB_PTR_AT(msg, UPB_SIZE(16, 24), upb_StringView) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 2); - *UPB_PTR_AT(msg, UPB_SIZE(8, 4), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { _upb_sethas(msg, 3); - *UPB_PTR_AT(msg, UPB_SIZE(12, 8), int32_t) = value; -} -UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { - _upb_sethas(msg, 4); - *UPB_PTR_AT(msg, UPB_SIZE(16, 12), int32_t) = value; + *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value; } extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout; @@ -5652,25 +5210,166 @@ extern const upb_MiniTable_File google_protobuf_descriptor_proto_upb_file_layout #endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ */ +#ifdef __cplusplus +extern "C" { +#endif + +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const upb_Map* map_val; + const upb_Message* msg_val; + const upb_Array* array_val; + upb_StringView str_val; +} upb_MessageValue; + +typedef union { + upb_Map* map; + upb_Message* msg; + upb_Array* array; +} upb_MutableMessageValue; + +/** upb_Array *****************************************************************/ + +/* Creates a new array on the given arena that holds elements of this type. */ +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); + +/* Returns the size of the array. */ +size_t upb_Array_Size(const upb_Array* arr); + +/* Returns the given element, which must be within the array's current size. */ +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); + +/* Sets the given element, which must be within the array's current size. */ +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); + +/* Appends an element to the array. Returns false on allocation failure. */ +bool upb_Array_Append(upb_Array* array, upb_MessageValue val, upb_Arena* arena); + +/* Moves elements within the array using memmove(). Like memmove(), the source + * and destination elements may be overlapping. */ +void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); + +/* Inserts one or more empty elements into the array. Existing elements are + * shifted right. The new elements have undefined state and must be set with + * `upb_Array_Set()`. + * REQUIRES: `i <= upb_Array_Size(arr)` */ +bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); + +/* Deletes one or more elements from the array. Existing elements are shifted + * left. + * REQUIRES: `i + count <= upb_Array_Size(arr)` */ +void upb_Array_Delete(upb_Array* array, size_t i, size_t count); + +/* Changes the size of a vector. New elements are initialized to empty/0. + * Returns false on allocation failure. */ +bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); + +/** upb_Map *******************************************************************/ + +/* Creates a new map on the given arena with the given key/value size. */ +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type); + +/* Returns the number of entries in the map. */ +size_t upb_Map_Size(const upb_Map* map); + +/* Stores a value for the given key into |*val| (or the zero value if the key is + * not present). Returns whether the key was present. The |val| pointer may be + * NULL, in which case the function tests whether the given key is present. */ +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +/* Removes all entries in the map. */ +void upb_Map_Clear(upb_Map* map); + +typedef enum { + // LINT.IfChange + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, + // LINT.ThenChange(//depot/google3/third_party/upb/upb/msg_internal.h) +} upb_MapInsertStatus; + +/* Sets the given key to the given value, returning whether the key was inserted + * or replaced. If the key was inserted, then any existing iterators will be + * invalidated. */ +upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena); + +/* Sets the given key to the given value. Returns false if memory allocation + * failed. If the key is newly inserted, then any existing iterators will be + * invalidated. */ +UPB_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + return upb_Map_Insert(map, key, val, arena) != + kUpb_MapInsertStatus_OutOfMemory; +} + +/* Deletes this key from the table. Returns true if the key was present. */ +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key); + +/* Map iteration: + * + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); + * + * // If mutating is desired. + * upb_MapIterator_SetValue(map, iter, value2); + * } + */ + +/* Advances to the next entry. Returns false if no more entries are present. */ +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); + +/* Returns true if the iterator still points to a valid entry, or false if the + * iterator is past the last element. It is an error to call this function with + * kUpb_Map_Begin (you must call next() at least once first). */ +bool upb_MapIterator_Done(const upb_Map* map, size_t iter); + +/* Returns the key and value for this entry of the map. */ +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); + +/* Sets the value for this entry. The iterator must not be done, and the + * iterator must not have been initialized const. */ +void upb_MapIterator_SetValue(upb_Map* map, size_t iter, + upb_MessageValue value); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_COLLECTIONS_H_ */ + +/** upb/decode_internal.h ************************************************************/ /* * Internal implementation details of the decoder that are shared between * decode.c and decode_fast.c. */ -#ifndef UPB_INTERNAL_DECODE_H_ -#define UPB_INTERNAL_DECODE_H_ +#ifndef UPB_DECODE_INT_H_ +#define UPB_DECODE_INT_H_ + +#include + +#include "third_party/utf8_range/utf8_range.h" + +/** upb/upb_internal.h ************************************************************/ +#ifndef UPB_INT_H_ +#define UPB_INT_H_ -#ifndef UPB_INTERNAL_ARENA_H_ -#define UPB_INTERNAL_ARENA_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - +struct mem_block; typedef struct mem_block mem_block; struct upb_Arena { @@ -5695,16 +5394,19 @@ struct upb_Arena { mem_block *freelist, *freelist_tail; }; -#ifdef __cplusplus -} /* extern "C" */ -#endif +// Encodes a float or double that is round-trippable, but as short as possible. +// These routines are not fully optimal (not guaranteed to be shortest), but are +// short-ish and match the implementation that has been used in protobuf since +// the beginning. +// +// The given buffer size must be at least kUpb_RoundTripBufferSize. +enum { kUpb_RoundTripBufferSize = 32 }; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); +#endif /* UPB_INT_H_ */ -#endif /* UPB_INTERNAL_ARENA_H_ */ - -#include "third_party/utf8_range/utf8_range.h" - -// Must be last. +/* Must be last. */ #define DECODE_NOGROUP (uint32_t) - 1 @@ -5737,12 +5439,12 @@ typedef struct upb_Decoder { * of our optimizations. That is also why we must declare it in a separate file, * otherwise the compiler will see that it calls longjmp() and deduce that it is * noreturn. */ -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); +const char* fastdecode_err(upb_Decoder* d, int status); extern const uint8_t upb_utf8_offsets[]; UPB_INLINE -bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { +bool decode_verifyutf8_inl(const char* ptr, int len) { const char* end = ptr + len; // Check 8 bytes at a time for any non-ASCII char. @@ -5765,9 +5467,9 @@ non_ascii: return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; } -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* l); +const char* decode_checkrequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* l); /* x86-64 pointers always have the high 16 bits matching. So we can shift * left 8 and right 8 without loss of information. */ @@ -5780,8 +5482,8 @@ UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { } UPB_INLINE -const char* _upb_Decoder_IsDoneFallbackInline(upb_Decoder* d, const char* ptr, - int overrun, int* status) { +const char* decode_isdonefallback_inl(upb_Decoder* d, const char* ptr, + int overrun, int* status) { if (overrun < d->limit) { /* Need to copy remaining data into patch buffer. */ UPB_ASSERT(overrun < 16); @@ -5808,27 +5510,26 @@ const char* _upb_Decoder_IsDoneFallbackInline(upb_Decoder* d, const char* ptr, } } -const char* _upb_Decoder_IsDoneFallback(upb_Decoder* d, const char* ptr, - int overrun); +const char* decode_isdonefallback(upb_Decoder* d, const char* ptr, int overrun); UPB_INLINE -bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { +bool decode_isdone(upb_Decoder* d, const char** ptr) { int overrun = *ptr - d->end; if (UPB_LIKELY(*ptr < d->limit_ptr)) { return false; } else if (UPB_LIKELY(overrun == d->limit)) { return true; } else { - *ptr = _upb_Decoder_IsDoneFallback(d, *ptr, overrun); + *ptr = decode_isdonefallback(d, *ptr, overrun); return false; } } #if UPB_FASTTABLE UPB_INLINE -const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { +const char* fastdecode_tagdispatch(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t tag) { const upb_MiniTable* table_p = decode_totablep(table); uint8_t mask = table; uint64_t data; @@ -5841,486 +5542,251 @@ const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, } #endif -UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { +UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) { uint16_t tag; memcpy(&tag, ptr, 2); return tag; } -UPB_INLINE void _upb_Decoder_CheckLimit(upb_Decoder* d) { +UPB_INLINE void decode_checklimit(upb_Decoder* d) { UPB_ASSERT(d->limit_ptr == d->end + UPB_MIN(0, d->limit)); } -UPB_INLINE int _upb_Decoder_PushLimit(upb_Decoder* d, const char* ptr, - int size) { +UPB_INLINE int decode_pushlimit(upb_Decoder* d, const char* ptr, int size) { int limit = size + (int)(ptr - d->end); int delta = d->limit - limit; - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); d->limit = limit; d->limit_ptr = d->end + UPB_MIN(0, limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); return delta; } -UPB_INLINE void _upb_Decoder_PopLimit(upb_Decoder* d, const char* ptr, - int saved_delta) { +UPB_INLINE void decode_poplimit(upb_Decoder* d, const char* ptr, + int saved_delta) { UPB_ASSERT(ptr - d->end == d->limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); d->limit += saved_delta; d->limit_ptr = d->end + UPB_MIN(0, d->limit); - _upb_Decoder_CheckLimit(d); + decode_checklimit(d); } -#endif /* UPB_INTERNAL_DECODE_H_ */ +#endif /* UPB_DECODE_INT_H_ */ -#ifndef UPB_JSON_DECODE_H_ -#define UPB_JSON_DECODE_H_ +/** upb/json_decode.h ************************************************************/ +#ifndef UPB_JSONDECODE_H_ +#define UPB_JSONDECODE_H_ -#ifndef UPB_REFLECTION_DEF_H_ -#define UPB_REFLECTION_DEF_H_ +/** upb/def.h ************************************************************/ +#ifndef UPB_DEF_H_ +#define UPB_DEF_H_ -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +/* Must be last. */ -#ifndef UPB_REFLECTION_DEF_POOL_H_ -#define UPB_REFLECTION_DEF_POOL_H_ - - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -// Declarations common to all public def types. - -#ifndef UPB_REFLECTION_COMMON_H_ -#define UPB_REFLECTION_COMMON_H_ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +struct upb_EnumDef; +typedef struct upb_EnumDef upb_EnumDef; +struct upb_EnumValueDef; +typedef struct upb_EnumValueDef upb_EnumValueDef; +struct upb_ExtensionRange; +typedef struct upb_ExtensionRange upb_ExtensionRange; +struct upb_FieldDef; +typedef struct upb_FieldDef upb_FieldDef; +struct upb_FileDef; +typedef struct upb_FileDef upb_FileDef; +struct upb_MethodDef; +typedef struct upb_MethodDef upb_MethodDef; +struct upb_MessageDef; +typedef struct upb_MessageDef upb_MessageDef; +struct upb_OneofDef; +typedef struct upb_OneofDef upb_OneofDef; +struct upb_ServiceDef; +typedef struct upb_ServiceDef upb_ServiceDef; +struct upb_streamdef; +typedef struct upb_streamdef upb_streamdef; +struct upb_DefPool; +typedef struct upb_DefPool upb_DefPool; +typedef struct upb_EnumReservedRange upb_EnumReservedRange; +typedef struct upb_MessageReservedRange upb_MessageReservedRange; +typedef struct symtab_addctx symtab_addctx; typedef enum { kUpb_Syntax_Proto2 = 2, kUpb_Syntax_Proto3 = 3 } upb_Syntax; -// Forward declarations for circular references. -typedef struct upb_DefPool upb_DefPool; -typedef struct upb_EnumDef upb_EnumDef; -typedef struct upb_EnumValueDef upb_EnumValueDef; -typedef struct upb_ExtensionRange upb_ExtensionRange; -typedef struct upb_FieldDef upb_FieldDef; -typedef struct upb_FileDef upb_FileDef; -typedef struct upb_MessageDef upb_MessageDef; -typedef struct upb_MethodDef upb_MethodDef; -typedef struct upb_OneofDef upb_OneofDef; -typedef struct upb_ServiceDef upb_ServiceDef; - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -typedef struct upb_DefBuilder upb_DefBuilder; - -#endif /* UPB_REFLECTION_COMMON_H_ */ - -#ifndef UPB_REFLECTION_DEF_TYPE_H_ -#define UPB_REFLECTION_DEF_TYPE_H_ - - -// Must be last. - -// Inside a symtab we store tagged pointers to specific def types. -typedef enum { - UPB_DEFTYPE_MASK = 7, - - // Only inside symtab table. - UPB_DEFTYPE_EXT = 0, - UPB_DEFTYPE_MSG = 1, - UPB_DEFTYPE_ENUM = 2, - UPB_DEFTYPE_ENUMVAL = 3, - UPB_DEFTYPE_SERVICE = 4, - - // Only inside message table. - UPB_DEFTYPE_FIELD = 0, - UPB_DEFTYPE_ONEOF = 1, - UPB_DEFTYPE_FIELD_JSONNAME = 2, -} upb_deftype_t; - -#ifdef __cplusplus -extern "C" { -#endif - -// Our 3-bit pointer tagging requires all pointers to be multiples of 8. -// The arena will always yield 8-byte-aligned addresses, however we put -// the defs into arrays. For each element in the array to be 8-byte-aligned, -// the sizes of each def type must also be a multiple of 8. -// -// If any of these asserts fail, we need to add or remove padding on 32-bit -// machines (64-bit machines will have 8-byte alignment already due to -// pointers, which all of these structs have). -UPB_INLINE void _upb_DefType_CheckPadding(size_t size) { - UPB_ASSERT((size & UPB_DEFTYPE_MASK) == 0); -} - -upb_deftype_t _upb_DefType_Type(upb_value v); - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type); - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_TYPE_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -void upb_DefPool_Free(upb_DefPool* s); - -upb_DefPool* upb_DefPool_New(void); - -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym); - -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len); - -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym); - -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym); - -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name); - -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len); - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTable_Extension* ext); - -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym); - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum); - -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name); - -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size); - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name); - -const upb_FileDef* upb_DefPool_AddFile( - upb_DefPool* s, const google_protobuf_FileDescriptorProto* file_proto, - upb_Status* status); - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s); - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_POOL_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_DEF_H_ -#define UPB_REFLECTION_ENUM_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); -int32_t upb_EnumDef_Default(const upb_EnumDef* e); -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name); -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size); -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num); -const char* upb_EnumDef_FullName(const upb_EnumDef* e); -bool upb_EnumDef_HasOptions(const upb_EnumDef* e); -bool upb_EnumDef_IsClosed(const upb_EnumDef* e); - -// Creates a mini descriptor string for an enum, returns true on success. -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out); - -const char* upb_EnumDef_Name(const upb_EnumDef* e); -const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); -int upb_EnumDef_ValueCount(const upb_EnumDef* e); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_H_ -#define UPB_REFLECTION_ENUM_VALUE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v); -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v); -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v); -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v); -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v); -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v); -const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( - const upb_EnumValueDef* v); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_EXTENSION_RANGE_H_ -#define UPB_REFLECTION_EXTENSION_RANGE_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); - -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); -const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( - const upb_ExtensionRange* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_EXTENSION_RANGE_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FIELD_DEF_H_ -#define UPB_REFLECTION_FIELD_DEF_H_ - - -// Must be last. - -// Maximum field number allowed for FieldDefs. -// This is an inherent limit of the protobuf wire format. -#define kUpb_MaxFieldNumber ((1 << 29) - 1) - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f); -upb_CType upb_FieldDef_CType(const upb_FieldDef* f); -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); -const char* upb_FieldDef_FullName(const upb_FieldDef* f); -bool upb_FieldDef_HasDefault(const upb_FieldDef* f); -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); -bool upb_FieldDef_HasOptions(const upb_FieldDef* f); -bool upb_FieldDef_HasPresence(const upb_FieldDef* f); -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); -uint32_t upb_FieldDef_Index(const upb_FieldDef* f); -bool upb_FieldDef_IsExtension(const upb_FieldDef* f); -bool upb_FieldDef_IsMap(const upb_FieldDef* f); -bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool upb_FieldDef_IsPacked(const upb_FieldDef* f); -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); -bool upb_FieldDef_IsRequired(const upb_FieldDef* f); -bool upb_FieldDef_IsString(const upb_FieldDef* f); -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); -const char* upb_FieldDef_JsonName(const upb_FieldDef* f); -upb_Label upb_FieldDef_Label(const upb_FieldDef* f); -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); - -// Creates a mini descriptor string for a field, returns true on success. -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out); - -const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f); -const char* upb_FieldDef_Name(const upb_FieldDef* f); -uint32_t upb_FieldDef_Number(const upb_FieldDef* f); -const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FIELD_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_FILE_DEF_H_ -#define UPB_REFLECTION_FILE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); -int upb_FileDef_DependencyCount(const upb_FileDef* f); -bool upb_FileDef_HasOptions(const upb_FileDef* f); -const char* upb_FileDef_Name(const upb_FileDef* f); -const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); -const char* upb_FileDef_Package(const upb_FileDef* f); -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); - -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); -int upb_FileDef_ServiceCount(const upb_FileDef* f); - -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f); - -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); - -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); - -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); - -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FILE_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_DEF_H_ -#define UPB_REFLECTION_MESSAGE_DEF_H_ - - -// Must be last. - -// Well-known field tag numbers for map-entry messages. -#define kUpb_MapEntry_KeyFieldNumber 1 -#define kUpb_MapEntry_ValueFieldNumber 2 - -// Well-known field tag numbers for Any messages. -#define kUpb_Any_TypeFieldNumber 1 -#define kUpb_Any_ValueFieldNumber 2 - -// Well-known field tag numbers for duration messages. -#define kUpb_Duration_SecondsFieldNumber 1 -#define kUpb_Duration_NanosFieldNumber 2 - -// Well-known field tag numbers for timestamp messages. -#define kUpb_Timestamp_SecondsFieldNumber 1 -#define kUpb_Timestamp_NanosFieldNumber 2 - -// All the different kind of well known type messages. For simplicity of check, -// number wrappers and string wrappers are grouped together. Make sure the -// order and number of these groups are not changed. +/* All the different kind of well known type messages. For simplicity of check, + * number wrappers and string wrappers are grouped together. Make sure the + * order and merber of these groups are not changed. + */ typedef enum { kUpb_WellKnown_Unspecified, kUpb_WellKnown_Any, kUpb_WellKnown_FieldMask, kUpb_WellKnown_Duration, kUpb_WellKnown_Timestamp, - - // number wrappers + /* number wrappers */ kUpb_WellKnown_DoubleValue, kUpb_WellKnown_FloatValue, kUpb_WellKnown_Int64Value, kUpb_WellKnown_UInt64Value, kUpb_WellKnown_Int32Value, kUpb_WellKnown_UInt32Value, - - // string wrappers + /* string wrappers */ kUpb_WellKnown_StringValue, kUpb_WellKnown_BytesValue, kUpb_WellKnown_BoolValue, kUpb_WellKnown_Value, kUpb_WellKnown_ListValue, - kUpb_WellKnown_Struct, + kUpb_WellKnown_Struct } upb_WellKnown; -#ifdef __cplusplus -extern "C" { -#endif +/* upb_FieldDef ***************************************************************/ +/* Maximum field number allowed for FieldDefs. This is an inherent limit of the + * protobuf wire format. */ +#define kUpb_MaxFieldNumber ((1 << 29) - 1) + +const google_protobuf_FieldOptions* upb_FieldDef_Options(const upb_FieldDef* f); +bool upb_FieldDef_HasOptions(const upb_FieldDef* f); +const char* upb_FieldDef_FullName(const upb_FieldDef* f); +upb_CType upb_FieldDef_CType(const upb_FieldDef* f); +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f); +upb_Label upb_FieldDef_Label(const upb_FieldDef* f); +uint32_t upb_FieldDef_Number(const upb_FieldDef* f); +const char* upb_FieldDef_Name(const upb_FieldDef* f); +const char* upb_FieldDef_JsonName(const upb_FieldDef* f); +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f); +bool upb_FieldDef_IsExtension(const upb_FieldDef* f); +bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f); +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f); +uint32_t upb_FieldDef_Index(const upb_FieldDef* f); +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f); +bool upb_FieldDef_IsString(const upb_FieldDef* f); +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); +bool upb_FieldDef_IsMap(const upb_FieldDef* f); +bool upb_FieldDef_HasDefault(const upb_FieldDef* f); +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f); +bool upb_FieldDef_HasPresence(const upb_FieldDef* f); +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f); +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f); +const upb_MiniTable_Field* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f); +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); + +/* upb_OneofDef ***************************************************************/ + +const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); +bool upb_OneofDef_HasOptions(const upb_OneofDef* o); +const char* upb_OneofDef_Name(const upb_OneofDef* o); +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o); +uint32_t upb_OneofDef_Index(const upb_OneofDef* o); +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); +int upb_OneofDef_FieldCount(const upb_OneofDef* o); +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); + +/* Oneof lookups: + * - ntof: look up a field by name. + * - ntofz: look up a field by name (as a null-terminated string). + * - itof: look up a field by number. */ +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t length); +UPB_INLINE const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, + const char* name) { + return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); +} +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num); + +/* upb_MessageDef *************************************************************/ + +/* Well-known field tag numbers for map-entry messages. */ +#define kUpb_MapEntry_KeyFieldNumber 1 +#define kUpb_MapEntry_ValueFieldNumber 2 + +/* Well-known field tag numbers for Any messages. */ +#define kUpb_Any_TypeFieldNumber 1 +#define kUpb_Any_ValueFieldNumber 2 + +/* Well-known field tag numbers for duration messages. */ +#define kUpb_Duration_SecondsFieldNumber 1 +#define kUpb_Duration_NanosFieldNumber 2 + +/* Well-known field tag numbers for timestamp messages. */ +#define kUpb_Timestamp_SecondsFieldNumber 1 +#define kUpb_Timestamp_NanosFieldNumber 2 + +const google_protobuf_MessageOptions* upb_MessageDef_Options( + const upb_MessageDef* m); +bool upb_MessageDef_HasOptions(const upb_MessageDef* m); +const char* upb_MessageDef_FullName(const upb_MessageDef* m); +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m); - +const char* upb_MessageDef_Name(const upb_MessageDef* m); +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); +int upb_MessageDef_FieldCount(const upb_MessageDef* m); +int upb_MessageDef_OneofCount(const upb_MessageDef* m); const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, int i); -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m); - const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i); -int upb_MessageDef_FieldCount(const upb_MessageDef* m); +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i); +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m); - -// Returns a field by either JSON name or regular proto name. -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( +UPB_INLINE const upb_OneofDef* upb_MessageDef_FindOneofByName( const upb_MessageDef* m, const char* name) { - return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); + return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); } -// Lookup of either field or oneof by name. Returns whether either was found. -// If the return is true, then the found def will be set, and the non-found -// one set to NULL. +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindFieldByName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +} + +UPB_INLINE bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { + return google_protobuf_MessageOptions_map_entry(upb_MessageDef_Options(m)); +} + +UPB_INLINE bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { + return google_protobuf_MessageOptions_message_set_wire_format( + upb_MessageDef_Options(m)); +} + +/* Nested entities. */ +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i); +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i); + +/* Lookup of either field or oneof by name. Returns whether either was found. + * If the return is true, then the found def will be set, and the non-found + * one set to NULL. */ bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t size, + const char* name, size_t len, const upb_FieldDef** f, const upb_OneofDef** o); + UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, const char* name, const upb_FieldDef** f, @@ -6328,152 +5794,197 @@ UPB_INLINE bool upb_MessageDef_FindByName(const upb_MessageDef* m, return upb_MessageDef_FindByNameWithSize(m, name, strlen(name), f, o); } -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name); -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i); -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name); -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size); -const char* upb_MessageDef_FullName(const upb_MessageDef* m); -bool upb_MessageDef_HasOptions(const upb_MessageDef* m); -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m); -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m); +/* Returns a field by either JSON name or regular proto name. */ +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t len); +UPB_INLINE const upb_FieldDef* upb_MessageDef_FindByJsonName( + const upb_MessageDef* m, const char* name) { + return upb_MessageDef_FindByJsonNameWithSize(m, name, strlen(name)); +} -// Creates a mini descriptor string for a message, returns true on success. -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out); +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i); +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m); -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m); -const char* upb_MessageDef_Name(const upb_MessageDef* m); +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i); +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m); -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i); -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i); -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i); +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m); -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m); -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m); +/* upb_ExtensionRange *********************************************************/ -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i); -int upb_MessageDef_OneofCount(const upb_MessageDef* m); +const google_protobuf_ExtensionRangeOptions* upb_ExtensionRange_Options( + const upb_ExtensionRange* r); +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r); +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r); -const google_protobuf_MessageOptions* upb_MessageDef_Options(const upb_MessageDef* m); -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m); -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m); +/* upb_EnumDef ****************************************************************/ -#ifdef __cplusplus -} /* extern "C" */ -#endif +const google_protobuf_EnumOptions* upb_EnumDef_Options(const upb_EnumDef* e); +bool upb_EnumDef_HasOptions(const upb_EnumDef* e); +const char* upb_EnumDef_FullName(const upb_EnumDef* e); +const char* upb_EnumDef_Name(const upb_EnumDef* e); +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e); +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e); +int32_t upb_EnumDef_Default(const upb_EnumDef* e); +int upb_EnumDef_ValueCount(const upb_EnumDef* e); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i); +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* e, const char* name, size_t len); +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, + int32_t num); +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num); -#endif /* UPB_REFLECTION_MESSAGE_DEF_H_ */ +// Convenience wrapper. +UPB_INLINE const upb_EnumValueDef* upb_EnumDef_FindValueByName( + const upb_EnumDef* e, const char* name) { + return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); +} -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i); +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e); -#ifndef UPB_REFLECTION_METHOD_DEF_H_ -#define UPB_REFLECTION_METHOD_DEF_H_ +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i); +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e); +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r); +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r); -// Must be last. +/* upb_EnumValueDef ***********************************************************/ -#ifdef __cplusplus -extern "C" { -#endif +const google_protobuf_EnumValueOptions* upb_EnumValueDef_Options( + const upb_EnumValueDef* e); +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* e); +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* e); +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* e); +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* e); +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* e); -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); -const char* upb_MethodDef_FullName(const upb_MethodDef* m); +/* upb_FileDef ****************************************************************/ + +const google_protobuf_FileOptions* upb_FileDef_Options(const upb_FileDef* f); +bool upb_FileDef_HasOptions(const upb_FileDef* f); +const char* upb_FileDef_Name(const upb_FileDef* f); +const char* upb_FileDef_Package(const upb_FileDef* f); +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f); +int upb_FileDef_DependencyCount(const upb_FileDef* f); +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f); +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f); +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f); +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f); +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f); +int upb_FileDef_ServiceCount(const upb_FileDef* f); +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i); +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i); +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i); +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i); +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i); +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f); +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); + +/* upb_MethodDef **************************************************************/ + +const google_protobuf_MethodOptions* upb_MethodDef_Options( + const upb_MethodDef* m); bool upb_MethodDef_HasOptions(const upb_MethodDef* m); +const char* upb_MethodDef_FullName(const upb_MethodDef* m); int upb_MethodDef_Index(const upb_MethodDef* m); -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); const char* upb_MethodDef_Name(const upb_MethodDef* m); -const google_protobuf_MethodOptions* upb_MethodDef_Options(const upb_MethodDef* m); -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m); +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m); +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m); +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m); -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_METHOD_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_ONEOF_DEF_H_ -#define UPB_REFLECTION_ONEOF_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o); -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i); -int upb_OneofDef_FieldCount(const upb_OneofDef* o); -const char* upb_OneofDef_FullName(const upb_OneofDef* o); -bool upb_OneofDef_HasOptions(const upb_OneofDef* o); -uint32_t upb_OneofDef_Index(const upb_OneofDef* o); -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o); -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name); -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size); -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num); -const char* upb_OneofDef_Name(const upb_OneofDef* o); -int upb_OneofDef_numfields(const upb_OneofDef* o); -const google_protobuf_OneofOptions* upb_OneofDef_Options(const upb_OneofDef* o); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ONEOF_DEF_H_ */ - -// IWYU pragma: private, include "third_party/upb/upb/reflection/def.h" - -#ifndef UPB_REFLECTION_SERVICE_DEF_H_ -#define UPB_REFLECTION_SERVICE_DEF_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +/* upb_ServiceDef *************************************************************/ +const google_protobuf_ServiceOptions* upb_ServiceDef_Options( + const upb_ServiceDef* s); +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); +const char* upb_ServiceDef_Name(const upb_ServiceDef* s); +int upb_ServiceDef_Index(const upb_ServiceDef* s); const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s); +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, const char* name); -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s); -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s); -int upb_ServiceDef_Index(const upb_ServiceDef* s); -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i); -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s); -const char* upb_ServiceDef_Name(const upb_ServiceDef* s); -const google_protobuf_ServiceOptions* upb_ServiceDef_Options(const upb_ServiceDef* s); + +/* upb_DefPool ****************************************************************/ + +upb_DefPool* upb_DefPool_New(void); +void upb_DefPool_Free(upb_DefPool* s); +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym); +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym); +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym); +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len); +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name); +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size); +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name); +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len); +const upb_FileDef* upb_DefPool_AddFile( + upb_DefPool* s, const google_protobuf_FileDescriptorProto* file, + upb_Status* status); +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); +const upb_FieldDef* _upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTable_Extension* ext); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum); +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s); +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count); + +/* For generated code only: loads a generated descriptor. */ +typedef struct _upb_DefPool_Init { + struct _upb_DefPool_Init** deps; /* Dependencies of this file. */ + const upb_MiniTable_File* layout; + const char* filename; + upb_StringView descriptor; /* Serialized descriptor. */ +} _upb_DefPool_Init; + +// Should only be directly called by tests. This variant lets us suppress +// the use of compiled-in tables, forcing a rebuild of the tables at runtime. +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable); + +UPB_INLINE bool _upb_DefPool_LoadDefInit(upb_DefPool* s, + const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); +} + #ifdef __cplusplus } /* extern "C" */ -#endif +#endif /* __cplusplus */ - -#endif /* UPB_REFLECTION_SERVICE_DEF_H_ */ - -#endif /* UPB_REFLECTION_DEF_H_ */ - -// Must be last. +#endif /* UPB_DEF_H_ */ #ifdef __cplusplus extern "C" { @@ -6489,63 +6000,12 @@ bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, } /* extern "C" */ #endif - #endif /* UPB_JSONDECODE_H_ */ -#ifndef UPB_INTERNAL_UNICODE_H_ -#define UPB_INTERNAL_UNICODE_H_ +/** upb/reflection.h ************************************************************/ +#ifndef UPB_REFLECTION_H_ +#define UPB_REFLECTION_H_ -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Returns true iff a codepoint is the value for a high surrogate. -UPB_INLINE bool upb_Unicode_IsHigh(uint32_t cp) { - return (cp >= 0xd800 && cp <= 0xdbff); -} - -// Returns true iff a codepoint is the value for a low surrogate. -UPB_INLINE bool upb_Unicode_IsLow(uint32_t cp) { - return (cp >= 0xdc00 && cp <= 0xdfff); -} - -// Returns the high 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToHigh(uint32_t cp) { - return (cp >> 10) + 0xd7c0; -} - -// Returns the low 16-bit surrogate value for a supplementary codepoint. -// Does not sanity-check the input. -UPB_INLINE uint16_t upb_Unicode_ToLow(uint32_t cp) { - return (cp & 0x3ff) | 0xdc00; -} - -// Returns the 32-bit value corresponding to a pair of 16-bit surrogates. -// Does not sanity-check the input. -UPB_INLINE uint32_t upb_Unicode_FromPair(uint32_t high, uint32_t low) { - return ((high & 0x3ff) << 10) + (low & 0x3ff) + 0x10000; -} - -// Outputs a codepoint as UTF8. -// Returns the number of bytes written (1-4 on success, 0 on error). -// Does not sanity-check the input. Specifically does not check for surrogates. -int upb_Unicode_ToUTF8(uint32_t cp, char* out); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_UNICODE_H_ */ - -#ifndef UPB_REFLECTION_MESSAGE_H_ -#define UPB_REFLECTION_MESSAGE_H_ - - -// Must be last. #ifdef __cplusplus extern "C" { @@ -6553,6 +6013,12 @@ extern "C" { upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f); +/** upb_Message + * *******************************************************************/ + +/* Creates a new message of the given type in the given arena. */ +upb_Message* upb_Message_New(const upb_MessageDef* m, upb_Arena* a); + /* Returns the value associated with this field. */ upb_MessageValue upb_Message_Get(const upb_Message* msg, const upb_FieldDef* f); @@ -6612,28 +6078,24 @@ bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, #endif -#endif /* UPB_REFLECTION_MESSAGE_H_ */ +#endif /* UPB_REFLECTION_H_ */ -#ifndef UPB_JSON_ENCODE_H_ -#define UPB_JSON_ENCODE_H_ +/** upb/json_encode.h ************************************************************/ +#ifndef UPB_JSONENCODE_H_ +#define UPB_JSONENCODE_H_ -// Must be last. - #ifdef __cplusplus extern "C" { #endif enum { /* When set, emits 0/default values. TODO(haberman): proto3 only? */ - upb_JsonEncode_EmitDefaults = 1 << 0, + upb_JsonEncode_EmitDefaults = 1, - /* When set, use normal (snake_case) field names instead of JSON (camelCase) + /* When set, use normal (snake_caes) field names instead of JSON (camelCase) names. */ - upb_JsonEncode_UseProtoNames = 1 << 1, - - /* When set, emits enums as their integer values instead of as their names. */ - upb_JsonEncode_FormatEnumsAsIntegers = 1 << 2 + upb_JsonEncode_UseProtoNames = 2 }; /* Encodes the given |msg| to JSON format. The message's reflection is given in @@ -6652,35 +6114,9 @@ size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, } /* extern "C" */ #endif - #endif /* UPB_JSONENCODE_H_ */ -#ifndef UPB_INTERNAL_ENCODE_H_ -#define UPB_INTERNAL_ENCODE_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes a float or double that is round-trippable, but as short as possible. -// These routines are not fully optimal (not guaranteed to be shortest), but are -// short-ish and match the implementation that has been used in protobuf since -// the beginning. -// -// The given buffer size must be at least kUpb_RoundTripBufferSize. -enum { kUpb_RoundTripBufferSize = 32 }; -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_INTERNAL_ENCODE_H_ */ - +/** upb/internal/vsnprintf_compat.h ************************************************************/ #ifndef UPB_INTERNAL_VSNPRINTF_COMPAT_H_ #define UPB_INTERNAL_VSNPRINTF_COMPAT_H_ @@ -6705,6 +6141,7 @@ UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, #endif // UPB_INTERNAL_VSNPRINTF_COMPAT_H_ +/** upb/mini_table.h ************************************************************/ #ifndef UPB_MINI_TABLE_H_ #define UPB_MINI_TABLE_H_ @@ -6718,16 +6155,21 @@ extern "C" { const upb_MiniTable_Field* upb_MiniTable_FindFieldByNumber( const upb_MiniTable* table, uint32_t number); -upb_FieldType upb_MiniTableField_Type(const upb_MiniTable_Field* field); - UPB_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) { return mini_table->subs[field->submsg_index].submsg; } -UPB_INLINE const upb_MiniTable_Enum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* mini_table, const upb_MiniTable_Field* field) { - return mini_table->subs[field->submsg_index].subenum; +UPB_INLINE bool upb_MiniTable_Enum_CheckValue(const upb_MiniTable_Enum* e, + int32_t val) { + uint32_t uval = (uint32_t)val; + if (uval < 64) return e->mask & (1ULL << uval); + // OPT: binary search long lists? + int n = e->value_count; + for (int i = 0; i < n; i++) { + if (e->values[i] == val) return true; + } + return false; } /** upb_MtDataEncoder *********************************************************/ @@ -6766,8 +6208,7 @@ typedef struct { // char buf[256]; // char* ptr = buf; // e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr); // // Fields *must* be in field number order. // ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); // ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); @@ -6792,18 +6233,13 @@ char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, uint32_t field_num); -// Encodes the set of values for a given enum. The values must be given in +// Encodes the set of values for a given enum. The values must be given in // order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +void upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e); char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, uint32_t val); char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); -// Encodes an entire mini descriptor for one extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - /** upb_MiniTable *************************************************************/ typedef enum { @@ -6820,27 +6256,15 @@ typedef enum { upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, upb_MiniTablePlatform platform, upb_Arena* arena, upb_Status* status); - -// Links a sub-message field to a MiniTable for that sub-message. If a -// sub-message field is not linked, it will be treated as an unknown field -// during parsing, and setting the field will not be allowed. It is possible -// to link the message field later, at which point it will no longer be treated -// as unknown. However there is no synchronization for this operation, which -// means parallel mutation requires external synchronization. void upb_MiniTable_SetSubMessage(upb_MiniTable* table, upb_MiniTable_Field* field, const upb_MiniTable* sub); - -// Links an enum field to a MiniTable for that enum. All enum fields must -// be linked prior to parsing. void upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTable_Field* field, const upb_MiniTable_Enum* sub); -const char* upb_MiniTable_BuildExtension(const char* data, size_t len, - upb_MiniTable_Extension* ext, - const upb_MiniTable* extendee, - upb_MiniTable_Sub sub, - upb_Status* status); +bool upb_MiniTable_BuildExtension(const char* data, size_t len, + upb_MiniTable_Extension* ext, + upb_MiniTable_Sub sub, upb_Status* status); // Special-case functions for MessageSet layout and map entries. upb_MiniTable* upb_MiniTable_BuildMessageSet(upb_MiniTablePlatform platform, @@ -6878,547 +6302,7 @@ bool upb_IsTypePackable(upb_FieldType type); #endif /* UPB_MINI_TABLE_H_ */ -#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ -#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ - - -#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ -#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); - -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTable_Extension* ext, - upb_FieldDef* f); -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status); -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v); - -void** _upb_DefPool_ScratchData(const upb_DefPool* s); -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); - -// For generated code only: loads a generated descriptor. -typedef struct _upb_DefPool_Init { - struct _upb_DefPool_Init** deps; // Dependencies of this file. - const upb_MiniTable_File* layout; - const char* filename; - upb_StringView descriptor; // Serialized descriptor. -} _upb_DefPool_Init; - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); - -// Should only be directly called by tests. This variant lets us suppress -// the use of compiled-in tables, forcing a rebuild of the tables at runtime. -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ - -// Must be last. - -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (google_protobuf_##desc_type##_has_options(proto)) { \ - size_t size; \ - char* pb = google_protobuf_##options_type##_serialize( \ - google_protobuf_##desc_type##_options(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = \ - google_protobuf_##options_type##_parse(pb, size, _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const google_protobuf_##options_type*)kUpbDefOptDefault; \ - } - -#ifdef __cplusplus -extern "C" { -#endif - -struct upb_DefBuilder { - upb_DefPool* symtab; - upb_FileDef* file; // File we are building. - upb_Arena* arena; // Allocate defs here. - upb_Arena* tmp_arena; // For temporary allocations. - upb_Status* status; // Record errors here. - const upb_MiniTable_File* layout; // NULL if we should build layouts. - int enum_count; // Count of enums built so far. - int msg_count; // Count of messages built so far. - int ext_count; // Count of extensions built so far. - jmp_buf err; // longjmp() on error. -}; - -extern const char* kUpbDefOptDefault; - -// ctx->status has already been set elsewhere so just fail/longjmp() -UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx); - -UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, - ...) UPB_PRINTF(2, 3); -UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx); - -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name); - -// Given a symbol and the base symbol inside which it is defined, -// find the symbol's definition. -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type); - -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type); - -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end); - -const char* _upb_DefBuilder_FullToShort(const char* fullname); - -UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) { - if (bytes == 0) return NULL; - void* ret = upb_Arena_Malloc(ctx->arena, bytes); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} - -// Adds a symbol |v| to the symtab, which must be a def pointer previously -// packed with pack_def(). The def's pointer to upb_FileDef* must be set before -// adding, so we know which entries to remove if building this file fails. -UPB_INLINE void _upb_DefBuilder_Add(upb_DefBuilder* ctx, const char* name, - upb_value v) { - upb_StringView sym = {.data = name, .size = strlen(name)}; - bool ok = _upb_DefPool_InsertSym(ctx->symtab, sym, v, ctx->status); - if (!ok) _upb_DefBuilder_FailJmp(ctx); -} - -UPB_INLINE upb_Arena* _upb_DefBuilder_Arena(const upb_DefBuilder* ctx) { - return ctx->arena; -} - -UPB_INLINE upb_FileDef* _upb_DefBuilder_File(const upb_DefBuilder* ctx) { - return ctx->file; -} - -// This version of CheckIdent() is only called by other, faster versions after -// they detect a parsing error. -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full); - -// Verify a relative identifier string. The loop is branchless for speed. -UPB_INLINE void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); - - good &= is_alpha | is_numer; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); -} - -// Verify a full identifier string. This is slightly more complicated than -// verifying a relative identifier string because we must track '.' chars. -UPB_INLINE void _upb_DefBuilder_CheckIdentFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - bool start = true; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & !start; - const bool is_dot = (c == '.') & !start; - - good &= is_alpha | is_numer | is_dot; - start = is_dot; - } - - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, true); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i); -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a); -const upb_MiniTable_Enum* _upb_EnumDef_MiniTable(const upb_EnumDef* e); - -// Allocate and initialize an array of |n| enum defs. -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const google_protobuf_EnumDescriptorProto* const* protos, - const upb_MessageDef* containing_type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i); - -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const google_protobuf_EnumValueDescriptorProto* const* protos, upb_EnumDef* e, - bool* is_sorted); - -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ENUM_VALUE_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); - -const upb_MiniTable_Extension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f); -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f); - -// Allocate and initialize an array of |n| field defs. -upb_FieldDef* _upb_FieldDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_FieldDescriptorProto* const* protos, const char* prefix, - upb_MessageDef* m, bool* is_sorted); - -// Allocate and return a list of pointers to the |n| field defs in |ff|, -// sorted by field number. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FIELD_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_FILE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_FILE_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -const upb_MiniTable_Extension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i); -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f); -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f); - -// upb_FileDef_Package() returns "" if f->package is NULL, this does not. -const char* _upb_FileDef_RawPackage(const upb_FileDef* f); - -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const google_protobuf_FileDescriptorProto* file_proto); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_FILE_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i); -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m); -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t size, - upb_value v, upb_Arena* a); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f); -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m); -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m); - -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New( - upb_DefBuilder* ctx, int n, const google_protobuf_DescriptorProto* const* protos, - const upb_MessageDef* containing_type); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_MESSAGE_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ -#define UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int i); - -// Allocate and initialize an array of |n| service defs. -upb_ServiceDef* _upb_ServiceDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_ServiceDescriptorProto* const* protos); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_SERVICE_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ - - -// Must be last. - -// Manages the storage for mini descriptor strings as they are being encoded. -// TODO(b/234740652): Move some of this state directly into the encoder, maybe. -typedef struct { - upb_MtDataEncoder e; - size_t bufsize; - char* buf; - char* ptr; -} upb_DescState; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE void _upb_DescState_Init(upb_DescState* d) { - d->bufsize = kUpb_MtDataEncoder_MinSize * 2; - d->buf = NULL; - d->ptr = NULL; -} - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_DESC_STATE_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i); - -// Allocate and initialize an array of |n| extension ranges owned by |m|. -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_DescriptorProto_ExtensionRange* const* protos, - const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_EXTENSION_RANGE_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ -#define UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -bool _upb_OneofDef_Insert(upb_OneofDef* o, const upb_FieldDef* f, - const char* name, size_t size, upb_Arena* a); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_OneofDescriptorProto* const* protos, upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New( - upb_DefBuilder* ctx, int n, - const google_protobuf_MethodDescriptorProto* const* protos, upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ - -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -#ifndef UPB_MAP_SORTER_H_ -#define UPB_MAP_SORTER_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// _upb_mapsorter sorts maps and provides ordered iteration over the entries. -// Since maps can be recursive (map values can be messages which contain other -// maps), _upb_mapsorter can contain a stack of maps. - -typedef struct { - upb_tabent const** entries; - int size; - int cap; -} _upb_mapsorter; - -typedef struct { - int start; - int pos; - int end; -} _upb_sortedmap; - -UPB_INLINE void _upb_mapsorter_init(_upb_mapsorter* s) { - s->entries = NULL; - s->size = 0; - s->cap = 0; -} - -UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { - if (s->entries) free(s->entries); -} - -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, - _upb_sortedmap* sorted, upb_MapEntry* ent) { - if (sorted->pos == sorted->end) return false; - const upb_tabent* tabent = s->entries[sorted->pos++]; - upb_StringView key = upb_tabstrview(tabent->key); - _upb_map_fromkey(key, &ent->k, map->key_size); - upb_value val = {tabent->val.val}; - _upb_map_fromvalue(val, &ent->v, map->val_size); - return true; -} - -UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, - _upb_sortedmap* sorted) { - s->size = sorted->start; -} - -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MAP_SORTER_H_ */ - +/** upb/port_undef.inc ************************************************************/ /* See port_def.inc. This should #undef all macros #defined there. */ #undef UPB_SIZE @@ -7455,5 +6339,3 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, #undef UPB_UNPOISON_MEMORY_REGION #undef UPB_ASAN #undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 -#undef UPB_DEPRECATED -#undef UPB_GNUC_MIN diff --git a/libs/protobuf/ruby/google-protobuf.gemspec b/libs/protobuf/ruby/google-protobuf.gemspec index 5f226b0..a925fdc 100644 --- a/libs/protobuf/ruby/google-protobuf.gemspec +++ b/libs/protobuf/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.21.8" + s.version = "3.21.12" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/libs/protobuf/ruby/internal.bzl b/libs/protobuf/ruby/internal.bzl deleted file mode 100644 index 10ae108..0000000 --- a/libs/protobuf/ruby/internal.bzl +++ /dev/null @@ -1,35 +0,0 @@ -def internal_ruby_extension( - name, - extension, - deps = [], - **kwargs): - """Bazel rule to wrap up a generated ruby extension. - - NOTE: the rule is only an internal workaround. The interface may change and - the rule may be removed when everything is properly "Bazelified". - - Args: - name: the name of the target. - extension: the path of the extension file. - deps: extra dependencies to add. - **kwargs: extra arguments to forward to the genrule. - """ - - - native.genrule( - name = name, - srcs = deps + [ - "Rakefile", - ":srcs", - ":test_ruby_protos", - ":tests", - "@utf8_range//:utf8_range_srcs", - ], - tags = ["manual"], - outs = [extension], - cmd = "pushd `dirname $(location Rakefile)`\n" + - "BAZEL=true rake\n" + - "popd\n" + - "cp `dirname $(location Rakefile)`/%s $(OUTS)\n" % extension, - **kwargs, - ) diff --git a/libs/protobuf/ruby/lib/google/protobuf/message_exts.rb b/libs/protobuf/ruby/lib/google/protobuf/message_exts.rb index 3cc1a08..6608521 100644 --- a/libs/protobuf/ruby/lib/google/protobuf/message_exts.rb +++ b/libs/protobuf/ruby/lib/google/protobuf/message_exts.rb @@ -49,10 +49,5 @@ module Google end end - class AbstractMessage - include MessageExts - extend MessageExts::ClassMethods - end - private_constant :AbstractMessage end end diff --git a/libs/protobuf/ruby/pom.xml b/libs/protobuf/ruby/pom.xml index c533dd7..68dadac 100644 --- a/libs/protobuf/ruby/pom.xml +++ b/libs/protobuf/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.21.8 + 3.21.12 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.21.8 + 3.21.12 org.jruby diff --git a/libs/protobuf/ruby/tests/ruby_version.rb b/libs/protobuf/ruby/tests/ruby_version.rb deleted file mode 100644 index eb98960..0000000 --- a/libs/protobuf/ruby/tests/ruby_version.rb +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/ruby - -# Test that Kokoro is using the expected version of ruby. - -require 'test/unit' - -class RubyVersionTest < Test::Unit::TestCase - - def test_ruby_version - return if RUBY_PLATFORM == "java" - if not ENV["KOKORO_RUBY_VERSION"] - STDERR.puts("No kokoro ruby version found, skipping check") - return - end - - actual = RUBY_VERSION - expected = ENV["KOKORO_RUBY_VERSION"].delete_prefix("ruby-") - assert actual.start_with?(expected), "Version #{actual} found, expecting #{expected}" - end - - def test_jruby_version - return if RUBY_PLATFORM != "java" - if not ENV["KOKORO_RUBY_VERSION"] - STDERR.puts("No kokoro ruby version found, skipping check") - return - end - - expected = ENV["KOKORO_RUBY_VERSION"].delete_prefix("jruby-") - actual = JRUBY_VERSION - assert actual.start_with?(expected), "Version #{actual} found, expecting #{expected}" - end - -end diff --git a/libs/protobuf/ruby/travis-test.sh b/libs/protobuf/ruby/travis-test.sh index 39f58a2..f7fa815 100755 --- a/libs/protobuf/ruby/travis-test.sh +++ b/libs/protobuf/ruby/travis-test.sh @@ -5,12 +5,8 @@ set -ex test_version() { version=$1 - bazel_args="\ - $(../kokoro/common/bazel_flags.sh) \ - --action_env=PATH \ - --action_env=GEM_PATH \ - --action_env=GEM_HOME \ - --test_env=KOKORO_RUBY_VERSION=$version" + + RUBY_CONFORMANCE=test_ruby if [[ $version == jruby-9* ]] ; then bash --login -c \ @@ -18,14 +14,21 @@ test_version() { which ruby && \ git clean -f && \ gem install --no-document bundler && bundle && \ - bazel test //ruby/... $bazel_args --define=ruby_platform=java" + rake test && \ + rake gc_test && \ + cd ../conformance && make test_jruby && \ + cd ../ruby/compatibility_tests/v3.0.0 && ./test.sh" else bash --login -c \ "rvm install $version && rvm use $version && \ which ruby && \ git clean -f && \ gem install --no-document bundler -v 1.17.3 && bundle && \ - bazel test //ruby/... $bazel_args --define=ruby_platform=c" + rake test && \ + rake gc_test && \ + cd ../conformance && make ${RUBY_CONFORMANCE} && \ + cd ../ruby/compatibility_tests/v3.0.0 && \ + cp -R ../../lib lib && ./test.sh" fi } diff --git a/libs/protobuf/src/BUILD.bazel b/libs/protobuf/src/BUILD.bazel deleted file mode 100644 index aae838c..0000000 --- a/libs/protobuf/src/BUILD.bazel +++ /dev/null @@ -1,64 +0,0 @@ -################################################################################ -# Protocol Buffers: C++ Runtime -################################################################################ - -# Most rules are under google/protobuf. This package exists for convenience. -load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") -load("@upb//cmake:build_defs.bzl", "staleness_test") -load("//conformance:defs.bzl", "conformance_test") - -pkg_files( - name = "dist_files", - srcs = glob(["**"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -pkg_filegroup( - name = "all_dist_files", - srcs = [ - ":dist_files", - "//src/google/protobuf:dist_files", - "//src/google/protobuf/compiler:dist_files", - "//src/google/protobuf/compiler/cpp:dist_files", - "//src/google/protobuf/compiler/csharp:dist_files", - "//src/google/protobuf/compiler/java:dist_files", - "//src/google/protobuf/compiler/objectivec:dist_files", - "//src/google/protobuf/compiler/php:dist_files", - "//src/google/protobuf/compiler/python:dist_files", - "//src/google/protobuf/compiler/ruby:dist_files", - "//src/google/protobuf/io:dist_files", - "//src/google/protobuf/stubs:dist_files", - "//src/google/protobuf/testing:dist_files", - "//src/google/protobuf/util:dist_files", - ], - visibility = ["//pkg:__pkg__"], -) - -conformance_test( - name = "conformance_test", - failure_list = "//conformance:failure_list_cpp.txt", - testee = "//conformance:conformance_cpp", - text_format_failure_list = "//conformance:text_format_failure_list_cpp.txt", -) - -# Copy the generated file_lists.cmake into a place where the staleness test -# below can use it. -genrule( - name = "copy_cmake_lists", - srcs = ["//pkg:gen_src_file_lists"], - outs = ["cmake_copy/file_lists.cmake"], - cmd = "cp $< $@", - visibility = ["//visibility:private"], -) - -staleness_test( - name = "cmake_lists_staleness_test", - outs = ["file_lists.cmake"], - generated_pattern = "cmake_copy/%s", - # Only run this test if it is explicitly specified on the command line (not - # via //src:all or ...). This file will be automatically updated in a - # GitHub action, so developers should not worry about failures from this - # test. - tags = ["manual"], -) diff --git a/libs/protobuf/src/Makefile.am b/libs/protobuf/src/Makefile.am new file mode 100644 index 0000000..f48f7d4 --- /dev/null +++ b/libs/protobuf/src/Makefile.am @@ -0,0 +1,918 @@ +## Process this file with automake to produce Makefile.in + +if HAVE_ZLIB +GZCHECKPROGRAMS = zcgzip zcgunzip +GZHEADERS = google/protobuf/io/gzip_stream.h +GZTESTS = google/protobuf/io/gzip_stream_unittest.sh +ZLIB_DEF = -DHAVE_ZLIB=1 +else +GZCHECKPROGRAMS = +GZHEADERS = +GZTESTS = +ZLIB_DEF = +endif + +if HAVE_PTHREAD +PTHREAD_DEF = -DHAVE_PTHREAD=1 +else +PTHREAD_DEF = +endif + +PROTOBUF_VERSION = 32:12:0 + +if GCC +# Turn on all warnings except for sign comparison (we ignore sign comparison +# in Google so our code base have tons of such warnings). +NO_OPT_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) -Wall -Wno-sign-compare +else +NO_OPT_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) +endif + +AM_CXXFLAGS = $(NO_OPT_CXXFLAGS) $(PROTOBUF_OPT_FLAG) + +AM_LDFLAGS = $(PTHREAD_CFLAGS) ${LIBLOG_LIBS} + +# If I say "dist_include_DATA", automake complains that $(includedir) is not +# a "legitimate" directory for DATA. Screw you, automake. +protodir = $(includedir) + +# If you are adding new files here, also remember to change the build files for +# all other languages, //protoc-artifacts/build-zip.sh and run +# //update_file_list.sh for bazel. +nobase_dist_proto_DATA = \ + google/protobuf/any.proto \ + google/protobuf/api.proto \ + google/protobuf/compiler/plugin.proto \ + google/protobuf/descriptor.proto \ + google/protobuf/duration.proto \ + google/protobuf/empty.proto \ + google/protobuf/field_mask.proto \ + google/protobuf/source_context.proto \ + google/protobuf/struct.proto \ + google/protobuf/timestamp.proto \ + google/protobuf/type.proto \ + google/protobuf/wrappers.proto + +# Not sure why these don't get cleaned automatically. +clean-local: + rm -f *.loT + +CLEANFILES = $(protoc_outputs) unittest_proto_middleman \ + testzip.jar testzip.list testzip.proto testzip.zip \ + no_warning_test.cc + +MAINTAINERCLEANFILES = \ + Makefile.in + +nobase_include_HEADERS = \ + google/protobuf/any.h \ + google/protobuf/any.pb.h \ + google/protobuf/api.pb.h \ + google/protobuf/arena.h \ + google/protobuf/arena_impl.h \ + google/protobuf/arenastring.h \ + google/protobuf/arenaz_sampler.h \ + google/protobuf/compiler/code_generator.h \ + google/protobuf/compiler/command_line_interface.h \ + google/protobuf/compiler/cpp/cpp_generator.h \ + google/protobuf/compiler/cpp/file.h \ + google/protobuf/compiler/cpp/generator.h \ + google/protobuf/compiler/cpp/helpers.h \ + google/protobuf/compiler/cpp/names.h \ + google/protobuf/compiler/csharp/csharp_doc_comment.h \ + google/protobuf/compiler/csharp/csharp_generator.h \ + google/protobuf/compiler/csharp/csharp_names.h \ + google/protobuf/compiler/csharp/csharp_options.h \ + google/protobuf/compiler/importer.h \ + google/protobuf/compiler/java/generator.h \ + google/protobuf/compiler/java/java_generator.h \ + google/protobuf/compiler/java/kotlin_generator.h \ + google/protobuf/compiler/java/names.h \ + google/protobuf/compiler/objectivec/objectivec_generator.h \ + google/protobuf/compiler/objectivec/objectivec_helpers.h \ + google/protobuf/compiler/parser.h \ + google/protobuf/compiler/php/php_generator.h \ + google/protobuf/compiler/plugin.h \ + google/protobuf/compiler/plugin.pb.h \ + google/protobuf/compiler/python/generator.h \ + google/protobuf/compiler/python/pyi_generator.h \ + google/protobuf/compiler/python/python_generator.h \ + google/protobuf/compiler/ruby/ruby_generator.h \ + google/protobuf/descriptor.h \ + google/protobuf/descriptor.pb.h \ + google/protobuf/descriptor_database.h \ + google/protobuf/duration.pb.h \ + google/protobuf/dynamic_message.h \ + google/protobuf/empty.pb.h \ + google/protobuf/endian.h \ + google/protobuf/explicitly_constructed.h \ + google/protobuf/extension_set.h \ + google/protobuf/extension_set_inl.h \ + google/protobuf/field_access_listener.h \ + google/protobuf/field_mask.pb.h \ + google/protobuf/generated_enum_reflection.h \ + google/protobuf/generated_enum_util.h \ + google/protobuf/generated_message_bases.h \ + google/protobuf/generated_message_reflection.h \ + google/protobuf/generated_message_tctable_decl.h \ + google/protobuf/generated_message_tctable_impl.h \ + google/protobuf/generated_message_util.h \ + google/protobuf/has_bits.h \ + google/protobuf/implicit_weak_message.h \ + google/protobuf/inlined_string_field.h \ + google/protobuf/io/coded_stream.h \ + $(GZHEADERS) \ + google/protobuf/io/io_win32.h \ + google/protobuf/io/printer.h \ + google/protobuf/io/strtod.h \ + google/protobuf/io/tokenizer.h \ + google/protobuf/io/zero_copy_stream.h \ + google/protobuf/io/zero_copy_stream_impl.h \ + google/protobuf/io/zero_copy_stream_impl_lite.h \ + google/protobuf/map.h \ + google/protobuf/map_entry.h \ + google/protobuf/map_entry_lite.h \ + google/protobuf/map_field.h \ + google/protobuf/map_field_inl.h \ + google/protobuf/map_field_lite.h \ + google/protobuf/map_type_handler.h \ + google/protobuf/message.h \ + google/protobuf/message_lite.h \ + google/protobuf/metadata.h \ + google/protobuf/metadata_lite.h \ + google/protobuf/parse_context.h \ + google/protobuf/port.h \ + google/protobuf/port_def.inc \ + google/protobuf/port_undef.inc \ + google/protobuf/reflection.h \ + google/protobuf/reflection_internal.h \ + google/protobuf/reflection_ops.h \ + google/protobuf/repeated_field.h \ + google/protobuf/repeated_ptr_field.h \ + google/protobuf/service.h \ + google/protobuf/source_context.pb.h \ + google/protobuf/struct.pb.h \ + google/protobuf/stubs/bytestream.h \ + google/protobuf/stubs/callback.h \ + google/protobuf/stubs/casts.h \ + google/protobuf/stubs/common.h \ + google/protobuf/stubs/hash.h \ + google/protobuf/stubs/logging.h \ + google/protobuf/stubs/macros.h \ + google/protobuf/stubs/map_util.h \ + google/protobuf/stubs/mutex.h \ + google/protobuf/stubs/once.h \ + google/protobuf/stubs/platform_macros.h \ + google/protobuf/stubs/port.h \ + google/protobuf/stubs/status.h \ + google/protobuf/stubs/stl_util.h \ + google/protobuf/stubs/stringpiece.h \ + google/protobuf/stubs/strutil.h \ + google/protobuf/stubs/template_util.h \ + google/protobuf/text_format.h \ + google/protobuf/timestamp.pb.h \ + google/protobuf/type.pb.h \ + google/protobuf/unknown_field_set.h \ + google/protobuf/util/delimited_message_util.h \ + google/protobuf/util/field_comparator.h \ + google/protobuf/util/field_mask_util.h \ + google/protobuf/util/json_util.h \ + google/protobuf/util/message_differencer.h \ + google/protobuf/util/time_util.h \ + google/protobuf/util/type_resolver.h \ + google/protobuf/util/type_resolver_util.h \ + google/protobuf/wire_format.h \ + google/protobuf/wire_format_lite.h \ + google/protobuf/wrappers.pb.h + +lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la + +libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS) $(LIBATOMIC_LIBS) +libprotobuf_lite_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined +if HAVE_LD_VERSION_SCRIPT +libprotobuf_lite_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf-lite.map +EXTRA_libprotobuf_lite_la_DEPENDENCIES = libprotobuf-lite.map +endif +libprotobuf_lite_la_SOURCES = \ + google/protobuf/any_lite.cc \ + google/protobuf/arena.cc \ + google/protobuf/arenastring.cc \ + google/protobuf/arenaz_sampler.cc \ + google/protobuf/extension_set.cc \ + google/protobuf/generated_enum_util.cc \ + google/protobuf/generated_message_tctable_lite.cc \ + google/protobuf/generated_message_util.cc \ + google/protobuf/implicit_weak_message.cc \ + google/protobuf/inlined_string_field.cc \ + google/protobuf/io/coded_stream.cc \ + google/protobuf/io/io_win32.cc \ + google/protobuf/io/strtod.cc \ + google/protobuf/io/zero_copy_stream.cc \ + google/protobuf/io/zero_copy_stream_impl.cc \ + google/protobuf/io/zero_copy_stream_impl_lite.cc \ + google/protobuf/map.cc \ + google/protobuf/message_lite.cc \ + google/protobuf/parse_context.cc \ + google/protobuf/repeated_field.cc \ + google/protobuf/repeated_ptr_field.cc \ + google/protobuf/string_member_robber.h \ + google/protobuf/stubs/bytestream.cc \ + google/protobuf/stubs/common.cc \ + google/protobuf/stubs/int128.cc \ + google/protobuf/stubs/int128.h \ + google/protobuf/stubs/mathutil.h \ + google/protobuf/stubs/status.cc \ + google/protobuf/stubs/status_macros.h \ + google/protobuf/stubs/statusor.cc \ + google/protobuf/stubs/statusor.h \ + google/protobuf/stubs/stringpiece.cc \ + google/protobuf/stubs/stringprintf.cc \ + google/protobuf/stubs/stringprintf.h \ + google/protobuf/stubs/structurally_valid.cc \ + google/protobuf/stubs/strutil.cc \ + google/protobuf/stubs/time.cc \ + google/protobuf/stubs/time.h \ + google/protobuf/wire_format_lite.cc + +libprotobuf_la_LIBADD = $(PTHREAD_LIBS) $(LIBATOMIC_LIBS) +libprotobuf_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined +if HAVE_LD_VERSION_SCRIPT +libprotobuf_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf.map +EXTRA_libprotobuf_la_DEPENDENCIES = libprotobuf.map +endif +libprotobuf_la_SOURCES = \ + $(libprotobuf_lite_la_SOURCES) \ + google/protobuf/any.cc \ + google/protobuf/any.pb.cc \ + google/protobuf/api.pb.cc \ + google/protobuf/compiler/importer.cc \ + google/protobuf/compiler/parser.cc \ + google/protobuf/descriptor.cc \ + google/protobuf/descriptor.pb.cc \ + google/protobuf/descriptor_database.cc \ + google/protobuf/duration.pb.cc \ + google/protobuf/dynamic_message.cc \ + google/protobuf/empty.pb.cc \ + google/protobuf/extension_set_heavy.cc \ + google/protobuf/field_mask.pb.cc \ + google/protobuf/generated_message_bases.cc \ + google/protobuf/generated_message_reflection.cc \ + google/protobuf/generated_message_tctable_full.cc \ + google/protobuf/io/gzip_stream.cc \ + google/protobuf/io/printer.cc \ + google/protobuf/io/tokenizer.cc \ + google/protobuf/map_field.cc \ + google/protobuf/message.cc \ + google/protobuf/reflection_ops.cc \ + google/protobuf/service.cc \ + google/protobuf/source_context.pb.cc \ + google/protobuf/struct.pb.cc \ + google/protobuf/stubs/substitute.cc \ + google/protobuf/stubs/substitute.h \ + google/protobuf/text_format.cc \ + google/protobuf/timestamp.pb.cc \ + google/protobuf/type.pb.cc \ + google/protobuf/unknown_field_set.cc \ + google/protobuf/util/delimited_message_util.cc \ + google/protobuf/util/field_comparator.cc \ + google/protobuf/util/field_mask_util.cc \ + google/protobuf/util/internal/constants.h \ + google/protobuf/util/internal/datapiece.cc \ + google/protobuf/util/internal/datapiece.h \ + google/protobuf/util/internal/default_value_objectwriter.cc \ + google/protobuf/util/internal/default_value_objectwriter.h \ + google/protobuf/util/internal/error_listener.cc \ + google/protobuf/util/internal/error_listener.h \ + google/protobuf/util/internal/expecting_objectwriter.h \ + google/protobuf/util/internal/field_mask_utility.cc \ + google/protobuf/util/internal/field_mask_utility.h \ + google/protobuf/util/internal/json_escaping.cc \ + google/protobuf/util/internal/json_escaping.h \ + google/protobuf/util/internal/json_objectwriter.cc \ + google/protobuf/util/internal/json_objectwriter.h \ + google/protobuf/util/internal/json_stream_parser.cc \ + google/protobuf/util/internal/json_stream_parser.h \ + google/protobuf/util/internal/location_tracker.h \ + google/protobuf/util/internal/mock_error_listener.h \ + google/protobuf/util/internal/object_location_tracker.h \ + google/protobuf/util/internal/object_source.h \ + google/protobuf/util/internal/object_writer.cc \ + google/protobuf/util/internal/object_writer.h \ + google/protobuf/util/internal/proto_writer.cc \ + google/protobuf/util/internal/proto_writer.h \ + google/protobuf/util/internal/protostream_objectsource.cc \ + google/protobuf/util/internal/protostream_objectsource.h \ + google/protobuf/util/internal/protostream_objectwriter.cc \ + google/protobuf/util/internal/protostream_objectwriter.h \ + google/protobuf/util/internal/structured_objectwriter.h \ + google/protobuf/util/internal/type_info.cc \ + google/protobuf/util/internal/type_info.h \ + google/protobuf/util/internal/type_info_test_helper.h \ + google/protobuf/util/internal/utility.cc \ + google/protobuf/util/internal/utility.h \ + google/protobuf/util/json_util.cc \ + google/protobuf/util/message_differencer.cc \ + google/protobuf/util/time_util.cc \ + google/protobuf/util/type_resolver_util.cc \ + google/protobuf/wire_format.cc \ + google/protobuf/wrappers.pb.cc + +nodist_libprotobuf_la_SOURCES = $(nodist_libprotobuf_lite_la_SOURCES) + +libprotoc_la_LIBADD = $(PTHREAD_LIBS) libprotobuf.la +libprotoc_la_LDFLAGS = -version-info $(PROTOBUF_VERSION) -export-dynamic -no-undefined +if HAVE_LD_VERSION_SCRIPT +libprotoc_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotoc.map +EXTRA_libprotoc_la_DEPENDENCIES = libprotoc.map +endif +libprotoc_la_SOURCES = \ + google/protobuf/compiler/code_generator.cc \ + google/protobuf/compiler/command_line_interface.cc \ + google/protobuf/compiler/cpp/enum.cc \ + google/protobuf/compiler/cpp/enum.h \ + google/protobuf/compiler/cpp/enum_field.cc \ + google/protobuf/compiler/cpp/enum_field.h \ + google/protobuf/compiler/cpp/extension.cc \ + google/protobuf/compiler/cpp/extension.h \ + google/protobuf/compiler/cpp/field.cc \ + google/protobuf/compiler/cpp/field.h \ + google/protobuf/compiler/cpp/file.cc \ + google/protobuf/compiler/cpp/generator.cc \ + google/protobuf/compiler/cpp/helpers.cc \ + google/protobuf/compiler/cpp/map_field.cc \ + google/protobuf/compiler/cpp/map_field.h \ + google/protobuf/compiler/cpp/message.cc \ + google/protobuf/compiler/cpp/message.h \ + google/protobuf/compiler/cpp/message_field.cc \ + google/protobuf/compiler/cpp/message_field.h \ + google/protobuf/compiler/cpp/message_layout_helper.h \ + google/protobuf/compiler/cpp/options.h \ + google/protobuf/compiler/cpp/padding_optimizer.cc \ + google/protobuf/compiler/cpp/padding_optimizer.h \ + google/protobuf/compiler/cpp/parse_function_generator.cc \ + google/protobuf/compiler/cpp/parse_function_generator.h \ + google/protobuf/compiler/cpp/primitive_field.cc \ + google/protobuf/compiler/cpp/primitive_field.h \ + google/protobuf/compiler/cpp/service.cc \ + google/protobuf/compiler/cpp/service.h \ + google/protobuf/compiler/cpp/string_field.cc \ + google/protobuf/compiler/cpp/string_field.h \ + google/protobuf/compiler/csharp/csharp_doc_comment.cc \ + google/protobuf/compiler/csharp/csharp_enum.cc \ + google/protobuf/compiler/csharp/csharp_enum.h \ + google/protobuf/compiler/csharp/csharp_enum_field.cc \ + google/protobuf/compiler/csharp/csharp_enum_field.h \ + google/protobuf/compiler/csharp/csharp_field_base.cc \ + google/protobuf/compiler/csharp/csharp_field_base.h \ + google/protobuf/compiler/csharp/csharp_generator.cc \ + google/protobuf/compiler/csharp/csharp_helpers.cc \ + google/protobuf/compiler/csharp/csharp_helpers.h \ + google/protobuf/compiler/csharp/csharp_map_field.cc \ + google/protobuf/compiler/csharp/csharp_map_field.h \ + google/protobuf/compiler/csharp/csharp_message.cc \ + google/protobuf/compiler/csharp/csharp_message.h \ + google/protobuf/compiler/csharp/csharp_message_field.cc \ + google/protobuf/compiler/csharp/csharp_message_field.h \ + google/protobuf/compiler/csharp/csharp_primitive_field.cc \ + google/protobuf/compiler/csharp/csharp_primitive_field.h \ + google/protobuf/compiler/csharp/csharp_reflection_class.cc \ + google/protobuf/compiler/csharp/csharp_reflection_class.h \ + google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc \ + google/protobuf/compiler/csharp/csharp_repeated_enum_field.h \ + google/protobuf/compiler/csharp/csharp_repeated_message_field.cc \ + google/protobuf/compiler/csharp/csharp_repeated_message_field.h \ + google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc \ + google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h \ + google/protobuf/compiler/csharp/csharp_source_generator_base.cc \ + google/protobuf/compiler/csharp/csharp_source_generator_base.h \ + google/protobuf/compiler/csharp/csharp_wrapper_field.cc \ + google/protobuf/compiler/csharp/csharp_wrapper_field.h \ + google/protobuf/compiler/java/context.cc \ + google/protobuf/compiler/java/context.h \ + google/protobuf/compiler/java/doc_comment.cc \ + google/protobuf/compiler/java/doc_comment.h \ + google/protobuf/compiler/java/enum.cc \ + google/protobuf/compiler/java/enum.h \ + google/protobuf/compiler/java/enum_field.cc \ + google/protobuf/compiler/java/enum_field.h \ + google/protobuf/compiler/java/enum_field_lite.cc \ + google/protobuf/compiler/java/enum_field_lite.h \ + google/protobuf/compiler/java/enum_lite.cc \ + google/protobuf/compiler/java/enum_lite.h \ + google/protobuf/compiler/java/extension.cc \ + google/protobuf/compiler/java/extension.h \ + google/protobuf/compiler/java/extension_lite.cc \ + google/protobuf/compiler/java/extension_lite.h \ + google/protobuf/compiler/java/field.cc \ + google/protobuf/compiler/java/field.h \ + google/protobuf/compiler/java/file.cc \ + google/protobuf/compiler/java/file.h \ + google/protobuf/compiler/java/generator.cc \ + google/protobuf/compiler/java/generator_factory.cc \ + google/protobuf/compiler/java/generator_factory.h \ + google/protobuf/compiler/java/helpers.cc \ + google/protobuf/compiler/java/helpers.h \ + google/protobuf/compiler/java/kotlin_generator.cc \ + google/protobuf/compiler/java/map_field.cc \ + google/protobuf/compiler/java/map_field.h \ + google/protobuf/compiler/java/map_field_lite.cc \ + google/protobuf/compiler/java/map_field_lite.h \ + google/protobuf/compiler/java/message.cc \ + google/protobuf/compiler/java/message.h \ + google/protobuf/compiler/java/message_builder.cc \ + google/protobuf/compiler/java/message_builder.h \ + google/protobuf/compiler/java/message_builder_lite.cc \ + google/protobuf/compiler/java/message_builder_lite.h \ + google/protobuf/compiler/java/message_field.cc \ + google/protobuf/compiler/java/message_field.h \ + google/protobuf/compiler/java/message_field_lite.cc \ + google/protobuf/compiler/java/message_field_lite.h \ + google/protobuf/compiler/java/message_lite.cc \ + google/protobuf/compiler/java/message_lite.h \ + google/protobuf/compiler/java/name_resolver.cc \ + google/protobuf/compiler/java/name_resolver.h \ + google/protobuf/compiler/java/options.h \ + google/protobuf/compiler/java/primitive_field.cc \ + google/protobuf/compiler/java/primitive_field.h \ + google/protobuf/compiler/java/primitive_field_lite.cc \ + google/protobuf/compiler/java/primitive_field_lite.h \ + google/protobuf/compiler/java/service.cc \ + google/protobuf/compiler/java/service.h \ + google/protobuf/compiler/java/shared_code_generator.cc \ + google/protobuf/compiler/java/shared_code_generator.h \ + google/protobuf/compiler/java/string_field.cc \ + google/protobuf/compiler/java/string_field.h \ + google/protobuf/compiler/java/string_field_lite.cc \ + google/protobuf/compiler/java/string_field_lite.h \ + google/protobuf/compiler/objectivec/objectivec_enum.cc \ + google/protobuf/compiler/objectivec/objectivec_enum.h \ + google/protobuf/compiler/objectivec/objectivec_enum_field.cc \ + google/protobuf/compiler/objectivec/objectivec_enum_field.h \ + google/protobuf/compiler/objectivec/objectivec_extension.cc \ + google/protobuf/compiler/objectivec/objectivec_extension.h \ + google/protobuf/compiler/objectivec/objectivec_field.cc \ + google/protobuf/compiler/objectivec/objectivec_field.h \ + google/protobuf/compiler/objectivec/objectivec_file.cc \ + google/protobuf/compiler/objectivec/objectivec_file.h \ + google/protobuf/compiler/objectivec/objectivec_generator.cc \ + google/protobuf/compiler/objectivec/objectivec_helpers.cc \ + google/protobuf/compiler/objectivec/objectivec_map_field.cc \ + google/protobuf/compiler/objectivec/objectivec_map_field.h \ + google/protobuf/compiler/objectivec/objectivec_message.cc \ + google/protobuf/compiler/objectivec/objectivec_message.h \ + google/protobuf/compiler/objectivec/objectivec_message_field.cc \ + google/protobuf/compiler/objectivec/objectivec_message_field.h \ + google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h \ + google/protobuf/compiler/objectivec/objectivec_oneof.cc \ + google/protobuf/compiler/objectivec/objectivec_oneof.h \ + google/protobuf/compiler/objectivec/objectivec_primitive_field.cc \ + google/protobuf/compiler/objectivec/objectivec_primitive_field.h \ + google/protobuf/compiler/php/php_generator.cc \ + google/protobuf/compiler/plugin.cc \ + google/protobuf/compiler/plugin.pb.cc \ + google/protobuf/compiler/python/generator.cc \ + google/protobuf/compiler/python/helpers.cc \ + google/protobuf/compiler/python/helpers.h \ + google/protobuf/compiler/python/pyi_generator.cc \ + google/protobuf/compiler/ruby/ruby_generator.cc \ + google/protobuf/compiler/scc.h \ + google/protobuf/compiler/subprocess.cc \ + google/protobuf/compiler/subprocess.h \ + google/protobuf/compiler/zip_writer.cc \ + google/protobuf/compiler/zip_writer.h + +bin_PROGRAMS = protoc +protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la +protoc_SOURCES = google/protobuf/compiler/main.cc + +# Tests ============================================================== + +protoc_inputs = \ + google/protobuf/any_test.proto \ + google/protobuf/compiler/cpp/test_bad_identifiers.proto \ + google/protobuf/compiler/cpp/test_large_enum_value.proto \ + google/protobuf/map_lite_unittest.proto \ + google/protobuf/map_proto2_unittest.proto \ + google/protobuf/map_unittest.proto \ + google/protobuf/unittest.proto \ + google/protobuf/unittest_arena.proto \ + google/protobuf/unittest_custom_options.proto \ + google/protobuf/unittest_drop_unknown_fields.proto \ + google/protobuf/unittest_embed_optimize_for.proto \ + google/protobuf/unittest_empty.proto \ + google/protobuf/unittest_enormous_descriptor.proto \ + google/protobuf/unittest_import.proto \ + google/protobuf/unittest_import_lite.proto \ + google/protobuf/unittest_import_public.proto \ + google/protobuf/unittest_import_public_lite.proto \ + google/protobuf/unittest_lazy_dependencies.proto \ + google/protobuf/unittest_lazy_dependencies_custom_option.proto \ + google/protobuf/unittest_lazy_dependencies_enum.proto \ + google/protobuf/unittest_lite.proto \ + google/protobuf/unittest_lite_imports_nonlite.proto \ + google/protobuf/unittest_mset.proto \ + google/protobuf/unittest_mset_wire_format.proto \ + google/protobuf/unittest_no_field_presence.proto \ + google/protobuf/unittest_no_generic_services.proto \ + google/protobuf/unittest_optimize_for.proto \ + google/protobuf/unittest_preserve_unknown_enum.proto \ + google/protobuf/unittest_preserve_unknown_enum2.proto \ + google/protobuf/unittest_proto3.proto \ + google/protobuf/unittest_proto3_arena.proto \ + google/protobuf/unittest_proto3_arena_lite.proto \ + google/protobuf/unittest_proto3_lite.proto \ + google/protobuf/unittest_proto3_optional.proto \ + google/protobuf/unittest_well_known_types.proto \ + google/protobuf/util/internal/testdata/anys.proto \ + google/protobuf/util/internal/testdata/books.proto \ + google/protobuf/util/internal/testdata/default_value.proto \ + google/protobuf/util/internal/testdata/default_value_test.proto \ + google/protobuf/util/internal/testdata/field_mask.proto \ + google/protobuf/util/internal/testdata/maps.proto \ + google/protobuf/util/internal/testdata/oneofs.proto \ + google/protobuf/util/internal/testdata/proto3.proto \ + google/protobuf/util/internal/testdata/struct.proto \ + google/protobuf/util/internal/testdata/timestamp_duration.proto \ + google/protobuf/util/internal/testdata/wrappers.proto \ + google/protobuf/util/json_format.proto \ + google/protobuf/util/json_format_proto3.proto \ + google/protobuf/util/message_differencer_unittest.proto + +EXTRA_DIST = \ + $(protoc_inputs) \ + README.md \ + google/protobuf/compiler/package_info.h \ + google/protobuf/compiler/ruby/ruby_generated_code.proto \ + google/protobuf/compiler/ruby/ruby_generated_code_pb.rb \ + google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto \ + google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto \ + google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb \ + google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto \ + google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto \ + google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy_pb.rb \ + google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_pb.rb \ + google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto \ + google/protobuf/compiler/ruby/ruby_generated_pkg_implicit_pb.rb \ + google/protobuf/compiler/zip_output_unittest.sh \ + google/protobuf/io/gzip_stream.h \ + google/protobuf/io/gzip_stream_unittest.sh \ + google/protobuf/io/package_info.h \ + google/protobuf/package_info.h \ + google/protobuf/test_messages_proto2.proto \ + google/protobuf/test_messages_proto3.proto \ + google/protobuf/testdata/bad_utf8_string \ + google/protobuf/testdata/golden_message \ + google/protobuf/testdata/golden_message_maps \ + google/protobuf/testdata/golden_message_oneof_implemented \ + google/protobuf/testdata/golden_message_proto3 \ + google/protobuf/testdata/golden_packed_fields_message \ + google/protobuf/testdata/map_test_data.txt \ + google/protobuf/testdata/text_format_unittest_data.txt \ + google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt \ + google/protobuf/testdata/text_format_unittest_data_pointy.txt \ + google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt \ + google/protobuf/testdata/text_format_unittest_extensions_data.txt \ + google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt \ + google/protobuf/util/package_info.h \ + libprotobuf-lite.map \ + libprotobuf.map \ + libprotoc.map \ + solaris/libstdc++.la + +protoc_lite_outputs = \ + google/protobuf/map_lite_unittest.pb.cc \ + google/protobuf/map_lite_unittest.pb.h \ + google/protobuf/unittest_import_lite.pb.cc \ + google/protobuf/unittest_import_lite.pb.h \ + google/protobuf/unittest_import_public_lite.pb.cc \ + google/protobuf/unittest_import_public_lite.pb.h \ + google/protobuf/unittest_lite.pb.cc \ + google/protobuf/unittest_lite.pb.h + +protoc_outputs = \ + $(protoc_lite_outputs) \ + google/protobuf/any_test.pb.cc \ + google/protobuf/any_test.pb.h \ + google/protobuf/compiler/cpp/test_bad_identifiers.pb.cc \ + google/protobuf/compiler/cpp/test_bad_identifiers.pb.h \ + google/protobuf/compiler/cpp/test_large_enum_value.pb.cc \ + google/protobuf/compiler/cpp/test_large_enum_value.pb.h \ + google/protobuf/map_proto2_unittest.pb.cc \ + google/protobuf/map_proto2_unittest.pb.h \ + google/protobuf/map_unittest.pb.cc \ + google/protobuf/map_unittest.pb.h \ + google/protobuf/unittest.pb.cc \ + google/protobuf/unittest.pb.h \ + google/protobuf/unittest_arena.pb.cc \ + google/protobuf/unittest_arena.pb.h \ + google/protobuf/unittest_custom_options.pb.cc \ + google/protobuf/unittest_custom_options.pb.h \ + google/protobuf/unittest_drop_unknown_fields.pb.cc \ + google/protobuf/unittest_drop_unknown_fields.pb.h \ + google/protobuf/unittest_embed_optimize_for.pb.cc \ + google/protobuf/unittest_embed_optimize_for.pb.h \ + google/protobuf/unittest_empty.pb.cc \ + google/protobuf/unittest_empty.pb.h \ + google/protobuf/unittest_enormous_descriptor.pb.cc \ + google/protobuf/unittest_enormous_descriptor.pb.h \ + google/protobuf/unittest_import.pb.cc \ + google/protobuf/unittest_import.pb.h \ + google/protobuf/unittest_import_public.pb.cc \ + google/protobuf/unittest_import_public.pb.h \ + google/protobuf/unittest_lazy_dependencies.pb.cc \ + google/protobuf/unittest_lazy_dependencies.pb.h \ + google/protobuf/unittest_lazy_dependencies_custom_option.pb.cc \ + google/protobuf/unittest_lazy_dependencies_custom_option.pb.h \ + google/protobuf/unittest_lazy_dependencies_enum.pb.cc \ + google/protobuf/unittest_lazy_dependencies_enum.pb.h \ + google/protobuf/unittest_lite_imports_nonlite.pb.cc \ + google/protobuf/unittest_lite_imports_nonlite.pb.h \ + google/protobuf/unittest_mset.pb.cc \ + google/protobuf/unittest_mset.pb.h \ + google/protobuf/unittest_mset_wire_format.pb.cc \ + google/protobuf/unittest_mset_wire_format.pb.h \ + google/protobuf/unittest_no_field_presence.pb.cc \ + google/protobuf/unittest_no_field_presence.pb.h \ + google/protobuf/unittest_no_generic_services.pb.cc \ + google/protobuf/unittest_no_generic_services.pb.h \ + google/protobuf/unittest_optimize_for.pb.cc \ + google/protobuf/unittest_optimize_for.pb.h \ + google/protobuf/unittest_preserve_unknown_enum.pb.cc \ + google/protobuf/unittest_preserve_unknown_enum.pb.h \ + google/protobuf/unittest_preserve_unknown_enum2.pb.cc \ + google/protobuf/unittest_preserve_unknown_enum2.pb.h \ + google/protobuf/unittest_proto3.pb.cc \ + google/protobuf/unittest_proto3.pb.h \ + google/protobuf/unittest_proto3_arena.pb.cc \ + google/protobuf/unittest_proto3_arena.pb.h \ + google/protobuf/unittest_proto3_arena_lite.pb.cc \ + google/protobuf/unittest_proto3_arena_lite.pb.h \ + google/protobuf/unittest_proto3_lite.pb.cc \ + google/protobuf/unittest_proto3_lite.pb.h \ + google/protobuf/unittest_proto3_optional.pb.cc \ + google/protobuf/unittest_proto3_optional.pb.h \ + google/protobuf/unittest_well_known_types.pb.cc \ + google/protobuf/unittest_well_known_types.pb.h \ + google/protobuf/util/internal/testdata/anys.pb.cc \ + google/protobuf/util/internal/testdata/anys.pb.h \ + google/protobuf/util/internal/testdata/books.pb.cc \ + google/protobuf/util/internal/testdata/books.pb.h \ + google/protobuf/util/internal/testdata/default_value.pb.cc \ + google/protobuf/util/internal/testdata/default_value.pb.h \ + google/protobuf/util/internal/testdata/default_value_test.pb.cc \ + google/protobuf/util/internal/testdata/default_value_test.pb.h \ + google/protobuf/util/internal/testdata/field_mask.pb.cc \ + google/protobuf/util/internal/testdata/field_mask.pb.h \ + google/protobuf/util/internal/testdata/maps.pb.cc \ + google/protobuf/util/internal/testdata/maps.pb.h \ + google/protobuf/util/internal/testdata/oneofs.pb.cc \ + google/protobuf/util/internal/testdata/oneofs.pb.h \ + google/protobuf/util/internal/testdata/proto3.pb.cc \ + google/protobuf/util/internal/testdata/proto3.pb.h \ + google/protobuf/util/internal/testdata/struct.pb.cc \ + google/protobuf/util/internal/testdata/struct.pb.h \ + google/protobuf/util/internal/testdata/timestamp_duration.pb.cc \ + google/protobuf/util/internal/testdata/timestamp_duration.pb.h \ + google/protobuf/util/internal/testdata/wrappers.pb.cc \ + google/protobuf/util/internal/testdata/wrappers.pb.h \ + google/protobuf/util/json_format.pb.cc \ + google/protobuf/util/json_format.pb.h \ + google/protobuf/util/json_format_proto3.pb.cc \ + google/protobuf/util/json_format_proto3.pb.h \ + google/protobuf/util/message_differencer_unittest.pb.cc \ + google/protobuf/util/message_differencer_unittest.pb.h + +if USE_EXTERNAL_PROTOC + +unittest_proto_middleman: $(protoc_inputs) + $(PROTOC) -I$(srcdir) --cpp_out=. $^ + touch unittest_proto_middleman + +else + +# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is +# relative to srcdir, which may not be the same as the current directory when +# building out-of-tree. +unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs) + oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) --experimental_allow_proto3_optional ) + touch unittest_proto_middleman + +endif + +$(protoc_outputs): unittest_proto_middleman + +COMMON_TEST_SOURCES = \ + $(COMMON_LITE_TEST_SOURCES) \ + google/protobuf/compiler/cpp/unittest.h \ + google/protobuf/map_test_util.h \ + google/protobuf/map_test_util.inc \ + google/protobuf/reflection_tester.cc \ + google/protobuf/reflection_tester.h \ + google/protobuf/test_util.cc \ + google/protobuf/test_util.h \ + google/protobuf/test_util.inc \ + google/protobuf/test_util2.h \ + google/protobuf/testing/file.cc \ + google/protobuf/testing/file.h \ + google/protobuf/testing/googletest.cc \ + google/protobuf/testing/googletest.h + +GOOGLETEST_BUILD_DIR=../third_party/googletest/googletest +GOOGLEMOCK_BUILD_DIR=../third_party/googletest/googlemock +GOOGLETEST_SRC_DIR=$(srcdir)/../third_party/googletest/googletest +GOOGLEMOCK_SRC_DIR=$(srcdir)/../third_party/googletest/googlemock +check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \ + protobuf-lite-test test_plugin protobuf-lite-arena-test \ + no-warning-test $(GZCHECKPROGRAMS) +protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_test_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include \ + -I$(GOOGLEMOCK_SRC_DIR)/include +# Disable optimization for tests unless the user explicitly asked for it, +# since test_util.cc takes forever to compile with optimization (with GCC). +# See configure.ac for more info. +protobuf_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) +protobuf_test_SOURCES = \ + $(COMMON_TEST_SOURCES) \ + google/protobuf/any_test.cc \ + google/protobuf/arena_unittest.cc \ + google/protobuf/arenastring_unittest.cc \ + google/protobuf/arenaz_sampler_test.cc \ + google/protobuf/compiler/annotation_test_util.cc \ + google/protobuf/compiler/annotation_test_util.h \ + google/protobuf/compiler/command_line_interface_unittest.cc \ + google/protobuf/compiler/cpp/bootstrap_unittest.cc \ + google/protobuf/compiler/cpp/message_size_unittest.cc \ + google/protobuf/compiler/cpp/metadata_test.cc \ + google/protobuf/compiler/cpp/move_unittest.cc \ + google/protobuf/compiler/cpp/plugin_unittest.cc \ + google/protobuf/compiler/cpp/unittest.cc \ + google/protobuf/compiler/cpp/unittest.inc \ + google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc \ + google/protobuf/compiler/csharp/csharp_generator_unittest.cc \ + google/protobuf/compiler/importer_unittest.cc \ + google/protobuf/compiler/java/doc_comment_unittest.cc \ + google/protobuf/compiler/java/plugin_unittest.cc \ + google/protobuf/compiler/mock_code_generator.cc \ + google/protobuf/compiler/mock_code_generator.h \ + google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc \ + google/protobuf/compiler/parser_unittest.cc \ + google/protobuf/compiler/python/plugin_unittest.cc \ + google/protobuf/compiler/ruby/ruby_generator_unittest.cc \ + google/protobuf/descriptor_database_unittest.cc \ + google/protobuf/descriptor_unittest.cc \ + google/protobuf/drop_unknown_fields_test.cc \ + google/protobuf/dynamic_message_unittest.cc \ + google/protobuf/extension_set_unittest.cc \ + google/protobuf/generated_message_reflection_unittest.cc \ + google/protobuf/generated_message_tctable_lite_test.cc \ + google/protobuf/inlined_string_field_unittest.cc \ + google/protobuf/io/coded_stream_unittest.cc \ + google/protobuf/io/io_win32_unittest.cc \ + google/protobuf/io/printer_unittest.cc \ + google/protobuf/io/tokenizer_unittest.cc \ + google/protobuf/io/zero_copy_stream_unittest.cc \ + google/protobuf/map_field_test.cc \ + google/protobuf/map_test.cc \ + google/protobuf/map_test.inc \ + google/protobuf/message_unittest.cc \ + google/protobuf/message_unittest.inc \ + google/protobuf/no_field_presence_test.cc \ + google/protobuf/preserve_unknown_enum_test.cc \ + google/protobuf/proto3_arena_lite_unittest.cc \ + google/protobuf/proto3_arena_unittest.cc \ + google/protobuf/proto3_lite_unittest.cc \ + google/protobuf/proto3_lite_unittest.inc \ + google/protobuf/reflection_ops_unittest.cc \ + google/protobuf/repeated_field_reflection_unittest.cc \ + google/protobuf/repeated_field_unittest.cc \ + google/protobuf/stubs/bytestream_unittest.cc \ + google/protobuf/stubs/common_unittest.cc \ + google/protobuf/stubs/int128_unittest.cc \ + google/protobuf/stubs/status_test.cc \ + google/protobuf/stubs/statusor_test.cc \ + google/protobuf/stubs/stringpiece_unittest.cc \ + google/protobuf/stubs/stringprintf_unittest.cc \ + google/protobuf/stubs/structurally_valid_unittest.cc \ + google/protobuf/stubs/strutil_unittest.cc \ + google/protobuf/stubs/template_util_unittest.cc \ + google/protobuf/stubs/time_test.cc \ + google/protobuf/text_format_unittest.cc \ + google/protobuf/unknown_field_set_unittest.cc \ + google/protobuf/util/delimited_message_util_test.cc \ + google/protobuf/util/field_comparator_test.cc \ + google/protobuf/util/field_mask_util_test.cc \ + google/protobuf/util/internal/default_value_objectwriter_test.cc \ + google/protobuf/util/internal/json_objectwriter_test.cc \ + google/protobuf/util/internal/json_stream_parser_test.cc \ + google/protobuf/util/internal/protostream_objectsource_test.cc \ + google/protobuf/util/internal/protostream_objectwriter_test.cc \ + google/protobuf/util/internal/type_info_test_helper.cc \ + google/protobuf/util/json_util_test.cc \ + google/protobuf/util/message_differencer_unittest.cc \ + google/protobuf/util/time_util_test.cc \ + google/protobuf/util/type_resolver_util_test.cc \ + google/protobuf/well_known_types_unittest.cc \ + google/protobuf/wire_format_unittest.cc \ + google/protobuf/wire_format_unittest.inc + +nodist_protobuf_test_SOURCES = $(protoc_outputs) +$(am_protobuf_test_OBJECTS): unittest_proto_middleman + +# Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined. +protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \ + libprotoc.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lazy_descriptor_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include \ + -DPROTOBUF_TEST_NO_DESCRIPTORS +protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) +protobuf_lazy_descriptor_test_SOURCES = \ + google/protobuf/compiler/cpp/unittest.cc \ + $(COMMON_TEST_SOURCES) +nodist_protobuf_lazy_descriptor_test_SOURCES = $(protoc_outputs) +$(am_protobuf_lazy_descriptor_test_OBJECTS): unittest_proto_middleman + +COMMON_LITE_TEST_SOURCES = \ + google/protobuf/arena_test_util.cc \ + google/protobuf/arena_test_util.h \ + google/protobuf/map_lite_test_util.cc \ + google/protobuf/map_lite_test_util.h \ + google/protobuf/map_test_util_impl.h \ + google/protobuf/test_util_lite.cc \ + google/protobuf/test_util_lite.h + +# Build lite_unittest separately, since it doesn't use gtest. It can't +# depend on gtest because our internal version of gtest depend on proto +# full runtime and we want to make sure this test builds without full +# runtime. +protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lite_test_CPPFLAGS= -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include +protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) +protobuf_lite_test_SOURCES = \ + google/protobuf/lite_unittest.cc \ + $(COMMON_LITE_TEST_SOURCES) +nodist_protobuf_lite_test_SOURCES = $(protoc_lite_outputs) +$(am_protobuf_lite_test_OBJECTS): unittest_proto_middleman + +# lite_arena_unittest depends on gtest because teboring@ found that without +# gtest when building the test internally our memory sanitizer doesn't detect +# memory leaks (don't know why). +protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock.la \ + $(GOOGLEMOCK_BUILD_DIR)/lib/libgmock_main.la +protobuf_lite_arena_test_CPPFLAGS = -I$(GOOGLEMOCK_SRC_DIR)/include \ + -I$(GOOGLETEST_SRC_DIR)/include +protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS) +protobuf_lite_arena_test_SOURCES = \ + google/protobuf/lite_arena_unittest.cc \ + $(COMMON_LITE_TEST_SOURCES) +nodist_protobuf_lite_arena_test_SOURCES = $(protoc_lite_outputs) +$(am_protobuf_lite_arena_test_OBJECTS): unittest_proto_middleman + +# Test plugin binary. +test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ + $(GOOGLETEST_BUILD_DIR)/lib/libgtest.la +test_plugin_CPPFLAGS = -I$(GOOGLETEST_SRC_DIR)/include +test_plugin_SOURCES = \ + google/protobuf/compiler/mock_code_generator.cc \ + google/protobuf/compiler/test_plugin.cc \ + google/protobuf/testing/file.cc \ + google/protobuf/testing/file.h + +if HAVE_ZLIB +zcgzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la +zcgzip_SOURCES = google/protobuf/testing/zcgzip.cc + +zcgunzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la +zcgunzip_SOURCES = google/protobuf/testing/zcgunzip.cc +endif + +# This test target is to ensure all our public header files and generated +# code is free from warnings. We have to be more pedantic about these +# files because they are compiled by users with different compiler flags. +no_warning_test.cc: + echo "// Generated from Makefile.am" > no_warning_test.cc + for FILE in $(nobase_include_HEADERS); do \ + case $$FILE in *.inc) continue;; esac; \ + echo "#include <$${FILE}>" >> no_warning_test.cc; \ + done + echo "int main(int, char**) { return 0; }" >> no_warning_test.cc + +no_warning_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la +no_warning_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) \ + -Wall -Wextra -Werror -Wno-unused-parameter +nodist_no_warning_test_SOURCES = no_warning_test.cc $(protoc_outputs) + +TESTS = protobuf-test protobuf-lazy-descriptor-test protobuf-lite-test \ + google/protobuf/compiler/zip_output_unittest.sh $(GZTESTS) \ + protobuf-lite-arena-test no-warning-test diff --git a/libs/protobuf/src/README.md b/libs/protobuf/src/README.md index b28b0f0..cf843d7 100644 --- a/libs/protobuf/src/README.md +++ b/libs/protobuf/src/README.md @@ -5,31 +5,26 @@ Copyright 2008 Google Inc. https://developers.google.com/protocol-buffers/ -CMake Installation ------------------------ - -To compile or install protobuf from source using CMake, see -[cmake/README.md](../cmake/README.md). - -C++ Protobuf - Unix +C++ Installation - Unix ----------------------- To build protobuf from source, the following tools are needed: - * bazel - * git + * autoconf + * automake + * libtool + * make * g++ + * unzip -On Ubuntu/Debian, for example, you can install them with: +On Ubuntu/Debian, you can install them with: - sudo apt-get install g++ git bazel + sudo apt-get install autoconf automake libtool curl make g++ unzip On other platforms, please use the corresponding package managing tool to -install them before proceeding. See https://bazel.build/install for further -instructions on installing Bazel, or to build from source using CMake, see -[cmake/README.md](../cmake/README.md). +install them before proceeding. -To get the source, download the release .tar.gz or .zip package in the +To get the source, download one of the release .tar.gz or .zip packages in the release page: https://github.com/protocolbuffers/protobuf/releases/latest @@ -46,23 +41,79 @@ if you are using a release .tar.gz or .zip package): git clone https://github.com/protocolbuffers/protobuf.git cd protobuf git submodule update --init --recursive + ./autogen.sh -To build the C++ Protocol Buffer runtime and the Protocol Buffer compiler -(protoc) execute the following: +To build and install the C++ Protocol Buffer runtime and the Protocol +Buffer compiler (protoc) execute the following: - bazel build :protoc :protobuf -The compiler can then be installed, for example on Linux: + ./configure + make -j$(nproc) # $(nproc) ensures it uses all cores for compilation + make check + sudo make install + sudo ldconfig # refresh shared library cache. - cp bazel-bin/protoc /usr/local/bin +If "make check" fails, you can still install, but it is likely that +some features of this library will not work correctly on your system. +Proceed at your own risk. -For more usage information on Bazel, please refer to http://bazel.build. +For advanced usage information on configure and make, please refer to the +autoconf documentation: + + http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts + +**Hint on install location** + +By default, the package will be installed to /usr/local. However, +on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH. +You can add it, but it may be easier to just install to /usr +instead. To do this, invoke configure as follows: + + ./configure --prefix=/usr + +If you already built the package with a different prefix, make sure +to run "make clean" before building again. **Compiling dependent packages** -To compile a package that uses Protocol Buffers, you need to setup a Bazel -WORKSPACE that's hooked up to the protobuf repository and loads its -dependencies. For an example, see [WORKSPACE](../examples/WORKSPACE). +To compile a package that uses Protocol Buffers, you need to pass +various flags to your compiler and linker. As of version 2.2.0, +Protocol Buffers integrates with pkg-config to manage this. If you +have pkg-config installed, then you can invoke it to get a list of +flags like so: + + + pkg-config --cflags protobuf # print compiler flags + pkg-config --libs protobuf # print linker flags + pkg-config --cflags --libs protobuf # print both + + +For example: + + c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf` + +Note that packages written prior to the 2.2.0 release of Protocol +Buffers may not yet integrate with pkg-config to get flags, and may +not pass the correct set of flags to correctly link against +libprotobuf. If the package in question uses autoconf, you can +often fix the problem by invoking its configure script like: + + + configure CXXFLAGS="$(pkg-config --cflags protobuf)" \ + LIBS="$(pkg-config --libs protobuf)" + +This will force it to use the correct flags. + +If you are writing an autoconf-based package that uses Protocol +Buffers, you should probably use the PKG_CHECK_MODULES macro in your +configure script like: + + PKG_CHECK_MODULES([protobuf], [protobuf]) + +See the pkg-config man page for more info. + +If you only want protobuf-lite, substitute "protobuf-lite" in place +of "protobuf" in these examples. **Note for Mac users** @@ -76,16 +127,64 @@ To install Unix tools, you can install "port" following the instructions at https://www.macports.org . This will reside in /opt/local/bin/port for most Mac installations. - sudo /opt/local/bin/port install bazel + sudo /opt/local/bin/port install autoconf automake libtool Alternative for Homebrew users: - brew install bazel + brew install autoconf automake libtool Then follow the Unix instructions above. +**Note for cross-compiling** -C++ Protobuf - Windows +The makefiles normally invoke the protoc executable that they just +built in order to build tests. When cross-compiling, the protoc +executable may not be executable on the host machine. In this case, +you must build a copy of protoc for the host machine first, then use +the --with-protoc option to tell configure to use it instead. For +example: + + ./configure --with-protoc=protoc + +This will use the installed protoc (found in your $PATH) instead of +trying to execute the one built during the build process. You can +also use an executable that hasn't been installed. For example, if +you built the protobuf package for your host machine in ../host, +you might do: + + ./configure --with-protoc=../host/src/protoc + +Either way, you must make sure that the protoc executable you use +has the same version as the protobuf source code you are trying to +use it with. + +**Note for Solaris users** + +Solaris 10 x86 has a bug that will make linking fail, complaining +about libstdc++.la being invalid. We have included a work-around +in this package. To use the work-around, run configure as follows: + + ./configure LDFLAGS=-L$PWD/src/solaris + +See src/solaris/libstdc++.la for more info on this bug. + +**Note for HP C++ Tru64 users** + +To compile invoke configure as follows: + + ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM" + +Also, you will need to use gmake instead of make. + +**Note for AIX users** + +Compile using the IBM xlC C++ compiler as follows: + + ./configure CXX=xlC + +Also, you will need to use GNU `make` (`gmake`) instead of AIX `make`. + +C++ Installation - Windows -------------------------- If you only need the protoc binary, you can download it from the release @@ -121,10 +220,10 @@ That is, if you linked an executable against an older version of libprotobuf, it is unlikely to work with a newer version without re-compiling. This problem, when it occurs, will normally be detected immediately on startup of your app. Still, you may want to consider -using static linkage. You can configure this in your `cc_binary` Bazel rules -by specifying: +using static linkage. You can configure this package to install +static libraries only using: - linkstatic=True + ./configure --disable-shared Usage ----- diff --git a/libs/protobuf/src/file_lists.cmake b/libs/protobuf/src/file_lists.cmake deleted file mode 100644 index 1626c92..0000000 --- a/libs/protobuf/src/file_lists.cmake +++ /dev/null @@ -1,732 +0,0 @@ -# Auto-generated by //pkg:gen_src_file_lists_cmake -# -# This file contains lists of sources based on Bazel rules. It should -# be included from a hand-written CMake file that defines targets. -# -# Changes to this file will be overwritten based on Bazel definitions. - -if(${CMAKE_VERSION} VERSION_GREATER 3.10 OR ${CMAKE_VERSION} VERSION_EQUAL 3.10) - include_guard() -endif() - -# //pkg:protobuf -set(libprotobuf_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_heavy.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_full.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_gen.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/gzip_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/strtod.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_sink.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/lexer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/message_path.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/untyped_message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/writer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/zero_copy_buffered_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/json.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/service.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc -) - -# //pkg:protobuf -set(libprotobuf_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/api.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/type.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_allocation_policy.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_cleanup.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_inl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/field_access_listener.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_reflection.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_bases.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_decl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_gen.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/has_bits.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/gzip_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/strtod.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_sink.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/descriptor_traits.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/lexer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/message_path.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/parser_traits.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/unparser_traits.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/untyped_message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/writer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/internal/zero_copy_buffered_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/json/json.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_inl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_type_handler.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/port.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/port_def.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/port_undef.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_internal.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/service.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h -) - -# //pkg:protobuf_lite -set(libprotobuf_lite_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.cc -) - -# //pkg:protobuf_lite -set(libprotobuf_lite_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_allocation_policy.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_cleanup.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_config.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/endian.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/explicitly_constructed.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_inl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_enum_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_decl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/has_bits.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/implicit_weak_message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_impl_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_entry_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_type_handler.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/metadata_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/parse_context.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/port.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_ptr_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/callback.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/logging.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/mathutil.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/platform_macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/port.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/status_macros.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_lite.h -) - -# //pkg:protoc -set(libprotoc_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/code_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/extension.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/file.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/helpers.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/map_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/padding_optimizer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/parse_function_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/primitive_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/service.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/string_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_field_base.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_helpers.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_map_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/file.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_factory.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/helpers.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/extension.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/file.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/helpers.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/import_writer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/line_consumer.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/map_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/message.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/message_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/names.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/oneof.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/primitive_field.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/names.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/helpers.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/pyi_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/subprocess.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/zip_writer.cc -) - -# //pkg:protoc -set(libprotoc_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/code_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/enum_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/extension.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/file.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/helpers.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/map_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_layout_helper.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/names.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/options.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/padding_optimizer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/parse_function_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/primitive_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/service.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/string_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_doc_comment.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_enum_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_field_base.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_helpers.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_map_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_message_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_options.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_primitive_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_reflection_class.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/file.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_factory.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/helpers.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/options.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/extension.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/file.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/helpers.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/import_writer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/line_consumer.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/map_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/message.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/message_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/names.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/nsobject_methods.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/oneof.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/options.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/primitive_field.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/text_format_decode_data.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/names.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/php/php_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.pb.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/helpers.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/pyi_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/scc.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/subprocess.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/zip_writer.h -) - -# //src/google/protobuf:well_known_type_protos -set(wkt_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/any.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/api.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/duration.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/empty.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/field_mask.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/source_context.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/struct.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/timestamp.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/type.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/wrappers.proto -) - -# //src/google/protobuf:descriptor_proto -set(descriptor_proto_proto_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.proto -) - -# //src/google/protobuf:descriptor_proto -set(descriptor_proto_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.proto.pb.cc -) - -# //src/google/protobuf:descriptor_proto -set(descriptor_proto_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor.proto.pb.h -) - -# //src/google/protobuf:descriptor_proto -set(descriptor_proto_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_proto-descriptor-set.proto.bin -) - -# //src/google/protobuf/compiler:plugin_proto -set(plugin_proto_proto_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.proto -) - -# //src/google/protobuf/compiler:plugin_proto -set(plugin_proto_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.proto.pb.cc -) - -# //src/google/protobuf/compiler:plugin_proto -set(plugin_proto_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin.proto.pb.h -) - -# //src/google/protobuf/compiler:plugin_proto -set(plugin_proto_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/plugin_proto-descriptor-set.proto.bin -) - -# //pkg:common_test -set(common_test_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.cc -) - -# //pkg:common_test -set(common_test_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/mock_code_generator.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/file.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/testing/googletest.h -) - -# //pkg:lite_test_util -set(lite_test_util_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_test_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_test_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.cc -) - -# //pkg:lite_test_util -set(lite_test_util_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_test_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_test_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util_impl.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_lite_unittest.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.h -) - -# //pkg:test_util -set(test_util_srcs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.cc -) - -# //pkg:test_util -set(test_util_hdrs - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/annotation_test_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_unittest.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.inc - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util2.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util_lite.h - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.inc -) - -# //src/google/protobuf:full_test_srcs -set(protobuf_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_align_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arena_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenastring_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/arenaz_sampler_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_database_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/descriptor_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/drop_unknown_fields_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/dynamic_message_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/extension_set_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_reflection_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/generated_message_tctable_lite_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/inlined_string_field_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_field_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/message_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/no_field_presence_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/preserve_unknown_enum_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_arena_lite_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_arena_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/proto3_lite_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_ops_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field_reflection_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/text_format_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/unknown_field_set_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/well_known_types_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/wire_format_unittest.cc -) - -# //src/google/protobuf:test_proto_srcs -set(protobuf_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/any_test.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_proto2_unittest.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_unittest.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_arena.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_custom_options.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_drop_unknown_fields.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_embed_optimize_for.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_empty.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_enormous_descriptor.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_custom_option.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lazy_dependencies_enum.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite_imports_nonlite.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_mset_wire_format.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_field_presence.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_no_generic_services.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_optimize_for.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_preserve_unknown_enum2.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_arena_lite.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_lite.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_proto3_optional.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_well_known_types.proto -) - -# //src/google/protobuf:lite_test_srcs -set(protobuf_lite_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_arena_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/lite_unittest.cc -) - -# //src/google/protobuf:lite_test_proto_srcs -set(protobuf_lite_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/map_lite_unittest.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_lite.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_import_public_lite.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/unittest_lite.proto -) - -# //src/google/protobuf/compiler:test_srcs -set(compiler_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/command_line_interface_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/message_size_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/metadata_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/move_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/plugin_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/importer_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/plugin_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/line_consumer_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/names_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/text_format_decode_data_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/parser_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/python/plugin_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc -) - -# //src/google/protobuf/compiler:test_proto_srcs -set(compiler_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/cpp/test_large_enum_value.proto -) - -# //src/google/protobuf/compiler:test_plugin_srcs -set(test_plugin_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/test_plugin.cc -) - -# //src/google/protobuf/io:test_srcs -set(io_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/coded_stream_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/io_win32_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer_death_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/printer_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/tokenizer_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_sink_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/io/zero_copy_stream_unittest.cc -) - -# //src/google/protobuf/util:test_srcs -set(util_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/delimited_message_util_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_comparator_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/field_mask_util_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/time_util_test.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/type_resolver_util_test.cc -) - -# //src/google/protobuf/util:test_proto_srcs -set(util_test_protos_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_format.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/json_format_proto3.proto - ${protobuf_SOURCE_DIR}/src/google/protobuf/util/message_differencer_unittest.proto -) - -# //src/google/protobuf/stubs:test_srcs -set(stubs_test_files - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/bytestream_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/common_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/structurally_valid_unittest.cc - ${protobuf_SOURCE_DIR}/src/google/protobuf/stubs/strutil_unittest.cc -) diff --git a/libs/protobuf/src/google/protobuf/BUILD.bazel b/libs/protobuf/src/google/protobuf/BUILD.bazel deleted file mode 100644 index fedc0f4..0000000 --- a/libs/protobuf/src/google/protobuf/BUILD.bazel +++ /dev/null @@ -1,1291 +0,0 @@ -################################################################################ -# Protocol Buffers: C++ Runtime and common proto files -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_proto//proto:defs.bzl", "proto_library") -load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") - -package( - default_visibility = [ - "//:__pkg__", # "public" targets are alias rules in //. - "//json:__subpackages__", - ], -) - -proto_library( - name = "any_proto", - srcs = ["any.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "api_proto", - srcs = ["api.proto"], - strip_import_prefix = "/src", - deps = [ - "//:source_context_proto", - "//:type_proto", - ], -) - -proto_library( - name = "duration_proto", - srcs = ["duration.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "empty_proto", - srcs = ["empty.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "field_mask_proto", - srcs = ["field_mask.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "source_context_proto", - srcs = ["source_context.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "struct_proto", - srcs = ["struct.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "timestamp_proto", - srcs = ["timestamp.proto"], - strip_import_prefix = "/src", -) - -proto_library( - name = "type_proto", - srcs = ["type.proto"], - strip_import_prefix = "/src", - deps = [ - "//:any_proto", - "//:source_context_proto", - ], -) - -proto_library( - name = "wrappers_proto", - srcs = ["wrappers.proto"], - strip_import_prefix = "/src", -) - -# Generate code for the well-known types on demand. -# This needs to be done in a separate genrule because we publish protoc and the -# C++ runtime with the WKT code linked in. We need to use a stripped down -# compiler and runtime library to generate them, and cc_proto_library doesn't -# support swapping out the compiler binary (even though a custom runtime can -# be passed to proto_lang_toolchain). -# -# TODO(b/246826624) We still check in generated pb.h and pb.cc files purely to -# support CMake builds. These aren't used at all by Bazel and will be removed -# in the future once CMake can generate them too. - -WELL_KNOWN_TYPES = [ - "any", - "api", - "duration", - "empty", - "field_mask", - "source_context", - "struct", - "timestamp", - "type", - "wrappers", -] - -genrule( - name = "gen_wkt_cc_sources", - srcs = [wkt + ".proto" for wkt in WELL_KNOWN_TYPES], - outs = - [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES] + - [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], - cmd = """ - $(execpath //src/google/protobuf/compiler:protoc_nowkt) \ - --cpp_out=$(RULEDIR)/../.. \ - --proto_path=$$(dirname $$(dirname $$(dirname $(location any.proto)))) \ - $(SRCS) - """, - exec_tools = ["//src/google/protobuf/compiler:protoc_nowkt"], - visibility = ["//visibility:private"], -) - -cc_library( - name = "wkt_cc_proto", - srcs = [wkt + ".pb.cc" for wkt in WELL_KNOWN_TYPES], - hdrs = [wkt + ".pb.h" for wkt in WELL_KNOWN_TYPES], - copts = COPTS, - include_prefix = "google/protobuf", - linkopts = LINK_OPTS, - visibility = ["//pkg:__pkg__"], - deps = [":protobuf_nowkt"], -) - -# Built-in runtime types - -proto_library( - name = "descriptor_proto", - srcs = ["descriptor.proto"], - strip_import_prefix = "/src", - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - ], -) - -################################################################################ -# C++ Runtime Library -################################################################################ - -cc_library( - name = "port_def", - hdrs = [ - "port.h", - "port_def.inc", - "port_undef.inc", - ], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], -) - -cc_library( - name = "arena_align", - srcs = ["arena_align.cc"], - hdrs = ["arena_align.h"], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - "//src/google/protobuf/stubs:lite", - "@com_google_absl//absl/numeric:bits", - ], -) - -cc_library( - name = "arena_cleanup", - hdrs = ["arena_cleanup.h"], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - "@com_google_absl//absl/base:core_headers", - ], -) - -cc_library( - name = "arena_config", - srcs = ["arena_config.cc"], - hdrs = ["arena_config.h"], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - "//src/google/protobuf/stubs:lite", - ], -) - -cc_library( - name = "arena_allocation_policy", - hdrs = ["arena_allocation_policy.h"], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":arena_config", - "//src/google/protobuf/stubs:lite", - ], -) - -cc_library( - name = "arena", - srcs = [ - "arena.cc", - ], - hdrs = [ - "arena.h", - "arena_config.h", - "arena_impl.h", - "arenaz_sampler.h", - ], - include_prefix = "google/protobuf", - visibility = [ - "//:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":arena_allocation_policy", - ":arena_cleanup", - ":arena_config", - "//src/google/protobuf/stubs:lite", - "@com_google_absl//absl/synchronization", - ], -) - -cc_library( - name = "protobuf_lite", - srcs = [ - "any_lite.cc", - "arenastring.cc", - "arenaz_sampler.cc", - "extension_set.cc", - "generated_enum_util.cc", - "generated_message_tctable_lite.cc", - "generated_message_util.cc", - "implicit_weak_message.cc", - "inlined_string_field.cc", - "map.cc", - "message_lite.cc", - "parse_context.cc", - "repeated_field.cc", - "repeated_ptr_field.cc", - "wire_format_lite.cc", - ], - hdrs = [ - "any.h", - "arena.h", - "arena_impl.h", - "arenastring.h", - "arenaz_sampler.h", - "endian.h", - "explicitly_constructed.h", - "extension_set.h", - "extension_set_inl.h", - "generated_enum_util.h", - "generated_message_tctable_decl.h", - "generated_message_tctable_impl.h", - "generated_message_util.h", - "has_bits.h", - "implicit_weak_message.h", - "inlined_string_field.h", - "map.h", - "map_entry_lite.h", - "map_field_lite.h", - "map_type_handler.h", - "message_lite.h", - "metadata_lite.h", - "parse_context.h", - "port.h", - "repeated_field.h", - "repeated_ptr_field.h", - "wire_format_lite.h", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error", - ], - }), - include_prefix = "google/protobuf", - linkopts = LINK_OPTS, - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - "//src/google/protobuf:__subpackages__", - ], - # In Bazel 6.0+, these will be `interface_deps`: - deps = [ - ":arena", - ":arena_config", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs:lite", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/numeric:bits", - "@com_google_absl//absl/strings:internal", - "@com_google_absl//absl/synchronization", - "@com_google_absl//absl/time", - ], -) - -cc_library( - name = "protobuf_nowkt", - srcs = [ - "any.cc", - "descriptor.cc", - "descriptor.pb.cc", - "descriptor_database.cc", - "dynamic_message.cc", - "extension_set_heavy.cc", - "generated_message_bases.cc", - "generated_message_reflection.cc", - "generated_message_tctable_full.cc", - "generated_message_tctable_gen.cc", - "map_field.cc", - "message.cc", - "reflection_ops.cc", - "service.cc", - "text_format.cc", - "unknown_field_set.cc", - "wire_format.cc", - ], - hdrs = [ - "descriptor.h", - "descriptor.pb.h", - "descriptor_database.h", - "dynamic_message.h", - "field_access_listener.h", - "generated_enum_reflection.h", - "generated_message_bases.h", - "generated_message_reflection.h", - "generated_message_tctable_gen.h", - "map_entry.h", - "map_field.h", - "map_field_inl.h", - "message.h", - "metadata.h", - "reflection.h", - "reflection_internal.h", - "reflection_ops.h", - "service.h", - "text_format.h", - "unknown_field_set.h", - "wire_format.h", - ], - copts = COPTS, - include_prefix = "google/protobuf", - linkopts = LINK_OPTS, - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":protobuf_lite", - "//src/google/protobuf/io", - "//src/google/protobuf/io:gzip_stream", - "//src/google/protobuf/io:printer", - "//src/google/protobuf/io:tokenizer", - "//src/google/protobuf/stubs", - "@com_google_absl//absl/base", - "@com_google_absl//absl/base:dynamic_annotations", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/hash", - "@com_google_absl//absl/strings:internal", - "@com_google_absl//absl/synchronization", - "@com_google_absl//absl/time", - ], -) - -cc_library( - name = "protobuf", - copts = COPTS, - include_prefix = "google/protobuf", - linkopts = LINK_OPTS, - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":protobuf_nowkt", - ":wkt_cc_proto", - ], -) - -# This provides just the header files for use in projects that need to build -# shared libraries for dynamic loading. This target is available until Bazel -# adds native support for such use cases. -# TODO(keveman): Remove this target once the support gets added to Bazel. -cc_library( - name = "protobuf_headers", - hdrs = glob([ - "**/*.h", - "**/*.inc", - ]), -) - -filegroup( - name = "well_known_type_protos", - srcs = [ - "any.proto", - "api.proto", - "duration.proto", - "empty.proto", - "field_mask.proto", - "source_context.proto", - "struct.proto", - "timestamp.proto", - "type.proto", - "wrappers.proto", - ], - visibility = ["//:__subpackages__"], -) - -filegroup( - name = "descriptor_proto_srcs", - srcs = ["descriptor.proto"], - visibility = ["//:__subpackages__"], -) - -filegroup( - name = "testdata", - srcs = glob(["testdata/**/*"]) + [ - "descriptor.cc", - ], - visibility = [ - "//:__subpackages__", - "@upb//:__subpackages__", - ], -) - -filegroup( - name = "lite_test_proto_srcs", - srcs = [ - "map_lite_unittest.proto", - "unittest_import_lite.proto", - "unittest_import_public_lite.proto", - "unittest_lite.proto", - ], - visibility = ["//:__subpackages__"], -) - -proto_library( - name = "lite_test_protos", - srcs = [":lite_test_proto_srcs"], - strip_import_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - ":any_proto", - ":api_proto", - ":descriptor_proto", - ":duration_proto", - ":empty_proto", - ":field_mask_proto", - ":source_context_proto", - ":struct_proto", - ":timestamp_proto", - ":type_proto", - ":wrappers_proto", - ], -) - -filegroup( - name = "test_proto_srcs", - srcs = [ - "any_test.proto", - "map_proto2_unittest.proto", - "map_unittest.proto", - "unittest.proto", - "unittest_arena.proto", - "unittest_custom_options.proto", - "unittest_drop_unknown_fields.proto", - "unittest_embed_optimize_for.proto", - "unittest_empty.proto", - "unittest_enormous_descriptor.proto", - "unittest_import.proto", - "unittest_import_public.proto", - "unittest_lazy_dependencies.proto", - "unittest_lazy_dependencies_custom_option.proto", - "unittest_lazy_dependencies_enum.proto", - "unittest_lite_imports_nonlite.proto", - "unittest_mset.proto", - "unittest_mset_wire_format.proto", - "unittest_no_field_presence.proto", - "unittest_no_generic_services.proto", - "unittest_optimize_for.proto", - "unittest_preserve_unknown_enum.proto", - "unittest_preserve_unknown_enum2.proto", - "unittest_proto3.proto", - "unittest_proto3_arena.proto", - "unittest_proto3_arena_lite.proto", - "unittest_proto3_lite.proto", - "unittest_proto3_optional.proto", - "unittest_well_known_types.proto", - ], - visibility = ["//:__subpackages__"], -) - -proto_library( - name = "test_protos", - srcs = [":test_proto_srcs"], - strip_import_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - ":any_proto", - ":api_proto", - ":descriptor_proto", - ":duration_proto", - ":empty_proto", - ":field_mask_proto", - ":source_context_proto", - ":struct_proto", - ":timestamp_proto", - ":type_proto", - ":wrappers_proto", - ], -) - -proto_library( - name = "generic_test_protos", - srcs = [ - "map_proto2_unittest.proto", - "map_unittest.proto", - "unittest.proto", - "unittest_arena.proto", - "unittest_custom_options.proto", - "unittest_drop_unknown_fields.proto", - "unittest_embed_optimize_for.proto", - "unittest_empty.proto", - "unittest_enormous_descriptor.proto", - "unittest_import.proto", - "unittest_import_public.proto", - "unittest_lazy_dependencies.proto", - "unittest_lazy_dependencies_custom_option.proto", - "unittest_lazy_dependencies_enum.proto", - "unittest_lite_imports_nonlite.proto", - "unittest_mset.proto", - "unittest_mset_wire_format.proto", - "unittest_no_field_presence.proto", - "unittest_no_generic_services.proto", - "unittest_optimize_for.proto", - "unittest_preserve_unknown_enum.proto", - "unittest_preserve_unknown_enum2.proto", - "unittest_proto3.proto", - "unittest_proto3_arena.proto", - "unittest_proto3_arena_lite.proto", - "unittest_proto3_lite.proto", - "unittest_proto3_optional.proto", - "unittest_well_known_types.proto", - ], - strip_import_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - ":any_proto", - ":api_proto", - ":descriptor_proto", - ":duration_proto", - ":empty_proto", - ":field_mask_proto", - ":source_context_proto", - ":struct_proto", - ":timestamp_proto", - ":type_proto", - ":wrappers_proto", - ], -) - -exports_files( - [ - "test_messages_proto2.proto", - "test_messages_proto3.proto", - ], - visibility = [ - "//:__pkg__", - "//python:__pkg__", - ], -) - -proto_library( - name = "test_messages_proto2_proto", - srcs = ["test_messages_proto2.proto"], - strip_import_prefix = "/src", - visibility = [ - "//:__pkg__", - "//conformance:__pkg__", - "@upb//:__subpackages__", - ], -) - -proto_library( - name = "test_messages_proto3_proto", - srcs = ["test_messages_proto3.proto"], - strip_import_prefix = "/src", - visibility = [ - "//:__pkg__", - "//conformance:__pkg__", - "@upb//:__subpackages__", - ], - deps = [ - ":any_proto", - ":duration_proto", - ":field_mask_proto", - ":struct_proto", - ":timestamp_proto", - ":wrappers_proto", - ], -) - -cc_proto_library( - name = "cc_lite_test_protos", - deps = [":lite_test_protos"], -) - -cc_proto_library( - name = "cc_test_protos", - visibility = ["//src/google/protobuf:__subpackages__"], - deps = [":test_protos"], -) - -# Filegroup for golden comparison test: -filegroup( - name = "descriptor_cc_srcs", - testonly = 1, - data = [ - "descriptor.pb.cc", - "descriptor.pb.h", - ], - visibility = ["//src/google/protobuf/compiler/cpp:__pkg__"], -) - -cc_library( - name = "lite_test_util", - testonly = 1, - srcs = [ - "arena_test_util.cc", - "map_lite_test_util.cc", - "test_util_lite.cc", - ], - hdrs = [ - "arena_test_util.h", - "map_lite_test_util.h", - "map_test_util_impl.h", - "proto3_lite_unittest.inc", - "test_util_lite.h", - ], - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - ":cc_lite_test_protos", - ":test_util2", - "@com_google_googletest//:gtest", - ], -) - -cc_library( - name = "test_util", - testonly = 1, - srcs = [ - "reflection_tester.cc", - "test_util.cc", - ], - hdrs = [ - "map_test.inc", - "map_test_util.h", - "map_test_util.inc", - "message_unittest.inc", - "reflection_tester.h", - "test_util.h", - "test_util.inc", - "test_util_lite.h", - "wire_format_unittest.inc", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - ":cc_lite_test_protos", - ":cc_test_protos", - ":lite_test_util", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - ], -) - -cc_library( - name = "test_util2", - testonly = 1, - hdrs = ["test_util2.h"], - strip_include_prefix = "/src", - textual_hdrs = ["test_util.inc"], - visibility = ["//:__subpackages__"], - deps = [ - "//src/google/protobuf/io", - "@com_google_googletest//:gtest", - ], -) - -cc_test( - name = "any_test", - srcs = ["any_test.cc"], - deps = [ - ":protobuf", - ":test_util", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "arena_align_test", - srcs = ["arena_align_test.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":arena_align", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "arena_unittest", - srcs = ["arena_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":lite_test_util", - ":protobuf", - ":test_util", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "arenastring_unittest", - srcs = ["arenastring_unittest.cc"], - deps = [ - ":protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "arenaz_sampler_test", - srcs = ["arenaz_sampler_test.cc"], - deps = [ - ":protobuf", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "descriptor_database_unittest", - srcs = ["descriptor_database_unittest.cc"], - deps = [ - ":protobuf", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "descriptor_unittest", - srcs = ["descriptor_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/testing", - "@com_google_absl//absl/strings:str_format", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "drop_unknown_fields_test", - srcs = ["drop_unknown_fields_test.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "dynamic_message_unittest", - srcs = ["dynamic_message_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "extension_set_unittest", - srcs = ["extension_set_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "generated_message_reflection_unittest", - srcs = ["generated_message_reflection_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "generated_message_tctable_lite_test", - srcs = ["generated_message_tctable_lite_test.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":protobuf_lite", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "inlined_string_field_unittest", - srcs = ["inlined_string_field_unittest.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "lite_arena_unittest", - srcs = ["lite_arena_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":lite_test_util", - ":protobuf", - ":test_util", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "lite_unittest", - srcs = ["lite_unittest.cc"], - deps = [ - ":cc_lite_test_protos", - ":lite_test_util", - ":protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "map_field_test", - srcs = ["map_field_test.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "@com_google_absl//absl/strings:str_format", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "map_test", - srcs = [ - "map_test.cc", - "map_test.inc", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - data = [":testdata"], - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "message_unittest", - srcs = [ - "message_unittest.cc", - "message_unittest.inc", - ], - data = [":testdata"], - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "no_field_presence_test", - srcs = ["no_field_presence_test.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "preserve_unknown_enum_test", - srcs = ["preserve_unknown_enum_test.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "proto3_arena_lite_unittest", - srcs = ["proto3_arena_lite_unittest.cc"], - deps = [ - ":cc_test_protos", - ":protobuf", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "proto3_arena_unittest", - srcs = ["proto3_arena_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "proto3_lite_unittest", - srcs = [ - "proto3_lite_unittest.cc", - "proto3_lite_unittest.inc", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":cc_test_protos", - ":lite_test_util", - ":protobuf", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "reflection_ops_unittest", - srcs = ["reflection_ops_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "repeated_field_reflection_unittest", - srcs = ["repeated_field_reflection_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "repeated_field_unittest", - srcs = ["repeated_field_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "text_format_unittest", - srcs = ["text_format_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - data = [":testdata"], - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "unknown_field_set_unittest", - srcs = ["unknown_field_set_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-error=sign-compare", - ], - }), - deps = [ - ":cc_lite_test_protos", - ":protobuf", - ":test_util", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_absl//absl/synchronization", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "well_known_types_unittest", - srcs = ["well_known_types_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":cc_test_protos", - ":protobuf", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "wire_format_unittest", - srcs = [ - "wire_format_unittest.cc", - "wire_format_unittest.inc", - ], - deps = [ - ":cc_test_protos", - ":protobuf", - ":test_util", - ":test_util2", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Helper targets for Kotlin tests -################################################################################ - -proto_library( - name = "kt_unittest_protos", - srcs = [ - "map_proto2_unittest.proto", - "unittest.proto", - "unittest_import.proto", - "unittest_import_public.proto", - ], - strip_import_prefix = "/src", - visibility = ["//java/kotlin:__pkg__"], -) - -proto_library( - name = "kt_proto3_unittest_protos", - srcs = [ - "unittest_import.proto", - "unittest_import_public.proto", - "unittest_proto3.proto", - ], - strip_import_prefix = "/src", - visibility = [ - "//java/kotlin:__pkg__", - "//java/kotlin-lite:__pkg__", - ], -) - -################################################################################ -# Packaging rules -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "full_test_srcs", - srcs = glob( - include = [ - "*_test.cc", - "*unittest.cc", - ], - exclude = [ - "lite_unittest.cc", - "lite_arena_unittest.cc", - ], - ), - visibility = ["//pkg:__pkg__"], -) - -filegroup( - name = "lite_test_srcs", - srcs = [ - "lite_arena_unittest.cc", - "lite_unittest.cc", - ], - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/any.cc b/libs/protobuf/src/google/protobuf/any.cc index 1f6ef87..346fa19 100644 --- a/libs/protobuf/src/google/protobuf/any.cc +++ b/libs/protobuf/src/google/protobuf/any.cc @@ -28,15 +28,15 @@ // (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/any.h" +#include -#include "google/protobuf/arenastring.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/message.h" +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -47,7 +47,7 @@ bool AnyMetadata::PackFrom(Arena* arena, const Message& message) { } bool AnyMetadata::PackFrom(Arena* arena, const Message& message, - absl::string_view type_url_prefix) { + StringPiece type_url_prefix) { type_url_->Set( GetTypeUrl(message.GetDescriptor()->full_name(), type_url_prefix), arena); return message.SerializeToString(value_->Mutable(arena)); @@ -79,4 +79,4 @@ bool GetAnyFieldDescriptors(const Message& message, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/any.h b/libs/protobuf/src/google/protobuf/any.h index ab71a6c..92ea2bb 100644 --- a/libs/protobuf/src/google/protobuf/any.h +++ b/libs/protobuf/src/google/protobuf/any.h @@ -33,12 +33,12 @@ #include -#include "google/protobuf/port.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/message_lite.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -52,8 +52,8 @@ extern const char kAnyFullTypeName[]; // "google.protobuf.Any". extern const char kTypeGoogleApisComPrefix[]; // "type.googleapis.com/". extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/". -std::string GetTypeUrl(absl::string_view message_name, - absl::string_view type_url_prefix); +std::string GetTypeUrl(StringPiece message_name, + StringPiece type_url_prefix); // Helper class used to implement google::protobuf::Any. class PROTOBUF_EXPORT AnyMetadata { @@ -63,8 +63,6 @@ class PROTOBUF_EXPORT AnyMetadata { // AnyMetadata does not take ownership of "type_url" and "value". constexpr AnyMetadata(UrlType* type_url, ValueType* value) : type_url_(type_url), value_(value) {} - AnyMetadata(const AnyMetadata&) = delete; - AnyMetadata& operator=(const AnyMetadata&) = delete; // Packs a message using the default type URL prefix: "type.googleapis.com". // The resulted type URL will be "type.googleapis.com/". @@ -86,13 +84,13 @@ class PROTOBUF_EXPORT AnyMetadata { // Returns false if serializing the message failed. template bool PackFrom(Arena* arena, const T& message, - absl::string_view type_url_prefix) { + StringPiece type_url_prefix) { return InternalPackFrom(arena, message, type_url_prefix, T::FullMessageName()); } bool PackFrom(Arena* arena, const Message& message, - absl::string_view type_url_prefix); + StringPiece type_url_prefix); // Unpacks the payload into the given message. Returns false if the message's // type doesn't match the type specified in the type URL (i.e., the full @@ -115,14 +113,16 @@ class PROTOBUF_EXPORT AnyMetadata { private: bool InternalPackFrom(Arena* arena, const MessageLite& message, - absl::string_view type_url_prefix, - absl::string_view type_name); - bool InternalUnpackTo(absl::string_view type_name, + StringPiece type_url_prefix, + StringPiece type_name); + bool InternalUnpackTo(StringPiece type_name, MessageLite* message) const; - bool InternalIs(absl::string_view type_name) const; + bool InternalIs(StringPiece type_name) const; UrlType* type_url_; ValueType* value_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AnyMetadata); }; // Get the proto type name from Any::type_url value. For example, passing @@ -132,14 +132,14 @@ class PROTOBUF_EXPORT AnyMetadata { // // NOTE: this function is available publicly as a static method on the // generated message type: google::protobuf::Any::ParseAnyTypeUrl() -bool ParseAnyTypeUrl(absl::string_view type_url, std::string* full_type_name); +bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name); // Get the proto type name and prefix from Any::type_url value. For example, // passing "type.googleapis.com/rpc.QueryOrigin" will return // "type.googleapis.com/" in *url_prefix and "rpc.QueryOrigin" in // *full_type_name. Returns false if the type_url does not have a "/" in the // type url separating the full type name. -bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix, +bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix, std::string* full_type_name); // See if message is of type google.protobuf.Any, if so, return the descriptors @@ -152,6 +152,6 @@ bool GetAnyFieldDescriptors(const Message& message, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_ANY_H__ diff --git a/libs/protobuf/src/google/protobuf/any.pb.cc b/libs/protobuf/src/google/protobuf/any.pb.cc index 9649411..c02f9eb 100644 --- a/libs/protobuf/src/google/protobuf/any.pb.cc +++ b/libs/protobuf/src/google/protobuf/any.pb.cc @@ -1,26 +1,28 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -#include "google/protobuf/any.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + #if defined(__llvm__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wuninitialized" + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wuninitialized" #endif // __llvm__ PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Any::Any( @@ -30,88 +32,62 @@ PROTOBUF_CONSTEXPR Any::Any( , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._any_metadata_)*/{&_impl_.type_url_, &_impl_.value_}} {} struct AnyDefaultTypeInternal { - PROTOBUF_CONSTEXPR AnyDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR AnyDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~AnyDefaultTypeInternal() {} union { Any _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 AnyDefaultTypeInternal _Any_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 AnyDefaultTypeInternal _Any_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fany_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fany_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.type_url_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.value_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fany_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Any)}, +const uint32_t TableStruct_google_2fprotobuf_2fany_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.type_url_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Any, _impl_.value_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Any)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Any_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fany_2eproto[] PROTOBUF_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(\014Bv\n\023com.google.protobufB\010AnyProtoP\001Z" - ",google.golang.org/protobuf/types/known/" - "anypb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownT" - "ypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = { - false, - false, - 212, - descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, - "google/protobuf/any.proto", - &descriptor_table_google_2fprotobuf_2fany_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fany_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fany_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fany_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Any_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fany_2eproto[] PROTOBUF_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(\014Bv\n\023com.google.protobufB\010AnyProtoP\001Z" + ",google.golang.org/protobuf/types/known/" + "anypb\242\002\003GPB\252\002\036Google.Protobuf.WellKnownT" + "ypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fany_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto = { + false, false, 212, descriptor_table_protodef_google_2fprotobuf_2fany_2eproto, + "google/protobuf/any.proto", + &descriptor_table_google_2fprotobuf_2fany_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fany_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fany_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fany_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fany_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fany_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fany_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fany_2eproto(&descriptor_table_google_2fprotobuf_2fany_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fany_2eproto(&descriptor_table_google_2fprotobuf_2fany_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== bool Any::GetAnyFieldDescriptors( @@ -122,7 +98,7 @@ bool Any::GetAnyFieldDescriptors( message, type_url_field, value_field); } bool Any::ParseAnyTypeUrl( - ::absl::string_view type_url, + ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url, std::string* full_type_name) { return ::_pbi::ParseAnyTypeUrl(type_url, full_type_name); } @@ -218,7 +194,6 @@ void Any::Clear() { } const char* Any::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -268,7 +243,6 @@ failure: uint8_t* Any::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -298,7 +272,6 @@ uint8_t* Any::_InternalSerialize( } size_t Any::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any) size_t total_size = 0; @@ -333,7 +306,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Any::GetClassData() const { re void Any::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Any) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -375,11 +347,11 @@ void Any::InternalSwap(Any* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Any::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fany_2eproto_getter, &descriptor_table_google_2fprotobuf_2fany_2eproto_once, file_level_metadata_google_2fprotobuf_2fany_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -388,8 +360,9 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Any >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Any >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) #if defined(__llvm__) -#pragma clang diagnostic pop + #pragma clang diagnostic pop #endif // __llvm__ -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/any.pb.h b/libs/protobuf/src/google/protobuf/any.pb.h index 9921be5..2c06052 100644 --- a/libs/protobuf/src/google/protobuf/any.pb.h +++ b/libs/protobuf/src/google/protobuf/any.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/any.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fany_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,23 +43,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fany_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fany_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fany_2eproto; PROTOBUF_NAMESPACE_OPEN class Any; struct AnyDefaultTypeInternal; PROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Any>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Any* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Any>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Any final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { public: @@ -122,7 +113,7 @@ class PROTOBUF_EXPORT Any final : return _impl_._any_metadata_.PackFrom(GetArena(), message); } bool PackFrom(const ::PROTOBUF_NAMESPACE_ID::Message& message, - ::absl::string_view type_url_prefix) { + ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) { GOOGLE_DCHECK_NE(&message, this); return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix); } @@ -139,7 +130,7 @@ class PROTOBUF_EXPORT Any final : } template ::value>::type> bool PackFrom(const T& message, - ::absl::string_view type_url_prefix) { + ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url_prefix) { return _impl_._any_metadata_.PackFrom(GetArena(), message, type_url_prefix);} template ::value>::type> bool UnpackTo(T* message) const { @@ -148,7 +139,7 @@ class PROTOBUF_EXPORT Any final : template bool Is() const { return _impl_._any_metadata_.Is(); } - static bool ParseAnyTypeUrl(::absl::string_view type_url, + static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url, std::string* full_type_name); friend void swap(Any& a, Any& b) { a.Swap(&b); @@ -203,7 +194,7 @@ class PROTOBUF_EXPORT Any final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Any"; } protected: @@ -271,17 +262,12 @@ class PROTOBUF_EXPORT Any final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Any // string type_url = 1; @@ -308,11 +294,11 @@ inline const std::string& Any::_internal_type_url() const { return _impl_.type_url_.Get(); } inline void Any::_internal_set_type_url(const std::string& value) { - + _impl_.type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Any::_internal_mutable_type_url() { - + return _impl_.type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Any::release_type_url() { @@ -320,6 +306,11 @@ inline std::string* Any::release_type_url() { return _impl_.type_url_.Release(); } inline void Any::set_allocated_type_url(std::string* type_url) { + if (type_url != nullptr) { + + } else { + + } _impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.type_url_.IsDefault()) { @@ -353,11 +344,11 @@ inline const std::string& Any::_internal_value() const { return _impl_.value_.Get(); } inline void Any::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* Any::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* Any::release_value() { @@ -365,6 +356,11 @@ inline std::string* Any::release_value() { return _impl_.value_.Release(); } inline void Any::set_allocated_value(std::string* value) { + if (value != nullptr) { + + } else { + + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.value_.IsDefault()) { @@ -375,15 +371,14 @@ inline void Any::set_allocated_value(std::string* value) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fany_2eproto diff --git a/libs/protobuf/src/google/protobuf/any.proto b/libs/protobuf/src/google/protobuf/any.proto index 8bd9801..e2c2042 100644 --- a/libs/protobuf/src/google/protobuf/any.proto +++ b/libs/protobuf/src/google/protobuf/any.proto @@ -93,6 +93,7 @@ option objc_class_prefix = "GPB"; // in the type URL, for example "foo.bar.com/x/y.z" will yield type // name "y.z". // +// // JSON // // The JSON representation of an `Any` value uses the regular diff --git a/libs/protobuf/src/google/protobuf/any_lite.cc b/libs/protobuf/src/google/protobuf/any_lite.cc index a15d19f..f283a31 100644 --- a/libs/protobuf/src/google/protobuf/any_lite.cc +++ b/libs/protobuf/src/google/protobuf/any_lite.cc @@ -28,24 +28,23 @@ // (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/io/zero_copy_stream_impl_lite.h" -#include "absl/strings/match.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/any.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace internal { -std::string GetTypeUrl(absl::string_view message_name, - absl::string_view type_url_prefix) { +std::string GetTypeUrl(StringPiece message_name, + StringPiece type_url_prefix) { if (!type_url_prefix.empty() && type_url_prefix[type_url_prefix.size() - 1] == '/') { - return absl::StrCat(type_url_prefix, message_name); + return StrCat(type_url_prefix, message_name); } else { - return absl::StrCat(type_url_prefix, "/", message_name); + return StrCat(type_url_prefix, "/", message_name); } } @@ -54,13 +53,13 @@ const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/"; const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/"; bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message, - absl::string_view type_url_prefix, - absl::string_view type_name) { + StringPiece type_url_prefix, + StringPiece type_name) { type_url_->Set(GetTypeUrl(type_name, type_url_prefix), arena); return message.SerializeToString(value_->Mutable(arena)); } -bool AnyMetadata::InternalUnpackTo(absl::string_view type_name, +bool AnyMetadata::InternalUnpackTo(StringPiece type_name, MessageLite* message) const { if (!InternalIs(type_name)) { return false; @@ -68,14 +67,14 @@ bool AnyMetadata::InternalUnpackTo(absl::string_view type_name, return message->ParseFromString(value_->Get()); } -bool AnyMetadata::InternalIs(absl::string_view type_name) const { - absl::string_view type_url = type_url_->Get(); +bool AnyMetadata::InternalIs(StringPiece type_name) const { + StringPiece type_url = type_url_->Get(); return type_url.size() >= type_name.size() + 1 && type_url[type_url.size() - type_name.size() - 1] == '/' && - absl::EndsWith(type_url, type_name); + HasSuffixString(type_url, type_name); } -bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix, +bool ParseAnyTypeUrl(StringPiece type_url, std::string* url_prefix, std::string* full_type_name) { size_t pos = type_url.find_last_of('/'); if (pos == std::string::npos || pos + 1 == type_url.size()) { @@ -88,7 +87,7 @@ bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix, return true; } -bool ParseAnyTypeUrl(absl::string_view type_url, std::string* full_type_name) { +bool ParseAnyTypeUrl(StringPiece type_url, std::string* full_type_name) { return ParseAnyTypeUrl(type_url, nullptr, full_type_name); } diff --git a/libs/protobuf/src/google/protobuf/any_test.cc b/libs/protobuf/src/google/protobuf/any_test.cc index 7e6ecb2..a82afb2 100644 --- a/libs/protobuf/src/google/protobuf/any_test.cc +++ b/libs/protobuf/src/google/protobuf/any_test.cc @@ -28,14 +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. -#include "google/protobuf/any_test.pb.h" -#include "google/protobuf/unittest.pb.h" +#include +#include #include -#include "absl/strings/str_cat.h" // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -192,4 +191,4 @@ TEST(AnyTest, PackSelfDeath) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/api.pb.cc b/libs/protobuf/src/google/protobuf/api.pb.cc index da04763..24b6049 100644 --- a/libs/protobuf/src/google/protobuf/api.pb.cc +++ b/libs/protobuf/src/google/protobuf/api.pb.cc @@ -1,23 +1,25 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -#include "google/protobuf/api.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Api::Api( ::_pbi::ConstantInitialized): _impl_{ @@ -30,15 +32,14 @@ PROTOBUF_CONSTEXPR Api::Api( , /*decltype(_impl_.syntax_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct ApiDefaultTypeInternal { - PROTOBUF_CONSTEXPR ApiDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ApiDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ApiDefaultTypeInternal() {} union { Api _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ApiDefaultTypeInternal _Api_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ApiDefaultTypeInternal _Api_default_instance_; PROTOBUF_CONSTEXPR Method::Method( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.options_)*/{} @@ -50,155 +51,123 @@ PROTOBUF_CONSTEXPR Method::Method( , /*decltype(_impl_.syntax_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct MethodDefaultTypeInternal { - PROTOBUF_CONSTEXPR MethodDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MethodDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MethodDefaultTypeInternal() {} union { Method _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodDefaultTypeInternal _Method_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodDefaultTypeInternal _Method_default_instance_; PROTOBUF_CONSTEXPR Mixin::Mixin( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.root_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_._cached_size_)*/{}} {} struct MixinDefaultTypeInternal { - PROTOBUF_CONSTEXPR MixinDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MixinDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MixinDefaultTypeInternal() {} union { Mixin _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MixinDefaultTypeInternal _Mixin_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MixinDefaultTypeInternal _Mixin_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fapi_2eproto[3]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fapi_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.methods_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.version_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.source_context_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.mixins_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.syntax_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_type_url_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_streaming_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_type_url_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_streaming_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.syntax_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.root_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Api)}, - { 15, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Method)}, - { 30, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Mixin)}, +const uint32_t TableStruct_google_2fprotobuf_2fapi_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.methods_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.version_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.source_context_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.mixins_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Api, _impl_.syntax_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_type_url_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.request_streaming_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_type_url_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.response_streaming_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Method, _impl_.syntax_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Mixin, _impl_.root_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Api)}, + { 13, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Method)}, + { 26, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Mixin)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Api_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Method_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Mixin_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto[] PROTOBUF_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" - "\n\004name\030\001 \001(\t\022(\n\007methods\030\002 \003(\0132\027.google.p" - "rotobuf.Method\022(\n\007options\030\003 \003(\0132\027.google" - ".protobuf.Option\022\017\n\007version\030\004 \001(\t\0226\n\016sou" - "rce_context\030\005 \001(\0132\036.google.protobuf.Sour" - "ceContext\022&\n\006mixins\030\006 \003(\0132\026.google.proto" - "buf.Mixin\022\'\n\006syntax\030\007 \001(\0162\027.google.proto" - "buf.Syntax\"\325\001\n\006Method\022\014\n\004name\030\001 \001(\t\022\030\n\020r" - "equest_type_url\030\002 \001(\t\022\031\n\021request_streami" - "ng\030\003 \001(\010\022\031\n\021response_type_url\030\004 \001(\t\022\032\n\022r" - "esponse_streaming\030\005 \001(\010\022(\n\007options\030\006 \003(\013" - "2\027.google.protobuf.Option\022\'\n\006syntax\030\007 \001(" - "\0162\027.google.protobuf.Syntax\"#\n\005Mixin\022\014\n\004n" - "ame\030\001 \001(\t\022\014\n\004root\030\002 \001(\tBv\n\023com.google.pr" - "otobufB\010ApiProtoP\001Z,google.golang.org/pr" - "otobuf/types/known/apipb\242\002\003GPB\252\002\036Google." - "Protobuf.WellKnownTypesb\006proto3" -}; -static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fapi_2eproto_deps[2] = - { - &::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto, - &::descriptor_table_google_2fprotobuf_2ftype_2eproto, -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = { - false, - false, - 751, - descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, - "google/protobuf/api.proto", - &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, - descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, - 2, - 3, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fapi_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fapi_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Api_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Method_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Mixin_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto[] PROTOBUF_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" + "\n\004name\030\001 \001(\t\022(\n\007methods\030\002 \003(\0132\027.google.p" + "rotobuf.Method\022(\n\007options\030\003 \003(\0132\027.google" + ".protobuf.Option\022\017\n\007version\030\004 \001(\t\0226\n\016sou" + "rce_context\030\005 \001(\0132\036.google.protobuf.Sour" + "ceContext\022&\n\006mixins\030\006 \003(\0132\026.google.proto" + "buf.Mixin\022\'\n\006syntax\030\007 \001(\0162\027.google.proto" + "buf.Syntax\"\325\001\n\006Method\022\014\n\004name\030\001 \001(\t\022\030\n\020r" + "equest_type_url\030\002 \001(\t\022\031\n\021request_streami" + "ng\030\003 \001(\010\022\031\n\021response_type_url\030\004 \001(\t\022\032\n\022r" + "esponse_streaming\030\005 \001(\010\022(\n\007options\030\006 \003(\013" + "2\027.google.protobuf.Option\022\'\n\006syntax\030\007 \001(" + "\0162\027.google.protobuf.Syntax\"#\n\005Mixin\022\014\n\004n" + "ame\030\001 \001(\t\022\014\n\004root\030\002 \001(\tBv\n\023com.google.pr" + "otobufB\010ApiProtoP\001Z,google.golang.org/pr" + "otobuf/types/known/apipb\242\002\003GPB\252\002\036Google." + "Protobuf.WellKnownTypesb\006proto3" + ; +static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fapi_2eproto_deps[2] = { + &::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto, + &::descriptor_table_google_2fprotobuf_2ftype_2eproto, +}; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fapi_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto = { + false, false, 751, descriptor_table_protodef_google_2fprotobuf_2fapi_2eproto, + "google/protobuf/api.proto", + &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, descriptor_table_google_2fprotobuf_2fapi_2eproto_deps, 2, 3, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fapi_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fapi_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fapi_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fapi_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fapi_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fapi_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fapi_2eproto(&descriptor_table_google_2fprotobuf_2fapi_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fapi_2eproto(&descriptor_table_google_2fprotobuf_2fapi_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class Api::_Internal { @@ -329,7 +298,6 @@ void Api::Clear() { } const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -405,7 +373,7 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Syntax syntax = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); } else @@ -436,7 +404,6 @@ failure: uint8_t* Api::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -508,7 +475,6 @@ uint8_t* Api::_InternalSerialize( } size_t Api::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Api) size_t total_size = 0; @@ -577,7 +543,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Api::GetClassData() const { re void Api::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Api) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -638,11 +603,11 @@ void Api::InternalSwap(Api* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Api::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, file_level_metadata_google_2fprotobuf_2fapi_2eproto[0]); } + // =================================================================== class Method::_Internal { @@ -768,7 +733,6 @@ void Method::Clear() { } const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -836,7 +800,7 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Syntax syntax = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 56)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); } else @@ -867,7 +831,6 @@ failure: uint8_t* Method::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -938,7 +901,6 @@ uint8_t* Method::_InternalSerialize( } size_t Method::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Method) size_t total_size = 0; @@ -1003,7 +965,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Method::GetClassData() const { void Method::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Method) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1069,11 +1030,11 @@ void Method::InternalSwap(Method* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Method::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, file_level_metadata_google_2fprotobuf_2fapi_2eproto[1]); } + // =================================================================== class Mixin::_Internal { @@ -1164,7 +1125,6 @@ void Mixin::Clear() { } const char* Mixin::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1215,7 +1175,6 @@ failure: uint8_t* Mixin::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1249,7 +1208,6 @@ uint8_t* Mixin::_InternalSerialize( } size_t Mixin::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Mixin) size_t total_size = 0; @@ -1284,7 +1242,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Mixin::GetClassData() const { void Mixin::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Mixin) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1326,11 +1283,11 @@ void Mixin::InternalSwap(Mixin* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Mixin::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fapi_2eproto_getter, &descriptor_table_google_2fprotobuf_2fapi_2eproto_once, file_level_metadata_google_2fprotobuf_2fapi_2eproto[2]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -1347,5 +1304,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Mixin >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Mixin >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/api.pb.h b/libs/protobuf/src/google/protobuf/api.pb.h index cbfd5fc..2c45489 100644 --- a/libs/protobuf/src/google/protobuf/api.pb.h +++ b/libs/protobuf/src/google/protobuf/api.pb.h @@ -1,45 +1,40 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/api.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/source_context.pb.h" -#include "google/protobuf/type.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fapi_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -50,8 +45,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fapi_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fapi_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fapi_2eproto; PROTOBUF_NAMESPACE_OPEN class Api; struct ApiDefaultTypeInternal; @@ -62,21 +56,16 @@ PROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_; class Mixin; struct MixinDefaultTypeInternal; PROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Api>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Method>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Mixin>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Api* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Api>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Method* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Method>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Mixin* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Mixin>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Api final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { public: @@ -180,7 +169,7 @@ class PROTOBUF_EXPORT Api final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Api"; } protected: @@ -334,7 +323,8 @@ class PROTOBUF_EXPORT Api final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Method final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { @@ -439,7 +429,7 @@ class PROTOBUF_EXPORT Method final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Method"; } protected: @@ -571,7 +561,8 @@ class PROTOBUF_EXPORT Method final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fapi_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Mixin final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { @@ -676,7 +667,7 @@ class PROTOBUF_EXPORT Mixin final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Mixin"; } protected: @@ -743,17 +734,12 @@ class PROTOBUF_EXPORT Mixin final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Api // string name = 1; @@ -780,11 +766,11 @@ inline const std::string& Api::_internal_name() const { return _impl_.name_.Get(); } inline void Api::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Api::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Api::release_name() { @@ -792,6 +778,11 @@ inline std::string* Api::release_name() { return _impl_.name_.Release(); } inline void Api::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -902,11 +893,11 @@ inline const std::string& Api::_internal_version() const { return _impl_.version_.Get(); } inline void Api::_internal_set_version(const std::string& value) { - + _impl_.version_.Set(value, GetArenaForAllocation()); } inline std::string* Api::_internal_mutable_version() { - + return _impl_.version_.Mutable(GetArenaForAllocation()); } inline std::string* Api::release_version() { @@ -914,6 +905,11 @@ inline std::string* Api::release_version() { return _impl_.version_.Release(); } inline void Api::set_allocated_version(std::string* version) { + if (version != nullptr) { + + } else { + + } _impl_.version_.SetAllocated(version, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.version_.IsDefault()) { @@ -945,6 +941,11 @@ inline void Api::unsafe_arena_set_allocated_source_context( delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_); } _impl_.source_context_ = source_context; + if (source_context) { + + } else { + + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.source_context) } inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Api::release_source_context() { @@ -995,9 +996,9 @@ inline void Api::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCon source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context) @@ -1091,11 +1092,11 @@ inline const std::string& Method::_internal_name() const { return _impl_.name_.Get(); } inline void Method::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_name() { @@ -1103,6 +1104,11 @@ inline std::string* Method::release_name() { return _impl_.name_.Release(); } inline void Method::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -1136,11 +1142,11 @@ inline const std::string& Method::_internal_request_type_url() const { return _impl_.request_type_url_.Get(); } inline void Method::_internal_set_request_type_url(const std::string& value) { - + _impl_.request_type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_request_type_url() { - + return _impl_.request_type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_request_type_url() { @@ -1148,6 +1154,11 @@ inline std::string* Method::release_request_type_url() { return _impl_.request_type_url_.Release(); } inline void Method::set_allocated_request_type_url(std::string* request_type_url) { + if (request_type_url != nullptr) { + + } else { + + } _impl_.request_type_url_.SetAllocated(request_type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.request_type_url_.IsDefault()) { @@ -1169,7 +1180,7 @@ inline bool Method::request_streaming() const { return _internal_request_streaming(); } inline void Method::_internal_set_request_streaming(bool value) { - + _impl_.request_streaming_ = value; } inline void Method::set_request_streaming(bool value) { @@ -1201,11 +1212,11 @@ inline const std::string& Method::_internal_response_type_url() const { return _impl_.response_type_url_.Get(); } inline void Method::_internal_set_response_type_url(const std::string& value) { - + _impl_.response_type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Method::_internal_mutable_response_type_url() { - + return _impl_.response_type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Method::release_response_type_url() { @@ -1213,6 +1224,11 @@ inline std::string* Method::release_response_type_url() { return _impl_.response_type_url_.Release(); } inline void Method::set_allocated_response_type_url(std::string* response_type_url) { + if (response_type_url != nullptr) { + + } else { + + } _impl_.response_type_url_.SetAllocated(response_type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.response_type_url_.IsDefault()) { @@ -1234,7 +1250,7 @@ inline bool Method::response_streaming() const { return _internal_response_streaming(); } inline void Method::_internal_set_response_streaming(bool value) { - + _impl_.response_streaming_ = value; } inline void Method::set_response_streaming(bool value) { @@ -1327,11 +1343,11 @@ inline const std::string& Mixin::_internal_name() const { return _impl_.name_.Get(); } inline void Mixin::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Mixin::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Mixin::release_name() { @@ -1339,6 +1355,11 @@ inline std::string* Mixin::release_name() { return _impl_.name_.Release(); } inline void Mixin::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -1372,11 +1393,11 @@ inline const std::string& Mixin::_internal_root() const { return _impl_.root_.Get(); } inline void Mixin::_internal_set_root(const std::string& value) { - + _impl_.root_.Set(value, GetArenaForAllocation()); } inline std::string* Mixin::_internal_mutable_root() { - + return _impl_.root_.Mutable(GetArenaForAllocation()); } inline std::string* Mixin::release_root() { @@ -1384,6 +1405,11 @@ inline std::string* Mixin::release_root() { return _impl_.root_.Release(); } inline void Mixin::set_allocated_root(std::string* root) { + if (root != nullptr) { + + } else { + + } _impl_.root_.SetAllocated(root, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.root_.IsDefault()) { @@ -1394,15 +1420,18 @@ inline void Mixin::set_allocated_root(std::string* root) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fapi_2eproto diff --git a/libs/protobuf/src/google/protobuf/api.proto b/libs/protobuf/src/google/protobuf/api.proto index 426c240..3d598fc 100644 --- a/libs/protobuf/src/google/protobuf/api.proto +++ b/libs/protobuf/src/google/protobuf/api.proto @@ -82,6 +82,7 @@ message Api { // be omitted. Zero major versions must only be used for // experimental, non-GA interfaces. // + // string version = 4; // Source context for the protocol buffer service represented by this diff --git a/libs/protobuf/src/google/protobuf/arena.cc b/libs/protobuf/src/google/protobuf/arena.cc index 327c26e..6ba508a 100644 --- a/libs/protobuf/src/google/protobuf/arena.cc +++ b/libs/protobuf/src/google/protobuf/arena.cc @@ -28,7 +28,7 @@ // (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/arena.h" +#include #include #include @@ -37,47 +37,21 @@ #include #include -#include "absl/synchronization/mutex.h" -#include "google/protobuf/arena_allocation_policy.h" -#include "google/protobuf/arena_impl.h" -#include "google/protobuf/arenaz_sampler.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include #ifdef ADDRESS_SANITIZER #include #endif // ADDRESS_SANITIZER // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace internal { -namespace { - -#if defined(__GNUC__) && __GNUC__ >= 5 -// kSentryArenaBlock is used for arenas which can be referenced pre-main. So, -// constexpr is required. -constexpr ArenaBlock kSentryArenaBlock; - -ArenaBlock* SentryArenaBlock() { - // const_cast<> is okay as kSentryArenaBlock will never be mutated. - return const_cast(&kSentryArenaBlock); -} -#else -// TODO(b/248322260) Remove this once we're not using GCC 4.9 for tests. -// There is a compiler bug in this version that causes the above constexpr to -// fail. This version is no longer in our support window, but we use it in -// some of our aarch64 docker images. -ArenaBlock* SentryArenaBlock() { - static const ArenaBlock kSentryArenaBlock; - // const_cast<> is okay as kSentryArenaBlock will never be mutated. - return const_cast(&kSentryArenaBlock); -} -#endif - -} // namespace static SerialArena::Memory AllocateMemory(const AllocationPolicy* policy_ptr, size_t last_size, size_t min_bytes) { @@ -130,54 +104,27 @@ class GetDeallocator { size_t* space_allocated_; }; -// It is guaranteed that this is constructed in `b`. IOW, this is not the first -// arena and `b` cannot be sentry. -SerialArena::SerialArena(ArenaBlock* b, ThreadSafeArena& parent) - : ptr_{b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize)}, - limit_{b->Limit()}, - head_{b}, - space_allocated_{b->size}, - parent_{parent} { - GOOGLE_DCHECK(!b->IsSentry()); +SerialArena::SerialArena(Block* b, void* owner, ThreadSafeArenaStats* stats) + : space_allocated_(b->size) { + owner_ = owner; + head_ = b; + ptr_ = b->Pointer(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize); + limit_ = b->Pointer(b->size & static_cast(-8)); + arena_stats_ = stats; } -// It is guaranteed that this is the first SerialArena. Use sentry block. -SerialArena::SerialArena(ThreadSafeArena& parent) - : head_{SentryArenaBlock()}, parent_{parent} {} - -// It is guaranteed that this is the first SerialArena but `b` may be user -// provided or newly allocated to store AllocationPolicy. -SerialArena::SerialArena(FirstSerialArena, ArenaBlock* b, - ThreadSafeArena& parent) - : head_{b}, space_allocated_{b->size}, parent_{parent} { - if (b->IsSentry()) return; - - set_ptr(b->Pointer(kBlockHeaderSize)); - limit_ = b->Limit(); -} - -void SerialArena::Init(ArenaBlock* b, size_t offset) { - set_ptr(b->Pointer(offset)); - limit_ = b->Limit(); - head_.store(b, std::memory_order_relaxed); - space_used_.store(0, std::memory_order_relaxed); - space_allocated_.store(b->size, std::memory_order_relaxed); - cached_block_length_ = 0; - cached_blocks_ = nullptr; -} - -SerialArena* SerialArena::New(Memory mem, ThreadSafeArena& parent) { +SerialArena* SerialArena::New(Memory mem, void* owner, + ThreadSafeArenaStats* stats) { GOOGLE_DCHECK_LE(kBlockHeaderSize + ThreadSafeArena::kSerialArenaSize, mem.size); - ThreadSafeArenaStats::RecordAllocateStats(parent.arena_stats_.MutableStats(), - /*used=*/0, /*allocated=*/mem.size, - /*wasted=*/0); - auto b = new (mem.ptr) ArenaBlock{nullptr, mem.size}; - return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, parent); + ThreadSafeArenaStats::RecordAllocateStats( + stats, /*requested=*/mem.size, /*allocated=*/mem.size, /*wasted=*/0); + auto b = new (mem.ptr) Block{nullptr, mem.size}; + return new (b->Pointer(kBlockHeaderSize)) SerialArena(b, owner, stats); } template SerialArena::Memory SerialArena::Free(Deallocator deallocator) { - ArenaBlock* b = head(); + Block* b = head_; Memory mem = {b, b->size}; while (b->next) { b = b->next; // We must first advance before deleting this block @@ -188,288 +135,76 @@ SerialArena::Memory SerialArena::Free(Deallocator deallocator) { } PROTOBUF_NOINLINE -void* SerialArena::AllocateAlignedFallback(size_t n) { - AllocateNewBlock(n); +std::pair +SerialArena::AllocateAlignedWithCleanupFallback( + size_t n, const AllocationPolicy* policy) { + AllocateNewBlock(n + kCleanupSize, policy); + return AllocateFromExistingWithCleanupFallback(n); +} + +PROTOBUF_NOINLINE +void* SerialArena::AllocateAlignedFallback(size_t n, + const AllocationPolicy* policy) { + AllocateNewBlock(n, policy); return AllocateFromExisting(n); } -PROTOBUF_NOINLINE -void* SerialArena::AllocateAlignedWithCleanupFallback( - size_t n, size_t align, void (*destructor)(void*)) { - size_t required = AlignUpTo(n, align) + cleanup::Size(destructor); - AllocateNewBlock(required); - return AllocateFromExistingWithCleanupFallback(n, align, destructor); -} +void SerialArena::AllocateNewBlock(size_t n, const AllocationPolicy* policy) { + // Sync limit to block + head_->start = reinterpret_cast(limit_); -PROTOBUF_NOINLINE -void SerialArena::AddCleanupFallback(void* elem, void (*destructor)(void*)) { - size_t required = cleanup::Size(destructor); - AllocateNewBlock(required); - AddCleanupFromExisting(elem, destructor); -} - -void SerialArena::AllocateNewBlock(size_t n) { - size_t used = 0; - size_t wasted = 0; - ArenaBlock* old_head = head(); - if (!old_head->IsSentry()) { - // Sync limit to block - old_head->cleanup_nodes = limit_; - - // Record how much used in this block. - used = static_cast(ptr() - old_head->Pointer(kBlockHeaderSize)); - wasted = old_head->size - used; - space_used_.store(space_used_.load(std::memory_order_relaxed) + used, - std::memory_order_relaxed); - } + // Record how much used in this block. + size_t used = ptr_ - head_->Pointer(kBlockHeaderSize); + size_t wasted = head_->size - used; + space_used_ += used; // TODO(sbenza): Evaluate if pushing unused space into the cached blocks is a // win. In preliminary testing showed increased memory savings as expected, // but with a CPU regression. The regression might have been an artifact of // the microbenchmark. - auto mem = AllocateMemory(parent_.AllocPolicy(), old_head->size, n); + auto mem = AllocateMemory(policy, head_->size, n); // We don't want to emit an expensive RMW instruction that requires // exclusive access to a cacheline. Hence we write it in terms of a // regular add. - space_allocated_.store( - space_allocated_.load(std::memory_order_relaxed) + mem.size, - std::memory_order_relaxed); - ThreadSafeArenaStats::RecordAllocateStats(parent_.arena_stats_.MutableStats(), - /*used=*/used, + auto relaxed = std::memory_order_relaxed; + space_allocated_.store(space_allocated_.load(relaxed) + mem.size, relaxed); + ThreadSafeArenaStats::RecordAllocateStats(arena_stats_, /*requested=*/n, /*allocated=*/mem.size, wasted); - auto* new_head = new (mem.ptr) ArenaBlock{old_head, mem.size}; - set_ptr(new_head->Pointer(kBlockHeaderSize)); - limit_ = new_head->Limit(); - // Previous writes must take effect before writing new head. - head_.store(new_head, std::memory_order_release); + head_ = new (mem.ptr) Block{head_, mem.size}; + ptr_ = head_->Pointer(kBlockHeaderSize); + limit_ = head_->Pointer(head_->size); #ifdef ADDRESS_SANITIZER - ASAN_POISON_MEMORY_REGION(ptr(), limit_ - ptr()); + ASAN_POISON_MEMORY_REGION(ptr_, limit_ - ptr_); #endif // ADDRESS_SANITIZER } uint64_t SerialArena::SpaceUsed() const { - // Note: the calculation below technically causes a race with - // AllocateNewBlock when called from another thread (which happens in - // ThreadSafeArena::SpaceUsed). However, worst-case space_used_ will have - // stale data and the calculation will incorrectly assume 100% - // usage of the *current* block. - // TODO(mkruskal) Consider eliminating this race in exchange for a possible - // performance hit on ARM (see cl/455186837). - const ArenaBlock* h = head_.load(std::memory_order_acquire); - if (h->IsSentry()) return 0; - - const uint64_t current_block_size = h->size; - uint64_t current_space_used = std::min( - static_cast( - ptr() - const_cast(h)->Pointer(kBlockHeaderSize)), - current_block_size); - return current_space_used + space_used_.load(std::memory_order_relaxed); + uint64_t space_used = ptr_ - head_->Pointer(kBlockHeaderSize); + space_used += space_used_; + // Remove the overhead of the SerialArena itself. + space_used -= ThreadSafeArena::kSerialArenaSize; + return space_used; } void SerialArena::CleanupList() { - ArenaBlock* b = head(); - if (b->IsSentry()) return; - - b->cleanup_nodes = limit_; + Block* b = head_; + b->start = reinterpret_cast(limit_); do { - char* limit = b->Limit(); - char* it = reinterpret_cast(b->cleanup_nodes); - GOOGLE_DCHECK(!b->IsSentry() || it == limit); - if (it < limit) { - // A prefetch distance of 8 here was chosen arbitrarily. It makes the - // pending nodes fill a cacheline which seemed nice. - constexpr int kPrefetchDist = 8; - cleanup::Tag pending_type[kPrefetchDist]; - char* pending_node[kPrefetchDist]; - - int pos = 0; - for (; pos < kPrefetchDist && it < limit; ++pos) { - pending_type[pos] = cleanup::Type(it); - pending_node[pos] = it; - it += cleanup::Size(pending_type[pos]); - } - - if (pos < kPrefetchDist) { - for (int i = 0; i < pos; ++i) { - cleanup::DestroyNode(pending_type[i], pending_node[i]); - } - } else { - pos = 0; - while (it < limit) { - cleanup::PrefetchNode(it); - cleanup::DestroyNode(pending_type[pos], pending_node[pos]); - pending_type[pos] = cleanup::Type(it); - pending_node[pos] = it; - it += cleanup::Size(pending_type[pos]); - pos = (pos + 1) % kPrefetchDist; - } - for (int i = pos; i < pos + kPrefetchDist; ++i) { - cleanup::DestroyNode(pending_type[i % kPrefetchDist], - pending_node[i % kPrefetchDist]); - } + auto* limit = reinterpret_cast( + b->Pointer(b->size & static_cast(-8))); + auto it = b->start; + auto num = limit - it; + if (num > 0) { + for (; it < limit; it++) { + it->cleanup(it->elem); } } b = b->next; } while (b); } -// Stores arrays of void* and SerialArena* instead of linked list of -// SerialArena* to speed up traversing all SerialArena. The cost of walk is non -// trivial when there are many nodes. Separately storing "ids" minimizes cache -// footprints and more efficient when looking for matching arena. -// -// Uses absl::container_internal::Layout to emulate the following: -// -// struct SerialArenaChunk { -// struct SerialArenaChunkHeader { -// SerialArenaChunk* next_chunk; -// uint32_t capacity; -// std::atomic size; -// } header; -// std::atomic ids[]; -// std::atomic arenas[]; -// }; -// -// where the size of "ids" and "arenas" is determined at runtime; hence the use -// of Layout. -struct SerialArenaChunkHeader { - constexpr SerialArenaChunkHeader(uint32_t capacity, uint32_t size) - : next_chunk(nullptr), capacity(capacity), size(size) {} - - ThreadSafeArena::SerialArenaChunk* next_chunk; - uint32_t capacity; - std::atomic size; -}; - -class ThreadSafeArena::SerialArenaChunk { - public: - SerialArenaChunk(uint32_t capacity, void* me, SerialArena* serial) { - new (&header()) SerialArenaChunkHeader{capacity, 1}; - - new (&id(0)) std::atomic{me}; - for (uint32_t i = 1; i < capacity; ++i) { - new (&id(i)) std::atomic{nullptr}; - } - - new (&arena(0)) std::atomic{serial}; - for (uint32_t i = 1; i < capacity; ++i) { - new (&arena(i)) std::atomic{nullptr}; - } - } - - bool IsSentry() const { return capacity() == 0; } - - // next_chunk - const SerialArenaChunk* next_chunk() const { return header().next_chunk; } - SerialArenaChunk* next_chunk() { return header().next_chunk; } - void set_next(SerialArenaChunk* next_chunk) { - header().next_chunk = next_chunk; - } - - // capacity - uint32_t capacity() const { return header().capacity; } - void set_capacity(uint32_t capacity) { header().capacity = capacity; } - - // ids: returns up to size(). - absl::Span> ids() const { - return Layout(capacity()).Slice(ptr()).first(safe_size()); - } - absl::Span> ids() { - return Layout(capacity()).Slice(ptr()).first(safe_size()); - } - std::atomic& id(uint32_t i) { - GOOGLE_DCHECK_LT(i, capacity()); - return Layout(capacity()).Pointer(ptr())[i]; - } - - // arenas: returns up to size(). - absl::Span> arenas() const { - return Layout(capacity()).Slice(ptr()).first(safe_size()); - } - absl::Span> arenas() { - return Layout(capacity()).Slice(ptr()).first(safe_size()); - } - const std::atomic& arena(uint32_t i) const { - GOOGLE_DCHECK_LT(i, capacity()); - return Layout(capacity()).Pointer(ptr())[i]; - } - std::atomic& arena(uint32_t i) { - GOOGLE_DCHECK_LT(i, capacity()); - return Layout(capacity()).Pointer(ptr())[i]; - } - - // Tries to insert {id, serial} to head chunk. Returns false if the head is - // already full. - // - // Note that the updating "size", "id", "arena" is individually atomic but - // those are not protected by a mutex. This is acceptable because concurrent - // lookups from SpaceUsed or SpaceAllocated accept inaccuracy due to race. On - // other paths, either race is not possible (GetSerialArenaFallback) or must - // be prevented by users (CleanupList, Free). - bool insert(void* me, SerialArena* serial) { - uint32_t idx = size().fetch_add(1, std::memory_order_relaxed); - // Bail out if this chunk is full. - if (idx >= capacity()) { - // Write old value back to avoid potential overflow. - size().store(capacity(), std::memory_order_relaxed); - return false; - } - - id(idx).store(me, std::memory_order_relaxed); - arena(idx).store(serial, std::memory_order_release); - return true; - } - - constexpr static size_t AllocSize(size_t n) { return Layout(n).AllocSize(); } - - private: - constexpr static int kHeader = 0; - constexpr static int kIds = 1; - constexpr static int kArenas = 2; - - using layout_type = absl::container_internal::Layout< - SerialArenaChunkHeader, std::atomic, std::atomic>; - - const char* ptr() const { return reinterpret_cast(this); } - char* ptr() { return reinterpret_cast(this); } - - SerialArenaChunkHeader& header() { - return *layout_type::Partial().Pointer(ptr()); - } - const SerialArenaChunkHeader& header() const { - return *layout_type::Partial().Pointer(ptr()); - } - - std::atomic& size() { return header().size; } - const std::atomic& size() const { return header().size; } - - // Returns the size capped by the capacity as fetch_add may result in a size - // greater than capacity. - uint32_t safe_size() const { - return std::min(capacity(), size().load(std::memory_order_relaxed)); - } - - constexpr static layout_type Layout(size_t n) { - return layout_type( - /*header*/ 1, - /*ids*/ n, - /*arenas*/ n); - } -}; - -constexpr SerialArenaChunkHeader kSentryArenaChunk = {0, 0}; - -ThreadSafeArena::SerialArenaChunk* ThreadSafeArena::SentrySerialArenaChunk() { - // const_cast is okay because the sentry chunk is never mutated. Also, - // reinterpret_cast is acceptable here as it should be identical to - // SerialArenaChunk with zero payload. This is a necessary trick to - // constexpr initialize kSentryArenaChunk. - return reinterpret_cast( - const_cast(&kSentryArenaChunk)); -} - ThreadSafeArena::CacheAlignedLifecycleIdGenerator ThreadSafeArena::lifecycle_id_generator_; @@ -491,71 +226,66 @@ PROTOBUF_THREAD_LOCAL ThreadSafeArena::ThreadCache nullptr}; #endif -ThreadSafeArena::ThreadSafeArena() : first_arena_(*this) { Init(); } - -// Constructor solely used by message-owned arena. -ThreadSafeArena::ThreadSafeArena(internal::MessageOwned) - : tag_and_id_(kMessageOwnedArena), first_arena_(*this) { +void ThreadSafeArena::InitializeFrom(void* mem, size_t size) { + GOOGLE_DCHECK_EQ(reinterpret_cast(mem) & 7, 0u); + GOOGLE_DCHECK(!AllocPolicy()); // Reset should call InitializeWithPolicy instead. Init(); -} -ThreadSafeArena::ThreadSafeArena(char* mem, size_t size) - : first_arena_(FirstSerialArena{}, FirstBlock(mem, size), *this) { - Init(); -} - -ThreadSafeArena::ThreadSafeArena(void* mem, size_t size, - const AllocationPolicy& policy) - : first_arena_(FirstSerialArena{}, FirstBlock(mem, size, policy), *this) { - InitializeWithPolicy(policy); -} - -ArenaBlock* ThreadSafeArena::FirstBlock(void* buf, size_t size) { - GOOGLE_DCHECK_EQ(reinterpret_cast(buf) & 7, 0u); - if (buf == nullptr || size <= kBlockHeaderSize) { - return SentryArenaBlock(); - } - // Record user-owned block. - alloc_policy_.set_is_user_owned_initial_block(true); - return new (buf) ArenaBlock{nullptr, size}; -} - -ArenaBlock* ThreadSafeArena::FirstBlock(void* buf, size_t size, - const AllocationPolicy& policy) { - if (policy.IsDefault()) return FirstBlock(buf, size); - - GOOGLE_DCHECK_EQ(reinterpret_cast(buf) & 7, 0u); - - SerialArena::Memory mem; - if (buf == nullptr || size < kBlockHeaderSize + kAllocPolicySize) { - mem = AllocateMemory(&policy, 0, kAllocPolicySize); - } else { - mem = {buf, size}; - // Record user-owned block. + // Ignore initial block if it is too small. + if (mem != nullptr && size >= kBlockHeaderSize + kSerialArenaSize) { alloc_policy_.set_is_user_owned_initial_block(true); + SetInitialBlock(mem, size); } - - return new (mem.ptr) ArenaBlock{nullptr, mem.size}; } -void ThreadSafeArena::InitializeWithPolicy(const AllocationPolicy& policy) { - Init(); - - if (policy.IsDefault()) return; - +void ThreadSafeArena::InitializeWithPolicy(void* mem, size_t size, + AllocationPolicy policy) { #ifndef NDEBUG const uint64_t old_alloc_policy = alloc_policy_.get_raw(); // If there was a policy (e.g., in Reset()), make sure flags were preserved. #define GOOGLE_DCHECK_POLICY_FLAGS_() \ if (old_alloc_policy > 3) \ - GOOGLE_CHECK_EQ(old_alloc_policy & 3, alloc_policy_.get_raw() & 3) + GOOGLE_CHECK_EQ(old_alloc_policy & 3, alloc_policy_.get_raw() & 3) #else #define GOOGLE_DCHECK_POLICY_FLAGS_() #endif // NDEBUG + if (policy.IsDefault()) { + // Legacy code doesn't use the API above, but provides the initial block + // through ArenaOptions. I suspect most do not touch the allocation + // policy parameters. + InitializeFrom(mem, size); + GOOGLE_DCHECK_POLICY_FLAGS_(); + return; + } + GOOGLE_DCHECK_EQ(reinterpret_cast(mem) & 7, 0u); + Init(); + + // Ignore initial block if it is too small. We include an optional + // AllocationPolicy in this check, so that this can be allocated on the + // first block. + constexpr size_t kAPSize = internal::AlignUpTo8(sizeof(AllocationPolicy)); + constexpr size_t kMinimumSize = kBlockHeaderSize + kSerialArenaSize + kAPSize; + + // The value for alloc_policy_ stores whether or not allocations should be + // recorded. + alloc_policy_.set_should_record_allocs( + policy.metrics_collector != nullptr && + policy.metrics_collector->RecordAllocs()); + // Make sure we have an initial block to store the AllocationPolicy. + if (mem != nullptr && size >= kMinimumSize) { + alloc_policy_.set_is_user_owned_initial_block(true); + } else { + auto tmp = AllocateMemory(&policy, 0, kMinimumSize); + mem = tmp.ptr; + size = tmp.size; + } + SetInitialBlock(mem, size); + + auto sa = threads_.load(std::memory_order_relaxed); // We ensured enough space so this cannot fail. void* p; - if (!first_arena_.MaybeAllocateAligned(kAllocPolicySize, &p)) { + if (!sa || !sa->MaybeAllocateAligned(kAPSize, &p)) { GOOGLE_LOG(FATAL) << "MaybeAllocateAligned cannot fail here."; return; } @@ -568,100 +298,41 @@ void ThreadSafeArena::InitializeWithPolicy(const AllocationPolicy& policy) { #undef GOOGLE_DCHECK_POLICY_FLAGS_ } -uint64_t ThreadSafeArena::GetNextLifeCycleId() { +void ThreadSafeArena::Init() { +#ifndef NDEBUG + const bool was_message_owned = IsMessageOwned(); +#endif // NDEBUG ThreadCache& tc = thread_cache(); - uint64_t id = tc.next_lifecycle_id; + auto id = tc.next_lifecycle_id; // We increment lifecycle_id's by multiples of two so we can use bit 0 as // a tag. constexpr uint64_t kDelta = 2; constexpr uint64_t kInc = ThreadCache::kPerThreadIds * kDelta; if (PROTOBUF_PREDICT_FALSE((id & (kInc - 1)) == 0)) { + constexpr auto relaxed = std::memory_order_relaxed; // On platforms that don't support uint64_t atomics we can certainly not // afford to increment by large intervals and expect uniqueness due to // wrapping, hence we only add by 1. - id = lifecycle_id_generator_.id.fetch_add(1, std::memory_order_relaxed) * - kInc; + id = lifecycle_id_generator_.id.fetch_add(1, relaxed) * kInc; } tc.next_lifecycle_id = id + kDelta; - return id; -} - -// We assume that #threads / arena is bimodal; i.e. majority small ones are -// single threaded but some big ones are highly concurrent. To balance between -// memory overhead and minimum pointer chasing, we start with few entries and -// exponentially (4x) grow with a limit (255 entries). Note that parameters are -// picked for x64 architectures as hint and the actual size is calculated by -// Layout. -ThreadSafeArena::SerialArenaChunk* ThreadSafeArena::NewSerialArenaChunk( - uint32_t prev_capacity, void* id, SerialArena* serial) { - constexpr size_t kMaxBytes = 4096; // Can hold up to 255 entries. - constexpr size_t kGrowthFactor = 4; - constexpr size_t kHeaderSize = SerialArenaChunk::AllocSize(0); - constexpr size_t kEntrySize = SerialArenaChunk::AllocSize(1) - kHeaderSize; - - // On x64 arch: {4, 16, 64, 256, 256, ...} * 16. - size_t prev_bytes = SerialArenaChunk::AllocSize(prev_capacity); - size_t next_bytes = std::min(kMaxBytes, prev_bytes * kGrowthFactor); - uint32_t next_capacity = - static_cast(next_bytes - kHeaderSize) / kEntrySize; - // Growth based on bytes needs to be adjusted by AllocSize. - next_bytes = SerialArenaChunk::AllocSize(next_capacity); - void* mem; - mem = ::operator new(next_bytes); - - return new (mem) SerialArenaChunk{next_capacity, id, serial}; -} - -// Tries to reserve an entry by atomic fetch_add. If the head chunk is already -// full (size >= capacity), acquires the mutex and adds a new head. -void ThreadSafeArena::AddSerialArena(void* id, SerialArena* serial) { - SerialArenaChunk* head = head_.load(std::memory_order_acquire); - // Fast path without acquiring mutex. - if (!head->IsSentry() && head->insert(id, serial)) { - return; - } - - // Slow path with acquiring mutex. - absl::MutexLock lock(&mutex_); - - // Refetch and if someone else installed a new head, try allocating on that! - SerialArenaChunk* new_head = head_.load(std::memory_order_acquire); - if (new_head != head) { - if (new_head->insert(id, serial)) return; - // Update head to link to the latest one. - head = new_head; - } - - new_head = NewSerialArenaChunk(head->capacity(), id, serial); - new_head->set_next(head); - - // Use "std::memory_order_release" to make sure prior stores are visible after - // this one. - head_.store(new_head, std::memory_order_release); -} - -void ThreadSafeArena::Init() { - const bool message_owned = IsMessageOwned(); - if (!message_owned) { - // Message-owned arenas bypass thread cache and do not need life cycle ID. - tag_and_id_ = GetNextLifeCycleId(); - } else { - GOOGLE_DCHECK_EQ(tag_and_id_, kMessageOwnedArena); - } + // Message ownership is stored in tag_and_id_, and is set in the constructor. + // This flag bit must be preserved, even across calls to Reset(). + tag_and_id_ = id | (tag_and_id_ & kMessageOwnedArena); + hint_.store(nullptr, std::memory_order_relaxed); + threads_.store(nullptr, std::memory_order_relaxed); +#ifndef NDEBUG + GOOGLE_CHECK_EQ(was_message_owned, IsMessageOwned()); +#endif // NDEBUG arena_stats_ = Sample(); - head_.store(SentrySerialArenaChunk(), std::memory_order_relaxed); - GOOGLE_DCHECK_EQ(message_owned, IsMessageOwned()); - first_owner_ = &thread_cache(); +} - // Record allocation for the first block that was either user-provided or - // newly allocated. - ThreadSafeArenaStats::RecordAllocateStats( - arena_stats_.MutableStats(), - /*used=*/0, - /*allocated=*/first_arena_.SpaceAllocated(), - /*wasted=*/0); - - CacheSerialArena(&first_arena_); +void ThreadSafeArena::SetInitialBlock(void* mem, size_t size) { + SerialArena* serial = SerialArena::New({mem, size}, &thread_cache(), + arena_stats_.MutableStats()); + serial->set_next(NULL); + threads_.store(serial, std::memory_order_relaxed); + CacheSerialArena(serial); } ThreadSafeArena::~ThreadSafeArena() { @@ -671,41 +342,32 @@ ThreadSafeArena::~ThreadSafeArena() { size_t space_allocated = 0; auto mem = Free(&space_allocated); + + // Policy is about to get deleted. + auto* p = alloc_policy_.get(); + ArenaMetricsCollector* collector = p ? p->metrics_collector : nullptr; + if (alloc_policy_.is_user_owned_initial_block()) { #ifdef ADDRESS_SANITIZER // Unpoison the initial block, now that it's going back to the user. ASAN_UNPOISON_MEMORY_REGION(mem.ptr, mem.size); #endif // ADDRESS_SANITIZER space_allocated += mem.size; - } else if (mem.size > 0) { + } else { GetDeallocator(alloc_policy_.get(), &space_allocated)(mem); } + + if (collector) collector->OnDestroy(space_allocated); } SerialArena::Memory ThreadSafeArena::Free(size_t* space_allocated) { + SerialArena::Memory mem = {nullptr, 0}; auto deallocator = GetDeallocator(alloc_policy_.get(), space_allocated); - - WalkSerialArenaChunk([deallocator](SerialArenaChunk* chunk) { - absl::Span> span = chunk->arenas(); - // Walks arenas backward to handle the first serial arena the last. Freeing - // in reverse-order to the order in which objects were created may not be - // necessary to Free and we should revisit this. (b/247560530) - for (auto it = span.rbegin(); it != span.rend(); ++it) { - SerialArena* serial = it->load(std::memory_order_relaxed); - GOOGLE_DCHECK_NE(serial, nullptr); - // Always frees the first block of "serial" as it cannot be user-provided. - SerialArena::Memory mem = serial->Free(deallocator); - GOOGLE_DCHECK_NE(mem.ptr, nullptr); - deallocator(mem); - } - - // Delete the chunk as we're done with it. - internal::SizedDelete(chunk, - SerialArenaChunk::AllocSize(chunk->capacity())); + PerSerialArena([deallocator, &mem](SerialArena* a) { + if (mem.ptr) deallocator(mem); + mem = a->Free(deallocator); }); - - // The first block of the first arena is special and let the caller handle it. - return first_arena_.Free(deallocator); + return mem; } uint64_t ThreadSafeArena::Reset() { @@ -713,169 +375,132 @@ uint64_t ThreadSafeArena::Reset() { // refer to memory in other blocks. CleanupList(); - // Discard all blocks except the first one. Whether it is user-provided or - // allocated, always reuse the first block for the first arena. + // Discard all blocks except the special block (if present). size_t space_allocated = 0; auto mem = Free(&space_allocated); - space_allocated += mem.size; + arena_stats_.RecordReset(); - // Reset the first arena with the first block. This avoids redundant - // free / allocation and re-allocating for AllocationPolicy. Adjust offset if - // we need to preserve alloc_policy_. - if (alloc_policy_.is_user_owned_initial_block() || - alloc_policy_.get() != nullptr) { - size_t offset = alloc_policy_.get() == nullptr - ? kBlockHeaderSize - : kBlockHeaderSize + kAllocPolicySize; - first_arena_.Init(new (mem.ptr) ArenaBlock{nullptr, mem.size}, offset); + AllocationPolicy* policy = alloc_policy_.get(); + if (policy) { + auto saved_policy = *policy; + if (alloc_policy_.is_user_owned_initial_block()) { + space_allocated += mem.size; + } else { + GetDeallocator(alloc_policy_.get(), &space_allocated)(mem); + mem.ptr = nullptr; + mem.size = 0; + } + ArenaMetricsCollector* collector = saved_policy.metrics_collector; + if (collector) collector->OnReset(space_allocated); + InitializeWithPolicy(mem.ptr, mem.size, saved_policy); } else { - first_arena_.Init(SentryArenaBlock(), 0); + GOOGLE_DCHECK(!alloc_policy_.should_record_allocs()); + // Nullptr policy + if (alloc_policy_.is_user_owned_initial_block()) { + space_allocated += mem.size; + InitializeFrom(mem.ptr, mem.size); + } else { + GetDeallocator(alloc_policy_.get(), &space_allocated)(mem); + Init(); + } } - // Since the first block and potential alloc_policy on the first block is - // preserved, this can be initialized by Init(). - Init(); - return space_allocated; } -void* ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*)) { +std::pair +ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, + const std::type_info* type) { SerialArena* arena; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAlignedWithCleanup(n, align, destructor); + if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && + GetSerialArenaFast(&arena))) { + return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get()); } else { - return AllocateAlignedWithCleanupFallback(n, align, destructor); + return AllocateAlignedWithCleanupFallback(n, type); } } void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) { SerialArena* arena; if (PROTOBUF_PREDICT_FALSE(!GetSerialArenaFast(&arena))) { - arena = GetSerialArenaFallback(kMaxCleanupNodeSize); + arena = GetSerialArenaFallback(&thread_cache()); } - arena->AddCleanup(elem, cleanup); + arena->AddCleanup(elem, cleanup, AllocPolicy()); } PROTOBUF_NOINLINE -void* ThreadSafeArena::AllocateAlignedWithCleanupFallback( - size_t n, size_t align, void (*destructor)(void*)) { - return GetSerialArenaFallback(n + kMaxCleanupNodeSize) - ->AllocateAlignedWithCleanup(n, align, destructor); -} - -template -void ThreadSafeArena::WalkConstSerialArenaChunk(Functor fn) const { - const SerialArenaChunk* chunk = head_.load(std::memory_order_acquire); - - for (; !chunk->IsSentry(); chunk = chunk->next_chunk()) { - fn(chunk); - } -} - -template -void ThreadSafeArena::WalkSerialArenaChunk(Functor fn) { - // By omitting an Acquire barrier we help the sanitizer that any user code - // that doesn't properly synchronize Reset() or the destructor will throw a - // TSAN warning. - SerialArenaChunk* chunk = head_.load(std::memory_order_relaxed); - - while (!chunk->IsSentry()) { - // Cache next chunk in case this chunk is destroyed. - SerialArenaChunk* next_chunk = chunk->next_chunk(); - fn(chunk); - chunk = next_chunk; - } -} - -template -void ThreadSafeArena::PerConstSerialArenaInChunk(Functor fn) const { - WalkConstSerialArenaChunk([&fn](const SerialArenaChunk* chunk) { - for (const auto& each : chunk->arenas()) { - const SerialArena* serial = each.load(std::memory_order_acquire); - // It is possible that newly added SerialArena is not updated although - // size was. This is acceptable for SpaceAllocated and SpaceUsed. - if (serial == nullptr) continue; - fn(serial); +void* ThreadSafeArena::AllocateAlignedFallback(size_t n, + const std::type_info* type) { + if (alloc_policy_.should_record_allocs()) { + alloc_policy_.RecordAlloc(type, n); + SerialArena* arena; + if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { + return arena->AllocateAligned(n, alloc_policy_.get()); } - }); + } + return GetSerialArenaFallback(&thread_cache()) + ->AllocateAligned(n, alloc_policy_.get()); +} + +PROTOBUF_NOINLINE +std::pair +ThreadSafeArena::AllocateAlignedWithCleanupFallback( + size_t n, const std::type_info* type) { + if (alloc_policy_.should_record_allocs()) { + alloc_policy_.RecordAlloc(type, n); + SerialArena* arena; + if (GetSerialArenaFast(&arena)) { + return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get()); + } + } + return GetSerialArenaFallback(&thread_cache()) + ->AllocateAlignedWithCleanup(n, alloc_policy_.get()); } uint64_t ThreadSafeArena::SpaceAllocated() const { - uint64_t space_allocated = first_arena_.SpaceAllocated(); - PerConstSerialArenaInChunk([&space_allocated](const SerialArena* serial) { - space_allocated += serial->SpaceAllocated(); - }); - return space_allocated; + SerialArena* serial = threads_.load(std::memory_order_acquire); + uint64_t res = 0; + for (; serial; serial = serial->next()) { + res += serial->SpaceAllocated(); + } + return res; } uint64_t ThreadSafeArena::SpaceUsed() const { - // First arena is inlined to ThreadSafeArena and the first block's overhead is - // smaller than others that contain SerialArena. - uint64_t space_used = first_arena_.SpaceUsed(); - PerConstSerialArenaInChunk([&space_used](const SerialArena* serial) { - // SerialArena on chunks directly allocated from the block and needs to be - // subtracted from SpaceUsed. - space_used += serial->SpaceUsed() - kSerialArenaSize; - }); + SerialArena* serial = threads_.load(std::memory_order_acquire); + uint64_t space_used = 0; + for (; serial; serial = serial->next()) { + space_used += serial->SpaceUsed(); + } return space_used - (alloc_policy_.get() ? sizeof(AllocationPolicy) : 0); } -template -PROTOBUF_NOINLINE void* ThreadSafeArena::AllocateAlignedFallback(size_t n) { - return GetSerialArenaFallback(n)->AllocateAligned(n); -} - -template void* ThreadSafeArena::AllocateAlignedFallback< - AllocationClient::kDefault>(size_t); -template void* - ThreadSafeArena::AllocateAlignedFallback(size_t); - void ThreadSafeArena::CleanupList() { - WalkSerialArenaChunk([](SerialArenaChunk* chunk) { - absl::Span> span = chunk->arenas(); - // Walks arenas backward to handle the first serial arena the last. - // Destroying in reverse-order to the construction is often assumed by users - // and required not to break inter-object dependencies. (b/247560530) - for (auto it = span.rbegin(); it != span.rend(); ++it) { - SerialArena* serial = it->load(std::memory_order_relaxed); - GOOGLE_DCHECK_NE(serial, nullptr); - serial->CleanupList(); - } - }); - // First arena must be cleaned up last. (b/247560530) - first_arena_.CleanupList(); + PerSerialArena([](SerialArena* a) { a->CleanupList(); }); } PROTOBUF_NOINLINE -SerialArena* ThreadSafeArena::GetSerialArenaFallback(size_t n) { - void* const id = &thread_cache(); - if (id == first_owner_) { - CacheSerialArena(&first_arena_); - return &first_arena_; - } - - // Search matching SerialArena. - SerialArena* serial = nullptr; - WalkConstSerialArenaChunk([&serial, id](const SerialArenaChunk* chunk) { - absl::Span> ids = chunk->ids(); - for (uint32_t i = 0; i < ids.size(); ++i) { - if (ids[i].load(std::memory_order_relaxed) == id) { - serial = chunk->arena(i).load(std::memory_order_relaxed); - GOOGLE_DCHECK_NE(serial, nullptr); - break; - } +SerialArena* ThreadSafeArena::GetSerialArenaFallback(void* me) { + // Look for this SerialArena in our linked list. + SerialArena* serial = threads_.load(std::memory_order_acquire); + for (; serial; serial = serial->next()) { + if (serial->owner() == me) { + break; } - }); + } if (!serial) { // This thread doesn't have any SerialArena, which also means it doesn't - // have any blocks yet. So we'll allocate its first block now. It must be - // big enough to host SerialArena and the pending request. + // have any blocks yet. So we'll allocate its first block now. serial = SerialArena::New( - AllocateMemory(alloc_policy_.get(), 0, n + kSerialArenaSize), *this); + AllocateMemory(alloc_policy_.get(), 0, kSerialArenaSize), me, + arena_stats_.MutableStats()); - AddSerialArena(id, serial); + SerialArena* head = threads_.load(std::memory_order_relaxed); + do { + serial->set_next(head); + } while (!threads_.compare_exchange_weak( + head, serial, std::memory_order_release, std::memory_order_relaxed)); } CacheSerialArena(serial); @@ -884,18 +509,29 @@ SerialArena* ThreadSafeArena::GetSerialArenaFallback(size_t n) { } // namespace internal -void* Arena::Allocate(size_t n) { return impl_.AllocateAligned(n); } - -void* Arena::AllocateForArray(size_t n) { - return impl_.AllocateAligned(n); +PROTOBUF_FUNC_ALIGN(32) +void* Arena::AllocateAlignedNoHook(size_t n) { + return impl_.AllocateAligned(n, nullptr); } -void* Arena::AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*)) { - return impl_.AllocateAlignedWithCleanup(n, align, destructor); +PROTOBUF_FUNC_ALIGN(32) +void* Arena::AllocateAlignedWithHook(size_t n, const std::type_info* type) { + return impl_.AllocateAligned(n, type); +} + +PROTOBUF_FUNC_ALIGN(32) +void* Arena::AllocateAlignedWithHookForArray(size_t n, + const std::type_info* type) { + return impl_.AllocateAligned(n, type); +} + +PROTOBUF_FUNC_ALIGN(32) +std::pair +Arena::AllocateAlignedWithCleanup(size_t n, const std::type_info* type) { + return impl_.AllocateAlignedWithCleanup(n, type); } } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/arena.h b/libs/protobuf/src/google/protobuf/arena.h index d3dec65..3b5f16c 100644 --- a/libs/protobuf/src/google/protobuf/arena.h +++ b/libs/protobuf/src/google/protobuf/arena.h @@ -49,12 +49,11 @@ using type_info = ::type_info; #endif #include -#include "google/protobuf/arena_config.h" -#include "google/protobuf/arena_impl.h" -#include "google/protobuf/port.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -87,15 +86,25 @@ class InternalMetadata; // defined in metadata_lite.h class LazyField; // defined in lazy_field.h class EpsCopyInputStream; // defined in parse_context.h class RepeatedPtrFieldBase; // defined in repeated_ptr_field.h -class TcParser; // defined in generated_message_tctable_impl.h template class GenericTypeHandler; // defined in repeated_field.h +inline PROTOBUF_ALWAYS_INLINE +void* AlignTo(void* ptr, size_t align) { + return reinterpret_cast( + (reinterpret_cast(ptr) + align - 1) & (~align + 1)); +} + +// Templated cleanup methods. +template +void arena_destruct_object(void* object) { + reinterpret_cast(object)->~T(); +} + template struct ObjectDestructor { - constexpr static void (*destructor)(void*) = - &internal::cleanup::arena_destruct_object; + constexpr static void (*destructor)(void*) = &arena_destruct_object; }; template @@ -122,7 +131,7 @@ struct ArenaOptions { // here. size_t max_block_size; - // An initial block of memory for the arena to use, or nullptr for none. If + // An initial block of memory for the arena to use, or NULL for none. If // provided, the block must live at least as long as the arena itself. The // creator of the Arena retains ownership of the block after the Arena is // destroyed. @@ -144,8 +153,8 @@ struct ArenaOptions { ArenaOptions() : start_block_size(internal::AllocationPolicy::kDefaultStartBlockSize), - max_block_size(internal::GetDefaultArenaMaxBlockSize()), - initial_block(nullptr), + max_block_size(internal::AllocationPolicy::kDefaultMaxBlockSize), + initial_block(NULL), initial_block_size(0), block_alloc(nullptr), block_dealloc(nullptr), @@ -167,6 +176,7 @@ struct ArenaOptions { res.max_block_size = max_block_size; res.block_alloc = block_alloc; res.block_dealloc = block_dealloc; + res.metrics_collector = MetricsCollector(); return res; } @@ -176,6 +186,14 @@ struct ArenaOptions { friend class ArenaOptionsTestFriend; }; +// Support for non-RTTI environments. (The metrics hooks API uses type +// information.) +#if PROTOBUF_RTTI +#define RTTI_TYPE_ID(type) (&typeid(type)) +#else +#define RTTI_TYPE_ID(type) (NULL) +#endif + // Arena allocator. Arena allocation replaces ordinary (heap-based) allocation // with new/delete, and improves performance by aggregating allocations into // larger blocks and freeing allocations all at once. Protocol messages are @@ -203,7 +221,7 @@ struct ArenaOptions { // with `args` (without `arena`), called when a T is allocated on the heap; // and a constructor callable with `Arena* arena, Args&&... args`, called when // a T is allocated on an arena. If the second constructor is called with a -// null arena pointer, it must be equivalent to invoking the first +// NULL arena pointer, it must be equivalent to invoking the first // (`args`-only) constructor. // // - The type T must have a particular type trait: a nested type @@ -213,7 +231,7 @@ struct ArenaOptions { // // - The type T *may* have the type trait |DestructorSkippable_|. If this type // trait is present in the type, then its destructor will not be called if and -// only if it was passed a non-null arena pointer. If this type trait is not +// only if it was passed a non-NULL arena pointer. If this type trait is not // present on the type, then its destructor is always called when the // containing arena is destroyed. // @@ -252,10 +270,13 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { inline ~Arena() {} + // TODO(protobuf-team): Fix callers to use constructor and delete this method. + void Init(const ArenaOptions&) {} + // API to create proto2 message objects on the arena. If the arena passed in - // is nullptr, then a heap allocated object is returned. Type T must be a - // message defined in a .proto file with cc_enable_arenas set to true, - // otherwise a compilation error will occur. + // is NULL, then a heap allocated object is returned. Type T must be a message + // defined in a .proto file with cc_enable_arenas set to true, otherwise a + // compilation error will occur. // // RepeatedField and RepeatedPtrField may also be instantiated directly on an // arena with this method. @@ -294,26 +315,17 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { static_cast(args)...); } - // API to delete any objects not on an arena. This can be used to safely - // clean up messages or repeated fields without knowing whether or not they're - // owned by an arena. The pointer passed to this function should not be used - // again. - template - PROTOBUF_ALWAYS_INLINE static void Destroy(T* obj) { - if (InternalGetOwningArena(obj) == nullptr) delete obj; - } - // Allocates memory with the specific size and alignment. void* AllocateAligned(size_t size, size_t align = 8) { if (align <= 8) { - return Allocate(internal::AlignUpTo8(size)); + return AllocateAlignedNoHook(internal::AlignUpTo8(size)); } else { // We are wasting space by over allocating align - 8 bytes. Compared // to a dedicated function that takes current alignment in consideration. // Such a scheme would only waste (align - 8)/2 bytes on average, but // requires a dedicated function in the outline arena allocation // functions. Possibly re-evaluate tradeoffs later. - return internal::AlignTo(Allocate(size + align - 8), align); + return internal::AlignTo(AllocateAlignedNoHook(size + align - 8), align); } } @@ -332,7 +344,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { "CreateArray requires a trivially destructible type"); GOOGLE_CHECK_LE(num_elements, std::numeric_limits::max() / sizeof(T)) << "Requested size is too large to fit into size_t."; - if (arena == nullptr) { + if (arena == NULL) { return static_cast(::operator new[](num_elements * sizeof(T))); } else { return arena->CreateInternalRawArray(num_elements); @@ -347,12 +359,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // sizes of the underlying blocks. uint64_t 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. This is a best-effort - // estimate and may inaccurately calculate space used by other threads - // executing concurrently with the call to this method. These inaccuracies - // are due to race conditions, and are bounded but unpredictable. Stale data - // can lead to underestimates of the space used, and race conditions can lead - // to overestimates (up to the current block size). + // 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. uint64_t SpaceUsed() const { return impl_.SpaceUsed(); } // Frees all storage allocated by this arena after calling destructors @@ -376,8 +385,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // arena-allocated memory. template PROTOBUF_ALWAYS_INLINE void OwnDestructor(T* object) { - if (object != nullptr) { - impl_.AddCleanup(object, &internal::cleanup::arena_destruct_object); + if (object != NULL) { + impl_.AddCleanup(object, &internal::arena_destruct_object); } } @@ -391,9 +400,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { } // Retrieves the arena associated with |value| if |value| is an arena-capable - // message, or nullptr otherwise. If possible, the call resolves at compile - // time. Note that we can often devirtualize calls to `value->GetArena()` so - // usually calling this method is unnecessary. + // message, or NULL otherwise. If possible, the call resolves at compile time. + // Note that we can often devirtualize calls to `value->GetArena()` so usually + // calling this method is unnecessary. template PROTOBUF_ALWAYS_INLINE static Arena* GetArena(const T* value) { return GetArenaInternal(value); @@ -402,62 +411,40 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { template class InternalHelper { private: - // A SFINAE friendly trait that probes for `U` but always evalues to - // `Arena*`. - template - using EnableIfArena = - typename std::enable_if::value, Arena*>::type; - - // Rather than use SFINAE that must fully cover the space of options in a - // mutually exclusive fashion, we use implicit conversions to base classes - // to force an explicit ranking for our preferences. The lowest ranked - // version that compiles will be accepted. - struct Rank2 {}; - struct Rank1 : Rank2 {}; - struct Rank0 : Rank1 {}; - - static Arena* GetOwningArena(const T* p) { - return GetOwningArena(Rank0{}, p); - } - - template - static auto GetOwningArena(Rank0, const U* p) - -> EnableIfArenaGetOwningArena())> { - return p->GetOwningArena(); - } - - template - static Arena* GetOwningArena(Rank1, const U* p) { - return nullptr; - } + // Provides access to protected GetOwningArena to generated messages. + static Arena* GetOwningArena(const T* p) { return p->GetOwningArena(); } static void InternalSwap(T* a, T* b) { a->InternalSwap(b); } - static Arena* GetArenaForAllocation(const T* p) { - return GetArenaForAllocation(Rank0{}, p); - } - - static Arena* GetArena(const T* p) { - // Rather than replicate probing for `GetArena` with fallback to nullptr, - // we borrow the implementation of `GetArenaForAllocation` but skip - // `Rank0` which probes for `GetArenaForAllocation`. - return GetArenaForAllocation(Rank1{}, p); - } - - template - static auto GetArenaForAllocation(Rank0, const U* p) - -> EnableIfArenaGetArenaForAllocation())> { + static Arena* GetArenaForAllocationInternal( + const T* p, std::true_type /*is_derived_from*/) { return p->GetArenaForAllocation(); } - template - static auto GetArenaForAllocation(Rank1, const U* p) - -> EnableIfArenaGetArena())> { + static Arena* GetArenaForAllocationInternal( + const T* p, std::false_type /*is_derived_from*/) { + return GetArenaForAllocationForNonMessage( + p, typename is_arena_constructable::type()); + } + + static Arena* GetArenaForAllocationForNonMessage( + const T* p, std::true_type /*is_arena_constructible*/) { return p->GetArena(); } - template - static Arena* GetArenaForAllocation(Rank2, const U* p) { + static Arena* GetArenaForAllocationForNonMessage( + const T* p, std::false_type /*is_arena_constructible*/) { + return GetArenaForAllocationForNonMessageNonArenaConstructible( + p, typename has_get_arena::type()); + } + + static Arena* GetArenaForAllocationForNonMessageNonArenaConstructible( + const T* p, std::true_type /*has_get_arena*/) { + return p->GetArena(); + } + + static Arena* GetArenaForAllocationForNonMessageNonArenaConstructible( + const T* /* p */, std::false_type /*has_get_arena*/) { return nullptr; } @@ -483,6 +470,18 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { sizeof(char)> is_arena_constructable; + template () + .GetArena())>::value, + int>::type = 0> + static char HasGetArena(decltype(&U::GetArena)); + template + static double HasGetArena(...); + + typedef std::integral_constant(nullptr)) == + sizeof(char)> + has_get_arena; template static T* Construct(void* ptr, Args&&... args) { @@ -493,6 +492,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { return new T(nullptr); } + static Arena* GetArena(const T* p) { return p->GetArena(); } + friend class Arena; friend class TestUtil::ReflectionTester; }; @@ -508,7 +509,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // For internal use only. template static Arena* InternalGetArenaForAllocation(const T* p) { - return InternalHelper::GetArenaForAllocation(p); + return InternalHelper::GetArenaForAllocationInternal( + p, std::is_convertible()); } // Creates message-owned arena. For internal use only. @@ -540,6 +542,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { private: internal::ThreadSafeArena impl_; + template + struct has_get_arena : InternalHelper::has_get_arena {}; + // Constructor solely used by message-owned arena. inline Arena(internal::MessageOwned) : impl_(internal::MessageOwned{}) {} @@ -558,7 +563,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { static_assert( InternalHelper::is_arena_constructable::value, "CreateMessage can only construct types that are ArenaConstructable"); - if (arena == nullptr) { + if (arena == NULL) { return new T(nullptr, static_cast(args)...); } else { return arena->DoCreateMessage(static_cast(args)...); @@ -573,7 +578,7 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { static_assert( InternalHelper::is_arena_constructable::value, "CreateMessage can only construct types that are ArenaConstructable"); - if (arena == nullptr) { + if (arena == NULL) { // Generated arena constructor T(Arena*) is protected. Call via // InternalHelper. return InternalHelper::New(); @@ -582,13 +587,27 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { } } + // Allocate and also optionally call collector with the allocated type info + // when allocation recording is enabled. PROTOBUF_NDEBUG_INLINE void* AllocateInternal(size_t size, size_t align, - void (*destructor)(void*)) { + void (*destructor)(void*), + const std::type_info* type) { // Monitor allocation if needed. if (destructor == nullptr) { - return AllocateAligned(size, align); + return AllocateAlignedWithHook(size, align, type); } else { - return AllocateAlignedWithCleanup(size, align, destructor); + if (align <= 8) { + auto res = AllocateAlignedWithCleanup(internal::AlignUpTo8(size), type); + res.second->elem = res.first; + res.second->cleanup = destructor; + return res.first; + } else { + auto res = AllocateAlignedWithCleanup(size + align - 8, type); + auto ptr = internal::AlignTo(res.first, align); + res.second->elem = ptr; + res.second->cleanup = destructor; + return ptr; + } } } @@ -627,7 +646,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // We count on compiler to realize that if sizeof(T) is a multiple of // 8 AlignUpTo can be elided. const size_t n = sizeof(T) * num_elements; - return static_cast(AllocateAlignedForArray(n, alignof(T))); + return static_cast( + AllocateAlignedWithHookForArray(n, alignof(T), RTTI_TYPE_ID(T))); } template @@ -636,7 +656,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { AllocateInternal(sizeof(T), alignof(T), internal::ObjectDestructor< InternalHelper::is_destructor_skippable::value, - T>::destructor), + T>::destructor, + RTTI_TYPE_ID(T)), this, std::forward(args)...); } @@ -687,8 +708,9 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { internal::ObjectDestructor::value, T>::destructor; T* result = - new (arena->AllocateInternal(sizeof(T), alignof(T), destructor)) - T(std::forward(args)...); + new (arena->AllocateInternal(sizeof(T), alignof(T), destructor, + RTTI_TYPE_ID(T))) + T(std::forward(args)...); return result; } } @@ -701,7 +723,8 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { auto destructor = internal::ObjectDestructor::value, T>::destructor; - return new (arena->AllocateInternal(sizeof(T), alignof(T), destructor)) + return new (arena->AllocateInternal(sizeof(T), alignof(T), destructor, + RTTI_TYPE_ID(T))) T(std::forward(args)...); } } @@ -713,13 +736,13 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // using the virtual destructor instead. template PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::true_type) { - if (object != nullptr) { + if (object != NULL) { impl_.AddCleanup(object, &internal::arena_delete_object); } } template PROTOBUF_ALWAYS_INLINE void OwnInternal(T* object, std::false_type) { - if (object != nullptr) { + if (object != NULL) { impl_.AddCleanup(object, &internal::arena_delete_object); } } @@ -727,35 +750,87 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { // Implementation for GetArena(). Only message objects with // InternalArenaConstructable_ tags can be associated with an arena, and such // objects must implement a GetArena() method. - template + template ::value, int>::type = 0> PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { return InternalHelper::GetArena(value); } + template ::value && + has_get_arena::value, + int>::type = 0> + PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { + return value->GetArena(); + } + template ::value && + !has_get_arena::value, + int>::type = 0> + PROTOBUF_ALWAYS_INLINE static Arena* GetArenaInternal(const T* value) { + (void)value; + return nullptr; + } - void* AllocateAlignedForArray(size_t n, size_t align) { + template + PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArena(const T* value) { + return GetOwningArenaInternal( + value, std::is_convertible()); + } + + // Implementation for GetOwningArena(). All and only message objects have + // GetOwningArena() method. + template + PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal( + const T* value, std::true_type) { + return InternalHelper::GetOwningArena(value); + } + template + PROTOBUF_ALWAYS_INLINE static Arena* GetOwningArenaInternal( + const T* /* value */, std::false_type) { + return nullptr; + } + + void* AllocateAlignedWithHookForArray(size_t n, size_t align, + const std::type_info* type) { if (align <= 8) { - return AllocateForArray(internal::AlignUpTo8(n)); + return AllocateAlignedWithHookForArray(internal::AlignUpTo8(n), type); } else { // We are wasting space by over allocating align - 8 bytes. Compared // to a dedicated function that takes current alignment in consideration. // Such a scheme would only waste (align - 8)/2 bytes on average, but // requires a dedicated function in the outline arena allocation // functions. Possibly re-evaluate tradeoffs later. - return internal::AlignTo(AllocateForArray(n + align - 8), align); + return internal::AlignTo( + AllocateAlignedWithHookForArray(n + align - 8, type), align); } } - void* Allocate(size_t n); - void* AllocateForArray(size_t n); - void* AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*)); + void* AllocateAlignedWithHook(size_t n, size_t align, + const std::type_info* type) { + if (align <= 8) { + return AllocateAlignedWithHook(internal::AlignUpTo8(n), type); + } else { + // We are wasting space by over allocating align - 8 bytes. Compared + // to a dedicated function that takes current alignment in consideration. + // Such a scheme would only waste (align - 8)/2 bytes on average, but + // requires a dedicated function in the outline arena allocation + // functions. Possibly re-evaluate tradeoffs later. + return internal::AlignTo(AllocateAlignedWithHook(n + align - 8, type), + align); + } + } + + void* AllocateAlignedNoHook(size_t n); + void* AllocateAlignedWithHook(size_t n, const std::type_info* type); + void* AllocateAlignedWithHookForArray(size_t n, const std::type_info* type); + std::pair + AllocateAlignedWithCleanup(size_t n, const std::type_info* type); template friend class internal::GenericTypeHandler; friend class internal::InternalMetadata; // For user_arena(). friend class internal::LazyField; // For CreateMaybeMessage. friend class internal::EpsCopyInputStream; // For parser performance - friend class internal::TcParser; // For parser performance friend class MessageLite; template friend class Map; @@ -765,9 +840,12 @@ class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final { friend struct internal::ArenaTestPeer; }; +// Defined above for supporting environments without RTTI. +#undef RTTI_TYPE_ID + } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_ARENA_H__ diff --git a/libs/protobuf/src/google/protobuf/arena_align.h b/libs/protobuf/src/google/protobuf/arena_align.h deleted file mode 100644 index 968d5be..0000000 --- a/libs/protobuf/src/google/protobuf/arena_align.h +++ /dev/null @@ -1,155 +0,0 @@ -// 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 provides alignment utilities for use in arenas. -// -// `ArenaAlign` contains a single `align` data member and provides -// the below functions which operate on the given alignment. -// -// Ceil(size_t n) - rounds `n` up to the nearest `align` boundary. -// Floor(size_t n) - rounds `n` down to the nearest `align` boundary. -// Ceil(T* P) - rounds `p` up to the nearest `align` boundary. -// IsAligned(size_t n) - returns true if `n` is aligned to `align` -// IsAligned(T* p) - returns true if `p` is aligned to `align` -// CheckAligned(T* p) - returns `p`. Checks alignment of `p` in debug. -// -// Additionally there is an optimized `CeilDefaultAligned(T*)` method which is -// equivalent to `Ceil(ArenaAlignDefault().CheckAlign(p))` but more efficiently -// implemented as a 'check only' for ArenaAlignDefault. -// -// These classes allow for generic arena logic using 'alignment policies'. -// -// For example: -// -// template -// void* NaiveAlloc(size_t n, Align align) { -// align.CheckAligned(n); -// uint8_t* ptr = align.CeilDefaultAligned(ptr_); -// ptr_ += n; -// return ptr; -// } -// -// void CallSites() { -// void *p1 = NaiveAlloc(n, ArenaAlignDefault()); -// void *p2 = NaiveAlloc(n, ArenaAlignAs(32)); -// } -// -#ifndef GOOGLE_PROTOBUF_ARENA_ALIGN_H__ -#define GOOGLE_PROTOBUF_ARENA_ALIGN_H__ - -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/numeric/bits.h" - -namespace google { -namespace protobuf { -namespace internal { - -struct ArenaAlignDefault { - static constexpr size_t align = 8; // NOLINT - - static constexpr bool IsAligned(size_t n) { return (n & (align - 1)) == 0; } - - template - static bool IsAligned(T* ptr) { - return (reinterpret_cast(ptr) & (align - 1)) == 0; - } - - static constexpr size_t Ceil(size_t n) { return (n + align - 1) & -align; } - static constexpr size_t Floor(size_t n) { return (n & ~(align - 1)); } - - template - T* Ceil(T* ptr) const { - uintptr_t intptr = reinterpret_cast(ptr); - return reinterpret_cast((intptr + align - 1) & -align); - } - - template - T* CeilDefaultAligned(T* ptr) const { - return ArenaAlignDefault().CheckAligned(ptr); - } - - // Address sanitizer enabled alignment check - template - static T* CheckAligned(T* ptr) { - GOOGLE_DCHECK(IsAligned(ptr)) << static_cast(ptr); - return ptr; - } -}; - -struct ArenaAlign { - static constexpr bool IsDefault() { return false; }; - - size_t align; - - constexpr bool IsAligned(size_t n) const { return (n & (align - 1)) == 0; } - - template - bool IsAligned(T* ptr) const { - return (reinterpret_cast(ptr) & (align - 1)) == 0; - } - - constexpr size_t Ceil(size_t n) const { return (n + align - 1) & -align; } - constexpr size_t Floor(size_t n) const { return (n & ~(align - 1)); } - - template - T* Ceil(T* ptr) const { - uintptr_t intptr = reinterpret_cast(ptr); - return reinterpret_cast((intptr + align - 1) & -align); - } - - template - T* CeilDefaultAligned(T* ptr) const { - return Ceil(ArenaAlignDefault().CheckAligned(ptr)); - } - - // Address sanitizer enabled alignment check - template - T* CheckAligned(T* ptr) const { - GOOGLE_DCHECK(IsAligned(ptr)) << static_cast(ptr); - return ptr; - } -}; - -inline ArenaAlign ArenaAlignAs(size_t align) { - // align must be a non zero power of 2 >= 8 - GOOGLE_DCHECK_NE(align, 0); - GOOGLE_DCHECK(absl::has_single_bit(align)) << "Invalid alignment " << align; - return ArenaAlign{align}; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ARENA_ALIGN_H__ diff --git a/libs/protobuf/src/google/protobuf/arena_align_test.cc b/libs/protobuf/src/google/protobuf/arena_align_test.cc deleted file mode 100644 index e17cb33..0000000 --- a/libs/protobuf/src/google/protobuf/arena_align_test.cc +++ /dev/null @@ -1,215 +0,0 @@ -// 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/arena_align.h" - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { -namespace { - -using ::testing::Eq; - -TEST(ArenaAlignDefault, Align) { - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.align, Eq(8)); -} - -TEST(ArenaAlignDefault, Floor) { - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.Floor(0), Eq(0)); - EXPECT_THAT(align_default.Floor(1), Eq(0)); - EXPECT_THAT(align_default.Floor(7), Eq(0)); - EXPECT_THAT(align_default.Floor(8), Eq(8)); - EXPECT_THAT(align_default.Floor(9), Eq(8)); - EXPECT_THAT(align_default.Floor(15), Eq(8)); - EXPECT_THAT(align_default.Floor(16), Eq(16)); -} - -TEST(ArenaAlignDefault, Ceil) { - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.Ceil(0), Eq(0)); - EXPECT_THAT(align_default.Ceil(1), Eq(8)); - EXPECT_THAT(align_default.Ceil(7), Eq(8)); - EXPECT_THAT(align_default.Ceil(8), Eq(8)); - EXPECT_THAT(align_default.Ceil(9), Eq(16)); - EXPECT_THAT(align_default.Ceil(15), Eq(16)); - EXPECT_THAT(align_default.Ceil(16), Eq(16)); -} - -TEST(ArenaAlignDefault, CeilPtr) { - alignas(8) char p[17] = {0}; - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.Ceil(p + 0), Eq(p + 0)); - EXPECT_THAT(align_default.Ceil(p + 1), Eq(p + 8)); - EXPECT_THAT(align_default.Ceil(p + 7), Eq(p + 8)); - EXPECT_THAT(align_default.Ceil(p + 8), Eq(p + 8)); - EXPECT_THAT(align_default.Ceil(p + 9), Eq(p + 16)); - EXPECT_THAT(align_default.Ceil(p + 15), Eq(p + 16)); - EXPECT_THAT(align_default.Ceil(p + 16), Eq(p + 16)); -} - -TEST(ArenaAlignDefault, CheckAligned) { - alignas(8) char p[17] = {0}; - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.CheckAligned(p + 0), Eq(p + 0)); - EXPECT_THAT(align_default.CheckAligned(p + 8), Eq(p + 8)); - EXPECT_THAT(align_default.CheckAligned(p + 16), Eq(p + 16)); -#ifdef PROTOBUF_HAS_DEATH_TEST - EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 1), ".*"); - EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 7), ".*"); - EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 9), ".*"); - EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 15), ".*"); - EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 17), ".*"); -#endif // PROTOBUF_HAS_DEATH_TEST -} - -TEST(ArenaAlignDefault, CeilDefaultAligned) { - alignas(8) char p[17] = {0}; - auto align_default = ArenaAlignDefault(); - EXPECT_THAT(align_default.CeilDefaultAligned(p + 0), Eq(p + 0)); - EXPECT_THAT(align_default.CeilDefaultAligned(p + 8), Eq(p + 8)); - EXPECT_THAT(align_default.CeilDefaultAligned(p + 16), Eq(p + 16)); -#ifdef PROTOBUF_HAS_DEATH_TEST - EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 1), ".*"); - EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 7), ".*"); - EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 9), ".*"); - EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 15), ".*"); - EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 17), ".*"); -#endif // PROTOBUF_HAS_DEATH_TEST -} - -TEST(ArenaAlignDefault, IsAligned) { - auto align_default = ArenaAlignDefault(); - EXPECT_TRUE(align_default.IsAligned(0)); - EXPECT_FALSE(align_default.IsAligned(1)); - EXPECT_FALSE(align_default.IsAligned(7)); - EXPECT_TRUE(align_default.IsAligned(8)); - EXPECT_FALSE(align_default.IsAligned(9)); - EXPECT_FALSE(align_default.IsAligned(15)); - EXPECT_TRUE(align_default.IsAligned(16)); -} - -TEST(ArenaAlign, Align) { - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.align, Eq(64)); -} - -TEST(ArenaAlign, Floor) { - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.Floor(0), Eq(0)); - EXPECT_THAT(align_64.Floor(1), Eq(0)); - EXPECT_THAT(align_64.Floor(63), Eq(0)); - EXPECT_THAT(align_64.Floor(64), Eq(64)); - EXPECT_THAT(align_64.Floor(65), Eq(64)); - EXPECT_THAT(align_64.Floor(127), Eq(64)); - EXPECT_THAT(align_64.Floor(128), Eq(128)); -} - -TEST(ArenaAlign, Ceil) { - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.Ceil(0), Eq(0)); - EXPECT_THAT(align_64.Ceil(1), Eq(64)); - EXPECT_THAT(align_64.Ceil(63), Eq(64)); - EXPECT_THAT(align_64.Ceil(64), Eq(64)); - EXPECT_THAT(align_64.Ceil(65), Eq(128)); - EXPECT_THAT(align_64.Ceil(127), Eq(128)); - EXPECT_THAT(align_64.Ceil(128), Eq(128)); -} - -TEST(ArenaAlign, CeilPtr) { - alignas(64) char p[129] = {0}; - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.Ceil(p + 0), Eq(p)); - EXPECT_THAT(align_64.Ceil(p + 1), Eq(p + 64)); - EXPECT_THAT(align_64.Ceil(p + 63), Eq(p + 64)); - EXPECT_THAT(align_64.Ceil(p + 64), Eq(p + 64)); - EXPECT_THAT(align_64.Ceil(p + 65), Eq(p + 128)); - EXPECT_THAT(align_64.Ceil(p + 127), Eq(p + 128)); - EXPECT_THAT(align_64.Ceil(p + 128), Eq(p + 128)); -} - -TEST(ArenaAlign, CheckAligned) { - alignas(128) char p[129] = {0}; - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.CheckAligned(p + 0), Eq(p)); - EXPECT_THAT(align_64.CheckAligned(p + 64), Eq(p + 64)); - EXPECT_THAT(align_64.CheckAligned(p + 128), Eq(p + 128)); -#ifdef PROTOBUF_HAS_DEATH_TEST - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 1), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 7), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 8), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 56), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 63), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 65), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 72), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 120), ".*"); - EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 129), ".*"); -#endif // PROTOBUF_HAS_DEATH_TEST -} - -TEST(ArenaAlign, CeilDefaultAligned) { - alignas(128) char p[129] = {0}; - auto align_64 = ArenaAlignAs(64); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 0), Eq(p)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 8), Eq(p + 64)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 56), Eq(p + 64)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 64), Eq(p + 64)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 72), Eq(p + 128)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 120), Eq(p + 128)); - EXPECT_THAT(align_64.CeilDefaultAligned(p + 128), Eq(p + 128)); -#ifdef PROTOBUF_HAS_DEATH_TEST - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 1), ".*"); - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 7), ".*"); - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 63), ".*"); - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 65), ".*"); - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 127), ".*"); - EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 129), ".*"); -#endif // PROTOBUF_HAS_DEATH_TEST -} - -TEST(ArenaAlign, IsAligned) { - auto align_64 = ArenaAlignAs(64); - EXPECT_TRUE(align_64.IsAligned(0)); - EXPECT_FALSE(align_64.IsAligned(1)); - EXPECT_FALSE(align_64.IsAligned(63)); - EXPECT_TRUE(align_64.IsAligned(64)); - EXPECT_FALSE(align_64.IsAligned(65)); - EXPECT_FALSE(align_64.IsAligned(127)); - EXPECT_TRUE(align_64.IsAligned(128)); -} - -} // namespace -} // namespace internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/arena_allocation_policy.h b/libs/protobuf/src/google/protobuf/arena_allocation_policy.h deleted file mode 100644 index 2427cf4..0000000 --- a/libs/protobuf/src/google/protobuf/arena_allocation_policy.h +++ /dev/null @@ -1,126 +0,0 @@ -// 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_ARENA_ALLOCATION_POLICY_H__ -#define GOOGLE_PROTOBUF_ARENA_ALLOCATION_POLICY_H__ - -#include -#include - -#include "google/protobuf/arena_config.h" - -namespace google { -namespace protobuf { -namespace internal { - -// `AllocationPolicy` defines `Arena` allocation policies. Applications can -// customize the initial and maximum sizes for arena allocation, as well as set -// custom allocation and deallocation functions. `AllocationPolicy` is for -// protocol buffer internal use only, and typically created from a user facing -// public configuration class such as `ArenaOptions`. -struct AllocationPolicy { - static constexpr size_t kDefaultStartBlockSize = 256; - - size_t start_block_size = kDefaultStartBlockSize; - size_t max_block_size = GetDefaultArenaMaxBlockSize(); - - void* (*block_alloc)(size_t) = nullptr; - void (*block_dealloc)(void*, size_t) = nullptr; - - bool IsDefault() const { - return start_block_size == kDefaultStartBlockSize && - max_block_size == GetDefaultArenaMaxBlockSize() && - block_alloc == nullptr && block_dealloc == nullptr; - } -}; - -// Tagged pointer to an AllocationPolicy. -class TaggedAllocationPolicyPtr { - public: - constexpr TaggedAllocationPolicyPtr() : policy_(0) {} - - explicit TaggedAllocationPolicyPtr(AllocationPolicy* policy) - : policy_(reinterpret_cast(policy)) {} - - void set_policy(AllocationPolicy* policy) { - auto bits = policy_ & kTagsMask; - policy_ = reinterpret_cast(policy) | bits; - } - - AllocationPolicy* get() { - return reinterpret_cast(policy_ & kPtrMask); - } - const AllocationPolicy* get() const { - return reinterpret_cast(policy_ & kPtrMask); - } - - AllocationPolicy& operator*() { return *get(); } - const AllocationPolicy& operator*() const { return *get(); } - - AllocationPolicy* operator->() { return get(); } - const AllocationPolicy* operator->() const { return get(); } - - bool is_user_owned_initial_block() const { - return static_cast(get_mask()); - } - void set_is_user_owned_initial_block(bool v) { - set_mask(v); - } - - uintptr_t get_raw() const { return policy_; } - - private: - enum : uintptr_t { - kUserOwnedInitialBlock = 1, - }; - - static constexpr uintptr_t kTagsMask = 7; - static constexpr uintptr_t kPtrMask = ~kTagsMask; - - template - uintptr_t get_mask() const { - return policy_ & kMask; - } - template - void set_mask(bool v) { - if (v) { - policy_ |= kMask; - } else { - policy_ &= ~kMask; - } - } - uintptr_t policy_; -}; - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ARENA_ALLOCATION_POLICY_H__ diff --git a/libs/protobuf/src/google/protobuf/arena_cleanup.h b/libs/protobuf/src/google/protobuf/arena_cleanup.h deleted file mode 100644 index ee36d1c..0000000 --- a/libs/protobuf/src/google/protobuf/arena_cleanup.h +++ /dev/null @@ -1,189 +0,0 @@ -// 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_ARENA_CLEANUP_H__ -#define GOOGLE_PROTOBUF_ARENA_CLEANUP_H__ - -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/base/attributes.h" - - - -namespace google { -namespace protobuf { -namespace internal { -namespace cleanup { - -// Helper function invoking the destructor of `object` -template -void arena_destruct_object(void* object) { - reinterpret_cast(object)->~T(); -} - -// Tag defines the type of cleanup / cleanup object. This tag is stored in the -// lowest 2 bits of the `elem` value identifying the type of node. All node -// types must start with a `uintptr_t` that stores `Tag` in its low two bits. -enum class Tag : uintptr_t { - kDynamic = 0, // DynamicNode - kString = 1, // StringNode (std::string) -}; - -// DynamicNode contains the object (`elem`) that needs to be -// destroyed, and the function to destroy it (`destructor`) -// elem must be aligned at minimum on a 4 byte boundary. -struct DynamicNode { - uintptr_t elem; - void (*destructor)(void*); -}; - -// StringNode contains a `std::string` object (`elem`) that needs to be -// destroyed. The lowest 2 bits of `elem` contain the non-zero kString tag. -struct StringNode { - uintptr_t elem; -}; - - -// EnableSpecializedTags() return true if the alignment of tagged objects -// such as std::string allow us to poke tags in the 2 LSB bits. -inline constexpr bool EnableSpecializedTags() { - // For now we require 2 bits - return alignof(std::string) >= 8; -} - -// Adds a cleanup entry identified by `tag` at memory location `pos`. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE void CreateNode(Tag tag, void* pos, - const void* elem_raw, - void (*destructor)(void*)) { - auto elem = reinterpret_cast(elem_raw); - if (EnableSpecializedTags()) { - GOOGLE_DCHECK_EQ(elem & 3, 0ULL); // Must be aligned - switch (tag) { - case Tag::kString: { - StringNode n = {elem | static_cast(Tag::kString)}; - memcpy(pos, &n, sizeof(n)); - return; - } - default: - break; - } - } - DynamicNode n = {elem, destructor}; - memcpy(pos, &n, sizeof(n)); -} - -// Optimization: performs a prefetch on `elem_address`. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE void PrefetchNode( - const void* elem_address) { - (void)elem_address; -} - -// Destroys the node idenitfied by `tag` stored at memory location `pos`. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE void DestroyNode(Tag tag, const void* pos) { - if (EnableSpecializedTags()) { - switch (tag) { - case Tag::kString: { - StringNode n; - memcpy(&n, pos, sizeof(n)); - auto* s = reinterpret_cast(n.elem & ~0x7ULL); - // Some compilers don't like fully qualified explicit dtor calls, - // so use an alias to avoid having to type `::`. - using string_type = std::string; - s->~string_type(); - return; - } - default: - break; - } - } - DynamicNode n; - memcpy(&n, pos, sizeof(n)); - n.destructor(reinterpret_cast(n.elem)); -} - -// Returns the `tag` identifying the type of object for `destructor` or -// kDynamic if `destructor` does not identify a well know object type. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE Tag Type(void (*destructor)(void*)) { - if (EnableSpecializedTags()) { - if (destructor == &arena_destruct_object) { - return Tag::kString; - } - } - return Tag::kDynamic; -} - -// Returns the `tag` identifying the type of object stored at memory location -// `elem`, which represents the first uintptr_t value in the node. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE Tag Type(void* raw) { - if (!EnableSpecializedTags()) return Tag::kDynamic; - - uintptr_t elem; - memcpy(&elem, raw, sizeof(elem)); - switch (static_cast(elem & 0x7ULL)) { - case Tag::kDynamic: - return Tag::kDynamic; - case Tag::kString: - return Tag::kString; - default: - GOOGLE_LOG(FATAL) << "Corrupted cleanup tag: " << (elem & 0x7ULL); - return Tag::kDynamic; - } -} - -// Returns the required size in bytes off the node type identified by `tag`. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t Size(Tag tag) { - if (!EnableSpecializedTags()) return sizeof(DynamicNode); - - switch (tag) { - case Tag::kDynamic: - return sizeof(DynamicNode); - case Tag::kString: - return sizeof(StringNode); - default: - GOOGLE_LOG(FATAL) << "Corrupted cleanup tag: " << static_cast(tag); - return sizeof(DynamicNode); - } -} - -// Returns the required size in bytes off the node type for `destructor`. -inline ABSL_ATTRIBUTE_ALWAYS_INLINE size_t Size(void (*destructor)(void*)) { - return destructor == nullptr ? 0 : Size(Type(destructor)); -} - -} // namespace cleanup -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ARENA_CLEANUP_H__ diff --git a/libs/protobuf/src/google/protobuf/arena_impl.h b/libs/protobuf/src/google/protobuf/arena_impl.h index 9d2de93..7672768 100644 --- a/libs/protobuf/src/google/protobuf/arena_impl.h +++ b/libs/protobuf/src/google/protobuf/arena_impl.h @@ -35,23 +35,20 @@ #include #include -#include -#include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/numeric/bits.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/arena_allocation_policy.h" -#include "google/protobuf/arena_cleanup.h" -#include "google/protobuf/arena_config.h" -#include "google/protobuf/arenaz_sampler.h" -#include "google/protobuf/port.h" +#include +#include +#include +#ifdef ADDRESS_SANITIZER +#include +#endif // ADDRESS_SANITIZER + +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { @@ -65,56 +62,11 @@ enum { kCacheAlignment = 64 }; enum { kCacheAlignment = alignof(max_align_t) }; // do the best we can #endif -inline PROTOBUF_ALWAYS_INLINE constexpr size_t AlignUpTo8(size_t n) { +inline constexpr size_t AlignUpTo8(size_t n) { // Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.) return (n + 7) & static_cast(-8); } -inline PROTOBUF_ALWAYS_INLINE constexpr size_t AlignUpTo(size_t n, size_t a) { - // We are wasting space by over allocating align - 8 bytes. Compared to a - // dedicated function that takes current alignment in consideration. Such a - // scheme would only waste (align - 8)/2 bytes on average, but requires a - // dedicated function in the outline arena allocation functions. Possibly - // re-evaluate tradeoffs later. - return a <= 8 ? AlignUpTo8(n) : n + a - 8; -} - -inline PROTOBUF_ALWAYS_INLINE void* AlignTo(void* p, size_t a) { - if (a <= 8) { - return p; - } else { - auto u = reinterpret_cast(p); - return reinterpret_cast((u + a - 1) & (~a + 1)); - } -} - -// Arena blocks are variable length malloc-ed objects. The following structure -// describes the common header for all blocks. -struct ArenaBlock { - // For the sentry block with zero-size where ptr_, limit_, cleanup_nodes all - // point to "this". - constexpr ArenaBlock() - : next(nullptr), cleanup_nodes(this), size(0) {} - - ArenaBlock(ArenaBlock* next, size_t size) - : next(next), cleanup_nodes(nullptr), size(size) { - GOOGLE_DCHECK_GT(size, sizeof(ArenaBlock)); - } - - char* Pointer(size_t n) { - GOOGLE_DCHECK_LE(n, size); - return reinterpret_cast(this) + n; - } - char* Limit() { return Pointer(size & static_cast(-8)); } - - bool IsSentry() const { return size == 0; } - - ArenaBlock* const next; - void* cleanup_nodes; - const size_t size; - // data follows -}; - using LifecycleIdAtomic = uint64_t; // MetricsCollector collects stats for a particular arena. @@ -150,15 +102,94 @@ class PROTOBUF_EXPORT ArenaMetricsCollector { const bool record_allocs_; }; -enum class AllocationClient { kDefault, kArray }; +struct AllocationPolicy { + static constexpr size_t kDefaultStartBlockSize = 256; + static constexpr size_t kDefaultMaxBlockSize = 8192; -class ThreadSafeArena; + size_t start_block_size = kDefaultStartBlockSize; + size_t max_block_size = kDefaultMaxBlockSize; + void* (*block_alloc)(size_t) = nullptr; + void (*block_dealloc)(void*, size_t) = nullptr; + ArenaMetricsCollector* metrics_collector = nullptr; -// Tag type used to invoke the constructor of the first SerialArena. -struct FirstSerialArena { - explicit FirstSerialArena() = default; + bool IsDefault() const { + return start_block_size == kDefaultMaxBlockSize && + max_block_size == kDefaultMaxBlockSize && block_alloc == nullptr && + block_dealloc == nullptr && metrics_collector == nullptr; + } }; +// Tagged pointer to an AllocationPolicy. +class TaggedAllocationPolicyPtr { + public: + constexpr TaggedAllocationPolicyPtr() : policy_(0) {} + + explicit TaggedAllocationPolicyPtr(AllocationPolicy* policy) + : policy_(reinterpret_cast(policy)) {} + + void set_policy(AllocationPolicy* policy) { + auto bits = policy_ & kTagsMask; + policy_ = reinterpret_cast(policy) | bits; + } + + AllocationPolicy* get() { + return reinterpret_cast(policy_ & kPtrMask); + } + const AllocationPolicy* get() const { + return reinterpret_cast(policy_ & kPtrMask); + } + + AllocationPolicy& operator*() { return *get(); } + const AllocationPolicy& operator*() const { return *get(); } + + AllocationPolicy* operator->() { return get(); } + const AllocationPolicy* operator->() const { return get(); } + + bool is_user_owned_initial_block() const { + return static_cast(get_mask()); + } + void set_is_user_owned_initial_block(bool v) { + set_mask(v); + } + + bool should_record_allocs() const { + return static_cast(get_mask()); + } + void set_should_record_allocs(bool v) { set_mask(v); } + + uintptr_t get_raw() const { return policy_; } + + inline void RecordAlloc(const std::type_info* allocated_type, + size_t n) const { + get()->metrics_collector->OnAlloc(allocated_type, n); + } + + private: + enum : uintptr_t { + kUserOwnedInitialBlock = 1, + kRecordAllocs = 2, + }; + + static constexpr uintptr_t kTagsMask = 7; + static constexpr uintptr_t kPtrMask = ~kTagsMask; + + template + uintptr_t get_mask() const { + return policy_ & kMask; + } + template + void set_mask(bool v) { + if (v) { + policy_ |= kMask; + } else { + policy_ &= ~kMask; + } + } + uintptr_t policy_; +}; + +enum class AllocationClient { kDefault, kArray }; + // A simple arena allocator. Calls to allocate functions must be properly // serialized by the caller, hence this class cannot be used as a general // purpose allocator in a multi-threaded program. It serves as a building block @@ -167,7 +198,7 @@ struct FirstSerialArena { // This class manages // 1) Arena bump allocation + owning memory blocks. // 2) Maintaining a cleanup list. -// It delegates the actual memory allocation back to ThreadSafeArena, which +// It delagetes the actual memory allocation back to ThreadSafeArena, which // contains the information on block growth policy and backing memory allocation // used. class PROTOBUF_EXPORT SerialArena { @@ -177,6 +208,13 @@ class PROTOBUF_EXPORT SerialArena { size_t size; }; + // 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. + }; + void CleanupList(); uint64_t SpaceAllocated() const { return space_allocated_.load(std::memory_order_relaxed); @@ -184,7 +222,7 @@ class PROTOBUF_EXPORT SerialArena { uint64_t SpaceUsed() const; bool HasSpace(size_t n) const { - return n <= static_cast(limit_ - ptr()); + return n <= static_cast(limit_ - ptr_); } // See comments on `cached_blocks_` member for details. @@ -192,14 +230,16 @@ class PROTOBUF_EXPORT SerialArena { if (PROTOBUF_PREDICT_FALSE(size < 16)) return nullptr; // We round up to the next larger block in case the memory doesn't match // the pattern we are looking for. - const size_t index = absl::bit_width(size - 1) - 4; + const size_t index = Bits::Log2FloorNonZero64(size - 1) - 3; if (index >= cached_block_length_) return nullptr; auto& cached_head = cached_blocks_[index]; if (cached_head == nullptr) return nullptr; void* ret = cached_head; - PROTOBUF_UNPOISON_MEMORY_REGION(ret, size); +#ifdef ADDRESS_SANITIZER + ASAN_UNPOISON_MEMORY_REGION(ret, size); +#endif // ADDRESS_SANITIZER cached_head = cached_head->next; return ret; } @@ -212,9 +252,9 @@ class PROTOBUF_EXPORT SerialArena { // the right size. We can statically know if the allocation size can benefit // from it. template - void* AllocateAligned(size_t n) { + void* AllocateAligned(size_t n, const AllocationPolicy* policy) { GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. - GOOGLE_DCHECK_GE(limit_, ptr()); + GOOGLE_DCHECK_GE(limit_, ptr_); if (alloc_client == AllocationClient::kArray) { if (void* res = TryAllocateFromCachedBlock(n)) { @@ -223,16 +263,18 @@ class PROTOBUF_EXPORT SerialArena { } if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) { - return AllocateAlignedFallback(n); + return AllocateAlignedFallback(n, policy); } return AllocateFromExisting(n); } private: void* AllocateFromExisting(size_t n) { - PROTOBUF_UNPOISON_MEMORY_REGION(ptr(), n); - void* ret = ptr(); - set_ptr(static_cast(ret) + n); + void* ret = ptr_; + ptr_ += n; +#ifdef ADDRESS_SANITIZER + ASAN_UNPOISON_MEMORY_REGION(ret, n); +#endif // ADDRESS_SANITIZER return ret; } @@ -244,13 +286,13 @@ class PROTOBUF_EXPORT SerialArena { if (sizeof(void*) < 8) { if (PROTOBUF_PREDICT_FALSE(size < 16)) return; } else { - PROTOBUF_ASSUME(size >= 16); + GOOGLE_DCHECK(size >= 16); } // We round down to the next smaller block in case the memory doesn't match // the pattern we are looking for. eg, someone might have called Reserve() // on the repeated field. - const size_t index = absl::bit_width(size) - 5; + const size_t index = Bits::Log2FloorNonZero64(size) - 4; if (PROTOBUF_PREDICT_FALSE(index >= cached_block_length_)) { // We can't put this object on the freelist so make this object the @@ -261,15 +303,7 @@ class PROTOBUF_EXPORT SerialArena { std::copy(cached_blocks_, cached_blocks_ + cached_block_length_, new_list); - - // We need to unpoison this memory before filling it in case it has been - // poisoned by another santizer client. - PROTOBUF_UNPOISON_MEMORY_REGION( - new_list + cached_block_length_, - (new_size - cached_block_length_) * sizeof(CachedBlock*)); - std::fill(new_list + cached_block_length_, new_list + new_size, nullptr); - cached_blocks_ = new_list; // Make the size fit in uint8_t. This is the power of two, so we don't // need anything larger. @@ -283,108 +317,98 @@ class PROTOBUF_EXPORT SerialArena { auto* new_node = static_cast(p); new_node->next = cached_head; cached_head = new_node; - PROTOBUF_POISON_MEMORY_REGION(p, size); +#ifdef ADDRESS_SANITIZER + ASAN_POISON_MEMORY_REGION(p, size); +#endif // ADDRESS_SANITIZER } public: // Allocate space if the current region provides enough space. bool MaybeAllocateAligned(size_t n, void** out) { GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. - GOOGLE_DCHECK_GE(limit_, ptr()); + GOOGLE_DCHECK_GE(limit_, ptr_); if (PROTOBUF_PREDICT_FALSE(!HasSpace(n))) return false; *out = AllocateFromExisting(n); return true; } - // If there is enough space in the current block, allocate space for one `T` - // object and register for destruction. The object has not been constructed - // and the memory returned is uninitialized. - template - PROTOBUF_ALWAYS_INLINE void* MaybeAllocateWithCleanup() { - GOOGLE_DCHECK_GE(limit_, ptr()); - static_assert(!std::is_trivially_destructible::value, - "This function is only for non-trivial types."); - - constexpr int aligned_size = AlignUpTo8(sizeof(T)); - constexpr auto destructor = cleanup::arena_destruct_object; - size_t required = aligned_size + cleanup::Size(destructor); - if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return nullptr; + std::pair AllocateAlignedWithCleanup( + size_t n, const AllocationPolicy* policy) { + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. + if (PROTOBUF_PREDICT_FALSE(!HasSpace(n + kCleanupSize))) { + return AllocateAlignedWithCleanupFallback(n, policy); } - void* ptr = AllocateFromExistingWithCleanupFallback(aligned_size, - alignof(T), destructor); - PROTOBUF_ASSUME(ptr != nullptr); - return ptr; - } - - PROTOBUF_ALWAYS_INLINE - void* AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*)) { - size_t required = AlignUpTo(n, align) + cleanup::Size(destructor); - if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return AllocateAlignedWithCleanupFallback(n, align, destructor); - } - return AllocateFromExistingWithCleanupFallback(n, align, destructor); - } - - PROTOBUF_ALWAYS_INLINE - void AddCleanup(void* elem, void (*destructor)(void*)) { - size_t required = cleanup::Size(destructor); - if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return AddCleanupFallback(elem, destructor); - } - AddCleanupFromExisting(elem, destructor); + return AllocateFromExistingWithCleanupFallback(n); } private: - void* AllocateFromExistingWithCleanupFallback(size_t n, size_t align, - void (*destructor)(void*)) { - n = AlignUpTo(n, align); - PROTOBUF_UNPOISON_MEMORY_REGION(ptr(), n); - void* ret = internal::AlignTo(ptr(), align); - set_ptr(ptr() + n); - GOOGLE_DCHECK_GE(limit_, ptr()); - AddCleanupFromExisting(ret, destructor); - return ret; + std::pair AllocateFromExistingWithCleanupFallback( + size_t n) { + void* ret = ptr_; + ptr_ += n; + limit_ -= kCleanupSize; +#ifdef ADDRESS_SANITIZER + ASAN_UNPOISON_MEMORY_REGION(ret, n); + ASAN_UNPOISON_MEMORY_REGION(limit_, kCleanupSize); +#endif // ADDRESS_SANITIZER + return CreatePair(ret, reinterpret_cast(limit_)); } - PROTOBUF_ALWAYS_INLINE - void AddCleanupFromExisting(void* elem, void (*destructor)(void*)) { - cleanup::Tag tag = cleanup::Type(destructor); - size_t n = cleanup::Size(tag); - - PROTOBUF_UNPOISON_MEMORY_REGION(limit_ - n, n); - limit_ -= n; - GOOGLE_DCHECK_GE(limit_, ptr()); - cleanup::CreateNode(tag, limit_, elem, destructor); + public: + void AddCleanup(void* elem, void (*cleanup)(void*), + const AllocationPolicy* policy) { + auto res = AllocateAlignedWithCleanup(0, policy); + res.second->elem = elem; + res.second->cleanup = cleanup; } + void* owner() const { return owner_; } + SerialArena* next() const { return next_; } + void set_next(SerialArena* next) { next_ = next; } + private: friend class ThreadSafeArena; + friend class ArenaBenchmark; // Creates a new SerialArena inside mem using the remaining memory as for // future allocations. - // The `parent` arena must outlive the serial arena, which is guaranteed - // because the parent manages the lifetime of the serial arenas. - static SerialArena* New(SerialArena::Memory mem, ThreadSafeArena& parent); + static SerialArena* New(SerialArena::Memory mem, void* owner, + ThreadSafeArenaStats* stats); // Free SerialArena returning the memory passed in to New template Memory Free(Deallocator deallocator); - // Members are declared here to track sizeof(SerialArena) and hotness - // centrally. They are (roughly) laid out in descending order of hotness. + // Blocks are variable length malloc-ed objects. The following structure + // describes the common header for all blocks. + struct Block { + Block(Block* next, size_t size) : next(next), size(size), start(nullptr) {} + + char* Pointer(size_t n) { + GOOGLE_DCHECK(n <= size); + return reinterpret_cast(this) + n; + } + + Block* const next; + const size_t size; + CleanupNode* start; + // data follows + }; + + void* owner_; // &ThreadCache of this thread; + Block* head_; // Head of linked list of blocks. + SerialArena* next_; // Next SerialArena in this linked list. + size_t space_used_ = 0; // Necessary for metrics. + std::atomic space_allocated_; // Next pointer to allocate from. Always 8-byte aligned. Points inside // head_ (and head_->pos will always be non-canonical). We keep these // here to reduce indirection. - std::atomic ptr_{nullptr}; + char* ptr_; // Limiting address up to which memory can be allocated from the head block. - char* limit_ = nullptr; - - std::atomic head_{nullptr}; // Head of linked list of blocks. - std::atomic space_used_{0}; // Necessary for metrics. - std::atomic space_allocated_{0}; - ThreadSafeArena& parent_; + char* limit_; + // For holding sampling information. The pointer is owned by the + // ThreadSafeArena that holds this serial arena. + ThreadSafeArenaStats* arena_stats_; // Repeated*Field and Arena play together to reduce memory consumption by // reusing blocks. Currently, natural growth of the repeated field types makes @@ -400,32 +424,20 @@ class PROTOBUF_EXPORT SerialArena { uint8_t cached_block_length_ = 0; CachedBlock** cached_blocks_ = nullptr; - // Helper getters/setters to handle relaxed operations on atomic variables. - ArenaBlock* head() { return head_.load(std::memory_order_relaxed); } - const ArenaBlock* head() const { - return head_.load(std::memory_order_relaxed); + // Constructor is private as only New() should be used. + inline SerialArena(Block* b, void* owner, ThreadSafeArenaStats* stats); + void* AllocateAlignedFallback(size_t n, const AllocationPolicy* policy); + std::pair AllocateAlignedWithCleanupFallback( + size_t n, const AllocationPolicy* policy); + void AllocateNewBlock(size_t n, const AllocationPolicy* policy); + + std::pair CreatePair(void* ptr, CleanupNode* node) { + return {ptr, node}; } - char* ptr() { return ptr_.load(std::memory_order_relaxed); } - const char* ptr() const { return ptr_.load(std::memory_order_relaxed); } - void set_ptr(char* ptr) { return ptr_.store(ptr, std::memory_order_relaxed); } - - // Constructor is private as only New() should be used. - inline SerialArena(ArenaBlock* b, ThreadSafeArena& parent); - - // Constructors to handle the first SerialArena. - inline explicit SerialArena(ThreadSafeArena& parent); - inline SerialArena(FirstSerialArena, ArenaBlock* b, ThreadSafeArena& parent); - - void* AllocateAlignedFallback(size_t n); - void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, - void (*destructor)(void*)); - void AddCleanupFallback(void* elem, void (*destructor)(void*)); - inline void AllocateNewBlock(size_t n); - inline void Init(ArenaBlock* b, size_t offset); - public: - static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(ArenaBlock)); + static constexpr size_t kBlockHeaderSize = AlignUpTo8(sizeof(Block)); + static constexpr size_t kCleanupSize = AlignUpTo8(sizeof(CleanupNode)); }; // Tag type used to invoke the constructor of message-owned arena. @@ -443,22 +455,19 @@ struct MessageOwned { // use #ifdef the select the best implementation based on hardware / OS. class PROTOBUF_EXPORT ThreadSafeArena { public: - ThreadSafeArena(); + ThreadSafeArena() { Init(); } // Constructor solely used by message-owned arena. - explicit ThreadSafeArena(internal::MessageOwned); + ThreadSafeArena(internal::MessageOwned) : tag_and_id_(kMessageOwnedArena) { + Init(); + } - ThreadSafeArena(char* mem, size_t size); + ThreadSafeArena(char* mem, size_t size) { InitializeFrom(mem, size); } explicit ThreadSafeArena(void* mem, size_t size, - const AllocationPolicy& policy); - - // All protos have pointers back to the arena hence Arena must have - // pointer stability. - ThreadSafeArena(const ThreadSafeArena&) = delete; - ThreadSafeArena& operator=(const ThreadSafeArena&) = delete; - ThreadSafeArena(ThreadSafeArena&&) = delete; - ThreadSafeArena& operator=(ThreadSafeArena&&) = delete; + const AllocationPolicy& policy) { + InitializeWithPolicy(mem, size, policy); + } // Destructor deletes all owned heap allocated objects, and destructs objects // that have non-trivial destructors, except for proto2 message objects whose @@ -472,12 +481,13 @@ class PROTOBUF_EXPORT ThreadSafeArena { uint64_t SpaceUsed() const; template - void* AllocateAligned(size_t n) { + void* AllocateAligned(size_t n, const std::type_info* type) { SerialArena* arena; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { - return arena->AllocateAligned(n); + if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && + GetSerialArenaFast(&arena))) { + return arena->AllocateAligned(n, AllocPolicy()); } else { - return AllocateAlignedFallback(n); + return AllocateAlignedFallback(n, type); } } @@ -495,14 +505,15 @@ class PROTOBUF_EXPORT ThreadSafeArena { // code for the happy path. PROTOBUF_NDEBUG_INLINE bool MaybeAllocateAligned(size_t n, void** out) { SerialArena* arena; - if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { + if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && + GetSerialArenaFromThreadCache(&arena))) { return arena->MaybeAllocateAligned(n, out); } return false; } - void* AllocateAlignedWithCleanup(size_t n, size_t align, - void (*destructor)(void*)); + std::pair AllocateAlignedWithCleanup( + size_t n, const std::type_info* type); // Add object pointer and cleanup function pointer to the list. void AddCleanup(void* elem, void (*cleanup)(void*)); @@ -513,73 +524,62 @@ class PROTOBUF_EXPORT ThreadSafeArena { } private: - friend class ArenaBenchmark; - friend class TcParser; - friend class SerialArena; - friend struct SerialArenaChunkHeader; - static uint64_t GetNextLifeCycleId(); - - class SerialArenaChunk; - - // Returns a new SerialArenaChunk that has {id, serial} at slot 0. It may - // grow based on "prev_num_slots". - static SerialArenaChunk* NewSerialArenaChunk(uint32_t prev_capacity, void* id, - SerialArena* serial); - static SerialArenaChunk* SentrySerialArenaChunk(); - - // Returns the first ArenaBlock* for the first SerialArena. If users provide - // one, use it if it's acceptable. Otherwise returns a sentry block. - ArenaBlock* FirstBlock(void* buf, size_t size); - // Same as the above but returns a valid block if "policy" is not default. - ArenaBlock* FirstBlock(void* buf, size_t size, - const AllocationPolicy& policy); - - // Adds SerialArena to the chunked list. May create a new chunk. - void AddSerialArena(void* id, SerialArena* serial); - - // Members are declared here to track sizeof(ThreadSafeArena) and hotness - // centrally. - // Unique for each arena. Changes on Reset(). uint64_t tag_and_id_ = 0; - - TaggedAllocationPolicyPtr alloc_policy_; // Tagged pointer to AllocPolicy. - ThreadSafeArenaStatsHandle arena_stats_; - - // Adding a new chunk to head_ must be protected by mutex_. - absl::Mutex mutex_; - // Pointer to a linked list of SerialArenaChunk. - std::atomic head_{nullptr}; - - void* first_owner_; - // Must be declared after alloc_policy_; otherwise, it may lose info on - // user-provided initial block. - SerialArena first_arena_; - // The LSB of tag_and_id_ indicates if the arena is message-owned. enum : uint64_t { kMessageOwnedArena = 1 }; + TaggedAllocationPolicyPtr alloc_policy_; // Tagged pointer to AllocPolicy. + static_assert(std::is_trivially_destructible{}, "SerialArena needs to be trivially destructible."); + // Pointer to a linked list of SerialArena. + std::atomic threads_; + std::atomic hint_; // Fast thread-local block access const AllocationPolicy* AllocPolicy() const { return alloc_policy_.get(); } - void InitializeWithPolicy(const AllocationPolicy& policy); - void* AllocateAlignedWithCleanupFallback(size_t n, size_t align, - void (*destructor)(void*)); + void InitializeFrom(void* mem, size_t size); + void InitializeWithPolicy(void* mem, size_t size, AllocationPolicy policy); + void* AllocateAlignedFallback(size_t n, const std::type_info* type); + std::pair + AllocateAlignedWithCleanupFallback(size_t n, const std::type_info* type); void Init(); + void SetInitialBlock(void* mem, size_t size); // Delete or Destruct all objects owned by the arena. void CleanupList(); + inline uint64_t LifeCycleId() const { + return tag_and_id_ & ~kMessageOwnedArena; + } + inline void CacheSerialArena(SerialArena* serial) { - if (!IsMessageOwned()) { - thread_cache().last_serial_arena = serial; - thread_cache().last_lifecycle_id_seen = tag_and_id_; - } + thread_cache().last_serial_arena = serial; + thread_cache().last_lifecycle_id_seen = tag_and_id_; + // TODO(haberman): evaluate whether we would gain efficiency by getting rid + // of hint_. It's the only write we do to ThreadSafeArena in the allocation + // path, which will dirty the cache line. + + hint_.store(serial, std::memory_order_release); } PROTOBUF_NDEBUG_INLINE bool GetSerialArenaFast(SerialArena** arena) { + if (GetSerialArenaFromThreadCache(arena)) return true; + + // Check whether we own the last accessed SerialArena on this arena. This + // fast path optimizes the case where a single thread uses multiple arenas. + ThreadCache* tc = &thread_cache(); + SerialArena* serial = hint_.load(std::memory_order_acquire); + if (PROTOBUF_PREDICT_TRUE(serial != nullptr && serial->owner() == tc)) { + *arena = serial; + return true; + } + return false; + } + + PROTOBUF_NDEBUG_INLINE bool GetSerialArenaFromThreadCache( + SerialArena** arena) { // 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. @@ -590,27 +590,16 @@ class PROTOBUF_EXPORT ThreadSafeArena { } return false; } + SerialArena* GetSerialArenaFallback(void* me); - // Finds SerialArena or creates one if not found. When creating a new one, - // create a big enough block to accommodate n bytes. - SerialArena* GetSerialArenaFallback(size_t n); - - template - void* AllocateAlignedFallback(size_t n); - - // Executes callback function over SerialArenaChunk. Passes const - // SerialArenaChunk*. template - void WalkConstSerialArenaChunk(Functor fn) const; + void PerSerialArena(Functor fn) { + // By omitting an Acquire barrier we ensure that any user code that doesn't + // properly synchronize Reset() or the destructor will throw a TSAN warning. + SerialArena* serial = threads_.load(std::memory_order_relaxed); - // Executes callback function over SerialArenaChunk. - template - void WalkSerialArenaChunk(Functor fn); - - // Executes callback function over SerialArena in chunked list in reverse - // chronological order. Passes const SerialArena*. - template - void PerConstSerialArenaInChunk(Functor fn) const; + for (; serial; serial = serial->next()) fn(serial); + } // Releases all memory except the first block which it returns. The first // block might be owned by the user and thus need some extra checks before @@ -652,8 +641,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { #pragma warning(disable : 4324) #endif struct alignas(kCacheAlignment) CacheAlignedLifecycleIdGenerator { - constexpr CacheAlignedLifecycleIdGenerator() : id{0} {} - std::atomic id; }; static CacheAlignedLifecycleIdGenerator lifecycle_id_generator_; @@ -670,15 +657,20 @@ class PROTOBUF_EXPORT ThreadSafeArena { static ThreadCache& thread_cache() { return thread_cache_; } #endif + ThreadSafeArenaStatsHandle arena_stats_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ThreadSafeArena); + // All protos have pointers back to the arena hence Arena must have + // pointer stability. + ThreadSafeArena(ThreadSafeArena&&) = delete; + ThreadSafeArena& operator=(ThreadSafeArena&&) = delete; + public: - // kBlockHeaderSize is sizeof(ArenaBlock), aligned up to the nearest multiple - // of 8 to protect the invariant that pos is always at a multiple of 8. + // kBlockHeaderSize 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 constexpr size_t kBlockHeaderSize = SerialArena::kBlockHeaderSize; static constexpr size_t kSerialArenaSize = (sizeof(SerialArena) + 7) & static_cast(-8); - static constexpr size_t kAllocPolicySize = - AlignUpTo8(sizeof(AllocationPolicy)); - static constexpr size_t kMaxCleanupNodeSize = 16; static_assert(kBlockHeaderSize % 8 == 0, "kBlockHeaderSize must be a multiple of 8."); static_assert(kSerialArenaSize % 8 == 0, @@ -689,6 +681,6 @@ class PROTOBUF_EXPORT ThreadSafeArena { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__ diff --git a/libs/protobuf/src/google/protobuf/arena_test_util.cc b/libs/protobuf/src/google/protobuf/arena_test_util.cc index 50f20a1..2cb5075 100644 --- a/libs/protobuf/src/google/protobuf/arena_test_util.cc +++ b/libs/protobuf/src/google/protobuf/arena_test_util.cc @@ -28,10 +28,10 @@ // (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/arena_test_util.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include #define EXPECT_EQ GOOGLE_CHECK_EQ diff --git a/libs/protobuf/src/google/protobuf/arena_test_util.h b/libs/protobuf/src/google/protobuf/arena_test_util.h index 0c00e76..6e42d4b 100644 --- a/libs/protobuf/src/google/protobuf/arena_test_util.h +++ b/libs/protobuf/src/google/protobuf/arena_test_util.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__ -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/arena_unittest.cc b/libs/protobuf/src/google/protobuf/arena_unittest.cc index 8d76d7f..7539b4b 100644 --- a/libs/protobuf/src/google/protobuf/arena_unittest.cc +++ b/libs/protobuf/src/google/protobuf/arena_unittest.cc @@ -28,7 +28,7 @@ // (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/arena.h" +#include #include #include @@ -39,30 +39,28 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_arena.pb.h" +#include +#include +#include +#include #include #include -#include "absl/strings/string_view.h" -#include "absl/synchronization/barrier.h" -#include "google/protobuf/arena_test_util.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/message.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "absl/synchronization/mutex.h" // Must be included last -#include "google/protobuf/port_def.inc" +#include using proto2_arena_unittest::ArenaMessage; using protobuf_unittest::ForeignMessage; @@ -86,10 +84,10 @@ class Notifier { class SimpleDataType { public: - SimpleDataType() : notifier_(nullptr) {} + SimpleDataType() : notifier_(NULL) {} void SetNotifier(Notifier* notifier) { notifier_ = notifier; } virtual ~SimpleDataType() { - if (notifier_ != nullptr) { + if (notifier_ != NULL) { notifier_->Notify(); } }; @@ -103,13 +101,12 @@ class SimpleDataType { class PleaseDontCopyMe { public: explicit PleaseDontCopyMe(int value) : value_(value) {} - PleaseDontCopyMe(const PleaseDontCopyMe&) = delete; - PleaseDontCopyMe& operator=(const PleaseDontCopyMe&) = delete; int value() const { return value_; } private: int value_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PleaseDontCopyMe); }; // A class that takes four different types as constructor arguments. @@ -119,15 +116,14 @@ class MustBeConstructedWithOneThroughFour { const std::string& three, const PleaseDontCopyMe* four) : one_(one), two_(two), three_(three), four_(four) {} - MustBeConstructedWithOneThroughFour( - const MustBeConstructedWithOneThroughFour&) = delete; - MustBeConstructedWithOneThroughFour& operator=( - const MustBeConstructedWithOneThroughFour&) = delete; int one_; const char* const two_; std::string three_; const PleaseDontCopyMe* four_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughFour); }; // A class that takes eight different types as constructor arguments. @@ -147,10 +143,6 @@ class MustBeConstructedWithOneThroughEight { six_(six), seven_(seven), eight_(eight) {} - MustBeConstructedWithOneThroughEight( - const MustBeConstructedWithOneThroughEight&) = delete; - MustBeConstructedWithOneThroughEight& operator=( - const MustBeConstructedWithOneThroughEight&) = delete; int one_; const char* const two_; @@ -160,6 +152,9 @@ class MustBeConstructedWithOneThroughEight { const char* const six_; std::string seven_; std::string eight_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MustBeConstructedWithOneThroughEight); }; TEST(ArenaTest, ArenaConstructable) { @@ -176,17 +171,17 @@ TEST(ArenaTest, DestructorSkippable) { TEST(ArenaTest, BasicCreate) { Arena arena; - EXPECT_TRUE(Arena::Create(&arena) != nullptr); - EXPECT_TRUE(Arena::Create(&arena) != nullptr); - EXPECT_TRUE(Arena::Create(&arena) != nullptr); - EXPECT_TRUE(Arena::Create(&arena) != nullptr); - EXPECT_TRUE(Arena::Create(&arena) != nullptr); + EXPECT_TRUE(Arena::Create(&arena) != NULL); + EXPECT_TRUE(Arena::Create(&arena) != NULL); + EXPECT_TRUE(Arena::Create(&arena) != NULL); + EXPECT_TRUE(Arena::Create(&arena) != NULL); + EXPECT_TRUE(Arena::Create(&arena) != NULL); arena.Own(new int32_t); arena.Own(new int64_t); arena.Own(new float); arena.Own(new double); arena.Own(new std::string); - arena.Own(nullptr); + arena.Own(NULL); Notifier notifier; SimpleDataType* data = Arena::Create(&arena); data->SetNotifier(¬ifier); @@ -201,7 +196,7 @@ TEST(ArenaTest, CreateAndConstCopy) { Arena arena; const std::string s("foo"); const std::string* s_copy = Arena::Create(&arena, s); - EXPECT_TRUE(s_copy != nullptr); + EXPECT_TRUE(s_copy != NULL); EXPECT_EQ("foo", s); EXPECT_EQ("foo", *s_copy); } @@ -210,7 +205,7 @@ TEST(ArenaTest, CreateAndNonConstCopy) { Arena arena; std::string s("foo"); const std::string* s_copy = Arena::Create(&arena, s); - EXPECT_TRUE(s_copy != nullptr); + EXPECT_TRUE(s_copy != NULL); EXPECT_EQ("foo", s); EXPECT_EQ("foo", *s_copy); } @@ -219,7 +214,7 @@ TEST(ArenaTest, CreateAndMove) { Arena arena; std::string s("foo"); const std::string* s_move = Arena::Create(&arena, std::move(s)); - EXPECT_TRUE(s_move != nullptr); + EXPECT_TRUE(s_move != NULL); EXPECT_TRUE(s.empty()); // NOLINT EXPECT_EQ("foo", *s_move); } @@ -231,7 +226,7 @@ TEST(ArenaTest, CreateWithFourConstructorArguments) { const MustBeConstructedWithOneThroughFour* new_object = Arena::Create(&arena, 1, "2", three, &four); - EXPECT_TRUE(new_object != nullptr); + EXPECT_TRUE(new_object != NULL); ASSERT_EQ(1, new_object->one_); ASSERT_STREQ("2", new_object->two_); ASSERT_EQ("3", new_object->three_); @@ -247,7 +242,7 @@ TEST(ArenaTest, CreateWithEightConstructorArguments) { const MustBeConstructedWithOneThroughEight* new_object = Arena::Create( &arena, 1, "2", three, &four, 5, "6", seven, eight); - EXPECT_TRUE(new_object != nullptr); + EXPECT_TRUE(new_object != NULL); ASSERT_EQ(1, new_object->one_); ASSERT_STREQ("2", new_object->two_); ASSERT_EQ("3", new_object->three_); @@ -282,8 +277,7 @@ TEST(ArenaTest, CreateWithMoveArguments) { TEST(ArenaTest, InitialBlockTooSmall) { // Construct a small blocks of memory to be used by the arena allocator; then, // allocate an object which will not fit in the initial block. - for (uint32_t size = 0; size <= internal::SerialArena::kBlockHeaderSize + 32; - size++) { + for (int size = 0; size <= Arena::kBlockOverhead + 32; size++) { std::vector arena_block(size); ArenaOptions options; options.initial_block = arena_block.data(); @@ -313,26 +307,6 @@ TEST(ArenaTest, InitialBlockTooSmall) { } } -TEST(ArenaTest, CreateDestroy) { - TestAllTypes original; - TestUtil::SetAllFields(&original); - - // Test memory leak. - Arena arena; - TestAllTypes* heap_message = Arena::CreateMessage(nullptr); - TestAllTypes* arena_message = Arena::CreateMessage(&arena); - - *heap_message = original; - *arena_message = original; - - Arena::Destroy(heap_message); - Arena::Destroy(arena_message); - - // The arena message should still exist. - EXPECT_EQ(strlen(original.optional_string().c_str()), - strlen(arena_message->optional_string().c_str())); -} - TEST(ArenaTest, Parsing) { TestAllTypes original; TestUtil::SetAllFields(&original); @@ -510,7 +484,7 @@ TEST(ArenaTest, ReleaseMessage) { TestAllTypes::NestedMessage* released_null = arena_message->release_optional_nested_message(); - EXPECT_EQ(nullptr, released_null); + EXPECT_EQ(NULL, released_null); } TEST(ArenaTest, SetAllocatedString) { @@ -611,8 +585,8 @@ TEST(ArenaTest, SwapBetweenArenaAndNonArenaUsingReflection) { } TEST(ArenaTest, ReleaseFromArenaMessageMakesCopy) { - TestAllTypes::NestedMessage* nested_msg = nullptr; - std::string* nested_string = nullptr; + TestAllTypes::NestedMessage* nested_msg = NULL; + std::string* nested_string = NULL; { Arena arena; TestAllTypes* arena_message = Arena::CreateMessage(&arena); @@ -629,7 +603,7 @@ TEST(ArenaTest, ReleaseFromArenaMessageMakesCopy) { #if PROTOBUF_RTTI TEST(ArenaTest, ReleaseFromArenaMessageUsingReflectionMakesCopy) { - TestAllTypes::NestedMessage* nested_msg = nullptr; + TestAllTypes::NestedMessage* nested_msg = NULL; // Note: no string: reflection API only supports releasing submessages. { Arena arena; @@ -797,7 +771,7 @@ TEST(ArenaTest, AddAllocatedWithReflection) { } TEST(ArenaTest, RepeatedPtrFieldAddClearedTest) { -#ifndef PROTOBUF_FUTURE_REMOVE_CLEARED_API +#ifndef PROTOBUF_FUTURE_BREAKING_CHANGES { RepeatedPtrField repeated_field; EXPECT_TRUE(repeated_field.empty()); @@ -808,7 +782,7 @@ TEST(ArenaTest, RepeatedPtrFieldAddClearedTest) { EXPECT_TRUE(repeated_field.empty()); EXPECT_EQ(0, repeated_field.size()); } -#endif // !PROTOBUF_FUTURE_REMOVE_CLEARED_API +#endif // !PROTOBUF_FUTURE_BREAKING_CHANGES { RepeatedPtrField repeated_field; EXPECT_TRUE(repeated_field.empty()); @@ -1104,7 +1078,7 @@ TEST(ArenaTest, ArenaOneofReflection) { EXPECT_TRUE(refl->HasOneof(*message, oneof)); submsg = refl->ReleaseMessage(message, msg_field); EXPECT_FALSE(refl->HasOneof(*message, oneof)); - EXPECT_TRUE(submsg->GetArena() == nullptr); + EXPECT_TRUE(submsg->GetArena() == NULL); delete submsg; } @@ -1117,7 +1091,7 @@ void TestSwapRepeatedField(Arena* arena1, Arena* arena2) { TestAllTypes* t = Arena::CreateMessage(arena1); t->set_optional_string("field1"); t->set_optional_int32(i); - if (arena1 != nullptr) { + if (arena1 != NULL) { field1.UnsafeArenaAddAllocated(t); } else { field1.AddAllocated(t); @@ -1127,7 +1101,7 @@ void TestSwapRepeatedField(Arena* arena1, Arena* arena2) { TestAllTypes* t = Arena::CreateMessage(arena2); t->set_optional_string("field2"); t->set_optional_int32(i); - if (arena2 != nullptr) { + if (arena2 != NULL) { field2.UnsafeArenaAddAllocated(t); } else { field2.AddAllocated(t); @@ -1160,12 +1134,12 @@ TEST(ArenaTest, SwapRepeatedFieldWithDifferentArenas) { TEST(ArenaTest, SwapRepeatedFieldWithNoArenaOnRightHandSide) { Arena arena; - TestSwapRepeatedField(&arena, nullptr); + TestSwapRepeatedField(&arena, NULL); } TEST(ArenaTest, SwapRepeatedFieldWithNoArenaOnLeftHandSide) { Arena arena; - TestSwapRepeatedField(nullptr, &arena); + TestSwapRepeatedField(NULL, &arena); } TEST(ArenaTest, ExtensionsOnArena) { @@ -1224,11 +1198,11 @@ TEST(ArenaTest, RepeatedFieldOnArena) { TestAllTypes* extracted_messages[5]; // ExtractSubrange should copy to the heap. repeated_message.ExtractSubrange(0, 5, extracted_messages); - EXPECT_EQ(nullptr, extracted_messages[0]->GetArena()); + EXPECT_EQ(NULL, extracted_messages[0]->GetArena()); // We need to free the heap-allocated messages to prevent a leak. for (int i = 0; i < 5; i++) { delete extracted_messages[i]; - extracted_messages[i] = nullptr; + extracted_messages[i] = NULL; } } @@ -1348,7 +1322,7 @@ TEST(ArenaTest, MessageLiteOnArena) { { MessageLite* generic_message = prototype->New(&arena); - EXPECT_TRUE(generic_message != nullptr); + EXPECT_TRUE(generic_message != NULL); EXPECT_EQ(&arena, generic_message->GetArena()); EXPECT_TRUE(generic_message->ParseFromString(serialized)); TestAllTypes* deserialized = static_cast(generic_message); @@ -1409,31 +1383,6 @@ TEST(ArenaTest, SpaceAllocated_and_Used) { EXPECT_EQ(1024, arena_2.Reset()); } -namespace { - -void VerifyArenaOverhead(Arena& arena, size_t overhead) { - EXPECT_EQ(0, arena.SpaceAllocated()); - - // Allocate a tiny block and record the allocation size. - constexpr size_t kTinySize = 8; - Arena::CreateArray(&arena, kTinySize); - uint64_t space_allocated = arena.SpaceAllocated(); - - // Next allocation expects to fill up the block but no new block. - uint64_t next_size = space_allocated - overhead - kTinySize; - Arena::CreateArray(&arena, next_size); - - EXPECT_EQ(space_allocated, arena.SpaceAllocated()); -} - -} // namespace - -TEST(ArenaTest, FirstArenaOverhead) { - Arena arena; - VerifyArenaOverhead(arena, internal::SerialArena::kBlockHeaderSize); -} - - TEST(ArenaTest, BlockSizeDoubling) { Arena arena; EXPECT_EQ(0, arena.SpaceUsed()); @@ -1450,7 +1399,7 @@ TEST(ArenaTest, BlockSizeDoubling) { ASSERT_GT(arena.SpaceAllocated(), first_block_size); auto second_block_size = (arena.SpaceAllocated() - first_block_size); - EXPECT_GE(second_block_size, 2*first_block_size); + EXPECT_EQ(second_block_size, 2*first_block_size); } TEST(ArenaTest, Alignment) { @@ -1494,8 +1443,8 @@ TEST(ArenaTest, GetArenaShouldReturnTheArenaForArenaAllocatedMessages) { TEST(ArenaTest, GetArenaShouldReturnNullForNonArenaAllocatedMessages) { ArenaMessage message; const ArenaMessage* const_pointer_to_message = &message; - EXPECT_EQ(nullptr, Arena::GetArena(&message)); - EXPECT_EQ(nullptr, Arena::GetArena(const_pointer_to_message)); + EXPECT_EQ(NULL, Arena::GetArena(&message)); + EXPECT_EQ(NULL, Arena::GetArena(const_pointer_to_message)); } TEST(ArenaTest, GetArenaShouldReturnNullForNonArenaCompatibleTypes) { @@ -1561,19 +1510,14 @@ TEST(ArenaTest, SpaceReuseForArraysSizeChecks) { TEST(ArenaTest, SpaceReusePoisonsAndUnpoisonsMemory) { #ifdef ADDRESS_SANITIZER char buf[1024]{}; - constexpr int kSize = 32; { Arena arena(buf, sizeof(buf)); std::vector pointers; for (int i = 0; i < 100; ++i) { - void* p = Arena::CreateArray(&arena, kSize); - // Simulate other ASan client managing shadow memory. - ASAN_POISON_MEMORY_REGION(p, kSize); - ASAN_UNPOISON_MEMORY_REGION(p, kSize - 4); - pointers.push_back(p); + pointers.push_back(Arena::CreateArray(&arena, 16)); } for (void* p : pointers) { - internal::ArenaTestPeer::ReturnArrayMemory(&arena, p, kSize); + internal::ArenaTestPeer::ReturnArrayMemory(&arena, p, 16); // The first one is not poisoned because it becomes the freelist. if (p != pointers[0]) EXPECT_TRUE(__asan_address_is_poisoned(p)); } @@ -1598,8 +1542,93 @@ TEST(ArenaTest, SpaceReusePoisonsAndUnpoisonsMemory) { #endif // ADDRESS_SANITIZER } +namespace { +uint32_t hooks_num_init = 0; +uint32_t hooks_num_allocations = 0; +uint32_t hooks_num_reset = 0; +uint32_t hooks_num_destruct = 0; + +void ClearHookCounts() { + hooks_num_init = 0; + hooks_num_allocations = 0; + hooks_num_reset = 0; + hooks_num_destruct = 0; +} +} // namespace + +// A helper utility class that handles arena callbacks. +class ArenaOptionsTestFriend final : public internal::ArenaMetricsCollector { + public: + static internal::ArenaMetricsCollector* NewWithAllocs() { + return new ArenaOptionsTestFriend(true); + } + + static internal::ArenaMetricsCollector* NewWithoutAllocs() { + return new ArenaOptionsTestFriend(false); + } + + static void Enable(ArenaOptions* options) { + ClearHookCounts(); + options->make_metrics_collector = &ArenaOptionsTestFriend::NewWithAllocs; + } + + static void EnableWithoutAllocs(ArenaOptions* options) { + ClearHookCounts(); + options->make_metrics_collector = &ArenaOptionsTestFriend::NewWithoutAllocs; + } + + explicit ArenaOptionsTestFriend(bool record_allocs) + : ArenaMetricsCollector(record_allocs) { + ++hooks_num_init; + } + void OnDestroy(uint64_t space_allocated) override { + ++hooks_num_destruct; + delete this; + } + void OnReset(uint64_t space_allocated) override { ++hooks_num_reset; } + void OnAlloc(const std::type_info* allocated_type, + uint64_t alloc_size) override { + ++hooks_num_allocations; + } +}; + +// Test the hooks are correctly called. +TEST(ArenaTest, ArenaHooksSanity) { + ArenaOptions options; + ArenaOptionsTestFriend::Enable(&options); + + // Scope for defining the arena + { + Arena arena(options); + EXPECT_EQ(1, hooks_num_init); + EXPECT_EQ(0, hooks_num_allocations); + Arena::Create(&arena); + if (std::is_trivially_destructible::value) { + EXPECT_EQ(1, hooks_num_allocations); + } else { + EXPECT_EQ(2, hooks_num_allocations); + } + arena.Reset(); + arena.Reset(); + EXPECT_EQ(2, hooks_num_reset); + } + EXPECT_EQ(2, hooks_num_reset); + EXPECT_EQ(1, hooks_num_destruct); +} + +// Test that allocation hooks are not called when we don't need them. +TEST(ArenaTest, ArenaHooksWhenAllocationsNotNeeded) { + ArenaOptions options; + ArenaOptionsTestFriend::EnableWithoutAllocs(&options); + + Arena arena(options); + EXPECT_EQ(0, hooks_num_allocations); + Arena::Create(&arena); + EXPECT_EQ(0, hooks_num_allocations); +} + } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/arenastring.cc b/libs/protobuf/src/google/protobuf/arenastring.cc index f033d67..af0c9df 100644 --- a/libs/protobuf/src/google/protobuf/arenastring.cc +++ b/libs/protobuf/src/google/protobuf/arenastring.cc @@ -28,20 +28,20 @@ // (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/arenastring.h" +#include #include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" +#include +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { @@ -71,7 +71,7 @@ static_assert(alignof(ExplicitlyConstructedArenaString) >= 4, ""); } // namespace const std::string& LazyString::Init() const { - static absl::Mutex mu{absl::kConstInit}; + static WrappedMutex mu{GOOGLE_PROTOBUF_LINKER_INITIALIZED}; mu.Lock(); const std::string* res = inited_.load(std::memory_order_acquire); if (res == nullptr) { @@ -87,7 +87,7 @@ const std::string& LazyString::Init() const { namespace { -#if defined(NDEBUG) || !defined(GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL) +#if defined(NDEBUG) || !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL class ScopedCheckPtrInvariants { public: @@ -97,16 +97,16 @@ class ScopedCheckPtrInvariants { #endif // NDEBUG || !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL // Creates a heap allocated std::string value. -inline TaggedStringPtr CreateString(absl::string_view value) { +inline TaggedStringPtr CreateString(ConstStringParam value) { TaggedStringPtr res; res.SetAllocated(new std::string(value.data(), value.length())); return res; } -#ifndef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL +#if !GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL // Creates an arena allocated std::string value. -TaggedStringPtr CreateArenaString(Arena& arena, absl::string_view s) { +TaggedStringPtr CreateArenaString(Arena& arena, ConstStringParam s) { TaggedStringPtr res; res.SetMutableArena(Arena::Create(&arena, s.data(), s.length())); return res; @@ -116,7 +116,7 @@ TaggedStringPtr CreateArenaString(Arena& arena, absl::string_view s) { } // namespace -void ArenaStringPtr::Set(absl::string_view value, Arena* arena) { +void ArenaStringPtr::Set(ConstStringParam value, Arena* arena) { ScopedCheckPtrInvariants check(&tagged_ptr_); if (IsDefault()) { // If we're not on an arena, skip straight to a true string to avoid @@ -124,19 +124,7 @@ void ArenaStringPtr::Set(absl::string_view value, Arena* arena) { tagged_ptr_ = arena != nullptr ? CreateArenaString(*arena, value) : CreateString(value); } else { -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (arena == nullptr) { - auto* old = tagged_ptr_.GetIfAllocated(); - tagged_ptr_ = CreateString(value); - delete old; - } else { - auto* old = UnsafeMutablePointer(); - tagged_ptr_ = CreateArenaString(*arena, value); - old->assign("garbagedata"); - } -#else // PROTOBUF_FORCE_COPY_DEFAULT_STRING UnsafeMutablePointer()->assign(value.data(), value.length()); -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING } } @@ -276,4 +264,4 @@ const char* EpsCopyInputStream::ReadArenaString(const char* ptr, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/arenastring.h b/libs/protobuf/src/google/protobuf/arenastring.h index 519e50d..6bc8395 100644 --- a/libs/protobuf/src/google/protobuf/arenastring.h +++ b/libs/protobuf/src/google/protobuf/arenastring.h @@ -36,15 +36,14 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/explicitly_constructed.h" +#include +#include +#include +#include +#include // must be last: -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -260,12 +259,12 @@ struct PROTOBUF_EXPORT ArenaStringPtr { // instance known to not carry any heap allocated value. inline void InitAllocated(std::string* str, Arena* arena); - void Set(absl::string_view value, Arena* arena); + void Set(ConstStringParam value, Arena* arena); void Set(std::string&& value, Arena* arena); void Set(const char* s, Arena* arena); void Set(const char* s, size_t n, Arena* arena); - void SetBytes(absl::string_view value, Arena* arena); + void SetBytes(ConstStringParam value, Arena* arena); void SetBytes(std::string&& value, Arena* arena); void SetBytes(const char* s, Arena* arena); void SetBytes(const void* p, size_t n, Arena* arena); @@ -407,14 +406,14 @@ inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) { } inline void ArenaStringPtr::Set(const char* s, Arena* arena) { - Set(absl::string_view{s}, arena); + Set(ConstStringParam{s}, arena); } inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) { - Set(absl::string_view{s, n}, arena); + Set(ConstStringParam{s, n}, arena); } -inline void ArenaStringPtr::SetBytes(absl::string_view value, Arena* arena) { +inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) { Set(value, arena); } @@ -427,7 +426,7 @@ inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) { } inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) { - Set(absl::string_view{static_cast(p), n}, arena); + Set(ConstStringParam{static_cast(p), n}, arena); } // Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs. @@ -476,6 +475,6 @@ inline std::string* ArenaStringPtr::UnsafeMutablePointer() { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_ARENASTRING_H__ diff --git a/libs/protobuf/src/google/protobuf/arenastring_unittest.cc b/libs/protobuf/src/google/protobuf/arenastring_unittest.cc index efb4bf3..0e5ea9b 100644 --- a/libs/protobuf/src/google/protobuf/arenastring_unittest.cc +++ b/libs/protobuf/src/google/protobuf/arenastring_unittest.cc @@ -28,7 +28,7 @@ // (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/arenastring.h" +#include #include #include @@ -37,18 +37,18 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/message_lite.h" +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/string_view.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -151,4 +151,4 @@ TEST_P(DualArena, Swap) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/arenaz_sampler.cc b/libs/protobuf/src/google/protobuf/arenaz_sampler.cc index 44e53e5..0eac693 100644 --- a/libs/protobuf/src/google/protobuf/arenaz_sampler.cc +++ b/libs/protobuf/src/google/protobuf/arenaz_sampler.cc @@ -28,16 +28,15 @@ // (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/arenaz_sampler.h" +#include #include #include #include -#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -57,93 +56,64 @@ namespace { PROTOBUF_CONSTINIT std::atomic g_arenaz_enabled{true}; PROTOBUF_CONSTINIT std::atomic g_arenaz_sample_parameter{1 << 10}; -PROTOBUF_CONSTINIT std::atomic - g_arenaz_config_listener{nullptr}; PROTOBUF_THREAD_LOCAL absl::profiling_internal::ExponentialBiased g_exponential_biased_generator; -void TriggerThreadSafeArenazConfigListener() { - auto* listener = g_arenaz_config_listener.load(std::memory_order_acquire); - if (listener != nullptr) listener(); -} - } // namespace -PROTOBUF_THREAD_LOCAL SamplingState global_sampling_state = { - /*next_sample=*/0, /*sample_stride=*/0}; +PROTOBUF_THREAD_LOCAL int64_t global_next_sample = 1LL << 10; -ThreadSafeArenaStats::ThreadSafeArenaStats() { PrepareForSampling(0); } +ThreadSafeArenaStats::ThreadSafeArenaStats() { PrepareForSampling(); } ThreadSafeArenaStats::~ThreadSafeArenaStats() = default; -void ThreadSafeArenaStats::BlockStats::PrepareForSampling() { +void ThreadSafeArenaStats::PrepareForSampling() { num_allocations.store(0, std::memory_order_relaxed); + num_resets.store(0, std::memory_order_relaxed); + bytes_requested.store(0, std::memory_order_relaxed); bytes_allocated.store(0, std::memory_order_relaxed); - bytes_used.store(0, std::memory_order_relaxed); bytes_wasted.store(0, std::memory_order_relaxed); -} - -void ThreadSafeArenaStats::PrepareForSampling(int64_t stride) { - for (auto& blockstats : block_histogram) blockstats.PrepareForSampling(); - max_block_size.store(0, std::memory_order_relaxed); + max_bytes_allocated.store(0, std::memory_order_relaxed); thread_ids.store(0, std::memory_order_relaxed); - weight = stride; // The inliner makes hardcoded skip_count difficult (especially when combined // with LTO). We use the ability to exclude stacks by regex when encoding // instead. depth = absl::GetStackTrace(stack, kMaxStackDepth, /* skip_count= */ 0); } -size_t ThreadSafeArenaStats::FindBin(size_t bytes) { - if (bytes <= kMaxSizeForBinZero) return 0; - if (bytes <= kMaxSizeForPenultimateBin) { - // absl::bit_width() returns one plus the base-2 logarithm of x, with any - // fractional part discarded. - return absl::bit_width(absl::bit_ceil(bytes)) - kLogMaxSizeForBinZero - 1; +void RecordResetSlow(ThreadSafeArenaStats* info) { + const size_t max_bytes = + info->max_bytes_allocated.load(std::memory_order_relaxed); + const size_t allocated_bytes = + info->bytes_allocated.load(std::memory_order_relaxed); + if (max_bytes < allocated_bytes) { + info->max_bytes_allocated.store(allocated_bytes); } - return kBlockHistogramBins - 1; + info->bytes_requested.store(0, std::memory_order_relaxed); + info->bytes_allocated.store(0, std::memory_order_relaxed); + info->bytes_wasted.fetch_add(0, std::memory_order_relaxed); + info->num_allocations.fetch_add(0, std::memory_order_relaxed); + info->num_resets.fetch_add(1, std::memory_order_relaxed); } -std::pair ThreadSafeArenaStats::MinMaxBlockSizeForBin( - size_t bin) { - ABSL_ASSERT(bin < kBlockHistogramBins); - if (bin == 0) return {1, kMaxSizeForBinZero}; - if (bin < kBlockHistogramBins - 1) { - return {(1 << (kLogMaxSizeForBinZero + bin - 1)) + 1, - 1 << (kLogMaxSizeForBinZero + bin)}; - } - return {kMaxSizeForPenultimateBin + 1, std::numeric_limits::max()}; -} - -void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used, +void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested, size_t allocated, size_t wasted) { - // Update the allocated bytes for the current block. - ThreadSafeArenaStats::BlockStats& curr = - info->block_histogram[ThreadSafeArenaStats::FindBin(allocated)]; - curr.bytes_allocated.fetch_add(allocated, std::memory_order_relaxed); - curr.num_allocations.fetch_add(1, std::memory_order_relaxed); - - // Update the used and wasted bytes for the previous block. - ThreadSafeArenaStats::BlockStats& prev = - info->block_histogram[ThreadSafeArenaStats::FindBin(used + wasted)]; - prev.bytes_used.fetch_add(used, std::memory_order_relaxed); - prev.bytes_wasted.fetch_add(wasted, std::memory_order_relaxed); - - if (info->max_block_size.load(std::memory_order_relaxed) < allocated) { - info->max_block_size.store(allocated, std::memory_order_relaxed); + info->bytes_requested.fetch_add(requested, std::memory_order_relaxed); + info->bytes_allocated.fetch_add(allocated, std::memory_order_relaxed); + info->bytes_wasted.fetch_add(wasted, std::memory_order_relaxed); + info->num_allocations.fetch_add(1, std::memory_order_relaxed); + const uint64_t tid = (1ULL << (GetCachedTID() % 63)); + const uint64_t thread_ids = info->thread_ids.load(std::memory_order_relaxed); + if (!(thread_ids & tid)) { + info->thread_ids.store(thread_ids | tid, std::memory_order_relaxed); } - const uint64_t tid = 1ULL << (GetCachedTID() % 63); - info->thread_ids.fetch_or(tid, std::memory_order_relaxed); } -ThreadSafeArenaStats* SampleSlow(SamplingState& sampling_state) { - bool first = sampling_state.next_sample < 0; - const int64_t next_stride = g_exponential_biased_generator.GetStride( +ThreadSafeArenaStats* SampleSlow(int64_t* next_sample) { + bool first = *next_sample < 0; + *next_sample = g_exponential_biased_generator.GetStride( g_arenaz_sample_parameter.load(std::memory_order_relaxed)); // Small values of interval are equivalent to just sampling next time. - ABSL_ASSERT(next_stride >= 1); - sampling_state.next_sample = next_stride; - const int64_t old_stride = - absl::exchange(sampling_state.sample_stride, next_stride); + ABSL_ASSERT(*next_sample >= 1); // g_arenaz_enabled can be dynamically flipped, we need to set a threshold low // enough that we will start sampling in a reasonable time, so we just use the @@ -152,36 +122,18 @@ ThreadSafeArenaStats* SampleSlow(SamplingState& sampling_state) { // We will only be negative on our first count, so we should just retry in // that case. if (first) { - if (PROTOBUF_PREDICT_TRUE(--sampling_state.next_sample > 0)) return nullptr; - return SampleSlow(sampling_state); + if (PROTOBUF_PREDICT_TRUE(--*next_sample > 0)) return nullptr; + return SampleSlow(next_sample); } - return GlobalThreadSafeArenazSampler().Register(old_stride); -} - -void SetThreadSafeArenazConfigListener(ThreadSafeArenazConfigListener l) { - g_arenaz_config_listener.store(l, std::memory_order_release); -} - -bool IsThreadSafeArenazEnabled() { - return g_arenaz_enabled.load(std::memory_order_acquire); + return GlobalThreadSafeArenazSampler().Register(); } void SetThreadSafeArenazEnabled(bool enabled) { - SetThreadSafeArenazEnabledInternal(enabled); - TriggerThreadSafeArenazConfigListener(); -} - -void SetThreadSafeArenazEnabledInternal(bool enabled) { g_arenaz_enabled.store(enabled, std::memory_order_release); } void SetThreadSafeArenazSampleParameter(int32_t rate) { - SetThreadSafeArenazSampleParameterInternal(rate); - TriggerThreadSafeArenazConfigListener(); -} - -void SetThreadSafeArenazSampleParameterInternal(int32_t rate) { if (rate > 0) { g_arenaz_sample_parameter.store(rate, std::memory_order_release); } else { @@ -190,16 +142,7 @@ void SetThreadSafeArenazSampleParameterInternal(int32_t rate) { } } -int32_t ThreadSafeArenazSampleParameter() { - return g_arenaz_sample_parameter.load(std::memory_order_relaxed); -} - void SetThreadSafeArenazMaxSamples(int32_t max) { - SetThreadSafeArenazMaxSamplesInternal(max); - TriggerThreadSafeArenazConfigListener(); -} - -void SetThreadSafeArenazMaxSamplesInternal(int32_t max) { if (max > 0) { GlobalThreadSafeArenazSampler().SetMaxSamples(max); } else { @@ -208,14 +151,9 @@ void SetThreadSafeArenazMaxSamplesInternal(int32_t max) { } } -size_t ThreadSafeArenazMaxSamples() { - return GlobalThreadSafeArenazSampler().GetMaxSamples(); -} - void SetThreadSafeArenazGlobalNextSample(int64_t next_sample) { if (next_sample >= 0) { - global_sampling_state.next_sample = next_sample; - global_sampling_state.sample_stride = next_sample; + global_next_sample = next_sample; } else { ABSL_RAW_LOG(ERROR, "Invalid thread safe arenaz next sample: %lld", static_cast(next_sample)); // NOLINT(runtime/int) @@ -228,16 +166,9 @@ ThreadSafeArenaStats* SampleSlow(int64_t* next_sample) { return nullptr; } -void SetThreadSafeArenazConfigListener(ThreadSafeArenazConfigListener) {} void SetThreadSafeArenazEnabled(bool enabled) {} -void SetThreadSafeArenazEnabledInternal(bool enabled) {} -bool IsThreadSafeArenazEnabled() { return false; } void SetThreadSafeArenazSampleParameter(int32_t rate) {} -void SetThreadSafeArenazSampleParameterInternal(int32_t rate) {} -int32_t ThreadSafeArenazSampleParameter() { return 0; } void SetThreadSafeArenazMaxSamples(int32_t max) {} -void SetThreadSafeArenazMaxSamplesInternal(int32_t max) {} -size_t ThreadSafeArenazMaxSamples() { return 0; } void SetThreadSafeArenazGlobalNextSample(int64_t next_sample) {} #endif // defined(PROTOBUF_ARENAZ_SAMPLE) diff --git a/libs/protobuf/src/google/protobuf/arenaz_sampler.h b/libs/protobuf/src/google/protobuf/arenaz_sampler.h index 23ab83a..b04b0cc 100644 --- a/libs/protobuf/src/google/protobuf/arenaz_sampler.h +++ b/libs/protobuf/src/google/protobuf/arenaz_sampler.h @@ -31,15 +31,13 @@ #ifndef GOOGLE_PROTOBUF_SRC_GOOGLE_PROTOBUF_ARENAZ_SAMPLER_H__ #define GOOGLE_PROTOBUF_SRC_GOOGLE_PROTOBUF_ARENAZ_SAMPLER_H__ -#include #include #include #include -#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -47,7 +45,8 @@ namespace internal { #if defined(PROTOBUF_ARENAZ_SAMPLE) struct ThreadSafeArenaStats; -void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t used, +void RecordResetSlow(ThreadSafeArenaStats* info); +void RecordAllocateSlow(ThreadSafeArenaStats* info, size_t requested, size_t allocated, size_t wasted); // Stores information about a sampled thread safe arena. All mutations to this // *must* be made through `Record*` functions below. All reads from this *must* @@ -59,42 +58,20 @@ struct ThreadSafeArenaStats ~ThreadSafeArenaStats(); // Puts the object into a clean state, fills in the logically `const` members, - // blocking for any readers that are currently sampling the object. The - // 'stride' parameter is the number of ThreadSafeArenas that were instantiated - // between this sample and the previous one. - void PrepareForSampling(int64_t stride) - ABSL_EXCLUSIVE_LOCKS_REQUIRED(init_mu); + // blocking for any readers that are currently sampling the object. + void PrepareForSampling() ABSL_EXCLUSIVE_LOCKS_REQUIRED(init_mu); // These fields are mutated by the various Record* APIs and need to be // thread-safe. - struct BlockStats { - std::atomic num_allocations; - std::atomic bytes_allocated; - std::atomic bytes_used; - std::atomic bytes_wasted; - - void PrepareForSampling(); - }; - - // block_histogram is a kBlockHistogramBins sized histogram. The zeroth bin - // stores info about blocks of size \in [1, 1 << kLogMaxSizeForBinZero]. Bin - // i, where i > 0, stores info for blocks of size \in (max_size_bin (i-1), - // 1 << (kLogMaxSizeForBinZero + i)]. The final bin stores info about blocks - // of size \in [kMaxSizeForPenultimateBin + 1, - // std::numeric_limits::max()]. - static constexpr size_t kBlockHistogramBins = 15; - static constexpr size_t kLogMaxSizeForBinZero = 7; - static constexpr size_t kMaxSizeForBinZero = (1 << kLogMaxSizeForBinZero); - static constexpr size_t kMaxSizeForPenultimateBin = - 1 << (kLogMaxSizeForBinZero + kBlockHistogramBins - 2); - std::array block_histogram; - - // Records the largest block allocated for the arena. - std::atomic max_block_size; - // Bit `i` is set to 1 indicates that a thread with `tid % 63 = i` accessed - // the underlying arena. We use `% 63` as a rudimentary hash to ensure some - // bit mixing for thread-ids; `% 64` would only grab the low bits and might - // create sampling artifacts. + std::atomic num_allocations; + std::atomic num_resets; + std::atomic bytes_requested; + std::atomic bytes_allocated; + std::atomic bytes_wasted; + // Records the largest size an arena ever had. Maintained across resets. + std::atomic max_bytes_allocated; + // Bit i when set to 1 indicates that a thread with tid % 63 = i accessed the + // underlying arena. The field is maintained across resets. std::atomic thread_ids; // All of the fields below are set by `PrepareForSampling`, they must not @@ -105,32 +82,14 @@ struct ThreadSafeArenaStats static constexpr int kMaxStackDepth = 64; int32_t depth; void* stack[kMaxStackDepth]; - static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t used, + static void RecordAllocateStats(ThreadSafeArenaStats* info, size_t requested, size_t allocated, size_t wasted) { if (PROTOBUF_PREDICT_TRUE(info == nullptr)) return; - RecordAllocateSlow(info, used, allocated, wasted); + RecordAllocateSlow(info, requested, allocated, wasted); } - - // Returns the bin for the provided size. - static size_t FindBin(size_t bytes); - - // Returns the min and max bytes that can be stored in the histogram for - // blocks in the provided bin. - static std::pair MinMaxBlockSizeForBin(size_t bin); }; -struct SamplingState { - // Number of ThreadSafeArenas that should be instantiated before the next - // ThreadSafeArena is sampled. This variable is decremented with each - // instantiation. - int64_t next_sample; - // When we make a sampling decision, we record that distance between from the - // previous sample so we can weight each sample. 'distance' here is the - // number of instantiations of ThreadSafeArena. - int64_t sample_stride; -}; - -ThreadSafeArenaStats* SampleSlow(SamplingState& sampling_state); +ThreadSafeArenaStats* SampleSlow(int64_t* next_sample); void UnsampleSlow(ThreadSafeArenaStats* info); class ThreadSafeArenaStatsHandle { @@ -156,6 +115,11 @@ class ThreadSafeArenaStatsHandle { return *this; } + void RecordReset() { + if (PROTOBUF_PREDICT_TRUE(info_ == nullptr)) return; + RecordResetSlow(info_); + } + ThreadSafeArenaStats* MutableStats() { return info_; } friend void swap(ThreadSafeArenaStatsHandle& lhs, @@ -172,27 +136,24 @@ class ThreadSafeArenaStatsHandle { using ThreadSafeArenazSampler = ::absl::profiling_internal::SampleRecorder; -extern PROTOBUF_THREAD_LOCAL SamplingState global_sampling_state; +extern PROTOBUF_THREAD_LOCAL int64_t global_next_sample; // Returns an RAII sampling handle that manages registration and unregistation // with the global sampler. inline ThreadSafeArenaStatsHandle Sample() { - if (PROTOBUF_PREDICT_TRUE(--global_sampling_state.next_sample > 0)) { + if (PROTOBUF_PREDICT_TRUE(--global_next_sample > 0)) { return ThreadSafeArenaStatsHandle(nullptr); } - return ThreadSafeArenaStatsHandle(SampleSlow(global_sampling_state)); + return ThreadSafeArenaStatsHandle(SampleSlow(&global_next_sample)); } #else - -using SamplingState = int64_t; - struct ThreadSafeArenaStats { static void RecordAllocateStats(ThreadSafeArenaStats*, size_t /*requested*/, size_t /*allocated*/, size_t /*wasted*/) {} }; -ThreadSafeArenaStats* SampleSlow(SamplingState& next_sample); +ThreadSafeArenaStats* SampleSlow(int64_t* next_sample); void UnsampleSlow(ThreadSafeArenaStats* info); class ThreadSafeArenaStatsHandle { @@ -226,29 +187,14 @@ inline ThreadSafeArenaStatsHandle Sample() { // Returns a global Sampler. ThreadSafeArenazSampler& GlobalThreadSafeArenazSampler(); -using ThreadSafeArenazConfigListener = void (*)(); -void SetThreadSafeArenazConfigListener(ThreadSafeArenazConfigListener l); - // Enables or disables sampling for thread safe arenas. void SetThreadSafeArenazEnabled(bool enabled); -void SetThreadSafeArenazEnabledInternal(bool enabled); - -// Returns true if sampling is on, false otherwise. -bool IsThreadSafeArenazEnabled(); // Sets the rate at which thread safe arena will be sampled. void SetThreadSafeArenazSampleParameter(int32_t rate); -void SetThreadSafeArenazSampleParameterInternal(int32_t rate); - -// Returns the rate at which thread safe arena will be sampled. -int32_t ThreadSafeArenazSampleParameter(); // Sets a soft max for the number of samples that will be kept. void SetThreadSafeArenazMaxSamples(int32_t max); -void SetThreadSafeArenazMaxSamplesInternal(int32_t max); - -// Returns the max number of samples that will be kept. -size_t ThreadSafeArenazMaxSamples(); // Sets the current value for when arenas should be next sampled. void SetThreadSafeArenazGlobalNextSample(int64_t next_sample); @@ -257,5 +203,5 @@ void SetThreadSafeArenazGlobalNextSample(int64_t next_sample); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_SRC_PROTOBUF_ARENAZ_SAMPLER_H__ diff --git a/libs/protobuf/src/google/protobuf/arenaz_sampler_test.cc b/libs/protobuf/src/google/protobuf/arenaz_sampler_test.cc index 98ff042..1bfec54 100644 --- a/libs/protobuf/src/google/protobuf/arenaz_sampler_test.cc +++ b/libs/protobuf/src/google/protobuf/arenaz_sampler_test.cc @@ -28,21 +28,19 @@ // (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/arenaz_sampler.h" +#include -#include -#include #include #include -#include #include #include #include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -58,27 +56,18 @@ class ThreadSafeArenaStatsHandlePeer { return h->info_; } }; - std::vector GetBytesAllocated(ThreadSafeArenazSampler* s) { std::vector res; s->Iterate([&](const ThreadSafeArenaStats& info) { - for (const auto& block_stats : info.block_histogram) { - size_t bytes_allocated = - block_stats.bytes_allocated.load(std::memory_order_acquire); - if (bytes_allocated != 0) { - res.push_back(bytes_allocated); - } - } + res.push_back(info.bytes_allocated.load(std::memory_order_acquire)); }); return res; } -ThreadSafeArenaStats* Register(ThreadSafeArenazSampler* s, size_t size, - int64_t stride) { - auto* info = s->Register(stride); +ThreadSafeArenaStats* Register(ThreadSafeArenazSampler* s, size_t size) { + auto* info = s->Register(); assert(info != nullptr); - info->block_histogram[0].bytes_allocated.store(size, - std::memory_order_relaxed); + info->bytes_allocated.store(size); return info; } @@ -90,148 +79,75 @@ namespace { TEST(ThreadSafeArenaStatsTest, PrepareForSampling) { ThreadSafeArenaStats info; - constexpr int64_t kTestStride = 107; - absl::MutexLock l(&info.init_mu); - info.PrepareForSampling(kTestStride); + MutexLock l(&info.init_mu); + info.PrepareForSampling(); - for (const auto& block_stats : info.block_histogram) { - EXPECT_EQ(block_stats.num_allocations.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_used.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_allocated.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_wasted.load(std::memory_order_relaxed), 0); - } - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 0); - EXPECT_EQ(info.weight, kTestStride); + EXPECT_EQ(info.num_allocations.load(), 0); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_requested.load(), 0); + EXPECT_EQ(info.bytes_allocated.load(), 0); + EXPECT_EQ(info.bytes_wasted.load(), 0); + EXPECT_EQ(info.max_bytes_allocated.load(), 0); - for (auto& block_stats : info.block_histogram) { - block_stats.num_allocations.store(1, std::memory_order_relaxed); - block_stats.bytes_used.store(1, std::memory_order_relaxed); - block_stats.bytes_allocated.store(1, std::memory_order_relaxed); - block_stats.bytes_wasted.store(1, std::memory_order_relaxed); - } - info.max_block_size.store(1, std::memory_order_relaxed); + info.num_allocations.store(1, std::memory_order_relaxed); + info.num_resets.store(1, std::memory_order_relaxed); + info.bytes_requested.store(1, std::memory_order_relaxed); + info.bytes_allocated.store(1, std::memory_order_relaxed); + info.bytes_wasted.store(1, std::memory_order_relaxed); + info.max_bytes_allocated.store(1, std::memory_order_relaxed); - info.PrepareForSampling(2 * kTestStride); - for (auto& block_stats : info.block_histogram) { - EXPECT_EQ(block_stats.num_allocations.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_used.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_allocated.load(std::memory_order_relaxed), 0); - EXPECT_EQ(block_stats.bytes_wasted.load(std::memory_order_relaxed), 0); - } - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 0); - EXPECT_EQ(info.weight, 2 * kTestStride); -} - -TEST(ThreadSafeArenaStatsTest, FindBin) { - size_t current_bin = 0; - size_t bytes = 1; - while (current_bin < ThreadSafeArenaStats::kBlockHistogramBins - 1) { - size_t next_bin = ThreadSafeArenaStats::FindBin(bytes); - if (next_bin != current_bin) { - // Test the bins increase linearly. - EXPECT_EQ(next_bin, current_bin + 1); - // Test the bins change only at values of the form 2^k + 1. - EXPECT_EQ(absl::popcount(bytes - 1), 1); - current_bin = next_bin; - } - ++bytes; - } -} - -TEST(ThreadSafeArenaStatsTest, MinMaxBlockSizeForBin) { - std::pair current_limits = - ThreadSafeArenaStats::MinMaxBlockSizeForBin(0); - EXPECT_EQ(current_limits.first, 1); - EXPECT_LT(current_limits.first, current_limits.second); - for (size_t i = 1; i < ThreadSafeArenaStats::kBlockHistogramBins; ++i) { - std::pair next_limits = - ThreadSafeArenaStats::MinMaxBlockSizeForBin(i); - EXPECT_LT(next_limits.first, next_limits.second); - // Test the limits do not have gaps. - EXPECT_EQ(next_limits.first, current_limits.second + 1); - if (i != ThreadSafeArenaStats::kBlockHistogramBins - 1) { - EXPECT_EQ(next_limits.second, 2 * current_limits.second); - } - current_limits = next_limits; - } - // Test the limits cover the entire range possible. - EXPECT_EQ(current_limits.second, std::numeric_limits::max()); + info.PrepareForSampling(); + EXPECT_EQ(info.num_allocations.load(), 0); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_requested.load(), 0); + EXPECT_EQ(info.bytes_allocated.load(), 0); + EXPECT_EQ(info.bytes_wasted.load(), 0); + EXPECT_EQ(info.max_bytes_allocated.load(), 0); } TEST(ThreadSafeArenaStatsTest, RecordAllocateSlow) { ThreadSafeArenaStats info; - constexpr int64_t kTestStride = 458; - absl::MutexLock l(&info.init_mu); - info.PrepareForSampling(kTestStride); - RecordAllocateSlow(&info, /*requested=*/0, /*allocated=*/128, /*wasted=*/0); - EXPECT_EQ( - info.block_histogram[0].num_allocations.load(std::memory_order_relaxed), - 1); - EXPECT_EQ(info.block_histogram[0].bytes_used.load(std::memory_order_relaxed), - 0); - EXPECT_EQ( - info.block_histogram[0].bytes_allocated.load(std::memory_order_relaxed), - 128); - EXPECT_EQ( - info.block_histogram[0].bytes_wasted.load(std::memory_order_relaxed), 0); - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 128); - RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/256, - /*wasted=*/28); - EXPECT_EQ(info.block_histogram[0].bytes_used.load(std::memory_order_relaxed), - 100); - EXPECT_EQ( - info.block_histogram[0].bytes_wasted.load(std::memory_order_relaxed), 28); - EXPECT_EQ( - info.block_histogram[1].num_allocations.load(std::memory_order_relaxed), - 1); - EXPECT_EQ( - info.block_histogram[1].bytes_allocated.load(std::memory_order_relaxed), - 256); - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 256); -} - -TEST(ThreadSafeArenaStatsTest, RecordAllocateSlowMaxBlockSizeTest) { - ThreadSafeArenaStats info; - constexpr int64_t kTestStride = 458; - absl::MutexLock l(&info.init_mu); - info.PrepareForSampling(kTestStride); + MutexLock l(&info.init_mu); + info.PrepareForSampling(); RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/128, /*wasted=*/0); - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 128); + EXPECT_EQ(info.num_allocations.load(), 1); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_requested.load(), 100); + EXPECT_EQ(info.bytes_allocated.load(), 128); + EXPECT_EQ(info.bytes_wasted.load(), 0); + EXPECT_EQ(info.max_bytes_allocated.load(), 0); RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/256, /*wasted=*/28); - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 256); - RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/128, - /*wasted=*/28); - EXPECT_EQ(info.max_block_size.load(std::memory_order_relaxed), 256); + EXPECT_EQ(info.num_allocations.load(), 2); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_requested.load(), 200); + EXPECT_EQ(info.bytes_allocated.load(), 384); + EXPECT_EQ(info.bytes_wasted.load(), 28); + EXPECT_EQ(info.max_bytes_allocated.load(), 0); } -TEST(ThreadSafeArenazSamplerTest, SamplingCorrectness) { - SetThreadSafeArenazEnabled(true); - for (int p = 0; p <= 15; ++p) { - SetThreadSafeArenazSampleParameter(1 << p); - SetThreadSafeArenazGlobalNextSample(1 << p); - const int kTrials = 1000 << p; - std::vector hv; - for (int i = 0; i < kTrials; ++i) { - ThreadSafeArenaStatsHandle h = Sample(); - if (h.MutableStats() != nullptr) hv.push_back(std::move(h)); - } - // Ideally samples << p should be very close to kTrials. But we keep a - // factor of two guard band. - EXPECT_GE(hv.size() << p, kTrials / 2); - EXPECT_LE(hv.size() << p, 2 * kTrials); - } +TEST(ThreadSafeArenaStatsTest, RecordResetSlow) { + ThreadSafeArenaStats info; + MutexLock l(&info.init_mu); + info.PrepareForSampling(); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_allocated.load(), 0); + RecordAllocateSlow(&info, /*requested=*/100, /*allocated=*/128, /*wasted=*/0); + EXPECT_EQ(info.num_resets.load(), 0); + EXPECT_EQ(info.bytes_allocated.load(), 128); + RecordResetSlow(&info); + EXPECT_EQ(info.num_resets.load(), 1); + EXPECT_EQ(info.bytes_allocated.load(), 0); } TEST(ThreadSafeArenazSamplerTest, SmallSampleParameter) { SetThreadSafeArenazEnabled(true); SetThreadSafeArenazSampleParameter(100); - constexpr int64_t kTestStride = 0; for (int i = 0; i < 1000; ++i) { - SamplingState sampling_state = {kTestStride, kTestStride}; - ThreadSafeArenaStats* sample = SampleSlow(sampling_state); - EXPECT_GT(sampling_state.next_sample, 0); + int64_t next_sample = 0; + ThreadSafeArenaStats* sample = SampleSlow(&next_sample); + EXPECT_GT(next_sample, 0); EXPECT_NE(sample, nullptr); UnsampleSlow(sample); } @@ -240,12 +156,11 @@ TEST(ThreadSafeArenazSamplerTest, SmallSampleParameter) { TEST(ThreadSafeArenazSamplerTest, LargeSampleParameter) { SetThreadSafeArenazEnabled(true); SetThreadSafeArenazSampleParameter(std::numeric_limits::max()); - constexpr int64_t kTestStride = 0; for (int i = 0; i < 1000; ++i) { - SamplingState sampling_state = {kTestStride, kTestStride}; - ThreadSafeArenaStats* sample = SampleSlow(sampling_state); - EXPECT_GT(sampling_state.next_sample, 0); + int64_t next_sample = 0; + ThreadSafeArenaStats* sample = SampleSlow(&next_sample); + EXPECT_GT(next_sample, 0); EXPECT_NE(sample, nullptr); UnsampleSlow(sample); } @@ -272,19 +187,14 @@ TEST(ThreadSafeArenazSamplerTest, Sample) { TEST(ThreadSafeArenazSamplerTest, Handle) { auto& sampler = GlobalThreadSafeArenazSampler(); - constexpr int64_t kTestStride = 17; - ThreadSafeArenaStatsHandle h(sampler.Register(kTestStride)); + ThreadSafeArenaStatsHandle h(sampler.Register()); auto* info = ThreadSafeArenaStatsHandlePeer::GetInfo(&h); - info->block_histogram[0].bytes_allocated.store(0x12345678, - std::memory_order_relaxed); + info->bytes_allocated.store(0x12345678, std::memory_order_relaxed); bool found = false; sampler.Iterate([&](const ThreadSafeArenaStats& h) { if (&h == info) { - EXPECT_EQ( - h.block_histogram[0].bytes_allocated.load(std::memory_order_relaxed), - 0x12345678); - EXPECT_EQ(h.weight, kTestStride); + EXPECT_EQ(h.bytes_allocated.load(), 0x12345678); found = true; } }); @@ -296,8 +206,7 @@ TEST(ThreadSafeArenazSamplerTest, Handle) { if (&h == info) { // this will only happen if some other thread has resurrected the info // the old handle was using. - if (h.block_histogram[0].bytes_allocated.load( - std::memory_order_relaxed) == 0x12345678) { + if (h.bytes_allocated.load() == 0x12345678) { found = true; } } @@ -307,13 +216,12 @@ TEST(ThreadSafeArenazSamplerTest, Handle) { TEST(ThreadSafeArenazSamplerTest, Registration) { ThreadSafeArenazSampler sampler; - constexpr int64_t kTestStride = 100; - auto* info1 = Register(&sampler, 1, kTestStride); + auto* info1 = Register(&sampler, 1); EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1)); - auto* info2 = Register(&sampler, 2, kTestStride); + auto* info2 = Register(&sampler, 2); EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1, 2)); - info1->block_histogram[0].bytes_allocated.store(3, std::memory_order_relaxed); + info1->bytes_allocated.store(3); EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(3, 2)); sampler.Unregister(info1); @@ -323,20 +231,19 @@ TEST(ThreadSafeArenazSamplerTest, Registration) { TEST(ThreadSafeArenazSamplerTest, Unregistration) { ThreadSafeArenazSampler sampler; std::vector infos; - constexpr int64_t kTestStride = 200; for (size_t i = 0; i < 3; ++i) { - infos.push_back(Register(&sampler, i + 1, kTestStride)); + infos.push_back(Register(&sampler, i)); } - EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1, 2, 3)); + EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(0, 1, 2)); sampler.Unregister(infos[1]); - EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1, 3)); + EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(0, 2)); - infos.push_back(Register(&sampler, 3, kTestStride)); - infos.push_back(Register(&sampler, 4, kTestStride)); - EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1, 3, 3, 4)); + infos.push_back(Register(&sampler, 3)); + infos.push_back(Register(&sampler, 4)); + EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(0, 2, 3, 4)); sampler.Unregister(infos[3]); - EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(1, 3, 4)); + EXPECT_THAT(GetBytesAllocated(&sampler), UnorderedElementsAre(0, 2, 4)); sampler.Unregister(infos[0]); sampler.Unregister(infos[2]); @@ -350,19 +257,18 @@ TEST(ThreadSafeArenazSamplerTest, MultiThreaded) { ThreadPool pool(10); for (int i = 0; i < 10; ++i) { - const int64_t sampling_stride = 11 + i % 3; - pool.Schedule([&sampler, &stop, sampling_stride]() { + pool.Schedule([&sampler, &stop]() { std::random_device rd; std::mt19937 gen(rd()); std::vector infoz; while (!stop.HasBeenNotified()) { if (infoz.empty()) { - infoz.push_back(sampler.Register(sampling_stride)); + infoz.push_back(sampler.Register()); } switch (std::uniform_int_distribution<>(0, 1)(gen)) { case 0: { - infoz.push_back(sampler.Register(sampling_stride)); + infoz.push_back(sampler.Register()); break; } case 1: { @@ -371,7 +277,6 @@ TEST(ThreadSafeArenazSamplerTest, MultiThreaded) { ThreadSafeArenaStats* info = infoz[p]; infoz[p] = infoz.back(); infoz.pop_back(); - EXPECT_EQ(info->weight, sampling_stride); sampler.Unregister(info); break; } @@ -387,10 +292,9 @@ TEST(ThreadSafeArenazSamplerTest, MultiThreaded) { TEST(ThreadSafeArenazSamplerTest, Callback) { ThreadSafeArenazSampler sampler; - constexpr int64_t kTestStride = 203; - auto* info1 = Register(&sampler, 1, kTestStride); - auto* info2 = Register(&sampler, 2, kTestStride); + auto* info1 = Register(&sampler, 1); + auto* info2 = Register(&sampler, 2); static const ThreadSafeArenaStats* expected; @@ -411,33 +315,6 @@ TEST(ThreadSafeArenazSamplerTest, Callback) { sampler.Unregister(info2); } -TEST(ThreadSafeArenazSamplerTest, InitialBlockReportsZeroUsedAndWasted) { - SetThreadSafeArenazEnabled(true); - // Setting 1 as the parameter value means one in every two arenas would be - // sampled, on average. - int32_t oldparam = ThreadSafeArenazSampleParameter(); - SetThreadSafeArenazSampleParameter(1); - SetThreadSafeArenazGlobalNextSample(0); - constexpr int kSize = 571; - int count_found_allocation = 0; - auto& sampler = GlobalThreadSafeArenazSampler(); - for (int i = 0; i < 10; ++i) { - char block[kSize]; - google::protobuf::Arena arena(/*initial_block=*/block, /*initial_block_size=*/kSize); - sampler.Iterate([&](const ThreadSafeArenaStats& h) { - const auto& histbin = - h.block_histogram[ThreadSafeArenaStats::FindBin(kSize)]; - if (histbin.bytes_allocated.load(std::memory_order_relaxed) == kSize) { - count_found_allocation++; - EXPECT_EQ(histbin.bytes_used, 0); - EXPECT_EQ(histbin.bytes_wasted, 0); - } - }); - } - EXPECT_GT(count_found_allocation, 0); - SetThreadSafeArenazSampleParameter(oldparam); -} - class ThreadSafeArenazSamplerTestThread : public Thread { protected: void Run() override { @@ -455,7 +332,7 @@ class ThreadSafeArenazSamplerTestThread : public Thread { public: ThreadSafeArenazSamplerTestThread(const thread::Options& options, - absl::string_view name, + StringPiece name, google::protobuf::Arena* arena, absl::Barrier* barrier) : Thread(options, name), arena_(arena), barrier_(barrier) {} @@ -469,7 +346,6 @@ TEST(ThreadSafeArenazSamplerTest, MultiThread) { SetThreadSafeArenazEnabled(true); // Setting 1 as the parameter value means one in every two arenas would be // sampled, on average. - int32_t oldparam = ThreadSafeArenazSampleParameter(); SetThreadSafeArenazSampleParameter(1); SetThreadSafeArenazGlobalNextSample(0); auto& sampler = GlobalThreadSafeArenazSampler(); @@ -483,7 +359,7 @@ TEST(ThreadSafeArenazSamplerTest, MultiThread) { std::vector> threads; for (int i = 0; i < kNumThreads; i++) { auto t = std::make_unique( - options, absl::StrCat("thread", i), &arena, barrier); + options, StrCat("thread", i), &arena, barrier); t->Start(); threads.push_back(std::move(t)); } @@ -497,95 +373,6 @@ TEST(ThreadSafeArenazSamplerTest, MultiThread) { } } EXPECT_GT(count, 0); - SetThreadSafeArenazSampleParameter(oldparam); -} - -class SampleFirstArenaThread : public Thread { - protected: - void Run() override { - google::protobuf::Arena arena; - google::protobuf::ArenaSafeUniquePtr< - protobuf_test_messages::proto2::TestAllTypesProto2> - message = google::protobuf::MakeArenaSafeUnique< - protobuf_test_messages::proto2::TestAllTypesProto2>(&arena); - GOOGLE_CHECK(message != nullptr); - arena_created_.Notify(); - samples_counted_.WaitForNotification(); - } - - public: - explicit SampleFirstArenaThread(const thread::Options& options) - : Thread(options, "SampleFirstArenaThread") {} - - absl::Notification arena_created_; - absl::Notification samples_counted_; -}; - -// Test that the first arena created on a thread may and may not be chosen for -// sampling. -TEST(ThreadSafeArenazSamplerTest, SampleFirstArena) { - SetThreadSafeArenazEnabled(true); - auto& sampler = GlobalThreadSafeArenazSampler(); - - enum class SampleResult { - kSampled, - kUnsampled, - kSpoiled, - }; - - auto count_samples = [&]() { - int count = 0; - sampler.Iterate([&](const ThreadSafeArenaStats& h) { ++count; }); - return count; - }; - - auto run_sample_experiment = [&]() { - int before = count_samples(); - thread::Options options; - options.set_joinable(true); - SampleFirstArenaThread t(options); - t.Start(); - t.arena_created_.WaitForNotification(); - int during = count_samples(); - t.samples_counted_.Notify(); - t.Join(); - int after = count_samples(); - - // If we didn't get back where we were, some other thread may have - // created an arena and produced an invalid experiment run. - if (before != after) return SampleResult::kSpoiled; - - switch (during - before) { - case 1: - return SampleResult::kSampled; - case 0: - return SampleResult::kUnsampled; - default: - return SampleResult::kSpoiled; - } - }; - - constexpr int kTrials = 10000; - bool sampled = false; - bool unsampled = false; - for (int i = 0; i < kTrials; ++i) { - switch (run_sample_experiment()) { - case SampleResult::kSampled: - sampled = true; - break; - case SampleResult::kUnsampled: - unsampled = true; - break; - default: - break; - } - - // This is the success criteria for the entire test. At some point - // we sampled the first arena and at some point we did not. - if (sampled && unsampled) return; - } - EXPECT_TRUE(sampled); - EXPECT_TRUE(unsampled); } #endif // defined(PROTOBUF_ARENAZ_SAMPLE) diff --git a/libs/protobuf/src/google/protobuf/compiler/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/BUILD.bazel deleted file mode 100644 index af05903..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/BUILD.bazel +++ /dev/null @@ -1,375 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") -load( - "@rules_pkg//:mappings.bzl", - "pkg_attributes", - "pkg_files", - "strip_prefix", -) -load("@rules_proto//proto:defs.bzl", "proto_library") -load("//build_defs:arch_tests.bzl", "aarch64_test", "x86_64_test") -load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS") - -proto_library( - name = "plugin_proto", - srcs = ["plugin.proto"], - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - ], - deps = ["//:descriptor_proto"], -) - -cc_library( - name = "importer", - srcs = [ - "importer.cc", - "parser.cc", - ], - hdrs = [ - "importer.h", - "parser.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler", - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "code_generator", - srcs = [ - "code_generator.cc", - "plugin.cc", - "plugin.pb.cc", - ], - hdrs = [ - "code_generator.h", - "plugin.h", - "plugin.pb.h", - "scc.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler", - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "command_line_interface", - srcs = [ - "command_line_interface.cc", - "subprocess.cc", - "zip_writer.cc", - ], - hdrs = [ - "command_line_interface.h", - "subprocess.h", - "zip_writer.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler", - visibility = ["//visibility:public"], - deps = [ - ":code_generator", - ":importer", - "//src/google/protobuf:protobuf_nowkt", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - ], -) - -cc_library( - name = "protoc_lib_nowkt", - srcs = [ - "main.cc", - ], - copts = COPTS, - deps = [ - ":code_generator", - ":command_line_interface", - ":importer", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler/cpp", - "//src/google/protobuf/compiler/csharp", - "//src/google/protobuf/compiler/java", - "//src/google/protobuf/compiler/objectivec", - "//src/google/protobuf/compiler/php", - "//src/google/protobuf/compiler/python", - "//src/google/protobuf/compiler/ruby", - ], -) - -cc_binary( - name = "protoc_nowkt", - copts = COPTS, - linkopts = LINK_OPTS + PROTOC_LINK_OPTS, - visibility = [ - "//src/google/protobuf:__pkg__", - ], - deps = [":protoc_lib_nowkt"], -) - -cc_library( - name = "protoc_lib", - copts = COPTS, - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - ], - deps = [ - ":protoc_lib_nowkt", - "//:protobuf", - ], -) - -# Note: this is an alias for now. In the future, this rule will become the -# cc_binary for protoc, and //:protoc will become an alias. -alias( - name = "protoc", - actual = "//:protoc", - visibility = ["//visibility:public"], -) - -# Test that the protoc binary is built for the correct architecture. -aarch64_test( - name = "protoc_aarch64_test", - bazel_binaries = ["//:protoc"], -) - -x86_64_test( - name = "protoc_x86_64_test", - bazel_binaries = ["//:protoc"], -) - -################################################################################ -# Tests and support libraries -################################################################################ - -cc_library( - name = "annotation_test_util", - testonly = 1, - srcs = ["annotation_test_util.cc"], - hdrs = ["annotation_test_util.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//visibility:public"], - deps = [ - ":code_generator", - ":command_line_interface", - "//:protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/testing", - ], -) - -################################################################################ -# Tests -################################################################################ - -filegroup( - name = "plugin_proto_srcs", - testonly = 1, - srcs = [ - "plugin.pb.cc", - "plugin.pb.h", - "plugin.proto", - ], - visibility = [ - "//src/google/protobuf/compiler/cpp:__pkg__", - ], -) - -exports_files( - srcs = ["plugin.proto"], - visibility = ["//:__pkg__"], -) - -cc_library( - name = "mock_code_generator", - testonly = 1, - srcs = ["mock_code_generator.cc"], - hdrs = ["mock_code_generator.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//pkg:__pkg__"], - deps = [ - ":code_generator", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - ], -) - -cc_binary( - name = "test_plugin", - testonly = 1, - srcs = ["test_plugin.cc"], - copts = COPTS, - deps = [ - ":code_generator", - ":mock_code_generator", - ], -) - -cc_test( - name = "command_line_interface_unittest", - srcs = ["command_line_interface_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated", - "-Wno-deprecated-declarations", - ], - }) + [ - # Note: This only works on Windows with symlinks and runfiles enabled. - "-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH=\\\"$(rootpath :test_plugin)\\\"", - ], - data = [ - ":test_plugin", - "//:test_proto_srcs", - "//src/google/protobuf:testdata", - ], - deps = [ - ":code_generator", - ":command_line_interface", - ":mock_code_generator", - "//:protobuf", - "//src/google/protobuf/compiler/cpp:names", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "importer_unittest", - srcs = ["importer_unittest.cc"], - copts = COPTS, - deps = [ - ":importer", - "//:protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "parser_unittest", - srcs = ["parser_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated", - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":importer", - "//:protobuf", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Generates protoc release artifacts. -################################################################################ - -genrule( - name = "protoc_readme", - outs = ["readme.txt"], - cmd = """ -echo "Protocol Buffers - Google's data interchange format -Copyright 2008 Google Inc. -https://developers.google.com/protocol-buffers/ -This package contains a precompiled binary version of the protocol buffer -compiler (protoc). This binary is intended for users who want to use Protocol -Buffers in languages other than C++ but do not want to compile protoc -themselves. To install, simply place this binary somewhere in your PATH. -If you intend to use the included well known types then don't forget to -copy the contents of the 'include' directory somewhere as well, for example -into '/usr/local/include/'. -Please refer to our official github site for more installation instructions: - https://github.com/protocolbuffers/protobuf" > $@ - """, - visibility = ["//:__pkg__"], -) - -pkg_files( - name = "compiler_plugin_protos_files", - srcs = ["plugin.proto"], - prefix = "include/google/protobuf/compiler", - visibility = ["//pkg:__pkg__"], -) - -pkg_files( - name = "protoc_files", - srcs = [":protoc"], - attributes = pkg_attributes(mode = "0555"), - prefix = "bin/", - visibility = ["//:__pkg__"], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]) + [ - "//src/google/protobuf/compiler/cpp:test_srcs", - "//src/google/protobuf/compiler/csharp:test_srcs", - "//src/google/protobuf/compiler/java:test_srcs", - "//src/google/protobuf/compiler/objectivec:test_srcs", - "//src/google/protobuf/compiler/php:test_srcs", - "//src/google/protobuf/compiler/python:test_srcs", - "//src/google/protobuf/compiler/ruby:test_srcs", - ], - visibility = ["//pkg:__pkg__"], -) - -filegroup( - name = "test_plugin_srcs", - srcs = ["test_plugin.cc"], - visibility = ["//pkg:__pkg__"], -) - -filegroup( - name = "test_proto_srcs", - srcs = [ - "//src/google/protobuf/compiler/cpp:test_proto_srcs", - ], - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.cc b/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.cc index 76d39ab..f0815c5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.cc +++ b/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.cc @@ -28,20 +28,20 @@ // (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/compiler/annotation_test_util.h" +#include #include #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.h b/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.h index b8356c2..b7c6ddd 100644 --- a/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.h +++ b/libs/protobuf/src/google/protobuf/compiler/annotation_test_util.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_COMPILER_ANNOTATION_TEST_UTIL_H__ -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include #include // Utilities that assist in writing tests for generator annotations. diff --git a/libs/protobuf/src/google/protobuf/compiler/code_generator.cc b/libs/protobuf/src/google/protobuf/compiler/code_generator.cc index 3f48e37..dc9d450 100644 --- a/libs/protobuf/src/google/protobuf/compiler/code_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/code_generator.cc @@ -32,14 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/code_generator.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/compiler/plugin.pb.h" -#include "google/protobuf/descriptor.h" -#include "absl/strings/str_split.h" -#include "absl/strings/strip.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -108,7 +107,7 @@ void GeneratorContext::GetCompilerVersion(Version* version) const { void ParseGeneratorParameter( const std::string& text, std::vector >* output) { - std::vector parts = absl::StrSplit(text, ",", absl::SkipEmpty()); + std::vector parts = Split(text, ",", true); for (int i = 0; i < parts.size(); i++) { std::string::size_type equals_pos = parts[i].find_first_of('='); @@ -126,10 +125,10 @@ void ParseGeneratorParameter( // Strips ".proto" or ".protodevel" from the end of a filename. std::string StripProto(const std::string& filename) { - if (absl::EndsWith(filename, ".protodevel")) { - return std::string(absl::StripSuffix(filename, ".protodevel")); + if (HasSuffixString(filename, ".protodevel")) { + return StripSuffixString(filename, ".protodevel"); } else { - return std::string(absl::StripSuffix(filename, ".proto")); + return StripSuffixString(filename, ".proto"); } } diff --git a/libs/protobuf/src/google/protobuf/compiler/code_generator.h b/libs/protobuf/src/google/protobuf/compiler/code_generator.h index 55b510a..9c0b115 100644 --- a/libs/protobuf/src/google/protobuf/compiler/code_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/code_generator.h @@ -41,11 +41,10 @@ #include #include #include - -#include "google/protobuf/port.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -70,9 +69,7 @@ class GeneratorContext; // be registered with CommandLineInterface to support various languages. class PROTOC_EXPORT CodeGenerator { public: - CodeGenerator() {} - CodeGenerator(const CodeGenerator&) = delete; - CodeGenerator& operator=(const CodeGenerator&) = delete; + inline CodeGenerator() {} virtual ~CodeGenerator(); // Generates code for the given proto file, generating one or more files in @@ -123,6 +120,9 @@ class PROTOC_EXPORT CodeGenerator { // version of the library. When protobufs does a api breaking change, the // method can be removed. virtual bool HasGenerateAll() const { return true; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); }; // CodeGenerators generate one or more files in a given directory. This @@ -131,10 +131,8 @@ class PROTOC_EXPORT CodeGenerator { // runs. class PROTOC_EXPORT GeneratorContext { public: - GeneratorContext() { + inline GeneratorContext() { } - GeneratorContext(const GeneratorContext&) = delete; - GeneratorContext& operator=(const GeneratorContext&) = delete; virtual ~GeneratorContext(); // Opens the given file, truncating it if it exists, and returns a @@ -179,6 +177,9 @@ class PROTOC_EXPORT GeneratorContext { // this GeneratorContext. virtual void GetCompilerVersion(Version* version) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); }; // The type GeneratorContext was once called OutputDirectory. This typedef @@ -201,6 +202,6 @@ PROTOC_EXPORT std::string StripProto(const std::string& filename); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/command_line_interface.cc b/libs/protobuf/src/google/protobuf/compiler/command_line_interface.cc index 84e096a..5e9a2c4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/command_line_interface.cc +++ b/libs/protobuf/src/google/protobuf/compiler/command_line_interface.cc @@ -32,12 +32,11 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/command_line_interface.h" +#include -#include "google/protobuf/stubs/platform_macros.h" +#include #include -#include #include #ifdef major #undef major @@ -59,10 +58,6 @@ #include // For PATH_MAX #include -#include -#include -#include -#include #if defined(__APPLE__) #include @@ -70,29 +65,29 @@ #include #endif -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/compiler/subprocess.h" -#include "google/protobuf/compiler/plugin.pb.h" -#include "absl/strings/match.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/importer.h" -#include "google/protobuf/compiler/zip_writer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/text_format.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -179,7 +174,7 @@ bool TryCreateParentDirectory(const std::string& prefix, // Recursively create parent directories to the output file. // On Windows, both '/' and '\' are valid path separators. std::vector parts = - absl::StrSplit(filename, absl::ByAnyChar("/\\"), absl::SkipEmpty()); + Split(filename, "/\\", true); std::string path_so_far = prefix; for (int i = 0; i < parts.size() - 1; i++) { path_so_far += parts[i]; @@ -344,12 +339,9 @@ class CommandLineInterface::ErrorPrinter void AddErrorOrWarning(const std::string& filename, int line, int column, const std::string& message, const std::string& type, std::ostream& out) { + // Print full path when running under MSVS std::string dfile; - if ( -#ifndef PROTOBUF_OPENSOURCE - // Print full path when running under MSVS - format_ == CommandLineInterface::ERROR_FORMAT_MSVS && -#endif // !PROTOBUF_OPENSOURCE + if (format_ == CommandLineInterface::ERROR_FORMAT_MSVS && tree_ != nullptr && tree_->VirtualFileToDiskFile(filename, &dfile)) { out << dfile; } else { @@ -406,6 +398,7 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext { // Get name of all output files. void GetOutputFilenames(std::vector* output_filenames); + // implements GeneratorContext -------------------------------------- io::ZeroCopyOutputStream* Open(const std::string& filename) override; io::ZeroCopyOutputStream* OpenForAppend(const std::string& filename) override; @@ -822,7 +815,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { // Find the insertion point. std::string magic_string = - absl::Substitute("@@protoc_insertion_point($0)", insertion_point_); + strings::Substitute("@@protoc_insertion_point($0)", insertion_point_); std::string::size_type pos = target->find(magic_string); if (pos == std::string::npos) { @@ -871,7 +864,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { // Now copy in the data. std::string::size_type data_pos = 0; - char* target_ptr = &(*target)[pos]; + char* target_ptr = ::google::protobuf::string_as_array(target) + pos; while (data_pos < data_.size()) { // Copy indent. memcpy(target_ptr, indent_.data(), indent_.size()); @@ -888,7 +881,8 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { } UpdateMetadata(data_, pos, data_.size() + indent_size, indent_.size()); - GOOGLE_CHECK_EQ(target_ptr, &(*target)[pos] + data_.size() + indent_size); + GOOGLE_CHECK_EQ(target_ptr, + ::google::protobuf::string_as_array(target) + pos + data_.size() + indent_size); } } } @@ -969,7 +963,6 @@ PopulateSingleSimpleDescriptorDatabase(const std::string& descriptor_set_name); int CommandLineInterface::Run(int argc, const char* const argv[]) { Clear(); - switch (ParseArguments(argc, argv)) { case PARSE_ARGUMENT_DONE_AND_EXIT: return 0; @@ -1063,9 +1056,9 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { if (mode_ == MODE_COMPILE) { for (int i = 0; i < output_directives_.size(); i++) { std::string output_location = output_directives_[i].output_location; - if (!absl::EndsWith(output_location, ".zip") && - !absl::EndsWith(output_location, ".jar") && - !absl::EndsWith(output_location, ".srcjar")) { + if (!HasSuffixString(output_location, ".zip") && + !HasSuffixString(output_location, ".jar") && + !HasSuffixString(output_location, ".srcjar")) { AddTrailingSlash(&output_location); } @@ -1083,15 +1076,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { } } + // Write all output to disk. for (const auto& pair : output_directories) { const std::string& location = pair.first; GeneratorContextImpl* directory = pair.second.get(); - if (absl::EndsWith(location, "/")) { + if (HasSuffixString(location, "/")) { if (!directory->WriteAllToDisk(location)) { return 1; } } else { - if (absl::EndsWith(location, ".jar")) { + if (HasSuffixString(location, ".jar")) { directory->AddJarManifest(); } @@ -1157,6 +1151,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { // Do not add a default case. } } + return 0; } @@ -1281,7 +1276,6 @@ bool CommandLineInterface::ParseInputFiles( } parsed_files->push_back(parsed_file); - // Enforce --disallow_services. if (disallow_services_ && parsed_file->service_count() > 0) { std::cerr << parsed_file->name() @@ -1301,9 +1295,9 @@ bool CommandLineInterface::ParseInputFiles( direct_dependencies_.end()) { indirect_imports = true; std::cerr << parsed_file->name() << ": " - << absl::StrReplaceAll( - direct_dependencies_violation_msg_, - {{"%s", parsed_file->dependency(i)->name()}}) + << StringReplace(direct_dependencies_violation_msg_, "%s", + parsed_file->dependency(i)->name(), + true /* replace_all */) << std::endl; } } @@ -1685,7 +1679,8 @@ CommandLineInterface::InterpretArgument(const std::string& name, })) { case google::protobuf::io::win32::ExpandWildcardsResult::kSuccess: break; - case google::protobuf::io::win32::ExpandWildcardsResult::kErrorNoMatchingFile: + case google::protobuf::io::win32::ExpandWildcardsResult:: + kErrorNoMatchingFile: // Path does not exist, is not a file, or it's longer than MAX_PATH and // long path handling is disabled. std::cerr << "Invalid file name pattern or missing input file \"" @@ -1706,9 +1701,9 @@ CommandLineInterface::InterpretArgument(const std::string& name, // 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 parts = absl::StrSplit( - value, absl::ByAnyChar(CommandLineInterface::kPathSeparator), - absl::SkipEmpty()); + std::vector parts = Split( + value, CommandLineInterface::kPathSeparator, + true); for (int i = 0; i < parts.size(); i++) { std::string virtual_path; @@ -1762,7 +1757,7 @@ CommandLineInterface::InterpretArgument(const std::string& name, direct_dependencies_explicitly_set_ = true; std::vector direct = - absl::StrSplit(value, ":", absl::SkipEmpty()); + Split(value, ":", true); GOOGLE_DCHECK(direct_dependencies_.empty()); direct_dependencies_.insert(direct.begin(), direct.end()); @@ -1788,9 +1783,9 @@ CommandLineInterface::InterpretArgument(const std::string& name, return PARSE_ARGUMENT_FAIL; } - descriptor_set_in_names_ = absl::StrSplit( - value, absl::ByAnyChar(CommandLineInterface::kPathSeparator), - absl::SkipEmpty()); + descriptor_set_in_names_ = Split( + value, CommandLineInterface::kPathSeparator, + true); } else if (name == "-o" || name == "--descriptor_set_out") { if (!descriptor_set_out_name_.empty()) { @@ -1848,7 +1843,7 @@ CommandLineInterface::InterpretArgument(const std::string& name, if (!version_info_.empty()) { std::cout << version_info_ << std::endl; } - std::cout << "libprotoc " << internal::ProtocVersionString(PROTOBUF_VERSION) + std::cout << "libprotoc " << internal::VersionString(PROTOBUF_VERSION) << PROTOBUF_VERSION_SUFFIX << std::endl; return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler. @@ -1948,30 +1943,14 @@ CommandLineInterface::InterpretArgument(const std::string& name, } mode_ = MODE_PRINT; print_mode_ = PRINT_FREE_FIELDS; - } else if (name == "--enable_codegen_trace") { - // We use environment variables here so that subprocesses see this setting - // when we spawn them. - // - // Setting environment variables is more-or-less asking for a data race, - // because C got this wrong and did not mandate synchronization. - // In practice, this code path is "only" in the main thread of protoc, and - // it is common knowledge that touching setenv in a library is asking for - // life-ruining bugs *anyways*. As such, there is a reasonable probability - // that there isn't another thread kicking environment variables at this - // moment. - -#ifdef _WIN32 - ::_putenv(absl::StrCat(io::Printer::kProtocCodegenTrace, "=yes").c_str()); -#else - ::setenv(io::Printer::kProtocCodegenTrace.data(), "yes", 0); -#endif } else { // Some other flag. Look it up in the generators list. - const GeneratorInfo* generator_info = FindGeneratorByFlag(name); + const GeneratorInfo* generator_info = + FindOrNull(generators_by_flag_name_, name); if (generator_info == nullptr && - (plugin_prefix_.empty() || !absl::EndsWith(name, "_out"))) { + (plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) { // Check if it's a generator option flag. - generator_info = FindGeneratorByOption(name); + generator_info = FindOrNull(generators_by_option_name_, name); if (generator_info != nullptr) { std::string* parameters = &generator_parameters_[generator_info->flag_name]; @@ -1979,7 +1958,7 @@ CommandLineInterface::InterpretArgument(const std::string& name, parameters->append(","); } parameters->append(value); - } else if (absl::StartsWith(name, "--") && absl::EndsWith(name, "_opt")) { + } else if (HasPrefixString(name, "--") && HasSuffixString(name, "_opt")) { std::string* parameters = &plugin_parameters_[PluginName(plugin_prefix_, name)]; if (!parameters->empty()) { @@ -2090,10 +2069,7 @@ Parse PROTO_FILES and generate output based on the options given: defined in the given proto files. Groups share the same field number space with the parent message. Extension ranges are counted as - occupied fields numbers. - --enable_codegen_trace Enables tracing which parts of protoc are - responsible for what codegen output. Not supported - by all backends or on all platforms.)"; + occupied fields numbers.)"; if (!plugin_prefix_.empty()) { std::cout << R"( --plugin=EXECUTABLE Specifies a plugin executable to use. @@ -2106,15 +2082,16 @@ Parse PROTO_FILES and generate output based on the options given: the executable's own name differs.)"; } - for (const auto& kv : generators_by_flag_name_) { + for (GeneratorMap::iterator iter = generators_by_flag_name_.begin(); + iter != generators_by_flag_name_.end(); ++iter) { // FIXME(kenton): If the text is long enough it will wrap, which is ugly, // but fixing this nicely (e.g. splitting on spaces) is probably more // trouble than it's worth. std::cout << std::endl - << " " << kv.first << "=OUT_DIR " - << std::string(19 - kv.first.size(), + << " " << iter->first << "=OUT_DIR " + << std::string(19 - iter->first.size(), ' ') // Spaces for alignment. - << kv.second.help_text; + << iter->second.help_text; } std::cout << R"( @ Read options and filenames from file. If a @@ -2146,8 +2123,7 @@ bool CommandLineInterface::EnforceProto3OptionalSupport( << codegen_name << " hasn't been updated to support optional fields in " "proto3. Please ask the owner of this code generator to " - "support proto3 optional." - << std::endl; + "support proto3 optional."; return false; } } @@ -2163,8 +2139,8 @@ bool CommandLineInterface::GenerateOutput( std::string error; if (output_directive.generator == nullptr) { // This is a plugin. - GOOGLE_CHECK(absl::StartsWith(output_directive.name, "--") && - absl::EndsWith(output_directive.name, "_out")) + GOOGLE_CHECK(HasPrefixString(output_directive.name, "--") && + HasSuffixString(output_directive.name, "_out")) << "Bad name for plugin generator: " << output_directive.name; std::string plugin_name = PluginName(plugin_prefix_, output_directive.name); @@ -2320,7 +2296,7 @@ bool CommandLineInterface::GeneratePluginOutput( std::string communicate_error; if (!subprocess.Communicate(request, &response, &communicate_error)) { - *error = absl::Substitute("$0: $1", plugin_name, communicate_error); + *error = strings::Substitute("$0: $1", plugin_name, communicate_error); return false; } @@ -2347,7 +2323,7 @@ bool CommandLineInterface::GeneratePluginOutput( current_output.reset(); current_output.reset(generator_context->Open(output_file.name())); } else if (current_output == nullptr) { - *error = absl::Substitute( + *error = strings::Substitute( "$0: First file chunk returned by plugin did not specify a file " "name.", plugin_name); @@ -2530,20 +2506,6 @@ void CommandLineInterface::GetTransitiveDependencies( } } -const CommandLineInterface::GeneratorInfo* -CommandLineInterface::FindGeneratorByFlag(const std::string& name) const { - auto it = generators_by_flag_name_.find(name); - if (it == generators_by_flag_name_.end()) return nullptr; - return &it->second; -} - -const CommandLineInterface::GeneratorInfo* -CommandLineInterface::FindGeneratorByOption(const std::string& option) const { - auto it = generators_by_option_name_.find(option); - if (it == generators_by_option_name_.end()) return nullptr; - return &it->second; -} - namespace { // Utility function for PrintFreeFieldNumbers. @@ -2615,7 +2577,7 @@ void GatherOccupiedFieldRanges( void FormatFreeFieldNumbers(const std::string& name, const std::set& ranges) { std::string output; - absl::StrAppendFormat(&output, "%-35s free:", name.c_str()); + StringAppendF(&output, "%-35s free:", name.c_str()); int next_free_number = 1; for (std::set::const_iterator i = ranges.begin(); i != ranges.end(); ++i) { @@ -2626,17 +2588,17 @@ void FormatFreeFieldNumbers(const std::string& name, if (next_free_number < i->first) { if (next_free_number + 1 == i->first) { // Singleton - absl::StrAppendFormat(&output, " %d", next_free_number); + StringAppendF(&output, " %d", next_free_number); } else { // Range - absl::StrAppendFormat(&output, " %d-%d", next_free_number, + StringAppendF(&output, " %d-%d", next_free_number, i->first - 1); } } next_free_number = i->second; } if (next_free_number <= FieldDescriptor::kMaxNumber) { - absl::StrAppendFormat(&output, " %d-INF", next_free_number); + StringAppendF(&output, " %d-INF", next_free_number); } std::cout << output << std::endl; } diff --git a/libs/protobuf/src/google/protobuf/compiler/command_line_interface.h b/libs/protobuf/src/google/protobuf/compiler/command_line_interface.h index 6965e1a..e842550 100644 --- a/libs/protobuf/src/google/protobuf/compiler/command_line_interface.h +++ b/libs/protobuf/src/google/protobuf/compiler/command_line_interface.h @@ -39,7 +39,6 @@ #define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ #include -#include #include #include #include @@ -49,11 +48,10 @@ #include #include -#include "absl/strings/string_view.h" -#include "google/protobuf/port.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -117,8 +115,6 @@ class PROTOC_EXPORT CommandLineInterface { static const char* const kPathSeparator; CommandLineInterface(); - CommandLineInterface(const CommandLineInterface&) = delete; - CommandLineInterface& operator=(const CommandLineInterface&) = delete; ~CommandLineInterface(); // Register a code generator for a language. @@ -356,11 +352,7 @@ class PROTOC_EXPORT CommandLineInterface { CodeGenerator* generator; std::string help_text; }; - - const GeneratorInfo* FindGeneratorByFlag(const std::string& name) const; - const GeneratorInfo* FindGeneratorByOption(const std::string& option) const; - - using GeneratorMap = std::map; + typedef std::map GeneratorMap; GeneratorMap generators_by_flag_name_; GeneratorMap generators_by_option_name_; // A map from generator names to the parameters specified using the option @@ -406,7 +398,7 @@ class PROTOC_EXPORT CommandLineInterface { // True if we should treat warnings as errors that fail the compilation. bool fatal_warnings_ = false; - std::vector> + std::vector > proto_path_; // Search path for proto files. std::vector input_files_; // Names of the input proto files. @@ -459,12 +451,14 @@ class PROTOC_EXPORT CommandLineInterface { // When using --encode, this will be passed to SetSerializationDeterministic. bool deterministic_output_ = false; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); }; } // namespace compiler } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc index 4009b9e..f48135e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -38,8 +38,6 @@ #include -#include "absl/strings/str_format.h" - #ifndef _MSC_VER #include #endif @@ -47,34 +45,31 @@ #include #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/any.pb.h" -#include "google/protobuf/test_util2.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/status/status.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/compiler/mock_code_generator.h" -#include "google/protobuf/compiler/subprocess.h" -#include "google/protobuf/compiler/cpp/names.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -324,7 +319,7 @@ void CommandLineInterfaceTest::TearDown() { } void CommandLineInterfaceTest::Run(const std::string& command) { - RunWithArgs(absl::StrSplit(command, " ", absl::SkipEmpty())); + RunWithArgs(Split(command, " ", true)); } void CommandLineInterfaceTest::RunWithArgs(std::vector args) { @@ -354,7 +349,7 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector args) { "test_plugin.exe", // Other Win32 (MSVC) "test_plugin", // Unix }; - for (int i = 0; i < ABSL_ARRAYSIZE(possible_paths); i++) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(possible_paths); i++) { if (access(possible_paths[i], F_OK) == 0) { plugin_path = possible_paths[i]; break; @@ -362,10 +357,9 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector args) { } #endif - if (plugin_path.empty() || !FileExists(plugin_path)) { + if (plugin_path.empty()) { GOOGLE_LOG(ERROR) - << "Plugin executable not found. Plugin tests are likely to fail." - << plugin_path; + << "Plugin executable not found. Plugin tests are likely to fail."; } else { args.push_back("--plugin=prefix-gen-plug=" + plugin_path); } @@ -373,8 +367,8 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector args) { std::unique_ptr argv(new const char*[args.size()]); - for (size_t i = 0; i < args.size(); i++) { - args[i] = absl::StrReplaceAll(args[i], {{"$tmpdir", temp_directory_}}); + for (int i = 0; i < args.size(); i++) { + args[i] = StringReplace(args[i], "$tmpdir", temp_directory_, true); argv[i] = args[i].c_str(); } @@ -411,7 +405,7 @@ void CommandLineInterfaceTest::CreateTempFile(const std::string& name, // Write file. std::string full_name = temp_directory_ + "/" + name; GOOGLE_CHECK_OK(File::SetContents( - full_name, absl::StrReplaceAll(contents, {{"$tmpdir", temp_directory_}}), + full_name, StringReplace(contents, "$tmpdir", temp_directory_, true), true)); } @@ -430,7 +424,7 @@ void CommandLineInterfaceTest::ExpectNoErrors() { void CommandLineInterfaceTest::ExpectErrorText( const std::string& expected_text) { EXPECT_NE(0, return_code_); - EXPECT_EQ(absl::StrReplaceAll(expected_text, {{"$tmpdir", temp_directory_}}), + EXPECT_EQ(StringReplace(expected_text, "$tmpdir", temp_directory_, true), error_text_); } @@ -543,7 +537,7 @@ void CommandLineInterfaceTest::ExpectFileContent(const std::string& filename, std::string file_contents; GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true)); - EXPECT_EQ(absl::StrReplaceAll(content, {{"$tmpdir", temp_directory_}}), + EXPECT_EQ(StringReplace(content, "$tmpdir", temp_directory_, true), file_contents); } @@ -795,7 +789,6 @@ 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; @@ -832,7 +825,7 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) { field->set_number(1); WriteDescriptorSet("baz_and_bat.bin", &file_descriptor_set); - Run(absl::Substitute( + Run(strings::Substitute( "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " "--descriptor_set_in=$0 foo.proto bar.proto", std::string("$tmpdir/foo_and_bar.bin") + @@ -848,7 +841,7 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) { ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", "bar.proto", "Bar"); - Run(absl::Substitute( + Run(strings::Substitute( "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " "--descriptor_set_in=$0 baz.proto bat.proto", std::string("$tmpdir/foo_and_bar.bin") + @@ -906,7 +899,7 @@ TEST_F(CommandLineInterfaceTest, field->set_number(1); WriteDescriptorSet("foo_and_baz.bin", &file_descriptor_set); - Run(absl::Substitute( + Run(strings::Substitute( "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " "--descriptor_set_in=$0 bar.proto", std::string("$tmpdir/foo_and_bar.bin") + @@ -1312,7 +1305,7 @@ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) { "}\n"); CreateTempFile("b/foo.proto", "this should not be parsed\n"); - Run(absl::Substitute( + Run(strings::Substitute( "protocol_compiler --test_out=$$tmpdir --proto_path=$0 foo.proto", std::string("$tmpdir/a") + CommandLineInterface::kPathSeparator + "$tmpdir/b")); @@ -2260,9 +2253,9 @@ TEST_F(CommandLineInterfaceTest, PluginReceivesCompilerVersion) { Run("protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto"); - ExpectErrorSubstring(absl::StrFormat("Saw compiler_version: %d %s", - GOOGLE_PROTOBUF_VERSION, - GOOGLE_PROTOBUF_VERSION_SUFFIX)); + ExpectErrorSubstring(StringPrintf("Saw compiler_version: %d %s", + GOOGLE_PROTOBUF_VERSION, + GOOGLE_PROTOBUF_VERSION_SUFFIX)); } TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) { @@ -2593,8 +2586,8 @@ class EncodeDecodeTest : public testing::TestWithParam { bool Run(const std::string& command, bool specify_proto_files = true) { std::vector args; args.push_back("protoc"); - for (absl::string_view split_piece : - absl::StrSplit(command, " ", absl::SkipEmpty())) { + for (StringPiece split_piece : + Split(command, " ", true)) { args.push_back(std::string(split_piece)); } if (specify_proto_files) { @@ -2603,7 +2596,7 @@ class EncodeDecodeTest : public testing::TestWithParam { args.push_back("--proto_path=" + TestUtil::TestSourceDir()); break; case DESCRIPTOR_SET_IN: - args.push_back(absl::StrCat("--descriptor_set_in=", + args.push_back(StrCat("--descriptor_set_in=", unittest_proto_descriptor_set_filename_)); break; default: @@ -2688,7 +2681,7 @@ class EncodeDecodeTest : public testing::TestWithParam { TEST_P(EncodeDecodeTest, Encode) { RedirectStdinFromFile(TestUtil::GetTestDataPath( - "third_party/protobuf/" + "net/proto2/internal/" "testdata/text_format_unittest_data_oneof_implemented.txt")); std::string args; if (GetParam() != DESCRIPTOR_SET_IN) { @@ -2697,18 +2690,18 @@ TEST_P(EncodeDecodeTest, Encode) { } EXPECT_TRUE(Run(args + " --encode=protobuf_unittest.TestAllTypes")); ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_message_oneof_implemented")); + "net/proto2/internal/testdata/golden_message_oneof_implemented")); ExpectStderrMatchesText(""); } TEST_P(EncodeDecodeTest, Decode) { RedirectStdinFromFile(TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_message_oneof_implemented")); + "net/proto2/internal/testdata/golden_message_oneof_implemented")); EXPECT_TRUE( Run(TestUtil::MaybeTranslatePath("net/proto2/internal/unittest.proto") + " --decode=protobuf_unittest.TestAllTypes")); ExpectStdoutMatchesTextFile(TestUtil::GetTestDataPath( - "third_party/protobuf/" + "net/proto2/internal/" "testdata/text_format_unittest_data_oneof_implemented.txt")); ExpectStderrMatchesText(""); } @@ -2757,7 +2750,7 @@ TEST_P(EncodeDecodeTest, ProtoParseError) { TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) { RedirectStdinFromFile(TestUtil::GetTestDataPath( - "third_party/protobuf/" + "net/proto2/internal/" "testdata/text_format_unittest_data_oneof_implemented.txt")); std::string args; if (GetParam() != DESCRIPTOR_SET_IN) { @@ -2767,13 +2760,13 @@ TEST_P(EncodeDecodeTest, EncodeDeterministicOutput) { EXPECT_TRUE(Run( args + " --encode=protobuf_unittest.TestAllTypes --deterministic_output")); ExpectStdoutMatchesBinaryFile(TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_message_oneof_implemented")); + "net/proto2/internal/testdata/golden_message_oneof_implemented")); ExpectStderrMatchesText(""); } TEST_P(EncodeDecodeTest, DecodeDeterministicOutput) { RedirectStdinFromFile(TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_message_oneof_implemented")); + "net/proto2/internal/testdata/golden_message_oneof_implemented")); EXPECT_FALSE( Run(TestUtil::MaybeTranslatePath("net/proto2/internal/unittest.proto") + " --decode=protobuf_unittest.TestAllTypes --deterministic_output")); @@ -2787,7 +2780,7 @@ INSTANTIATE_TEST_SUITE_P(FileDescriptorSetSource, EncodeDecodeTest, #endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN -#include "google/protobuf/port_undef.inc" +#include } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/cpp/BUILD.bazel deleted file mode 100644 index 7f0ef6a..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/BUILD.bazel +++ /dev/null @@ -1,260 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - C++ code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_proto//proto:defs.bzl", "proto_library") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "names", - hdrs = ["names.h"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/cpp", - visibility = ["//visibility:public"], - deps = [ - ":names_internal", - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf:protobuf_nowkt", - ], -) - -cc_library( - name = "names_internal", - hdrs = [ - "helpers.h", - "names.h", - "options.h", - ], - srcs = [ - "helpers.cc", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/cpp", - visibility = ["//pkg:__pkg__"], - deps = [ - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf:protobuf_nowkt", - ], -) - -cc_library( - name = "cpp", - srcs = [ - "enum.cc", - "enum_field.cc", - "extension.cc", - "field.cc", - "file.cc", - "generator.cc", - "map_field.cc", - "message.cc", - "message_field.cc", - "padding_optimizer.cc", - "parse_function_generator.cc", - "primitive_field.cc", - "service.cc", - "string_field.cc", - ], - hdrs = [ - "enum.h", - "enum_field.h", - "extension.h", - "field.h", - "file.h", - "generator.h", - "map_field.h", - "message.h", - "message_field.h", - "message_layout_helper.h", - "padding_optimizer.h", - "parse_function_generator.h", - "primitive_field.h", - "service.h", - "string_field.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/cpp", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":names_internal", - ":names", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/container:btree", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/container:layout", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/synchronization", - ], -) - -proto_library( - name = "test_bad_identifiers_proto", - testonly = 1, - srcs = ["test_bad_identifiers.proto"], - strip_import_prefix = "/src", -) - -cc_proto_library( - name = "test_bad_identifiers_cc_proto", - testonly = 1, - deps = [":test_bad_identifiers_proto"], -) - -proto_library( - name = "test_large_enum_value_proto", - testonly = 1, - srcs = ["test_large_enum_value.proto"], - strip_import_prefix = "/src", -) - -cc_proto_library( - name = "test_large_enum_value_cc_proto", - testonly = 1, - deps = [":test_large_enum_value_proto"], -) - -cc_library( - name = "unittest_lib", - hdrs = [ - "unittest.h", - "unittest.inc", - ], - strip_include_prefix = "/src", - visibility = ["//pkg:__pkg__"], -) - -cc_test( - name = "unittest", - srcs = ["unittest.cc"], - copts = COPTS, - data = [ - "//:test_proto_srcs", - "//src/google/protobuf:testdata", - ], - deps = [ - ":cpp", - ":test_bad_identifiers_cc_proto", - ":unittest_lib", - "//:protobuf", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "bootstrap_unittest", - srcs = ["bootstrap_unittest.cc"], - data = [ - "//:well_known_type_protos", - "//src/google/protobuf:descriptor_cc_srcs", - "//src/google/protobuf:descriptor_proto_srcs", - "//src/google/protobuf:testdata", - "//src/google/protobuf/compiler:plugin_proto_srcs", - ], - deps = [ - ":cpp", - "//:protobuf", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "message_size_unittest", - srcs = ["message_size_unittest.cc"], - deps = [ - "//:protobuf", - "//src/google/protobuf:cc_test_protos", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "metadata_test", - srcs = ["metadata_test.cc"], - deps = [ - ":cpp", - "//:protobuf", - "//src/google/protobuf/compiler:annotation_test_util", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "move_unittest", - srcs = ["move_unittest.cc"], - copts = COPTS, - deps = [ - "//:protobuf", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util", - "//src/google/protobuf/stubs:lite", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "plugin_unittest", - srcs = ["plugin_unittest.cc"], - deps = [ - ":cpp", - "//:protobuf", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/io", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) - -filegroup( - name = "test_proto_srcs", - srcs = [ - "test_bad_identifiers.proto", - "test_large_enum_value.proto", - ], - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc index 3ea5d73..2619e60 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc @@ -42,33 +42,29 @@ // "generate_descriptor_proto.sh" and add // descriptor.pb.{h,cc} to your changelist. -#include +#include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/cpp/generator.h" -#include "google/protobuf/compiler/importer.h" -#include "google/protobuf/test_util2.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/container/flat_hash_map.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { + namespace { -std::string FindWithDefault( - const absl::flat_hash_map& m, - const std::string& k, const std::string& v) { - auto it = m.find(k); - if (it == m.end()) return v; - return it->second; -} class MockErrorCollector : public MultiFileErrorCollector { public: @@ -80,7 +76,7 @@ class MockErrorCollector : public MultiFileErrorCollector { // implements ErrorCollector --------------------------------------- void AddError(const std::string& filename, int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, + strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, message); } }; @@ -99,6 +95,7 @@ class MockGeneratorContext : public GeneratorContext { File::GetContents(TestUtil::TestSourceDir() + "/" + physical_filename, &actual_contents, true)) << physical_filename; + CleanStringLineEndings(&actual_contents, false); #ifdef WRITE_FILES // Define to debug mismatched files. GOOGLE_CHECK_OK(File::SetContents("/tmp/expected.cc", expected_contents, @@ -138,8 +135,8 @@ const char* test_protos[][2] = { TEST(BootstrapTest, GeneratedFilesMatch) { // We need a mapping from the actual file to virtual and actual path // of the data to compare to. - absl::flat_hash_map vpath_map; - absl::flat_hash_map rpath_map; + std::map vpath_map; + std::map rpath_map; rpath_map["third_party/protobuf/test_messages_proto2"] = "net/proto2/z_generated_example/test_messages_proto2"; rpath_map["third_party/protobuf/test_messages_proto3"] = diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h b/libs/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h index 599b4ab..1716ab2 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h @@ -1,36 +1,6 @@ -// 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_COMPILER_CPP_CPP_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ -#include "google/protobuf/compiler/cpp/generator.h" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CPP_CPP_GENERATOR_H_ diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/enum.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/enum.cc index 940a169..8124369 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/enum.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/enum.cc @@ -32,47 +32,26 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/enum.h" +#include -#include #include #include -#include -#include -#include +#include -#include "google/protobuf/descriptor.h" -#include "absl/container/btree_map.h" -#include "absl/container/btree_set.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/names.h" +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { -namespace { -absl::flat_hash_map EnumVars( - const EnumDescriptor* enum_, const Options& options, - const EnumValueDescriptor* min, const EnumValueDescriptor* max) { - auto classname = ClassName(enum_, false); - return { - {"Enum", enum_->name()}, - {"Enum_", ResolveKeyword(enum_->name())}, - {"Msg_Enum", classname}, - {"::Msg_Enum", QualifiedClassName(enum_, options)}, - {"Msg_Enum_", - enum_->containing_type() == nullptr ? "" : absl::StrCat(classname, "_")}, - {"kMin", absl::StrCat(min->number())}, - {"kMax", absl::StrCat(max->number())}, - }; -} -// The ARRAYSIZE constant is the max enum value plus 1. If the max enum value -// is kint32max, ARRAYSIZE will overflow. In such cases we should omit the -// generation of the ARRAYSIZE constant. +namespace { +// The GOOGLE_ARRAYSIZE constant is the max enum value plus 1. If the max enum value +// is kint32max, GOOGLE_ARRAYSIZE will overflow. In such cases we should omit the +// generation of the GOOGLE_ARRAYSIZE constant. bool ShouldGenerateArraySize(const EnumDescriptor* descriptor) { int32_t max_value = descriptor->value(0)->number(); for (int i = 0; i < descriptor->value_count(); i++) { @@ -82,317 +61,251 @@ bool ShouldGenerateArraySize(const EnumDescriptor* descriptor) { } return max_value != std::numeric_limits::max(); } -} // namespace -EnumGenerator::ValueLimits EnumGenerator::ValueLimits::FromEnum( - const EnumDescriptor* descriptor) { - const EnumValueDescriptor* min_desc = descriptor->value(0); - const EnumValueDescriptor* max_desc = descriptor->value(0); - for (int i = 1; i < descriptor->value_count(); ++i) { - if (descriptor->value(i)->number() < min_desc->number()) { - min_desc = descriptor->value(i); - } - if (descriptor->value(i)->number() > max_desc->number()) { - max_desc = descriptor->value(i); - } +// Returns the number of unique numeric enum values. This is less than +// descriptor->value_count() when there are aliased values. +int CountUniqueValues(const EnumDescriptor* descriptor) { + std::set values; + for (int i = 0; i < descriptor->value_count(); ++i) { + values.insert(descriptor->value(i)->number()); } - - return EnumGenerator::ValueLimits{min_desc, max_desc}; + return values.size(); } +} // namespace + EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor, + const std::map& vars, const Options& options) - : enum_(descriptor), + : descriptor_(descriptor), + classname_(ClassName(descriptor, false)), options_(options), generate_array_size_(ShouldGenerateArraySize(descriptor)), - has_reflection_(HasDescriptorMethods(enum_->file(), options_)), - limits_(ValueLimits::FromEnum(enum_)) { - // The conditions here for what is "sparse" are not rigorously - // chosen. - size_t values_range = static_cast(limits_.max->number()) - - static_cast(limits_.min->number()); - size_t total_values = static_cast(enum_->value_count()); - should_cache_ = has_reflection_ && - (values_range < 16u || values_range < total_values * 2u); + variables_(vars) { + variables_["classname"] = classname_; + variables_["classtype"] = QualifiedClassName(descriptor_, options); + variables_["short_name"] = descriptor_->name(); + variables_["nested_name"] = descriptor_->name(); + variables_["resolved_name"] = ResolveKeyword(descriptor_->name()); + variables_["prefix"] = + (descriptor_->containing_type() == nullptr) ? "" : classname_ + "_"; } -void EnumGenerator::GenerateDefinition(io::Printer* p) { - auto v1 = p->WithVars(EnumVars(enum_, options_, limits_.min, limits_.max)); +EnumGenerator::~EnumGenerator() {} - auto v2 = p->WithVars({ - {"Msg_Enum_Enum_MIN", - absl::StrCat(p->LookupVar("Msg_Enum_"), enum_->name(), "_MIN"), enum_}, - {"Msg_Enum_Enum_MAX", - absl::StrCat(p->LookupVar("Msg_Enum_"), enum_->name(), "_MAX"), enum_}, - }); - p->Emit( - { - {"values", - [&] { - for (int i = 0; i < enum_->value_count(); ++i) { - const auto* value = enum_->value(i); - p->Emit( - { - { - "Msg_Enum_VALUE", - absl::StrCat(p->LookupVar("Msg_Enum_"), - EnumValueName(value)), - value, - }, - {"kNumber", Int32ToString(value->number())}, - {"DEPRECATED", value->options().deprecated() - ? "PROTOBUF_DEPRECATED_ENUM" - : ""}, - }, - R"cc( - $Msg_Enum_VALUE$$ DEPRECATED$ = $kNumber$, - )cc"); - } - }}, - // Only emit annotations for the $Msg_Enum$ used in the `enum` - // definition. - {"Msg_Enum_annotated", p->LookupVar("Msg_Enum"), enum_}, - {"open_enum_sentinels", - [&] { - if (enum_->is_closed()) { - return; - } +void EnumGenerator::GenerateDefinition(io::Printer* printer) { + Formatter format(printer, variables_); + format("enum ${1$$classname$$}$ : int {\n", descriptor_); + format.Indent(); - // For open enum semantics: generate min and max sentinel values - // equal to INT32_MIN and INT32_MAX - p->Emit({{"Msg_Enum_Msg_Enum_", - absl::StrCat(p->LookupVar("Msg_Enum"), "_", - p->LookupVar("Msg_Enum_"))}}, - R"cc( - $Msg_Enum_Msg_Enum_$INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), - $Msg_Enum_Msg_Enum_$INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), - )cc"); - }}, - }, - R"cc( - enum $Msg_Enum_annotated$ : int { - $values$, - $open_enum_sentinels$, - }; + const EnumValueDescriptor* min_value = descriptor_->value(0); + const EnumValueDescriptor* max_value = descriptor_->value(0); - $dllexport_decl $bool $Msg_Enum$_IsValid(int value); - constexpr $Msg_Enum$ $Msg_Enum_Enum_MIN$ = static_cast<$Msg_Enum$>($kMin$); - constexpr $Msg_Enum$ $Msg_Enum_Enum_MAX$ = static_cast<$Msg_Enum$>($kMax$); - )cc"); + for (int i = 0; i < descriptor_->value_count(); i++) { + auto format_value = format; + format_value.Set("name", EnumValueName(descriptor_->value(i))); + // In C++, an value of -2147483648 gets interpreted as the negative of + // 2147483648, and since 2147483648 can't fit in an integer, this produces a + // compiler warning. This works around that issue. + format_value.Set("number", Int32ToString(descriptor_->value(i)->number())); + format_value.Set("deprecation", + DeprecatedAttribute(options_, descriptor_->value(i))); + + if (i > 0) format_value(",\n"); + format_value("${1$$prefix$$name$$}$ $deprecation$= $number$", + descriptor_->value(i)); + + if (descriptor_->value(i)->number() < min_value->number()) { + min_value = descriptor_->value(i); + } + if (descriptor_->value(i)->number() > max_value->number()) { + max_value = descriptor_->value(i); + } + } + + if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { + // For new enum semantics: generate min and max sentinel values equal to + // INT32_MIN and INT32_MAX + if (descriptor_->value_count() > 0) format(",\n"); + format( + "$classname$_$prefix$INT_MIN_SENTINEL_DO_NOT_USE_ = " + "std::numeric_limits<$int32$>::min(),\n" + "$classname$_$prefix$INT_MAX_SENTINEL_DO_NOT_USE_ = " + "std::numeric_limits<$int32$>::max()"); + } + + format.Outdent(); + format("\n};\n"); + + format( + "$dllexport_decl $bool $classname$_IsValid(int value);\n" + "constexpr $classname$ ${1$$prefix$$short_name$_MIN$}$ = " + "$prefix$$2$;\n" + "constexpr $classname$ ${1$$prefix$$short_name$_MAX$}$ = " + "$prefix$$3$;\n", + descriptor_, EnumValueName(min_value), EnumValueName(max_value)); if (generate_array_size_) { - p->Emit( - {{"Msg_Enum_Enum_ARRAYSIZE", - absl::StrCat(p->LookupVar("Msg_Enum_"), enum_->name(), "_ARRAYSIZE"), - enum_}}, - R"cc( - constexpr int $Msg_Enum_Enum_ARRAYSIZE$ = $kMax$ + 1; - )cc"); + format( + "constexpr int ${1$$prefix$$short_name$_ARRAYSIZE$}$ = " + "$prefix$$short_name$_MAX + 1;\n\n", + descriptor_); } - if (has_reflection_) { - p->Emit(R"cc( - $dllexport_decl $const ::$proto_ns$::EnumDescriptor* - $Msg_Enum$_descriptor(); - )cc"); - } else { - p->Emit(R"cc( - const std::string& $Msg_Enum$_Name($Msg_Enum$ value); - )cc"); + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + "$dllexport_decl $const ::$proto_ns$::EnumDescriptor* " + "$classname$_descriptor();\n"); } - // There are three possible implementations of $Enum$_Name() and - // $Msg_Enum$_Parse(), depending on whether we are using a dense enum name - // cache or not, and whether or not we have reflection. Very little code is - // shared between the three, so it is split into three Emit() calls. - - // Can't use WithVars here, since callbacks can only be passed to Emit() - // directly. Because this includes $Enum$, it must be a callback. - auto write_assert = [&] { - p->Emit(R"cc( - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to $Enum$_Name()."); - )cc"); - }; - - if (should_cache_ || !has_reflection_) { - p->Emit({{"static_assert", write_assert}}, R"cc( - template - const std::string& $Msg_Enum$_Name(T value) { - $static_assert$; - return $Msg_Enum$_Name(static_cast<$Msg_Enum$>(value)); - } - )cc"); - if (should_cache_) { - // Using the NameOfEnum routine can be slow, so we create a small - // cache of pointers to the std::string objects that reflection - // stores internally. This cache is a simple contiguous array of - // pointers, so if the enum values are sparse, it's not worth it. - p->Emit(R"cc( - template <> - inline const std::string& $Msg_Enum$_Name($Msg_Enum$ value) { - return ::$proto_ns$::internal::NameOfDenseEnum<$Msg_Enum$_descriptor, - $kMin$, $kMax$>( - static_cast(value)); - } - )cc"); - } else { - p->Emit(R"cc( - const std::string& $Msg_Enum$_Name($Msg_Enum$ value); - )cc"); - } - } else { - p->Emit({{"static_assert", write_assert}}, R"cc( - template - const std::string& $Msg_Enum$_Name(T value) { - $static_assert$; - return ::$proto_ns$::internal::NameOfEnum($Msg_Enum$_descriptor(), value); - } - )cc"); + // The _Name and _Parse functions. The lite implementation is table-based, so + // we make sure to keep the tables hidden in the .cc file. + if (!HasDescriptorMethods(descriptor_->file(), options_)) { + format("const std::string& $classname$_Name($classname$ value);\n"); } - - if (has_reflection_) { - p->Emit(R"cc( - inline bool $Msg_Enum$_Parse(absl::string_view name, $Msg_Enum$* value) { - return ::$proto_ns$::internal::ParseNamedEnum<$Msg_Enum$>( - $Msg_Enum$_descriptor(), name, value); - } - )cc"); + // The _Name() function accepts the enum type itself but also any integral + // type. + format( + "template\n" + "inline const std::string& $classname$_Name(T enum_t_value) {\n" + " static_assert(::std::is_same::value ||\n" + " ::std::is_integral::value,\n" + " \"Incorrect type passed to function $classname$_Name.\");\n"); + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + " return ::$proto_ns$::internal::NameOfEnum(\n" + " $classname$_descriptor(), enum_t_value);\n"); } else { - p->Emit(R"cc( - bool $Msg_Enum$_Parse(absl::string_view name, $Msg_Enum$* value); - )cc"); + format( + " return $classname$_Name(static_cast<$classname$>(enum_t_value));\n"); + } + format("}\n"); + + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + "inline bool $classname$_Parse(\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* " + "value) " + "{\n" + " return ::$proto_ns$::internal::ParseNamedEnum<$classname$>(\n" + " $classname$_descriptor(), name, value);\n" + "}\n"); + } else { + format( + "bool $classname$_Parse(\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* " + "value);\n"); } } -void EnumGenerator::GenerateGetEnumDescriptorSpecializations(io::Printer* p) { - auto v = p->WithVars(EnumVars(enum_, options_, limits_.min, limits_.max)); - - p->Emit(R"cc( - template <> - struct is_proto_enum<$::Msg_Enum$> : std::true_type {}; - )cc"); - if (!has_reflection_) { - return; +void EnumGenerator::GenerateGetEnumDescriptorSpecializations( + io::Printer* printer) { + Formatter format(printer, variables_); + format( + "template <> struct is_proto_enum< $classtype$> : ::std::true_type " + "{};\n"); + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + "template <>\n" + "inline const EnumDescriptor* GetEnumDescriptor< $classtype$>() {\n" + " return $classtype$_descriptor();\n" + "}\n"); } - p->Emit(R"cc( - template <> - inline const EnumDescriptor* GetEnumDescriptor<$::Msg_Enum$>() { - return $::Msg_Enum$_descriptor(); - } - )cc"); } -void EnumGenerator::GenerateSymbolImports(io::Printer* p) const { - auto v = p->WithVars(EnumVars(enum_, options_, limits_.min, limits_.max)); +void EnumGenerator::GenerateSymbolImports(io::Printer* printer) const { + Formatter format(printer, variables_); + format("typedef $classname$ $resolved_name$;\n"); - p->Emit(R"cc( - using $Enum_$ = $Msg_Enum$; - )cc"); - - for (int j = 0; j < enum_->value_count(); ++j) { - const auto* value = enum_->value(j); - p->Emit( - { - {"VALUE", EnumValueName(enum_->value(j)), value}, - {"DEPRECATED", - value->options().deprecated() ? "PROTOBUF_DEPRECATED_ENUM" : ""}, - }, - R"cc( - $DEPRECATED $static constexpr $Enum_$ $VALUE$ = $Msg_Enum$_$VALUE$; - )cc"); + for (int j = 0; j < descriptor_->value_count(); j++) { + std::string deprecated_attr = + DeprecatedAttribute(options_, descriptor_->value(j)); + format( + "$1$static constexpr $resolved_name$ ${2$$3$$}$ =\n" + " $classname$_$3$;\n", + deprecated_attr, descriptor_->value(j), + EnumValueName(descriptor_->value(j))); } - p->Emit( - { - {"Enum_MIN", absl::StrCat(enum_->name(), "_MIN"), enum_}, - {"Enum_MAX", absl::StrCat(enum_->name(), "_MAX"), enum_}, - }, - R"cc( - static inline bool $Enum$_IsValid(int value) { - return $Msg_Enum$_IsValid(value); - } - static constexpr $Enum_$ $Enum_MIN$ = $Msg_Enum$_$Enum$_MIN; - static constexpr $Enum_$ $Enum_MAX$ = $Msg_Enum$_$Enum$_MAX; - )cc"); - + format( + "static inline bool $nested_name$_IsValid(int value) {\n" + " return $classname$_IsValid(value);\n" + "}\n" + "static constexpr $resolved_name$ ${1$$nested_name$_MIN$}$ =\n" + " $classname$_$nested_name$_MIN;\n" + "static constexpr $resolved_name$ ${1$$nested_name$_MAX$}$ =\n" + " $classname$_$nested_name$_MAX;\n", + descriptor_); if (generate_array_size_) { - p->Emit( - {{"Enum_ARRAYSIZE", absl::StrCat(enum_->name(), "_ARRAYSIZE"), enum_}}, - R"cc( - static constexpr int $Enum_ARRAYSIZE$ = $Msg_Enum$_$Enum$_ARRAYSIZE; - )cc"); + format( + "static constexpr int ${1$$nested_name$_ARRAYSIZE$}$ =\n" + " $classname$_$nested_name$_ARRAYSIZE;\n", + descriptor_); } - if (has_reflection_) { - p->Emit(R"cc( - static inline const ::$proto_ns$::EnumDescriptor* $Enum$_descriptor() { - return $Msg_Enum$_descriptor(); - } - )cc"); + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + "static inline const ::$proto_ns$::EnumDescriptor*\n" + "$nested_name$_descriptor() {\n" + " return $classname$_descriptor();\n" + "}\n"); } - p->Emit(R"cc( - template - static inline const std::string& $Enum$_Name(T value) { - return $Msg_Enum$_Name(value); - } - static inline bool $Enum$_Parse(absl::string_view name, $Enum_$* value) { - return $Msg_Enum$_Parse(name, value); - } - )cc"); + format( + "template\n" + "static inline const std::string& $nested_name$_Name(T enum_t_value) {\n" + " static_assert(::std::is_same::value ||\n" + " ::std::is_integral::value,\n" + " \"Incorrect type passed to function $nested_name$_Name.\");\n" + " return $classname$_Name(enum_t_value);\n" + "}\n"); + format( + "static inline bool " + "$nested_name$_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name,\n" + " $resolved_name$* value) {\n" + " return $classname$_Parse(name, value);\n" + "}\n"); } -void EnumGenerator::GenerateMethods(int idx, io::Printer* p) { - auto v = p->WithVars(EnumVars(enum_, options_, limits_.min, limits_.max)); - - if (has_reflection_) { - p->Emit({{"idx", idx}}, R"cc( - const ::$proto_ns$::EnumDescriptor* $Msg_Enum$_descriptor() { - ::$proto_ns$::internal::AssignDescriptors(&$desc_table$); - return $file_level_enum_descriptors$[$idx$]; - } - )cc"); +void EnumGenerator::GenerateMethods(int idx, io::Printer* printer) { + Formatter format(printer, variables_); + if (HasDescriptorMethods(descriptor_->file(), options_)) { + format( + "const ::$proto_ns$::EnumDescriptor* $classname$_descriptor() {\n" + " ::$proto_ns$::internal::AssignDescriptors(&$desc_table$);\n" + " return $file_level_enum_descriptors$[$1$];\n" + "}\n", + idx); } - p->Emit({{"cases", - [&] { - // Multiple values may have the same number. Make sure we only - // cover each number once by first constructing a set containing - // all valid numbers, then printing a case statement for each - // element. + format( + "bool $classname$_IsValid(int value) {\n" + " switch (value) {\n"); - std::vector numbers; - numbers.reserve(enum_->value_count()); - for (int i = 0; i < enum_->value_count(); ++i) { - numbers.push_back(enum_->value(i)->number()); - } - // Sort and deduplicate `numbers`. - absl::c_sort(numbers); - numbers.erase(std::unique(numbers.begin(), numbers.end()), - numbers.end()); + // Multiple values may have the same number. Make sure we only cover + // each number once by first constructing a set containing all valid + // numbers, then printing a case statement for each element. - for (int n : numbers) { - p->Emit({{"n", n}}, R"cc( - case $n$: - )cc"); - } - }}}, - R"( - bool $Msg_Enum$_IsValid(int value) { - switch (value) { - $cases$; - return true; - default: - return false; - } - } - )"); + std::set numbers; + for (int j = 0; j < descriptor_->value_count(); j++) { + const EnumValueDescriptor* value = descriptor_->value(j); + numbers.insert(value->number()); + } - if (!has_reflection_) { + for (std::set::iterator iter = numbers.begin(); iter != numbers.end(); + ++iter) { + format(" case $1$:\n", Int32ToString(*iter)); + } + + format( + " return true;\n" + " default:\n" + " return false;\n" + " }\n" + "}\n" + "\n"); + + if (!HasDescriptorMethods(descriptor_->file(), options_)) { // In lite mode (where descriptors are unavailable), we generate separate // tables for mapping between enum names and numbers. The _entries table // contains the bulk of the data and is sorted by name, while @@ -406,168 +319,119 @@ void EnumGenerator::GenerateMethods(int idx, io::Printer* p) { // numerical value. In cases where there are multiple names for the same // number, we treat the first name appearing in the .proto file as the // canonical one. - - absl::btree_map name_to_number; - absl::flat_hash_map number_to_canonical_name; - for (int i = 0; i < enum_->value_count(); ++i) { - const auto* value = enum_->value(i); + std::map name_to_number; + std::map number_to_canonical_name; + for (int i = 0; i < descriptor_->value_count(); i++) { + const EnumValueDescriptor* value = descriptor_->value(i); name_to_number.emplace(value->name(), value->number()); - // The same number may appear with multiple names, so we use emplace() to // let the first name win. number_to_canonical_name.emplace(value->number(), value->name()); } - // Build the offset table for the strings table. - struct Offset { - int number; - size_t index, byte_offset, len; - }; - std::vector offsets; - size_t index = 0; - size_t offset = 0; - for (const auto& e : name_to_number) { - offsets.push_back(Offset{e.second, index, offset, e.first.size()}); - ++index; - offset += e.first.size(); + format( + "static ::$proto_ns$::internal::ExplicitlyConstructed " + "$classname$_strings[$1$] = {};\n\n", + CountUniqueValues(descriptor_)); + + // We concatenate all the names for a given enum into one big string + // literal. If instead we store an array of string literals, the linker + // seems to put all enum strings for a given .proto file in the same + // section, which hinders its ability to strip out unused strings. + format("static const char $classname$_names[] ="); + for (const auto& p : name_to_number) { + format("\n \"$1$\"", p.first); } - absl::c_sort(offsets, [](const auto& a, const auto& b) { - return a.byte_offset < b.byte_offset; - }); + format(";\n\n"); - std::vector offsets_by_number = offsets; - absl::c_sort(offsets_by_number, [](const auto& a, const auto& b) { - return a.number < b.number; - }); + format( + "static const ::$proto_ns$::internal::EnumEntry $classname$_entries[] " + "= {\n"); + int i = 0; + std::map number_to_index; + int data_index = 0; + for (const auto& p : name_to_number) { + format(" { {$classname$_names + $1$, $2$}, $3$ },\n", data_index, + p.first.size(), p.second); + if (number_to_canonical_name[p.second] == p.first) { + number_to_index.emplace(p.second, i); + } + ++i; + data_index += p.first.size(); + } - offsets_by_number.erase( - std::unique( - offsets_by_number.begin(), offsets_by_number.end(), - [](const auto& a, const auto& b) { return a.number == b.number; }), - offsets_by_number.end()); + format( + "};\n" + "\n" + "static const int $classname$_entries_by_number[] = {\n"); + for (const auto& p : number_to_index) { + format(" $1$, // $2$ -> $3$\n", p.second, p.first, + number_to_canonical_name[p.first]); + } + format( + "};\n" + "\n"); - p->Emit( - { - {"num_unique", number_to_canonical_name.size()}, - {"num_declared", enum_->value_count()}, - {"names", - // We concatenate all the names for a given enum into one big - // string literal. If instead we store an array of string - // literals, the linker seems to put all enum strings for a given - // .proto file in the same section, which hinders its ability to - // strip out unused strings. - [&] { - for (const auto& e : name_to_number) { - p->Emit({{"name", e.first}}, R"cc( - "$name$" - )cc"); - } - }}, - {"entries", - [&] { - for (const auto& offset : offsets) { - p->Emit({{"number", offset.number}, - {"offset", offset.byte_offset}, - {"len", offset.len}}, - R"cc( - {{&$Msg_Enum$_names[$offset$], $len$}, $number$}, - )cc"); - } - }}, - {"entries_by_number", - [&] { - for (const auto& offset : offsets_by_number) { - p->Emit({{"number", offset.number}, - {"index", offset.index}, - {"name", number_to_canonical_name[offset.number]}}, - R"cc( - $index$, // $number$ -> $name$ - )cc"); - } - }}, - }, - R"cc( - static ::$proto_ns$::internal::ExplicitlyConstructed - $Msg_Enum$_strings[$num_unique$] = {}; - - static const char $Msg_Enum$_names[] = { - $names$, - }; - - static const ::$proto_ns$::internal::EnumEntry $Msg_Enum$_entries[] = - { - $entries$, - }; - - static const int $Msg_Enum$_entries_by_number[] = { - $entries_by_number$, - }; - - const std::string& $Msg_Enum$_Name($Msg_Enum$ value) { - static const bool kDummy = - ::$proto_ns$::internal::InitializeEnumStrings( - $Msg_Enum$_entries, $Msg_Enum$_entries_by_number, - $num_unique$, $Msg_Enum$_strings); - (void)kDummy; - - int idx = ::$proto_ns$::internal::LookUpEnumName( - $Msg_Enum$_entries, $Msg_Enum$_entries_by_number, $num_unique$, - value); - return idx == -1 ? ::$proto_ns$::internal::GetEmptyString() - : $Msg_Enum$_strings[idx].get(); - } - - bool $Msg_Enum$_Parse(absl::string_view name, $Msg_Enum$* value) { - int int_value; - bool success = ::$proto_ns$::internal::LookUpEnumValue( - $Msg_Enum$_entries, $num_declared$, name, &int_value); - if (success) { - *value = static_cast<$Msg_Enum$>(int_value); - } - return success; - } - )cc"); + format( + "const std::string& $classname$_Name(\n" + " $classname$ value) {\n" + " static const bool dummy =\n" + " ::$proto_ns$::internal::InitializeEnumStrings(\n" + " $classname$_entries,\n" + " $classname$_entries_by_number,\n" + " $1$, $classname$_strings);\n" + " (void) dummy;\n" + " int idx = ::$proto_ns$::internal::LookUpEnumName(\n" + " $classname$_entries,\n" + " $classname$_entries_by_number,\n" + " $1$, value);\n" + " return idx == -1 ? ::$proto_ns$::internal::GetEmptyString() :\n" + " $classname$_strings[idx].get();\n" + "}\n", + CountUniqueValues(descriptor_)); + format( + "bool $classname$_Parse(\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, $classname$* " + "value) " + "{\n" + " int int_value;\n" + " bool success = ::$proto_ns$::internal::LookUpEnumValue(\n" + " $classname$_entries, $1$, name, &int_value);\n" + " if (success) {\n" + " *value = static_cast<$classname$>(int_value);\n" + " }\n" + " return success;\n" + "}\n", + descriptor_->value_count()); } - if (enum_->containing_type() != nullptr) { + if (descriptor_->containing_type() != nullptr) { + std::string parent = ClassName(descriptor_->containing_type(), false); // Before C++17, we must define the static constants which were // declared in the header, to give the linker a place to put them. // But MSVC++ pre-2015 and post-2017 (version 15.5+) insists that we not. - p->Emit( - { - {"Msg_", ClassName(enum_->containing_type(), false)}, - {"constexpr_storage", - [&] { - for (int i = 0; i < enum_->value_count(); i++) { - p->Emit({{"VALUE", EnumValueName(enum_->value(i))}}, - R"cc( - constexpr $Msg_Enum$ $Msg_$::$VALUE$; - )cc"); - } - }}, - {"array_size", - [&] { - if (generate_array_size_) { - p->Emit(R"cc( - constexpr int $Msg_$::$Enum$_ARRAYSIZE; - )cc"); - } - }}, - }, - R"( - #if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) - - $constexpr_storage$; - constexpr $Msg_Enum$ $Msg_$::$Enum$_MIN; - constexpr $Msg_Enum$ $Msg_$::$Enum$_MAX; - $array_size$; + format( + "#if (__cplusplus < 201703) && " + "(!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))\n"); - #endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) - )"); + for (int i = 0; i < descriptor_->value_count(); i++) { + format("constexpr $classname$ $1$::$2$;\n", parent, + EnumValueName(descriptor_->value(i))); + } + format( + "constexpr $classname$ $1$::$nested_name$_MIN;\n" + "constexpr $classname$ $1$::$nested_name$_MAX;\n", + parent); + if (generate_array_size_) { + format("constexpr int $1$::$nested_name$_ARRAYSIZE;\n", parent); + } + + format( + "#endif // (__cplusplus < 201703) && " + "(!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912))\n"); } } + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/enum.h b/libs/protobuf/src/google/protobuf/compiler/cpp/enum.h index 158a548..610d4fc 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/enum.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/enum.h @@ -39,62 +39,63 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/io/printer.h" +#include +#include + +namespace google { +namespace protobuf { +namespace io { +class Printer; // printer.h +} +} // namespace protobuf +} // namespace google namespace google { namespace protobuf { namespace compiler { namespace cpp { + class EnumGenerator { public: - EnumGenerator(const EnumDescriptor* descriptor, const Options& options); - - EnumGenerator(const EnumGenerator&) = delete; - EnumGenerator& operator=(const EnumGenerator&) = delete; - - ~EnumGenerator() = default; + // See generator.cc for the meaning of dllexport_decl. + EnumGenerator(const EnumDescriptor* descriptor, + const std::map& vars, + const Options& options); + ~EnumGenerator(); // Generate header code defining the enum. This code should be placed // within the enum's package namespace, but NOT within any class, even for // nested enums. - void GenerateDefinition(io::Printer* p); + void GenerateDefinition(io::Printer* printer); // Generate specialization of GetEnumDescriptor(). // Precondition: in ::google::protobuf namespace. - void GenerateGetEnumDescriptorSpecializations(io::Printer* p); + void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); // For enums nested within a message, generate code to import all the enum's // symbols (e.g. the enum type name, all its values, etc.) into the class's // namespace. This should be placed inside the class definition in the // header. - void GenerateSymbolImports(io::Printer* p) const; + void GenerateSymbolImports(io::Printer* printer) const; // Source file stuff. // Generate non-inline methods related to the enum, such as IsValidValue(). // Goes in the .cc file. EnumDescriptors are stored in an array, idx is // the index in this array that corresponds with this enum. - void GenerateMethods(int idx, io::Printer* p); + void GenerateMethods(int idx, io::Printer* printer); private: + const EnumDescriptor* descriptor_; + const std::string classname_; + const Options& options_; + // whether to generate the *_ARRAYSIZE constant. + const bool generate_array_size_; + + std::map variables_; + friend class FileGenerator; - - struct ValueLimits { - const EnumValueDescriptor* min; - const EnumValueDescriptor* max; - - static ValueLimits FromEnum(const EnumDescriptor* descriptor); - }; - - const EnumDescriptor* enum_; - Options options_; - - bool generate_array_size_; - bool should_cache_; - bool has_reflection_; - ValueLimits limits_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.cc index 3b8b033..8ffb699 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.cc @@ -32,12 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/enum_field.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -103,7 +104,7 @@ void EnumFieldGenerator::GenerateInlineAccessorDefinitions( " return _internal_$name$();\n" "}\n" "inline void $classname$::_internal_set_$name$($type$ value) {\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) { + if (!HasPreservingUnknownEnumSemantics(descriptor_)) { format(" assert($type$_IsValid(value));\n"); } format( @@ -203,7 +204,7 @@ void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions( " return _internal_$name$();\n" "}\n" "inline void $classname$::_internal_set_$name$($type$ value) {\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) { + if (!HasPreservingUnknownEnumSemantics(descriptor_)) { format(" assert($type$_IsValid(value));\n"); } format( @@ -251,9 +252,7 @@ void RepeatedEnumFieldGenerator::GeneratePrivateMembers( format("::$proto_ns$::RepeatedField $name$_;\n"); if (descriptor_->is_packed() && HasGeneratedMethods(descriptor_->file(), options_)) { - format( - "mutable ::$proto_ns$::internal::CachedSize " - "$cached_byte_size_name$;\n"); + format("mutable std::atomic $cached_byte_size_name$;\n"); } } @@ -290,7 +289,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions( " return _internal_$name$(index);\n" "}\n" "inline void $classname$::set_$name$(int index, $type$ value) {\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) { + if (!HasPreservingUnknownEnumSemantics(descriptor_)) { format(" assert($type$_IsValid(value));\n"); } format( @@ -299,7 +298,7 @@ void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "inline void $classname$::_internal_add_$name$($type$ value) {\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) { + if (!HasPreservingUnknownEnumSemantics(descriptor_)) { format(" assert($type$_IsValid(value));\n"); } format( @@ -365,7 +364,7 @@ void RepeatedEnumFieldGenerator::GenerateSerializeWithCachedSizesToArray( format( "{\n" " int byte_size = " - "$cached_byte_size_field$.Get();\n" + "$cached_byte_size_field$.load(std::memory_order_relaxed);\n" " if (byte_size > 0) {\n" " target = stream->WriteEnumPacked(\n" " $number$, $field$, byte_size, target);\n" @@ -403,7 +402,8 @@ void RepeatedEnumFieldGenerator::GenerateByteSize(io::Printer* printer) const { "::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n" "}\n" "int cached_size = ::_pbi::ToCachedSize(data_size);\n" - "$cached_byte_size_field$.Set(cached_size);\n" + "$cached_byte_size_field$.store(cached_size,\n" + " std::memory_order_relaxed);\n" "total_size += data_size;\n"); } else { format("total_size += ($tag_size$UL * count) + data_size;\n"); diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.h index e5d476c..61bae85 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/enum_field.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/cpp/field.h" +#include namespace google { namespace protobuf { @@ -48,8 +48,6 @@ namespace cpp { class EnumFieldGenerator : public FieldGenerator { public: EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - EnumFieldGenerator(const EnumFieldGenerator&) = delete; - EnumFieldGenerator& operator=(const EnumFieldGenerator&) = delete; ~EnumFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -68,14 +66,15 @@ class EnumFieldGenerator : public FieldGenerator { io::Printer* printer) const override; void GenerateAggregateInitializer(io::Printer* printer) const override; void GenerateCopyAggregateInitializer(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); }; class EnumOneofFieldGenerator : public EnumFieldGenerator { public: EnumOneofFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - EnumOneofFieldGenerator(const EnumOneofFieldGenerator&) = delete; - EnumOneofFieldGenerator& operator=(const EnumOneofFieldGenerator&) = delete; ~EnumOneofFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -83,6 +82,9 @@ class EnumOneofFieldGenerator : public EnumFieldGenerator { void GenerateClearingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumOneofFieldGenerator); }; class RepeatedEnumFieldGenerator : public FieldGenerator { @@ -90,9 +92,6 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options); ~RepeatedEnumFieldGenerator() override; - RepeatedEnumFieldGenerator(const RepeatedEnumFieldGenerator&) = delete; - RepeatedEnumFieldGenerator& operator=(const RepeatedEnumFieldGenerator&) = - delete; // implements FieldGenerator --------------------------------------- void GeneratePrivateMembers(io::Printer* printer) const override; @@ -113,6 +112,9 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { io::Printer* printer) const override; void GenerateAggregateInitializer(io::Printer* printer) const override; void GenerateCopyAggregateInitializer(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/extension.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/extension.cc index 9b6ddc8..950ed9e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/extension.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/extension.cc @@ -32,15 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/extension.h" +#include #include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -78,6 +77,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, type_traits_.append(" >"); break; } + SetCommonVars(options, &variables_); SetCommonMessageDataVariables(descriptor_->containing_type(), &variables_); variables_["extendee"] = QualifiedClassName(descriptor_->containing_type(), options_); @@ -86,14 +86,14 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, variables_["name"] = ResolveKeyword(name); variables_["constant_name"] = FieldConstantName(descriptor_); variables_["field_type"] = - absl::StrCat(static_cast(descriptor_->type())); + StrCat(static_cast(descriptor_->type())); variables_["packed"] = descriptor_->is_packed() ? "true" : "false"; std::string scope = IsScoped() ? ClassName(descriptor_->extension_scope(), false) + "::" : ""; variables_["scope"] = scope; variables_["scoped_name"] = ExtensionName(descriptor_); - variables_["number"] = absl::StrCat(descriptor_->number()); + variables_["number"] = StrCat(descriptor_->number()); bool add_verify_fn = // Only verify msgs. @@ -104,7 +104,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor, variables_["verify_fn"] = add_verify_fn - ? absl::StrCat("&", FieldMessageTypeName(descriptor_, options_), + ? StrCat("&", FieldMessageTypeName(descriptor_, options_), "::InternalVerify") : "nullptr"; } @@ -159,8 +159,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) { // it in the header which would be annoying for other reasons. So we // replace :: with _ in the name and declare it as a global. default_str = - absl::StrReplaceAll(variables_["scoped_name"], {{"::", "_"}}) + - "_default"; + StringReplace(variables_["scoped_name"], "::", "_", true) + "_default"; format("const std::string $1$($2$);\n", default_str, DefaultValue(options_, descriptor_)); } else if (descriptor_->message_type()) { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/extension.h b/libs/protobuf/src/google/protobuf/compiler/cpp/extension.h index 1c0e020..282931f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/extension.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/extension.h @@ -38,8 +38,8 @@ #include #include -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/port.h" +#include +#include namespace google { namespace protobuf { @@ -66,8 +66,6 @@ class ExtensionGenerator { explicit ExtensionGenerator(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - ExtensionGenerator(const ExtensionGenerator&) = delete; - ExtensionGenerator& operator=(const ExtensionGenerator&) = delete; ~ExtensionGenerator(); // Header stuff. @@ -85,6 +83,8 @@ class ExtensionGenerator { MessageSCCAnalyzer* scc_analyzer_; std::map variables_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/field.cc index 3199dce..90d2084 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/field.cc @@ -32,26 +32,25 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/field.h" +#include #include #include #include -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/primitive_field.h" -#include "google/protobuf/compiler/cpp/string_field.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/compiler/cpp/enum_field.h" -#include "google/protobuf/compiler/cpp/map_field.h" -#include "google/protobuf/compiler/cpp/message_field.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -63,22 +62,22 @@ using internal::WireFormat; namespace { void MaySetAnnotationVariable(const Options& options, - absl::string_view annotation_name, - absl::string_view substitute_template_prefix, - absl::string_view prepared_template, - int field_index, absl::string_view access_type, + StringPiece annotation_name, + StringPiece substitute_template_prefix, + StringPiece prepared_template, + int field_index, StringPiece access_type, std::map* variables) { if (options.field_listener_options.forbidden_field_listener_events.count( std::string(annotation_name))) return; - (*variables)[absl::StrCat("annotate_", annotation_name)] = absl::Substitute( - absl::StrCat(substitute_template_prefix, prepared_template, ");\n"), + (*variables)[StrCat("annotate_", annotation_name)] = strings::Substitute( + StrCat(substitute_template_prefix, prepared_template, ");\n"), field_index, access_type); } std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor, - absl::string_view proto_ns, - absl::string_view field_member) { + StringPiece proto_ns, + StringPiece field_member) { std::string field_name = google::protobuf::compiler::cpp::FieldName(descriptor); std::string field_pointer = descriptor->options().ctype() == google::protobuf::FieldOptions::STRING @@ -86,13 +85,13 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor, : "$0"; if (descriptor->default_value_string().empty()) { - return absl::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ", + return strings::Substitute(StrCat("_internal_has_", field_name, "() ? ", field_pointer, ": nullptr"), field_member); } if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING_PIECE) { - return absl::Substitute(absl::StrCat("_internal_has_", field_name, "() ? ", + return strings::Substitute(StrCat("_internal_has_", field_name, "() ? ", field_pointer, ": nullptr"), field_member); } @@ -101,25 +100,25 @@ std::string GenerateTemplateForOneofString(const FieldDescriptor* descriptor, descriptor->options().ctype() == google::protobuf::FieldOptions::STRING ? "&$1.get()" : "&$1"; - return absl::Substitute( - absl::StrCat("_internal_has_", field_name, "() ? ", field_pointer, " : ", + return strings::Substitute( + StrCat("_internal_has_", field_name, "() ? ", field_pointer, " : ", default_value_pointer), field_member, MakeDefaultFieldName(descriptor)); } std::string GenerateTemplateForSingleString(const FieldDescriptor* descriptor, - absl::string_view field_member) { + StringPiece field_member) { if (descriptor->default_value_string().empty()) { - return absl::StrCat("&", field_member); + return StrCat("&", field_member); } if (descriptor->options().ctype() == google::protobuf::FieldOptions::STRING) { - return absl::Substitute( + return strings::Substitute( "$0.IsDefault() ? &$1.get() : $0.UnsafeGetPointer()", field_member, MakeDefaultFieldName(descriptor)); } - return absl::StrCat("&", field_member); + return StrCat("&", field_member); } } // namespace @@ -135,12 +134,12 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, "annotate_release", "annotate_set", "annotate_size", "annotate_clear", "annotate_add_mutable", }; - for (size_t i = 0; i < ABSL_ARRAYSIZE(kAccessorsAnnotations); ++i) { + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(kAccessorsAnnotations); ++i) { (*variables)[kAccessorsAnnotations[i]] = ""; } if (options.annotate_accessor) { - for (size_t i = 0; i < ABSL_ARRAYSIZE(kAccessorsAnnotations); ++i) { - (*variables)[kAccessorsAnnotations[i]] = absl::StrCat( + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(kAccessorsAnnotations); ++i) { + (*variables)[kAccessorsAnnotations[i]] = StrCat( " ", FieldName(descriptor), "_AccessedNoStrip = true;\n"); } } @@ -154,8 +153,9 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, std::string field_member = (*variables)["field"]; const google::protobuf::OneofDescriptor* oneof_member = descriptor->real_containing_oneof(); + const std::string proto_ns = (*variables)["proto_ns"]; const std::string substitute_template_prefix = - absl::StrCat(" ", (*variables)["tracker"], ".$1<$0>(this, "); + StrCat(" ", (*variables)["tracker"], ".$1<$0>(this, "); std::string prepared_template; // Flat template is needed if the prepared one is introspecting the values @@ -166,9 +166,9 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, if (descriptor->is_repeated() && !descriptor->is_map()) { if (descriptor->type() != FieldDescriptor::TYPE_MESSAGE && descriptor->type() != FieldDescriptor::TYPE_GROUP) { - prepared_template = absl::Substitute("&$0.Get(index)", field_member); + prepared_template = strings::Substitute("&$0.Get(index)", field_member); prepared_add_template = - absl::Substitute("&$0.Get($0.size() - 1)", field_member); + strings::Substitute("&$0.Get($0.size() - 1)", field_member); } else { prepared_template = "nullptr"; prepared_add_template = "nullptr"; @@ -181,18 +181,18 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { if (oneof_member) { prepared_template = GenerateTemplateForOneofString( - descriptor, ProtobufNamespace(options), field_member); + descriptor, (*variables)["proto_ns"], field_member); } else { prepared_template = GenerateTemplateForSingleString(descriptor, field_member); } } else { - prepared_template = absl::StrCat("&", field_member); + prepared_template = StrCat("&", field_member); } if (descriptor->is_repeated() && !descriptor->is_map() && descriptor->type() != FieldDescriptor::TYPE_MESSAGE && descriptor->type() != FieldDescriptor::TYPE_GROUP) { - prepared_flat_template = absl::StrCat("&", field_member); + prepared_flat_template = StrCat("&", field_member); } else { prepared_flat_template = prepared_template; } @@ -232,85 +232,51 @@ void AddAccessorAnnotations(const FieldDescriptor* descriptor, "OnAddMutable", variables); } -absl::flat_hash_map FieldVars( - const FieldDescriptor* desc, const Options& opts) { - bool split = ShouldSplit(desc, opts); - absl::flat_hash_map vars = { - {"ns", Namespace(desc, opts)}, - {"name", FieldName(desc)}, - {"index", absl::StrCat(desc->index())}, - {"number", absl::StrCat(desc->number())}, - {"classname", ClassName(FieldScope(desc), false)}, - {"declared_type", DeclaredTypeMethodName(desc->type())}, - {"field", FieldMemberName(desc, split)}, - {"tag_size", - absl::StrCat(WireFormat::TagSize(desc->number(), desc->type()))}, - {"deprecated_attr", DeprecatedAttribute(opts, desc)}, - {"set_hasbit", ""}, - {"clear_hasbit", ""}, - {"maybe_prepare_split_message", - split ? "PrepareSplitMessageForWrite();" : ""}, - - // 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. - {"{", ""}, - {"}", ""}, - }; - - // TODO(b/245791219): Refactor AddAccessorAnnotations to avoid this - // workaround. - std::map workaround = { - {"field", vars["field"]}, - {"tracker", "Impl_::_tracker_"}, - }; - AddAccessorAnnotations(desc, opts, &workaround); - for (auto& pair : workaround) { - vars.emplace(pair); - } - - return vars; -} - void SetCommonFieldVariables(const FieldDescriptor* descriptor, std::map* variables, const Options& options) { + SetCommonVars(options, variables); SetCommonMessageDataVariables(descriptor->containing_type(), variables); - for (auto& pair : FieldVars(descriptor, options)) { - variables->emplace(pair); - } -} + (*variables)["ns"] = Namespace(descriptor, options); + (*variables)["name"] = FieldName(descriptor); + (*variables)["index"] = StrCat(descriptor->index()); + (*variables)["number"] = StrCat(descriptor->number()); + (*variables)["classname"] = ClassName(FieldScope(descriptor), false); + (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type()); + bool split = ShouldSplit(descriptor, options); + (*variables)["field"] = FieldMemberName(descriptor, split); -absl::flat_hash_map OneofFieldVars( - const FieldDescriptor* descriptor) { - if (descriptor->containing_oneof() == nullptr) { - return {}; - } + (*variables)["tag_size"] = StrCat( + WireFormat::TagSize(descriptor->number(), descriptor->type())); + (*variables)["deprecated_attr"] = DeprecatedAttribute(options, descriptor); - return {{"oneof_name", descriptor->containing_oneof()->name()}}; -} + (*variables)["set_hasbit"] = ""; + (*variables)["clear_hasbit"] = ""; + (*variables)["maybe_prepare_split_message"] = + split ? " PrepareSplitMessageForWrite();\n" : ""; -void SetCommonOneofFieldVariables( - const FieldDescriptor* descriptor, - std::map* variables) { - for (auto& pair : OneofFieldVars(descriptor)) { - variables->emplace(pair); - } + AddAccessorAnnotations(descriptor, options, variables); + + // 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 FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { - if (!internal::cpp::HasHasbit(descriptor_)) { + if (!HasHasbit(descriptor_)) { GOOGLE_CHECK_EQ(has_bit_index, -1); return; } - variables_["set_hasbit"] = absl::StrCat( + variables_["set_hasbit"] = StrCat( variables_["has_bits"], "[", has_bit_index / 32, "] |= 0x", - absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8), "u;"); - variables_["clear_hasbit"] = absl::StrCat( + strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8), "u;"); + variables_["clear_hasbit"] = StrCat( variables_["has_bits"], "[", has_bit_index / 32, "] &= ~0x", - absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8), "u;"); + strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8), "u;"); } void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) { @@ -321,16 +287,16 @@ void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) { // The first bit is the tracking bit for on demand registering ArenaDtor. GOOGLE_CHECK_GT(inlined_string_index, 0) << "_inlined_string_donated_'s bit 0 is reserved for arena dtor tracking"; - variables_["inlined_string_donated"] = absl::StrCat( + variables_["inlined_string_donated"] = StrCat( "(", variables_["inlined_string_donated_array"], "[", inlined_string_index / 32, "] & 0x", - absl::Hex(1u << (inlined_string_index % 32), absl::kZeroPad8), + strings::Hex(1u << (inlined_string_index % 32), strings::ZERO_PAD_8), "u) != 0;"); variables_["donating_states_word"] = - absl::StrCat(variables_["inlined_string_donated_array"], "[", + StrCat(variables_["inlined_string_donated_array"], "[", inlined_string_index / 32, "]"); - variables_["mask_for_undonate"] = absl::StrCat( - "~0x", absl::Hex(1u << (inlined_string_index % 32), absl::kZeroPad8), + variables_["mask_for_undonate"] = StrCat( + "~0x", strings::Hex(1u << (inlined_string_index % 32), strings::ZERO_PAD_8), "u"); } @@ -364,6 +330,13 @@ void FieldGenerator::GenerateCopyConstructorCode(io::Printer* printer) const { } } +void SetCommonOneofFieldVariables( + const FieldDescriptor* descriptor, + std::map* variables) { + const std::string prefix = descriptor->containing_oneof()->name() + "_."; + (*variables)["oneof_name"] = descriptor->containing_oneof()->name(); +} + FieldGenerator::~FieldGenerator() {} FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor, diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/field.h index db0d64d..dd2a51a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/field.h @@ -40,9 +40,9 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/options.h" +#include +#include +#include namespace google { namespace protobuf { @@ -57,12 +57,6 @@ namespace protobuf { namespace compiler { namespace cpp { -absl::flat_hash_map FieldVars( - const FieldDescriptor* desc, const Options& opts); - -absl::flat_hash_map OneofFieldVars( - const FieldDescriptor* descriptor); - // Helper function: set variables in the map that are the same for all // field code generators. // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', @@ -80,8 +74,6 @@ class FieldGenerator { explicit FieldGenerator(const FieldDescriptor* descriptor, const Options& options) : descriptor_(descriptor), options_(options) {} - FieldGenerator(const FieldGenerator&) = delete; - FieldGenerator& operator=(const FieldGenerator&) = delete; virtual ~FieldGenerator(); virtual void GenerateSerializeWithCachedSizes( io::Printer* printer) const final{}; @@ -158,6 +150,9 @@ class FieldGenerator { // method, invoked by each of the generated constructors. virtual void GenerateConstructorCode(io::Printer* printer) const = 0; + // Generate initialization code for private members in the cold struct. + virtual void GenerateCreateSplitMessageCode(io::Printer* printer) const {} + // Generate any code that needs to go in the class's SharedDtor() method, // invoked by the destructor. // Most field types don't need this, so the default implementation is empty. @@ -227,6 +222,9 @@ class FieldGenerator { const FieldDescriptor* descriptor_; const Options& options_; std::map variables_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); }; // Convenience class which constructs FieldGenerators for a Descriptor. @@ -234,8 +232,6 @@ class FieldGeneratorMap { public: FieldGeneratorMap(const Descriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - FieldGeneratorMap(const FieldGeneratorMap&) = delete; - FieldGeneratorMap& operator=(const FieldGeneratorMap&) = delete; ~FieldGeneratorMap(); const FieldGenerator& get(const FieldDescriptor* field) const; @@ -262,6 +258,8 @@ class FieldGeneratorMap { static FieldGenerator* MakeGenerator(const FieldDescriptor* field, const Options& options, MessageSCCAnalyzer* scc_analyzer); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/file.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/file.cc index fdb84ac..838e0ab 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/file.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/file.cc @@ -32,144 +32,132 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/file.h" +#include #include #include #include #include -#include #include #include -#include #include -#include "google/protobuf/compiler/scc.h" -#include "absl/container/btree_map.h" -#include "absl/container/btree_set.h" -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" -#include "absl/strings/escaping.h" -#include "absl/strings/match.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" -#include "absl/strings/strip.h" -#include "google/protobuf/compiler/cpp/enum.h" -#include "google/protobuf/compiler/cpp/extension.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/message.h" -#include "google/protobuf/compiler/cpp/names.h" -#include "google/protobuf/compiler/cpp/service.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" - -#include "google/protobuf/stubs/strutil.h" // for StringReplace. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { + namespace { -absl::flat_hash_map FileVars( - const FileDescriptor* file, const Options& options) { - return { - {"filename", file->name()}, - {"package_ns", Namespace(file, options)}, - {"tablename", UniqueName("TableStruct", file, options)}, - {"desc_table", DescriptorTableName(file, options)}, - {"dllexport_decl", options.dllexport_decl}, - {"file_level_metadata", UniqueName("file_level_metadata", file, options)}, - {"file_level_enum_descriptors", - UniqueName("file_level_enum_descriptors", file, options)}, - {"file_level_service_descriptors", - UniqueName("file_level_service_descriptors", file, options)}, - }; + +// When we forward-declare things, we want to create a sorted order so our +// output is deterministic and minimizes namespace changes. +template +std::string GetSortKey(const T& val) { + return val.full_name(); +} + +template <> +std::string GetSortKey(const FileDescriptor& val) { + return val.name(); +} + +template +bool CompareSortKeys(const T* a, const T* b) { + return GetSortKey(*a) < GetSortKey(*b); +} + +template +std::vector Sorted(const std::unordered_set& vals) { + std::vector sorted(vals.begin(), vals.end()); + std::sort(sorted.begin(), sorted.end(), CompareSortKeys); + return sorted; } // TODO(b/203101078): remove pragmas that suppresses uninitialized warnings when // clang bug is fixed. -void MuteWuninitialized(io::Printer* p) { - p->Emit(R"( - #if defined(__llvm__) - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wuninitialized" - #endif // __llvm__ - )"); +inline void MuteWuninitialized(Formatter& format) { + format( + "#if defined(__llvm__)\n" + " #pragma clang diagnostic push\n" + " #pragma clang diagnostic ignored \"-Wuninitialized\"\n" + "#endif // __llvm__\n"); } -void UnmuteWuninitialized(io::Printer* p) { - p->Emit(R"( - #if defined(__llvm__) - #pragma clang diagnostic pop - #endif // __llvm__ - )"); +inline void UnmuteWuninitialized(Formatter& format) { + format( + "#if defined(__llvm__)\n" + " #pragma clang diagnostic pop\n" + "#endif // __llvm__\n"); } + } // namespace FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) : file_(file), options_(options), scc_analyzer_(options) { + // These variables are the same on a file level + SetCommonVars(options, &variables_); + variables_["dllexport_decl"] = options.dllexport_decl; + variables_["tablename"] = UniqueName("TableStruct", file_, options_); + variables_["file_level_metadata"] = + UniqueName("file_level_metadata", file_, options_); + variables_["desc_table"] = DescriptorTableName(file_, options_); + variables_["file_level_enum_descriptors"] = + UniqueName("file_level_enum_descriptors", file_, options_); + variables_["file_level_service_descriptors"] = + UniqueName("file_level_service_descriptors", file_, options_); + variables_["filename"] = file_->name(); + variables_["package_ns"] = Namespace(file_, options); + std::vector msgs = FlattenMessagesInFile(file); - - for (int i = 0; i < msgs.size(); ++i) { - message_generators_.push_back(absl::make_unique( - msgs[i], variables_, i, options, &scc_analyzer_)); - message_generators_.back()->AddGenerators(&enum_generators_, - &extension_generators_); + for (int i = 0; i < msgs.size(); i++) { + // Deleted in destructor + MessageGenerator* msg_gen = + new MessageGenerator(msgs[i], variables_, i, options, &scc_analyzer_); + message_generators_.emplace_back(msg_gen); + msg_gen->AddGenerators(&enum_generators_, &extension_generators_); } - for (int i = 0; i < file->enum_type_count(); ++i) { - enum_generators_.push_back( - absl::make_unique(file->enum_type(i), options)); + for (int i = 0; i < file->enum_type_count(); i++) { + enum_generators_.emplace_back( + new EnumGenerator(file->enum_type(i), variables_, options)); } - for (int i = 0; i < file->service_count(); ++i) { - service_generators_.push_back(absl::make_unique( - file->service(i), variables_, options)); + for (int i = 0; i < file->service_count(); i++) { + service_generators_.emplace_back( + new ServiceGenerator(file->service(i), variables_, options)); } if (HasGenericServices(file_, options_)) { - for (int i = 0; i < service_generators_.size(); ++i) { + 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_.push_back(absl::make_unique( - file->extension(i), options, &scc_analyzer_)); + for (int i = 0; i < file->extension_count(); i++) { + extension_generators_.emplace_back( + new ExtensionGenerator(file->extension(i), options, &scc_analyzer_)); } - for (int i = 0; i < file->weak_dependency_count(); ++i) { weak_deps_.insert(file->weak_dependency(i)); } } -void FileGenerator::GenerateFile(io::Printer* p, GeneratedFileType file_type, - std::function cb) { - auto v = p->WithVars(FileVars(file_, options_)); - auto guard = IncludeGuard(file_, file_type, options_); - p->Emit({{"cb", cb}, {"guard", guard}}, R"( - // Generated by the protocol buffer compiler. DO NOT EDIT! - // source: $filename$ +FileGenerator::~FileGenerator() = default; - #ifndef $guard$ - #define $guard$ - - #include - #include - #include - - $cb$; - - #endif // $guard$ - )"); -} - -void FileGenerator::GenerateMacroUndefs(io::Printer* p) { +void FileGenerator::GenerateMacroUndefs(io::Printer* printer) { + Formatter format(printer, variables_); // Only do this for protobuf's own types. There are some google3 protos using // macros as field names and the generated code compiles after the macro // expansion. Undefing these macros actually breaks such code. @@ -177,472 +165,410 @@ void FileGenerator::GenerateMacroUndefs(io::Printer* p) { file_->name() != "google/protobuf/compiler/plugin.proto") { return; } - + std::vector names_to_undef; std::vector fields; ListAllFields(file_, &fields); - - absl::flat_hash_set all_fields; - for (const FieldDescriptor* field : fields) { - all_fields.insert(field->name()); - } - - for (absl::string_view name : {"major", "minor"}) { - if (!all_fields.contains(name)) { - continue; + for (int i = 0; i < fields.size(); i++) { + const std::string& name = fields[i]->name(); + static const char* kMacroNames[] = {"major", "minor"}; + for (int j = 0; j < GOOGLE_ARRAYSIZE(kMacroNames); ++j) { + if (name == kMacroNames[j]) { + names_to_undef.push_back(name); + break; + } } - - p->Emit({{"name", std::string(name)}}, R"( - #ifdef $name$ - #undef $name$ - #endif // $name$ - )"); + } + for (int i = 0; i < names_to_undef.size(); ++i) { + format( + "#ifdef $1$\n" + "#undef $1$\n" + "#endif\n", + names_to_undef[i]); } } +void FileGenerator::GenerateHeader(io::Printer* printer) { + Formatter format(printer, variables_); -void FileGenerator::GenerateSharedHeaderCode(io::Printer* p) { - p->Emit( - { - {"port_def", - [&] { IncludeFile("net/proto2/public/port_def.inc", p); }}, - {"port_undef", - [&] { IncludeFile("net/proto2/public/port_undef.inc", p); }}, - {"dllexport_macro", FileDllExport(file_, options_)}, - {"undefs", [&] { GenerateMacroUndefs(p); }}, - {"global_state_decls", - [&] { GenerateGlobalStateFunctionDeclarations(p); }}, - {"fwd_decls", [&] { GenerateForwardDeclarations(p); }}, - {"proto2_ns_enums", - [&] { GenerateProto2NamespaceEnumSpecializations(p); }}, - {"main_decls", - [&] { - NamespaceOpener ns(Namespace(file_, options_), p); - p->Emit( - { - {"enums", [&] { GenerateEnumDefinitions(p); }}, - {"messages", [&] { GenerateMessageDefinitions(p); }}, - {"services", [&] { GenerateServiceDefinitions(p); }}, - {"extensions", [&] { GenerateExtensionIdentifiers(p); }}, - {"inline_fns", - [&] { GenerateInlineFunctionDefinitions(p); }}, - }, - R"( - $enums$ + // port_def.inc must be included after all other includes. + IncludeFile("net/proto2/public/port_def.inc", printer); + format("#define $1$$ dllexport_decl$\n", FileDllExport(file_, options_)); + GenerateMacroUndefs(printer); - $hrule_thick$ + // For Any support with lite protos, we need to friend AnyMetadata, so we + // forward-declare it here. + format( + "PROTOBUF_NAMESPACE_OPEN\n" + "namespace internal {\n" + "class AnyMetadata;\n" + "} // namespace internal\n" + "PROTOBUF_NAMESPACE_CLOSE\n"); - $messages$ + GenerateGlobalStateFunctionDeclarations(printer); - $hrule_thick$ + GenerateForwardDeclarations(printer); - $services$ + { + NamespaceOpener ns(Namespace(file_, options_), format); - $extensions$ + format("\n"); - $hrule_thick$ + GenerateEnumDefinitions(printer); - $inline_fns$ + format(kThickSeparator); + format("\n"); - // @@protoc_insertion_point(namespace_scope) - )"); - }}, - }, - R"( - // Must be included last. - $port_def$ + GenerateMessageDefinitions(printer); - #define $dllexport_macro$$ dllexport_decl$ - $undefs$ + format("\n"); + format(kThickSeparator); + format("\n"); - PROTOBUF_NAMESPACE_OPEN - namespace internal { - class AnyMetadata; - } // namespace internal - PROTOBUF_NAMESPACE_CLOSE + GenerateServiceDefinitions(printer); - $global_state_decls$; - $fwd_decls$ + GenerateExtensionIdentifiers(printer); - $main_decls$ + format("\n"); + format(kThickSeparator); + format("\n"); - $proto2_ns_enums$ + GenerateInlineFunctionDefinitions(printer); - // @@protoc_insertion_point(global_scope) + format( + "\n" + "// @@protoc_insertion_point(namespace_scope)\n" + "\n"); + } - $port_undef$ - )"); + // We need to specialize some templates in the ::google::protobuf namespace: + GenerateProto2NamespaceEnumSpecializations(printer); + + format( + "\n" + "// @@protoc_insertion_point(global_scope)\n" + "\n"); + IncludeFile("net/proto2/public/port_undef.inc", printer); } -void FileGenerator::GenerateProtoHeader(io::Printer* p, - absl::string_view info_path) { +void FileGenerator::GenerateProtoHeader(io::Printer* printer, + const std::string& info_path) { + Formatter format(printer, variables_); if (!options_.proto_h) { return; } - GenerateFile(p, GeneratedFileType::kProtoH, [&] { + GenerateTopHeaderGuard(printer, false); + + if (!options_.opensource_runtime) { + format( + "#ifdef SWIG\n" + "#error \"Do not SWIG-wrap protobufs.\"\n" + "#endif // SWIG\n" + "\n"); + } + + if (IsBootstrapProto(options_, file_)) { + format("// IWYU pragma: private, include \"$1$.proto.h\"\n\n", + StripProto(file_->name())); + } + + GenerateLibraryIncludes(printer); + + for (int i = 0; i < file_->public_dependency_count(); i++) { + const FileDescriptor* dep = file_->public_dependency(i); + format("#include \"$1$.proto.h\"\n", StripProto(dep->name())); + } + + format("// @@protoc_insertion_point(includes)\n"); + + GenerateMetadataPragma(printer, info_path); + + GenerateHeader(printer); + + GenerateBottomHeaderGuard(printer, false); +} + +void FileGenerator::GeneratePBHeader(io::Printer* printer, + const std::string& info_path) { + Formatter format(printer, variables_); + GenerateTopHeaderGuard(printer, true); + + if (options_.proto_h) { + std::string target_basename = StripProto(file_->name()); if (!options_.opensource_runtime) { - p->Emit(R"( - #ifdef SWIG - #error "Do not SWIG-wrap protobufs." - #endif // SWIG - )"); + GetBootstrapBasename(options_, target_basename, &target_basename); } - if (IsBootstrapProto(options_, file_)) { - p->Emit({{"name", StripProto(file_->name())}}, R"cc( - // IWYU pragma: private, include "$name$.proto.h" - )cc"); + format("#include \"$1$.proto.h\" // IWYU pragma: export\n", + target_basename); + } else { + GenerateLibraryIncludes(printer); + } + + if (options_.transitive_pb_h) { + GenerateDependencyIncludes(printer); + } + + // This is unfortunately necessary for some plugins. I don't see why we + // need two of the same insertion points. + // TODO(gerbens) remove this. + format("// @@protoc_insertion_point(includes)\n"); + + GenerateMetadataPragma(printer, info_path); + + if (!options_.proto_h) { + GenerateHeader(printer); + } else { + { + NamespaceOpener ns(Namespace(file_, options_), format); + format( + "\n" + "// @@protoc_insertion_point(namespace_scope)\n"); } + format( + "\n" + "// @@protoc_insertion_point(global_scope)\n" + "\n"); + } - p->Emit( - { - {"library_includes", [&] { GenerateLibraryIncludes(p); }}, - {"proto_includes", - [&] { - for (int i = 0; i < file_->public_dependency_count(); ++i) { - const FileDescriptor* dep = file_->public_dependency(i); - p->Emit({{"name", StripProto(dep->name())}}, R"( - #include "$name$.proto.h" - )"); - } - }}, - {"metadata_pragma", [&] { GenerateMetadataPragma(p, info_path); }}, - {"header_main", [&] { GenerateSharedHeaderCode(p); }}, - }, - R"cc( - $library_includes$; - $proto_includes$; - // @@protoc_insertion_point(includes) - - $metadata_pragma$; - $header_main$; - )cc"); - }); + GenerateBottomHeaderGuard(printer, true); } -void FileGenerator::GeneratePBHeader(io::Printer* p, - absl::string_view info_path) { - GenerateFile(p, GeneratedFileType::kPbH, [&] { - p->Emit( - { - {"library_includes", - [&] { - if (options_.proto_h) { - std::string target_basename = StripProto(file_->name()); - if (!options_.opensource_runtime) { - GetBootstrapBasename(options_, target_basename, - &target_basename); - } - p->Emit({{"name", target_basename}}, R"( - #include "$name$.proto.h" // IWYU pragma: export - )"); - } else { - GenerateLibraryIncludes(p); - } - }}, - {"proto_includes", - [&] { - if (options_.transitive_pb_h) { - GenerateDependencyIncludes(p); - } - }}, - {"metadata_pragma", [&] { GenerateMetadataPragma(p, info_path); }}, - {"header_main", - [&] { - if (!options_.proto_h) { - GenerateSharedHeaderCode(p); - return; - } - - { - NamespaceOpener ns(Namespace(file_, options_), p); - p->Emit(R"cc( - - // @@protoc_insertion_point(namespace_scope) - )cc"); - } - p->Emit(R"cc( - - // @@protoc_insertion_point(global_scope) - )cc"); - }}, - }, - R"cc( - $library_includes$; - $proto_includes$; - // @@protoc_insertion_point(includes) - - $metadata_pragma$; - $header_main$; - )cc"); - }); -} - -void FileGenerator::DoIncludeFile(absl::string_view google3_name, - bool do_export, io::Printer* p) { - absl::string_view prefix = "net/proto2/"; - GOOGLE_CHECK(absl::StartsWith(google3_name, prefix)) << google3_name; - - auto v = p->WithVars( - {{"export_suffix", do_export ? "// IWYU pragma: export" : ""}}); +void FileGenerator::DoIncludeFile(const std::string& google3_name, + bool do_export, io::Printer* printer) { + Formatter format(printer, variables_); + const std::string prefix = "net/proto2/"; + GOOGLE_CHECK(google3_name.find(prefix) == 0) << google3_name; if (options_.opensource_runtime) { - absl::ConsumePrefix(&google3_name, prefix); - std::string path(google3_name); + std::string path = google3_name.substr(prefix.size()); path = StringReplace(path, "internal/", "", false); path = StringReplace(path, "proto/", "", false); path = StringReplace(path, "public/", "", false); - if (options_.runtime_include_base.empty()) { - p->Emit({{"path", path}}, R"( - #include "google/protobuf/$path$"$ export_suffix$ - )"); + format("#include ", path); } else { - p->Emit({{"base", options_.runtime_include_base}, {"path", path}}, R"( - #include "$base$google/protobuf/$path$"$ export_suffix$ - )"); + format("#include \"$1$google/protobuf/$2$\"", + options_.runtime_include_base, path); } } else { - std::string path(google3_name); + std::string path = google3_name; // The bootstrapped proto generated code needs to use the // third_party/protobuf header paths to avoid circular dependencies. if (options_.bootstrap) { - path = StringReplace(path, "net/proto2/public", "third_party/protobuf", - false); + path = StringReplace(google3_name, "net/proto2/public", + "third_party/protobuf", false); } - - p->Emit({{"path", path}}, R"( - #include "$path$"$ export_suffix$ - )"); + format("#include \"$1$\"", path); } + + if (do_export) { + format(" // IWYU pragma: export"); + } + + format("\n"); } -std::string FileGenerator::CreateHeaderInclude(absl::string_view basename, +std::string FileGenerator::CreateHeaderInclude(const std::string& basename, const FileDescriptor* file) { - if (options_.opensource_runtime && IsWellKnownMessage(file) && - !options_.runtime_include_base.empty()) { - return absl::StrCat("\"", options_.runtime_include_base, basename, "\""); + bool use_system_include = false; + std::string name = basename; + + if (options_.opensource_runtime) { + if (IsWellKnownMessage(file)) { + if (options_.runtime_include_base.empty()) { + use_system_include = true; + } else { + name = options_.runtime_include_base + basename; + } + } } - return absl::StrCat("\"", basename, "\""); + std::string left = "\""; + std::string right = "\""; + if (use_system_include) { + left = "<"; + right = ">"; + } + return left + name + right; } -void FileGenerator::GenerateSourceIncludes(io::Printer* p) { +void FileGenerator::GenerateSourceIncludes(io::Printer* printer) { + Formatter format(printer, variables_); std::string target_basename = StripProto(file_->name()); if (!options_.opensource_runtime) { GetBootstrapBasename(options_, target_basename, &target_basename); } + target_basename += options_.proto_h ? ".proto.h" : ".pb.h"; + format( + "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "// source: $filename$\n" + "\n" + "#include $1$\n" + "\n" + "#include \n" // for swap() + "\n", + CreateHeaderInclude(target_basename, file_)); - absl::StrAppend(&target_basename, options_.proto_h ? ".proto.h" : ".pb.h"); - p->Emit({{"h_include", CreateHeaderInclude(target_basename, file_)}}, - R"( - // Generated by the protocol buffer compiler. DO NOT EDIT! - // source: $filename$ - - #include $h_include$ - - #include - )"); - - IncludeFile("net/proto2/io/public/coded_stream.h", p); + IncludeFile("net/proto2/io/public/coded_stream.h", printer); // TODO(gerbens) This is to include parse_context.h, we need a better way - IncludeFile("net/proto2/public/extension_set.h", p); - IncludeFile("net/proto2/public/wire_format_lite.h", p); + IncludeFile("net/proto2/public/extension_set.h", printer); + IncludeFile("net/proto2/public/wire_format_lite.h", printer); // Unknown fields implementation in lite mode uses StringOutputStream if (!UseUnknownFieldSet(file_, options_) && !message_generators_.empty()) { - IncludeFile("net/proto2/io/public/zero_copy_stream_impl_lite.h", p); + IncludeFile("net/proto2/io/public/zero_copy_stream_impl_lite.h", printer); } if (HasDescriptorMethods(file_, options_)) { - IncludeFile("net/proto2/public/descriptor.h", p); - IncludeFile("net/proto2/public/generated_message_reflection.h", p); - IncludeFile("net/proto2/public/reflection_ops.h", p); - IncludeFile("net/proto2/public/wire_format.h", p); + IncludeFile("net/proto2/public/descriptor.h", printer); + IncludeFile("net/proto2/public/generated_message_reflection.h", printer); + IncludeFile("net/proto2/public/reflection_ops.h", printer); + IncludeFile("net/proto2/public/wire_format.h", printer); } if (HasGeneratedMethods(file_, options_) && options_.tctable_mode != Options::kTCTableNever) { - IncludeFile("net/proto2/public/generated_message_tctable_impl.h", p); + IncludeFile("net/proto2/public/generated_message_tctable_impl.h", printer); } if (options_.proto_h) { // Use the smaller .proto.h files. - for (int i = 0; i < file_->dependency_count(); ++i) { + for (int i = 0; i < file_->dependency_count(); i++) { const FileDescriptor* dep = file_->dependency(i); - - if (!options_.opensource_runtime && - IsDepWeak(dep)) { // Do not import weak deps. - continue; - } - + // Do not import weak deps. + if (!options_.opensource_runtime && IsDepWeak(dep)) continue; std::string basename = StripProto(dep->name()); if (IsBootstrapProto(options_, file_)) { GetBootstrapBasename(options_, basename, &basename); } - p->Emit({{"name", basename}}, R"( - #include "$name$.proto.h" - )"); + format("#include \"$1$.proto.h\"\n", basename); } } - if (HasCordFields(file_, options_)) { - p->Emit(R"( - #include "third_party/absl/strings/internal/string_constant.h" - )"); + format( + "#include \"third_party/absl/strings/internal/string_constant.h\"\n"); } - p->Emit(R"cc( - // @@protoc_insertion_point(includes) - - // Must be included last. - )cc"); - IncludeFile("net/proto2/public/port_def.inc", p); + format("// @@protoc_insertion_point(includes)\n"); + IncludeFile("net/proto2/public/port_def.inc", printer); } -void FileGenerator::GenerateSourcePrelude(io::Printer* p) { +void FileGenerator::GenerateSourcePrelude(io::Printer* printer) { + Formatter format(printer, variables_); + // For MSVC builds, we use #pragma init_seg to move the initialization of our // libraries to happen before the user code. // This worksaround the fact that MSVC does not do constant initializers when // required by the standard. - p->Emit(R"cc( - PROTOBUF_PRAGMA_INIT_SEG - namespace _pb = ::$proto_ns$; - namespace _pbi = ::$proto_ns$::internal; - )cc"); + format("\nPROTOBUF_PRAGMA_INIT_SEG\n"); + // Generate convenience aliases. + format( + "\n" + "namespace _pb = ::$1$;\n" + "namespace _pbi = _pb::internal;\n", + ProtobufNamespace(options_)); if (HasGeneratedMethods(file_, options_) && options_.tctable_mode != Options::kTCTableNever) { - p->Emit(R"cc( - namespace _fl = ::$proto_ns$::internal::field_layout; - )cc"); + format("namespace _fl = _pbi::field_layout;\n"); } + format("\n"); } -void FileGenerator::GenerateSourceDefaultInstance(int idx, io::Printer* p) { +void FileGenerator::GenerateSourceDefaultInstance(int idx, + io::Printer* printer) { + Formatter format(printer, variables_); MessageGenerator* generator = message_generators_[idx].get(); - // Generate the split instance first because it's needed in the constexpr // constructor. - if (ShouldSplit(generator->descriptor(), options_)) { + if (ShouldSplit(generator->descriptor_, options_)) { // Use a union to disable the destructor of the _instance member. // We can constant initialize, but the object will still have a non-trivial // destructor that we need to elide. - // + format( + "struct $1$ {\n" + " PROTOBUF_CONSTEXPR $1$()\n" + " : _instance{", + DefaultInstanceType(generator->descriptor_, options_, + /*split=*/true)); + generator->GenerateInitDefaultSplitInstance(printer); + format( + "} {}\n" + " ~$1$() {}\n" + " union {\n" + " $2$ _instance;\n" + " };\n" + "};\n", + DefaultInstanceType(generator->descriptor_, options_, /*split=*/true), + StrCat(generator->classname_, "::Impl_::Split")); // NO_DESTROY is not necessary for correctness. The empty destructor is // enough. However, the empty destructor fails to be elided in some // configurations (like non-opt or with certain sanitizers). NO_DESTROY is // there just to improve performance and binary size in these builds. - p->Emit( - { - {"type", DefaultInstanceType(generator->descriptor(), options_, - /*split=*/true)}, - {"name", DefaultInstanceName(generator->descriptor(), options_, - /*split=*/true)}, - {"default", - [&] { generator->GenerateInitDefaultSplitInstance(p); }}, - {"class", absl::StrCat(ClassName(generator->descriptor()), - "::Impl_::Split")}, - }, - R"cc( - struct $type$ { - PROTOBUF_CONSTEXPR $type$() : _instance{$default$} {} - union { - $class$ _instance; - }; - }; - - PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const $type$ $name$; - )cc"); + format( + "PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT " + "PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $1$ $2$;\n", + DefaultInstanceType(generator->descriptor_, options_, /*split=*/true), + DefaultInstanceName(generator->descriptor_, options_, /*split=*/true)); } - generator->GenerateConstexprConstructor(p); + generator->GenerateConstexprConstructor(printer); + format( + "struct $1$ {\n" + " PROTOBUF_CONSTEXPR $1$()\n" + " : _instance(::_pbi::ConstantInitialized{}) {}\n" + " ~$1$() {}\n" + " union {\n" + " $2$ _instance;\n" + " };\n" + "};\n", + DefaultInstanceType(generator->descriptor_, options_), + generator->classname_); + format( + "PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT " + "PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $1$ $2$;\n", + DefaultInstanceType(generator->descriptor_, options_), + DefaultInstanceName(generator->descriptor_, options_)); - p->Emit( - { - {"type", DefaultInstanceType(generator->descriptor(), options_)}, - {"name", DefaultInstanceName(generator->descriptor(), options_)}, - {"default", [&] { generator->GenerateInitDefaultSplitInstance(p); }}, - {"class", ClassName(generator->descriptor())}, - }, - R"cc( - struct $type$ { - PROTOBUF_CONSTEXPR $type$() : _instance(::_pbi::ConstantInitialized{}) {} - ~$type$() {} - union { - $class$ _instance; - }; - }; - - PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 $type$ $name$; - )cc"); - - for (int i = 0; i < generator->descriptor()->field_count(); ++i) { - const FieldDescriptor* field = generator->descriptor()->field(i); - if (!IsStringInlined(field, options_)) { - continue; + for (int i = 0; i < generator->descriptor_->field_count(); i++) { + const FieldDescriptor* field = generator->descriptor_->field(i); + if (IsStringInlined(field, options_)) { + // Force the initialization of the inlined string in the default instance. + format( + "PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 std::true_type " + "$1$::Impl_::_init_inline_$2$_ = " + "($3$._instance.$4$.Init(), std::true_type{});\n", + ClassName(generator->descriptor_), FieldName(field), + DefaultInstanceName(generator->descriptor_, options_), + FieldMemberName(field, ShouldSplit(field, options_))); } - - // Force the initialization of the inlined string in the default instance. - p->Emit( - { - {"class", ClassName(generator->descriptor())}, - {"field", FieldName(field)}, - {"default", DefaultInstanceName(generator->descriptor(), options_)}, - {"member", FieldMemberName(field, ShouldSplit(field, options_))}, - }, - R"cc( - PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 std::true_type - $class$::Impl_::_init_inline_$field$_ = - ($default$._instance.$member$.Init(), std::true_type{}); - )cc"); } if (options_.lite_implicit_weak_fields) { - p->Emit( - { - {"ptr", DefaultInstancePtr(generator->descriptor(), options_)}, - {"name", DefaultInstanceName(generator->descriptor(), options_)}, - }, - R"cc( - PROTOBUF_CONSTINIT const void* $ptr$ = &$name$; - )cc"); + format( + "PROTOBUF_CONSTINIT const void* $1$ =\n" + " &$2$;\n", + DefaultInstancePtr(generator->descriptor_, options_), + DefaultInstanceName(generator->descriptor_, options_)); } } // A list of things defined in one .pb.cc file that we need to reference from // another .pb.cc file. struct FileGenerator::CrossFileReferences { - // When we forward-declare things, we want to create a sorted order so our - // output is deterministic and minimizes namespace changes. - struct DescCompare { - template - bool operator()(const T* const& a, const T* const& b) const { - return a->full_name() < b->full_name(); - } - - bool operator()(const FileDescriptor* const& a, - const FileDescriptor* const& b) const { - return a->name() < b->name(); - } - }; - // Populated if we are referencing from messages or files. - absl::btree_set weak_default_instances; + std::unordered_set weak_default_instances; // Only if we are referencing from files. - absl::btree_set strong_reflection_files; - absl::btree_set weak_reflection_files; + std::unordered_set strong_reflection_files; + std::unordered_set weak_reflection_files; }; void FileGenerator::GetCrossFileReferencesForField(const FieldDescriptor* field, CrossFileReferences* refs) { const Descriptor* msg = field->message_type(); - if (msg == nullptr) { - return; - } + if (msg == nullptr) return; if (IsImplicitWeakField(field, options_, &scc_analyzer_) || IsWeak(field, options_)) { @@ -656,13 +582,10 @@ void FileGenerator::GetCrossFileReferencesForFile(const FileDescriptor* file, GetCrossFileReferencesForField(field, refs); }); - if (!HasDescriptorMethods(file, options_)) { - return; - } + if (!HasDescriptorMethods(file, options_)) return; - for (int i = 0; i < file->dependency_count(); ++i) { + for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dep = file->dependency(i); - if (IsDepWeak(dep)) { refs->weak_reflection_files.insert(dep); } else { @@ -673,128 +596,119 @@ void FileGenerator::GetCrossFileReferencesForFile(const FileDescriptor* file, // Generates references to variables defined in other files. void FileGenerator::GenerateInternalForwardDeclarations( - const CrossFileReferences& refs, io::Printer* p) { - { - NamespaceOpener ns(p); - for (auto instance : refs.weak_default_instances) { - ns.ChangeTo(Namespace(instance, options_)); + const CrossFileReferences& refs, io::Printer* printer) { + Formatter format(printer, variables_); + { + NamespaceOpener ns(format); + for (auto instance : Sorted(refs.weak_default_instances)) { + ns.ChangeTo(Namespace(instance, options_)); if (options_.lite_implicit_weak_fields) { - p->Emit({{"ptr", DefaultInstancePtr(instance, options_)}}, R"cc( - PROTOBUF_CONSTINIT __attribute__((weak)) const void* $ptr$ = - &::_pbi::implicit_weak_message_default_instance; - )cc"); + format( + "PROTOBUF_CONSTINIT __attribute__((weak)) const void* $1$ =\n" + " &::_pbi::implicit_weak_message_default_instance;\n", + DefaultInstancePtr(instance, options_)); } else { - p->Emit({{"type", DefaultInstanceType(instance, options_)}, - {"name", DefaultInstanceName(instance, options_)}}, - R"cc( - extern __attribute__((weak)) $type$ $name$; - )cc"); + format("extern __attribute__((weak)) $1$ $2$;\n", + DefaultInstanceType(instance, options_), + DefaultInstanceName(instance, options_)); } } } - for (auto file : refs.weak_reflection_files) { - p->Emit({{"table", DescriptorTableName(file, options_)}}, R"cc( - extern __attribute__((weak)) const ::_pbi::DescriptorTable $table$; - )cc"); + for (auto file : Sorted(refs.weak_reflection_files)) { + format( + "extern __attribute__((weak)) const ::_pbi::DescriptorTable $1$;\n", + DescriptorTableName(file, options_)); } } -void FileGenerator::GenerateSourceForMessage(int idx, io::Printer* p) { - auto v = p->WithVars(FileVars(file_, options_)); +void FileGenerator::GenerateSourceForMessage(int idx, io::Printer* printer) { + Formatter format(printer, variables_); + GenerateSourceIncludes(printer); + GenerateSourcePrelude(printer); - GenerateSourceIncludes(p); - GenerateSourcePrelude(p); - - if (IsAnyMessage(file_, options_)) { - MuteWuninitialized(p); - } + if (IsAnyMessage(file_, options_)) MuteWuninitialized(format); CrossFileReferences refs; - ForEachField(message_generators_[idx]->descriptor(), + ForEachField(message_generators_[idx]->descriptor_, [this, &refs](const FieldDescriptor* field) { GetCrossFileReferencesForField(field, &refs); }); + GenerateInternalForwardDeclarations(refs, printer); - GenerateInternalForwardDeclarations(refs, p); + { // package namespace + NamespaceOpener ns(Namespace(file_, options_), format); + + // Define default instances + GenerateSourceDefaultInstance(idx, printer); + + // Generate classes. + format("\n"); + message_generators_[idx]->GenerateClassMethods(printer); + + format( + "\n" + "// @@protoc_insertion_point(namespace_scope)\n"); + } // end package namespace { - NamespaceOpener ns(Namespace(file_, options_), p); - p->Emit( - { - {"defaults", [&] { GenerateSourceDefaultInstance(idx, p); }}, - {"class_methods", - [&] { message_generators_[idx]->GenerateClassMethods(p); }}, - }, - R"cc( - $defaults$; - - $class_methods$; - - // @@protoc_insertion_point(namespace_scope) - )cc"); + NamespaceOpener proto_ns(ProtobufNamespace(options_), format); + message_generators_[idx]->GenerateSourceInProto2Namespace(printer); } - { - NamespaceOpener proto_ns(ProtobufNamespace(options_), p); - message_generators_[idx]->GenerateSourceInProto2Namespace(p); - } + if (IsAnyMessage(file_, options_)) UnmuteWuninitialized(format); - if (IsAnyMessage(file_, options_)) { - UnmuteWuninitialized(p); - } - - p->Emit(R"cc( - // @@protoc_insertion_point(global_scope) - )cc"); + format( + "\n" + "// @@protoc_insertion_point(global_scope)\n"); } -void FileGenerator::GenerateSourceForExtension(int idx, io::Printer* p) { - auto v = p->WithVars(FileVars(file_, options_)); - GenerateSourceIncludes(p); - GenerateSourcePrelude(p); - - NamespaceOpener ns(Namespace(file_, options_), p); - extension_generators_[idx]->GenerateDefinition(p); +void FileGenerator::GenerateSourceForExtension(int idx, io::Printer* printer) { + Formatter format(printer, variables_); + GenerateSourceIncludes(printer); + GenerateSourcePrelude(printer); + NamespaceOpener ns(Namespace(file_, options_), format); + extension_generators_[idx]->GenerateDefinition(printer); } -void FileGenerator::GenerateGlobalSource(io::Printer* p) { - auto v = p->WithVars(FileVars(file_, options_)); - GenerateSourceIncludes(p); - GenerateSourcePrelude(p); +void FileGenerator::GenerateGlobalSource(io::Printer* printer) { + Formatter format(printer, variables_); + GenerateSourceIncludes(printer); + GenerateSourcePrelude(printer); { // Define the code to initialize reflection. This code uses a global // constructor to register reflection data with the runtime pre-main. if (HasDescriptorMethods(file_, options_)) { - GenerateReflectionInitializationCode(p); + GenerateReflectionInitializationCode(printer); } } - NamespaceOpener ns(Namespace(file_, options_), p); - for (int i = 0; i < enum_generators_.size(); ++i) { - enum_generators_[i]->GenerateMethods(i, p); + NamespaceOpener ns(Namespace(file_, options_), format); + + // Generate enums. + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->GenerateMethods(i, printer); } } -void FileGenerator::GenerateSource(io::Printer* p) { - auto v = p->WithVars(FileVars(file_, options_)); - - GenerateSourceIncludes(p); - GenerateSourcePrelude(p); +void FileGenerator::GenerateSource(io::Printer* printer) { + Formatter format(printer, variables_); + GenerateSourceIncludes(printer); + GenerateSourcePrelude(printer); CrossFileReferences refs; GetCrossFileReferencesForFile(file_, &refs); - GenerateInternalForwardDeclarations(refs, p); + GenerateInternalForwardDeclarations(refs, printer); - if (IsAnyMessage(file_, options_)) { - MuteWuninitialized(p); - } + if (IsAnyMessage(file_, options_)) MuteWuninitialized(format); { - NamespaceOpener ns(Namespace(file_, options_), p); - for (int i = 0; i < message_generators_.size(); ++i) { - GenerateSourceDefaultInstance(i, p); + NamespaceOpener ns(Namespace(file_, options_), format); + + // Define default instances + for (int i = 0; i < message_generators_.size(); i++) { + GenerateSourceDefaultInstance(i, printer); } } @@ -802,155 +716,144 @@ void FileGenerator::GenerateSource(io::Printer* p) { if (HasDescriptorMethods(file_, options_)) { // Define the code to initialize reflection. This code uses a global // constructor to register reflection data with the runtime pre-main. - GenerateReflectionInitializationCode(p); + GenerateReflectionInitializationCode(printer); } } { - NamespaceOpener ns(Namespace(file_, options_), p); + NamespaceOpener ns(Namespace(file_, options_), format); // Actually implement the protos // Generate enums. - for (int i = 0; i < enum_generators_.size(); ++i) { - enum_generators_[i]->GenerateMethods(i, p); + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->GenerateMethods(i, printer); } // Generate classes. - for (int i = 0; i < message_generators_.size(); ++i) { - p->Emit(R"( - $hrule_thick$ - )"); - message_generators_[i]->GenerateClassMethods(p); + for (int i = 0; i < message_generators_.size(); i++) { + format("\n"); + format(kThickSeparator); + format("\n"); + message_generators_[i]->GenerateClassMethods(printer); } if (HasGenericServices(file_, options_)) { // Generate services. - for (int i = 0; i < service_generators_.size(); ++i) { - p->Emit(R"( - $hrule_thick$ - )"); - service_generators_[i]->GenerateImplementation(p); + for (int i = 0; i < service_generators_.size(); i++) { + if (i == 0) format("\n"); + format(kThickSeparator); + format("\n"); + service_generators_[i]->GenerateImplementation(printer); } } // Define extensions. - for (int i = 0; i < extension_generators_.size(); ++i) { - extension_generators_[i]->GenerateDefinition(p); + for (int i = 0; i < extension_generators_.size(); i++) { + extension_generators_[i]->GenerateDefinition(printer); } - p->Emit(R"cc( - // @@protoc_insertion_point(namespace_scope) - )cc"); + format( + "\n" + "// @@protoc_insertion_point(namespace_scope)\n"); } { - NamespaceOpener proto_ns(ProtobufNamespace(options_), p); - for (int i = 0; i < message_generators_.size(); ++i) { - message_generators_[i]->GenerateSourceInProto2Namespace(p); + NamespaceOpener proto_ns(ProtobufNamespace(options_), format); + for (int i = 0; i < message_generators_.size(); i++) { + message_generators_[i]->GenerateSourceInProto2Namespace(printer); } } - p->Emit(R"cc( - // @@protoc_insertion_point(global_scope) - )cc"); + format( + "\n" + "// @@protoc_insertion_point(global_scope)\n"); - if (IsAnyMessage(file_, options_)) { - UnmuteWuninitialized(p); - } + if (IsAnyMessage(file_, options_)) UnmuteWuninitialized(format); - IncludeFile("net/proto2/public/port_undef.inc", p); + IncludeFile("net/proto2/public/port_undef.inc", printer); } -void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) { - if (!message_generators_.empty()) { - p->Emit({{"len", message_generators_.size()}}, R"cc( - static ::_pb::Metadata $file_level_metadata$[$len$]; - )cc"); - } +void FileGenerator::GenerateReflectionInitializationCode(io::Printer* printer) { + Formatter format(printer, variables_); + if (!message_generators_.empty()) { + format("static ::_pb::Metadata $file_level_metadata$[$1$];\n", + message_generators_.size()); + } if (!enum_generators_.empty()) { - p->Emit({{"len", enum_generators_.size()}}, R"cc( - static const ::_pb::EnumDescriptor* $file_level_enum_descriptors$[$len$]; - )cc"); + format( + "static const ::_pb::EnumDescriptor* " + "$file_level_enum_descriptors$[$1$];\n", + enum_generators_.size()); } else { - p->Emit(R"cc( - static constexpr const ::_pb::EnumDescriptor** - $file_level_enum_descriptors$ = nullptr; - )cc"); + format( + "static " + "constexpr ::_pb::EnumDescriptor const** " + "$file_level_enum_descriptors$ = nullptr;\n"); } - if (HasGenericServices(file_, options_) && file_->service_count() > 0) { - p->Emit({{"len", file_->service_count()}}, R"cc( - static const ::_pb::ServiceDescriptor* - $file_level_service_descriptors$[$len$]; - )cc"); + format( + "static " + "const ::_pb::ServiceDescriptor* " + "$file_level_service_descriptors$[$1$];\n", + file_->service_count()); } else { - p->Emit(R"cc( - static constexpr const ::_pb::ServiceDescriptor** - $file_level_service_descriptors$ = nullptr; - )cc"); + format( + "static " + "constexpr ::_pb::ServiceDescriptor const** " + "$file_level_service_descriptors$ = nullptr;\n"); } if (!message_generators_.empty()) { - std::vector> offsets; - offsets.reserve(message_generators_.size()); - - p->Emit( - { - {"offsets", - [&] { - for (int i = 0; i < message_generators_.size(); ++i) { - offsets.push_back(message_generators_[i]->GenerateOffsets(p)); - } - }}, - {"schemas", - [&] { - int offset = 0; - for (int i = 0; i < message_generators_.size(); ++i) { - message_generators_[i]->GenerateSchema(p, offset, - offsets[i].second); - offset += offsets[i].first; - } - }}, - {"defaults", - [&] { - for (auto& gen : message_generators_) { - p->Emit( - { - {"ns", Namespace(gen->descriptor(), options_)}, - {"class", ClassName(gen->descriptor())}, - }, - R"cc( - &$ns$::_$class$_default_instance_._instance, - )cc"); - } - }}, - }, - R"cc( - const uint32_t $tablename$::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - $offsets$, - }; - - static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - $schemas$, - }; - - static const ::_pb::Message* const file_default_instances[] = { - $defaults$, - }; - )cc"); + format( + "\n" + "const $uint32$ $tablename$::offsets[] " + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); + format.Indent(); + std::vector > pairs; + pairs.reserve(message_generators_.size()); + for (int i = 0; i < message_generators_.size(); i++) { + pairs.push_back(message_generators_[i]->GenerateOffsets(printer)); + } + format.Outdent(); + format( + "};\n" + "static const ::_pbi::MigrationSchema schemas[] " + "PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {\n"); + format.Indent(); + { + int offset = 0; + for (int i = 0; i < message_generators_.size(); i++) { + message_generators_[i]->GenerateSchema(printer, offset, + pairs[i].second); + offset += pairs[i].first; + } + } + format.Outdent(); + format( + "};\n" + "\nstatic const ::_pb::Message* const file_default_instances[] = {\n"); + format.Indent(); + for (int i = 0; i < message_generators_.size(); i++) { + const Descriptor* descriptor = message_generators_[i]->descriptor_; + format("&$1$::_$2$_default_instance_._instance,\n", + Namespace(descriptor, options_), // 1 + ClassName(descriptor)); // 2 + } + format.Outdent(); + format( + "};\n" + "\n"); } else { - // Ee still need these symbols to exist. - // - // MSVC doesn't like empty arrays, so we add a dummy. - p->Emit(R"cc( - const uint32_t $tablename$::offsets[1] = {}; - static constexpr ::_pbi::MigrationSchema* schemas = nullptr; - static constexpr ::_pb::Message* const* file_default_instances = nullptr; - )cc"); + // we still need these symbols to exist + format( + // MSVC doesn't like empty arrays, so we add a dummy. + "const $uint32$ $tablename$::offsets[1] = {};\n" + "static constexpr ::_pbi::MigrationSchema* schemas = nullptr;\n" + "static constexpr ::_pb::Message* const* " + "file_default_instances = nullptr;\n" + "\n"); } // --------------------------------------------------------------- @@ -958,88 +861,63 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) { // Embed the descriptor. We simply serialize the entire // FileDescriptorProto/ and embed it as a string literal, which is parsed and // built into real descriptors at initialization time. - + const std::string protodef_name = + UniqueName("descriptor_table_protodef", file_, options_); + format("const char $1$[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) =\n", + protodef_name); + format.Indent(); FileDescriptorProto file_proto; file_->CopyTo(&file_proto); std::string file_data; file_proto.SerializeToString(&file_data); - auto desc_name = UniqueName("descriptor_table_protodef", file_, options_); - p->Emit( - {{"desc_name", desc_name}, - {"encoded_file_proto", - [&] { - absl::string_view data = file_data; - if (data.size() <= 65535) { - static constexpr size_t kBytesPerLine = 40; - while (!data.empty()) { - auto to_write = std::min(kBytesPerLine, data.size()); - auto chunk = data.substr(0, to_write); - data = data.substr(to_write); - - p->Emit({{"text", EscapeTrigraphs(absl::CEscape(chunk))}}, R"cc( - "$text$" - )cc"); - } - return; - } - - // Workaround for MSVC: "Error C1091: compiler limit: string exceeds - // 65535 bytes in length". Declare a static array of chars rather than - // use a string literal. Only write 25 bytes per line. - static constexpr size_t kBytesPerLine = 25; - while (!data.empty()) { - auto to_write = std::min(kBytesPerLine, data.size()); - auto chunk = data.substr(0, to_write); - data = data.substr(to_write); - - std::string line; - for (char c : chunk) { - absl::StrAppend(&line, "'", - absl::CEscape(absl::string_view(&c, 1)), "', "); - } - - p->Emit({{"line", line}}, R"cc( - $line$ - )cc"); - } - }}}, - R"cc( - const char $desc_name$[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - $encoded_file_proto$, - }; - )cc"); + { + if (file_data.size() > 65535) { + // Workaround for MSVC: "Error C1091: compiler limit: string exceeds + // 65535 bytes in length". Declare a static array of chars rather than + // use a string literal. Only write 25 bytes per line. + static const int kBytesPerLine = 25; + format("{ "); + for (int i = 0; i < file_data.size();) { + for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) { + format("'$1$', ", CEscape(file_data.substr(i, 1))); + } + format("\n"); + } + format("'\\0' }"); // null-terminate + } else { + // Only write 40 bytes per line. + static const int kBytesPerLine = 40; + for (int i = 0; i < file_data.size(); i += kBytesPerLine) { + format( + "\"$1$\"\n", + EscapeTrigraphs(CEscape(file_data.substr(i, kBytesPerLine)))); + } + } + format(";\n"); + } + format.Outdent(); CrossFileReferences refs; GetCrossFileReferencesForFile(file_, &refs); - size_t num_deps = + int num_deps = refs.strong_reflection_files.size() + refs.weak_reflection_files.size(); // Build array of DescriptorTable deps. if (num_deps > 0) { - p->Emit( - { - {"len", num_deps}, - {"deps", - [&] { - for (auto dep : refs.strong_reflection_files) { - p->Emit({{"name", DescriptorTableName(dep, options_)}}, R"cc( - &::$name$, - )cc"); - } - for (auto dep : refs.weak_reflection_files) { - p->Emit({{"name", DescriptorTableName(dep, options_)}}, R"cc( - &::$name$, - )cc"); - } - }}, - }, - R"cc( - static const ::_pbi::DescriptorTable* const $desc_table$_deps[$len$] = - { - $deps$, - }; - )cc"); + format( + "static const ::_pbi::DescriptorTable* const " + "$desc_table$_deps[$1$] = {\n", + num_deps); + + for (auto dep : Sorted(refs.strong_reflection_files)) { + format(" &::$1$,\n", DescriptorTableName(dep, options_)); + } + for (auto dep : Sorted(refs.weak_reflection_files)) { + format(" &::$1$,\n", DescriptorTableName(dep, options_)); + } + + format("};\n"); } // The DescriptorTable itself. @@ -1047,355 +925,342 @@ void FileGenerator::GenerateReflectionInitializationCode(io::Printer* p) { // however this might cause a tsan failure in superroot b/148382879, // so disable for now. bool eager = false; - p->Emit( - { - {"eager", eager ? "true" : "false"}, - {"file_proto_len", file_data.size()}, - {"proto_name", desc_name}, - {"deps_ptr", num_deps == 0 - ? "nullptr" - : absl::StrCat(p->LookupVar("desc_table"), "_deps")}, - {"num_deps", num_deps}, - {"num_msgs", message_generators_.size()}, - {"msgs_ptr", message_generators_.empty() - ? "nullptr" - : std::string(p->LookupVar("file_level_metadata"))}, - }, - R"cc( - static ::absl::once_flag $desc_table$_once; - const ::_pbi::DescriptorTable $desc_table$ = { - false, - $eager$, - $file_proto_len$, - $proto_name$, - "$filename$", - &$desc_table$_once, - $deps_ptr$, - $num_deps$, - $num_msgs$, - schemas, - file_default_instances, - $tablename$::offsets, - $msgs_ptr$, - $file_level_enum_descriptors$, - $file_level_service_descriptors$, - }; - - // This function exists to be marked as weak. - // It can significantly speed up compilation by breaking up LLVM's SCC - // in the .pb.cc translation units. Large translation units see a - // reduction of more than 35% of walltime for optimized builds. Without - // the weak attribute all the messages in the file, including all the - // vtables and everything they use become part of the same SCC through - // a cycle like: - // GetMetadata -> descriptor table -> default instances -> - // vtables -> GetMetadata - // By adding a weak function here we break the connection from the - // individual vtables back into the descriptor table. - PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* $desc_table$_getter() { - return &$desc_table$; - } - )cc"); + format( + "static ::_pbi::once_flag $desc_table$_once;\n" + "const ::_pbi::DescriptorTable $desc_table$ = {\n" + " false, $1$, $2$, $3$,\n" + " \"$filename$\",\n" + " &$desc_table$_once, $4$, $5$, $6$,\n" + " schemas, file_default_instances, $tablename$::offsets,\n" + " $7$, $file_level_enum_descriptors$,\n" + " $file_level_service_descriptors$,\n" + "};\n" + // This function exists to be marked as weak. + // It can significantly speed up compilation by breaking up LLVM's SCC in + // the .pb.cc translation units. Large translation units see a reduction + // of more than 35% of walltime for optimized builds. + // Without the weak attribute all the messages in the file, including all + // the vtables and everything they use become part of the same SCC through + // a cycle like: + // GetMetadata -> descriptor table -> default instances -> + // vtables -> GetMetadata + // By adding a weak function here we break the connection from the + // individual vtables back into the descriptor table. + "PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* " + "$desc_table$_getter() {\n" + " return &$desc_table$;\n" + "}\n" + "\n", + eager ? "true" : "false", file_data.size(), protodef_name, + num_deps == 0 ? "nullptr" : variables_["desc_table"] + "_deps", num_deps, + message_generators_.size(), + message_generators_.empty() ? "nullptr" + : variables_["file_level_metadata"]); // For descriptor.proto we want to avoid doing any dynamic initialization, // because in some situations that would otherwise pull in a lot of // unnecessary code that can't be stripped by --gc-sections. Descriptor // initialization will still be performed lazily when it's needed. - if (file_->name() == "net/proto2/proto/descriptor.proto") { - return; + if (file_->name() != "net/proto2/proto/descriptor.proto") { + format( + "// Force running AddDescriptors() at dynamic initialization time.\n" + "PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 " + "static ::_pbi::AddDescriptorsRunner $1$(&$desc_table$);\n", + UniqueName("dynamic_init_dummy", file_, options_)); } - - p->Emit({{"dummy", UniqueName("dynamic_init_dummy", file_, options_)}}, R"cc( - // Force running AddDescriptors() at dynamic initialization time. - PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 - static ::_pbi::AddDescriptorsRunner $dummy$(&$desc_table$); - )cc"); } class FileGenerator::ForwardDeclarations { public: - void AddMessage(const Descriptor* d) { classes_.emplace(ClassName(d), d); } - void AddEnum(const EnumDescriptor* d) { enums_.emplace(ClassName(d), d); } - void AddSplit(const Descriptor* d) { splits_.emplace(ClassName(d), d); } + void AddMessage(const Descriptor* d) { classes_[ClassName(d)] = d; } + void AddEnum(const EnumDescriptor* d) { enums_[ClassName(d)] = d; } + void AddSplit(const Descriptor* d) { splits_[ClassName(d)] = d; } - void Print(io::Printer* p, const Options& options) const { - for (const auto& e : enums_) { - p->Emit({{"enum", e.first, e.second}}, R"cc( - enum $enum$ : int; - bool $enum$_IsValid(int value); - )cc"); + void Print(const Formatter& format, const Options& options) const { + for (const auto& p : enums_) { + const std::string& enumname = p.first; + const EnumDescriptor* enum_desc = p.second; + format( + "enum ${1$$2$$}$ : int;\n" + "bool $2$_IsValid(int value);\n", + enum_desc, enumname); } - - for (const auto& c : classes_) { - const Descriptor* desc = c.second; - p->Emit( - { - {"class", c.first, desc}, - {"default_type", DefaultInstanceType(desc, options)}, - {"default_name", DefaultInstanceName(desc, options)}, - }, - R"cc( - class $class$; - struct $default_type$; - $dllexport_decl $extern $default_type$ $default_name$; - )cc"); + for (const auto& p : classes_) { + const std::string& classname = p.first; + const Descriptor* class_desc = p.second; + format( + "class ${1$$2$$}$;\n" + "struct $3$;\n" + "$dllexport_decl $extern $3$ $4$;\n", + class_desc, classname, DefaultInstanceType(class_desc, options), + DefaultInstanceName(class_desc, options)); } - - for (const auto& s : splits_) { - const Descriptor* desc = s.second; - p->Emit( - { - {"default_type", - DefaultInstanceType(desc, options, /*split=*/true)}, - {"default_name", - DefaultInstanceName(desc, options, /*split=*/true)}, - }, - R"cc( - struct $default_type$; - $dllexport_decl $extern const $default_type$ $default_name$; - )cc"); + for (const auto& p : splits_) { + const Descriptor* class_desc = p.second; + format( + "struct $1$;\n" + "$dllexport_decl $extern $1$ $2$;\n", + DefaultInstanceType(class_desc, options, /*split=*/true), + DefaultInstanceName(class_desc, options, /*split=*/true)); } } - void PrintTopLevelDecl(io::Printer* p, const Options& options) const { - for (const auto& c : classes_) { - p->Emit({{"class", QualifiedClassName(c.second, options)}}, R"cc( - template <> - $dllexport_decl $$class$* Arena::CreateMaybeMessage<$class$>(Arena*); - )cc"); + void PrintTopLevelDecl(const Formatter& format, + const Options& options) const { + for (const auto& pair : classes_) { + format( + "template<> $dllexport_decl $" + "$1$* Arena::CreateMaybeMessage<$1$>(Arena*);\n", + QualifiedClassName(pair.second, options)); } } private: - absl::btree_map classes_; - absl::btree_map enums_; - absl::btree_map splits_; + std::map classes_; + std::map enums_; + std::map splits_; }; -static void PublicImportDFS( - const FileDescriptor* fd, - absl::flat_hash_set& fd_set) { - for (int i = 0; i < fd->public_dependency_count(); ++i) { +static void PublicImportDFS(const FileDescriptor* fd, + std::unordered_set* fd_set) { + for (int i = 0; i < fd->public_dependency_count(); i++) { const FileDescriptor* dep = fd->public_dependency(i); - if (fd_set.insert(dep).second) { - PublicImportDFS(dep, fd_set); - } + if (fd_set->insert(dep).second) PublicImportDFS(dep, fd_set); } } -void FileGenerator::GenerateForwardDeclarations(io::Printer* p) { +void FileGenerator::GenerateForwardDeclarations(io::Printer* printer) { + Formatter format(printer, variables_); std::vector classes; + std::vector enums; + FlattenMessagesInFile(file_, &classes); // All messages need forward decls. - std::vector enums; if (options_.proto_h) { // proto.h needs extra forward declarations. // All classes / enums referred to as field members std::vector fields; ListAllFields(file_, &fields); - for (const auto* field : fields) { - classes.push_back(field->containing_type()); - classes.push_back(field->message_type()); - enums.push_back(field->enum_type()); + for (int i = 0; i < fields.size(); i++) { + classes.push_back(fields[i]->containing_type()); + classes.push_back(fields[i]->message_type()); + enums.push_back(fields[i]->enum_type()); } - ListAllTypesForServices(file_, &classes); } // Calculate the set of files whose definitions we get through include. // No need to forward declare types that are defined in these. - absl::flat_hash_set public_set; - PublicImportDFS(file_, public_set); + std::unordered_set public_set; + PublicImportDFS(file_, &public_set); - absl::btree_map decls; - for (const auto* d : classes) { - if (d != nullptr && !public_set.count(d->file())) + std::map decls; + for (int i = 0; i < classes.size(); i++) { + const Descriptor* d = classes[i]; + if (d && !public_set.count(d->file())) decls[Namespace(d, options_)].AddMessage(d); } - for (const auto* e : enums) { - if (e != nullptr && !public_set.count(e->file())) - decls[Namespace(e, options_)].AddEnum(e); + for (int i = 0; i < enums.size(); i++) { + const EnumDescriptor* d = enums[i]; + if (d && !public_set.count(d->file())) + decls[Namespace(d, options_)].AddEnum(d); } for (const auto& mg : message_generators_) { - const Descriptor* d = mg->descriptor(); - if (d != nullptr && public_set.count(d->file()) == 0u && - ShouldSplit(mg->descriptor(), options_)) + const Descriptor* d = mg->descriptor_; + if ((d != nullptr) && (public_set.count(d->file()) == 0u) && + ShouldSplit(mg->descriptor_, options_)) decls[Namespace(d, options_)].AddSplit(d); } - NamespaceOpener ns(p); - for (const auto& decl : decls) { - ns.ChangeTo(decl.first); - decl.second.Print(p, options_); + { + NamespaceOpener ns(format); + for (const auto& pair : decls) { + ns.ChangeTo(pair.first); + pair.second.Print(format, options_); + } } - - ns.ChangeTo("PROTOBUF_NAMESPACE_ID"); - for (const auto& decl : decls) { - decl.second.PrintTopLevelDecl(p, options_); + format("PROTOBUF_NAMESPACE_OPEN\n"); + for (const auto& pair : decls) { + pair.second.PrintTopLevelDecl(format, options_); } + format("PROTOBUF_NAMESPACE_CLOSE\n"); } -void FileGenerator::GenerateLibraryIncludes(io::Printer* p) { +void FileGenerator::GenerateTopHeaderGuard(io::Printer* printer, bool pb_h) { + Formatter format(printer, variables_); + // Generate top of header. + format( + "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "// source: $filename$\n" + "\n" + "#ifndef $1$\n" + "#define $1$\n" + "\n" + "#include \n" + "#include \n", + IncludeGuard(file_, pb_h, options_)); + if (!options_.opensource_runtime && !enum_generators_.empty()) { + // Add header to provide std::is_integral for safe Enum_Name() function. + format("#include \n"); + } + format("\n"); +} + +void FileGenerator::GenerateBottomHeaderGuard(io::Printer* printer, bool pb_h) { + Formatter format(printer, variables_); + format("#endif // $GOOGLE_PROTOBUF$_INCLUDED_$1$\n", + IncludeGuard(file_, pb_h, options_)); +} + +void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { + Formatter format(printer, variables_); if (UsingImplicitWeakFields(file_, options_)) { - IncludeFile("net/proto2/public/implicit_weak_message.h", p); + IncludeFile("net/proto2/public/implicit_weak_message.h", printer); } if (HasWeakFields(file_, options_)) { GOOGLE_CHECK(!options_.opensource_runtime); - IncludeFile("net/proto2/public/weak_field_map.h", p); + IncludeFile("net/proto2/public/weak_field_map.h", printer); } if (HasLazyFields(file_, options_, &scc_analyzer_)) { GOOGLE_CHECK(!options_.opensource_runtime); - IncludeFile("net/proto2/public/lazy_field.h", p); + IncludeFile("net/proto2/public/lazy_field.h", printer); } if (ShouldVerify(file_, options_, &scc_analyzer_)) { - IncludeFile("net/proto2/public/wire_format_verify.h", p); + IncludeFile("net/proto2/public/wire_format_verify.h", printer); } if (options_.opensource_runtime) { // Verify the protobuf library header version is compatible with the protoc // version before going any further. - IncludeFile("net/proto2/public/port_def.inc", p); - p->Emit( - { - {"min_version", PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC}, - {"version", PROTOBUF_VERSION}, - }, - R"( - #if PROTOBUF_VERSION < $min_version$ - #error "This file was generated by a newer version of protoc which is" - #error "incompatible with your Protocol Buffer headers. Please update" - #error "your headers." - #endif // PROTOBUF_VERSION - - #if $version$ < PROTOBUF_MIN_PROTOC_VERSION - #error "This file was generated by an older version of protoc which is" - #error "incompatible with your Protocol Buffer headers. Please" - #error "regenerate this file with a newer version of protoc." - #endif // PROTOBUF_MIN_PROTOC_VERSION - )"); - IncludeFile("net/proto2/public/port_undef.inc", p); + IncludeFile("net/proto2/public/port_def.inc", printer); + format( + "#if PROTOBUF_VERSION < $1$\n" + "#error This file was generated by a newer version of protoc which is\n" + "#error incompatible with your Protocol Buffer headers. Please update\n" + "#error your headers.\n" + "#endif\n" + "#if $2$ < PROTOBUF_MIN_PROTOC_VERSION\n" + "#error This file was generated by an older version of protoc which " + "is\n" + "#error incompatible with your Protocol Buffer headers. Please\n" + "#error regenerate this file with a newer version of protoc.\n" + "#endif\n" + "\n", + PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC, // 1 + PROTOBUF_VERSION); // 2 + IncludeFile("net/proto2/public/port_undef.inc", printer); } // OK, it's now safe to #include other files. - IncludeFile("net/proto2/io/public/coded_stream.h", p); - IncludeFile("net/proto2/public/arena.h", p); - IncludeFile("net/proto2/public/arenastring.h", p); + IncludeFile("net/proto2/io/public/coded_stream.h", printer); + IncludeFile("net/proto2/public/arena.h", printer); + IncludeFile("net/proto2/public/arenastring.h", printer); if ((options_.force_inline_string || options_.profile_driven_inline_string) && !options_.opensource_runtime) { - IncludeFile("net/proto2/public/inlined_string_field.h", p); + IncludeFile("net/proto2/public/inlined_string_field.h", printer); } if (HasSimpleBaseClasses(file_, options_)) { - IncludeFile("net/proto2/public/generated_message_bases.h", p); + IncludeFile("net/proto2/public/generated_message_bases.h", printer); } if (HasGeneratedMethods(file_, options_) && options_.tctable_mode != Options::kTCTableNever) { - IncludeFile("net/proto2/public/generated_message_tctable_decl.h", p); + IncludeFile("net/proto2/public/generated_message_tctable_decl.h", printer); } - IncludeFile("net/proto2/public/generated_message_util.h", p); - IncludeFile("net/proto2/public/metadata_lite.h", p); + IncludeFile("net/proto2/public/generated_message_util.h", printer); + IncludeFile("net/proto2/public/metadata_lite.h", printer); if (HasDescriptorMethods(file_, options_)) { - IncludeFile("net/proto2/public/generated_message_reflection.h", p); + IncludeFile("net/proto2/public/generated_message_reflection.h", printer); } if (!message_generators_.empty()) { if (HasDescriptorMethods(file_, options_)) { - IncludeFile("net/proto2/public/message.h", p); + IncludeFile("net/proto2/public/message.h", printer); } else { - IncludeFile("net/proto2/public/message_lite.h", p); + IncludeFile("net/proto2/public/message_lite.h", printer); } } if (options_.opensource_runtime) { // Open-source relies on unconditional includes of these. - IncludeFileAndExport("net/proto2/public/repeated_field.h", p); - IncludeFileAndExport("net/proto2/public/extension_set.h", p); + IncludeFileAndExport("net/proto2/public/repeated_field.h", printer); + IncludeFileAndExport("net/proto2/public/extension_set.h", printer); } else { // Google3 includes these files only when they are necessary. if (HasExtensionsOrExtendableMessage(file_)) { - IncludeFileAndExport("net/proto2/public/extension_set.h", p); + IncludeFileAndExport("net/proto2/public/extension_set.h", printer); } if (HasRepeatedFields(file_)) { - IncludeFileAndExport("net/proto2/public/repeated_field.h", p); + IncludeFileAndExport("net/proto2/public/repeated_field.h", printer); } if (HasStringPieceFields(file_, options_)) { - IncludeFile("net/proto2/public/string_piece_field_support.h", p); + IncludeFile("net/proto2/public/string_piece_field_support.h", printer); } if (HasCordFields(file_, options_)) { - p->Emit(R"( - #include "third_party/absl/strings/cord.h" - )"); + format("#include \"third_party/absl/strings/cord.h\"\n"); } } if (HasMapFields(file_)) { - IncludeFileAndExport("net/proto2/public/map.h", p); + IncludeFileAndExport("net/proto2/public/map.h", printer); if (HasDescriptorMethods(file_, options_)) { - IncludeFile("net/proto2/public/map_entry.h", p); - IncludeFile("net/proto2/public/map_field_inl.h", p); + IncludeFile("net/proto2/public/map_entry.h", printer); + IncludeFile("net/proto2/public/map_field_inl.h", printer); } else { - IncludeFile("net/proto2/public/map_entry_lite.h", p); - IncludeFile("net/proto2/public/map_field_lite.h", p); + IncludeFile("net/proto2/public/map_entry_lite.h", printer); + IncludeFile("net/proto2/public/map_field_lite.h", printer); } } if (HasEnumDefinitions(file_)) { if (HasDescriptorMethods(file_, options_)) { - IncludeFile("net/proto2/public/generated_enum_reflection.h", p); + IncludeFile("net/proto2/public/generated_enum_reflection.h", printer); } else { - IncludeFile("net/proto2/public/generated_enum_util.h", p); + IncludeFile("net/proto2/public/generated_enum_util.h", printer); } } if (HasGenericServices(file_, options_)) { - IncludeFile("net/proto2/public/service.h", p); + IncludeFile("net/proto2/public/service.h", printer); } if (UseUnknownFieldSet(file_, options_) && !message_generators_.empty()) { - IncludeFile("net/proto2/public/unknown_field_set.h", p); + IncludeFile("net/proto2/public/unknown_field_set.h", printer); } } -void FileGenerator::GenerateMetadataPragma(io::Printer* p, - absl::string_view info_path) { - if (info_path.empty() || options_.annotation_pragma_name.empty() || - options_.annotation_guard_name.empty()) { - return; +void FileGenerator::GenerateMetadataPragma(io::Printer* printer, + const std::string& info_path) { + Formatter format(printer, variables_); + if (!info_path.empty() && !options_.annotation_pragma_name.empty() && + !options_.annotation_guard_name.empty()) { + format.Set("guard", options_.annotation_guard_name); + format.Set("pragma", options_.annotation_pragma_name); + format.Set("info_path", info_path); + format( + "#ifdef $guard$\n" + "#pragma $pragma$ \"$info_path$\"\n" + "#endif // $guard$\n"); } - - p->Emit( - { - {"guard", options_.annotation_guard_name}, - {"pragma", options_.annotation_pragma_name}, - {"info_path", std::string(info_path)}, - }, - R"( - #ifdef $guard$ - #pragma $pragma$ "$info_path$" - #endif // $guard$ - )"); } -void FileGenerator::GenerateDependencyIncludes(io::Printer* p) { - for (int i = 0; i < file_->dependency_count(); ++i) { - const FileDescriptor* dep = file_->dependency(i); +void FileGenerator::GenerateDependencyIncludes(io::Printer* printer) { + Formatter format(printer, variables_); + for (int i = 0; i < file_->dependency_count(); i++) { + std::string basename = StripProto(file_->dependency(i)->name()); // Do not import weak deps. - if (IsDepWeak(dep)) { - continue; - } + if (IsDepWeak(file_->dependency(i))) continue; - std::string basename = StripProto(dep->name()); if (IsBootstrapProto(options_, file_)) { GetBootstrapBasename(options_, basename, &basename); } - p->Emit( - {{"name", CreateHeaderInclude(absl::StrCat(basename, ".pb.h"), dep)}}, - R"( - #include $name$ - )"); + format("#include $1$\n", + CreateHeaderInclude(basename + ".pb.h", file_->dependency(i))); } } -void FileGenerator::GenerateGlobalStateFunctionDeclarations(io::Printer* p) { +void FileGenerator::GenerateGlobalStateFunctionDeclarations( + io::Printer* printer) { + Formatter format(printer, variables_); // Forward-declare the DescriptorTable because this is referenced by .pb.cc // files depending on this file. // @@ -1403,102 +1268,114 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations(io::Printer* p) { // weak fields must refer to table struct but cannot include the header. // Also it annotates extra weak attributes. // TODO(gerbens) make sure this situation is handled better. - p->Emit(R"cc( - // Internal implementation detail -- do not use these members. - struct $dllexport_decl $$tablename$ { - static const uint32_t offsets[]; - }; - )cc"); - + format( + "\n" + "// Internal implementation detail -- do not use these members.\n" + "struct $dllexport_decl $$tablename$ {\n" + " static const $uint32$ offsets[];\n" + "};\n"); if (HasDescriptorMethods(file_, options_)) { - p->Emit(R"cc( - $dllexport_decl $extern const ::$proto_ns$::internal::DescriptorTable - $desc_table$; - )cc"); + format( + "$dllexport_decl $extern const ::$proto_ns$::internal::DescriptorTable " + "$desc_table$;\n"); } } -void FileGenerator::GenerateMessageDefinitions(io::Printer* p) { - for (int i = 0; i < message_generators_.size(); ++i) { - p->Emit(R"cc( - $hrule_thin$ - )cc"); - message_generators_[i]->GenerateClassDefinition(p); +void FileGenerator::GenerateMessageDefinitions(io::Printer* printer) { + Formatter format(printer, variables_); + // Generate class definitions. + for (int i = 0; i < message_generators_.size(); i++) { + if (i > 0) { + format("\n"); + format(kThinSeparator); + format("\n"); + } + message_generators_[i]->GenerateClassDefinition(printer); } } -void FileGenerator::GenerateEnumDefinitions(io::Printer* p) { - for (int i = 0; i < enum_generators_.size(); ++i) { - enum_generators_[i]->GenerateDefinition(p); +void FileGenerator::GenerateEnumDefinitions(io::Printer* printer) { + // Generate enum definitions. + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->GenerateDefinition(printer); } } -void FileGenerator::GenerateServiceDefinitions(io::Printer* p) { - if (!HasGenericServices(file_, options_)) { - return; - } +void FileGenerator::GenerateServiceDefinitions(io::Printer* printer) { + Formatter format(printer, variables_); + if (HasGenericServices(file_, options_)) { + // Generate service definitions. + for (int i = 0; i < service_generators_.size(); i++) { + if (i > 0) { + format("\n"); + format(kThinSeparator); + format("\n"); + } + service_generators_[i]->GenerateDeclarations(printer); + } - for (int i = 0; i < service_generators_.size(); ++i) { - p->Emit(R"cc( - $hrule_thin$ - )cc"); - service_generators_[i]->GenerateDeclarations(p); + format("\n"); + format(kThickSeparator); + format("\n"); } - - p->Emit(R"cc( - $hrule_thick$ - )cc"); } -void FileGenerator::GenerateExtensionIdentifiers(io::Printer* p) { +void FileGenerator::GenerateExtensionIdentifiers(io::Printer* printer) { // Declare extension identifiers. These are in global scope and so only // the global scope extensions. for (auto& extension_generator : extension_generators_) { - if (extension_generator->IsScoped()) { - continue; - } - extension_generator->GenerateDeclaration(p); + if (extension_generator->IsScoped()) continue; + extension_generator->GenerateDeclaration(printer); } } -void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* p) { +void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) { + Formatter format(printer, variables_); // TODO(gerbens) remove pragmas when gcc is no longer used. Current version // of gcc fires a bogus error when compiled with strict-aliasing. - p->Emit(R"( - #ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" - #endif // __GNUC__ - )"); - - for (int i = 0; i < message_generators_.size(); ++i) { - p->Emit(R"cc( - $hrule_thin$ - )cc"); - message_generators_[i]->GenerateInlineMethods(p); + format( + "#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) { + format(kThinSeparator); + format("\n"); + } + message_generators_[i]->GenerateInlineMethods(printer); } + format( + "#ifdef __GNUC__\n" + " #pragma GCC diagnostic pop\n" + "#endif // __GNUC__\n"); - p->Emit(R"( - #ifdef __GNUC__ - #pragma GCC diagnostic pop - #endif // __GNUC__ - )"); + for (int i = 0; i < message_generators_.size(); i++) { + if (i > 0) { + format(kThinSeparator); + format("\n"); + } + } } -void FileGenerator::GenerateProto2NamespaceEnumSpecializations(io::Printer* p) { - // Emit GetEnumDescriptor specializations into google::protobuf namespace. - if (!HasEnumDefinitions(file_)) { - return; +void FileGenerator::GenerateProto2NamespaceEnumSpecializations( + io::Printer* printer) { + Formatter format(printer, variables_); + // Emit GetEnumDescriptor specializations into google::protobuf namespace: + if (HasEnumDefinitions(file_)) { + format("\n"); + { + NamespaceOpener proto_ns(ProtobufNamespace(options_), format); + format("\n"); + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer); + } + format("\n"); + } } - - p->PrintRaw("\n"); - NamespaceOpener ns(ProtobufNamespace(options_), p); - p->PrintRaw("\n"); - for (auto& gen : enum_generators_) { - gen->GenerateGetEnumDescriptorSpecializations(p); - } - p->PrintRaw("\n"); } + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/file.h b/libs/protobuf/src/google/protobuf/compiler/cpp/file.h index cd38345..ca05361 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/file.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/file.h @@ -36,47 +36,52 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__ #include -#include #include #include #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/compiler/scc.h" -#include "absl/container/flat_hash_set.h" -#include "google/protobuf/compiler/cpp/enum.h" -#include "google/protobuf/compiler/cpp/extension.h" -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/message.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/compiler/cpp/service.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include +namespace google { +namespace protobuf { +class FileDescriptor; // descriptor.h +namespace io { +class Printer; // printer.h +} +} // namespace protobuf +} // namespace google namespace google { namespace protobuf { namespace compiler { namespace cpp { + +class EnumGenerator; // enum.h +class MessageGenerator; // message.h +class ServiceGenerator; // service.h +class ExtensionGenerator; // extension.h + class FileGenerator { public: + // See generator.cc for the meaning of dllexport_decl. FileGenerator(const FileDescriptor* file, const Options& options); + ~FileGenerator(); - FileGenerator(const FileGenerator&) = delete; - FileGenerator& operator=(const FileGenerator&) = delete; - - ~FileGenerator() = default; + // Shared code between the two header generators below. + void GenerateHeader(io::Printer* printer); // info_path, if non-empty, should be the path (relative to printer's // output) to the metadata file describing this proto header. - void GenerateProtoHeader(io::Printer* p, absl::string_view info_path); + void GenerateProtoHeader(io::Printer* printer, const std::string& info_path); // info_path, if non-empty, should be the path (relative to printer's // output) to the metadata file describing this PB header. - void GeneratePBHeader(io::Printer* p, absl::string_view info_path); - void GenerateSource(io::Printer* p); + void GeneratePBHeader(io::Printer* printer, const std::string& info_path); + void GenerateSource(io::Printer* printer); // The following member functions are used when the lite_implicit_weak_fields // option is set. In this mode the code is organized a bit differently to @@ -87,86 +92,78 @@ class FileGenerator { int NumMessages() const { return message_generators_.size(); } int NumExtensions() const { return extension_generators_.size(); } // Generates the source file for one message. - void GenerateSourceForMessage(int idx, io::Printer* p); + void GenerateSourceForMessage(int idx, io::Printer* printer); // Generates the source file for one extension. - void GenerateSourceForExtension(int idx, io::Printer* p); + void GenerateSourceForExtension(int idx, io::Printer* printer); // Generates a source file containing everything except messages and // extensions. - void GenerateGlobalSource(io::Printer* p); + void GenerateGlobalSource(io::Printer* printer); private: - // Generates a file, setting up the necessary accoutrements that start and - // end the file, calling `cb` in between. - // - // This includes header guards and file-global variables. - void GenerateFile(io::Printer* p, GeneratedFileType file_type, - std::function cb); - - // Shared code between the two header generators. - void GenerateSharedHeaderCode(io::Printer* p); - // Internal type used by GenerateForwardDeclarations (defined in file.cc). class ForwardDeclarations; struct CrossFileReferences; - void IncludeFile(absl::string_view google3_name, io::Printer* p) { - DoIncludeFile(google3_name, false, p); + void IncludeFile(const std::string& google3_name, io::Printer* printer) { + DoIncludeFile(google3_name, false, printer); } - void IncludeFileAndExport(absl::string_view google3_name, io::Printer* p) { - DoIncludeFile(google3_name, true, p); + void IncludeFileAndExport(const std::string& google3_name, + io::Printer* printer) { + DoIncludeFile(google3_name, true, printer); } - void DoIncludeFile(absl::string_view google3_name, bool do_export, - io::Printer* p); + void DoIncludeFile(const std::string& google3_name, bool do_export, + io::Printer* printer); - std::string CreateHeaderInclude(absl::string_view basename, + std::string CreateHeaderInclude(const std::string& basename, const FileDescriptor* file); void GetCrossFileReferencesForField(const FieldDescriptor* field, CrossFileReferences* refs); void GetCrossFileReferencesForFile(const FileDescriptor* file, CrossFileReferences* refs); void GenerateInternalForwardDeclarations(const CrossFileReferences& refs, - io::Printer* p); - void GenerateSourceIncludes(io::Printer* p); - void GenerateSourcePrelude(io::Printer* p); - void GenerateSourceDefaultInstance(int idx, io::Printer* p); + io::Printer* printer); + void GenerateSourceIncludes(io::Printer* printer); + void GenerateSourcePrelude(io::Printer* printer); + void GenerateSourceDefaultInstance(int idx, io::Printer* printer); void GenerateInitForSCC(const SCC* scc, const CrossFileReferences& refs, - io::Printer* p); - void GenerateReflectionInitializationCode(io::Printer* p); + io::Printer* printer); + void GenerateReflectionInitializationCode(io::Printer* printer); // For other imports, generates their forward-declarations. - void GenerateForwardDeclarations(io::Printer* p); + void GenerateForwardDeclarations(io::Printer* printer); // Generates top or bottom of a header file. - void GenerateTopHeaderGuard(io::Printer* p, GeneratedFileType file_type); - void GenerateBottomHeaderGuard(io::Printer* p, GeneratedFileType file_type); + void GenerateTopHeaderGuard(io::Printer* printer, bool pb_h); + void GenerateBottomHeaderGuard(io::Printer* printer, bool pb_h); // Generates #include directives. - void GenerateLibraryIncludes(io::Printer* p); - void GenerateDependencyIncludes(io::Printer* p); + void GenerateLibraryIncludes(io::Printer* printer); + void GenerateDependencyIncludes(io::Printer* printer); // Generate a pragma to pull in metadata using the given info_path (if // non-empty). info_path should be relative to printer's output. - void GenerateMetadataPragma(io::Printer* p, absl::string_view info_path); + void GenerateMetadataPragma(io::Printer* printer, + const std::string& info_path); // Generates a couple of different pieces before definitions: - void GenerateGlobalStateFunctionDeclarations(io::Printer* p); + void GenerateGlobalStateFunctionDeclarations(io::Printer* printer); // Generates types for classes. - void GenerateMessageDefinitions(io::Printer* p); + void GenerateMessageDefinitions(io::Printer* printer); - void GenerateEnumDefinitions(io::Printer* p); + void GenerateEnumDefinitions(io::Printer* printer); // Generates generic service definitions. - void GenerateServiceDefinitions(io::Printer* p); + void GenerateServiceDefinitions(io::Printer* printer); // Generates extension identifiers. - void GenerateExtensionIdentifiers(io::Printer* p); + void GenerateExtensionIdentifiers(io::Printer* printer); // Generates inline function definitions. - void GenerateInlineFunctionDefinitions(io::Printer* p); + void GenerateInlineFunctionDefinitions(io::Printer* printer); - void GenerateProto2NamespaceEnumSpecializations(io::Printer* p); + void GenerateProto2NamespaceEnumSpecializations(io::Printer* printer); // Sometimes the names we use in a .proto file happen to be defined as // macros on some platforms (e.g., macro/minor used in plugin.proto are @@ -175,7 +172,7 @@ class FileGenerator { // undef the macro for these few platforms, or rename the field name for all // platforms. Since these names are part of protobuf public API, renaming is // generally a breaking change so we prefer the #undef approach. - void GenerateMacroUndefs(io::Printer* p); + void GenerateMacroUndefs(io::Printer* printer); bool IsDepWeak(const FileDescriptor* dep) const { if (weak_deps_.count(dep) != 0) { @@ -185,16 +182,13 @@ class FileGenerator { return false; } - absl::flat_hash_set weak_deps_; + std::set weak_deps_; const FileDescriptor* file_; - Options options_; + const Options options_; MessageSCCAnalyzer scc_analyzer_; - // This member is unused and should be deleted once all old-style variable - // maps are gone. - // TODO(b/245791219) std::map variables_; // Contains the post-order walk of all the messages (and child messages) in @@ -203,6 +197,8 @@ class FileGenerator { std::vector> enum_generators_; std::vector> service_generators_; std::vector> extension_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/generator.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/generator.cc index 56a2012..63a2bce 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/generator.cc @@ -32,66 +32,31 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/generator.h" +#include #include #include #include #include -#include "google/protobuf/stubs/strutil.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/compiler/cpp/file.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { + +CppGenerator::CppGenerator() {} +CppGenerator::~CppGenerator() {} + namespace { -std::string NumberedCcFileName(absl::string_view basename, int number) { - return absl::StrCat(basename, ".out/", number, ".cc"); -} - -absl::flat_hash_map CommonVars( - const Options& options) { - bool is_oss = options.opensource_runtime; - return { - {"proto_ns", ProtobufNamespace(options)}, - {"string", "std::string"}, - {"int8", "int8_t"}, - {"int32", "int32_t"}, - {"int64", "int64_t"}, - {"uint8", "uint8_t"}, - {"uint32", "uint32_t"}, - {"uint64", "uint64_t"}, - - {"hrule_thick", kThickSeparator}, - {"hrule_thin", kThinSeparator}, - - // Warning: there is some clever naming/splitting here to avoid extract - // script rewrites. The names of these variables must not be things that - // the extract script will rewrite. That's why we use "CHK" (for example) - // instead of "GOOGLE_CHECK". - // - // These values are things the extract script would rewrite if we did not - // split them. It might not strictly matter since we don't generate - // google3 code in open-source. But it's good to prevent surprising - // things from happening. - {"GOOGLE_PROTOBUF", is_oss ? "GOOGLE_PROTOBUF" - : "GOOGLE3_PROTOBU" - "F"}, - {"CHK", is_oss ? "GOOGLE_CHECK" - : "CHEC" - "K"}, - {"DCHK", is_oss ? "GOOGLE_DCHECK" - : "DCHEC" - "K"}, - }; +std::string NumberedCcFileName(const std::string& basename, int number) { + return StrCat(basename, ".out/", number, ".cc"); } } // namespace @@ -99,7 +64,7 @@ bool CppGenerator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const { - std::vector> options; + std::vector > options; ParseGeneratorParameter(parameter, &options); // ----------------------------------------------------------------- @@ -128,71 +93,70 @@ bool CppGenerator::Generate(const FileDescriptor* file, file_options.opensource_runtime = opensource_runtime_; file_options.runtime_include_base = runtime_include_base_; - for (const auto& option : options) { - const auto& key = option.first; - const auto& value = option.second; - - if (key == "dllexport_decl") { - file_options.dllexport_decl = value; - } else if (key == "safe_boundary_check") { + for (int i = 0; i < options.size(); i++) { + if (options[i].first == "dllexport_decl") { + file_options.dllexport_decl = options[i].second; + } else if (options[i].first == "safe_boundary_check") { file_options.safe_boundary_check = true; - } else if (key == "annotate_headers") { + } else if (options[i].first == "annotate_headers") { file_options.annotate_headers = true; - } else if (key == "annotation_pragma_name") { - file_options.annotation_pragma_name = value; - } else if (key == "annotation_guard_name") { - file_options.annotation_guard_name = value; - } else if (key == "speed") { + } else if (options[i].first == "annotation_pragma_name") { + file_options.annotation_pragma_name = options[i].second; + } else if (options[i].first == "annotation_guard_name") { + file_options.annotation_guard_name = options[i].second; + } else if (options[i].first == "speed") { file_options.enforce_mode = EnforceOptimizeMode::kSpeed; - } else if (key == "code_size") { + } else if (options[i].first == "code_size") { file_options.enforce_mode = EnforceOptimizeMode::kCodeSize; - } else if (key == "lite") { + } else if (options[i].first == "lite") { file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime; - } else if (key == "lite_implicit_weak_fields") { + } else if (options[i].first == "lite_implicit_weak_fields") { file_options.enforce_mode = EnforceOptimizeMode::kLiteRuntime; file_options.lite_implicit_weak_fields = true; - if (!value.empty()) { - file_options.num_cc_files = strto32(value.c_str(), nullptr, 10); + if (!options[i].second.empty()) { + file_options.num_cc_files = + strto32(options[i].second.c_str(), nullptr, 10); } - } else if (key == "proto_h") { + } else if (options[i].first == "proto_h") { file_options.proto_h = true; - } else if (key == "proto_static_reflection_h") { - } else if (key == "annotate_accessor") { + } else if (options[i].first == "annotate_accessor") { file_options.annotate_accessor = true; - } else if (key == "inject_field_listener_events") { + } else if (options[i].first == "inject_field_listener_events") { file_options.field_listener_options.inject_field_listener_events = true; - } else if (key == "forbidden_field_listener_events") { + } else if (options[i].first == "forbidden_field_listener_events") { std::size_t pos = 0; do { - std::size_t next_pos = value.find_first_of("+", pos); + std::size_t next_pos = options[i].second.find_first_of("+", pos); if (next_pos == std::string::npos) { - next_pos = value.size(); + next_pos = options[i].second.size(); } if (next_pos > pos) file_options.field_listener_options.forbidden_field_listener_events - .insert(value.substr(pos, next_pos - pos)); + .insert(options[i].second.substr(pos, next_pos - pos)); pos = next_pos + 1; - } while (pos < value.size()); - } else if (key == "unverified_lazy_message_sets") { + } while (pos < options[i].second.size()); + } else if (options[i].first == "verified_lazy") { + file_options.unverified_lazy = false; + } else if (options[i].first == "unverified_lazy_message_sets") { file_options.unverified_lazy_message_sets = true; - } else if (key == "message_owned_arena_trial") { + } else if (options[i].first == "message_owned_arena_trial") { file_options.message_owned_arena_trial = true; - } else if (key == "force_eagerly_verified_lazy") { + } else if (options[i].first == "force_eagerly_verified_lazy") { file_options.force_eagerly_verified_lazy = true; - } else if (key == "experimental_tail_call_table_mode") { - if (value == "never") { + } else if (options[i].first == "experimental_tail_call_table_mode") { + if (options[i].second == "never") { file_options.tctable_mode = Options::kTCTableNever; - } else if (value == "guarded") { + } else if (options[i].second == "guarded") { file_options.tctable_mode = Options::kTCTableGuarded; - } else if (value == "always") { + } else if (options[i].second == "always") { file_options.tctable_mode = Options::kTCTableAlways; } else { - *error = - "Unknown value for experimental_tail_call_table_mode: " + value; + *error = "Unknown value for experimental_tail_call_table_mode: " + + options[i].second; return false; } } else { - *error = "Unknown generator option: " + key; + *error = "Unknown generator option: " + options[i].first; return false; } } @@ -210,17 +174,6 @@ bool CppGenerator::Generate(const FileDescriptor* file, std::string basename = StripProto(file->name()); - auto generate_reserved_static_reflection_header = [&basename, - &generator_context]() { - auto output = absl::WrapUnique(generator_context->Open( - absl::StrCat(basename, ".proto.static_reflection.h"))); - io::Printer(output.get()).Emit(R"cc( - // Reserved for future use. - )cc"); - }; - // Suppress maybe unused warning. - (void)generate_reserved_static_reflection_header; - if (MaybeBootstrap(file_options, generator_context, file_options.bootstrap, &basename)) { return true; @@ -230,51 +183,39 @@ bool CppGenerator::Generate(const FileDescriptor* file, // Generate header(s). if (file_options.proto_h) { - auto output = absl::WrapUnique( - generator_context->Open(absl::StrCat(basename, ".proto.h"))); - + std::unique_ptr output( + generator_context->Open(basename + ".proto.h")); GeneratedCodeInfo annotations; io::AnnotationProtoCollector annotation_collector( &annotations); - io::Printer::Options options; - if (file_options.annotate_headers) { - options.annotation_collector = &annotation_collector; - } - - io::Printer p(output.get(), options); - auto v = p.WithVars(CommonVars(file_options)); - - std::string info_path = absl::StrCat(basename, ".proto.h.meta"); + std::string info_path = basename + ".proto.h.meta"; + io::Printer printer( + output.get(), '$', + file_options.annotate_headers ? &annotation_collector : nullptr); file_generator.GenerateProtoHeader( - &p, file_options.annotate_headers ? info_path : ""); - + &printer, file_options.annotate_headers ? info_path : ""); if (file_options.annotate_headers) { - auto info_output = absl::WrapUnique(generator_context->Open(info_path)); + std::unique_ptr info_output( + generator_context->Open(info_path)); annotations.SerializeToZeroCopyStream(info_output.get()); } } { - auto output = absl::WrapUnique( - generator_context->Open(absl::StrCat(basename, ".pb.h"))); - + std::unique_ptr output( + generator_context->Open(basename + ".pb.h")); GeneratedCodeInfo annotations; io::AnnotationProtoCollector annotation_collector( &annotations); - io::Printer::Options options; - if (file_options.annotate_headers) { - options.annotation_collector = &annotation_collector; - } - - io::Printer p(output.get(), options); - auto v = p.WithVars(CommonVars(file_options)); - - std::string info_path = absl::StrCat(basename, ".pb.h.meta"); + std::string info_path = basename + ".pb.h.meta"; + io::Printer printer( + output.get(), '$', + file_options.annotate_headers ? &annotation_collector : nullptr); file_generator.GeneratePBHeader( - &p, file_options.annotate_headers ? info_path : ""); - + &printer, file_options.annotate_headers ? info_path : ""); if (file_options.annotate_headers) { - auto info_output = absl::WrapUnique(generator_context->Open(info_path)); + std::unique_ptr info_output( + generator_context->Open(info_path)); annotations.SerializeToZeroCopyStream(info_output.get()); } } @@ -284,12 +225,10 @@ bool CppGenerator::Generate(const FileDescriptor* file, { // This is the global .cc file, containing // enum/services/tables/reflection - auto output = absl::WrapUnique( - generator_context->Open(absl::StrCat(basename, ".pb.cc"))); - io::Printer p(output.get()); - auto v = p.WithVars(CommonVars(file_options)); - - file_generator.GenerateGlobalSource(&p); + std::unique_ptr output( + generator_context->Open(basename + ".pb.cc")); + io::Printer printer(output.get(), '$'); + file_generator.GenerateGlobalSource(&printer); } int num_cc_files = @@ -305,43 +244,35 @@ bool CppGenerator::Generate(const FileDescriptor* file, "and extensions."; num_cc_files = file_options.num_cc_files; } - int cc_file_number = 0; - for (int i = 0; i < file_generator.NumMessages(); ++i) { - auto output = absl::WrapUnique(generator_context->Open( + for (int i = 0; i < file_generator.NumMessages(); i++) { + std::unique_ptr output(generator_context->Open( NumberedCcFileName(basename, cc_file_number++))); - io::Printer p(output.get()); - auto v = p.WithVars(CommonVars(file_options)); - - file_generator.GenerateSourceForMessage(i, &p); + io::Printer printer(output.get(), '$'); + file_generator.GenerateSourceForMessage(i, &printer); } - - for (int i = 0; i < file_generator.NumExtensions(); ++i) { - auto output = absl::WrapUnique(generator_context->Open( + for (int i = 0; i < file_generator.NumExtensions(); i++) { + std::unique_ptr output(generator_context->Open( NumberedCcFileName(basename, cc_file_number++))); - io::Printer p(output.get()); - auto v = p.WithVars(CommonVars(file_options)); - - file_generator.GenerateSourceForExtension(i, &p); + io::Printer printer(output.get(), '$'); + file_generator.GenerateSourceForExtension(i, &printer); } - // Create empty placeholder files if necessary to match the expected number // of files. - while (cc_file_number < num_cc_files) { - (void)absl::WrapUnique(generator_context->Open( - NumberedCcFileName(basename, cc_file_number++))); + for (; cc_file_number < num_cc_files; ++cc_file_number) { + std::unique_ptr output(generator_context->Open( + NumberedCcFileName(basename, cc_file_number))); } } else { - auto output = absl::WrapUnique( - generator_context->Open(absl::StrCat(basename, ".pb.cc"))); - io::Printer p(output.get()); - auto v = p.WithVars(CommonVars(file_options)); - - file_generator.GenerateSource(&p); + std::unique_ptr output( + generator_context->Open(basename + ".pb.cc")); + io::Printer printer(output.get(), '$'); + file_generator.GenerateSource(&printer); } return true; } + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/generator.h b/libs/protobuf/src/google/protobuf/compiler/cpp/generator.h index aa4ee82..1a374b9 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/generator.h @@ -38,27 +38,24 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ #include -#include - -#include "google/protobuf/compiler/code_generator.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { + // CodeGenerator implementation which generates a C++ source file and // header. If you create your own protocol compiler binary and you want // it to support C++ output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. class PROTOC_EXPORT CppGenerator : public CodeGenerator { public: - CppGenerator() = default; - CppGenerator(const CppGenerator&) = delete; - CppGenerator& operator=(const CppGenerator&) = delete; - ~CppGenerator() override = default; + CppGenerator(); + ~CppGenerator() override; enum class Runtime { kGoogle3, // Use the internal google3 runtime. @@ -77,29 +74,34 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator { // If set to a non-empty string, generated code will do: // #include "/google/protobuf/message.h" // instead of: - // #include "google/protobuf/message.h" + // #include // This has no effect if opensource_runtime = false. - void set_runtime_include_base(std::string base) { - runtime_include_base_ = std::move(base); + void set_runtime_include_base(const std::string& base) { + runtime_include_base_ = base; } + // implements CodeGenerator ---------------------------------------- bool Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const override; uint64_t GetSupportedFeatures() const override { + // We don't fully support this yet, but this is needed to unblock the tests, + // and we will have full support before the experimental flag is removed. return FEATURE_PROTO3_OPTIONAL; } private: - bool opensource_runtime_ = PROTO2_IS_OSS; + bool opensource_runtime_ = true; std::string runtime_include_base_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator); }; + } // namespace cpp } // namespace compiler } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.cc index e17ccc5..4b7c5c9 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.cc @@ -32,46 +32,35 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/helpers.h" +#include -#include #include #include #include #include #include #include -#include -#include -#include +#include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/compiler/scc.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" -#include "absl/strings/substitute.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/compiler/cpp/names.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/descriptor.pb.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -83,12 +72,11 @@ namespace { static const char kAnyMessageName[] = "Any"; static const char kAnyProtoFile[] = "google/protobuf/any.proto"; -std::string DotsToColons(absl::string_view name) { - return absl::StrReplaceAll(name, {{".", "::"}}); +std::string DotsToColons(const std::string& name) { + return StringReplace(name, ".", "::", true); } -static const char* const kKeywordList[] = { - // +static const char* const kKeywordList[] = { // "NULL", "alignas", "alignof", @@ -171,43 +159,48 @@ static const char* const kKeywordList[] = { "wchar_t", "while", "xor", - "xor_eq", -#ifdef PROTOBUF_FUTURE_CPP20_KEYWORDS // C++20 keywords. - "char8_t", - "char16_t", - "char32_t", - "concept", - "consteval", - "constinit", - "co_await", - "co_return", - "co_yield", - "requires", -#endif // !PROTOBUF_FUTURE_BREAKING_CHANGES -}; + "xor_eq"}; -const absl::flat_hash_set& Keywords() { - static const auto* keywords = [] { - auto* keywords = new absl::flat_hash_set(); - - for (const auto keyword : kKeywordList) { - keywords->emplace(keyword); - } - return keywords; - }(); - return *keywords; +static std::unordered_set* MakeKeywordsMap() { + auto* result = new std::unordered_set(); + for (const auto keyword : kKeywordList) { + result->emplace(keyword); + } + return result; } +static std::unordered_set& kKeywords = *MakeKeywordsMap(); + std::string IntTypeName(const Options& options, const std::string& type) { return type + "_t"; } +void SetIntVar(const Options& options, const std::string& type, + std::map* variables) { + (*variables)[type] = IntTypeName(options, type); +} + // Returns true if the message can potentially allocate memory for its field. // This is used to determine if message-owned arena will be useful. bool AllocExpected(const Descriptor* descriptor) { return false; } +// Describes different approaches to detect non-canonical int32 encoding. Only +// kNever or kAlways is eligible for *simple* verification methods. +enum class VerifyInt32Type { + kCustom, // Only check if field number matches. + kNever, // Do not check. + kAlways, // Always check. +}; + +inline VerifySimpleType VerifyInt32TypeToVerifyCustom(VerifyInt32Type t) { + static VerifySimpleType kCustomTypes[] = { + VerifySimpleType::kCustom, VerifySimpleType::kCustomInt32Never, + VerifySimpleType::kCustomInt32Always}; + return kCustomTypes[static_cast(t) - + static_cast(VerifyInt32Type::kCustom)]; +} } // namespace @@ -235,66 +228,83 @@ bool IsLazilyVerifiedLazy(const FieldDescriptor* field, return false; } -absl::flat_hash_map MessageVars( - const Descriptor* desc) { - absl::string_view prefix = IsMapEntryMessage(desc) ? "" : "_impl_."; - return { - {"any_metadata", absl::StrCat(prefix, "_any_metadata_")}, - {"cached_size", absl::StrCat(prefix, "_cached_size_")}, - {"extensions", absl::StrCat(prefix, "_extensions_")}, - {"has_bits", absl::StrCat(prefix, "_has_bits_")}, - {"inlined_string_donated_array", - absl::StrCat(prefix, "_inlined_string_donated_")}, - {"oneof_case", absl::StrCat(prefix, "_oneof_case_")}, - {"tracker", "Impl_::_tracker_"}, - {"weak_field_map", absl::StrCat(prefix, "_weak_field_map_")}, - {"split", absl::StrCat(prefix, "_split_")}, - {"cached_split_ptr", "cached_split_ptr"}, - }; +void SetCommonVars(const Options& options, + std::map* variables) { + (*variables)["proto_ns"] = ProtobufNamespace(options); + + // Warning: there is some clever naming/splitting here to avoid extract script + // rewrites. The names of these variables must not be things that the extract + // script will rewrite. That's why we use "CHK" (for example) instead of + // "GOOGLE_CHECK". + if (options.opensource_runtime) { + (*variables)["GOOGLE_PROTOBUF"] = "GOOGLE_PROTOBUF"; + (*variables)["CHK"] = "GOOGLE_CHECK"; + (*variables)["DCHK"] = "GOOGLE_DCHECK"; + } else { + // These values are things the extract script would rewrite if we did not + // split them. It might not strictly matter since we don't generate google3 + // code in open-source. But it's good to prevent surprising things from + // happening. + (*variables)["GOOGLE_PROTOBUF"] = + "GOOGLE3" + "_PROTOBUF"; + (*variables)["CHK"] = + "CH" + "ECK"; + (*variables)["DCHK"] = + "DCH" + "ECK"; + } + + SetIntVar(options, "int8", variables); + SetIntVar(options, "uint8", variables); + SetIntVar(options, "uint32", variables); + SetIntVar(options, "uint64", variables); + SetIntVar(options, "int32", variables); + SetIntVar(options, "int64", variables); + (*variables)["string"] = "std::string"; } void SetCommonMessageDataVariables( const Descriptor* descriptor, std::map* variables) { - for (auto& pair : MessageVars(descriptor)) { - variables->emplace(pair); - } -} - -absl::flat_hash_map UnknownFieldsVars( - const Descriptor* desc, const Options& opts) { - std::string proto_ns = ProtobufNamespace(opts); - - std::string unknown_fields_type; - std::string default_instance; - if (UseUnknownFieldSet(desc->file(), opts)) { - unknown_fields_type = absl::StrCat("::", proto_ns, "::UnknownFieldSet"); - default_instance = absl::StrCat(unknown_fields_type, "::default_instance"); - } else { - unknown_fields_type = - PrimitiveTypeName(opts, FieldDescriptor::CPPTYPE_STRING); - default_instance = - absl::StrCat("::", proto_ns, "::internal::GetEmptyString"); - } - - return { - {"unknown_fields", - absl::Substitute("_internal_metadata_.unknown_fields<$0>($1)", - unknown_fields_type, default_instance)}, - {"unknown_fields_type", unknown_fields_type}, - {"have_unknown_fields", "_internal_metadata_.have_unknown_fields()"}, - {"mutable_unknown_fields", - absl::Substitute("_internal_metadata_.mutable_unknown_fields<$0>()", - unknown_fields_type)}, - }; + std::string prefix = IsMapEntryMessage(descriptor) ? "" : "_impl_."; + (*variables)["any_metadata"] = prefix + "_any_metadata_"; + (*variables)["cached_size"] = prefix + "_cached_size_"; + (*variables)["extensions"] = prefix + "_extensions_"; + (*variables)["has_bits"] = prefix + "_has_bits_"; + (*variables)["inlined_string_donated_array"] = + prefix + "_inlined_string_donated_"; + (*variables)["oneof_case"] = prefix + "_oneof_case_"; + (*variables)["tracker"] = "Impl_::_tracker_"; + (*variables)["weak_field_map"] = prefix + "_weak_field_map_"; + (*variables)["split"] = prefix + "_split_"; + (*variables)["cached_split_ptr"] = "cached_split_ptr"; } void SetUnknownFieldsVariable(const Descriptor* descriptor, const Options& options, std::map* variables) { - for (auto& pair : UnknownFieldsVars(descriptor, options)) { - variables->emplace(pair); + std::string proto_ns = ProtobufNamespace(options); + std::string unknown_fields_type; + if (UseUnknownFieldSet(descriptor->file(), options)) { + unknown_fields_type = "::" + proto_ns + "::UnknownFieldSet"; + (*variables)["unknown_fields"] = + "_internal_metadata_.unknown_fields<" + unknown_fields_type + ">(" + + unknown_fields_type + "::default_instance)"; + } else { + unknown_fields_type = + PrimitiveTypeName(options, FieldDescriptor::CPPTYPE_STRING); + (*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields<" + + unknown_fields_type + ">(::" + proto_ns + + "::internal::GetEmptyString)"; } + (*variables)["unknown_fields_type"] = unknown_fields_type; + (*variables)["have_unknown_fields"] = + "_internal_metadata_.have_unknown_fields()"; + (*variables)["mutable_unknown_fields"] = + "_internal_metadata_.mutable_unknown_fields<" + unknown_fields_type + + ">()"; } std::string UnderscoresToCamelCase(const std::string& input, @@ -389,7 +399,7 @@ std::string QualifiedClassName(const EnumDescriptor* d) { std::string ExtensionName(const FieldDescriptor* d) { if (const Descriptor* scope = d->extension_scope()) - return absl::StrCat(ClassName(scope), "::", ResolveKeyword(d->name())); + return StrCat(ClassName(scope), "::", ResolveKeyword(d->name())); return ResolveKeyword(d->name()); } @@ -484,7 +494,7 @@ std::string SuperClassName(const Descriptor* descriptor, } std::string ResolveKeyword(const std::string& name) { - if (Keywords().count(name) > 0) { + if (kKeywords.count(name) > 0) { return name + "_"; } return name; @@ -492,23 +502,23 @@ std::string ResolveKeyword(const std::string& name) { std::string FieldName(const FieldDescriptor* field) { std::string result = field->name(); - absl::AsciiStrToLower(&result); - if (Keywords().count(result) > 0) { + LowerString(&result); + if (kKeywords.count(result) > 0) { result.append("_"); } return result; } std::string FieldMemberName(const FieldDescriptor* field, bool split) { - absl::string_view prefix = + StringPiece prefix = IsMapEntryMessage(field->containing_type()) ? "" : "_impl_."; - absl::string_view split_prefix = split ? "_split_->" : ""; + StringPiece split_prefix = split ? "_split_->" : ""; if (field->real_containing_oneof() == nullptr) { - return absl::StrCat(prefix, split_prefix, FieldName(field), "_"); + return StrCat(prefix, split_prefix, FieldName(field), "_"); } // Oneof fields are never split. GOOGLE_CHECK(!split); - return absl::StrCat(prefix, field->containing_oneof()->name(), "_.", + return StrCat(prefix, field->containing_oneof()->name(), "_.", FieldName(field), "_"); } @@ -522,12 +532,12 @@ std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field) { GOOGLE_DCHECK(field->containing_oneof()); const std::string qualification = QualifiedClassName(field->containing_type()); - return absl::StrCat(qualification, "::", OneofCaseConstantName(field)); + return StrCat(qualification, "::", OneofCaseConstantName(field)); } std::string EnumValueName(const EnumValueDescriptor* enum_value) { std::string result = enum_value->name(); - if (Keywords().count(result) > 0) { + if (kKeywords.count(result) > 0) { result.append("_"); } return result; @@ -567,7 +577,7 @@ std::string FieldConstantName(const FieldDescriptor* field) { // This field's camelcase name is not unique. As a hack, add the field // number to the constant name. This makes the constant rather useless, // but what can we do? - result += "_" + absl::StrCat(field->number()); + result += "_" + StrCat(field->number()); } return result; @@ -703,9 +713,9 @@ std::string Int32ToString(int number) { if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 - return absl::StrCat(number + 1, " - 1"); + return StrCat(number + 1, " - 1"); } else { - return absl::StrCat(number); + return StrCat(number); } } @@ -713,13 +723,13 @@ static std::string Int64ToString(int64_t number) { if (number == std::numeric_limits::min()) { // This needs to be special-cased, see explanation here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52661 - return absl::StrCat("int64_t{", number + 1, "} - 1"); + return StrCat("int64_t{", number + 1, "} - 1"); } - return absl::StrCat("int64_t{", number, "}"); + return StrCat("int64_t{", number, "}"); } static std::string UInt64ToString(uint64_t number) { - return absl::StrCat("uint64_t{", number, "u}"); + return StrCat("uint64_t{", number, "u}"); } std::string DefaultValue(const FieldDescriptor* field) { @@ -731,7 +741,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { case FieldDescriptor::CPPTYPE_INT32: return Int32ToString(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: - return absl::StrCat(field->default_value_uint32()) + "u"; + return StrCat(field->default_value_uint32()) + "u"; case FieldDescriptor::CPPTYPE_INT64: return Int64ToString(field->default_value_int64()); case FieldDescriptor::CPPTYPE_UINT64: @@ -772,12 +782,12 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { case FieldDescriptor::CPPTYPE_ENUM: // Lazy: Generate a static_cast because we don't have a helper function // that constructs the full name of an enum value. - return absl::Substitute( + return strings::Substitute( "static_cast< $0 >($1)", ClassName(field->enum_type(), true), Int32ToString(field->default_value_enum()->number())); case FieldDescriptor::CPPTYPE_STRING: return "\"" + - EscapeTrigraphs(absl::CEscape(field->default_value_string())) + + EscapeTrigraphs(CEscape(field->default_value_string())) + "\""; case FieldDescriptor::CPPTYPE_MESSAGE: return "*" + FieldMessageTypeName(field, options) + @@ -794,13 +804,13 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { std::string FilenameIdentifier(const std::string& filename) { std::string result; for (int i = 0; i < filename.size(); i++) { - if (absl::ascii_isalnum(filename[i])) { + if (ascii_isalnum(filename[i])) { result.push_back(filename[i]); } else { // Not alphanumeric. To avoid any possibility of name conflicts we // use the hex code for the character. - absl::StrAppend(&result, "_", - absl::Hex(static_cast(filename[i]))); + StrAppend(&result, "_", + strings::Hex(static_cast(filename[i]))); } } return result; @@ -816,14 +826,14 @@ std::string QualifiedFileLevelSymbol(const FileDescriptor* file, const std::string& name, const Options& options) { if (file->package().empty()) { - return absl::StrCat("::", name); + return StrCat("::", name); } - return absl::StrCat(Namespace(file, options), "::", name); + return StrCat(Namespace(file, options), "::", name); } // Escape C++ trigraphs by escaping question marks to \? -std::string EscapeTrigraphs(absl::string_view to_escape) { - return absl::StrReplaceAll(to_escape, {{"?", "\\?"}}); +std::string EscapeTrigraphs(const std::string& to_escape) { + return StringReplace(to_escape, "?", "\\?", true); } // Escaped function name to eliminate naming conflict. @@ -832,13 +842,13 @@ std::string SafeFunctionName(const Descriptor* descriptor, const std::string& prefix) { // Do not use FieldName() since it will escape keywords. std::string name = field->name(); - absl::AsciiStrToLower(&name); + LowerString(&name); std::string function_name = prefix + name; if (descriptor->FindFieldByName(function_name)) { // Single underscore will also make it conflicting with the private data // member. We use double underscore to escape function names. function_name.append("__"); - } else if (Keywords().count(name) > 0) { + } else if (kKeywords.count(name) > 0) { // If the field name is a keyword, we append the underscore back to keep it // consistent with other function names. function_name.append("_"); @@ -846,9 +856,6 @@ std::string SafeFunctionName(const Descriptor* descriptor, return function_name; } -bool IsProfileDriven(const Options& options) { - return options.access_info_map != nullptr; -} bool IsStringInlined(const FieldDescriptor* descriptor, const Options& options) { (void)descriptor; @@ -896,13 +903,6 @@ bool HasLazyFields(const FileDescriptor* file, const Options& options, bool ShouldSplit(const Descriptor*, const Options&) { return false; } bool ShouldSplit(const FieldDescriptor*, const Options&) { return false; } -bool ShouldForceAllocationOnConstruction(const Descriptor* desc, - const Options& options) { - (void)desc; - (void)options; - return false; -} - static bool HasRepeatedFields(const Descriptor* descriptor) { for (int i = 0; i < descriptor->field_count(); ++i) { if (descriptor->field(i)->label() == FieldDescriptor::LABEL_REPEATED) { @@ -1041,7 +1041,7 @@ bool ShouldVerify(const FileDescriptor* file, const Options& options, bool IsUtf8String(const FieldDescriptor* field) { return IsProto3(field->file()) && - field->type() == FieldDescriptor::TYPE_STRING; + field->type() == FieldDescriptor::TYPE_STRING; } VerifySimpleType ShouldVerifySimple(const Descriptor* descriptor) { @@ -1091,7 +1091,7 @@ bool IsAnyMessage(const Descriptor* descriptor, const Options& options) { } bool IsWellKnownMessage(const FileDescriptor* file) { - static const auto* well_known_files = new absl::flat_hash_set{ + static const std::unordered_set well_known_files{ "google/protobuf/any.proto", "google/protobuf/api.proto", "google/protobuf/compiler/plugin.proto", @@ -1105,47 +1105,32 @@ bool IsWellKnownMessage(const FileDescriptor* file) { "google/protobuf/type.proto", "google/protobuf/wrappers.proto", }; - return well_known_files->find(file->name()) != well_known_files->end(); + return well_known_files.find(file->name()) != well_known_files.end(); } -void NamespaceOpener::ChangeTo(absl::string_view name) { - std::vector new_stack = - absl::StrSplit(name, "::", absl::SkipEmpty()); - size_t len = std::min(name_stack_.size(), new_stack.size()); - size_t common_idx = 0; - while (common_idx < len) { - if (name_stack_[common_idx] != new_stack[common_idx]) { - break; - } - ++common_idx; - } +static bool FieldEnforceUtf8(const FieldDescriptor* field, + const Options& options) { + return true; +} - for (size_t i = name_stack_.size(); i > common_idx; i--) { - const auto& ns = name_stack_[i - 1]; - if (ns == "PROTOBUF_NAMESPACE_ID") { - p_->Emit(R"cc( - PROTOBUF_NAMESPACE_CLOSE - )cc"); - } else { - p_->Emit({{"ns", ns}}, R"( - } // namespace $ns$ - )"); - } - } - for (size_t i = common_idx; i < new_stack.size(); ++i) { - const auto& ns = new_stack[i]; - if (ns == "PROTOBUF_NAMESPACE_ID") { - p_->Emit(R"cc( - PROTOBUF_NAMESPACE_OPEN - )cc"); - } else { - p_->Emit({{"ns", ns}}, R"( - namespace $ns$ { - )"); - } - } +static bool FileUtf8Verification(const FileDescriptor* file, + const Options& options) { + return true; +} - name_stack_ = std::move(new_stack); +// Which level of UTF-8 enforcemant is placed on this file. +Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, + const Options& options) { + if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && + FieldEnforceUtf8(field, options)) { + return Utf8CheckMode::kStrict; + } else if (GetOptimizeFor(field->file(), options) != + FileOptions::LITE_RUNTIME && + FileUtf8Verification(field->file(), options)) { + return Utf8CheckMode::kVerify; + } else { + return Utf8CheckMode::kNone; + } } static void GenerateUtf8CheckCode(const FieldDescriptor* field, @@ -1154,10 +1139,8 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field, const char* strict_function, const char* verify_function, const Formatter& format) { - switch (internal::cpp::GetUtf8CheckMode( - field, - GetOptimizeFor(field->file(), options) == FileOptions::LITE_RUNTIME)) { - case internal::cpp::Utf8CheckMode::kStrict: { + switch (GetUtf8CheckMode(field, options)) { + case Utf8CheckMode::kStrict: { if (for_parse) { format("DO_("); } @@ -1177,7 +1160,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field, format.Outdent(); break; } - case internal::cpp::Utf8CheckMode::kVerify: { + case Utf8CheckMode::kVerify: { format("::$proto_ns$::internal::WireFormat::$1$(\n", verify_function); format.Indent(); format(parameters); @@ -1190,7 +1173,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field, format.Outdent(); break; } - case internal::cpp::Utf8CheckMode::kNone: + case Utf8CheckMode::kNone: break; } } @@ -1360,19 +1343,16 @@ bool GetBootstrapBasename(const Options& options, const std::string& basename, return false; } - static const auto* bootstrap_mapping = - // TODO(b/242858704) Replace these with string_view once we remove - // StringPiece. - new absl::flat_hash_map{ - {"net/proto2/proto/descriptor", - "third_party/protobuf/descriptor"}, - {"net/proto2/compiler/proto/plugin", - "net/proto2/compiler/proto/plugin"}, - {"net/proto2/compiler/proto/profile", - "net/proto2/compiler/proto/profile_bootstrap"}, - }; - auto iter = bootstrap_mapping->find(basename); - if (iter == bootstrap_mapping->end()) { + std::unordered_map bootstrap_mapping{ + {"net/proto2/proto/descriptor", + "third_party/protobuf/descriptor"}, + {"net/proto2/compiler/proto/plugin", + "net/proto2/compiler/proto/plugin"}, + {"net/proto2/compiler/proto/profile", + "net/proto2/compiler/proto/profile_bootstrap"}, + }; + auto iter = bootstrap_mapping.find(basename); + if (iter == bootstrap_mapping.end()) { *bootstrap_basename = basename; return false; } else { @@ -1397,64 +1377,70 @@ bool MaybeBootstrap(const Options& options, GeneratorContext* generator_context, // Adjust basename, but don't abort code generation. *basename = bootstrap_basename; return false; + } else { + const std::string& forward_to_basename = bootstrap_basename; + + // Generate forwarding headers and empty .pb.cc. + { + std::unique_ptr output( + generator_context->Open(*basename + ".pb.h")); + io::Printer printer(output.get(), '$', nullptr); + printer.Print( + "#ifndef PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n" + "#define PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n" + "#include \"$forward_to_basename$.pb.h\" // IWYU pragma: export\n" + "#endif // PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PB_H\n", + "forward_to_basename", forward_to_basename, "filename_identifier", + FilenameIdentifier(*basename)); + + if (!options.opensource_runtime) { + // HACK HACK HACK, tech debt from the deeps of proto1 and SWIG + // protocoltype is SWIG'ed and we need to forward + if (*basename == "net/proto/protocoltype") { + printer.Print( + "#ifdef SWIG\n" + "%include \"$forward_to_basename$.pb.h\"\n" + "#endif // SWIG\n", + "forward_to_basename", forward_to_basename); + } + } + } + + { + std::unique_ptr output( + generator_context->Open(*basename + ".proto.h")); + io::Printer printer(output.get(), '$', nullptr); + printer.Print( + "#ifndef PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n" + "#define PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n" + "#include \"$forward_to_basename$.proto.h\" // IWYU pragma: " + "export\n" + "#endif // " + "PROTOBUF_INCLUDED_$filename_identifier$_FORWARD_PROTO_H\n", + "forward_to_basename", forward_to_basename, "filename_identifier", + FilenameIdentifier(*basename)); + } + + { + std::unique_ptr output( + generator_context->Open(*basename + ".pb.cc")); + io::Printer printer(output.get(), '$', nullptr); + printer.Print("\n"); + } + + { + std::unique_ptr output( + generator_context->Open(*basename + ".pb.h.meta")); + } + + { + std::unique_ptr output( + generator_context->Open(*basename + ".proto.h.meta")); + } + + // Abort code generation. + return true; } - - auto pb_h = absl::WrapUnique( - generator_context->Open(absl::StrCat(*basename, ".pb.h"))); - - io::Printer p(pb_h.get()); - p.Emit( - { - {"fwd_to", bootstrap_basename}, - {"file", FilenameIdentifier(*basename)}, - {"fwd_to_suffix", options.opensource_runtime ? "pb" : "proto"}, - {"swig_evil", - [&] { - if (options.opensource_runtime) { - return; - } - p.Emit(R"( - #ifdef SWIG - %include "$fwd_to$.pb.h" - #endif // SWIG - )"); - }}, - }, - R"( - #ifndef PROTOBUF_INCLUDED_$file$_FORWARD_PB_H - #define PROTOBUF_INCLUDED_$file$_FORWARD_PB_H - #include "$fwd_to$.$fwd_to_suffix$.h" // IWYU pragma: export - #endif // PROTOBUF_INCLUDED_$file$_FORWARD_PB_H - $swig_evil$; - )"); - - auto proto_h = absl::WrapUnique( - generator_context->Open(absl::StrCat(*basename, ".proto.h"))); - io::Printer(proto_h.get()) - .Emit( - { - {"fwd_to", bootstrap_basename}, - {"file", FilenameIdentifier(*basename)}, - }, - R"( - #ifndef PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H - #define PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H - #include "$fwd_to$.proto.h" // IWYU pragma: export - #endif // PROTOBUF_INCLUDED_$file$_FORWARD_PROTO_H - )"); - - auto pb_cc = absl::WrapUnique( - generator_context->Open(absl::StrCat(*basename, ".pb.cc"))); - io::Printer(pb_cc.get()).PrintRaw("\n"); - - (void)absl::WrapUnique( - generator_context->Open(absl::StrCat(*basename, ".pb.h.meta"))); - - (void)absl::WrapUnique( - generator_context->Open(absl::StrCat(*basename, ".proto.h.meta"))); - - // Abort code generation. - return true; } static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file, @@ -1502,18 +1488,9 @@ static bool HasExtensionFromFile(const Message& msg, const FileDescriptor* file, static bool HasBootstrapProblem(const FileDescriptor* file, const Options& options, bool* has_opt_codesize_extension) { - struct BoostrapGlobals { - absl::Mutex mutex; - absl::flat_hash_set cached ABSL_GUARDED_BY(mutex); - absl::flat_hash_set non_cached - ABSL_GUARDED_BY(mutex); - }; - static auto& bootstrap_cache = *new BoostrapGlobals(); - - absl::MutexLock lock(&bootstrap_cache.mutex); - if (bootstrap_cache.cached.contains(file)) return true; - if (bootstrap_cache.non_cached.contains(file)) return false; - + static auto& cache = *new std::unordered_map; + auto it = cache.find(file); + if (it != cache.end()) return it->second; // In order to build the data structures for the reflective parse, it needs // to parse the serialized descriptor describing all the messages defined in // this file. Obviously this presents a bootstrap problem for descriptor @@ -1549,13 +1526,9 @@ static bool HasBootstrapProblem(const FileDescriptor* file, Message* fd_proto = factory.GetPrototype(fd_proto_descriptor)->New(); fd_proto->ParseFromString(linkedin_fd_proto.SerializeAsString()); - bool res = HasExtensionFromFile(*fd_proto, file, options, - has_opt_codesize_extension); - if (res) { - bootstrap_cache.cached.insert(file); - } else { - bootstrap_cache.non_cached.insert(file); - } + bool& res = cache[file]; + res = HasExtensionFromFile(*fd_proto, file, options, + has_opt_codesize_extension); delete fd_proto; return res; } diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.h b/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.h index 15df165..d8dcda7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/helpers.h @@ -41,23 +41,18 @@ #include #include -#include "google/protobuf/compiler/scc.h" -#include "google/protobuf/compiler/code_generator.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/match.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/compiler/cpp/names.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/port.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/strings/str_cat.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -89,17 +84,14 @@ inline std::string DeprecatedAttribute(const Options& /* options */, extern const char kThickSeparator[]; extern const char kThinSeparator[]; -absl::flat_hash_map MessageVars( - const Descriptor* desc); +void SetCommonVars(const Options& options, + std::map* variables); // Variables to access message data from the message scope. void SetCommonMessageDataVariables( const Descriptor* descriptor, std::map* variables); -absl::flat_hash_map UnknownFieldsVars( - const Descriptor* desc, const Options& opts); - void SetUnknownFieldsVariable(const Descriptor* descriptor, const Options& options, std::map* variables); @@ -228,7 +220,7 @@ inline const Descriptor* FieldScope(const FieldDescriptor* field) { std::string FieldMessageTypeName(const FieldDescriptor* field, const Options& options); -// Get the C++ type name for a primitive type (e.g. "double", "::int32", etc.). +// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.). const char* PrimitiveTypeName(FieldDescriptor::CppType type); std::string PrimitiveTypeName(const Options& options, FieldDescriptor::CppType type); @@ -304,7 +296,7 @@ std::string QualifiedFileLevelSymbol(const FileDescriptor* file, const Options& options); // Escape C++ trigraphs by escaping question marks to \? -std::string EscapeTrigraphs(absl::string_view to_escape); +std::string EscapeTrigraphs(const std::string& to_escape); // Escaped function name to eliminate naming conflict. std::string SafeFunctionName(const Descriptor* descriptor, @@ -335,8 +327,6 @@ inline bool IsWeak(const FieldDescriptor* field, const Options& options) { return false; } -bool IsProfileDriven(const Options& options); - bool IsStringInlined(const FieldDescriptor* descriptor, const Options& options); // For a string field, returns the effective ctype. If the actual ctype is @@ -387,11 +377,6 @@ bool ShouldSplit(const Descriptor* desc, const Options& options); // Is the given field being split out? bool ShouldSplit(const FieldDescriptor* field, const Options& options); -// Should we generate code that force creating an allocation in the constructor -// of the given message? -bool ShouldForceAllocationOnConstruction(const Descriptor* desc, - const Options& options); - inline bool IsFieldUsed(const FieldDescriptor* /* field */, const Options& /* options */) { return true; @@ -470,13 +455,35 @@ inline bool IsProto3(const FileDescriptor* file) { return file->syntax() == FileDescriptor::SYNTAX_PROTO3; } +inline bool HasHasbit(const FieldDescriptor* field) { + // This predicate includes proto3 message fields only if they have "optional". + // Foo submsg1 = 1; // HasHasbit() == false + // optional Foo submsg2 = 2; // HasHasbit() == true + // This is slightly odd, as adding "optional" to a singular proto3 field does + // not change the semantics or API. However whenever any field in a message + // has a hasbit, it forces reflection to include hasbit offsets for *all* + // fields, even if almost all of them are set to -1 (no hasbit). So to avoid + // causing a sudden size regression for ~all proto3 messages, we give proto3 + // message fields a hasbit only if "optional" is present. If the user is + // explicitly writing "optional", it is likely they are writing it on + // primitive fields also. + return (field->has_optional_keyword() || field->is_required()) && + !field->options().weak(); +} + +// Returns true if 'enum' semantics are such that unknown values are preserved +// in the enum field itself, rather than going to the UnknownFieldSet. +inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) { + return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; +} + inline bool IsCrossFileMessage(const FieldDescriptor* field) { return field->type() == FieldDescriptor::TYPE_MESSAGE && field->message_type()->file() != field->file(); } inline std::string MakeDefaultName(const FieldDescriptor* field) { - return absl::StrCat("_i_give_permission_to_break_this_code_default_", + return StrCat("_i_give_permission_to_break_this_code_default_", FieldName(field), "_"); } @@ -491,11 +498,11 @@ inline std::string MakeDefaultName(const FieldDescriptor* field) { // exists at some nested level like: // internal_container_._i_give_permission_to_break_this_code_default_field_; inline std::string MakeDefaultFieldName(const FieldDescriptor* field) { - return absl::StrCat("Impl_::", MakeDefaultName(field)); + return StrCat("Impl_::", MakeDefaultName(field)); } inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) { - return absl::StrCat("_", FieldName(field), "_cached_byte_size_"); + return StrCat("_", FieldName(field), "_cached_byte_size_"); } // Semantically distinct from MakeVarintCachedSizeName in that it gives the C++ @@ -511,7 +518,7 @@ inline std::string MakeVarintCachedSizeName(const FieldDescriptor* field) { // internal_container_._field_cached_byte_size_; inline std::string MakeVarintCachedSizeFieldName(const FieldDescriptor* field, bool split) { - return absl::StrCat("_impl_.", split ? "_split_->" : "", "_", + return StrCat("_impl_.", split ? "_split_->" : "", "_", FieldName(field), "_cached_byte_size_"); } @@ -524,26 +531,12 @@ bool IsAnyMessage(const Descriptor* descriptor, const Options& options); bool IsWellKnownMessage(const FileDescriptor* descriptor); -enum class GeneratedFileType : int { kPbH, kProtoH, kProtoStaticReflectionH }; - -inline std::string IncludeGuard(const FileDescriptor* file, - GeneratedFileType file_type, +inline std::string IncludeGuard(const FileDescriptor* file, bool pb_h, const Options& options) { // If we are generating a .pb.h file and the proto_h option is enabled, then // the .pb.h gets an extra suffix. - std::string extension; - switch (file_type) { - case GeneratedFileType::kPbH: - extension = ".pb.h"; - break; - case GeneratedFileType::kProtoH: - extension = ".proto.h"; - break; - case GeneratedFileType::kProtoStaticReflectionH: - extension = ".proto.static_reflection.h"; - } - std::string filename_identifier = - FilenameIdentifier(file->name() + extension); + std::string filename_identifier = FilenameIdentifier( + file->name() + (pb_h && options.proto_h ? ".pb.h" : "")); if (IsWellKnownMessage(file)) { // For well-known messages we need third_party/protobuf and net/proto2 to @@ -857,9 +850,9 @@ class PROTOC_EXPORT Formatter { template ::value>::type> static std::string ToString(I x) { - return absl::StrCat(x); + return StrCat(x); } - static std::string ToString(absl::Hex x) { return absl::StrCat(x); } + static std::string ToString(strings::Hex x) { return StrCat(x); } static std::string ToString(const FieldDescriptor* d) { return Payload(d); } static std::string ToString(const Descriptor* d) { return Payload(d); } static std::string ToString(const EnumDescriptor* d) { return Payload(d); } @@ -881,48 +874,69 @@ class PROTOC_EXPORT Formatter { } }; -template -std::string FieldComment(const T* field) { +template +void PrintFieldComment(const Formatter& format, const T* field) { // Print the field's (or oneof's) proto-syntax definition as a comment. // We don't want to print group bodies so we cut off after the first // line. DebugStringOptions options; options.elide_group_body = true; options.elide_oneof_body = true; - - for (absl::string_view chunk : - absl::StrSplit(field->DebugStringWithOptions(options), '\n')) { - return std::string(chunk); - } - - return ""; -} - -template -void PrintFieldComment(const Formatter& format, const T* field) { - format("// $1$\n", FieldComment(field)); + std::string def = field->DebugStringWithOptions(options); + format("// $1$\n", def.substr(0, def.find_first_of('\n'))); } class PROTOC_EXPORT NamespaceOpener { public: - explicit NamespaceOpener(io::Printer* p) : p_(p) {} - explicit NamespaceOpener(const Formatter& format) : p_(format.printer()) {} - NamespaceOpener(absl::string_view name, const Formatter& format) + explicit NamespaceOpener(const Formatter& format) + : printer_(format.printer()) {} + NamespaceOpener(const std::string& name, const Formatter& format) : NamespaceOpener(format) { ChangeTo(name); } - NamespaceOpener(absl::string_view name, io::Printer* p) : NamespaceOpener(p) { - ChangeTo(name); - } ~NamespaceOpener() { ChangeTo(""); } - void ChangeTo(absl::string_view name); + void ChangeTo(const std::string& name) { + std::vector new_stack_ = + Split(name, "::", true); + size_t len = std::min(name_stack_.size(), new_stack_.size()); + size_t common_idx = 0; + while (common_idx < len) { + if (name_stack_[common_idx] != new_stack_[common_idx]) break; + common_idx++; + } + for (auto it = name_stack_.crbegin(); + it != name_stack_.crend() - common_idx; ++it) { + if (*it == "PROTOBUF_NAMESPACE_ID") { + printer_->Print("PROTOBUF_NAMESPACE_CLOSE\n"); + } else { + printer_->Print("} // namespace $ns$\n", "ns", *it); + } + } + name_stack_.swap(new_stack_); + for (size_t i = common_idx; i < name_stack_.size(); ++i) { + if (name_stack_[i] == "PROTOBUF_NAMESPACE_ID") { + printer_->Print("PROTOBUF_NAMESPACE_OPEN\n"); + } else { + printer_->Print("namespace $ns$ {\n", "ns", name_stack_[i]); + } + } + } private: - io::Printer* p_; + io::Printer* printer_; std::vector name_stack_; }; +enum class Utf8CheckMode { + kStrict = 0, // Parsing will fail if non UTF-8 data is in string fields. + kVerify = 1, // Only log an error but parsing will succeed. + kNone = 2, // No UTF-8 check. +}; + +Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, + const Options& options); + void GenerateUtf8CheckCodeForString(const FieldDescriptor* field, const Options& options, bool for_parse, const char* parameters, @@ -933,6 +947,43 @@ void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field, const char* parameters, const Formatter& format); +template +struct FieldRangeImpl { + struct Iterator { + using iterator_category = std::forward_iterator_tag; + using value_type = const FieldDescriptor*; + using difference_type = int; + + value_type operator*() { return descriptor->field(idx); } + + friend bool operator==(const Iterator& a, const Iterator& b) { + GOOGLE_DCHECK(a.descriptor == b.descriptor); + return a.idx == b.idx; + } + friend bool operator!=(const Iterator& a, const Iterator& b) { + return !(a == b); + } + + Iterator& operator++() { + idx++; + return *this; + } + + int idx; + const T* descriptor; + }; + + Iterator begin() const { return {0, descriptor}; } + Iterator end() const { return {descriptor->field_count(), descriptor}; } + + const T* descriptor; +}; + +template +FieldRangeImpl FieldRange(const T* desc) { + return {desc}; +} + struct OneOfRangeImpl { struct Iterator { using iterator_category = std::forward_iterator_tag; @@ -1008,6 +1059,6 @@ bool HasMessageFieldOrExtension(const Descriptor* desc); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.cc index c73be5f..3a55ef5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.cc @@ -28,19 +28,24 @@ // (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/compiler/cpp/map_field.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/ascii.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { namespace compiler { namespace cpp { + +bool IsProto3Field(const FieldDescriptor* field_descriptor) { + const FileDescriptor* file_descriptor = field_descriptor->file(); + return file_descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3; +} + void SetMessageVariables(const FieldDescriptor* descriptor, std::map* variables, const Options& options) { @@ -62,12 +67,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, (*variables)["val_cpp"] = PrimitiveTypeName(options, val->cpp_type()); } (*variables)["key_wire_type"] = - "TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(key->type())); + "TYPE_" + ToUpper(DeclaredTypeMethodName(key->type())); (*variables)["val_wire_type"] = - "TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(val->type())); + "TYPE_" + ToUpper(DeclaredTypeMethodName(val->type())); (*variables)["map_classname"] = ClassName(descriptor->message_type(), false); - (*variables)["number"] = absl::StrCat(descriptor->number()); - (*variables)["tag"] = absl::StrCat(internal::WireFormat::MakeTag(descriptor)); + (*variables)["number"] = StrCat(descriptor->number()); + (*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor)); if (HasDescriptorMethods(descriptor->file(), options)) { (*variables)["lite"] = ""; diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.h index 06f3e0a..678a128 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/map_field.h @@ -34,8 +34,8 @@ #include #include -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/message_field.h" +#include +#include namespace google { namespace protobuf { @@ -46,8 +46,6 @@ class MapFieldGenerator : public FieldGenerator { public: MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - MapFieldGenerator(const MapFieldGenerator&) = delete; - MapFieldGenerator& operator=(const MapFieldGenerator&) = delete; ~MapFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -73,6 +71,8 @@ class MapFieldGenerator : public FieldGenerator { private: const bool has_required_fields_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/message.cc index 9d5d621..69069da 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message.cc @@ -32,44 +32,39 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/message.h" +#include #include -#include #include #include -#include #include #include -#include #include #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/map_entry_lite.h" -#include "google/protobuf/wire_format.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/cpp/enum.h" -#include "google/protobuf/compiler/cpp/extension.h" -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/padding_optimizer.h" -#include "google/protobuf/compiler/cpp/parse_function_generator.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -78,8 +73,6 @@ namespace cpp { using internal::WireFormat; using internal::WireFormatLite; -using internal::cpp::HasHasbit; -using internal::cpp::Utf8CheckMode; namespace { @@ -91,28 +84,27 @@ static constexpr int kNoHasbit = -1; // masks must be non-zero. std::string ConditionalToCheckBitmasks( const std::vector& masks, bool return_success = true, - absl::string_view has_bits_var = "_impl_._has_bits_") { + StringPiece has_bits_var = "_impl_._has_bits_") { std::vector parts; for (int i = 0; i < masks.size(); i++) { if (masks[i] == 0) continue; - std::string m = absl::StrCat("0x", absl::Hex(masks[i], absl::kZeroPad8)); + std::string m = StrCat("0x", strings::Hex(masks[i], strings::ZERO_PAD_8)); // Each xor evaluates to 0 if the expected bits are present. parts.push_back( - absl::StrCat("((", has_bits_var, "[", i, "] & ", m, ") ^ ", m, ")")); + StrCat("((", has_bits_var, "[", i, "] & ", m, ") ^ ", m, ")")); } GOOGLE_CHECK(!parts.empty()); // If we have multiple parts, each expected to be 0, then bitwise-or them. std::string result = parts.size() == 1 ? parts[0] - : absl::StrCat("(", absl::StrJoin(parts, "\n | "), ")"); + : StrCat("(", Join(parts, "\n | "), ")"); return result + (return_success ? " == 0" : " != 0"); } -void PrintPresenceCheck(const FieldDescriptor* field, - const std::vector& has_bit_indices, io::Printer* p, - int* cached_has_word_index) { - Formatter format(p); +void PrintPresenceCheck(const Formatter& format, const FieldDescriptor* field, + const std::vector& has_bit_indices, + io::Printer* printer, int* cached_has_word_index) { if (!field->options().weak()) { int has_bit_index = has_bit_indices[field->index()]; if (*cached_has_word_index != (has_bit_index / 32)) { @@ -120,7 +112,7 @@ void PrintPresenceCheck(const FieldDescriptor* field, format("cached_has_bits = $has_bits$[$1$];\n", *cached_has_word_index); } const std::string mask = - absl::StrCat(absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8)); + StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); format("if (cached_has_bits & 0x$1$u) {\n", mask); } else { format("if (has_$1$()) {\n", FieldName(field)); @@ -191,6 +183,10 @@ bool CanBeManipulatedAsRawBytes(const FieldDescriptor* field, return ret; } +bool StrContains(const std::string& haystack, const std::string& needle) { + return haystack.find(needle) != std::string::npos; +} + // Finds runs of fields for which `predicate` is true. // RunMap maps from fields that start each run to the number of fields in that // run. This is optimized for the common case that there are very few runs in @@ -219,14 +215,13 @@ RunMap FindRuns(const std::vector& fields, // considered non-default (will be sent over the wire), for message types // without true field presence. Should only be called if // !HasHasbit(field). -bool EmitFieldNonDefaultCondition(io::Printer* p, const std::string& prefix, +bool EmitFieldNonDefaultCondition(io::Printer* printer, + const std::string& prefix, const FieldDescriptor* field) { GOOGLE_CHECK(!HasHasbit(field)); - Formatter format(p); - auto v = p->WithVars({{ - {"prefix", prefix}, - {"name", FieldName(field)}, - }}); + Formatter format(printer); + format.Set("prefix", prefix); + format.Set("name", FieldName(field)); // Merge and serialize semantics: primitive fields are merged/serialized only // if non-zero (numeric) or non-empty (string). if (!field->is_repeated() && !field->containing_oneof()) { @@ -295,9 +290,9 @@ void CollectMapInfo(const Options& options, const Descriptor* descriptor, vars["val_cpp"] = PrimitiveTypeName(options, val->cpp_type()); } vars["key_wire_type"] = - "TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(key->type())); + "TYPE_" + ToUpper(DeclaredTypeMethodName(key->type())); vars["val_wire_type"] = - "TYPE_" + absl::AsciiStrToUpper(DeclaredTypeMethodName(val->type())); + "TYPE_" + ToUpper(DeclaredTypeMethodName(val->type())); } // Does the given field have a private (internal helper only) has_$name$() @@ -308,6 +303,14 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) { return IsProto3(field->file()) && field->real_containing_oneof(); } +// TODO(ckennelly): Cull these exclusions if/when these protos do not have +// their methods overridden by subclasses. + +bool ShouldMarkClassAsFinal(const Descriptor* descriptor, + const Options& options) { + return true; +} + // Returns true to make the message serialize in order, decided by the following // factors in the order of precedence. @@ -408,6 +411,7 @@ class ColdChunkSkipper { has_bit_indices_(has_bit_indices), access_info_map_(options.access_info_map), cold_threshold_(cold_threshold) { + SetCommonVars(options, &variables_); SetCommonMessageDataVariables(descriptor, &variables_); } @@ -415,8 +419,8 @@ class ColdChunkSkipper { // prefix to _has_bits_ to allow MergeFrom to use "from._has_bits_". // Otherwise, it should be "". void OnStartChunk(int chunk, int cached_has_word_index, - const std::string& from, io::Printer* p); - bool OnEndChunk(int chunk, io::Printer* p); + const std::string& from, io::Printer* printer); + bool OnEndChunk(int chunk, io::Printer* printer); private: bool IsColdChunk(int chunk); @@ -444,8 +448,9 @@ bool ColdChunkSkipper::IsColdChunk(int chunk) { void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, - const std::string& from, io::Printer* p) { - Formatter format(p); + const std::string& from, + io::Printer* printer) { + Formatter format(printer, variables_); if (!access_info_map_) { return; } else if (chunk < limit_chunk_) { @@ -487,7 +492,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, if (this_word != first_word) { format(" ||\n "); } - auto v = p->WithVars({{"mask", absl::Hex(mask, absl::kZeroPad8)}}); + format.Set("mask", strings::Hex(mask, strings::ZERO_PAD_8)); if (this_word == cached_has_word_index) { format("(cached_has_bits & 0x$mask$u) != 0"); } else { @@ -498,8 +503,8 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, format.Indent(); } -bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* p) { - Formatter format(p); +bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* printer) { + Formatter format(printer, variables_); if (chunk != limit_chunk_ - 1) { return false; } @@ -508,152 +513,145 @@ bool ColdChunkSkipper::OnEndChunk(int chunk, io::Printer* p) { return true; } -void AnnotationVar(const Descriptor* desc, const Options& options, - absl::flat_hash_map& vars, - absl::string_view name, absl::string_view val) { - if (!HasTracker(desc, options) || - options.field_listener_options.forbidden_field_listener_events.count( - std::string(absl::StripPrefix(name, "annotate_"))) != 0) { - val = ""; - } - - vars.emplace(name, absl::StrCat(absl::StripAsciiWhitespace(val), "\n")); +void MaySetAnnotationVariable(const Options& options, + StringPiece annotation_name, + StringPiece injector_template_prefix, + StringPiece injector_template_suffix, + std::map* variables) { + if (options.field_listener_options.forbidden_field_listener_events.count( + std::string(annotation_name))) + return; + (*variables)[StrCat("annotate_", annotation_name)] = strings::Substitute( + StrCat(injector_template_prefix, injector_template_suffix), + (*variables)["classtype"]); } -absl::flat_hash_map ClassVars(const Descriptor* desc, - Options opts) { - absl::flat_hash_map vars = MessageVars(desc); - vars.emplace("classname", ClassName(desc, false)); - vars.emplace("classtype", QualifiedClassName(desc, opts)); - vars.emplace("full_name", desc->full_name()); - vars.emplace("superclass", SuperClassName(desc, opts)); - - for (auto& pair : UnknownFieldsVars(desc, opts)) { - vars.emplace(pair); +void GenerateExtensionAnnotations( + const Descriptor* descriptor, const Options& options, + std::map* variables) { + const std::map accessor_annotations_to_hooks = { + {"annotate_extension_has", "OnHasExtension"}, + {"annotate_extension_clear", "OnClearExtension"}, + {"annotate_extension_repeated_size", "OnExtensionSize"}, + {"annotate_extension_get", "OnGetExtension"}, + {"annotate_extension_mutable", "OnMutableExtension"}, + {"annotate_extension_set", "OnSetExtension"}, + {"annotate_extension_release", "OnReleaseExtension"}, + {"annotate_repeated_extension_get", "OnGetExtension"}, + {"annotate_repeated_extension_mutable", "OnMutableExtension"}, + {"annotate_repeated_extension_set", "OnSetExtension"}, + {"annotate_repeated_extension_add", "OnAddExtension"}, + {"annotate_repeated_extension_add_mutable", "OnAddMutableExtension"}, + {"annotate_repeated_extension_list", "OnListExtension"}, + {"annotate_repeated_extension_list_mutable", "OnMutableListExtension"}, + }; + for (const auto& annotation : accessor_annotations_to_hooks) { + (*variables)[annotation.first] = ""; } - - AnnotationVar(desc, opts, vars, "annotate_serialize", R"cc( - Impl_::_tracker_.OnSerialize(this); - )cc"); - AnnotationVar(desc, opts, vars, "annotate_deserialize", R"cc( - Impl_::_tracker_.OnDeserialize(this); - )cc"); - // TODO(danilak): Ideally annotate_reflection should not exist and we need - // to annotate all reflective calls on our own, however, as this is a cause - // for side effects, i.e. reading values dynamically, we want the users know - // that dynamic access can happen. - AnnotationVar(desc, opts, vars, "annotate_reflection", R"cc( - Impl_::_tracker_.OnGetMetadata(); - )cc"); - AnnotationVar(desc, opts, vars, "annotate_bytesize", R"cc( - Impl_::_tracker_.OnByteSize(this); - )cc"); - AnnotationVar(desc, opts, vars, "annotate_mergefrom", R"cc( - Impl_::_tracker_.OnMergeFrom(_this, &from); - )cc"); - - static constexpr std::array, - 14> - kVarToHook = {{ - {"annotate_extension_has", "OnHasExtension"}, - {"annotate_extension_clear", "OnClearExtension"}, - {"annotate_extension_repeated_size", "OnExtensionSize"}, - {"annotate_extension_get", "OnGetExtension"}, - {"annotate_extension_mutable", "OnMutableExtension"}, - {"annotate_extension_set", "OnSetExtension"}, - {"annotate_extension_release", "OnReleaseExtension"}, - {"annotate_repeated_extension_get", "OnGetExtension"}, - {"annotate_repeated_extension_mutable", "OnMutableExtension"}, - {"annotate_repeated_extension_set", "OnSetExtension"}, - {"annotate_repeated_extension_add", "OnAddExtension"}, - {"annotate_repeated_extension_add_mutable", "OnAddMutableExtension"}, - {"annotate_repeated_extension_list", "OnListExtension"}, - {"annotate_repeated_extension_list_mutable", - "OnMutableListExtension"}, - }}; - - for (const auto& annotation : kVarToHook) { - vars[annotation.first] = ""; + if (!HasTracker(descriptor, options)) { + return; } - if (!HasTracker(desc, opts)) { - return vars; - } - - absl::string_view extensions = vars["extensions"]; - for (const auto& annotation : kVarToHook) { - absl::string_view name = annotation.first; - absl::string_view call = annotation.second; - - if (!absl::StrContains(name, "repeated") && - !absl::StrContains(name, "size") && !absl::StrContains(name, "clear")) { + StringPiece tracker = (*variables)["tracker"]; + StringPiece extensions = (*variables)["extensions"]; + for (const auto& annotation : accessor_annotations_to_hooks) { + const std::string& annotation_name = annotation.first; + const std::string& listener_call = annotation.second; + if (!StrContains(annotation_name, "repeated") && + !StrContains(annotation_name, "size") && + !StrContains(annotation_name, "clear")) { // Primitive fields accessors. // "Has" is here as users calling "has" on a repeated field is a mistake. - vars[name] = std::string(absl::StripAsciiWhitespace(absl::Substitute( - R"cc( - Impl_::_tracker_.$0(this, id.number(), - _proto_TypeTraits::GetPtr( - id.number(), $1, id.default_value_ref())); - )cc", - call, extensions))); - continue; - } - - if (absl::StrContains(name, "repeated") && - !absl::StrContains(name, "list") && !absl::StrContains(name, "size")) { + (*variables)[annotation_name] = StrCat( + " ", tracker, ".", listener_call, + "(this, id.number(), _proto_TypeTraits::GetPtr(id.number(), ", + extensions, ", id.default_value_ref()));"); + } else if (StrContains(annotation_name, "repeated") && + !StrContains(annotation_name, "list") && + !StrContains(annotation_name, "size")) { // Repeated index accessors. std::string str_index = "index"; - if (absl::StrContains(name, "add")) { - str_index = absl::StrCat(extensions, ".ExtensionSize(id.number()) - 1"); + if (StrContains(annotation_name, "add")) { + str_index = StrCat(extensions, ".ExtensionSize(id.number()) - 1"); } - vars[name] = std::string(absl::StripAsciiWhitespace(absl::Substitute( - R"cc( - Impl_::_tracker_.$0(this, id.number(), - _proto_TypeTraits::GetPtr(id.number(), $1, $2)); - )cc", - call, extensions, str_index))); - continue; - } - - if (absl::StrContains(name, "list") || absl::StrContains(name, "size")) { + (*variables)[annotation_name] = + StrCat(" ", tracker, ".", listener_call, + "(this, id.number(), " + "_proto_TypeTraits::GetPtr(id.number(), ", + extensions, ", ", str_index, "));"); + } else if (StrContains(annotation_name, "list") || + StrContains(annotation_name, "size")) { // Repeated full accessors. - vars[name] = std::string(absl::StripAsciiWhitespace(absl::Substitute( - R"cc( - Impl_::_tracker_.$0(this, id.number(), - _proto_TypeTraits::GetRepeatedPtr(id.number(), - $1)); - )cc", - call, extensions))); - continue; + (*variables)[annotation_name] = StrCat( + " ", tracker, ".", listener_call, + "(this, id.number(), _proto_TypeTraits::GetRepeatedPtr(id.number(), ", + extensions, "));"); + } else { + // Generic accessors such as "clear". + // TODO(b/190614678): Generalize clear from both repeated and non repeated + // calls, currently their underlying memory interfaces are very different. + // Or think of removing clear callback as no usages are needed and no + // memory exist after calling clear(). } - - // Generic accessors such as "clear". - // TODO(b/190614678): Generalize clear from both repeated and non repeated - // calls, currently their underlying memory interfaces are very different. - // Or think of removing clear callback as no usages are needed and no - // memory exist after calling clear(). } - - return vars; } } // anonymous namespace // =================================================================== -MessageGenerator::MessageGenerator(const Descriptor* descriptor, - const std::map&, - int index_in_file_messages, - const Options& options, - MessageSCCAnalyzer* scc_analyzer) +MessageGenerator::MessageGenerator( + const Descriptor* descriptor, + const std::map& vars, int index_in_file_messages, + const Options& options, MessageSCCAnalyzer* scc_analyzer) : descriptor_(descriptor), index_in_file_messages_(index_in_file_messages), + classname_(ClassName(descriptor, false)), options_(options), field_generators_(descriptor, options, scc_analyzer), - scc_analyzer_(scc_analyzer) { - + max_has_bit_index_(0), + max_inlined_string_index_(0), + num_weak_fields_(0), + scc_analyzer_(scc_analyzer), + variables_(vars) { if (!message_layout_helper_) { - message_layout_helper_ = std::make_unique(); + message_layout_helper_.reset(new PaddingOptimizer()); } + SetCommonMessageDataVariables(descriptor, &variables_); + + // Variables that apply to this class + variables_["classname"] = classname_; + variables_["classtype"] = QualifiedClassName(descriptor_, options); + variables_["full_name"] = descriptor_->full_name(); + variables_["superclass"] = SuperClassName(descriptor_, options_); + variables_["annotate_serialize"] = ""; + variables_["annotate_deserialize"] = ""; + variables_["annotate_reflection"] = ""; + variables_["annotate_bytesize"] = ""; + variables_["annotate_mergefrom"] = ""; + + if (HasTracker(descriptor_, options_)) { + const std::string injector_template = + StrCat(" ", variables_["tracker"], "."); + + MaySetAnnotationVariable(options, "serialize", injector_template, + "OnSerialize(this);\n", &variables_); + MaySetAnnotationVariable(options, "deserialize", injector_template, + "OnDeserialize(this);\n", &variables_); + // TODO(danilak): Ideally annotate_reflection should not exist and we need + // to annotate all reflective calls on our own, however, as this is a cause + // for side effects, i.e. reading values dynamically, we want the users know + // that dynamic access can happen. + MaySetAnnotationVariable(options, "reflection", injector_template, + "OnGetMetadata();\n", &variables_); + MaySetAnnotationVariable(options, "bytesize", injector_template, + "OnByteSize(this);\n", &variables_); + MaySetAnnotationVariable(options, "mergefrom", injector_template, + "OnMergeFrom(_this, &from);\n", &variables_); + } + + GenerateExtensionAnnotations(descriptor_, options_, &variables_); + + SetUnknownFieldsVariable(descriptor_, options_, &variables_); // Compute optimized field order to be used for layout and initialization // purposes. @@ -663,11 +661,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, } if (IsWeak(field, options_)) { - ++num_weak_fields_; - continue; - } - - if (!field->real_containing_oneof()) { + num_weak_fields_++; + } else if (!field->real_containing_oneof()) { optimized_order_.push_back(field); } } @@ -688,9 +683,8 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, inlined_string_indices_.resize(descriptor_->field_count(), kNoHasbit); // The bitset[0] is for arena dtor tracking. Donating states start from // bitset[1]; - ++max_inlined_string_index_; + max_inlined_string_index_++; } - inlined_string_indices_[field->index()] = max_inlined_string_index_++; } } @@ -703,17 +697,20 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, field_generators_.SetInlinedStringIndices(inlined_string_indices_); } + num_required_fields_ = 0; for (int i = 0; i < descriptor->field_count(); i++) { if (descriptor->field(i)->is_required()) { ++num_required_fields_; } } - parse_function_generator_ = std::make_unique( + parse_function_generator_.reset(new ParseFunctionGenerator( descriptor_, max_has_bit_index_, has_bit_indices_, - inlined_string_indices_, options_, scc_analyzer_, variables_); + inlined_string_indices_, options_, scc_analyzer_, variables_)); } +MessageGenerator::~MessageGenerator() = default; + size_t MessageGenerator::HasBitsSize() const { return (max_has_bit_index_ + 31) / 32; } @@ -742,24 +739,24 @@ void MessageGenerator::AddGenerators( std::vector>* extension_generators) { for (int i = 0; i < descriptor_->enum_type_count(); i++) { enum_generators->emplace_back( - std::make_unique(descriptor_->enum_type(i), options_)); + new EnumGenerator(descriptor_->enum_type(i), variables_, options_)); enum_generators_.push_back(enum_generators->back().get()); } for (int i = 0; i < descriptor_->extension_count(); i++) { - extension_generators->emplace_back(std::make_unique( + extension_generators->emplace_back(new ExtensionGenerator( descriptor_->extension(i), options_, scc_analyzer_)); extension_generators_.push_back(extension_generators->back().get()); } } -void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { - Formatter format(p); +void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) { + Formatter format(printer, variables_); // optimized_fields_ does not contain fields where // field->real_containing_oneof() // so we need to iterate over those as well. // // We place the non-oneof fields in optimized_order_, as that controls the - // order of the _has_bits_ entries and we want GDB's pretty ps to be + // order of the _has_bits_ entries and we want GDB's pretty printers to be // able to infer these indices from the k[FIELDNAME]FieldNumber order. std::vector ordered_fields; ordered_fields.reserve(descriptor_->field_count()); @@ -781,7 +778,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { std::map vars; SetCommonFieldVariables(field, &vars, options_); - auto v = p->WithVars(std::move(vars)); + format.AddMap(vars); format(" ${1$$2$$}$ = $number$,\n", field, FieldConstantName(field)); } format("};\n"); @@ -789,7 +786,12 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { for (auto field : ordered_fields) { PrintFieldComment(format, field); - auto v = p->WithVars(FieldVars(field, options_)); + Formatter::SaveState save(&format); + + std::map vars; + SetCommonFieldVariables(field, &vars, options_); + format.AddMap(vars); + if (field->is_repeated()) { format("$deprecated_attr$int ${1$$name$_size$}$() const$2$\n", field, !IsFieldStripped(field, options_) ? ";" : " {__builtin_trap();}"); @@ -822,7 +824,8 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { !IsFieldStripped(field, options_) ? ";" : "{__builtin_trap();}"); // Generate type-specific accessor declarations. - field_generators_.get(field).GenerateAccessorDeclarations(p); + field_generators_.get(field).GenerateAccessorDeclarations(printer); + format("\n"); } @@ -1039,10 +1042,8 @@ $annotate_repeated_extension_list_mutable$ for (auto oneof : OneOfRange(descriptor_)) { Formatter::SaveState saver(&format); - auto v = p->WithVars({ - {"oneof_name", oneof->name()}, - {"camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true)}, - }); + format.Set("oneof_name", oneof->name()); + format.Set("camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true)); format( "void ${1$clear_$oneof_name$$}$();\n" "$camel_oneof_name$Case $oneof_name$_case() const;\n", @@ -1051,8 +1052,7 @@ $annotate_repeated_extension_list_mutable$ } void MessageGenerator::GenerateSingularFieldHasBits( - const FieldDescriptor* field, io::Printer* p) { - Formatter format(p); + const FieldDescriptor* field, Formatter format) { if (IsFieldStripped(field, options_)) { format( "inline bool $classname$::has_$name$() const { " @@ -1071,11 +1071,9 @@ void MessageGenerator::GenerateSingularFieldHasBits( int has_bit_index = HasBitIndex(field); GOOGLE_CHECK_NE(has_bit_index, kNoHasbit); - auto v = p->WithVars({ - {"has_array_index", has_bit_index / 32}, - {"has_mask", absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8)}, - }); - + format.Set("has_array_index", has_bit_index / 32); + format.Set("has_mask", + strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); format( "inline bool $classname$::_internal_has_$name$() const {\n" " bool value = " @@ -1118,14 +1116,12 @@ void MessageGenerator::GenerateSingularFieldHasBits( } } -void MessageGenerator::GenerateOneofHasBits(io::Printer* p) { - Formatter format(p); - for (const auto* oneof : OneOfRange(descriptor_)) { - auto v = p->WithVars({ - {"oneof_index", oneof->index()}, - {"oneof_name", oneof->name()}, - {"cap_oneof_name", absl::AsciiStrToUpper(oneof->name())}, - }); +void MessageGenerator::GenerateOneofHasBits(io::Printer* printer) { + Formatter format(printer, variables_); + for (auto oneof : OneOfRange(descriptor_)) { + format.Set("oneof_name", oneof->name()); + format.Set("oneof_index", oneof->index()); + format.Set("cap_oneof_name", ToUpper(oneof->name())); format( "inline bool $classname$::has_$oneof_name$() const {\n" " return $oneof_name$_case() != $cap_oneof_name$_NOT_SET;\n" @@ -1137,8 +1133,7 @@ void MessageGenerator::GenerateOneofHasBits(io::Printer* p) { } void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field, - io::Printer* p) { - Formatter format(p); + const Formatter& format) { if (IsFieldStripped(field, options_)) { if (HasHasMethod(field)) { format( @@ -1183,8 +1178,7 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field, } void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, - bool is_inline, io::Printer* p) { - Formatter format(p); + bool is_inline, Formatter format) { if (IsFieldStripped(field, options_)) { format("void $classname$::clear_$name$() { __builtin_trap(); }\n"); return; @@ -1201,10 +1195,9 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, if (field->real_containing_oneof()) { // Clear this field only if it is the active field in this oneof, // otherwise ignore - auto v = p->WithVars(OneofFieldVars(field)); format("if (_internal_has_$name$()) {\n"); format.Indent(); - field_generators_.get(field).GenerateClearingCode(p); + field_generators_.get(field).GenerateClearingCode(format.printer()); format("clear_has_$oneof_name$();\n"); format.Outdent(); format("}\n"); @@ -1212,12 +1205,12 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, if (ShouldSplit(field, options_)) { format("if (IsSplitMessageDefault()) return;\n"); } - field_generators_.get(field).GenerateClearingCode(p); + field_generators_.get(field).GenerateClearingCode(format.printer()); if (HasHasbit(field)) { int has_bit_index = HasBitIndex(field); - auto v = p->WithVars({{"has_array_index", has_bit_index / 32}, - {"has_mask", absl::Hex(1u << (has_bit_index % 32), - absl::kZeroPad8)}}); + format.Set("has_array_index", has_bit_index / 32); + format.Set("has_mask", + strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); format("$has_bits$[$has_array_index$] &= ~0x$has_mask$u;\n"); } } @@ -1226,8 +1219,8 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, format("}\n"); } -void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) { - Formatter format(p); +void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* printer) { + Formatter format(printer, variables_); format("// $classname$\n\n"); for (auto field : FieldRange(descriptor_)) { @@ -1237,7 +1230,12 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) { continue; } - auto v = p->WithVars(FieldVars(field, options_)); + std::map vars; + SetCommonFieldVariables(field, &vars, options_); + + Formatter::SaveState saver(&format); + format.AddMap(vars); + // Generate has_$name$() or $name$_size(). if (field->is_repeated()) { if (IsFieldStripped(field, options_)) { @@ -1259,42 +1257,43 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) { : ""); } } else if (field->real_containing_oneof()) { - auto v = p->WithVars({ - {"field_name", UnderscoresToCamelCase(field->name(), true)}, - {"oneof_name", field->containing_oneof()->name()}, - {"oneof_index", absl::StrCat(field->containing_oneof()->index())}, - }); - GenerateOneofMemberHasBits(field, p); + format.Set("field_name", UnderscoresToCamelCase(field->name(), true)); + format.Set("oneof_name", field->containing_oneof()->name()); + format.Set("oneof_index", + StrCat(field->containing_oneof()->index())); + GenerateOneofMemberHasBits(field, format); } else { // Singular field. - GenerateSingularFieldHasBits(field, p); + GenerateSingularFieldHasBits(field, format); } if (!IsCrossFileMaybeMap(field)) { - GenerateFieldClear(field, true, p); + GenerateFieldClear(field, true, format); } + // Generate type-specific accessors. if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateInlineAccessorDefinitions(p); + field_generators_.get(field).GenerateInlineAccessorDefinitions(printer); } format("\n"); } // Generate has_$name$() and clear_has_$name$() functions for oneofs. - GenerateOneofHasBits(p); + GenerateOneofHasBits(printer); } -void MessageGenerator::GenerateClassDefinition(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); +void MessageGenerator::GenerateClassDefinition(io::Printer* printer) { + Formatter format(printer, variables_); + format.Set("class_final", + ShouldMarkClassAsFinal(descriptor_, options_) ? "final" : ""); if (IsMapEntryMessage(descriptor_)) { std::map vars; CollectMapInfo(options_, descriptor_, &vars); vars["lite"] = HasDescriptorMethods(descriptor_->file(), options_) ? "" : "Lite"; - auto v = p->WithVars(std::move(vars)); + format.AddMap(vars); format( "class $classname$ : public " "::$proto_ns$::internal::MapEntry$lite$<$classname$, \n" @@ -1315,9 +1314,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { " static const $classname$* internal_default_instance() { return " "reinterpret_cast(&_$classname$_default_instance_); }\n"); - auto utf8_check = internal::cpp::GetUtf8CheckMode( - descriptor_->field(0), GetOptimizeFor(descriptor_->file(), options_) == - FileOptions::LITE_RUNTIME); + auto utf8_check = GetUtf8CheckMode(descriptor_->field(0), options_); if (descriptor_->field(0)->type() == FieldDescriptor::TYPE_STRING && utf8_check != Utf8CheckMode::kNone) { if (utf8_check == Utf8CheckMode::kStrict) { @@ -1389,7 +1386,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { } format( - "class $dllexport_decl $${1$$classname$$}$ final :\n" + "class $dllexport_decl $${1$$classname$$}$$ class_final$ :\n" " public $superclass$ /* @@protoc_insertion_point(" "class_definition:$full_name$) */ {\n", descriptor_); @@ -1492,7 +1489,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { format("$1$ = $2$,\n", OneofCaseConstantName(field), // 1 field->number()); // 2 } - format("$1$_NOT_SET = 0,\n", absl::AsciiStrToUpper(oneof->name())); + format("$1$_NOT_SET = 0,\n", ToUpper(oneof->name())); format.Outdent(); format( "};\n" @@ -1521,7 +1518,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { " return $any_metadata$.PackFrom(GetArena(), message);\n" "}\n" "bool PackFrom(const ::$proto_ns$::Message& message,\n" - " ::absl::string_view type_url_prefix) {\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam " + "type_url_prefix) {\n" " $DCHK$_NE(&message, this);\n" " return $any_metadata$.PackFrom(GetArena(), message, " "type_url_prefix);\n" @@ -1543,7 +1541,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "!std::is_convertible" "::value>::type>\n" "bool PackFrom(const T& message,\n" - " ::absl::string_view type_url_prefix) {\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam " + "type_url_prefix) {\n" " return $any_metadata$.PackFrom(GetArena(), message, " "type_url_prefix);" "}\n" @@ -1561,7 +1560,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "}\n" "template \n" "bool PackFrom(const T& message,\n" - " ::absl::string_view type_url_prefix) {\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam " + "type_url_prefix) {\n" " return $any_metadata$.PackFrom(GetArena(), message, " "type_url_prefix);\n" "}\n" @@ -1574,7 +1574,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "template bool Is() const {\n" " return $any_metadata$.Is();\n" "}\n" - "static bool ParseAnyTypeUrl(::absl::string_view type_url,\n" + "static bool ParseAnyTypeUrl(::PROTOBUF_NAMESPACE_ID::ConstStringParam " + "type_url,\n" " std::string* full_type_name);\n"); } @@ -1611,9 +1612,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { // For instances that derive from Message (rather than MessageLite), some // methods are virtual and should be marked as final. - auto v2 = p->WithVars( - {{"full_final", - HasDescriptorMethods(descriptor_->file(), options_) ? "final" : ""}}); + format.Set("full_final", HasDescriptorMethods(descriptor_->file(), options_) + ? "final" + : ""); if (HasGeneratedMethods(descriptor_->file(), options_)) { if (HasDescriptorMethods(descriptor_->file(), options_)) { @@ -1663,7 +1664,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "\n" "size_t ByteSizeLong() const final;\n"); - parse_function_generator_->GenerateMethodDecls(p); + parse_function_generator_->GenerateMethodDecls(printer); format( "$uint8$* _InternalSerialize(\n" @@ -1692,9 +1693,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { // Friend AnyMetadata so that it can call this FullMessageName() method. "\nprivate:\n" "friend class ::$proto_ns$::internal::AnyMetadata;\n" - "static ::absl::string_view FullMessageName() {\n" + "static $1$ FullMessageName() {\n" " return \"$full_name$\";\n" - "}\n"); + "}\n", + options_.opensource_runtime ? "::PROTOBUF_NAMESPACE_ID::StringPiece" + : "::StringPiece"); format( // TODO(gerbens) Make this private! Currently people are deriving from @@ -1755,7 +1758,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { format( "private:\n" "inline bool IsSplitMessageDefault() const {\n" - " return $split$ == reinterpret_cast(&$1$);\n" + " return $split$ == reinterpret_cast(&$1$);\n" "}\n" "PROTOBUF_NOINLINE void PrepareSplitMessageForWrite();\n" "public:\n", @@ -1770,9 +1773,8 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { for (int i = 0; i < descriptor_->nested_type_count(); i++) { const Descriptor* nested_type = descriptor_->nested_type(i); if (!IsMapEntryMessage(nested_type)) { - auto v = - p->WithVars({{"nested_full_name", ClassName(nested_type, false)}, - {"nested_name", ResolveKeyword(nested_type->name())}}); + format.Set("nested_full_name", ClassName(nested_type, false)); + format.Set("nested_name", ResolveKeyword(nested_type->name())); format("typedef ${1$$nested_full_name$$}$ ${1$$nested_name$$}$;\n", nested_type); } @@ -1785,7 +1787,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { // Import all nested enums and their values into this class's scope with // typedefs and constants. for (int i = 0; i < descriptor_->enum_type_count(); i++) { - enum_generators_[i]->GenerateSymbolImports(p); + enum_generators_[i]->GenerateSymbolImports(printer); format("\n"); } @@ -1794,11 +1796,11 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { "\n"); // Generate accessor methods for all fields. - GenerateFieldAccessorDeclarations(p); + GenerateFieldAccessorDeclarations(printer); // Declare extension identifiers. for (int i = 0; i < descriptor_->extension_count(); i++) { - extension_generators_[i]->GenerateDeclaration(p); + extension_generators_[i]->GenerateDeclaration(printer); } @@ -1837,7 +1839,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { } if (HasGeneratedMethods(descriptor_->file(), options_)) { - parse_function_generator_->GenerateDataDecls(p); + parse_function_generator_->GenerateDataDecls(printer); } // Prepare decls for _cached_size_ and _has_bits_. Their position in the @@ -1850,7 +1852,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { const size_t sizeof_has_bits = HasBitsSize(); const std::string has_bits_decl = sizeof_has_bits == 0 ? "" - : absl::StrCat("::$proto_ns$::internal::HasBits<", + : StrCat("::$proto_ns$::internal::HasBits<", sizeof_has_bits, "> _has_bits_;\n"); format( @@ -1906,9 +1908,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { // Emit some private and static members for (auto field : optimized_order_) { const FieldGenerator& generator = field_generators_.get(field); - generator.GenerateStaticMembers(p); + generator.GenerateStaticMembers(printer); if (!ShouldSplit(field, options_)) { - generator.GeneratePrivateMembers(p); + generator.GeneratePrivateMembers(printer); } } if (ShouldSplit(descriptor_, options_)) { @@ -1917,15 +1919,13 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { for (auto field : optimized_order_) { if (!ShouldSplit(field, options_)) continue; const FieldGenerator& generator = field_generators_.get(field); - generator.GeneratePrivateMembers(p); + generator.GeneratePrivateMembers(printer); } format.Outdent(); format( " typedef void InternalArenaConstructable_;\n" " typedef void DestructorSkippable_;\n" "};\n" - "static_assert(std::is_trivially_copy_constructible::value);\n" - "static_assert(std::is_trivially_destructible::value);\n" "Split* _split_;\n"); } @@ -1942,14 +1942,14 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { camel_oneof_name); for (auto field : FieldRange(oneof)) { if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GeneratePrivateMembers(p); + field_generators_.get(field).GeneratePrivateMembers(printer); } } format.Outdent(); format("} $1$_;\n", oneof->name()); for (auto field : FieldRange(oneof)) { if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateStaticMembers(p); + field_generators_.get(field).GenerateStaticMembers(printer); } } } @@ -1986,6 +1986,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { } if (ShouldSplit(descriptor_, options_)) { + format( + "static Impl_::Split* CreateSplitMessage(" + "::$proto_ns$::Arena* arena);\n"); format("friend struct $1$;\n", DefaultInstanceType(descriptor_, options_, /*split=*/true)); } @@ -1999,19 +2002,16 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { GOOGLE_DCHECK(!need_to_emit_cached_size); } // NOLINT(readability/fn_size) -void MessageGenerator::GenerateInlineMethods(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); +void MessageGenerator::GenerateInlineMethods(io::Printer* printer) { if (IsMapEntryMessage(descriptor_)) return; - GenerateFieldAccessorDefinitions(p); + GenerateFieldAccessorDefinitions(printer); // Generate oneof_case() functions. for (auto oneof : OneOfRange(descriptor_)) { - Formatter format(p); - auto v = p->WithVars({ - {"camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true)}, - {"oneof_name", oneof->name()}, - {"oneof_index", oneof->index()}, - }); + Formatter format(printer, variables_); + format.Set("camel_oneof_name", UnderscoresToCamelCase(oneof->name(), true)); + format.Set("oneof_name", oneof->name()); + format.Set("oneof_index", oneof->index()); format( "inline $classname$::$camel_oneof_name$Case $classname$::" "${1$$oneof_name$_case$}$() const {\n" @@ -2022,10 +2022,9 @@ void MessageGenerator::GenerateInlineMethods(io::Printer* p) { } } -void MessageGenerator::GenerateSchema(io::Printer* p, int offset, +void MessageGenerator::GenerateSchema(io::Printer* printer, int offset, int has_offset) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); + Formatter format(printer, variables_); has_offset = !has_bit_indices_.empty() || IsMapEntryMessage(descriptor_) ? offset + has_offset : -1; @@ -2037,13 +2036,13 @@ void MessageGenerator::GenerateSchema(io::Printer* p, int offset, GOOGLE_DCHECK(!IsMapEntryMessage(descriptor_)); inlined_string_indices_offset = has_offset + has_bit_indices_.size(); } + format("{ $1$, $2$, $3$, sizeof($classtype$)},\n", offset, has_offset, inlined_string_indices_offset); } -void MessageGenerator::GenerateClassMethods(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); +void MessageGenerator::GenerateClassMethods(io::Printer* printer) { + Formatter format(printer, variables_); if (IsMapEntryMessage(descriptor_)) { format( "$classname$::$classname$() {}\n" @@ -2088,7 +2087,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { } format( "bool $classname$::ParseAnyTypeUrl(\n" - " ::absl::string_view type_url,\n" + " ::PROTOBUF_NAMESPACE_ID::ConstStringParam type_url,\n" " std::string* full_type_name) {\n" " return ::_pbi::ParseAnyTypeUrl(type_url, full_type_name);\n" "}\n" @@ -2102,17 +2101,10 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { if (!has_bit_indices_.empty()) { format( "using HasBits = " - "decltype(std::declval<$classname$>().$has_bits$);\n" - "static constexpr int32_t kHasBitsOffset =\n" - " 8 * PROTOBUF_FIELD_OFFSET($classname$, _impl_._has_bits_);\n"); - } - if (descriptor_->real_oneof_decl_count() > 0) { - format( - "static constexpr int32_t kOneofCaseOffset =\n" - " PROTOBUF_FIELD_OFFSET($classtype$, $oneof_case$);\n"); + "decltype(std::declval<$classname$>().$has_bits$);\n"); } for (auto field : FieldRange(descriptor_)) { - field_generators_.get(field).GenerateInternalAccessorDeclarations(p); + field_generators_.get(field).GenerateInternalAccessorDeclarations(printer); if (IsFieldStripped(field, options_)) { continue; } @@ -2140,7 +2132,8 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { format("};\n\n"); for (auto field : FieldRange(descriptor_)) { if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateInternalAccessorDefinitions(p); + field_generators_.get(field).GenerateInternalAccessorDefinitions( + printer); } } @@ -2149,49 +2142,54 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { if (IsFieldStripped(field, options_)) { continue; } - field_generators_.get(field).GenerateNonInlineAccessorDefinitions(p); + field_generators_.get(field).GenerateNonInlineAccessorDefinitions(printer); if (IsCrossFileMaybeMap(field)) { - auto v1 = p->WithVars(FieldVars(field, options_)); - auto v2 = p->WithVars(OneofFieldVars(field)); - GenerateFieldClear(field, false, p); + Formatter::SaveState saver(&format); + std::map vars; + SetCommonFieldVariables(field, &vars, options_); + if (field->real_containing_oneof()) { + SetCommonOneofFieldVariables(field, &vars); + } + format.AddMap(vars); + GenerateFieldClear(field, false, format); } } - GenerateStructors(p); + GenerateStructors(printer); format("\n"); if (descriptor_->real_oneof_decl_count() > 0) { - GenerateOneofClear(p); + GenerateOneofClear(printer); format("\n"); } if (HasGeneratedMethods(descriptor_->file(), options_)) { - GenerateClear(p); + GenerateClear(printer); format("\n"); if (!HasSimpleBaseClass(descriptor_, options_)) { - parse_function_generator_->GenerateMethodImpls(p); + parse_function_generator_->GenerateMethodImpls(printer); format("\n"); - parse_function_generator_->GenerateDataDefinitions(p); + parse_function_generator_->GenerateDataDefinitions(printer); } - GenerateSerializeWithCachedSizesToArray(p); + GenerateSerializeWithCachedSizesToArray(printer); format("\n"); - GenerateByteSize(p); + GenerateByteSize(printer); format("\n"); - GenerateMergeFrom(p); + GenerateMergeFrom(printer); format("\n"); - GenerateClassSpecificMergeImpl(p); + GenerateClassSpecificMergeImpl(printer); format("\n"); - GenerateCopyFrom(p); + GenerateCopyFrom(printer); format("\n"); - GenerateIsInitialized(p); + GenerateIsInitialized(printer); format("\n"); } @@ -2199,19 +2197,14 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { format( "void $classname$::PrepareSplitMessageForWrite() {\n" " if (IsSplitMessageDefault()) {\n" - " void* chunk = " - "::PROTOBUF_NAMESPACE_ID::internal::CreateSplitMessageGeneric(" - "GetArenaForAllocation(), &$1$, sizeof(Impl_::Split), this, &$2$);\n" - " $split$ = reinterpret_cast(chunk);\n" + " $split$ = CreateSplitMessage(GetArenaForAllocation());\n" " }\n" - "}\n", - DefaultInstanceName(descriptor_, options_, /*split=*/true), - DefaultInstanceName(descriptor_, options_, /*split=*/false)); + "}\n"); } - GenerateVerify(p); + GenerateVerify(printer); - GenerateSwap(p); + GenerateSwap(printer); format("\n"); if (HasDescriptorMethods(descriptor_->file(), options_)) { @@ -2249,9 +2242,9 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { } } -std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); +std::pair MessageGenerator::GenerateOffsets( + io::Printer* printer) { + Formatter format(printer, variables_); if (!has_bit_indices_.empty() || IsMapEntryMessage(descriptor_)) { format("PROTOBUF_FIELD_OFFSET($classtype$, $has_bits$),\n"); @@ -2281,16 +2274,7 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { } else { format("~0u, // no _inlined_string_donated_\n"); } - if (ShouldSplit(descriptor_, options_)) { - format( - "PROTOBUF_FIELD_OFFSET($classtype$, $split$),\n" - "sizeof($classtype$::Impl_::Split),\n"); - } else { - format( - "~0u, // no _split_\n" - "~0u, // no sizeof(Split)\n"); - } - const int kNumGenericOffsets = 8; // the number of fixed offsets above + const int kNumGenericOffsets = 6; // the number of fixed offsets above const size_t offsets = kNumGenericOffsets + descriptor_->field_count() + descriptor_->real_oneof_decl_count(); size_t entries = offsets; @@ -2318,17 +2302,12 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { // offset of the field, so that the information is available when // reflectively accessing the field at run time. // - // We embed whether the field is cold to the MSB of the offset, and whether - // the field is eagerly verified lazy or inlined string to the LSB of the - // offset. - - if (ShouldSplit(field, options_)) { - format(" | ::_pbi::kSplitFieldOffsetMask /*split*/"); - } + // Embed whether the field is eagerly verified lazy or inlined string to the + // LSB of the offset. if (IsEagerlyVerifiedLazy(field, options_, scc_analyzer_)) { - format(" | 0x1u /*eagerly verified lazy*/"); + format(" | 0x1u // eagerly verified lazy\n"); } else if (IsStringInlined(field, options_)) { - format(" | 0x1u /*inlined*/"); + format(" | 0x1u // inlined\n"); } format(",\n"); } @@ -2349,7 +2328,7 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { entries += has_bit_indices_.size(); for (int i = 0; i < has_bit_indices_.size(); i++) { const std::string index = - has_bit_indices_[i] >= 0 ? absl::StrCat(has_bit_indices_[i]) : "~0u"; + has_bit_indices_[i] >= 0 ? StrCat(has_bit_indices_[i]) : "~0u"; format("$1$,\n", index); } } @@ -2358,7 +2337,7 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { for (int inlined_string_index : inlined_string_indices_) { const std::string index = inlined_string_index >= 0 - ? absl::StrCat(inlined_string_index, ", // inlined_string_index") + ? StrCat(inlined_string_index, ", // inlined_string_index") : "~0u,"; format("$1$\n", index); } @@ -2367,9 +2346,9 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { return std::make_pair(entries, offsets); } -void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { +void MessageGenerator::GenerateSharedConstructorCode(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); format( "inline void $classname$::SharedCtor(\n" @@ -2415,19 +2394,12 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { continue; } put_sep(); - field_generators_.get(field).GenerateAggregateInitializer(p); + field_generators_.get(field).GenerateAggregateInitializer(printer); } if (ShouldSplit(descriptor_, options_)) { put_sep(); - // We can't assign the default split to this->split without the const_cast - // because the former is a const. The const_cast is safe because we don't - // intend to modify the default split through this pointer, and we also - // expect the default split to be in the rodata section which is protected - // from mutation. - format( - "decltype($split$){const_cast" - "(reinterpret_cast(&$1$))}", - DefaultInstanceName(descriptor_, options_, /*split=*/true)); + format("decltype($split$){reinterpret_cast(&$1$)}", + DefaultInstanceName(descriptor_, options_, /*split=*/true)); } for (auto oneof : OneOfRange(descriptor_)) { put_sep(); @@ -2485,14 +2457,7 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { if (ShouldSplit(field, options_)) { continue; } - field_generators_.get(field).GenerateConstructorCode(p); - } - - if (ShouldForceAllocationOnConstruction(descriptor_, options_)) { - format( - "#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n" - "$mutable_unknown_fields$;\n" - "#endif // PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n"); + field_generators_.get(field).GenerateConstructorCode(printer); } for (auto oneof : OneOfRange(descriptor_)) { @@ -2503,11 +2468,49 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { format("}\n\n"); } -void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* p) { +void MessageGenerator::GenerateCreateSplitMessage(io::Printer* printer) { + Formatter format(printer, variables_); + format( + "$classname$::Impl_::Split* " + "$classname$::CreateSplitMessage(::$proto_ns$::Arena* arena) {\n"); + format.Indent(); + const char* field_sep = " "; + const auto put_sep = [&] { + format("\n$1$ ", field_sep); + field_sep = ","; + }; + format( + "const size_t size = sizeof(Impl_::Split);\n" + "void* chunk = (arena == nullptr) ?\n" + " ::operator new(size) :\n" + " arena->AllocateAligned(size, alignof(Impl_::Split));\n" + "Impl_::Split* ptr = reinterpret_cast(chunk);\n" + "new (ptr) Impl_::Split{"); + format.Indent(); + for (const FieldDescriptor* field : optimized_order_) { + GOOGLE_DCHECK(!IsFieldStripped(field, options_)); + if (ShouldSplit(field, options_)) { + put_sep(); + field_generators_.get(field).GenerateAggregateInitializer(printer); + } + } + format.Outdent(); + format("};\n"); + for (const FieldDescriptor* field : optimized_order_) { + GOOGLE_DCHECK(!IsFieldStripped(field, options_)); + if (ShouldSplit(field, options_)) { + field_generators_.get(field).GenerateCreateSplitMessageCode(printer); + } + } + format("return ptr;\n"); + format.Outdent(); + format("}\n"); +} + +void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* printer) { if (!ShouldSplit(descriptor_, options_)) return; - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); + Formatter format(printer, variables_); const char* field_sep = " "; const auto put_sep = [&] { format("\n$1$ ", field_sep); @@ -2516,14 +2519,15 @@ void MessageGenerator::GenerateInitDefaultSplitInstance(io::Printer* p) { for (const auto* field : optimized_order_) { if (ShouldSplit(field, options_)) { put_sep(); - field_generators_.get(field).GenerateConstexprAggregateInitializer(p); + field_generators_.get(field).GenerateConstexprAggregateInitializer( + printer); } } } -void MessageGenerator::GenerateSharedDestructorCode(io::Printer* p) { +void MessageGenerator::GenerateSharedDestructorCode(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); format("inline void $classname$::SharedDtor() {\n"); format.Indent(); @@ -2539,7 +2543,7 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* p) { if (ShouldSplit(field, options_)) { continue; } - field_generators_.get(field).GenerateDestructorCode(p); + field_generators_.get(field).GenerateDestructorCode(printer); } if (ShouldSplit(descriptor_, options_)) { format("if (!IsSplitMessageDefault()) {\n"); @@ -2547,7 +2551,7 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* p) { format("auto* $cached_split_ptr$ = $split$;\n"); for (auto field : optimized_order_) { if (ShouldSplit(field, options_)) { - field_generators_.get(field).GenerateDestructorCode(p); + field_generators_.get(field).GenerateDestructorCode(printer); } } format("delete $cached_split_ptr$;\n"); @@ -2589,10 +2593,10 @@ ArenaDtorNeeds MessageGenerator::NeedsArenaDestructor() const { return needs; } -void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { +void MessageGenerator::GenerateArenaDestructorCode(io::Printer* printer) { GOOGLE_CHECK(NeedsArenaDestructor() > ArenaDtorNeeds::kNone); - Formatter format(p); + Formatter format(printer, variables_); // Generate the ArenaDtor() method. Track whether any fields actually produced // code that needs to be called. @@ -2610,7 +2614,7 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { if (IsFieldStripped(field, options_) || ShouldSplit(field, options_)) continue; const FieldGenerator& fg = field_generators_.get(field); - fg.GenerateArenaDestructorCode(p); + fg.GenerateArenaDestructorCode(printer); } if (ShouldSplit(descriptor_, options_)) { format("if (!_this->IsSplitMessageDefault()) {\n"); @@ -2619,7 +2623,7 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { if (IsFieldStripped(field, options_) || !ShouldSplit(field, options_)) continue; const FieldGenerator& fg = field_generators_.get(field); - fg.GenerateArenaDestructorCode(p); + fg.GenerateArenaDestructorCode(printer); } format.Outdent(); format("}\n"); @@ -2629,7 +2633,7 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { for (auto oneof : OneOfRange(descriptor_)) { for (auto field : FieldRange(oneof)) { if (IsFieldStripped(field, options_)) continue; - field_generators_.get(field).GenerateArenaDestructorCode(p); + field_generators_.get(field).GenerateArenaDestructorCode(printer); } } @@ -2637,9 +2641,8 @@ void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { format("}\n"); } -void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); +void MessageGenerator::GenerateConstexprConstructor(io::Printer* printer) { + Formatter format(printer, variables_); if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) { format( @@ -2682,11 +2685,12 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) { continue; } put_sep(); - field_generators_.get(field).GenerateConstexprAggregateInitializer(p); + field_generators_.get(field).GenerateConstexprAggregateInitializer( + printer); } if (ShouldSplit(descriptor_, options_)) { put_sep(); - format("/*decltype($split$)*/const_cast(&$1$._instance)", + format("/*decltype($split$)*/&$1$._instance", DefaultInstanceName(descriptor_, options_, /*split=*/true)); } @@ -2721,8 +2725,8 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) { format("} {}\n"); } -void MessageGenerator::GenerateCopyConstructorBody(io::Printer* p) const { - Formatter format(p); +void MessageGenerator::GenerateCopyConstructorBody(io::Printer* printer) const { + Formatter format(printer, variables_); const RunMap runs = FindRuns(optimized_order_, [this](const FieldDescriptor* field) { @@ -2734,11 +2738,17 @@ void MessageGenerator::GenerateCopyConstructorBody(io::Printer* p) const { " static_cast(reinterpret_cast(&$last$) -\n" " reinterpret_cast(&$first$)) + sizeof($last$));\n"; - if (ShouldForceAllocationOnConstruction(descriptor_, options_)) { - format( - "#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n" - "$mutable_unknown_fields$;\n" - "#endif // PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION\n"); + if (ShouldSplit(descriptor_, options_)) { + format("if (!from.IsSplitMessageDefault()) {\n"); + format.Indent(); + format("_this->PrepareSplitMessageForWrite();\n"); + for (auto field : optimized_order_) { + if (ShouldSplit(field, options_)) { + field_generators_.get(field).GenerateCopyConstructorCode(printer); + } + } + format.Outdent(); + format("}\n"); } for (size_t i = 0; i < optimized_order_.size(); ++i) { @@ -2758,36 +2768,21 @@ void MessageGenerator::GenerateCopyConstructorBody(io::Printer* p) const { const std::string last_field_name = FieldMemberName(optimized_order_[i + run_length - 1], /*cold=*/false); - auto v = p->WithVars({ - {"first", first_field_name}, - {"last", last_field_name}, - }); + format.Set("first", first_field_name); + format.Set("last", last_field_name); + format(pod_template.c_str()); i += run_length - 1; // ++i at the top of the loop. } else { - field_generators_.get(field).GenerateCopyConstructorCode(p); + field_generators_.get(field).GenerateCopyConstructorCode(printer); } } - - if (ShouldSplit(descriptor_, options_)) { - format("if (!from.IsSplitMessageDefault()) {\n"); - format.Indent(); - format("_this->PrepareSplitMessageForWrite();\n"); - // TODO(b/122856539): cache the split pointers. - for (auto field : optimized_order_) { - if (ShouldSplit(field, options_)) { - field_generators_.get(field).GenerateCopyConstructorCode(p); - } - } - format.Outdent(); - format("}\n"); - } } -void MessageGenerator::GenerateStructors(io::Printer* p) { - Formatter format(p); +void MessageGenerator::GenerateStructors(io::Printer* printer) { + Formatter format(printer, variables_); format( "$classname$::$classname$(::$proto_ns$::Arena* arena,\n" @@ -2808,30 +2803,9 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { " // @@protoc_insertion_point(arena_constructor:$full_name$)\n" "}\n"); - // If the message contains only scalar fields (ints and enums), - // then we can copy the entire impl_ section with a single statement. - bool copy_construct_impl = - !ShouldSplit(descriptor_, options_) && - !HasSimpleBaseClass(descriptor_, options_) && - (descriptor_->extension_range_count() == 0 && - descriptor_->real_oneof_decl_count() == 0 && num_weak_fields_ == 0); - for (const auto& field : optimized_order_) { - if (!copy_construct_impl) break; - if (field->is_repeated() || field->is_extension()) { - copy_construct_impl = false; - } else if (field->cpp_type() != FieldDescriptor::CPPTYPE_ENUM && - field->cpp_type() != FieldDescriptor::CPPTYPE_INT32 && - field->cpp_type() != FieldDescriptor::CPPTYPE_INT64 && - field->cpp_type() != FieldDescriptor::CPPTYPE_UINT32 && - field->cpp_type() != FieldDescriptor::CPPTYPE_UINT64 && - field->cpp_type() != FieldDescriptor::CPPTYPE_FLOAT && - field->cpp_type() != FieldDescriptor::CPPTYPE_DOUBLE && - field->cpp_type() != FieldDescriptor::CPPTYPE_BOOL) { - copy_construct_impl = false; - } else { - // non-repeated integer fields are fine to copy en masse. - } - } + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); // Generate the copy constructor. if (UsingImplicitWeakFields(descriptor_->file(), options_)) { @@ -2844,16 +2818,6 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { " : $classname$() {\n" " MergeFrom(from);\n" "}\n"); - } else if (copy_construct_impl) { - format( - "$classname$::$classname$(const $classname$& from)\n" - " : $superclass$(), _impl_(from._impl_) {\n" - " _internal_metadata_.MergeFrom<$unknown_fields_type$>(\n" - " from._internal_metadata_);\n"); - format( - " // @@protoc_insertion_point(copy_constructor:$full_name$)\n" - "}\n" - "\n"); } else { format( "$classname$::$classname$(const $classname$& from)\n" @@ -2899,14 +2863,12 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { continue; } put_sep(); - field_generators_.get(field).GenerateCopyAggregateInitializer(p); + field_generators_.get(field).GenerateCopyAggregateInitializer(printer); } if (ShouldSplit(descriptor_, options_)) { put_sep(); - format( - "decltype($split$){const_cast" - "(reinterpret_cast(&$1$))}", - DefaultInstanceName(descriptor_, options_, /*split=*/true)); + format("decltype($split$){reinterpret_cast(&$1$)}", + DefaultInstanceName(descriptor_, options_, /*split=*/true)); } for (auto oneof : OneOfRange(descriptor_)) { put_sep(); @@ -2945,7 +2907,7 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { "from.$extensions$);\n"); } - GenerateCopyConstructorBody(p); + GenerateCopyConstructorBody(printer); // Copy oneof fields. Oneof field requires oneof case check. for (auto oneof : OneOfRange(descriptor_)) { @@ -2958,7 +2920,7 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format.Indent(); if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateMergingCode(p); + field_generators_.get(field).GenerateMergingCode(printer); } format("break;\n"); format.Outdent(); @@ -2968,7 +2930,7 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { "case $1$_NOT_SET: {\n" " break;\n" "}\n", - absl::AsciiStrToUpper(oneof->name())); + ToUpper(oneof->name())); format.Outdent(); format("}\n"); } @@ -2981,7 +2943,11 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { } // Generate the shared constructor code. - GenerateSharedConstructorCode(p); + GenerateSharedConstructorCode(printer); + + if (ShouldSplit(descriptor_, options_)) { + GenerateCreateSplitMessage(printer); + } // Generate the destructor. if (!HasSimpleBaseClass(descriptor_, options_)) { @@ -3011,11 +2977,11 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { } // Generate the shared destructor code. - GenerateSharedDestructorCode(p); + GenerateSharedDestructorCode(printer); // Generate the arena-specific destructor code. if (NeedsArenaDestructor() > ArenaDtorNeeds::kNone) { - GenerateArenaDestructorCode(p); + GenerateArenaDestructorCode(printer); } if (!HasSimpleBaseClass(descriptor_, options_)) { @@ -3027,9 +2993,8 @@ void MessageGenerator::GenerateStructors(io::Printer* p) { } } -void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* p) { - auto v = p->WithVars(ClassVars(descriptor_, options_)); - Formatter format(p); +void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* printer) { + Formatter format(printer, variables_); format( "template<> " "PROTOBUF_NOINLINE $classtype$*\n" @@ -3038,9 +3003,9 @@ void MessageGenerator::GenerateSourceInProto2Namespace(io::Printer* p) { "}\n"); } -void MessageGenerator::GenerateClear(io::Printer* p) { +void MessageGenerator::GenerateClear(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); // The maximum number of bytes we will memset to zero without checking their // hasbit to see if a zero-init is necessary. @@ -3092,26 +3057,15 @@ void MessageGenerator::GenerateClear(io::Printer* p) { ColdChunkSkipper cold_skipper(descriptor_, options_, chunks, has_bit_indices_, kColdRatio); int cached_has_word_index = -1; - bool first_split_chunk_processed = false; - for (size_t chunk_index = 0; chunk_index < chunks.size(); chunk_index++) { + + for (int chunk_index = 0; chunk_index < chunks.size(); chunk_index++) { std::vector& chunk = chunks[chunk_index]; - cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "", p); + cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "", printer); const FieldDescriptor* memset_start = nullptr; const FieldDescriptor* memset_end = nullptr; bool saw_non_zero_init = false; - bool chunk_is_split = - !chunk.empty() && ShouldSplit(chunk.front(), options_); - // All chunks after the first split chunk should also be split. - GOOGLE_CHECK(!first_split_chunk_processed || chunk_is_split); - if (chunk_is_split && !first_split_chunk_processed) { - // Some fields are cleared without checking has_bit. So we add the - // condition here to avoid writing to the default split instance. - format("if (!IsSplitMessageDefault()) {\n"); - format.Indent(); - first_split_chunk_processed = true; - } - + bool chunk_is_cold = !chunk.empty() && ShouldSplit(chunk.front(), options_); for (const auto& field : chunk) { if (CanInitializeByZeroing(field)) { GOOGLE_CHECK(!saw_non_zero_init); @@ -3135,7 +3089,7 @@ void MessageGenerator::GenerateClear(io::Printer* p) { // Emit an if() that will let us skip the whole chunk if none are set. uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = - absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8)); + StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check @@ -3151,19 +3105,25 @@ void MessageGenerator::GenerateClear(io::Printer* p) { format.Indent(); } + if (chunk_is_cold) { + format("if (!IsSplitMessageDefault()) {\n"); + format.Indent(); + } + if (memset_start) { if (memset_start == memset_end) { // For clarity, do not memset a single field. - field_generators_.get(memset_start).GenerateMessageClearingCode(p); + field_generators_.get(memset_start) + .GenerateMessageClearingCode(printer); } else { - GOOGLE_CHECK_EQ(chunk_is_split, ShouldSplit(memset_start, options_)); - GOOGLE_CHECK_EQ(chunk_is_split, ShouldSplit(memset_end, options_)); + GOOGLE_CHECK_EQ(chunk_is_cold, ShouldSplit(memset_start, options_)); + GOOGLE_CHECK_EQ(chunk_is_cold, ShouldSplit(memset_end, options_)); format( "::memset(&$1$, 0, static_cast(\n" " reinterpret_cast(&$2$) -\n" " reinterpret_cast(&$1$)) + sizeof($2$));\n", - FieldMemberName(memset_start, chunk_is_split), - FieldMemberName(memset_end, chunk_is_split)); + FieldMemberName(memset_start, chunk_is_cold), + FieldMemberName(memset_end, chunk_is_cold)); } } @@ -3180,10 +3140,11 @@ void MessageGenerator::GenerateClear(io::Printer* p) { field->cpp_type() == FieldDescriptor::CPPTYPE_STRING); if (have_enclosing_if) { - PrintPresenceCheck(field, has_bit_indices_, p, &cached_has_word_index); + PrintPresenceCheck(format, field, has_bit_indices_, printer, + &cached_has_word_index); } - field_generators_.get(field).GenerateMessageClearingCode(p); + field_generators_.get(field).GenerateMessageClearingCode(printer); if (have_enclosing_if) { format.Outdent(); @@ -3191,19 +3152,17 @@ void MessageGenerator::GenerateClear(io::Printer* p) { } } + if (chunk_is_cold) { + format.Outdent(); + format("}\n"); + } + if (have_outer_if) { format.Outdent(); format("}\n"); } - if (chunk_index == chunks.size() - 1) { - if (first_split_chunk_processed) { - format.Outdent(); - format("}\n"); - } - } - - if (cold_skipper.OnEndChunk(chunk_index, p)) { + if (cold_skipper.OnEndChunk(chunk_index, printer)) { // Reset here as it may have been updated in just closed if statement. cached_has_word_index = -1; } @@ -3225,18 +3184,21 @@ void MessageGenerator::GenerateClear(io::Printer* p) { format("$has_bits$.Clear();\n"); } + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); format("_internal_metadata_.Clear<$unknown_fields_type$>();\n"); format.Outdent(); format("}\n"); } -void MessageGenerator::GenerateOneofClear(io::Printer* p) { +void MessageGenerator::GenerateOneofClear(io::Printer* printer) { // Generated function clears the active field and union case (e.g. foo_case_). int i = 0; for (auto oneof : OneOfRange(descriptor_)) { - Formatter format(p); - auto v = p->WithVars({{"oneofname", oneof->name()}}); + Formatter format(printer, variables_); + format.Set("oneofname", oneof->name()); format( "void $classname$::clear_$oneofname$() {\n" @@ -3251,7 +3213,7 @@ void MessageGenerator::GenerateOneofClear(io::Printer* p) { if (!IsStringOrMessage(field) || IsFieldStripped(field, options_)) { format("// No need to clear\n"); } else { - field_generators_.get(field).GenerateClearingCode(p); + field_generators_.get(field).GenerateClearingCode(printer); } format("break;\n"); format.Outdent(); @@ -3261,12 +3223,12 @@ void MessageGenerator::GenerateOneofClear(io::Printer* p) { "case $1$_NOT_SET: {\n" " break;\n" "}\n", - absl::AsciiStrToUpper(oneof->name())); + ToUpper(oneof->name())); format.Outdent(); format( "}\n" "$oneof_case$[$1$] = $2$_NOT_SET;\n", - i, absl::AsciiStrToUpper(oneof->name())); + i, ToUpper(oneof->name())); format.Outdent(); format( "}\n" @@ -3275,9 +3237,9 @@ void MessageGenerator::GenerateOneofClear(io::Printer* p) { } } -void MessageGenerator::GenerateSwap(io::Printer* p) { +void MessageGenerator::GenerateSwap(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); format("void $classname$::InternalSwap($classname$* other) {\n"); format.Indent(); @@ -3290,6 +3252,9 @@ void MessageGenerator::GenerateSwap(io::Printer* p) { "\n"); } + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); if (HasNonSplitOptionalString(descriptor_, options_)) { format( "auto* lhs_arena = GetArenaForAllocation();\n" @@ -3328,10 +3293,8 @@ void MessageGenerator::GenerateSwap(io::Printer* p) { const std::string last_field_name = FieldMemberName( optimized_order_[i + run_length - 1], /*cold=*/false); - auto v = p->WithVars({ - {"first", first_field_name}, - {"last", last_field_name}, - }); + format.Set("first", first_field_name); + format.Set("last", last_field_name); format( "::PROTOBUF_NAMESPACE_ID::internal::memswap<\n" @@ -3344,7 +3307,7 @@ void MessageGenerator::GenerateSwap(io::Printer* p) { i += run_length - 1; // ++i at the top of the loop. } else { - field_generators_.get(field).GenerateSwappingCode(p); + field_generators_.get(field).GenerateSwappingCode(printer); } } if (ShouldSplit(descriptor_, options_)) { @@ -3381,8 +3344,8 @@ void MessageGenerator::GenerateSwap(io::Printer* p) { format("}\n"); } -void MessageGenerator::GenerateMergeFrom(io::Printer* p) { - Formatter format(p); +void MessageGenerator::GenerateMergeFrom(io::Printer* printer) { + Formatter format(printer, variables_); if (!HasSimpleBaseClass(descriptor_, options_)) { if (HasDescriptorMethods(descriptor_->file(), options_)) { // We don't override the generalized MergeFrom (aka that which @@ -3428,10 +3391,10 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* p) { } } -void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { +void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; // Generate the class-specific MergeFrom, which avoids the GOOGLE_CHECK and cast. - Formatter format(p); + Formatter format(printer, variables_); if (!HasDescriptorMethods(descriptor_->file(), options_)) { // For messages that don't inherit from Message, just implement MergeFrom // directly. @@ -3482,13 +3445,14 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { const std::vector& chunk = chunks[chunk_index]; bool have_outer_if = chunk.size() > 1 && HasByteIndex(chunk.front()) != kNoHasbit; - cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "from.", p); + cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "from.", + printer); if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = - absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8)); + StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check @@ -3512,13 +3476,13 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { const FieldGenerator& generator = field_generators_.get(field); if (field->is_repeated()) { - generator.GenerateMergingCode(p); + generator.GenerateMergingCode(printer); } else if (field->is_optional() && !HasHasbit(field)) { // Merge semantics without true field presence: primitive fields are // merged only if non-zero (numeric) or non-empty (string). bool have_enclosing_if = - EmitFieldNonDefaultCondition(p, "from.", field); - generator.GenerateMergingCode(p); + EmitFieldNonDefaultCondition(printer, "from.", field); + generator.GenerateMergingCode(printer); if (have_enclosing_if) { format.Outdent(); format("}\n"); @@ -3529,15 +3493,15 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { GOOGLE_CHECK(HasHasbit(field)); format("if (from._internal_has_$1$()) {\n", FieldName(field)); format.Indent(); - generator.GenerateMergingCode(p); + generator.GenerateMergingCode(printer); format.Outdent(); format("}\n"); } else { // Check hasbit, using cached bits. GOOGLE_CHECK(HasHasbit(field)); int has_bit_index = has_bit_indices_[field->index()]; - const std::string mask = absl::StrCat( - absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8)); + const std::string mask = StrCat( + strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); format("if (cached_has_bits & 0x$1$u) {\n", mask); format.Indent(); @@ -3545,9 +3509,9 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { // Defer hasbit modification until the end of chunk. // This can reduce the number of loads/stores by up to 7 per 8 fields. deferred_has_bit_changes = true; - generator.GenerateCopyConstructorCode(p); + generator.GenerateCopyConstructorCode(printer); } else { - generator.GenerateMergingCode(p); + generator.GenerateMergingCode(printer); } format.Outdent(); @@ -3567,7 +3531,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { format("}\n"); } - if (cold_skipper.OnEndChunk(chunk_index, p)) { + if (cold_skipper.OnEndChunk(chunk_index, printer)) { // Reset here as it may have been updated in just closed if statement. cached_has_word_index = -1; } @@ -3581,7 +3545,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format.Indent(); if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateMergingCode(p); + field_generators_.get(field).GenerateMergingCode(printer); } format("break;\n"); format.Outdent(); @@ -3591,7 +3555,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { "case $1$_NOT_SET: {\n" " break;\n" "}\n", - absl::AsciiStrToUpper(oneof->name())); + ToUpper(oneof->name())); format.Outdent(); format("}\n"); } @@ -3618,9 +3582,9 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { format("}\n"); } -void MessageGenerator::GenerateCopyFrom(io::Printer* p) { +void MessageGenerator::GenerateCopyFrom(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); if (HasDescriptorMethods(descriptor_->file(), options_)) { // We don't override the generalized CopyFrom (aka that which // takes in the Message base class as a parameter); instead we just @@ -3679,15 +3643,15 @@ void MessageGenerator::GenerateCopyFrom(io::Printer* p) { format("}\n"); } -void MessageGenerator::GenerateVerify(io::Printer* p) { +void MessageGenerator::GenerateVerify(io::Printer* printer) { } void MessageGenerator::GenerateSerializeOneofFields( - io::Printer* p, const std::vector& fields) { - Formatter format(p); + io::Printer* printer, const std::vector& fields) { + Formatter format(printer, variables_); GOOGLE_CHECK(!fields.empty()); if (fields.size() == 1) { - GenerateSerializeOneField(p, fields[0], -1); + GenerateSerializeOneField(printer, fields[0], -1); return; } // We have multiple mutually exclusive choices. Emit a switch statement. @@ -3697,7 +3661,8 @@ void MessageGenerator::GenerateSerializeOneofFields( for (auto field : fields) { format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format.Indent(); - field_generators_.get(field).GenerateSerializeWithCachedSizesToArray(p); + field_generators_.get(field).GenerateSerializeWithCachedSizesToArray( + printer); format("break;\n"); format.Outdent(); format("}\n"); @@ -3709,10 +3674,10 @@ void MessageGenerator::GenerateSerializeOneofFields( "}\n"); } -void MessageGenerator::GenerateSerializeOneField(io::Printer* p, +void MessageGenerator::GenerateSerializeOneField(io::Printer* printer, const FieldDescriptor* field, int cached_has_bits_index) { - Formatter format(p); + Formatter format(printer, variables_); if (!field->options().weak()) { // For weakfields, PrintFieldComment is called during iteration. PrintFieldComment(format, field); @@ -3725,7 +3690,7 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p, int has_bit_index = HasBitIndex(field); if (cached_has_bits_index == has_bit_index / 32) { const std::string mask = - absl::StrCat(absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8)); + StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); format("if (cached_has_bits & 0x$1$u) {\n", mask); } else { @@ -3735,10 +3700,10 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p, format.Indent(); have_enclosing_if = true; } else if (field->is_optional() && !HasHasbit(field)) { - have_enclosing_if = EmitFieldNonDefaultCondition(p, "this->", field); + have_enclosing_if = EmitFieldNonDefaultCondition(printer, "this->", field); } - field_generators_.get(field).GenerateSerializeWithCachedSizesToArray(p); + field_generators_.get(field).GenerateSerializeWithCachedSizesToArray(printer); if (have_enclosing_if) { format.Outdent(); @@ -3748,20 +3713,21 @@ void MessageGenerator::GenerateSerializeOneField(io::Printer* p, } void MessageGenerator::GenerateSerializeOneExtensionRange( - io::Printer* p, const Descriptor::ExtensionRange* range) { + io::Printer* printer, const Descriptor::ExtensionRange* range) { std::map vars = variables_; - vars["start"] = absl::StrCat(range->start); - vars["end"] = absl::StrCat(range->end); - Formatter format(p, vars); + vars["start"] = StrCat(range->start); + vars["end"] = StrCat(range->end); + Formatter format(printer, vars); format("// Extension range [$start$, $end$)\n"); format( "target = $extensions$._InternalSerialize(\n" "internal_default_instance(), $start$, $end$, target, stream);\n\n"); } -void MessageGenerator::GenerateSerializeWithCachedSizesToArray(io::Printer* p) { +void MessageGenerator::GenerateSerializeWithCachedSizesToArray( + io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. format( @@ -3772,7 +3738,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray(io::Printer* p) { " target = $extensions$." "InternalSerializeMessageSetWithCachedSizesToArray(\n" // "internal_default_instance(), target, stream);\n"); - + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); format( " target = ::_pbi::" "InternalSerializeUnknownMessageSetItemsToArray(\n" @@ -3798,14 +3766,14 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray(io::Printer* p) { format.Indent(); } - GenerateSerializeWithCachedSizesBody(p); + GenerateSerializeWithCachedSizesBody(printer); if (!ShouldSerializeInOrder(descriptor_, options_)) { format.Outdent(); format("#else // NDEBUG\n"); format.Indent(); - GenerateSerializeWithCachedSizesBodyShuffled(p); + GenerateSerializeWithCachedSizesBodyShuffled(printer); format.Outdent(); format("#endif // !NDEBUG\n"); @@ -3820,9 +3788,10 @@ void MessageGenerator::GenerateSerializeWithCachedSizesToArray(io::Printer* p) { "}\n"); } -void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { +void MessageGenerator::GenerateSerializeWithCachedSizesBody( + io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); // If there are multiple fields in a row from the same oneof then we // coalesce them and emit a switch statement. This is more efficient // because it lets the C++ compiler know this is a "at most one can happen" @@ -3830,9 +3799,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { // compiler's emitted code might check has_y() even when has_x() is true. class LazySerializerEmitter { public: - LazySerializerEmitter(MessageGenerator* mg, io::Printer* p) + LazySerializerEmitter(MessageGenerator* mg, io::Printer* printer) : mg_(mg), - p_(p), + format_(printer), eager_(IsProto3(mg->descriptor_->file())), cached_has_bit_index_(kNoHasbit) {} @@ -3841,7 +3810,6 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { // If conditions allow, try to accumulate a run of fields from the same // oneof, and handle them at the next Flush(). void Emit(const FieldDescriptor* field) { - Formatter format(p_); if (eager_ || MustFlush(field)) { Flush(); } @@ -3857,13 +3825,14 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { // Reload. int new_index = has_bit_index / 32; - format("cached_has_bits = _impl_._has_bits_[$1$];\n", new_index); + format_("cached_has_bits = _impl_._has_bits_[$1$];\n", new_index); cached_has_bit_index_ = new_index; } } - mg_->GenerateSerializeOneField(p_, field, cached_has_bit_index_); + mg_->GenerateSerializeOneField(format_.printer(), field, + cached_has_bit_index_); } else { v_.push_back(field); } @@ -3877,7 +3846,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { void Flush() { if (!v_.empty()) { - mg_->GenerateSerializeOneofFields(p_, v_); + mg_->GenerateSerializeOneofFields(format_.printer(), v_); v_.clear(); } } @@ -3891,8 +3860,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { } MessageGenerator* mg_; - io::Printer* p_; - bool eager_; + Formatter format_; + const bool eager_; std::vector v_; // cached_has_bit_index_ maintains that: @@ -3903,8 +3872,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { class LazyExtensionRangeEmitter { public: - LazyExtensionRangeEmitter(MessageGenerator* mg, io::Printer* p) - : mg_(mg), p_(p) {} + LazyExtensionRangeEmitter(MessageGenerator* mg, io::Printer* printer) + : mg_(mg), format_(printer) {} void AddToRange(const Descriptor::ExtensionRange* range) { if (!has_current_range_) { @@ -3920,14 +3889,15 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { void Flush() { if (has_current_range_) { - mg_->GenerateSerializeOneExtensionRange(p_, ¤t_combined_range_); + mg_->GenerateSerializeOneExtensionRange(format_.printer(), + ¤t_combined_range_); } has_current_range_ = false; } private: MessageGenerator* mg_; - io::Printer* p_; + Formatter format_; bool has_current_range_ = false; Descriptor::ExtensionRange current_combined_range_; }; @@ -3977,8 +3947,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { // Merge the fields and the extension ranges, both sorted by field number. { - LazySerializerEmitter e(this, p); - LazyExtensionRangeEmitter re(this, p); + LazySerializerEmitter e(this, printer); + LazyExtensionRangeEmitter re(this, printer); LargestWeakFieldHolder largest_weak_field; int i, j; for (i = 0, j = 0; @@ -4008,6 +3978,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { e.EmitIfNotNull(largest_weak_field.Release()); } + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); format("if (PROTOBUF_PREDICT_FALSE($have_unknown_fields$)) {\n"); format.Indent(); if (UseUnknownFieldSet(descriptor_->file(), options_)) { @@ -4026,8 +3999,8 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBody(io::Printer* p) { } void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( - io::Printer* p) { - Formatter format(p); + io::Printer* printer) { + Formatter format(printer, variables_); std::vector ordered_fields = SortFieldsByNumber(descriptor_); @@ -4069,7 +4042,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( format("case $1$: {\n", index++); format.Indent(); - GenerateSerializeOneField(p, f, -1); + GenerateSerializeOneField(printer, f, -1); format("break;\n"); format.Outdent(); @@ -4080,7 +4053,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( format("case $1$: {\n", index++); format.Indent(); - GenerateSerializeOneExtensionRange(p, r); + GenerateSerializeOneExtensionRange(printer, r); format("break;\n"); format.Outdent(); @@ -4097,6 +4070,9 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( format.Outdent(); format("}\n"); + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); format("if (PROTOBUF_PREDICT_FALSE($have_unknown_fields$)) {\n"); format.Indent(); if (UseUnknownFieldSet(descriptor_->file(), options_)) { @@ -4130,12 +4106,15 @@ std::vector MessageGenerator::RequiredFieldsBitMask() const { return masks; } -void MessageGenerator::GenerateByteSize(io::Printer* p) { +void MessageGenerator::GenerateByteSize(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); format( "size_t $classname$::ByteSizeLong() const {\n" "$annotate_bytesize$" @@ -4170,7 +4149,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { FieldName(field)); format.Indent(); PrintFieldComment(format, field); - field_generators_.get(field).GenerateByteSize(p); + field_generators_.get(field).GenerateByteSize(printer); format.Outdent(); format("}\n"); } @@ -4197,6 +4176,10 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { "\n"); } + std::map vars; + SetUnknownFieldsVariable(descriptor_, options_, &vars); + format.AddMap(vars); + // Handle required fields (if any). We expect all of them to be // present, so emit one conditional that checks for that. If they are all // present then the fast path executes; otherwise the slow path executes. @@ -4211,7 +4194,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { for (auto field : optimized_order_) { if (!field->is_required()) continue; PrintFieldComment(format, field); - field_generators_.get(field).GenerateByteSize(p); + field_generators_.get(field).GenerateByteSize(printer); format("\n"); } format.Outdent(); @@ -4226,7 +4209,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { PrintFieldComment(format, field); format("if (_internal_has_$1$()) {\n", FieldName(field)); format.Indent(); - field_generators_.get(field).GenerateByteSize(p); + field_generators_.get(field).GenerateByteSize(printer); format.Outdent(); format("}\n"); } @@ -4256,13 +4239,13 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { const std::vector& chunk = chunks[chunk_index]; const bool have_outer_if = chunk.size() > 1 && HasWordIndex(chunk[0]) != kNoHasbit; - cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "", p); + cold_skipper.OnStartChunk(chunk_index, cached_has_word_index, "", printer); if (have_outer_if) { // Emit an if() that will let us skip the whole chunk if none are set. uint32_t chunk_mask = GenChunkMask(chunk, has_bit_indices_); std::string chunk_mask_str = - absl::StrCat(absl::Hex(chunk_mask, absl::kZeroPad8)); + StrCat(strings::Hex(chunk_mask, strings::ZERO_PAD_8)); // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check @@ -4291,15 +4274,17 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { // No presence check is required. need_extra_newline = true; } else if (HasHasbit(field)) { - PrintPresenceCheck(field, has_bit_indices_, p, &cached_has_word_index); + PrintPresenceCheck(format, field, has_bit_indices_, printer, + &cached_has_word_index); have_enclosing_if = true; } else { // Without field presence: field is serialized only if it has a // non-default value. - have_enclosing_if = EmitFieldNonDefaultCondition(p, "this->", field); + have_enclosing_if = + EmitFieldNonDefaultCondition(printer, "this->", field); } - generator.GenerateByteSize(p); + generator.GenerateByteSize(printer); if (have_enclosing_if) { format.Outdent(); @@ -4317,7 +4302,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { format("}\n"); } - if (cold_skipper.OnEndChunk(chunk_index, p)) { + if (cold_skipper.OnEndChunk(chunk_index, printer)) { // Reset here as it may have been updated in just closed if statement. cached_has_word_index = -1; } @@ -4333,7 +4318,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format.Indent(); if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateByteSize(p); + field_generators_.get(field).GenerateByteSize(printer); } format("break;\n"); format.Outdent(); @@ -4343,7 +4328,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { "case $1$_NOT_SET: {\n" " break;\n" "}\n", - absl::AsciiStrToUpper(oneof->name())); + ToUpper(oneof->name())); format.Outdent(); format("}\n"); } @@ -4382,9 +4367,9 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { format("}\n"); } -void MessageGenerator::GenerateIsInitialized(io::Printer* p) { +void MessageGenerator::GenerateIsInitialized(io::Printer* printer) { if (HasSimpleBaseClass(descriptor_, options_)) return; - Formatter format(p); + Formatter format(printer, variables_); format("bool $classname$::IsInitialized() const {\n"); format.Indent(); @@ -4403,7 +4388,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) { // Now check that all non-oneof embedded messages are initialized. for (auto field : optimized_order_) { - field_generators_.get(field).GenerateIsInitialized(p); + field_generators_.get(field).GenerateIsInitialized(printer); } if (num_weak_fields_) { // For Weak fields. @@ -4432,7 +4417,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) { format("case k$1$: {\n", UnderscoresToCamelCase(field->name(), true)); format.Indent(); if (!IsFieldStripped(field, options_)) { - field_generators_.get(field).GenerateIsInitialized(p); + field_generators_.get(field).GenerateIsInitialized(printer); } format("break;\n"); format.Outdent(); @@ -4442,7 +4427,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) { "case $1$_NOT_SET: {\n" " break;\n" "}\n", - absl::AsciiStrToUpper(oneof->name())); + ToUpper(oneof->name())); format.Outdent(); format("}\n"); } @@ -4458,4 +4443,4 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message.h b/libs/protobuf/src/google/protobuf/compiler/cpp/message.h index 0196606..5bdfcb3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message.h @@ -36,39 +36,40 @@ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__ #include -#include -#include #include #include #include -#include -#include -#include "absl/container/flat_hash_map.h" -#include "google/protobuf/compiler/cpp/enum.h" -#include "google/protobuf/compiler/cpp/extension.h" -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/message_layout_helper.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/compiler/cpp/parse_function_generator.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace io { +class Printer; // printer.h +} +} // namespace protobuf +} // namespace google namespace google { namespace protobuf { namespace compiler { namespace cpp { + +class EnumGenerator; // enum.h +class ExtensionGenerator; // extension.h + class MessageGenerator { public: + // See generator.cc for the meaning of dllexport_decl. MessageGenerator(const Descriptor* descriptor, - const std::map& ignored, + const std::map& vars, int index_in_file_messages, const Options& options, MessageSCCAnalyzer* scc_analyzer); - - MessageGenerator(const MessageGenerator&) = delete; - MessageGenerator& operator=(const MessageGenerator&) = delete; - - ~MessageGenerator() = default; + ~MessageGenerator(); // Append the two types of nested generators to the corresponding vector. void AddGenerators( @@ -76,94 +77,95 @@ class MessageGenerator { std::vector>* extension_generators); // Generate definitions for this class and all its nested types. - void GenerateClassDefinition(io::Printer* p); + void GenerateClassDefinition(io::Printer* printer); // Generate definitions of inline methods (placed at the end of the header // file). - void GenerateInlineMethods(io::Printer* p); + void GenerateInlineMethods(io::Printer* printer); + + // Source file stuff. // Generate all non-inline methods for this class. - void GenerateClassMethods(io::Printer* p); + void GenerateClassMethods(io::Printer* printer); // Generate source file code that should go outside any namespace. - void GenerateSourceInProto2Namespace(io::Printer* p); - - - void GenerateInitDefaultSplitInstance(io::Printer* p); - - // Generate the constexpr constructor for constant initialization of the - // default instance. - void GenerateConstexprConstructor(io::Printer* p); - - void GenerateSchema(io::Printer* p, int offset, int has_offset); - - // Generate the field offsets array. Returns the a pair of the total number - // of entries generated and the index of the first has_bit entry. - std::pair GenerateOffsets(io::Printer* p); - - const Descriptor* descriptor() const { return descriptor_; } + void GenerateSourceInProto2Namespace(io::Printer* printer); private: // Generate declarations and definitions of accessors for fields. - void GenerateFieldAccessorDeclarations(io::Printer* p); - void GenerateFieldAccessorDefinitions(io::Printer* p); + void GenerateFieldAccessorDeclarations(io::Printer* printer); + void GenerateFieldAccessorDefinitions(io::Printer* printer); + + // Generate the field offsets array. Returns the a pair of the total number + // of entries generated and the index of the first has_bit entry. + std::pair GenerateOffsets(io::Printer* printer); + void GenerateSchema(io::Printer* printer, int offset, int has_offset); // Generate constructors and destructor. - void GenerateStructors(io::Printer* p); + void GenerateStructors(io::Printer* printer); // The compiler typically generates multiple copies of each constructor and // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx // Placing common code in a separate method reduces the generated code size. // // Generate the shared constructor code. - void GenerateSharedConstructorCode(io::Printer* p); + void GenerateSharedConstructorCode(io::Printer* printer); // Generate the shared destructor code. - void GenerateSharedDestructorCode(io::Printer* p); + void GenerateSharedDestructorCode(io::Printer* printer); // Generate the arena-specific destructor code. - void GenerateArenaDestructorCode(io::Printer* p); + void GenerateArenaDestructorCode(io::Printer* printer); + + // Generate the constexpr constructor for constant initialization of the + // default instance. + void GenerateConstexprConstructor(io::Printer* printer); + + void GenerateCreateSplitMessage(io::Printer* printer); + void GenerateInitDefaultSplitInstance(io::Printer* printer); // Generate standard Message methods. - void GenerateClear(io::Printer* p); - void GenerateOneofClear(io::Printer* p); - void GenerateVerify(io::Printer* p); - void GenerateSerializeWithCachedSizes(io::Printer* p); - void GenerateSerializeWithCachedSizesToArray(io::Printer* p); - void GenerateSerializeWithCachedSizesBody(io::Printer* p); - void GenerateSerializeWithCachedSizesBodyShuffled(io::Printer* p); - void GenerateByteSize(io::Printer* p); - void GenerateMergeFrom(io::Printer* p); - void GenerateClassSpecificMergeImpl(io::Printer* p); - void GenerateCopyFrom(io::Printer* p); - void GenerateSwap(io::Printer* p); - void GenerateIsInitialized(io::Printer* p); + void GenerateClear(io::Printer* printer); + void GenerateOneofClear(io::Printer* printer); + void GenerateVerify(io::Printer* printer); + void GenerateSerializeWithCachedSizes(io::Printer* printer); + void GenerateSerializeWithCachedSizesToArray(io::Printer* printer); + void GenerateSerializeWithCachedSizesBody(io::Printer* printer); + void GenerateSerializeWithCachedSizesBodyShuffled(io::Printer* printer); + void GenerateByteSize(io::Printer* printer); + void GenerateMergeFrom(io::Printer* printer); + void GenerateClassSpecificMergeImpl(io::Printer* printer); + void GenerateCopyFrom(io::Printer* printer); + void GenerateSwap(io::Printer* printer); + void GenerateIsInitialized(io::Printer* printer); // Helpers for GenerateSerializeWithCachedSizes(). // // cached_has_bit_index maintains that: // cached_has_bits = _has_bits_[cached_has_bit_index] // for cached_has_bit_index >= 0 - void GenerateSerializeOneField(io::Printer* p, const FieldDescriptor* field, + void GenerateSerializeOneField(io::Printer* printer, + const FieldDescriptor* field, int cached_has_bits_index); // Generate a switch statement to serialize 2+ fields from the same oneof. // Or, if fields.size() == 1, just call GenerateSerializeOneField(). void GenerateSerializeOneofFields( - io::Printer* p, const std::vector& fields); + io::Printer* printer, const std::vector& fields); void GenerateSerializeOneExtensionRange( - io::Printer* p, const Descriptor::ExtensionRange* range); + io::Printer* printer, const Descriptor::ExtensionRange* range); // Generates has_foo() functions and variables for singular field has-bits. void GenerateSingularFieldHasBits(const FieldDescriptor* field, - io::Printer* p); + Formatter format); // Generates has_foo() functions and variables for oneof field has-bits. - void GenerateOneofHasBits(io::Printer* p); + void GenerateOneofHasBits(io::Printer* printer); // Generates has_foo_bar() functions for oneof members. - void GenerateOneofMemberHasBits(const FieldDescriptor* field, io::Printer* p); + void GenerateOneofMemberHasBits(const FieldDescriptor* field, + const Formatter& format); // Generates the clear_foo() method for a field. void GenerateFieldClear(const FieldDescriptor* field, bool is_inline, - io::Printer* p); + Formatter format); // Generates the body of the message's copy constructor. - void GenerateCopyConstructorBody(io::Printer* p) const; + void GenerateCopyConstructorBody(io::Printer* printer) const; // Returns the level that this message needs ArenaDtor. If the message has // a field that is not arena-exclusive, it needs an ArenaDtor @@ -179,13 +181,15 @@ class MessageGenerator { size_t HasBitsSize() const; size_t InlinedStringDonatedSize() const; - int HasBitIndex(const FieldDescriptor* field) const; - int HasByteIndex(const FieldDescriptor* field) const; - int HasWordIndex(const FieldDescriptor* field) const; + int HasBitIndex(const FieldDescriptor* a) const; + int HasByteIndex(const FieldDescriptor* a) const; + int HasWordIndex(const FieldDescriptor* a) const; + bool SameHasByte(const FieldDescriptor* a, const FieldDescriptor* b) const; std::vector RequiredFieldsBitMask() const; const Descriptor* descriptor_; int index_in_file_messages_; + std::string classname_; Options options_; FieldGeneratorMap field_generators_; // optimized_order_ is the order we layout the message's fields in the @@ -195,19 +199,19 @@ class MessageGenerator { // optimized_order_ excludes oneof fields and weak fields. std::vector optimized_order_; std::vector has_bit_indices_; - int max_has_bit_index_ = 0; + int max_has_bit_index_; // A map from field index to inlined_string index. For non-inlined-string // fields, the element is -1. If there is no inlined string in the message, // this is empty. std::vector inlined_string_indices_; // The count of inlined_string fields in the message. - int max_inlined_string_index_ = 0; + int max_inlined_string_index_; std::vector enum_generators_; std::vector extension_generators_; - int num_required_fields_ = 0; - int num_weak_fields_ = 0; + int num_required_fields_; + int num_weak_fields_; std::unique_ptr message_layout_helper_; std::unique_ptr parse_function_generator_; @@ -216,6 +220,8 @@ class MessageGenerator { std::map variables_; + friend class FileGenerator; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.cc index d2df9a2..7e87a07 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.cc @@ -32,13 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/message_field.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" +#include namespace google { namespace protobuf { @@ -73,7 +73,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, QualifiedDefaultInstancePtr(descriptor->message_type(), options), implicit_weak); (*variables)["type_reference_function"] = - implicit_weak ? (" ::" + ProtobufNamespace(options) + + implicit_weak ? (" ::" + (*variables)["proto_ns"] + "::internal::StrongReference(reinterpret_cast(\n" + (*variables)["type_default_instance"] + "));\n") @@ -191,19 +191,12 @@ void MessageFieldGenerator::GenerateInlineAccessorDefinitions( } else { format(" $field$ = $name$;\n"); } - auto nonempty = [this](const char* fn) { - auto var_it = variables_.find(fn); - return var_it != variables_.end() && !var_it->second.empty(); - }; - if (nonempty("set_hasbit") || nonempty("clear_hasbit")) { - format( - " if ($name$) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n"); - } format( + " if ($name$) {\n" + " $set_hasbit$\n" + " } else {\n" + " $clear_hasbit$\n" + " }\n" "$annotate_set$" " // @@protoc_insertion_point(field_unsafe_arena_set_allocated" ":$full_name$)\n" @@ -350,7 +343,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions( format( "::$proto_ns$::MessageLite*\n" "$classname$::_Internal::mutable_$name$($classname$* msg) {\n"); - if (internal::cpp::HasHasbit(descriptor_)) { + if (HasHasbit(descriptor_)) { format(" msg->$set_hasbit$\n"); } if (descriptor_->real_containing_oneof() == nullptr) { @@ -383,7 +376,7 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const { GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); - if (!internal::cpp::HasHasbit(descriptor_)) { + if (!HasHasbit(descriptor_)) { // If we don't have has-bits, message presence is indicated only by ptr != // nullptr. Thus on clear, we need to delete the object. format( @@ -401,7 +394,7 @@ void MessageFieldGenerator::GenerateMessageClearingCode( GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); - if (!internal::cpp::HasHasbit(descriptor_)) { + if (!HasHasbit(descriptor_)) { // If we don't have has-bits, message presence is indicated only by ptr != // nullptr. Thus on clear, we need to delete the object. format( diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.h index 39efe28..70c42c0 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message_field.h @@ -38,8 +38,8 @@ #include #include -#include "google/protobuf/compiler/cpp/field.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include namespace google { namespace protobuf { @@ -51,8 +51,6 @@ class MessageFieldGenerator : public FieldGenerator { MessageFieldGenerator(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - MessageFieldGenerator(const MessageFieldGenerator&) = delete; - MessageFieldGenerator& operator=(const MessageFieldGenerator&) = delete; ~MessageFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -83,6 +81,9 @@ class MessageFieldGenerator : public FieldGenerator { protected: const bool implicit_weak_field_; const bool has_required_fields_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator); }; class MessageOneofFieldGenerator : public MessageFieldGenerator { @@ -90,9 +91,6 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { MessageOneofFieldGenerator(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - MessageOneofFieldGenerator(const MessageOneofFieldGenerator&) = delete; - MessageOneofFieldGenerator& operator=(const MessageOneofFieldGenerator&) = - delete; ~MessageOneofFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -108,6 +106,9 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator { void GenerateDestructorCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; void GenerateIsInitialized(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator); }; class RepeatedMessageFieldGenerator : public FieldGenerator { @@ -115,9 +116,6 @@ class RepeatedMessageFieldGenerator : public FieldGenerator { RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor, const Options& options, MessageSCCAnalyzer* scc_analyzer); - RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete; - RepeatedMessageFieldGenerator& operator=( - const RepeatedMessageFieldGenerator&) = delete; ~RepeatedMessageFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -138,6 +136,8 @@ class RepeatedMessageFieldGenerator : public FieldGenerator { private: const bool implicit_weak_field_; const bool has_required_fields_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message_layout_helper.h b/libs/protobuf/src/google/protobuf/compiler/cpp/message_layout_helper.h index 7727e67..a8813a1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message_layout_helper.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message_layout_helper.h @@ -35,8 +35,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_LAYOUT_HELPER_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_LAYOUT_HELPER_H__ -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/cpp/options.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/message_size_unittest.cc index ed4a90e..761988b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -28,10 +28,10 @@ // (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/unittest.pb.h" +#include #include #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { @@ -139,9 +139,9 @@ TEST(GeneratedMessageTest, OneStringSize) { TEST(GeneratedMessageTest, MoreStringSize) { struct MockGenerated : public MockMessageBase { // 16 bytes + int has_bits[1]; // 4 bytes int cached_size; // 4 bytes MockRepeatedPtrField data; // 24 bytes - // + 4 bytes padding }; GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48); EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated)); diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc index 2a51655..1ffd357 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc @@ -30,15 +30,15 @@ #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/cpp/generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/compiler/annotation_test_util.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/move_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/move_unittest.cc index e723346..eb7cd1c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/move_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/move_unittest.cc @@ -28,9 +28,9 @@ // (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 +#include +#include #include #if LANG_CXX11 diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/names.h b/libs/protobuf/src/google/protobuf/compiler/cpp/names.h index d83cabb..7404ac5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/names.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/names.h @@ -34,7 +34,7 @@ #include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -92,6 +92,6 @@ PROTOC_EXPORT std::string StripProto(const std::string& filename); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CPP_NAMES_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/options.h b/libs/protobuf/src/google/protobuf/compiler/cpp/options.h index 7aab669..5d935e9 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/options.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/options.h @@ -40,7 +40,6 @@ namespace google { namespace protobuf { namespace compiler { class AccessInfoMap; -class SplitMap; namespace cpp { @@ -59,7 +58,6 @@ struct FieldListenerOptions { // Generator options (see generator.cc for a description of each): struct Options { const AccessInfoMap* access_info_map = nullptr; - const SplitMap* split_map = nullptr; std::string dllexport_decl; std::string runtime_include_base; std::string annotation_pragma_name; @@ -82,10 +80,10 @@ struct Options { bool annotate_accessor = false; bool unused_field_stripping = false; bool unverified_lazy_message_sets = false; + bool unverified_lazy = false; bool profile_driven_inline_string = true; bool message_owned_arena_trial = false; bool force_split = false; - bool profile_driven_split = true; #ifdef PROTOBUF_STABLE_EXPERIMENTS bool force_eagerly_verified_lazy = true; bool force_inline_string = true; diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.cc index 74804b2..2091052 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.cc @@ -28,9 +28,9 @@ // (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/compiler/cpp/padding_optimizer.h" +#include -#include "google/protobuf/compiler/cpp/helpers.h" +#include namespace google { namespace protobuf { @@ -85,11 +85,41 @@ class FieldGroup { } // namespace -static void OptimizeLayoutHelper(std::vector* fields, - const Options& options, - MessageSCCAnalyzer* scc_analyzer) { - if (fields->empty()) return; - +// Reorder 'fields' so that if the fields are output into a c++ class in the new +// order, fields of similar family (see below) are together and within each +// family, alignment padding is minimized. +// +// We try to do this while keeping each field as close as possible to its field +// number order so that we don't reduce cache locality much for function that +// access each field in order. Originally, OptimizePadding used declaration +// order for its decisions, but generated code minus the serializer/parsers uses +// the output of OptimizePadding as well (stored in +// MessageGenerator::optimized_order_). Since the serializers use field number +// order, we use that as a tie-breaker. +// +// We classify each field into a particular "family" of fields, that we perform +// the same operation on in our generated functions. +// +// REPEATED is placed first, as the C++ compiler automatically initializes +// these fields in layout order. +// +// STRING is grouped next, as our Clear/SharedCtor/SharedDtor walks it and +// calls ArenaStringPtr::Destroy on each. +// +// LAZY_MESSAGE is grouped next, as it interferes with the ability to memset +// non-repeated fields otherwise. +// +// MESSAGE is grouped next, as our Clear/SharedDtor code walks it and calls +// delete on each. We initialize these fields with a NULL pointer (see +// MessageFieldGenerator::GenerateConstructorCode), which allows them to be +// memset. +// +// ZERO_INITIALIZABLE is memset in Clear/SharedCtor +// +// OTHER these fields are initialized one-by-one. +void PaddingOptimizer::OptimizeLayout( + std::vector* fields, const Options& options, + MessageSCCAnalyzer* scc_analyzer) { // The sorted numeric order of Family determines the declaration order in the // memory layout. enum Family { @@ -192,61 +222,6 @@ static void OptimizeLayoutHelper(std::vector* fields, } } -// Reorder 'fields' so that if the fields are output into a c++ class in the new -// order, fields of similar family (see below) are together and within each -// family, alignment padding is minimized. -// -// We try to do this while keeping each field as close as possible to its field -// number order so that we don't reduce cache locality much for function that -// access each field in order. Originally, OptimizePadding used declaration -// order for its decisions, but generated code minus the serializer/parsers uses -// the output of OptimizePadding as well (stored in -// MessageGenerator::optimized_order_). Since the serializers use field number -// order, we use that as a tie-breaker. -// -// We classify each field into a particular "family" of fields, that we perform -// the same operation on in our generated functions. -// -// REPEATED is placed first, as the C++ compiler automatically initializes -// these fields in layout order. -// -// STRING is grouped next, as our Clear/SharedCtor/SharedDtor walks it and -// calls ArenaStringPtr::Destroy on each. -// -// LAZY_MESSAGE is grouped next, as it interferes with the ability to memset -// non-repeated fields otherwise. -// -// MESSAGE is grouped next, as our Clear/SharedDtor code walks it and calls -// delete on each. We initialize these fields with a NULL pointer (see -// MessageFieldGenerator::GenerateConstructorCode), which allows them to be -// memset. -// -// ZERO_INITIALIZABLE is memset in Clear/SharedCtor -// -// OTHER these fields are initialized one-by-one. -// -// If there are split fields in `fields`, they will be placed at the end. The -// order within split fields follows the same rule, aka classify and order by -// "family". -void PaddingOptimizer::OptimizeLayout( - std::vector* fields, const Options& options, - MessageSCCAnalyzer* scc_analyzer) { - std::vector normal; - std::vector split; - for (const auto* field : *fields) { - if (ShouldSplit(field, options)) { - split.push_back(field); - } else { - normal.push_back(field); - } - } - OptimizeLayoutHelper(&normal, options, scc_analyzer); - OptimizeLayoutHelper(&split, options, scc_analyzer); - fields->clear(); - fields->insert(fields->end(), normal.begin(), normal.end()); - fields->insert(fields->end(), split.begin(), split.end()); -} - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.h b/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.h index 4f55e64..9c76f38 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/padding_optimizer.h @@ -35,7 +35,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__ #define GOOGLE_PROTOBUF_COMPILER_CPP_PADDING_OPTIMIZER_H__ -#include "google/protobuf/compiler/cpp/message_layout_helper.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.cc index 64edf64..0f1d767 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -28,18 +28,15 @@ // (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/compiler/cpp/parse_function_generator.h" +#include #include #include #include #include -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/generated_message_tctable_gen.h" -#include "google/protobuf/generated_message_tctable_impl.h" +#include +#include namespace google { namespace protobuf { @@ -47,21 +44,9 @@ namespace compiler { namespace cpp { namespace { -using internal::TailCallTableInfo; -using internal::cpp::Utf8CheckMode; using google::protobuf::internal::WireFormat; using google::protobuf::internal::WireFormatLite; -bool UseDirectTcParserTable(const FieldDescriptor* field, - const Options& options) { - if (field->cpp_type() != field->CPPTYPE_MESSAGE) return false; - auto* m = field->message_type(); - return !m->options().message_set_wire_format() && - m->file()->options().optimize_for() != FileOptions::CODE_SIZE && - !HasSimpleBaseClass(m, options) && !HasTracker(m, options) - ; -} - std::vector GetOrderedFields( const Descriptor* descriptor, const Options& options) { std::vector ordered_fields; @@ -81,26 +66,364 @@ bool HasInternalAccessors(const FieldOptions::CType ctype) { return ctype == FieldOptions::STRING || ctype == FieldOptions::CORD; } -} // namespace +int TagSize(uint32_t field_number) { + if (field_number < 16) return 1; + GOOGLE_CHECK_LT(field_number, (1 << 14)) + << "coded tag for " << field_number << " too big for uint16_t"; + return 2; +} -class ParseFunctionGenerator::GeneratedOptionProvider final - : public internal::TailCallTableInfo::OptionProvider { - public: - explicit GeneratedOptionProvider(ParseFunctionGenerator* gen) : gen_(gen) {} - TailCallTableInfo::PerFieldOptions GetForField( - const FieldDescriptor* field) const final { - return {IsLazy(field, gen_->options_, gen_->scc_analyzer_), - IsStringInlined(field, gen_->options_), - IsImplicitWeakField(field, gen_->options_, gen_->scc_analyzer_), - UseDirectTcParserTable(field, gen_->options_), - GetOptimizeFor(field->file(), gen_->options_) == - FileOptions::LITE_RUNTIME, - ShouldSplit(field, gen_->options_)}; +std::string FieldParseFunctionName( + const TailCallTableInfo::FieldEntryInfo& entry, const Options& options); + +bool IsFieldEligibleForFastParsing( + const TailCallTableInfo::FieldEntryInfo& entry, const Options& options, + MessageSCCAnalyzer* scc_analyzer) { + const auto* field = entry.field; + // Map, oneof, weak, and lazy fields are not handled on the fast path. + if (field->is_map() || field->real_containing_oneof() || + field->options().weak() || + IsImplicitWeakField(field, options, scc_analyzer) || + IsLazy(field, options, scc_analyzer)) { + return false; } - private: - ParseFunctionGenerator* gen_; -}; + // We will check for a valid auxiliary index range later. However, we might + // want to change the value we check for inlined string fields. + int aux_idx = entry.aux_idx; + + switch (field->type()) { + case FieldDescriptor::TYPE_ENUM: + // If enum values are not validated at parse time, then this field can be + // handled on the fast path like an int32. + if (HasPreservingUnknownEnumSemantics(field)) { + break; + } + if (field->is_repeated() && field->is_packed()) { + return false; + } + break; + + // Some bytes fields can be handled on fast path. + case FieldDescriptor::TYPE_STRING: + case FieldDescriptor::TYPE_BYTES: + if (field->options().ctype() != FieldOptions::STRING) { + return false; + } + if (IsStringInlined(field, options)) { + GOOGLE_CHECK(!field->is_repeated()); + // For inlined strings, the donation state index is stored in the + // `aux_idx` field of the fast parsing info. We need to check the range + // of that value instead of the auxiliary index. + aux_idx = entry.inlined_string_idx; + } + break; + + default: + break; + } + + if (HasHasbit(field)) { + // The tailcall parser can only update the first 32 hasbits. Fields with + // has-bits beyond the first 32 are handled by mini parsing/fallback. + GOOGLE_CHECK_GE(entry.hasbit_idx, 0) << field->DebugString(); + if (entry.hasbit_idx >= 32) return false; + } + + // If the field needs auxiliary data, then the aux index is needed. This + // must fit in a uint8_t. + if (aux_idx > std::numeric_limits::max()) { + return false; + } + + // The largest tag that can be read by the tailcall parser is two bytes + // when varint-coded. This allows 14 bits for the numeric tag value: + // byte 0 byte 1 + // 1nnnnttt 0nnnnnnn + // ^^^^^^^ ^^^^^^^ + if (field->number() >= 1 << 11) return false; + + return true; +} + +std::vector SplitFastFieldsForSize( + const std::vector& field_entries, + int table_size_log2, const Options& options, + MessageSCCAnalyzer* scc_analyzer) { + std::vector result(1 << table_size_log2); + const uint32_t idx_mask = result.size() - 1; + + for (const auto& entry : field_entries) { + if (!IsFieldEligibleForFastParsing(entry, options, scc_analyzer)) { + continue; + } + + const auto* field = entry.field; + uint32_t tag = WireFormat::MakeTag(field); + + // Construct the varint-coded tag. If it is more than 7 bits, we need to + // shift the high bits and add a continue bit. + if (uint32_t hibits = tag & 0xFFFFFF80) { + tag = tag + hibits + 128; // tag = lobits + 2*hibits + 128 + } + + // The field index is determined by the low bits of the field number, where + // the table size determines the width of the mask. The largest table + // supported is 32 entries. The parse loop uses these bits directly, so that + // the dispatch does not require arithmetic: + // byte 0 byte 1 + // tag: 1nnnnttt 0nnnnnnn + // ^^^^^ + // idx (table_size_log2=5) + // This means that any field number that does not fit in the lower 4 bits + // will always have the top bit of its table index asserted. + const uint32_t fast_idx = (tag >> 3) & idx_mask; + + TailCallTableInfo::FastFieldInfo& info = result[fast_idx]; + if (info.field != nullptr) { + // This field entry is already filled. + continue; + } + + // Fill in this field's entry: + GOOGLE_CHECK(info.func_name.empty()) << info.func_name; + info.func_name = FieldParseFunctionName(entry, options); + info.field = field; + info.coded_tag = tag; + // If this field does not have presence, then it can set an out-of-bounds + // bit (tailcall parsing uses a uint64_t for hasbits, but only stores 32). + info.hasbit_idx = HasHasbit(field) ? entry.hasbit_idx : 63; + if (IsStringInlined(field, options)) { + GOOGLE_CHECK(!field->is_repeated()); + info.aux_idx = static_cast(entry.inlined_string_idx); + } else { + info.aux_idx = static_cast(entry.aux_idx); + } + } + return result; +} + +// Filter out fields that will be handled by mini parsing. +std::vector FilterMiniParsedFields( + const std::vector& fields, const Options& options, + MessageSCCAnalyzer* scc_analyzer) { + std::vector generated_fallback_fields; + + for (const auto* field : fields) { + bool handled = false; + switch (field->type()) { + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_SFIXED32: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED64: + case FieldDescriptor::TYPE_BOOL: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_INT64: + // These are handled by MiniParse, so we don't need any generated + // fallback code. + handled = true; + break; + + case FieldDescriptor::TYPE_ENUM: + if (field->is_repeated() && !HasPreservingUnknownEnumSemantics(field)) { + // TODO(b/206890171): handle packed repeated closed enums + // Non-packed repeated can be handled using tables, but we still + // need to generate fallback code for all repeated enums in order to + // handle packed encoding. This is because of the lite/full split + // when handling invalid enum values in a packed field. + handled = false; + } else { + handled = true; + } + break; + + case FieldDescriptor::TYPE_BYTES: + case FieldDescriptor::TYPE_STRING: + if (IsStringInlined(field, options)) { + // TODO(b/198211897): support InilnedStringField. + handled = false; + } else { + handled = true; + } + break; + + case FieldDescriptor::TYPE_MESSAGE: + case FieldDescriptor::TYPE_GROUP: + // TODO(b/210762816): support remaining field types. + if (field->is_map() || IsWeak(field, options) || + IsImplicitWeakField(field, options, scc_analyzer) || + IsLazy(field, options, scc_analyzer)) { + handled = false; + } else { + handled = true; + } + break; + + default: + handled = false; + break; + } + if (!handled) generated_fallback_fields.push_back(field); + } + + return generated_fallback_fields; +} + +} // namespace + +TailCallTableInfo::TailCallTableInfo( + const Descriptor* descriptor, const Options& options, + const std::vector& ordered_fields, + const std::vector& has_bit_indices, + const std::vector& inlined_string_indices, + MessageSCCAnalyzer* scc_analyzer) { + int oneof_count = descriptor->real_oneof_decl_count(); + // If this message has any oneof fields, store the case offset in the first + // auxiliary entry. + if (oneof_count > 0) { + GOOGLE_LOG_IF(DFATAL, ordered_fields.empty()) + << "Invalid message: " << descriptor->full_name() << " has " + << oneof_count << " oneof declarations, but no fields"; + aux_entries.push_back(StrCat("_fl::Offset{offsetof(", + ClassName(descriptor), + ", _impl_._oneof_case_)}")); + } + + // If this message has any inlined string fields, store the donation state + // offset in the second auxiliary entry. + if (!inlined_string_indices.empty()) { + aux_entries.resize(2); // pad if necessary + aux_entries[1] = + StrCat("_fl::Offset{offsetof(", ClassName(descriptor), + ", _impl_._inlined_string_donated_)}"); + } + + // Fill in mini table entries. + for (const FieldDescriptor* field : ordered_fields) { + field_entries.push_back( + {field, (HasHasbit(field) ? has_bit_indices[field->index()] : -1)}); + auto& entry = field_entries.back(); + + if (field->type() == FieldDescriptor::TYPE_MESSAGE || + field->type() == FieldDescriptor::TYPE_GROUP) { + // Message-typed fields have a FieldAux with the default instance pointer. + if (field->is_map()) { + // TODO(b/205904770): generate aux entries for maps + } else if (IsWeak(field, options)) { + // Don't generate anything for weak fields. They are handled by the + // generated fallback. + } else if (IsImplicitWeakField(field, options, scc_analyzer)) { + // Implicit weak fields don't need to store a default instance pointer. + } else if (IsLazy(field, options, scc_analyzer)) { + // Lazy fields are handled by the generated fallback function. + } else { + field_entries.back().aux_idx = aux_entries.size(); + const Descriptor* field_type = field->message_type(); + aux_entries.push_back(StrCat( + "reinterpret_cast(&", QualifiedDefaultInstanceName(field_type, options), ")")); + } + } else if (field->type() == FieldDescriptor::TYPE_ENUM && + !HasPreservingUnknownEnumSemantics(field)) { + // Enum fields which preserve unknown values (proto3 behavior) are + // effectively int32 fields with respect to parsing -- i.e., the value + // does not need to be validated at parse time. + // + // Enum fields which do not preserve unknown values (proto2 behavior) use + // a FieldAux to store validation information. If the enum values are + // sequential (and within a range we can represent), then the FieldAux + // entry represents the range using the minimum value (which must fit in + // an int16_t) and count (a uint16_t). Otherwise, the entry holds a + // pointer to the generated Name_IsValid function. + + entry.aux_idx = aux_entries.size(); + const EnumDescriptor* enum_type = field->enum_type(); + GOOGLE_CHECK_GT(enum_type->value_count(), 0) << enum_type->DebugString(); + + // Check if the enum values are a single, contiguous range. + std::vector enum_values; + for (int i = 0, N = enum_type->value_count(); i < N; ++i) { + enum_values.push_back(enum_type->value(i)->number()); + } + auto values_begin = enum_values.begin(); + auto values_end = enum_values.end(); + std::sort(values_begin, values_end); + enum_values.erase(std::unique(values_begin, values_end), values_end); + + if (enum_values.back() - enum_values[0] == enum_values.size() - 1 && + enum_values[0] >= std::numeric_limits::min() && + enum_values[0] <= std::numeric_limits::max() && + enum_values.size() <= std::numeric_limits::max()) { + entry.is_enum_range = true; + aux_entries.push_back( + StrCat(enum_values[0], ", ", enum_values.size())); + } else { + entry.is_enum_range = false; + aux_entries.push_back( + StrCat(QualifiedClassName(enum_type, options), "_IsValid")); + } + } else if ((field->type() == FieldDescriptor::TYPE_STRING || + field->type() == FieldDescriptor::TYPE_BYTES) && + IsStringInlined(field, options)) { + GOOGLE_CHECK(!field->is_repeated()); + // Inlined strings have an extra marker to represent their donation state. + int idx = inlined_string_indices[field->index()]; + // For mini parsing, the donation state index is stored as an `offset` + // auxiliary entry. + entry.aux_idx = aux_entries.size(); + aux_entries.push_back(StrCat("_fl::Offset{", idx, "}")); + // For fast table parsing, the donation state index is stored instead of + // the aux_idx (this will limit the range to 8 bits). + entry.inlined_string_idx = idx; + } + } + + // Choose the smallest fast table that covers the maximum number of fields. + table_size_log2 = 0; // fallback value + int num_fast_fields = -1; + for (int try_size_log2 : {0, 1, 2, 3, 4, 5}) { + size_t try_size = 1 << try_size_log2; + auto split_fields = SplitFastFieldsForSize(field_entries, try_size_log2, + options, scc_analyzer); + GOOGLE_CHECK_EQ(split_fields.size(), try_size); + int try_num_fast_fields = 0; + for (const auto& info : split_fields) { + if (info.field != nullptr) ++try_num_fast_fields; + } + // Use this size if (and only if) it covers more fields. + if (try_num_fast_fields > num_fast_fields) { + fast_path_fields = std::move(split_fields); + table_size_log2 = try_size_log2; + num_fast_fields = try_num_fast_fields; + } + // The largest table we allow has the same number of entries as the message + // has fields, rounded up to the next power of 2 (e.g., a message with 5 + // fields can have a fast table of size 8). A larger table *might* cover + // more fields in certain cases, but a larger table in that case would have + // mostly empty entries; so, we cap the size to avoid pathologically sparse + // tables. + if (try_size > ordered_fields.size()) { + break; + } + } + + // Filter out fields that are handled by MiniParse. We don't need to generate + // a fallback for these, which saves code size. + fallback_fields = FilterMiniParsedFields(ordered_fields, options, + scc_analyzer); + + // If there are no fallback fields, and at most one extension range, the + // parser can use a generic fallback function. Otherwise, a message-specific + // fallback routine is needed. + use_generated_fallback = + !fallback_fields.empty() || descriptor->extension_range_count() > 1; +} ParseFunctionGenerator::ParseFunctionGenerator( const Descriptor* descriptor, int max_has_bit_index, @@ -117,9 +440,10 @@ ParseFunctionGenerator::ParseFunctionGenerator( num_hasbits_(max_has_bit_index) { if (should_generate_tctable()) { tc_table_info_.reset(new TailCallTableInfo( - descriptor_, ordered_fields_, GeneratedOptionProvider(this), - has_bit_indices, inlined_string_indices)); + descriptor_, options_, ordered_fields_, has_bit_indices, + inlined_string_indices, scc_analyzer)); } + SetCommonVars(options_, &variables_); SetCommonMessageDataVariables(descriptor_, &variables_); SetUnknownFieldsVariable(descriptor_, options_, &variables_); variables_["classname"] = ClassName(descriptor, false); @@ -194,9 +518,6 @@ bool ParseFunctionGenerator::should_generate_tctable() const { if (options_.tctable_mode == Options::kTCTableNever) { return false; } - if (HasSimpleBaseClass(descriptor_, options_)) { - return false; - } return true; } @@ -226,7 +547,7 @@ void ParseFunctionGenerator::GenerateTailcallFallbackFunction( if (num_hasbits_ > 0) { // Sync hasbits - format("typed_msg->_impl_._has_bits_[0] |= hasbits;\n"); + format("typed_msg->_impl_._has_bits_[0] = hasbits;\n"); } format("uint32_t tag = data.tag();\n"); @@ -271,12 +592,6 @@ struct NumToEntryTable { static NumToEntryTable MakeNumToEntryTable( const std::vector& field_descriptors); -static int FieldNameDataSize(const std::vector& data) { - // We add a +1 here to allow for a NUL termination character. It makes the - // codegen nicer. - return data.empty() ? 0 : data.size() + 1; -} - void ParseFunctionGenerator::GenerateDataDecls(io::Printer* printer) { if (!should_generate_tctable()) { return; @@ -289,12 +604,10 @@ void ParseFunctionGenerator::GenerateDataDecls(io::Printer* printer) { } auto field_num_to_entry_table = MakeNumToEntryTable(ordered_fields_); format( - "friend class ::$proto_ns$::internal::TcParser;\n" "static const ::$proto_ns$::internal::" "TcParseTable<$1$, $2$, $3$, $4$, $5$> _table_;\n", tc_table_info_->table_size_log2, ordered_fields_.size(), - tc_table_info_->aux_entries.size(), - FieldNameDataSize(tc_table_info_->field_name_data), + tc_table_info_->aux_entries.size(), CalculateFieldNamesSize(), field_num_to_entry_table.size16()); if (should_generate_guarded_tctable()) { format.Outdent(); @@ -448,13 +761,12 @@ void ParseFunctionGenerator::GenerateTailCallTable(Formatter& format) { // unknown fields and potentially an extension range. auto field_num_to_entry_table = MakeNumToEntryTable(ordered_fields_); format( - "PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1\n" + "PROTOBUF_ATTRIBUTE_INIT_PRIORITY1\n" "const ::_pbi::TcParseTable<$1$, $2$, $3$, $4$, $5$> " "$classname$::_table_ = " "{\n", tc_table_info_->table_size_log2, ordered_fields_.size(), - tc_table_info_->aux_entries.size(), - FieldNameDataSize(tc_table_info_->field_name_data), + tc_table_info_->aux_entries.size(), CalculateFieldNamesSize(), field_num_to_entry_table.size16()); { auto table_scope = format.ScopedIndent(); @@ -562,62 +874,19 @@ void ParseFunctionGenerator::GenerateTailCallTable(Formatter& format) { { // aux_entries[] auto aux_scope = format.ScopedIndent(); - for (const auto& aux_entry : tc_table_info_->aux_entries) { - switch (aux_entry.type) { - case TailCallTableInfo::kNothing: - format("{},\n"); - break; - case TailCallTableInfo::kInlinedStringDonatedOffset: - format( - "{_fl::Offset{offsetof($classname$, " - "_impl_._inlined_string_donated_)}},\n"); - break; - case TailCallTableInfo::kSplitOffset: - format( - "{_fl::Offset{offsetof($classname$, _impl_._split_)}},\n"); - break; - case TailCallTableInfo::kSplitSizeof: - format("{_fl::Offset{sizeof($classname$::Impl_::Split)}},\n"); - break; - case TailCallTableInfo::kSubMessage: - format("{::_pbi::FieldAuxDefaultMessage{}, &$1$},\n", - QualifiedDefaultInstanceName( - aux_entry.field->message_type(), options_)); - break; - case TailCallTableInfo::kSubTable: - format("{::_pbi::TcParser::GetTable<$1$>()},\n", - QualifiedClassName(aux_entry.field->message_type(), - options_)); - break; - case TailCallTableInfo::kSubMessageWeak: - format("{::_pbi::FieldAuxDefaultMessage{}, &$1$},\n", - QualifiedDefaultInstancePtr( - aux_entry.field->message_type(), options_)); - break; - case TailCallTableInfo::kEnumRange: - format("{$1$, $2$},\n", aux_entry.enum_range.start, - aux_entry.enum_range.size); - break; - case TailCallTableInfo::kEnumValidator: - format( - "{$1$_IsValid},\n", - QualifiedClassName(aux_entry.field->enum_type(), options_)); - break; - case TailCallTableInfo::kNumericOffset: - format("{_fl::Offset{$1$}},\n", aux_entry.offset); - break; - } + for (const std::string& aux_entry : tc_table_info_->aux_entries) { + format("{$1$},\n", aux_entry); } } format("}}, {{\n"); } } // ordered_fields_.empty() - { - // field_names[] - auto field_name_scope = format.ScopedIndent(); - GenerateFieldNames(format); - } - format("}},\n"); + { + // field_names[] + auto field_name_scope = format.ScopedIndent(); + GenerateFieldNames(format); + } + format("}},\n"); } format("};\n\n"); // _table_ } @@ -629,171 +898,144 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) { } if (info.func_name.empty()) { format("{::_pbi::TcParser::MiniParse, {}},\n"); - } else if (info.field == nullptr) { - // Fast slot that is not associated with a field. Eg end group tags. - format("{$1$, {$2$, $3$}},\n", info.func_name, info.coded_tag, - info.nonfield_info); } else { - GOOGLE_CHECK(!ShouldSplit(info.field, options_)); - - std::string func_name = info.func_name; - if (GetOptimizeFor(info.field->file(), options_) == FileOptions::SPEED) { - // For 1-byte tags we have a more optimized version of the varint parser - // that can hardcode the offset and has bit. - if (absl::EndsWith(func_name, "V8S1") || - absl::EndsWith(func_name, "V32S1") || - absl::EndsWith(func_name, "V64S1")) { - std::string field_type = absl::EndsWith(func_name, "V8S1") ? "bool" - : absl::EndsWith(func_name, "V32S1") - ? "uint32_t" - : "uint64_t"; - func_name = absl::StrCat( - "::_pbi::TcParser::SingularVarintNoZag1<", field_type, - ", offsetof(", // - ClassName(info.field->containing_type()), // - ", ", // - FieldMemberName(info.field, /*split=*/false), // - "), ", // - info.hasbit_idx, // - ">()"); - } - } - + bool cold = ShouldSplit(info.field, options_); format( "{$1$,\n" - " {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$, $5$)}},\n", - func_name, info.coded_tag, info.hasbit_idx, info.aux_idx, - FieldMemberName(info.field, /*split=*/false)); + " {$2$, $3$, $4$, PROTOBUF_FIELD_OFFSET($classname$$5$, $6$)}},\n", + info.func_name, info.coded_tag, info.hasbit_idx, info.aux_idx, + cold ? "::Impl_::Split" : "", + cold ? FieldName(info.field) + "_" + : FieldMemberName(info.field, /*cold=*/false)); } } } static void FormatFieldKind(Formatter& format, - const TailCallTableInfo::FieldEntryInfo& entry) { - // In here we convert the runtime value of entry.type_card back into a - // sequence of literal enum labels. We use the mnenonic labels for nicer - // codegen. - namespace fl = internal::field_layout; - const uint16_t type_card = entry.type_card; - const int rep_index = (type_card & fl::kRepMask) >> fl::kRepShift; - const int tv_index = (type_card & fl::kTvMask) >> fl::kTvShift; - - format("("); - static constexpr const char* kFieldCardNames[] = {"Singular", "Optional", - "Repeated", "Oneof"}; - static_assert((fl::kFcSingular >> fl::kFcShift) == 0, ""); - static_assert((fl::kFcOptional >> fl::kFcShift) == 1, ""); - static_assert((fl::kFcRepeated >> fl::kFcShift) == 2, ""); - static_assert((fl::kFcOneof >> fl::kFcShift) == 3, ""); - - format("::_fl::kFc$1$", - kFieldCardNames[(type_card & fl::kFcMask) >> fl::kFcShift]); - -#define PROTOBUF_INTERNAL_TYPE_CARD_CASE(x) \ - case fl::k##x: \ - format(" | ::_fl::k" #x); \ - break - - switch (type_card & fl::kFkMask) { - case fl::kFkString: { - switch (type_card & ~fl::kFcMask & ~fl::kRepMask & ~fl::kSplitMask) { - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bytes); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(RawString); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Utf8String); - default: - GOOGLE_LOG(FATAL) << "Unknown type_card: 0x" << type_card; - } - - static constexpr const char* kRepNames[] = {"AString", "IString", "Cord", - "SPiece", "SString"}; - static_assert((fl::kRepAString >> fl::kRepShift) == 0, ""); - static_assert((fl::kRepIString >> fl::kRepShift) == 1, ""); - static_assert((fl::kRepCord >> fl::kRepShift) == 2, ""); - static_assert((fl::kRepSPiece >> fl::kRepShift) == 3, ""); - static_assert((fl::kRepSString >> fl::kRepShift) == 4, ""); - - format(" | ::_fl::kRep$1$", kRepNames[rep_index]); - break; - } - - case fl::kFkMessage: { - format(" | ::_fl::kMessage"); - - static constexpr const char* kRepNames[] = {nullptr, "Group", "Lazy"}; - static_assert((fl::kRepGroup >> fl::kRepShift) == 1, ""); - static_assert((fl::kRepLazy >> fl::kRepShift) == 2, ""); - - if (auto* rep = kRepNames[rep_index]) { - format(" | ::_fl::kRep$1$", rep); - } - - static constexpr const char* kXFormNames[] = {nullptr, "Default", "Table", - "WeakPtr"}; - static_assert((fl::kTvDefault >> fl::kTvShift) == 1, ""); - static_assert((fl::kTvTable >> fl::kTvShift) == 2, ""); - static_assert((fl::kTvWeakPtr >> fl::kTvShift) == 3, ""); - - if (auto* xform = kXFormNames[tv_index]) { - format(" | ::_fl::kTv$1$", xform); - } - break; - } - - case fl::kFkMap: - format(" | ::_fl::kMap"); - break; - - case fl::kFkNone: - break; - - case fl::kFkVarint: - case fl::kFkPackedVarint: - case fl::kFkFixed: - case fl::kFkPackedFixed: { - switch (type_card & ~fl::kFcMask & ~fl::kSplitMask) { - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Bool); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Float); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Enum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(EnumRange); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(OpenEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Fixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(UInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Int64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(SInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(Double); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedBool); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt32); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFloat); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedEnumRange); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedOpenEnum); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedUInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSFixed64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt64); - PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedDouble); - default: - GOOGLE_LOG(FATAL) << "Unknown type_card: 0x" << type_card; - } - } + const TailCallTableInfo::FieldEntryInfo& entry, + const Options& options, + MessageSCCAnalyzer* scc_analyzer) { + const FieldDescriptor* field = entry.field; + // Spell the field kind in proto language declaration order, starting with + // cardinality: + format("(::_fl::kFc"); + if (HasHasbit(field)) { + format("Optional"); + } else if (field->is_repeated()) { + format("Repeated"); + } else if (field->real_containing_oneof()) { + format("Oneof"); + } else { + format("Singular"); } - if (type_card & fl::kSplitMask) { - format(" | ::_fl::kSplitTrue"); + // The rest of the type uses convenience aliases: + format(" | ::_fl::k"); + if (field->is_repeated() && field->is_packed()) { + format("Packed"); + } + switch (field->type()) { + case FieldDescriptor::TYPE_DOUBLE: + format("Double"); + break; + case FieldDescriptor::TYPE_FLOAT: + format("Float"); + break; + case FieldDescriptor::TYPE_FIXED32: + format("Fixed32"); + break; + case FieldDescriptor::TYPE_SFIXED32: + format("SFixed32"); + break; + case FieldDescriptor::TYPE_FIXED64: + format("Fixed64"); + break; + case FieldDescriptor::TYPE_SFIXED64: + format("SFixed64"); + break; + case FieldDescriptor::TYPE_BOOL: + format("Bool"); + break; + case FieldDescriptor::TYPE_ENUM: + if (HasPreservingUnknownEnumSemantics(field)) { + // No validation is required. + format("OpenEnum"); + } else if (entry.is_enum_range) { + // Validation is done by range check (start/length in FieldAux). + format("EnumRange"); + } else { + // Validation uses the generated _IsValid function. + format("Enum"); + } + break; + case FieldDescriptor::TYPE_UINT32: + format("UInt32"); + break; + case FieldDescriptor::TYPE_SINT32: + format("SInt32"); + break; + case FieldDescriptor::TYPE_INT32: + format("Int32"); + break; + case FieldDescriptor::TYPE_UINT64: + format("UInt64"); + break; + case FieldDescriptor::TYPE_SINT64: + format("SInt64"); + break; + case FieldDescriptor::TYPE_INT64: + format("Int64"); + break; + + case FieldDescriptor::TYPE_BYTES: + format("Bytes"); + break; + case FieldDescriptor::TYPE_STRING: { + auto mode = GetUtf8CheckMode(field, options); + switch (mode) { + case Utf8CheckMode::kStrict: + format("Utf8String"); + break; + case Utf8CheckMode::kVerify: + format("RawString"); + break; + case Utf8CheckMode::kNone: + // Treat LITE_RUNTIME strings as bytes. + format("Bytes"); + break; + default: + GOOGLE_LOG(FATAL) << "Invalid Utf8CheckMode (" << static_cast(mode) + << ") for " << field->DebugString(); + } + break; + } + + case FieldDescriptor::TYPE_GROUP: + format("Message | ::_fl::kRepGroup"); + break; + case FieldDescriptor::TYPE_MESSAGE: + if (field->is_map()) { + format("Map"); + } else { + format("Message"); + if (IsLazy(field, options, scc_analyzer)) { + format(" | ::_fl::kRepLazy"); + } else if (IsImplicitWeakField(field, options, scc_analyzer)) { + format(" | ::_fl::kRepIWeak"); + } + } + break; } -#undef PROTOBUF_INTERNAL_TYPE_CARD_CASE + // Fill in extra information about string and bytes field representations. + if (field->type() == FieldDescriptor::TYPE_BYTES || + field->type() == FieldDescriptor::TYPE_STRING) { + if (field->is_repeated()) { + format(" | ::_fl::kRepSString"); + } else { + format(" | ::_fl::kRepAString"); + } + } format(")"); } @@ -809,68 +1051,78 @@ void ParseFunctionGenerator::GenerateFieldEntries(Formatter& format) { format("/* weak */ 0, 0, 0, 0"); } else { const OneofDescriptor* oneof = field->real_containing_oneof(); - bool split = ShouldSplit(field, options_); - if (split) { - format("PROTOBUF_FIELD_OFFSET($classname$::Impl_::Split, $1$), ", - FieldName(field) + "_"); - } else { - format("PROTOBUF_FIELD_OFFSET($classname$, $1$), ", - FieldMemberName(field, /*cold=*/false)); - } - if (oneof) { - format("_Internal::kOneofCaseOffset + $1$, ", 4 * oneof->index()); - } else if (num_hasbits_ > 0 || IsMapEntryMessage(descriptor_)) { - if (entry.hasbit_idx >= 0) { - format("_Internal::kHasBitsOffset + $1$, ", entry.hasbit_idx); - } else { - format("$1$, ", entry.hasbit_idx); - } - } else { - format("0, "); - } - format("$1$,\n ", entry.aux_idx); - FormatFieldKind(format, entry); + bool cold = ShouldSplit(field, options_); + format("PROTOBUF_FIELD_OFFSET($classname$$1$, $2$), $3$, $4$,\n ", + cold ? "::Impl_::Split" : "", + cold ? FieldName(field) + "_" + : FieldMemberName(field, /*cold=*/false), + (oneof ? oneof->index() : entry.hasbit_idx), entry.aux_idx); + FormatFieldKind(format, entry, options_, scc_analyzer_); } format("},\n"); } } -void ParseFunctionGenerator::GenerateFieldNames(Formatter& format) { - if (tc_table_info_->field_name_data.empty()) { - // No names to output. - return; +static constexpr int kMaxNameLength = 255; + +int ParseFunctionGenerator::CalculateFieldNamesSize() const { + // The full name of the message appears first. + int size = std::min(static_cast(descriptor_->full_name().size()), + kMaxNameLength); + int lengths_size = 1; + for (const auto& entry : tc_table_info_->field_entries) { + const FieldDescriptor* field = entry.field; + GOOGLE_CHECK_LE(field->name().size(), kMaxNameLength); + size += field->name().size(); + lengths_size += 1; } + // align to an 8-byte boundary + lengths_size = (lengths_size + 7) & -8; + return size + lengths_size + 1; +} - // We could just output the bytes directly, but we want it to look better than - // that in the source code. Also, it is more efficient for compilation time to - // have a literal string than an initializer list of chars. +static void FormatOctal(Formatter& format, int size) { + int octal_size = ((size >> 6) & 3) * 100 + // + ((size >> 3) & 7) * 10 + // + ((size >> 0) & 7); + format("\\$1$", octal_size); +} - const int total_sizes = - static_cast(((tc_table_info_->field_entries.size() + 1) + 7) & ~7); - const uint8_t* p = tc_table_info_->field_name_data.data(); - const uint8_t* sizes = p; - const uint8_t* sizes_end = sizes + total_sizes; - - // First print all the sizes as octal +void ParseFunctionGenerator::GenerateFieldNames(Formatter& format) { + // First, we output the size of each string, as an unsigned byte. The first + // string is the message name. + int count = 1; format("\""); - for (int i = 0; i < total_sizes; ++i) { - int size = *p++; - int octal_size = ((size >> 6) & 3) * 100 + // - ((size >> 3) & 7) * 10 + // - ((size >> 0) & 7); - format("\\$1$", octal_size); + FormatOctal(format, + std::min(static_cast(descriptor_->full_name().size()), 255)); + for (const auto& entry : tc_table_info_->field_entries) { + FormatOctal(format, entry.field->name().size()); + ++count; + } + while (count & 7) { // align to an 8-byte boundary + format("\\0"); + ++count; } format("\"\n"); - - // Then print each name in a line of its own - for (; sizes < sizes_end; p += *sizes++) { - if (*sizes != 0) format("\"$1$\"\n", std::string(p, p + *sizes)); + // The message name is stored at the beginning of the string + std::string message_name = descriptor_->full_name(); + if (message_name.size() > kMaxNameLength) { + static constexpr int kNameHalfLength = (kMaxNameLength - 3) / 2; + message_name = StrCat( + message_name.substr(0, kNameHalfLength), "...", + message_name.substr(message_name.size() - kNameHalfLength)); + } + format("\"$1$\"\n", message_name); + // Then we output the actual field names + for (const auto& entry : tc_table_info_->field_entries) { + const FieldDescriptor* field = entry.field; + format("\"$1$\"\n", field->name()); } } void ParseFunctionGenerator::GenerateArenaString(Formatter& format, const FieldDescriptor* field) { - if (internal::cpp::HasHasbit(field)) { + if (HasHasbit(field)) { format("_Internal::set_has_$1$(&$has_bits$);\n", FieldName(field)); } format( @@ -932,9 +1184,7 @@ void ParseFunctionGenerator::GenerateStrings(Formatter& format, // to verify UTF8 when we already know parsing failed. format("CHK_(ptr);\n"); if (!check_utf8) return; // return if this is a bytes field - auto level = internal::cpp::GetUtf8CheckMode( - field, - GetOptimizeFor(field->file(), options_) == FileOptions::LITE_RUNTIME); + auto level = GetUtf8CheckMode(field, options_); switch (level) { case Utf8CheckMode::kNone: return; @@ -948,7 +1198,7 @@ void ParseFunctionGenerator::GenerateStrings(Formatter& format, std::string field_name; field_name = "nullptr"; if (HasDescriptorMethods(field->file(), options_)) { - field_name = absl::StrCat("\"", field->full_name(), "\""); + field_name = StrCat("\"", field->full_name(), "\""); } format("::_pbi::VerifyUTF8(str, $1$)", field_name); switch (level) { @@ -969,7 +1219,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, const FieldDescriptor* field) { if (field->is_packable()) { if (field->type() == FieldDescriptor::TYPE_ENUM && - !internal::cpp::HasPreservingUnknownEnumSemantics(field)) { + !HasPreservingUnknownEnumSemantics(field)) { std::string enum_type = QualifiedClassName(field->enum_type(), options_); format( "ptr = " @@ -998,7 +1248,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, const FieldDescriptor* val = field->message_type()->map_value(); GOOGLE_CHECK(val); if (val->type() == FieldDescriptor::TYPE_ENUM && - !internal::cpp::HasPreservingUnknownEnumSemantics(field)) { + !HasPreservingUnknownEnumSemantics(field)) { format( "auto object = " "::$proto_ns$::internal::InitEnumParseWrapper<" @@ -1017,7 +1267,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, format( "ctx->set_lazy_eager_verify_func($1$);\n", eager_verify - ? absl::StrCat("&", ClassName(field->message_type(), true), + ? StrCat("&", ClassName(field->message_type(), true), "::InternalVerify") : "nullptr"); } @@ -1032,7 +1282,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, "}\n" "auto* lazy_field = $msg$$field$;\n", field->containing_oneof()->name()); - } else if (internal::cpp::HasHasbit(field)) { + } else if (HasHasbit(field)) { format( "_Internal::set_has_$name$(&$has_bits$);\n" "auto* lazy_field = &$msg$$field$;\n"); @@ -1106,12 +1356,12 @@ void ParseFunctionGenerator::GenerateFieldBody( {{"name", FieldName(field)}, {"primitive_type", PrimitiveTypeName(options_, field->cpp_type())}}); if (field->is_repeated()) { - format.AddMap({{"put_field", absl::StrCat("add_", FieldName(field))}, - {"mutable_field", absl::StrCat("add_", FieldName(field))}}); + format.AddMap({{"put_field", StrCat("add_", FieldName(field))}, + {"mutable_field", StrCat("add_", FieldName(field))}}); } else { format.AddMap( - {{"put_field", absl::StrCat("set_", FieldName(field))}, - {"mutable_field", absl::StrCat("mutable_", FieldName(field))}}); + {{"put_field", StrCat("set_", FieldName(field))}, + {"mutable_field", StrCat("mutable_", FieldName(field))}}); } uint32_t tag = WireFormatLite::MakeTag(field->number(), wiretype); switch (wiretype) { @@ -1121,17 +1371,14 @@ void ParseFunctionGenerator::GenerateFieldBody( format.Set("enum_type", QualifiedClassName(field->enum_type(), options_)); format( - "$uint32$ val = ::$proto_ns$::internal::ReadVarint32(&ptr);\n" + "$uint64$ val = ::$proto_ns$::internal::ReadVarint64(&ptr);\n" "CHK_(ptr);\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(field)) { - format( - "if " - "(PROTOBUF_PREDICT_TRUE($enum_type$_IsValid(static_cast(val)" - "))) {\n"); + if (!HasPreservingUnknownEnumSemantics(field)) { + format("if (PROTOBUF_PREDICT_TRUE($enum_type$_IsValid(val))) {\n"); format.Indent(); } format("$msg$_internal_$put_field$(static_cast<$enum_type$>(val));\n"); - if (!internal::cpp::HasPreservingUnknownEnumSemantics(field)) { + if (!HasPreservingUnknownEnumSemantics(field)) { format.Outdent(); format( "} else {\n" @@ -1158,7 +1405,7 @@ void ParseFunctionGenerator::GenerateFieldBody( "CHK_(ptr);\n", zigzag, size); } else { - if (internal::cpp::HasHasbit(field)) { + if (HasHasbit(field)) { format("_Internal::set_has_$name$(&$has_bits$);\n"); } format( @@ -1177,7 +1424,7 @@ void ParseFunctionGenerator::GenerateFieldBody( "::$proto_ns$::internal::UnalignedLoad<$primitive_type$>(ptr));\n" "ptr += sizeof($primitive_type$);\n"); } else { - if (internal::cpp::HasHasbit(field)) { + if (HasHasbit(field)) { format("_Internal::set_has_$name$(&$has_bits$);\n"); } format( @@ -1365,45 +1612,112 @@ void ParseFunctionGenerator::GenerateFieldSwitch( format("} // switch\n"); } -#if 0 -void PopulateFastFieldEntry(const Descriptor* descriptor, - const TailCallTableInfo::FieldEntryInfo& entry, - const Options& options, - TailCallTableInfo::FastFieldInfo& info) { - ..... - if (name == "V8S1") { - info.func_name = absl::StrCat( - "::_pbi::TcParser::SingularVarintNoZag1()"); - } else if (name == "V32S1") { - info.func_name = absl::StrCat( - "::_pbi::TcParser::SingularVarintNoZag1()"); - } else if (name == "V64S1") { - info.func_name = absl::StrCat( - "::_pbi::TcParser::SingularVarintNoZag1()"); - } else { - info.func_name = absl::StrCat("::_pbi::TcParser::Fast", name); +namespace { + +std::string FieldParseFunctionName( + const TailCallTableInfo::FieldEntryInfo& entry, const Options& options) { + const FieldDescriptor* field = entry.field; + std::string name = "::_pbi::TcParser::Fast"; + + switch (field->type()) { + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_SFIXED32: + case FieldDescriptor::TYPE_FLOAT: + name.append("F32"); + break; + + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED64: + case FieldDescriptor::TYPE_DOUBLE: + name.append("F64"); + break; + + case FieldDescriptor::TYPE_BOOL: + name.append("V8"); + break; + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_UINT32: + name.append("V32"); + break; + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_UINT64: + name.append("V64"); + break; + + case FieldDescriptor::TYPE_ENUM: + if (HasPreservingUnknownEnumSemantics(field)) { + name.append("V32"); + break; + } + if (field->is_repeated() && field->is_packed()) { + GOOGLE_LOG(DFATAL) << "Enum validation not handled: " << field->DebugString(); + return ""; + } + name.append(entry.is_enum_range ? "Er" : "Ev"); + break; + + case FieldDescriptor::TYPE_SINT32: + name.append("Z32"); + break; + case FieldDescriptor::TYPE_SINT64: + name.append("Z64"); + break; + + case FieldDescriptor::TYPE_BYTES: + name.append("B"); + if (IsStringInlined(field, options)) { + name.append("i"); + } + break; + case FieldDescriptor::TYPE_STRING: + switch (GetUtf8CheckMode(field, options)) { + case Utf8CheckMode::kNone: + name.append("B"); + break; + case Utf8CheckMode::kVerify: + name.append("S"); + break; + case Utf8CheckMode::kStrict: + name.append("U"); + break; + default: + GOOGLE_LOG(DFATAL) << "Mode not handled: " + << static_cast(GetUtf8CheckMode(field, options)); + return ""; + } + if (IsStringInlined(field, options)) { + name.append("i"); + } + break; + + case FieldDescriptor::TYPE_MESSAGE: + name.append("M"); + break; + case FieldDescriptor::TYPE_GROUP: + name.append("G"); + break; + + default: + GOOGLE_LOG(DFATAL) << "Type not handled: " << field->DebugString(); + return ""; } - info.aux_idx = aux_idx; + + // The field implementation functions are prefixed by cardinality: + // `S` for optional or implicit fields. + // `R` for non-packed repeated. + // `P` for packed repeated. + name.append(field->is_packed() ? "P" + : field->is_repeated() ? "R" + : field->real_containing_oneof() ? "O" + : "S"); + + // Append the tag length. Fast parsing only handles 1- or 2-byte tags. + name.append(TagSize(field->number()) == 1 ? "1" : "2"); + + return name; } -#endif + +} // namespace } // namespace cpp } // namespace compiler diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.h b/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.h index b55feda..542a15a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/parse_function_generator.h @@ -35,18 +35,58 @@ #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/generated_message_tctable_gen.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { +// Helper class for generating tailcall parsing functions. +struct TailCallTableInfo { + TailCallTableInfo(const Descriptor* descriptor, const Options& options, + const std::vector& ordered_fields, + const std::vector& has_bit_indices, + const std::vector& inlined_string_indices, + MessageSCCAnalyzer* scc_analyzer); + + // Fields parsed by the table fast-path. + struct FastFieldInfo { + std::string func_name; + const FieldDescriptor* field; + uint16_t coded_tag; + uint8_t hasbit_idx; + uint8_t aux_idx; + }; + std::vector fast_path_fields; + + // Fields parsed by mini parsing routines. + struct FieldEntryInfo { + const FieldDescriptor* field; + int hasbit_idx; + int inlined_string_idx; + uint16_t aux_idx; + // True for enums entirely covered by the start/length fields of FieldAux: + bool is_enum_range; + }; + std::vector field_entries; + std::vector aux_entries; + + // Fields parsed by generated fallback function. + std::vector fallback_fields; + + // Table size. + int table_size_log2; + // Mask for has-bits of required fields. + uint32_t has_hasbits_required_mask; + // True if a generated fallback function is required instead of generic. + bool use_generated_fallback; +}; + // ParseFunctionGenerator generates the _InternalParse function for a message // (and any associated supporting members). class ParseFunctionGenerator { @@ -71,8 +111,6 @@ class ParseFunctionGenerator { void GenerateDataDefinitions(io::Printer* printer); private: - class GeneratedOptionProvider; - // Returns true if tailcall table code should be generated. bool should_generate_tctable() const; @@ -96,6 +134,7 @@ class ParseFunctionGenerator { void GenerateTailCallTable(Formatter& format); void GenerateFastFieldEntries(Formatter& format); void GenerateFieldEntries(Formatter& format); + int CalculateFieldNamesSize() const; void GenerateFieldNames(Formatter& format); // Generates parsing code for an `ArenaString` field. @@ -127,7 +166,7 @@ class ParseFunctionGenerator { MessageSCCAnalyzer* scc_analyzer_; const Options& options_; std::map variables_; - std::unique_ptr tc_table_info_; + std::unique_ptr tc_table_info_; std::vector inlined_string_indices_; const std::vector ordered_fields_; int num_hasbits_; diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/plugin_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/plugin_unittest.cc index 30bd374..f023dcf 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/plugin_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/plugin_unittest.cc @@ -36,13 +36,13 @@ #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/cpp/generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.cc index ff30c94..6c92ede 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -32,12 +32,12 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/primitive_field.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/cpp/helpers.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -108,10 +108,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, bool cold = ShouldSplit(descriptor, options); (*variables)["cached_byte_size_field"] = MakeVarintCachedSizeFieldName(descriptor, cold); - (*variables)["tag"] = absl::StrCat(internal::WireFormat::MakeTag(descriptor)); + (*variables)["tag"] = StrCat(internal::WireFormat::MakeTag(descriptor)); int fixed_size = FixedSize(descriptor->type()); if (fixed_size != -1) { - (*variables)["fixed_size"] = absl::StrCat(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } (*variables)["wire_format_field_type"] = FieldDescriptorProto_Type_Name( static_cast(descriptor->type())); @@ -328,9 +328,7 @@ void RepeatedPrimitiveFieldGenerator::GeneratePrivateMembers( format("::$proto_ns$::RepeatedField< $type$ > $name$_;\n"); if (descriptor_->is_packed() && FixedSize(descriptor_->type()) == -1 && HasGeneratedMethods(descriptor_->file(), options_)) { - format( - "mutable ::$proto_ns$::internal::CachedSize " - "$cached_byte_size_name$;\n"); + format("mutable std::atomic $cached_byte_size_name$;\n"); } } @@ -435,7 +433,7 @@ void RepeatedPrimitiveFieldGenerator::GenerateSerializeWithCachedSizesToArray( format( "{\n" " int byte_size = " - "$cached_byte_size_field$.Get();\n" + "$cached_byte_size_field$.load(std::memory_order_relaxed);\n" " if (byte_size > 0) {\n" " target = stream->Write$declared_type$Packed(\n" " $number$, _internal_$name$(), byte_size, target);\n" @@ -486,7 +484,8 @@ void RepeatedPrimitiveFieldGenerator::GenerateByteSize( if (FixedSize(descriptor_->type()) == -1) { format( "int cached_size = ::_pbi::ToCachedSize(data_size);\n" - "$cached_byte_size_field$.Set(cached_size);\n"); + "$cached_byte_size_field$.store(cached_size,\n" + " std::memory_order_relaxed);\n"); } format("total_size += data_size;\n"); } else { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.h index b39c846..bb8a08a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/primitive_field.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/cpp/field.h" +#include namespace google { namespace protobuf { @@ -49,8 +49,6 @@ class PrimitiveFieldGenerator : public FieldGenerator { public: PrimitiveFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete; - PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete; ~PrimitiveFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -69,15 +67,15 @@ class PrimitiveFieldGenerator : public FieldGenerator { io::Printer* printer) const override; void GenerateAggregateInitializer(io::Printer* printer) const override; void GenerateCopyAggregateInitializer(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator); }; class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { public: PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - PrimitiveOneofFieldGenerator(const PrimitiveOneofFieldGenerator&) = delete; - PrimitiveOneofFieldGenerator& operator=(const PrimitiveOneofFieldGenerator&) = - delete; ~PrimitiveOneofFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -85,16 +83,15 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator { void GenerateClearingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveOneofFieldGenerator); }; class RepeatedPrimitiveFieldGenerator : public FieldGenerator { public: RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - RepeatedPrimitiveFieldGenerator(const RepeatedPrimitiveFieldGenerator&) = - delete; - RepeatedPrimitiveFieldGenerator& operator=( - const RepeatedPrimitiveFieldGenerator&) = delete; ~RepeatedPrimitiveFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -116,6 +113,9 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { io::Printer* printer) const override; void GenerateAggregateInitializer(io::Printer* printer) const override; void GenerateCopyAggregateInitializer(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/service.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/service.cc index baa58b9..7a0d480 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/service.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/service.cc @@ -32,280 +32,293 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/service.h" +#include -#include -#include - -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace cpp { -void ServiceGenerator::GenerateDeclarations(io::Printer* printer) { - auto vars = printer->WithVars(&vars_); - printer->Emit( - { - {"virts", [&] { GenerateMethodSignatures(kVirtual, printer); }}, - {"impls", [&] { GenerateMethodSignatures(kNonVirtual, printer); }}, - }, - R"cc( - class $classname$_Stub; - class $dllexport_decl $$classname$ : public ::$proto_ns$::Service { - protected: - $classname$() = default; - public: - using Stub = $classname$_Stub; +namespace { - $classname$(const $classname$&) = delete; - $classname$& operator=(const $classname$&) = delete; - virtual ~$classname$() = default; - - static const ::$proto_ns$::ServiceDescriptor* descriptor(); - - $virts$; - - // implements Service ---------------------------------------------- - const ::$proto_ns$::ServiceDescriptor* GetDescriptor() override; - - void CallMethod(const ::$proto_ns$::MethodDescriptor* method, - ::$proto_ns$::RpcController* controller, - const ::$proto_ns$::Message* request, - ::$proto_ns$::Message* response, - ::google::protobuf::Closure* done) override; - - const ::$proto_ns$::Message& GetRequestPrototype( - const ::$proto_ns$::MethodDescriptor* method) const override; - - const ::$proto_ns$::Message& GetResponsePrototype( - const ::$proto_ns$::MethodDescriptor* method) const override; - }; - - class $dllexport_decl $$classname$_Stub : public $classname$ { - public: - $classname$_Stub(::$proto_ns$::RpcChannel* channel); - $classname$_Stub(::$proto_ns$::RpcChannel* channel, - ::$proto_ns$::Service::ChannelOwnership ownership); - - $classname$_Stub(const $classname$_Stub&) = delete; - $classname$_Stub& operator=(const $classname$_Stub&) = delete; - - ~$classname$_Stub() override; - - inline ::$proto_ns$::RpcChannel* channel() { return channel_; } - - // implements $classname$ ------------------------------------------ - $impls$; - - private: - ::$proto_ns$::RpcChannel* channel_; - bool owns_channel_; - }; - )cc"); +void InitMethodVariables(const MethodDescriptor* method, const Options& options, + Formatter* format) { + format->Set("name", method->name()); + format->Set("input_type", QualifiedClassName(method->input_type(), options)); + format->Set("output_type", + QualifiedClassName(method->output_type(), options)); } -void ServiceGenerator::GenerateMethodSignatures(VirtualOrNot virtual_or_not, - io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); ++i) { - const MethodDescriptor* method = descriptor_->method(i); +} // namespace - printer->Emit( - { - {"name", method->name()}, - {"input", QualifiedClassName(method->input_type(), *options_)}, - {"output", QualifiedClassName(method->output_type(), *options_)}, - {"virtual", virtual_or_not == kVirtual ? "virtual" : ""}, - {"override", virtual_or_not != kVirtual ? "override" : ""}, - }, - // No cc, clang-format does not format this string well due to the - // $ override$ substitution. - R"( - $virtual $void $name$(::$proto_ns$::RpcController* controller, - const $input$* request, - $output$* response, - ::google::protobuf::Closure* done)$ override$; - )"); +ServiceGenerator::ServiceGenerator( + const ServiceDescriptor* descriptor, + const std::map& vars, const Options& options) + : descriptor_(descriptor), vars_(vars), options_(options) { + vars_["classname"] = descriptor_->name(); + vars_["full_name"] = descriptor_->full_name(); +} + +ServiceGenerator::~ServiceGenerator() {} + +void ServiceGenerator::GenerateDeclarations(io::Printer* printer) { + Formatter format(printer, vars_); + // Forward-declare the stub type. + format( + "class $classname$_Stub;\n" + "\n"); + + GenerateInterface(printer); + GenerateStubDefinition(printer); +} + +void ServiceGenerator::GenerateInterface(io::Printer* printer) { + Formatter format(printer, vars_); + format( + "class $dllexport_decl $$classname$ : public ::$proto_ns$::Service {\n" + " protected:\n" + " // This class should be treated as an abstract interface.\n" + " inline $classname$() {};\n" + " public:\n" + " virtual ~$classname$();\n"); + printer->Indent(); + + format( + "\n" + "typedef $classname$_Stub Stub;\n" + "\n" + "static const ::$proto_ns$::ServiceDescriptor* descriptor();\n" + "\n"); + + GenerateMethodSignatures(VIRTUAL, printer); + + format( + "\n" + "// implements Service ----------------------------------------------\n" + "\n" + "const ::$proto_ns$::ServiceDescriptor* GetDescriptor();\n" + "void CallMethod(const ::$proto_ns$::MethodDescriptor* method,\n" + " ::$proto_ns$::RpcController* controller,\n" + " const ::$proto_ns$::Message* request,\n" + " ::$proto_ns$::Message* response,\n" + " ::google::protobuf::Closure* done);\n" + "const ::$proto_ns$::Message& GetRequestPrototype(\n" + " const ::$proto_ns$::MethodDescriptor* method) const;\n" + "const ::$proto_ns$::Message& GetResponsePrototype(\n" + " const ::$proto_ns$::MethodDescriptor* method) const;\n"); + + printer->Outdent(); + format( + "\n" + " private:\n" + " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$);\n" + "};\n" + "\n"); +} + +void ServiceGenerator::GenerateStubDefinition(io::Printer* printer) { + Formatter format(printer, vars_); + format( + "class $dllexport_decl $$classname$_Stub : public $classname$ {\n" + " public:\n"); + + printer->Indent(); + + format( + "$classname$_Stub(::$proto_ns$::RpcChannel* channel);\n" + "$classname$_Stub(::$proto_ns$::RpcChannel* channel,\n" + " ::$proto_ns$::Service::ChannelOwnership ownership);\n" + "~$classname$_Stub();\n" + "\n" + "inline ::$proto_ns$::RpcChannel* channel() { return channel_; }\n" + "\n" + "// implements $classname$ ------------------------------------------\n" + "\n"); + + GenerateMethodSignatures(NON_VIRTUAL, printer); + + printer->Outdent(); + format( + " private:\n" + " ::$proto_ns$::RpcChannel* channel_;\n" + " bool owns_channel_;\n" + " GOOGLE_DISALLOW_EVIL_CONSTRUCTORS($classname$_Stub);\n" + "};\n" + "\n"); +} + +void ServiceGenerator::GenerateMethodSignatures(VirtualOrNon virtual_or_non, + io::Printer* printer) { + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + Formatter format(printer, vars_); + InitMethodVariables(method, options_, &format); + format.Set("virtual", virtual_or_non == VIRTUAL ? "virtual " : ""); + format( + "$virtual$void $name$(::$proto_ns$::RpcController* controller,\n" + " const $input_type$* request,\n" + " $output_type$* response,\n" + " ::google::protobuf::Closure* done);\n"); } } // =================================================================== void ServiceGenerator::GenerateImplementation(io::Printer* printer) { - auto vars = printer->WithVars(&vars_); - printer->Emit( - { - {"index", index_in_metadata_}, - {"no_impl_methods", [&] { GenerateNotImplementedMethods(printer); }}, - {"call_method", [&] { GenerateCallMethod(printer); }}, - {"get_request", [&] { GenerateGetPrototype(kRequest, printer); }}, - {"get_response", [&] { GenerateGetPrototype(kResponse, printer); }}, - {"stub_methods", [&] { GenerateStubMethods(printer); }}, - }, - R"cc( - const ::$proto_ns$::ServiceDescriptor* $classname$::descriptor() { - ::$proto_ns$::internal::AssignDescriptors(&$desc_table$); - return $file_level_service_descriptors$[$index$]; - } + Formatter format(printer, vars_); + format( + "$classname$::~$classname$() {}\n" + "\n" + "const ::$proto_ns$::ServiceDescriptor* $classname$::descriptor() {\n" + " " + "::$proto_ns$::internal::AssignDescriptors(&$desc_table$);\n" + " return $file_level_service_descriptors$[$1$];\n" + "}\n" + "\n" + "const ::$proto_ns$::ServiceDescriptor* $classname$::GetDescriptor() {\n" + " return descriptor();\n" + "}\n" + "\n", + index_in_metadata_); - const ::$proto_ns$::ServiceDescriptor* $classname$::GetDescriptor() { - return descriptor(); - } + // Generate methods of the interface. + GenerateNotImplementedMethods(printer); + GenerateCallMethod(printer); + GenerateGetPrototype(REQUEST, printer); + GenerateGetPrototype(RESPONSE, printer); - $no_impl_methods$; + // Generate stub implementation. + format( + "$classname$_Stub::$classname$_Stub(::$proto_ns$::RpcChannel* channel)\n" + " : channel_(channel), owns_channel_(false) {}\n" + "$classname$_Stub::$classname$_Stub(\n" + " ::$proto_ns$::RpcChannel* channel,\n" + " ::$proto_ns$::Service::ChannelOwnership ownership)\n" + " : channel_(channel),\n" + " owns_channel_(ownership == " + "::$proto_ns$::Service::STUB_OWNS_CHANNEL) " + "{}\n" + "$classname$_Stub::~$classname$_Stub() {\n" + " if (owns_channel_) delete channel_;\n" + "}\n" + "\n"); - $call_method$; - - $get_request$; - - $get_response$; - - $classname$_Stub::$classname$_Stub(::$proto_ns$::RpcChannel* channel) - : channel_(channel), owns_channel_(false) {} - - $classname$_Stub::$classname$_Stub( - ::$proto_ns$::RpcChannel* channel, - ::$proto_ns$::Service::ChannelOwnership ownership) - : channel_(channel), - owns_channel_(ownership == - ::$proto_ns$::Service::STUB_OWNS_CHANNEL) {} - - $classname$_Stub::~$classname$_Stub() { - if (owns_channel_) delete channel_; - } - - $stub_methods$; - )cc"); + GenerateStubMethods(printer); } void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); ++i) { + for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - - printer->Emit( - { - {"name", method->name()}, - {"input", QualifiedClassName(method->input_type(), *options_)}, - {"output", QualifiedClassName(method->output_type(), *options_)}, - }, - R"cc( - void $classname$::$name$(::$proto_ns$::RpcController* controller, - const $input$*, $output$*, ::google::protobuf::Closure* done) { - controller->SetFailed("Method $name$() not implemented."); - done->Run(); - } - )cc"); + Formatter format(printer, vars_); + InitMethodVariables(method, options_, &format); + format( + "void $classname$::$name$(::$proto_ns$::RpcController* controller,\n" + " const $input_type$*,\n" + " $output_type$*,\n" + " ::google::protobuf::Closure* done) {\n" + " controller->SetFailed(\"Method $name$() not implemented.\");\n" + " done->Run();\n" + "}\n" + "\n"); } } void ServiceGenerator::GenerateCallMethod(io::Printer* printer) { - printer->Emit( - { - {"index", absl::StrCat(index_in_metadata_)}, - {"cases", [&] { GenerateCallMethodCases(printer); }}, - }, - R"cc( - void $classname$::CallMethod( - const ::$proto_ns$::MethodDescriptor* method, - ::$proto_ns$::RpcController* controller, - const ::$proto_ns$::Message* request, - ::$proto_ns$::Message* response, ::google::protobuf::Closure* done) { - GOOGLE_DCHECK_EQ(method->service(), $file_level_service_descriptors$[$index$]); - switch (method->index()) { - $cases$; + Formatter format(printer, vars_); + format( + "void $classname$::CallMethod(const ::$proto_ns$::MethodDescriptor* " + "method,\n" + " ::$proto_ns$::RpcController* controller,\n" + " const ::$proto_ns$::Message* request,\n" + " ::$proto_ns$::Message* response,\n" + " ::google::protobuf::Closure* done) {\n" + " GOOGLE_DCHECK_EQ(method->service(), $file_level_service_descriptors$[$1$]);\n" + " switch(method->index()) {\n", + index_in_metadata_); - default: - GOOGLE_LOG(FATAL) << "Bad method index; this should never happen."; - break; - } - } - )cc"); + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + Formatter format_method(printer, vars_); + InitMethodVariables(method, options_, &format_method); + + // Note: down_cast does not work here because it only works on pointers, + // not references. + format_method( + " case $1$:\n" + " $name$(controller,\n" + " ::$proto_ns$::internal::DownCast(\n" + " request),\n" + " ::$proto_ns$::internal::DownCast<$output_type$*>(\n" + " response),\n" + " done);\n" + " break;\n", + i); + } + + format( + " default:\n" + " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n" + " break;\n" + " }\n" + "}\n" + "\n"); } void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which, io::Printer* printer) { - printer->Emit( - { - {"which", which == kRequest ? "Request" : "Response"}, - {"which_type", which == kRequest ? "input" : "output"}, - {"cases", - [&] { - for (int i = 0; i < descriptor_->method_count(); ++i) { - const MethodDescriptor* method = descriptor_->method(i); - const Descriptor* type = which == kRequest - ? method->input_type() - : method->output_type(); - - printer->Emit( - { - {"index", absl::StrCat(i)}, - {"type", QualifiedClassName(type, *options_)}, - }, - R"cc( - case $index$: - return $type$::default_instance(); - )cc"); - } - }}, - }, - R"cc( - const ::$proto_ns$::Message& $classname$::Get$which$Prototype( - const ::$proto_ns$::MethodDescriptor* method) const { - GOOGLE_DCHECK_EQ(method->service(), descriptor()); - switch (method->index()) { - $cases$; - - default: - GOOGLE_LOG(FATAL) << "Bad method index; this should never happen."; - return *::$proto_ns$::MessageFactory::generated_factory() - ->GetPrototype(method->$which_type$_type()); - } - } - )cc"); -} - -void ServiceGenerator::GenerateCallMethodCases(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); ++i) { - const MethodDescriptor* method = descriptor_->method(i); - printer->Emit( - { - {"name", method->name()}, - {"input", QualifiedClassName(method->input_type(), *options_)}, - {"output", QualifiedClassName(method->output_type(), *options_)}, - {"index", absl::StrCat(i)}, - }, - R"cc( - case $index$: - $name$(controller, - ::$proto_ns$::internal::DownCast(request), - ::$proto_ns$::internal::DownCast<$output$*>(response), done); - break; - )cc"); + Formatter format(printer, vars_); + if (which == REQUEST) { + format("const ::$proto_ns$::Message& $classname$::GetRequestPrototype(\n"); + } else { + format("const ::$proto_ns$::Message& $classname$::GetResponsePrototype(\n"); } + + format( + " const ::$proto_ns$::MethodDescriptor* method) const {\n" + " GOOGLE_DCHECK_EQ(method->service(), descriptor());\n" + " switch(method->index()) {\n"); + + for (int i = 0; i < descriptor_->method_count(); i++) { + const MethodDescriptor* method = descriptor_->method(i); + const Descriptor* type = + (which == REQUEST) ? method->input_type() : method->output_type(); + + format( + " case $1$:\n" + " return $2$::default_instance();\n", + i, QualifiedClassName(type, options_)); + } + + format( + " default:\n" + " GOOGLE_LOG(FATAL) << \"Bad method index; this should never happen.\";\n" + " return *::$proto_ns$::MessageFactory::generated_factory()\n" + " ->GetPrototype(method->$1$_type());\n" + " }\n" + "}\n" + "\n", + which == REQUEST ? "input" : "output"); } void ServiceGenerator::GenerateStubMethods(io::Printer* printer) { - for (int i = 0; i < descriptor_->method_count(); ++i) { + for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); - - printer->Emit( - { - {"name", method->name()}, - {"input", QualifiedClassName(method->input_type(), *options_)}, - {"output", QualifiedClassName(method->output_type(), *options_)}, - {"index", absl::StrCat(i)}, - }, - R"cc( - void $classname$_Stub::$name$(::$proto_ns$::RpcController* controller, - const $input$* request, - $output$* response, ::google::protobuf::Closure* done) { - channel_->CallMethod(descriptor()->method($index$), controller, - request, response, done); - } - )cc"); + Formatter format(printer, vars_); + InitMethodVariables(method, options_, &format); + format( + "void $classname$_Stub::$name$(::$proto_ns$::RpcController* " + "controller,\n" + " const $input_type$* request,\n" + " $output_type$* response,\n" + " ::google::protobuf::Closure* done) {\n" + " channel_->CallMethod(descriptor()->method($1$),\n" + " controller, request, response, done);\n" + "}\n", + i); } } diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/service.h b/libs/protobuf/src/google/protobuf/compiler/cpp/service.h index 34b8914..b3bd2d7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/service.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/service.h @@ -38,48 +38,60 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/cpp/options.h" -#include "google/protobuf/io/printer.h" +#include +#include + +namespace google { +namespace protobuf { +namespace io { +class Printer; // printer.h +} +} // namespace protobuf +} // namespace google namespace google { namespace protobuf { namespace compiler { namespace cpp { + class ServiceGenerator { public: // See generator.cc for the meaning of dllexport_decl. - ServiceGenerator(const ServiceDescriptor* descriptor, - const std::map& vars, - const Options& options) - : descriptor_(descriptor), options_(&options), vars_(vars) { - vars_["classname"] = descriptor_->name(); - vars_["full_name"] = descriptor_->full_name(); - } + explicit ServiceGenerator(const ServiceDescriptor* descriptor, + const std::map& vars, + const Options& options); + ~ServiceGenerator(); - ServiceGenerator(const ServiceGenerator&) = delete; - ServiceGenerator& operator=(const ServiceGenerator&) = delete; - ServiceGenerator(ServiceGenerator&&) = delete; - ServiceGenerator& operator=(ServiceGenerator&&) = delete; - - ~ServiceGenerator() = default; + // Header stuff. // Generate the class definitions for the service's interface and the // stub implementation. void GenerateDeclarations(io::Printer* printer); + // Source file stuff. + // Generate implementations of everything declared by // GenerateDeclarations(). void GenerateImplementation(io::Printer* printer); private: - enum RequestOrResponse { kRequest, kResponse }; - enum VirtualOrNot { kVirtual, kNonVirtual }; + enum RequestOrResponse { REQUEST, RESPONSE }; + enum VirtualOrNon { VIRTUAL, NON_VIRTUAL }; + + // Header stuff. + + // Generate the service abstract interface. + void GenerateInterface(io::Printer* printer); + + // Generate the stub class definition. + void GenerateStubDefinition(io::Printer* printer); // Prints signatures for all methods in the - void GenerateMethodSignatures(VirtualOrNot virtual_or_not, + void GenerateMethodSignatures(VirtualOrNon virtual_or_non, io::Printer* printer); + // Source file stuff. + // Generate the default implementations of the service methods, which // produce a "not implemented" error. void GenerateNotImplementedMethods(io::Printer* printer); @@ -90,20 +102,19 @@ class ServiceGenerator { // Generate the Get{Request,Response}Prototype() methods. void GenerateGetPrototype(RequestOrResponse which, io::Printer* printer); - // Generate the cases in CallMethod(). - void GenerateCallMethodCases(io::Printer* printer); - // Generate the stub's implementations of the service methods. void GenerateStubMethods(io::Printer* printer); const ServiceDescriptor* descriptor_; - const Options* options_; std::map vars_; + const Options& options_; int index_in_metadata_; friend class FileGenerator; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); }; + } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.cc index bcb1253..9e7c96d 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.cc @@ -32,14 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/cpp/string_field.h" +#include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" namespace google { namespace protobuf { @@ -53,12 +52,12 @@ void SetStringVariables(const FieldDescriptor* descriptor, const Options& options) { SetCommonFieldVariables(descriptor, variables, options); - const std::string kNS = "::" + ProtobufNamespace(options) + "::internal::"; + const std::string kNS = "::" + (*variables)["proto_ns"] + "::internal::"; const std::string kArenaStringPtr = kNS + "ArenaStringPtr"; (*variables)["default"] = DefaultValue(options, descriptor); (*variables)["default_length"] = - absl::StrCat(descriptor->default_value_string().length()); + StrCat(descriptor->default_value_string().length()); (*variables)["default_variable_name"] = MakeDefaultName(descriptor); (*variables)["default_variable_field"] = MakeDefaultFieldName(descriptor); @@ -68,7 +67,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, (*variables)["lazy_variable_args"] = ""; } else { (*variables)["lazy_variable"] = - absl::StrCat(QualifiedClassName(descriptor->containing_type(), options), + StrCat(QualifiedClassName(descriptor->containing_type(), options), "::", MakeDefaultFieldName(descriptor)); (*variables)["default_string"] = (*variables)["lazy_variable"] + ".get()"; @@ -80,6 +79,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; (*variables)["setter"] = descriptor->type() == FieldDescriptor::TYPE_BYTES ? "SetBytes" : "Set"; + (*variables)["null_check"] = (*variables)["DCHK"] + "(value != nullptr);\n"; // NOTE: Escaped here to unblock proto1->proto2 migration. // TODO(liujisi): Extend this to apply for other conflicting methods. (*variables)["release_name"] = @@ -89,7 +89,7 @@ void SetStringVariables(const FieldDescriptor* descriptor, if (options.opensource_runtime) { (*variables)["string_piece"] = "::std::string"; } else { - (*variables)["string_piece"] = "::absl::string_view"; + (*variables)["string_piece"] = "::StringPiece"; } } @@ -286,7 +286,7 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions( "$maybe_prepare_split_message$" " // @@protoc_insertion_point(field_release:$full_name$)\n"); - if (internal::cpp::HasHasbit(descriptor_)) { + if (HasHasbit(descriptor_)) { format( " if (!_internal_has_$name$()) {\n" " return nullptr;\n" @@ -297,7 +297,9 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions( if (descriptor_->default_value_string().empty()) { format( "#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n" - " $field$.Set(\"\", GetArenaForAllocation());\n" + " if ($field$.IsDefault()) {\n" + " $field$.Set(\"\", GetArenaForAllocation());\n" + " }\n" "#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"); } format(" return p;\n"); @@ -313,20 +315,12 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions( format( "}\n" "inline void $classname$::set_allocated_$name$(std::string* $name$) {\n" - "$maybe_prepare_split_message$"); - - auto nonempty = [this](const char* fn) { - auto var_it = variables_.find(fn); - return var_it != variables_.end() && !var_it->second.empty(); - }; - if (nonempty("set_hasbit") || nonempty("clear_hasbit")) { - format( - " if ($name$ != nullptr) {\n" - " $set_hasbit$\n" - " } else {\n" - " $clear_hasbit$\n" - " }\n"); - } + "$maybe_prepare_split_message$" + " if ($name$ != nullptr) {\n" + " $set_hasbit$\n" + " } else {\n" + " $clear_hasbit$\n" + " }\n"); if (!inlined_) { format(" $field$.SetAllocated($name$, GetArenaForAllocation());\n"); if (descriptor_->default_value_string().empty()) { @@ -383,7 +377,7 @@ void StringFieldGenerator::GenerateMessageClearingCode( // If we have a hasbit, then the Clear() method of the protocol buffer // will have checked that this field is set. If so, we can avoid redundant // checks against the default variable. - const bool must_be_present = internal::cpp::HasHasbit(descriptor_); + const bool must_be_present = HasHasbit(descriptor_); if (inlined_ && must_be_present) { // Calling mutable_$name$() gives us a string reference and sets the has bit @@ -451,6 +445,21 @@ void StringFieldGenerator::GenerateConstructorCode(io::Printer* printer) const { } } +void StringFieldGenerator::GenerateCreateSplitMessageCode( + io::Printer* printer) const { + GOOGLE_CHECK(ShouldSplit(descriptor_, options_)); + GOOGLE_CHECK(!inlined_); + Formatter format(printer, variables_); + format("ptr->$name$_.InitDefault();\n"); + if (IsString(descriptor_, options_) && + descriptor_->default_value_string().empty()) { + format( + "#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING\n" + " ptr->$name$_.Set(\"\", GetArenaForAllocation());\n" + "#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING\n"); + } +} + void StringFieldGenerator::GenerateCopyConstructorCode( io::Printer* printer) const { Formatter format(printer, variables_); @@ -459,7 +468,7 @@ void StringFieldGenerator::GenerateCopyConstructorCode( format("new (&_this->$field$) ::_pbi::InlinedStringField();\n"); } - if (internal::cpp::HasHasbit(descriptor_)) { + if (HasHasbit(descriptor_)) { format("if (from._internal_has_$name$()) {\n"); } else { format("if (!from._internal_$name$().empty()) {\n"); @@ -545,9 +554,13 @@ void StringFieldGenerator::GenerateConstexprAggregateInitializer( format("/*decltype($field$)*/{nullptr, false}"); return; } - format( - "/*decltype($field$)*/{&::_pbi::fixed_address_empty_string, " - "::_pbi::ConstantInitialized{}}"); + if (descriptor_->default_value_string().empty()) { + format( + "/*decltype($field$)*/{&::_pbi::fixed_address_empty_string, " + "::_pbi::ConstantInitialized{}}"); + } else { + format("/*decltype($field$)*/{nullptr, ::_pbi::ConstantInitialized{}}"); + } } void StringFieldGenerator::GenerateAggregateInitializer( @@ -579,7 +592,7 @@ StringOneofFieldGenerator::StringOneofFieldGenerator( SetCommonOneofFieldVariables(descriptor, &variables_); variables_["field_name"] = UnderscoresToCamelCase(descriptor->name(), true); variables_["oneof_index"] = - absl::StrCat(descriptor->containing_oneof()->index()); + StrCat(descriptor->containing_oneof()->index()); } StringOneofFieldGenerator::~StringOneofFieldGenerator() {} @@ -724,7 +737,7 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations( if (!options_.opensource_runtime) { format( "$deprecated_attr$void ${1$set_$name$$}$(int index, " - "absl::string_view value);\n", + "StringPiece value);\n", descriptor_); } format( @@ -737,7 +750,7 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations( descriptor_); if (!options_.opensource_runtime) { format( - "$deprecated_attr$void ${1$add_$name$$}$(absl::string_view value);\n", + "$deprecated_attr$void ${1$add_$name$$}$(StringPiece value);\n", descriptor_); } format( @@ -811,7 +824,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" "inline void $classname$::set_$name$(int index, const char* value) {\n" - " $DCHK$(value != nullptr);" + " $null_check$" " $field$.Mutable(index)->assign(value);\n" "$annotate_set$" " // @@protoc_insertion_point(field_set_char:$full_name$)\n" @@ -819,7 +832,7 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions( if (!options_.opensource_runtime) { format( "inline void " - "$classname$::set_$name$(int index, absl::string_view value) {\n" + "$classname$::set_$name$(int index, StringPiece value) {\n" " $field$.Mutable(index)->assign(value.data(), value.size());\n" "$annotate_set$" " // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n" @@ -848,14 +861,14 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions( " // @@protoc_insertion_point(field_add:$full_name$)\n" "}\n" "inline void $classname$::add_$name$(const char* value) {\n" - " $DCHK$(value != nullptr);" + " $null_check$" " $field$.Add()->assign(value);\n" "$annotate_add$" " // @@protoc_insertion_point(field_add_char:$full_name$)\n" "}\n"); if (!options_.opensource_runtime) { format( - "inline void $classname$::add_$name$(absl::string_view value) {\n" + "inline void $classname$::add_$name$(StringPiece value) {\n" " $field$.Add()->assign(value.data(), value.size());\n" "$annotate_add$" " // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.h b/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.h index 02bee85..db5f18b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/string_field.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/cpp/field.h" +#include namespace google { namespace protobuf { @@ -49,8 +49,6 @@ class StringFieldGenerator : public FieldGenerator { public: StringFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - StringFieldGenerator(const StringFieldGenerator&) = delete; - StringFieldGenerator& operator=(const StringFieldGenerator&) = delete; ~StringFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -65,6 +63,7 @@ class StringFieldGenerator : public FieldGenerator { void GenerateMergingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; + void GenerateCreateSplitMessageCode(io::Printer* printer) const override; void GenerateCopyConstructorCode(io::Printer* printer) const override; void GenerateDestructorCode(io::Printer* printer) const override; void GenerateArenaDestructorCode(io::Printer* printer) const override; @@ -80,15 +79,13 @@ class StringFieldGenerator : public FieldGenerator { private: bool inlined_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator); }; class StringOneofFieldGenerator : public StringFieldGenerator { public: StringOneofFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - StringOneofFieldGenerator(const StringOneofFieldGenerator&) = delete; - StringOneofFieldGenerator& operator=(const StringOneofFieldGenerator&) = - delete; ~StringOneofFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -100,15 +97,15 @@ class StringOneofFieldGenerator : public StringFieldGenerator { void GenerateMessageClearingCode(io::Printer* printer) const override; void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOneofFieldGenerator); }; class RepeatedStringFieldGenerator : public FieldGenerator { public: RepeatedStringFieldGenerator(const FieldDescriptor* descriptor, const Options& options); - RepeatedStringFieldGenerator(const RepeatedStringFieldGenerator&) = delete; - RepeatedStringFieldGenerator& operator=(const RepeatedStringFieldGenerator&) = - delete; ~RepeatedStringFieldGenerator() override; // implements FieldGenerator --------------------------------------- @@ -126,6 +123,9 @@ class RepeatedStringFieldGenerator : public FieldGenerator { void GenerateSerializeWithCachedSizesToArray( io::Printer* printer) const override; void GenerateByteSize(io::Printer* printer) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator); }; } // namespace cpp diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto b/libs/protobuf/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto index 028248e..466a841 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto @@ -61,9 +61,7 @@ message TestConflictingSymbolNames { optional int32 total_size = 6; optional int32 tag = 7; - enum TestEnum { - FOO = 0; - } + enum TestEnum { FOO = 0; } message Data1 { repeated int32 data = 1; } diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.cc b/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.cc index a52280d..e2730d7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.cc @@ -44,12 +44,12 @@ // correctly and produces the interfaces we expect, which is why this test // is written this way. -#include "google/protobuf/compiler/cpp/unittest.h" +#include -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_embed_optimize_for.pb.h" -#include "google/protobuf/unittest_optimize_for.pb.h" -#include "google/protobuf/test_util.h" +#include +#include +#include +#include #define MESSAGE_TEST_NAME MessageTest #define GENERATED_DESCRIPTOR_TEST_NAME GeneratedDescriptorTest @@ -64,7 +64,7 @@ #define UNITTEST_IMPORT ::protobuf_unittest_import // Must include after the above macros. -#include "google/protobuf/compiler/cpp/unittest.inc" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.inc b/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.inc index 1f65a90..0b47176 100644 --- a/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.inc +++ b/libs/protobuf/src/google/protobuf/compiler/cpp/unittest.inc @@ -49,36 +49,37 @@ #include #include -#include "google/protobuf/compiler/cpp/unittest.h" -#include "absl/strings/cord.h" -#include "absl/strings/string_view.h" +#include +#include #ifndef _MSC_VER // We exclude this large proto because it's too large for // visual studio to compile (report internal errors). -#include "google/protobuf/unittest_enormous_descriptor.pb.h" +#include #endif -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/compiler/cpp/helpers.h" -#include "google/protobuf/unittest_no_generic_services.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include #include -#include "absl/base/casts.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/compiler/cpp/test_bad_identifiers.pb.h" -#include "google/protobuf/compiler/importer.h" -#include "google/protobuf/compiler/scc.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/test_util2.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -101,7 +102,7 @@ class MockErrorCollector : public MultiFileErrorCollector { // implements ErrorCollector --------------------------------------- void AddError(const std::string& filename, int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, + strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, message); } }; @@ -601,7 +602,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, UpcastCopyFrom) { TestUtil::SetAllFields(&message1); - const Message* source = absl::implicit_cast(&message1); + const Message* source = implicit_cast(&message1); message2.CopyFrom(*source); TestUtil::ExpectAllFieldsSet(message2); @@ -663,7 +664,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, SerializationToArray) { TestUtil::SetAllFields(&message1); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -677,7 +678,8 @@ TEST(GENERATED_MESSAGE_TEST_NAME, PackedFieldsSerializationToArray) { TestUtil::SetPackedFields(&packed_message1); int packed_size = packed_message1.ByteSizeLong(); packed_data.resize(packed_size); - uint8_t* start = reinterpret_cast(&packed_data[0]); + uint8_t* start = + reinterpret_cast(::google::protobuf::string_as_array(&packed_data)); uint8_t* end = packed_message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(packed_size, end - start); EXPECT_TRUE(packed_message2.ParseFromString(packed_data)); @@ -694,7 +696,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, SerializationToStream) { data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); message1.SerializeWithCachedSizes(&output_stream); EXPECT_FALSE(output_stream.HadError()); @@ -713,7 +715,7 @@ TEST(GENERATED_MESSAGE_TEST_NAME, PackedFieldsSerializationToStream) { data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); message1.SerializeWithCachedSizes(&output_stream); EXPECT_FALSE(output_stream.HadError()); @@ -1820,7 +1822,7 @@ TEST_F(OneofTest, UpcastCopyFrom) { message1.mutable_foogroup()->set_a(123); EXPECT_TRUE(message1.has_foogroup()); - const Message* source = absl::implicit_cast(&message1); + const Message* source = implicit_cast(&message1); message2.CopyFrom(*source); EXPECT_TRUE(message2.has_foogroup()); @@ -1839,7 +1841,7 @@ std::string data; message1.set_foo_int(123); int size = message1.ByteSizeLong(); data.resize(size); -uint8_t* start = reinterpret_cast(&data[0]); +uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1853,7 +1855,7 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_string("foo"); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1868,7 +1870,7 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_bytes("moo"); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1882,7 +1884,7 @@ EXPECT_EQ(message2.foo_int(), 123); message1.set_foo_enum(UNITTEST::TestOneof2::FOO); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1896,7 +1898,7 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foo_message()->set_moo_int(234); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1910,7 +1912,7 @@ EXPECT_EQ(message2.foo_int(), 123); message1.mutable_foogroup()->set_a(345); int size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -1935,11 +1937,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -1956,11 +1958,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -1978,11 +1980,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -1999,11 +2001,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -2020,11 +2022,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -2041,11 +2043,11 @@ data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); - io::CodedOutputStream output_stream(&array_stream); - message1.SerializeWithCachedSizes(&output_stream); - EXPECT_FALSE(output_stream.HadError()); - EXPECT_EQ(size, output_stream.ByteCount()); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); + io::CodedOutputStream output_stream(&array_stream); + message1.SerializeWithCachedSizes(&output_stream); + EXPECT_FALSE(output_stream.HadError()); + EXPECT_EQ(size, output_stream.ByteCount()); } EXPECT_TRUE(message2.ParseFromString(data)); @@ -2221,4 +2223,4 @@ TEST(DESCRIPTOR_INIT_TEST_NAME, Initialized) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/csharp/BUILD.bazel deleted file mode 100644 index 433e0b2..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/BUILD.bazel +++ /dev/null @@ -1,133 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - C# code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "names", - hdrs = ["names.h"], - srcs = ["names.cc"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/csharp", - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "csharp", - srcs = [ - "csharp_doc_comment.cc", - "csharp_enum.cc", - "csharp_enum_field.cc", - "csharp_field_base.cc", - "csharp_generator.cc", - "csharp_helpers.cc", - "csharp_map_field.cc", - "csharp_message.cc", - "csharp_message_field.cc", - "csharp_primitive_field.cc", - "csharp_reflection_class.cc", - "csharp_repeated_enum_field.cc", - "csharp_repeated_message_field.cc", - "csharp_repeated_primitive_field.cc", - "csharp_source_generator_base.cc", - "csharp_wrapper_field.cc", - ], - hdrs = [ - "csharp_doc_comment.h", - "csharp_enum.h", - "csharp_enum_field.h", - "csharp_field_base.h", - "csharp_generator.h", - "csharp_helpers.h", - "csharp_map_field.h", - "csharp_message.h", - "csharp_message_field.h", - "csharp_options.h", - "csharp_primitive_field.h", - "csharp_reflection_class.h", - "csharp_repeated_enum_field.h", - "csharp_repeated_message_field.h", - "csharp_repeated_primitive_field.h", - "csharp_source_generator_base.h", - "csharp_wrapper_field.h", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": ["-Wno-overloaded-virtual"], - }), - include_prefix = "google/protobuf/compiler/csharp", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":names", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "bootstrap_unittest", - srcs = ["csharp_bootstrap_unittest.cc"], - data = [ - "//:well_known_type_protos", - "//conformance:all_files", - "//conformance:conformance_proto", - "//csharp:wkt_cs_srcs", - "//src/google/protobuf:descriptor_proto_srcs", - "//src/google/protobuf:testdata", - ], - deps = [ - ":csharp", - "//:protobuf", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "generator_unittest", - srcs = ["csharp_generator_unittest.cc"], - deps = [ - ":csharp", - "//:protobuf", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/io", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index a477a81..84aacca 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -39,18 +39,19 @@ #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/csharp/csharp_generator.h" -#include "google/protobuf/compiler/importer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" namespace google { namespace protobuf { @@ -69,8 +70,8 @@ class MockErrorCollector : public MultiFileErrorCollector { // implements ErrorCollector --------------------------------------- void AddError(const std::string& filename, int line, int column, const std::string& message) { - absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, - message); + strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", + filename, line, column, message); } }; @@ -177,6 +178,12 @@ TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) { "WellKnownTypes/Wrappers.cs", "../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs"); + generate_test.SetParameter(""); + source_tree.MapPath("", TestSourceDir() + "/../conformance"); + generate_test.Run(importer.Import("conformance.proto"), + "Conformance.cs", + "../csharp/src/Google.Protobuf.Conformance/Conformance.cs"); + EXPECT_EQ("", error_collector.text_); } diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc index 507b826..225d6dc 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc @@ -31,12 +31,10 @@ // Author: kenton@google.com (Kenton Varda) // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" - -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -56,9 +54,10 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) { } // XML escaping... no need for apostrophes etc as the whole text is going to be a child // node of a summary element, not part of an attribute. - comments = absl::StrReplaceAll(comments, {{"&", "&"}, {"<", "<"}}); + comments = StringReplace(comments, "&", "&", true); + comments = StringReplace(comments, "<", "<", true); std::vector lines; - lines = absl::StrSplit(comments, "\n", absl::AllowEmpty()); + lines = Split(comments, "\n", false); // TODO: We really should work out which part to put in the summary and which to put in the remarks... // but that needs to be part of a bigger effort to understand the markdown better anyway. printer->Print("/// \n"); diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h index 40c35ec..75eb0ea 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h @@ -32,8 +32,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_DOC_COMMENT_H__ -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc index 846da9b..73679ca 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc @@ -28,18 +28,19 @@ // (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/compiler/csharp/csharp_enum.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { @@ -56,9 +57,6 @@ EnumGenerator::~EnumGenerator() { void EnumGenerator::Generate(io::Printer* printer) { WriteEnumDocComment(printer, descriptor_); - if (descriptor_->options().deprecated()) { - printer->Print("[global::System.ObsoleteAttribute]\n"); - } printer->Print("$access_level$ enum $name$ {\n", "access_level", class_access_level(), "name", descriptor_->name()); @@ -67,9 +65,6 @@ void EnumGenerator::Generate(io::Printer* printer) { std::set used_number; for (int i = 0; i < descriptor_->value_count(); i++) { WriteEnumValueDocComment(printer, descriptor_->value(i)); - if (descriptor_->value(i)->options().deprecated()) { - printer->Print("[global::System.ObsoleteAttribute]\n"); - } std::string original_name = descriptor_->value(i)->name(); std::string name = GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name()); @@ -85,12 +80,12 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print("[pbr::OriginalName(\"$original_name$\", PreferredAlias = false)] $name$ = $number$,\n", "original_name", original_name, "name", name, - "number", absl::StrCat(number)); + "number", StrCat(number)); } else { printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$,\n", "original_name", original_name, "name", name, - "number", absl::StrCat(number)); + "number", StrCat(number)); } } printer->Outdent(); diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h index 098102b..e409c2e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h @@ -33,10 +33,10 @@ #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc index 065e1cc..55fb60c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc @@ -28,18 +28,18 @@ // (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/compiler/csharp/csharp_enum_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h index c31d55f..0c6b023 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_primitive_field.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc index bc45d74..17847e3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -28,23 +28,22 @@ // (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/compiler/csharp/csharp_field_base.h" - #include #include #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" +#include +#include +#include namespace google { namespace protobuf { @@ -64,13 +63,13 @@ void FieldGeneratorBase::SetCommonFieldVariables( uint tag = internal::WireFormat::MakeTag(descriptor_); uint8_t tag_array[5]; io::CodedOutputStream::WriteTagToArray(tag, tag_array); - std::string tag_bytes = absl::StrCat(tag_array[0]); + std::string tag_bytes = StrCat(tag_array[0]); for (int i = 1; i < part_tag_size; i++) { - tag_bytes += ", " + absl::StrCat(tag_array[i]); + tag_bytes += ", " + StrCat(tag_array[i]); } - (*variables)["tag"] = absl::StrCat(tag); - (*variables)["tag_size"] = absl::StrCat(tag_size); + (*variables)["tag"] = StrCat(tag); + (*variables)["tag_size"] = StrCat(tag_size); (*variables)["tag_bytes"] = tag_bytes; if (descriptor_->type() == FieldDescriptor::Type::TYPE_GROUP) { @@ -78,12 +77,12 @@ void FieldGeneratorBase::SetCommonFieldVariables( descriptor_->number(), internal::WireFormatLite::WIRETYPE_END_GROUP); io::CodedOutputStream::WriteTagToArray(tag, tag_array); - tag_bytes = absl::StrCat(tag_array[0]); + tag_bytes = StrCat(tag_array[0]); for (int i = 1; i < part_tag_size; i++) { - tag_bytes += ", " + absl::StrCat(tag_array[i]); + tag_bytes += ", " + StrCat(tag_array[i]); } - variables_["end_tag"] = absl::StrCat(tag); + variables_["end_tag"] = StrCat(tag); variables_["end_tag_bytes"] = tag_bytes; } @@ -109,8 +108,8 @@ void FieldGeneratorBase::SetCommonFieldVariables( (*variables)["has_not_property_check"] = "!" + (*variables)["has_property_check"]; (*variables)["other_has_not_property_check"] = "!" + (*variables)["other_has_property_check"]; if (presenceIndex_ != -1) { - std::string hasBitsNumber = absl::StrCat(presenceIndex_ / 32); - std::string hasBitsMask = absl::StrCat(1 << (presenceIndex_ % 32)); + std::string hasBitsNumber = StrCat(presenceIndex_ / 32); + std::string hasBitsMask = StrCat(1 << (presenceIndex_ % 32)); (*variables)["has_field_check"] = "(_hasBits" + hasBitsNumber + " & " + hasBitsMask + ") != 0"; (*variables)["set_has_field"] = "_hasBits" + hasBitsNumber + " |= " + hasBitsMask; (*variables)["clear_has_field"] = "_hasBits" + hasBitsNumber + " &= ~" + hasBitsMask; @@ -326,7 +325,7 @@ std::string FieldGeneratorBase::GetStringDefaultValueInternal(const FieldDescrip else return "global::System.Text.Encoding.UTF8.GetString(global::System." "Convert.FromBase64String(\"" + - StringToBase64(descriptor->default_value_string()) + "\"), 0, " + absl::StrCat(descriptor->default_value_string().length()) + ")"; + StringToBase64(descriptor->default_value_string()) + "\"), 0, " + StrCat(descriptor->default_value_string().length()) + ")"; } std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) { @@ -362,7 +361,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) } else if (std::isnan(value)) { return "double.NaN"; } - return absl::StrCat(value) + "D"; + return StrCat(value) + "D"; } case FieldDescriptor::TYPE_FLOAT: { float value = descriptor->default_value_float(); @@ -373,18 +372,18 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) } else if (std::isnan(value)) { return "float.NaN"; } - return absl::StrCat(value) + "F"; + return StrCat(value) + "F"; } case FieldDescriptor::TYPE_INT64: - return absl::StrCat(descriptor->default_value_int64()) + "L"; + return StrCat(descriptor->default_value_int64()) + "L"; case FieldDescriptor::TYPE_UINT64: - return absl::StrCat(descriptor->default_value_uint64()) + "UL"; + return StrCat(descriptor->default_value_uint64()) + "UL"; case FieldDescriptor::TYPE_INT32: - return absl::StrCat(descriptor->default_value_int32()); + return StrCat(descriptor->default_value_int32()); case FieldDescriptor::TYPE_FIXED64: - return absl::StrCat(descriptor->default_value_uint64()) + "UL"; + return StrCat(descriptor->default_value_uint64()) + "UL"; case FieldDescriptor::TYPE_FIXED32: - return absl::StrCat(descriptor->default_value_uint32()); + return StrCat(descriptor->default_value_uint32()); case FieldDescriptor::TYPE_BOOL: if (descriptor->default_value_bool()) { return "true"; @@ -396,15 +395,15 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) case FieldDescriptor::TYPE_BYTES: return GetBytesDefaultValueInternal(descriptor); case FieldDescriptor::TYPE_UINT32: - return absl::StrCat(descriptor->default_value_uint32()); + return StrCat(descriptor->default_value_uint32()); case FieldDescriptor::TYPE_SFIXED32: - return absl::StrCat(descriptor->default_value_int32()); + return StrCat(descriptor->default_value_int32()); case FieldDescriptor::TYPE_SFIXED64: - return absl::StrCat(descriptor->default_value_int64()) + "L"; + return StrCat(descriptor->default_value_int64()) + "L"; case FieldDescriptor::TYPE_SINT32: - return absl::StrCat(descriptor->default_value_int32()); + return StrCat(descriptor->default_value_int32()); case FieldDescriptor::TYPE_SINT64: - return absl::StrCat(descriptor->default_value_int64()) + "L"; + return StrCat(descriptor->default_value_int64()) + "L"; default: GOOGLE_LOG(FATAL)<< "Unknown field type."; return ""; @@ -412,7 +411,7 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor) } std::string FieldGeneratorBase::number() { - return absl::StrCat(descriptor_->number()); + return StrCat(descriptor_->number()); } std::string FieldGeneratorBase::capitalized_type_name() { @@ -463,5 +462,3 @@ std::string FieldGeneratorBase::capitalized_type_name() { } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h index b2ad2c2..c7b7469 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -32,16 +32,12 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_FIELD_BASE_H__ #include +#include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc index 0152072..5ce0651 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -28,19 +28,20 @@ // (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/compiler/csharp/csharp_generator.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/compiler/csharp/csharp_reflection_class.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h index ea2746e..f41f9b8 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h @@ -35,9 +35,9 @@ #include -#include "google/protobuf/compiler/code_generator.h" +#include -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -65,6 +65,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc index ca4fb9d..e21eff1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc @@ -30,13 +30,14 @@ #include -#include "google/protobuf/any.pb.h" -#include "google/protobuf/compiler/command_line_interface.h" +#include +#include +#include +#include +#include +#include + #include -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" namespace google { namespace protobuf { @@ -73,22 +74,6 @@ TEST(DescriptorProtoHelpers, IsDescriptorOptionMessage) { EXPECT_FALSE(IsDescriptorOptionMessage(DescriptorProto::descriptor())); } -TEST(CSharpIdentifiers, UnderscoresToCamelCase) { - EXPECT_EQ("FooBar", UnderscoresToCamelCase("Foo_Bar", true)); - EXPECT_EQ("fooBar", UnderscoresToCamelCase("FooBar", false)); - EXPECT_EQ("foo123", UnderscoresToCamelCase("foo_123", false)); - // remove leading underscores - EXPECT_EQ("Foo123", UnderscoresToCamelCase("_Foo_123", true)); - // this one has slight unexpected output as it capitalises the first - // letter after consuming the underscores, but this was the existing - // behaviour so I have not changed it - EXPECT_EQ("FooBar", UnderscoresToCamelCase("___fooBar", false)); - // leave a leading underscore for identifiers that would otherwise - // be invalid because they would start with a digit - EXPECT_EQ("_123Foo", UnderscoresToCamelCase("_123_foo", true)); - EXPECT_EQ("_123Foo", UnderscoresToCamelCase("___123_foo", true)); -} - } // namespace } // namespace csharp } // namespace compiler diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 1ff5444..73ca868 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -32,32 +32,28 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/csharp/csharp_helpers.h" - #include #include -#include #include +#include -#include "absl/container/flat_hash_set.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/compiler/csharp/csharp_enum_field.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" -#include "google/protobuf/compiler/csharp/csharp_map_field.h" -#include "google/protobuf/compiler/csharp/csharp_message_field.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/compiler/csharp/csharp_primitive_field.h" -#include "google/protobuf/compiler/csharp/csharp_repeated_enum_field.h" -#include "google/protobuf/compiler/csharp/csharp_repeated_message_field.h" -#include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h" -#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -110,6 +106,84 @@ CSharpType GetCSharpType(FieldDescriptor::Type type) { return (CSharpType) -1; } +std::string StripDotProto(const std::string& proto_file) { + int lastindex = proto_file.find_last_of("."); + return proto_file.substr(0, lastindex); +} + +std::string GetFileNamespace(const FileDescriptor* descriptor) { + if (descriptor->options().has_csharp_namespace()) { + return descriptor->options().csharp_namespace(); + } + return UnderscoresToCamelCase(descriptor->package(), true, true); +} + +// Returns the Pascal-cased last part of the proto file. For example, +// input of "google/protobuf/foo_bar.proto" would result in "FooBar". +std::string GetFileNameBase(const FileDescriptor* descriptor) { + std::string proto_file = descriptor->name(); + int lastslash = proto_file.find_last_of("/"); + std::string base = proto_file.substr(lastslash + 1); + return UnderscoresToPascalCase(StripDotProto(base)); +} + +std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor) { + // TODO: Detect collisions with existing messages, + // and append an underscore if necessary. + return GetFileNameBase(descriptor) + "Reflection"; +} + +std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor) { + // TODO: Detect collisions with existing messages, + // and append an underscore if necessary. + return GetFileNameBase(descriptor) + "Extensions"; +} + +// TODO(jtattermusch): can we reuse a utility function? +std::string UnderscoresToCamelCase(const std::string& input, + bool cap_next_letter, + bool preserve_period) { + std::string result; + // Note: I distrust ctype.h due to locales. + for (int i = 0; i < input.size(); i++) { + if ('a' <= input[i] && input[i] <= 'z') { + if (cap_next_letter) { + result += input[i] + ('A' - 'a'); + } else { + result += input[i]; + } + cap_next_letter = false; + } else if ('A' <= input[i] && input[i] <= 'Z') { + if (i == 0 && !cap_next_letter) { + // Force first letter to lower-case unless explicitly told to + // capitalize it. + result += input[i] + ('a' - 'A'); + } else { + // Capital letters after the first are left as-is. + result += input[i]; + } + cap_next_letter = false; + } else if ('0' <= input[i] && input[i] <= '9') { + result += input[i]; + cap_next_letter = true; + } else { + cap_next_letter = true; + if (input[i] == '.' && preserve_period) { + result += '.'; + } + } + } + // Add a trailing "_" if the name should be altered. + if (input.size() > 0 && input[input.size() - 1] == '#') { + result += '_'; + } + return result; +} + +std::string UnderscoresToPascalCase(const std::string& input) { + return UnderscoresToCamelCase(input, true); +} + // Convert a string which is expected to be SHOUTY_CASE (but may not be *precisely* shouty) // into a PascalCase string. Precise rules implemented: @@ -126,18 +200,18 @@ std::string ShoutyToPascalCase(const std::string& input) { char previous = '_'; for (int i = 0; i < input.size(); i++) { char current = input[i]; - if (!absl::ascii_isalnum(current)) { + if (!ascii_isalnum(current)) { previous = current; continue; } - if (!absl::ascii_isalnum(previous)) { - result += absl::ascii_toupper(current); - } else if (absl::ascii_isdigit(previous)) { - result += absl::ascii_toupper(current); - } else if (absl::ascii_islower(previous)) { + if (!ascii_isalnum(previous)) { + result += ascii_toupper(current); + } else if (ascii_isdigit(previous)) { + result += ascii_toupper(current); + } else if (ascii_islower(previous)) { result += current; } else { - result += absl::ascii_tolower(current); + result += ascii_tolower(current); } previous = current; } @@ -155,7 +229,7 @@ std::string TryRemovePrefix(const std::string& prefix, const std::string& value) std::string prefix_to_match = ""; for (size_t i = 0; i < prefix.size(); i++) { if (prefix[i] != '_') { - prefix_to_match += absl::ascii_tolower(prefix[i]); + prefix_to_match += ascii_tolower(prefix[i]); } } @@ -168,7 +242,7 @@ std::string TryRemovePrefix(const std::string& prefix, const std::string& value) if (value[value_index] == '_') { continue; } - if (absl::ascii_tolower(value[value_index]) != prefix_to_match[prefix_index++]) { + if (ascii_tolower(value[value_index]) != prefix_to_match[prefix_index++]) { // Failed to match the prefix - bail out early. return value; } @@ -202,7 +276,7 @@ std::string GetEnumValueName(const std::string& enum_name, const std::string& en std::string result = ShoutyToPascalCase(stripped); // Just in case we have an enum name of FOO and a value of FOO_2... make sure the returned // string is a valid identifier. - if (absl::ascii_isdigit(result[0])) { + if (ascii_isdigit(result[0])) { result = "_" + result; } return result; @@ -246,6 +320,32 @@ uint GetGroupEndTag(const Descriptor* descriptor) { return 0; } +std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { + std::string result = GetFileNamespace(file); + if (!result.empty()) { + result += '.'; + } + std::string classname; + if (file->package().empty()) { + classname = name; + } else { + // Strip the proto package from full_name since we've replaced it with + // the C# namespace. + classname = name.substr(file->package().size() + 1); + } + result += StringReplace(classname, ".", ".Types.", true); + return "global::" + result; +} + +std::string GetReflectionClassName(const FileDescriptor* descriptor) { + std::string result = GetFileNamespace(descriptor); + if (!result.empty()) { + result += '.'; + } + result += GetReflectionClassUnqualifiedName(descriptor); + return "global::" + result; +} + std::string GetFullExtensionName(const FieldDescriptor* descriptor) { if (descriptor->extension_scope()) { return GetClassName(descriptor->extension_scope()) + ".Extensions." + GetPropertyName(descriptor); @@ -255,6 +355,14 @@ std::string GetFullExtensionName(const FieldDescriptor* descriptor) { } } +std::string GetClassName(const Descriptor* descriptor) { + return ToCSharpName(descriptor->full_name(), descriptor->file()); +} + +std::string GetClassName(const EnumDescriptor* descriptor) { + return ToCSharpName(descriptor->full_name(), descriptor->file()); +} + // Groups are hacky: The name of the field is just the lower-cased name // of the group type. In C#, though, we would like to retain the original // capitalization of the type name. @@ -271,30 +379,15 @@ std::string GetFieldConstantName(const FieldDescriptor* field) { } std::string GetPropertyName(const FieldDescriptor* descriptor) { - // Names of members declared or overridden in the message. - static const auto& reserved_member_names = *new absl::flat_hash_set({ - "Types", - "Descriptor", - "Equals", - "ToString", - "GetHashCode", - "WriteTo", - "Clone", - "CalculateSize", - "MergeFrom", - "OnConstruction", - "Parser" - }); - // TODO(jtattermusch): consider introducing csharp_property_name field option std::string property_name = UnderscoresToPascalCase(GetFieldName(descriptor)); - // Avoid either our own type name or reserved names. + // Avoid either our own type name or reserved names. Note that not all names + // are reserved - a field called to_string, write_to etc would still cause a problem. // There are various ways of ending up with naming collisions, but we try to avoid obvious - // ones. In particular, we avoid the names of all the members we generate. - // Note that we *don't* add an underscore for MemberwiseClone or GetType. Those generate - // warnings, but not errors; changing the name now could be a breaking change. + // ones. if (property_name == descriptor->containing_type()->name() - || reserved_member_names.find(property_name) != reserved_member_names.end()) { + || property_name == "Types" + || property_name == "Descriptor") { property_name += "_"; } return property_name; @@ -307,6 +400,40 @@ std::string GetOneofCaseName(const FieldDescriptor* descriptor) { return property_name == "None" ? "None_" : property_name; } +std::string GetOutputFile(const FileDescriptor* descriptor, + const std::string file_extension, + const bool generate_directories, + const std::string base_namespace, + std::string* error) { + std::string relative_filename = GetFileNameBase(descriptor) + file_extension; + if (!generate_directories) { + return relative_filename; + } + std::string ns = GetFileNamespace(descriptor); + std::string namespace_suffix = ns; + if (!base_namespace.empty()) { + // Check that the base_namespace is either equal to or a leading part of + // the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't + // be regarded as a prefix of "Foo.Bar". The simplest option is to add "." + // to both. + std::string extended_ns = ns + "."; + if (extended_ns.find(base_namespace + ".") != 0) { + *error = "Namespace " + ns + " is not a prefix namespace of base namespace " + base_namespace; + return ""; // This will be ignored, because we've set an error. + } + namespace_suffix = ns.substr(base_namespace.length()); + if (namespace_suffix.find(".") == 0) { + namespace_suffix = namespace_suffix.substr(1); + } + } + + std::string namespace_dir = StringReplace(namespace_suffix, ".", "/", true); + if (!namespace_dir.empty()) { + namespace_dir += "/"; + } + return namespace_dir + relative_filename; +} + // TODO: c&p from Java protoc plugin // For encodings with fixed sizes, returns that size in bytes. Otherwise // returns -1. @@ -470,5 +597,3 @@ bool IsNullable(const FieldDescriptor* descriptor) { } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h index b9aa556..836bd5d 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -36,15 +36,14 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__ #include +#include +#include +#include +#include +#include +#include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/port.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -73,6 +72,15 @@ enum CSharpType { // Converts field type to corresponding C# type. CSharpType GetCSharpType(FieldDescriptor::Type type); +std::string StripDotProto(const std::string& proto_file); + +// Gets unqualified name of the reflection class +std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor); +// Gets unqualified name of the extension class +std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor); + +std::string GetClassName(const EnumDescriptor* descriptor); + std::string GetFieldName(const FieldDescriptor* descriptor); std::string GetFieldConstantName(const FieldDescriptor* field); @@ -83,6 +91,16 @@ std::string GetOneofCaseName(const FieldDescriptor* descriptor); int GetFixedSize(FieldDescriptor::Type type); +std::string UnderscoresToCamelCase(const std::string& input, + bool cap_next_letter, + bool preserve_period); + +inline std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter) { + return UnderscoresToCamelCase(input, cap_next_letter, false); +} + +std::string UnderscoresToPascalCase(const std::string& input); + // Note that we wouldn't normally want to export this (we're not expecting // it to be used outside libprotoc itself) but this exposes it for testing. std::string PROTOC_EXPORT GetEnumValueName(const std::string& enum_name, @@ -175,6 +193,6 @@ inline bool RequiresPresenceBit(const FieldDescriptor* descriptor) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_HELPERS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc index 50d8b1d..a13b995 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -28,16 +28,18 @@ // (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/compiler/csharp/csharp_map_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include namespace google { namespace protobuf { @@ -88,7 +90,7 @@ void MapFieldGenerator::GenerateMembers(io::Printer* printer) { void MapFieldGenerator::GenerateMergingCode(io::Printer* printer) { printer->Print( variables_, - "$name$_.MergeFrom(other.$name$_);\n"); + "$name$_.Add(other.$name$_);\n"); } void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h index c4713d0..23b3619 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc index bdbd480..a119bdd 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -28,28 +28,26 @@ // (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/compiler/csharp/csharp_message.h" - +#include #include #include -#include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_enum.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -163,7 +161,7 @@ void MessageGenerator::Generate(io::Printer* printer) { for (int i = 0; i < has_bit_field_count_; i++) { // don't use arrays since all arrays are heap allocated, saving allocations // use ints instead of bytes since bytes lack bitwise operators, saving casts - printer->Print("private int _hasBits$i$;\n", "i", absl::StrCat(i)); + printer->Print("private int _hasBits$i$;\n", "i", StrCat(i)); } WriteGeneratedCodeAttributes(printer); @@ -175,10 +173,10 @@ void MessageGenerator::Generate(io::Printer* printer) { // Access the message descriptor via the relevant file descriptor or containing message descriptor. if (!descriptor_->containing_type()) { vars["descriptor_accessor"] = GetReflectionClassName(descriptor_->file()) - + ".Descriptor.MessageTypes[" + absl::StrCat(descriptor_->index()) + "]"; + + ".Descriptor.MessageTypes[" + StrCat(descriptor_->index()) + "]"; } else { vars["descriptor_accessor"] = GetClassName(descriptor_->containing_type()) - + ".Descriptor.NestedTypes[" + absl::StrCat(descriptor_->index()) + "]"; + + ".Descriptor.NestedTypes[" + StrCat(descriptor_->index()) + "]"; } WriteGeneratedCodeAttributes(printer); @@ -218,7 +216,7 @@ void MessageGenerator::Generate(io::Printer* printer) { "public const int $field_constant_name$ = $index$;\n", "field_name", fieldDescriptor->name(), "field_constant_name", GetFieldConstantName(fieldDescriptor), - "index", absl::StrCat(fieldDescriptor->number())); + "index", StrCat(fieldDescriptor->number())); std::unique_ptr generator( CreateFieldGeneratorInternal(fieldDescriptor)); generator->GenerateMembers(printer); @@ -242,7 +240,7 @@ void MessageGenerator::Generate(io::Printer* printer) { const FieldDescriptor* field = oneof->field(j); printer->Print("$oneof_case_name$ = $index$,\n", "oneof_case_name", GetOneofCaseName(field), - "index", absl::StrCat(field->number())); + "index", StrCat(field->number())); } printer->Outdent(); printer->Print("}\n"); @@ -384,7 +382,7 @@ void MessageGenerator::GenerateCloningCode(io::Printer* printer) { "public $class_name$($class_name$ other) : this() {\n"); printer->Indent(); for (int i = 0; i < has_bit_field_count_; i++) { - printer->Print("_hasBits$i$ = other._hasBits$i$;\n", "i", absl::StrCat(i)); + printer->Print("_hasBits$i$ = other._hasBits$i$;\n", "i", StrCat(i)); } // Clone non-oneof fields first (treating optional proto3 fields as non-oneof) for (int i = 0; i < descriptor_->field_count(); i++) { @@ -700,7 +698,7 @@ void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_pars printer->Print( "case $end_tag$:\n" " return;\n", - "end_tag", absl::StrCat(end_tag_)); + "end_tag", StrCat(end_tag_)); } if (has_extension_ranges_) { printer->Print(vars, @@ -729,13 +727,13 @@ void MessageGenerator::GenerateMainParseLoop(io::Printer* printer, bool use_pars printer->Print( "case $packed_tag$:\n", "packed_tag", - absl::StrCat( + StrCat( internal::WireFormatLite::MakeTag( field->number(), internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED))); } - printer->Print("case $tag$: {\n", "tag", absl::StrCat(tag)); + printer->Print("case $tag$: {\n", "tag", StrCat(tag)); printer->Indent(); std::unique_ptr generator( CreateFieldGeneratorInternal(field)); @@ -779,5 +777,3 @@ FieldGeneratorBase* MessageGenerator::CreateFieldGeneratorInternal( } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h index 86025dc..d02767e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h @@ -34,9 +34,9 @@ #include #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc index 1f30bdc..487d01d 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc @@ -28,17 +28,21 @@ // (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/compiler/csharp/csharp_message_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h index fbbe4c4..e76dfd2 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/names.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h similarity index 70% rename from libs/protobuf/src/google/protobuf/compiler/csharp/names.h rename to libs/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h index 4826ea0..67e53b6 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/names.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h @@ -39,8 +39,10 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ #include +#include +#include -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -71,35 +73,9 @@ std::string PROTOC_EXPORT GetClassName(const Descriptor* descriptor); // descriptor != NULL // // Returns: -// The fully-qualified C# enum class name. -std::string GetClassName(const EnumDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The unqualified name of the C# class that provides access to the file -// descriptor. Proto compiler generates +// The fully-qualified name of the C# class that provides +// access to the file descriptor. Proto compiler generates // such class for each .proto file processed. -std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor); - -// Gets unqualified name of the extension class -// Requires: -// descriptor != NULL -// -// Returns: -// The unqualified name of the generated C# extensions class that provide -// access to extensions. Proto compiler generates such class for each -// .proto file processed that contains extensions. -std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified name of the C# class that provides access to the file -// descriptor. Proto compiler generates such class for each .proto file -// processed. std::string PROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor); @@ -123,23 +99,11 @@ std::string PROTOC_EXPORT GetOutputFile(const FileDescriptor* descriptor, const std::string base_namespace, std::string* error); -std::string UnderscoresToPascalCase(const std::string& input); - -// Note that we wouldn't normally want to export this (we're not expecting -// it to be used outside libprotoc itself) but this exposes it for testing. -std::string PROTOC_EXPORT UnderscoresToCamelCase(const std::string& input, - bool cap_next_letter, - bool preserve_period); - -inline std::string UnderscoresToCamelCase(const std::string& input, bool cap_next_letter) { - return UnderscoresToCamelCase(input, cap_next_letter, false); -} - } // namespace csharp } // namespace compiler } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index 1467bd3..e7d5116 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -28,18 +28,19 @@ // (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/compiler/csharp/csharp_primitive_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { @@ -214,7 +215,7 @@ void PrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { } else { printer->Print( "size += $tag_size$ + $fixed_size$;\n", - "fixed_size", absl::StrCat(fixedSize), + "fixed_size", StrCat(fixedSize), "tag_size", variables_["tag_size"]); } printer->Outdent(); diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index d6fb715..6d495d5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc index c6d6cd0..d9ab4b4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc @@ -28,24 +28,23 @@ // (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/compiler/csharp/csharp_reflection_class.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/str_join.h" -#include "google/protobuf/compiler/csharp/csharp_enum.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_message.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" + +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -214,7 +213,7 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) { for (int i = 0; i < file_->extension_count(); i++) { extensions.push_back(GetFullExtensionName(file_->extension(i))); } - printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", absl::StrJoin(extensions, ", ")); + printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", Join(extensions, ", ")); } else { printer->Print("null, "); @@ -266,7 +265,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript for (int i = 0; i < descriptor->field_count(); i++) { fields.push_back(GetPropertyName(descriptor->field(i))); } - printer->Print("new[]{ \"$fields$\" }, ", "fields", absl::StrJoin(fields, "\", \"")); + printer->Print("new[]{ \"$fields$\" }, ", "fields", Join(fields, "\", \"")); } else { printer->Print("null, "); @@ -279,7 +278,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript for (int i = 0; i < descriptor->oneof_decl_count(); i++) { oneofs.push_back(UnderscoresToCamelCase(descriptor->oneof_decl(i)->name(), true)); } - printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs", absl::StrJoin(oneofs, "\", \"")); + printer->Print("new[]{ \"$oneofs$\" }, ", "oneofs", Join(oneofs, "\", \"")); } else { printer->Print("null, "); @@ -292,7 +291,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript for (int i = 0; i < descriptor->enum_type_count(); i++) { enums.push_back(GetClassName(descriptor->enum_type(i))); } - printer->Print("new[]{ typeof($enums$) }, ", "enums", absl::StrJoin(enums, "), typeof(")); + printer->Print("new[]{ typeof($enums$) }, ", "enums", Join(enums, "), typeof(")); } else { printer->Print("null, "); @@ -304,7 +303,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript for (int i = 0; i < descriptor->extension_count(); i++) { extensions.push_back(GetFullExtensionName(descriptor->extension(i))); } - printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", absl::StrJoin(extensions, ", ")); + printer->Print("new pb::Extension[] { $extensions$ }, ", "extensions", Join(extensions, ", ")); } else { printer->Print("null, "); @@ -329,5 +328,3 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h index daffb32..9554727 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h @@ -33,10 +33,10 @@ #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_source_generator_base.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc index 1a9fd1d..04bc7bb 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc @@ -28,18 +28,18 @@ // (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/compiler/csharp/csharp_repeated_enum_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h index 08ce992..2379f38 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc index 6ac7e2d..8a93cd1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc @@ -28,19 +28,19 @@ // (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/compiler/csharp/csharp_repeated_message_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_message_field.h" -#include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h index f2c935a..026efea 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc index df97ccf..0eacf91 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc @@ -28,18 +28,18 @@ // (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/compiler/csharp/csharp_repeated_primitive_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h index 92485a2..bdd12a0 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc index f12db82..7157e6e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc @@ -28,18 +28,18 @@ // (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/compiler/csharp/csharp_source_generator_base.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h index 01b0187..17a5269 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h @@ -33,8 +33,8 @@ #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc index 2569082..e638dd8 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc @@ -28,18 +28,18 @@ // (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/compiler/csharp/csharp_wrapper_field.h" - #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/csharp/csharp_doc_comment.h" -#include "google/protobuf/compiler/csharp/csharp_helpers.h" -#include "google/protobuf/compiler/csharp/csharp_options.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h index 6b15aa0..cc8a313 100644 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/csharp/csharp_field_base.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/csharp/names.cc b/libs/protobuf/src/google/protobuf/compiler/csharp/names.cc deleted file mode 100644 index b4ca408..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/csharp/names.cc +++ /dev/null @@ -1,225 +0,0 @@ -// 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. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#include "google/protobuf/compiler/csharp/names.h" - -#include - -#include "absl/strings/str_replace.h" -#include "google/protobuf/compiler/csharp/names.h" -#include "google/protobuf/descriptor.pb.h" - -// Must be last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace csharp { - -namespace { - -std::string StripDotProto(const std::string& proto_file) { - int lastindex = proto_file.find_last_of('.'); - return proto_file.substr(0, lastindex); -} - -// Returns the Pascal-cased last part of the proto file. For example, -// input of "google/protobuf/foo_bar.proto" would result in "FooBar". -std::string GetFileNameBase(const FileDescriptor* descriptor) { - std::string proto_file = descriptor->name(); - int lastslash = proto_file.find_last_of('/'); - std::string base = proto_file.substr(lastslash + 1); - return UnderscoresToPascalCase(StripDotProto(base)); -} - -std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { - std::string result = GetFileNamespace(file); - if (!result.empty()) { - result += '.'; - } - std::string classname; - if (file->package().empty()) { - classname = name; - } else { - // Strip the proto package from full_name since we've replaced it with - // the C# namespace. - classname = name.substr(file->package().size() + 1); - } - result += absl::StrReplaceAll(classname, {{".", ".Types."}}); - return "global::" + result; -} - -} // namespace - -std::string GetFileNamespace(const FileDescriptor* descriptor) { - if (descriptor->options().has_csharp_namespace()) { - return descriptor->options().csharp_namespace(); - } - return UnderscoresToCamelCase(descriptor->package(), true, true); -} - -std::string GetClassName(const Descriptor* descriptor) { - return ToCSharpName(descriptor->full_name(), descriptor->file()); -} - -std::string GetClassName(const EnumDescriptor* descriptor) { - return ToCSharpName(descriptor->full_name(), descriptor->file()); -} - -std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor) { - // TODO: Detect collisions with existing messages, - // and append an underscore if necessary. - return GetFileNameBase(descriptor) + "Reflection"; -} - -std::string GetReflectionClassName(const FileDescriptor* descriptor) { - std::string result = GetFileNamespace(descriptor); - if (!result.empty()) { - result += '.'; - } - result += GetReflectionClassUnqualifiedName(descriptor); - return "global::" + result; -} - -std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor) { - // TODO: Detect collisions with existing messages, - // and append an underscore if necessary. - return GetFileNameBase(descriptor) + "Extensions"; -} - -std::string GetOutputFile(const FileDescriptor* descriptor, - const std::string file_extension, - const bool generate_directories, - const std::string base_namespace, - std::string* error) { - std::string relative_filename = GetFileNameBase(descriptor) + file_extension; - if (!generate_directories) { - return relative_filename; - } - std::string ns = GetFileNamespace(descriptor); - std::string namespace_suffix = ns; - if (!base_namespace.empty()) { - // Check that the base_namespace is either equal to or a leading part of - // the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't - // be regarded as a prefix of "Foo.Bar". The simplest option is to add "." - // to both. - std::string extended_ns = ns + "."; - if (extended_ns.find(base_namespace + ".") != 0) { - *error = "Namespace " + ns + " is not a prefix namespace of base namespace " + base_namespace; - return ""; // This will be ignored, because we've set an error. - } - namespace_suffix = ns.substr(base_namespace.length()); - if (namespace_suffix.find('.') == 0) { - namespace_suffix = namespace_suffix.substr(1); - } - } - - std::string namespace_dir = - absl::StrReplaceAll(namespace_suffix, {{".", "/"}}); - if (!namespace_dir.empty()) { - namespace_dir += "/"; - } - return namespace_dir + relative_filename; -} - -std::string UnderscoresToPascalCase(const std::string& input) { - return UnderscoresToCamelCase(input, true); -} - -// TODO(jtattermusch): can we reuse a utility function? -std::string UnderscoresToCamelCase(const std::string& input, - bool cap_next_letter, - bool preserve_period) { - std::string result; - - // Note: I distrust ctype.h due to locales. - for (int i = 0; i < input.size(); i++) { - if ('a' <= input[i] && input[i] <= 'z') { - if (cap_next_letter) { - result += input[i] + ('A' - 'a'); - } else { - result += input[i]; - } - cap_next_letter = false; - } else if ('A' <= input[i] && input[i] <= 'Z') { - if (i == 0 && !cap_next_letter) { - // Force first letter to lower-case unless explicitly told to - // capitalize it. - result += input[i] + ('a' - 'A'); - } else { - // Capital letters after the first are left as-is. - result += input[i]; - } - cap_next_letter = false; - } else if ('0' <= input[i] && input[i] <= '9') { - result += input[i]; - cap_next_letter = true; - } else { - cap_next_letter = true; - if (input[i] == '.' && preserve_period) { - result += '.'; - } - } - } - // Add a trailing "_" if the name should be altered. - if (input.size() > 0 && input[input.size() - 1] == '#') { - result += '_'; - } - - // https://github.com/protocolbuffers/protobuf/issues/8101 - // To avoid generating invalid identifiers - if the input string - // starts with _ (or multiple underscores then digit) then - // we need to preserve the underscore as an identifier cannot start - // with a digit. - // This check is being done after the loop rather than before - // to handle the case where there are multiple underscores before the - // first digit. We let them all be consumed so we can see if we would - // start with a digit. - // Note: not preserving leading underscores for all otherwise valid identifiers - // so as to not break anything that relies on the existing behaviour - if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') - && input.size() > 0 && input[0] == '_') - { - result.insert(0, 1, '_'); - } - return result; -} - -} // namespace csharp -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/importer.cc b/libs/protobuf/src/google/protobuf/compiler/importer.cc index a2de7e5..f1e26f8 100644 --- a/libs/protobuf/src/google/protobuf/compiler/importer.cc +++ b/libs/protobuf/src/google/protobuf/compiler/importer.cc @@ -32,8 +32,6 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/importer.h" - #ifdef _MSC_VER #include #else @@ -46,17 +44,13 @@ #include #include -#include -#include "absl/strings/match.h" -#include "absl/strings/str_join.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/compiler/parser.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include +#include +#include +#include #ifdef _WIN32 #include @@ -76,7 +70,7 @@ using google::protobuf::io::win32::open; // Returns true if the text looks like a Windows-style absolute path, starting // with a drive letter. Example: "C:\foo". TODO(kenton): Share this with // copy in command_line_interface.cc? -static bool IsWindowsAbsolutePath(absl::string_view text) { +static bool IsWindowsAbsolutePath(const std::string& text) { #if defined(_WIN32) || defined(__CYGWIN__) return text.size() >= 3 && text[1] == ':' && isalpha(text[0]) && (text[2] == '/' || text[2] == '\\') && text.find_last_of(':') == 1; @@ -257,6 +251,10 @@ DiskSourceTree::DiskSourceTree() {} DiskSourceTree::~DiskSourceTree() {} +static inline char LastChar(const std::string& str) { + return str[str.size() - 1]; +} + // Given a path, returns an equivalent path with these changes: // - On Windows, any backslashes are replaced with forward slashes. // - Any instances of the directory "." are removed. @@ -276,38 +274,45 @@ DiskSourceTree::~DiskSourceTree() {} // then if foo/bar is a symbolic link, foo/bar/baz.proto will canonicalize // to a path which does not appear to be under foo, and thus the compiler // will complain that baz.proto is not inside the --proto_path. -static std::string CanonicalizePath(absl::string_view path) { +static std::string CanonicalizePath(std::string path) { #ifdef _WIN32 // The Win32 API accepts forward slashes as a path delimiter even though // backslashes are standard. Let's avoid confusion and use only forward // slashes. - std::string path_str; - if (absl::StartsWith(path, "\\\\")) { + if (HasPrefixString(path, "\\\\")) { // Avoid converting two leading backslashes. - path_str = "\\\\" + absl::StrReplaceAll(path.substr(2), {{"\\", "/"}}); + path = "\\\\" + StringReplace(path.substr(2), "\\", "/", true); } else { - path_str = absl::StrReplaceAll(path, {{"\\", "/"}}); + path = StringReplace(path, "\\", "/", true); } - path = path_str; #endif - std::vector canonical_parts; - if (!path.empty() && path.front() == '/') canonical_parts.push_back(""); - for (absl::string_view part : absl::StrSplit(path, '/', absl::SkipEmpty())) { + std::vector canonical_parts; + std::vector parts = Split( + path, "/", true); // Note: Removes empty parts. + for (const std::string& part : parts) { if (part == ".") { // Ignore. } else { canonical_parts.push_back(part); } } - if (!path.empty() && path.back() == '/') canonical_parts.push_back(""); - - return absl::StrJoin(canonical_parts, "/"); + std::string result = Join(canonical_parts, "/"); + if (!path.empty() && path[0] == '/') { + // Restore leading slash. + result = '/' + result; + } + if (!path.empty() && LastChar(path) == '/' && !result.empty() && + LastChar(result) != '/') { + // Restore trailing slash. + result += '/'; + } + return result; } -static inline bool ContainsParentReference(absl::string_view path) { - return path == ".." || absl::StartsWith(path, "../") || - absl::EndsWith(path, "/..") || absl::StrContains(path, "/../"); +static inline bool ContainsParentReference(const std::string& path) { + return path == ".." || HasPrefixString(path, "../") || + HasSuffixString(path, "/..") || path.find("/../") != std::string::npos; } // Maps a file from an old location to a new one. Typically, old_prefix is @@ -327,28 +332,28 @@ static inline bool ContainsParentReference(absl::string_view path) { // assert(!ApplyMapping("foo/bar", "baz", "qux", &result)); // assert(!ApplyMapping("foo/bar", "baz", "qux", &result)); // assert(!ApplyMapping("foobar", "foo", "baz", &result)); -static bool ApplyMapping(absl::string_view filename, - absl::string_view old_prefix, - absl::string_view new_prefix, std::string* result) { +static bool ApplyMapping(const std::string& filename, + const std::string& old_prefix, + const std::string& new_prefix, std::string* result) { if (old_prefix.empty()) { // old_prefix matches any relative path. if (ContainsParentReference(filename)) { // We do not allow the file name to use "..". return false; } - if (absl::StartsWith(filename, "/") || IsWindowsAbsolutePath(filename)) { + if (HasPrefixString(filename, "/") || IsWindowsAbsolutePath(filename)) { // This is an absolute path, so it isn't matched by the empty string. return false; } - result->assign(std::string(new_prefix)); + result->assign(new_prefix); if (!result->empty()) result->push_back('/'); - result->append(std::string(filename)); + result->append(filename); return true; - } else if (absl::StartsWith(filename, old_prefix)) { + } else if (HasPrefixString(filename, old_prefix)) { // old_prefix is a prefix of the filename. Is it the whole filename? if (filename.size() == old_prefix.size()) { // Yep, it's an exact match. - *result = std::string(new_prefix); + *result = new_prefix; return true; } else { // Not an exact match. Is the next character a '/'? Otherwise, @@ -365,14 +370,14 @@ static bool ApplyMapping(absl::string_view filename, if (after_prefix_start != -1) { // Yep. So the prefixes are directories and the filename is a file // inside them. - absl::string_view after_prefix = filename.substr(after_prefix_start); + std::string after_prefix = filename.substr(after_prefix_start); if (ContainsParentReference(after_prefix)) { // We do not allow the file name to use "..". return false; } - result->assign(std::string(new_prefix)); + result->assign(new_prefix); if (!result->empty()) result->push_back('/'); - result->append(std::string(after_prefix)); + result->append(after_prefix); return true; } } @@ -381,14 +386,13 @@ static bool ApplyMapping(absl::string_view filename, return false; } -void DiskSourceTree::MapPath(absl::string_view virtual_path, - absl::string_view disk_path) { - mappings_.push_back( - Mapping(std::string(virtual_path), CanonicalizePath(disk_path))); +void DiskSourceTree::MapPath(const std::string& virtual_path, + const std::string& disk_path) { + mappings_.push_back(Mapping(virtual_path, CanonicalizePath(disk_path))); } DiskSourceTree::DiskFileToVirtualFileResult -DiskSourceTree::DiskFileToVirtualFile(absl::string_view disk_file, +DiskSourceTree::DiskFileToVirtualFile(const std::string& disk_file, std::string* virtual_file, std::string* shadowing_disk_file) { int mapping_index = -1; @@ -432,14 +436,14 @@ DiskSourceTree::DiskFileToVirtualFile(absl::string_view disk_file, return SUCCESS; } -bool DiskSourceTree::VirtualFileToDiskFile(absl::string_view virtual_file, +bool DiskSourceTree::VirtualFileToDiskFile(const std::string& virtual_file, std::string* disk_file) { std::unique_ptr stream( OpenVirtualFile(virtual_file, disk_file)); return stream != nullptr; } -io::ZeroCopyInputStream* DiskSourceTree::Open(absl::string_view filename) { +io::ZeroCopyInputStream* DiskSourceTree::Open(const std::string& filename) { return OpenVirtualFile(filename, nullptr); } @@ -448,7 +452,7 @@ std::string DiskSourceTree::GetLastErrorMessage() { } io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile( - absl::string_view virtual_file, std::string* disk_file) { + const std::string& virtual_file, std::string* disk_file) { if (virtual_file != CanonicalizePath(virtual_file) || ContainsParentReference(virtual_file)) { // We do not allow importing of paths containing things like ".." or @@ -485,11 +489,11 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenVirtualFile( } io::ZeroCopyInputStream* DiskSourceTree::OpenDiskFile( - absl::string_view filename) { + const std::string& filename) { struct stat sb; int ret = 0; do { - ret = stat(std::string(filename).c_str(), &sb); + ret = stat(filename.c_str(), &sb); } while (ret != 0 && errno == EINTR); #if defined(_WIN32) if (ret == 0 && sb.st_mode & S_IFDIR) { @@ -504,7 +508,7 @@ io::ZeroCopyInputStream* DiskSourceTree::OpenDiskFile( #endif int file_descriptor; do { - file_descriptor = open(std::string(filename).c_str(), O_RDONLY); + file_descriptor = open(filename.c_str(), O_RDONLY); } while (file_descriptor < 0 && errno == EINTR); if (file_descriptor >= 0) { io::FileInputStream* result = new io::FileInputStream(file_descriptor); diff --git a/libs/protobuf/src/google/protobuf/compiler/importer.h b/libs/protobuf/src/google/protobuf/compiler/importer.h index 3b8dd51..2fb88b9 100644 --- a/libs/protobuf/src/google/protobuf/compiler/importer.h +++ b/libs/protobuf/src/google/protobuf/compiler/importer.h @@ -42,12 +42,12 @@ #include #include -#include "google/protobuf/compiler/parser.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor_database.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -159,8 +159,6 @@ class PROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { class PROTOBUF_EXPORT Importer { public: Importer(SourceTree* source_tree, MultiFileErrorCollector* error_collector); - Importer(const Importer&) = delete; - Importer& operator=(const Importer&) = delete; ~Importer(); // Import the given file and build a FileDescriptor representing it. If @@ -190,15 +188,15 @@ class PROTOBUF_EXPORT Importer { private: SourceTreeDescriptorDatabase database_; DescriptorPool pool_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); }; // If the importer encounters problems while trying to import the proto files, // it reports them to a MultiFileErrorCollector. class PROTOBUF_EXPORT MultiFileErrorCollector { public: - MultiFileErrorCollector() {} - MultiFileErrorCollector(const MultiFileErrorCollector&) = delete; - MultiFileErrorCollector& operator=(const MultiFileErrorCollector&) = delete; + inline MultiFileErrorCollector() {} virtual ~MultiFileErrorCollector(); // Line and column numbers are zero-based. A line number of -1 indicates @@ -208,6 +206,9 @@ class PROTOBUF_EXPORT MultiFileErrorCollector { virtual void AddWarning(const std::string& /* filename */, int /* line */, int /* column */, const std::string& /* message */) {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); }; // Abstract interface which represents a directory tree containing proto files. @@ -216,16 +217,14 @@ class PROTOBUF_EXPORT MultiFileErrorCollector { // below. class PROTOBUF_EXPORT SourceTree { public: - SourceTree() {} - SourceTree(const SourceTree&) = delete; - SourceTree& operator=(const SourceTree&) = delete; + inline SourceTree() {} virtual ~SourceTree(); // Open the given file and return a stream that reads it, or NULL if not // found. The caller takes ownership of the returned object. The filename // must be a path relative to the root of the source tree and must not // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(absl::string_view filename) = 0; + virtual io::ZeroCopyInputStream* Open(const std::string& filename) = 0; // If Open() returns NULL, calling this method immediately will return an // description of the error. @@ -233,6 +232,9 @@ class PROTOBUF_EXPORT SourceTree { // better error reporting. // TODO(xiaofeng): change this to a pure virtual function. virtual std::string GetLastErrorMessage(); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); }; // An implementation of SourceTree which loads files from locations on disk. @@ -241,8 +243,6 @@ class PROTOBUF_EXPORT SourceTree { class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { public: DiskSourceTree(); - DiskSourceTree(const DiskSourceTree&) = delete; - DiskSourceTree& operator=(const DiskSourceTree&) = delete; ~DiskSourceTree() override; // Map a path on disk to a location in the SourceTree. The path may be @@ -261,7 +261,7 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { // // disk_path may be an absolute path or relative to the current directory, // just like a path you'd pass to open(). - void MapPath(absl::string_view virtual_path, absl::string_view disk_path); + void MapPath(const std::string& virtual_path, const std::string& disk_path); // Return type for DiskFileToVirtualFile(). enum DiskFileToVirtualFileResult { @@ -292,17 +292,17 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { // * NO_MAPPING: Indicates that no mapping was found which contains this // file. DiskFileToVirtualFileResult DiskFileToVirtualFile( - absl::string_view disk_file, std::string* virtual_file, + const std::string& disk_file, std::string* virtual_file, std::string* shadowing_disk_file); // Given a virtual path, find the path to the file on disk. // Return true and update disk_file with the on-disk path if the file exists. // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(absl::string_view virtual_file, + bool VirtualFileToDiskFile(const std::string& virtual_file, std::string* disk_file); // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(absl::string_view filename) override; + io::ZeroCopyInputStream* Open(const std::string& filename) override; std::string GetLastErrorMessage() override; @@ -311,26 +311,28 @@ class PROTOBUF_EXPORT DiskSourceTree : public SourceTree { std::string virtual_path; std::string disk_path; - inline Mapping(std::string virtual_path_param, std::string disk_path_param) - : virtual_path(std::move(virtual_path_param)), - disk_path(std::move(disk_path_param)) {} + inline Mapping(const std::string& virtual_path_param, + const std::string& disk_path_param) + : virtual_path(virtual_path_param), disk_path(disk_path_param) {} }; std::vector mappings_; std::string last_error_message_; // Like Open(), but returns the on-disk path in disk_file if disk_file is // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(absl::string_view virtual_file, + io::ZeroCopyInputStream* OpenVirtualFile(const std::string& virtual_file, std::string* disk_file); // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(absl::string_view filename); + io::ZeroCopyInputStream* OpenDiskFile(const std::string& filename); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); }; } // namespace compiler } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/importer_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/importer_unittest.cc index 21044c7..d2810ad 100644 --- a/libs/protobuf/src/google/protobuf/compiler/importer_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/importer_unittest.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/importer.h" +#include #include +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/container/flat_hash_map.h" -#include "absl/strings/substitute.h" - -#include "google/protobuf/stubs/strutil.h" +#include +#include +#include namespace google { namespace protobuf { @@ -74,13 +74,13 @@ class MockErrorCollector : public MultiFileErrorCollector { // implements ErrorCollector --------------------------------------- void AddError(const std::string& filename, int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, + strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n", filename, line, column, message); } void AddWarning(const std::string& filename, int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line, + strings::SubstituteAndAppend(&warning_text_, "$0:$1:$2: $3\n", filename, line, column, message); } }; @@ -93,22 +93,24 @@ class MockSourceTree : public SourceTree { MockSourceTree() {} ~MockSourceTree() override {} - void AddFile(absl::string_view name, const char* contents) { + void AddFile(const std::string& name, const char* contents) { files_[name] = contents; } // implements SourceTree ------------------------------------------- - io::ZeroCopyInputStream* Open(absl::string_view filename) override { - auto it = files_.find(filename); - if (it == files_.end()) return nullptr; - return new io::ArrayInputStream(it->second, - static_cast(strlen(it->second))); + io::ZeroCopyInputStream* Open(const std::string& filename) override { + const char* contents = FindPtrOrNull(files_, filename); + if (contents == nullptr) { + return nullptr; + } else { + return new io::ArrayInputStream(contents, strlen(contents)); + } } std::string GetLastErrorMessage() override { return "File not found."; } private: - absl::flat_hash_map files_; + std::unordered_map files_; }; // =================================================================== diff --git a/libs/protobuf/src/google/protobuf/compiler/java/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/java/BUILD.bazel deleted file mode 100644 index 3ccc73d..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/java/BUILD.bazel +++ /dev/null @@ -1,171 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - Java code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "names", - hdrs = ["names.h"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/java", - visibility = ["//visibility:public"], - deps = [ - ":names_internal", - "//src/google/protobuf:protobuf_nowkt", - ], -) - -cc_library( - name = "names_internal", - hdrs = [ - "helpers.h", - "name_resolver.h", - "names.h", - "options.h", - ], - srcs = [ - "helpers.cc", - "name_resolver.cc", - "names.cc", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/java", - visibility = ["//pkg:__pkg__"], - deps = [ - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf:protobuf_nowkt", - "@com_google_absl//absl/container:flat_hash_set", - ], -) - -cc_library( - name = "java", - srcs = [ - "context.cc", - "doc_comment.cc", - "enum.cc", - "enum_field.cc", - "enum_field_lite.cc", - "enum_lite.cc", - "extension.cc", - "extension_lite.cc", - "field.cc", - "file.cc", - "generator.cc", - "generator_factory.cc", - "kotlin_generator.cc", - "map_field.cc", - "map_field_lite.cc", - "message.cc", - "message_builder.cc", - "message_builder_lite.cc", - "message_field.cc", - "message_field_lite.cc", - "message_lite.cc", - "message_serialization.cc", - "primitive_field.cc", - "primitive_field_lite.cc", - "service.cc", - "shared_code_generator.cc", - "string_field.cc", - "string_field_lite.cc", - ], - hdrs = [ - "context.h", - "doc_comment.h", - "enum.h", - "enum_field.h", - "enum_field_lite.h", - "enum_lite.h", - "extension.h", - "extension_lite.h", - "field.h", - "file.h", - "generator.h", - "generator_factory.h", - "kotlin_generator.h", - "map_field.h", - "map_field_lite.h", - "message.h", - "message_builder.h", - "message_builder_lite.h", - "message_field.h", - "message_field_lite.h", - "message_lite.h", - "message_serialization.h", - "primitive_field.h", - "primitive_field_lite.h", - "service.h", - "shared_code_generator.h", - "string_field.h", - "string_field_lite.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/java", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":names_internal", - ":names", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "doc_comment_unittest", - srcs = ["doc_comment_unittest.cc"], - data = [ - "//:well_known_type_protos", - "//conformance:conformance_proto", - "//src/google/protobuf:descriptor_proto_srcs", - ], - deps = [ - ":java", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "plugin_unittest", - srcs = ["plugin_unittest.cc"], - deps = [ - ":java", - "//:protobuf", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs:lite", - "//src/google/protobuf/testing", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/java/context.cc b/libs/protobuf/src/google/protobuf/compiler/java/context.cc index b9f0c8f..cdc0d44 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/context.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/context.cc @@ -28,13 +28,14 @@ // (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/compiler/java/context.h" +#include -#include "google/protobuf/descriptor.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/field.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -42,7 +43,7 @@ namespace compiler { namespace java { Context::Context(const FileDescriptor* file, const Options& options) - : name_resolver_(new ClassNameResolver(options)), options_(options) { + : name_resolver_(new ClassNameResolver), options_(options) { InitializeFieldGeneratorInfo(file); } @@ -130,10 +131,10 @@ void Context::InitializeFieldGeneratorInfoForFields( std::vector conflict_reason(fields.size()); for (int i = 0; i < fields.size(); ++i) { const FieldDescriptor* field = fields[i]; - const std::string& name = CapitalizedFieldName(field); + const std::string& name = UnderscoresToCapitalizedCamelCase(field); for (int j = i + 1; j < fields.size(); ++j) { const FieldDescriptor* other = fields[j]; - const std::string& other_name = CapitalizedFieldName(other); + const std::string& other_name = UnderscoresToCapitalizedCamelCase(other); if (name == other_name) { is_conflict[i] = is_conflict[j] = true; conflict_reason[i] = conflict_reason[j] = @@ -154,12 +155,12 @@ void Context::InitializeFieldGeneratorInfoForFields( const FieldDescriptor* field = fields[i]; FieldGeneratorInfo info; info.name = CamelCaseFieldName(field); - info.capitalized_name = CapitalizedFieldName(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. if (is_conflict[i]) { - info.name += absl::StrCat(field->number()); - info.capitalized_name += absl::StrCat(field->number()); + info.name += StrCat(field->number()); + info.capitalized_name += StrCat(field->number()); info.disambiguated_reason = conflict_reason[i]; } field_generator_info_map_[field] = info; @@ -168,22 +169,24 @@ void Context::InitializeFieldGeneratorInfoForFields( const FieldGeneratorInfo* Context::GetFieldGeneratorInfo( const FieldDescriptor* field) const { - auto it = field_generator_info_map_.find(field); - if (it == field_generator_info_map_.end()) { + const FieldGeneratorInfo* result = + FindOrNull(field_generator_info_map_, field); + if (result == NULL) { GOOGLE_LOG(FATAL) << "Can not find FieldGeneratorInfo for field: " << field->full_name(); } - return &it->second; + return result; } const OneofGeneratorInfo* Context::GetOneofGeneratorInfo( const OneofDescriptor* oneof) const { - auto it = oneof_generator_info_map_.find(oneof); - if (it == oneof_generator_info_map_.end()) { + const OneofGeneratorInfo* result = + FindOrNull(oneof_generator_info_map_, oneof); + if (result == NULL) { GOOGLE_LOG(FATAL) << "Can not find OneofGeneratorInfo for oneof: " << oneof->name(); } - return &it->second; + return result; } // Does this message class have generated parsing, serialization, and other diff --git a/libs/protobuf/src/google/protobuf/compiler/java/context.h b/libs/protobuf/src/google/protobuf/compiler/java/context.h index 2291cfa..c224ab7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/context.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/context.h @@ -31,13 +31,12 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_CONTEXT_H__ +#include #include #include -#include "absl/container/flat_hash_map.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/port.h" +#include +#include namespace google { namespace protobuf { @@ -66,8 +65,6 @@ struct OneofGeneratorInfo; class Context { public: Context(const FileDescriptor* file, const Options& options); - Context(const Context&) = delete; - Context& operator=(const Context&) = delete; ~Context(); // Get the name resolver associated with this context. The resolver @@ -100,27 +97,14 @@ class Context { const std::vector& fields); std::unique_ptr name_resolver_; - absl::flat_hash_map + std::map field_generator_info_map_; - absl::flat_hash_map + std::map oneof_generator_info_map_; Options options_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context); }; -template -void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer, - Descriptor* descriptor, bool immutable, - const std::string& suffix = "") { - if (IsOwnFile(descriptor, immutable)) { - PrintGeneratedAnnotation(printer, '$', - context->options().annotate_code - ? AnnotationFileName(descriptor, suffix) - : "", - context->options()); - } -} - - } // namespace java } // namespace compiler } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.cc b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.cc index fb5b554..066bff6 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.cc @@ -32,15 +32,13 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/doc_comment.h" +#include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include namespace google { namespace protobuf { @@ -105,65 +103,26 @@ std::string EscapeJavadoc(const std::string& input) { return result; } -static std::string EscapeKdoc(const std::string& input) { - std::string result; - result.reserve(input.size() * 2); - - char prev = 'a'; - - for (char c : input) { - switch (c) { - case '*': - // Avoid "/*". - if (prev == '/') { - result.append("*"); - } else { - result.push_back(c); - } - break; - case '/': - // Avoid "*/". - if (prev == '*') { - result.append("/"); - } else { - result.push_back(c); - } - break; - default: - result.push_back(c); - break; - } - - prev = c; - } - - return result; -} - static void WriteDocCommentBodyForLocation(io::Printer* printer, - const SourceLocation& location, - const bool kdoc) { + const SourceLocation& location) { std::string comments = location.leading_comments.empty() ? location.trailing_comments : location.leading_comments; if (!comments.empty()) { - if (kdoc) { - comments = EscapeKdoc(comments); - } else { - comments = EscapeJavadoc(comments); - } + // TODO(kenton): Ideally we should parse the comment text as Markdown and + // write it back as HTML, but this requires a Markdown parser. For now + // we just use
     to get fixed-width text formatting.
     
    -    std::vector lines = absl::StrSplit(comments, "\n");
    +    // If the comment itself contains block comment start or end markers,
    +    // HTML-escape them so that they don't accidentally close the doc comment.
    +    comments = EscapeJavadoc(comments);
    +
    +    std::vector lines = Split(comments, "\n");
         while (!lines.empty() && lines.back().empty()) {
           lines.pop_back();
         }
     
    -    if (kdoc) {
    -      printer->Print(" * ```\n");
    -    } else {
    -      printer->Print(" * 
    \n");
    -    }
    -
    +    printer->Print(" * 
    \n");
         for (int i = 0; i < lines.size(); i++) {
           // Most lines should start with a space.  Watch out for lines that start
           // with a /, since putting that right after the leading asterisk will
    @@ -174,23 +133,18 @@ static void WriteDocCommentBodyForLocation(io::Printer* printer,
             printer->Print(" *$line$\n", "line", lines[i]);
           }
         }
    -
    -    if (kdoc) {
    -      printer->Print(" * ```\n");
    -    } else {
    -      printer->Print(" * 
    \n"); - } - printer->Print(" *\n"); + printer->Print( + " *
    \n" + " *\n"); } } template static void WriteDocCommentBody(io::Printer* printer, - const DescriptorType* descriptor, - const bool kdoc) { + const DescriptorType* descriptor) { SourceLocation location; if (descriptor->GetSourceLocation(&location)) { - WriteDocCommentBodyForLocation(printer, location, kdoc); + WriteDocCommentBodyForLocation(printer, location); } } @@ -210,36 +164,16 @@ static std::string FirstLineOf(const std::string& value) { return result; } -static void WriteDebugString(io::Printer* printer, const FieldDescriptor* field, - const bool kdoc) { - if (kdoc) { - printer->Print(" * `$def$`\n", "def", - EscapeKdoc(FirstLineOf(field->DebugString()))); - } else { - printer->Print(" * $def$\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); - } -} - -void WriteMessageDocComment(io::Printer* printer, const Descriptor* message, - const bool kdoc) { +void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) { printer->Print("/**\n"); - WriteDocCommentBody(printer, message, kdoc); - if (kdoc) { - printer->Print( - " * Protobuf type `$fullname$`\n" - " */\n", - "fullname", EscapeKdoc(message->full_name())); - } else { - printer->Print( - " * Protobuf type {@code $fullname$}\n" - " */\n", - "fullname", EscapeJavadoc(message->full_name())); - } + WriteDocCommentBody(printer, message); + printer->Print( + " * Protobuf type {@code $fullname$}\n" + " */\n", + "fullname", EscapeJavadoc(message->full_name())); } -void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, - const bool kdoc) { +void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) { // We start the comment with the main body based on the comments from the // .proto file (if present). We then continue with the field declaration, // e.g.: @@ -247,14 +181,9 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, // And then we end with the javadoc tags if applicable. // If the field is a group, the debug string might end with {. printer->Print("/**\n"); - WriteDocCommentBody(printer, field, kdoc); - if (kdoc) { - printer->Print(" * `$def$`\n", "def", - EscapeKdoc(FirstLineOf(field->DebugString()))); - } else { - printer->Print(" * $def$\n", "def", - EscapeJavadoc(FirstLineOf(field->DebugString()))); - } + WriteDocCommentBody(printer, field); + printer->Print(" * $def$\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); printer->Print(" */\n"); } @@ -285,11 +214,12 @@ void WriteDeprecatedJavadoc(io::Printer* printer, const FieldDescriptor* field, void WriteFieldAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder, const bool kdoc) { + const bool builder) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field, kdoc); - WriteDebugString(printer, field, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field); + printer->Print(" * $def$\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); + WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: printer->Print(" * @return Whether the $name$ field is set.\n", "name", @@ -343,12 +273,12 @@ void WriteFieldAccessorDocComment(io::Printer* printer, void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder, - const bool kdoc) { + const bool builder) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field, kdoc); - WriteDebugString(printer, field, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field); + printer->Print(" * $def$\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); + WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: // Should never happen @@ -413,12 +343,12 @@ void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder, - const bool kdoc) { + const bool builder) { printer->Print("/**\n"); - WriteDocCommentBody(printer, field, kdoc); - WriteDebugString(printer, field, kdoc); - if (!kdoc) WriteDeprecatedJavadoc(printer, field, type); + WriteDocCommentBody(printer, field); + printer->Print(" * $def$\n", "def", + EscapeJavadoc(FirstLineOf(field->DebugString()))); + WriteDeprecatedJavadoc(printer, field, type); switch (type) { case HAZZER: // Should never happen @@ -469,28 +399,19 @@ void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, // Enum -void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, - const bool kdoc) { +void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) { printer->Print("/**\n"); - WriteDocCommentBody(printer, enum_, kdoc); - if (kdoc) { - printer->Print( - " * Protobuf enum `$fullname$`\n" - " */\n", - "fullname", EscapeKdoc(enum_->full_name())); - } else { - printer->Print( - " * Protobuf enum {@code $fullname$}\n" - " */\n", - "fullname", EscapeJavadoc(enum_->full_name())); - } + WriteDocCommentBody(printer, enum_); + printer->Print( + " * Protobuf enum {@code $fullname$}\n" + " */\n", + "fullname", EscapeJavadoc(enum_->full_name())); } void WriteEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value) { printer->Print("/**\n"); - WriteDocCommentBody(printer, value, /* kdoc */ false); - + WriteDocCommentBody(printer, value); printer->Print( " * $def$\n" " */\n", @@ -500,7 +421,7 @@ void WriteEnumValueDocComment(io::Printer* printer, void WriteServiceDocComment(io::Printer* printer, const ServiceDescriptor* service) { printer->Print("/**\n"); - WriteDocCommentBody(printer, service, /* kdoc */ false); + WriteDocCommentBody(printer, service); printer->Print( " * Protobuf service {@code $fullname$}\n" " */\n", @@ -510,7 +431,7 @@ void WriteServiceDocComment(io::Printer* printer, void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method) { printer->Print("/**\n"); - WriteDocCommentBody(printer, method, /* kdoc */ false); + WriteDocCommentBody(printer, method); printer->Print( " * $def$\n" " */\n", diff --git a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.h b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.h index de8e6bf..7f68778 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment.h @@ -35,10 +35,10 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ -#include "google/protobuf/descriptor.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -67,27 +67,21 @@ enum FieldAccessorType { LIST_MULTI_ADDER }; -void WriteMessageDocComment(io::Printer* printer, const Descriptor* message, - const bool kdoc = false); -void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field, - const bool kdoc = false); +void WriteMessageDocComment(io::Printer* printer, const Descriptor* message); +void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field); void WriteFieldAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder = false, - const bool kdoc = false); + const bool builder = false); void WriteFieldEnumValueAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder = false, - const bool kdoc = false); + const bool builder = false); void WriteFieldStringBytesAccessorDocComment(io::Printer* printer, const FieldDescriptor* field, const FieldAccessorType type, - const bool builder = false, - const bool kdoc = false); -void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, - const bool kdoc = false); + const bool builder = false); +void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_); void WriteEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value); void WriteServiceDocComment(io::Printer* printer, @@ -96,7 +90,6 @@ void WriteMethodDocComment(io::Printer* printer, const MethodDescriptor* method); // Exposed for testing only. -// Also called by proto1-Java code generator. PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input); } // namespace java @@ -104,6 +97,6 @@ PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_DOC_COMMENT_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment_unittest.cc index 687b25f..3fcdf07 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/doc_comment_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/doc_comment_unittest.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/compiler/java/doc_comment.h" +#include #include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum.cc b/libs/protobuf/src/google/protobuf/compiler/java/enum.cc index 788c9dd..0cab93c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum.cc @@ -32,21 +32,21 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/enum.h" +#include #include #include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -80,10 +80,6 @@ EnumGenerator::~EnumGenerator() {} void EnumGenerator::Generate(io::Printer* printer) { WriteEnumDocComment(printer, descriptor_); MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_); - - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } printer->Print( "$deprecation$public enum $classname$\n" " implements com.google.protobuf.ProtocolMessageEnum {\n", @@ -105,8 +101,8 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { std::map vars; vars["name"] = canonical_values_[i]->name(); - vars["index"] = absl::StrCat(canonical_values_[i]->index()); - vars["number"] = absl::StrCat(canonical_values_[i]->number()); + vars["index"] = StrCat(canonical_values_[i]->index()); + vars["number"] = StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); if (canonical_values_[i]->options().deprecated()) { printer->Print("@java.lang.Deprecated\n"); @@ -148,7 +144,7 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { std::map vars; vars["name"] = descriptor_->value(i)->name(); - vars["number"] = absl::StrCat(descriptor_->value(i)->number()); + vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; vars["deprecation"] = descriptor_->value(i)->options().deprecated() @@ -185,32 +181,23 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print( " return value;\n" "}\n" - "\n"); - if (context_->options().opensource_runtime) { - printer->Print( - "/**\n" - " * @param value The numeric wire value of the corresponding enum " - "entry.\n" - " * @return The enum associated with the given numeric wire value.\n" - " * @deprecated Use {@link #forNumber(int)} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public static $classname$ valueOf(int value) {\n" - " return forNumber(value);\n" - "}\n" - "\n", - "classname", descriptor_->name()); - } - printer->Print( + "\n" "/**\n" " * @param value The numeric wire value of the corresponding enum " "entry.\n" " * @return The enum associated with the given numeric wire value.\n" - " */\n"); - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n"); - } - printer->Print( + " * @deprecated Use {@link #forNumber(int)} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public static $classname$ valueOf(int value) {\n" + " return forNumber(value);\n" + "}\n" + "\n" + "/**\n" + " * @param value The numeric wire value of the corresponding enum " + "entry.\n" + " * @return The enum associated with the given numeric wire value.\n" + " */\n" "public static $classname$ forNumber(int value) {\n" " switch (value) {\n", "classname", descriptor_->name()); @@ -220,7 +207,7 @@ void EnumGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { printer->Print("case $number$: return $name$;\n", "name", canonical_values_[i]->name(), "number", - absl::StrCat(canonical_values_[i]->number())); + StrCat(canonical_values_[i]->number())); } printer->Outdent(); @@ -290,7 +277,7 @@ void EnumGenerator::Generate(io::Printer* printer) { " return $file$.getDescriptor().getEnumTypes().get($index$);\n", "file", name_resolver_->GetClassName(descriptor_->file(), immutable_api_), - "index", absl::StrCat(descriptor_->index())); + "index", StrCat(descriptor_->index())); } else { printer->Print( " return $parent$.$descriptor$.getEnumTypes().get($index$);\n", @@ -303,7 +290,7 @@ void EnumGenerator::Generate(io::Printer* printer) { .no_standard_descriptor_accessor() ? "getDefaultInstance().getDescriptorForType()" : "getDescriptor()", - "index", absl::StrCat(descriptor_->index())); + "index", StrCat(descriptor_->index())); } printer->Print( @@ -407,4 +394,4 @@ bool EnumGenerator::CanUseEnumValues() { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum.h b/libs/protobuf/src/google/protobuf/compiler/java/enum.h index 8868e47..0a2c363 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum.h @@ -37,7 +37,7 @@ #include #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { @@ -62,8 +62,6 @@ class EnumGenerator { public: EnumGenerator(const EnumDescriptor* descriptor, bool immutable_api, Context* context); - EnumGenerator(const EnumGenerator&) = delete; - EnumGenerator& operator=(const EnumGenerator&) = delete; ~EnumGenerator(); void Generate(io::Printer* printer); @@ -90,6 +88,8 @@ class EnumGenerator { ClassNameResolver* name_resolver_; bool CanUseEnumValues(); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_field.cc b/libs/protobuf/src/google/protobuf/compiler/java/enum_field.cc index b6c8dc7..e64ee5b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_field.cc @@ -42,7 +42,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" +#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -58,57 +58,50 @@ namespace java { namespace { -void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetEnumVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->enum_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + (*variables)["kt_type"] = (*variables)["type"]; (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->enum_type()); - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = - absl::StrCat(descriptor->default_value_enum()->number()); - (*variables)["tag"] = absl::StrCat( + StrCat(descriptor->default_value_enum()->number()); + (*variables)["tag"] = StrCat( static_cast(internal::WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); - // Note that these have a trailing ";". (*variables)["set_has_field_bit_message"] = GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; - + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"] + - ".getNumber()"; + (*variables)["set_has_field_bit_to_local"] = ""; + variables->insert({"is_field_present_message", + StrCat((*variables)["name"], "_ != ", + (*variables)["default"], ".getNumber()")}); } // For repeated builders, one bit is used for whether the array is immutable. @@ -116,15 +109,21 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + + // Note that these have a trailing ";". + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); if (SupportUnknownEnumValue(descriptor->file())) { - (*variables)["unknown"] = (*variables)["type"] + ".UNRECOGNIZED"; + variables->insert( + {"unknown", StrCat((*variables)["type"], ".UNRECOGNIZED")}); } else { - (*variables)["unknown"] = (*variables)["default"]; + variables->insert({"unknown", (*variables)["default"]}); } } @@ -135,7 +134,10 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -143,13 +145,19 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator( ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {} +int ImmutableEnumFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableEnumFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableEnumFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableEnumFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -168,7 +176,7 @@ void ImmutableEnumFieldGenerator::GenerateInterfaceMembers( } void ImmutableEnumFieldGenerator::GenerateMembers(io::Printer* printer) const { - printer->Print(variables_, "private int $name$_;\n"); + printer->Print(variables_, "private int $name$_ = $default_number$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); @@ -223,8 +231,8 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$Value$}$(int value) {\n" - " $set_has_field_bit_builder$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " onChanged();\n" " return this;\n" "}\n"); @@ -267,7 +275,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers( void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -277,28 +285,15 @@ void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n" " }\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n" - " @JvmName(\"${$get$kt_capitalized_name$Value$}$\")\n" - " get() = $kt_dsl_builder$.${$get$capitalized_name$Value$}$()\n" - " @JvmName(\"${$set$kt_capitalized_name$Value$}$\")\n" - " set(value) {\n" - " $kt_dsl_builder$.${$set$capitalized_name$Value$}$(value)\n" - " }\n"); - } - WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -319,9 +314,7 @@ void ImmutableEnumFieldGenerator::GenerateInitializationCode( void ImmutableEnumFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default_number$;\n" - "$clear_has_field_bit_builder$\n"); + printer->Print(variables_, "$name$_ = $default_number$;\n"); } void ImmutableEnumFieldGenerator::GenerateMergingCode( @@ -344,13 +337,13 @@ void ImmutableEnumFieldGenerator::GenerateMergingCode( void ImmutableEnumFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print("}\n"); } void ImmutableEnumFieldGenerator::GenerateBuilderParsingCode( @@ -502,6 +495,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return $default$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, SETTER, /* builder */ true); printer->Print(variables_, @@ -516,6 +510,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, /* builder */ true); printer->Print( @@ -538,10 +533,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderClearCode( void ImmutableEnumOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // No-Op: Handled by single statement for the oneof } void ImmutableEnumOneofFieldGenerator::GenerateMergingCode( @@ -630,11 +622,8 @@ void ImmutableEnumOneofFieldGenerator::GenerateHashCode( RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetEnumVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), name_resolver_, - &variables_, context); -} + : ImmutableEnumFieldGenerator(descriptor, messageBitIndex, builderBitIndex, + context) {} RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {} @@ -987,6 +976,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderParsingCodeFromPacked( "}\n" "input.popLimit(oldLimit);\n"); } + void RepeatedImmutableEnumFieldGenerator::GenerateSerializationCode( io::Printer* printer) const { if (descriptor_->is_packed()) { @@ -1067,7 +1057,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -1078,7 +1068,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -1089,7 +1079,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -1101,7 +1091,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -1112,7 +1102,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1125,7 +1115,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1137,7 +1127,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_field.h b/libs/protobuf/src/google/protobuf/compiler/java/enum_field.h index 25ab073..8f0a5c3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_field.h @@ -68,6 +68,8 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -90,6 +92,8 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; std::map variables_; ClassNameResolver* name_resolver_; }; @@ -117,7 +121,7 @@ class ImmutableEnumOneofFieldGenerator : public ImmutableEnumFieldGenerator { void GenerateHashCode(io::Printer* printer) const override; }; -class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableEnumFieldGenerator : public ImmutableEnumFieldGenerator { public: explicit RepeatedImmutableEnumFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -150,11 +154,6 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator { void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - std::map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.cc index 470bc9d..e80b938 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.cc @@ -32,24 +32,24 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/enum_field_lite.h" +#include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -68,22 +68,20 @@ bool EnableExperimentalRuntimeForLite() { void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->enum_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + (*variables)["kt_type"] = (*variables)["type"]; (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->enum_type()); - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_number"] = - absl::StrCat(descriptor->default_value_enum()->number()); - (*variables)["tag"] = absl::StrCat( + StrCat(descriptor->default_value_enum()->number()); + (*variables)["tag"] = StrCat( static_cast(internal::WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + (*variables)["tag_size"] = StrCat( internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler @@ -97,12 +95,6 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["required"] = descriptor->is_required() ? "true" : "false"; if (HasHasbit(descriptor)) { - if (!context->options().opensource_runtime) { - (*variables)["bit_field_id"] = absl::StrCat(messageBitIndex / 32); - (*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex); - (*variables)["bit_field_mask"] = - absl::StrCat(1 << (messageBitIndex % 32)); - } // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); @@ -136,9 +128,6 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex, // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. (*variables)["null_check"] = "value.getClass();\n"; - // Calls to Annotate() use variable ranges to know which text to annotate. - (*variables)["{"] = ""; - (*variables)["}"] = ""; } } // namespace @@ -153,7 +142,7 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator( name_resolver_(context->GetNameResolver()) { SetEnumVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), name_resolver_, - &variables_, context); + &variables_); } ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {} @@ -167,37 +156,19 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, - "$deprecation$boolean ${$has$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$boolean has$capitalized_name$();\n"); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, - "$deprecation$int ${$get$capitalized_name$Value$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$int get$capitalized_name$Value();\n"); } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); } void ImmutableEnumFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$,\n" - " isRequired=$required$)\n"); - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "@com.google.protobuf.ProtoPresenceCheckedField(\n" - " presenceBitsId=$bit_field_id$,\n" - " mask=$bit_field_mask$)\n"); - } - } printer->Print(variables_, "private int $name$_;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { @@ -315,7 +286,7 @@ void ImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -325,28 +296,15 @@ void ImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$set$capitalized_name$$}$(value)\n" " }\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - variables_, - "$kt_deprecation$public var $kt_name$Value: kotlin.Int\n" - " @JvmName(\"${$get$kt_capitalized_name$Value$}$\")\n" - " get() = $kt_dsl_builder$.${$get$capitalized_name$Value$}$()\n" - " @JvmName(\"${$set$kt_capitalized_name$Value$}$\")\n" - " set(value) {\n" - " $kt_dsl_builder$.${$set$capitalized_name$Value$}$(value)\n" - " }\n"); - } - WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -543,7 +501,7 @@ RepeatedImmutableEnumFieldLiteGenerator:: name_resolver_(context->GetNameResolver()) { SetEnumVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), name_resolver_, - &variables_, context); + &variables_); } RepeatedImmutableEnumFieldLiteGenerator:: @@ -556,43 +514,29 @@ int RepeatedImmutableEnumFieldLiteGenerator::GetNumBitsForMessage() const { void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); - printer->Print(variables_, - "$deprecation$java.util.List<$type$> " - "${$get$capitalized_name$List$}$();\n"); - printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); - printer->Print(variables_, - "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); - printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); printer->Print( variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$java.util.List<$type$> get$capitalized_name$List();\n"); + WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); + printer->Print(variables_, + "$deprecation$int get$capitalized_name$Count();\n"); + WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); + printer->Print(variables_, + "$deprecation$$type$ get$capitalized_name$(int index);\n"); if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$java.util.List\n" - "${$get$capitalized_name$ValueList$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "get$capitalized_name$ValueList();\n"); WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print( - variables_, - "$deprecation$int ${$get$capitalized_name$Value$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecation$int get$capitalized_name$Value(int index);\n"); } } void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$)\n"); - } printer->Print( variables_, "private com.google.protobuf.Internal.IntList $name$_;\n" @@ -849,7 +793,6 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$Value$}$(int value) {\n" - " copyOnWrite();\n" " instance.add$capitalized_name$Value(value);\n" " return this;\n" "}\n"); @@ -887,7 +830,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -898,7 +841,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -909,7 +852,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -921,7 +864,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -932,7 +875,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -945,7 +888,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -957,7 +900,7 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" @@ -977,4 +920,4 @@ std::string RepeatedImmutableEnumFieldLiteGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.h index 8d7a7d1..492b268 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -62,10 +62,6 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { explicit ImmutableEnumFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableEnumFieldLiteGenerator(const ImmutableEnumFieldLiteGenerator&) = - delete; - ImmutableEnumFieldLiteGenerator& operator=( - const ImmutableEnumFieldLiteGenerator&) = delete; ~ImmutableEnumFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator @@ -87,6 +83,9 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator { const int messageBitIndex_; Context* context_; ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumFieldLiteGenerator); }; class ImmutableEnumOneofFieldLiteGenerator @@ -94,16 +93,15 @@ class ImmutableEnumOneofFieldLiteGenerator public: ImmutableEnumOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableEnumOneofFieldLiteGenerator( - const ImmutableEnumOneofFieldLiteGenerator&) = delete; - ImmutableEnumOneofFieldLiteGenerator& operator=( - const ImmutableEnumOneofFieldLiteGenerator&) = delete; ~ImmutableEnumOneofFieldLiteGenerator() override; void GenerateMembers(io::Printer* printer) const override; void GenerateBuilderMembers(io::Printer* printer) const override; void GenerateFieldInfo(io::Printer* printer, std::vector* output) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableEnumOneofFieldLiteGenerator); }; class RepeatedImmutableEnumFieldLiteGenerator @@ -111,10 +109,6 @@ class RepeatedImmutableEnumFieldLiteGenerator public: explicit RepeatedImmutableEnumFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - RepeatedImmutableEnumFieldLiteGenerator( - const RepeatedImmutableEnumFieldLiteGenerator&) = delete; - RepeatedImmutableEnumFieldLiteGenerator& operator=( - const RepeatedImmutableEnumFieldLiteGenerator&) = delete; ~RepeatedImmutableEnumFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator ------------------------------------ @@ -134,6 +128,8 @@ class RepeatedImmutableEnumFieldLiteGenerator std::map variables_; Context* context_; ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableEnumFieldLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.cc index 47cae62..4387090 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.cc @@ -32,18 +32,19 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/enum_lite.h" +#include #include #include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -88,7 +89,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { std::map vars; vars["name"] = canonical_values_[i]->name(); - vars["number"] = absl::StrCat(canonical_values_[i]->number()); + vars["number"] = StrCat(canonical_values_[i]->number()); WriteEnumValueDocComment(printer, canonical_values_[i]); if (canonical_values_[i]->options().deprecated()) { printer->Print("@java.lang.Deprecated\n"); @@ -122,7 +123,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->value_count(); i++) { std::map vars; vars["name"] = descriptor_->value(i)->name(); - vars["number"] = absl::StrCat(descriptor_->value(i)->number()); + vars["number"] = StrCat(descriptor_->value(i)->number()); vars["{"] = ""; vars["}"] = ""; vars["deprecation"] = descriptor_->value(i)->options().deprecated() @@ -152,26 +153,17 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { printer->Print( " return value;\n" "}\n" - "\n"); - if (context_->options().opensource_runtime) { - printer->Print( - "/**\n" - " * @param value The number of the enum to look for.\n" - " * @return The enum associated with the given number.\n" - " * @deprecated Use {@link #forNumber(int)} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public static $classname$ valueOf(int value) {\n" - " return forNumber(value);\n" - "}\n" - "\n", - "classname", descriptor_->name()); - } - - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n"); - } - printer->Print( + "\n" + "/**\n" + " * @param value The number of the enum to look for.\n" + " * @return The enum associated with the given number.\n" + " * @deprecated Use {@link #forNumber(int)} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public static $classname$ valueOf(int value) {\n" + " return forNumber(value);\n" + "}\n" + "\n" "public static $classname$ forNumber(int value) {\n" " switch (value) {\n", "classname", descriptor_->name()); @@ -181,7 +173,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { for (int i = 0; i < canonical_values_.size(); i++) { printer->Print("case $number$: return $name$;\n", "name", canonical_values_[i]->name(), "number", - absl::StrCat(canonical_values_[i]->number())); + StrCat(canonical_values_[i]->number())); } printer->Outdent(); @@ -220,35 +212,6 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { " };\n" "\n", "classname", descriptor_->name()); - if (!context_->options().opensource_runtime) { - printer->Print( - "/**\n" - " * Override of toString that prints the number and name.\n" - " * This is primarily intended as a developer aid.\n" - " *\n" - " *

    NOTE: This implementation is liable to change in the future,\n" - " * and should not be relied on in code.\n" - " */\n" - "@java.lang.Override\n" - "public java.lang.String toString() {\n" - " StringBuilder result = new StringBuilder(\"<\");\n" - " result.append(getClass().getName()).append('@')\n" - " .append(java.lang.Integer.toHexString(\n" - " java.lang.System.identityHashCode(this)));\n"); - if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print( - " if (this != UNRECOGNIZED) {\n" - " result.append(\" number=\").append(getNumber());\n" - " }\n"); - } else { - printer->Print(" result.append(\" number=\").append(getNumber());\n"); - } - printer->Print( - " return result.append(\" name=\")\n" - " .append(name()).append('>').toString();\n" - "}\n" - "\n"); - } printer->Print( "private final int value;\n\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.h index 13306b1..50f3fe7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/enum_lite.h @@ -37,7 +37,7 @@ #include #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { @@ -62,8 +62,6 @@ class EnumLiteGenerator { public: EnumLiteGenerator(const EnumDescriptor* descriptor, bool immutable_api, Context* context); - EnumLiteGenerator(const EnumLiteGenerator&) = delete; - EnumLiteGenerator& operator=(const EnumLiteGenerator&) = delete; ~EnumLiteGenerator(); void Generate(io::Printer* printer); @@ -88,6 +86,8 @@ class EnumLiteGenerator { Context* context_; ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/extension.cc b/libs/protobuf/src/google/protobuf/compiler/java/extension.cc index 24a392e..8b93eb1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/extension.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/extension.cc @@ -32,17 +32,17 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/extension.h" +#include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -51,9 +51,7 @@ namespace java { ImmutableExtensionGenerator::ImmutableExtensionGenerator( const FieldDescriptor* descriptor, Context* context) - : descriptor_(descriptor), - name_resolver_(context->GetNameResolver()), - context_(context) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { if (descriptor_->extension_scope() != NULL) { scope_ = name_resolver_->GetImmutableClassName(descriptor_->extension_scope()); @@ -68,19 +66,18 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {} void ExtensionGenerator::InitTemplateVars( const FieldDescriptor* descriptor, const std::string& scope, bool immutable, ClassNameResolver* name_resolver, - std::map* vars_pointer, Context* context) { + std::map* vars_pointer) { std::map& vars = *vars_pointer; vars["scope"] = scope; vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor); vars["containing_type"] = name_resolver->GetClassName(descriptor->containing_type(), immutable); - vars["number"] = absl::StrCat(descriptor->number()); + vars["number"] = StrCat(descriptor->number()); vars["constant_name"] = FieldConstantName(descriptor); - vars["index"] = absl::StrCat(descriptor->index()); + vars["index"] = StrCat(descriptor->index()); vars["default"] = descriptor->is_repeated() ? "" - : DefaultValue(descriptor, immutable, name_resolver, - context->options()); + : DefaultValue(descriptor, immutable, name_resolver); vars["type_constant"] = FieldTypeName(GetType(descriptor)); vars["packed"] = descriptor->is_packed() ? "true" : "false"; vars["enum_map"] = "null"; @@ -119,7 +116,7 @@ void ImmutableExtensionGenerator::Generate(io::Printer* printer) { std::map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, - &vars, context_); + &vars); printer->Print(vars, "public static final int $constant_name$ = $number$;\n"); WriteFieldDocComment(printer, descriptor_); @@ -159,7 +156,7 @@ int ImmutableExtensionGenerator::GenerateNonNestedInitializationCode( printer->Print( "$name$.internalInit(descriptor.getExtensions().get($index$));\n", "name", UnderscoresToCamelCaseCheckReserved(descriptor_), "index", - absl::StrCat(descriptor_->index())); + StrCat(descriptor_->index())); bytecode_estimate += 21; } return bytecode_estimate; @@ -177,4 +174,4 @@ int ImmutableExtensionGenerator::GenerateRegistrationCode( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/extension.h b/libs/protobuf/src/google/protobuf/compiler/java/extension.h index b9dc995..318cfa4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/extension.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/extension.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/port.h" +#include namespace google { namespace protobuf { @@ -66,8 +66,6 @@ namespace java { class ExtensionGenerator { public: explicit ExtensionGenerator() {} - ExtensionGenerator(const ExtensionGenerator&) = delete; - ExtensionGenerator& operator=(const ExtensionGenerator&) = delete; virtual ~ExtensionGenerator() {} virtual void Generate(io::Printer* printer) = 0; @@ -81,20 +79,19 @@ class ExtensionGenerator { virtual int GenerateRegistrationCode(io::Printer* printer) = 0; protected: - static void InitTemplateVars(const FieldDescriptor* descriptor, - const std::string& scope, bool immutable, - ClassNameResolver* name_resolver, - std::map* vars_pointer, - Context* context); + static void InitTemplateVars( + const FieldDescriptor* descriptor, const std::string& scope, + bool immutable, ClassNameResolver* name_resolver, + std::map* vars_pointer); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator); }; class ImmutableExtensionGenerator : public ExtensionGenerator { public: explicit ImmutableExtensionGenerator(const FieldDescriptor* descriptor, Context* context); - ImmutableExtensionGenerator(const ImmutableExtensionGenerator&) = delete; - ImmutableExtensionGenerator& operator=(const ImmutableExtensionGenerator&) = - delete; ~ImmutableExtensionGenerator() override; void Generate(io::Printer* printer) override; @@ -105,7 +102,9 @@ class ImmutableExtensionGenerator : public ExtensionGenerator { const FieldDescriptor* descriptor_; ClassNameResolver* name_resolver_; std::string scope_; - Context* context_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.cc index e18dc65..bffb1d6 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.cc @@ -28,16 +28,17 @@ // (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/compiler/java/extension_lite.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -46,9 +47,7 @@ namespace java { ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator( const FieldDescriptor* descriptor, Context* context) - : descriptor_(descriptor), - name_resolver_(context->GetNameResolver()), - context_(context) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { if (descriptor_->extension_scope() != NULL) { scope_ = name_resolver_->GetImmutableClassName(descriptor_->extension_scope()); @@ -63,7 +62,7 @@ void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) { std::map vars; const bool kUseImmutableNames = true; InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_, - &vars, context_); + &vars); printer->Print(vars, "public static final int $constant_name$ = $number$;\n"); WriteFieldDocComment(printer, descriptor_); @@ -118,4 +117,4 @@ int ImmutableExtensionLiteGenerator::GenerateRegistrationCode( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.h index 015f2ee..264230c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/extension_lite.h @@ -34,8 +34,8 @@ #include #include -#include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/port.h" +#include +#include namespace google { namespace protobuf { @@ -49,10 +49,6 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator { public: explicit ImmutableExtensionLiteGenerator(const FieldDescriptor* descriptor, Context* context); - ImmutableExtensionLiteGenerator(const ImmutableExtensionLiteGenerator&) = - delete; - ImmutableExtensionLiteGenerator& operator=( - const ImmutableExtensionLiteGenerator&) = delete; ~ImmutableExtensionLiteGenerator() override; void Generate(io::Printer* printer) override; @@ -67,7 +63,8 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator { const FieldDescriptor* descriptor_; ClassNameResolver* name_resolver_; std::string scope_; - Context* context_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/field.cc b/libs/protobuf/src/google/protobuf/compiler/java/field.cc index 831f88a..3dd528f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/field.cc @@ -32,27 +32,27 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/field.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/enum_field.h" -#include "google/protobuf/compiler/java/enum_field_lite.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/map_field.h" -#include "google/protobuf/compiler/java/map_field_lite.h" -#include "google/protobuf/compiler/java/message_field.h" -#include "google/protobuf/compiler/java/message_field_lite.h" -#include "google/protobuf/compiler/java/primitive_field.h" -#include "google/protobuf/compiler/java/primitive_field_lite.h" -#include "google/protobuf/compiler/java/string_field.h" -#include "google/protobuf/compiler/java/string_field_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { @@ -250,7 +250,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["capitalized_name"] = info->capitalized_name; (*variables)["disambiguated_reason"] = info->disambiguated_reason; (*variables)["constant_name"] = FieldConstantName(descriptor); - (*variables)["number"] = absl::StrCat(descriptor->number()); + (*variables)["number"] = StrCat(descriptor->number()); (*variables)["kt_dsl_builder"] = "_builder"; // These variables are placeholders to pick out the beginning and ends of // identifiers for annotations (when doing so with existing variables would @@ -285,13 +285,13 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor, (*variables)["oneof_name"] = info->name; (*variables)["oneof_capitalized_name"] = info->capitalized_name; (*variables)["oneof_index"] = - absl::StrCat(descriptor->containing_oneof()->index()); + StrCat(descriptor->containing_oneof()->index()); (*variables)["oneof_stored_type"] = GetOneofStoredType(descriptor); (*variables)["set_oneof_case_message"] = - info->name + "Case_ = " + absl::StrCat(descriptor->number()); + info->name + "Case_ = " + StrCat(descriptor->number()); (*variables)["clear_oneof_case_message"] = info->name + "Case_ = 0"; (*variables)["has_oneof_case_message"] = - info->name + "Case_ == " + absl::StrCat(descriptor->number()); + info->name + "Case_ == " + StrCat(descriptor->number()); } void PrintExtraFieldInfo(const std::map& variables, diff --git a/libs/protobuf/src/google/protobuf/compiler/java/field.h b/libs/protobuf/src/google/protobuf/compiler/java/field.h index 5ac57cd..7f82316 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/field.h @@ -40,10 +40,9 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/port.h" +#include +#include +#include namespace google { namespace protobuf { @@ -67,10 +66,10 @@ namespace java { class ImmutableFieldGenerator { public: ImmutableFieldGenerator() {} - ImmutableFieldGenerator(const ImmutableFieldGenerator&) = delete; - ImmutableFieldGenerator& operator=(const ImmutableFieldGenerator&) = delete; virtual ~ImmutableFieldGenerator(); + virtual int GetMessageBitIndex() const = 0; + virtual int GetBuilderBitIndex() const = 0; virtual int GetNumBitsForMessage() const = 0; virtual int GetNumBitsForBuilder() const = 0; virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; @@ -92,14 +91,14 @@ class ImmutableFieldGenerator { virtual void GenerateHashCode(io::Printer* printer) const = 0; virtual std::string GetBoxedType() const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator); }; class ImmutableFieldLiteGenerator { public: ImmutableFieldLiteGenerator() {} - ImmutableFieldLiteGenerator(const ImmutableFieldLiteGenerator&) = delete; - ImmutableFieldLiteGenerator& operator=(const ImmutableFieldLiteGenerator&) = - delete; virtual ~ImmutableFieldLiteGenerator(); virtual int GetNumBitsForMessage() const = 0; @@ -112,6 +111,9 @@ class ImmutableFieldLiteGenerator { virtual void GenerateKotlinDslMembers(io::Printer* printer) const = 0; virtual std::string GetBoxedType() const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldLiteGenerator); }; @@ -120,8 +122,6 @@ template class FieldGeneratorMap { public: explicit FieldGeneratorMap(const Descriptor* descriptor, Context* context); - FieldGeneratorMap(const FieldGeneratorMap&) = delete; - FieldGeneratorMap& operator=(const FieldGeneratorMap&) = delete; ~FieldGeneratorMap(); const FieldGeneratorType& get(const FieldDescriptor* field) const; @@ -129,6 +129,8 @@ class FieldGeneratorMap { private: const Descriptor* descriptor_; std::vector> field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); }; template diff --git a/libs/protobuf/src/google/protobuf/compiler/java/file.cc b/libs/protobuf/src/google/protobuf/compiler/java/file.cc index 4776277..cf27703 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/file.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/file.cc @@ -32,30 +32,30 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/file.h" +#include #include #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/dynamic_message.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/enum.h" -#include "google/protobuf/compiler/java/enum_lite.h" -#include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/compiler/java/generator_factory.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/message.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/compiler/java/service.h" -#include "google/protobuf/compiler/java/shared_code_generator.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -175,10 +175,10 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate, if ((*bytecode_estimate) > bytesPerMethod) { ++(*method_num); - printer->Print(chain_statement, "method_num", absl::StrCat(*method_num)); + printer->Print(chain_statement, "method_num", StrCat(*method_num)); printer->Outdent(); printer->Print("}\n"); - printer->Print(method_decl, "method_num", absl::StrCat(*method_num)); + printer->Print(method_decl, "method_num", StrCat(*method_num)); printer->Indent(); *bytecode_estimate = 0; } @@ -188,7 +188,7 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate, FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options, bool immutable_api) : file_(file), - java_package_(FileJavaPackage(file, immutable_api, options)), + java_package_(FileJavaPackage(file, immutable_api)), message_generators_(file->message_type_count()), extension_generators_(file->extension_count()), context_(new Context(file, options)), @@ -196,7 +196,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options, options_(options), immutable_api_(immutable_api) { classname_ = name_resolver_->GetFileClassName(file, immutable_api); - generator_factory_.reset(new ImmutableGeneratorFactory(context_.get())); + generator_factory_.reset(new ImmutableGeneratorFactory(context_.get())); for (int i = 0; i < file_->message_type_count(); ++i) { message_generators_[i].reset( generator_factory_->NewMessageGenerator(file_->message_type(i))); @@ -271,12 +271,8 @@ void FileGenerator::Generate(io::Printer* printer) { "package", java_package_); } PrintGeneratedAnnotation( - printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "", - options_); + printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : ""); - if (!options_.opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } printer->Print( "$deprecation$public final class $classname$ {\n" " private $ctor$() {}\n", @@ -405,14 +401,11 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( " descriptor;\n" "static {\n", // TODO(dweis): Mark this as final. - "final", options_.opensource_runtime ? "" : "final"); + "final", ""); printer->Indent(); - if (options_.opensource_runtime) { - SharedCodeGenerator shared_code_generator(file_, options_); - shared_code_generator.GenerateDescriptors(printer); - } else { - } + SharedCodeGenerator shared_code_generator(file_, options_); + shared_code_generator.GenerateDescriptors(printer); int bytecode_estimate = 0; int method_num = 0; @@ -506,8 +499,8 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( printer->Print( "descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n", - "immutable_package", FileJavaPackage(file_, true, options_), - "descriptor_classname", name_resolver_->GetDescriptorClassName(file_)); + "immutable_package", FileJavaPackage(file_, true), "descriptor_classname", + name_resolver_->GetDescriptorClassName(file_)); for (int i = 0; i < file_->message_type_count(); i++) { message_generators_[i]->GenerateStaticVariableInitializers(printer); @@ -554,7 +547,7 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( scope = name_resolver_->GetMutableClassName(field->extension_scope()) + ".getDescriptor()"; } else { - scope = FileJavaPackage(field->file(), true, options_) + "." + + scope = FileJavaPackage(field->file(), true) + "." + name_resolver_->GetDescriptorClassName(field->file()) + ".descriptor"; } @@ -567,11 +560,11 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable( " $scope$.getExtensions().get($index$),\n" " (com.google.protobuf.Message) defaultExtensionInstance);\n" "}\n", - "scope", scope, "index", absl::StrCat(field->index()), "class", + "scope", scope, "index", StrCat(field->index()), "class", name_resolver_->GetImmutableClassName(field->message_type())); } else { printer->Print("registry.add($scope$.getExtensions().get($index$));\n", - "scope", scope, "index", absl::StrCat(field->index())); + "scope", scope, "index", StrCat(field->index())); } } printer->Print( @@ -711,18 +704,15 @@ void FileGenerator::GenerateKotlinSiblings( options_.annotate_code ? &annotation_collector : nullptr); printer.Print( - "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "//Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// source: $filename$\n" "\n", "filename", descriptor->file()->name()); - printer.Print( - "// Generated files should ignore deprecation warnings\n" - "@file:Suppress(\"DEPRECATION\")"); if (!java_package_.empty()) { printer.Print( "package $package$;\n" "\n", - "package", EscapeKotlinKeywords(java_package_)); + "package", java_package_); } generator->GenerateKotlinMembers(&printer); @@ -746,4 +736,4 @@ bool FileGenerator::ShouldIncludeDependency(const FileDescriptor* descriptor, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/file.h b/libs/protobuf/src/google/protobuf/compiler/java/file.h index bf1e23b..b2e0373 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/file.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/file.h @@ -39,8 +39,8 @@ #include #include -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/port.h" +#include +#include namespace google { namespace protobuf { @@ -70,8 +70,6 @@ class FileGenerator { public: FileGenerator(const FileDescriptor* file, const Options& options, bool immutable_api = true); - FileGenerator(const FileGenerator&) = delete; - FileGenerator& operator=(const FileGenerator&) = delete; ~FileGenerator(); // Checks for problems that would otherwise lead to cryptic compile errors. @@ -116,6 +114,8 @@ class FileGenerator { ClassNameResolver* name_resolver_; const Options options_; bool immutable_api_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/generator.cc b/libs/protobuf/src/google/protobuf/compiler/java/generator.cc index 2f345ef..85e3991 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/generator.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/generator.h" +#include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "absl/strings/str_format.h" -#include "google/protobuf/compiler/java/file.h" -#include "google/protobuf/compiler/java/generator_factory.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/compiler/java/shared_code_generator.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" +#include namespace google { namespace protobuf { @@ -74,8 +74,6 @@ bool JavaGenerator::Generate(const FileDescriptor* file, ParseGeneratorParameter(parameter, &options); Options file_options; - file_options.opensource_runtime = opensource_runtime_; - for (int i = 0; i < options.size(); i++) { if (options[i].first == "output_list_file") { file_options.output_list_file = options[i].second; diff --git a/libs/protobuf/src/google/protobuf/compiler/java/generator.h b/libs/protobuf/src/google/protobuf/compiler/java/generator.h index fc7755c..bbc7170 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/generator.h @@ -38,10 +38,10 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ #include -#include "google/protobuf/compiler/code_generator.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -55,8 +55,6 @@ namespace java { class PROTOC_EXPORT JavaGenerator : public CodeGenerator { public: JavaGenerator(); - JavaGenerator(const JavaGenerator&) = delete; - JavaGenerator& operator=(const JavaGenerator&) = delete; ~JavaGenerator() override; // implements CodeGenerator ---------------------------------------- @@ -65,12 +63,8 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator { uint64_t GetSupportedFeatures() const override; - void set_opensource_runtime(bool opensource) { - opensource_runtime_ = opensource; - } - private: - bool opensource_runtime_ = PROTO2_IS_OSS; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); }; } // namespace java @@ -78,6 +72,6 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.cc b/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.cc index 86baf0b..dd526ba 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.cc @@ -30,17 +30,17 @@ // Author: liujisi@google.com (Pherl Liu) -#include "google/protobuf/compiler/java/generator_factory.h" +#include -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/enum_field.h" -#include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/compiler/java/extension_lite.h" -#include "google/protobuf/compiler/java/field.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/message.h" -#include "google/protobuf/compiler/java/message_lite.h" -#include "google/protobuf/compiler/java/service.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.h b/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.h index b2fb054..807bca3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/generator_factory.h @@ -33,7 +33,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_FACTORY_H__ -#include "google/protobuf/port.h" +#include namespace google { namespace protobuf { @@ -59,8 +59,6 @@ namespace java { class GeneratorFactory { public: GeneratorFactory(); - GeneratorFactory(const GeneratorFactory&) = delete; - GeneratorFactory& operator=(const GeneratorFactory&) = delete; virtual ~GeneratorFactory(); virtual MessageGenerator* NewMessageGenerator( @@ -71,15 +69,15 @@ class GeneratorFactory { virtual ServiceGenerator* NewServiceGenerator( const ServiceDescriptor* descriptor) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorFactory); }; // Factory that creates generators for immutable-default messages. class ImmutableGeneratorFactory : public GeneratorFactory { public: ImmutableGeneratorFactory(Context* context); - ImmutableGeneratorFactory(const ImmutableGeneratorFactory&) = delete; - ImmutableGeneratorFactory& operator=(const ImmutableGeneratorFactory&) = - delete; ~ImmutableGeneratorFactory() override; MessageGenerator* NewMessageGenerator( @@ -93,6 +91,7 @@ class ImmutableGeneratorFactory : public GeneratorFactory { private: Context* context_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableGeneratorFactory); }; diff --git a/libs/protobuf/src/google/protobuf/compiler/java/helpers.cc b/libs/protobuf/src/google/protobuf/compiler/java/helpers.cc index 553f004..15ee8f5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/helpers.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/helpers.cc @@ -32,29 +32,25 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/helpers.h" +#include #include #include #include +#include #include -#include "google/protobuf/wire_format.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/container/flat_hash_set.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include // for hash // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -69,9 +65,78 @@ const char kThickSeparator[] = const char kThinSeparator[] = "// -------------------------------------------------------------------\n"; +namespace { + +const char* kDefaultPackage = ""; + +// Names that should be avoided (in UpperCamelCase format). +// Using them will cause the compiler to generate accessors whose names +// collide with methods defined in base classes. +// Keep this list in sync with specialFieldNames in +// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java +const char* kForbiddenWordList[] = { + // java.lang.Object: + "Class", + // com.google.protobuf.MessageLiteOrBuilder: + "DefaultInstanceForType", + // com.google.protobuf.MessageLite: + "ParserForType", + "SerializedSize", + // com.google.protobuf.MessageOrBuilder: + "AllFields", + "DescriptorForType", + "InitializationErrorString", + "UnknownFields", + // obsolete. kept for backwards compatibility of generated code + "CachedSize", +}; + +const std::unordered_set* kReservedNames = + new std::unordered_set({ + "abstract", "assert", "boolean", "break", "byte", + "case", "catch", "char", "class", "const", + "continue", "default", "do", "double", "else", + "enum", "extends", "final", "finally", "float", + "for", "goto", "if", "implements", "import", + "instanceof", "int", "interface", "long", "native", + "new", "package", "private", "protected", "public", + "return", "short", "static", "strictfp", "super", + "switch", "synchronized", "this", "throw", "throws", + "transient", "try", "void", "volatile", "while", + }); + +bool IsForbidden(const std::string& field_name) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) { + if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) { + return true; + } + } + return false; +} + +std::string FieldName(const FieldDescriptor* field) { + std::string field_name; + // Groups are hacky: The name of the field is just the lower-cased name + // of the group type. In Java, though, we would like to retain the original + // capitalization of the type name. + if (GetType(field) == FieldDescriptor::TYPE_GROUP) { + field_name = field->message_type()->name(); + } else { + field_name = field->name(); + } + if (IsForbidden(field_name)) { + // Append a trailing "#" to indicate that the name should be decorated to + // avoid collision with other names. + field_name += "#"; + } + return field_name; +} + + +} // namespace + void PrintGeneratedAnnotation(io::Printer* printer, char delimiter, - const std::string& annotation_file, - Options options) { + const std::string& annotation_file) { if (annotation_file.empty()) { return; } @@ -90,8 +155,8 @@ void PrintEnumVerifierLogic(io::Printer* printer, const char* var_name, const char* terminating_string, bool enforce_lite) { std::string enum_verifier_string = - enforce_lite ? absl::StrCat(var_name, ".internalGetVerifier()") - : absl::StrCat( + enforce_lite ? StrCat(var_name, ".internalGetVerifier()") + : StrCat( "new com.google.protobuf.Internal.EnumVerifier() {\n" " @java.lang.Override\n" " public boolean isInRange(int number) {\n" @@ -102,7 +167,7 @@ void PrintEnumVerifierLogic(io::Printer* printer, " }"); printer->Print( variables, - absl::StrCat(enum_verifier_string, terminating_string).c_str()); + StrCat(enum_verifier_string, terminating_string).c_str()); } std::string UnderscoresToCamelCase(const std::string& input, @@ -151,7 +216,7 @@ std::string ToCamelCase(const std::string& input, bool lower_first) { if (i == '_') { capitalize_next = true; } else if (capitalize_next) { - result.push_back(absl::ascii_toupper(i)); + result.push_back(ToUpperCh(i)); capitalize_next = false; } else { result.push_back(i); @@ -160,43 +225,62 @@ std::string ToCamelCase(const std::string& input, bool lower_first) { // Lower-case the first letter. if (lower_first && !result.empty()) { - result[0] = absl::ascii_tolower(result[0]); + result[0] = ToLowerCh(result[0]); } return result; } -// Names that should be avoided as field names in Kotlin. -// All Kotlin hard keywords are in this list. -bool IsForbiddenKotlin(absl::string_view field_name) { - static const auto& kKotlinForbiddenNames = - *new absl::flat_hash_set({ - "as", "as?", "break", "class", "continue", "do", - "else", "false", "for", "fun", "if", "in", - "!in", "interface", "is", "!is", "null", "object", - "package", "return", "super", "this", "throw", "true", - "try", "typealias", "typeof", "val", "var", "when", - "while", - }); - - return kKotlinForbiddenNames.contains(field_name); +char ToUpperCh(char ch) { + return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch; } -std::string EscapeKotlinKeywords(std::string name) { - std::vector escaped_packages; - std::vector packages = absl::StrSplit(name, "."); // NOLINT - for (const std::string& package : packages) { - if (IsForbiddenKotlin(package)) { - escaped_packages.push_back("`" + package + "`"); - } else { - escaped_packages.push_back(package); - } +char ToLowerCh(char ch) { + return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch; +} + +std::string UnderscoresToCamelCase(const FieldDescriptor* field) { + return UnderscoresToCamelCase(FieldName(field), false); +} + +std::string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) { + return UnderscoresToCamelCase(FieldName(field), true); +} + +std::string CapitalizedFieldName(const FieldDescriptor* field) { + return UnderscoresToCapitalizedCamelCase(field); +} + +std::string UnderscoresToCamelCase(const MethodDescriptor* method) { + return UnderscoresToCamelCase(method->name(), false); +} + +std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) { + std::string name = UnderscoresToCamelCase(field); + if (kReservedNames->find(name) != kReservedNames->end()) { + return name + "_"; } - return absl::StrJoin(escaped_packages, "."); + return name; +} + +// Names that should be avoided as field names in Kotlin. +// All Kotlin hard keywords are in this list. +const std::unordered_set* kKotlinForbiddenNames = + new std::unordered_set({ + "as", "as?", "break", "class", "continue", "do", "else", + "false", "for", "fun", "if", "in", "!in", "interface", + "is", "!is", "null", "object", "package", "return", "super", + "this", "throw", "true", "try", "typealias", "typeof", "val", + "var", "when", "while", + }); + +bool IsForbiddenKotlin(const std::string& field_name) { + return kKotlinForbiddenNames->find(field_name) != + kKotlinForbiddenNames->end(); } std::string UniqueFileScopeIdentifier(const Descriptor* descriptor) { - return "static_" + absl::StrReplaceAll(descriptor->full_name(), {{".", "_"}}); + return "static_" + StringReplace(descriptor->full_name(), ".", "_", true); } std::string CamelCaseFieldName(const FieldDescriptor* field) { @@ -208,15 +292,57 @@ std::string CamelCaseFieldName(const FieldDescriptor* field) { } std::string FileClassName(const FileDescriptor* file, bool immutable) { - return ClassNameResolver().GetFileClassName(file, immutable); + ClassNameResolver name_resolver; + return name_resolver.GetFileClassName(file, immutable); +} + +std::string FileJavaPackage(const FileDescriptor* file, bool immutable) { + std::string result; + + if (file->options().has_java_package()) { + result = file->options().java_package(); + } else { + result = kDefaultPackage; + if (!file->package().empty()) { + if (!result.empty()) result += '.'; + result += file->package(); + } + } + + return result; +} + +std::string FileJavaPackage(const FileDescriptor* file) { + return FileJavaPackage(file, true /* immutable */); } std::string JavaPackageToDir(std::string package_name) { - std::string package_dir = absl::StrReplaceAll(package_name, {{".", "/"}}); + std::string package_dir = StringReplace(package_name, ".", "/", true); if (!package_dir.empty()) package_dir += "/"; return package_dir; } +std::string ClassName(const Descriptor* descriptor) { + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + +std::string ClassName(const EnumDescriptor* descriptor) { + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + +std::string ClassName(const ServiceDescriptor* descriptor) { + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + +std::string ClassName(const FileDescriptor* descriptor) { + ClassNameResolver name_resolver; + return name_resolver.GetClassName(descriptor, true); +} + + std::string ExtraMessageInterfaces(const Descriptor* descriptor) { std::string interfaces = "// @@protoc_insertion_point(message_implements:" + descriptor->full_name() + ")"; @@ -238,7 +364,7 @@ std::string ExtraMessageOrBuilderInterfaces(const Descriptor* descriptor) { std::string FieldConstantName(const FieldDescriptor* field) { std::string name = field->name() + "_FIELD_NUMBER"; - absl::AsciiStrToUpper(&name); + ToUpper(&name); return name; } @@ -393,7 +519,7 @@ std::string GetOneofStoredType(const FieldDescriptor* field) { case JAVATYPE_ENUM: return "java.lang.Integer"; case JAVATYPE_MESSAGE: - return ClassNameResolver().GetClassName(field->message_type(), true); + return ClassName(field->message_type()); default: return BoxedPrimitiveTypeName(javaType); } @@ -456,19 +582,19 @@ bool AllAscii(const std::string& text) { } std::string DefaultValue(const FieldDescriptor* field, bool immutable, - ClassNameResolver* name_resolver, Options options) { + ClassNameResolver* name_resolver) { // Switch on CppType since we need to know which default_value_* method // of FieldDescriptor to call. switch (field->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return absl::StrCat(field->default_value_int32()); + return StrCat(field->default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: // Need to print as a signed int since Java has no unsigned. - return absl::StrCat(static_cast(field->default_value_uint32())); + return StrCat(static_cast(field->default_value_uint32())); case FieldDescriptor::CPPTYPE_INT64: - return absl::StrCat(field->default_value_int64()) + "L"; + return StrCat(field->default_value_int64()) + "L"; case FieldDescriptor::CPPTYPE_UINT64: - return absl::StrCat(static_cast(field->default_value_uint64())) + + return StrCat(static_cast(field->default_value_uint64())) + "L"; case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field->default_value_double(); @@ -500,21 +626,21 @@ std::string DefaultValue(const FieldDescriptor* field, bool immutable, if (GetType(field) == FieldDescriptor::TYPE_BYTES) { if (field->has_default_value()) { // See comments in Internal.java for gory details. - return absl::Substitute( + return strings::Substitute( "com.google.protobuf.Internal.bytesDefaultValue(\"$0\")", - absl::CEscape(field->default_value_string())); + CEscape(field->default_value_string())); } else { return "com.google.protobuf.ByteString.EMPTY"; } } else { if (AllAscii(field->default_value_string())) { // All chars are ASCII. In this case CEscape() works fine. - return "\"" + absl::CEscape(field->default_value_string()) + "\""; + return "\"" + CEscape(field->default_value_string()) + "\""; } else { // See comments in Internal.java for gory details. - return absl::Substitute( + return strings::Substitute( "com.google.protobuf.Internal.stringDefaultValue(\"$0\")", - absl::CEscape(field->default_value_string())); + CEscape(field->default_value_string())); } } @@ -587,7 +713,7 @@ const char* bit_masks[] = { std::string GetBitFieldName(int index) { std::string varName = "bitField"; - varName += absl::StrCat(index); + varName += StrCat(index); varName += "_"; return varName; } @@ -680,8 +806,7 @@ bool IsReferenceType(JavaType type) { return false; } -const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable, - Options options) { +const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) { switch (GetType(field)) { case FieldDescriptor::TYPE_INT32: return "Int32"; @@ -798,7 +923,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { // already_seen is used to avoid checking the same type multiple times // (and also to protect against recursion). bool HasRequiredFields(const Descriptor* type, - absl::flat_hash_set* already_seen) { + std::unordered_set* already_seen) { if (already_seen->count(type) > 0) { // The type is already in cache. This means that either: // a. The type has no required fields. @@ -833,7 +958,7 @@ bool HasRequiredFields(const Descriptor* type, } bool HasRequiredFields(const Descriptor* type) { - absl::flat_hash_set already_seen; + std::unordered_set already_seen; return HasRequiredFields(type, &already_seen); } @@ -978,7 +1103,7 @@ void EscapeUtf16ToString(uint16_t code, std::string* output) { } else if (code >= 0x20 && code <= 0x7f) { output->push_back(static_cast(code)); } else { - output->append(absl::StrFormat("\\u%04x", code)); + output->append(StringPrintf("\\u%04x", code)); } } @@ -987,4 +1112,4 @@ void EscapeUtf16ToString(uint16_t code, std::string* output) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/helpers.h b/libs/protobuf/src/google/protobuf/compiler/java/helpers.h index 9273ae3..9f1a557 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/helpers.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/helpers.h @@ -38,15 +38,10 @@ #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/compiler/java/names.h" -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/descriptor.pb.h" - -// Must be last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -58,7 +53,7 @@ namespace java { extern const char kThickSeparator[]; extern const char kThinSeparator[]; -bool IsForbiddenKotlin(absl::string_view field_name); +bool IsForbiddenKotlin(const std::string& field_name); // If annotation_file is non-empty, prints a javax.annotation.Generated // annotation to the given Printer. annotation_file will be referenced in the @@ -69,8 +64,7 @@ bool IsForbiddenKotlin(absl::string_view field_name); // annotation_file should be generated from the filename of the source file // being annotated (which in turn must be a Java identifier plus ".java"). void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$', - const std::string& annotation_file = "", - Options options = {}); + const std::string& annotation_file = ""); // If a GeneratedMessageLite contains non-lite enums, then its verifier // must be instantiated inline, rather than retrieved from the enum class. @@ -84,6 +78,25 @@ void PrintEnumVerifierLogic(io::Printer* printer, // first letter. std::string ToCamelCase(const std::string& input, bool lower_first); +char ToUpperCh(char ch); +char ToLowerCh(char ch); + +// Converts a name to camel-case. If cap_first_letter is true, capitalize the +// first letter. +std::string UnderscoresToCamelCase(const std::string& name, + bool cap_first_letter); +// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes +// "fooBarBaz" or "FooBarBaz", respectively. +std::string UnderscoresToCamelCase(const FieldDescriptor* field); +std::string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); + +// Similar, but for method names. (Typically, this merely has the effect +// of lower-casing the first letter of the name.) +std::string UnderscoresToCamelCase(const MethodDescriptor* method); + +// Same as UnderscoresToCamelCase, but checks for reserved keywords +std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field); + // Similar to UnderscoresToCamelCase, but guarantees that the result is a // complete Java identifier by adding a _ if needed. std::string CamelCaseFieldName(const FieldDescriptor* field); @@ -100,15 +113,11 @@ std::string UniqueFileScopeIdentifier(const Descriptor* descriptor); std::string FileClassName(const FileDescriptor* file, bool immutable = true); // Returns the file's Java package name. -std::string FileJavaPackage(const FileDescriptor* file, bool immutable, - Options options = {}); +std::string FileJavaPackage(const FileDescriptor* file, bool immutable); // Returns output directory for the given package name. std::string JavaPackageToDir(std::string package_name); -// Returns the name with Kotlin keywords enclosed in backticks -std::string EscapeKotlinKeywords(std::string name); - // Comma-separate list of option-specified interfaces implemented by the // Message, to follow the "implements" declaration of the Message definition. std::string ExtraMessageInterfaces(const Descriptor* descriptor); @@ -189,6 +198,18 @@ std::string AnnotationFileName(const Descriptor* descriptor, return descriptor->name() + suffix + ".java.pb.meta"; } +template +void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer, + Descriptor* descriptor, bool immutable, + const std::string& suffix = "") { + if (IsOwnFile(descriptor, immutable)) { + PrintGeneratedAnnotation(printer, '$', + context->options().annotate_code + ? AnnotationFileName(descriptor, suffix) + : ""); + } +} + // Get the unqualified name that should be used for a field's field // number constant. std::string FieldConstantName(const FieldDescriptor* field); @@ -230,12 +251,10 @@ const char* FieldTypeName(const FieldDescriptor::Type field_type); class ClassNameResolver; std::string DefaultValue(const FieldDescriptor* field, bool immutable, - ClassNameResolver* name_resolver, - Options options = {}); + ClassNameResolver* name_resolver); inline std::string ImmutableDefaultValue(const FieldDescriptor* field, - ClassNameResolver* name_resolver, - Options options = {}) { - return DefaultValue(field, true, name_resolver, options); + ClassNameResolver* name_resolver) { + return DefaultValue(field, true, name_resolver); } bool IsDefaultValueJavaDefault(const FieldDescriptor* field); bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field); @@ -314,8 +333,7 @@ bool IsReferenceType(JavaType type); // Returns the capitalized name for calling relative functions in // CodedInputStream -const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable, - Options options); +const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable); // For encodings with fixed sizes, returns that size in bytes. Otherwise // returns -1. @@ -453,5 +471,4 @@ std::pair GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/java_generator.h b/libs/protobuf/src/google/protobuf/compiler/java/java_generator.h index 45d30a5..294b1bd 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/java_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/java_generator.h @@ -1,36 +1,6 @@ -// 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_COMPILER_JAVA_JAVA_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ -#include "google/protobuf/compiler/java/generator.h" +#include #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_JAVA_GENERATOR_H_ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.cc b/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.cc index 3470ccb..1af548a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.cc @@ -28,13 +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. -#include "google/protobuf/compiler/java/kotlin_generator.h" +#include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/java/file.h" -#include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/options.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.h b/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.h index 312b653..ccd9688 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/kotlin_generator.h @@ -35,10 +35,10 @@ #include -#include "google/protobuf/compiler/code_generator.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -52,8 +52,6 @@ namespace java { class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { public: KotlinGenerator(); - KotlinGenerator(const KotlinGenerator&) = delete; - KotlinGenerator& operator=(const KotlinGenerator&) = delete; ~KotlinGenerator() override; // implements CodeGenerator ---------------------------------------- @@ -61,6 +59,9 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { GeneratorContext* context, std::string* error) const override; uint64_t GetSupportedFeatures() const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(KotlinGenerator); }; } // namespace java @@ -68,6 +69,6 @@ class PROTOC_EXPORT KotlinGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_KOTLIN_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/map_field.cc b/libs/protobuf/src/google/protobuf/compiler/java/map_field.cc index 2b69bb6..777f107 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/map_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/map_field.cc @@ -88,10 +88,10 @@ std::string WireType(const FieldDescriptor* field) { std::string(FieldTypeName(field->type())); } -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - Context* context, - std::map* variables) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, Context* context, + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); ClassNameResolver* name_resolver = context->GetNameResolver(); @@ -102,12 +102,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, const JavaType keyJavaType = GetJavaType(key); const JavaType valueJavaType = GetJavaType(value); - // The code that generates the open-source version appears not to understand - // #else, so we have an #ifndef instead. - std::string pass_through_nullness = - context->options().opensource_runtime - ? "/* nullable */\n" - : "@com.google.protobuf.Internal.ProtoPassThroughNullness "; + std::string pass_through_nullness = "/* nullable */\n"; (*variables)["key_type"] = TypeName(key, name_resolver, false); std::string boxed_key_type = TypeName(key, name_resolver, true); @@ -118,75 +113,87 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["short_key_type"] = boxed_key_type.substr(boxed_key_type.rfind('.') + 1); (*variables)["key_wire_type"] = WireType(key); - (*variables)["key_default_value"] = - DefaultValue(key, true, name_resolver, context->options()); + (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver); (*variables)["key_null_check"] = IsReferenceType(keyJavaType) ? "if (key == null) { throw new NullPointerException(\"map key\"); }" : ""; (*variables)["value_null_check"] = valueJavaType != JAVATYPE_ENUM && IsReferenceType(valueJavaType) - ? "if (value == null) {\n" - " throw new NullPointerException(\"map value\");\n" - "}\n" + ? "if (value == null) { " + "throw new NullPointerException(\"map value\"); }" : ""; if (valueJavaType == JAVATYPE_ENUM) { // We store enums as Integers internally. (*variables)["value_type"] = "int"; - (*variables)["value_type_pass_through_nullness"] = - (*variables)["value_type"]; + variables->insert( + {"value_type_pass_through_nullness", (*variables)["value_type"]}); (*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver, context->options()) + - ".getNumber()"; + DefaultValue(value, true, name_resolver) + ".getNumber()"; (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); - (*variables)["value_enum_type_pass_through_nullness"] = - pass_through_nullness + (*variables)["value_enum_type"]; + variables->insert( + {"value_enum_type_pass_through_nullness", + StrCat(pass_through_nullness, (*variables)["value_enum_type"])}); if (SupportUnknownEnumValue(descriptor->file())) { // Map unknown values to a special UNRECOGNIZED value if supported. - (*variables)["unrecognized_value"] = - (*variables)["value_enum_type"] + ".UNRECOGNIZED"; + variables->insert( + {"unrecognized_value", + StrCat((*variables)["value_enum_type"], ".UNRECOGNIZED")}); } else { // Map unknown values to the default value if we don't have UNRECOGNIZED. (*variables)["unrecognized_value"] = - DefaultValue(value, true, name_resolver, context->options()); + DefaultValue(value, true, name_resolver); } } else { (*variables)["value_type"] = TypeName(value, name_resolver, false); - (*variables)["value_type_pass_through_nullness"] = - (IsReferenceType(valueJavaType) ? pass_through_nullness : "") + - (*variables)["value_type"]; + variables->insert( + {"value_type_pass_through_nullness", + StrCat( + (IsReferenceType(valueJavaType) ? pass_through_nullness : ""), + (*variables)["value_type"])}); (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver, context->options()); + DefaultValue(value, true, name_resolver); } - (*variables)["type_parameters"] = - (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; + variables->insert( + {"type_parameters", StrCat((*variables)["boxed_key_type"], ", ", + (*variables)["boxed_value_type"])}); // TODO(birdo): Add @deprecated javadoc when generating javadoc is supported // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; - (*variables)["default_entry"] = - (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; - (*variables)["map_field_parameter"] = (*variables)["default_entry"]; + variables->insert( + {"default_entry", StrCat((*variables)["capitalized_name"], + "DefaultEntryHolder.defaultEntry")}); + variables->insert({"map_field_parameter", (*variables)["default_entry"]}); (*variables)["descriptor"] = name_resolver->GetImmutableClassName(descriptor->file()) + ".internal_" + UniqueFileScopeIdentifier(descriptor->message_type()) + "_descriptor, "; (*variables)["ver"] = GeneratedCodeVersionSuffix(); + + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["get_has_field_bit_from_local"] = + GenerateGetBitFromLocal(builderBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -195,6 +202,8 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), name_resolver_(context->GetNameResolver()), context_(context) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, @@ -204,6 +213,14 @@ ImmutableMapFieldGenerator::ImmutableMapFieldGenerator( ImmutableMapFieldGenerator::~ImmutableMapFieldGenerator() {} +int ImmutableMapFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableMapFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableMapFieldGenerator::GetNumBitsForMessage() const { return 0; } int ImmutableMapFieldGenerator::GetNumBitsForBuilder() const { return 1; } @@ -220,16 +237,14 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -267,30 +282,27 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$\n" - "$value_type_pass_through_nullness$ " + "$deprecation$$value_type_pass_through_nullness$ " "${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" - " $key_type$ key);\n"); + printer->Print( + variables_, + "$deprecation$$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$type_parameters$>\n" - "${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$type_parameters$>\n" + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" @@ -298,17 +310,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers( printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$\n" - "$value_type_pass_through_nullness$ " + "$deprecation$$value_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key);\n"); + printer->Print( + variables_, + "$deprecation$$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" + " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); } } @@ -364,42 +375,45 @@ void ImmutableMapFieldGenerator::GenerateMembers(io::Printer* printer) const { void ImmutableMapFieldGenerator::GenerateBuilderMembers( io::Printer* printer) const { - printer->Print(variables_, - "private com.google.protobuf.MapField<\n" - " $type_parameters$> $name$_;\n" - "private com.google.protobuf.MapField<$type_parameters$>\n" - "internalGet$capitalized_name$() {\n" - " if ($name$_ == null) {\n" - " return com.google.protobuf.MapField.emptyMapField(\n" - " $map_field_parameter$);\n" - " }\n" - " return $name$_;\n" - "}\n" - "private com.google.protobuf.MapField<$type_parameters$>\n" - "internalGetMutable$capitalized_name$() {\n" - " $on_changed$;\n" - " if ($name$_ == null) {\n" - " $name$_ = com.google.protobuf.MapField.newMapField(\n" - " $map_field_parameter$);\n" - " }\n" - " if (!$name$_.isMutable()) {\n" - " $name$_ = $name$_.copy();\n" - " }\n" - " return $name$_;\n" - "}\n"); + printer->Print( + variables_, + "private com.google.protobuf.MapField<\n" + " $type_parameters$> $name$_;\n" + "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n" + " internalGet$capitalized_name$() {\n" + " if ($name$_ == null) {\n" + " return com.google.protobuf.MapField.emptyMapField(\n" + " $map_field_parameter$);\n" + " }\n" + " return $name$_;\n" + "}\n" + "$deprecation$private com.google.protobuf.MapField<$type_parameters$>\n" + " internalGetMutable$capitalized_name$() {\n" + " if ($name$_ == null) {\n" + " $name$_ = com.google.protobuf.MapField.newMapField(\n" + " $map_field_parameter$);\n" + " }\n" + " if (!$name$_.isMutable()) {\n" + " $name$_ = $name$_.copy();\n" + " }\n" + " $set_has_field_bit_builder$\n" + " $on_changed$\n" + " 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$public Builder ${$clear$capitalized_name$$}$() {\n" + " $clear_has_field_bit_builder$\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" + "$deprecation$public Builder ${$remove$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" @@ -407,21 +421,21 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use alternate mutation accessors instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$getMutable$capitalized_name$$}$() {\n" - " return internalGetAdapted$capitalized_name$Map(\n" - " internalGetMutable$capitalized_name$().getMutableMap());\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print( + variables_, + "/**\n" + " * Use alternate mutation accessors instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + " ${$getMutable$capitalized_name$$}$() {\n" + " $set_has_field_bit_builder$\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" @@ -431,9 +445,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, $name$ValueConverter.doBackward(value));\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -442,23 +458,24 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap())\n" " .putAll(values);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (SupportUnknownEnumValue(descriptor_->file())) { - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use alternate mutation accessors instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "${$getMutable$capitalized_name$Value$}$() {\n" - " return internalGetMutable$capitalized_name$().getMutableMap();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print( + variables_, + "/**\n" + " * Use alternate mutation accessors instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" + "${$getMutable$capitalized_name$Value$}$() {\n" + " $set_has_field_bit_builder$\n" + " return internalGetMutable$capitalized_name$().getMutableMap();\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -469,9 +486,11 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -479,100 +498,100 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers( " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .putAll(values);\n" + " $set_has_field_bit_builder$\n" " return this;\n" "}\n"); printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use alternate mutation accessors instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$>\n" - "${$getMutable$capitalized_name$$}$() {\n" - " return internalGetMutable$capitalized_name$().getMutableMap();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print( + variables_, + "/**\n" + " * Use alternate mutation accessors instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$type_parameters$>\n" + " ${$getMutable$capitalized_name$$}$() {\n" + " $set_has_field_bit_builder$\n" + " return 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_type$ value) {\n" " $key_null_check$\n" " $value_null_check$\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .put(key, value);\n" + " $set_has_field_bit_builder$\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$public Builder ${$putAll$capitalized_name$$}$(\n" + " java.util.Map<$type_parameters$> values) {\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .putAll(values);\n" + " $set_has_field_bit_builder$\n" + " return this;\n" + "}\n"); printer->Annotate("{", "}", descriptor_); } } void ImmutableMapFieldGenerator::GenerateMapGetters( io::Printer* printer) const { - printer->Print(variables_, - "$deprecation$\n" - "public int ${$get$capitalized_name$Count$}$() {\n" - " return internalGet$capitalized_name$().getMap().size();\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$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" "@java.lang.Override\n" - "public boolean ${$contains$capitalized_name$$}$(\n" + "$deprecation$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) { - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Override\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$$}$() {\n" + " return get$capitalized_name$Map();\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "$deprecation$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_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_enum_type_pass_through_nullness$ " + "$deprecation$public $value_enum_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type_pass_through_nullness$ defaultValue) {\n" @@ -584,12 +603,12 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " : defaultValue;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" + "$deprecation$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" @@ -600,6 +619,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( " return $name$ValueConverter.doForward(map.get(key));\n" "}\n"); printer->Annotate("{", "}", descriptor_); + if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -614,21 +634,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "${$get$capitalized_name$ValueMap$}$() {\n" - " return internalGet$capitalized_name$().getMap();\n" - "}\n"); + printer->Print(variables_, + "@java.lang.Override\n" + "$deprecation$public java.util.Map<$boxed_key_type$, " + "$boxed_value_type$>\n" + "${$get$capitalized_name$ValueMap$}$() {\n" + " return internalGet$capitalized_name$().getMap();\n" + "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type_pass_through_nullness$ " + "$deprecation$public $value_type_pass_through_nullness$ " "${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue) {\n" @@ -642,8 +660,8 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" + "$deprecation$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" @@ -656,24 +674,21 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> " - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Override\n" + "@java.lang.Deprecated\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_, "@java.lang.Override\n" - "$deprecation$\n" - "public java.util.Map<$type_parameters$> " + "$deprecation$public java.util.Map<$type_parameters$> " "${$get$capitalized_name$Map$}$() {\n" " return internalGet$capitalized_name$().getMap();\n" "}\n"); @@ -682,8 +697,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( printer->Print( variables_, "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type_pass_through_nullness$ " + "$deprecation$public $value_type_pass_through_nullness$ " "${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type_pass_through_nullness$ defaultValue) {\n" @@ -694,19 +708,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters( "}\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "@java.lang.Override\n" - "$deprecation$\n" - "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " java.util.Map<$type_parameters$> map =\n" - " internalGet$capitalized_name$().getMap();\n" - " if (!map.containsKey(key)) {\n" - " throw new java.lang.IllegalArgumentException();\n" - " }\n" - " return map.get(key);\n" - "}\n"); + printer->Print( + variables_, + "@java.lang.Override\n" + "$deprecation$public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" + " $key_type$ key) {\n" + " $key_null_check$\n" + " java.util.Map<$type_parameters$> map =\n" + " internalGet$capitalized_name$().getMap();\n" + " if (!map.containsKey(key)) {\n" + " throw new java.lang.IllegalArgumentException();\n" + " }\n" + " return map.get(key);\n" + "}\n"); printer->Annotate("{", "}", descriptor_); } } @@ -724,7 +738,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$kt_deprecation$ public val $kt_name$: " @@ -736,7 +750,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$get$capitalized_name$Map$}$()\n" " )\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@JvmName(\"put$kt_capitalized_name$\")\n" @@ -746,7 +760,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -758,7 +772,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " put(key, value)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -769,7 +783,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -781,7 +795,7 @@ void ImmutableMapFieldGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$putAll$capitalized_name$$}$(map)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -805,6 +819,7 @@ void ImmutableMapFieldGenerator::GenerateInitializationCode( void ImmutableMapFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { + // No need to clear the has-bit since we clear the bitField ints all at once. printer->Print(variables_, "internalGetMutable$capitalized_name$().clear();\n"); } @@ -813,14 +828,17 @@ void ImmutableMapFieldGenerator::GenerateMergingCode( io::Printer* printer) const { printer->Print(variables_, "internalGetMutable$capitalized_name$().mergeFrom(\n" - " other.internalGet$capitalized_name$());\n"); + " other.internalGet$capitalized_name$());\n" + "$set_has_field_bit_builder$\n"); } void ImmutableMapFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { printer->Print(variables_, - "result.$name$_ = internalGet$capitalized_name$();\n" - "result.$name$_.makeImmutable();\n"); + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = internalGet$capitalized_name$();\n" + " result.$name$_.makeImmutable();\n" + "}\n"); } void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( @@ -837,6 +855,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( "} else {\n" " internalGetMutable$capitalized_name$().getMutableMap().put(\n" " $name$__.getKey(), $name$__.getValue());\n" + " $set_has_field_bit_builder$\n" "}\n"); } else { printer->Print( @@ -845,7 +864,8 @@ void ImmutableMapFieldGenerator::GenerateBuilderParsingCode( "$name$__ = input.readMessage(\n" " $default_entry$.getParserForType(), extensionRegistry);\n" "internalGetMutable$capitalized_name$().getMutableMap().put(\n" - " $name$__.getKey(), $name$__.getValue());\n"); + " $name$__.getKey(), $name$__.getValue());\n" + "$set_has_field_bit_builder$\n"); } } void ImmutableMapFieldGenerator::GenerateSerializationCode( diff --git a/libs/protobuf/src/google/protobuf/compiler/java/map_field.h b/libs/protobuf/src/google/protobuf/compiler/java/map_field.h index 4341508..d54a28b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/map_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/map_field.h @@ -46,6 +46,8 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { ~ImmutableMapFieldGenerator() override; // implements ImmutableFieldGenerator --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -68,6 +70,8 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator { private: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; std::map variables_; ClassNameResolver* name_resolver_; Context* context_; diff --git a/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.cc index 22bc306..ed6f8f3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.cc @@ -28,18 +28,18 @@ // (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/compiler/java/map_field_lite.h" +#include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -104,18 +104,14 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, const JavaType keyJavaType = GetJavaType(key); const JavaType valueJavaType = GetJavaType(value); - std::string pass_through_nullness = - context->options().opensource_runtime - ? "/* nullable */\n" - : "@com.google.protobuf.Internal.ProtoPassThroughNullness "; + std::string pass_through_nullness = "/* nullable */\n"; (*variables)["key_type"] = TypeName(key, name_resolver, false); (*variables)["boxed_key_type"] = TypeName(key, name_resolver, true); (*variables)["kt_key_type"] = KotlinTypeName(key, name_resolver); (*variables)["kt_value_type"] = KotlinTypeName(value, name_resolver); (*variables)["key_wire_type"] = WireType(key); - (*variables)["key_default_value"] = - DefaultValue(key, true, name_resolver, context->options()); + (*variables)["key_default_value"] = DefaultValue(key, true, name_resolver); // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. (*variables)["key_null_check"] = @@ -130,13 +126,10 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, if (GetJavaType(value) == JAVATYPE_ENUM) { // We store enums as Integers internally. (*variables)["value_type"] = "int"; - (*variables)["value_type_pass_through_nullness"] = - (*variables)["value_type"]; (*variables)["boxed_value_type"] = "java.lang.Integer"; (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver, context->options()) + - ".getNumber()"; + DefaultValue(value, true, name_resolver) + ".getNumber()"; (*variables)["value_enum_type"] = TypeName(value, name_resolver, false); @@ -150,7 +143,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, } else { // Map unknown values to the default value if we don't have UNRECOGNIZED. (*variables)["unrecognized_value"] = - DefaultValue(value, true, name_resolver, context->options()); + DefaultValue(value, true, name_resolver); } } else { (*variables)["value_type"] = TypeName(value, name_resolver, false); @@ -162,7 +155,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["boxed_value_type"] = TypeName(value, name_resolver, true); (*variables)["value_wire_type"] = WireType(value); (*variables)["value_default_value"] = - DefaultValue(value, true, name_resolver, context->options()); + DefaultValue(value, true, name_resolver); } (*variables)["type_parameters"] = (*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"]; @@ -178,8 +171,6 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["default_entry"] = (*variables)["capitalized_name"] + "DefaultEntryHolder.defaultEntry"; - // { and } variables are used as delimiters when emitting annotations. - (*variables)["{"] = (*variables)["}"] = ""; } } // namespace @@ -210,16 +201,14 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( " $key_type$ key);\n"); printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -258,10 +247,9 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$\n" - "$value_type_pass_through_nullness$ " - "${$get$capitalized_name$ValueOrDefault$}$(\n" + "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" - " $value_type_pass_through_nullness$ defaultValue);\n"); + " $value_type$ defaultValue);\n"); printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -271,16 +259,14 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers( printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "java.util.Map<$type_parameters$>\n" - "${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "java.util.Map<$type_parameters$>\n" + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.Map<$type_parameters$>\n" @@ -317,12 +303,6 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " $value_wire_type$,\n" " $value_default_value$);\n" "}\n"); - if (!context_->options().opensource_runtime) { - printer->Print(variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.MAP)\n"); - } printer->Print(variables_, "private com.google.protobuf.MapFieldLite<\n" " $type_parameters$> $name$_ =\n" @@ -364,19 +344,16 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( " com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n" " $value_enum_type$.internalGetValueMap(),\n" " $unrecognized_value$);\n"); - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$$}$() {\n" + " return get$capitalized_name$Map();\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -396,10 +373,9 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( variables_, "@java.lang.Override\n" "$deprecation$\n" - "public $value_enum_type_pass_through_nullness$ " - "${$get$capitalized_name$OrDefault$}$(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" - " $value_enum_type_pass_through_nullness$ defaultValue) {\n" + " $value_enum_type$ defaultValue) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" " internalGet$capitalized_name$();\n" @@ -453,10 +429,9 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( variables_, "@java.lang.Override\n" "$deprecation$\n" - "public $value_type_pass_through_nullness$ " - "${$get$capitalized_name$ValueOrDefault$}$(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" - " $value_type_pass_through_nullness$ defaultValue) {\n" + " $value_type$ defaultValue) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" " internalGet$capitalized_name$();\n" @@ -481,19 +456,17 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> " - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Override\n" + "@java.lang.Deprecated\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_, "@java.lang.Override\n" @@ -509,10 +482,9 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers( variables_, "@java.lang.Override\n" "$deprecation$\n" - "public $value_type_pass_through_nullness$ " - "${$get$capitalized_name$OrDefault$}$(\n" + "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" - " $value_type_pass_through_nullness$ defaultValue) {\n" + " $value_type$ defaultValue) {\n" " $key_null_check$\n" " java.util.Map<$type_parameters$> map =\n" " internalGet$capitalized_name$();\n" @@ -624,19 +596,16 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { - if (context_->options().opensource_runtime) { - printer->Print( - variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$$}$() {\n" + " return get$capitalized_name$Map();\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" @@ -732,10 +701,9 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( variables_, "@java.lang.Override\n" "$deprecation$\n" - "public $value_type_pass_through_nullness$ " - "${$get$capitalized_name$ValueOrDefault$}$(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" - " $value_type_pass_through_nullness$ defaultValue) {\n" + " $value_type$ defaultValue) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" " instance.get$capitalized_name$ValueMap();\n" @@ -782,19 +750,17 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( printer->Annotate("{", "}", descriptor_); } } else { - if (context_->options().opensource_runtime) { - printer->Print(variables_, - "/**\n" - " * Use {@link #get$capitalized_name$Map()} instead.\n" - " */\n" - "@java.lang.Override\n" - "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> " - "${$get$capitalized_name$$}$() {\n" - " return get$capitalized_name$Map();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "/**\n" + " * Use {@link #get$capitalized_name$Map()} instead.\n" + " */\n" + "@java.lang.Override\n" + "@java.lang.Deprecated\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_, "@java.lang.Override\n" @@ -810,10 +776,9 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers( variables_, "@java.lang.Override\n" "$deprecation$\n" - "public $value_type_pass_through_nullness$ " - "${$get$capitalized_name$OrDefault$}$(\n" + "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" - " $value_type_pass_through_nullness$ defaultValue) {\n" + " $value_type$ defaultValue) {\n" " $key_null_check$\n" " java.util.Map<$type_parameters$> map =\n" " instance.get$capitalized_name$Map();\n" @@ -876,7 +841,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$kt_deprecation$ public val $kt_name$: " @@ -888,7 +853,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$get$capitalized_name$Map$}$()\n" " )\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@JvmName(\"put$kt_capitalized_name$\")\n" @@ -898,7 +863,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$put$capitalized_name$$}$(key, value)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -910,7 +875,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " put(key, value)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -921,7 +886,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$remove$capitalized_name$$}$(key)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -933,7 +898,7 @@ void ImmutableMapFieldLiteGenerator::GenerateKotlinDslMembers( " $kt_dsl_builder$.${$putAll$capitalized_name$$}$(map)\n" " }\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -959,4 +924,4 @@ std::string ImmutableMapFieldLiteGenerator::GetBoxedType() const { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.h index 46a2d9f..964f098 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/map_field_lite.h @@ -33,7 +33,7 @@ #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message.cc b/libs/protobuf/src/google/protobuf/compiler/java/message.cc index eae7bb3..a29d9a7 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/message.h" +#include #include #include @@ -40,27 +40,25 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/enum.h" -#include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/compiler/java/generator_factory.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/message_builder.h" -#include "google/protobuf/compiler/java/message_builder_lite.h" -#include "google/protobuf/compiler/java/message_serialization.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -117,7 +115,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables( std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); - vars["index"] = absl::StrCat(descriptor_->index()); + vars["index"] = StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type()); @@ -161,7 +159,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers( int bytecode_estimate = 0; std::map vars; vars["identifier"] = UniqueFileScopeIdentifier(descriptor_); - vars["index"] = absl::StrCat(descriptor_->index()); + vars["index"] = StrCat(descriptor_->index()); vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_); if (descriptor_->containing_type() != NULL) { vars["parent"] = UniqueFileScopeIdentifier(descriptor_->containing_type()); @@ -263,9 +261,6 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer( void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true, "OrBuilder"); - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } if (descriptor_->extension_range_count() > 0) { printer->Print( "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" @@ -298,7 +293,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { for (auto oneof : oneofs_) { printer->Print( "\n" - "$classname$.$oneof_capitalized_name$Case " + "public $classname$.$oneof_capitalized_name$Case " "get$oneof_capitalized_name$Case();\n", "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname", @@ -325,10 +320,6 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { WriteMessageDocComment(printer, descriptor_); MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true); - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } - // The builder_type stores the super type name of the nested Builder class. std::string builder_type; if (descriptor_->extension_range_count() > 0) { @@ -342,7 +333,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { " $classname$> implements\n" " $extra_interfaces$\n" " $classname$OrBuilder {\n"); - builder_type = absl::Substitute( + builder_type = strings::Substitute( "com.google.protobuf.GeneratedMessage$1.ExtendableBuilder<$0, ?>", name_resolver_->GetImmutableClassName(descriptor_), GeneratedCodeVersionSuffix()); @@ -356,7 +347,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { " $extra_interfaces$\n" " $classname$OrBuilder {\n"); builder_type = - absl::Substitute("com.google.protobuf.GeneratedMessage$0.Builder", + strings::Substitute("com.google.protobuf.GeneratedMessage$0.Builder", GeneratedCodeVersionSuffix()); } printer->Print("private static final long serialVersionUID = 0L;\n"); @@ -431,63 +422,54 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; - vars["oneof_index"] = absl::StrCat((oneof)->index()); - vars["{"] = ""; - vars["}"] = ""; + vars["oneof_index"] = StrCat((oneof)->index()); // oneofCase_ and oneof_ printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" - "@SuppressWarnings(\"serial\")\n" "private java.lang.Object $oneof_name$_;\n"); // OneofCase enum printer->Print( vars, - "public enum ${$$oneof_capitalized_name$Case$}$\n" + "public enum $oneof_capitalized_name$Case\n" // TODO(dweis): Remove EnumLite when we want to break compatibility with // 3.x users " implements com.google.protobuf.Internal.EnumLite,\n" " com.google.protobuf.AbstractMessage.InternalOneOfEnum {\n"); - printer->Annotate("{", "}", oneof); printer->Indent(); for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print( "$deprecation$$field_name$($field_number$),\n", "deprecation", field->options().deprecated() ? "@java.lang.Deprecated " : "", - "field_name", absl::AsciiStrToUpper(field->name()), "field_number", - absl::StrCat(field->number())); - printer->Annotate("field_name", field); + "field_name", ToUpper(field->name()), "field_number", + StrCat(field->number())); } printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name", - absl::AsciiStrToUpper(vars["oneof_name"])); + ToUpper(vars["oneof_name"])); printer->Print(vars, "private final int value;\n" "private $oneof_capitalized_name$Case(int value) {\n" " this.value = value;\n" "}\n"); - if (context_->options().opensource_runtime) { - printer->Print( - vars, - "/**\n" - " * @param value The number of the enum to look for.\n" - " * @return The enum associated with the given number.\n" - " * @deprecated Use {@link #forNumber(int)} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public static $oneof_capitalized_name$Case valueOf(int value) {\n" - " return forNumber(value);\n" - "}\n" - "\n"); - } printer->Print( vars, + "/**\n" + " * @param value The number of the enum to look for.\n" + " * @return The enum associated with the given number.\n" + " * @deprecated Use {@link #forNumber(int)} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public static $oneof_capitalized_name$Case valueOf(int value) {\n" + " return forNumber(value);\n" + "}\n" + "\n" "public static $oneof_capitalized_name$Case forNumber(int value) {\n" " switch (value) {\n"); for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print(" case $field_number$: return $field_name$;\n", - "field_number", absl::StrCat(field->number()), - "field_name", absl::AsciiStrToUpper(field->name())); + "field_number", StrCat(field->number()), + "field_name", ToUpper(field->name())); } printer->Print( " case 0: return $cap_oneof_name$_NOT_SET;\n" @@ -497,18 +479,17 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "public int getNumber() {\n" " return this.value;\n" "}\n", - "cap_oneof_name", absl::AsciiStrToUpper(vars["oneof_name"])); + "cap_oneof_name", ToUpper(vars["oneof_name"])); printer->Outdent(); printer->Print("};\n\n"); // oneofCase() printer->Print(vars, "public $oneof_capitalized_name$Case\n" - "${$get$oneof_capitalized_name$Case$}$() {\n" + "get$oneof_capitalized_name$Case() {\n" " return $oneof_capitalized_name$Case.forNumber(\n" " $oneof_name$Case_);\n" "}\n" "\n"); - printer->Annotate("{", "}", oneof); } if (IsAnyMessage(descriptor_)) { @@ -519,7 +500,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("public static final int $constant_name$ = $number$;\n", "constant_name", FieldConstantName(descriptor_->field(i)), - "number", absl::StrCat(descriptor_->field(i)->number())); + "number", StrCat(descriptor_->field(i)->number())); printer->Annotate("constant_name", descriptor_->field(i)); field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); printer->Print("\n"); @@ -599,6 +580,13 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods( std::unique_ptr sorted_fields( SortFieldsByNumber(descriptor_)); + std::vector sorted_extensions; + sorted_extensions.reserve(descriptor_->extension_range_count()); + 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(), + ExtensionRangeOrdering()); printer->Print( "@java.lang.Override\n" "public void writeTo(com.google.protobuf.CodedOutputStream output)\n" @@ -633,8 +621,19 @@ void ImmutableMessageGenerator::GenerateMessageSerializationMethods( } } - GenerateSerializeFieldsAndExtensions(printer, field_generators_, descriptor_, - sorted_fields.get()); + // Merge the fields and the extension ranges, both sorted by field number. + for (int i = 0, j = 0; + i < descriptor_->field_count() || j < sorted_extensions.size();) { + if (i == descriptor_->field_count()) { + GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); + } else if (j == sorted_extensions.size()) { + GenerateSerializeOneField(printer, sorted_fields[i++]); + } else if (sorted_fields[i]->number() < sorted_extensions[j]->start) { + GenerateSerializeOneField(printer, sorted_fields[i++]); + } else { + GenerateSerializeOneExtensionRange(printer, sorted_extensions[j++]); + } + } if (descriptor_->options().message_set_wire_format()) { printer->Print("getUnknownFields().writeAsMessageSetTo(output);\n"); @@ -765,6 +764,17 @@ void ImmutableMessageGenerator::GenerateParseFromMethods(io::Printer* printer) { GeneratedCodeVersionSuffix()); } +void ImmutableMessageGenerator::GenerateSerializeOneField( + io::Printer* printer, const FieldDescriptor* field) { + field_generators_.get(field).GenerateSerializationCode(printer); +} + +void ImmutableMessageGenerator::GenerateSerializeOneExtensionRange( + io::Printer* printer, const Descriptor::ExtensionRange* range) { + printer->Print("extensionWriter.writeUntil($end$, output);\n", "end", + StrCat(range->end)); +} + // =================================================================== void ImmutableMessageGenerator::GenerateBuilder(io::Printer* printer) { @@ -836,7 +846,7 @@ void ImmutableMessageGenerator::GenerateDescriptorMethods( printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", - "number", absl::StrCat(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -994,10 +1004,6 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( printer->Print( "@java.lang.Override\n" "public boolean equals("); - if (!context_->options().opensource_runtime) { - printer->Print( - "@com.google.protobuf.Internal.ProtoMethodAcceptsNullParameter\n"); - } printer->Print("final java.lang.Object obj) {\n"); printer->Indent(); printer->Print( @@ -1005,8 +1011,6 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( " return true;\n" "}\n" "if (!(obj instanceof $classname$)) {\n" - // don't simply return false because mutable and immutable types - // can be equal " return super.equals(obj);\n" "}\n" "$classname$ other = ($classname$) obj;\n" @@ -1046,7 +1050,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print("case $field_number$:\n", "field_number", - absl::StrCat(field->number())); + StrCat(field->number())); printer->Indent(); field_generators_.get(field).GenerateEqualsCode(printer); printer->Print("break;\n"); @@ -1121,7 +1125,7 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode( for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print("case $field_number$:\n", "field_number", - absl::StrCat(field->number())); + StrCat(field->number())); printer->Indent(); field_generators_.get(field).GenerateHashCode(printer); printer->Print("break;\n"); @@ -1269,8 +1273,7 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { " @kotlin.jvm.JvmSynthetic\n" " @kotlin.PublishedApi\n" " internal fun _build(): $message$ = _builder.build()\n", - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + "message", name_resolver_->GetClassName(descriptor_, true)); printer->Indent(); @@ -1291,7 +1294,7 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name, "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + name_resolver_->GetClassName(descriptor_, true)); } if (descriptor_->extension_range_count() > 0) { @@ -1304,15 +1307,8 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const { void ImmutableMessageGenerator::GenerateKotlinMembers( io::Printer* printer) const { - printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n", - "camelcase_name", - name_resolver_->GetKotlinFactoryName(descriptor_)); - - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); - } - printer->Print( + "@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n" "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " "kotlin.Unit): " "$message$ " @@ -1320,13 +1316,9 @@ void ImmutableMessageGenerator::GenerateKotlinMembers( " $message_kt$.Dsl._create($message$.newBuilder()).apply { block() " "}._build()\n", "camelcase_name", name_resolver_->GetKotlinFactoryName(descriptor_), - "message_kt", - EscapeKotlinKeywords( - name_resolver_->GetKotlinExtensionsClassName(descriptor_)), - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + "message_kt", name_resolver_->GetKotlinExtensionsClassName(descriptor_), + "message", name_resolver_->GetClassName(descriptor_, true)); - WriteMessageDocComment(printer, descriptor_, /* kdoc */ true); printer->Print("public object $name$Kt {\n", "name", descriptor_->name()); printer->Indent(); GenerateKotlinDsl(printer); @@ -1341,22 +1333,15 @@ void ImmutableMessageGenerator::GenerateKotlinMembers( void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers( io::Printer* printer) const { - printer->Print("@kotlin.jvm.JvmSynthetic\n"); - - if (context_->options().opensource_runtime) { - printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); - } - printer->Print( + "@kotlin.jvm.JvmSynthetic\n" "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> " - "kotlin.Unit): $message$ =\n" + "kotlin.Unit): " + "$message$ =\n" " $message_kt$.Dsl._create(this.toBuilder()).apply { block() " "}._build()\n\n", - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)), - "message_kt", - EscapeKotlinKeywords( - name_resolver_->GetKotlinExtensionsClassName(descriptor_))); + "message", name_resolver_->GetClassName(descriptor_, true), "message_kt", + name_resolver_->GetKotlinExtensionsClassName(descriptor_)); for (int i = 0; i < descriptor_->nested_type_count(); i++) { if (IsMapEntry(descriptor_->nested_type(i))) continue; @@ -1374,21 +1359,18 @@ void ImmutableMessageGenerator::GenerateKotlinOrNull(io::Printer* printer) const printer->Print( "public val $full_classname$OrBuilder.$camelcase_name$OrNull: $full_name$?\n" " get() = if (has$name$()) get$name$() else null\n\n", - "full_classname", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)), + "full_classname", name_resolver_->GetClassName(descriptor_, true), "camelcase_name", context_->GetFieldGeneratorInfo(field)->name, "full_name", - EscapeKotlinKeywords( - name_resolver_->GetImmutableClassName(field->message_type())), - "name", context_->GetFieldGeneratorInfo(field)->capitalized_name); + name_resolver_->GetImmutableClassName(field->message_type()), "name", + context_->GetFieldGeneratorInfo(field)->capitalized_name); } } } void ImmutableMessageGenerator::GenerateKotlinExtensions( io::Printer* printer) const { - std::string message_name = - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)); + std::string message_name = name_resolver_->GetClassName(descriptor_, true); printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" @@ -1471,7 +1453,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions( printer->Print( "@kotlin.jvm.JvmSynthetic\n" "@Suppress(\"NOTHING_TO_INLINE\")\n" - "public inline operator fun set(\n" + "inline operator fun set(\n" " extension: com.google.protobuf.ExtensionLite<$message$, T>,\n" " value: T\n" ") {\n" @@ -1587,14 +1569,12 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { " defaultInstance.getDescriptorForType().getFullName());\n" "}\n" "\n" - "@SuppressWarnings(\"serial\")\n" "private volatile com.google.protobuf.Message cachedUnpackValue;\n" "\n" "@java.lang.SuppressWarnings(\"unchecked\")\n" "public T unpack(\n" " java.lang.Class clazz)\n" - " throws com.google.protobuf.InvalidProtocolBufferException {\n"); - printer->Print( + " throws com.google.protobuf.InvalidProtocolBufferException {\n" " boolean invalidClazz = false;\n" " if (cachedUnpackValue != null) {\n" " if (cachedUnpackValue.getClass() == clazz) {\n" @@ -1620,4 +1600,4 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message.h b/libs/protobuf/src/google/protobuf/compiler/java/message.h index 0380eab..2dbd0dd 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -64,8 +64,6 @@ static const int kMaxStaticSize = 1 << 15; // aka 32k class MessageGenerator { public: explicit MessageGenerator(const Descriptor* descriptor); - MessageGenerator(const MessageGenerator&) = delete; - MessageGenerator& operator=(const MessageGenerator&) = delete; virtual ~MessageGenerator(); // All static variables have to be declared at the top-level of the file @@ -95,14 +93,14 @@ class MessageGenerator { protected: const Descriptor* descriptor_; std::set oneofs_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator); }; class ImmutableMessageGenerator : public MessageGenerator { public: ImmutableMessageGenerator(const Descriptor* descriptor, Context* context); - ImmutableMessageGenerator(const ImmutableMessageGenerator&) = delete; - ImmutableMessageGenerator& operator=(const ImmutableMessageGenerator&) = - delete; ~ImmutableMessageGenerator() override; void Generate(io::Printer* printer) override; @@ -125,6 +123,10 @@ class ImmutableMessageGenerator : public MessageGenerator { void GenerateMessageSerializationMethods(io::Printer* printer); void GenerateParseFromMethods(io::Printer* printer); + void GenerateSerializeOneField(io::Printer* printer, + const FieldDescriptor* field); + void GenerateSerializeOneExtensionRange( + io::Printer* printer, const Descriptor::ExtensionRange* range); void GenerateBuilder(io::Printer* printer); void GenerateIsInitialized(io::Printer* printer); @@ -141,6 +143,8 @@ class ImmutableMessageGenerator : public MessageGenerator { Context* context_; ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_builder.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_builder.cc index 150c4e6..32ad668 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_builder.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_builder.cc @@ -37,14 +37,14 @@ #include #include #include +#include #include #include "google/protobuf/io/coded_stream.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/substitute.h" +#include "google/protobuf/stubs/strutil.h" +#include "google/protobuf/stubs/substitute.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/enum.h" @@ -131,7 +131,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; - vars["oneof_index"] = absl::StrCat(oneof->index()); + vars["oneof_index"] = StrCat(oneof->index()); // oneofCase_ and oneof_ printer->Print(vars, "private int $oneof_name$Case_ = 0;\n" @@ -146,12 +146,11 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { "\n" "public Builder clear$oneof_capitalized_name$() {\n" " $oneof_name$Case_ = 0;\n" - " $oneof_name$_ = null;\n"); - printer->Print(" onChanged();\n"); - printer->Print( - " return this;\n" - "}\n" - "\n"); + " $oneof_name$_ = null;\n" + " onChanged();\n" + " return this;\n" + "}\n" + "\n"); } // Integers for bit fields. @@ -172,26 +171,24 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) { .GenerateBuilderMembers(printer); } - if (context_->options().opensource_runtime) { - // 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( - "@java.lang.Override\n" - "public final Builder setUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return super.setUnknownFields(unknownFields);\n" - "}\n" - "\n" - "@java.lang.Override\n" - "public final Builder mergeUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return super.mergeUnknownFields(unknownFields);\n" - "}\n" - "\n"); - } + // 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( + "@java.lang.Override\n" + "public final Builder setUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.setUnknownFields(unknownFields);\n" + "}\n" + "\n" + "@java.lang.Override\n" + "public final Builder mergeUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.mergeUnknownFields(unknownFields);\n" + "}\n" + "\n"); printer->Print( "\n" @@ -237,7 +234,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) { printer->Print( "case $number$:\n" " return internalGet$capitalized_name$();\n", - "number", absl::StrCat(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -262,7 +259,7 @@ void MessageBuilderGenerator::GenerateDescriptorMethods(io::Printer* printer) { printer->Print( "case $number$:\n" " return internalGetMutable$capitalized_name$();\n", - "number", absl::StrCat(field->number()), "capitalized_name", + "number", StrCat(field->number()), "capitalized_name", info->capitalized_name); } printer->Print( @@ -358,6 +355,11 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( " super.clear();\n"); printer->Indent(); + int totalBuilderInts = (descriptor_->field_count() + 31) / 32; + for (int i = 0; i < totalBuilderInts; i++) { + printer->Print("$bit_field_name$ = 0;\n", "bit_field_name", + GetBitFieldName(i)); + } for (int i = 0; i < descriptor_->field_count(); i++) { field_generators_.get(descriptor_->field(i)) @@ -409,135 +411,77 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( "\n", "classname", name_resolver_->GetImmutableClassName(descriptor_)); + GenerateBuildPartial(printer); + + // 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( "@java.lang.Override\n" - "public $classname$ buildPartial() {\n" - " $classname$ result = new $classname$(this);\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - - printer->Indent(); - - int totalBuilderBits = 0; - int totalMessageBits = 0; - for (int i = 0; i < descriptor_->field_count(); i++) { - const ImmutableFieldGenerator& field = - field_generators_.get(descriptor_->field(i)); - totalBuilderBits += field.GetNumBitsForBuilder(); - totalMessageBits += field.GetNumBitsForMessage(); - } - int totalBuilderInts = (totalBuilderBits + 31) / 32; - int totalMessageInts = (totalMessageBits + 31) / 32; - - // Local vars for from and to bit fields to avoid accessing the builder and - // message over and over for these fields. Seems to provide a slight - // perforamance improvement in micro benchmark and this is also what proto1 - // code does. - for (int i = 0; i < totalBuilderInts; i++) { - printer->Print("int from_$bit_field_name$ = $bit_field_name$;\n", - "bit_field_name", GetBitFieldName(i)); - } - for (int i = 0; i < totalMessageInts; i++) { - printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name", - GetBitFieldName(i)); - } - - // Output generation code for each field. - for (int i = 0; i < descriptor_->field_count(); i++) { - field_generators_.get(descriptor_->field(i)).GenerateBuildingCode(printer); - } - - // Copy the bit field results to the generated message - for (int i = 0; i < totalMessageInts; i++) { - printer->Print("result.$bit_field_name$ = to_$bit_field_name$;\n", - "bit_field_name", GetBitFieldName(i)); - } - - for (auto oneof : oneofs_) { - printer->Print("result.$oneof_name$Case_ = $oneof_name$Case_;\n", - "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); - } - - printer->Outdent(); - - printer->Print(" onBuilt();\n"); - - printer->Print( - " return result;\n" + "public Builder clone() {\n" + " return super.clone();\n" "}\n" - "\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); + "@java.lang.Override\n" + "public Builder setField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " java.lang.Object value) {\n" + " return super.setField(field, value);\n" + "}\n" + "@java.lang.Override\n" + "public Builder clearField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field) {\n" + " return super.clearField(field);\n" + "}\n" + "@java.lang.Override\n" + "public Builder clearOneof(\n" + " com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n" + " return super.clearOneof(oneof);\n" + "}\n" + "@java.lang.Override\n" + "public Builder setRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " int index, java.lang.Object value) {\n" + " return super.setRepeatedField(field, index, value);\n" + "}\n" + "@java.lang.Override\n" + "public Builder addRepeatedField(\n" + " com.google.protobuf.Descriptors.FieldDescriptor field,\n" + " java.lang.Object value) {\n" + " return super.addRepeatedField(field, value);\n" + "}\n"); - if (context_->options().opensource_runtime) { - // 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). + if (descriptor_->extension_range_count() > 0) { printer->Print( "@java.lang.Override\n" - "public Builder clone() {\n" - " return super.clone();\n" + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, Type> extension,\n" + " Type value) {\n" + " return super.setExtension(extension, value);\n" "}\n" "@java.lang.Override\n" - "public Builder setField(\n" - " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " java.lang.Object value) {\n" - " return super.setField(field, value);\n" + "public Builder setExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " int index, Type value) {\n" + " return super.setExtension(extension, index, value);\n" "}\n" "@java.lang.Override\n" - "public Builder clearField(\n" - " com.google.protobuf.Descriptors.FieldDescriptor field) {\n" - " return super.clearField(field);\n" + "public Builder addExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, java.util.List> extension,\n" + " Type value) {\n" + " return super.addExtension(extension, value);\n" "}\n" "@java.lang.Override\n" - "public Builder clearOneof(\n" - " com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n" - " return super.clearOneof(oneof);\n" - "}\n" - "@java.lang.Override\n" - "public Builder setRepeatedField(\n" - " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " int index, java.lang.Object value) {\n" - " return super.setRepeatedField(field, index, value);\n" - "}\n" - "@java.lang.Override\n" - "public Builder addRepeatedField(\n" - " com.google.protobuf.Descriptors.FieldDescriptor field,\n" - " java.lang.Object value) {\n" - " return super.addRepeatedField(field, value);\n" - "}\n"); - - if (descriptor_->extension_range_count() > 0) { - printer->Print( - "@java.lang.Override\n" - "public Builder setExtension(\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $classname$, Type> extension,\n" - " Type value) {\n" - " return super.setExtension(extension, value);\n" - "}\n" - "@java.lang.Override\n" - "public Builder setExtension(\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $classname$, java.util.List> extension,\n" - " int index, Type value) {\n" - " return super.setExtension(extension, index, value);\n" - "}\n" - "@java.lang.Override\n" - "public Builder addExtension(\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $classname$, java.util.List> extension,\n" - " Type value) {\n" - " return super.addExtension(extension, value);\n" - "}\n" - "@java.lang.Override\n" - "public Builder clearExtension(\n" - " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" - " $classname$, ?> extension) {\n" - " return super.clearExtension(extension);\n" - "}\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); - } + "public Builder clearExtension(\n" + " com.google.protobuf.GeneratedMessage.GeneratedExtension<\n" + " $classname$, ?> extension) {\n" + " return super.clearExtension(extension);\n" + "}\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); } // ----------------------------------------------------------------- @@ -580,7 +524,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( for (int j = 0; j < oneof->field_count(); j++) { const FieldDescriptor* field = oneof->field(j); printer->Print("case $field_name$: {\n", "field_name", - absl::AsciiStrToUpper(field->name())); + ToUpper(field->name())); printer->Indent(); field_generators_.get(field).GenerateMergingCode(printer); printer->Print("break;\n"); @@ -592,7 +536,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( " break;\n" "}\n", "cap_oneof_name", - absl::AsciiStrToUpper(context_->GetOneofGeneratorInfo(oneof)->name)); + ToUpper(context_->GetOneofGeneratorInfo(oneof)->name)); printer->Outdent(); printer->Print("}\n"); } @@ -615,6 +559,156 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods( } } +void MessageBuilderGenerator::GenerateBuildPartial(io::Printer* printer) { + printer->Print( + "@java.lang.Override\n" + "public $classname$ buildPartial() {\n" + " $classname$ result = new $classname$(this);\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + + printer->Indent(); + + // Handle the repeated fields first so that the "mutable bits" are cleared. + bool has_repeated_fields = false; + for (int i = 0; i < descriptor_->field_count(); ++i) { + if (descriptor_->field(i)->is_repeated() && + !IsMapField(descriptor_->field(i))) { + has_repeated_fields = true; + printer->Print("buildPartialRepeatedFields(result);\n"); + break; + } + } + + // One buildPartial#() per from_bit_field + int totalBuilderInts = (descriptor_->field_count() + 31) / 32; + if (totalBuilderInts > 0) { + for (int i = 0; i < totalBuilderInts; ++i) { + printer->Print( + "if ($bit_field_name$ != 0) { buildPartial$piece$(result); }\n", + "bit_field_name", GetBitFieldName(i), "piece", StrCat(i)); + } + } + + if (!oneofs_.empty()) { + printer->Print("buildPartialOneofs(result);\n"); + } + + printer->Outdent(); + printer->Print( + " onBuilt();\n" + " return result;\n" + "}\n" + "\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + + // Build Repeated Fields + if (has_repeated_fields) { + printer->Print( + "private void buildPartialRepeatedFields($classname$ result) {\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); + printer->Indent(); + for (int i = 0; i < descriptor_->field_count(); ++i) { + if (descriptor_->field(i)->is_repeated() && + !IsMapField(descriptor_->field(i))) { + const ImmutableFieldGenerator& field = + field_generators_.get(descriptor_->field(i)); + field.GenerateBuildingCode(printer); + } + } + printer->Outdent(); + printer->Print("}\n\n"); + } + + // Build non-oneof fields + int start_field = 0; + for (int i = 0; i < totalBuilderInts; i++) { + start_field = GenerateBuildPartialPiece(printer, i, start_field); + } + + // Build Oneofs + if (!oneofs_.empty()) { + printer->Print("private void buildPartialOneofs($classname$ result) {\n", + "classname", + name_resolver_->GetImmutableClassName(descriptor_)); + printer->Indent(); + for (auto oneof : oneofs_) { + printer->Print( + "result.$oneof_name$Case_ = $oneof_name$Case_;\n" + "result.$oneof_name$_ = this.$oneof_name$_;\n", + "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name); + for (int i = 0; i < oneof->field_count(); ++i) { + if (oneof->field(i)->message_type() != nullptr) { + const ImmutableFieldGenerator& field = + field_generators_.get(oneof->field(i)); + field.GenerateBuildingCode(printer); + } + } + } + printer->Outdent(); + printer->Print("}\n\n"); + } +} + +int MessageBuilderGenerator::GenerateBuildPartialPiece(io::Printer* printer, + int piece, + int first_field) { + printer->Print( + "private void buildPartial$piece$($classname$ result) {\n" + " int from_$bit_field_name$ = $bit_field_name$;\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_), "piece", + StrCat(piece), "bit_field_name", GetBitFieldName(piece)); + printer->Indent(); + std::set declared_to_bitfields; + + int bit = 0; + int next = first_field; + for (; bit < 32 && next < descriptor_->field_count(); ++next) { + const ImmutableFieldGenerator& field = + field_generators_.get(descriptor_->field(next)); + bit += field.GetNumBitsForBuilder(); + + // Skip oneof fields that are handled separately + if (IsRealOneof(descriptor_->field(next))) { + continue; + } + + // Skip repeated fields because they are currently handled + // in separate buildPartial sub-methods. + if (descriptor_->field(next)->is_repeated() && + !IsMapField(descriptor_->field(next))) { + continue; + } + // Skip fields without presence bits in the builder + if (field.GetNumBitsForBuilder() == 0) { + continue; + } + + // Track message bits if necessary + if (field.GetNumBitsForMessage() > 0) { + int to_bitfield = field.GetMessageBitIndex() / 32; + if (declared_to_bitfields.count(to_bitfield) == 0) { + printer->Print("int to_$bit_field_name$ = 0;\n", "bit_field_name", + GetBitFieldName(to_bitfield)); + declared_to_bitfields.insert(to_bitfield); + } + } + + // Copy the field from the builder to the message + field.GenerateBuildingCode(printer); + } + + // Copy the bit field results to the generated message + for (int to_bitfield : declared_to_bitfields) { + printer->Print("result.$bit_field_name$ |= to_$bit_field_name$;\n", + "bit_field_name", GetBitFieldName(to_bitfield)); + } + + printer->Outdent(); + printer->Print("}\n\n"); + + return next; +} + // =================================================================== void MessageBuilderGenerator::GenerateBuilderParsingMethods( @@ -681,7 +775,7 @@ void MessageBuilderGenerator::GenerateBuilderFieldParsingCase( io::Printer* printer, const FieldDescriptor* field) { uint32_t tag = WireFormatLite::MakeTag( field->number(), WireFormat::WireTypeForFieldType(field->type())); - std::string tagString = absl::StrCat(static_cast(tag)); + std::string tagString = StrCat(static_cast(tag)); printer->Print("case $tag$: {\n", "tag", tagString); printer->Indent(); @@ -700,7 +794,7 @@ void MessageBuilderGenerator::GenerateBuilderPackedFieldParsingCase( // packed version of this field regardless of field->options().packed(). uint32_t tag = WireFormatLite::MakeTag( field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); - std::string tagString = absl::StrCat(static_cast(tag)); + std::string tagString = StrCat(static_cast(tag)); printer->Print("case $tag$: {\n", "tag", tagString); printer->Indent(); diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_builder.h b/libs/protobuf/src/google/protobuf/compiler/java/message_builder.h index 5d37bb6..4b1cc7e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_builder.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_builder.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -63,14 +63,17 @@ class MessageBuilderGenerator { public: explicit MessageBuilderGenerator(const Descriptor* descriptor, Context* context); - MessageBuilderGenerator(const MessageBuilderGenerator&) = delete; - MessageBuilderGenerator& operator=(const MessageBuilderGenerator&) = delete; virtual ~MessageBuilderGenerator(); virtual void Generate(io::Printer* printer); private: void GenerateCommonBuilderMethods(io::Printer* printer); + void GenerateBuildPartial(io::Printer* printer); + int GenerateBuildPartialPiece(io::Printer* printer, int piece, + int first_field); + int GenerateBuildPartialPieceWithoutPresence(io::Printer* printer, int piece, + int first_field); void GenerateDescriptorMethods(io::Printer* printer); void GenerateBuilderParsingMethods(io::Printer* printer); void GenerateBuilderFieldParsingCases(io::Printer* printer); @@ -85,6 +88,8 @@ class MessageBuilderGenerator { ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; std::set oneofs_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.cc index 1f9d13e..526f949 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.cc @@ -32,30 +32,29 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/message_builder_lite.h" +#include #include #include #include -#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/enum.h" -#include "google/protobuf/compiler/java/extension.h" -#include "google/protobuf/compiler/java/generator_factory.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -82,50 +81,41 @@ MessageBuilderLiteGenerator::~MessageBuilderLiteGenerator() {} void MessageBuilderLiteGenerator::Generate(io::Printer* printer) { WriteMessageDocComment(printer, descriptor_); - std::map vars = { - {"{", ""}, - {"}", ""}, - {"classname", name_resolver_->GetImmutableClassName(descriptor_)}, - {"extra_interfaces", ExtraBuilderInterfaces(descriptor_)}, - {"extendible", - descriptor_->extension_range_count() > 0 ? "Extendable" : ""}, - }; printer->Print( - vars, - "public static final class ${$Builder$}$ extends\n" + "public static final class Builder extends\n" " com.google.protobuf.GeneratedMessageLite.$extendible$Builder<\n" " $classname$, Builder> implements\n" " $extra_interfaces$\n" - " $classname$OrBuilder {\n"); - printer->Annotate("{", "}", descriptor_); + " $classname$OrBuilder {\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_), + "extra_interfaces", ExtraBuilderInterfaces(descriptor_), "extendible", + descriptor_->extension_range_count() > 0 ? "Extendable" : ""); printer->Indent(); GenerateCommonBuilderMethods(printer); // oneof + std::map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; - vars["oneof_index"] = absl::StrCat(oneof->index()); + vars["oneof_index"] = StrCat(oneof->index()); // oneofCase() and clearOneof() printer->Print(vars, "@java.lang.Override\n" "public $oneof_capitalized_name$Case\n" - " ${$get$oneof_capitalized_name$Case$}$() {\n" + " get$oneof_capitalized_name$Case() {\n" " return instance.get$oneof_capitalized_name$Case();\n" - "}\n"); - printer->Annotate("{", "}", oneof); - printer->Print(vars, + "}\n" "\n" - "public Builder ${$clear$oneof_capitalized_name$$}$() {\n" + "public Builder clear$oneof_capitalized_name$() {\n" " copyOnWrite();\n" " instance.clear$oneof_capitalized_name$();\n" " return this;\n" "}\n" "\n"); - printer->Annotate("{", "}", oneof); } for (int i = 0; i < descriptor_->field_count(); i++) { @@ -163,4 +153,4 @@ void MessageBuilderLiteGenerator::GenerateCommonBuilderMethods( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.h index f21aec6..0d895fc 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_builder_lite.h @@ -38,7 +38,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -63,9 +63,6 @@ class MessageBuilderLiteGenerator { public: explicit MessageBuilderLiteGenerator(const Descriptor* descriptor, Context* context); - MessageBuilderLiteGenerator(const MessageBuilderLiteGenerator&) = delete; - MessageBuilderLiteGenerator& operator=(const MessageBuilderLiteGenerator&) = - delete; virtual ~MessageBuilderLiteGenerator(); virtual void Generate(io::Printer* printer); @@ -78,6 +75,8 @@ class MessageBuilderLiteGenerator { ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; std::set oneofs_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageBuilderLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_field.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_field.cc index 0e06ed7..5093be4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_field.cc @@ -39,6 +39,7 @@ #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" +#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -55,16 +56,16 @@ namespace java { namespace { -void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, - int builderBitIndex, const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetMessageVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + (*variables)["kt_type"] = (*variables)["type"]; (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -74,40 +75,31 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; (*variables)["ver"] = GeneratedCodeVersionSuffix(); (*variables)["get_parser"] = - ExposePublicParser(descriptor->message_type()->file()) && - context->options().opensource_runtime - ? "PARSER" - : "parser()"; + ExposePublicParser(descriptor->message_type()->file()) ? "PARSER" + : "parser()"; if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); // Note that these have a trailing ";". - (*variables)["set_has_field_bit_message"] = - GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != null"; + (*variables)["set_has_field_bit_to_local"] = ""; + variables->insert({"is_field_present_message", + StrCat((*variables)["name"], "_ != null")}); } // For repeated builders, one bit is used for whether the array is immutable. @@ -115,10 +107,13 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); } } // namespace @@ -129,6 +124,8 @@ ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), name_resolver_(context->GetNameResolver()), context_(context) { SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, @@ -138,13 +135,19 @@ ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator( ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {} +int ImmutableMessageFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableMessageFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableMessageFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableMessageFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutableMessageFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -177,24 +180,6 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $get_has_field_bit_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print( - variables_, - "@java.lang.Override\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_, - "@java.lang.Override\n" - "$deprecation$public $type$OrBuilder " - "${$get$capitalized_name$OrBuilder$}$() {\n" - " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); } else { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( @@ -204,24 +189,25 @@ void ImmutableMessageFieldGenerator::GenerateMembers( " return $name$_ != null;\n" "}\n"); printer->Annotate("{", "}", descriptor_); - WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print( - variables_, - "@java.lang.Override\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_, - "@java.lang.Override\n" - "$deprecation$public $type$OrBuilder " - "${$get$capitalized_name$OrBuilder$}$() {\n" - " return get$capitalized_name$();\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); } + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); + printer->Print( + variables_, + "@java.lang.Override\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_, + "@java.lang.Override\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$() {\n" + " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition( @@ -259,9 +245,6 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( // When using nested-builders, the code initially works just like the // non-nested builder case. It only creates a nested builder lazily on // demand and then forever delegates to it after creation. - - bool has_hasbit = HasHasbit(descriptor_); - printer->Print(variables_, "private $type$ $name$_;\n"); printer->Print(variables_, @@ -276,21 +259,11 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( // boolean hasField() WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - if (has_hasbit) { - printer->Print( - variables_, - "$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" - " return $name$Builder_ != null || $name$_ != null;\n" - "}\n"); - printer->Annotate("{", "}", descriptor_); - } + printer->Print(variables_, + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return $get_has_field_bit_builder$;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); // Field getField() WriteFieldAccessorDocComment(printer, descriptor_, GETTER); @@ -308,12 +281,12 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( "if (value == null) {\n" " throw new NullPointerException();\n" "}\n" - "$name$_ = value;\n" - "$on_changed$\n", + "$name$_ = value;\n", "$name$Builder_.setMessage(value);\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); // Field.Builder setField(Field.Builder builderForValue) @@ -323,58 +296,48 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", - "$name$_ = builderForValue.build();\n" - "$on_changed$\n", + "$name$_ = builderForValue.build();\n", "$name$Builder_.setMessage(builderForValue.build());\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); - // Field.Builder mergeField(Field value) + // Message.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)", - - has_hasbit - ? "if ($get_has_field_bit_builder$ &&\n" - " $name$_ != null &&\n" - " $name$_ != $type$.getDefaultInstance()) {\n" - " $name$_ =\n" - " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n" - "} else {\n" - " $name$_ = value;\n" - "}\n" - "$on_changed$\n" - : "if ($name$_ != null) {\n" - " $name$_ =\n" - " $type$.newBuilder($name$_).mergeFrom(value).buildPartial();\n" - "} else {\n" - " $name$_ = value;\n" - "}\n" - "$on_changed$\n", + "if ($get_has_field_bit_builder$ &&\n" + " $name$_ != null &&\n" + " $name$_ != $type$.getDefaultInstance()) {\n" + " get$capitalized_name$Builder().mergeFrom(value);\n" + "} else {\n" + " $name$_ = value;\n" + "}\n", "$name$Builder_.mergeFrom(value);\n", "$set_has_field_bit_builder$\n" + "$on_changed$\n" "return this;\n"); - // Field.Builder clearField() + // Message.Builder clearField() WriteFieldDocComment(printer, descriptor_); - PrintNestedBuilderFunction( - printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", - - "$name$_ = null;\n" - "$on_changed$\n", - - has_hasbit ? "$name$Builder_.clear();\n" - : "$name$_ = null;\n" - "$name$Builder_ = null;\n", - - "$clear_has_field_bit_builder$\n" - "return this;\n"); + printer->Print(variables_, + "$deprecation$public Builder clear$capitalized_name$() {\n" + " $clear_has_field_bit_builder$\n" + " $name$_ = null;\n" + " if ($name$Builder_ != null) {\n" + " $name$Builder_.dispose();\n" + " $name$Builder_ = null;\n" + " }\n" + " $on_changed$\n" + " return this;\n" + "}\n"); + // Field.Builder getFieldBuilder() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$.Builder " @@ -384,6 +347,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // FieldOrBuilder getFieldOrBuilder() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " @@ -396,6 +361,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( " }\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // SingleFieldBuilder getFieldFieldBuilder WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -416,7 +383,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers( void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -427,14 +394,13 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -454,9 +420,7 @@ void ImmutableMessageFieldGenerator::GenerateKotlinOrNull(io::Printer* printer) void ImmutableMessageFieldGenerator::GenerateFieldBuilderInitializationCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); - } + printer->Print(variables_, "get$capitalized_name$FieldBuilder();\n"); } void ImmutableMessageFieldGenerator::GenerateInitializationCode( @@ -464,17 +428,13 @@ void ImmutableMessageFieldGenerator::GenerateInitializationCode( void ImmutableMessageFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - PrintNestedBuilderCondition(printer, "$name$_ = null;\n", - - "$name$Builder_.clear();\n"); - printer->Print(variables_, "$clear_has_field_bit_builder$\n"); - } else { - PrintNestedBuilderCondition(printer, "$name$_ = null;\n", - - "$name$_ = null;\n" - "$name$Builder_ = null;\n"); - } + // No need to clear the has-bit since we clear the bitField ints all at once. + printer->Print(variables_, + "$name$_ = null;\n" + "if ($name$Builder_ != null) {\n" + " $name$Builder_.dispose();\n" + " $name$Builder_ = null;\n" + "}\n"); } void ImmutableMessageFieldGenerator::GenerateMergingCode( @@ -487,19 +447,15 @@ void ImmutableMessageFieldGenerator::GenerateMergingCode( void ImmutableMessageFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHasbit(descriptor_)) { - printer->Print(variables_, "if ($get_has_field_bit_from_local$) {\n"); - printer->Indent(); - PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", - "result.$name$_ = $name$Builder_.build();\n"); - printer->Outdent(); - printer->Print(variables_, - " $set_has_field_bit_to_local$;\n" - "}\n"); - } else { - PrintNestedBuilderCondition(printer, "result.$name$_ = $name$_;\n", - "result.$name$_ = $name$Builder_.build();\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$Builder_ == null\n" + " ? $name$_\n" + " : $name$Builder_.build();\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } + printer->Print("}\n"); } void ImmutableMessageFieldGenerator::GenerateBuilderParsingCode( @@ -580,6 +536,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateMembers( " return $has_oneof_case_message$;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + WriteFieldAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "@java.lang.Override\n" @@ -763,7 +720,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers( " $oneof_name$_ = null;\n" " }\n" " $set_oneof_case_message$;\n" - " $on_changed$;\n" + " $on_changed$\n" " return $name$Builder_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); @@ -780,16 +737,11 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderClearCode( void ImmutableMessageOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, "if ($has_oneof_case_message$) {\n"); - printer->Indent(); - - PrintNestedBuilderCondition( - printer, "result.$oneof_name$_ = $oneof_name$_;\n", - - "result.$oneof_name$_ = $name$Builder_.build();\n"); - - printer->Outdent(); - printer->Print("}\n"); + printer->Print(variables_, + "if ($has_oneof_case_message$ &&\n" + " $name$Builder_ != null) {\n" + " result.$oneof_name$_ = $name$Builder_.build();\n" + "}\n"); } void ImmutableMessageOneofFieldGenerator::GenerateMergingCode( @@ -839,11 +791,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateSerializedSizeCode( RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetMessageVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutableMessageFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutableMessageFieldGenerator:: ~RepeatedImmutableMessageFieldGenerator() {} @@ -897,6 +846,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_;\n" // note: unmodifiable list "}\n"); printer->Annotate("{", "}", descriptor_); + + // List getFieldOrBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -906,6 +857,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_;\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // int getFieldCount() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -914,6 +867,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.size();\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // Field getField(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -922,6 +877,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateMembers( " return $name$_.get(index);\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // FieldOrBuilder getFieldOrBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "@java.lang.Override\n" @@ -1147,7 +1104,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "return this;\n"); - // Builder clearAllRepeatedField() + // Builder clearRepeatedField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction( printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()", @@ -1174,6 +1131,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "return this;\n"); + // Field.Builder getRepeatedFieldBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1183,6 +1141,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // FieldOrBuilder getRepeatedFieldOrBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " @@ -1196,6 +1155,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // List getRepeatedFieldOrBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1209,6 +1169,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( "}\n"); printer->Annotate("{", "}", descriptor_); + // Field.Builder addRepeatedField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$.Builder " @@ -1217,6 +1178,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // Field.Builder addRepeatedFieldBuilder(int index) WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1226,6 +1189,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers( " index, $type$.getDefaultInstance());\n" "}\n"); printer->Annotate("{", "}", descriptor_); + + // List getRepeatedFieldBuilderList() WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, @@ -1398,7 +1363,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -1409,7 +1374,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -1420,7 +1385,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -1432,7 +1397,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -1443,7 +1408,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1456,7 +1421,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1468,7 +1433,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_field.h b/libs/protobuf/src/google/protobuf/compiler/java/message_field.h index 4fe5ac7..f16062f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_field.h @@ -70,6 +70,8 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -92,18 +94,20 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; std::map variables_; ClassNameResolver* name_resolver_; Context* context_; - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, - const char* nested_builder_case) const; - void PrintNestedBuilderFunction(io::Printer* printer, - const char* method_prototype, - const char* regular_case, - const char* nested_builder_case, - const char* trailing_code) const; + virtual void PrintNestedBuilderCondition( + io::Printer* printer, const char* regular_case, + const char* nested_builder_case) const; + virtual void PrintNestedBuilderFunction(io::Printer* printer, + const char* method_prototype, + const char* regular_case, + const char* nested_builder_case, + const char* trailing_code) const; private: void GenerateKotlinOrNull(io::Printer* printer) const; @@ -131,7 +135,8 @@ class ImmutableMessageOneofFieldGenerator void GenerateSerializedSizeCode(io::Printer* printer) const override; }; -class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableMessageFieldGenerator + : public ImmutableMessageFieldGenerator { public: explicit RepeatedImmutableMessageFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -164,18 +169,14 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator { std::string GetBoxedType() const override; protected: - const FieldDescriptor* descriptor_; - std::map variables_; - ClassNameResolver* name_resolver_; - - void PrintNestedBuilderCondition(io::Printer* printer, - const char* regular_case, - const char* nested_builder_case) const; + void PrintNestedBuilderCondition( + io::Printer* printer, const char* regular_case, + const char* nested_builder_case) const override; void PrintNestedBuilderFunction(io::Printer* printer, const char* method_prototype, const char* regular_case, const char* nested_builder_case, - const char* trailing_code) const; + const char* trailing_code) const override; }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.cc index d01ccc1..da96790 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.cc @@ -32,22 +32,22 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/message_field_lite.h" +#include #include #include #include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -59,13 +59,12 @@ namespace { void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["type"] = name_resolver->GetImmutableClassName(descriptor->message_type()); - (*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]); + (*variables)["kt_type"] = (*variables)["type"]; (*variables)["mutable_type"] = name_resolver->GetMutableClassName(descriptor->message_type()); (*variables)["group_or_message"] = @@ -109,9 +108,6 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex, // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. (*variables)["null_check"] = "value.getClass();\n"; - // Annotations often use { and } to determine ranges. - (*variables)["{"] = ""; - (*variables)["}"] = ""; } } // namespace @@ -122,11 +118,10 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), messageBitIndex_(messageBitIndex), - name_resolver_(context->GetNameResolver()), - context_(context) { + name_resolver_(context->GetNameResolver()) { SetMessageVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {} @@ -142,13 +137,9 @@ int ImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const { void ImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers( io::Printer* printer) const { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); - printer->Print(variables_, - "$deprecation$boolean ${$has$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n"); WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); } void ImmutableMessageFieldLiteGenerator::GenerateMembers( @@ -297,7 +288,7 @@ void ImmutableMessageFieldLiteGenerator::GenerateBuilderMembers( void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -308,14 +299,13 @@ void ImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -505,12 +495,10 @@ RepeatedImmutableMessageFieldLiteGenerator:: RepeatedImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) - : descriptor_(descriptor), - name_resolver_(context->GetNameResolver()), - context_(context) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetMessageVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } RepeatedImmutableMessageFieldLiteGenerator:: @@ -529,28 +517,17 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers( WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$java.util.List<$type$> \n" - " ${$get$capitalized_name$List$}$();\n"); - printer->Annotate("{", "}", descriptor_); - WriteFieldDocComment(printer, descriptor_); - printer->Print( - variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + " get$capitalized_name$List();\n"); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$$type$ get$capitalized_name$(int index);\n"); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$int get$capitalized_name$Count();\n"); } void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$)\n"); - } printer->Print( variables_, "private com.google.protobuf.Internal.ProtobufList<$type$> $name$_;\n"); @@ -832,7 +809,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -843,7 +820,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -854,7 +831,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -866,7 +843,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -877,7 +854,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -890,7 +867,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -902,7 +879,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( "}\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" @@ -918,4 +895,4 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.h index c5387a6..4253acc 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -62,10 +62,6 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { explicit ImmutableMessageFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableMessageFieldLiteGenerator( - const ImmutableMessageFieldLiteGenerator&) = delete; - ImmutableMessageFieldLiteGenerator& operator=( - const ImmutableMessageFieldLiteGenerator&) = delete; ~ImmutableMessageFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator @@ -86,9 +82,9 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator { std::map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; - Context* context_; private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldLiteGenerator); void GenerateKotlinOrNull(io::Printer* printer) const; }; @@ -98,10 +94,6 @@ class ImmutableMessageOneofFieldLiteGenerator ImmutableMessageOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableMessageOneofFieldLiteGenerator( - const ImmutableMessageOneofFieldLiteGenerator&) = delete; - ImmutableMessageOneofFieldLiteGenerator& operator=( - const ImmutableMessageOneofFieldLiteGenerator&) = delete; ~ImmutableMessageOneofFieldLiteGenerator() override; void GenerateMembers(io::Printer* printer) const override; @@ -109,6 +101,8 @@ class ImmutableMessageOneofFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector* output) const override; + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageOneofFieldLiteGenerator); }; class RepeatedImmutableMessageFieldLiteGenerator @@ -116,10 +110,6 @@ class RepeatedImmutableMessageFieldLiteGenerator public: explicit RepeatedImmutableMessageFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - RepeatedImmutableMessageFieldLiteGenerator( - const RepeatedImmutableMessageFieldLiteGenerator&) = delete; - RepeatedImmutableMessageFieldLiteGenerator& operator=( - const RepeatedImmutableMessageFieldLiteGenerator&) = delete; ~RepeatedImmutableMessageFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator ------------------------------------ @@ -138,7 +128,9 @@ class RepeatedImmutableMessageFieldLiteGenerator const FieldDescriptor* descriptor_; std::map variables_; ClassNameResolver* name_resolver_; - Context* context_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_lite.cc index 475a30b..9a85734 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_lite.cc @@ -32,34 +32,32 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/message_lite.h" +#include #include #include #include #include -#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/enum_lite.h" -#include "google/protobuf/compiler/java/extension_lite.h" -#include "google/protobuf/compiler/java/generator_factory.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/message_builder.h" -#include "google/protobuf/compiler/java/message_builder_lite.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -116,33 +114,26 @@ int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers( void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true, "OrBuilder"); - - std::map variables = { - {"{", ""}, - {"}", ""}, - {"deprecation", - descriptor_->options().deprecated() ? "@java.lang.Deprecated " : ""}, - {"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_)}, - {"classname", descriptor_->name()}, - }; - - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } if (descriptor_->extension_range_count() > 0) { printer->Print( - variables, "$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n" " $extra_interfaces$\n" " com.google.protobuf.GeneratedMessageLite.\n" " ExtendableMessageOrBuilder<\n" - " $classname$, $classname$.Builder> {\n"); + " $classname$, $classname$.Builder> {\n", + "deprecation", + descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), + "classname", descriptor_->name(), "{", "", "}", ""); } else { printer->Print( - variables, "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" " $extra_interfaces$\n" - " com.google.protobuf.MessageLiteOrBuilder {\n"); + " com.google.protobuf.MessageLiteOrBuilder {\n", + "deprecation", + descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", + "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), + "classname", descriptor_->name(), "{", "", "}", ""); } printer->Annotate("{", "}", descriptor_); @@ -153,15 +144,13 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { .GenerateInterfaceMembers(printer); } for (auto oneof : oneofs_) { - variables["oneof_capitalized_name"] = - context_->GetOneofGeneratorInfo(oneof)->capitalized_name; - variables["classname"] = - context_->GetNameResolver()->GetImmutableClassName(descriptor_); - printer->Print(variables, - "\n" - "public ${$$classname$.$oneof_capitalized_name$Case$}$ " - "get$oneof_capitalized_name$Case();\n"); - printer->Annotate("{", "}", oneof); + printer->Print( + "\n" + "public $classname$.$oneof_capitalized_name$Case " + "get$oneof_capitalized_name$Case();\n", + "oneof_capitalized_name", + context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "classname", + context_->GetNameResolver()->GetImmutableClassName(descriptor_)); } printer->Outdent(); @@ -173,7 +162,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true); - std::map variables = {{"{", ""}, {"}", ""}}; + std::map variables; variables["static"] = is_own_file ? " " : " static "; variables["classname"] = descriptor_->name(); variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_); @@ -190,18 +179,18 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { if (descriptor_->extension_range_count() > 0) { printer->Print( variables, - "$deprecation$public $static$final class ${$$classname$$}$ extends\n" + "$deprecation$public $static$final class $classname$ extends\n" " com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n" " $classname$, $classname$.Builder> implements\n" " $extra_interfaces$\n" " $classname$OrBuilder {\n"); - builder_type = absl::Substitute( + builder_type = strings::Substitute( "com.google.protobuf.GeneratedMessageLite.ExtendableBuilder<$0, ?>", name_resolver_->GetImmutableClassName(descriptor_)); } else { printer->Print( variables, - "$deprecation$public $static$final class ${$$classname$$}$ extends\n" + "$deprecation$public $static$final class $classname$ extends\n" " com.google.protobuf.GeneratedMessageLite<\n" " $classname$, $classname$.Builder> implements\n" " $extra_interfaces$\n" @@ -209,7 +198,6 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { builder_type = "com.google.protobuf.GeneratedMessageLite.Builder"; } - printer->Annotate("{", "}", descriptor_); printer->Indent(); GenerateConstructor(printer); @@ -242,57 +230,49 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { } // oneof - std::map vars = {{"{", ""}, {"}", ""}}; + std::map vars; for (auto oneof : oneofs_) { vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name; vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(oneof)->capitalized_name; - vars["oneof_index"] = absl::StrCat((oneof)->index()); - if (context_->options().opensource_runtime) { - // oneofCase_ and oneof_ - printer->Print(vars, - "private int $oneof_name$Case_ = 0;\n" - "private java.lang.Object $oneof_name$_;\n"); - } + vars["oneof_index"] = StrCat((oneof)->index()); + // oneofCase_ and oneof_ + printer->Print(vars, + "private int $oneof_name$Case_ = 0;\n" + "private java.lang.Object $oneof_name$_;\n"); // OneofCase enum - printer->Print(vars, "public enum ${$$oneof_capitalized_name$Case$}$ {\n"); - printer->Annotate("{", "}", oneof); + printer->Print(vars, "public enum $oneof_capitalized_name$Case {\n"); printer->Indent(); for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print("$field_name$($field_number$),\n", "field_name", - absl::AsciiStrToUpper(field->name()), "field_number", - absl::StrCat(field->number())); - printer->Annotate("field_name", field); + ToUpper(field->name()), "field_number", + StrCat(field->number())); } printer->Print("$cap_oneof_name$_NOT_SET(0);\n", "cap_oneof_name", - absl::AsciiStrToUpper(vars["oneof_name"])); + ToUpper(vars["oneof_name"])); printer->Print(vars, "private final int value;\n" "private $oneof_capitalized_name$Case(int value) {\n" " this.value = value;\n" "}\n"); - if (context_->options().opensource_runtime) { - printer->Print( - vars, - "/**\n" - " * @deprecated Use {@link #forNumber(int)} instead.\n" - " */\n" - "@java.lang.Deprecated\n" - "public static $oneof_capitalized_name$Case valueOf(int value) {\n" - " return forNumber(value);\n" - "}\n" - "\n"); - } printer->Print( vars, + "/**\n" + " * @deprecated Use {@link #forNumber(int)} instead.\n" + " */\n" + "@java.lang.Deprecated\n" + "public static $oneof_capitalized_name$Case valueOf(int value) {\n" + " return forNumber(value);\n" + "}\n" + "\n" "public static $oneof_capitalized_name$Case forNumber(int value) {\n" " switch (value) {\n"); for (int j = 0; j < (oneof)->field_count(); j++) { const FieldDescriptor* field = (oneof)->field(j); printer->Print(" case $field_number$: return $field_name$;\n", - "field_number", absl::StrCat(field->number()), - "field_name", absl::AsciiStrToUpper(field->name())); + "field_number", StrCat(field->number()), + "field_name", ToUpper(field->name())); } printer->Print( " case 0: return $cap_oneof_name$_NOT_SET;\n" @@ -304,34 +284,30 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { "public int getNumber() {\n" " return this.value;\n" "}\n", - "cap_oneof_name", absl::AsciiStrToUpper(vars["oneof_name"])); + "cap_oneof_name", ToUpper(vars["oneof_name"])); printer->Outdent(); printer->Print("};\n\n"); // oneofCase() printer->Print(vars, "@java.lang.Override\n" "public $oneof_capitalized_name$Case\n" - "${$get$oneof_capitalized_name$Case$}$() {\n" + "get$oneof_capitalized_name$Case() {\n" " return $oneof_capitalized_name$Case.forNumber(\n" " $oneof_name$Case_);\n" - "}\n"); - printer->Annotate("{", "}", oneof); - printer->Print(vars, + "}\n" "\n" - "private void ${$clear$oneof_capitalized_name$$}$() {\n" + "private void clear$oneof_capitalized_name$() {\n" " $oneof_name$Case_ = 0;\n" " $oneof_name$_ = null;\n" "}\n" "\n"); - printer->Annotate("{", "}", oneof); } // Fields for (int i = 0; i < descriptor_->field_count(); i++) { printer->Print("public static final int $constant_name$ = $number$;\n", "constant_name", FieldConstantName(descriptor_->field(i)), - "number", absl::StrCat(descriptor_->field(i)->number())); - printer->Annotate("constant_name", descriptor_->field(i)); + "number", StrCat(descriptor_->field(i)->number())); field_generators_.get(descriptor_->field(i)).GenerateMembers(printer); printer->Print("\n"); } @@ -771,8 +747,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( " @kotlin.jvm.JvmSynthetic\n" " @kotlin.PublishedApi\n" " internal fun _build(): $message$ = _builder.build()\n", - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + "message", name_resolver_->GetClassName(descriptor_, true)); printer->Indent(); @@ -793,7 +768,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( "oneof_name", context_->GetOneofGeneratorInfo(oneof)->name, "oneof_capitalized_name", context_->GetOneofGeneratorInfo(oneof)->capitalized_name, "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + name_resolver_->GetClassName(descriptor_, true)); } if (descriptor_->extension_range_count() > 0) { @@ -806,26 +781,17 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl( void ImmutableMessageLiteGenerator::GenerateKotlinMembers( io::Printer* printer) const { - printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n", - "camelcase_name", - name_resolver_->GetKotlinFactoryName(descriptor_)); - - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); - } printer->Print( + "@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n" "public inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> " - "kotlin.Unit): $message$ =\n" + "kotlin.Unit): " + "$message$ =\n" " $message_kt$.Dsl._create($message$.newBuilder()).apply { block() " "}._build()\n", "camelcase_name", name_resolver_->GetKotlinFactoryName(descriptor_), - "message_kt", - EscapeKotlinKeywords( - name_resolver_->GetKotlinExtensionsClassName(descriptor_)), - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); + "message_kt", name_resolver_->GetKotlinExtensionsClassName(descriptor_), + "message", name_resolver_->GetClassName(descriptor_, true)); - WriteMessageDocComment(printer, descriptor_, /* kdoc */ true); printer->Print("public object $name$Kt {\n", "name", descriptor_->name()); printer->Indent(); GenerateKotlinDsl(printer); @@ -840,19 +806,14 @@ void ImmutableMessageLiteGenerator::GenerateKotlinMembers( void ImmutableMessageLiteGenerator::GenerateTopLevelKotlinMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n"); - } printer->Print( "public inline fun $message$.copy(block: $message_kt$.Dsl.() -> " - "kotlin.Unit): $message$ =\n" + "kotlin.Unit): " + "$message$ =\n" " $message_kt$.Dsl._create(this.toBuilder()).apply { block() " "}._build()\n\n", - "message", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)), - "message_kt", - EscapeKotlinKeywords( - name_resolver_->GetKotlinExtensionsClassName(descriptor_))); + "message", name_resolver_->GetClassName(descriptor_, true), "message_kt", + name_resolver_->GetKotlinExtensionsClassName(descriptor_)); for (int i = 0; i < descriptor_->nested_type_count(); i++) { if (IsMapEntry(descriptor_->nested_type(i))) continue; @@ -872,21 +833,18 @@ void ImmutableMessageLiteGenerator::GenerateKotlinOrNull(io::Printer* printer) c "public val $full_classname$OrBuilder.$camelcase_name$OrNull: " "$full_name$?\n" " get() = if (has$name$()) get$name$() else null\n\n", - "full_classname", - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)), + "full_classname", name_resolver_->GetClassName(descriptor_, true), "camelcase_name", context_->GetFieldGeneratorInfo(field)->name, "full_name", - EscapeKotlinKeywords( - name_resolver_->GetImmutableClassName(field->message_type())), - "name", context_->GetFieldGeneratorInfo(field)->capitalized_name); + name_resolver_->GetImmutableClassName(field->message_type()), "name", + context_->GetFieldGeneratorInfo(field)->capitalized_name); } } } void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( io::Printer* printer) const { - std::string message_name = - EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true)); + std::string message_name = name_resolver_->GetClassName(descriptor_, true); printer->Print( "@Suppress(\"UNCHECKED_CAST\")\n" @@ -1042,4 +1000,4 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/message_lite.h index 2794040..d1e4b68 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/message_lite.h @@ -35,8 +35,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_LITE_H__ -#include "google/protobuf/compiler/java/field.h" -#include "google/protobuf/compiler/java/message.h" +#include +#include namespace google { namespace protobuf { @@ -46,9 +46,6 @@ namespace java { class ImmutableMessageLiteGenerator : public MessageGenerator { public: ImmutableMessageLiteGenerator(const Descriptor* descriptor, Context* context); - ImmutableMessageLiteGenerator(const ImmutableMessageLiteGenerator&) = delete; - ImmutableMessageLiteGenerator& operator=( - const ImmutableMessageLiteGenerator&) = delete; ~ImmutableMessageLiteGenerator() override; void Generate(io::Printer* printer) override; @@ -76,6 +73,8 @@ class ImmutableMessageLiteGenerator : public MessageGenerator { Context* context_; ClassNameResolver* name_resolver_; FieldGeneratorMap field_generators_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization.h b/libs/protobuf/src/google/protobuf/compiler/java/message_serialization.h deleted file mode 100644 index 3b11c47..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization.h +++ /dev/null @@ -1,103 +0,0 @@ -// 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_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__ - -#include -#include -#include - -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/java/field.h" -#include "google/protobuf/compiler/java/helpers.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// Generates code to serialize a single extension range. -void GenerateSerializeExtensionRange(io::Printer* printer, - const Descriptor::ExtensionRange* range); - -// Generates code to serialize all fields and extension ranges for the specified -// message descriptor, sorting serialization calls in increasing order by field -// number. -// -// Templatized to support different field generator implementations. -template -void GenerateSerializeFieldsAndExtensions( - io::Printer* printer, - const FieldGeneratorMap& field_generators, - const Descriptor* descriptor, const FieldDescriptor** sorted_fields) { - std::vector sorted_extensions; - sorted_extensions.reserve(descriptor->extension_range_count()); - 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(), - ExtensionRangeOrdering()); - - std::size_t range_idx = 0; - - // Merge the fields and the extension ranges, both sorted by field number. - for (int i = 0; i < descriptor->field_count(); ++i) { - const FieldDescriptor* field = sorted_fields[i]; - - // Collapse all extension ranges up until the next field. This leads to - // shorter and more efficient codegen for messages containing a large - // number of extension ranges without fields in between them. - const Descriptor::ExtensionRange* range = nullptr; - while (range_idx < sorted_extensions.size() && - sorted_extensions[range_idx]->end <= field->number()) { - range = sorted_extensions[range_idx++]; - } - - if (range != nullptr) { - GenerateSerializeExtensionRange(printer, range); - } - field_generators.get(field).GenerateSerializationCode(printer); - } - - // After serializing all fields, serialize any remaining extensions via a - // single writeUntil call. - if (range_idx < sorted_extensions.size()) { - GenerateSerializeExtensionRange(printer, sorted_extensions.back()); - } -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_MESSAGE_SERIALIZATION_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.cc deleted file mode 100644 index 2ef7309..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.cc +++ /dev/null @@ -1,125 +0,0 @@ -// 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 -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include -#include "google/protobuf/testing/googletest.h" -#include -#include "absl/strings/str_cat.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/test_util2.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { -namespace { - -using ::testing::ElementsAre; - -// Generates Java code for the specified Java proto, returning the compiler's -// exit status. -int CompileJavaProto(std::string proto_file_name) { - JavaGenerator java_generator; - - CommandLineInterface cli; - cli.RegisterGenerator("--java_out", &java_generator, /*help_text=*/""); - - std::string proto_path = absl::StrCat( - "--proto_path=", - TestUtil::GetTestDataPath("third_party/protobuf/compiler/java")); - std::string java_out = absl::StrCat("--java_out=", TestTempDir()); - - const char* argv[] = { - "protoc", - proto_path.c_str(), - java_out.c_str(), - proto_file_name.c_str(), - }; - - return cli.Run(4, argv); -} - -TEST(MessageSerializationTest, CollapseAdjacentExtensionRanges) { - GOOGLE_CHECK_EQ(CompileJavaProto("message_serialization_unittest.proto"), 0); - - std::string java_source; - GOOGLE_CHECK_OK(File::GetContents( - // Open-source codebase does not support file::JoinPath, so we manually - // concatenate instead. - absl::StrCat(TestTempDir(), - "/TestMessageWithManyExtensionRanges.java"), - &java_source, true)); - - // Open-source codebase does not support constexpr absl::string_view. - static constexpr const char kWriteUntilCall[] = "extensionWriter.writeUntil("; - - std::vector range_ends; - - // Open-source codebase does not have absl::StrSplit overload taking a single - // char delimiter. - // - // NOLINTNEXTLINE(abseil-faster-strsplit-delimiter) - for (const auto& line : absl::StrSplit(java_source, "\n")) { - // Extract end position from writeUntil call. (Open-source codebase does not - // support RE2.) - std::size_t write_until_pos = line.find(kWriteUntilCall); - if (write_until_pos == std::string::npos) { - continue; - } - write_until_pos += (sizeof(kWriteUntilCall) - 1); - - std::size_t comma_pos = line.find(',', write_until_pos); - if (comma_pos == std::string::npos) { - continue; - } - - range_ends.push_back( - std::string(line.substr(write_until_pos, comma_pos - write_until_pos))); - } - - EXPECT_THAT(range_ends, ElementsAre("3", "13", "43")); -} - -} // namespace -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.proto b/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.proto deleted file mode 100644 index 9cfdf42..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization_unittest.proto +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -syntax = "proto2"; - -package protobuf_unittest; - -option java_multiple_files = true; -option java_package = ""; - -// Each batch of extension ranges not separated by a non-extension field should -// be serialized using a single ExtensionWriter#writeUntil call. -message TestMessageWithManyExtensionRanges { - // First extension range: ends at field number 3 (exclusive) - extensions 1 to 2; - - optional int32 foo = 3; - optional int32 bar = 5; - - // Second extension range: ends at field number 13 (exclusive) - extensions 6; - extensions 8; - extensions 10 to 12; - - optional int32 baz = 23; - - // Third extension range: ends at field number 43 (exclusive) - extensions 42; -} diff --git a/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.cc b/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.cc index 84e74ff..06a637e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.cc @@ -28,21 +28,18 @@ // (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/compiler/java/name_resolver.h" +#include #include #include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/names.h" - +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -111,7 +108,7 @@ std::string ClassNameWithoutPackage(const ServiceDescriptor* descriptor, // Return true if a and b are equals (case insensitive). NameEquality CheckNameEquality(const std::string& a, const std::string& b) { - if (absl::AsciiStrToUpper(a) == absl::AsciiStrToUpper(b)) { + if (ToUpper(a) == ToUpper(b)) { if (a == b) { return NameEquality::EXACT_EQUAL; } @@ -144,6 +141,10 @@ bool MessageHasConflictingClassName(const Descriptor* message, } // namespace +ClassNameResolver::ClassNameResolver() {} + +ClassNameResolver::~ClassNameResolver() {} + std::string ClassNameResolver::GetFileDefaultImmutableClassName( const FileDescriptor* file) { std::string basename; @@ -216,12 +217,8 @@ bool ClassNameResolver::HasConflictingClassName(const FileDescriptor* file, } std::string ClassNameResolver::GetDescriptorClassName( - const FileDescriptor* file) { - if (options_.opensource_runtime) { - return GetFileImmutableClassName(file); - } else { - return GetFileImmutableClassName(file) + "InternalDescriptors"; - } + const FileDescriptor* descriptor) { + return GetFileImmutableClassName(descriptor); } std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor, @@ -231,7 +228,7 @@ std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor, std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor, bool immutable, bool kotlin) { - std::string result = FileJavaPackage(descriptor, immutable, options_); + std::string result = FileJavaPackage(descriptor, immutable); if (!result.empty()) result += '.'; result += GetFileClassName(descriptor, immutable, kotlin); return result; @@ -251,7 +248,7 @@ std::string ClassNameResolver::GetClassFullName( bool immutable, bool is_own_file, bool kotlin) { std::string result; if (is_own_file) { - result = FileJavaPackage(file, immutable, options_); + result = FileJavaPackage(file, immutable); } else { result = GetClassName(file, immutable, kotlin); } @@ -311,13 +308,13 @@ std::string ClassNameResolver::GetJavaClassFullName( bool immutable, bool kotlin) { std::string result; if (MultipleJavaFiles(file, immutable)) { - result = FileJavaPackage(file, immutable, options_); + result = FileJavaPackage(file, immutable); if (!result.empty()) result += '.'; } else { result = GetClassName(file, immutable, kotlin); if (!result.empty()) result += '$'; } - result += absl::StrReplaceAll(name_without_package, {{".", "$"}}); + result += StringReplace(name_without_package, ".", "$", true); return result; } @@ -375,7 +372,7 @@ std::string ClassNameResolver::GetDowngradedFileClassName( std::string ClassNameResolver::GetDowngradedClassName( const Descriptor* descriptor) { - return FileJavaPackage(descriptor->file(), true, options_) + "." + + return FileJavaPackage(descriptor->file()) + "." + GetDowngradedFileClassName(descriptor->file()) + "." + ClassNameWithoutPackage(descriptor, false); } @@ -385,4 +382,4 @@ std::string ClassNameResolver::GetDowngradedClassName( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.h b/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.h index d73b355..103cace 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/name_resolver.h @@ -34,13 +34,10 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/port.h" +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -61,11 +58,8 @@ enum NameEquality { NO_MATCH, EXACT_EQUAL, EQUAL_IGNORE_CASE }; // Thread-safety note: This class is *not* thread-safe. class ClassNameResolver { public: - explicit ClassNameResolver(const Options& options = {}) : options_(options) {} - ~ClassNameResolver() = default; - - ClassNameResolver(const ClassNameResolver&) = delete; - ClassNameResolver& operator=(const ClassNameResolver&) = delete; + ClassNameResolver(); + ~ClassNameResolver(); // Gets the unqualified outer class name for the file. std::string GetFileClassName(const FileDescriptor* file, bool immutable); @@ -141,8 +135,6 @@ class ClassNameResolver { const FileDescriptor* file, bool immutable, bool is_own_file, bool kotlin); - Options options_; - private: // Get the Java Class style full name of a message. std::string GetJavaClassFullName(const std::string& name_without_package, @@ -153,6 +145,8 @@ class ClassNameResolver { // Caches the result to provide better performance. std::map file_immutable_outer_class_names_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver); }; } // namespace java @@ -160,6 +154,6 @@ class ClassNameResolver { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAME_RESOLVER_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/names.cc b/libs/protobuf/src/google/protobuf/compiler/java/names.cc deleted file mode 100644 index f4f0858..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/java/names.cc +++ /dev/null @@ -1,193 +0,0 @@ -// 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. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#include "google/protobuf/compiler/java/names.h" - -#include - -#include "absl/container/flat_hash_set.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/compiler/java/names.h" -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/descriptor.pb.h" - -// Must be last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -namespace { - -const char* DefaultPackage(Options options) { - return options.opensource_runtime ? "" : "com.google.protos"; -} - -bool IsReservedName(absl::string_view name) { - static const auto& kReservedNames = - *new absl::flat_hash_set({ - "abstract", "assert", "boolean", "break", "byte", - "case", "catch", "char", "class", "const", - "continue", "default", "do", "double", "else", - "enum", "extends", "final", "finally", "float", - "for", "goto", "if", "implements", "import", - "instanceof", "int", "interface", "long", "native", - "new", "package", "private", "protected", "public", - "return", "short", "static", "strictfp", "super", - "switch", "synchronized", "this", "throw", "throws", - "transient", "try", "void", "volatile", "while", - }); - return kReservedNames.contains(name); -} - -bool IsForbidden(const std::string& field_name) { - // Names that should be avoided (in UpperCamelCase format). - // Using them will cause the compiler to generate accessors whose names - // collide with methods defined in base classes. - // Keep this list in sync with specialFieldNames in - // java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java - static const auto& kForbiddenNames = - *new absl::flat_hash_set({ - // java.lang.Object: - "Class", - // com.google.protobuf.MessageLiteOrBuilder: - "DefaultInstanceForType", - // com.google.protobuf.MessageLite: - "ParserForType", - "SerializedSize", - // com.google.protobuf.MessageOrBuilder: - "AllFields", - "DescriptorForType", - "InitializationErrorString", - "UnknownFields", - // obsolete. kept for backwards compatibility of generated code - "CachedSize", - }); - return kForbiddenNames.contains(UnderscoresToCamelCase(field_name, true)); -} - -std::string FieldName(const FieldDescriptor* field) { - std::string field_name; - // Groups are hacky: The name of the field is just the lower-cased name - // of the group type. In Java, though, we would like to retain the original - // capitalization of the type name. - if (GetType(field) == FieldDescriptor::TYPE_GROUP) { - field_name = field->message_type()->name(); - } else { - field_name = field->name(); - } - if (IsForbidden(field_name)) { - // Append a trailing "#" to indicate that the name should be decorated to - // avoid collision with other names. - field_name += "#"; - } - return field_name; -} - -} // namespace - -std::string ClassName(const Descriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - -std::string ClassName(const EnumDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - -std::string ClassName(const ServiceDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - -std::string ClassName(const FileDescriptor* descriptor) { - ClassNameResolver name_resolver; - return name_resolver.GetClassName(descriptor, true); -} - -std::string FileJavaPackage(const FileDescriptor* file, bool immutable, - Options options) { - std::string result; - - if (file->options().has_java_package()) { - result = file->options().java_package(); - } else { - result = DefaultPackage(options); - if (!file->package().empty()) { - if (!result.empty()) result += '.'; - result += file->package(); - } - } - - return result; -} - -std::string FileJavaPackage(const FileDescriptor* file, Options options) { - return FileJavaPackage(file, true /* immutable */, options); -} - -std::string CapitalizedFieldName(const FieldDescriptor* field) { - return UnderscoresToCamelCase(FieldName(field), true); -} - -std::string UnderscoresToCamelCase(const FieldDescriptor* field) { - return UnderscoresToCamelCase(FieldName(field), false); -} - -std::string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) { - return UnderscoresToCamelCase(FieldName(field), true); -} - -std::string UnderscoresToCamelCase(const MethodDescriptor* method) { - return UnderscoresToCamelCase(method->name(), false); -} - -std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) { - std::string name = UnderscoresToCamelCase(field); - if (IsReservedName(name)) { - return name + "_"; - } - return name; -} - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/names.h b/libs/protobuf/src/google/protobuf/compiler/java/names.h index 5c55bb3..313ace4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/names.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/names.h @@ -40,12 +40,6 @@ #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/compiler/java/options.h" - -// Must be last. -#include "google/protobuf/port_def.inc" - namespace google { namespace protobuf { @@ -91,8 +85,7 @@ std::string ClassName(const ServiceDescriptor* descriptor); // // Returns: // Java package name. -std::string FileJavaPackage(const FileDescriptor* descriptor, - Options options = {}); +std::string FileJavaPackage(const FileDescriptor* descriptor); // Requires: // descriptor != NULL @@ -100,36 +93,8 @@ std::string FileJavaPackage(const FileDescriptor* descriptor, // Capitalized camel case name field name. std::string CapitalizedFieldName(const FieldDescriptor* descriptor); -// Returns: -// Converts a name to camel-case. If cap_first_letter is true, capitalize the -// first letter. -std::string UnderscoresToCamelCase(const std::string& name, - bool cap_first_letter); -// Requires: -// field != NULL -// Returns: -// Converts the field's name to camel-case, e.g. "foo_bar_baz" becomes -// "fooBarBaz" or "FooBarBaz", respectively. -std::string UnderscoresToCamelCase(const FieldDescriptor* field); - -// Requires: -// method != NULL -// Returns: -// Similar, but for method names. (Typically, this merely has the effect -// of lower-casing the first letter of the name.) -std::string UnderscoresToCamelCase(const MethodDescriptor* method); - -// Requires: -// field != NULL -// Returns: -// Same as UnderscoresToCamelCase, but checks for reserved keywords -std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field); - - } // namespace java } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/options.h b/libs/protobuf/src/google/protobuf/compiler/java/options.h index 79d90fd..6c29be1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/options.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/options.h @@ -33,8 +33,6 @@ #include -#include "google/protobuf/port_def.inc" - namespace google { namespace protobuf { namespace compiler { @@ -56,7 +54,6 @@ struct Options { // When set, the protoc will generate the current files and all the transitive // dependencies as lite runtime. bool enforce_lite; - bool opensource_runtime = PROTO2_IS_OSS; // If true, we should build .meta files and emit @Generated annotations into // generated code. bool annotate_code; @@ -73,5 +70,4 @@ struct Options { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/plugin_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/java/plugin_unittest.cc index 7fcfd87..8135f86 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/plugin_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/plugin_unittest.cc @@ -33,15 +33,15 @@ #include #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/str_split.h" namespace google { namespace protobuf { @@ -114,7 +114,7 @@ TEST(JavaPluginTest, PluginTest) { std::string output; GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/Test.java", &output, true)); - std::vector lines = absl::StrSplit(output, "\n"); + std::vector lines = Split(output, "\n"); bool found_generated_annotation = false; bool found_do_not_edit = false; for (const auto& line : lines) { diff --git a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.cc b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.cc index 87dbdb6..2e3b8ea 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.cc @@ -42,7 +42,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" +#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -57,74 +57,71 @@ using internal::WireFormat; namespace { -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); - (*variables)["field_type"] = (*variables)["type"]; + variables->insert({"field_type", (*variables)["type"]}); + std::string name = (*variables)["name"]; if (javaType == JAVATYPE_BOOLEAN || javaType == JAVATYPE_DOUBLE || javaType == JAVATYPE_FLOAT || javaType == JAVATYPE_INT || javaType == JAVATYPE_LONG) { std::string capitalized_type = UnderscoresToCamelCase( PrimitiveTypeName(javaType), /*cap_first_letter=*/true); (*variables)["field_list_type"] = - "com.google.protobuf.Internal." + capitalized_type + "List"; - (*variables)["empty_list"] = "empty" + capitalized_type + "List()"; - (*variables)["create_list"] = "new" + capitalized_type + "List()"; - (*variables)["mutable_copy_list"] = - "mutableCopy(" + (*variables)["name"] + "_)"; - (*variables)["name_make_immutable"] = - (*variables)["name"] + "_.makeImmutable()"; - (*variables)["repeated_get"] = - (*variables)["name"] + "_.get" + capitalized_type; - (*variables)["repeated_add"] = - (*variables)["name"] + "_.add" + capitalized_type; - (*variables)["repeated_set"] = - (*variables)["name"] + "_.set" + capitalized_type; - } else { - (*variables)["field_list_type"] = - "java.util.List<" + (*variables)["boxed_type"] + ">"; + StrCat("com.google.protobuf.Internal.", capitalized_type, "List"); + (*variables)["empty_list"] = + StrCat("empty", capitalized_type, "List()"); (*variables)["create_list"] = - "new java.util.ArrayList<" + (*variables)["boxed_type"] + ">()"; - (*variables)["mutable_copy_list"] = "new java.util.ArrayList<" + - (*variables)["boxed_type"] + ">(" + - (*variables)["name"] + "_)"; - (*variables)["empty_list"] = "java.util.Collections.emptyList()"; + StrCat("new", capitalized_type, "List()"); + (*variables)["mutable_copy_list"] = + StrCat("mutableCopy(", name, "_)"); (*variables)["name_make_immutable"] = - (*variables)["name"] + "_ = java.util.Collections.unmodifiableList(" + - (*variables)["name"] + "_)"; - (*variables)["repeated_get"] = (*variables)["name"] + "_.get"; - (*variables)["repeated_add"] = (*variables)["name"] + "_.add"; - (*variables)["repeated_set"] = (*variables)["name"] + "_.set"; + StrCat(name, "_.makeImmutable()"); + (*variables)["repeated_get"] = + StrCat(name, "_.get", capitalized_type); + (*variables)["repeated_add"] = + StrCat(name, "_.add", capitalized_type); + (*variables)["repeated_set"] = + StrCat(name, "_.set", capitalized_type); + } else { + std::string boxed_type = (*variables)["boxed_type"]; + (*variables)["field_list_type"] = + StrCat("java.util.List<", boxed_type, ">"); + (*variables)["create_list"] = + StrCat("new java.util.ArrayList<", boxed_type, ">()"); + (*variables)["mutable_copy_list"] = + StrCat("new java.util.ArrayList<", boxed_type, ">(", name, "_)"); + (*variables)["empty_list"] = "java.util.Collections.emptyList()"; + (*variables)["name_make_immutable"] = StrCat( + name, "_ = java.util.Collections.unmodifiableList(", name, "_)"); + (*variables)["repeated_get"] = StrCat(name, "_.get"); + (*variables)["repeated_add"] = StrCat(name, "_.add"); + (*variables)["repeated_set"] = StrCat(name, "_.set"); } - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_init"] = IsDefaultValueJavaDefault(descriptor) ? "" - : ("= " + ImmutableDefaultValue(descriptor, name_resolver, - context->options())); - (*variables)["capitalized_type"] = GetCapitalizedType( - descriptor, /* immutable = */ true, context->options()); + : ("= " + ImmutableDefaultValue(descriptor, name_resolver)); + (*variables)["capitalized_type"] = + GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - absl::StrCat(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); if (IsReferenceType(GetJavaType(descriptor))) { (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; + "if (value == null) { throw new NullPointerException(); }"; } else { (*variables)["null_check"] = ""; } @@ -134,52 +131,41 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; (*variables)["kt_deprecation"] = descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " + ? StrCat("@kotlin.Deprecated(message = \"Field ", name, + " is deprecated\") ") : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { - (*variables)["fixed_size"] = absl::StrCat(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } (*variables)["on_changed"] = "onChanged();"; if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); - // Note that these have a trailing ";". - (*variables)["set_has_field_bit_message"] = - GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; - + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex) + ";"; (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { - (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - + (*variables)["set_has_field_bit_to_local"] = ""; switch (descriptor->type()) { case FieldDescriptor::TYPE_BYTES: (*variables)["is_field_present_message"] = - "!" + (*variables)["name"] + "_.isEmpty()"; + StrCat("!", name, "_.isEmpty()"); break; case FieldDescriptor::TYPE_FLOAT: (*variables)["is_field_present_message"] = - "java.lang.Float.floatToRawIntBits(" + (*variables)["name"] + - "_) != 0"; + StrCat("java.lang.Float.floatToRawIntBits(", name, "_) != 0"); break; case FieldDescriptor::TYPE_DOUBLE: - (*variables)["is_field_present_message"] = - "java.lang.Double.doubleToRawLongBits(" + (*variables)["name"] + - "_) != 0"; + (*variables)["is_field_present_message"] = StrCat( + "java.lang.Double.doubleToRawLongBits(", name, "_) != 0"); break; default: - (*variables)["is_field_present_message"] = - (*variables)["name"] + "_ != " + (*variables)["default"]; + variables->insert( + {"is_field_present_message", + StrCat(name, "_ != ", (*variables)["default"])}); break; } } @@ -189,10 +175,15 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + // Always track the presence of a field explicitly in the builder, regardless + // of syntax. + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -202,7 +193,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -210,13 +204,19 @@ ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator( ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {} +int ImmutablePrimitiveFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutablePrimitiveFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutablePrimitiveFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutablePrimitiveFieldGenerator::GetNumBitsForBuilder() const { return 1; } void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( io::Printer* printer) const { @@ -231,7 +231,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateInterfaceMembers( void ImmutablePrimitiveFieldGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print(variables_, "private $field_type$ $name$_;\n"); + printer->Print(variables_, "private $field_type$ $name$_ = $default$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); @@ -281,9 +281,9 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" - "$null_check$" - " $set_has_field_bit_builder$\n" + " $null_check$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -314,7 +314,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: $kt_type$\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -325,15 +325,14 @@ void ImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -356,9 +355,8 @@ void ImmutablePrimitiveFieldGenerator::GenerateInitializationCode( void ImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default$;\n" - "$clear_has_field_bit_builder$\n"); + // No need to clear the has-bit since we clear the bitField ints all at once. + printer->Print(variables_, "$name$_ = $default$;\n"); } void ImmutablePrimitiveFieldGenerator::GenerateMergingCode( @@ -378,23 +376,13 @@ void ImmutablePrimitiveFieldGenerator::GenerateMergingCode( void ImmutablePrimitiveFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - if (IsDefaultValueJavaDefault(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " result.$name$_ = $name$_;\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); - } else { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n" - "result.$name$_ = $name$_;\n"); - } - } else { - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$\n"); } + printer->Print("}\n"); } void ImmutablePrimitiveFieldGenerator::GenerateBuilderParsingCode( @@ -583,7 +571,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$set$capitalized_name$$}$($type$ value) {\n" - "$null_check$" + " $null_check$\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" @@ -614,10 +602,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderClearCode( void ImmutablePrimitiveOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // no-op } void ImmutablePrimitiveOneofFieldGenerator::GenerateMergingCode( @@ -675,11 +660,8 @@ RepeatedImmutablePrimitiveFieldGenerator:: int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutablePrimitiveFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutablePrimitiveFieldGenerator:: ~RepeatedImmutablePrimitiveFieldGenerator() {} @@ -759,7 +741,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( " if (!$get_mutable_bit_builder$) {\n" " $name$_ = $mutable_copy_list$;\n" " $set_mutable_bit_builder$;\n" - " }\n" + " }\n" "}\n"); // Note: We return an unmodifiable list because otherwise the caller @@ -794,7 +776,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $repeated_set$(index, value);\n" " $on_changed$\n" @@ -806,7 +788,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder " "${$add$capitalized_name$$}$($type$ value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $repeated_add$(value);\n" " $on_changed$\n" @@ -851,7 +833,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "public class ${$$kt_capitalized_name$Proxy$}$ private constructor()" " : com.google.protobuf.kotlin.DslProxy()\n"); - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$ public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -862,7 +844,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -873,7 +855,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -885,7 +867,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -896,7 +878,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -909,7 +891,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -921,7 +903,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" @@ -944,9 +926,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateInitializationCode( void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $empty_list$;\n" - "$clear_mutable_bit_builder$;\n"); + printer->Print(variables_, "$name$_ = $empty_list$;\n"); } void RepeatedImmutablePrimitiveFieldGenerator::GenerateMergingCode( diff --git a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.h b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.h index d8104ba..9d95655 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field.h @@ -70,6 +70,8 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -92,6 +94,8 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; std::map variables_; ClassNameResolver* name_resolver_; }; @@ -119,7 +123,7 @@ class ImmutablePrimitiveOneofFieldGenerator }; class RepeatedImmutablePrimitiveFieldGenerator - : public ImmutableFieldGenerator { + : public ImmutablePrimitiveFieldGenerator { public: explicit RepeatedImmutablePrimitiveFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -152,11 +156,6 @@ class RepeatedImmutablePrimitiveFieldGenerator void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - std::map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.cc index e370815..28c23d5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.cc @@ -32,22 +32,21 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/primitive_field_lite.h" +#include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -70,21 +69,19 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); JavaType javaType = GetJavaType(descriptor); (*variables)["type"] = PrimitiveTypeName(javaType); (*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType); (*variables)["kt_type"] = KotlinTypeName(javaType); (*variables)["field_type"] = (*variables)["type"]; - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); - (*variables)["capitalized_type"] = GetCapitalizedType( - descriptor, /* immutable = */ true, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); + (*variables)["capitalized_type"] = + GetCapitalizedType(descriptor, /* immutable = */ true); (*variables)["tag"] = - absl::StrCat(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["required"] = descriptor->is_required() ? "true" : "false"; @@ -126,7 +123,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, if (javaType == JAVATYPE_BYTES) { (*variables)["bytes_default"] = - absl::AsciiStrToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; + ToUpper((*variables)["name"]) + "_DEFAULT_VALUE"; } if (IsReferenceType(javaType)) { @@ -148,7 +145,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, : ""; int fixed_size = FixedSize(GetType(descriptor)); if (fixed_size != -1) { - (*variables)["fixed_size"] = absl::StrCat(fixed_size); + (*variables)["fixed_size"] = StrCat(fixed_size); } if (HasHasbit(descriptor)) { @@ -192,8 +189,6 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, GenerateGetBitFromLocal(builderBitIndex); (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); - // Annotations often use { and } variables to denote ranges. - (*variables)["{"] = (*variables)["}"] = ""; } } // namespace @@ -204,11 +199,10 @@ ImmutablePrimitiveFieldLiteGenerator::ImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), messageBitIndex_(messageBitIndex), - context_(context), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } ImmutablePrimitiveFieldLiteGenerator::~ImmutablePrimitiveFieldLiteGenerator() {} @@ -225,9 +219,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers( "$deprecation$boolean has$capitalized_name$();\n"); } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print(variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); } void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers( @@ -239,20 +231,6 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers( variables_, "private static final $field_type$ $bytes_default$ = $default$;\n"); } - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$,\n" - " isRequired=$required$)\n"); - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "@com.google.protobuf.ProtoPresenceCheckedField(\n" - " presenceBitsId=$bit_field_id$,\n" - " mask=$bit_field_mask$)\n"); - } - } printer->Print(variables_, "private $field_type$ $name$_;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { @@ -356,15 +334,14 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -515,7 +492,7 @@ RepeatedImmutablePrimitiveFieldLiteGenerator:: name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } RepeatedImmutablePrimitiveFieldLiteGenerator:: @@ -530,17 +507,13 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers( WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$java.util.List<$boxed_type$> " - "${$get$capitalized_name$List$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); printer->Print(variables_, - "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print( - variables_, - "$deprecation$$type$ ${$get$capitalized_name$$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecation$$type$ get$capitalized_name$(int index);\n"); } void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateMembers( @@ -712,7 +685,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( " )\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -723,7 +696,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -735,7 +708,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"addAll$kt_capitalized_name$\")\n" @@ -746,7 +719,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -759,7 +732,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -771,7 +744,7 @@ void RepeatedImmutablePrimitiveFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.h index 410b7d6..2da0cd8 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/primitive_field_lite.h @@ -39,7 +39,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -62,10 +62,6 @@ class ImmutablePrimitiveFieldLiteGenerator public: explicit ImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutablePrimitiveFieldLiteGenerator( - const ImmutablePrimitiveFieldLiteGenerator&) = delete; - ImmutablePrimitiveFieldLiteGenerator& operator=( - const ImmutablePrimitiveFieldLiteGenerator&) = delete; ~ImmutablePrimitiveFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator @@ -85,8 +81,10 @@ class ImmutablePrimitiveFieldLiteGenerator const FieldDescriptor* descriptor_; std::map variables_; const int messageBitIndex_; - Context* context_; ClassNameResolver* name_resolver_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveFieldLiteGenerator); }; class ImmutablePrimitiveOneofFieldLiteGenerator @@ -95,10 +93,6 @@ class ImmutablePrimitiveOneofFieldLiteGenerator ImmutablePrimitiveOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutablePrimitiveOneofFieldLiteGenerator( - const ImmutablePrimitiveOneofFieldLiteGenerator&) = delete; - ImmutablePrimitiveOneofFieldLiteGenerator& operator=( - const ImmutablePrimitiveOneofFieldLiteGenerator&) = delete; ~ImmutablePrimitiveOneofFieldLiteGenerator() override; void GenerateMembers(io::Printer* printer) const override; @@ -106,6 +100,9 @@ class ImmutablePrimitiveOneofFieldLiteGenerator void GenerateFieldInfo(io::Printer* printer, std::vector* output) const override; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutablePrimitiveOneofFieldLiteGenerator); }; class RepeatedImmutablePrimitiveFieldLiteGenerator @@ -113,10 +110,6 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator public: explicit RepeatedImmutablePrimitiveFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - RepeatedImmutablePrimitiveFieldLiteGenerator( - const RepeatedImmutablePrimitiveFieldLiteGenerator&) = delete; - RepeatedImmutablePrimitiveFieldLiteGenerator& operator=( - const RepeatedImmutablePrimitiveFieldLiteGenerator&) = delete; ~RepeatedImmutablePrimitiveFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator ------------------------------------ @@ -136,6 +129,8 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator std::map variables_; Context* context_; ClassNameResolver* name_resolver_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutablePrimitiveFieldLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/service.cc b/libs/protobuf/src/google/protobuf/compiler/java/service.cc index d0c525b..9e20620 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/service.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/service.cc @@ -32,17 +32,17 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/service.h" +#include -#include "google/protobuf/io/printer.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include // Must be last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -68,10 +68,6 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) { WriteServiceDocComment(printer, descriptor_); MaybePrintGeneratedAnnotation(context_, printer, descriptor_, /* immutable = */ true); - if (!context_->options().opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } - printer->Print( "public $static$ abstract class $classname$\n" " implements com.google.protobuf.Service {\n", @@ -96,7 +92,7 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) { " return $file$.getDescriptor().getServices().get($index$);\n" "}\n", "file", name_resolver_->GetImmutableClassName(descriptor_->file()), - "index", absl::StrCat(descriptor_->index())); + "index", StrCat(descriptor_->index())); GenerateGetDescriptorForType(printer); // Generate more stuff. @@ -216,7 +212,7 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) { for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = absl::StrCat(i); + vars["index"] = StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); @@ -263,7 +259,7 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod( for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = absl::StrCat(i); + vars["index"] = StrCat(i); vars["method"] = UnderscoresToCamelCase(method); vars["input"] = name_resolver_->GetImmutableClassName(method->input_type()); vars["output"] = GetOutput(method); @@ -308,7 +304,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which, for (int i = 0; i < descriptor_->method_count(); i++) { const MethodDescriptor* method = descriptor_->method(i); std::map vars; - vars["index"] = absl::StrCat(i); + vars["index"] = StrCat(i); vars["type"] = (which == REQUEST) ? name_resolver_->GetImmutableClassName(method->input_type()) @@ -363,7 +359,7 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) { printer->Indent(); std::map vars; - vars["index"] = absl::StrCat(i); + vars["index"] = StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, "channel.callMethod(\n" @@ -427,7 +423,7 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) { printer->Indent(); std::map vars; - vars["index"] = absl::StrCat(i); + vars["index"] = StrCat(i); vars["output"] = GetOutput(method); printer->Print(vars, "return ($output$) channel.callBlockingMethod(\n" @@ -480,4 +476,4 @@ void ImmutableServiceGenerator::GenerateBlockingMethodSignature( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/java/service.h b/libs/protobuf/src/google/protobuf/compiler/java/service.h index 06f50ff..9cb9021 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/service.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/service.h @@ -36,7 +36,7 @@ #define GOOGLE_PROTOBUF_COMPILER_JAVA_SERVICE_H__ #include -#include "google/protobuf/descriptor.h" +#include namespace google { namespace protobuf { @@ -60,8 +60,6 @@ namespace java { class ServiceGenerator { public: explicit ServiceGenerator(const ServiceDescriptor* descriptor); - ServiceGenerator(const ServiceGenerator&) = delete; - ServiceGenerator& operator=(const ServiceGenerator&) = delete; virtual ~ServiceGenerator(); virtual void Generate(io::Printer* printer) = 0; @@ -71,15 +69,15 @@ class ServiceGenerator { protected: const ServiceDescriptor* descriptor_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator); }; class ImmutableServiceGenerator : public ServiceGenerator { public: ImmutableServiceGenerator(const ServiceDescriptor* descriptor, Context* context); - ImmutableServiceGenerator(const ImmutableServiceGenerator&) = delete; - ImmutableServiceGenerator& operator=(const ImmutableServiceGenerator&) = - delete; ~ImmutableServiceGenerator() override; void Generate(io::Printer* printer) override; @@ -130,6 +128,7 @@ class ImmutableServiceGenerator : public ServiceGenerator { Context* context_; ClassNameResolver* name_resolver_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableServiceGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.cc b/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.cc index c70b61c..39b96ee 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.cc @@ -30,19 +30,19 @@ // Author: xiaofeng@google.com (Feng Xiao) -#include "google/protobuf/compiler/java/shared_code_generator.h" +#include #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/descriptor.h" -#include "absl/strings/escaping.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" -#include "google/protobuf/compiler/java/names.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -51,16 +51,14 @@ namespace java { SharedCodeGenerator::SharedCodeGenerator(const FileDescriptor* file, const Options& options) - : name_resolver_(new ClassNameResolver(options)), - file_(file), - options_(options) {} + : name_resolver_(new ClassNameResolver), file_(file), options_(options) {} SharedCodeGenerator::~SharedCodeGenerator() {} void SharedCodeGenerator::Generate( GeneratorContext* context, std::vector* file_list, std::vector* annotation_file_list) { - std::string java_package = FileJavaPackage(file_, true, options_); + std::string java_package = FileJavaPackage(file_); std::string package_dir = JavaPackageToDir(java_package); if (HasDescriptorMethods(file_, options_.enforce_lite)) { @@ -89,12 +87,7 @@ void SharedCodeGenerator::Generate( "package", java_package); } PrintGeneratedAnnotation(printer.get(), '$', - options_.annotate_code ? info_relative_path : "", - options_); - - if (!options_.opensource_runtime) { - printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); - } + options_.annotate_code ? info_relative_path : ""); printer->Print( "public final class $classname$ {\n" " public static com.google.protobuf.Descriptors.FileDescriptor\n" @@ -159,7 +152,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { } } printer->Print("\"$data$\"", "data", - absl::CEscape(file_data.substr(i, kBytesPerLine))); + CEscape(file_data.substr(i, kBytesPerLine))); } printer->Outdent(); @@ -170,7 +163,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { std::vector > dependencies; for (int i = 0; i < file_->dependency_count(); i++) { std::string filename = file_->dependency(i)->name(); - std::string package = FileJavaPackage(file_->dependency(i), true, options_); + std::string package = FileJavaPackage(file_->dependency(i)); std::string classname = name_resolver_->GetDescriptorClassName(file_->dependency(i)); std::string full_name; @@ -187,15 +180,13 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) { printer->Print( "descriptor = com.google.protobuf.Descriptors.FileDescriptor\n" " .internalBuildGeneratedFileFrom(descriptorData,\n"); - if (options_.opensource_runtime) { - printer->Print( - " new com.google.protobuf.Descriptors.FileDescriptor[] {\n"); + printer->Print( + " new com.google.protobuf.Descriptors.FileDescriptor[] {\n"); - for (int i = 0; i < dependencies.size(); i++) { - const std::string& dependency = dependencies[i].second; - printer->Print(" $dependency$.getDescriptor(),\n", "dependency", - dependency); - } + for (int i = 0; i < dependencies.size(); i++) { + const std::string& dependency = dependencies[i].second; + printer->Print(" $dependency$.getDescriptor(),\n", "dependency", + dependency); } printer->Print(" });\n"); diff --git a/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.h b/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.h index fdb4f0e..b1f6eb3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/shared_code_generator.h @@ -39,8 +39,8 @@ #include #include -#include "google/protobuf/compiler/java/options.h" -#include "google/protobuf/port.h" +#include +#include namespace google { namespace protobuf { @@ -67,8 +67,6 @@ namespace java { class SharedCodeGenerator { public: SharedCodeGenerator(const FileDescriptor* file, const Options& options); - SharedCodeGenerator(const SharedCodeGenerator&) = delete; - SharedCodeGenerator& operator=(const SharedCodeGenerator&) = delete; ~SharedCodeGenerator(); void Generate(GeneratorContext* generator_context, @@ -81,6 +79,7 @@ class SharedCodeGenerator { std::unique_ptr name_resolver_; const FileDescriptor* file_; const Options options_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SharedCodeGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/string_field.cc b/libs/protobuf/src/google/protobuf/compiler/java/string_field.cc index 910ee8e..5f20792 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/string_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/string_field.cc @@ -43,7 +43,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" +#include "google/protobuf/stubs/strutil.h" #include "google/protobuf/compiler/java/context.h" #include "google/protobuf/compiler/java/doc_comment.h" #include "google/protobuf/compiler/java/helpers.h" @@ -59,30 +59,25 @@ using internal::WireFormatLite; namespace { -void SetPrimitiveVariables(const FieldDescriptor* descriptor, - int messageBitIndex, int builderBitIndex, - const FieldGeneratorInfo* info, - ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { +void SetPrimitiveVariables( + const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, + const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, + std::map* variables, + Context* context) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY"; - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_init"] = - "= " + - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "String"; (*variables)["tag"] = - absl::StrCat(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); (*variables)["null_check"] = - " if (value == null) {\n" - " throw new NullPointerException();\n" - " }\n"; + "if (value == null) { throw new NullPointerException(); }"; (*variables)["isStringEmpty"] = "com.google.protobuf.GeneratedMessage" + GeneratedCodeVersionSuffix() + ".isStringEmpty"; @@ -96,34 +91,33 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, // by the proto compiler (*variables)["deprecation"] = descriptor->options().deprecated() ? "@java.lang.Deprecated " : ""; - (*variables)["kt_deprecation"] = - descriptor->options().deprecated() - ? "@kotlin.Deprecated(message = \"Field " + (*variables)["name"] + - " is deprecated\") " - : ""; + variables->insert( + {"kt_deprecation", + descriptor->options().deprecated() + ? StrCat("@kotlin.Deprecated(message = \"Field ", + (*variables)["name"], " is deprecated\") ") + : ""}); (*variables)["on_changed"] = "onChanged();"; if (HasHasbit(descriptor)) { // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); - (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); + (*variables)["set_has_field_bit_to_local"] = + GenerateSetBitToLocal(messageBitIndex); // Note that these have a trailing ";". (*variables)["set_has_field_bit_message"] = GenerateSetBit(messageBitIndex) + ";"; - (*variables)["set_has_field_bit_builder"] = - GenerateSetBit(builderBitIndex) + ";"; - (*variables)["clear_has_field_bit_builder"] = - GenerateClearBit(builderBitIndex) + ";"; (*variables)["is_field_present_message"] = GenerateGetBit(messageBitIndex); } else { + (*variables)["get_has_field_bit_message"] = ""; + (*variables)["set_has_field_bit_to_local"] = ""; (*variables)["set_has_field_bit_message"] = ""; - (*variables)["set_has_field_bit_builder"] = ""; - (*variables)["clear_has_field_bit_builder"] = ""; - (*variables)["is_field_present_message"] = - "!" + (*variables)["isStringEmpty"] + "(" + (*variables)["name"] + "_)"; + variables->insert({"is_field_present_message", + StrCat("!", (*variables)["isStringEmpty"], "(", + (*variables)["name"], "_)")}); } // For repeated builders, one bit is used for whether the array is immutable. @@ -131,10 +125,13 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["set_mutable_bit_builder"] = GenerateSetBit(builderBitIndex); (*variables)["clear_mutable_bit_builder"] = GenerateClearBit(builderBitIndex); + (*variables)["get_has_field_bit_builder"] = GenerateGetBit(builderBitIndex); (*variables)["get_has_field_bit_from_local"] = GenerateGetBitFromLocal(builderBitIndex); - (*variables)["set_has_field_bit_to_local"] = - GenerateSetBitToLocal(messageBitIndex); + (*variables)["set_has_field_bit_builder"] = + GenerateSetBit(builderBitIndex) + ";"; + (*variables)["clear_has_field_bit_builder"] = + GenerateClearBit(builderBitIndex) + ";"; } } // namespace @@ -144,7 +141,10 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, ImmutableStringFieldGenerator::ImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { + : descriptor_(descriptor), + message_bit_index_(messageBitIndex), + builder_bit_index_(builderBitIndex), + name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, context->GetFieldGeneratorInfo(descriptor), name_resolver_, &variables_, context); @@ -152,13 +152,19 @@ ImmutableStringFieldGenerator::ImmutableStringFieldGenerator( ImmutableStringFieldGenerator::~ImmutableStringFieldGenerator() {} +int ImmutableStringFieldGenerator::GetMessageBitIndex() const { + return message_bit_index_; +} + +int ImmutableStringFieldGenerator::GetBuilderBitIndex() const { + return builder_bit_index_; +} + int ImmutableStringFieldGenerator::GetNumBitsForMessage() const { return HasHasbit(descriptor_) ? 1 : 0; } -int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { - return GetNumBitsForMessage(); -} +int ImmutableStringFieldGenerator::GetNumBitsForBuilder() const { return 1; } // A note about how strings are handled. This code used to just store a String // in the Message. This had two issues: @@ -210,8 +216,9 @@ void ImmutableStringFieldGenerator::GenerateInterfaceMembers( void ImmutableStringFieldGenerator::GenerateMembers( io::Printer* printer) const { - printer->Print(variables_, "@SuppressWarnings(\"serial\")\n" - "private volatile java.lang.Object $name$_;\n"); + printer->Print(variables_, + "@SuppressWarnings(\"serial\")\n" + "private volatile java.lang.Object $name$_ = $default$;\n"); PrintExtraFieldInfo(variables_, printer); if (HasHazzer(descriptor_)) { @@ -330,9 +337,9 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" - " $set_has_field_bit_builder$\n" + " $null_check$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -341,14 +348,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( /* builder */ true); printer->Print( variables_, - "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" - " $clear_has_field_bit_builder$\n"); + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\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_, " $name$_ = getDefaultInstance().get$capitalized_name$();\n"); printer->Print(variables_, + " $clear_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -359,14 +366,14 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); } printer->Print(variables_, - " $set_has_field_bit_builder$\n" " $name$_ = value;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" " return this;\n" "}\n"); @@ -374,7 +381,7 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers( void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: kotlin.String\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -385,15 +392,14 @@ void ImmutableStringFieldGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -414,9 +420,7 @@ void ImmutableStringFieldGenerator::GenerateInitializationCode( void ImmutableStringFieldGenerator::GenerateBuilderClearCode( io::Printer* printer) const { - printer->Print(variables_, - "$name$_ = $default$;\n" - "$clear_has_field_bit_builder$\n"); + printer->Print(variables_, "$name$_ = $default$;\n"); } void ImmutableStringFieldGenerator::GenerateMergingCode( @@ -426,14 +430,15 @@ void ImmutableStringFieldGenerator::GenerateMergingCode( // all string fields to Strings when copying fields from a Message. printer->Print(variables_, "if (other.has$capitalized_name$()) {\n" - " $set_has_field_bit_builder$\n" " $name$_ = other.$name$_;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" "}\n"); } else { printer->Print(variables_, "if (!other.get$capitalized_name$().isEmpty()) {\n" " $name$_ = other.$name$_;\n" + " $set_has_field_bit_builder$\n" " $on_changed$\n" "}\n"); } @@ -441,13 +446,13 @@ void ImmutableStringFieldGenerator::GenerateMergingCode( void ImmutableStringFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "if ($get_has_field_bit_from_local$) {\n" - " $set_has_field_bit_to_local$;\n" - "}\n"); + printer->Print(variables_, + "if ($get_has_field_bit_from_local$) {\n" + " result.$name$_ = $name$_;\n"); + if (GetNumBitsForMessage() > 0) { + printer->Print(variables_, " $set_has_field_bit_to_local$;\n"); } - printer->Print(variables_, "result.$name$_ = $name$_;\n"); + printer->Print("}\n"); } void ImmutableStringFieldGenerator::GenerateBuilderParsingCode( @@ -646,7 +651,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" @@ -673,7 +678,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -703,10 +708,7 @@ void ImmutableStringOneofFieldGenerator::GenerateMergingCode( void ImmutableStringOneofFieldGenerator::GenerateBuildingCode( io::Printer* printer) const { - printer->Print(variables_, - "if ($has_oneof_case_message$) {\n" - " result.$oneof_name$_ = $oneof_name$_;\n" - "}\n"); + // No-Op: oneof fields are built by a single statement } void ImmutableStringOneofFieldGenerator::GenerateBuilderParsingCode( @@ -745,11 +747,8 @@ void ImmutableStringOneofFieldGenerator::GenerateSerializedSizeCode( RepeatedImmutableStringFieldGenerator::RepeatedImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, Context* context) - : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { - SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex, - context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); -} + : ImmutableStringFieldGenerator(descriptor, messageBitIndex, + builderBitIndex, context) {} RepeatedImmutableStringFieldGenerator:: ~RepeatedImmutableStringFieldGenerator() {} @@ -888,7 +887,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.set(index, value);\n" " $on_changed$\n" @@ -900,7 +899,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( printer->Print(variables_, "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" - "$null_check$" + " $null_check$\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" " $on_changed$\n" @@ -937,7 +936,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers( variables_, "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" - "$null_check$"); + " $null_check$\n"); printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -964,8 +963,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( " : com.google.protobuf.kotlin.DslProxy()\n"); // property for List - WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$kt_deprecation$public val $kt_name$: " "com.google.protobuf.kotlin.DslList" @@ -977,7 +975,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List.add(String) WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -989,7 +987,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += String WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -1002,7 +1000,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List.addAll(Iterable) WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1015,7 +1013,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1029,7 +1027,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( // List[Int] = String WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -1041,7 +1039,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/string_field.h b/libs/protobuf/src/google/protobuf/compiler/java/string_field.h index c9b6256..814ebf2 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/string_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/string_field.h @@ -69,6 +69,8 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { // implements ImmutableFieldGenerator // --------------------------------------- + int GetMessageBitIndex() const override; + int GetBuilderBitIndex() const override; int GetNumBitsForMessage() const override; int GetNumBitsForBuilder() const override; void GenerateInterfaceMembers(io::Printer* printer) const override; @@ -91,6 +93,8 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator { protected: const FieldDescriptor* descriptor_; + int message_bit_index_; + int builder_bit_index_; std::map variables_; ClassNameResolver* name_resolver_; }; @@ -118,7 +122,8 @@ class ImmutableStringOneofFieldGenerator void GenerateSerializedSizeCode(io::Printer* printer) const override; }; -class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { +class RepeatedImmutableStringFieldGenerator + : public ImmutableStringFieldGenerator { public: explicit RepeatedImmutableStringFieldGenerator( const FieldDescriptor* descriptor, int messageBitIndex, @@ -149,11 +154,6 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator { void GenerateKotlinDslMembers(io::Printer* printer) const override; std::string GetBoxedType() const override; - - private: - const FieldDescriptor* descriptor_; - std::map variables_; - ClassNameResolver* name_resolver_; }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.cc b/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.cc index df86df7..49f6891 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.cc +++ b/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.cc @@ -33,21 +33,21 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/java/string_field_lite.h" +#include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/wire_format.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/java/context.h" -#include "google/protobuf/compiler/java/doc_comment.h" -#include "google/protobuf/compiler/java/helpers.h" -#include "google/protobuf/compiler/java/name_resolver.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -63,22 +63,19 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex, const FieldGeneratorInfo* info, ClassNameResolver* name_resolver, - std::map* variables, - Context* context) { + std::map* variables) { SetCommonFieldVariables(descriptor, info, variables); (*variables)["empty_list"] = "com.google.protobuf.GeneratedMessageLite.emptyProtobufList()"; - (*variables)["default"] = - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_init"] = - "= " + - ImmutableDefaultValue(descriptor, name_resolver, context->options()); + "= " + ImmutableDefaultValue(descriptor, name_resolver); (*variables)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = - absl::StrCat(static_cast(WireFormat::MakeTag(descriptor))); - (*variables)["tag_size"] = absl::StrCat( + StrCat(static_cast(WireFormat::MakeTag(descriptor))); + (*variables)["tag_size"] = StrCat( WireFormat::TagSize(descriptor->number(), GetType(descriptor))); // We use `x.getClass()` as a null check because it generates less bytecode // than an `if (x == null) { throw ... }` statement. @@ -95,17 +92,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, " is deprecated\") " : ""; (*variables)["required"] = descriptor->is_required() ? "true" : "false"; - if (!context->options().opensource_runtime) { - (*variables)["enforce_utf8"] = CheckUtf8(descriptor) ? "true" : "false"; - } if (HasHasbit(descriptor)) { - if (!context->options().opensource_runtime) { - (*variables)["bit_field_id"] = absl::StrCat(messageBitIndex / 32); - (*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex); - (*variables)["bit_field_mask"] = - absl::StrCat(1 << (messageBitIndex % 32)); - } // For singular messages and builders, one bit is used for the hasField bit. (*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex); @@ -128,8 +116,6 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, GenerateGetBitFromLocal(builderBitIndex); (*variables)["set_has_field_bit_to_local"] = GenerateSetBitToLocal(messageBitIndex); - // Annotations often use { and } variables to denote text ranges. - (*variables)["{"] = (*variables)["}"] = ""; } } // namespace @@ -140,11 +126,10 @@ ImmutableStringFieldLiteGenerator::ImmutableStringFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context) : descriptor_(descriptor), messageBitIndex_(messageBitIndex), - name_resolver_(context->GetNameResolver()), - context_(context) { + name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } ImmutableStringFieldLiteGenerator::~ImmutableStringFieldLiteGenerator() {} @@ -183,38 +168,19 @@ void ImmutableStringFieldLiteGenerator::GenerateInterfaceMembers( if (HasHazzer(descriptor_)) { WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print(variables_, - "$deprecation$boolean ${$has$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$boolean has$capitalized_name$();\n"); } WriteFieldAccessorDocComment(printer, descriptor_, GETTER); - printer->Print( - variables_, - "$deprecation$java.lang.String ${$get$capitalized_name$$}$();\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecation$java.lang.String get$capitalized_name$();\n"); WriteFieldStringBytesAccessorDocComment(printer, descriptor_, GETTER); printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" - " ${$get$capitalized_name$Bytes$}$();\n"); - printer->Annotate("{", "}", descriptor_); + " get$capitalized_name$Bytes();\n"); } void ImmutableStringFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$,\n" - " isRequired=$required$,\n" - " isEnforceUtf8=$enforce_utf8$)\n"); - if (HasHazzer(descriptor_)) { - printer->Print(variables_, - "@com.google.protobuf.ProtoPresenceCheckedField(\n" - " presenceBitsId=$bit_field_id$,\n" - " mask=$bit_field_mask$)\n"); - } - } printer->Print(variables_, "private java.lang.String $name$_;\n"); PrintExtraFieldInfo(variables_, printer); @@ -345,7 +311,7 @@ void ImmutableStringFieldLiteGenerator::GenerateBuilderMembers( void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( io::Printer* printer) const { - WriteFieldDocComment(printer, descriptor_, /* kdoc */ true); + WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$kt_deprecation$public var $kt_name$: kotlin.String\n" " @JvmName(\"${$get$kt_capitalized_name$$}$\")\n" @@ -356,15 +322,14 @@ void ImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( " }\n"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" "}\n"); if (HasHazzer(descriptor_)) { - WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, HAZZER); printer->Print( variables_, "public fun ${$has$kt_capitalized_name$$}$(): kotlin.Boolean {\n" @@ -554,12 +519,10 @@ RepeatedImmutableStringFieldLiteGenerator:: RepeatedImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context) - : descriptor_(descriptor), - name_resolver_(context->GetNameResolver()), - context_(context) { + : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) { SetPrimitiveVariables(descriptor, messageBitIndex, 0, context->GetFieldGeneratorInfo(descriptor), - name_resolver_, &variables_, context); + name_resolver_, &variables_); } RepeatedImmutableStringFieldLiteGenerator:: @@ -574,34 +537,22 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateInterfaceMembers( WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print(variables_, "$deprecation$java.util.List\n" - " ${$get$capitalized_name$List$}$();\n"); - printer->Annotate("{", "}", descriptor_); + " get$capitalized_name$List();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_COUNT); printer->Print(variables_, - "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); - printer->Annotate("{", "}", descriptor_); + "$deprecation$int get$capitalized_name$Count();\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); - printer->Print(variables_, - "$deprecation$java.lang.String " - "${$get$capitalized_name$$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecation$java.lang.String get$capitalized_name$(int index);\n"); WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_GETTER); printer->Print(variables_, "$deprecation$com.google.protobuf.ByteString\n" - " ${$get$capitalized_name$Bytes$}$(int index);\n"); - printer->Annotate("{", "}", descriptor_); + " get$capitalized_name$Bytes(int index);\n"); } void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers( io::Printer* printer) const { - if (!context_->options().opensource_runtime) { - printer->Print( - variables_, - "@com.google.protobuf.ProtoField(\n" - " fieldNumber=$number$,\n" - " type=com.google.protobuf.FieldType.$annotation_field_type$,\n" - " isEnforceUtf8=$enforce_utf8$)\n"); - } printer->Print( variables_, "private com.google.protobuf.Internal.ProtobufList " @@ -801,8 +752,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( " : com.google.protobuf.kotlin.DslProxy()\n"); // property for List - WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER, - /* builder */ false, /* kdoc */ true); + WriteFieldAccessorDocComment(printer, descriptor_, LIST_GETTER); printer->Print( variables_, "$kt_deprecation$public val $kt_name$: " @@ -816,7 +766,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( // List.add(String) WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"add$kt_capitalized_name$\")\n" @@ -828,7 +778,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( // List += String WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"plusAssign$kt_capitalized_name$\")\n" @@ -841,7 +791,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( // List.addAll(Iterable) WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -854,7 +804,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( // List += Iterable WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -868,7 +818,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( // List[Int] = String WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print( variables_, "@kotlin.jvm.JvmSynthetic\n" @@ -880,7 +830,7 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateKotlinDslMembers( "}"); WriteFieldAccessorDocComment(printer, descriptor_, CLEARER, - /* builder */ false, /* kdoc */ true); + /* builder */ false); printer->Print(variables_, "@kotlin.jvm.JvmSynthetic\n" "@kotlin.jvm.JvmName(\"clear$kt_capitalized_name$\")\n" diff --git a/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.h b/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.h index f35da28..b6ad1ea 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.h +++ b/libs/protobuf/src/google/protobuf/compiler/java/string_field_lite.h @@ -40,7 +40,7 @@ #include #include -#include "google/protobuf/compiler/java/field.h" +#include namespace google { namespace protobuf { @@ -63,10 +63,6 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { explicit ImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableStringFieldLiteGenerator(const ImmutableStringFieldLiteGenerator&) = - delete; - ImmutableStringFieldLiteGenerator& operator=( - const ImmutableStringFieldLiteGenerator&) = delete; ~ImmutableStringFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator @@ -87,7 +83,9 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator { std::map variables_; const int messageBitIndex_; ClassNameResolver* name_resolver_; - Context* context_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator); }; class ImmutableStringOneofFieldLiteGenerator @@ -95,10 +93,6 @@ class ImmutableStringOneofFieldLiteGenerator public: ImmutableStringOneofFieldLiteGenerator(const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - ImmutableStringOneofFieldLiteGenerator( - const ImmutableStringOneofFieldLiteGenerator&) = delete; - ImmutableStringOneofFieldLiteGenerator& operator=( - const ImmutableStringOneofFieldLiteGenerator&) = delete; ~ImmutableStringOneofFieldLiteGenerator() override; private: @@ -106,6 +100,8 @@ class ImmutableStringOneofFieldLiteGenerator void GenerateBuilderMembers(io::Printer* printer) const override; void GenerateFieldInfo(io::Printer* printer, std::vector* output) const override; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringOneofFieldLiteGenerator); }; class RepeatedImmutableStringFieldLiteGenerator @@ -113,10 +109,6 @@ class RepeatedImmutableStringFieldLiteGenerator public: explicit RepeatedImmutableStringFieldLiteGenerator( const FieldDescriptor* descriptor, int messageBitIndex, Context* context); - RepeatedImmutableStringFieldLiteGenerator( - const RepeatedImmutableStringFieldLiteGenerator&) = delete; - RepeatedImmutableStringFieldLiteGenerator& operator=( - const RepeatedImmutableStringFieldLiteGenerator&) = delete; ~RepeatedImmutableStringFieldLiteGenerator() override; // implements ImmutableFieldLiteGenerator ------------------------------------ @@ -135,7 +127,8 @@ class RepeatedImmutableStringFieldLiteGenerator const FieldDescriptor* descriptor_; std::map variables_; ClassNameResolver* name_resolver_; - Context* context_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator); }; } // namespace java diff --git a/libs/protobuf/src/google/protobuf/compiler/main.cc b/libs/protobuf/src/google/protobuf/compiler/main.cc index dfce4fb..3960946 100644 --- a/libs/protobuf/src/google/protobuf/compiler/main.cc +++ b/libs/protobuf/src/google/protobuf/compiler/main.cc @@ -28,19 +28,19 @@ // (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/compiler/command_line_interface.h" -#include "google/protobuf/compiler/cpp/generator.h" -#include "google/protobuf/compiler/csharp/csharp_generator.h" -#include "google/protobuf/compiler/java/generator.h" -#include "google/protobuf/compiler/java/kotlin_generator.h" -#include "google/protobuf/compiler/objectivec/generator.h" -#include "google/protobuf/compiler/php/php_generator.h" -#include "google/protobuf/compiler/python/generator.h" -#include "google/protobuf/compiler/python/pyi_generator.h" -#include "google/protobuf/compiler/ruby/ruby_generator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -66,10 +66,6 @@ int ProtobufMain(int argc, char* argv[]) { cli.RegisterGenerator("--java_out", "--java_opt", &java_generator, "Generate Java source file."); -#ifdef GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE - java_generator.set_opensource_runtime(true); -#endif - // Proto2 Kotlin java::KotlinGenerator kt_generator; cli.RegisterGenerator("--kotlin_out", "--kotlin_opt", &kt_generator, @@ -80,11 +76,6 @@ int ProtobufMain(int argc, char* argv[]) { python::Generator py_generator; cli.RegisterGenerator("--python_out", "--python_opt", &py_generator, "Generate Python source file."); - -#ifdef GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE - py_generator.set_opensource_runtime(true); -#endif - // Python pyi python::PyiGenerator pyi_generator; cli.RegisterGenerator("--pyi_out", &pyi_generator, diff --git a/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.cc b/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.cc index a4cc9e6..4d04511 100644 --- a/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/compiler/mock_code_generator.h" +#include #include @@ -39,23 +39,21 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/plugin.pb.h" -#include "google/protobuf/descriptor.pb.h" +#include + +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/str_join.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "absl/strings/strip.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/text_format.h" +#include +#include +#include +#include +#include #ifdef major #undef major @@ -76,7 +74,7 @@ std::string CommaSeparatedList( for (size_t i = 0; i < all_files.size(); i++) { names.push_back(all_files[i]->name()); } - return absl::StrJoin(names, ","); + return Join(names, ","); } static const char* kFirstInsertionPointName = "first_mock_insertion_point"; @@ -111,7 +109,7 @@ void MockCodeGenerator::ExpectGenerated( &content, true)); std::vector lines = - absl::StrSplit(content, "\n", absl::SkipEmpty()); + Split(content, "\n", true); while (!lines.empty() && lines.back().empty()) { lines.pop_back(); @@ -122,7 +120,7 @@ void MockCodeGenerator::ExpectGenerated( std::vector insertion_list; if (!insertions.empty()) { - insertion_list = absl::StrSplit(insertions, ",", absl::SkipEmpty()); + insertion_list = Split(insertions, ",", true); } EXPECT_EQ(lines.size(), 3 + insertion_list.size() * 2); @@ -207,8 +205,8 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, std::string* error) const { bool annotate = false; for (int i = 0; i < file->message_type_count(); i++) { - if (absl::StartsWith(file->message_type(i)->name(), "MockCodeGenerator_")) { - absl::string_view command = absl::StripPrefix( + if (HasPrefixString(file->message_type(i)->name(), "MockCodeGenerator_")) { + std::string command = StripPrefixString( file->message_type(i)->name(), "MockCodeGenerator_"); if (command == "Error") { *error = "Saw message type MockCodeGenerator_Error."; @@ -251,12 +249,12 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, } } - bool insert_endlines = absl::StartsWith(parameter, "insert_endlines="); - if (insert_endlines || absl::StartsWith(parameter, "insert=")) { - std::vector insert_into = absl::StrSplit( - absl::StripPrefix(parameter, - insert_endlines ? "insert_endlines=" : "insert="), - ',', absl::SkipEmpty()); + bool insert_endlines = HasPrefixString(parameter, "insert_endlines="); + if (insert_endlines || HasPrefixString(parameter, "insert=")) { + std::vector insert_into = Split( + StripPrefixString( + parameter, insert_endlines ? "insert_endlines=" : "insert="), + ",", true); for (size_t i = 0; i < insert_into.size(); i++) { { @@ -264,7 +262,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, std::string content = GetOutputFileContent(name_, "first_insert", file, context); if (insert_endlines) { - absl::StrReplaceAll({{",", ",\n"}}, &content); + GlobalReplaceSubstring(",", ",\n", &content); } if (annotate) { auto* annotation = info.add_annotation(); @@ -289,7 +287,7 @@ bool MockCodeGenerator::Generate(const FileDescriptor* file, std::string content = GetOutputFileContent(name_, "second_insert", file, context); if (insert_endlines) { - absl::StrReplaceAll({{",", ",\n"}}, &content); + GlobalReplaceSubstring(",", ",\n", &content); } if (annotate) { auto* annotation = info.add_annotation(); @@ -377,7 +375,7 @@ std::string MockCodeGenerator::GetOutputFileContent( const std::string& generator_name, const std::string& parameter, const std::string& file, const std::string& parsed_file_list, const std::string& first_message_name) { - return absl::Substitute("$0: $1, $2, $3, $4\n", generator_name, parameter, + return strings::Substitute("$0: $1, $2, $3, $4\n", generator_name, parameter, file, first_message_name, parsed_file_list); } diff --git a/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.h b/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.h index f91b7bc..45d735a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/mock_code_generator.h @@ -36,7 +36,7 @@ #include #include -#include "google/protobuf/compiler/code_generator.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/objectivec/BUILD.bazel deleted file mode 100644 index 25fb412..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ /dev/null @@ -1,152 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - ObjC code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "names", - hdrs = ["names.h"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/objectivec", - visibility = ["//visibility:public"], - deps = [ - ":names_internal", - ], -) - -cc_library( - name = "names_internal", - hdrs = [ - "names.h", - "nsobject_methods.h", - ], - srcs = [ - "names.cc", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/objectivec", - visibility = ["//pkg:__pkg__"], - deps = [ - ":line_consumer", - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf:protobuf_nowkt", - ], -) - -cc_library( - name = "line_consumer", - hdrs = ["line_consumer.h"], - srcs = ["line_consumer.cc"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/objectivec", - visibility = ["//pkg:__pkg__"], - deps = [ - "//src/google/protobuf/compiler:code_generator", - "//src/google/protobuf:protobuf_nowkt", - ], -) - -cc_library( - name = "objectivec", - srcs = [ - "enum.cc", - "enum_field.cc", - "extension.cc", - "field.cc", - "file.cc", - "generator.cc", - "helpers.cc", - "import_writer.cc", - "map_field.cc", - "message.cc", - "message_field.cc", - "oneof.cc", - "primitive_field.cc", - "text_format_decode_data.cc", - ], - hdrs = [ - "enum.h", - "enum_field.h", - "extension.h", - "field.h", - "file.h", - "generator.h", - "helpers.h", - "import_writer.h", - "map_field.h", - "message.h", - "message_field.h", - "oneof.h", - "options.h", - "primitive_field.h", - "text_format_decode_data.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/objectivec", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":line_consumer", - ":names", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "line_consumer_unittest", - srcs = ["line_consumer_unittest.cc"], - deps = [ - ":line_consumer", - "//src/google/protobuf/io", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "names_unittest", - srcs = ["names_unittest.cc"], - deps = [ - ":names", - "//src/google/protobuf/io", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "text_format_decode_data_unittest", - srcs = ["text_format_decode_data_unittest.cc"], - deps = [ - ":objectivec", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.cc deleted file mode 100644 index 73d9349..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.cc +++ /dev/null @@ -1,392 +0,0 @@ -// 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/compiler/objectivec/helpers.h" - -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_split.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/stubs/strutil.h" - -// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some -// error cases, so it seems to be ok to use as a back door for errors. - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -std::string EscapeTrigraphs(absl::string_view to_escape) { - return absl::StrReplaceAll(to_escape, {{"?", "\\?"}}); -} - -namespace { - -std::string GetZeroEnumNameForFlagType(const FlagType flag_type) { - switch (flag_type) { - case FLAGTYPE_DESCRIPTOR_INITIALIZATION: - return "GPBDescriptorInitializationFlag_None"; - case FLAGTYPE_EXTENSION: - return "GPBExtensionNone"; - case FLAGTYPE_FIELD: - return "GPBFieldNone"; - default: - GOOGLE_LOG(FATAL) << "Can't get here."; - return "0"; - } -} - -std::string GetEnumNameForFlagType(const FlagType flag_type) { - switch (flag_type) { - case FLAGTYPE_DESCRIPTOR_INITIALIZATION: - return "GPBDescriptorInitializationFlags"; - case FLAGTYPE_EXTENSION: - return "GPBExtensionOptions"; - case FLAGTYPE_FIELD: - return "GPBFieldFlags"; - default: - GOOGLE_LOG(FATAL) << "Can't get here."; - return std::string(); - } -} - -std::string HandleExtremeFloatingPoint(std::string val, bool add_float_suffix) { - if (val == "nan") { - return "NAN"; - } else if (val == "inf") { - return "INFINITY"; - } else if (val == "-inf") { - return "-INFINITY"; - } else { - // float strings with ., e or E need to have f appended - if (add_float_suffix && (val.find('.') != std::string::npos || - val.find('e') != std::string::npos || - val.find('E') != std::string::npos)) { - val += "f"; - } - return val; - } -} - -} // namespace - -std::string GetCapitalizedType(const FieldDescriptor* field) { - switch (field->type()) { - case FieldDescriptor::TYPE_INT32: - return "Int32"; - case FieldDescriptor::TYPE_UINT32: - return "UInt32"; - case FieldDescriptor::TYPE_SINT32: - return "SInt32"; - case FieldDescriptor::TYPE_FIXED32: - return "Fixed32"; - case FieldDescriptor::TYPE_SFIXED32: - return "SFixed32"; - case FieldDescriptor::TYPE_INT64: - return "Int64"; - case FieldDescriptor::TYPE_UINT64: - return "UInt64"; - case FieldDescriptor::TYPE_SINT64: - return "SInt64"; - case FieldDescriptor::TYPE_FIXED64: - return "Fixed64"; - case FieldDescriptor::TYPE_SFIXED64: - return "SFixed64"; - case FieldDescriptor::TYPE_FLOAT: - return "Float"; - case FieldDescriptor::TYPE_DOUBLE: - return "Double"; - case FieldDescriptor::TYPE_BOOL: - return "Bool"; - case FieldDescriptor::TYPE_STRING: - return "String"; - case FieldDescriptor::TYPE_BYTES: - return "Bytes"; - case FieldDescriptor::TYPE_ENUM: - return "Enum"; - case FieldDescriptor::TYPE_GROUP: - return "Group"; - case FieldDescriptor::TYPE_MESSAGE: - return "Message"; - } - - // Some compilers report reaching end of function even though all cases of - // the enum are handed in the switch. - GOOGLE_LOG(FATAL) << "Can't get here."; - return std::string(); -} - -ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type) { - switch (field_type) { - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_SFIXED32: - return OBJECTIVECTYPE_INT32; - - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_FIXED32: - return OBJECTIVECTYPE_UINT32; - - case FieldDescriptor::TYPE_INT64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_SFIXED64: - return OBJECTIVECTYPE_INT64; - - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_FIXED64: - return OBJECTIVECTYPE_UINT64; - - case FieldDescriptor::TYPE_FLOAT: - return OBJECTIVECTYPE_FLOAT; - - case FieldDescriptor::TYPE_DOUBLE: - return OBJECTIVECTYPE_DOUBLE; - - case FieldDescriptor::TYPE_BOOL: - return OBJECTIVECTYPE_BOOLEAN; - - case FieldDescriptor::TYPE_STRING: - return OBJECTIVECTYPE_STRING; - - case FieldDescriptor::TYPE_BYTES: - return OBJECTIVECTYPE_DATA; - - case FieldDescriptor::TYPE_ENUM: - return OBJECTIVECTYPE_ENUM; - - case FieldDescriptor::TYPE_GROUP: - case FieldDescriptor::TYPE_MESSAGE: - return OBJECTIVECTYPE_MESSAGE; - } - - // Some compilers report reaching end of function even though all cases of - // the enum are handed in the switch. - GOOGLE_LOG(FATAL) << "Can't get here."; - return OBJECTIVECTYPE_INT32; -} - -std::string GPBGenericValueFieldName(const FieldDescriptor* field) { - // Returns the field within the GPBGenericValue union to use for the given - // field. - if (field->is_repeated()) { - return "valueMessage"; - } - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: - return "valueInt32"; - case FieldDescriptor::CPPTYPE_UINT32: - return "valueUInt32"; - case FieldDescriptor::CPPTYPE_INT64: - return "valueInt64"; - case FieldDescriptor::CPPTYPE_UINT64: - return "valueUInt64"; - case FieldDescriptor::CPPTYPE_FLOAT: - return "valueFloat"; - case FieldDescriptor::CPPTYPE_DOUBLE: - return "valueDouble"; - case FieldDescriptor::CPPTYPE_BOOL: - return "valueBool"; - case FieldDescriptor::CPPTYPE_STRING: - if (field->type() == FieldDescriptor::TYPE_BYTES) { - return "valueData"; - } else { - return "valueString"; - } - case FieldDescriptor::CPPTYPE_ENUM: - return "valueEnum"; - case FieldDescriptor::CPPTYPE_MESSAGE: - return "valueMessage"; - } - - // Some compilers report reaching end of function even though all cases of - // the enum are handed in the switch. - GOOGLE_LOG(FATAL) << "Can't get here."; - return std::string(); -} - -std::string DefaultValue(const FieldDescriptor* field) { - // Repeated fields don't have defaults. - if (field->is_repeated()) { - return "nil"; - } - - // Switch on cpp_type since we need to know which default_value_* method - // of FieldDescriptor to call. - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: - // gcc and llvm reject the decimal form of kint32min and kint64min. - if (field->default_value_int32() == INT_MIN) { - return "-0x80000000"; - } - return absl::StrCat(field->default_value_int32()); - case FieldDescriptor::CPPTYPE_UINT32: - return absl::StrCat(field->default_value_uint32()) + "U"; - case FieldDescriptor::CPPTYPE_INT64: - // gcc and llvm reject the decimal form of kint32min and kint64min. - if (field->default_value_int64() == LLONG_MIN) { - return "-0x8000000000000000LL"; - } - return absl::StrCat(field->default_value_int64()) + "LL"; - case FieldDescriptor::CPPTYPE_UINT64: - return absl::StrCat(field->default_value_uint64()) + "ULL"; - case FieldDescriptor::CPPTYPE_DOUBLE: - return HandleExtremeFloatingPoint( - SimpleDtoa(field->default_value_double()), false); - case FieldDescriptor::CPPTYPE_FLOAT: - return HandleExtremeFloatingPoint( - SimpleFtoa(field->default_value_float()), true); - case FieldDescriptor::CPPTYPE_BOOL: - return field->default_value_bool() ? "YES" : "NO"; - case FieldDescriptor::CPPTYPE_STRING: { - const bool has_default_value = field->has_default_value(); - const std::string& default_string = field->default_value_string(); - if (!has_default_value || default_string.length() == 0) { - // If the field is defined as being the empty string, - // then we will just assign to nil, as the empty string is the - // default for both strings and data. - return "nil"; - } - if (field->type() == FieldDescriptor::TYPE_BYTES) { - // We want constant fields in our data structures so we can - // declare them as static. To achieve this we cheat and stuff - // a escaped c string (prefixed with a length) into the data - // field, and cast it to an (NSData*) so it will compile. - // The runtime library knows how to handle it. - - // Must convert to a standard byte order for packing length into - // a cstring. - uint32_t length = ghtonl(default_string.length()); - std::string bytes((const char*)&length, sizeof(length)); - bytes.append(default_string); - return "(NSData*)\"" + EscapeTrigraphs(absl::CEscape(bytes)) + "\""; - } else { - return "@\"" + EscapeTrigraphs(absl::CEscape(default_string)) + "\""; - } - } - case FieldDescriptor::CPPTYPE_ENUM: - return EnumValueName(field->default_value_enum()); - case FieldDescriptor::CPPTYPE_MESSAGE: - return "nil"; - } - - // Some compilers report reaching end of function even though all cases of - // the enum are handed in the switch. - GOOGLE_LOG(FATAL) << "Can't get here."; - return std::string(); -} - -std::string BuildFlagsString(const FlagType flag_type, - const std::vector& strings) { - if (strings.empty()) { - return GetZeroEnumNameForFlagType(flag_type); - } else if (strings.size() == 1) { - return strings[0]; - } - std::string string("(" + GetEnumNameForFlagType(flag_type) + ")("); - for (size_t i = 0; i != strings.size(); ++i) { - if (i > 0) { - string.append(" | "); - } - string.append(strings[i]); - } - string.append(")"); - return string; -} - -std::string ObjCClass(const std::string& class_name) { - return std::string("GPBObjCClass(") + class_name + ")"; -} - -std::string ObjCClassDeclaration(const std::string& class_name) { - return std::string("GPBObjCClassDeclaration(") + class_name + ");"; -} - -std::string BuildCommentsString(const SourceLocation& location, - bool prefer_single_line) { - const std::string& comments = location.leading_comments.empty() - ? location.trailing_comments - : location.leading_comments; - std::vector lines; - lines = absl::StrSplit(comments, "\n", absl::AllowEmpty()); - while (!lines.empty() && lines.back().empty()) { - lines.pop_back(); - } - // If there are no comments, just return an empty string. - if (lines.empty()) { - return ""; - } - - std::string prefix; - std::string suffix; - std::string final_comments; - std::string epilogue; - - bool add_leading_space = false; - - if (prefer_single_line && lines.size() == 1) { - prefix = "/** "; - suffix = " */\n"; - } else { - prefix = "* "; - suffix = "\n"; - final_comments += "/**\n"; - epilogue = " **/\n"; - add_leading_space = true; - } - - for (size_t i = 0; i < lines.size(); i++) { - std::string line = absl::StrReplaceAll( - absl::StripPrefix(lines[i], " "), - {// HeaderDoc and appledoc use '\' and '@' for markers; escape them. - {"\\", "\\\\"}, - {"@", "\\@"}, - // Decouple / from * to not have inline comments inside comments. - {"/*", "/\\*"}, - {"*/", "*\\/"}}); - line = prefix + line; - absl::StripAsciiWhitespace(&line); - // If not a one line, need to add the first space before *, as - // absl::StripAsciiWhitespace would have removed it. - line = (add_leading_space ? " " : "") + line; - final_comments += line + suffix; - } - final_comments += epilogue; - return final_comments; -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.h deleted file mode 100644 index c37c036..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/helpers.h +++ /dev/null @@ -1,165 +0,0 @@ -// 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. - -// Helper functions for generating ObjectiveC code. - -#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ - -#include -#include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) { - return file->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - -// Escape C++ trigraphs by escaping question marks to "\?". -std::string EscapeTrigraphs(absl::string_view to_escape); - -enum ObjectiveCType { - OBJECTIVECTYPE_INT32, - OBJECTIVECTYPE_UINT32, - OBJECTIVECTYPE_INT64, - OBJECTIVECTYPE_UINT64, - OBJECTIVECTYPE_FLOAT, - OBJECTIVECTYPE_DOUBLE, - OBJECTIVECTYPE_BOOLEAN, - OBJECTIVECTYPE_STRING, - OBJECTIVECTYPE_DATA, - OBJECTIVECTYPE_ENUM, - OBJECTIVECTYPE_MESSAGE -}; - -enum FlagType { - FLAGTYPE_DESCRIPTOR_INITIALIZATION, - FLAGTYPE_EXTENSION, - FLAGTYPE_FIELD -}; - -std::string GetCapitalizedType(const FieldDescriptor* field); - -ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type); - -inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { - return GetObjectiveCType(field->type()); -} - -inline bool IsPrimitiveType(const FieldDescriptor* field) { - ObjectiveCType type = GetObjectiveCType(field); - switch (type) { - case OBJECTIVECTYPE_INT32: - case OBJECTIVECTYPE_UINT32: - case OBJECTIVECTYPE_INT64: - case OBJECTIVECTYPE_UINT64: - case OBJECTIVECTYPE_FLOAT: - case OBJECTIVECTYPE_DOUBLE: - case OBJECTIVECTYPE_BOOLEAN: - case OBJECTIVECTYPE_ENUM: - return true; - break; - default: - return false; - } -} - -inline bool IsReferenceType(const FieldDescriptor* field) { - return !IsPrimitiveType(field); -} - -std::string GPBGenericValueFieldName(const FieldDescriptor* field); -std::string DefaultValue(const FieldDescriptor* field); - -std::string BuildFlagsString(const FlagType type, - const std::vector& strings); - -// Returns a symbol that can be used in C code to refer to an Objective C -// class without initializing the class. -std::string ObjCClass(const std::string& class_name); - -// Declares an Objective C class without initializing the class so that it can -// be refrerred to by ObjCClass. -std::string ObjCClassDeclaration(const std::string& class_name); - -// Builds HeaderDoc/appledoc style comments out of the comments in the .proto -// file. -std::string BuildCommentsString(const SourceLocation& location, - bool prefer_single_line); - -template -std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, - const FileDescriptor* file = NULL, - bool preSpace = true, - bool postNewline = false) { - bool isDeprecated = descriptor->options().deprecated(); - // The file is only passed when checking Messages & Enums, so those types - // get tagged. At the moment, it doesn't seem to make sense to tag every - // field or enum value with when the file is deprecated. - bool isFileLevelDeprecation = false; - if (!isDeprecated && file) { - isFileLevelDeprecation = file->options().deprecated(); - isDeprecated = isFileLevelDeprecation; - } - if (isDeprecated) { - std::string message; - const FileDescriptor* sourceFile = descriptor->file(); - if (isFileLevelDeprecation) { - message = sourceFile->name() + " is deprecated."; - } else { - message = descriptor->full_name() + " is deprecated (see " + - sourceFile->name() + ")."; - } - - std::string result = std::string("GPB_DEPRECATED_MSG(\"") + message + "\")"; - if (preSpace) { - result.insert(0, " "); - } - if (postNewline) { - result.append("\n"); - } - return result; - } else { - return ""; - } -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.cc deleted file mode 100644 index a0291b0..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.cc +++ /dev/null @@ -1,258 +0,0 @@ -// 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/compiler/objectivec/import_writer.h" - -#include "absl/strings/ascii.h" -#include "google/protobuf/compiler/objectivec/line_consumer.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" - -// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some -// error cases, so it seems to be ok to use as a back door for errors. - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -namespace { - -class ProtoFrameworkCollector : public LineConsumer { - public: - ProtoFrameworkCollector( - std::map* inout_proto_file_to_framework_name) - : map_(inout_proto_file_to_framework_name) {} - - virtual bool ConsumeLine(const absl::string_view& line, - std::string* out_error) override; - - private: - std::map* map_; -}; - -bool ProtoFrameworkCollector::ConsumeLine(const absl::string_view& line, - std::string* out_error) { - int offset = line.find(':'); - if (offset == absl::string_view::npos) { - *out_error = - std::string("Framework/proto file mapping line without colon sign: '") + - std::string(line) + "'."; - return false; - } - absl::string_view framework_name = - absl::StripAsciiWhitespace(line.substr(0, offset)); - absl::string_view proto_file_list = - absl::StripAsciiWhitespace(line.substr(offset + 1)); - - int start = 0; - while (start < proto_file_list.length()) { - offset = proto_file_list.find(',', start); - if (offset == absl::string_view::npos) { - offset = proto_file_list.length(); - } - - absl::string_view proto_file = absl::StripAsciiWhitespace( - proto_file_list.substr(start, offset - start)); - if (!proto_file.empty()) { - std::map::iterator existing_entry = - map_->find(std::string(proto_file)); - if (existing_entry != map_->end()) { - std::cerr << "warning: duplicate proto file reference, replacing " - "framework entry for '" - << std::string(proto_file) << "' with '" - << std::string(framework_name) << "' (was '" - << existing_entry->second << "')." << std::endl; - std::cerr.flush(); - } - - if (proto_file.find(' ') != absl::string_view::npos) { - std::cerr << "note: framework mapping file had a proto file with a " - "space in, hopefully that isn't a missing comma: '" - << std::string(proto_file) << "'" << std::endl; - std::cerr.flush(); - } - - (*map_)[std::string(proto_file)] = std::string(framework_name); - } - - start = offset + 1; - } - - return true; -} - -} // namespace - -ImportWriter::ImportWriter( - const std::string& generate_for_named_framework, - const std::string& named_framework_to_proto_path_mappings_path, - const std::string& runtime_import_prefix, bool include_wkt_imports) - : generate_for_named_framework_(generate_for_named_framework), - named_framework_to_proto_path_mappings_path_( - named_framework_to_proto_path_mappings_path), - runtime_import_prefix_(runtime_import_prefix), - include_wkt_imports_(include_wkt_imports), - need_to_parse_mapping_file_(true) {} - -ImportWriter::~ImportWriter() {} - -void ImportWriter::AddFile(const FileDescriptor* file, - const std::string& header_extension) { - if (IsProtobufLibraryBundledProtoFile(file)) { - // The imports of the WKTs are only needed within the library itself, - // in other cases, they get skipped because the generated code already - // import GPBProtocolBuffers.h and hence proves them. - if (include_wkt_imports_) { - const std::string header_name = - "GPB" + FilePathBasename(file) + header_extension; - protobuf_imports_.push_back(header_name); - } - return; - } - - // Lazy parse any mappings. - if (need_to_parse_mapping_file_) { - ParseFrameworkMappings(); - } - - std::map::iterator proto_lookup = - proto_file_to_framework_name_.find(file->name()); - if (proto_lookup != proto_file_to_framework_name_.end()) { - other_framework_imports_.push_back( - proto_lookup->second + "/" + FilePathBasename(file) + header_extension); - return; - } - - if (!generate_for_named_framework_.empty()) { - other_framework_imports_.push_back(generate_for_named_framework_ + "/" + - FilePathBasename(file) + - header_extension); - return; - } - - other_imports_.push_back(FilePath(file) + header_extension); -} - -void ImportWriter::Print(io::Printer* printer) const { - bool add_blank_line = false; - - if (!protobuf_imports_.empty()) { - PrintRuntimeImports(printer, protobuf_imports_, runtime_import_prefix_); - add_blank_line = true; - } - - if (!other_framework_imports_.empty()) { - if (add_blank_line) { - printer->Print("\n"); - } - - for (std::vector::const_iterator iter = - other_framework_imports_.begin(); - iter != other_framework_imports_.end(); ++iter) { - printer->Print("#import <$header$>\n", "header", *iter); - } - - add_blank_line = true; - } - - if (!other_imports_.empty()) { - if (add_blank_line) { - printer->Print("\n"); - } - - for (std::vector::const_iterator iter = other_imports_.begin(); - iter != other_imports_.end(); ++iter) { - printer->Print("#import \"$header$\"\n", "header", *iter); - } - } -} - -void ImportWriter::PrintRuntimeImports( - io::Printer* printer, const std::vector& header_to_import, - const std::string& runtime_import_prefix, bool default_cpp_symbol) { - // Given an override, use that. - if (!runtime_import_prefix.empty()) { - for (const auto& header : header_to_import) { - printer->Print(" #import \"$import_prefix$/$header$\"\n", "import_prefix", - runtime_import_prefix, "header", header); - } - return; - } - - const std::string framework_name(ProtobufLibraryFrameworkName); - const std::string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name)); - - if (default_cpp_symbol) { - printer->Print( - // clang-format off - "// This CPP symbol can be defined to use imports that match up to the framework\n" - "// imports needed when using CocoaPods.\n" - "#if !defined($cpp_symbol$)\n" - " #define $cpp_symbol$ 0\n" - "#endif\n" - "\n", - // clang-format on - "cpp_symbol", cpp_symbol); - } - - printer->Print("#if $cpp_symbol$\n", "cpp_symbol", cpp_symbol); - for (const auto& header : header_to_import) { - printer->Print(" #import <$framework_name$/$header$>\n", "framework_name", - framework_name, "header", header); - } - printer->Print("#else\n"); - for (const auto& header : header_to_import) { - printer->Print(" #import \"$header$\"\n", "header", header); - } - printer->Print("#endif\n"); -} - -void ImportWriter::ParseFrameworkMappings() { - need_to_parse_mapping_file_ = false; - if (named_framework_to_proto_path_mappings_path_.empty()) { - return; // Nothing to do. - } - - ProtoFrameworkCollector collector(&proto_file_to_framework_name_); - std::string parse_error; - if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_, &collector, - &parse_error)) { - std::cerr << "error parsing " - << named_framework_to_proto_path_mappings_path_ << " : " - << parse_error << std::endl; - std::cerr.flush(); - } -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.cc deleted file mode 100644 index b668875..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.cc +++ /dev/null @@ -1,218 +0,0 @@ -// 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 _MSC_VER -#include -#endif -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "absl/strings/ascii.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/objectivec/line_consumer.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" - -// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some -// error cases, so it seems to be ok to use as a back door for errors. - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// is transitively included in this file. Import the functions explicitly -// in this port namespace to avoid ambiguous definition. -namespace posix { -#ifdef _WIN32 -using google::protobuf::io::win32::open; -#else // !_WIN32 -using ::open; -#endif // _WIN32 -} // namespace posix - -namespace { - -bool ascii_isnewline(char c) { return c == '\n' || c == '\r'; } - -bool ReadLine(absl::string_view* input, absl::string_view* line) { - for (int len = 0; len < input->size(); ++len) { - if (ascii_isnewline((*input)[len])) { - *line = absl::string_view(input->data(), len); - ++len; // advance over the newline - *input = absl::string_view(input->data() + len, input->size() - len); - return true; - } - } - return false; // Ran out of input with no newline. -} - -void RemoveComment(absl::string_view* input) { - int offset = input->find('#'); - if (offset != absl::string_view::npos) { - input->remove_suffix(input->length() - offset); - } -} - -class Parser { - public: - Parser(LineConsumer* line_consumer) - : line_consumer_(line_consumer), line_(0) {} - - // Feeds in some input, parse what it can, returning success/failure. Calling - // again after an error is undefined. - bool ParseChunk(absl::string_view chunk, std::string* out_error); - - // Should be called to finish parsing (after all input has been provided via - // successful calls to ParseChunk(), calling after a ParseChunk() failure is - // undefined). Returns success/failure. - bool Finish(std::string* out_error); - - int last_line() const { return line_; } - - private: - LineConsumer* line_consumer_; - int line_; - std::string leftover_; -}; - -bool Parser::ParseChunk(absl::string_view chunk, std::string* out_error) { - absl::string_view full_chunk; - if (!leftover_.empty()) { - leftover_ += std::string(chunk); - full_chunk = absl::string_view(leftover_); - } else { - full_chunk = chunk; - } - - absl::string_view line; - while (ReadLine(&full_chunk, &line)) { - ++line_; - RemoveComment(&line); - line = absl::StripAsciiWhitespace(line); - if (!line.empty() && !line_consumer_->ConsumeLine(line, out_error)) { - if (out_error->empty()) { - *out_error = "ConsumeLine failed without setting an error."; - } - leftover_.clear(); - return false; - } - } - - if (full_chunk.empty()) { - leftover_.clear(); - } else { - leftover_ = std::string(full_chunk); - } - return true; -} - -bool Parser::Finish(std::string* out_error) { - // If there is still something to go, flush it with a newline. - if (!leftover_.empty() && !ParseChunk("\n", out_error)) { - return false; - } - // This really should never fail if ParseChunk succeeded, but check to be - // sure. - if (!leftover_.empty()) { - *out_error = "ParseSimple Internal error: finished with pending data."; - return false; - } - return true; -} - -std::string FullErrorString(const std::string& name, int line_num, - const std::string& msg) { - return std::string("error: ") + name + " Line " + absl::StrCat(line_num) + - ", " + msg; -} - -} // namespace - -LineConsumer::LineConsumer() {} - -LineConsumer::~LineConsumer() {} - -bool ParseSimpleFile(const std::string& path, LineConsumer* line_consumer, - std::string* out_error) { - int fd; - do { - fd = posix::open(path.c_str(), O_RDONLY); - } while (fd < 0 && errno == EINTR); - if (fd < 0) { - *out_error = std::string("error: Unable to open \"") + path + "\", " + - strerror(errno); - return false; - } - io::FileInputStream file_stream(fd); - file_stream.SetCloseOnDelete(true); - - return ParseSimpleStream(file_stream, path, line_consumer, out_error); -} - -bool ParseSimpleStream(io::ZeroCopyInputStream& input_stream, - const std::string& stream_name, - LineConsumer* line_consumer, std::string* out_error) { - std::string local_error; - Parser parser(line_consumer); - const void* buf; - int buf_len; - while (input_stream.Next(&buf, &buf_len)) { - if (buf_len == 0) { - continue; - } - - if (!parser.ParseChunk( - absl::string_view(static_cast(buf), buf_len), - &local_error)) { - *out_error = - FullErrorString(stream_name, parser.last_line(), local_error); - return false; - } - } - if (!parser.Finish(&local_error)) { - *out_error = FullErrorString(stream_name, parser.last_line(), local_error); - return false; - } - return true; -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.h deleted file mode 100644 index bdddf08..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer.h +++ /dev/null @@ -1,75 +0,0 @@ -// 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_COMPILER_OBJECTIVEC_LINE_CONSUMER_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_LINE_CONSUMER_H__ - -#include -#include - -#include "google/protobuf/io/zero_copy_stream.h" - -// Must be included last -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// TODO(b/250947994): PROTOC_EXPORT is only used to allow the CMake build to -// find/link these in the unittest, this is not public api. - -// Helper for parsing simple files. -class PROTOC_EXPORT LineConsumer { - public: - LineConsumer(); - virtual ~LineConsumer(); - virtual bool ConsumeLine(const absl::string_view& line, - std::string* out_error) = 0; -}; - -bool PROTOC_EXPORT ParseSimpleFile(const std::string& path, - LineConsumer* line_consumer, - std::string* out_error); - -bool PROTOC_EXPORT ParseSimpleStream(io::ZeroCopyInputStream& input_stream, - const std::string& stream_name, - LineConsumer* line_consumer, - std::string* out_error); - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_LINE_CONSUMER_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer_unittest.cc deleted file mode 100644 index ff8ff87..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/line_consumer_unittest.cc +++ /dev/null @@ -1,180 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 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/compiler/objectivec/line_consumer.h" - -#include - -#include "absl/strings/str_cat.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { -namespace { - -class TestLineCollector : public LineConsumer { - public: - explicit TestLineCollector(std::vector* inout_lines, - const std::string* reject_line = nullptr, - bool skip_msg = false) - : lines_(inout_lines), reject_(reject_line), skip_msg_(skip_msg) {} - - bool ConsumeLine(const absl::string_view& line, - std::string* out_error) override { - if (reject_ && *reject_ == line) { - if (!skip_msg_) { - *out_error = std::string("Rejected '") + *reject_ + "'"; - } - return false; - } - if (lines_) { - lines_->emplace_back(line); - } - return true; - } - - private: - std::vector* lines_; - const std::string* reject_; - bool skip_msg_; -}; - -const int kBlockSizes[] = {-1, 1, 2, 5, 64}; -const int kBlockSizeCount = ABSL_ARRAYSIZE(kBlockSizes); - -TEST(ObjCHelper, ParseSimple_BasicsSuccess) { - const std::vector>> tests = { - {"", {}}, - {"a", {"a"}}, - {"a c", {"a c"}}, - {" a c ", {"a c"}}, - {"\ta c ", {"a c"}}, - {"abc\n", {"abc"}}, - {"abc\nd f", {"abc", "d f"}}, - {"\n abc \n def \n\n", {"abc", "def"}}, - }; - - for (const auto& test : tests) { - for (int i = 0; i < kBlockSizeCount; i++) { - io::ArrayInputStream input(test.first.data(), test.first.size(), - kBlockSizes[i]); - std::string err_str; - std::vector lines; - TestLineCollector collector(&lines); - EXPECT_TRUE(ParseSimpleStream(input, "dummy", &collector, &err_str)); - EXPECT_EQ(lines, test.second); - EXPECT_TRUE(err_str.empty()); - } - } -} - -TEST(ObjCHelper, ParseSimple_DropsComments) { - const std::vector>> tests = { - {"# nothing", {}}, - {"#", {}}, - {"##", {}}, - {"\n# nothing\n", {}}, - {"a # same line", {"a"}}, - {"a # same line\n", {"a"}}, - {"a\n# line\nc", {"a", "c"}}, - {"# n o t # h i n g #", {}}, - {"## n o # t h i n g #", {}}, - {"a# n o t # h i n g #", {"a"}}, - {"a\n## n o # t h i n g #", {"a"}}, - }; - - for (const auto& test : tests) { - for (int i = 0; i < kBlockSizeCount; i++) { - io::ArrayInputStream input(test.first.data(), test.first.size(), - kBlockSizes[i]); - std::string err_str; - std::vector lines; - TestLineCollector collector(&lines); - EXPECT_TRUE(ParseSimpleStream(input, "dummy", &collector, &err_str)); - EXPECT_EQ(lines, test.second); - EXPECT_TRUE(err_str.empty()); - } - } -} - -TEST(ObjCHelper, ParseSimple_RejectLines) { - const std::vector> tests = { - std::make_tuple("a\nb\nc", "a", 1), - std::make_tuple("a\nb\nc", "b", 2), - std::make_tuple("a\nb\nc", "c", 3), - std::make_tuple("a\nb\nc\n", "c", 3), - }; - - for (const auto& test : tests) { - for (int i = 0; i < kBlockSizeCount; i++) { - io::ArrayInputStream input(std::get<0>(test).data(), - std::get<0>(test).size(), kBlockSizes[i]); - std::string err_str; - TestLineCollector collector(nullptr, &std::get<1>(test)); - EXPECT_FALSE(ParseSimpleStream(input, "dummy", &collector, &err_str)); - std::string expected_err = - absl::StrCat("error: dummy Line ", std::get<2>(test), ", Rejected '", - std::get<1>(test), "'"); - EXPECT_EQ(err_str, expected_err); - } - } -} - -TEST(ObjCHelper, ParseSimple_RejectLinesNoMessage) { - const std::vector> tests = { - std::make_tuple("a\nb\nc", "a", 1), - std::make_tuple("a\nb\nc", "b", 2), - std::make_tuple("a\nb\nc", "c", 3), - std::make_tuple("a\nb\nc\n", "c", 3), - }; - - for (const auto& test : tests) { - for (int i = 0; i < kBlockSizeCount; i++) { - io::ArrayInputStream input(std::get<0>(test).data(), - std::get<0>(test).size(), kBlockSizes[i]); - std::string err_str; - TestLineCollector collector(nullptr, &std::get<1>(test), - true /* skip msg */); - EXPECT_FALSE(ParseSimpleStream(input, "dummy", &collector, &err_str)); - std::string expected_err = - absl::StrCat("error: dummy Line ", std::get<2>(test), - ", ConsumeLine failed without setting an error."); - EXPECT_EQ(err_str, expected_err); - } - } -} - -} // namespace -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/method_dump.sh b/libs/protobuf/src/google/protobuf/compiler/objectivec/method_dump.sh index 332d42a..193825d 100755 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/method_dump.sh +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/method_dump.sh @@ -1,7 +1,7 @@ #!/bin/bash -# Updates nsobject_methods.h by generating a list of all of the properties and -# methods on NSObject that Protobufs should not overload from iOS and macOS combined. +# Updates objectivec_nsobject_methods.h by generating a list of all of the properties +# and methods on NSObject that Protobufs should not overload from iOS and macOS combined. # # The rules: # - No property should ever be overloaded. @@ -82,9 +82,9 @@ int main(int argc, const char * argv[]) { for (NSString *item in array) { // Some items with _ in them get returned in quotes, so do not add more. if ([item hasPrefix:@"\""]) { - printf(" %s,\n", item.UTF8String); + printf("\t%s,\n", item.UTF8String); } else { - printf(" \"%s\",\n", item.UTF8String); + printf("\t\"%s\",\n", item.UTF8String); } } } @@ -110,7 +110,7 @@ END_FOOTER ) # Check to make sure we are updating the correct file. -if [[ ! -e "nsobject_methods.h" ]]; then +if [[ ! -e "objectivec_nsobject_methods.h" ]]; then echo "error: Must be run in the src/google/protobuf/compiler/objectivec directory" exit 1 fi @@ -154,7 +154,7 @@ echo $"$file_footer" >> "$temp_dir"/methods_sorted.txt # Check for differences. Turn off error checking because we expect diff to fail when # there are no differences. set +e -diff_out=$(diff -I "^//.*$" "$temp_dir"/methods_sorted.txt nsobject_methods.h) +diff_out=$(diff -I "^//.*$" "$temp_dir"/methods_sorted.txt objectivec_nsobject_methods.h) removed_methods=$(echo "$diff_out" | grep '^>.*$') set -e if [[ -n "$removed_methods" ]]; then @@ -168,12 +168,12 @@ if [[ -n "$removed_methods" ]]; then echo "$removed_methods" echo "" echo "New Version: $temp_dir/methods_sorted.txt" - echo "Old Version: nsobject_methods.h" + echo "Old Version: objectivec_nsobject_methods.h" exit 1 fi if [[ -n "$diff_out" ]]; then echo "Added Methods:" echo "$(echo "$diff_out" | grep '^<.*$' | sed -e 's/^< "\(.*\)",$/ \1/')" fi; -cp "$temp_dir"/methods_sorted.txt nsobject_methods.h +cp "$temp_dir"/methods_sorted.txt objectivec_nsobject_methods.h rm -rf "$temp_dir" diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/names.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/names.cc deleted file mode 100644 index e9cd9a3..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/names.cc +++ /dev/null @@ -1,1233 +0,0 @@ -// 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/compiler/objectivec/names.h" - -#include -#include -#include -#include -#include -#include - -#include "absl/strings/ascii.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/objectivec/line_consumer.h" -#include "google/protobuf/compiler/objectivec/nsobject_methods.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" - -// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some -// error cases, so it seems to be ok to use as a back door for errors. - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -namespace { - -bool BoolFromEnvVar(const char* env_var, bool default_value) { - const char* value = getenv(env_var); - if (value) { - return std::string("YES") == absl::AsciiStrToUpper(value); - } - return default_value; -} - -class SimpleLineCollector : public LineConsumer { - public: - explicit SimpleLineCollector(std::unordered_set* inout_set) - : set_(inout_set) {} - - virtual bool ConsumeLine(const absl::string_view& line, - std::string* out_error) override { - set_->insert(std::string(line)); - return true; - } - - private: - std::unordered_set* set_; -}; - -class PackageToPrefixesCollector : public LineConsumer { - public: - PackageToPrefixesCollector( - const std::string& usage, - std::map* inout_package_to_prefix_map) - : usage_(usage), prefix_map_(inout_package_to_prefix_map) {} - - virtual bool ConsumeLine(const absl::string_view& line, - std::string* out_error) override; - - private: - const std::string usage_; - std::map* prefix_map_; -}; - -class PrefixModeStorage { - public: - PrefixModeStorage(); - - std::string package_to_prefix_mappings_path() const { - return package_to_prefix_mappings_path_; - } - void set_package_to_prefix_mappings_path(const std::string& path) { - package_to_prefix_mappings_path_ = path; - package_to_prefix_map_.clear(); - } - - std::string prefix_from_proto_package_mappings(const FileDescriptor* file); - - bool use_package_name() const { return use_package_name_; } - void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } - - std::string exception_path() const { return exception_path_; } - void set_exception_path(const std::string& path) { - exception_path_ = path; - exceptions_.clear(); - } - - bool is_package_exempted(const std::string& package); - - // When using a proto package as the prefix, this should be added as the - // prefix in front of it. - const std::string& forced_package_prefix() const { return forced_prefix_; } - void set_forced_package_prefix(const std::string& prefix) { - forced_prefix_ = prefix; - } - - private: - bool use_package_name_; - std::map package_to_prefix_map_; - std::string package_to_prefix_mappings_path_; - std::string exception_path_; - std::string forced_prefix_; - std::unordered_set exceptions_; -}; - -PrefixModeStorage::PrefixModeStorage() { - // Even thought there are generation options, have an env back door since some - // of these helpers could be used in other plugins. - - use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); - - const char* exception_path = - getenv("GPB_OBJC_PACKAGE_PREFIX_EXCEPTIONS_PATH"); - if (exception_path) { - exception_path_ = exception_path; - } - - const char* prefix = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX_PREFIX"); - if (prefix) { - forced_prefix_ = prefix; - } -} - -std::string PrefixModeStorage::prefix_from_proto_package_mappings( - const FileDescriptor* file) { - if (!file) { - return ""; - } - - if (package_to_prefix_map_.empty() && - !package_to_prefix_mappings_path_.empty()) { - std::string error_str; - // Re use the same collector as we use for expected_prefixes_path since the - // file format is the same. - PackageToPrefixesCollector collector("Package to prefixes", - &package_to_prefix_map_); - if (!ParseSimpleFile(package_to_prefix_mappings_path_, &collector, - &error_str)) { - if (error_str.empty()) { - error_str = std::string("protoc:0: warning: Failed to parse") + - std::string(" prefix to proto package mappings file: ") + - package_to_prefix_mappings_path_; - } - std::cerr << error_str << std::endl; - std::cerr.flush(); - package_to_prefix_map_.clear(); - } - } - - const std::string package = file->package(); - // For files without packages, the can be registered as "no_package:PATH", - // allowing the expected prefixes file. - static const std::string no_package_prefix("no_package:"); - const std::string lookup_key = - package.empty() ? no_package_prefix + file->name() : package; - - std::map::const_iterator prefix_lookup = - package_to_prefix_map_.find(lookup_key); - - if (prefix_lookup != package_to_prefix_map_.end()) { - return prefix_lookup->second; - } - - return ""; -} - -bool PrefixModeStorage::is_package_exempted(const std::string& package) { - if (exceptions_.empty() && !exception_path_.empty()) { - std::string error_str; - SimpleLineCollector collector(&exceptions_); - if (!ParseSimpleFile(exception_path_, &collector, &error_str)) { - if (error_str.empty()) { - error_str = std::string("protoc:0: warning: Failed to parse") + - std::string(" package prefix exceptions file: ") + - exception_path_; - } - std::cerr << error_str << std::endl; - std::cerr.flush(); - exceptions_.clear(); - } - - // If the file was empty put something in it so it doesn't get reloaded over - // and over. - if (exceptions_.empty()) { - exceptions_.insert(""); - } - } - - return exceptions_.count(package) != 0; -} - -PrefixModeStorage g_prefix_mode; - -} // namespace - -std::string GetPackageToPrefixMappingsPath() { - return g_prefix_mode.package_to_prefix_mappings_path(); -} - -void SetPackageToPrefixMappingsPath(const std::string& file_path) { - g_prefix_mode.set_package_to_prefix_mappings_path(file_path); -} - -bool UseProtoPackageAsDefaultPrefix() { - return g_prefix_mode.use_package_name(); -} - -void SetUseProtoPackageAsDefaultPrefix(bool on_or_off) { - g_prefix_mode.set_use_package_name(on_or_off); -} - -std::string GetProtoPackagePrefixExceptionList() { - return g_prefix_mode.exception_path(); -} - -void SetProtoPackagePrefixExceptionList(const std::string& file_path) { - g_prefix_mode.set_exception_path(file_path); -} - -std::string GetForcedPackagePrefix() { - return g_prefix_mode.forced_package_prefix(); -} - -void SetForcedPackagePrefix(const std::string& prefix) { - g_prefix_mode.set_forced_package_prefix(prefix); -} - -namespace { - -std::unordered_set MakeWordsMap(const char* const words[], - size_t num_words) { - std::unordered_set result; - for (int i = 0; i < num_words; i++) { - result.insert(words[i]); - } - return result; -} - -const char* const kUpperSegmentsList[] = {"url", "http", "https"}; - -std::unordered_set kUpperSegments = - MakeWordsMap(kUpperSegmentsList, ABSL_ARRAYSIZE(kUpperSegmentsList)); - -// Internal helper for name handing. -// Do not expose this outside of helpers, stick to having functions for specific -// cases (ClassName(), FieldName()), so there is always consistent suffix rules. -std::string UnderscoresToCamelCase(const std::string& input, - bool first_capitalized) { - std::vector values; - std::string current; - - bool last_char_was_number = false; - bool last_char_was_lower = false; - bool last_char_was_upper = false; - for (int i = 0; i < input.size(); i++) { - char c = input[i]; - if (absl::ascii_isdigit(c)) { - if (!last_char_was_number) { - values.push_back(current); - current = ""; - } - current += c; - last_char_was_number = last_char_was_lower = last_char_was_upper = false; - last_char_was_number = true; - } else if (absl::ascii_islower(c)) { - // lowercase letter can follow a lowercase or uppercase letter - if (!last_char_was_lower && !last_char_was_upper) { - values.push_back(current); - current = ""; - } - current += c; // already lower - last_char_was_number = last_char_was_lower = last_char_was_upper = false; - last_char_was_lower = true; - } else if (absl::ascii_isupper(c)) { - if (!last_char_was_upper) { - values.push_back(current); - current = ""; - } - current += absl::ascii_tolower(c); - last_char_was_number = last_char_was_lower = last_char_was_upper = false; - last_char_was_upper = true; - } else { - last_char_was_number = last_char_was_lower = last_char_was_upper = false; - } - } - values.push_back(current); - - std::string result; - bool first_segment_forces_upper = false; - for (std::vector::iterator i = values.begin(); i != values.end(); - ++i) { - std::string value = *i; - bool all_upper = (kUpperSegments.count(value) > 0); - if (all_upper && (result.length() == 0)) { - first_segment_forces_upper = true; - } - for (int j = 0; j < value.length(); j++) { - if (j == 0 || all_upper) { - value[j] = absl::ascii_toupper(value[j]); - } else { - // Nothing, already in lower. - } - } - result += value; - } - if ((result.length() != 0) && !first_capitalized && - !first_segment_forces_upper) { - result[0] = absl::ascii_tolower(result[0]); - } - return result; -} - -const char* const kReservedWordList[] = { - // Note NSObject Methods: - // These are brought in from nsobject_methods.h that is generated - // using method_dump.sh. See kNSObjectMethods below. - - // Objective C "keywords" that aren't in C - // From - // http://stackoverflow.com/questions/1873630/reserved-keywords-in-objective-c - // with some others added on. - "id", - "_cmd", - "super", - "in", - "out", - "inout", - "bycopy", - "byref", - "oneway", - "self", - "instancetype", - "nullable", - "nonnull", - "nil", - "Nil", - "YES", - "NO", - "weak", - - // C/C++ keywords (Incl C++ 0x11) - // From http://en.cppreference.com/w/cpp/keywords - "and", - "and_eq", - "alignas", - "alignof", - "asm", - "auto", - "bitand", - "bitor", - "bool", - "break", - "case", - "catch", - "char", - "char16_t", - "char32_t", - "class", - "compl", - "const", - "constexpr", - "const_cast", - "continue", - "decltype", - "default", - "delete", - "double", - "dynamic_cast", - "else", - "enum", - "explicit", - "export", - "extern ", - "false", - "float", - "for", - "friend", - "goto", - "if", - "inline", - "int", - "long", - "mutable", - "namespace", - "new", - "noexcept", - "not", - "not_eq", - "nullptr", - "operator", - "or", - "or_eq", - "private", - "protected", - "public", - "register", - "reinterpret_cast", - "return", - "short", - "signed", - "sizeof", - "static", - "static_assert", - "static_cast", - "struct", - "switch", - "template", - "this", - "thread_local", - "throw", - "true", - "try", - "typedef", - "typeid", - "typename", - "union", - "unsigned", - "using", - "virtual", - "void", - "volatile", - "wchar_t", - "while", - "xor", - "xor_eq", - - // C99 keywords - // From - // http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fkeyw.htm - "restrict", - - // GCC/Clang extension - "typeof", - - // Not a keyword, but will break you - "NULL", - - // C88+ specs call for these to be macros, so depending on what they are - // defined to be it can lead to odd errors for some Xcode/SDK versions. - "stdin", - "stdout", - "stderr", - - // Objective-C Runtime typedefs - // From - "Category", - "Ivar", - "Method", - "Protocol", - - // GPBMessage Methods - // Only need to add instance methods that may conflict with - // method declared in protos. The main cases are methods - // that take no arguments, or setFoo:/hasFoo: type methods. - "clear", - "data", - "delimitedData", - "descriptor", - "extensionRegistry", - "extensionsCurrentlySet", - "initialized", - "isInitialized", - "serializedSize", - "sortedExtensionsInUse", - "unknownFields", - - // MacTypes.h names - "Fixed", - "Fract", - "Size", - "LogicalAddress", - "PhysicalAddress", - "ByteCount", - "ByteOffset", - "Duration", - "AbsoluteTime", - "OptionBits", - "ItemCount", - "PBVersion", - "ScriptCode", - "LangCode", - "RegionCode", - "OSType", - "ProcessSerialNumber", - "Point", - "Rect", - "FixedPoint", - "FixedRect", - "Style", - "StyleParameter", - "StyleField", - "TimeScale", - "TimeBase", - "TimeRecord", -}; - -// returns true is input starts with __ or _[A-Z] which are reserved identifiers -// in C/ C++. All calls should go through UnderscoresToCamelCase before getting -// here but this verifies and allows for future expansion if we decide to -// redefine what a reserved C identifier is (for example the GNU list -// https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html ) -bool IsReservedCIdentifier(const std::string& input) { - if (input.length() > 2) { - if (input.at(0) == '_') { - if (isupper(input.at(1)) || input.at(1) == '_') { - return true; - } - } - } - return false; -} - -std::string SanitizeNameForObjC(const std::string& prefix, - const std::string& input, - const std::string& extension, - std::string* out_suffix_added) { - static const std::unordered_set kReservedWords = - MakeWordsMap(kReservedWordList, ABSL_ARRAYSIZE(kReservedWordList)); - static const std::unordered_set kNSObjectMethods = - MakeWordsMap(kNSObjectMethodsList, ABSL_ARRAYSIZE(kNSObjectMethodsList)); - std::string sanitized; - // We add the prefix in the cases where the string is missing a prefix. - // We define "missing a prefix" as where 'input': - // a) Doesn't start with the prefix or - // b) Isn't equivalent to the prefix or - // c) Has the prefix, but the letter after the prefix is lowercase - if (absl::StartsWith(input, prefix)) { - if (input.length() == prefix.length() || - !absl::ascii_isupper(input[prefix.length()])) { - sanitized = prefix + input; - } else { - sanitized = input; - } - } else { - sanitized = prefix + input; - } - if (IsReservedCIdentifier(sanitized) || - (kReservedWords.count(sanitized) > 0) || - (kNSObjectMethods.count(sanitized) > 0)) { - if (out_suffix_added) *out_suffix_added = extension; - return sanitized + extension; - } - if (out_suffix_added) out_suffix_added->clear(); - return sanitized; -} - -std::string NameFromFieldDescriptor(const FieldDescriptor* field) { - if (field->type() == FieldDescriptor::TYPE_GROUP) { - return field->message_type()->name(); - } else { - return field->name(); - } -} - -void PathSplit(const std::string& path, std::string* directory, - std::string* basename) { - std::string::size_type last_slash = path.rfind('/'); - if (last_slash == std::string::npos) { - if (directory) { - *directory = ""; - } - if (basename) { - *basename = path; - } - } else { - if (directory) { - *directory = path.substr(0, last_slash); - } - if (basename) { - *basename = path.substr(last_slash + 1); - } - } -} - -bool IsSpecialNamePrefix(const std::string& name, - const std::string* special_names, size_t count) { - for (size_t i = 0; i < count; ++i) { - const size_t length = special_names[i].length(); - if (name.compare(0, length, special_names[i]) == 0) { - if (name.length() > length) { - // If name is longer than the special_names[i] that it matches - // the next character must be not lower case (newton vs newTon vs - // new_ton). - return !absl::ascii_islower(name[length]); - } else { - return true; - } - } - } - return false; -} - -void MaybeUnQuote(absl::string_view* input) { - if ((input->length() >= 2) && - ((*input->data() == '\'' || *input->data() == '"')) && - ((*input)[input->length() - 1] == *input->data())) { - input->remove_prefix(1); - input->remove_suffix(1); - } -} - -} // namespace - -bool IsRetainedName(const std::string& name) { - // List of prefixes from - // http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html - static const std::string retained_names[] = {"new", "alloc", "copy", - "mutableCopy"}; - return IsSpecialNamePrefix( - name, retained_names, sizeof(retained_names) / sizeof(retained_names[0])); -} - -bool IsInitName(const std::string& name) { - static const std::string init_names[] = {"init"}; - return IsSpecialNamePrefix(name, init_names, - sizeof(init_names) / sizeof(init_names[0])); -} - -bool IsCreateName(const std::string& name) { - // List of segments from - // https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029 - static const std::string create_names[] = {"Create", "Copy"}; - const size_t count = sizeof(create_names) / sizeof(create_names[0]); - - for (size_t i = 0; i < count; ++i) { - const size_t length = create_names[i].length(); - size_t pos = name.find(create_names[i]); - if (pos != std::string::npos) { - // The above docs don't actually call out anything about the characters - // before the special words. So it's not clear if something like - // "FOOCreate" would or would not match the "The Create Rule", but by not - // checking, and claiming it does match, then callers will annotate with - // `cf_returns_not_retained` which will ensure things work as desired. - // - // The footnote here is the docs do have a passing reference to "NoCopy", - // but again, not looking for that and just returning `true` will cause - // callers to annotate the api as not being a Create Rule function. - - // If name is longer than the create_names[i] that it matches the next - // character must be not lower case (Copyright vs CopyFoo vs Copy_Foo). - if (name.length() > pos + length) { - return !absl::ascii_islower(name[pos + length]); - } else { - return true; - } - } - } - return false; -} - -std::string BaseFileName(const FileDescriptor* file) { - std::string basename; - PathSplit(file->name(), NULL, &basename); - return basename; -} - -std::string FileClassPrefix(const FileDescriptor* file) { - // Always honor the file option. - if (file->options().has_objc_class_prefix()) { - return file->options().objc_class_prefix(); - } - - // If package prefix is specified in an prefix to proto mappings file then use - // that. - std::string objc_class_prefix = - g_prefix_mode.prefix_from_proto_package_mappings(file); - if (!objc_class_prefix.empty()) { - return objc_class_prefix; - } - - // If package prefix isn't enabled, done. - if (!g_prefix_mode.use_package_name()) { - return ""; - } - - // If the package is in the exceptions list, done. - if (g_prefix_mode.is_package_exempted(file->package())) { - return ""; - } - - // Transform the package into a prefix: use the dot segments as part, - // camelcase each one and then join them with underscores, and add an - // underscore at the end. - std::string result; - const std::vector segments = - absl::StrSplit(file->package(), ".", absl::SkipEmpty()); - for (const auto& segment : segments) { - const std::string part = UnderscoresToCamelCase(segment, true); - if (part.empty()) { - continue; - } - if (!result.empty()) { - result.append("_"); - } - result.append(part); - } - if (!result.empty()) { - result.append("_"); - } - return g_prefix_mode.forced_package_prefix() + result; -} - -std::string FilePath(const FileDescriptor* file) { - std::string output; - std::string basename; - std::string directory; - PathSplit(file->name(), &directory, &basename); - if (directory.length() > 0) { - output = directory + "/"; - } - basename = StripProto(basename); - - // CamelCase to be more ObjC friendly. - basename = UnderscoresToCamelCase(basename, true); - - output += basename; - return output; -} - -std::string FilePathBasename(const FileDescriptor* file) { - std::string output; - std::string basename; - std::string directory; - PathSplit(file->name(), &directory, &basename); - basename = StripProto(basename); - - // CamelCase to be more ObjC friendly. - output = UnderscoresToCamelCase(basename, true); - - return output; -} - -std::string FileClassName(const FileDescriptor* file) { - const std::string prefix = FileClassPrefix(file); - const std::string name = - UnderscoresToCamelCase(StripProto(BaseFileName(file)), true) + "Root"; - // There aren't really any reserved words that end in "Root", but playing - // it safe and checking. - return SanitizeNameForObjC(prefix, name, "_RootClass", NULL); -} - -std::string ClassNameWorker(const Descriptor* descriptor) { - std::string name; - if (descriptor->containing_type() != NULL) { - name = ClassNameWorker(descriptor->containing_type()); - name += "_"; - } - return name + descriptor->name(); -} - -std::string ClassNameWorker(const EnumDescriptor* descriptor) { - std::string name; - if (descriptor->containing_type() != NULL) { - name = ClassNameWorker(descriptor->containing_type()); - name += "_"; - } - return name + descriptor->name(); -} - -std::string ClassName(const Descriptor* descriptor) { - return ClassName(descriptor, NULL); -} - -std::string ClassName(const Descriptor* descriptor, - std::string* out_suffix_added) { - // 1. Message names are used as is (style calls for CamelCase, trust it). - // 2. Check for reserved word at the very end and then suffix things. - const std::string prefix = FileClassPrefix(descriptor->file()); - const std::string name = ClassNameWorker(descriptor); - return SanitizeNameForObjC(prefix, name, "_Class", out_suffix_added); -} - -std::string EnumName(const EnumDescriptor* descriptor) { - // 1. Enum names are used as is (style calls for CamelCase, trust it). - // 2. Check for reserved word at the every end and then suffix things. - // message Fixed { - // message Size {...} - // enum Mumble {...} - // ... - // } - // yields Fixed_Class, Fixed_Size. - const std::string prefix = FileClassPrefix(descriptor->file()); - const std::string name = ClassNameWorker(descriptor); - return SanitizeNameForObjC(prefix, name, "_Enum", NULL); -} - -std::string EnumValueName(const EnumValueDescriptor* descriptor) { - // Because of the Switch enum compatibility, the name on the enum has to have - // the suffix handing, so it slightly diverges from how nested classes work. - // enum Fixed { - // FOO = 1 - // } - // yields Fixed_Enum and Fixed_Enum_Foo (not Fixed_Foo). - const std::string class_name = EnumName(descriptor->type()); - const std::string value_str = - UnderscoresToCamelCase(descriptor->name(), true); - const std::string name = class_name + "_" + value_str; - // There aren't really any reserved words with an underscore and a leading - // capital letter, but playing it safe and checking. - return SanitizeNameForObjC("", name, "_Value", NULL); -} - -std::string EnumValueShortName(const EnumValueDescriptor* descriptor) { - // Enum value names (EnumValueName above) are the enum name turned into - // a class name and then the value name is CamelCased and concatenated; the - // whole thing then gets sanitized for reserved words. - // The "short name" is intended to be the final leaf, the value name; but - // you can't simply send that off to sanitize as that could result in it - // getting modified when the full name didn't. For example enum - // "StorageModes" has a value "retain". So the full name is - // "StorageModes_Retain", but if we sanitize "retain" it would become - // "RetainValue". - // So the right way to get the short name is to take the full enum name - // and then strip off the enum name (leaving the value name and anything - // done by sanitize). - const std::string class_name = EnumName(descriptor->type()); - const std::string long_name_prefix = class_name + "_"; - const std::string long_name = EnumValueName(descriptor); - return std::string(absl::StripPrefix(long_name, long_name_prefix)); -} - -std::string UnCamelCaseEnumShortName(const std::string& name) { - std::string result; - for (int i = 0; i < name.size(); i++) { - char c = name[i]; - if (i > 0 && absl::ascii_isupper(c)) { - result += '_'; - } - result += absl::ascii_toupper(c); - } - return result; -} - -std::string ExtensionMethodName(const FieldDescriptor* descriptor) { - const std::string name = NameFromFieldDescriptor(descriptor); - const std::string result = UnderscoresToCamelCase(name, false); - return SanitizeNameForObjC("", result, "_Extension", NULL); -} - -std::string FieldName(const FieldDescriptor* field) { - const std::string name = NameFromFieldDescriptor(field); - std::string result = UnderscoresToCamelCase(name, false); - if (field->is_repeated() && !field->is_map()) { - // Add "Array" before do check for reserved worlds. - result += "Array"; - } else { - // If it wasn't repeated, but ends in "Array", force on the _p suffix. - if (absl::EndsWith(result, "Array")) { - result += "_p"; - } - } - return SanitizeNameForObjC("", result, "_p", NULL); -} - -std::string FieldNameCapitalized(const FieldDescriptor* field) { - // Want the same suffix handling, so upcase the first letter of the other - // name. - std::string result = FieldName(field); - if (result.length() > 0) { - result[0] = absl::ascii_toupper(result[0]); - } - return result; -} - -std::string OneofEnumName(const OneofDescriptor* descriptor) { - const Descriptor* fieldDescriptor = descriptor->containing_type(); - std::string name = ClassName(fieldDescriptor); - name += "_" + UnderscoresToCamelCase(descriptor->name(), true) + "_OneOfCase"; - // No sanitize needed because the OS never has names that end in _OneOfCase. - return name; -} - -std::string OneofName(const OneofDescriptor* descriptor) { - std::string name = UnderscoresToCamelCase(descriptor->name(), false); - // No sanitize needed because it gets OneOfCase added and that shouldn't - // ever conflict. - return name; -} - -std::string OneofNameCapitalized(const OneofDescriptor* descriptor) { - // Use the common handling and then up-case the first letter. - std::string result = OneofName(descriptor); - if (result.length() > 0) { - result[0] = absl::ascii_toupper(result[0]); - } - return result; -} - -std::string UnCamelCaseFieldName(const std::string& name, - const FieldDescriptor* field) { - absl::string_view worker(name); - if (absl::EndsWith(worker, "_p")) { - worker = absl::StripSuffix(worker, "_p"); - } - if (field->is_repeated() && absl::EndsWith(worker, "Array")) { - worker = absl::StripSuffix(worker, "Array"); - } - if (field->type() == FieldDescriptor::TYPE_GROUP) { - if (worker.length() > 0) { - if (absl::ascii_islower(worker[0])) { - std::string copy(worker); - copy[0] = absl::ascii_toupper(worker[0]); - return copy; - } - } - return std::string(worker); - } else { - std::string result; - for (int i = 0; i < worker.size(); i++) { - char c = worker[i]; - if (absl::ascii_isupper(c)) { - if (i > 0) { - result += '_'; - } - result += absl::ascii_tolower(c); - } else { - result += c; - } - } - return result; - } -} - -// Making these a generator option for folks that don't use CocoaPods, but do -// want to put the library in a framework is an interesting question. The -// problem is it means changing sources shipped with the library to actually -// use a different value; so it isn't as simple as a option. -const char* const ProtobufLibraryFrameworkName = "Protobuf"; - -std::string ProtobufFrameworkImportSymbol(const std::string& framework_name) { - // GPB_USE_[framework_name]_FRAMEWORK_IMPORTS - std::string result = std::string("GPB_USE_"); - result += absl::AsciiStrToUpper(framework_name); - result += "_FRAMEWORK_IMPORTS"; - return result; -} - -bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file) { - // We don't check the name prefix or proto package because some files - // (descriptor.proto), aren't shipped generated by the library, so this - // seems to be the safest way to only catch the ones shipped. - const std::string name = file->name(); - if (name == "google/protobuf/any.proto" || - name == "google/protobuf/api.proto" || - name == "google/protobuf/duration.proto" || - name == "google/protobuf/empty.proto" || - name == "google/protobuf/field_mask.proto" || - name == "google/protobuf/source_context.proto" || - name == "google/protobuf/struct.proto" || - name == "google/protobuf/timestamp.proto" || - name == "google/protobuf/type.proto" || - name == "google/protobuf/wrappers.proto") { - return true; - } - return false; -} - -namespace { - -bool PackageToPrefixesCollector::ConsumeLine(const absl::string_view& line, - std::string* out_error) { - int offset = line.find('='); - if (offset == absl::string_view::npos) { - *out_error = - usage_ + " file line without equal sign: '" + absl::StrCat(line) + "'."; - return false; - } - absl::string_view package = - absl::StripAsciiWhitespace(line.substr(0, offset)); - absl::string_view prefix = - absl::StripAsciiWhitespace(line.substr(offset + 1)); - MaybeUnQuote(&prefix); - // Don't really worry about error checking the package/prefix for - // being valid. Assume the file is validated when it is created/edited. - (*prefix_map_)[std::string(package)] = std::string(prefix); - return true; -} - -bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, - std::map* prefix_map, - std::string* out_error) { - if (expected_prefixes_path.empty()) { - return true; - } - - PackageToPrefixesCollector collector("Expected prefixes", prefix_map); - return ParseSimpleFile(expected_prefixes_path, &collector, out_error); -} - -bool ValidateObjCClassPrefix( - const FileDescriptor* file, const std::string& expected_prefixes_path, - const std::map& expected_package_prefixes, - bool prefixes_must_be_registered, bool require_prefixes, - std::string* out_error) { - // Reminder: An explicit prefix option of "" is valid in case the default - // prefixing is set to use the proto package and a file needs to be generated - // without any prefix at all (for legacy reasons). - - bool has_prefix = file->options().has_objc_class_prefix(); - bool have_expected_prefix_file = !expected_prefixes_path.empty(); - - const std::string prefix = file->options().objc_class_prefix(); - const std::string package = file->package(); - // For files without packages, the can be registered as "no_package:PATH", - // allowing the expected prefixes file. - static const std::string no_package_prefix("no_package:"); - const std::string lookup_key = - package.empty() ? no_package_prefix + file->name() : package; - - // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some - // error cases, so it seems to be ok to use as a back door for warnings. - - // Check: Error - See if there was an expected prefix for the package and - // report if it doesn't match (wrong or missing). - std::map::const_iterator package_match = - expected_package_prefixes.find(lookup_key); - if (package_match != expected_package_prefixes.end()) { - // There was an entry, and... - if (has_prefix && package_match->second == prefix) { - // ...it matches. All good, out of here! - return true; - } else { - // ...it didn't match! - *out_error = "error: Expected 'option objc_class_prefix = \"" + - package_match->second + "\";'"; - if (!package.empty()) { - *out_error += " for package '" + package + "'"; - } - *out_error += " in '" + file->name() + "'"; - if (has_prefix) { - *out_error += "; but found '" + prefix + "' instead"; - } - *out_error += "."; - return false; - } - } - - // If there was no prefix option, we're done at this point. - if (!has_prefix) { - if (require_prefixes) { - *out_error = "error: '" + file->name() + - "' does not have a required 'option" + - " objc_class_prefix'."; - return false; - } - return true; - } - - // When the prefix is non empty, check it against the expected entries. - if (!prefix.empty() && have_expected_prefix_file) { - // For a non empty prefix, look for any other package that uses the prefix. - std::string other_package_for_prefix; - for (std::map::const_iterator i = - expected_package_prefixes.begin(); - i != expected_package_prefixes.end(); ++i) { - if (i->second == prefix) { - other_package_for_prefix = i->first; - // Stop on the first real package listing, if it was a no_package file - // specific entry, keep looking to try and find a package one. - if (!absl::StartsWith(other_package_for_prefix, no_package_prefix)) { - break; - } - } - } - - // Check: Error - Make sure the prefix wasn't expected for a different - // package (overlap is allowed, but it has to be listed as an expected - // overlap). - if (!other_package_for_prefix.empty()) { - *out_error = "error: Found 'option objc_class_prefix = \"" + prefix + - "\";' in '" + file->name() + - "'; that prefix is already used for "; - if (absl::StartsWith(other_package_for_prefix, no_package_prefix)) { - absl::StrAppend( - out_error, "file '", - absl::StripPrefix(other_package_for_prefix, no_package_prefix), - "'."); - } else { - absl::StrAppend(out_error, "'package ", - other_package_for_prefix + ";'."); - } - absl::StrAppend(out_error, " It can only be reused by adding '", - lookup_key, " = ", prefix, - "' to the expected prefixes file (", - expected_prefixes_path, ")."); - return false; // Only report first usage of the prefix. - } - } // !prefix.empty() && have_expected_prefix_file - - // Check: Warning - Make sure the prefix is is a reasonable value according - // to Apple's rules (the checks above implicitly whitelist anything that - // doesn't meet these rules). - if (!prefix.empty() && !absl::ascii_isupper(prefix[0])) { - std::cerr << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" - << prefix << "\";' in '" << file->name() << "';" - << " it should start with a capital letter." << std::endl; - std::cerr.flush(); - } - if (!prefix.empty() && prefix.length() < 3) { - // Apple reserves 2 character prefixes for themselves. They do use some - // 3 character prefixes, but they haven't updated the rules/docs. - std::cerr << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" - << prefix << "\";' in '" << file->name() << "';" - << " Apple recommends they should be at least 3 characters long." - << std::endl; - std::cerr.flush(); - } - - // Check: Error/Warning - If the given package/prefix pair wasn't expected, - // issue a error/warning to added to the file. - if (have_expected_prefix_file) { - if (prefixes_must_be_registered) { - *out_error = - "error: '" + file->name() + "' has 'option objc_class_prefix = \"" + - prefix + "\";', but it is not registered. Add '" + lookup_key + - " = " + (prefix.empty() ? "\"\"" : prefix) + - "' to the expected prefixes file (" + expected_prefixes_path + ")."; - return false; - } - - std::cerr - << "protoc:0: warning: Found unexpected 'option objc_class_prefix = \"" - << prefix << "\";' in '" << file->name() << "'; consider adding '" - << lookup_key << " = " << (prefix.empty() ? "\"\"" : prefix) - << "' to the expected prefixes file (" << expected_prefixes_path << ")." - << std::endl; - std::cerr.flush(); - } - - return true; -} - -} // namespace - -Options::Options() { - // While there are generator options, also support env variables to help with - // build systems where it isn't as easy to hook in for add the generation - // options when invoking protoc. - const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); - if (file_path) { - expected_prefixes_path = file_path; - } - const char* suppressions = - getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES_SUPPRESSIONS"); - if (suppressions) { - expected_prefixes_suppressions = - absl::StrSplit(suppressions, ";", absl::SkipEmpty()); - } - prefixes_must_be_registered = - BoolFromEnvVar("GPB_OBJC_PREFIXES_MUST_BE_REGISTERED", false); - require_prefixes = BoolFromEnvVar("GPB_OBJC_REQUIRE_PREFIXES", false); -} - -bool ValidateObjCClassPrefixes(const std::vector& files, - std::string* out_error) { - // Options's ctor load from the environment. - Options options; - return ValidateObjCClassPrefixes(files, options, out_error); -} - -bool ValidateObjCClassPrefixes(const std::vector& files, - const Options& generation_options, - std::string* out_error) { - // Allow a '-' as the path for the expected prefixes to completely disable - // even the most basic of checks. - if (generation_options.expected_prefixes_path == "-") { - return true; - } - - // Load the expected package prefixes, if available, to validate against. - std::map expected_package_prefixes; - if (!LoadExpectedPackagePrefixes(generation_options.expected_prefixes_path, - &expected_package_prefixes, out_error)) { - return false; - } - - for (int i = 0; i < files.size(); i++) { - bool should_skip = - (std::find(generation_options.expected_prefixes_suppressions.begin(), - generation_options.expected_prefixes_suppressions.end(), - files[i]->name()) != - generation_options.expected_prefixes_suppressions.end()); - if (should_skip) { - continue; - } - - bool is_valid = ValidateObjCClassPrefix( - files[i], generation_options.expected_prefixes_path, - expected_package_prefixes, - generation_options.prefixes_must_be_registered, - generation_options.require_prefixes, out_error); - if (!is_valid) { - return false; - } - } - return true; -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/names.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/names.h deleted file mode 100644 index f1c67d0..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/names.h +++ /dev/null @@ -1,180 +0,0 @@ -// 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. - -// Helper functions for generating ObjectiveC code. - -#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__ - -#include -#include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/zero_copy_stream.h" - -// Must be included last -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// Get/Set the path to a file to load for objc class prefix lookups. -std::string PROTOC_EXPORT GetPackageToPrefixMappingsPath(); -void PROTOC_EXPORT SetPackageToPrefixMappingsPath(const std::string& file_path); -// Get/Set if the proto package should be used to make the default prefix for -// symbols. This will then impact most of the type naming apis below. It is done -// as a global to not break any other generator reusing the methods since they -// are exported. -bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix(); -void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off); -// Get/Set the path to a file to load as exceptions when -// `UseProtoPackageAsDefaultPrefix()` is `true`. An empty string means there -// should be no exceptions. -std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList(); -void PROTOC_EXPORT -SetProtoPackagePrefixExceptionList(const std::string& file_path); -// Get/Set a prefix to add before the prefix generated from the package name. -// This is only used when UseProtoPackageAsDefaultPrefix() is True. -std::string PROTOC_EXPORT GetForcedPackagePrefix(); -void PROTOC_EXPORT SetForcedPackagePrefix(const std::string& prefix); - -// Returns true if the name requires a ns_returns_not_retained attribute applied -// to it. -bool PROTOC_EXPORT IsRetainedName(const std::string& name); - -// Returns true if the name starts with "init" and will need to have special -// handling under ARC. -bool PROTOC_EXPORT IsInitName(const std::string& name); - -// Returns true if the name requires a cf_returns_not_retained attribute applied -// to it. -bool PROTOC_EXPORT IsCreateName(const std::string& name); - -// Gets the objc_class_prefix or the prefix made from the proto package. -std::string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); - -// Gets the path of the file we're going to generate (sans the .pb.h -// extension). The path will be dependent on the objectivec package -// declared in the proto package. -std::string PROTOC_EXPORT FilePath(const FileDescriptor* file); - -// Just like FilePath(), but without the directory part. -std::string PROTOC_EXPORT FilePathBasename(const FileDescriptor* file); - -// Gets the name of the root class we'll generate in the file. This class -// is not meant for external consumption, but instead contains helpers that -// the rest of the classes need -std::string PROTOC_EXPORT FileClassName(const FileDescriptor* file); - -// These return the fully-qualified class name corresponding to the given -// descriptor. -std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor); -std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor, - std::string* out_suffix_added); -std::string PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); - -// Returns the fully-qualified name of the enum value corresponding to the -// the descriptor. -std::string PROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); - -// Returns the name of the enum value corresponding to the descriptor. -std::string PROTOC_EXPORT -EnumValueShortName(const EnumValueDescriptor* descriptor); - -// Reverse what an enum does. -std::string PROTOC_EXPORT UnCamelCaseEnumShortName(const std::string& name); - -// Returns the name to use for the extension (used as the method off the file's -// Root class). -std::string PROTOC_EXPORT -ExtensionMethodName(const FieldDescriptor* descriptor); - -// Returns the transformed field name. -std::string PROTOC_EXPORT FieldName(const FieldDescriptor* field); -std::string PROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); - -// Returns the transformed oneof name. -std::string PROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); -std::string PROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); -std::string PROTOC_EXPORT -OneofNameCapitalized(const OneofDescriptor* descriptor); - -// Reverse of the above. -std::string PROTOC_EXPORT UnCamelCaseFieldName(const std::string& name, - const FieldDescriptor* field); - -// The name the commonly used by the library when built as a framework. -// This lines up to the name used in the CocoaPod. -extern PROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; -// Returns the CPP symbol name to use as the gate for framework style imports -// for the given framework name to use. -std::string PROTOC_EXPORT -ProtobufFrameworkImportSymbol(const std::string& framework_name); - -// --------------------------------------------------------------------------- - -// These aren't really "naming" related, but can be useful for something -// building on top of ObjC Protos to be able to share the knowledge/enforcement. - -// Checks if the file is one of the proto's bundled with the library. -bool PROTOC_EXPORT -IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); - -// Generator Prefix Validation Options (see generator.cc for a -// description of each): -struct Options { - Options(); - std::string expected_prefixes_path; - std::vector expected_prefixes_suppressions; - bool prefixes_must_be_registered; - bool require_prefixes; -}; - -// Checks the prefix for the given files and outputs any warnings as needed. If -// there are flat out errors, then out_error is filled in with the first error -// and the result is false. -bool PROTOC_EXPORT ValidateObjCClassPrefixes( - const std::vector& files, - const Options& validation_options, std::string* out_error); -// Same was the other ValidateObjCClassPrefixes() calls, but the options all -// come from the environment variables. -bool PROTOC_EXPORT ValidateObjCClassPrefixes( - const std::vector& files, std::string* out_error); - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/names_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/names_unittest.cc deleted file mode 100644 index 8063049..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/names_unittest.cc +++ /dev/null @@ -1,139 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 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/compiler/objectivec/names.h" - -#include - -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { -namespace { - -TEST(ObjCHelper, IsRetainedName) { - EXPECT_TRUE(IsRetainedName("new")); - EXPECT_TRUE(IsRetainedName("alloc")); - EXPECT_TRUE(IsRetainedName("copy")); - EXPECT_TRUE(IsRetainedName("mutableCopy")); - EXPECT_TRUE(IsRetainedName("newFoo")); - EXPECT_TRUE(IsRetainedName("allocFoo")); - EXPECT_TRUE(IsRetainedName("copyFoo")); - EXPECT_TRUE(IsRetainedName("mutableCopyFoo")); - EXPECT_TRUE(IsRetainedName("new_foo")); - EXPECT_TRUE(IsRetainedName("alloc_foo")); - EXPECT_TRUE(IsRetainedName("copy_foo")); - EXPECT_TRUE(IsRetainedName("mutableCopy_foo")); - - EXPECT_FALSE(IsRetainedName("")); - EXPECT_FALSE(IsRetainedName("ne")); - EXPECT_FALSE(IsRetainedName("all")); - EXPECT_FALSE(IsRetainedName("co")); - EXPECT_FALSE(IsRetainedName("mutable")); - EXPECT_FALSE(IsRetainedName("New")); - EXPECT_FALSE(IsRetainedName("Alloc")); - EXPECT_FALSE(IsRetainedName("Copy")); - EXPECT_FALSE(IsRetainedName("MutableCopy")); - EXPECT_FALSE(IsRetainedName("newer")); - EXPECT_FALSE(IsRetainedName("alloced")); - EXPECT_FALSE(IsRetainedName("copying")); - EXPECT_FALSE(IsRetainedName("mutableCopying")); - - EXPECT_FALSE(IsRetainedName("init")); - EXPECT_FALSE(IsRetainedName("Create")); - EXPECT_FALSE(IsRetainedName("Copy")); -} - -TEST(ObjCHelper, IsInitName) { - EXPECT_TRUE(IsInitName("init")); - EXPECT_TRUE(IsInitName("initFoo")); - EXPECT_TRUE(IsInitName("init_foo")); - - EXPECT_FALSE(IsInitName("")); - EXPECT_FALSE(IsInitName("in")); - EXPECT_FALSE(IsInitName("Init")); - EXPECT_FALSE(IsInitName("inIt")); - EXPECT_FALSE(IsInitName("initial")); - EXPECT_FALSE(IsInitName("initiAl")); - EXPECT_FALSE(IsInitName("fooInit")); - EXPECT_FALSE(IsInitName("foo_init")); - - EXPECT_FALSE(IsInitName("new")); - EXPECT_FALSE(IsInitName("alloc")); - EXPECT_FALSE(IsInitName("copy")); - EXPECT_FALSE(IsInitName("mutableCopy")); - EXPECT_FALSE(IsInitName("Create")); - EXPECT_FALSE(IsInitName("Copy")); -} - -TEST(ObjCHelper, IsCreateName) { - EXPECT_TRUE(IsCreateName("Create")); - EXPECT_TRUE(IsCreateName("Copy")); - EXPECT_TRUE(IsCreateName("CreateFoo")); - EXPECT_TRUE(IsCreateName("CopyFoo")); - EXPECT_TRUE(IsCreateName("Create_foo")); - EXPECT_TRUE(IsCreateName("Copy_foo")); - EXPECT_TRUE(IsCreateName("ReCreate")); - EXPECT_TRUE(IsCreateName("ReCopy")); - EXPECT_TRUE(IsCreateName("FOOCreate")); - EXPECT_TRUE(IsCreateName("FOOCopy")); - EXPECT_TRUE(IsCreateName("CreateWithCopy")); - - EXPECT_FALSE(IsCreateName("")); - EXPECT_FALSE(IsCreateName("Crea")); - EXPECT_FALSE(IsCreateName("Co")); - EXPECT_FALSE(IsCreateName("create")); - EXPECT_FALSE(IsCreateName("recreate")); - EXPECT_FALSE(IsCreateName("recopy")); - EXPECT_FALSE(IsCreateName("ReCreated")); - EXPECT_FALSE(IsCreateName("ReCopying")); - - EXPECT_FALSE(IsCreateName("init")); - EXPECT_FALSE(IsCreateName("new")); - EXPECT_FALSE(IsCreateName("alloc")); - EXPECT_FALSE(IsCreateName("copy")); - EXPECT_TRUE(IsCreateName("mutableCopy")); -} - -// TODO(thomasvl): Should probably add some unittests for all the special cases -// of name mangling (class name, field name, enum names). Rather than doing -// this with an ObjC test in the objectivec directory, we should be able to -// use src/google/protobuf/compiler/importer* (like other tests) to support a -// virtual file system to feed in protos, once we have the Descriptor tree, the -// tests could use the helper methods for generating names and validate the -// right things are happening. - -} // namespace -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/nsobject_methods.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/nsobject_methods.h deleted file mode 100644 index 7a1b9ef..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/nsobject_methods.h +++ /dev/null @@ -1,227 +0,0 @@ -// 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. - -// NSObject methods -// Autogenerated by method_dump.sh. Do not edit by hand. -// Date: Thu Nov 1 14:12:16 PDT 2018 -// macOS: MacOSX10.14.sdk -// iOS: iPhoneSimulator12.1.sdk - -const char* const kNSObjectMethodsList[] = { - "CAMLType", - "CA_copyRenderValue", - "CA_prepareRenderValue", - "NS_copyCGImage", - "NS_tiledLayerVisibleRect", - "___tryRetain_OA", - "__autorelease_OA", - "__dealloc_zombie", - "__release_OA", - "__retain_OA", - "_accessibilityFinalize", - "_accessibilityIsTableViewDescendant", - "_accessibilityUIElementSpecifier", - "_accessibilityUseConvenienceAPI", - "_allowsDirectEncoding", - "_asScriptTerminologyNameArray", - "_asScriptTerminologyNameString", - "_bindingAdaptor", - "_cfTypeID", - "_copyDescription", - "_destroyObserverList", - "_didEndKeyValueObserving", - "_implicitObservationInfo", - "_internalAccessibilityAttributedHint", - "_internalAccessibilityAttributedLabel", - "_internalAccessibilityAttributedValue", - "_isAXConnector", - "_isAccessibilityContainerSectionCandidate", - "_isAccessibilityContentNavigatorSectionCandidate", - "_isAccessibilityContentSectionCandidate", - "_isAccessibilityTopLevelNavigatorSectionCandidate", - "_isDeallocating", - "_isKVOA", - "_isToManyChangeInformation", - "_ivarDescription", - "_localClassNameForClass", - "_methodDescription", - "_observerStorage", - "_overrideUseFastBlockObservers", - "_propertyDescription", - "_releaseBindingAdaptor", - "_scriptingCount", - "_scriptingCountNonrecursively", - "_scriptingDebugDescription", - "_scriptingExists", - "_scriptingShouldCheckObjectIndexes", - "_shortMethodDescription", - "_shouldSearchChildrenForSection", - "_traitStorageList", - "_tryRetain", - "_ui_descriptionBuilder", - "_uikit_variesByTraitCollections", - "_web_description", - "_webkit_invokeOnMainThread", - "_willBeginKeyValueObserving", - "accessibilityActivate", - "accessibilityActivationPoint", - "accessibilityAllowsOverriddenAttributesWhenIgnored", - "accessibilityAssistiveTechnologyFocusedIdentifiers", - "accessibilityAttributedHint", - "accessibilityAttributedLabel", - "accessibilityAttributedValue", - "accessibilityContainer", - "accessibilityContainerType", - "accessibilityCustomActions", - "accessibilityCustomRotors", - "accessibilityDecrement", - "accessibilityDragSourceDescriptors", - "accessibilityDropPointDescriptors", - "accessibilityElementCount", - "accessibilityElementDidBecomeFocused", - "accessibilityElementDidLoseFocus", - "accessibilityElementIsFocused", - "accessibilityElements", - "accessibilityElementsHidden", - "accessibilityFrame", - "accessibilityHeaderElements", - "accessibilityHint", - "accessibilityIdentification", - "accessibilityIdentifier", - "accessibilityIncrement", - "accessibilityLabel", - "accessibilityLanguage", - "accessibilityLocalizedStringKey", - "accessibilityNavigationStyle", - "accessibilityOverriddenAttributes", - "accessibilityParameterizedAttributeNames", - "accessibilityPath", - "accessibilityPerformEscape", - "accessibilityPerformMagicTap", - "accessibilityPresenterProcessIdentifier", - "accessibilityShouldUseUniqueId", - "accessibilitySupportsNotifications", - "accessibilitySupportsOverriddenAttributes", - "accessibilityTemporaryChildren", - "accessibilityTraits", - "accessibilityValue", - "accessibilityViewIsModal", - "accessibilityVisibleArea", - "allPropertyKeys", - "allowsWeakReference", - "attributeKeys", - "autoContentAccessingProxy", - "autorelease", - "awakeFromNib", - "boolValueSafe", - "bs_encoded", - "bs_isPlistableType", - "bs_secureEncoded", - "cl_json_serializeKey", - "class", - "classCode", - "classDescription", - "classForArchiver", - "classForCoder", - "classForKeyedArchiver", - "classForPortCoder", - "className", - "clearProperties", - "copy", - "dealloc", - "debugDescription", - "defaultAccessibilityTraits", - "description", - "doubleValueSafe", - "entityName", - "exposedBindings", - "finalize", - "finishObserving", - "flushKeyBindings", - "hash", - "init", - "int64ValueSafe", - "isAccessibilityElement", - "isAccessibilityElementByDefault", - "isElementAccessibilityExposedToInterfaceBuilder", - "isFault", - "isNSArray__", - "isNSCFConstantString__", - "isNSData__", - "isNSDate__", - "isNSDictionary__", - "isNSNumber__", - "isNSObject__", - "isNSOrderedSet__", - "isNSSet__", - "isNSString__", - "isNSTimeZone__", - "isNSValue__", - "isProxy", - "mutableCopy", - "nilValueForKey", - "objectSpecifier", - "observationInfo", - "pep_onDetachedThread", - "pep_onMainThread", - "pep_onMainThreadIfNecessary", - "prepareForInterfaceBuilder", - "release", - "releaseOnMainThread", - "retain", - "retainCount", - "retainWeakReference", - "scriptingProperties", - "self", - "shouldGroupAccessibilityChildren", - "storedAccessibilityActivationPoint", - "storedAccessibilityContainerType", - "storedAccessibilityElementsHidden", - "storedAccessibilityFrame", - "storedAccessibilityNavigationStyle", - "storedAccessibilityTraits", - "storedAccessibilityViewIsModal", - "storedIsAccessibilityElement", - "storedShouldGroupAccessibilityChildren", - "stringValueSafe", - "superclass", - "toManyRelationshipKeys", - "toOneRelationshipKeys", - "traitStorageList", - "un_safeBoolValue", - "userInterfaceItemIdentifier", - "utf8ValueSafe", - "valuesForKeysWithDictionary", - "zone", - // Protocol: CAAnimatableValue - // Protocol: CARenderValue - // Protocol: NSObject - // Protocol: ROCKRemoteInvocationInterface -}; diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc similarity index 74% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/enum.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index af3e335..ea8f394 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -28,37 +28,23 @@ // (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/compiler/objectivec/enum.h" - -#include #include #include -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/compiler/objectivec/text_format_decode_data.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include // std::find() namespace google { namespace protobuf { namespace compiler { namespace objectivec { -namespace { -std::string SafelyPrintIntToCode(int v) { - if (v == std::numeric_limits::min()) { - // Some compilers try to parse -2147483648 as two tokens and then get spicy - // about the fact that +2147483648 cannot be represented as an int. - return absl::StrCat(v + 1, " - 1"); - } else { - return absl::StrCat(v); - } -} -} // namespace EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) - : descriptor_(descriptor), name_(EnumName(descriptor_)) { + : descriptor_(descriptor), + name_(EnumName(descriptor_)) { // Track the names for the enum values, and if an alias overlaps a base // value, skip making a name for it. Likewise if two alias overlap, the // first one wins. @@ -120,33 +106,29 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { // doesn't have to bother with the `enum_extensibility` attribute, as the // default will be what is needed. - printer->Print( - "$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", - "comments", enum_comments, "deprecated_attribute", - GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()), "name", - name_); + printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", + "comments", enum_comments, + "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()), + "name", name_); printer->Indent(); if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { // Include the unknown value. printer->Print( - // clang-format off - "/**\n" - " * Value used if any message's field encounters a value that is not defined\n" - " * by this enum. The message will also have C functions to get/set the rawValue\n" - " * of the field.\n" - " **/\n" - "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n", - // clang-format on - "name", name_); + "/**\n" + " * Value used if any message's field encounters a value that is not defined\n" + " * by this enum. The message will also have C functions to get/set the rawValue\n" + " * of the field.\n" + " **/\n" + "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n", + "name", name_); } for (int i = 0; i < all_values_.size(); i++) { - if (alias_values_to_skip_.find(all_values_[i]) != - alias_values_to_skip_.end()) { + if (alias_values_to_skip_.find(all_values_[i]) != alias_values_to_skip_.end()) { continue; } if (all_values_[i]->GetSourceLocation(&location)) { - std::string comments = BuildCommentsString(location, true); + std::string comments = BuildCommentsString(location, true).c_str(); if (comments.length() > 0) { if (i > 0) { printer->Print("\n"); @@ -155,14 +137,14 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { } } - printer->Print("$name$$deprecated_attribute$ = $value$,\n", "name", - EnumValueName(all_values_[i]), "deprecated_attribute", - GetOptionalDeprecatedAttribute(all_values_[i]), "value", - SafelyPrintIntToCode(all_values_[i]->number())); + printer->Print( + "$name$$deprecated_attribute$ = $value$,\n", + "name", EnumValueName(all_values_[i]), + "deprecated_attribute", GetOptionalDeprecatedAttribute(all_values_[i]), + "value", StrCat(all_values_[i]->number())); } printer->Outdent(); printer->Print( - // clang-format off "};\n" "\n" "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n" @@ -172,7 +154,6 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { " * the time this source was generated.\n" " **/\n" "BOOL $name$_IsValidValue(int32_t value);\n" - // clang-format on "\n", "name", name_); } @@ -203,42 +184,38 @@ void EnumGenerator::GenerateSource(io::Printer* printer) { } printer->Print( - // clang-format off "GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n" " static _Atomic(GPBEnumDescriptor*) descriptor = nil;\n" " if (!descriptor) {\n", - // clang-format on "name", name_); static const int kBytesPerLine = 40; // allow for escaping - printer->Print(" static const char *valueNames ="); + printer->Print( + " static const char *valueNames ="); for (int i = 0; i < text_blob.size(); i += kBytesPerLine) { printer->Print( - "\n \"$data$\"", "data", - EscapeTrigraphs(absl::CEscape(text_blob.substr(i, kBytesPerLine)))); + "\n \"$data$\"", + "data", EscapeTrigraphs(CEscape(text_blob.substr(i, kBytesPerLine)))); } printer->Print( ";\n" " static const int32_t values[] = {\n"); for (int i = 0; i < all_values_.size(); i++) { - printer->Print(" $name$,\n", "name", EnumValueName(all_values_[i])); + printer->Print(" $name$,\n", "name", EnumValueName(all_values_[i])); } printer->Print(" };\n"); if (text_format_decode_data.num_entries() == 0) { printer->Print( - // clang-format off " GPBEnumDescriptor *worker =\n" " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n" " valueNames:valueNames\n" " values:values\n" " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n" " enumVerifier:$name$_IsValidValue];\n", - // clang-format on "name", name_); - } else { - printer->Print( - // clang-format off + } else { + printer->Print( " static const char *extraTextFormatInfo = \"$extraTextFormatInfo$\";\n" " GPBEnumDescriptor *worker =\n" " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n" @@ -247,41 +224,35 @@ void EnumGenerator::GenerateSource(io::Printer* printer) { " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n" " enumVerifier:$name$_IsValidValue\n" " extraTextFormatInfo:extraTextFormatInfo];\n", - // clang-format on - "name", name_, "extraTextFormatInfo", - absl::CEscape(text_format_decode_data.Data())); - } - // clang-format off - printer->Print( - " GPBEnumDescriptor *expected = nil;\n" - " if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n" - " [worker release];\n" - " }\n" - " }\n" - " return descriptor;\n" - "}\n\n"); - // clang-format on + "name", name_, + "extraTextFormatInfo", CEscape(text_format_decode_data.Data())); + } + printer->Print( + " GPBEnumDescriptor *expected = nil;\n" + " if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n" + " [worker release];\n" + " }\n" + " }\n" + " return descriptor;\n" + "}\n\n"); printer->Print( - // clang-format off "BOOL $name$_IsValidValue(int32_t value__) {\n" " switch (value__) {\n", - // clang-format on "name", name_); for (int i = 0; i < base_values_.size(); i++) { - printer->Print(" case $name$:\n", "name", - EnumValueName(base_values_[i])); + printer->Print( + " case $name$:\n", + "name", EnumValueName(base_values_[i])); } - // clang-format off printer->Print( " return YES;\n" " default:\n" " return NO;\n" " }\n" "}\n\n"); - // clang-format on } } // namespace objectivec } // namespace compiler diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h similarity index 97% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/enum.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h index 65f7411..1d5741a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h @@ -31,12 +31,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ENUM_H__ -#include #include +#include #include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc similarity index 90% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index c08cbde..6e0d69b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -28,14 +28,12 @@ // (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/compiler/objectivec/enum_field.h" - #include #include -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include namespace google { namespace protobuf { @@ -79,7 +77,6 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations( return; } - // clang-format off printer->Print( variables_, "/**\n" @@ -94,14 +91,12 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations( " **/\n" "void Set$owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message, int32_t value);\n" "\n"); - // clang-format on } void EnumFieldGenerator::GenerateCFunctionImplementations( io::Printer* printer) const { if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) return; - // clang-format off printer->Print( variables_, "int32_t $owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message) {\n" @@ -116,13 +111,13 @@ void EnumFieldGenerator::GenerateCFunctionImplementations( " GPBSetMessageRawEnumField(message, field, value);\n" "}\n" "\n"); - // clang-format on } void EnumFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { - SingleFieldGenerator::DetermineForwardDeclarations(fwd_decls, - include_external_types); + std::set* fwd_decls, + bool include_external_types) const { + SingleFieldGenerator::DetermineForwardDeclarations( + fwd_decls, include_external_types); // If it is an enum defined in a different file (and not a WKT), then we'll // need a forward declaration for it. When it is in our file, all the enums // are output before the message, so it will be declared before it is needed. @@ -146,8 +141,8 @@ RepeatedEnumFieldGenerator::~RepeatedEnumFieldGenerator() {} void RepeatedEnumFieldGenerator::FinishInitialization(void) { RepeatedFieldGenerator::FinishInitialization(); - variables_["array_comment"] = "// |" + variables_["name"] + "| contains |" + - variables_["storage_type"] + "|\n"; + variables_["array_comment"] = + "// |" + variables_["name"] + "| contains |" + variables_["storage_type"] + "|\n"; } } // namespace objectivec diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h similarity index 97% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h index ac4e70f..f0d685c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/enum_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h @@ -33,8 +33,7 @@ #include #include - -#include "google/protobuf/compiler/objectivec/field.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/extension.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc similarity index 79% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/extension.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index d23cf5c..9cebcb2 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/extension.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -28,15 +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. -#include "google/protobuf/compiler/objectivec/extension.h" - #include -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -52,7 +50,7 @@ ExtensionGenerator::ExtensionGenerator(const std::string& root_class_name, // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. std::cerr << "error: Extension is a map<>!" - << " That used to be blocked by the compiler." << std::endl; + << " That used to be blocked by the compiler." << std::endl; std::cerr.flush(); abort(); } @@ -76,14 +74,10 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { } // Unlike normal message fields, check if the file for the extension was // deprecated. - vars["deprecated_attribute"] = - GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()); - // clang-format off - printer->Print( - vars, - "$comments$" - "+ (GPBExtensionDescriptor *)$method_name$$storage_attribute$$deprecated_attribute$;\n"); - // clang-format on + vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()); + printer->Print(vars, + "$comments$" + "+ (GPBExtensionDescriptor *)$method_name$$storage_attribute$$deprecated_attribute$;\n"); } void ExtensionGenerator::GenerateStaticVariablesInitialization( @@ -92,7 +86,7 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization( vars["root_class_and_method_name"] = root_class_and_method_name_; const std::string containing_type = ClassName(descriptor_->containing_type()); vars["extended_type"] = ObjCClass(containing_type); - vars["number"] = absl::StrCat(descriptor_->number()); + vars["number"] = StrCat(descriptor_->number()); std::vector options; if (descriptor_->is_repeated()) options.push_back("GPBExtensionRepeated"); @@ -121,25 +115,22 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization( if (objc_type == OBJECTIVECTYPE_ENUM) { vars["enum_desc_func_name"] = - EnumName(descriptor_->enum_type()) + "_EnumDescriptor"; + EnumName(descriptor_->enum_type()) + "_EnumDescriptor"; } else { vars["enum_desc_func_name"] = "NULL"; } - // clang-format off - printer->Print( - vars, - "{\n" - " .defaultValue.$default_name$ = $default$,\n" - " .singletonName = GPBStringifySymbol($root_class_and_method_name$),\n" - " .extendedClass.clazz = $extended_type$,\n" - " .messageOrGroupClass.clazz = $type$,\n" - " .enumDescriptorFunc = $enum_desc_func_name$,\n" - " .fieldNumber = $number$,\n" - " .dataType = $extension_type$,\n" - " .options = $options$,\n" - "},\n"); - // clang-format on + printer->Print(vars, + "{\n" + " .defaultValue.$default_name$ = $default$,\n" + " .singletonName = GPBStringifySymbol($root_class_and_method_name$),\n" + " .extendedClass.clazz = $extended_type$,\n" + " .messageOrGroupClass.clazz = $type$,\n" + " .enumDescriptorFunc = $enum_desc_func_name$,\n" + " .fieldNumber = $number$,\n" + " .dataType = $extension_type$,\n" + " .options = $options$,\n" + "},\n"); } void ExtensionGenerator::DetermineObjectiveCClassDefinitions( @@ -154,11 +145,9 @@ void ExtensionGenerator::DetermineObjectiveCClassDefinitions( } void ExtensionGenerator::GenerateRegistrationSource(io::Printer* printer) { - // clang-format off printer->Print( "[registry addExtension:$root_class_and_method_name$];\n", "root_class_and_method_name", root_class_and_method_name_); - // clang-format on } } // namespace objectivec diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/extension.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h similarity index 97% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/extension.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h index cfdf718..d412f4a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/extension.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_EXTENSION_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_EXTENSION_H__ -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/field.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc similarity index 80% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/field.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc index 94663be..004ea19 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -28,18 +28,16 @@ // (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/compiler/objectivec/field.h" - #include -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/enum_field.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/map_field.h" -#include "google/protobuf/compiler/objectivec/message_field.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/compiler/objectivec/primitive_field.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -76,10 +74,9 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["raw_field_name"] = raw_field_name; (*variables)["field_number_name"] = classname + "_FieldNumber_" + capitalized_name; - (*variables)["field_number"] = absl::StrCat(descriptor->number()); + (*variables)["field_number"] = StrCat(descriptor->number()); (*variables)["field_type"] = GetCapitalizedType(descriptor); - (*variables)["deprecated_attribute"] = - GetOptionalDeprecatedAttribute(descriptor); + (*variables)["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor); std::vector field_flags; if (descriptor->is_repeated()) field_flags.push_back("GPBFieldRepeated"); if (descriptor->is_required()) field_flags.push_back("GPBFieldRequired"); @@ -110,59 +107,14 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, (*variables)["dataTypeSpecific_name"] = "clazz"; (*variables)["dataTypeSpecific_value"] = "Nil"; - (*variables)["storage_offset_value"] = "(uint32_t)offsetof(" + classname + - "__storage_, " + camel_case_name + ")"; + (*variables)["storage_offset_value"] = + "(uint32_t)offsetof(" + classname + "__storage_, " + camel_case_name + ")"; (*variables)["storage_offset_comment"] = ""; // Clear some common things so they can be set just when needed. (*variables)["storage_attribute"] = ""; } -bool HasNonZeroDefaultValue(const FieldDescriptor* field) { - // Repeated fields don't have defaults. - if (field->is_repeated()) { - return false; - } - - // As much as checking field->has_default_value() seems useful, it isn't - // because of enums. proto2 syntax allows the first item in an enum (the - // default) to be non zero. So checking field->has_default_value() would - // result in missing this non zero default. See MessageWithOneBasedEnum in - // objectivec/Tests/unittest_objc.proto for a test Message to confirm this. - - // Some proto file set the default to the zero value, so make sure the value - // isn't the zero case. - switch (field->cpp_type()) { - case FieldDescriptor::CPPTYPE_INT32: - return field->default_value_int32() != 0; - case FieldDescriptor::CPPTYPE_UINT32: - return field->default_value_uint32() != 0U; - case FieldDescriptor::CPPTYPE_INT64: - return field->default_value_int64() != 0LL; - case FieldDescriptor::CPPTYPE_UINT64: - return field->default_value_uint64() != 0ULL; - case FieldDescriptor::CPPTYPE_DOUBLE: - return field->default_value_double() != 0.0; - case FieldDescriptor::CPPTYPE_FLOAT: - return field->default_value_float() != 0.0f; - case FieldDescriptor::CPPTYPE_BOOL: - return field->default_value_bool(); - case FieldDescriptor::CPPTYPE_STRING: { - const std::string& default_string = field->default_value_string(); - return default_string.length() != 0; - } - case FieldDescriptor::CPPTYPE_ENUM: - return field->default_value_enum()->number() != 0; - case FieldDescriptor::CPPTYPE_MESSAGE: - return false; - } - - // Some compilers report reaching end of function even though all cases of - // the enum are handed in the switch. - GOOGLE_LOG(FATAL) << "Can't get here."; - return false; -} - } // namespace FieldGenerator* FieldGenerator::Make(const FieldDescriptor* field) { @@ -214,10 +166,13 @@ FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor) FieldGenerator::~FieldGenerator() {} void FieldGenerator::GenerateFieldNumberConstant(io::Printer* printer) const { - printer->Print(variables_, "$field_number_name$ = $field_number$,\n"); + printer->Print( + variables_, + "$field_number_name$ = $field_number$,\n"); } -void FieldGenerator::GenerateCFunctionDeclarations(io::Printer* printer) const { +void FieldGenerator::GenerateCFunctionDeclarations( + io::Printer* printer) const { // Nothing } @@ -227,7 +182,8 @@ void FieldGenerator::GenerateCFunctionImplementations( } void FieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { + std::set* fwd_decls, + bool include_external_types) const { // Nothing } @@ -236,11 +192,10 @@ void FieldGenerator::DetermineObjectiveCClassDefinitions( // Nothing } -void FieldGenerator::GenerateFieldDescription(io::Printer* printer, - bool include_default) const { +void FieldGenerator::GenerateFieldDescription( + io::Printer* printer, bool include_default) const { // Printed in the same order as the structure decl. if (include_default) { - // clang-format off printer->Print( variables_, "{\n" @@ -253,9 +208,7 @@ void FieldGenerator::GenerateFieldDescription(io::Printer* printer, " .core.flags = $fieldflags$,\n" " .core.dataType = GPBDataType$field_type$,\n" "},\n"); - // clang-format on } else { - // clang-format off printer->Print( variables_, "{\n" @@ -267,25 +220,25 @@ void FieldGenerator::GenerateFieldDescription(io::Printer* printer, " .flags = $fieldflags$,\n" " .dataType = GPBDataType$field_type$,\n" "},\n"); - // clang-format on } } void FieldGenerator::SetRuntimeHasBit(int has_index) { - variables_["has_index"] = absl::StrCat(has_index); + variables_["has_index"] = StrCat(has_index); } void FieldGenerator::SetNoHasBit(void) { variables_["has_index"] = "GPBNoHasBit"; } -int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { return 0; } +int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { + return 0; +} void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) { // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. - std::cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." - << std::endl; + std::cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << std::endl; std::cerr.flush(); abort(); } @@ -295,7 +248,7 @@ void FieldGenerator::SetOneofIndexBase(int index_base) { if (oneof != NULL) { int index = oneof->index() + index_base; // Flip the sign to mark it as a oneof. - variables_["has_index"] = absl::StrCat(-index); + variables_["has_index"] = StrCat(-index); } } @@ -326,18 +279,14 @@ void SingleFieldGenerator::GenerateFieldStorageDeclaration( void SingleFieldGenerator::GeneratePropertyDeclaration( io::Printer* printer) const { printer->Print(variables_, "$comments$"); - // clang-format off printer->Print( variables_, "@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;\n" "\n"); - // clang-format on if (WantsHasProperty()) { - // clang-format off printer->Print( variables_, "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n"); - // clang-format on } } @@ -375,30 +324,26 @@ void ObjCObjFieldGenerator::GenerateFieldStorageDeclaration( void ObjCObjFieldGenerator::GeneratePropertyDeclaration( io::Printer* printer) const { + // Differs from SingleFieldGenerator::GeneratePropertyDeclaration() in that // it uses pointers and deals with Objective C's rules around storage name // conventions (init*, new*, etc.) printer->Print(variables_, "$comments$"); - // clang-format off printer->Print( variables_, "@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n"); - // clang-format on if (WantsHasProperty()) { - // clang-format off printer->Print( variables_, "/** Test to see if @c $name$ has been set. */\n" "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n"); - // clang-format on } if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 printer->Print(variables_, - "- ($property_type$ *)$name$ " - "GPB_METHOD_FAMILY_NONE$deprecated_attribute$;\n"); + "- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$;\n"); } printer->Print("\n"); } @@ -431,28 +376,25 @@ void RepeatedFieldGenerator::GeneratePropertyImplementation( void RepeatedFieldGenerator::GeneratePropertyDeclaration( io::Printer* printer) const { + // Repeated fields don't need the has* properties, but they do expose a // *Count (to check without autocreation). So for the field property we need // the same logic as ObjCObjFieldGenerator::GeneratePropertyDeclaration() for // dealing with needing Objective C's rules around storage name conventions // (init*, new*, etc.) - // clang-format off printer->Print( variables_, "$comments$" "$array_comment$" "@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n" - "/** The number of items in @c $name$ without causing the container to be created. */\n" + "/** The number of items in @c $name$ without causing the array to be created. */\n" "@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;\n"); - // clang-format on if (IsInitName(variables_.find("name")->second)) { // If property name starts with init we need to annotate it to get past ARC. // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227 - // clang-format off printer->Print(variables_, "- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$;\n"); - // clang-format on } printer->Print("\n"); } @@ -467,7 +409,8 @@ FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor) extension_generators_(descriptor->extension_count()) { // Construct all the FieldGenerators. for (int i = 0; i < descriptor->field_count(); i++) { - field_generators_[i].reset(FieldGenerator::Make(descriptor->field(i))); + field_generators_[i].reset( + FieldGenerator::Make(descriptor->field(i))); } for (int i = 0; i < descriptor->extension_count(); i++) { extension_generators_[i].reset( diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/field.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h similarity index 88% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/field.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h index aae1188..759ef80 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/field.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h @@ -33,9 +33,8 @@ #include #include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { @@ -64,14 +63,15 @@ class FieldGenerator { virtual void GenerateCFunctionImplementations(io::Printer* printer) const; // Exposed for subclasses, should always call it on the parent class also. - virtual void DetermineForwardDeclarations(std::set* fwd_decls, - bool include_external_types) const; + virtual void DetermineForwardDeclarations( + std::set* fwd_decls, + bool include_external_types) const; virtual void DetermineObjectiveCClassDefinitions( std::set* fwd_decls) const; // Used during generation, not intended to be extended by subclasses. - void GenerateFieldDescription(io::Printer* printer, - bool include_default) const; + void GenerateFieldDescription( + io::Printer* printer, bool include_default) const; void GenerateFieldNumberConstant(io::Printer* printer) const; // Exposed to get and set the has bits information. @@ -111,12 +111,10 @@ class SingleFieldGenerator : public FieldGenerator { SingleFieldGenerator(const SingleFieldGenerator&) = delete; SingleFieldGenerator& operator=(const SingleFieldGenerator&) = delete; - virtual void GenerateFieldStorageDeclaration( - io::Printer* printer) const override; + virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override; virtual void GeneratePropertyDeclaration(io::Printer* printer) const override; - virtual void GeneratePropertyImplementation( - io::Printer* printer) const override; + virtual void GeneratePropertyImplementation(io::Printer* printer) const override; virtual bool RuntimeUsesHasBit(void) const override; @@ -132,8 +130,7 @@ class ObjCObjFieldGenerator : public SingleFieldGenerator { ObjCObjFieldGenerator(const ObjCObjFieldGenerator&) = delete; ObjCObjFieldGenerator& operator=(const ObjCObjFieldGenerator&) = delete; - virtual void GenerateFieldStorageDeclaration( - io::Printer* printer) const override; + virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override; virtual void GeneratePropertyDeclaration(io::Printer* printer) const override; protected: @@ -147,12 +144,10 @@ class RepeatedFieldGenerator : public ObjCObjFieldGenerator { RepeatedFieldGenerator(const RepeatedFieldGenerator&) = delete; RepeatedFieldGenerator& operator=(const RepeatedFieldGenerator&) = delete; - virtual void GenerateFieldStorageDeclaration( - io::Printer* printer) const override; + virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override; virtual void GeneratePropertyDeclaration(io::Printer* printer) const override; - virtual void GeneratePropertyImplementation( - io::Printer* printer) const override; + virtual void GeneratePropertyImplementation(io::Printer* printer) const override; virtual bool RuntimeUsesHasBit(void) const override; diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/file.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc similarity index 85% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/file.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc index 2fe4ccd..50b4285 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/file.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc @@ -28,22 +28,20 @@ // (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/compiler/objectivec/file.h" - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // std::find() #include #include -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/objectivec/enum.h" -#include "google/protobuf/compiler/objectivec/extension.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/import_writer.h" -#include "google/protobuf/compiler/objectivec/message.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" - // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some // error cases, so it seems to be ok to use as a back door for errors. @@ -137,7 +135,7 @@ struct FileDescriptorsOrderedByName { } // namespace -FileGenerator::CommonState::CommonState() {} +FileGenerator::CommonState::CommonState() { } const FileGenerator::CommonState::MinDepsEntry& FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( @@ -147,33 +145,29 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( return it->second; } - std::unordered_set min_deps_collector; - std::unordered_set covered_deps_collector; - std::unordered_set to_prune; + std::set min_deps_collector; + std::set covered_deps_collector; + std::set to_prune; for (int i = 0; i < file->dependency_count(); i++) { const FileDescriptor* dep = file->dependency(i); MinDepsEntry dep_info = CollectMinimalFileDepsContainingExtensionsInternal(dep); // Everything the dep covered, this file will also cover. - covered_deps_collector.insert(dep_info.covered_deps.begin(), - dep_info.covered_deps.end()); + covered_deps_collector.insert(dep_info.covered_deps.begin(), dep_info.covered_deps.end()); // Prune everything from the dep's covered list in case another dep lists it // as a min dep. to_prune.insert(dep_info.covered_deps.begin(), dep_info.covered_deps.end()); // Does the dep have any extensions... if (dep_info.has_extensions) { - // Yes -> Add this file, prune its min_deps and add them to the covered - // deps. + // Yes -> Add this file, prune its min_deps and add them to the covered deps. min_deps_collector.insert(dep); to_prune.insert(dep_info.min_deps.begin(), dep_info.min_deps.end()); - covered_deps_collector.insert(dep_info.min_deps.begin(), - dep_info.min_deps.end()); + covered_deps_collector.insert(dep_info.min_deps.begin(), dep_info.min_deps.end()); } else { // No -> Just use its min_deps. - min_deps_collector.insert(dep_info.min_deps.begin(), - dep_info.min_deps.end()); + min_deps_collector.insert(dep_info.min_deps.begin(), dep_info.min_deps.end()); } } @@ -182,25 +176,22 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( // Fast path: if nothing to prune or there was only one dep, the prune work is // a waste, skip it. if (to_prune.empty() || file->dependency_count() == 1) { - return deps_info_cache_ - .insert( - {file, {file_has_exts, min_deps_collector, covered_deps_collector}}) - .first->second; + return deps_info_cache_.insert( + {file, {file_has_exts, min_deps_collector, covered_deps_collector}}).first->second; } - std::unordered_set min_deps; + std::set min_deps; std::copy_if(min_deps_collector.begin(), min_deps_collector.end(), std::inserter(min_deps, min_deps.end()), - [&](const FileDescriptor* value) { - return to_prune.find(value) == to_prune.end(); - }); - return deps_info_cache_ - .insert({file, {file_has_exts, min_deps, covered_deps_collector}}) - .first->second; + [&](const FileDescriptor* value){ + return to_prune.find(value) == to_prune.end(); + }); + return deps_info_cache_.insert( + {file, {file_has_exts, min_deps, covered_deps_collector}}).first->second; } -// Collect the deps of the given file that contain extensions. This can be used -// to create the chain of roots that need to be wired together. +// Collect the deps of the given file that contain extensions. This can be used to +// create the chain of roots that need to be wired together. // // NOTE: If any changes are made to this and the supporting functions, you will // need to manually validate what the generated code is for the test files: @@ -211,8 +202,8 @@ FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensionsInternal( const std::vector FileGenerator::CommonState::CollectMinimalFileDepsContainingExtensions( const FileDescriptor* file) { - std::unordered_set min_deps = - CollectMinimalFileDepsContainingExtensionsInternal(file).min_deps; + std::set min_deps = + CollectMinimalFileDepsContainingExtensionsInternal(file).min_deps; // Sort the list since pointer order isn't stable across runs. std::vector result(min_deps.begin(), min_deps.end()); std::sort(result.begin(), result.end(), FileDescriptorsOrderedByName()); @@ -268,7 +259,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // compiled, since that will be the versions for the ObjC runtime at that // time. The constants in the generated code will then get their values at // at compile time (so checking against the headers being used to compile). - // clang-format off printer->Print( "#if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$\n" "#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.\n" @@ -277,13 +267,11 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.\n" "#endif\n" "\n", - "google_protobuf_objc_version", absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); - // clang-format on + "google_protobuf_objc_version", StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); // The bundled protos (WKTs) don't use of forward declarations. bool headers_use_forward_declarations = - generation_options_.headers_use_forward_declarations && - !is_bundled_proto_; + generation_options_.headers_use_forward_declarations && !is_bundled_proto_; { ImportWriter import_writer( @@ -309,7 +297,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // deprecated-declarations suppression is only needed if some place in this // proto file is something deprecated or if it references something from // another file that is deprecated. - // clang-format off printer->Print( "// @@protoc_insertion_point(imports)\n" "\n" @@ -318,7 +305,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "\n" "CF_EXTERN_C_BEGIN\n" "\n"); - // clang-format on std::set fwd_decls; for (const auto& generator : message_generators_) { @@ -350,7 +336,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // For extensions to chain together, the Root gets created even if there // are no extensions. printer->Print( - // clang-format off "#pragma mark - $root_class_name$\n" "\n" "/**\n" @@ -366,7 +351,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "GPB_FINAL @interface $root_class_name$ : GPBRootObject\n" "@end\n" "\n", - // clang-format off "root_class_name", root_class_name_); if (!extension_generators_.empty()) { @@ -386,7 +370,6 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { generator->GenerateMessageHeader(printer); } - // clang-format off printer->Print( "NS_ASSUME_NONNULL_END\n" "\n" @@ -394,10 +377,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "\n" "#pragma clang diagnostic pop\n" "\n" - "// @@protoc_insertion_point(global_scope)\n" - "\n" - "// clange-format on\n"); - // clang-format on + "// @@protoc_insertion_point(global_scope)\n"); } void FileGenerator::GenerateSource(io::Printer* printer) { @@ -417,12 +397,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) { } std::vector deps_with_extensions = - common_state_.CollectMinimalFileDepsContainingExtensions(file_); + common_state_.CollectMinimalFileDepsContainingExtensions(file_); // The bundled protos (WKTs) don't use of forward declarations. bool headers_use_forward_declarations = - generation_options_.headers_use_forward_declarations && - !is_bundled_proto_; + generation_options_.headers_use_forward_declarations && !is_bundled_proto_; { ImportWriter import_writer( @@ -443,7 +422,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { public_import_names.insert(file_->public_dependency(i)->name()); } for (int i = 0; i < file_->dependency_count(); i++) { - const FileDescriptor* dep = file_->dependency(i); + const FileDescriptor *dep = file_->dependency(i); bool public_import = (public_import_names.count(dep->name()) != 0); if (!public_import) { import_writer.AddFile(dep, header_extension); @@ -488,13 +467,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // another file that is deprecated. // dollar-in-identifier-extension is needed because we use references to // objc class names that have $ in identifiers. - // clang-format off printer->Print( "// @@protoc_insertion_point(imports)\n" "\n" "#pragma clang diagnostic push\n" "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"); - // clang-format on if (includes_oneof) { // The generated code for oneof's uses direct ivar access, suppress the // warning in case developer turn that on in the context they compile the @@ -503,20 +480,17 @@ void FileGenerator::GenerateSource(io::Printer* printer) { "#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n"); } if (!fwd_decls.empty()) { - // clang-format off printer->Print( - "#pragma clang diagnostic ignored \"-Wdollar-in-identifier-extension\"\n"); - // clang-format on + "#pragma clang diagnostic ignored \"-Wdollar-in-identifier-extension\"\n"); } - printer->Print("\n"); + printer->Print( + "\n"); if (!fwd_decls.empty()) { - // clang-format off printer->Print( "#pragma mark - Objective C Class declarations\n" "// Forward declarations of Objective C classes that we can use as\n" "// static values in struct initializers.\n" "// We don't use [Foo class] because it is not a static value.\n"); - // clang-format on } for (const auto& i : fwd_decls) { printer->Print("$value$\n", "value", i); @@ -525,11 +499,9 @@ void FileGenerator::GenerateSource(io::Printer* printer) { printer->Print("\n"); } printer->Print( - // clang-format off "#pragma mark - $root_class_name$\n" "\n" "@implementation $root_class_name$\n\n", - // clang-format on "root_class_name", root_class_name_); const bool file_contains_extensions = FileContainsExtensions(file_); @@ -537,7 +509,6 @@ void FileGenerator::GenerateSource(io::Printer* printer) { // If there were any extensions or this file has any dependencies, output // a registry to override to create the file specific registry. if (file_contains_extensions || !deps_with_extensions.empty()) { - // clang-format off printer->Print( "+ (GPBExtensionRegistry*)extensionRegistry {\n" " // This is called by +initialize so there is no need to worry\n" @@ -546,13 +517,13 @@ void FileGenerator::GenerateSource(io::Printer* printer) { " if (!registry) {\n" " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n" " registry = [[GPBExtensionRegistry alloc] init];\n"); - // clang-format on printer->Indent(); printer->Indent(); if (file_contains_extensions) { - printer->Print("static GPBExtensionDescription descriptions[] = {\n"); + printer->Print( + "static GPBExtensionDescription descriptions[] = {\n"); printer->Indent(); for (const auto& generator : extension_generators_) { generator->GenerateStaticVariablesInitialization(printer); @@ -561,7 +532,6 @@ void FileGenerator::GenerateSource(io::Printer* printer) { generator->GenerateStaticVariablesInitialization(printer); } printer->Outdent(); - // clang-format off printer->Print( "};\n" "for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {\n" @@ -572,20 +542,15 @@ void FileGenerator::GenerateSource(io::Printer* printer) { " [self globallyRegisterExtension:extension];\n" " [extension release];\n" "}\n"); - // clang-format on } if (deps_with_extensions.empty()) { - // clang-format off printer->Print( "// None of the imports (direct or indirect) defined extensions, so no need to add\n" "// them to this registry.\n"); - // clang-format on } else { - // clang-format off printer->Print( "// Merge in the imports (direct or indirect) that defined extensions.\n"); - // clang-format on for (std::vector::iterator iter = deps_with_extensions.begin(); iter != deps_with_extensions.end(); ++iter) { @@ -599,25 +564,19 @@ void FileGenerator::GenerateSource(io::Printer* printer) { printer->Outdent(); printer->Outdent(); - // clang-format off printer->Print( " }\n" " return registry;\n" "}\n"); - // clang-format on } else { if (file_->dependency_count() > 0) { - // clang-format off printer->Print( "// No extensions in the file and none of the imports (direct or indirect)\n" "// defined extensions, so no need to generate +extensionRegistry.\n"); - // clang-format on } else { - // clang-format off printer->Print( "// No extensions in the file and no imports, so no need to generate\n" "// +extensionRegistry.\n"); - // clang-format on } } @@ -640,9 +599,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { vars["syntax"] = "GPBFileSyntaxProto3"; break; } - // clang-format off - printer->Print( - vars, + printer->Print(vars, "#pragma mark - $root_class_name$_FileDescriptor\n" "\n" "static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {\n" @@ -651,30 +608,23 @@ void FileGenerator::GenerateSource(io::Printer* printer) { " static GPBFileDescriptor *descriptor = NULL;\n" " if (!descriptor) {\n" " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"); - // clang-format on if (!vars["objc_prefix"].empty()) { - // clang-format off printer->Print( vars, " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" " objcPrefix:@\"$objc_prefix$\"\n" " syntax:$syntax$];\n"); - // clang-format on } else { - // clang-format off printer->Print( vars, " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" " syntax:$syntax$];\n"); - // clang-format on } - // clang-format off printer->Print( " }\n" " return descriptor;\n" "}\n" "\n"); - // clang-format on } for (const auto& generator : enum_generators_) { @@ -684,15 +634,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) { generator->GenerateSource(printer); } - // clang-format off printer->Print( - "\n" - "#pragma clang diagnostic pop\n" - "\n" - "// @@protoc_insertion_point(global_scope)\n" - "\n" - "// clang-format on\n"); - // clang-format on + "\n" + "#pragma clang diagnostic pop\n" + "\n" + "// @@protoc_insertion_point(global_scope)\n"); } // Helper to print the import of the runtime support at the top of generated @@ -703,7 +649,6 @@ void FileGenerator::PrintFileRuntimePreamble( const std::vector& headers_to_import) const { printer->Print( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" - "// clang-format off\n" "// source: $filename$\n" "\n", "filename", file_->name()); @@ -717,13 +662,14 @@ void FileGenerator::PrintFileRuntimePreamble( import_prefix += "/"; } for (const auto& header : headers_to_import) { - printer->Print("#import \"$import_prefix$$header$\"\n", "import_prefix", - import_prefix, "header", header); + printer->Print( + "#import \"$import_prefix$$header$\"\n", + "import_prefix", import_prefix, + "header", header); } } else { - ImportWriter::PrintRuntimeImports(printer, headers_to_import, - generation_options_.runtime_import_prefix, - true); + ImportWriter::PrintRuntimeImports( + printer, headers_to_import, generation_options_.runtime_import_prefix, true); } printer->Print("\n"); diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/file.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h similarity index 82% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/file.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h index 21404ba..ef49cf8 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/file.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h @@ -31,14 +31,12 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FILE_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FILE_H__ +#include +#include #include -#include -#include #include - -#include "google/protobuf/compiler/objectivec/options.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { @@ -51,6 +49,17 @@ class MessageGenerator; class FileGenerator { public: + struct GenerationOptions { + GenerationOptions() + // TODO(thomasvl): Eventually flip this default to false for better + // interop with Swift if proto usages span modules made from ObjC sources. + : headers_use_forward_declarations(true) {} + std::string generate_for_named_framework; + std::string named_framework_to_proto_path_mappings_path; + std::string runtime_import_prefix; + bool headers_use_forward_declarations; + }; + // Wrapper for some common state that is shared between file generations to // improve performance when more than one file is generated at a time. struct CommonState { @@ -62,14 +71,13 @@ class FileGenerator { private: struct MinDepsEntry { bool has_extensions; - std::unordered_set min_deps; + std::set min_deps; // `covered_deps` are the transtive deps of `min_deps_w_exts` that also // have extensions. - std::unordered_set covered_deps; + std::set covered_deps; }; - const MinDepsEntry& CollectMinimalFileDepsContainingExtensionsInternal( - const FileDescriptor* file); - std::unordered_map deps_info_cache_; + const MinDepsEntry& CollectMinimalFileDepsContainingExtensionsInternal(const FileDescriptor* file); + std::map deps_info_cache_; }; FileGenerator(const FileDescriptor* file, diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/generator.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc similarity index 88% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/generator.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc index 1b96368..9dccf14 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc @@ -28,21 +28,16 @@ // (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/compiler/objectivec/generator.h" - #include #include #include #include - -#include "absl/strings/ascii.h" -#include "absl/strings/str_split.h" -#include "absl/strings/strip.h" -#include "google/protobuf/compiler/objectivec/file.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -56,7 +51,7 @@ namespace { // invalid, `result` is unchanged. bool StringToBool(const std::string& value, bool* result) { std::string upper_value(value); - absl::AsciiStrToUpper(&upper_value); + UpperString(&upper_value); if (upper_value == "NO") { *result = false; return true; @@ -75,7 +70,9 @@ ObjectiveCGenerator::ObjectiveCGenerator() {} ObjectiveCGenerator::~ObjectiveCGenerator() {} -bool ObjectiveCGenerator::HasGenerateAll() const { return true; } +bool ObjectiveCGenerator::HasGenerateAll() const { + return true; +} bool ObjectiveCGenerator::Generate(const FileDescriptor* file, const std::string& parameter, @@ -95,15 +92,14 @@ bool ObjectiveCGenerator::GenerateAll( // options along with their values. If the option appears multiple times, only // the last value will be considered. // - // e.g. protoc ... - // --objc_opt=expected_prefixes=file.txt,generate_for_named_framework=MyFramework + // e.g. protoc ... --objc_opt=expected_prefixes=file.txt,generate_for_named_framework=MyFramework Options validation_options; - GenerationOptions generation_options; + FileGenerator::GenerationOptions generation_options; std::vector > options; ParseGeneratorParameter(parameter, &options); - for (size_t i = 0; i < options.size(); i++) { + for (int i = 0; i < options.size(); i++) { if (options[i].first == "expected_prefixes_path") { // Path to find a file containing the expected prefixes // (objc_class_prefix "PREFIX") for proto packages (package NAME). The @@ -126,8 +122,8 @@ bool ObjectiveCGenerator::GenerateAll( // A semicolon delimited string that lists the paths of .proto files to // exclude from the package prefix validations (expected_prefixes_path). // This is provided as an "out", to skip some files being checked. - for (absl::string_view split_piece : - absl::StrSplit(options[i].second, ";", absl::SkipEmpty())) { + for (StringPiece split_piece : Split( + options[i].second, ";", true)) { validation_options.expected_prefixes_suppressions.push_back( std::string(split_piece)); } @@ -141,8 +137,7 @@ bool ObjectiveCGenerator::GenerateAll( // Default is "no". if (!StringToBool(options[i].second, &validation_options.prefixes_must_be_registered)) { - *error = "error: Unknown value for prefixes_must_be_registered: " + - options[i].second; + *error = "error: Unknown value for prefixes_must_be_registered: " + options[i].second; return false; } } else if (options[i].first == "require_prefixes") { @@ -154,8 +149,7 @@ bool ObjectiveCGenerator::GenerateAll( // Default is "no". if (!StringToBool(options[i].second, &validation_options.require_prefixes)) { - *error = - "error: Unknown value for require_prefixes: " + options[i].second; + *error = "error: Unknown value for require_prefixes: " + options[i].second; return false; } } else if (options[i].first == "generate_for_named_framework") { @@ -168,8 +162,7 @@ bool ObjectiveCGenerator::GenerateAll( // the "default" framework name used for everything that wasn't mapped by // the mapping file. generation_options.generate_for_named_framework = options[i].second; - } else if (options[i].first == - "named_framework_to_proto_path_mappings_path") { + } else if (options[i].first == "named_framework_to_proto_path_mappings_path") { // Path to find a file containing the list of framework names and proto // files. The generator uses this to decide if a proto file // referenced should use a framework style import vs. a user level import @@ -190,20 +183,17 @@ bool ObjectiveCGenerator::GenerateAll( // mappings file, it will use the default framework name if one was passed // with generate_for_named_framework, or the relative path to it's include // path otherwise. - generation_options.named_framework_to_proto_path_mappings_path = - options[i].second; + generation_options.named_framework_to_proto_path_mappings_path = options[i].second; } else if (options[i].first == "runtime_import_prefix") { // Path to use as a prefix on #imports of runtime provided headers in the // generated files. When integrating ObjC protos into a build system, // this can be used to avoid having to add the runtime directory to the // header search path since the generate #import will be more complete. - generation_options.runtime_import_prefix = - std::string(absl::StripSuffix(options[i].second, "/")); + generation_options.runtime_import_prefix = StripSuffixString(options[i].second, "/"); } else if (options[i].first == "package_to_prefix_mappings_path") { // Path to use for when loading the objc class prefix mappings to use. - // The `objc_class_prefix` file option is always honored first if one is - // present. This option also has precedent over the use_package_as_prefix - // option. + // The `objc_class_prefix` file option is always honored first if one is present. + // This option also has precedent over the use_package_as_prefix option. // // The format of the file is: // - An entry is a line of "package=prefix". @@ -240,15 +230,10 @@ bool ObjectiveCGenerator::GenerateAll( // - A comment can go on a line after a expected package/prefix pair. // (i.e. - "some.proto.package # comment") SetProtoPackagePrefixExceptionList(options[i].second); - } else if (options[i].first == "package_as_prefix_forced_prefix") { - // String to use as the prefix when deriving a prefix from the package - // name. So this only applies when use_package_as_prefix is also used. - SetForcedPackagePrefix(options[i].second); } else if (options[i].first == "headers_use_forward_declarations") { if (!StringToBool(options[i].second, &generation_options.headers_use_forward_declarations)) { - *error = "error: Unknown value for headers_use_forward_declarations: " + - options[i].second; + *error = "error: Unknown value for headers_use_forward_declarations: " + options[i].second; return false; } } else { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/generator.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h similarity index 94% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/generator.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h index 7de5b41..1dbc666 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h @@ -34,12 +34,10 @@ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ #include +#include +#include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" - -// Must be included last -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -76,6 +74,6 @@ class PROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc new file mode 100644 index 0000000..b15f580 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc @@ -0,0 +1,2043 @@ +// 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 _MSC_VER +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some +// error cases, so it seems to be ok to use as a back door for errors. + +namespace google { +namespace protobuf { +namespace compiler { +namespace objectivec { + +// is transitively included in this file. Import the functions explicitly +// in this port namespace to avoid ambiguous definition. +namespace posix { +#ifdef _WIN32 +using ::google::protobuf::io::win32::open; +#else +using ::open; +#endif +} // namespace port + +namespace { + +bool BoolFromEnvVar(const char* env_var, bool default_value) { + const char* value = getenv(env_var); + if (value) { + return std::string("YES") == ToUpper(value); + } + return default_value; +} + +class SimpleLineCollector : public LineConsumer { + public: + SimpleLineCollector(std::unordered_set* inout_set) + : set_(inout_set) {} + + virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override { + set_->insert(std::string(line)); + return true; + } + + private: + std::unordered_set* set_; +}; + +class PackageToPrefixesCollector : public LineConsumer { + public: + PackageToPrefixesCollector(const std::string &usage, + std::map* inout_package_to_prefix_map) + : usage_(usage), prefix_map_(inout_package_to_prefix_map) {} + + virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override; + + private: + const std::string usage_; + std::map* prefix_map_; +}; + +class PrefixModeStorage { + public: + PrefixModeStorage(); + + const std::string package_to_prefix_mappings_path() const { return package_to_prefix_mappings_path_; } + void set_package_to_prefix_mappings_path(const std::string& path) { + package_to_prefix_mappings_path_ = path; + package_to_prefix_map_.clear(); + } + + std::string prefix_from_proto_package_mappings(const FileDescriptor* file); + + bool use_package_name() const { return use_package_name_; } + void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; } + + const std::string exception_path() const { return exception_path_; } + void set_exception_path(const std::string& path) { + exception_path_ = path; + exceptions_.clear(); + } + + bool is_package_exempted(const std::string& package); + + // When using a proto package as the prefix, this should be added as the + // prefix in front of it. + const std::string& forced_package_prefix() const { return forced_prefix_; } + + private: + bool use_package_name_; + std::map package_to_prefix_map_; + std::string package_to_prefix_mappings_path_; + std::string exception_path_; + std::string forced_prefix_; + std::unordered_set exceptions_; +}; + +PrefixModeStorage::PrefixModeStorage() { + // Even thought there are generation options, have an env back door since some + // of these helpers could be used in other plugins. + + use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false); + + const char* exception_path = getenv("GPB_OBJC_PACKAGE_PREFIX_EXCEPTIONS_PATH"); + if (exception_path) { + exception_path_ = exception_path; + } + + // This one is a not expected to be common, so it doesn't get a generation + // option, just the env var. + const char* prefix = getenv("GPB_OBJC_USE_PACKAGE_AS_PREFIX_PREFIX"); + if (prefix) { + forced_prefix_ = prefix; + } +} + +std::string PrefixModeStorage::prefix_from_proto_package_mappings(const FileDescriptor* file) { + if (!file) { + return ""; + } + + if (package_to_prefix_map_.empty() && !package_to_prefix_mappings_path_.empty()) { + std::string error_str; + // Re use the same collector as we use for expected_prefixes_path since the file + // format is the same. + PackageToPrefixesCollector collector("Package to prefixes", &package_to_prefix_map_); + if (!ParseSimpleFile(package_to_prefix_mappings_path_, &collector, &error_str)) { + if (error_str.empty()) { + error_str = std::string("protoc:0: warning: Failed to parse") + + std::string(" prefix to proto package mappings file: ") + + package_to_prefix_mappings_path_; + } + std::cerr << error_str << std::endl; + std::cerr.flush(); + package_to_prefix_map_.clear(); + } + } + + const std::string package = file->package(); + // For files without packages, the can be registered as "no_package:PATH", + // allowing the expected prefixes file. + static const std::string no_package_prefix("no_package:"); + const std::string lookup_key = package.empty() ? no_package_prefix + file->name() : package; + + std::map::const_iterator prefix_lookup = + package_to_prefix_map_.find(lookup_key); + + if (prefix_lookup != package_to_prefix_map_.end()) { + return prefix_lookup->second; + } + + return ""; +} + +bool PrefixModeStorage::is_package_exempted(const std::string& package) { + if (exceptions_.empty() && !exception_path_.empty()) { + std::string error_str; + SimpleLineCollector collector(&exceptions_); + if (!ParseSimpleFile(exception_path_, &collector, &error_str)) { + if (error_str.empty()) { + error_str = std::string("protoc:0: warning: Failed to parse") + + std::string(" package prefix exceptions file: ") + + exception_path_; + } + std::cerr << error_str << std::endl; + std::cerr.flush(); + exceptions_.clear(); + } + + // If the file was empty put something in it so it doesn't get reloaded over + // and over. + if (exceptions_.empty()) { + exceptions_.insert(""); + } + } + + return exceptions_.count(package) != 0; +} + +PrefixModeStorage g_prefix_mode; + +} // namespace + +std::string GetPackageToPrefixMappingsPath() { + return g_prefix_mode.package_to_prefix_mappings_path(); +} + +void SetPackageToPrefixMappingsPath(const std::string& file_path) { + g_prefix_mode.set_package_to_prefix_mappings_path(file_path); +} + +bool UseProtoPackageAsDefaultPrefix() { + return g_prefix_mode.use_package_name(); +} + +void SetUseProtoPackageAsDefaultPrefix(bool on_or_off) { + g_prefix_mode.set_use_package_name(on_or_off); +} + +std::string GetProtoPackagePrefixExceptionList() { + return g_prefix_mode.exception_path(); +} + +void SetProtoPackagePrefixExceptionList(const std::string& file_path) { + g_prefix_mode.set_exception_path(file_path); +} + +Options::Options() { + // While there are generator options, also support env variables to help with + // build systems where it isn't as easy to hook in for add the generation + // options when invoking protoc. + const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES"); + if (file_path) { + expected_prefixes_path = file_path; + } + const char* suppressions = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES_SUPPRESSIONS"); + if (suppressions) { + expected_prefixes_suppressions = + Split(suppressions, ";", true); + } + prefixes_must_be_registered = + BoolFromEnvVar("GPB_OBJC_PREFIXES_MUST_BE_REGISTERED", false); + require_prefixes = BoolFromEnvVar("GPB_OBJC_REQUIRE_PREFIXES", false); +} + +namespace { + +std::unordered_set MakeWordsMap(const char* const words[], + size_t num_words) { + std::unordered_set result; + for (int i = 0; i < num_words; i++) { + result.insert(words[i]); + } + return result; +} + +const char* const kUpperSegmentsList[] = {"url", "http", "https"}; + +std::unordered_set kUpperSegments = + MakeWordsMap(kUpperSegmentsList, GOOGLE_ARRAYSIZE(kUpperSegmentsList)); + +bool ascii_isnewline(char c) { + return c == '\n' || c == '\r'; +} + +// Internal helper for name handing. +// Do not expose this outside of helpers, stick to having functions for specific +// cases (ClassName(), FieldName()), so there is always consistent suffix rules. +std::string UnderscoresToCamelCase(const std::string& input, + bool first_capitalized) { + std::vector values; + std::string current; + + bool last_char_was_number = false; + bool last_char_was_lower = false; + bool last_char_was_upper = false; + for (int i = 0; i < input.size(); i++) { + char c = input[i]; + if (ascii_isdigit(c)) { + if (!last_char_was_number) { + values.push_back(current); + current = ""; + } + current += c; + last_char_was_number = last_char_was_lower = last_char_was_upper = false; + last_char_was_number = true; + } else if (ascii_islower(c)) { + // lowercase letter can follow a lowercase or uppercase letter + if (!last_char_was_lower && !last_char_was_upper) { + values.push_back(current); + current = ""; + } + current += c; // already lower + last_char_was_number = last_char_was_lower = last_char_was_upper = false; + last_char_was_lower = true; + } else if (ascii_isupper(c)) { + if (!last_char_was_upper) { + values.push_back(current); + current = ""; + } + current += ascii_tolower(c); + last_char_was_number = last_char_was_lower = last_char_was_upper = false; + last_char_was_upper = true; + } else { + last_char_was_number = last_char_was_lower = last_char_was_upper = false; + } + } + values.push_back(current); + + std::string result; + bool first_segment_forces_upper = false; + for (std::vector::iterator i = values.begin(); i != values.end(); + ++i) { + std::string value = *i; + bool all_upper = (kUpperSegments.count(value) > 0); + if (all_upper && (result.length() == 0)) { + first_segment_forces_upper = true; + } + for (int j = 0; j < value.length(); j++) { + if (j == 0 || all_upper) { + value[j] = ascii_toupper(value[j]); + } else { + // Nothing, already in lower. + } + } + result += value; + } + if ((result.length() != 0) && + !first_capitalized && + !first_segment_forces_upper) { + result[0] = ascii_tolower(result[0]); + } + return result; +} + +const char* const kReservedWordList[] = { + // Note NSObject Methods: + // These are brought in from objectivec_nsobject_methods.h that is generated + // using method_dump.sh. See kNSObjectMethods below. + + // Objective C "keywords" that aren't in C + // From + // http://stackoverflow.com/questions/1873630/reserved-keywords-in-objective-c + // with some others added on. + "id", "_cmd", "super", "in", "out", "inout", "bycopy", "byref", "oneway", + "self", "instancetype", "nullable", "nonnull", "nil", "Nil", + "YES", "NO", "weak", + + // C/C++ keywords (Incl C++ 0x11) + // From http://en.cppreference.com/w/cpp/keywords + "and", "and_eq", "alignas", "alignof", "asm", "auto", "bitand", "bitor", + "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "class", + "compl", "const", "constexpr", "const_cast", "continue", "decltype", + "default", "delete", "double", "dynamic_cast", "else", "enum", "explicit", + "export", "extern ", "false", "float", "for", "friend", "goto", "if", + "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", + "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", + "public", "register", "reinterpret_cast", "return", "short", "signed", + "sizeof", "static", "static_assert", "static_cast", "struct", "switch", + "template", "this", "thread_local", "throw", "true", "try", "typedef", + "typeid", "typename", "union", "unsigned", "using", "virtual", "void", + "volatile", "wchar_t", "while", "xor", "xor_eq", + + // C99 keywords + // From + // http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fkeyw.htm + "restrict", + + // GCC/Clang extension + "typeof", + + // Not a keyword, but will break you + "NULL", + + // C88+ specs call for these to be macros, so depending on what they are + // defined to be it can lead to odd errors for some Xcode/SDK versions. + "stdin", "stdout", "stderr", + + // Objective-C Runtime typedefs + // From + "Category", "Ivar", "Method", "Protocol", + + // GPBMessage Methods + // Only need to add instance methods that may conflict with + // method declared in protos. The main cases are methods + // that take no arguments, or setFoo:/hasFoo: type methods. + "clear", "data", "delimitedData", "descriptor", "extensionRegistry", + "extensionsCurrentlySet", "initialized", "isInitialized", "serializedSize", + "sortedExtensionsInUse", "unknownFields", + + // MacTypes.h names + "Fixed", "Fract", "Size", "LogicalAddress", "PhysicalAddress", "ByteCount", + "ByteOffset", "Duration", "AbsoluteTime", "OptionBits", "ItemCount", + "PBVersion", "ScriptCode", "LangCode", "RegionCode", "OSType", + "ProcessSerialNumber", "Point", "Rect", "FixedPoint", "FixedRect", "Style", + "StyleParameter", "StyleField", "TimeScale", "TimeBase", "TimeRecord", +}; + +// returns true is input starts with __ or _[A-Z] which are reserved identifiers +// in C/ C++. All calls should go through UnderscoresToCamelCase before getting here +// but this verifies and allows for future expansion if we decide to redefine what a +// reserved C identifier is (for example the GNU list +// https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html ) +bool IsReservedCIdentifier(const std::string& input) { + if (input.length() > 2) { + if (input.at(0) == '_') { + if (isupper(input.at(1)) || input.at(1) == '_') { + return true; + } + } + } + return false; +} + +std::string SanitizeNameForObjC(const std::string& prefix, + const std::string& input, + const std::string& extension, + std::string* out_suffix_added) { + static const std::unordered_set kReservedWords = + MakeWordsMap(kReservedWordList, GOOGLE_ARRAYSIZE(kReservedWordList)); + static const std::unordered_set kNSObjectMethods = + MakeWordsMap(kNSObjectMethodsList, GOOGLE_ARRAYSIZE(kNSObjectMethodsList)); + std::string sanitized; + // We add the prefix in the cases where the string is missing a prefix. + // We define "missing a prefix" as where 'input': + // a) Doesn't start with the prefix or + // b) Isn't equivalent to the prefix or + // c) Has the prefix, but the letter after the prefix is lowercase + if (HasPrefixString(input, prefix)) { + if (input.length() == prefix.length() || !ascii_isupper(input[prefix.length()])) { + sanitized = prefix + input; + } else { + sanitized = input; + } + } else { + sanitized = prefix + input; + } + if (IsReservedCIdentifier(sanitized) || + (kReservedWords.count(sanitized) > 0) || + (kNSObjectMethods.count(sanitized) > 0)) { + if (out_suffix_added) *out_suffix_added = extension; + return sanitized + extension; + } + if (out_suffix_added) out_suffix_added->clear(); + return sanitized; +} + +std::string NameFromFieldDescriptor(const FieldDescriptor* field) { + if (field->type() == FieldDescriptor::TYPE_GROUP) { + return field->message_type()->name(); + } else { + return field->name(); + } +} + +void PathSplit(const std::string& path, std::string* directory, + std::string* basename) { + std::string::size_type last_slash = path.rfind('/'); + if (last_slash == std::string::npos) { + if (directory) { + *directory = ""; + } + if (basename) { + *basename = path; + } + } else { + if (directory) { + *directory = path.substr(0, last_slash); + } + if (basename) { + *basename = path.substr(last_slash + 1); + } + } +} + +bool IsSpecialName(const std::string& name, const std::string* special_names, + size_t count) { + for (size_t i = 0; i < count; ++i) { + size_t length = special_names[i].length(); + if (name.compare(0, length, special_names[i]) == 0) { + if (name.length() > length) { + // If name is longer than the retained_name[i] that it matches + // the next character must be not lower case (newton vs newTon vs + // new_ton). + return !ascii_islower(name[length]); + } else { + return true; + } + } + } + return false; +} + +std::string GetZeroEnumNameForFlagType(const FlagType flag_type) { + switch(flag_type) { + case FLAGTYPE_DESCRIPTOR_INITIALIZATION: + return "GPBDescriptorInitializationFlag_None"; + case FLAGTYPE_EXTENSION: + return "GPBExtensionNone"; + case FLAGTYPE_FIELD: + return "GPBFieldNone"; + default: + GOOGLE_LOG(FATAL) << "Can't get here."; + return "0"; + } +} + +std::string GetEnumNameForFlagType(const FlagType flag_type) { + switch(flag_type) { + case FLAGTYPE_DESCRIPTOR_INITIALIZATION: + return "GPBDescriptorInitializationFlags"; + case FLAGTYPE_EXTENSION: + return "GPBExtensionOptions"; + case FLAGTYPE_FIELD: + return "GPBFieldFlags"; + default: + GOOGLE_LOG(FATAL) << "Can't get here."; + return std::string(); + } +} + +void MaybeUnQuote(StringPiece* input) { + if ((input->length() >= 2) && + ((*input->data() == '\'' || *input->data() == '"')) && + ((*input)[input->length() - 1] == *input->data())) { + input->remove_prefix(1); + input->remove_suffix(1); + } +} + +} // namespace + +// Escape C++ trigraphs by escaping question marks to \? +std::string EscapeTrigraphs(const std::string& to_escape) { + return StringReplace(to_escape, "?", "\\?", true); +} + +void TrimWhitespace(StringPiece* input) { + while (!input->empty() && ascii_isspace(*input->data())) { + input->remove_prefix(1); + } + while (!input->empty() && ascii_isspace((*input)[input->length() - 1])) { + input->remove_suffix(1); + } +} + +bool IsRetainedName(const std::string& name) { + // List of prefixes from + // http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html + static const std::string retained_names[] = {"new", "alloc", "copy", + "mutableCopy"}; + return IsSpecialName(name, retained_names, + sizeof(retained_names) / sizeof(retained_names[0])); +} + +bool IsInitName(const std::string& name) { + static const std::string init_names[] = {"init"}; + return IsSpecialName(name, init_names, + sizeof(init_names) / sizeof(init_names[0])); +} + +std::string BaseFileName(const FileDescriptor* file) { + std::string basename; + PathSplit(file->name(), NULL, &basename); + return basename; +} + +std::string FileClassPrefix(const FileDescriptor* file) { + // Always honor the file option. + if (file->options().has_objc_class_prefix()) { + return file->options().objc_class_prefix(); + } + + // If package prefix is specified in an prefix to proto mappings file then use that. + std::string objc_class_prefix = g_prefix_mode.prefix_from_proto_package_mappings(file); + if (!objc_class_prefix.empty()) { + return objc_class_prefix; + } + + // If package prefix isn't enabled, done. + if (!g_prefix_mode.use_package_name()) { + return ""; + } + + // If the package is in the exceptions list, done. + if (g_prefix_mode.is_package_exempted(file->package())) { + return ""; + } + + // Transform the package into a prefix: use the dot segments as part, + // camelcase each one and then join them with underscores, and add an + // underscore at the end. + std::string result; + const std::vector segments = Split(file->package(), ".", true); + for (const auto& segment : segments) { + const std::string part = UnderscoresToCamelCase(segment, true); + if (part.empty()) { + continue; + } + if (!result.empty()) { + result.append("_"); + } + result.append(part); + } + if (!result.empty()) { + result.append("_"); + } + return g_prefix_mode.forced_package_prefix() + result; +} + +std::string FilePath(const FileDescriptor* file) { + std::string output; + std::string basename; + std::string directory; + PathSplit(file->name(), &directory, &basename); + if (directory.length() > 0) { + output = directory + "/"; + } + basename = StripProto(basename); + + // CamelCase to be more ObjC friendly. + basename = UnderscoresToCamelCase(basename, true); + + output += basename; + return output; +} + +std::string FilePathBasename(const FileDescriptor* file) { + std::string output; + std::string basename; + std::string directory; + PathSplit(file->name(), &directory, &basename); + basename = StripProto(basename); + + // CamelCase to be more ObjC friendly. + output = UnderscoresToCamelCase(basename, true); + + return output; +} + +std::string FileClassName(const FileDescriptor* file) { + const std::string prefix = FileClassPrefix(file); + const std::string name = + UnderscoresToCamelCase(StripProto(BaseFileName(file)), true) + "Root"; + // There aren't really any reserved words that end in "Root", but playing + // it safe and checking. + return SanitizeNameForObjC(prefix, name, "_RootClass", NULL); +} + +std::string ClassNameWorker(const Descriptor* descriptor) { + std::string name; + if (descriptor->containing_type() != NULL) { + name = ClassNameWorker(descriptor->containing_type()); + name += "_"; + } + return name + descriptor->name(); +} + +std::string ClassNameWorker(const EnumDescriptor* descriptor) { + std::string name; + if (descriptor->containing_type() != NULL) { + name = ClassNameWorker(descriptor->containing_type()); + name += "_"; + } + return name + descriptor->name(); +} + +std::string ClassName(const Descriptor* descriptor) { + return ClassName(descriptor, NULL); +} + +std::string ClassName(const Descriptor* descriptor, + std::string* out_suffix_added) { + // 1. Message names are used as is (style calls for CamelCase, trust it). + // 2. Check for reserved word at the very end and then suffix things. + const std::string prefix = FileClassPrefix(descriptor->file()); + const std::string name = ClassNameWorker(descriptor); + return SanitizeNameForObjC(prefix, name, "_Class", out_suffix_added); +} + +std::string EnumName(const EnumDescriptor* descriptor) { + // 1. Enum names are used as is (style calls for CamelCase, trust it). + // 2. Check for reserved word at the every end and then suffix things. + // message Fixed { + // message Size {...} + // enum Mumble {...} + // ... + // } + // yields Fixed_Class, Fixed_Size. + const std::string prefix = FileClassPrefix(descriptor->file()); + const std::string name = ClassNameWorker(descriptor); + return SanitizeNameForObjC(prefix, name, "_Enum", NULL); +} + +std::string EnumValueName(const EnumValueDescriptor* descriptor) { + // Because of the Switch enum compatibility, the name on the enum has to have + // the suffix handing, so it slightly diverges from how nested classes work. + // enum Fixed { + // FOO = 1 + // } + // yields Fixed_Enum and Fixed_Enum_Foo (not Fixed_Foo). + const std::string class_name = EnumName(descriptor->type()); + const std::string value_str = + UnderscoresToCamelCase(descriptor->name(), true); + const std::string name = class_name + "_" + value_str; + // There aren't really any reserved words with an underscore and a leading + // capital letter, but playing it safe and checking. + return SanitizeNameForObjC("", name, "_Value", NULL); +} + +std::string EnumValueShortName(const EnumValueDescriptor* descriptor) { + // Enum value names (EnumValueName above) are the enum name turned into + // a class name and then the value name is CamelCased and concatenated; the + // whole thing then gets sanitized for reserved words. + // The "short name" is intended to be the final leaf, the value name; but + // you can't simply send that off to sanitize as that could result in it + // getting modified when the full name didn't. For example enum + // "StorageModes" has a value "retain". So the full name is + // "StorageModes_Retain", but if we sanitize "retain" it would become + // "RetainValue". + // So the right way to get the short name is to take the full enum name + // and then strip off the enum name (leaving the value name and anything + // done by sanitize). + const std::string class_name = EnumName(descriptor->type()); + const std::string long_name_prefix = class_name + "_"; + const std::string long_name = EnumValueName(descriptor); + return StripPrefixString(long_name, long_name_prefix); +} + +std::string UnCamelCaseEnumShortName(const std::string& name) { + std::string result; + for (int i = 0; i < name.size(); i++) { + char c = name[i]; + if (i > 0 && ascii_isupper(c)) { + result += '_'; + } + result += ascii_toupper(c); + } + return result; +} + +std::string ExtensionMethodName(const FieldDescriptor* descriptor) { + const std::string name = NameFromFieldDescriptor(descriptor); + const std::string result = UnderscoresToCamelCase(name, false); + return SanitizeNameForObjC("", result, "_Extension", NULL); +} + +std::string FieldName(const FieldDescriptor* field) { + const std::string name = NameFromFieldDescriptor(field); + std::string result = UnderscoresToCamelCase(name, false); + if (field->is_repeated() && !field->is_map()) { + // Add "Array" before do check for reserved worlds. + result += "Array"; + } else { + // If it wasn't repeated, but ends in "Array", force on the _p suffix. + if (HasSuffixString(result, "Array")) { + result += "_p"; + } + } + return SanitizeNameForObjC("", result, "_p", NULL); +} + +std::string FieldNameCapitalized(const FieldDescriptor* field) { + // Want the same suffix handling, so upcase the first letter of the other + // name. + std::string result = FieldName(field); + if (result.length() > 0) { + result[0] = ascii_toupper(result[0]); + } + return result; +} + +std::string OneofEnumName(const OneofDescriptor* descriptor) { + const Descriptor* fieldDescriptor = descriptor->containing_type(); + std::string name = ClassName(fieldDescriptor); + name += "_" + UnderscoresToCamelCase(descriptor->name(), true) + "_OneOfCase"; + // No sanitize needed because the OS never has names that end in _OneOfCase. + return name; +} + +std::string OneofName(const OneofDescriptor* descriptor) { + std::string name = UnderscoresToCamelCase(descriptor->name(), false); + // No sanitize needed because it gets OneOfCase added and that shouldn't + // ever conflict. + return name; +} + +std::string OneofNameCapitalized(const OneofDescriptor* descriptor) { + // Use the common handling and then up-case the first letter. + std::string result = OneofName(descriptor); + if (result.length() > 0) { + result[0] = ascii_toupper(result[0]); + } + return result; +} + +std::string ObjCClass(const std::string& class_name) { + return std::string("GPBObjCClass(") + class_name + ")"; +} + +std::string ObjCClassDeclaration(const std::string& class_name) { + return std::string("GPBObjCClassDeclaration(") + class_name + ");"; +} + +std::string UnCamelCaseFieldName(const std::string& name, const FieldDescriptor* field) { + std::string worker(name); + if (HasSuffixString(worker, "_p")) { + worker = StripSuffixString(worker, "_p"); + } + if (field->is_repeated() && HasSuffixString(worker, "Array")) { + worker = StripSuffixString(worker, "Array"); + } + if (field->type() == FieldDescriptor::TYPE_GROUP) { + if (worker.length() > 0) { + if (ascii_islower(worker[0])) { + worker[0] = ascii_toupper(worker[0]); + } + } + return worker; + } else { + std::string result; + for (int i = 0; i < worker.size(); i++) { + char c = worker[i]; + if (ascii_isupper(c)) { + if (i > 0) { + result += '_'; + } + result += ascii_tolower(c); + } else { + result += c; + } + } + return result; + } +} + +std::string GetCapitalizedType(const FieldDescriptor* field) { + switch (field->type()) { + case FieldDescriptor::TYPE_INT32: + return "Int32"; + case FieldDescriptor::TYPE_UINT32: + return "UInt32"; + case FieldDescriptor::TYPE_SINT32: + return "SInt32"; + case FieldDescriptor::TYPE_FIXED32: + return "Fixed32"; + case FieldDescriptor::TYPE_SFIXED32: + return "SFixed32"; + case FieldDescriptor::TYPE_INT64: + return "Int64"; + case FieldDescriptor::TYPE_UINT64: + return "UInt64"; + case FieldDescriptor::TYPE_SINT64: + return "SInt64"; + case FieldDescriptor::TYPE_FIXED64: + return "Fixed64"; + case FieldDescriptor::TYPE_SFIXED64: + return "SFixed64"; + case FieldDescriptor::TYPE_FLOAT: + return "Float"; + case FieldDescriptor::TYPE_DOUBLE: + return "Double"; + case FieldDescriptor::TYPE_BOOL: + return "Bool"; + case FieldDescriptor::TYPE_STRING: + return "String"; + case FieldDescriptor::TYPE_BYTES: + return "Bytes"; + case FieldDescriptor::TYPE_ENUM: + return "Enum"; + case FieldDescriptor::TYPE_GROUP: + return "Group"; + case FieldDescriptor::TYPE_MESSAGE: + return "Message"; + } + + // Some compilers report reaching end of function even though all cases of + // the enum are handed in the switch. + GOOGLE_LOG(FATAL) << "Can't get here."; + return std::string(); +} + +ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type) { + switch (field_type) { + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_SFIXED32: + return OBJECTIVECTYPE_INT32; + + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_FIXED32: + return OBJECTIVECTYPE_UINT32; + + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_SFIXED64: + return OBJECTIVECTYPE_INT64; + + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_FIXED64: + return OBJECTIVECTYPE_UINT64; + + case FieldDescriptor::TYPE_FLOAT: + return OBJECTIVECTYPE_FLOAT; + + case FieldDescriptor::TYPE_DOUBLE: + return OBJECTIVECTYPE_DOUBLE; + + case FieldDescriptor::TYPE_BOOL: + return OBJECTIVECTYPE_BOOLEAN; + + case FieldDescriptor::TYPE_STRING: + return OBJECTIVECTYPE_STRING; + + case FieldDescriptor::TYPE_BYTES: + return OBJECTIVECTYPE_DATA; + + case FieldDescriptor::TYPE_ENUM: + return OBJECTIVECTYPE_ENUM; + + case FieldDescriptor::TYPE_GROUP: + case FieldDescriptor::TYPE_MESSAGE: + return OBJECTIVECTYPE_MESSAGE; + } + + // Some compilers report reaching end of function even though all cases of + // the enum are handed in the switch. + GOOGLE_LOG(FATAL) << "Can't get here."; + return OBJECTIVECTYPE_INT32; +} + +bool IsPrimitiveType(const FieldDescriptor* field) { + ObjectiveCType type = GetObjectiveCType(field); + switch (type) { + case OBJECTIVECTYPE_INT32: + case OBJECTIVECTYPE_UINT32: + case OBJECTIVECTYPE_INT64: + case OBJECTIVECTYPE_UINT64: + case OBJECTIVECTYPE_FLOAT: + case OBJECTIVECTYPE_DOUBLE: + case OBJECTIVECTYPE_BOOLEAN: + case OBJECTIVECTYPE_ENUM: + return true; + break; + default: + return false; + } +} + +bool IsReferenceType(const FieldDescriptor* field) { + return !IsPrimitiveType(field); +} + +static std::string HandleExtremeFloatingPoint(std::string val, + bool add_float_suffix) { + if (val == "nan") { + return "NAN"; + } else if (val == "inf") { + return "INFINITY"; + } else if (val == "-inf") { + return "-INFINITY"; + } else { + // float strings with ., e or E need to have f appended + if (add_float_suffix && (val.find(".") != std::string::npos || + val.find("e") != std::string::npos || + val.find("E") != std::string::npos)) { + val += "f"; + } + return val; + } +} + +std::string GPBGenericValueFieldName(const FieldDescriptor* field) { + // Returns the field within the GPBGenericValue union to use for the given + // field. + if (field->is_repeated()) { + return "valueMessage"; + } + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_INT32: + return "valueInt32"; + case FieldDescriptor::CPPTYPE_UINT32: + return "valueUInt32"; + case FieldDescriptor::CPPTYPE_INT64: + return "valueInt64"; + case FieldDescriptor::CPPTYPE_UINT64: + return "valueUInt64"; + case FieldDescriptor::CPPTYPE_FLOAT: + return "valueFloat"; + case FieldDescriptor::CPPTYPE_DOUBLE: + return "valueDouble"; + case FieldDescriptor::CPPTYPE_BOOL: + return "valueBool"; + case FieldDescriptor::CPPTYPE_STRING: + if (field->type() == FieldDescriptor::TYPE_BYTES) { + return "valueData"; + } else { + return "valueString"; + } + case FieldDescriptor::CPPTYPE_ENUM: + return "valueEnum"; + case FieldDescriptor::CPPTYPE_MESSAGE: + return "valueMessage"; + } + + // Some compilers report reaching end of function even though all cases of + // the enum are handed in the switch. + GOOGLE_LOG(FATAL) << "Can't get here."; + return std::string(); +} + + +std::string DefaultValue(const FieldDescriptor* field) { + // Repeated fields don't have defaults. + if (field->is_repeated()) { + return "nil"; + } + + // Switch on cpp_type since we need to know which default_value_* method + // of FieldDescriptor to call. + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_INT32: + // gcc and llvm reject the decimal form of kint32min and kint64min. + if (field->default_value_int32() == INT_MIN) { + return "-0x80000000"; + } + return StrCat(field->default_value_int32()); + case FieldDescriptor::CPPTYPE_UINT32: + return StrCat(field->default_value_uint32()) + "U"; + case FieldDescriptor::CPPTYPE_INT64: + // gcc and llvm reject the decimal form of kint32min and kint64min. + if (field->default_value_int64() == LLONG_MIN) { + return "-0x8000000000000000LL"; + } + return StrCat(field->default_value_int64()) + "LL"; + case FieldDescriptor::CPPTYPE_UINT64: + return StrCat(field->default_value_uint64()) + "ULL"; + case FieldDescriptor::CPPTYPE_DOUBLE: + return HandleExtremeFloatingPoint( + SimpleDtoa(field->default_value_double()), false); + case FieldDescriptor::CPPTYPE_FLOAT: + return HandleExtremeFloatingPoint( + SimpleFtoa(field->default_value_float()), true); + case FieldDescriptor::CPPTYPE_BOOL: + return field->default_value_bool() ? "YES" : "NO"; + case FieldDescriptor::CPPTYPE_STRING: { + const bool has_default_value = field->has_default_value(); + const std::string& default_string = field->default_value_string(); + if (!has_default_value || default_string.length() == 0) { + // If the field is defined as being the empty string, + // then we will just assign to nil, as the empty string is the + // default for both strings and data. + return "nil"; + } + if (field->type() == FieldDescriptor::TYPE_BYTES) { + // We want constant fields in our data structures so we can + // declare them as static. To achieve this we cheat and stuff + // a escaped c string (prefixed with a length) into the data + // field, and cast it to an (NSData*) so it will compile. + // The runtime library knows how to handle it. + + // Must convert to a standard byte order for packing length into + // a cstring. + uint32_t length = ghtonl(default_string.length()); + std::string bytes((const char*)&length, sizeof(length)); + bytes.append(default_string); + return "(NSData*)\"" + EscapeTrigraphs(CEscape(bytes)) + "\""; + } else { + return "@\"" + EscapeTrigraphs(CEscape(default_string)) + "\""; + } + } + case FieldDescriptor::CPPTYPE_ENUM: + return EnumValueName(field->default_value_enum()); + case FieldDescriptor::CPPTYPE_MESSAGE: + return "nil"; + } + + // Some compilers report reaching end of function even though all cases of + // the enum are handed in the switch. + GOOGLE_LOG(FATAL) << "Can't get here."; + return std::string(); +} + +bool HasNonZeroDefaultValue(const FieldDescriptor* field) { + // Repeated fields don't have defaults. + if (field->is_repeated()) { + return false; + } + + // As much as checking field->has_default_value() seems useful, it isn't + // because of enums. proto2 syntax allows the first item in an enum (the + // default) to be non zero. So checking field->has_default_value() would + // result in missing this non zero default. See MessageWithOneBasedEnum in + // objectivec/Tests/unittest_objc.proto for a test Message to confirm this. + + // Some proto file set the default to the zero value, so make sure the value + // isn't the zero case. + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_INT32: + return field->default_value_int32() != 0; + case FieldDescriptor::CPPTYPE_UINT32: + return field->default_value_uint32() != 0U; + case FieldDescriptor::CPPTYPE_INT64: + return field->default_value_int64() != 0LL; + case FieldDescriptor::CPPTYPE_UINT64: + return field->default_value_uint64() != 0ULL; + case FieldDescriptor::CPPTYPE_DOUBLE: + return field->default_value_double() != 0.0; + case FieldDescriptor::CPPTYPE_FLOAT: + return field->default_value_float() != 0.0f; + case FieldDescriptor::CPPTYPE_BOOL: + return field->default_value_bool(); + case FieldDescriptor::CPPTYPE_STRING: { + const std::string& default_string = field->default_value_string(); + return default_string.length() != 0; + } + case FieldDescriptor::CPPTYPE_ENUM: + return field->default_value_enum()->number() != 0; + case FieldDescriptor::CPPTYPE_MESSAGE: + return false; + } + + // Some compilers report reaching end of function even though all cases of + // the enum are handed in the switch. + GOOGLE_LOG(FATAL) << "Can't get here."; + return false; +} + +std::string BuildFlagsString(const FlagType flag_type, + const std::vector& strings) { + if (strings.empty()) { + return GetZeroEnumNameForFlagType(flag_type); + } else if (strings.size() == 1) { + return strings[0]; + } + std::string string("(" + GetEnumNameForFlagType(flag_type) + ")("); + for (size_t i = 0; i != strings.size(); ++i) { + if (i > 0) { + string.append(" | "); + } + string.append(strings[i]); + } + string.append(")"); + return string; +} + +std::string BuildCommentsString(const SourceLocation& location, + bool prefer_single_line) { + const std::string& comments = location.leading_comments.empty() + ? location.trailing_comments + : location.leading_comments; + std::vector lines; + lines = Split(comments, "\n", false); + while (!lines.empty() && lines.back().empty()) { + lines.pop_back(); + } + // If there are no comments, just return an empty string. + if (lines.empty()) { + return ""; + } + + std::string prefix; + std::string suffix; + std::string final_comments; + std::string epilogue; + + bool add_leading_space = false; + + if (prefer_single_line && lines.size() == 1) { + prefix = "/** "; + suffix = " */\n"; + } else { + prefix = "* "; + suffix = "\n"; + final_comments += "/**\n"; + epilogue = " **/\n"; + add_leading_space = true; + } + + for (int i = 0; i < lines.size(); i++) { + std::string line = StripPrefixString(lines[i], " "); + // HeaderDoc and appledoc use '\' and '@' for markers; escape them. + line = StringReplace(line, "\\", "\\\\", true); + line = StringReplace(line, "@", "\\@", true); + // Decouple / from * to not have inline comments inside comments. + line = StringReplace(line, "/*", "/\\*", true); + line = StringReplace(line, "*/", "*\\/", true); + line = prefix + line; + StripWhitespace(&line); + // If not a one line, need to add the first space before *, as + // StripWhitespace would have removed it. + line = (add_leading_space ? " " : "") + line; + final_comments += line + suffix; + } + final_comments += epilogue; + return final_comments; +} + +// Making these a generator option for folks that don't use CocoaPods, but do +// want to put the library in a framework is an interesting question. The +// problem is it means changing sources shipped with the library to actually +// use a different value; so it isn't as simple as a option. +const char* const ProtobufLibraryFrameworkName = "Protobuf"; + +std::string ProtobufFrameworkImportSymbol(const std::string& framework_name) { + // GPB_USE_[framework_name]_FRAMEWORK_IMPORTS + std::string result = std::string("GPB_USE_"); + result += ToUpper(framework_name); + result += "_FRAMEWORK_IMPORTS"; + return result; +} + +bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file) { + // We don't check the name prefix or proto package because some files + // (descriptor.proto), aren't shipped generated by the library, so this + // seems to be the safest way to only catch the ones shipped. + const std::string name = file->name(); + if (name == "google/protobuf/any.proto" || + name == "google/protobuf/api.proto" || + name == "google/protobuf/duration.proto" || + name == "google/protobuf/empty.proto" || + name == "google/protobuf/field_mask.proto" || + name == "google/protobuf/source_context.proto" || + name == "google/protobuf/struct.proto" || + name == "google/protobuf/timestamp.proto" || + name == "google/protobuf/type.proto" || + name == "google/protobuf/wrappers.proto") { + return true; + } + return false; +} + +bool ReadLine(StringPiece* input, StringPiece* line) { + for (int len = 0; len < input->size(); ++len) { + if (ascii_isnewline((*input)[len])) { + *line = StringPiece(input->data(), len); + ++len; // advance over the newline + *input = StringPiece(input->data() + len, input->size() - len); + return true; + } + } + return false; // Ran out of input with no newline. +} + +void RemoveComment(StringPiece* input) { + int offset = input->find('#'); + if (offset != StringPiece::npos) { + input->remove_suffix(input->length() - offset); + } +} + +namespace { + +bool PackageToPrefixesCollector::ConsumeLine( + const StringPiece& line, std::string* out_error) { + int offset = line.find('='); + if (offset == StringPiece::npos) { + *out_error = usage_ + " file line without equal sign: '" + StrCat(line) + "'."; + return false; + } + StringPiece package = line.substr(0, offset); + StringPiece prefix = line.substr(offset + 1); + TrimWhitespace(&package); + TrimWhitespace(&prefix); + MaybeUnQuote(&prefix); + // Don't really worry about error checking the package/prefix for + // being valid. Assume the file is validated when it is created/edited. + (*prefix_map_)[std::string(package)] = std::string(prefix); + return true; +} + +bool LoadExpectedPackagePrefixes(const std::string& expected_prefixes_path, + std::map* prefix_map, + std::string* out_error) { + if (expected_prefixes_path.empty()) { + return true; + } + + PackageToPrefixesCollector collector("Expected prefixes", prefix_map); + return ParseSimpleFile( + expected_prefixes_path, &collector, out_error); +} + +bool ValidateObjCClassPrefix( + const FileDescriptor* file, const std::string& expected_prefixes_path, + const std::map& expected_package_prefixes, + bool prefixes_must_be_registered, bool require_prefixes, + std::string* out_error) { + // Reminder: An explicit prefix option of "" is valid in case the default + // prefixing is set to use the proto package and a file needs to be generated + // without any prefix at all (for legacy reasons). + + bool has_prefix = file->options().has_objc_class_prefix(); + bool have_expected_prefix_file = !expected_prefixes_path.empty(); + + const std::string prefix = file->options().objc_class_prefix(); + const std::string package = file->package(); + // For files without packages, the can be registered as "no_package:PATH", + // allowing the expected prefixes file. + static const std::string no_package_prefix("no_package:"); + const std::string lookup_key = + package.empty() ? no_package_prefix + file->name() : package; + + // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some + // error cases, so it seems to be ok to use as a back door for warnings. + + // Check: Error - See if there was an expected prefix for the package and + // report if it doesn't match (wrong or missing). + std::map::const_iterator package_match = + expected_package_prefixes.find(lookup_key); + if (package_match != expected_package_prefixes.end()) { + // There was an entry, and... + if (has_prefix && package_match->second == prefix) { + // ...it matches. All good, out of here! + return true; + } else { + // ...it didn't match! + *out_error = "error: Expected 'option objc_class_prefix = \"" + + package_match->second + "\";'"; + if (!package.empty()) { + *out_error += " for package '" + package + "'"; + } + *out_error += " in '" + file->name() + "'"; + if (has_prefix) { + *out_error += "; but found '" + prefix + "' instead"; + } + *out_error += "."; + return false; + } + } + + // If there was no prefix option, we're done at this point. + if (!has_prefix) { + if (require_prefixes) { + *out_error = + "error: '" + file->name() + "' does not have a required 'option" + + " objc_class_prefix'."; + return false; + } + return true; + } + + // When the prefix is non empty, check it against the expected entries. + if (!prefix.empty() && have_expected_prefix_file) { + // For a non empty prefix, look for any other package that uses the prefix. + std::string other_package_for_prefix; + for (std::map::const_iterator i = + expected_package_prefixes.begin(); + i != expected_package_prefixes.end(); ++i) { + if (i->second == prefix) { + other_package_for_prefix = i->first; + // Stop on the first real package listing, if it was a no_package file + // specific entry, keep looking to try and find a package one. + if (!HasPrefixString(other_package_for_prefix, no_package_prefix)) { + break; + } + } + } + + // Check: Error - Make sure the prefix wasn't expected for a different + // package (overlap is allowed, but it has to be listed as an expected + // overlap). + if (!other_package_for_prefix.empty()) { + *out_error = + "error: Found 'option objc_class_prefix = \"" + prefix + + "\";' in '" + file->name() + "'; that prefix is already used for "; + if (HasPrefixString(other_package_for_prefix, no_package_prefix)) { + *out_error += "file '" + + StripPrefixString(other_package_for_prefix, no_package_prefix) + + "'."; + } else { + *out_error += "'package " + other_package_for_prefix + ";'."; + } + *out_error += + " It can only be reused by adding '" + lookup_key + " = " + prefix + + "' to the expected prefixes file (" + expected_prefixes_path + ")."; + return false; // Only report first usage of the prefix. + } + } // !prefix.empty() && have_expected_prefix_file + + // Check: Warning - Make sure the prefix is is a reasonable value according + // to Apple's rules (the checks above implicitly whitelist anything that + // doesn't meet these rules). + if (!prefix.empty() && !ascii_isupper(prefix[0])) { + std::cerr + << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" + << prefix << "\";' in '" << file->name() << "';" + << " it should start with a capital letter." << std::endl; + std::cerr.flush(); + } + if (!prefix.empty() && prefix.length() < 3) { + // Apple reserves 2 character prefixes for themselves. They do use some + // 3 character prefixes, but they haven't updated the rules/docs. + std::cerr + << "protoc:0: warning: Invalid 'option objc_class_prefix = \"" + << prefix << "\";' in '" << file->name() << "';" + << " Apple recommends they should be at least 3 characters long." + << std::endl; + std::cerr.flush(); + } + + // Check: Error/Warning - If the given package/prefix pair wasn't expected, + // issue a error/warning to added to the file. + if (have_expected_prefix_file) { + if (prefixes_must_be_registered) { + *out_error = + "error: '" + file->name() + "' has 'option objc_class_prefix = \"" + + prefix + "\";', but it is not registered. Add '" + lookup_key + " = " + + (prefix.empty() ? "\"\"" : prefix) + + "' to the expected prefixes file (" + expected_prefixes_path + ")."; + return false; + } + + std::cerr + << "protoc:0: warning: Found unexpected 'option objc_class_prefix = \"" + << prefix << "\";' in '" << file->name() << "'; consider adding '" + << lookup_key << " = " << (prefix.empty() ? "\"\"" : prefix) + << "' to the expected prefixes file (" << expected_prefixes_path + << ")." << std::endl; + std::cerr.flush(); + } + + return true; +} + +} // namespace + +bool ValidateObjCClassPrefixes(const std::vector& files, + std::string* out_error) { + // Options's ctor load from the environment. + Options options; + return ValidateObjCClassPrefixes(files, options, out_error); +} + +bool ValidateObjCClassPrefixes(const std::vector& files, + const Options& generation_options, + std::string* out_error) { + // Allow a '-' as the path for the expected prefixes to completely disable + // even the most basic of checks. + if (generation_options.expected_prefixes_path == "-") { + return true; + } + + // Load the expected package prefixes, if available, to validate against. + std::map expected_package_prefixes; + if (!LoadExpectedPackagePrefixes(generation_options.expected_prefixes_path, + &expected_package_prefixes, + out_error)) { + return false; + } + + for (int i = 0; i < files.size(); i++) { + bool should_skip = + (std::find(generation_options.expected_prefixes_suppressions.begin(), + generation_options.expected_prefixes_suppressions.end(), + files[i]->name()) + != generation_options.expected_prefixes_suppressions.end()); + if (should_skip) { + continue; + } + + bool is_valid = + ValidateObjCClassPrefix(files[i], + generation_options.expected_prefixes_path, + expected_package_prefixes, + generation_options.prefixes_must_be_registered, + generation_options.require_prefixes, + out_error); + if (!is_valid) { + return false; + } + } + return true; +} + +TextFormatDecodeData::TextFormatDecodeData() { } + +TextFormatDecodeData::~TextFormatDecodeData() { } + +void TextFormatDecodeData::AddString(int32_t key, + const std::string& input_for_decode, + const std::string& desired_output) { + for (std::vector::const_iterator i = entries_.begin(); + i != entries_.end(); ++i) { + if (i->first == key) { + std::cerr << "error: duplicate key (" << key + << ") making TextFormat data, input: \"" << input_for_decode + << "\", desired: \"" << desired_output << "\"." << std::endl; + std::cerr.flush(); + abort(); + } + } + + const std::string& data = TextFormatDecodeData::DecodeDataForString( + input_for_decode, desired_output); + entries_.push_back(DataEntry(key, data)); +} + +std::string TextFormatDecodeData::Data() const { + std::ostringstream data_stringstream; + + if (num_entries() > 0) { + io::OstreamOutputStream data_outputstream(&data_stringstream); + io::CodedOutputStream output_stream(&data_outputstream); + + output_stream.WriteVarint32(num_entries()); + for (std::vector::const_iterator i = entries_.begin(); + i != entries_.end(); ++i) { + output_stream.WriteVarint32(i->first); + output_stream.WriteString(i->second); + } + } + + data_stringstream.flush(); + return data_stringstream.str(); +} + +namespace { + +// Helper to build up the decode data for a string. +class DecodeDataBuilder { + public: + DecodeDataBuilder() { Reset(); } + + bool AddCharacter(const char desired, const char input); + void AddUnderscore() { + Push(); + need_underscore_ = true; + } + std::string Finish() { + Push(); + return decode_data_; + } + + private: + static constexpr uint8_t kAddUnderscore = 0x80; + + static constexpr uint8_t kOpAsIs = 0x00; + static constexpr uint8_t kOpFirstUpper = 0x40; + static constexpr uint8_t kOpFirstLower = 0x20; + static constexpr uint8_t kOpAllUpper = 0x60; + + static constexpr int kMaxSegmentLen = 0x1f; + + void AddChar(const char desired) { + ++segment_len_; + is_all_upper_ &= ascii_isupper(desired); + } + + void Push() { + uint8_t op = (op_ | segment_len_); + if (need_underscore_) op |= kAddUnderscore; + if (op != 0) { + decode_data_ += (char)op; + } + Reset(); + } + + bool AddFirst(const char desired, const char input) { + if (desired == input) { + op_ = kOpAsIs; + } else if (desired == ascii_toupper(input)) { + op_ = kOpFirstUpper; + } else if (desired == ascii_tolower(input)) { + op_ = kOpFirstLower; + } else { + // Can't be transformed to match. + return false; + } + AddChar(desired); + return true; + } + + void Reset() { + need_underscore_ = false; + op_ = 0; + segment_len_ = 0; + is_all_upper_ = true; + } + + bool need_underscore_; + bool is_all_upper_; + uint8_t op_; + int segment_len_; + + std::string decode_data_; +}; + +bool DecodeDataBuilder::AddCharacter(const char desired, const char input) { + // If we've hit the max size, push to start a new segment. + if (segment_len_ == kMaxSegmentLen) { + Push(); + } + if (segment_len_ == 0) { + return AddFirst(desired, input); + } + + // Desired and input match... + if (desired == input) { + // If we aren't transforming it, or we're upper casing it and it is + // supposed to be uppercase; just add it to the segment. + if ((op_ != kOpAllUpper) || ascii_isupper(desired)) { + AddChar(desired); + return true; + } + + // Add the current segment, and start the next one. + Push(); + return AddFirst(desired, input); + } + + // If we need to uppercase, and everything so far has been uppercase, + // promote op to AllUpper. + if ((desired == ascii_toupper(input)) && is_all_upper_) { + op_ = kOpAllUpper; + AddChar(desired); + return true; + } + + // Give up, push and start a new segment. + Push(); + return AddFirst(desired, input); +} + +// If decode data can't be generated, a directive for the raw string +// is used instead. +std::string DirectDecodeString(const std::string& str) { + std::string result; + result += (char)'\0'; // Marker for full string. + result += str; + result += (char)'\0'; // End of string. + return result; +} + +} // namespace + +// static +std::string TextFormatDecodeData::DecodeDataForString( + const std::string& input_for_decode, const std::string& desired_output) { + if (input_for_decode.empty() || desired_output.empty()) { + std::cerr << "error: got empty string for making TextFormat data, input: \"" + << input_for_decode << "\", desired: \"" << desired_output << "\"." + << std::endl; + std::cerr.flush(); + abort(); + } + if ((input_for_decode.find('\0') != std::string::npos) || + (desired_output.find('\0') != std::string::npos)) { + std::cerr << "error: got a null char in a string for making TextFormat data," + << " input: \"" << CEscape(input_for_decode) << "\", desired: \"" + << CEscape(desired_output) << "\"." << std::endl; + std::cerr.flush(); + abort(); + } + + DecodeDataBuilder builder; + + // Walk the output building it from the input. + int x = 0; + for (int y = 0; y < desired_output.size(); y++) { + const char d = desired_output[y]; + if (d == '_') { + builder.AddUnderscore(); + continue; + } + + if (x >= input_for_decode.size()) { + // Out of input, no way to encode it, just return a full decode. + return DirectDecodeString(desired_output); + } + if (builder.AddCharacter(d, input_for_decode[x])) { + ++x; // Consumed one input + } else { + // Couldn't transform for the next character, just return a full decode. + return DirectDecodeString(desired_output); + } + } + + if (x != input_for_decode.size()) { + // Extra input (suffix from name sanitizing?), just return a full decode. + return DirectDecodeString(desired_output); + } + + // Add the end marker. + return builder.Finish() + (char)'\0'; +} + +namespace { + +class Parser { + public: + Parser(LineConsumer* line_consumer) + : line_consumer_(line_consumer), line_(0) {} + + // Feeds in some input, parse what it can, returning success/failure. Calling + // again after an error is undefined. + bool ParseChunk(StringPiece chunk, std::string* out_error); + + // Should be called to finish parsing (after all input has been provided via + // successful calls to ParseChunk(), calling after a ParseChunk() failure is + // undefined). Returns success/failure. + bool Finish(std::string* out_error); + + int last_line() const { return line_; } + + private: + LineConsumer* line_consumer_; + int line_; + std::string leftover_; +}; + +bool Parser::ParseChunk(StringPiece chunk, std::string* out_error) { + StringPiece full_chunk; + if (!leftover_.empty()) { + leftover_ += std::string(chunk); + full_chunk = StringPiece(leftover_); + } else { + full_chunk = chunk; + } + + StringPiece line; + while (ReadLine(&full_chunk, &line)) { + ++line_; + RemoveComment(&line); + TrimWhitespace(&line); + if (!line.empty() && !line_consumer_->ConsumeLine(line, out_error)) { + if (out_error->empty()) { + *out_error = "ConsumeLine failed without setting an error."; + } + leftover_.clear(); + return false; + } + } + + if (full_chunk.empty()) { + leftover_.clear(); + } else { + leftover_ = std::string(full_chunk); + } + return true; +} + +bool Parser::Finish(std::string* out_error) { + // If there is still something to go, flush it with a newline. + if (!leftover_.empty() && !ParseChunk("\n", out_error)) { + return false; + } + // This really should never fail if ParseChunk succeeded, but check to be sure. + if (!leftover_.empty()) { + *out_error = "ParseSimple Internal error: finished with pending data."; + return false; + } + return true; +} + +std::string FullErrorString(const std::string& name, int line_num, const std::string& msg) { + return std::string("error: ") + name + " Line " + StrCat(line_num) + ", " + msg; +} + +} // namespace + +LineConsumer::LineConsumer() {} + +LineConsumer::~LineConsumer() {} + +bool ParseSimpleFile(const std::string& path, LineConsumer* line_consumer, + std::string* out_error) { + int fd; + do { + fd = posix::open(path.c_str(), O_RDONLY); + } while (fd < 0 && errno == EINTR); + if (fd < 0) { + *out_error = std::string("error: Unable to open \"") + path + "\", " + + strerror(errno); + return false; + } + io::FileInputStream file_stream(fd); + file_stream.SetCloseOnDelete(true); + + return ParseSimpleStream(file_stream, path, line_consumer, out_error); +} + +bool ParseSimpleStream(io::ZeroCopyInputStream& input_stream, + const std::string& stream_name, + LineConsumer* line_consumer, + std::string* out_error) { + std::string local_error; + Parser parser(line_consumer); + const void* buf; + int buf_len; + while (input_stream.Next(&buf, &buf_len)) { + if (buf_len == 0) { + continue; + } + + if (!parser.ParseChunk(StringPiece(static_cast(buf), buf_len), + &local_error)) { + *out_error = FullErrorString(stream_name, parser.last_line(), local_error); + return false; + } + } + if (!parser.Finish(&local_error)) { + *out_error = FullErrorString(stream_name, parser.last_line(), local_error); + return false; + } + return true; +} + +ImportWriter::ImportWriter( + const std::string& generate_for_named_framework, + const std::string& named_framework_to_proto_path_mappings_path, + const std::string& runtime_import_prefix, bool include_wkt_imports) + : generate_for_named_framework_(generate_for_named_framework), + named_framework_to_proto_path_mappings_path_( + named_framework_to_proto_path_mappings_path), + runtime_import_prefix_(runtime_import_prefix), + include_wkt_imports_(include_wkt_imports), + need_to_parse_mapping_file_(true) {} + +ImportWriter::~ImportWriter() {} + +void ImportWriter::AddFile(const FileDescriptor* file, + const std::string& header_extension) { + if (IsProtobufLibraryBundledProtoFile(file)) { + // The imports of the WKTs are only needed within the library itself, + // in other cases, they get skipped because the generated code already + // import GPBProtocolBuffers.h and hence proves them. + if (include_wkt_imports_) { + const std::string header_name = + "GPB" + FilePathBasename(file) + header_extension; + protobuf_imports_.push_back(header_name); + } + return; + } + + // Lazy parse any mappings. + if (need_to_parse_mapping_file_) { + ParseFrameworkMappings(); + } + + std::map::iterator proto_lookup = + proto_file_to_framework_name_.find(file->name()); + if (proto_lookup != proto_file_to_framework_name_.end()) { + other_framework_imports_.push_back( + proto_lookup->second + "/" + + FilePathBasename(file) + header_extension); + return; + } + + if (!generate_for_named_framework_.empty()) { + other_framework_imports_.push_back( + generate_for_named_framework_ + "/" + + FilePathBasename(file) + header_extension); + return; + } + + other_imports_.push_back(FilePath(file) + header_extension); +} + +void ImportWriter::Print(io::Printer* printer) const { + bool add_blank_line = false; + + if (!protobuf_imports_.empty()) { + PrintRuntimeImports(printer, protobuf_imports_, runtime_import_prefix_); + add_blank_line = true; + } + + if (!other_framework_imports_.empty()) { + if (add_blank_line) { + printer->Print("\n"); + } + + for (std::vector::const_iterator iter = + other_framework_imports_.begin(); + iter != other_framework_imports_.end(); ++iter) { + printer->Print( + "#import <$header$>\n", + "header", *iter); + } + + add_blank_line = true; + } + + if (!other_imports_.empty()) { + if (add_blank_line) { + printer->Print("\n"); + } + + for (std::vector::const_iterator iter = other_imports_.begin(); + iter != other_imports_.end(); ++iter) { + printer->Print( + "#import \"$header$\"\n", + "header", *iter); + } + } +} + +void ImportWriter::PrintRuntimeImports( + io::Printer* printer, const std::vector& header_to_import, + const std::string& runtime_import_prefix, bool default_cpp_symbol) { + // Given an override, use that. + if (!runtime_import_prefix.empty()) { + for (const auto& header : header_to_import) { + printer->Print( + " #import \"$import_prefix$/$header$\"\n", + "import_prefix", runtime_import_prefix, + "header", header); + } + return; + } + + const std::string framework_name(ProtobufLibraryFrameworkName); + const std::string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name)); + + if (default_cpp_symbol) { + printer->Print( + "// This CPP symbol can be defined to use imports that match up to the framework\n" + "// imports needed when using CocoaPods.\n" + "#if !defined($cpp_symbol$)\n" + " #define $cpp_symbol$ 0\n" + "#endif\n" + "\n", + "cpp_symbol", cpp_symbol); + } + + printer->Print( + "#if $cpp_symbol$\n", + "cpp_symbol", cpp_symbol); + for (const auto& header : header_to_import) { + printer->Print( + " #import <$framework_name$/$header$>\n", + "framework_name", framework_name, + "header", header); + } + printer->Print( + "#else\n"); + for (const auto& header : header_to_import) { + printer->Print( + " #import \"$header$\"\n", + "header", header); + } + printer->Print( + "#endif\n"); +} + +void ImportWriter::ParseFrameworkMappings() { + need_to_parse_mapping_file_ = false; + if (named_framework_to_proto_path_mappings_path_.empty()) { + return; // Nothing to do. + } + + ProtoFrameworkCollector collector(&proto_file_to_framework_name_); + std::string parse_error; + if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_, + &collector, &parse_error)) { + std::cerr << "error parsing " << named_framework_to_proto_path_mappings_path_ + << " : " << parse_error << std::endl; + std::cerr.flush(); + } +} + +bool ImportWriter::ProtoFrameworkCollector::ConsumeLine( + const StringPiece& line, std::string* out_error) { + int offset = line.find(':'); + if (offset == StringPiece::npos) { + *out_error = + std::string("Framework/proto file mapping line without colon sign: '") + + std::string(line) + "'."; + return false; + } + StringPiece framework_name = line.substr(0, offset); + StringPiece proto_file_list = line.substr(offset + 1); + TrimWhitespace(&framework_name); + + int start = 0; + while (start < proto_file_list.length()) { + offset = proto_file_list.find(',', start); + if (offset == StringPiece::npos) { + offset = proto_file_list.length(); + } + + StringPiece proto_file = proto_file_list.substr(start, offset - start); + TrimWhitespace(&proto_file); + if (!proto_file.empty()) { + std::map::iterator existing_entry = + map_->find(std::string(proto_file)); + if (existing_entry != map_->end()) { + std::cerr << "warning: duplicate proto file reference, replacing " + "framework entry for '" + << std::string(proto_file) << "' with '" << std::string(framework_name) + << "' (was '" << existing_entry->second << "')." << std::endl; + std::cerr.flush(); + } + + if (proto_file.find(' ') != StringPiece::npos) { + std::cerr << "note: framework mapping file had a proto file with a " + "space in, hopefully that isn't a missing comma: '" + << std::string(proto_file) << "'" << std::endl; + std::cerr.flush(); + } + + (*map_)[std::string(proto_file)] = std::string(framework_name); + } + + start = offset + 1; + } + + return true; +} + +} // namespace objectivec +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h new file mode 100644 index 0000000..d21fed2 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -0,0 +1,353 @@ +// 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. + +// Helper functions for generating ObjectiveC code. + +#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ +#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ + +#include +#include + +#include +#include +#include + +#include + +namespace google { +namespace protobuf { +namespace compiler { +namespace objectivec { + +// Get/Set the path to a file to load for objc class prefix lookups. +std::string PROTOC_EXPORT GetPackageToPrefixMappingsPath(); +void PROTOC_EXPORT SetPackageToPrefixMappingsPath( + const std::string& file_path); +// Get/Set if the proto package should be used to make the default prefix for +// symbols. This will then impact most of the type naming apis below. It is done +// as a global to not break any other generator reusing the methods since they +// are exported. +bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix(); +void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off); +// Get/Set the path to a file to load as exceptions when +// `UseProtoPackageAsDefaultPrefix()` is `true`. An empty string means there +// should be no exceptions. +std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList(); +void PROTOC_EXPORT SetProtoPackagePrefixExceptionList( + const std::string& file_path); + +// Generator Prefix Validation Options (see objectivec_generator.cc for a +// description of each): +struct Options { + Options(); + std::string expected_prefixes_path; + std::vector expected_prefixes_suppressions; + bool prefixes_must_be_registered; + bool require_prefixes; +}; + +// Escape C++ trigraphs by escaping question marks to "\?". +std::string PROTOC_EXPORT EscapeTrigraphs(const std::string& to_escape); + +// Remove white space from either end of a StringPiece. +void PROTOC_EXPORT TrimWhitespace(StringPiece* input); + +// Returns true if the name requires a ns_returns_not_retained attribute applied +// to it. +bool PROTOC_EXPORT IsRetainedName(const std::string& name); + +// Returns true if the name starts with "init" and will need to have special +// handling under ARC. +bool PROTOC_EXPORT IsInitName(const std::string& name); + +// Gets the objc_class_prefix or the prefix made from the proto package. +std::string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); + +// Gets the path of the file we're going to generate (sans the .pb.h +// extension). The path will be dependent on the objectivec package +// declared in the proto package. +std::string PROTOC_EXPORT FilePath(const FileDescriptor* file); + +// Just like FilePath(), but without the directory part. +std::string PROTOC_EXPORT FilePathBasename(const FileDescriptor* file); + +// Gets the name of the root class we'll generate in the file. This class +// is not meant for external consumption, but instead contains helpers that +// the rest of the classes need +std::string PROTOC_EXPORT FileClassName(const FileDescriptor* file); + +// These return the fully-qualified class name corresponding to the given +// descriptor. +std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor); +std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor, + std::string* out_suffix_added); +std::string PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); + +// Returns the fully-qualified name of the enum value corresponding to the +// the descriptor. +std::string PROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); + +// Returns the name of the enum value corresponding to the descriptor. +std::string PROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor); + +// Reverse what an enum does. +std::string PROTOC_EXPORT UnCamelCaseEnumShortName(const std::string& name); + +// Returns the name to use for the extension (used as the method off the file's +// Root class). +std::string PROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor); + +// Returns the transformed field name. +std::string PROTOC_EXPORT FieldName(const FieldDescriptor* field); +std::string PROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); + +// Returns the transformed oneof name. +std::string PROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); +std::string PROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); +std::string PROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor); + +// Returns a symbol that can be used in C code to refer to an Objective C +// class without initializing the class. +std::string PROTOC_EXPORT ObjCClass(const std::string& class_name); + +// Declares an Objective C class without initializing the class so that it can +// be refrerred to by ObjCClass. +std::string PROTOC_EXPORT ObjCClassDeclaration(const std::string& class_name); + +inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) { + return file->syntax() == FileDescriptor::SYNTAX_PROTO3; +} + +inline bool IsMapEntryMessage(const Descriptor* descriptor) { + return descriptor->options().map_entry(); +} + +// Reverse of the above. +std::string PROTOC_EXPORT UnCamelCaseFieldName(const std::string& name, + const FieldDescriptor* field); + +enum ObjectiveCType { + OBJECTIVECTYPE_INT32, + OBJECTIVECTYPE_UINT32, + OBJECTIVECTYPE_INT64, + OBJECTIVECTYPE_UINT64, + OBJECTIVECTYPE_FLOAT, + OBJECTIVECTYPE_DOUBLE, + OBJECTIVECTYPE_BOOLEAN, + OBJECTIVECTYPE_STRING, + OBJECTIVECTYPE_DATA, + OBJECTIVECTYPE_ENUM, + OBJECTIVECTYPE_MESSAGE +}; + +enum FlagType { + FLAGTYPE_DESCRIPTOR_INITIALIZATION, + FLAGTYPE_EXTENSION, + FLAGTYPE_FIELD +}; + +template +std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, + const FileDescriptor* file = NULL, + bool preSpace = true, + bool postNewline = false) { + bool isDeprecated = descriptor->options().deprecated(); + // The file is only passed when checking Messages & Enums, so those types + // get tagged. At the moment, it doesn't seem to make sense to tag every + // field or enum value with when the file is deprecated. + bool isFileLevelDeprecation = false; + if (!isDeprecated && file) { + isFileLevelDeprecation = file->options().deprecated(); + isDeprecated = isFileLevelDeprecation; + } + if (isDeprecated) { + std::string message; + const FileDescriptor* sourceFile = descriptor->file(); + if (isFileLevelDeprecation) { + message = sourceFile->name() + " is deprecated."; + } else { + message = descriptor->full_name() + " is deprecated (see " + + sourceFile->name() + ")."; + } + + std::string result = std::string("GPB_DEPRECATED_MSG(\"") + message + "\")"; + if (preSpace) { + result.insert(0, " "); + } + if (postNewline) { + result.append("\n"); + } + return result; + } else { + return ""; + } +} + +std::string PROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field); + +ObjectiveCType PROTOC_EXPORT +GetObjectiveCType(FieldDescriptor::Type field_type); + +inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { + return GetObjectiveCType(field->type()); +} + +bool PROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field); +bool PROTOC_EXPORT IsReferenceType(const FieldDescriptor* field); + +std::string PROTOC_EXPORT +GPBGenericValueFieldName(const FieldDescriptor* field); +std::string PROTOC_EXPORT DefaultValue(const FieldDescriptor* field); +bool PROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field); + +std::string PROTOC_EXPORT +BuildFlagsString(const FlagType type, const std::vector& strings); + +// Builds HeaderDoc/appledoc style comments out of the comments in the .proto +// file. +std::string PROTOC_EXPORT BuildCommentsString(const SourceLocation& location, + bool prefer_single_line); + +// The name the commonly used by the library when built as a framework. +// This lines up to the name used in the CocoaPod. +extern PROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; +// Returns the CPP symbol name to use as the gate for framework style imports +// for the given framework name to use. +std::string PROTOC_EXPORT +ProtobufFrameworkImportSymbol(const std::string& framework_name); + +// Checks if the file is one of the proto's bundled with the library. +bool PROTOC_EXPORT +IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); + +// Checks the prefix for the given files and outputs any warnings as needed. If +// there are flat out errors, then out_error is filled in with the first error +// and the result is false. +bool PROTOC_EXPORT ValidateObjCClassPrefixes( + const std::vector& files, + const Options& validation_options, std::string* out_error); +// Same was the other ValidateObjCClassPrefixes() calls, but the options all +// come from the environment variables. +bool PROTOC_EXPORT ValidateObjCClassPrefixes( + const std::vector& files, std::string* out_error); + +// Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform +// the input into the expected output. +class PROTOC_EXPORT TextFormatDecodeData { + public: + TextFormatDecodeData(); + ~TextFormatDecodeData(); + + TextFormatDecodeData(const TextFormatDecodeData&) = delete; + TextFormatDecodeData& operator=(const TextFormatDecodeData&) = delete; + + void AddString(int32_t key, const std::string& input_for_decode, + const std::string& desired_output); + size_t num_entries() const { return entries_.size(); } + std::string Data() const; + + static std::string DecodeDataForString(const std::string& input_for_decode, + const std::string& desired_output); + + private: + typedef std::pair DataEntry; + std::vector entries_; +}; + +// Helper for parsing simple files. +class PROTOC_EXPORT LineConsumer { + public: + LineConsumer(); + virtual ~LineConsumer(); + virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) = 0; +}; + +bool PROTOC_EXPORT ParseSimpleFile(const std::string& path, + LineConsumer* line_consumer, + std::string* out_error); + +bool PROTOC_EXPORT ParseSimpleStream(io::ZeroCopyInputStream& input_stream, + const std::string& stream_name, + LineConsumer* line_consumer, + std::string* out_error); + +// Helper class for parsing framework import mappings and generating +// import statements. +class PROTOC_EXPORT ImportWriter { + public: + ImportWriter(const std::string& generate_for_named_framework, + const std::string& named_framework_to_proto_path_mappings_path, + const std::string& runtime_import_prefix, + bool include_wkt_imports); + ~ImportWriter(); + + void AddFile(const FileDescriptor* file, const std::string& header_extension); + void Print(io::Printer* printer) const; + + static void PrintRuntimeImports(io::Printer* printer, + const std::vector& header_to_import, + const std::string& runtime_import_prefix, + bool default_cpp_symbol = false); + + private: + class ProtoFrameworkCollector : public LineConsumer { + public: + ProtoFrameworkCollector(std::map* inout_proto_file_to_framework_name) + : map_(inout_proto_file_to_framework_name) {} + + virtual bool ConsumeLine(const StringPiece& line, std::string* out_error) override; + + private: + std::map* map_; + }; + + void ParseFrameworkMappings(); + + const std::string generate_for_named_framework_; + const std::string named_framework_to_proto_path_mappings_path_; + const std::string runtime_import_prefix_; + const bool include_wkt_imports_; + std::map proto_file_to_framework_name_; + bool need_to_parse_mapping_file_; + + std::vector protobuf_imports_; + std::vector other_framework_imports_; + std::vector other_imports_; +}; + +} // namespace objectivec +} // namespace compiler +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc similarity index 67% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data_unittest.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc index 6cec537..7ae6a92 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc @@ -28,13 +28,10 @@ // (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/compiler/objectivec/text_format_decode_data.h" - +#include +#include #include -// Must be included last -#include "google/protobuf/port_def.inc" - namespace google { namespace protobuf { namespace compiler { @@ -104,12 +101,10 @@ TEST(ObjCHelper, TextFormatDecodeData_DecodeDataForString_ByteCodes) { // Long name so multiple decode ops are needed. - // clang-format off input_for_decode = "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000"; desired_output_for_decode = "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000"; - // clang-format on expected = std::string("\x04\xA5\xA4\xA2\xBF\x1F\x0E\x84\x0", 9); result = TextFormatDecodeData::DecodeDataForString(input_for_decode, desired_output_for_decode); @@ -159,13 +154,11 @@ TEST(ObjCHelper, TextFormatDecodeData_RawStrings) { EXPECT_EQ(4, decode_data.num_entries()); uint8_t expected_data[] = { - // clang-format off 0x4, 0x1, 0x0, 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 0x0, 0x3, 0x0, 'a', 'b', 'c', 'd', 'e', 'z', 'g', 'h', 'I', 'J', 0x0, 0x2, 0x0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 0x0, 0x4, 0x0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 'z', 0x0, - // clang-format on }; std::string expected((const char*)expected_data, sizeof(expected_data)); @@ -179,15 +172,12 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { decode_data.AddString(3, "abcdefghIJ", "_AbcdefghIJ"); decode_data.AddString(2, "abcdefghIJ", "Abcd_EfghIJ"); decode_data.AddString(4, "abcdefghIJ", "ABCD__EfghI_j"); - // clang-format off decode_data.AddString(1000, "longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000", "long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000"); - // clang-format on EXPECT_EQ(5, decode_data.num_entries()); - // clang-format off uint8_t expected_data[] = { 0x5, // All as is (00 op) @@ -206,12 +196,12 @@ TEST(ObjCHelper, TextFormatDecodeData_ByteCodes) { // underscore, as is + 3 (00 op) 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0, }; - // clang-format on std::string expected((const char*)expected_data, sizeof(expected_data)); EXPECT_EQ(expected, decode_data.Data()); } + // Death tests do not work on Windows as of yet. #ifdef PROTOBUF_HAS_DEATH_TEST TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) { @@ -252,10 +242,143 @@ TEST(ObjCHelperDeathTest, TextFormatDecodeData_Failures) { } #endif // PROTOBUF_HAS_DEATH_TEST +class TestLineCollector : public LineConsumer { + public: + TestLineCollector(std::vector* inout_lines, + const std::string* reject_line = nullptr, + bool skip_msg = false) + : lines_(inout_lines), reject_(reject_line), skip_msg_(skip_msg) {} + + bool ConsumeLine(const StringPiece& line, std::string* out_error) override { + if (reject_ && *reject_ == line) { + if (!skip_msg_) { + *out_error = std::string("Rejected '") + *reject_ + "'"; + } + return false; + } + if (lines_) { + lines_->emplace_back(line); + } + return true; + } + + private: + std::vector* lines_; + const std::string* reject_; + bool skip_msg_; +}; + +const int kBlockSizes[] = {-1, 1, 2, 5, 64}; +const int kBlockSizeCount = GOOGLE_ARRAYSIZE(kBlockSizes); + +TEST(ObjCHelper, ParseSimple_BasicsSuccess) { + const std::vector>> tests = { + {"", {}}, + {"a", {"a"}}, + {"a c", {"a c"}}, + {" a c ", {"a c"}}, + {"\ta c ", {"a c"}}, + {"abc\n", {"abc"}}, + {"abc\nd f", {"abc", "d f"}}, + {"\n abc \n def \n\n", {"abc", "def"}}, + }; + + for (const auto& test : tests) { + for (int i = 0; i < kBlockSizeCount; i++) { + io::ArrayInputStream input(test.first.data(), test.first.size(), kBlockSizes[i]); + std::string err_str; + std::vector lines; + TestLineCollector collector(&lines); + EXPECT_TRUE(ParseSimpleStream(input, "dummy", &collector, &err_str)); + EXPECT_EQ(lines, test.second); + EXPECT_TRUE(err_str.empty()); + } + } +} + +TEST(ObjCHelper, ParseSimple_DropsComments) { + const std::vector>> tests = { + {"# nothing", {}}, + {"#", {}}, + {"##", {}}, + {"\n# nothing\n", {}}, + {"a # same line", {"a"}}, + {"a # same line\n", {"a"}}, + {"a\n# line\nc", {"a", "c"}}, + {"# n o t # h i n g #", {}}, + {"## n o # t h i n g #", {}}, + {"a# n o t # h i n g #", {"a"}}, + {"a\n## n o # t h i n g #", {"a"}}, + }; + + for (const auto& test : tests) { + for (int i = 0; i < kBlockSizeCount; i++) { + io::ArrayInputStream input(test.first.data(), test.first.size(), kBlockSizes[i]); + std::string err_str; + std::vector lines; + TestLineCollector collector(&lines); + EXPECT_TRUE(ParseSimpleStream(input, "dummy", &collector, &err_str)); + EXPECT_EQ(lines, test.second); + EXPECT_TRUE(err_str.empty()); + } + } +} + +TEST(ObjCHelper, ParseSimple_RejectLines) { + const std::vector> tests = { + std::make_tuple("a\nb\nc", "a", 1), + std::make_tuple("a\nb\nc", "b", 2), + std::make_tuple("a\nb\nc", "c", 3), + std::make_tuple("a\nb\nc\n", "c", 3), + }; + + for (const auto& test : tests) { + for (int i = 0; i < kBlockSizeCount; i++) { + io::ArrayInputStream input(std::get<0>(test).data(), std::get<0>(test).size(), + kBlockSizes[i]); + std::string err_str; + TestLineCollector collector(nullptr, &std::get<1>(test)); + EXPECT_FALSE(ParseSimpleStream(input, "dummy", &collector, &err_str)); + std::string expected_err = + StrCat("error: dummy Line ", std::get<2>(test), ", Rejected '", std::get<1>(test), "'"); + EXPECT_EQ(err_str, expected_err); + } + } +} + +TEST(ObjCHelper, ParseSimple_RejectLinesNoMessage) { + const std::vector> tests = { + std::make_tuple("a\nb\nc", "a", 1), + std::make_tuple("a\nb\nc", "b", 2), + std::make_tuple("a\nb\nc", "c", 3), + std::make_tuple("a\nb\nc\n", "c", 3), + }; + + for (const auto& test : tests) { + for (int i = 0; i < kBlockSizeCount; i++) { + io::ArrayInputStream input(std::get<0>(test).data(), std::get<0>(test).size(), + kBlockSizes[i]); + std::string err_str; + TestLineCollector collector(nullptr, &std::get<1>(test), true /* skip msg */); + EXPECT_FALSE(ParseSimpleStream(input, "dummy", &collector, &err_str)); + std::string expected_err = + StrCat("error: dummy Line ", std::get<2>(test), + ", ConsumeLine failed without setting an error."); + EXPECT_EQ(err_str, expected_err); + } + } +} + +// TODO(thomasvl): Should probably add some unittests for all the special cases +// of name mangling (class name, field name, enum names). Rather than doing +// this with an ObjC test in the objectivec directory, we should be able to +// use src/google/protobuf/compiler/importer* (like other tests) to support a +// virtual file system to feed in protos, once we have the Descriptor tree, the +// tests could use the helper methods for generating names and validate the +// right things are happening. + } // namespace } // namespace objectivec } // namespace compiler } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc similarity index 89% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc index 0c6acb3..99d7581 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc @@ -28,14 +28,12 @@ // (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/compiler/objectivec/map_field.h" - #include #include -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include namespace google { namespace protobuf { @@ -85,7 +83,8 @@ const char* MapEntryTypeName(const FieldDescriptor* descriptor, bool isKey) { MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor) : RepeatedFieldGenerator(descriptor) { - const FieldDescriptor* key_descriptor = descriptor->message_type()->map_key(); + const FieldDescriptor* key_descriptor = + descriptor->message_type()->map_key(); const FieldDescriptor* value_descriptor = descriptor->message_type()->map_value(); value_field_generator_.reset(FieldGenerator::Make(value_descriptor)); @@ -135,8 +134,8 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor) variables_["array_storage_type"] = class_name; if (value_is_object_type) { variables_["array_property_type"] = - class_name + "<" + value_field_generator_->variable("storage_type") + - "*>"; + class_name + "<" + + value_field_generator_->variable("storage_type") + "*>"; } } @@ -156,15 +155,15 @@ void MapFieldGenerator::FinishInitialization(void) { descriptor_->message_type()->map_value(); if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_ENUM) { variables_["array_comment"] = - "// |" + variables_["name"] + "| values are |" + - value_field_generator_->variable("storage_type") + "|\n"; + "// |" + variables_["name"] + "| values are |" + value_field_generator_->variable("storage_type") + "|\n"; } } void MapFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { - RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls, - include_external_types); + std::set* fwd_decls, + bool include_external_types) const { + RepeatedFieldGenerator::DetermineForwardDeclarations( + fwd_decls, include_external_types); const FieldDescriptor* value_descriptor = descriptor_->message_type()->map_value(); // Within a file there is no requirement on the order of the messages, so @@ -186,8 +185,8 @@ void MapFieldGenerator::DetermineObjectiveCClassDefinitions( const FieldDescriptor* value_descriptor = descriptor_->message_type()->map_value(); if (GetObjectiveCType(value_descriptor) == OBJECTIVECTYPE_MESSAGE) { - fwd_decls->insert( - ObjCClassDeclaration(value_field_generator_->variable("storage_type"))); + fwd_decls->insert(ObjCClassDeclaration( + value_field_generator_->variable("storage_type"))); } } diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h similarity index 97% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h index bea9f6d..d9aa387 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/map_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h @@ -33,8 +33,7 @@ #include #include - -#include "google/protobuf/compiler/objectivec/field.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/message.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc similarity index 87% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/message.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc index a68aa60..4ebb75c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/message.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -28,21 +28,20 @@ // (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/compiler/objectivec/message.h" - #include #include #include -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/enum.h" -#include "google/protobuf/compiler/objectivec/extension.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/compiler/objectivec/text_format_decode_data.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -50,11 +49,6 @@ namespace compiler { namespace objectivec { namespace { - -bool IsMapEntryMessage(const Descriptor* descriptor) { - return descriptor->options().map_entry(); -} - struct FieldOrderingByNumber { inline bool operator()(const FieldDescriptor* a, const FieldDescriptor* b) const { @@ -152,12 +146,11 @@ struct ExtensionRangeOrdering { // and return it. const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { const FieldDescriptor** fields = - new const FieldDescriptor*[descriptor->field_count()]; + new const FieldDescriptor* [descriptor->field_count()]; for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } - std::sort(fields, fields + descriptor->field_count(), - FieldOrderingByNumber()); + std::sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber()); return fields; } @@ -165,15 +158,14 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) { // array and return it. const FieldDescriptor** SortFieldsByStorageSize(const Descriptor* descriptor) { const FieldDescriptor** fields = - new const FieldDescriptor*[descriptor->field_count()]; + new const FieldDescriptor* [descriptor->field_count()]; for (int i = 0; i < descriptor->field_count(); i++) { fields[i] = descriptor->field(i); } std::sort(fields, fields + descriptor->field_count(), - FieldOrderingByStorageSize()); + FieldOrderingByStorageSize()); return fields; } - } // namespace MessageGenerator::MessageGenerator(const std::string& root_classname, @@ -201,7 +193,8 @@ MessageGenerator::MessageGenerator(const std::string& root_classname, for (int i = 0; i < descriptor_->nested_type_count(); i++) { MessageGenerator* generator = - new MessageGenerator(root_classname_, descriptor_->nested_type(i)); + new MessageGenerator(root_classname_, + descriptor_->nested_type(i)); nested_message_generators_.emplace_back(generator); } } @@ -220,7 +213,8 @@ void MessageGenerator::GenerateStaticVariablesInitialization( } void MessageGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) { + std::set* fwd_decls, + bool include_external_types) { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); @@ -304,18 +298,16 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { } printer->Print( - // clang-format off "#pragma mark - $classname$\n" "\n", - // clang-format on "classname", class_name_); if (descriptor_->field_count()) { std::unique_ptr sorted_fields( SortFieldsByNumber(descriptor_)); - printer->Print("typedef GPB_ENUM($classname$_FieldNumber) {\n", "classname", - class_name_); + printer->Print("typedef GPB_ENUM($classname$_FieldNumber) {\n", + "classname", class_name_); printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -340,10 +332,9 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { } printer->Print( - // clang-format off "$comments$$deprecated_attribute$GPB_FINAL @interface $classname$ : GPBMessage\n\n", - // clang-format on - "classname", class_name_, "deprecated_attribute", deprecated_attribute_, + "classname", class_name_, + "deprecated_attribute", deprecated_attribute_, "comments", message_comments); std::vector seen_oneofs(oneof_generators_.size(), 0); @@ -376,8 +367,8 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { } if (descriptor_->extension_count() > 0) { - printer->Print("@interface $classname$ (DynamicMethods)\n\n", "classname", - class_name_); + printer->Print("@interface $classname$ (DynamicMethods)\n\n", + "classname", class_name_); for (const auto& generator : extension_generators_) { generator->GenerateMembersHeader(printer); } @@ -392,23 +383,20 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { void MessageGenerator::GenerateSource(io::Printer* printer) { if (!IsMapEntryMessage(descriptor_)) { printer->Print( - // clang-format off "#pragma mark - $classname$\n" "\n", - // clang-format on "classname", class_name_); if (!deprecated_attribute_.empty()) { // No warnings when compiling the impl of this deprecated class. - // clang-format off printer->Print( "#pragma clang diagnostic push\n" "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n" "\n"); - // clang-format on } - printer->Print("@implementation $classname$\n\n", "classname", class_name_); + printer->Print("@implementation $classname$\n\n", + "classname", class_name_); for (const auto& generator : oneof_generators_) { generator->GeneratePropertyImplementation(printer); @@ -431,7 +419,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { } std::sort(sorted_extensions.begin(), sorted_extensions.end(), - ExtensionRangeOrdering()); + ExtensionRangeOrdering()); // Assign has bits: // 1. FieldGeneratorMap::CalculateHasBits() loops through the fields seeing @@ -457,13 +445,11 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { sizeof_has_storage += oneof_generators_.size(); printer->Print( - // clang-format off "\n" "typedef struct $classname$__storage_ {\n" " uint32_t _has_storage_[$sizeof_has_storage$];\n", - // clang-format on - "classname", class_name_, "sizeof_has_storage", - absl::StrCat(sizeof_has_storage)); + "classname", class_name_, + "sizeof_has_storage", StrCat(sizeof_has_storage)); printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -474,14 +460,13 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { printer->Print("} $classname$__storage_;\n\n", "classname", class_name_); - // clang-format off + printer->Print( "// This method is threadsafe because it is initially called\n" "// in +initialize for each subclass.\n" "+ (GPBDescriptor *)descriptor {\n" " static GPBDescriptor *descriptor = nil;\n" " if (!descriptor) {\n"); - // clang-format on TextFormatDecodeData text_format_decode_data; bool has_fields = descriptor_->field_count() > 0; @@ -495,21 +480,23 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { if (has_fields) { printer->Indent(); printer->Indent(); - printer->Print("static $field_description_type$ fields[] = {\n", - "field_description_type", field_description_type); + printer->Print( + "static $field_description_type$ fields[] = {\n", + "field_description_type", field_description_type); printer->Indent(); for (int i = 0; i < descriptor_->field_count(); ++i) { const FieldGenerator& field_generator = field_generators_.get(sorted_fields[i]); field_generator.GenerateFieldDescription(printer, need_defaults); if (field_generator.needs_textformat_name_support()) { - text_format_decode_data.AddString( - sorted_fields[i]->number(), field_generator.generated_objc_name(), - field_generator.raw_field_name()); + text_format_decode_data.AddString(sorted_fields[i]->number(), + field_generator.generated_objc_name(), + field_generator.raw_field_name()); } } printer->Outdent(); - printer->Print("};\n"); + printer->Print( + "};\n"); printer->Outdent(); printer->Outdent(); } @@ -534,10 +521,9 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { if (descriptor_->options().message_set_wire_format()) { init_flags.push_back("GPBDescriptorInitializationFlag_WireFormat"); } - vars["init_flags"] = - BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION, init_flags); + vars["init_flags"] = BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION, + init_flags); - // clang-format off printer->Print( vars, " GPBDescriptor *localDescriptor =\n" @@ -548,63 +534,55 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " fieldCount:$fields_count$\n" " storageSize:sizeof($classname$__storage_)\n" " flags:$init_flags$];\n"); - // clang-format on if (!oneof_generators_.empty()) { - printer->Print(" static const char *oneofs[] = {\n"); + printer->Print( + " static const char *oneofs[] = {\n"); for (const auto& generator : oneof_generators_) { printer->Print(" \"$name$\",\n", "name", generator->DescriptorName()); } printer->Print( - // clang-format off " };\n" " [localDescriptor setupOneofs:oneofs\n" " count:(uint32_t)(sizeof(oneofs) / sizeof(char*))\n" " firstHasIndex:$first_has_index$];\n", - // clang-format on "first_has_index", oneof_generators_[0]->HasIndexAsString()); } if (text_format_decode_data.num_entries() != 0) { const std::string text_format_data_str(text_format_decode_data.Data()); - // clang-format off printer->Print( "#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n" " static const char *extraTextFormatInfo ="); - // clang-format on static const int kBytesPerLine = 40; // allow for escaping for (int i = 0; i < text_format_data_str.size(); i += kBytesPerLine) { - printer->Print("\n \"$data$\"", "data", - EscapeTrigraphs(absl::CEscape( - text_format_data_str.substr(i, kBytesPerLine)))); + printer->Print( + "\n \"$data$\"", + "data", EscapeTrigraphs( + CEscape(text_format_data_str.substr(i, kBytesPerLine)))); } - // clang-format off printer->Print( ";\n" " [localDescriptor setupExtraTextInfo:extraTextFormatInfo];\n" "#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n"); - // clang-format on } if (!sorted_extensions.empty()) { - printer->Print(" static const GPBExtensionRange ranges[] = {\n"); + printer->Print( + " static const GPBExtensionRange ranges[] = {\n"); for (int i = 0; i < sorted_extensions.size(); i++) { - printer->Print(" { .start = $start$, .end = $end$ },\n", "start", - absl::StrCat(sorted_extensions[i]->start), "end", - absl::StrCat(sorted_extensions[i]->end)); + printer->Print(" { .start = $start$, .end = $end$ },\n", + "start", StrCat(sorted_extensions[i]->start), + "end", StrCat(sorted_extensions[i]->end)); } - // clang-format off printer->Print( " };\n" " [localDescriptor setupExtensionRanges:ranges\n" " count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];\n"); - // clang-format on } if (descriptor_->containing_type() != NULL) { std::string containing_class = ClassName(descriptor_->containing_type()); std::string parent_class_ref = ObjCClass(containing_class); printer->Print( - // clang-format off " [localDescriptor setupContainingMessageClass:$parent_class_ref$];\n", - // clang-format on "parent_class_ref", parent_class_ref); } std::string suffix_added; @@ -614,7 +592,6 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n", "suffix", suffix_added); } - // clang-format off printer->Print( " #if defined(DEBUG) && DEBUG\n" " NSAssert(descriptor == nil, @\"Startup recursed!\");\n" @@ -624,14 +601,11 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { " return descriptor;\n" "}\n\n" "@end\n\n"); - // clang-format on if (!deprecated_attribute_.empty()) { - // clang-format off printer->Print( "#pragma clang diagnostic pop\n" "\n"); - // clang-format on } for (int i = 0; i < descriptor_->field_count(); i++) { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/message.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h similarity index 94% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/message.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h index 137f35a..9d14430 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/message.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -31,14 +31,13 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_MESSAGE_H__ -#include #include +#include #include - -#include "google/protobuf/compiler/objectivec/field.h" -#include "google/protobuf/compiler/objectivec/oneof.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc similarity index 82% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index 62e6281..2ff0b44 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -28,14 +28,12 @@ // (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/compiler/objectivec/message_field.h" - #include #include -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include namespace google { namespace protobuf { @@ -67,14 +65,15 @@ MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor) MessageFieldGenerator::~MessageFieldGenerator() {} void MessageFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { - ObjCObjFieldGenerator::DetermineForwardDeclarations(fwd_decls, - include_external_types); + std::set* fwd_decls, + bool include_external_types) const { + ObjCObjFieldGenerator::DetermineForwardDeclarations( + fwd_decls, include_external_types); // Within a file there is no requirement on the order of the messages, so // local references need a forward declaration. External files (not WKTs), // need one when requested. - if ((include_external_types && !IsProtobufLibraryBundledProtoFile( - descriptor_->message_type()->file())) || + if ((include_external_types && + !IsProtobufLibraryBundledProtoFile(descriptor_->message_type()->file())) || descriptor_->file() == descriptor_->message_type()->file()) { // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); @@ -98,14 +97,15 @@ RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator( RepeatedMessageFieldGenerator::~RepeatedMessageFieldGenerator() {} void RepeatedMessageFieldGenerator::DetermineForwardDeclarations( - std::set* fwd_decls, bool include_external_types) const { - RepeatedFieldGenerator::DetermineForwardDeclarations(fwd_decls, - include_external_types); + std::set* fwd_decls, + bool include_external_types) const { + RepeatedFieldGenerator::DetermineForwardDeclarations( + fwd_decls, include_external_types); // Within a file there is no requirement on the order of the messages, so // local references need a forward declaration. External files (not WKTs), // need one when requested. - if ((include_external_types && !IsProtobufLibraryBundledProtoFile( - descriptor_->message_type()->file())) || + if ((include_external_types && + !IsProtobufLibraryBundledProtoFile(descriptor_->message_type()->file())) || descriptor_->file() == descriptor_->message_type()->file()) { // Class name is already in "storage_type". fwd_decls->insert("@class " + variable("storage_type")); diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h similarity index 95% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h index 90ff3ab..49a84fb 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/message_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h @@ -33,8 +33,7 @@ #include #include - -#include "google/protobuf/compiler/objectivec/field.h" +#include namespace google { namespace protobuf { @@ -68,8 +67,7 @@ class RepeatedMessageFieldGenerator : public RepeatedFieldGenerator { virtual ~RepeatedMessageFieldGenerator(); RepeatedMessageFieldGenerator(const RepeatedMessageFieldGenerator&) = delete; - RepeatedMessageFieldGenerator operator=( - const RepeatedMessageFieldGenerator&) = delete; + RepeatedMessageFieldGenerator operator=(const RepeatedMessageFieldGenerator&) = delete; public: virtual void DetermineForwardDeclarations( diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h new file mode 100644 index 0000000..1633046 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_nsobject_methods.h @@ -0,0 +1,197 @@ +// NSObject methods +// Autogenerated by method_dump.sh. Do not edit by hand. +// Date: Thu Nov 1 14:12:16 PDT 2018 +// macOS: MacOSX10.14.sdk +// iOS: iPhoneSimulator12.1.sdk + +const char* const kNSObjectMethodsList[] = { + "CAMLType", + "CA_copyRenderValue", + "CA_prepareRenderValue", + "NS_copyCGImage", + "NS_tiledLayerVisibleRect", + "___tryRetain_OA", + "__autorelease_OA", + "__dealloc_zombie", + "__release_OA", + "__retain_OA", + "_accessibilityFinalize", + "_accessibilityIsTableViewDescendant", + "_accessibilityUIElementSpecifier", + "_accessibilityUseConvenienceAPI", + "_allowsDirectEncoding", + "_asScriptTerminologyNameArray", + "_asScriptTerminologyNameString", + "_bindingAdaptor", + "_cfTypeID", + "_copyDescription", + "_destroyObserverList", + "_didEndKeyValueObserving", + "_implicitObservationInfo", + "_internalAccessibilityAttributedHint", + "_internalAccessibilityAttributedLabel", + "_internalAccessibilityAttributedValue", + "_isAXConnector", + "_isAccessibilityContainerSectionCandidate", + "_isAccessibilityContentNavigatorSectionCandidate", + "_isAccessibilityContentSectionCandidate", + "_isAccessibilityTopLevelNavigatorSectionCandidate", + "_isDeallocating", + "_isKVOA", + "_isToManyChangeInformation", + "_ivarDescription", + "_localClassNameForClass", + "_methodDescription", + "_observerStorage", + "_overrideUseFastBlockObservers", + "_propertyDescription", + "_releaseBindingAdaptor", + "_scriptingCount", + "_scriptingCountNonrecursively", + "_scriptingDebugDescription", + "_scriptingExists", + "_scriptingShouldCheckObjectIndexes", + "_shortMethodDescription", + "_shouldSearchChildrenForSection", + "_traitStorageList", + "_tryRetain", + "_ui_descriptionBuilder", + "_uikit_variesByTraitCollections", + "_web_description", + "_webkit_invokeOnMainThread", + "_willBeginKeyValueObserving", + "accessibilityActivate", + "accessibilityActivationPoint", + "accessibilityAllowsOverriddenAttributesWhenIgnored", + "accessibilityAssistiveTechnologyFocusedIdentifiers", + "accessibilityAttributedHint", + "accessibilityAttributedLabel", + "accessibilityAttributedValue", + "accessibilityContainer", + "accessibilityContainerType", + "accessibilityCustomActions", + "accessibilityCustomRotors", + "accessibilityDecrement", + "accessibilityDragSourceDescriptors", + "accessibilityDropPointDescriptors", + "accessibilityElementCount", + "accessibilityElementDidBecomeFocused", + "accessibilityElementDidLoseFocus", + "accessibilityElementIsFocused", + "accessibilityElements", + "accessibilityElementsHidden", + "accessibilityFrame", + "accessibilityHeaderElements", + "accessibilityHint", + "accessibilityIdentification", + "accessibilityIdentifier", + "accessibilityIncrement", + "accessibilityLabel", + "accessibilityLanguage", + "accessibilityLocalizedStringKey", + "accessibilityNavigationStyle", + "accessibilityOverriddenAttributes", + "accessibilityParameterizedAttributeNames", + "accessibilityPath", + "accessibilityPerformEscape", + "accessibilityPerformMagicTap", + "accessibilityPresenterProcessIdentifier", + "accessibilityShouldUseUniqueId", + "accessibilitySupportsNotifications", + "accessibilitySupportsOverriddenAttributes", + "accessibilityTemporaryChildren", + "accessibilityTraits", + "accessibilityValue", + "accessibilityViewIsModal", + "accessibilityVisibleArea", + "allPropertyKeys", + "allowsWeakReference", + "attributeKeys", + "autoContentAccessingProxy", + "autorelease", + "awakeFromNib", + "boolValueSafe", + "bs_encoded", + "bs_isPlistableType", + "bs_secureEncoded", + "cl_json_serializeKey", + "class", + "classCode", + "classDescription", + "classForArchiver", + "classForCoder", + "classForKeyedArchiver", + "classForPortCoder", + "className", + "clearProperties", + "copy", + "dealloc", + "debugDescription", + "defaultAccessibilityTraits", + "description", + "doubleValueSafe", + "entityName", + "exposedBindings", + "finalize", + "finishObserving", + "flushKeyBindings", + "hash", + "init", + "int64ValueSafe", + "isAccessibilityElement", + "isAccessibilityElementByDefault", + "isElementAccessibilityExposedToInterfaceBuilder", + "isFault", + "isNSArray__", + "isNSCFConstantString__", + "isNSData__", + "isNSDate__", + "isNSDictionary__", + "isNSNumber__", + "isNSObject__", + "isNSOrderedSet__", + "isNSSet__", + "isNSString__", + "isNSTimeZone__", + "isNSValue__", + "isProxy", + "mutableCopy", + "nilValueForKey", + "objectSpecifier", + "observationInfo", + "pep_onDetachedThread", + "pep_onMainThread", + "pep_onMainThreadIfNecessary", + "prepareForInterfaceBuilder", + "release", + "releaseOnMainThread", + "retain", + "retainCount", + "retainWeakReference", + "scriptingProperties", + "self", + "shouldGroupAccessibilityChildren", + "storedAccessibilityActivationPoint", + "storedAccessibilityContainerType", + "storedAccessibilityElementsHidden", + "storedAccessibilityFrame", + "storedAccessibilityNavigationStyle", + "storedAccessibilityTraits", + "storedAccessibilityViewIsModal", + "storedIsAccessibilityElement", + "storedShouldGroupAccessibilityChildren", + "stringValueSafe", + "superclass", + "toManyRelationshipKeys", + "toOneRelationshipKeys", + "traitStorageList", + "un_safeBoolValue", + "userInterfaceItemIdentifier", + "utf8ValueSafe", + "valuesForKeysWithDictionary", + "zone", +// Protocol: CAAnimatableValue +// Protocol: CARenderValue +// Protocol: NSObject +// Protocol: ROCKRemoteInvocationInterface +}; diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc similarity index 82% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc index 6fd934a..1bef293 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc @@ -28,15 +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. -#include "google/protobuf/compiler/objectivec/oneof.h" - #include #include -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -48,7 +46,7 @@ OneofGenerator::OneofGenerator(const OneofDescriptor* descriptor) variables_["enum_name"] = OneofEnumName(descriptor_); variables_["name"] = OneofName(descriptor_); variables_["capitalized_name"] = OneofNameCapitalized(descriptor_); - variables_["raw_index"] = absl::StrCat(descriptor_->index()); + variables_["raw_index"] = StrCat(descriptor_->index()); const Descriptor* msg_descriptor = descriptor_->containing_type(); variables_["owning_message_class"] = ClassName(msg_descriptor); @@ -67,57 +65,58 @@ OneofGenerator::~OneofGenerator() {} void OneofGenerator::SetOneofIndexBase(int index_base) { int index = descriptor_->index() + index_base; // Flip the sign to mark it as a oneof. - variables_["index"] = absl::StrCat(-index); + variables_["index"] = StrCat(-index); } void OneofGenerator::GenerateCaseEnum(io::Printer* printer) { - printer->Print(variables_, "typedef GPB_ENUM($enum_name$) {\n"); + printer->Print( + variables_, + "typedef GPB_ENUM($enum_name$) {\n"); printer->Indent(); - printer->Print(variables_, "$enum_name$_GPBUnsetOneOfCase = 0,\n"); + printer->Print( + variables_, + "$enum_name$_GPBUnsetOneOfCase = 0,\n"); std::string enum_name = variables_["enum_name"]; for (int j = 0; j < descriptor_->field_count(); j++) { const FieldDescriptor* field = descriptor_->field(j); std::string field_name = FieldNameCapitalized(field); - printer->Print("$enum_name$_$field_name$ = $field_number$,\n", "enum_name", - enum_name, "field_name", field_name, "field_number", - absl::StrCat(field->number())); + printer->Print( + "$enum_name$_$field_name$ = $field_number$,\n", + "enum_name", enum_name, + "field_name", field_name, + "field_number", StrCat(field->number())); } printer->Outdent(); - // clang-format off printer->Print( "};\n" "\n"); - // clang-format on } void OneofGenerator::GeneratePublicCasePropertyDeclaration( io::Printer* printer) { - // clang-format off printer->Print( variables_, "$comments$" "@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;\n" "\n"); - // clang-format on } void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { - // clang-format off printer->Print( variables_, "/**\n" " * Clears whatever value was set for the oneof '$name$'.\n" " **/\n" "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message);\n"); - // clang-format on } void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) { - printer->Print(variables_, "@dynamic $name$OneOfCase;\n"); + printer->Print( + variables_, + "@dynamic $name$OneOfCase;\n"); } void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { - // clang-format off printer->Print( variables_, "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message) {\n" @@ -125,7 +124,6 @@ void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { " GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:$raw_index$];\n" " GPBClearOneof(message, oneof);\n" "}\n"); - // clang-format on } std::string OneofGenerator::DescriptorName(void) const { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h similarity index 97% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h index c89cdd9..034f07f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/oneof.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h @@ -31,12 +31,11 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__ -#include #include +#include #include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/io/printer.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc similarity index 93% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.cc rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index b6a44d2..1fefde5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.cc +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -28,15 +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. -#include "google/protobuf/compiler/objectivec/primitive_field.h" - #include #include -#include "absl/strings/str_cat.h" -#include "google/protobuf/compiler/objectivec/helpers.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/printer.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -72,7 +70,7 @@ const char* PrimitiveTypeName(const FieldDescriptor* descriptor) { case OBJECTIVECTYPE_ENUM: return "int32_t"; case OBJECTIVECTYPE_MESSAGE: - return NULL; // Messages go through message_field.cc|h. + return NULL; // Messages go through objectivec_message_field.cc|h. } // Some compilers report reaching end of function even though all cases of @@ -105,7 +103,7 @@ const char* PrimitiveArrayTypeName(const FieldDescriptor* descriptor) { case OBJECTIVECTYPE_ENUM: return "Enum"; case OBJECTIVECTYPE_MESSAGE: - // Want NSArray (but goes through message_field.cc|h). + // Want NSArray (but goes through objectivec_message_field.cc|h). return ""; } @@ -152,7 +150,7 @@ int PrimitiveFieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { void PrimitiveFieldGenerator::SetExtraRuntimeHasBitsBase(int has_base) { if (GetObjectiveCType(descriptor_) == OBJECTIVECTYPE_BOOLEAN) { // Set into the offset the has bit to use for the actual value. - variables_["storage_offset_value"] = absl::StrCat(has_base); + variables_["storage_offset_value"] = StrCat(has_base); variables_["storage_offset_comment"] = " // Stored in _has_storage_ to save space."; } diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h similarity index 95% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.h rename to libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h index 5d509d2..06a1528 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/primitive_field.h +++ b/libs/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h @@ -31,7 +31,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ -#include "google/protobuf/compiler/objectivec/field.h" +#include namespace google { namespace protobuf { @@ -48,8 +48,7 @@ class PrimitiveFieldGenerator : public SingleFieldGenerator { PrimitiveFieldGenerator(const PrimitiveFieldGenerator&) = delete; PrimitiveFieldGenerator& operator=(const PrimitiveFieldGenerator&) = delete; - virtual void GenerateFieldStorageDeclaration( - io::Printer* printer) const override; + virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const override; virtual int ExtraRuntimeHasBitsNeeded(void) const override; virtual void SetExtraRuntimeHasBitsBase(int index_base) override; diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc b/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc deleted file mode 100644 index 3bc4eef..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.cc +++ /dev/null @@ -1,267 +0,0 @@ -// 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/compiler/objectivec/text_format_decode_data.h" - -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/objectivec/names.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" - -// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some -// error cases, so it seems to be ok to use as a back door for errors. - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -namespace { - -// Helper to build up the decode data for a string. -class DecodeDataBuilder { - public: - DecodeDataBuilder() { Reset(); } - - bool AddCharacter(const char desired, const char input); - void AddUnderscore() { - Push(); - need_underscore_ = true; - } - std::string Finish() { - Push(); - return decode_data_; - } - - private: - static constexpr uint8_t kAddUnderscore = 0x80; - - static constexpr uint8_t kOpAsIs = 0x00; - static constexpr uint8_t kOpFirstUpper = 0x40; - static constexpr uint8_t kOpFirstLower = 0x20; - static constexpr uint8_t kOpAllUpper = 0x60; - - static constexpr int kMaxSegmentLen = 0x1f; - - void AddChar(const char desired) { - ++segment_len_; - is_all_upper_ &= absl::ascii_isupper(desired); - } - - void Push() { - uint8_t op = (op_ | segment_len_); - if (need_underscore_) op |= kAddUnderscore; - if (op != 0) { - decode_data_ += (char)op; - } - Reset(); - } - - bool AddFirst(const char desired, const char input) { - if (desired == input) { - op_ = kOpAsIs; - } else if (desired == absl::ascii_toupper(input)) { - op_ = kOpFirstUpper; - } else if (desired == absl::ascii_tolower(input)) { - op_ = kOpFirstLower; - } else { - // Can't be transformed to match. - return false; - } - AddChar(desired); - return true; - } - - void Reset() { - need_underscore_ = false; - op_ = 0; - segment_len_ = 0; - is_all_upper_ = true; - } - - bool need_underscore_; - bool is_all_upper_; - uint8_t op_; - int segment_len_; - - std::string decode_data_; -}; - -bool DecodeDataBuilder::AddCharacter(const char desired, const char input) { - // If we've hit the max size, push to start a new segment. - if (segment_len_ == kMaxSegmentLen) { - Push(); - } - if (segment_len_ == 0) { - return AddFirst(desired, input); - } - - // Desired and input match... - if (desired == input) { - // If we aren't transforming it, or we're upper casing it and it is - // supposed to be uppercase; just add it to the segment. - if ((op_ != kOpAllUpper) || absl::ascii_isupper(desired)) { - AddChar(desired); - return true; - } - - // Add the current segment, and start the next one. - Push(); - return AddFirst(desired, input); - } - - // If we need to uppercase, and everything so far has been uppercase, - // promote op to AllUpper. - if ((desired == absl::ascii_toupper(input)) && is_all_upper_) { - op_ = kOpAllUpper; - AddChar(desired); - return true; - } - - // Give up, push and start a new segment. - Push(); - return AddFirst(desired, input); -} - -// If decode data can't be generated, a directive for the raw string -// is used instead. -std::string DirectDecodeString(const std::string& str) { - std::string result; - result += (char)'\0'; // Marker for full string. - result += str; - result += (char)'\0'; // End of string. - return result; -} - -} // namespace - -TextFormatDecodeData::TextFormatDecodeData() {} - -TextFormatDecodeData::~TextFormatDecodeData() {} - -void TextFormatDecodeData::AddString(int32_t key, - const std::string& input_for_decode, - const std::string& desired_output) { - for (std::vector::const_iterator i = entries_.begin(); - i != entries_.end(); ++i) { - if (i->first == key) { - std::cerr << "error: duplicate key (" << key - << ") making TextFormat data, input: \"" << input_for_decode - << "\", desired: \"" << desired_output << "\"." << std::endl; - std::cerr.flush(); - abort(); - } - } - - const std::string& data = TextFormatDecodeData::DecodeDataForString( - input_for_decode, desired_output); - entries_.push_back(DataEntry(key, data)); -} - -std::string TextFormatDecodeData::Data() const { - std::ostringstream data_stringstream; - - if (num_entries() > 0) { - io::OstreamOutputStream data_outputstream(&data_stringstream); - io::CodedOutputStream output_stream(&data_outputstream); - - output_stream.WriteVarint32(num_entries()); - for (std::vector::const_iterator i = entries_.begin(); - i != entries_.end(); ++i) { - output_stream.WriteVarint32(i->first); - output_stream.WriteString(i->second); - } - } - - data_stringstream.flush(); - return data_stringstream.str(); -} - -// static -std::string TextFormatDecodeData::DecodeDataForString( - const std::string& input_for_decode, const std::string& desired_output) { - if (input_for_decode.empty() || desired_output.empty()) { - std::cerr << "error: got empty string for making TextFormat data, input: \"" - << input_for_decode << "\", desired: \"" << desired_output - << "\"." << std::endl; - std::cerr.flush(); - abort(); - } - if ((input_for_decode.find('\0') != std::string::npos) || - (desired_output.find('\0') != std::string::npos)) { - std::cerr - << "error: got a null char in a string for making TextFormat data," - << " input: \"" << absl::CEscape(input_for_decode) << "\", desired: \"" - << absl::CEscape(desired_output) << "\"." << std::endl; - std::cerr.flush(); - abort(); - } - - DecodeDataBuilder builder; - - // Walk the output building it from the input. - int x = 0; - for (int y = 0; y < desired_output.size(); y++) { - const char d = desired_output[y]; - if (d == '_') { - builder.AddUnderscore(); - continue; - } - - if (x >= input_for_decode.size()) { - // Out of input, no way to encode it, just return a full decode. - return DirectDecodeString(desired_output); - } - if (builder.AddCharacter(d, input_for_decode[x])) { - ++x; // Consumed one input - } else { - // Couldn't transform for the next character, just return a full decode. - return DirectDecodeString(desired_output); - } - } - - if (x != input_for_decode.size()) { - // Extra input (suffix from name sanitizing?), just return a full decode. - return DirectDecodeString(desired_output); - } - - // Add the end marker. - return builder.Finish() + (char)'\0'; -} - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.h b/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.h deleted file mode 100644 index 280d65a..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/text_format_decode_data.h +++ /dev/null @@ -1,78 +0,0 @@ -// 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_COMPILER_OBJECTIVEC_TEXT_FORMAT_DECODE_DATA_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_TEXT_FORMAT_DECODE_DATA_H__ - -#include -#include - -// Must be included last -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// TODO(b/250947994): PROTOC_EXPORT is only used to allow the CMake build to -// find/link these in the unittest, this is not public api. - -// Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform -// the input into the expected output. -class PROTOC_EXPORT TextFormatDecodeData { - public: - TextFormatDecodeData(); - ~TextFormatDecodeData(); - - TextFormatDecodeData(const TextFormatDecodeData&) = delete; - TextFormatDecodeData& operator=(const TextFormatDecodeData&) = delete; - - void AddString(int32_t key, const std::string& input_for_decode, - const std::string& desired_output); - size_t num_entries() const { return entries_.size(); } - std::string Data() const; - - static std::string DecodeDataForString(const std::string& input_for_decode, - const std::string& desired_output); - - private: - typedef std::pair DataEntry; - std::vector entries_; -}; - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_TEXT_FORMAT_DECODE_DATA_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/parser.cc b/libs/protobuf/src/google/protobuf/compiler/parser.cc index 625281d..5bd37d1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/parser.cc +++ b/libs/protobuf/src/google/protobuf/compiler/parser.cc @@ -34,36 +34,33 @@ // // Recursive descent FTW. -#include "google/protobuf/compiler/parser.h" +#include #include #include #include -#include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/base/casts.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/port.h" -#include "google/protobuf/wire_format.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { -namespace { -using ::google::protobuf::internal::DownCast; +using internal::WireFormat; + +namespace { typedef std::unordered_map TypeNameMap; @@ -289,16 +286,6 @@ bool Parser::ConsumeInteger64(uint64_t max_value, uint64_t* output, } } -bool Parser::TryConsumeInteger64(uint64_t max_value, uint64_t* output) { - if (LookingAtType(io::Tokenizer::TYPE_INTEGER) && - io::Tokenizer::ParseInteger(input_->current().text, max_value, - output)) { - input_->Next(); - return true; - } - return false; -} - bool Parser::ConsumeNumber(double* output, const char* error) { if (LookingAtType(io::Tokenizer::TYPE_FLOAT)) { *output = io::Tokenizer::ParseFloat(input_->current().text); @@ -307,19 +294,13 @@ bool Parser::ConsumeNumber(double* output, const char* error) { } else if (LookingAtType(io::Tokenizer::TYPE_INTEGER)) { // Also accept integers. uint64_t value = 0; - if (io::Tokenizer::ParseInteger(input_->current().text, + if (!io::Tokenizer::ParseInteger(input_->current().text, std::numeric_limits::max(), &value)) { - *output = value; - } else if (input_->current().text[0] == '0') { - // octal or hexadecimal; don't bother parsing as float - AddError("Integer out of range."); - // We still return true because we did, in fact, parse a number. - } else if (!io::Tokenizer::TryParseFloat(input_->current().text, output)) { - // out of int range, and not valid float? 🤷 AddError("Integer out of range."); // We still return true because we did, in fact, parse a number. } + *output = value; input_->Next(); return true; } else if (LookingAt("inf")) { @@ -406,14 +387,11 @@ void Parser::AddError(const std::string& error) { AddError(input_->current().line, input_->current().column, error); } -void Parser::AddWarning(int line, int column, const std::string& warning) { - if (error_collector_ != nullptr) { - error_collector_->AddWarning(line, column, warning); - } -} - void Parser::AddWarning(const std::string& warning) { - AddWarning(input_->current().line, input_->current().column, warning); + if (error_collector_ != nullptr) { + error_collector_->AddWarning(input_->current().line, + input_->current().column, warning); + } } // ------------------------------------------------------------------- @@ -656,17 +634,14 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) { root_location.RecordLegacyLocation(file, DescriptorPool::ErrorCollector::OTHER); - if (require_syntax_identifier_ || LookingAt("syntax") - ) { + if (require_syntax_identifier_ || LookingAt("syntax")) { if (!ParseSyntaxIdentifier(root_location)) { // Don't attempt to parse the file if we didn't recognize the syntax // identifier. return false; } // Store the syntax into the file. - if (file != nullptr) { - file->set_syntax(syntax_identifier_); - } + if (file != nullptr) file->set_syntax(syntax_identifier_); } else if (!stop_after_syntax_identifier_) { GOOGLE_LOG(WARNING) << "No syntax specified for the proto file: " << file->name() << ". Please use 'syntax = \"proto2\";' " @@ -703,10 +678,9 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) { bool Parser::ParseSyntaxIdentifier(const LocationRecorder& parent) { LocationRecorder syntax_location(parent, FileDescriptorProto::kSyntaxFieldNumber); - DO(Consume("syntax", - "File must begin with a syntax statement, e.g. 'syntax = " - "\"proto2\";'.")); - + DO(Consume( + "syntax", + "File must begin with a syntax statement, e.g. 'syntax = \"proto2\";'.")); DO(Consume("=")); io::Tokenizer::Token syntax_token = input_->current(); std::string syntax; @@ -714,6 +688,7 @@ bool Parser::ParseSyntaxIdentifier(const LocationRecorder& parent) { DO(ConsumeEndOfDeclaration(";", &syntax_location)); syntax_identifier_ = syntax; + if (syntax != "proto2" && syntax != "proto3" && !stop_after_syntax_identifier_) { AddError(syntax_token.line, syntax_token.column, @@ -1109,7 +1084,7 @@ bool Parser::ParseMessageFieldNoLabel( AddError(name_token.line, name_token.column, "Group names must start with a capital letter."); } - absl::AsciiStrToLower(field->mutable_name()); + LowerString(field->mutable_name()); field->set_type_name(group->name()); if (LookingAt("{")) { @@ -1308,7 +1283,7 @@ bool Parser::ParseDefaultAssignment( DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. - default_value->append(absl::StrCat(value)); + default_value->append(StrCat(value)); break; } @@ -1331,24 +1306,24 @@ bool Parser::ParseDefaultAssignment( DO(ConsumeInteger64(max_value, &value, "Expected integer for field default value.")); // And stringify it again. - default_value->append(absl::StrCat(value)); + default_value->append(StrCat(value)); break; } case FieldDescriptorProto::TYPE_FLOAT: - case FieldDescriptorProto::TYPE_DOUBLE: { + case FieldDescriptorProto::TYPE_DOUBLE: // These types can be negative. if (TryConsume("-")) { default_value->append("-"); } // Parse the integer because we have to convert hex integers to decimal // floats. - double value = 0.0; + double value; DO(ConsumeNumber(&value, "Expected number.")); // And stringify it again. default_value->append(SimpleDtoa(value)); break; - } + case FieldDescriptorProto::TYPE_BOOL: if (TryConsume("true")) { default_value->assign("true"); @@ -1371,7 +1346,7 @@ bool Parser::ParseDefaultAssignment( case FieldDescriptorProto::TYPE_BYTES: DO(ConsumeString(default_value, "Expected string.")); - *default_value = absl::CEscape(*default_value); + *default_value = CEscape(*default_value); break; case FieldDescriptorProto::TYPE_ENUM: @@ -1499,7 +1474,7 @@ bool Parser::ParseOption(Message* options, } UninterpretedOption* uninterpreted_option = - DownCast(options->GetReflection()->AddMessage( + down_cast(options->GetReflection()->AddMessage( options, uninterpreted_option_field)); // Parse dot-separated name. @@ -1571,26 +1546,23 @@ bool Parser::ParseOption(Message* options, is_negative ? static_cast(std::numeric_limits::max()) + 1 : std::numeric_limits::max(); - if (TryConsumeInteger64(max_value, &value)) { - if (is_negative) { - value_location.AddPath( - UninterpretedOption::kNegativeIntValueFieldNumber); - uninterpreted_option->set_negative_int_value( - static_cast(0 - value)); - } else { - value_location.AddPath( - UninterpretedOption::kPositiveIntValueFieldNumber); - uninterpreted_option->set_positive_int_value(value); - } - break; + DO(ConsumeInteger64(max_value, &value, "Expected integer.")); + if (is_negative) { + value_location.AddPath( + UninterpretedOption::kNegativeIntValueFieldNumber); + uninterpreted_option->set_negative_int_value( + static_cast(0 - value)); + } else { + value_location.AddPath( + UninterpretedOption::kPositiveIntValueFieldNumber); + uninterpreted_option->set_positive_int_value(value); } - // value too large for an integer; fall through below to treat as floating point - ABSL_FALLTHROUGH_INTENDED; + break; } case io::Tokenizer::TYPE_FLOAT: { value_location.AddPath(UninterpretedOption::kDoubleValueFieldNumber); - double value = 0.0; + double value; DO(ConsumeNumber(&value, "Expected number.")); uninterpreted_option->set_double_value(is_negative ? -value : value); break; @@ -1751,23 +1723,11 @@ bool Parser::ParseReserved(DescriptorProto* message, } } -bool Parser::ParseReservedName(std::string* name, const char* error_message) { - // Capture the position of the token, in case we have to report an - // error after it is consumed. - int line = input_->current().line; - int col = input_->current().column; - DO(ConsumeString(name, error_message)); - if (!io::Tokenizer::IsIdentifier(*name)) { - AddWarning(line, col, absl::StrFormat("Reserved name \"%s\" is not a valid identifier.", *name)); - } - return true; -} - bool Parser::ParseReservedNames(DescriptorProto* message, const LocationRecorder& parent_location) { do { LocationRecorder location(parent_location, message->reserved_name_size()); - DO(ParseReservedName(message->add_reserved_name(), "Expected field name.")); + DO(ConsumeString(message->add_reserved_name(), "Expected field name.")); } while (TryConsume(",")); DO(ConsumeEndOfDeclaration(";", &parent_location)); return true; @@ -1822,42 +1782,42 @@ bool Parser::ParseReservedNumbers(DescriptorProto* message, return true; } -bool Parser::ParseReserved(EnumDescriptorProto* proto, - const LocationRecorder& enum_location) { +bool Parser::ParseReserved(EnumDescriptorProto* message, + const LocationRecorder& message_location) { io::Tokenizer::Token start_token = input_->current(); // Parse the declaration. DO(Consume("reserved")); if (LookingAtType(io::Tokenizer::TYPE_STRING)) { - LocationRecorder location(enum_location, + LocationRecorder location(message_location, EnumDescriptorProto::kReservedNameFieldNumber); location.StartAt(start_token); - return ParseReservedNames(proto, location); + return ParseReservedNames(message, location); } else { - LocationRecorder location(enum_location, + LocationRecorder location(message_location, EnumDescriptorProto::kReservedRangeFieldNumber); location.StartAt(start_token); - return ParseReservedNumbers(proto, location); + return ParseReservedNumbers(message, location); } } -bool Parser::ParseReservedNames(EnumDescriptorProto* proto, +bool Parser::ParseReservedNames(EnumDescriptorProto* message, const LocationRecorder& parent_location) { do { - LocationRecorder location(parent_location, proto->reserved_name_size()); - DO(ParseReservedName(proto->add_reserved_name(), "Expected enum value.")); + LocationRecorder location(parent_location, message->reserved_name_size()); + DO(ConsumeString(message->add_reserved_name(), "Expected enum value.")); } while (TryConsume(",")); DO(ConsumeEndOfDeclaration(";", &parent_location)); return true; } -bool Parser::ParseReservedNumbers(EnumDescriptorProto* proto, +bool Parser::ParseReservedNumbers(EnumDescriptorProto* message, const LocationRecorder& parent_location) { bool first = true; do { - LocationRecorder location(parent_location, proto->reserved_range_size()); + LocationRecorder location(parent_location, message->reserved_range_size()); EnumDescriptorProto::EnumReservedRange* range = - proto->add_reserved_range(); + message->add_reserved_range(); int start, end; io::Tokenizer::Token start_token; { @@ -2435,27 +2395,33 @@ bool SourceLocationTable::Find( const Message* descriptor, DescriptorPool::ErrorCollector::ErrorLocation location, int* line, int* column) const { - auto it = location_map_.find({descriptor, location}); - if (it == location_map_.end()) { + const std::pair* result = + FindOrNull(location_map_, std::make_pair(descriptor, location)); + if (result == nullptr) { *line = -1; *column = 0; return false; + } else { + *line = result->first; + *column = result->second; + return true; } - std::tie(*line, *column) = it->second; - return true; } bool SourceLocationTable::FindImport(const Message* descriptor, const std::string& name, int* line, int* column) const { - auto it = import_location_map_.find({descriptor, name}); - if (it == import_location_map_.end()) { + const std::pair* result = + FindOrNull(import_location_map_, std::make_pair(descriptor, name)); + if (result == nullptr) { *line = -1; *column = 0; return false; + } else { + *line = result->first; + *column = result->second; + return true; } - std::tie(*line, *column) = it->second; - return true; } void SourceLocationTable::Add( diff --git a/libs/protobuf/src/google/protobuf/compiler/parser.h b/libs/protobuf/src/google/protobuf/compiler/parser.h index cac3855..d4eb763 100644 --- a/libs/protobuf/src/google/protobuf/compiler/parser.h +++ b/libs/protobuf/src/google/protobuf/compiler/parser.h @@ -42,13 +42,13 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -71,8 +71,6 @@ class SourceLocationTable; class PROTOBUF_EXPORT Parser { public: Parser(); - Parser(const Parser&) = delete; - Parser& operator=(const Parser&) = delete; ~Parser(); // Parse the entire input and construct a FileDescriptorProto representing @@ -180,9 +178,6 @@ class PROTOBUF_EXPORT Parser { // is greater than max_value, an error will be reported. bool ConsumeInteger64(uint64_t max_value, uint64_t* output, const char* error); - // Try to consume a 64-bit integer and store its value in "output". No - // error is reported on failure, allowing caller to consume token another way. - bool TryConsumeInteger64(uint64_t max_value, uint64_t* output); // Consume a number and store its value in "output". This will accept // tokens of either INTEGER or FLOAT type. bool ConsumeNumber(double* output, const char* error); @@ -216,9 +211,6 @@ class PROTOBUF_EXPORT Parser { // of the current token. void AddError(const std::string& error); - // Invokes error_collector_->AddWarning(), if error_collector_ is not NULL. - void AddWarning(int line, int column, const std::string& warning); - // Invokes error_collector_->AddWarning() with the line and column number // of the current token. void AddWarning(const std::string& warning); @@ -400,7 +392,6 @@ class PROTOBUF_EXPORT Parser { const LocationRecorder& message_location); bool ParseReservedNames(DescriptorProto* message, const LocationRecorder& parent_location); - bool ParseReservedName(std::string* name, const char* error_message); bool ParseReservedNumbers(DescriptorProto* message, const LocationRecorder& parent_location); bool ParseReserved(EnumDescriptorProto* message, @@ -554,6 +545,8 @@ class PROTOBUF_EXPORT Parser { // the next element (See SourceCodeInfo.Location in descriptor.proto), when // ConsumeEndOfDeclaration() is called. std::vector upcoming_detached_comments_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); }; // A table mapping (descriptor, ErrorLocation) pairs -- as reported by @@ -604,6 +597,6 @@ class PROTOBUF_EXPORT SourceLocationTable { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/parser_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/parser_unittest.cc index 8260721..2d681d9 100644 --- a/libs/protobuf/src/google/protobuf/compiler/parser_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/parser_unittest.cc @@ -32,26 +32,26 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/compiler/parser.h" +#include #include #include #include #include -#include "google/protobuf/test_util2.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/any.pb.h" -#include "google/protobuf/unittest_custom_options.pb.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/text_format.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/str_join.h" -#include "absl/strings/substitute.h" +#include +#include namespace google { namespace protobuf { @@ -69,11 +69,11 @@ class MockErrorCollector : public io::ErrorCollector { // implements ErrorCollector --------------------------------------- void AddWarning(int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&warning_, "$0:$1: $2\n", line, column, message); + strings::SubstituteAndAppend(&warning_, "$0:$1: $2\n", line, column, message); } void AddError(int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message); + strings::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message); } }; @@ -147,16 +147,6 @@ class ParserTest : public testing::Test { EXPECT_EQ(io::Tokenizer::TYPE_END, input_->current().type); } - // Parse the text and expect that the given warnings are reported. - void ExpectHasWarnings(const char* text, const char* expected_warnings) { - SetupParser(text); - FileDescriptorProto file; - ASSERT_TRUE(parser_->Parse(input_.get(), &file)); - EXPECT_EQ(io::Tokenizer::TYPE_END, input_->current().type); - ASSERT_EQ("", error_collector_.text_); - EXPECT_EQ(expected_warnings, error_collector_.warning_); - } - // Same as above but does not expect that the parser parses the complete // input. void ExpectHasEarlyExitErrors(const char* text, const char* expected_errors) { @@ -274,7 +264,6 @@ TEST_F(ParserTest, WarnIfFieldNameContainsNumberImmediatelyFollowUnderscore) { "song_name_1.") != std::string::npos); } - // =================================================================== typedef ParserTest ParseMessageTest; @@ -602,56 +591,6 @@ TEST_F(ParseMessageTest, FieldOptions) { "}"); } -TEST_F(ParseMessageTest, FieldOptionsSupportLargeDecimalLiteral) { - // decimal integer literal > uint64 max - ExpectParsesTo( - "import \"google/protobuf/descriptor.proto\";\n" - "extend google.protobuf.FieldOptions {\n" - " optional double f = 10101;\n" - "}\n" - "message TestMessage {\n" - " optional double a = 1 [default = 18446744073709551616];\n" - " optional double b = 2 [default = -18446744073709551616];\n" - " optional double c = 3 [(f) = 18446744073709551616];\n" - " optional double d = 4 [(f) = -18446744073709551616];\n" - "}\n", - - "dependency: \"google/protobuf/descriptor.proto\"" - "extension {" - " name: \"f\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 10101" - " extendee: \"google.protobuf.FieldOptions\"" - "}" - "message_type {" - " name: \"TestMessage\"" - " field {" - " name: \"a\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 1" - " default_value: \"1.8446744073709552e+19\"" - " }" - " field {" - " name: \"b\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 2" - " default_value: \"-1.8446744073709552e+19\"" - " }" - " field {" - " name: \"c\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 3" - " options{" - " uninterpreted_option{" - " name{ name_part: \"f\" is_extension: true }" - " double_value: 1.8446744073709552e+19" - " }" - " }" - " }" - " field {" - " name: \"d\" label: LABEL_OPTIONAL type: TYPE_DOUBLE number: 4" - " options{" - " uninterpreted_option{" - " name{ name_part: \"f\" is_extension: true }" - " double_value: -1.8446744073709552e+19" - " }" - " }" - " }" - "}"); -} - TEST_F(ParseMessageTest, Oneof) { ExpectParsesTo( "message TestMessage {\n" @@ -1735,17 +1674,6 @@ TEST_F(ParseErrorTest, EnumReservedMissingQuotes) { "2:11: Expected enum value or number range.\n"); } -TEST_F(ParseErrorTest, EnumReservedInvalidIdentifier) { - ExpectHasWarnings( - R"pb( - enum TestEnum { - FOO = 1; - reserved "foo bar"; - } - )pb", - "3:17: Reserved name \"foo bar\" is not a valid identifier.\n"); -} - // ------------------------------------------------------------------- // Reserved field number errors @@ -1773,16 +1701,6 @@ TEST_F(ParseErrorTest, ReservedMissingQuotes) { "1:11: Expected field name or number range.\n"); } -TEST_F(ParseErrorTest, ReservedInvalidIdentifier) { - ExpectHasWarnings( - R"pb( - message Foo { - reserved "foo bar"; - } - )pb", - "2:17: Reserved name \"foo bar\" is not a valid identifier.\n"); -} - TEST_F(ParseErrorTest, ReservedNegativeNumber) { ExpectHasErrors( "message Foo {\n" @@ -1972,22 +1890,6 @@ TEST_F(ParserValidationErrorTest, FieldDefaultValueError) { "2:32: Enum type \"Baz\" has no value named \"NO_SUCH_VALUE\".\n"); } -TEST_F(ParserValidationErrorTest, FieldDefaultIntegerOutOfRange) { - ExpectHasErrors( - "message Foo {\n" - " optional double bar = 1 [default = 0x10000000000000000];\n" - "}\n", - "1:37: Integer out of range.\n"); -} - -TEST_F(ParserValidationErrorTest, FieldOptionOutOfRange) { - ExpectHasErrors( - "message Foo {\n" - " optional double bar = 1 [foo = 0x10000000000000000];\n" - "}\n", - "1:33: Integer out of range.\n"); -} - TEST_F(ParserValidationErrorTest, FileOptionNameError) { ExpectHasValidationErrors( "option foo = 5;", @@ -2499,7 +2401,7 @@ TEST_F(ParseDescriptorDebugTest, TestCommentsInDebugString) { const std::string debug_string = descriptor->DebugStringWithOptions(debug_string_options); - for (int i = 0; i < ABSL_ARRAYSIZE(expected_comments); ++i) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(expected_comments); ++i) { std::string::size_type found_pos = debug_string.find(expected_comments[i]); EXPECT_TRUE(found_pos != std::string::npos) @@ -2775,8 +2677,8 @@ class SourceInfoTest : public ParserTest { return true; } } else { - std::pair start_pos = markers_.at(start_marker); - std::pair end_pos = markers_.at(end_marker); + std::pair start_pos = FindOrDie(markers_, start_marker); + std::pair end_pos = FindOrDie(markers_, end_marker); RepeatedField expected_span; expected_span.Add(start_pos.first); @@ -2807,7 +2709,7 @@ class SourceInfoTest : public ParserTest { } else { EXPECT_EQ( expected_leading_detached_comments, - absl::StrJoin(iter->second->leading_detached_comments(), "\n")); + Join(iter->second->leading_detached_comments(), "\n")); } spans_.erase(iter); diff --git a/libs/protobuf/src/google/protobuf/compiler/php/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/php/BUILD.bazel deleted file mode 100644 index 3f8376f..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/php/BUILD.bazel +++ /dev/null @@ -1,59 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - PHP code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "names", - hdrs = ["names.h"], - srcs = ["names.cc"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/php", - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "php", - srcs = ["php_generator.cc"], - hdrs = ["php_generator.h"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/php", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - ":names", - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/strings", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/php/names.cc b/libs/protobuf/src/google/protobuf/compiler/php/names.cc deleted file mode 100644 index 20e169e..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/php/names.cc +++ /dev/null @@ -1,144 +0,0 @@ -// 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/compiler/php/names.h" - -#include - -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/plugin.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" - -const char* const kReservedNames[] = { - "abstract", "and", "array", "as", "break", - "callable", "case", "catch", "class", "clone", - "const", "continue", "declare", "default", "die", - "do", "echo", "else", "elseif", "empty", - "enddeclare", "endfor", "endforeach", "endif", "endswitch", - "endwhile", "eval", "exit", "extends", "final", - "finally", "fn", "for", "foreach", "function", - "global", "goto", "if", "implements", "include", - "include_once", "instanceof", "insteadof", "interface", "isset", - "list", "match", "namespace", "new", "or", - "parent", "print", "private", "protected", "public", - "readonly", "require", "require_once", "return", "self", - "static", "switch", "throw", "trait", "try", - "unset", "use", "var", "while", "xor", - "yield", "int", "float", "bool", "string", - "true", "false", "null", "void", "iterable"}; -const int kReservedNamesSize = 80; - -namespace google { -namespace protobuf { -namespace compiler { -namespace php { - -bool IsReservedName(absl::string_view name) { - std::string lower(name); - std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); - for (int i = 0; i < kReservedNamesSize; i++) { - if (lower == kReservedNames[i]) { - return true; - } - } - return false; -} - -std::string ReservedNamePrefix(const std::string& classname, - const FileDescriptor* file) { - if (IsReservedName(classname)) { - if (file->package() == "google.protobuf") { - return "GPB"; - } else { - return "PB"; - } - } - - return ""; -} - -namespace { - -template -std::string ClassNamePrefixImpl(const std::string& classname, - const DescriptorType* desc) { - const std::string& prefix = (desc->file()->options()).php_class_prefix(); - if (!prefix.empty()) { - return prefix; - } - - return ReservedNamePrefix(classname, desc->file()); -} - -template -std::string GeneratedClassNameImpl(const DescriptorType* desc) { - std::string classname = ClassNamePrefixImpl(desc->name(), desc) + desc->name(); - const Descriptor* containing = desc->containing_type(); - while (containing != NULL) { - classname = ClassNamePrefixImpl(containing->name(), desc) + containing->name() - + '\\' + classname; - containing = containing->containing_type(); - } - return classname; -} - -std::string GeneratedClassNameImpl(const ServiceDescriptor* desc) { - std::string classname = desc->name(); - return ClassNamePrefixImpl(classname, desc) + classname; -} - -} // namespace - -std::string ClassNamePrefix(const std::string& classname, - const Descriptor* desc) { - return ClassNamePrefixImpl(classname, desc); -} -std::string ClassNamePrefix(const std::string& classname, - const EnumDescriptor* desc) { - return ClassNamePrefixImpl(classname, desc); -} - -std::string GeneratedClassName(const Descriptor* desc) { - return GeneratedClassNameImpl(desc); -} - -std::string GeneratedClassName(const EnumDescriptor* desc) { - return GeneratedClassNameImpl(desc); -} - -std::string GeneratedClassName(const ServiceDescriptor* desc) { - return GeneratedClassNameImpl(desc); -} - -} // namespace php -} // namespace compiler -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/php/names.h b/libs/protobuf/src/google/protobuf/compiler/php/names.h deleted file mode 100644 index cf4f942..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/php/names.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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_COMPILER_PHP_NAMES_H__ -#define GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__ - -#include "google/protobuf/descriptor.h" - -#include - -#include "absl/strings/string_view.h" -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace compiler { -namespace php { - -// Whether or not a name is reserved. -PROTOC_EXPORT bool IsReservedName(absl::string_view name); - -// A prefix to stick in front of reserved names to avoid clashes. -PROTOC_EXPORT std::string ReservedNamePrefix(const std::string& classname, - const FileDescriptor* file); - -// A prefix to stick in front of all class names. -PROTOC_EXPORT std::string ClassNamePrefix(const std::string& classname, - const Descriptor* desc); -PROTOC_EXPORT std::string ClassNamePrefix(const std::string& classname, - const EnumDescriptor* desc); - -// To skip reserved keywords in php, some generated classname are prefixed. -// Other code generators may need following API to figure out the actual -// classname. -PROTOC_EXPORT std::string GeneratedClassName(const Descriptor* desc); -PROTOC_EXPORT std::string GeneratedClassName(const EnumDescriptor* desc); -PROTOC_EXPORT std::string GeneratedClassName(const ServiceDescriptor* desc); - -} // namespace php -} // namespace compiler -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/php/php_generator.cc b/libs/protobuf/src/google/protobuf/compiler/php/php_generator.cc index b7b1d17..f3aa92f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/php/php_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/php/php_generator.cc @@ -28,22 +28,18 @@ // (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/compiler/php/php_generator.h" +#include + +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/compiler/code_generator.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" - -#include "google/protobuf/stubs/strutil.h" // for StringReplace. - const std::string kDescriptorFile = "google/protobuf/descriptor.proto"; const std::string kEmptyFile = "google/protobuf/empty.proto"; const std::string kEmptyMetadataFile = "GPBMetadata/Google/Protobuf/GPBEmpty.php"; @@ -51,11 +47,29 @@ const std::string kDescriptorMetadataFile = "GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; const std::string kDescriptorDirName = "Google/Protobuf/Internal"; const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; +const char* const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "finally", "fn", "for", "foreach", "function", + "global", "goto", "if", "implements", "include", + "include_once", "instanceof", "insteadof", "interface", "isset", + "list", "match", "namespace", "new", "or", + "parent", "print", "private", "protected", "public", + "readonly", "require", "require_once", "return", "self", + "static", "switch", "throw", "trait", "try", + "unset", "use", "var", "while", "xor", + "yield", "int", "float", "bool", "string", + "true", "false", "null", "void", "iterable"}; const char* const kValidConstantNames[] = { "int", "float", "bool", "string", "true", "false", "null", "void", "iterable", "parent", "self", "readonly" }; +const int kReservedNamesSize = 80; const int kValidConstantNamesSize = 12; const int kFieldSetter = 1; const int kFieldGetter = 2; @@ -107,16 +121,70 @@ void GenerateServiceDocComment(io::Printer* printer, void GenerateServiceMethodDocComment(io::Printer* printer, const MethodDescriptor* method); +std::string ReservedNamePrefix(const std::string& classname, + const FileDescriptor* file) { + bool is_reserved = false; + + std::string lower = classname; + std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + is_reserved = true; + break; + } + } + + if (is_reserved) { + if (file->package() == "google.protobuf") { + return "GPB"; + } else { + return "PB"; + } + } + + return ""; +} + template std::string DescriptorFullName(const DescriptorType* desc, bool is_internal) { if (is_internal) { - return StringReplace(desc->full_name(), "google.protobuf", + return StringReplace(desc->full_name(), + "google.protobuf", "google.protobuf.internal", false); } else { return desc->full_name(); } } +template +std::string ClassNamePrefix(const std::string& classname, + const DescriptorType* desc) { + const std::string& prefix = (desc->file()->options()).php_class_prefix(); + if (!prefix.empty()) { + return prefix; + } + + return ReservedNamePrefix(classname, desc->file()); +} + +template +std::string GeneratedClassNameImpl(const DescriptorType* desc) { + std::string classname = ClassNamePrefix(desc->name(), desc) + desc->name(); + const Descriptor* containing = desc->containing_type(); + while (containing != NULL) { + classname = ClassNamePrefix(containing->name(), desc) + containing->name() + + '\\' + classname; + containing = containing->containing_type(); + } + return classname; +} + +std::string GeneratedClassNameImpl(const ServiceDescriptor* desc) { + std::string classname = desc->name(); + return ClassNamePrefix(classname, desc) + classname; +} + template std::string LegacyGeneratedClassName(const DescriptorType* desc) { std::string classname = desc->name(); @@ -128,13 +196,31 @@ std::string LegacyGeneratedClassName(const DescriptorType* desc) { return ClassNamePrefix(classname, desc) + classname; } +std::string ClassNamePrefix(const std::string& classname) { + std::string lower = classname; + std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + return "PB"; + } + } + + return ""; +} + std::string ConstantNamePrefix(const std::string& classname) { bool is_reserved = false; std::string lower = classname; std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); - is_reserved = IsReservedName(lower); + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + is_reserved = true; + break; + } + } for (int i = 0; i < kValidConstantNamesSize; i++) { if (lower == kValidConstantNames[i]) { @@ -169,7 +255,7 @@ std::string RootPhpNamespace(const DescriptorType* desc, template std::string FullClassName(const DescriptorType* desc, const Options& options) { - std::string classname = GeneratedClassName(desc); + std::string classname = GeneratedClassNameImpl(desc); std::string php_namespace = RootPhpNamespace(desc, options); if (!php_namespace.empty()) { return php_namespace + "\\" + classname; @@ -195,11 +281,6 @@ std::string LegacyFullClassName(const DescriptorType* desc, return classname; } -std::string PhpNamePrefix(const std::string& classname) { - if (IsReservedName(classname)) return "PB"; - return ""; -} - std::string PhpName(const std::string& full_name, const Options& options) { if (options.is_descriptor) { return kDescriptorPackageName; @@ -213,7 +294,7 @@ std::string PhpName(const std::string& full_name, const Options& options) { segment += full_name[i] + ('A' - 'a'); cap_next_letter = false; } else if (full_name[i] == '.') { - result += PhpNamePrefix(segment) + segment + '\\'; + result += ClassNamePrefix(segment) + segment + '\\'; segment = ""; cap_next_letter = true; } else { @@ -221,7 +302,7 @@ std::string PhpName(const std::string& full_name, const Options& options) { cap_next_letter = false; } } - result += PhpNamePrefix(segment) + segment; + result += ClassNamePrefix(segment) + segment; return result; } @@ -253,7 +334,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file, const Options& options) { const std::string& proto_file = file->name(); int start_index = 0; - int first_index = proto_file.find_first_of('/', start_index); + int first_index = proto_file.find_first_of("/", start_index); std::string result = ""; std::string segment = ""; @@ -266,7 +347,7 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file, // Append directory name. std::string file_no_suffix; - int lastindex = proto_file.find_last_of('.'); + int lastindex = proto_file.find_last_of("."); if (proto_file == kEmptyFile) { return kEmptyMetadataFile; } else { @@ -290,12 +371,12 @@ std::string GeneratedMetadataFileName(const FileDescriptor* file, file_no_suffix.substr(start_index, first_index - start_index), true); result += ReservedNamePrefix(segment, file) + segment + "/"; start_index = first_index + 1; - first_index = file_no_suffix.find_first_of('/', start_index); + first_index = file_no_suffix.find_first_of("/", start_index); } } // Append file name. - int file_name_start = file_no_suffix.find_last_of('/'); + int file_name_start = file_no_suffix.find_last_of("/"); if (file_name_start == std::string::npos) { file_name_start = 0; } else { @@ -422,7 +503,7 @@ std::string PhpSetterTypeName(const FieldDescriptor* field, } if (field->is_repeated()) { // accommodate for edge case with multiple types. - size_t start_pos = type.find('|'); + size_t start_pos = type.find("|"); if (start_pos != std::string::npos) { type.replace(start_pos, 1, ">|array<"); } @@ -682,8 +763,8 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options, "$arr = GPBUtil::checkMapField($var, " "\\Google\\Protobuf\\Internal\\GPBType::^key_type^, " "\\Google\\Protobuf\\Internal\\GPBType::^value_type^", - "key_type", absl::AsciiStrToUpper(key->type_name()), - "value_type", absl::AsciiStrToUpper(value->type_name())); + "key_type", ToUpper(key->type_name()), + "value_type", ToUpper(value->type_name())); if (value->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print( ", \\^class_name^);\n", @@ -701,7 +782,7 @@ void GenerateFieldAccessor(const FieldDescriptor* field, const Options& options, printer->Print( "$arr = GPBUtil::checkRepeatedField($var, " "\\Google\\Protobuf\\Internal\\GPBType::^type^", - "type", absl::AsciiStrToUpper(field->type_name())); + "type", ToUpper(field->type_name())); if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print( ", \\^class_name^);\n", @@ -831,9 +912,9 @@ void GenerateMessageToPool(const std::string& name_prefix, "->map('^field^', \\Google\\Protobuf\\Internal\\GPBType::^key^, " "\\Google\\Protobuf\\Internal\\GPBType::^value^, ^number^^other^)\n", "field", field->name(), - "key", absl::AsciiStrToUpper(key->type_name()), - "value", absl::AsciiStrToUpper(val->type_name()), - "number", absl::StrCat(field->number()), + "key", ToUpper(key->type_name()), + "value", ToUpper(val->type_name()), + "number", StrCat(field->number()), "other", EnumOrMessageSuffix(val, true)); } else if (!field->real_containing_oneof()) { printer->Print( @@ -841,8 +922,8 @@ void GenerateMessageToPool(const std::string& name_prefix, "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n", "field", field->name(), "label", LabelForField(field), - "type", absl::AsciiStrToUpper(field->type_name()), - "number", absl::StrCat(field->number()), + "type", ToUpper(field->type_name()), + "number", StrCat(field->number()), "other", EnumOrMessageSuffix(field, true)); } } @@ -859,8 +940,8 @@ void GenerateMessageToPool(const std::string& name_prefix, "->value('^field^', " "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n", "field", field->name(), - "type", absl::AsciiStrToUpper(field->type_name()), - "number", absl::StrCat(field->number()), + "type", ToUpper(field->type_name()), + "number", StrCat(field->number()), "other", EnumOrMessageSuffix(field, true)); } printer->Print("->finish()\n"); @@ -1025,7 +1106,7 @@ static bool NeedsUnwrapping(const FileDescriptor* file, has_aggregate_metadata_prefix = true; } else { for (const auto& prefix : options.aggregate_metadata_prefixes) { - if (absl::StartsWith(file->package(), prefix)) { + if (HasPrefixString(file->package(), prefix)) { has_aggregate_metadata_prefix = true; break; } @@ -1154,7 +1235,7 @@ void GenerateHead(const FileDescriptor* file, io::Printer* printer) { } std::string FilenameToClassname(const std::string& filename) { - int lastindex = filename.find_last_of('.'); + int lastindex = filename.find_last_of("."); std::string result = filename.substr(0, lastindex); for (int i = 0; i < result.size(); i++) { if (result[i] == '/') { @@ -1174,7 +1255,7 @@ void GenerateMetadataFile(const FileDescriptor* file, const Options& options, GenerateHead(file, &printer); std::string fullname = FilenameToClassname(filename); - int lastindex = fullname.find_last_of('\\'); + int lastindex = fullname.find_last_of("\\"); if (lastindex != std::string::npos) { printer.Print( @@ -1229,7 +1310,7 @@ void LegacyGenerateClassFile(const FileDescriptor* file, Outdent(&printer); printer.Print("}\n"); printer.Print("class_exists(^new^::class);\n", - "new", GeneratedClassName(desc)); + "new", GeneratedClassNameImpl(desc)); printer.Print("@trigger_error('^old^ is deprecated and will be removed in " "the next major release. Use ^fullname^ instead', E_USER_DEPRECATED);\n\n", "old", LegacyFullClassName(desc, options), @@ -1286,7 +1367,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, GenerateHead(file, &printer); std::string fullname = FilenameToClassname(filename); - int lastindex = fullname.find_last_of('\\'); + int lastindex = fullname.find_last_of("\\"); if (lastindex != std::string::npos) { printer.Print( @@ -1386,7 +1467,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, Outdent(&printer); printer.Print("}\n\n"); - // write legacy alias for backwards compatibility with nested messages and enums + // write legacy file for backwards compatibility with nested messages and enums if (en->containing_type() != NULL) { printer.Print( "// Adding a class alias for backwards compatibility with the previous class name.\n"); @@ -1394,6 +1475,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, "class_alias(^new^::class, \\^old^::class);\n\n", "new", fullname, "old", LegacyFullClassName(en, options)); + LegacyGenerateClassFile(file, en, options, generator_context); } // Write legacy file for backwards compatibility with "readonly" keywword @@ -1427,7 +1509,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, GenerateHead(file, &printer); std::string fullname = FilenameToClassname(filename); - int lastindex = fullname.find_last_of('\\'); + int lastindex = fullname.find_last_of("\\"); if (lastindex != std::string::npos) { printer.Print( @@ -1513,7 +1595,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, Outdent(&printer); printer.Print("}\n\n"); - // write legacy alias for backwards compatibility with nested messages and enums + // write legacy file for backwards compatibility with nested messages and enums if (message->containing_type() != NULL) { printer.Print( "// Adding a class alias for backwards compatibility with the previous class name.\n"); @@ -1521,6 +1603,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, "class_alias(^new^::class, \\^old^::class);\n\n", "new", fullname, "old", LegacyFullClassName(message, options)); + LegacyGenerateClassFile(file, message, options, generator_context); } // Write legacy file for backwards compatibility with "readonly" keywword @@ -1557,7 +1640,7 @@ void GenerateServiceFile( GenerateHead(file, &printer); std::string fullname = FilenameToClassname(filename); - int lastindex = fullname.find_last_of('\\'); + int lastindex = fullname.find_last_of("\\"); if (!file->options().php_namespace().empty() || (!file->options().has_php_namespace() && !file->package().empty()) || @@ -1668,7 +1751,7 @@ static void GenerateDocCommentBodyForLocation( // HTML-escape them so that they don't accidentally close the doc comment. comments = EscapePhpdoc(comments); - std::vector lines = absl::StrSplit(comments, "\n", absl::SkipEmpty()); + std::vector lines = Split(comments, "\n", true); while (!lines.empty() && lines.back().empty()) { lines.pop_back(); } @@ -1867,13 +1950,17 @@ void GenerateServiceMethodDocComment(io::Printer* printer, } std::string FilenameCName(const FileDescriptor* file) { - return absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}}); + std::string c_name = file->name(); + c_name = StringReplace(c_name, ".", "_", true); + c_name = StringReplace(c_name, "/", "_", true); + return c_name; } void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) { - std::string c_name = absl::StrReplaceAll(desc->full_name(), {{".", "_"}}); - std::string php_name = - absl::StrReplaceAll(FullClassName(desc, Options()), {{"\\", "\\\\"}}); + std::string c_name = desc->full_name(); + c_name = StringReplace(c_name, ".", "_", true); + std::string php_name = FullClassName(desc, Options()); + php_name = StringReplace(php_name, "\\", "\\\\", true); printer->Print( "/* $c_name$ */\n" "\n" @@ -1956,9 +2043,10 @@ void GenerateCEnum(const EnumDescriptor* desc, io::Printer* printer) { } void GenerateCMessage(const Descriptor* message, io::Printer* printer) { - std::string c_name = absl::StrReplaceAll(message->full_name(), {{".", "_"}}); - std::string php_name = - absl::StrReplaceAll(FullClassName(message, Options()), {{"\\", "\\\\"}}); + std::string c_name = message->full_name(); + c_name = StringReplace(c_name, ".", "_", true); + std::string php_name = FullClassName(message, Options()); + php_name = StringReplace(php_name, "\\", "\\\\", true); printer->Print( "/* $c_name$ */\n" "\n" @@ -2108,7 +2196,8 @@ void GenerateCMessage(const Descriptor* message, io::Printer* printer) { } void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) { - std::string c_name = absl::StrReplaceAll(desc->full_name(), {{".", "_"}}); + std::string c_name = desc->full_name(); + c_name = StringReplace(c_name, ".", "_", true); printer->Print( " $c_name$_ModuleInit();\n", @@ -2116,7 +2205,8 @@ void GenerateEnumCInit(const EnumDescriptor* desc, io::Printer* printer) { } void GenerateCInit(const Descriptor* message, io::Printer* printer) { - std::string c_name = absl::StrReplaceAll(message->full_name(), {{".", "_"}}); + std::string c_name = message->full_name(); + c_name = StringReplace(c_name, ".", "_", true); printer->Print( " $c_name$_ModuleInit();\n", @@ -2158,9 +2248,8 @@ void GenerateCWellKnownTypes(const std::vector& files, std::string metadata_filename = GeneratedMetadataFileName(file, Options()); std::string metadata_classname = FilenameToClassname(metadata_filename); std::string metadata_c_name = - absl::StrReplaceAll(metadata_classname, {{"\\", "_"}}); - metadata_classname = - absl::StrReplaceAll(metadata_classname, {{"\\", "\\\\"}}); + StringReplace(metadata_classname, "\\", "_", true); + metadata_classname = StringReplace(metadata_classname, "\\", "\\\\", true); FileDescriptorProto file_proto; file->CopyTo(&file_proto); std::string serialized; @@ -2178,7 +2267,7 @@ void GenerateCWellKnownTypes(const std::vector& files, for (size_t i = 0; i < serialized.size();) { for (size_t j = 0; j < 25 && i < serialized.size(); ++i, ++j) { - printer.Print("'$ch$', ", "ch", absl::CEscape(serialized.substr(i, 1))); + printer.Print("'$ch$', ", "ch", CEscape(serialized.substr(i, 1))); } printer.Print("\n"); } @@ -2241,7 +2330,7 @@ void GenerateCWellKnownTypes(const std::vector& files, std::string metadata_filename = GeneratedMetadataFileName(file, Options()); std::string metadata_classname = FilenameToClassname(metadata_filename); std::string metadata_c_name = - absl::StrReplaceAll(metadata_classname, {{"\\", "_"}}); + StringReplace(metadata_classname, "\\", "_", true); printer.Print( " $metadata_c_name$_ModuleInit();\n", "metadata_c_name", metadata_c_name); @@ -2259,6 +2348,18 @@ void GenerateCWellKnownTypes(const std::vector& files, } // namespace +std::string GeneratedClassName(const Descriptor* desc) { + return GeneratedClassNameImpl(desc); +} + +std::string GeneratedClassName(const EnumDescriptor* desc) { + return GeneratedClassNameImpl(desc); +} + +std::string GeneratedClassName(const ServiceDescriptor* desc) { + return GeneratedClassNameImpl(desc); +} + bool Generator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, @@ -2293,11 +2394,11 @@ bool Generator::GenerateAll(const std::vector& files, std::string* error) const { Options options; - for (const auto& option : absl::StrSplit(parameter, ",", absl::SkipEmpty())) { - const std::vector option_pair = absl::StrSplit(option, "=", absl::SkipEmpty()); - if (absl::StartsWith(option_pair[0], "aggregate_metadata")) { + for (const auto& option : Split(parameter, ",", true)) { + const std::vector option_pair = Split(option, "=", true); + if (HasPrefixString(option_pair[0], "aggregate_metadata")) { options.aggregate_metadata = true; - for (const auto& prefix : absl::StrSplit(option_pair[1], "#", absl::AllowEmpty())) { + for (const auto& prefix : Split(option_pair[1], "#", false)) { options.aggregate_metadata_prefixes.emplace(prefix); GOOGLE_LOG(INFO) << prefix; } diff --git a/libs/protobuf/src/google/protobuf/compiler/php/php_generator.h b/libs/protobuf/src/google/protobuf/compiler/php/php_generator.h index 2729b4a..17cb59c 100644 --- a/libs/protobuf/src/google/protobuf/compiler/php/php_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/php/php_generator.h @@ -31,13 +31,12 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ #define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/php/names.h" -#include "google/protobuf/descriptor.h" +#include +#include #include -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -71,6 +70,13 @@ class PROTOC_EXPORT Generator : public CodeGenerator { std::string* error) const; }; +// To skip reserved keywords in php, some generated classname are prefixed. +// Other code generators may need following API to figure out the actual +// classname. +PROTOC_EXPORT std::string GeneratedClassName(const Descriptor* desc); +PROTOC_EXPORT std::string GeneratedClassName(const EnumDescriptor* desc); +PROTOC_EXPORT std::string GeneratedClassName(const ServiceDescriptor* desc); + inline bool IsWrapperType(const FieldDescriptor* descriptor) { return descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto"; @@ -81,6 +87,6 @@ inline bool IsWrapperType(const FieldDescriptor* descriptor) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/plugin.cc b/libs/protobuf/src/google/protobuf/compiler/plugin.cc index b7e5c0e..0a32384 100644 --- a/libs/protobuf/src/google/protobuf/compiler/plugin.cc +++ b/libs/protobuf/src/google/protobuf/compiler/plugin.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/compiler/plugin.h" +#include #include #include @@ -41,14 +41,14 @@ #include #endif -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/compiler/plugin.pb.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include +#include +#include +#include +#include +#include namespace google { diff --git a/libs/protobuf/src/google/protobuf/compiler/plugin.h b/libs/protobuf/src/google/protobuf/compiler/plugin.h index 388f51a..611713e 100644 --- a/libs/protobuf/src/google/protobuf/compiler/plugin.h +++ b/libs/protobuf/src/google/protobuf/compiler/plugin.h @@ -65,7 +65,7 @@ #include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -91,6 +91,6 @@ bool GenerateCode(const CodeGeneratorRequest& request, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/plugin.pb.cc b/libs/protobuf/src/google/protobuf/compiler/plugin.pb.cc index 5560777..8f8d83f 100644 --- a/libs/protobuf/src/google/protobuf/compiler/plugin.pb.cc +++ b/libs/protobuf/src/google/protobuf/compiler/plugin.pb.cc @@ -1,23 +1,25 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -#include "google/protobuf/compiler/plugin.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN namespace compiler { PROTOBUF_CONSTEXPR Version::Version( @@ -29,15 +31,14 @@ PROTOBUF_CONSTEXPR Version::Version( , /*decltype(_impl_.minor_)*/0 , /*decltype(_impl_.patch_)*/0} {} struct VersionDefaultTypeInternal { - PROTOBUF_CONSTEXPR VersionDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR VersionDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~VersionDefaultTypeInternal() {} union { Version _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 VersionDefaultTypeInternal _Version_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 VersionDefaultTypeInternal _Version_default_instance_; PROTOBUF_CONSTEXPR CodeGeneratorRequest::CodeGeneratorRequest( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -47,15 +48,14 @@ PROTOBUF_CONSTEXPR CodeGeneratorRequest::CodeGeneratorRequest( , /*decltype(_impl_.parameter_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.compiler_version_)*/nullptr} {} struct CodeGeneratorRequestDefaultTypeInternal { - PROTOBUF_CONSTEXPR CodeGeneratorRequestDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR CodeGeneratorRequestDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~CodeGeneratorRequestDefaultTypeInternal() {} union { CodeGeneratorRequest _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; PROTOBUF_CONSTEXPR CodeGeneratorResponse_File::CodeGeneratorResponse_File( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -65,15 +65,14 @@ PROTOBUF_CONSTEXPR CodeGeneratorResponse_File::CodeGeneratorResponse_File( , /*decltype(_impl_.content_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.generated_code_info_)*/nullptr} {} struct CodeGeneratorResponse_FileDefaultTypeInternal { - PROTOBUF_CONSTEXPR CodeGeneratorResponse_FileDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR CodeGeneratorResponse_FileDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~CodeGeneratorResponse_FileDefaultTypeInternal() {} union { CodeGeneratorResponse_File _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; PROTOBUF_CONSTEXPR CodeGeneratorResponse::CodeGeneratorResponse( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -82,163 +81,130 @@ PROTOBUF_CONSTEXPR CodeGeneratorResponse::CodeGeneratorResponse( , /*decltype(_impl_.error_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.supported_features_)*/uint64_t{0u}} {} struct CodeGeneratorResponseDefaultTypeInternal { - PROTOBUF_CONSTEXPR CodeGeneratorResponseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR CodeGeneratorResponseDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~CodeGeneratorResponseDefaultTypeInternal() {} union { CodeGeneratorResponse _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; } // namespace compiler PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[4]; static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto[1]; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.major_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.minor_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.patch_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.suffix_), - 1, - 2, - 3, - 0, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.file_to_generate_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.parameter_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.proto_file_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.compiler_version_), - ~0u, - 0, - ~0u, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.insertion_point_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.content_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.generated_code_info_), - 0, - 1, - 2, - 3, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.error_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.supported_features_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.file_), - 0, - 1, - ~0u, -}; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, 12, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::Version)}, - { 16, 28, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest)}, - { 32, 44, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File)}, - { 48, 59, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse)}, +const uint32_t TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.major_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.minor_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.patch_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::Version, _impl_.suffix_), + 1, + 2, + 3, + 0, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.file_to_generate_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.parameter_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.proto_file_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest, _impl_.compiler_version_), + ~0u, + 0, + ~0u, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.insertion_point_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.content_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File, _impl_.generated_code_info_), + 0, + 1, + 2, + 3, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.error_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.supported_features_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse, _impl_.file_), + 0, + 1, + ~0u, +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, 10, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::Version)}, + { 14, 24, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest)}, + { 28, 38, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File)}, + { 42, 51, -1, sizeof(::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::compiler::_Version_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorRequest_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorResponse_File_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorResponse_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2eproto[] PROTOBUF_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" - "\001 \001(\005\022\r\n\005minor\030\002 \001(\005\022\r\n\005patch\030\003 \001(\005\022\016\n\006s" - "uffix\030\004 \001(\t\"\272\001\n\024CodeGeneratorRequest\022\030\n\020" - "file_to_generate\030\001 \003(\t\022\021\n\tparameter\030\002 \001(" - "\t\0228\n\nproto_file\030\017 \003(\0132$.google.protobuf." - "FileDescriptorProto\022;\n\020compiler_version\030" - "\003 \001(\0132!.google.protobuf.compiler.Version" - "\"\301\002\n\025CodeGeneratorResponse\022\r\n\005error\030\001 \001(" - "\t\022\032\n\022supported_features\030\002 \001(\004\022B\n\004file\030\017 " - "\003(\01324.google.protobuf.compiler.CodeGener" - "atorResponse.File\032\177\n\004File\022\014\n\004name\030\001 \001(\t\022" - "\027\n\017insertion_point\030\002 \001(\t\022\017\n\007content\030\017 \001(" - "\t\022\?\n\023generated_code_info\030\020 \001(\0132\".google." - "protobuf.GeneratedCodeInfo\"8\n\007Feature\022\020\n" - "\014FEATURE_NONE\020\000\022\033\n\027FEATURE_PROTO3_OPTION" - "AL\020\001BW\n\034com.google.protobuf.compilerB\014Pl" - "uginProtosZ)google.golang.org/protobuf/t" - "ypes/pluginpb" -}; -static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_deps[1] = - { - &::descriptor_table_google_2fprotobuf_2fdescriptor_2eproto, -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto = { - false, - false, - 773, - descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2eproto, - "google/protobuf/compiler/plugin.proto", - &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, - descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_deps, - 1, - 4, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto, + &::PROTOBUF_NAMESPACE_ID::compiler::_Version_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorRequest_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorResponse_File_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::compiler::_CodeGeneratorResponse_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2eproto[] PROTOBUF_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" + "\001 \001(\005\022\r\n\005minor\030\002 \001(\005\022\r\n\005patch\030\003 \001(\005\022\016\n\006s" + "uffix\030\004 \001(\t\"\272\001\n\024CodeGeneratorRequest\022\030\n\020" + "file_to_generate\030\001 \003(\t\022\021\n\tparameter\030\002 \001(" + "\t\0228\n\nproto_file\030\017 \003(\0132$.google.protobuf." + "FileDescriptorProto\022;\n\020compiler_version\030" + "\003 \001(\0132!.google.protobuf.compiler.Version" + "\"\301\002\n\025CodeGeneratorResponse\022\r\n\005error\030\001 \001(" + "\t\022\032\n\022supported_features\030\002 \001(\004\022B\n\004file\030\017 " + "\003(\01324.google.protobuf.compiler.CodeGener" + "atorResponse.File\032\177\n\004File\022\014\n\004name\030\001 \001(\t\022" + "\027\n\017insertion_point\030\002 \001(\t\022\017\n\007content\030\017 \001(" + "\t\022\?\n\023generated_code_info\030\020 \001(\0132\".google." + "protobuf.GeneratedCodeInfo\"8\n\007Feature\022\020\n" + "\014FEATURE_NONE\020\000\022\033\n\027FEATURE_PROTO3_OPTION" + "AL\020\001BW\n\034com.google.protobuf.compilerB\014Pl" + "uginProtosZ)google.golang.org/protobuf/t" + "ypes/pluginpb" + ; +static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_deps[1] = { + &::descriptor_table_google_2fprotobuf_2fdescriptor_2eproto, +}; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto = { + false, false, 773, descriptor_table_protodef_google_2fprotobuf_2fcompiler_2fplugin_2eproto, + "google/protobuf/compiler/plugin.proto", + &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_deps, 1, 4, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fcompiler_2fplugin_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fcompiler_2fplugin_2eproto(&descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fcompiler_2fplugin_2eproto(&descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto); PROTOBUF_NAMESPACE_OPEN namespace compiler { const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* CodeGeneratorResponse_Feature_descriptor() { @@ -254,24 +220,20 @@ bool CodeGeneratorResponse_Feature_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse::FEATURE_NONE; constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse::FEATURE_PROTO3_OPTIONAL; constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse::Feature_MIN; constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse::Feature_MAX; constexpr int CodeGeneratorResponse::Feature_ARRAYSIZE; +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) // =================================================================== class Version::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(Version, _impl_._has_bits_); static void set_has_major(HasBits* has_bits) { (*has_bits)[0] |= 2u; } @@ -374,7 +336,6 @@ void Version::Clear() { } const char* Version::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -446,7 +407,6 @@ failure: uint8_t* Version::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -489,7 +449,6 @@ uint8_t* Version::_InternalSerialize( } size_t Version::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.Version) size_t total_size = 0; @@ -535,7 +494,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Version::GetClassData() const void Version::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -590,18 +548,16 @@ void Version::InternalSwap(Version* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Version::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[0]); } + // =================================================================== class CodeGeneratorRequest::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_._has_bits_); static void set_has_parameter(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -712,7 +668,6 @@ void CodeGeneratorRequest::Clear() { } const char* CodeGeneratorRequest::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -795,7 +750,6 @@ failure: uint8_t* CodeGeneratorRequest::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -845,7 +799,6 @@ uint8_t* CodeGeneratorRequest::_InternalSerialize( } size_t CodeGeneratorRequest::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorRequest) size_t total_size = 0; @@ -898,7 +851,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorRequest::GetClass void CodeGeneratorRequest::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -948,18 +900,16 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata CodeGeneratorRequest::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[1]); } + // =================================================================== class CodeGeneratorResponse_File::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse_File, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -1105,7 +1055,6 @@ void CodeGeneratorResponse_File::Clear() { } const char* CodeGeneratorResponse_File::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -1182,7 +1131,6 @@ failure: uint8_t* CodeGeneratorResponse_File::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse.File) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1234,7 +1182,6 @@ uint8_t* CodeGeneratorResponse_File::_InternalSerialize( } size_t CodeGeneratorResponse_File::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse.File) size_t total_size = 0; @@ -1286,7 +1233,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse_File::Ge void CodeGeneratorResponse_File::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1344,18 +1290,16 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) } ::PROTOBUF_NAMESPACE_ID::Metadata CodeGeneratorResponse_File::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[2]); } + // =================================================================== class CodeGeneratorResponse::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse, _impl_._has_bits_); static void set_has_error(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -1446,7 +1390,6 @@ void CodeGeneratorResponse::Clear() { } const char* CodeGeneratorResponse::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -1513,7 +1456,6 @@ failure: uint8_t* CodeGeneratorResponse::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1552,7 +1494,6 @@ uint8_t* CodeGeneratorResponse::_InternalSerialize( } size_t CodeGeneratorResponse::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse) size_t total_size = 0; @@ -1595,7 +1536,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*CodeGeneratorResponse::GetClas void CodeGeneratorResponse::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1641,11 +1581,11 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata CodeGeneratorResponse::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_getter, &descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto_once, file_level_metadata_google_2fprotobuf_2fcompiler_2fplugin_2eproto[3]); } + // @@protoc_insertion_point(namespace_scope) } // namespace compiler PROTOBUF_NAMESPACE_CLOSE @@ -1667,5 +1607,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRespo return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/compiler/plugin.pb.h b/libs/protobuf/src/google/protobuf/compiler/plugin.pb.h index d86c270..5f3fa52 100644 --- a/libs/protobuf/src/google/protobuf/compiler/plugin.pb.h +++ b/libs/protobuf/src/google/protobuf/compiler/plugin.pb.h @@ -1,51 +1,46 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/compiler/plugin.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fcompiler_2fplugin_2eproto PROTOC_EXPORT #ifdef major #undef major -#endif // major +#endif #ifdef minor #undef minor -#endif // minor - +#endif PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -56,8 +51,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOC_EXPORT TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto { static const uint32_t offsets[]; }; -PROTOC_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto; +PROTOC_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fcompiler_2fplugin_2eproto; PROTOBUF_NAMESPACE_OPEN namespace compiler { class CodeGeneratorRequest; @@ -73,52 +67,41 @@ class Version; struct VersionDefaultTypeInternal; PROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_; } // namespace compiler -template <> -PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest>(Arena*); -template <> -PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse>(Arena*); -template <> -PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File>(Arena*); -template <> -PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::Version* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::Version>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorRequest>(Arena*); +template<> PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse>(Arena*); +template<> PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_File>(Arena*); +template<> PROTOC_EXPORT ::PROTOBUF_NAMESPACE_ID::compiler::Version* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::compiler::Version>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN namespace compiler { + enum CodeGeneratorResponse_Feature : int { CodeGeneratorResponse_Feature_FEATURE_NONE = 0, - CodeGeneratorResponse_Feature_FEATURE_PROTO3_OPTIONAL = 1, + CodeGeneratorResponse_Feature_FEATURE_PROTO3_OPTIONAL = 1 }; - PROTOC_EXPORT bool CodeGeneratorResponse_Feature_IsValid(int value); -constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse_Feature_Feature_MIN = static_cast(0); -constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse_Feature_Feature_MAX = static_cast(1); -constexpr int CodeGeneratorResponse_Feature_Feature_ARRAYSIZE = 1 + 1; -PROTOC_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -CodeGeneratorResponse_Feature_descriptor(); -template -const std::string& CodeGeneratorResponse_Feature_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Feature_Name()."); - return CodeGeneratorResponse_Feature_Name(static_cast(value)); +constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse_Feature_Feature_MIN = CodeGeneratorResponse_Feature_FEATURE_NONE; +constexpr CodeGeneratorResponse_Feature CodeGeneratorResponse_Feature_Feature_MAX = CodeGeneratorResponse_Feature_FEATURE_PROTO3_OPTIONAL; +constexpr int CodeGeneratorResponse_Feature_Feature_ARRAYSIZE = CodeGeneratorResponse_Feature_Feature_MAX + 1; + +PROTOC_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* CodeGeneratorResponse_Feature_descriptor(); +template +inline const std::string& CodeGeneratorResponse_Feature_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function CodeGeneratorResponse_Feature_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + CodeGeneratorResponse_Feature_descriptor(), enum_t_value); } -template <> -inline const std::string& CodeGeneratorResponse_Feature_Name(CodeGeneratorResponse_Feature value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool CodeGeneratorResponse_Feature_Parse(absl::string_view name, CodeGeneratorResponse_Feature* value) { +inline bool CodeGeneratorResponse_Feature_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, CodeGeneratorResponse_Feature* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - CodeGeneratorResponse_Feature_descriptor(), name, value); + CodeGeneratorResponse_Feature_descriptor(), name, value); } - // =================================================================== - -// ------------------------------------------------------------------- - class PROTOC_EXPORT Version final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { public: @@ -229,7 +212,7 @@ class PROTOC_EXPORT Version final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.compiler.Version"; } protected: @@ -326,7 +309,8 @@ class PROTOC_EXPORT Version final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOC_EXPORT CodeGeneratorRequest final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { @@ -438,7 +422,7 @@ class PROTOC_EXPORT CodeGeneratorRequest final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.compiler.CodeGeneratorRequest"; } protected: @@ -556,7 +540,8 @@ class PROTOC_EXPORT CodeGeneratorRequest final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOC_EXPORT CodeGeneratorResponse_File final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { @@ -668,7 +653,7 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.compiler.CodeGeneratorResponse.File"; } protected: @@ -780,7 +765,8 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fcompiler_2fplugin_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOC_EXPORT CodeGeneratorResponse final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { @@ -892,7 +878,7 @@ class PROTOC_EXPORT CodeGeneratorResponse final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.compiler.CodeGeneratorResponse"; } protected: @@ -909,23 +895,33 @@ class PROTOC_EXPORT CodeGeneratorResponse final : typedef CodeGeneratorResponse_File File; - using Feature = CodeGeneratorResponse_Feature; - static constexpr Feature FEATURE_NONE = CodeGeneratorResponse_Feature_FEATURE_NONE; - static constexpr Feature FEATURE_PROTO3_OPTIONAL = CodeGeneratorResponse_Feature_FEATURE_PROTO3_OPTIONAL; + typedef CodeGeneratorResponse_Feature Feature; + static constexpr Feature FEATURE_NONE = + CodeGeneratorResponse_Feature_FEATURE_NONE; + static constexpr Feature FEATURE_PROTO3_OPTIONAL = + CodeGeneratorResponse_Feature_FEATURE_PROTO3_OPTIONAL; static inline bool Feature_IsValid(int value) { return CodeGeneratorResponse_Feature_IsValid(value); } - static constexpr Feature Feature_MIN = CodeGeneratorResponse_Feature_Feature_MIN; - static constexpr Feature Feature_MAX = CodeGeneratorResponse_Feature_Feature_MAX; - static constexpr int Feature_ARRAYSIZE = CodeGeneratorResponse_Feature_Feature_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Feature_descriptor() { + static constexpr Feature Feature_MIN = + CodeGeneratorResponse_Feature_Feature_MIN; + static constexpr Feature Feature_MAX = + CodeGeneratorResponse_Feature_Feature_MAX; + static constexpr int Feature_ARRAYSIZE = + CodeGeneratorResponse_Feature_Feature_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + Feature_descriptor() { return CodeGeneratorResponse_Feature_descriptor(); } - template - static inline const std::string& Feature_Name(T value) { - return CodeGeneratorResponse_Feature_Name(value); + template + static inline const std::string& Feature_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Feature_Name."); + return CodeGeneratorResponse_Feature_Name(enum_t_value); } - static inline bool Feature_Parse(absl::string_view name, Feature* value) { + static inline bool Feature_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + Feature* value) { return CodeGeneratorResponse_Feature_Parse(name, value); } @@ -1005,17 +1001,12 @@ class PROTOC_EXPORT CodeGeneratorResponse final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Version // optional int32 major = 1; @@ -1149,7 +1140,9 @@ inline std::string* Version::release_suffix() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.suffix_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.suffix_.Set("", GetArenaForAllocation()); + if (_impl_.suffix_.IsDefault()) { + _impl_.suffix_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1207,7 +1200,8 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, std::string&& // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.file_to_generate_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.file_to_generate_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { @@ -1227,7 +1221,8 @@ inline void CodeGeneratorRequest::add_file_to_generate(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.file_to_generate_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.file_to_generate_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { @@ -1292,7 +1287,9 @@ inline std::string* CodeGeneratorRequest::release_parameter() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.parameter_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.parameter_.Set("", GetArenaForAllocation()); + if (_impl_.parameter_.IsDefault()) { + _impl_.parameter_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1489,7 +1486,9 @@ inline std::string* CodeGeneratorResponse_File::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1555,7 +1554,9 @@ inline std::string* CodeGeneratorResponse_File::release_insertion_point() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.insertion_point_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.insertion_point_.Set("", GetArenaForAllocation()); + if (_impl_.insertion_point_.IsDefault()) { + _impl_.insertion_point_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1621,7 +1622,9 @@ inline std::string* CodeGeneratorResponse_File::release_content() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.content_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.content_.Set("", GetArenaForAllocation()); + if (_impl_.content_.IsDefault()) { + _impl_.content_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1778,7 +1781,9 @@ inline std::string* CodeGeneratorResponse::release_error() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.error_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.error_.Set("", GetArenaForAllocation()); + if (_impl_.error_.IsDefault()) { + _impl_.error_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -1866,20 +1871,25 @@ CodeGeneratorResponse::file() const { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) + } // namespace compiler PROTOBUF_NAMESPACE_CLOSE - PROTOBUF_NAMESPACE_OPEN +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_Feature> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_Feature> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_Feature>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_Feature>() { return ::PROTOBUF_NAMESPACE_ID::compiler::CodeGeneratorResponse_Feature_descriptor(); } @@ -1887,6 +1897,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fcompiler_2fplugin_2eproto diff --git a/libs/protobuf/src/google/protobuf/compiler/plugin.proto b/libs/protobuf/src/google/protobuf/compiler/plugin.proto index b233bce..9242aac 100644 --- a/libs/protobuf/src/google/protobuf/compiler/plugin.proto +++ b/libs/protobuf/src/google/protobuf/compiler/plugin.proto @@ -30,6 +30,9 @@ // Author: kenton@google.com (Kenton Varda) // +// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to +// change. +// // protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is // just a program that reads a CodeGeneratorRequest from stdin and writes a // CodeGeneratorResponse to stdout. @@ -89,6 +92,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/libs/protobuf/src/google/protobuf/compiler/python/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/python/BUILD.bazel deleted file mode 100644 index 933d063..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/python/BUILD.bazel +++ /dev/null @@ -1,69 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - Python code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "python", - srcs = [ - "generator.cc", - "helpers.cc", - "pyi_generator.cc", - ], - hdrs = [ - "generator.h", - "helpers.h", - "pyi_generator.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/compiler/python", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - "@com_github_grpc_grpc//tools/distrib/python/grpcio_tools:__subpackages__", - ], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/synchronization", - ], -) - -cc_test( - name = "plugin_unittest", - srcs = ["plugin_unittest.cc"], - copts = COPTS, - deps = [ - ":python", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/io", - "//src/google/protobuf/testing", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/python/generator.cc b/libs/protobuf/src/google/protobuf/compiler/python/generator.cc index 1ff2497..d8d6d74 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/python/generator.cc @@ -42,7 +42,7 @@ // performance-minded Python code leverage the fast C++ implementation // directly. -#include "google/protobuf/compiler/python/generator.h" +#include #include #include @@ -52,22 +52,17 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/strip.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/compiler/python/helpers.h" -#include "google/protobuf/compiler/python/pyi_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -84,8 +79,8 @@ std::string ModuleAlias(const std::string& filename) { // We can't have dots in the module name, so we replace each with _dot_. // But that could lead to a collision between a.b and a_dot_b, so we also // duplicate each underscore. - absl::StrReplaceAll({{"_", "__"}}, &module_name); - absl::StrReplaceAll({{".", "_dot_"}}, &module_name); + GlobalReplaceSubstring("_", "__", &module_name); + GlobalReplaceSubstring(".", "_dot_", &module_name); return module_name; } @@ -95,7 +90,29 @@ std::string ModuleAlias(const std::string& filename) { // in proto2/public/reflection.py. const char kDescriptorKey[] = "DESCRIPTOR"; -const char kThirdPartyPrefix[] = "google3.third_party.py."; + +// file output by this generator. +void PrintTopBoilerplate(io::Printer* printer, const FileDescriptor* file, + bool descriptor_proto) { + // TODO(robinson): Allow parameterization of Python version? + printer->Print( + "# -*- coding: utf-8 -*-\n" + "# Generated by the protocol buffer compiler. DO NOT EDIT!\n" + "# source: $filename$\n" + "\"\"\"Generated protocol buffer code.\"\"\"\n", + "filename", file->name()); + printer->Print( + "from google.protobuf.internal import builder as _builder\n" + "from google.protobuf import descriptor as _descriptor\n" + "from google.protobuf import descriptor_pool as " + "_descriptor_pool\n" + "from google.protobuf import symbol_database as " + "_symbol_database\n"); + + printer->Print("# @@protoc_insertion_point(imports)\n\n"); + printer->Print("_sym_db = _symbol_database.Default()\n"); + printer->Print("\n\n"); +} // Returns a Python literal giving the default value for a field. // If the field specifies no explicit default value, we'll return @@ -114,13 +131,13 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { switch (field.cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return absl::StrCat(field.default_value_int32()); + return StrCat(field.default_value_int32()); case FieldDescriptor::CPPTYPE_UINT32: - return absl::StrCat(field.default_value_uint32()); + return StrCat(field.default_value_uint32()); case FieldDescriptor::CPPTYPE_INT64: - return absl::StrCat(field.default_value_int64()); + return StrCat(field.default_value_int64()); case FieldDescriptor::CPPTYPE_UINT64: - return absl::StrCat(field.default_value_uint64()); + return StrCat(field.default_value_uint64()); case FieldDescriptor::CPPTYPE_DOUBLE: { double value = field.default_value_double(); if (value == std::numeric_limits::infinity()) { @@ -156,9 +173,9 @@ std::string StringifyDefaultValue(const FieldDescriptor& field) { case FieldDescriptor::CPPTYPE_BOOL: return field.default_value_bool() ? "True" : "False"; case FieldDescriptor::CPPTYPE_ENUM: - return absl::StrCat(field.default_value_enum()->number()); + return StrCat(field.default_value_enum()->number()); case FieldDescriptor::CPPTYPE_STRING: - return "b\"" + absl::CEscape(field.default_value_string()) + + return "b\"" + CEscape(field.default_value_string()) + (field.type() != FieldDescriptor::TYPE_STRING ? "\"" : "\".decode('utf-8')"); @@ -195,42 +212,26 @@ uint64_t Generator::GetSupportedFeatures() const { return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL; } -GeneratorOptions Generator::ParseParameter(const std::string& parameter, - std::string* error) const { - GeneratorOptions options; - - std::vector > option_pairs; - ParseGeneratorParameter(parameter, &option_pairs); - - for (const std::pair& option : option_pairs) { - if (!opensource_runtime_ && - option.first == "no_enforce_api_compatibility") { - // TODO(b/241584880): remove this legacy option, it has no effect. - } else if (!opensource_runtime_ && option.first == "bootstrap") { - options.bootstrap = true; - } else if (option.first == "pyi_out") { - options.generate_pyi = true; - } else if (option.first == "annotate_code") { - options.annotate_pyi = true; - } else { - *error = "Unknown generator option: " + option.first; - } - } - return options; -} - bool Generator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* context, std::string* error) const { // ----------------------------------------------------------------- - GeneratorOptions options = ParseParameter(parameter, error); - if (!error->empty()) return false; + // parse generator options + bool cpp_generated_lib_linked = false; - // Generate pyi typing information - if (options.generate_pyi) { - python::PyiGenerator pyi_generator; - std::string pyi_options = options.annotate_pyi ? "annotate_code" : ""; - if (!pyi_generator.Generate(file, pyi_options, context, error)) { + std::vector > options; + ParseGeneratorParameter(parameter, &options); + + for (int i = 0; i < options.size(); i++) { + if (options[i].first == "cpp_generated_lib_linked") { + cpp_generated_lib_linked = true; + } else if (options[i].first == "pyi_out") { + python::PyiGenerator pyi_generator; + if (!pyi_generator.Generate(file, "", context, error)) { + return false; + } + } else { + *error = "Unknown generator option: " + options[i].first; return false; } } @@ -242,106 +243,75 @@ bool Generator::Generate(const FileDescriptor* file, // TODO(kenton): The proper thing to do would be to allocate any state on // the stack and use that, so that the Generator class itself does not need // to have any mutable members. Then it is implicitly thread-safe. - absl::MutexLock lock(&mutex_); + MutexLock lock(&mutex_); file_ = file; std::string filename = GetFileName(file, ".py"); + pure_python_workable_ = !cpp_generated_lib_linked; + if (HasPrefixString(file->name(), "google/protobuf/")) { + pure_python_workable_ = true; + } FileDescriptorProto fdp; file_->CopyTo(&fdp); fdp.SerializeToString(&file_descriptor_serialized_); - if (!opensource_runtime_ && GeneratingDescriptorProto()) { - std::string bootstrap_filename = - "net/proto2/python/internal/descriptor_pb2.py"; - if (options.bootstrap) { - filename = bootstrap_filename; - } else { - std::unique_ptr output(context->Open(filename)); - io::Printer printer(output.get(), '$'); - printer.Print( - "from $internal_package$ import descriptor_pb2\n" - "\n", - "internal_package", InternalPackage()); - - // For static checkers, we need to explicitly assign to the symbols we - // publicly export. - for (int i = 0; i < file_->message_type_count(); i++) { - const Descriptor* message = file_->message_type(i); - printer.Print("$name$ = descriptor_pb2.$name$\n", "name", - message->name()); - } - - // Sadly some clients access our internal variables (starting with "_"). - // To support them, we iterate over *all* symbols to expose even the - // private ones. Statically type-checked code should (especially) never - // use these, so we don't worry about making them available to pytype - // checks. - printer.Print( - "\n" - "globals().update(descriptor_pb2.__dict__)\n" - "\n"); - - printer.Print( - "# @@protoc_insertion_point(module_scope)\n" - "\n"); - return true; - } - } std::unique_ptr output(context->Open(filename)); GOOGLE_CHECK(output.get()); io::Printer printer(output.get(), '$'); printer_ = &printer; - PrintTopBoilerplate(); - PrintImports(); - PrintFileDescriptor(); - if (GeneratingDescriptorProto()) { - printer_->Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); - printer_->Indent(); - // Create enums before message descriptors - PrintAllNestedEnumsInFile(); - PrintMessageDescriptors(); - FixForeignFieldsInDescriptors(); - printer_->Outdent(); - printer_->Print("else:\n"); - printer_->Indent(); + PrintTopBoilerplate(printer_, file_, GeneratingDescriptorProto()); + if (pure_python_workable_) { + PrintImports(); } - // Find the message descriptors first and then use the message - // descriptor to find enums. - printer_->Print( - "_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())\n"); - if (GeneratingDescriptorProto()) { - printer_->Outdent(); + PrintFileDescriptor(); + if (pure_python_workable_) { + if (GeneratingDescriptorProto()) { + printer_->Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); + printer_->Indent(); + // Create enums before message descriptors + PrintAllNestedEnumsInFile(); + PrintMessageDescriptors(); + FixForeignFieldsInDescriptors(); + printer_->Outdent(); + printer_->Print("else:\n"); + printer_->Indent(); + } + // Find the message descriptors first and then use the message + // descriptor to find enums. + printer_->Print( + "_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())\n"); + if (GeneratingDescriptorProto()) { + printer_->Outdent(); + } } std::string module_name = ModuleName(file->name()); - if (!opensource_runtime_) { - module_name = - std::string(absl::StripPrefix(module_name, kThirdPartyPrefix)); - } printer_->Print( "_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, '$module_name$', " "globals())\n", "module_name", module_name); - printer.Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); - printer_->Indent(); + if (pure_python_workable_) { + printer.Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); + printer_->Indent(); - // We have to fix up the extensions after the message classes themselves, - // since they need to call static RegisterExtension() methods on these - // classes. - FixForeignFieldsInExtensions(); - // Descriptor options may have custom extensions. These custom options - // 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(); + // We have to fix up the extensions after the message classes themselves, + // since they need to call static RegisterExtension() methods on these + // classes. + FixForeignFieldsInExtensions(); + // Descriptor options may have custom extensions. These custom options + // 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(); - // Set serialized_start and serialized_end. - SetSerializedPbInterval(); + // Set serialized_start and serialized_end. + SetSerializedPbInterval(); - printer_->Outdent(); + printer_->Outdent(); + } if (HasGenericServices(file)) { printer_->Print( "_builder.BuildServices(DESCRIPTOR, '$module_name$', globals())\n", @@ -353,34 +323,6 @@ bool Generator::Generate(const FileDescriptor* file, return !printer.failed(); } -// file output by this generator. -void Generator::PrintTopBoilerplate() const { - // TODO(robinson): Allow parameterization of Python version? - printer_->Print( - "# -*- coding: utf-8 -*-\n" - "# Generated by the protocol buffer compiler. DO NOT EDIT!\n" - "# source: $filename$\n" - "\"\"\"Generated protocol buffer code.\"\"\"\n", - "filename", file_->name()); - if (!opensource_runtime_) { - // This import is needed so that compatibility proto1 compiler output - // inserted at protoc_insertion_point can refer to other protos like - // google3.a.b.c. Code generated by proto2 compiler doesn't do it, and - // instead uses aliases assigned when importing modules. - printer_->Print("import google3\n"); - } - printer_->Print( - "from $internal_package$ import builder as _builder\n" - "from $public_package$ import descriptor as _descriptor\n" - "from $public_package$ import descriptor_pool as _descriptor_pool\n" - "from $public_package$ import symbol_database as _symbol_database\n", - "internal_package", InternalPackage(), "public_package", PublicPackage()); - - printer_->Print("# @@protoc_insertion_point(imports)\n\n"); - printer_->Print("_sym_db = _symbol_database.Default()\n"); - printer_->Print("\n\n"); -} - // Prints Python imports for all modules imported by |file|. void Generator::PrintImports() const { for (int i = 0; i < file_->dependency_count(); ++i) { @@ -388,10 +330,6 @@ void Generator::PrintImports() const { std::string module_name = ModuleName(filename); std::string module_alias = ModuleAlias(filename); - if (!opensource_runtime_) { - module_name = - std::string(absl::StripPrefix(module_name, kThirdPartyPrefix)); - } if (ContainsPythonKeyword(module_name)) { // If the module path contains a Python keyword, we have to quote the // module name and import it using importlib. Otherwise the usual kind of @@ -422,10 +360,6 @@ void Generator::PrintImports() const { // Print public imports. for (int i = 0; i < file_->public_dependency_count(); ++i) { std::string module_name = ModuleName(file_->public_dependency(i)->name()); - if (!opensource_runtime_) { - module_name = - std::string(absl::StripPrefix(module_name, kThirdPartyPrefix)); - } printer_->Print("from $module$ import *\n", "module", module_name); } printer_->Print("\n"); @@ -439,7 +373,7 @@ void Generator::PrintFileDescriptor() const { m["package"] = file_->package(); m["syntax"] = StringifySyntax(file_->syntax()); m["options"] = OptionsValue(file_->options().SerializeAsString()); - m["serialized_descriptor"] = absl::CHexEscape(file_descriptor_serialized_); + m["serialized_descriptor"] = strings::CHexEscape(file_descriptor_serialized_); if (GeneratingDescriptorProto()) { printer_->Print("if _descriptor._USE_C_DESCRIPTORS == False:\n"); printer_->Indent(); @@ -455,26 +389,30 @@ void Generator::PrintFileDescriptor() const { " create_key=_descriptor._internal_create_key,\n"; printer_->Print(m, file_descriptor_template); printer_->Indent(); - printer_->Print("serialized_pb=b'$value$'\n", "value", - absl::CHexEscape(file_descriptor_serialized_)); - if (file_->dependency_count() != 0) { - printer_->Print(",\ndependencies=["); - for (int i = 0; i < file_->dependency_count(); ++i) { - std::string module_alias = ModuleAlias(file_->dependency(i)->name()); - printer_->Print("$module_alias$.DESCRIPTOR,", "module_alias", - module_alias); + if (pure_python_workable_) { + printer_->Print("serialized_pb=b'$value$'\n", "value", + strings::CHexEscape(file_descriptor_serialized_)); + if (file_->dependency_count() != 0) { + printer_->Print(",\ndependencies=["); + for (int i = 0; i < file_->dependency_count(); ++i) { + std::string module_alias = ModuleAlias(file_->dependency(i)->name()); + printer_->Print("$module_alias$.DESCRIPTOR,", "module_alias", + module_alias); + } + printer_->Print("]"); } - printer_->Print("]"); - } - if (file_->public_dependency_count() > 0) { - printer_->Print(",\npublic_dependencies=["); - for (int i = 0; i < file_->public_dependency_count(); ++i) { - std::string module_alias = - ModuleAlias(file_->public_dependency(i)->name()); - printer_->Print("$module_alias$.DESCRIPTOR,", "module_alias", - module_alias); + if (file_->public_dependency_count() > 0) { + printer_->Print(",\npublic_dependencies=["); + for (int i = 0; i < file_->public_dependency_count(); ++i) { + std::string module_alias = + ModuleAlias(file_->public_dependency(i)->name()); + printer_->Print("$module_alias$.DESCRIPTOR,", "module_alias", + module_alias); + } + printer_->Print("]"); } - printer_->Print("]"); + } else { + printer_->Print("serialized_pb=''\n"); } // TODO(falk): Also print options and fix the message_type, enum_type, @@ -529,9 +467,11 @@ void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { printer_->Indent(); printer_->Indent(); - for (int i = 0; i < enum_descriptor.value_count(); ++i) { - PrintEnumValueDescriptor(*enum_descriptor.value(i)); - printer_->Print(",\n"); + if (pure_python_workable_) { + for (int i = 0; i < enum_descriptor.value_count(); ++i) { + PrintEnumValueDescriptor(*enum_descriptor.value(i)); + printer_->Print(",\n"); + } } printer_->Outdent(); @@ -542,8 +482,10 @@ void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const { EnumDescriptorProto edp; printer_->Outdent(); printer_->Print(")\n"); - printer_->Print("_sym_db.RegisterEnumDescriptor($name$)\n", "name", - module_level_descriptor_name); + if (pure_python_workable_) { + printer_->Print("_sym_db.RegisterEnumDescriptor($name$)\n", "name", + module_level_descriptor_name); + } printer_->Print("\n"); } @@ -593,13 +535,13 @@ void Generator::PrintServiceDescriptor( void Generator::PrintDescriptorKeyAndModuleName( const ServiceDescriptor& descriptor) const { std::string name = ModuleLevelServiceDescriptorName(descriptor); + if (!pure_python_workable_) { + name = "_descriptor.ServiceDescriptor(full_name='" + + descriptor.full_name() + "')"; + } printer_->Print("$descriptor_key$ = $descriptor_name$,\n", "descriptor_key", kDescriptorKey, "descriptor_name", name); std::string module_name = ModuleName(file_->name()); - if (!opensource_runtime_) { - module_name = - std::string(absl::StripPrefix(module_name, kThirdPartyPrefix)); - } printer_->Print("__module__ = '$module_name$'\n", "module_name", module_name); } @@ -692,8 +634,8 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { for (int i = 0; i < message_descriptor.extension_range_count(); ++i) { const Descriptor::ExtensionRange* range = message_descriptor.extension_range(i); - printer_->Print("($start$, $end$), ", "start", absl::StrCat(range->start), - "end", absl::StrCat(range->end)); + printer_->Print("($start$, $end$), ", "start", StrCat(range->start), + "end", StrCat(range->end)); } printer_->Print("],\n"); printer_->Print("oneofs=[\n"); @@ -703,7 +645,7 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const { m.clear(); m["name"] = desc->name(); m["full_name"] = desc->full_name(); - m["index"] = absl::StrCat(desc->index()); + m["index"] = StrCat(desc->index()); options_string = OptionsValue(desc->options().SerializeAsString()); if (options_string == "None") { m["serialized_options"] = ""; @@ -786,13 +728,14 @@ void Generator::PrintMessage(const Descriptor& message_descriptor, PrintNestedMessages(message_descriptor, qualified_name, to_register); std::map m; m["descriptor_key"] = kDescriptorKey; - m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor); + if (pure_python_workable_) { + m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor); + } else { + m["descriptor_name"] = "_descriptor.Descriptor(full_name='" + + message_descriptor.full_name() + "')"; + } printer_->Print(m, "'$descriptor_key$' : $descriptor_name$,\n"); std::string module_name = ModuleName(file_->name()); - if (!opensource_runtime_) { - module_name = - std::string(absl::StripPrefix(module_name, kThirdPartyPrefix)); - } printer_->Print("'__module__' : '$module_name$'\n", "module_name", module_name); printer_->Print("# @@protoc_insertion_point(class_scope:$full_name$)\n", @@ -951,7 +894,7 @@ std::string Generator::FieldReferencingExpression( if (!containing_type) { return ResolveKeyword(field.name()); } - return absl::Substitute("$0.$1['$2']", + return strings::Substitute("$0.$1['$2']", ModuleLevelDescriptorName(*containing_type), python_dict_name, field.name()); } @@ -1048,8 +991,8 @@ void Generator::PrintEnumValueDescriptor( descriptor.options().SerializeToString(&options_string); std::map m; m["name"] = descriptor.name(); - m["index"] = absl::StrCat(descriptor.index()); - m["number"] = absl::StrCat(descriptor.number()); + m["index"] = StrCat(descriptor.index()); + m["number"] = StrCat(descriptor.number()); m["options"] = OptionsValue(options_string); printer_->Print(m, "_descriptor.EnumValueDescriptor(\n" @@ -1065,7 +1008,7 @@ std::string Generator::OptionsValue( if (serialized_options.length() == 0 || GeneratingDescriptorProto()) { return "None"; } else { - return "b'" + absl::CEscape(serialized_options) + "'"; + return "b'" + CEscape(serialized_options) + "'"; } } @@ -1077,11 +1020,11 @@ void Generator::PrintFieldDescriptor(const FieldDescriptor& field, std::map m; m["name"] = field.name(); m["full_name"] = field.full_name(); - m["index"] = absl::StrCat(field.index()); - m["number"] = absl::StrCat(field.number()); - m["type"] = absl::StrCat(field.type()); - m["cpp_type"] = absl::StrCat(field.cpp_type()); - m["label"] = absl::StrCat(field.label()); + m["index"] = StrCat(field.index()); + m["number"] = StrCat(field.number()); + m["type"] = StrCat(field.type()); + m["cpp_type"] = StrCat(field.cpp_type()); + m["label"] = StrCat(field.label()); m["has_default_value"] = field.has_default_value() ? "True" : "False"; m["default_value"] = StringifyDefaultValue(field); m["is_extension"] = is_extension ? "True" : "False"; @@ -1163,7 +1106,7 @@ std::string Generator::ModuleLevelDescriptorName( // The C++ implementation doesn't guard against this either. Leaving // it for now... std::string name = NamePrefixedWithNestedTypes(descriptor, "_"); - absl::AsciiStrToUpper(&name); + ToUpper(&name); // Module-private for now. Easy to make public later; almost impossible // to make private later. name = "_" + name; @@ -1193,7 +1136,7 @@ std::string Generator::ModuleLevelMessageName( std::string Generator::ModuleLevelServiceDescriptorName( const ServiceDescriptor& descriptor) const { std::string name = descriptor.name(); - absl::AsciiStrToUpper(&name); + ToUpper(&name); name = "_" + name; if (descriptor.file() != file_) { name = ModuleAlias(descriptor.file()->name()) + "." + name; @@ -1201,16 +1144,6 @@ std::string Generator::ModuleLevelServiceDescriptorName( return name; } -std::string Generator::PublicPackage() const { - return opensource_runtime_ ? "google.protobuf" - : "google3.net.google.protobuf.python.public"; -} - -std::string Generator::InternalPackage() const { - return opensource_runtime_ ? "google.protobuf.internal" - : "google3.net.google.protobuf.python.internal"; -} - // Prints standard constructor arguments serialized_start and serialized_end. // Args: // descriptor: The cpp descriptor to have a serialized reference. @@ -1232,8 +1165,8 @@ void Generator::PrintSerializedPbInterval(const DescriptorT& descriptor, printer_->Print( "$name$._serialized_start=$serialized_start$\n" "$name$._serialized_end=$serialized_end$\n", - "name", name, "serialized_start", absl::StrCat(offset), "serialized_end", - absl::StrCat(offset + sp.size())); + "name", name, "serialized_start", StrCat(offset), "serialized_end", + StrCat(offset + sp.size())); } namespace { @@ -1323,7 +1256,7 @@ void Generator::FixAllDescriptorOptions() const { void Generator::FixOptionsForOneof(const OneofDescriptor& oneof) const { std::string oneof_options = OptionsValue(oneof.options().SerializeAsString()); if (oneof_options != "None") { - std::string oneof_name = absl::Substitute( + std::string oneof_name = strings::Substitute( "$0.$1['$2']", ModuleLevelDescriptorName(*oneof.containing_type()), "oneofs_by_name", oneof.name()); PrintDescriptorOptionsFixingCode(oneof_name, oneof_options, printer_); @@ -1345,7 +1278,7 @@ void Generator::FixOptionsForEnum(const EnumDescriptor& enum_descriptor) const { OptionsValue(value_descriptor.options().SerializeAsString()); if (value_options != "None") { PrintDescriptorOptionsFixingCode( - absl::StrFormat("%s.values_by_name[\"%s\"]", descriptor_name.c_str(), + StringPrintf("%s.values_by_name[\"%s\"]", descriptor_name.c_str(), value_descriptor.name().c_str()), value_options, printer_); } diff --git a/libs/protobuf/src/google/protobuf/compiler/python/generator.h b/libs/protobuf/src/google/protobuf/compiler/python/generator.h index 3fa946d..f1fecbc 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/python/generator.h @@ -37,11 +37,11 @@ #include -#include "absl/synchronization/mutex.h" -#include "google/protobuf/compiler/code_generator.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -64,18 +64,9 @@ namespace python { // If you create your own protocol compiler binary and you want it to support // Python output, you can do so by registering an instance of this // CodeGenerator with the CommandLineInterface in your main() function. - -struct GeneratorOptions { - bool generate_pyi = false; - bool annotate_pyi = false; - bool bootstrap = false; -}; - class PROTOC_EXPORT Generator : public CodeGenerator { public: Generator(); - Generator(const Generator&) = delete; - Generator& operator=(const Generator&) = delete; ~Generator() override; // CodeGenerator methods. @@ -85,13 +76,7 @@ class PROTOC_EXPORT Generator : public CodeGenerator { uint64_t GetSupportedFeatures() const override; - void set_opensource_runtime(bool opensource) { - opensource_runtime_ = opensource; - } - private: - GeneratorOptions ParseParameter(const std::string& parameter, - std::string* error) const; void PrintImports() const; void PrintFileDescriptor() const; void PrintAllNestedEnumsInFile() const; @@ -143,7 +128,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { const FieldDescriptor& extension_field) const; void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const; - void PrintTopBoilerplate() const; void PrintServices() const; void PrintServiceDescriptors() const; void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; @@ -161,8 +145,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { std::string ModuleLevelMessageName(const Descriptor& descriptor) const; std::string ModuleLevelServiceDescriptorName( const ServiceDescriptor& descriptor) const; - std::string PublicPackage() const; - std::string InternalPackage() const; template void PrintSerializedPbInterval(const DescriptorT& descriptor, @@ -184,12 +166,13 @@ class PROTOC_EXPORT Generator : public CodeGenerator { // Very coarse-grained lock to ensure that Generate() is reentrant. // Guards file_, printer_ and file_descriptor_serialized_. - mutable absl::Mutex mutex_; + mutable Mutex mutex_; mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. mutable std::string file_descriptor_serialized_; mutable io::Printer* printer_; // Set in Generate(). Under mutex_. + mutable bool pure_python_workable_; - bool opensource_runtime_ = true; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); }; } // namespace python @@ -197,6 +180,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/python/helpers.cc b/libs/protobuf/src/google/protobuf/compiler/python/helpers.cc index e58ed9c..e4d3c13 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/helpers.cc +++ b/libs/protobuf/src/google/protobuf/compiler/python/helpers.cc @@ -28,18 +28,14 @@ // (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/compiler/python/helpers.h" +#include #include -#include "absl/strings/escaping.h" -#include "absl/strings/match.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/str_split.h" -#include "absl/strings/strip.h" -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -49,7 +45,8 @@ namespace python { // Returns the Python module name expected for a given .proto filename. std::string ModuleName(const std::string& filename) { std::string basename = StripProto(filename); - absl::StrReplaceAll({{"-", "_"}, {"/", "."}}, &basename); + ReplaceCharacters(&basename, "-", '_'); + ReplaceCharacters(&basename, "/", '.'); return basename + "_pb2"; } @@ -71,7 +68,7 @@ const char* const* kKeywordsEnd = kKeywords + (sizeof(kKeywords) / sizeof(kKeywords[0])); bool ContainsPythonKeyword(const std::string& module_name) { - std::vector tokens = absl::StrSplit(module_name, "."); + std::vector tokens = Split(module_name, "."); for (int i = 0; i < static_cast(tokens.size()); ++i) { if (std::find(kKeywords, kKeywordsEnd, tokens[i]) != kKeywordsEnd) { return true; @@ -95,7 +92,7 @@ std::string GetFileName(const FileDescriptor* file_des, const std::string& suffix) { std::string module_name = ModuleName(file_des->name()); std::string filename = module_name; - absl::StrReplaceAll({{".", "/"}}, &filename); + ReplaceCharacters(&filename, ".", '/'); filename += suffix; return filename; } @@ -104,12 +101,6 @@ bool HasGenericServices(const FileDescriptor* file) { return file->service_count() > 0 && file->options().py_generic_services(); } -std::string GeneratedCodeToBase64(const GeneratedCodeInfo& annotations) { - std::string result; - absl::Base64Escape(annotations.SerializeAsString(), &result); - return result; -} - template std::string NamePrefixedWithNestedTypes(const DescriptorT& descriptor, const std::string& separator) { diff --git a/libs/protobuf/src/google/protobuf/compiler/python/helpers.h b/libs/protobuf/src/google/protobuf/compiler/python/helpers.h index 3741fbb..a68ceb1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/helpers.h +++ b/libs/protobuf/src/google/protobuf/compiler/python/helpers.h @@ -33,15 +33,14 @@ #include -#include "absl/strings/str_replace.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" +#include namespace google { namespace protobuf { namespace compiler { namespace python { + std::string ModuleName(const std::string& filename); std::string StrippedModuleName(const std::string& filename); bool ContainsPythonKeyword(const std::string& module_name); @@ -50,7 +49,6 @@ std::string ResolveKeyword(const std::string& name); std::string GetFileName(const FileDescriptor* file_des, const std::string& suffix); bool HasGenericServices(const FileDescriptor* file); -std::string GeneratedCodeToBase64(const GeneratedCodeInfo& annotations); template std::string NamePrefixedWithNestedTypes(const DescriptorT& descriptor, diff --git a/libs/protobuf/src/google/protobuf/compiler/python/plugin_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/python/plugin_unittest.cc index b8f25cf..7f9589b 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/plugin_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/python/plugin_unittest.cc @@ -33,15 +33,15 @@ #include #include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/compiler/python/generator.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/str_split.h" namespace google { namespace protobuf { @@ -107,7 +107,7 @@ TEST(PythonPluginTest, ImportTest) { std::string output; GOOGLE_CHECK_OK(File::GetContents(TestTempDir() + "/test1_pb2.py", &output, true)); - std::vector lines = absl::StrSplit(output, "\n"); + std::vector lines = Split(output, "\n"); std::string expected_import = "import test2_pb2"; bool found_expected_import = false; for (int i = 0; i < lines.size(); ++i) { diff --git a/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.cc b/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.cc index b09ceb2..1ccc9a2 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.cc @@ -28,57 +28,61 @@ // (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/compiler/python/pyi_generator.h" +#include #include -#include -#include "absl/strings/ascii.h" -#include "absl/strings/match.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/compiler/python/helpers.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { namespace python { +template +struct SortByName { + bool operator()(const DescriptorT* l, const DescriptorT* r) const { + return l->name() < r->name(); + } +}; + PyiGenerator::PyiGenerator() : file_(nullptr) {} PyiGenerator::~PyiGenerator() {} +void PyiGenerator::PrintItemMap( + const std::map& item_map) const { + for (const auto& entry : item_map) { + printer_->Print("$key$: $value$\n", "key", entry.first, "value", + entry.second); + } +} + template -std::string PyiGenerator::ModuleLevelName(const DescriptorT& descriptor) const { +std::string PyiGenerator::ModuleLevelName( + const DescriptorT& descriptor, + const std::map& import_map) const { std::string name = NamePrefixedWithNestedTypes(descriptor, "."); if (descriptor.file() != file_) { std::string module_alias; std::string filename = descriptor.file()->name(); - if (import_map_.find(filename) == import_map_.end()) { + if (import_map.find(filename) == import_map.end()) { std::string module_name = ModuleName(descriptor.file()->name()); - std::vector tokens = absl::StrSplit(module_name, "."); + std::vector tokens = Split(module_name, "."); module_alias = "_" + tokens.back(); } else { - module_alias = import_map_.at(filename); + module_alias = import_map.at(filename); } name = module_alias + "." + name; } return name; } -std::string PyiGenerator::PublicPackage() const { - return opensource_runtime_ ? "google.protobuf" - : "google3.net.google.protobuf.python.public"; -} - -std::string PyiGenerator::InternalPackage() const { - return opensource_runtime_ ? "google.protobuf.internal" - : "google3.net.google.protobuf.python.internal"; -} - struct ImportModules { bool has_repeated = false; // _containers bool has_iterable = false; // typing.Iterable @@ -152,6 +156,7 @@ void CheckImportModules(const Descriptor* descriptor, void PyiGenerator::PrintImportForDescriptor( const FileDescriptor& desc, + std::map* import_map, std::set* seen_aliases) const { const std::string& filename = desc.name(); std::string module_name = StrippedModuleName(filename); @@ -171,19 +176,21 @@ void PyiGenerator::PrintImportForDescriptor( } printer_->Print("$statement$ as $alias$\n", "statement", import_statement, "alias", alias); - import_map_[filename] = alias; + (*import_map)[filename] = alias; seen_aliases->insert(alias); } -void PyiGenerator::PrintImports() const { +void PyiGenerator::PrintImports( + std::map* item_map, + std::map* import_map) const { // Prints imported dependent _pb2 files. std::set seen_aliases; for (int i = 0; i < file_->dependency_count(); ++i) { const FileDescriptor* dep = file_->dependency(i); - PrintImportForDescriptor(*dep, &seen_aliases); + PrintImportForDescriptor(*dep, import_map, &seen_aliases); for (int j = 0; j < dep->public_dependency_count(); ++j) { PrintImportForDescriptor( - *dep->public_dependency(j), &seen_aliases); + *dep->public_dependency(j), import_map, &seen_aliases); } } @@ -195,10 +202,6 @@ void PyiGenerator::PrintImports() const { if (file_->enum_type_count() > 0) { import_modules.has_enums = true; } - if (!opensource_runtime_ && file_->service_count() > 0) { - import_modules.has_optional = true; - import_modules.has_union = true; - } for (int i = 0; i < file_->message_type_count(); i++) { CheckImportModules(file_->message_type(i), &import_modules); } @@ -207,50 +210,37 @@ void PyiGenerator::PrintImports() const { // required in the proto file. if (import_modules.has_repeated) { printer_->Print( - "from $internal_package$ import containers as _containers\n", - "internal_package", InternalPackage()); + "from google.protobuf.internal import containers as " + "_containers\n"); } if (import_modules.has_enums) { printer_->Print( - "from $internal_package$ import enum_type_wrapper as " - "_enum_type_wrapper\n", - "internal_package", InternalPackage()); + "from google.protobuf.internal import enum_type_wrapper" + " as _enum_type_wrapper\n"); } if (import_modules.has_extendable) { printer_->Print( - "from $internal_package$ import python_message as _python_message\n", - "internal_package", InternalPackage()); + "from google.protobuf.internal import python_message" + " as _python_message\n"); } if (import_modules.has_well_known_type) { printer_->Print( - "from $internal_package$ import well_known_types as " - "_well_known_types\n", - "internal_package", InternalPackage()); + "from google.protobuf.internal import well_known_types" + " as _well_known_types\n"); } - printer_->Print("from $public_package$ import descriptor as _descriptor\n", - "public_package", PublicPackage()); + printer_->Print( + "from google.protobuf import" + " descriptor as _descriptor\n"); if (import_modules.has_messages) { - printer_->Print("from $public_package$ import message as _message\n", - "public_package", PublicPackage()); + printer_->Print( + "from google.protobuf import message as _message\n"); } - if (opensource_runtime_) { - if (HasGenericServices(file_)) { - printer_->Print("from $public_package$ import service as _service\n", - "public_package", PublicPackage()); - } - } else { - if (file_->service_count() > 0) { - printer_->Print( - "from google3.net.rpc.python import proto_python_api_2_stub as " - "_proto_python_api_2_stub\n" - "from google3.net.rpc.python import pywraprpc as _pywraprpc\n" - "from google3.net.rpc.python import rpcserver as _rpcserver\n"); - } + if (HasGenericServices(file_)) { + printer_->Print( + "from google.protobuf import service as" + " _service\n"); } printer_->Print("from typing import "); - if (!opensource_runtime_ && file_->service_count() > 0) { - printer_->Print("Any as _Any, "); - } printer_->Print("ClassVar as _ClassVar"); if (import_modules.has_iterable) { printer_->Print(", Iterable as _Iterable"); @@ -264,7 +254,7 @@ void PyiGenerator::PrintImports() const { if (import_modules.has_union) { printer_->Print(", Union as _Union"); } - printer_->Print("\n"); + printer_->Print("\n\n"); // Public imports for (int i = 0; i < file_->public_dependency_count(); ++i) { @@ -282,16 +272,17 @@ void PyiGenerator::PrintImports() const { module_name, "enum_class", public_dep->enum_type(i)->name()); } + // Enum values for public imports + for (int i = 0; i < public_dep->enum_type_count(); ++i) { + const EnumDescriptor* enum_descriptor = public_dep->enum_type(i); + for (int j = 0; j < enum_descriptor->value_count(); ++j) { + (*item_map)[enum_descriptor->value(j)->name()] = + ModuleLevelName(*enum_descriptor, *import_map); + } + } + // Top level extensions for public imports + AddExtensions(*public_dep, item_map); } -printer_->Print("\n"); -} - -// Annotate wrapper for debugging purposes -// Print a message after Annotate to see what is annotated. -template -void PyiGenerator::Annotate(const std::string& label, - const DescriptorT* descriptor) const { -printer_->Annotate(label.c_str(), descriptor); } void PyiGenerator::PrintEnum(const EnumDescriptor& enum_descriptor) const { @@ -300,22 +291,22 @@ void PyiGenerator::PrintEnum(const EnumDescriptor& enum_descriptor) const { "class $enum_name$(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):\n" " __slots__ = []\n", "enum_name", enum_name); - Annotate("enum_name", &enum_descriptor); } -void PyiGenerator::PrintEnumValues( - const EnumDescriptor& enum_descriptor) const { +// Adds enum value to item map which will be ordered and printed later. +void PyiGenerator::AddEnumValue( + const EnumDescriptor& enum_descriptor, + std::map* item_map, + const std::map& import_map) const { // enum values - std::string module_enum_name = ModuleLevelName(enum_descriptor); + std::string module_enum_name = ModuleLevelName(enum_descriptor, import_map); for (int j = 0; j < enum_descriptor.value_count(); ++j) { const EnumValueDescriptor* value_descriptor = enum_descriptor.value(j); - printer_->Print("$name$: $module_enum_name$\n", - "name", value_descriptor->name(), - "module_enum_name", module_enum_name); - Annotate("name", value_descriptor); + (*item_map)[value_descriptor->name()] = module_enum_name; } } +// Prints top level enums void PyiGenerator::PrintTopLevelEnums() const { for (int i = 0; i < file_->enum_type_count(); ++i) { printer_->Print("\n"); @@ -323,23 +314,25 @@ void PyiGenerator::PrintTopLevelEnums() const { } } +// Add top level extensions to item_map which will be ordered and +// printed later. template -void PyiGenerator::PrintExtensions(const DescriptorT& descriptor) const { +void PyiGenerator::AddExtensions( + const DescriptorT& descriptor, + std::map* item_map) const { for (int i = 0; i < descriptor.extension_count(); ++i) { const FieldDescriptor* extension_field = descriptor.extension(i); std::string constant_name = extension_field->name() + "_FIELD_NUMBER"; - absl::AsciiStrToUpper(&constant_name); - printer_->Print("$constant_name$: _ClassVar[int]\n", - "constant_name", constant_name); - printer_->Print("$name$: _descriptor.FieldDescriptor\n", - "name", extension_field->name()); - Annotate("name", extension_field); + ToUpper(&constant_name); + (*item_map)[constant_name] = "_ClassVar[int]"; + (*item_map)[extension_field->name()] = "_descriptor.FieldDescriptor"; } } // Returns the string format of a field's cpp_type std::string PyiGenerator::GetFieldType( - const FieldDescriptor& field_des, const Descriptor& containing_des) const { + const FieldDescriptor& field_des, const Descriptor& containing_des, + const std::map& import_map) const { switch (field_des.cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: case FieldDescriptor::CPPTYPE_UINT32: @@ -352,7 +345,7 @@ std::string PyiGenerator::GetFieldType( case FieldDescriptor::CPPTYPE_BOOL: return "bool"; case FieldDescriptor::CPPTYPE_ENUM: - return ModuleLevelName(*field_des.enum_type()); + return ModuleLevelName(*field_des.enum_type(), import_map); case FieldDescriptor::CPPTYPE_STRING: if (field_des.type() == FieldDescriptor::TYPE_STRING) { return "str"; @@ -363,7 +356,7 @@ std::string PyiGenerator::GetFieldType( // If the field is inside a nested message and the nested message has the // same name as a top-level message, then we need to prefix the field type // with the module name for disambiguation. - std::string name = ModuleLevelName(*field_des.message_type()); + std::string name = ModuleLevelName(*field_des.message_type(), import_map); if ((containing_des.containing_type() != nullptr && name == containing_des.name())) { std::string module = ModuleName(field_des.file()->name()); @@ -378,7 +371,8 @@ std::string PyiGenerator::GetFieldType( } void PyiGenerator::PrintMessage( - const Descriptor& message_descriptor, bool is_nested) const { + const Descriptor& message_descriptor, bool is_nested, + const std::map& import_map) const { if (!is_nested) { printer_->Print("\n"); } @@ -393,15 +387,20 @@ void PyiGenerator::PrintMessage( } printer_->Print("class $class_name$(_message.Message$extra_base$):\n", "class_name", class_name, "extra_base", extra_base); - Annotate("class_name", &message_descriptor); printer_->Indent(); printer_->Indent(); + std::vector fields; + fields.reserve(message_descriptor.field_count()); + for (int i = 0; i < message_descriptor.field_count(); ++i) { + fields.push_back(message_descriptor.field(i)); + } + std::sort(fields.begin(), fields.end(), SortByName()); + // Prints slots printer_->Print("__slots__ = [", "class_name", class_name); bool first_item = true; - for (int i = 0; i < message_descriptor.field_count(); ++i) { - const FieldDescriptor* field_des = message_descriptor.field(i); + for (const auto& field_des : fields) { if (IsPythonKeyword(field_des->name())) { continue; } @@ -414,34 +413,48 @@ void PyiGenerator::PrintMessage( } printer_->Print("]\n"); + std::map item_map; // Prints Extensions for extendable messages if (message_descriptor.extension_range_count() > 0) { - printer_->Print("Extensions: _python_message._ExtensionDict\n"); + item_map["Extensions"] = "_python_message._ExtensionDict"; } // Prints nested enums + std::vector nested_enums; + nested_enums.reserve(message_descriptor.enum_type_count()); for (int i = 0; i < message_descriptor.enum_type_count(); ++i) { - PrintEnum(*message_descriptor.enum_type(i)); - PrintEnumValues(*message_descriptor.enum_type(i)); + nested_enums.push_back(message_descriptor.enum_type(i)); + } + std::sort(nested_enums.begin(), nested_enums.end(), + SortByName()); + + for (const auto& entry : nested_enums) { + PrintEnum(*entry); + // Adds enum value to item_map which will be ordered and printed later + AddEnumValue(*entry, &item_map, import_map); } // Prints nested messages + std::vector nested_messages; + nested_messages.reserve(message_descriptor.nested_type_count()); for (int i = 0; i < message_descriptor.nested_type_count(); ++i) { - PrintMessage(*message_descriptor.nested_type(i), true); + nested_messages.push_back(message_descriptor.nested_type(i)); + } + std::sort(nested_messages.begin(), nested_messages.end(), + SortByName()); + + for (const auto& entry : nested_messages) { + PrintMessage(*entry, true, import_map); } - PrintExtensions(message_descriptor); + // Adds extensions to item_map which will be ordered and printed later + AddExtensions(message_descriptor, &item_map); - // Prints field number - for (int i = 0; i < message_descriptor.field_count(); ++i) { - const FieldDescriptor& field_des = *message_descriptor.field(i); - printer_->Print( - "$field_number_name$: _ClassVar[int]\n", "field_number_name", - absl::AsciiStrToUpper(field_des.name()) + "_FIELD_NUMBER"); - } - // Prints field name and type + // Adds field number and field descriptor to item_map for (int i = 0; i < message_descriptor.field_count(); ++i) { const FieldDescriptor& field_des = *message_descriptor.field(i); + item_map[ToUpper(field_des.name()) + "_FIELD_NUMBER"] = + "_ClassVar[int]"; if (IsPythonKeyword(field_des.name())) { continue; } @@ -452,26 +465,27 @@ void PyiGenerator::PrintMessage( field_type = (value_des->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? "_containers.MessageMap[" : "_containers.ScalarMap["); - field_type += GetFieldType(*key_des, message_descriptor); + field_type += GetFieldType(*key_des, message_descriptor, import_map); field_type += ", "; - field_type += GetFieldType(*value_des, message_descriptor); + field_type += GetFieldType(*value_des, message_descriptor, import_map); } else { if (field_des.is_repeated()) { field_type = (field_des.cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ? "_containers.RepeatedCompositeFieldContainer[" : "_containers.RepeatedScalarFieldContainer["); } - field_type += GetFieldType(field_des, message_descriptor); + field_type += GetFieldType(field_des, message_descriptor, import_map); } if (field_des.is_repeated()) { field_type += "]"; } - printer_->Print("$name$: $type$\n", - "name", field_des.name(), "type", field_type); - Annotate("name", &field_des); + item_map[field_des.name()] = field_type; } + // Prints all items in item_map + PrintItemMap(item_map); + // Prints __init__ printer_->Print("def __init__(self"); bool has_key_words = false; @@ -491,7 +505,6 @@ void PyiGenerator::PrintMessage( } is_first = false; printer_->Print(", $field_name$: ", "field_name", field_name); - Annotate("field_name", field_des); if (field_des->is_repeated() || field_des->cpp_type() != FieldDescriptor::CPPTYPE_BOOL) { printer_->Print("_Optional["); @@ -500,9 +513,9 @@ void PyiGenerator::PrintMessage( const Descriptor* map_entry = field_des->message_type(); printer_->Print( "_Mapping[$key_type$, $value_type$]", "key_type", - GetFieldType(*map_entry->field(0), message_descriptor), + GetFieldType(*map_entry->field(0), message_descriptor, import_map), "value_type", - GetFieldType(*map_entry->field(1), message_descriptor)); + GetFieldType(*map_entry->field(1), message_descriptor, import_map)); } else { if (field_des->is_repeated()) { printer_->Print("_Iterable["); @@ -510,15 +523,15 @@ void PyiGenerator::PrintMessage( if (field_des->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer_->Print( "_Union[$type_name$, _Mapping]", "type_name", - GetFieldType(*field_des, message_descriptor)); + GetFieldType(*field_des, message_descriptor, import_map)); } else { if (field_des->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer_->Print("_Union[$type_name$, str]", "type_name", - ModuleLevelName(*field_des->enum_type())); + ModuleLevelName(*field_des->enum_type(), import_map)); } else { printer_->Print( "$type_name$", "type_name", - GetFieldType(*field_des, message_descriptor)); + GetFieldType(*field_des, message_descriptor, import_map)); } } if (field_des->is_repeated()) { @@ -540,87 +553,78 @@ void PyiGenerator::PrintMessage( printer_->Outdent(); } -void PyiGenerator::PrintMessages() const { +void PyiGenerator::PrintMessages( + const std::map& import_map) const { // Deterministically order the descriptors. + std::vector messages; + messages.reserve(file_->message_type_count()); for (int i = 0; i < file_->message_type_count(); ++i) { - PrintMessage(*file_->message_type(i), false); + messages.push_back(file_->message_type(i)); + } + std::sort(messages.begin(), messages.end(), SortByName()); + + for (const auto& entry : messages) { + PrintMessage(*entry, false, import_map); } } void PyiGenerator::PrintServices() const { - // Prints $Service$ and $Service$_Stub classes + std::vector services; + services.reserve(file_->service_count()); for (int i = 0; i < file_->service_count(); ++i) { + services.push_back(file_->service(i)); + } + std::sort(services.begin(), services.end(), SortByName()); + + // Prints $Service$ and $Service$_Stub classes + for (const auto& entry : services) { printer_->Print("\n"); printer_->Print( "class $service_name$(_service.service): ...\n\n" "class $service_name$_Stub($service_name$): ...\n", - "service_name", file_->service(i)->name()); + "service_name", entry->name()); } } - bool PyiGenerator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* context, std::string* error) const { - absl::MutexLock lock(&mutex_); - import_map_.clear(); + MutexLock lock(&mutex_); // Calculate file name. file_ = file; - // In google3, devtools/python/blaze/pytype/pytype_impl.bzl uses --pyi_out to - // directly set the output file name. - std::vector > options; - ParseGeneratorParameter(parameter, &options); - - std::string filename; - bool annotate_code = false; - for (const std::pair& option : options) { - if (option.first == "annotate_code") { - annotate_code = true; - } else if (absl::EndsWith(option.first, ".pyi")) { - filename = option.first; - } else { - *error = "Unknown generator option: " + option.first; - return false; - } - } - - if (filename.empty()) { - filename = GetFileName(file, ".pyi"); - } + std::string filename = + parameter.empty() ? GetFileName(file, ".pyi") : parameter; std::unique_ptr output(context->Open(filename)); GOOGLE_CHECK(output.get()); - GeneratedCodeInfo annotations; - io::AnnotationProtoCollector annotation_collector( - &annotations); - io::Printer printer(output.get(), '$', - annotate_code ? &annotation_collector : nullptr); + io::Printer printer(output.get(), '$'); printer_ = &printer; - PrintImports(); - printer_->Print("DESCRIPTOR: _descriptor.FileDescriptor\n"); + // item map will store "DESCRIPTOR", top level extensions, top level enum + // values. The items will be sorted and printed later. + std::map item_map; - // Prints extensions and enums from imports. - for (int i = 0; i < file_->public_dependency_count(); ++i) { - const FileDescriptor* public_dep = file_->public_dependency(i); - PrintExtensions(*public_dep); - for (int i = 0; i < public_dep->enum_type_count(); ++i) { - const EnumDescriptor* enum_descriptor = public_dep->enum_type(i); - PrintEnumValues(*enum_descriptor); - } - } + // Adds "DESCRIPTOR" into item_map. + item_map["DESCRIPTOR"] = "_descriptor.FileDescriptor"; - PrintTopLevelEnums(); - // Prints top level enum values + // import_map will be a mapping from filename to module alias, e.g. + // "google3/foo/bar.py" -> "_bar" + std::map import_map; + + PrintImports(&item_map, &import_map); + // Adds top level enum values to item_map. for (int i = 0; i < file_->enum_type_count(); ++i) { - PrintEnumValues(*file_->enum_type(i)); + AddEnumValue(*file_->enum_type(i), &item_map, import_map); } - // Prints top level Extensions - PrintExtensions(*file_); - PrintMessages(); + // Adds top level extensions to item_map. + AddExtensions(*file_, &item_map); + // Prints item map + PrintItemMap(item_map); - if (opensource_runtime_ && HasGenericServices(file)) { + PrintMessages(import_map); + PrintTopLevelEnums(); + if (HasGenericServices(file)) { PrintServices(); } return true; diff --git a/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.h b/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.h index 7f1e5d8..9611ed4 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/python/pyi_generator.h @@ -39,11 +39,11 @@ #include #include -#include "absl/synchronization/mutex.h" -#include "google/protobuf/compiler/code_generator.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -63,8 +63,6 @@ namespace python { class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenerator { public: PyiGenerator(); - PyiGenerator(const PyiGenerator&) = delete; - PyiGenerator& operator=(const PyiGenerator&) = delete; ~PyiGenerator() override; // CodeGenerator methods. @@ -78,35 +76,38 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera private: void PrintImportForDescriptor(const FileDescriptor& desc, + std::map* import_map, std::set* seen_aliases) const; - template - void Annotate(const std::string& label, const DescriptorT* descriptor) const; - void PrintImports() const; - void PrintTopLevelEnums() const; + void PrintImports(std::map* item_map, + std::map* import_map) const; void PrintEnum(const EnumDescriptor& enum_descriptor) const; - void PrintEnumValues(const EnumDescriptor& enum_descriptor) const; + void AddEnumValue(const EnumDescriptor& enum_descriptor, + std::map* item_map, + const std::map& import_map) const; + void PrintTopLevelEnums() const; template - void PrintExtensions(const DescriptorT& descriptor) const; - void PrintMessages() const; - void PrintMessage(const Descriptor& message_descriptor, bool is_nested) const; + void AddExtensions(const DescriptorT& descriptor, + std::map* item_map) const; + void PrintMessages( + const std::map& import_map) const; + void PrintMessage(const Descriptor& message_descriptor, bool is_nested, + const std::map& import_map) const; void PrintServices() const; + void PrintItemMap(const std::map& item_map) const; std::string GetFieldType( - const FieldDescriptor& field_des, const Descriptor& containing_des) const; + const FieldDescriptor& field_des, const Descriptor& containing_des, + const std::map& import_map) const; template - std::string ModuleLevelName(const DescriptorT& descriptor) const; - std::string PublicPackage() const; - std::string InternalPackage() const; - - bool opensource_runtime_ = true; + std::string ModuleLevelName( + const DescriptorT& descriptor, + const std::map& import_map) const; // Very coarse-grained lock to ensure that Generate() is reentrant. - // Guards file_, printer_, and import_map_. - mutable absl::Mutex mutex_; + // Guards file_ and printer_. + mutable Mutex mutex_; mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. mutable io::Printer* printer_; // Set in Generate(). Under mutex_. - // import_map will be a mapping from filename to module alias, e.g. - // "google3/foo/bar.py" -> "_bar" - mutable std::map import_map_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PyiGenerator); }; } // namespace python @@ -114,6 +115,6 @@ class PROTOC_EXPORT PyiGenerator : public google::protobuf::compiler::CodeGenera } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_PYI_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/python/python_generator.h b/libs/protobuf/src/google/protobuf/compiler/python/python_generator.h index a46cf5e..21d48cd 100644 --- a/libs/protobuf/src/google/protobuf/compiler/python/python_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/python/python_generator.h @@ -1,36 +1,6 @@ -// 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_COMPILER_PYTHON_PYTHON_GENERATOR_H_ #define GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ -#include "google/protobuf/compiler/python/generator.h" +#include #endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_PYTHON_GENERATOR_H_ diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/BUILD.bazel b/libs/protobuf/src/google/protobuf/compiler/ruby/BUILD.bazel deleted file mode 100644 index 7abfeb6..0000000 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/BUILD.bazel +++ /dev/null @@ -1,70 +0,0 @@ -################################################################################ -# Protocol Buffers Compiler - Ruby code generator -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "ruby", - srcs = ["ruby_generator.cc"], - hdrs = ["ruby_generator.h"], - copts = COPTS, - include_prefix = "google/protobuf/compiler/ruby", - visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/compiler:__pkg__", - ], - deps = [ - "//src/google/protobuf:protobuf_nowkt", - "//src/google/protobuf/compiler:code_generator", - ], -) - -cc_test( - name = "generator_unittest", - srcs = ["ruby_generator_unittest.cc"], - data = [ - "ruby_generated_code.proto", - "ruby_generated_code_pb.rb", - "ruby_generated_code_proto2.proto", - "ruby_generated_code_proto2_import.proto", - "ruby_generated_code_proto2_pb.rb", - "ruby_generated_pkg_explicit.proto", - "ruby_generated_pkg_explicit_legacy.proto", - "ruby_generated_pkg_explicit_legacy_pb.rb", - "ruby_generated_pkg_explicit_pb.rb", - "ruby_generated_pkg_implicit.proto", - "ruby_generated_pkg_implicit_pb.rb", - "//src/google/protobuf:testdata", - ], - deps = [ - ":ruby", - "//src/google/protobuf/compiler:command_line_interface", - "//src/google/protobuf/io", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//src/google/protobuf/compiler:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto index 56173c2..70ec9f1 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto3"; package A.B.C; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto index cd4955d..ea7f783 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto2"; package A.B.C; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto index 9fc1719..9ec0738 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_import.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto2"; package A.B.C; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto index 153cec6..8d7c948 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto3"; package one.two.a_three; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto index 6515634..7a0d260 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto3"; package one.two.a_three.and; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto index 23eaa43..544db64 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit.proto @@ -1,33 +1,3 @@ -// 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. - syntax = "proto3"; package one.two.a_three; diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc index be643d8..d4a53d5 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -28,17 +28,17 @@ // (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/compiler/ruby/ruby_generator.h" - #include #include -#include "google/protobuf/compiler/code_generator.h" -#include "google/protobuf/compiler/plugin.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include + +#include namespace google { namespace protobuf { @@ -68,7 +68,7 @@ std::string NumberToString(numeric_type value) { } std::string GetRequireName(const std::string& proto_file) { - int lastindex = proto_file.find_last_of('.'); + int lastindex = proto_file.find_last_of("."); return proto_file.substr(0, lastindex) + "_pb"; } @@ -421,7 +421,7 @@ int GeneratePackageModules(const FileDescriptor* file, io::Printer* printer) { // -> A.B.C if (package_name.find("::") != std::string::npos) { need_change_to_module = false; - } else if (package_name.find('.') != std::string::npos) { + } else if (package_name.find(".") != std::string::npos) { GOOGLE_LOG(WARNING) << "ruby_package option should be in the form of:" << " 'A::B::C' and not 'A.B.C'"; } diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h index a6881ff..647bb83 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h @@ -35,9 +35,9 @@ #include -#include "google/protobuf/compiler/code_generator.h" +#include -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -62,6 +62,6 @@ class PROTOC_EXPORT Generator : public CodeGenerator { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc index 31d3770..c3ce1d3 100644 --- a/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc +++ b/libs/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc @@ -28,17 +28,17 @@ // (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/compiler/ruby/ruby_generator.h" - -#include #include +#include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include + +#include #include -#include "google/protobuf/compiler/command_line_interface.h" -#include "google/protobuf/io/printer.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/scc.h b/libs/protobuf/src/google/protobuf/compiler/scc.h index 2408dcd..7b95689 100644 --- a/libs/protobuf/src/google/protobuf/compiler/scc.h +++ b/libs/protobuf/src/google/protobuf/compiler/scc.h @@ -33,12 +33,12 @@ #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -64,8 +64,6 @@ template class PROTOC_EXPORT SCCAnalyzer { public: explicit SCCAnalyzer() : index_(0) {} - SCCAnalyzer(const SCCAnalyzer&) = delete; - SCCAnalyzer& operator=(const SCCAnalyzer&) = delete; const SCC* GetSCC(const Descriptor* descriptor) { if (cache_.count(descriptor)) return cache_[descriptor].scc; @@ -153,12 +151,15 @@ class PROTOC_EXPORT SCCAnalyzer { } } } + + // This is necessary for compiler bug in msvc2015. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SCCAnalyzer); }; } // namespace compiler } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_SCC_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/subprocess.cc b/libs/protobuf/src/google/protobuf/compiler/subprocess.cc index ae1f5dd..6f547db 100644 --- a/libs/protobuf/src/google/protobuf/compiler/subprocess.cc +++ b/libs/protobuf/src/google/protobuf/compiler/subprocess.cc @@ -30,7 +30,7 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/compiler/subprocess.h" +#include #include #include @@ -43,17 +43,26 @@ #include #endif -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/strings/escaping.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/message.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { namespace compiler { +namespace { +char* portable_strdup(const char* s) { + char* ns = (char*)malloc(strlen(s) + 1); + if (ns != nullptr) { + strcpy(ns, s); + } + return ns; +} +} // namespace + #ifdef _WIN32 static void CloseHandleOrDie(HANDLE handle) { @@ -264,12 +273,12 @@ bool Subprocess::Communicate(const Message& input, Message* output, child_handle_ = nullptr; if (exit_code != 0) { - *error = absl::Substitute("Plugin failed with status code $0.", exit_code); + *error = strings::Substitute("Plugin failed with status code $0.", exit_code); return false; } if (!output->ParseFromString(output_data)) { - *error = "Plugin output is unparseable: " + absl::CEscape(output_data); + *error = "Plugin output is unparseable: " + CEscape(output_data); return false; } @@ -308,16 +317,6 @@ Subprocess::~Subprocess() { } } -namespace { -char* portable_strdup(const char* s) { - char* ns = (char*)malloc(strlen(s) + 1); - if (ns != nullptr) { - strcpy(ns, s); - } - return ns; -} -} // namespace - void Subprocess::Start(const std::string& program, SearchMode search_mode) { // Note that we assume that there are no other threads, thus we don't have to // do crazy stuff like using socket pairs or avoiding libc locks. @@ -472,12 +471,12 @@ bool Subprocess::Communicate(const Message& input, Message* output, if (WEXITSTATUS(status) != 0) { int error_code = WEXITSTATUS(status); *error = - absl::Substitute("Plugin failed with status code $0.", error_code); + strings::Substitute("Plugin failed with status code $0.", error_code); return false; } } else if (WIFSIGNALED(status)) { int signal = WTERMSIG(status); - *error = absl::Substitute("Plugin killed by signal $0.", signal); + *error = strings::Substitute("Plugin killed by signal $0.", signal); return false; } else { *error = "Neither WEXITSTATUS nor WTERMSIG is true?"; @@ -485,7 +484,7 @@ bool Subprocess::Communicate(const Message& input, Message* output, } if (!output->ParseFromString(output_data)) { - *error = "Plugin output is unparseable: " + absl::CEscape(output_data); + *error = "Plugin output is unparseable: " + CEscape(output_data); return false; } diff --git a/libs/protobuf/src/google/protobuf/compiler/subprocess.h b/libs/protobuf/src/google/protobuf/compiler/subprocess.h index b6bf282..5cb784d 100644 --- a/libs/protobuf/src/google/protobuf/compiler/subprocess.h +++ b/libs/protobuf/src/google/protobuf/compiler/subprocess.h @@ -42,12 +42,12 @@ #include #include #endif // !_WIN32 +#include + #include -#include "google/protobuf/port.h" - // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -109,6 +109,6 @@ class PROTOC_EXPORT Subprocess { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMPILER_SUBPROCESS_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/test_plugin.cc b/libs/protobuf/src/google/protobuf/compiler/test_plugin.cc index 2ed1e3d..2556078 100644 --- a/libs/protobuf/src/google/protobuf/compiler/test_plugin.cc +++ b/libs/protobuf/src/google/protobuf/compiler/test_plugin.cc @@ -37,8 +37,8 @@ #include -#include "google/protobuf/compiler/mock_code_generator.h" -#include "google/protobuf/compiler/plugin.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/zip_writer.cc b/libs/protobuf/src/google/protobuf/compiler/zip_writer.cc index 73b9ef5..72e1d71 100644 --- a/libs/protobuf/src/google/protobuf/compiler/zip_writer.cc +++ b/libs/protobuf/src/google/protobuf/compiler/zip_writer.cc @@ -33,11 +33,11 @@ // // Based on http://www.pkware.com/documents/casestudies/APPNOTE.TXT -#include "google/protobuf/compiler/zip_writer.h" +#include #include -#include "google/protobuf/io/coded_stream.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/compiler/zip_writer.h b/libs/protobuf/src/google/protobuf/compiler/zip_writer.h index 89717c7..5d7f69a 100644 --- a/libs/protobuf/src/google/protobuf/compiler/zip_writer.h +++ b/libs/protobuf/src/google/protobuf/compiler/zip_writer.h @@ -35,8 +35,8 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/descriptor.cc b/libs/protobuf/src/google/protobuf/descriptor.cc index a65ba74..5f3427d 100644 --- a/libs/protobuf/src/google/protobuf/descriptor.cc +++ b/libs/protobuf/src/google/protobuf/descriptor.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/descriptor.h" +#include #include #include @@ -44,47 +44,53 @@ #include #include #include +#include +#include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/base/call_once.h" -#include "absl/base/casts.h" -#include "absl/base/dynamic_annotations.h" -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" -#include "absl/hash/hash.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_join.h" -#include "absl/strings/str_split.h" -#include "absl/strings/substitute.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/any.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor_database.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/io/strtod.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/port.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef PACKAGE // autoheader #defines this. :( // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { -namespace { -using ::google::protobuf::internal::DownCast; +namespace { const int kPackageLimit = 100; +// Note: I distrust ctype.h due to locales. +char ToUpper(char ch) { + return (ch >= 'a' && ch <= 'z') ? (ch - 'a' + 'A') : ch; +} + +char ToLower(char ch) { + return (ch >= 'A' && ch <= 'Z') ? (ch - 'A' + 'a') : ch; +} std::string ToCamelCase(const std::string& input, bool lower_first) { bool capitalize_next = !lower_first; @@ -95,7 +101,7 @@ std::string ToCamelCase(const std::string& input, bool lower_first) { if (character == '_') { capitalize_next = true; } else if (capitalize_next) { - result.push_back(absl::ascii_toupper(character)); + result.push_back(ToUpper(character)); capitalize_next = false; } else { result.push_back(character); @@ -104,7 +110,7 @@ std::string ToCamelCase(const std::string& input, bool lower_first) { // Lower-case the first letter. if (lower_first && !result.empty()) { - result[0] = absl::ascii_tolower(result[0]); + result[0] = ToLower(result[0]); } return result; @@ -119,7 +125,7 @@ std::string ToJsonName(const std::string& input) { if (character == '_') { capitalize_next = true; } else if (capitalize_next) { - result.push_back(absl::ascii_toupper(character)); + result.push_back(ToUpper(character)); capitalize_next = false; } else { result.push_back(character); @@ -424,13 +430,13 @@ class FlatAllocatorImpl { } std::string lowercase_name = name; - absl::AsciiStrToLower(&lowercase_name); + LowerString(&lowercase_name); std::string camelcase_name = ToCamelCase(name, /* lower_first = */ true); std::string json_name = opt_json_name != nullptr ? *opt_json_name : ToJsonName(name); - absl::string_view all_names[] = {name, lowercase_name, camelcase_name, + StringPiece all_names[] = {name, lowercase_name, camelcase_name, json_name}; std::sort(all_names, all_names + 4); int unique = @@ -451,7 +457,7 @@ class FlatAllocatorImpl { GOOGLE_CHECK(has_allocated()); std::string full_name = - scope.empty() ? name : absl::StrCat(scope, ".", name); + scope.empty() ? name : StrCat(scope, ".", name); // Fast path for snake_case names, which follow the style guide. if (opt_json_name == nullptr) { @@ -488,7 +494,7 @@ class FlatAllocatorImpl { FieldNamesResult result{nullptr, 0, 0, 0}; std::string lowercase_name = name; - absl::AsciiStrToLower(&lowercase_name); + LowerString(&lowercase_name); result.lowercase_index = push_name(std::move(lowercase_name)); result.camelcase_index = push_name(ToCamelCase(name, /* lower_first = */ true)); @@ -569,6 +575,7 @@ class Symbol { METHOD, FULL_PACKAGE, SUB_PACKAGE, + QUERY_KEY }; Symbol() { @@ -634,6 +641,35 @@ class Symbol { : nullptr; } + // Not a real symbol. + // Only used for heterogeneous lookups and never actually inserted in the + // tables. + // TODO(b/215557658): If we templetize QueryKey on the expected object type we + // can skip the switches for the eq function altogether. + struct QueryKey : internal::SymbolBase { + StringPiece name; + const void* parent; + int field_number; + + // Adaptor functions to look like a Symbol to the comparators. + StringPiece full_name() const { return name; } + std::pair parent_number_key() const { + return {parent, field_number}; + } + std::pair parent_name_key() const { + return {parent, name}; + } + }; + // This constructor is implicit to allow for non-transparent lookups when + // necessary. + // For transparent lookup cases we query directly with the object without the + // type erasure layer. + Symbol(QueryKey& value) : ptr_(&value) { // NOLINT + value.symbol_type_ = QUERY_KEY; + } + const QueryKey* query_key() const { + return type() == QUERY_KEY ? static_cast(ptr_) : nullptr; + } #undef DEFINE_MEMBERS Type type() const { return static_cast(ptr_->symbol_type_); } @@ -671,7 +707,7 @@ class Symbol { } } - absl::string_view full_name() const { + StringPiece full_name() const { switch (type()) { case MESSAGE: return descriptor()->full_name(); @@ -690,15 +726,17 @@ class Symbol { case FULL_PACKAGE: return file_descriptor()->package(); case SUB_PACKAGE: - return absl::string_view(sub_package_file_descriptor()->file->package()) + return StringPiece(sub_package_file_descriptor()->file->package()) .substr(0, sub_package_file_descriptor()->name_size); + case QUERY_KEY: + return query_key()->full_name(); default: GOOGLE_CHECK(false); } return ""; } - std::pair parent_name_key() const { + std::pair parent_name_key() const { const auto or_file = [&](const void* p) { return p ? p : GetFile(); }; switch (type()) { case MESSAGE: @@ -725,6 +763,24 @@ class Symbol { return {GetFile(), service_descriptor()->name()}; case METHOD: return {method_descriptor()->service(), method_descriptor()->name()}; + case QUERY_KEY: + return query_key()->parent_name_key(); + default: + GOOGLE_CHECK(false); + } + return {}; + } + + std::pair parent_number_key() const { + switch (type()) { + case FIELD: + return {field_descriptor()->containing_type(), + field_descriptor()->number()}; + case ENUM_VALUE: + return {enum_value_descriptor()->type(), + enum_value_descriptor()->number()}; + case QUERY_KEY: + return query_key()->parent_number_key(); default: GOOGLE_CHECK(false); } @@ -838,9 +894,9 @@ std::string EnumValueToPascalCase(const std::string& input) { next_upper = true; } else { if (next_upper) { - result.push_back(absl::ascii_toupper(character)); + result.push_back(ToUpper(character)); } else { - result.push_back(absl::ascii_tolower(character)); + result.push_back(ToLower(character)); } next_upper = false; } @@ -852,18 +908,18 @@ std::string EnumValueToPascalCase(const std::string& input) { // Class to remove an enum prefix from enum values. class PrefixRemover { public: - PrefixRemover(absl::string_view prefix) { + PrefixRemover(StringPiece prefix) { // Strip underscores and lower-case the prefix. for (char character : prefix) { if (character != '_') { - prefix_ += absl::ascii_tolower(character); + prefix_ += ascii_tolower(character); } } } // Tries to remove the enum prefix from this enum value. // If this is not possible, returns the input verbatim. - std::string MaybeRemove(absl::string_view str) { + std::string MaybeRemove(StringPiece str) { // We can't just lowercase and strip str and look for a prefix. // We need to properly recognize the difference between: // @@ -882,7 +938,7 @@ class PrefixRemover { continue; } - if (absl::ascii_tolower(str[i]) != prefix_[j++]) { + if (ascii_tolower(str[i]) != prefix_[j++]) { return std::string(str); } } @@ -919,16 +975,60 @@ class PrefixRemover { // hash-maps for each object. // // The keys to these hash-maps are (parent, name) or (parent, number) pairs. -struct FullNameQuery { - absl::string_view query; - absl::string_view full_name() const { return query; } + +typedef std::pair PointerStringPair; + +typedef std::pair DescriptorIntPair; + +#define HASH_MAP std::unordered_map +#define HASH_SET std::unordered_set +#define HASH_FXN hash + +template +struct PointerIntegerPairHash { + size_t operator()(const PairType& p) const { + static const size_t prime1 = 16777499; + static const size_t prime2 = 16777619; + return reinterpret_cast(p.first) * prime1 ^ + static_cast(p.second) * prime2; + } + +#ifdef _MSC_VER + // Used only by MSVC and platforms where hash_map is not available. + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; +#endif + inline bool operator()(const PairType& a, const PairType& b) const { + return a < b; + } }; + +struct PointerStringPairHash { + size_t operator()(const PointerStringPair& p) const { + static const size_t prime = 16777619; + hash string_hash; + return reinterpret_cast(p.first) * prime ^ + static_cast(string_hash(p.second)); + } + +#ifdef _MSC_VER + // Used only by MSVC and platforms where hash_map is not available. + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; +#endif + inline bool operator()(const PointerStringPair& a, + const PointerStringPair& b) const { + return a < b; + } +}; + + struct SymbolByFullNameHash { using is_transparent = void; template size_t operator()(const T& s) const { - return absl::HashOf(s.full_name()); + return HASH_FXN{}(s.full_name()); } }; struct SymbolByFullNameEq { @@ -940,20 +1040,14 @@ struct SymbolByFullNameEq { } }; using SymbolsByNameSet = - absl::flat_hash_set; + HASH_SET; -struct ParentNameQuery { - std::pair query; - std::pair parent_name_key() const { - return query; - } -}; struct SymbolByParentHash { using is_transparent = void; template size_t operator()(const T& s) const { - return absl::HashOf(s.parent_name_key()); + return PointerStringPairHash{}(s.parent_name_key()); } }; struct SymbolByParentEq { @@ -965,94 +1059,52 @@ struct SymbolByParentEq { } }; using SymbolsByParentSet = - absl::flat_hash_set; + HASH_SET; -struct FilesByNameHash { - using is_transparent = void; +typedef HASH_MAP> + FilesByNameMap; - size_t operator()(absl::string_view name) const { return absl::HashOf(name); } +typedef HASH_MAP + FieldsByNameMap; - size_t operator()(const FileDescriptor* file) const { - return absl::HashOf(file->name()); - } -}; - -struct FilesByNameEq { - using is_transparent = void; - - bool operator()(absl::string_view lhs, absl::string_view rhs) const { - return lhs == rhs; - } - bool operator()(absl::string_view lhs, const FileDescriptor* rhs) const { - return lhs == rhs->name(); - } - bool operator()(const FileDescriptor* lhs, absl::string_view rhs) const { - return lhs->name() == rhs; - } - bool operator()(const FileDescriptor* lhs, const FileDescriptor* rhs) const { - return lhs == rhs || lhs->name() == rhs->name(); - } -}; -using FilesByNameSet = - absl::flat_hash_set; - -using FieldsByNameMap = - absl::flat_hash_map, - const FieldDescriptor*>; - -struct ParentNumberQuery { - std::pair query; -}; -std::pair ObjectToParentNumber(const FieldDescriptor* field) { - return {field->containing_type(), field->number()}; -} -std::pair ObjectToParentNumber( - const EnumValueDescriptor* enum_value) { - return {enum_value->type(), enum_value->number()}; -} -std::pair ObjectToParentNumber(ParentNumberQuery query) { - return query.query; -} -struct ParentNumberHash { +struct FieldsByNumberHash { using is_transparent = void; template - size_t operator()(const T& t) const { - return absl::HashOf(ObjectToParentNumber(t)); + size_t operator()(const T& s) const { + return PointerIntegerPairHash>{}( + s.parent_number_key()); } }; -struct ParentNumberEq { +struct FieldsByNumberEq { using is_transparent = void; template bool operator()(const T& a, const U& b) const { - return ObjectToParentNumber(a) == ObjectToParentNumber(b); + return a.parent_number_key() == b.parent_number_key(); } }; -using FieldsByNumberSet = absl::flat_hash_set; -using EnumValuesByNumberSet = - absl::flat_hash_set; +using FieldsByNumberSet = + HASH_SET; +using EnumValuesByNumberSet = FieldsByNumberSet; // This is a map rather than a hash-map, since we use it to iterate // through all the extensions that extend a given Descriptor, and an // ordered data structure that implements lower_bound is convenient // for that. -using ExtensionsGroupedByDescriptorMap = - std::map, const FieldDescriptor*>; -using LocationsByPathMap = - absl::flat_hash_map; +typedef std::map + ExtensionsGroupedByDescriptorMap; +typedef HASH_MAP + LocationsByPathMap; -absl::flat_hash_set* NewAllowedProto3Extendee() { +std::set* NewAllowedProto3Extendee() { + auto allowed_proto3_extendees = new std::set; const char* kOptionNames[] = { "FileOptions", "MessageOptions", "FieldOptions", "EnumOptions", "EnumValueOptions", "ServiceOptions", "MethodOptions", "OneofOptions", "ExtensionRangeOptions"}; - auto allowed_proto3_extendees = new absl::flat_hash_set(); - allowed_proto3_extendees->reserve(sizeof(kOptionNames) / - sizeof(kOptionNames[0])); - for (const char* option_name : kOptionNames) { // descriptor.proto has a different package name in opensource. We allow // both so the opensource protocol compiler can also compile internal @@ -1061,7 +1113,7 @@ absl::flat_hash_set* NewAllowedProto3Extendee() { option_name); // Split the word to trick the opensource processing scripts so they // will keep the original package name. - allowed_proto3_extendees->insert(std::string("proto2.") + option_name); + allowed_proto3_extendees->insert(std::string("proto") + "2." + option_name); } return allowed_proto3_extendees; } @@ -1099,19 +1151,16 @@ class FileDescriptorTables { // Finding items. // Returns a null Symbol (symbol.IsNull() is true) if not found. - // TODO(sbenza): All callers to this function know the type they are looking - // for. If we propagate that information statically we can make the query - // faster. inline Symbol FindNestedSymbol(const void* parent, - absl::string_view name) const; + StringPiece name) const; // These return nullptr if not found. inline const FieldDescriptor* FindFieldByNumber(const Descriptor* parent, int number) const; inline const FieldDescriptor* FindFieldByLowercaseName( - const void* parent, absl::string_view lowercase_name) const; + const void* parent, StringPiece lowercase_name) const; inline const FieldDescriptor* FindFieldByCamelcaseName( - const void* parent, absl::string_view camelcase_name) const; + const void* parent, StringPiece camelcase_name) const; inline const EnumValueDescriptor* FindEnumValueByNumber( const EnumDescriptor* parent, int number) const; // This creates a new EnumValueDescriptor if not found, in a thread-safe way. @@ -1129,7 +1178,7 @@ class FileDescriptorTables { bool AddEnumValueByNumber(EnumValueDescriptor* value); // Populates p->first->locations_by_path_ from p->second. - // Unusual signature dictated by absl::call_once. + // Unusual signature dictated by internal::call_once. static void BuildLocationsByPath( std::pair* p); @@ -1154,8 +1203,8 @@ class FileDescriptorTables { void FieldsByCamelcaseNamesLazyInitInternal() const; SymbolsByParentSet symbols_by_parent_; - mutable absl::once_flag fields_by_lowercase_name_once_; - mutable absl::once_flag fields_by_camelcase_name_once_; + mutable internal::once_flag fields_by_lowercase_name_once_; + mutable internal::once_flag fields_by_camelcase_name_once_; // Make these fields atomic to avoid race conditions with // GetEstimatedOwnedMemoryBytesSize. Once the pointer is set the map won't // change anymore. @@ -1167,12 +1216,12 @@ class FileDescriptorTables { PROTOBUF_GUARDED_BY(unknown_enum_values_mu_); // Populated on first request to save space, hence constness games. - mutable absl::once_flag locations_by_path_once_; + mutable internal::once_flag locations_by_path_once_; mutable LocationsByPathMap locations_by_path_; // Mutex to protect the unknown-enum-value map due to dynamic // EnumValueDescriptor creation on unknown values. - mutable absl::Mutex unknown_enum_values_mu_; + mutable internal::WrappedMutex unknown_enum_values_mu_; }; namespace internal { @@ -1254,39 +1303,39 @@ class DescriptorPool::Tables { // execution of the current public API call, but for compatibility with // legacy clients, this is cleared at the beginning of each public API call. // Not used when fallback_database_ == nullptr. - absl::flat_hash_set known_bad_files_; + HASH_SET known_bad_files_; // A set of symbols which we have tried to load from the fallback database // and encountered errors. We will not attempt to load them again during // execution of the current public API call, but for compatibility with // legacy clients, this is cleared at the beginning of each public API call. - absl::flat_hash_set known_bad_symbols_; + HASH_SET known_bad_symbols_; // The set of descriptors for which we've already loaded the full // set of extensions numbers from fallback_database_. - absl::flat_hash_set extensions_loaded_from_db_; + HASH_SET extensions_loaded_from_db_; // Maps type name to Descriptor::WellKnownType. This is logically global // and const, but we make it a member here to simplify its construction and // destruction. This only has 20-ish entries and is one per DescriptorPool, // so the overhead is small. - absl::flat_hash_map well_known_types_; + HASH_MAP well_known_types_; // ----------------------------------------------------------------- // Finding items. // Find symbols. This returns a null Symbol (symbol.IsNull() is true) // if not found. - inline Symbol FindSymbol(absl::string_view key) const; + inline Symbol FindSymbol(StringPiece key) const; // This implements the body of DescriptorPool::Find*ByName(). It should // really be a private method of DescriptorPool, but that would require // declaring Symbol in descriptor.h, which would drag all kinds of other // stuff into the header. Yay C++. - Symbol FindByNameHelper(const DescriptorPool* pool, absl::string_view name); + Symbol FindByNameHelper(const DescriptorPool* pool, StringPiece name); // These return nullptr if not found. - inline const FileDescriptor* FindFile(absl::string_view key) const; + inline const FileDescriptor* FindFile(StringPiece key) const; inline const FieldDescriptor* FindExtension(const Descriptor* extendee, int number) const; inline void FindAllExtensions(const Descriptor* extendee, @@ -1345,7 +1394,7 @@ class DescriptorPool::Tables { flat_allocs_; SymbolsByNameSet symbols_by_name_; - FilesByNameSet files_by_name_; + FilesByNameMap files_by_name_; ExtensionsGroupedByDescriptorMap extensions_; struct CheckPoint { @@ -1369,7 +1418,7 @@ class DescriptorPool::Tables { std::vector checkpoints_; std::vector symbols_after_checkpoint_; std::vector files_after_checkpoint_; - std::vector> extensions_after_checkpoint_; + std::vector extensions_after_checkpoint_; }; DescriptorPool::Tables::Tables() { @@ -1434,7 +1483,7 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() { } for (size_t i = checkpoint.pending_files_before_checkpoint; i < files_after_checkpoint_.size(); i++) { - files_by_name_.erase(files_after_checkpoint_[i]); + files_by_name_.erase(files_after_checkpoint_[i]->name()); } for (size_t i = checkpoint.pending_extensions_before_checkpoint; i < extensions_after_checkpoint_.size(); i++) { @@ -1454,28 +1503,33 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() { // ------------------------------------------------------------------- -inline Symbol DescriptorPool::Tables::FindSymbol(absl::string_view key) const { - auto it = symbols_by_name_.find(FullNameQuery{key}); +inline Symbol DescriptorPool::Tables::FindSymbol(StringPiece key) const { + Symbol::QueryKey name; + name.name = key; + auto it = symbols_by_name_.find(name); return it == symbols_by_name_.end() ? Symbol() : *it; } inline Symbol FileDescriptorTables::FindNestedSymbol( - const void* parent, absl::string_view name) const { - auto it = symbols_by_parent_.find(ParentNameQuery{{parent, name}}); + const void* parent, StringPiece name) const { + Symbol::QueryKey query; + query.name = name; + query.parent = parent; + auto it = symbols_by_parent_.find(query); return it == symbols_by_parent_.end() ? Symbol() : *it; } Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool, - absl::string_view name) { + StringPiece name) { if (pool->mutex_ != nullptr) { // Fast path: the Symbol is already cached. This is just a hash lookup. - absl::ReaderMutexLock lock(pool->mutex_); + ReaderMutexLock lock(pool->mutex_); if (known_bad_symbols_.empty() && known_bad_files_.empty()) { Symbol result = FindSymbol(name); if (!result.IsNull()) return result; } } - absl::MutexLockMaybe lock(pool->mutex_); + MutexLockMaybe lock(pool->mutex_); if (pool->fallback_database_ != nullptr) { known_bad_symbols_.clear(); known_bad_files_.clear(); @@ -1498,10 +1552,8 @@ Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool, } inline const FileDescriptor* DescriptorPool::Tables::FindFile( - absl::string_view key) const { - auto it = files_by_name_.find(key); - if (it == files_by_name_.end()) return nullptr; - return *it; + StringPiece key) const { + return FindPtrOrNull(files_by_name_, key); } inline const FieldDescriptor* FileDescriptorTables::FindFieldByNumber( @@ -1513,8 +1565,12 @@ inline const FieldDescriptor* FileDescriptorTables::FindFieldByNumber( return parent->field(number - 1); } - auto it = fields_by_number_.find(ParentNumberQuery{{parent, number}}); - return it == fields_by_number_.end() ? nullptr : *it; + Symbol::QueryKey query; + query.parent = parent; + query.field_number = number; + + auto it = fields_by_number_.find(query); + return it == fields_by_number_.end() ? nullptr : it->field_descriptor(); } const void* FileDescriptorTables::FindParentForFieldsByMap( @@ -1547,15 +1603,13 @@ void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const { } inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName( - const void* parent, absl::string_view lowercase_name) const { - absl::call_once(fields_by_lowercase_name_once_, - &FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, - this); - const auto* fields = - fields_by_lowercase_name_.load(std::memory_order_acquire); - auto it = fields->find({parent, lowercase_name}); - if (it == fields->end()) return nullptr; - return it->second; + const void* parent, StringPiece lowercase_name) const { + internal::call_once( + fields_by_lowercase_name_once_, + &FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this); + return FindPtrOrNull( + *fields_by_lowercase_name_.load(std::memory_order_acquire), + PointerStringPair(parent, lowercase_name)); } void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic( @@ -1575,14 +1629,13 @@ void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const { } inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName( - const void* parent, absl::string_view camelcase_name) const { - absl::call_once(fields_by_camelcase_name_once_, - FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, - this); - auto* fields = fields_by_camelcase_name_.load(std::memory_order_acquire); - auto it = fields->find({parent, camelcase_name}); - if (it == fields->end()) return nullptr; - return it->second; + const void* parent, StringPiece camelcase_name) const { + internal::call_once( + fields_by_camelcase_name_once_, + FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this); + return FindPtrOrNull( + *fields_by_camelcase_name_.load(std::memory_order_acquire), + PointerStringPair(parent, camelcase_name)); } inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber( @@ -1595,8 +1648,13 @@ inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber( return parent->value(number - base); } - auto it = enum_values_by_number_.find(ParentNumberQuery{{parent, number}}); - return it == enum_values_by_number_.end() ? nullptr : *it; + Symbol::QueryKey query; + query.parent = parent; + query.field_number = number; + + auto it = enum_values_by_number_.find(query); + return it == enum_values_by_number_.end() ? nullptr + : it->enum_value_descriptor(); } inline const EnumValueDescriptor* @@ -1610,30 +1668,34 @@ FileDescriptorTables::FindEnumValueByNumberCreatingIfUnknown( } } - const ParentNumberQuery query{{parent, number}}; + Symbol::QueryKey query; + query.parent = parent; + query.field_number = number; // Second try, with reader lock held on unknown enum values: common case. { - absl::ReaderMutexLock l(&unknown_enum_values_mu_); + ReaderMutexLock l(&unknown_enum_values_mu_); auto it = unknown_enum_values_by_number_.find(query); - if (it != unknown_enum_values_by_number_.end()) { - return *it; + if (it != unknown_enum_values_by_number_.end() && + it->enum_value_descriptor() != nullptr) { + return it->enum_value_descriptor(); } } // If not found, try again with writer lock held, and create new descriptor if // necessary. { - absl::WriterMutexLock l(&unknown_enum_values_mu_); + WriterMutexLock l(&unknown_enum_values_mu_); auto it = unknown_enum_values_by_number_.find(query); - if (it != unknown_enum_values_by_number_.end()) { - return *it; + if (it != unknown_enum_values_by_number_.end() && + it->enum_value_descriptor() != nullptr) { + return it->enum_value_descriptor(); } // Create an EnumValueDescriptor dynamically. We don't insert it into the // EnumDescriptor (it's not a part of the enum as originally defined), but // we do insert it into the table so that we can return the same pointer // later. - std::string enum_value_name = absl::StrFormat( + std::string enum_value_name = StringPrintf( "UNKNOWN_ENUM_VALUE_%s_%d", parent->name().c_str(), number); auto* pool = DescriptorPool::generated_pool(); auto* tables = const_cast(pool->tables_.get()); @@ -1643,26 +1705,24 @@ FileDescriptorTables::FindEnumValueByNumberCreatingIfUnknown( { // Must lock the pool because we will do allocations in the shared arena. - absl::MutexLockMaybe l2(pool->mutex_); + MutexLockMaybe l2(pool->mutex_); alloc.FinalizePlanning(tables); } EnumValueDescriptor* result = alloc.AllocateArray(1); result->all_names_ = alloc.AllocateStrings( enum_value_name, - absl::StrCat(parent->full_name(), ".", enum_value_name)); + StrCat(parent->full_name(), ".", enum_value_name)); result->number_ = number; result->type_ = parent; result->options_ = &EnumValueOptions::default_instance(); - unknown_enum_values_by_number_.insert(result); + unknown_enum_values_by_number_.insert(Symbol::EnumValue(result, 0)); return result; } } inline const FieldDescriptor* DescriptorPool::Tables::FindExtension( const Descriptor* extendee, int number) const { - auto it = extensions_.find({extendee, number}); - if (it == extensions_.end()) return nullptr; - return it->second; + return FindPtrOrNull(extensions_, std::make_pair(extendee, number)); } inline void DescriptorPool::Tables::FindAllExtensions( @@ -1697,7 +1757,7 @@ bool FileDescriptorTables::AddAliasUnderParent(const void* parent, } bool DescriptorPool::Tables::AddFile(const FileDescriptor* file) { - if (files_by_name_.insert(file).second) { + if (InsertIfNotPresent(&files_by_name_, file->name(), file)) { files_after_checkpoint_.push_back(file); return true; } else { @@ -1720,7 +1780,7 @@ bool FileDescriptorTables::AddFieldByNumber(FieldDescriptor* field) { return field->containing_type()->field(field->number() - 1) == field; } - return fields_by_number_.insert(field).second; + return fields_by_number_.insert(Symbol(field)).second; } bool FileDescriptorTables::AddEnumValueByNumber(EnumValueDescriptor* value) { @@ -1730,14 +1790,13 @@ bool FileDescriptorTables::AddEnumValueByNumber(EnumValueDescriptor* value) { value->number() <= static_cast(base) + value->type()->sequential_value_limit_) return true; - return enum_values_by_number_.insert(value).second; + return enum_values_by_number_.insert(Symbol::EnumValue(value, 0)).second; } bool DescriptorPool::Tables::AddExtension(const FieldDescriptor* field) { - auto it_inserted = - extensions_.insert({{field->containing_type(), field->number()}, field}); - if (it_inserted.second) { - extensions_after_checkpoint_.push_back(it_inserted.first->first); + DescriptorIntPair key(field->containing_type(), field->number()); + if (InsertIfNotPresent(&extensions_, key, field)) { + extensions_after_checkpoint_.push_back(key); return true; } else { return false; @@ -1783,7 +1842,7 @@ void FileDescriptorTables::BuildLocationsByPath( std::pair* p) { for (int i = 0, len = p->second->location_size(); i < len; ++i) { const SourceCodeInfo_Location* loc = &p->second->location().Get(i); - p->first->locations_by_path_[absl::StrJoin(loc->path(), ",")] = loc; + p->first->locations_by_path_[Join(loc->path(), ",")] = loc; } } @@ -1791,11 +1850,9 @@ const SourceCodeInfo_Location* FileDescriptorTables::GetSourceLocation( const std::vector& path, const SourceCodeInfo* info) const { std::pair p( std::make_pair(this, info)); - absl::call_once(locations_by_path_once_, - FileDescriptorTables::BuildLocationsByPath, &p); - auto it = locations_by_path_.find(absl::StrJoin(path, ",")); - if (it == locations_by_path_.end()) return nullptr; - return it->second; + internal::call_once(locations_by_path_once_, + FileDescriptorTables::BuildLocationsByPath, &p); + return FindPtrOrNull(locations_by_path_, Join(path, ",")); } // =================================================================== @@ -1817,7 +1874,7 @@ DescriptorPool::DescriptorPool() DescriptorPool::DescriptorPool(DescriptorDatabase* fallback_database, ErrorCollector* error_collector) - : mutex_(new absl::Mutex), + : mutex_(new internal::WrappedMutex), fallback_database_(fallback_database), default_error_collector_(error_collector), underlay_(nullptr), @@ -1851,7 +1908,7 @@ void DescriptorPool::InternalDontEnforceDependencies() { enforce_dependencies_ = false; } -void DescriptorPool::AddUnusedImportTrackFile(absl::string_view file_name, +void DescriptorPool::AddUnusedImportTrackFile(ConstStringParam file_name, bool is_error) { unused_import_track_files_[std::string(file_name)] = is_error; } @@ -1860,8 +1917,8 @@ void DescriptorPool::ClearUnusedImportTrackFiles() { unused_import_track_files_.clear(); } -bool DescriptorPool::InternalIsFileLoaded(absl::string_view filename) const { - absl::MutexLockMaybe lock(mutex_); +bool DescriptorPool::InternalIsFileLoaded(ConstStringParam filename) const { + MutexLockMaybe lock(mutex_); return tables_->FindFile(filename) != nullptr; } @@ -1937,8 +1994,8 @@ void DescriptorPool::InternalAddGeneratedFile( // there's nothing more important to do (read: never). const FileDescriptor* DescriptorPool::FindFileByName( - absl::string_view name) const { - absl::MutexLockMaybe lock(mutex_); + ConstStringParam name) const { + MutexLockMaybe lock(mutex_); if (fallback_database_ != nullptr) { tables_->known_bad_symbols_.clear(); tables_->known_bad_files_.clear(); @@ -1957,8 +2014,8 @@ const FileDescriptor* DescriptorPool::FindFileByName( } const FileDescriptor* DescriptorPool::FindFileContainingSymbol( - absl::string_view symbol_name) const { - absl::MutexLockMaybe lock(mutex_); + ConstStringParam symbol_name) const { + MutexLockMaybe lock(mutex_); if (fallback_database_ != nullptr) { tables_->known_bad_symbols_.clear(); tables_->known_bad_files_.clear(); @@ -1978,12 +2035,12 @@ const FileDescriptor* DescriptorPool::FindFileContainingSymbol( } const Descriptor* DescriptorPool::FindMessageTypeByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).descriptor(); } const FieldDescriptor* DescriptorPool::FindFieldByName( - absl::string_view name) const { + ConstStringParam name) const { if (const FieldDescriptor* field = tables_->FindByNameHelper(this, name).field_descriptor()) { if (!field->is_extension()) { @@ -1994,7 +2051,7 @@ const FieldDescriptor* DescriptorPool::FindFieldByName( } const FieldDescriptor* DescriptorPool::FindExtensionByName( - absl::string_view name) const { + ConstStringParam name) const { if (const FieldDescriptor* field = tables_->FindByNameHelper(this, name).field_descriptor()) { if (field->is_extension()) { @@ -2005,27 +2062,27 @@ const FieldDescriptor* DescriptorPool::FindExtensionByName( } const OneofDescriptor* DescriptorPool::FindOneofByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).oneof_descriptor(); } const EnumDescriptor* DescriptorPool::FindEnumTypeByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).enum_descriptor(); } const EnumValueDescriptor* DescriptorPool::FindEnumValueByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).enum_value_descriptor(); } const ServiceDescriptor* DescriptorPool::FindServiceByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).service_descriptor(); } const MethodDescriptor* DescriptorPool::FindMethodByName( - absl::string_view name) const { + ConstStringParam name) const { return tables_->FindByNameHelper(this, name).method_descriptor(); } @@ -2035,13 +2092,13 @@ const FieldDescriptor* DescriptorPool::FindExtensionByNumber( // A faster path to reduce lock contention in finding extensions, assuming // most extensions will be cache hit. if (mutex_ != nullptr) { - absl::ReaderMutexLock lock(mutex_); + ReaderMutexLock lock(mutex_); const FieldDescriptor* result = tables_->FindExtension(extendee, number); if (result != nullptr) { return result; } } - absl::MutexLockMaybe lock(mutex_); + MutexLockMaybe lock(mutex_); if (fallback_database_ != nullptr) { tables_->known_bad_symbols_.clear(); tables_->known_bad_files_.clear(); @@ -2081,7 +2138,7 @@ const FieldDescriptor* DescriptorPool::InternalFindExtensionByNumberNoLock( } const FieldDescriptor* DescriptorPool::FindExtensionByPrintableName( - const Descriptor* extendee, absl::string_view printable_name) const { + const Descriptor* extendee, ConstStringParam printable_name) const { if (extendee->extension_range_count() == 0) return nullptr; const FieldDescriptor* result = FindExtensionByName(printable_name); if (result != nullptr && result->containing_type() == extendee) { @@ -2110,7 +2167,7 @@ const FieldDescriptor* DescriptorPool::FindExtensionByPrintableName( void DescriptorPool::FindAllExtensions( const Descriptor* extendee, std::vector* out) const { - absl::MutexLockMaybe lock(mutex_); + MutexLockMaybe lock(mutex_); if (fallback_database_ != nullptr) { tables_->known_bad_symbols_.clear(); tables_->known_bad_files_.clear(); @@ -2151,7 +2208,7 @@ const FieldDescriptor* Descriptor::FindFieldByNumber(int key) const { } const FieldDescriptor* Descriptor::FindFieldByLowercaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = file()->tables_->FindFieldByLowercaseName(this, key); if (result == nullptr || result->is_extension()) { @@ -2162,7 +2219,7 @@ const FieldDescriptor* Descriptor::FindFieldByLowercaseName( } const FieldDescriptor* Descriptor::FindFieldByCamelcaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = file()->tables_->FindFieldByCamelcaseName(this, key); if (result == nullptr || result->is_extension()) { @@ -2172,27 +2229,25 @@ const FieldDescriptor* Descriptor::FindFieldByCamelcaseName( } } -const FieldDescriptor* Descriptor::FindFieldByName( - absl::string_view key) const { +const FieldDescriptor* Descriptor::FindFieldByName(ConstStringParam key) const { const FieldDescriptor* field = file()->tables_->FindNestedSymbol(this, key).field_descriptor(); return field != nullptr && !field->is_extension() ? field : nullptr; } -const OneofDescriptor* Descriptor::FindOneofByName( - absl::string_view key) const { +const OneofDescriptor* Descriptor::FindOneofByName(ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).oneof_descriptor(); } const FieldDescriptor* Descriptor::FindExtensionByName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* field = file()->tables_->FindNestedSymbol(this, key).field_descriptor(); return field != nullptr && field->is_extension() ? field : nullptr; } const FieldDescriptor* Descriptor::FindExtensionByLowercaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = file()->tables_->FindFieldByLowercaseName(this, key); if (result == nullptr || !result->is_extension()) { @@ -2203,7 +2258,7 @@ const FieldDescriptor* Descriptor::FindExtensionByLowercaseName( } const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = file()->tables_->FindFieldByCamelcaseName(this, key); if (result == nullptr || !result->is_extension()) { @@ -2213,18 +2268,17 @@ const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName( } } -const Descriptor* Descriptor::FindNestedTypeByName( - absl::string_view key) const { +const Descriptor* Descriptor::FindNestedTypeByName(ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).descriptor(); } const EnumDescriptor* Descriptor::FindEnumTypeByName( - absl::string_view key) const { + ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).enum_descriptor(); } const EnumValueDescriptor* Descriptor::FindEnumValueByName( - absl::string_view key) const { + ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).enum_value_descriptor(); } @@ -2241,7 +2295,7 @@ const FieldDescriptor* Descriptor::map_value() const { } const EnumValueDescriptor* EnumDescriptor::FindValueByName( - absl::string_view key) const { + ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).enum_value_descriptor(); } @@ -2255,39 +2309,39 @@ const EnumValueDescriptor* EnumDescriptor::FindValueByNumberCreatingIfUnknown( } const MethodDescriptor* ServiceDescriptor::FindMethodByName( - absl::string_view key) const { + ConstStringParam key) const { return file()->tables_->FindNestedSymbol(this, key).method_descriptor(); } const Descriptor* FileDescriptor::FindMessageTypeByName( - absl::string_view key) const { + ConstStringParam key) const { return tables_->FindNestedSymbol(this, key).descriptor(); } const EnumDescriptor* FileDescriptor::FindEnumTypeByName( - absl::string_view key) const { + ConstStringParam key) const { return tables_->FindNestedSymbol(this, key).enum_descriptor(); } const EnumValueDescriptor* FileDescriptor::FindEnumValueByName( - absl::string_view key) const { + ConstStringParam key) const { return tables_->FindNestedSymbol(this, key).enum_value_descriptor(); } const ServiceDescriptor* FileDescriptor::FindServiceByName( - absl::string_view key) const { + ConstStringParam key) const { return tables_->FindNestedSymbol(this, key).service_descriptor(); } const FieldDescriptor* FileDescriptor::FindExtensionByName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* field = tables_->FindNestedSymbol(this, key).field_descriptor(); return field != nullptr && field->is_extension() ? field : nullptr; } const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = tables_->FindFieldByLowercaseName(this, key); if (result == nullptr || !result->is_extension()) { return nullptr; @@ -2297,7 +2351,7 @@ const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName( } const FieldDescriptor* FileDescriptor::FindExtensionByCamelcaseName( - absl::string_view key) const { + ConstStringParam key) const { const FieldDescriptor* result = tables_->FindFieldByCamelcaseName(this, key); if (result == nullptr || !result->is_extension()) { return nullptr; @@ -2354,7 +2408,7 @@ EnumDescriptor::FindReservedRangeContainingNumber(int number) const { // ------------------------------------------------------------------- bool DescriptorPool::TryFindFileInFallbackDatabase( - absl::string_view name) const { + StringPiece name) const { if (fallback_database_ == nullptr) return false; auto name_string = std::string(name); @@ -2369,7 +2423,7 @@ bool DescriptorPool::TryFindFileInFallbackDatabase( return true; } -bool DescriptorPool::IsSubSymbolOfBuiltType(absl::string_view name) const { +bool DescriptorPool::IsSubSymbolOfBuiltType(StringPiece name) const { auto prefix = std::string(name); for (;;) { std::string::size_type dot_pos = prefix.find_last_of('.'); @@ -2392,7 +2446,7 @@ bool DescriptorPool::IsSubSymbolOfBuiltType(absl::string_view name) const { } bool DescriptorPool::TryFindSymbolInFallbackDatabase( - absl::string_view name) const { + StringPiece name) const { if (fallback_database_ == nullptr) return false; auto name_string = std::string(name); @@ -2469,13 +2523,13 @@ std::string FieldDescriptor::DefaultValueAsString( GOOGLE_CHECK(has_default_value()) << "No default value"; switch (cpp_type()) { case CPPTYPE_INT32: - return absl::StrCat(default_value_int32_t()); + return StrCat(default_value_int32_t()); case CPPTYPE_INT64: - return absl::StrCat(default_value_int64_t()); + return StrCat(default_value_int64_t()); case CPPTYPE_UINT32: - return absl::StrCat(default_value_uint32_t()); + return StrCat(default_value_uint32_t()); case CPPTYPE_UINT64: - return absl::StrCat(default_value_uint64_t()); + return StrCat(default_value_uint64_t()); case CPPTYPE_FLOAT: return SimpleFtoa(default_value_float()); case CPPTYPE_DOUBLE: @@ -2484,10 +2538,10 @@ std::string FieldDescriptor::DefaultValueAsString( return default_value_bool() ? "true" : "false"; case CPPTYPE_STRING: if (quote_string_type) { - return "\"" + absl::CEscape(default_value_string()) + "\""; + return "\"" + CEscape(default_value_string()) + "\""; } else { if (type() == TYPE_BYTES) { - return absl::CEscape(default_value_string()); + return CEscape(default_value_string()); } else { return default_value_string(); } @@ -2505,7 +2559,10 @@ std::string FieldDescriptor::DefaultValueAsString( // CopyTo methods ==================================================== void FileDescriptor::CopyTo(FileDescriptorProto* proto) const { - CopyHeadingTo(proto); + proto->set_name(name()); + if (!package().empty()) proto->set_package(package()); + // TODO(liujisi): Also populate when syntax="proto2". + if (syntax() == SYNTAX_PROTO3) proto->set_syntax(SyntaxName(syntax())); for (int i = 0; i < dependency_count(); i++) { proto->add_dependency(dependency(i)->name()); @@ -2531,21 +2588,9 @@ void FileDescriptor::CopyTo(FileDescriptorProto* proto) const { for (int i = 0; i < extension_count(); i++) { extension(i)->CopyTo(proto->add_extension()); } -} -void FileDescriptor::CopyHeadingTo(FileDescriptorProto* proto) const { - proto->set_name(name()); - if (!package().empty()) { - proto->set_package(package()); - } - - // TODO(liujisi): Also populate when syntax="proto2". - if (syntax() == SYNTAX_PROTO3 - ) { - proto->set_syntax(SyntaxName(syntax())); - } if (&options() != &FileOptions::default_instance()) { - *proto->mutable_options() = options(); + proto->mutable_options()->CopyFrom(options()); } } @@ -2635,9 +2680,9 @@ void FieldDescriptor::CopyTo(FieldDescriptorProto* proto) const { // Some compilers do not allow static_cast directly between two enum types, // so we must cast to int first. proto->set_label(static_cast( - absl::implicit_cast(label()))); + implicit_cast(label()))); proto->set_type(static_cast( - absl::implicit_cast(type()))); + implicit_cast(type()))); if (is_extension()) { if (!containing_type()->is_unqualified_placeholder_) { @@ -2844,7 +2889,7 @@ bool FormatBracketedOptions(int depth, const Message& options, const DescriptorPool* pool, std::string* output) { std::vector all_options; if (RetrieveOptions(depth, options, pool, &all_options)) { - output->append(absl::StrJoin(all_options, ", ")); + output->append(Join(all_options, ", ")); } return !all_options.empty(); } @@ -2856,7 +2901,7 @@ bool FormatLineOptions(int depth, const Message& options, std::vector all_options; if (RetrieveOptions(depth, options, pool, &all_options)) { for (const std::string& option : all_options) { - absl::SubstituteAndAppend(output, "$0option $1;\n", prefix, option); + strings::SubstituteAndAppend(output, "$0option $1;\n", prefix, option); } } return !all_options.empty(); @@ -2907,11 +2952,11 @@ class SourceLocationCommentPrinter { // the DebugString() output. std::string FormatComment(const std::string& comment_text) { std::string stripped_comment = comment_text; - absl::StripAsciiWhitespace(&stripped_comment); - std::vector lines = absl::StrSplit(stripped_comment, "\n"); + StripWhitespace(&stripped_comment); + std::vector lines = Split(stripped_comment, "\n"); std::string output; for (const std::string& line : lines) { - absl::SubstituteAndAppend(&output, "$0// $1\n", prefix_, line); + strings::SubstituteAndAppend(&output, "$0// $1\n", prefix_, line); } return output; } @@ -2940,7 +2985,7 @@ std::string FileDescriptor::DebugStringWithOptions( SourceLocationCommentPrinter syntax_comment(this, path, "", debug_string_options); syntax_comment.AddPreComment(&contents); - absl::SubstituteAndAppend(&contents, "syntax = \"$0\";\n\n", + strings::SubstituteAndAppend(&contents, "syntax = \"$0\";\n\n", SyntaxName(syntax())); syntax_comment.AddPostComment(&contents); } @@ -2948,20 +2993,22 @@ std::string FileDescriptor::DebugStringWithOptions( SourceLocationCommentPrinter comment_printer(this, "", debug_string_options); comment_printer.AddPreComment(&contents); - absl::flat_hash_set public_dependencies( - public_dependencies_, public_dependencies_ + public_dependency_count_); - absl::flat_hash_set weak_dependencies( - weak_dependencies_, weak_dependencies_ + weak_dependency_count_); + std::set public_dependencies; + std::set weak_dependencies; + public_dependencies.insert(public_dependencies_, + public_dependencies_ + public_dependency_count_); + weak_dependencies.insert(weak_dependencies_, + weak_dependencies_ + weak_dependency_count_); for (int i = 0; i < dependency_count(); i++) { - if (public_dependencies.contains(i)) { - absl::SubstituteAndAppend(&contents, "import public \"$0\";\n", + if (public_dependencies.count(i) > 0) { + strings::SubstituteAndAppend(&contents, "import public \"$0\";\n", dependency(i)->name()); - } else if (weak_dependencies.contains(i)) { - absl::SubstituteAndAppend(&contents, "import weak \"$0\";\n", + } else if (weak_dependencies.count(i) > 0) { + strings::SubstituteAndAppend(&contents, "import weak \"$0\";\n", dependency(i)->name()); } else { - absl::SubstituteAndAppend(&contents, "import \"$0\";\n", + strings::SubstituteAndAppend(&contents, "import \"$0\";\n", dependency(i)->name()); } } @@ -2972,7 +3019,7 @@ std::string FileDescriptor::DebugStringWithOptions( SourceLocationCommentPrinter package_comment(this, path, "", debug_string_options); package_comment.AddPreComment(&contents); - absl::SubstituteAndAppend(&contents, "package $0;\n\n", package()); + strings::SubstituteAndAppend(&contents, "package $0;\n\n", package()); package_comment.AddPostComment(&contents); } @@ -2987,7 +3034,7 @@ std::string FileDescriptor::DebugStringWithOptions( // Find all the 'group' type extensions; we will not output their nested // definitions (those will be done with their group field descriptor). - absl::flat_hash_set groups; + std::set groups; for (int i = 0; i < extension_count(); i++) { if (extension(i)->type() == FieldDescriptor::TYPE_GROUP) { groups.insert(extension(i)->message_type()); @@ -2995,7 +3042,7 @@ std::string FileDescriptor::DebugStringWithOptions( } for (int i = 0; i < message_type_count(); i++) { - if (!groups.contains(message_type(i))) { + if (groups.count(message_type(i)) == 0) { message_type(i)->DebugString(0, &contents, debug_string_options, /* include_opening_clause */ true); contents.append("\n"); @@ -3012,7 +3059,7 @@ std::string FileDescriptor::DebugStringWithOptions( if (extension(i)->containing_type() != containing_type) { if (i > 0) contents.append("}\n\n"); containing_type = extension(i)->containing_type(); - absl::SubstituteAndAppend(&contents, "extend .$0 {\n", + strings::SubstituteAndAppend(&contents, "extend .$0 {\n", containing_type->full_name()); } extension(i)->DebugString(1, &contents, debug_string_options); @@ -3051,7 +3098,7 @@ void Descriptor::DebugString(int depth, std::string* contents, comment_printer.AddPreComment(contents); if (include_opening_clause) { - absl::SubstituteAndAppend(contents, "$0message $1", prefix, name()); + strings::SubstituteAndAppend(contents, "$0message $1", prefix, name()); } contents->append(" {\n"); @@ -3060,7 +3107,7 @@ void Descriptor::DebugString(int depth, std::string* contents, // Find all the 'group' types for fields and extensions; we will not output // their nested definitions (those will be done with their group field // descriptor). - absl::flat_hash_set groups; + std::set groups; for (int i = 0; i < field_count(); i++) { if (field(i)->type() == FieldDescriptor::TYPE_GROUP) { groups.insert(field(i)->message_type()); @@ -3073,7 +3120,7 @@ void Descriptor::DebugString(int depth, std::string* contents, } for (int i = 0; i < nested_type_count(); i++) { - if (!groups.contains(nested_type(i))) { + if (groups.count(nested_type(i)) == 0) { nested_type(i)->DebugString(depth, contents, debug_string_options, /* include_opening_clause */ true); } @@ -3092,7 +3139,7 @@ void Descriptor::DebugString(int depth, std::string* contents, } for (int i = 0; i < extension_range_count(); i++) { - absl::SubstituteAndAppend(contents, "$0 extensions $1 to $2;\n", prefix, + strings::SubstituteAndAppend(contents, "$0 extensions $1 to $2;\n", prefix, extension_range(i)->start, extension_range(i)->end - 1); } @@ -3101,26 +3148,26 @@ void Descriptor::DebugString(int depth, std::string* contents, const Descriptor* containing_type = nullptr; for (int i = 0; i < extension_count(); i++) { if (extension(i)->containing_type() != containing_type) { - if (i > 0) absl::SubstituteAndAppend(contents, "$0 }\n", prefix); + if (i > 0) strings::SubstituteAndAppend(contents, "$0 }\n", prefix); containing_type = extension(i)->containing_type(); - absl::SubstituteAndAppend(contents, "$0 extend .$1 {\n", prefix, + strings::SubstituteAndAppend(contents, "$0 extend .$1 {\n", prefix, containing_type->full_name()); } extension(i)->DebugString(depth + 1, contents, debug_string_options); } if (extension_count() > 0) - absl::SubstituteAndAppend(contents, "$0 }\n", prefix); + strings::SubstituteAndAppend(contents, "$0 }\n", prefix); if (reserved_range_count() > 0) { - absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); + strings::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_range_count(); i++) { const Descriptor::ReservedRange* range = reserved_range(i); if (range->end == range->start + 1) { - absl::SubstituteAndAppend(contents, "$0, ", range->start); + strings::SubstituteAndAppend(contents, "$0, ", range->start); } else if (range->end > FieldDescriptor::kMaxNumber) { - absl::SubstituteAndAppend(contents, "$0 to max, ", range->start); + strings::SubstituteAndAppend(contents, "$0 to max, ", range->start); } else { - absl::SubstituteAndAppend(contents, "$0 to $1, ", range->start, + strings::SubstituteAndAppend(contents, "$0 to $1, ", range->start, range->end - 1); } } @@ -3128,15 +3175,15 @@ void Descriptor::DebugString(int depth, std::string* contents, } if (reserved_name_count() > 0) { - absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); + strings::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_name_count(); i++) { - absl::SubstituteAndAppend(contents, "\"$0\", ", - absl::CEscape(reserved_name(i))); + strings::SubstituteAndAppend(contents, "\"$0\", ", + CEscape(reserved_name(i))); } contents->replace(contents->size() - 2, 2, ";\n"); } - absl::SubstituteAndAppend(contents, "$0}\n", prefix); + strings::SubstituteAndAppend(contents, "$0}\n", prefix); comment_printer.AddPostComment(contents); } @@ -3150,7 +3197,7 @@ std::string FieldDescriptor::DebugStringWithOptions( std::string contents; int depth = 0; if (is_extension()) { - absl::SubstituteAndAppend(&contents, "extend .$0 {\n", + strings::SubstituteAndAppend(&contents, "extend .$0 {\n", containing_type()->full_name()); depth = 1; } @@ -3181,7 +3228,7 @@ void FieldDescriptor::DebugString( // Special case map fields. if (is_map()) { - absl::SubstituteAndAppend( + strings::SubstituteAndAppend( &field_type, "map<$0, $1>", message_type()->field(0)->FieldTypeNameDebugString(), message_type()->field(1)->FieldTypeNameDebugString()); @@ -3189,7 +3236,7 @@ void FieldDescriptor::DebugString( field_type = FieldTypeNameDebugString(); } - std::string label = absl::StrCat(kLabelToName[this->label()], " "); + std::string label = StrCat(kLabelToName[this->label()], " "); // Label is omitted for maps, oneof, and plain proto3 fields. if (is_map() || real_containing_oneof() || @@ -3201,14 +3248,14 @@ void FieldDescriptor::DebugString( debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend( + strings::SubstituteAndAppend( contents, "$0$1$2 $3 = $4", prefix, label, field_type, type() == TYPE_GROUP ? message_type()->name() : name(), number()); bool bracketed = false; if (has_default_value()) { bracketed = true; - absl::SubstituteAndAppend(contents, " [default = $0", + strings::SubstituteAndAppend(contents, " [default = $0", DefaultValueAsString(true)); } if (has_json_name_) { @@ -3219,7 +3266,7 @@ void FieldDescriptor::DebugString( contents->append(", "); } contents->append("json_name = \""); - contents->append(absl::CEscape(json_name())); + contents->append(CEscape(json_name())); contents->append("\""); } @@ -3269,7 +3316,7 @@ void OneofDescriptor::DebugString( SourceLocationCommentPrinter comment_printer(this, prefix, debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend(contents, "$0oneof $1 {", prefix, name()); + strings::SubstituteAndAppend(contents, "$0oneof $1 {", prefix, name()); FormatLineOptions(depth, options(), containing_type()->file()->pool(), contents); @@ -3281,7 +3328,7 @@ void OneofDescriptor::DebugString( for (int i = 0; i < field_count(); i++) { field(i)->DebugString(depth, contents, debug_string_options); } - absl::SubstituteAndAppend(contents, "$0}\n", prefix); + strings::SubstituteAndAppend(contents, "$0}\n", prefix); } comment_printer.AddPostComment(contents); } @@ -3308,7 +3355,7 @@ void EnumDescriptor::DebugString( debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend(contents, "$0enum $1 {\n", prefix, name()); + strings::SubstituteAndAppend(contents, "$0enum $1 {\n", prefix, name()); FormatLineOptions(depth, options(), file()->pool(), contents); @@ -3317,15 +3364,15 @@ void EnumDescriptor::DebugString( } if (reserved_range_count() > 0) { - absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); + strings::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_range_count(); i++) { const EnumDescriptor::ReservedRange* range = reserved_range(i); if (range->end == range->start) { - absl::SubstituteAndAppend(contents, "$0, ", range->start); + strings::SubstituteAndAppend(contents, "$0, ", range->start); } else if (range->end == INT_MAX) { - absl::SubstituteAndAppend(contents, "$0 to max, ", range->start); + strings::SubstituteAndAppend(contents, "$0 to max, ", range->start); } else { - absl::SubstituteAndAppend(contents, "$0 to $1, ", range->start, + strings::SubstituteAndAppend(contents, "$0 to $1, ", range->start, range->end); } } @@ -3333,15 +3380,15 @@ void EnumDescriptor::DebugString( } if (reserved_name_count() > 0) { - absl::SubstituteAndAppend(contents, "$0 reserved ", prefix); + strings::SubstituteAndAppend(contents, "$0 reserved ", prefix); for (int i = 0; i < reserved_name_count(); i++) { - absl::SubstituteAndAppend(contents, "\"$0\", ", - absl::CEscape(reserved_name(i))); + strings::SubstituteAndAppend(contents, "\"$0\", ", + CEscape(reserved_name(i))); } contents->replace(contents->size() - 2, 2, ";\n"); } - absl::SubstituteAndAppend(contents, "$0}\n", prefix); + strings::SubstituteAndAppend(contents, "$0}\n", prefix); comment_printer.AddPostComment(contents); } @@ -3367,12 +3414,12 @@ void EnumValueDescriptor::DebugString( debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend(contents, "$0$1 = $2", prefix, name(), number()); + strings::SubstituteAndAppend(contents, "$0$1 = $2", prefix, name(), number()); std::string formatted_options; if (FormatBracketedOptions(depth, options(), type()->file()->pool(), &formatted_options)) { - absl::SubstituteAndAppend(contents, " [$0]", formatted_options); + strings::SubstituteAndAppend(contents, " [$0]", formatted_options); } contents->append(";\n"); @@ -3398,7 +3445,7 @@ void ServiceDescriptor::DebugString( debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend(contents, "service $0 {\n", name()); + strings::SubstituteAndAppend(contents, "service $0 {\n", name()); FormatLineOptions(1, options(), file()->pool(), contents); @@ -3433,7 +3480,7 @@ void MethodDescriptor::DebugString( debug_string_options); comment_printer.AddPreComment(contents); - absl::SubstituteAndAppend( + strings::SubstituteAndAppend( contents, "$0rpc $1($4.$2) returns ($5.$3)", prefix, name(), input_type()->full_name(), output_type()->full_name(), client_streaming() ? "stream " : "", server_streaming() ? "stream " : ""); @@ -3441,7 +3488,7 @@ void MethodDescriptor::DebugString( std::string formatted_options; if (FormatLineOptions(depth, options(), service()->file()->pool(), &formatted_options)) { - absl::SubstituteAndAppend(contents, " {\n$0$1}\n", formatted_options, + strings::SubstituteAndAppend(contents, " {\n$0$1}\n", formatted_options, prefix); } else { contents->append(";\n"); @@ -3651,7 +3698,7 @@ class DescriptorBuilder { std::string filename_; FileDescriptor* file_; FileDescriptorTables* file_tables_; - absl::flat_hash_set dependencies_; + std::set dependencies_; struct MessageHints { int fields_to_suggest = 0; @@ -3674,11 +3721,11 @@ class DescriptorBuilder { } }; - absl::flat_hash_map message_hints_; + std::unordered_map message_hints_; // unused_dependency_ is used to record the unused imported files. // Note: public import is not considered. - absl::flat_hash_set unused_dependency_; + std::set unused_dependency_; // If LookupSymbol() finds a symbol that is in a file which is not a declared // dependency of this file, it will fail, but will set @@ -3902,8 +3949,6 @@ class DescriptorBuilder { // specified builder, which must not be nullptr. We don't take ownership of // the builder. explicit OptionInterpreter(DescriptorBuilder* builder); - OptionInterpreter(const OptionInterpreter&) = delete; - OptionInterpreter& operator=(const OptionInterpreter&) = delete; ~OptionInterpreter(); @@ -4020,6 +4065,8 @@ class DescriptorBuilder { // Factory used to create the dynamic messages we need to parse // any aggregate option values we encounter. DynamicMessageFactory dynamic_factory_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OptionInterpreter); }; // Work-around for broken compilers: According to the C++ standard, @@ -4212,7 +4259,7 @@ void DescriptorBuilder::AddWarning( bool DescriptorBuilder::IsInPackage(const FileDescriptor* file, const std::string& package_name) { - return absl::StartsWith(file->package(), package_name) && + return HasPrefixString(file->package(), package_name) && (file->package().size() == package_name.size() || file->package()[package_name.size()] == '.'); } @@ -4228,7 +4275,7 @@ Symbol DescriptorBuilder::FindSymbolNotEnforcingDepsHelper( const DescriptorPool* pool, const std::string& name, bool build_it) { // If we are looking at an underlay, we must lock its mutex_, since we are // accessing the underlay's tables_ directly. - absl::MutexLockMaybe lock((pool == pool_) ? nullptr : pool->mutex_); + MutexLockMaybe lock((pool == pool_) ? nullptr : pool->mutex_); Symbol result = pool->tables_->FindSymbol(name); if (result.IsNull() && pool->underlay_ != nullptr) { @@ -4258,7 +4305,7 @@ Symbol DescriptorBuilder::FindSymbolNotEnforcingDeps(const std::string& name, // Only find symbols which were defined in this file or one of its // dependencies. const FileDescriptor* file = result.GetFile(); - if (file == file_ || dependencies_.contains(file)) { + if (file == file_ || dependencies_.count(file) > 0) { unused_dependency_.erase(file); } return result; @@ -4277,7 +4324,7 @@ Symbol DescriptorBuilder::FindSymbol(const std::string& name, bool build_it) { // Only find symbols which were defined in this file or one of its // dependencies. const FileDescriptor* file = result.GetFile(); - if (file == file_ || dependencies_.contains(file)) { + if (file == file_ || dependencies_.count(file) > 0) { return result; } @@ -4290,9 +4337,11 @@ Symbol DescriptorBuilder::FindSymbol(const std::string& name, bool build_it) { // dependency also defines the same package. We can't really rule out this // symbol unless none of the dependencies define it. if (IsInPackage(file_, name)) return result; - for (const auto* dep : dependencies_) { + for (std::set::const_iterator it = + dependencies_.begin(); + it != dependencies_.end(); ++it) { // Note: A dependency may be nullptr if it was not found or had errors. - if (dep != nullptr && IsInPackage(dep, name)) return result; + if (*it != nullptr && IsInPackage(*it, name)) return result; } } @@ -4390,7 +4439,7 @@ Symbol DescriptorBuilder::LookupSymbol( return result; } -static bool ValidateQualifiedName(absl::string_view name) { +static bool ValidateQualifiedName(StringPiece name) { bool last_was_period = false; for (char character : name) { @@ -4410,20 +4459,20 @@ static bool ValidateQualifiedName(absl::string_view name) { return !name.empty() && !last_was_period; } -Symbol DescriptorPool::NewPlaceholder(absl::string_view name, +Symbol DescriptorPool::NewPlaceholder(StringPiece name, PlaceholderType placeholder_type) const { - absl::MutexLockMaybe lock(mutex_); + MutexLockMaybe lock(mutex_); return NewPlaceholderWithMutexHeld(name, placeholder_type); } Symbol DescriptorPool::NewPlaceholderWithMutexHeld( - absl::string_view name, PlaceholderType placeholder_type) const { + StringPiece name, PlaceholderType placeholder_type) const { if (mutex_) { mutex_->AssertHeld(); } // Compute names. - absl::string_view placeholder_full_name; - absl::string_view placeholder_name; + StringPiece placeholder_full_name; + StringPiece placeholder_name; const std::string* placeholder_package; if (!ValidateQualifiedName(name)) return Symbol(); @@ -4463,7 +4512,7 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld( } FileDescriptor* placeholder_file = NewPlaceholderFileWithMutexHeld( - absl::StrCat(placeholder_full_name, ".placeholder.proto"), alloc); + StrCat(placeholder_full_name, ".placeholder.proto"), alloc); placeholder_file->package_ = placeholder_package; if (placeholder_type == PLACEHOLDER_ENUM) { @@ -4532,8 +4581,8 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld( } FileDescriptor* DescriptorPool::NewPlaceholderFile( - absl::string_view name) const { - absl::MutexLockMaybe lock(mutex_); + StringPiece name) const { + MutexLockMaybe lock(mutex_); internal::FlatAllocator alloc; alloc.PlanArray(1); alloc.PlanArray(1); @@ -4543,7 +4592,7 @@ FileDescriptor* DescriptorPool::NewPlaceholderFile( } FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld( - absl::string_view name, internal::FlatAllocator& alloc) const { + StringPiece name, internal::FlatAllocator& alloc) const { if (mutex_) { mutex_->AssertHeld(); } @@ -4933,8 +4982,7 @@ static void PlanAllocationSize(const FileDescriptorProto& proto, internal::FlatAllocator& alloc) { alloc.PlanArray(1); alloc.PlanArray(1); - alloc.PlanArray(2 - ); // name + package + alloc.PlanArray(2); // name + package if (proto.has_options()) alloc.PlanArray(1); if (proto.has_source_code_info()) alloc.PlanArray(1); @@ -5103,13 +5151,13 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl( } // Make sure all dependencies are loaded. - absl::flat_hash_set seen_dependencies; + std::set seen_dependencies; result->dependency_count_ = proto.dependency_size(); result->dependencies_ = alloc.AllocateArray(proto.dependency_size()); result->dependencies_once_ = nullptr; unused_dependency_.clear(); - absl::flat_hash_set weak_deps; + std::set weak_deps; for (int i = 0; i < proto.weak_dependency_size(); ++i) { weak_deps.insert(proto.weak_dependency(i)); } @@ -5135,7 +5183,7 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl( if (dependency == nullptr) { if (!pool_->lazily_build_dependencies_) { if (pool_->allow_unknown_ || - (!pool_->enforce_weak_ && weak_deps.contains(i))) { + (!pool_->enforce_weak_ && weak_deps.find(i) != weak_deps.end())) { internal::FlatAllocator lazy_dep_alloc; lazy_dep_alloc.PlanArray(1); lazy_dep_alloc.PlanArray(1); @@ -5172,8 +5220,8 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl( } void* data = tables_->AllocateBytes( - static_cast(sizeof(absl::once_flag)) + total_char_size); - result->dependencies_once_ = ::new (data) absl::once_flag{}; + static_cast(sizeof(internal::once_flag) + total_char_size)); + result->dependencies_once_ = ::new (data) internal::once_flag{}; char* name_data = reinterpret_cast(result->dependencies_once_ + 1); for (int i = 0; i < proto.dependency_size(); i++) { @@ -5310,7 +5358,7 @@ const std::string* DescriptorBuilder::AllocateNameStrings( return alloc.AllocateStrings(proto_name, proto_name); } else { return alloc.AllocateStrings(proto_name, - absl::StrCat(scope, ".", proto_name)); + StrCat(scope, ".", proto_name)); } } @@ -5404,7 +5452,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, if (range1.end() > range2.start() && range2.end() > range1.start()) { AddError(result->full_name(), proto.reserved_range(i), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Reserved range $0 to $1 overlaps with " + strings::Substitute("Reserved range $0 to $1 overlaps with " "already-defined range $2 to $3.", range2.start(), range2.end() - 1, range1.start(), range1.end() - 1)); @@ -5412,12 +5460,14 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, } } - absl::flat_hash_set reserved_name_set; + HASH_SET reserved_name_set; for (int i = 0; i < proto.reserved_name_size(); i++) { const std::string& name = proto.reserved_name(i); - if (!reserved_name_set.insert(name).second) { + if (reserved_name_set.find(name) == reserved_name_set.end()) { + reserved_name_set.insert(name); + } else { AddError(name, proto, DescriptorPool::ErrorCollector::NAME, - absl::Substitute("Field name \"$0\" is reserved multiple times.", + strings::Substitute("Field name \"$0\" is reserved multiple times.", name)); } } @@ -5433,7 +5483,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, AddError( field->full_name(), proto.extension_range(j), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute( + strings::Substitute( "Extension range $0 to $1 includes field \"$2\" ($3).", range->start, range->end - 1, field->name(), field->number())); } @@ -5445,7 +5495,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, proto.reserved_range(j), DescriptorPool::ErrorCollector::NUMBER); AddError(field->full_name(), proto.reserved_range(j), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Field \"$0\" uses reserved number $1.", + strings::Substitute("Field \"$0\" uses reserved number $1.", field->name(), field->number())); } } @@ -5453,7 +5503,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, AddError( field->full_name(), proto.field(i), DescriptorPool::ErrorCollector::NAME, - absl::Substitute("Field name \"$0\" is reserved.", field->name())); + strings::Substitute("Field name \"$0\" is reserved.", field->name())); } } @@ -5467,7 +5517,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, if (range1->end > range2->start && range2->end > range1->start) { AddError(result->full_name(), proto.extension_range(i), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Extension range $0 to $1 overlaps with " + strings::Substitute("Extension range $0 to $1 overlaps with " "reserved range $2 to $3.", range1->start, range1->end - 1, range2->start, range2->end - 1)); @@ -5478,7 +5528,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto, if (range1->end > range2->start && range2->end > range1->start) { AddError(result->full_name(), proto.extension_range(i), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Extension range $0 to $1 overlaps with " + strings::Substitute("Extension range $0 to $1 overlaps with " "already-defined range $2 to $3.", range2->start, range2->end - 1, range1->start, range1->end - 1)); @@ -5526,9 +5576,9 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, // Some compilers do not allow static_cast directly between two enum types, // so we must cast to int first. result->type_ = static_cast( - absl::implicit_cast(proto.type())); + implicit_cast(proto.type())); result->label_ = static_cast( - absl::implicit_cast(proto.label())); + implicit_cast(proto.label())); if (result->label_ == FieldDescriptor::LABEL_REQUIRED) { // An extension cannot have a required field (b/13365836). @@ -5623,9 +5673,8 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, break; case FieldDescriptor::CPPTYPE_STRING: if (result->type() == FieldDescriptor::TYPE_BYTES) { - std::string value; - absl::CUnescape(proto.default_value(), &value); - result->default_value_string_ = alloc.AllocateStrings(value); + result->default_value_string_ = alloc.AllocateStrings( + UnescapeCEscapeString(proto.default_value())); } else { result->default_value_string_ = alloc.AllocateStrings(proto.default_value()); @@ -5706,14 +5755,14 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, message_hints_[parent].RequestHintOnFieldNumbers( proto, DescriptorPool::ErrorCollector::NUMBER); AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Field numbers cannot be greater than $0.", + strings::Substitute("Field numbers cannot be greater than $0.", FieldDescriptor::kMaxNumber)); } else if (result->number() >= FieldDescriptor::kFirstReservedNumber && result->number() <= FieldDescriptor::kLastReservedNumber) { message_hints_[parent].RequestHintOnFieldNumbers( proto, DescriptorPool::ErrorCollector::NUMBER); AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute( + strings::Substitute( "Field numbers $0 through $1 are reserved for the protocol " "buffer library implementation.", FieldDescriptor::kFirstReservedNumber, @@ -5748,7 +5797,7 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto, proto.oneof_index() >= parent->oneof_decl_count()) { AddError(result->full_name(), proto, DescriptorPool::ErrorCollector::TYPE, - absl::Substitute("FieldDescriptorProto.oneof_index $0 is " + strings::Substitute("FieldDescriptorProto.oneof_index $0 is " "out of range for type \"$1\".", proto.oneof_index(), parent->name())); } else { @@ -5997,7 +6046,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, if (range1.end() >= range2.start() && range2.end() >= range1.start()) { AddError(result->full_name(), proto.reserved_range(i), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Reserved range $0 to $1 overlaps with " + strings::Substitute("Reserved range $0 to $1 overlaps with " "already-defined range $2 to $3.", range2.start(), range2.end(), range1.start(), range1.end())); @@ -6005,14 +6054,14 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, } } - absl::flat_hash_set reserved_name_set; + HASH_SET reserved_name_set; for (int i = 0; i < proto.reserved_name_size(); i++) { const std::string& name = proto.reserved_name(i); if (reserved_name_set.find(name) == reserved_name_set.end()) { reserved_name_set.insert(name); } else { AddError(name, proto, DescriptorPool::ErrorCollector::NAME, - absl::Substitute("Enum value \"$0\" is reserved multiple times.", + strings::Substitute("Enum value \"$0\" is reserved multiple times.", name)); } } @@ -6024,7 +6073,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, if (range->start <= value->number() && value->number() <= range->end) { AddError(value->full_name(), proto.reserved_range(j), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Enum value \"$0\" uses reserved number $1.", + strings::Substitute("Enum value \"$0\" uses reserved number $1.", value->name(), value->number())); } } @@ -6032,7 +6081,7 @@ void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto, AddError( value->full_name(), proto.value(i), DescriptorPool::ErrorCollector::NAME, - absl::Substitute("Enum value \"$0\" is reserved.", value->name())); + strings::Substitute("Enum value \"$0\" is reserved.", value->name())); } } } @@ -6230,7 +6279,7 @@ void DescriptorBuilder::CrossLinkMessage(Descriptor* message, message->field(i - 1)->containing_oneof() != oneof_decl) { AddError(message->full_name() + "." + message->field(i - 1)->name(), proto.field(i - 1), DescriptorPool::ErrorCollector::TYPE, - absl::Substitute( + strings::Substitute( "Fields in the same oneof must be defined consecutively. " "\"$0\" cannot be defined before the completion of the " "\"$1\" oneof definition.", @@ -6350,7 +6399,7 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field, if (!skip_check) { AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("\"$0\" does not declare $1 as an " + strings::Substitute("\"$0\" does not declare $1 as an " "extension number.", field->containing_type()->full_name(), field->number())); @@ -6400,9 +6449,8 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field, int name_sizes = static_cast(name.size() + 1 + proto.default_value().size() + 1); - field->type_once_ = ::new (tables_->AllocateBytes( - static_cast(sizeof(absl::once_flag)) + name_sizes)) - absl::once_flag{}; + field->type_once_ = ::new (tables_->AllocateBytes(static_cast( + sizeof(internal::once_flag) + name_sizes))) internal::once_flag{}; char* names = reinterpret_cast(field->type_once_ + 1); memcpy(names, name.c_str(), name.size() + 1); @@ -6541,14 +6589,14 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field, if (field->is_extension()) { AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Extension number $0 has already been used " + strings::Substitute("Extension number $0 has already been used " "in \"$1\" by extension \"$2\".", field->number(), containing_type_name, conflicting_field->full_name())); } else { AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Field number $0 has already been used in " + strings::Substitute("Field number $0 has already been used in " "\"$1\" by field \"$2\".", field->number(), containing_type_name, conflicting_field->name())); @@ -6562,7 +6610,7 @@ void DescriptorBuilder::CrossLinkField(FieldDescriptor* field, field->containing_type() == nullptr ? "unknown" : field->containing_type()->full_name(); - std::string error_msg = absl::Substitute( + std::string error_msg = strings::Substitute( "Extension number $0 has already been used in \"$1\" by extension " "\"$2\" defined in $3.", field->number(), containing_type_name, @@ -6660,9 +6708,8 @@ void DescriptorBuilder::SuggestFieldNumbers(FileDescriptor* file, for (int message_index = 0; message_index < file->message_type_count(); message_index++) { const Descriptor* message = &file->message_types_[message_index]; - auto hints_it = message_hints_.find(message); - if (hints_it == message_hints_.end()) continue; - auto* hints = &hints_it->second; + auto* hints = FindOrNull(message_hints_, message); + if (!hints) continue; constexpr int kMaxSuggestions = 3; int fields_to_suggest = std::min(kMaxSuggestions, hints->fields_to_suggest); if (fields_to_suggest <= 0) continue; @@ -6904,7 +6951,7 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message, if (message->extension_range(i)->end > max_extension_range + 1) { AddError(message->full_name(), proto.extension_range(i), DescriptorPool::ErrorCollector::NUMBER, - absl::Substitute("Extension numbers cannot be greater than $0.", + strings::Substitute("Extension numbers cannot be greater than $0.", max_extension_range)); } @@ -7262,7 +7309,7 @@ bool DescriptorBuilder::OptionInterpreter::InterpretOptions( *original_options, original_uninterpreted_options_field); for (int i = 0; i < num_uninterpreted_options; ++i) { src_path.push_back(i); - uninterpreted_option_ = DownCast( + uninterpreted_option_ = down_cast( &original_options->GetReflection()->GetRepeatedMessage( *original_options, original_uninterpreted_options_field, i)); if (!InterpretSingleOption(options, src_path, @@ -7682,27 +7729,6 @@ bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet( return true; } -namespace { -// Helpers for method below - -template std::string ValueOutOfRange( - absl::string_view type_name, absl::string_view option_name) { - return absl::StrFormat( - "Value out of range, %d to %d, for %s option \"%s\".", \ - std::numeric_limits::min(), std::numeric_limits::max(), - type_name, option_name); -} - -template std::string ValueMustBeInt( - absl::string_view type_name, absl::string_view option_name) { - return absl::StrFormat( - "Value must be integer, from %d to %d, for %s option \"%s\".", \ - std::numeric_limits::min(), std::numeric_limits::max(), - type_name, option_name); -} - -} // namespace - bool DescriptorBuilder::OptionInterpreter::SetOptionValue( const FieldDescriptor* option_field, UnknownFieldSet* unknown_fields) { // We switch on the CppType to validate. @@ -7711,7 +7737,8 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError(ValueOutOfRange("int32", option_field->full_name())); + return AddValueError("Value out of range for int32 option \"" + + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7720,14 +7747,16 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( } else if (uninterpreted_option_->has_negative_int_value()) { if (uninterpreted_option_->negative_int_value() < static_cast(std::numeric_limits::min())) { - return AddValueError(ValueOutOfRange("int32", option_field->full_name())); + return AddValueError("Value out of range for int32 option \"" + + option_field->full_name() + "\"."); } else { SetInt32(option_field->number(), uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError(ValueMustBeInt("int32", option_field->full_name())); + return AddValueError("Value must be integer for int32 option \"" + + option_field->full_name() + "\"."); } break; @@ -7735,7 +7764,8 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > static_cast(std::numeric_limits::max())) { - return AddValueError(ValueOutOfRange("int64", option_field->full_name())); + return AddValueError("Value out of range for int64 option \"" + + option_field->full_name() + "\"."); } else { SetInt64(option_field->number(), uninterpreted_option_->positive_int_value(), @@ -7746,7 +7776,8 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->negative_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(ValueMustBeInt("int64", option_field->full_name())); + return AddValueError("Value must be integer for int64 option \"" + + option_field->full_name() + "\"."); } break; @@ -7754,14 +7785,18 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( if (uninterpreted_option_->has_positive_int_value()) { if (uninterpreted_option_->positive_int_value() > std::numeric_limits::max()) { - return AddValueError(ValueOutOfRange("uint32", option_field->full_name())); + return AddValueError("Value out of range for uint32 option \"" + + option_field->name() + "\"."); } else { SetUInt32(option_field->number(), uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } } else { - return AddValueError(ValueMustBeInt("uint32", option_field->full_name())); + return AddValueError( + "Value must be non-negative integer for uint32 " + "option \"" + + option_field->full_name() + "\"."); } break; @@ -7771,7 +7806,10 @@ bool DescriptorBuilder::OptionInterpreter::SetOptionValue( uninterpreted_option_->positive_int_value(), option_field->type(), unknown_fields); } else { - return AddValueError(ValueMustBeInt("uint64", option_field->full_name())); + return AddValueError( + "Value must be non-negative integer for uint64 " + "option \"" + + option_field->full_name() + "\"."); } break; @@ -8116,20 +8154,22 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, auto itr = pool_->unused_import_track_files_.find(proto.name()); bool is_error = itr != pool_->unused_import_track_files_.end() && itr->second; - for (const auto* unused : unused_dependency_) { - std::string error_message = "Import " + unused->name() + " is unused."; + for (std::set::const_iterator it = + unused_dependency_.begin(); + it != unused_dependency_.end(); ++it) { + std::string error_message = "Import " + (*it)->name() + " is unused."; if (is_error) { - AddError(unused->name(), proto, DescriptorPool::ErrorCollector::IMPORT, + AddError((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT, error_message); } else { - AddWarning(unused->name(), proto, - DescriptorPool::ErrorCollector::IMPORT, error_message); + AddWarning((*it)->name(), proto, DescriptorPool::ErrorCollector::IMPORT, + error_message); } } } } -Symbol DescriptorPool::CrossLinkOnDemandHelper(absl::string_view name, +Symbol DescriptorPool::CrossLinkOnDemandHelper(StringPiece name, bool expecting_enum) const { (void)expecting_enum; // Parameter is used by Google-internal code. auto lookup_name = std::string(name); @@ -8191,11 +8231,11 @@ void FieldDescriptor::TypeOnceInit(const FieldDescriptor* to_init) { } // message_type(), enum_type(), default_value_enum(), and type() -// all share the same absl::call_once init path to do lazy +// all share the same internal::call_once init path to do lazy // import building and cross linking of a field of a message. const Descriptor* FieldDescriptor::message_type() const { if (type_once_) { - absl::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); + internal::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); } return type_ == TYPE_MESSAGE || type_ == TYPE_GROUP ? type_descriptor_.message_type @@ -8204,14 +8244,14 @@ const Descriptor* FieldDescriptor::message_type() const { const EnumDescriptor* FieldDescriptor::enum_type() const { if (type_once_) { - absl::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); + internal::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); } return type_ == TYPE_ENUM ? type_descriptor_.enum_type : nullptr; } const EnumValueDescriptor* FieldDescriptor::default_value_enum() const { if (type_once_) { - absl::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); + internal::call_once(*type_once_, FieldDescriptor::TypeOnceInit, this); } return default_value_enum_; } @@ -8244,9 +8284,9 @@ void FileDescriptor::DependenciesOnceInit(const FileDescriptor* to_init) { const FileDescriptor* FileDescriptor::dependency(int index) const { if (dependencies_once_) { // Do once init for all indices, as it's unlikely only a single index would - // be called, and saves on absl::call_once allocations. - absl::call_once(*dependencies_once_, FileDescriptor::DependenciesOnceInit, - this); + // be called, and saves on internal::call_once allocations. + internal::call_once(*dependencies_once_, + FileDescriptor::DependenciesOnceInit, this); } return dependencies_[index]; } @@ -8265,7 +8305,7 @@ void LazyDescriptor::Set(const Descriptor* descriptor) { descriptor_ = descriptor; } -void LazyDescriptor::SetLazy(absl::string_view name, +void LazyDescriptor::SetLazy(StringPiece name, const FileDescriptor* file) { // verify Init() has been called and Set hasn't been called yet. GOOGLE_CHECK(!descriptor_); @@ -8274,7 +8314,7 @@ void LazyDescriptor::SetLazy(absl::string_view name, GOOGLE_CHECK(file->pool_->lazily_build_dependencies_); GOOGLE_CHECK(!file->finished_building_); once_ = ::new (file->pool_->tables_->AllocateBytes(static_cast( - sizeof(absl::once_flag) + name.size() + 1))) absl::once_flag{}; + sizeof(internal::once_flag) + name.size() + 1))) internal::once_flag{}; char* lazy_name = reinterpret_cast(once_ + 1); memcpy(lazy_name, name.data(), name.size()); lazy_name[name.size()] = 0; @@ -8282,7 +8322,7 @@ void LazyDescriptor::SetLazy(absl::string_view name, void LazyDescriptor::Once(const ServiceDescriptor* service) { if (once_) { - absl::call_once(*once_, [&] { + internal::call_once(*once_, [&] { auto* file = service->file(); GOOGLE_CHECK(file->finished_building_); const char* lazy_name = reinterpret_cast(once_ + 1); @@ -8292,51 +8332,9 @@ void LazyDescriptor::Once(const ServiceDescriptor* service) { } } -namespace cpp { -bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) { - return field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - -bool HasHasbit(const FieldDescriptor* field) { - // This predicate includes proto3 message fields only if they have "optional". - // Foo submsg1 = 1; // HasHasbit() == false - // optional Foo submsg2 = 2; // HasHasbit() == true - // This is slightly odd, as adding "optional" to a singular proto3 field does - // not change the semantics or API. However whenever any field in a message - // has a hasbit, it forces reflection to include hasbit offsets for *all* - // fields, even if almost all of them are set to -1 (no hasbit). So to avoid - // causing a sudden size regression for ~all proto3 messages, we give proto3 - // message fields a hasbit only if "optional" is present. If the user is - // explicitly writing "optional", it is likely they are writing it on - // primitive fields also. - return (field->has_optional_keyword() || field->is_required()) && - !field->options().weak(); -} - -static bool FieldEnforceUtf8(const FieldDescriptor* field) { - return true; -} - -static bool FileUtf8Verification(const FileDescriptor* file) { - return true; -} - -// Which level of UTF-8 enforcemant is placed on this file. -Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, bool is_lite) { - if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && - FieldEnforceUtf8(field)) { - return Utf8CheckMode::kStrict; - } else if (!is_lite && FileUtf8Verification(field->file())) { - return Utf8CheckMode::kVerify; - } else { - return Utf8CheckMode::kNone; - } -} - -} // namespace cpp } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/descriptor.h b/libs/protobuf/src/google/protobuf/descriptor.h index 5a8b5f3..6e536e5 100644 --- a/libs/protobuf/src/google/protobuf/descriptor.h +++ b/libs/protobuf/src/google/protobuf/descriptor.h @@ -54,26 +54,27 @@ #ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__ #define GOOGLE_PROTOBUF_DESCRIPTOR_H__ + #include -#include -#include #include #include #include #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/port.h" -#include "absl/base/call_once.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include + +// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. +#ifdef TYPE_BOOL +#undef TYPE_BOOL +#endif // TYPE_BOOL #ifdef SWIG #define PROTOBUF_EXPORT @@ -219,7 +220,7 @@ class PROTOBUF_EXPORT LazyDescriptor { // build time if the symbol wasn't found and building of the file containing // that type is delayed because lazily_build_dependencies_ is set on the pool. // Should not be called after Set() has been called. - void SetLazy(absl::string_view name, const FileDescriptor* file); + void SetLazy(StringPiece name, const FileDescriptor* file); // Returns the current value of the descriptor, thread-safe. If SetLazy(...) // has been called, will do a one-time cross link of the type specified, @@ -234,7 +235,7 @@ class PROTOBUF_EXPORT LazyDescriptor { const Descriptor* descriptor_; // The once_ flag is followed by a NUL terminated string for the type name. - absl::once_flag* once_; + internal::once_flag* once_; }; class PROTOBUF_EXPORT SymbolBase { @@ -260,10 +261,6 @@ class PROTOBUF_EXPORT SymbolBaseN : public SymbolBase {}; class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { public: typedef DescriptorProto Proto; -#ifndef SWIG - Descriptor(const Descriptor&) = delete; - Descriptor& operator=(const Descriptor&) = delete; -#endif // The name of the message type, not including its scope. const std::string& name() const; @@ -352,20 +349,20 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // exists. const FieldDescriptor* FindFieldByNumber(int number) const; // Looks up a field by name. Returns nullptr if no such field exists. - const FieldDescriptor* FindFieldByName(absl::string_view name) const; + const FieldDescriptor* FindFieldByName(ConstStringParam name) const; // Looks up a field by lowercased name (as returned by lowercase_name()). // This lookup may be ambiguous if multiple field names differ only by case, // in which case the field returned is chosen arbitrarily from the matches. const FieldDescriptor* FindFieldByLowercaseName( - absl::string_view lowercase_name) const; + ConstStringParam lowercase_name) const; // Looks up a field by camel-case name (as returned by camelcase_name()). // This lookup may be ambiguous if multiple field names differ in a way that // leads them to have identical camel-case names, in which case the field // returned is chosen arbitrarily from the matches. const FieldDescriptor* FindFieldByCamelcaseName( - absl::string_view camelcase_name) const; + ConstStringParam camelcase_name) const; // The number of oneofs in this message type. int oneof_decl_count() const; @@ -378,7 +375,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { const OneofDescriptor* oneof_decl(int index) const; // Looks up a oneof by name. Returns nullptr if no such oneof exists. - const OneofDescriptor* FindOneofByName(absl::string_view name) const; + const OneofDescriptor* FindOneofByName(ConstStringParam name) const; // Nested type stuff ----------------------------------------------- @@ -390,7 +387,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // Looks up a nested type by name. Returns nullptr if no such nested type // exists. - const Descriptor* FindNestedTypeByName(absl::string_view name) const; + const Descriptor* FindNestedTypeByName(ConstStringParam name) const; // Enum stuff ------------------------------------------------------ @@ -402,11 +399,11 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // Looks up an enum type by name. Returns nullptr if no such enum type // exists. - const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const; + const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; // Looks up an enum value by name, among all enum types in this message. // Returns nullptr if no such value exists. - const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const; + const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; // Extensions ------------------------------------------------------ @@ -470,17 +467,17 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { // Looks up a named extension (which extends some *other* message type) // defined within this message type's scope. - const FieldDescriptor* FindExtensionByName(absl::string_view name) const; + const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; // Similar to FindFieldByLowercaseName(), but finds extensions defined within // this message type's scope. const FieldDescriptor* FindExtensionByLowercaseName( - absl::string_view name) const; + ConstStringParam name) const; // Similar to FindFieldByCamelcaseName(), but finds extensions defined within // this message type's scope. const FieldDescriptor* FindExtensionByCamelcaseName( - absl::string_view name) const; + ConstStringParam name) const; // Reserved fields ------------------------------------------------- @@ -510,7 +507,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { const std::string& reserved_name(int index) const; // Returns true if the field name is reserved. - bool IsReservedName(absl::string_view name) const; + bool IsReservedName(ConstStringParam name) const; // Source Location --------------------------------------------------- @@ -612,6 +609,7 @@ class PROTOBUF_EXPORT Descriptor : private internal::SymbolBase { friend class OneofDescriptor; friend class MethodDescriptor; friend class FileDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(Descriptor, 136); @@ -630,11 +628,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { public: typedef FieldDescriptorProto Proto; -#ifndef SWIG - FieldDescriptor(const FieldDescriptor&) = delete; - FieldDescriptor& operator=(const FieldDescriptor&) = delete; -#endif - // Identifies a field type. 0 is reserved for errors. The order is weird // for historical reasons. Types 12 and up are new in proto2. enum Type { @@ -761,10 +754,6 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { // Reflection::HasField() is semantically meaningful. bool has_presence() const; - // Returns true if this TYPE_STRING-typed field requires UTF-8 validation on - // parse. - bool requires_utf8_validation() const; - // Index of this field within the message's field array, or the file or // extension scope's extensions array. int index() const; @@ -952,7 +941,7 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { // The once_flag is followed by a NUL terminated string for the type name and // enum default value (or empty string if no default enum). - absl::once_flag* type_once_; + internal::once_flag* type_once_; static void TypeOnceInit(const FieldDescriptor* to_init); void InternalTypeOnceInit() const; const Descriptor* containing_type_; @@ -997,6 +986,7 @@ class PROTOBUF_EXPORT FieldDescriptor : private internal::SymbolBase { friend class FileDescriptor; friend class Descriptor; friend class OneofDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FieldDescriptor, 72); @@ -1006,11 +996,6 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase { public: typedef OneofDescriptorProto Proto; -#ifndef SWIG - OneofDescriptor(const OneofDescriptor&) = delete; - OneofDescriptor& operator=(const OneofDescriptor&) = delete; -#endif - const std::string& name() const; // Name of this oneof. const std::string& full_name() const; // Fully-qualified name of the oneof. @@ -1082,6 +1067,7 @@ class PROTOBUF_EXPORT OneofDescriptor : private internal::SymbolBase { OneofDescriptor() {} friend class DescriptorBuilder; friend class Descriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(OneofDescriptor, 40); @@ -1093,11 +1079,6 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { public: typedef EnumDescriptorProto Proto; -#ifndef SWIG - EnumDescriptor(const EnumDescriptor&) = delete; - EnumDescriptor& operator=(const EnumDescriptor&) = delete; -#endif - // The name of this enum type in the containing scope. const std::string& name() const; @@ -1118,7 +1099,7 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { const EnumValueDescriptor* value(int index) const; // Looks up a value by name. Returns nullptr if no such value exists. - const EnumValueDescriptor* FindValueByName(absl::string_view name) const; + const EnumValueDescriptor* FindValueByName(ConstStringParam name) const; // Looks up a value by number. Returns nullptr if no such value exists. If // multiple values have this number, the first one defined is returned. const EnumValueDescriptor* FindValueByNumber(int number) const; @@ -1147,13 +1128,6 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { // with AllowUnknownDependencies() set. bool is_placeholder() const; - // Returns true whether this is a "closed" enum, meaning that it: - // - Has a fixed set of named values. - // - Encountering values not in this set causes them to be treated as unknown - // fields. - // - The first value (i.e., the default) may be nonzero. - bool is_closed() const; - // Reserved fields ------------------------------------------------- // A range of reserved field numbers. @@ -1183,7 +1157,7 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { const std::string& reserved_name(int index) const; // Returns true if the field name is reserved. - bool IsReservedName(absl::string_view name) const; + bool IsReservedName(ConstStringParam name) const; // Source Location --------------------------------------------------- @@ -1264,6 +1238,7 @@ class PROTOBUF_EXPORT EnumDescriptor : private internal::SymbolBase { friend class FileDescriptor; friend class DescriptorPool; friend class Reflection; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumDescriptor, 72); @@ -1278,11 +1253,6 @@ class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>, public: typedef EnumValueDescriptorProto Proto; -#ifndef SWIG - EnumValueDescriptor(const EnumValueDescriptor&) = delete; - EnumValueDescriptor& operator=(const EnumValueDescriptor&) = delete; -#endif - const std::string& name() const; // Name of this enum constant. int index() const; // Index within the enums's Descriptor. int number() const; // Numeric value of this enum constant. @@ -1353,6 +1323,7 @@ class PROTOBUF_EXPORT EnumValueDescriptor : private internal::SymbolBaseN<0>, friend class DescriptorPool; friend class FileDescriptorTables; friend class Reflection; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(EnumValueDescriptor, 32); @@ -1363,11 +1334,6 @@ class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase { public: typedef ServiceDescriptorProto Proto; -#ifndef SWIG - ServiceDescriptor(const ServiceDescriptor&) = delete; - ServiceDescriptor& operator=(const ServiceDescriptor&) = delete; -#endif - // The name of the service, not including its containing scope. const std::string& name() const; // The fully-qualified name of the service, scope delimited by periods. @@ -1391,7 +1357,7 @@ class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase { const MethodDescriptor* method(int index) const; // Look up a MethodDescriptor by name. - const MethodDescriptor* FindMethodByName(absl::string_view name) const; + const MethodDescriptor* FindMethodByName(ConstStringParam name) const; // See Descriptor::CopyTo(). void CopyTo(ServiceDescriptorProto* proto) const; @@ -1440,6 +1406,7 @@ class PROTOBUF_EXPORT ServiceDescriptor : private internal::SymbolBase { friend class DescriptorBuilder; friend class FileDescriptor; friend class MethodDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(ServiceDescriptor, 48); @@ -1452,11 +1419,6 @@ class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase { public: typedef MethodDescriptorProto Proto; -#ifndef SWIG - MethodDescriptor(const MethodDescriptor&) = delete; - MethodDescriptor& operator=(const MethodDescriptor&) = delete; -#endif - // Name of this method, not including containing scope. const std::string& name() const; // The fully-qualified name of the method, scope delimited by periods. @@ -1533,6 +1495,7 @@ class PROTOBUF_EXPORT MethodDescriptor : private internal::SymbolBase { MethodDescriptor() {} friend class DescriptorBuilder; friend class ServiceDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); }; PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(MethodDescriptor, 64); @@ -1544,11 +1507,6 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { public: typedef FileDescriptorProto Proto; -#ifndef SWIG - FileDescriptor(const FileDescriptor&) = delete; - FileDescriptor& operator=(const FileDescriptor&) = delete; -#endif - // The filename, relative to the source tree. // e.g. "foo/bar/baz.proto" const std::string& name() const; @@ -1616,11 +1574,7 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { const FileOptions& options() const; // Syntax of this file. - enum Syntax -#ifndef SWIG - : int -#endif // !SWIG - { + enum Syntax { SYNTAX_UNKNOWN = 0, SYNTAX_PROTO2 = 2, SYNTAX_PROTO3 = 3, @@ -1630,25 +1584,25 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { // Find a top-level message type by name (not full_name). Returns nullptr if // not found. - const Descriptor* FindMessageTypeByName(absl::string_view name) const; + const Descriptor* FindMessageTypeByName(ConstStringParam name) const; // Find a top-level enum type by name. Returns nullptr if not found. - const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const; + const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; // Find an enum value defined in any top-level enum by name. Returns nullptr // if not found. - const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const; + const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; // Find a service definition by name. Returns nullptr if not found. - const ServiceDescriptor* FindServiceByName(absl::string_view name) const; + const ServiceDescriptor* FindServiceByName(ConstStringParam name) const; // Find a top-level extension definition by name. Returns nullptr if not // found. - const FieldDescriptor* FindExtensionByName(absl::string_view name) const; + const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; // Similar to FindExtensionByName(), but searches by lowercased-name. See // Descriptor::FindFieldByLowercaseName(). const FieldDescriptor* FindExtensionByLowercaseName( - absl::string_view name) const; + ConstStringParam name) const; // Similar to FindExtensionByName(), but searches by camelcased-name. See // Descriptor::FindFieldByCamelcaseName(). const FieldDescriptor* FindExtensionByCamelcaseName( - absl::string_view name) const; + ConstStringParam name) const; // See Descriptor::CopyTo(). // Notes: @@ -1661,9 +1615,6 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { // Fill the json_name field of FieldDescriptorProto for all fields. Can only // be called after CopyTo(). void CopyJsonNameTo(FileDescriptorProto* proto) const; - // Fills in the file-level settings of this file (e.g. syntax, package, - // file options) to `proto`. - void CopyHeadingTo(FileDescriptorProto* proto) const; // See Descriptor::DebugString(). std::string DebugString() const; @@ -1709,7 +1660,7 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { // dependencies_once_ contain a once_flag followed by N NUL terminated // strings. Dependencies that do not need to be loaded will be empty. ie just // {'\0'} - absl::once_flag* dependencies_once_; + internal::once_flag* dependencies_once_; static void DependenciesOnceInit(const FileDescriptor* to_init); void InternalDependenciesOnceInit() const; @@ -1748,9 +1699,10 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase { friend class EnumValueDescriptor; friend class MethodDescriptor; friend class ServiceDescriptor; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); }; -PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FileDescriptor, 152); +PROTOBUF_INTERNAL_CHECK_CLASS_SIZE(FileDescriptor, 144); // =================================================================== @@ -1810,10 +1762,6 @@ class PROTOBUF_EXPORT DescriptorPool { explicit DescriptorPool(DescriptorDatabase* fallback_database, ErrorCollector* error_collector = nullptr); -#ifndef SWIG - DescriptorPool(const DescriptorPool&) = delete; - DescriptorPool& operator=(const DescriptorPool&) = delete; -#endif ~DescriptorPool(); // Get a pointer to the generated pool. Generated protocol message classes @@ -1824,28 +1772,28 @@ class PROTOBUF_EXPORT DescriptorPool { // Find a FileDescriptor in the pool by file name. Returns nullptr if not // found. - const FileDescriptor* FindFileByName(absl::string_view name) const; + const FileDescriptor* FindFileByName(ConstStringParam name) const; // Find the FileDescriptor in the pool which defines the given symbol. // If any of the Find*ByName() methods below would succeed, then this is // equivalent to calling that method and calling the result's file() method. // Otherwise this returns nullptr. const FileDescriptor* FindFileContainingSymbol( - absl::string_view symbol_name) const; + ConstStringParam symbol_name) const; // Looking up descriptors ------------------------------------------ // These find descriptors by fully-qualified name. These will find both // top-level descriptors and nested descriptors. They return nullptr if not // found. - const Descriptor* FindMessageTypeByName(absl::string_view name) const; - const FieldDescriptor* FindFieldByName(absl::string_view name) const; - const FieldDescriptor* FindExtensionByName(absl::string_view name) const; - const OneofDescriptor* FindOneofByName(absl::string_view name) const; - const EnumDescriptor* FindEnumTypeByName(absl::string_view name) const; - const EnumValueDescriptor* FindEnumValueByName(absl::string_view name) const; - const ServiceDescriptor* FindServiceByName(absl::string_view name) const; - const MethodDescriptor* FindMethodByName(absl::string_view name) const; + const Descriptor* FindMessageTypeByName(ConstStringParam name) const; + const FieldDescriptor* FindFieldByName(ConstStringParam name) const; + const FieldDescriptor* FindExtensionByName(ConstStringParam name) const; + const OneofDescriptor* FindOneofByName(ConstStringParam name) const; + const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const; + const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const; + const ServiceDescriptor* FindServiceByName(ConstStringParam name) const; + const MethodDescriptor* FindMethodByName(ConstStringParam name) const; // Finds an extension of the given type by number. The extendee must be // a member of this DescriptorPool or one of its underlays. @@ -1858,7 +1806,7 @@ class PROTOBUF_EXPORT DescriptorPool { // or one of its underlays. Returns nullptr if there is no known message // extension with the given printable name. const FieldDescriptor* FindExtensionByPrintableName( - const Descriptor* extendee, absl::string_view printable_name) const; + const Descriptor* extendee, ConstStringParam printable_name) const; // Finds extensions of extendee. The extensions will be appended to // out in an undefined order. Only extensions defined directly in @@ -1876,10 +1824,6 @@ class PROTOBUF_EXPORT DescriptorPool { class PROTOBUF_EXPORT ErrorCollector { public: inline ErrorCollector() {} -#ifndef SWIG - ErrorCollector(const ErrorCollector&) = delete; - ErrorCollector& operator=(const ErrorCollector&) = delete; -#endif virtual ~ErrorCollector(); // These constants specify what exact part of the construct is broken. @@ -1920,6 +1864,9 @@ class PROTOBUF_EXPORT DescriptorPool { ErrorLocation /*location*/, // One of the location constants, above. const std::string& /*message*/ // Human-readable error message. ) {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); }; // Convert the FileDescriptorProto to real descriptors and place them in @@ -2032,11 +1979,11 @@ class PROTOBUF_EXPORT DescriptorPool { // For internal (unit test) use only: Returns true if a FileDescriptor has // been constructed for the given file, false otherwise. Useful for testing // lazy descriptor initialization behavior. - bool InternalIsFileLoaded(absl::string_view filename) const; + bool InternalIsFileLoaded(ConstStringParam filename) const; // Add a file to unused_import_track_files_. DescriptorBuilder will log // warnings or errors for those files if there is any unused import. - void AddUnusedImportTrackFile(absl::string_view file_name, + void AddUnusedImportTrackFile(ConstStringParam file_name, bool is_error = false); void ClearUnusedImportTrackFiles(); @@ -2054,14 +2001,14 @@ class PROTOBUF_EXPORT DescriptorPool { // Return true if the given name is a sub-symbol of any non-package // descriptor that already exists in the descriptor pool. (The full // definition of such types is already known.) - bool IsSubSymbolOfBuiltType(absl::string_view name) const; + bool IsSubSymbolOfBuiltType(StringPiece name) const; // Tries to find something in the fallback database and link in the // corresponding proto file. Returns true if successful, in which case // the caller should search for the thing again. These are declared // const because they are called by (semantically) const methods. - bool TryFindFileInFallbackDatabase(absl::string_view name) const; - bool TryFindSymbolInFallbackDatabase(absl::string_view name) const; + bool TryFindFileInFallbackDatabase(StringPiece name) const; + bool TryFindSymbolInFallbackDatabase(StringPiece name) const; bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type, int field_number) const; @@ -2082,13 +2029,13 @@ class PROTOBUF_EXPORT DescriptorPool { // symbol is defined if necessary. Will create a placeholder if the type // doesn't exist in the fallback database, or the file doesn't build // successfully. - Symbol CrossLinkOnDemandHelper(absl::string_view name, + Symbol CrossLinkOnDemandHelper(StringPiece name, bool expecting_enum) const; // Create a placeholder FileDescriptor of the specified name - FileDescriptor* NewPlaceholderFile(absl::string_view name) const; + FileDescriptor* NewPlaceholderFile(StringPiece name) const; FileDescriptor* NewPlaceholderFileWithMutexHeld( - absl::string_view name, internal::FlatAllocator& alloc) const; + StringPiece name, internal::FlatAllocator& alloc) const; enum PlaceholderType { PLACEHOLDER_MESSAGE, @@ -2096,14 +2043,14 @@ class PROTOBUF_EXPORT DescriptorPool { PLACEHOLDER_EXTENDABLE_MESSAGE }; // Create a placeholder Descriptor of the specified name - Symbol NewPlaceholder(absl::string_view name, + Symbol NewPlaceholder(StringPiece name, PlaceholderType placeholder_type) const; - Symbol NewPlaceholderWithMutexHeld(absl::string_view name, + Symbol NewPlaceholderWithMutexHeld(StringPiece name, PlaceholderType placeholder_type) const; // If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a // mutex which must be locked while accessing tables_. - absl::Mutex* mutex_; + internal::WrappedMutex* mutex_; // See constructor. DescriptorDatabase* fallback_database_; @@ -2124,6 +2071,8 @@ class PROTOBUF_EXPORT DescriptorPool { // Set of files to track for unused imports. The bool value when true means // unused imports are treated as errors (and as warnings when false). std::map unused_import_track_files_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); }; @@ -2214,10 +2163,6 @@ PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, reserved_range, const EnumDescriptor::ReservedRange*) PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, reserved_name_count, int) -inline bool EnumDescriptor::is_closed() const { - return file()->syntax() != FileDescriptor::SYNTAX_PROTO3; -} - PROTOBUF_DEFINE_NAME_ACCESSOR(EnumValueDescriptor) PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int) PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*) @@ -2274,9 +2219,9 @@ inline bool Descriptor::IsReservedNumber(int number) const { return FindReservedRangeContainingNumber(number) != nullptr; } -inline bool Descriptor::IsReservedName(absl::string_view name) const { +inline bool Descriptor::IsReservedName(ConstStringParam name) const { for (int i = 0; i < reserved_name_count(); i++) { - if (name == static_cast(reserved_name(i))) { + if (name == static_cast(reserved_name(i))) { return true; } } @@ -2293,9 +2238,9 @@ inline bool EnumDescriptor::IsReservedNumber(int number) const { return FindReservedRangeContainingNumber(number) != nullptr; } -inline bool EnumDescriptor::IsReservedName(absl::string_view name) const { +inline bool EnumDescriptor::IsReservedName(ConstStringParam name) const { for (int i = 0; i < reserved_name_count(); i++) { - if (name == static_cast(reserved_name(i))) { + if (name == static_cast(reserved_name(i))) { return true; } } @@ -2340,7 +2285,7 @@ inline FieldDescriptor::Label FieldDescriptor::label() const { inline FieldDescriptor::Type FieldDescriptor::type() const { if (type_once_) { - absl::call_once(*type_once_, &FieldDescriptor::TypeOnceInit, this); + internal::call_once(*type_once_, &FieldDescriptor::TypeOnceInit, this); } return static_cast(type_); } @@ -2382,11 +2327,6 @@ inline bool FieldDescriptor::has_presence() const { file()->syntax() == FileDescriptor::SYNTAX_PROTO2; } -inline bool FieldDescriptor::requires_utf8_validation() const { - return type() == TYPE_STRING && - file()->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - // To save space, index() is computed by looking at the descriptor's position // in the parent's array of children. inline int FieldDescriptor::index() const { @@ -2491,79 +2431,10 @@ inline FileDescriptor::Syntax FileDescriptor::syntax() const { return static_cast(syntax_); } -namespace internal { - -// FieldRange(desc) provides an iterable range for the fields of a -// descriptor type, appropriate for range-for loops. - -template -struct FieldRangeImpl; - -template -FieldRangeImpl FieldRange(const T* desc) { - return {desc}; -} - -template -struct FieldRangeImpl { - struct Iterator { - using iterator_category = std::forward_iterator_tag; - using value_type = const FieldDescriptor*; - using difference_type = int; - - value_type operator*() { return descriptor->field(idx); } - - friend bool operator==(const Iterator& a, const Iterator& b) { - GOOGLE_DCHECK(a.descriptor == b.descriptor); - return a.idx == b.idx; - } - friend bool operator!=(const Iterator& a, const Iterator& b) { - return !(a == b); - } - - Iterator& operator++() { - idx++; - return *this; - } - - int idx; - const T* descriptor; - }; - - Iterator begin() const { return {0, descriptor}; } - Iterator end() const { return {descriptor->field_count(), descriptor}; } - - const T* descriptor; -}; - -// The context for these functions under `cpp` is "for the C++ implementation". -// In particular, questions like "does this field have a has bit?" have a -// different answer depending on the language. -namespace cpp { -// Returns true if 'enum' semantics are such that unknown values are preserved -// in the enum field itself, rather than going to the UnknownFieldSet. -PROTOBUF_EXPORT bool HasPreservingUnknownEnumSemantics( - const FieldDescriptor* field); - -PROTOBUF_EXPORT bool HasHasbit(const FieldDescriptor* field); - -#ifndef SWIG -enum class Utf8CheckMode { - kStrict = 0, // Parsing will fail if non UTF-8 data is in string fields. - kVerify = 1, // Only log an error but parsing will succeed. - kNone = 2, // No UTF-8 check. -}; -PROTOBUF_EXPORT Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field, - bool is_lite); -#endif // !SWIG - -} // namespace cpp -} // namespace internal - } // namespace protobuf } // namespace google #undef PROTOBUF_INTERNAL_CHECK_CLASS_SIZE -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ diff --git a/libs/protobuf/src/google/protobuf/descriptor.pb.cc b/libs/protobuf/src/google/protobuf/descriptor.pb.cc index 67b315a..d3bfb46 100644 --- a/libs/protobuf/src/google/protobuf/descriptor.pb.cc +++ b/libs/protobuf/src/google/protobuf/descriptor.pb.cc @@ -1,38 +1,39 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -#include "google/protobuf/descriptor.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR FileDescriptorSet::FileDescriptorSet( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.file_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct FileDescriptorSetDefaultTypeInternal { - PROTOBUF_CONSTEXPR FileDescriptorSetDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FileDescriptorSetDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FileDescriptorSetDefaultTypeInternal() {} union { FileDescriptorSet _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; PROTOBUF_CONSTEXPR FileDescriptorProto::FileDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -47,19 +48,17 @@ PROTOBUF_CONSTEXPR FileDescriptorProto::FileDescriptorProto( , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.package_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.syntax_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} - , /*decltype(_impl_.edition_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.options_)*/nullptr , /*decltype(_impl_.source_code_info_)*/nullptr} {} struct FileDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR FileDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FileDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FileDescriptorProtoDefaultTypeInternal() {} union { FileDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -68,15 +67,14 @@ PROTOBUF_CONSTEXPR DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRang , /*decltype(_impl_.start_)*/0 , /*decltype(_impl_.end_)*/0} {} struct DescriptorProto_ExtensionRangeDefaultTypeInternal { - PROTOBUF_CONSTEXPR DescriptorProto_ExtensionRangeDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR DescriptorProto_ExtensionRangeDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~DescriptorProto_ExtensionRangeDefaultTypeInternal() {} union { DescriptorProto_ExtensionRange _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; PROTOBUF_CONSTEXPR DescriptorProto_ReservedRange::DescriptorProto_ReservedRange( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -84,15 +82,14 @@ PROTOBUF_CONSTEXPR DescriptorProto_ReservedRange::DescriptorProto_ReservedRange( , /*decltype(_impl_.start_)*/0 , /*decltype(_impl_.end_)*/0} {} struct DescriptorProto_ReservedRangeDefaultTypeInternal { - PROTOBUF_CONSTEXPR DescriptorProto_ReservedRangeDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR DescriptorProto_ReservedRangeDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~DescriptorProto_ReservedRangeDefaultTypeInternal() {} union { DescriptorProto_ReservedRange _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; PROTOBUF_CONSTEXPR DescriptorProto::DescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -108,30 +105,28 @@ PROTOBUF_CONSTEXPR DescriptorProto::DescriptorProto( , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.options_)*/nullptr} {} struct DescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR DescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR DescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~DescriptorProtoDefaultTypeInternal() {} union { DescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; PROTOBUF_CONSTEXPR ExtensionRangeOptions::ExtensionRangeOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} , /*decltype(_impl_.uninterpreted_option_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct ExtensionRangeOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR ExtensionRangeOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ExtensionRangeOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ExtensionRangeOptionsDefaultTypeInternal() {} union { ExtensionRangeOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ExtensionRangeOptionsDefaultTypeInternal _ExtensionRangeOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ExtensionRangeOptionsDefaultTypeInternal _ExtensionRangeOptions_default_instance_; PROTOBUF_CONSTEXPR FieldDescriptorProto::FieldDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -148,15 +143,14 @@ PROTOBUF_CONSTEXPR FieldDescriptorProto::FieldDescriptorProto( , /*decltype(_impl_.label_)*/1 , /*decltype(_impl_.type_)*/1} {} struct FieldDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR FieldDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FieldDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FieldDescriptorProtoDefaultTypeInternal() {} union { FieldDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR OneofDescriptorProto::OneofDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -164,15 +158,14 @@ PROTOBUF_CONSTEXPR OneofDescriptorProto::OneofDescriptorProto( , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.options_)*/nullptr} {} struct OneofDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR OneofDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR OneofDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~OneofDescriptorProtoDefaultTypeInternal() {} union { OneofDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -180,15 +173,14 @@ PROTOBUF_CONSTEXPR EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_En , /*decltype(_impl_.start_)*/0 , /*decltype(_impl_.end_)*/0} {} struct EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal() {} union { EnumDescriptorProto_EnumReservedRange _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal _EnumDescriptorProto_EnumReservedRange_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDescriptorProto_EnumReservedRangeDefaultTypeInternal _EnumDescriptorProto_EnumReservedRange_default_instance_; PROTOBUF_CONSTEXPR EnumDescriptorProto::EnumDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -199,15 +191,14 @@ PROTOBUF_CONSTEXPR EnumDescriptorProto::EnumDescriptorProto( , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.options_)*/nullptr} {} struct EnumDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumDescriptorProtoDefaultTypeInternal() {} union { EnumDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR EnumValueDescriptorProto::EnumValueDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -216,15 +207,14 @@ PROTOBUF_CONSTEXPR EnumValueDescriptorProto::EnumValueDescriptorProto( , /*decltype(_impl_.options_)*/nullptr , /*decltype(_impl_.number_)*/0} {} struct EnumValueDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumValueDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumValueDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumValueDescriptorProtoDefaultTypeInternal() {} union { EnumValueDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR ServiceDescriptorProto::ServiceDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -233,15 +223,14 @@ PROTOBUF_CONSTEXPR ServiceDescriptorProto::ServiceDescriptorProto( , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.options_)*/nullptr} {} struct ServiceDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR ServiceDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ServiceDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ServiceDescriptorProtoDefaultTypeInternal() {} union { ServiceDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR MethodDescriptorProto::MethodDescriptorProto( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -253,15 +242,14 @@ PROTOBUF_CONSTEXPR MethodDescriptorProto::MethodDescriptorProto( , /*decltype(_impl_.client_streaming_)*/false , /*decltype(_impl_.server_streaming_)*/false} {} struct MethodDescriptorProtoDefaultTypeInternal { - PROTOBUF_CONSTEXPR MethodDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MethodDescriptorProtoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MethodDescriptorProtoDefaultTypeInternal() {} union { MethodDescriptorProto _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; PROTOBUF_CONSTEXPR FileOptions::FileOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -289,15 +277,14 @@ PROTOBUF_CONSTEXPR FileOptions::FileOptions( , /*decltype(_impl_.optimize_for_)*/1 , /*decltype(_impl_.cc_enable_arenas_)*/true} {} struct FileOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR FileOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FileOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FileOptionsDefaultTypeInternal() {} union { FileOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileOptionsDefaultTypeInternal _FileOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FileOptionsDefaultTypeInternal _FileOptions_default_instance_; PROTOBUF_CONSTEXPR MessageOptions::MessageOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -309,15 +296,14 @@ PROTOBUF_CONSTEXPR MessageOptions::MessageOptions( , /*decltype(_impl_.deprecated_)*/false , /*decltype(_impl_.map_entry_)*/false} {} struct MessageOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR MessageOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MessageOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MessageOptionsDefaultTypeInternal() {} union { MessageOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; PROTOBUF_CONSTEXPR FieldOptions::FieldOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -332,30 +318,28 @@ PROTOBUF_CONSTEXPR FieldOptions::FieldOptions( , /*decltype(_impl_.deprecated_)*/false , /*decltype(_impl_.weak_)*/false} {} struct FieldOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR FieldOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FieldOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FieldOptionsDefaultTypeInternal() {} union { FieldOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; PROTOBUF_CONSTEXPR OneofOptions::OneofOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} , /*decltype(_impl_.uninterpreted_option_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct OneofOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR OneofOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR OneofOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~OneofOptionsDefaultTypeInternal() {} union { OneofOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; PROTOBUF_CONSTEXPR EnumOptions::EnumOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -365,15 +349,14 @@ PROTOBUF_CONSTEXPR EnumOptions::EnumOptions( , /*decltype(_impl_.allow_alias_)*/false , /*decltype(_impl_.deprecated_)*/false} {} struct EnumOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumOptionsDefaultTypeInternal() {} union { EnumOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; PROTOBUF_CONSTEXPR EnumValueOptions::EnumValueOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -382,15 +365,14 @@ PROTOBUF_CONSTEXPR EnumValueOptions::EnumValueOptions( , /*decltype(_impl_.uninterpreted_option_)*/{} , /*decltype(_impl_.deprecated_)*/false} {} struct EnumValueOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumValueOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumValueOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumValueOptionsDefaultTypeInternal() {} union { EnumValueOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; PROTOBUF_CONSTEXPR ServiceOptions::ServiceOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -399,15 +381,14 @@ PROTOBUF_CONSTEXPR ServiceOptions::ServiceOptions( , /*decltype(_impl_.uninterpreted_option_)*/{} , /*decltype(_impl_.deprecated_)*/false} {} struct ServiceOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR ServiceOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ServiceOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ServiceOptionsDefaultTypeInternal() {} union { ServiceOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; PROTOBUF_CONSTEXPR MethodOptions::MethodOptions( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._extensions_)*/{} @@ -417,15 +398,14 @@ PROTOBUF_CONSTEXPR MethodOptions::MethodOptions( , /*decltype(_impl_.deprecated_)*/false , /*decltype(_impl_.idempotency_level_)*/0} {} struct MethodOptionsDefaultTypeInternal { - PROTOBUF_CONSTEXPR MethodOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR MethodOptionsDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~MethodOptionsDefaultTypeInternal() {} union { MethodOptions _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; PROTOBUF_CONSTEXPR UninterpretedOption_NamePart::UninterpretedOption_NamePart( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -433,15 +413,14 @@ PROTOBUF_CONSTEXPR UninterpretedOption_NamePart::UninterpretedOption_NamePart( , /*decltype(_impl_.name_part_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.is_extension_)*/false} {} struct UninterpretedOption_NamePartDefaultTypeInternal { - PROTOBUF_CONSTEXPR UninterpretedOption_NamePartDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR UninterpretedOption_NamePartDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~UninterpretedOption_NamePartDefaultTypeInternal() {} union { UninterpretedOption_NamePart _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; PROTOBUF_CONSTEXPR UninterpretedOption::UninterpretedOption( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -454,15 +433,14 @@ PROTOBUF_CONSTEXPR UninterpretedOption::UninterpretedOption( , /*decltype(_impl_.negative_int_value_)*/int64_t{0} , /*decltype(_impl_.double_value_)*/0} {} struct UninterpretedOptionDefaultTypeInternal { - PROTOBUF_CONSTEXPR UninterpretedOptionDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR UninterpretedOptionDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~UninterpretedOptionDefaultTypeInternal() {} union { UninterpretedOption _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; PROTOBUF_CONSTEXPR SourceCodeInfo_Location::SourceCodeInfo_Location( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -475,29 +453,27 @@ PROTOBUF_CONSTEXPR SourceCodeInfo_Location::SourceCodeInfo_Location( , /*decltype(_impl_.leading_comments_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.trailing_comments_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}} {} struct SourceCodeInfo_LocationDefaultTypeInternal { - PROTOBUF_CONSTEXPR SourceCodeInfo_LocationDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR SourceCodeInfo_LocationDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~SourceCodeInfo_LocationDefaultTypeInternal() {} union { SourceCodeInfo_Location _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; PROTOBUF_CONSTEXPR SourceCodeInfo::SourceCodeInfo( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.location_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct SourceCodeInfoDefaultTypeInternal { - PROTOBUF_CONSTEXPR SourceCodeInfoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR SourceCodeInfoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~SourceCodeInfoDefaultTypeInternal() {} union { SourceCodeInfo _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; PROTOBUF_CONSTEXPR GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_._has_bits_)*/{} @@ -506,762 +482,674 @@ PROTOBUF_CONSTEXPR GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation( , /*decltype(_impl_._path_cached_byte_size_)*/{0} , /*decltype(_impl_.source_file_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.begin_)*/0 - , /*decltype(_impl_.end_)*/0 - , /*decltype(_impl_.semantic_)*/0} {} + , /*decltype(_impl_.end_)*/0} {} struct GeneratedCodeInfo_AnnotationDefaultTypeInternal { - PROTOBUF_CONSTEXPR GeneratedCodeInfo_AnnotationDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR GeneratedCodeInfo_AnnotationDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~GeneratedCodeInfo_AnnotationDefaultTypeInternal() {} union { GeneratedCodeInfo_Annotation _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; PROTOBUF_CONSTEXPR GeneratedCodeInfo::GeneratedCodeInfo( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.annotation_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct GeneratedCodeInfoDefaultTypeInternal { - PROTOBUF_CONSTEXPR GeneratedCodeInfoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR GeneratedCodeInfoDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~GeneratedCodeInfoDefaultTypeInternal() {} union { GeneratedCodeInfo _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[27]; -static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[7]; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet, _impl_.file_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.package_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.dependency_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.public_dependency_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.weak_dependency_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.message_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.enum_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.service_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.extension_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.source_code_info_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.syntax_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.edition_), - 0, - 1, - ~0u, - ~0u, - ~0u, - ~0u, - ~0u, - ~0u, - ~0u, - 4, - 5, - 2, - 3, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.start_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.end_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.options_), - 1, - 2, - 0, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_.start_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_.end_), - 0, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.field_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.extension_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.nested_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.enum_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.extension_range_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.oneof_decl_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.reserved_range_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.reserved_name_), - 0, - ~0u, - ~0u, - ~0u, - ~0u, - ~0u, - ~0u, - 1, - ~0u, - ~0u, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _impl_.uninterpreted_option_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.number_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.label_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.type_name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.extendee_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.default_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.oneof_index_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.json_name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.proto3_optional_), - 0, - 6, - 9, - 10, - 2, - 1, - 3, - 7, - 4, - 5, - 8, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_.options_), - 0, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_.start_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_.end_), - 0, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.reserved_range_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.reserved_name_), - 0, - ~0u, - 1, - ~0u, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.number_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.options_), - 0, - 2, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.method_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.options_), - 0, - ~0u, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.input_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.output_type_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.client_streaming_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.server_streaming_), - 0, - 1, - 2, - 3, - 4, - 5, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_package_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_outer_classname_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_multiple_files_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_generate_equals_and_hash_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_string_check_utf8_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.optimize_for_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.go_package_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.cc_generic_services_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_generic_services_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.py_generic_services_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_generic_services_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.cc_enable_arenas_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.objc_class_prefix_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.csharp_namespace_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.swift_prefix_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_class_prefix_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_namespace_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_metadata_namespace_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.ruby_package_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.uninterpreted_option_), - 0, - 1, - 10, - 11, - 12, - 18, - 2, - 13, - 14, - 15, - 16, - 17, - 19, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.message_set_wire_format_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.no_standard_descriptor_accessor_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.map_entry_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.uninterpreted_option_), - 0, - 1, - 2, - 3, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.ctype_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.packed_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.jstype_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.lazy_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.unverified_lazy_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.weak_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.uninterpreted_option_), - 0, - 2, - 1, - 3, - 4, - 5, - 6, - ~0u, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _impl_.uninterpreted_option_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.allow_alias_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.uninterpreted_option_), - 0, - 1, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_.uninterpreted_option_), - 0, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_.uninterpreted_option_), - 0, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _internal_metadata_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_._extensions_), - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.deprecated_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.idempotency_level_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.uninterpreted_option_), - 0, - 1, - ~0u, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_.name_part_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_.is_extension_), - 0, - 1, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.identifier_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.positive_int_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.negative_int_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.double_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.string_value_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.aggregate_value_), - ~0u, - 0, - 3, - 4, - 5, - 1, - 2, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.path_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.span_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.leading_comments_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.trailing_comments_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.leading_detached_comments_), - ~0u, - ~0u, - 0, - 1, - ~0u, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo, _impl_.location_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_._has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.path_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.source_file_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.begin_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.end_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.semantic_), - ~0u, - 0, - 1, - 2, - 3, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo, _impl_.annotation_), -}; +static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[6]; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet)}, - { 9, 30, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto)}, - { 43, 54, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange)}, - { 57, 67, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange)}, - { 69, 87, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto)}, - { 97, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions)}, - { 106, 125, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto)}, - { 136, 146, -1, sizeof(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto)}, - { 148, 158, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange)}, - { 160, 173, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto)}, - { 178, 189, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto)}, - { 192, 203, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto)}, - { 206, 220, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto)}, - { 226, 255, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileOptions)}, - { 276, 289, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MessageOptions)}, - { 294, 310, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldOptions)}, - { 318, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::OneofOptions)}, - { 327, 338, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumOptions)}, - { 341, 351, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValueOptions)}, - { 353, 363, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ServiceOptions)}, - { 365, 376, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MethodOptions)}, - { 379, 389, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart)}, - { 391, 406, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UninterpretedOption)}, - { 413, 426, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location)}, - { 431, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo)}, - { 440, 453, -1, sizeof(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation)}, - { 458, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo)}, +const uint32_t TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet, _impl_.file_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.package_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.dependency_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.public_dependency_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.weak_dependency_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.message_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.enum_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.service_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.extension_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.source_code_info_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto, _impl_.syntax_), + 0, + 1, + ~0u, + ~0u, + ~0u, + ~0u, + ~0u, + ~0u, + ~0u, + 3, + 4, + 2, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.start_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.end_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange, _impl_.options_), + 1, + 2, + 0, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_.start_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange, _impl_.end_), + 0, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.field_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.extension_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.nested_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.enum_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.extension_range_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.oneof_decl_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.reserved_range_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DescriptorProto, _impl_.reserved_name_), + 0, + ~0u, + ~0u, + ~0u, + ~0u, + ~0u, + ~0u, + 1, + ~0u, + ~0u, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions, _impl_.uninterpreted_option_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.number_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.label_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.type_name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.extendee_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.default_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.oneof_index_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.json_name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto, _impl_.proto3_optional_), + 0, + 6, + 9, + 10, + 2, + 1, + 3, + 7, + 4, + 5, + 8, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto, _impl_.options_), + 0, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_.start_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange, _impl_.end_), + 0, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.reserved_range_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto, _impl_.reserved_name_), + 0, + ~0u, + 1, + ~0u, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.number_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto, _impl_.options_), + 0, + 2, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.method_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto, _impl_.options_), + 0, + ~0u, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.input_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.output_type_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.client_streaming_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto, _impl_.server_streaming_), + 0, + 1, + 2, + 3, + 4, + 5, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_package_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_outer_classname_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_multiple_files_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_generate_equals_and_hash_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_string_check_utf8_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.optimize_for_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.go_package_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.cc_generic_services_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.java_generic_services_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.py_generic_services_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_generic_services_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.cc_enable_arenas_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.objc_class_prefix_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.csharp_namespace_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.swift_prefix_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_class_prefix_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_namespace_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.php_metadata_namespace_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.ruby_package_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FileOptions, _impl_.uninterpreted_option_), + 0, + 1, + 10, + 11, + 12, + 18, + 2, + 13, + 14, + 15, + 16, + 17, + 19, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.message_set_wire_format_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.no_standard_descriptor_accessor_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.map_entry_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MessageOptions, _impl_.uninterpreted_option_), + 0, + 1, + 2, + 3, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.ctype_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.packed_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.jstype_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.lazy_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.unverified_lazy_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.weak_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldOptions, _impl_.uninterpreted_option_), + 0, + 2, + 1, + 3, + 4, + 5, + 6, + ~0u, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::OneofOptions, _impl_.uninterpreted_option_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.allow_alias_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumOptions, _impl_.uninterpreted_option_), + 0, + 1, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValueOptions, _impl_.uninterpreted_option_), + 0, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ServiceOptions, _impl_.uninterpreted_option_), + 0, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _internal_metadata_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_._extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.deprecated_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.idempotency_level_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::MethodOptions, _impl_.uninterpreted_option_), + 0, + 1, + ~0u, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_.name_part_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart, _impl_.is_extension_), + 0, + 1, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.identifier_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.positive_int_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.negative_int_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.double_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.string_value_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UninterpretedOption, _impl_.aggregate_value_), + ~0u, + 0, + 3, + 4, + 5, + 1, + 2, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.path_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.span_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.leading_comments_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.trailing_comments_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location, _impl_.leading_detached_comments_), + ~0u, + ~0u, + 0, + 1, + ~0u, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo, _impl_.location_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.path_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.source_file_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.begin_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation, _impl_.end_), + ~0u, + 0, + 1, + 2, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo, _impl_.annotation_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileDescriptorSet)}, + { 7, 25, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileDescriptorProto)}, + { 37, 46, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange)}, + { 49, 57, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange)}, + { 59, 75, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DescriptorProto)}, + { 85, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions)}, + { 92, 109, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto)}, + { 120, 128, -1, sizeof(::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto)}, + { 130, 138, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange)}, + { 140, 151, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto)}, + { 156, 165, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto)}, + { 168, 177, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto)}, + { 180, 192, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto)}, + { 198, 225, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FileOptions)}, + { 246, 257, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MessageOptions)}, + { 262, 276, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldOptions)}, + { 284, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::OneofOptions)}, + { 291, 300, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumOptions)}, + { 303, 311, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValueOptions)}, + { 313, 321, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ServiceOptions)}, + { 323, 332, -1, sizeof(::PROTOBUF_NAMESPACE_ID::MethodOptions)}, + { 335, 343, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart)}, + { 345, 358, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UninterpretedOption)}, + { 365, 376, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location)}, + { 381, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceCodeInfo)}, + { 388, 398, -1, sizeof(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation)}, + { 402, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_FileDescriptorSet_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_FileDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_ExtensionRange_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_ReservedRange_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_ExtensionRangeOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_FieldDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_OneofDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumDescriptorProto_EnumReservedRange_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumValueDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_ServiceDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_MethodDescriptorProto_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_FileOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_MessageOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_FieldOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_OneofOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumValueOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_ServiceOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_MethodOptions_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_UninterpretedOption_NamePart_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_UninterpretedOption_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_SourceCodeInfo_Location_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_SourceCodeInfo_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_GeneratedCodeInfo_Annotation_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_GeneratedCodeInfo_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] PROTOBUF_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" - "roto\"\354\003\n\023FileDescriptorProto\022\014\n\004name\030\001 \001" - "(\t\022\017\n\007package\030\002 \001(\t\022\022\n\ndependency\030\003 \003(\t\022" - "\031\n\021public_dependency\030\n \003(\005\022\027\n\017weak_depen" - "dency\030\013 \003(\005\0226\n\014message_type\030\004 \003(\0132 .goog" - "le.protobuf.DescriptorProto\0227\n\tenum_type" - "\030\005 \003(\0132$.google.protobuf.EnumDescriptorP" - "roto\0228\n\007service\030\006 \003(\0132\'.google.protobuf." - "ServiceDescriptorProto\0228\n\textension\030\007 \003(" - "\0132%.google.protobuf.FieldDescriptorProto" - "\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\022\017\n\007edition\030\r \001(\t\"\251\005\n\017DescriptorProto\022" - "\014\n\004name\030\001 \001(\t\0224\n\005field\030\002 \003(\0132%.google.pr" - "otobuf.FieldDescriptorProto\0228\n\textension" - "\030\006 \003(\0132%.google.protobuf.FieldDescriptor" - "Proto\0225\n\013nested_type\030\003 \003(\0132 .google.prot" - "obuf.DescriptorProto\0227\n\tenum_type\030\004 \003(\0132" - "$.google.protobuf.EnumDescriptorProto\022H\n" - "\017extension_range\030\005 \003(\0132/.google.protobuf" - ".DescriptorProto.ExtensionRange\0229\n\noneof" - "_decl\030\010 \003(\0132%.google.protobuf.OneofDescr" - "iptorProto\0220\n\007options\030\007 \001(\0132\037.google.pro" - "tobuf.MessageOptions\022F\n\016reserved_range\030\t" - " \003(\0132..google.protobuf.DescriptorProto.R" - "eservedRange\022\025\n\rreserved_name\030\n \003(\t\032e\n\016E" - "xtensionRange\022\r\n\005start\030\001 \001(\005\022\013\n\003end\030\002 \001(" - "\005\0227\n\007options\030\003 \001(\0132&.google.protobuf.Ext" - "ensionRangeOptions\032+\n\rReservedRange\022\r\n\005s" - "tart\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"g\n\025ExtensionRang" - "eOptions\022C\n\024uninterpreted_option\030\347\007 \003(\0132" - "$.google.protobuf.UninterpretedOption*\t\010" - "\350\007\020\200\200\200\200\002\"\325\005\n\024FieldDescriptorProto\022\014\n\004nam" - "e\030\001 \001(\t\022\016\n\006number\030\003 \001(\005\022:\n\005label\030\004 \001(\0162+" - ".google.protobuf.FieldDescriptorProto.La" - "bel\0228\n\004type\030\005 \001(\0162*.google.protobuf.Fiel" - "dDescriptorProto.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.Fie" - "ldOptions\022\027\n\017proto3_optional\030\021 \001(\010\"\266\002\n\004T" - "ype\022\017\n\013TYPE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\n" - "TYPE_INT64\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_IN" - "T32\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\nTYP" - "E_GROUP\020\n\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTE" - "S\020\014\022\017\n\013TYPE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rT" - "YPE_SFIXED32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYP" - "E_SINT32\020\021\022\017\n\013TYPE_SINT64\020\022\"C\n\005Label\022\022\n\016" - "LABEL_OPTIONAL\020\001\022\022\n\016LABEL_REQUIRED\020\002\022\022\n\016" - "LABEL_REPEATED\020\003\"T\n\024OneofDescriptorProto" - "\022\014\n\004name\030\001 \001(\t\022.\n\007options\030\002 \001(\0132\035.google" - ".protobuf.OneofOptions\"\244\002\n\023EnumDescripto" - "rProto\022\014\n\004name\030\001 \001(\t\0228\n\005value\030\002 \003(\0132).go" - "ogle.protobuf.EnumValueDescriptorProto\022-" - "\n\007options\030\003 \001(\0132\034.google.protobuf.EnumOp" - "tions\022N\n\016reserved_range\030\004 \003(\01326.google.p" - "rotobuf.EnumDescriptorProto.EnumReserved" - "Range\022\025\n\rreserved_name\030\005 \003(\t\032/\n\021EnumRese" - "rvedRange\022\r\n\005start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"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!.googl" - "e.protobuf.EnumValueOptions\"\220\001\n\026ServiceD" - "escriptorProto\022\014\n\004name\030\001 \001(\t\0226\n\006method\030\002" - " \003(\0132&.google.protobuf.MethodDescriptorP" - "roto\0220\n\007options\030\003 \001(\0132\037.google.protobuf." - "ServiceOptions\"\301\001\n\025MethodDescriptorProto" - "\022\014\n\004name\030\001 \001(\t\022\022\n\ninput_type\030\002 \001(\t\022\023\n\013ou" - "tput_type\030\003 \001(\t\022/\n\007options\030\004 \001(\0132\036.googl" - "e.protobuf.MethodOptions\022\037\n\020client_strea" - "ming\030\005 \001(\010:\005false\022\037\n\020server_streaming\030\006 " - "\001(\010:\005false\"\245\006\n\013FileOptions\022\024\n\014java_packa" - "ge\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\035ja" - "va_generate_equals_and_hash\030\024 \001(\010B\002\030\001\022%\n" - "\026java_string_check_utf8\030\033 \001(\010:\005false\022F\n\014" - "optimize_for\030\t \001(\0162).google.protobuf.Fil" - "eOptions.OptimizeMode:\005SPEED\022\022\n\ngo_packa" - "ge\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 \001(\010:\005f" - "alse\022$\n\025java_generic_services\030\021 \001(\010:\005fal" - "se\022\"\n\023py_generic_services\030\022 \001(\010:\005false\022#" - "\n\024php_generic_services\030* \001(\010:\005false\022\031\n\nd" - "eprecated\030\027 \001(\010:\005false\022\036\n\020cc_enable_aren" - "as\030\037 \001(\010:\004true\022\031\n\021objc_class_prefix\030$ \001(" - "\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014swift_pre" - "fix\030\' \001(\t\022\030\n\020php_class_prefix\030( \001(\t\022\025\n\rp" - "hp_namespace\030) \001(\t\022\036\n\026php_metadata_names" - "pace\030, \001(\t\022\024\n\014ruby_package\030- \001(\t\022C\n\024unin" - "terpreted_option\030\347\007 \003(\0132$.google.protobu" - "f.UninterpretedOption\":\n\014OptimizeMode\022\t\n" - "\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LITE_RUNTIME\020" - "\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\204\002\n\016MessageOptions\022&\n" - "\027message_set_wire_format\030\001 \001(\010:\005false\022.\n" - "\037no_standard_descriptor_accessor\030\002 \001(\010:\005" - "false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\021\n\tmap_" - "entry\030\007 \001(\010\022C\n\024uninterpreted_option\030\347\007 \003" - "(\0132$.google.protobuf.UninterpretedOption" - "*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ\004\010\t\020" - "\n\"\276\003\n\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#.goog" - "le.protobuf.FieldOptions.CType:\006STRING\022\016" - "\n\006packed\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.google." - "protobuf.FieldOptions.JSType:\tJS_NORMAL\022" - "\023\n\004lazy\030\005 \001(\010:\005false\022\036\n\017unverified_lazy\030" - "\017 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022" - "\023\n\004weak\030\n \001(\010:\005false\022C\n\024uninterpreted_op" - "tion\030\347\007 \003(\0132$.google.protobuf.Uninterpre" - "tedOption\"/\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_NORMA" - "L\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\024uninterpre" - "ted_option\030\347\007 \003(\0132$.google.protobuf.Unin" - "terpretedOption*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOptio" - "ns\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\n" - "deprecated\030\001 \001(\010:\005false\022C\n\024uninterpreted" - "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" - "pretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOption" - "s\022\031\n\ndeprecated\030! \001(\010:\005false\022C\n\024uninterp" - "reted_option\030\347\007 \003(\0132$.google.protobuf.Un" - "interpretedOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodO" - "ptions\022\031\n\ndeprecated\030! \001(\010:\005false\022_\n\021ide" - "mpotency_level\030\" \001(\0162/.google.protobuf.M" - "ethodOptions.IdempotencyLevel:\023IDEMPOTEN" - "CY_UNKNOWN\022C\n\024uninterpreted_option\030\347\007 \003(" - "\0132$.google.protobuf.UninterpretedOption\"" - "P\n\020IdempotencyLevel\022\027\n\023IDEMPOTENCY_UNKNO" - "WN\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\004" - "name\030\002 \003(\0132-.google.protobuf.Uninterpret" - "edOption.NamePart\022\030\n\020identifier_value\030\003 " - "\001(\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022negat" - "ive_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_val" - "ue\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\016SourceCodeInfo" - "\022:\n\010location\030\001 \003(\0132(.google.protobuf.Sou" - "rceCodeInfo.Location\032\206\001\n\010Location\022\020\n\004pat" - "h\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading" - "_comments\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001" - "(\t\022!\n\031leading_detached_comments\030\006 \003(\t\"\234\002" - "\n\021GeneratedCodeInfo\022A\n\nannotation\030\001 \003(\0132" - "-.google.protobuf.GeneratedCodeInfo.Anno" - "tation\032\303\001\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(\005\022H\n\010semantic\030\005 \001(\01626.google.prot" - "obuf.GeneratedCodeInfo.Annotation.Semant" - "ic\"(\n\010Semantic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALI" - "AS\020\002B~\n\023com.google.protobufB\020DescriptorP" - "rotosH\001Z-google.golang.org/protobuf/type" - "s/descriptorpb\370\001\001\242\002\003GPB\252\002\032Google.Protobu" - "f.Reflection" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { - false, - false, - 6212, - descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, - "google/protobuf/descriptor.proto", - &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, - nullptr, - 0, - 27, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto, + &::PROTOBUF_NAMESPACE_ID::_FileDescriptorSet_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_FileDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_ExtensionRange_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_ReservedRange_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_DescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_ExtensionRangeOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_FieldDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_OneofDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumDescriptorProto_EnumReservedRange_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumValueDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_ServiceDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_MethodDescriptorProto_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_FileOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_MessageOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_FieldOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_OneofOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumValueOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_ServiceOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_MethodOptions_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_UninterpretedOption_NamePart_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_UninterpretedOption_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_SourceCodeInfo_Location_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_SourceCodeInfo_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_GeneratedCodeInfo_Annotation_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_GeneratedCodeInfo_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] PROTOBUF_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" + "roto\"\333\003\n\023FileDescriptorProto\022\014\n\004name\030\001 \001" + "(\t\022\017\n\007package\030\002 \001(\t\022\022\n\ndependency\030\003 \003(\t\022" + "\031\n\021public_dependency\030\n \003(\005\022\027\n\017weak_depen" + "dency\030\013 \003(\005\0226\n\014message_type\030\004 \003(\0132 .goog" + "le.protobuf.DescriptorProto\0227\n\tenum_type" + "\030\005 \003(\0132$.google.protobuf.EnumDescriptorP" + "roto\0228\n\007service\030\006 \003(\0132\'.google.protobuf." + "ServiceDescriptorProto\0228\n\textension\030\007 \003(" + "\0132%.google.protobuf.FieldDescriptorProto" + "\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\"\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" + "ype\030\003 \003(\0132 .google.protobuf.DescriptorPr" + "oto\0227\n\tenum_type\030\004 \003(\0132$.google.protobuf" + ".EnumDescriptorProto\022H\n\017extension_range\030" + "\005 \003(\0132/.google.protobuf.DescriptorProto." + "ExtensionRange\0229\n\noneof_decl\030\010 \003(\0132%.goo" + "gle.protobuf.OneofDescriptorProto\0220\n\007opt" + "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\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\"\325\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\022\027\n\017prot" + "o3_optional\030\021 \001(\010\"\266\002\n\004Type\022\017\n\013TYPE_DOUBL" + "E\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE_INT64\020\003\022\017\n\013T" + "YPE_UINT64\020\004\022\016\n\nTYPE_INT32\020\005\022\020\n\014TYPE_FIX" + "ED64\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_UINT3" + "2\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_SINT32\020\021\022\017\n\013TYP" + "E_SINT64\020\022\"C\n\005Label\022\022\n\016LABEL_OPTIONAL\020\001\022" + "\022\n\016LABEL_REQUIRED\020\002\022\022\n\016LABEL_REPEATED\020\003\"" + "T\n\024OneofDescriptorProto\022\014\n\004name\030\001 \001(\t\022.\n" + "\007options\030\002 \001(\0132\035.google.protobuf.OneofOp" + "tions\"\244\002\n\023EnumDescriptorProto\022\014\n\004name\030\001 " + "\001(\t\0228\n\005value\030\002 \003(\0132).google.protobuf.Enu" + "mValueDescriptorProto\022-\n\007options\030\003 \001(\0132\034" + ".google.protobuf.EnumOptions\022N\n\016reserved" + "_range\030\004 \003(\01326.google.protobuf.EnumDescr" + "iptorProto.EnumReservedRange\022\025\n\rreserved" + "_name\030\005 \003(\t\032/\n\021EnumReservedRange\022\r\n\005star" + "t\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"l\n\030EnumValueDescrip" + "torProto\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.EnumVa" + "lueOptions\"\220\001\n\026ServiceDescriptorProto\022\014\n" + "\004name\030\001 \001(\t\0226\n\006method\030\002 \003(\0132&.google.pro" + "tobuf.MethodDescriptorProto\0220\n\007options\030\003" + " \001(\0132\037.google.protobuf.ServiceOptions\"\301\001" + "\n\025MethodDescriptorProto\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.Method" + "Options\022\037\n\020client_streaming\030\005 \001(\010:\005false" + "\022\037\n\020server_streaming\030\006 \001(\010:\005false\"\245\006\n\013Fi" + "leOptions\022\024\n\014java_package\030\001 \001(\t\022\034\n\024java_" + "outer_classname\030\010 \001(\t\022\"\n\023java_multiple_f" + "iles\030\n \001(\010:\005false\022)\n\035java_generate_equal" + "s_and_hash\030\024 \001(\010B\002\030\001\022%\n\026java_string_chec" + "k_utf8\030\033 \001(\010:\005false\022F\n\014optimize_for\030\t \001(" + "\0162).google.protobuf.FileOptions.Optimize" + "Mode:\005SPEED\022\022\n\ngo_package\030\013 \001(\t\022\"\n\023cc_ge" + "neric_services\030\020 \001(\010:\005false\022$\n\025java_gene" + "ric_services\030\021 \001(\010:\005false\022\"\n\023py_generic_" + "services\030\022 \001(\010:\005false\022#\n\024php_generic_ser" + "vices\030* \001(\010:\005false\022\031\n\ndeprecated\030\027 \001(\010:\005" + "false\022\036\n\020cc_enable_arenas\030\037 \001(\010:\004true\022\031\n" + "\021objc_class_prefix\030$ \001(\t\022\030\n\020csharp_names" + "pace\030% \001(\t\022\024\n\014swift_prefix\030\' \001(\t\022\030\n\020php_" + "class_prefix\030( \001(\t\022\025\n\rphp_namespace\030) \001(" + "\t\022\036\n\026php_metadata_namespace\030, \001(\t\022\024\n\014rub" + "y_package\030- \001(\t\022C\n\024uninterpreted_option\030" + "\347\007 \003(\0132$.google.protobuf.UninterpretedOp" + "tion\":\n\014OptimizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_" + "SIZE\020\002\022\020\n\014LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020" + "\'\"\204\002\n\016MessageOptions\022&\n\027message_set_wire" + "_format\030\001 \001(\010:\005false\022.\n\037no_standard_desc" + "riptor_accessor\030\002 \001(\010:\005false\022\031\n\ndeprecat" + "ed\030\003 \001(\010:\005false\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024un" + "interpreted_option\030\347\007 \003(\0132$.google.proto" + "buf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005" + "J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ\004\010\t\020\n\"\276\003\n\014FieldOption" + "s\022:\n\005ctype\030\001 \001(\0162#.google.protobuf.Field" + "Options.CType:\006STRING\022\016\n\006packed\030\002 \001(\010\022\?\n" + "\006jstype\030\006 \001(\0162$.google.protobuf.FieldOpt" + "ions.JSType:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005fa" + "lse\022\036\n\017unverified_lazy\030\017 \001(\010:\005false\022\031\n\nd" + "eprecated\030\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005fa" + "lse\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goo" + "gle.protobuf.UninterpretedOption\"/\n\005CTyp" + "e\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_NORMAL\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\014One" + "ofOptions\022C\n\024uninterpreted_option\030\347\007 \003(\013" + "2$.google.protobuf.UninterpretedOption*\t" + "\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOptions\022\023\n\013allow_alias" + "\030\002 \001(\010\022\031\n\ndeprecated\030\003 \001(\010:\005false\022C\n\024uni" + "nterpreted_option\030\347\007 \003(\0132$.google.protob" + "uf.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\024uninterpreted_option\030\347\007 \003(\0132$." + "google.protobuf.UninterpretedOption*\t\010\350\007" + "\020\200\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndeprecated\030!" + " \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n\ndepreca" + "ted\030! \001(\010:\005false\022_\n\021idempotency_level\030\" " + "\001(\0162/.google.protobuf.MethodOptions.Idem" + "potencyLevel:\023IDEMPOTENCY_UNKNOWN\022C\n\024uni" + "nterpreted_option\030\347\007 \003(\0132$.google.protob" + "uf.UninterpretedOption\"P\n\020IdempotencyLev" + "el\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n\017NO_SIDE_E" + "FFECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023" + "UninterpretedOption\022;\n\004name\030\002 \003(\0132-.goog" + "le.protobuf.UninterpretedOption.NamePart" + "\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022positive_i" + "nt_value\030\004 \001(\004\022\032\n\022negative_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\010NameP" + "art\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_extension\030\002" + " \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010location\030\001 \003(" + "\0132(.google.protobuf.SourceCodeInfo.Locat" + "ion\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004sp" + "an\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003 \001(\t\022\031" + "\n\021trailing_comments\030\004 \001(\t\022!\n\031leading_det" + "ached_comments\030\006 \003(\t\"\247\001\n\021GeneratedCodeIn" + "fo\022A\n\nannotation\030\001 \003(\0132-.google.protobuf" + ".GeneratedCodeInfo.Annotation\032O\n\nAnnotat" + "ion\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~\n\023com.go" + "ogle.protobufB\020DescriptorProtosH\001Z-googl" + "e.golang.org/protobuf/types/descriptorpb" + "\370\001\001\242\002\003GPB\252\002\032Google.Protobuf.Reflection" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { + false, false, 6078, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, + "google/protobuf/descriptor.proto", + &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, nullptr, 0, 27, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fdescriptor_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fdescriptor_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fdescriptor_2eproto(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fdescriptor_2eproto(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); PROTOBUF_NAMESPACE_OPEN const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldDescriptorProto_Type_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); @@ -1292,9 +1180,8 @@ bool FieldDescriptorProto_Type_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FieldDescriptorProto_Type FieldDescriptorProto::TYPE_DOUBLE; constexpr FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FLOAT; constexpr FieldDescriptorProto_Type FieldDescriptorProto::TYPE_INT64; @@ -1316,9 +1203,7 @@ constexpr FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SINT64; constexpr FieldDescriptorProto_Type FieldDescriptorProto::Type_MIN; constexpr FieldDescriptorProto_Type FieldDescriptorProto::Type_MAX; constexpr int FieldDescriptorProto::Type_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldDescriptorProto_Label_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[1]; @@ -1333,18 +1218,15 @@ bool FieldDescriptorProto_Label_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FieldDescriptorProto_Label FieldDescriptorProto::LABEL_OPTIONAL; constexpr FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REQUIRED; constexpr FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REPEATED; constexpr FieldDescriptorProto_Label FieldDescriptorProto::Label_MIN; constexpr FieldDescriptorProto_Label FieldDescriptorProto::Label_MAX; constexpr int FieldDescriptorProto::Label_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FileOptions_OptimizeMode_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[2]; @@ -1359,18 +1241,15 @@ bool FileOptions_OptimizeMode_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FileOptions_OptimizeMode FileOptions::SPEED; constexpr FileOptions_OptimizeMode FileOptions::CODE_SIZE; constexpr FileOptions_OptimizeMode FileOptions::LITE_RUNTIME; constexpr FileOptions_OptimizeMode FileOptions::OptimizeMode_MIN; constexpr FileOptions_OptimizeMode FileOptions::OptimizeMode_MAX; constexpr int FileOptions::OptimizeMode_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldOptions_CType_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[3]; @@ -1385,18 +1264,15 @@ bool FieldOptions_CType_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FieldOptions_CType FieldOptions::STRING; constexpr FieldOptions_CType FieldOptions::CORD; constexpr FieldOptions_CType FieldOptions::STRING_PIECE; constexpr FieldOptions_CType FieldOptions::CType_MIN; constexpr FieldOptions_CType FieldOptions::CType_MAX; constexpr int FieldOptions::CType_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldOptions_JSType_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[4]; @@ -1411,18 +1287,15 @@ bool FieldOptions_JSType_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr FieldOptions_JSType FieldOptions::JS_NORMAL; constexpr FieldOptions_JSType FieldOptions::JS_STRING; constexpr FieldOptions_JSType FieldOptions::JS_NUMBER; constexpr FieldOptions_JSType FieldOptions::JSType_MIN; constexpr FieldOptions_JSType FieldOptions::JSType_MAX; constexpr int FieldOptions::JSType_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* MethodOptions_IdempotencyLevel_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[5]; @@ -1437,44 +1310,16 @@ bool MethodOptions_IdempotencyLevel_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr MethodOptions_IdempotencyLevel MethodOptions::IDEMPOTENCY_UNKNOWN; constexpr MethodOptions_IdempotencyLevel MethodOptions::NO_SIDE_EFFECTS; constexpr MethodOptions_IdempotencyLevel MethodOptions::IDEMPOTENT; constexpr MethodOptions_IdempotencyLevel MethodOptions::IdempotencyLevel_MIN; constexpr MethodOptions_IdempotencyLevel MethodOptions::IdempotencyLevel_MAX; constexpr int MethodOptions::IdempotencyLevel_ARRAYSIZE; +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) -const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* GeneratedCodeInfo_Annotation_Semantic_descriptor() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto); - return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[6]; -} -bool GeneratedCodeInfo_Annotation_Semantic_IsValid(int value) { - switch (value) { - case 0: - case 1: - case 2: - return true; - default: - return false; - } -} -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) - -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::NONE; -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::SET; -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::ALIAS; -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::Semantic_MIN; -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::Semantic_MAX; -constexpr int GeneratedCodeInfo_Annotation::Semantic_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) // =================================================================== class FileDescriptorSet::_Internal { @@ -1537,7 +1382,6 @@ void FileDescriptorSet::Clear() { } const char* FileDescriptorSet::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1581,7 +1425,6 @@ failure: uint8_t* FileDescriptorSet::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorSet) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1603,7 +1446,6 @@ uint8_t* FileDescriptorSet::_InternalSerialize( } size_t FileDescriptorSet::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileDescriptorSet) size_t total_size = 0; @@ -1631,7 +1473,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorSet::GetClassDat void FileDescriptorSet::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorSet) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1661,18 +1502,16 @@ void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FileDescriptorSet::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[0]); } + // =================================================================== class FileDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(FileDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -1681,18 +1520,15 @@ class FileDescriptorProto::_Internal { } static const ::PROTOBUF_NAMESPACE_ID::FileOptions& options(const FileDescriptorProto* msg); static void set_has_options(HasBits* has_bits) { - (*has_bits)[0] |= 16u; + (*has_bits)[0] |= 8u; } static const ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo& source_code_info(const FileDescriptorProto* msg); static void set_has_source_code_info(HasBits* has_bits) { - (*has_bits)[0] |= 32u; + (*has_bits)[0] |= 16u; } static void set_has_syntax(HasBits* has_bits) { (*has_bits)[0] |= 4u; } - static void set_has_edition(HasBits* has_bits) { - (*has_bits)[0] |= 8u; - } }; const ::PROTOBUF_NAMESPACE_ID::FileOptions& @@ -1725,7 +1561,6 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) , decltype(_impl_.name_){} , decltype(_impl_.package_){} , decltype(_impl_.syntax_){} - , decltype(_impl_.edition_){} , decltype(_impl_.options_){nullptr} , decltype(_impl_.source_code_info_){nullptr}}; @@ -1754,14 +1589,6 @@ FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from) _this->_impl_.syntax_.Set(from._internal_syntax(), _this->GetArenaForAllocation()); } - _impl_.edition_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.edition_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (from._internal_has_edition()) { - _this->_impl_.edition_.Set(from._internal_edition(), - _this->GetArenaForAllocation()); - } if (from._internal_has_options()) { _this->_impl_.options_ = new ::PROTOBUF_NAMESPACE_ID::FileOptions(*from._impl_.options_); } @@ -1788,7 +1615,6 @@ inline void FileDescriptorProto::SharedCtor( , decltype(_impl_.name_){} , decltype(_impl_.package_){} , decltype(_impl_.syntax_){} - , decltype(_impl_.edition_){} , decltype(_impl_.options_){nullptr} , decltype(_impl_.source_code_info_){nullptr} }; @@ -1804,10 +1630,6 @@ inline void FileDescriptorProto::SharedCtor( #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING _impl_.syntax_.Set("", GetArenaForAllocation()); #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.edition_.InitDefault(); - #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.edition_.Set("", GetArenaForAllocation()); - #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING } FileDescriptorProto::~FileDescriptorProto() { @@ -1831,7 +1653,6 @@ inline void FileDescriptorProto::SharedDtor() { _impl_.name_.Destroy(); _impl_.package_.Destroy(); _impl_.syntax_.Destroy(); - _impl_.edition_.Destroy(); if (this != internal_default_instance()) delete _impl_.options_; if (this != internal_default_instance()) delete _impl_.source_code_info_; } @@ -1854,7 +1675,7 @@ void FileDescriptorProto::Clear() { _impl_.public_dependency_.Clear(); _impl_.weak_dependency_.Clear(); cached_has_bits = _impl_._has_bits_[0]; - if (cached_has_bits & 0x0000003fu) { + if (cached_has_bits & 0x0000001fu) { if (cached_has_bits & 0x00000001u) { _impl_.name_.ClearNonDefaultToEmpty(); } @@ -1865,13 +1686,10 @@ void FileDescriptorProto::Clear() { _impl_.syntax_.ClearNonDefaultToEmpty(); } if (cached_has_bits & 0x00000008u) { - _impl_.edition_.ClearNonDefaultToEmpty(); - } - if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(_impl_.options_ != nullptr); _impl_.options_->Clear(); } - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(_impl_.source_code_info_ != nullptr); _impl_.source_code_info_->Clear(); } @@ -1881,7 +1699,6 @@ void FileDescriptorProto::Clear() { } const char* FileDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -2041,18 +1858,6 @@ const char* FileDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseCo } else goto handle_unusual; continue; - // optional string edition = 13; - case 13: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 106)) { - auto str = _internal_mutable_edition(); - ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); - CHK_(ptr); - #ifndef NDEBUG - ::_pbi::VerifyUTF8(str, "google.protobuf.FileDescriptorProto.edition"); - #endif // !NDEBUG - } else - goto handle_unusual; - continue; default: goto handle_unusual; } // switch @@ -2079,7 +1884,6 @@ failure: uint8_t* FileDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -2148,14 +1952,14 @@ uint8_t* FileDescriptorProto::_InternalSerialize( } // optional .google.protobuf.FileOptions options = 8; - if (cached_has_bits & 0x00000010u) { + if (cached_has_bits & 0x00000008u) { target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessage(8, _Internal::options(this), _Internal::options(this).GetCachedSize(), target, stream); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000010u) { target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessage(9, _Internal::source_code_info(this), _Internal::source_code_info(this).GetCachedSize(), target, stream); @@ -2183,16 +1987,6 @@ uint8_t* FileDescriptorProto::_InternalSerialize( 12, this->_internal_syntax(), target); } - // optional string edition = 13; - if (cached_has_bits & 0x00000008u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->_internal_edition().data(), static_cast(this->_internal_edition().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "google.protobuf.FileDescriptorProto.edition"); - target = stream->WriteStringMaybeAliased( - 13, this->_internal_edition(), target); - } - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); @@ -2202,7 +1996,6 @@ uint8_t* FileDescriptorProto::_InternalSerialize( } size_t FileDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileDescriptorProto) size_t total_size = 0; @@ -2265,7 +2058,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { } cached_has_bits = _impl_._has_bits_[0]; - if (cached_has_bits & 0x0000003fu) { + if (cached_has_bits & 0x0000001fu) { // optional string name = 1; if (cached_has_bits & 0x00000001u) { total_size += 1 + @@ -2287,22 +2080,15 @@ size_t FileDescriptorProto::ByteSizeLong() const { this->_internal_syntax()); } - // optional string edition = 13; - if (cached_has_bits & 0x00000008u) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_edition()); - } - // optional .google.protobuf.FileOptions options = 8; - if (cached_has_bits & 0x00000010u) { + if (cached_has_bits & 0x00000008u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( *_impl_.options_); } // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000010u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( *_impl_.source_code_info_); @@ -2322,7 +2108,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileDescriptorProto::GetClassD void FileDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -2336,7 +2121,7 @@ void FileDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, co _this->_impl_.public_dependency_.MergeFrom(from._impl_.public_dependency_); _this->_impl_.weak_dependency_.MergeFrom(from._impl_.weak_dependency_); cached_has_bits = from._impl_._has_bits_[0]; - if (cached_has_bits & 0x0000003fu) { + if (cached_has_bits & 0x0000001fu) { if (cached_has_bits & 0x00000001u) { _this->_internal_set_name(from._internal_name()); } @@ -2347,13 +2132,10 @@ void FileDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, co _this->_internal_set_syntax(from._internal_syntax()); } if (cached_has_bits & 0x00000008u) { - _this->_internal_set_edition(from._internal_edition()); - } - if (cached_has_bits & 0x00000010u) { _this->_internal_mutable_options()->::PROTOBUF_NAMESPACE_ID::FileOptions::MergeFrom( from._internal_options()); } - if (cached_has_bits & 0x00000020u) { + if (cached_has_bits & 0x00000010u) { _this->_internal_mutable_source_code_info()->::PROTOBUF_NAMESPACE_ID::SourceCodeInfo::MergeFrom( from._internal_source_code_info()); } @@ -2408,10 +2190,6 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { &_impl_.syntax_, lhs_arena, &other->_impl_.syntax_, rhs_arena ); - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( - &_impl_.edition_, lhs_arena, - &other->_impl_.edition_, rhs_arena - ); ::PROTOBUF_NAMESPACE_ID::internal::memswap< PROTOBUF_FIELD_OFFSET(FileDescriptorProto, _impl_.source_code_info_) + sizeof(FileDescriptorProto::_impl_.source_code_info_) @@ -2421,18 +2199,16 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FileDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[1]); } + // =================================================================== class DescriptorProto_ExtensionRange::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(DescriptorProto_ExtensionRange, _impl_._has_bits_); static void set_has_start(HasBits* has_bits) { (*has_bits)[0] |= 2u; } @@ -2527,7 +2303,6 @@ void DescriptorProto_ExtensionRange::Clear() { } const char* DescriptorProto_ExtensionRange::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -2586,7 +2361,6 @@ failure: uint8_t* DescriptorProto_ExtensionRange::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ExtensionRange) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -2620,7 +2394,6 @@ uint8_t* DescriptorProto_ExtensionRange::_InternalSerialize( } size_t DescriptorProto_ExtensionRange::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto.ExtensionRange) size_t total_size = 0; @@ -2661,7 +2434,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ExtensionRange void DescriptorProto_ExtensionRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ExtensionRange) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -2711,18 +2483,16 @@ void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange } ::PROTOBUF_NAMESPACE_ID::Metadata DescriptorProto_ExtensionRange::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[2]); } + // =================================================================== class DescriptorProto_ReservedRange::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(DescriptorProto_ReservedRange, _impl_._has_bits_); static void set_has_start(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -2738,9 +2508,18 @@ DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(::PROTOBUF_NAMESPAC // @@protoc_insertion_point(arena_constructor:google.protobuf.DescriptorProto.ReservedRange) } DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(const DescriptorProto_ReservedRange& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + DescriptorProto_ReservedRange* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.start_){} + , decltype(_impl_.end_){}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::memcpy(&_impl_.start_, &from._impl_.start_, + static_cast(reinterpret_cast(&_impl_.end_) - + reinterpret_cast(&_impl_.start_)) + sizeof(_impl_.end_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.DescriptorProto.ReservedRange) } @@ -2790,7 +2569,6 @@ void DescriptorProto_ReservedRange::Clear() { } const char* DescriptorProto_ReservedRange::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -2841,7 +2619,6 @@ failure: uint8_t* DescriptorProto_ReservedRange::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ReservedRange) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -2868,7 +2645,6 @@ uint8_t* DescriptorProto_ReservedRange::_InternalSerialize( } size_t DescriptorProto_ReservedRange::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto.ReservedRange) size_t total_size = 0; @@ -2902,7 +2678,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto_ReservedRange: void DescriptorProto_ReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto.ReservedRange) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -2945,18 +2720,16 @@ void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange* } ::PROTOBUF_NAMESPACE_ID::Metadata DescriptorProto_ReservedRange::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[3]); } + // =================================================================== class DescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(DescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -3088,7 +2861,6 @@ void DescriptorProto::Clear() { } const char* DescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -3249,7 +3021,6 @@ failure: uint8_t* DescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -3347,7 +3118,6 @@ uint8_t* DescriptorProto::_InternalSerialize( } size_t DescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DescriptorProto) size_t total_size = 0; @@ -3442,7 +3212,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DescriptorProto::GetClassData( void DescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -3517,11 +3286,11 @@ void DescriptorProto::InternalSwap(DescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata DescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[4]); } + // =================================================================== class ExtensionRangeOptions::_Internal { @@ -3589,7 +3358,6 @@ void ExtensionRangeOptions::Clear() { } const char* ExtensionRangeOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -3638,7 +3406,6 @@ failure: uint8_t* ExtensionRangeOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ExtensionRangeOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -3664,7 +3431,6 @@ uint8_t* ExtensionRangeOptions::_InternalSerialize( } size_t ExtensionRangeOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ExtensionRangeOptions) size_t total_size = 0; @@ -3694,7 +3460,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ExtensionRangeOptions::GetClas void ExtensionRangeOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ExtensionRangeOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -3730,18 +3495,16 @@ void ExtensionRangeOptions::InternalSwap(ExtensionRangeOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata ExtensionRangeOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[5]); } + // =================================================================== class FieldDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(FieldDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -3963,7 +3726,6 @@ void FieldDescriptorProto::Clear() { } const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -4006,9 +3768,9 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseC // optional .google.protobuf.FieldDescriptorProto.Label label = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 32)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label_IsValid(val))) { _internal_set_label(static_cast<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(4, val, mutable_unknown_fields()); @@ -4019,9 +3781,9 @@ const char* FieldDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseC // optional .google.protobuf.FieldDescriptorProto.Type type = 5; case 5: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 40)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type_IsValid(val))) { _internal_set_type(static_cast<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(5, val, mutable_unknown_fields()); @@ -4117,7 +3879,6 @@ failure: uint8_t* FieldDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -4221,7 +3982,6 @@ uint8_t* FieldDescriptorProto::_InternalSerialize( } size_t FieldDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldDescriptorProto) size_t total_size = 0; @@ -4316,7 +4076,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldDescriptorProto::GetClass void FieldDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -4417,18 +4176,16 @@ void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FieldDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[6]); } + // =================================================================== class OneofDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(OneofDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -4528,7 +4285,6 @@ void OneofDescriptorProto::Clear() { } const char* OneofDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -4581,7 +4337,6 @@ failure: uint8_t* OneofDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -4613,7 +4368,6 @@ uint8_t* OneofDescriptorProto::_InternalSerialize( } size_t OneofDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.OneofDescriptorProto) size_t total_size = 0; @@ -4651,7 +4405,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofDescriptorProto::GetClass void OneofDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -4698,18 +4451,16 @@ void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata OneofDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[7]); } + // =================================================================== class EnumDescriptorProto_EnumReservedRange::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(EnumDescriptorProto_EnumReservedRange, _impl_._has_bits_); static void set_has_start(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -4725,9 +4476,18 @@ EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange(::P // @@protoc_insertion_point(arena_constructor:google.protobuf.EnumDescriptorProto.EnumReservedRange) } EnumDescriptorProto_EnumReservedRange::EnumDescriptorProto_EnumReservedRange(const EnumDescriptorProto_EnumReservedRange& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + EnumDescriptorProto_EnumReservedRange* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.start_){} + , decltype(_impl_.end_){}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::memcpy(&_impl_.start_, &from._impl_.start_, + static_cast(reinterpret_cast(&_impl_.end_) - + reinterpret_cast(&_impl_.start_)) + sizeof(_impl_.end_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.EnumDescriptorProto.EnumReservedRange) } @@ -4777,7 +4537,6 @@ void EnumDescriptorProto_EnumReservedRange::Clear() { } const char* EnumDescriptorProto_EnumReservedRange::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -4828,7 +4587,6 @@ failure: uint8_t* EnumDescriptorProto_EnumReservedRange::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -4855,7 +4613,6 @@ uint8_t* EnumDescriptorProto_EnumReservedRange::_InternalSerialize( } size_t EnumDescriptorProto_EnumReservedRange::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) size_t total_size = 0; @@ -4889,7 +4646,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto_EnumReserv void EnumDescriptorProto_EnumReservedRange::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto.EnumReservedRange) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -4932,18 +4688,16 @@ void EnumDescriptorProto_EnumReservedRange::InternalSwap(EnumDescriptorProto_Enu } ::PROTOBUF_NAMESPACE_ID::Metadata EnumDescriptorProto_EnumReservedRange::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[8]); } + // =================================================================== class EnumDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(EnumDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -5055,7 +4809,6 @@ void EnumDescriptorProto::Clear() { } const char* EnumDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -5151,7 +4904,6 @@ failure: uint8_t* EnumDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -5209,7 +4961,6 @@ uint8_t* EnumDescriptorProto::_InternalSerialize( } size_t EnumDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumDescriptorProto) size_t total_size = 0; @@ -5269,7 +5020,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumDescriptorProto::GetClassD void EnumDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -5324,18 +5074,16 @@ void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata EnumDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[9]); } + // =================================================================== class EnumValueDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(EnumValueDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -5442,7 +5190,6 @@ void EnumValueDescriptorProto::Clear() { } const char* EnumValueDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -5504,7 +5251,6 @@ failure: uint8_t* EnumValueDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -5542,7 +5288,6 @@ uint8_t* EnumValueDescriptorProto::_InternalSerialize( } size_t EnumValueDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValueDescriptorProto) size_t total_size = 0; @@ -5585,7 +5330,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueDescriptorProto::GetC void EnumValueDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -5641,18 +5385,16 @@ void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata EnumValueDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[10]); } + // =================================================================== class ServiceDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(ServiceDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -5756,7 +5498,6 @@ void ServiceDescriptorProto::Clear() { } const char* ServiceDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -5822,7 +5563,6 @@ failure: uint8_t* ServiceDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -5862,7 +5602,6 @@ uint8_t* ServiceDescriptorProto::_InternalSerialize( } size_t ServiceDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ServiceDescriptorProto) size_t total_size = 0; @@ -5907,7 +5646,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceDescriptorProto::GetCla void ServiceDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -5958,18 +5696,16 @@ void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata ServiceDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[11]); } + // =================================================================== class MethodDescriptorProto::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(MethodDescriptorProto, _impl_._has_bits_); static void set_has_name(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -6127,7 +5863,6 @@ void MethodDescriptorProto::Clear() { } const char* MethodDescriptorProto::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -6222,7 +5957,6 @@ failure: uint8_t* MethodDescriptorProto::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodDescriptorProto) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -6286,7 +6020,6 @@ uint8_t* MethodDescriptorProto::_InternalSerialize( } size_t MethodDescriptorProto::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MethodDescriptorProto) size_t total_size = 0; @@ -6348,7 +6081,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodDescriptorProto::GetClas void MethodDescriptorProto::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodDescriptorProto) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -6421,18 +6153,16 @@ void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata MethodDescriptorProto::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[12]); } + // =================================================================== class FileOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(FileOptions, _impl_._has_bits_); static void set_has_java_package(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -6779,7 +6509,6 @@ void FileOptions::Clear() { } const char* FileOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -6813,9 +6542,9 @@ const char* FileOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* c // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; case 9: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 72)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode_IsValid(val))) { _internal_set_optimize_for(static_cast<::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(9, val, mutable_unknown_fields()); @@ -7044,7 +6773,6 @@ failure: uint8_t* FileOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -7232,7 +6960,6 @@ uint8_t* FileOptions::_InternalSerialize( } size_t FileOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FileOptions) size_t total_size = 0; @@ -7390,7 +7117,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FileOptions::GetClassData() co void FileOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FileOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -7546,18 +7272,16 @@ void FileOptions::InternalSwap(FileOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FileOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[13]); } + // =================================================================== class MessageOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(MessageOptions, _impl_._has_bits_); static void set_has_message_set_wire_format(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -7650,7 +7374,6 @@ void MessageOptions::Clear() { } const char* MessageOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -7737,7 +7460,6 @@ failure: uint8_t* MessageOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MessageOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -7788,7 +7510,6 @@ uint8_t* MessageOptions::_InternalSerialize( } size_t MessageOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MessageOptions) size_t total_size = 0; @@ -7841,7 +7562,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MessageOptions::GetClassData() void MessageOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MessageOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -7900,18 +7620,16 @@ void MessageOptions::InternalSwap(MessageOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata MessageOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[14]); } + // =================================================================== class FieldOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(FieldOptions, _impl_._has_bits_); static void set_has_ctype(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -8022,7 +7740,6 @@ void FieldOptions::Clear() { } const char* FieldOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -8032,9 +7749,9 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType_IsValid(val))) { _internal_set_ctype(static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_CType>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(1, val, mutable_unknown_fields()); @@ -8072,9 +7789,9 @@ const char* FieldOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 48)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType_IsValid(val))) { _internal_set_jstype(static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(6, val, mutable_unknown_fields()); @@ -8144,7 +7861,6 @@ failure: uint8_t* FieldOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -8215,7 +7931,6 @@ uint8_t* FieldOptions::_InternalSerialize( } size_t FieldOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldOptions) size_t total_size = 0; @@ -8285,7 +8000,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldOptions::GetClassData() c void FieldOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -8353,11 +8067,11 @@ void FieldOptions::InternalSwap(FieldOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FieldOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[15]); } + // =================================================================== class OneofOptions::_Internal { @@ -8425,7 +8139,6 @@ void OneofOptions::Clear() { } const char* OneofOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -8474,7 +8187,6 @@ failure: uint8_t* OneofOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -8500,7 +8212,6 @@ uint8_t* OneofOptions::_InternalSerialize( } size_t OneofOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.OneofOptions) size_t total_size = 0; @@ -8530,7 +8241,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*OneofOptions::GetClassData() c void OneofOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.OneofOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -8566,18 +8276,16 @@ void OneofOptions::InternalSwap(OneofOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata OneofOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[16]); } + // =================================================================== class EnumOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(EnumOptions, _impl_._has_bits_); static void set_has_allow_alias(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -8660,7 +8368,6 @@ void EnumOptions::Clear() { } const char* EnumOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -8729,7 +8436,6 @@ failure: uint8_t* EnumOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -8768,7 +8474,6 @@ uint8_t* EnumOptions::_InternalSerialize( } size_t EnumOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumOptions) size_t total_size = 0; @@ -8811,7 +8516,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumOptions::GetClassData() co void EnumOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -8864,18 +8568,16 @@ void EnumOptions::InternalSwap(EnumOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata EnumOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[17]); } + // =================================================================== class EnumValueOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(EnumValueOptions, _impl_._has_bits_); static void set_has_deprecated(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -8949,7 +8651,6 @@ void EnumValueOptions::Clear() { } const char* EnumValueOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -9009,7 +8710,6 @@ failure: uint8_t* EnumValueOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -9042,7 +8742,6 @@ uint8_t* EnumValueOptions::_InternalSerialize( } size_t EnumValueOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValueOptions) size_t total_size = 0; @@ -9078,7 +8777,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValueOptions::GetClassData void EnumValueOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValueOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -9119,18 +8817,16 @@ void EnumValueOptions::InternalSwap(EnumValueOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata EnumValueOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[18]); } + // =================================================================== class ServiceOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(ServiceOptions, _impl_._has_bits_); static void set_has_deprecated(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -9204,7 +8900,6 @@ void ServiceOptions::Clear() { } const char* ServiceOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -9264,7 +8959,6 @@ failure: uint8_t* ServiceOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -9297,7 +8991,6 @@ uint8_t* ServiceOptions::_InternalSerialize( } size_t ServiceOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ServiceOptions) size_t total_size = 0; @@ -9333,7 +9026,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ServiceOptions::GetClassData() void ServiceOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ServiceOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -9374,18 +9066,16 @@ void ServiceOptions::InternalSwap(ServiceOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata ServiceOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[19]); } + // =================================================================== class MethodOptions::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(MethodOptions, _impl_._has_bits_); static void set_has_deprecated(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -9471,7 +9161,6 @@ void MethodOptions::Clear() { } const char* MethodOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -9490,9 +9179,9 @@ const char* MethodOptions::_InternalParse(const char* ptr, ::_pbi::ParseContext* // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; case 34: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel_IsValid(static_cast(val)))) { + if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel_IsValid(val))) { _internal_set_idempotency_level(static_cast<::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(34, val, mutable_unknown_fields()); @@ -9544,7 +9233,6 @@ failure: uint8_t* MethodOptions::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodOptions) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -9584,7 +9272,6 @@ uint8_t* MethodOptions::_InternalSerialize( } size_t MethodOptions::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.MethodOptions) size_t total_size = 0; @@ -9628,7 +9315,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*MethodOptions::GetClassData() void MethodOptions::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.MethodOptions) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -9681,18 +9367,16 @@ void MethodOptions::InternalSwap(MethodOptions* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata MethodOptions::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[20]); } + // =================================================================== class UninterpretedOption_NamePart::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(UninterpretedOption_NamePart, _impl_._has_bits_); static void set_has_name_part(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -9782,7 +9466,6 @@ void UninterpretedOption_NamePart::Clear() { } const char* UninterpretedOption_NamePart::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -9836,7 +9519,6 @@ failure: uint8_t* UninterpretedOption_NamePart::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption.NamePart) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -9885,7 +9567,6 @@ size_t UninterpretedOption_NamePart::RequiredFieldsByteSizeFallback() const { return total_size; } size_t UninterpretedOption_NamePart::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UninterpretedOption.NamePart) size_t total_size = 0; @@ -9918,7 +9599,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption_NamePart:: void UninterpretedOption_NamePart::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption.NamePart) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -9963,18 +9643,16 @@ void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* ot } ::PROTOBUF_NAMESPACE_ID::Metadata UninterpretedOption_NamePart::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[21]); } + // =================================================================== class UninterpretedOption::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(UninterpretedOption, _impl_._has_bits_); static void set_has_identifier_value(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -10125,7 +9803,6 @@ void UninterpretedOption::Clear() { } const char* UninterpretedOption::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -10231,7 +9908,6 @@ failure: uint8_t* UninterpretedOption::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -10298,7 +9974,6 @@ uint8_t* UninterpretedOption::_InternalSerialize( } size_t UninterpretedOption::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UninterpretedOption) size_t total_size = 0; @@ -10365,7 +10040,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UninterpretedOption::GetClassD void UninterpretedOption::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UninterpretedOption) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -10438,18 +10112,16 @@ void UninterpretedOption::InternalSwap(UninterpretedOption* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata UninterpretedOption::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[22]); } + // =================================================================== class SourceCodeInfo_Location::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(SourceCodeInfo_Location, _impl_._has_bits_); static void set_has_leading_comments(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -10568,7 +10240,6 @@ void SourceCodeInfo_Location::Clear() { } const char* SourceCodeInfo_Location::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -10664,14 +10335,13 @@ failure: uint8_t* SourceCodeInfo_Location::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo.Location) uint32_t cached_has_bits = 0; (void) cached_has_bits; // repeated int32 path = 1 [packed = true]; { - int byte_size = _impl_._path_cached_byte_size_.Get(); + int byte_size = _impl_._path_cached_byte_size_.load(std::memory_order_relaxed); if (byte_size > 0) { target = stream->WriteInt32Packed( 1, _internal_path(), byte_size, target); @@ -10680,7 +10350,7 @@ uint8_t* SourceCodeInfo_Location::_InternalSerialize( // repeated int32 span = 2 [packed = true]; { - int byte_size = _impl_._span_cached_byte_size_.Get(); + int byte_size = _impl_._span_cached_byte_size_.load(std::memory_order_relaxed); if (byte_size > 0) { target = stream->WriteInt32Packed( 2, _internal_span(), byte_size, target); @@ -10727,7 +10397,6 @@ uint8_t* SourceCodeInfo_Location::_InternalSerialize( } size_t SourceCodeInfo_Location::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceCodeInfo.Location) size_t total_size = 0; @@ -10744,7 +10413,8 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const { ::_pbi::WireFormatLite::Int32Size(static_cast(data_size)); } int cached_size = ::_pbi::ToCachedSize(data_size); - _impl_._path_cached_byte_size_.Set(cached_size); + _impl_._path_cached_byte_size_.store(cached_size, + std::memory_order_relaxed); total_size += data_size; } @@ -10757,7 +10427,8 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const { ::_pbi::WireFormatLite::Int32Size(static_cast(data_size)); } int cached_size = ::_pbi::ToCachedSize(data_size); - _impl_._span_cached_byte_size_.Set(cached_size); + _impl_._span_cached_byte_size_.store(cached_size, + std::memory_order_relaxed); total_size += data_size; } @@ -10799,7 +10470,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo_Location::GetCl void SourceCodeInfo_Location::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo.Location) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -10851,11 +10521,11 @@ void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata SourceCodeInfo_Location::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[23]); } + // =================================================================== class SourceCodeInfo::_Internal { @@ -10918,7 +10588,6 @@ void SourceCodeInfo::Clear() { } const char* SourceCodeInfo::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -10962,7 +10631,6 @@ failure: uint8_t* SourceCodeInfo::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -10984,7 +10652,6 @@ uint8_t* SourceCodeInfo::_InternalSerialize( } size_t SourceCodeInfo::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceCodeInfo) size_t total_size = 0; @@ -11012,7 +10679,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceCodeInfo::GetClassData() void SourceCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceCodeInfo) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -11040,18 +10706,16 @@ void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata SourceCodeInfo::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[24]); } + // =================================================================== class GeneratedCodeInfo_Annotation::_Internal { public: using HasBits = decltype(std::declval()._impl_._has_bits_); - static constexpr int32_t kHasBitsOffset = - 8 * PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_._has_bits_); static void set_has_source_file(HasBits* has_bits) { (*has_bits)[0] |= 1u; } @@ -11061,9 +10725,6 @@ class GeneratedCodeInfo_Annotation::_Internal { static void set_has_end(HasBits* has_bits) { (*has_bits)[0] |= 4u; } - static void set_has_semantic(HasBits* has_bits) { - (*has_bits)[0] |= 8u; - } }; GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(::PROTOBUF_NAMESPACE_ID::Arena* arena, @@ -11082,8 +10743,7 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn , /*decltype(_impl_._path_cached_byte_size_)*/{0} , decltype(_impl_.source_file_){} , decltype(_impl_.begin_){} - , decltype(_impl_.end_){} - , decltype(_impl_.semantic_){}}; + , decltype(_impl_.end_){}}; _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); _impl_.source_file_.InitDefault(); @@ -11095,8 +10755,8 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn _this->GetArenaForAllocation()); } ::memcpy(&_impl_.begin_, &from._impl_.begin_, - static_cast(reinterpret_cast(&_impl_.semantic_) - - reinterpret_cast(&_impl_.begin_)) + sizeof(_impl_.semantic_)); + static_cast(reinterpret_cast(&_impl_.end_) - + reinterpret_cast(&_impl_.begin_)) + sizeof(_impl_.end_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo.Annotation) } @@ -11112,7 +10772,6 @@ inline void GeneratedCodeInfo_Annotation::SharedCtor( , decltype(_impl_.source_file_){} , decltype(_impl_.begin_){0} , decltype(_impl_.end_){0} - , decltype(_impl_.semantic_){0} }; _impl_.source_file_.InitDefault(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING @@ -11150,17 +10809,16 @@ void GeneratedCodeInfo_Annotation::Clear() { if (cached_has_bits & 0x00000001u) { _impl_.source_file_.ClearNonDefaultToEmpty(); } - if (cached_has_bits & 0x0000000eu) { + if (cached_has_bits & 0x00000006u) { ::memset(&_impl_.begin_, 0, static_cast( - reinterpret_cast(&_impl_.semantic_) - - reinterpret_cast(&_impl_.begin_)) + sizeof(_impl_.semantic_)); + reinterpret_cast(&_impl_.end_) - + reinterpret_cast(&_impl_.begin_)) + sizeof(_impl_.end_)); } _impl_._has_bits_.Clear(); _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); } const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; while (!ctx->Done(&ptr)) { @@ -11208,19 +10866,6 @@ const char* GeneratedCodeInfo_Annotation::_InternalParse(const char* ptr, ::_pbi } else goto handle_unusual; continue; - // optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 40)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - if (PROTOBUF_PREDICT_TRUE(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic_IsValid(static_cast(val)))) { - _internal_set_semantic(static_cast<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic>(val)); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(5, val, mutable_unknown_fields()); - } - } else - goto handle_unusual; - continue; default: goto handle_unusual; } // switch @@ -11247,14 +10892,13 @@ failure: uint8_t* GeneratedCodeInfo_Annotation::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo.Annotation) uint32_t cached_has_bits = 0; (void) cached_has_bits; // repeated int32 path = 1 [packed = true]; { - int byte_size = _impl_._path_cached_byte_size_.Get(); + int byte_size = _impl_._path_cached_byte_size_.load(std::memory_order_relaxed); if (byte_size > 0) { target = stream->WriteInt32Packed( 1, _internal_path(), byte_size, target); @@ -11284,13 +10928,6 @@ uint8_t* GeneratedCodeInfo_Annotation::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteInt32ToArray(4, this->_internal_end(), target); } - // optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5; - if (cached_has_bits & 0x00000008u) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteEnumToArray( - 5, this->_internal_semantic(), target); - } - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); @@ -11300,7 +10937,6 @@ uint8_t* GeneratedCodeInfo_Annotation::_InternalSerialize( } size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.GeneratedCodeInfo.Annotation) size_t total_size = 0; @@ -11317,12 +10953,13 @@ size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { ::_pbi::WireFormatLite::Int32Size(static_cast(data_size)); } int cached_size = ::_pbi::ToCachedSize(data_size); - _impl_._path_cached_byte_size_.Set(cached_size); + _impl_._path_cached_byte_size_.store(cached_size, + std::memory_order_relaxed); total_size += data_size; } cached_has_bits = _impl_._has_bits_[0]; - if (cached_has_bits & 0x0000000fu) { + if (cached_has_bits & 0x00000007u) { // optional string source_file = 2; if (cached_has_bits & 0x00000001u) { total_size += 1 + @@ -11340,12 +10977,6 @@ size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(this->_internal_end()); } - // optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5; - if (cached_has_bits & 0x00000008u) { - total_size += 1 + - ::_pbi::WireFormatLite::EnumSize(this->_internal_semantic()); - } - } return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); } @@ -11360,7 +10991,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo_Annotation:: void GeneratedCodeInfo_Annotation::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo.Annotation) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -11368,7 +10998,7 @@ void GeneratedCodeInfo_Annotation::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& t _this->_impl_.path_.MergeFrom(from._impl_.path_); cached_has_bits = from._impl_._has_bits_[0]; - if (cached_has_bits & 0x0000000fu) { + if (cached_has_bits & 0x00000007u) { if (cached_has_bits & 0x00000001u) { _this->_internal_set_source_file(from._internal_source_file()); } @@ -11378,9 +11008,6 @@ void GeneratedCodeInfo_Annotation::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& t if (cached_has_bits & 0x00000004u) { _this->_impl_.end_ = from._impl_.end_; } - if (cached_has_bits & 0x00000008u) { - _this->_impl_.semantic_ = from._impl_.semantic_; - } _this->_impl_._has_bits_[0] |= cached_has_bits; } _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); @@ -11409,19 +11036,19 @@ void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* ot &other->_impl_.source_file_, rhs_arena ); ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_.semantic_) - + sizeof(GeneratedCodeInfo_Annotation::_impl_.semantic_) + PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_.end_) + + sizeof(GeneratedCodeInfo_Annotation::_impl_.end_) - PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_.begin_)>( reinterpret_cast(&_impl_.begin_), reinterpret_cast(&other->_impl_.begin_)); } ::PROTOBUF_NAMESPACE_ID::Metadata GeneratedCodeInfo_Annotation::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[25]); } + // =================================================================== class GeneratedCodeInfo::_Internal { @@ -11484,7 +11111,6 @@ void GeneratedCodeInfo::Clear() { } const char* GeneratedCodeInfo::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -11528,7 +11154,6 @@ failure: uint8_t* GeneratedCodeInfo::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -11550,7 +11175,6 @@ uint8_t* GeneratedCodeInfo::_InternalSerialize( } size_t GeneratedCodeInfo::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.GeneratedCodeInfo) size_t total_size = 0; @@ -11578,7 +11202,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GeneratedCodeInfo::GetClassDat void GeneratedCodeInfo::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.GeneratedCodeInfo) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -11606,11 +11229,11 @@ void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata GeneratedCodeInfo::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_getter, &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, file_level_metadata_google_2fprotobuf_2fdescriptor_2eproto[26]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -11723,5 +11346,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo >(Arena* a return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/descriptor.pb.h b/libs/protobuf/src/google/protobuf/descriptor.pb.h index f592e76..9ae046a 100644 --- a/libs/protobuf/src/google/protobuf/descriptor.pb.h +++ b/libs/protobuf/src/google/protobuf/descriptor.pb.h @@ -1,44 +1,39 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/descriptor.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fdescriptor_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -49,8 +44,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fdescriptor_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fdescriptor_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto; PROTOBUF_NAMESPACE_OPEN class DescriptorProto; struct DescriptorProtoDefaultTypeInternal; @@ -133,63 +127,38 @@ PROTOBUF_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOpti class UninterpretedOption_NamePart; struct UninterpretedOption_NamePartDefaultTypeInternal; PROTOBUF_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValueOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValueOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileDescriptorSet* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileDescriptorSet>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MessageOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MessageOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MethodOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MethodOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::OneofOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::OneofOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ServiceOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ServiceOptions>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceCodeInfo>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UninterpretedOption* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UninterpretedOption>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart>(Arena*); PROTOBUF_NAMESPACE_CLOSE - PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto_ExtensionRange>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DescriptorProto_ReservedRange>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumDescriptorProto_EnumReservedRange>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValueDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValueOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValueOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ExtensionRangeOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileDescriptorSet* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileDescriptorSet>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FileOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MessageOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MessageOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MethodDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::MethodOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::MethodOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::OneofDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::OneofOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::OneofOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ServiceDescriptorProto>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ServiceOptions* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ServiceOptions>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceCodeInfo>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceCodeInfo_Location>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UninterpretedOption* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UninterpretedOption>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UninterpretedOption_NamePart>(Arena*); +PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_OPEN + enum FieldDescriptorProto_Type : int { FieldDescriptorProto_Type_TYPE_DOUBLE = 1, FieldDescriptorProto_Type_TYPE_FLOAT = 2, @@ -208,212 +177,149 @@ enum FieldDescriptorProto_Type : int { FieldDescriptorProto_Type_TYPE_SFIXED32 = 15, FieldDescriptorProto_Type_TYPE_SFIXED64 = 16, FieldDescriptorProto_Type_TYPE_SINT32 = 17, - FieldDescriptorProto_Type_TYPE_SINT64 = 18, + FieldDescriptorProto_Type_TYPE_SINT64 = 18 }; - PROTOBUF_EXPORT bool FieldDescriptorProto_Type_IsValid(int value); -constexpr FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MIN = static_cast(1); -constexpr FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MAX = static_cast(18); -constexpr int FieldDescriptorProto_Type_Type_ARRAYSIZE = 18 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -FieldDescriptorProto_Type_descriptor(); -template -const std::string& FieldDescriptorProto_Type_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Type_Name()."); - return FieldDescriptorProto_Type_Name(static_cast(value)); +constexpr FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MIN = FieldDescriptorProto_Type_TYPE_DOUBLE; +constexpr FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MAX = FieldDescriptorProto_Type_TYPE_SINT64; +constexpr int FieldDescriptorProto_Type_Type_ARRAYSIZE = FieldDescriptorProto_Type_Type_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldDescriptorProto_Type_descriptor(); +template +inline const std::string& FieldDescriptorProto_Type_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function FieldDescriptorProto_Type_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + FieldDescriptorProto_Type_descriptor(), enum_t_value); } -template <> -inline const std::string& FieldDescriptorProto_Type_Name(FieldDescriptorProto_Type value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool FieldDescriptorProto_Type_Parse(absl::string_view name, FieldDescriptorProto_Type* value) { +inline bool FieldDescriptorProto_Type_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, FieldDescriptorProto_Type* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - FieldDescriptorProto_Type_descriptor(), name, value); + FieldDescriptorProto_Type_descriptor(), name, value); } enum FieldDescriptorProto_Label : int { FieldDescriptorProto_Label_LABEL_OPTIONAL = 1, FieldDescriptorProto_Label_LABEL_REQUIRED = 2, - FieldDescriptorProto_Label_LABEL_REPEATED = 3, + FieldDescriptorProto_Label_LABEL_REPEATED = 3 }; - PROTOBUF_EXPORT bool FieldDescriptorProto_Label_IsValid(int value); -constexpr FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MIN = static_cast(1); -constexpr FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MAX = static_cast(3); -constexpr int FieldDescriptorProto_Label_Label_ARRAYSIZE = 3 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -FieldDescriptorProto_Label_descriptor(); -template -const std::string& FieldDescriptorProto_Label_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Label_Name()."); - return FieldDescriptorProto_Label_Name(static_cast(value)); +constexpr FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MIN = FieldDescriptorProto_Label_LABEL_OPTIONAL; +constexpr FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MAX = FieldDescriptorProto_Label_LABEL_REPEATED; +constexpr int FieldDescriptorProto_Label_Label_ARRAYSIZE = FieldDescriptorProto_Label_Label_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldDescriptorProto_Label_descriptor(); +template +inline const std::string& FieldDescriptorProto_Label_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function FieldDescriptorProto_Label_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + FieldDescriptorProto_Label_descriptor(), enum_t_value); } -template <> -inline const std::string& FieldDescriptorProto_Label_Name(FieldDescriptorProto_Label value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool FieldDescriptorProto_Label_Parse(absl::string_view name, FieldDescriptorProto_Label* value) { +inline bool FieldDescriptorProto_Label_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, FieldDescriptorProto_Label* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - FieldDescriptorProto_Label_descriptor(), name, value); + FieldDescriptorProto_Label_descriptor(), name, value); } enum FileOptions_OptimizeMode : int { FileOptions_OptimizeMode_SPEED = 1, FileOptions_OptimizeMode_CODE_SIZE = 2, - FileOptions_OptimizeMode_LITE_RUNTIME = 3, + FileOptions_OptimizeMode_LITE_RUNTIME = 3 }; - PROTOBUF_EXPORT bool FileOptions_OptimizeMode_IsValid(int value); -constexpr FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MIN = static_cast(1); -constexpr FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MAX = static_cast(3); -constexpr int FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE = 3 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -FileOptions_OptimizeMode_descriptor(); -template -const std::string& FileOptions_OptimizeMode_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to OptimizeMode_Name()."); - return FileOptions_OptimizeMode_Name(static_cast(value)); +constexpr FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MIN = FileOptions_OptimizeMode_SPEED; +constexpr FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MAX = FileOptions_OptimizeMode_LITE_RUNTIME; +constexpr int FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE = FileOptions_OptimizeMode_OptimizeMode_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FileOptions_OptimizeMode_descriptor(); +template +inline const std::string& FileOptions_OptimizeMode_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function FileOptions_OptimizeMode_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + FileOptions_OptimizeMode_descriptor(), enum_t_value); } -template <> -inline const std::string& FileOptions_OptimizeMode_Name(FileOptions_OptimizeMode value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool FileOptions_OptimizeMode_Parse(absl::string_view name, FileOptions_OptimizeMode* value) { +inline bool FileOptions_OptimizeMode_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, FileOptions_OptimizeMode* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - FileOptions_OptimizeMode_descriptor(), name, value); + FileOptions_OptimizeMode_descriptor(), name, value); } enum FieldOptions_CType : int { FieldOptions_CType_STRING = 0, FieldOptions_CType_CORD = 1, - FieldOptions_CType_STRING_PIECE = 2, + FieldOptions_CType_STRING_PIECE = 2 }; - PROTOBUF_EXPORT bool FieldOptions_CType_IsValid(int value); -constexpr FieldOptions_CType FieldOptions_CType_CType_MIN = static_cast(0); -constexpr FieldOptions_CType FieldOptions_CType_CType_MAX = static_cast(2); -constexpr int FieldOptions_CType_CType_ARRAYSIZE = 2 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -FieldOptions_CType_descriptor(); -template -const std::string& FieldOptions_CType_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to CType_Name()."); - return FieldOptions_CType_Name(static_cast(value)); +constexpr FieldOptions_CType FieldOptions_CType_CType_MIN = FieldOptions_CType_STRING; +constexpr FieldOptions_CType FieldOptions_CType_CType_MAX = FieldOptions_CType_STRING_PIECE; +constexpr int FieldOptions_CType_CType_ARRAYSIZE = FieldOptions_CType_CType_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldOptions_CType_descriptor(); +template +inline const std::string& FieldOptions_CType_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function FieldOptions_CType_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + FieldOptions_CType_descriptor(), enum_t_value); } -template <> -inline const std::string& FieldOptions_CType_Name(FieldOptions_CType value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool FieldOptions_CType_Parse(absl::string_view name, FieldOptions_CType* value) { +inline bool FieldOptions_CType_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, FieldOptions_CType* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - FieldOptions_CType_descriptor(), name, value); + FieldOptions_CType_descriptor(), name, value); } enum FieldOptions_JSType : int { FieldOptions_JSType_JS_NORMAL = 0, FieldOptions_JSType_JS_STRING = 1, - FieldOptions_JSType_JS_NUMBER = 2, + FieldOptions_JSType_JS_NUMBER = 2 }; - PROTOBUF_EXPORT bool FieldOptions_JSType_IsValid(int value); -constexpr FieldOptions_JSType FieldOptions_JSType_JSType_MIN = static_cast(0); -constexpr FieldOptions_JSType FieldOptions_JSType_JSType_MAX = static_cast(2); -constexpr int FieldOptions_JSType_JSType_ARRAYSIZE = 2 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -FieldOptions_JSType_descriptor(); -template -const std::string& FieldOptions_JSType_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to JSType_Name()."); - return FieldOptions_JSType_Name(static_cast(value)); +constexpr FieldOptions_JSType FieldOptions_JSType_JSType_MIN = FieldOptions_JSType_JS_NORMAL; +constexpr FieldOptions_JSType FieldOptions_JSType_JSType_MAX = FieldOptions_JSType_JS_NUMBER; +constexpr int FieldOptions_JSType_JSType_ARRAYSIZE = FieldOptions_JSType_JSType_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* FieldOptions_JSType_descriptor(); +template +inline const std::string& FieldOptions_JSType_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function FieldOptions_JSType_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + FieldOptions_JSType_descriptor(), enum_t_value); } -template <> -inline const std::string& FieldOptions_JSType_Name(FieldOptions_JSType value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool FieldOptions_JSType_Parse(absl::string_view name, FieldOptions_JSType* value) { +inline bool FieldOptions_JSType_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, FieldOptions_JSType* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - FieldOptions_JSType_descriptor(), name, value); + FieldOptions_JSType_descriptor(), name, value); } enum MethodOptions_IdempotencyLevel : int { MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN = 0, MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS = 1, - MethodOptions_IdempotencyLevel_IDEMPOTENT = 2, + MethodOptions_IdempotencyLevel_IDEMPOTENT = 2 }; - PROTOBUF_EXPORT bool MethodOptions_IdempotencyLevel_IsValid(int value); -constexpr MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN = static_cast(0); -constexpr MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX = static_cast(2); -constexpr int MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE = 2 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -MethodOptions_IdempotencyLevel_descriptor(); -template -const std::string& MethodOptions_IdempotencyLevel_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to IdempotencyLevel_Name()."); - return MethodOptions_IdempotencyLevel_Name(static_cast(value)); +constexpr MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN = MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN; +constexpr MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX = MethodOptions_IdempotencyLevel_IDEMPOTENT; +constexpr int MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE = MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* MethodOptions_IdempotencyLevel_descriptor(); +template +inline const std::string& MethodOptions_IdempotencyLevel_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function MethodOptions_IdempotencyLevel_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + MethodOptions_IdempotencyLevel_descriptor(), enum_t_value); } -template <> -inline const std::string& MethodOptions_IdempotencyLevel_Name(MethodOptions_IdempotencyLevel value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool MethodOptions_IdempotencyLevel_Parse(absl::string_view name, MethodOptions_IdempotencyLevel* value) { +inline bool MethodOptions_IdempotencyLevel_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, MethodOptions_IdempotencyLevel* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - MethodOptions_IdempotencyLevel_descriptor(), name, value); + MethodOptions_IdempotencyLevel_descriptor(), name, value); } -enum GeneratedCodeInfo_Annotation_Semantic : int { - GeneratedCodeInfo_Annotation_Semantic_NONE = 0, - GeneratedCodeInfo_Annotation_Semantic_SET = 1, - GeneratedCodeInfo_Annotation_Semantic_ALIAS = 2, -}; - -PROTOBUF_EXPORT bool GeneratedCodeInfo_Annotation_Semantic_IsValid(int value); -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation_Semantic_Semantic_MIN = static_cast(0); -constexpr GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation_Semantic_Semantic_MAX = static_cast(2); -constexpr int GeneratedCodeInfo_Annotation_Semantic_Semantic_ARRAYSIZE = 2 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -GeneratedCodeInfo_Annotation_Semantic_descriptor(); -template -const std::string& GeneratedCodeInfo_Annotation_Semantic_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Semantic_Name()."); - return GeneratedCodeInfo_Annotation_Semantic_Name(static_cast(value)); -} -template <> -inline const std::string& GeneratedCodeInfo_Annotation_Semantic_Name(GeneratedCodeInfo_Annotation_Semantic value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool GeneratedCodeInfo_Annotation_Semantic_Parse(absl::string_view name, GeneratedCodeInfo_Annotation_Semantic* value) { - return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - GeneratedCodeInfo_Annotation_Semantic_descriptor(), name, value); -} - // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT FileDescriptorSet final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ { public: @@ -524,7 +430,7 @@ class PROTOBUF_EXPORT FileDescriptorSet final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FileDescriptorSet"; } protected: @@ -575,7 +481,8 @@ class PROTOBUF_EXPORT FileDescriptorSet final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT FileDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorProto) */ { @@ -687,7 +594,7 @@ class PROTOBUF_EXPORT FileDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FileDescriptorProto"; } protected: @@ -715,7 +622,6 @@ class PROTOBUF_EXPORT FileDescriptorProto final : kNameFieldNumber = 1, kPackageFieldNumber = 2, kSyntaxFieldNumber = 12, - kEditionFieldNumber = 13, kOptionsFieldNumber = 8, kSourceCodeInfoFieldNumber = 9, }; @@ -913,24 +819,6 @@ class PROTOBUF_EXPORT FileDescriptorProto final : std::string* _internal_mutable_syntax(); public: - // optional string edition = 13; - bool has_edition() const; - private: - bool _internal_has_edition() const; - public: - void clear_edition(); - const std::string& edition() const; - template - void set_edition(ArgT0&& arg0, ArgT... args); - std::string* mutable_edition(); - PROTOBUF_NODISCARD std::string* release_edition(); - void set_allocated_edition(std::string* edition); - private: - const std::string& _internal_edition() const; - inline PROTOBUF_ALWAYS_INLINE void _internal_set_edition(const std::string& value); - std::string* _internal_mutable_edition(); - public: - // optional .google.protobuf.FileOptions options = 8; bool has_options() const; private: @@ -987,13 +875,13 @@ class PROTOBUF_EXPORT FileDescriptorProto final : ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr package_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr syntax_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr edition_; ::PROTOBUF_NAMESPACE_ID::FileOptions* options_; ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* source_code_info_; }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ExtensionRange) */ { @@ -1105,7 +993,7 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.DescriptorProto.ExtensionRange"; } protected: @@ -1187,7 +1075,8 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ReservedRange) */ { @@ -1299,7 +1188,7 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.DescriptorProto.ReservedRange"; } protected: @@ -1361,7 +1250,8 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT DescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto) */ { @@ -1473,7 +1363,7 @@ class PROTOBUF_EXPORT DescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.DescriptorProto"; } protected: @@ -1714,7 +1604,8 @@ class PROTOBUF_EXPORT DescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT ExtensionRangeOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ExtensionRangeOptions) */ { @@ -1826,7 +1717,7 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.ExtensionRangeOptions"; } protected: @@ -2069,7 +1960,8 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT FieldDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { @@ -2181,7 +2073,7 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FieldDescriptorProto"; } protected: @@ -2196,60 +2088,97 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : // nested types ---------------------------------------------------- - using Type = FieldDescriptorProto_Type; - static constexpr Type TYPE_DOUBLE = FieldDescriptorProto_Type_TYPE_DOUBLE; - static constexpr Type TYPE_FLOAT = FieldDescriptorProto_Type_TYPE_FLOAT; - static constexpr Type TYPE_INT64 = FieldDescriptorProto_Type_TYPE_INT64; - static constexpr Type TYPE_UINT64 = FieldDescriptorProto_Type_TYPE_UINT64; - static constexpr Type TYPE_INT32 = FieldDescriptorProto_Type_TYPE_INT32; - static constexpr Type TYPE_FIXED64 = FieldDescriptorProto_Type_TYPE_FIXED64; - static constexpr Type TYPE_FIXED32 = FieldDescriptorProto_Type_TYPE_FIXED32; - static constexpr Type TYPE_BOOL = FieldDescriptorProto_Type_TYPE_BOOL; - static constexpr Type TYPE_STRING = FieldDescriptorProto_Type_TYPE_STRING; - static constexpr Type TYPE_GROUP = FieldDescriptorProto_Type_TYPE_GROUP; - static constexpr Type TYPE_MESSAGE = FieldDescriptorProto_Type_TYPE_MESSAGE; - static constexpr Type TYPE_BYTES = FieldDescriptorProto_Type_TYPE_BYTES; - static constexpr Type TYPE_UINT32 = FieldDescriptorProto_Type_TYPE_UINT32; - static constexpr Type TYPE_ENUM = FieldDescriptorProto_Type_TYPE_ENUM; - static constexpr Type TYPE_SFIXED32 = FieldDescriptorProto_Type_TYPE_SFIXED32; - static constexpr Type TYPE_SFIXED64 = FieldDescriptorProto_Type_TYPE_SFIXED64; - static constexpr Type TYPE_SINT32 = FieldDescriptorProto_Type_TYPE_SINT32; - static constexpr Type TYPE_SINT64 = FieldDescriptorProto_Type_TYPE_SINT64; + typedef FieldDescriptorProto_Type Type; + static constexpr Type TYPE_DOUBLE = + FieldDescriptorProto_Type_TYPE_DOUBLE; + static constexpr Type TYPE_FLOAT = + FieldDescriptorProto_Type_TYPE_FLOAT; + static constexpr Type TYPE_INT64 = + FieldDescriptorProto_Type_TYPE_INT64; + static constexpr Type TYPE_UINT64 = + FieldDescriptorProto_Type_TYPE_UINT64; + static constexpr Type TYPE_INT32 = + FieldDescriptorProto_Type_TYPE_INT32; + static constexpr Type TYPE_FIXED64 = + FieldDescriptorProto_Type_TYPE_FIXED64; + static constexpr Type TYPE_FIXED32 = + FieldDescriptorProto_Type_TYPE_FIXED32; + static constexpr Type TYPE_BOOL = + FieldDescriptorProto_Type_TYPE_BOOL; + static constexpr Type TYPE_STRING = + FieldDescriptorProto_Type_TYPE_STRING; + static constexpr Type TYPE_GROUP = + FieldDescriptorProto_Type_TYPE_GROUP; + static constexpr Type TYPE_MESSAGE = + FieldDescriptorProto_Type_TYPE_MESSAGE; + static constexpr Type TYPE_BYTES = + FieldDescriptorProto_Type_TYPE_BYTES; + static constexpr Type TYPE_UINT32 = + FieldDescriptorProto_Type_TYPE_UINT32; + static constexpr Type TYPE_ENUM = + FieldDescriptorProto_Type_TYPE_ENUM; + static constexpr Type TYPE_SFIXED32 = + FieldDescriptorProto_Type_TYPE_SFIXED32; + static constexpr Type TYPE_SFIXED64 = + FieldDescriptorProto_Type_TYPE_SFIXED64; + static constexpr Type TYPE_SINT32 = + FieldDescriptorProto_Type_TYPE_SINT32; + static constexpr Type TYPE_SINT64 = + FieldDescriptorProto_Type_TYPE_SINT64; static inline bool Type_IsValid(int value) { return FieldDescriptorProto_Type_IsValid(value); } - static constexpr Type Type_MIN = FieldDescriptorProto_Type_Type_MIN; - static constexpr Type Type_MAX = FieldDescriptorProto_Type_Type_MAX; - static constexpr int Type_ARRAYSIZE = FieldDescriptorProto_Type_Type_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Type_descriptor() { + static constexpr Type Type_MIN = + FieldDescriptorProto_Type_Type_MIN; + static constexpr Type Type_MAX = + FieldDescriptorProto_Type_Type_MAX; + static constexpr int Type_ARRAYSIZE = + FieldDescriptorProto_Type_Type_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + Type_descriptor() { return FieldDescriptorProto_Type_descriptor(); } - template - static inline const std::string& Type_Name(T value) { - return FieldDescriptorProto_Type_Name(value); + template + static inline const std::string& Type_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Type_Name."); + return FieldDescriptorProto_Type_Name(enum_t_value); } - static inline bool Type_Parse(absl::string_view name, Type* value) { + static inline bool Type_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + Type* value) { return FieldDescriptorProto_Type_Parse(name, value); } - using Label = FieldDescriptorProto_Label; - static constexpr Label LABEL_OPTIONAL = FieldDescriptorProto_Label_LABEL_OPTIONAL; - static constexpr Label LABEL_REQUIRED = FieldDescriptorProto_Label_LABEL_REQUIRED; - static constexpr Label LABEL_REPEATED = FieldDescriptorProto_Label_LABEL_REPEATED; + typedef FieldDescriptorProto_Label Label; + static constexpr Label LABEL_OPTIONAL = + FieldDescriptorProto_Label_LABEL_OPTIONAL; + static constexpr Label LABEL_REQUIRED = + FieldDescriptorProto_Label_LABEL_REQUIRED; + static constexpr Label LABEL_REPEATED = + FieldDescriptorProto_Label_LABEL_REPEATED; static inline bool Label_IsValid(int value) { return FieldDescriptorProto_Label_IsValid(value); } - static constexpr Label Label_MIN = FieldDescriptorProto_Label_Label_MIN; - static constexpr Label Label_MAX = FieldDescriptorProto_Label_Label_MAX; - static constexpr int Label_ARRAYSIZE = FieldDescriptorProto_Label_Label_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Label_descriptor() { + static constexpr Label Label_MIN = + FieldDescriptorProto_Label_Label_MIN; + static constexpr Label Label_MAX = + FieldDescriptorProto_Label_Label_MAX; + static constexpr int Label_ARRAYSIZE = + FieldDescriptorProto_Label_Label_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + Label_descriptor() { return FieldDescriptorProto_Label_descriptor(); } - template - static inline const std::string& Label_Name(T value) { - return FieldDescriptorProto_Label_Name(value); + template + static inline const std::string& Label_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Label_Name."); + return FieldDescriptorProto_Label_Name(enum_t_value); } - static inline bool Label_Parse(absl::string_view name, Label* value) { + static inline bool Label_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + Label* value) { return FieldDescriptorProto_Label_Parse(name, value); } @@ -2465,7 +2394,8 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT OneofDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofDescriptorProto) */ { @@ -2577,7 +2507,7 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.OneofDescriptorProto"; } protected: @@ -2649,7 +2579,8 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto.EnumReservedRange) */ { @@ -2761,7 +2692,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumDescriptorProto.EnumReservedRange"; } protected: @@ -2823,7 +2754,8 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto) */ { @@ -2935,7 +2867,7 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumDescriptorProto"; } protected: @@ -3075,7 +3007,8 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumValueDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueDescriptorProto) */ { @@ -3187,7 +3120,7 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumValueDescriptorProto"; } protected: @@ -3274,7 +3207,8 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT ServiceDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceDescriptorProto) */ { @@ -3386,7 +3320,7 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.ServiceDescriptorProto"; } protected: @@ -3478,7 +3412,8 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT MethodDescriptorProto final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodDescriptorProto) */ { @@ -3590,7 +3525,7 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.MethodDescriptorProto"; } protected: @@ -3732,7 +3667,8 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT FileOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileOptions) */ { @@ -3844,7 +3780,7 @@ class PROTOBUF_EXPORT FileOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FileOptions"; } protected: @@ -3859,24 +3795,35 @@ class PROTOBUF_EXPORT FileOptions final : // nested types ---------------------------------------------------- - using OptimizeMode = FileOptions_OptimizeMode; - static constexpr OptimizeMode SPEED = FileOptions_OptimizeMode_SPEED; - static constexpr OptimizeMode CODE_SIZE = FileOptions_OptimizeMode_CODE_SIZE; - static constexpr OptimizeMode LITE_RUNTIME = FileOptions_OptimizeMode_LITE_RUNTIME; + typedef FileOptions_OptimizeMode OptimizeMode; + static constexpr OptimizeMode SPEED = + FileOptions_OptimizeMode_SPEED; + static constexpr OptimizeMode CODE_SIZE = + FileOptions_OptimizeMode_CODE_SIZE; + static constexpr OptimizeMode LITE_RUNTIME = + FileOptions_OptimizeMode_LITE_RUNTIME; static inline bool OptimizeMode_IsValid(int value) { return FileOptions_OptimizeMode_IsValid(value); } - static constexpr OptimizeMode OptimizeMode_MIN = FileOptions_OptimizeMode_OptimizeMode_MIN; - static constexpr OptimizeMode OptimizeMode_MAX = FileOptions_OptimizeMode_OptimizeMode_MAX; - static constexpr int OptimizeMode_ARRAYSIZE = FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* OptimizeMode_descriptor() { + static constexpr OptimizeMode OptimizeMode_MIN = + FileOptions_OptimizeMode_OptimizeMode_MIN; + static constexpr OptimizeMode OptimizeMode_MAX = + FileOptions_OptimizeMode_OptimizeMode_MAX; + static constexpr int OptimizeMode_ARRAYSIZE = + FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + OptimizeMode_descriptor() { return FileOptions_OptimizeMode_descriptor(); } - template - static inline const std::string& OptimizeMode_Name(T value) { - return FileOptions_OptimizeMode_Name(value); + template + static inline const std::string& OptimizeMode_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function OptimizeMode_Name."); + return FileOptions_OptimizeMode_Name(enum_t_value); } - static inline bool OptimizeMode_Parse(absl::string_view name, OptimizeMode* value) { + static inline bool OptimizeMode_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + OptimizeMode* value) { return FileOptions_OptimizeMode_Parse(name, value); } @@ -4459,7 +4406,8 @@ class PROTOBUF_EXPORT FileOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT MessageOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MessageOptions) */ { @@ -4571,7 +4519,7 @@ class PROTOBUF_EXPORT MessageOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.MessageOptions"; } protected: @@ -4875,7 +4823,8 @@ class PROTOBUF_EXPORT MessageOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT FieldOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldOptions) */ { @@ -4987,7 +4936,7 @@ class PROTOBUF_EXPORT FieldOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FieldOptions"; } protected: @@ -5002,45 +4951,67 @@ class PROTOBUF_EXPORT FieldOptions final : // nested types ---------------------------------------------------- - using CType = FieldOptions_CType; - static constexpr CType STRING = FieldOptions_CType_STRING; - static constexpr CType CORD = FieldOptions_CType_CORD; - static constexpr CType STRING_PIECE = FieldOptions_CType_STRING_PIECE; + typedef FieldOptions_CType CType; + static constexpr CType STRING = + FieldOptions_CType_STRING; + static constexpr CType CORD = + FieldOptions_CType_CORD; + static constexpr CType STRING_PIECE = + FieldOptions_CType_STRING_PIECE; static inline bool CType_IsValid(int value) { return FieldOptions_CType_IsValid(value); } - static constexpr CType CType_MIN = FieldOptions_CType_CType_MIN; - static constexpr CType CType_MAX = FieldOptions_CType_CType_MAX; - static constexpr int CType_ARRAYSIZE = FieldOptions_CType_CType_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* CType_descriptor() { + static constexpr CType CType_MIN = + FieldOptions_CType_CType_MIN; + static constexpr CType CType_MAX = + FieldOptions_CType_CType_MAX; + static constexpr int CType_ARRAYSIZE = + FieldOptions_CType_CType_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + CType_descriptor() { return FieldOptions_CType_descriptor(); } - template - static inline const std::string& CType_Name(T value) { - return FieldOptions_CType_Name(value); + template + static inline const std::string& CType_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function CType_Name."); + return FieldOptions_CType_Name(enum_t_value); } - static inline bool CType_Parse(absl::string_view name, CType* value) { + static inline bool CType_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + CType* value) { return FieldOptions_CType_Parse(name, value); } - using JSType = FieldOptions_JSType; - static constexpr JSType JS_NORMAL = FieldOptions_JSType_JS_NORMAL; - static constexpr JSType JS_STRING = FieldOptions_JSType_JS_STRING; - static constexpr JSType JS_NUMBER = FieldOptions_JSType_JS_NUMBER; + typedef FieldOptions_JSType JSType; + static constexpr JSType JS_NORMAL = + FieldOptions_JSType_JS_NORMAL; + static constexpr JSType JS_STRING = + FieldOptions_JSType_JS_STRING; + static constexpr JSType JS_NUMBER = + FieldOptions_JSType_JS_NUMBER; static inline bool JSType_IsValid(int value) { return FieldOptions_JSType_IsValid(value); } - static constexpr JSType JSType_MIN = FieldOptions_JSType_JSType_MIN; - static constexpr JSType JSType_MAX = FieldOptions_JSType_JSType_MAX; - static constexpr int JSType_ARRAYSIZE = FieldOptions_JSType_JSType_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* JSType_descriptor() { + static constexpr JSType JSType_MIN = + FieldOptions_JSType_JSType_MIN; + static constexpr JSType JSType_MAX = + FieldOptions_JSType_JSType_MAX; + static constexpr int JSType_ARRAYSIZE = + FieldOptions_JSType_JSType_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + JSType_descriptor() { return FieldOptions_JSType_descriptor(); } - template - static inline const std::string& JSType_Name(T value) { - return FieldOptions_JSType_Name(value); + template + static inline const std::string& JSType_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function JSType_Name."); + return FieldOptions_JSType_Name(enum_t_value); } - static inline bool JSType_Parse(absl::string_view name, JSType* value) { + static inline bool JSType_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + JSType* value) { return FieldOptions_JSType_Parse(name, value); } @@ -5378,7 +5349,8 @@ class PROTOBUF_EXPORT FieldOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT OneofOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofOptions) */ { @@ -5490,7 +5462,7 @@ class PROTOBUF_EXPORT OneofOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.OneofOptions"; } protected: @@ -5733,7 +5705,8 @@ class PROTOBUF_EXPORT OneofOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumOptions) */ { @@ -5845,7 +5818,7 @@ class PROTOBUF_EXPORT EnumOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumOptions"; } protected: @@ -6119,7 +6092,8 @@ class PROTOBUF_EXPORT EnumOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumValueOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueOptions) */ { @@ -6231,7 +6205,7 @@ class PROTOBUF_EXPORT EnumValueOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumValueOptions"; } protected: @@ -6490,7 +6464,8 @@ class PROTOBUF_EXPORT EnumValueOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT ServiceOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceOptions) */ { @@ -6602,7 +6577,7 @@ class PROTOBUF_EXPORT ServiceOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.ServiceOptions"; } protected: @@ -6861,7 +6836,8 @@ class PROTOBUF_EXPORT ServiceOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT MethodOptions final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodOptions) */ { @@ -6973,7 +6949,7 @@ class PROTOBUF_EXPORT MethodOptions final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.MethodOptions"; } protected: @@ -6988,24 +6964,35 @@ class PROTOBUF_EXPORT MethodOptions final : // nested types ---------------------------------------------------- - using IdempotencyLevel = MethodOptions_IdempotencyLevel; - static constexpr IdempotencyLevel IDEMPOTENCY_UNKNOWN = MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN; - static constexpr IdempotencyLevel NO_SIDE_EFFECTS = MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS; - static constexpr IdempotencyLevel IDEMPOTENT = MethodOptions_IdempotencyLevel_IDEMPOTENT; + typedef MethodOptions_IdempotencyLevel IdempotencyLevel; + static constexpr IdempotencyLevel IDEMPOTENCY_UNKNOWN = + MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN; + static constexpr IdempotencyLevel NO_SIDE_EFFECTS = + MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS; + static constexpr IdempotencyLevel IDEMPOTENT = + MethodOptions_IdempotencyLevel_IDEMPOTENT; static inline bool IdempotencyLevel_IsValid(int value) { return MethodOptions_IdempotencyLevel_IsValid(value); } - static constexpr IdempotencyLevel IdempotencyLevel_MIN = MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN; - static constexpr IdempotencyLevel IdempotencyLevel_MAX = MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX; - static constexpr int IdempotencyLevel_ARRAYSIZE = MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* IdempotencyLevel_descriptor() { + static constexpr IdempotencyLevel IdempotencyLevel_MIN = + MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN; + static constexpr IdempotencyLevel IdempotencyLevel_MAX = + MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX; + static constexpr int IdempotencyLevel_ARRAYSIZE = + MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + IdempotencyLevel_descriptor() { return MethodOptions_IdempotencyLevel_descriptor(); } - template - static inline const std::string& IdempotencyLevel_Name(T value) { - return MethodOptions_IdempotencyLevel_Name(value); + template + static inline const std::string& IdempotencyLevel_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function IdempotencyLevel_Name."); + return MethodOptions_IdempotencyLevel_Name(enum_t_value); } - static inline bool IdempotencyLevel_Parse(absl::string_view name, IdempotencyLevel* value) { + static inline bool IdempotencyLevel_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + IdempotencyLevel* value) { return MethodOptions_IdempotencyLevel_Parse(name, value); } @@ -7268,7 +7255,8 @@ class PROTOBUF_EXPORT MethodOptions final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT UninterpretedOption_NamePart final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption.NamePart) */ { @@ -7380,7 +7368,7 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.UninterpretedOption.NamePart"; } protected: @@ -7450,7 +7438,8 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT UninterpretedOption final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption) */ { @@ -7562,7 +7551,7 @@ class PROTOBUF_EXPORT UninterpretedOption final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.UninterpretedOption"; } protected: @@ -7721,7 +7710,8 @@ class PROTOBUF_EXPORT UninterpretedOption final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT SourceCodeInfo_Location final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo.Location) */ { @@ -7833,7 +7823,7 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.SourceCodeInfo.Location"; } protected: @@ -7972,16 +7962,17 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; ::PROTOBUF_NAMESPACE_ID::RepeatedField< int32_t > path_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _path_cached_byte_size_; + mutable std::atomic _path_cached_byte_size_; ::PROTOBUF_NAMESPACE_ID::RepeatedField< int32_t > span_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _span_cached_byte_size_; + mutable std::atomic _span_cached_byte_size_; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField leading_detached_comments_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr leading_comments_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr trailing_comments_; }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT SourceCodeInfo final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo) */ { @@ -8093,7 +8084,7 @@ class PROTOBUF_EXPORT SourceCodeInfo final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.SourceCodeInfo"; } protected: @@ -8146,7 +8137,8 @@ class PROTOBUF_EXPORT SourceCodeInfo final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo.Annotation) */ { @@ -8258,7 +8250,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.GeneratedCodeInfo.Annotation"; } protected: @@ -8273,27 +8265,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : // nested types ---------------------------------------------------- - using Semantic = GeneratedCodeInfo_Annotation_Semantic; - static constexpr Semantic NONE = GeneratedCodeInfo_Annotation_Semantic_NONE; - static constexpr Semantic SET = GeneratedCodeInfo_Annotation_Semantic_SET; - static constexpr Semantic ALIAS = GeneratedCodeInfo_Annotation_Semantic_ALIAS; - static inline bool Semantic_IsValid(int value) { - return GeneratedCodeInfo_Annotation_Semantic_IsValid(value); - } - static constexpr Semantic Semantic_MIN = GeneratedCodeInfo_Annotation_Semantic_Semantic_MIN; - static constexpr Semantic Semantic_MAX = GeneratedCodeInfo_Annotation_Semantic_Semantic_MAX; - static constexpr int Semantic_ARRAYSIZE = GeneratedCodeInfo_Annotation_Semantic_Semantic_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Semantic_descriptor() { - return GeneratedCodeInfo_Annotation_Semantic_descriptor(); - } - template - static inline const std::string& Semantic_Name(T value) { - return GeneratedCodeInfo_Annotation_Semantic_Name(value); - } - static inline bool Semantic_Parse(absl::string_view name, Semantic* value) { - return GeneratedCodeInfo_Annotation_Semantic_Parse(name, value); - } - // accessors ------------------------------------------------------- enum : int { @@ -8301,7 +8272,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : kSourceFileFieldNumber = 2, kBeginFieldNumber = 3, kEndFieldNumber = 4, - kSemanticFieldNumber = 5, }; // repeated int32 path = 1 [packed = true]; int path_size() const; @@ -8369,19 +8339,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : void _internal_set_end(int32_t value); public: - // optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5; - bool has_semantic() const; - private: - bool _internal_has_semantic() const; - public: - void clear_semantic(); - ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic semantic() const; - void set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value); - private: - ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic _internal_semantic() const; - void _internal_set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value); - public: - // @@protoc_insertion_point(class_scope:google.protobuf.GeneratedCodeInfo.Annotation) private: class _Internal; @@ -8393,15 +8350,15 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; ::PROTOBUF_NAMESPACE_ID::RepeatedField< int32_t > path_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _path_cached_byte_size_; + mutable std::atomic _path_cached_byte_size_; ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr source_file_; int32_t begin_; int32_t end_; - int semantic_; }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fdescriptor_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT GeneratedCodeInfo final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo) */ { @@ -8513,7 +8470,7 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.GeneratedCodeInfo"; } protected: @@ -8570,17 +8527,12 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // FileDescriptorSet // repeated .google.protobuf.FileDescriptorProto file = 1; @@ -8674,7 +8626,9 @@ inline std::string* FileDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -8740,7 +8694,9 @@ inline std::string* FileDescriptorProto::release_package() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.package_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.package_.Set("", GetArenaForAllocation()); + if (_impl_.package_.IsDefault()) { + _impl_.package_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -8794,7 +8750,8 @@ inline void FileDescriptorProto::set_dependency(int index, std::string&& value) // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::set_dependency(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.dependency_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.dependency_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { @@ -8814,7 +8771,8 @@ inline void FileDescriptorProto::add_dependency(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::add_dependency(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.dependency_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.dependency_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::add_dependency(const char* value, size_t size) { @@ -9088,7 +9046,7 @@ FileDescriptorProto::extension() const { // optional .google.protobuf.FileOptions options = 8; inline bool FileDescriptorProto::_internal_has_options() const { - bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; PROTOBUF_ASSUME(!value || _impl_.options_ != nullptr); return value; } @@ -9097,7 +9055,7 @@ inline bool FileDescriptorProto::has_options() const { } inline void FileDescriptorProto::clear_options() { if (_impl_.options_ != nullptr) _impl_.options_->Clear(); - _impl_._has_bits_[0] &= ~0x00000010u; + _impl_._has_bits_[0] &= ~0x00000008u; } inline const ::PROTOBUF_NAMESPACE_ID::FileOptions& FileDescriptorProto::_internal_options() const { const ::PROTOBUF_NAMESPACE_ID::FileOptions* p = _impl_.options_; @@ -9115,14 +9073,14 @@ inline void FileDescriptorProto::unsafe_arena_set_allocated_options( } _impl_.options_ = options; if (options) { - _impl_._has_bits_[0] |= 0x00000010u; + _impl_._has_bits_[0] |= 0x00000008u; } else { - _impl_._has_bits_[0] &= ~0x00000010u; + _impl_._has_bits_[0] &= ~0x00000008u; } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.FileDescriptorProto.options) } inline ::PROTOBUF_NAMESPACE_ID::FileOptions* FileDescriptorProto::release_options() { - _impl_._has_bits_[0] &= ~0x00000010u; + _impl_._has_bits_[0] &= ~0x00000008u; ::PROTOBUF_NAMESPACE_ID::FileOptions* temp = _impl_.options_; _impl_.options_ = nullptr; #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE @@ -9138,13 +9096,13 @@ inline ::PROTOBUF_NAMESPACE_ID::FileOptions* FileDescriptorProto::release_option } inline ::PROTOBUF_NAMESPACE_ID::FileOptions* FileDescriptorProto::unsafe_arena_release_options() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.options) - _impl_._has_bits_[0] &= ~0x00000010u; + _impl_._has_bits_[0] &= ~0x00000008u; ::PROTOBUF_NAMESPACE_ID::FileOptions* temp = _impl_.options_; _impl_.options_ = nullptr; return temp; } inline ::PROTOBUF_NAMESPACE_ID::FileOptions* FileDescriptorProto::_internal_mutable_options() { - _impl_._has_bits_[0] |= 0x00000010u; + _impl_._has_bits_[0] |= 0x00000008u; if (_impl_.options_ == nullptr) { auto* p = CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FileOptions>(GetArenaForAllocation()); _impl_.options_ = p; @@ -9168,9 +9126,9 @@ inline void FileDescriptorProto::set_allocated_options(::PROTOBUF_NAMESPACE_ID:: options = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, options, submessage_arena); } - _impl_._has_bits_[0] |= 0x00000010u; + _impl_._has_bits_[0] |= 0x00000008u; } else { - _impl_._has_bits_[0] &= ~0x00000010u; + _impl_._has_bits_[0] &= ~0x00000008u; } _impl_.options_ = options; // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.options) @@ -9178,7 +9136,7 @@ inline void FileDescriptorProto::set_allocated_options(::PROTOBUF_NAMESPACE_ID:: // optional .google.protobuf.SourceCodeInfo source_code_info = 9; inline bool FileDescriptorProto::_internal_has_source_code_info() const { - bool value = (_impl_._has_bits_[0] & 0x00000020u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00000010u) != 0; PROTOBUF_ASSUME(!value || _impl_.source_code_info_ != nullptr); return value; } @@ -9187,7 +9145,7 @@ inline bool FileDescriptorProto::has_source_code_info() const { } inline void FileDescriptorProto::clear_source_code_info() { if (_impl_.source_code_info_ != nullptr) _impl_.source_code_info_->Clear(); - _impl_._has_bits_[0] &= ~0x00000020u; + _impl_._has_bits_[0] &= ~0x00000010u; } inline const ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo& FileDescriptorProto::_internal_source_code_info() const { const ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* p = _impl_.source_code_info_; @@ -9205,14 +9163,14 @@ inline void FileDescriptorProto::unsafe_arena_set_allocated_source_code_info( } _impl_.source_code_info_ = source_code_info; if (source_code_info) { - _impl_._has_bits_[0] |= 0x00000020u; + _impl_._has_bits_[0] |= 0x00000010u; } else { - _impl_._has_bits_[0] &= ~0x00000020u; + _impl_._has_bits_[0] &= ~0x00000010u; } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.FileDescriptorProto.source_code_info) } inline ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { - _impl_._has_bits_[0] &= ~0x00000020u; + _impl_._has_bits_[0] &= ~0x00000010u; ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* temp = _impl_.source_code_info_; _impl_.source_code_info_ = nullptr; #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE @@ -9228,13 +9186,13 @@ inline ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* FileDescriptorProto::release_sou } inline ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* FileDescriptorProto::unsafe_arena_release_source_code_info() { // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.source_code_info) - _impl_._has_bits_[0] &= ~0x00000020u; + _impl_._has_bits_[0] &= ~0x00000010u; ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* temp = _impl_.source_code_info_; _impl_.source_code_info_ = nullptr; return temp; } inline ::PROTOBUF_NAMESPACE_ID::SourceCodeInfo* FileDescriptorProto::_internal_mutable_source_code_info() { - _impl_._has_bits_[0] |= 0x00000020u; + _impl_._has_bits_[0] |= 0x00000010u; if (_impl_.source_code_info_ == nullptr) { auto* p = CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceCodeInfo>(GetArenaForAllocation()); _impl_.source_code_info_ = p; @@ -9258,9 +9216,9 @@ inline void FileDescriptorProto::set_allocated_source_code_info(::PROTOBUF_NAMES source_code_info = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_code_info, submessage_arena); } - _impl_._has_bits_[0] |= 0x00000020u; + _impl_._has_bits_[0] |= 0x00000010u; } else { - _impl_._has_bits_[0] &= ~0x00000020u; + _impl_._has_bits_[0] &= ~0x00000010u; } _impl_.source_code_info_ = source_code_info; // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.source_code_info) @@ -9313,7 +9271,9 @@ inline std::string* FileDescriptorProto::release_syntax() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.syntax_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.syntax_.Set("", GetArenaForAllocation()); + if (_impl_.syntax_.IsDefault()) { + _impl_.syntax_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -9332,72 +9292,6 @@ inline void FileDescriptorProto::set_allocated_syntax(std::string* syntax) { // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.syntax) } -// optional string edition = 13; -inline bool FileDescriptorProto::_internal_has_edition() const { - bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; - return value; -} -inline bool FileDescriptorProto::has_edition() const { - return _internal_has_edition(); -} -inline void FileDescriptorProto::clear_edition() { - _impl_.edition_.ClearToEmpty(); - _impl_._has_bits_[0] &= ~0x00000008u; -} -inline const std::string& FileDescriptorProto::edition() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.edition) - return _internal_edition(); -} -template -inline PROTOBUF_ALWAYS_INLINE -void FileDescriptorProto::set_edition(ArgT0&& arg0, ArgT... args) { - _impl_._has_bits_[0] |= 0x00000008u; - _impl_.edition_.Set(static_cast(arg0), args..., GetArenaForAllocation()); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.edition) -} -inline std::string* FileDescriptorProto::mutable_edition() { - std::string* _s = _internal_mutable_edition(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.edition) - return _s; -} -inline const std::string& FileDescriptorProto::_internal_edition() const { - return _impl_.edition_.Get(); -} -inline void FileDescriptorProto::_internal_set_edition(const std::string& value) { - _impl_._has_bits_[0] |= 0x00000008u; - _impl_.edition_.Set(value, GetArenaForAllocation()); -} -inline std::string* FileDescriptorProto::_internal_mutable_edition() { - _impl_._has_bits_[0] |= 0x00000008u; - return _impl_.edition_.Mutable(GetArenaForAllocation()); -} -inline std::string* FileDescriptorProto::release_edition() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.edition) - if (!_internal_has_edition()) { - return nullptr; - } - _impl_._has_bits_[0] &= ~0x00000008u; - auto* p = _impl_.edition_.Release(); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.edition_.Set("", GetArenaForAllocation()); -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - return p; -} -inline void FileDescriptorProto::set_allocated_edition(std::string* edition) { - if (edition != nullptr) { - _impl_._has_bits_[0] |= 0x00000008u; - } else { - _impl_._has_bits_[0] &= ~0x00000008u; - } - _impl_.edition_.SetAllocated(edition, GetArenaForAllocation()); -#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - if (_impl_.edition_.IsDefault()) { - _impl_.edition_.Set("", GetArenaForAllocation()); - } -#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.edition) -} - // ------------------------------------------------------------------- // DescriptorProto_ExtensionRange @@ -9659,7 +9553,9 @@ inline std::string* DescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10083,7 +9979,8 @@ inline void DescriptorProto::set_reserved_name(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::set_reserved_name(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::set_reserved_name(int index, const char* value, size_t size) { @@ -10103,7 +10000,8 @@ inline void DescriptorProto::add_reserved_name(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::add_reserved_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::add_reserved_name(const char* value, size_t size) { @@ -10216,7 +10114,9 @@ inline std::string* FieldDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10368,7 +10268,9 @@ inline std::string* FieldDescriptorProto::release_type_name() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.type_name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.type_name_.Set("", GetArenaForAllocation()); + if (_impl_.type_name_.IsDefault()) { + _impl_.type_name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10434,7 +10336,9 @@ inline std::string* FieldDescriptorProto::release_extendee() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.extendee_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.extendee_.Set("", GetArenaForAllocation()); + if (_impl_.extendee_.IsDefault()) { + _impl_.extendee_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10500,7 +10404,9 @@ inline std::string* FieldDescriptorProto::release_default_value() { _impl_._has_bits_[0] &= ~0x00000008u; auto* p = _impl_.default_value_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.default_value_.Set("", GetArenaForAllocation()); + if (_impl_.default_value_.IsDefault()) { + _impl_.default_value_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10594,7 +10500,9 @@ inline std::string* FieldDescriptorProto::release_json_name() { _impl_._has_bits_[0] &= ~0x00000010u; auto* p = _impl_.json_name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.json_name_.Set("", GetArenaForAllocation()); + if (_impl_.json_name_.IsDefault()) { + _impl_.json_name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -10782,7 +10690,9 @@ inline std::string* OneofDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11002,7 +10912,9 @@ inline std::string* EnumDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11226,7 +11138,8 @@ inline void EnumDescriptorProto::set_reserved_name(int index, std::string&& valu // @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::set_reserved_name(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.reserved_name_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::set_reserved_name(int index, const char* value, size_t size) { @@ -11246,7 +11159,8 @@ inline void EnumDescriptorProto::add_reserved_name(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::add_reserved_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.reserved_name_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::add_reserved_name(const char* value, size_t size) { @@ -11315,7 +11229,9 @@ inline std::string* EnumValueDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11503,7 +11419,9 @@ inline std::string* ServiceDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11703,7 +11621,9 @@ inline std::string* MethodDescriptorProto::release_name() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_.Set("", GetArenaForAllocation()); + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11769,7 +11689,9 @@ inline std::string* MethodDescriptorProto::release_input_type() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.input_type_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.input_type_.Set("", GetArenaForAllocation()); + if (_impl_.input_type_.IsDefault()) { + _impl_.input_type_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -11835,7 +11757,9 @@ inline std::string* MethodDescriptorProto::release_output_type() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.output_type_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.output_type_.Set("", GetArenaForAllocation()); + if (_impl_.output_type_.IsDefault()) { + _impl_.output_type_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12051,7 +11975,9 @@ inline std::string* FileOptions::release_java_package() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.java_package_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.java_package_.Set("", GetArenaForAllocation()); + if (_impl_.java_package_.IsDefault()) { + _impl_.java_package_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12117,7 +12043,9 @@ inline std::string* FileOptions::release_java_outer_classname() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.java_outer_classname_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.java_outer_classname_.Set("", GetArenaForAllocation()); + if (_impl_.java_outer_classname_.IsDefault()) { + _impl_.java_outer_classname_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12296,7 +12224,9 @@ inline std::string* FileOptions::release_go_package() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.go_package_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.go_package_.Set("", GetArenaForAllocation()); + if (_impl_.go_package_.IsDefault()) { + _impl_.go_package_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12530,7 +12460,9 @@ inline std::string* FileOptions::release_objc_class_prefix() { _impl_._has_bits_[0] &= ~0x00000008u; auto* p = _impl_.objc_class_prefix_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.objc_class_prefix_.Set("", GetArenaForAllocation()); + if (_impl_.objc_class_prefix_.IsDefault()) { + _impl_.objc_class_prefix_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12596,7 +12528,9 @@ inline std::string* FileOptions::release_csharp_namespace() { _impl_._has_bits_[0] &= ~0x00000010u; auto* p = _impl_.csharp_namespace_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.csharp_namespace_.Set("", GetArenaForAllocation()); + if (_impl_.csharp_namespace_.IsDefault()) { + _impl_.csharp_namespace_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12662,7 +12596,9 @@ inline std::string* FileOptions::release_swift_prefix() { _impl_._has_bits_[0] &= ~0x00000020u; auto* p = _impl_.swift_prefix_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.swift_prefix_.Set("", GetArenaForAllocation()); + if (_impl_.swift_prefix_.IsDefault()) { + _impl_.swift_prefix_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12728,7 +12664,9 @@ inline std::string* FileOptions::release_php_class_prefix() { _impl_._has_bits_[0] &= ~0x00000040u; auto* p = _impl_.php_class_prefix_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.php_class_prefix_.Set("", GetArenaForAllocation()); + if (_impl_.php_class_prefix_.IsDefault()) { + _impl_.php_class_prefix_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12794,7 +12732,9 @@ inline std::string* FileOptions::release_php_namespace() { _impl_._has_bits_[0] &= ~0x00000080u; auto* p = _impl_.php_namespace_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.php_namespace_.Set("", GetArenaForAllocation()); + if (_impl_.php_namespace_.IsDefault()) { + _impl_.php_namespace_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12860,7 +12800,9 @@ inline std::string* FileOptions::release_php_metadata_namespace() { _impl_._has_bits_[0] &= ~0x00000100u; auto* p = _impl_.php_metadata_namespace_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.php_metadata_namespace_.Set("", GetArenaForAllocation()); + if (_impl_.php_metadata_namespace_.IsDefault()) { + _impl_.php_metadata_namespace_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -12926,7 +12868,9 @@ inline std::string* FileOptions::release_ruby_package() { _impl_._has_bits_[0] &= ~0x00000200u; auto* p = _impl_.ruby_package_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.ruby_package_.Set("", GetArenaForAllocation()); + if (_impl_.ruby_package_.IsDefault()) { + _impl_.ruby_package_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -13823,7 +13767,9 @@ inline std::string* UninterpretedOption_NamePart::release_name_part() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.name_part_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.name_part_.Set("", GetArenaForAllocation()); + if (_impl_.name_part_.IsDefault()) { + _impl_.name_part_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -13961,7 +13907,9 @@ inline std::string* UninterpretedOption::release_identifier_value() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.identifier_value_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.identifier_value_.Set("", GetArenaForAllocation()); + if (_impl_.identifier_value_.IsDefault()) { + _impl_.identifier_value_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14111,7 +14059,9 @@ inline std::string* UninterpretedOption::release_string_value() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.string_value_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.string_value_.Set("", GetArenaForAllocation()); + if (_impl_.string_value_.IsDefault()) { + _impl_.string_value_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14177,7 +14127,9 @@ inline std::string* UninterpretedOption::release_aggregate_value() { _impl_._has_bits_[0] &= ~0x00000004u; auto* p = _impl_.aggregate_value_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.aggregate_value_.Set("", GetArenaForAllocation()); + if (_impl_.aggregate_value_.IsDefault()) { + _impl_.aggregate_value_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14341,7 +14293,9 @@ inline std::string* SourceCodeInfo_Location::release_leading_comments() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.leading_comments_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.leading_comments_.Set("", GetArenaForAllocation()); + if (_impl_.leading_comments_.IsDefault()) { + _impl_.leading_comments_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14407,7 +14361,9 @@ inline std::string* SourceCodeInfo_Location::release_trailing_comments() { _impl_._has_bits_[0] &= ~0x00000002u; auto* p = _impl_.trailing_comments_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.trailing_comments_.Set("", GetArenaForAllocation()); + if (_impl_.trailing_comments_.IsDefault()) { + _impl_.trailing_comments_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14461,7 +14417,8 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, st // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.leading_detached_comments_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, size_t size) { @@ -14481,7 +14438,8 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(std::string&& // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.leading_detached_comments_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, size_t size) { @@ -14641,7 +14599,9 @@ inline std::string* GeneratedCodeInfo_Annotation::release_source_file() { _impl_._has_bits_[0] &= ~0x00000001u; auto* p = _impl_.source_file_.Release(); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING - _impl_.source_file_.Set("", GetArenaForAllocation()); + if (_impl_.source_file_.IsDefault()) { + _impl_.source_file_.Set("", GetArenaForAllocation()); + } #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING return p; } @@ -14716,35 +14676,6 @@ inline void GeneratedCodeInfo_Annotation::set_end(int32_t value) { // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.end) } -// optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5; -inline bool GeneratedCodeInfo_Annotation::_internal_has_semantic() const { - bool value = (_impl_._has_bits_[0] & 0x00000008u) != 0; - return value; -} -inline bool GeneratedCodeInfo_Annotation::has_semantic() const { - return _internal_has_semantic(); -} -inline void GeneratedCodeInfo_Annotation::clear_semantic() { - _impl_.semantic_ = 0; - _impl_._has_bits_[0] &= ~0x00000008u; -} -inline ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::_internal_semantic() const { - return static_cast< ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic >(_impl_.semantic_); -} -inline ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::semantic() const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.semantic) - return _internal_semantic(); -} -inline void GeneratedCodeInfo_Annotation::_internal_set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value) { - assert(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic_IsValid(value)); - _impl_._has_bits_[0] |= 0x00000008u; - _impl_.semantic_ = value; -} -inline void GeneratedCodeInfo_Annotation::set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value) { - _internal_set_semantic(value); - // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.semantic) -} - // ------------------------------------------------------------------- // GeneratedCodeInfo @@ -14790,62 +14721,101 @@ GeneratedCodeInfo::annotation() const { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type>() { return ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label>() { return ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode>() { return ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::FieldOptions_CType> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::FieldOptions_CType>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType>() { return ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType>() { return ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel>() { return ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel_descriptor(); } -template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic>() { - return ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic_descriptor(); -} PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fdescriptor_2eproto diff --git a/libs/protobuf/src/google/protobuf/descriptor.proto b/libs/protobuf/src/google/protobuf/descriptor.proto index 0636a87..f8eb216 100644 --- a/libs/protobuf/src/google/protobuf/descriptor.proto +++ b/libs/protobuf/src/google/protobuf/descriptor.proto @@ -36,6 +36,7 @@ // A valid .proto file can be translated directly to a FileDescriptorProto // without any other information (e.g. without reading its imports). + syntax = "proto2"; package google.protobuf; @@ -85,13 +86,8 @@ message FileDescriptorProto { optional SourceCodeInfo source_code_info = 9; // The syntax of the proto file. - // The supported values are "proto2", "proto3", and "editions". - // - // If `edition` is present, this value must be "editions". + // The supported values are "proto2" and "proto3". optional string syntax = 12; - - // The edition of the proto file, which is an opaque string. - optional string edition = 13; } // Describes a message type. @@ -133,6 +129,7 @@ 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; } @@ -308,6 +305,7 @@ message MethodDescriptorProto { optional bool server_streaming = 6 [default = false]; } + // =================================================================== // Options @@ -348,6 +346,7 @@ message FileOptions { // domain names. optional string java_package = 1; + // Controls the name of the wrapper Java class generated for the .proto file. // That class will always contain the .proto file's getDescriptor() method as // well as any top-level extensions defined in the .proto file. @@ -374,6 +373,7 @@ message FileOptions { // This option has no effect on when used with the lite runtime. optional bool java_string_check_utf8 = 27 [default = false]; + // Generated classes can be optimized for speed or code size. enum OptimizeMode { SPEED = 1; // Generate complete code for parsing, serialization, @@ -390,6 +390,9 @@ message FileOptions { // - Otherwise, the basename of the .proto file, without extension. optional string go_package = 11; + + + // Should generic services be generated in each language? "Generic" services // are not specific to any particular RPC system. They are generated by the // main code generators in each language (without additional plugins). @@ -415,6 +418,7 @@ message FileOptions { // only to generated classes for C++. optional bool cc_enable_arenas = 31 [default = true]; + // Sets the objective c class prefix which is prepended to all objective c // generated classes from this .proto. There is no default. optional string objc_class_prefix = 36; @@ -447,6 +451,7 @@ message FileOptions { // determining the ruby package. optional string ruby_package = 45; + // The parser stores options it doesn't recognize here. // See the documentation for the "Options" section above. repeated UninterpretedOption uninterpreted_option = 999; @@ -492,10 +497,6 @@ message MessageOptions { reserved 4, 5, 6; - // NOTE: Do not set the option in .proto files. Always use the maps syntax - // instead. The option should only be implicitly set by the proto compiler - // parser. - // // Whether the message is an automatically generated map entry type for the // maps field. // @@ -513,11 +514,16 @@ message MessageOptions { // use a native map in the target language to hold the keys and values. // The reflection APIs in such implementations still need to work as // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. optional bool map_entry = 7; reserved 8; // javalite_serializable reserved 9; // javanano_as_lite + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -586,6 +592,7 @@ message FieldOptions { // call from multiple threads concurrently, while non-const methods continue // to require exclusive access. // + // // Note that implementations may choose not to check required fields within // a lazy sub-message. That is, calling IsInitialized() on the outer message // may return true even if the inner message has missing required fields. @@ -597,8 +604,11 @@ message FieldOptions { // check its required fields, regardless of whether or not the message has // been parsed. // - // As of May 2022, lazy verifies the contents of the byte stream during - // parsing. An invalid byte stream will cause the overall parsing to fail. + // As of 2021, lazy does no correctness checks on the byte stream during + // parsing. This may lead to crashes if and when an invalid byte stream is + // finally parsed upon access. + // + // TODO(b/211906113): Enable validation on lazy fields. optional bool lazy = 5 [default = false]; // unverified_lazy does no correctness checks on the byte stream. This should @@ -615,6 +625,7 @@ message FieldOptions { // For Google-internal migration only. Do not use. optional bool weak = 10 [default = false]; + // The parser stores options it doesn't recognize here. See above. repeated UninterpretedOption uninterpreted_option = 999; @@ -718,6 +729,7 @@ message MethodOptions { extensions 1000 to max; } + // A message representing a option the parser does not recognize. This only // appears in options protos created by the compiler::Parser class. // DescriptorPool resolves these when building Descriptor objects. Therefore, @@ -902,20 +914,8 @@ message GeneratedCodeInfo { optional int32 begin = 3; // Identifies the ending offset in bytes in the generated code that - // relates to the identified object. The end offset should be one past + // relates to the identified offset. The end offset should be one past // the last relevant byte (so the length of the text = end - begin). optional int32 end = 4; - - // Represents the identified object's effect on the element in the original - // .proto file. - enum Semantic { - // There is no effect or the effect is indescribable. - NONE = 0; - // The element is set or otherwise mutated. - SET = 1; - // An alias to the element is returned. - ALIAS = 2; - } - optional Semantic semantic = 5; } } diff --git a/libs/protobuf/src/google/protobuf/descriptor_database.cc b/libs/protobuf/src/google/protobuf/descriptor_database.cc index 5e0d6c3..203000d 100644 --- a/libs/protobuf/src/google/protobuf/descriptor_database.cc +++ b/libs/protobuf/src/google/protobuf/descriptor_database.cc @@ -32,16 +32,14 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/descriptor_database.h" +#include #include #include -#include -#include "absl/strings/ascii.h" -#include "absl/strings/match.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include namespace google { @@ -54,7 +52,7 @@ void RecordMessageNames(const DescriptorProto& desc_proto, GOOGLE_CHECK(desc_proto.has_name()); std::string full_name = prefix.empty() ? desc_proto.name() - : absl::StrCat(prefix, ".", desc_proto.name()); + : StrCat(prefix, ".", desc_proto.name()); output->insert(full_name); for (const auto& d : desc_proto.nested_type()) { @@ -119,7 +117,7 @@ SimpleDescriptorDatabase::~SimpleDescriptorDatabase() {} template bool SimpleDescriptorDatabase::DescriptorIndex::AddFile( const FileDescriptorProto& file, Value value) { - if (!by_name_.insert({file.name(), value}).second) { + if (!InsertIfNotPresent(&by_name_, file.name(), value)) { GOOGLE_LOG(ERROR) << "File already exists in database: " << file.name(); return false; } @@ -153,7 +151,7 @@ namespace { // Returns true if and only if all characters in the name are alphanumerics, // underscores, or periods. -bool ValidateSymbolName(absl::string_view name) { +bool ValidateSymbolName(StringPiece name) { for (char c : name) { // I don't trust ctype.h due to locales. :( if (c != '.' && c != '_' && (c < '0' || c > '9') && (c < 'A' || c > 'Z') && @@ -187,9 +185,9 @@ typename Container::const_iterator FindLastLessOrEqual( // True if either the arguments are equal or super_symbol identifies a // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of // "foo.bar.baz", but not a parent of "foo.barbaz"). -bool IsSubSymbol(absl::string_view sub_symbol, absl::string_view super_symbol) { +bool IsSubSymbol(StringPiece sub_symbol, StringPiece super_symbol) { return sub_symbol == super_symbol || - (absl::StartsWith(super_symbol, sub_symbol) && + (HasPrefixString(super_symbol, sub_symbol) && super_symbol[sub_symbol.size()] == '.'); } @@ -273,11 +271,10 @@ bool SimpleDescriptorDatabase::DescriptorIndex::AddExtension( if (!field.extendee().empty() && field.extendee()[0] == '.') { // The extension is fully-qualified. We can use it as a lookup key in // the by_symbol_ table. - if (!by_extension_ - .insert( - {std::make_pair(field.extendee().substr(1), field.number()), - value}) - .second) { + if (!InsertIfNotPresent( + &by_extension_, + std::make_pair(field.extendee().substr(1), field.number()), + value)) { GOOGLE_LOG(ERROR) << "Extension conflicts with extension already in database: " "extend " << field.extendee() << " { " << field.name() << " = " @@ -295,9 +292,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex::AddExtension( template Value SimpleDescriptorDatabase::DescriptorIndex::FindFile( const std::string& filename) { - auto it = by_name_.find(filename); - if (it == by_name_.end()) return {}; - return it->second; + return FindWithDefault(by_name_, filename, Value()); } template @@ -313,9 +308,8 @@ Value SimpleDescriptorDatabase::DescriptorIndex::FindSymbol( template Value SimpleDescriptorDatabase::DescriptorIndex::FindExtension( const std::string& containing_type, int field_number) { - auto it = by_extension_.find({containing_type, field_number}); - if (it == by_extension_.end()) return {}; - return it->second; + return FindWithDefault( + by_extension_, std::make_pair(containing_type, field_number), Value()); } template @@ -358,10 +352,6 @@ bool SimpleDescriptorDatabase::AddAndOwn(const FileDescriptorProto* file) { return index_.AddFile(*file, file); } -bool SimpleDescriptorDatabase::AddUnowned(const FileDescriptorProto* file) { - return index_.AddFile(*file, file); -} - bool SimpleDescriptorDatabase::FindFileByName(const std::string& filename, FileDescriptorProto* output) { return MaybeCopy(index_.FindFile(filename), output); @@ -407,24 +397,24 @@ class EncodedDescriptorDatabase::DescriptorIndex { template bool AddFile(const FileProto& file, Value value); - Value FindFile(absl::string_view filename); - Value FindSymbol(absl::string_view name); - Value FindSymbolOnlyFlat(absl::string_view name) const; - Value FindExtension(absl::string_view containing_type, int field_number); - bool FindAllExtensionNumbers(absl::string_view containing_type, + Value FindFile(StringPiece filename); + Value FindSymbol(StringPiece name); + Value FindSymbolOnlyFlat(StringPiece name) const; + Value FindExtension(StringPiece containing_type, int field_number); + bool FindAllExtensionNumbers(StringPiece containing_type, std::vector* output); void FindAllFileNames(std::vector* output) const; private: friend class EncodedDescriptorDatabase; - bool AddSymbol(absl::string_view symbol); + bool AddSymbol(StringPiece symbol); template - bool AddNestedExtensions(absl::string_view filename, + bool AddNestedExtensions(StringPiece filename, const DescProto& message_type); template - bool AddExtension(absl::string_view filename, const FieldProto& field); + bool AddExtension(StringPiece filename, const FieldProto& field); // All the maps below have two representations: // - a std::set<> where we insert initially. @@ -437,8 +427,8 @@ class EncodedDescriptorDatabase::DescriptorIndex { using String = std::string; - String EncodeString(absl::string_view str) const { return String(str); } - absl::string_view DecodeString(const String& str, int) const { return str; } + String EncodeString(StringPiece str) const { return String(str); } + StringPiece DecodeString(const String& str, int) const { return str; } struct EncodedEntry { // Do not use `Value` here to avoid the padding of that object. @@ -455,7 +445,7 @@ class EncodedDescriptorDatabase::DescriptorIndex { int data_offset; String encoded_name; - absl::string_view name(const DescriptorIndex& index) const { + StringPiece name(const DescriptorIndex& index) const { return index.DecodeString(encoded_name, data_offset); } }; @@ -465,10 +455,10 @@ class EncodedDescriptorDatabase::DescriptorIndex { bool operator()(const FileEntry& a, const FileEntry& b) const { return a.name(index) < b.name(index); } - bool operator()(const FileEntry& a, absl::string_view b) const { + bool operator()(const FileEntry& a, StringPiece b) const { return a.name(index) < b; } - bool operator()(absl::string_view a, const FileEntry& b) const { + bool operator()(StringPiece a, const FileEntry& b) const { return a < b.name(index); } }; @@ -479,17 +469,17 @@ class EncodedDescriptorDatabase::DescriptorIndex { int data_offset; String encoded_symbol; - absl::string_view package(const DescriptorIndex& index) const { + StringPiece package(const DescriptorIndex& index) const { return index.DecodeString(index.all_values_[data_offset].encoded_package, data_offset); } - absl::string_view symbol(const DescriptorIndex& index) const { + StringPiece symbol(const DescriptorIndex& index) const { return index.DecodeString(encoded_symbol, data_offset); } std::string AsString(const DescriptorIndex& index) const { auto p = package(index); - return absl::StrCat(p, p.empty() ? "" : ".", symbol(index)); + return StrCat(p, p.empty() ? "" : ".", symbol(index)); } }; @@ -499,16 +489,16 @@ class EncodedDescriptorDatabase::DescriptorIndex { std::string AsString(const SymbolEntry& entry) const { return entry.AsString(index); } - static absl::string_view AsString(absl::string_view str) { return str; } + static StringPiece AsString(StringPiece str) { return str; } - std::pair GetParts( + std::pair GetParts( const SymbolEntry& entry) const { auto package = entry.package(index); - if (package.empty()) return {entry.symbol(index), absl::string_view{}}; + if (package.empty()) return {entry.symbol(index), StringPiece{}}; return {package, entry.symbol(index)}; } - std::pair GetParts( - absl::string_view str) const { + std::pair GetParts( + StringPiece str) const { return {str, {}}; } @@ -535,7 +525,7 @@ class EncodedDescriptorDatabase::DescriptorIndex { struct ExtensionEntry { int data_offset; String encoded_extendee; - absl::string_view extendee(const DescriptorIndex& index) const { + StringPiece extendee(const DescriptorIndex& index) const { return index.DecodeString(encoded_extendee, data_offset).substr(1); } int extension_number; @@ -548,10 +538,10 @@ class EncodedDescriptorDatabase::DescriptorIndex { std::make_tuple(b.extendee(index), b.extension_number); } bool operator()(const ExtensionEntry& a, - std::tuple b) const { + std::tuple b) const { return std::make_tuple(a.extendee(index), a.extension_number) < b; } - bool operator()(std::tuple a, + bool operator()(std::tuple a, const ExtensionEntry& b) const { return a < std::make_tuple(b.extendee(index), b.extension_number); } @@ -644,10 +634,9 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddFile(const FileProto& file, } all_values_.back().encoded_package = EncodeString(file.package()); - if (!by_name_ - .insert({static_cast(all_values_.size() - 1), - EncodeString(file.name())}) - .second || + if (!InsertIfNotPresent( + &by_name_, FileEntry{static_cast(all_values_.size() - 1), + EncodeString(file.name())}) || std::binary_search(by_name_flat_.begin(), by_name_flat_.end(), file.name(), by_name_.key_comp())) { GOOGLE_LOG(ERROR) << "File already exists in database: " << file.name(); @@ -673,7 +662,7 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddFile(const FileProto& file, } template -static bool CheckForMutualSubsymbols(absl::string_view symbol_name, Iter* iter, +static bool CheckForMutualSubsymbols(StringPiece symbol_name, Iter* iter, Iter2 end, const Index& index) { if (*iter != end) { if (IsSubSymbol((*iter)->AsString(index), symbol_name)) { @@ -701,7 +690,7 @@ static bool CheckForMutualSubsymbols(absl::string_view symbol_name, Iter* iter, } bool EncodedDescriptorDatabase::DescriptorIndex::AddSymbol( - absl::string_view symbol) { + StringPiece symbol) { SymbolEntry entry = {static_cast(all_values_.size() - 1), EncodeString(symbol)}; std::string entry_as_string = entry.AsString(*this); @@ -741,7 +730,7 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddSymbol( template bool EncodedDescriptorDatabase::DescriptorIndex::AddNestedExtensions( - absl::string_view filename, const DescProto& message_type) { + StringPiece filename, const DescProto& message_type) { for (const auto& nested_type : message_type.nested_type()) { if (!AddNestedExtensions(filename, nested_type)) return false; } @@ -753,14 +742,14 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddNestedExtensions( template bool EncodedDescriptorDatabase::DescriptorIndex::AddExtension( - absl::string_view filename, const FieldProto& field) { + StringPiece filename, const FieldProto& field) { if (!field.extendee().empty() && field.extendee()[0] == '.') { // The extension is fully-qualified. We can use it as a lookup key in // the by_symbol_ table. - if (!by_extension_ - .insert({static_cast(all_values_.size() - 1), - EncodeString(field.extendee()), field.number()}) - .second || + if (!InsertIfNotPresent( + &by_extension_, + ExtensionEntry{static_cast(all_values_.size() - 1), + EncodeString(field.extendee()), field.number()}) || std::binary_search( by_extension_flat_.begin(), by_extension_flat_.end(), std::make_pair(field.extendee().substr(1), field.number()), @@ -780,14 +769,14 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddExtension( } std::pair -EncodedDescriptorDatabase::DescriptorIndex::FindSymbol(absl::string_view name) { +EncodedDescriptorDatabase::DescriptorIndex::FindSymbol(StringPiece name) { EnsureFlat(); return FindSymbolOnlyFlat(name); } std::pair EncodedDescriptorDatabase::DescriptorIndex::FindSymbolOnlyFlat( - absl::string_view name) const { + StringPiece name) const { auto iter = FindLastLessOrEqual(&by_symbol_flat_, name, by_symbol_.key_comp()); @@ -799,7 +788,7 @@ EncodedDescriptorDatabase::DescriptorIndex::FindSymbolOnlyFlat( std::pair EncodedDescriptorDatabase::DescriptorIndex::FindExtension( - absl::string_view containing_type, int field_number) { + StringPiece containing_type, int field_number) { EnsureFlat(); auto it = std::lower_bound( @@ -831,7 +820,7 @@ void EncodedDescriptorDatabase::DescriptorIndex::EnsureFlat() { } bool EncodedDescriptorDatabase::DescriptorIndex::FindAllExtensionNumbers( - absl::string_view containing_type, std::vector* output) { + StringPiece containing_type, std::vector* output) { EnsureFlat(); bool success = false; @@ -864,7 +853,7 @@ void EncodedDescriptorDatabase::DescriptorIndex::FindAllFileNames( std::pair EncodedDescriptorDatabase::DescriptorIndex::FindFile( - absl::string_view filename) { + StringPiece filename) { EnsureFlat(); auto it = std::lower_bound(by_name_flat_.begin(), by_name_flat_.end(), diff --git a/libs/protobuf/src/google/protobuf/descriptor_database.h b/libs/protobuf/src/google/protobuf/descriptor_database.h index 942f975..f4f06bb 100644 --- a/libs/protobuf/src/google/protobuf/descriptor_database.h +++ b/libs/protobuf/src/google/protobuf/descriptor_database.h @@ -43,11 +43,11 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/port.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -74,8 +74,6 @@ class MergedDescriptorDatabase; class PROTOBUF_EXPORT DescriptorDatabase { public: inline DescriptorDatabase() {} - DescriptorDatabase(const DescriptorDatabase&) = delete; - DescriptorDatabase& operator=(const DescriptorDatabase&) = delete; virtual ~DescriptorDatabase(); // Find a file by file name. Fills in in *output and returns true if found. @@ -138,6 +136,9 @@ class PROTOBUF_EXPORT DescriptorDatabase { // searching all message names, otherwise returns false and leaves output // unchanged. bool FindAllMessageNames(std::vector* output); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); }; // A DescriptorDatabase into which you can insert files manually. @@ -164,8 +165,6 @@ class PROTOBUF_EXPORT DescriptorDatabase { class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { public: SimpleDescriptorDatabase(); - SimpleDescriptorDatabase(const SimpleDescriptorDatabase&) = delete; - SimpleDescriptorDatabase& operator=(const SimpleDescriptorDatabase&) = delete; ~SimpleDescriptorDatabase() override; // Adds the FileDescriptorProto to the database, making a copy. The object @@ -177,10 +176,6 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { // Adds the FileDescriptorProto to the database and takes ownership of it. bool AddAndOwn(const FileDescriptorProto* file); - // Adds the FileDescriptorProto to the database and not take ownership of it. - // The owner must ensure file outlives the SimpleDescriptorDatabase. - bool AddUnowned(const FileDescriptorProto* file); - // implements DescriptorDatabase ----------------------------------- bool FindFileByName(const std::string& filename, FileDescriptorProto* output) override; @@ -279,6 +274,8 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { // If file is non-nullptr, copy it into *output and return true, otherwise // return false. bool MaybeCopy(const FileDescriptorProto* file, FileDescriptorProto* output); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase); }; // Very similar to SimpleDescriptorDatabase, but stores all the descriptors @@ -289,9 +286,6 @@ class PROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { public: EncodedDescriptorDatabase(); - EncodedDescriptorDatabase(const EncodedDescriptorDatabase&) = delete; - EncodedDescriptorDatabase& operator=(const EncodedDescriptorDatabase&) = - delete; ~EncodedDescriptorDatabase() override; // Adds the FileDescriptorProto to the database. The descriptor is provided @@ -333,14 +327,14 @@ class PROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { // return true, otherwise return false. bool MaybeParse(std::pair encoded_file, FileDescriptorProto* output); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase); }; // A DescriptorDatabase that fetches files from a given pool. class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { public: explicit DescriptorPoolDatabase(const DescriptorPool& pool); - DescriptorPoolDatabase(const DescriptorPoolDatabase&) = delete; - DescriptorPoolDatabase& operator=(const DescriptorPoolDatabase&) = delete; ~DescriptorPoolDatabase() override; // implements DescriptorDatabase ----------------------------------- @@ -356,6 +350,7 @@ class PROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { private: const DescriptorPool& pool_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase); }; // A DescriptorDatabase that wraps two or more others. It first searches the @@ -370,8 +365,6 @@ class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { // DescriptorDatabases need to stick around. explicit MergedDescriptorDatabase( const std::vector& sources); - MergedDescriptorDatabase(const MergedDescriptorDatabase&) = delete; - MergedDescriptorDatabase& operator=(const MergedDescriptorDatabase&) = delete; ~MergedDescriptorDatabase() override; // implements DescriptorDatabase ----------------------------------- @@ -394,11 +387,12 @@ class PROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { private: std::vector sources_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase); }; } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ diff --git a/libs/protobuf/src/google/protobuf/descriptor_database_unittest.cc b/libs/protobuf/src/google/protobuf/descriptor_database_unittest.cc index d06d0c0..f582448 100644 --- a/libs/protobuf/src/google/protobuf/descriptor_database_unittest.cc +++ b/libs/protobuf/src/google/protobuf/descriptor_database_unittest.cc @@ -34,18 +34,18 @@ // // This file makes extensive use of RFC 3092. :) -#include "google/protobuf/descriptor_database.h" +#include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/text_format.h" +#include +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include @@ -572,29 +572,6 @@ TEST(SimpleDescriptorDatabaseExtraTest, FindAllMessageNames) { EXPECT_THAT(messages, ::testing::UnorderedElementsAre("foo.Foo", "Bar")); } -TEST(SimpleDescriptorDatabaseExtraTest, AddUnowned) { - FileDescriptorProto f; - f.set_name("foo.proto"); - f.set_package("foo"); - f.add_message_type()->set_name("Foo"); - - FileDescriptorProto b; - b.set_name("bar.proto"); - b.set_package(""); - b.add_message_type()->set_name("Bar"); - - SimpleDescriptorDatabase db; - db.AddUnowned(&f); - db.AddUnowned(&b); - - std::vector packages; - EXPECT_TRUE(db.FindAllPackageNames(&packages)); - EXPECT_THAT(packages, ::testing::UnorderedElementsAre("foo", "")); - std::vector messages; - EXPECT_TRUE(db.FindAllMessageNames(&messages)); - EXPECT_THAT(messages, ::testing::UnorderedElementsAre("foo.Foo", "Bar")); -} - // =================================================================== class MergedDescriptorDatabaseTest : public testing::Test { diff --git a/libs/protobuf/src/google/protobuf/descriptor_unittest.cc b/libs/protobuf/src/google/protobuf/descriptor_unittest.cc index ab187ae..dc47531 100644 --- a/libs/protobuf/src/google/protobuf/descriptor_unittest.cc +++ b/libs/protobuf/src/google/protobuf/descriptor_unittest.cc @@ -38,34 +38,33 @@ #include #include -#include "google/protobuf/any.pb.h" -#include "google/protobuf/compiler/importer.h" -#include "google/protobuf/compiler/parser.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "absl/strings/str_format.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/unittest_lazy_dependencies.pb.h" -#include "google/protobuf/unittest_proto3_arena.pb.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/dynamic_message.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/stubs/strutil.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/substitute.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include using ::testing::AnyOf; @@ -248,7 +247,7 @@ class MockErrorCollector : public DescriptorPool::ErrorCollector { break; } - absl::SubstituteAndAppend(&text_, "$0: $1: $2: $3\n", filename, + strings::SubstituteAndAppend(&text_, "$0: $1: $2: $3\n", filename, element_name, location_name, message); } @@ -293,7 +292,7 @@ class MockErrorCollector : public DescriptorPool::ErrorCollector { break; } - absl::SubstituteAndAppend(&warning_text_, "$0: $1: $2: $3\n", filename, + strings::SubstituteAndAppend(&warning_text_, "$0: $1: $2: $3\n", filename, element_name, location_name, message); } }; @@ -554,29 +553,6 @@ TEST_F(FileDescriptorTest, Syntax) { } } -TEST_F(FileDescriptorTest, CopyHeadingTo) { - FileDescriptorProto proto; - proto.set_name("foo.proto"); - proto.set_package("foo.bar.baz"); - proto.set_syntax("proto3"); - proto.mutable_options()->set_java_package("foo.bar.baz"); - - // Won't be copied. - proto.add_message_type()->set_name("Foo"); - - DescriptorPool pool; - const FileDescriptor* file = pool.BuildFile(proto); - ASSERT_NE(file, nullptr); - - FileDescriptorProto other; - file->CopyHeadingTo(&other); - EXPECT_EQ(other.name(), "foo.proto"); - EXPECT_EQ(other.package(), "foo.bar.baz"); - EXPECT_EQ(other.syntax(), "proto3"); - EXPECT_EQ(other.options().java_package(), "foo.bar.baz"); - EXPECT_TRUE(other.message_type().empty()); -} - void ExtractDebugString( const FileDescriptor* file, std::set* visited, std::vector>* debug_strings) { @@ -593,7 +569,7 @@ class SimpleErrorCollector : public io::ErrorCollector { public: // implements ErrorCollector --------------------------------------- void AddError(int line, int column, const std::string& message) override { - last_error_ = absl::StrFormat("%d:%d:%s", line, column, message); + last_error_ = StringPrintf("%d:%d:", line, column) + message; } const std::string& last_error() { return last_error_; } @@ -1087,34 +1063,6 @@ TEST_F(DescriptorTest, FieldLabel) { EXPECT_TRUE(baz_->is_repeated()); } -TEST_F(DescriptorTest, NeedsUtf8Check) { - EXPECT_FALSE(foo_->requires_utf8_validation()); - EXPECT_FALSE(bar_->requires_utf8_validation()); - - // Build a copy of the file in proto3. - FileDescriptorProto foo_file3; - foo_file_->CopyTo(&foo_file3); - foo_file3.set_syntax("proto3"); - - // Make this valid proto3 by removing `required` and the one group field. - for (auto& f : *foo_file3.mutable_message_type(1)->mutable_field()) { - f.clear_label(); - if (f.type() == FieldDescriptorProto::TYPE_GROUP) { - f.set_type(FieldDescriptorProto::TYPE_MESSAGE); - } - } - // Make this valid proto3 by making the first enum value be zero. - foo_file3.mutable_enum_type(0)->mutable_value(0)->set_number(0); - - DescriptorPool pool3; - const Descriptor* message3 = pool3.BuildFile(foo_file3)->message_type(1); - const FieldDescriptor* foo3 = message3->field(0); - const FieldDescriptor* bar3 = message3->field(1); - - EXPECT_TRUE(foo3->requires_utf8_validation()); - EXPECT_FALSE(bar3->requires_utf8_validation()); -} - TEST_F(DescriptorTest, IsMap) { EXPECT_TRUE(map_->is_map()); EXPECT_FALSE(baz_->is_map()); @@ -1587,23 +1535,6 @@ TEST_F(EnumDescriptorTest, ValueType) { EXPECT_EQ(enum2_, baz2_->type()); } -TEST_F(EnumDescriptorTest, IsClosed) { - // enum_ is proto2. - EXPECT_TRUE(enum_->is_closed()); - - // Make a proto3 version of enum_. - FileDescriptorProto foo_file3; - foo_file_->CopyTo(&foo_file3); - foo_file3.set_syntax("proto3"); - - // Make this valid proto3 by making the first enum value be zero. - foo_file3.mutable_enum_type(0)->mutable_value(0)->set_number(0); - - DescriptorPool pool3; - const EnumDescriptor* enum3 = pool3.BuildFile(foo_file3)->enum_type(0); - EXPECT_FALSE(enum3->is_closed()); -} - // =================================================================== // Test service descriptors. @@ -2775,19 +2706,15 @@ TEST_F(MiscTest, DefaultValues) { ->set_default_value("hello"); AddField(message_proto, "data", 9, label, FD::TYPE_BYTES) ->set_default_value("\\001\\002\\003"); - AddField(message_proto, "data2", 10, label, FD::TYPE_BYTES) - ->set_default_value("\\X01\\X2\\X3"); - AddField(message_proto, "data3", 11, label, FD::TYPE_BYTES) - ->set_default_value("\\x01\\x2\\x3"); FieldDescriptorProto* enum_field = - AddField(message_proto, "enum", 12, label, FD::TYPE_ENUM); + AddField(message_proto, "enum", 10, label, FD::TYPE_ENUM); enum_field->set_type_name("DummyEnum"); enum_field->set_default_value("B"); // Strings are allowed to have empty defaults. (At one point, due to // a bug, empty defaults for strings were rejected. Oops.) - AddField(message_proto, "empty_string", 13, label, FD::TYPE_STRING) + AddField(message_proto, "empty_string", 11, label, FD::TYPE_STRING) ->set_default_value(""); // Add a second set of fields with implicit default values. @@ -2817,7 +2744,7 @@ TEST_F(MiscTest, DefaultValues) { ASSERT_EQ(1, file->message_type_count()); const Descriptor* message = file->message_type(0); - ASSERT_EQ(23, message->field_count()); + ASSERT_EQ(21, message->field_count()); // Check the default values. ASSERT_TRUE(message->field(0)->has_default_value()); @@ -2831,8 +2758,6 @@ TEST_F(MiscTest, DefaultValues) { ASSERT_TRUE(message->field(8)->has_default_value()); ASSERT_TRUE(message->field(9)->has_default_value()); ASSERT_TRUE(message->field(10)->has_default_value()); - ASSERT_TRUE(message->field(11)->has_default_value()); - ASSERT_TRUE(message->field(12)->has_default_value()); EXPECT_EQ(-1, message->field(0)->default_value_int32()); EXPECT_EQ(int64_t{-1000000000000}, message->field(1)->default_value_int64()); @@ -2843,11 +2768,11 @@ TEST_F(MiscTest, DefaultValues) { EXPECT_TRUE(message->field(6)->default_value_bool()); EXPECT_EQ("hello", message->field(7)->default_value_string()); EXPECT_EQ("\001\002\003", message->field(8)->default_value_string()); - EXPECT_EQ("\001\002\003", message->field(9)->default_value_string()); - EXPECT_EQ("\001\002\003", message->field(10)->default_value_string()); - EXPECT_EQ(enum_value_b, message->field(11)->default_value_enum()); - EXPECT_EQ("", message->field(12)->default_value_string()); + EXPECT_EQ(enum_value_b, message->field(9)->default_value_enum()); + EXPECT_EQ("", message->field(10)->default_value_string()); + ASSERT_FALSE(message->field(11)->has_default_value()); + ASSERT_FALSE(message->field(12)->has_default_value()); ASSERT_FALSE(message->field(13)->has_default_value()); ASSERT_FALSE(message->field(14)->has_default_value()); ASSERT_FALSE(message->field(15)->has_default_value()); @@ -2856,19 +2781,17 @@ TEST_F(MiscTest, DefaultValues) { ASSERT_FALSE(message->field(18)->has_default_value()); ASSERT_FALSE(message->field(19)->has_default_value()); ASSERT_FALSE(message->field(20)->has_default_value()); - ASSERT_FALSE(message->field(21)->has_default_value()); - ASSERT_FALSE(message->field(22)->has_default_value()); - EXPECT_EQ(0, message->field(13)->default_value_int32()); - EXPECT_EQ(0, message->field(14)->default_value_int64()); - EXPECT_EQ(0, message->field(15)->default_value_uint32()); - EXPECT_EQ(0, message->field(16)->default_value_uint64()); - EXPECT_EQ(0.0f, message->field(17)->default_value_float()); - EXPECT_EQ(0.0, message->field(18)->default_value_double()); - EXPECT_FALSE(message->field(19)->default_value_bool()); - EXPECT_EQ("", message->field(20)->default_value_string()); - EXPECT_EQ("", message->field(21)->default_value_string()); - EXPECT_EQ(enum_value_a, message->field(22)->default_value_enum()); + EXPECT_EQ(0, message->field(11)->default_value_int32()); + EXPECT_EQ(0, message->field(12)->default_value_int64()); + EXPECT_EQ(0, message->field(13)->default_value_uint32()); + EXPECT_EQ(0, message->field(14)->default_value_uint64()); + EXPECT_EQ(0.0f, message->field(15)->default_value_float()); + EXPECT_EQ(0.0, message->field(16)->default_value_double()); + EXPECT_FALSE(message->field(17)->default_value_bool()); + EXPECT_EQ("", message->field(18)->default_value_string()); + EXPECT_EQ("", message->field(19)->default_value_string()); + EXPECT_EQ(enum_value_a, message->field(20)->default_value_enum()); } TEST_F(MiscTest, FieldOptions) { @@ -4321,7 +4244,7 @@ TEST_F(ValidationErrorTest, ReservedFieldsDebugString) { } TEST_F(ValidationErrorTest, DebugStringReservedRangeMax) { - const FileDescriptor* file = BuildFile(absl::Substitute( + const FileDescriptor* file = BuildFile(strings::Substitute( "name: \"foo.proto\" " "enum_type { " " name: \"Bar\"" @@ -5371,7 +5294,8 @@ TEST_F(ValidationErrorTest, InputTypeNotDefined) { " method { name: \"A\" input_type: \"Bar\" output_type: \"Foo\" }" "}", - "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not defined.\n"); + "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not defined.\n" + ); } TEST_F(ValidationErrorTest, InputTypeNotAMessage) { @@ -5384,7 +5308,8 @@ TEST_F(ValidationErrorTest, InputTypeNotAMessage) { " method { name: \"A\" input_type: \"Bar\" output_type: \"Foo\" }" "}", - "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not a message type.\n"); + "foo.proto: TestService.A: INPUT_TYPE: \"Bar\" is not a message type.\n" + ); } TEST_F(ValidationErrorTest, OutputTypeNotDefined) { @@ -5396,7 +5321,8 @@ TEST_F(ValidationErrorTest, OutputTypeNotDefined) { " method { name: \"A\" input_type: \"Foo\" output_type: \"Bar\" }" "}", - "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not defined.\n"); + "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not defined.\n" + ); } TEST_F(ValidationErrorTest, OutputTypeNotAMessage) { @@ -5409,8 +5335,8 @@ TEST_F(ValidationErrorTest, OutputTypeNotAMessage) { " method { name: \"A\" input_type: \"Foo\" output_type: \"Bar\" }" "}", - "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not a message " - "type.\n"); + "foo.proto: TestService.A: OUTPUT_TYPE: \"Bar\" is not a message type.\n" + ); } @@ -5631,7 +5557,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfPositiveRange) { " positive_int_value: 0x80000000 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2147483648 to 2147483647, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range " "for int32 option \"foo\".\n"); } @@ -5648,7 +5574,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueOutOfNegativeRange) { " negative_int_value: -0x80000001 } " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -2147483648 to 2147483647, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range " "for int32 option \"foo\".\n"); } @@ -5664,7 +5590,7 @@ TEST_F(ValidationErrorTest, Int32OptionValueIsNotPositiveInt) { " is_extension: true } " " string_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -2147483648 to 2147483647, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " "for int32 option \"foo\".\n"); } @@ -5682,7 +5608,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueOutOfRange) { "} " "}", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, -9223372036854775808 to 9223372036854775807, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range " "for int64 option \"foo\".\n"); } @@ -5698,7 +5624,7 @@ TEST_F(ValidationErrorTest, Int64OptionValueIsNotPositiveInt) { " is_extension: true } " " identifier_value: \"5\" } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from -9223372036854775808 to 9223372036854775807, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be integer " "for int64 option \"foo\".\n"); } @@ -5714,7 +5640,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueOutOfRange) { " is_extension: true } " " positive_int_value: 0x100000000 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value out of range, 0 to 4294967295, " + "foo.proto: foo.proto: OPTION_VALUE: Value out of range " "for uint32 option \"foo\".\n"); } @@ -5730,7 +5656,7 @@ TEST_F(ValidationErrorTest, UInt32OptionValueIsNotPositiveInt) { " is_extension: true } " " double_value: -5.6 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 4294967295, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " "for uint32 option \"foo\".\n"); } @@ -5746,7 +5672,7 @@ TEST_F(ValidationErrorTest, UInt64OptionValueIsNotPositiveInt) { " is_extension: true } " " negative_int_value: -5 } }", - "foo.proto: foo.proto: OPTION_VALUE: Value must be integer, from 0 to 18446744073709551615, " + "foo.proto: foo.proto: OPTION_VALUE: Value must be non-negative integer " "for uint64 option \"foo\".\n"); } @@ -5918,7 +5844,7 @@ TEST_F(ValidationErrorTest, DuplicateExtensionFieldNumber) { // errors. The "value" argument is embedded inside the // "uninterpreted_option" portion of the result. static std::string EmbedAggregateValue(const char* value) { - return absl::Substitute( + return strings::Substitute( "name: \"foo.proto\" " "dependency: \"google/protobuf/descriptor.proto\" " "message_type { name: \"Foo\" } " @@ -6042,8 +5968,8 @@ TEST_F(ValidationErrorTest, RollbackAfterError) { " }" "}", - "foo.proto: TestService.Baz: INPUT_TYPE: \"NoSuchType\" is not " - "defined.\n"); + "foo.proto: TestService.Baz: INPUT_TYPE: \"NoSuchType\" is not defined.\n" + ); // Make sure that if we build the same file again with the error fixed, // it works. If the above rollback was incomplete, then some symbols will @@ -6203,9 +6129,7 @@ static const char* kMapEntryKeyTypeErrorMessage = TEST_F(ValidationErrorTest, MapEntryBase) { FileDescriptorProto file_proto; FillValidMapEntry(&file_proto); - std::string text_proto; - TextFormat::PrintToString(file_proto, &text_proto); - BuildFile(text_proto); + BuildFile(file_proto.DebugString()); } TEST_F(ValidationErrorTest, MapEntryExtensionRange) { @@ -7414,19 +7338,19 @@ class ExponentialErrorDatabase : public DescriptorDatabase { bool PopulateFile(int file_num, FileDescriptorProto* output) { GOOGLE_CHECK_GE(file_num, 0); output->Clear(); - output->set_name(absl::Substitute("file$0.proto", file_num)); + output->set_name(strings::Substitute("file$0.proto", file_num)); // file0.proto doesn't define Message0 if (file_num > 0) { DescriptorProto* message = output->add_message_type(); - message->set_name(absl::Substitute("Message$0", file_num)); + message->set_name(strings::Substitute("Message$0", file_num)); for (int i = 0; i < file_num; ++i) { - output->add_dependency(absl::Substitute("file$0.proto", i)); + output->add_dependency(strings::Substitute("file$0.proto", i)); FieldDescriptorProto* field = message->add_field(); - field->set_name(absl::Substitute("field$0", i)); + field->set_name(strings::Substitute("field$0", i)); field->set_number(i); field->set_label(FieldDescriptorProto::LABEL_OPTIONAL); field->set_type(FieldDescriptorProto::TYPE_MESSAGE); - field->set_type_name(absl::Substitute("Message$0", i)); + field->set_type_name(strings::Substitute("Message$0", i)); } } return true; @@ -7476,8 +7400,6 @@ TEST_F(DatabaseBackedPoolTest, DoesntFallbackOnWrongType) { class AbortingErrorCollector : public DescriptorPool::ErrorCollector { public: AbortingErrorCollector() {} - AbortingErrorCollector(const AbortingErrorCollector&) = delete; - AbortingErrorCollector& operator=(const AbortingErrorCollector&) = delete; void AddError(const std::string& filename, const std::string& element_name, const Message* message, ErrorLocation location, @@ -7485,6 +7407,9 @@ class AbortingErrorCollector : public DescriptorPool::ErrorCollector { GOOGLE_LOG(FATAL) << "AddError() called unexpectedly: " << filename << " [" << element_name << "]: " << error_message; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AbortingErrorCollector); }; // A source tree containing only one file. @@ -7492,10 +7417,8 @@ class SingletonSourceTree : public compiler::SourceTree { public: SingletonSourceTree(const std::string& filename, const std::string& contents) : filename_(filename), contents_(contents) {} - SingletonSourceTree(const SingletonSourceTree&) = delete; - SingletonSourceTree& operator=(const SingletonSourceTree&) = delete; - io::ZeroCopyInputStream* Open(absl::string_view filename) override { + io::ZeroCopyInputStream* Open(const std::string& filename) override { return filename == filename_ ? new io::ArrayInputStream(contents_.data(), contents_.size()) : nullptr; @@ -7504,6 +7427,8 @@ class SingletonSourceTree : public compiler::SourceTree { private: const std::string filename_; const std::string contents_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SingletonSourceTree); }; const char* const kSourceLocationTestInput = @@ -7598,7 +7523,7 @@ class SourceLocationTest : public testing::Test { } static std::string PrintSourceLocation(const SourceLocation& loc) { - return absl::Substitute("$0:$1-$2:$3", 1 + loc.start_line, + return strings::Substitute("$0:$1-$2:$3", 1 + loc.start_line, 1 + loc.start_column, 1 + loc.end_line, 1 + loc.end_column); } @@ -8502,4 +8427,4 @@ TEST_F(LazilyBuildDependenciesTest, Dependency) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/drop_unknown_fields_test.cc b/libs/protobuf/src/google/protobuf/drop_unknown_fields_test.cc index 747cb5b..55c6b67 100644 --- a/libs/protobuf/src/google/protobuf/drop_unknown_fields_test.cc +++ b/libs/protobuf/src/google/protobuf/drop_unknown_fields_test.cc @@ -30,9 +30,9 @@ #include -#include "google/protobuf/unittest_drop_unknown_fields.pb.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message_lite.h" +#include +#include +#include #include using unittest_drop_unknown_fields::Foo; diff --git a/libs/protobuf/src/google/protobuf/duration.pb.cc b/libs/protobuf/src/google/protobuf/duration.pb.cc index 7c60f7f..72766bd 100644 --- a/libs/protobuf/src/google/protobuf/duration.pb.cc +++ b/libs/protobuf/src/google/protobuf/duration.pb.cc @@ -1,23 +1,25 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -#include "google/protobuf/duration.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Duration::Duration( ::_pbi::ConstantInitialized): _impl_{ @@ -25,88 +27,62 @@ PROTOBUF_CONSTEXPR Duration::Duration( , /*decltype(_impl_.nanos_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct DurationDefaultTypeInternal { - PROTOBUF_CONSTEXPR DurationDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR DurationDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~DurationDefaultTypeInternal() {} union { Duration _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DurationDefaultTypeInternal _Duration_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DurationDefaultTypeInternal _Duration_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fduration_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fduration_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.seconds_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.nanos_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fduration_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Duration)}, +const uint32_t TableStruct_google_2fprotobuf_2fduration_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.seconds_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Duration, _impl_.nanos_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Duration)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Duration_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fduration_2eproto[] PROTOBUF_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\203\001\n\023com.google.protobufB\rD" - "urationProtoP\001Z1google.golang.org/protob" - "uf/types/known/durationpb\370\001\001\242\002\003GPB\252\002\036Goo" - "gle.Protobuf.WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fduration_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fduration_2eproto = { - false, - false, - 235, - descriptor_table_protodef_google_2fprotobuf_2fduration_2eproto, - "google/protobuf/duration.proto", - &descriptor_table_google_2fprotobuf_2fduration_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fduration_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fduration_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fduration_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Duration_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fduration_2eproto[] PROTOBUF_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\203\001\n\023com.google.protobufB\rD" + "urationProtoP\001Z1google.golang.org/protob" + "uf/types/known/durationpb\370\001\001\242\002\003GPB\252\002\036Goo" + "gle.Protobuf.WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fduration_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fduration_2eproto = { + false, false, 235, descriptor_table_protodef_google_2fprotobuf_2fduration_2eproto, + "google/protobuf/duration.proto", + &descriptor_table_google_2fprotobuf_2fduration_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fduration_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fduration_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fduration_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fduration_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fduration_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fduration_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fduration_2eproto(&descriptor_table_google_2fprotobuf_2fduration_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fduration_2eproto(&descriptor_table_google_2fprotobuf_2fduration_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class Duration::_Internal { @@ -120,9 +96,17 @@ Duration::Duration(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.Duration) } Duration::Duration(const Duration& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + Duration* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.seconds_){} + , decltype(_impl_.nanos_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::memcpy(&_impl_.seconds_, &from._impl_.seconds_, + static_cast(reinterpret_cast(&_impl_.nanos_) - + reinterpret_cast(&_impl_.seconds_)) + sizeof(_impl_.nanos_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.Duration) } @@ -167,7 +151,6 @@ void Duration::Clear() { } const char* Duration::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -214,7 +197,6 @@ failure: uint8_t* Duration::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -240,7 +222,6 @@ uint8_t* Duration::_InternalSerialize( } size_t Duration::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration) size_t total_size = 0; @@ -271,7 +252,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Duration::GetClassData() const void Duration::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Duration) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -309,11 +289,11 @@ void Duration::InternalSwap(Duration* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Duration::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fduration_2eproto_getter, &descriptor_table_google_2fprotobuf_2fduration_2eproto_once, file_level_metadata_google_2fprotobuf_2fduration_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -322,5 +302,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Duration >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Duration >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/duration.pb.h b/libs/protobuf/src/google/protobuf/duration.pb.h index a3f393a..a5272c8 100644 --- a/libs/protobuf/src/google/protobuf/duration.pb.h +++ b/libs/protobuf/src/google/protobuf/duration.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/duration.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fduration_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,23 +43,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fduration_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fduration_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fduration_2eproto; PROTOBUF_NAMESPACE_OPEN class Duration; struct DurationDefaultTypeInternal; PROTOBUF_EXPORT extern DurationDefaultTypeInternal _Duration_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Duration* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Duration>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Duration* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Duration>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Duration final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ { public: @@ -168,7 +159,7 @@ class PROTOBUF_EXPORT Duration final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Duration"; } protected: @@ -225,17 +216,12 @@ class PROTOBUF_EXPORT Duration final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Duration // int64 seconds = 1; @@ -250,7 +236,7 @@ inline int64_t Duration::seconds() const { return _internal_seconds(); } inline void Duration::_internal_set_seconds(int64_t value) { - + _impl_.seconds_ = value; } inline void Duration::set_seconds(int64_t value) { @@ -270,7 +256,7 @@ inline int32_t Duration::nanos() const { return _internal_nanos(); } inline void Duration::_internal_set_nanos(int32_t value) { - + _impl_.nanos_ = value; } inline void Duration::set_nanos(int32_t value) { @@ -279,15 +265,14 @@ inline void Duration::set_nanos(int32_t value) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fduration_2eproto diff --git a/libs/protobuf/src/google/protobuf/duration.proto b/libs/protobuf/src/google/protobuf/duration.proto index a0d91df..81c3e36 100644 --- a/libs/protobuf/src/google/protobuf/duration.proto +++ b/libs/protobuf/src/google/protobuf/duration.proto @@ -99,6 +99,7 @@ option objc_class_prefix = "GPB"; // be expressed in JSON format as "3.000000001s", and 3 seconds and 1 // microsecond should be expressed in JSON format as "3.000001s". // +// message Duration { // Signed seconds of the span of time. Must be from -315,576,000,000 // to +315,576,000,000 inclusive. Note: these bounds are computed from: diff --git a/libs/protobuf/src/google/protobuf/dynamic_message.cc b/libs/protobuf/src/google/protobuf/dynamic_message.cc index 16bce6e..1c96ca2 100644 --- a/libs/protobuf/src/google/protobuf/dynamic_message.cc +++ b/libs/protobuf/src/google/protobuf/dynamic_message.cc @@ -62,7 +62,7 @@ // Item 8 of "More Effective C++" discusses this in more detail, though // I don't have the book on me right now so I'm not sure. -#include "google/protobuf/dynamic_message.h" +#include #include #include @@ -70,23 +70,23 @@ #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/wire_format.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -105,6 +105,22 @@ namespace { bool IsMapFieldInApi(const FieldDescriptor* field) { return field->is_map(); } +// Sync with helpers.h. +inline bool HasHasbit(const FieldDescriptor* field) { + // This predicate includes proto3 message fields only if they have "optional". + // Foo submsg1 = 1; // HasHasbit() == false + // optional Foo submsg2 = 2; // HasHasbit() == true + // This is slightly odd, as adding "optional" to a singular proto3 field does + // not change the semantics or API. However whenever any field in a message + // has a hasbit, it forces reflection to include hasbit offsets for *all* + // fields, even if almost all of them are set to -1 (no hasbit). So to avoid + // causing a sudden size regression for ~all proto3 messages, we give proto3 + // message fields a hasbit only if "optional" is present. If the user is + // explicitly writing "optional", it is likely they are writing it on + // primitive fields also. + return (field->has_optional_keyword() || field->is_required()) && + !field->options().weak(); +} inline bool InRealOneof(const FieldDescriptor* field) { return field->containing_oneof() && @@ -208,8 +224,6 @@ class DynamicMessage : public Message { // This should only be used by GetPrototypeNoLock() to avoid dead lock. DynamicMessage(DynamicMessageFactory::TypeInfo* type_info, bool lock_factory); - DynamicMessage(const DynamicMessage&) = delete; - DynamicMessage& operator=(const DynamicMessage&) = delete; ~DynamicMessage() override; @@ -271,6 +285,7 @@ class DynamicMessage : public Message { const DynamicMessageFactory::TypeInfo* type_info_; mutable std::atomic cached_byte_size_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessage); }; struct DynamicMessageFactory::TypeInfo { @@ -298,21 +313,7 @@ struct DynamicMessageFactory::TypeInfo { TypeInfo() : prototype(nullptr) {} - ~TypeInfo() { - delete prototype; - - // Scribble the payload to prevent unsanitized opt builds from silently - // allowing use-after-free bugs where the factory is destroyed but the - // DynamicMessage instances are still used. - // This is a common bug with DynamicMessageFactory. - // NOTE: This must happen after deleting the prototype. - if (offsets != nullptr) { - std::fill_n(offsets.get(), type->field_count(), 0xCDCDCDCDu); - } - if (has_bits_indices != nullptr) { - std::fill_n(has_bits_indices.get(), type->field_count(), 0xCDCDCDCDu); - } - } + ~TypeInfo() { delete prototype; } }; DynamicMessage::DynamicMessage(const DynamicMessageFactory::TypeInfo* type_info) @@ -652,7 +653,7 @@ DynamicMessageFactory::~DynamicMessageFactory() { } const Message* DynamicMessageFactory::GetPrototype(const Descriptor* type) { - absl::MutexLock lock(&prototypes_mutex_); + MutexLock lock(&prototypes_mutex_); return GetPrototypeNoLock(type); } @@ -704,7 +705,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( type_info->has_bits_offset = -1; int max_hasbit = 0; for (int i = 0; i < type->field_count(); i++) { - if (internal::cpp::HasHasbit(type->field(i))) { + if (HasHasbit(type->field(i))) { if (type_info->has_bits_offset == -1) { // At least one field in the message requires a hasbit, so allocate // hasbits. @@ -807,11 +808,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( type_info->oneof_case_offset, type_info->size, type_info->weak_field_map_offset, - nullptr, // inlined_string_indices_ - 0, // inlined_string_donated_offset_ - -1, // split_offset_ - -1, // sizeof_split_ - }; + nullptr /* inlined_string_indices_ */, + 0 /* inlined_string_donated_offset_ */}; type_info->reflection.reset( new Reflection(type_info->type, schema, type_info->pool, this)); @@ -825,4 +823,4 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" // NOLINT +#include // NOLINT diff --git a/libs/protobuf/src/google/protobuf/dynamic_message.h b/libs/protobuf/src/google/protobuf/dynamic_message.h index bec0a1e..6fa6425 100644 --- a/libs/protobuf/src/google/protobuf/dynamic_message.h +++ b/libs/protobuf/src/google/protobuf/dynamic_message.h @@ -44,18 +44,18 @@ #include #include -#include "absl/synchronization/mutex.h" -#include "google/protobuf/message.h" -#include "google/protobuf/port.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -81,9 +81,6 @@ class DescriptorPool; // descriptor.h // encapsulates this "cache". All DynamicMessages of the same type created // from the same factory will share the same support data. Any Descriptors // used with a particular factory must outlive the factory. -// -// The thread safety for this class is subtle, see comments around GetPrototype -// for details class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { public: // Construct a DynamicMessageFactory that will search for extensions in @@ -98,8 +95,6 @@ class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { // this is almost never what you want to do. Almost all users should use // the zero-arg constructor. DynamicMessageFactory(const DescriptorPool* pool); - DynamicMessageFactory(const DynamicMessageFactory&) = delete; - DynamicMessageFactory& operator=(const DynamicMessageFactory&) = delete; ~DynamicMessageFactory() override; @@ -138,10 +133,12 @@ class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { struct TypeInfo; std::unordered_map prototypes_; - mutable absl::Mutex prototypes_mutex_; + mutable internal::WrappedMutex prototypes_mutex_; friend class DynamicMessage; const Message* GetPrototypeNoLock(const Descriptor* type); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory); }; // Helper for computing a sorted list of map entries via reflection. @@ -225,6 +222,6 @@ class PROTOBUF_EXPORT DynamicMapSorter { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ diff --git a/libs/protobuf/src/google/protobuf/dynamic_message_unittest.cc b/libs/protobuf/src/google/protobuf/dynamic_message_unittest.cc index 6dd1184..7ac2029 100644 --- a/libs/protobuf/src/google/protobuf/dynamic_message_unittest.cc +++ b/libs/protobuf/src/google/protobuf/dynamic_message_unittest.cc @@ -40,19 +40,19 @@ // reflection_ops_unittest, cover the rest of the functionality used by // DynamicMessage. -#include "google/protobuf/dynamic_message.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_no_field_presence.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/test_util.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/empty.pb.cc b/libs/protobuf/src/google/protobuf/empty.pb.cc index c04ad78..3a30776 100644 --- a/libs/protobuf/src/google/protobuf/empty.pb.cc +++ b/libs/protobuf/src/google/protobuf/empty.pb.cc @@ -1,106 +1,82 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -#include "google/protobuf/empty.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Empty::Empty( ::_pbi::ConstantInitialized) {} struct EmptyDefaultTypeInternal { - PROTOBUF_CONSTEXPR EmptyDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EmptyDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EmptyDefaultTypeInternal() {} union { Empty _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EmptyDefaultTypeInternal _Empty_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EmptyDefaultTypeInternal _Empty_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fempty_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fempty_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Empty, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fempty_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Empty)}, +const uint32_t TableStruct_google_2fprotobuf_2fempty_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Empty, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Empty)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Empty_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fempty_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - "\n\033google/protobuf/empty.proto\022\017google.pr" - "otobuf\"\007\n\005EmptyB}\n\023com.google.protobufB\n" - "EmptyProtoP\001Z.google.golang.org/protobuf" - "/types/known/emptypb\370\001\001\242\002\003GPB\252\002\036Google.P" - "rotobuf.WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fempty_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fempty_2eproto = { - false, - false, - 190, - descriptor_table_protodef_google_2fprotobuf_2fempty_2eproto, - "google/protobuf/empty.proto", - &descriptor_table_google_2fprotobuf_2fempty_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fempty_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fempty_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fempty_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Empty_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fempty_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\033google/protobuf/empty.proto\022\017google.pr" + "otobuf\"\007\n\005EmptyB}\n\023com.google.protobufB\n" + "EmptyProtoP\001Z.google.golang.org/protobuf" + "/types/known/emptypb\370\001\001\242\002\003GPB\252\002\036Google.P" + "rotobuf.WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fempty_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fempty_2eproto = { + false, false, 190, descriptor_table_protodef_google_2fprotobuf_2fempty_2eproto, + "google/protobuf/empty.proto", + &descriptor_table_google_2fprotobuf_2fempty_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fempty_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fempty_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fempty_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fempty_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fempty_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fempty_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fempty_2eproto(&descriptor_table_google_2fprotobuf_2fempty_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fempty_2eproto(&descriptor_table_google_2fprotobuf_2fempty_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class Empty::_Internal { @@ -136,11 +112,11 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Empty::GetClassData() const { ::PROTOBUF_NAMESPACE_ID::Metadata Empty::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fempty_2eproto_getter, &descriptor_table_google_2fprotobuf_2fempty_2eproto_once, file_level_metadata_google_2fprotobuf_2fempty_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -149,5 +125,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Empty >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Empty >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/empty.pb.h b/libs/protobuf/src/google/protobuf/empty.pb.h index 807dc9c..bcb6478 100644 --- a/libs/protobuf/src/google/protobuf/empty.pb.h +++ b/libs/protobuf/src/google/protobuf/empty.pb.h @@ -1,44 +1,39 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/empty.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_bases.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fempty_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -49,23 +44,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fempty_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fempty_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fempty_2eproto; PROTOBUF_NAMESPACE_OPEN class Empty; struct EmptyDefaultTypeInternal; PROTOBUF_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Empty* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Empty>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Empty* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Empty>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Empty final : public ::PROTOBUF_NAMESPACE_ID::internal::ZeroFieldsBase /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ { public: @@ -154,7 +145,7 @@ class PROTOBUF_EXPORT Empty final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Empty"; } protected: @@ -185,29 +176,23 @@ class PROTOBUF_EXPORT Empty final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Empty #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fempty_2eproto diff --git a/libs/protobuf/src/google/protobuf/endian.h b/libs/protobuf/src/google/protobuf/endian.h index 2527b3e..e0ee6cd 100644 --- a/libs/protobuf/src/google/protobuf/endian.h +++ b/libs/protobuf/src/google/protobuf/endian.h @@ -38,7 +38,7 @@ #include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -193,6 +193,6 @@ inline uint64_t ToHost(uint64_t value) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_ENDIAN_H__ diff --git a/libs/protobuf/src/google/protobuf/explicitly_constructed.h b/libs/protobuf/src/google/protobuf/explicitly_constructed.h index c273644..174c59a 100644 --- a/libs/protobuf/src/google/protobuf/explicitly_constructed.h +++ b/libs/protobuf/src/google/protobuf/explicitly_constructed.h @@ -35,11 +35,11 @@ #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { @@ -92,6 +92,6 @@ using ExplicitlyConstructedArenaString = ExplicitlyConstructed; } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_EXPLICITLY_CONSTRUCTED_H__ diff --git a/libs/protobuf/src/google/protobuf/extension_set.cc b/libs/protobuf/src/google/protobuf/extension_set.cc index 791c1e3..fada4f5 100644 --- a/libs/protobuf/src/google/protobuf/extension_set.cc +++ b/libs/protobuf/src/google/protobuf/extension_set.cc @@ -32,30 +32,32 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/extension_set.h" +#include #include +#include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/arena.h" -#include "absl/container/flat_hash_set.h" -#include "absl/hash/hash.h" -#include "google/protobuf/extension_set_inl.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_field.h" - -// must be last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// clang-format off +#include // must be last. +// clang-format on namespace google { namespace protobuf { namespace internal { + namespace { inline WireFormatLite::FieldType real_type(FieldType type) { @@ -69,6 +71,8 @@ inline WireFormatLite::CppType cpp_type(FieldType type) { // Registry stuff. +// Note that we cannot use hetererogeneous lookup for std containers since we +// need to support C++11. struct ExtensionEq { bool operator()(const ExtensionInfo& lhs, const ExtensionInfo& rhs) const { return lhs.message == rhs.message && lhs.number == rhs.number; @@ -77,12 +81,13 @@ struct ExtensionEq { struct ExtensionHasher { std::size_t operator()(const ExtensionInfo& info) const { - return absl::HashOf(info.message, info.number); + return std::hash{}(info.message) ^ + std::hash{}(info.number); } }; using ExtensionRegistry = - absl::flat_hash_set; + std::unordered_set; static const ExtensionRegistry* global_registry = nullptr; @@ -91,7 +96,7 @@ static const ExtensionRegistry* global_registry = nullptr; void Register(const ExtensionInfo& info) { static auto local_static_registry = OnShutdownDelete(new ExtensionRegistry); global_registry = local_static_registry; - if (!local_static_registry->insert(info).second) { + if (!InsertIfNotPresent(local_static_registry, info)) { GOOGLE_LOG(FATAL) << "Multiple extension registrations for type \"" << info.message->GetTypeName() << "\", field number " << info.number << "."; @@ -1959,4 +1964,4 @@ LazyEagerVerifyFnType FindExtensionLazyEagerVerifyFn( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/extension_set.h b/libs/protobuf/src/google/protobuf/extension_set.h index 2ce566a..0e6d052 100644 --- a/libs/protobuf/src/google/protobuf/extension_set.h +++ b/libs/protobuf/src/google/protobuf/extension_set.h @@ -46,17 +46,16 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/port.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/port.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" // Must be last +#include // Must be last // clang-format on #ifdef SWIG @@ -186,8 +185,6 @@ class PROTOBUF_EXPORT ExtensionSet { constexpr ExtensionSet(); explicit ExtensionSet(Arena* arena); ExtensionSet(ArenaInitialized, Arena* arena) : ExtensionSet(arena) {} - ExtensionSet(const ExtensionSet&) = delete; - ExtensionSet& operator=(const ExtensionSet&) = delete; ~ExtensionSet(); // These are called at startup by protocol-compiler-generated code to @@ -541,8 +538,6 @@ class PROTOBUF_EXPORT ExtensionSet { class PROTOBUF_EXPORT LazyMessageExtension { public: LazyMessageExtension() {} - LazyMessageExtension(const LazyMessageExtension&) = delete; - LazyMessageExtension& operator=(const LazyMessageExtension&) = delete; virtual ~LazyMessageExtension() {} virtual LazyMessageExtension* New(Arena* arena) const = 0; @@ -579,6 +574,8 @@ class PROTOBUF_EXPORT ExtensionSet { private: virtual void UnusedKeyMethod(); // Dummy key method to avoid weak vtable. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyMessageExtension); }; // Give access to function defined below to see LazyMessageExtension. friend LazyMessageExtension* MaybeCreateLazyExtension(Arena* arena); @@ -911,6 +908,8 @@ class PROTOBUF_EXPORT ExtensionSet { } map_; static void DeleteFlatMap(const KeyValue* flat, uint16_t flat_capacity); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet); }; constexpr ExtensionSet::ExtensionSet() @@ -1263,8 +1262,6 @@ class EnumTypeTraits { template static void Register(int number, FieldType type, bool is_packed, LazyEagerVerifyFnType fn) { - // Avoid -Wunused-parameter - (void)fn; ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number, type, false, is_packed, IsValid); } @@ -1331,8 +1328,6 @@ class RepeatedEnumTypeTraits { template static void Register(int number, FieldType type, bool is_packed, LazyEagerVerifyFnType fn) { - // Avoid -Wunused-parameter - (void)fn; ExtensionSet::RegisterEnumExtension(&ExtendeeT::default_instance(), number, type, true, is_packed, IsValid); } @@ -1561,6 +1556,6 @@ void LinkExtensionReflection( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ diff --git a/libs/protobuf/src/google/protobuf/extension_set_heavy.cc b/libs/protobuf/src/google/protobuf/extension_set_heavy.cc index 0ccce3c..a4bb948 100644 --- a/libs/protobuf/src/google/protobuf/extension_set_heavy.cc +++ b/libs/protobuf/src/google/protobuf/extension_set_heavy.cc @@ -35,25 +35,24 @@ // Contains methods defined in extension_set.h which cannot be part of the // lite library because they use descriptors or reflection. -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "absl/base/casts.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/extension_set_inl.h" -#include "google/protobuf/message.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -414,7 +413,7 @@ size_t ExtensionSet::Extension::SpaceUsedExcludingSelfLong() const { if (is_lazy) { total_size += lazymessage_value->SpaceUsedLong(); } else { - total_size += DownCast(message_value)->SpaceUsedLong(); + total_size += down_cast(message_value)->SpaceUsedLong(); } break; default: @@ -438,4 +437,4 @@ uint8_t* ExtensionSet::SerializeMessageSetWithCachedSizesToArray( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/extension_set_inl.h b/libs/protobuf/src/google/protobuf/extension_set_inl.h index 8256455..e4e7117 100644 --- a/libs/protobuf/src/google/protobuf/extension_set_inl.h +++ b/libs/protobuf/src/google/protobuf/extension_set_inl.h @@ -31,9 +31,9 @@ #ifndef GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__ #define GOOGLE_PROTOBUF_EXTENSION_SET_INL_H__ -#include "google/protobuf/extension_set.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/parse_context.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/extension_set_unittest.cc b/libs/protobuf/src/google/protobuf/extension_set_unittest.cc index 5d07a98..207e10c 100644 --- a/libs/protobuf/src/google/protobuf/extension_set_unittest.cc +++ b/libs/protobuf/src/google/protobuf/extension_set_unittest.cc @@ -32,32 +32,29 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/extension_set.h" - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_mset.pb.h" -#include "google/protobuf/io/coded_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/dynamic_message.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/base/casts.h" -#include "absl/strings/cord.h" -#include "absl/strings/match.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/test_util2.h" - -#include "google/protobuf/stubs/strutil.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { @@ -65,7 +62,6 @@ namespace protobuf { namespace internal { namespace { -using ::google::protobuf::internal::DownCast; using TestUtil::EqualsToSerialized; // This test closely mirrors third_party/protobuf/compiler/cpp/unittest.cc @@ -551,7 +547,7 @@ TEST(ExtensionSetTest, SerializationToArray) { size_t size = source.ByteSizeLong(); std::string data; data.resize(size); - uint8_t* target = reinterpret_cast(&data[0]); + uint8_t* target = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = source.SerializeWithCachedSizesToArray(target); EXPECT_EQ(size, end - target); EXPECT_TRUE(destination.ParseFromString(data)); @@ -573,7 +569,7 @@ TEST(ExtensionSetTest, SerializationToStream) { std::string data; data.resize(size); { - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); source.SerializeWithCachedSizes(&output_stream); ASSERT_FALSE(output_stream.HadError()); @@ -595,7 +591,7 @@ TEST(ExtensionSetTest, PackedSerializationToArray) { size_t size = source.ByteSizeLong(); std::string data; data.resize(size); - uint8_t* target = reinterpret_cast(&data[0]); + uint8_t* target = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = source.SerializeWithCachedSizesToArray(target); EXPECT_EQ(size, end - target); EXPECT_TRUE(destination.ParseFromString(data)); @@ -617,7 +613,7 @@ TEST(ExtensionSetTest, PackedSerializationToStream) { std::string data; data.resize(size); { - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); source.SerializeWithCachedSizes(&output_stream); ASSERT_FALSE(output_stream.HadError()); @@ -856,10 +852,8 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) { const size_t old_capacity = \ message->GetRepeatedExtension(unittest::repeated_##type##_extension) \ .Capacity(); \ - EXPECT_GE( \ - old_capacity, \ - (RepeatedFieldLowerClampLimit())); \ + EXPECT_GE(old_capacity, \ + (RepeatedFieldLowerClampLimit())); \ for (int i = 0; i < 16; ++i) { \ message->AddExtension(unittest::repeated_##type##_extension, value); \ } \ @@ -1235,7 +1229,7 @@ TEST(ExtensionSetTest, DynamicExtensions) { std::string prefix = "." + template_descriptor->full_name() + "."; if (extension->has_type_name()) { std::string* type_name = extension->mutable_type_name(); - if (absl::StartsWith(*type_name, prefix)) { + if (HasPrefixString(*type_name, prefix)) { type_name->replace(0, prefix.size(), ".dynamic_extensions."); } } diff --git a/libs/protobuf/src/google/protobuf/field_access_listener.h b/libs/protobuf/src/google/protobuf/field_access_listener.h index fd54f0e..47422e6 100644 --- a/libs/protobuf/src/google/protobuf/field_access_listener.h +++ b/libs/protobuf/src/google/protobuf/field_access_listener.h @@ -33,8 +33,8 @@ #include -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" +#include +#include namespace google { @@ -57,7 +57,7 @@ struct NoOpAccessListener { // to differentiate the protos during the runtime before the start of the // program, use this functor to get its name. We either way need it for // LITE_RUNTIME protos as they don't have descriptors at all. - explicit NoOpAccessListener(absl::string_view (*name_extractor)()) {} + explicit NoOpAccessListener(StringPiece (*name_extractor)()) {} // called repeatedly during serialization/deserialization/ByteSize of // Reflection as: // AccessListener::OnSerialize(this); diff --git a/libs/protobuf/src/google/protobuf/field_mask.pb.cc b/libs/protobuf/src/google/protobuf/field_mask.pb.cc index de87758..7860bfb 100644 --- a/libs/protobuf/src/google/protobuf/field_mask.pb.cc +++ b/libs/protobuf/src/google/protobuf/field_mask.pb.cc @@ -1,110 +1,86 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -#include "google/protobuf/field_mask.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR FieldMask::FieldMask( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.paths_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct FieldMaskDefaultTypeInternal { - PROTOBUF_CONSTEXPR FieldMaskDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FieldMaskDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FieldMaskDefaultTypeInternal() {} union { FieldMask _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldMaskDefaultTypeInternal _FieldMask_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldMaskDefaultTypeInternal _FieldMask_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _impl_.paths_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldMask)}, +const uint32_t TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FieldMask, _impl_.paths_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FieldMask)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_FieldMask_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2ffield_5fmask_2eproto[] PROTOBUF_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" - "\205\001\n\023com.google.protobufB\016FieldMaskProtoP" - "\001Z2google.golang.org/protobuf/types/know" - "n/fieldmaskpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf" - ".WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto = { - false, - false, - 223, - descriptor_table_protodef_google_2fprotobuf_2ffield_5fmask_2eproto, - "google/protobuf/field_mask.proto", - &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto, - file_level_service_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto, + &::PROTOBUF_NAMESPACE_ID::_FieldMask_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2ffield_5fmask_2eproto[] PROTOBUF_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" + "\205\001\n\023com.google.protobufB\016FieldMaskProtoP" + "\001Z2google.golang.org/protobuf/types/know" + "n/fieldmaskpb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf" + ".WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto = { + false, false, 223, descriptor_table_protodef_google_2fprotobuf_2ffield_5fmask_2eproto, + "google/protobuf/field_mask.proto", + &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto, file_level_enum_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto, + file_level_service_descriptors_google_2fprotobuf_2ffield_5fmask_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ffield_5fmask_2eproto(&descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ffield_5fmask_2eproto(&descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class FieldMask::_Internal { @@ -167,7 +143,6 @@ void FieldMask::Clear() { } const char* FieldMask::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -213,7 +188,6 @@ failure: uint8_t* FieldMask::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -237,7 +211,6 @@ uint8_t* FieldMask::_InternalSerialize( } size_t FieldMask::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask) size_t total_size = 0; @@ -266,7 +239,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FieldMask::GetClassData() cons void FieldMask::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FieldMask) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -294,11 +266,11 @@ void FieldMask::InternalSwap(FieldMask* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FieldMask::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_getter, &descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto_once, file_level_metadata_google_2fprotobuf_2ffield_5fmask_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -307,5 +279,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::FieldMask >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::FieldMask >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/field_mask.pb.h b/libs/protobuf/src/google/protobuf/field_mask.pb.h index 3a181fd..8f90e4c 100644 --- a/libs/protobuf/src/google/protobuf/field_mask.pb.h +++ b/libs/protobuf/src/google/protobuf/field_mask.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/field_mask.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ffield_5fmask_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,23 +43,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ffield_5fmask_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ffield_5fmask_2eproto; PROTOBUF_NAMESPACE_OPEN class FieldMask; struct FieldMaskDefaultTypeInternal; PROTOBUF_EXPORT extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldMask* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldMask>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FieldMask* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FieldMask>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT FieldMask final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ { public: @@ -168,7 +159,7 @@ class PROTOBUF_EXPORT FieldMask final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FieldMask"; } protected: @@ -229,17 +220,12 @@ class PROTOBUF_EXPORT FieldMask final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // FieldMask // repeated string paths = 1; @@ -277,7 +263,8 @@ inline void FieldMask::set_paths(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths) } inline void FieldMask::set_paths(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.paths_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) } inline void FieldMask::set_paths(int index, const char* value, size_t size) { @@ -297,7 +284,8 @@ inline void FieldMask::add_paths(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) } inline void FieldMask::add_paths(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.paths_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.paths_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) } inline void FieldMask::add_paths(const char* value, size_t size) { @@ -316,15 +304,14 @@ FieldMask::mutable_paths() { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ffield_5fmask_2eproto diff --git a/libs/protobuf/src/google/protobuf/generated_enum_reflection.h b/libs/protobuf/src/google/protobuf/generated_enum_reflection.h index 31ddc12..b96a9c6 100644 --- a/libs/protobuf/src/google/protobuf/generated_enum_reflection.h +++ b/libs/protobuf/src/google/protobuf/generated_enum_reflection.h @@ -42,16 +42,16 @@ #include -#include "google/protobuf/port.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/generated_enum_util.h" +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -74,10 +74,10 @@ namespace internal { // an enum name of the given type, returning true and filling in value on // success, or returning false and leaving value unchanged on failure. PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, - absl::string_view name, int* value); + ConstStringParam name, int* value); template -bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name, +bool ParseNamedEnum(const EnumDescriptor* descriptor, ConstStringParam name, EnumType* value) { int tmp; if (!ParseNamedEnum(descriptor, name, &tmp)) return false; @@ -95,6 +95,6 @@ PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_enum_util.cc b/libs/protobuf/src/google/protobuf/generated_enum_util.cc index ab21577..df7583e 100644 --- a/libs/protobuf/src/google/protobuf/generated_enum_util.cc +++ b/libs/protobuf/src/google/protobuf/generated_enum_util.cc @@ -28,11 +28,11 @@ // (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_enum_util.h" +#include #include -#include "google/protobuf/generated_message_util.h" +#include namespace google { namespace protobuf { @@ -40,7 +40,7 @@ namespace internal { namespace { bool EnumCompareByName(const EnumEntry& a, const EnumEntry& b) { - return absl::string_view(a.name) < absl::string_view(b.name); + return StringPiece(a.name) < StringPiece(b.name); } // Gets the numeric value of the EnumEntry at the given index, but returns a @@ -57,7 +57,7 @@ int GetValue(const EnumEntry* enums, int i, int target) { } // namespace bool LookUpEnumValue(const EnumEntry* enums, size_t size, - absl::string_view name, int* value) { + StringPiece name, int* value) { EnumEntry target{name, 0}; auto it = std::lower_bound(enums, enums + size, target, EnumCompareByName); if (it != enums + size && it->name == name) { diff --git a/libs/protobuf/src/google/protobuf/generated_enum_util.h b/libs/protobuf/src/google/protobuf/generated_enum_util.h index 86e1bb9..5d10ac0 100644 --- a/libs/protobuf/src/google/protobuf/generated_enum_util.h +++ b/libs/protobuf/src/google/protobuf/generated_enum_util.h @@ -34,11 +34,11 @@ #include -#include "absl/strings/string_view.h" -#include "google/protobuf/message_lite.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -58,13 +58,13 @@ namespace internal { // protos. This struct and the following related functions should only be used // by protobuf generated code. struct EnumEntry { - absl::string_view name; + StringPiece name; int value; }; // Looks up a numeric enum value given the string name. PROTOBUF_EXPORT bool LookUpEnumValue(const EnumEntry* enums, size_t size, - absl::string_view name, int* value); + StringPiece name, int* value); // Looks up an enum name given the numeric value. PROTOBUF_EXPORT int LookUpEnumName(const EnumEntry* enums, @@ -80,6 +80,6 @@ PROTOBUF_EXPORT bool InitializeEnumStrings( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_bases.cc b/libs/protobuf/src/google/protobuf/generated_message_bases.cc index 2ccca16..306a38e 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_bases.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_bases.cc @@ -28,17 +28,17 @@ // (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_bases.h" +#include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include // Must be last: -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -121,4 +121,4 @@ void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/generated_message_bases.h b/libs/protobuf/src/google/protobuf/generated_message_bases.h index e831079..b295218 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_bases.h +++ b/libs/protobuf/src/google/protobuf/generated_message_bases.h @@ -35,14 +35,14 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/message.h" -#include "google/protobuf/parse_context.h" +#include +#include +#include +#include +#include // Must come last: -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -82,6 +82,6 @@ class PROTOBUF_EXPORT ZeroFieldsBase : public Message { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_BASES_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_reflection.cc b/libs/protobuf/src/google/protobuf/generated_message_reflection.cc index 43d0c10..2a807e0 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_reflection.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_reflection.cc @@ -32,36 +32,29 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/generated_message_reflection.h" +#include #include -#include -#include -#include #include -#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/base/casts.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/generated_message_tctable_gen.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/inlined_string_field.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on #define GOOGLE_PROTOBUF_HAS_ONEOF @@ -80,6 +73,7 @@ using google::protobuf::internal::OnShutdownDelete; using google::protobuf::internal::ReflectionSchema; using google::protobuf::internal::RepeatedPtrFieldBase; using google::protobuf::internal::StringSpaceUsedExcludingSelfLong; +using google::protobuf::internal::WrappedMutex; namespace google { namespace protobuf { @@ -101,7 +95,7 @@ Message* MaybeForceCopy(Arena* arena, Message* msg) { namespace internal { -bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name, +bool ParseNamedEnum(const EnumDescriptor* descriptor, ConstStringParam name, int* value) { const EnumValueDescriptor* d = descriptor->FindValueByName(name); if (d == nullptr) return false; @@ -114,54 +108,6 @@ const std::string& NameOfEnum(const EnumDescriptor* descriptor, int value) { return (d == nullptr ? GetEmptyString() : d->name()); } -// Internal helper routine for NameOfDenseEnum in the header file. -// Allocates and fills a simple array of string pointers, based on -// reflection information about the names of the enums. This routine -// allocates max_val + 1 entries, under the assumption that all the enums -// fall in the range [min_val .. max_val]. -const std::string** MakeDenseEnumCache(const EnumDescriptor* desc, int min_val, - int max_val) { - auto* str_ptrs = - new const std::string*[static_cast(max_val - min_val + 1)](); - const int count = desc->value_count(); - for (int i = 0; i < count; ++i) { - const int num = desc->value(i)->number(); - if (str_ptrs[num - min_val] == nullptr) { - // Don't over-write an existing entry, because in case of duplication, the - // first one wins. - str_ptrs[num - min_val] = &desc->value(i)->name(); - } - } - // Change any unfilled entries to point to the empty string. - for (int i = 0; i < max_val - min_val + 1; ++i) { - if (str_ptrs[i] == nullptr) str_ptrs[i] = &GetEmptyStringAlreadyInited(); - } - return str_ptrs; -} - -PROTOBUF_NOINLINE const std::string& NameOfDenseEnumSlow( - int v, DenseEnumCacheInfo* deci) { - if (v < deci->min_val || v > deci->max_val) - return GetEmptyStringAlreadyInited(); - - const std::string** new_cache = - MakeDenseEnumCache(deci->descriptor_fn(), deci->min_val, deci->max_val); - const std::string** old_cache = nullptr; - - if (deci->cache.compare_exchange_strong(old_cache, new_cache, - std::memory_order_release, - std::memory_order_acquire)) { - // We successfully stored our new cache, and the old value was nullptr. - return *new_cache[v - deci->min_val]; - } else { - // In the time it took to create our enum cache, another thread also - // created one, and put it into deci->cache. So delete ours, and - // use theirs instead. - delete[] new_cache; - return *old_cache[v - deci->min_val]; - } -} - } // namespace internal // =================================================================== @@ -293,12 +239,6 @@ Reflection::Reflection(const Descriptor* descriptor, last_non_weak_field_index_ = descriptor_->field_count() - 1; } -Reflection::~Reflection() { - // No need to use sized delete. This code path is uncommon and it would not be - // worth saving or recalculating the size. - ::operator delete(const_cast(tcparse_table_)); -} - const UnknownFieldSet& Reflection::GetUnknownFields( const Message& message) const { return GetInternalMetadata(message).unknown_fields( @@ -454,19 +394,7 @@ size_t Reflection::SpaceUsedLong(const Message& message) const { } } } -#ifndef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG return total_size; -#else - // Use both `this` and `dummy` to generate the seed so that the scale factor - // is both per-object and non-predictable, but consistent across multiple - // calls in the same binary. - static bool dummy; - uintptr_t seed = - reinterpret_cast(&dummy) ^ reinterpret_cast(this); - // Fuzz the size by +/- 50%. - double scale = (static_cast(seed % 10000) / 10000) + 0.5; - return total_size * scale; -#endif } namespace { @@ -1055,6 +983,8 @@ void Reflection::Swap(Message* message1, Message* message2) const { return; } + GOOGLE_DCHECK_EQ(message1->GetOwningArena(), message2->GetOwningArena()); + UnsafeArenaSwap(message1, message2); } @@ -1084,6 +1014,9 @@ void Reflection::SwapFieldsImpl( std::set swapped_oneof; + GOOGLE_DCHECK(!unsafe_shallow_swap || message1->GetArenaForAllocation() == + message2->GetArenaForAllocation()); + const Message* prototype = message_factory_->GetPrototype(message1->GetDescriptor()); for (const auto* field : fields) { @@ -1140,9 +1073,6 @@ void Reflection::SwapFields( void Reflection::UnsafeShallowSwapFields( Message* message1, Message* message2, const std::vector& fields) const { - GOOGLE_DCHECK_EQ(message1->GetArenaForAllocation(), - message2->GetArenaForAllocation()); - SwapFieldsImpl(message1, message2, fields); } @@ -1173,11 +1103,6 @@ bool Reflection::HasField(const Message& message, } void Reflection::UnsafeArenaSwap(Message* lhs, Message* rhs) const { - GOOGLE_DCHECK_EQ(lhs->GetOwningArena(), rhs->GetOwningArena()); - InternalSwap(lhs, rhs); -} - -void Reflection::InternalSwap(Message* lhs, Message* rhs) const { if (lhs == rhs) return; MutableInternalMetadata(lhs)->InternalSwap(MutableInternalMetadata(rhs)); @@ -1186,14 +1111,8 @@ void Reflection::InternalSwap(Message* lhs, Message* rhs) const { const FieldDescriptor* field = descriptor_->field(i); if (schema_.InRealOneof(field)) continue; if (schema_.IsFieldStripped(field)) continue; - if (schema_.IsSplit(field)) { - continue; - } UnsafeShallowSwapField(lhs, rhs, field); } - if (schema_.IsSplit()) { - std::swap(*MutableSplitField(lhs), *MutableSplitField(rhs)); - } const int oneof_decl_count = descriptor_->oneof_decl_count(); for (int i = 0; i < oneof_decl_count; i++) { const OneofDescriptor* oneof = descriptor_->oneof_decl(i); @@ -2491,7 +2410,7 @@ int Reflection::MapSize(const Message& message, // ----------------------------------------------------------------------------- const FieldDescriptor* Reflection::FindKnownExtensionByName( - absl::string_view name) const { + const std::string& name) const { if (!schema_.HasExtensionSet()) return nullptr; return descriptor_pool_->FindExtensionByPrintableName(descriptor_, name); } @@ -2515,35 +2434,13 @@ bool Reflection::SupportsUnknownEnumValues() const { template const Type& Reflection::GetRawNonOneof(const Message& message, const FieldDescriptor* field) const { - if (schema_.IsSplit(field)) { - return *GetConstPointerAtOffset( - GetSplitField(&message), schema_.GetFieldOffsetNonOneof(field)); - } return GetConstRefAtOffset(message, schema_.GetFieldOffsetNonOneof(field)); } -void Reflection::PrepareSplitMessageForWrite(Message* message) const { - GOOGLE_DCHECK_NE(message, schema_.default_instance_); - void** split = MutableSplitField(message); - const void* default_split = GetSplitField(schema_.default_instance_); - if (*split == default_split) { - uint32_t size = schema_.SizeofSplit(); - Arena* arena = message->GetArenaForAllocation(); - *split = (arena == nullptr) ? ::operator new(size) - : arena->AllocateAligned(size); - memcpy(*split, default_split, size); - } -} - template Type* Reflection::MutableRawNonOneof(Message* message, const FieldDescriptor* field) const { - if (schema_.IsSplit(field)) { - PrepareSplitMessageForWrite(message); - return GetPointerAtOffset(*MutableSplitField(message), - schema_.GetFieldOffsetNonOneof(field)); - } return GetPointerAtOffset(message, schema_.GetFieldOffsetNonOneof(field)); } @@ -2551,11 +2448,6 @@ Type* Reflection::MutableRawNonOneof(Message* message, template Type* Reflection::MutableRaw(Message* message, const FieldDescriptor* field) const { - if (schema_.IsSplit(field)) { - PrepareSplitMessageForWrite(message); - return GetPointerAtOffset(*MutableSplitField(message), - schema_.GetFieldOffset(field)); - } return GetPointerAtOffset(message, schema_.GetFieldOffset(field)); } @@ -2972,366 +2864,6 @@ const MapFieldBase* Reflection::GetMapData(const Message& message, return &(GetRaw(message, field)); } -template -static uint32_t AlignTo(uint32_t v) { - return (v + alignof(T) - 1) & ~(alignof(T) - 1); -} - -static internal::TailCallParseFunc GetFastParseFunction( - absl::string_view name) { - // This list must be synchronized with TcParser. - // Missing entries are replaced with MiniParse in opt mode to avoid runtime - // failures. It check-fails in debug mode. - static const auto* const map = - new absl::flat_hash_map{ - {"::_pbi::TcParser::FastF32S1", internal::TcParser::FastF32S1}, - {"::_pbi::TcParser::FastF32S2", internal::TcParser::FastF32S2}, - {"::_pbi::TcParser::FastF32R1", internal::TcParser::FastF32R1}, - {"::_pbi::TcParser::FastF32R2", internal::TcParser::FastF32R2}, - {"::_pbi::TcParser::FastF32P1", internal::TcParser::FastF32P1}, - {"::_pbi::TcParser::FastF32P2", internal::TcParser::FastF32P2}, - {"::_pbi::TcParser::FastF64S1", internal::TcParser::FastF64S1}, - {"::_pbi::TcParser::FastF64S2", internal::TcParser::FastF64S2}, - {"::_pbi::TcParser::FastF64R1", internal::TcParser::FastF64R1}, - {"::_pbi::TcParser::FastF64R2", internal::TcParser::FastF64R2}, - {"::_pbi::TcParser::FastF64P1", internal::TcParser::FastF64P1}, - {"::_pbi::TcParser::FastF64P2", internal::TcParser::FastF64P2}, - {"::_pbi::TcParser::FastV8S1", internal::TcParser::FastV8S1}, - {"::_pbi::TcParser::FastV8S2", internal::TcParser::FastV8S2}, - {"::_pbi::TcParser::FastV8R1", internal::TcParser::FastV8R1}, - {"::_pbi::TcParser::FastV8R2", internal::TcParser::FastV8R2}, - {"::_pbi::TcParser::FastV8P1", internal::TcParser::FastV8P1}, - {"::_pbi::TcParser::FastV8P2", internal::TcParser::FastV8P2}, - {"::_pbi::TcParser::FastV32S1", internal::TcParser::FastV32S1}, - {"::_pbi::TcParser::FastV32S2", internal::TcParser::FastV32S2}, - {"::_pbi::TcParser::FastV32R1", internal::TcParser::FastV32R1}, - {"::_pbi::TcParser::FastV32R2", internal::TcParser::FastV32R2}, - {"::_pbi::TcParser::FastV32P1", internal::TcParser::FastV32P1}, - {"::_pbi::TcParser::FastV32P2", internal::TcParser::FastV32P2}, - {"::_pbi::TcParser::FastV64S1", internal::TcParser::FastV64S1}, - {"::_pbi::TcParser::FastV64S2", internal::TcParser::FastV64S2}, - {"::_pbi::TcParser::FastV64R1", internal::TcParser::FastV64R1}, - {"::_pbi::TcParser::FastV64R2", internal::TcParser::FastV64R2}, - {"::_pbi::TcParser::FastV64P1", internal::TcParser::FastV64P1}, - {"::_pbi::TcParser::FastV64P2", internal::TcParser::FastV64P2}, - {"::_pbi::TcParser::FastZ32S1", internal::TcParser::FastZ32S1}, - {"::_pbi::TcParser::FastZ32S2", internal::TcParser::FastZ32S2}, - {"::_pbi::TcParser::FastZ32R1", internal::TcParser::FastZ32R1}, - {"::_pbi::TcParser::FastZ32R2", internal::TcParser::FastZ32R2}, - {"::_pbi::TcParser::FastZ32P1", internal::TcParser::FastZ32P1}, - {"::_pbi::TcParser::FastZ32P2", internal::TcParser::FastZ32P2}, - {"::_pbi::TcParser::FastZ64S1", internal::TcParser::FastZ64S1}, - {"::_pbi::TcParser::FastZ64S2", internal::TcParser::FastZ64S2}, - {"::_pbi::TcParser::FastZ64R1", internal::TcParser::FastZ64R1}, - {"::_pbi::TcParser::FastZ64R2", internal::TcParser::FastZ64R2}, - {"::_pbi::TcParser::FastZ64P1", internal::TcParser::FastZ64P1}, - {"::_pbi::TcParser::FastZ64P2", internal::TcParser::FastZ64P2}, - {"::_pbi::TcParser::FastErS1", internal::TcParser::FastErS1}, - {"::_pbi::TcParser::FastErS2", internal::TcParser::FastErS2}, - {"::_pbi::TcParser::FastErR1", internal::TcParser::FastErR1}, - {"::_pbi::TcParser::FastErR2", internal::TcParser::FastErR2}, - {"::_pbi::TcParser::FastEr0S1", internal::TcParser::FastEr0S1}, - {"::_pbi::TcParser::FastEr0S2", internal::TcParser::FastEr0S2}, - {"::_pbi::TcParser::FastEr0R1", internal::TcParser::FastEr0R1}, - {"::_pbi::TcParser::FastEr0R2", internal::TcParser::FastEr0R2}, - {"::_pbi::TcParser::FastEr1S1", internal::TcParser::FastEr1S1}, - {"::_pbi::TcParser::FastEr1S2", internal::TcParser::FastEr1S2}, - {"::_pbi::TcParser::FastEr1R1", internal::TcParser::FastEr1R1}, - {"::_pbi::TcParser::FastEr1R2", internal::TcParser::FastEr1R2}, - {"::_pbi::TcParser::FastEvS1", internal::TcParser::FastEvS1}, - {"::_pbi::TcParser::FastEvS2", internal::TcParser::FastEvS2}, - {"::_pbi::TcParser::FastEvR1", internal::TcParser::FastEvR1}, - {"::_pbi::TcParser::FastEvR2", internal::TcParser::FastEvR2}, - {"::_pbi::TcParser::FastBS1", internal::TcParser::FastBS1}, - {"::_pbi::TcParser::FastBS2", internal::TcParser::FastBS2}, - {"::_pbi::TcParser::FastBR1", internal::TcParser::FastBR1}, - {"::_pbi::TcParser::FastBR2", internal::TcParser::FastBR2}, - {"::_pbi::TcParser::FastSS1", internal::TcParser::FastSS1}, - {"::_pbi::TcParser::FastSS2", internal::TcParser::FastSS2}, - {"::_pbi::TcParser::FastSR1", internal::TcParser::FastSR1}, - {"::_pbi::TcParser::FastSR2", internal::TcParser::FastSR2}, - {"::_pbi::TcParser::FastUS1", internal::TcParser::FastUS1}, - {"::_pbi::TcParser::FastUS2", internal::TcParser::FastUS2}, - {"::_pbi::TcParser::FastUR1", internal::TcParser::FastUR1}, - {"::_pbi::TcParser::FastUR2", internal::TcParser::FastUR2}, - {"::_pbi::TcParser::FastBiS1", internal::TcParser::FastBiS1}, - {"::_pbi::TcParser::FastBiS2", internal::TcParser::FastBiS2}, - {"::_pbi::TcParser::FastSiS1", internal::TcParser::FastSiS1}, - {"::_pbi::TcParser::FastSiS2", internal::TcParser::FastSiS2}, - {"::_pbi::TcParser::FastUiS1", internal::TcParser::FastUiS1}, - {"::_pbi::TcParser::FastUiS2", internal::TcParser::FastUiS2}, - {"::_pbi::TcParser::FastMdS1", internal::TcParser::FastMdS1}, - {"::_pbi::TcParser::FastMdS2", internal::TcParser::FastMdS2}, - {"::_pbi::TcParser::FastGdS1", internal::TcParser::FastGdS1}, - {"::_pbi::TcParser::FastGdS2", internal::TcParser::FastGdS2}, - {"::_pbi::TcParser::FastMtS1", internal::TcParser::FastMtS1}, - {"::_pbi::TcParser::FastMtS2", internal::TcParser::FastMtS2}, - {"::_pbi::TcParser::FastGtS1", internal::TcParser::FastGtS1}, - {"::_pbi::TcParser::FastGtS2", internal::TcParser::FastGtS2}, - {"::_pbi::TcParser::FastMdR1", internal::TcParser::FastMdR1}, - {"::_pbi::TcParser::FastMdR2", internal::TcParser::FastMdR2}, - {"::_pbi::TcParser::FastGdR1", internal::TcParser::FastGdR1}, - {"::_pbi::TcParser::FastGdR2", internal::TcParser::FastGdR2}, - {"::_pbi::TcParser::FastMtR1", internal::TcParser::FastMtR1}, - {"::_pbi::TcParser::FastMtR2", internal::TcParser::FastMtR2}, - {"::_pbi::TcParser::FastGtR1", internal::TcParser::FastGtR1}, - {"::_pbi::TcParser::FastGtR2", internal::TcParser::FastGtR2}, - {"::_pbi::TcParser::FastEndG1", internal::TcParser::FastEndG1}, - {"::_pbi::TcParser::FastEndG2", internal::TcParser::FastEndG2}, - }; - auto it = map->find(name); - if (it == map->end()) { - GOOGLE_LOG(DFATAL) << "Failed to find function: " << name; - // Let's not crash in opt, just in case. - // MiniParse is always a valid parser. - return &internal::TcParser::MiniParse; - } - return it->second; -} - -const internal::TcParseTableBase* Reflection::CreateTcParseTableForMessageSet() - const { - // ParseLoop can't parse message set wire format. - // Create a dummy table that only exists to make TcParser::ParseLoop jump - // into the reflective parse loop. - - using Table = internal::TcParseTable<0, 0, 0, 0, 1>; - // We use `operator new` here because the destruction will be done with - // `operator delete` unconditionally. - void* p = ::operator new(sizeof(Table)); - auto* full_table = ::new (p) Table{ - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, schema_.default_instance_, nullptr}, - {{{&internal::TcParser::ReflectionParseLoop, {}}}}}; - GOOGLE_DCHECK_EQ(static_cast(&full_table->header), - static_cast(full_table)); - return &full_table->header; -} - -void Reflection::PopulateTcParseFastEntries( - const internal::TailCallTableInfo& table_info, - TcParseTableBase::FastFieldEntry* fast_entries) const { - for (const auto& fast_field : table_info.fast_path_fields) { - if (fast_field.field == nullptr) { - if (fast_field.func_name.empty()) { - // No fast entry here. Use mini parser. - *fast_entries++ = {internal::TcParser::MiniParse, {}}; - } else { - // No field, but still a special entry. - *fast_entries++ = {GetFastParseFunction(fast_field.func_name), - {fast_field.coded_tag, fast_field.nonfield_info}}; - } - } else if (fast_field.func_name.find("TcParser::FastEv") != - fast_field.func_name.npos) { - // We can't use fast parsing for these entries because we can't specify - // the validator. Use the reflection based parser called from MiniParse. - // TODO(b/239592582): Implement a fast parser for these enums. - *fast_entries++ = {internal::TcParser::MiniParse, {}}; - } else { - *fast_entries++ = { - GetFastParseFunction(fast_field.func_name), - {fast_field.coded_tag, fast_field.hasbit_idx, fast_field.aux_idx, - static_cast(schema_.GetFieldOffset(fast_field.field))}}; - } - } -} - -static void PopulateTcParseLookupTable( - const internal::TailCallTableInfo& table_info, uint16_t* lookup_table) { - for (const auto& entry_block : table_info.num_to_entry_table.blocks) { - *lookup_table++ = entry_block.first_fnum & 0xFFFF; - *lookup_table++ = entry_block.first_fnum >> 16; - *lookup_table++ = entry_block.entries.size(); - for (auto se16 : entry_block.entries) { - *lookup_table++ = se16.skipmap; - *lookup_table++ = se16.field_entry_offset; - } - } - *lookup_table++ = 0xFFFF; - *lookup_table++ = 0xFFFF; -} - -void Reflection::PopulateTcParseEntries( - internal::TailCallTableInfo& table_info, - TcParseTableBase::FieldEntry* entries) const { - for (const auto& entry : table_info.field_entries) { - const FieldDescriptor* field = entry.field; - if (field->options().weak()) { - // Weak fields are handled by the generated fallback function. - // (These are handled by legacy Google-internal logic.) - *entries = {}; - } else if (field->type() == field->TYPE_ENUM && - table_info.aux_entries[entry.aux_idx].type == - internal::TailCallTableInfo::kEnumValidator) { - // Mini parse can't handle it. Fallback to reflection. - *entries = {}; - table_info.aux_entries[entry.aux_idx] = {}; - } else { - const OneofDescriptor* oneof = field->real_containing_oneof(); - entries->offset = schema_.GetFieldOffset(field); - if (oneof != nullptr) { - entries->has_idx = schema_.oneof_case_offset_ + 4 * oneof->index(); - } else if (schema_.HasHasbits()) { - entries->has_idx = - static_cast(8 * schema_.HasBitsOffset() + entry.hasbit_idx); - } else { - entries->has_idx = 0; - } - entries->aux_idx = entry.aux_idx; - entries->type_card = entry.type_card; - } - - ++entries; - } -} - -void Reflection::PopulateTcParseFieldAux( - const internal::TailCallTableInfo& table_info, - TcParseTableBase::FieldAux* field_aux) const { - for (const auto& aux_entry : table_info.aux_entries) { - switch (aux_entry.type) { - case internal::TailCallTableInfo::kNothing: - *field_aux++ = {}; - break; - case internal::TailCallTableInfo::kInlinedStringDonatedOffset: - field_aux++->offset = - static_cast(schema_.inlined_string_donated_offset_); - break; - case internal::TailCallTableInfo::kSplitOffset: - field_aux++->offset = schema_.SplitOffset(); - break; - case internal::TailCallTableInfo::kSplitSizeof: - field_aux++->offset = schema_.SizeofSplit(); - break; - case internal::TailCallTableInfo::kSubTable: - case internal::TailCallTableInfo::kSubMessageWeak: - GOOGLE_LOG(FATAL) << "Not supported"; - break; - case internal::TailCallTableInfo::kSubMessage: - field_aux++->message_default_p = - GetDefaultMessageInstance(aux_entry.field); - break; - case internal::TailCallTableInfo::kEnumRange: - field_aux++->enum_range = {aux_entry.enum_range.start, - aux_entry.enum_range.size}; - break; - case internal::TailCallTableInfo::kEnumValidator: - GOOGLE_LOG(FATAL) << "Not supported."; - break; - case internal::TailCallTableInfo::kNumericOffset: - field_aux++->offset = aux_entry.offset; - break; - } - } -} - -const internal::TcParseTableBase* Reflection::CreateTcParseTable() const { - using TcParseTableBase = internal::TcParseTableBase; - - if (descriptor_->options().message_set_wire_format()) { - return CreateTcParseTableForMessageSet(); - } - - std::vector fields; - constexpr int kNoHasbit = -1; - std::vector has_bit_indices( - static_cast(descriptor_->field_count()), kNoHasbit); - std::vector inlined_string_indices = has_bit_indices; - for (int i = 0; i < descriptor_->field_count(); ++i) { - auto* field = descriptor_->field(i); - if (schema_.IsFieldStripped(field)) continue; - - fields.push_back(field); - has_bit_indices[static_cast(field->index())] = - static_cast(schema_.HasBitIndex(field)); - - if (IsInlined(field)) { - inlined_string_indices[static_cast(field->index())] = - schema_.InlinedStringIndex(field); - } - } - std::sort(fields.begin(), fields.end(), - [](const FieldDescriptor* a, const FieldDescriptor* b) { - return a->number() < b->number(); - }); - - class ReflectionOptionProvider final - : public internal::TailCallTableInfo::OptionProvider { - public: - explicit ReflectionOptionProvider(const Reflection& ref) : ref_(ref) {} - internal::TailCallTableInfo::PerFieldOptions GetForField( - const FieldDescriptor* field) const final { - return {ref_.IsLazyField(field), // - ref_.IsInlined(field), // - - // Only LITE can be implicitly weak. - /* is_implicitly_weak */ false, - - // We could change this to use direct table. - // Might be easier to do when all messages support TDP. - /* use_direct_tcparser_table */ false, - - /* is_lite */ false, // - ref_.schema_.IsSplit(field)}; - } - - private: - const Reflection& ref_; - }; - internal::TailCallTableInfo table_info( - descriptor_, fields, ReflectionOptionProvider(*this), has_bit_indices, - inlined_string_indices); - - const size_t fast_entries_count = table_info.fast_path_fields.size(); - GOOGLE_CHECK_EQ(fast_entries_count, 1 << table_info.table_size_log2); - const uint16_t lookup_table_offset = AlignTo( - sizeof(TcParseTableBase) + - fast_entries_count * sizeof(TcParseTableBase::FastFieldEntry)); - const uint32_t field_entry_offset = AlignTo( - lookup_table_offset + - sizeof(uint16_t) * table_info.num_to_entry_table.size16()); - const uint32_t aux_offset = AlignTo( - field_entry_offset + - sizeof(TcParseTableBase::FieldEntry) * fields.size()); - - int byte_size = - aux_offset + - sizeof(TcParseTableBase::FieldAux) * table_info.aux_entries.size() + - sizeof(char) * table_info.field_name_data.size(); - - void* p = ::operator new(byte_size); - auto* res = ::new (p) TcParseTableBase{ - static_cast(schema_.HasHasbits() ? schema_.HasBitsOffset() : 0), - // extensions handled through reflection. - 0, 0, 0, - static_cast(fields.empty() ? 0 : fields.back()->number()), - static_cast((fast_entries_count - 1) << 3), lookup_table_offset, - table_info.num_to_entry_table.skipmap32, field_entry_offset, - static_cast(fields.size()), - static_cast(table_info.aux_entries.size()), aux_offset, - schema_.default_instance_, &internal::TcParser::ReflectionFallback}; - - // Now copy the rest of the payloads - PopulateTcParseFastEntries(table_info, res->fast_entry(0)); - - PopulateTcParseLookupTable(table_info, res->field_lookup_begin()); - - PopulateTcParseEntries(table_info, res->field_entries_begin()); - - PopulateTcParseFieldAux(table_info, res->field_aux(0u)); - - // Copy the name data. - if (!table_info.field_name_data.empty()) { - memcpy(res->name_data(), table_info.field_name_data.data(), - table_info.field_name_data.size()); - } - // Validation to make sure we used all the bytes correctly. - GOOGLE_CHECK_EQ(res->name_data() + table_info.field_name_data.size() - - reinterpret_cast(res), - byte_size); - - return res; -} - namespace { // Helper function to transform migration schema into reflection schema. @@ -3340,11 +2872,9 @@ ReflectionSchema MigrationToReflectionSchema( MigrationSchema migration_schema) { ReflectionSchema result; result.default_instance_ = *default_instance; - // First 9 offsets are offsets to the special fields. The following offsets + // First 7 offsets are offsets to the special fields. The following offsets // are the proto fields. - // - // TODO(congliu): Find a way to not encode sizeof_split_ in offsets. - result.offsets_ = offsets + migration_schema.offsets_index + 8; + result.offsets_ = offsets + migration_schema.offsets_index + 6; result.has_bit_indices_ = offsets + migration_schema.has_bit_indices_index; result.has_bits_offset_ = offsets[migration_schema.offsets_index + 0]; result.metadata_offset_ = offsets[migration_schema.offsets_index + 1]; @@ -3354,8 +2884,6 @@ ReflectionSchema MigrationToReflectionSchema( result.weak_field_map_offset_ = offsets[migration_schema.offsets_index + 4]; result.inlined_string_donated_offset_ = offsets[migration_schema.offsets_index + 5]; - result.split_offset_ = offsets[migration_schema.offsets_index + 6]; - result.sizeof_split_ = offsets[migration_schema.offsets_index + 7]; result.inlined_string_indices_ = offsets + migration_schema.inlined_string_indices_index; return result; @@ -3442,7 +2970,7 @@ struct MetadataOwner { private: MetadataOwner() = default; // private because singleton - absl::Mutex mu_; + WrappedMutex mu_; std::vector > metadata_arrays_; }; @@ -3453,7 +2981,7 @@ void AssignDescriptorsImpl(const DescriptorTable* table, bool eager) { { // This only happens once per proto file. So a global mutex to serialize // calls to AddDescriptors. - static absl::Mutex mu{absl::kConstInit}; + static WrappedMutex mu{GOOGLE_PROTOBUF_LINKER_INITIALIZED}; mu.Lock(); AddDescriptors(table); mu.Unlock(); @@ -3548,8 +3076,9 @@ void RegisterAllTypesInternal(const Metadata* file_level_metadata, int size) { namespace internal { Metadata AssignDescriptors(const DescriptorTable* (*table)(), - absl::once_flag* once, const Metadata& metadata) { - absl::call_once(*once, [=] { + internal::once_flag* once, + const Metadata& metadata) { + call_once(*once, [=] { auto* t = table(); AssignDescriptorsImpl(t, t->is_eager); }); @@ -3559,7 +3088,7 @@ Metadata AssignDescriptors(const DescriptorTable* (*table)(), void AssignDescriptors(const DescriptorTable* table, bool eager) { if (!eager) eager = table->is_eager; - absl::call_once(*table->once, AssignDescriptorsImpl, table, eager); + call_once(*table->once, AssignDescriptorsImpl, table, eager); } AddDescriptorsRunner::AddDescriptorsRunner(const DescriptorTable* table) { @@ -3636,4 +3165,4 @@ bool IsDescendant(Message& root, const Message& message) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/generated_message_reflection.h b/libs/protobuf/src/google/protobuf/generated_message_reflection.h index 70a75aa..334b2cc 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_reflection.h +++ b/libs/protobuf/src/google/protobuf/generated_message_reflection.h @@ -38,19 +38,17 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ -#include +#include +#include +#include +#include +#include +#include +#include -#include "google/protobuf/stubs/common.h" -#include "absl/base/call_once.h" -#include "absl/base/casts.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/port.h" -#include "google/protobuf/unknown_field_set.h" // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -74,16 +72,6 @@ class DefaultEmptyOneof; class ExtensionSet; // extension_set.h class WeakFieldMap; // weak_field_map.h -// Tag used on offsets for fields that don't have a real offset. -// For example, weak message fields go into the WeakFieldMap and not in an -// actual field. -constexpr uint32_t kInvalidFieldOffsetTag = 0x40000000u; - -// Mask used on offsets for split fields. -constexpr uint32_t kSplitFieldOffsetMask = 0x80000000u; -constexpr uint32_t kLazyMask = 0x1u; -constexpr uint32_t kInlinedMask = 0x1u; - // This struct describes the internal layout of the message, hence this is // used to act on the message reflectively. // default_instance: The default instance of the message. This is only @@ -246,24 +234,6 @@ struct ReflectionSchema { return false; } - bool IsSplit() const { return split_offset_ != -1; } - - bool IsSplit(const FieldDescriptor* field) const { - return split_offset_ != -1 && - (offsets_[field->index()] & kSplitFieldOffsetMask) != 0; - } - - // Byte offset of _split_. - uint32_t SplitOffset() const { - GOOGLE_DCHECK(IsSplit()); - return static_cast(split_offset_); - } - - uint32_t SizeofSplit() const { - GOOGLE_DCHECK(IsSplit()); - return static_cast(sizeof_split_); - } - bool HasWeakFields() const { return weak_field_map_offset_ > 0; } @@ -284,8 +254,6 @@ struct ReflectionSchema { int weak_field_map_offset_; const uint32_t* inlined_string_indices_; int inlined_string_donated_offset_; - int split_offset_; - int sizeof_split_; // We tag offset values to provide additional data about fields (such as // "unused" or "lazy" or "inlined"). @@ -293,15 +261,15 @@ struct ReflectionSchema { if (type == FieldDescriptor::TYPE_MESSAGE || type == FieldDescriptor::TYPE_STRING || type == FieldDescriptor::TYPE_BYTES) { - return v & (~kSplitFieldOffsetMask) & (~kInlinedMask) & (~kLazyMask); + return v & 0xFFFFFFFEu; } - return v & (~kSplitFieldOffsetMask); + return v; } static bool Inlined(uint32_t v, FieldDescriptor::Type type) { if (type == FieldDescriptor::TYPE_STRING || type == FieldDescriptor::TYPE_BYTES) { - return (v & kInlinedMask) != 0u; + return (v & 1u) != 0u; } else { // Non string/byte fields are not inlined. return false; @@ -331,7 +299,7 @@ struct PROTOBUF_EXPORT DescriptorTable { int size; // of serialized descriptor const char* descriptor; const char* filename; - absl::once_flag* once; + once_flag* once; const DescriptorTable* const* deps; int num_deps; int num_messages; @@ -344,6 +312,13 @@ struct PROTOBUF_EXPORT DescriptorTable { const ServiceDescriptor** file_level_service_descriptors; }; +enum { + // Tag used on offsets for fields that don't have a real offset. + // For example, weak message fields go into the WeakFieldMap and not in an + // actual field. + kInvalidFieldOffsetTag = 0x40000000u, +}; + // AssignDescriptors() pulls the compiled FileDescriptor from the DescriptorPool // and uses it to populate all of the global variables which store pointers to // the descriptor objects. It also constructs the reflection objects. It is @@ -357,7 +332,7 @@ void PROTOBUF_EXPORT AssignDescriptors(const DescriptorTable* table, // It takes a `Metadata` and returns it to allow for tail calls and reduce // binary size. Metadata PROTOBUF_EXPORT AssignDescriptors(const DescriptorTable* (*table)(), - absl::once_flag* once, + internal::once_flag* once, const Metadata& metadata); // These cannot be in lite so we put them in the reflection. @@ -370,38 +345,10 @@ struct PROTOBUF_EXPORT AddDescriptorsRunner { explicit AddDescriptorsRunner(const DescriptorTable* table); }; -struct DenseEnumCacheInfo { - std::atomic cache; - int min_val; - int max_val; - const EnumDescriptor* (*descriptor_fn)(); -}; -PROTOBUF_EXPORT const std::string& NameOfDenseEnumSlow(int v, - DenseEnumCacheInfo*); - -// Similar to the routine NameOfEnum, this routine returns the name of an enum. -// Unlike that routine, it allocates, on-demand, a block of pointers to the -// std::string objects allocated by reflection to store the enum names. This -// way, as long as the enum values are fairly dense, looking them up can be -// very fast. This assumes all the enums fall in the range [min_val .. max_val]. -template -const std::string& NameOfDenseEnum(int v) { - static_assert(max_val - min_val >= 0, "Too many enums between min and max."); - static DenseEnumCacheInfo deci = {/* atomic ptr */ {}, min_val, max_val, - descriptor_fn}; - const std::string** cache = deci.cache.load(std::memory_order_acquire ); - if (PROTOBUF_PREDICT_TRUE(cache != nullptr)) { - if (PROTOBUF_PREDICT_TRUE(v >= min_val && v <= max_val)) { - return *cache[v - min_val]; - } - } - return NameOfDenseEnumSlow(v, &deci); -} - } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc b/libs/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc index 83f2ec6..50ce399 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc @@ -42,26 +42,25 @@ // compiler/cpp/unittest, except using the reflection interface // rather than generated accessors. -#include "google/protobuf/generated_message_reflection.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_mset.pb.h" -#include "google/protobuf/unittest_mset_wire_format.pb.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/cord.h" -#include "google/protobuf/map_test_util.h" -#include "google/protobuf/test_util.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -1262,6 +1261,8 @@ TEST(GeneratedMessageReflectionTest, UsageErrors) { const Reflection* reflection = message.GetReflection(); const Descriptor* descriptor = message.GetDescriptor(); +#define f(NAME) descriptor->FindFieldByName(NAME) + // Testing every single failure mode would be too much work. Let's just // check a few. EXPECT_DEATH( @@ -1300,6 +1301,8 @@ TEST(GeneratedMessageReflectionTest, UsageErrors) { " Message type: protobuf_unittest.TestAllTypes\n" " Field : protobuf_unittest.ForeignMessage.c\n" " Problem : Field does not match message type."); + +#undef f } #endif // PROTOBUF_HAS_DEATH_TEST diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_decl.h b/libs/protobuf/src/google/protobuf/generated_message_tctable_decl.h index dd4845b..b1bb1de 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_decl.h +++ b/libs/protobuf/src/google/protobuf/generated_message_tctable_decl.h @@ -36,16 +36,15 @@ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_DECL_H__ #include -#include #include #include #include -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" +#include +#include // Must come last: -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -86,27 +85,6 @@ struct TcFieldData { uint8_t aux_idx() const { return static_cast(data >> 24); } uint16_t offset() const { return static_cast(data >> 48); } - // Constructor for special entries that do not represent a field. - // - End group: `nonfield_info` is the decoded tag. - constexpr TcFieldData(uint16_t coded_tag, uint16_t nonfield_info) - : data(uint64_t{nonfield_info} << 16 | // - uint64_t{coded_tag}) {} - - // Fields used in non-field entries - // - // Bit: - // +-----------+-------------------+ - // |63 .. 32|31 .. 0| - // +---------------+---------------+ - // : . : . : . 16|=======| [16] coded_tag() - // : . : . 32|=======| . : [16] decoded_tag() - // :---.---:---.---: . : . : [32] (unused) - // +-----------+-------------------+ - // |63 .. 32|31 .. 0| - // +---------------+---------------+ - - uint16_t decoded_tag() const { return static_cast(data >> 16); } - // Fields used in mini table parsing: // // Bit: @@ -142,8 +120,6 @@ struct Offset { #pragma warning(disable : 4324) #endif -struct FieldAuxDefaultMessage {}; - // Base class for message-level table with info for the tail-call parser. struct alignas(uint64_t) TcParseTableBase { // Common attributes for message layout: @@ -197,58 +173,25 @@ struct alignas(uint64_t) TcParseTableBase { // Table entry for fast-path tailcall dispatch handling. struct FastFieldEntry { // Target function for dispatch: - mutable std::atomic target_atomic; - + TailCallParseFunc target; // Field data used during parse: TcFieldData bits; - - // Default initializes this instance with undefined values. - FastFieldEntry() = default; - - // Constant initializes this instance - constexpr FastFieldEntry(TailCallParseFunc func, TcFieldData bits) - : target_atomic(func), bits(bits) {} - - // FastFieldEntry is copy-able and assignable, which is intended - // mainly for testing and debugging purposes. - FastFieldEntry(const FastFieldEntry& rhs) noexcept - : FastFieldEntry(rhs.target(), rhs.bits) {} - FastFieldEntry& operator=(const FastFieldEntry& rhs) noexcept { - SetTarget(rhs.target()); - bits = rhs.bits; - return *this; - } - - // Protocol buffer code should use these relaxed accessors. - TailCallParseFunc target() const { - return target_atomic.load(std::memory_order_relaxed); - } - void SetTarget(TailCallParseFunc func) const { - return target_atomic.store(func, std::memory_order_relaxed); - } }; // There is always at least one table entry. const FastFieldEntry* fast_entry(size_t idx) const { return reinterpret_cast(this + 1) + idx; } - FastFieldEntry* fast_entry(size_t idx) { - return reinterpret_cast(this + 1) + idx; - } // Returns a begin iterator (pointer) to the start of the field lookup table. const uint16_t* field_lookup_begin() const { return reinterpret_cast(reinterpret_cast(this) + lookup_table_offset); } - uint16_t* field_lookup_begin() { - return reinterpret_cast(reinterpret_cast(this) + - lookup_table_offset); - } // Field entry for all fields. struct FieldEntry { uint32_t offset; // offset in the message object - int32_t has_idx; // has-bit index, relative to the message object + int32_t has_idx; // has-bit index uint16_t aux_idx; // index for `field_aux`. uint16_t type_card; // `FieldType` and `Cardinality` (see _impl.h) }; @@ -258,49 +201,29 @@ struct alignas(uint64_t) TcParseTableBase { return reinterpret_cast( reinterpret_cast(this) + field_entries_offset); } - FieldEntry* field_entries_begin() { - return reinterpret_cast(reinterpret_cast(this) + - field_entries_offset); - } // Auxiliary entries for field types that need extra information. union FieldAux { - constexpr FieldAux() : message_default_p(nullptr) {} + constexpr FieldAux() : message_default(nullptr) {} constexpr FieldAux(bool (*enum_validator)(int)) : enum_validator(enum_validator) {} constexpr FieldAux(field_layout::Offset off) : offset(off.off) {} constexpr FieldAux(int16_t range_start, uint16_t range_length) : enum_range{range_start, range_length} {} - constexpr FieldAux(const MessageLite* msg) : message_default_p(msg) {} - constexpr FieldAux(FieldAuxDefaultMessage, const void* msg) - : message_default_p(msg) {} - constexpr FieldAux(const TcParseTableBase* table) : table(table) {} + constexpr FieldAux(const MessageLite* msg) : message_default(msg) {} bool (*enum_validator)(int); struct { int16_t start; // minimum enum number (if it fits) uint16_t length; // length of range (i.e., max = start + length - 1) } enum_range; uint32_t offset; - const void* message_default_p; - const TcParseTableBase* table; - - const MessageLite* message_default() const { - return static_cast(message_default_p); - } - const MessageLite* message_default_weak() const { - return *static_cast(message_default_p); - } + const MessageLite* message_default; }; const FieldAux* field_aux(uint32_t idx) const { return reinterpret_cast(reinterpret_cast(this) + aux_offset) + idx; } - FieldAux* field_aux(uint32_t idx) { - return reinterpret_cast(reinterpret_cast(this) + - aux_offset) + - idx; - } const FieldAux* field_aux(const FieldEntry* entry) const { return field_aux(entry->aux_idx); } @@ -311,11 +234,6 @@ struct alignas(uint64_t) TcParseTableBase { aux_offset + num_aux_entries * sizeof(FieldAux)); } - char* name_data() { - return reinterpret_cast(reinterpret_cast(this) + - aux_offset + - num_aux_entries * sizeof(FieldAux)); - } }; #if defined(_MSC_VER) && !defined(_WIN64) @@ -347,7 +265,7 @@ struct TcParseTable { // Entries for all fields: std::array field_entries; std::array aux_entries; - std::array field_names; + std::array field_names; }; // Partial specialization: if there are no aux entries, there will be no array. @@ -363,7 +281,7 @@ struct TcParseTable field_lookup_table; std::array field_entries; - std::array field_names; + std::array field_names; }; // Partial specialization: if there are no fields at all, then we can save space @@ -375,7 +293,7 @@ struct TcParseTable<0, 0, 0, kNameTableSize, kFieldLookupSize> { // The fast parsing loop will always use this entry, so it must be present. std::array fast_entries; std::array field_lookup_table; - std::array field_names; + std::array field_names; }; static_assert(std::is_standard_layout>::value, @@ -389,6 +307,6 @@ static_assert(offsetof(TcParseTable<1>, fast_entries) == } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_DECL_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_full.cc b/libs/protobuf/src/google/protobuf/generated_message_tctable_full.cc index f224d4c..b77bb8d 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_full.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_tctable_full.cc @@ -30,61 +30,24 @@ #include -#include "google/protobuf/extension_set.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/message.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format.h" +#include +#include +#include +#include +#include -// must be last -#include "google/protobuf/port_def.inc" +// clang-format off +#include +// clang-format on namespace google { namespace protobuf { namespace internal { -using ::google::protobuf::internal::DownCast; const char* TcParser::GenericFallback(PROTOBUF_TC_PARAM_DECL) { return GenericFallbackImpl(PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::ReflectionFallback(PROTOBUF_TC_PARAM_DECL) { - SyncHasbits(msg, hasbits, table); - uint32_t tag = data.tag(); - if (tag == 0 || (tag & 7) == WireFormatLite::WIRETYPE_END_GROUP) { - ctx->SetLastTag(tag); - return ptr; - } - - auto* full_msg = DownCast(msg); - auto* descriptor = full_msg->GetDescriptor(); - auto* reflection = full_msg->GetReflection(); - int field_number = WireFormatLite::GetTagFieldNumber(tag); - const FieldDescriptor* field = descriptor->FindFieldByNumber(field_number); - - // If that failed, check if the field is an extension. - if (field == nullptr && descriptor->IsExtensionNumber(field_number)) { - if (ctx->data().pool == nullptr) { - field = reflection->FindKnownExtensionByNumber(field_number); - } else { - field = ctx->data().pool->FindExtensionByNumber(descriptor, field_number); - } - } - - return WireFormat::_InternalParseAndMergeField(full_msg, ptr, ctx, tag, - reflection, field); -} - -const char* TcParser::ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL) { - (void)data; - (void)table; - (void)hasbits; - // Call into the wire format reflective parse loop. - return WireFormat::_InternalParse(DownCast(msg), ptr, ctx); -} - } // namespace internal } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.cc b/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.cc deleted file mode 100644 index e31d191..0000000 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.cc +++ /dev/null @@ -1,860 +0,0 @@ -// 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_tctable_gen.h" - -#include -#include -#include -#include -#include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/generated_message_tctable_decl.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/wire_format.h" - -// Must come last: -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace internal { - -namespace { - -bool GetEnumValidationRange(const EnumDescriptor* enum_type, int16_t& start, - uint16_t& size) { - GOOGLE_CHECK_GT(enum_type->value_count(), 0) << enum_type->DebugString(); - - // Check if the enum values are a single, contiguous range. - std::vector enum_values; - for (int i = 0, N = static_cast(enum_type->value_count()); i < N; ++i) { - enum_values.push_back(enum_type->value(i)->number()); - } - auto values_begin = enum_values.begin(); - auto values_end = enum_values.end(); - std::sort(values_begin, values_end); - enum_values.erase(std::unique(values_begin, values_end), values_end); - - if (std::numeric_limits::min() <= enum_values[0] && - enum_values[0] <= std::numeric_limits::max() && - enum_values.size() <= std::numeric_limits::max() && - static_cast(enum_values[0] + enum_values.size() - 1) == - enum_values.back()) { - start = static_cast(enum_values[0]); - size = static_cast(enum_values.size()); - return true; - } else { - return false; - } -} - -void PopulateFastFieldEntry(const TailCallTableInfo::FieldEntryInfo& entry, - const TailCallTableInfo::PerFieldOptions& options, - TailCallTableInfo::FastFieldInfo& info) { - const FieldDescriptor* field = entry.field; - std::string name = "::_pbi::TcParser::Fast"; - uint8_t aux_idx = static_cast(entry.aux_idx); - - static const char* kPrefix[] = { - nullptr, // 0 - "F64", // TYPE_DOUBLE = 1, - "F32", // TYPE_FLOAT = 2, - "V64", // TYPE_INT64 = 3, - "V64", // TYPE_UINT64 = 4, - "V32", // TYPE_INT32 = 5, - "F64", // TYPE_FIXED64 = 6, - "F32", // TYPE_FIXED32 = 7, - "V8", // TYPE_BOOL = 8, - "", // TYPE_STRING = 9, - "G", // TYPE_GROUP = 10, - "M", // TYPE_MESSAGE = 11, - "B", // TYPE_BYTES = 12, - "V32", // TYPE_UINT32 = 13, - "", // TYPE_ENUM = 14, - "F32", // TYPE_SFIXED32 = 15, - "F64", // TYPE_SFIXED64 = 16, - "Z32", // TYPE_SINT32 = 17, - "Z64", // TYPE_SINT64 = 18, - }; - name.append(kPrefix[field->type()]); - - if (field->type() == field->TYPE_ENUM) { - // Enums are handled as: - // - V32 for open enums - // - Er (and Er0/Er1) for sequential enums - // - Ev for the rest - if (cpp::HasPreservingUnknownEnumSemantics(field)) { - name.append("V32"); - } else if (field->is_repeated() && field->is_packed()) { - GOOGLE_LOG(DFATAL) << "Enum validation not handled: " << field->DebugString(); - return; - } else { - int16_t start; - uint16_t size; - if (GetEnumValidationRange(field->enum_type(), start, size)) { - name.append("Er"); - int max_value = start + size - 1; - if (max_value <= 127 && (start == 0 || start == 1)) { - name.append(1, '0' + start); - aux_idx = max_value; - } - } else { - name.append("Ev"); - } - } - } - if (field->type() == field->TYPE_STRING) { - switch (internal::cpp::GetUtf8CheckMode(field, options.is_lite)) { - case internal::cpp::Utf8CheckMode::kStrict: - name.append("U"); - break; - case internal::cpp::Utf8CheckMode::kVerify: - name.append("S"); - break; - case internal::cpp::Utf8CheckMode::kNone: - name.append("B"); - break; - } - } - if (field->type() == field->TYPE_STRING || - field->type() == field->TYPE_BYTES) { - if (options.is_string_inlined) { - name.append("i"); - GOOGLE_CHECK(!field->is_repeated()); - aux_idx = static_cast(entry.inlined_string_idx); - } - } - if (field->type() == field->TYPE_MESSAGE || - field->type() == field->TYPE_GROUP) { - name.append(options.use_direct_tcparser_table ? "t" : "d"); - } - - // The field implementation functions are prefixed by cardinality: - // `S` for optional or implicit fields. - // `R` for non-packed repeated. - // `P` for packed repeated. - name.append(field->is_packed() ? "P" - : field->is_repeated() ? "R" - : field->real_containing_oneof() ? "O" - : "S"); - - // Append the tag length. Fast parsing only handles 1- or 2-byte tags. - name.append(field->number() < 16 ? "1" : "2"); - - info.func_name = std::move(name); - info.aux_idx = aux_idx; -} - -bool IsFieldEligibleForFastParsing( - const TailCallTableInfo::FieldEntryInfo& entry, - const TailCallTableInfo::OptionProvider& option_provider) { - const auto* field = entry.field; - const auto options = option_provider.GetForField(field); - // Map, oneof, weak, and lazy fields are not handled on the fast path. - if (field->is_map() || field->real_containing_oneof() || - field->options().weak() || options.is_implicitly_weak || - options.is_lazy || options.should_split) { - return false; - } - - // We will check for a valid auxiliary index range later. However, we might - // want to change the value we check for inlined string fields. - int aux_idx = entry.aux_idx; - - switch (field->type()) { - case FieldDescriptor::TYPE_ENUM: - // If enum values are not validated at parse time, then this field can be - // handled on the fast path like an int32. - if (cpp::HasPreservingUnknownEnumSemantics(field)) { - break; - } - if (field->is_repeated() && field->is_packed()) { - return false; - } - break; - - // Some bytes fields can be handled on fast path. - case FieldDescriptor::TYPE_STRING: - case FieldDescriptor::TYPE_BYTES: - if (field->options().ctype() != FieldOptions::STRING) { - return false; - } - if (options.is_string_inlined) { - GOOGLE_CHECK(!field->is_repeated()); - // For inlined strings, the donation state index is stored in the - // `aux_idx` field of the fast parsing info. We need to check the range - // of that value instead of the auxiliary index. - aux_idx = entry.inlined_string_idx; - } - break; - - default: - break; - } - - if (cpp::HasHasbit(field)) { - // The tailcall parser can only update the first 32 hasbits. Fields with - // has-bits beyond the first 32 are handled by mini parsing/fallback. - GOOGLE_CHECK_GE(entry.hasbit_idx, 0) << field->DebugString(); - if (entry.hasbit_idx >= 32) return false; - } - - // If the field needs auxiliary data, then the aux index is needed. This - // must fit in a uint8_t. - if (aux_idx > std::numeric_limits::max()) { - return false; - } - - // The largest tag that can be read by the tailcall parser is two bytes - // when varint-coded. This allows 14 bits for the numeric tag value: - // byte 0 byte 1 - // 1nnnnttt 0nnnnnnn - // ^^^^^^^ ^^^^^^^ - if (field->number() >= 1 << 11) return false; - - return true; -} - -absl::optional GetEndGroupTag(const Descriptor* descriptor) { - auto* parent = descriptor->containing_type(); - if (parent == nullptr) return absl::nullopt; - for (int i = 0; i < parent->field_count(); ++i) { - auto* field = parent->field(i); - if (field->type() == field->TYPE_GROUP && - field->message_type() == descriptor) { - return WireFormatLite::MakeTag(field->number(), - WireFormatLite::WIRETYPE_END_GROUP); - } - } - return absl::nullopt; -} - -uint32_t RecodeTagForFastParsing(uint32_t tag) { - GOOGLE_DCHECK_LE(tag, 0x3FFF); - // Construct the varint-coded tag. If it is more than 7 bits, we need to - // shift the high bits and add a continue bit. - if (uint32_t hibits = tag & 0xFFFFFF80) { - // hi = tag & ~0x7F - // lo = tag & 0x7F - // This shifts hi to the left by 1 to the next byte and sets the - // continuation bit. - tag = tag + hibits + 128; - } - return tag; -} - -std::vector SplitFastFieldsForSize( - absl::optional end_group_tag, - const std::vector& field_entries, - int table_size_log2, - const TailCallTableInfo::OptionProvider& option_provider) { - std::vector result(1 << table_size_log2); - const uint32_t idx_mask = static_cast(result.size() - 1); - const auto tag_to_idx = [&](uint32_t tag) { - // The field index is determined by the low bits of the field number, where - // the table size determines the width of the mask. The largest table - // supported is 32 entries. The parse loop uses these bits directly, so that - // the dispatch does not require arithmetic: - // byte 0 byte 1 - // tag: 1nnnnttt 0nnnnnnn - // ^^^^^ - // idx (table_size_log2=5) - // This means that any field number that does not fit in the lower 4 bits - // will always have the top bit of its table index asserted. - return (tag >> 3) & idx_mask; - }; - - if (end_group_tag.has_value() && (*end_group_tag >> 14) == 0) { - // Fits in 1 or 2 varint bytes. - const uint32_t tag = RecodeTagForFastParsing(*end_group_tag); - const uint32_t fast_idx = tag_to_idx(tag); - - TailCallTableInfo::FastFieldInfo& info = result[fast_idx]; - info.func_name = "::_pbi::TcParser::FastEndG"; - info.func_name.append(*end_group_tag < 128 ? "1" : "2"); - info.coded_tag = tag; - info.nonfield_info = *end_group_tag; - } - - for (const auto& entry : field_entries) { - if (!IsFieldEligibleForFastParsing(entry, option_provider)) { - continue; - } - - const auto* field = entry.field; - const auto options = option_provider.GetForField(field); - const uint32_t tag = RecodeTagForFastParsing(WireFormat::MakeTag(field)); - const uint32_t fast_idx = tag_to_idx(tag); - - TailCallTableInfo::FastFieldInfo& info = result[fast_idx]; - if (!info.func_name.empty()) { - // This field entry is already filled. - continue; - } - - // Fill in this field's entry: - GOOGLE_CHECK(info.func_name.empty()) << info.func_name; - PopulateFastFieldEntry(entry, options, info); - info.field = field; - info.coded_tag = tag; - // If this field does not have presence, then it can set an out-of-bounds - // bit (tailcall parsing uses a uint64_t for hasbits, but only stores 32). - info.hasbit_idx = cpp::HasHasbit(field) ? entry.hasbit_idx : 63; - } - return result; -} - -// Filter out fields that will be handled by mini parsing. -std::vector FilterMiniParsedFields( - const std::vector& fields, - const TailCallTableInfo::OptionProvider& option_provider -) { - std::vector generated_fallback_fields; - - for (const auto* field : fields) { - auto options = option_provider.GetForField(field); - - bool handled = false; - switch (field->type()) { - case FieldDescriptor::TYPE_DOUBLE: - case FieldDescriptor::TYPE_FLOAT: - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_BOOL: - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_INT64: - // These are handled by MiniParse, so we don't need any generated - // fallback code. - handled = true; - break; - - case FieldDescriptor::TYPE_ENUM: - if (field->is_repeated() && - !cpp::HasPreservingUnknownEnumSemantics(field)) { - // TODO(b/206890171): handle packed repeated closed enums - // Non-packed repeated can be handled using tables, but we still - // need to generate fallback code for all repeated enums in order to - // handle packed encoding. This is because of the lite/full split - // when handling invalid enum values in a packed field. - handled = false; - } else { - handled = true; - } - break; - - case FieldDescriptor::TYPE_BYTES: - case FieldDescriptor::TYPE_STRING: - if (options.is_string_inlined) { - // TODO(b/198211897): support InilnedStringField. - handled = false; - } else { - handled = true; - } - break; - - case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_GROUP: - // TODO(b/210762816): support remaining field types. - if (field->is_map() || field->options().weak() || options.is_lazy) { - handled = false; - } else { - handled = true; - } - break; - - default: - handled = false; - break; - } - if (!handled) generated_fallback_fields.push_back(field); - } - - return generated_fallback_fields; -} - -// We only need field names for reporting UTF-8 parsing errors, so we only -// emit them for string fields with Utf8 transform specified. -absl::string_view FieldNameForTable( - const TailCallTableInfo::FieldEntryInfo& entry) { - const auto* field = entry.field; - if (field->type() == FieldDescriptor::TYPE_STRING) { - const uint16_t xform_val = entry.type_card & field_layout::kTvMask; - - switch (xform_val) { - case field_layout::kTvUtf8: - case field_layout::kTvUtf8Debug: - return field->name(); - } - } - return ""; -} - -std::vector GenerateFieldNames( - const Descriptor* descriptor, - const std::vector& entries) { - static constexpr int kMaxNameLength = 255; - std::vector out; - - bool found_needed_name = false; - for (const auto& entry : entries) { - if (!FieldNameForTable(entry).empty()) { - found_needed_name = true; - break; - } - } - - // No names needed. Omit the whole table. - if (!found_needed_name) { - return out; - } - - // First, we output the size of each string, as an unsigned byte. The first - // string is the message name. - int count = 1; - out.push_back(std::min(static_cast(descriptor->full_name().size()), - kMaxNameLength)); - for (const auto& entry : entries) { - out.push_back(FieldNameForTable(entry).size()); - ++count; - } - while (count & 7) { // align to an 8-byte boundary - out.push_back(0); - ++count; - } - // The message name is stored at the beginning of the string - std::string message_name = descriptor->full_name(); - if (message_name.size() > kMaxNameLength) { - static constexpr int kNameHalfLength = (kMaxNameLength - 3) / 2; - message_name = absl::StrCat( - message_name.substr(0, kNameHalfLength), "...", - message_name.substr(message_name.size() - kNameHalfLength)); - } - out.insert(out.end(), message_name.begin(), message_name.end()); - // Then we output the actual field names - for (const auto& entry : entries) { - const auto& field_name = FieldNameForTable(entry); - out.insert(out.end(), field_name.begin(), field_name.end()); - } - - return out; -} - -TailCallTableInfo::NumToEntryTable MakeNumToEntryTable( - const std::vector& field_descriptors) { - TailCallTableInfo::NumToEntryTable num_to_entry_table; - num_to_entry_table.skipmap32 = static_cast(-1); - - // skip_entry_block is the current block of SkipEntries that we're - // appending to. cur_block_first_fnum is the number of the first - // field represented by the block. - uint16_t field_entry_index = 0; - uint16_t N = field_descriptors.size(); - // First, handle field numbers 1-32, which affect only the initial - // skipmap32 and don't generate additional skip-entry blocks. - for (; field_entry_index != N; ++field_entry_index) { - auto* field_descriptor = field_descriptors[field_entry_index]; - if (field_descriptor->number() > 32) break; - auto skipmap32_index = field_descriptor->number() - 1; - num_to_entry_table.skipmap32 -= 1 << skipmap32_index; - } - // If all the field numbers were less than or equal to 32, we will have - // no further entries to process, and we are already done. - if (field_entry_index == N) return num_to_entry_table; - - TailCallTableInfo::SkipEntryBlock* block = nullptr; - bool start_new_block = true; - // To determine sparseness, track the field number corresponding to - // the start of the most recent skip entry. - uint32_t last_skip_entry_start = 0; - for (; field_entry_index != N; ++field_entry_index) { - auto* field_descriptor = field_descriptors[field_entry_index]; - uint32_t fnum = static_cast(field_descriptor->number()); - GOOGLE_CHECK_GT(fnum, last_skip_entry_start); - if (start_new_block == false) { - // If the next field number is within 15 of the last_skip_entry_start, we - // continue writing just to that entry. If it's between 16 and 31 more, - // then we just extend the current block by one. If it's more than 31 - // more, we have to add empty skip entries in order to continue using the - // existing block. Obviously it's just 32 more, it doesn't make sense to - // start a whole new block, since new blocks mean having to write out - // their starting field number, which is 32 bits, as well as the size of - // the additional block, which is 16... while an empty SkipEntry16 only - // costs 32 bits. So if it was 48 more, it's a slight space win; we save - // 16 bits, but probably at the cost of slower run time. We're choosing - // 96 for now. - if (fnum - last_skip_entry_start > 96) start_new_block = true; - } - if (start_new_block) { - num_to_entry_table.blocks.push_back({fnum}); - block = &num_to_entry_table.blocks.back(); - start_new_block = false; - } - - auto skip_entry_num = (fnum - block->first_fnum) / 16; - auto skip_entry_index = (fnum - block->first_fnum) % 16; - while (skip_entry_num >= block->entries.size()) - block->entries.push_back({0xFFFF, field_entry_index}); - block->entries[skip_entry_num].skipmap -= 1 << (skip_entry_index); - - last_skip_entry_start = fnum - skip_entry_index; - } - return num_to_entry_table; -} - -uint16_t MakeTypeCardForField( - const FieldDescriptor* field, - const TailCallTableInfo::PerFieldOptions& options) { - uint16_t type_card; - namespace fl = internal::field_layout; - if (internal::cpp::HasHasbit(field)) { - type_card = fl::kFcOptional; - } else if (field->is_repeated()) { - type_card = fl::kFcRepeated; - } else if (field->real_containing_oneof()) { - type_card = fl::kFcOneof; - } else { - type_card = fl::kFcSingular; - } - - // The rest of the type uses convenience aliases: - switch (field->type()) { - case FieldDescriptor::TYPE_DOUBLE: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedDouble - : fl::kDouble; - break; - case FieldDescriptor::TYPE_FLOAT: - type_card |= field->is_repeated() && field->is_packed() ? fl::kPackedFloat - : fl::kFloat; - break; - case FieldDescriptor::TYPE_FIXED32: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedFixed32 - : fl::kFixed32; - break; - case FieldDescriptor::TYPE_SFIXED32: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedSFixed32 - : fl::kSFixed32; - break; - case FieldDescriptor::TYPE_FIXED64: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedFixed64 - : fl::kFixed64; - break; - case FieldDescriptor::TYPE_SFIXED64: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedSFixed64 - : fl::kSFixed64; - break; - case FieldDescriptor::TYPE_BOOL: - type_card |= field->is_repeated() && field->is_packed() ? fl::kPackedBool - : fl::kBool; - break; - case FieldDescriptor::TYPE_ENUM: - if (internal::cpp::HasPreservingUnknownEnumSemantics(field)) { - // No validation is required. - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedOpenEnum - : fl::kOpenEnum; - } else { - int16_t start; - uint16_t size; - if (GetEnumValidationRange(field->enum_type(), start, size)) { - // Validation is done by range check (start/length in FieldAux). - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedEnumRange - : fl::kEnumRange; - } else { - // Validation uses the generated _IsValid function. - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedEnum - : fl::kEnum; - } - } - break; - case FieldDescriptor::TYPE_UINT32: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedUInt32 - : fl::kUInt32; - break; - case FieldDescriptor::TYPE_SINT32: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedSInt32 - : fl::kSInt32; - break; - case FieldDescriptor::TYPE_INT32: - type_card |= field->is_repeated() && field->is_packed() ? fl::kPackedInt32 - : fl::kInt32; - break; - case FieldDescriptor::TYPE_UINT64: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedUInt64 - : fl::kUInt64; - break; - case FieldDescriptor::TYPE_SINT64: - type_card |= field->is_repeated() && field->is_packed() - ? fl::kPackedSInt64 - : fl::kSInt64; - break; - case FieldDescriptor::TYPE_INT64: - type_card |= field->is_repeated() && field->is_packed() ? fl::kPackedInt64 - : fl::kInt64; - break; - - case FieldDescriptor::TYPE_BYTES: - type_card |= fl::kBytes; - break; - case FieldDescriptor::TYPE_STRING: { - switch (internal::cpp::GetUtf8CheckMode(field, options.is_lite)) { - case internal::cpp::Utf8CheckMode::kStrict: - type_card |= fl::kUtf8String; - break; - case internal::cpp::Utf8CheckMode::kVerify: - type_card |= fl::kRawString; - break; - case internal::cpp::Utf8CheckMode::kNone: - type_card |= fl::kBytes; - break; - } - break; - } - - case FieldDescriptor::TYPE_GROUP: - type_card |= 0 | fl::kMessage | fl::kRepGroup; - if (options.is_implicitly_weak) { - type_card |= fl::kTvWeakPtr; - } else if (options.use_direct_tcparser_table) { - type_card |= fl::kTvTable; - } else { - type_card |= fl::kTvDefault; - } - break; - case FieldDescriptor::TYPE_MESSAGE: - if (field->is_map()) { - type_card |= fl::kMap; - } else { - type_card |= fl::kMessage; - if (options.is_lazy) { - type_card |= fl::kRepLazy; - } - - if (options.is_implicitly_weak) { - type_card |= fl::kTvWeakPtr; - } else if (options.use_direct_tcparser_table) { - type_card |= fl::kTvTable; - } else { - type_card |= fl::kTvDefault; - } - } - break; - } - - // Fill in extra information about string and bytes field representations. - if (field->type() == FieldDescriptor::TYPE_BYTES || - field->type() == FieldDescriptor::TYPE_STRING) { - if (field->is_repeated()) { - type_card |= fl::kRepSString; - } else { - type_card |= fl::kRepAString; - } - } - - if (options.should_split) { - type_card |= fl::kSplitTrue; - } - - return type_card; -} - -} // namespace - -TailCallTableInfo::TailCallTableInfo( - const Descriptor* descriptor, - const std::vector& ordered_fields, - const OptionProvider& option_provider, - const std::vector& has_bit_indices, - const std::vector& inlined_string_indices) { - // If this message has any inlined string fields, store the donation state - // offset in the second auxiliary entry. - if (!inlined_string_indices.empty()) { - aux_entries.resize(1); // pad if necessary - aux_entries[0] = {kInlinedStringDonatedOffset}; - } - - // If this message is split, store the split pointer offset in the third - // auxiliary entry. - for (auto* field : ordered_fields) { - if (option_provider.GetForField(field).should_split) { - aux_entries.resize(3); // pad if necessary - aux_entries[1] = {kSplitOffset}; - aux_entries[2] = {kSplitSizeof}; - break; - } - } - - // Fill in mini table entries. - for (const FieldDescriptor* field : ordered_fields) { - auto options = option_provider.GetForField(field); - field_entries.push_back( - {field, internal::cpp ::HasHasbit(field) - ? has_bit_indices[static_cast(field->index())] - : -1}); - auto& entry = field_entries.back(); - entry.type_card = MakeTypeCardForField(field, options); - - if (field->type() == FieldDescriptor::TYPE_MESSAGE || - field->type() == FieldDescriptor::TYPE_GROUP) { - // Message-typed fields have a FieldAux with the default instance pointer. - if (field->is_map()) { - // TODO(b/205904770): generate aux entries for maps - } else if (field->options().weak()) { - // Don't generate anything for weak fields. They are handled by the - // generated fallback. - } else if (options.is_lazy) { - // Lazy fields are handled by the generated fallback function. - } else { - field_entries.back().aux_idx = aux_entries.size(); - aux_entries.push_back({options.is_implicitly_weak ? kSubMessageWeak - : options.use_direct_tcparser_table - ? kSubTable - : kSubMessage, - {field}}); - } - } else if (field->type() == FieldDescriptor::TYPE_ENUM && - !cpp::HasPreservingUnknownEnumSemantics(field)) { - // Enum fields which preserve unknown values (proto3 behavior) are - // effectively int32 fields with respect to parsing -- i.e., the value - // does not need to be validated at parse time. - // - // Enum fields which do not preserve unknown values (proto2 behavior) use - // a FieldAux to store validation information. If the enum values are - // sequential (and within a range we can represent), then the FieldAux - // entry represents the range using the minimum value (which must fit in - // an int16_t) and count (a uint16_t). Otherwise, the entry holds a - // pointer to the generated Name_IsValid function. - - entry.aux_idx = aux_entries.size(); - aux_entries.push_back({}); - auto& aux_entry = aux_entries.back(); - - if (GetEnumValidationRange(field->enum_type(), aux_entry.enum_range.start, - aux_entry.enum_range.size)) { - aux_entry.type = kEnumRange; - } else { - aux_entry.type = kEnumValidator; - aux_entry.field = field; - } - - } else if ((field->type() == FieldDescriptor::TYPE_STRING || - field->type() == FieldDescriptor::TYPE_BYTES) && - options.is_string_inlined) { - GOOGLE_CHECK(!field->is_repeated()); - // Inlined strings have an extra marker to represent their donation state. - int idx = inlined_string_indices[static_cast(field->index())]; - // For mini parsing, the donation state index is stored as an `offset` - // auxiliary entry. - entry.aux_idx = aux_entries.size(); - aux_entries.push_back({kNumericOffset}); - aux_entries.back().offset = idx; - // For fast table parsing, the donation state index is stored instead of - // the aux_idx (this will limit the range to 8 bits). - entry.inlined_string_idx = idx; - } - } - - table_size_log2 = 0; // fallback value - int num_fast_fields = -1; - auto end_group_tag = GetEndGroupTag(descriptor); - for (int try_size_log2 : {0, 1, 2, 3, 4, 5}) { - size_t try_size = 1 << try_size_log2; - auto split_fields = SplitFastFieldsForSize(end_group_tag, field_entries, - try_size_log2, option_provider); - GOOGLE_CHECK_EQ(split_fields.size(), try_size); - int try_num_fast_fields = 0; - for (const auto& info : split_fields) { - if (info.field != nullptr) ++try_num_fast_fields; - } - // Use this size if (and only if) it covers more fields. - if (try_num_fast_fields > num_fast_fields) { - fast_path_fields = std::move(split_fields); - table_size_log2 = try_size_log2; - num_fast_fields = try_num_fast_fields; - } - // The largest table we allow has the same number of entries as the - // message has fields, rounded up to the next power of 2 (e.g., a message - // with 5 fields can have a fast table of size 8). A larger table *might* - // cover more fields in certain cases, but a larger table in that case - // would have mostly empty entries; so, we cap the size to avoid - // pathologically sparse tables. - if (end_group_tag.has_value()) { - // If this message uses group encoding, the tables are sometimes very - // sparse because the fields in the group avoid using the same field - // numbering as the parent message (even though currently, the proto - // compiler allows the overlap, and there is no possible conflict.) - // As such, this test produces a false negative as far as whether the - // large table will be worth it. So we disable the test in this case. - } else { - if (try_size > ordered_fields.size()) { - break; - } - } - } - - // Filter out fields that are handled by MiniParse. We don't need to generate - // a fallback for these, which saves code size. - fallback_fields = FilterMiniParsedFields(ordered_fields, option_provider - ); - - num_to_entry_table = MakeNumToEntryTable(ordered_fields); - GOOGLE_CHECK_EQ(field_entries.size(), ordered_fields.size()); - field_name_data = GenerateFieldNames(descriptor, field_entries); - - // If there are no fallback fields, and at most one extension range, the - // parser can use a generic fallback function. Otherwise, a message-specific - // fallback routine is needed. - use_generated_fallback = - !fallback_fields.empty() || descriptor->extension_range_count() > 1; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.h b/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.h deleted file mode 100644 index ac24dd7..0000000 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_gen.h +++ /dev/null @@ -1,164 +0,0 @@ -// 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 contains routines to generate tail-call table parsing tables. -// Everything in this file is for internal use only. - -#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__ -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__ - -#include -#include -#include -#include - -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/generated_message_tctable_decl.h" - -// Must come last: -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace internal { - -// Helper class for generating tailcall parsing functions. -struct PROTOBUF_EXPORT TailCallTableInfo { - struct PerFieldOptions { - bool is_lazy; - bool is_string_inlined; - bool is_implicitly_weak; - bool use_direct_tcparser_table; - bool is_lite; - bool should_split; - }; - class OptionProvider { - public: - virtual PerFieldOptions GetForField(const FieldDescriptor*) const = 0; - - protected: - ~OptionProvider() = default; - }; - - TailCallTableInfo(const Descriptor* descriptor, - const std::vector& ordered_fields, - const OptionProvider& option_provider, - const std::vector& has_bit_indices, - const std::vector& inlined_string_indices); - - // Fields parsed by the table fast-path. - struct FastFieldInfo { - std::string func_name; - const FieldDescriptor* field; - uint16_t coded_tag; - uint8_t hasbit_idx; - uint8_t aux_idx; - uint16_t nonfield_info; - }; - std::vector fast_path_fields; - - // Fields parsed by mini parsing routines. - struct FieldEntryInfo { - const FieldDescriptor* field; - int hasbit_idx; - int inlined_string_idx; - uint16_t aux_idx; - uint16_t type_card; - }; - std::vector field_entries; - - enum AuxType { - kNothing = 0, - kInlinedStringDonatedOffset, - kSplitOffset, - kSplitSizeof, - kSubMessage, - kSubTable, - kSubMessageWeak, - kEnumRange, - kEnumValidator, - kNumericOffset, - }; - struct AuxEntry { - AuxType type; - struct EnumRange { - int16_t start; - uint16_t size; - }; - union { - const FieldDescriptor* field; - uint32_t offset; - EnumRange enum_range; - }; - }; - std::vector aux_entries; - - // Fields parsed by generated fallback function. - std::vector fallback_fields; - - struct SkipEntry16 { - uint16_t skipmap; - uint16_t field_entry_offset; - }; - struct SkipEntryBlock { - uint32_t first_fnum; - std::vector entries; - }; - struct NumToEntryTable { - uint32_t skipmap32; // for fields #1 - #32 - std::vector blocks; - // Compute the number of uint16_t required to represent this table. - int size16() const { - int size = 2; // for the termination field# - for (const auto& block : blocks) { - // 2 for the field#, 1 for a count of skip entries, 2 for each entry. - size += static_cast(3 + block.entries.size() * 2); - } - return size; - } - }; - NumToEntryTable num_to_entry_table; - - std::vector field_name_data; - - // Table size. - int table_size_log2; - // True if a generated fallback function is required instead of generic. - bool use_generated_fallback; -}; - -} // namespace internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_impl.h b/libs/protobuf/src/google/protobuf/generated_message_tctable_impl.h index f51be94..21fa533 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_impl.h +++ b/libs/protobuf/src/google/protobuf/generated_message_tctable_impl.h @@ -32,20 +32,18 @@ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_IMPL_H__ #include -#include -#include #include -#include -#include "google/protobuf/port.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/generated_message_tctable_decl.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include // Must come last: -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -55,12 +53,6 @@ class UnknownFieldSet; namespace internal { -enum { - kInlinedStringAuxIdx = 0, - kSplitOffsetAuxIdx = 1, - kSplitSizeAuxIdx = 2, -}; - // Field layout enums. // // Structural information about fields is packed into a 16-bit value. The enum @@ -72,11 +64,10 @@ enum { // |15 .. 8|7 .. 0| // +-----------------------+-----------------------+ // : . : . : . : . : . : . : 3|========| [3] FieldType -// : : : : : : . 4|==| : : [1] FieldSplit -// : : : : : 6|=====| . : : [2] FieldCardinality -// : . : . : . : 9|========| . : . : . : [3] FieldRep -// : : :11|=====| : : : : : [2] TransformValidation -// : . :13|=====| : . : . : . : . : . : [2] FormatDiscriminator +// : : : : : : 5|=====| : : [2] FieldCardinality +// : . : . : . : . 8|========| : . : . : [3] FieldRep +// : : : 10|=====| : : : : [2] TransformValidation +// : . : .12|=====| . : . : . : . : . : [2] FormatDiscriminator // +-----------------------+-----------------------+ // |15 .. 8|7 .. 0| // +-----------------------+-----------------------+ @@ -104,21 +95,11 @@ enum FieldKind : uint16_t { static_assert(kFkMap < (1 << kFkBits), "too many types"); -// Split (1 bit): -enum FieldSplit : uint16_t { - kSplitShift = kFkShift+ kFkBits, - kSplitBits = 1, - kSplitMask = ((1 << kSplitBits) - 1) << kSplitShift, - - kSplitFalse = 0, - kSplitTrue = 1 << kSplitShift, -}; - // Cardinality (2 bits): // These values determine how many values a field can have and its presence. // Packed fields are represented in FieldType. enum Cardinality : uint16_t { - kFcShift = kSplitShift+ kSplitBits, + kFcShift = kFkShift + kFkBits, kFcBits = 2, kFcMask = ((1 << kFcBits) - 1) << kFcShift, @@ -149,6 +130,7 @@ enum FieldRep : uint16_t { kRepMessage = 0, // MessageLite* kRepGroup = 1 << kRepShift, // MessageLite* (WT=3,4) kRepLazy = 2 << kRepShift, // LazyField* + kRepIWeak = 3 << kRepShift, // ImplicitWeak }; // Transform/validation (2 bits): @@ -165,11 +147,6 @@ enum TransformValidation : uint16_t { // String fields: kTvUtf8Debug = 1 << kTvShift, // proto2 kTvUtf8 = 2 << kTvShift, // proto3 - - // Message fields: - kTvDefault = 1 << kTvShift, // Aux has default_instance* - kTvTable = 2 << kTvShift, // Aux has TcParseTableBase* - kTvWeakPtr = 3 << kTvShift, // Aux has default_instance** (for weak) }; static_assert((kTvEnum & kTvRange) != 0, @@ -198,7 +175,7 @@ enum FormatDiscriminator : uint16_t { }; // Update this assertion (and comments above) when adding or removing bits: -static_assert(kFmtShift + kFmtBits == 13, "number of bits changed"); +static_assert(kFmtShift + kFmtBits == 12, "number of bits changed"); // This assertion should not change unless the storage width changes: static_assert(kFmtShift + kFmtBits <= 16, "too many bits"); @@ -206,48 +183,48 @@ static_assert(kFmtShift + kFmtBits <= 16, "too many bits"); // Convenience aliases (16 bits, with format): enum FieldType : uint16_t { // Numeric types: - kBool = 0 | kFkVarint | kRep8Bits, + kBool = kFkVarint | kRep8Bits, - kFixed32 = 0 | kFkFixed | kRep32Bits | kFmtUnsigned, - kUInt32 = 0 | kFkVarint | kRep32Bits | kFmtUnsigned, - kSFixed32 = 0 | kFkFixed | kRep32Bits | kFmtSigned, - kInt32 = 0 | kFkVarint | kRep32Bits | kFmtSigned, - kSInt32 = 0 | kFkVarint | kRep32Bits | kFmtSigned | kTvZigZag, - kFloat = 0 | kFkFixed | kRep32Bits | kFmtFloating, - kEnum = 0 | kFkVarint | kRep32Bits | kFmtEnum | kTvEnum, - kEnumRange = 0 | kFkVarint | kRep32Bits | kFmtEnum | kTvRange, - kOpenEnum = 0 | kFkVarint | kRep32Bits | kFmtEnum, + kFixed32 = kFkFixed | kRep32Bits | kFmtUnsigned, + kUInt32 = kFkVarint | kRep32Bits | kFmtUnsigned, + kSFixed32 = kFkFixed | kRep32Bits | kFmtSigned, + kInt32 = kFkVarint | kRep32Bits | kFmtSigned, + kSInt32 = kFkVarint | kRep32Bits | kFmtSigned | kTvZigZag, + kFloat = kFkFixed | kRep32Bits | kFmtFloating, + kEnum = kFkVarint | kRep32Bits | kFmtEnum | kTvEnum, + kEnumRange = kFkVarint | kRep32Bits | kFmtEnum | kTvRange, + kOpenEnum = kFkVarint | kRep32Bits | kFmtEnum, - kFixed64 = 0 | kFkFixed | kRep64Bits | kFmtUnsigned, - kUInt64 = 0 | kFkVarint | kRep64Bits | kFmtUnsigned, - kSFixed64 = 0 | kFkFixed | kRep64Bits | kFmtSigned, - kInt64 = 0 | kFkVarint | kRep64Bits | kFmtSigned, - kSInt64 = 0 | kFkVarint | kRep64Bits | kFmtSigned | kTvZigZag, - kDouble = 0 | kFkFixed | kRep64Bits | kFmtFloating, + kFixed64 = kFkFixed | kRep64Bits | kFmtUnsigned, + kUInt64 = kFkVarint | kRep64Bits | kFmtUnsigned, + kSFixed64 = kFkFixed | kRep64Bits | kFmtSigned, + kInt64 = kFkVarint | kRep64Bits | kFmtSigned, + kSInt64 = kFkVarint | kRep64Bits | kFmtSigned | kTvZigZag, + kDouble = kFkFixed | kRep64Bits | kFmtFloating, - kPackedBool = 0 | kFkPackedVarint | kRep8Bits, + kPackedBool = kFkPackedVarint | kRep8Bits, - kPackedFixed32 = 0 | kFkPackedFixed | kRep32Bits | kFmtUnsigned, - kPackedUInt32 = 0 | kFkPackedVarint | kRep32Bits | kFmtUnsigned, - kPackedSFixed32 = 0 | kFkPackedFixed | kRep32Bits | kFmtSigned, - kPackedInt32 = 0 | kFkPackedVarint | kRep32Bits | kFmtSigned, - kPackedSInt32 = 0 | kFkPackedVarint | kRep32Bits | kFmtSigned | kTvZigZag, - kPackedFloat = 0 | kFkPackedFixed | kRep32Bits | kFmtFloating, - kPackedEnum = 0 | kFkPackedVarint | kRep32Bits | kFmtEnum | kTvEnum, - kPackedEnumRange = 0 | kFkPackedVarint | kRep32Bits | kFmtEnum | kTvRange, - kPackedOpenEnum = 0 | kFkPackedVarint | kRep32Bits | kFmtEnum, + kPackedFixed32 = kFkPackedFixed | kRep32Bits | kFmtUnsigned, + kPackedUInt32 = kFkPackedVarint | kRep32Bits | kFmtUnsigned, + kPackedSFixed32 = kFkPackedFixed | kRep32Bits | kFmtSigned, + kPackedInt32 = kFkPackedVarint | kRep32Bits | kFmtSigned, + kPackedSInt32 = kFkPackedVarint | kRep32Bits | kFmtSigned | kTvZigZag, + kPackedFloat = kFkPackedFixed | kRep32Bits | kFmtFloating, + kPackedEnum = kFkPackedVarint | kRep32Bits | kFmtEnum | kTvEnum, + kPackedEnumRange = kFkPackedVarint | kRep32Bits | kFmtEnum | kTvRange, + kPackedOpenEnum = kFkPackedVarint | kRep32Bits | kFmtEnum, - kPackedFixed64 = 0 | kFkPackedFixed | kRep64Bits | kFmtUnsigned, - kPackedUInt64 = 0 | kFkPackedVarint | kRep64Bits | kFmtUnsigned, - kPackedSFixed64 = 0 | kFkPackedFixed | kRep64Bits | kFmtSigned, - kPackedInt64 = 0 | kFkPackedVarint | kRep64Bits | kFmtSigned, - kPackedSInt64 = 0 | kFkPackedVarint | kRep64Bits | kFmtSigned | kTvZigZag, - kPackedDouble = 0 | kFkPackedFixed | kRep64Bits | kFmtFloating, + kPackedFixed64 = kFkPackedFixed | kRep64Bits | kFmtUnsigned, + kPackedUInt64 = kFkPackedVarint | kRep64Bits | kFmtUnsigned, + kPackedSFixed64 = kFkPackedFixed | kRep64Bits | kFmtSigned, + kPackedInt64 = kFkPackedVarint | kRep64Bits | kFmtSigned, + kPackedSInt64 = kFkPackedVarint | kRep64Bits | kFmtSigned | kTvZigZag, + kPackedDouble = kFkPackedFixed | kRep64Bits | kFmtFloating, // String types: - kBytes = 0 | kFkString | kFmtArray, - kRawString = 0 | kFkString | kFmtUtf8 | kTvUtf8Debug, - kUtf8String = 0 | kFkString | kFmtUtf8 | kTvUtf8, + kBytes = kFkString | kFmtArray, + kRawString = kFkString | kFmtUtf8 | kTvUtf8Debug, + kUtf8String = kFkString | kFmtUtf8 | kTvUtf8, // Message types: kMessage = kFkMessage, @@ -255,16 +232,27 @@ enum FieldType : uint16_t { // Map types: kMap = kFkMap, }; + // clang-format on } // namespace field_layout +// PROTOBUF_TC_PARAM_DECL are the parameters for tailcall functions, it is +// defined in port_def.inc. +// +// Note that this is performance sensitive: changing the parameters will change +// the registers used by the ABI calling convention, which subsequently affects +// register selection logic inside the function. + +// PROTOBUF_TC_PARAM_PASS passes values to match PROTOBUF_TC_PARAM_DECL. +#define PROTOBUF_TC_PARAM_PASS msg, ptr, ctx, table, hasbits, data + #ifndef NDEBUG template +#ifndef _MSC_VER +[[noreturn]] +#endif void AlignFail(uintptr_t address) { GOOGLE_LOG(FATAL) << "Unaligned (" << align << ") access at " << address; - - // Explicit abort to let compilers know this function does not return - abort(); } extern template void AlignFail<4>(uintptr_t); @@ -274,15 +262,8 @@ extern template void AlignFail<8>(uintptr_t); // TcParser implements most of the parsing logic for tailcall tables. class PROTOBUF_EXPORT TcParser final { public: - template - static constexpr const TcParseTableBase* GetTable() { - return &T::_table_.header; - } - static const char* GenericFallback(PROTOBUF_TC_PARAM_DECL); static const char* GenericFallbackLite(PROTOBUF_TC_PARAM_DECL); - static const char* ReflectionFallback(PROTOBUF_TC_PARAM_DECL); - static const char* ReflectionParseLoop(PROTOBUF_TC_PARAM_DECL); static const char* ParseLoop(MessageLite* msg, const char* ptr, ParseContext* ctx, @@ -342,33 +323,6 @@ class PROTOBUF_EXPORT TcParser final { static const char* FastZ64P1(PROTOBUF_TC_PARAM_DECL); static const char* FastZ64P2(PROTOBUF_TC_PARAM_DECL); - // Manually unrolled and specialized Varint parsing. - template - static const char* SpecializedUnrolledVImpl1(PROTOBUF_TC_PARAM_DECL); - template - static const char* SpecializedFastV8S1(PROTOBUF_TC_PARAM_DECL); - - template - static constexpr TailCallParseFunc SingularVarintNoZag1() { - if (data_offset < 100) { - if (sizeof(FieldType) == 1) { - return &SpecializedFastV8S1; - } - return &SpecializedUnrolledVImpl1; - } else if (sizeof(FieldType) == 1) { - return &FastV8S1; - } else if (sizeof(FieldType) == 4) { - return &FastV32S1; - } else if (sizeof(FieldType) == 8) { - return &FastV64S1; - } else { - static_assert(sizeof(FieldType) == 1 || sizeof(FieldType) == 4 || - sizeof(FieldType) == 8, - ""); - return nullptr; - } - } - // Functions referenced by generated fast tables (closed enum): // E: closed enum (N.B.: open enums use V32, above) // r: enum range v: enum validator (_IsValid function) @@ -383,15 +337,6 @@ class PROTOBUF_EXPORT TcParser final { static const char* FastEvR1(PROTOBUF_TC_PARAM_DECL); static const char* FastEvR2(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr0S1(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr0S2(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr0R1(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr0R2(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr1S1(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr1S2(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr1R1(PROTOBUF_TC_PARAM_DECL); - static const char* FastEr1R2(PROTOBUF_TC_PARAM_DECL); - // Functions referenced by generated fast tables (string types): // B: bytes S: string U: UTF-8 string // (empty): ArenaStringPtr i: InlinedString @@ -419,26 +364,16 @@ class PROTOBUF_EXPORT TcParser final { // Functions referenced by generated fast tables (message types): // M: message G: group - // d: default* t: TcParseTable* (the contents of aux) // S: singular R: repeated // 1/2: tag length (bytes) - static const char* FastMdS1(PROTOBUF_TC_PARAM_DECL); - static const char* FastMdS2(PROTOBUF_TC_PARAM_DECL); - static const char* FastGdS1(PROTOBUF_TC_PARAM_DECL); - static const char* FastGdS2(PROTOBUF_TC_PARAM_DECL); - static const char* FastMtS1(PROTOBUF_TC_PARAM_DECL); - static const char* FastMtS2(PROTOBUF_TC_PARAM_DECL); - static const char* FastGtS1(PROTOBUF_TC_PARAM_DECL); - static const char* FastGtS2(PROTOBUF_TC_PARAM_DECL); - - static const char* FastMdR1(PROTOBUF_TC_PARAM_DECL); - static const char* FastMdR2(PROTOBUF_TC_PARAM_DECL); - static const char* FastGdR1(PROTOBUF_TC_PARAM_DECL); - static const char* FastGdR2(PROTOBUF_TC_PARAM_DECL); - static const char* FastMtR1(PROTOBUF_TC_PARAM_DECL); - static const char* FastMtR2(PROTOBUF_TC_PARAM_DECL); - static const char* FastGtR1(PROTOBUF_TC_PARAM_DECL); - static const char* FastGtR2(PROTOBUF_TC_PARAM_DECL); + static const char* FastMS1(PROTOBUF_TC_PARAM_DECL); + static const char* FastMS2(PROTOBUF_TC_PARAM_DECL); + static const char* FastMR1(PROTOBUF_TC_PARAM_DECL); + static const char* FastMR2(PROTOBUF_TC_PARAM_DECL); + static const char* FastGS1(PROTOBUF_TC_PARAM_DECL); + static const char* FastGS2(PROTOBUF_TC_PARAM_DECL); + static const char* FastGR1(PROTOBUF_TC_PARAM_DECL); + static const char* FastGR2(PROTOBUF_TC_PARAM_DECL); template static inline T& RefAt(void* x, size_t offset) { @@ -483,30 +418,21 @@ class PROTOBUF_EXPORT TcParser final { // parsing. static const char* MiniParse(PROTOBUF_TC_PARAM_DECL); - static const char* FastEndG1(PROTOBUF_TC_PARAM_DECL); - static const char* FastEndG2(PROTOBUF_TC_PARAM_DECL); - private: friend class GeneratedTcTableLiteTest; - static void* MaybeGetSplitBase(MessageLite* msg, const bool is_split, - const TcParseTableBase* table, - google::protobuf::internal::ParseContext* ctx); - template + template static inline const char* SingularParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL); - template + template static inline const char* RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL); - template - static const char* FastEndGroupImpl(PROTOBUF_TC_PARAM_DECL); - static inline PROTOBUF_ALWAYS_INLINE void SyncHasbits( MessageLite* msg, uint64_t hasbits, const TcParseTableBase* table) { const uint32_t has_bits_offset = table->has_bits_offset; if (has_bits_offset) { // Only the first 32 has-bits are updated. Nothing above those is stored, // but e.g. messages without has-bits update the upper bits. - RefAt(msg, has_bits_offset) |= static_cast(hasbits); + RefAt(msg, has_bits_offset) = static_cast(hasbits); } } @@ -571,12 +497,8 @@ class PROTOBUF_EXPORT TcParser final { // Implementations for fast enum field parsing functions: template static inline const char* SingularEnum(PROTOBUF_TC_PARAM_DECL); - template - static inline const char* SingularEnumSmallRange(PROTOBUF_TC_PARAM_DECL); template static inline const char* RepeatedEnum(PROTOBUF_TC_PARAM_DECL); - template - static inline const char* RepeatedEnumSmallRange(PROTOBUF_TC_PARAM_DECL); // Implementations for fast string field parsing functions: enum Utf8Type { kNoUtf8 = 0, kUtf8 = 1, kUtf8ValidateOnly = 2 }; @@ -585,15 +507,11 @@ class PROTOBUF_EXPORT TcParser final { template static inline const char* RepeatedString(PROTOBUF_TC_PARAM_DECL); - static inline const char* ParseRepeatedStringOnce( - const char* ptr, Arena* arena, SerialArena* serial_arena, - ParseContext* ctx, RepeatedPtrField& field); - // Mini field lookup: static const TcParseTableBase::FieldEntry* FindFieldEntry( const TcParseTableBase* table, uint32_t field_num); - static absl::string_view MessageName(const TcParseTableBase* table); - static absl::string_view FieldName(const TcParseTableBase* table, + static StringPiece MessageName(const TcParseTableBase* table); + static StringPiece FieldName(const TcParseTableBase* table, const TcParseTableBase::FieldEntry*); static bool ChangeOneof(const TcParseTableBase* table, const TcParseTableBase::FieldEntry& entry, @@ -603,216 +521,33 @@ class PROTOBUF_EXPORT TcParser final { // UTF-8 validation: static void ReportFastUtf8Error(uint32_t decoded_tag, const TcParseTableBase* table); - static bool MpVerifyUtf8(absl::string_view wire_bytes, + static bool MpVerifyUtf8(StringPiece wire_bytes, const TcParseTableBase* table, const TcParseTableBase::FieldEntry& entry, uint16_t xform_val); // For FindFieldEntry tests: friend class FindFieldEntryTest; - friend struct ParseFunctionGeneratorTestPeer; static constexpr const uint32_t kMtSmallScanSize = 4; // Mini parsing: - template static const char* MpVarint(PROTOBUF_TC_PARAM_DECL); static const char* MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL); static const char* MpPackedVarint(PROTOBUF_TC_PARAM_DECL); - template static const char* MpFixed(PROTOBUF_TC_PARAM_DECL); static const char* MpRepeatedFixed(PROTOBUF_TC_PARAM_DECL); static const char* MpPackedFixed(PROTOBUF_TC_PARAM_DECL); - template static const char* MpString(PROTOBUF_TC_PARAM_DECL); static const char* MpRepeatedString(PROTOBUF_TC_PARAM_DECL); - template static const char* MpMessage(PROTOBUF_TC_PARAM_DECL); static const char* MpRepeatedMessage(PROTOBUF_TC_PARAM_DECL); static const char* MpMap(PROTOBUF_TC_PARAM_DECL); }; -// Notes: -// 1) if data_offset is negative, it's read from data.offset() -// 2) if hasbit_idx is negative, it's read from data.hasbit_idx() -template -const char* TcParser::SpecializedFastV8S1(PROTOBUF_TC_PARAM_DECL) { - using TagType = uint8_t; - - // Special case for a varint bool field with a tag of 1 byte: - // The coded_tag() field will actually contain the value too and we can check - // both at the same time. - auto coded_tag = data.coded_tag(); - if (PROTOBUF_PREDICT_TRUE(coded_tag == 0x0000 || coded_tag == 0x0100)) { - auto& field = - RefAt(msg, data_offset >= 0 ? data_offset : data.offset()); - // Note: we use `data.data` because Clang generates suboptimal code when - // using coded_tag. - // In x86_64 this uses the CH register to read the second byte out of - // `data`. - uint8_t value = data.data >> 8; - // The assume allows using a mov instead of test+setne. - PROTOBUF_ASSUME(value <= 1); - field = static_cast(value); - - ptr += sizeof(TagType) + 1; // Consume the tag and the value. - if (hasbit_idx < 0) { - hasbits |= (uint64_t{1} << data.hasbit_idx()); - } else { - if (hasbit_idx < 32) { - hasbits |= (uint64_t{1} << hasbit_idx); - } else { - static_assert(hasbit_idx == 63 || (hasbit_idx < 32), - "hard-coded hasbit_idx should be 0-31, or the special" - "value 63, which indicates the field has no has-bit."); - // TODO(jorg): investigate whether higher hasbit indices are worth - // supporting. Something like: - // auto& hasblock = TcParser::RefAt(msg, hasbit_idx / 32 * 4); - // hasblock |= uint32_t{1} << (hasbit_idx % 32); - } - } - - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - - // If it didn't match above either the tag is wrong, or the value is encoded - // non-canonically. - // Jump to MiniParse as wrong tag is the most probable reason. - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); -} - -template -const char* TcParser::SpecializedUnrolledVImpl1(PROTOBUF_TC_PARAM_DECL) { - using TagType = uint8_t; - // super-early success test... - if (PROTOBUF_PREDICT_TRUE(((data.data) & 0x80FF) == 0)) { - ptr += sizeof(TagType); // Consume tag - if (hasbit_idx < 32) { - hasbits |= (uint64_t{1} << hasbit_idx); - } - uint8_t value = data.data >> 8; - RefAt(msg, data_offset) = value; - ptr += 1; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - ptr += sizeof(TagType); // Consume tag - if (hasbit_idx < 32) { - hasbits |= (uint64_t{1} << hasbit_idx); - } - - // Few registers - auto* out = &RefAt(msg, data_offset); - uint64_t res = 0xFF & (data.data >> 8); - /* if (PROTOBUF_PREDICT_FALSE(res & 0x80)) */ { - res = RotRight7AndReplaceLowByte(res, ptr[1]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[2]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[3]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[4]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[5]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[6]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[7]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - res = RotRight7AndReplaceLowByte(res, ptr[8]); - if (PROTOBUF_PREDICT_FALSE(res & 0x80)) { - if (ptr[9] & 0xFE) return nullptr; - res = RotateLeft(res, -7) & ~1; - res += ptr[9] & 1; - *out = RotateLeft(res, 63); - ptr += 10; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 56); - ptr += 9; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 49); - ptr += 8; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 42); - ptr += 7; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 35); - ptr += 6; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 28); - ptr += 5; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 21); - ptr += 4; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 14); - ptr += 3; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = RotateLeft(res, 7); - ptr += 2; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); - } - *out = res; - ptr += 1; - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); -} - -// Dispatch to the designated parse function -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::TagDispatch( - PROTOBUF_TC_PARAM_DECL) { - const auto coded_tag = UnalignedLoad(ptr); - const size_t idx = coded_tag & table->fast_idx_mask; - PROTOBUF_ASSUME((idx & 7) == 0); - auto* fast_entry = table->fast_entry(idx >> 3); - data = fast_entry->bits; - data.data ^= coded_tag; - PROTOBUF_MUSTTAIL return fast_entry->target()(PROTOBUF_TC_PARAM_PASS); -} - -// We can only safely call from field to next field if the call is optimized -// to a proper tail call. Otherwise we blow through stack. Clang and gcc -// reliably do this optimization in opt mode, but do not perform this in debug -// mode. Luckily the structure of the algorithm is such that it's always -// possible to just return and use the enclosing parse loop as a trampoline. -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToTagDispatch( - PROTOBUF_TC_PARAM_DECL) { - constexpr bool always_return = !PROTOBUF_TAILCALL; - if (always_return || !ctx->DataAvailable(ptr)) { - PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); - } - PROTOBUF_MUSTTAIL return TagDispatch(PROTOBUF_TC_PARAM_PASS); -} - -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToParseLoop( - PROTOBUF_TC_PARAM_DECL) { - (void)data; - (void)ctx; - SyncHasbits(msg, hasbits, table); - return ptr; -} - -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::Error( - PROTOBUF_TC_PARAM_DECL) { - (void)data; - (void)ctx; - (void)ptr; - SyncHasbits(msg, hasbits, table); - return nullptr; -} - } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_IMPL_H__ diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_lite.cc b/libs/protobuf/src/google/protobuf/generated_message_tctable_lite.cc index f8402d3..9993811 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_lite.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_tctable_lite.cc @@ -30,18 +30,17 @@ #include #include -#include -#include "google/protobuf/extension_set.h" -#include "google/protobuf/generated_message_tctable_decl.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/inlined_string_field.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { @@ -67,31 +66,78 @@ const char* TcParser::GenericFallbackLite(PROTOBUF_TC_PARAM_DECL) { // Core fast parsing implementation: ////////////////////////////////////////////////////////////////////////////// +class TcParser::ScopedArenaSwap final { + public: + ScopedArenaSwap(MessageLite* msg, ParseContext* ctx) + : ctx_(ctx), saved_(ctx->data().arena) { + ctx_->data().arena = msg->GetArenaForAllocation(); + } + ScopedArenaSwap(const ScopedArenaSwap&) = delete; + ~ScopedArenaSwap() { ctx_->data().arena = saved_; } + + private: + ParseContext* const ctx_; + Arena* const saved_; +}; + PROTOBUF_NOINLINE const char* TcParser::ParseLoop( MessageLite* msg, const char* ptr, ParseContext* ctx, const TcParseTableBase* table) { - // Note: TagDispatch uses a dispatch table at "&table->fast_entries". - // For fast dispatch, we'd like to have a pointer to that, but if we use - // that expression, there's no easy way to get back to "table", which we also - // need during dispatch. It turns out that "table + 1" points exactly to - // fast_entries, so we just increment table by 1 here, to get the register - // holding the value we want. - table += 1; + ScopedArenaSwap saved(msg, ctx); while (!ctx->Done(&ptr)) { -#if defined(__GNUC__) - // Note: this asm prevents the compiler (clang, specifically) from - // believing (thanks to CSE) that it needs to dedicate a registeer both - // to "table" and "&table->fast_entries". - // TODO(b/64614992): remove this asm - asm("" : "+r"(table)); -#endif - ptr = TagDispatch(msg, ptr, ctx, {}, table - 1, 0); + // Unconditionally read has bits, even if we don't have has bits. + // has_bits_offset will be 0 and we will just read something valid. + uint64_t hasbits = ReadAt(msg, table->has_bits_offset); + ptr = TagDispatch(msg, ptr, ctx, table, hasbits, {}); if (ptr == nullptr) break; if (ctx->LastTag() != 1) break; // Ended on terminating tag } return ptr; } + // Dispatch to the designated parse function +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::TagDispatch( + PROTOBUF_TC_PARAM_DECL) { + const auto coded_tag = UnalignedLoad(ptr); + const size_t idx = coded_tag & table->fast_idx_mask; + PROTOBUF_ASSUME((idx & 7) == 0); + auto* fast_entry = table->fast_entry(idx >> 3); + data = fast_entry->bits; + data.data ^= coded_tag; + PROTOBUF_MUSTTAIL return fast_entry->target(PROTOBUF_TC_PARAM_PASS); +} + +// We can only safely call from field to next field if the call is optimized +// to a proper tail call. Otherwise we blow through stack. Clang and gcc +// reliably do this optimization in opt mode, but do not perform this in debug +// mode. Luckily the structure of the algorithm is such that it's always +// possible to just return and use the enclosing parse loop as a trampoline. +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToTagDispatch( + PROTOBUF_TC_PARAM_DECL) { + constexpr bool always_return = !PROTOBUF_TAILCALL; + if (always_return || !ctx->DataAvailable(ptr)) { + PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); + } + PROTOBUF_MUSTTAIL return TagDispatch(PROTOBUF_TC_PARAM_PASS); +} + +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ToParseLoop( + PROTOBUF_TC_PARAM_DECL) { + (void)data; + (void)ctx; + SyncHasbits(msg, hasbits, table); + return ptr; +} + +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::Error( + PROTOBUF_TC_PARAM_DECL) { + (void)data; + (void)ctx; + (void)ptr; + SyncHasbits(msg, hasbits, table); + return nullptr; +} + // On the fast path, a (matching) 1-byte tag already has the decoded value. static uint32_t FastDecodeTag(uint8_t coded_tag) { return coded_tag; @@ -225,7 +271,7 @@ const TcParseTableBase::FieldEntry* TcParser::FindFieldEntry( // This is designed to be compact but not particularly fast to retrieve. // In particular, it takes O(n) to retrieve the name of the n'th field, // which is usually fine because most protos have fewer than 10 fields. -static absl::string_view FindName(const char* name_data, size_t entries, +static StringPiece FindName(const char* name_data, size_t entries, size_t index) { // The compiler unrolls these... if this isn't fast enough, // there's an AVX version at https://godbolt.org/z/eojrjqzfr @@ -241,11 +287,11 @@ static absl::string_view FindName(const char* name_data, size_t entries, return {start, size}; } -absl::string_view TcParser::MessageName(const TcParseTableBase* table) { +StringPiece TcParser::MessageName(const TcParseTableBase* table) { return FindName(table->name_data(), table->num_field_entries + 1, 0); } -absl::string_view TcParser::FieldName(const TcParseTableBase* table, +StringPiece TcParser::FieldName(const TcParseTableBase* table, const FieldEntry* field_entry) { const FieldEntry* const field_entries = table->field_entries_begin(); auto field_index = static_cast(field_entry - field_entries); @@ -256,9 +302,7 @@ absl::string_view TcParser::FieldName(const TcParseTableBase* table, const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { uint32_t tag; ptr = ReadTagInlined(ptr, &tag); - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) { - return Error(PROTOBUF_TC_PARAM_PASS); - } + if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) return nullptr; auto* entry = FindFieldEntry(table, tag >> 3); if (entry == nullptr) { @@ -274,67 +318,36 @@ const char* TcParser::MiniParse(PROTOBUF_TC_PARAM_DECL) { data.data = entry_offset << 32 | tag; using field_layout::FieldKind; - auto field_type = - entry->type_card & (+field_layout::kSplitMask | FieldKind::kFkMask); + auto field_type = entry->type_card & FieldKind::kFkMask; switch (field_type) { case FieldKind::kFkNone: PROTOBUF_MUSTTAIL return table->fallback(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkVarint: - PROTOBUF_MUSTTAIL return MpVarint(PROTOBUF_TC_PARAM_PASS); + PROTOBUF_MUSTTAIL return MpVarint(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkPackedVarint: PROTOBUF_MUSTTAIL return MpPackedVarint(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkFixed: - PROTOBUF_MUSTTAIL return MpFixed(PROTOBUF_TC_PARAM_PASS); + PROTOBUF_MUSTTAIL return MpFixed(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkPackedFixed: PROTOBUF_MUSTTAIL return MpPackedFixed(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkString: - PROTOBUF_MUSTTAIL return MpString(PROTOBUF_TC_PARAM_PASS); + PROTOBUF_MUSTTAIL return MpString(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkMessage: - PROTOBUF_MUSTTAIL return MpMessage(PROTOBUF_TC_PARAM_PASS); + PROTOBUF_MUSTTAIL return MpMessage(PROTOBUF_TC_PARAM_PASS); case FieldKind::kFkMap: PROTOBUF_MUSTTAIL return MpMap(PROTOBUF_TC_PARAM_PASS); - - case +field_layout::kSplitMask | FieldKind::kFkNone: - PROTOBUF_FALLTHROUGH_INTENDED; - case +field_layout::kSplitMask | FieldKind::kFkPackedVarint: - PROTOBUF_FALLTHROUGH_INTENDED; - case +field_layout::kSplitMask | FieldKind::kFkPackedFixed: - PROTOBUF_FALLTHROUGH_INTENDED; - case +field_layout::kSplitMask | FieldKind::kFkMap: - return Error(PROTOBUF_TC_PARAM_PASS); - - case +field_layout::kSplitMask | FieldKind::kFkVarint: - PROTOBUF_MUSTTAIL return MpVarint(PROTOBUF_TC_PARAM_PASS); - case +field_layout::kSplitMask | FieldKind::kFkFixed: - PROTOBUF_MUSTTAIL return MpFixed(PROTOBUF_TC_PARAM_PASS); - case +field_layout::kSplitMask | FieldKind::kFkString: - PROTOBUF_MUSTTAIL return MpString(PROTOBUF_TC_PARAM_PASS); - case +field_layout::kSplitMask | FieldKind::kFkMessage: - PROTOBUF_MUSTTAIL return MpMessage(PROTOBUF_TC_PARAM_PASS); default: return Error(PROTOBUF_TC_PARAM_PASS); } } -template -const char* TcParser::FastEndGroupImpl(PROTOBUF_TC_PARAM_DECL) { - if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - ctx->SetLastTag(data.decoded_tag()); - ptr += sizeof(TagType); - PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEndG1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return FastEndGroupImpl(PROTOBUF_TC_PARAM_PASS); -} -const char* TcParser::FastEndG2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return FastEndGroupImpl(PROTOBUF_TC_PARAM_PASS); -} - namespace { +// Offset returns the address `offset` bytes after `base`. +inline void* Offset(void* base, uint32_t offset) { + return static_cast(base) + offset; +} + // InvertPacked changes tag bits from the given wire type to length // delimited. This is the difference expected between packed and non-packed // repeated fields. @@ -349,9 +362,9 @@ inline PROTOBUF_ALWAYS_INLINE void InvertPacked(TcFieldData& data) { // Message fields ////////////////////////////////////////////////////////////////////////////// -template -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularParseMessageAuxImpl( - PROTOBUF_TC_PARAM_DECL) { +template +inline PROTOBUF_ALWAYS_INLINE +const char* TcParser::SingularParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL) { if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); } @@ -360,145 +373,74 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularParseMessageAuxImpl( hasbits |= (uint64_t{1} << data.hasbit_idx()); SyncHasbits(msg, hasbits, table); auto& field = RefAt(msg, data.offset()); - - if (aux_is_table) { - const auto* inner_table = table->field_aux(data.aux_idx())->table; - if (field == nullptr) { - field = inner_table->default_instance->New(msg->GetArenaForAllocation()); - } - if (group_coding) { - return ctx->ParseGroup(field, ptr, FastDecodeTag(saved_tag), - inner_table); - } - return ctx->ParseMessage(field, ptr, inner_table); - } else { - if (field == nullptr) { - const MessageLite* default_instance = - table->field_aux(data.aux_idx())->message_default(); - field = default_instance->New(msg->GetArenaForAllocation()); - } - if (group_coding) { - return ctx->ParseGroup(field, ptr, FastDecodeTag(saved_tag)); - } - return ctx->ParseMessage(field, ptr); + if (field == nullptr) { + const MessageLite* default_instance = + table->field_aux(data.aux_idx())->message_default; + field = default_instance->New(ctx->data().arena); } + if (group_coding) { + return ctx->ParseGroup(field, ptr, FastDecodeTag(saved_tag)); + } + return ctx->ParseMessage(field, ptr); } -const char* TcParser::FastMdS1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( +const char* TcParser::FastMS1(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastMdS2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( +const char* TcParser::FastMS2(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastGdS1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( +const char* TcParser::FastGS1(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastGdS2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( +const char* TcParser::FastGS2(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastMtS1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastMtS2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastGtS1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastGtS2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -template -inline PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedParseMessageAuxImpl( - PROTOBUF_TC_PARAM_DECL) { +template +inline PROTOBUF_ALWAYS_INLINE +const char* TcParser::RepeatedParseMessageAuxImpl(PROTOBUF_TC_PARAM_DECL) { if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); } - const auto expected_tag = UnalignedLoad(ptr); - const auto aux = *table->field_aux(data.aux_idx()); + auto saved_tag = UnalignedLoad(ptr); + ptr += sizeof(TagType); + SyncHasbits(msg, hasbits, table); + const MessageLite* default_instance = + table->field_aux(data.aux_idx())->message_default; auto& field = RefAt(msg, data.offset()); - do { - ptr += sizeof(TagType); - MessageLite* submsg = field.Add>( - aux_is_table ? aux.table->default_instance : aux.message_default()); - if (aux_is_table) { - if (group_coding) { - ptr = ctx->ParseGroup(submsg, ptr, - FastDecodeTag(expected_tag), aux.table); - } else { - ptr = ctx->ParseMessage(submsg, ptr, aux.table); - } - } else { - if (group_coding) { - ptr = ctx->ParseGroup(submsg, ptr, FastDecodeTag(expected_tag)); - } else { - ptr = ctx->ParseMessage(submsg, ptr); - } - } - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) { - PROTOBUF_MUSTTAIL return Error(PROTOBUF_TC_PARAM_PASS); - } - if (PROTOBUF_PREDICT_FALSE(!ctx->DataAvailable(ptr))) { - PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); - } - } while (UnalignedLoad(ptr) == expected_tag); - - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); + MessageLite* submsg = + field.Add>(default_instance); + if (group_coding) { + return ctx->ParseGroup(submsg, ptr, FastDecodeTag(saved_tag)); + } + return ctx->ParseMessage(submsg, ptr); } -const char* TcParser::FastMdR1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( +const char* TcParser::FastMR1(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastMdR2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( +const char* TcParser::FastMR2(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastGdR1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( +const char* TcParser::FastGR1(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } -const char* TcParser::FastGdR2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastMtR1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastMtR2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastGtR1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastGtR2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( +const char* TcParser::FastGR2(PROTOBUF_TC_PARAM_DECL) { + PROTOBUF_MUSTTAIL return RepeatedParseMessageAuxImpl( PROTOBUF_TC_PARAM_PASS); } @@ -556,7 +498,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedFixed( auto elem = field.Add(); int space = field.Capacity() - idx; idx = 0; - const auto expected_tag = UnalignedLoad(ptr); + auto expected_tag = UnalignedLoad(ptr); do { ptr += sizeof(TagType); elem[idx++] = UnalignedLoad(ptr); @@ -826,13 +768,7 @@ PROTOBUF_NOINLINE const char* TcParser::SingularVarBigint( const ::google::protobuf::internal::TcParseTableBase* table; uint64_t hasbits; }; - Spill spill = {data.data, msg, table, hasbits}; -#if defined(__GNUC__) - // This empty asm block convinces the compiler that the contents of spill may - // have changed, and thus can't be cached in registers. It's similar to, but - // more optimal then, the effect of declaring it "volatile". - asm("" : "+m"(spill)); -#endif + volatile Spill spill = {data.data, msg, table, hasbits}; uint64_t tmp; PROTOBUF_ASSUME(static_cast(*ptr) < 0); @@ -852,7 +788,8 @@ PROTOBUF_NOINLINE const char* TcParser::SingularVarBigint( } const char* TcParser::FastV8S1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SpecializedFastV8S1<-1, -1>(PROTOBUF_TC_PARAM_PASS); + PROTOBUF_MUSTTAIL return SingularVarint( + PROTOBUF_TC_PARAM_PASS); } const char* TcParser::FastV8S2(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_MUSTTAIL return SingularVarint( @@ -905,7 +842,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedVarint( } } auto& field = RefAt>(msg, data.offset()); - const auto expected_tag = UnalignedLoad(ptr); + auto expected_tag = UnalignedLoad(ptr); do { ptr += sizeof(TagType); uint64_t tmp; @@ -1040,6 +977,10 @@ const char* TcParser::FastZ64P2(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_NOINLINE const char* TcParser::FastUnknownEnumFallback( PROTOBUF_TC_PARAM_DECL) { + (void)msg; + (void)ctx; + (void)hasbits; + // If we know we want to put this field directly into the unknown field set, // then we can skip the call to MiniParse and directly call table->fallback. // However, we first have to update `data` to contain the decoded tag. @@ -1106,7 +1047,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedEnum( } } auto& field = RefAt>(msg, data.offset()); - const auto expected_tag = UnalignedLoad(ptr); + auto expected_tag = UnalignedLoad(ptr); const TcParseTableBase::FieldAux aux = *table->field_aux(data.aux_idx()); do { const char* ptr2 = ptr; // save for unknown enum case @@ -1148,98 +1089,13 @@ const char* TcParser::FastEvR2(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_TC_PARAM_PASS); } -template -PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularEnumSmallRange( - PROTOBUF_TC_PARAM_DECL) { - if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - - uint8_t v = ptr[sizeof(TagType)]; - if (PROTOBUF_PREDICT_FALSE(min > v || v > data.aux_idx())) { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - - RefAt(msg, data.offset()) = v; - ptr += sizeof(TagType) + 1; - hasbits |= (uint64_t{1} << data.hasbit_idx()); - PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr0S1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr0S2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr1S1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr1S2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return SingularEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - - -template -PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedEnumSmallRange( - PROTOBUF_TC_PARAM_DECL) { - if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { - InvertPacked(data); - if (data.coded_tag() == 0) { - // Packed parsing is handled by generated fallback. - PROTOBUF_MUSTTAIL return FastUnknownEnumFallback(PROTOBUF_TC_PARAM_PASS); - } else { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - } - auto& field = RefAt>(msg, data.offset()); - auto expected_tag = UnalignedLoad(ptr); - const uint8_t max = data.aux_idx(); - do { - uint8_t v = ptr[sizeof(TagType)]; - if (PROTOBUF_PREDICT_FALSE(min > v || v > max)) { - PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); - } - field.Add(static_cast(v)); - ptr += sizeof(TagType) + 1; - if (PROTOBUF_PREDICT_FALSE(!ctx->DataAvailable(ptr))) break; - } while (UnalignedLoad(ptr) == expected_tag); - - PROTOBUF_MUSTTAIL return ToParseLoop(PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr0R1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} -const char* TcParser::FastEr0R2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - -const char* TcParser::FastEr1R1(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} -const char* TcParser::FastEr1R2(PROTOBUF_TC_PARAM_DECL) { - PROTOBUF_MUSTTAIL return RepeatedEnumSmallRange( - PROTOBUF_TC_PARAM_PASS); -} - ////////////////////////////////////////////////////////////////////////////// // String/bytes fields ////////////////////////////////////////////////////////////////////////////// // Defined in wire_format_lite.cc -void PrintUTF8ErrorLog(absl::string_view message_name, - absl::string_view field_name, const char* operation_str, +void PrintUTF8ErrorLog(StringPiece message_name, + StringPiece field_name, const char* operation_str, bool emit_stacktrace); void TcParser::ReportFastUtf8Error(uint32_t decoded_tag, @@ -1272,7 +1128,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularString( ptr += sizeof(TagType); hasbits |= (uint64_t{1} << data.hasbit_idx()); auto& field = RefAt(msg, data.offset()); - auto arena = msg->GetArenaForAllocation(); + auto arena = ctx->data().arena; if (arena) { ptr = ctx->ReadArenaString(ptr, &field, arena); } else { @@ -1286,7 +1142,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularString( #endif return ToParseLoop(PROTOBUF_TC_PARAM_PASS); default: - if (PROTOBUF_PREDICT_TRUE(::google::protobuf::internal::IsStructurallyValidUTF8(field.Get()))) { + if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(field.Get()))) { return ToParseLoop(PROTOBUF_TC_PARAM_PASS); } ReportFastUtf8Error(FastDecodeTag(saved_tag), table); @@ -1347,52 +1203,31 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedString( if (PROTOBUF_PREDICT_FALSE(data.coded_tag() != 0)) { PROTOBUF_MUSTTAIL return MiniParse(PROTOBUF_TC_PARAM_PASS); } - const auto expected_tag = UnalignedLoad(ptr); + auto expected_tag = UnalignedLoad(ptr); auto& field = RefAt>(msg, data.offset()); - - const auto validate_last_string = [expected_tag, table, &field] { + do { + ptr += sizeof(TagType); + std::string* str = field.Add(); + ptr = InlineGreedyStringParser(str, ptr, ctx); + if (ptr == nullptr) { + return Error(PROTOBUF_TC_PARAM_PASS); + } switch (utf8) { case kNoUtf8: #ifdef NDEBUG case kUtf8ValidateOnly: #endif - return true; + break; default: - if (PROTOBUF_PREDICT_TRUE( - ::google::protobuf::internal::IsStructurallyValidUTF8(field[field.size() - 1]))) { - return true; + if (PROTOBUF_PREDICT_TRUE(IsStructurallyValidUTF8(*str))) { + break; } ReportFastUtf8Error(FastDecodeTag(expected_tag), table); - if (utf8 == kUtf8) return false; - return true; + if (utf8 == kUtf8) return Error(PROTOBUF_TC_PARAM_PASS); + break; } - }; - - auto* arena = field.GetOwningArena(); - SerialArena* serial_arena; - if (PROTOBUF_PREDICT_TRUE(arena != nullptr && - arena->impl_.GetSerialArenaFast(&serial_arena) && - field.PrepareForParse())) { - do { - ptr += sizeof(TagType); - ptr = ParseRepeatedStringOnce(ptr, arena, serial_arena, ctx, field); - - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || !validate_last_string())) { - return Error(PROTOBUF_TC_PARAM_PASS); - } - if (!ctx->DataAvailable(ptr)) break; - } while (UnalignedLoad(ptr) == expected_tag); - } else { - do { - ptr += sizeof(TagType); - std::string* str = field.Add(); - ptr = InlineGreedyStringParser(str, ptr, ctx); - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || !validate_last_string())) { - return Error(PROTOBUF_TC_PARAM_PASS); - } - if (!ctx->DataAvailable(ptr)) break; - } while (UnalignedLoad(ptr) == expected_tag); - } + if (!ctx->DataAvailable(ptr)) break; + } while (UnalignedLoad(ptr) == expected_tag); return ToParseLoop(PROTOBUF_TC_PARAM_PASS); } @@ -1426,14 +1261,20 @@ const char* TcParser::FastUR2(PROTOBUF_TC_PARAM_DECL) { ////////////////////////////////////////////////////////////////////////////// namespace { -inline void SetHas(const FieldEntry& entry, MessageLite* msg) { - auto has_idx = static_cast(entry.has_idx); +inline void SetHas(const TcParseTableBase* table, const FieldEntry& entry, + MessageLite* msg, uint64_t& hasbits) { + int32_t has_idx = entry.has_idx; + if (has_idx < 32) { + hasbits |= uint64_t{1} << has_idx; + } else { + auto* hasblocks = &TcParser::RefAt(msg, table->has_bits_offset); #if defined(__x86_64__) && defined(__GNUC__) - asm("bts %1, %0\n" : "+m"(*msg) : "r"(has_idx)); + asm("bts %1, %0\n" : "+m"(*hasblocks) : "r"(has_idx)); #else - auto& hasblock = TcParser::RefAt(msg, has_idx / 32 * 4); - hasblock |= uint32_t{1} << (has_idx % 32); + auto& hasblock = hasblocks[has_idx / 32]; + hasblock |= uint32_t{1} << (has_idx % 32); #endif + } } } // namespace @@ -1444,8 +1285,11 @@ bool TcParser::ChangeOneof(const TcParseTableBase* table, const TcParseTableBase::FieldEntry& entry, uint32_t field_num, ParseContext* ctx, MessageLite* msg) { - // The _oneof_case_ value offset is stored in the has-bit index. - uint32_t* oneof_case = &TcParser::RefAt(msg, entry.has_idx); + // The _oneof_case_ array offset is stored in the first aux entry. + uint32_t oneof_case_offset = table->field_aux(0u)->offset; + // The _oneof_case_ array index is stored in the has-bit index. + uint32_t* oneof_case = + &TcParser::RefAt(msg, oneof_case_offset) + entry.has_idx; uint32_t current_case = *oneof_case; *oneof_case = field_num; @@ -1479,9 +1323,10 @@ bool TcParser::ChangeOneof(const TcParseTableBase* table, } else if (current_kind == field_layout::kFkMessage) { switch (current_rep) { case field_layout::kRepMessage: - case field_layout::kRepGroup: { + case field_layout::kRepGroup: + case field_layout::kRepIWeak: { auto& field = RefAt(msg, current_entry->offset); - if (!msg->GetArenaForAllocation()) { + if (!ctx->data().arena) { delete field; } break; @@ -1495,39 +1340,6 @@ bool TcParser::ChangeOneof(const TcParseTableBase* table, return true; } -namespace { -uint32_t GetSplitOffset(const TcParseTableBase* table) { - return table->field_aux(kSplitOffsetAuxIdx)->offset; -} - -uint32_t GetSizeofSplit(const TcParseTableBase* table) { - return table->field_aux(kSplitSizeAuxIdx)->offset; -} -} // namespace - -void* TcParser::MaybeGetSplitBase(MessageLite* msg, const bool is_split, - const TcParseTableBase* table, - ::google::protobuf::internal::ParseContext* ctx) { - void* out = msg; - if (is_split) { - const uint32_t split_offset = GetSplitOffset(table); - void* default_split = - TcParser::RefAt(table->default_instance, split_offset); - void*& split = TcParser::RefAt(msg, split_offset); - if (split == default_split) { - // Allocate split instance when needed. - uint32_t size = GetSizeofSplit(table); - Arena* arena = msg->GetArenaForAllocation(); - split = (arena == nullptr) ? ::operator new(size) - : arena->AllocateAligned(size); - memcpy(split, default_split, size); - } - out = split; - } - return out; -} - -template const char* TcParser::MpFixed(PROTOBUF_TC_PARAM_DECL) { const auto& entry = RefAt(table, data.entry_offset()); const uint16_t type_card = entry.type_card; @@ -1552,17 +1364,16 @@ const char* TcParser::MpFixed(PROTOBUF_TC_PARAM_DECL) { } // Set the field present: if (card == field_layout::kFcOptional) { - SetHas(entry, msg); + SetHas(table, entry, msg, hasbits); } else if (card == field_layout::kFcOneof) { ChangeOneof(table, entry, data.tag() >> 3, ctx, msg); } - void* const base = MaybeGetSplitBase(msg, is_split, table, ctx); // Copy the value: if (rep == field_layout::kRep64Bits) { - RefAt(base, entry.offset) = UnalignedLoad(ptr); + RefAt(msg, entry.offset) = UnalignedLoad(ptr); ptr += sizeof(uint64_t); } else { - RefAt(base, entry.offset) = UnalignedLoad(ptr); + RefAt(msg, entry.offset) = UnalignedLoad(ptr); ptr += sizeof(uint32_t); } PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); @@ -1647,7 +1458,6 @@ const char* TcParser::MpPackedFixed(PROTOBUF_TC_PARAM_DECL) { PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); } -template const char* TcParser::MpVarint(PROTOBUF_TC_PARAM_DECL) { const auto& entry = RefAt(table, data.entry_offset()); const uint16_t type_card = entry.type_card; @@ -1691,19 +1501,18 @@ const char* TcParser::MpVarint(PROTOBUF_TC_PARAM_DECL) { // Mark the field as present: const bool is_oneof = card == field_layout::kFcOneof; if (card == field_layout::kFcOptional) { - SetHas(entry, msg); + SetHas(table, entry, msg, hasbits); } else if (is_oneof) { ChangeOneof(table, entry, data.tag() >> 3, ctx, msg); } - void* const base = MaybeGetSplitBase(msg, is_split, table, ctx); if (rep == field_layout::kRep64Bits) { - RefAt(base, entry.offset) = tmp; + RefAt(msg, entry.offset) = tmp; } else if (rep == field_layout::kRep32Bits) { - RefAt(base, entry.offset) = static_cast(tmp); + RefAt(msg, entry.offset) = static_cast(tmp); } else { GOOGLE_DCHECK_EQ(rep, static_cast(field_layout::kRep8Bits)); - RefAt(base, entry.offset) = static_cast(tmp); + RefAt(msg, entry.offset) = static_cast(tmp); } PROTOBUF_MUSTTAIL return ToTagDispatch(PROTOBUF_TC_PARAM_PASS); @@ -1822,11 +1631,11 @@ const char* TcParser::MpPackedVarint(PROTOBUF_TC_PARAM_DECL) { return Error(PROTOBUF_TC_PARAM_PASS); } -bool TcParser::MpVerifyUtf8(absl::string_view wire_bytes, +bool TcParser::MpVerifyUtf8(StringPiece wire_bytes, const TcParseTableBase* table, const FieldEntry& entry, uint16_t xform_val) { if (xform_val == field_layout::kTvUtf8) { - if (!::google::protobuf::internal::IsStructurallyValidUTF8(wire_bytes)) { + if (!IsStructurallyValidUTF8(wire_bytes)) { PrintUTF8ErrorLog(MessageName(table), FieldName(table, &entry), "parsing", false); return false; @@ -1835,7 +1644,7 @@ bool TcParser::MpVerifyUtf8(absl::string_view wire_bytes, } #ifndef NDEBUG if (xform_val == field_layout::kTvUtf8Debug) { - if (!::google::protobuf::internal::IsStructurallyValidUTF8(wire_bytes)) { + if (!IsStructurallyValidUTF8(wire_bytes)) { PrintUTF8ErrorLog(MessageName(table), FieldName(table, &entry), "parsing", false); } @@ -1844,7 +1653,6 @@ bool TcParser::MpVerifyUtf8(absl::string_view wire_bytes, return true; } -template const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) { const auto& entry = RefAt(table, data.entry_offset()); const uint16_t type_card = entry.type_card; @@ -1868,18 +1676,17 @@ const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) { const bool is_oneof = card == field_layout::kFcOneof; bool need_init = false; if (card == field_layout::kFcOptional) { - SetHas(entry, msg); + SetHas(table, entry, msg, hasbits); } else if (is_oneof) { need_init = ChangeOneof(table, entry, data.tag() >> 3, ctx, msg); } bool is_valid = false; - void* const base = MaybeGetSplitBase(msg, is_split, table, ctx); + Arena* arena = ctx->data().arena; switch (rep) { case field_layout::kRepAString: { - auto& field = RefAt(base, entry.offset); + auto& field = RefAt(msg, entry.offset); if (need_init) field.InitDefault(); - Arena* arena = msg->GetArenaForAllocation(); if (arena) { ptr = ctx->ReadArenaString(ptr, &field, arena); } else { @@ -1902,19 +1709,6 @@ const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) { return ToParseLoop(PROTOBUF_TC_PARAM_PASS); } -PROTOBUF_ALWAYS_INLINE const char* TcParser::ParseRepeatedStringOnce( - const char* ptr, Arena* arena, SerialArena* serial_arena, ParseContext* ctx, - RepeatedPtrField& field) { - int size = ReadSize(&ptr); - if (PROTOBUF_PREDICT_FALSE(!ptr)) return {}; - auto* str = Arena::Create(arena); - field.AddAllocatedForParse(str); - ptr = ctx->ReadString(ptr, size, str); - if (PROTOBUF_PREDICT_FALSE(!ptr)) return {}; - PROTOBUF_ASSUME(ptr != nullptr); - return ptr; -} - const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) { const auto& entry = RefAt(table, data.entry_offset()); const uint16_t type_card = entry.type_card; @@ -1932,39 +1726,18 @@ const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) { auto& field = RefAt>(msg, entry.offset); const char* ptr2 = ptr; uint32_t next_tag; - - auto* arena = field.GetOwningArena(); - SerialArena* serial_arena; - if (PROTOBUF_PREDICT_TRUE( - arena != nullptr && - arena->impl_.GetSerialArenaFast(&serial_arena) && - field.PrepareForParse())) { - do { - ptr = ptr2; - ptr = ParseRepeatedStringOnce(ptr, arena, serial_arena, ctx, field); - if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || - !MpVerifyUtf8(field[field.size() - 1], - table, entry, xform_val))) { - return Error(PROTOBUF_TC_PARAM_PASS); - } - if (!ctx->DataAvailable(ptr)) break; - ptr2 = ReadTag(ptr, &next_tag); - } while (next_tag == decoded_tag); - } else { - do { - ptr = ptr2; - std::string* str = field.Add(); - ptr = InlineGreedyStringParser(str, ptr, ctx); - if (PROTOBUF_PREDICT_FALSE( - ptr == nullptr || - !MpVerifyUtf8(*str, table, entry, xform_val))) { - return Error(PROTOBUF_TC_PARAM_PASS); - } - if (!ctx->DataAvailable(ptr)) break; - ptr2 = ReadTag(ptr, &next_tag); - } while (next_tag == decoded_tag); - } - + do { + ptr = ptr2; + std::string* str = field.Add(); + ptr = InlineGreedyStringParser(str, ptr, ctx); + if (PROTOBUF_PREDICT_FALSE( + ptr == nullptr || + !MpVerifyUtf8(*str, table, entry, xform_val))) { + return Error(PROTOBUF_TC_PARAM_PASS); + } + if (!ctx->DataAvailable(ptr)) break; + ptr2 = ReadTag(ptr, &next_tag); + } while (next_tag == decoded_tag); break; } @@ -1978,7 +1751,6 @@ const char* TcParser::MpRepeatedString(PROTOBUF_TC_PARAM_DECL) { return ToParseLoop(PROTOBUF_TC_PARAM_PASS); } -template const char* TcParser::MpMessage(PROTOBUF_TC_PARAM_DECL) { const auto& entry = RefAt(table, data.entry_offset()); const uint16_t type_card = entry.type_card; @@ -2017,39 +1789,21 @@ const char* TcParser::MpMessage(PROTOBUF_TC_PARAM_DECL) { const bool is_oneof = card == field_layout::kFcOneof; bool need_init = false; if (card == field_layout::kFcOptional) { - SetHas(entry, msg); + SetHas(table, entry, msg, hasbits); } else if (is_oneof) { need_init = ChangeOneof(table, entry, data.tag() >> 3, ctx, msg); } - - void* const base = MaybeGetSplitBase(msg, is_split, table, ctx); - SyncHasbits(msg, hasbits, table); - MessageLite*& field = RefAt(base, entry.offset); - if ((type_card & field_layout::kTvMask) == field_layout::kTvTable) { - auto* inner_table = table->field_aux(&entry)->table; - if (need_init || field == nullptr) { - field = inner_table->default_instance->New(msg->GetArenaForAllocation()); - } - if (is_group) { - return ctx->ParseGroup(field, ptr, decoded_tag, inner_table); - } - return ctx->ParseMessage(field, ptr, inner_table); - } else { - if (need_init || field == nullptr) { - const MessageLite* def; - if ((type_card & field_layout::kTvMask) == field_layout::kTvDefault) { - def = table->field_aux(&entry)->message_default(); - } else { - GOOGLE_DCHECK_EQ(type_card & field_layout::kTvMask, +field_layout::kTvWeakPtr); - def = table->field_aux(&entry)->message_default_weak(); - } - field = def->New(msg->GetArenaForAllocation()); - } - if (is_group) { - return ctx->ParseGroup(field, ptr, decoded_tag); - } - return ctx->ParseMessage(field, ptr); + MessageLite*& field = RefAt(msg, entry.offset); + if (need_init || field == nullptr) { + const MessageLite* default_instance = + table->field_aux(&entry)->message_default; + field = default_instance->New(ctx->data().arena); } + SyncHasbits(msg, hasbits, table); + if (is_group) { + return ctx->ParseGroup(field, ptr, decoded_tag); + } + return ctx->ParseMessage(field, ptr); } const char* TcParser::MpRepeatedMessage(PROTOBUF_TC_PARAM_DECL) { @@ -2083,31 +1837,15 @@ const char* TcParser::MpRepeatedMessage(PROTOBUF_TC_PARAM_DECL) { } SyncHasbits(msg, hasbits, table); + const MessageLite* default_instance = + table->field_aux(&entry)->message_default; auto& field = RefAt(msg, entry.offset); - const auto aux = *table->field_aux(&entry); - if ((type_card & field_layout::kTvMask) == field_layout::kTvTable) { - auto* inner_table = aux.table; - auto& field = RefAt(msg, entry.offset); - MessageLite* value = field.Add>( - inner_table->default_instance); - if (is_group) { - return ctx->ParseGroup(value, ptr, decoded_tag, inner_table); - } - return ctx->ParseMessage(value, ptr, inner_table); - } else { - const MessageLite* def; - if ((type_card & field_layout::kTvMask) == field_layout::kTvDefault) { - def = aux.message_default(); - } else { - GOOGLE_DCHECK_EQ(type_card & field_layout::kTvMask, +field_layout::kTvWeakPtr); - def = aux.message_default_weak(); - } - MessageLite* value = field.Add>(def); - if (is_group) { - return ctx->ParseGroup(value, ptr, decoded_tag); - } - return ctx->ParseMessage(value, ptr); + MessageLite* value = + field.Add>(default_instance); + if (is_group) { + return ctx->ParseGroup(value, ptr, decoded_tag); } + return ctx->ParseMessage(value, ptr); } const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) { diff --git a/libs/protobuf/src/google/protobuf/generated_message_tctable_lite_test.cc b/libs/protobuf/src/google/protobuf/generated_message_tctable_lite_test.cc index 79b0d46..4310803 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_tctable_lite_test.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_tctable_lite_test.cc @@ -30,8 +30,8 @@ #include -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include #include #include @@ -45,7 +45,7 @@ using ::testing::Eq; using ::testing::Not; MATCHER_P3(IsEntryForFieldNum, table, field_num, field_numbers_table, - absl::StrCat(negation ? "isn't " : "", + StrCat(negation ? "isn't " : "", "the field entry for field number ", field_num)) { if (arg == nullptr) { *result_listener << "which is nullptr"; @@ -80,7 +80,7 @@ TEST(IsEntryForFieldNumTest, Matcher) { }}; // clang-format on int table_field_numbers[] = {1, 2, 3}; - table.field_lookup_table = {{65535, 65535}}; + table.field_lookup_table = {65535, 65535}; auto& entries = table.field_entries; EXPECT_THAT(&entries[0], IsEntryForFieldNum(&table, 1, table_field_numbers)); @@ -108,7 +108,7 @@ class FindFieldEntryTest : public ::testing::Test { // Calls the private `FieldName` function. template - static absl::string_view FieldName( + static StringPiece FieldName( const TcParseTable& table, const TcParseTableBase::FieldEntry* entry) { @@ -118,7 +118,7 @@ class FindFieldEntryTest : public ::testing::Test { // Calls the private `MessageName` function. template - static absl::string_view MessageName( + static StringPiece MessageName( const TcParseTable& table) { return TcParser::MessageName(&table.header); @@ -300,10 +300,10 @@ TEST_F(FindFieldEntryTest, OutOfRange) { EXPECT_THAT(entry, IsEntryForFieldNum(&table, field_num, table_field_numbers)); - absl::string_view name = FieldName(table, entry); + StringPiece name = FieldName(table, entry); EXPECT_EQ(name.length(), field_num); while (name[0] == '0') name.remove_prefix(1); // strip leading zeores - EXPECT_EQ(name, absl::StrCat(field_num)); + EXPECT_EQ(name, StrCat(field_num)); } for (int field_num : {0, 4, 112, 500000000}) { EXPECT_THAT(FindFieldEntry(table, field_num), Eq(nullptr)); @@ -557,7 +557,7 @@ TEST_F(FindFieldEntryTest, BigMessage) { for (int field_num : {1, 12, 31, 42, 57, 68, 79, 90, 101, 119, 249, 402, 412}) { auto* entry = FindFieldEntry(test_all_types_table, field_num); - absl::string_view name = FieldName(test_all_types_table, entry); + StringPiece name = FieldName(test_all_types_table, entry); switch (field_num) { case 1: EXPECT_THAT(name, Eq("optional_int32")); diff --git a/libs/protobuf/src/google/protobuf/generated_message_util.cc b/libs/protobuf/src/google/protobuf/generated_message_util.cc index f9c75c6..cad12a3 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_util.cc +++ b/libs/protobuf/src/google/protobuf/generated_message_util.cc @@ -32,23 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/generated_message_util.h" +#include #include #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.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 +#include +#include +#include +#include +#include +#include +#include // Must be included last -#include "google/protobuf/port_def.inc" +#include PROTOBUF_PRAGMA_INIT_SEG @@ -406,4 +406,4 @@ MessageLite* GetOwnedMessageInternal(Arena* message_arena, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/generated_message_util.h b/libs/protobuf/src/google/protobuf/generated_message_util.h index 42c7db7..71d15cd 100644 --- a/libs/protobuf/src/google/protobuf/generated_message_util.h +++ b/libs/protobuf/src/google/protobuf/generated_message_util.h @@ -43,24 +43,22 @@ #include #include #include -#include #include -#include "google/protobuf/stubs/common.h" -#include "absl/base/call_once.h" -#include "absl/base/casts.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/any.h" -#include "google/protobuf/has_bits.h" -#include "google/protobuf/implicit_weak_message.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/wire_format_lite.h" - +#include +#include // Add direct dep on port for pb.cc +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -78,6 +76,15 @@ class CodedInputStream; namespace internal { +template +inline To DownCast(From* f) { + return PROTOBUF_NAMESPACE_ID::internal::down_cast(f); +} +template +inline To DownCast(From& f) { + return PROTOBUF_NAMESPACE_ID::internal::down_cast(f); +} + // This fastpath inlines a single branch instead of having to make the // InitProtobufDefaults function call. @@ -178,58 +185,13 @@ T* GetOwnedMessage(Arena* message_arena, T* submessage, // Hide atomic from the public header and allow easy change to regular int // on platforms where the atomic might have a perf impact. -// -// CachedSize is like std::atomic but with some important changes: -// -// 1) CachedSize uses Get / Set rather than load / store. -// 2) CachedSize always uses relaxed ordering. -// 3) CachedSize is assignable and copy-constructible. -// 4) CachedSize has a constexpr default constructor, and a constexpr -// constructor that takes an int argument. -// 5) If the compiler supports the __atomic_load_n / __atomic_store_n builtins, -// then CachedSize is trivially copyable. -// -// Developed at https://godbolt.org/z/vYcx7zYs1 ; supports gcc, clang, MSVC. class PROTOBUF_EXPORT CachedSize { - private: - using Scalar = int; - public: - constexpr CachedSize() noexcept : atom_(Scalar{}) {} - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr CachedSize(Scalar desired) noexcept : atom_(desired) {} -#if PROTOBUF_BUILTIN_ATOMIC - constexpr CachedSize(const CachedSize& other) = default; - - Scalar Get() const noexcept { - return __atomic_load_n(&atom_, __ATOMIC_RELAXED); - } - - void Set(Scalar desired) noexcept { - __atomic_store_n(&atom_, desired, __ATOMIC_RELAXED); - } -#else - CachedSize(const CachedSize& other) noexcept : atom_(other.Get()) {} - CachedSize& operator=(const CachedSize& other) noexcept { - Set(other.Get()); - return *this; - } - - Scalar Get() const noexcept { // - return atom_.load(std::memory_order_relaxed); - } - - void Set(Scalar desired) noexcept { - atom_.store(desired, std::memory_order_relaxed); - } -#endif + int Get() const { return size_.load(std::memory_order_relaxed); } + void Set(int size) { size_.store(size, std::memory_order_relaxed); } private: -#if PROTOBUF_BUILTIN_ATOMIC - Scalar atom_; -#else - std::atomic atom_; -#endif + std::atomic size_{0}; }; PROTOBUF_EXPORT void DestroyMessage(const void* message); @@ -247,6 +209,6 @@ inline void OnShutdownDestroyString(const std::string* ptr) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/has_bits.h b/libs/protobuf/src/google/protobuf/has_bits.h index b90c450..f8a4587 100644 --- a/libs/protobuf/src/google/protobuf/has_bits.h +++ b/libs/protobuf/src/google/protobuf/has_bits.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_HAS_BITS_H__ #define GOOGLE_PROTOBUF_HAS_BITS_H__ -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/port.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -112,6 +112,6 @@ inline bool HasBits::empty() const { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_HAS_BITS_H__ diff --git a/libs/protobuf/src/google/protobuf/implicit_weak_message.cc b/libs/protobuf/src/google/protobuf/implicit_weak_message.cc index 5fac836..27ed6b6 100644 --- a/libs/protobuf/src/google/protobuf/implicit_weak_message.cc +++ b/libs/protobuf/src/google/protobuf/implicit_weak_message.cc @@ -28,14 +28,14 @@ // (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/implicit_weak_message.h" +#include -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include PROTOBUF_PRAGMA_INIT_SEG @@ -69,4 +69,4 @@ const ImplicitWeakMessage* ImplicitWeakMessage::default_instance() { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/implicit_weak_message.h b/libs/protobuf/src/google/protobuf/implicit_weak_message.h index 1915e8c..b894ab4 100644 --- a/libs/protobuf/src/google/protobuf/implicit_weak_message.h +++ b/libs/protobuf/src/google/protobuf/implicit_weak_message.h @@ -33,17 +33,17 @@ #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include // This file is logically internal-only and should only be used by protobuf // generated code. @@ -62,8 +62,6 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { : data_(nullptr) {} explicit ImplicitWeakMessage(Arena* arena) : MessageLite(arena), data_(new std::string) {} - ImplicitWeakMessage(const ImplicitWeakMessage&) = delete; - ImplicitWeakMessage& operator=(const ImplicitWeakMessage&) = delete; ~ImplicitWeakMessage() override { // data_ will be null in the default instance, but we can safely call delete @@ -117,6 +115,7 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { // the default instance can be constant-initialized. In the const methods, we // have to handle the possibility of data_ being null. std::string* data_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImplicitWeakMessage); }; struct ImplicitWeakMessageDefaultType; @@ -209,6 +208,6 @@ struct WeakRepeatedPtrField { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IMPLICIT_WEAK_MESSAGE_H__ diff --git a/libs/protobuf/src/google/protobuf/inlined_string_field.cc b/libs/protobuf/src/google/protobuf/inlined_string_field.cc index 34b73d2..0c3e476 100644 --- a/libs/protobuf/src/google/protobuf/inlined_string_field.cc +++ b/libs/protobuf/src/google/protobuf/inlined_string_field.cc @@ -28,18 +28,16 @@ // (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/inlined_string_field.h" - -#include "google/protobuf/arena.h" -#include "absl/strings/internal/resize_uninitialized.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { diff --git a/libs/protobuf/src/google/protobuf/inlined_string_field.h b/libs/protobuf/src/google/protobuf/inlined_string_field.h index fe52a4d..79e37d4 100644 --- a/libs/protobuf/src/google/protobuf/inlined_string_field.h +++ b/libs/protobuf/src/google/protobuf/inlined_string_field.h @@ -34,15 +34,15 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/port.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/message_lite.h" +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -130,7 +130,7 @@ class PROTOBUF_EXPORT InlinedStringField { // `donated == ((donating_states & ~mask) != 0)` // // This method never changes the `donating_states`. - void Set(absl::string_view value, Arena* arena, bool donated, + void Set(ConstStringParam value, Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg); // Rvalue Set. If this field is donated, this method will undonate this field @@ -149,7 +149,7 @@ class PROTOBUF_EXPORT InlinedStringField { ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg); - void SetBytes(absl::string_view value, Arena* arena, bool donated, + void SetBytes(ConstStringParam value, Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg); void SetBytes(std::string&& value, Arena* arena, bool donated, @@ -167,7 +167,7 @@ class PROTOBUF_EXPORT InlinedStringField { ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg); - PROTOBUF_NDEBUG_INLINE void SetNoArena(absl::string_view value); + PROTOBUF_NDEBUG_INLINE void SetNoArena(StringPiece value); PROTOBUF_NDEBUG_INLINE void SetNoArena(std::string&& value); // Basic accessors. @@ -228,7 +228,7 @@ class PROTOBUF_EXPORT InlinedStringField { return Release(); } - void Set(const std::string*, absl::string_view value, Arena* arena, + void Set(const std::string*, ConstStringParam value, Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg) { Set(value, arena, donated, donating_states, mask, msg); @@ -261,7 +261,7 @@ class PROTOBUF_EXPORT InlinedStringField { Set(const_string_ref, arena, donated, donating_states, mask, msg); } - void SetBytes(const std::string*, absl::string_view value, Arena* arena, + void SetBytes(const std::string*, ConstStringParam value, Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg) { Set(value, arena, donated, donating_states, mask, msg); @@ -297,7 +297,7 @@ class PROTOBUF_EXPORT InlinedStringField { msg); } - void SetNoArena(const std::string*, absl::string_view value) { + void SetNoArena(const std::string*, StringPiece value) { SetNoArena(value); } void SetNoArena(const std::string*, std::string&& value) { @@ -413,7 +413,7 @@ inline void InlinedStringField::DestroyNoArena(const std::string*) { this->~InlinedStringField(); } -inline void InlinedStringField::SetNoArena(absl::string_view value) { +inline void InlinedStringField::SetNoArena(StringPiece value) { get_mutable()->assign(value.data(), value.length()); } @@ -427,7 +427,7 @@ inline PROTOBUF_NDEBUG_INLINE void InlinedStringField::InternalSwap( MessageLite* lhs_msg, // InlinedStringField* rhs, Arena* rhs_arena, bool rhs_arena_dtor_registered, MessageLite* rhs_msg) { -#ifdef GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE +#if GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE lhs->get_mutable()->swap(*rhs->get_mutable()); if (!lhs_arena_dtor_registered && rhs_arena_dtor_registered) { lhs_msg->OnDemandRegisterArenaDtor(lhs_arena); @@ -445,7 +445,7 @@ inline PROTOBUF_NDEBUG_INLINE void InlinedStringField::InternalSwap( #endif } -inline void InlinedStringField::Set(absl::string_view value, Arena* arena, +inline void InlinedStringField::Set(ConstStringParam value, Arena* arena, bool donated, uint32_t* /*donating_states*/, uint32_t /*mask*/, MessageLite* /*msg*/) { (void)arena; @@ -456,17 +456,17 @@ inline void InlinedStringField::Set(absl::string_view value, Arena* arena, inline void InlinedStringField::Set(const char* str, ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg) { - Set(absl::string_view(str), arena, donated, donating_states, mask, msg); + Set(ConstStringParam(str), arena, donated, donating_states, mask, msg); } inline void InlinedStringField::Set(const char* str, size_t size, ::google::protobuf::Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg) { - Set(absl::string_view{str, size}, arena, donated, donating_states, mask, msg); + Set(ConstStringParam{str, size}, arena, donated, donating_states, mask, msg); } -inline void InlinedStringField::SetBytes(absl::string_view value, Arena* arena, +inline void InlinedStringField::SetBytes(ConstStringParam value, Arena* arena, bool donated, uint32_t* donating_states, uint32_t mask, MessageLite* msg) { @@ -527,6 +527,6 @@ inline std::string* InlinedStringField::MutableNoCopy(std::nullptr_t) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__ diff --git a/libs/protobuf/src/google/protobuf/inlined_string_field_unittest.cc b/libs/protobuf/src/google/protobuf/inlined_string_field_unittest.cc index 53552df..9efe6e9 100644 --- a/libs/protobuf/src/google/protobuf/inlined_string_field_unittest.cc +++ b/libs/protobuf/src/google/protobuf/inlined_string_field_unittest.cc @@ -28,7 +28,7 @@ // (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/inlined_string_field.h" +#include #include #include @@ -38,14 +38,13 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/arenastring.h" +#include +#include +#include +#include +#include #include -#include "absl/strings/string_view.h" -#include "google/protobuf/message.h" +#include namespace google { diff --git a/libs/protobuf/src/google/protobuf/io/BUILD.bazel b/libs/protobuf/src/google/protobuf/io/BUILD.bazel deleted file mode 100644 index cce6296..0000000 --- a/libs/protobuf/src/google/protobuf/io/BUILD.bazel +++ /dev/null @@ -1,185 +0,0 @@ -# Protobuf IO library. - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS") - -package( - default_visibility = ["//visibility:public"], -) - -cc_library( - name = "io", - srcs = [ - "coded_stream.cc", - "zero_copy_stream.cc", - "zero_copy_stream_impl.cc", - "zero_copy_stream_impl_lite.cc", - ], - hdrs = [ - "coded_stream.h", - "zero_copy_stream.h", - "zero_copy_stream_impl.h", - "zero_copy_stream_impl_lite.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/io", - deps = [ - ":io_win32", - "//src/google/protobuf:arena", - "//src/google/protobuf/stubs:lite", - "@com_google_absl//absl/strings:internal", - ], -) - -cc_library( - name = "zero_copy_sink", - srcs = ["zero_copy_sink.cc"], - hdrs = ["zero_copy_sink.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - ":io", - "//src/google/protobuf/stubs", - ], -) - -cc_test( - name = "zero_copy_sink_test", - srcs = ["zero_copy_sink_test.cc"], - copts = COPTS, - deps = [ - ":zero_copy_sink", - "//src/google/protobuf/stubs", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "printer", - srcs = ["printer.cc"], - hdrs = ["printer.h"], - copts = COPTS, - include_prefix = "google/protobuf/io", - deps = [ - ":zero_copy_sink", - "//src/google/protobuf/stubs", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/cleanup", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/functional:function_ref", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:span", - "@com_google_absl//absl/types:variant", - ], -) - -cc_library( - name = "tokenizer", - srcs = [ - "strtod.cc", - "tokenizer.cc", - ], - hdrs = [ - "strtod.h", - "tokenizer.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/io", - deps = [ - ":io", - "//src/google/protobuf/stubs", - ], -) - -cc_library( - name = "gzip_stream", - srcs = ["gzip_stream.cc"], - hdrs = ["gzip_stream.h"], - copts = COPTS, - include_prefix = "google/protobuf/io", - deps = [ - ":io", - "//src/google/protobuf/stubs", - ] + select({ - "//build_defs:config_msvc": [], - "//conditions:default": ["@zlib//:zlib"], - }), -) - -cc_library( - name = "io_win32", - srcs = ["io_win32.cc"], - hdrs = ["io_win32.h"], - copts = COPTS, - include_prefix = "google/protobuf/io", - visibility = ["//pkg:__pkg__"], - deps = [ - "//src/google/protobuf:arena", - "//src/google/protobuf/stubs:lite", - ], -) - -cc_test( - name = "io_test", - srcs = [ - "coded_stream_unittest.cc", - "printer_death_test.cc", - "printer_unittest.cc", - "tokenizer_unittest.cc", - "zero_copy_stream_unittest.cc", - ], - copts = COPTS, - data = [ - "//src/google/protobuf:testdata", - ], - deps = [ - ":gzip_stream", - ":io", - "//:protobuf", - "//src/google/protobuf:test_util2", - "//src/google/protobuf/testing", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "win32_test", - srcs = ["io_win32_unittest.cc"], - tags = [ - "manual", - "windows", - ], - deps = [ - "//:protobuf_lite", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/io/coded_stream.cc b/libs/protobuf/src/google/protobuf/io/coded_stream.cc index b29fccf..487e1b8 100644 --- a/libs/protobuf/src/google/protobuf/io/coded_stream.cc +++ b/libs/protobuf/src/google/protobuf/io/coded_stream.cc @@ -38,7 +38,7 @@ // will not cross the end of the buffer, since we can avoid a lot // of branching in this case. -#include "google/protobuf/io/coded_stream.h" +#include #include @@ -46,18 +46,16 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/strings/internal/resize_uninitialized.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -262,7 +260,7 @@ bool CodedInputStream::ReadString(std::string* buffer, int size) { if (size < 0) return false; // security: size is often user-supplied if (BufferSize() >= size) { - absl::strings_internal::STLStringResizeUninitialized(buffer, size); + STLStringResizeUninitialized(buffer, size); std::pair z = as_string_data(buffer); if (z.second) { // Oddly enough, memcpy() requires its first two args to be non-NULL even @@ -966,4 +964,4 @@ uint8_t* CodedOutputStream::WriteVarint32ToArrayOutOfLineHelper(uint32_t value, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/io/coded_stream.h b/libs/protobuf/src/google/protobuf/io/coded_stream.h index d849a1b..c8fc994 100644 --- a/libs/protobuf/src/google/protobuf/io/coded_stream.h +++ b/libs/protobuf/src/google/protobuf/io/coded_stream.h @@ -109,6 +109,7 @@ #ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ + #include #include @@ -127,15 +128,15 @@ #endif -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/numeric/bits.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -177,8 +178,6 @@ class PROTOBUF_EXPORT CodedInputStream { // faster than using an ArrayInputStream. PushLimit(size) is implied by // this constructor. explicit CodedInputStream(const uint8_t* buffer, int size); - CodedInputStream(const CodedInputStream&) = delete; - CodedInputStream& operator=(const CodedInputStream&) = delete; // Destroy the CodedInputStream and position the underlying // ZeroCopyInputStream at the first unread byte. If an error occurred while @@ -519,6 +518,8 @@ class PROTOBUF_EXPORT CodedInputStream { MessageFactory* GetExtensionFactory(); private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream); + const uint8_t* buffer_; const uint8_t* buffer_end_; // pointer to the end of the buffer. ZeroCopyInputStream* input_; @@ -680,7 +681,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream { if (PROTOBUF_PREDICT_FALSE(end_ - ptr < size)) { return WriteRawFallback(data, size, ptr); } - std::memcpy(ptr, data, static_cast(size)); + std::memcpy(ptr, data, size); return ptr + size; } // Writes the buffer specified by data, size to the stream. Possibly by @@ -1060,8 +1061,6 @@ class PROTOBUF_EXPORT CodedOutputStream { template ::value>::type> CodedOutputStream(Stream* stream, bool eager_init); - CodedOutputStream(const CodedOutputStream&) = delete; - CodedOutputStream& operator=(const CodedOutputStream&) = delete; // Destroy the CodedOutputStream and position the underlying // ZeroCopyOutputStream immediately after the last byte written. @@ -1289,6 +1288,7 @@ class PROTOBUF_EXPORT CodedOutputStream { // REQUIRES: value >= 0x80, and that (value & 7f) has been written to *target. static uint8_t* WriteVarint32ToArrayOutOfLineHelper(uint32_t value, uint8_t* target); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); }; // inline methods ==================================================== @@ -1729,16 +1729,15 @@ inline size_t CodedOutputStream::VarintSize32(uint32_t value) { // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 // Use an explicit multiplication to implement the divide of // a number in the 1..31 range. - // - // Explicit OR 0x1 to avoid calling absl::bit_width(0), which is - // requires a branch to check for on many platforms. - uint32_t log2value = absl::bit_width(value | 0x1) - 1; + // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is + // undefined. + uint32_t log2value = Bits::Log2FloorNonZero(value | 0x1); return static_cast((log2value * 9 + 73) / 64); } inline size_t CodedOutputStream::VarintSize32PlusOne(uint32_t value) { // Same as above, but one more. - uint32_t log2value = absl::bit_width(value | 0x1) - 1; + uint32_t log2value = Bits::Log2FloorNonZero(value | 0x1); return static_cast((log2value * 9 + 73 + 64) / 64); } @@ -1746,16 +1745,15 @@ inline size_t CodedOutputStream::VarintSize64(uint64_t value) { // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 // Use an explicit multiplication to implement the divide of // a number in the 1..63 range. - // - // Explicit OR 0x1 to avoid calling absl::bit_width(0), which is - // requires a branch to check for on many platforms. - uint32_t log2value = absl::bit_width(value | 0x1) - 1; + // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is + // undefined. + uint32_t log2value = Bits::Log2FloorNonZero64(value | 0x1); return static_cast((log2value * 9 + 73) / 64); } inline size_t CodedOutputStream::VarintSize64PlusOne(uint64_t value) { // Same as above, but one more. - uint32_t log2value = absl::bit_width(value | 0x1) - 1; + uint32_t log2value = Bits::Log2FloorNonZero64(value | 0x1); return static_cast((log2value * 9 + 73 + 64) / 64); } @@ -1779,7 +1777,7 @@ inline void CodedOutputStream::WriteRawMaybeAliased(const void* data, inline uint8_t* CodedOutputStream::WriteRawToArray(const void* data, int size, uint8_t* target) { - memcpy(target, data, static_cast(size)); + memcpy(target, data, size); return target + size; } @@ -1796,6 +1794,6 @@ inline uint8_t* CodedOutputStream::WriteStringToArray(const std::string& str, #pragma runtime_checks("c", restore) #endif // _MSC_VER && !defined(__INTEL_COMPILER) -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/libs/protobuf/src/google/protobuf/io/coded_stream_unittest.cc b/libs/protobuf/src/google/protobuf/io/coded_stream_unittest.cc index ae55382..b32bf45 100644 --- a/libs/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +++ b/libs/protobuf/src/google/protobuf/io/coded_stream_unittest.cc @@ -34,7 +34,7 @@ // // This file contains tests and benchmarks. -#include "google/protobuf/io/coded_stream.h" +#include #include @@ -43,20 +43,17 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" +#include +#include +#include +#include +#include #include -#include "absl/base/casts.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/cord.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" - -#include "google/protobuf/testing/googletest.h" - +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include + namespace google { namespace protobuf { @@ -72,7 +69,7 @@ namespace { // run multiple times, once for each item in some input array. TEST_1D // tests all cases in a single input array. TEST_2D tests all // combinations of cases from two arrays. The arrays must be statically -// defined such that the ABSL_ARRAYSIZE() macro works on them. Example: +// defined such that the GOOGLE_ARRAYSIZE() macro works on them. Example: // // int kCases[] = {1, 2, 3, 4} // TEST_1D(MyFixture, MyTest, kCases) { @@ -95,7 +92,7 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (size_t i = 0; i < ABSL_ARRAYSIZE(CASES); i++) { \ + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \ SCOPED_TRACE(testing::Message() \ << #CASES " case #" << i << ": " << CASES[i]); \ DoSingleCase(CASES[i]); \ @@ -114,8 +111,8 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (size_t i = 0; i < ABSL_ARRAYSIZE(CASES1); i++) { \ - for (size_t j = 0; j < ABSL_ARRAYSIZE(CASES2); j++) { \ + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \ + for (size_t j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \ SCOPED_TRACE(testing::Message() \ << #CASES1 " case #" << i << ": " << CASES1[i] << ", " \ << #CASES2 " case #" << j << ": " << CASES2[j]); \ @@ -137,7 +134,7 @@ class CodedStreamTest : public testing::Test { static uint8_t buffer_[kBufferSize]; }; -uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize] = {}; +uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize]; // We test each operation over a variety of block sizes to insure that // we test cases where reads or writes cross buffer boundaries, cases @@ -728,7 +725,7 @@ TEST_1D(CodedStreamTest, ReadStringImpossiblyLarge, kBlockSizes) { TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) { // Same test as above, except directly use a buffer. This used to cause // crashes while the above did not. - uint8_t buffer[8] = {}; + uint8_t buffer[8]; CodedInputStream coded_input(buffer, 8); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); @@ -1319,7 +1316,7 @@ class ReallyBigInputStream : public ZeroCopyInputStream { int backup_amount_; private: - char buffer_[1024] = {}; + char buffer_[1024]; int64_t buffer_count_; }; @@ -1348,4 +1345,4 @@ TEST_F(CodedStreamTest, InputOver2G) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/io/gzip_stream.cc b/libs/protobuf/src/google/protobuf/io/gzip_stream.cc index d9d44a0..a5284b3 100644 --- a/libs/protobuf/src/google/protobuf/io/gzip_stream.cc +++ b/libs/protobuf/src/google/protobuf/io/gzip_stream.cc @@ -35,11 +35,11 @@ #if HAVE_ZLIB -#include "google/protobuf/io/gzip_stream.h" -#include "google/protobuf/port.h" +#include +#include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/io/gzip_stream.h b/libs/protobuf/src/google/protobuf/io/gzip_stream.h index eec111c..4cf71b6 100644 --- a/libs/protobuf/src/google/protobuf/io/gzip_stream.h +++ b/libs/protobuf/src/google/protobuf/io/gzip_stream.h @@ -43,13 +43,14 @@ #ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ #define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/port.h" + +#include +#include +#include #include "zlib.h" // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -74,9 +75,7 @@ class PROTOBUF_EXPORT GzipInputStream PROTOBUF_FUTURE_FINAL // buffer_size and format may be -1 for default of 64kB and GZIP format explicit GzipInputStream(ZeroCopyInputStream* sub_stream, Format format = AUTO, int buffer_size = -1); - GzipInputStream(const GzipInputStream&) = delete; - GzipInputStream& operator=(const GzipInputStream&) = delete; - ~GzipInputStream() override; + virtual ~GzipInputStream(); // Return last error message or NULL if no error. inline const char* ZlibErrorMessage() const { return zcontext_.msg; } @@ -103,6 +102,8 @@ class PROTOBUF_EXPORT GzipInputStream PROTOBUF_FUTURE_FINAL int Inflate(int flush); void DoNextOutput(const void** data, int* size); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipInputStream); }; class PROTOBUF_EXPORT GzipOutputStream PROTOBUF_FUTURE_FINAL @@ -141,10 +142,8 @@ class PROTOBUF_EXPORT GzipOutputStream PROTOBUF_FUTURE_FINAL // Create a GzipOutputStream with the given options. GzipOutputStream(ZeroCopyOutputStream* sub_stream, const Options& options); - GzipOutputStream(const GzipOutputStream&) = delete; - GzipOutputStream& operator=(const GzipOutputStream&) = delete; - ~GzipOutputStream() override; + virtual ~GzipOutputStream(); // Return last error message or NULL if no error. inline const char* ZlibErrorMessage() const { return zcontext_.msg; } @@ -193,12 +192,14 @@ class PROTOBUF_EXPORT GzipOutputStream PROTOBUF_FUTURE_FINAL // Takes zlib flush mode. // Returns zlib error code. int Deflate(int flush); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipOutputStream); }; } // namespace io } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ diff --git a/libs/protobuf/src/google/protobuf/io/io_win32.cc b/libs/protobuf/src/google/protobuf/io/io_win32.cc index 684c567..4e81908 100644 --- a/libs/protobuf/src/google/protobuf/io/io_win32.cc +++ b/libs/protobuf/src/google/protobuf/io/io_win32.cc @@ -49,7 +49,7 @@ // debug failing tests if that's caused by the long path support. #define SUPPORT_LONGPATHS -#include "google/protobuf/io/io_win32.h" +#include #include #include diff --git a/libs/protobuf/src/google/protobuf/io/io_win32.h b/libs/protobuf/src/google/protobuf/io/io_win32.h index 370bcaa..a72b4ea 100644 --- a/libs/protobuf/src/google/protobuf/io/io_win32.h +++ b/libs/protobuf/src/google/protobuf/io/io_win32.h @@ -52,10 +52,10 @@ #include #include -#include "google/protobuf/port.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include // Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the // following functions already, except for mkdir. @@ -134,7 +134,7 @@ PROTOBUF_EXPORT bool wcs_to_utf8(const wchar_t* input, std::string* out); #define STDOUT_FILENO 1 #endif -#include "google/protobuf/port_undef.inc" +#include #endif // defined(_WIN32) diff --git a/libs/protobuf/src/google/protobuf/io/io_win32_unittest.cc b/libs/protobuf/src/google/protobuf/io/io_win32_unittest.cc index d4e50b8..e8f378f 100644 --- a/libs/protobuf/src/google/protobuf/io/io_win32_unittest.cc +++ b/libs/protobuf/src/google/protobuf/io/io_win32_unittest.cc @@ -40,7 +40,7 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN -#include "google/protobuf/io/io_win32.h" +#include #include #include diff --git a/libs/protobuf/src/google/protobuf/io/printer.cc b/libs/protobuf/src/google/protobuf/io/printer.cc index acedbd4..47bd00b 100644 --- a/libs/protobuf/src/google/protobuf/io/printer.cc +++ b/libs/protobuf/src/google/protobuf/io/printer.cc @@ -32,230 +32,195 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/io/printer.h" +#include -#include +#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/container/flat_hash_map.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/match.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/strings/strip.h" -#include "absl/types/optional.h" -#include "absl/types/span.h" -#include "absl/types/variant.h" +#include +#include +#include namespace google { namespace protobuf { namespace io { -namespace { -// Returns the number of spaces of the first non empty line. -size_t RawStringIndentLen(absl::string_view format) { - // We are processing a call that looks like - // - // p->Emit(R"cc( - // class Foo { - // int x, y, z; - // }; - // )cc"); - // - // or - // - // p->Emit(R"cc( - // - // class Foo { - // int x, y, z; - // }; - // )cc"); - // - // To compute the indent, we need to discard all leading newlines, then - // count all spaces until we reach a non-space; this run of spaces is - // stripped off at the start of each line. - size_t len = 0; - while (absl::ConsumePrefix(&format, "\n")) { - } - while (absl::ConsumePrefix(&format, " ")) { - ++len; - } +Printer::Printer(ZeroCopyOutputStream* output, char variable_delimiter) + : variable_delimiter_(variable_delimiter), + output_(output), + buffer_(NULL), + buffer_size_(0), + offset_(0), + at_start_of_line_(true), + failed_(false), + annotation_collector_(NULL) {} - return len; -} +Printer::Printer(ZeroCopyOutputStream* output, char variable_delimiter, + AnnotationCollector* annotation_collector) + : variable_delimiter_(variable_delimiter), + output_(output), + buffer_(NULL), + buffer_size_(0), + offset_(0), + at_start_of_line_(true), + failed_(false), + annotation_collector_(annotation_collector) {} -// Returns the amount of additional indenting past `raw_string_indent_len`. -size_t ConsumeIndentForLine(size_t raw_string_indent_len, - absl::string_view& format) { - size_t total_indent = 0; - while (absl::ConsumePrefix(&format, " ")) { - ++total_indent; - } - if (total_indent < raw_string_indent_len) { - total_indent = 0; - } else { - total_indent -= raw_string_indent_len; - } - return total_indent; -} - -template -absl::optional LookupInFrameStack( - absl::string_view var, - absl::Span(absl::string_view)>> frames) { - for (size_t i = frames.size(); i >= 1; --i) { - auto val = frames[i - 1](var); - if (val.has_value()) { - return val; - } - } - return absl::nullopt; -} -} // namespace - -constexpr absl::string_view Printer::kProtocCodegenTrace; - -Printer::Printer(ZeroCopyOutputStream* output, Options options) - : sink_(output), options_(options) { - if (!options_.enable_codegen_trace.has_value()) { - // Trace-by-default is threaded through via an env var, rather than a - // global, so that child processes can pick it up as well. The flag - // --enable_codegen_trace setenv()'s this in protoc's startup code. - static const bool kEnableCodegenTrace = - ::getenv(kProtocCodegenTrace.data()) != nullptr; - options_.enable_codegen_trace = kEnableCodegenTrace; +Printer::~Printer() { + // Only BackUp() if we invoked Next() at least once, and we have never failed. + // Note that we always call `Backup`, i.e. we call BackUp(0) as some output + // streams have buffered output, and BackUp() serves as a flush event in such + // implementations. + if (buffer_ != nullptr && !failed_) { + output_->BackUp(buffer_size_); } } -absl::string_view Printer::LookupVar(absl::string_view var) { - LookupResult result = LookupInFrameStack(var, absl::MakeSpan(var_lookups_)); - GOOGLE_CHECK(result.has_value()) << "could not find " << var; - auto* view = absl::get_if(&*result); - GOOGLE_CHECK(view != nullptr) << "could not find " << var - << "; found callback instead"; - - return *view; -} - -bool Printer::Validate(bool cond, Printer::PrintOptions opts, - absl::FunctionRef message) { - if (!cond) { - if (opts.checks_are_debug_only) { - GOOGLE_LOG(DFATAL) << message(); - } else { - GOOGLE_LOG(FATAL) << message(); - } +bool Printer::GetSubstitutionRange(const char* varname, + std::pair* range) { + std::map >::const_iterator iter = + substitutions_.find(varname); + if (iter == substitutions_.end()) { + GOOGLE_LOG(DFATAL) << " Undefined variable in annotation: " << varname; + return false; } - return cond; -} - -bool Printer::Validate(bool cond, Printer::PrintOptions opts, - absl::string_view message) { - return Validate(cond, opts, [=] { return std::string(message); }); -} - -// This function is outlined to isolate the use of -// GOOGLE_CHECK into the .cc file. -void Printer::Outdent() { - PrintOptions opts; - opts.checks_are_debug_only = true; - if (!Validate(indent_ >= options_.spaces_per_indent, opts, - "Outdent() without matching Indent()")) { - return; + if (iter->second.first > iter->second.second) { + GOOGLE_LOG(DFATAL) << " Variable used for annotation used multiple times: " + << varname; + return false; } - indent_ -= options_.spaces_per_indent; + *range = iter->second; + return true; } -void Printer::Emit( - std::initializer_list< - VarDefinition> - vars, - absl::string_view format, SourceLocation loc) { - PrintOptions opts; - opts.strip_raw_string_indentation = true; - opts.loc = loc; - - auto defs = WithDefs(vars); - - PrintImpl(format, {}, opts); -} - -absl::optional> Printer::GetSubstitutionRange( - absl::string_view varname, PrintOptions opts) { - auto it = substitutions_.find(std::string(varname)); - if (!Validate(it != substitutions_.end(), opts, [varname] { - return absl::StrCat("undefined variable in annotation: ", varname); - })) { - return absl::nullopt; - } - - std::pair range = it->second; - if (!Validate(range.first <= range.second, opts, [varname] { - return absl::StrCat( - "variable used for annotation used multiple times: ", varname); - })) { - return absl::nullopt; - } - - return range; -} - -void Printer::Annotate(absl::string_view begin_varname, - absl::string_view end_varname, - absl::string_view file_path, +void Printer::Annotate(const char* begin_varname, const char* end_varname, + const std::string& file_path, const std::vector& path) { - if (options_.annotation_collector == nullptr) { + if (annotation_collector_ == NULL) { + // Can't generate signatures with this Printer. return; } - - PrintOptions opts; - opts.checks_are_debug_only = true; - auto begin = GetSubstitutionRange(begin_varname, opts); - auto end = GetSubstitutionRange(end_varname, opts); - if (!begin.has_value() || !end.has_value()) { + std::pair begin, end; + if (!GetSubstitutionRange(begin_varname, &begin) || + !GetSubstitutionRange(end_varname, &end)) { return; } - if (begin->first > end->second) { - GOOGLE_LOG(DFATAL) << "annotation has negative length from " << begin_varname + if (begin.first > end.second) { + GOOGLE_LOG(DFATAL) << " Annotation has negative length from " << begin_varname << " to " << end_varname; - return; + } else { + annotation_collector_->AddAnnotation(begin.first, end.second, file_path, + path); } - options_.annotation_collector->AddAnnotation(begin->first, end->second, - std::string(file_path), path); } -void Printer::WriteRaw(const char* data, size_t size) { - if (failed_ || size == 0) { +void Printer::Print(const std::map& variables, + const char* text) { + 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') { + // 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'. + WriteRaw(text + pos, i - pos + 1); + pos = i + 1; + + // 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. + + // Write what we have so far. + WriteRaw(text + pos, i - pos); + pos = i + 1; + + // Find closing delimiter. + const char* end = strchr(text + pos, variable_delimiter_); + if (end == NULL) { + GOOGLE_LOG(DFATAL) << " Unclosed variable name."; + end = text + pos; + } + int endpos = end - text; + + std::string varname(text + pos, endpos - pos); + if (varname.empty()) { + // Two delimiters in a row reduce to a literal delimiter character. + WriteRaw(&variable_delimiter_, 1); + } else { + // Replace with the variable's value. + std::map::const_iterator iter = + variables.find(varname); + if (iter == variables.end()) { + GOOGLE_LOG(DFATAL) << " Undefined variable: " << varname; + } else { + if (at_start_of_line_ && iter->second.empty()) { + line_start_variables_.push_back(varname); + } + WriteRaw(iter->second.data(), iter->second.size()); + std::pair >::iterator, + bool> + 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 + // annotation. + inserted.first->second = std::make_pair(1, 0); + } + } + } + + // Advance past this variable. + i = endpos; + pos = endpos + 1; + } + } + + // Write the rest. + WriteRaw(text + pos, size - pos); +} + +void Printer::Indent() { indent_ += " "; } + +void Printer::Outdent() { + if (indent_.empty()) { + GOOGLE_LOG(DFATAL) << " Outdent() without matching Indent()."; return; } - if (at_start_of_line_ && data[0] != '\n') { + indent_.resize(indent_.size() - 2); +} + +void Printer::PrintRaw(const std::string& data) { + WriteRaw(data.data(), data.size()); +} + +void Printer::PrintRaw(const char* data) { + if (failed_) return; + WriteRaw(data, strlen(data)); +} + +void Printer::WriteRaw(const char* data, int size) { + if (failed_) return; + if (size == 0) return; + + if (at_start_of_line_ && (size > 0) && (data[0] != '\n')) { // Insert an indent. at_start_of_line_ = false; - for (size_t i = 0; i < indent_; ++i) { - sink_.Write(" "); - } - - if (failed_) { - return; - } - + CopyToBuffer(indent_.data(), indent_.size()); + if (failed_) return; // Fix up empty variables (e.g., "{") that should be annotated as // coming after the indent. - for (const std::string& var : line_start_variables_) { - substitutions_[var].first += indent_; - substitutions_[var].second += indent_; + for (std::vector::iterator i = line_start_variables_.begin(); + i != line_start_variables_.end(); ++i) { + substitutions_[*i].first += indent_.size(); + substitutions_[*i].second += indent_.size(); } } @@ -264,397 +229,175 @@ void Printer::WriteRaw(const char* data, size_t size) { // the current line. line_start_variables_.clear(); - sink_.Append(data, size); - failed_ |= sink_.failed(); + CopyToBuffer(data, size); } -void Printer::IndentIfAtStart() { - if (!at_start_of_line_) { - return; - } - - for (size_t i = 0; i < indent_; ++i) { - sink_.Write(" "); - } - at_start_of_line_ = false; -} - -void Printer::PrintCodegenTrace(absl::optional loc) { - if (!options_.enable_codegen_trace.value_or(false) || !loc.has_value()) { - return; - } - - if (!at_start_of_line_) { - at_start_of_line_ = true; - line_start_variables_.clear(); - sink_.Write("\n"); - } - - PrintRaw(absl::StrFormat("%s @%s:%d\n", options_.comment_start, - loc->file_name(), loc->line())); - at_start_of_line_ = true; -} - -bool Printer::ValidateIndexLookupInBounds(size_t index, - size_t current_arg_index, - size_t args_len, PrintOptions opts) { - if (!Validate(index < args_len, opts, [this, index] { - return absl::StrFormat("annotation %c{%d%c is out of bounds", - options_.variable_delimiter, index + 1, - options_.variable_delimiter); - })) { - return false; - } - if (!Validate( - index <= current_arg_index, opts, [this, index, current_arg_index] { - return absl::StrFormat( - "annotation arg must be in correct order as given; expected " - "%c{%d%c but got %c{%d%c", - options_.variable_delimiter, current_arg_index + 1, - options_.variable_delimiter, options_.variable_delimiter, - index + 1, options_.variable_delimiter); - })) { - return false; - } +bool Printer::Next() { + do { + void* void_buffer; + if (!output_->Next(&void_buffer, &buffer_size_)) { + failed_ = true; + return false; + } + buffer_ = reinterpret_cast(void_buffer); + } while (buffer_size_ == 0); return true; } -void Printer::PrintImpl(absl::string_view format, - absl::Span args, PrintOptions opts) { - // Inside of this function, we set indentation as we print new lines from the - // format string. No matter how we exit this function, we should fix up the - // indent to what it was before we entered; a cleanup makes it easy to avoid - // this mistake. - size_t original_indent = indent_; - auto unindent = - absl::MakeCleanup([this, original_indent] { indent_ = original_indent; }); +void Printer::CopyToBuffer(const char* data, int size) { + if (failed_) return; + if (size == 0) return; - absl::string_view original = format; - - line_start_variables_.clear(); - - if (opts.use_substitution_map) { - substitutions_.clear(); + while (size > buffer_size_) { + // Data exceeds space in the buffer. Copy what we can and request a + // new buffer. + if (buffer_size_ > 0) { + memcpy(buffer_, data, buffer_size_); + offset_ += buffer_size_; + data += buffer_size_; + size -= buffer_size_; + } + void* void_buffer; + failed_ = !output_->Next(&void_buffer, &buffer_size_); + if (failed_) return; + buffer_ = reinterpret_cast(void_buffer); } - size_t raw_string_indent_len = - opts.strip_raw_string_indentation ? RawStringIndentLen(format) : 0; - - if (opts.strip_raw_string_indentation) { - // We only want to remove a single newline from the input string to allow - // extra newlines at the start to go into the generated code. - absl::ConsumePrefix(&format, "\n"); - while (absl::ConsumePrefix(&format, " ")) { - } - } - - PrintCodegenTrace(opts.loc); - - size_t arg_index = 0; - std::vector annot_stack; - std::vector> annot_records; - while (!format.empty()) { - // Skip to the next special character. We do this so that we can delay - // printing "normal" text until we know what kind of variable substitution - // we're doing, since that may require trimming whitespace. - size_t next_special = 0; - for (; next_special < format.size(); ++next_special) { - if (format[next_special] == options_.variable_delimiter || - format[next_special] == '\n') { - break; - } - } - - absl::string_view next_chunk = format.substr(0, next_special); - format = format.substr(next_special); - - if (format.empty()) { - PrintRaw(next_chunk); - break; - } - - char c = format.front(); - format = format.substr(1); - if (c == '\n') { - PrintRaw(next_chunk); - at_start_of_line_ = true; - line_start_variables_.clear(); - sink_.Write("\n"); - indent_ = - original_indent + ConsumeIndentForLine(raw_string_indent_len, format); - continue; - } else if (c != options_.variable_delimiter) { - PrintRaw(next_chunk); - continue; - } - - size_t end = format.find(options_.variable_delimiter); - if (!Validate(end != absl::string_view::npos, opts, [format] { - return absl::StrCat("unclosed variable name: \"", - absl::CHexEscape(format), "\""); - })) { - PrintRaw(next_chunk); - WriteRaw(&options_.variable_delimiter, 1); - PrintRaw(format); - break; - } - - absl::string_view match = format.substr(0, end); - absl::string_view var = match; - format = format.substr(end + 1); - - if (var.empty()) { - // `$$` is an escape for just `$`. - PrintRaw(next_chunk); - WriteRaw(&options_.variable_delimiter, 1); - continue; - } - - if (opts.use_curly_brace_substitutions && absl::ConsumePrefix(&var, "{")) { - PrintRaw(next_chunk); - - if (!Validate(var.size() == 1u, opts, "expected single-digit variable")) { - continue; - } - - if (!Validate(absl::ascii_isdigit(var[0]), opts, - "expected digit after {")) { - continue; - } - - size_t idx = var[0] - '1'; - if (!ValidateIndexLookupInBounds(idx, arg_index, args.size(), opts)) { - continue; - } - - if (idx == arg_index) { - ++arg_index; - } - - IndentIfAtStart(); - annot_stack.push_back({{sink_.bytes_written(), 0}, args[idx]}); - continue; - } else if (opts.use_curly_brace_substitutions && - absl::ConsumePrefix(&var, "}")) { - PrintRaw(next_chunk); - - // The rest of var is actually ignored, and this is apparently - // public API now. Oops? - if (!Validate(!annot_stack.empty(), opts, - "unexpected end of annotation")) { - continue; - } - - annot_stack.back().first.second = sink_.bytes_written(); - if (options_.annotation_collector != nullptr) { - options_.annotation_collector->AddAnnotationNew(annot_stack.back()); - } - IndentIfAtStart(); - annot_stack.pop_back(); - continue; - } - - absl::string_view prefix, suffix; - if (opts.strip_spaces_around_vars) { - var = absl::StripLeadingAsciiWhitespace(var); - prefix = match.substr(0, match.size() - var.size()); - var = absl::StripTrailingAsciiWhitespace(var); - suffix = match.substr(prefix.size() + var.size()); - } - - if (!Validate(!var.empty(), opts, "unexpected empty variable")) { - PrintRaw(next_chunk); - continue; - } - - LookupResult sub; - absl::optional same_name_record; - if (opts.allow_digit_substitions && absl::ascii_isdigit(var[0])) { - PrintRaw(next_chunk); - - if (!Validate(var.size() == 1u, opts, "expected single-digit variable")) { - continue; - } - - size_t idx = var[0] - '1'; - if (!ValidateIndexLookupInBounds(idx, arg_index, args.size(), opts)) { - continue; - } - if (idx == arg_index) { - ++arg_index; - } - sub = args[idx]; - } else if (opts.use_annotation_frames && - (var == "_start" || var == "_end")) { - bool is_start = var == "_start"; - - size_t next_delim = format.find('$'); - if (!Validate(next_delim != absl::string_view::npos, opts, - "$_start$ must be followed by a name and another $")) { - PrintRaw(next_chunk); - continue; - } - - auto var = format.substr(0, next_delim); - format = format.substr(next_delim + 1); - - if (is_start) { - PrintRaw(next_chunk); - IndentIfAtStart(); - annot_records.push_back({var, sink_.bytes_written()}); - // Skip all whitespace immediately after a _start. - while (!format.empty() && absl::ascii_isspace(format.front())) { - format = format.substr(1); - } - } else { - // Skip all whitespace immediately *before* an _end. - while (!next_chunk.empty() && absl::ascii_isspace(next_chunk.back())) { - next_chunk = next_chunk.substr(0, next_chunk.size() - 1); - } - PrintRaw(next_chunk); - - // If a line consisted *only* of an _end, this will likely result in - // a blank line if we do not zap the newline after it, and any - // indentation beyond that. - if (at_start_of_line_) { - absl::ConsumePrefix(&format, "\n"); - indent_ = original_indent + - ConsumeIndentForLine(raw_string_indent_len, format); - } - - auto record_var = annot_records.back(); - annot_records.pop_back(); - - if (!Validate(record_var.first == var, opts, [record_var, var] { - return absl::StrFormat( - "_start and _end variables must match, but got %s and %s, " - "respectively", - record_var.first, var); - })) { - continue; - } - - absl::optional record = - LookupInFrameStack(var, absl::MakeSpan(annotation_lookups_)); - - if (!Validate(record.has_value(), opts, [var] { - return absl::StrCat("undefined variable: \"", - absl::CHexEscape(var), "\""); - })) { - continue; - } - - if (options_.annotation_collector != nullptr) { - options_.annotation_collector->AddAnnotation( - record_var.second, sink_.bytes_written(), record->file_path, - record->path); - } - } - - continue; - } else { - PrintRaw(next_chunk); - sub = LookupInFrameStack(var, absl::MakeSpan(var_lookups_)); - - if (opts.use_annotation_frames) { - same_name_record = - LookupInFrameStack(var, absl::MakeSpan(annotation_lookups_)); - } - } - - // By returning here in case of empty we also skip possible spaces inside - // the $...$, i.e. "void$ dllexpor$ f();" -> "void f();" in the empty case. - if (!Validate(sub.has_value(), opts, [var] { - return absl::StrCat("undefined variable: \"", absl::CHexEscape(var), - "\""); - })) { - continue; - } - - size_t range_start = sink_.bytes_written(); - size_t range_end = sink_.bytes_written(); - - if (auto* str = absl::get_if(&*sub)) { - if (at_start_of_line_ && str->empty()) { - line_start_variables_.emplace_back(var); - } - - if (!str->empty()) { - // If `sub` is empty, we do not print the spaces around it. - PrintRaw(prefix); - PrintRaw(*str); - range_end = sink_.bytes_written(); - range_start = range_end - str->size(); - PrintRaw(suffix); - } - } else { - auto* fnc = absl::get_if>(&*sub); - GOOGLE_CHECK(fnc != nullptr); - - Validate( - prefix.empty() && suffix.empty(), opts, - "substitution that resolves to callback cannot contain whitespace"); - - range_start = sink_.bytes_written(); - (*fnc)(); - range_end = sink_.bytes_written(); - - // If we just evaluated a closure, and we are at the start of a line, that - // means it finished with a newline. If a newline follows immediately - // after, we drop it. This helps callback formatting "work as expected" - // with respect to forms like - // - // class Foo { - // $methods$; - // }; - // - // Without this line, this would turn into something like - // - // class Foo { - // void Bar() {} - // - // }; - // - // in many cases. We *also* do this if a ; or , follows the substitution, - // because this helps clang-format keep its head on in many cases. - // Users that need to keep the semi can write $foo$/**/; - if (!absl::ConsumePrefix(&format, ";")) { - absl::ConsumePrefix(&format, ","); - } - absl::ConsumePrefix(&format, "\n"); - indent_ = - original_indent + ConsumeIndentForLine(raw_string_indent_len, format); - } - - if (same_name_record.has_value() && - options_.annotation_collector != nullptr) { - options_.annotation_collector->AddAnnotation(range_start, range_end, - same_name_record->file_path, - same_name_record->path); - } - - if (opts.use_substitution_map) { - auto insertion = substitutions_.emplace( - std::string(var), std::make_pair(range_start, range_end)); - - if (!insertion.second) { - // This variable was used multiple times. - // Make its span have negative length so - // we can detect it if it gets used in an - // annotation. - insertion.first->second = {1, 0}; - } - } - } - - Validate(arg_index == args.size(), opts, - [original] { return absl::StrCat("unused args: ", original); }); - Validate(annot_stack.empty(), opts, [this, original] { - return absl::StrFormat( - "annotation range was not closed; expected %c}%c: %s", - options_.variable_delimiter, options_.variable_delimiter, original); - }); + // Buffer is big enough to receive the data; copy it. + memcpy(buffer_, data, size); + buffer_ += size; + buffer_size_ -= size; + offset_ += size; } + +void Printer::IndentIfAtStart() { + if (at_start_of_line_) { + CopyToBuffer(indent_.data(), indent_.size()); + at_start_of_line_ = false; + } +} + +void Printer::FormatInternal(const std::vector& args, + const std::map& vars, + const char* format) { + auto save = format; + int arg_index = 0; + std::vector annotations; + while (*format) { + char c = *format++; + switch (c) { + case '$': + format = WriteVariable(args, vars, format, &arg_index, &annotations); + continue; + case '\n': + at_start_of_line_ = true; + line_start_variables_.clear(); + break; + default: + IndentIfAtStart(); + break; + } + push_back(c); + } + if (arg_index != static_cast(args.size())) { + GOOGLE_LOG(FATAL) << " Unused arguments. " << save; + } + if (!annotations.empty()) { + GOOGLE_LOG(FATAL) << " Annotation range is not-closed, expect $}$. " << save; + } +} + +const char* Printer::WriteVariable( + const std::vector& args, + const std::map& vars, const char* format, + int* arg_index, std::vector* annotations) { + auto start = format; + auto end = strchr(format, '$'); + if (!end) { + GOOGLE_LOG(FATAL) << " Unclosed variable name."; + } + format = end + 1; + if (end == start) { + // "$$" is an escape for just '$' + IndentIfAtStart(); + push_back('$'); + return format; + } + if (*start == '{') { + GOOGLE_CHECK(std::isdigit(start[1])); + GOOGLE_CHECK_EQ(end - start, 2); + int idx = start[1] - '1'; + if (idx < 0 || static_cast(idx) >= args.size()) { + GOOGLE_LOG(FATAL) << "Annotation ${" << idx + 1 << "$ is out of bounds."; + } + if (idx > *arg_index) { + GOOGLE_LOG(FATAL) << "Annotation arg must be in correct order as given. Expected" + << " ${" << (*arg_index) + 1 << "$ got ${" << idx + 1 << "$."; + } else if (idx == *arg_index) { + (*arg_index)++; + } + IndentIfAtStart(); + annotations->push_back({{offset_, 0}, args[idx]}); + return format; + } else if (*start == '}') { + GOOGLE_CHECK(annotations); + if (annotations->empty()) { + GOOGLE_LOG(FATAL) << "Unexpected end of annotation found."; + } + auto& a = annotations->back(); + a.first.second = offset_; + if (annotation_collector_) annotation_collector_->AddAnnotationNew(a); + annotations->pop_back(); + return format; + } + auto start_var = start; + while (start_var < end && *start_var == ' ') start_var++; + if (start_var == end) { + GOOGLE_LOG(FATAL) << " Empty variable."; + } + auto end_var = end; + while (start_var < end_var && *(end_var - 1) == ' ') end_var--; + std::string var_name{ + start_var, static_cast(end_var - start_var)}; + std::string sub; + if (std::isdigit(var_name[0])) { + GOOGLE_CHECK_EQ(var_name.size(), 1U); // No need for multi-digits + int idx = var_name[0] - '1'; // Start counting at 1 + GOOGLE_CHECK_GE(idx, 0); + if (static_cast(idx) >= args.size()) { + GOOGLE_LOG(FATAL) << "Argument $" << idx + 1 << "$ is out of bounds."; + } + if (idx > *arg_index) { + GOOGLE_LOG(FATAL) << "Arguments must be used in same order as given. Expected $" + << (*arg_index) + 1 << "$ got $" << idx + 1 << "$."; + } else if (idx == *arg_index) { + (*arg_index)++; + } + sub = args[idx]; + } else { + auto it = vars.find(var_name); + if (it == vars.end()) { + GOOGLE_LOG(FATAL) << " Unknown variable: " << var_name << "."; + } + sub = it->second; + } + + // By returning here in case of empty we also skip possible spaces inside + // the $...$, i.e. "void$ dllexpor$ f();" -> "void f();" in the empty case. + if (sub.empty()) return format; + + // We're going to write something non-empty so we need a possible indent. + IndentIfAtStart(); + + // Write the possible spaces in front. + CopyToBuffer(start, start_var - start); + // Write a non-empty substituted variable. + CopyToBuffer(sub.c_str(), sub.size()); + // Finish off with writing possible trailing spaces. + CopyToBuffer(end_var, end - end_var); + return format; +} + } // namespace io } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/io/printer.h b/libs/protobuf/src/google/protobuf/io/printer.h index 450e90f..92a4321 100644 --- a/libs/protobuf/src/google/protobuf/io/printer.h +++ b/libs/protobuf/src/google/protobuf/io/printer.h @@ -37,41 +37,27 @@ #ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__ #define GOOGLE_PROTOBUF_IO_PRINTER_H__ -#include -#include -#include + #include #include -#include -#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/cleanup/cleanup.h" -#include "absl/container/flat_hash_map.h" -#include "absl/functional/function_ref.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/variant.h" -#include "google/protobuf/io/zero_copy_sink.h" - +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace io { + +class ZeroCopyOutputStream; // zero_copy_stream.h + // Records annotations about a Printer's output. class PROTOBUF_EXPORT AnnotationCollector { public: - // Annotation is a offset range and a payload pair. This payload's layout is - // specific to derived types of AnnotationCollector. - using Annotation = std::pair, std::string>; - - virtual ~AnnotationCollector() = default; + // Annotation is a offset range and a payload pair. + typedef std::pair, std::string> Annotation; // Records that the bytes in file_path beginning with begin_offset and ending // before end_offset are associated with the SourceCodeInfo-style path. @@ -81,29 +67,28 @@ class PROTOBUF_EXPORT AnnotationCollector { // TODO(gerbens) I don't see why we need virtuals here. Just a vector of // range, payload pairs stored in a context should suffice. - virtual void AddAnnotationNew(Annotation&) {} + virtual void AddAnnotationNew(Annotation& /* a */) {} + + virtual ~AnnotationCollector() {} }; -// Records annotations about a Printer's output to a Protobuf message, -// assuming that it has a repeated submessage field named `annotation` with -// fields matching -// -// message ??? { -// repeated int32 path = 1; -// optional string source_file = 2; -// optional int32 begin = 3; -// optional int32 end = 4; -// } +// Records annotations about a Printer's output to the given protocol buffer, +// assuming that the buffer has an ::Annotation message exposing path, +// source_file, begin and end fields. template class AnnotationProtoCollector : public AnnotationCollector { public: + // annotation_proto is the protocol buffer to which new Annotations should be + // added. It is not owned by the AnnotationProtoCollector. explicit AnnotationProtoCollector(AnnotationProto* annotation_proto) : annotation_proto_(annotation_proto) {} + // Override for AnnotationCollector::AddAnnotation. void AddAnnotation(size_t begin_offset, size_t end_offset, const std::string& file_path, const std::vector& path) override { - auto* annotation = annotation_proto_->add_annotation(); + typename AnnotationProto::Annotation* annotation = + annotation_proto_->add_annotation(); for (int i = 0; i < path.size(); ++i) { annotation->add_path(path[i]); } @@ -111,7 +96,7 @@ class AnnotationProtoCollector : public AnnotationCollector { annotation->set_begin(begin_offset); annotation->set_end(end_offset); } - + // Override for AnnotationCollector::AddAnnotation. void AddAnnotationNew(Annotation& a) override { auto* annotation = annotation_proto_->add_annotation(); annotation->ParseFromString(a.second); @@ -120,202 +105,10 @@ class AnnotationProtoCollector : public AnnotationCollector { } private: - AnnotationProto* annotation_proto_; + // The protocol buffer to which new annotations should be added. + AnnotationProto* const annotation_proto_; }; -// A source code printer for assisting in code generation. -// -// This type implements a simple templating language for substiting variables -// into static, user-provided strings, and also tracks indentation -// automatically. -// -// The main entry-point for this type is the Emit function, which can be used -// thus: -// -// Printer p(output); -// p.Emit({{"class", my_class_name}}, R"cc( -// class $class$ { -// public: -// $class$(int x) : x_(x) {} -// private: -// int x_; -// }; -// )cc"); -// -// Substitutions are of the form $var$, which is looked up in the map passed in -// as the first argument. The variable delimiter character, $, can be chosen to -// be something convenient for the target language. For example, in PHP, which -// makes heavy use of $, it can be made into something like # instead. -// -// A literal $ can be emitted by writing $$. -// -// Substitutions may contain spaces around the name of the variable, which will -// be ignored for the purposes of looking up the variable to substitute in, but -// which will be reproduced in the output: -// -// p.Emit({{"foo", "bar"}}, "$ foo $"); -// -// emits the string " bar ". If the substituted-in variable is the empty string, -// then the surrounding spaces are *not* printed: -// -// p.Emit({{"xzy", xyz}}, "$xyz $Thing"); -// -// If xyz is "Foo", this will become "Foo Thing", but if it is "", this becomes -// "Thing", rather than " Thing". This helps minimize awkward whitespace in the -// output. -// -// The value may be any type that can be stringified with `absl::StrCat`: -// -// p.Emit({{"num", 5}}, "x = $num$;"); -// -// If a variable is referenced in the format string that is missing, the program -// will crash. Callers must statically know that every variable reference is -// valid, and MUST NOT pass user-provided strings directly into Emit(). -// -// # Callback Substitution -// -// Instead of passing a string into Emit(), it is possible to pass in a callback -// as a variable mapping. This will take indentation into account, which allows -// factoring out parts of a formatting string while ensuring braces are -// balanced: -// -// p.Emit( -// {{"methods", [&] { -// p.Emit(R"cc( -// int Bar() { -// return 42; -// } -// )cc"); -// }}}, -// R"cc( -// class Foo { -// public: -// $methods$; -// }; -// )cc" -// ); -// -// This emits -// -// class Foo { -// public: -// int Bar() { -// return 42; -// } -// }; -// -// # Lookup Frames -// -// If many calls to Emit() use the same set of variables, they can be stored -// in a *variable lookup frame*, like so: -// -// auto vars = p.WithVars({{"class_name", my_class_name}}); -// p.Emit(R"cc( -// class $class_name$ { -// public: -// $class_name$(int x); -// // Etc. -// }; -// )cc"); -// -// WithVars() returns an RAII object that will "pop" the lookup frame on scope -// exit, ensuring that the variables remain local. There are a few different -// overloads of WithVars(); it accepts a map type, like absl::flat_hash_map, -// either by-value (which will cause the Printer to store a copy), or by -// pointer (which will cause the Printer to store a pointer, potentially -// avoiding a copy.) -// -// p.Emit(vars, "..."); is effectively syntax sugar for -// -// { auto v = p.WithVars(vars); p.Emit("..."); } -// -// NOTE: callbacks are *not* allowed with WithVars; callbacks should be local -// to a specific Emit() call. -// -// # Annotations -// -// If Printer is given an AnnotationCollector, it will use it to record which -// spans of generated code correspond to user-indicated descriptors. There are -// a few different ways of indicating when to emit annotations. -// -// The WithAnnotations() function is like WithVars(), but accepts maps with -// string keys and descriptor values. It adds an annotation variable frame and -// returns an RAII object that pops the frame. -// -// There are two different ways to annotate code. In the first, when -// substituting a variable, if there is an annotation with the same name, then -// the resulting expanded value's span will be annotated with that annotation. -// For example: -// -// auto v = p.WithVars({{"class_name", my_class_name}}); -// auto a = p.WithAnnotations({{"class_name", message_descriptor}}); -// p.Emit(R"cc( -// class $class_name$ { -// public: -// $class_name$(int x); -// // Etc. -// }; -// )cc"); -// -// The span corresponding to whatever $class_name$ expands to will be annotated -// as having come from message_descriptor. -// -// For convenience, this can be done with a single WithVars(), using the special -// three-argument form: -// -// auto v = p.WithVars({{"class_name", my_class_name, message_descriptor}}); -// p.Emit(R"cc( -// class $class_name$ { -// public: -// $class_name$(int x); -// // Etc. -// }; -// )cc"); -// -// -// Alternatively, a range may be given explicitly: -// -// auto a = p.WithAnnotations({{"my_desc", message_descriptor}}); -// p.Emit(R"cc( -// $_start$my_desc$ -// class Foo { -// // Etc. -// }; -// $_end$my_desc$ -// )cc"); -// -// The special $_start$ and $_end$ variables indicate the start and end of an -// annotated span, which is annotated with the variable that follows. This -// form can produce somewhat unreadable format strings and is not recommended. -// -// Note that whitespace after a $_start$ and before an $_end$ is not printed. -// -// # Indentation -// -// Printer tracks an indentation amount to add to each new line, independent -// from indentation in an Emit() call's literal. The amount of indentation to -// add is controlled by the WithIndent() function: -// -// p.Emit("class $class_name$ {"); -// { -// auto indent = p.WithIndent(); -// p.Emit(R"cc( -// public: -// $class_name$(int x); -// )cc"); -// } -// p.Emit("};"); -// -// This will automatically add one level of indentation to all code in scope of -// `indent`, which is an RAII object much like the return value of `WithVars()`. -// -// # Old API -// TODO(b/242326974): Delete this documentation. -// -// Printer supports an older-style API that is in the process of being -// re-written. The old documentation is reproduced here until all use-cases are -// handled. -// // This simple utility class assists in code generation. It basically // allows the caller to define a set of variables and then output some // text with variable substitutions. Example usage: @@ -387,310 +180,26 @@ class AnnotationProtoCollector : public AnnotationCollector { // // This code associates the span covering "call(bar,bar)" in the output with the // call_ descriptor. + class PROTOBUF_EXPORT Printer { - private: - // This type exists to work around an absl type that has not yet been - // released. - struct SourceLocation { - static SourceLocation current() { return {}; } - absl::string_view file_name() { return ""; } - int line() { return 0; } - }; - - struct AnnotationRecord { - std::vector path; - std::string file_path; - - // AnnotationRecord's constructors are *not* marked as explicit, - // specifically so that it is possible to construct a - // map by writing - // - // {{"foo", my_cool_descriptor}, {"bar", "file.proto"}} - - template < - typename String, - std::enable_if_t::value, - int> = 0> - AnnotationRecord( // NOLINT(google-explicit-constructor) - const String& file_path) - : file_path(file_path) {} - - template ::value, int> = 0> - AnnotationRecord(const Desc* desc) // NOLINT(google-explicit-constructor) - : file_path(desc->file()->name()) { - desc->GetLocationPath(&path); - } - }; - - // Sink type for constructing values to pass to WithVars() and Emit(). - template - struct VarDefinition { - using StringOrCallback = absl::variant>; - - template - VarDefinition(Key&& key, Value&& value) - : key(std::forward(key)), - value(ToStringOrCallback(std::forward(value), Rank2{})), - annotation(absl::nullopt) {} - - // NOTE: This is an overload rather than taking optional - // with a default argument of nullopt, because we want to pick up - // AnnotationRecord's user-defined conversions. Because going from - // e.g. Descriptor* -> optional requires two user-defined - // conversions, this does not work. - template - VarDefinition(Key&& key, Value&& value, AnnotationRecord annotation) - : key(std::forward(key)), - value(ToStringOrCallback(std::forward(value), Rank2{})), - annotation(std::move(annotation)) {} - - K key; - StringOrCallback value; - absl::optional annotation; - - private: - // go/ranked-overloads - struct Rank0 {}; - struct Rank1 : Rank0 {}; - struct Rank2 : Rank1 {}; - - // Dummy template for delayed instantiation, which is required for the - // static assert below to kick in only when this function is called when it - // shouldn't. - // - // This is done to produce a better error message than the "candidate does - // not match" SFINAE errors. - template - StringOrCallback ToStringOrCallback(std::function cb, Rank2) { - static_assert( - allowed, "callback-typed variables are not allowed in this location"); - return cb; - } - - // Separate from the AlphaNum overload to avoid copies when taking strings - // by value. - StringOrCallback ToStringOrCallback(std::string s, Rank1) { return s; } - - StringOrCallback ToStringOrCallback(const absl::AlphaNum& s, Rank0) { - return std::string(s.Piece()); - } - }; - public: - static constexpr char kDefaultVariableDelimiter = '$'; - static constexpr absl::string_view kProtocCodegenTrace = - "PROTOC_CODEGEN_TRACE"; + // Create a printer that writes text to the given output stream. Use the + // given character as the delimiter for variables. + Printer(ZeroCopyOutputStream* output, char variable_delimiter); - // Options for controlling how the output of a Printer is formatted. - struct Options { - Options() = default; - Options(const Options&) = default; - Options(Options&&) = default; - Options(char variable_delimiter, AnnotationCollector* annotation_collector) - : variable_delimiter(variable_delimiter), - annotation_collector(annotation_collector) {} - - // The delimiter for variable substitutions, e.g. $foo$. - char variable_delimiter = kDefaultVariableDelimiter; - // An optional listener the Printer calls whenever it emits a source - // annotation; may be null. - AnnotationCollector* annotation_collector = nullptr; - // The "comment start" token for the language being generated. This is used - // to allow the Printer to emit debugging annotations in the source code - // output. - absl::string_view comment_start = "//"; - // The number of spaces that a single level of indentation adds by default; - // this is the amount that WithIndent() increases indentation by. - size_t spaces_per_indent = 2; - // Whether to emit a "codegen trace" for calls to Emit(). If true, each call - // to Emit() will print a comment indicating where in the source of the - // compiler the Emit() call occurred. - // - // If disengaged, defaults to whether or not the environment variable - // `PROTOC_CODEGEN_TRACE` is set. - absl::optional enable_codegen_trace = absl::nullopt; - }; - - // Constructs a new Printer with the default options to output to - // `output`. - explicit Printer(ZeroCopyOutputStream* output) : Printer(output, Options{}) {} - - // Constructs a new printer with the given set of options to output to - // `output`. - Printer(ZeroCopyOutputStream* output, Options options); - - // Old-style constructor. Avoid in preference to the two constructors above. - // - // Will eventually be marked as deprecated. + // Create a printer that writes text to the given output stream. Use the + // given character as the delimiter for variables. If annotation_collector + // is not null, Printer will provide it with annotations about code written + // to the stream. annotation_collector is not owned by Printer. Printer(ZeroCopyOutputStream* output, char variable_delimiter, - AnnotationCollector* annotation_collector = nullptr) - : Printer(output, Options{variable_delimiter, annotation_collector}) {} + AnnotationCollector* annotation_collector); - Printer(const Printer&) = delete; - Printer& operator=(const Printer&) = delete; - - // Pushes a new variable lookup frame that stores `vars` by reference. - // - // Returns an RAII object that pops the lookup frame. - template - auto WithVars(const Map* vars) { - var_lookups_.emplace_back([vars](absl::string_view var) -> LookupResult { - auto it = vars->find(std::string(var)); - if (it == vars->end()) { - return absl::nullopt; - } - return absl::string_view(it->second); - }); - return absl::MakeCleanup([this] { var_lookups_.pop_back(); }); - } - - // Pushes a new variable lookup frame that stores `vars` by value. - // - // When writing `WithVars({...})`, this is the overload that will be called, - // and it will synthesize an `absl::flat_hash_map`. - // - // Returns an RAII object that pops the lookup frame. - template , - std::enable_if_t::value, int> = 0> - auto WithVars(Map&& vars) { - var_lookups_.emplace_back([vars = std::forward(vars)]( - absl::string_view var) -> LookupResult { - auto it = vars.find(std::string(var)); - if (it == vars.end()) { - return absl::nullopt; - } - return absl::string_view(it->second); - }); - return absl::MakeCleanup([this] { var_lookups_.pop_back(); }); - } - - auto WithVars(std::initializer_list< - VarDefinition> - vars); - - // Looks up a variable set with WithVars(). - // - // Will crash if: - // - `var` is not present in the lookup frame table. - // - `var` is a callback, rather than a string. - absl::string_view LookupVar(absl::string_view var); - - // Pushes a new annotation lookup frame that stores `vars` by reference. - // - // Returns an RAII object that pops the lookup frame. - template - auto WithAnnotations(const Map* vars) { - annotation_lookups_.emplace_back( - [vars](absl::string_view var) -> absl::optional { - auto it = vars->find(std::string(var)); - if (it == vars->end()) { - return absl::nullopt; - } - return AnnotationRecord(it->second); - }); - return absl::MakeCleanup([this] { annotation_lookups_.pop_back(); }); - } - - // Pushes a new variable lookup frame that stores `vars` by value. - // - // When writing `WithAnnotations({...})`, this is the overload that will be - // called, and it will synthesize an `absl::flat_hash_map`. - // - // Returns an RAII object that pops the lookup frame. - template > - auto WithAnnotations(Map&& vars) { - annotation_lookups_.emplace_back( - [vars = std::forward(vars)]( - absl::string_view var) -> absl::optional { - auto it = vars.find(std::string(var)); - if (it == vars.end()) { - return absl::nullopt; - } - return AnnotationRecord(it->second); - }); - return absl::MakeCleanup([this] { annotation_lookups_.pop_back(); }); - } - - // Increases the indentation by `indent` spaces; when nullopt, increments - // indentation by the configured default spaces_per_indent. - // - // Returns an RAII object that removes this indentation. - auto WithIndent(absl::optional indent = absl::nullopt) { - size_t delta = indent.value_or(options_.spaces_per_indent); - indent_ += delta; - return absl::MakeCleanup([this, delta] { indent_ -= delta; }); - } - - // Emits formatted source code to the underlying output. See the class - // documentation for more details. - // - // `format` MUST be a string constant. - void Emit(absl::string_view format, - SourceLocation loc = SourceLocation::current()) { - Emit({}, format, loc); - } - - // Emits formatted source code to the underlying output, injecting - // additional variables as a lookup frame for just this call. See the class - // documentation for more details. - // - // `format` MUST be a string constant. - void Emit(std::initializer_list< - VarDefinition> - vars, - absl::string_view format, - SourceLocation loc = SourceLocation::current()); - - // Write a string directly to the underlying output, performing no formatting - // of any sort. - void PrintRaw(absl::string_view data) { WriteRaw(data.data(), data.size()); } - - // Write a string directly to the underlying output, performing no formatting - // of any sort. - void WriteRaw(const char* data, size_t size); - - // True if any write to the underlying stream failed. (We don't just - // crash in this case because this is an I/O failure, not a programming - // error.) - bool failed() const { return failed_; } - - // -- Old-style API below; to be deprecated and removed. -- - // TODO(b/242326974): Deprecate these APIs. - - template > - void Print(const Map& vars, absl::string_view text) { - PrintOptions opts; - opts.checks_are_debug_only = true; - opts.use_substitution_map = true; - opts.allow_digit_substitions = false; - - auto pop = WithVars(&vars); - PrintImpl(text, {}, opts); - } - - template - void Print(absl::string_view text, const Args&... args) { - static_assert(sizeof...(args) % 2 == 0, ""); - - // Include an extra arg, since a zero-length array is ill-formed, and - // MSVC complains. - absl::string_view vars[] = {args..., ""}; - absl::flat_hash_map map; - map.reserve(sizeof...(args) / 2); - for (size_t i = 0; i < sizeof...(args); i += 2) { - map.emplace(std::string(vars[i]), std::string(vars[i + 1])); - } - - Print(map, text); - } + ~Printer(); // Link a substitution variable emitted by the last call to Print to the // object described by descriptor. template - void Annotate(absl::string_view varname, const SomeDescriptor* descriptor) { + void Annotate(const char* varname, const SomeDescriptor* descriptor) { Annotate(varname, varname, descriptor); } @@ -699,12 +208,13 @@ class PROTOBUF_EXPORT Printer { // begins at begin_varname's value and ends after the last character of the // value substituted for end_varname. template - void Annotate(absl::string_view begin_varname, absl::string_view end_varname, + void Annotate(const char* begin_varname, const char* end_varname, const SomeDescriptor* descriptor) { - if (options_.annotation_collector == nullptr) { + if (annotation_collector_ == NULL) { + // Annotations aren't turned on for this Printer, so don't pay the cost + // of building the location path. return; } - std::vector path; descriptor->GetLocationPath(&path); Annotate(begin_varname, end_varname, descriptor->file()->name(), path); @@ -712,7 +222,7 @@ class PROTOBUF_EXPORT Printer { // Link a substitution variable emitted by the last call to Print to the file // with path file_name. - void Annotate(absl::string_view varname, absl::string_view file_name) { + void Annotate(const char* varname, const std::string& file_name) { Annotate(varname, varname, file_name); } @@ -720,203 +230,158 @@ class PROTOBUF_EXPORT Printer { // the last call to Print to the file with path file_name. The range begins // at begin_varname's value and ends after the last character of the value // substituted for end_varname. - void Annotate(absl::string_view begin_varname, absl::string_view end_varname, - absl::string_view file_name) { - if (options_.annotation_collector == nullptr) { + void Annotate(const char* begin_varname, const char* end_varname, + const std::string& file_name) { + if (annotation_collector_ == NULL) { + // Annotations aren't turned on for this Printer. return; } - - Annotate(begin_varname, end_varname, file_name, {}); + std::vector empty_path; + Annotate(begin_varname, end_varname, file_name, empty_path); } - // Indent text by `options.spaces_per_indent`; undone by Outdent(). - void Indent() { indent_ += options_.spaces_per_indent; } + // Print some text after applying variable substitutions. If a particular + // variable in the text is not defined, this will crash. Variables to be + // substituted are identified by their names surrounded by delimiter + // characters (as given to the constructor). The variable bindings are + // defined by the given map. + void Print(const std::map& variables, + const char* text); - // Undoes a call to Indent(). + // Like the first Print(), except the substitutions are given as parameters. + template + void Print(const char* text, const Args&... args) { + std::map vars; + PrintInternal(&vars, text, args...); + } + + // Indent text by two spaces. After calling Indent(), two spaces will be + // inserted at the beginning of each line of text. Indent() may be called + // multiple times to produce deeper indents. + void Indent(); + + // Reduces the current indent level by two spaces, or crashes if the indent + // level is zero. void Outdent(); - // FormatInternal is a helper function not meant to use directly, use - // compiler::cpp::Formatter instead. - void FormatInternal(absl::Span args, - const std::map& vars, - absl::string_view format) { - PrintOptions opts; - opts.use_curly_brace_substitutions = true; - opts.strip_spaces_around_vars = true; + // Write a string to the output buffer. + // This method does not look for newlines to add indentation. + void PrintRaw(const std::string& data); - auto pop = WithVars(&vars); - PrintImpl(format, args, opts); - } + // Write a zero-delimited string to output buffer. + // This method does not look for newlines to add indentation. + void PrintRaw(const char* data); + + // Write some bytes to the output buffer. + // This method does not look for newlines to add indentation. + void WriteRaw(const char* data, int size); + + // FormatInternal is a helper function not meant to use directly, use + // compiler::cpp::Formatter instead. This function is meant to support + // formatting text using named variables (eq. "$foo$) from a lookup map (vars) + // and variables directly supplied by arguments (eq "$1$" meaning first + // argument which is the zero index element of args). + void FormatInternal(const std::vector& args, + const std::map& vars, + const char* format); + + // True if any write to the underlying stream failed. (We don't just + // crash in this case because this is an I/O failure, not a programming + // error.) + bool failed() const { return failed_; } private: - // Options for PrintImpl(). - struct PrintOptions { - // The callsite of the public entry-point. Only Emit() sets this. - absl::optional loc; - // If set, Validate() calls will not crash the program. - bool checks_are_debug_only = false; - // If set, the `substitutions_` map will be populated as variables are - // substituted. - bool use_substitution_map = false; - // If set, the ${1$ and $}$ forms will be substituted. These are used for - // a slightly janky annotation-insertion mechanism in FormatInternal, that - // requires that passed-in substitution variables be serialized protos. - bool use_curly_brace_substitutions = false; - // If set, the $n$ forms will be substituted, pulling from the `args` - // argument to PrintImpl(). - bool allow_digit_substitions = true; - // If set, when a variable substitution with spaces in it, such as $ var$, - // is encountered, the spaces are stripped, so that it is as if it was - // $var$. If $var$ substitutes to a non-empty string, the removed spaces are - // printed around the substituted value. - // - // See the class documentation for more information on this behavior. - bool strip_spaces_around_vars = true; - // If set, leading whitespace will be stripped from the format string to - // determine the "extraneous indentation" that is produced when the format - // string is a C++ raw string. This is used to remove leading spaces from - // a raw string that would otherwise result in erratic indentation in the - // output. - bool strip_raw_string_indentation = false; - // If set, the annotation lookup frames are searched, per the annotation - // semantics of Emit() described in the class documentation. - bool use_annotation_frames = true; - }; + // Link the output range defined by the substitution variables as emitted by + // the last call to Print to the object found at the SourceCodeInfo-style path + // in a file with path file_path. The range begins at the start of + // begin_varname's value and ends after the last character of the value + // substituted for end_varname. Note that begin_varname and end_varname + // may refer to the same variable. + void Annotate(const char* begin_varname, const char* end_varname, + const std::string& file_path, const std::vector& path); - // Emit an annotation for the range defined by the given substitution - // variables, as set by the most recent call to PrintImpl() that set - // `use_substitution_map` to true. - // - // The range begins at the start of `begin_varname`'s value and ends after the - // last byte of `end_varname`'s value. - // - // `begin_varname` and `end_varname may` refer to the same variable. - void Annotate(absl::string_view begin_varname, absl::string_view end_varname, - absl::string_view file_path, const std::vector& path); + // Base case + void PrintInternal(std::map* vars, + const char* text) { + Print(*vars, text); + } - // The core printing implementation. There are three public entry points, - // which enable different slices of functionality that are controlled by the - // `opts` argument. - void PrintImpl(absl::string_view format, absl::Span args, - PrintOptions opts); + template + void PrintInternal(std::map* vars, const char* text, + const char* key, const std::string& value, + const Args&... args) { + (*vars)[key] = value; + PrintInternal(vars, text, args...); + } - // This is a private function only so that it can see PrintOptions. - static bool Validate(bool cond, PrintOptions opts, - absl::FunctionRef message); - static bool Validate(bool cond, PrintOptions opts, absl::string_view message); + // Copy size worth of bytes from data to buffer_. + void CopyToBuffer(const char* data, int size); - // Performs calls to `Validate()` to check that `index < current_arg_index` - // and `index < args_len`, producing appropriate log lines if the checks fail, - // and crashing if necessary. - bool ValidateIndexLookupInBounds(size_t index, size_t current_arg_index, - size_t args_len, PrintOptions opts); + void push_back(char c) { + if (failed_) return; + if (buffer_size_ == 0) { + if (!Next()) return; + } + *buffer_++ = c; + buffer_size_--; + offset_++; + } - // Prints indentation if `at_start_of_line_` is true. - void IndentIfAtStart(); + bool Next(); - // Prints a codegen trace, for the given location in the compiler's source. - void PrintCodegenTrace(absl::optional loc); + inline void IndentIfAtStart(); + const char* WriteVariable( + const std::vector& args, + const std::map& vars, const char* format, + int* arg_index, + std::vector* annotations); - // The core implementation for "fully-elaborated" variable definitions. This - // is a private function to avoid users being able to set `allow_callbacks`. - template - auto WithDefs(std::initializer_list> vars); + const char variable_delimiter_; - // Returns the start and end of the value that was substituted in place of - // the variable `varname` in the last call to PrintImpl() (with - // `use_substitution_map` set), if such a variable was substituted exactly - // once. - absl::optional> GetSubstitutionRange( - absl::string_view varname, PrintOptions opts); + ZeroCopyOutputStream* const output_; + char* buffer_; + int buffer_size_; + // The current position, in bytes, in the output stream. This is equivalent + // to the total number of bytes that have been written so far. This value is + // used to calculate annotation ranges in the substitutions_ map below. + size_t offset_; - google::protobuf::io::zc_sink_internal::ZeroCopyStreamByteSink sink_; - Options options_; - size_t indent_ = 0; - bool at_start_of_line_ = true; - bool failed_ = false; - - using LookupResult = - absl::optional>>; - - std::vector> var_lookups_; - - std::vector< - std::function(absl::string_view)>> - annotation_lookups_; + std::string indent_; + bool at_start_of_line_; + bool failed_; // A map from variable name to [start, end) offsets in the output buffer. - // - // This stores the data looked up by GetSubstitutionRange(). - std::map> substitutions_; - // Keeps track of the keys in `substitutions_` that need to be updated when + // These refer to the offsets used for a variable after the last call to + // Print. If a variable was used more than once, the entry used in + // this map is set to a negative-length span. For singly-used variables, the + // start offset is the beginning of the substitution; the end offset is the + // last byte of the substitution plus one (such that (end - start) is the + // length of the substituted string). + std::map > 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 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 + // fails a debug assertion). + bool GetSubstitutionRange(const char* varname, + std::pair* range); + + // If non-null, annotation_collector_ is used to store annotations about + // generated code. + AnnotationCollector* const annotation_collector_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Printer); }; -template -auto Printer::WithDefs( - std::initializer_list> vars) { - absl::flat_hash_map>> - var_map; - var_map.reserve(vars.size()); - - absl::flat_hash_map annotation_map; - - for (auto& var : vars) { - auto result = var_map.insert({var.key, var.value}); - GOOGLE_CHECK(result.second) << "repeated variable in Emit() or WithVars() call: \"" - << var.key << "\""; - if (var.annotation.has_value()) { - annotation_map.insert({var.key, *var.annotation}); - } - } - - var_lookups_.emplace_back( - [map = std::move(var_map)](absl::string_view var) -> LookupResult { - auto it = map.find(var); - if (it == map.end()) { - return absl::nullopt; - } - if (auto* str = absl::get_if(&it->second)) { - return absl::string_view(*str); - } - - auto* f = absl::get_if>(&it->second); - GOOGLE_CHECK(f != nullptr); - return *f; - }); - - bool has_annotations = !annotation_map.empty(); - if (has_annotations) { - annotation_lookups_.emplace_back( - [map = std::move(annotation_map)]( - absl::string_view var) -> absl::optional { - auto it = map.find(var); - if (it == map.end()) { - return absl::nullopt; - } - return it->second; - }); - } - - return absl::MakeCleanup([this, has_annotations] { - var_lookups_.pop_back(); - if (has_annotations) { - annotation_lookups_.pop_back(); - } - }); -} - -inline auto Printer::WithVars( - std::initializer_list> - vars) { - return WithDefs(vars); -} } // namespace io } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_PRINTER_H__ diff --git a/libs/protobuf/src/google/protobuf/io/printer_death_test.cc b/libs/protobuf/src/google/protobuf/io/printer_death_test.cc deleted file mode 100644 index 5497168..0000000 --- a/libs/protobuf/src/google/protobuf/io/printer_death_test.cc +++ /dev/null @@ -1,174 +0,0 @@ -// 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. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. - -#include "google/protobuf/io/printer.h" - -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include -#include "google/protobuf/testing/googletest.h" -#include -#include "absl/container/flat_hash_map.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" - -namespace google { -namespace protobuf { -namespace io { -class PrinterTest : public testing::Test { - protected: - ZeroCopyOutputStream* output() { - GOOGLE_CHECK(stream_.has_value()); - return &*stream_; - } - absl::string_view written() { - stream_.reset(); - return out_; - } - - std::string out_; - absl::optional stream_{&out_}; -}; - -// FakeDescriptorFile defines only those members that Printer uses to write out -// annotations. -struct FakeDescriptorFile { - const std::string& name() const { return filename; } - std::string filename; -}; - -// FakeDescriptor defines only those members that Printer uses to write out -// annotations. -struct FakeDescriptor { - const FakeDescriptorFile* file() const { return &fake_file; } - void GetLocationPath(std::vector* output) const { *output = path; } - - FakeDescriptorFile fake_file; - std::vector path; -}; - -class FakeAnnotationCollector : public AnnotationCollector { - public: - ~FakeAnnotationCollector() override = default; - - void AddAnnotation(size_t begin_offset, size_t end_offset, - const std::string& file_path, - const std::vector& path) override { - } -}; - -#ifdef PROTOBUF_HAS_DEATH_TEST -TEST_F(PrinterTest, Death) { - Printer printer(output(), '$'); - - EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), ""); - EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), ""); - EXPECT_DEBUG_DEATH(printer.Outdent(), ""); -} - -TEST_F(PrinterTest, AnnotateMultipleUsesDeath) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - printer.Print("012$foo$4$foo$\n", "foo", "3"); - - FakeDescriptor descriptor{{"path"}, {33}}; - EXPECT_DEBUG_DEATH(printer.Annotate("foo", "foo", &descriptor), ""); -} - -TEST_F(PrinterTest, AnnotateNegativeLengthDeath) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - - FakeDescriptor descriptor{{"path"}, {33}}; - EXPECT_DEBUG_DEATH(printer.Annotate("bar", "foo", &descriptor), ""); -} - -TEST_F(PrinterTest, AnnotateUndefinedDeath) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - printer.Print("012$foo$4$foo$\n", "foo", "3"); - - FakeDescriptor descriptor{{"path"}, {33}}; - EXPECT_DEBUG_DEATH(printer.Annotate("bar", "bar", &descriptor), ""); -} - -TEST_F(PrinterTest, FormatInternalUnusedArgs) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - - EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$1$"), ""); -} - -TEST_F(PrinterTest, FormatInternalOutOfOrderArgs) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - - EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$2$ $1$"), ""); -} - -TEST_F(PrinterTest, FormatInternalZeroArg) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - - EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$0$"), ""); -} - -TEST_F(PrinterTest, FormatInternalOutOfBounds) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - - EXPECT_DEATH(printer.FormatInternal({"arg1", "arg2"}, {}, "$1$ $2$ $3$"), ""); -} - -TEST_F(PrinterTest, FormatInternalUnknownVar) { - FakeAnnotationCollector collector; - Printer printer(output(), '$', &collector); - - EXPECT_DEATH(printer.FormatInternal({}, {}, "$huh$"), ""); - EXPECT_DEATH(printer.FormatInternal({}, {}, "$ $"), ""); -} -#endif // PROTOBUF_HAS_DEATH_TEST -} // namespace io -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/io/printer_unittest.cc b/libs/protobuf/src/google/protobuf/io/printer_unittest.cc index 4e2dd7a..ed54d1d 100644 --- a/libs/protobuf/src/google/protobuf/io/printer_unittest.cc +++ b/libs/protobuf/src/google/protobuf/io/printer_unittest.cc @@ -32,388 +32,530 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/io/printer.h" +#include -#include -#include -#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" -#include -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include #include -#include "absl/container/flat_hash_map.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include namespace google { namespace protobuf { namespace io { -using ::testing::AllOf; -using ::testing::ElementsAre; -using ::testing::ExplainMatchResult; -using ::testing::Field; -using ::testing::IsEmpty; -using ::testing::MatchesRegex; -class PrinterTest : public testing::Test { - protected: - ZeroCopyOutputStream* output() { - GOOGLE_CHECK(stream_.has_value()); - return &*stream_; - } - absl::string_view written() { - stream_.reset(); - return out_; - } +// Each test repeats over several block sizes in order to test both cases +// where particular writes cross a buffer boundary and cases where they do +// not. - std::string out_; - absl::optional stream_{&out_}; -}; - -TEST_F(PrinterTest, EmptyPrinter) { - Printer printer(output(), '\0'); - EXPECT_FALSE(printer.failed()); +TEST(Printer, EmptyPrinter) { + char buffer[8192]; + const int block_size = 100; + ArrayOutputStream output(buffer, GOOGLE_ARRAYSIZE(buffer), block_size); + Printer printer(&output, '\0'); + EXPECT_TRUE(!printer.failed()); } -TEST_F(PrinterTest, BasicPrinting) { - { - Printer printer(output(), '\0'); +TEST(Printer, BasicPrinting) { + char buffer[8192]; - printer.Print("Hello World!"); - printer.Print(" This is the same line.\n"); - printer.Print("But this is a new one.\nAnd this is another one."); - EXPECT_FALSE(printer.failed()); + for (int block_size = 1; block_size < 512; block_size *= 2) { + ArrayOutputStream output(buffer, sizeof(buffer), block_size); + + { + Printer printer(&output, '\0'); + + printer.Print("Hello World!"); + printer.Print(" This is the same line.\n"); + printer.Print("But this is a new one.\nAnd this is another one."); + + EXPECT_FALSE(printer.failed()); + } + + buffer[output.ByteCount()] = '\0'; + + EXPECT_STREQ( + "Hello World! This is the same line.\n" + "But this is a new one.\n" + "And this is another one.", + buffer); } - - EXPECT_EQ(written(), - "Hello World! This is the same line.\n" - "But this is a new one.\n" - "And this is another one."); } -TEST_F(PrinterTest, WriteRaw) { - { - absl::string_view string_obj = "From an object\n"; - Printer printer(output(), '$'); - printer.WriteRaw("Hello World!", 12); - printer.PrintRaw(" This is the same line.\n"); - printer.PrintRaw("But this is a new one.\nAnd this is another one."); - printer.WriteRaw("\n", 1); - printer.PrintRaw(string_obj); - EXPECT_FALSE(printer.failed()); - } +TEST(Printer, WriteRaw) { + char buffer[8192]; - EXPECT_EQ(written(), - "Hello World! This is the same line.\n" - "But this is a new one.\n" - "And this is another one." - "\n" - "From an object\n"); + for (int block_size = 1; block_size < 512; block_size *= 2) { + ArrayOutputStream output(buffer, sizeof(buffer), block_size); + + { + std::string string_obj = "From an object\n"; + Printer printer(&output, '$'); + printer.WriteRaw("Hello World!", 12); + printer.PrintRaw(" This is the same line.\n"); + printer.PrintRaw("But this is a new one.\nAnd this is another one."); + printer.WriteRaw("\n", 1); + printer.PrintRaw(string_obj); + EXPECT_FALSE(printer.failed()); + } + + buffer[output.ByteCount()] = '\0'; + + EXPECT_STREQ( + "Hello World! This is the same line.\n" + "But this is a new one.\n" + "And this is another one." + "\n" + "From an object\n", + buffer); + } } -TEST_F(PrinterTest, VariableSubstitution) { - { - Printer printer(output(), '$'); +TEST(Printer, VariableSubstitution) { + char buffer[8192]; - absl::flat_hash_map vars{ - {"foo", "World"}, - {"bar", "$foo$"}, - {"abcdefg", "1234"}, - }; + for (int block_size = 1; block_size < 512; block_size *= 2) { + ArrayOutputStream output(buffer, sizeof(buffer), block_size); - printer.Print(vars, "Hello $foo$!\nbar = $bar$\n"); - printer.PrintRaw("RawBit\n"); - printer.Print(vars, "$abcdefg$\nA literal dollar sign: $$"); + { + Printer printer(&output, '$'); + std::map vars; - vars["foo"] = "blah"; - printer.Print(vars, "\nNow foo = $foo$."); + vars["foo"] = "World"; + vars["bar"] = "$foo$"; + vars["abcdefg"] = "1234"; - EXPECT_FALSE(printer.failed()); + printer.Print(vars, "Hello $foo$!\nbar = $bar$\n"); + printer.PrintRaw("RawBit\n"); + printer.Print(vars, "$abcdefg$\nA literal dollar sign: $$"); + + vars["foo"] = "blah"; + printer.Print(vars, "\nNow foo = $foo$."); + + EXPECT_FALSE(printer.failed()); + } + + buffer[output.ByteCount()] = '\0'; + + EXPECT_STREQ( + "Hello World!\n" + "bar = $foo$\n" + "RawBit\n" + "1234\n" + "A literal dollar sign: $\n" + "Now foo = blah.", + buffer); } - - EXPECT_EQ(written(), - "Hello World!\n" - "bar = $foo$\n" - "RawBit\n" - "1234\n" - "A literal dollar sign: $\n" - "Now foo = blah."); } -TEST_F(PrinterTest, InlineVariableSubstitution) { +TEST(Printer, InlineVariableSubstitution) { + char buffer[8192]; + + ArrayOutputStream output(buffer, sizeof(buffer)); + { - Printer printer(output(), '$'); + Printer printer(&output, '$'); printer.Print("Hello $foo$!\n", "foo", "World"); printer.PrintRaw("RawBit\n"); printer.Print("$foo$ $bar$\n", "foo", "one", "bar", "two"); EXPECT_FALSE(printer.failed()); } - EXPECT_EQ(written(), - "Hello World!\n" - "RawBit\n" - "one two\n"); + buffer[output.ByteCount()] = '\0'; + + EXPECT_STREQ( + "Hello World!\n" + "RawBit\n" + "one two\n", + buffer); } -// FakeDescriptorFile defines only those members that Printer uses to write out +// MockDescriptorFile defines only those members that Printer uses to write out // annotations. -struct FakeDescriptorFile { - const std::string& name() const { return filename; } - std::string filename; -}; - -// FakeDescriptor defines only those members that Printer uses to write out -// annotations. -struct FakeDescriptor { - const FakeDescriptorFile* file() const { return &fake_file; } - void GetLocationPath(std::vector* output) const { *output = path; } - - FakeDescriptorFile fake_file; - std::vector path; -}; - -class FakeAnnotationCollector : public AnnotationCollector { +class MockDescriptorFile { public: - ~FakeAnnotationCollector() override = default; + explicit MockDescriptorFile(const std::string& file) : file_(file) {} - // Records that the bytes in file_path beginning with begin_offset and ending - // before end_offset are associated with the SourceCodeInfo-style path. - void AddAnnotation(size_t begin_offset, size_t end_offset, - const std::string& file_path, - const std::vector& path) override { - annotations_.emplace_back( - Record{begin_offset, end_offset, file_path, path}); - } - - void AddAnnotationNew(Annotation& a) override { - GeneratedCodeInfo::Annotation annotation; - annotation.ParseFromString(a.second); - - Record r{a.first.first, a.first.second, annotation.source_file(), {}}; - for (int i : annotation.path()) { - r.path.push_back(i); - } - - annotations_.emplace_back(r); - } - - struct Record { - size_t start, end; - std::string file_path; - std::vector path; - - friend std::ostream& operator<<(std::ostream& out, const Record& record) { - return out << "Record{" << record.start << ", " << record.end << ", \"" - << record.file_path << "\", [" - << absl::StrJoin(record.path, ", ") << "]}"; - } - }; - - absl::Span Get() const { return annotations_; } + // The mock filename for this file. + const std::string& name() const { return file_; } private: - std::vector annotations_; + std::string file_; }; -template -testing::Matcher Annotation(Start start, - End end, - FilePath file_path, - Path path) { - return AllOf(Field("start", &FakeAnnotationCollector::Record::start, start), - Field("end", &FakeAnnotationCollector::Record::end, end), - Field("file_path", &FakeAnnotationCollector::Record::file_path, - file_path), - Field("path", &FakeAnnotationCollector::Record::path, path)); -} +// MockDescriptor defines only those members that Printer uses to write out +// annotations. +class MockDescriptor { + public: + MockDescriptor(const std::string& file, const std::vector& path) + : file_(file), path_(path) {} -TEST_F(PrinterTest, AnnotateMap) { - FakeAnnotationCollector collector; + // The mock file in which this descriptor was defined. + const MockDescriptorFile* file() const { return &file_; } + + private: + // Allows access to GetLocationPath. + friend class Printer; + + // Copies the pre-stored path to output. + void GetLocationPath(std::vector* output) const { *output = path_; } + + MockDescriptorFile file_; + std::vector path_; +}; + +TEST(Printer, AnnotateMap) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); - absl::flat_hash_map vars = {{"foo", "3"}, - {"bar", "5"}}; + Printer printer(&output, '$', &info_collector); + std::map vars; + vars["foo"] = "3"; + vars["bar"] = "5"; printer.Print(vars, "012$foo$4$bar$\n"); - - FakeDescriptor descriptor_1{{"path_1"}, {33}}; - FakeDescriptor descriptor_2{{"path_2"}, {11, 22}}; + std::vector path_1; + path_1.push_back(33); + std::vector path_2; + path_2.push_back(11); + path_2.push_back(22); + MockDescriptor descriptor_1("path_1", path_1); + MockDescriptor descriptor_2("path_2", path_2); printer.Annotate("foo", "foo", &descriptor_1); printer.Annotate("bar", "bar", &descriptor_2); } - - EXPECT_EQ(written(), "012345\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(3, 4, "path_1", ElementsAre(33)), - Annotation(5, 6, "path_2", ElementsAre(11, 22)))); + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("012345\n", buffer); + ASSERT_EQ(2, info.annotation_size()); + const GeneratedCodeInfo::Annotation* foo = info.annotation(0).path_size() == 1 + ? &info.annotation(0) + : &info.annotation(1); + const GeneratedCodeInfo::Annotation* bar = info.annotation(0).path_size() == 1 + ? &info.annotation(1) + : &info.annotation(0); + ASSERT_EQ(1, foo->path_size()); + ASSERT_EQ(2, bar->path_size()); + EXPECT_EQ(33, foo->path(0)); + EXPECT_EQ(11, bar->path(0)); + EXPECT_EQ(22, bar->path(1)); + EXPECT_EQ("path_1", foo->source_file()); + EXPECT_EQ("path_2", bar->source_file()); + EXPECT_EQ(3, foo->begin()); + EXPECT_EQ(4, foo->end()); + EXPECT_EQ(5, bar->begin()); + EXPECT_EQ(6, bar->end()); } -TEST_F(PrinterTest, AnnotateInline) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateInline) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - - FakeDescriptor descriptor_1{{"path_1"}, {33}}; - FakeDescriptor descriptor_2{{"path_2"}, {11, 22}}; + std::vector path_1; + path_1.push_back(33); + std::vector path_2; + path_2.push_back(11); + path_2.push_back(22); + MockDescriptor descriptor_1("path_1", path_1); + MockDescriptor descriptor_2("path_2", path_2); printer.Annotate("foo", "foo", &descriptor_1); printer.Annotate("bar", "bar", &descriptor_2); } - - EXPECT_EQ(written(), "012345\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(3, 4, "path_1", ElementsAre(33)), - Annotation(5, 6, "path_2", ElementsAre(11, 22)))); + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("012345\n", buffer); + ASSERT_EQ(2, info.annotation_size()); + const GeneratedCodeInfo::Annotation* foo = info.annotation(0).path_size() == 1 + ? &info.annotation(0) + : &info.annotation(1); + const GeneratedCodeInfo::Annotation* bar = info.annotation(0).path_size() == 1 + ? &info.annotation(1) + : &info.annotation(0); + ASSERT_EQ(1, foo->path_size()); + ASSERT_EQ(2, bar->path_size()); + EXPECT_EQ(33, foo->path(0)); + EXPECT_EQ(11, bar->path(0)); + EXPECT_EQ(22, bar->path(1)); + EXPECT_EQ("path_1", foo->source_file()); + EXPECT_EQ("path_2", bar->source_file()); + EXPECT_EQ(3, foo->begin()); + EXPECT_EQ(4, foo->end()); + EXPECT_EQ(5, bar->begin()); + EXPECT_EQ(6, bar->end()); } -TEST_F(PrinterTest, AnnotateRange) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateRange) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); - - FakeDescriptor descriptor{{"path"}, {33}}; + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); printer.Annotate("foo", "bar", &descriptor); } - - EXPECT_EQ(written(), "012345\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(3, 6, "path", ElementsAre(33)))); + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("012345\n", buffer); + ASSERT_EQ(1, info.annotation_size()); + const GeneratedCodeInfo::Annotation* foobar = &info.annotation(0); + ASSERT_EQ(1, foobar->path_size()); + EXPECT_EQ(33, foobar->path(0)); + EXPECT_EQ("path", foobar->source_file()); + EXPECT_EQ(3, foobar->begin()); + EXPECT_EQ(6, foobar->end()); } -TEST_F(PrinterTest, AnnotateEmptyRange) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateEmptyRange) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Print("012$foo$4$baz$$bam$$bar$\n", "foo", "3", "bar", "5", "baz", "", "bam", ""); - - FakeDescriptor descriptor{{"path"}, {33}}; + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); printer.Annotate("baz", "bam", &descriptor); } - - EXPECT_EQ(written(), "012345\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(5, 5, "path", ElementsAre(33)))); + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("012345\n", buffer); + ASSERT_EQ(1, info.annotation_size()); + const GeneratedCodeInfo::Annotation* bazbam = &info.annotation(0); + ASSERT_EQ(1, bazbam->path_size()); + EXPECT_EQ(33, bazbam->path(0)); + EXPECT_EQ("path", bazbam->source_file()); + EXPECT_EQ(5, bazbam->begin()); + EXPECT_EQ(5, bazbam->end()); } -TEST_F(PrinterTest, AnnotateDespiteUnrelatedMultipleUses) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateDespiteUnrelatedMultipleUses) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Print("012$foo$4$foo$$bar$\n", "foo", "3", "bar", "5"); - - FakeDescriptor descriptor{{"path"}, {33}}; + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); printer.Annotate("bar", "bar", &descriptor); } - - EXPECT_EQ(written(), "0123435\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(6, 7, "path", ElementsAre(33)))); + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("0123435\n", buffer); + ASSERT_EQ(1, info.annotation_size()); + const GeneratedCodeInfo::Annotation* bar = &info.annotation(0); + ASSERT_EQ(1, bar->path_size()); + EXPECT_EQ(33, bar->path(0)); + EXPECT_EQ("path", bar->source_file()); + EXPECT_EQ(6, bar->begin()); + EXPECT_EQ(7, bar->end()); } -TEST_F(PrinterTest, AnnotateIndent) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateIndent) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Print("0\n"); printer.Indent(); - printer.Print("$foo$", "foo", "4"); - FakeDescriptor descriptor1{{"path"}, {44}}; - printer.Annotate("foo", &descriptor1); - + std::vector path; + path.push_back(44); + MockDescriptor descriptor("path", path); + printer.Annotate("foo", &descriptor); printer.Print(",\n"); printer.Print("$bar$", "bar", "9"); - FakeDescriptor descriptor2{{"path"}, {99}}; - printer.Annotate("bar", &descriptor2); - + path[0] = 99; + MockDescriptor descriptor_two("path", path); + printer.Annotate("bar", &descriptor_two); printer.Print("\n${$$D$$}$\n", "{", "", "}", "", "D", "d"); - FakeDescriptor descriptor3{{"path"}, {1313}}; - printer.Annotate("{", "}", &descriptor3); - + path[0] = 1313; + MockDescriptor descriptor_three("path", path); + printer.Annotate("{", "}", &descriptor_three); printer.Outdent(); printer.Print("\n"); } - - EXPECT_EQ(written(), "0\n 4,\n 9\n d\n\n"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(4, 5, "path", ElementsAre(44)), - Annotation(9, 10, "path", ElementsAre(99)), - Annotation(13, 14, "path", ElementsAre(1313)))); + 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_F(PrinterTest, AnnotateIndentNewline) { - FakeAnnotationCollector collector; +TEST(Printer, AnnotateIndentNewline) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); { - Printer printer(output(), '$', &collector); + Printer printer(&output, '$', &info_collector); printer.Indent(); - printer.Print("$A$$N$$B$C\n", "A", "", "N", "\nz", "B", ""); - FakeDescriptor descriptor{{"path"}, {0}}; + std::vector path; + path.push_back(0); + MockDescriptor descriptor("path", path); printer.Annotate("A", "B", &descriptor); - printer.Outdent(); printer.Print("\n"); } - EXPECT_EQ(written(), "\nz C\n\n"); - - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(0, 4, "path", ElementsAre(0)))); + 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_F(PrinterTest, Indenting) { - { - Printer printer(output(), '$'); - absl::flat_hash_map vars = {{"newline", "\n"}}; +TEST(Printer, Indenting) { + char buffer[8192]; - printer.Print("This is not indented.\n"); - printer.Indent(); - printer.Print("This is indented\nAnd so is this\n"); - printer.Outdent(); - printer.Print("But this is not."); - printer.Indent(); - printer.Print( - " And this is still the same line.\n" - "But this is indented.\n"); - printer.PrintRaw("RawBit has indent at start\n"); - printer.PrintRaw("but not after a raw newline\n"); - printer.Print(vars, - "Note that a newline in a variable will break " - "indenting, as we see$newline$here.\n"); - printer.Indent(); - printer.Print("And this"); - printer.Outdent(); - printer.Outdent(); - printer.Print(" is double-indented\nBack to normal."); + for (int block_size = 1; block_size < 512; block_size *= 2) { + ArrayOutputStream output(buffer, sizeof(buffer), block_size); - EXPECT_FALSE(printer.failed()); + { + Printer printer(&output, '$'); + std::map vars; + + vars["newline"] = "\n"; + + printer.Print("This is not indented.\n"); + printer.Indent(); + printer.Print("This is indented\nAnd so is this\n"); + printer.Outdent(); + printer.Print("But this is not."); + printer.Indent(); + printer.Print( + " And this is still the same line.\n" + "But this is indented.\n"); + printer.PrintRaw("RawBit has indent at start\n"); + printer.PrintRaw("but not after a raw newline\n"); + printer.Print(vars, + "Note that a newline in a variable will break " + "indenting, as we see$newline$here.\n"); + printer.Indent(); + printer.Print("And this"); + printer.Outdent(); + printer.Outdent(); + printer.Print(" is double-indented\nBack to normal."); + + EXPECT_FALSE(printer.failed()); + } + + buffer[output.ByteCount()] = '\0'; + + EXPECT_STREQ( + "This is not indented.\n" + " This is indented\n" + " And so is this\n" + "But this is not. And this is still the same line.\n" + " But this is indented.\n" + " RawBit has indent at start\n" + "but not after a raw newline\n" + "Note that a newline in a variable will break indenting, as we see\n" + "here.\n" + " And this is double-indented\n" + "Back to normal.", + buffer); } - - EXPECT_EQ( - written(), - "This is not indented.\n" - " This is indented\n" - " And so is this\n" - "But this is not. And this is still the same line.\n" - " But this is indented.\n" - " RawBit has indent at start\n" - "but not after a raw newline\n" - "Note that a newline in a variable will break indenting, as we see\n" - "here.\n" - " And this is double-indented\n" - "Back to normal."); } -TEST_F(PrinterTest, WriteFailurePartial) { - std::string buffer(17, '\xaa'); - ArrayOutputStream output(&buffer[0], buffer.size()); +// Death tests do not work on Windows as of yet. +#ifdef PROTOBUF_HAS_DEATH_TEST +TEST(Printer, Death) { + char buffer[8192]; + + ArrayOutputStream output(buffer, sizeof(buffer)); + Printer printer(&output, '$'); + + EXPECT_DEBUG_DEATH(printer.Print("$nosuchvar$"), "Undefined variable"); + EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); + EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); +} + +TEST(Printer, AnnotateMultipleUsesDeath) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); + { + Printer printer(&output, '$', &info_collector); + printer.Print("012$foo$4$foo$\n", "foo", "3"); + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); + EXPECT_DEBUG_DEATH(printer.Annotate("foo", "foo", &descriptor), "multiple"); + } +} + +TEST(Printer, AnnotateNegativeLengthDeath) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); + { + Printer printer(&output, '$', &info_collector); + printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5"); + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); + EXPECT_DEBUG_DEATH(printer.Annotate("bar", "foo", &descriptor), "negative"); + } +} + +TEST(Printer, AnnotateUndefinedDeath) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector info_collector(&info); + { + Printer printer(&output, '$', &info_collector); + printer.Print("012$foo$4$foo$\n", "foo", "3"); + std::vector path; + path.push_back(33); + MockDescriptor descriptor("path", path); + EXPECT_DEBUG_DEATH(printer.Annotate("bar", "bar", &descriptor), + "Undefined"); + } +} +#endif // PROTOBUF_HAS_DEATH_TEST + +TEST(Printer, WriteFailurePartial) { + char buffer[17]; + + ArrayOutputStream output(buffer, sizeof(buffer)); Printer printer(&output, '$'); // Print 16 bytes to almost fill the buffer (should not fail). @@ -431,12 +573,13 @@ TEST_F(PrinterTest, WriteFailurePartial) { EXPECT_TRUE(printer.failed()); // Buffer should contain the first 17 bytes written. - EXPECT_EQ(buffer, "0123456789abcdef<"); + EXPECT_EQ("0123456789abcdef<", std::string(buffer, sizeof(buffer))); } -TEST_F(PrinterTest, WriteFailureExact) { - std::string buffer(16, '\xaa'); - ArrayOutputStream output(&buffer[0], buffer.size()); +TEST(Printer, WriteFailureExact) { + char buffer[16]; + + ArrayOutputStream output(buffer, sizeof(buffer)); Printer printer(&output, '$'); // Print 16 bytes to fill the buffer exactly (should not fail). @@ -452,358 +595,139 @@ TEST_F(PrinterTest, WriteFailureExact) { EXPECT_TRUE(printer.failed()); // Buffer should contain the first 16 bytes written. - EXPECT_EQ(buffer, "0123456789abcdef"); + EXPECT_EQ("0123456789abcdef", std::string(buffer, sizeof(buffer))); } -TEST_F(PrinterTest, FormatInternalDirectSub) { +TEST(Printer, FormatInternal) { + std::vector args{"arg1", "arg2"}; + std::map vars{ + {"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}; + // Substitution tests { - Printer printer(output(), '$'); - printer.FormatInternal({"arg1", "arg2"}, {}, "$1$ $2$"); + // Direct arg substitution + std::string s; + { + StringOutputStream output(&s); + Printer printer(&output, '$'); + printer.FormatInternal(args, vars, "$1$ $2$"); + } + EXPECT_EQ("arg1 arg2", s); } - EXPECT_EQ(written(), "arg1 arg2"); -} - -TEST_F(PrinterTest, FormatInternalSubWithSpacesLeft) { { - Printer printer(output(), '$'); - printer.FormatInternal({}, {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, - "$foo$$ baz$$ empty$"); + // Variable substitution including spaces left + std::string s; + { + StringOutputStream output(&s); + Printer printer(&output, '$'); + printer.FormatInternal({}, vars, "$foo$$ baz$$ empty$"); + } + EXPECT_EQ("bar bla", s); } - EXPECT_EQ(written(), "bar bla"); -} - -TEST_F(PrinterTest, FormatInternalSubWithSpacesRight) { { - Printer printer(output(), '$'); - printer.FormatInternal({}, {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, - "$empty $$foo $$baz$"); + // Variable substitution including spaces right + std::string s; + { + StringOutputStream output(&s); + Printer printer(&output, '$'); + printer.FormatInternal({}, vars, "$empty $$foo $$baz$"); + } + EXPECT_EQ("bar bla", s); } - EXPECT_EQ(written(), "bar bla"); -} - -TEST_F(PrinterTest, FormatInternalSubMixed) { { - Printer printer(output(), '$'); - printer.FormatInternal({"arg1", "arg2"}, - {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, - "$empty $$1$ $foo $$2$ $baz$"); - } - EXPECT_EQ(written(), "arg1 bar arg2 bla"); -} - -TEST_F(PrinterTest, FormatInternalIndent) { - { - Printer printer(output(), '$'); - printer.Indent(); - printer.FormatInternal({"arg1", "arg2"}, - {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, - "$empty $\n\n$1$ $foo $$2$\n$baz$"); - printer.Outdent(); - } - EXPECT_EQ(written(), "\n\n arg1 bar arg2\n bla"); -} - -TEST_F(PrinterTest, FormatInternalAnnotations) { - FakeAnnotationCollector collector; - { - Printer printer(output(), '$', &collector); - - printer.Indent(); - GeneratedCodeInfo::Annotation annotation; - annotation.set_source_file("file.proto"); - annotation.add_path(33); - - printer.FormatInternal({annotation.SerializeAsString(), "arg1", "arg2"}, - {{"foo", "bar"}, {"baz", "bla"}, {"empty", ""}}, - "$empty $\n\n${1$$2$$}$ $3$\n$baz$"); - printer.Outdent(); + // Mixed variable substitution + std::string s; + { + StringOutputStream output(&s); + Printer printer(&output, '$'); + printer.FormatInternal(args, vars, "$empty $$1$ $foo $$2$ $baz$"); + } + EXPECT_EQ("arg1 bar arg2 bla", s); } - EXPECT_EQ(written(), "\n\n arg1 arg2\n bla"); - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(4, 8, "file.proto", ElementsAre(33)))); -} - -TEST_F(PrinterTest, Emit) { + // Indentation tests { - Printer printer(output()); - printer.Emit(R"cc( - class Foo { - int x, y, z; - }; - )cc"); - printer.Emit(R"java( - public final class Bar { - Bar() {} - } - )java"); + // Empty lines shouldn't indent. + std::string s; + { + StringOutputStream output(&s); + Printer printer(&output, '$'); + printer.Indent(); + printer.FormatInternal(args, vars, "$empty $\n\n$1$ $foo $$2$\n$baz$"); + printer.Outdent(); + } + EXPECT_EQ("\n\n arg1 bar arg2\n bla", s); } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z;\n" - "};\n" - "public final class Bar {\n" - " Bar() {}\n" - "}\n"); -} - -TEST_F(PrinterTest, EmitKeepsExtraLine) { { - Printer printer(output()); - printer.Emit(R"cc( - - class Foo { - int x, y, z; - }; - )cc"); - printer.Emit(R"java( - - public final class Bar { - Bar() {} - } - )java"); + // Annotations should respect indentation. + std::string s; + GeneratedCodeInfo info; + { + StringOutputStream output(&s); + AnnotationProtoCollector info_collector(&info); + Printer printer(&output, '$', &info_collector); + printer.Indent(); + GeneratedCodeInfo::Annotation annotation; + annotation.set_source_file("file.proto"); + annotation.add_path(33); + std::vector args{annotation.SerializeAsString(), "arg1", + "arg2"}; + printer.FormatInternal(args, vars, "$empty $\n\n${1$$2$$}$ $3$\n$baz$"); + printer.Outdent(); + } + EXPECT_EQ("\n\n arg1 arg2\n bla", s); + ASSERT_EQ(1, info.annotation_size()); + const GeneratedCodeInfo::Annotation* arg1 = &info.annotation(0); + ASSERT_EQ(1, arg1->path_size()); + EXPECT_EQ(33, arg1->path(0)); + EXPECT_EQ("file.proto", arg1->source_file()); + EXPECT_EQ(4, arg1->begin()); + EXPECT_EQ(8, arg1->end()); } - - EXPECT_EQ(written(), - "\n" - "class Foo {\n" - " int x, y, z;\n" - "};\n" - "\n" - "public final class Bar {\n" - " Bar() {}\n" - "}\n"); -} - -TEST_F(PrinterTest, EmitWithSubs) { +#ifdef PROTOBUF_HAS_DEATH_TEST + // Death tests in case of illegal format strings. { - Printer printer(output()); - printer.Emit( - {{"class", "Foo"}, {"f1", "x"}, {"f2", "y"}, {"f3", "z"}, {"init", 42}}, - R"cc( - class $class$ { - int $f1$, $f2$, $f3$ = $init$; - }; - )cc"); + // Unused arguments + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal(args, vars, "$empty $$1$"), "Unused"); } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z = 42;\n" - "};\n"); -} - -TEST_F(PrinterTest, EmitWithVars) { { - Printer printer(output()); - auto v = printer.WithVars({ - {"class", "Foo"}, - {"f1", "x"}, - {"f2", "y"}, - {"f3", "z"}, - {"init", 42}, - }); - printer.Emit(R"cc( - class $class$ { - int $f1$, $f2$, $f3$ = $init$; - }; - )cc"); + // Wrong order arguments + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal(args, vars, "$2$ $1$"), "order"); } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z = 42;\n" - "};\n"); -} - -TEST_F(PrinterTest, EmitWithSpacedVars) { { - Printer printer(output()); - auto v = printer.WithVars({ - {"is_final", "final"}, - {"isnt_final", ""}, - {"class", "Foo"}, - }); - printer.Emit(R"java( - public $is_final $class $class$ { - // Stuff. - } - )java"); - printer.Emit(R"java( - public $isnt_final $class $class$ { - // Stuff. - } - )java"); + // Zero is illegal argument + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal(args, vars, "$0$"), "failed"); } - - EXPECT_EQ(written(), - "public final class Foo {\n" - " // Stuff.\n" - "}\n" - "public class Foo {\n" - " // Stuff.\n" - "}\n"); -} - -TEST_F(PrinterTest, EmitWithIndent) { { - Printer printer(output()); - auto v = printer.WithIndent(); - printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( - class Foo { - int $f1$, $f2$, $f3$; - }; - )cc"); + // Argument out of bounds + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal(args, vars, "$1$ $2$ $3$"), "bounds"); } - - EXPECT_EQ(written(), - " class Foo {\n" - " int x, y, z;\n" - " };\n"); -} - - -TEST_F(PrinterTest, EmitSameNameAnnotation) { - FakeAnnotationCollector collector; { - Printer printer(output(), '$', &collector); - FakeDescriptor descriptor{{"file.proto"}, {33}}; - auto v = printer.WithVars({{"class", "Foo"}}); - auto a = printer.WithAnnotations({{"class", &descriptor}}); - - printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( - class $class$ { - int $f1$, $f2$, $f3$; - }; - )cc"); + // Unknown variable + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal(args, vars, "$huh$ $1$$2$"), "Unknown"); } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z;\n" - "};\n"); - - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(6, 9, "file.proto", ElementsAre(33)))); -} - -TEST_F(PrinterTest, EmitSameNameAnnotationFileNameOnly) { - FakeAnnotationCollector collector; { - Printer printer(output(), '$', &collector); - auto v = printer.WithVars({{"class", "Foo"}}); - auto a = printer.WithAnnotations({{"class", "file.proto"}}); - - printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( - class $class$ { - int $f1$, $f2$, $f3$; - }; - )cc"); + // Illegal variable + std::string s; + StringOutputStream output(&s); + Printer printer(&output, '$'); + EXPECT_DEATH(printer.FormatInternal({}, vars, "$ $"), "Empty"); } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z;\n" - "};\n"); - - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(6, 9, "file.proto", IsEmpty()))); -} - -TEST_F(PrinterTest, EmitThreeArgWithVars) { - FakeAnnotationCollector collector; - { - Printer printer(output(), '$', &collector); - auto v = printer.WithVars({{"class", "Foo", "file.proto"}}); - - printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( - class $class$ { - int $f1$, $f2$, $f3$; - }; - )cc"); - } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z;\n" - "};\n"); - - EXPECT_THAT(collector.Get(), - ElementsAre(Annotation(6, 9, "file.proto", IsEmpty()))); -} - -TEST_F(PrinterTest, EmitRangeAnnotation) { - FakeAnnotationCollector collector; - { - Printer printer(output(), '$', &collector); - FakeDescriptor descriptor1{{"file1.proto"}, {33}}; - FakeDescriptor descriptor2{{"file2.proto"}, {11, 22}}; - auto v = printer.WithVars({{"class", "Foo"}}); - auto a = printer.WithAnnotations({ - {"message", &descriptor1}, - {"field", &descriptor2}, - }); - - printer.Emit({{"f1", "x"}, {"f2", "y"}, {"f3", "z"}}, R"cc( - $_start$message$ class $class$ { - $_start$field$ int $f1$, $f2$, $f3$; - $_end$field$ - }; - $_end$message$ - )cc"); - } - - EXPECT_EQ(written(), - "class Foo {\n" - " int x, y, z;\n" - "};\n"); - - EXPECT_THAT( - collector.Get(), - ElementsAre(Annotation(14, 27, "file2.proto", ElementsAre(11, 22)), - Annotation(0, 30, "file1.proto", ElementsAre(33)))); -} - -TEST_F(PrinterTest, EmitCallbacks) { - { - Printer printer(output()); - printer.Emit( - { - {"class", "Foo"}, - {"method", "bar"}, - {"methods", - [&] { - printer.Emit(R"cc( - int $method$() { return 42; } - )cc"); - }}, - {"fields", - [&] { - printer.Emit(R"cc( - int $method$_; - )cc"); - }}, - }, - R"cc( - class $class$ { - public: - $methods$; - - private: - $fields$; - }; - )cc"); - } - - EXPECT_EQ(written(), - "class Foo {\n" - " public:\n" - " int bar() { return 42; }\n" - "\n" - " private:\n" - " int bar_;\n" - "};\n"); +#endif // PROTOBUF_HAS_DEATH_TEST } } // namespace io diff --git a/libs/protobuf/src/google/protobuf/io/strtod.cc b/libs/protobuf/src/google/protobuf/io/strtod.cc index 61c6c29..03acb5b 100644 --- a/libs/protobuf/src/google/protobuf/io/strtod.cc +++ b/libs/protobuf/src/google/protobuf/io/strtod.cc @@ -28,17 +28,17 @@ // (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/io/strtod.h" +#include #include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include -#include "google/protobuf/stubs/strutil.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/io/tokenizer.cc b/libs/protobuf/src/google/protobuf/io/tokenizer.cc index 88bbc89..f9e0776 100644 --- a/libs/protobuf/src/google/protobuf/io/tokenizer.cc +++ b/libs/protobuf/src/google/protobuf/io/tokenizer.cc @@ -88,17 +88,18 @@ // I'd love to hear about other alternatives, though, as this code isn't // exactly pretty. -#include "google/protobuf/io/tokenizer.h" +#include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_format.h" -#include "google/protobuf/io/strtod.h" -#include "google/protobuf/io/zero_copy_stream.h" +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -405,7 +406,7 @@ void Tokenizer::ConsumeString(char delimiter) { case '\n': { if (!allow_multiline_strings_) { - AddError("Multiline strings are not allowed. Did you miss a \"?."); + AddError("String literals cannot cross line boundaries."); return; } NextChar(); @@ -421,7 +422,7 @@ void Tokenizer::ConsumeString(char delimiter) { // Possibly followed by two more octal digits, but these will // just be consumed by the main loop anyway so we don't need // to do so explicitly here. - } else if (TryConsume('x') || TryConsume('X')) { + } else if (TryConsume('x')) { if (!TryConsumeOne()) { AddError("Expected hex digits for escape sequence."); } @@ -707,7 +708,7 @@ bool Tokenizer::Next() { if (current_char_ & 0x80) { error_collector_->AddError( line_, column_, - absl::StrFormat("Interpreting non ascii codepoint %d.", + StringPrintf("Interpreting non ascii codepoint %d.", static_cast(current_char_))); } NextChar(); @@ -745,8 +746,6 @@ class CommentCollector { : prev_trailing_comments_(prev_trailing_comments), detached_comments_(detached_comments), next_leading_comments_(next_leading_comments), - num_comments_(0), - has_trailing_comment_(false), has_comment_(false), is_line_comment_(false), can_attach_to_prev_(true) { @@ -798,7 +797,6 @@ class CommentCollector { if (prev_trailing_comments_ != NULL) { prev_trailing_comments_->append(comment_buffer_); } - has_trailing_comment_ = true; can_attach_to_prev_ = false; } else { if (detached_comments_ != NULL) { @@ -806,39 +804,17 @@ class CommentCollector { } } ClearBuffer(); - num_comments_++; } } void DetachFromPrev() { can_attach_to_prev_ = false; } - void MaybeDetachComment() { - int count = num_comments_; - if (has_comment_) count++; - - // If there's one comment, make sure it is detached. - if (count == 1) { - if (has_trailing_comment_ && prev_trailing_comments_ != NULL) { - std::string trail = *prev_trailing_comments_; - if (detached_comments_ != NULL) { - // push trailing comment to front of detached - detached_comments_->insert(detached_comments_->begin(), 1, trail); - } - prev_trailing_comments_->clear(); - } - // flush pending comment so it's detached instead of leading - Flush(); - } - } - private: std::string* prev_trailing_comments_; std::vector* detached_comments_; std::string* next_leading_comments_; std::string comment_buffer_; - int num_comments_; - bool has_trailing_comment_; // True if any comments were read into comment_buffer_. This can be true even // if comment_buffer_ is empty, namely if the comment was "/**/". @@ -860,9 +836,6 @@ bool Tokenizer::NextWithComments(std::string* prev_trailing_comments, CommentCollector collector(prev_trailing_comments, detached_comments, next_leading_comments); - int prev_line = line_; - int trailing_comment_end_line = -1; - if (current_.type == TYPE_START) { // Ignore unicode byte order mark(BOM) if it appears at the file // beginning. Only UTF-8 BOM (0xEF 0xBB 0xBF) is accepted. @@ -876,14 +849,12 @@ bool Tokenizer::NextWithComments(std::string* prev_trailing_comments, } } collector.DetachFromPrev(); - prev_line = -1; } else { // A comment appearing on the same line must be attached to the previous // declaration. ConsumeZeroOrMore(); switch (TryConsumeCommentStart()) { case LINE_COMMENT: - trailing_comment_end_line = line_; ConsumeLineComment(collector.GetBufferForLineComment()); // Don't allow comments on subsequent lines to be attached to a trailing @@ -892,8 +863,14 @@ bool Tokenizer::NextWithComments(std::string* prev_trailing_comments, break; case BLOCK_COMMENT: ConsumeBlockComment(collector.GetBufferForBlockComment()); - trailing_comment_end_line = line_; + ConsumeZeroOrMore(); + if (!TryConsume('\n')) { + // Oops, the next token is on the same line. If we recorded a comment + // we really have no idea which token it should be attached to. + collector.ClearBuffer(); + return Next(); + } // Don't allow comments on subsequent lines to be attached to a trailing // comment. @@ -941,13 +918,6 @@ bool Tokenizer::NextWithComments(std::string* prev_trailing_comments, // makes no sense to attach a comment to the following token. collector.Flush(); } - if (prev_line == line_ || trailing_comment_end_line == line_) { - // When previous token and this one are on the same line, or - // even if a multi-line trailing comment ends on the same line - // as this token, it's unclear to what token the comment - // should be attached. So we detach it. - collector.MaybeDetachComment(); - } return result; } break; @@ -1032,20 +1002,9 @@ bool Tokenizer::ParseInteger(const std::string& text, uint64_t max_value, } double Tokenizer::ParseFloat(const std::string& text) { - double result = 0; - if (!TryParseFloat(text, &result)) { - GOOGLE_LOG(DFATAL) - << " Tokenizer::ParseFloat() passed text that could not have been" - " tokenized as a float: " - << absl::CEscape(text); - } - return result; -} - -bool Tokenizer::TryParseFloat(const std::string& text, double* result) { const char* start = text.c_str(); char* end; - *result = NoLocaleStrtod(start, &end); + double result = NoLocaleStrtod(start, &end); // "1e" is not a valid float, but if the tokenizer reads it, it will // report an error but still return it as a valid token. We need to @@ -1061,7 +1020,12 @@ bool Tokenizer::TryParseFloat(const std::string& text, double* result) { ++end; } - return static_cast(end - start) == text.size() && *start != '-'; + GOOGLE_LOG_IF(DFATAL, + static_cast(end - start) != text.size() || *start == '-') + << " Tokenizer::ParseFloat() passed text that could not have been" + " tokenized as a float: " + << CEscape(text); + return result; } // Helper to append a Unicode code point to a string as UTF8, without bringing @@ -1088,7 +1052,7 @@ static void AppendUTF8(uint32_t code_point, std::string* output) { // Unicode code points end at 0x10FFFF, so this is out-of-range. // ConsumeString permits hex values up to 0x1FFFFF, and FetchUnicodePoint // doesn't perform a range check. - absl::StrAppendFormat(output, "\\U%08x", code_point); + StringAppendF(output, "\\U%08x", code_point); return; } tmp = ghtonl(tmp); @@ -1181,7 +1145,7 @@ void Tokenizer::ParseStringAppend(const std::string& text, if (text_size == 0) { GOOGLE_LOG(DFATAL) << " Tokenizer::ParseStringAppend() passed text that could not" " have been tokenized as a string: " - << absl::CEscape(text); + << CEscape(text); return; } @@ -1215,7 +1179,7 @@ void Tokenizer::ParseStringAppend(const std::string& text, } output->push_back(static_cast(code)); - } else if (*ptr == 'x' || *ptr == 'X') { + } else if (*ptr == 'x') { // A hex escape. May zero, one, or two digits. (The zero case // will have been caught as an error earlier.) int code = 0; @@ -1272,4 +1236,4 @@ bool Tokenizer::IsIdentifier(const std::string& text) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/io/tokenizer.h b/libs/protobuf/src/google/protobuf/io/tokenizer.h index 73877cc..4abab7e 100644 --- a/libs/protobuf/src/google/protobuf/io/tokenizer.h +++ b/libs/protobuf/src/google/protobuf/io/tokenizer.h @@ -37,15 +37,15 @@ #ifndef GOOGLE_PROTOBUF_IO_TOKENIZER_H__ #define GOOGLE_PROTOBUF_IO_TOKENIZER_H__ + #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/port.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -69,8 +69,6 @@ typedef int ColumnNumber; class PROTOBUF_EXPORT ErrorCollector { public: inline ErrorCollector() {} - ErrorCollector(const ErrorCollector&) = delete; - ErrorCollector& operator=(const ErrorCollector&) = delete; virtual ~ErrorCollector(); // Indicates that there was an error in the input at the given line and @@ -84,6 +82,9 @@ class PROTOBUF_EXPORT ErrorCollector { // 1 to each before printing them. virtual void AddWarning(int /* line */, ColumnNumber /* column */, const std::string& /* message */) {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); }; // This class converts a stream of raw text into a stream of tokens for @@ -98,8 +99,6 @@ class PROTOBUF_EXPORT Tokenizer { // input stream and writes errors to the given error_collector. // The caller keeps ownership of input and error_collector. Tokenizer(ZeroCopyInputStream* input, ErrorCollector* error_collector); - Tokenizer(const Tokenizer&) = delete; - Tokenizer& operator=(const Tokenizer&) = delete; ~Tokenizer(); enum TokenType { @@ -150,11 +149,11 @@ class PROTOBUF_EXPORT Tokenizer { // Get the current token. This is updated when Next() is called. Before // the first call to Next(), current() has type TYPE_START and no contents. - const Token& current() const; + const Token& current(); // Return the previous token -- i.e. what current() returned before the // previous call to Next(). - const Token& previous() const; + const Token& previous(); // Advance to the next token. Returns false if the end of the input is // reached. @@ -214,10 +213,6 @@ class PROTOBUF_EXPORT Tokenizer { // result is undefined (possibly an assert failure). static double ParseFloat(const std::string& text); - // Parses given text as if it were a TYPE_FLOAT token. Returns false if the - // given text is not actually a valid float literal. - static bool TryParseFloat(const std::string& text, double* result); - // Parses a TYPE_STRING token. This never fails, so long as the text actually // comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the // result is undefined (possibly an assert failure). @@ -281,6 +276,8 @@ class PROTOBUF_EXPORT Tokenizer { // ----------------------------------------------------------------- private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Tokenizer); + Token current_; // Returned by current(). Token previous_; // Returned by previous(). @@ -426,9 +423,9 @@ class PROTOBUF_EXPORT Tokenizer { }; // inline methods ==================================================== -inline const Tokenizer::Token& Tokenizer::current() const { return current_; } +inline const Tokenizer::Token& Tokenizer::current() { return current_; } -inline const Tokenizer::Token& Tokenizer::previous() const { return previous_; } +inline const Tokenizer::Token& Tokenizer::previous() { return previous_; } inline void Tokenizer::ParseString(const std::string& text, std::string* output) { @@ -440,6 +437,6 @@ inline void Tokenizer::ParseString(const std::string& text, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__ diff --git a/libs/protobuf/src/google/protobuf/io/tokenizer_unittest.cc b/libs/protobuf/src/google/protobuf/io/tokenizer_unittest.cc index 3d59f63..16ba940 100644 --- a/libs/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +++ b/libs/protobuf/src/google/protobuf/io/tokenizer_unittest.cc @@ -32,19 +32,19 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/io/tokenizer.h" +#include #include #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/escaping.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include #include namespace google { @@ -63,7 +63,7 @@ namespace { // run multiple times, once for each item in some input array. TEST_1D // tests all cases in a single input array. TEST_2D tests all // combinations of cases from two arrays. The arrays must be statically -// defined such that the ABSL_ARRAYSIZE() macro works on them. Example: +// defined such that the GOOGLE_ARRAYSIZE() macro works on them. Example: // // int kCases[] = {1, 2, 3, 4} // TEST_1D(MyFixture, MyTest, kCases) { @@ -83,7 +83,7 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (int i = 0; i < ABSL_ARRAYSIZE(CASES); i++) { \ + for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \ SCOPED_TRACE(testing::Message() \ << #CASES " case #" << i << ": " << CASES[i]); \ DoSingleCase(CASES[i]); \ @@ -102,8 +102,8 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (int i = 0; i < ABSL_ARRAYSIZE(CASES1); i++) { \ - for (int j = 0; j < ABSL_ARRAYSIZE(CASES2); j++) { \ + for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \ + for (int j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \ SCOPED_TRACE(testing::Message() \ << #CASES1 " case #" << i << ": " << CASES1[i] << ", " \ << #CASES2 " case #" << j << ": " << CASES2[j]); \ @@ -163,7 +163,7 @@ class TestErrorCollector : public ErrorCollector { // implements ErrorCollector --------------------------------------- void AddError(int line, int column, const std::string& message) { - absl::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message); + strings::SubstituteAndAppend(&text_, "$0:$1: $2\n", line, column, message); } }; @@ -201,7 +201,7 @@ struct SimpleTokenCase { inline std::ostream& operator<<(std::ostream& out, const SimpleTokenCase& test_case) { - return out << absl::CEscape(test_case.input); + return out << CEscape(test_case.input); } SimpleTokenCase kSimpleTokenCases[] = { @@ -370,7 +370,7 @@ struct MultiTokenCase { inline std::ostream& operator<<(std::ostream& out, const MultiTokenCase& test_case) { - return out << absl::CEscape(test_case.input); + return out << CEscape(test_case.input); } MultiTokenCase kMultiTokenCases[] = { @@ -614,7 +614,7 @@ TEST_1D(TokenizerTest, ShCommentStyle, kBlockSizes) { tokenizer.set_comment_style(Tokenizer::SH_COMMENT_STYLE); // Advance through tokens and check that they are parsed as expected. - for (int i = 0; i < ABSL_ARRAYSIZE(kTokens); i++) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(kTokens); i++) { EXPECT_TRUE(tokenizer.Next()); EXPECT_EQ(tokenizer.current().text, kTokens[i]); } @@ -641,7 +641,7 @@ struct DocCommentCase { inline std::ostream& operator<<(std::ostream& out, const DocCommentCase& test_case) { - return out << absl::CEscape(test_case.input); + return out << CEscape(test_case.input); } DocCommentCase kDocCommentCases[] = { @@ -651,10 +651,10 @@ DocCommentCase kDocCommentCases[] = { {}, ""}, - {"prev /* detached */ next", + {"prev /* ignored */ next", "", - {" detached "}, + {}, ""}, {"prev // trailing comment\n" @@ -664,13 +664,6 @@ DocCommentCase kDocCommentCases[] = { {}, ""}, - {"prev\n" - "/* leading comment */ next", - - "", - {}, - " leading comment "}, - {"prev\n" "// leading comment\n" "// line 2\n" @@ -770,45 +763,6 @@ DocCommentCase kDocCommentCases[] = { "", {}, " leading comment\n"}, - - {"prev /* many comments*/ /* all inline */ /* will be handled */ next", - - " many comments", - {" all inline "}, - " will be handled "}, - - {R"pb( - prev /* a single block comment - that spans multiple lines - is detached if it ends - on the same line as next */ next" - )pb", - - "", - {" a single block comment\n" - "that spans multiple lines\n" - "is detached if it ends\n" - "on the same line as next "}, - ""}, - - {R"pb( - prev /* trailing */ /* leading */ next" - )pb", - - " trailing ", - {}, - " leading "}, - - {R"pb( - prev /* multi-line - trailing */ /* an oddly - placed detached */ /* an oddly - placed leading */ next" - )pb", - - " multi-line\ntrailing ", - {" an oddly\nplaced detached "}, - " an oddly\nplaced leading "}, }; TEST_2D(TokenizerTest, DocComments, kDocCommentCases, kBlockSizes) { @@ -842,7 +796,7 @@ TEST_2D(TokenizerTest, DocComments, kDocCommentCases, kBlockSizes) { prev_trailing_comments); for (int i = 0; i < detached_comments.size(); i++) { - ASSERT_LT(i, ABSL_ARRAYSIZE(kDocCommentCases)); + ASSERT_LT(i, GOOGLE_ARRAYSIZE(kDocCommentCases)); ASSERT_TRUE(kDocCommentCases_case.detached_comments[i] != NULL); EXPECT_EQ(kDocCommentCases_case.detached_comments[i], detached_comments[i]); } @@ -1045,8 +999,6 @@ TEST_F(TokenizerTest, ParseString) { EXPECT_EQ("\1x\1\123\739\52\334n\3", output); Tokenizer::ParseString("'\\x20\\x4'", &output); EXPECT_EQ("\x20\x4", output); - Tokenizer::ParseString("'\\X20\\X4'", &output); - EXPECT_EQ("\x20\x4", output); // Test invalid strings that may still be tokenized as strings. Tokenizer::ParseString("\"\\a\\l\\v\\t", &output); // \l is invalid @@ -1106,17 +1058,16 @@ struct ErrorCase { }; inline std::ostream& operator<<(std::ostream& out, const ErrorCase& test_case) { - return out << absl::CEscape(test_case.input); + return out << CEscape(test_case.input); } ErrorCase kErrorCases[] = { // String errors. {"'\\l' foo", true, "0:2: Invalid escape sequence in string literal.\n"}, - {"'\\X' foo", true, "0:3: Expected hex digits for escape sequence.\n"}, + {"'\\X' foo", true, "0:2: Invalid escape sequence in string literal.\n"}, {"'\\x' foo", true, "0:3: Expected hex digits for escape sequence.\n"}, {"'foo", false, "0:4: Unexpected end of string.\n"}, - {"'bar\nfoo", true, - "0:4: Multiline strings are not allowed. Did you miss a \"?.\n"}, + {"'bar\nfoo", true, "0:4: String literals cannot cross line boundaries.\n"}, {"'\\u01' foo", true, "0:5: Expected four hex digits for \\u escape sequence.\n"}, {"'\\u01' foo", true, diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_sink_test.cc b/libs/protobuf/src/google/protobuf/io/zero_copy_sink_test.cc deleted file mode 100644 index 7c69eda..0000000 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_sink_test.cc +++ /dev/null @@ -1,228 +0,0 @@ -// 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/io/zero_copy_sink.h" - -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" - -namespace google { -namespace protobuf { -namespace io { -namespace zc_sink_internal { -namespace { - -class ChunkedString { - public: - explicit ChunkedString(absl::string_view data, size_t skipped_patterns) - : data_(data), skipped_patterns_(skipped_patterns) {} - - // Returns the next chunk; empty if out of chunks. - absl::string_view NextChunk() { - if (pattern_bit_idx_ == data_.size()) { - return ""; - } - size_t start = pattern_bit_idx_; - do { - ++pattern_bit_idx_; - } while (pattern_bit_idx_ < data_.size() && - (pattern_ >> pattern_bit_idx_ & 1) == 0); - size_t end = pattern_bit_idx_; - return data_.substr(start, end - start); - } - - // Resets the stream and runs the next pattern of splits. - bool NextPattern() { - pattern_ += skipped_patterns_; - if (pattern_ >= (1 << data_.size())) { - return false; - } - pattern_bit_idx_ = 0; - return true; - } - - // prints out the pattern as a sequence of quoted strings. - std::string PatternAsQuotedString() { - std::string out; - size_t start = 0; - for (size_t i = 0; i <= data_.size(); ++i) { - if (i == data_.size() || (pattern_ >> start & 1) != 0) { - if (!out.empty()) { - absl::StrAppend(&out, " "); - } - absl::StrAppend( - &out, "\"", - absl::CHexEscape(std::string{data_.substr(start, i - start)}), - "\""); - start = i; - } - } - return out; - } - - private: - absl::string_view data_; - size_t skipped_patterns_; - // pattern_ is a bitset indicating at which indices we insert a seam. - uint64_t pattern_ = 0; - size_t pattern_bit_idx_ = 0; -}; - -class PatternedOutputStream : public io::ZeroCopyOutputStream { - public: - explicit PatternedOutputStream(ChunkedString data) : data_(data) {} - - bool Next(void** buffer, int* length) override { - absl::string_view segment; - if (!back_up_.empty()) { - segment = back_up_.back(); - back_up_.pop_back(); - } else { - segment_ = data_.NextChunk(); - segment = segment_; - } - - if (segment_.empty()) { - return false; - } - - // TODO(b/234159981): This is only ever constructed in test code, and only - // from non-const bytes, so this is a valid cast. We need to do this since - // OSS proto does not yet have absl::Span; once we take a full Abseil - // dependency we should use that here instead. - *buffer = const_cast(segment.data()); - *length = static_cast(segment.size()); - byte_count_ += static_cast(segment.size()); - return true; - } - - void BackUp(int length) override { - GOOGLE_CHECK(length <= static_cast(segment_.size())); - - size_t backup = segment_.size() - static_cast(length); - back_up_.push_back(segment_.substr(backup)); - segment_ = segment_.substr(0, backup); - byte_count_ -= static_cast(length); - } - - int64_t ByteCount() const override { return byte_count_; } - - private: - ChunkedString data_; - absl::string_view segment_; - - std::vector back_up_; - int64_t byte_count_ = 0; -}; - -class ZeroCopyStreamByteSinkTest : public testing::Test { - protected: - std::array output_{}; - absl::string_view output_view_{output_.data(), output_.size()}; - ChunkedString output_chunks_{output_view_, 7}; -}; - -TEST_F(ZeroCopyStreamByteSinkTest, WriteExact) { - do { - SCOPED_TRACE(output_chunks_.PatternAsQuotedString()); - ChunkedString input("0123456789", 1); - - do { - SCOPED_TRACE(input.PatternAsQuotedString()); - output_ = {}; - PatternedOutputStream output_stream(output_chunks_); - ZeroCopyStreamByteSink byte_sink(&output_stream); - SCOPED_TRACE(input.PatternAsQuotedString()); - absl::string_view chunk; - while (!(chunk = input.NextChunk()).empty()) { - byte_sink.Append(chunk.data(), chunk.size()); - } - } while (input.NextPattern()); - - ASSERT_EQ(output_view_, "0123456789"); - } while (output_chunks_.NextPattern()); -} - -TEST_F(ZeroCopyStreamByteSinkTest, WriteShort) { - do { - SCOPED_TRACE(output_chunks_.PatternAsQuotedString()); - ChunkedString input("012345678", 1); - - do { - SCOPED_TRACE(input.PatternAsQuotedString()); - output_ = {}; - PatternedOutputStream output_stream(output_chunks_); - ZeroCopyStreamByteSink byte_sink(&output_stream); - SCOPED_TRACE(input.PatternAsQuotedString()); - absl::string_view chunk; - while (!(chunk = input.NextChunk()).empty()) { - byte_sink.Append(chunk.data(), chunk.size()); - } - } while (input.NextPattern()); - - ASSERT_EQ(output_view_, absl::string_view("012345678\0", 10)); - } while (output_chunks_.NextPattern()); -} - -TEST_F(ZeroCopyStreamByteSinkTest, WriteLong) { - do { - SCOPED_TRACE(output_chunks_.PatternAsQuotedString()); - ChunkedString input("0123456789A", 1); - - do { - SCOPED_TRACE(input.PatternAsQuotedString()); - output_ = {}; - PatternedOutputStream output_stream(output_chunks_); - ZeroCopyStreamByteSink byte_sink(&output_stream); - SCOPED_TRACE(input.PatternAsQuotedString()); - absl::string_view chunk; - while (!(chunk = input.NextChunk()).empty()) { - byte_sink.Append(chunk.data(), chunk.size()); - } - } while (input.NextPattern()); - - ASSERT_EQ(output_view_, "0123456789"); - } while (output_chunks_.NextPattern()); -} -} // namespace -} // namespace zc_sink_internal -} // namespace io -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream.cc b/libs/protobuf/src/google/protobuf/io/zero_copy_stream.cc index 83b7225..f81555e 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream.cc +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream.cc @@ -32,10 +32,10 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/io/zero_copy_stream.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream.h b/libs/protobuf/src/google/protobuf/io/zero_copy_stream.h index ad27345..2041cbf 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream.h +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream.h @@ -107,12 +107,12 @@ #ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/port.h" + +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -127,8 +127,6 @@ class ZeroCopyOutputStream; class PROTOBUF_EXPORT ZeroCopyInputStream { public: ZeroCopyInputStream() {} - ZeroCopyInputStream(const ZeroCopyInputStream&) = delete; - ZeroCopyInputStream& operator=(const ZeroCopyInputStream&) = delete; virtual ~ZeroCopyInputStream() {} // Obtains a chunk of data from the stream. @@ -183,6 +181,9 @@ class PROTOBUF_EXPORT ZeroCopyInputStream { // Returns the total number of bytes read since this object was created. virtual int64_t ByteCount() const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyInputStream); }; // Abstract interface similar to an output stream but designed to minimize @@ -190,8 +191,6 @@ class PROTOBUF_EXPORT ZeroCopyInputStream { class PROTOBUF_EXPORT ZeroCopyOutputStream { public: ZeroCopyOutputStream() {} - ZeroCopyOutputStream(const ZeroCopyOutputStream&) = delete; - ZeroCopyOutputStream& operator=(const ZeroCopyOutputStream&) = delete; virtual ~ZeroCopyOutputStream() {} // Obtains a buffer into which data can be written. Any data written @@ -247,12 +246,15 @@ class PROTOBUF_EXPORT ZeroCopyOutputStream { virtual bool WriteAliasedRaw(const void* data, int size); virtual bool AllowsAliasing() const { return false; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyOutputStream); }; } // namespace io } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc index 041930e..c66bc86 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -43,10 +43,11 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include +#include +#include namespace google { diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h index d5a119c..a385992 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h @@ -40,15 +40,16 @@ #ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ + #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -70,8 +71,6 @@ class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL // 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(const FileInputStream&) = delete; - FileInputStream& operator=(const FileInputStream&) = delete; // Flushes any buffers and closes the underlying file. Returns false if // an error occurs during the process; use GetErrno() to examine the error. @@ -102,8 +101,6 @@ class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL : public CopyingInputStream { public: CopyingFileInputStream(int file_descriptor); - CopyingFileInputStream(const CopyingFileInputStream&) = delete; - CopyingFileInputStream& operator=(const CopyingFileInputStream&) = delete; ~CopyingFileInputStream() override; bool Close(); @@ -126,10 +123,14 @@ class PROTOBUF_EXPORT FileInputStream PROTOBUF_FUTURE_FINAL // Did we try to seek once and fail? If so, we assume this file descriptor // doesn't support seeking and won't try again. bool previous_seek_failed_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream); }; CopyingFileInputStream copying_input_; CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream); }; // =================================================================== @@ -149,8 +150,6 @@ class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL // that should be returned by Next(). Otherwise, a reasonable default // is used. explicit FileOutputStream(int file_descriptor, int block_size = -1); - FileOutputStream(const FileOutputStream&) = delete; - FileOutputStream& operator=(const FileOutputStream&) = delete; ~FileOutputStream() override; @@ -177,8 +176,6 @@ class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL : public CopyingOutputStream { public: CopyingFileOutputStream(int file_descriptor); - CopyingFileOutputStream(const CopyingFileOutputStream&) = delete; - CopyingFileOutputStream& operator=(const CopyingFileOutputStream&) = delete; ~CopyingFileOutputStream() override; bool Close(); @@ -196,9 +193,13 @@ class PROTOBUF_EXPORT FileOutputStream PROTOBUF_FUTURE_FINAL // The errno of the I/O error, if one has occurred. Otherwise, zero. int errno_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream); }; CopyingFileOutputStream copying_output_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream); }; // =================================================================== @@ -215,8 +216,6 @@ class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL // 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(const IstreamInputStream&) = delete; - IstreamInputStream& operator=(const IstreamInputStream&) = delete; // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size) override; @@ -229,9 +228,6 @@ class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL : public CopyingInputStream { public: CopyingIstreamInputStream(std::istream* input); - CopyingIstreamInputStream(const CopyingIstreamInputStream&) = delete; - CopyingIstreamInputStream& operator=(const CopyingIstreamInputStream&) = - delete; ~CopyingIstreamInputStream() override; // implements CopyingInputStream --------------------------------- @@ -241,10 +237,14 @@ class PROTOBUF_EXPORT IstreamInputStream PROTOBUF_FUTURE_FINAL private: // The stream. std::istream* input_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); }; CopyingIstreamInputStream copying_input_; CopyingInputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); }; // =================================================================== @@ -261,8 +261,6 @@ class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL // that should be returned by Next(). Otherwise, a reasonable default // is used. explicit OstreamOutputStream(std::ostream* stream, int block_size = -1); - OstreamOutputStream(const OstreamOutputStream&) = delete; - OstreamOutputStream& operator=(const OstreamOutputStream&) = delete; ~OstreamOutputStream() override; // implements ZeroCopyOutputStream --------------------------------- @@ -275,9 +273,6 @@ class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL : public CopyingOutputStream { public: CopyingOstreamOutputStream(std::ostream* output); - CopyingOstreamOutputStream(const CopyingOstreamOutputStream&) = delete; - CopyingOstreamOutputStream& operator=(const CopyingOstreamOutputStream&) = - delete; ~CopyingOstreamOutputStream() override; // implements CopyingOutputStream -------------------------------- @@ -286,10 +281,14 @@ class PROTOBUF_EXPORT OstreamOutputStream PROTOBUF_FUTURE_FINAL private: // The stream. std::ostream* output_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); }; CopyingOstreamOutputStream copying_output_; CopyingOutputStreamAdaptor impl_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); }; // =================================================================== @@ -307,8 +306,6 @@ class PROTOBUF_EXPORT ConcatenatingInputStream PROTOBUF_FUTURE_FINAL // 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(const ConcatenatingInputStream&) = delete; - ConcatenatingInputStream& operator=(const ConcatenatingInputStream&) = delete; ~ConcatenatingInputStream() override = default; // implements ZeroCopyInputStream ---------------------------------- @@ -324,6 +321,8 @@ class PROTOBUF_EXPORT ConcatenatingInputStream PROTOBUF_FUTURE_FINAL ZeroCopyInputStream* const* streams_; int stream_count_; int64_t bytes_retired_; // Bytes read from previous streams. + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); }; // =================================================================== @@ -332,6 +331,6 @@ class PROTOBUF_EXPORT ConcatenatingInputStream PROTOBUF_FUTURE_FINAL } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index 9940263..b3dfd84 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -32,20 +32,15 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" +#include #include #include -#include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/base/casts.h" -#include "absl/strings/cord.h" -#include "absl/strings/internal/resize_uninitialized.h" - -// Must be included last -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include namespace google { namespace protobuf { @@ -159,7 +154,7 @@ bool StringOutputStream::Next(void** data, int* size) { // Avoid integer overflow in returned '*size'. new_size = std::min(new_size, old_size + std::numeric_limits::max()); // Increase the size, also make sure that it is at least kMinimumSize. - absl::strings_internal::STLStringResizeUninitialized( + STLStringResizeUninitialized( target_, std::max(new_size, kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness. @@ -188,7 +183,7 @@ int CopyingInputStream::Skip(int count) { int skipped = 0; while (skipped < count) { int bytes = Read(junk, std::min(count - skipped, - absl::implicit_cast(sizeof(junk)))); + implicit_cast(sizeof(junk)))); if (bytes <= 0) { // EOF or read error. return skipped; diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h index a23713c..cbda328 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -44,19 +44,19 @@ #ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ #define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ + #include #include #include -#include -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -78,10 +78,6 @@ class PROTOBUF_EXPORT ArrayInputStream PROTOBUF_FUTURE_FINAL ArrayInputStream(const void* data, int size, int block_size = -1); ~ArrayInputStream() override = default; - // `ArrayInputStream` is neither copiable nor assignable - ArrayInputStream(const ArrayInputStream&) = delete; - ArrayInputStream& operator=(const ArrayInputStream&) = delete; - // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size) override; void BackUp(int count) override; @@ -97,6 +93,8 @@ class PROTOBUF_EXPORT ArrayInputStream PROTOBUF_FUTURE_FINAL int position_; int last_returned_size_; // How many bytes we returned last time Next() // was called (used for error checking only). + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayInputStream); }; // =================================================================== @@ -115,10 +113,6 @@ class PROTOBUF_EXPORT ArrayOutputStream PROTOBUF_FUTURE_FINAL ArrayOutputStream(void* data, int size, int block_size = -1); ~ArrayOutputStream() override = default; - // `ArrayOutputStream` is neither copiable nor assignable - ArrayOutputStream(const ArrayOutputStream&) = delete; - ArrayOutputStream& operator=(const ArrayOutputStream&) = delete; - // implements ZeroCopyOutputStream --------------------------------- bool Next(void** data, int* size) override; void BackUp(int count) override; @@ -132,6 +126,8 @@ class PROTOBUF_EXPORT ArrayOutputStream PROTOBUF_FUTURE_FINAL int position_; int last_returned_size_; // How many bytes we returned last time Next() // was called (used for error checking only). + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayOutputStream); }; // =================================================================== @@ -152,10 +148,6 @@ class PROTOBUF_EXPORT StringOutputStream PROTOBUF_FUTURE_FINAL explicit StringOutputStream(std::string* target); ~StringOutputStream() override = default; - // `StringOutputStream` is neither copiable nor assignable - StringOutputStream(const StringOutputStream&) = delete; - StringOutputStream& operator=(const StringOutputStream&) = delete; - // implements ZeroCopyOutputStream --------------------------------- bool Next(void** data, int* size) override; void BackUp(int count) override; @@ -165,6 +157,8 @@ class PROTOBUF_EXPORT StringOutputStream PROTOBUF_FUTURE_FINAL static constexpr size_t kMinimumSize = 16; std::string* target_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream); }; // Note: There is no StringInputStream. Instead, just create an @@ -221,10 +215,6 @@ class PROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream { int block_size = -1); ~CopyingInputStreamAdaptor() override; - // `CopyingInputStreamAdaptor` is neither copiable nor assignable - CopyingInputStreamAdaptor(const CopyingInputStreamAdaptor&) = delete; - CopyingInputStreamAdaptor& operator=(const CopyingInputStreamAdaptor&) = delete; - // Call SetOwnsCopyingStream(true) to tell the CopyingInputStreamAdaptor to // delete the underlying CopyingInputStream when it is destroyed. void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } @@ -265,6 +255,8 @@ class PROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream { // BackUp(). These need to be returned again. // 0 <= backup_bytes_ <= buffer_used_ int backup_bytes_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingInputStreamAdaptor); }; // =================================================================== @@ -306,10 +298,6 @@ class PROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream { int block_size = -1); ~CopyingOutputStreamAdaptor() override; - // `CopyingOutputStreamAdaptor` is neither copiable nor assignable - CopyingOutputStreamAdaptor(const CopyingOutputStreamAdaptor&) = delete; - CopyingOutputStreamAdaptor& operator=(const CopyingOutputStreamAdaptor&) = delete; - // Writes all pending data to the underlying stream. Returns false if a // write error occurred on the underlying stream. (The underlying // stream itself is not necessarily flushed.) @@ -354,6 +342,8 @@ class PROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream { // returned by Next()). When BackUp() is called, we just reduce this. // 0 <= buffer_used_ <= buffer_size_. int buffer_used_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOutputStreamAdaptor); }; // =================================================================== @@ -366,10 +356,6 @@ class PROTOBUF_EXPORT LimitingInputStream PROTOBUF_FUTURE_FINAL LimitingInputStream(ZeroCopyInputStream* input, int64_t limit); ~LimitingInputStream() override; - // `LimitingInputStream` is neither copiable nor assignable - LimitingInputStream(const LimitingInputStream&) = delete; - LimitingInputStream& operator=(const LimitingInputStream&) = delete; - // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size) override; void BackUp(int count) override; @@ -381,15 +367,31 @@ class PROTOBUF_EXPORT LimitingInputStream PROTOBUF_FUTURE_FINAL ZeroCopyInputStream* input_; int64_t limit_; // Decreases as we go, becomes negative if we overshoot. int64_t prior_bytes_read_; // Bytes read on underlying stream at construction + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); }; // =================================================================== +// mutable_string_data() and as_string_data() are workarounds to improve +// the performance of writing new data to an existing string. Unfortunately +// the methods provided by the string class are suboptimal, and using memcpy() +// is mildly annoying because it requires its pointer args to be non-NULL even +// if we ask it to copy 0 bytes. Furthermore, string_as_array() has the +// property that it always returns NULL if its arg is the empty string, exactly +// what we want to avoid if we're using it in conjunction with memcpy()! +// With C++11, the desired memcpy() boils down to memcpy(..., &(*s)[0], size), +// where s is a string*. Without C++11, &(*s)[0] is not guaranteed to be safe, +// so we use string_as_array(), and live with the extra logic that tests whether +// *s is empty. + // Return a pointer to mutable characters underlying the given string. The // return value is valid until the next time the string is resized. We // trust the caller to treat the return value as an array of length s->size(). inline char* mutable_string_data(std::string* s) { + // This should be simpler & faster than string_as_array() because the latter + // is guaranteed to return NULL when *s is empty, so it has to check for that. return &(*s)[0]; } @@ -406,6 +408,6 @@ inline std::pair as_string_data(std::string* s) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc index 5930710..d4e5b54 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +++ b/libs/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc @@ -61,22 +61,21 @@ #include #include -#include -#include "google/protobuf/testing/file.h" -#include "google/protobuf/test_util2.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include +#include +#include #if HAVE_ZLIB -#include "google/protobuf/io/gzip_stream.h" +#include #endif -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include #include namespace google { @@ -140,7 +139,7 @@ class IoTest : public testing::Test { }; const int IoTest::kBlockSizes[] = {-1, 1, 2, 5, 7, 10, 23, 64}; -const int IoTest::kBlockSizeCount = ABSL_ARRAYSIZE(IoTest::kBlockSizes); +const int IoTest::kBlockSizeCount = GOOGLE_ARRAYSIZE(IoTest::kBlockSizes); bool IoTest::WriteToOutput(ZeroCopyOutputStream* output, const void* data, int size) { @@ -571,7 +570,7 @@ TEST_F(IoTest, CompressionOptions) { // Some ad-hoc testing of compression options. std::string golden_filename = - TestUtil::GetTestDataPath("third_party/protobuf/testdata/golden_message"); + TestUtil::GetTestDataPath("net/proto2/internal/testdata/golden_message"); std::string golden; GOOGLE_CHECK_OK(File::GetContents(golden_filename, &golden, true)); @@ -720,9 +719,6 @@ TEST_F(IoTest, StringIo) { // Verifies that outputs up to kint32max can be created. TEST_F(IoTest, LargeOutput) { - // Filter out this test on 32-bit architectures and tsan builds. - if(sizeof(void*) < 8) return; -#ifndef THREAD_SANITIZER std::string str; StringOutputStream output(&str); void* unused_data; @@ -734,7 +730,6 @@ TEST_F(IoTest, LargeOutput) { // Further increases should be possible. output.Next(&unused_data, &size); EXPECT_GT(size, 0); -#endif // THREAD_SANITIZER } @@ -1029,7 +1024,7 @@ TEST_F(IoTest, ConcatenatingInputStream) { &input5, &input6, &input7}; // Create the concatenating stream and read. - ConcatenatingInputStream input(streams, ABSL_ARRAYSIZE(streams)); + ConcatenatingInputStream input(streams, GOOGLE_ARRAYSIZE(streams)); ReadStuff(&input); } @@ -1057,7 +1052,7 @@ TEST_F(IoTest, LimitingInputStream) { TEST_F(IoTest, LimitingInputStreamByteCount) { const int kHalfBufferSize = 128; const int kBufferSize = kHalfBufferSize * 2; - uint8 buffer[kBufferSize] = {}; + uint8 buffer[kBufferSize]; // Set up input. Only allow half to be read at once. ArrayInputStream array_input(buffer, kBufferSize, kHalfBufferSize); diff --git a/libs/protobuf/src/google/protobuf/json/BUILD.bazel b/libs/protobuf/src/google/protobuf/json/BUILD.bazel deleted file mode 100644 index 15e90c4..0000000 --- a/libs/protobuf/src/google/protobuf/json/BUILD.bazel +++ /dev/null @@ -1,268 +0,0 @@ -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("//build_defs:cpp_opts.bzl", "COPTS") - -package(default_visibility = [ - "//src/google/protobuf/json:__pkg__", - "//pkg:__pkg__", -]) - -licenses(["notice"]) - -cc_library( - name = "json", - srcs = ["json.cc"], - hdrs = ["json.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//visibility:public"], - deps = [ - ":parser", - ":unparser", - "//src/google/protobuf", - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "//src/google/protobuf/io:zero_copy_sink", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/base", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "json_test", - srcs = ["json_test.cc"], - copts = COPTS, - deps = [ - ":json", - "//src/google/protobuf", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "//src/google/protobuf/util:json_format_cc_proto", - "//src/google/protobuf/util:json_format_proto3_cc_proto", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/flags:flag", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "test_input_stream", - testonly = True, - hdrs = ["internal/test_input_stream.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//visibility:private"], - deps = [ - "//src/google/protobuf/io", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "zero_copy_buffered_stream", - srcs = ["internal/zero_copy_buffered_stream.cc"], - hdrs = ["internal/zero_copy_buffered_stream.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "@com_google_absl//absl/algorithm:container", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - ], -) - -cc_test( - name = "zero_copy_buffered_stream_test", - srcs = ["internal/zero_copy_buffered_stream_test.cc"], - copts = COPTS, - deps = [ - ":test_input_stream", - ":zero_copy_buffered_stream", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "untyped_message", - srcs = ["internal/untyped_message.cc"], - hdrs = ["internal/untyped_message.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - "//src/google/protobuf", - "//src/google/protobuf:port_def", - "//src/google/protobuf:protobuf_lite", - "//src/google/protobuf/io", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:span", - "@com_google_absl//absl/types:variant", - ], -) - -cc_library( - name = "lexer", - srcs = ["internal/lexer.cc"], - hdrs = ["internal/lexer.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - ":message_path", - ":zero_copy_buffered_stream", - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "@com_google_absl//absl/algorithm:container", - "@com_google_absl//absl/numeric:bits", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - ], -) - -cc_test( - name = "lexer_test", - srcs = ["internal/lexer_test.cc"], - copts = COPTS, - deps = [ - ":lexer", - ":test_input_stream", - "//src/google/protobuf/io", - "@com_google_absl//absl/algorithm:container", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:variant", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "writer", - srcs = ["internal/writer.cc"], - hdrs = ["internal/writer.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "//src/google/protobuf/io:zero_copy_sink", - "@com_google_absl//absl/algorithm:container", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - ], -) - -cc_library( - name = "descriptor_traits", - hdrs = ["internal/descriptor_traits.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - ":lexer", - ":untyped_message", - "//src/google/protobuf", - "//src/google/protobuf:port_def", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/algorithm:container", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:optional", - ], -) - -cc_library( - name = "parser", - srcs = [ - "internal/parser.cc", - ], - hdrs = [ - "internal/parser.h", - "internal/parser_traits.h", - ], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - ":descriptor_traits", - ":lexer", - "//src/google/protobuf", - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "//src/google/protobuf/io:zero_copy_sink", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/base", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:span", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "unparser", - srcs = [ - "internal/unparser.cc", - ], - hdrs = [ - "internal/unparser.h", - "internal/unparser_traits.h", - ], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - ":descriptor_traits", - ":untyped_message", - ":writer", - "//src/google/protobuf", - "//src/google/protobuf:port_def", - "//src/google/protobuf/io", - "//src/google/protobuf/util:type_resolver_util", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", - "@com_google_absl//absl/types:optional", - "@com_google_absl//absl/types:variant", - ], -) - -cc_library( - name = "message_path", - srcs = ["internal/message_path.cc"], - hdrs = ["internal/message_path.h"], - copts = COPTS, - strip_include_prefix = "/src", - deps = [ - "//src/google/protobuf", - "@com_google_absl//absl/cleanup", - "@com_google_absl//absl/strings", - ], -) diff --git a/libs/protobuf/src/google/protobuf/json/internal/descriptor_traits.h b/libs/protobuf/src/google/protobuf/json/internal/descriptor_traits.h deleted file mode 100644 index 2d08f3a..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/descriptor_traits.h +++ /dev/null @@ -1,513 +0,0 @@ -// 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_JSON_INTERNAL_DESCRIPTOR_TRAITS_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_DESCRIPTOR_TRAITS_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "absl/algorithm/container.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/match.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "google/protobuf/json/internal/lexer.h" -#include "google/protobuf/json/internal/untyped_message.h" -#include "google/protobuf/stubs/status_macros.h" - - -// Must be included last. -#include "google/protobuf/port_def.inc" - -// Traits for working with descriptor.proto and type.proto generically. - -namespace google { -namespace protobuf { -namespace json_internal { -enum class MessageType { - kNotWellKnown, - kAny, - kWrapper, - kStruct, - kList, - kValue, - kNull, - kTimestamp, - kDuration, - kFieldMask, -}; - -inline MessageType ClassifyMessage(absl::string_view name) { - constexpr absl::string_view kWellKnownPkg = "google.protobuf."; - if (!absl::StartsWith(name, kWellKnownPkg)) { - return MessageType::kNotWellKnown; - } - name = name.substr(kWellKnownPkg.size()); - - switch (name.size()) { - case 3: - if (name == "Any") { - return MessageType::kAny; - } - break; - case 5: - if (name == "Value") { - return MessageType::kValue; - } - break; - case 6: - if (name == "Struct") { - return MessageType::kStruct; - } - break; - case 8: - if (name == "Duration") { - return MessageType::kDuration; - } - break; - case 9: - if (name == "BoolValue") { - return MessageType::kWrapper; - } - if (name == "NullValue") { - return MessageType::kNull; - } - if (name == "ListValue") { - return MessageType::kList; - } - if (name == "Timestamp") { - return MessageType::kTimestamp; - } - if (name == "FieldMask") { - return MessageType::kFieldMask; - } - break; - case 10: - if (name == "BytesValue" || name == "FloatValue" || - name == "Int32Value" || name == "Int64Value") { - return MessageType::kWrapper; - } - break; - case 11: - if (name == "DoubleValue" || name == "StringValue" || - name == "UInt32Value" || name == "UInt64Value") { - return MessageType::kWrapper; - } - break; - default: - break; - } - - return MessageType::kNotWellKnown; -} - -// Helper alias templates to avoid needing to write `typename` in function -// signatures. -template -using Field = typename Traits::Field; -template -using Desc = typename Traits::Desc; - -// Traits for proto2-ish descriptors. -struct Proto2Descriptor { - // A descriptor for introspecting the fields of a message type. - // - // Desc needs to be handled through a const Desc& in most (but not - // all, in the case of ResolverTraits) cases, so we do not include the const* - // annotation on this type. - using Desc = Descriptor; - - // A field descriptor for introspecting a single field. - // - // Field is always copyable, so this can be a pointer directly. - using Field = const FieldDescriptor*; - - /// Functions for working with descriptors. /// - - static absl::string_view TypeName(const Desc& d) { return d.full_name(); } - - static absl::optional FieldByNumber(const Desc& d, int32_t number) { - if (const auto* field = d.FindFieldByNumber(number)) { - return field; - } - return absl::nullopt; - } - - static Field MustHaveField(const Desc& d, int32_t number, - JsonLocation::SourceLocation loc = - JsonLocation::SourceLocation::current()) { - auto f = FieldByNumber(d, number); - if (!f.has_value()) { - GOOGLE_LOG(FATAL) - << absl::StrFormat( - "%s has, by definition, a field numbered %d, but it could not " - "be " - "looked up; this is a bug", - TypeName(d), number); - } - return *f; - } - - static absl::optional FieldByName(const Desc& d, - absl::string_view name) { - if (const auto* field = d.FindFieldByCamelcaseName(name)) { - return field; - } - - if (const auto* field = d.FindFieldByName(name)) { - return field; - } - - for (int i = 0; i < d.field_count(); ++i) { - const auto* field = d.field(i); - if (field->has_json_name() && field->json_name() == name) { - return field; - } - } - - return absl::nullopt; - } - - static Field KeyField(const Desc& d) { return d.map_key(); } - - static Field ValueField(const Desc& d) { return d.map_value(); } - - static size_t FieldCount(const Desc& d) { return d.field_count(); } - - static Field FieldByIndex(const Desc& d, size_t idx) { return d.field(idx); } - - static absl::optional ExtensionByName(const Desc& d, - absl::string_view name) { - auto* field = d.file()->pool()->FindExtensionByName(name); - if (field == nullptr) { - return absl::nullopt; - } - return field; - } - - /// Functions for introspecting fields. /// - - static absl::string_view FieldName(Field f) { return f->name(); } - static absl::string_view FieldJsonName(Field f) { - return f->has_json_name() ? f->json_name() : f->camelcase_name(); - } - static absl::string_view FieldFullName(Field f) { return f->full_name(); } - - static absl::string_view FieldTypeName(Field f) { - if (f->type() == FieldDescriptor::TYPE_MESSAGE) { - return f->message_type()->full_name(); - } - if (f->type() == FieldDescriptor::TYPE_ENUM) { - return f->enum_type()->full_name(); - } - return ""; - } - - static FieldDescriptor::Type FieldType(Field f) { return f->type(); } - - static int32_t FieldNumber(Field f) { return f->number(); } - - static bool Is32Bit(Field f) { - switch (f->cpp_type()) { - case FieldDescriptor::CPPTYPE_UINT32: - case FieldDescriptor::CPPTYPE_INT32: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_FLOAT: - return true; - default: - return false; - } - } - - static const Desc& ContainingType(Field f) { return *f->containing_type(); } - - static bool IsMap(Field f) { return f->is_map(); } - - static bool IsRepeated(Field f) { return f->is_repeated(); } - - static bool IsOptional(Field f) { return f->has_presence(); } - - static bool IsExtension(Field f) { return f->is_extension(); } - - static bool IsOneof(Field f) { return f->containing_oneof() != nullptr; } - - static absl::StatusOr EnumNumberByName(Field f, - absl::string_view name, - bool case_insensitive) { - if (case_insensitive) { - for (int i = 0; i < f->enum_type()->value_count(); ++i) { - const auto* ev = f->enum_type()->value(i); - if (absl::EqualsIgnoreCase(name, ev->name())) { - return ev->number(); - } - } - return absl::InvalidArgumentError( - absl::StrFormat("unknown enum value: '%s'", name)); - } - - if (const auto* ev = f->enum_type()->FindValueByName(name)) { - return ev->number(); - } - - return absl::InvalidArgumentError( - absl::StrFormat("unknown enum value: '%s'", name)); - } - - static absl::StatusOr EnumNameByNumber(Field f, int32_t number) { - if (const auto* ev = f->enum_type()->FindValueByNumber(number)) { - return ev->name(); - } - return absl::InvalidArgumentError( - absl::StrFormat("unknown enum number: '%d'", number)); - } - - // Looks up the corresponding Desc for `f`'s type, if there is one, and - // calls `body` with it. - // - // This needs to have this funny callback API since whether or not the - // Descriptor equivalent is an owning type depends on the trait. - template - static absl::Status WithFieldType(Field f, F body) { - return body(*f->message_type()); - } - - // Like WithFieldType, but using dynamic lookup by type URL. - template - static absl::Status WithDynamicType(const Desc& desc, - const std::string& type_url, F body) { - size_t slash = type_url.rfind('/'); - if (slash == absl::string_view::npos || slash == 0) { - return absl::InvalidArgumentError(absl::StrCat( - "@type must contain at least one / and a nonempty host; got: ", - type_url)); - } - absl::string_view type_name(type_url); - type_name = type_name.substr(slash + 1); - - const Descriptor* dyn_desc = - desc.file()->pool()->FindMessageTypeByName(type_name); - if (dyn_desc == nullptr) { - return absl::InvalidArgumentError( - absl::StrFormat("could not find @type '%s'", type_url)); - } - - return body(*dyn_desc); - } -}; - -// Traits for proto3-ish deserialization. -// -// See Proto2Descriptor for API docs. -struct Proto3Type { - using Desc = ResolverPool::Message; - using Field = const ResolverPool::Field*; - - /// Functions for working with descriptors. /// - static absl::string_view TypeName(const Desc& d) { return d.proto().name(); } - - static absl::optional FieldByNumber(const Desc& d, int32_t number) { - const auto* f = d.FindField(number); - return f == nullptr ? absl::nullopt : absl::make_optional(f); - } - - static Field MustHaveField(const Desc& d, int32_t number, - JsonLocation::SourceLocation loc = - JsonLocation::SourceLocation::current()) { - auto f = FieldByNumber(d, number); - if (!f.has_value()) { - GOOGLE_LOG(FATAL) - << absl::StrFormat( - "%s has, by definition, a field numbered %d, but it could not " - "be " - "looked up; this is a bug", - TypeName(d), number); - } - return *f; - } - - static absl::optional FieldByName(const Desc& d, - absl::string_view name) { - const auto* f = d.FindField(name); - return f == nullptr ? absl::nullopt : absl::make_optional(f); - } - - static Field KeyField(const Desc& d) { return &d.FieldsByIndex()[0]; } - - static Field ValueField(const Desc& d) { return &d.FieldsByIndex()[1]; } - - static size_t FieldCount(const Desc& d) { return d.proto().fields_size(); } - - static Field FieldByIndex(const Desc& d, size_t idx) { - return &d.FieldsByIndex()[idx]; - } - - static absl::optional ExtensionByName(const Desc& d, - absl::string_view name) { - // type.proto cannot represent extensions, so this function always - // fails. - return absl::nullopt; - } - - /// Functions for introspecting fields. /// - - static absl::string_view FieldName(Field f) { return f->proto().name(); } - static absl::string_view FieldJsonName(Field f) { - return f->proto().json_name(); - } - static absl::string_view FieldFullName(Field f) { return f->proto().name(); } - - static absl::string_view FieldTypeName(Field f) { - absl::string_view url = f->proto().type_url(); - - // If there is no slash, `slash` is string_view::npos, which is guaranteed - // to be -1. - size_t slash = url.rfind('/'); - return url.substr(slash + 1); - } - - static FieldDescriptor::Type FieldType(Field f) { - // The descriptor.proto and type.proto field type enums are required to be - // the same, so we leverage this. - return static_cast(f->proto().kind()); - } - - static int32_t FieldNumber(Field f) { return f->proto().number(); } - - static bool Is32Bit(Field f) { - switch (f->proto().kind()) { - case google::protobuf::Field::TYPE_INT32: - case google::protobuf::Field::TYPE_SINT32: - case google::protobuf::Field::TYPE_UINT32: - case google::protobuf::Field::TYPE_FIXED32: - case google::protobuf::Field::TYPE_SFIXED32: - case google::protobuf::Field::TYPE_FLOAT: - return true; - default: - return false; - } - } - - static const Desc& ContainingType(Field f) { return f->parent(); } - static bool IsMap(Field f) { - if (f->proto().kind() != google::protobuf::Field::TYPE_MESSAGE) { - return false; - } - - bool value = false; - (void)WithFieldType(f, [&value](const Desc& desc) { - value = absl::c_any_of(desc.proto().options(), [&](auto& option) { - return option.name() == "map_entry"; - }); - return absl::OkStatus(); - }); - return value; - } - - static bool IsRepeated(Field f) { - return f->proto().cardinality() == - google::protobuf::Field::CARDINALITY_REPEATED; - } - - static bool IsOptional(Field f) { - return f->proto().cardinality() == - google::protobuf::Field::CARDINALITY_OPTIONAL; - } - - static bool IsExtension(Field f) { return false; } - - static bool IsOneof(Field f) { return f->proto().oneof_index() != 0; } - - static absl::StatusOr EnumNumberByName(Field f, - absl::string_view name, - bool case_insensitive) { - auto e = f->EnumType(); - RETURN_IF_ERROR(e.status()); - - for (const auto& ev : (**e).proto().enumvalue()) { - if (case_insensitive) { - // Two ifs to avoid doing operator== twice if the names are not equal. - if (absl::EqualsIgnoreCase(ev.name(), name)) { - return ev.number(); - } - } else if (ev.name() == name) { - return ev.number(); - } - } - return absl::InvalidArgumentError( - absl::StrFormat("unknown enum value: '%s'", name)); - } - - static absl::StatusOr EnumNameByNumber(Field f, int32_t number) { - auto e = f->EnumType(); - RETURN_IF_ERROR(e.status()); - - for (const auto& ev : (**e).proto().enumvalue()) { - if (ev.number() == number) { - return ev.name(); - } - } - return absl::InvalidArgumentError( - absl::StrFormat("unknown enum number: '%d'", number)); - } - - template - static absl::Status WithFieldType(Field f, F body) { - auto m = f->MessageType(); - RETURN_IF_ERROR(m.status()); - return body(**m); - } - - template - static absl::Status WithDynamicType(const Desc& desc, - const std::string& type_url, F body) { - auto dyn_desc = desc.pool()->FindMessage(type_url); - RETURN_IF_ERROR(dyn_desc.status()); - return body(**dyn_desc); - } -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_DESCRIPTOR_TRAITS_INTERNAL_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/lexer.cc b/libs/protobuf/src/google/protobuf/json/internal/lexer.cc deleted file mode 100644 index 5698eab..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/lexer.cc +++ /dev/null @@ -1,541 +0,0 @@ -// 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/json/internal/lexer.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/algorithm/container.h" -#include "absl/numeric/bits.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/ascii.h" -#include "absl/strings/numbers.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -namespace { -// Randomly inserts bonus whitespace of a few different kinds into a string. -// -// This utility is intended to make error messages hostile to machine -// interpretation as a Hyrum's Law countermeasure, without potentially confusing -// human readers. -void HardenAgainstHyrumsLaw(absl::string_view to_obfuscate, std::string& out) { - // Get some simple randomness from ASLR, which is enabled in most - // environments. Our goal is to be annoying, not secure. - static const void* const kAslrSeed = &kAslrSeed; - // Per-call randomness from a relaxed atomic. - static std::atomic kCounterSeed{0}; - - constexpr uint64_t kA = 0x5851f42d4c957f2dull; - constexpr uint64_t kB = 0x14057b7ef767814full; - - uint64_t state = absl::bit_cast(kAslrSeed) + kB + - kCounterSeed.fetch_add(1, std::memory_order_relaxed); - auto rng = [&state, &kA, &kB] { - state = state * kA + kB; - return absl::rotr(static_cast(((state >> 18) ^ state) >> 27), - state >> 59); - }; - (void)rng(); // Advance state once. - - out.reserve(to_obfuscate.size() + absl::c_count(to_obfuscate, ' ')); - for (char c : to_obfuscate) { - out.push_back(c); - if (c != ' ' || rng() % 3 != 0) { - continue; - } - - size_t count = rng() % 2 + 1; - for (size_t i = 0; i < count; ++i) { - out.push_back(' '); - } - } -} -} // namespace - -constexpr size_t ParseOptions::kDefaultDepth; - -absl::Status JsonLocation::Invalid(absl::string_view message, - SourceLocation sl) const { - // NOTE: we intentionally do not harden the "invalid JSON" part, so that - // people have a hope of grepping for it in logs. That part is easy to - // commit to, as stability goes. - // - // This copies the error twice. Because this is the "unhappy" path, this - // function is cold and can afford the waste. - std::string status_message = "invalid JSON"; - std::string to_obfuscate; - if (path != nullptr) { - absl::StrAppend(&to_obfuscate, " in "); - path->Describe(to_obfuscate); - to_obfuscate.push_back(','); - } - absl::StrAppendFormat(&to_obfuscate, " near %zu:%zu (offset %zu): %s", - line + 1, col + 1, offset, message); - HardenAgainstHyrumsLaw(to_obfuscate, status_message); - - return absl::InvalidArgumentError(std::move(status_message)); -} - -absl::StatusOr JsonLexer::PeekKind() { - RETURN_IF_ERROR(SkipToToken()); - char c = stream_.PeekChar(); - switch (c) { - case '{': - return JsonLexer::kObj; - case '[': - return JsonLexer::kArr; - case '"': - case '\'': - return JsonLexer::kStr; - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return JsonLexer::kNum; - case 't': - return JsonLexer::kTrue; - case 'f': - return JsonLexer::kFalse; - case 'n': - return JsonLexer::kNull; - default: - return Invalid(absl::StrFormat("unexpected character: '%c'", c)); - } -} - -absl::Status JsonLexer::SkipValue() { - absl::StatusOr kind = PeekKind(); - RETURN_IF_ERROR(kind.status()); - - switch (*kind) { - case JsonLexer::kObj: - return VisitObject( - [this](LocationWith&) { return SkipValue(); }); - case JsonLexer::kArr: - return VisitArray([this] { return SkipValue(); }); - case JsonLexer::kStr: - return ParseUtf8().status(); - case JsonLexer::kNum: - return ParseNumber().status(); - case JsonLexer::kTrue: - return Expect("true"); - case JsonLexer::kFalse: - return Expect("false"); - case JsonLexer::kNull: - return Expect("null"); - default: - break; - } - // Some compilers seem to fail to realize this is a basic block - // terminator and incorrectly believe this function is missing - // a return. - GOOGLE_CHECK(false) << "unreachable"; - return absl::OkStatus(); -} - -absl::StatusOr JsonLexer::ParseU16HexCodepoint() { - absl::StatusOr> escape = Take(4); - RETURN_IF_ERROR(escape.status()); - - uint16_t u16 = 0; - for (char c : escape->value.AsView()) { - if (c >= '0' && c <= '9') { - c -= '0'; - } else if (c >= 'a' && c <= 'f') { - c = c - 'a' + 10; - } else if (c >= 'A' && c <= 'F') { - c = c - 'A' + 10; - } else { - return Invalid("invalid Unicode escape"); - } - u16 <<= 4; - u16 |= c; - } - - return u16; -} - -absl::Status JsonLexer::SkipToToken() { - while (true) { - RETURN_IF_ERROR(stream_.BufferAtLeast(1).status()); - switch (stream_.PeekChar()) { - case '\n': - RETURN_IF_ERROR(Advance(1)); - ++json_loc_.line; - json_loc_.col = 0; - break; - case '\r': - case '\t': - case ' ': - RETURN_IF_ERROR(Advance(1)); - break; - default: - return absl::OkStatus(); - } - } -} - -absl::StatusOr> JsonLexer::ParseRawNumber() { - RETURN_IF_ERROR(SkipToToken()); - - enum { kInt, kFraction, kExponent } state = kInt; - char prev_var = 0; - auto number = TakeWhile([state, prev_var](size_t index, char c) mutable { - char prev = prev_var; - prev_var = c; - if (absl::ascii_isdigit(c)) { - return true; - } - - bool last_was_int = absl::ascii_isdigit(prev); - // These checks handle transitions between the integer, fractional, and - // exponent part of a number. This will cut off at the first syntax error. - // Because all numbers must be followed by `,`, `]`, or `}`, we can let - // that catch what's left behind. - if (state == kInt && c == '-') { - return !last_was_int; - } - if (state == kInt && last_was_int && c == '.') { - state = kFraction; - return true; - } - if (state != kExponent && last_was_int && (c == 'e' || c == 'E')) { - state = kExponent; - return true; - } - if ((prev == 'e' || prev == 'E') && (c == '-' || c == '+')) { - return true; - } - - return false; - }); - - RETURN_IF_ERROR(number.status()); - absl::string_view number_text = number->value.AsView(); - - if (number_text.empty() || number_text == "-") { - return number->loc.Invalid("expected a number"); - } - - auto without_minus = - number_text[0] == '-' ? number_text.substr(1) : number_text; - if (without_minus.size() > 1 && without_minus[0] == '0' && - absl::ascii_isdigit(without_minus[1])) { - return number->loc.Invalid("number cannot have extraneous leading zero"); - } - - if (number_text.back() == '.') { - return number->loc.Invalid("number cannot have trailing period"); - } - - double d; - if (!absl::SimpleAtod(number_text, &d) || !std::isfinite(d)) { - return number->loc.Invalid( - absl::StrFormat("invalid number: '%s'", number_text)); - } - - // Find the next token, to make sure we didn't leave something behind we - // shouldn't have. - if (!stream_.AtEof()) { - RETURN_IF_ERROR(SkipToToken()); - switch (stream_.PeekChar()) { - case ',': - case ']': - case '}': - break; - default: - return Invalid( - absl::StrFormat("unexpected character: '%c'", stream_.PeekChar())); - } - } - - return number; -} - -absl::StatusOr> JsonLexer::ParseNumber() { - auto number = ParseRawNumber(); - RETURN_IF_ERROR(number.status()); - - double d; - if (!absl::SimpleAtod(number->value.AsView(), &d) || !std::isfinite(d)) { - return number->loc.Invalid( - absl::StrFormat("invalid number: '%s'", number->value.AsView())); - } - - return LocationWith{d, number->loc}; -} - -absl::StatusOr JsonLexer::ParseUnicodeEscape(char out_utf8[4]) { - auto hex = ParseU16HexCodepoint(); - RETURN_IF_ERROR(hex.status()); - - uint32_t rune = *hex; - if (rune >= 0xd800 && rune <= 0xdbff) { - // Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. - uint32_t high = rune; - - RETURN_IF_ERROR(Expect("\\u")); - auto hex = ParseU16HexCodepoint(); - RETURN_IF_ERROR(hex.status()); - - uint32_t low = *hex; - if (low < 0xdc00 || low > 0xdfff) { - return Invalid("invalid low surrogate"); - } - - rune = (high & 0x3ff) << 10; - rune |= (low & 0x3ff); - rune += 0x10000; - } else if (rune >= 0xdc00 && rune <= 0xdfff) { - return Invalid("unpaired low surrogate"); - } - - // Write as UTF-8. - if (rune <= 0x7f) { - out_utf8[0] = rune; - return 1; - } else if (rune <= 0x07ff) { - out_utf8[0] = ((rune >> 6) & 0x1f) | 0xc0; - out_utf8[1] = ((rune >> 0) & 0x3f) | 0x80; - return 2; - } else if (rune <= 0xffff) { - out_utf8[0] = ((rune >> 12) & 0x0f) | 0xe0; - out_utf8[1] = ((rune >> 6) & 0x3f) | 0x80; - out_utf8[2] = ((rune >> 0) & 0x3f) | 0x80; - return 3; - } else if (rune < 0x10ffff) { - out_utf8[0] = ((rune >> 18) & 0x07) | 0xF0; - out_utf8[1] = ((rune >> 12) & 0x3f) | 0x80; - out_utf8[2] = ((rune >> 6) & 0x3f) | 0x80; - out_utf8[3] = ((rune >> 0) & 0x3f) | 0x80; - return 4; - } else { - return Invalid("invalid codepoint"); - } -} - -static char ParseSimpleEscape(char c, bool allow_legacy_syntax) { - switch (c) { - case '"': - return '"'; - case '\\': - return '\\'; - case '/': - return '/'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case '\'': - if (allow_legacy_syntax) { - return '\''; - } - ABSL_FALLTHROUGH_INTENDED; - default: - return 0; - } -} - -absl::StatusOr> JsonLexer::ParseUtf8() { - RETURN_IF_ERROR(SkipToToken()); - // This is a non-standard extension accepted by the ESF parser that we will - // need to accept for backwards-compat. - bool is_single_quote = stream_.PeekChar() == '\''; - if (!options_.allow_legacy_syntax && is_single_quote) { - return Invalid("expected '\"'"); - } - - JsonLocation loc = json_loc_; - RETURN_IF_ERROR(Expect(is_single_quote ? "'" : "\"")); - - // on_heap is empty if we do not need to heap-allocate the string. - std::string on_heap; - LocationWith mark = BeginMark(); - while (true) { - RETURN_IF_ERROR(stream_.BufferAtLeast(1).status()); - - char c = stream_.PeekChar(); - RETURN_IF_ERROR(Advance(1)); - switch (c) { - case '"': - case '\'': { - if (c != (is_single_quote ? '\'' : '"')) { - goto normal_character; - } - - if (!on_heap.empty()) { - return LocationWith{ - MaybeOwnedString(std::move(on_heap)), loc}; - } - // NOTE: the 1 below clips off the " from the end of the string. - return LocationWith{mark.value.UpToUnread(1), loc}; - } - case '\\': { - if (on_heap.empty()) { - // The 1 skips over the `\`. - on_heap = std::string(mark.value.UpToUnread(1).AsView()); - // Clang-tidy incorrectly notes this as being moved-from multiple - // times, but it can only occur in one loop iteration. The mark is - // destroyed only if we need to handle an escape when on_heap is - // empty. Because this branch unconditionally pushes to on_heap, this - // condition can never be reached in any iteration that follows it. - // This, at most one move every actually occurs. - std::move(mark).value.Discard(); - } - RETURN_IF_ERROR(stream_.BufferAtLeast(1).status()); - - char c = stream_.PeekChar(); - RETURN_IF_ERROR(Advance(1)); - if (c == 'u' || (c == 'U' && options_.allow_legacy_syntax)) { - // Ensure there is actual space to scribble the UTF-8 onto. - on_heap.resize(on_heap.size() + 4); - auto written = ParseUnicodeEscape(&on_heap[on_heap.size() - 4]); - RETURN_IF_ERROR(written.status()); - on_heap.resize(on_heap.size() - 4 + *written); - } else { - char escape = ParseSimpleEscape(c, options_.allow_legacy_syntax); - if (escape == 0) { - return Invalid(absl::StrFormat("invalid escape char: '%c'", c)); - } - on_heap.push_back(escape); - } - break; - } - normal_character: - default: { - uint8_t uc = static_cast(c); - // If people have newlines in their strings, that's their problem; it - // is too difficult to support correctly in our location tracking, and - // is out of spec, so users will get slightly wrong locations in errors. - if ((uc < 0x20 || uc == 0xff) && !options_.allow_legacy_syntax) { - return Invalid(absl::StrFormat( - "invalid control character 0x%02x in string", uc)); - } - - // Verify this is valid UTF-8. UTF-8 is a varint encoding satisfying - // one of the following (big-endian) patterns: - // - // 0b0xxxxxxx - // 0b110xxxxx'10xxxxxx - // 0b1110xxxx'10xxxxxx'10xxxxxx - // 0b11110xxx'10xxxxxx'10xxxxxx'10xxxxxx - // - // We don't need to decode it; just validate it. - size_t lookahead = 0; - switch (absl::countl_one(uc)) { - case 0: - break; - case 2: - lookahead = 1; - break; - case 3: - lookahead = 2; - break; - case 4: - lookahead = 3; - break; - default: - return Invalid("invalid UTF-8 in string"); - } - - if (!on_heap.empty()) { - on_heap.push_back(c); - } - for (int i = 0; i < lookahead; ++i) { - RETURN_IF_ERROR(stream_.BufferAtLeast(1).status()); - uint8_t uc = static_cast(stream_.PeekChar()); - if ((uc >> 6) != 2) { - return Invalid("invalid UTF-8 in string"); - } - if (!on_heap.empty()) { - on_heap.push_back(stream_.PeekChar()); - } - RETURN_IF_ERROR(Advance(1)); - } - break; - } - } - } - - return Invalid("EOF inside string"); -} - -absl::StatusOr> JsonLexer::ParseBareWord() { - RETURN_IF_ERROR(SkipToToken()); - auto ident = TakeWhile( - [](size_t, char c) { return c == '_' || absl::ascii_isalnum(c); }); - RETURN_IF_ERROR(ident.status()); - absl::string_view text = ident->value.AsView(); - - if (text.empty() || absl::ascii_isdigit(text[0]) || text == "null" || - text == "true" || text == "false") { - return ident->loc.Invalid("expected bare word"); - } - return ident; -} - -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/lexer.h b/libs/protobuf/src/google/protobuf/json/internal/lexer.h deleted file mode 100644 index a4631cc..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/lexer.h +++ /dev/null @@ -1,361 +0,0 @@ -// 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. - -// Internal JSON tokenization utilities; not public API. -#ifndef GOOGLE_PROTOBUF_JSON_INTERNAL_LEXER_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_LEXER_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/match.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/json/internal/message_path.h" -#include "google/protobuf/json/internal/zero_copy_buffered_stream.h" -#include "google/protobuf/stubs/status_macros.h" - - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -// This is a duplicate of JsonParseOptions from json_util.h; it must be -// re-defined here so that :json_lexer does not need to depend on :json_util. -struct ParseOptions { - bool ignore_unknown_fields = false; - bool case_insensitive_enum_parsing = false; - - static constexpr size_t kDefaultDepth = 100; - - // The number of times we may recurse before bailing out on the grounds of - // avoiding pathological input. - int recursion_depth = kDefaultDepth; - - // The original parser used by json_util2 accepted a number of non-standard - // options. Setting this flag enables them. - // - // What those extensions were is explicitly not documented, beyond what exists - // in the unit tests; we intend to remove this setting eventually. See - // b/234868512. - bool allow_legacy_syntax = false; -}; - -// A position in JSON input, for error context. -struct JsonLocation { - // This type exists to work around an absl type that has not yet been - // released. - struct SourceLocation { - static SourceLocation current() { return {}; } - }; - - // Line and column are both zero-indexed in-memory. - size_t offset = 0; - size_t line = 0; - size_t col = 0; - const MessagePath* path = nullptr; - - // Creates an absl::InvalidArgumentError with line/column information. - absl::Status Invalid(absl::string_view message, - SourceLocation sl = SourceLocation::current()) const; -}; - -template -struct LocationWith { - T value; - JsonLocation loc; -}; - -class JsonLexer { - public: - // A kind of token that PeekKind() can detect. - enum Kind { - kObj, - kArr, - kStr, - kNum, - kTrue, - kFalse, - kNull, - }; - - using SourceLocation = JsonLocation::SourceLocation; - - JsonLexer(io::ZeroCopyInputStream* stream, const ParseOptions& options, - MessagePath* path = nullptr, JsonLocation start = {}) - : stream_(stream), options_(options), json_loc_(start), path_(path) { - json_loc_.path = path_; - } - - const ParseOptions& options() const { return options_; } - - const MessagePath& path() const { return *path_; } - MessagePath& path() { return *path_; } - - // Creates an absl::InvalidArgumentError with line/column information. - absl::Status Invalid(absl::string_view message, - SourceLocation sl = SourceLocation::current()) { - return json_loc_.Invalid(message, sl); - } - - // Expects the next bytes to be parsed (after consuming whitespace) to be - // exactly `literal`. If they are, consumes them; otherwise returns an error. - absl::Status Expect(absl::string_view literal, - SourceLocation sl = SourceLocation::current()) { - RETURN_IF_ERROR(SkipToToken()); - auto buffering = stream_.BufferAtLeast(literal.size()); - RETURN_IF_ERROR(buffering.status()); - - if (!absl::StartsWith(stream_.Unread(), literal)) { - return Invalid( - absl::StrFormat("unexpected character: '%c'; expected '%s'", - stream_.PeekChar(), literal), - sl); - } - - return Advance(literal.size()); - } - - // Like Expect(), but returns a boolean. This makes it clear that the - // lookahead is failible. - bool Peek(absl::string_view literal) { - // Suppress the error; this can only fail on EOF in which case we would - // return false regardless. - (void)SkipToToken(); - auto ignored = stream_.BufferAtLeast(literal.size()); - if (!absl::StartsWith(stream_.Unread(), literal)) { - return false; - } - - // We just ensured we had enough buffered so we can suppress this error. - (void)Advance(literal.size()); - return true; - } - - // Like Peek(string), but returns true if and only if a token of the given - // kind can be lexed next. Returns false on EOF, just like Peek(string). - bool Peek(Kind needle) { - auto kind = PeekKind(); - return kind.ok() && *kind == needle; - } - - // Consumes all whitespace and other ignored characters until the next - // token. - // - // This function returns an error on EOF, so PeekChar() can be safely - // called if it returns ok. - absl::Status SkipToToken(); - - // Returns which kind of value token (i.e., something that can occur after - // a `:`) is next up to be parsed. - absl::StatusOr PeekKind(); - - // Parses a JSON number. - absl::StatusOr> ParseNumber(); - - // Parses a number as a string, without turning it into an integer. - absl::StatusOr> ParseRawNumber(); - - // Parses a UTF-8 string. If the contents of the string happen to actually be - // UTF-8, it will return a zero-copy view; otherwise it will allocate. - absl::StatusOr> ParseUtf8(); - - // Walks over an array, calling `f` each time an element is reached. - // - // `f` should have type `() -> absl::Status`. - template - absl::Status VisitArray(F f); - - // Walks over an object, calling `f` just after parsing each `:`. - // - // `f` should have type `(absl::string_view) -> absl::Status`. - template - absl::Status VisitObject(F f); - - // Parses a single value and discards it. - absl::Status SkipValue(); - - // Forwards of functions from ZeroCopyBufferedStream. - - bool AtEof() { - // Ignore whitespace for the purposes of finding the EOF. This will return - // an error if we hit EOF, so we discard it. - (void)SkipToToken(); - return stream_.AtEof(); - } - - absl::StatusOr> Take(size_t len) { - JsonLocation loc = json_loc_; - auto taken = stream_.Take(len); - RETURN_IF_ERROR(taken.status()); - return LocationWith{*std::move(taken), loc}; - } - - template - absl::StatusOr> TakeWhile(Pred p) { - JsonLocation loc = json_loc_; - auto taken = stream_.TakeWhile(std::move(p)); - RETURN_IF_ERROR(taken.status()); - return LocationWith{*std::move(taken), loc}; - } - - LocationWith BeginMark() { return {stream_.BeginMark(), json_loc_}; } - - private: - friend BufferingGuard; - friend Mark; - friend MaybeOwnedString; - - absl::Status Push() { - if (options_.recursion_depth == 0) { - return Invalid("JSON content was too deeply nested"); - } - --options_.recursion_depth; - return absl::OkStatus(); - } - - void Pop() { ++options_.recursion_depth; } - - // Parses the next four bytes as a 16-bit hex numeral. - absl::StatusOr ParseU16HexCodepoint(); - - // Parses a Unicode escape (\uXXXX); this may be a surrogate pair, so it may - // consume the character that follows. Both are encoded as utf8 into - // `out_utf8`; returns the number of bytes written. - absl::StatusOr ParseUnicodeEscape(char out_utf8[4]); - - // Parses an alphanumeric "identifier", for use with the non-standard - // "unquoted keys" extension. - absl::StatusOr> ParseBareWord(); - - absl::Status Advance(size_t bytes) { - RETURN_IF_ERROR(stream_.Advance(bytes)); - json_loc_.offset += static_cast(bytes); - json_loc_.col += static_cast(bytes); - return absl::OkStatus(); - } - - ZeroCopyBufferedStream stream_; - - ParseOptions options_; - JsonLocation json_loc_; - MessagePath* path_; -}; - -template -absl::Status JsonLexer::VisitArray(F f) { - RETURN_IF_ERROR(Expect("[")); - RETURN_IF_ERROR(Push()); - - if (Peek("]")) { - Pop(); - return absl::OkStatus(); - } - - bool has_comma = true; - do { - if (!has_comma) { - return Invalid("expected ','"); - } - RETURN_IF_ERROR(f()); - has_comma = Peek(","); - } while (!Peek("]")); - - if (!options_.allow_legacy_syntax && has_comma) { - return Invalid("expected ']'"); - } - - Pop(); - return absl::OkStatus(); -} - -// Walks over an object, calling `f` just after parsing each `:`. -// -// `f` should have type `(MaybeOwnedString&) -> absl::Status`. -template -absl::Status JsonLexer::VisitObject(F f) { - RETURN_IF_ERROR(Expect("{")); - RETURN_IF_ERROR(Push()); - - if (Peek("}")) { - Pop(); - return absl::OkStatus(); - } - - bool has_comma = true; - do { - if (!has_comma) { - return Invalid("expected ','"); - } - RETURN_IF_ERROR(SkipToToken()); - - absl::StatusOr> key; - if (stream_.PeekChar() == '"' || stream_.PeekChar() == '\'') { - key = ParseUtf8(); - } else if (options_.allow_legacy_syntax) { - key = ParseBareWord(); - } else { - return Invalid("expected '\"'"); - } - - RETURN_IF_ERROR(key.status()); - RETURN_IF_ERROR(Expect(":")); - RETURN_IF_ERROR(f(*key)); - has_comma = Peek(","); - } while (!Peek("}")); - Pop(); - - if (!options_.allow_legacy_syntax && has_comma) { - return Invalid("expected '}'"); - } - - return absl::OkStatus(); -} -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_LEXER_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/lexer_test.cc b/libs/protobuf/src/google/protobuf/json/internal/lexer_test.cc deleted file mode 100644 index 92a6f3a..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/lexer_test.cc +++ /dev/null @@ -1,740 +0,0 @@ -// 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/json/internal/lexer.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include -#include -#include "absl/algorithm/container.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/string_view.h" -#include "absl/types/variant.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/json/internal/test_input_stream.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -namespace { -using ::testing::_; -using ::testing::ElementsAre; -using ::testing::Field; -using ::testing::HasSubstr; -using ::testing::IsEmpty; -using ::testing::Pair; -using ::testing::SizeIs; -using ::testing::VariantWith; - -// TODO(b/234474291): Use the gtest versions once that's available in OSS. -MATCHER_P(IsOkAndHolds, inner, - absl::StrCat("is OK and holds ", testing::PrintToString(inner))) { - if (!arg.ok()) { - *result_listener << arg.status(); - return false; - } - return testing::ExplainMatchResult(inner, *arg, result_listener); -} - -// absl::Status GetStatus(const absl::Status& s) { return s; } -template -absl::Status GetStatus(const absl::StatusOr& s) { - return s.status(); -} - -MATCHER_P(StatusIs, status, - absl::StrCat(".status() is ", testing::PrintToString(status))) { - return GetStatus(arg).code() == status; -} - -#define EXPECT_OK(x) EXPECT_THAT(x, StatusIs(absl::StatusCode::kOk)) -#define ASSERT_OK(x) ASSERT_THAT(x, StatusIs(absl::StatusCode::kOk)) - -// TODO(b/234868512): There are several tests that validate non-standard -// behavior that is assumed to be present in the wild due to Hyrum's Law. These -// tests are grouped under the `NonStandard` suite. These tests ensure the -// non-standard syntax is accepted, and that disabling legacy mode rejects them. -// -// All other tests are strictly-conforming. - -// A generic JSON value, which is gtest-matcher friendly and stream-printable. -struct Value { - static absl::StatusOr Parse(io::ZeroCopyInputStream* stream, - ParseOptions options = {}) { - JsonLexer lex(stream, options); - return Parse(lex); - } - static absl::StatusOr Parse(JsonLexer& lex) { - absl::StatusOr kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - - switch (*kind) { - case JsonLexer::kNull: - RETURN_IF_ERROR(lex.Expect("null")); - return Value{Null{}}; - case JsonLexer::kFalse: - RETURN_IF_ERROR(lex.Expect("false")); - return Value{false}; - case JsonLexer::kTrue: - RETURN_IF_ERROR(lex.Expect("true")); - return Value{true}; - case JsonLexer::kNum: { - absl::StatusOr> num = lex.ParseNumber(); - RETURN_IF_ERROR(num.status()); - return Value{num->value}; - } - case JsonLexer::kStr: { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - return Value{str->value.ToString()}; - } - case JsonLexer::kArr: { - std::vector arr; - absl::Status s = lex.VisitArray([&arr, &lex]() -> absl::Status { - absl::StatusOr val = Value::Parse(lex); - RETURN_IF_ERROR(val.status()); - arr.emplace_back(*std::move(val)); - return absl::OkStatus(); - }); - RETURN_IF_ERROR(s); - return Value{std::move(arr)}; - } - case JsonLexer::kObj: { - std::vector> obj; - absl::Status s = lex.VisitObject( - [&obj, &lex](LocationWith& key) -> absl::Status { - absl::StatusOr val = Value::Parse(lex); - RETURN_IF_ERROR(val.status()); - obj.emplace_back(std::move(key.value.ToString()), - *std::move(val)); - return absl::OkStatus(); - }); - RETURN_IF_ERROR(s); - return Value{std::move(obj)}; - } - } - } - - friend std::ostream& operator<<(std::ostream& os, const Value& v) { - if (absl::holds_alternative(v.value)) { - os << "null"; - } else if (const auto* x = absl::get_if(&v.value)) { - os << "bool:" << (*x ? "true" : "false"); - } else if (const auto* x = absl::get_if(&v.value)) { - os << "num:" << *x; - } else if (const auto* x = absl::get_if(&v.value)) { - os << "str:" << absl::CHexEscape(*x); - } else if (const auto* x = absl::get_if(&v.value)) { - os << "arr:["; - bool first = true; - for (const auto& val : *x) { - if (!first) { - os << ", "; - } - os << val; - } - os << "]"; - } else if (const auto* x = absl::get_if(&v.value)) { - os << "obj:["; - bool first = true; - for (const auto& kv : *x) { - if (!first) { - os << ", "; - first = false; - } - os << kv.first << ":" << kv.second; - } - os << "]"; - } - return os; - } - - struct Null {}; - using Array = std::vector; - using Object = std::vector>; - absl::variant value; -}; - -template -testing::Matcher ValueIs(M inner) { - return Field(&Value::value, VariantWith(inner)); -} - -// Executes `test` once for each three-segment split of `json`. -void Do(absl::string_view json, - std::function test, - bool verify_all_consumed = true) { - SCOPED_TRACE(absl::StrCat("json: ", absl::CHexEscape(json))); - - for (size_t i = 0; i < json.size(); ++i) { - for (size_t j = 0; j < json.size() - i + 1; ++j) { - SCOPED_TRACE(absl::StrFormat("json[0:%d], json[%d:%d], json[%d:%d]", i, i, - i + j, i + j, json.size())); - std::string first(json.substr(0, i)); - std::string second(json.substr(i, j)); - std::string third(json.substr(i + j)); - - TestInputStream in = {first, second, third}; - test(&in); - if (testing::Test::HasFailure()) { - return; - } - - if (verify_all_consumed) { - if (!absl::c_all_of(third, - [](char c) { return absl::ascii_isspace(c); })) { - ASSERT_GE(in.Consumed(), 3); - } else if (!absl::c_all_of( - second, [](char c) { return absl::ascii_isspace(c); })) { - ASSERT_GE(in.Consumed(), 2); - } else { - ASSERT_GE(in.Consumed(), 1); - } - } - } - } -} - -void BadInner(absl::string_view json, ParseOptions opts = {}) { - Do( - json, - [=](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream, opts), - StatusIs(absl::StatusCode::kInvalidArgument)); - }, - false); -} - -// Like Do, but runs a legacy syntax test twice: once with legacy settings, once -// without. For the latter, the test is expected to fail; for the former, -// `test` is called so it can run expectations. -void DoLegacy(absl::string_view json, std::function test) { - Do(json, [&](io::ZeroCopyInputStream* stream) { - ParseOptions options; - options.allow_legacy_syntax = true; - auto value = Value::Parse(stream, options); - ASSERT_OK(value); - test(*value); - }); - BadInner(json); -} - -// Like Bad, but ensures json fails to parse in both modes. -void Bad(absl::string_view json) { - ParseOptions options; - options.allow_legacy_syntax = true; - BadInner(json, options); - BadInner(json); -} - -TEST(LexerTest, Null) { - Do("null", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), IsOkAndHolds(ValueIs(_))); - }); -} - -TEST(LexerTest, False) { - Do("false", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), IsOkAndHolds(ValueIs(false))); - }); -} - -TEST(LexerTest, True) { - Do("true", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), IsOkAndHolds(ValueIs(true))); - }); -} - -TEST(LexerTest, Typos) { - Bad("-"); - Bad("-foo"); - Bad("nule"); -} - -TEST(LexerTest, UnknownCharacters) { - Bad("*"); - Bad("[*]"); - Bad("{key: *}"); -} - -TEST(LexerTest, EmptyString) { - Do(R"json("")json", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(IsEmpty()))); - }); -} - -TEST(LexerTest, SimpleString) { - Do(R"json("My String")json", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs("My String"))); - }); -} - -TEST(NonStandard, SingleQuoteString) { - DoLegacy(R"json('My String')json", [=](const Value& value) { - EXPECT_THAT(value, ValueIs("My String")); - }); -} - -TEST(NonStandard, ControlCharsInString) { - DoLegacy("\"\1\2\3\4\5\6\7\b\n\f\r\"", [=](const Value& value) { - EXPECT_THAT(value, ValueIs("\1\2\3\4\5\6\7\b\n\f\r")); - }); -} - -TEST(LexerTest, Latin) { - Do(R"json("Pokémon")json", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs("Pokémon"))); - }); -} - -TEST(LexerTest, Cjk) { - Do(R"json("施氏食獅史")json", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs("施氏食獅史"))); - }); -} - -TEST(LexerTest, BrokenString) { - Bad(R"json("broken)json"); - Bad(R"json("broken')json"); - Bad(R"json("broken\")json"); -} - -TEST(NonStandard, BrokenString) { - Bad(R"json('broken)json"); - Bad(R"json('broken")json"); -} - -TEST(LexerTest, BrokenEscape) { - Bad(R"json("\)json"); - Bad(R"json("\a")json"); - Bad(R"json("\u")json"); - Bad(R"json("\u123")json"); - Bad(R"json("\u{1f36f}")json"); - Bad(R"json("\u123$$$")json"); - Bad(R"json("\ud800\udcfg")json"); -} - -void GoodNumber(absl::string_view json, double value) { - Do(json, [value](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), IsOkAndHolds(ValueIs(value))); - }); -} - -TEST(LexerTest, Zero) { - GoodNumber("0", 0); - GoodNumber("0.0", 0); - GoodNumber("0.000", 0); - GoodNumber("-0", -0.0); - GoodNumber("-0.0", -0.0); - - Bad("00"); - Bad("-00"); -} - -TEST(LexerTest, Integer) { - GoodNumber("123456", 123456); - GoodNumber("-79497823553162768", -79497823553162768); - GoodNumber("11779497823553163264", 11779497823553163264u); - - Bad("0777"); -} - -TEST(LexerTest, Overflow) { - GoodNumber("18446744073709551616", 18446744073709552000.0); - GoodNumber("-18446744073709551616", -18446744073709551616.0); - - Bad("1.89769e308"); - Bad("-1.89769e308"); -} - -TEST(LexerTest, Double) { - GoodNumber("42.5", 42.5); - GoodNumber("42.50", 42.50); - GoodNumber("-1045.235", -1045.235); - GoodNumber("-0.235", -0.235); - - Bad("42."); - Bad("01.3"); - Bad(".5"); - Bad("-.5"); -} - -TEST(LexerTest, Scientific) { - GoodNumber("1.2345e+10", 1.2345e+10); - GoodNumber("1.2345e-10", 1.2345e-10); - GoodNumber("1.2345e10", 1.2345e10); - GoodNumber("1.2345E+10", 1.2345e+10); - GoodNumber("1.2345E-10", 1.2345e-10); - GoodNumber("1.2345E10", 1.2345e10); - GoodNumber("0e0", 0); - GoodNumber("9E9", 9e9); - - Bad("1.e5"); - Bad("-e5"); - Bad("1e"); - Bad("1e-"); - Bad("1e+"); -} - -TEST(LexerTest, EmptyArray) { - Do("[]", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(IsEmpty()))); - }); -} - -TEST(LexerTest, PrimitiveArray) { - absl::string_view json = R"json( - [true, false, null, "string"] - )json"; - Do(json, [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(ElementsAre( - ValueIs(true), // - ValueIs(false), // - ValueIs(_), // - ValueIs("string") // - )))); - }); -} - -TEST(LexerTest, BrokenArray) { - Bad("["); - Bad("[["); - Bad("[true, null}"); -} - -TEST(LexerTest, BrokenStringInArray) { Bad(R"json(["Unterminated])json"); } - -TEST(LexerTest, NestedArray) { - absl::string_view json = R"json( - [ - [22, -127, 45.3, -1056.4, 11779497823553162765], - {"key": true} - ] - )json"; - Do(json, [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(ElementsAre( - ValueIs(ElementsAre( - ValueIs(22), // - ValueIs(-127), // - ValueIs(45.3), // - ValueIs(-1056.4), // - ValueIs(11779497823553162765u) // - )), - ValueIs( - ElementsAre(Pair("key", ValueIs(true)))))))); - }); -} - -TEST(LexerTest, EmptyObject) { - Do("{}", [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(IsEmpty()))); - }); -} - -TEST(LexerTest, BrokenObject) { - Bad("{"); - Bad("{{"); - Bad(R"json({"key": true])json"); - Bad(R"json({"key")json"); - Bad(R"json({"key":})json"); -} - -TEST(LexerTest, BrokenStringInObject) { - Bad(R"json({"oops": "Unterminated})json"); -} - -TEST(LexerTest, NonPairInObject) { - Bad("{null}"); - Bad("{true}"); - Bad("{false}"); - Bad("{42}"); - Bad("{[null]}"); - Bad(R"json({{"nest_pas": true}})json"); - Bad(R"json({"missing colon"})json"); -} - -TEST(NonStandard, NonPairInObject) { - Bad("{'missing colon'}"); - Bad("{missing_colon}"); -} - -TEST(LexerTest, WrongCommas) { - Bad("[null null]"); - Bad("[null,, null]"); - Bad(R"json({"a": 0 "b": true})json"); - Bad(R"json({"a": 0,, "b": true})json"); -} - -TEST(NonStandard, Keys) { - DoLegacy(R"json({'s': true})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs( - ElementsAre(Pair("s", ValueIs(true))))); - }); - DoLegacy(R"json({key: null})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs( - ElementsAre(Pair("key", ValueIs(_))))); - }); - DoLegacy(R"json({snake_key: []})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre(Pair( - "snake_key", ValueIs(IsEmpty()))))); - }); - DoLegacy(R"json({camelKey: {}})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre(Pair( - "camelKey", ValueIs(IsEmpty()))))); - }); -} - -TEST(NonStandard, KeywordPrefixedKeys) { - DoLegacy(R"json({nullkey: "a"})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre( - Pair("nullkey", ValueIs("a"))))); - }); - DoLegacy(R"json({truekey: "b"})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre( - Pair("truekey", ValueIs("b"))))); - }); - DoLegacy(R"json({falsekey: "c"})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre( - Pair("falsekey", ValueIs("c"))))); - }); -} - -TEST(LexerTest, BadKeys) { - Bad("{null: 0}"); - Bad("{true: 0}"); - Bad("{false: 0}"); - Bad("{lisp-kebab: 0}"); - Bad("{42: true}"); -} - -TEST(LexerTest, NestedObject) { - absl::string_view json = R"json( - { - "t": true, - "f": false, - "n": null, - "s": "a string", - "pi": 22, - "ni": -127, - "pd": 45.3, - "nd": -1056.4, - "pl": 11779497823553162765, - "l": [ [ ] ], - "o": { "key": true } - } - )json"; - Do(json, [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(ElementsAre( - Pair("t", ValueIs(true)), // - Pair("f", ValueIs(false)), // - Pair("n", ValueIs(_)), // - Pair("s", ValueIs("a string")), // - Pair("pi", ValueIs(22)), // - Pair("ni", ValueIs(-127)), // - Pair("pd", ValueIs(45.3)), // - Pair("nd", ValueIs(-1056.4)), // - Pair("pl", ValueIs(11779497823553162765u)), // - Pair("l", ValueIs(ElementsAre( - ValueIs(IsEmpty())))), // - Pair("o", ValueIs(ElementsAre( - Pair("key", ValueIs(true))))) // - )))); - }); -} - -TEST(LexerTest, RejectNonUtf8) { - absl::string_view json = R"json( - { "address": x"施氏食獅史" } - )json"; - Bad(absl::StrReplaceAll(json, {{"x", "\xff"}})); -} - -TEST(LexerTest, RejectNonUtf8String) { - absl::string_view json = R"json( - { "address": "施氏x食獅史" } - )json"; - Bad(absl::StrReplaceAll(json, {{"x", "\xff"}})); -} - -TEST(LexerTest, RejectNonUtf8Prefix) { Bad("\xff{}"); } - -TEST(LexerTest, SurrogateEscape) { - absl::string_view json = R"json( - [ "\ud83d\udc08\u200D\u2b1B\ud83d\uDdA4" ] - )json"; - Do(json, [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs( - ElementsAre(ValueIs("🐈‍⬛🖤"))))); - }); -} - -TEST(LexerTest, InvalidCodePoint) { Bad(R"json(["\ude36"])json"); } - -TEST(LexerTest, LonelyHighSurrogate) { - Bad(R"json(["\ud83d"])json"); - Bad(R"json(["\ud83d|trailing"])json"); - Bad(R"json(["\ud83d\ude--"])json"); - Bad(R"json(["\ud83d\ud83d"])json"); -} - -TEST(LexerTest, AsciiEscape) { - absl::string_view json = R"json( - ["\b", "\ning", "test\f", "\r\t", "test\\\"\/ing"] - )json"; - Do(json, [](io::ZeroCopyInputStream* stream) { - EXPECT_THAT(Value::Parse(stream), - IsOkAndHolds(ValueIs(ElementsAre( - ValueIs("\b"), // - ValueIs("\ning"), // - ValueIs("test\f"), // - ValueIs("\r\t"), // - ValueIs("test\\\"/ing") // - )))); - }); -} - -TEST(NonStandard, AsciiEscape) { - DoLegacy(R"json(["\'", '\''])json", [](const Value& value) { - EXPECT_THAT(value, - ValueIs(ElementsAre(ValueIs("'"), // - ValueIs("'") // - ))); - }); -} - -TEST(NonStandard, TrailingCommas) { - DoLegacy(R"json({"foo": 42,})json", [](const Value& value) { - EXPECT_THAT(value, ValueIs( - ElementsAre(Pair("foo", ValueIs(42))))); - }); - DoLegacy(R"json({"foo": [42,],})json", [](const Value& value) { - EXPECT_THAT( - value, - ValueIs(ElementsAre(Pair( - "foo", ValueIs(ElementsAre(ValueIs(42))))))); - }); - DoLegacy(R"json([42,])json", [](const Value& value) { - EXPECT_THAT(value, ValueIs(ElementsAre(ValueIs(42)))); - }); - DoLegacy(R"json([{},])json", [](const Value& value) { - EXPECT_THAT(value, ValueIs( - ElementsAre(ValueIs(IsEmpty())))); - }); -} - -// These strings are enormous; so that the test actually finishes in a -// reasonable time, we skip using Do(). - -TEST(LexerTest, ArrayRecursion) { - std::string ok = std::string(ParseOptions::kDefaultDepth, '[') + - std::string(ParseOptions::kDefaultDepth, ']'); - - { - io::ArrayInputStream stream(ok.data(), static_cast(ok.size())); - auto value = Value::Parse(&stream); - ASSERT_OK(value); - - Value* v = &*value; - for (int i = 0; i < ParseOptions::kDefaultDepth - 1; ++i) { - ASSERT_THAT(*v, ValueIs(SizeIs(1))); - v = &absl::get(v->value)[0]; - } - ASSERT_THAT(*v, ValueIs(IsEmpty())); - } - - { - std::string evil = absl::StrFormat("[%s]", ok); - io::ArrayInputStream stream(evil.data(), static_cast(evil.size())); - ASSERT_THAT(Value::Parse(&stream), - StatusIs(absl::StatusCode::kInvalidArgument)); - } -} - -TEST(LexerTest, ObjectRecursion) { - std::string ok; - for (int i = 0; i < ParseOptions::kDefaultDepth - 1; ++i) { - absl::StrAppend(&ok, "{\"k\":"); - } - absl::StrAppend(&ok, "{"); - ok += std::string(ParseOptions::kDefaultDepth, '}'); - - { - io::ArrayInputStream stream(ok.data(), static_cast(ok.size())); - auto value = Value::Parse(&stream); - ASSERT_OK(value); - - Value* v = &*value; - for (int i = 0; i < ParseOptions::kDefaultDepth - 1; ++i) { - ASSERT_THAT(*v, ValueIs(ElementsAre(Pair("k", _)))); - v = &absl::get(v->value)[0].second; - } - ASSERT_THAT(*v, ValueIs(IsEmpty())); - } - { - std::string evil = absl::StrFormat("{\"k\":%s}", ok); - io::ArrayInputStream stream(evil.data(), static_cast(evil.size())); - ASSERT_THAT(Value::Parse(&stream), - StatusIs(absl::StatusCode::kInvalidArgument)); - } -} -} // namespace -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/message_path.h b/libs/protobuf/src/google/protobuf/json/internal/message_path.h deleted file mode 100644 index b1a3f9f..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/message_path.h +++ /dev/null @@ -1,84 +0,0 @@ -// 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_JSON_INTERNAL_MESSAGE_PATH_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_MESSAGE_PATH_H__ - -#include -#include - -#include "absl/cleanup/cleanup.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" - -namespace google { -namespace protobuf { -namespace json_internal { -// A path in a Protobuf message, annotated specifically for producing nice -// errors. -class MessagePath { - public: - explicit MessagePath(absl::string_view message_root) - : components_( - {Component{FieldDescriptor::TYPE_MESSAGE, message_root, "", -1}}) {} - - // Pushes a new field name, along with an optional type name if it is - // a message or enum. - // - // Returns an RAII object that will pop the field component on scope exit. - auto Push(absl::string_view field_name, FieldDescriptor::Type type, - absl::string_view type_name = "") { - // -1 makes it so the first call to NextRepeated makes the index 0. - components_.push_back(Component{type, type_name, field_name, -1}); - return absl::MakeCleanup([this] { components_.pop_back(); }); - } - - // Increments the index of this field, indicating it is a repeated field. - // - // The first time this is called, the field will be marked as repeated and - // the index will become 0. - void NextRepeated() { ++components_.back().repeated_index; } - - // Appends a description of the current state of the path to `out`. - void Describe(std::string& out) const; - - private: - struct Component { - FieldDescriptor::Type type; - absl::string_view type_name, field_name; - int32_t repeated_index; - }; - std::vector components_; -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_MESSAGE_PATH_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/parser.cc b/libs/protobuf/src/google/protobuf/json/internal/parser.cc deleted file mode 100644 index a7706f6..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/parser.cc +++ /dev/null @@ -1,1374 +0,0 @@ -// 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/json/internal/parser.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "absl/base/attributes.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/match.h" -#include "absl/strings/numbers.h" -#include "absl/strings/str_format.h" -#include "absl/strings/str_split.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/span.h" -#include "google/protobuf/io/zero_copy_sink.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/json/internal/descriptor_traits.h" -#include "google/protobuf/json/internal/lexer.h" -#include "google/protobuf/json/internal/parser_traits.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -namespace { -// This file contains code that drives a JsonLexer to visit a JSON document and -// convert it into some form of proto. -// -// This semantic layer is duplicated: proto2-ish code can deserialize directly -// into a message, whereas proto3-ish code deserializes into a byte stream, -// using TypeResolvers instead of Descriptors. -// -// The parsing code is templated over which of these two reflection + output -// combinations is used. The traits types that collect the per-instantiation -// functionality can be found in json_util2_parser_traits-inl.h. - -// This table maps an unsigned `char` value, interpreted as an ASCII character, -// to a corresponding value in the base64 alphabet (both traditional and -// "web-safe" characters are included). -// -// If a character is not valid base64, it maps to -1; this is used by the bit -// operations that assemble a base64-encoded word to determine if an error -// occurred, by checking the sign bit. -constexpr signed char kBase64Table[256] = { - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, - 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, - 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, - -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, - 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, - 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, - 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, - -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, - 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, - 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, - 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, - 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1}; - -uint32_t Base64Lookup(char c) { - // Sign-extend return value so high bit will be set on any unexpected char. - return static_cast(kBase64Table[static_cast(c)]); -} - -// Decodes `base64` in-place, shrinking the length as appropriate. -absl::StatusOr> DecodeBase64InPlace(absl::Span base64) { - // We decode in place. This is safe because this is a new buffer (not - // aliasing the input) and because base64 decoding shrinks 4 bytes into 3. - char* out = base64.data(); - const char* ptr = base64.data(); - const char* end = ptr + base64.size(); - const char* end4 = ptr + (base64.size() & ~3u); - - for (; ptr < end4; ptr += 4, out += 3) { - auto val = Base64Lookup(ptr[0]) << 18 | Base64Lookup(ptr[1]) << 12 | - Base64Lookup(ptr[2]) << 6 | Base64Lookup(ptr[3]) << 0; - - if (static_cast(val) < 0) { - // Junk chars or padding. Remove trailing padding, if any. - if (end - ptr == 4 && ptr[3] == '=') { - if (ptr[2] == '=') { - end -= 2; - } else { - end -= 1; - } - } - break; - } - - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out[2] = val & 0xff; - } - - if (ptr < end) { - uint32_t val = ~0u; - switch (end - ptr) { - case 2: - val = Base64Lookup(ptr[0]) << 18 | Base64Lookup(ptr[1]) << 12; - out[0] = val >> 16; - out += 1; - break; - case 3: - val = Base64Lookup(ptr[0]) << 18 | Base64Lookup(ptr[1]) << 12 | - Base64Lookup(ptr[2]) << 6; - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out += 2; - break; - } - - if (static_cast(val) < 0) { - return absl::InvalidArgumentError("corrupt base64"); - } - } - - return absl::Span(base64.data(), - static_cast(out - base64.data())); -} - -template -absl::StatusOr> ParseIntInner(JsonLexer& lex, double lo, - double hi) { - absl::StatusOr kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - - LocationWith n; - switch (*kind) { - case JsonLexer::kNum: { - absl::StatusOr> x = lex.ParseRawNumber(); - RETURN_IF_ERROR(x.status()); - n.loc = x->loc; - if (absl::SimpleAtoi(x->value.AsView(), &n.value)) { - break; - } - - double d; - if (!absl::SimpleAtod(x->value.AsView(), &d) || !std::isfinite(d)) { - return x->loc.Invalid( - absl::StrFormat("invalid number: '%s'", x->value.AsView())); - } - - // Conversion overflow here would be UB. - if (lo > d || d > hi) { - return lex.Invalid("JSON number out of range for int"); - } - n.value = static_cast(d); - if (d - static_cast(n.value) != 0) { - return lex.Invalid( - "expected integer, but JSON number had fractional part"); - } - break; - } - case JsonLexer::kStr: { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - // SimpleAtoi will ignore leading and trailing whitespace, so we need - // to check for it ourselves. - for (char c : str->value.AsView()) { - if (absl::ascii_isspace(c)) { - return lex.Invalid("non-number characters in quoted number"); - } - } - if (!absl::SimpleAtoi(str->value.AsView(), &n.value)) { - return str->loc.Invalid("non-number characters in quoted number"); - } - n.loc = str->loc; - break; - } - default: - return lex.Invalid("expected number or string"); - } - - return n; -} - -template -absl::StatusOr ParseInt(JsonLexer& lex, Field field) { - absl::StatusOr> n = - ParseIntInner(lex, -9007199254740992.0, 9007199254740992.0); - RETURN_IF_ERROR(n.status()); - - if (Traits::Is32Bit(field)) { - if (std::numeric_limits::min() > n->value || - n->value > std::numeric_limits::max()) { - return n->loc.Invalid("integer out of range"); - } - } - - return n->value; -} - -template -absl::StatusOr ParseUInt(JsonLexer& lex, Field field) { - absl::StatusOr> n = - ParseIntInner(lex, 0, 18014398509481984.0); - RETURN_IF_ERROR(n.status()); - - if (Traits::Is32Bit(field)) { - if (n->value > std::numeric_limits::max()) { - return n->loc.Invalid("integer out of range"); - } - } - - return n->value; -} - -template -absl::StatusOr ParseFp(JsonLexer& lex, Field field) { - absl::StatusOr kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - - double n; - switch (*kind) { - case JsonLexer::kNum: { - absl::StatusOr> d = lex.ParseNumber(); - RETURN_IF_ERROR(d.status()); - n = d->value; - break; - } - case JsonLexer::kStr: { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - - if (str->value == "NaN") { - n = NAN; - } else if (str->value == "Infinity") { - n = INFINITY; - } else if (str->value == "-Infinity") { - n = -INFINITY; - } else if (!absl::SimpleAtod(str->value.AsView(), &n)) { - return str->loc.Invalid("non-number characters in quoted number"); - } - break; - } - default: - return lex.Invalid("expected number or string"); - } - - if (Traits::Is32Bit(field)) { - // Detect out-of-range 32-bit floats by seeing whether the conversion result - // is still finite. Finite extreme values may have textual representations - // that parse to 64-bit values outside the 32-bit range, but which are - // closer to the 32-bit extreme than to the "next value with the same - // precision". - if (std::isfinite(n) && !std::isfinite(static_cast(n))) { - return lex.Invalid("float out of range"); - } - } - - return n; -} - -template -absl::StatusOr ParseStrOrBytes(JsonLexer& lex, - Field field) { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - - if (Traits::FieldType(field) == FieldDescriptor::TYPE_BYTES) { - std::string& b64 = str->value.ToString(); - absl::StatusOr> decoded = - DecodeBase64InPlace(absl::MakeSpan(&b64[0], b64.size())); - if (!decoded.ok()) { - return str->loc.Invalid(decoded.status().message()); - } - b64.resize(decoded->size()); - } - - return std::move(str->value.ToString()); -} - -template -absl::StatusOr> ParseEnumFromStr(JsonLexer& lex, - MaybeOwnedString& str, - Field field) { - absl::StatusOr value = Traits::EnumNumberByName( - field, str.AsView(), lex.options().case_insensitive_enum_parsing); - if (value.ok()) { - return absl::optional(*value); - } - - int32_t i; - if (absl::SimpleAtoi(str.AsView(), &i)) { - return absl::optional(i); - } else if (lex.options().ignore_unknown_fields) { - return {absl::nullopt}; - } - - return value.status(); -} - -// Parses an enum; can return nullopt if a quoted enumerator that we don't -// know about is received and `ignore_unknown_fields` is set. -template -absl::StatusOr> ParseEnum(JsonLexer& lex, - Field field) { - absl::StatusOr kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - - int32_t n = 0; - switch (*kind) { - case JsonLexer::kStr: { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - - auto e = ParseEnumFromStr(lex, str->value, field); - RETURN_IF_ERROR(e.status()); - if (!e->has_value()) { - return {absl::nullopt}; - } - n = **e; - break; - } - case JsonLexer::kNum: - return ParseInt(lex, field); - default: - return lex.Invalid("expected number or string"); - } - - return n; -} - -// Mutually recursive with functions that follow. -template -absl::Status ParseMessage(JsonLexer& lex, const Desc& desc, - Msg& msg, bool any_reparse); -template -absl::Status ParseField(JsonLexer& lex, const Desc& desc, - absl::string_view name, Msg& msg); - -template -absl::Status ParseSingular(JsonLexer& lex, Field field, - Msg& msg) { - auto field_type = Traits::FieldType(field); - if (lex.Peek(JsonLexer::kNull)) { - auto message_type = ClassifyMessage(Traits::FieldTypeName(field)); - switch (field_type) { - case FieldDescriptor::TYPE_ENUM: - if (message_type == MessageType::kNull) { - Traits::SetEnum(field, msg, 0); - } - break; - case FieldDescriptor::TYPE_MESSAGE: { - if (message_type == MessageType::kValue) { - return Traits::NewMsg( - field, msg, - [&](const Desc& type, Msg& msg) -> absl::Status { - auto field = Traits::FieldByNumber(type, 1); - GOOGLE_DCHECK(field.has_value()); - RETURN_IF_ERROR(lex.Expect("null")); - Traits::SetEnum(Traits::MustHaveField(type, 1), msg, 0); - return absl::OkStatus(); - }); - } - break; - } - default: - break; - } - return lex.Expect("null"); - } - - switch (field_type) { - case FieldDescriptor::TYPE_FLOAT: { - auto x = ParseFp(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetFloat(field, msg, *x); - break; - } - case FieldDescriptor::TYPE_DOUBLE: { - auto x = ParseFp(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetDouble(field, msg, *x); - break; - } - - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_INT64: { - auto x = ParseInt(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetInt64(field, msg, *x); - break; - } - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_UINT64: { - auto x = ParseUInt(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetUInt64(field, msg, *x); - break; - } - - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_INT32: { - auto x = ParseInt(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetInt32(field, msg, static_cast(*x)); - break; - } - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_UINT32: { - auto x = ParseUInt(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetUInt32(field, msg, static_cast(*x)); - break; - } - case FieldDescriptor::TYPE_BOOL: { - absl::StatusOr kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - - switch (*kind) { - case JsonLexer::kTrue: - RETURN_IF_ERROR(lex.Expect("true")); - Traits::SetBool(field, msg, true); - break; - case JsonLexer::kFalse: - RETURN_IF_ERROR(lex.Expect("false")); - Traits::SetBool(field, msg, false); - break; - case JsonLexer::kStr: { - if (!lex.options().allow_legacy_syntax) { - goto bad; - } - - auto x = lex.ParseUtf8(); - RETURN_IF_ERROR(x.status()); - - bool flag; - if (!absl::SimpleAtob(x->value, &flag)) { - // Is this error a lie? Do we accept things otyher than "true" and - // "false" because SimpleAtob does? Absolutely! - return x->loc.Invalid("expected 'true' or 'false'"); - } - Traits::SetBool(field, msg, flag); - - break; - } - bad: - default: - return lex.Invalid("expected 'true' or 'false'"); - } - break; - } - case FieldDescriptor::TYPE_STRING: - case FieldDescriptor::TYPE_BYTES: { - auto x = ParseStrOrBytes(lex, field); - RETURN_IF_ERROR(x.status()); - Traits::SetString(field, msg, *x); - break; - } - case FieldDescriptor::TYPE_ENUM: { - absl::StatusOr> x = ParseEnum(lex, field); - RETURN_IF_ERROR(x.status()); - - if (x->has_value() || !Traits::IsOptional(field)) { - Traits::SetEnum(field, msg, x->value_or(0)); - } - break; - } - case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_GROUP: { - return Traits::NewMsg( - field, msg, - [&](const Desc& type, Msg& msg) -> absl::Status { - return ParseMessage(lex, type, msg, - /*any_reparse=*/false); - }); - } - default: - return lex.Invalid( - absl::StrCat("unsupported field type: ", Traits::FieldType(field))); - } - - return absl::OkStatus(); -} - -template -absl::Status EmitNull(JsonLexer& lex, Field field, Msg& msg) { - switch (Traits::FieldType(field)) { - case FieldDescriptor::TYPE_FLOAT: - Traits::SetFloat(field, msg, 0); - break; - case FieldDescriptor::TYPE_DOUBLE: - Traits::SetDouble(field, msg, 0); - break; - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_INT64: - Traits::SetInt64(field, msg, 0); - break; - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_UINT64: - Traits::SetUInt64(field, msg, 0); - break; - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_INT32: - Traits::SetInt32(field, msg, 0); - break; - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_UINT32: - Traits::SetUInt32(field, msg, 0); - break; - case FieldDescriptor::TYPE_BOOL: - Traits::SetBool(field, msg, false); - break; - case FieldDescriptor::TYPE_STRING: - case FieldDescriptor::TYPE_BYTES: - Traits::SetString(field, msg, ""); - break; - case FieldDescriptor::TYPE_ENUM: - Traits::SetEnum(field, msg, 0); - break; - case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_GROUP: - return Traits::NewMsg(field, msg, - [](const auto&, const auto&) -> absl::Status { - return absl::OkStatus(); - }); - default: - return lex.Invalid( - absl::StrCat("unsupported field type: ", Traits::FieldType(field))); - } - return absl::OkStatus(); -} - -template -absl::Status ParseArray(JsonLexer& lex, Field field, Msg& msg) { - if (lex.Peek(JsonLexer::kNull)) { - return lex.Expect("null"); - } - - return lex.VisitArray([&]() -> absl::Status { - lex.path().NextRepeated(); - MessageType type = ClassifyMessage(Traits::FieldTypeName(field)); - - if (lex.Peek(JsonLexer::kNull)) { - if (type == MessageType::kValue) { - return ParseSingular(lex, field, msg); - } - if (type == MessageType::kNull) { - return ParseSingular(lex, field, msg); - } - - if (lex.options().allow_legacy_syntax) { - RETURN_IF_ERROR(lex.Expect("null")); - return EmitNull(lex, field, msg); - } - return lex.Invalid("null cannot occur inside of repeated fields"); - } - - // Note that this is sufficient to catch when we are inside of a ListValue, - // because a ListValue's sole field is of type Value. Thus, we only need to - // classify cases in which we are inside of an array and parsing messages - // that like looking like arrays. - // - // This will also correctly handle e.g. writing out a ListValue with the - // legacy syntax of `{"values": [[0], [1], [2]]}`, which does not go through - // the custom parser handler. - bool can_flatten = - type != MessageType::kValue && type != MessageType::kList; - if (can_flatten && lex.options().allow_legacy_syntax && - lex.Peek(JsonLexer::kArr)) { - // You read that right. In legacy mode, if we encounter an array within - // an array, we just flatten it as part of the current array! - // - // This DOES NOT apply when parsing a google.protobuf.Value or a - // google.protobuf.ListValue! - return ParseArray(lex, field, msg); - } - return ParseSingular(lex, field, msg); - }); -} - -template -absl::Status ParseMap(JsonLexer& lex, Field field, Msg& msg) { - if (lex.Peek(JsonLexer::kNull)) { - return lex.Expect("null"); - } - - absl::flat_hash_set keys_seen; - return lex.VisitObject( - [&](LocationWith& key) -> absl::Status { - lex.path().NextRepeated(); - auto insert_result = keys_seen.emplace(key.value.AsView()); - if (!insert_result.second) { - return key.loc.Invalid(absl::StrFormat( - "got unexpectedly-repeated repeated map key: '%s'", - key.value.AsView())); - } - return Traits::NewMsg( - field, msg, - [&](const Desc& type, Msg& entry) -> absl::Status { - auto key_field = Traits::KeyField(type); - switch (Traits::FieldType(key_field)) { - case FieldDescriptor::TYPE_INT64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_SFIXED64: { - int64_t n; - if (!absl::SimpleAtoi(key.value.AsView(), &n)) { - return key.loc.Invalid( - "non-number characters in quoted number"); - } - Traits::SetInt64(key_field, entry, n); - break; - } - case FieldDescriptor::TYPE_UINT64: - case FieldDescriptor::TYPE_FIXED64: { - uint64_t n; - if (!absl::SimpleAtoi(key.value.AsView(), &n)) { - return key.loc.Invalid( - "non-number characters in quoted number"); - } - Traits::SetUInt64(key_field, entry, n); - break; - } - case FieldDescriptor::TYPE_INT32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_SFIXED32: { - int32_t n; - if (!absl::SimpleAtoi(key.value.AsView(), &n)) { - return key.loc.Invalid( - "non-number characters in quoted number"); - } - Traits::SetInt32(key_field, entry, n); - break; - } - case FieldDescriptor::TYPE_UINT32: - case FieldDescriptor::TYPE_FIXED32: { - uint32_t n; - if (!absl::SimpleAtoi(key.value.AsView(), &n)) { - return key.loc.Invalid( - "non-number characters in quoted number"); - } - Traits::SetUInt32(key_field, entry, n); - break; - } - case FieldDescriptor::TYPE_BOOL: { - if (key.value == "true") { - Traits::SetBool(key_field, entry, true); - } else if (key.value == "false") { - Traits::SetBool(key_field, entry, false); - } else { - return key.loc.Invalid(absl::StrFormat( - "expected bool string, got '%s'", key.value.AsView())); - } - break; - } - case FieldDescriptor::TYPE_ENUM: { - MaybeOwnedString key_str = key.value; - auto e = ParseEnumFromStr(lex, key_str, field); - RETURN_IF_ERROR(e.status()); - Traits::SetEnum(key_field, entry, e->value_or(0)); - break; - } - case FieldDescriptor::TYPE_STRING: { - Traits::SetString(key_field, entry, - std::move(key.value.ToString())); - break; - } - default: - return lex.Invalid("unsupported map key type"); - } - - return ParseSingular(lex, Traits::ValueField(type), - entry); - }); - }); -} - -absl::optional TakeTimeDigitsWithSuffixAndAdvance( - absl::string_view& data, int max_digits, absl::string_view end) { - GOOGLE_DCHECK_LE(max_digits, 9); - - uint32_t val = 0; - int limit = max_digits; - while (!data.empty()) { - if (limit-- < 0) { - return absl::nullopt; - } - uint32_t digit = data[0] - '0'; - if (digit >= 10) { - break; - } - - val *= 10; - val += digit; - data = data.substr(1); - } - if (!absl::StartsWith(data, end)) { - return absl::nullopt; - } - - data = data.substr(end.size()); - return val; -} - -absl::optional TakeNanosAndAdvance(absl::string_view& data) { - int32_t frac_secs = 0; - size_t frac_digits = 0; - if (absl::StartsWith(data, ".")) { - for (char c : data.substr(1)) { - if (!absl::ascii_isdigit(c)) { - break; - } - ++frac_digits; - } - auto digits = data.substr(1, frac_digits); - if (frac_digits == 0 || frac_digits > 9 || - !absl::SimpleAtoi(digits, &frac_secs)) { - return absl::nullopt; - } - data = data.substr(frac_digits + 1); - } - for (int i = 0; i < 9 - frac_digits; ++i) { - frac_secs *= 10; - } - return frac_secs; -} - -template -absl::Status ParseTimestamp(JsonLexer& lex, const Desc& desc, - Msg& msg) { - if (lex.Peek(JsonLexer::kNull)) { - return lex.Expect("null"); - } - - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - - absl::string_view data = str->value.AsView(); - if (data.size() < 20) { - return str->loc.Invalid("timestamp string too short"); - } - - int64_t secs; - { - /* 1972-01-01T01:00:00 */ - auto year = TakeTimeDigitsWithSuffixAndAdvance(data, 4, "-"); - if (!year.has_value() || *year == 0) { - return str->loc.Invalid("bad year in timestamp"); - } - auto mon = TakeTimeDigitsWithSuffixAndAdvance(data, 2, "-"); - if (!mon.has_value() || *mon == 0) { - return str->loc.Invalid("bad month in timestamp"); - } - auto day = TakeTimeDigitsWithSuffixAndAdvance(data, 2, "T"); - if (!day.has_value() || *day == 0) { - return str->loc.Invalid("bad day in timestamp"); - } - auto hour = TakeTimeDigitsWithSuffixAndAdvance(data, 2, ":"); - if (!hour.has_value()) { - return str->loc.Invalid("bad hours in timestamp"); - } - auto min = TakeTimeDigitsWithSuffixAndAdvance(data, 2, ":"); - if (!min.has_value()) { - return str->loc.Invalid("bad minutes in timestamp"); - } - auto sec = TakeTimeDigitsWithSuffixAndAdvance(data, 2, ""); - if (!sec.has_value()) { - return str->loc.Invalid("bad seconds in timestamp"); - } - - uint32_t m_adj = *mon - 3; // March-based month. - uint32_t carry = m_adj > *mon ? 1 : 0; - - uint32_t year_base = 4800; // Before min year, multiple of 400. - uint32_t y_adj = *year + year_base - carry; - - uint32_t month_days = ((m_adj + carry * 12) * 62719 + 769) / 2048; - uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; - int32_t epoch_days = - y_adj * 365 + leap_days + month_days + (*day - 1) - 2472632; - - secs = int64_t{epoch_days} * 86400 + *hour * 3600 + *min * 60 + *sec; - } - - auto nanos = TakeNanosAndAdvance(data); - if (!nanos.has_value()) { - return str->loc.Invalid("timestamp had bad nanoseconds"); - } - - if (data.empty()) { - return str->loc.Invalid("timestamp missing timezone offset"); - } - - { - // [+-]hh:mm or Z - bool neg = false; - switch (data[0]) { - case '-': - neg = true; - ABSL_FALLTHROUGH_INTENDED; - case '+': { - if (data.size() != 6) { - return str->loc.Invalid("timestamp offset of wrong size."); - } - - data = data.substr(1); - auto hour = TakeTimeDigitsWithSuffixAndAdvance(data, 2, ":"); - auto mins = TakeTimeDigitsWithSuffixAndAdvance(data, 2, ""); - if (!hour.has_value() || !mins.has_value()) { - return str->loc.Invalid("timestamp offset has bad hours and minutes"); - } - - int64_t offset = (*hour * 60 + *mins) * 60; - secs += (neg ? offset : -offset); - break; - } - // Lowercase z is not accepted, per the spec. - case 'Z': - if (data.size() == 1) { - break; - } - ABSL_FALLTHROUGH_INTENDED; - default: - return str->loc.Invalid("bad timezone offset"); - } - } - - Traits::SetInt64(Traits::MustHaveField(desc, 1), msg, secs); - Traits::SetInt32(Traits::MustHaveField(desc, 2), msg, *nanos); - - return absl::OkStatus(); -} - -template -absl::Status ParseDuration(JsonLexer& lex, const Desc& desc, - Msg& msg) { - if (lex.Peek(JsonLexer::kNull)) { - return lex.Expect("null"); - } - - constexpr int64_t kMaxSeconds = int64_t{3652500} * 86400; - - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - - size_t int_part_end = 0; - for (char c : str->value.AsView()) { - if (!absl::ascii_isdigit(c) && c != '-') { - break; - } - ++int_part_end; - } - if (int_part_end == 0) { - return str->loc.Invalid("duration must start with an integer"); - } - - absl::string_view sec_digits = str->value.AsView().substr(0, int_part_end); - int64_t secs; - if (!absl::SimpleAtoi(sec_digits, &secs)) { - return str->loc.Invalid("duration had bad seconds"); - } - - if (secs > kMaxSeconds || secs < -kMaxSeconds) { - return str->loc.Invalid("duration out of range"); - } - - absl::string_view rest = str->value.AsView().substr(int_part_end); - auto nanos = TakeNanosAndAdvance(rest); - if (!nanos.has_value()) { - return str->loc.Invalid("duration had bad nanoseconds"); - } - - bool isNegative = (secs < 0) || absl::StartsWith(sec_digits, "-"); - if (isNegative) { - *nanos *= -1; - } - - if (rest != "s") { - return str->loc.Invalid("duration must end with a single 's'"); - } - - Traits::SetInt64(Traits::MustHaveField(desc, 1), msg, secs); - Traits::SetInt32(Traits::MustHaveField(desc, 2), msg, *nanos); - - return absl::OkStatus(); -} - -template -absl::Status ParseFieldMask(JsonLexer& lex, const Desc& desc, - Msg& msg) { - absl::StatusOr> str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - auto paths = str->value.AsView(); - - // The special case of the empty string is not handled correctly below, - // because StrSplit("", ',') is [""], not []. - if (paths.empty()) { - return absl::OkStatus(); - } - - // google.protobuf.FieldMask has a single field with number 1. - auto paths_field = Traits::MustHaveField(desc, 1); - for (absl::string_view path : absl::StrSplit(paths, ',')) { - std::string snake_path; - // Assume approximately six-letter words, so add one extra space for an - // underscore for every six bytes. - snake_path.reserve(path.size() * 7 / 6); - for (char c : path) { - if (absl::ascii_isdigit(c) || absl::ascii_islower(c) || c == '.') { - snake_path.push_back(c); - } else if (absl::ascii_isupper(c)) { - snake_path.push_back('_'); - snake_path.push_back(absl::ascii_tolower(c)); - } else if (lex.options().allow_legacy_syntax) { - snake_path.push_back(c); - } else { - return str->loc.Invalid("unexpected character in FieldMask"); - } - } - Traits::SetString(paths_field, msg, snake_path); - } - - return absl::OkStatus(); -} - -template -absl::Status ParseAny(JsonLexer& lex, const Desc& desc, - Msg& msg) { - // Buffer an entire object. Because @type can occur anywhere, we're forced - // to do this. - RETURN_IF_ERROR(lex.SkipToToken()); - auto mark = lex.BeginMark(); - - // Search for @type, buffering the entire object along the way so we can - // reparse it. - absl::optional type_url; - RETURN_IF_ERROR(lex.VisitObject( - [&](const LocationWith& key) -> absl::Status { - if (key.value == "@type") { - if (type_url.has_value()) { - return key.loc.Invalid("repeated @type in Any"); - } - - absl::StatusOr> maybe_url = - lex.ParseUtf8(); - RETURN_IF_ERROR(maybe_url.status()); - type_url = std::move(maybe_url)->value; - return absl::OkStatus(); - } - return lex.SkipValue(); - })); - - // Build a new lexer over the skipped object. - absl::string_view any_text = mark.value.UpToUnread(); - io::ArrayInputStream in(any_text.data(), any_text.size()); - // Copying lex.options() is important; it inherits the recursion - // limit. - JsonLexer any_lex(&in, lex.options(), &lex.path(), mark.loc); - - if (!type_url.has_value() && !lex.options().allow_legacy_syntax) { - return mark.loc.Invalid("missing @type in Any"); - } - - if (type_url.has_value()) { - Traits::SetString(Traits::MustHaveField(desc, 1), msg, type_url->AsView()); - return Traits::NewDynamic( - Traits::MustHaveField(desc, 2), type_url->ToString(), msg, - [&](const Desc& desc, Msg& msg) { - auto pop = any_lex.path().Push("", FieldDescriptor::TYPE_MESSAGE, - Traits::TypeName(desc)); - return ParseMessage(any_lex, desc, msg, - /*any_reparse=*/true); - }); - } else { - // Empty {} is accepted in legacy mode. - GOOGLE_DCHECK(lex.options().allow_legacy_syntax); - RETURN_IF_ERROR(any_lex.VisitObject([&](auto&) { - return mark.loc.Invalid( - "in legacy mode, missing @type in Any is only allowed for an empty " - "object"); - })); - return absl::OkStatus(); - } -} - -// These are mutually recursive with ParseValue. -template -absl::Status ParseStructValue(JsonLexer& lex, const Desc& desc, - Msg& msg); -template -absl::Status ParseListValue(JsonLexer& lex, const Desc& desc, - Msg& msg); - -template -absl::Status ParseValue(JsonLexer& lex, const Desc& desc, - Msg& msg) { - auto kind = lex.PeekKind(); - RETURN_IF_ERROR(kind.status()); - // NOTE: The field numbers 1 through 6 are the numbers of the oneof fields - // in google.protobuf.Value. Conformance tests verify the correctness of - // these numbers. - switch (*kind) { - case JsonLexer::kNull: { - auto field = Traits::MustHaveField(desc, 1); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - RETURN_IF_ERROR(lex.Expect("null")); - Traits::SetEnum(field, msg, 0); - break; - } - case JsonLexer::kNum: { - auto field = Traits::MustHaveField(desc, 2); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - auto number = lex.ParseNumber(); - RETURN_IF_ERROR(number.status()); - Traits::SetDouble(field, msg, number->value); - break; - } - case JsonLexer::kStr: { - auto field = Traits::MustHaveField(desc, 3); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - auto str = lex.ParseUtf8(); - RETURN_IF_ERROR(str.status()); - Traits::SetString(field, msg, std::move(str->value.ToString())); - break; - } - case JsonLexer::kFalse: - case JsonLexer::kTrue: { - auto field = Traits::MustHaveField(desc, 4); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - // "Quoted" bools, including non-standard Abseil Atob bools, are not - // supported, because all strings are treated as genuine JSON strings. - if (*kind == JsonLexer::kTrue) { - RETURN_IF_ERROR(lex.Expect("true")); - Traits::SetBool(field, msg, true); - } else { - RETURN_IF_ERROR(lex.Expect("false")); - Traits::SetBool(field, msg, false); - } - break; - } - case JsonLexer::kObj: { - auto field = Traits::MustHaveField(desc, 5); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - return Traits::NewMsg(field, msg, [&](auto& desc, auto& msg) { - return ParseStructValue(lex, desc, msg); - }); - } - case JsonLexer::kArr: { - auto field = Traits::MustHaveField(desc, 6); - auto pop = - lex.path().Push(Traits::FieldName(field), Traits::FieldType(field), - Traits::FieldTypeName(field)); - - return Traits::NewMsg(field, msg, [&](auto& desc, auto& msg) { - return ParseListValue(lex, desc, msg); - }); - } - } - - return absl::OkStatus(); -} - -template -absl::Status ParseStructValue(JsonLexer& lex, const Desc& desc, - Msg& msg) { - auto entry_field = Traits::MustHaveField(desc, 1); - auto pop = lex.path().Push("", FieldDescriptor::TYPE_MESSAGE, - Traits::FieldTypeName(entry_field)); - - // Structs are always cleared even if set to {}. - Traits::RecordAsSeen(entry_field, msg); - - // Parsing a map does the right thing: Struct has a single map field; keys are correctly parsed as strings, and the values - // recurse into ParseMessage, which will be routed into ParseValue. This - // results in some extra overhead, but performance is not what we're going - // for here. - return ParseMap(lex, entry_field, msg); -} - -template -absl::Status ParseListValue(JsonLexer& lex, const Desc& desc, - Msg& msg) { - auto entry_field = Traits::MustHaveField(desc, 1); - auto pop = lex.path().Push("", FieldDescriptor::TYPE_MESSAGE, - Traits::FieldTypeName(entry_field)); - - // ListValues are always cleared even if set to []. - Traits::RecordAsSeen(entry_field, msg); - // Parsing an array does the right thing: see the analogous comment in - // ParseStructValue. - return ParseArray(lex, entry_field, msg); -} - -template -absl::Status ParseField(JsonLexer& lex, const Desc& desc, - absl::string_view name, Msg& msg) { - absl::optional> field; - if (absl::StartsWith(name, "[") && absl::EndsWith(name, "]")) { - absl::string_view extn_name = name.substr(1, name.size() - 2); - field = Traits::ExtensionByName(desc, extn_name); - } else { - field = Traits::FieldByName(desc, name); - } - - if (!field.has_value()) { - if (!lex.options().ignore_unknown_fields) { - return lex.Invalid(absl::StrFormat("no such field: '%s'", name)); - } - return lex.SkipValue(); - } - - auto pop = lex.path().Push(name, Traits::FieldType(*field), - Traits::FieldTypeName(*field)); - - if (Traits::HasParsed( - *field, msg, - /*allow_repeated_non_oneof=*/lex.options().allow_legacy_syntax) && - !lex.Peek(JsonLexer::kNull)) { - return lex.Invalid(absl::StrFormat( - "'%s' has already been set (either directly or as part of a oneof)", - name)); - } - - if (Traits::IsMap(*field)) { - return ParseMap(lex, *field, msg); - } - - if (Traits::IsRepeated(*field)) { - if (lex.options().allow_legacy_syntax && !lex.Peek(JsonLexer::kArr)) { - // The original ESF parser permits a single element in place of an array - // thereof. - return ParseSingular(lex, *field, msg); - } - return ParseArray(lex, *field, msg); - } - - return ParseSingular(lex, *field, msg); -} - -template -absl::Status ParseMessage(JsonLexer& lex, const Desc& desc, - Msg& msg, bool any_reparse) { - MessageType type = ClassifyMessage(Traits::TypeName(desc)); - if (!any_reparse) { - switch (type) { - case MessageType::kAny: - return ParseAny(lex, desc, msg); - case MessageType::kValue: - return ParseValue(lex, desc, msg); - case MessageType::kStruct: - return ParseStructValue(lex, desc, msg); - default: - break; - } - // For some types, the ESF parser permits parsing the "non-special" version. - // It is not clear if this counts as out-of-spec, but we're treating it as - // such. - bool is_upcoming_object = lex.Peek(JsonLexer::kObj); - if (!(is_upcoming_object && lex.options().allow_legacy_syntax)) { - switch (type) { - case MessageType::kList: - return ParseListValue(lex, desc, msg); - case MessageType::kWrapper: { - return ParseSingular(lex, Traits::MustHaveField(desc, 1), - msg); - } - case MessageType::kTimestamp: - return ParseTimestamp(lex, desc, msg); - case MessageType::kDuration: - return ParseDuration(lex, desc, msg); - case MessageType::kFieldMask: - return ParseFieldMask(lex, desc, msg); - default: - break; - } - } - } - - return lex.VisitObject( - [&](LocationWith& name) -> absl::Status { - // If this is a well-known type, we expect its contents to be inside - // of a JSON field named "value". - if (any_reparse) { - if (name.value == "@type") { - RETURN_IF_ERROR(lex.SkipValue()); - return absl::OkStatus(); - } - if (type != MessageType::kNotWellKnown) { - if (name.value != "value") { - return lex.Invalid( - "fields in a well-known-typed Any must be @type or value"); - } - // Parse the upcoming value as the message itself. This is *not* - // an Any reparse because we do not expect to see @type in the - // upcoming value. - return ParseMessage(lex, desc, msg, - /*any_reparse=*/false); - } - } - - return ParseField(lex, desc, name.value.AsView(), msg); - }); -} -} // namespace - -absl::Status JsonStringToMessage(absl::string_view input, Message* message, - json_internal::ParseOptions options) { - MessagePath path(message->GetDescriptor()->full_name()); - PROTOBUF_DLOG(INFO) << "json2/input: " << absl::CHexEscape(input); - io::ArrayInputStream in(input.data(), input.size()); - JsonLexer lex(&in, options, &path); - - ParseProto2Descriptor::Msg msg(message); - absl::Status s = - ParseMessage(lex, *message->GetDescriptor(), msg, - /*any_reparse=*/false); - if (s.ok() && !lex.AtEof()) { - s = absl::InvalidArgumentError( - "extraneous characters after end of JSON object"); - } - - PROTOBUF_DLOG(INFO) << "json2/status: " << s; - PROTOBUF_DLOG(INFO) << "json2/output: " << message->DebugString(); - - return s; -} - -absl::Status JsonToBinaryStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* json_input, - io::ZeroCopyOutputStream* binary_output, - json_internal::ParseOptions options) { - // NOTE: Most of the contortions in this function are to allow for capture of - // input and output of the parser in GOOGLE_DLOG mode. Destruction order is very - // critical in this function, because io::ZeroCopy*Stream types usually only - // flush on destruction. - - // For GOOGLE_DLOG, we would like to print out the input and output, which requires - // buffering both instead of doing "zero copy". This block, and the one at - // the end of the function, set up and tear down interception of the input - // and output streams. - std::string copy; - std::string out; - absl::optional tee_input; - absl::optional tee_output; - if (PROTOBUF_DEBUG) { - const void* data; - int len; - while (json_input->Next(&data, &len)) { - copy.resize(copy.size() + len); - std::memcpy(©[copy.size() - len], data, len); - } - tee_input.emplace(copy.data(), copy.size()); - tee_output.emplace(&out); - } - - PROTOBUF_DLOG(INFO) << "json2/input: " << absl::CHexEscape(copy); - - // This scope forces the CodedOutputStream inside of `msg` to flush before we - // possibly handle logging the binary protobuf output. - absl::Status s; - { - MessagePath path(type_url); - JsonLexer lex(tee_input.has_value() ? &*tee_input : json_input, options, - &path); - Msg msg(tee_output.has_value() ? &*tee_output - : binary_output); - - ResolverPool pool(resolver); - auto desc = pool.FindMessage(type_url); - RETURN_IF_ERROR(desc.status()); - - s = ParseMessage(lex, **desc, msg, /*any_reparse=*/false); - if (s.ok() && !lex.AtEof()) { - s = absl::InvalidArgumentError( - "extraneous characters after end of JSON object"); - } - } - - if (PROTOBUF_DEBUG) { - tee_output.reset(); // Flush the output stream. - io::zc_sink_internal::ZeroCopyStreamByteSink(binary_output) - .Append(out.data(), out.size()); - } - - PROTOBUF_DLOG(INFO) << "json2/status: " << s; - PROTOBUF_DLOG(INFO) << "json2/output: " << absl::BytesToHexString(out); - return s; -} -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/parser.h b/libs/protobuf/src/google/protobuf/json/internal/parser.h deleted file mode 100644 index 79ba29a..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/parser.h +++ /dev/null @@ -1,59 +0,0 @@ -// 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_JSON_INTERNAL_PARSER_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_PARSER_H__ - -#include - -#include "google/protobuf/message.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/json/internal/lexer.h" -#include "google/protobuf/util/type_resolver.h" - -namespace google { -namespace protobuf { -namespace json_internal { -// Internal version of google::protobuf::util::JsonStringToMessage; see json_util.h for -// details. -absl::Status JsonStringToMessage(absl::string_view input, Message* message, - json_internal::ParseOptions options); -// Internal version of google::protobuf::util::JsonToBinaryStream; see json_util.h for -// details. -absl::Status JsonToBinaryStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* json_input, - io::ZeroCopyOutputStream* binary_output, - json_internal::ParseOptions options); -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_PARSER_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/parser_traits.h b/libs/protobuf/src/google/protobuf/json/internal/parser_traits.h deleted file mode 100644 index 957354c..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/parser_traits.h +++ /dev/null @@ -1,425 +0,0 @@ -// 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_JSON_INTERNAL_PARSER_TRAITS_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_PARSER_TRAITS_H__ - -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/wire_format_lite.h" -#include "absl/base/attributes.h" -#include "absl/base/casts.h" -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" -#include "absl/status/status.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/json/internal/descriptor_traits.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -using ::google::protobuf::internal::WireFormatLite; - -// See the comment in json_util2_parser.cc for more information. -// -// The type traits in this file describe how to parse to a protobuf -// representation used by the JSON API, either via proto reflection or by -// emitting wire format to an output stream. - -// Helper alias templates to avoid needing to write `typename` in function -// signatures. -template -using Msg = typename Traits::Msg; - -struct ParseProto2Descriptor : Proto2Descriptor { - // A message value that fields can be written to, but not read from. - class Msg { - public: - explicit Msg(Message* msg) : msg_(msg) {} - - private: - friend ParseProto2Descriptor; - Message* msg_; - // Because `msg` might already have oneofs set, we need to track which were - // set *during* the parse separately. - absl::flat_hash_set parsed_oneofs_indices_; - absl::flat_hash_set parsed_fields_; - }; - - static bool HasParsed(Field f, const Msg& msg, - bool allow_repeated_non_oneof) { - if (f->real_containing_oneof()) { - return msg.parsed_oneofs_indices_.contains( - f->real_containing_oneof()->index()); - } - if (allow_repeated_non_oneof) { - return false; - } - return msg.parsed_fields_.contains(f->number()); - } - - /// Functions for writing fields. /// - - // Marks a field as having been "seen". This will clear the field if it is - // the first occurrence thereof. - // - // All setters call this function automatically, but it may also be called - // eagerly to clear a pre-existing value that might not be overwritten, such - // as when parsing a repeated field. - static void RecordAsSeen(Field f, Msg& msg) { - bool inserted = msg.parsed_fields_.insert(f->number()).second; - if (inserted) { - msg.msg_->GetReflection()->ClearField(msg.msg_, f); - } - - if (f->real_containing_oneof() != nullptr) { - msg.parsed_oneofs_indices_.insert(f->real_containing_oneof()->index()); - } - } - - // Adds a new message and calls body on it. - // - // Body should have a signature `absl::Status(const Desc&, Msg&)`. - template - static absl::Status NewMsg(Field f, Msg& msg, F body) { - RecordAsSeen(f, msg); - - Message* new_msg; - if (f->is_repeated()) { - new_msg = msg.msg_->GetReflection()->AddMessage(msg.msg_, f); - } else { - new_msg = msg.msg_->GetReflection()->MutableMessage(msg.msg_, f); - } - Msg wrapper(new_msg); - return body(*f->message_type(), wrapper); - } - - // Adds a new dynamic message with the given type name and calls body on it. - // - // Body should have a signature `absl::Status(const Desc&, Msg&)`. - template - static absl::Status NewDynamic(Field f, const std::string& type_url, Msg& msg, - F body) { - RecordAsSeen(f, msg); - return WithDynamicType( - *f->containing_type(), type_url, [&](const Desc& desc) -> absl::Status { - DynamicMessageFactory factory; - std::unique_ptr dynamic(factory.GetPrototype(&desc)->New()); - Msg wrapper(dynamic.get()); - RETURN_IF_ERROR(body(desc, wrapper)); - - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddString(msg.msg_, f, - dynamic->SerializeAsString()); - } else { - msg.msg_->GetReflection()->SetString(msg.msg_, f, - dynamic->SerializeAsString()); - } - return absl::OkStatus(); - }); - } - - static void SetFloat(Field f, Msg& msg, float x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddFloat(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetFloat(msg.msg_, f, x); - } - } - - static void SetDouble(Field f, Msg& msg, double x) { - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddDouble(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetDouble(msg.msg_, f, x); - } - } - - static void SetInt64(Field f, Msg& msg, int64_t x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddInt64(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetInt64(msg.msg_, f, x); - } - } - - static void SetUInt64(Field f, Msg& msg, uint64_t x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddUInt64(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetUInt64(msg.msg_, f, x); - } - } - - static void SetInt32(Field f, Msg& msg, int32 x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddInt32(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetInt32(msg.msg_, f, x); - } - } - - static void SetUInt32(Field f, Msg& msg, uint32 x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddUInt32(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetUInt32(msg.msg_, f, x); - } - } - - static void SetBool(Field f, Msg& msg, bool x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddBool(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetBool(msg.msg_, f, x); - } - } - - static void SetString(Field f, Msg& msg, absl::string_view x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddString(msg.msg_, f, std::string(x)); - } else { - msg.msg_->GetReflection()->SetString(msg.msg_, f, std::string(x)); - } - } - - static void SetEnum(Field f, Msg& msg, int32_t x) { - RecordAsSeen(f, msg); - if (f->is_repeated()) { - msg.msg_->GetReflection()->AddEnumValue(msg.msg_, f, x); - } else { - msg.msg_->GetReflection()->SetEnumValue(msg.msg_, f, x); - } - } -}; - -// Traits for proto3-ish deserialization. -// -// This includes a rudimentary proto serializer, since message fields are -// written directly instead of being reflectively written to a proto field. -// -// See MessageTraits for API docs. -struct ParseProto3Type : Proto3Type { - class Msg { - public: - explicit Msg(io::ZeroCopyOutputStream* stream) : stream_(stream) {} - - private: - friend ParseProto3Type; - io::CodedOutputStream stream_; - absl::flat_hash_set parsed_oneofs_indices_; - absl::flat_hash_set parsed_fields_; - }; - - static bool HasParsed(Field f, const Msg& msg, - bool allow_repeated_non_oneof) { - if (f->proto().oneof_index() != 0) { - return msg.parsed_oneofs_indices_.contains(f->proto().oneof_index()); - } - if (allow_repeated_non_oneof) { - return false; - } - return msg.parsed_fields_.contains(f->proto().number()); - } - - /// Functions for writing fields. /// - - static void RecordAsSeen(Field f, Msg& msg) { - msg.parsed_fields_.insert(f->proto().number()); - if (f->proto().oneof_index() != 0) { - msg.parsed_oneofs_indices_.insert(f->proto().oneof_index()); - } - } - - template - static absl::Status NewMsg(Field f, Msg& msg, F body) { - return NewDynamic(f, f->proto().type_url(), msg, body); - } - - template - static absl::Status NewDynamic(Field f, const std::string& type_url, Msg& msg, - F body) { - RecordAsSeen(f, msg); - return WithDynamicType( - f->parent(), type_url, [&](const Desc& desc) -> absl::Status { - if (f->proto().kind() == google::protobuf::Field::TYPE_GROUP) { - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_START_GROUP); - RETURN_IF_ERROR(body(desc, msg)); - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_END_GROUP); - return absl::OkStatus(); - } - - std::string out; - io::StringOutputStream stream(&out); - Msg new_msg(&stream); - RETURN_IF_ERROR(body(desc, new_msg)); - - new_msg.stream_.Trim(); // Should probably be called "Flush()". - absl::string_view written( - out.data(), static_cast(new_msg.stream_.ByteCount())); - SetString(f, msg, written); - return absl::OkStatus(); - }); - } - - static void SetFloat(Field f, Msg& msg, float x) { - RecordAsSeen(f, msg); - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_FIXED32); - msg.stream_.WriteLittleEndian32(absl::bit_cast(x)); - } - - static void SetDouble(Field f, Msg& msg, double x) { - RecordAsSeen(f, msg); - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_FIXED64); - msg.stream_.WriteLittleEndian64(absl::bit_cast(x)); - } - - static void SetInt64(Field f, Msg& msg, int64_t x) { - SetInt(f, msg, x); - } - - static void SetUInt64(Field f, Msg& msg, uint64_t x) { - SetInt(f, msg, x); - } - - static void SetInt32(Field f, Msg& msg, int32_t x) { - SetInt(f, msg, x); - } - - static void SetUInt32(Field f, Msg& msg, uint32_t x) { - SetInt(f, msg, x); - } - - static void SetBool(Field f, Msg& msg, bool x) { - RecordAsSeen(f, msg); - msg.stream_.WriteTag(f->proto().number() << 3); - char b = x ? 0x01 : 0x00; - msg.stream_.WriteRaw(&b, 1); - } - - static void SetString(Field f, Msg& msg, absl::string_view x) { - RecordAsSeen(f, msg); - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_LENGTH_DELIMITED); - msg.stream_.WriteVarint64(static_cast(x.size())); - msg.stream_.WriteRaw(x.data(), x.size()); - } - - static void SetEnum(Field f, Msg& msg, int32_t x) { - RecordAsSeen(f, msg); - msg.stream_.WriteTag(f->proto().number() << 3); - // Sign extension is deliberate here. - msg.stream_.WriteVarint32(x); - } - - private: - using Kind = google::protobuf::Field::Kind; - // Sets a field of *some* integer type, with the given kinds for the possible - // encodings. This avoids quadruplicating this code in the helpers for the - // four major integer types. - template - static void SetInt(Field f, Msg& msg, Int x) { - RecordAsSeen(f, msg); - switch (f->proto().kind()) { - case zigzag: - // Regardless of the integer type, ZigZag64 will do the right thing, - // because ZigZag is not dependent on the width of the integer: it is - // always `2 * abs(n) + (n < 0)`. - x = static_cast( - internal::WireFormatLite::ZigZagEncode64(static_cast(x))); - ABSL_FALLTHROUGH_INTENDED; - case varint: - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_VARINT); - if (sizeof(Int) == 4) { - msg.stream_.WriteVarint32(static_cast(x)); - } else { - msg.stream_.WriteVarint64(static_cast(x)); - } - break; - case fixed: { - if (sizeof(Int) == 4) { - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_FIXED32); - msg.stream_.WriteLittleEndian32(static_cast(x)); - } else { - msg.stream_.WriteTag(f->proto().number() << 3 | - WireFormatLite::WIRETYPE_FIXED64); - msg.stream_.WriteLittleEndian64(static_cast(x)); - } - break; - } - default: { // Unreachable. - } - } - } -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_PARSER_TRAITS_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/test_input_stream.h b/libs/protobuf/src/google/protobuf/json/internal/test_input_stream.h deleted file mode 100644 index 1a05c9b..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/test_input_stream.h +++ /dev/null @@ -1,106 +0,0 @@ -// 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_UTIL_TEST_INPUT_STREAM_H__ -#define GOOGLE_PROTOBUF_UTIL_TEST_INPUT_STREAM_H__ - -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status_macros.h" - -namespace google { -namespace protobuf { -namespace json_internal { -// A ZeroCopyInputStream for writing unit tests. -class TestInputStream final : public io::ZeroCopyInputStream { - public: - TestInputStream(std::initializer_list strings) - : strings_(strings) {} - explicit TestInputStream(std::vector strings) - : strings_(std::move(strings)) {} - ~TestInputStream() override = default; - - size_t Consumed() const { return next_; } - - bool Next(const void** data, int* size) override { - if (next_ == strings_.size()) { - return false; - } - - if (next_ > 0) { - // Destroy the previous string so that ASAN can catch misbehavior - // correctly. - ReconstructAt(&strings_[next_ - 1]); - } - - absl::string_view next = strings_[next_++]; - *data = next.data(); - *size = static_cast(next.size()); - return true; - } - - // TestInputStream currently does not support these members. - void BackUp(int) override { GOOGLE_CHECK(false); } - bool Skip(int) override { - GOOGLE_CHECK(false); - return false; - } - int64_t ByteCount() const override { - GOOGLE_CHECK(false); - return 0; - } - - private: - // Some versions of Clang can't figure out that - // x.std::string::~string() - // is valid syntax, so we indirect through a type param, instead. - // - // Of course, our luck has it that std::destroy_at is a C++17 feature. :) - template - static void ReconstructAt(T* p) { - p->~T(); - new (p) T; - } - - std::vector strings_; - size_t next_ = 0; -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_UTIL_TEST_INPUT_STREAM_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/unparser.cc b/libs/protobuf/src/google/protobuf/json/internal/unparser.cc deleted file mode 100644 index 6b83019..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/unparser.cc +++ /dev/null @@ -1,880 +0,0 @@ -// 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/json/internal/unparser.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "absl/status/status.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/json/internal/descriptor_traits.h" -#include "google/protobuf/json/internal/unparser_traits.h" -#include "google/protobuf/json/internal/writer.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -namespace { -template -bool IsEmpty(const Msg& msg, const Desc& desc) { - size_t count = Traits::FieldCount(desc); - for (size_t i = 0; i < count; ++i) { - if (Traits::GetSize(Traits::FieldByIndex(desc, i), msg) > 0) { - return false; - } - } - return true; -} - -enum class IntegerEnumStyle { - kQuoted, - kUnquoted, -}; - -template -void WriteEnum(JsonWriter& writer, Field field, int32_t value, - IntegerEnumStyle int_style = IntegerEnumStyle::kUnquoted) { - if (ClassifyMessage(Traits::FieldTypeName(field)) == MessageType::kNull) { - writer.Write("null"); - return; - } - - if (!writer.options().always_print_enums_as_ints) { - auto name = Traits::EnumNameByNumber(field, value); - if (name.ok()) { - writer.Write("\"", *name, "\""); - return; - } - } - - if (int_style == IntegerEnumStyle::kQuoted) { - writer.Write("\"", value, "\""); - } else { - writer.Write(value); - } -} - -// Mutually recursive with functions that follow. -template -absl::Status WriteMessage(JsonWriter& writer, const Msg& msg, - const Desc& desc, bool is_top_level = false); - -// This is templatized so that defaults, singular, and repeated fields can both -// use the same enormous switch-case. -template -absl::Status WriteSingular(JsonWriter& writer, Field field, - Args&&... args) { - // When the pack `args` is empty, the caller has requested printing the - // default value. - bool is_default = sizeof...(Args) == 0; - switch (Traits::FieldType(field)) { - case FieldDescriptor::TYPE_FLOAT: { - auto x = Traits::GetFloat(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - if (writer.options().allow_legacy_syntax && is_default && - !std::isfinite(*x)) { - *x = 0; - } - writer.Write(*x); - break; - } - case FieldDescriptor::TYPE_DOUBLE: { - auto x = Traits::GetDouble(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - if (writer.options().allow_legacy_syntax && is_default && - !std::isfinite(*x)) { - *x = 0; - } - writer.Write(*x); - break; - } - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_INT64: { - auto x = Traits::GetInt64(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_UINT64: { - auto x = Traits::GetUInt64(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_INT32: { - auto x = Traits::GetInt32(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(*x); - break; - } - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_UINT32: { - auto x = Traits::GetUInt32(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(*x); - break; - } - case FieldDescriptor::TYPE_BOOL: { - auto x = Traits::GetBool(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(*x ? "true" : "false"); - break; - } - case FieldDescriptor::TYPE_STRING: { - auto x = Traits::GetString(field, writer.ScratchBuf(), - std::forward(args)...); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_BYTES: { - auto x = Traits::GetString(field, writer.ScratchBuf(), - std::forward(args)...); - RETURN_IF_ERROR(x.status()); - if (writer.options().allow_legacy_syntax && is_default) { - // Although difficult to verify, it appears that the original ESF parser - // fails to unescape the contents of a - // google.protobuf.Field.default_value, which may potentially be - // escaped if it is for a `bytes` field (note that default_value is a - // `string` regardless of what type the field is). - // - // However, our parser's type.proto guts actually know to do this - // correctly, so this bug must be manually re-introduced. - writer.WriteBase64(absl::CEscape(*x)); - } else { - writer.WriteBase64(*x); - } - break; - } - case FieldDescriptor::TYPE_ENUM: { - auto x = Traits::GetEnumValue(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - WriteEnum(writer, field, *x); - break; - } - case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_GROUP: { - auto x = Traits::GetMessage(field, std::forward(args)...); - RETURN_IF_ERROR(x.status()); - return WriteMessage(writer, **x, Traits::GetDesc(**x)); - } - default: - return absl::InvalidArgumentError( - absl::StrCat("unsupported field type: ", Traits::FieldType(field))); - } - - return absl::OkStatus(); -} - -template -absl::Status WriteRepeated(JsonWriter& writer, const Msg& msg, - Field field) { - writer.Write("["); - writer.Push(); - - size_t count = Traits::GetSize(field, msg); - bool first = true; - for (size_t i = 0; i < count; ++i) { - if (ClassifyMessage(Traits::FieldTypeName(field)) == MessageType::kValue) { - bool empty = false; - RETURN_IF_ERROR(Traits::WithFieldType( - field, [&](const Desc& desc) -> absl::Status { - auto inner = Traits::GetMessage(field, msg, i); - RETURN_IF_ERROR(inner.status()); - empty = IsEmpty(**inner, desc); - return absl::OkStatus(); - })); - - // Empty google.protobuf.Values are silently discarded. - if (empty) { - continue; - } - } - writer.WriteComma(first); - writer.NewLine(); - RETURN_IF_ERROR(WriteSingular(writer, field, msg, i)); - } - - writer.Pop(); - if (!first) { - writer.NewLine(); - } - writer.Write("]"); - return absl::OkStatus(); -} - -template -absl::Status WriteMapKey(JsonWriter& writer, const Msg& entry, - Field field) { - switch (Traits::FieldType(field)) { - case FieldDescriptor::TYPE_SFIXED64: - case FieldDescriptor::TYPE_SINT64: - case FieldDescriptor::TYPE_INT64: { - auto x = Traits::GetInt64(field, entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_FIXED64: - case FieldDescriptor::TYPE_UINT64: { - auto x = Traits::GetUInt64(field, entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_SFIXED32: - case FieldDescriptor::TYPE_SINT32: - case FieldDescriptor::TYPE_INT32: { - auto x = Traits::GetInt32(field, entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_FIXED32: - case FieldDescriptor::TYPE_UINT32: { - auto x = Traits::GetUInt32(field, entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_BOOL: { - auto x = Traits::GetBool(field, entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x ? "true" : "false")); - break; - } - case FieldDescriptor::TYPE_STRING: { - auto x = Traits::GetString(field, writer.ScratchBuf(), entry); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - break; - } - case FieldDescriptor::TYPE_ENUM: { - auto x = Traits::GetEnumValue(field, entry); - RETURN_IF_ERROR(x.status()); - WriteEnum(writer, field, *x, IntegerEnumStyle::kQuoted); - break; - } - default: - return absl::InvalidArgumentError( - absl::StrCat("unsupported map key type: ", Traits::FieldType(field))); - } - return absl::OkStatus(); -} - -template -absl::StatusOr IsEmptyValue(const Msg& msg, Field field) { - if (ClassifyMessage(Traits::FieldTypeName(field)) != MessageType::kValue) { - return false; - } - bool empty = false; - RETURN_IF_ERROR(Traits::WithFieldType( - field, [&](const Desc& desc) -> absl::Status { - auto inner = Traits::GetMessage(field, msg); - RETURN_IF_ERROR(inner.status()); - empty = IsEmpty(**inner, desc); - return absl::OkStatus(); - })); - return empty; -} - -template -absl::Status WriteMap(JsonWriter& writer, const Msg& msg, - Field field) { - writer.Write("{"); - writer.Push(); - - size_t count = Traits::GetSize(field, msg); - bool first = true; - for (size_t i = 0; i < count; ++i) { - absl::StatusOr*> entry = - Traits::GetMessage(field, msg, i); - RETURN_IF_ERROR(entry.status()); - const Desc& type = Traits::GetDesc(**entry); - - auto is_empty = IsEmptyValue(**entry, Traits::ValueField(type)); - RETURN_IF_ERROR(is_empty.status()); - if (*is_empty) { - // Empty google.protobuf.Values are silently discarded. - continue; - } - - writer.WriteComma(first); - writer.NewLine(); - RETURN_IF_ERROR( - WriteMapKey(writer, **entry, Traits::KeyField(type))); - writer.Write(":"); - writer.Whitespace(" "); - RETURN_IF_ERROR( - WriteSingular(writer, Traits::ValueField(type), **entry)); - } - - writer.Pop(); - if (!first) { - writer.NewLine(); - } - writer.Write("}"); - return absl::OkStatus(); -} - -template -absl::Status WriteField(JsonWriter& writer, const Msg& msg, - Field field, bool& first) { - if (!Traits::IsRepeated(field)) { // Repeated case is handled in - // WriteRepeated. - auto is_empty = IsEmptyValue(msg, field); - RETURN_IF_ERROR(is_empty.status()); - if (*is_empty) { - // Empty google.protobuf.Values are silently discarded. - return absl::OkStatus(); - } - } - - writer.WriteComma(first); - writer.NewLine(); - - if (Traits::IsExtension(field)) { - writer.Write(MakeQuoted("[", Traits::FieldFullName(field), "]"), ":"); - } else if (writer.options().preserve_proto_field_names) { - writer.Write(MakeQuoted(Traits::FieldName(field)), ":"); - } else { - // The generator for type.proto and the internals of descriptor.cc disagree - // on what the json name of a PascalCase field is supposed to be; type.proto - // seems to (incorrectly?) capitalize the first letter, which is the - // behavior ESF defaults to. To fix this, if the original field name starts - // with an uppercase letter, and the Json name does not, we uppercase it. - absl::string_view original_name = Traits::FieldName(field); - absl::string_view json_name = Traits::FieldJsonName(field); - if (writer.options().allow_legacy_syntax && - absl::ascii_isupper(original_name[0]) && - !absl::ascii_isupper(json_name[0])) { - writer.Write(MakeQuoted(absl::ascii_toupper(original_name[0]), - original_name.substr(1)), - ":"); - } else { - writer.Write(MakeQuoted(json_name), ":"); - } - } - writer.Whitespace(" "); - - if (Traits::IsMap(field)) { - return WriteMap(writer, msg, field); - } else if (Traits::IsRepeated(field)) { - return WriteRepeated(writer, msg, field); - } else if (Traits::GetSize(field, msg) == 0) { - // We can only get here if always_print_primitive_fields is true. - GOOGLE_DCHECK(writer.options().always_print_primitive_fields); - - if (Traits::FieldType(field) == FieldDescriptor::TYPE_GROUP) { - // We do not yet have full group support, but this is required so that we - // pass the same tests as the ESF parser. - writer.Write("null"); - return absl::OkStatus(); - } - return WriteSingular(writer, field); - } - - return WriteSingular(writer, field, msg); -} - -template -absl::Status WriteFields(JsonWriter& writer, const Msg& msg, - const Desc& desc, bool& first) { - std::vector> fields; - size_t total = Traits::FieldCount(desc); - fields.reserve(total); - for (size_t i = 0; i < total; ++i) { - Field field = Traits::FieldByIndex(desc, i); - - bool has = Traits::GetSize(field, msg) > 0; - if (writer.options().always_print_primitive_fields) { - bool is_singular_message = - !Traits::IsRepeated(field) && - Traits::FieldType(field) == FieldDescriptor::TYPE_MESSAGE; - has |= !is_singular_message && !Traits::IsOneof(field); - } - - if (has) { - fields.push_back(field); - } - } - - // Add extensions *before* sorting. - Traits::FindAndAppendExtensions(msg, fields); - - // Fields are guaranteed to be serialized in field number order. - absl::c_sort(fields, [](const auto& a, const auto& b) { - return Traits::FieldNumber(a) < Traits::FieldNumber(b); - }); - - for (auto field : fields) { - RETURN_IF_ERROR(WriteField(writer, msg, field, first)); - } - - return absl::OkStatus(); -} - -template -absl::Status WriteStructValue(JsonWriter& writer, const Msg& msg, - const Desc& desc); -template -absl::Status WriteListValue(JsonWriter& writer, const Msg& msg, - const Desc& desc); - -template -absl::Status WriteValue(JsonWriter& writer, const Msg& msg, - const Desc& desc, bool is_top_level) { - // NOTE: The field numbers 1 through 6 are the numbers of the oneof fields in - // google.protobuf.Value. Conformance tests verify the correctness of these - // numbers. - if (Traits::GetSize(Traits::MustHaveField(desc, 1), msg) > 0) { - writer.Write("null"); - return absl::OkStatus(); - } - - auto number_field = Traits::MustHaveField(desc, 2); - if (Traits::GetSize(number_field, msg) > 0) { - auto x = Traits::GetDouble(number_field, msg); - RETURN_IF_ERROR(x.status()); - writer.Write(*x); - return absl::OkStatus(); - } - - auto string_field = Traits::MustHaveField(desc, 3); - if (Traits::GetSize(string_field, msg) > 0) { - auto x = Traits::GetString(string_field, writer.ScratchBuf(), msg); - RETURN_IF_ERROR(x.status()); - writer.Write(MakeQuoted(*x)); - return absl::OkStatus(); - } - - auto bool_field = Traits::MustHaveField(desc, 4); - if (Traits::GetSize(bool_field, msg) > 0) { - auto x = Traits::GetBool(bool_field, msg); - RETURN_IF_ERROR(x.status()); - writer.Write(*x ? "true" : "false"); - return absl::OkStatus(); - } - - auto struct_field = Traits::MustHaveField(desc, 5); - if (Traits::GetSize(struct_field, msg) > 0) { - auto x = Traits::GetMessage(struct_field, msg); - RETURN_IF_ERROR(x.status()); - return Traits::WithFieldType(struct_field, [&](const Desc& type) { - return WriteStructValue(writer, **x, type); - }); - } - - auto list_field = Traits::MustHaveField(desc, 6); - if (Traits::GetSize(list_field, msg) > 0) { - auto x = Traits::GetMessage(list_field, msg); - RETURN_IF_ERROR(x.status()); - return Traits::WithFieldType(list_field, [&](const Desc& type) { - return WriteListValue(writer, **x, type); - }); - } - - GOOGLE_CHECK(is_top_level) << "empty, non-top-level Value must be handled one layer " - "up, since it prints an empty string; reaching this " - "statement is always a bug"; - return absl::OkStatus(); -} - -template -absl::Status WriteStructValue(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - return WriteMap(writer, msg, Traits::MustHaveField(desc, 1)); -} - -template -absl::Status WriteListValue(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - return WriteRepeated(writer, msg, Traits::MustHaveField(desc, 1)); -} - -template -absl::Status WriteTimestamp(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - auto secs_field = Traits::MustHaveField(desc, 1); - auto secs = Traits::GetSize(secs_field, msg) > 0 - ? Traits::GetInt64(secs_field, msg) - : 0; - RETURN_IF_ERROR(secs.status()); - - if (*secs < -62135596800) { - return absl::InvalidArgumentError( - "minimum acceptable time value is 0001-01-01T00:00:00Z"); - } else if (*secs > 253402300799) { - return absl::InvalidArgumentError( - "maximum acceptable time value is 9999-12-31T23:59:59Z"); - } - - // Ensure seconds is positive. - *secs += 62135596800; - - auto nanos_field = Traits::MustHaveField(desc, 2); - auto nanos = Traits::GetSize(nanos_field, msg) > 0 - ? Traits::GetInt32(nanos_field, msg) - : 0; - RETURN_IF_ERROR(nanos.status()); - - // Julian Day -> Y/M/D, Algorithm from: - // Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for - // Processing Calendar Dates," Communications of the Association of - // Computing Machines, vol. 11 (1968), p. 657. - int32_t L, N, I, J, K; - L = static_cast(*secs / 86400) - 719162 + 68569 + 2440588; - N = 4 * L / 146097; - L = L - (146097 * N + 3) / 4; - I = 4000 * (L + 1) / 1461001; - L = L - 1461 * I / 4 + 31; - J = 80 * L / 2447; - K = L - 2447 * J / 80; - L = J / 11; - J = J + 2 - 12 * L; - I = 100 * (N - 49) + I + L; - - int32_t sec = *secs % 60; - int32_t min = (*secs / 60) % 60; - int32_t hour = (*secs / 3600) % 24; - - if (*nanos == 0) { - writer.Write(absl::StrFormat(R"("%04d-%02d-%02dT%02d:%02d:%02dZ")", I, J, K, - hour, min, sec)); - return absl::OkStatus(); - } - - size_t digits = 9; - uint32_t frac_seconds = std::abs(*nanos); - while (frac_seconds % 1000 == 0) { - frac_seconds /= 1000; - digits -= 3; - } - - writer.Write(absl::StrFormat(R"("%04d-%02d-%02dT%02d:%02d:%02d.%.*dZ")", I, J, - K, hour, min, sec, digits, frac_seconds)); - return absl::OkStatus(); -} - -template -absl::Status WriteDuration(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - constexpr int64_t kMaxSeconds = int64_t{3652500} * 86400; - constexpr int64_t kMaxNanos = 999999999; - - auto secs_field = Traits::MustHaveField(desc, 1); - auto secs = Traits::GetSize(secs_field, msg) > 0 - ? Traits::GetInt64(secs_field, msg) - : 0; - RETURN_IF_ERROR(secs.status()); - - if (*secs > kMaxSeconds || *secs < -kMaxSeconds) { - return absl::InvalidArgumentError("duration out of range"); - } - - auto nanos_field = Traits::MustHaveField(desc, 2); - auto nanos = Traits::GetSize(nanos_field, msg) > 0 - ? Traits::GetInt32(nanos_field, msg) - : 0; - RETURN_IF_ERROR(nanos.status()); - - if (*nanos > kMaxNanos || *nanos < -kMaxNanos) { - return absl::InvalidArgumentError("duration out of range"); - } - if ((*secs != 0) && (*nanos != 0) && ((*secs < 0) != (*nanos < 0))) { - return absl::InvalidArgumentError("nanos and seconds signs do not match"); - } - - if (*nanos == 0) { - writer.Write(absl::StrFormat(R"("%ds")", *secs)); - return absl::OkStatus(); - } - - size_t digits = 9; - uint32_t frac_seconds = std::abs(*nanos); - while (frac_seconds % 1000 == 0) { - frac_seconds /= 1000; - digits -= 3; - } - - absl::string_view sign = ((*secs < 0) || (*nanos < 0)) ? "-" : ""; - writer.Write(absl::StrFormat(R"("%s%d.%.*ds")", sign, std::abs(*secs), digits, - frac_seconds)); - return absl::OkStatus(); -} - -template -absl::Status WriteFieldMask(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - // google.protobuf.FieldMask has a single field with number 1. - auto paths_field = Traits::MustHaveField(desc, 1); - size_t paths = Traits::GetSize(paths_field, msg); - writer.Write('"'); - - bool first = true; - for (size_t i = 0; i < paths; ++i) { - writer.WriteComma(first); - auto path = Traits::GetString(paths_field, writer.ScratchBuf(), msg, i); - RETURN_IF_ERROR(path.status()); - bool saw_under = false; - for (char c : *path) { - if (absl::ascii_islower(c) && saw_under) { - writer.Write(absl::ascii_toupper(c)); - } else if (absl::ascii_isdigit(c) || absl::ascii_islower(c) || c == '.') { - writer.Write(c); - } else if (c == '_' && - (!saw_under || writer.options().allow_legacy_syntax)) { - saw_under = true; - continue; - } else if (!writer.options().allow_legacy_syntax) { - return absl::InvalidArgumentError("unexpected character in FieldMask"); - } else { - if (saw_under) { - writer.Write('_'); - } - writer.Write(c); - } - saw_under = false; - } - } - writer.Write('"'); - - return absl::OkStatus(); -} - -template -absl::Status WriteAny(JsonWriter& writer, const Msg& msg, - const Desc& desc) { - auto type_url_field = Traits::MustHaveField(desc, 1); - auto value_field = Traits::MustHaveField(desc, 2); - - bool has_type_url = Traits::GetSize(type_url_field, msg) > 0; - bool has_value = Traits::GetSize(value_field, msg) > 0; - if (!has_type_url && !has_value) { - writer.Write("{}"); - return absl::OkStatus(); - } else if (!has_type_url) { - return absl::InvalidArgumentError("broken Any: missing type URL"); - } else if (!has_value && !writer.options().allow_legacy_syntax) { - return absl::InvalidArgumentError("broken Any: missing value"); - } - - writer.Write("{"); - writer.Push(); - - auto type_url = Traits::GetString(type_url_field, writer.ScratchBuf(), msg); - RETURN_IF_ERROR(type_url.status()); - writer.NewLine(); - writer.Write("\"@type\":"); - writer.Whitespace(" "); - writer.Write(MakeQuoted(*type_url)); - - return Traits::WithDynamicType( - desc, std::string(*type_url), - [&](const Desc& any_desc) -> absl::Status { - absl::string_view any_bytes; - if (has_value) { - absl::StatusOr bytes = - Traits::GetString(value_field, writer.ScratchBuf(), msg); - RETURN_IF_ERROR(bytes.status()); - any_bytes = *bytes; - } - - return Traits::WithDecodedMessage( - any_desc, any_bytes, - [&](const Msg& unerased) -> absl::Status { - bool first = false; - if (ClassifyMessage(Traits::TypeName(any_desc)) != - MessageType::kNotWellKnown) { - writer.WriteComma(first); - writer.NewLine(); - writer.Write("\"value\":"); - writer.Whitespace(" "); - RETURN_IF_ERROR( - WriteMessage(writer, unerased, any_desc)); - } else { - RETURN_IF_ERROR( - WriteFields(writer, unerased, any_desc, first)); - } - writer.Pop(); - if (!first) { - writer.NewLine(); - } - writer.Write("}"); - return absl::OkStatus(); - }); - }); -} - -template -absl::Status WriteMessage(JsonWriter& writer, const Msg& msg, - const Desc& desc, bool is_top_level) { - switch (ClassifyMessage(Traits::TypeName(desc))) { - case MessageType::kAny: - return WriteAny(writer, msg, desc); - case MessageType::kWrapper: { - auto field = Traits::MustHaveField(desc, 1); - if (Traits::GetSize(field, msg) == 0) { - return WriteSingular(writer, field); - } - return WriteSingular(writer, field, msg); - } - case MessageType::kValue: - return WriteValue(writer, msg, desc, is_top_level); - case MessageType::kStruct: - return WriteStructValue(writer, msg, desc); - case MessageType::kList: - return WriteListValue(writer, msg, desc); - case MessageType::kTimestamp: - return WriteTimestamp(writer, msg, desc); - case MessageType::kDuration: - return WriteDuration(writer, msg, desc); - case MessageType::kFieldMask: - return WriteFieldMask(writer, msg, desc); - default: { - writer.Write("{"); - writer.Push(); - bool first = true; - RETURN_IF_ERROR(WriteFields(writer, msg, desc, first)); - writer.Pop(); - if (!first) { - writer.NewLine(); - } - writer.Write("}"); - return absl::OkStatus(); - } - } -} -} // namespace - -absl::Status MessageToJsonString(const Message& message, std::string* output, - json_internal::WriterOptions options) { - PROTOBUF_DLOG(INFO) << "json2/input: " << message.DebugString(); - io::StringOutputStream out(output); - JsonWriter writer(&out, options); - absl::Status s = WriteMessage( - writer, message, *message.GetDescriptor(), /*is_top_level=*/true); - PROTOBUF_DLOG(INFO) << "json2/status: " << s; - RETURN_IF_ERROR(s); - - writer.NewLine(); - PROTOBUF_DLOG(INFO) << "json2/output: " << absl::CHexEscape(*output); - return absl::OkStatus(); -} - -absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* binary_input, - io::ZeroCopyOutputStream* json_output, - json_internal::WriterOptions options) { - // NOTE: Most of the contortions in this function are to allow for capture of - // input and output of the parser in GOOGLE_DLOG mode. Destruction order is very - // critical in this function, because io::ZeroCopy*Stream types usually only - // flush on destruction. - - // For GOOGLE_DLOG, we would like to print out the input and output, which requires - // buffering both instead of doing "zero copy". This block, and the one at - // the end of the function, set up and tear down interception of the input - // and output streams. - std::string copy; - std::string out; - absl::optional tee_input; - absl::optional tee_output; - if (PROTOBUF_DEBUG) { - const void* data; - int len; - while (binary_input->Next(&data, &len)) { - copy.resize(copy.size() + len); - std::memcpy(©[copy.size() - len], data, len); - } - tee_input.emplace(copy.data(), copy.size()); - tee_output.emplace(&out); - } - - PROTOBUF_DLOG(INFO) << "json2/input: " << absl::BytesToHexString(copy); - - ResolverPool pool(resolver); - auto desc = pool.FindMessage(type_url); - RETURN_IF_ERROR(desc.status()); - - io::CodedInputStream stream(tee_input.has_value() ? &*tee_input - : binary_input); - auto msg = UntypedMessage::ParseFromStream(*desc, stream); - RETURN_IF_ERROR(msg.status()); - - JsonWriter writer(tee_output.has_value() ? &*tee_output : json_output, - options); - absl::Status s = WriteMessage( - writer, *msg, UnparseProto3Type::GetDesc(*msg), - /*is_top_level=*/true); - PROTOBUF_DLOG(INFO) << "json2/status: " << s; - RETURN_IF_ERROR(s); - - if (PROTOBUF_DEBUG) { - tee_output.reset(); // Flush the output stream. - io::zc_sink_internal::ZeroCopyStreamByteSink(json_output) - .Append(out.data(), out.size()); - } - - PROTOBUF_DLOG(INFO) << "json2/output: " << absl::CHexEscape(out); - - writer.NewLine(); - return absl::OkStatus(); -} -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/unparser.h b/libs/protobuf/src/google/protobuf/json/internal/unparser.h deleted file mode 100644 index a9a935d..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/unparser.h +++ /dev/null @@ -1,59 +0,0 @@ -// 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_JSON_INTERNAL_UNPARSER_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_UNPARSER_H__ - -#include - -#include "google/protobuf/message.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/json/internal/writer.h" -#include "google/protobuf/util/type_resolver.h" - -namespace google { -namespace protobuf { -namespace json_internal { -// Internal version of google::protobuf::util::MessageToJsonString; see json_util.h for -// details. -absl::Status MessageToJsonString(const Message& message, std::string* output, - json_internal::WriterOptions options); -// Internal version of google::protobuf::util::BinaryToJsonStream; see json_util.h for -// details. -absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* binary_input, - io::ZeroCopyOutputStream* json_output, - json_internal::WriterOptions options); -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_UNPARSER_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/unparser_traits.h b/libs/protobuf/src/google/protobuf/json/internal/unparser_traits.h deleted file mode 100644 index 9e1f3ef..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/unparser_traits.h +++ /dev/null @@ -1,443 +0,0 @@ -// 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_JSON_INTERNAL_UNPARSER_TRAITS_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_UNPARSER_TRAITS_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" -#include "absl/container/flat_hash_map.h" -#include "absl/status/status.h" -#include "absl/strings/escaping.h" -#include "absl/strings/numbers.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/variant.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/json/internal/descriptor_traits.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -// The type traits in this file provide describe how to read from protobuf -// representation used by the JSON API, either via proto reflection or via -// something ad-hoc for type.proto. - -// Helper alias templates to avoid needing to write `typename` in function -// signatures. -template -using Msg = typename Traits::Msg; - -// Traits for proto2-ish deserialization. -struct UnparseProto2Descriptor : Proto2Descriptor { - // A message value that fields can be read from. - using Msg = Message; - - static const Desc& GetDesc(const Msg& msg) { return *msg.GetDescriptor(); } - - // Appends extension fields to `fields`. - static void FindAndAppendExtensions(const Msg& msg, - std::vector& fields) { - // Note that it is *not* correct to use ListFields for getting a list of - // fields to write, because the way that JSON decides to print non-extension - // fields is slightly subtle. That logic is handled elsewhere; we're only - // here to get extensions. - std::vector all_fields; - msg.GetReflection()->ListFields(msg, &all_fields); - - for (Field field : all_fields) { - if (field->is_extension()) { - fields.push_back(field); - } - } - } - - static size_t GetSize(Field f, const Msg& msg) { - if (f->is_repeated()) { - return msg.GetReflection()->FieldSize(msg, f); - } else { - return msg.GetReflection()->HasField(msg, f) ? 1 : 0; - } - } - - static absl::StatusOr GetFloat(Field f) { - return f->default_value_float(); - } - - static absl::StatusOr GetDouble(Field f) { - return f->default_value_double(); - } - - static absl::StatusOr GetInt32(Field f) { - return f->default_value_int32(); - } - - static absl::StatusOr GetUInt32(Field f) { - return f->default_value_uint32(); - } - - static absl::StatusOr GetInt64(Field f) { - return f->default_value_int64(); - } - - static absl::StatusOr GetUInt64(Field f) { - return f->default_value_uint64(); - } - - static absl::StatusOr GetBool(Field f) { - return f->default_value_bool(); - } - - static absl::StatusOr GetEnumValue(Field f) { - return f->default_value_enum()->number(); - } - - static absl::StatusOr GetString(Field f, - std::string& scratch) { - return f->default_value_string(); - } - - static absl::StatusOr GetMessage(Field f) { - return absl::InternalError("message fields cannot have defaults"); - } - - static absl::StatusOr GetFloat(Field f, const Msg& msg) { - return msg.GetReflection()->GetFloat(msg, f); - } - - static absl::StatusOr GetDouble(Field f, const Msg& msg) { - return msg.GetReflection()->GetDouble(msg, f); - } - - static absl::StatusOr GetInt32(Field f, const Msg& msg) { - return msg.GetReflection()->GetInt32(msg, f); - } - - static absl::StatusOr GetUInt32(Field f, const Msg& msg) { - return msg.GetReflection()->GetUInt32(msg, f); - } - - static absl::StatusOr GetInt64(Field f, const Msg& msg) { - return msg.GetReflection()->GetInt64(msg, f); - } - - static absl::StatusOr GetUInt64(Field f, const Msg& msg) { - return msg.GetReflection()->GetUInt64(msg, f); - } - - static absl::StatusOr GetBool(Field f, const Msg& msg) { - return msg.GetReflection()->GetBool(msg, f); - } - - static absl::StatusOr GetEnumValue(Field f, const Msg& msg) { - return msg.GetReflection()->GetEnumValue(msg, f); - } - - static absl::StatusOr GetString(Field f, - std::string& scratch, - const Msg& msg) { - return msg.GetReflection()->GetStringReference(msg, f, &scratch); - } - - static absl::StatusOr GetMessage(Field f, const Msg& msg) { - return &msg.GetReflection()->GetMessage(msg, f); - } - - static absl::StatusOr GetFloat(Field f, const Msg& msg, size_t idx) { - return msg.GetReflection()->GetRepeatedFloat(msg, f, idx); - } - - static absl::StatusOr GetDouble(Field f, const Msg& msg, size_t idx) { - return msg.GetReflection()->GetRepeatedDouble(msg, f, idx); - } - - static absl::StatusOr GetInt32(Field f, const Msg& msg, size_t idx) { - return msg.GetReflection()->GetRepeatedInt32(msg, f, idx); - } - - static absl::StatusOr GetUInt32(Field f, const Msg& msg, - size_t idx) { - return msg.GetReflection()->GetRepeatedUInt32(msg, f, idx); - } - - static absl::StatusOr GetInt64(Field f, const Msg& msg, size_t idx) { - return msg.GetReflection()->GetRepeatedInt64(msg, f, idx); - } - - static absl::StatusOr GetUInt64(Field f, const Msg& msg, - size_t idx) { - return msg.GetReflection()->GetRepeatedUInt64(msg, f, idx); - } - - static absl::StatusOr GetBool(Field f, const Msg& msg, size_t idx) { - return msg.GetReflection()->GetRepeatedBool(msg, f, idx); - } - - static absl::StatusOr GetEnumValue(Field f, const Msg& msg, - size_t idx) { - return msg.GetReflection()->GetRepeatedEnumValue(msg, f, idx); - } - - static absl::StatusOr GetString(Field f, - std::string& scratch, - const Msg& msg, - size_t idx) { - return msg.GetReflection()->GetRepeatedStringReference(msg, f, idx, - &scratch); - } - - static absl::StatusOr GetMessage(Field f, const Msg& msg, - size_t idx) { - return &msg.GetReflection()->GetRepeatedMessage(msg, f, idx); - } - - template - static absl::Status WithDecodedMessage(const Desc& desc, - absl::string_view data, F body) { - DynamicMessageFactory factory; - std::unique_ptr unerased(factory.GetPrototype(&desc)->New()); - unerased->ParseFromString(data); - - // Explicitly create a const reference, so that we do not accidentally pass - // a mutable reference to `body`. - const Msg& ref = *unerased; - return body(ref); - } -}; - -struct UnparseProto3Type : Proto3Type { - using Msg = UntypedMessage; - - static const Desc& GetDesc(const Msg& msg) { return msg.desc(); } - - static void FindAndAppendExtensions(const Msg&, std::vector&) { - // type.proto does not support extensions. - } - - static size_t GetSize(Field f, const Msg& msg) { - return msg.Count(f->proto().number()); - } - - static absl::StatusOr GetFloat(Field f) { - if (f->proto().default_value().empty()) { - return 0.0; - } - float x; - if (!absl::SimpleAtof(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetDouble(Field f) { - if (f->proto().default_value().empty()) { - return 0.0; - } - double x; - if (!absl::SimpleAtod(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetInt32(Field f) { - if (f->proto().default_value().empty()) { - return 0; - } - int32_t x; - if (!absl::SimpleAtoi(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetUInt32(Field f) { - if (f->proto().default_value().empty()) { - return 0; - } - uint32_t x; - if (!absl::SimpleAtoi(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetInt64(Field f) { - if (f->proto().default_value().empty()) { - return 0; - } - int64_t x; - if (!absl::SimpleAtoi(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetUInt64(Field f) { - if (f->proto().default_value().empty()) { - return 0; - } - uint64_t x; - if (!absl::SimpleAtoi(f->proto().default_value(), &x)) { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - return x; - } - - static absl::StatusOr GetBool(Field f) { - if (f->proto().default_value().empty()) { - return false; - } else if (f->proto().default_value() == "false") { - return false; - } else if (f->proto().default_value() == "true") { - return true; - } else { - return absl::InternalError(absl::StrCat( - "bad default value in type.proto: ", f->parent().proto().name())); - } - } - - static absl::StatusOr GetEnumValue(Field f) { - if (f->proto().default_value().empty()) { - auto e = f->EnumType(); - RETURN_IF_ERROR(e.status()); - - return (**e).proto().enumvalue(0).number(); - } - return EnumNumberByName(f, f->proto().default_value(), - /*case_insensitive=*/false); - } - - static absl::StatusOr GetString(Field f, - std::string& scratch) { - absl::CUnescape(f->proto().default_value(), &scratch); - return scratch; - } - - static absl::StatusOr GetMessage(Field f) { - return absl::InternalError("message fields cannot have defaults"); - } - - static absl::StatusOr GetFloat(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetDouble(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetInt32(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetUInt32(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetInt64(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetUInt64(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetBool(Field f, const Msg& msg, size_t idx = 0) { - return msg.Get(f->proto().number())[idx] == Msg::kTrue; - } - - static absl::StatusOr GetEnumValue(Field f, const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetString(Field f, - std::string& scratch, - const Msg& msg, - size_t idx = 0) { - return msg.Get(f->proto().number())[idx]; - } - - static absl::StatusOr GetMessage(Field f, const Msg& msg, - size_t idx = 0) { - return &msg.Get(f->proto().number())[idx]; - } - - template - static absl::Status WithDecodedMessage(const Desc& desc, - absl::string_view data, F body) { - io::CodedInputStream stream(reinterpret_cast(data.data()), - data.size()); - auto unerased = Msg::ParseFromStream(&desc, stream); - RETURN_IF_ERROR(unerased.status()); - - // Explicitly create a const reference, so that we do not accidentally pass - // a mutable reference to `body`. - const Msg& ref = *unerased; - return body(ref); - } -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_UNPARSER_TRAITS_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/untyped_message.cc b/libs/protobuf/src/google/protobuf/json/internal/untyped_message.cc deleted file mode 100644 index 0390034..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/untyped_message.cc +++ /dev/null @@ -1,548 +0,0 @@ -// 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/json/internal/untyped_message.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" -#include "absl/container/flat_hash_map.h" -#include "absl/status/status.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/span.h" -#include "absl/types/variant.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/stubs/status_macros.h" - - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -using ::google::protobuf::Field; -using ::google::protobuf::internal::WireFormatLite; - -absl::StatusOr ResolverPool::Field::MessageType() - const { - GOOGLE_CHECK(proto().kind() == google::protobuf::Field::TYPE_MESSAGE || - proto().kind() == google::protobuf::Field::TYPE_GROUP) - << proto().kind(); - if (type_ == nullptr) { - auto type = pool_->FindMessage(proto().type_url()); - RETURN_IF_ERROR(type.status()); - type_ = *type; - } - return reinterpret_cast(type_); -} - -absl::StatusOr ResolverPool::Field::EnumType() - const { - GOOGLE_CHECK(proto().kind() == google::protobuf::Field::TYPE_ENUM) << proto().kind(); - if (type_ == nullptr) { - auto type = pool_->FindEnum(proto().type_url()); - RETURN_IF_ERROR(type.status()); - type_ = *type; - } - return reinterpret_cast(type_); -} - -absl::Span ResolverPool::Message::FieldsByIndex() - const { - if (raw_.fields_size() > 0 && fields_ == nullptr) { - fields_ = std::unique_ptr(new Field[raw_.fields_size()]); - for (size_t i = 0; i < raw_.fields_size(); ++i) { - fields_[i].pool_ = pool_; - fields_[i].raw_ = &raw_.fields(i); - fields_[i].parent_ = this; - } - } - - return absl::MakeSpan(fields_.get(), proto().fields_size()); -} - -const ResolverPool::Field* ResolverPool::Message::FindField( - absl::string_view name) const { - if (raw_.fields_size() == 0) { - return nullptr; - } - - if (fields_by_name_.empty()) { - const Field* found = nullptr; - for (auto& field : FieldsByIndex()) { - if (field.proto().name() == name || field.proto().json_name() == name) { - found = &field; - } - fields_by_name_.try_emplace(field.proto().name(), &field); - fields_by_name_.try_emplace(field.proto().json_name(), &field); - } - return found; - } - - auto it = fields_by_name_.find(name); - return it == fields_by_name_.end() ? nullptr : it->second; -} - -const ResolverPool::Field* ResolverPool::Message::FindField( - int32_t number) const { - if (raw_.fields_size() == 0) { - return nullptr; - } - - bool is_small = raw_.fields_size() < 8; - if (is_small || fields_by_number_.empty()) { - const Field* found = nullptr; - for (auto& field : FieldsByIndex()) { - if (field.proto().number() == number) { - found = &field; - } - if (!is_small) { - fields_by_number_.try_emplace(field.proto().number(), &field); - } - } - return found; - } - - auto it = fields_by_number_.find(number); - return it == fields_by_number_.end() ? nullptr : it->second; -} - -absl::StatusOr ResolverPool::FindMessage( - absl::string_view url) { - auto it = messages_.find(url); - if (it != messages_.end()) { - return it->second.get(); - } - - auto msg = absl::WrapUnique(new Message(this)); - std::string url_buf(url); - RETURN_IF_ERROR(resolver_->ResolveMessageType(url_buf, &msg->raw_)); - - return messages_.try_emplace(std::move(url_buf), std::move(msg)) - .first->second.get(); -} - -absl::StatusOr ResolverPool::FindEnum( - absl::string_view url) { - auto it = enums_.find(url); - if (it != enums_.end()) { - return it->second.get(); - } - - auto enoom = absl::WrapUnique(new Enum(this)); - std::string url_buf(url); - RETURN_IF_ERROR(resolver_->ResolveEnumType(url_buf, &enoom->raw_)); - - return enums_.try_emplace(std::move(url_buf), std::move(enoom)) - .first->second.get(); -} - -absl::Status UntypedMessage::Decode(io::CodedInputStream& stream, - absl::optional current_group) { - while (true) { - std::vector group_stack; - uint32_t tag = stream.ReadTag(); - if (tag == 0) { - return absl::OkStatus(); - } - - int32_t field_number = tag >> 3; - int32_t wire_type = tag & 7; - - // EGROUP markers can show up as "unknown fields", so we need to handle them - // before we even do field lookup. Being inside of a group behaves as if a - // special field has been added to the message. - if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) { - if (!current_group.has_value()) { - return absl::InvalidArgumentError(absl::StrFormat( - "attempted to close group %d before SGROUP tag", field_number)); - } - if (field_number != *current_group) { - return absl::InvalidArgumentError( - absl::StrFormat("attempted to close group %d while inside group %d", - field_number, *current_group)); - } - return absl::OkStatus(); - } - - const auto* field = desc_->FindField(field_number); - if (!group_stack.empty() || field == nullptr) { - // Skip unknown field. If the group-stack is non-empty, we are in the - // process of working through an unknown group. - switch (wire_type) { - case WireFormatLite::WIRETYPE_VARINT: { - uint64_t x; - if (!stream.ReadVarint64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - continue; - } - case WireFormatLite::WIRETYPE_FIXED64: { - uint64_t x; - if (!stream.ReadLittleEndian64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - continue; - } - case WireFormatLite::WIRETYPE_FIXED32: { - uint32_t x; - if (!stream.ReadLittleEndian32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - continue; - } - case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: { - uint32_t x; - if (!stream.ReadVarint32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - stream.Skip(x); - continue; - } - case WireFormatLite::WIRETYPE_START_GROUP: { - group_stack.push_back(field_number); - continue; - } - case WireFormatLite::WIRETYPE_END_GROUP: { - if (group_stack.empty()) { - return absl::InvalidArgumentError(absl::StrFormat( - "attempted to close group %d before SGROUP tag", field_number)); - } - if (field_number != group_stack.back()) { - return absl::InvalidArgumentError(absl::StrFormat( - "attempted to close group %d while inside group %d", - field_number, *current_group)); - } - group_stack.pop_back(); - continue; - } - default: - return absl::InvalidArgumentError( - absl::StrCat("unknown wire type: ", wire_type)); - } - } - switch (wire_type) { - case WireFormatLite::WIRETYPE_VARINT: - RETURN_IF_ERROR(DecodeVarint(stream, *field)); - break; - case WireFormatLite::WIRETYPE_FIXED64: - RETURN_IF_ERROR(Decode64Bit(stream, *field)); - break; - case WireFormatLite::WIRETYPE_FIXED32: - RETURN_IF_ERROR(Decode32Bit(stream, *field)); - break; - case WireFormatLite::WIRETYPE_LENGTH_DELIMITED: - RETURN_IF_ERROR(DecodeDelimited(stream, *field)); - break; - case WireFormatLite::WIRETYPE_START_GROUP: { - if (field->proto().kind() != Field::TYPE_GROUP) { - return absl::InvalidArgumentError(absl::StrFormat( - "field number %d is not a group", field->proto().number())); - } - auto group_desc = field->MessageType(); - RETURN_IF_ERROR(group_desc.status()); - - UntypedMessage group(*group_desc); - RETURN_IF_ERROR(group.Decode(stream, field_number)); - RETURN_IF_ERROR(InsertField(*field, std::move(group))); - break; - } - case WireFormatLite::WIRETYPE_END_GROUP: - GOOGLE_CHECK(false) << "unreachable"; - break; - default: - return absl::InvalidArgumentError( - absl::StrCat("unknown wire type: ", wire_type)); - } - } - - return absl::OkStatus(); -} - -absl::Status UntypedMessage::DecodeVarint(io::CodedInputStream& stream, - const ResolverPool::Field& field) { - switch (field.proto().kind()) { - case Field::TYPE_BOOL: { - char byte; - if (!stream.ReadRaw(&byte, 1)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - switch (byte) { - case 0: - RETURN_IF_ERROR(InsertField(field, kFalse)); - break; - case 1: - RETURN_IF_ERROR(InsertField(field, kTrue)); - break; - default: - return absl::InvalidArgumentError( - absl::StrFormat("bad value for bool: \\x%02x", byte)); - } - break; - } - case Field::TYPE_INT32: - case Field::TYPE_SINT32: - case Field::TYPE_UINT32: - case Field::TYPE_ENUM: { - uint32_t x; - if (!stream.ReadVarint32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - if (field.proto().kind() == Field::TYPE_UINT32) { - RETURN_IF_ERROR(InsertField(field, x)); - break; - } - if (field.proto().kind() == Field::TYPE_SINT32) { - x = WireFormatLite::ZigZagDecode32(x); - } - RETURN_IF_ERROR(InsertField(field, static_cast(x))); - break; - } - case Field::TYPE_INT64: - case Field::TYPE_SINT64: - case Field::TYPE_UINT64: { - uint64_t x; - if (!stream.ReadVarint64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - if (field.proto().kind() == Field::TYPE_UINT64) { - RETURN_IF_ERROR(InsertField(field, x)); - break; - } - if (field.proto().kind() == Field::TYPE_SINT64) { - x = WireFormatLite::ZigZagDecode64(x); - } - RETURN_IF_ERROR(InsertField(field, static_cast(x))); - break; - } - default: - return absl::InvalidArgumentError(absl::StrFormat( - "field type %d (number %d) does not support varint fields", - field.proto().kind(), field.proto().number())); - } - return absl::OkStatus(); -} - -absl::Status UntypedMessage::Decode64Bit(io::CodedInputStream& stream, - const ResolverPool::Field& field) { - switch (field.proto().kind()) { - case Field::TYPE_FIXED64: { - uint64_t x; - if (!stream.ReadLittleEndian64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, x)); - break; - } - case Field::TYPE_SFIXED64: { - uint64_t x; - if (!stream.ReadLittleEndian64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, static_cast(x))); - break; - } - case Field::TYPE_DOUBLE: { - uint64_t x; - if (!stream.ReadLittleEndian64(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, absl::bit_cast(x))); - break; - } - default: - return absl::InvalidArgumentError( - absl::StrFormat("field type %d (number %d) does not support " - "type 64-bit fields", - field.proto().kind(), field.proto().number())); - } - return absl::OkStatus(); -} - -absl::Status UntypedMessage::Decode32Bit(io::CodedInputStream& stream, - const ResolverPool::Field& field) { - switch (field.proto().kind()) { - case Field::TYPE_FIXED32: { - uint32_t x; - if (!stream.ReadLittleEndian32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, x)); - break; - } - case Field::TYPE_SFIXED32: { - uint32_t x; - if (!stream.ReadLittleEndian32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, static_cast(x))); - break; - } - case Field::TYPE_FLOAT: { - uint32_t x; - if (!stream.ReadLittleEndian32(&x)) { - return absl::InvalidArgumentError("unexpected EOF"); - } - RETURN_IF_ERROR(InsertField(field, absl::bit_cast(x))); - break; - } - default: - return absl::InvalidArgumentError(absl::StrFormat( - "field type %d (number %d) does not support 32-bit fields", - field.proto().kind(), field.proto().number())); - } - return absl::OkStatus(); -} - -absl::Status UntypedMessage::DecodeDelimited(io::CodedInputStream& stream, - const ResolverPool::Field& field) { - auto limit = stream.ReadLengthAndPushLimit(); - if (limit == 0) { - return absl::InvalidArgumentError("unexpected EOF"); - } - - switch (field.proto().kind()) { - case Field::TYPE_STRING: - case Field::TYPE_BYTES: { - std::string buf; - if (!stream.ReadString(&buf, stream.BytesUntilLimit())) { - return absl::InvalidArgumentError("unexpected EOF"); - } - if (field.proto().kind() == Field::TYPE_STRING) { - if (desc_->proto().syntax() == google::protobuf::SYNTAX_PROTO3 && - ::google::protobuf::internal::IsStructurallyValidUTF8(buf.data(), buf.size())) { - return absl::InvalidArgumentError("proto3 strings must be UTF-8"); - } - } - - RETURN_IF_ERROR(InsertField(field, std::move(buf))); - break; - } - case Field::TYPE_MESSAGE: { - auto inner_desc = field.MessageType(); - RETURN_IF_ERROR(inner_desc.status()); - - auto inner = ParseFromStream(*inner_desc, stream); - RETURN_IF_ERROR(inner.status()); - RETURN_IF_ERROR(InsertField(field, std::move(*inner))); - break; - } - default: { - // This is definitely a packed field. - while (stream.BytesUntilLimit() > 0) { - switch (field.proto().kind()) { - case Field::TYPE_BOOL: - case Field::TYPE_INT32: - case Field::TYPE_SINT32: - case Field::TYPE_UINT32: - case Field::TYPE_ENUM: - case Field::TYPE_INT64: - case Field::TYPE_SINT64: - case Field::TYPE_UINT64: - RETURN_IF_ERROR(DecodeVarint(stream, field)); - break; - case Field::TYPE_FIXED64: - case Field::TYPE_SFIXED64: - case Field::TYPE_DOUBLE: - RETURN_IF_ERROR(Decode64Bit(stream, field)); - break; - case Field::TYPE_FIXED32: - case Field::TYPE_SFIXED32: - case Field::TYPE_FLOAT: - RETURN_IF_ERROR(Decode32Bit(stream, field)); - break; - default: - return absl::InvalidArgumentError(absl::StrFormat( - "field type %d (number %d) does not support type 2 records", - field.proto().kind(), field.proto().number())); - } - } - break; - } - } - stream.PopLimit(limit); - return absl::OkStatus(); -} - -template -absl::Status UntypedMessage::InsertField(const ResolverPool::Field& field, - T value) { - int32_t number = field.proto().number(); - auto emplace_result = fields_.try_emplace(number, std::move(value)); - if (emplace_result.second) { - return absl::OkStatus(); - } - - if (field.proto().cardinality() != - google::protobuf::Field::CARDINALITY_REPEATED) { - return absl::InvalidArgumentError( - absl::StrCat("repeated entries for singular field number ", number)); - } - - Value& slot = emplace_result.first->second; - if (auto* extant = absl::get_if(&slot)) { - std::vector repeated; - repeated.push_back(std::move(*extant)); - repeated.push_back(std::move(value)); - - slot = std::move(repeated); - } else if (auto* extant = absl::get_if>(&slot)) { - extant->push_back(std::move(value)); - } else { - return absl::InvalidArgumentError( - absl::StrFormat("inconsistent types for field number %d: tried to " - "insert %s, but index was %d", - number, typeid(T).name(), slot.index())); - } - - return absl::OkStatus(); -} - -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/untyped_message.h b/libs/protobuf/src/google/protobuf/json/internal/untyped_message.h deleted file mode 100644 index 1b4ad8f..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/untyped_message.h +++ /dev/null @@ -1,258 +0,0 @@ -// 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_UITL_UNTYPED_MESSAGE_H__ -#define GOOGLE_PROTOBUF_UITL_UNTYPED_MESSAGE_H__ - -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/type.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/message.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" -#include "absl/container/flat_hash_map.h" -#include "absl/status/status.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "absl/types/span.h" -#include "absl/types/variant.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -struct SizeVisitor { - template - size_t operator()(const std::vector& x) { - return x.size(); - } - - template - size_t operator()(const T& x) { - return 1; - } -}; - -// A DescriptorPool-like type for caching lookups from a TypeResolver. -// -// This type and all of its nested types are thread-hostile. -class ResolverPool { - public: - class Message; - class Enum; - class Field { - public: - Field(const Field&) = delete; - Field& operator=(const Field&) = delete; - - absl::StatusOr MessageType() const; - absl::StatusOr EnumType() const; - - const Message& parent() const { return *parent_; } - const google::protobuf::Field& proto() const { return *raw_; } - - private: - friend class ResolverPool; - - Field() = default; - - ResolverPool* pool_ = nullptr; - const google::protobuf::Field* raw_ = nullptr; - const Message* parent_ = nullptr; - mutable const void* type_ = nullptr; - }; - - class Message { - public: - Message(const Message&) = delete; - Message& operator=(const Message&) = delete; - - absl::Span FieldsByIndex() const; - const Field* FindField(absl::string_view name) const; - const Field* FindField(int32_t number) const; - - const google::protobuf::Type& proto() const { return raw_; } - ResolverPool* pool() const { return pool_; } - - private: - friend class ResolverPool; - - explicit Message(ResolverPool* pool) : pool_(pool) {} - - ResolverPool* pool_; - google::protobuf::Type raw_; - mutable std::unique_ptr fields_; - mutable absl::flat_hash_map - fields_by_name_; - mutable absl::flat_hash_map fields_by_number_; - }; - - class Enum { - public: - Enum(const Enum&) = delete; - Enum& operator=(const Enum&) = delete; - - const google::protobuf::Enum& proto() const { return raw_; } - ResolverPool* pool() const { return pool_; } - - private: - friend class ResolverPool; - - explicit Enum(ResolverPool* pool) : pool_(pool) {} - - ResolverPool* pool_; - google::protobuf::Enum raw_; - mutable absl::flat_hash_map - values_; - }; - - explicit ResolverPool(google::protobuf::util::TypeResolver* resolver) - : resolver_(resolver) {} - - ResolverPool(const ResolverPool&) = delete; - ResolverPool& operator=(const ResolverPool&) = delete; - - absl::StatusOr FindMessage(absl::string_view url); - absl::StatusOr FindEnum(absl::string_view url); - - private: - absl::flat_hash_map> messages_; - absl::flat_hash_map> enums_; - google::protobuf::util::TypeResolver* resolver_; -}; - -// A parsed wire-format proto that uses TypeReslover for parsing. -// -// This type is an implementation detail of the JSON parser. -class UntypedMessage final { - public: - // New nominal type instead of `bool` to avoid vector shenanigans. - enum Bool : unsigned char { kTrue, kFalse }; - using Value = absl::variant, std::vector, - std::vector, std::vector, - std::vector, std::vector, - std::vector, std::vector, - std::vector>; - - UntypedMessage(const UntypedMessage&) = delete; - UntypedMessage& operator=(const UntypedMessage&) = delete; - UntypedMessage(UntypedMessage&&) = default; - UntypedMessage& operator=(UntypedMessage&&) = default; - - // Tries to parse a proto with the given descriptor from an input stream. - static absl::StatusOr ParseFromStream( - const ResolverPool::Message* desc, io::CodedInputStream& stream) { - UntypedMessage msg(std::move(desc)); - RETURN_IF_ERROR(msg.Decode(stream)); - return std::move(msg); - } - - // Returns the number of elements in a field by number. - // - // Optional fields are treated like repeated fields with one or zero elements. - size_t Count(int32_t field_number) const { - auto it = fields_.find(field_number); - if (it == fields_.end()) { - return 0; - } - - return absl::visit(SizeVisitor{}, it->second); - } - - // Returns the contents of a field by number. - // - // Optional fields are treated like repeated fields with one or zero elements. - // If the field is not set, returns an empty span. - // - // If `T` is the wrong type, this function crashes. - template - absl::Span Get(int32_t field_number) const { - auto it = fields_.find(field_number); - if (it == fields_.end()) { - return {}; - } - - if (auto* val = absl::get_if(&it->second)) { - return absl::Span(val, 1); - } else if (auto* vec = absl::get_if>(&it->second)) { - return *vec; - } else { - GOOGLE_CHECK(false) << "wrong type for UntypedMessage::Get(" << field_number - << ")"; - } - } - - const ResolverPool::Message& desc() const { return *desc_; } - - private: - enum Cardinality { kSingular, kRepeated }; - - explicit UntypedMessage(const ResolverPool::Message* desc) : desc_(desc) {} - - absl::Status Decode(io::CodedInputStream& stream, - absl::optional current_group = absl::nullopt); - - absl::Status DecodeVarint(io::CodedInputStream& stream, - const ResolverPool::Field& field); - absl::Status Decode64Bit(io::CodedInputStream& stream, - const ResolverPool::Field& field); - absl::Status Decode32Bit(io::CodedInputStream& stream, - const ResolverPool::Field& field); - absl::Status DecodeDelimited(io::CodedInputStream& stream, - const ResolverPool::Field& field); - - template - absl::Status InsertField(const ResolverPool::Field& field, T value); - - const ResolverPool::Message* desc_; - absl::flat_hash_map fields_; -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_UITL_UNTYPED_MESSAGE_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/writer.cc b/libs/protobuf/src/google/protobuf/json/internal/writer.cc deleted file mode 100644 index 20fa3e9..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/writer.cc +++ /dev/null @@ -1,329 +0,0 @@ -// 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/json/internal/writer.h" - -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/algorithm/container.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { - -// Tries to write a non-finite double if necessary; returns false if -// nothing was written. -bool JsonWriter::MaybeWriteSpecialFp(double val) { - if (val == std::numeric_limits::infinity()) { - Write("\"Infinity\""); - } else if (val == -std::numeric_limits::infinity()) { - Write("\"-Infinity\""); - } else if (std::isnan(val)) { - Write("\"NaN\""); - } else { - return false; - } - return true; -} - -void JsonWriter::WriteBase64(absl::string_view str) { - // This is the regular base64, not the "web-safe" version. - constexpr absl::string_view kBase64 = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - const char* ptr = str.data(); - const char* end = ptr + str.size(); - - // Reads the `n`th character off of `ptr` while gracefully avoiding - // sign extension due to implicit conversions - auto read = [&](size_t n) { - return static_cast(static_cast(ptr[n])); - }; - - char buf[4]; - absl::string_view view(buf, sizeof(buf)); - Write("\""); - - while (end - ptr >= 3) { - buf[0] = kBase64[read(0) >> 2]; - buf[1] = kBase64[((read(0) & 0x3) << 4) | (read(1) >> 4)]; - buf[2] = kBase64[((read(1) & 0xf) << 2) | (read(2) >> 6)]; - buf[3] = kBase64[read(2) & 0x3f]; - Write(view); - ptr += 3; - } - - switch (end - ptr) { - case 2: - buf[0] = kBase64[read(0) >> 2]; - buf[1] = kBase64[((read(0) & 0x3) << 4) | (read(1) >> 4)]; - buf[2] = kBase64[(read(1) & 0xf) << 2]; - buf[3] = '='; - Write(view); - break; - case 1: - buf[0] = kBase64[read(0) >> 2]; - buf[1] = kBase64[((read(0) & 0x3) << 4)]; - buf[2] = '='; - buf[3] = '='; - Write(view); - break; - } - - Write("\""); -} - -// The minimum value of a unicode high-surrogate code unit in the utf-16 -// encoding. A high-surrogate is also known as a leading-surrogate. -// See http://www.unicode.org/glossary/#high_surrogate_code_unit -static constexpr uint16_t kMinHighSurrogate = 0xd800; - -// The minimum value of a unicode low-surrogate code unit in the utf-16 -// encoding. A low-surrogate is also known as a trailing-surrogate. -// See http://www.unicode.org/glossary/#low_surrogate_code_unit -static constexpr uint16_t kMinLowSurrogate = 0xdc00; - -// The maximum value of a unicode low-surrogate code unit in the utf-16 -// encoding. A low-surrogate is also known as a trailing surrogate. -// See http://www.unicode.org/glossary/#low_surrogate_code_unit -static constexpr uint16_t kMaxLowSurrogate = 0xdfff; - -// The minimum value of a unicode supplementary code point. -// See http://www.unicode.org/glossary/#supplementary_code_point -static constexpr uint32_t kMinSupplementaryCodePoint = 0x010000; - -// The maximum value of a unicode code point. -// See http://www.unicode.org/glossary/#code_point -static constexpr uint32_t kMaxCodePoint = 0x10ffff; - -// Indicates decoding failure; not a valid Unicode scalar. -static constexpr uint32_t kErrorSentinel = 0xaaaaaaaa; - -// A Unicode Scalar encoded two ways. -struct Utf8Scalar { - // The Unicode scalar value as a 32-bit integer. If decoding failed, this - // is equal to kErrorSentinel. - uint32_t u32; - // The Unicode scalar value encoded as UTF-8 bytes. May not reflect the - // contents of `u32` if it is kErrorSentinel. - absl::string_view utf8; -}; - -// Parses a single UTF-8-encoded Unicode scalar from `str`. Returns a pair of -// the scalar and the UTF-8-encoded content corresponding to it from `str`. -// -// Returns U+FFFD on failure, and consumes an unspecified number of bytes in -// doing so. -static Utf8Scalar ConsumeUtf8Scalar(absl::string_view& str) { - GOOGLE_DCHECK(!str.empty()); - uint32_t scalar = static_cast(str[0]); - const char* start = str.data(); - size_t len = 1; - - str = str.substr(1); - - // Verify this is valid UTF-8. UTF-8 is a varint encoding satisfying - // one of the following (big-endian) patterns: - // - // 0b0xxxxxxx - // 0b110xxxxx'10xxxxxx - // 0b1110xxxx'10xxxxxx'10xxxxxx - // 0b11110xxx'10xxxxxx'10xxxxxx'10xxxxxx - // - // We don't need to decode it; just validate it. - int lookahead = 0; - switch (absl::countl_one(static_cast(scalar))) { - case 0: - break; - case 2: - lookahead = 1; - scalar &= (1 << 5) - 1; - break; - case 3: - lookahead = 2; - scalar &= (1 << 4) - 1; - break; - case 4: - lookahead = 3; - scalar &= (1 << 3) - 1; - break; - default: - scalar = kErrorSentinel; - break; - } - - for (int i = 0; i < lookahead; ++i) { - if (str.empty()) { - scalar = kErrorSentinel; - break; - } - - uint8_t next = str[0]; - str = str.substr(1); - ++len; - - // Looking for top 2 bits are 0b10. - if (next >> 6 != 2) { - scalar = kErrorSentinel; - break; - } - next &= (1 << 6) - 1; - scalar <<= 6; - scalar |= next; - } - - if (scalar > kMaxCodePoint) { - scalar = kErrorSentinel; - } - - return {scalar, absl::string_view(start, len)}; -} - -// Decides whether we must escape `scalar`. -// -// If the given Unicode scalar would not use a \u escape, `custom_escape` will -// be set to a non-empty string. -static bool MustEscape(uint32_t scalar, absl::string_view& custom_escape) { - switch (scalar) { - // These escapes are defined by the JSON spec. We do not escape /. - case '\n': - custom_escape = R"(\n)"; - return true; - case '\r': - custom_escape = R"(\r)"; - return true; - case '\t': - custom_escape = R"(\t)"; - return true; - case '\"': - custom_escape = R"(\")"; - return true; - case '\f': - custom_escape = R"(\f)"; - return true; - case '\b': - custom_escape = R"(\b)"; - return true; - case '\\': - custom_escape = R"(\\)"; - return true; - - case kErrorSentinel: - // Decoding failure turns into spaces, *not* replacement characters. We - // handle this separately from "normal" spaces so that it follows the - // escaping code-path. - // - // Note that literal replacement characters in the input string DO NOT - // get turned into spaces; this is only for decoding failures! - custom_escape = " "; - return true; - - // These are not required by the JSON spec, but help - // to prevent security bugs in JavaScript. - // - // These were originally present in the ESF parser, so they are kept for - // legacy compatibility (and because escaping most of these is in good - // taste, regardless). - case '<': - case '>': - case 0xfeff: // Zero width no-break space. - case 0xfff9: // Interlinear annotation anchor. - case 0xfffa: // Interlinear annotation separator. - case 0xfffb: // Interlinear annotation terminator. - case 0x00ad: // Soft-hyphen. - case 0x06dd: // Arabic end of ayah. - case 0x070f: // Syriac abbreviation mark. - case 0x17b4: // Khmer vowel inherent Aq. - case 0x17b5: // Khmer vowel inherent Aa. - case 0x000e0001: // Language tag. - return true; - default: - static constexpr std::pair kEscapedRanges[] = { - {0x0000, 0x001f}, // ASCII control. - {0x007f, 0x009f}, // High ASCII bytes. - {0x0600, 0x0603}, // Arabic signs. - {0x200b, 0x200f}, // Zero width etc. - {0x2028, 0x202e}, // Separators etc. - {0x2060, 0x2064}, // Invisible etc. - {0x206a, 0x206f}, // Shaping etc. - {0x0001d173, 0x0001d17a}, // Music formatting. - {0x000e0020, 0x000e007f}, // TAG symbols. - }; - - return absl::c_any_of(kEscapedRanges, [scalar](auto range) { - return range.first <= scalar && scalar <= range.second; - }); - } -} - -void JsonWriter::WriteEscapedUtf8(absl::string_view str) { - while (!str.empty()) { - auto scalar = ConsumeUtf8Scalar(str); - absl::string_view custom_escape; - - if (!MustEscape(scalar.u32, custom_escape)) { - Write(scalar.utf8); - continue; - } - - if (!custom_escape.empty()) { - Write(custom_escape); - continue; - } - - if (scalar.u32 < 0x10000) { - WriteUEscape(scalar.u32); - continue; - } - - uint16_t lo = - (scalar.u32 & (kMaxLowSurrogate - kMinLowSurrogate)) + kMinLowSurrogate; - uint16_t hi = (scalar.u32 >> 10) + - (kMinHighSurrogate - (kMinSupplementaryCodePoint >> 10)); - WriteUEscape(hi); - WriteUEscape(lo); - } -} - -void JsonWriter::WriteUEscape(uint16_t val) { - char hex[7]; - int len = absl::SNPrintF(hex, sizeof(hex), R"(\u%04x)", val); - Write(absl::string_view(hex, static_cast(len))); -} -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/writer.h b/libs/protobuf/src/google/protobuf/json/internal/writer.h deleted file mode 100644 index 912fc04..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/writer.h +++ /dev/null @@ -1,241 +0,0 @@ -// 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_JSON_INTERNAL_WRITER_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_WRITER_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/strutil.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_sink.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -struct WriterOptions { - // Whether to add spaces, line breaks and indentation to make the JSON output - // easy to read. - bool add_whitespace = false; - // Whether to always print primitive fields. By default proto3 primitive - // fields with default values will be omitted in JSON output. For example, an - // int32 field set to 0 will be omitted. Set this flag to true will override - // the default behavior and print primitive fields regardless of their values. - bool always_print_primitive_fields = false; - // Whether to always print enums as ints. By default they are rendered as - // strings. - bool always_print_enums_as_ints = false; - // Whether to preserve proto field names - bool preserve_proto_field_names = false; - // The original parser used by json_util2 accepted a number of non-standard - // options. Setting this flag enables them. - // - // What those extensions were is explicitly not documented, beyond what exists - // in the unit tests; we intend to remove this setting eventually. See - // b/234868512. - bool allow_legacy_syntax = false; -}; - -template -void EachInner(const Tuple& value, F f, std::index_sequence) { - int ignored[] = - {(f(std::get(value)), 0)...}; // NOLINT(readability/braces) - (void)ignored; -} - -// Executes f on each element of value. -template -void Each(const Tuple& value, F f) { - EachInner(value, f, - std::make_index_sequence::value>()); -} - -// See JsonWriter::Write(). -template -struct Quoted { - std::tuple value; -}; - -// Because this is not C++17 yet, we cannot add a deduction guide. -template -static Quoted MakeQuoted(T... t) { - return Quoted{std::make_tuple(t...)}; -} - -class JsonWriter { - public: - JsonWriter(io::ZeroCopyOutputStream* out, WriterOptions options) - : sink_(out), options_(options) {} - - const WriterOptions& options() const { return options_; } - - void Push() { ++indent_; } - void Pop() { --indent_; } - - // The many overloads of Write() will write a value to the underlying stream. - // Some values may want to be quoted; the Quoted<> type will automatically add - // quotes and escape sequences. - // - // Note that Write() is not implemented for 64-bit integers, since they - // cannot be crisply represented without quotes; use MakeQuoted for that. - - void Write(absl::string_view str) { sink_.Append(str.data(), str.size()); } - - void Write(char c) { sink_.Append(&c, 1); } - - // The precision on this and the following function are completely made-up, - // in an attempt to match the behavior of the ESF parser. - void Write(double val) { - if (!MaybeWriteSpecialFp(val)) { - Write(SimpleDtoa(val)); - } - } - - void Write(float val) { - if (!MaybeWriteSpecialFp(val)) { - Write(SimpleFtoa(val)); - } - } - - void Write(int32_t val) { - char buf[22]; - int len = absl::SNPrintF(buf, sizeof(buf), "%d", val); - absl::string_view view(buf, static_cast(len)); - Write(view); - } - - void Write(uint32_t val) { - char buf[22]; - int len = absl::SNPrintF(buf, sizeof(buf), "%d", val); - absl::string_view view(buf, static_cast(len)); - Write(view); - } - - void Write(int64_t) = delete; - void Write(uint64_t) = delete; - - template - void Write(Quoted val) { - Write('"'); - Each(val.value, [this](auto x) { this->WriteQuoted(x); }); - Write('"'); - } - - template - auto Write(Ts... args) -> - // This bit of SFINAE avoids this function being called with one argument, - // so the other overloads of Write() can be picked up instead. - typename std::enable_if::type { - Each(std::make_tuple(args...), [this](auto x) { this->Write(x); }); - } - - void Whitespace(absl::string_view ws) { - if (options_.add_whitespace) { - Write(ws); - } - } - - void NewLine() { - Whitespace("\n"); - for (int i = 0; i < indent_; ++i) { - Whitespace(" "); - } - } - - void WriteComma(bool& is_first) { - if (is_first) { - is_first = false; - return; - } - Write(","); - } - - void WriteBase64(absl::string_view str); - - // Returns a buffer that can be re-used throughout a writing session as - // variable-length scratch space. - std::string& ScratchBuf() { return scratch_buf_; } - - private: - template - void WriteQuoted(T val) { - Write(val); - } - - void WriteQuoted(absl::string_view val) { WriteEscapedUtf8(val); } - - void WriteQuoted(int64_t val) { - char buf[22]; - int len = absl::SNPrintF(buf, sizeof(buf), "%d", val); - absl::string_view view(buf, static_cast(len)); - Write(view); - } - - void WriteQuoted(uint64_t val) { - char buf[22]; - int len = absl::SNPrintF(buf, sizeof(buf), "%d", val); - absl::string_view view(buf, static_cast(len)); - Write(view); - } - - // Tries to write a non-finite double if necessary; returns false if - // nothing was written. - bool MaybeWriteSpecialFp(double val); - - void WriteEscapedUtf8(absl::string_view str); - void WriteUEscape(uint16_t val); - - io::zc_sink_internal::ZeroCopyStreamByteSink sink_; - WriterOptions options_; - int indent_ = 0; - - std::string scratch_buf_; -}; -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_WRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.cc b/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.cc deleted file mode 100644 index 9801ed2..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.cc +++ /dev/null @@ -1,148 +0,0 @@ -// 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/json/internal/zero_copy_buffered_stream.h" - -#include -#include -#include -#include - -#include "absl/algorithm/container.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json_internal { -absl::Status ZeroCopyBufferedStream::Advance(size_t bytes) { - while (bytes != 0) { - if (Unread().empty() && !ReadChunk()) { - return absl::InvalidArgumentError("unexpected EOF"); - } - size_t to_skip = std::min(bytes, Unread().size()); - cursor_ += to_skip; - bytes -= to_skip; - } - - if (using_buf_) { - GOOGLE_DCHECK_LE(cursor_, buffer_start_ + buf_.size()); - } else { - GOOGLE_DCHECK_LE(cursor_, last_chunk_.size()); - } - - return absl::OkStatus(); -} - -absl::StatusOr ZeroCopyBufferedStream::BufferAtLeast( - size_t bytes) { - // This MUST be an empty guard before the first call to ReadChunk(); - // otherwise we risk unconditional buffering. - BufferingGuard guard; - while (Unread().size() < bytes) { - if (!Unread().empty()) { - // We must buffer before reading if Unread() is nonempty; otherwise we - // risk discarding part of the unread buffer. However, we must NOT - // buffer before calling ReadChunk if it *is* empty, because then we - // would buffer unconditionally. - // - // There are tests to verify both of these cases. - guard = BufferingGuard(this); - } - if (!ReadChunk()) { - return absl::InvalidArgumentError("unexpected EOF"); - } - guard = BufferingGuard(this); - } - GOOGLE_DCHECK_GE(Unread().size(), bytes); - return BufferingGuard(this); -} - -void ZeroCopyBufferedStream::DownRefBuffer() { - GOOGLE_DCHECK_GT(outstanding_buffer_borrows_, 0); - - --outstanding_buffer_borrows_; - if (outstanding_buffer_borrows_ > 0 || !using_buf_) { - return; - } - - // The "virtual length" is the size of the buffer cursor_ indexes into, which - // is bigger than buf_. - size_t virtual_buf_len = buf_.size() + buffer_start_; - size_t last_chunk_in_buf = virtual_buf_len - last_chunk_.size(); - // If we are inside of `last_chunk_`, set the cursor there; otherwise, we have - // a dangling reference somewhere. - GOOGLE_DCHECK_LE(last_chunk_in_buf, virtual_buf_len) << absl::StrFormat( - "%d, %d, %d", buf_.size(), last_chunk_.size(), buffer_start_); - if (cursor_ <= last_chunk_in_buf) { - cursor_ = 0; - } else { - cursor_ -= last_chunk_in_buf; - } - buf_.clear(); - using_buf_ = false; -} - -bool ZeroCopyBufferedStream::ReadChunk() { - if (eof_) { - return false; - } - // We are buffering a second chunk, so we need to put the current chunk - // into the buffer. - if (outstanding_buffer_borrows_ > 0 && !using_buf_) { - absl::c_copy(RawBuffer(buffer_start_), std::back_inserter(buf_)); - using_buf_ = true; - } - - const void* data; - int len; - if (!stream_->Next(&data, &len)) { - eof_ = true; - return false; - } - - last_chunk_ = absl::string_view(static_cast(data), - static_cast(len)); - if (using_buf_) { - absl::c_copy(last_chunk_, std::back_inserter(buf_)); - // Cursor does not need to move, because it is still inside of `buf_`. - } else { - cursor_ = 0; - buffer_start_ = 0; - } - return true; -} -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.h b/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.h deleted file mode 100644 index dc081e0..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream.h +++ /dev/null @@ -1,355 +0,0 @@ -// 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_JSON_INTERNAL_ZERO_COPY_BUFFERED_STREAM_H__ -#define GOOGLE_PROTOBUF_JSON_INTERNAL_ZERO_COPY_BUFFERED_STREAM_H__ - -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/str_format.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -// Utilities for parsing contiguous buffers out of ZeroCopyInputStreams. - -namespace google { -namespace protobuf { -namespace json_internal { -// Forward decl. for use by helper types below. -class ZeroCopyBufferedStream; - -// An RAII type that represents holding a reference into the backing buffer -// of a ZeroCopyBufferedStream. This allows for automatic management of the -// backing buffer. -class BufferingGuard { - public: - explicit BufferingGuard(ZeroCopyBufferedStream* owner = nullptr); - ~BufferingGuard(); - - BufferingGuard(const BufferingGuard& other) : BufferingGuard(other.owner_) {} - BufferingGuard& operator=(const BufferingGuard& other) { - this->~BufferingGuard(); - new (this) BufferingGuard(other); - return *this; - } - - private: - friend class Mark; - ZeroCopyBufferedStream* owner_ = nullptr; -}; - -// A string that may own its contents, or live inside of a buffer owned by -// a ZeroCopyBufferedStream. -// -// Note that this type holds onto a reference to the owning -// ZeroCopyBufferedStream; this allows it to be durable against strings being -// moved around for buffering puroses. -class MaybeOwnedString { - public: - explicit MaybeOwnedString(std::string value) : data_(std::move(value)) {} - MaybeOwnedString(ZeroCopyBufferedStream* stream, size_t start, size_t len, - BufferingGuard token) - : data_(StreamOwned{stream, start, len}), token_(token) {} - - // Returns the string as a view, regardless of whether it is owned or not. - absl::string_view AsView() const { - if (auto* unowned = absl::get_if(&data_)) { - return unowned->AsView(); - } - - return absl::get(data_); - } - - operator absl::string_view() const { return AsView(); } // NOLINT - - // Returns a reference to an owned string; if the wrapped string is not - // owned, this function will perform a copy and make it owned. - std::string& ToString() { - if (auto* unowned = absl::get_if(&data_)) { - data_ = std::string(unowned->AsView()); - token_ = BufferingGuard{}; - } - - return absl::get(data_); - } - - template - friend bool operator==(const MaybeOwnedString& lhs, const String& rhs) { - return lhs.AsView() == rhs; - } - template - friend bool operator!=(const MaybeOwnedString& lhs, const String& rhs) { - return !(lhs == rhs); - } - - private: - struct StreamOwned { - ZeroCopyBufferedStream* stream; - size_t start, len; - absl::string_view AsView() const; - }; - absl::variant data_; - BufferingGuard token_; -}; - -// A mark in a stream. See ZeroCopyBufferedStream::Mark(). -class Mark { - public: - // Returns a maybe-owned string up to the unread bytes boundary, except for - // the last `clip` bytes. - MaybeOwnedString UpToUnread(size_t clip = 0) const; - - // Discards this mark and its hold on the buffer. - void Discard() && { guard_ = BufferingGuard(); } - - private: - friend ZeroCopyBufferedStream; - Mark(size_t offset, BufferingGuard guard) : offset_(offset), guard_(guard) {} - - size_t offset_; - BufferingGuard guard_; -}; - -// A wrapper over a ZeroCopyInputStream that allows doing as-needed buffer for -// obtaining contiguous chunks larger than those the underlying stream might -// provide, while minimizing the amount of actual copying. -class ZeroCopyBufferedStream { - public: - explicit ZeroCopyBufferedStream(io::ZeroCopyInputStream* stream) - : stream_(stream) {} - - // Returns whether the stream is currently at eof. - // - // This function will buffer at least one character to verify whether it - // actually *is* at EOF. - bool AtEof() { - (void)BufferAtLeast(1); - return eof_; - } - - // Takes exactly n characters from a string. - absl::StatusOr Take(size_t len) { - auto buffering = BufferAtLeast(len); - RETURN_IF_ERROR(buffering.status()); - - size_t start = cursor_; - RETURN_IF_ERROR(Advance(len)); - return MaybeOwnedString(this, start, len, *buffering); - } - - // Takes characters to form a string, according to the given predicate. Stops - // early if an EOF is hit. - // - // The predicate must have type `(int, char) -> bool`; the first argument - // is the index of the character. - template - absl::StatusOr TakeWhile(Pred p); - - // Places a mark in the stream, ensuring that all characters consumed after - // the mark are buffered. This can be used to parse some characters and then - // recover everything that follows as a contiguous string_view so that it may - // be processed a second time. - // - // The returned value is an RAII type that ensure the buffer sticks around - // long enough. - Mark BeginMark() { return Mark(cursor_, BufferingGuard(this)); } - - // Peeks the next character in the stream. - // - // This function will not enable buffering on its own, and will read past the - // end of the buffer if at EOF; BufferAtLeast() should be called before - // calling this function. - char PeekChar() { - GOOGLE_DCHECK(!Unread().empty()); - return Unread()[0]; - } - - // Advances the cursor by the given number of bytes. - absl::Status Advance(size_t bytes); - - // Returns a view of the current buffer, which may be either the owned - // `buf_` or the stream-owned `last_chunk_`. - // - // The returned view is unstable: calling any function may invalidate it, - // because there will not be a `BufferingGuard` to guard it. - absl::string_view RawBuffer(size_t start, - size_t len = absl::string_view::npos) const; - - // Returns a view of RawBuffer, unread bytes; this will not be the entirety - // of the underlying stream. - absl::string_view Unread() const { return RawBuffer(cursor_); } - - bool IsBuffering() const { return using_buf_; } - - // Buffers at least `bytes` bytes ahead of the current cursor position, - // possibly enabling buffering. - // - // Returns an error if that many bytes could not be RawBuffer. - absl::StatusOr BufferAtLeast(size_t bytes); - - private: - friend BufferingGuard; - friend Mark; - friend MaybeOwnedString; - - // Increments the buffering refcount; this will also update `buffer_start_` if - // necessary. - void UpRefBuffer() { - if (outstanding_buffer_borrows_++ == 0) { - buffer_start_ = cursor_; - } - } - - // Decrements the buffering refcount; calling this function if the refcount is - // zero is undefined behavior. - // - // This function should not be called directly; it is called automatically - // by the destructor of `BufferingGuard`. - void DownRefBuffer(); - - // Obtains a new chunk from the underlying stream; returns whether there is - // still more data to read. - bool ReadChunk(); - - // The streamer implements a buffering stream on top of the given stream, by - // the following mechanism: - // - `cursor_` is an offset into either `last_chunk_` or `buf_`, which can - // be obtained via RawBuffer() and Unread(): - // - If `using_buf_` is true, it is an offset into `buf_`. - // - Otherwise it is an offset into `last_chunk_`. - // - If `outstanding_buffer_borrows_ > 0`, someone needs the buffer to stick - // around. MaybeUnownedString::StreamOwned is implemented such that it does - // not hold onto `last_chunk_` directly, so we can freely copy it into - // `buf_` as needed arises. - // - Note that we can copy only part if we update `buffer_start_`; see - // RawBuffer(). - // - If we would read more data and `outstanding_buffer_borrows_ > 0`, instead - // of trashing `last_chunk_`, we copy it into `buf_` and append to `buf_` - // each time we read. - // - If `outstanding_buffer_borrows_ == 0`, we can trash `buf_` and go back to - // using `last_chunk_` directly. See `DownRefBuffer()`. - io::ZeroCopyInputStream* stream_; - absl::string_view last_chunk_; - std::vector buf_; - bool using_buf_ = false; - size_t cursor_ = 0; - // Invariant: this always refers to the earliest point at which we requested - // buffering, since the last time outstanding_buffer_borrows_ was zero. - size_t buffer_start_ = 0; - bool eof_ = false; - int outstanding_buffer_borrows_ = 0; -}; - -// These functions all rely on the definition of ZeroCopyBufferedStream, so must -// come after it. -inline BufferingGuard::BufferingGuard(ZeroCopyBufferedStream* owner) - : owner_(owner) { - if (owner_ != nullptr) { - owner_->UpRefBuffer(); - } -} - -inline BufferingGuard::~BufferingGuard() { - if (owner_ != nullptr) { - owner_->DownRefBuffer(); - owner_ = nullptr; - } -} - -inline absl::string_view MaybeOwnedString::StreamOwned::AsView() const { - return stream->RawBuffer(start, len); -} - -inline MaybeOwnedString Mark::UpToUnread(size_t clip) const { - return MaybeOwnedString(guard_.owner_, offset_, - guard_.owner_->cursor_ - offset_ - clip, guard_); -} - -template -absl::StatusOr ZeroCopyBufferedStream::TakeWhile(Pred p) { - size_t start = cursor_; - BufferingGuard guard(this); - while (true) { - if (!BufferAtLeast(1).ok()) { - // We treat EOF as ending the take, rather than being an error. - break; - } - if (!p(cursor_ - start, PeekChar())) { - break; - } - RETURN_IF_ERROR(Advance(1)); - } - - return MaybeOwnedString(this, start, cursor_ - start, guard); -} - -inline absl::string_view ZeroCopyBufferedStream::RawBuffer(size_t start, - size_t len) const { - absl::string_view view = last_chunk_; - if (using_buf_) { - GOOGLE_DCHECK_LE(buffer_start_, start); - start -= buffer_start_; - view = absl::string_view(buf_.data(), buf_.size()); - } -#if 0 - // This print statement is especially useful for trouble-shooting low-level - // bugs in the buffering logic. - GOOGLE_LOG(INFO) << absl::StreamFormat("%s(\"%s\")[%d:%d]/%d:%d @ %p", - using_buf_ ? "buf_" : "last_chunk_", - view, start, static_cast(len), - buffer_start_, cursor_, this); -#endif - GOOGLE_DCHECK_LE(start, view.size()); - if (len == absl::string_view::npos) { - return view.substr(start); - } - - GOOGLE_DCHECK_LE(start + len, view.size()); - return view.substr(start, len); -} -} // namespace json_internal -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_JSON_INTERNAL_ZERO_COPY_BUFFERED_STREAM_H__ diff --git a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream_test.cc b/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream_test.cc deleted file mode 100644 index 714062e..0000000 --- a/libs/protobuf/src/google/protobuf/json/internal/zero_copy_buffered_stream_test.cc +++ /dev/null @@ -1,165 +0,0 @@ -// 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/json/internal/zero_copy_buffered_stream.h" - -#include -#include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include -#include -#include "absl/strings/string_view.h" -#include "google/protobuf/json/internal/test_input_stream.h" -#include "google/protobuf/stubs/status_macros.h" - -namespace google { -namespace protobuf { -namespace json_internal { -namespace { -// TODO(b/234474291): Use the gtest versions once that's available in OSS. -MATCHER_P(IsOkAndHolds, inner, - absl::StrCat("is OK and holds ", testing::PrintToString(inner))) { - if (!arg.ok()) { - *result_listener << arg.status(); - return false; - } - return testing::ExplainMatchResult(inner, *arg, result_listener); -} - -absl::Status GetStatus(const absl::Status& s) { return s; } -template -absl::Status GetStatus(const absl::StatusOr& s) { - return s.status(); -} - -MATCHER_P(StatusIs, status, - absl::StrCat(".status() is ", testing::PrintToString(status))) { - return GetStatus(arg).code() == status; -} - -#define EXPECT_OK(x) EXPECT_THAT(x, StatusIs(absl::StatusCode::kOk)) -#define ASSERT_OK(x) ASSERT_THAT(x, StatusIs(absl::StatusCode::kOk)) - -TEST(ZcBufferTest, ReadUnbuffered) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - { - auto chunk = stream.Take(3); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("foo")); - } - - { - auto chunk = stream.Take(3); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("bar")); - } - - { - auto chunk = stream.Take(3); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("baz")); - } -} - -TEST(ZcBufferTest, ReadBuffered) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - { - auto chunk = stream.Take(4); - EXPECT_TRUE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("foob")); - } - - { - auto chunk = stream.Take(2); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("ar")); - } -} - -TEST(ZcBufferTest, HoldAcrossSeam) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - auto chunk = stream.Take(3); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("foo")); - - auto chunk2 = stream.Take(3); - EXPECT_TRUE(stream.IsBuffering()); - EXPECT_THAT(chunk2, IsOkAndHolds("bar")); - EXPECT_THAT(chunk, IsOkAndHolds("foo")); -} - -TEST(ZcBufferTest, BufferAcrossSeam) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - auto chunk = stream.Take(2); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(chunk, IsOkAndHolds("fo")); - - auto chunk2 = stream.Take(3); - EXPECT_TRUE(stream.IsBuffering()); - EXPECT_THAT(chunk2, IsOkAndHolds("oba")); - EXPECT_THAT(chunk, IsOkAndHolds("fo")); -} - -TEST(ZcBufferTest, MarkUnbuffered) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - ASSERT_OK(stream.Advance(1)); - auto mark = stream.BeginMark(); - ASSERT_OK(stream.Advance(2)); - EXPECT_FALSE(stream.IsBuffering()); - EXPECT_THAT(mark.UpToUnread(), "oo"); -} - -TEST(ZcBufferTest, MarkBuffered) { - TestInputStream in{"foo", "bar", "baz"}; - ZeroCopyBufferedStream stream(&in); - - ASSERT_OK(stream.Advance(1)); - auto mark = stream.BeginMark(); - ASSERT_OK(stream.Advance(5)); - EXPECT_TRUE(stream.IsBuffering()); - EXPECT_THAT(mark.UpToUnread(), "oobar"); -} -} // namespace -} // namespace json_internal -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/json.cc b/libs/protobuf/src/google/protobuf/json/json.cc deleted file mode 100644 index 6cbc0bb..0000000 --- a/libs/protobuf/src/google/protobuf/json/json.cc +++ /dev/null @@ -1,133 +0,0 @@ -// 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/json/json.h" - -#include - -#include "absl/status/status.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/json/internal/parser.h" -#include "google/protobuf/json/internal/unparser.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json { - -absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* binary_input, - io::ZeroCopyOutputStream* json_output, - const PrintOptions& options) { - google::protobuf::json_internal::WriterOptions opts; - opts.add_whitespace = options.add_whitespace; - opts.preserve_proto_field_names = options.preserve_proto_field_names; - opts.always_print_enums_as_ints = options.always_print_enums_as_ints; - opts.always_print_primitive_fields = options.always_print_primitive_fields; - - // TODO(b/234868512): Drop this setting. - opts.allow_legacy_syntax = true; - - return google::protobuf::json_internal::BinaryToJsonStream( - resolver, type_url, binary_input, json_output, opts); -} - -absl::Status BinaryToJsonString(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - const std::string& binary_input, - std::string* json_output, - const PrintOptions& options) { - io::ArrayInputStream input_stream(binary_input.data(), binary_input.size()); - io::StringOutputStream output_stream(json_output); - return BinaryToJsonStream(resolver, type_url, &input_stream, &output_stream, - options); -} - -absl::Status JsonToBinaryStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* json_input, - io::ZeroCopyOutputStream* binary_output, - const ParseOptions& options) { - google::protobuf::json_internal::ParseOptions opts; - opts.ignore_unknown_fields = options.ignore_unknown_fields; - opts.case_insensitive_enum_parsing = options.case_insensitive_enum_parsing; - - // TODO(b/234868512): Drop this setting. - opts.allow_legacy_syntax = true; - - return google::protobuf::json_internal::JsonToBinaryStream( - resolver, type_url, json_input, binary_output, opts); -} - -absl::Status JsonToBinaryString(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - absl::string_view json_input, - std::string* binary_output, - const ParseOptions& options) { - io::ArrayInputStream input_stream(json_input.data(), json_input.size()); - io::StringOutputStream output_stream(binary_output); - return JsonToBinaryStream(resolver, type_url, &input_stream, &output_stream, - options); -} - -absl::Status MessageToJsonString(const Message& message, std::string* output, - const PrintOptions& options) { - google::protobuf::json_internal::WriterOptions opts; - opts.add_whitespace = options.add_whitespace; - opts.preserve_proto_field_names = options.preserve_proto_field_names; - opts.always_print_enums_as_ints = options.always_print_enums_as_ints; - opts.always_print_primitive_fields = options.always_print_primitive_fields; - - // TODO(b/234868512): Drop this setting. - opts.allow_legacy_syntax = true; - - return google::protobuf::json_internal::MessageToJsonString(message, output, opts); -} - -absl::Status JsonStringToMessage(absl::string_view input, Message* message, - const ParseOptions& options) { - google::protobuf::json_internal::ParseOptions opts; - opts.ignore_unknown_fields = options.ignore_unknown_fields; - opts.case_insensitive_enum_parsing = options.case_insensitive_enum_parsing; - - // TODO(b/234868512): Drop this setting. - opts.allow_legacy_syntax = true; - - return google::protobuf::json_internal::JsonStringToMessage(input, message, opts); -} -} // namespace json -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/json.h b/libs/protobuf/src/google/protobuf/json/json.h deleted file mode 100644 index 531de6b..0000000 --- a/libs/protobuf/src/google/protobuf/json/json.h +++ /dev/null @@ -1,190 +0,0 @@ -// 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. - -// Utility functions to convert between protobuf binary format and proto3 JSON -// format. -#ifndef GOOGLE_PROTOBUF_JSON_JSON_H__ -#define GOOGLE_PROTOBUF_JSON_JSON_H__ - -#include - -#include "absl/status/status.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/message.h" -#include "google/protobuf/util/type_resolver.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json { -struct ParseOptions { - // Whether to ignore unknown JSON fields during parsing - bool ignore_unknown_fields = false; - - // If true, when a lowercase enum value fails to parse, try convert it to - // UPPER_CASE and see if it matches a valid enum. - // WARNING: This option exists only to preserve legacy behavior. Avoid using - // this option. If your enum needs to support different casing, consider using - // allow_alias instead. - bool case_insensitive_enum_parsing = false; - - ParseOptions() - : ignore_unknown_fields(false), case_insensitive_enum_parsing(false) {} -}; - -struct PrintOptions { - // Whether to add spaces, line breaks and indentation to make the JSON output - // easy to read. - bool add_whitespace = false; - // Whether to always print primitive fields. By default proto3 primitive - // fields with default values will be omitted in JSON output. For example, an - // int32 field set to 0 will be omitted. Set this flag to true will override - // the default behavior and print primitive fields regardless of their values. - bool always_print_primitive_fields = false; - // Whether to always print enums as ints. By default they are rendered as - // strings. - bool always_print_enums_as_ints = false; - // Whether to preserve proto field names - bool preserve_proto_field_names = false; - - PrintOptions() - : add_whitespace(false), - always_print_primitive_fields(false), - always_print_enums_as_ints(false), - preserve_proto_field_names(false) {} -}; - -// Converts from protobuf message to JSON and appends it to |output|. This is a -// simple wrapper of BinaryToJsonString(). It will use the DescriptorPool of the -// passed-in message to resolve Any types. -// -// Please note that non-OK statuses are not a stable output of this API and -// subject to change without notice. -PROTOBUF_EXPORT absl::Status MessageToJsonString(const Message& message, - std::string* output, - const PrintOptions& options); - -inline absl::Status MessageToJsonString(const Message& message, - std::string* output) { - return MessageToJsonString(message, output, PrintOptions()); -} - -// Converts from JSON to protobuf message. This is a simple wrapper of -// JsonStringToBinary(). It will use the DescriptorPool of the passed-in -// message to resolve Any types. -// -// Please note that non-OK statuses are not a stable output of this API and -// subject to change without notice. -PROTOBUF_EXPORT absl::Status JsonStringToMessage(absl::string_view input, - Message* message, - const ParseOptions& options); - -inline absl::Status JsonStringToMessage(absl::string_view input, - Message* message) { - return JsonStringToMessage(input, message, ParseOptions()); -} - -// Converts protobuf binary data to JSON. -// The conversion will fail if: -// 1. TypeResolver fails to resolve a type. -// 2. input is not valid protobuf wire format, or conflicts with the type -// information returned by TypeResolver. -// Note that unknown fields will be discarded silently. -// -// Please note that non-OK statuses are not a stable output of this API and -// subject to change without notice. -PROTOBUF_EXPORT absl::Status BinaryToJsonStream( - google::protobuf::util::TypeResolver* resolver, const std::string& type_url, - io::ZeroCopyInputStream* binary_input, - io::ZeroCopyOutputStream* json_output, const PrintOptions& options); - -inline absl::Status BinaryToJsonStream(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - io::ZeroCopyInputStream* binary_input, - io::ZeroCopyOutputStream* json_output) { - return BinaryToJsonStream(resolver, type_url, binary_input, json_output, - PrintOptions()); -} - -PROTOBUF_EXPORT absl::Status BinaryToJsonString( - google::protobuf::util::TypeResolver* resolver, const std::string& type_url, - const std::string& binary_input, std::string* json_output, - const PrintOptions& options); - -inline absl::Status BinaryToJsonString(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - const std::string& binary_input, - std::string* json_output) { - return BinaryToJsonString(resolver, type_url, binary_input, json_output, - PrintOptions()); -} - -// Converts JSON data to protobuf binary format. -// The conversion will fail if: -// 1. TypeResolver fails to resolve a type. -// 2. input is not valid JSON format, or conflicts with the type -// information returned by TypeResolver. -// -// Please note that non-OK statuses are not a stable output of this API and -// subject to change without notice. -PROTOBUF_EXPORT absl::Status JsonToBinaryStream( - google::protobuf::util::TypeResolver* resolver, const std::string& type_url, - io::ZeroCopyInputStream* json_input, - io::ZeroCopyOutputStream* binary_output, const ParseOptions& options); - -inline absl::Status JsonToBinaryStream( - google::protobuf::util::TypeResolver* resolver, const std::string& type_url, - io::ZeroCopyInputStream* json_input, - io::ZeroCopyOutputStream* binary_output) { - return JsonToBinaryStream(resolver, type_url, json_input, binary_output, - ParseOptions()); -} - -PROTOBUF_EXPORT absl::Status JsonToBinaryString( - google::protobuf::util::TypeResolver* resolver, const std::string& type_url, - absl::string_view json_input, std::string* binary_output, - const ParseOptions& options); - -inline absl::Status JsonToBinaryString(google::protobuf::util::TypeResolver* resolver, - const std::string& type_url, - absl::string_view json_input, - std::string* binary_output) { - return JsonToBinaryString(resolver, type_url, json_input, binary_output, - ParseOptions()); -} -} // namespace json -} // namespace protobuf -} // namespace google - -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_JSON_JSON_H__ diff --git a/libs/protobuf/src/google/protobuf/json/json_test.cc b/libs/protobuf/src/google/protobuf/json/json_test.cc deleted file mode 100644 index 1abf851..0000000 --- a/libs/protobuf/src/google/protobuf/json/json_test.cc +++ /dev/null @@ -1,1303 +0,0 @@ -// 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/json/json.h" - -#include -#include -#include -#include -#include -#include - -#include "google/protobuf/duration.pb.h" -#include "google/protobuf/field_mask.pb.h" -#include "google/protobuf/struct.pb.h" -#include "google/protobuf/timestamp.pb.h" -#include "google/protobuf/wrappers.pb.h" -#include "google/protobuf/unittest.pb.h" -#include -#include -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor_database.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/util/json_format.pb.h" -#include "google/protobuf/util/json_format_proto3.pb.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/util/type_resolver_util.h" -#include "google/protobuf/stubs/status_macros.h" - -// Must be included last. -#include "google/protobuf/port_def.inc" - -namespace google { -namespace protobuf { -namespace json { -namespace { -using ::google::protobuf::util::TypeResolver; -using ::proto3::MapIn; -using ::proto3::TestAny; -using ::proto3::TestEnumValue; -using ::proto3::TestMap; -using ::proto3::TestMessage; -using ::proto3::TestOneof; -using ::proto3::TestWrapper; -using ::testing::ElementsAre; -using ::testing::IsEmpty; -using ::testing::Not; -using ::testing::SizeIs; - -// TODO(b/234474291): Use the gtest versions once that's available in OSS. -MATCHER_P(IsOkAndHolds, inner, - absl::StrCat("is OK and holds ", testing::PrintToString(inner))) { - if (!arg.ok()) { - *result_listener << arg.status(); - return false; - } - return testing::ExplainMatchResult(inner, *arg, result_listener); -} - -absl::Status GetStatus(const absl::Status& s) { return s; } -template -absl::Status GetStatus(const absl::StatusOr& s) { - return s.status(); -} - -MATCHER_P(StatusIs, status, - absl::StrCat(".status() is ", testing::PrintToString(status))) { - return GetStatus(arg).code() == status; -} - -#define EXPECT_OK(x) EXPECT_THAT(x, StatusIs(absl::StatusCode::kOk)) -#define ASSERT_OK(x) ASSERT_THAT(x, StatusIs(absl::StatusCode::kOk)) - -enum class Codec { - kReflective, - kResolver, -}; - -class JsonTest : public testing::TestWithParam { - protected: - absl::StatusOr ToJson(const Message& proto, - PrintOptions options = {}) { - if (GetParam() == Codec::kReflective) { - std::string result; - RETURN_IF_ERROR(MessageToJsonString(proto, &result, options)); - return result; - } - std::string proto_data = proto.SerializeAsString(); - io::ArrayInputStream in(proto_data.data(), proto_data.size()); - - std::string result; - io::StringOutputStream out(&result); - - RETURN_IF_ERROR(BinaryToJsonStream( - resolver_.get(), - absl::StrCat("type.googleapis.com/", proto.GetTypeName()), &in, &out, - options)); - return result; - } - - // The out parameter comes first since `json` tends to be a very long string, - // and clang-format does a poor job if it is not the last parameter. - absl::Status ToProto(Message& proto, absl::string_view json, - ParseOptions options = {}) { - if (GetParam() == Codec::kReflective) { - return JsonStringToMessage(json, &proto, options); - } - io::ArrayInputStream in(json.data(), json.size()); - - std::string result; - io::StringOutputStream out(&result); - - RETURN_IF_ERROR(JsonToBinaryStream( - resolver_.get(), - absl::StrCat("type.googleapis.com/", proto.GetTypeName()), &in, &out, - options)); - - if (!proto.ParseFromString(result)) { - return absl::InternalError("wire format parse failed"); - } - return absl::OkStatus(); - } - - template - absl::StatusOr ToProto(absl::string_view json, - ParseOptions options = {}) { - Proto proto; - RETURN_IF_ERROR(ToProto(proto, json, options)); - return proto; - } - - std::unique_ptr resolver_{ - google::protobuf::util::NewTypeResolverForDescriptorPool( - "type.googleapis.com", DescriptorPool::generated_pool())}; -}; - -INSTANTIATE_TEST_SUITE_P(JsonTestSuite, JsonTest, - testing::Values(Codec::kReflective, Codec::kResolver)); - -TEST_P(JsonTest, TestWhitespaces) { - TestMessage m; - m.mutable_message_value(); - m.set_string_value("foo"); - m.add_repeated_bool_value(true); - m.add_repeated_bool_value(false); - - EXPECT_THAT( - ToJson(m), - IsOkAndHolds( - R"({"stringValue":"foo","messageValue":{},"repeatedBoolValue":[true,false]})")); - - PrintOptions options; - options.add_whitespace = true; - // Note: whitespace here is significant. - EXPECT_THAT(ToJson(m, options), IsOkAndHolds(R"({ - "stringValue": "foo", - "messageValue": {}, - "repeatedBoolValue": [ - true, - false - ] -} -)")); -} - -TEST_P(JsonTest, TestDefaultValues) { - TestMessage m; - EXPECT_THAT(ToJson(m), IsOkAndHolds("{}")); - - PrintOptions options; - options.always_print_primitive_fields = true; - EXPECT_THAT(ToJson(m, options), IsOkAndHolds("{\"boolValue\":false," - "\"int32Value\":0," - "\"int64Value\":\"0\"," - "\"uint32Value\":0," - "\"uint64Value\":\"0\"," - "\"floatValue\":0," - "\"doubleValue\":0," - "\"stringValue\":\"\"," - "\"bytesValue\":\"\"," - "\"enumValue\":\"FOO\"," - "\"repeatedBoolValue\":[]," - "\"repeatedInt32Value\":[]," - "\"repeatedInt64Value\":[]," - "\"repeatedUint32Value\":[]," - "\"repeatedUint64Value\":[]," - "\"repeatedFloatValue\":[]," - "\"repeatedDoubleValue\":[]," - "\"repeatedStringValue\":[]," - "\"repeatedBytesValue\":[]," - "\"repeatedEnumValue\":[]," - "\"repeatedMessageValue\":[]" - "}")); - - m.set_string_value("i am a test string value"); - m.set_bytes_value("i am a test bytes value"); - EXPECT_THAT( - ToJson(m, options), - IsOkAndHolds("{\"boolValue\":false," - "\"int32Value\":0," - "\"int64Value\":\"0\"," - "\"uint32Value\":0," - "\"uint64Value\":\"0\"," - "\"floatValue\":0," - "\"doubleValue\":0," - "\"stringValue\":\"i am a test string value\"," - "\"bytesValue\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\"," - "\"enumValue\":\"FOO\"," - "\"repeatedBoolValue\":[]," - "\"repeatedInt32Value\":[]," - "\"repeatedInt64Value\":[]," - "\"repeatedUint32Value\":[]," - "\"repeatedUint64Value\":[]," - "\"repeatedFloatValue\":[]," - "\"repeatedDoubleValue\":[]," - "\"repeatedStringValue\":[]," - "\"repeatedBytesValue\":[]," - "\"repeatedEnumValue\":[]," - "\"repeatedMessageValue\":[]" - "}")); - - EXPECT_THAT( - ToJson(protobuf_unittest::TestAllTypes(), options), - IsOkAndHolds( - R"({"optionalInt32":0,"optionalInt64":"0","optionalUint32":0,)" - R"("optionalUint64":"0","optionalSint32":0,"optionalSint64":"0","optionalFixed32":0,)" - R"("optionalFixed64":"0","optionalSfixed32":0,"optionalSfixed64":"0",)" - R"("optionalFloat":0,"optionalDouble":0,"optionalBool":false,"optionalString":"",)" - R"("optionalBytes":"","optionalgroup":null,"optionalNestedEnum":"FOO","optionalForeignEnum":"FOREIGN_FOO",)" - R"("optionalImportEnum":"IMPORT_FOO","optionalStringPiece":"","optionalCord":"",)" - R"("repeatedInt32":[],"repeatedInt64":[],"repeatedUint32":[],"repeatedUint64":[],)" - R"("repeatedSint32":[],"repeatedSint64":[],"repeatedFixed32":[],"repeatedFixed64":[],)" - R"("repeatedSfixed32":[],"repeatedSfixed64":[],"repeatedFloat":[],"repeatedDouble":[],)" - R"("repeatedBool":[],"repeatedString":[],"repeatedBytes":[],"repeatedgroup":[],)" - R"("repeatedNestedMessage":[],"repeatedForeignMessage":[],"repeatedImportMessage":[],)" - R"("repeatedNestedEnum":[],"repeatedForeignEnum":[],"repeatedImportEnum":[],)" - R"("repeatedStringPiece":[],"repeatedCord":[],"repeatedLazyMessage":[],"defaultInt32":41,)" - R"("defaultInt64":"42","defaultUint32":43,"defaultUint64":"44","defaultSint32":-45,)" - R"("defaultSint64":"46","defaultFixed32":47,"defaultFixed64":"48","defaultSfixed32":49,)" - R"("defaultSfixed64":"-50","defaultFloat":51.5,"defaultDouble":52000,"defaultBool":true,)" - R"("defaultString":"hello","defaultBytes":"d29ybGQ=","defaultNestedEnum":"BAR",)" - R"("defaultForeignEnum":"FOREIGN_BAR","defaultImportEnum":"IMPORT_BAR",)" - R"("defaultStringPiece":"abc","defaultCord":"123"})")); - - EXPECT_THAT( - ToJson(protobuf_unittest::TestExtremeDefaultValues(), options), - IsOkAndHolds( - R"({"escapedBytes":"XDAwMFwwMDFcMDA3XDAxMFwwMTRcblxyXHRcMDEzXFxcJ1wiXDM3Ng==")" - R"(,"largeUint32":4294967295,"largeUint64":"18446744073709551615",)" - R"("smallInt32":-2147483647,"smallInt64":"-9223372036854775807",)" - R"("utf8String":"ሴ","zeroFloat":0,"oneFloat":1,"smallFloat":1.5,)" - R"("negativeOneFloat":-1,"negativeFloat":-1.5,"largeFloat":2e+08,)" - R"("smallNegativeFloat":-8e-28,"infDouble":0,"negInfDouble":0,)" - R"("nanDouble":0,"infFloat":0,"negInfFloat":0,"nanFloat":0,)" - R"("cppTrigraph":"? ? ?? ?? ??? ??/ ??-","reallySmallInt32":-2147483648)" - R"(,"reallySmallInt64":"-9223372036854775808","stringWithZero":"hel\u0000lo")" - R"(,"bytesWithZero":"d29yXDAwMGxk","stringPieceWithZero":"ab\u0000c")" - R"(,"cordWithZero":"12\u00003","replacementString":"${unknown}"})")); -} - -TEST_P(JsonTest, TestPreserveProtoFieldNames) { - TestMessage m; - m.mutable_message_value(); - - PrintOptions options; - options.preserve_proto_field_names = true; - EXPECT_THAT(ToJson(m, options), IsOkAndHolds("{\"message_value\":{}}")); - -} - -TEST_P(JsonTest, Camels) { - protobuf_unittest::TestCamelCaseFieldNames m; - m.set_stringfield("sTRINGfIELD"); - - EXPECT_THAT(ToJson(m), IsOkAndHolds(R"({"StringField":"sTRINGfIELD"})")); -} - -TEST_P(JsonTest, EvilString) { - auto m = ToProto(R"json( - {"string_value": ")json" - "\n\r\b\f\1\2\3" - "\"}"); - ASSERT_OK(m); - EXPECT_EQ(m->string_value(), "\n\r\b\f\1\2\3"); -} - -TEST_P(JsonTest, TestAlwaysPrintEnumsAsInts) { - TestMessage orig; - orig.set_enum_value(proto3::BAR); - orig.add_repeated_enum_value(proto3::FOO); - orig.add_repeated_enum_value(proto3::BAR); - - PrintOptions print_options; - print_options.always_print_enums_as_ints = true; - - auto printed = ToJson(orig, print_options); - ASSERT_THAT(printed, - IsOkAndHolds("{\"enumValue\":1,\"repeatedEnumValue\":[0,1]}")); - - auto parsed = ToProto(*printed); - ASSERT_OK(parsed); - - EXPECT_EQ(parsed->enum_value(), proto3::BAR); - EXPECT_THAT(parsed->repeated_enum_value(), - ElementsAre(proto3::FOO, proto3::BAR)); -} - -TEST_P(JsonTest, TestPrintEnumsAsIntsWithDefaultValue) { - TestEnumValue orig; - // orig.set_enum_value1(proto3::FOO) - orig.set_enum_value2(proto3::FOO); - orig.set_enum_value3(proto3::BAR); - - PrintOptions print_options; - print_options.always_print_enums_as_ints = true; - print_options.always_print_primitive_fields = true; - - auto printed = ToJson(orig, print_options); - ASSERT_THAT( - printed, - IsOkAndHolds("{\"enumValue1\":0,\"enumValue2\":0,\"enumValue3\":1}")); - - auto parsed = ToProto(*printed); - - EXPECT_EQ(parsed->enum_value1(), proto3::FOO); - EXPECT_EQ(parsed->enum_value2(), proto3::FOO); - EXPECT_EQ(parsed->enum_value3(), proto3::BAR); -} - -TEST_P(JsonTest, TestPrintProto2EnumAsIntWithDefaultValue) { - protobuf_unittest::TestDefaultEnumValue orig; - - PrintOptions print_options; - print_options.always_print_enums_as_ints = true; - print_options.always_print_primitive_fields = true; - - auto printed = ToJson(orig, print_options); - ASSERT_THAT(printed, IsOkAndHolds("{\"enumValue\":2}")); - - auto parsed = ToProto(*printed); - ASSERT_OK(parsed); - - EXPECT_EQ(parsed->enum_value(), protobuf_unittest::DEFAULT); -} - -TEST_P(JsonTest, QuotedEnumValue) { - auto m = ToProto(R"json( - {"enumValue1": "1"} - )json"); - ASSERT_OK(m); - EXPECT_THAT(m->enum_value1(), proto3::BAR); -} - -TEST_P(JsonTest, WebSafeBytes) { - auto m = ToProto(R"json({ - "bytesValue": "-_" - })json"); - ASSERT_OK(m); - - EXPECT_EQ(m->bytes_value(), "\xfb"); -} - -TEST_P(JsonTest, ParseMessage) { - auto m = ToProto(R"json( - { - "boolValue": true, - "int32Value": 1234567891, - "int64Value": -5302428716536692736, - "uint32Value": 42, - "uint64Value": 530242871653669, - "floatValue": 3.4e+38, - "doubleValue": -55.3, - "stringValue": "foo bar baz", - "enumValue": "BAR", - "messageValue": { - "value": 2048 - }, - - "repeatedBoolValue": [true], - "repeatedInt32Value": [0, -42], - "repeatedUint64Value": [1, 2], - "repeatedDoubleValue": [1.5, -2], - "repeatedStringValue": ["foo", "bar ", ""], - "repeatedEnumValue": [1, "FOO"], - "repeatedMessageValue": [ - {"value": 40}, - {}, - {"value": 96} - ] - } - )json"); - ASSERT_OK(m); - - EXPECT_TRUE(m->bool_value()); - EXPECT_EQ(m->int32_value(), 1234567891); - EXPECT_EQ(m->int64_value(), -5302428716536692736); - EXPECT_EQ(m->uint32_value(), 42); - EXPECT_EQ(m->uint64_value(), 530242871653669); - EXPECT_EQ(m->float_value(), 3.4e+38f); - EXPECT_EQ(m->double_value(), - -55.3); // This value is intentionally not a nice - // round number in base 2, so its floating point - // representation has many digits at the end, which - // printing back to JSON must handle well. - EXPECT_EQ(m->string_value(), "foo bar baz"); - EXPECT_EQ(m->enum_value(), proto3::EnumType::BAR); - EXPECT_EQ(m->message_value().value(), 2048); - - EXPECT_THAT(m->repeated_bool_value(), ElementsAre(true)); - EXPECT_THAT(m->repeated_int32_value(), ElementsAre(0, -42)); - EXPECT_THAT(m->repeated_uint64_value(), ElementsAre(1, 2)); - EXPECT_THAT(m->repeated_double_value(), ElementsAre(1.5, -2)); - EXPECT_THAT(m->repeated_string_value(), ElementsAre("foo", "bar ", "")); - EXPECT_THAT(m->repeated_enum_value(), ElementsAre(proto3::BAR, proto3::FOO)); - - ASSERT_THAT(m->repeated_message_value(), SizeIs(3)); - EXPECT_EQ(m->repeated_message_value(0).value(), 40); - EXPECT_EQ(m->repeated_message_value(1).value(), 0); - EXPECT_EQ(m->repeated_message_value(2).value(), 96); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"boolValue":true,"int32Value":1234567891,"int64Value":"-5302428716536692736",)" - R"("uint32Value":42,"uint64Value":"530242871653669","floatValue":3.4e+38,)" - R"("doubleValue":-55.3,"stringValue":"foo bar baz","enumValue":"BAR",)" - R"("messageValue":{"value":2048},"repeatedBoolValue":[true],"repeatedInt32Value":[0,-42])" - R"(,"repeatedUint64Value":["1","2"],"repeatedDoubleValue":[1.5,-2],)" - R"("repeatedStringValue":["foo","bar ",""],"repeatedEnumValue":["BAR","FOO"],)" - R"("repeatedMessageValue":[{"value":40},{},{"value":96}]})")); -} - -TEST_P(JsonTest, CurseOfAtob) { - auto m = ToProto(R"json( - { - repeatedBoolValue: ["0", "1", "false", "true", "f", "t", "no", "yes", "n", "y"] - } - )json"); - ASSERT_OK(m); - EXPECT_THAT(m->repeated_bool_value(), - ElementsAre(false, true, false, true, false, true, false, true, - false, true)); -} - -TEST_P(JsonTest, FloatPrecision) { - google::protobuf::Value v; - v.mutable_list_value()->add_values()->set_number_value(0.9900000095367432); - v.mutable_list_value()->add_values()->set_number_value(0.8799999952316284); - - EXPECT_THAT(ToJson(v), - IsOkAndHolds("[0.99000000953674316,0.87999999523162842]")); -} - -TEST_P(JsonTest, FloatMinMaxValue) { - // 3.4028235e38 is FLT_MAX to 8-significant-digits. The final digit (5) - // is rounded up; that means that when parsing this as a 64-bit FP number, - // the value ends up higher than FLT_MAX. We still want to accept it though, - // as a reasonable representation of FLT_MAX. - auto m = ToProto(R"json( - { - "repeatedFloatValue": [3.4028235e38, -3.4028235e38], - } - )json"); - ASSERT_OK(m); - EXPECT_THAT(m->repeated_float_value(), ElementsAre(FLT_MAX, -FLT_MAX)); -} - -TEST_P(JsonTest, FloatOutOfRange) { - // Check that the slightly-lenient parsing demonstrated in FloatMinMaxValue - // doesn't mean we allow all values. The value being parsed differs only - // in the least significant (represented) digit. - auto m = ToProto(R"json( - { - "floatValue": 3.4028236e38 - } - )json"); - EXPECT_THAT(m, StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, ParseLegacySingleRepeatedField) { - auto m = ToProto(R"json({ - "repeatedInt32Value": 1997, - "repeatedStringValue": "oh no", - "repeatedEnumValue": "BAR", - "repeatedMessageValue": {"value": -1} - })json"); - ASSERT_OK(m); - - EXPECT_THAT(m->repeated_int32_value(), ElementsAre(1997)); - EXPECT_THAT(m->repeated_string_value(), ElementsAre("oh no")); - EXPECT_THAT(m->repeated_enum_value(), ElementsAre(proto3::EnumType::BAR)); - - ASSERT_THAT(m->repeated_message_value(), SizeIs(1)); - EXPECT_EQ(m->repeated_message_value(0).value(), -1); - - EXPECT_THAT(ToJson(*m), - IsOkAndHolds(R"({"repeatedInt32Value":[1997],)" - R"("repeatedStringValue":["oh no"],)" - R"("repeatedEnumValue":["BAR"],)" - R"("repeatedMessageValue":[{"value":-1}]})")); -} - -TEST_P(JsonTest, ParseMap) { - TestMap message; - (*message.mutable_string_map())["hello"] = 1234; - auto printed = ToJson(message); - ASSERT_THAT(printed, IsOkAndHolds(R"({"stringMap":{"hello":1234}})")); - - auto other = ToProto(*printed); - ASSERT_OK(other); - EXPECT_EQ(other->DebugString(), message.DebugString()); -} - -TEST_P(JsonTest, RepeatedMapKey) { - EXPECT_THAT(ToProto(R"json({ - "string_map": { - "twiceKey": 0, - "twiceKey": 1 - } - })json"), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, ParsePrimitiveMapIn) { - MapIn message; - PrintOptions print_options; - print_options.always_print_primitive_fields = true; - auto printed = ToJson(message, print_options); - ASSERT_THAT( - ToJson(message, print_options), - IsOkAndHolds(R"({"other":"","things":[],"mapInput":{},"mapAny":{}})")); - - auto other = ToProto(*printed); - ASSERT_OK(other); - EXPECT_EQ(other->DebugString(), message.DebugString()); -} - -TEST_P(JsonTest, PrintPrimitiveOneof) { - TestOneof message; - PrintOptions options; - options.always_print_primitive_fields = true; - message.mutable_oneof_message_value(); - EXPECT_THAT(ToJson(message, options), - IsOkAndHolds(R"({"oneofMessageValue":{"value":0}})")); - - message.set_oneof_int32_value(1); - EXPECT_THAT(ToJson(message, options), - IsOkAndHolds(R"({"oneofInt32Value":1})")); -} - -TEST_P(JsonTest, ParseOverOneof) { - TestOneof m; - m.set_oneof_string_value("foo"); - ASSERT_OK(ToProto(m, R"json({ - "oneofInt32Value": 5, - })json")); - EXPECT_EQ(m.oneof_int32_value(), 5); -} - -TEST_P(JsonTest, RepeatedSingularKeys) { - auto m = ToProto(R"json({ - "int32Value": 1, - "int32Value": 2 - })json"); - EXPECT_OK(m); - EXPECT_EQ(m->int32_value(), 2); -} - -TEST_P(JsonTest, RepeatedRepeatedKeys) { - auto m = ToProto(R"json({ - "repeatedInt32Value": [1], - "repeatedInt32Value": [2, 3] - })json"); - EXPECT_OK(m); - EXPECT_THAT(m->repeated_int32_value(), ElementsAre(1, 2, 3)); -} - -TEST_P(JsonTest, RepeatedOneofKeys) { - EXPECT_THAT(ToProto(R"json({ - "oneofInt32Value": 1, - "oneofStringValue": "foo" - })json"), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, TestParseIgnoreUnknownFields) { - ParseOptions options; - options.ignore_unknown_fields = true; - EXPECT_OK(ToProto(R"({"unknownName":0})", options)); - - TestMessage m; - m.GetReflection()->MutableUnknownFields(&m)->AddFixed32(9001, 9001); - m.GetReflection()->MutableUnknownFields(&m)->AddFixed64(9001, 9001); - m.GetReflection()->MutableUnknownFields(&m)->AddVarint(9001, 9001); - m.GetReflection()->MutableUnknownFields(&m)->AddLengthDelimited(9001, "9001"); - EXPECT_THAT(ToJson(m), IsOkAndHolds("{}")); -} - -TEST_P(JsonTest, TestParseErrors) { - // Parsing should fail if the field name can not be recognized. - EXPECT_THAT(ToProto(R"({"unknownName": 0})"), - StatusIs(absl::StatusCode::kInvalidArgument)); - // Parsing should fail if the value is invalid. - EXPECT_THAT(ToProto(R"("{"int32Value": 2147483648})"), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, TestDynamicMessage) { - // Create a new DescriptorPool with the same protos as the generated one. - DescriptorPoolDatabase database(*DescriptorPool::generated_pool()); - DescriptorPool pool(&database); - // A dynamic version of the test proto. - DynamicMessageFactory factory; - std::unique_ptr message( - factory.GetPrototype(pool.FindMessageTypeByName("proto3.TestMessage")) - ->New()); - ASSERT_OK(ToProto(*message, R"json( - { - "int32Value": 1024, - "repeatedInt32Value": [1, 2], - "messageValue": { - "value": 2048 - }, - "repeatedMessageValue": [ - {"value": 40}, - {"value": 96} - ] - } - )json")); - - // Convert to generated message for easy inspection. - TestMessage generated; - EXPECT_TRUE(generated.ParseFromString(message->SerializeAsString())); - - EXPECT_EQ(generated.int32_value(), 1024); - EXPECT_THAT(generated.repeated_int32_value(), ElementsAre(1, 2)); - - EXPECT_EQ(generated.message_value().value(), 2048); - ASSERT_EQ(generated.repeated_message_value_size(), 2); - EXPECT_EQ(generated.repeated_message_value(0).value(), 40); - EXPECT_EQ(generated.repeated_message_value(1).value(), 96); - - auto message_json = ToJson(*message); - ASSERT_OK(message_json); - auto generated_json = ToJson(generated); - ASSERT_OK(generated_json); - EXPECT_EQ(*message_json, *generated_json); -} - -TEST_P(JsonTest, TestParsingAny) { - auto m = ToProto(R"json( - { - "value": { - "@type": "type.googleapis.com/proto3.TestMessage", - "int32_value": 5, - "string_value": "expected_value", - "message_value": {"value": 1} - } - } - )json"); - ASSERT_OK(m); - - TestMessage t; - ASSERT_TRUE(m->value().UnpackTo(&t)); - EXPECT_EQ(t.int32_value(), 5); - EXPECT_EQ(t.string_value(), "expected_value"); - EXPECT_EQ(t.message_value().value(), 1); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"value":{"@type":"type.googleapis.com/proto3.TestMessage",)" - R"("int32Value":5,"stringValue":"expected_value","messageValue":{"value":1}}})")); -} - -TEST_P(JsonTest, TestParsingAnyMiddleAtType) { - auto m = ToProto(R"json( - { - "value": { - "int32_value": 5, - "string_value": "expected_value", - "@type": "type.googleapis.com/proto3.TestMessage", - "message_value": {"value": 1} - } - } - )json"); - ASSERT_OK(m); - - TestMessage t; - ASSERT_TRUE(m->value().UnpackTo(&t)); - EXPECT_EQ(t.int32_value(), 5); - EXPECT_EQ(t.string_value(), "expected_value"); - EXPECT_EQ(t.message_value().value(), 1); -} - -TEST_P(JsonTest, TestParsingAnyEndAtType) { - auto m = ToProto(R"json( - { - "value": { - "int32_value": 5, - "string_value": "expected_value", - "message_value": {"value": 1}, - "@type": "type.googleapis.com/proto3.TestMessage" - } - } - )json"); - ASSERT_OK(m); - - TestMessage t; - ASSERT_TRUE(m->value().UnpackTo(&t)); - EXPECT_EQ(t.int32_value(), 5); - EXPECT_EQ(t.string_value(), "expected_value"); - EXPECT_EQ(t.message_value().value(), 1); -} - -TEST_P(JsonTest, TestParsingNestedAnys) { - auto m = ToProto(R"json( - { - "value": { - "value": { - "int32_value": 5, - "string_value": "expected_value", - "message_value": {"value": 1}, - "@type": "type.googleapis.com/proto3.TestMessage" - }, - "@type": "type.googleapis.com/google.protobuf.Any" - } - } - )json"); - ASSERT_OK(m); - - google::protobuf::Any inner; - ASSERT_TRUE(m->value().UnpackTo(&inner)); - - TestMessage t; - ASSERT_TRUE(inner.UnpackTo(&t)); - EXPECT_EQ(t.int32_value(), 5); - EXPECT_EQ(t.string_value(), "expected_value"); - EXPECT_EQ(t.message_value().value(), 1); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"value":{"@type":"type.googleapis.com/google.protobuf.Any",)" - R"("value":{"@type":"type.googleapis.com/proto3.TestMessage",)" - R"("int32Value":5,"stringValue":"expected_value","messageValue":{"value":1}}}})")); -} - -TEST_P(JsonTest, TestParsingBrokenAny) { - auto m = ToProto(R"json( - { - "value": {} - } - )json"); - ASSERT_OK(m); - EXPECT_EQ(m->value().type_url(), ""); - EXPECT_EQ(m->value().value(), ""); - - EXPECT_THAT(ToProto(R"json( - { - "value": { - "type_url": "garbage", - "value": "bW9yZSBnYXJiYWdl" - } - } - )json"), - StatusIs(absl::StatusCode::kInvalidArgument)); - - TestAny m2; - m2.mutable_value(); - EXPECT_THAT(ToJson(m2), IsOkAndHolds(R"({"value":{}})")); - m2.mutable_value()->set_value("garbage"); - // The ESF parser does not return InvalidArgument for this error. - EXPECT_THAT(ToJson(m2), Not(StatusIs(absl::StatusCode::kOk))); - - m2.Clear(); - m2.mutable_value()->set_type_url("type.googleapis.com/proto3.TestMessage"); - EXPECT_THAT( - ToJson(m2), - IsOkAndHolds( - R"({"value":{"@type":"type.googleapis.com/proto3.TestMessage"}})")); -} - -TEST_P(JsonTest, TestFlatList) { - auto m = ToProto(R"json( - { - "repeatedInt32Value": [[[5]], [6]] - } - )json"); - ASSERT_OK(m); - EXPECT_THAT(m->repeated_int32_value(), ElementsAre(5, 6)); - - // The above flatteing behavior is suppressed for google::protobuf::ListValue. - auto m2 = ToProto(R"json( - { - "repeatedInt32Value": [[[5]], [6]] - } - )json"); - ASSERT_OK(m2); - auto fields = m2->struct_value().fields(); - auto list = fields["repeatedInt32Value"].list_value(); - EXPECT_EQ(list.values(0) - .list_value() - .values(0) - .list_value() - .values(0) - .number_value(), - 5); - EXPECT_EQ(list.values(1).list_value().values(0).number_value(), 6); -} - -TEST_P(JsonTest, ParseWrappers) { - auto m = ToProto(R"json( - { - "boolValue": true, - "int32Value": 42, - "stringValue": "ieieo", - } - )json"); - ASSERT_OK(m); - - EXPECT_TRUE(m->bool_value().value()); - EXPECT_EQ(m->int32_value().value(), 42); - EXPECT_EQ(m->string_value().value(), "ieieo"); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"boolValue":true,"int32Value":42,"stringValue":"ieieo"})")); - - auto m2 = ToProto(R"json( - { - "boolValue": { "value": true }, - "int32Value": { "value": 42 }, - "stringValue": { "value": "ieieo" }, - } - )json"); - ASSERT_OK(m2); - - EXPECT_TRUE(m2->bool_value().value()); - EXPECT_EQ(m2->int32_value().value(), 42); - EXPECT_EQ(m2->string_value().value(), "ieieo"); -} - -TEST_P(JsonTest, TestParsingUnknownAnyFields) { - absl::string_view input = R"json( - { - "value": { - "@type": "type.googleapis.com/proto3.TestMessage", - "unknown_field": "UNKNOWN_VALUE", - "string_value": "expected_value" - } - } - )json"; - - EXPECT_THAT(ToProto(input), - StatusIs(absl::StatusCode::kInvalidArgument)); - - ParseOptions options; - options.ignore_unknown_fields = true; - auto m = ToProto(input, options); - ASSERT_OK(m); - - TestMessage t; - ASSERT_TRUE(m->value().UnpackTo(&t)); - EXPECT_EQ(t.string_value(), "expected_value"); -} - -TEST_P(JsonTest, TestHugeBareString) { - auto m = ToProto(R"json({ - "int64Value": 6009652459062546621 - })json"); - ASSERT_OK(m); - EXPECT_EQ(m->int64_value(), 6009652459062546621); -} - -TEST_P(JsonTest, TestParsingUnknownEnumsProto2) { - absl::string_view input = R"json({"ayuLmao": "UNKNOWN_VALUE"})json"; - - EXPECT_THAT(ToProto(input), - StatusIs(absl::StatusCode::kInvalidArgument)); - - ParseOptions options; - options.ignore_unknown_fields = true; - auto m = ToProto(input, options); - ASSERT_OK(m); - EXPECT_FALSE(m->has_a()); -} - -TEST_P(JsonTest, TestParsingUnknownEnumsProto3) { - TestMessage m; - absl::string_view input = R"json({"enum_value":"UNKNOWN_VALUE"})json"; - - m.set_enum_value(proto3::BAR); - ASSERT_THAT(ToProto(m, input), StatusIs(absl::StatusCode::kInvalidArgument)); - EXPECT_EQ(m.enum_value(), proto3::BAR); // Keep previous value - - ParseOptions options; - options.ignore_unknown_fields = true; - ASSERT_OK(ToProto(m, input, options)); - EXPECT_EQ(m.enum_value(), 0); // Unknown enum value must be decoded as 0 -} - -TEST_P(JsonTest, TestParsingUnknownEnumsProto3FromInt) { - TestMessage m; - absl::string_view input = R"json({"enum_value":12345})json"; - - m.set_enum_value(proto3::BAR); - ASSERT_OK(ToProto(m, input)); - EXPECT_EQ(m.enum_value(), 12345); - - ParseOptions options; - options.ignore_unknown_fields = true; - ASSERT_OK(ToProto(m, input, options)); - EXPECT_EQ(m.enum_value(), 12345); -} - -// Trying to pass an object as an enum field value is always treated as an -// error -TEST_P(JsonTest, TestParsingUnknownEnumsProto3FromObject) { - absl::string_view input = R"json({"enum_value": {}})json"; - - EXPECT_THAT(ToProto(input), - StatusIs(absl::StatusCode::kInvalidArgument)); - - ParseOptions options; - options.ignore_unknown_fields = true; - EXPECT_THAT(ToProto(input, options), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, TestParsingUnknownEnumsProto3FromArray) { - absl::string_view input = R"json({"enum_value": []})json"; - - EXPECT_THAT(ToProto(input), - StatusIs(absl::StatusCode::kInvalidArgument)); - - ParseOptions options; - options.ignore_unknown_fields = true; - EXPECT_THAT(ToProto(input, options), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, TestParsingEnumCaseSensitive) { - TestMessage m; - m.set_enum_value(proto3::FOO); - EXPECT_THAT(ToProto(m, R"json({"enum_value": "bar"})json"), - StatusIs(absl::StatusCode::kInvalidArgument)); - // Default behavior is case-sensitive, so keep previous value. - EXPECT_EQ(m.enum_value(), proto3::FOO); -} - -TEST_P(JsonTest, TestParsingEnumLowercase) { - ParseOptions options; - options.case_insensitive_enum_parsing = true; - auto m = - ToProto(R"json({"enum_value": "TLSv1_2"})json", options); - ASSERT_OK(m); - EXPECT_THAT(m->enum_value(), proto3::TLSv1_2); -} - -TEST_P(JsonTest, TestParsingEnumIgnoreCase) { - TestMessage m; - m.set_enum_value(proto3::FOO); - - ParseOptions options; - options.case_insensitive_enum_parsing = true; - ASSERT_OK(ToProto(m, R"json({"enum_value":"bar"})json", options)); - EXPECT_EQ(m.enum_value(), proto3::BAR); -} - -TEST_P(JsonTest, Extensions) { - if (GetParam() == Codec::kResolver) { - GTEST_SKIP(); - } - - auto m = ToProto(R"json({ - "[protobuf_unittest.TestMixedFieldsAndExtensions.c]": 42, - "a": 5, - "b": [1, 2, 3], - "[protobuf_unittest.TestMixedFieldsAndExtensions.d]": [1, 1, 2, 3, 5, 8, 13] - })json"); - ASSERT_OK(m); - EXPECT_EQ(m->a(), 5); - EXPECT_THAT(m->b(), ElementsAre(1, 2, 3)); - EXPECT_EQ(m->GetExtension(protobuf_unittest::TestMixedFieldsAndExtensions::c), - 42); - EXPECT_THAT( - m->GetRepeatedExtension(protobuf_unittest::TestMixedFieldsAndExtensions::d), - ElementsAre(1, 1, 2, 3, 5, 8, 13)); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"a":5,)" - R"("[protobuf_unittest.TestMixedFieldsAndExtensions.c]":42,)" - R"("b":[1,2,3],)" - R"("[protobuf_unittest.TestMixedFieldsAndExtensions.d]":[1,1,2,3,5,8,13]})")); -} - -// Parsing does NOT work like MergeFrom: existing repeated field values are -// clobbered, not appended to. -TEST_P(JsonTest, TestOverwriteRepeated) { - TestMessage m; - m.add_repeated_int32_value(5); - - ASSERT_OK(ToProto(m, R"json({"repeated_int32_value": [1, 2, 3]})json")); - EXPECT_THAT(m.repeated_int32_value(), ElementsAre(1, 2, 3)); -} - - -TEST_P(JsonTest, TestDuration) { - auto m = ToProto(R"json( - { - "value": "123456.789s", - "repeated_value": ["0.1s", "999s"] - } - )json"); - ASSERT_OK(m); - - EXPECT_EQ(m->value().seconds(), 123456); - EXPECT_EQ(m->value().nanos(), 789000000); - - EXPECT_THAT(m->repeated_value(), SizeIs(2)); - EXPECT_EQ(m->repeated_value(0).seconds(), 0); - EXPECT_EQ(m->repeated_value(0).nanos(), 100000000); - EXPECT_EQ(m->repeated_value(1).seconds(), 999); - EXPECT_EQ(m->repeated_value(1).nanos(), 0); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"value":"123456.789s","repeatedValue":["0.100s","999s"]})")); - - auto m2 = ToProto(R"json( - { - "value": {"seconds": 4, "nanos": 5}, - } - )json"); - ASSERT_OK(m2); - - EXPECT_EQ(m2->value().seconds(), 4); - EXPECT_EQ(m2->value().nanos(), 5); - - // Negative duration with zero seconds. - auto m3 = ToProto(R"json( - { - "value": {"nanos": -5}, - } - )json"); - ASSERT_OK(m3); - EXPECT_EQ(m3->value().seconds(), 0); - EXPECT_EQ(m3->value().nanos(), -5); - EXPECT_THAT(ToJson(m3->value()), IsOkAndHolds("\"-0.000000005s\"")); - - // Negative duration with zero nanos. - auto m4 = ToProto(R"json( - { - "value": {"seconds": -5}, - } - )json"); - ASSERT_OK(m4); - EXPECT_EQ(m4->value().seconds(), -5); - EXPECT_EQ(m4->value().nanos(), 0); - EXPECT_THAT(ToJson(m4->value()), IsOkAndHolds("\"-5s\"")); - - // Parse "0.5s" as a JSON string. - auto m5 = ToProto(R"json( - { - "value": "0.5s", - } - )json"); - ASSERT_OK(m5); - EXPECT_EQ(m5->value().seconds(), 0); - EXPECT_EQ(m5->value().nanos(), 500000000); - EXPECT_THAT(ToJson(m5->value()), IsOkAndHolds("\"0.500s\"")); -} - -// These tests are not exhaustive; tests in //third_party/protobuf/conformance -// are more comprehensive. -TEST_P(JsonTest, TestTimestamp) { - auto m = ToProto(R"json( - { - "value": "1996-02-27T12:00:00Z", - "repeated_value": ["9999-12-31T23:59:59Z"] - } - )json"); - ASSERT_OK(m); - - EXPECT_EQ(m->value().seconds(), 825422400); - EXPECT_EQ(m->value().nanos(), 0); - EXPECT_THAT(m->repeated_value(), SizeIs(1)); - EXPECT_EQ(m->repeated_value(0).seconds(), 253402300799); - EXPECT_EQ(m->repeated_value(0).nanos(), 0); - - EXPECT_THAT( - ToJson(*m), - IsOkAndHolds( - R"({"value":"1996-02-27T12:00:00Z","repeatedValue":["9999-12-31T23:59:59Z"]})")); - - auto m2 = ToProto(R"json( - { - "value": {"seconds": 4, "nanos": 5}, - } - )json"); - ASSERT_OK(m2); - - EXPECT_EQ(m2->value().seconds(), 4); - EXPECT_EQ(m2->value().nanos(), 5); -} - -// This test case comes from Envoy's tests. They like to parse a Value out of -// YAML, turn it into JSON, and then parse it as a different proto. This means -// we must be extremely careful with integer fields, because they need to -// round-trip through doubles. This happens all over Envoy. :( -TEST_P(JsonTest, TestEnvoyRoundTrip) { - auto m = ToProto(R"json( - { - "value": {"seconds": 1234567891, "nanos": 234000000}, - } - )json"); - ASSERT_OK(m); - - auto j = ToJson(*m); - ASSERT_OK(j); - - auto m2 = ToProto(*j); - ASSERT_OK(m2); - - EXPECT_EQ(m2->value().seconds(), 1234567891); - EXPECT_EQ(m2->value().nanos(), 234000000); -} - -TEST_P(JsonTest, TestFieldMask) { - auto m = ToProto(R"json( - { - "value": "foo,bar.bazBaz" - } - )json"); - ASSERT_OK(m); - - EXPECT_THAT(m->value().paths(), ElementsAre("foo", "bar.baz_baz")); - EXPECT_THAT(ToJson(*m), IsOkAndHolds(R"({"value":"foo,bar.bazBaz"})")); - - auto m2 = ToProto(R"json( - { - "value": { - "paths": ["yep.really"] - }, - } - )json"); - ASSERT_OK(m2); - - EXPECT_THAT(m2->value().paths(), ElementsAre("yep.really")); -} - -TEST_P(JsonTest, TestFieldMaskSnakeCase) { - auto m = ToProto(R"json( - { - "value": "foo_bar" - } - )json"); - ASSERT_OK(m); - - EXPECT_THAT(m->value().paths(), ElementsAre("foo_bar")); -} - -TEST_P(JsonTest, TestLegalNullsInArray) { - auto m = ToProto(R"json({ - "repeatedNullValue": [null] - })json"); - ASSERT_OK(m); - - EXPECT_THAT(m->repeated_null_value(), - ElementsAre(google::protobuf::NULL_VALUE)); - - auto m2 = ToProto(R"json({ - "repeatedValue": [null] - })json"); - ASSERT_OK(m2); - - ASSERT_THAT(m2->repeated_value(), SizeIs(1)); - EXPECT_TRUE(m2->repeated_value(0).has_null_value()); - - m2->Clear(); - m2->mutable_value(); // Materialize an empty singular Value. - m2->add_repeated_value(); - m2->add_repeated_value()->set_string_value("solitude"); - m2->add_repeated_value(); - EXPECT_THAT(ToJson(*m2), IsOkAndHolds(R"({"repeatedValue":["solitude"]})")); -} - -TEST_P(JsonTest, EmptyValue) { - EXPECT_THAT(ToJson(google::protobuf::Value()), IsOkAndHolds("")); - - google::protobuf::Struct s; - s.mutable_fields()->emplace("empty", google::protobuf::Value()); - EXPECT_THAT(ToJson(s), IsOkAndHolds("{}")); -} - -TEST_P(JsonTest, TrailingGarbage) { - EXPECT_THAT(ToProto("{}garbage"), - StatusIs(absl::StatusCode::kInvalidArgument)); -} - -TEST_P(JsonTest, ListList) { - auto m = ToProto(R"json({ - "repeated_value": [["ayy", "lmao"]] - })json"); - ASSERT_OK(m); - - EXPECT_EQ(m->repeated_value(0).values(0).string_value(), "ayy"); - EXPECT_EQ(m->repeated_value(0).values(1).string_value(), "lmao"); - - m = ToProto(R"json({ - "repeated_value": [{ - "values": ["ayy", "lmao"] - }] - })json"); - ASSERT_OK(m); - - EXPECT_EQ(m->repeated_value(0).values(0).string_value(), "ayy"); - EXPECT_EQ(m->repeated_value(0).values(1).string_value(), "lmao"); -} - -TEST_P(JsonTest, HtmlEscape) { - TestMessage m; - m.set_string_value(""); - EXPECT_THAT(ToJson(m), - IsOkAndHolds(R"({"stringValue":"\u003c/script\u003e"})")); - - proto3::TestEvilJson m2; - PrintOptions opts; - opts.always_print_primitive_fields = true; - EXPECT_THAT( - ToJson(m2, opts), - IsOkAndHolds( - R"({"regular_name":0,"\u003c/script\u003e":0,)" - R"("unbalanced\"quotes":0,)" - R"("\"\u003cscript\u003ealert('hello!);\u003c/script\u003e":0})")); -} - -TEST_P(JsonTest, FieldOrder) { - // $ protoscope -s <<< "3: 3 22: 2 1: 1 22: 2" - std::string out; - absl::Status s = BinaryToJsonString( - resolver_.get(), "type.googleapis.com/proto3.TestMessage", - "\x18\x03\xb0\x01\x02\x08\x01\xb0\x01\x02", &out); - ASSERT_OK(s); - EXPECT_EQ( - out, - R"({"boolValue":true,"int64Value":"3","repeatedInt32Value":[2,2]})"); -} - -// JSON values get special treatment when it comes to pre-existing values in -// their repeated fields, when parsing through their dedicated syntax. -TEST_P(JsonTest, ClearPreExistingRepeatedInJsonValues) { - google::protobuf::ListValue l; - l.add_values()->set_string_value("hello"); - ASSERT_OK(JsonStringToMessage("[]", &l)); - EXPECT_THAT(l.values(), IsEmpty()); - - google::protobuf::Struct s; - (*s.mutable_fields())["hello"].set_string_value("world"); - ASSERT_OK(JsonStringToMessage("{}", &s)); - EXPECT_THAT(s.fields(), IsEmpty()); -} - -} // namespace -} // namespace json -} // namespace protobuf -} // namespace google diff --git a/libs/protobuf/src/google/protobuf/lite_arena_unittest.cc b/libs/protobuf/src/google/protobuf/lite_arena_unittest.cc index 927663d..d68c6c9 100644 --- a/libs/protobuf/src/google/protobuf/lite_arena_unittest.cc +++ b/libs/protobuf/src/google/protobuf/lite_arena_unittest.cc @@ -28,8 +28,8 @@ // (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/arena_test_util.h" -#include "google/protobuf/map_lite_test_util.h" +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/lite_unittest.cc b/libs/protobuf/src/google/protobuf/lite_unittest.cc index 1a03171..583d325 100644 --- a/libs/protobuf/src/google/protobuf/lite_unittest.cc +++ b/libs/protobuf/src/google/protobuf/lite_unittest.cc @@ -34,22 +34,21 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_lite_unittest.pb.h" -#include "google/protobuf/unittest_lite.pb.h" +#include +#include +#include +#include #include -#include "absl/strings/match.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/arena_test_util.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/map_lite_test_util.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/test_util_lite.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -675,7 +674,8 @@ TEST(Lite, AllLite28) { MapLiteTestUtil::SetMapFields(&message1); size_t size = message1.ByteSizeLong(); data.resize(size); - ::uint8_t* start = reinterpret_cast<::uint8_t*>(&data[0]); + ::uint8_t* start = + reinterpret_cast<::uint8_t*>(::google::protobuf::string_as_array(&data)); ::uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -695,7 +695,7 @@ TEST(Lite, AllLite29) { data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); message1.SerializeWithCachedSizes(&output_stream); EXPECT_FALSE(output_stream.HadError()); @@ -1143,8 +1143,8 @@ TEST(Lite, CorrectEnding) { TEST(Lite, DebugString) { protobuf_unittest::TestAllTypesLite message1, message2; - EXPECT_TRUE(absl::StartsWith(message1.DebugString(), "MessageLite at 0x")); - EXPECT_TRUE(absl::StartsWith(message2.DebugString(), "MessageLite at 0x")); + EXPECT_TRUE(HasPrefixString(message1.DebugString(), "MessageLite at 0x")); + EXPECT_TRUE(HasPrefixString(message2.DebugString(), "MessageLite at 0x")); // DebugString() and ShortDebugString() are the same for now. EXPECT_EQ(message1.DebugString(), message1.ShortDebugString()); diff --git a/libs/protobuf/src/google/protobuf/map.cc b/libs/protobuf/src/google/protobuf/map.cc index 1d7535d..d60a9a2 100644 --- a/libs/protobuf/src/google/protobuf/map.cc +++ b/libs/protobuf/src/google/protobuf/map.cc @@ -28,7 +28,7 @@ // (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/map.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/map.h b/libs/protobuf/src/google/protobuf/map.h index 9f7c200..008c192 100644 --- a/libs/protobuf/src/google/protobuf/map.h +++ b/libs/protobuf/src/google/protobuf/map.h @@ -55,19 +55,19 @@ #include #endif -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/generated_enum_util.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -333,11 +333,6 @@ inline size_t SpaceUsedInValues(const void*) { return 0; } } // namespace internal -#ifdef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE -// This is the class for Map's internal value_type. -template -using MapPair = std::pair; -#else // This is the class for Map's internal value_type. Instead of using // std::pair as value_type, we use this class which provides us more control of // its process of construction and destruction. @@ -368,7 +363,6 @@ struct PROTOBUF_ATTRIBUTE_STANDALONE_DEBUG MapPair { friend class Arena; friend class Map; }; -#endif // Map is an associative container type used to store protobuf map // fields. Each Map instance may or may not use a different hash function, a @@ -385,7 +379,6 @@ class Map { public: using key_type = Key; using mapped_type = T; - using init_type = std::pair; using value_type = MapPair; using pointer = value_type*; @@ -428,22 +421,6 @@ class Map { ~Map() {} private: - template - struct SameAsElementReference - : std::is_same::type>::type, - typename std::remove_cv< - typename std::remove_reference

    ::type>::type> {}; - - template - using RequiresInsertable = - typename std::enable_if::value || - SameAsElementReference

    ::value, - int>::type; - template - using RequiresNotInit = - typename std::enable_if::value, int>::type; - using Allocator = internal::MapAllocator; // InnerMap is a generic hash-based map. It doesn't contain any @@ -489,9 +466,6 @@ class Map { table_(const_cast(internal::kGlobalEmptyTable)), alloc_(arena) {} - InnerMap(const InnerMap&) = delete; - InnerMap& operator=(const InnerMap&) = delete; - ~InnerMap() { if (alloc_.arena() == nullptr && num_buckets_ != internal::kGlobalEmptyTableSize) { @@ -1207,6 +1181,7 @@ class Map { size_type index_of_first_non_null_; void** table_; // an array with num_buckets_ entries Allocator alloc_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(InnerMap); }; // end of class InnerMap template @@ -1295,6 +1270,7 @@ class Map { const_iterator cbegin() const { return begin(); } const_iterator cend() const { return end(); } + // Capacity size_type size() const { return elements_.size(); } bool empty() const { return size() == 0; } @@ -1375,31 +1351,23 @@ class Map { elements_.try_emplace(std::forward(k), std::forward(args)...); return std::pair(iterator(p.first), p.second); } - std::pair insert(init_type&& value) { - return try_emplace(std::move(value.first), std::move(value.second)); + std::pair insert(const value_type& value) { + return try_emplace(value.first, value.second); } - template = 0> - std::pair insert(P&& value) { - return try_emplace(std::forward

    (value).first, - std::forward

    (value).second); + std::pair insert(value_type&& value) { + return try_emplace(value.first, std::move(value.second)); } template std::pair emplace(Args&&... args) { - return EmplaceInternal(Rank0{}, std::forward(args)...); + return insert(value_type(std::forward(args)...)); } template void insert(InputIt first, InputIt last) { for (; first != last; ++first) { - auto&& pair = *first; - try_emplace(pair.first, pair.second); + try_emplace(first->first, first->second); } } - void insert(std::initializer_list values) { - insert(values.begin(), values.end()); - } - template = 0, - RequiresInsertable = 0> - void insert(std::initializer_list

    values) { + void insert(std::initializer_list values) { insert(values.begin(), values.end()); } @@ -1437,7 +1405,7 @@ class Map { void swap(Map& other) { if (arena() == other.arena()) { - InternalSwap(&other); + InternalSwap(other); } else { // TODO(zuguang): optimize this. The temporary copy can be allocated // in the same arena as the other message, and the "other = copy" can @@ -1448,7 +1416,7 @@ class Map { } } - void InternalSwap(Map* other) { elements_.Swap(&other->elements_); } + void InternalSwap(Map& other) { elements_.Swap(&other.elements_); } // Access to hasher. Currently this returns a copy, but it may // be modified to return a const reference in the future. @@ -1460,23 +1428,6 @@ class Map { } private: - struct Rank1 {}; - struct Rank0 : Rank1 {}; - - // We try to construct `init_type` from `Args` with a fall back to - // `value_type`. The latter is less desired as it unconditionally makes a copy - // of `value_type::first`. - template - auto EmplaceInternal(Rank0, Args&&... args) -> - typename std::enable_if::value, - std::pair>::type { - return insert(init_type(std::forward(args)...)); - } - template - std::pair EmplaceInternal(Rank1, Args&&... args) { - return insert(value_type(std::forward(args)...)); - } - Arena* arena() const { return elements_.arena(); } InnerMap elements_; @@ -1492,6 +1443,6 @@ class Map { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MAP_H__ diff --git a/libs/protobuf/src/google/protobuf/map_entry.h b/libs/protobuf/src/google/protobuf/map_entry.h index d220d90..536dec9 100644 --- a/libs/protobuf/src/google/protobuf/map_entry.h +++ b/libs/protobuf/src/google/protobuf/map_entry.h @@ -31,16 +31,16 @@ #ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__ #define GOOGLE_PROTOBUF_MAP_ENTRY_H__ -#include "google/protobuf/port.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/map_entry_lite.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -98,8 +98,6 @@ class MapEntry : public MapEntryImpl(arena) {} - MapEntry(const MapEntry&) = delete; - MapEntry& operator=(const MapEntry&) = delete; ~MapEntry() override { Message::_internal_metadata_.template Delete(); } @@ -123,12 +121,14 @@ class MapEntry : public MapEntryImpl friend class internal::MapField; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); }; } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ diff --git a/libs/protobuf/src/google/protobuf/map_entry_lite.h b/libs/protobuf/src/google/protobuf/map_entry_lite.h index 78ed4f2..6b08cd9 100644 --- a/libs/protobuf/src/google/protobuf/map_entry_lite.h +++ b/libs/protobuf/src/google/protobuf/map_entry_lite.h @@ -37,20 +37,19 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "absl/base/casts.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/map.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" - +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif @@ -160,9 +159,6 @@ class MapEntryImpl : public Base { value_(ValueTypeHandler::Constinit()), _has_bits_{} {} - MapEntryImpl(const MapEntryImpl&) = delete; - MapEntryImpl& operator=(const MapEntryImpl&) = delete; - ~MapEntryImpl() override { if (Base::GetArenaForAllocation() != nullptr) return; KeyTypeHandler::DeleteNoArena(key_); @@ -433,6 +429,8 @@ class MapEntryImpl : public Base { template friend class internal::MapFieldLite; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryImpl); }; template SuperType; constexpr MapEntryLite() {} - MapEntryLite(const MapEntryLite&) = delete; - MapEntryLite& operator=(const MapEntryLite&) = delete; explicit MapEntryLite(Arena* arena) : SuperType(arena) {} ~MapEntryLite() override { MessageLite::_internal_metadata_.template Delete(); } void MergeFrom(const MapEntryLite& other) { MergeFromInternal(other); } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); }; // Helpers for deterministic serialization ============================= @@ -559,6 +558,6 @@ class MapSorterPtr { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/map_field.cc b/libs/protobuf/src/google/protobuf/map_field.cc index b340104..ed662df 100644 --- a/libs/protobuf/src/google/protobuf/map_field.cc +++ b/libs/protobuf/src/google/protobuf/map_field.cc @@ -28,20 +28,18 @@ // (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/map_field.h" +#include #include -#include "google/protobuf/port.h" -#include "google/protobuf/map_field_inl.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace internal { -using ::google::protobuf::internal::DownCast; void MapFieldBase::Destruct() { if (arena_ == nullptr) { @@ -429,7 +427,7 @@ void DynamicMapField::MergeFrom(const MapFieldBase& other) { } void DynamicMapField::Swap(MapFieldBase* other) { - DynamicMapField* other_field = DownCast(other); + DynamicMapField* other_field = down_cast(other); std::swap(this->MapFieldBase::repeated_field_, other_field->repeated_field_); map_.swap(other_field->map_); // a relaxed swap of the atomic @@ -653,4 +651,4 @@ size_t DynamicMapField::SpaceUsedExcludingSelfNoLock() const { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/map_field.h b/libs/protobuf/src/google/protobuf/map_field.h index 0f1a607..287d58f 100644 --- a/libs/protobuf/src/google/protobuf/map_field.h +++ b/libs/protobuf/src/google/protobuf/map_field.h @@ -34,22 +34,22 @@ #include #include -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/map_entry.h" -#include "google/protobuf/map_field_lite.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -342,12 +342,10 @@ class PROTOBUF_EXPORT MapFieldBase { constexpr MapFieldBase(ConstantInitialized) : arena_(nullptr), repeated_field_(nullptr), - mutex_(absl::kConstInit), + mutex_(GOOGLE_PROTOBUF_LINKER_INITIALIZED), state_(STATE_MODIFIED_MAP) {} explicit MapFieldBase(Arena* arena) : arena_(arena), repeated_field_(nullptr), state_(STATE_MODIFIED_MAP) {} - MapFieldBase(const MapFieldBase&) = delete; - MapFieldBase& operator=(const MapFieldBase&) = delete; protected: ~MapFieldBase() { // "protected" stops users from deleting a `MapFieldBase *` @@ -451,8 +449,9 @@ class PROTOBUF_EXPORT MapFieldBase { Arena* arena_; mutable RepeatedPtrField* repeated_field_; - mutable absl::Mutex mutex_; // The thread to synchronize map and repeated - // field needs to get lock first; + mutable internal::WrappedMutex + mutex_; // The thread to synchronize map and repeated field + // needs to get lock first; mutable std::atomic state_; private: @@ -485,6 +484,8 @@ class PROTOBUF_EXPORT MapFieldBase { // Swaps state_ with another MapFieldBase void SwapState(MapFieldBase* other); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldBase); }; // This class provides common Map Reflection implementations for generated @@ -493,8 +494,6 @@ template class TypeDefinedMapFieldBase : public MapFieldBase { public: TypeDefinedMapFieldBase() {} - TypeDefinedMapFieldBase(const TypeDefinedMapFieldBase&) = delete; - TypeDefinedMapFieldBase& operator=(const TypeDefinedMapFieldBase&) = delete; // This constructor is for constant initialized global instances. // It uses a linker initialized mutex, so it is not compatible with regular @@ -530,6 +529,7 @@ class TypeDefinedMapFieldBase : public MapFieldBase { void IncreaseIterator(MapIterator* map_iter) const override; 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 @@ -562,8 +562,6 @@ class MapField : public TypeDefinedMapFieldBase { typedef Map MapType; MapField() : impl_() {} - MapField(const MapField&) = delete; - MapField& operator=(const MapField&) = delete; virtual ~MapField() {} // Destruct() must already have been called! void Destruct() { impl_.Destruct(); @@ -637,6 +635,7 @@ class MapField : public TypeDefinedMapFieldBase { friend class ::PROTOBUF_NAMESPACE_ID::Arena; friend class MapFieldStateTest; // For testing, it needs raw access to impl_ + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapField); }; template #endif // GOOGLE_PROTOBUF_MAP_FIELD_H__ diff --git a/libs/protobuf/src/google/protobuf/map_field_inl.h b/libs/protobuf/src/google/protobuf/map_field_inl.h index 9311abd..7c4c232 100644 --- a/libs/protobuf/src/google/protobuf/map_field_inl.h +++ b/libs/protobuf/src/google/protobuf/map_field_inl.h @@ -33,14 +33,10 @@ #include -#include "absl/base/casts.h" -#include "google/protobuf/map.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_type_handler.h" -#include "google/protobuf/port.h" - -// must be last -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -282,7 +278,7 @@ template ::Swap( MapFieldBase* other) { MapFieldBase::Swap(other); - MapField* other_field = DownCast(other); + MapField* other_field = down_cast(other); impl_.Swap(&other_field->impl_); } @@ -291,7 +287,7 @@ template void MapField::UnsafeShallowSwap(MapFieldBase* other) { - InternalSwap(DownCast(other)); + InternalSwap(down_cast(other)); } template ::const_iterator it = map.begin(); it != map.end(); ++it) { EntryType* new_entry = - DownCast(default_entry->New(this->MapFieldBase::arena_)); + down_cast(default_entry->New(this->MapFieldBase::arena_)); repeated_field->AddAllocated(new_entry); (*new_entry->mutable_key()) = it->first; (*new_entry->mutable_value()) = it->second; @@ -376,6 +372,4 @@ size_t MapField -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/port.h" -#include "google/protobuf/map.h" -#include "google/protobuf/map_entry_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -83,7 +83,7 @@ class MapFieldLite { // data in it, as would happen if a vector was resize'd to zero. // Map::Swap with an empty map accomplishes that. decltype(map_) swapped_map(map_.arena()); - map_.InternalSwap(&swapped_map); + map_.InternalSwap(swapped_map); } ~MapFieldLite() { if (map_.arena() == nullptr && !map_.empty()) { @@ -105,7 +105,7 @@ class MapFieldLite { } } void Swap(MapFieldLite* other) { map_.swap(other->map_); } - void InternalSwap(MapFieldLite* other) { map_.InternalSwap(&other->map_); } + void InternalSwap(MapFieldLite* other) { map_.InternalSwap(other->map_); } // Used in the implementation of parsing. Caller should take the ownership iff // arena_ is nullptr. @@ -204,6 +204,6 @@ inline PROTOBUF_NOINLINE void MapFieldLiteNotDestructed(void* map_field_lite) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/map_field_test.cc b/libs/protobuf/src/google/protobuf/map_field_test.cc index f060183..1659c95 100644 --- a/libs/protobuf/src/google/protobuf/map_field_test.cc +++ b/libs/protobuf/src/google/protobuf/map_field_test.cc @@ -32,22 +32,21 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/map.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/str_format.h" -#include "google/protobuf/arena_test_util.h" -#include "google/protobuf/map_test_util.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -72,6 +71,14 @@ class MapFieldBaseStub : public MapFieldBase { MapFieldBaseStub() {} virtual ~MapFieldBaseStub() { MapFieldBase::Destruct(); } explicit MapFieldBaseStub(Arena* arena) : MapFieldBase(arena) {} + // Get underlined repeated field without synchronizing map. + RepeatedPtrField* InternalRepeatedField() { return repeated_field_; } + bool IsMapClean() { + return state_.load(std::memory_order_relaxed) != STATE_MODIFIED_MAP; + } + bool IsRepeatedClean() { + return state_.load(std::memory_order_relaxed) != STATE_MODIFIED_REPEATED; + } void SetMapDirty() { state_.store(STATE_MODIFIED_MAP, std::memory_order_relaxed); } @@ -285,34 +292,26 @@ class MapFieldStateTest void Expect(MapFieldType* map_field, State state, int map_size, int repeated_size, bool is_repeated_null) { + MapFieldBase* map_field_base = map_field; + MapFieldBaseStub* stub = + reinterpret_cast(map_field_base); + // We use MutableMap on impl_ because we don't want to disturb the syncing Map* map = map_field->impl_.MutableMap(); - RepeatedPtrField* repeated_field = map_field->repeated_field_; + RepeatedPtrField* repeated_field = stub->InternalRepeatedField(); switch (state) { case MAP_DIRTY: - EXPECT_FALSE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_MAP); - EXPECT_TRUE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_REPEATED); + EXPECT_FALSE(stub->IsMapClean()); + EXPECT_TRUE(stub->IsRepeatedClean()); break; case REPEATED_DIRTY: - EXPECT_TRUE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_MAP); - EXPECT_FALSE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_REPEATED); + EXPECT_TRUE(stub->IsMapClean()); + EXPECT_FALSE(stub->IsRepeatedClean()); break; case CLEAN: - EXPECT_TRUE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_MAP); - EXPECT_TRUE( - map_field->state_.load(std::memory_order_relaxed) != - MapFieldType::STATE_MODIFIED_REPEATED); + EXPECT_TRUE(stub->IsMapClean()); + EXPECT_TRUE(stub->IsRepeatedClean()); break; default: FAIL(); diff --git a/libs/protobuf/src/google/protobuf/map_lite_test_util.cc b/libs/protobuf/src/google/protobuf/map_lite_test_util.cc index d519ba4..121f267 100644 --- a/libs/protobuf/src/google/protobuf/map_lite_test_util.cc +++ b/libs/protobuf/src/google/protobuf/map_lite_test_util.cc @@ -28,10 +28,10 @@ // (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/map_lite_test_util.h" +#include -#include "google/protobuf/map_lite_unittest.pb.h" -#include "google/protobuf/map_test_util_impl.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/map_lite_test_util.h b/libs/protobuf/src/google/protobuf/map_lite_test_util.h index a4a1e61..573de7b 100644 --- a/libs/protobuf/src/google/protobuf/map_lite_test_util.h +++ b/libs/protobuf/src/google/protobuf/map_lite_test_util.h @@ -31,7 +31,7 @@ #ifndef GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_MAP_LITE_TEST_UTIL_H__ -#include "google/protobuf/map_lite_unittest.pb.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/map_test.cc b/libs/protobuf/src/google/protobuf/map_test.cc index 4eee747..f7c024c 100644 --- a/libs/protobuf/src/google/protobuf/map_test.cc +++ b/libs/protobuf/src/google/protobuf/map_test.cc @@ -28,10 +28,10 @@ // (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/map_proto2_unittest.pb.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/reflection_tester.h" -#include "google/protobuf/test_util2.h" +#include +#include +#include +#include #define BRIDGE_UNITTEST ::google::protobuf::bridge_unittest @@ -41,13 +41,13 @@ // Must include after defining UNITTEST, etc. // clang-format off -#include "google/protobuf/test_util.inc" -#include "google/protobuf/map_test_util.inc" -#include "google/protobuf/map_test.inc" +#include +#include +#include // clang-format on // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -84,5 +84,3 @@ TEST(MapTest, Aligned8OnArena) { MapTest_Aligned(); } } // namespace internal } // namespace protobuf } // namespace google - -#include "google/protobuf/port_undef.inc" diff --git a/libs/protobuf/src/google/protobuf/map_test.inc b/libs/protobuf/src/google/protobuf/map_test.inc index 9b839ae..18a7bfb 100644 --- a/libs/protobuf/src/google/protobuf/map_test.inc +++ b/libs/protobuf/src/google/protobuf/map_test.inc @@ -46,36 +46,36 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "absl/base/casts.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/arena_test_util.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor_database.h" -#include "google/protobuf/dynamic_message.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/map.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/message.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/test_util2.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/util/message_differencer.h" -#include "google/protobuf/util/time_util.h" -#include "google/protobuf/wire_format.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -92,7 +92,6 @@ void MapTestForceDeterministic() { } namespace { -using internal::DownCast; // Map API Test ===================================================== @@ -738,47 +737,6 @@ TEST_F(MapImplTest, InsertSingleRValue) { EXPECT_FALSE(result2.second); } -TEST_F(MapImplTest, InsertSingleBraceInitList) { - int32_t key = 0; - int32_t value1 = 100; - int32_t value2 = 101; - - // Insert a non-existing key. - auto result1 = map_.insert({key, value1}); - ExpectSingleElement(key, value1); - - auto it1 = result1.first; - EXPECT_EQ(key, it1->first); - EXPECT_EQ(value1, it1->second); - EXPECT_TRUE(result1.second); - - // Insert an existing key. - auto result2 = map_.insert({key, value2}); - ExpectSingleElement(key, value1); - - auto it2 = result2.first; - EXPECT_TRUE(it1 == it2); - EXPECT_FALSE(result2.second); -} - -TEST_F(MapImplTest, InsertSingleBraceInitListTypeMismatch) { - int32_t key = 0; - int32_t value1 = 100; - int32_t value2 = 101; - Map m; - - // Insert a non-existing key. - auto result1 = m.insert({key, value1}); - EXPECT_TRUE(result1.second); - - // Insert an existing key. - auto result2 = m.insert({key, value2}); - EXPECT_FALSE(result2.second); - - EXPECT_TRUE(result1.first == result2.first); -} - - TEST_F(MapImplTest, TryEmplace) { using ::testing::Pair; using ::testing::UnorderedElementsAre; @@ -811,59 +769,6 @@ TEST_F(MapImplTest, Emplace) { m, UnorderedElementsAre(Pair(1, "one"), Pair(2, "two"), Pair(42, "aaa"))); } -#ifndef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE - -TEST_F(MapImplTest, EmplaceKeyOnly) { - using ::testing::Pair; - using ::testing::UnorderedElementsAre; - - Map m; - - m.emplace(1); - EXPECT_EQ(m.size(), 1); - - const int32_t key = 42; - m.emplace(key); - EXPECT_THAT(m, UnorderedElementsAre(Pair(1, ""), Pair(42, ""))); -} - -#else - -TEST_F(MapImplTest, ValueTypeNoImplicitConversion) { - using vt = typename Map::value_type; - - EXPECT_FALSE((std::is_convertible< - vt, std::pair>>::value)); -} - -enum class ConstructorType { - kDefault, - kCopy, - kMove, -}; - -struct ConstructorTag { - ConstructorTag() : invoked_constructor(ConstructorType::kDefault) {} - ConstructorTag(const ConstructorTag&) - : invoked_constructor(ConstructorType::kCopy) {} - ConstructorTag(ConstructorTag&&) - : invoked_constructor(ConstructorType::kMove) {} - - ConstructorType invoked_constructor; -}; - -TEST_F(MapImplTest, ValueTypeHasMoveConstructor) { - using vt = typename Map::value_type; - ConstructorTag l, r; - - vt pair(l, std::move(r)); - - EXPECT_EQ(pair.first.invoked_constructor, ConstructorType::kCopy); - EXPECT_EQ(pair.second.invoked_constructor, ConstructorType::kMove); -} - -#endif // !PROTOBUF_FUTURE_MAP_PAIR_UPGRADE - struct CountedInstance { CountedInstance() { ++num_created; } CountedInstance(const CountedInstance&) : CountedInstance() {} @@ -1488,7 +1393,7 @@ TEST_F(MapImplTest, ConstInit) { static int Func(int i, int j) { return i * j; } -static std::string StrFunc(int i, int j) { return absl::StrCat(Func(i, j)); } +static std::string StrFunc(int i, int j) { return StrCat(Func(i, j)); } static int Int(const std::string& value) { int result = 0; @@ -1611,7 +1516,7 @@ TEST_F(MapFieldReflectionTest, RegularFields) { message_int32_message.GetReflection()->GetInt32( message_int32_message, fd_map_int32_foreign_message_key); const ForeignMessage& value_int32_message = - DownCast( + down_cast( message_int32_message.GetReflection()->GetMessage( message_int32_message, fd_map_int32_foreign_message_value)); EXPECT_EQ(value_int32_message.c(), Func(key_int32_message, 6)); @@ -1648,7 +1553,7 @@ TEST_F(MapFieldReflectionTest, RegularFields) { message_int32_message.GetReflection()->GetInt32( message_int32_message, fd_map_int32_foreign_message_key); const ForeignMessage& value_int32_message = - DownCast( + down_cast( message_int32_message.GetReflection()->GetMessage( message_int32_message, fd_map_int32_foreign_message_value)); EXPECT_EQ(value_int32_message.c(), Func(key_int32_message, 6)); @@ -1685,7 +1590,7 @@ TEST_F(MapFieldReflectionTest, RegularFields) { int32_t key_int32_message = message_int32_message->GetReflection()->GetInt32( *message_int32_message, fd_map_int32_foreign_message_key); - ForeignMessage* value_int32_message = DownCast( + ForeignMessage* value_int32_message = down_cast( message_int32_message->GetReflection()->MutableMessage( message_int32_message, fd_map_int32_foreign_message_value)); value_int32_message->set_c(Func(key_int32_message, -6)); @@ -1841,7 +1746,7 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefForRegularFields) { message_int32_message.GetReflection()->GetInt32( message_int32_message, fd_map_int32_foreign_message_key); const ForeignMessage& value_int32_message = - DownCast( + down_cast( message_int32_message.GetReflection()->GetMessage( message_int32_message, fd_map_int32_foreign_message_value)); EXPECT_EQ(value_int32_message.c(), Func(key_int32_message, 6)); @@ -1882,7 +1787,7 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefForRegularFields) { message_int32_message.GetReflection()->GetInt32( message_int32_message, fd_map_int32_foreign_message_key); const ForeignMessage& value_int32_message = - DownCast( + down_cast( message_int32_message.GetReflection()->GetMessage( message_int32_message, fd_map_int32_foreign_message_value)); EXPECT_EQ(value_int32_message.c(), Func(key_int32_message, 6)); @@ -2012,7 +1917,7 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefForRegularFields) { int32_t key = message.GetReflection()->GetInt32( message, fd_map_int32_foreign_message_key); const ForeignMessage& sub_message = - DownCast(message.GetReflection()->GetMessage( + down_cast(message.GetReflection()->GetMessage( message, fd_map_int32_foreign_message_value)); result[key].MergeFrom(sub_message); ++index; @@ -2167,13 +2072,13 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefForRegularFields) { const Message& message0a = mmf_int32_foreign_message.Get(0, entry_int32_foreign_message.get()); const ForeignMessage& sub_message0a = - DownCast(message0a.GetReflection()->GetMessage( + down_cast(message0a.GetReflection()->GetMessage( message0a, fd_map_int32_foreign_message_value)); int32_t int32_value0a = sub_message0a.c(); const Message& message9a = mmf_int32_foreign_message.Get(9, entry_int32_foreign_message.get()); const ForeignMessage& sub_message9a = - DownCast(message9a.GetReflection()->GetMessage( + down_cast(message9a.GetReflection()->GetMessage( message9a, fd_map_int32_foreign_message_value)); int32_t int32_value9a = sub_message9a.c(); @@ -2182,13 +2087,13 @@ TEST_F(MapFieldReflectionTest, RepeatedFieldRefForRegularFields) { const Message& message0b = mmf_int32_foreign_message.Get(0, entry_int32_foreign_message.get()); const ForeignMessage& sub_message0b = - DownCast(message0b.GetReflection()->GetMessage( + down_cast(message0b.GetReflection()->GetMessage( message0b, fd_map_int32_foreign_message_value)); int32_t int32_value0b = sub_message0b.c(); const Message& message9b = mmf_int32_foreign_message.Get(9, entry_int32_foreign_message.get()); const ForeignMessage& sub_message9b = - DownCast(message9b.GetReflection()->GetMessage( + down_cast(message9b.GetReflection()->GetMessage( message9b, fd_map_int32_foreign_message_value)); int32_t int32_value9b = sub_message9b.c(); @@ -2526,7 +2431,7 @@ TEST(GeneratedMapFieldTest, UpcastCopyFrom) { MapTestUtil::SetMapFields(&message1); - const Message* source = absl::implicit_cast(&message1); + const Message* source = implicit_cast(&message1); message2.CopyFrom(*source); MapTestUtil::ExpectMapFieldsSet(message2); @@ -2692,7 +2597,7 @@ TEST(GeneratedMapFieldTest, SerializationToArray) { MapTestUtil::SetMapFields(&message1); size_t size = message1.ByteSizeLong(); data.resize(size); - uint8_t* start = reinterpret_cast(&data[0]); + uint8_t* start = reinterpret_cast(::google::protobuf::string_as_array(&data)); uint8_t* end = message1.SerializeWithCachedSizesToArray(start); EXPECT_EQ(size, end - start); EXPECT_TRUE(message2.ParseFromString(data)); @@ -2708,7 +2613,7 @@ TEST(GeneratedMapFieldTest, SerializationToStream) { data.resize(size); { // Allow the output stream to buffer only one byte at a time. - io::ArrayOutputStream array_stream(&data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&data), size, 1); io::CodedOutputStream output_stream(&array_stream); message1.SerializeWithCachedSizes(&output_stream); EXPECT_FALSE(output_stream.HadError()); @@ -3033,7 +2938,7 @@ TEST(GeneratedMapFieldTest, MessagesMustMerge) { *p++ = 0; *p++ = WireFormatLite::MakeTag(2, WireFormatLite::WIRETYPE_LENGTH_DELIMITED); *p++ = payload_size; - absl::StrAppend(&s, dummy4_s, dummy5_s); + StrAppend(&s, dummy4_s, dummy5_s); // Test key then value then value. int key = 0; @@ -3739,7 +3644,7 @@ static std::string DeterministicSerializationWithSerializePartialToCodedStream( const T& t) { const size_t size = t.ByteSizeLong(); std::string result(size, '\0'); - io::ArrayOutputStream array_stream(&result[0], size); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size); io::CodedOutputStream output_stream(&array_stream); output_stream.SetSerializationDeterministic(true); t.SerializePartialToCodedStream(&output_stream); @@ -3753,7 +3658,7 @@ static std::string DeterministicSerializationWithSerializeToCodedStream( const T& t) { const size_t size = t.ByteSizeLong(); std::string result(size, '\0'); - io::ArrayOutputStream array_stream(&result[0], size); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size); io::CodedOutputStream output_stream(&array_stream); output_stream.SetSerializationDeterministic(true); t.SerializeToCodedStream(&output_stream); @@ -3766,7 +3671,7 @@ template static std::string DeterministicSerialization(const T& t) { const size_t size = t.ByteSizeLong(); std::string result(size, '\0'); - io::ArrayOutputStream array_stream(&result[0], size); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&result), size); { io::CodedOutputStream output_stream(&array_stream); output_stream.SetSerializationDeterministic(true); @@ -3784,7 +3689,7 @@ static std::string DeterministicSerialization(const T& t) { static std::string ConstructKey(uint64_t n) { std::string s(n % static_cast(9), '\0'); if (s.empty()) { - return absl::StrCat(n); + return StrCat(n); } else { while (n != 0) { s[n % s.size()] = (n >> 10) & 0x7f; @@ -3844,7 +3749,7 @@ TEST(MapSerializationTest, DeterministicSubmessage) { const std::string filename = "golden_message_maps"; std::string golden; GOOGLE_CHECK_OK(File::GetContents( - TestUtil::GetTestDataPath("third_party/protobuf/testdata/" + filename), + TestUtil::GetTestDataPath("net/proto2/internal/testdata/" + filename), &golden, true)); t.ParseFromString(golden); *(p.mutable_m()) = t; @@ -3886,10 +3791,11 @@ TEST(TextFormatMapTest, DynamicMessage) { std::string expected_text; GOOGLE_CHECK_OK( - File::GetContents(TestUtil::GetTestDataPath("third_party/protobuf/" + File::GetContents(TestUtil::GetTestDataPath("net/proto2/internal/" "testdata/map_test_data.txt"), &expected_text, true)); + CleanStringLineEndings(&expected_text, false); std::string actual_text; TextFormat::PrintToString(*message, &actual_text); EXPECT_EQ(actual_text, expected_text); @@ -3902,10 +3808,11 @@ TEST(TextFormatMapTest, Sorted) { std::string expected_text; GOOGLE_CHECK_OK( - File::GetContents(TestUtil::GetTestDataPath("third_party/protobuf/" + File::GetContents(TestUtil::GetTestDataPath("net/proto2/internal/" "testdata/map_test_data.txt"), &expected_text, true)); + CleanStringLineEndings(&expected_text, false); TextFormat::Printer printer; std::string actual_text; printer.PrintToString(message, &actual_text); @@ -3921,10 +3828,10 @@ TEST(TextFormatMapTest, Sorted) { TEST(TextFormatMapTest, ParseCorruptedString) { std::string serialized_message; - GOOGLE_CHECK_OK(File::GetContents( - TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_message_maps"), - &serialized_message, true)); + GOOGLE_CHECK_OK( + File::GetContents(TestUtil::GetTestDataPath( + "net/proto2/internal/testdata/golden_message_maps"), + &serialized_message, true)); UNITTEST::TestMaps message; GOOGLE_CHECK(message.ParseFromString(serialized_message)); TestParseCorruptedString(message); @@ -4161,4 +4068,4 @@ TEST(MoveTest, MoveAssignmentWorks) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/map_test_util.h b/libs/protobuf/src/google/protobuf/map_test_util.h index 130e494..f3215db 100644 --- a/libs/protobuf/src/google/protobuf/map_test_util.h +++ b/libs/protobuf/src/google/protobuf/map_test_util.h @@ -31,14 +31,14 @@ #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_H__ -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/reflection_tester.h" +#include +#include #define UNITTEST ::protobuf_unittest #define BRIDGE_UNITTEST ::google::protobuf::bridge_unittest // Must be included after defining UNITTEST, etc. -#include "google/protobuf/map_test_util.inc" +#include #undef UNITTEST #undef BRIDGE_UNITTEST diff --git a/libs/protobuf/src/google/protobuf/map_test_util.inc b/libs/protobuf/src/google/protobuf/map_test_util.inc index 14b781a..5b12c76 100644 --- a/libs/protobuf/src/google/protobuf/map_test_util.inc +++ b/libs/protobuf/src/google/protobuf/map_test_util.inc @@ -28,9 +28,9 @@ // (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/descriptor.h" -#include "google/protobuf/map_test_util_impl.h" -#include "google/protobuf/message.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/map_test_util_impl.h b/libs/protobuf/src/google/protobuf/map_test_util_impl.h index adbc3fc..655aec8 100644 --- a/libs/protobuf/src/google/protobuf/map_test_util_impl.h +++ b/libs/protobuf/src/google/protobuf/map_test_util_impl.h @@ -31,8 +31,8 @@ #ifndef GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__ #define GOOGLE_PROTOBUF_MAP_TEST_UTIL_IMPL_H__ -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include #include diff --git a/libs/protobuf/src/google/protobuf/map_type_handler.h b/libs/protobuf/src/google/protobuf/map_type_handler.h index c092792..c210c63 100644 --- a/libs/protobuf/src/google/protobuf/map_type_handler.h +++ b/libs/protobuf/src/google/protobuf/map_type_handler.h @@ -31,11 +31,11 @@ #ifndef GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ #define GOOGLE_PROTOBUF_MAP_TYPE_HANDLER_H__ -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" diff --git a/libs/protobuf/src/google/protobuf/map_unittest.proto b/libs/protobuf/src/google/protobuf/map_unittest.proto index 7c88c55..263ef61 100644 --- a/libs/protobuf/src/google/protobuf/map_unittest.proto +++ b/libs/protobuf/src/google/protobuf/map_unittest.proto @@ -76,6 +76,7 @@ message TestSameTypeMap { map map2 = 2; } + enum MapEnum { MAP_ENUM_FOO = 0; MAP_ENUM_BAR = 1; diff --git a/libs/protobuf/src/google/protobuf/message.cc b/libs/protobuf/src/google/protobuf/message.cc index e43d93a..6cdc6c8 100644 --- a/libs/protobuf/src/google/protobuf/message.cc +++ b/libs/protobuf/src/google/protobuf/message.cc @@ -32,42 +32,40 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/message.h" +#include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "absl/base/casts.h" -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/reflection_internal.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { + namespace internal { // TODO(gerbens) make this factorized better. This should not have to hop @@ -77,7 +75,6 @@ void RegisterFileLevelMetadata(const DescriptorTable* descriptor_table); } // namespace internal -using internal::DownCast; using internal::ReflectionOps; using internal::WireFormat; using internal::WireFormatLite; @@ -95,7 +92,7 @@ void Message::MergeFrom(const Message& from) { } void Message::CheckTypeAndMergeFrom(const MessageLite& other) { - MergeFrom(*DownCast(&other)); + MergeFrom(*down_cast(&other)); } void Message::CopyFrom(const Message& from) { @@ -155,7 +152,7 @@ void Message::FindInitializationErrors(std::vector* errors) const { std::string Message::InitializationErrorString() const { std::vector errors; FindInitializationErrors(&errors); - return absl::StrJoin(errors, ", "); + return Join(errors, ", "); } void Message::CheckInitialized() const { @@ -170,15 +167,7 @@ void Message::DiscardUnknownFields() { const char* Message::_InternalParse(const char* ptr, internal::ParseContext* ctx) { -#if defined(PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION) - auto meta = GetMetadata(); - ptr = internal::TcParser::ParseLoop(this, ptr, ctx, - meta.reflection->GetTcParseTable()); - - return ptr; -#else return WireFormat::_InternalParse(this, ptr, ctx); -#endif } uint8_t* Message::_InternalSerialize(uint8_t* target, @@ -224,18 +213,6 @@ uint64_t Message::GetInvariantPerBuild(uint64_t salt) { return salt; } -namespace internal { -void* CreateSplitMessageGeneric(Arena* arena, const void* default_split, - size_t size, const void* message, - const void* default_message) { - GOOGLE_DCHECK_NE(message, default_message); - void* split = - (arena == nullptr) ? ::operator new(size) : arena->AllocateAligned(size); - memcpy(split, default_split, size); - return split; -} -} // namespace internal - // ============================================================================= // MessageFactory @@ -243,6 +220,11 @@ MessageFactory::~MessageFactory() {} namespace { + +#define HASH_MAP std::unordered_map +#define STR_HASH_FXN hash<::google::protobuf::StringPiece> + + class GeneratedMessageFactory final : public MessageFactory { public: static GeneratedMessageFactory* singleton(); @@ -254,58 +236,14 @@ class GeneratedMessageFactory final : public MessageFactory { const Message* GetPrototype(const Descriptor* type) override; private: - const Message* FindInTypeMap(const Descriptor* type) - ABSL_SHARED_LOCKS_REQUIRED(mutex_) - { - auto it = type_map_.find(type); - if (it == type_map_.end()) return nullptr; - return it->second; - } - - const google::protobuf::internal::DescriptorTable* FindInFileMap( - absl::string_view name) { - auto it = files_.find(name); - if (it == files_.end()) return nullptr; - return *it; - } - - struct DescriptorByNameHash { - using is_transparent = void; - size_t operator()(const google::protobuf::internal::DescriptorTable* t) const { - return absl::HashOf(absl::string_view{t->filename}); - } - - size_t operator()(absl::string_view name) const { - return absl::HashOf(name); - } - }; - struct DescriptorByNameEq { - using is_transparent = void; - bool operator()(const google::protobuf::internal::DescriptorTable* lhs, - const google::protobuf::internal::DescriptorTable* rhs) const { - return lhs == rhs || (*this)(lhs->filename, rhs->filename); - } - bool operator()(absl::string_view lhs, - const google::protobuf::internal::DescriptorTable* rhs) const { - return (*this)(lhs, rhs->filename); - } - bool operator()(const google::protobuf::internal::DescriptorTable* lhs, - absl::string_view rhs) const { - return (*this)(lhs->filename, rhs); - } - bool operator()(absl::string_view lhs, absl::string_view rhs) const { - return lhs == rhs; - } - }; - // Only written at static init time, so does not require locking. - absl::flat_hash_set - files_; + HASH_MAP + file_map_; - absl::Mutex mutex_; - absl::flat_hash_map type_map_ - ABSL_GUARDED_BY(mutex_); + internal::WrappedMutex mutex_; + // Initialized lazily, so requires locking. + std::unordered_map type_map_; }; GeneratedMessageFactory* GeneratedMessageFactory::singleton() { @@ -316,7 +254,7 @@ GeneratedMessageFactory* GeneratedMessageFactory::singleton() { void GeneratedMessageFactory::RegisterFile( const google::protobuf::internal::DescriptorTable* table) { - if (!files_.insert(table).second) { + if (!InsertIfNotPresent(&file_map_, table->filename, table)) { GOOGLE_LOG(FATAL) << "File is already registered: " << table->filename; } } @@ -331,7 +269,7 @@ void GeneratedMessageFactory::RegisterType(const Descriptor* descriptor, // function during GetPrototype(), in which case we already have locked // the mutex. mutex_.AssertHeld(); - if (!type_map_.try_emplace(descriptor, prototype).second) { + if (!InsertIfNotPresent(&type_map_, descriptor, prototype)) { GOOGLE_LOG(DFATAL) << "Type is already registered: " << descriptor->full_name(); } } @@ -339,8 +277,8 @@ void GeneratedMessageFactory::RegisterType(const Descriptor* descriptor, const Message* GeneratedMessageFactory::GetPrototype(const Descriptor* type) { { - absl::ReaderMutexLock lock(&mutex_); - const Message* result = FindInTypeMap(type); + ReaderMutexLock lock(&mutex_); + const Message* result = FindPtrOrNull(type_map_, type); if (result != nullptr) return result; } @@ -350,7 +288,7 @@ const Message* GeneratedMessageFactory::GetPrototype(const Descriptor* type) { // Apparently the file hasn't been registered yet. Let's do that now. const internal::DescriptorTable* registration_data = - FindInFileMap(type->file()->name()); + FindPtrOrNull(file_map_, type->file()->name().c_str()); if (registration_data == nullptr) { GOOGLE_LOG(DFATAL) << "File appears to be in generated pool but wasn't " "registered: " @@ -358,15 +296,15 @@ const Message* GeneratedMessageFactory::GetPrototype(const Descriptor* type) { return nullptr; } - absl::WriterMutexLock lock(&mutex_); + WriterMutexLock lock(&mutex_); // Check if another thread preempted us. - const Message* result = FindInTypeMap(type); + const Message* result = FindPtrOrNull(type_map_, type); if (result == nullptr) { // Nope. OK, register everything. internal::RegisterFileLevelMetadata(registration_data); // Should be here now. - result = FindInTypeMap(type); + result = FindPtrOrNull(type_map_, type); } if (result == nullptr) { @@ -458,18 +396,9 @@ PROTOBUF_NOINLINE GenericTypeHandler::GetOwningArena(Message* value) { return value->GetOwningArena(); } - -template void InternalMetadata::DoClear(); -template void InternalMetadata::DoMergeFrom( - const UnknownFieldSet& other); -template void InternalMetadata::DoSwap(UnknownFieldSet* other); -template Arena* InternalMetadata::DeleteOutOfLineHelper(); -template UnknownFieldSet* -InternalMetadata::mutable_unknown_fields_slow(); - } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/message.h b/libs/protobuf/src/google/protobuf/message.h index b831fa6..39ec154 100644 --- a/libs/protobuf/src/google/protobuf/message.h +++ b/libs/protobuf/src/google/protobuf/message.h @@ -116,23 +116,19 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "absl/base/call_once.h" -#include "absl/base/casts.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/generated_message_tctable_decl.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/map.h" // TODO(b/211442718): cleanup -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include +#include +#include +#include // TODO(b/211442718): cleanup +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -161,7 +157,6 @@ struct DescriptorTable; class MapFieldBase; class SwapFieldHelper; class CachedSize; -struct TailCallTableInfo; } // namespace internal class UnknownFieldSet; // unknown_field_set.h namespace io { @@ -208,12 +203,12 @@ struct Metadata { namespace internal { template -inline To* GetPointerAtOffset(void* message, uint32_t offset) { +inline To* GetPointerAtOffset(Message* message, uint32_t offset) { return reinterpret_cast(reinterpret_cast(message) + offset); } template -const To* GetConstPointerAtOffset(const void* message, uint32_t offset) { +const To* GetConstPointerAtOffset(const Message* message, uint32_t offset) { return reinterpret_cast(reinterpret_cast(message) + offset); } @@ -245,8 +240,6 @@ PROTOBUF_EXPORT bool IsDescendant(Message& root, const Message& message); class PROTOBUF_EXPORT Message : public MessageLite { public: constexpr Message() {} - Message(const Message&) = delete; - Message& operator=(const Message&) = delete; // Basic Operations ------------------------------------------------ @@ -305,10 +298,6 @@ class PROTOBUF_EXPORT Message : public MessageLite { // using reflection (rather than the generated code implementation for // ByteSize()). Like ByteSize(), its CPU time is linear in the number of // fields defined for the proto. - // - // Note: The precise value of this method should never be depended on, and can - // change substantially due to internal details. In debug builds, this will - // include a random fuzz factor to prevent these dependencies. virtual size_t SpaceUsedLong() const; PROTOBUF_DEPRECATED_MSG("Please use SpaceUsedLong() instead") @@ -411,14 +400,12 @@ class PROTOBUF_EXPORT Message : public MessageLite { protected: static uint64_t GetInvariantPerBuild(uint64_t salt); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message); }; namespace internal { -// Creates and returns an allocation for a split message. -void* CreateSplitMessageGeneric(Arena* arena, const void* default_split, - size_t size, const void* message, - const void* default_message); - // Forward-declare interfaces used to implement RepeatedFieldRef. // These are protobuf internals that users shouldn't care about. class RepeatedFieldAccessor; @@ -472,10 +459,6 @@ class MutableRepeatedFieldRef; // memory leaks. So, instead we ended up with this flat interface. class PROTOBUF_EXPORT Reflection final { public: - Reflection(const Reflection&) = delete; - Reflection& operator=(const Reflection&) = delete; - ~Reflection(); - // Get the UnknownFieldSet for the message. This contains fields which // were seen when the Message was parsed but were not recognized according // to the Message's definition. @@ -493,11 +476,6 @@ class PROTOBUF_EXPORT Reflection final { return internal::ToIntSize(SpaceUsedLong(message)); } - // Returns true if the given message is a default message instance. - bool IsDefaultInstance(const Message& message) const { - return schema_.IsDefaultInstance(message); - } - // Check if the given non-repeated field is set. bool HasField(const Message& message, const FieldDescriptor* field) const; @@ -914,7 +892,8 @@ class PROTOBUF_EXPORT Reflection final { // Try to find an extension of this message type by fully-qualified field // name. Returns nullptr if no extension is known for this name or number. - const FieldDescriptor* FindKnownExtensionByName(absl::string_view name) const; + const FieldDescriptor* FindKnownExtensionByName( + const std::string& name) const; // Try to find an extension of this message type by field number. // Returns nullptr if no extension is known for this name or number. @@ -1050,11 +1029,6 @@ class PROTOBUF_EXPORT Reflection final { bool IsLazilyVerifiedLazyField(const FieldDescriptor* field) const; bool IsEagerlyVerifiedLazyField(const FieldDescriptor* field) const; - bool IsSplit(const FieldDescriptor* field) const { - return schema_.IsSplit(field); - } - - friend class FastReflectionBase; friend class FastReflectionMessageMutator; friend bool internal::IsDescendant(Message& root, const Message& message); @@ -1068,34 +1042,10 @@ class PROTOBUF_EXPORT Reflection final { // contain weak fields, then this field equals descriptor_->field_count(). int last_non_weak_field_index_; - // The table-driven parser table. - // This table is generated on demand for Message types that did not override - // _InternalParse. It uses the reflection information to do so. - mutable absl::once_flag tcparse_table_once_; - using TcParseTableBase = internal::TcParseTableBase; - mutable const TcParseTableBase* tcparse_table_ = nullptr; - - const TcParseTableBase* GetTcParseTable() const { - absl::call_once(tcparse_table_once_, - [&] { tcparse_table_ = CreateTcParseTable(); }); - return tcparse_table_; - } - - const TcParseTableBase* CreateTcParseTable() const; - const TcParseTableBase* CreateTcParseTableForMessageSet() const; - void PopulateTcParseFastEntries( - const internal::TailCallTableInfo& table_info, - TcParseTableBase::FastFieldEntry* fast_entries) const; - void PopulateTcParseEntries(internal::TailCallTableInfo& table_info, - TcParseTableBase::FieldEntry* entries) const; - void PopulateTcParseFieldAux(const internal::TailCallTableInfo& table_info, - TcParseTableBase::FieldAux* field_aux) const; - template friend class RepeatedFieldRef; template friend class MutableRepeatedFieldRef; - friend class Message; friend class ::PROTOBUF_NAMESPACE_ID::MessageLayoutInspector; friend class ::PROTOBUF_NAMESPACE_ID::AssignDescriptorsHelper; friend class DynamicMessageFactory; @@ -1224,14 +1174,6 @@ class PROTOBUF_EXPORT Reflection final { inline void SwapInlinedStringDonated(Message* lhs, Message* rhs, const FieldDescriptor* field) const; - // Returns the `_split_` pointer. Requires: IsSplit() == true. - inline const void* GetSplitField(const Message* message) const; - // Returns the address of the `_split_` pointer. Requires: IsSplit() == true. - inline void** MutableSplitField(Message* message) const; - - // Allocate the split instance if needed. - void PrepareSplitMessageForWrite(Message* message) const; - // Shallow-swap fields listed in fields vector of two messages. It is the // caller's responsibility to make sure shallow swap is safe. void UnsafeShallowSwapFields( @@ -1255,8 +1197,6 @@ class PROTOBUF_EXPORT Reflection final { void SwapOneofField(Message* lhs, Message* rhs, const OneofDescriptor* oneof_descriptor) const; - void InternalSwap(Message* lhs, Message* rhs) const; - inline bool HasOneofField(const Message& message, const FieldDescriptor* field) const; inline void SetOneofCase(Message* message, @@ -1320,17 +1260,14 @@ class PROTOBUF_EXPORT Reflection final { const Reflection* reflection, const char* ptr, internal::ParseContext* ctx); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); }; // Abstract interface for a factory for message objects. -// -// The thread safety for this class is implementation dependent, see comments -// around GetPrototype for details class PROTOBUF_EXPORT MessageFactory { public: inline MessageFactory() {} - MessageFactory(const MessageFactory&) = delete; - MessageFactory& operator=(const MessageFactory&) = delete; virtual ~MessageFactory(); // Given a Descriptor, gets or constructs the default (prototype) Message @@ -1386,6 +1323,9 @@ class PROTOBUF_EXPORT MessageFactory { static void InternalRegisterGeneratedMessage(const Descriptor* descriptor, const Message* prototype); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFactory); }; #define DECLARE_GET_REPEATED_FIELD(TYPE) \ @@ -1432,7 +1372,7 @@ const T* DynamicCastToGenerated(const Message* from) { #else bool ok = from != nullptr && T::default_instance().GetReflection() == from->GetReflection(); - return ok ? internal::DownCast(from) : nullptr; + return ok ? down_cast(from) : nullptr; #endif } @@ -1541,32 +1481,17 @@ bool Reflection::HasOneofField(const Message& message, static_cast(field->number())); } -const void* Reflection::GetSplitField(const Message* message) const { - GOOGLE_DCHECK(schema_.IsSplit()); - return *internal::GetConstPointerAtOffset(message, - schema_.SplitOffset()); -} - -void** Reflection::MutableSplitField(Message* message) const { - GOOGLE_DCHECK(schema_.IsSplit()); - return internal::GetPointerAtOffset(message, schema_.SplitOffset()); -} - template const Type& Reflection::GetRaw(const Message& message, const FieldDescriptor* field) const { GOOGLE_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) << "Field = " << field->full_name(); - if (schema_.IsSplit(field)) { - return *internal::GetConstPointerAtOffset( - GetSplitField(&message), schema_.GetFieldOffset(field)); - } return internal::GetConstRefAtOffset(message, schema_.GetFieldOffset(field)); } } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MESSAGE_H__ diff --git a/libs/protobuf/src/google/protobuf/message_lite.cc b/libs/protobuf/src/google/protobuf/message_lite.cc index eea99e0..da66c19 100644 --- a/libs/protobuf/src/google/protobuf/message_lite.cc +++ b/libs/protobuf/src/google/protobuf/message_lite.cc @@ -33,48 +33,39 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/message_lite.h" +#include #include #include #include -#include - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/arena.h" -#include "absl/base/dynamic_annotations.h" -#include "absl/strings/cord.h" -#include "absl/strings/internal/resize_uninitialized.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { -MessageLite::~MessageLite(){ -// Defined out of line to save code space -} - std::string MessageLite::InitializationErrorString() const { return "(cannot determine missing fields for lite message)"; } std::string MessageLite::DebugString() const { std::uintptr_t address = reinterpret_cast(this); - return absl::StrCat("MessageLite at 0x", absl::Hex(address)); + return StrCat("MessageLite at 0x", strings::Hex(address)); } namespace { @@ -121,8 +112,8 @@ std::string InitializationErrorMessage(const char* action, return result; } -inline absl::string_view as_string_view(const void* data, int size) { - return absl::string_view(static_cast(data), size); +inline StringPiece as_string_view(const void* data, int size) { + return StringPiece(static_cast(data), size); } // Returns true of all required fields are present / have values. @@ -145,7 +136,7 @@ void MessageLite::LogInitializationErrorMessage() const { namespace internal { template -bool MergeFromImpl(absl::string_view input, MessageLite* msg, +bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags) { const char* ptr; internal::ParseContext ctx(io::CodedInputStream::GetDefaultRecursionLimit(), @@ -187,9 +178,9 @@ bool MergeFromImpl(BoundedZCIS input, MessageLite* msg, return false; } -template bool MergeFromImpl(absl::string_view input, MessageLite* msg, +template bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); -template bool MergeFromImpl(absl::string_view input, MessageLite* msg, +template bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); template bool MergeFromImpl(io::ZeroCopyInputStream* input, MessageLite* msg, @@ -314,11 +305,11 @@ bool MessageLite::ParsePartialFromBoundedZeroCopyStream( return ParseFrom(internal::BoundedZCIS{input, size}); } -bool MessageLite::ParseFromString(absl::string_view data) { +bool MessageLite::ParseFromString(ConstStringParam data) { return ParseFrom(data); } -bool MessageLite::ParsePartialFromString(absl::string_view data) { +bool MessageLite::ParsePartialFromString(ConstStringParam data) { return ParseFrom(data); } @@ -330,7 +321,7 @@ bool MessageLite::ParsePartialFromArray(const void* data, int size) { return ParseFrom(as_string_view(data, size)); } -bool MessageLite::MergeFromString(absl::string_view data) { +bool MessageLite::MergeFromString(ConstStringParam data) { return ParseFrom(data); } @@ -460,8 +451,7 @@ bool MessageLite::AppendPartialToString(std::string* output) const { return false; } - absl::strings_internal::STLStringResizeUninitializedAmortized( - output, old_size + byte_size); + STLStringResizeUninitializedAmortized(output, old_size + byte_size); uint8_t* start = reinterpret_cast(io::mutable_string_data(output) + old_size); SerializeToArrayImpl(*this, start, byte_size); @@ -576,7 +566,7 @@ struct ShutdownData { } std::vector> functions; - absl::Mutex mutex; + Mutex mutex; }; static void RunZeroArgFunc(const void* arg) { @@ -590,7 +580,7 @@ void OnShutdown(void (*func)()) { void OnShutdownRun(void (*f)(const void*), const void* arg) { auto shutdown_data = ShutdownData::get(); - absl::MutexLock lock(&shutdown_data->mutex); + MutexLock lock(&shutdown_data->mutex); shutdown_data->functions.push_back(std::make_pair(f, arg)); } @@ -609,4 +599,4 @@ void ShutdownProtobufLibrary() { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/message_lite.h b/libs/protobuf/src/google/protobuf/message_lite.h index 92e5b73..950ae1a 100644 --- a/libs/protobuf/src/google/protobuf/message_lite.h +++ b/libs/protobuf/src/google/protobuf/message_lite.h @@ -43,20 +43,19 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "absl/base/call_once.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/explicitly_constructed.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // TODO(b/211442718): cleanup // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on #ifdef SWIG @@ -169,9 +168,7 @@ PROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const std::string& str); class PROTOBUF_EXPORT MessageLite { public: constexpr MessageLite() {} - MessageLite(const MessageLite&) = delete; - MessageLite& operator=(const MessageLite&) = delete; - virtual ~MessageLite(); + virtual ~MessageLite() = default; // Basic Operations ------------------------------------------------ @@ -280,11 +277,11 @@ class PROTOBUF_EXPORT MessageLite { // format, matching the encoding output by MessageLite::SerializeToString(). // If you'd like to convert a human-readable string into a protocol buffer // object, see google::protobuf::TextFormat::ParseFromString(). - PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromString(absl::string_view data); + PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromString(ConstStringParam data); // Like ParseFromString(), but accepts messages that are missing // required fields. PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParsePartialFromString( - absl::string_view data); + ConstStringParam data); // Parse a protocol buffer contained in an array of bytes. PROTOBUF_ATTRIBUTE_REINITIALIZES bool ParseFromArray(const void* data, int size); @@ -315,7 +312,7 @@ class PROTOBUF_EXPORT MessageLite { bool MergePartialFromCodedStream(io::CodedInputStream* input); // Merge a protocol buffer contained in a string. - bool MergeFromString(absl::string_view data); + bool MergeFromString(ConstStringParam data); // Serialization --------------------------------------------------- @@ -495,17 +492,19 @@ class PROTOBUF_EXPORT MessageLite { void LogInitializationErrorMessage() const; bool MergeFromImpl(io::CodedInputStream* input, ParseFlags parse_flags); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); }; namespace internal { template -bool MergeFromImpl(absl::string_view input, MessageLite* msg, +bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); -extern template bool MergeFromImpl(absl::string_view input, +extern template bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); -extern template bool MergeFromImpl(absl::string_view input, +extern template bool MergeFromImpl(StringPiece input, MessageLite* msg, MessageLite::ParseFlags parse_flags); @@ -587,6 +586,6 @@ T* OnShutdownDelete(T* p) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/message_unittest.cc b/libs/protobuf/src/google/protobuf/message_unittest.cc index dbf84b6..f71f60c 100644 --- a/libs/protobuf/src/google/protobuf/message_unittest.cc +++ b/libs/protobuf/src/google/protobuf/message_unittest.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/unittest.pb.h" +#include #define MESSAGE_TEST_NAME MessageTest #define MESSAGE_FACTORY_TEST_NAME MessageFactoryTest @@ -42,7 +42,7 @@ // Must include after the above macros. // clang-format off -#include "google/protobuf/test_util.inc" -#include "google/protobuf/message_unittest.inc" -#include "google/protobuf/arena.h" +#include +#include +#include // clang-format on diff --git a/libs/protobuf/src/google/protobuf/message_unittest.inc b/libs/protobuf/src/google/protobuf/message_unittest.inc index 742f3bd..fa2bbbf 100644 --- a/libs/protobuf/src/google/protobuf/message_unittest.inc +++ b/libs/protobuf/src/google/protobuf/message_unittest.inc @@ -40,34 +40,31 @@ #include #include -#include #include -#include -#include "google/protobuf/message.h" -#include "absl/strings/cord.h" +#include #ifndef _MSC_VER #include #endif #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/test_util2.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace google { @@ -127,7 +124,7 @@ TEST(MESSAGE_TEST_NAME, SerializeToBrokenOstream) { TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) { std::string filename = - TestUtil::GetTestDataPath("third_party/protobuf/testdata/golden_message"); + TestUtil::GetTestDataPath("net/proto2/internal/testdata/golden_message"); int file = open(filename.c_str(), O_RDONLY | O_BINARY); ASSERT_GE(file, 0); @@ -140,7 +137,7 @@ TEST(MESSAGE_TEST_NAME, ParseFromFileDescriptor) { TEST(MESSAGE_TEST_NAME, ParsePackedFromFileDescriptor) { std::string filename = TestUtil::GetTestDataPath( - "third_party/protobuf/testdata/golden_packed_fields_message"); + "net/proto2/internal/testdata/golden_packed_fields_message"); int file = open(filename.c_str(), O_RDONLY | O_BINARY); ASSERT_GE(file, 0); @@ -258,7 +255,7 @@ TEST(MESSAGE_TEST_NAME, ParseFailsIfExtensionNotInitialized) { } EXPECT_THAT(errors, - testing::ElementsAre(absl::Substitute( + testing::ElementsAre(strings::Substitute( "Can't parse message of type \"$0.TestChildExtension\" " "because it is missing required fields: " "optional_extension.($0.TestRequired.single).a, " @@ -288,32 +285,6 @@ TEST(MESSAGE_TEST_NAME, MergeFromUninitialized) { EXPECT_TRUE(TestUtil::EqualsToSerialized(q, p.SerializePartialAsString())); } -TEST(MESSAGE_TEST_NAME, UninitializedAndTooDeep) { - UNITTEST::TestRequiredForeign original; - original.mutable_optional_message()->set_a(1); - original.mutable_optional_lazy_message() - ->mutable_child() - ->mutable_payload() - ->set_optional_int64(0); - - std::string data; - ASSERT_TRUE(original.SerializePartialToString(&data)); - - UNITTEST::TestRequiredForeign pass; - ASSERT_TRUE(pass.ParsePartialFromString(data)); - ASSERT_FALSE(pass.IsInitialized()); - - io::ArrayInputStream array_stream(data.data(), data.size()); - io::CodedInputStream input_stream(&array_stream); - input_stream.SetRecursionLimit(2); - - UNITTEST::TestRequiredForeign fail; - EXPECT_FALSE(fail.ParsePartialFromCodedStream(&input_stream)); - - UNITTEST::TestRequiredForeign fail_uninitialized; - EXPECT_FALSE(fail_uninitialized.ParseFromString(data)); -} - TEST(MESSAGE_TEST_NAME, ExplicitLazyExceedRecursionLimit) { UNITTEST::NestedTestAllTypes original, parsed; // Build proto with recursion depth of 3. @@ -451,25 +422,6 @@ TEST(MESSAGE_TEST_NAME, ParseFailsIfExtensionWireMalformed) { EXPECT_FALSE(p.ParseFromString(serialized)); } -TEST(MESSAGE_TEST_NAME, ParseFailsIfGroupFieldMalformed) { - UNITTEST::TestMutualRecursionA original, parsed; - original.mutable_bb() - ->mutable_a() - ->mutable_subgroup() - ->mutable_sub_message() - ->mutable_b() - ->set_optional_int32(-1); - - std::string data; - ASSERT_TRUE(original.SerializeToString(&data)); - // Should parse correctly. - ASSERT_TRUE(parsed.ParseFromString(data)); - // Overwriting the last byte of varint (-1) to 0xFF results in malformed wire. - data[data.size() - 2] = 0xFF; - - EXPECT_FALSE(parsed.ParseFromString(data)); -} - TEST(MESSAGE_TEST_NAME, UninitializedAndMalformed) { UNITTEST::TestRequiredForeign o, p1, p2; o.mutable_optional_message()->set_a(-1); @@ -1175,305 +1127,5 @@ TEST(MESSAGE_TEST_NAME, PreservesFloatingPointNegative0) { std::signbit(out_message.optional_double())); } -// Adds `non_canonical_bytes` bytes to the varint representation at the tail of -// the buffer. -// `buf` points to the start of the buffer, `p` points to one-past-the-end. -// Returns the new one-past-the-end pointer. -uint8_t* AddNonCanonicalBytes(const uint8_t* buf, uint8_t* p, - int non_canonical_bytes) { - // varint can have a max of 10 bytes. - while (non_canonical_bytes-- > 0 && p - buf < 10) { - // Add a dummy byte at the end. - p[-1] |= 0x80; - p[0] = 0; - ++p; - } - return p; -} - -std::string EncodeEnumValue(int number, int value, int non_canonical_bytes) { - uint8_t buf[100]; - uint8_t* p = buf; - - p = internal::WireFormatLite::WriteEnumToArray(number, value, p); - p = AddNonCanonicalBytes(buf, p, non_canonical_bytes); - return std::string(buf, p); -} - -std::string EncodeOtherField() { - UNITTEST::EnumParseTester obj; - obj.set_other_field(1); - return obj.SerializeAsString(); -} - -TEST(MESSAGE_TEST_NAME, TestEnumParsers) { - UNITTEST::EnumParseTester obj; - - const auto other_field = EncodeOtherField(); - - // Encode a boolean field for many different cases and verify that it can be - // parsed as expected. - // There are: - // - optional/repeated/packed fields - // - field tags that encode in 1/2/3 bytes - // - canonical and non-canonical encodings of the varint - // - last vs not last field - // - label combinations to trigger different parsers: sequential, small - // sequential, non-validated. - - constexpr int kInvalidValue = 0x900913; - auto* ref = obj.GetReflection(); - auto* descriptor = obj.descriptor(); - for (bool use_tail_field : {false, true}) { - SCOPED_TRACE(use_tail_field); - for (int non_canonical_bytes = 0; non_canonical_bytes < 5; - ++non_canonical_bytes) { - SCOPED_TRACE(non_canonical_bytes); - for (int i = 0; i < descriptor->field_count(); ++i) { - const auto* field = descriptor->field(i); - if (field->name() == "other_field") continue; - SCOPED_TRACE(field->full_name()); - const auto* enum_desc = field->enum_type(); - for (int e = 0; e < enum_desc->value_count(); ++e) { - const auto* value_desc = enum_desc->value(e); - if (value_desc->number() < 0 && non_canonical_bytes > 0) { - // Negative numbers only have a canonical representation. - continue; - } - SCOPED_TRACE(value_desc->number()); - GOOGLE_CHECK_NE(value_desc->number(), kInvalidValue) - << "Invalid value is a real label."; - auto encoded = EncodeEnumValue(field->number(), value_desc->number(), - non_canonical_bytes); - if (use_tail_field) { - // Make sure that fields after this one can be parsed too. ie test - // that the "next" jump is correct too. - encoded += other_field; - } - - EXPECT_TRUE(obj.ParseFromString(encoded)); - if (field->is_repeated()) { - ASSERT_EQ(ref->FieldSize(obj, field), 1); - EXPECT_EQ(ref->GetRepeatedEnumValue(obj, field, 0), - value_desc->number()); - } else { - EXPECT_TRUE(ref->HasField(obj, field)); - EXPECT_EQ(ref->GetEnumValue(obj, field), value_desc->number()); - } - auto& unknown = ref->GetUnknownFields(obj); - ASSERT_EQ(unknown.field_count(), 0); - } - - SCOPED_TRACE("Invalid value"); - // Try an invalid value, which should go to the unknown fields. - EXPECT_TRUE(obj.ParseFromString(EncodeEnumValue( - field->number(), kInvalidValue, non_canonical_bytes))); - if (field->is_repeated()) { - ASSERT_EQ(ref->FieldSize(obj, field), 0); - } else { - EXPECT_FALSE(ref->HasField(obj, field)); - EXPECT_EQ(ref->GetEnumValue(obj, field), - enum_desc->value(0)->number()); - } - auto& unknown = ref->GetUnknownFields(obj); - ASSERT_EQ(unknown.field_count(), 1); - EXPECT_EQ(unknown.field(0).number(), field->number()); - EXPECT_EQ(unknown.field(0).type(), unknown.field(0).TYPE_VARINT); - EXPECT_EQ(unknown.field(0).varint(), kInvalidValue); - } - } - } -} - -std::string EncodeBoolValue(int number, bool value, int non_canonical_bytes) { - uint8_t buf[100]; - uint8_t* p = buf; - - p = internal::WireFormatLite::WriteBoolToArray(number, value, p); - p = AddNonCanonicalBytes(buf, p, non_canonical_bytes); - return std::string(buf, p); -} - -TEST(MESSAGE_TEST_NAME, TestBoolParsers) { - UNITTEST::BoolParseTester obj; - - const auto other_field = EncodeOtherField(); - - // Encode a boolean field for many different cases and verify that it can be - // parsed as expected. - // There are: - // - optional/repeated/packed fields - // - field tags that encode in 1/2/3 bytes - // - canonical and non-canonical encodings of the varint - // - last vs not last field - - auto* ref = obj.GetReflection(); - auto* descriptor = obj.descriptor(); - for (bool use_tail_field : {false, true}) { - SCOPED_TRACE(use_tail_field); - for (int non_canonical_bytes = 0; non_canonical_bytes < 10; - ++non_canonical_bytes) { - SCOPED_TRACE(non_canonical_bytes); - for (int i = 0; i < descriptor->field_count(); ++i) { - const auto* field = descriptor->field(i); - if (field->name() == "other_field") continue; - SCOPED_TRACE(field->full_name()); - for (bool value : {false, true}) { - SCOPED_TRACE(value); - auto encoded = - EncodeBoolValue(field->number(), value, non_canonical_bytes); - if (use_tail_field) { - // Make sure that fields after this one can be parsed too. ie test - // that the "next" jump is correct too. - encoded += other_field; - } - - EXPECT_TRUE(obj.ParseFromString(encoded)); - if (field->is_repeated()) { - ASSERT_EQ(ref->FieldSize(obj, field), 1); - EXPECT_EQ(ref->GetRepeatedBool(obj, field, 0), value); - } else { - EXPECT_TRUE(ref->HasField(obj, field)); - EXPECT_EQ(ref->GetBool(obj, field), value); - } - auto& unknown = ref->GetUnknownFields(obj); - ASSERT_EQ(unknown.field_count(), 0); - } - } - } - } -} - -TEST(MESSAGE_TEST_NAME, IsDefaultInstance) { - UNITTEST::TestAllTypes msg; - const auto& default_msg = UNITTEST::TestAllTypes::default_instance(); - const auto* r = msg.GetReflection(); - EXPECT_TRUE(r->IsDefaultInstance(default_msg)); - EXPECT_FALSE(r->IsDefaultInstance(msg)); -} - -std::string EncodeStringValue(int number, const std::string& value) { - uint8_t buf[100]; - return std::string( - buf, internal::WireFormatLite::WriteStringToArray(number, value, buf)); -} - -class TestInputStream final : public io::ZeroCopyInputStream { - public: - explicit TestInputStream(absl::string_view payload, size_t break_pos) - : payload_(payload), break_pos_(break_pos) {} - - bool Next(const void** data, int* size) override { - if (payload_.empty()) return false; - const auto to_consume = payload_.substr(0, break_pos_); - *data = to_consume.data(); - *size = to_consume.size(); - payload_.remove_prefix(to_consume.size()); - // The next time will consume the rest. - break_pos_ = payload_.npos; - - return true; - } - - void BackUp(int) override { GOOGLE_CHECK(false); } - bool Skip(int) override { - GOOGLE_CHECK(false); - return false; - } - int64_t ByteCount() const override { - GOOGLE_CHECK(false); - return 0; - } - - private: - absl::string_view payload_; - size_t break_pos_; -}; - -TEST(MESSAGE_TEST_NAME, TestRepeatedStringParsers) { - google::protobuf::Arena arena; - - const std::string sample = - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - const auto* const descriptor = UNITTEST::StringParseTester::descriptor(); - - static const size_t sso_capacity = std::string().capacity(); - if (sso_capacity == 0) GTEST_SKIP(); - // SSO, !SSO, and off-by-one just in case - for (size_t size : - {sso_capacity - 1, sso_capacity, sso_capacity + 1, sso_capacity + 2}) { - SCOPED_TRACE(size); - const std::string value = sample.substr(0, size); - for (int i = 0; i < descriptor->field_count(); ++i) { - const auto* field = descriptor->field(i); - SCOPED_TRACE(field->full_name()); - const auto encoded = EncodeStringValue(field->number(), sample) + - EncodeStringValue(field->number(), value); - // Check for different breaks in the input stream to test cases where - // the payload can be read and can't be read in one go. - for (size_t i = 1; i <= encoded.size(); ++i) { - TestInputStream input_stream(encoded, i); - - auto& obj = *arena.CreateMessage(&arena); - auto* ref = obj.GetReflection(); - EXPECT_TRUE(obj.ParseFromZeroCopyStream(&input_stream)); - if (field->is_repeated()) { - ASSERT_EQ(ref->FieldSize(obj, field), 2); - EXPECT_EQ(ref->GetRepeatedString(obj, field, 0), sample); - EXPECT_EQ(ref->GetRepeatedString(obj, field, 1), value); - } else { - EXPECT_EQ(ref->GetString(obj, field), value); - } - } - } - } -} - -TEST(MESSAGE_TEST_NAME, TestRegressionOnParseFailureNotSettingHasBits) { - std::string single_field; - // We use blocks because we want fully new instances of the proto. We are - // testing .Clear(), so we can't use it to set up the test. - { - UNITTEST::TestAllTypes message; - message.set_optional_int32(17); - single_field = message.SerializeAsString(); - } - const auto validate_message = [] (auto& message) { - if (!message.has_optional_int32()) { - EXPECT_EQ(message.optional_int32(), 0); - } - message.Clear(); - EXPECT_FALSE(message.has_optional_int32()); - EXPECT_EQ(message.optional_int32(), 0); - }; - { - // Verify the setup is correct. - UNITTEST::TestAllTypes message; - EXPECT_FALSE(message.has_optional_int32()); - EXPECT_EQ(message.optional_int32(), 0); - EXPECT_TRUE(message.ParseFromString(single_field)); - validate_message(message); - } - { - // Run the regression. - // These are the steps: - // - The stream contains a fast field, and then a failure in MiniParse - // - The parsing fails. - // - We call clear. - // - The fast field should be reset. - UNITTEST::TestAllTypes message; - EXPECT_FALSE(message.has_optional_int32()); - EXPECT_EQ(message.optional_int32(), 0); - // The second tag will fail to parse because it has too many continuation - // bits. - auto with_error = - absl::StrCat(single_field, std::string(100, static_cast(0x80))); - EXPECT_FALSE(message.ParseFromString(with_error)); - validate_message(message); - } -} - } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/metadata_lite.h b/libs/protobuf/src/google/protobuf/metadata_lite.h index 0700327..0c31517 100644 --- a/libs/protobuf/src/google/protobuf/metadata_lite.h +++ b/libs/protobuf/src/google/protobuf/metadata_lite.h @@ -32,13 +32,12 @@ #define GOOGLE_PROTOBUF_METADATA_LITE_H__ #include - -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "google/protobuf/port.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -46,9 +45,6 @@ namespace google { namespace protobuf { - -class UnknownFieldSet; - namespace internal { // This is the representation for messages that support arena allocation. It @@ -284,19 +280,6 @@ PROTOBUF_EXPORT void InternalMetadata::DoMergeFrom( template <> PROTOBUF_EXPORT void InternalMetadata::DoSwap(std::string* other); -// Instantiated once in message.cc (where the definition of UnknownFieldSet is -// known) to prevent much duplication across translation units of a large build. -extern template PROTOBUF_EXPORT void -InternalMetadata::DoClear(); -extern template PROTOBUF_EXPORT void -InternalMetadata::DoMergeFrom(const UnknownFieldSet& other); -extern template PROTOBUF_EXPORT void -InternalMetadata::DoSwap(UnknownFieldSet* other); -extern template PROTOBUF_EXPORT Arena* -InternalMetadata::DeleteOutOfLineHelper(); -extern template PROTOBUF_EXPORT UnknownFieldSet* -InternalMetadata::mutable_unknown_fields_slow(); - // This helper RAII class is needed to efficiently parse unknown fields. We // should only call mutable_unknown_fields if there are actual unknown fields. // The obvious thing to just use a stack string and swap it at the end of @@ -328,6 +311,6 @@ class PROTOBUF_EXPORT LiteUnknownFieldSetter { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_METADATA_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/no_field_presence_test.cc b/libs/protobuf/src/google/protobuf/no_field_presence_test.cc index d28fb14..2582cfe 100644 --- a/libs/protobuf/src/google/protobuf/no_field_presence_test.cc +++ b/libs/protobuf/src/google/protobuf/no_field_presence_test.cc @@ -30,10 +30,10 @@ #include -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_no_field_presence.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" +#include +#include +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/parse_context.cc b/libs/protobuf/src/google/protobuf/parse_context.cc index 63f76fd..59852fd 100644 --- a/libs/protobuf/src/google/protobuf/parse_context.cc +++ b/libs/protobuf/src/google/protobuf/parse_context.cc @@ -28,19 +28,19 @@ // (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/parse_context.h" +#include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/endian.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/repeated_field.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -279,8 +279,7 @@ const char* ParseContext::ReadSizeAndPushLimitAndDepth(const char* ptr, const char* ParseContext::ParseMessage(MessageLite* msg, const char* ptr) { int old; ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); - if (ptr == nullptr) return ptr; - ptr = msg->_InternalParse(ptr, this); + ptr = ptr ? msg->_InternalParse(ptr, this) : nullptr; depth_++; if (!PopLimit(old)) return nullptr; return ptr; @@ -300,7 +299,7 @@ void WriteVarint(uint32_t num, uint64_t val, std::string* s) { WriteVarint(val, s); } -void WriteLengthDelimited(uint32_t num, absl::string_view val, std::string* s) { +void WriteLengthDelimited(uint32_t num, StringPiece val, std::string* s) { WriteVarint((num << 3) + 2, s); WriteVarint(val.size(), s); s->append(val.data(), val.size()); @@ -308,7 +307,7 @@ void WriteLengthDelimited(uint32_t num, absl::string_view val, std::string* s) { std::pair VarintParseSlow32(const char* p, uint32_t res) { - for (std::uint32_t i = 1; i < 5; i++) { + for (std::uint32_t i = 2; i < 5; i++) { uint32_t byte = static_cast(p[i]); res += (byte - 1) << (7 * i); if (PROTOBUF_PREDICT_TRUE(byte < 128)) { @@ -328,7 +327,7 @@ std::pair VarintParseSlow32(const char* p, std::pair VarintParseSlow64(const char* p, uint32_t res32) { uint64_t res = res32; - for (std::uint32_t i = 1; i < 10; i++) { + for (std::uint32_t i = 2; i < 10; i++) { uint64_t byte = static_cast(p[i]); res += (byte - 1) << (7 * i); if (PROTOBUF_PREDICT_TRUE(byte < 128)) { @@ -377,12 +376,12 @@ const char* StringParser(const char* begin, const char* end, void* object, } // Defined in wire_format_lite.cc -void PrintUTF8ErrorLog(absl::string_view message_name, - absl::string_view field_name, const char* operation_str, +void PrintUTF8ErrorLog(StringPiece message_name, + StringPiece field_name, const char* operation_str, bool emit_stacktrace); -bool VerifyUTF8(absl::string_view str, const char* field_name) { - if (!::google::protobuf::internal::IsStructurallyValidUTF8(str)) { +bool VerifyUTF8(StringPiece str, const char* field_name) { + if (!IsStructurallyValidUTF8(str)) { PrintUTF8ErrorLog("", field_name, "parsing", false); return false; } @@ -542,226 +541,8 @@ const char* UnknownFieldParse(uint32_t tag, std::string* unknown, return FieldParser(tag, field_parser, ptr, ctx); } -#ifdef __aarch64__ -// Generally, speaking, the ARM-optimized Varint decode algorithm is to extract -// and concatenate all potentially valid data bits, compute the actual length -// of the Varint, and mask off the data bits which are not actually part of the -// result. More detail on the two main parts is shown below. -// -// 1) Extract and concatenate all potentially valid data bits. -// Two ARM-specific features help significantly: -// a) Efficient and non-destructive bit extraction (UBFX) -// b) A single instruction can perform both an OR with a shifted -// second operand in one cycle. E.g., the following two lines do the same -// thing -// ```result = operand_1 | (operand2 << 7);``` -// ```ORR %[result], %[operand_1], %[operand_2], LSL #7``` -// The figure below shows the implementation for handling four chunks. -// -// Bits 32 31-24 23 22-16 15 14-8 7 6-0 -// +----+---------+----+---------+----+---------+----+---------+ -// |CB 3| Chunk 3 |CB 2| Chunk 2 |CB 1| Chunk 1 |CB 0| Chunk 0 | -// +----+---------+----+---------+----+---------+----+---------+ -// | | | | -// UBFX UBFX UBFX UBFX -- cycle 1 -// | | | | -// V V V V -// Combined LSL #7 and ORR Combined LSL #7 and ORR -- cycle 2 -// | | -// V V -// Combined LSL #14 and ORR -- cycle 3 -// | -// V -// Parsed bits 0-27 -// -// -// 2) Calculate the index of the cleared continuation bit in order to determine -// where the encoded Varint ends and the size of the decoded value. The -// easiest way to do this is mask off all data bits, leaving just the -// continuation bits. We actually need to do the masking on an inverted -// copy of the data, which leaves a 1 in all continuation bits which were -// originally clear. The number of trailing zeroes in this value indicates -// the size of the Varint. -// -// AND 0x80 0x80 0x80 0x80 0x80 0x80 0x80 0x80 -// -// Bits 63 55 47 39 31 23 15 7 -// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ -// ~ |CB 7| |CB 6| |CB 5| |CB 4| |CB 3| |CB 2| |CB 1| |CB 0| | -// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ -// | | | | | | | | -// V V V V V V V V -// Bits 63 55 47 39 31 23 15 7 -// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ -// |~CB 7|0|~CB 6|0|~CB 5|0|~CB 4|0|~CB 3|0|~CB 2|0|~CB 1|0|~CB 0|0| -// +----+--+----+--+----+--+----+--+----+--+----+--+----+--+----+--+ -// | -// CTZ -// V -// Index of first cleared continuation bit -// -// -// While this is implemented in C++ significant care has been taken to ensure -// the compiler emits the best instruction sequence. In some cases we use the -// following two functions to manipulate the compiler's scheduling decisions. -// -// Controls compiler scheduling by telling it that the first value is modified -// by the second value the callsite. This is useful if non-critical path -// instructions are too aggressively scheduled, resulting in a slowdown of the -// actual critical path due to opportunity costs. An example usage is shown -// where a false dependence of num_bits on result is added to prevent checking -// for a very unlikely error until all critical path instructions have been -// fetched. -// -// ``` -// num_bits = -// result = -// num_bits = ValueBarrier(num_bits, result); -// if (num_bits == 63) { -// GOOGLE_LOG(FATAL) << "Invalid num_bits value"; -// } -// ``` -template -PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1, - V2Type value2) { - asm("" : "+r"(value1) : "r"(value2)); - return value1; -} - -// Falsely indicate that the specific value is modified at this location. This -// prevents code which depends on this value from being scheduled earlier. -template -PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1) { - asm("" : "+r"(value1)); - return value1; -} - -PROTOBUF_ALWAYS_INLINE inline uint64_t ExtractAndMergeTwoChunks( - uint64_t data, uint64_t first_byte) { - GOOGLE_DCHECK(first_byte <= 6); - uint64_t first = Ubfx7(data, first_byte * 8); - uint64_t second = Ubfx7(data, (first_byte + 1) * 8); - return ForceToRegister(first | (second << 7)); -} - -struct SlowPathEncodedInfo { - const char* p; - uint64_t last8; - uint64_t valid_bits; - uint64_t valid_chunk_bits; - uint64_t masked_cont_bits; -}; - -// Performs multiple actions which are identical between 32 and 64 bit Varints -// in order to compute the length of the encoded Varint and compute the new -// of p. -PROTOBUF_ALWAYS_INLINE inline SlowPathEncodedInfo ComputeLengthAndUpdateP( - const char* p) { - SlowPathEncodedInfo result; - // Load the last two bytes of the encoded Varint. - std::memcpy(&result.last8, p + 2, sizeof(result.last8)); - uint64_t mask = ForceToRegister(0x8080808080808080); - // Only set continuation bits remain - result.masked_cont_bits = ForceToRegister(mask & (~result.last8)); - // The first cleared continuation bit is the most significant 1 in the - // reversed value. Result is undefined for an input of 0 and we handle that - // case below. - result.valid_bits = absl::countr_zero(result.masked_cont_bits); - // Calculates the number of chunks in the encoded Varint. This value is low - // by three as neither the cleared continuation chunk nor the first two chunks - // are counted. - uint64_t set_continuation_bits = result.valid_bits >> 3; - // Update p to point past the encoded Varint. - result.p = p + set_continuation_bits + 3; - // Calculate number of valid data bits in the decoded value so invalid bits - // can be masked off. Value is too low by 14 but we account for that when - // calculating the mask. - result.valid_chunk_bits = result.valid_bits - set_continuation_bits; - return result; -} - -constexpr uint64_t kResultMaskUnshifted = 0xffffffffffffc000ULL; -constexpr uint64_t kFirstResultBitChunk1 = 1 * 7; -constexpr uint64_t kFirstResultBitChunk2 = 2 * 7; -constexpr uint64_t kFirstResultBitChunk3 = 3 * 7; -constexpr uint64_t kFirstResultBitChunk4 = 4 * 7; -constexpr uint64_t kFirstResultBitChunk6 = 6 * 7; -constexpr uint64_t kFirstResultBitChunk8 = 8 * 7; -constexpr uint64_t kValidBitsForInvalidVarint = 0x60; - -PROTOBUF_NOINLINE const char* VarintParseSlowArm64(const char* p, uint64_t* out, - uint64_t first8) { - SlowPathEncodedInfo info = ComputeLengthAndUpdateP(p); - // Extract data bits from the low six chunks. This includes chunks zero and - // one which we already know are valid. - uint64_t merged_01 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/0); - uint64_t merged_23 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/2); - uint64_t merged_45 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/4); - // Low 42 bits of decoded value. - uint64_t result = merged_01 | merged_23 << kFirstResultBitChunk2 | - merged_45 << kFirstResultBitChunk4; - // This immediate ends in 14 zeroes since valid_chunk_bits is too low by 14. - uint64_t result_mask = kResultMaskUnshifted << info.valid_chunk_bits; - // masked_cont_bits is 0 iff the Varint is invalid. In that case - info.valid_bits = - info.masked_cont_bits ? info.valid_bits : kValidBitsForInvalidVarint; - // Test for early exit if Varint does not exceed 6 chunks. Branching on one - // bit is faster on ARM than via a compare and branch. - if (PROTOBUF_PREDICT_FALSE((info.valid_bits & 0x20) != 0)) { - // Extract data bits from high four chunks. - uint64_t merged_67 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/6); - // Last two chunks come from last two bytes of info.last8. - uint64_t merged_89 = - ExtractAndMergeTwoChunks(info.last8, /*first_chunk=*/6); - result |= merged_67 << kFirstResultBitChunk6; - result |= merged_89 << kFirstResultBitChunk8; - // Handle an invalid Varint with all 10 continuation bits set. - info.masked_cont_bits = ValueBarrier(info.masked_cont_bits); - if (PROTOBUF_PREDICT_FALSE(info.masked_cont_bits == 0)) { - *out = 0; - return nullptr; - } - } - // Mask off invalid data bytes. - result &= ~result_mask; - *out = result; - return info.p; -} - -// See comments in VarintParseSlowArm64 for a description of the algorithm. -// Differences in the 32 bit version are noted below. -PROTOBUF_NOINLINE const char* VarintParseSlowArm32(const char* p, uint32_t* out, - uint64_t first8) { - // This also skips the slop bytes. - SlowPathEncodedInfo info = ComputeLengthAndUpdateP(p); - // Extract data bits from chunks 1-4. Chunk zero is merged in below. - uint64_t merged_12 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/1); - uint64_t merged_34 = ExtractAndMergeTwoChunks(first8, /*first_chunk=*/3); - first8 = ValueBarrier(first8, p); - uint64_t result = Ubfx7(first8, /*start=*/0); - result = ForceToRegister(result | merged_12 << kFirstResultBitChunk1); - result = ForceToRegister(result | merged_34 << kFirstResultBitChunk3); - uint64_t result_mask = kResultMaskUnshifted << info.valid_chunk_bits; - result &= ~result_mask; - // It is extremely unlikely that a Varint is invalid so checking that - // condition isn't on the critical path. Here we make sure that we don't do so - // until result has been computed. - info.masked_cont_bits = ValueBarrier(info.masked_cont_bits, result); - if (PROTOBUF_PREDICT_FALSE(info.masked_cont_bits == 0)) { - // Makes the compiler think out was modified here. This ensures it won't - // predicate this extremely predictable branch. - out = ValueBarrier(out); - *out = 0; - return nullptr; - } - *out = result; - return info.p; -} - -#endif // __aarch64__ - } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/parse_context.h b/libs/protobuf/src/google/protobuf/parse_context.h index c50e373..7aea50c 100644 --- a/libs/protobuf/src/google/protobuf/parse_context.h +++ b/libs/protobuf/src/google/protobuf/parse_context.h @@ -36,23 +36,21 @@ #include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/arena.h" -#include "absl/strings/internal/resize_uninitialized.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/endian.h" -#include "google/protobuf/implicit_weak_message.h" -#include "google/protobuf/inlined_string_field.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/wire_format_lite.h" - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { @@ -66,11 +64,11 @@ namespace internal { // Template code below needs to know about the existence of these functions. PROTOBUF_EXPORT void WriteVarint(uint32_t num, uint64_t val, std::string* s); -PROTOBUF_EXPORT void WriteLengthDelimited(uint32_t num, absl::string_view val, +PROTOBUF_EXPORT void WriteLengthDelimited(uint32_t num, StringPiece val, std::string* s); // Inline because it is just forwarding to s->WriteVarint inline void WriteVarint(uint32_t num, uint64_t val, UnknownFieldSet* s); -inline void WriteLengthDelimited(uint32_t num, absl::string_view val, +inline void WriteLengthDelimited(uint32_t num, StringPiece val, UnknownFieldSet* s); @@ -159,13 +157,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { PROTOBUF_NODISCARD const char* ReadString(const char* ptr, int size, std::string* s) { if (size <= buffer_end_ + kSlopBytes - ptr) { - // Fundamentally we just want to do assign to the string. - // However micro-benchmarks regress on string reading cases. So we copy - // the same logic from the old CodedInputStream ReadString. Note: as of - // Apr 2021, this is still a significant win over `assign()`. - absl::strings_internal::STLStringResizeUninitialized(s, size); - char* z = &(*s)[0]; - memcpy(z, ptr, size); + s->assign(ptr, size); return ptr + size; } return ReadStringFallback(ptr, size, s); @@ -212,10 +204,6 @@ class PROTOBUF_EXPORT EpsCopyInputStream { int BytesUntilLimit(const char* ptr) const { return limit_ + static_cast(buffer_end_ - ptr); } - // Maximum number of sequential bytes that can be read starting from `ptr`. - int MaximumReadSize(const char* ptr) const { - return static_cast(limit_end_ - ptr) + kSlopBytes; - } // Returns true if more data is available, if false is returned one has to // call Done for further checks. bool DataAvailable(const char* ptr) { return ptr < limit_end_; } @@ -241,7 +229,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { return res.second; } - const char* InitFrom(absl::string_view flat) { + const char* InitFrom(StringPiece flat) { overall_limit_ = 0; if (flat.size() > kSlopBytes) { limit_ = kSlopBytes; @@ -250,9 +238,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { if (aliasing_ == kOnPatch) aliasing_ = kNoDelta; return flat.data(); } else { - if (!flat.empty()) { - std::memcpy(buffer_, flat.data(), flat.size()); - } + std::memcpy(buffer_, flat.data(), flat.size()); limit_ = 0; limit_end_ = buffer_end_ = buffer_ + flat.size(); next_chunk_ = nullptr; @@ -339,7 +325,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { template const char* AppendSize(const char* ptr, int size, const A& append) { - int chunk_size = static_cast(buffer_end_ + kSlopBytes - ptr); + int chunk_size = buffer_end_ + kSlopBytes - ptr; do { GOOGLE_DCHECK(size > chunk_size); if (next_chunk_ == nullptr) return nullptr; @@ -353,7 +339,7 @@ class PROTOBUF_EXPORT EpsCopyInputStream { ptr = Next(); if (ptr == nullptr) return nullptr; // passed the limit ptr += kSlopBytes; - chunk_size = static_cast(buffer_end_ + kSlopBytes - ptr); + chunk_size = buffer_end_ + kSlopBytes - ptr; } while (size > chunk_size); append(ptr, size); return ptr + size; @@ -401,6 +387,7 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { struct Data { const DescriptorPool* pool = nullptr; MessageFactory* factory = nullptr; + Arena* arena = nullptr; }; template @@ -440,17 +427,6 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { bool>::type = true> PROTOBUF_NODISCARD const char* ParseMessage(T* msg, const char* ptr); - template - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* ParseMessage( - MessageLite* msg, const char* ptr, const Table* table) { - int old; - ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); - ptr = ptr ? TcParser::ParseLoop(msg, ptr, this, table) : nullptr; - depth_++; - if (!PopLimit(old)) return nullptr; - return ptr; - } - template PROTOBUF_NODISCARD PROTOBUF_NDEBUG_INLINE const char* ParseGroup( T* msg, const char* ptr, uint32_t tag) { @@ -463,18 +439,6 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { return ptr; } - template - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* ParseGroup( - MessageLite* msg, const char* ptr, uint32_t tag, const Table* table) { - if (--depth_ < 0) return nullptr; - group_depth_++; - ptr = TcParser::ParseLoop(msg, ptr, this, table); - group_depth_--; - depth_++; - if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(tag))) return nullptr; - return ptr; - } - private: // Out-of-line routine to save space in ParseContext::ParseMessage // int old; @@ -487,11 +451,6 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { PROTOBUF_NODISCARD const char* ReadSizeAndPushLimitAndDepth(const char* ptr, int* old_limit); - // As above, but fully inlined for the cases where we care about performance - // more than size. eg TcParser. - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* - ReadSizeAndPushLimitAndDepthInlined(const char* ptr, int* old_limit); - // The context keeps an internal stack to keep track of the recursive // part of the parse state. // Current depth of the active parser, depth counts down. @@ -575,64 +534,21 @@ inline const char* VarintParseSlow(const char* p, uint32_t res, uint64_t* out) { return tmp.first; } -#ifdef __aarch64__ -const char* VarintParseSlowArm64(const char* p, uint64_t* out, uint64_t first8); -const char* VarintParseSlowArm32(const char* p, uint32_t* out, uint64_t first8); - -inline const char* VarintParseSlowArm(const char* p, uint32_t* out, - uint64_t first8) { - return VarintParseSlowArm32(p, out, first8); -} - -inline const char* VarintParseSlowArm(const char* p, uint64_t* out, - uint64_t first8) { - return VarintParseSlowArm64(p, out, first8); -} - -// Moves data into a register and returns data. This impacts the compiler's -// scheduling and instruction selection decisions. -static PROTOBUF_ALWAYS_INLINE inline uint64_t ForceToRegister(uint64_t data) { - asm("" : "+r"(data)); - return data; -} - -// Performs a 7 bit UBFX (Unsigned Bit Extract) starting at the indicated bit. -static PROTOBUF_ALWAYS_INLINE inline uint64_t Ubfx7(uint64_t data, - uint64_t start) { - return ForceToRegister((data >> start) & 0x7f); -} - -#endif // __aarch64__ - template PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) { -#if defined(__aarch64__) && defined(PROTOBUF_LITTLE_ENDIAN) - // This optimization is not supported in big endian mode - uint64_t first8; - std::memcpy(&first8, p, sizeof(first8)); - if (PROTOBUF_PREDICT_TRUE((first8 & 0x80) == 0)) { - *out = static_cast(first8); - return p + 1; - } - if (PROTOBUF_PREDICT_TRUE((first8 & 0x8000) == 0)) { - uint64_t chunk1; - uint64_t chunk2; - // Extracting the two chunks this way gives a speedup for this path. - chunk1 = Ubfx7(first8, 0); - chunk2 = Ubfx7(first8, 8); - *out = chunk1 | (chunk2 << 7); - return p + 2; - } - return VarintParseSlowArm(p, out, first8); -#else // __aarch64__ auto ptr = reinterpret_cast(p); uint32_t res = ptr[0]; - if ((res & 0x80) == 0) { + if (!(res & 0x80)) { *out = res; return p + 1; } + uint32_t byte = ptr[1]; + res += (byte - 1) << 7; + if (!(byte & 0x80)) { + *out = res; + return p + 2; + } return VarintParseSlow(p, res, out); -#endif // __aarch64__ } // Used for tags, could read up to 5 bytes which must be available. @@ -674,7 +590,6 @@ PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE constexpr T RotateLeft( PROTOBUF_NODISCARD inline PROTOBUF_ALWAYS_INLINE uint64_t RotRight7AndReplaceLowByte(uint64_t res, const char& byte) { - // TODO(b/239808098): remove the inline assembly #if defined(__x86_64__) && defined(__GNUC__) // This will only use one register for `res`. // `byte` comes as a reference to allow the compiler to generate code like: @@ -834,26 +749,12 @@ PROTOBUF_NODISCARD const char* ParseContext::ParseMessage(T* msg, const char* ptr) { int old; ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); - if (ptr == nullptr) return ptr; - ptr = msg->_InternalParse(ptr, this); + ptr = ptr ? msg->_InternalParse(ptr, this) : nullptr; depth_++; if (!PopLimit(old)) return nullptr; return ptr; } -inline const char* ParseContext::ReadSizeAndPushLimitAndDepthInlined( - const char* ptr, int* old_limit) { - int size = ReadSize(&ptr); - if (PROTOBUF_PREDICT_FALSE(!ptr)) { - // Make sure this isn't uninitialized even on error return - *old_limit = 0; - return nullptr; - } - *old_limit = PushLimit(ptr, size); - if (--depth_ < 0) return nullptr; - return ptr; -} - template const char* EpsCopyInputStream::ReadRepeatedFixed(const char* ptr, Tag expected_tag, @@ -882,7 +783,7 @@ template const char* EpsCopyInputStream::ReadPackedFixed(const char* ptr, int size, RepeatedField* out) { GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - int nbytes = static_cast(buffer_end_ + kSlopBytes - ptr); + int nbytes = buffer_end_ + kSlopBytes - ptr; while (size > nbytes) { int num = nbytes / sizeof(T); int old_entries = out->size(); @@ -900,16 +801,14 @@ const char* EpsCopyInputStream::ReadPackedFixed(const char* ptr, int size, ptr = Next(); if (ptr == nullptr) return nullptr; ptr += kSlopBytes - (nbytes - block_size); - nbytes = static_cast(buffer_end_ + kSlopBytes - ptr); + nbytes = buffer_end_ + kSlopBytes - ptr; } int num = size / sizeof(T); - int block_size = num * sizeof(T); - if(num == 0) return size == block_size ? ptr : nullptr; int old_entries = out->size(); out->Reserve(old_entries + num); + int block_size = num * sizeof(T); auto dst = out->AddNAlreadyReserved(num); #ifdef PROTOBUF_LITTLE_ENDIAN - GOOGLE_CHECK(dst != nullptr) << out << "," << num; std::memcpy(dst, ptr, block_size); #else for (int i = 0; i < num; i++) dst[i] = UnalignedLoad(ptr + i * sizeof(T)); @@ -934,11 +833,11 @@ template const char* EpsCopyInputStream::ReadPackedVarint(const char* ptr, Add add) { int size = ReadSize(&ptr); GOOGLE_PROTOBUF_PARSER_ASSERT(ptr); - int chunk_size = static_cast(buffer_end_ - ptr); + int chunk_size = buffer_end_ - ptr; while (size > chunk_size) { ptr = ReadPackedVarintArray(ptr, buffer_end_, add); if (ptr == nullptr) return nullptr; - int overrun = static_cast(ptr - buffer_end_); + int overrun = ptr - buffer_end_; GOOGLE_DCHECK(overrun >= 0 && overrun <= kSlopBytes); if (size - chunk_size <= kSlopBytes) { // The current buffer contains all the information needed, we don't need @@ -959,7 +858,7 @@ const char* EpsCopyInputStream::ReadPackedVarint(const char* ptr, Add add) { ptr = Next(); if (ptr == nullptr) return nullptr; ptr += overrun; - chunk_size = static_cast(buffer_end_ - ptr); + chunk_size = buffer_end_ - ptr; } auto end = ptr + size; ptr = ReadPackedVarintArray(ptr, end, add); @@ -968,7 +867,7 @@ const char* EpsCopyInputStream::ReadPackedVarint(const char* ptr, Add add) { // Helper for verification of utf8 PROTOBUF_EXPORT -bool VerifyUTF8(absl::string_view s, const char* field_name); +bool VerifyUTF8(StringPiece s, const char* field_name); inline bool VerifyUTF8(const std::string* s, const char* field_name) { return VerifyUTF8(*s, field_name); @@ -1121,6 +1020,6 @@ PROTOBUF_NODISCARD PROTOBUF_EXPORT const char* UnknownFieldParse( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_PARSE_CONTEXT_H__ diff --git a/libs/protobuf/src/google/protobuf/port.h b/libs/protobuf/src/google/protobuf/port.h index f3c6e66..a5c060b 100644 --- a/libs/protobuf/src/google/protobuf/port.h +++ b/libs/protobuf/src/google/protobuf/port.h @@ -36,27 +36,17 @@ #ifndef GOOGLE_PROTOBUF_PORT_H__ #define GOOGLE_PROTOBUF_PORT_H__ -#include #include #include -#include - - -// must be last -#include "google/protobuf/port_def.inc" namespace google { namespace protobuf { namespace internal { - - inline void SizedDelete(void* p, size_t size) { #if defined(__cpp_sized_deallocation) ::operator delete(p, size); #else - // Avoid -Wunused-parameter - (void)size; ::operator delete(p); #endif } @@ -64,8 +54,6 @@ inline void SizedArrayDelete(void* p, size_t size) { #if defined(__cpp_sized_deallocation) ::operator delete[](p, size); #else - // Avoid -Wunused-parameter - (void)size; ::operator delete[](p); #endif } @@ -85,35 +73,8 @@ struct ArenaInitialized { explicit ArenaInitialized() = default; }; -template -inline To DownCast(From* f) { - static_assert( - std::is_base_of::type>::value, - "illegal DownCast"); - -#if PROTOBUF_RTTI - // RTTI: debug mode only! - assert(f == nullptr || dynamic_cast(f) != nullptr); -#endif - return static_cast(f); -} - -template -inline ToRef DownCast(From& f) { - using To = typename std::remove_reference::type; - static_assert(std::is_base_of::value, "illegal DownCast"); - -#if PROTOBUF_RTTI - // RTTI: debug mode only! - assert(dynamic_cast(&f) != nullptr); -#endif - return *static_cast(&f); -} - } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" - #endif // GOOGLE_PROTOBUF_PORT_H__ diff --git a/libs/protobuf/src/google/protobuf/port_def.inc b/libs/protobuf/src/google/protobuf/port_def.inc index bac7b90..6c6aa18 100644 --- a/libs/protobuf/src/google/protobuf/port_def.inc +++ b/libs/protobuf/src/google/protobuf/port_def.inc @@ -118,15 +118,6 @@ #define PROTOBUF_has_builtin_DEFINED_ #endif -#ifdef ADDRESS_SANITIZER -#include -#define PROTOBUF_POISON_MEMORY_REGION(p, n) ASAN_POISON_MEMORY_REGION(p, n) -#define PROTOBUF_UNPOISON_MEMORY_REGION(p, n) ASAN_UNPOISON_MEMORY_REGION(p, n) -#else // ADDRESS_SANITIZER -#define PROTOBUF_POISON_MEMORY_REGION(p, n) -#define PROTOBUF_UNPOISON_MEMORY_REGION(p, n) -#endif // ADDRESS_SANITIZER - // Portable PROTOBUF_BUILTIN_BSWAPxx definitions // Code must check for availability, e.g.: `defined(PROTOBUF_BUILTIN_BSWAP32)` #ifdef PROTOBUF_BUILTIN_BSWAP16 @@ -148,11 +139,6 @@ #define PROTOBUF_BUILTIN_BSWAP64(x) __builtin_bswap64(x) #endif -// Portable check for gcc-style atomic built-ins -#if __has_builtin(__atomic_load_n) -#define PROTOBUF_BUILTIN_ATOMIC 1 -#endif - // Portable check for GCC minimum version: // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html #if defined(__GNUC__) && defined(__GNUC_MINOR__) \ @@ -163,13 +149,6 @@ # define PROTOBUF_GNUC_MIN(x, y) 0 #endif -#if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) -#define PROTOBUF_CLANG_MIN(x, y) \ - (__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y)) -#else -#define PROTOBUF_CLANG_MIN(x, y) 0 -#endif - // Portable check for MSVC minimum version: // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros #if defined(_MSC_VER) @@ -190,38 +169,16 @@ // Future versions of protobuf will include breaking changes to some APIs. // This macro can be set to enable these API changes ahead of time, so that // user code can be updated before upgrading versions of protobuf. - -#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES - -// Used to upgrade google::protobuf::MapPair to std::pair. -// Owner: mordberg@ -#define PROTOBUF_FUTURE_MAP_PAIR_UPGRADE 1 - -// Used on classes that are historically not marked as final, but that may be -// marked final in future (breaking) releases. -// Owner: kfm@ -#define PROTOBUF_FUTURE_FINAL final - -// Used to remove the RTTI checks for `DefaultFieldComparator`. -// Owner: kfm@ -#define PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR 1 - -// Used to remove the manipulation of cleared elements in RepeatedPtrField. -// Owner: mkruskal@ -#define PROTOBUF_FUTURE_REMOVE_CLEARED_API 1 - -// Used to escape C++20 keywords. -// TODO(mkruskal): ping b/238664698 when this lands in opensource. -// Owner: mkruskal@ -#define PROTOBUF_FUTURE_CPP20_KEYWORDS 1 -#else +// PROTOBUF_FUTURE_FINAL is used on classes that are historically not marked as +// final, but that may be marked final in future (breaking) releases. +// #define PROTOBUF_FUTURE_BREAKING_CHANGES 1 +// #define PROTOBUF_FUTURE_FINAL final #define PROTOBUF_FUTURE_FINAL -#endif #ifdef PROTOBUF_VERSION #error PROTOBUF_VERSION was previously defined #endif -#define PROTOBUF_VERSION 3021008 +#define PROTOBUF_VERSION 3021012 #ifdef PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC #error PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC was previously defined @@ -399,6 +356,15 @@ # define PROTOBUF_DEPRECATED_ENUM #endif +#ifdef PROTOBUF_FUNC_ALIGN +#error PROTOBUF_FUNC_ALIGN was previously defined +#endif +#if __has_attribute(aligned) || PROTOBUF_GNUC_MIN(4, 3) +#define PROTOBUF_FUNC_ALIGN(bytes) __attribute__((aligned(bytes))) +#else +#define PROTOBUF_FUNC_ALIGN(bytes) +#endif + #ifdef PROTOBUF_RETURNS_NONNULL #error PROTOBUF_RETURNS_NONNULL was previously defined #endif @@ -561,20 +527,12 @@ #error PROTOBUF_FORCE_RESET_IN_CLEAR was previously defined #endif -#ifdef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG -#error PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG was previously defined -#endif - // Force copy the default string to a string field so that non-optimized builds // have harder-to-rely-on address stability. #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING #error PROTOBUF_FORCE_COPY_DEFAULT_STRING was previously defined #endif -#ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION -#error PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION was previously defined -#endif - #ifdef PROTOBUF_FALLTHROUGH_INTENDED #error PROTOBUF_FALLTHROUGH_INTENDED was previously defined #endif @@ -677,39 +635,30 @@ // This experiment is purely for the purpose of gathering data. All code guarded // by this flag is supposed to be removed after this experiment. #define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT - #ifdef PROTOBUF_CONSTINIT #error PROTOBUF_CONSTINIT was previously defined #endif - -// Lexan sets both MSV_VER and clang, so handle it with the clang path. -#if defined(_MSC_VER) && !defined(__clang__) -// MSVC 17 currently seems to raise an error about constant-initialized pointers. -# if PROTOBUF_MSC_VER_MIN(1930) -# define PROTOBUF_CONSTINIT -# define PROTOBUF_CONSTEXPR constexpr -# endif -#else -# if defined(__cpp_constinit) && !defined(__CYGWIN__) -# define PROTOBUF_CONSTINIT constinit -# define PROTOBUF_CONSTEXPR constexpr +#if defined(__cpp_constinit) && !defined(_MSC_VER) +#define PROTOBUF_CONSTINIT constinit +#define PROTOBUF_CONSTEXPR constexpr // Some older Clang versions incorrectly raise an error about // constant-initializing weak default instance pointers. Versions 12.0 and // higher seem to work, except that XCode 12.5.1 shows the error even though it // uses Clang 12.0.5. -# elif !defined(__CYGWIN__) && \ - __has_cpp_attribute(clang::require_constant_initialization) && \ - ((defined(__APPLE__) && PROTOBUF_CLANG_MIN(13, 0)) || \ - (!defined(__APPLE__) && PROTOBUF_CLANG_MIN(12, 0))) -# define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] -# define PROTOBUF_CONSTEXPR constexpr -# elif PROTOBUF_GNUC_MIN(12, 2) -# define PROTOBUF_CONSTINIT __constinit -# define PROTOBUF_CONSTEXPR constexpr -# endif -#endif - -#ifndef PROTOBUF_CONSTINIT +// Clang-cl on Windows raises error also. +#elif !defined(_MSC_VER) && __has_cpp_attribute(clang::require_constant_initialization) && \ + ((defined(__APPLE__) && __clang_major__ >= 13) || \ + (!defined(__APPLE__) && __clang_major__ >= 12)) +#define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]] +#define PROTOBUF_CONSTEXPR constexpr +#elif PROTOBUF_GNUC_MIN(12, 2) +#define PROTOBUF_CONSTINIT __constinit +#define PROTOBUF_CONSTEXPR constexpr +// MSVC 17 currently seems to raise an error about constant-initialized pointers. +#elif defined(_MSC_VER) && _MSC_VER >= 1930 +#define PROTOBUF_CONSTINIT +#define PROTOBUF_CONSTEXPR constexpr +#else #define PROTOBUF_CONSTINIT #define PROTOBUF_CONSTEXPR #endif @@ -822,35 +771,21 @@ # endif #endif -// Tail call table-driven parsing is enabled by default. +// Tail call table-driven parsing can be enabled by defining +// PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER at compilation time. Note +// that this macro is for small-scale testing only, and is not supported. #ifdef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED #error PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED was previously declared #endif +#if defined(PROTOBUF_EXPERIMENTAL_USE_TAIL_CALL_TABLE_PARSER) #define PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED 1 - -#ifdef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION -#error PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION was previously defined #endif -#if !defined(PROTOBUF_TEMPORARY_DISABLE_TABLE_PARSER_ON_REFLECTION) -#define PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION 1 -#endif // PROTOBUF_ENABLE_FORCE_ALLOCATION_ON_CONSTRUCTION -// Note that this is performance sensitive: changing the parameters will change -// the registers used by the ABI calling convention, which subsequently affects -// register selection logic inside the function. -// Arguments `msg`, `ptr` and `ctx` are the 1st/2nd/3rd argument to match the -// signature of ParseLoop. -// -// Note for x86_64: `data` must be the third or fourth argument for performance -// reasons. In order to efficiently read the second byte of `data` we need it to -// be passed in RDX or RCX. -#define PROTOBUF_TC_PARAM_DECL \ - ::google::protobuf::MessageLite *msg, const char *ptr, \ - ::google::protobuf::internal::ParseContext *ctx, \ - ::google::protobuf::internal::TcFieldData data, \ - const ::google::protobuf::internal::TcParseTableBase *table, uint64_t hasbits -// PROTOBUF_TC_PARAM_PASS passes values to match PROTOBUF_TC_PARAM_DECL. -#define PROTOBUF_TC_PARAM_PASS msg, ptr, ctx, data, table, hasbits +#define PROTOBUF_TC_PARAM_DECL \ + ::google::protobuf::MessageLite *msg, const char *ptr, \ + ::google::protobuf::internal::ParseContext *ctx, \ + const ::google::protobuf::internal::TcParseTableBase *table, \ + uint64_t hasbits, ::google::protobuf::internal::TcFieldData data #ifdef PROTOBUF_UNUSED #error PROTOBUF_UNUSED was previously defined @@ -866,36 +801,13 @@ // ThreadSafeArenaz is turned off completely in opensource builds. -// autoheader defines this in some circumstances -#ifdef PACKAGE -#define PROTOBUF_DID_UNDEF_PACKAGE -#pragma push_macro("PACKAGE") -#undef PACKAGE -#endif - -// autoheader defines this in some circumstances -#ifdef PACKAGE -#define PROTOBUF_DID_UNDEF_PACKAGE -#pragma push_macro("PACKAGE") -#undef PACKAGE -#endif - -// linux is a legacy MACRO defined in most popular C++ standards. -#ifdef linux -#pragma push_macro("linux") -#undef linux -#define PROTOBUF_DID_UNDEF_LINUX -#endif - // Windows declares several inconvenient macro names. We #undef them and then // restore them in port_undef.inc. -#ifdef _WIN32 +#ifdef _MSC_VER #pragma push_macro("CREATE_NEW") #undef CREATE_NEW #pragma push_macro("DELETE") #undef DELETE -#pragma push_macro("DOMAIN") -#undef DOMAIN #pragma push_macro("DOUBLE_CLICK") #undef DOUBLE_CLICK #pragma push_macro("ERROR") @@ -908,8 +820,6 @@ #undef ERROR_NOT_FOUND #pragma push_macro("GetClassName") #undef GetClassName -#pragma push_macro("GetCurrentTime") -#undef GetCurrentTime #pragma push_macro("GetMessage") #undef GetMessage #pragma push_macro("GetObject") @@ -946,7 +856,7 @@ #undef STRICT #pragma push_macro("timezone") #undef timezone -#endif // _WIN32 +#endif // _MSC_VER #ifdef __APPLE__ // Inconvenient macro names from usr/include/math.h in some macOS SDKs. @@ -960,11 +870,6 @@ // Inconvenient macro names from usr/include/sys/syslimits.h in some macOS SDKs. #pragma push_macro("UID_MAX") #undef UID_MAX -#pragma push_macro("GID_MAX") -#undef GID_MAX -// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. -#pragma push_macro("TYPE_BOOL") -#undef TYPE_BOOL #endif // __APPLE__ #if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER) @@ -974,29 +879,13 @@ #undef DEBUG #endif // defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER) -// Protobuf does not support building with a number of warnings that are noisy -// (and of variable quality across compiler versions) or impossible to implement -// effectively but which people turn on anyways. -#ifdef __GNUC__ -#pragma GCC diagnostic push -// Some of the warnings below only exist in some GCC versions; those version -// ranges are poorly documented. -#pragma GCC diagnostic ignored "-Wpragmas" +#if PROTOBUF_GNUC_MIN(3, 0) // GCC does not allow disabling diagnostics within an expression: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one // globally even though it's only used for PROTOBUF_FIELD_OFFSET. +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winvalid-offsetof" -// This warning verifies that non-void-returning functions return a value in -// all paths. However, this warning is noisy, and requires adding unnecessary -// returns in unreachable positions. -#pragma GCC diagnostic ignored "-Wreturn-type" -// Some versions of GCC seem to think that -// [this] { Foo(); } -// leaves `this` unused, even though `Foo();` is a member function of the -// captured `this`. -// https://bugzilla.mozilla.org/show_bug.cgi?id=1373625 -#pragma GCC diagnostic ignored "-Wunused-lambda-capture" -#endif // __GNUC__ +#endif // Silence some MSVC warnings in all our code. #ifdef _MSC_VER @@ -1014,23 +903,6 @@ #pragma warning(disable: 4125) #endif -#if PROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII -#define PROTOBUF_DEBUG true -#else -#define PROTOBUF_DEBUG false -#endif - -// This `for` allows us to condition the `GOOGLE_LOG` on the define above, so that -// code can write `PROTOBUF_DLOG(INFO) << ...;` and have it turned off when -// debug logging is off. -// -// This is a `for`, not and `if`, to avoid it accidentally chaining with an -// `else` below it. -#define PROTOBUF_DLOG(x) \ - for (bool b = PROTOBUF_DEBUG; b; b = false) GOOGLE_LOG(x) - -#define PROTO2_IS_OSS true - // We don't want code outside port_def doing complex testing, so // remove our portable condition test macros to nudge folks away from // using it themselves. diff --git a/libs/protobuf/src/google/protobuf/port_undef.inc b/libs/protobuf/src/google/protobuf/port_undef.inc index 00b721b..e880fa5 100644 --- a/libs/protobuf/src/google/protobuf/port_undef.inc +++ b/libs/protobuf/src/google/protobuf/port_undef.inc @@ -35,14 +35,10 @@ #error "port_undef.inc must be included after port_def.inc" #endif -#undef PROTOBUF_POISON_MEMORY_REGION -#undef PROTOBUF_UNPOISON_MEMORY_REGION #undef PROTOBUF_BUILTIN_BSWAP16 #undef PROTOBUF_BUILTIN_BSWAP32 #undef PROTOBUF_BUILTIN_BSWAP64 -#undef PROTOBUF_BUILTIN_ATOMIC #undef PROTOBUF_GNUC_MIN -#undef PROTOBUF_CLANG_MIN #undef PROTOBUF_MSC_VER_MIN #undef PROTOBUF_CPLUSPLUS_MIN #undef PROTOBUF_NAMESPACE @@ -57,6 +53,7 @@ #undef PROTOBUF_DEPRECATED #undef PROTOBUF_DEPRECATED_ENUM #undef PROTOBUF_DEPRECATED_MSG +#undef PROTOBUF_FUNC_ALIGN #undef PROTOBUF_RETURNS_NONNULL #undef PROTOBUF_ATTRIBUTE_REINITIALIZES #undef PROTOBUF_RTTI @@ -75,9 +72,7 @@ #undef PROTOBUF_FORCE_COPY_IN_SWAP #undef PROTOBUF_FORCE_COPY_IN_MOVE #undef PROTOBUF_FORCE_RESET_IN_CLEAR -#undef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG #undef PROTOBUF_FORCE_COPY_DEFAULT_STRING -#undef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION #undef PROTOBUF_NAMESPACE_OPEN #undef PROTOBUF_NAMESPACE_CLOSE #undef PROTOBUF_UNUSED @@ -104,47 +99,26 @@ #undef PROTOBUF_MSAN #undef PROTOBUF_TSAN #undef PROTOBUF_TAIL_CALL_TABLE_PARSER_ENABLED -#undef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION #undef PROTOBUF_TC_PARAM_DECL #undef PROTOBUF_EXCLUSIVE_LOCKS_REQUIRED #undef PROTOBUF_LOCKS_EXCLUDED #undef PROTOBUF_NO_THREAD_SAFETY_ANALYSIS #undef PROTOBUF_GUARDED_BY -#undef PROTOBUF_DEBUG -#undef PROTOBUF_DLOG -#undef PROTO2_IS_OSS #ifdef PROTOBUF_FUTURE_BREAKING_CHANGES #undef PROTOBUF_FUTURE_BREAKING_CHANGES -#undef PROTOBUF_FUTURE_MAP_PAIR_UPGRADE -#undef PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR -#undef PROTOBUF_FUTURE_REMOVE_CLEARED_API #endif -#undef PROTOBUF_FUTURE_FINAL - -// Restore macros that may have been #undef'd in port_def.inc. - -#ifdef PROTOBUF_DID_UNDEF_PACKAGE -#pragma pop_macro("PACKAGE") -#undef PROTOBUF_DID_UNDEF_PACKAGE -#endif - -#ifdef PROTOBUF_DID_UNDEF_LINUX -#pragma pop_macro("linux") -#endif - -#ifdef _WIN32 +// Restore macro that may have been #undef'd in port_def.inc. +#ifdef _MSC_VER #pragma pop_macro("CREATE_NEW") #pragma pop_macro("DELETE") -#pragma pop_macro("DOMAIN") #pragma pop_macro("DOUBLE_CLICK") #pragma pop_macro("ERROR") #pragma pop_macro("ERROR_BUSY") #pragma pop_macro("ERROR_INSTALL_FAILED") #pragma pop_macro("ERROR_NOT_FOUND") #pragma pop_macro("GetClassName") -#pragma pop_macro("GetCurrentTime") #pragma pop_macro("GetMessage") #pragma pop_macro("GetObject") #pragma pop_macro("IGNORE") @@ -170,8 +144,6 @@ #pragma pop_macro("TRUE") #pragma pop_macro("FALSE") #pragma pop_macro("UID_MAX") -#pragma pop_macro("GID_MAX") -#pragma pop_macro("TYPE_BOOL") #endif // __APPLE__ #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) diff --git a/libs/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc b/libs/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc index 64d8247..7e6bbf1 100644 --- a/libs/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc +++ b/libs/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc @@ -28,11 +28,11 @@ // (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/unittest.pb.h" -#include "google/protobuf/unittest_preserve_unknown_enum.pb.h" -#include "google/protobuf/unittest_preserve_unknown_enum2.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/dynamic_message.h" +#include +#include +#include +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc b/libs/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc index 7c37f3f..06b8d08 100644 --- a/libs/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc +++ b/libs/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc @@ -32,8 +32,9 @@ #include #include -#include "google/protobuf/unittest_proto3_arena.pb.h" -#include "google/protobuf/arena.h" +#include +#include +#include #include using proto3_arena_unittest::TestAllTypes; diff --git a/libs/protobuf/src/google/protobuf/proto3_arena_unittest.cc b/libs/protobuf/src/google/protobuf/proto3_arena_unittest.cc index 0f55865..cfbe198 100644 --- a/libs/protobuf/src/google/protobuf/proto3_arena_unittest.cc +++ b/libs/protobuf/src/google/protobuf/proto3_arena_unittest.cc @@ -32,17 +32,18 @@ #include #include -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_proto3_arena.pb.h" -#include "google/protobuf/unittest_proto3_optional.pb.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/text_format.h" +#include +#include +#include +#include +#include +#include #include -#include "absl/strings/match.h" -#include "google/protobuf/test_util.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include using proto3_arena_unittest::ForeignMessage; using proto3_arena_unittest::TestAllTypes; @@ -296,7 +297,7 @@ TEST(Proto3OptionalTest, OptionalFieldDescriptor) { for (int i = 0; i < d->field_count(); i++) { const FieldDescriptor* f = d->field(i); - if (absl::StartsWith(f->name(), "singular")) { + if (HasPrefixString(f->name(), "singular")) { EXPECT_FALSE(f->has_optional_keyword()) << f->full_name(); EXPECT_FALSE(f->has_presence()) << f->full_name(); EXPECT_FALSE(f->containing_oneof()) << f->full_name(); diff --git a/libs/protobuf/src/google/protobuf/proto3_lite_unittest.cc b/libs/protobuf/src/google/protobuf/proto3_lite_unittest.cc index e3012db..abeeedb 100644 --- a/libs/protobuf/src/google/protobuf/proto3_lite_unittest.cc +++ b/libs/protobuf/src/google/protobuf/proto3_lite_unittest.cc @@ -28,13 +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. -#include "google/protobuf/unittest_proto3.pb.h" +#include #define LITE_TEST_NAME Proto3LiteTest #define UNITTEST ::proto3_unittest // Must include after the above macros. -#include "google/protobuf/proto3_lite_unittest.inc" +#include // Make extract script happy. namespace google { diff --git a/libs/protobuf/src/google/protobuf/proto3_lite_unittest.inc b/libs/protobuf/src/google/protobuf/proto3_lite_unittest.inc index a60bb68..5878163 100644 --- a/libs/protobuf/src/google/protobuf/proto3_lite_unittest.inc +++ b/libs/protobuf/src/google/protobuf/proto3_lite_unittest.inc @@ -32,7 +32,8 @@ #include #include -#include "google/protobuf/arena.h" +#include +#include #include using UNITTEST::TestAllTypes; diff --git a/libs/protobuf/src/google/protobuf/reflection.h b/libs/protobuf/src/google/protobuf/reflection.h index df9e5a7..7b75a43 100644 --- a/libs/protobuf/src/google/protobuf/reflection.h +++ b/libs/protobuf/src/google/protobuf/reflection.h @@ -36,15 +36,15 @@ #include -#include "google/protobuf/message.h" -#include "google/protobuf/generated_enum_util.h" +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -565,6 +565,6 @@ struct RefTypeTraits< } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_REFLECTION_H__ diff --git a/libs/protobuf/src/google/protobuf/reflection_internal.h b/libs/protobuf/src/google/protobuf/reflection_internal.h index 5e2cfa0..f749c3e 100644 --- a/libs/protobuf/src/google/protobuf/reflection_internal.h +++ b/libs/protobuf/src/google/protobuf/reflection_internal.h @@ -31,10 +31,9 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__ #define GOOGLE_PROTOBUF_REFLECTION_INTERNAL_H__ -#include "absl/strings/cord.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/reflection_ops.cc b/libs/protobuf/src/google/protobuf/reflection_ops.cc index 0ef6c9a..3a1972e 100644 --- a/libs/protobuf/src/google/protobuf/reflection_ops.cc +++ b/libs/protobuf/src/google/protobuf/reflection_ops.cc @@ -31,22 +31,21 @@ // Author: kenton@google.com (Kenton Varda) // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/reflection_ops.h" +#include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -375,7 +374,7 @@ static std::string SubMessagePrefix(const std::string& prefix, } if (index != -1) { result.append("["); - result.append(absl::StrCat(index)); + result.append(StrCat(index)); result.append("]"); } result.append("."); @@ -457,4 +456,4 @@ void GenericSwap(Message* lhs, Message* rhs) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/reflection_ops.h b/libs/protobuf/src/google/protobuf/reflection_ops.h index b6f1bd2..0a45702 100644 --- a/libs/protobuf/src/google/protobuf/reflection_ops.h +++ b/libs/protobuf/src/google/protobuf/reflection_ops.h @@ -38,15 +38,15 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ #define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ -#include "google/protobuf/message.h" -#include "google/protobuf/port.h" +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -63,8 +63,6 @@ namespace internal { // This class is really a namespace that contains only static methods. class PROTOBUF_EXPORT ReflectionOps { public: - ReflectionOps() = delete; - static void Copy(const Message& from, Message* to); static void Merge(const Message& from, Message* to); static void Clear(Message* message); @@ -79,12 +77,16 @@ class PROTOBUF_EXPORT ReflectionOps { static void FindInitializationErrors(const Message& message, const std::string& prefix, std::vector* errors); + + private: + // All methods are static. No need to construct. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionOps); }; } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ diff --git a/libs/protobuf/src/google/protobuf/reflection_ops_unittest.cc b/libs/protobuf/src/google/protobuf/reflection_ops_unittest.cc index 282e4ae..513ce47 100644 --- a/libs/protobuf/src/google/protobuf/reflection_ops_unittest.cc +++ b/libs/protobuf/src/google/protobuf/reflection_ops_unittest.cc @@ -32,16 +32,17 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/reflection_ops.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/descriptor.h" +#include +#include +#include +#include +#include #include -#include "google/protobuf/test_util.h" +#include -#include "google/protobuf/stubs/strutil.h" +#include namespace google { namespace protobuf { @@ -459,7 +460,7 @@ TEST(ReflectionOpsTest, OneofIsInitialized) { static std::string FindInitializationErrors(const Message& message) { std::vector errors; ReflectionOps::FindInitializationErrors(message, "", &errors); - return absl::StrJoin(errors, ","); + return Join(errors, ","); } TEST(ReflectionOpsTest, FindInitializationErrors) { diff --git a/libs/protobuf/src/google/protobuf/reflection_tester.cc b/libs/protobuf/src/google/protobuf/reflection_tester.cc index 23084dc..4c6db03 100644 --- a/libs/protobuf/src/google/protobuf/reflection_tester.cc +++ b/libs/protobuf/src/google/protobuf/reflection_tester.cc @@ -28,14 +28,14 @@ // (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/reflection_tester.h" +#include #include -#include "google/protobuf/map_field.h" -#include "google/protobuf/message.h" +#include +#include // Must include last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -1670,4 +1670,4 @@ void MapReflectionTester::ExpectClearViaReflectionIterator(Message* message) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/reflection_tester.h b/libs/protobuf/src/google/protobuf/reflection_tester.h index 7a124af..3a2dc81 100644 --- a/libs/protobuf/src/google/protobuf/reflection_tester.h +++ b/libs/protobuf/src/google/protobuf/reflection_tester.h @@ -31,10 +31,10 @@ #ifndef GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ #define GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ -#include "google/protobuf/message.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -117,6 +117,6 @@ class MapReflectionTester { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_REFLECTION_TESTER_H__ diff --git a/libs/protobuf/src/google/protobuf/repeated_field.cc b/libs/protobuf/src/google/protobuf/repeated_field.cc index 9e1d419..7264d0a 100644 --- a/libs/protobuf/src/google/protobuf/repeated_field.cc +++ b/libs/protobuf/src/google/protobuf/repeated_field.cc @@ -32,16 +32,15 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/repeated_field.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "absl/strings/cord.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -69,4 +68,4 @@ template class PROTOBUF_EXPORT_TEMPLATE_DEFINE RepeatedIterator; } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/repeated_field.h b/libs/protobuf/src/google/protobuf/repeated_field.h index bc70129..3fb734e 100644 --- a/libs/protobuf/src/google/protobuf/repeated_field.h +++ b/libs/protobuf/src/google/protobuf/repeated_field.h @@ -52,17 +52,16 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_ptr_field.h" +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -95,41 +94,60 @@ constexpr int RepeatedFieldLowerClampLimit() { constexpr int kRepeatedFieldUpperClampLimit = (std::numeric_limits::max() / 2) + 1; -// Swaps two blocks of memory of size kSize: -template -void memswap(char* a, char* b) { -#if __SIZEOF_INT128__ - using Buffer = __uint128_t; -#else - using Buffer = uint64_t; -#endif +template +inline int CalculateReserve(Iter begin, Iter end, std::forward_iterator_tag) { + return static_cast(std::distance(begin, end)); +} - constexpr size_t kBlockSize = sizeof(Buffer); - Buffer buf; - for (size_t i = 0; i < kSize / kBlockSize; ++i) { - memcpy(&buf, a, kBlockSize); - memcpy(a, b, kBlockSize); - memcpy(b, &buf, kBlockSize); - a += kBlockSize; - b += kBlockSize; +template +inline int CalculateReserve(Iter /*begin*/, Iter /*end*/, + std::input_iterator_tag /*unused*/) { + return -1; +} + +template +inline int CalculateReserve(Iter begin, Iter end) { + typedef typename std::iterator_traits::iterator_category Category; + return CalculateReserve(begin, end, Category()); +} + +// Swaps two blocks of memory of size sizeof(T). +template +inline void SwapBlock(char* p, char* q) { + T tmp; + memcpy(&tmp, p, sizeof(T)); + memcpy(p, q, sizeof(T)); + memcpy(q, &tmp, sizeof(T)); +} + +// Swaps two blocks of memory of size kSize: +// template void memswap(char* p, char* q); +template +inline typename std::enable_if<(kSize == 0), void>::type memswap(char*, char*) { +} + +#define PROTO_MEMSWAP_DEF_SIZE(reg_type, max_size) \ + template \ + typename std::enable_if<(kSize >= sizeof(reg_type) && kSize < (max_size)), \ + void>::type \ + memswap(char* p, char* q) { \ + SwapBlock(p, q); \ + memswap(p + sizeof(reg_type), \ + q + sizeof(reg_type)); \ } -#if defined(__GNUC__) && !defined(__clang__) - // Workaround GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpragmas" -#pragma GCC diagnostic ignored "-Wstringop-overflow" -#endif // __GNUC__ +PROTO_MEMSWAP_DEF_SIZE(uint8_t, 2) +PROTO_MEMSWAP_DEF_SIZE(uint16_t, 4) +PROTO_MEMSWAP_DEF_SIZE(uint32_t, 8) - // Swap the leftover bytes, could be zero. - memcpy(&buf, a, kSize % kBlockSize); - memcpy(a, b, kSize % kBlockSize); - memcpy(b, &buf, kSize % kBlockSize); +#ifdef __SIZEOF_INT128__ +PROTO_MEMSWAP_DEF_SIZE(uint64_t, 16) +PROTO_MEMSWAP_DEF_SIZE(__uint128_t, (1u << 31)) +#else +PROTO_MEMSWAP_DEF_SIZE(uint64_t, (1u << 31)) +#endif -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif // GCC -} +#undef PROTO_MEMSWAP_DEF_SIZE template class RepeatedIterator; @@ -228,10 +246,16 @@ class RepeatedField final { Element* mutable_data(); const Element* data() const; - // Swaps entire contents with "other". If they are separate arenas, then + // Swaps entire contents with "other". If they are separate arenas then, // copies data between each other. void Swap(RepeatedField* other); + // Swaps entire contents with "other". Should be called only if the caller can + // guarantee that both repeated fields are on the same arena or are on the + // heap. Swapping between different arenas is disallowed and caught by a + // GOOGLE_DCHECK (see API docs for details). + void UnsafeArenaSwap(RepeatedField* other); + // Swaps two elements. void SwapElements(int index1, int index2); @@ -289,14 +313,8 @@ class RepeatedField final { iterator erase(const_iterator first, const_iterator last); // Gets the Arena on which this RepeatedField stores its elements. - // Message-owned arenas are not exposed by this method, which will return - // nullptr for messages owned by MOAs. inline Arena* GetArena() const { - Arena* arena = GetOwningArena(); - if (arena == nullptr || arena->InternalIsMessageOwnedArena()) { - return nullptr; - } - return arena; + return GetOwningArena(); } // For internal use only. @@ -304,7 +322,6 @@ class RepeatedField final { // This is public due to it being called by generated code. inline void InternalSwap(RepeatedField* other); - private: template friend class Arena::InternalHelper; @@ -314,12 +331,6 @@ class RepeatedField final { : rep()->arena; } - // Swaps entire contents with "other". Should be called only if the caller can - // guarantee that both repeated fields are on the same arena or are on the - // heap. Swapping between different arenas is disallowed and caught by a - // GOOGLE_DCHECK (see API docs for details). - void UnsafeArenaSwap(RepeatedField* other); - static constexpr int kInitialSize = 0; // A note on the representation here (see also comment below for // RepeatedPtrFieldBase's struct Rep): @@ -333,16 +344,6 @@ class RepeatedField final { // RepeatedField class to avoid costly cache misses due to the indirection. int current_size_; int total_size_; - - // Replaces current_size_ with new_size and returns the previous value of - // current_size_. This function is intended to be the only place where - // current_size_ is modified. - inline int ExchangeCurrentSize(int new_size) { - const int prev_size = current_size_; - current_size_ = new_size; - return prev_size; - } - // Pad the Rep after arena allow for power-of-two byte sizes when // sizeof(Element) > sizeof(Arena*). eg for 16-byte objects. static PROTOBUF_CONSTEXPR const size_t kRepHeaderSize = @@ -355,7 +356,6 @@ class RepeatedField final { } }; - // If total_size_ == 0 this points to an Arena otherwise it points to the // elements member of a Rep struct. Using this invariant allows the storage of // the arena pointer without an extra allocation in the constructor. @@ -448,13 +448,8 @@ class RepeatedField final { // // Typically, due to the fact that adder is a local stack variable, the // compiler will be successful in mem-to-reg transformation and the machine - // code will be - // loop: - // cmp %size, %capacity - // jae fallback - // mov dword ptr [%buffer + %size * 4], %val - // inc %size - // jmp loop + // code will be loop: cmp %size, %capacity jae fallback mov dword ptr [%buffer + // + %size * 4], %val inc %size jmp loop // // The first version executes at 7 cycles per iteration while the second // version executes at only 1 or 2 cycles. @@ -466,11 +461,7 @@ class RepeatedField final { capacity_ = repeated_field_->total_size_; buffer_ = repeated_field_->unsafe_elements(); } - FastAdderImpl(const FastAdderImpl&) = delete; - FastAdderImpl& operator=(const FastAdderImpl&) = delete; - ~FastAdderImpl() { - repeated_field_->current_size_ = index_; - } + ~FastAdderImpl() { repeated_field_->current_size_ = index_; } void Add(Element val) { if (index_ == capacity_) { @@ -487,6 +478,8 @@ class RepeatedField final { int index_; int capacity_; Element* buffer_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FastAdderImpl); }; // FastAdder is a wrapper for adding fields. The specialization above handles @@ -495,12 +488,11 @@ class RepeatedField final { class FastAdderImpl { public: explicit FastAdderImpl(RepeatedField* rf) : repeated_field_(rf) {} - FastAdderImpl(const FastAdderImpl&) = delete; - FastAdderImpl& operator=(const FastAdderImpl&) = delete; void Add(const Element& val) { repeated_field_->Add(val); } private: RepeatedField* repeated_field_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FastAdderImpl); }; using FastAdder = FastAdderImpl<>; @@ -624,13 +616,13 @@ inline int RepeatedField::Capacity() const { template inline void RepeatedField::AddAlreadyReserved(const Element& value) { GOOGLE_DCHECK_LT(current_size_, total_size_); - elements()[ExchangeCurrentSize(current_size_ + 1)] = value; + elements()[current_size_++] = value; } template inline Element* RepeatedField::AddAlreadyReserved() { GOOGLE_DCHECK_LT(current_size_, total_size_); - return &elements()[ExchangeCurrentSize(current_size_ + 1)]; + return &elements()[current_size_++]; } template @@ -641,7 +633,9 @@ inline Element* RepeatedField::AddNAlreadyReserved(int elements) { // total_size_ == 0. In this case the return pointer points to a zero size // array (n == 0). Hence we can just use unsafe_elements(), because the user // cannot dereference the pointer anyway. - return unsafe_elements() + ExchangeCurrentSize(current_size_ + elements); + Element* ret = unsafe_elements() + current_size_; + current_size_ += elements; + return ret; } template @@ -649,11 +643,9 @@ inline void RepeatedField::Resize(int new_size, const Element& value) { GOOGLE_DCHECK_GE(new_size, 0); if (new_size > current_size_) { Reserve(new_size); - std::fill(&elements()[ExchangeCurrentSize(new_size)], &elements()[new_size], - value); - } else { - ExchangeCurrentSize(new_size); + std::fill(&elements()[current_size_], &elements()[new_size], value); } + current_size_ = new_size; } template @@ -693,41 +685,46 @@ inline void RepeatedField::Set(int index, const Element& value) { template inline void RepeatedField::Add(const Element& value) { - if (current_size_ == total_size_) { + uint32_t size = current_size_; + if (static_cast(size) == total_size_) { // value could reference an element of the array. Reserving new space will // invalidate the reference. So we must make a copy first. auto tmp = value; Reserve(total_size_ + 1); - elements()[ExchangeCurrentSize(current_size_ + 1)] = std::move(tmp); + elements()[size] = std::move(tmp); } else { - elements()[ExchangeCurrentSize(current_size_ + 1)] = value; + elements()[size] = value; } + current_size_ = size + 1; } template inline Element* RepeatedField::Add() { - if (current_size_ == total_size_) Reserve(total_size_ + 1); - return &elements()[ExchangeCurrentSize(current_size_ + 1)]; + uint32_t size = current_size_; + if (static_cast(size) == total_size_) Reserve(total_size_ + 1); + auto ptr = &elements()[size]; + current_size_ = size + 1; + return ptr; } template template inline void RepeatedField::Add(Iter begin, Iter end) { - if (std::is_base_of< - std::forward_iterator_tag, - typename std::iterator_traits::iterator_category>::value) { - int additional = static_cast(std::distance(begin, end)); - if (additional == 0) return; + int reserve = internal::CalculateReserve(begin, end); + if (reserve != -1) { + if (reserve == 0) { + return; + } - int new_size = current_size_ + additional; - Reserve(new_size); + Reserve(reserve + size()); // TODO(ckennelly): The compiler loses track of the buffer freshly // allocated by Reserve() by the time we call elements, so it cannot // guarantee that elements does not alias [begin(), end()). // // If restrict is available, annotating the pointer obtained from elements() // causes this to lower to memcpy instead of memmove. - std::copy(begin, end, elements() + ExchangeCurrentSize(new_size)); + std::copy(begin, end, elements() + size()); + current_size_ = reserve + size(); } else { FastAdder fast_adder(this); for (; begin != end; ++begin) fast_adder.Add(*begin); @@ -737,7 +734,7 @@ inline void RepeatedField::Add(Iter begin, Iter end) { template inline void RepeatedField::RemoveLast() { GOOGLE_DCHECK_GT(current_size_, 0); - ExchangeCurrentSize(current_size_ - 1); + current_size_--; } template @@ -762,7 +759,7 @@ void RepeatedField::ExtractSubrange(int start, int num, template inline void RepeatedField::Clear() { - ExchangeCurrentSize(0); + current_size_ = 0; } template @@ -983,7 +980,7 @@ template inline void RepeatedField::Truncate(int new_size) { GOOGLE_DCHECK_LE(new_size, current_size_); if (current_size_ > 0) { - ExchangeCurrentSize(new_size); + current_size_ = new_size; } } @@ -1217,6 +1214,6 @@ extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE RepeatedIterator; } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__ diff --git a/libs/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc b/libs/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc index 2d30578..25e8200 100644 --- a/libs/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/libs/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -33,27 +33,25 @@ // Test reflection methods for aggregate access to Repeated[Ptr]Fields. // This test proto2 methods on a proto2 layout. -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/reflection.h" +#include +#include +#include +#include #include -#include "absl/base/casts.h" -#include "absl/strings/cord.h" -#include "google/protobuf/port.h" -#include "google/protobuf/test_util.h" +#include namespace google { namespace protobuf { -namespace { -using internal::DownCast; using unittest::ForeignMessage; using unittest::TestAllExtensions; using unittest::TestAllTypes; +namespace { + static int Func(int i, int j) { return i * j; } -static std::string StrFunc(int i, int j) { return absl::StrCat(Func(i, 4)); } +static std::string StrFunc(int i, int j) { return StrCat(Func(i, 4)); } TEST(RepeatedFieldReflectionTest, RegularFields) { TestAllTypes message; @@ -115,7 +113,7 @@ TEST(RepeatedFieldReflectionTest, RegularFields) { EXPECT_EQ(rf_double.Get(i), Func(i, 2)); EXPECT_EQ(rpf_string.Get(i), StrFunc(i, 5)); EXPECT_EQ(rpf_foreign_message.Get(i).c(), Func(i, 6)); - EXPECT_EQ(DownCast(&rpf_message.Get(i))->c(), + EXPECT_EQ(down_cast(&rpf_message.Get(i))->c(), Func(i, 6)); // Check gets through mutable objects. @@ -123,7 +121,7 @@ TEST(RepeatedFieldReflectionTest, RegularFields) { EXPECT_EQ(mrf_double->Get(i), Func(i, 2)); EXPECT_EQ(mrpf_string->Get(i), StrFunc(i, 5)); EXPECT_EQ(mrpf_foreign_message->Get(i).c(), Func(i, 6)); - EXPECT_EQ(DownCast(&mrpf_message->Get(i))->c(), + EXPECT_EQ(down_cast(&mrpf_message->Get(i))->c(), Func(i, 6)); // Check sets through mutable objects. @@ -135,7 +133,7 @@ TEST(RepeatedFieldReflectionTest, RegularFields) { EXPECT_EQ(message.repeated_double(i), Func(i, -2)); EXPECT_EQ(message.repeated_string(i), StrFunc(i, -5)); EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, -6)); - DownCast(mrpf_message->Mutable(i))->set_c(Func(i, 7)); + down_cast(mrpf_message->Mutable(i))->set_c(Func(i, 7)); EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); } @@ -295,7 +293,7 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { ForeignMessage scratch_space; EXPECT_EQ(rf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); EXPECT_EQ( - DownCast(rf_message.Get(i, &scratch_space)).c(), + down_cast(rf_message.Get(i, &scratch_space)).c(), Func(i, 6)); // Check gets through mutable objects. @@ -304,7 +302,8 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { EXPECT_EQ(mrf_string.Get(i), StrFunc(i, 5)); EXPECT_EQ(mrf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); EXPECT_EQ( - DownCast(mrf_message.Get(i, &scratch_space)).c(), + down_cast(mrf_message.Get(i, &scratch_space)) + .c(), Func(i, 6)); // Check sets through mutable objects. diff --git a/libs/protobuf/src/google/protobuf/repeated_field_unittest.cc b/libs/protobuf/src/google/protobuf/repeated_field_unittest.cc index 6f91b16..d8a82bf 100644 --- a/libs/protobuf/src/google/protobuf/repeated_field_unittest.cc +++ b/libs/protobuf/src/google/protobuf/repeated_field_unittest.cc @@ -35,7 +35,7 @@ // TODO(kenton): Improve this unittest to bring it up to the standards of // other proto2 unittests. -#include "google/protobuf/repeated_field.h" +#include #include #include @@ -47,18 +47,17 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/unittest.pb.h" +#include +#include +#include +#include #include +#include #include -#include "absl/numeric/bits.h" -#include "absl/strings/cord.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/stubs/strutil.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -180,7 +179,7 @@ void CheckAllocationSizes(bool is_ptr) { // Must be `>= 16`, as expected by the Arena. ASSERT_GE(last_alloc, 16); // Must be of a power of two. - size_t log2 = absl::bit_width(last_alloc) - 1; + size_t log2 = Bits::Log2FloorNonZero64(last_alloc); ASSERT_EQ((1 << log2), last_alloc); } @@ -306,60 +305,6 @@ TEST(RepeatedField, SwapLargeLarge) { } } -template -void TestMemswap() { - SCOPED_TRACE(kSize); - - const auto a_char = [](int i) -> char { return (i % ('z' - 'a')) + 'a'; }; - const auto b_char = [](int i) -> char { return (i % ('Z' - 'A')) + 'A'; }; - std::string a, b; - for (int i = 0; i < kSize; ++i) { - a += a_char(i); - b += b_char(i); - } - // We will not swap these. - a += "+"; - b += "-"; - - std::string expected_a = b, expected_b = a; - expected_a.back() = '+'; - expected_b.back() = '-'; - - internal::memswap(&a[0], &b[0]); - - // ODR use the functions in a way that forces the linker to keep them. That - // way we can see their generated code. - volatile auto odr_use_for_asm_dump = &internal::memswap; - (void)odr_use_for_asm_dump; - - EXPECT_EQ(expected_a, a); - EXPECT_EQ(expected_b, b); -} - -TEST(Memswap, VerifyWithSmallAndLargeSizes) { - // Arbitrary sizes - TestMemswap<0>(); - TestMemswap<1>(); - TestMemswap<10>(); - TestMemswap<100>(); - TestMemswap<1000>(); - TestMemswap<10000>(); - TestMemswap<100000>(); - TestMemswap<1000000>(); - - // Pointer aligned sizes - TestMemswap(); - TestMemswap(); - TestMemswap(); - TestMemswap(); - - // Test also just the block size and no leftover. - TestMemswap<64 * 1>(); - TestMemswap<64 * 2>(); - TestMemswap<64 * 3>(); - TestMemswap<64 * 4>(); -} - // Determines how much space was reserved by the given field by adding elements // to it until it re-allocates its space. static int ReservedSpace(RepeatedField* field) { @@ -429,14 +374,14 @@ TEST(RepeatedField, ReserveNothing) { TEST(RepeatedField, ReserveLowerClamp) { int clamped_value = internal::CalculateReserveSize(0, 1); - EXPECT_GE(clamped_value, sizeof(void*) / sizeof(bool)); + EXPECT_GE(clamped_value, 8 / sizeof(bool)); EXPECT_EQ((internal::RepeatedFieldLowerClampLimit()), clamped_value); // EXPECT_EQ(clamped_value, (internal::CalculateReserveSize( clamped_value, 2))); clamped_value = internal::CalculateReserveSize(0, 1); - EXPECT_GE(clamped_value, sizeof(void*) / sizeof(int)); + EXPECT_GE(clamped_value, 8 / sizeof(int)); EXPECT_EQ((internal::RepeatedFieldLowerClampLimit()), clamped_value); // EXPECT_EQ(clamped_value, (internal::CalculateReserveSize me; - me.Add(0); std::stringstream ss; ss << 1 << ' ' << 2; me.Add(std::istream_iterator(ss), std::istream_iterator()); - ASSERT_EQ(me.size(), 3); - ASSERT_EQ(me.Get(0), 0); - ASSERT_EQ(me.Get(1), 1); - ASSERT_EQ(me.Get(2), 2); + ASSERT_EQ(me.size(), 2); + ASSERT_EQ(me.Get(0), 1); + ASSERT_EQ(me.Get(1), 2); } TEST(RepeatedField, AddAndAssignRanges) { @@ -1315,7 +1258,7 @@ TEST(RepeatedPtrField, ClearedElements) { field.Clear(); EXPECT_EQ(field.ClearedCount(), 2); -#ifndef PROTOBUF_FUTURE_REMOVE_CLEARED_API +#ifndef PROTOBUF_FUTURE_BREAKING_CHANGES EXPECT_EQ(field.ReleaseCleared(), original); // Take ownership again. EXPECT_EQ(field.ClearedCount(), 1); EXPECT_NE(field.Add(), original); @@ -1327,7 +1270,7 @@ TEST(RepeatedPtrField, ClearedElements) { EXPECT_EQ(field.ClearedCount(), 1); EXPECT_EQ(field.Add(), original); EXPECT_EQ(field.ClearedCount(), 0); -#endif // !PROTOBUF_FUTURE_REMOVE_CLEARED_API +#endif // !PROTOBUF_FUTURE_BREAKING_CHANGES } // Test all code paths in AddAllocated(). @@ -2334,11 +2277,11 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, TestAllTypes goldenproto; for (int i = 0; i < 10; ++i) { std::string* new_data = new std::string; - *new_data = "name-" + absl::StrCat(i); + *new_data = "name-" + StrCat(i); data.push_back(new_data); new_data = goldenproto.add_repeated_string(); - *new_data = "name-" + absl::StrCat(i); + *new_data = "name-" + StrCat(i); } TestAllTypes testproto; std::copy(data.begin(), data.end(), @@ -2371,7 +2314,7 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, auto* goldenproto = Arena::CreateMessage(&arena); for (int i = 0; i < 10; ++i) { auto* new_data = goldenproto->add_repeated_string(); - *new_data = "name-" + absl::StrCat(i); + *new_data = "name-" + StrCat(i); data.push_back(new_data); } auto* testproto = Arena::CreateMessage(&arena); @@ -2417,4 +2360,4 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, MoveProtos) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/repeated_ptr_field.cc b/libs/protobuf/src/google/protobuf/repeated_ptr_field.cc index 1661474..8e86727 100644 --- a/libs/protobuf/src/google/protobuf/repeated_ptr_field.cc +++ b/libs/protobuf/src/google/protobuf/repeated_ptr_field.cc @@ -34,14 +34,14 @@ #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/implicit_weak_message.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -116,7 +116,7 @@ void* RepeatedPtrFieldBase::AddOutOfLineHelper(void* obj) { InternalExtend(1); // Equivalent to "Reserve(total_size_ + 1)" } ++rep_->allocated_size; - rep_->elements[ExchangeCurrentSize(current_size_ + 1)] = obj; + rep_->elements[current_size_++] = obj; return obj; } @@ -125,14 +125,13 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) { // Close up a gap of "num" elements starting at offset "start". for (int i = start + num; i < rep_->allocated_size; ++i) rep_->elements[i - num] = rep_->elements[i]; - ExchangeCurrentSize(current_size_ - num); + current_size_ -= num; rep_->allocated_size -= num; } MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { if (rep_ != nullptr && current_size_ < rep_->allocated_size) { - return reinterpret_cast( - rep_->elements[ExchangeCurrentSize(current_size_ + 1)]); + return reinterpret_cast(rep_->elements[current_size_++]); } if (!rep_ || rep_->allocated_size == total_size_) { Reserve(total_size_ + 1); @@ -141,7 +140,7 @@ MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { MessageLite* result = prototype ? prototype->New(arena_) : Arena::CreateMessage(arena_); - rep_->elements[ExchangeCurrentSize(current_size_ + 1)] = result; + rep_->elements[current_size_++] = result; return result; } @@ -150,4 +149,4 @@ MessageLite* RepeatedPtrFieldBase::AddWeak(const MessageLite* prototype) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/repeated_ptr_field.h b/libs/protobuf/src/google/protobuf/repeated_ptr_field.h index 706a005..401230b 100644 --- a/libs/protobuf/src/google/protobuf/repeated_ptr_field.h +++ b/libs/protobuf/src/google/protobuf/repeated_ptr_field.h @@ -58,16 +58,15 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/port.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -211,8 +210,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { typename TypeHandler::Type* Add( const typename TypeHandler::Type* prototype = nullptr) { if (rep_ != nullptr && current_size_ < rep_->allocated_size) { - return cast( - rep_->elements[ExchangeCurrentSize(current_size_ + 1)]); + return cast(rep_->elements[current_size_++]); } typename TypeHandler::Type* result = TypeHandler::NewFromPrototype(prototype, arena_); @@ -225,9 +223,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { typename std::enable_if::type* = nullptr> inline void Add(typename TypeHandler::Type&& value) { if (rep_ != nullptr && current_size_ < rep_->allocated_size) { - *cast( - rep_->elements[ExchangeCurrentSize(current_size_ + 1)]) = - std::move(value); + *cast(rep_->elements[current_size_++]) = std::move(value); return; } if (!rep_ || rep_->allocated_size == total_size_) { @@ -236,7 +232,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ++rep_->allocated_size; typename TypeHandler::Type* result = TypeHandler::New(arena_, std::move(value)); - rep_->elements[ExchangeCurrentSize(current_size_ + 1)] = result; + rep_->elements[current_size_++] = result; } template @@ -287,7 +283,12 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { const int n = current_size_; GOOGLE_DCHECK_GE(n, 0); if (n > 0) { - ClearNonEmpty(); + void* const* elements = rep_->elements; + int i = 0; + do { + TypeHandler::Clear(cast(elements[i++])); + } while (i < n); + current_size_ = 0; } } @@ -316,40 +317,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { std::tie(arena_, current_size_, total_size_, rep_) = temp; } - // Prepares the container for adding elements via `AddAllocatedForParse`. - // It ensures some invariants to avoid checking then in the Add loop: - // - rep_ is not null. - // - there are no preallocated elements. - // Returns true if the invariants hold and `AddAllocatedForParse` can be - // used. - bool PrepareForParse() { - if (current_size_ == total_size_) { - InternalExtend(1); - } - return rep_->allocated_size == current_size_; - } - - // Similar to `AddAllocated` but faster. - // Can only be invoked after a call to `PrepareForParse` that returned `true`, - // or other calls to `AddAllocatedForParse`. - template - void AddAllocatedForParse(typename TypeHandler::Type* value) { - PROTOBUF_ASSUME(rep_ != nullptr); - PROTOBUF_ASSUME(current_size_ == rep_->allocated_size); - if (current_size_ == total_size_) { - // The array is completely full with no cleared objects, so grow it. - InternalExtend(1); - } - rep_->elements[current_size_++] = value; - ++rep_->allocated_size; - } - protected: template void RemoveLast() { GOOGLE_DCHECK_GT(current_size_, 0); - ExchangeCurrentSize(current_size_ - 1); - TypeHandler::Clear(cast(rep_->elements[current_size_])); + TypeHandler::Clear(cast(rep_->elements[--current_size_])); } template @@ -431,8 +403,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template typename TypeHandler::Type* AddFromCleared() { if (rep_ != nullptr && current_size_ < rep_->allocated_size) { - return cast( - rep_->elements[ExchangeCurrentSize(current_size_ + 1)]); + return cast(rep_->elements[current_size_++]); } else { return nullptr; } @@ -468,7 +439,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ++rep_->allocated_size; } - rep_->elements[ExchangeCurrentSize(current_size_ + 1)] = value; + rep_->elements[current_size_++] = value; } template @@ -483,9 +454,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template typename TypeHandler::Type* UnsafeArenaReleaseLast() { GOOGLE_DCHECK_GT(current_size_, 0); - ExchangeCurrentSize(current_size_ - 1); typename TypeHandler::Type* result = - cast(rep_->elements[current_size_]); + cast(rep_->elements[--current_size_]); --rep_->allocated_size; if (current_size_ < rep_->allocated_size) { // There are cleared elements on the end; replace the removed element @@ -538,7 +508,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // allocated list. elems[rep_->allocated_size] = elems[current_size_]; } - elems[ExchangeCurrentSize(current_size_ + 1)] = value; + elems[current_size_] = value; + current_size_ = current_size_ + 1; rep_->allocated_size = rep_->allocated_size + 1; } else { AddAllocatedSlowWithCopy(value, element_arena, arena); @@ -560,7 +531,8 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // allocated list. elems[rep_->allocated_size] = elems[current_size_]; } - elems[ExchangeCurrentSize(current_size_ + 1)] = value; + elems[current_size_] = value; + current_size_ = current_size_ + 1; ++rep_->allocated_size; } else { UnsafeArenaAddAllocated(value); @@ -640,16 +612,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { temp.Destroy(); // Frees rep_ if `other` had no arena. } - // Gets the Arena on which this RepeatedPtrField stores its elements. - // Message-owned arenas are not exposed by this method, which will return - // nullptr for messages owned by MOAs. - inline Arena* GetArena() const { - Arena* arena = GetOwningArena(); - if (arena == nullptr || arena->InternalIsMessageOwnedArena()) { - return nullptr; - } - return arena; - } + inline Arena* GetArena() const { return arena_; } protected: inline Arena* GetOwningArena() const { return arena_; } @@ -672,16 +635,6 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { Arena* arena_; int current_size_; int total_size_; - - // Replaces current_size_ with new_size and returns the previous value of - // current_size_. This function is intended to be the only place where - // current_size_ is modified. - inline int ExchangeCurrentSize(int new_size) { - int prev_size = current_size_; - current_size_ = new_size; - return prev_size; - } - struct Rep { int allocated_size; // Here we declare a huge array as a way of approximating C's "flexible @@ -701,26 +654,12 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return reinterpret_cast(element); } - // Out-of-line helper routine for Clear() once the inlined check has - // determined the container is non-empty - template - PROTOBUF_NOINLINE void ClearNonEmpty() { - const int n = current_size_; - void* const* elements = rep_->elements; - int i = 0; - GOOGLE_DCHECK_GT(n, - 0); // do/while loop to avoid initial test because we know n > 0 - do { - TypeHandler::Clear(cast(elements[i++])); - } while (i < n); - ExchangeCurrentSize(0); - } - // Non-templated inner function to avoid code duplication. Takes a function // pointer to the type-specific (templated) inner allocate/merge loop. - PROTOBUF_NOINLINE void MergeFromInternal( - const RepeatedPtrFieldBase& other, - void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)) { + void MergeFromInternal(const RepeatedPtrFieldBase& other, + void (RepeatedPtrFieldBase::*inner_loop)(void**, + void**, int, + int)) { // Note: wrapper has already guaranteed that other.rep_ != nullptr here. int other_size = other.current_size_; void** other_elements = other.rep_->elements; @@ -728,7 +667,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { int allocated_elems = rep_->allocated_size - current_size_; (this->*inner_loop)(new_elements, other_elements, other_size, allocated_elems); - ExchangeCurrentSize(current_size_ + other_size); + current_size_ += other_size; if (rep_->allocated_size < current_size_) { rep_->allocated_size = current_size_; } @@ -823,7 +762,7 @@ class GenericTypeHandler { } } static inline Arena* GetOwningArena(GenericType* value) { - return Arena::InternalGetOwningArena(value); + return Arena::GetOwningArena(value); } static inline void Clear(GenericType* value) { value->Clear(); } @@ -881,10 +820,10 @@ class StringTypeHandler { typedef std::string Type; using Movable = IsMovable; - static PROTOBUF_NOINLINE std::string* New(Arena* arena) { + static inline std::string* New(Arena* arena) { return Arena::Create(arena); } - static PROTOBUF_NOINLINE std::string* New(Arena* arena, std::string&& value) { + static inline std::string* New(Arena* arena, std::string&& value) { return Arena::Create(arena, std::move(value)); } static inline std::string* NewFromPrototype(const std::string*, @@ -1144,7 +1083,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // Gets the number of cleared objects that are currently being kept // around for reuse. int ClearedCount() const; -#ifndef PROTOBUF_FUTURE_REMOVE_CLEARED_API +#ifndef PROTOBUF_FUTURE_BREAKING_CHANGES // Adds an element to the pool of cleared objects, passing ownership to // the RepeatedPtrField. The element must be cleared prior to calling // this method. @@ -1159,7 +1098,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // This method cannot be called when the repeated field is on an arena; doing // so will trigger a GOOGLE_DCHECK-failure. PROTOBUF_NODISCARD Element* ReleaseCleared(); -#endif // !PROTOBUF_FUTURE_REMOVE_CLEARED_API +#endif // !PROTOBUF_FUTURE_BREAKING_CHANGES // Removes the element referenced by position. // @@ -1202,12 +1141,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void ExtractSubrangeInternal(int start, int num, Element** elements, std::false_type); - void AddAllocatedForParse(Element* p) { - return RepeatedPtrFieldBase::AddAllocatedForParse(p); - } - friend class Arena; - friend class internal::TcParser; template friend struct WeakRepeatedPtrField; @@ -1336,7 +1270,7 @@ inline Element* RepeatedPtrField::Mutable(int index) { } template -PROTOBUF_NOINLINE Element* RepeatedPtrField::Add() { +inline Element* RepeatedPtrField::Add() { return RepeatedPtrFieldBase::Add(); } @@ -1351,7 +1285,7 @@ inline void RepeatedPtrField::Add(Iter begin, Iter end) { if (std::is_base_of< std::forward_iterator_tag, typename std::iterator_traits::iterator_category>::value) { - int reserve = static_cast(std::distance(begin, end)); + int reserve = std::distance(begin, end); Reserve(size() + reserve); } for (; begin != end; ++begin) { @@ -1496,8 +1430,8 @@ RepeatedPtrField::erase(const_iterator position) { template inline typename RepeatedPtrField::iterator RepeatedPtrField::erase(const_iterator first, const_iterator last) { - size_type pos_offset = static_cast(std::distance(cbegin(), first)); - size_type last_offset = static_cast(std::distance(cbegin(), last)); + size_type pos_offset = std::distance(cbegin(), first); + size_type last_offset = std::distance(cbegin(), last); DeleteSubrange(pos_offset, last_offset - pos_offset); return begin() + pos_offset; } @@ -1571,7 +1505,7 @@ inline int RepeatedPtrField::ClearedCount() const { return RepeatedPtrFieldBase::ClearedCount(); } -#ifndef PROTOBUF_FUTURE_REMOVE_CLEARED_API +#ifndef PROTOBUF_FUTURE_BREAKING_CHANGES template inline void RepeatedPtrField::AddCleared(Element* value) { return RepeatedPtrFieldBase::AddCleared(value); @@ -1581,7 +1515,7 @@ template inline Element* RepeatedPtrField::ReleaseCleared() { return RepeatedPtrFieldBase::ReleaseCleared(); } -#endif // !PROTOBUF_FUTURE_REMOVE_CLEARED_API +#endif // !PROTOBUF_FUTURE_BREAKING_CHANGES template inline void RepeatedPtrField::Reserve(int new_size) { @@ -2031,6 +1965,6 @@ extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__ diff --git a/libs/protobuf/src/google/protobuf/service.cc b/libs/protobuf/src/google/protobuf/service.cc index da1ae78..5394568 100644 --- a/libs/protobuf/src/google/protobuf/service.cc +++ b/libs/protobuf/src/google/protobuf/service.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/service.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/service.h b/libs/protobuf/src/google/protobuf/service.h index a512e71..d288eb5 100644 --- a/libs/protobuf/src/google/protobuf/service.h +++ b/libs/protobuf/src/google/protobuf/service.h @@ -102,17 +102,15 @@ #include - -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/port.h" +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -136,8 +134,6 @@ class Message; // message.h class PROTOBUF_EXPORT Service { public: inline Service() {} - Service(const Service&) = delete; - Service& operator=(const Service&) = delete; virtual ~Service(); // When constructing a stub, you may pass STUB_OWNS_CHANNEL as the second @@ -194,6 +190,9 @@ class PROTOBUF_EXPORT Service { const MethodDescriptor* method) const = 0; virtual const Message& GetResponsePrototype( const MethodDescriptor* method) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service); }; // An RpcController mediates a single method call. The primary purpose of @@ -207,8 +206,6 @@ class PROTOBUF_EXPORT Service { class PROTOBUF_EXPORT RpcController { public: inline RpcController() {} - RpcController(const RpcController&) = delete; - RpcController& operator=(const RpcController&) = delete; virtual ~RpcController(); // Client-side methods --------------------------------------------- @@ -259,6 +256,9 @@ class PROTOBUF_EXPORT RpcController { // // NotifyOnCancel() must be called no more than once per request. virtual void NotifyOnCancel(Closure* callback) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcController); }; // Abstract interface for an RPC channel. An RpcChannel represents a @@ -272,8 +272,6 @@ class PROTOBUF_EXPORT RpcController { class PROTOBUF_EXPORT RpcChannel { public: inline RpcChannel() {} - RpcChannel(const RpcChannel&) = delete; - RpcChannel& operator=(const RpcChannel&) = delete; virtual ~RpcChannel(); // Call the given method of the remote service. The signature of this @@ -284,11 +282,14 @@ class PROTOBUF_EXPORT RpcChannel { virtual void CallMethod(const MethodDescriptor* method, RpcController* controller, const Message* request, Message* response, Closure* done) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel); }; } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_SERVICE_H__ diff --git a/libs/protobuf/src/google/protobuf/source_context.pb.cc b/libs/protobuf/src/google/protobuf/source_context.pb.cc index ce0f339..e7525e9 100644 --- a/libs/protobuf/src/google/protobuf/source_context.pb.cc +++ b/libs/protobuf/src/google/protobuf/source_context.pb.cc @@ -1,110 +1,86 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -#include "google/protobuf/source_context.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR SourceContext::SourceContext( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.file_name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_._cached_size_)*/{}} {} struct SourceContextDefaultTypeInternal { - PROTOBUF_CONSTEXPR SourceContextDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR SourceContextDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~SourceContextDefaultTypeInternal() {} union { SourceContext _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceContextDefaultTypeInternal _SourceContext_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 SourceContextDefaultTypeInternal _SourceContext_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _impl_.file_name_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceContext)}, +const uint32_t TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::SourceContext, _impl_.file_name_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::SourceContext)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_SourceContext_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fsource_5fcontext_2eproto[] PROTOBUF_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\212\001\n\023com.google.protobufB\022Sou" - "rceContextProtoP\001Z6google.golang.org/pro" - "tobuf/types/known/sourcecontextpb\242\002\003GPB\252" - "\002\036Google.Protobuf.WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto = { - false, - false, - 240, - descriptor_table_protodef_google_2fprotobuf_2fsource_5fcontext_2eproto, - "google/protobuf/source_context.proto", - &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto, + &::PROTOBUF_NAMESPACE_ID::_SourceContext_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fsource_5fcontext_2eproto[] PROTOBUF_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\212\001\n\023com.google.protobufB\022Sou" + "rceContextProtoP\001Z6google.golang.org/pro" + "tobuf/types/known/sourcecontextpb\242\002\003GPB\252" + "\002\036Google.Protobuf.WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto = { + false, false, 240, descriptor_table_protodef_google_2fprotobuf_2fsource_5fcontext_2eproto, + "google/protobuf/source_context.proto", + &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fsource_5fcontext_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fsource_5fcontext_2eproto(&descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fsource_5fcontext_2eproto(&descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class SourceContext::_Internal { @@ -179,7 +155,6 @@ void SourceContext::Clear() { } const char* SourceContext::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -220,7 +195,6 @@ failure: uint8_t* SourceContext::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -244,7 +218,6 @@ uint8_t* SourceContext::_InternalSerialize( } size_t SourceContext::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext) size_t total_size = 0; @@ -272,7 +245,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*SourceContext::GetClassData() void SourceContext::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.SourceContext) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -307,11 +279,11 @@ void SourceContext::InternalSwap(SourceContext* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata SourceContext::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_getter, &descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto_once, file_level_metadata_google_2fprotobuf_2fsource_5fcontext_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -320,5 +292,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::SourceContext >(Arena* arena return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::SourceContext >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/source_context.pb.h b/libs/protobuf/src/google/protobuf/source_context.pb.h index 5517333..63e7d11 100644 --- a/libs/protobuf/src/google/protobuf/source_context.pb.h +++ b/libs/protobuf/src/google/protobuf/source_context.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/source_context.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fsource_5fcontext_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,23 +43,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fsource_5fcontext_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto; PROTOBUF_NAMESPACE_OPEN class SourceContext; struct SourceContextDefaultTypeInternal; PROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceContext* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceContext>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::SourceContext* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::SourceContext>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT SourceContext final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ { public: @@ -168,7 +159,7 @@ class PROTOBUF_EXPORT SourceContext final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.SourceContext"; } protected: @@ -219,17 +210,12 @@ class PROTOBUF_EXPORT SourceContext final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // SourceContext // string file_name = 1; @@ -256,11 +242,11 @@ inline const std::string& SourceContext::_internal_file_name() const { return _impl_.file_name_.Get(); } inline void SourceContext::_internal_set_file_name(const std::string& value) { - + _impl_.file_name_.Set(value, GetArenaForAllocation()); } inline std::string* SourceContext::_internal_mutable_file_name() { - + return _impl_.file_name_.Mutable(GetArenaForAllocation()); } inline std::string* SourceContext::release_file_name() { @@ -268,6 +254,11 @@ inline std::string* SourceContext::release_file_name() { return _impl_.file_name_.Release(); } inline void SourceContext::set_allocated_file_name(std::string* file_name) { + if (file_name != nullptr) { + + } else { + + } _impl_.file_name_.SetAllocated(file_name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.file_name_.IsDefault()) { @@ -278,15 +269,14 @@ inline void SourceContext::set_allocated_file_name(std::string* file_name) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fsource_5fcontext_2eproto diff --git a/libs/protobuf/src/google/protobuf/string_member_robber.h b/libs/protobuf/src/google/protobuf/string_member_robber.h index e16069a..a4c1051 100644 --- a/libs/protobuf/src/google/protobuf/string_member_robber.h +++ b/libs/protobuf/src/google/protobuf/string_member_robber.h @@ -34,8 +34,5 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" - #endif // GOOGLE_PROTOBUF_STRING_MEMBER_ROBBER_H__ diff --git a/libs/protobuf/src/google/protobuf/struct.pb.cc b/libs/protobuf/src/google/protobuf/struct.pb.cc index eb92db0..87c72d4 100644 --- a/libs/protobuf/src/google/protobuf/struct.pb.cc +++ b/libs/protobuf/src/google/protobuf/struct.pb.cc @@ -1,201 +1,168 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -#include "google/protobuf/struct.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Struct_FieldsEntry_DoNotUse::Struct_FieldsEntry_DoNotUse( ::_pbi::ConstantInitialized) {} struct Struct_FieldsEntry_DoNotUseDefaultTypeInternal { - PROTOBUF_CONSTEXPR Struct_FieldsEntry_DoNotUseDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR Struct_FieldsEntry_DoNotUseDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~Struct_FieldsEntry_DoNotUseDefaultTypeInternal() {} union { Struct_FieldsEntry_DoNotUse _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_FieldsEntry_DoNotUse_default_instance_; PROTOBUF_CONSTEXPR Struct::Struct( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.fields_)*/{::_pbi::ConstantInitialized()} , /*decltype(_impl_._cached_size_)*/{}} {} struct StructDefaultTypeInternal { - PROTOBUF_CONSTEXPR StructDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR StructDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~StructDefaultTypeInternal() {} union { Struct _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StructDefaultTypeInternal _Struct_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StructDefaultTypeInternal _Struct_default_instance_; PROTOBUF_CONSTEXPR Value::Value( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.kind_)*/{} , /*decltype(_impl_._cached_size_)*/{} , /*decltype(_impl_._oneof_case_)*/{}} {} struct ValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ValueDefaultTypeInternal() {} union { Value _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ValueDefaultTypeInternal _Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ValueDefaultTypeInternal _Value_default_instance_; PROTOBUF_CONSTEXPR ListValue::ListValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.values_)*/{} , /*decltype(_impl_._cached_size_)*/{}} {} struct ListValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR ListValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR ListValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~ListValueDefaultTypeInternal() {} union { ListValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListValueDefaultTypeInternal _ListValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ListValueDefaultTypeInternal _ListValue_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fstruct_2eproto[4]; static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2fstruct_2eproto[1]; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fstruct_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _has_bits_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, key_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, value_), - 0, - 1, - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, _impl_.fields_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _internal_metadata_), - ~0u, // no _extensions_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_._oneof_case_[0]), - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - ::_pbi::kInvalidFieldOffsetTag, - ::_pbi::kInvalidFieldOffsetTag, - ::_pbi::kInvalidFieldOffsetTag, - ::_pbi::kInvalidFieldOffsetTag, - ::_pbi::kInvalidFieldOffsetTag, - ::_pbi::kInvalidFieldOffsetTag, - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_.kind_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _impl_.values_), -}; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fstruct_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, 10, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse)}, - { 12, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Struct)}, - { 21, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Value)}, - { 36, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ListValue)}, +const uint32_t TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _has_bits_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, key_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse, value_), + 0, + 1, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Struct, _impl_.fields_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _internal_metadata_), + ~0u, // no _extensions_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_._oneof_case_[0]), + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + ::_pbi::kInvalidFieldOffsetTag, + ::_pbi::kInvalidFieldOffsetTag, + ::_pbi::kInvalidFieldOffsetTag, + ::_pbi::kInvalidFieldOffsetTag, + ::_pbi::kInvalidFieldOffsetTag, + ::_pbi::kInvalidFieldOffsetTag, + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_.kind_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::ListValue, _impl_.values_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, 8, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse)}, + { 10, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Struct)}, + { 17, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Value)}, + { 30, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::ListValue)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Struct_FieldsEntry_DoNotUse_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Struct_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Value_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_ListValue_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fstruct_2eproto[] PROTOBUF_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" - "sEntry\022\013\n\003key\030\001 \001(\t\022%\n\005value\030\002 \001(\0132\026.goo" - "gle.protobuf.Value:\0028\001\"\352\001\n\005Value\0220\n\nnull" - "_value\030\001 \001(\0162\032.google.protobuf.NullValue" - "H\000\022\026\n\014number_value\030\002 \001(\001H\000\022\026\n\014string_val" - "ue\030\003 \001(\tH\000\022\024\n\nbool_value\030\004 \001(\010H\000\022/\n\014stru" - "ct_value\030\005 \001(\0132\027.google.protobuf.StructH" - "\000\0220\n\nlist_value\030\006 \001(\0132\032.google.protobuf." - "ListValueH\000B\006\n\004kind\"3\n\tListValue\022&\n\006valu" - "es\030\001 \003(\0132\026.google.protobuf.Value*\033\n\tNull" - "Value\022\016\n\nNULL_VALUE\020\000B\177\n\023com.google.prot" - "obufB\013StructProtoP\001Z/google.golang.org/p" - "rotobuf/types/known/structpb\370\001\001\242\002\003GPB\252\002\036" - "Google.Protobuf.WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fstruct_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fstruct_2eproto = { - false, - false, - 638, - descriptor_table_protodef_google_2fprotobuf_2fstruct_2eproto, - "google/protobuf/struct.proto", - &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, - nullptr, - 0, - 4, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fstruct_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fstruct_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fstruct_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Struct_FieldsEntry_DoNotUse_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Struct_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Value_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_ListValue_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fstruct_2eproto[] PROTOBUF_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" + "sEntry\022\013\n\003key\030\001 \001(\t\022%\n\005value\030\002 \001(\0132\026.goo" + "gle.protobuf.Value:\0028\001\"\352\001\n\005Value\0220\n\nnull" + "_value\030\001 \001(\0162\032.google.protobuf.NullValue" + "H\000\022\026\n\014number_value\030\002 \001(\001H\000\022\026\n\014string_val" + "ue\030\003 \001(\tH\000\022\024\n\nbool_value\030\004 \001(\010H\000\022/\n\014stru" + "ct_value\030\005 \001(\0132\027.google.protobuf.StructH" + "\000\0220\n\nlist_value\030\006 \001(\0132\032.google.protobuf." + "ListValueH\000B\006\n\004kind\"3\n\tListValue\022&\n\006valu" + "es\030\001 \003(\0132\026.google.protobuf.Value*\033\n\tNull" + "Value\022\016\n\nNULL_VALUE\020\000B\177\n\023com.google.prot" + "obufB\013StructProtoP\001Z/google.golang.org/p" + "rotobuf/types/known/structpb\370\001\001\242\002\003GPB\252\002\036" + "Google.Protobuf.WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fstruct_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fstruct_2eproto = { + false, false, 638, descriptor_table_protodef_google_2fprotobuf_2fstruct_2eproto, + "google/protobuf/struct.proto", + &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, nullptr, 0, 4, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fstruct_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fstruct_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fstruct_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fstruct_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fstruct_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fstruct_2eproto(&descriptor_table_google_2fprotobuf_2fstruct_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fstruct_2eproto(&descriptor_table_google_2fprotobuf_2fstruct_2eproto); PROTOBUF_NAMESPACE_OPEN const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* NullValue_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2fstruct_2eproto); @@ -209,6 +176,8 @@ bool NullValue_IsValid(int value) { return false; } } + + // =================================================================== Struct_FieldsEntry_DoNotUse::Struct_FieldsEntry_DoNotUse() {} @@ -222,6 +191,7 @@ void Struct_FieldsEntry_DoNotUse::MergeFrom(const Struct_FieldsEntry_DoNotUse& o &descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, file_level_metadata_google_2fprotobuf_2fstruct_2eproto[0]); } + // =================================================================== class Struct::_Internal { @@ -294,7 +264,6 @@ void Struct::Clear() { } const char* Struct::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -338,7 +307,6 @@ failure: uint8_t* Struct::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -378,7 +346,6 @@ uint8_t* Struct::_InternalSerialize( } size_t Struct::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Struct) size_t total_size = 0; @@ -408,7 +375,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Struct::GetClassData() const { void Struct::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Struct) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -436,17 +402,15 @@ void Struct::InternalSwap(Struct* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Struct::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, file_level_metadata_google_2fprotobuf_2fstruct_2eproto[1]); } + // =================================================================== class Value::_Internal { public: - static constexpr int32_t kOneofCaseOffset = - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Value, _impl_._oneof_case_); static const ::PROTOBUF_NAMESPACE_ID::Struct& struct_value(const Value* msg); static const ::PROTOBUF_NAMESPACE_ID::ListValue& list_value(const Value* msg); }; @@ -621,7 +585,6 @@ void Value::Clear() { } const char* Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -630,7 +593,7 @@ const char* Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.NullValue null_value = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_null_value(static_cast<::PROTOBUF_NAMESPACE_ID::NullValue>(val)); } else @@ -703,7 +666,6 @@ failure: uint8_t* Value::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -760,7 +722,6 @@ uint8_t* Value::_InternalSerialize( } size_t Value::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Value) size_t total_size = 0; @@ -823,7 +784,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Value::GetClassData() const { void Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Value) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -882,11 +842,11 @@ void Value::InternalSwap(Value* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Value::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, file_level_metadata_google_2fprotobuf_2fstruct_2eproto[2]); } + // =================================================================== class ListValue::_Internal { @@ -949,7 +909,6 @@ void ListValue::Clear() { } const char* ListValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -993,7 +952,6 @@ failure: uint8_t* ListValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1015,7 +973,6 @@ uint8_t* ListValue::_InternalSerialize( } size_t ListValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ListValue) size_t total_size = 0; @@ -1043,7 +1000,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*ListValue::GetClassData() cons void ListValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ListValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1071,11 +1027,11 @@ void ListValue::InternalSwap(ListValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata ListValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fstruct_2eproto_getter, &descriptor_table_google_2fprotobuf_2fstruct_2eproto_once, file_level_metadata_google_2fprotobuf_2fstruct_2eproto[3]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -1096,5 +1052,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::ListValue >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::ListValue >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/struct.pb.h b/libs/protobuf/src/google/protobuf/struct.pb.h index 5b0fe1b..002aa85 100644 --- a/libs/protobuf/src/google/protobuf/struct.pb.h +++ b/libs/protobuf/src/google/protobuf/struct.pb.h @@ -1,47 +1,42 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/struct.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#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" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fstruct_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -52,8 +47,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fstruct_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fstruct_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fstruct_2eproto; PROTOBUF_NAMESPACE_OPEN class ListValue; struct ListValueDefaultTypeInternal; @@ -67,54 +61,41 @@ PROTOBUF_EXPORT extern Struct_FieldsEntry_DoNotUseDefaultTypeInternal _Struct_Fi class Value; struct ValueDefaultTypeInternal; PROTOBUF_EXPORT extern ValueDefaultTypeInternal _Value_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ListValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ListValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Struct* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Struct>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Value>(Arena*); PROTOBUF_NAMESPACE_CLOSE - PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::ListValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::ListValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Struct* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Struct>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Struct_FieldsEntry_DoNotUse>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Value>(Arena*); +PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_OPEN + enum NullValue : int { NULL_VALUE = 0, - NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), - NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), + NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; - PROTOBUF_EXPORT bool NullValue_IsValid(int value); -constexpr NullValue NullValue_MIN = static_cast(0); -constexpr NullValue NullValue_MAX = static_cast(0); -constexpr int NullValue_ARRAYSIZE = 0 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -NullValue_descriptor(); -template -const std::string& NullValue_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to NullValue_Name()."); - return NullValue_Name(static_cast(value)); +constexpr NullValue NullValue_MIN = NULL_VALUE; +constexpr NullValue NullValue_MAX = NULL_VALUE; +constexpr int NullValue_ARRAYSIZE = NullValue_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* NullValue_descriptor(); +template +inline const std::string& NullValue_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function NullValue_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + NullValue_descriptor(), enum_t_value); } -template <> -inline const std::string& NullValue_Name(NullValue value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool NullValue_Parse(absl::string_view name, NullValue* value) { +inline bool NullValue_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, NullValue* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - NullValue_descriptor(), name, value); + NullValue_descriptor(), name, value); } - // =================================================================== - -// ------------------------------------------------------------------- - class Struct_FieldsEntry_DoNotUse : public ::PROTOBUF_NAMESPACE_ID::internal::MapEntry fields = 1; @@ -1169,19 +1148,24 @@ ListValue::values() const { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::NullValue> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::NullValue> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::NullValue>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::NullValue>() { return ::PROTOBUF_NAMESPACE_ID::NullValue_descriptor(); } @@ -1189,6 +1173,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fstruct_2eproto diff --git a/libs/protobuf/src/google/protobuf/stubs/BUILD.bazel b/libs/protobuf/src/google/protobuf/stubs/BUILD.bazel deleted file mode 100644 index 9cc3e75..0000000 --- a/libs/protobuf/src/google/protobuf/stubs/BUILD.bazel +++ /dev/null @@ -1,111 +0,0 @@ -# Protobuf stubs library. -# These are utilities that mirror the behavior of internal Google code. - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") - -package( - default_visibility = ["//:__subpackages__"], -) - -cc_library( - name = "lite", - srcs = [ - "bytestream.cc", - "common.cc", - "structurally_valid.cc", - "strutil.cc", - ], - hdrs = [ - "bytestream.h", - "callback.h", - "common.h", - "logging.h", - "mathutil.h", - "platform_macros.h", - "port.h", - "status_macros.h", - "strutil.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/stubs", - linkopts = LINK_OPTS, - deps = [ - "//src/google/protobuf:port_def", - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings", - ], -) - -cc_library( - name = "stubs", - srcs = [ - ], - hdrs = [ - ], - copts = COPTS, - include_prefix = "google/protobuf/stubs", - textual_hdrs = [ - "bytestream.h", - "callback.h", - "common.h", - "logging.h", - "mathutil.h", - "platform_macros.h", - "port.h", - "status_macros.h", - "strutil.h", - ], - deps = [ - ":lite", - "//src/google/protobuf:port_def", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", - ], -) - -cc_test( - name = "stubs_test", - srcs = [ - "bytestream_unittest.cc", - "common_unittest.cc", - "structurally_valid_unittest.cc", - "strutil_unittest.cc", - ], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - linkopts = LINK_OPTS, - deps = [ - ":lite", - ":stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/stubs/bytestream.cc b/libs/protobuf/src/google/protobuf/stubs/bytestream.cc index f9dc2c6..980d6f6 100644 --- a/libs/protobuf/src/google/protobuf/stubs/bytestream.cc +++ b/libs/protobuf/src/google/protobuf/stubs/bytestream.cc @@ -28,13 +28,12 @@ // (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/bytestream.h" +#include #include - #include -#include "google/protobuf/stubs/logging.h" +#include namespace google { namespace protobuf { @@ -42,7 +41,7 @@ namespace strings { void ByteSource::CopyTo(ByteSink* sink, size_t n) { while (n > 0) { - absl::string_view fragment = Peek(); + StringPiece fragment = Peek(); if (fragment.empty()) { GOOGLE_LOG(DFATAL) << "ByteSource::CopyTo() overran input."; break; @@ -124,10 +123,8 @@ char* GrowingArrayByteSink::GetBuffer(size_t* nbytes) { void GrowingArrayByteSink::Expand(size_t amount) { // Expand by at least 50%. size_t new_capacity = std::max(capacity_ + amount, (3 * capacity_) / 2); char* bigger = new char[new_capacity]; - if(buf_ != nullptr) { - memcpy(bigger, buf_, size_); - delete[] buf_; - } + memcpy(bigger, buf_, size_); + delete[] buf_; buf_ = bigger; capacity_ = new_capacity; } @@ -152,7 +149,9 @@ size_t ArrayByteSource::Available() const { return input_.size(); } -absl::string_view ArrayByteSource::Peek() { return input_; } +StringPiece ArrayByteSource::Peek() { + return input_; +} void ArrayByteSource::Skip(size_t n) { GOOGLE_DCHECK_LE(n, input_.size()); @@ -173,9 +172,9 @@ size_t LimitByteSource::Available() const { return available; } -absl::string_view LimitByteSource::Peek() { - absl::string_view piece = source_->Peek(); - return absl::string_view(piece.data(), std::min(piece.size(), limit_)); +StringPiece LimitByteSource::Peek() { + StringPiece piece = source_->Peek(); + return StringPiece(piece.data(), std::min(piece.size(), limit_)); } void LimitByteSource::Skip(size_t n) { diff --git a/libs/protobuf/src/google/protobuf/stubs/bytestream.h b/libs/protobuf/src/google/protobuf/stubs/bytestream.h index a11233e..c7a48de 100644 --- a/libs/protobuf/src/google/protobuf/stubs/bytestream.h +++ b/libs/protobuf/src/google/protobuf/stubs/bytestream.h @@ -44,21 +44,19 @@ // NullByteSink Consumes a never-ending stream of bytes // // ByteSource: -// ArrayByteSource Reads from an array or string +// ArrayByteSource Reads from an array or string/StringPiece // LimitedByteSource Limits the number of bytes read from an #ifndef GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ #define GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ #include - #include -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/common.h" +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" // NOLINT +#include class CordByteSink; @@ -80,8 +78,6 @@ namespace strings { class PROTOBUF_EXPORT ByteSink { public: ByteSink() {} - ByteSink(const ByteSink&) = delete; - ByteSink& operator=(const ByteSink&) = delete; virtual ~ByteSink() {} // Appends the "n" bytes starting at "bytes". @@ -91,6 +87,9 @@ class PROTOBUF_EXPORT ByteSink { // subclasses may use internal buffers that require calling Flush() at the end // of the stream. virtual void Flush(); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSink); }; // An abstract interface for an object that produces a fixed-size sequence of @@ -100,7 +99,7 @@ class PROTOBUF_EXPORT ByteSink { // // ByteSource* source = ... // while (source->Available() > 0) { -// absl::string_view data = source->Peek(); +// StringPiece data = source->Peek(); // ... do something with "data" ... // source->Skip(data.length()); // } @@ -108,8 +107,6 @@ class PROTOBUF_EXPORT ByteSink { class PROTOBUF_EXPORT ByteSource { public: ByteSource() {} - ByteSource(const ByteSource&) = delete; - ByteSource& operator=(const ByteSource&) = delete; virtual ~ByteSource() {} // Returns the number of bytes left to read from the source. Available() @@ -121,18 +118,17 @@ class PROTOBUF_EXPORT ByteSource { // indicative of the fixed-size nature of a ByteSource. virtual size_t Available() const = 0; - // Returns an absl::string_view of the next contiguous region of the source. - // Does not reposition the source. The returned region is empty iff - // Available() == 0. + // Returns a StringPiece of the next contiguous region of the source. Does not + // reposition the source. The returned region is empty iff Available() == 0. // // The returned region is valid until the next call to Skip() or until this // object is destroyed, whichever occurs first. // - // The length of the returned absl::string_view will be <= Available(). - virtual absl::string_view Peek() = 0; + // The length of the returned StringPiece will be <= Available(). + virtual StringPiece Peek() = 0; - // Skips the next n bytes. Invalidates any absl::string_view returned by a - // previous call to Peek(). + // Skips the next n bytes. Invalidates any StringPiece returned by a previous + // call to Peek(). // // REQUIRES: Available() >= n virtual void Skip(size_t n) = 0; @@ -144,6 +140,9 @@ class PROTOBUF_EXPORT ByteSource { // // REQUIRES: Available() >= n virtual void CopyTo(ByteSink* sink, size_t n); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSource); }; // @@ -163,8 +162,6 @@ class PROTOBUF_EXPORT ByteSource { // class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { public: - UncheckedArrayByteSink(const UncheckedArrayByteSink&) = delete; - UncheckedArrayByteSink& operator=(const UncheckedArrayByteSink&) = delete; explicit UncheckedArrayByteSink(char* dest) : dest_(dest) {} virtual void Append(const char* data, size_t n) override; @@ -176,6 +173,7 @@ class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { private: char* dest_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UncheckedArrayByteSink); }; // Implementation of ByteSink that writes to a sized byte array. This sink will @@ -193,8 +191,6 @@ class PROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { public: CheckedArrayByteSink(char* outbuf, size_t capacity); - CheckedArrayByteSink(const CheckedArrayByteSink&) = delete; - CheckedArrayByteSink& operator=(const CheckedArrayByteSink&) = delete; virtual void Append(const char* bytes, size_t n) override; // Returns the number of bytes actually written to the sink. @@ -209,6 +205,7 @@ class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { const size_t capacity_; size_t size_; bool overflowed_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CheckedArrayByteSink); }; // Implementation of ByteSink that allocates an internal buffer (a char array) @@ -230,8 +227,6 @@ class PROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { public: explicit GrowingArrayByteSink(size_t estimated_size); - GrowingArrayByteSink(const GrowingArrayByteSink&) = delete; - GrowingArrayByteSink& operator=(const GrowingArrayByteSink&) = delete; virtual ~GrowingArrayByteSink(); virtual void Append(const char* bytes, size_t n) override; @@ -246,6 +241,7 @@ class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { size_t capacity_; char* buf_; size_t size_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GrowingArrayByteSink); }; // Implementation of ByteSink that appends to the given string. @@ -261,12 +257,11 @@ class PROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { class PROTOBUF_EXPORT StringByteSink : public ByteSink { public: explicit StringByteSink(std::string* dest) : dest_(dest) {} - StringByteSink(const StringByteSink&) = delete; - StringByteSink& operator=(const StringByteSink&) = delete; virtual void Append(const char* data, size_t n) override; private: std::string* dest_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringByteSink); }; // Implementation of ByteSink that discards all data. @@ -279,16 +274,17 @@ class PROTOBUF_EXPORT StringByteSink : public ByteSink { class PROTOBUF_EXPORT NullByteSink : public ByteSink { public: NullByteSink() {} - NullByteSink(const NullByteSink&) = delete; - NullByteSink& operator=(const NullByteSink&) = delete; void Append(const char* /*data*/, size_t /*n*/) override {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(NullByteSink); }; // // Some commonly used implementations of ByteSource // -// Implementation of ByteSource that reads from an absl::string_view. +// Implementation of ByteSource that reads from a StringPiece. // // Example: // @@ -299,16 +295,15 @@ class PROTOBUF_EXPORT NullByteSink : public ByteSink { // class PROTOBUF_EXPORT ArrayByteSource : public ByteSource { public: - explicit ArrayByteSource(absl::string_view s) : input_(s) {} - ArrayByteSource(const ArrayByteSource&) = delete; - ArrayByteSource& operator=(const ArrayByteSource&) = delete; + explicit ArrayByteSource(StringPiece s) : input_(s) {} virtual size_t Available() const override; - virtual absl::string_view Peek() override; + virtual StringPiece Peek() override; virtual void Skip(size_t n) override; private: - absl::string_view input_; + StringPiece input_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayByteSource); }; // Implementation of ByteSource that wraps another ByteSource, limiting the @@ -335,7 +330,7 @@ class PROTOBUF_EXPORT LimitByteSource : public ByteSource { LimitByteSource(ByteSource* source, size_t limit); virtual size_t Available() const override; - virtual absl::string_view Peek() override; + virtual StringPiece Peek() override; virtual void Skip(size_t n) override; // We override CopyTo so that we can forward to the underlying source, in @@ -351,6 +346,6 @@ class PROTOBUF_EXPORT LimitByteSource : public ByteSource { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" // NOLINT +#include #endif // GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc index 0e5f5a5..cb11825 100644 --- a/libs/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc +++ b/libs/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc @@ -28,15 +28,14 @@ // (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/bytestream.h" +#include -#include #include #include - #include -#include "google/protobuf/testing/googletest.h" +#include +#include namespace google { namespace protobuf { @@ -48,20 +47,22 @@ namespace { // one fragment. class MockByteSource : public ByteSource { public: - MockByteSource(absl::string_view data, int block_size) - : data_(data), block_size_(block_size) {} + MockByteSource(StringPiece data, int block_size) + : data_(data), block_size_(block_size) {} size_t Available() const { return data_.size(); } - absl::string_view Peek() { return data_.substr(0, block_size_); } + StringPiece Peek() { + return data_.substr(0, block_size_); + } void Skip(size_t n) { data_.remove_prefix(n); } private: - absl::string_view data_; + StringPiece data_; int block_size_; }; TEST(ByteSourceTest, CopyTo) { - absl::string_view data("Hello world!"); + StringPiece data("Hello world!"); MockByteSource source(data, 3); std::string str; StringByteSink sink(&str); @@ -71,7 +72,7 @@ TEST(ByteSourceTest, CopyTo) { } TEST(ByteSourceTest, CopySubstringTo) { - absl::string_view data("Hello world!"); + StringPiece data("Hello world!"); MockByteSource source(data, 3); source.Skip(1); std::string str; @@ -83,7 +84,7 @@ TEST(ByteSourceTest, CopySubstringTo) { } TEST(ByteSourceTest, LimitByteSource) { - absl::string_view data("Hello world!"); + StringPiece data("Hello world!"); MockByteSource source(data, 3); LimitByteSource limit_source(&source, 6); EXPECT_EQ(6, limit_source.Available()); @@ -109,7 +110,7 @@ TEST(ByteSourceTest, LimitByteSource) { } TEST(ByteSourceTest, CopyToStringByteSink) { - absl::string_view data("Hello world!"); + StringPiece data("Hello world!"); MockByteSource source(data, 3); std::string str; StringByteSink sink(&str); @@ -122,6 +123,8 @@ class FlushingByteSink : public StringByteSink { public: explicit FlushingByteSink(std::string* dest) : StringByteSink(dest) {} virtual void Flush() { Append("z", 1); } + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FlushingByteSink); }; // Write and Flush via the ByteSink superclass interface. diff --git a/libs/protobuf/src/google/protobuf/stubs/callback.h b/libs/protobuf/src/google/protobuf/stubs/callback.h index ed4b9f7..43d546d 100644 --- a/libs/protobuf/src/google/protobuf/stubs/callback.h +++ b/libs/protobuf/src/google/protobuf/stubs/callback.h @@ -1,39 +1,11 @@ -// 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_STUBS_CALLBACK_H_ #define GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ #include -#include "google/protobuf/port_def.inc" +#include + +#include // =================================================================== // emulates google3/base/callback.h @@ -101,44 +73,48 @@ namespace protobuf { class PROTOBUF_EXPORT Closure { public: Closure() {} - Closure(const Closure&) = delete; - Closure& operator=(const Closure&) = delete; virtual ~Closure(); virtual void Run() = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure); }; template class ResultCallback { public: ResultCallback() {} - ResultCallback(const ResultCallback&) = delete; - ResultCallback& operator=(const ResultCallback&) = delete; virtual ~ResultCallback() {} virtual R Run() = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback); }; template class PROTOBUF_EXPORT ResultCallback1 { public: ResultCallback1() {} - ResultCallback1(const ResultCallback1&) = delete; - ResultCallback1& operator=(const ResultCallback1&) = delete; virtual ~ResultCallback1() {} virtual R Run(A1) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback1); }; template class PROTOBUF_EXPORT ResultCallback2 { public: ResultCallback2() {} - ResultCallback2(const ResultCallback2&) = delete; - ResultCallback2& operator=(const ResultCallback2&) = delete; virtual ~ResultCallback2() {} virtual R Run(A1,A2) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback2); }; namespace internal { @@ -602,6 +578,6 @@ void PROTOBUF_EXPORT DoNothing(); } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/casts.h b/libs/protobuf/src/google/protobuf/stubs/casts.h new file mode 100644 index 0000000..ad29dac --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/casts.h @@ -0,0 +1,138 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2014 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_CASTS_H__ +#define GOOGLE_PROTOBUF_CASTS_H__ + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace internal { + +// Use implicit_cast as a safe version of static_cast or const_cast +// for upcasting in the type hierarchy (i.e. casting a pointer to Foo +// to a pointer to SuperclassOfFoo or casting a pointer to Foo to +// a const pointer to Foo). +// When you use implicit_cast, the compiler checks that the cast is safe. +// Such explicit implicit_casts are necessary in surprisingly many +// situations where C++ demands an exact type match instead of an +// argument type convertible to a target type. +// +// The From type can be inferred, so the preferred syntax for using +// implicit_cast is the same as for static_cast etc.: +// +// implicit_cast(expr) +// +// implicit_cast would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +template +inline To implicit_cast(From const &f) { + return f; +} + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, +// when you downcast, you should use this macro. In debug mode, we +// use dynamic_cast<> to double-check the downcast is legal (we die +// if it's not). In normal mode, we do the efficient static_cast<> +// instead. Thus, it's important to test in debug mode to make sure +// the cast is legal! +// This is the only place in the code we should use dynamic_cast<>. +// In particular, you SHOULDN'T be using dynamic_cast<> in order to +// do RTTI (eg code like this: +// if (dynamic_cast(foo)) HandleASubclass1Object(foo); +// if (dynamic_cast(foo)) HandleASubclass2Object(foo); +// You should design the code some other way not to need this. + +template // use like this: down_cast(foo); +inline To down_cast(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + if (false) { + implicit_cast(0); + } + +#if !defined(NDEBUG) && PROTOBUF_RTTI + assert(f == nullptr || dynamic_cast(f) != nullptr); // RTTI: debug mode only! +#endif + return static_cast(f); +} + +template // use like this: down_cast(foo); +inline To down_cast(From& f) { + typedef typename std::remove_reference::type* ToAsPointer; + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + if (false) { + implicit_cast(0); + } + +#if !defined(NDEBUG) && PROTOBUF_RTTI + // RTTI: debug mode only! + assert(dynamic_cast(&f) != nullptr); +#endif + return *static_cast(&f); +} + +template +inline To bit_cast(const From& from) { + static_assert(sizeof(From) == sizeof(To), "bit_cast_with_different_sizes"); + To dest; + memcpy(&dest, &from, sizeof(dest)); + return dest; +} + +} // namespace internal + +// We made these internal so that they would show up as such in the docs, +// but we don't want to stick "internal::" in front of them everywhere. +using internal::implicit_cast; +using internal::down_cast; +using internal::bit_cast; + +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_CASTS_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/common.cc b/libs/protobuf/src/google/protobuf/stubs/common.cc index d5c80bc..e0a807f 100644 --- a/libs/protobuf/src/google/protobuf/stubs/common.cc +++ b/libs/protobuf/src/google/protobuf/stubs/common.cc @@ -30,13 +30,12 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/stubs/common.h" - -#include -#include +#include #include +#include #include +#include #include #ifdef _WIN32 @@ -50,14 +49,15 @@ #include #endif -#include "absl/status/status.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/strutil.h" +#include +#include +#include +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" // NOLINT +#include namespace google { namespace protobuf { @@ -108,21 +108,6 @@ std::string VersionString(int version) { return buffer; } -std::string ProtocVersionString(int version) { - int minor = (version / 1000) % 1000; - int micro = version % 1000; - - // 128 bytes should always be enough, but we use snprintf() anyway to be - // safe. - char buffer[128]; - snprintf(buffer, sizeof(buffer), "%d.%d", minor, micro); - - // Guard against broken MSVC snprintf(). - buffer[sizeof(buffer) - 1] = '\0'; - - return buffer; -} - } // namespace internal // =================================================================== @@ -193,7 +178,7 @@ void NullLogHandler(LogLevel /* level */, const char* /* filename */, } static LogHandler* log_handler_ = &DefaultLogHandler; -static std::atomic log_silencer_count_{0}; +static std::atomic log_silencer_count_ = ATOMIC_VAR_INIT(0); LogMessage& LogMessage::operator<<(const std::string& value) { message_ += value; @@ -205,29 +190,36 @@ LogMessage& LogMessage::operator<<(const char* value) { return *this; } -LogMessage& LogMessage::operator<<(absl::string_view value) { - absl::StrAppend(&message_, value); +LogMessage& LogMessage::operator<<(const StringPiece& value) { + message_ += value.ToString(); return *this; } -LogMessage& LogMessage::operator<<(const absl::Status& status) { +LogMessage& LogMessage::operator<<(const util::Status& status) { message_ += status.ToString(); return *this; } +LogMessage& LogMessage::operator<<(const uint128& value) { + std::ostringstream str; + str << value; + message_ += str.str(); + return *this; +} + LogMessage& LogMessage::operator<<(char value) { - return *this << absl::string_view(&value, 1); + return *this << StringPiece(&value, 1); } LogMessage& LogMessage::operator<<(void* value) { - absl::StrAppend(&message_, strings::Hex(reinterpret_cast(value))); + StrAppend(&message_, strings::Hex(reinterpret_cast(value))); return *this; } #undef DECLARE_STREAM_OPERATOR #define DECLARE_STREAM_OPERATOR(TYPE) \ LogMessage& LogMessage::operator<<(TYPE value) { \ - absl::StrAppend(&message_, value); \ + StrAppend(&message_, value); \ return *this; \ } @@ -329,4 +321,4 @@ const char* FatalException::what() const throw() { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" // NOLINT +#include diff --git a/libs/protobuf/src/google/protobuf/stubs/common.h b/libs/protobuf/src/google/protobuf/stubs/common.h index 78bb925..0b9fa81 100644 --- a/libs/protobuf/src/google/protobuf/stubs/common.h +++ b/libs/protobuf/src/google/protobuf/stubs/common.h @@ -43,27 +43,10 @@ #include #include -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/platform_macros.h" -#include "google/protobuf/stubs/port.h" - -// Enforce C++14 as the minimum. -#if defined(_MSVC_LANG) -#if _MSVC_LANG < 201402L -#error "C++ versions less than C++14 are not supported." -#endif // _MSVC_LANG < 201402L -#elif defined(__cplusplus) -// Special-case GCC < 5.0, as it has a strange __cplusplus value for C++14 -#if defined(__GNUC__) && __GNUC__ < 5 -#if __cplusplus < 201300L -#error "C++ versions less than C++14 are not supported." -#endif // __cplusplus < 201300L -#else // defined(__GNUC__) && __GNUC__ < 5 -#if __cplusplus < 201402L -#error "C++ versions less than C++14 are not supported." -#endif // __cplusplus < 201402L -#endif // defined(__GNUC__) && __GNUC__ < 5 -#endif +#include +#include +#include +#include #ifndef PROTOBUF_USE_EXCEPTIONS #if defined(_MSC_VER) && defined(_CPPUNWIND) @@ -86,7 +69,7 @@ #include #endif -#include "google/protobuf/port_def.inc" +#include namespace std {} @@ -99,7 +82,7 @@ namespace internal { // The current version, represented as a single integer to make comparison // easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3021008 +#define GOOGLE_PROTOBUF_VERSION 3021012 // A suffix string for alpha, beta or rc releases. Empty for stable releases. #define GOOGLE_PROTOBUF_VERSION_SUFFIX "" @@ -123,12 +106,7 @@ void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, const char* filename); // Converts a numeric version number to a string. -std::string PROTOBUF_EXPORT -VersionString(int version); // NOLINT(runtime/string) - -// Prints the protoc compiler version (no major version) -std::string PROTOBUF_EXPORT -ProtocVersionString(int version); // NOLINT(runtime/string) +std::string PROTOBUF_EXPORT VersionString(int version); } // namespace internal @@ -151,12 +129,12 @@ namespace internal { // structurally_valid.cc. PROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); -inline bool IsStructurallyValidUTF8(absl::string_view str) { +inline bool IsStructurallyValidUTF8(StringPiece str) { return IsStructurallyValidUTF8(str.data(), static_cast(str.length())); } // Returns initial number of bytes of structurally valid UTF-8. -PROTOBUF_EXPORT int UTF8SpnStructurallyValid(absl::string_view str); +PROTOBUF_EXPORT int UTF8SpnStructurallyValid(StringPiece str); // Coerce UTF-8 byte string in src_str to be // a structurally-valid equal-length string by selectively @@ -170,8 +148,7 @@ PROTOBUF_EXPORT int UTF8SpnStructurallyValid(absl::string_view str); // // Optimized for: all structurally valid and no byte copying is done. // -PROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid(absl::string_view str, - char* dst, +PROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid(StringPiece str, char* dst, char replace_char); } // namespace internal @@ -215,6 +192,6 @@ class FatalException : public std::exception { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/common_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/common_unittest.cc index 7c86204..c55e452 100644 --- a/libs/protobuf/src/google/protobuf/stubs/common_unittest.cc +++ b/libs/protobuf/src/google/protobuf/stubs/common_unittest.cc @@ -30,18 +30,16 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/stubs/common.h" - -#include - #include +#include +#include +#include +#include +#include +#include -#include "absl/strings/ascii.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/strutil.h" -#include "google/protobuf/testing/googletest.h" +#include +#include namespace google { namespace protobuf { @@ -58,7 +56,7 @@ TEST(VersionTest, VersionMatchesConfig) { std::string version = PACKAGE_VERSION; int pos = 0; while (pos < version.size() && - (absl::ascii_isdigit(version[pos]) || version[pos] == '.')) { + (ascii_isdigit(version[pos]) || version[pos] == '.')) { ++pos; } version.erase(pos); @@ -83,8 +81,9 @@ std::vector captured_messages_; void CaptureLog(LogLevel level, const char* filename, int line, const std::string& message) { - captured_messages_.push_back(absl::Substitute( - "$0 $1:$2: $3", static_cast(level), filename, line, message)); + captured_messages_.push_back( + strings::Substitute("$0 $1:$2: $3", + implicit_cast(level), filename, line, message)); } TEST(LoggingTest, DefaultLogging) { @@ -95,14 +94,11 @@ TEST(LoggingTest, DefaultLogging) { GOOGLE_LOG(ERROR ) << "An error."; std::string text = GetCapturedTestStderr(); - EXPECT_EQ(absl::StrCat("[libprotobuf INFO " __FILE__ ":", line + 1, - "] A message.\n" - "[libprotobuf WARNING " __FILE__ ":", - line + 2, - "] A warning.\n" - "[libprotobuf ERROR " __FILE__ ":", - line + 3, "] An error.\n"), - text); + EXPECT_EQ( + "[libprotobuf INFO " __FILE__ ":" + SimpleItoa(line + 1) + "] A message.\n" + "[libprotobuf WARNING " __FILE__ ":" + SimpleItoa(line + 2) + "] A warning.\n" + "[libprotobuf ERROR " __FILE__ ":" + SimpleItoa(line + 3) + "] An error.\n", + text); } TEST(LoggingTest, NullLogging) { @@ -131,10 +127,12 @@ TEST(LoggingTest, CaptureLogging) { EXPECT_TRUE(SetLogHandler(old_handler) == &CaptureLog); ASSERT_EQ(2, captured_messages_.size()); - EXPECT_EQ(absl::StrCat("2 " __FILE__ ":", start_line + 1, ": An error."), - captured_messages_[0]); - EXPECT_EQ(absl::StrCat("1 " __FILE__ ":", start_line + 2, ": A warning."), - captured_messages_[1]); + EXPECT_EQ( + "2 " __FILE__ ":" + SimpleItoa(start_line + 1) + ": An error.", + captured_messages_[0]); + EXPECT_EQ( + "1 " __FILE__ ":" + SimpleItoa(start_line + 2) + ": A warning.", + captured_messages_[1]); } TEST(LoggingTest, SilenceLogging) { @@ -155,10 +153,12 @@ TEST(LoggingTest, SilenceLogging) { EXPECT_TRUE(SetLogHandler(old_handler) == &CaptureLog); ASSERT_EQ(2, captured_messages_.size()); - EXPECT_EQ(absl::StrCat("0 " __FILE__ ":", line1, ": Visible1"), - captured_messages_[0]); - EXPECT_EQ(absl::StrCat("0 " __FILE__ ":", line2, ": Visible2"), - captured_messages_[1]); + EXPECT_EQ( + "0 " __FILE__ ":" + SimpleItoa(line1) + ": Visible1", + captured_messages_[0]); + EXPECT_EQ( + "0 " __FILE__ ":" + SimpleItoa(line2) + ": Visible2", + captured_messages_[1]); } class ClosureTest : public testing::Test { diff --git a/libs/protobuf/src/google/protobuf/stubs/hash.h b/libs/protobuf/src/google/protobuf/stubs/hash.h new file mode 100644 index 0000000..a7ec068 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/hash.h @@ -0,0 +1,114 @@ +// 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. + +// Author: kenton@google.com (Kenton Varda) + +#ifndef GOOGLE_PROTOBUF_STUBS_HASH_H__ +#define GOOGLE_PROTOBUF_STUBS_HASH_H__ + +#include +#include +#include +#include + +# define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START \ + namespace google { \ + namespace protobuf { +# define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END }} + +namespace google { +namespace protobuf { + +template +struct hash : public std::hash {}; + +template +struct hash { + inline size_t operator()(const Key* key) const { + return reinterpret_cast(key); + } +}; + +// Unlike the old SGI version, the TR1 "hash" does not special-case char*. So, +// we go ahead and provide our own implementation. +template <> +struct hash { + inline size_t operator()(const char* str) const { + size_t result = 0; + for (; *str != '\0'; str++) { + result = 5 * result + static_cast(*str); + } + return result; + } +}; + +template<> +struct hash { + size_t operator()(bool x) const { + return static_cast(x); + } +}; + +template <> +struct hash { + inline size_t operator()(const std::string& key) const { + return hash()(key.c_str()); + } + + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; + inline bool operator()(const std::string& a, const std::string& b) const { + return a < b; + } +}; + +template +struct hash > { + inline size_t operator()(const std::pair& key) const { + size_t first_hash = hash()(key.first); + size_t second_hash = hash()(key.second); + + // FIXME(kenton): What is the best way to compute this hash? I have + // no idea! This seems a bit better than an XOR. + return first_hash * ((1 << 16) - 1) + second_hash; + } + + static const size_t bucket_size = 4; + static const size_t min_buckets = 8; + inline bool operator()(const std::pair& a, + const std::pair& b) const { + return a < b; + } +}; + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/int128.cc b/libs/protobuf/src/google/protobuf/stubs/int128.cc new file mode 100644 index 0000000..a151cfb --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/int128.cc @@ -0,0 +1,193 @@ +// 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 + +#include +#include // NOLINT(readability/streams) +#include + +#include + +#include + +namespace google { +namespace protobuf { + +const uint128_pod kuint128max = {uint64_t{0xFFFFFFFFFFFFFFFFu}, + uint64_t{0xFFFFFFFFFFFFFFFFu}}; + +// Returns the 0-based position of the last set bit (i.e., most significant bit) +// in the given uint64. The argument may not be 0. +// +// For example: +// Given: 5 (decimal) == 101 (binary) +// Returns: 2 +#define STEP(T, n, pos, sh) \ + do { \ + if ((n) >= (static_cast(1) << (sh))) { \ + (n) = (n) >> (sh); \ + (pos) |= (sh); \ + } \ + } while (0) +static inline int Fls64(uint64_t n) { + GOOGLE_DCHECK_NE(0, n); + int pos = 0; + STEP(uint64_t, n, pos, 0x20); + uint32_t n32 = n; + STEP(uint32_t, n32, pos, 0x10); + STEP(uint32_t, n32, pos, 0x08); + STEP(uint32_t, n32, pos, 0x04); + return pos + ((uint64_t{0x3333333322221100u} >> (n32 << 2)) & 0x3); +} +#undef STEP + +// Like Fls64() above, but returns the 0-based position of the last set bit +// (i.e., most significant bit) in the given uint128. The argument may not be 0. +static inline int Fls128(uint128 n) { + if (uint64_t hi = Uint128High64(n)) { + return Fls64(hi) + 64; + } + return Fls64(Uint128Low64(n)); +} + +void uint128::DivModImpl(uint128 dividend, uint128 divisor, + uint128* quotient_ret, uint128* remainder_ret) { + if (divisor == 0) { + GOOGLE_LOG(FATAL) << "Division or mod by zero: dividend.hi=" << dividend.hi_ + << ", lo=" << dividend.lo_; + } else if (dividend < divisor) { + *quotient_ret = 0; + *remainder_ret = dividend; + return; + } else { + int dividend_bit_length = Fls128(dividend); + int divisor_bit_length = Fls128(divisor); + int difference = dividend_bit_length - divisor_bit_length; + uint128 quotient = 0; + while (difference >= 0) { + quotient <<= 1; + uint128 shifted_divisor = divisor << difference; + if (shifted_divisor <= dividend) { + dividend -= shifted_divisor; + quotient += 1; + } + difference -= 1; + } + //record the final quotient and remainder + *quotient_ret = quotient; + *remainder_ret = dividend; + } +} + + +uint128& uint128::operator/=(const uint128& divisor) { + uint128 quotient = 0; + uint128 remainder = 0; + DivModImpl(*this, divisor, "ient, &remainder); + *this = quotient; + return *this; +} +uint128& uint128::operator%=(const uint128& divisor) { + uint128 quotient = 0; + uint128 remainder = 0; + DivModImpl(*this, divisor, "ient, &remainder); + *this = remainder; + return *this; +} + +std::ostream& operator<<(std::ostream& o, const uint128& b) { + std::ios_base::fmtflags flags = o.flags(); + + // Select a divisor which is the largest power of the base < 2^64. + uint128 div; + std::streamsize div_base_log; + switch (flags & std::ios::basefield) { + case std::ios::hex: + div = + static_cast(uint64_t{0x1000000000000000u}); // 16^15 + div_base_log = 15; + break; + case std::ios::oct: + div = static_cast( + uint64_t{01000000000000000000000u}); // 8^21 + div_base_log = 21; + break; + default: // std::ios::dec + div = static_cast( + uint64_t{10000000000000000000u}); // 10^19 + div_base_log = 19; + break; + } + + // Now piece together the uint128 representation from three chunks of + // the original value, each less than "div" and therefore representable + // as a uint64. + std::ostringstream os; + std::ios_base::fmtflags copy_mask = + std::ios::basefield | std::ios::showbase | std::ios::uppercase; + os.setf(flags & copy_mask, copy_mask); + uint128 high = b; + uint128 low; + uint128::DivModImpl(high, div, &high, &low); + uint128 mid; + uint128::DivModImpl(high, div, &high, &mid); + if (high.lo_ != 0) { + os << high.lo_; + os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); + os << mid.lo_; + os << std::setw(div_base_log); + } else if (mid.lo_ != 0) { + os << mid.lo_; + os << std::noshowbase << std::setfill('0') << std::setw(div_base_log); + } + os << low.lo_; + std::string rep = os.str(); + + // Add the requisite padding. + std::streamsize width = o.width(0); + auto repSize = static_cast(rep.size()); + if (width > repSize) { + if ((flags & std::ios::adjustfield) == std::ios::left) { + rep.append(width - repSize, o.fill()); + } else { + rep.insert(static_cast(0), width - repSize, + o.fill()); + } + } + + // Stream the final representation in a single "<<" call. + return o << rep; +} + +} // namespace protobuf +} // namespace google + +#include // NOLINT diff --git a/libs/protobuf/src/google/protobuf/stubs/int128.h b/libs/protobuf/src/google/protobuf/stubs/int128.h new file mode 100644 index 0000000..92d7bdf --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/int128.h @@ -0,0 +1,387 @@ +// 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_STUBS_INT128_H_ +#define GOOGLE_PROTOBUF_STUBS_INT128_H_ + +#include + +#include + +#include + +namespace google { +namespace protobuf { + +struct uint128_pod; + +// TODO(xiaofeng): Define GOOGLE_PROTOBUF_HAS_CONSTEXPR when constexpr is +// available. +#ifdef GOOGLE_PROTOBUF_HAS_CONSTEXPR +# define UINT128_CONSTEXPR constexpr +#else +# define UINT128_CONSTEXPR +#endif + +// An unsigned 128-bit integer type. Thread-compatible. +class PROTOBUF_EXPORT uint128 { + public: + UINT128_CONSTEXPR uint128(); // Sets to 0, but don't trust on this behavior. + UINT128_CONSTEXPR uint128(uint64_t top, uint64_t bottom); +#ifndef SWIG + UINT128_CONSTEXPR uint128(int bottom); + UINT128_CONSTEXPR uint128(uint32_t bottom); // Top 96 bits = 0 +#endif + UINT128_CONSTEXPR uint128(uint64_t bottom); // hi_ = 0 + UINT128_CONSTEXPR uint128(const uint128_pod &val); + + // Trivial copy constructor, assignment operator and destructor. + + void Initialize(uint64_t top, uint64_t bottom); + + // Arithmetic operators. + uint128& operator+=(const uint128& b); + uint128& operator-=(const uint128& b); + uint128& operator*=(const uint128& b); + // Long division/modulo for uint128. + uint128& operator/=(const uint128& b); + uint128& operator%=(const uint128& b); + uint128 operator++(int); + uint128 operator--(int); + uint128& operator<<=(int); + uint128& operator>>=(int); + uint128& operator&=(const uint128& b); + uint128& operator|=(const uint128& b); + uint128& operator^=(const uint128& b); + uint128& operator++(); + uint128& operator--(); + + friend uint64_t Uint128Low64(const uint128& v); + friend uint64_t Uint128High64(const uint128& v); + + // We add "std::" to avoid including all of port.h. + PROTOBUF_EXPORT friend std::ostream& operator<<(std::ostream& o, + const uint128& b); + + private: + static void DivModImpl(uint128 dividend, uint128 divisor, + uint128* quotient_ret, uint128* remainder_ret); + + // Little-endian memory order optimizations can benefit from + // having lo_ first, hi_ last. + // See util/endian/endian.h and Load128/Store128 for storing a uint128. + uint64_t lo_; + uint64_t hi_; + + // Not implemented, just declared for catching automatic type conversions. + uint128(uint8_t); + uint128(uint16_t); + uint128(float v); + uint128(double v); +}; + +// This is a POD form of uint128 which can be used for static variables which +// need to be operated on as uint128. +struct uint128_pod { + // Note: The ordering of fields is different than 'class uint128' but the + // same as its 2-arg constructor. This enables more obvious initialization + // of static instances, which is the primary reason for this struct in the + // first place. This does not seem to defeat any optimizations wrt + // operations involving this struct. + uint64_t hi; + uint64_t lo; +}; + +PROTOBUF_EXPORT extern const uint128_pod kuint128max; + +// allow uint128 to be logged +PROTOBUF_EXPORT extern std::ostream& operator<<(std::ostream& o, + const uint128& b); + +// Methods to access low and high pieces of 128-bit value. +// Defined externally from uint128 to facilitate conversion +// to native 128-bit types when compilers support them. +inline uint64_t Uint128Low64(const uint128& v) { return v.lo_; } +inline uint64_t Uint128High64(const uint128& v) { return v.hi_; } + +// TODO: perhaps it would be nice to have int128, a signed 128-bit type? + +// -------------------------------------------------------------------------- +// Implementation details follow +// -------------------------------------------------------------------------- +inline bool operator==(const uint128& lhs, const uint128& rhs) { + return (Uint128Low64(lhs) == Uint128Low64(rhs) && + Uint128High64(lhs) == Uint128High64(rhs)); +} +inline bool operator!=(const uint128& lhs, const uint128& rhs) { + return !(lhs == rhs); +} + +inline UINT128_CONSTEXPR uint128::uint128() : lo_(0), hi_(0) {} +inline UINT128_CONSTEXPR uint128::uint128(uint64_t top, uint64_t bottom) + : lo_(bottom), hi_(top) {} +inline UINT128_CONSTEXPR uint128::uint128(const uint128_pod& v) + : lo_(v.lo), hi_(v.hi) {} +inline UINT128_CONSTEXPR uint128::uint128(uint64_t bottom) + : lo_(bottom), hi_(0) {} +#ifndef SWIG +inline UINT128_CONSTEXPR uint128::uint128(uint32_t bottom) + : lo_(bottom), hi_(0) {} +inline UINT128_CONSTEXPR uint128::uint128(int bottom) + : lo_(bottom), hi_(static_cast((bottom < 0) ? -1 : 0)) {} +#endif + +#undef UINT128_CONSTEXPR + +inline void uint128::Initialize(uint64_t top, uint64_t bottom) { + hi_ = top; + lo_ = bottom; +} + +// Comparison operators. + +#define CMP128(op) \ +inline bool operator op(const uint128& lhs, const uint128& rhs) { \ + return (Uint128High64(lhs) == Uint128High64(rhs)) ? \ + (Uint128Low64(lhs) op Uint128Low64(rhs)) : \ + (Uint128High64(lhs) op Uint128High64(rhs)); \ +} + +CMP128(<) +CMP128(>) +CMP128(>=) +CMP128(<=) + +#undef CMP128 + +// Unary operators + +inline uint128 operator-(const uint128& val) { + const uint64_t hi_flip = ~Uint128High64(val); + const uint64_t lo_flip = ~Uint128Low64(val); + const uint64_t lo_add = lo_flip + 1; + if (lo_add < lo_flip) { + return uint128(hi_flip + 1, lo_add); + } + return uint128(hi_flip, lo_add); +} + +inline bool operator!(const uint128& val) { + return !Uint128High64(val) && !Uint128Low64(val); +} + +// Logical operators. + +inline uint128 operator~(const uint128& val) { + return uint128(~Uint128High64(val), ~Uint128Low64(val)); +} + +#define LOGIC128(op) \ +inline uint128 operator op(const uint128& lhs, const uint128& rhs) { \ + return uint128(Uint128High64(lhs) op Uint128High64(rhs), \ + Uint128Low64(lhs) op Uint128Low64(rhs)); \ +} + +LOGIC128(|) +LOGIC128(&) +LOGIC128(^) + +#undef LOGIC128 + +#define LOGICASSIGN128(op) \ +inline uint128& uint128::operator op(const uint128& other) { \ + hi_ op other.hi_; \ + lo_ op other.lo_; \ + return *this; \ +} + +LOGICASSIGN128(|=) +LOGICASSIGN128(&=) +LOGICASSIGN128(^=) + +#undef LOGICASSIGN128 + +// Shift operators. + +inline uint128 operator<<(const uint128& val, int amount) { + // uint64 shifts of >= 64 are undefined, so we will need some special-casing. + if (amount < 64) { + if (amount == 0) { + return val; + } + uint64_t new_hi = (Uint128High64(val) << amount) | + (Uint128Low64(val) >> (64 - amount)); + uint64_t new_lo = Uint128Low64(val) << amount; + return uint128(new_hi, new_lo); + } else if (amount < 128) { + return uint128(Uint128Low64(val) << (amount - 64), 0); + } else { + return uint128(0, 0); + } +} + +inline uint128 operator>>(const uint128& val, int amount) { + // uint64 shifts of >= 64 are undefined, so we will need some special-casing. + if (amount < 64) { + if (amount == 0) { + return val; + } + uint64_t new_hi = Uint128High64(val) >> amount; + uint64_t new_lo = (Uint128Low64(val) >> amount) | + (Uint128High64(val) << (64 - amount)); + return uint128(new_hi, new_lo); + } else if (amount < 128) { + return uint128(0, Uint128High64(val) >> (amount - 64)); + } else { + return uint128(0, 0); + } +} + +inline uint128& uint128::operator<<=(int amount) { + // uint64 shifts of >= 64 are undefined, so we will need some special-casing. + if (amount < 64) { + if (amount != 0) { + hi_ = (hi_ << amount) | (lo_ >> (64 - amount)); + lo_ = lo_ << amount; + } + } else if (amount < 128) { + hi_ = lo_ << (amount - 64); + lo_ = 0; + } else { + hi_ = 0; + lo_ = 0; + } + return *this; +} + +inline uint128& uint128::operator>>=(int amount) { + // uint64 shifts of >= 64 are undefined, so we will need some special-casing. + if (amount < 64) { + if (amount != 0) { + lo_ = (lo_ >> amount) | (hi_ << (64 - amount)); + hi_ = hi_ >> amount; + } + } else if (amount < 128) { + lo_ = hi_ >> (amount - 64); + hi_ = 0; + } else { + lo_ = 0; + hi_ = 0; + } + return *this; +} + +inline uint128 operator+(const uint128& lhs, const uint128& rhs) { + return uint128(lhs) += rhs; +} + +inline uint128 operator-(const uint128& lhs, const uint128& rhs) { + return uint128(lhs) -= rhs; +} + +inline uint128 operator*(const uint128& lhs, const uint128& rhs) { + return uint128(lhs) *= rhs; +} + +inline uint128 operator/(const uint128& lhs, const uint128& rhs) { + return uint128(lhs) /= rhs; +} + +inline uint128 operator%(const uint128& lhs, const uint128& rhs) { + return uint128(lhs) %= rhs; +} + +inline uint128& uint128::operator+=(const uint128& b) { + hi_ += b.hi_; + uint64_t lolo = lo_ + b.lo_; + if (lolo < lo_) + ++hi_; + lo_ = lolo; + return *this; +} + +inline uint128& uint128::operator-=(const uint128& b) { + hi_ -= b.hi_; + if (b.lo_ > lo_) + --hi_; + lo_ -= b.lo_; + return *this; +} + +inline uint128& uint128::operator*=(const uint128& b) { + uint64_t a96 = hi_ >> 32; + uint64_t a64 = hi_ & 0xffffffffu; + uint64_t a32 = lo_ >> 32; + uint64_t a00 = lo_ & 0xffffffffu; + uint64_t b96 = b.hi_ >> 32; + uint64_t b64 = b.hi_ & 0xffffffffu; + uint64_t b32 = b.lo_ >> 32; + uint64_t b00 = b.lo_ & 0xffffffffu; + // multiply [a96 .. a00] x [b96 .. b00] + // terms higher than c96 disappear off the high side + // terms c96 and c64 are safe to ignore carry bit + uint64_t c96 = a96 * b00 + a64 * b32 + a32 * b64 + a00 * b96; + uint64_t c64 = a64 * b00 + a32 * b32 + a00 * b64; + this->hi_ = (c96 << 32) + c64; + this->lo_ = 0; + // add terms after this one at a time to capture carry + *this += uint128(a32 * b00) << 32; + *this += uint128(a00 * b32) << 32; + *this += a00 * b00; + return *this; +} + +inline uint128 uint128::operator++(int) { + uint128 tmp(*this); + *this += 1; + return tmp; +} + +inline uint128 uint128::operator--(int) { + uint128 tmp(*this); + *this -= 1; + return tmp; +} + +inline uint128& uint128::operator++() { + *this += 1; + return *this; +} + +inline uint128& uint128::operator--() { + *this -= 1; + return *this; +} + +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_INT128_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/int128_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/int128_unittest.cc new file mode 100644 index 0000000..b1634f0 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/int128_unittest.cc @@ -0,0 +1,511 @@ +// 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 + +#include +#include +#include + +#include +#include + +#include + +namespace google { +namespace protobuf { + +TEST(Int128, AllTests) { + uint128 zero(0); + uint128 one(1); + uint128 one_2arg(0, 1); + uint128 two(0, 2); + uint128 three(0, 3); + uint128 big(2000, 2); + uint128 big_minus_one(2000, 1); + uint128 bigger(2001, 1); + uint128 biggest(kuint128max); + uint128 high_low(1, 0); + uint128 low_high(0, std::numeric_limits::max()); + EXPECT_LT(one, two); + EXPECT_GT(two, one); + EXPECT_LT(one, big); + EXPECT_LT(one, big); + EXPECT_EQ(one, one_2arg); + EXPECT_NE(one, two); + EXPECT_GT(big, one); + EXPECT_GE(big, two); + EXPECT_GE(big, big_minus_one); + EXPECT_GT(big, big_minus_one); + EXPECT_LT(big_minus_one, big); + EXPECT_LE(big_minus_one, big); + EXPECT_NE(big_minus_one, big); + EXPECT_LT(big, biggest); + EXPECT_LE(big, biggest); + EXPECT_GT(biggest, big); + EXPECT_GE(biggest, big); + EXPECT_EQ(big, ~~big); + EXPECT_EQ(one, one | one); + EXPECT_EQ(big, big | big); + EXPECT_EQ(one, one | zero); + EXPECT_EQ(one, one & one); + EXPECT_EQ(big, big & big); + EXPECT_EQ(zero, one & zero); + EXPECT_EQ(zero, big & ~big); + EXPECT_EQ(zero, one ^ one); + EXPECT_EQ(zero, big ^ big); + EXPECT_EQ(one, one ^ zero); + + // Shift operators. + EXPECT_EQ(big, big << 0); + EXPECT_EQ(big, big >> 0); + EXPECT_GT(big << 1, big); + EXPECT_LT(big >> 1, big); + EXPECT_EQ(big, (big << 10) >> 10); + EXPECT_EQ(big, (big >> 1) << 1); + EXPECT_EQ(one, (one << 80) >> 80); + EXPECT_EQ(zero, (one >> 80) << 80); + EXPECT_EQ(zero, big >> 128); + EXPECT_EQ(zero, big << 128); + + // Shift assignments. + uint128 big_copy = big; + EXPECT_EQ(big << 0, big_copy <<= 0); + big_copy = big; + EXPECT_EQ(big >> 0, big_copy >>= 0); + big_copy = big; + EXPECT_EQ(big << 1, big_copy <<= 1); + big_copy = big; + EXPECT_EQ(big >> 1, big_copy >>= 1); + big_copy = big; + EXPECT_EQ(big << 10, big_copy <<= 10); + big_copy = big; + EXPECT_EQ(big >> 10, big_copy >>= 10); + big_copy = big; + EXPECT_EQ(big << 64, big_copy <<= 64); + big_copy = big; + EXPECT_EQ(big >> 64, big_copy >>= 64); + big_copy = big; + EXPECT_EQ(big << 73, big_copy <<= 73); + big_copy = big; + EXPECT_EQ(big >> 73, big_copy >>= 73); + big_copy = big; + EXPECT_EQ(big << 128, big_copy <<= 128); + big_copy = big; + EXPECT_EQ(big >> 128, big_copy >>= 128); + + EXPECT_EQ(Uint128High64(biggest), std::numeric_limits::max()); + EXPECT_EQ(Uint128Low64(biggest), std::numeric_limits::max()); + EXPECT_EQ(zero + one, one); + EXPECT_EQ(one + one, two); + EXPECT_EQ(big_minus_one + one, big); + EXPECT_EQ(one - one, zero); + EXPECT_EQ(one - zero, one); + EXPECT_EQ(zero - one, biggest); + EXPECT_EQ(big - big, zero); + EXPECT_EQ(big - one, big_minus_one); + EXPECT_EQ(big + std::numeric_limits::max(), bigger); + EXPECT_EQ(biggest + 1, zero); + EXPECT_EQ(zero - 1, biggest); + EXPECT_EQ(high_low - one, low_high); + EXPECT_EQ(low_high + one, high_low); + EXPECT_EQ(Uint128High64((uint128(1) << 64) - 1), 0); + EXPECT_EQ(Uint128Low64((uint128(1) << 64) - 1), std::numeric_limits::max()); + EXPECT_TRUE(!!one); + EXPECT_TRUE(!!high_low); + EXPECT_FALSE(!!zero); + EXPECT_FALSE(!one); + EXPECT_FALSE(!high_low); + EXPECT_TRUE(!zero); + EXPECT_TRUE(zero == 0); + EXPECT_FALSE(zero != 0); + EXPECT_FALSE(one == 0); + EXPECT_TRUE(one != 0); + + uint128 test = zero; + EXPECT_EQ(++test, one); + EXPECT_EQ(test, one); + EXPECT_EQ(test++, one); + EXPECT_EQ(test, two); + EXPECT_EQ(test -= 2, zero); + EXPECT_EQ(test, zero); + EXPECT_EQ(test += 2, two); + EXPECT_EQ(test, two); + EXPECT_EQ(--test, one); + EXPECT_EQ(test, one); + EXPECT_EQ(test--, one); + EXPECT_EQ(test, zero); + EXPECT_EQ(test |= three, three); + EXPECT_EQ(test &= one, one); + EXPECT_EQ(test ^= three, two); + EXPECT_EQ(test >>= 1, one); + EXPECT_EQ(test <<= 1, two); + + EXPECT_EQ(big, -(-big)); + EXPECT_EQ(two, -((-one) - 1)); + EXPECT_EQ(kuint128max, -one); + EXPECT_EQ(zero, -zero); + + GOOGLE_LOG(INFO) << one; + GOOGLE_LOG(INFO) << big_minus_one; +} + +TEST(Int128, PodTests) { + uint128_pod pod = { 12345, 67890 }; + uint128 from_pod(pod); + EXPECT_EQ(12345, Uint128High64(from_pod)); + EXPECT_EQ(67890, Uint128Low64(from_pod)); + + uint128 zero(0); + uint128_pod zero_pod = {0, 0}; + uint128 one(1); + uint128_pod one_pod = {0, 1}; + uint128 two(2); + uint128_pod two_pod = {0, 2}; + uint128 three(3); + uint128_pod three_pod = {0, 3}; + uint128 big(1, 0); + uint128_pod big_pod = {1, 0}; + + EXPECT_EQ(zero, zero_pod); + EXPECT_EQ(zero_pod, zero); + EXPECT_EQ(zero_pod, zero_pod); + EXPECT_EQ(one, one_pod); + EXPECT_EQ(one_pod, one); + EXPECT_EQ(one_pod, one_pod); + EXPECT_EQ(two, two_pod); + EXPECT_EQ(two_pod, two); + EXPECT_EQ(two_pod, two_pod); + + EXPECT_NE(one, two_pod); + EXPECT_NE(one_pod, two); + EXPECT_NE(one_pod, two_pod); + + EXPECT_LT(one, two_pod); + EXPECT_LT(one_pod, two); + EXPECT_LT(one_pod, two_pod); + EXPECT_LE(one, one_pod); + EXPECT_LE(one_pod, one); + EXPECT_LE(one_pod, one_pod); + EXPECT_LE(one, two_pod); + EXPECT_LE(one_pod, two); + EXPECT_LE(one_pod, two_pod); + + EXPECT_GT(two, one_pod); + EXPECT_GT(two_pod, one); + EXPECT_GT(two_pod, one_pod); + EXPECT_GE(two, two_pod); + EXPECT_GE(two_pod, two); + EXPECT_GE(two_pod, two_pod); + EXPECT_GE(two, one_pod); + EXPECT_GE(two_pod, one); + EXPECT_GE(two_pod, one_pod); + + EXPECT_EQ(three, one | two_pod); + EXPECT_EQ(three, one_pod | two); + EXPECT_EQ(three, one_pod | two_pod); + EXPECT_EQ(one, three & one_pod); + EXPECT_EQ(one, three_pod & one); + EXPECT_EQ(one, three_pod & one_pod); + EXPECT_EQ(two, three ^ one_pod); + EXPECT_EQ(two, three_pod ^ one); + EXPECT_EQ(two, three_pod ^ one_pod); + EXPECT_EQ(two, three & (~one)); + EXPECT_EQ(three, ~~three); + + EXPECT_EQ(two, two_pod << 0); + EXPECT_EQ(two, one_pod << 1); + EXPECT_EQ(big, one_pod << 64); + EXPECT_EQ(zero, one_pod << 128); + EXPECT_EQ(two, two_pod >> 0); + EXPECT_EQ(one, two_pod >> 1); + EXPECT_EQ(one, big_pod >> 64); + + EXPECT_EQ(one, zero + one_pod); + EXPECT_EQ(one, zero_pod + one); + EXPECT_EQ(one, zero_pod + one_pod); + EXPECT_EQ(one, two - one_pod); + EXPECT_EQ(one, two_pod - one); + EXPECT_EQ(one, two_pod - one_pod); +} + +TEST(Int128, OperatorAssignReturnRef) { + uint128 v(1); + (v += 4) -= 3; + EXPECT_EQ(2, v); +} + +TEST(Int128, Multiply) { + uint128 a, b, c; + + // Zero test. + a = 0; + b = 0; + c = a * b; + EXPECT_EQ(0, c); + + // Max carries. + a = uint128(0) - 1; + b = uint128(0) - 1; + c = a * b; + EXPECT_EQ(1, c); + + // Self-operation with max carries. + c = uint128(0) - 1; + c *= c; + EXPECT_EQ(1, c); + + // 1-bit x 1-bit. + for (int i = 0; i < 64; ++i) { + for (int j = 0; j < 64; ++j) { + a = uint128(1) << i; + b = uint128(1) << j; + c = a * b; + EXPECT_EQ(uint128(1) << (i+j), c); + } + } + + // Verified with dc. + a = uint128(uint64_t{0xffffeeeeddddccccu}, uint64_t{0xbbbbaaaa99998888u}); + b = uint128(uint64_t{0x7777666655554444u}, uint64_t{0x3333222211110000u}); + c = a * b; + EXPECT_EQ( + uint128(uint64_t{0x530EDA741C71D4C3u}, uint64_t{0xBF25975319080000u}), c); + EXPECT_EQ(0, c - b * a); + EXPECT_EQ(a * a - b * b, (a + b) * (a - b)); + + // Verified with dc. + a = uint128(uint64_t{0x0123456789abcdefu}, uint64_t{0xfedcba9876543210u}); + b = uint128(uint64_t{0x02468ace13579bdfu}, uint64_t{0xfdb97531eca86420u}); + c = a * b; + EXPECT_EQ( + uint128(uint64_t{0x97a87f4f261ba3f2u}, uint64_t{0x342d0bbf48948200u}), c); + EXPECT_EQ(0, c - b * a); + EXPECT_EQ(a*a - b*b, (a+b) * (a-b)); +} + +TEST(Int128, AliasTests) { + uint128 x1(1, 2); + uint128 x2(2, 4); + x1 += x1; + EXPECT_EQ(x2, x1); + + uint128 x3(1, static_cast(1) << 63); + uint128 x4(3, 0); + x3 += x3; + EXPECT_EQ(x4, x3); +} + +#ifdef PROTOBUF_HAS_DEATH_TEST +TEST(Int128, DivideByZeroCheckFails) { + uint128 a = 0; + uint128 b = 0; + EXPECT_DEATH(a / b, "Division or mod by zero:"); + a = 123; + EXPECT_DEATH(a / b, "Division or mod by zero:"); +} + +TEST(Int128, ModByZeroCheckFails) { + uint128 a = 0; + uint128 b = 0; + EXPECT_DEATH(a % b, "Division or mod by zero:"); + a = 123; + EXPECT_DEATH(a % b, "Division or mod by zero:"); +} +#endif // PROTOBUF_HAS_DEATH_TEST + +TEST(Int128, DivideAndMod) { + // a := q * b + r + uint128 a, b, q, r; + + // Zero test. + a = 0; + b = 123; + q = a / b; + r = a % b; + EXPECT_EQ(0, q); + EXPECT_EQ(0, r); + + a = uint128(uint64_t{0x530eda741c71d4c3u}, uint64_t{0xbf25975319080000u}); + q = uint128(uint64_t{0x4de2cab081u}, uint64_t{0x14c34ab4676e4babu}); + b = uint128(0x1110001); + r = uint128(0x3eb455); + ASSERT_EQ(a, q * b + r); // Sanity-check. + + uint128 result_q, result_r; + result_q = a / b; + result_r = a % b; + EXPECT_EQ(q, result_q); + EXPECT_EQ(r, result_r); + + // Try the other way around. + std::swap(q, b); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(q, result_q); + EXPECT_EQ(r, result_r); + // Restore. + std::swap(b, q); + + // Dividend < divisor; result should be q:0 r:. + std::swap(a, b); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(0, result_q); + EXPECT_EQ(a, result_r); + // Try the other way around. + std::swap(a, q); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(0, result_q); + EXPECT_EQ(a, result_r); + // Restore. + std::swap(q, a); + std::swap(b, a); + + // Try a large remainder. + b = a / 2 + 1; + uint128 expected_r(uint64_t{0x29876d3a0e38ea61u}, + uint64_t{0xdf92cba98c83ffffu}); + // Sanity checks. + ASSERT_EQ(a / 2 - 1, expected_r); + ASSERT_EQ(a, b + expected_r); + result_q = a / b; + result_r = a % b; + EXPECT_EQ(1, result_q); + EXPECT_EQ(expected_r, result_r); +} + +static uint64_t RandomUint64() { + uint64_t v1 = rand(); + uint64_t v2 = rand(); + uint64_t v3 = rand(); + return v1 * v2 + v3; +} + +TEST(Int128, DivideAndModRandomInputs) { + const int kNumIters = 1 << 18; + for (int i = 0; i < kNumIters; ++i) { + const uint128 a(RandomUint64(), RandomUint64()); + const uint128 b(RandomUint64(), RandomUint64()); + if (b == 0) { + continue; // Avoid a div-by-zero. + } + const uint128 q = a / b; + const uint128 r = a % b; + ASSERT_EQ(a, b * q + r); + } +} + +#ifdef GOOGLE_PROTOBUF_HAS_CONSTEXPR +TEST(Int128, ConstexprTest) { + constexpr uint128 zero; + constexpr uint128 one = 1; + constexpr uint128_pod pod = {2, 3}; + constexpr uint128 from_pod = pod; + constexpr uint128 minus_two = -2; + EXPECT_EQ(one, uint128(1)); + EXPECT_EQ(from_pod, uint128(2, 3)); + EXPECT_EQ(minus_two, uint128(-1ULL, -2ULL)); +} + +TEST(Int128, Traits) { + EXPECT_TRUE(std::is_trivially_copy_constructible::value); + EXPECT_TRUE(std::is_trivially_copy_assignable::value); + EXPECT_TRUE(std::is_trivially_destructible::value); +} +#endif // GOOGLE_PROTOBUF_HAS_CONSTEXPR + +TEST(Int128, OStream) { + struct { + uint128 val; + std::ios_base::fmtflags flags; + std::streamsize width; + char fill; + const char* rep; + } cases[] = { + // zero with different bases + {uint128(0), std::ios::dec, 0, '_', "0"}, + {uint128(0), std::ios::oct, 0, '_', "0"}, + {uint128(0), std::ios::hex, 0, '_', "0"}, + // crossover between lo_ and hi_ + {uint128(0, -1), std::ios::dec, 0, '_', "18446744073709551615"}, + {uint128(0, -1), std::ios::oct, 0, '_', "1777777777777777777777"}, + {uint128(0, -1), std::ios::hex, 0, '_', "ffffffffffffffff"}, + {uint128(1, 0), std::ios::dec, 0, '_', "18446744073709551616"}, + {uint128(1, 0), std::ios::oct, 0, '_', "2000000000000000000000"}, + {uint128(1, 0), std::ios::hex, 0, '_', "10000000000000000"}, + // just the top bit + {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::dec, 0, '_', + "170141183460469231731687303715884105728"}, + {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::oct, 0, '_', + "2000000000000000000000000000000000000000000"}, + {uint128(uint64_t{0x8000000000000000u}, 0), std::ios::hex, 0, '_', + "80000000000000000000000000000000"}, + // maximum uint128 value + {uint128(-1, -1), std::ios::dec, 0, '_', + "340282366920938463463374607431768211455"}, + {uint128(-1, -1), std::ios::oct, 0, '_', + "3777777777777777777777777777777777777777777"}, + {uint128(-1, -1), std::ios::hex, 0, '_', + "ffffffffffffffffffffffffffffffff"}, + // uppercase + {uint128(-1, -1), std::ios::hex | std::ios::uppercase, 0, '_', + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"}, + // showbase + {uint128(1), std::ios::dec | std::ios::showbase, 0, '_', "1"}, + {uint128(1), std::ios::oct | std::ios::showbase, 0, '_', "01"}, + {uint128(1), std::ios::hex | std::ios::showbase, 0, '_', "0x1"}, + // showbase does nothing on zero + {uint128(0), std::ios::dec | std::ios::showbase, 0, '_', "0"}, + {uint128(0), std::ios::oct | std::ios::showbase, 0, '_', "0"}, + {uint128(0), std::ios::hex | std::ios::showbase, 0, '_', "0"}, + // showpos does nothing on unsigned types + {uint128(1), std::ios::dec | std::ios::showpos, 0, '_', "1"}, + // padding + {uint128(9), std::ios::dec, 6, '_', "_____9"}, + {uint128(12345), std::ios::dec, 6, '_', "_12345"}, + // left adjustment + {uint128(9), std::ios::dec | std::ios::left, 6, '_', "9_____"}, + {uint128(12345), std::ios::dec | std::ios::left, 6, '_', "12345_"}, + }; + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(cases); ++i) { + std::ostringstream os; + os.flags(cases[i].flags); + os.width(cases[i].width); + os.fill(cases[i].fill); + os << cases[i].val; + EXPECT_EQ(cases[i].rep, os.str()); + } +} +} // namespace protobuf +} // namespace google + +#include diff --git a/libs/protobuf/src/google/protobuf/stubs/logging.h b/libs/protobuf/src/google/protobuf/stubs/logging.h index 004c557..8ecc2fa 100644 --- a/libs/protobuf/src/google/protobuf/stubs/logging.h +++ b/libs/protobuf/src/google/protobuf/stubs/logging.h @@ -31,12 +31,12 @@ #ifndef GOOGLE_PROTOBUF_STUBS_LOGGING_H_ #define GOOGLE_PROTOBUF_STUBS_LOGGING_H_ -#include "absl/status/status.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/port.h" +#include +#include +#include +#include -// Must be last. -#include "google/protobuf/port_def.inc" // NOLINT +#include // =================================================================== // emulates google3/base/logging.h @@ -86,8 +86,8 @@ class PROTOBUF_EXPORT LogMessage { LogMessage& operator<<(unsigned long long value); LogMessage& operator<<(double value); LogMessage& operator<<(void* value); - LogMessage& operator<<(absl::string_view value); - LogMessage& operator<<(const absl::Status& status); + LogMessage& operator<<(const StringPiece& value); + LogMessage& operator<<(const util::Status& status); LogMessage& operator<<(const uint128& value); private: @@ -234,6 +234,6 @@ class PROTOBUF_EXPORT LogSilencer { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" // NOLINT +#include #endif // GOOGLE_PROTOBUF_STUBS_LOGGING_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/macros.h b/libs/protobuf/src/google/protobuf/stubs/macros.h new file mode 100644 index 0000000..ae9a8b9 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/macros.h @@ -0,0 +1,93 @@ +// 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_MACROS_H__ +#define GOOGLE_PROTOBUF_MACROS_H__ + +namespace google { +namespace protobuf { + +#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS +#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete + +#undef GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS +#define GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName() = delete; \ + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete + +// =================================================================== +// from google3/base/basictypes.h + +// The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr. +// The expression is a compile-time constant, and therefore can be +// used in defining new arrays, for example. +// +// GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error +// +// "warning: division by zero in ..." +// +// when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer. +// You should only use GOOGLE_ARRAYSIZE on statically allocated arrays. +// +// The following comments are on the implementation details, and can +// be ignored by the users. +// +// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in +// the array) and sizeof(*(arr)) (the # of bytes in one array +// element). If the former is divisible by the latter, perhaps arr is +// indeed an array, in which case the division result is the # of +// elements in the array. Otherwise, arr cannot possibly be an array, +// and we generate a compiler error to prevent the code from +// compiling. +// +// Since the size of bool is implementation-defined, we need to cast +// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final +// result has type size_t. +// +// This macro is not perfect as it wrongfully accepts certain +// pointers, namely where the pointer size is divisible by the pointee +// size. Since all our code has to go through a 32-bit compiler, +// where a pointer is 4 bytes, this means all pointers to a type whose +// size is 3 or greater than 4 will be (righteously) rejected. +// +// Kudos to Jorg Brown for this simple and elegant implementation. + +#undef GOOGLE_ARRAYSIZE +#define GOOGLE_ARRAYSIZE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast(!(sizeof(a) % sizeof(*(a))))) + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_MACROS_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/map_util.h b/libs/protobuf/src/google/protobuf/stubs/map_util.h new file mode 100644 index 0000000..24e098a --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/map_util.h @@ -0,0 +1,769 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2014 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. + +// from google3/util/gtl/map_util.h +// Author: Anton Carver + +#ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ +#define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ + +#include +#include +#include +#include +#include + +#include + +namespace google { +namespace protobuf { +namespace internal { +// Local implementation of RemoveConst to avoid including base/type_traits.h. +template struct RemoveConst { typedef T type; }; +template struct RemoveConst : RemoveConst {}; +} // namespace internal + +// +// Find*() +// + +// Returns a const reference to the value associated with the given key if it +// exists. Crashes otherwise. +// +// This is intended as a replacement for operator[] as an rvalue (for reading) +// when the key is guaranteed to exist. +// +// operator[] for lookup is discouraged for several reasons: +// * It has a side-effect of inserting missing keys +// * It is not thread-safe (even when it is not inserting, it can still +// choose to resize the underlying storage) +// * It invalidates iterators (when it chooses to resize) +// * It default constructs a value object even if it doesn't need to +// +// This version assumes the key is printable, and includes it in the fatal log +// message. +template +const typename Collection::value_type::second_type& +FindOrDie(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; + return it->second; +} + +// Same as above, but returns a non-const reference. +template +typename Collection::value_type::second_type& +FindOrDie(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; + return it->second; +} + +// Same as FindOrDie above, but doesn't log the key on failure. +template +const typename Collection::value_type::second_type& +FindOrDieNoPrint(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found"; + return it->second; +} + +// Same as above, but returns a non-const reference. +template +typename Collection::value_type::second_type& +FindOrDieNoPrint(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "Map key not found"; + return it->second; +} + +// Returns a const reference to the value associated with the given key if it +// exists, otherwise returns a const reference to the provided default value. +// +// WARNING: If a temporary object is passed as the default "value," +// this function will return a reference to that temporary object, +// which will be destroyed at the end of the statement. A common +// example: if you have a map with string values, and you pass a char* +// as the default "value," either use the returned value immediately +// or store it in a string (not string&). +// Details: http://go/findwithdefault +template +const typename Collection::value_type::second_type& +FindWithDefault(const Collection& collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return value; + } + return it->second; +} + +// Returns a pointer to the const value associated with the given key if it +// exists, or nullptr otherwise. +template +const typename Collection::value_type::second_type* +FindOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return &it->second; +} + +// Same as above but returns a pointer to the non-const value. +template +typename Collection::value_type::second_type* +FindOrNull(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + return &it->second; +} + +// Returns the pointer value associated with the given key. If none is found, +// nullptr is returned. The function is designed to be used with a map of keys to +// pointers. +// +// This function does not distinguish between a missing key and a key mapped +// to nullptr. +template +typename Collection::value_type::second_type +FindPtrOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return typename Collection::value_type::second_type(); + } + return it->second; +} + +// Same as above, except takes non-const reference to collection. +// +// This function is needed for containers that propagate constness to the +// pointee, such as boost::ptr_map. +template +typename Collection::value_type::second_type +FindPtrOrNull(Collection& collection, // NOLINT + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection.find(key); + if (it == collection.end()) { + return typename Collection::value_type::second_type(); + } + return it->second; +} + +// Finds the pointer value associated with the given key in a map whose values +// are linked_ptrs. Returns nullptr if key is not found. +template +typename Collection::value_type::second_type::element_type* +FindLinkedPtrOrNull(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return 0; + } + // Since linked_ptr::get() is a const member returning a non const, + // we do not need a version of this function taking a non const collection. + return it->second.get(); +} + +// Same as above, but dies if the key is not found. +template +typename Collection::value_type::second_type::element_type& +FindLinkedPtrOrDie(const Collection& collection, + const typename Collection::value_type::first_type& key) { + typename Collection::const_iterator it = collection.find(key); + GOOGLE_CHECK(it != collection.end()) << "key not found: " << key; + // Since linked_ptr::operator*() is a const member returning a non const, + // we do not need a version of this function taking a non const collection. + return *it->second; +} + +// Finds the value associated with the given key and copies it to *value (if not +// nullptr). Returns false if the key was not found, true otherwise. +template +bool FindCopy(const Collection& collection, + const Key& key, + Value* const value) { + typename Collection::const_iterator it = collection.find(key); + if (it == collection.end()) { + return false; + } + if (value) { + *value = it->second; + } + return true; +} + +// +// Contains*() +// + +// Returns true if and only if the given collection contains the given key. +template +bool ContainsKey(const Collection& collection, const Key& key) { + return collection.find(key) != collection.end(); +} + +// Returns true if and only if the given collection contains the given key-value +// pair. +template +bool ContainsKeyValuePair(const Collection& collection, + const Key& key, + const Value& value) { + typedef typename Collection::const_iterator const_iterator; + std::pair range = collection.equal_range(key); + for (const_iterator it = range.first; it != range.second; ++it) { + if (it->second == value) { + return true; + } + } + return false; +} + +// +// Insert*() +// + +// Inserts the given key-value pair into the collection. Returns true if and +// only if the key from the given pair didn't previously exist. Otherwise, the +// value in the map is replaced with the value from the given pair. +template +bool InsertOrUpdate(Collection* const collection, + const typename Collection::value_type& vt) { + std::pair ret = collection->insert(vt); + if (!ret.second) { + // update + ret.first->second = vt.second; + return false; + } + return true; +} + +// Same as above, except that the key and value are passed separately. +template +bool InsertOrUpdate(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return InsertOrUpdate( + collection, typename Collection::value_type(key, value)); +} + +// Inserts/updates all the key-value pairs from the range defined by the +// iterators "first" and "last" into the given collection. +template +void InsertOrUpdateMany(Collection* const collection, + InputIterator first, InputIterator last) { + for (; first != last; ++first) { + InsertOrUpdate(collection, *first); + } +} + +// Change the value associated with a particular key in a map or hash_map +// of the form map which owns the objects pointed to by the +// value pointers. If there was an existing value for the key, it is deleted. +// True indicates an insert took place, false indicates an update + delete. +template +bool InsertAndDeleteExisting( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + std::pair ret = + collection->insert(typename Collection::value_type(key, value)); + if (!ret.second) { + delete ret.first->second; + ret.first->second = value; + return false; + } + return true; +} + +// Inserts the given key and value into the given collection if and only if the +// given key did NOT already exist in the collection. If the key previously +// existed in the collection, the value is not changed. Returns true if the +// key-value pair was inserted; returns false if the key was already present. +template +bool InsertIfNotPresent(Collection* const collection, + const typename Collection::value_type& vt) { + return collection->insert(vt).second; +} + +// Same as above except the key and value are passed separately. +template +bool InsertIfNotPresent( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return InsertIfNotPresent( + collection, typename Collection::value_type(key, value)); +} + +// Same as above except dies if the key already exists in the collection. +template +void InsertOrDie(Collection* const collection, + const typename Collection::value_type& value) { + GOOGLE_CHECK(InsertIfNotPresent(collection, value)) + << "duplicate value: " << value; +} + +// Same as above except doesn't log the value on error. +template +void InsertOrDieNoPrint(Collection* const collection, + const typename Collection::value_type& value) { + GOOGLE_CHECK(InsertIfNotPresent(collection, value)) << "duplicate value."; +} + +// Inserts the key-value pair into the collection. Dies if key was already +// present. +template +void InsertOrDie(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) + << "duplicate key: " << key; +} + +// Same as above except doesn't log the key on error. +template +void InsertOrDieNoPrint( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + GOOGLE_CHECK(InsertIfNotPresent(collection, key, data)) << "duplicate key."; +} + +// Inserts a new key and default-initialized value. Dies if the key was already +// present. Returns a reference to the value. Example usage: +// +// map m; +// SomeProto& proto = InsertKeyOrDie(&m, 3); +// proto.set_field("foo"); +template +typename Collection::value_type::second_type& InsertKeyOrDie( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type value_type; + std::pair res = + collection->insert(value_type(key, typename value_type::second_type())); + GOOGLE_CHECK(res.second) << "duplicate key: " << key; + return res.first->second; +} + +// +// Lookup*() +// + +// Looks up a given key and value pair in a collection and inserts the key-value +// pair if it's not already present. Returns a reference to the value associated +// with the key. +template +typename Collection::value_type::second_type& +LookupOrInsert(Collection* const collection, + const typename Collection::value_type& vt) { + return collection->insert(vt).first->second; +} + +// Same as above except the key-value are passed separately. +template +typename Collection::value_type::second_type& +LookupOrInsert(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value) { + return LookupOrInsert( + collection, typename Collection::value_type(key, value)); +} + +// Counts the number of equivalent elements in the given "sequence", and stores +// the results in "count_map" with element as the key and count as the value. +// +// Example: +// vector v = {"a", "b", "c", "a", "b"}; +// map m; +// AddTokenCounts(v, 1, &m); +// assert(m["a"] == 2); +// assert(m["b"] == 2); +// assert(m["c"] == 1); +template +void AddTokenCounts( + const Sequence& sequence, + const typename Collection::value_type::second_type& increment, + Collection* const count_map) { + for (typename Sequence::const_iterator it = sequence.begin(); + it != sequence.end(); ++it) { + typename Collection::value_type::second_type& value = + LookupOrInsert(count_map, *it, + typename Collection::value_type::second_type()); + value += increment; + } +} + +// Returns a reference to the value associated with key. If not found, a value +// is default constructed on the heap and added to the map. +// +// This function is useful for containers of the form map, where +// inserting a new key, value pair involves constructing a new heap-allocated +// Value, and storing a pointer to that in the collection. +template +typename Collection::value_type::second_type& +LookupOrInsertNew(Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename std::iterator_traits< + typename Collection::value_type::second_type>::value_type Element; + std::pair ret = + collection->insert(typename Collection::value_type( + key, + static_cast(nullptr))); + if (ret.second) { + ret.first->second = new Element(); + } + return ret.first->second; +} + +// Same as above but constructs the value using the single-argument constructor +// and the given "arg". +template +typename Collection::value_type::second_type& +LookupOrInsertNew(Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename std::iterator_traits< + typename Collection::value_type::second_type>::value_type Element; + std::pair ret = + collection->insert(typename Collection::value_type( + key, + static_cast(nullptr))); + if (ret.second) { + ret.first->second = new Element(arg); + } + return ret.first->second; +} + +// Lookup of linked/shared pointers is used in two scenarios: +// +// Use LookupOrInsertNewLinkedPtr if the container owns the elements. +// In this case it is fine working with the raw pointer as long as it is +// guaranteed that no other thread can delete/update an accessed element. +// A mutex will need to lock the container operation as well as the use +// of the returned elements. Finding an element may be performed using +// FindLinkedPtr*(). +// +// Use LookupOrInsertNewSharedPtr if the container does not own the elements +// for their whole lifetime. This is typically the case when a reader allows +// parallel updates to the container. In this case a Mutex only needs to lock +// container operations, but all element operations must be performed on the +// shared pointer. Finding an element must be performed using FindPtr*() and +// cannot be done with FindLinkedPtr*() even though it compiles. + +// Lookup a key in a map or hash_map whose values are linked_ptrs. If it is +// missing, set collection[key].reset(new Value::element_type) and return that. +// Value::element_type must be default constructable. +template +typename Collection::value_type::second_type::element_type* +LookupOrInsertNewLinkedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type::second_type Value; + std::pair ret = + collection->insert(typename Collection::value_type(key, Value())); + if (ret.second) { + ret.first->second.reset(new typename Value::element_type); + } + return ret.first->second.get(); +} + +// A variant of LookupOrInsertNewLinkedPtr where the value is constructed using +// a single-parameter constructor. Note: the constructor argument is computed +// even if it will not be used, so only values cheap to compute should be passed +// here. On the other hand it does not matter how expensive the construction of +// the actual stored value is, as that only occurs if necessary. +template +typename Collection::value_type::second_type::element_type* +LookupOrInsertNewLinkedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename Collection::value_type::second_type Value; + std::pair ret = + collection->insert(typename Collection::value_type(key, Value())); + if (ret.second) { + ret.first->second.reset(new typename Value::element_type(arg)); + } + return ret.first->second.get(); +} + +// Lookup a key in a map or hash_map whose values are shared_ptrs. If it is +// missing, set collection[key].reset(new Value::element_type). Unlike +// LookupOrInsertNewLinkedPtr, this function returns the shared_ptr instead of +// the raw pointer. Value::element_type must be default constructable. +template +typename Collection::value_type::second_type& +LookupOrInsertNewSharedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typedef typename Collection::value_type::second_type SharedPtr; + typedef typename Collection::value_type::second_type::element_type Element; + std::pair ret = + collection->insert(typename Collection::value_type(key, SharedPtr())); + if (ret.second) { + ret.first->second.reset(new Element()); + } + return ret.first->second; +} + +// A variant of LookupOrInsertNewSharedPtr where the value is constructed using +// a single-parameter constructor. Note: the constructor argument is computed +// even if it will not be used, so only values cheap to compute should be passed +// here. On the other hand it does not matter how expensive the construction of +// the actual stored value is, as that only occurs if necessary. +template +typename Collection::value_type::second_type& +LookupOrInsertNewSharedPtr( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const Arg& arg) { + typedef typename Collection::value_type::second_type SharedPtr; + typedef typename Collection::value_type::second_type::element_type Element; + std::pair ret = + collection->insert(typename Collection::value_type(key, SharedPtr())); + if (ret.second) { + ret.first->second.reset(new Element(arg)); + } + return ret.first->second; +} + +// +// Misc Utility Functions +// + +// Updates the value associated with the given key. If the key was not already +// present, then the key-value pair are inserted and "previous" is unchanged. If +// the key was already present, the value is updated and "*previous" will +// contain a copy of the old value. +// +// InsertOrReturnExisting has complementary behavior that returns the +// address of an already existing value, rather than updating it. +template +bool UpdateReturnCopy(Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& value, + typename Collection::value_type::second_type* previous) { + std::pair ret = + collection->insert(typename Collection::value_type(key, value)); + if (!ret.second) { + // update + if (previous) { + *previous = ret.first->second; + } + ret.first->second = value; + return true; + } + return false; +} + +// Same as above except that the key and value are passed as a pair. +template +bool UpdateReturnCopy(Collection* const collection, + const typename Collection::value_type& vt, + typename Collection::value_type::second_type* previous) { + std::pair ret = collection->insert(vt); + if (!ret.second) { + // update + if (previous) { + *previous = ret.first->second; + } + ret.first->second = vt.second; + return true; + } + return false; +} + +// Tries to insert the given key-value pair into the collection. Returns nullptr if +// the insert succeeds. Otherwise, returns a pointer to the existing value. +// +// This complements UpdateReturnCopy in that it allows to update only after +// verifying the old value and still insert quickly without having to look up +// twice. Unlike UpdateReturnCopy this also does not come with the issue of an +// undefined previous* in case new data was inserted. +template +typename Collection::value_type::second_type* InsertOrReturnExisting( + Collection* const collection, const typename Collection::value_type& vt) { + std::pair ret = collection->insert(vt); + if (ret.second) { + return nullptr; // Inserted, no existing previous value. + } else { + return &ret.first->second; // Return address of already existing value. + } +} + +// Same as above, except for explicit key and data. +template +typename Collection::value_type::second_type* InsertOrReturnExisting( + Collection* const collection, + const typename Collection::value_type::first_type& key, + const typename Collection::value_type::second_type& data) { + return InsertOrReturnExisting(collection, + typename Collection::value_type(key, data)); +} + +// Erases the collection item identified by the given key, and returns the value +// associated with that key. It is assumed that the value (i.e., the +// mapped_type) is a pointer. Returns nullptr if the key was not found in the +// collection. +// +// Examples: +// map my_map; +// +// One line cleanup: +// delete EraseKeyReturnValuePtr(&my_map, "abc"); +// +// Use returned value: +// std::unique_ptr value_ptr( +// EraseKeyReturnValuePtr(&my_map, "abc")); +// if (value_ptr.get()) +// value_ptr->DoSomething(); +// +template +typename Collection::value_type::second_type EraseKeyReturnValuePtr( + Collection* const collection, + const typename Collection::value_type::first_type& key) { + typename Collection::iterator it = collection->find(key); + if (it == collection->end()) { + return nullptr; + } + typename Collection::value_type::second_type v = it->second; + collection->erase(it); + return v; +} + +// Inserts all the keys from map_container into key_container, which must +// support insert(MapContainer::key_type). +// +// Note: any initial contents of the key_container are not cleared. +template +void InsertKeysFromMap(const MapContainer& map_container, + KeyContainer* key_container) { + GOOGLE_CHECK(key_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->insert(it->first); + } +} + +// Appends all the keys from map_container into key_container, which must +// support push_back(MapContainer::key_type). +// +// Note: any initial contents of the key_container are not cleared. +template +void AppendKeysFromMap(const MapContainer& map_container, + KeyContainer* key_container) { + GOOGLE_CHECK(key_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->push_back(it->first); + } +} + +// A more specialized overload of AppendKeysFromMap to optimize reallocations +// for the common case in which we're appending keys to a vector and hence can +// (and sometimes should) call reserve() first. +// +// (It would be possible to play SFINAE games to call reserve() for any +// container that supports it, but this seems to get us 99% of what we need +// without the complexity of a SFINAE-based solution.) +template +void AppendKeysFromMap(const MapContainer& map_container, + std::vector* key_container) { + GOOGLE_CHECK(key_container != nullptr); + // We now have the opportunity to call reserve(). Calling reserve() every + // time is a bad idea for some use cases: libstdc++'s implementation of + // vector<>::reserve() resizes the vector's backing store to exactly the + // given size (unless it's already at least that big). Because of this, + // the use case that involves appending a lot of small maps (total size + // N) one by one to a vector would be O(N^2). But never calling reserve() + // loses the opportunity to improve the use case of adding from a large + // map to an empty vector (this improves performance by up to 33%). A + // number of heuristics are possible; see the discussion in + // cl/34081696. Here we use the simplest one. + if (key_container->empty()) { + key_container->reserve(map_container.size()); + } + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + key_container->push_back(it->first); + } +} + +// Inserts all the values from map_container into value_container, which must +// support push_back(MapContainer::mapped_type). +// +// Note: any initial contents of the value_container are not cleared. +template +void AppendValuesFromMap(const MapContainer& map_container, + ValueContainer* value_container) { + GOOGLE_CHECK(value_container != nullptr); + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + value_container->push_back(it->second); + } +} + +// A more specialized overload of AppendValuesFromMap to optimize reallocations +// for the common case in which we're appending values to a vector and hence +// can (and sometimes should) call reserve() first. +// +// (It would be possible to play SFINAE games to call reserve() for any +// container that supports it, but this seems to get us 99% of what we need +// without the complexity of a SFINAE-based solution.) +template +void AppendValuesFromMap(const MapContainer& map_container, + std::vector* value_container) { + GOOGLE_CHECK(value_container != nullptr); + // See AppendKeysFromMap for why this is done. + if (value_container->empty()) { + value_container->reserve(map_container.size()); + } + for (typename MapContainer::const_iterator it = map_container.begin(); + it != map_container.end(); ++it) { + value_container->push_back(it->second); + } +} + +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/mathutil.h b/libs/protobuf/src/google/protobuf/stubs/mathutil.h index 908b245..1d16bce 100644 --- a/libs/protobuf/src/google/protobuf/stubs/mathutil.h +++ b/libs/protobuf/src/google/protobuf/stubs/mathutil.h @@ -30,13 +30,12 @@ #ifndef GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ #define GOOGLE_PROTOBUF_STUBS_MATHUTIL_H_ -#include - #include +#include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/stubs/mutex.h b/libs/protobuf/src/google/protobuf/stubs/mutex.h new file mode 100644 index 0000000..c459991 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/mutex.h @@ -0,0 +1,218 @@ +// Copyright (c) 2006, Google Inc. +// All rights reserved. +// +// 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_STUBS_MUTEX_H_ +#define GOOGLE_PROTOBUF_STUBS_MUTEX_H_ + +#include + +#ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP + +#include + +// GetMessage conflicts with GeneratedMessageReflection::GetMessage(). +#ifdef GetMessage +#undef GetMessage +#endif + +#endif + +#include + +// Define thread-safety annotations for use below, if we are building with +// Clang. +#if defined(__clang__) && !defined(SWIG) +#define GOOGLE_PROTOBUF_ACQUIRE(...) \ + __attribute__((acquire_capability(__VA_ARGS__))) +#define GOOGLE_PROTOBUF_RELEASE(...) \ + __attribute__((release_capability(__VA_ARGS__))) +#define GOOGLE_PROTOBUF_SCOPED_CAPABILITY __attribute__((scoped_lockable)) +#define GOOGLE_PROTOBUF_CAPABILITY(x) __attribute__((capability(x))) +#else +#define GOOGLE_PROTOBUF_ACQUIRE(...) +#define GOOGLE_PROTOBUF_RELEASE(...) +#define GOOGLE_PROTOBUF_SCOPED_CAPABILITY +#define GOOGLE_PROTOBUF_CAPABILITY(x) +#endif + +#include + +// =================================================================== +// emulates google3/base/mutex.h +namespace google { +namespace protobuf { +namespace internal { + +#define GOOGLE_PROTOBUF_LINKER_INITIALIZED + +#ifdef GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP + +// This class is a lightweight replacement for std::mutex on Windows platforms. +// std::mutex does not work on Windows XP SP2 with the latest VC++ libraries, +// because it utilizes the Concurrency Runtime that is only supported on Windows +// XP SP3 and above. +class PROTOBUF_EXPORT CriticalSectionLock { + public: + CriticalSectionLock() { InitializeCriticalSection(&critical_section_); } + ~CriticalSectionLock() { DeleteCriticalSection(&critical_section_); } + void lock() { EnterCriticalSection(&critical_section_); } + void unlock() { LeaveCriticalSection(&critical_section_); } + + private: + CRITICAL_SECTION critical_section_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CriticalSectionLock); +}; + +#endif + +// In MSVC std::mutex does not have a constexpr constructor. +// This wrapper makes the constructor constexpr. +template +class CallOnceInitializedMutex { + public: + constexpr CallOnceInitializedMutex() : flag_{}, buf_{} {} + ~CallOnceInitializedMutex() { get().~T(); } + + void lock() { get().lock(); } + void unlock() { get().unlock(); } + + private: + T& get() { + std::call_once(flag_, [&] { ::new (static_cast(&buf_)) T(); }); + return reinterpret_cast(buf_); + } + + std::once_flag flag_; + alignas(T) char buf_[sizeof(T)]; +}; + +// Mutex is a natural type to wrap. As both google and other organization have +// specialized mutexes. gRPC also provides an injection mechanism for custom +// mutexes. +class GOOGLE_PROTOBUF_CAPABILITY("mutex") PROTOBUF_EXPORT WrappedMutex { + public: +#if defined(__QNX__) + constexpr WrappedMutex() = default; +#else + constexpr WrappedMutex() {} +#endif + void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); } + void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); } + // Crash if this Mutex is not held exclusively by this thread. + // May fail to crash when it should; will never crash when it should not. + void AssertHeld() const {} + + private: +#if defined(GOOGLE_PROTOBUF_SUPPORT_WINDOWS_XP) + CallOnceInitializedMutex mu_{}; +#elif defined(_WIN32) + CallOnceInitializedMutex mu_{}; +#else + std::mutex mu_{}; +#endif +}; + +using Mutex = WrappedMutex; + +// MutexLock(mu) acquires mu when constructed and releases it when destroyed. +class GOOGLE_PROTOBUF_SCOPED_CAPABILITY PROTOBUF_EXPORT MutexLock { + public: + explicit MutexLock(Mutex* mu) GOOGLE_PROTOBUF_ACQUIRE(mu) : mu_(mu) { + this->mu_->Lock(); + } + ~MutexLock() GOOGLE_PROTOBUF_RELEASE() { this->mu_->Unlock(); } + + private: + Mutex *const mu_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock); +}; + +// TODO(kenton): Implement these? Hard to implement portably. +typedef MutexLock ReaderMutexLock; +typedef MutexLock WriterMutexLock; + +// MutexLockMaybe is like MutexLock, but is a no-op when mu is nullptr. +class PROTOBUF_EXPORT MutexLockMaybe { + public: + explicit MutexLockMaybe(Mutex *mu) : + mu_(mu) { if (this->mu_ != nullptr) { this->mu_->Lock(); } } + ~MutexLockMaybe() { if (this->mu_ != nullptr) { this->mu_->Unlock(); } } + private: + Mutex *const mu_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe); +}; + +#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) +template +class ThreadLocalStorage { + public: + ThreadLocalStorage() { + pthread_key_create(&key_, &ThreadLocalStorage::Delete); + } + ~ThreadLocalStorage() { + pthread_key_delete(key_); + } + T* Get() { + T* result = static_cast(pthread_getspecific(key_)); + if (result == nullptr) { + result = new T(); + pthread_setspecific(key_, result); + } + return result; + } + private: + static void Delete(void* value) { + delete static_cast(value); + } + pthread_key_t key_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ThreadLocalStorage); +}; +#endif + +} // namespace internal + +// We made these internal so that they would show up as such in the docs, +// but we don't want to stick "internal::" in front of them everywhere. +using internal::Mutex; +using internal::MutexLock; +using internal::ReaderMutexLock; +using internal::WriterMutexLock; +using internal::MutexLockMaybe; + +} // namespace protobuf +} // namespace google + +#undef GOOGLE_PROTOBUF_ACQUIRE +#undef GOOGLE_PROTOBUF_RELEASE + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_ diff --git a/libs/protobuf/src/google/protobuf/arena_config.cc b/libs/protobuf/src/google/protobuf/stubs/once.h similarity index 82% rename from libs/protobuf/src/google/protobuf/arena_config.cc rename to libs/protobuf/src/google/protobuf/stubs/once.h index 813f7d0..070d36d 100644 --- a/libs/protobuf/src/google/protobuf/arena_config.cc +++ b/libs/protobuf/src/google/protobuf/stubs/once.h @@ -28,26 +28,28 @@ // (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/arena_config.h" +#ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__ +#define GOOGLE_PROTOBUF_STUBS_ONCE_H__ -#include -#include +#include +#include -// Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace internal { -PROTOBUF_CONSTINIT const size_t kDefaultDefaultArenaMaxBlockSize = 8 << 10; +using once_flag = std::once_flag; +template +void call_once(Args&&... args ) { + std::call_once(std::forward(args)...); +} -namespace arena_config_internal { - -std::atomic default_arena_max_block_size{ - kDefaultDefaultArenaMaxBlockSize}; - -} // namespace arena_config_internal } // namespace internal } // namespace protobuf } // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_ONCE_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/port.h b/libs/protobuf/src/google/protobuf/stubs/port.h index d459a94..b074cb1 100644 --- a/libs/protobuf/src/google/protobuf/stubs/port.h +++ b/libs/protobuf/src/google/protobuf/stubs/port.h @@ -32,17 +32,15 @@ #define GOOGLE_PROTOBUF_STUBS_PORT_H_ #include +#include #include +#include +#include #include -#include -#include -#include +#include -#include "google/protobuf/stubs/platform_macros.h" - -// Must be last. -#include "google/protobuf/port_def.inc" // NOLINT +#include #undef PROTOBUF_LITTLE_ENDIAN #ifdef _WIN32 @@ -128,6 +126,8 @@ namespace google { namespace protobuf { +using ConstStringParam = const std::string &; + typedef unsigned int uint; typedef int8_t int8; @@ -147,6 +147,57 @@ static const int64 kint64min = -kint64max - 1; static const uint32 kuint32max = 0xFFFFFFFFu; static const uint64 kuint64max = uint64_t{0xFFFFFFFFFFFFFFFFu}; +#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) ||\ + defined(MEMORY_SANITIZER) + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus +uint16_t __sanitizer_unaligned_load16(const void *p); +uint32_t __sanitizer_unaligned_load32(const void *p); +uint64_t __sanitizer_unaligned_load64(const void *p); +void __sanitizer_unaligned_store16(void *p, uint16_t v); +void __sanitizer_unaligned_store32(void *p, uint32_t v); +void __sanitizer_unaligned_store64(void *p, uint64_t v); +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +inline uint16_t GOOGLE_UNALIGNED_LOAD16(const void *p) { + return __sanitizer_unaligned_load16(p); +} + +inline uint32_t GOOGLE_UNALIGNED_LOAD32(const void *p) { + return __sanitizer_unaligned_load32(p); +} + +inline uint64_t GOOGLE_UNALIGNED_LOAD64(const void *p) { + return __sanitizer_unaligned_load64(p); +} + +inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16_t v) { + __sanitizer_unaligned_store16(p, v); +} + +inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32_t v) { + __sanitizer_unaligned_store32(p, v); +} + +inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64_t v) { + __sanitizer_unaligned_store64(p, v); +} + +#elif defined(GOOGLE_PROTOBUF_USE_UNALIGNED) && GOOGLE_PROTOBUF_USE_UNALIGNED + +#define GOOGLE_UNALIGNED_LOAD16(_p) (*reinterpret_cast(_p)) +#define GOOGLE_UNALIGNED_LOAD32(_p) (*reinterpret_cast(_p)) +#define GOOGLE_UNALIGNED_LOAD64(_p) (*reinterpret_cast(_p)) + +#define GOOGLE_UNALIGNED_STORE16(_p, _val) (*reinterpret_cast(_p) = (_val)) +#define GOOGLE_UNALIGNED_STORE32(_p, _val) (*reinterpret_cast(_p) = (_val)) +#define GOOGLE_UNALIGNED_STORE64(_p, _val) (*reinterpret_cast(_p) = (_val)) + +#else inline uint16_t GOOGLE_UNALIGNED_LOAD16(const void *p) { uint16_t t; memcpy(&t, p, sizeof t); @@ -176,6 +227,7 @@ inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32_t v) { inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64_t v) { memcpy(p, &v, sizeof v); } +#endif #if defined(GOOGLE_PROTOBUF_OS_NACL) \ || (defined(__ANDROID__) && defined(__clang__) \ @@ -230,6 +282,69 @@ static inline uint64_t bswap_64(uint64_t x) { #endif +// =================================================================== +// from google3/util/bits/bits.h + +class Bits { + public: + static uint32_t Log2FloorNonZero(uint32_t n) { +#if defined(__GNUC__) + return 31 ^ static_cast(__builtin_clz(n)); +#elif defined(_MSC_VER) + unsigned long where; + _BitScanReverse(&where, n); + return where; +#else + return Log2FloorNonZero_Portable(n); +#endif + } + + static uint32_t Log2FloorNonZero64(uint64_t n) { + // Older versions of clang run into an instruction-selection failure when + // it encounters __builtin_clzll: + // https://bugs.chromium.org/p/nativeclient/issues/detail?id=4395 + // This includes arm-nacl-clang and clang in older Android NDK versions. + // To work around this, when we build with those we use the portable + // implementation instead. +#if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_USE_PORTABLE_LOG2) + return 63 ^ static_cast(__builtin_clzll(n)); +#elif defined(_MSC_VER) && defined(_M_X64) + unsigned long where; + _BitScanReverse64(&where, n); + return where; +#else + return Log2FloorNonZero64_Portable(n); +#endif + } + private: + static int Log2FloorNonZero_Portable(uint32_t n) { + if (n == 0) + return -1; + int log = 0; + uint32_t value = n; + for (int i = 4; i >= 0; --i) { + int shift = (1 << i); + uint32_t x = value >> shift; + if (x != 0) { + value = x; + log += shift; + } + } + assert(value == 1); + return log; + } + + static int Log2FloorNonZero64_Portable(uint64_t n) { + const uint32_t topbits = static_cast(n >> 32); + if (topbits == 0) { + // Top bits are zero, so scan in bottom bits + return static_cast(Log2FloorNonZero(static_cast(n))); + } else { + return 32 + static_cast(Log2FloorNonZero(topbits)); + } + } +}; + // =================================================================== // from google3/util/endian/endian.h PROTOBUF_EXPORT uint32_t ghtonl(uint32_t x); @@ -293,6 +408,6 @@ class BigEndian { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_STUBS_PORT_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/status.cc b/libs/protobuf/src/google/protobuf/stubs/status.cc new file mode 100644 index 0000000..f5c0fa4 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/status.cc @@ -0,0 +1,262 @@ +// 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 + +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace status_internal { +namespace { + +inline std::string StatusCodeToString(StatusCode code) { + switch (code) { + case StatusCode::kOk: + return "OK"; + case StatusCode::kCancelled: + return "CANCELLED"; + case StatusCode::kUnknown: + return "UNKNOWN"; + case StatusCode::kInvalidArgument: + return "INVALID_ARGUMENT"; + case StatusCode::kDeadlineExceeded: + return "DEADLINE_EXCEEDED"; + case StatusCode::kNotFound: + return "NOT_FOUND"; + case StatusCode::kAlreadyExists: + return "ALREADY_EXISTS"; + case StatusCode::kPermissionDenied: + return "PERMISSION_DENIED"; + case StatusCode::kUnauthenticated: + return "UNAUTHENTICATED"; + case StatusCode::kResourceExhausted: + return "RESOURCE_EXHAUSTED"; + case StatusCode::kFailedPrecondition: + return "FAILED_PRECONDITION"; + case StatusCode::kAborted: + return "ABORTED"; + case StatusCode::kOutOfRange: + return "OUT_OF_RANGE"; + case StatusCode::kUnimplemented: + return "UNIMPLEMENTED"; + case StatusCode::kInternal: + return "INTERNAL"; + case StatusCode::kUnavailable: + return "UNAVAILABLE"; + case StatusCode::kDataLoss: + return "DATA_LOSS"; + } + + // No default clause, clang will abort if a code is missing from + // above switch. + return "UNKNOWN"; +} + +} // namespace + +Status::Status() : error_code_(StatusCode::kOk) {} + +Status::Status(StatusCode error_code, StringPiece error_message) + : error_code_(error_code) { + if (error_code != StatusCode::kOk) { + error_message_ = error_message.ToString(); + } +} + +Status::Status(const Status& other) + : error_code_(other.error_code_), error_message_(other.error_message_) { +} + +Status& Status::operator=(const Status& other) { + error_code_ = other.error_code_; + error_message_ = other.error_message_; + return *this; +} + +bool Status::operator==(const Status& x) const { + return error_code_ == x.error_code_ && + error_message_ == x.error_message_; +} + +std::string Status::ToString() const { + if (error_code_ == StatusCode::kOk) { + return "OK"; + } else { + if (error_message_.empty()) { + return StatusCodeToString(error_code_); + } else { + return StatusCodeToString(error_code_) + ":" + error_message_; + } + } +} + +Status OkStatus() { return Status(); } + +std::ostream& operator<<(std::ostream& os, const Status& x) { + os << x.ToString(); + return os; +} + +bool IsAborted(const Status& status) { + return status.code() == StatusCode::kAborted; +} + +bool IsAlreadyExists(const Status& status) { + return status.code() == StatusCode::kAlreadyExists; +} + +bool IsCancelled(const Status& status) { + return status.code() == StatusCode::kCancelled; +} + +bool IsDataLoss(const Status& status) { + return status.code() == StatusCode::kDataLoss; +} + +bool IsDeadlineExceeded(const Status& status) { + return status.code() == StatusCode::kDeadlineExceeded; +} + +bool IsFailedPrecondition(const Status& status) { + return status.code() == StatusCode::kFailedPrecondition; +} + +bool IsInternal(const Status& status) { + return status.code() == StatusCode::kInternal; +} + +bool IsInvalidArgument(const Status& status) { + return status.code() == StatusCode::kInvalidArgument; +} + +bool IsNotFound(const Status& status) { + return status.code() == StatusCode::kNotFound; +} + +bool IsOutOfRange(const Status& status) { + return status.code() == StatusCode::kOutOfRange; +} + +bool IsPermissionDenied(const Status& status) { + return status.code() == StatusCode::kPermissionDenied; +} + +bool IsResourceExhausted(const Status& status) { + return status.code() == StatusCode::kResourceExhausted; +} + +bool IsUnauthenticated(const Status& status) { + return status.code() == StatusCode::kUnauthenticated; +} + +bool IsUnavailable(const Status& status) { + return status.code() == StatusCode::kUnavailable; +} + +bool IsUnimplemented(const Status& status) { + return status.code() == StatusCode::kUnimplemented; +} + +bool IsUnknown(const Status& status) { + return status.code() == StatusCode::kUnknown; +} + +Status AbortedError(StringPiece message) { + return Status(StatusCode::kAborted, message); +} + +Status AlreadyExistsError(StringPiece message) { + return Status(StatusCode::kAlreadyExists, message); +} + +Status CancelledError(StringPiece message) { + return Status(StatusCode::kCancelled, message); +} + +Status DataLossError(StringPiece message) { + return Status(StatusCode::kDataLoss, message); +} + +Status DeadlineExceededError(StringPiece message) { + return Status(StatusCode::kDeadlineExceeded, message); +} + +Status FailedPreconditionError(StringPiece message) { + return Status(StatusCode::kFailedPrecondition, message); +} + +Status InternalError(StringPiece message) { + return Status(StatusCode::kInternal, message); +} + +Status InvalidArgumentError(StringPiece message) { + return Status(StatusCode::kInvalidArgument, message); +} + +Status NotFoundError(StringPiece message) { + return Status(StatusCode::kNotFound, message); +} + +Status OutOfRangeError(StringPiece message) { + return Status(StatusCode::kOutOfRange, message); +} + +Status PermissionDeniedError(StringPiece message) { + return Status(StatusCode::kPermissionDenied, message); +} + +Status ResourceExhaustedError(StringPiece message) { + return Status(StatusCode::kResourceExhausted, message); +} + +Status UnauthenticatedError(StringPiece message) { + return Status(StatusCode::kUnauthenticated, message); +} + +Status UnavailableError(StringPiece message) { + return Status(StatusCode::kUnavailable, message); +} + +Status UnimplementedError(StringPiece message) { + return Status(StatusCode::kUnimplemented, message); +} + +Status UnknownError(StringPiece message) { + return Status(StatusCode::kUnknown, message); +} + +} // namespace status_internal +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/status.h b/libs/protobuf/src/google/protobuf/stubs/status.h new file mode 100644 index 0000000..c858cf6 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/status.h @@ -0,0 +1,196 @@ +// 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_STUBS_STATUS_H_ +#define GOOGLE_PROTOBUF_STUBS_STATUS_H_ + +#include + +#include + +#include + +namespace google { +namespace protobuf { +namespace util { +namespace status_internal { + +// These values must match error codes defined in google/rpc/code.proto. +enum class StatusCode : int { + kOk = 0, + kCancelled = 1, + kUnknown = 2, + kInvalidArgument = 3, + kDeadlineExceeded = 4, + kNotFound = 5, + kAlreadyExists = 6, + kPermissionDenied = 7, + kUnauthenticated = 16, + kResourceExhausted = 8, + kFailedPrecondition = 9, + kAborted = 10, + kOutOfRange = 11, + kUnimplemented = 12, + kInternal = 13, + kUnavailable = 14, + kDataLoss = 15, +}; + +class PROTOBUF_EXPORT Status { + public: + // Creates a "successful" status. + Status(); + + // Create a status in the canonical error space with the specified + // code, and error message. If "code == 0", error_message is + // ignored and a Status object identical to Status::kOk is + // constructed. + Status(StatusCode error_code, StringPiece error_message); + Status(const Status&); + Status& operator=(const Status& x); + ~Status() {} + + // Accessor + bool ok() const { return error_code_ == StatusCode::kOk; } + StatusCode code() const { return error_code_; } + StringPiece message() const { + return error_message_; + } + + bool operator==(const Status& x) const; + bool operator!=(const Status& x) const { + return !operator==(x); + } + + // Return a combination of the error code name and message. + std::string ToString() const; + + private: + StatusCode error_code_; + std::string error_message_; +}; + +// Returns an OK status, equivalent to a default constructed instance. Prefer +// usage of `OkStatus()` when constructing such an OK status. +PROTOBUF_EXPORT Status OkStatus(); + +// Prints a human-readable representation of 'x' to 'os'. +PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x); + +// These convenience functions return `true` if a given status matches the +// `StatusCode` error code of its associated function. +PROTOBUF_EXPORT bool IsAborted(const Status& status); +PROTOBUF_EXPORT bool IsAlreadyExists(const Status& status); +PROTOBUF_EXPORT bool IsCancelled(const Status& status); +PROTOBUF_EXPORT bool IsDataLoss(const Status& status); +PROTOBUF_EXPORT bool IsDeadlineExceeded(const Status& status); +PROTOBUF_EXPORT bool IsFailedPrecondition(const Status& status); +PROTOBUF_EXPORT bool IsInternal(const Status& status); +PROTOBUF_EXPORT bool IsInvalidArgument(const Status& status); +PROTOBUF_EXPORT bool IsNotFound(const Status& status); +PROTOBUF_EXPORT bool IsOutOfRange(const Status& status); +PROTOBUF_EXPORT bool IsPermissionDenied(const Status& status); +PROTOBUF_EXPORT bool IsResourceExhausted(const Status& status); +PROTOBUF_EXPORT bool IsUnauthenticated(const Status& status); +PROTOBUF_EXPORT bool IsUnavailable(const Status& status); +PROTOBUF_EXPORT bool IsUnimplemented(const Status& status); +PROTOBUF_EXPORT bool IsUnknown(const Status& status); + +// These convenience functions create an `Status` object with an error code as +// indicated by the associated function name, using the error message passed in +// `message`. +// +// These functions are intentionally named `*Error` rather than `*Status` to +// match the names from Abseil: +// https://github.com/abseil/abseil-cpp/blob/2e9532cc6c701a8323d0cffb468999ab804095ab/absl/status/status.h#L716 +PROTOBUF_EXPORT Status AbortedError(StringPiece message); +PROTOBUF_EXPORT Status AlreadyExistsError(StringPiece message); +PROTOBUF_EXPORT Status CancelledError(StringPiece message); +PROTOBUF_EXPORT Status DataLossError(StringPiece message); +PROTOBUF_EXPORT Status DeadlineExceededError(StringPiece message); +PROTOBUF_EXPORT Status FailedPreconditionError(StringPiece message); +PROTOBUF_EXPORT Status InternalError(StringPiece message); +PROTOBUF_EXPORT Status InvalidArgumentError(StringPiece message); +PROTOBUF_EXPORT Status NotFoundError(StringPiece message); +PROTOBUF_EXPORT Status OutOfRangeError(StringPiece message); +PROTOBUF_EXPORT Status PermissionDeniedError(StringPiece message); +PROTOBUF_EXPORT Status ResourceExhaustedError(StringPiece message); +PROTOBUF_EXPORT Status UnauthenticatedError(StringPiece message); +PROTOBUF_EXPORT Status UnavailableError(StringPiece message); +PROTOBUF_EXPORT Status UnimplementedError(StringPiece message); +PROTOBUF_EXPORT Status UnknownError(StringPiece message); + +} // namespace status_internal + +using ::google::protobuf::util::status_internal::Status; +using ::google::protobuf::util::status_internal::StatusCode; + +using ::google::protobuf::util::status_internal::IsAborted; +using ::google::protobuf::util::status_internal::IsAlreadyExists; +using ::google::protobuf::util::status_internal::IsCancelled; +using ::google::protobuf::util::status_internal::IsDataLoss; +using ::google::protobuf::util::status_internal::IsDeadlineExceeded; +using ::google::protobuf::util::status_internal::IsFailedPrecondition; +using ::google::protobuf::util::status_internal::IsInternal; +using ::google::protobuf::util::status_internal::IsInvalidArgument; +using ::google::protobuf::util::status_internal::IsNotFound; +using ::google::protobuf::util::status_internal::IsOutOfRange; +using ::google::protobuf::util::status_internal::IsPermissionDenied; +using ::google::protobuf::util::status_internal::IsResourceExhausted; +using ::google::protobuf::util::status_internal::IsUnauthenticated; +using ::google::protobuf::util::status_internal::IsUnavailable; +using ::google::protobuf::util::status_internal::IsUnimplemented; +using ::google::protobuf::util::status_internal::IsUnknown; + +using ::google::protobuf::util::status_internal::AbortedError; +using ::google::protobuf::util::status_internal::AlreadyExistsError; +using ::google::protobuf::util::status_internal::CancelledError; +using ::google::protobuf::util::status_internal::DataLossError; +using ::google::protobuf::util::status_internal::DeadlineExceededError; +using ::google::protobuf::util::status_internal::FailedPreconditionError; +using ::google::protobuf::util::status_internal::InternalError; +using ::google::protobuf::util::status_internal::InvalidArgumentError; +using ::google::protobuf::util::status_internal::NotFoundError; +using ::google::protobuf::util::status_internal::OkStatus; +using ::google::protobuf::util::status_internal::OutOfRangeError; +using ::google::protobuf::util::status_internal::PermissionDeniedError; +using ::google::protobuf::util::status_internal::ResourceExhaustedError; +using ::google::protobuf::util::status_internal::UnauthenticatedError; +using ::google::protobuf::util::status_internal::UnavailableError; +using ::google::protobuf::util::status_internal::UnimplementedError; +using ::google::protobuf::util::status_internal::UnknownError; + +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/status_macros.h b/libs/protobuf/src/google/protobuf/stubs/status_macros.h index fc2267e..407ff4c 100644 --- a/libs/protobuf/src/google/protobuf/stubs/status_macros.h +++ b/libs/protobuf/src/google/protobuf/stubs/status_macros.h @@ -33,12 +33,9 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_ #define GOOGLE_PROTOBUF_STUBS_STATUS_MACROS_H_ -#include "absl/status/status.h" -#include "absl/status/statusor.h" -#include "google/protobuf/stubs/common.h" - -// Needs to be last. -#include "google/protobuf/port_def.inc" // NOLINT +#include +#include +#include namespace google { namespace protobuf { @@ -52,7 +49,7 @@ namespace util { #define RETURN_IF_ERROR(expr) \ do { \ /* Using _status below to avoid capture problems if expr is "status". */ \ - const absl::Status _status = (expr); \ + const PROTOBUF_NAMESPACE_ID::util::Status _status = (expr); \ if (PROTOBUF_PREDICT_FALSE(!_status.ok())) return _status; \ } while (0) @@ -60,16 +57,16 @@ namespace util { #define STATUS_MACROS_CONCAT_NAME_INNER(x, y) x##y #define STATUS_MACROS_CONCAT_NAME(x, y) STATUS_MACROS_CONCAT_NAME_INNER(x, y) -template -absl::Status DoAssignOrReturn(T& lhs, absl::StatusOr result) { +template +Status DoAssignOrReturn(T& lhs, StatusOr result) { if (result.ok()) { lhs = result.value(); } return result.status(); } -#define ASSIGN_OR_RETURN_IMPL(status, lhs, rexpr) \ - absl::Status status = DoAssignOrReturn(lhs, (rexpr)); \ +#define ASSIGN_OR_RETURN_IMPL(status, lhs, rexpr) \ + Status status = DoAssignOrReturn(lhs, (rexpr)); \ if (PROTOBUF_PREDICT_FALSE(!status.ok())) return status; // Executes an expression that returns a util::StatusOr, extracting its value @@ -82,13 +79,11 @@ absl::Status DoAssignOrReturn(T& lhs, absl::StatusOr result) { // WARNING: ASSIGN_OR_RETURN expands into multiple statements; it cannot be used // in a single statement (e.g. as the body of an if statement without {})! #define ASSIGN_OR_RETURN(lhs, rexpr) \ - ASSIGN_OR_RETURN_IMPL( \ + ASSIGN_OR_RETURN_IMPL( \ STATUS_MACROS_CONCAT_NAME(_status_or_value, __COUNTER__), lhs, rexpr); } // namespace util } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" // NOLINT - #endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/status_test.cc b/libs/protobuf/src/google/protobuf/stubs/status_test.cc new file mode 100644 index 0000000..9e9edf7 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/status_test.cc @@ -0,0 +1,278 @@ +// 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 + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace { + +TEST(Status, Constructor) { + EXPECT_EQ(util::StatusCode::kOk, + util::Status(util::StatusCode::kOk, "").code()); + EXPECT_EQ(util::StatusCode::kCancelled, + util::Status(util::StatusCode::kCancelled, "").code()); + EXPECT_EQ(util::StatusCode::kUnknown, + util::Status(util::StatusCode::kUnknown, "").code()); + EXPECT_EQ(util::StatusCode::kInvalidArgument, + util::Status(util::StatusCode::kInvalidArgument, "").code()); + EXPECT_EQ(util::StatusCode::kDeadlineExceeded, + util::Status(util::StatusCode::kDeadlineExceeded, "").code()); + EXPECT_EQ(util::StatusCode::kNotFound, + util::Status(util::StatusCode::kNotFound, "").code()); + EXPECT_EQ(util::StatusCode::kAlreadyExists, + util::Status(util::StatusCode::kAlreadyExists, "").code()); + EXPECT_EQ(util::StatusCode::kPermissionDenied, + util::Status(util::StatusCode::kPermissionDenied, "").code()); + EXPECT_EQ(util::StatusCode::kUnauthenticated, + util::Status(util::StatusCode::kUnauthenticated, "").code()); + EXPECT_EQ(util::StatusCode::kResourceExhausted, + util::Status(util::StatusCode::kResourceExhausted, "").code()); + EXPECT_EQ(util::StatusCode::kFailedPrecondition, + util::Status(util::StatusCode::kFailedPrecondition, "").code()); + EXPECT_EQ(util::StatusCode::kAborted, + util::Status(util::StatusCode::kAborted, "").code()); + EXPECT_EQ(util::StatusCode::kOutOfRange, + util::Status(util::StatusCode::kOutOfRange, "").code()); + EXPECT_EQ(util::StatusCode::kUnimplemented, + util::Status(util::StatusCode::kUnimplemented, "").code()); + EXPECT_EQ(util::StatusCode::kInternal, + util::Status(util::StatusCode::kInternal, "").code()); + EXPECT_EQ(util::StatusCode::kUnavailable, + util::Status(util::StatusCode::kUnavailable, "").code()); + EXPECT_EQ(util::StatusCode::kDataLoss, + util::Status(util::StatusCode::kDataLoss, "").code()); +} + +TEST(Status, ConstructorZero) { + util::Status status(util::StatusCode::kOk, "msg"); + EXPECT_TRUE(status.ok()); + EXPECT_EQ("OK", status.ToString()); + EXPECT_EQ(util::OkStatus(), status); +} + +TEST(Status, ConvenienceConstructors) { + EXPECT_EQ(util::StatusCode::kOk, util::OkStatus().code()); + EXPECT_EQ("", util::OkStatus().message()); + + EXPECT_EQ(util::StatusCode::kCancelled, util::CancelledError("").code()); + EXPECT_EQ("", util::CancelledError("").message()); + EXPECT_EQ("foo", util::CancelledError("foo").message()); + EXPECT_EQ("bar", util::CancelledError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnknown, util::UnknownError("").code()); + EXPECT_EQ("", util::UnknownError("").message()); + EXPECT_EQ("foo", util::UnknownError("foo").message()); + EXPECT_EQ("bar", util::UnknownError("bar").message()); + + EXPECT_EQ(util::StatusCode::kInvalidArgument, + util::InvalidArgumentError("").code()); + EXPECT_EQ("", util::InvalidArgumentError("").message()); + EXPECT_EQ("foo", util::InvalidArgumentError("foo").message()); + EXPECT_EQ("bar", util::InvalidArgumentError("bar").message()); + + EXPECT_EQ(util::StatusCode::kDeadlineExceeded, + util::DeadlineExceededError("").code()); + EXPECT_EQ("", util::DeadlineExceededError("").message()); + EXPECT_EQ("foo", util::DeadlineExceededError("foo").message()); + EXPECT_EQ("bar", util::DeadlineExceededError("bar").message()); + + EXPECT_EQ(util::StatusCode::kNotFound, util::NotFoundError("").code()); + EXPECT_EQ("", util::NotFoundError("").message()); + EXPECT_EQ("foo", util::NotFoundError("foo").message()); + EXPECT_EQ("bar", util::NotFoundError("bar").message()); + + EXPECT_EQ(util::StatusCode::kAlreadyExists, + util::AlreadyExistsError("").code()); + EXPECT_EQ("", util::AlreadyExistsError("").message()); + EXPECT_EQ("foo", util::AlreadyExistsError("foo").message()); + EXPECT_EQ("bar", util::AlreadyExistsError("bar").message()); + + EXPECT_EQ(util::StatusCode::kPermissionDenied, + util::PermissionDeniedError("").code()); + EXPECT_EQ("", util::PermissionDeniedError("").message()); + EXPECT_EQ("foo", util::PermissionDeniedError("foo").message()); + EXPECT_EQ("bar", util::PermissionDeniedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnauthenticated, + util::UnauthenticatedError("").code()); + EXPECT_EQ("", util::UnauthenticatedError("").message()); + EXPECT_EQ("foo", util::UnauthenticatedError("foo").message()); + EXPECT_EQ("bar", util::UnauthenticatedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kResourceExhausted, + util::ResourceExhaustedError("").code()); + EXPECT_EQ("", util::ResourceExhaustedError("").message()); + EXPECT_EQ("foo", util::ResourceExhaustedError("foo").message()); + EXPECT_EQ("bar", util::ResourceExhaustedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kFailedPrecondition, + util::FailedPreconditionError("").code()); + EXPECT_EQ("", util::FailedPreconditionError("").message()); + EXPECT_EQ("foo", util::FailedPreconditionError("foo").message()); + EXPECT_EQ("bar", util::FailedPreconditionError("bar").message()); + + EXPECT_EQ(util::StatusCode::kAborted, util::AbortedError("").code()); + EXPECT_EQ("", util::AbortedError("").message()); + EXPECT_EQ("foo", util::AbortedError("foo").message()); + EXPECT_EQ("bar", util::AbortedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kOutOfRange, util::OutOfRangeError("").code()); + EXPECT_EQ("", util::OutOfRangeError("").message()); + EXPECT_EQ("foo", util::OutOfRangeError("foo").message()); + EXPECT_EQ("bar", util::OutOfRangeError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnimplemented, + util::UnimplementedError("").code()); + EXPECT_EQ("", util::UnimplementedError("").message()); + EXPECT_EQ("foo", util::UnimplementedError("foo").message()); + EXPECT_EQ("bar", util::UnimplementedError("bar").message()); + + EXPECT_EQ(util::StatusCode::kInternal, util::InternalError("").code()); + EXPECT_EQ("", util::InternalError("").message()); + EXPECT_EQ("foo", util::InternalError("foo").message()); + EXPECT_EQ("bar", util::InternalError("bar").message()); + + EXPECT_EQ(util::StatusCode::kUnavailable, util::UnavailableError("").code()); + EXPECT_EQ("", util::UnavailableError("").message()); + EXPECT_EQ("foo", util::UnavailableError("foo").message()); + EXPECT_EQ("bar", util::UnavailableError("bar").message()); + + EXPECT_EQ(util::StatusCode::kDataLoss, util::DataLossError("").code()); + EXPECT_EQ("", util::DataLossError("").message()); + EXPECT_EQ("foo", util::DataLossError("foo").message()); + EXPECT_EQ("bar", util::DataLossError("bar").message()); +} + +TEST(Status, ConvenienceTests) { + EXPECT_TRUE(util::OkStatus().ok()); + EXPECT_TRUE(util::IsCancelled(util::CancelledError(""))); + EXPECT_TRUE(util::IsUnknown(util::UnknownError(""))); + EXPECT_TRUE(util::IsInvalidArgument(util::InvalidArgumentError(""))); + EXPECT_TRUE(util::IsDeadlineExceeded(util::DeadlineExceededError(""))); + EXPECT_TRUE(util::IsNotFound(util::NotFoundError(""))); + EXPECT_TRUE(util::IsAlreadyExists(util::AlreadyExistsError(""))); + EXPECT_TRUE(util::IsPermissionDenied(util::PermissionDeniedError(""))); + EXPECT_TRUE(util::IsUnauthenticated(util::UnauthenticatedError(""))); + EXPECT_TRUE(util::IsResourceExhausted(util::ResourceExhaustedError(""))); + EXPECT_TRUE(util::IsFailedPrecondition(util::FailedPreconditionError(""))); + EXPECT_TRUE(util::IsAborted(util::AbortedError(""))); + EXPECT_TRUE(util::IsOutOfRange(util::OutOfRangeError(""))); + EXPECT_TRUE(util::IsUnimplemented(util::UnimplementedError(""))); + EXPECT_TRUE(util::IsInternal(util::InternalError(""))); + EXPECT_TRUE(util::IsUnavailable(util::UnavailableError(""))); + EXPECT_TRUE(util::IsDataLoss(util::DataLossError(""))); +} + +TEST(Status, Empty) { + util::Status status; + EXPECT_TRUE(status.ok()); + EXPECT_EQ(util::OkStatus(), status); + EXPECT_EQ(util::StatusCode::kOk, status.code()); + EXPECT_EQ("OK", status.ToString()); +} + +TEST(Status, CheckOK) { + util::Status status; + GOOGLE_CHECK_OK(status); + GOOGLE_CHECK_OK(status) << "Failed"; + GOOGLE_DCHECK_OK(status) << "Failed"; +} + +TEST(Status, ErrorMessage) { + util::Status status = util::InvalidArgumentError(""); + EXPECT_FALSE(status.ok()); + EXPECT_EQ("", status.message().ToString()); + EXPECT_EQ("INVALID_ARGUMENT", status.ToString()); + status = util::InvalidArgumentError("msg"); + EXPECT_FALSE(status.ok()); + EXPECT_EQ("msg", status.message().ToString()); + EXPECT_EQ("INVALID_ARGUMENT:msg", status.ToString()); + status = util::Status(util::StatusCode::kOk, "msg"); + EXPECT_TRUE(status.ok()); + EXPECT_EQ("", status.message().ToString()); + EXPECT_EQ("OK", status.ToString()); +} + +TEST(Status, Copy) { + util::Status a = util::UnknownError("message"); + util::Status b(a); + ASSERT_EQ(a.ToString(), b.ToString()); +} + +TEST(Status, Assign) { + util::Status a = util::UnknownError("message"); + util::Status b; + b = a; + ASSERT_EQ(a.ToString(), b.ToString()); +} + +TEST(Status, AssignEmpty) { + util::Status a = util::UnknownError("message"); + util::Status b; + a = b; + ASSERT_EQ(std::string("OK"), a.ToString()); + ASSERT_TRUE(b.ok()); + ASSERT_TRUE(a.ok()); +} + +TEST(Status, EqualsOK) { ASSERT_EQ(util::OkStatus(), util::Status()); } + +TEST(Status, EqualsSame) { + const util::Status a = util::CancelledError("message"); + const util::Status b = util::CancelledError("message"); + ASSERT_EQ(a, b); +} + +TEST(Status, EqualsCopy) { + const util::Status a = util::CancelledError("message"); + const util::Status b = a; + ASSERT_EQ(a, b); +} + +TEST(Status, EqualsDifferentCode) { + const util::Status a = util::CancelledError("message"); + const util::Status b = util::UnknownError("message"); + ASSERT_NE(a, b); +} + +TEST(Status, EqualsDifferentMessage) { + const util::Status a = util::CancelledError("message"); + const util::Status b = util::CancelledError("another"); + ASSERT_NE(a, b); +} + +} // namespace +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/objectivec/Tests/any_test.proto b/libs/protobuf/src/google/protobuf/stubs/statusor.cc similarity index 78% rename from libs/protobuf/objectivec/Tests/any_test.proto rename to libs/protobuf/src/google/protobuf/stubs/statusor.cc index f2461bf..9c0a178 100644 --- a/libs/protobuf/objectivec/Tests/any_test.proto +++ b/libs/protobuf/src/google/protobuf/stubs/statusor.cc @@ -28,17 +28,21 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -syntax = "proto3"; +#include -package objc.protobuf.tests.any; +#include -import "google/protobuf/any.proto"; +namespace google { +namespace protobuf { +namespace util { +namespace statusor_internal { -option objc_class_prefix = "Any"; - -message TestMessage { - int32 int32_value = 1; - google.protobuf.Any any_value = 2; - repeated google.protobuf.Any repeated_any_value = 3; - string text = 4; +void StatusOrHelper::Crash(const Status& status) { + GOOGLE_LOG(FATAL) << "Attempting to fetch value instead of handling error " + << status.ToString(); } + +} // namespace statusor_internal +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/statusor.h b/libs/protobuf/src/google/protobuf/stubs/statusor.h new file mode 100644 index 0000000..20e603e --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/statusor.h @@ -0,0 +1,253 @@ +// 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. + +// StatusOr is the union of a Status object and a T +// object. StatusOr models the concept of an object that is either a +// usable value, or an error Status explaining why such a value is +// not present. To this end, StatusOr does not allow its Status +// value to be OkStatus(). Further, StatusOr does not allow the +// contained pointer to be nullptr. +// +// The primary use-case for StatusOr is as the return value of a +// function which may fail. +// +// Example client usage for a StatusOr, where T is not a pointer: +// +// StatusOr result = DoBigCalculationThatCouldFail(); +// if (result.ok()) { +// float answer = result.value(); +// printf("Big calculation yielded: %f", answer); +// } else { +// LOG(ERROR) << result.status(); +// } +// +// Example client usage for a StatusOr: +// +// StatusOr result = FooFactory::MakeNewFoo(arg); +// if (result.ok()) { +// std::unique_ptr foo(result.value()); +// foo->DoSomethingCool(); +// } else { +// LOG(ERROR) << result.status(); +// } +// +// Example factory implementation returning StatusOr: +// +// StatusOr FooFactory::MakeNewFoo(int arg) { +// if (arg <= 0) { +// return InvalidArgumentError("Arg must be positive"); +// } else { +// return new Foo(arg); +// } +// } +// + +#ifndef GOOGLE_PROTOBUF_STUBS_STATUSOR_H_ +#define GOOGLE_PROTOBUF_STUBS_STATUSOR_H_ + +#include +#include +#include + +#include + +#include + +namespace google { +namespace protobuf { +namespace util { +namespace statusor_internal { + +template +class StatusOr { + template friend class StatusOr; + + public: + using value_type = T; + + // Construct a new StatusOr with Status::UNKNOWN status. + // Construct a new StatusOr with UnknownError() status. + explicit StatusOr(); + + // Construct a new StatusOr with the given non-ok status. After calling + // this constructor, calls to value() will CHECK-fail. + // + // NOTE: Not explicit - we want to use StatusOr as a return + // value, so it is convenient and sensible to be able to do 'return + // Status()' when the return type is StatusOr. + // + // REQUIRES: status != OkStatus(). This requirement is DCHECKed. + // In optimized builds, passing OkStatus() here will have the effect + // of passing PosixErrorSpace::EINVAL as a fallback. + StatusOr(const Status& status); // NOLINT + + // Construct a new StatusOr with the given value. If T is a plain pointer, + // value must not be nullptr. After calling this constructor, calls to + // value() will succeed, and calls to status() will return OK. + // + // NOTE: Not explicit - we want to use StatusOr as a return type + // so it is convenient and sensible to be able to do 'return T()' + // when when the return type is StatusOr. + // + // REQUIRES: if T is a plain pointer, value != nullptr. This requirement is + // DCHECKed. In optimized builds, passing a null pointer here will have + // the effect of passing PosixErrorSpace::EINVAL as a fallback. + StatusOr(const T& value); // NOLINT + + // Copy constructor. + StatusOr(const StatusOr& other); + + // Conversion copy constructor, T must be copy constructible from U + template + StatusOr(const StatusOr& other); + + // Assignment operator. + StatusOr& operator=(const StatusOr& other); + + // Conversion assignment operator, T must be assignable from U + template + StatusOr& operator=(const StatusOr& other); + + // Returns a reference to our status. If this contains a T, then + // returns OkStatus(). + const Status& status() const; + + // Returns this->status().ok() + bool ok() const; + + // Returns a reference to our current value, or CHECK-fails if !this->ok(). + const T& value () const; + + private: + Status status_; + T value_; +}; + +//////////////////////////////////////////////////////////////////////////////// +// Implementation details for StatusOr + +class PROTOBUF_EXPORT StatusOrHelper { + public: + // Move type-agnostic error handling to the .cc. + static void Crash(const util::Status& status); + + // Customized behavior for StatusOr vs. StatusOr + template + struct Specialize; +}; + +template +struct StatusOrHelper::Specialize { + // For non-pointer T, a reference can never be nullptr. + static inline bool IsValueNull(const T& /*t*/) { return false; } +}; + +template +struct StatusOrHelper::Specialize { + static inline bool IsValueNull(const T* t) { return t == nullptr; } +}; + +template +inline StatusOr::StatusOr() : status_(util::UnknownError("")) {} + +template +inline StatusOr::StatusOr(const Status& status) { + if (status.ok()) { + status_ = util::InternalError("OkStatus() is not a valid argument."); + } else { + status_ = status; + } +} + +template +inline StatusOr::StatusOr(const T& value) { + if (StatusOrHelper::Specialize::IsValueNull(value)) { + status_ = util::InternalError("nullptr is not a valid argument."); + } else { + status_ = util::OkStatus(); + value_ = value; + } +} + +template +inline StatusOr::StatusOr(const StatusOr& other) + : status_(other.status_), value_(other.value_) { +} + +template +inline StatusOr& StatusOr::operator=(const StatusOr& other) { + status_ = other.status_; + value_ = other.value_; + return *this; +} + +template +template +inline StatusOr::StatusOr(const StatusOr& other) + : status_(other.status_), value_(other.status_.ok() ? other.value_ : T()) { +} + +template +template +inline StatusOr& StatusOr::operator=(const StatusOr& other) { + status_ = other.status_; + if (status_.ok()) value_ = other.value_; + return *this; +} + +template +inline const Status& StatusOr::status() const { + return status_; +} + +template +inline bool StatusOr::ok() const { + return status().ok(); +} + +template +inline const T& StatusOr::value() const { + if (!status_.ok()) { + StatusOrHelper::Crash(status_); + } + return value_; +} + +} // namespace statusor_internal + +using ::google::protobuf::util::statusor_internal::StatusOr; + +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_STATUSOR_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/statusor_test.cc b/libs/protobuf/src/google/protobuf/stubs/statusor_test.cc new file mode 100644 index 0000000..403adcc --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/statusor_test.cc @@ -0,0 +1,272 @@ +// 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 + +#include +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace { + +class Base1 { + public: + virtual ~Base1() {} + int pad; +}; + +class Base2 { + public: + virtual ~Base2() {} + int yetotherpad; +}; + +class Derived : public Base1, public Base2 { + public: + virtual ~Derived() {} + int evenmorepad; +}; + +class CopyNoAssign { + public: + explicit CopyNoAssign(int value) : foo(value) {} + CopyNoAssign(const CopyNoAssign& other) : foo(other.foo) {} + int foo; + private: + const CopyNoAssign& operator=(const CopyNoAssign&); +}; + +TEST(StatusOr, TestDefaultCtor) { + StatusOr thing; + EXPECT_FALSE(thing.ok()); + EXPECT_EQ(util::UnknownError(""), thing.status()); +} + +TEST(StatusOr, TestStatusCtor) { + StatusOr thing(util::CancelledError("")); + EXPECT_FALSE(thing.ok()); + EXPECT_EQ(util::CancelledError(""), thing.status()); +} + +TEST(StatusOr, TestValueCtor) { + const int kI = 4; + StatusOr thing(kI); + EXPECT_TRUE(thing.ok()); + EXPECT_EQ(kI, thing.value()); +} + +TEST(StatusOr, TestCopyCtorStatusOk) { + const int kI = 4; + StatusOr original(kI); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); + EXPECT_EQ(original.value(), copy.value()); +} + +TEST(StatusOr, TestCopyCtorStatusNotOk) { + StatusOr original(util::CancelledError("")); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); +} + +TEST(StatusOr, TestCopyCtorStatusOKConverting) { + const int kI = 4; + StatusOr original(kI); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); + EXPECT_EQ(original.value(), copy.value()); +} + +TEST(StatusOr, TestCopyCtorStatusNotOkConverting) { + StatusOr original(util::CancelledError("")); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); +} + +TEST(StatusOr, TestAssignmentStatusOk) { + const int kI = 4; + StatusOr source(kI); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); + EXPECT_EQ(source.value(), target.value()); +} + +TEST(StatusOr, TestAssignmentStatusNotOk) { + StatusOr source(util::CancelledError("")); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); +} + +TEST(StatusOr, TestAssignmentStatusOKConverting) { + const int kI = 4; + StatusOr source(kI); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); + EXPECT_DOUBLE_EQ(source.value(), target.value()); +} + +TEST(StatusOr, TestAssignmentStatusNotOkConverting) { + StatusOr source(util::CancelledError("")); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); +} + +TEST(StatusOr, TestStatus) { + StatusOr good(4); + EXPECT_TRUE(good.ok()); + StatusOr bad(util::CancelledError("")); + EXPECT_FALSE(bad.ok()); + EXPECT_EQ(util::CancelledError(""), bad.status()); +} + +TEST(StatusOr, TestValue) { + const int kI = 4; + StatusOr thing(kI); + EXPECT_EQ(kI, thing.value()); +} + +TEST(StatusOr, TestValueConst) { + const int kI = 4; + const StatusOr thing(kI); + EXPECT_EQ(kI, thing.value()); +} + +TEST(StatusOr, TestPointerDefaultCtor) { + StatusOr thing; + EXPECT_FALSE(thing.ok()); + EXPECT_EQ(util::UnknownError(""), thing.status()); +} + +TEST(StatusOr, TestPointerStatusCtor) { + StatusOr thing(util::CancelledError("")); + EXPECT_FALSE(thing.ok()); + EXPECT_EQ(util::CancelledError(""), thing.status()); +} + +TEST(StatusOr, TestPointerValueCtor) { + const int kI = 4; + StatusOr thing(&kI); + EXPECT_TRUE(thing.ok()); + EXPECT_EQ(&kI, thing.value()); +} + +TEST(StatusOr, TestPointerCopyCtorStatusOk) { + const int kI = 0; + StatusOr original(&kI); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); + EXPECT_EQ(original.value(), copy.value()); +} + +TEST(StatusOr, TestPointerCopyCtorStatusNotOk) { + StatusOr original(util::CancelledError("")); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); +} + +TEST(StatusOr, TestPointerCopyCtorStatusOKConverting) { + Derived derived; + StatusOr original(&derived); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); + EXPECT_EQ(static_cast(original.value()), copy.value()); +} + +TEST(StatusOr, TestPointerCopyCtorStatusNotOkConverting) { + StatusOr original(util::CancelledError("")); + StatusOr copy(original); + EXPECT_EQ(original.status(), copy.status()); +} + +TEST(StatusOr, TestPointerAssignmentStatusOk) { + const int kI = 0; + StatusOr source(&kI); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); + EXPECT_EQ(source.value(), target.value()); +} + +TEST(StatusOr, TestPointerAssignmentStatusNotOk) { + StatusOr source(util::CancelledError("")); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); +} + +TEST(StatusOr, TestPointerAssignmentStatusOKConverting) { + Derived derived; + StatusOr source(&derived); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); + EXPECT_EQ(static_cast(source.value()), target.value()); +} + +TEST(StatusOr, TestPointerAssignmentStatusNotOkConverting) { + StatusOr source(util::CancelledError("")); + StatusOr target; + target = source; + EXPECT_EQ(source.status(), target.status()); +} + +TEST(StatusOr, TestPointerStatus) { + const int kI = 0; + StatusOr good(&kI); + EXPECT_TRUE(good.ok()); + StatusOr bad(util::CancelledError("")); + EXPECT_EQ(util::CancelledError(""), bad.status()); +} + +TEST(StatusOr, TestPointerValue) { + const int kI = 0; + StatusOr thing(&kI); + EXPECT_EQ(&kI, thing.value()); +} + +TEST(StatusOr, TestPointerValueConst) { + const int kI = 0; + const StatusOr thing(&kI); + EXPECT_EQ(&kI, thing.value()); +} + +} // namespace +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/stl_util.h b/libs/protobuf/src/google/protobuf/stubs/stl_util.h new file mode 100644 index 0000000..e6260d0 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stl_util.h @@ -0,0 +1,90 @@ +// 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. + +// from google3/util/gtl/stl_util.h + +#ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ +#define GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ + +#include + +#include + +// Must be last. +#include // NOLINT + +namespace google { +namespace protobuf { + +// Inside Google, this function implements a horrible, disgusting hack in which +// we reach into the string's private implementation and resize it without +// initializing the new bytes. In some cases doing this can significantly +// improve performance. However, since it's totally non-portable it has no +// place in open source code. Feel free to fill this function in with your +// own disgusting hack if you want the perf boost. +inline void STLStringResizeUninitialized(std::string* s, size_t new_size) { + s->resize(new_size); +} + +// As above, but we make sure to follow amortized growth in which we always +// increase the capacity by at least a constant factor >1. +inline void STLStringResizeUninitializedAmortized(std::string* s, + size_t new_size) { + const size_t cap = s->capacity(); + if (new_size > cap) { + // Make sure to always grow by at least a factor of 2x. + s->reserve(std::max(new_size, 2 * cap)); + } + STLStringResizeUninitialized(s, new_size); +} + +// Return a mutable char* pointing to a string's internal buffer, +// which may not be null-terminated. Writing through this pointer will +// modify the string. +// +// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the +// next call to a string method that invalidates iterators. +// +// As of 2006-04, there is no standard-blessed way of getting a +// mutable reference to a string's internal buffer. However, issue 530 +// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) +// proposes this as the method. According to Matt Austern, this should +// already work on all current implementations. +inline char* string_as_array(std::string* str) { + // DO NOT USE const_cast(str->data())! See the unittest for why. + return str->empty() ? nullptr : &*str->begin(); +} + +} // namespace protobuf +} // namespace google + +#include // NOLINT + +#endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/stringpiece.cc b/libs/protobuf/src/google/protobuf/stubs/stringpiece.cc new file mode 100644 index 0000000..7188046 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringpiece.cc @@ -0,0 +1,256 @@ +// 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 + +#include +#include +#include +#include +#include + +#include + +namespace google { +namespace protobuf { +namespace stringpiece_internal { + +std::ostream& operator<<(std::ostream& o, StringPiece piece) { + o.write(piece.data(), piece.size()); + return o; +} + +void StringPiece::LogFatalSizeTooBig(size_t size, const char* details) { + GOOGLE_LOG(FATAL) << "size too big: " << size << " details: " << details; +} + +void StringPiece::CopyToString(std::string* target) const { + target->assign(ptr_, length_); +} + +void StringPiece::AppendToString(std::string* target) const { + target->append(ptr_, length_); +} + +bool StringPiece::Consume(StringPiece x) { + if (starts_with(x)) { + ptr_ += x.length_; + length_ -= x.length_; + return true; + } + return false; +} + +bool StringPiece::ConsumeFromEnd(StringPiece x) { + if (ends_with(x)) { + length_ -= x.length_; + return true; + } + return false; +} + +StringPiece::size_type StringPiece::copy(char* buf, size_type n, + size_type pos) const { + size_type ret = std::min(length_ - pos, n); + memcpy(buf, ptr_ + pos, ret); + return ret; +} + +bool StringPiece::contains(StringPiece s) const { + return find(s, 0) != npos; +} + +StringPiece::size_type StringPiece::find(StringPiece s, size_type pos) const { + if (length_ <= 0 || pos > static_cast(length_)) { + if (length_ == 0 && pos == 0 && s.length_ == 0) return 0; + return npos; + } + const char *result = std::search(ptr_ + pos, ptr_ + length_, + s.ptr_, s.ptr_ + s.length_); + return result == ptr_ + length_ ? npos : result - ptr_; +} + +StringPiece::size_type StringPiece::find(char c, size_type pos) const { + if (length_ <= 0 || pos >= static_cast(length_)) { + return npos; + } + const char* result = static_cast( + memchr(ptr_ + pos, c, length_ - pos)); + return result != nullptr ? result - ptr_ : npos; +} + +StringPiece::size_type StringPiece::rfind(StringPiece s, size_type pos) const { + if (length_ < s.length_) return npos; + const size_t ulen = length_; + if (s.length_ == 0) return std::min(ulen, pos); + + const char* last = ptr_ + std::min(ulen - s.length_, pos) + s.length_; + const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_); + return result != last ? result - ptr_ : npos; +} + +// Search range is [0..pos] inclusive. If pos == npos, search everything. +StringPiece::size_type StringPiece::rfind(char c, size_type pos) const { + // Note: memrchr() is not available on Windows. + if (empty()) return npos; + for (size_type i = std::min(pos, length_ - 1);; --i) { + if (ptr_[i] == c) { + return i; + } + if (i == 0) break; + } + return npos; +} + +// For each character in characters_wanted, sets the index corresponding +// to the ASCII code of that character to 1 in table. This is used by +// the find_.*_of methods below to tell whether or not a character is in +// the lookup table in constant time. +// The argument `table' must be an array that is large enough to hold all +// the possible values of an unsigned char. Thus it should be be declared +// as follows: +// bool table[UCHAR_MAX + 1] +static inline void BuildLookupTable(StringPiece characters_wanted, + bool* table) { + const StringPiece::size_type length = characters_wanted.length(); + const char* const data = characters_wanted.data(); + for (StringPiece::size_type i = 0; i < length; ++i) { + table[static_cast(data[i])] = true; + } +} + +StringPiece::size_type StringPiece::find_first_of(StringPiece s, + size_type pos) const { + if (empty() || s.empty()) { + return npos; + } + // Avoid the cost of BuildLookupTable() for a single-character search. + if (s.length_ == 1) return find_first_of(s.ptr_[0], pos); + + bool lookup[UCHAR_MAX + 1] = { false }; + BuildLookupTable(s, lookup); + for (size_type i = pos; i < length_; ++i) { + if (lookup[static_cast(ptr_[i])]) { + return i; + } + } + return npos; +} + +StringPiece::size_type StringPiece::find_first_not_of(StringPiece s, + size_type pos) const { + if (empty()) return npos; + if (s.empty()) return 0; + // Avoid the cost of BuildLookupTable() for a single-character search. + if (s.length_ == 1) return find_first_not_of(s.ptr_[0], pos); + + bool lookup[UCHAR_MAX + 1] = { false }; + BuildLookupTable(s, lookup); + for (size_type i = pos; i < length_; ++i) { + if (!lookup[static_cast(ptr_[i])]) { + return i; + } + } + return npos; +} + +StringPiece::size_type StringPiece::find_first_not_of(char c, + size_type pos) const { + if (empty()) return npos; + + for (; pos < static_cast(length_); ++pos) { + if (ptr_[pos] != c) { + return pos; + } + } + return npos; +} + +StringPiece::size_type StringPiece::find_last_of(StringPiece s, + size_type pos) const { + if (empty() || s.empty()) return npos; + // Avoid the cost of BuildLookupTable() for a single-character search. + if (s.length_ == 1) return find_last_of(s.ptr_[0], pos); + + bool lookup[UCHAR_MAX + 1] = { false }; + BuildLookupTable(s, lookup); + for (size_type i = std::min(pos, length_ - 1);; --i) { + if (lookup[static_cast(ptr_[i])]) { + return i; + } + if (i == 0) break; + } + return npos; +} + +StringPiece::size_type StringPiece::find_last_not_of(StringPiece s, + size_type pos) const { + if (empty()) return npos; + + size_type i = std::min(pos, length() - 1); + if (s.empty()) return i; + + // Avoid the cost of BuildLookupTable() for a single-character search. + if (s.length_ == 1) return find_last_not_of(s.ptr_[0], pos); + + bool lookup[UCHAR_MAX + 1] = { false }; + BuildLookupTable(s, lookup); + for (;; --i) { + if (!lookup[static_cast(ptr_[i])]) { + return i; + } + if (i == 0) break; + } + return npos; +} + +StringPiece::size_type StringPiece::find_last_not_of(char c, + size_type pos) const { + if (empty()) return npos; + size_type i = std::min(pos, length_ - 1); + for (;; --i) { + if (ptr_[i] != c) { + return i; + } + if (i == 0) break; + } + return npos; +} + +StringPiece StringPiece::substr(size_type pos, size_type n) const { + if (pos > length()) pos = length(); + if (n > length_ - pos) n = length() - pos; + return StringPiece(ptr_ + pos, n); +} + +const StringPiece::size_type StringPiece::npos = size_type(-1); + +} // namespace stringpiece_internal +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/stringpiece.h b/libs/protobuf/src/google/protobuf/stubs/stringpiece.h new file mode 100644 index 0000000..c63e25b --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringpiece.h @@ -0,0 +1,402 @@ +// 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. + +// A StringPiece points to part or all of a string, Cord, double-quoted string +// literal, or other string-like object. A StringPiece does *not* own the +// string to which it points. A StringPiece is not null-terminated. +// +// You can use StringPiece as a function or method parameter. A StringPiece +// parameter can receive a double-quoted string literal argument, a "const +// char*" argument, a string argument, or a StringPiece argument with no data +// copying. Systematic use of StringPiece for arguments reduces data +// copies and strlen() calls. +// +// Prefer passing StringPieces by value: +// void MyFunction(StringPiece arg); +// If circumstances require, you may also pass by const reference: +// void MyFunction(const StringPiece& arg); // not preferred +// Both of these have the same lifetime semantics. Passing by value +// generates slightly smaller code. For more discussion, see the thread +// go/stringpiecebyvalue on c-users. +// +// StringPiece is also suitable for local variables if you know that +// the lifetime of the underlying object is longer than the lifetime +// of your StringPiece variable. +// +// Beware of binding a StringPiece to a temporary: +// StringPiece sp = obj.MethodReturningString(); // BAD: lifetime problem +// +// This code is okay: +// string str = obj.MethodReturningString(); // str owns its contents +// StringPiece sp(str); // GOOD, because str outlives sp +// +// StringPiece is sometimes a poor choice for a return value and usually a poor +// choice for a data member. If you do use a StringPiece this way, it is your +// responsibility to ensure that the object pointed to by the StringPiece +// outlives the StringPiece. +// +// A StringPiece may represent just part of a string; thus the name "Piece". +// For example, when splitting a string, vector is a natural data +// type for the output. For another example, a Cord is a non-contiguous, +// potentially very long string-like object. The Cord class has an interface +// that iteratively provides StringPiece objects that point to the +// successive pieces of a Cord object. +// +// A StringPiece is not null-terminated. If you write code that scans a +// StringPiece, you must check its length before reading any characters. +// Common idioms that work on null-terminated strings do not work on +// StringPiece objects. +// +// There are several ways to create a null StringPiece: +// StringPiece() +// StringPiece(nullptr) +// StringPiece(nullptr, 0) +// For all of the above, sp.data() == nullptr, sp.length() == 0, +// and sp.empty() == true. Also, if you create a StringPiece with +// a non-null pointer then sp.data() != nullptr. Once created, +// sp.data() will stay either nullptr or not-nullptr, except if you call +// sp.clear() or sp.set(). +// +// Thus, you can use StringPiece(nullptr) to signal an out-of-band value +// that is different from other StringPiece values. This is similar +// to the way that const char* p1 = nullptr; is different from +// const char* p2 = "";. +// +// There are many ways to create an empty StringPiece: +// StringPiece() +// StringPiece(nullptr) +// StringPiece(nullptr, 0) +// StringPiece("") +// StringPiece("", 0) +// StringPiece("abcdef", 0) +// StringPiece("abcdef"+6, 0) +// For all of the above, sp.length() will be 0 and sp.empty() will be true. +// For some empty StringPiece values, sp.data() will be nullptr. +// For some empty StringPiece values, sp.data() will not be nullptr. +// +// Be careful not to confuse: null StringPiece and empty StringPiece. +// The set of empty StringPieces properly includes the set of null StringPieces. +// That is, every null StringPiece is an empty StringPiece, +// but some non-null StringPieces are empty Stringpieces too. +// +// All empty StringPiece values compare equal to each other. +// Even a null StringPieces compares equal to a non-null empty StringPiece: +// StringPiece() == StringPiece("", 0) +// StringPiece(nullptr) == StringPiece("abc", 0) +// StringPiece(nullptr, 0) == StringPiece("abcdef"+6, 0) +// +// Look carefully at this example: +// StringPiece("") == nullptr +// True or false? TRUE, because StringPiece::operator== converts +// the right-hand side from nullptr to StringPiece(nullptr), +// and then compares two zero-length spans of characters. +// However, we are working to make this example produce a compile error. +// +// Suppose you want to write: +// bool TestWhat?(StringPiece sp) { return sp == nullptr; } // BAD +// Do not do that. Write one of these instead: +// bool TestNull(StringPiece sp) { return sp.data() == nullptr; } +// bool TestEmpty(StringPiece sp) { return sp.empty(); } +// The intent of TestWhat? is unclear. Did you mean TestNull or TestEmpty? +// Right now, TestWhat? behaves likes TestEmpty. +// We are working to make TestWhat? produce a compile error. +// TestNull is good to test for an out-of-band signal. +// TestEmpty is good to test for an empty StringPiece. +// +// Caveats (again): +// (1) The lifetime of the pointed-to string (or piece of a string) +// must be longer than the lifetime of the StringPiece. +// (2) There may or may not be a '\0' character after the end of +// StringPiece data. +// (3) A null StringPiece is empty. +// An empty StringPiece may or may not be a null StringPiece. + +#ifndef GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_ +#define GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_ + +#include +#include +#include +#include +#include +#include + +#if defined(__cpp_lib_string_view) +#include +#endif + +#include + +#include + +namespace google { +namespace protobuf { +namespace stringpiece_internal { + +class PROTOBUF_EXPORT StringPiece { + public: + using traits_type = std::char_traits; + using value_type = char; + using pointer = char*; + using const_pointer = const char*; + using reference = char&; + using const_reference = const char&; + using const_iterator = const char*; + using iterator = const_iterator; + using const_reverse_iterator = std::reverse_iterator; + using reverse_iterator = const_reverse_iterator; + using size_type = size_t; + using difference_type = std::ptrdiff_t; + + private: + const char* ptr_; + size_type length_; + + static constexpr size_type kMaxSize = + (std::numeric_limits::max)(); + + static size_type CheckSize(size_type size) { +#if !defined(NDEBUG) || defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 + if (PROTOBUF_PREDICT_FALSE(size > kMaxSize)) { + // Some people grep for this message in logs + // so take care if you ever change it. + LogFatalSizeTooBig(size, "string length exceeds max size"); + } +#endif + return size; + } + + // Out-of-line error path. + static void LogFatalSizeTooBig(size_type size, const char* details); + + public: + // We provide non-explicit singleton constructors so users can pass + // in a "const char*" or a "string" wherever a "StringPiece" is + // expected. + // + // Style guide exception granted: + // http://goto/style-guide-exception-20978288 + StringPiece() : ptr_(nullptr), length_(0) {} + + StringPiece(const char* str) // NOLINT(runtime/explicit) + : ptr_(str), length_(0) { + if (str != nullptr) { + length_ = CheckSize(strlen(str)); + } + } + + template + StringPiece( // NOLINT(runtime/explicit) + const std::basic_string, Allocator>& str) + : ptr_(str.data()), length_(0) { + length_ = CheckSize(str.size()); + } + +#if defined(__cpp_lib_string_view) + StringPiece( // NOLINT(runtime/explicit) + std::string_view str) + : ptr_(str.data()), length_(0) { + length_ = CheckSize(str.size()); + } +#endif + + StringPiece(const char* offset, size_type len) + : ptr_(offset), length_(CheckSize(len)) {} + + // data() may return a pointer to a buffer with embedded NULs, and the + // returned buffer may or may not be null terminated. Therefore it is + // typically a mistake to pass data() to a routine that expects a NUL + // terminated string. + const_pointer data() const { return ptr_; } + size_type size() const { return length_; } + size_type length() const { return length_; } + bool empty() const { return length_ == 0; } + + char operator[](size_type i) const { + assert(i < length_); + return ptr_[i]; + } + + void remove_prefix(size_type n) { + assert(length_ >= n); + ptr_ += n; + length_ -= n; + } + + void remove_suffix(size_type n) { + assert(length_ >= n); + length_ -= n; + } + + // returns {-1, 0, 1} + int compare(StringPiece x) const { + size_type min_size = length_ < x.length_ ? length_ : x.length_; + int r = memcmp(ptr_, x.ptr_, static_cast(min_size)); + if (r < 0) return -1; + if (r > 0) return 1; + if (length_ < x.length_) return -1; + if (length_ > x.length_) return 1; + return 0; + } + + std::string as_string() const { return ToString(); } + // We also define ToString() here, since many other string-like + // interfaces name the routine that converts to a C++ string + // "ToString", and it's confusing to have the method that does that + // for a StringPiece be called "as_string()". We also leave the + // "as_string()" method defined here for existing code. + std::string ToString() const { + if (ptr_ == nullptr) return ""; + return std::string(data(), static_cast(size())); + } + + explicit operator std::string() const { return ToString(); } + + void CopyToString(std::string* target) const; + void AppendToString(std::string* target) const; + + bool starts_with(StringPiece x) const { + return (length_ >= x.length_) && + (memcmp(ptr_, x.ptr_, static_cast(x.length_)) == 0); + } + + bool ends_with(StringPiece x) const { + return ((length_ >= x.length_) && + (memcmp(ptr_ + (length_-x.length_), x.ptr_, + static_cast(x.length_)) == 0)); + } + + // Checks whether StringPiece starts with x and if so advances the beginning + // of it to past the match. It's basically a shortcut for starts_with + // followed by remove_prefix. + bool Consume(StringPiece x); + // Like above but for the end of the string. + bool ConsumeFromEnd(StringPiece x); + + // standard STL container boilerplate + static const size_type npos; + const_iterator begin() const { return ptr_; } + const_iterator end() const { return ptr_ + length_; } + const_reverse_iterator rbegin() const { + return const_reverse_iterator(ptr_ + length_); + } + const_reverse_iterator rend() const { + return const_reverse_iterator(ptr_); + } + size_type max_size() const { return length_; } + size_type capacity() const { return length_; } + + // cpplint.py emits a false positive [build/include_what_you_use] + size_type copy(char* buf, size_type n, size_type pos = 0) const; // NOLINT + + bool contains(StringPiece s) const; + + size_type find(StringPiece s, size_type pos = 0) const; + size_type find(char c, size_type pos = 0) const; + size_type rfind(StringPiece s, size_type pos = npos) const; + size_type rfind(char c, size_type pos = npos) const; + + size_type find_first_of(StringPiece s, size_type pos = 0) const; + size_type find_first_of(char c, size_type pos = 0) const { + return find(c, pos); + } + size_type find_first_not_of(StringPiece s, size_type pos = 0) const; + size_type find_first_not_of(char c, size_type pos = 0) const; + size_type find_last_of(StringPiece s, size_type pos = npos) const; + size_type find_last_of(char c, size_type pos = npos) const { + return rfind(c, pos); + } + size_type find_last_not_of(StringPiece s, size_type pos = npos) const; + size_type find_last_not_of(char c, size_type pos = npos) const; + + StringPiece substr(size_type pos, size_type n = npos) const; +}; + +// This large function is defined inline so that in a fairly common case where +// one of the arguments is a literal, the compiler can elide a lot of the +// following comparisons. +inline bool operator==(StringPiece x, StringPiece y) { + StringPiece::size_type len = x.size(); + if (len != y.size()) { + return false; + } + + return x.data() == y.data() || len <= 0 || + memcmp(x.data(), y.data(), static_cast(len)) == 0; +} + +inline bool operator!=(StringPiece x, StringPiece y) { + return !(x == y); +} + +inline bool operator<(StringPiece x, StringPiece y) { + const StringPiece::size_type min_size = + x.size() < y.size() ? x.size() : y.size(); + const int r = memcmp(x.data(), y.data(), static_cast(min_size)); + return (r < 0) || (r == 0 && x.size() < y.size()); +} + +inline bool operator>(StringPiece x, StringPiece y) { + return y < x; +} + +inline bool operator<=(StringPiece x, StringPiece y) { + return !(x > y); +} + +inline bool operator>=(StringPiece x, StringPiece y) { + return !(x < y); +} + +// allow StringPiece to be logged +extern std::ostream& operator<<(std::ostream& o, StringPiece piece); + +} // namespace stringpiece_internal + +using ::google::protobuf::stringpiece_internal::StringPiece; + +} // namespace protobuf +} // namespace google + +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START +template<> struct hash { + size_t operator()(const StringPiece& s) const { + size_t result = 0; + for (const char *str = s.data(), *end = str + s.size(); str < end; str++) { + result = 5 * result + static_cast(*str); + } + return result; + } +}; +GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END + +#include + +#endif // STRINGS_STRINGPIECE_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc new file mode 100644 index 0000000..ba904cb --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc @@ -0,0 +1,695 @@ +// 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 + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace { +TEST(StringPiece, Ctor) { + { + // Null. + StringPiece s10; + EXPECT_TRUE(s10.data() == nullptr); + EXPECT_EQ(0, s10.length()); + } + + { + // const char* without length. + const char* hello = "hello"; + StringPiece s20(hello); + EXPECT_TRUE(s20.data() == hello); + EXPECT_EQ(5, s20.length()); + + // const char* with length. + StringPiece s21(hello, 4); + EXPECT_TRUE(s21.data() == hello); + EXPECT_EQ(4, s21.length()); + + // Not recommended, but valid C++ + StringPiece s22(hello, 6); + EXPECT_TRUE(s22.data() == hello); + EXPECT_EQ(6, s22.length()); + } + + { + // std::string. + std::string hola = "hola"; + StringPiece s30(hola); + EXPECT_TRUE(s30.data() == hola.data()); + EXPECT_EQ(4, s30.length()); + + // std::string with embedded '\0'. + hola.push_back('\0'); + hola.append("h2"); + hola.push_back('\0'); + StringPiece s31(hola); + EXPECT_TRUE(s31.data() == hola.data()); + EXPECT_EQ(8, s31.length()); + } + +#if defined(HAS_GLOBAL_STRING) + { + // ::string + std::string bonjour = "bonjour"; + StringPiece s40(bonjour); + EXPECT_TRUE(s40.data() == bonjour.data()); + EXPECT_EQ(7, s40.length()); + } +#endif + + // TODO(mec): StringPiece(StringPiece x, int pos); + // TODO(mec): StringPiece(StringPiece x, int pos, int len); + // TODO(mec): StringPiece(const StringPiece&); +} + +TEST(StringPiece, STLComparator) { + std::string s1("foo"); + std::string s2("bar"); + std::string s3("baz"); + + StringPiece p1(s1); + StringPiece p2(s2); + StringPiece p3(s3); + + typedef std::map TestMap; + TestMap map; + + map.insert(std::make_pair(p1, 0)); + map.insert(std::make_pair(p2, 1)); + map.insert(std::make_pair(p3, 2)); + EXPECT_EQ(map.size(), 3); + + TestMap::const_iterator iter = map.begin(); + EXPECT_EQ(iter->second, 1); + ++iter; + EXPECT_EQ(iter->second, 2); + ++iter; + EXPECT_EQ(iter->second, 0); + ++iter; + EXPECT_TRUE(iter == map.end()); + + TestMap::iterator new_iter = map.find("zot"); + EXPECT_TRUE(new_iter == map.end()); + + new_iter = map.find("bar"); + EXPECT_TRUE(new_iter != map.end()); + + map.erase(new_iter); + EXPECT_EQ(map.size(), 2); + + iter = map.begin(); + EXPECT_EQ(iter->second, 2); + ++iter; + EXPECT_EQ(iter->second, 0); + ++iter; + EXPECT_TRUE(iter == map.end()); +} + +TEST(StringPiece, ComparisonOperators) { +#define COMPARE(result, op, x, y) \ + EXPECT_EQ(result, StringPiece((x)) op StringPiece((y))); \ + EXPECT_EQ(result, StringPiece((x)).compare(StringPiece((y))) op 0) + + COMPARE(true, ==, "", ""); + COMPARE(true, ==, "", nullptr); + COMPARE(true, ==, nullptr, ""); + COMPARE(true, ==, "a", "a"); + COMPARE(true, ==, "aa", "aa"); + COMPARE(false, ==, "a", ""); + COMPARE(false, ==, "", "a"); + COMPARE(false, ==, "a", "b"); + COMPARE(false, ==, "a", "aa"); + COMPARE(false, ==, "aa", "a"); + + COMPARE(false, !=, "", ""); + COMPARE(false, !=, "a", "a"); + COMPARE(false, !=, "aa", "aa"); + COMPARE(true, !=, "a", ""); + COMPARE(true, !=, "", "a"); + COMPARE(true, !=, "a", "b"); + COMPARE(true, !=, "a", "aa"); + COMPARE(true, !=, "aa", "a"); + + COMPARE(true, <, "a", "b"); + COMPARE(true, <, "a", "aa"); + COMPARE(true, <, "aa", "b"); + COMPARE(true, <, "aa", "bb"); + COMPARE(false, <, "a", "a"); + COMPARE(false, <, "b", "a"); + COMPARE(false, <, "aa", "a"); + COMPARE(false, <, "b", "aa"); + COMPARE(false, <, "bb", "aa"); + + COMPARE(true, <=, "a", "a"); + COMPARE(true, <=, "a", "b"); + COMPARE(true, <=, "a", "aa"); + COMPARE(true, <=, "aa", "b"); + COMPARE(true, <=, "aa", "bb"); + COMPARE(false, <=, "b", "a"); + COMPARE(false, <=, "aa", "a"); + COMPARE(false, <=, "b", "aa"); + COMPARE(false, <=, "bb", "aa"); + + COMPARE(false, >=, "a", "b"); + COMPARE(false, >=, "a", "aa"); + COMPARE(false, >=, "aa", "b"); + COMPARE(false, >=, "aa", "bb"); + COMPARE(true, >=, "a", "a"); + COMPARE(true, >=, "b", "a"); + COMPARE(true, >=, "aa", "a"); + COMPARE(true, >=, "b", "aa"); + COMPARE(true, >=, "bb", "aa"); + + COMPARE(false, >, "a", "a"); + COMPARE(false, >, "a", "b"); + COMPARE(false, >, "a", "aa"); + COMPARE(false, >, "aa", "b"); + COMPARE(false, >, "aa", "bb"); + COMPARE(true, >, "b", "a"); + COMPARE(true, >, "aa", "a"); + COMPARE(true, >, "b", "aa"); + COMPARE(true, >, "bb", "aa"); + + std::string x; + for (int i = 0; i < 256; i++) { + x += 'a'; + std::string y = x; + COMPARE(true, ==, x, y); + for (int j = 0; j < i; j++) { + std::string z = x; + z[j] = 'b'; // Differs in position 'j' + COMPARE(false, ==, x, z); + COMPARE(true, <, x, z); + COMPARE(true, >, z, x); + if (j + 1 < i) { + z[j + 1] = 'A'; // Differs in position 'j+1' as well + COMPARE(false, ==, x, z); + COMPARE(true, <, x, z); + COMPARE(true, >, z, x); + z[j + 1] = 'z'; // Differs in position 'j+1' as well + COMPARE(false, ==, x, z); + COMPARE(true, <, x, z); + COMPARE(true, >, z, x); + } + } + } + +#undef COMPARE +} + +TEST(StringPiece, STL1) { + const StringPiece a("abcdefghijklmnopqrstuvwxyz"); + const StringPiece b("abc"); + const StringPiece c("xyz"); + const StringPiece d("foobar"); + const StringPiece e; + std::string temp("123"); + temp += '\0'; + temp += "456"; + const StringPiece f(temp); + + EXPECT_EQ(a[6], 'g'); + EXPECT_EQ(b[0], 'a'); + EXPECT_EQ(c[2], 'z'); + EXPECT_EQ(f[3], '\0'); + EXPECT_EQ(f[5], '5'); + + EXPECT_EQ(*d.data(), 'f'); + EXPECT_EQ(d.data()[5], 'r'); + EXPECT_TRUE(e.data() == nullptr); + + EXPECT_EQ(*a.begin(), 'a'); + EXPECT_EQ(*(b.begin() + 2), 'c'); + EXPECT_EQ(*(c.end() - 1), 'z'); + + EXPECT_EQ(*a.rbegin(), 'z'); + EXPECT_EQ(*(b.rbegin() + 2), 'a'); + EXPECT_EQ(*(c.rend() - 1), 'x'); + EXPECT_TRUE(a.rbegin() + 26 == a.rend()); + + EXPECT_EQ(a.size(), 26); + EXPECT_EQ(b.size(), 3); + EXPECT_EQ(c.size(), 3); + EXPECT_EQ(d.size(), 6); + EXPECT_EQ(e.size(), 0); + EXPECT_EQ(f.size(), 7); + + EXPECT_TRUE(!d.empty()); + EXPECT_TRUE(d.begin() != d.end()); + EXPECT_TRUE(d.begin() + 6 == d.end()); + + EXPECT_TRUE(e.empty()); + EXPECT_TRUE(e.begin() == e.end()); + + EXPECT_GE(a.max_size(), a.capacity()); + EXPECT_GE(a.capacity(), a.size()); + + char buf[4] = { '%', '%', '%', '%' }; + EXPECT_EQ(a.copy(buf, 4), 4); + EXPECT_EQ(buf[0], a[0]); + EXPECT_EQ(buf[1], a[1]); + EXPECT_EQ(buf[2], a[2]); + EXPECT_EQ(buf[3], a[3]); + EXPECT_EQ(a.copy(buf, 3, 7), 3); + EXPECT_EQ(buf[0], a[7]); + EXPECT_EQ(buf[1], a[8]); + EXPECT_EQ(buf[2], a[9]); + EXPECT_EQ(buf[3], a[3]); + EXPECT_EQ(c.copy(buf, 99), 3); + EXPECT_EQ(buf[0], c[0]); + EXPECT_EQ(buf[1], c[1]); + EXPECT_EQ(buf[2], c[2]); + EXPECT_EQ(buf[3], a[3]); +} + +// Separated from STL1() because some compilers produce an overly +// large stack frame for the combined function. +TEST(StringPiece, STL2) { + const StringPiece a("abcdefghijklmnopqrstuvwxyz"); + const StringPiece b("abc"); + const StringPiece c("xyz"); + const StringPiece e; + const StringPiece f("123" "\0" "456", 7); + + EXPECT_EQ(StringPiece::npos, std::string::npos); + + EXPECT_EQ(a.find(b), 0); + EXPECT_EQ(a.find(b, 1), StringPiece::npos); + EXPECT_EQ(a.find(c), 23); + EXPECT_EQ(a.find(c, 9), 23); + EXPECT_EQ(a.find(c, StringPiece::npos), StringPiece::npos); + EXPECT_EQ(b.find(c), StringPiece::npos); + EXPECT_EQ(b.find(c, StringPiece::npos), StringPiece::npos); + EXPECT_EQ(a.find(e), 0); + EXPECT_EQ(a.find(e, 17), 17); + StringPiece g("xx not found bb"); + EXPECT_EQ(a.find(g), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(e.find(b), StringPiece::npos); + EXPECT_EQ(e.find(b, 7), StringPiece::npos); + + size_t empty_search_pos = std::string().find(std::string()); + EXPECT_EQ(e.find(e), empty_search_pos); + EXPECT_EQ(e.find(e, 4), std::string().find(std::string(), 4)); + + EXPECT_EQ(a.find('a'), 0); + EXPECT_EQ(a.find('c'), 2); + EXPECT_EQ(a.find('z'), 25); + EXPECT_EQ(a.find('$'), StringPiece::npos); + EXPECT_EQ(a.find('\0'), StringPiece::npos); + EXPECT_EQ(f.find('\0'), 3); + EXPECT_EQ(f.find('3'), 2); + EXPECT_EQ(f.find('5'), 5); + EXPECT_EQ(g.find('o'), 4); + EXPECT_EQ(g.find('o', 4), 4); + EXPECT_EQ(g.find('o', 5), 8); + EXPECT_EQ(a.find('b', 5), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(e.find('\0'), StringPiece::npos); + EXPECT_EQ(e.find('\0', 7), StringPiece::npos); + EXPECT_EQ(e.find('x'), StringPiece::npos); + EXPECT_EQ(e.find('x', 7), StringPiece::npos); + + EXPECT_EQ(a.rfind(b), 0); + EXPECT_EQ(a.rfind(b, 1), 0); + EXPECT_EQ(a.rfind(c), 23); + EXPECT_EQ(a.rfind(c, 22), StringPiece::npos); + EXPECT_EQ(a.rfind(c, 1), StringPiece::npos); + EXPECT_EQ(a.rfind(c, 0), StringPiece::npos); + EXPECT_EQ(b.rfind(c), StringPiece::npos); + EXPECT_EQ(b.rfind(c, 0), StringPiece::npos); + EXPECT_EQ(a.rfind(e), a.as_string().rfind(std::string())); + EXPECT_EQ(a.rfind(e, 17), 17); + EXPECT_EQ(a.rfind(g), StringPiece::npos); + EXPECT_EQ(e.rfind(b), StringPiece::npos); + EXPECT_EQ(e.rfind(b, 7), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(e.rfind(e, 7), std::string().rfind(std::string())); + EXPECT_EQ(e.rfind(e), std::string().rfind(std::string())); + + EXPECT_EQ(g.rfind('o'), 8); + EXPECT_EQ(g.rfind('q'), StringPiece::npos); + EXPECT_EQ(g.rfind('o', 8), 8); + EXPECT_EQ(g.rfind('o', 7), 4); + EXPECT_EQ(g.rfind('o', 3), StringPiece::npos); + EXPECT_EQ(f.rfind('\0'), 3); + EXPECT_EQ(f.rfind('\0', 12), 3); + EXPECT_EQ(f.rfind('3'), 2); + EXPECT_EQ(f.rfind('5'), 5); + // empty string nonsense + EXPECT_EQ(e.rfind('o'), StringPiece::npos); + EXPECT_EQ(e.rfind('o', 7), StringPiece::npos); + + EXPECT_EQ(a.find_first_of(b), 0); + EXPECT_EQ(a.find_first_of(b, 0), 0); + EXPECT_EQ(a.find_first_of(b, 1), 1); + EXPECT_EQ(a.find_first_of(b, 2), 2); + EXPECT_EQ(a.find_first_of(b, 3), StringPiece::npos); + EXPECT_EQ(a.find_first_of(c), 23); + EXPECT_EQ(a.find_first_of(c, 23), 23); + EXPECT_EQ(a.find_first_of(c, 24), 24); + EXPECT_EQ(a.find_first_of(c, 25), 25); + EXPECT_EQ(a.find_first_of(c, 26), StringPiece::npos); + EXPECT_EQ(g.find_first_of(b), 13); + EXPECT_EQ(g.find_first_of(c), 0); + EXPECT_EQ(a.find_first_of(f), StringPiece::npos); + EXPECT_EQ(f.find_first_of(a), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(a.find_first_of(e), StringPiece::npos); + EXPECT_EQ(e.find_first_of(b), StringPiece::npos); + EXPECT_EQ(e.find_first_of(e), StringPiece::npos); + + EXPECT_EQ(a.find_first_not_of(b), 3); + EXPECT_EQ(a.find_first_not_of(c), 0); + EXPECT_EQ(b.find_first_not_of(a), StringPiece::npos); + EXPECT_EQ(c.find_first_not_of(a), StringPiece::npos); + EXPECT_EQ(f.find_first_not_of(a), 0); + EXPECT_EQ(a.find_first_not_of(f), 0); + EXPECT_EQ(a.find_first_not_of(e), 0); + // empty string nonsense + EXPECT_EQ(e.find_first_not_of(a), StringPiece::npos); + EXPECT_EQ(e.find_first_not_of(e), StringPiece::npos); + + StringPiece h("===="); + EXPECT_EQ(h.find_first_not_of('='), StringPiece::npos); + EXPECT_EQ(h.find_first_not_of('=', 3), StringPiece::npos); + EXPECT_EQ(h.find_first_not_of('\0'), 0); + EXPECT_EQ(g.find_first_not_of('x'), 2); + EXPECT_EQ(f.find_first_not_of('\0'), 0); + EXPECT_EQ(f.find_first_not_of('\0', 3), 4); + EXPECT_EQ(f.find_first_not_of('\0', 2), 2); + // empty string nonsense + EXPECT_EQ(e.find_first_not_of('x'), StringPiece::npos); + EXPECT_EQ(e.find_first_not_of('\0'), StringPiece::npos); + + // StringPiece g("xx not found bb"); + StringPiece i("56"); + EXPECT_EQ(h.find_last_of(a), StringPiece::npos); + EXPECT_EQ(g.find_last_of(a), g.size()-1); + EXPECT_EQ(a.find_last_of(b), 2); + EXPECT_EQ(a.find_last_of(c), a.size()-1); + EXPECT_EQ(f.find_last_of(i), 6); + EXPECT_EQ(a.find_last_of('a'), 0); + EXPECT_EQ(a.find_last_of('b'), 1); + EXPECT_EQ(a.find_last_of('z'), 25); + EXPECT_EQ(a.find_last_of('a', 5), 0); + EXPECT_EQ(a.find_last_of('b', 5), 1); + EXPECT_EQ(a.find_last_of('b', 0), StringPiece::npos); + EXPECT_EQ(a.find_last_of('z', 25), 25); + EXPECT_EQ(a.find_last_of('z', 24), StringPiece::npos); + EXPECT_EQ(f.find_last_of(i, 5), 5); + EXPECT_EQ(f.find_last_of(i, 6), 6); + EXPECT_EQ(f.find_last_of(a, 4), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(f.find_last_of(e), StringPiece::npos); + EXPECT_EQ(f.find_last_of(e, 4), StringPiece::npos); + EXPECT_EQ(e.find_last_of(e), StringPiece::npos); + EXPECT_EQ(e.find_last_of(f), StringPiece::npos); + EXPECT_EQ(e.find_last_of(e, 4), StringPiece::npos); + EXPECT_EQ(e.find_last_of(f, 4), StringPiece::npos); + + EXPECT_EQ(a.find_last_not_of(b), a.size()-1); + EXPECT_EQ(a.find_last_not_of(c), 22); + EXPECT_EQ(b.find_last_not_of(a), StringPiece::npos); + EXPECT_EQ(b.find_last_not_of(b), StringPiece::npos); + EXPECT_EQ(f.find_last_not_of(i), 4); + EXPECT_EQ(a.find_last_not_of(c, 24), 22); + EXPECT_EQ(a.find_last_not_of(b, 3), 3); + EXPECT_EQ(a.find_last_not_of(b, 2), StringPiece::npos); + // empty string nonsense + EXPECT_EQ(f.find_last_not_of(e), f.size()-1); + EXPECT_EQ(f.find_last_not_of(e, 4), 4); + EXPECT_EQ(e.find_last_not_of(e), StringPiece::npos); + EXPECT_EQ(e.find_last_not_of(f), StringPiece::npos); + EXPECT_EQ(e.find_last_not_of(e, 4), StringPiece::npos); + EXPECT_EQ(e.find_last_not_of(f, 4), StringPiece::npos); + + EXPECT_EQ(h.find_last_not_of('x'), h.size() - 1); + EXPECT_EQ(h.find_last_not_of('='), StringPiece::npos); + EXPECT_EQ(b.find_last_not_of('c'), 1); + EXPECT_EQ(h.find_last_not_of('x', 2), 2); + EXPECT_EQ(h.find_last_not_of('=', 2), StringPiece::npos); + EXPECT_EQ(b.find_last_not_of('b', 1), 0); + // empty string nonsense + EXPECT_EQ(e.find_last_not_of('x'), StringPiece::npos); + EXPECT_EQ(e.find_last_not_of('\0'), StringPiece::npos); + + EXPECT_EQ(a.substr(0, 3), b); + EXPECT_EQ(a.substr(23), c); + EXPECT_EQ(a.substr(23, 3), c); + EXPECT_EQ(a.substr(23, 99), c); + EXPECT_EQ(a.substr(0), a); + EXPECT_EQ(a.substr(3, 2), "de"); + // empty string nonsense + EXPECT_EQ(a.substr(99, 2), e); + EXPECT_EQ(e.substr(99), e); + EXPECT_EQ(e.substr(0, 99), e); + EXPECT_EQ(e.substr(99, 99), e); + // use of npos + EXPECT_EQ(a.substr(0, StringPiece::npos), a); + EXPECT_EQ(a.substr(23, StringPiece::npos), c); + EXPECT_EQ(a.substr(StringPiece::npos, 0), e); + EXPECT_EQ(a.substr(StringPiece::npos, 1), e); + EXPECT_EQ(a.substr(StringPiece::npos, StringPiece::npos), e); +} + +TEST(StringPiece, Custom) { + StringPiece a("foobar"); + std::string s1("123"); + s1 += '\0'; + s1 += "456"; + StringPiece b(s1); + StringPiece e; + std::string s2; + + // CopyToString + a.CopyToString(&s2); + EXPECT_EQ(s2.size(), 6); + EXPECT_EQ(s2, "foobar"); + b.CopyToString(&s2); + EXPECT_EQ(s2.size(), 7); + EXPECT_EQ(s1, s2); + e.CopyToString(&s2); + EXPECT_TRUE(s2.empty()); + + // AppendToString + s2.erase(); + a.AppendToString(&s2); + EXPECT_EQ(s2.size(), 6); + EXPECT_EQ(s2, "foobar"); + a.AppendToString(&s2); + EXPECT_EQ(s2.size(), 12); + EXPECT_EQ(s2, "foobarfoobar"); + + // starts_with + EXPECT_TRUE(a.starts_with(a)); + EXPECT_TRUE(a.starts_with("foo")); + EXPECT_TRUE(a.starts_with(e)); + EXPECT_TRUE(b.starts_with(s1)); + EXPECT_TRUE(b.starts_with(b)); + EXPECT_TRUE(b.starts_with(e)); + EXPECT_TRUE(e.starts_with("")); + EXPECT_TRUE(!a.starts_with(b)); + EXPECT_TRUE(!b.starts_with(a)); + EXPECT_TRUE(!e.starts_with(a)); + + // ends with + EXPECT_TRUE(a.ends_with(a)); + EXPECT_TRUE(a.ends_with("bar")); + EXPECT_TRUE(a.ends_with(e)); + EXPECT_TRUE(b.ends_with(s1)); + EXPECT_TRUE(b.ends_with(b)); + EXPECT_TRUE(b.ends_with(e)); + EXPECT_TRUE(e.ends_with("")); + EXPECT_TRUE(!a.ends_with(b)); + EXPECT_TRUE(!b.ends_with(a)); + EXPECT_TRUE(!e.ends_with(a)); + + // remove_prefix + StringPiece c(a); + c.remove_prefix(3); + EXPECT_EQ(c, "bar"); + c = a; + c.remove_prefix(0); + EXPECT_EQ(c, a); + c.remove_prefix(c.size()); + EXPECT_EQ(c, e); + + // remove_suffix + c = a; + c.remove_suffix(3); + EXPECT_EQ(c, "foo"); + c = a; + c.remove_suffix(0); + EXPECT_EQ(c, a); + c.remove_suffix(c.size()); + EXPECT_EQ(c, e); + + c = StringPiece("foobar", 7); + + // as_string + std::string s3(a.as_string().c_str(), 7); + EXPECT_EQ(c, s3); + std::string s4(e.as_string()); + EXPECT_TRUE(s4.empty()); + + // ToString + { + std::string s5(a.ToString().c_str(), 7); + EXPECT_EQ(c, s5); + std::string s6(e.ToString()); + EXPECT_TRUE(s6.empty()); + } + + // Consume + { + StringPiece str("foobar"); + EXPECT_TRUE(str.Consume("foo")); + EXPECT_EQ(str, "bar"); + EXPECT_FALSE(str.Consume("foo")); + EXPECT_FALSE(str.Consume("barbar")); + EXPECT_FALSE(str.Consume("ar")); + EXPECT_EQ(str, "bar"); + } + + { + StringPiece str("foobar"); + EXPECT_TRUE(str.ConsumeFromEnd("bar")); + EXPECT_EQ(str, "foo"); + EXPECT_FALSE(str.ConsumeFromEnd("bar")); + EXPECT_FALSE(str.ConsumeFromEnd("foofoo")); + EXPECT_FALSE(str.ConsumeFromEnd("fo")); + EXPECT_EQ(str, "foo"); + } +} + +TEST(StringPiece, Contains) { + StringPiece a("abcdefg"); + StringPiece b("abcd"); + StringPiece c("efg"); + StringPiece d("gh"); + EXPECT_TRUE(a.contains(b)); + EXPECT_TRUE(a.contains(c)); + EXPECT_TRUE(!a.contains(d)); +} + +TEST(StringPiece, NullInput) { + // we used to crash here, but now we don't. + StringPiece s(nullptr); + EXPECT_EQ(s.data(), (const char*)nullptr); + EXPECT_EQ(s.size(), 0); + + // .ToString() on a StringPiece with nullptr should produce the empty string. + EXPECT_EQ("", s.ToString()); + EXPECT_EQ("", s.as_string()); +} + +TEST(StringPiece, Comparisons2) { + StringPiece abc("abcdefghijklmnopqrstuvwxyz"); + + // check comparison operations on strings longer than 4 bytes. + EXPECT_EQ(abc, StringPiece("abcdefghijklmnopqrstuvwxyz")); + EXPECT_EQ(abc.compare(StringPiece("abcdefghijklmnopqrstuvwxyz")), 0); + + EXPECT_LT(abc, StringPiece("abcdefghijklmnopqrstuvwxzz")); + EXPECT_LT(abc.compare(StringPiece("abcdefghijklmnopqrstuvwxzz")), 0); + + EXPECT_GT(abc, StringPiece("abcdefghijklmnopqrstuvwxyy")); + EXPECT_GT(abc.compare(StringPiece("abcdefghijklmnopqrstuvwxyy")), 0); + + // starts_with + EXPECT_TRUE(abc.starts_with(abc)); + EXPECT_TRUE(abc.starts_with("abcdefghijklm")); + EXPECT_TRUE(!abc.starts_with("abcdefguvwxyz")); + + // ends_with + EXPECT_TRUE(abc.ends_with(abc)); + EXPECT_TRUE(!abc.ends_with("abcdefguvwxyz")); + EXPECT_TRUE(abc.ends_with("nopqrstuvwxyz")); +} + +TEST(ComparisonOpsTest, StringCompareNotAmbiguous) { + EXPECT_EQ("hello", std::string("hello")); + EXPECT_LT("hello", std::string("world")); +} + +TEST(ComparisonOpsTest, HeterogenousStringPieceEquals) { + EXPECT_EQ(StringPiece("hello"), std::string("hello")); + EXPECT_EQ("hello", StringPiece("hello")); +} + +TEST(FindOneCharTest, EdgeCases) { + StringPiece a("xxyyyxx"); + + // Set a = "xyyyx". + a.remove_prefix(1); + a.remove_suffix(1); + + EXPECT_EQ(0, a.find('x')); + EXPECT_EQ(0, a.find('x', 0)); + EXPECT_EQ(4, a.find('x', 1)); + EXPECT_EQ(4, a.find('x', 4)); + EXPECT_EQ(StringPiece::npos, a.find('x', 5)); + + EXPECT_EQ(4, a.rfind('x')); + EXPECT_EQ(4, a.rfind('x', 5)); + EXPECT_EQ(4, a.rfind('x', 4)); + EXPECT_EQ(0, a.rfind('x', 3)); + EXPECT_EQ(0, a.rfind('x', 0)); + + // Set a = "yyy". + a.remove_prefix(1); + a.remove_suffix(1); + + EXPECT_EQ(StringPiece::npos, a.find('x')); + EXPECT_EQ(StringPiece::npos, a.rfind('x')); +} + +#ifdef PROTOBUF_HAS_DEATH_TEST +#ifndef NDEBUG +TEST(NonNegativeLenTest, NonNegativeLen) { + EXPECT_DEATH(StringPiece("xyz", -1), "string length exceeds max size"); +} +#endif // ndef DEBUG +#endif // PROTOBUF_HAS_DEATH_TEST + +} // namespace +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/stringprintf.cc b/libs/protobuf/src/google/protobuf/stubs/stringprintf.cc new file mode 100644 index 0000000..a6ad4c0 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringprintf.cc @@ -0,0 +1,175 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2012 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. + +// from google3/base/stringprintf.cc + +#include + +#include +#include // For va_list and related operations +#include // MSVC requires this for _vsnprintf +#include + +#include +#include + +namespace google { +namespace protobuf { + +#ifdef _MSC_VER +#ifndef va_copy +// Define va_copy for MSVC. This is a hack, assuming va_list is simply a +// pointer into the stack and is safe to copy. +#define va_copy(dest, src) ((dest) = (src)) +#endif +#endif + +void StringAppendV(std::string* dst, const char* format, va_list ap) { + // First try with a small fixed size buffer + static const int kSpaceLength = 1024; + char space[kSpaceLength]; + + // It's possible for methods that use a va_list to invalidate + // the data in it upon use. The fix is to make a copy + // of the structure before using it and use that copy instead. + va_list backup_ap; + va_copy(backup_ap, ap); + int result = vsnprintf(space, kSpaceLength, format, backup_ap); + va_end(backup_ap); + + if (result < kSpaceLength) { + if (result >= 0) { + // Normal case -- everything fit. + dst->append(space, result); + return; + } + +#ifdef _MSC_VER + { + // Error or MSVC running out of space. MSVC 8.0 and higher + // can be asked about space needed with the special idiom below: + va_copy(backup_ap, ap); + result = vsnprintf(nullptr, 0, format, backup_ap); + va_end(backup_ap); + } +#endif + + if (result < 0) { + // Just an error. + return; + } + } + + // Increase the buffer size to the size requested by vsnprintf, + // plus one for the closing \0. + int length = result+1; + char* buf = new char[length]; + + // Restore the va_list before we use it again + va_copy(backup_ap, ap); + result = vsnprintf(buf, length, format, backup_ap); + va_end(backup_ap); + + if (result >= 0 && result < length) { + // It fit + dst->append(buf, result); + } + delete[] buf; +} + +std::string StringPrintf(const char* format, ...) { + va_list ap; + va_start(ap, format); + std::string result; + StringAppendV(&result, format, ap); + va_end(ap); + return result; +} + +const std::string& SStringPrintf(std::string* dst, const char* format, ...) { + va_list ap; + va_start(ap, format); + dst->clear(); + StringAppendV(dst, format, ap); + va_end(ap); + return *dst; +} + +void StringAppendF(std::string* dst, const char* format, ...) { + va_list ap; + va_start(ap, format); + StringAppendV(dst, format, ap); + va_end(ap); +} + +// Max arguments supported by StringPrintVector +const int kStringPrintfVectorMaxArgs = 32; + +// An empty block of zero for filler arguments. This is const so that if +// printf tries to write to it (via %n) then the program gets a SIGSEGV +// and we can fix the problem or protect against an attack. +static const char string_printf_empty_block[256] = { '\0' }; + +std::string StringPrintfVector(const char* format, + const std::vector& v) { + GOOGLE_CHECK_LE(v.size(), kStringPrintfVectorMaxArgs) + << "StringPrintfVector currently only supports up to " + << kStringPrintfVectorMaxArgs << " arguments. " + << "Feel free to add support for more if you need it."; + + // Add filler arguments so that bogus format+args have a harder time + // crashing the program, corrupting the program (%n), + // or displaying random chunks of memory to users. + + const char* cstr[kStringPrintfVectorMaxArgs]; + for (int i = 0; i < v.size(); ++i) { + cstr[i] = v[i].c_str(); + } + for (int i = v.size(); i < GOOGLE_ARRAYSIZE(cstr); ++i) { + cstr[i] = &string_printf_empty_block[0]; + } + + // I do not know any way to pass kStringPrintfVectorMaxArgs arguments, + // or any way to build a va_list by hand, or any API for printf + // that accepts an array of arguments. The best I can do is stick + // this COMPILE_ASSERT right next to the actual statement. + + static_assert(kStringPrintfVectorMaxArgs == 32, "arg_count_mismatch"); + return StringPrintf(format, + cstr[0], cstr[1], cstr[2], cstr[3], cstr[4], + cstr[5], cstr[6], cstr[7], cstr[8], cstr[9], + cstr[10], cstr[11], cstr[12], cstr[13], cstr[14], + cstr[15], cstr[16], cstr[17], cstr[18], cstr[19], + cstr[20], cstr[21], cstr[22], cstr[23], cstr[24], + cstr[25], cstr[26], cstr[27], cstr[28], cstr[29], + cstr[30], cstr[31]); +} +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/stringprintf.h b/libs/protobuf/src/google/protobuf/stubs/stringprintf.h new file mode 100644 index 0000000..e3858be --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringprintf.h @@ -0,0 +1,85 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2012 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. + +// from google3/base/stringprintf.h +// +// Printf variants that place their output in a C++ string. +// +// Usage: +// string result = StringPrintf("%d %s\n", 10, "hello"); +// SStringPrintf(&result, "%d %s\n", 10, "hello"); +// StringAppendF(&result, "%d %s\n", 20, "there"); + +#ifndef GOOGLE_PROTOBUF_STUBS_STRINGPRINTF_H +#define GOOGLE_PROTOBUF_STUBS_STRINGPRINTF_H + +#include +#include +#include + +#include + +#include + +namespace google { +namespace protobuf { + +// Return a C++ string +PROTOBUF_EXPORT extern std::string StringPrintf(const char* format, ...); + +// Store result into a supplied string and return it +PROTOBUF_EXPORT extern const std::string& SStringPrintf(std::string* dst, + const char* format, + ...); + +// Append result to a supplied string +PROTOBUF_EXPORT extern void StringAppendF(std::string* dst, const char* format, + ...); + +// Lower-level routine that takes a va_list and appends to a specified +// string. All other routines are just convenience wrappers around it. +PROTOBUF_EXPORT extern void StringAppendV(std::string* dst, const char* format, + va_list ap); + +// The max arguments supported by StringPrintfVector +PROTOBUF_EXPORT extern const int kStringPrintfVectorMaxArgs; + +// You can use this version when all your arguments are strings, but +// you don't know how many arguments you'll have at compile time. +// StringPrintfVector will LOG(FATAL) if v.size() > kStringPrintfVectorMaxArgs +PROTOBUF_EXPORT extern std::string StringPrintfVector( + const char* format, const std::vector& v); + +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_STRINGPRINTF_H diff --git a/libs/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc new file mode 100644 index 0000000..dbecd2b --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc @@ -0,0 +1,155 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2012 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. + +// from google3/base/stringprintf_unittest.cc + +#include +#include +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace { + +TEST(StringPrintfTest, Empty) { +#if 0 + // gcc 2.95.3, gcc 4.1.0, and gcc 4.2.2 all warn about this: + // warning: zero-length printf format string. + // so we do not allow them in google3. + EXPECT_EQ("", StringPrintf("")); +#endif + EXPECT_EQ("", StringPrintf("%s", std::string().c_str())); + EXPECT_EQ("", StringPrintf("%s", "")); +} + +TEST(StringPrintfTest, Misc) { +// MSVC and mingw does not support $ format specifier. +#if !defined(_MSC_VER) && !defined(__MINGW32__) + EXPECT_EQ("123hello w", StringPrintf("%3$d%2$s %1$c", 'w', "hello", 123)); +#endif // !_MSC_VER +} + +TEST(StringAppendFTest, Empty) { + std::string value("Hello"); + const char* empty = ""; + StringAppendF(&value, "%s", empty); + EXPECT_EQ("Hello", value); +} + +TEST(StringAppendFTest, EmptyString) { + std::string value("Hello"); + StringAppendF(&value, "%s", ""); + EXPECT_EQ("Hello", value); +} + +TEST(StringAppendFTest, String) { + std::string value("Hello"); + StringAppendF(&value, " %s", "World"); + EXPECT_EQ("Hello World", value); +} + +TEST(StringAppendFTest, Int) { + std::string value("Hello"); + StringAppendF(&value, " %d", 123); + EXPECT_EQ("Hello 123", value); +} + +TEST(StringPrintfTest, Multibyte) { + // If we are in multibyte mode and feed invalid multibyte sequence, + // StringPrintf should return an empty string instead of running + // out of memory while trying to determine destination buffer size. + // see b/4194543. + + char* old_locale_c = setlocale(LC_CTYPE, nullptr); + ASSERT_TRUE(old_locale_c != nullptr); + std::string old_locale = old_locale_c; + // Push locale with multibyte mode + setlocale(LC_CTYPE, "en_US.utf8"); + + const char kInvalidCodePoint[] = "\375\067s"; + std::string value = StringPrintf("%.*s", 3, kInvalidCodePoint); + + // In some versions of glibc (e.g. eglibc-2.11.1, aka GRTEv2), snprintf + // returns error given an invalid codepoint. Other versions + // (e.g. eglibc-2.15, aka pre-GRTEv3) emit the codepoint verbatim. + // We test that the output is one of the above. + EXPECT_TRUE(value.empty() || value == kInvalidCodePoint); + + // Repeat with longer string, to make sure that the dynamically + // allocated path in StringAppendV is handled correctly. + const size_t n = 2048; + std::array buf; + memset(&buf[0], ' ', n - 3); + memcpy(&buf[0] + n - 3, kInvalidCodePoint, 4); + value = StringPrintf("%.*s", n, &buf[0]); + // See GRTEv2 vs. GRTEv3 comment above. + EXPECT_TRUE(value.empty() || value == &buf[0]); + + setlocale(LC_CTYPE, old_locale.c_str()); +} + +TEST(StringPrintfTest, NoMultibyte) { + // No multibyte handling, but the string contains funny chars. + char* old_locale_c = setlocale(LC_CTYPE, nullptr); + ASSERT_TRUE(old_locale_c != nullptr); + std::string old_locale = old_locale_c; + setlocale(LC_CTYPE, "POSIX"); + std::string value = StringPrintf("%.*s", 3, "\375\067s"); + setlocale(LC_CTYPE, old_locale.c_str()); + EXPECT_EQ("\375\067s", value); +} + +TEST(StringPrintfTest, DontOverwriteErrno) { + // Check that errno isn't overwritten unless we're printing + // something significantly larger than what people are normally + // printing in their badly written PLOG() statements. + errno = ECHILD; + std::string value = StringPrintf("Hello, %s!", "World"); + EXPECT_EQ(ECHILD, errno); +} + +TEST(StringPrintfTest, LargeBuf) { + // Check that the large buffer is handled correctly. + int n = 2048; + char* buf = new char[n+1]; + memset(buf, ' ', n); + buf[n] = 0; + std::string value = StringPrintf("%s", buf); + EXPECT_EQ(buf, value); + delete[] buf; +} + +} // anonymous namespace +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/structurally_valid.cc b/libs/protobuf/src/google/protobuf/stubs/structurally_valid.cc index 418b40b..a535736 100644 --- a/libs/protobuf/src/google/protobuf/stubs/structurally_valid.cc +++ b/libs/protobuf/src/google/protobuf/stubs/structurally_valid.cc @@ -30,8 +30,9 @@ // Author: jrm@google.com (Jim Meehan) -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/common.h" +#include + +#include namespace google { namespace protobuf { @@ -562,7 +563,7 @@ bool IsStructurallyValidUTF8(const char* buf, int len) { return (bytes_consumed == len); } -int UTF8SpnStructurallyValid(absl::string_view str) { +int UTF8SpnStructurallyValid(StringPiece str) { if (!module_initialized_) return str.size(); int bytes_consumed = 0; @@ -583,7 +584,7 @@ int UTF8SpnStructurallyValid(absl::string_view str) { // // Fast case: all is structurally valid and no byte copying is done. // -char* UTF8CoerceToStructurallyValid(absl::string_view src_str, char* idst, +char* UTF8CoerceToStructurallyValid(StringPiece src_str, char* idst, const char replace_char) { const char* isrc = src_str.data(); const int len = src_str.length(); @@ -601,7 +602,7 @@ char* UTF8CoerceToStructurallyValid(absl::string_view src_str, char* idst, dst[0] = replace_char; // replace one bad byte src++; dst++; - absl::string_view str2(src, srclimit - src); + StringPiece str2(src, srclimit - src); n = UTF8SpnStructurallyValid(str2); // scan the remainder memmove(dst, src, n); // copy next good chunk src += n; diff --git a/libs/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc index bb56a68..ebd9c42 100644 --- a/libs/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +++ b/libs/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc @@ -31,10 +31,9 @@ // Copyright 2008 Google Inc. All Rights Reserved. // Author: xpeng@google.com (Peter Peng) +#include #include -#include "google/protobuf/stubs/common.h" - namespace google { namespace protobuf { namespace internal { diff --git a/libs/protobuf/src/google/protobuf/stubs/strutil.cc b/libs/protobuf/src/google/protobuf/stubs/strutil.cc index 7d088a8..594c8ea 100644 --- a/libs/protobuf/src/google/protobuf/stubs/strutil.cc +++ b/libs/protobuf/src/google/protobuf/stubs/strutil.cc @@ -30,20 +30,18 @@ // from google3/strings/strutil.cc -#include "google/protobuf/stubs/strutil.h" +#include #include -#include // FLT_DIG and DBL_DIG +#include // FLT_DIG and DBL_DIG #include #include - #include #include #include -#include "absl/strings/ascii.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/logging.h" +#include +#include #ifdef _WIN32 // MSVC has only _snprintf, not snprintf. @@ -62,7 +60,75 @@ namespace google { namespace protobuf { -namespace { +// These are defined as macros on some platforms. #undef them so that we can +// redefine them. +#undef isxdigit +#undef isprint + +// The definitions of these in ctype.h change based on locale. Since our +// string manipulation is all in relation to the protocol buffer and C++ +// languages, we always want to use the C locale. So, we re-define these +// exactly as we want them. +inline bool isxdigit(char c) { + return ('0' <= c && c <= '9') || + ('a' <= c && c <= 'f') || + ('A' <= c && c <= 'F'); +} + +inline bool isprint(char c) { + return c >= 0x20 && c <= 0x7E; +} + +// ---------------------------------------------------------------------- +// ReplaceCharacters +// Replaces any occurrence of the character 'remove' (or the characters +// in 'remove') with the character 'replacewith'. +// ---------------------------------------------------------------------- +void ReplaceCharacters(std::string *s, const char *remove, char replacewith) { + const char *str_start = s->c_str(); + const char *str = str_start; + for (str = strpbrk(str, remove); + str != nullptr; + str = strpbrk(str + 1, remove)) { + (*s)[str - str_start] = replacewith; + } +} + +void StripWhitespace(std::string *str) { + int str_length = str->length(); + + // Strip off leading whitespace. + int first = 0; + while (first < str_length && ascii_isspace(str->at(first))) { + ++first; + } + // If entire string is white space. + if (first == str_length) { + str->clear(); + return; + } + if (first > 0) { + str->erase(0, first); + str_length -= first; + } + + // Strip off trailing whitespace. + int last = str_length - 1; + while (last >= 0 && ascii_isspace(str->at(last))) { + --last; + } + if (last != (str_length - 1) && last >= 0) { + str->erase(last + 1, std::string::npos); + } +} + +// ---------------------------------------------------------------------- +// StringReplace() +// Replace the "old" pattern with the "new" pattern in a string, +// and append the result to "res". If replace_all is false, +// it only replaces the first instance of "old." +// ---------------------------------------------------------------------- + void StringReplace(const std::string &s, const std::string &oldsub, const std::string &newsub, bool replace_all, std::string *res) { @@ -84,7 +150,6 @@ void StringReplace(const std::string &s, const std::string &oldsub, } while (replace_all); res->append(s, start_pos, s.length() - start_pos); } -} // namespace // ---------------------------------------------------------------------- // StringReplace() @@ -102,6 +167,459 @@ std::string StringReplace(const std::string &s, const std::string &oldsub, return ret; } +// ---------------------------------------------------------------------- +// SplitStringUsing() +// Split a string using a character delimiter. Append the components +// to 'result'. +// +// Note: For multi-character delimiters, this routine will split on *ANY* of +// the characters in the string, not the entire string as a single delimiter. +// ---------------------------------------------------------------------- +template +static inline void SplitStringToIteratorUsing(StringPiece full, + const char *delim, ITR &result) { + // Optimize the common case where delim is a single character. + if (delim[0] != '\0' && delim[1] == '\0') { + char c = delim[0]; + const char* p = full.data(); + const char* end = p + full.size(); + while (p != end) { + if (*p == c) { + ++p; + } else { + const char* start = p; + while (++p != end && *p != c); + *result++ = std::string(start, p - start); + } + } + return; + } + + std::string::size_type begin_index, end_index; + begin_index = full.find_first_not_of(delim); + while (begin_index != std::string::npos) { + end_index = full.find_first_of(delim, begin_index); + if (end_index == std::string::npos) { + *result++ = std::string(full.substr(begin_index)); + return; + } + *result++ = + std::string(full.substr(begin_index, (end_index - begin_index))); + begin_index = full.find_first_not_of(delim, end_index); + } +} + +void SplitStringUsing(StringPiece full, const char *delim, + std::vector *result) { + std::back_insert_iterator > it(*result); + SplitStringToIteratorUsing(full, delim, it); +} + +// Split a string using a character delimiter. Append the components +// to 'result'. If there are consecutive delimiters, this function +// will return corresponding empty strings. The string is split into +// at most the specified number of pieces greedily. This means that the +// last piece may possibly be split further. To split into as many pieces +// as possible, specify 0 as the number of pieces. +// +// If "full" is the empty string, yields an empty string as the only value. +// +// If "pieces" is negative for some reason, it returns the whole string +// ---------------------------------------------------------------------- +template +static inline void SplitStringToIteratorAllowEmpty(StringPiece full, + const char *delim, + int pieces, ITR &result) { + std::string::size_type begin_index, end_index; + begin_index = 0; + + for (int i = 0; (i < pieces-1) || (pieces == 0); i++) { + end_index = full.find_first_of(delim, begin_index); + if (end_index == std::string::npos) { + *result++ = std::string(full.substr(begin_index)); + return; + } + *result++ = + std::string(full.substr(begin_index, (end_index - begin_index))); + begin_index = end_index + 1; + } + *result++ = std::string(full.substr(begin_index)); +} + +void SplitStringAllowEmpty(StringPiece full, const char *delim, + std::vector *result) { + std::back_insert_iterator > it(*result); + SplitStringToIteratorAllowEmpty(full, delim, 0, it); +} + +// ---------------------------------------------------------------------- +// JoinStrings() +// This merges a vector of string components with delim inserted +// as separaters between components. +// +// ---------------------------------------------------------------------- +template +static void JoinStringsIterator(const ITERATOR &start, const ITERATOR &end, + const char *delim, std::string *result) { + GOOGLE_CHECK(result != nullptr); + result->clear(); + int delim_length = strlen(delim); + + // Precompute resulting length so we can reserve() memory in one shot. + int length = 0; + for (ITERATOR iter = start; iter != end; ++iter) { + if (iter != start) { + length += delim_length; + } + length += iter->size(); + } + result->reserve(length); + + // Now combine everything. + for (ITERATOR iter = start; iter != end; ++iter) { + if (iter != start) { + result->append(delim, delim_length); + } + result->append(iter->data(), iter->size()); + } +} + +void JoinStrings(const std::vector &components, const char *delim, + std::string *result) { + JoinStringsIterator(components.begin(), components.end(), delim, result); +} + +// ---------------------------------------------------------------------- +// UnescapeCEscapeSequences() +// This does all the unescaping that C does: \ooo, \r, \n, etc +// Returns length of resulting string. +// The implementation of \x parses any positive number of hex digits, +// but it is an error if the value requires more than 8 bits, and the +// result is truncated to 8 bits. +// +// The second call stores its errors in a supplied string vector. +// If the string vector pointer is nullptr, it reports the errors with LOG(). +// ---------------------------------------------------------------------- + +#define IS_OCTAL_DIGIT(c) (((c) >= '0') && ((c) <= '7')) + +// Protocol buffers doesn't ever care about errors, but I don't want to remove +// the code. +#define LOG_STRING(LEVEL, VECTOR) GOOGLE_LOG_IF(LEVEL, false) + +int UnescapeCEscapeSequences(const char* source, char* dest) { + return UnescapeCEscapeSequences(source, dest, nullptr); +} + +int UnescapeCEscapeSequences(const char *source, char *dest, + std::vector *errors) { + GOOGLE_DCHECK(errors == nullptr) << "Error reporting not implemented."; + + char* d = dest; + const char* p = source; + + // Small optimization for case where source = dest and there's no escaping + while ( p == d && *p != '\0' && *p != '\\' ) + p++, d++; + + while (*p != '\0') { + if (*p != '\\') { + *d++ = *p++; + } else { + switch ( *++p ) { // skip past the '\\' + case '\0': + LOG_STRING(ERROR, errors) << "String cannot end with \\"; + *d = '\0'; + return d - dest; // we're done with p + case 'a': *d++ = '\a'; break; + case 'b': *d++ = '\b'; break; + case 'f': *d++ = '\f'; break; + case 'n': *d++ = '\n'; break; + case 'r': *d++ = '\r'; break; + case 't': *d++ = '\t'; break; + case 'v': *d++ = '\v'; break; + case '\\': *d++ = '\\'; break; + case '?': *d++ = '\?'; break; // \? Who knew? + case '\'': *d++ = '\''; break; + case '"': *d++ = '\"'; break; + case '0': case '1': case '2': case '3': // octal digit: 1 to 3 digits + case '4': case '5': case '6': case '7': { + char ch = *p - '0'; + if ( IS_OCTAL_DIGIT(p[1]) ) + ch = ch * 8 + *++p - '0'; + if ( IS_OCTAL_DIGIT(p[1]) ) // safe (and easy) to do this twice + ch = ch * 8 + *++p - '0'; // now points at last digit + *d++ = ch; + break; + } + case 'x': case 'X': { + if (!isxdigit(p[1])) { + if (p[1] == '\0') { + LOG_STRING(ERROR, errors) << "String cannot end with \\x"; + } else { + LOG_STRING(ERROR, errors) << + "\\x cannot be followed by non-hex digit: \\" << *p << p[1]; + } + break; + } + unsigned int ch = 0; + const char *hex_start = p; + while (isxdigit(p[1])) // arbitrarily many hex digits + ch = (ch << 4) + hex_digit_to_int(*++p); + if (ch > 0xFF) + LOG_STRING(ERROR, errors) + << "Value of " + << "\\" << std::string(hex_start, p + 1 - hex_start) + << " exceeds 8 bits"; + *d++ = ch; + break; + } +#if 0 // TODO(kenton): Support \u and \U? Requires runetochar(). + case 'u': { + // \uhhhh => convert 4 hex digits to UTF-8 + char32 rune = 0; + const char *hex_start = p; + for (int i = 0; i < 4; ++i) { + if (isxdigit(p[1])) { // Look one char ahead. + rune = (rune << 4) + hex_digit_to_int(*++p); // Advance p. + } else { + LOG_STRING(ERROR, errors) + << "\\u must be followed by 4 hex digits: \\" + << std::string(hex_start, p+1-hex_start); + break; + } + } + d += runetochar(d, &rune); + break; + } + case 'U': { + // \Uhhhhhhhh => convert 8 hex digits to UTF-8 + char32 rune = 0; + const char *hex_start = p; + for (int i = 0; i < 8; ++i) { + if (isxdigit(p[1])) { // Look one char ahead. + // Don't change rune until we're sure this + // is within the Unicode limit, but do advance p. + char32 newrune = (rune << 4) + hex_digit_to_int(*++p); + if (newrune > 0x10FFFF) { + LOG_STRING(ERROR, errors) + << "Value of \\" + << std::string(hex_start, p + 1 - hex_start) + << " exceeds Unicode limit (0x10FFFF)"; + break; + } else { + rune = newrune; + } + } else { + LOG_STRING(ERROR, errors) + << "\\U must be followed by 8 hex digits: \\" + << std::string(hex_start, p+1-hex_start); + break; + } + } + d += runetochar(d, &rune); + break; + } +#endif + default: + LOG_STRING(ERROR, errors) << "Unknown escape sequence: \\" << *p; + } + p++; // read past letter we escaped + } + } + *d = '\0'; + return d - dest; +} + +// ---------------------------------------------------------------------- +// UnescapeCEscapeString() +// This does the same thing as UnescapeCEscapeSequences, but creates +// a new string. The caller does not need to worry about allocating +// a dest buffer. This should be used for non performance critical +// tasks such as printing debug messages. It is safe for src and dest +// to be the same. +// +// The second call stores its errors in a supplied string vector. +// If the string vector pointer is nullptr, it reports the errors with LOG(). +// +// In the first and second calls, the length of dest is returned. In the +// the third call, the new string is returned. +// ---------------------------------------------------------------------- +int UnescapeCEscapeString(const std::string &src, std::string *dest) { + return UnescapeCEscapeString(src, dest, nullptr); +} + +int UnescapeCEscapeString(const std::string &src, std::string *dest, + std::vector *errors) { + std::unique_ptr unescaped(new char[src.size() + 1]); + int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), errors); + GOOGLE_CHECK(dest); + dest->assign(unescaped.get(), len); + return len; +} + +std::string UnescapeCEscapeString(const std::string &src) { + std::unique_ptr unescaped(new char[src.size() + 1]); + int len = UnescapeCEscapeSequences(src.c_str(), unescaped.get(), nullptr); + return std::string(unescaped.get(), len); +} + +// ---------------------------------------------------------------------- +// CEscapeString() +// CHexEscapeString() +// Copies 'src' to 'dest', escaping dangerous characters using +// C-style escape sequences. This is very useful for preparing query +// flags. 'src' and 'dest' should not overlap. The 'Hex' version uses +// hexadecimal rather than octal sequences. +// Returns the number of bytes written to 'dest' (not including the \0) +// or -1 if there was insufficient space. +// +// Currently only \n, \r, \t, ", ', \ and !isprint() chars are escaped. +// ---------------------------------------------------------------------- +int CEscapeInternal(const char* src, int src_len, char* dest, + int dest_len, bool use_hex, bool utf8_safe) { + const char* src_end = src + src_len; + int used = 0; + bool last_hex_escape = false; // true if last output char was \xNN + + for (; src < src_end; src++) { + if (dest_len - used < 2) // Need space for two letter escape + return -1; + + bool is_hex_escape = false; + switch (*src) { + case '\n': dest[used++] = '\\'; dest[used++] = 'n'; break; + case '\r': dest[used++] = '\\'; dest[used++] = 'r'; break; + case '\t': dest[used++] = '\\'; dest[used++] = 't'; break; + case '\"': dest[used++] = '\\'; dest[used++] = '\"'; break; + case '\'': dest[used++] = '\\'; dest[used++] = '\''; break; + case '\\': dest[used++] = '\\'; dest[used++] = '\\'; break; + default: + // Note that if we emit \xNN and the src character after that is a hex + // digit then that digit must be escaped too to prevent it being + // interpreted as part of the character code by C. + if ((!utf8_safe || static_cast(*src) < 0x80) && + (!isprint(*src) || + (last_hex_escape && isxdigit(*src)))) { + if (dest_len - used < 4) // need space for 4 letter escape + return -1; + sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"), + static_cast(*src)); + is_hex_escape = use_hex; + used += 4; + } else { + dest[used++] = *src; break; + } + } + last_hex_escape = is_hex_escape; + } + + if (dest_len - used < 1) // make sure that there is room for \0 + return -1; + + dest[used] = '\0'; // doesn't count towards return value though + return used; +} + +// Calculates the length of the C-style escaped version of 'src'. +// Assumes that non-printable characters are escaped using octal sequences, and +// that UTF-8 bytes are not handled specially. +static inline size_t CEscapedLength(StringPiece src) { + static char c_escaped_len[256] = { + 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4, // \t, \n, \r + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // ", ' + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // '0'..'9' + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'A'..'O' + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, // 'P'..'Z', '\' + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 'a'..'o' + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, // 'p'..'z', DEL + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + }; + + size_t escaped_len = 0; + for (StringPiece::size_type i = 0; i < src.size(); ++i) { + unsigned char c = static_cast(src[i]); + escaped_len += c_escaped_len[c]; + } + return escaped_len; +} + +// ---------------------------------------------------------------------- +// Escapes 'src' using C-style escape sequences, and appends the escaped string +// to 'dest'. This version is faster than calling CEscapeInternal as it computes +// the required space using a lookup table, and also does not do any special +// handling for Hex or UTF-8 characters. +// ---------------------------------------------------------------------- +void CEscapeAndAppend(StringPiece src, std::string *dest) { + size_t escaped_len = CEscapedLength(src); + if (escaped_len == src.size()) { + dest->append(src.data(), src.size()); + return; + } + + size_t cur_dest_len = dest->size(); + dest->resize(cur_dest_len + escaped_len); + char* append_ptr = &(*dest)[cur_dest_len]; + + for (StringPiece::size_type i = 0; i < src.size(); ++i) { + unsigned char c = static_cast(src[i]); + switch (c) { + case '\n': *append_ptr++ = '\\'; *append_ptr++ = 'n'; break; + case '\r': *append_ptr++ = '\\'; *append_ptr++ = 'r'; break; + case '\t': *append_ptr++ = '\\'; *append_ptr++ = 't'; break; + case '\"': *append_ptr++ = '\\'; *append_ptr++ = '\"'; break; + case '\'': *append_ptr++ = '\\'; *append_ptr++ = '\''; break; + case '\\': *append_ptr++ = '\\'; *append_ptr++ = '\\'; break; + default: + if (!isprint(c)) { + *append_ptr++ = '\\'; + *append_ptr++ = '0' + c / 64; + *append_ptr++ = '0' + (c % 64) / 8; + *append_ptr++ = '0' + c % 8; + } else { + *append_ptr++ = c; + } + break; + } + } +} + +std::string CEscape(const std::string &src) { + std::string dest; + CEscapeAndAppend(src, &dest); + return dest; +} + +namespace strings { + +std::string Utf8SafeCEscape(const std::string &src) { + const int dest_length = src.size() * 4 + 1; // Maximum possible expansion + std::unique_ptr dest(new char[dest_length]); + const int len = CEscapeInternal(src.data(), src.size(), + dest.get(), dest_length, false, true); + GOOGLE_DCHECK_GE(len, 0); + return std::string(dest.get(), len); +} + +std::string CHexEscape(const std::string &src) { + const int dest_length = src.size() * 4 + 1; // Maximum possible expansion + std::unique_ptr dest(new char[dest_length]); + const int len = CEscapeInternal(src.data(), src.size(), + dest.get(), dest_length, true, false); + GOOGLE_DCHECK_GE(len, 0); + return std::string(dest.get(), len); +} + +} // namespace strings + // ---------------------------------------------------------------------- // strto32_adaptor() // strtou32_adaptor() @@ -270,9 +788,378 @@ bool safe_uint_internal(std::string text, IntType *value_p) { return safe_parse_positive_int(text, value_p); } +// ---------------------------------------------------------------------- +// FastIntToBuffer() +// FastInt64ToBuffer() +// FastHexToBuffer() +// FastHex64ToBuffer() +// FastHex32ToBuffer() +// ---------------------------------------------------------------------- + +// Offset into buffer where FastInt64ToBuffer places the end of string +// null character. Also used by FastInt64ToBufferLeft. +static const int kFastInt64ToBufferOffset = 21; + +char *FastInt64ToBuffer(int64_t i, char* buffer) { + // We could collapse the positive and negative sections, but that + // would be slightly slower for positive numbers... + // 22 bytes is enough to store -2**64, -18446744073709551616. + char* p = buffer + kFastInt64ToBufferOffset; + *p-- = '\0'; + if (i >= 0) { + do { + *p-- = '0' + i % 10; + i /= 10; + } while (i > 0); + return p + 1; + } else { + // On different platforms, % and / have different behaviors for + // negative numbers, so we need to jump through hoops to make sure + // we don't divide negative numbers. + if (i > -10) { + i = -i; + *p-- = '0' + i; + *p = '-'; + return p; + } else { + // Make sure we aren't at MIN_INT, in which case we can't say i = -i + i = i + 10; + i = -i; + *p-- = '0' + i % 10; + // Undo what we did a moment ago + i = i / 10 + 1; + do { + *p-- = '0' + i % 10; + i /= 10; + } while (i > 0); + *p = '-'; + return p; + } + } +} + +// Offset into buffer where FastInt32ToBuffer places the end of string +// null character. Also used by FastInt32ToBufferLeft +static const int kFastInt32ToBufferOffset = 11; + +// Yes, this is a duplicate of FastInt64ToBuffer. But, we need this for the +// compiler to generate 32 bit arithmetic instructions. It's much faster, at +// least with 32 bit binaries. +char *FastInt32ToBuffer(int32_t i, char* buffer) { + // We could collapse the positive and negative sections, but that + // would be slightly slower for positive numbers... + // 12 bytes is enough to store -2**32, -4294967296. + char* p = buffer + kFastInt32ToBufferOffset; + *p-- = '\0'; + if (i >= 0) { + do { + *p-- = '0' + i % 10; + i /= 10; + } while (i > 0); + return p + 1; + } else { + // On different platforms, % and / have different behaviors for + // negative numbers, so we need to jump through hoops to make sure + // we don't divide negative numbers. + if (i > -10) { + i = -i; + *p-- = '0' + i; + *p = '-'; + return p; + } else { + // Make sure we aren't at MIN_INT, in which case we can't say i = -i + i = i + 10; + i = -i; + *p-- = '0' + i % 10; + // Undo what we did a moment ago + i = i / 10 + 1; + do { + *p-- = '0' + i % 10; + i /= 10; + } while (i > 0); + *p = '-'; + return p; + } + } +} + +char *FastHexToBuffer(int i, char* buffer) { + GOOGLE_CHECK(i >= 0) << "FastHexToBuffer() wants non-negative integers, not " << i; + + static const char *hexdigits = "0123456789abcdef"; + char *p = buffer + 21; + *p-- = '\0'; + do { + *p-- = hexdigits[i & 15]; // mod by 16 + i >>= 4; // divide by 16 + } while (i > 0); + return p + 1; +} + +char *InternalFastHexToBuffer(uint64_t value, char* buffer, int num_byte) { + static const char *hexdigits = "0123456789abcdef"; + buffer[num_byte] = '\0'; + for (int i = num_byte - 1; i >= 0; i--) { +#ifdef _M_X64 + // MSVC x64 platform has a bug optimizing the uint32(value) in the #else + // block. Given that the uint32 cast was to improve performance on 32-bit + // platforms, we use 64-bit '&' directly. + buffer[i] = hexdigits[value & 0xf]; +#else + buffer[i] = hexdigits[uint32_t(value) & 0xf]; +#endif + value >>= 4; + } + return buffer; +} + +char *FastHex64ToBuffer(uint64_t value, char* buffer) { + return InternalFastHexToBuffer(value, buffer, 16); +} + +char *FastHex32ToBuffer(uint32_t value, char* buffer) { + return InternalFastHexToBuffer(value, buffer, 8); +} + +// ---------------------------------------------------------------------- +// FastInt32ToBufferLeft() +// FastUInt32ToBufferLeft() +// FastInt64ToBufferLeft() +// FastUInt64ToBufferLeft() +// +// Like the Fast*ToBuffer() functions above, these are intended for speed. +// Unlike the Fast*ToBuffer() functions, however, these functions write +// their output to the beginning of the buffer (hence the name, as the +// output is left-aligned). The caller is responsible for ensuring that +// the buffer has enough space to hold the output. +// +// Returns a pointer to the end of the string (i.e. the null character +// terminating the string). +// ---------------------------------------------------------------------- + +static const char two_ASCII_digits[100][2] = { + {'0','0'}, {'0','1'}, {'0','2'}, {'0','3'}, {'0','4'}, + {'0','5'}, {'0','6'}, {'0','7'}, {'0','8'}, {'0','9'}, + {'1','0'}, {'1','1'}, {'1','2'}, {'1','3'}, {'1','4'}, + {'1','5'}, {'1','6'}, {'1','7'}, {'1','8'}, {'1','9'}, + {'2','0'}, {'2','1'}, {'2','2'}, {'2','3'}, {'2','4'}, + {'2','5'}, {'2','6'}, {'2','7'}, {'2','8'}, {'2','9'}, + {'3','0'}, {'3','1'}, {'3','2'}, {'3','3'}, {'3','4'}, + {'3','5'}, {'3','6'}, {'3','7'}, {'3','8'}, {'3','9'}, + {'4','0'}, {'4','1'}, {'4','2'}, {'4','3'}, {'4','4'}, + {'4','5'}, {'4','6'}, {'4','7'}, {'4','8'}, {'4','9'}, + {'5','0'}, {'5','1'}, {'5','2'}, {'5','3'}, {'5','4'}, + {'5','5'}, {'5','6'}, {'5','7'}, {'5','8'}, {'5','9'}, + {'6','0'}, {'6','1'}, {'6','2'}, {'6','3'}, {'6','4'}, + {'6','5'}, {'6','6'}, {'6','7'}, {'6','8'}, {'6','9'}, + {'7','0'}, {'7','1'}, {'7','2'}, {'7','3'}, {'7','4'}, + {'7','5'}, {'7','6'}, {'7','7'}, {'7','8'}, {'7','9'}, + {'8','0'}, {'8','1'}, {'8','2'}, {'8','3'}, {'8','4'}, + {'8','5'}, {'8','6'}, {'8','7'}, {'8','8'}, {'8','9'}, + {'9','0'}, {'9','1'}, {'9','2'}, {'9','3'}, {'9','4'}, + {'9','5'}, {'9','6'}, {'9','7'}, {'9','8'}, {'9','9'} +}; + +char* FastUInt32ToBufferLeft(uint32_t u, char* buffer) { + uint32_t digits; + const char *ASCII_digits = nullptr; + // The idea of this implementation is to trim the number of divides to as few + // as possible by using multiplication and subtraction rather than mod (%), + // and by outputting two digits at a time rather than one. + // The huge-number case is first, in the hopes that the compiler will output + // that case in one branch-free block of code, and only output conditional + // branches into it from below. + if (u >= 1000000000) { // >= 1,000,000,000 + digits = u / 100000000; // 100,000,000 + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; +sublt100_000_000: + u -= digits * 100000000; // 100,000,000 +lt100_000_000: + digits = u / 1000000; // 1,000,000 + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; +sublt1_000_000: + u -= digits * 1000000; // 1,000,000 +lt1_000_000: + digits = u / 10000; // 10,000 + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; +sublt10_000: + u -= digits * 10000; // 10,000 +lt10_000: + digits = u / 100; + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; +sublt100: + u -= digits * 100; +lt100: + digits = u; + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; +done: + *buffer = 0; + return buffer; + } + + if (u < 100) { + digits = u; + if (u >= 10) goto lt100; + *buffer++ = '0' + digits; + goto done; + } + if (u < 10000) { // 10,000 + if (u >= 1000) goto lt10_000; + digits = u / 100; + *buffer++ = '0' + digits; + goto sublt100; + } + if (u < 1000000) { // 1,000,000 + if (u >= 100000) goto lt1_000_000; + digits = u / 10000; // 10,000 + *buffer++ = '0' + digits; + goto sublt10_000; + } + if (u < 100000000) { // 100,000,000 + if (u >= 10000000) goto lt100_000_000; + digits = u / 1000000; // 1,000,000 + *buffer++ = '0' + digits; + goto sublt1_000_000; + } + // we already know that u < 1,000,000,000 + digits = u / 100000000; // 100,000,000 + *buffer++ = '0' + digits; + goto sublt100_000_000; +} + +char* FastInt32ToBufferLeft(int32_t i, char* buffer) { + uint32_t u = 0; + if (i < 0) { + *buffer++ = '-'; + u -= i; + } else { + u = i; + } + return FastUInt32ToBufferLeft(u, buffer); +} + +char* FastUInt64ToBufferLeft(uint64_t u64, char* buffer) { + int digits; + const char *ASCII_digits = nullptr; + + uint32_t u = static_cast(u64); + if (u == u64) return FastUInt32ToBufferLeft(u, buffer); + + uint64_t top_11_digits = u64 / 1000000000; + buffer = FastUInt64ToBufferLeft(top_11_digits, buffer); + u = u64 - (top_11_digits * 1000000000); + + digits = u / 10000000; // 10,000,000 + GOOGLE_DCHECK_LT(digits, 100); + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; + u -= digits * 10000000; // 10,000,000 + digits = u / 100000; // 100,000 + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; + u -= digits * 100000; // 100,000 + digits = u / 1000; // 1,000 + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; + u -= digits * 1000; // 1,000 + digits = u / 10; + ASCII_digits = two_ASCII_digits[digits]; + buffer[0] = ASCII_digits[0]; + buffer[1] = ASCII_digits[1]; + buffer += 2; + u -= digits * 10; + digits = u; + *buffer++ = '0' + digits; + *buffer = 0; + return buffer; +} + +char* FastInt64ToBufferLeft(int64_t i, char* buffer) { + uint64_t u = 0; + if (i < 0) { + *buffer++ = '-'; + u -= i; + } else { + u = i; + } + return FastUInt64ToBufferLeft(u, buffer); +} + +// ---------------------------------------------------------------------- +// SimpleItoa() +// Description: converts an integer to a string. +// +// Return value: string +// ---------------------------------------------------------------------- + +std::string SimpleItoa(int i) { + char buffer[kFastToBufferSize]; + return (sizeof(i) == 4) ? + FastInt32ToBuffer(i, buffer) : + FastInt64ToBuffer(i, buffer); +} + +std::string SimpleItoa(unsigned int i) { + char buffer[kFastToBufferSize]; + return std::string(buffer, (sizeof(i) == 4) + ? FastUInt32ToBufferLeft(i, buffer) + : FastUInt64ToBufferLeft(i, buffer)); +} + +std::string SimpleItoa(long i) { + char buffer[kFastToBufferSize]; + return (sizeof(i) == 4) ? + FastInt32ToBuffer(i, buffer) : + FastInt64ToBuffer(i, buffer); +} + +std::string SimpleItoa(unsigned long i) { + char buffer[kFastToBufferSize]; + return std::string(buffer, (sizeof(i) == 4) + ? FastUInt32ToBufferLeft(i, buffer) + : FastUInt64ToBufferLeft(i, buffer)); +} + +std::string SimpleItoa(long long i) { + char buffer[kFastToBufferSize]; + return (sizeof(i) == 4) ? + FastInt32ToBuffer(i, buffer) : + FastInt64ToBuffer(i, buffer); +} + +std::string SimpleItoa(unsigned long long i) { + char buffer[kFastToBufferSize]; + return std::string(buffer, (sizeof(i) == 4) + ? FastUInt32ToBufferLeft(i, buffer) + : FastUInt64ToBufferLeft(i, buffer)); +} + // ---------------------------------------------------------------------- // SimpleDtoa() // SimpleFtoa() +// DoubleToBuffer() +// FloatToBuffer() // We want to print the value without losing precision, but we also do // not want to print more digits than necessary. This turns out to be // trickier than it sounds. Numbers like 0.2 cannot be represented @@ -309,18 +1196,23 @@ bool safe_uint_internal(std::string text, IntType *value_p) { // implementation. // ---------------------------------------------------------------------- -namespace { -// In practice, doubles should never need more than 24 bytes and floats -// should never need more than 14 (including null terminators), but we -// overestimate to be safe. -constexpr int kDoubleToBufferSize = 32; -constexpr int kFloatToBufferSize = 24; - -static inline bool IsValidFloatChar(char c) { - return ('0' <= c && c <= '9') || c == 'e' || c == 'E' || c == '+' || c == '-'; +std::string SimpleDtoa(double value) { + char buffer[kDoubleToBufferSize]; + return DoubleToBuffer(value, buffer); } -void DelocalizeRadix(char *buffer) { +std::string SimpleFtoa(float value) { + char buffer[kFloatToBufferSize]; + return FloatToBuffer(value, buffer); +} + +static inline bool IsValidFloatChar(char c) { + return ('0' <= c && c <= '9') || + c == 'e' || c == 'E' || + c == '+' || c == '-'; +} + +void DelocalizeRadix(char* buffer) { // Fast check: if the buffer has a normal decimal point, assume no // translation is needed. if (strchr(buffer, '.') != nullptr) return; @@ -341,52 +1233,12 @@ void DelocalizeRadix(char *buffer) { if (!IsValidFloatChar(*buffer) && *buffer != '\0') { // It appears the radix was a multi-byte character. We need to remove the // extra bytes. - char *target = buffer; - do { - ++buffer; - } while (!IsValidFloatChar(*buffer) && *buffer != '\0'); + char* target = buffer; + do { ++buffer; } while (!IsValidFloatChar(*buffer) && *buffer != '\0'); memmove(target, buffer, strlen(buffer) + 1); } } -char *FloatToBuffer(float value, char *buffer) { - // FLT_DIG is 6 for IEEE-754 floats, which are used on almost all - // platforms these days. Just in case some system exists where FLT_DIG - // is significantly larger -- and risks overflowing our buffer -- we have - // this assert. - static_assert(FLT_DIG < 10, "FLT_DIG_is_too_big"); - - if (value == std::numeric_limits::infinity()) { - strcpy(buffer, "inf"); - return buffer; - } else if (value == -std::numeric_limits::infinity()) { - strcpy(buffer, "-inf"); - return buffer; - } else if (std::isnan(value)) { - strcpy(buffer, "nan"); - return buffer; - } - - int snprintf_result = - snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG, value); - - // The snprintf should never overflow because the buffer is significantly - // larger than the precision we asked for. - GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); - - float parsed_value; - if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) { - snprintf_result = - snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG + 3, value); - - // Should never overflow; see above. - GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); - } - - DelocalizeRadix(buffer); - return buffer; -} - char* DoubleToBuffer(double value, char* buffer) { // DBL_DIG is 15 for IEEE-754 doubles, which are used on almost all // platforms these days. Just in case some system exists where DBL_DIG @@ -430,17 +1282,6 @@ char* DoubleToBuffer(double value, char* buffer) { DelocalizeRadix(buffer); return buffer; } -} // namespace - -std::string SimpleDtoa(double value) { - char buffer[kDoubleToBufferSize]; - return DoubleToBuffer(value, buffer); -} - -std::string SimpleFtoa(float value) { - char buffer[kFloatToBufferSize]; - return FloatToBuffer(value, buffer); -} static int memcasecmp(const char *s1, const char *s2, size_t len) { const unsigned char *us1 = reinterpret_cast(s1); @@ -448,21 +1289,19 @@ static int memcasecmp(const char *s1, const char *s2, size_t len) { for (size_t i = 0; i < len; i++) { const int diff = - static_cast( - static_cast(absl::ascii_tolower(us1[i]))) - - static_cast( - static_cast(absl::ascii_tolower(us2[i]))); + static_cast(static_cast(ascii_tolower(us1[i]))) - + static_cast(static_cast(ascii_tolower(us2[i]))); if (diff != 0) return diff; } return 0; } -inline bool CaseEqual(absl::string_view s1, absl::string_view s2) { +inline bool CaseEqual(StringPiece s1, StringPiece s2) { if (s1.size() != s2.size()) return false; return memcasecmp(s1.data(), s2.data(), s1.size()) == 0; } -bool safe_strtob(absl::string_view str, bool *value) { +bool safe_strtob(StringPiece str, bool* value) { GOOGLE_CHECK(value != nullptr) << "nullptr output boolean given."; if (CaseEqual(str, "true") || CaseEqual(str, "t") || CaseEqual(str, "yes") || CaseEqual(str, "y") || @@ -494,7 +1333,7 @@ bool safe_strtod(const char* str, double* value) { char* endptr; *value = internal::NoLocaleStrtod(str, &endptr); if (endptr != str) { - while (absl::ascii_isspace(*endptr)) ++endptr; + while (ascii_isspace(*endptr)) ++endptr; } // Ignore range errors from strtod. The values it // returns on underflow and overflow are the right @@ -518,7 +1357,288 @@ bool safe_strtou64(const std::string &str, uint64_t *value) { return safe_uint_internal(str, value); } -namespace { +char* FloatToBuffer(float value, char* buffer) { + // FLT_DIG is 6 for IEEE-754 floats, which are used on almost all + // platforms these days. Just in case some system exists where FLT_DIG + // is significantly larger -- and risks overflowing our buffer -- we have + // this assert. + static_assert(FLT_DIG < 10, "FLT_DIG_is_too_big"); + + if (value == std::numeric_limits::infinity()) { + strcpy(buffer, "inf"); + return buffer; + } else if (value == -std::numeric_limits::infinity()) { + strcpy(buffer, "-inf"); + return buffer; + } else if (std::isnan(value)) { + strcpy(buffer, "nan"); + return buffer; + } + + int snprintf_result = + snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG, value); + + // The snprintf should never overflow because the buffer is significantly + // larger than the precision we asked for. + GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); + + float parsed_value; + if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) { + snprintf_result = + snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG + 3, value); + + // Should never overflow; see above. + GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); + } + + DelocalizeRadix(buffer); + return buffer; +} + +namespace strings { + +AlphaNum::AlphaNum(strings::Hex hex) { + char *const end = &digits[kFastToBufferSize]; + char *writer = end; + uint64_t value = hex.value; + uint64_t width = hex.spec; + // We accomplish minimum width by OR'ing in 0x10000 to the user's value, + // where 0x10000 is the smallest hex number that is as wide as the user + // asked for. + uint64_t mask = (static_cast(1) << ((width - 1) * 4)) | value; + static const char hexdigits[] = "0123456789abcdef"; + do { + *--writer = hexdigits[value & 0xF]; + value >>= 4; + mask >>= 4; + } while (mask != 0); + piece_data_ = writer; + piece_size_ = end - writer; +} + +} // namespace strings + +// ---------------------------------------------------------------------- +// StrCat() +// This merges the given strings or integers, with no delimiter. This +// is designed to be the fastest possible way to construct a string out +// of a mix of raw C strings, C++ strings, and integer values. +// ---------------------------------------------------------------------- + +// Append is merely a version of memcpy that returns the address of the byte +// after the area just overwritten. It comes in multiple flavors to minimize +// call overhead. +static char *Append1(char *out, const AlphaNum &x) { + if (x.size() > 0) { + memcpy(out, x.data(), x.size()); + out += x.size(); + } + return out; +} + +static char *Append2(char *out, const AlphaNum &x1, const AlphaNum &x2) { + if (x1.size() > 0) { + memcpy(out, x1.data(), x1.size()); + out += x1.size(); + } + if (x2.size() > 0) { + memcpy(out, x2.data(), x2.size()); + out += x2.size(); + } + return out; +} + +static char *Append4(char *out, const AlphaNum &x1, const AlphaNum &x2, + const AlphaNum &x3, const AlphaNum &x4) { + if (x1.size() > 0) { + memcpy(out, x1.data(), x1.size()); + out += x1.size(); + } + if (x2.size() > 0) { + memcpy(out, x2.data(), x2.size()); + out += x2.size(); + } + if (x3.size() > 0) { + memcpy(out, x3.data(), x3.size()); + out += x3.size(); + } + if (x4.size() > 0) { + memcpy(out, x4.data(), x4.size()); + out += x4.size(); + } + return out; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b) { + std::string result; + result.resize(a.size() + b.size()); + char *const begin = &*result.begin(); + char *out = Append2(begin, a, b); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c) { + std::string result; + result.resize(a.size() + b.size() + c.size()); + char *const begin = &*result.begin(); + char *out = Append2(begin, a, b); + out = Append1(out, c); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d, const AlphaNum &e) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size() + e.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + out = Append1(out, e); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d, const AlphaNum &e, const AlphaNum &f) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + out = Append2(out, e, f); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, + const AlphaNum &g) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size() + g.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + out = Append2(out, e, f); + out = Append1(out, g); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, + const AlphaNum &g, const AlphaNum &h) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size() + g.size() + h.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + out = Append4(out, e, f, g, h); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +std::string StrCat(const AlphaNum &a, const AlphaNum &b, const AlphaNum &c, + const AlphaNum &d, const AlphaNum &e, const AlphaNum &f, + const AlphaNum &g, const AlphaNum &h, const AlphaNum &i) { + std::string result; + result.resize(a.size() + b.size() + c.size() + d.size() + e.size() + + f.size() + g.size() + h.size() + i.size()); + char *const begin = &*result.begin(); + char *out = Append4(begin, a, b, c, d); + out = Append4(out, e, f, g, h); + out = Append1(out, i); + GOOGLE_DCHECK_EQ(out, begin + result.size()); + return result; +} + +// It's possible to call StrAppend with a char * pointer that is partway into +// the string we're appending to. However the results of this are random. +// Therefore, check for this in debug mode. Use unsigned math so we only have +// to do one comparison. +#define GOOGLE_DCHECK_NO_OVERLAP(dest, src) \ + GOOGLE_DCHECK_GT(uintptr_t((src).data() - (dest).data()), \ + uintptr_t((dest).size())) + +void StrAppend(std::string *result, const AlphaNum &a) { + GOOGLE_DCHECK_NO_OVERLAP(*result, a); + result->append(a.data(), a.size()); +} + +void StrAppend(std::string *result, const AlphaNum &a, const AlphaNum &b) { + GOOGLE_DCHECK_NO_OVERLAP(*result, a); + GOOGLE_DCHECK_NO_OVERLAP(*result, b); + std::string::size_type old_size = result->size(); + result->resize(old_size + a.size() + b.size()); + char *const begin = &*result->begin(); + char *out = Append2(begin + old_size, a, b); + GOOGLE_DCHECK_EQ(out, begin + result->size()); +} + +void StrAppend(std::string *result, const AlphaNum &a, const AlphaNum &b, + const AlphaNum &c) { + GOOGLE_DCHECK_NO_OVERLAP(*result, a); + GOOGLE_DCHECK_NO_OVERLAP(*result, b); + GOOGLE_DCHECK_NO_OVERLAP(*result, c); + std::string::size_type old_size = result->size(); + result->resize(old_size + a.size() + b.size() + c.size()); + char *const begin = &*result->begin(); + char *out = Append2(begin + old_size, a, b); + out = Append1(out, c); + GOOGLE_DCHECK_EQ(out, begin + result->size()); +} + +void StrAppend(std::string *result, const AlphaNum &a, const AlphaNum &b, + const AlphaNum &c, const AlphaNum &d) { + GOOGLE_DCHECK_NO_OVERLAP(*result, a); + GOOGLE_DCHECK_NO_OVERLAP(*result, b); + GOOGLE_DCHECK_NO_OVERLAP(*result, c); + GOOGLE_DCHECK_NO_OVERLAP(*result, d); + std::string::size_type old_size = result->size(); + result->resize(old_size + a.size() + b.size() + c.size() + d.size()); + char *const begin = &*result->begin(); + char *out = Append4(begin + old_size, a, b, c, d); + GOOGLE_DCHECK_EQ(out, begin + result->size()); +} + +int GlobalReplaceSubstring(const std::string &substring, + const std::string &replacement, std::string *s) { + GOOGLE_CHECK(s != nullptr); + if (s->empty() || substring.empty()) + return 0; + std::string tmp; + int num_replacements = 0; + int pos = 0; + for (StringPiece::size_type match_pos = + s->find(substring.data(), pos, substring.length()); + match_pos != std::string::npos; pos = match_pos + substring.length(), + match_pos = s->find(substring.data(), pos, + substring.length())) { + ++num_replacements; + // Append the original content before the match. + tmp.append(*s, pos, match_pos - pos); + // Append the replacement for the match. + tmp.append(replacement.begin(), replacement.end()); + } + // Append the content after the last match. If no replacements were made, the + // original string is left untouched. + if (num_replacements > 0) { + tmp.append(*s, pos, s->length() - pos); + s->swap(tmp); + } + return num_replacements; +} + int CalculateBase64EscapedLen(int input_len, bool do_padding) { // Base64 encodes three bytes of input at a time. If the input is not // divisible by three, we pad as appropriate. @@ -533,6 +1653,7 @@ int CalculateBase64EscapedLen(int input_len, bool do_padding) { // 64 input is an integral number of octets, only the following cases // can arise: + // Base64 encodes each three bytes of input into four bytes of output. int len = (input_len / 3) * 4; @@ -565,8 +1686,408 @@ int CalculateBase64EscapedLen(int input_len, bool do_padding) { return len; } -int Base64EscapeInternal(const unsigned char *src, int szsrc, char *dest, - int szdest, const absl::string_view base64, +// Base64Escape does padding, so this calculation includes padding. +int CalculateBase64EscapedLen(int input_len) { + return CalculateBase64EscapedLen(input_len, true); +} + +// ---------------------------------------------------------------------- +// int Base64Unescape() - base64 decoder +// int Base64Escape() - base64 encoder +// int WebSafeBase64Unescape() - Google's variation of base64 decoder +// int WebSafeBase64Escape() - Google's variation of base64 encoder +// +// Check out +// http://tools.ietf.org/html/rfc2045 for formal description, but what we +// care about is that... +// Take the encoded stuff in groups of 4 characters and turn each +// character into a code 0 to 63 thus: +// A-Z map to 0 to 25 +// a-z map to 26 to 51 +// 0-9 map to 52 to 61 +// +(- for WebSafe) maps to 62 +// /(_ for WebSafe) maps to 63 +// There will be four numbers, all less than 64 which can be represented +// by a 6 digit binary number (aaaaaa, bbbbbb, cccccc, dddddd respectively). +// Arrange the 6 digit binary numbers into three bytes as such: +// aaaaaabb bbbbcccc ccdddddd +// Equals signs (one or two) are used at the end of the encoded block to +// indicate that the text was not an integer multiple of three bytes long. +// ---------------------------------------------------------------------- + +int Base64UnescapeInternal(const char *src_param, int szsrc, + char *dest, int szdest, + const signed char* unbase64) { + static const char kPad64Equals = '='; + static const char kPad64Dot = '.'; + + int decode = 0; + int destidx = 0; + int state = 0; + unsigned int ch = 0; + unsigned int temp = 0; + + // If "char" is signed by default, using *src as an array index results in + // accessing negative array elements. Treat the input as a pointer to + // unsigned char to avoid this. + const unsigned char *src = reinterpret_cast(src_param); + + // The GET_INPUT macro gets the next input character, skipping + // over any whitespace, and stopping when we reach the end of the + // string or when we read any non-data character. The arguments are + // an arbitrary identifier (used as a label for goto) and the number + // of data bytes that must remain in the input to avoid aborting the + // loop. +#define GET_INPUT(label, remain) \ + label: \ + --szsrc; \ + ch = *src++; \ + decode = unbase64[ch]; \ + if (decode < 0) { \ + if (ascii_isspace(ch) && szsrc >= remain) \ + goto label; \ + state = 4 - remain; \ + break; \ + } + + // if dest is null, we're just checking to see if it's legal input + // rather than producing output. (I suspect this could just be done + // with a regexp...). We duplicate the loop so this test can be + // outside it instead of in every iteration. + + if (dest) { + // This loop consumes 4 input bytes and produces 3 output bytes + // per iteration. We can't know at the start that there is enough + // data left in the string for a full iteration, so the loop may + // break out in the middle; if so 'state' will be set to the + // number of input bytes read. + + while (szsrc >= 4) { + // We'll start by optimistically assuming that the next four + // bytes of the string (src[0..3]) are four good data bytes + // (that is, no nulls, whitespace, padding chars, or illegal + // chars). We need to test src[0..2] for nulls individually + // before constructing temp to preserve the property that we + // never read past a null in the string (no matter how long + // szsrc claims the string is). + + if (!src[0] || !src[1] || !src[2] || + (temp = ((unsigned(unbase64[src[0]]) << 18) | + (unsigned(unbase64[src[1]]) << 12) | + (unsigned(unbase64[src[2]]) << 6) | + (unsigned(unbase64[src[3]])))) & 0x80000000) { + // Iff any of those four characters was bad (null, illegal, + // whitespace, padding), then temp's high bit will be set + // (because unbase64[] is -1 for all bad characters). + // + // We'll back up and resort to the slower decoder, which knows + // how to handle those cases. + + GET_INPUT(first, 4); + temp = decode; + GET_INPUT(second, 3); + temp = (temp << 6) | decode; + GET_INPUT(third, 2); + temp = (temp << 6) | decode; + GET_INPUT(fourth, 1); + temp = (temp << 6) | decode; + } else { + // We really did have four good data bytes, so advance four + // characters in the string. + + szsrc -= 4; + src += 4; + decode = -1; + ch = '\0'; + } + + // temp has 24 bits of input, so write that out as three bytes. + + if (destidx+3 > szdest) return -1; + dest[destidx+2] = temp; + temp >>= 8; + dest[destidx+1] = temp; + temp >>= 8; + dest[destidx] = temp; + destidx += 3; + } + } else { + while (szsrc >= 4) { + if (!src[0] || !src[1] || !src[2] || + (temp = ((unsigned(unbase64[src[0]]) << 18) | + (unsigned(unbase64[src[1]]) << 12) | + (unsigned(unbase64[src[2]]) << 6) | + (unsigned(unbase64[src[3]])))) & 0x80000000) { + GET_INPUT(first_no_dest, 4); + GET_INPUT(second_no_dest, 3); + GET_INPUT(third_no_dest, 2); + GET_INPUT(fourth_no_dest, 1); + } else { + szsrc -= 4; + src += 4; + decode = -1; + ch = '\0'; + } + destidx += 3; + } + } + +#undef GET_INPUT + + // if the loop terminated because we read a bad character, return + // now. + if (decode < 0 && ch != '\0' && + ch != kPad64Equals && ch != kPad64Dot && !ascii_isspace(ch)) + return -1; + + if (ch == kPad64Equals || ch == kPad64Dot) { + // if we stopped by hitting an '=' or '.', un-read that character -- we'll + // look at it again when we count to check for the proper number of + // equals signs at the end. + ++szsrc; + --src; + } else { + // This loop consumes 1 input byte per iteration. It's used to + // clean up the 0-3 input bytes remaining when the first, faster + // loop finishes. 'temp' contains the data from 'state' input + // characters read by the first loop. + while (szsrc > 0) { + --szsrc; + ch = *src++; + decode = unbase64[ch]; + if (decode < 0) { + if (ascii_isspace(ch)) { + continue; + } else if (ch == '\0') { + break; + } else if (ch == kPad64Equals || ch == kPad64Dot) { + // back up one character; we'll read it again when we check + // for the correct number of pad characters at the end. + ++szsrc; + --src; + break; + } else { + return -1; + } + } + + // Each input character gives us six bits of output. + temp = (temp << 6) | decode; + ++state; + if (state == 4) { + // If we've accumulated 24 bits of output, write that out as + // three bytes. + if (dest) { + if (destidx+3 > szdest) return -1; + dest[destidx+2] = temp; + temp >>= 8; + dest[destidx+1] = temp; + temp >>= 8; + dest[destidx] = temp; + } + destidx += 3; + state = 0; + temp = 0; + } + } + } + + // Process the leftover data contained in 'temp' at the end of the input. + int expected_equals = 0; + switch (state) { + case 0: + // Nothing left over; output is a multiple of 3 bytes. + break; + + case 1: + // Bad input; we have 6 bits left over. + return -1; + + case 2: + // Produce one more output byte from the 12 input bits we have left. + if (dest) { + if (destidx+1 > szdest) return -1; + temp >>= 4; + dest[destidx] = temp; + } + ++destidx; + expected_equals = 2; + break; + + case 3: + // Produce two more output bytes from the 18 input bits we have left. + if (dest) { + if (destidx+2 > szdest) return -1; + temp >>= 2; + dest[destidx+1] = temp; + temp >>= 8; + dest[destidx] = temp; + } + destidx += 2; + expected_equals = 1; + break; + + default: + // state should have no other values at this point. + GOOGLE_LOG(FATAL) << "This can't happen; base64 decoder state = " << state; + } + + // The remainder of the string should be all whitespace, mixed with + // exactly 0 equals signs, or exactly 'expected_equals' equals + // signs. (Always accepting 0 equals signs is a google extension + // not covered in the RFC, as is accepting dot as the pad character.) + + int equals = 0; + while (szsrc > 0 && *src) { + if (*src == kPad64Equals || *src == kPad64Dot) + ++equals; + else if (!ascii_isspace(*src)) + return -1; + --szsrc; + ++src; + } + + return (equals == 0 || equals == expected_equals) ? destidx : -1; +} + +// The arrays below were generated by the following code +// #include +// #include +// #include +// #include +// main() +// { +// static const char Base64[] = +// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +// const char *pos; +// int idx, i, j; +// printf(" "); +// for (i = 0; i < 255; i += 8) { +// for (j = i; j < i + 8; j++) { +// pos = strchr(Base64, j); +// if ((pos == nullptr) || (j == 0)) +// idx = -1; +// else +// idx = pos - Base64; +// if (idx == -1) +// printf(" %2d, ", idx); +// else +// printf(" %2d/""*%c*""/,", idx, j); +// } +// printf("\n "); +// } +// } +// +// where the value of "Base64[]" was replaced by one of the base-64 conversion +// tables from the functions below. +static const signed char kUnBase64[] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 62/*+*/, -1, -1, -1, 63/*/ */, + 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/, + 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1, + -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/, + 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/, + 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/, + 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, -1, + -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/, + 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/, + 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/, + 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1 +}; +static const signed char kUnWebSafeBase64[] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 62/*-*/, -1, -1, + 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/, + 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1, + -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/, + 7/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/, + 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/, + 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, 63/*_*/, + -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/, + 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/, + 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/, + 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1 +}; + +int WebSafeBase64Unescape(const char *src, int szsrc, char *dest, int szdest) { + return Base64UnescapeInternal(src, szsrc, dest, szdest, kUnWebSafeBase64); +} + +static bool Base64UnescapeInternal(const char *src, int slen, std::string *dest, + const signed char *unbase64) { + // Determine the size of the output string. Base64 encodes every 3 bytes into + // 4 characters. any leftover chars are added directly for good measure. + // This is documented in the base64 RFC: http://tools.ietf.org/html/rfc3548 + const int dest_len = 3 * (slen / 4) + (slen % 4); + + dest->resize(dest_len); + + // We are getting the destination buffer by getting the beginning of the + // string and converting it into a char *. + const int len = Base64UnescapeInternal(src, slen, string_as_array(dest), + dest_len, unbase64); + if (len < 0) { + dest->clear(); + return false; + } + + // could be shorter if there was padding + GOOGLE_DCHECK_LE(len, dest_len); + dest->erase(len); + + return true; +} + +bool Base64Unescape(StringPiece src, std::string *dest) { + return Base64UnescapeInternal(src.data(), src.size(), dest, kUnBase64); +} + +bool WebSafeBase64Unescape(StringPiece src, std::string *dest) { + return Base64UnescapeInternal(src.data(), src.size(), dest, kUnWebSafeBase64); +} + +int Base64EscapeInternal(const unsigned char *src, int szsrc, + char *dest, int szdest, const char *base64, bool do_padding) { static const char kPad64 = '='; @@ -665,40 +2186,60 @@ int Base64EscapeInternal(const unsigned char *src, int szsrc, char *dest, return (cur_dest - dest); } +static const char kBase64Chars[] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +static const char kWebSafeBase64Chars[] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + +int Base64Escape(const unsigned char *src, int szsrc, char *dest, int szdest) { + return Base64EscapeInternal(src, szsrc, dest, szdest, kBase64Chars, true); +} +int WebSafeBase64Escape(const unsigned char *src, int szsrc, char *dest, + int szdest, bool do_padding) { + return Base64EscapeInternal(src, szsrc, dest, szdest, + kWebSafeBase64Chars, do_padding); +} + void Base64EscapeInternal(const unsigned char *src, int szsrc, std::string *dest, bool do_padding, - const absl::string_view base64_chars) { - const int calc_escaped_size = CalculateBase64EscapedLen(szsrc, do_padding); + const char *base64_chars) { + const int calc_escaped_size = + CalculateBase64EscapedLen(szsrc, do_padding); dest->resize(calc_escaped_size); - const int escaped_len = Base64EscapeInternal( - src, szsrc, &(*dest)[0], dest->size(), base64_chars, do_padding); + const int escaped_len = Base64EscapeInternal(src, szsrc, + string_as_array(dest), + dest->size(), + base64_chars, + do_padding); GOOGLE_DCHECK_EQ(calc_escaped_size, escaped_len); dest->erase(escaped_len); } -static constexpr absl::string_view kBase64Chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -static constexpr absl::string_view kWebSafeBase64Chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - -} // namespace - -namespace strings { - -void LegacyBase64EscapeWithoutPadding(absl::string_view src, - std::string *dest) { - Base64EscapeInternal(reinterpret_cast(src.data()), - src.size(), dest, /*do_padding=*/false, kBase64Chars); +void Base64Escape(const unsigned char *src, int szsrc, std::string *dest, + bool do_padding) { + Base64EscapeInternal(src, szsrc, dest, do_padding, kBase64Chars); } -void WebSafeBase64EscapeWithPadding(absl::string_view src, std::string *dest) { - Base64EscapeInternal(reinterpret_cast(src.data()), - src.size(), dest, - /*do_padding=*/true, kWebSafeBase64Chars); +void WebSafeBase64Escape(const unsigned char *src, int szsrc, std::string *dest, + bool do_padding) { + Base64EscapeInternal(src, szsrc, dest, do_padding, kWebSafeBase64Chars); } -} // namespace strings +void Base64Escape(StringPiece src, std::string *dest) { + Base64Escape(reinterpret_cast(src.data()), + src.size(), dest, true); +} + +void WebSafeBase64Escape(StringPiece src, std::string *dest) { + WebSafeBase64Escape(reinterpret_cast(src.data()), + src.size(), dest, false); +} + +void WebSafeBase64EscapeWithPadding(StringPiece src, std::string *dest) { + WebSafeBase64Escape(reinterpret_cast(src.data()), + src.size(), dest, true); +} // Helper to append a Unicode code point to a string as UTF8, without bringing // in any external dependencies. @@ -758,6 +2299,111 @@ int UTF8FirstLetterNumBytes(const char* src, int len) { return kUTF8LenTbl[*reinterpret_cast(src)]; } +// ---------------------------------------------------------------------- +// CleanStringLineEndings() +// Clean up a multi-line string to conform to Unix line endings. +// Reads from src and appends to dst, so usually dst should be empty. +// +// If there is no line ending at the end of a non-empty string, it can +// be added automatically. +// +// Four different types of input are correctly handled: +// +// - Unix/Linux files: line ending is LF: pass through unchanged +// +// - DOS/Windows files: line ending is CRLF: convert to LF +// +// - Legacy Mac files: line ending is CR: convert to LF +// +// - Garbled files: random line endings: convert gracefully +// lonely CR, lonely LF, CRLF: convert to LF +// +// @param src The multi-line string to convert +// @param dst The converted string is appended to this string +// @param auto_end_last_line Automatically terminate the last line +// +// Limitations: +// +// This does not do the right thing for CRCRLF files created by +// broken programs that do another Unix->DOS conversion on files +// that are already in CRLF format. For this, a two-pass approach +// brute-force would be needed that +// +// (1) determines the presence of LF (first one is ok) +// (2) if yes, removes any CR, else convert every CR to LF + +void CleanStringLineEndings(const std::string &src, std::string *dst, + bool auto_end_last_line) { + if (dst->empty()) { + dst->append(src); + CleanStringLineEndings(dst, auto_end_last_line); + } else { + std::string tmp = src; + CleanStringLineEndings(&tmp, auto_end_last_line); + dst->append(tmp); + } +} + +void CleanStringLineEndings(std::string *str, bool auto_end_last_line) { + ptrdiff_t output_pos = 0; + bool r_seen = false; + ptrdiff_t len = str->size(); + + char *p = &(*str)[0]; + + for (ptrdiff_t input_pos = 0; input_pos < len;) { + if (!r_seen && input_pos + 8 < len) { + uint64_t v = GOOGLE_UNALIGNED_LOAD64(p + input_pos); + // Loop over groups of 8 bytes at a time until we come across + // a word that has a byte whose value is less than or equal to + // '\r' (i.e. could contain a \n (0x0a) or a \r (0x0d) ). + // + // We use a has_less macro that quickly tests a whole 64-bit + // word to see if any of the bytes has a value < N. + // + // For more details, see: + // http://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord +#define has_less(x, n) (((x) - ~0ULL / 255 * (n)) & ~(x) & ~0ULL / 255 * 128) + if (!has_less(v, '\r' + 1)) { +#undef has_less + // No byte in this word has a value that could be a \r or a \n + if (output_pos != input_pos) { + GOOGLE_UNALIGNED_STORE64(p + output_pos, v); + } + input_pos += 8; + output_pos += 8; + continue; + } + } + std::string::const_reference in = p[input_pos]; + if (in == '\r') { + if (r_seen) p[output_pos++] = '\n'; + r_seen = true; + } else if (in == '\n') { + if (input_pos != output_pos) + p[output_pos++] = '\n'; + else + output_pos++; + r_seen = false; + } else { + if (r_seen) p[output_pos++] = '\n'; + r_seen = false; + if (input_pos != output_pos) + p[output_pos++] = in; + else + output_pos++; + } + input_pos++; + } + if (r_seen || + (auto_end_last_line && output_pos > 0 && p[output_pos - 1] != '\n')) { + str->resize(output_pos + 1); + str->operator[](output_pos) = '\n'; + } else if (output_pos < len) { + str->resize(output_pos); + } +} + namespace internal { // ---------------------------------------------------------------------- diff --git a/libs/protobuf/src/google/protobuf/stubs/strutil.h b/libs/protobuf/src/google/protobuf/stubs/strutil.h index 1e64d7b..9658abf 100644 --- a/libs/protobuf/src/google/protobuf/stubs/strutil.h +++ b/libs/protobuf/src/google/protobuf/stubs/strutil.h @@ -33,19 +33,14 @@ #ifndef GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ #define GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ +#include +#include #include #include +#include #include -#include "absl/strings/str_cat.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/stubs/common.h" - -// Must be last. -#include "google/protobuf/port_def.inc" // NOLINT - namespace google { namespace protobuf { @@ -58,6 +53,49 @@ namespace protobuf { #define strtoull strtoul #endif +// ---------------------------------------------------------------------- +// ascii_isalnum() +// Check if an ASCII character is alphanumeric. We can't use ctype's +// isalnum() because it is affected by locale. This function is applied +// to identifiers in the protocol buffer language, not to natural-language +// strings, so locale should not be taken into account. +// ascii_isdigit() +// Like above, but only accepts digits. +// ascii_isspace() +// Check if the character is a space character. +// ---------------------------------------------------------------------- + +inline bool ascii_isalnum(char c) { + return ('a' <= c && c <= 'z') || + ('A' <= c && c <= 'Z') || + ('0' <= c && c <= '9'); +} + +inline bool ascii_isdigit(char c) { + return ('0' <= c && c <= '9'); +} + +inline bool ascii_isspace(char c) { + return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || + c == '\r'; +} + +inline bool ascii_isupper(char c) { + return c >= 'A' && c <= 'Z'; +} + +inline bool ascii_islower(char c) { + return c >= 'a' && c <= 'z'; +} + +inline char ascii_toupper(char c) { + return ascii_islower(c) ? c - ('a' - 'A') : c; +} + +inline char ascii_tolower(char c) { + return ascii_isupper(c) ? c + ('a' - 'A') : c; +} + inline int hex_digit_to_int(char c) { /* Assume ASCII. */ int x = static_cast(c); @@ -67,6 +105,99 @@ inline int hex_digit_to_int(char c) { return x & 0xf; } +// ---------------------------------------------------------------------- +// HasPrefixString() +// Check if a string begins with a given prefix. +// StripPrefixString() +// Given a string and a putative prefix, returns the string minus the +// prefix string if the prefix matches, otherwise the original +// string. +// ---------------------------------------------------------------------- +inline bool HasPrefixString(StringPiece str, StringPiece prefix) { + return str.size() >= prefix.size() && + memcmp(str.data(), prefix.data(), prefix.size()) == 0; +} + +inline std::string StripPrefixString(const std::string& str, + const std::string& prefix) { + if (HasPrefixString(str, prefix)) { + return str.substr(prefix.size()); + } else { + return str; + } +} + +// ---------------------------------------------------------------------- +// HasSuffixString() +// Return true if str ends in suffix. +// StripSuffixString() +// Given a string and a putative suffix, returns the string minus the +// suffix string if the suffix matches, otherwise the original +// string. +// ---------------------------------------------------------------------- +inline bool HasSuffixString(StringPiece str, StringPiece suffix) { + return str.size() >= suffix.size() && + memcmp(str.data() + str.size() - suffix.size(), suffix.data(), + suffix.size()) == 0; +} + +inline std::string StripSuffixString(const std::string& str, + const std::string& suffix) { + if (HasSuffixString(str, suffix)) { + return str.substr(0, str.size() - suffix.size()); + } else { + return str; + } +} + +// ---------------------------------------------------------------------- +// ReplaceCharacters +// Replaces any occurrence of the character 'remove' (or the characters +// in 'remove') with the character 'replacewith'. +// Good for keeping html characters or protocol characters (\t) out +// of places where they might cause a problem. +// StripWhitespace +// Removes whitespaces from both ends of the given string. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT void ReplaceCharacters(std::string* s, const char* remove, + char replacewith); + +PROTOBUF_EXPORT void StripWhitespace(std::string* s); + +// ---------------------------------------------------------------------- +// LowerString() +// UpperString() +// ToUpper() +// Convert the characters in "s" to lowercase or uppercase. ASCII-only: +// these functions intentionally ignore locale because they are applied to +// identifiers used in the Protocol Buffer language, not to natural-language +// strings. +// ---------------------------------------------------------------------- + +inline void LowerString(std::string* s) { + std::string::iterator end = s->end(); + for (std::string::iterator i = s->begin(); i != end; ++i) { + // tolower() changes based on locale. We don't want this! + if ('A' <= *i && *i <= 'Z') *i += 'a' - 'A'; + } +} + +inline void UpperString(std::string* s) { + std::string::iterator end = s->end(); + for (std::string::iterator i = s->begin(); i != end; ++i) { + // toupper() changes based on locale. We don't want this! + if ('a' <= *i && *i <= 'z') *i += 'A' - 'a'; + } +} + +inline void ToUpper(std::string* s) { UpperString(s); } + +inline std::string ToUpper(const std::string& s) { + std::string out = s; + UpperString(&out); + return out; +} + // ---------------------------------------------------------------------- // StringReplace() // Give me a string and two patterns "old" and "new", and I replace @@ -80,6 +211,140 @@ PROTOBUF_EXPORT std::string StringReplace(const std::string& s, const std::string& newsub, bool replace_all); +// ---------------------------------------------------------------------- +// SplitStringUsing() +// Split a string using a character delimiter. Append the components +// to 'result'. If there are consecutive delimiters, this function skips +// over all of them. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT void SplitStringUsing(StringPiece full, const char* delim, + std::vector* res); + +// Split a string using one or more byte delimiters, presented +// as a nul-terminated c string. Append the components to 'result'. +// If there are consecutive delimiters, this function will return +// corresponding empty strings. If you want to drop the empty +// strings, try SplitStringUsing(). +// +// If "full" is the empty string, yields an empty string as the only value. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT void SplitStringAllowEmpty(StringPiece full, const char* delim, + std::vector* result); + +// ---------------------------------------------------------------------- +// Split() +// Split a string using a character delimiter. +// ---------------------------------------------------------------------- +inline std::vector Split(StringPiece full, const char* delim, + bool skip_empty = true) { + std::vector result; + if (skip_empty) { + SplitStringUsing(full, delim, &result); + } else { + SplitStringAllowEmpty(full, delim, &result); + } + return result; +} + +// ---------------------------------------------------------------------- +// JoinStrings() +// These methods concatenate a vector of strings into a C++ string, using +// the C-string "delim" as a separator between components. There are two +// flavors of the function, one flavor returns the concatenated string, +// another takes a pointer to the target string. In the latter case the +// target string is cleared and overwritten. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT void JoinStrings(const std::vector& components, + const char* delim, std::string* result); + +inline std::string JoinStrings(const std::vector& components, + const char* delim) { + std::string result; + JoinStrings(components, delim, &result); + return result; +} + +// ---------------------------------------------------------------------- +// UnescapeCEscapeSequences() +// Copies "source" to "dest", rewriting C-style escape sequences +// -- '\n', '\r', '\\', '\ooo', etc -- to their ASCII +// equivalents. "dest" must be sufficiently large to hold all +// the characters in the rewritten string (i.e. at least as large +// as strlen(source) + 1 should be safe, since the replacements +// are always shorter than the original escaped sequences). It's +// safe for source and dest to be the same. RETURNS the length +// of dest. +// +// It allows hex sequences \xhh, or generally \xhhhhh with an +// arbitrary number of hex digits, but all of them together must +// specify a value of a single byte (e.g. \x0045 is equivalent +// to \x45, and \x1234 is erroneous). +// +// It also allows escape sequences of the form \uhhhh (exactly four +// hex digits, upper or lower case) or \Uhhhhhhhh (exactly eight +// hex digits, upper or lower case) to specify a Unicode code +// point. The dest array will contain the UTF8-encoded version of +// that code-point (e.g., if source contains \u2019, then dest will +// contain the three bytes 0xE2, 0x80, and 0x99). +// +// Errors: In the first form of the call, errors are reported with +// LOG(ERROR). The same is true for the second form of the call if +// the pointer to the string std::vector is nullptr; otherwise, error +// messages are stored in the std::vector. In either case, the effect on +// the dest array is not defined, but rest of the source will be +// processed. +// ---------------------------------------------------------------------- + +PROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest); +PROTOBUF_EXPORT int UnescapeCEscapeSequences(const char* source, char* dest, + std::vector* errors); + +// ---------------------------------------------------------------------- +// UnescapeCEscapeString() +// This does the same thing as UnescapeCEscapeSequences, but creates +// a new string. The caller does not need to worry about allocating +// a dest buffer. This should be used for non performance critical +// tasks such as printing debug messages. It is safe for src and dest +// to be the same. +// +// The second call stores its errors in a supplied string vector. +// If the string vector pointer is nullptr, it reports the errors with LOG(). +// +// In the first and second calls, the length of dest is returned. In the +// the third call, the new string is returned. +// ---------------------------------------------------------------------- + +PROTOBUF_EXPORT int UnescapeCEscapeString(const std::string& src, + std::string* dest); +PROTOBUF_EXPORT int UnescapeCEscapeString(const std::string& src, + std::string* dest, + std::vector* errors); +PROTOBUF_EXPORT std::string UnescapeCEscapeString(const std::string& src); + +// ---------------------------------------------------------------------- +// CEscape() +// Escapes 'src' using C-style escape sequences and returns the resulting +// string. +// +// Escaped chars: \n, \r, \t, ", ', \, and !isprint(). +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT std::string CEscape(const std::string& src); + +// ---------------------------------------------------------------------- +// CEscapeAndAppend() +// Escapes 'src' using C-style escape sequences, and appends the escaped +// string to 'dest'. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT void CEscapeAndAppend(StringPiece src, std::string* dest); + +namespace strings { +// Like CEscape() but does not escape bytes with the upper bit set. +PROTOBUF_EXPORT std::string Utf8SafeCEscape(const std::string& src); + +// Like CEscape() but uses hex (\x) escapes instead of octals. +PROTOBUF_EXPORT std::string CHexEscape(const std::string& src); +} // namespace strings + // ---------------------------------------------------------------------- // strto32() // strtou32() @@ -132,21 +397,21 @@ inline uint64_t strtou64(const char *nptr, char **endptr, int base) { // safe_strtof() // safe_strtod() // ---------------------------------------------------------------------- -PROTOBUF_EXPORT bool safe_strtob(absl::string_view str, bool* value); +PROTOBUF_EXPORT bool safe_strtob(StringPiece str, bool* value); PROTOBUF_EXPORT bool safe_strto32(const std::string& str, int32_t* value); PROTOBUF_EXPORT bool safe_strtou32(const std::string& str, uint32_t* value); inline bool safe_strto32(const char* str, int32_t* value) { return safe_strto32(std::string(str), value); } -inline bool safe_strto32(absl::string_view str, int32_t* value) { - return safe_strto32(std::string(str), value); +inline bool safe_strto32(StringPiece str, int32_t* value) { + return safe_strto32(str.ToString(), value); } inline bool safe_strtou32(const char* str, uint32_t* value) { return safe_strtou32(std::string(str), value); } -inline bool safe_strtou32(absl::string_view str, uint32_t* value) { - return safe_strtou32(std::string(str), value); +inline bool safe_strtou32(StringPiece str, uint32_t* value) { + return safe_strtou32(str.ToString(), value); } PROTOBUF_EXPORT bool safe_strto64(const std::string& str, int64_t* value); @@ -154,14 +419,14 @@ PROTOBUF_EXPORT bool safe_strtou64(const std::string& str, uint64_t* value); inline bool safe_strto64(const char* str, int64_t* value) { return safe_strto64(std::string(str), value); } -inline bool safe_strto64(absl::string_view str, int64_t* value) { - return safe_strto64(std::string(str), value); +inline bool safe_strto64(StringPiece str, int64_t* value) { + return safe_strto64(str.ToString(), value); } inline bool safe_strtou64(const char* str, uint64_t* value) { return safe_strtou64(std::string(str), value); } -inline bool safe_strtou64(absl::string_view str, uint64_t* value) { - return safe_strtou64(std::string(str), value); +inline bool safe_strtou64(StringPiece str, uint64_t* value) { + return safe_strtou64(str.ToString(), value); } PROTOBUF_EXPORT bool safe_strtof(const char* str, float* value); @@ -172,46 +437,431 @@ inline bool safe_strtof(const std::string& str, float* value) { inline bool safe_strtod(const std::string& str, double* value) { return safe_strtod(str.c_str(), value); } -inline bool safe_strtof(absl::string_view str, float* value) { - return safe_strtof(std::string(str), value); +inline bool safe_strtof(StringPiece str, float* value) { + return safe_strtof(str.ToString(), value); } -inline bool safe_strtod(absl::string_view str, double* value) { - return safe_strtod(std::string(str), value); +inline bool safe_strtod(StringPiece str, double* value) { + return safe_strtod(str.ToString(), value); } +// ---------------------------------------------------------------------- +// FastIntToBuffer() +// FastHexToBuffer() +// FastHex64ToBuffer() +// FastHex32ToBuffer() +// FastTimeToBuffer() +// These are intended for speed. FastIntToBuffer() assumes the +// integer is non-negative. FastHexToBuffer() puts output in +// hex rather than decimal. FastTimeToBuffer() puts the output +// into RFC822 format. +// +// FastHex64ToBuffer() puts a 64-bit unsigned value in hex-format, +// padded to exactly 16 bytes (plus one byte for '\0') +// +// FastHex32ToBuffer() puts a 32-bit unsigned value in hex-format, +// padded to exactly 8 bytes (plus one byte for '\0') +// +// All functions take the output buffer as an arg. +// They all return a pointer to the beginning of the output, +// which may not be the beginning of the input buffer. +// ---------------------------------------------------------------------- + +// Suggested buffer size for FastToBuffer functions. Also works with +// DoubleToBuffer() and FloatToBuffer(). +static const int kFastToBufferSize = 32; + +PROTOBUF_EXPORT char* FastInt32ToBuffer(int32_t i, char* buffer); +PROTOBUF_EXPORT char* FastInt64ToBuffer(int64_t i, char* buffer); +char* FastUInt32ToBuffer(uint32_t i, char* buffer); // inline below +char* FastUInt64ToBuffer(uint64_t i, char* buffer); // inline below +PROTOBUF_EXPORT char* FastHexToBuffer(int i, char* buffer); +PROTOBUF_EXPORT char* FastHex64ToBuffer(uint64_t i, char* buffer); +PROTOBUF_EXPORT char* FastHex32ToBuffer(uint32_t i, char* buffer); + +// at least 22 bytes long +inline char* FastIntToBuffer(int i, char* buffer) { + return (sizeof(i) == 4 ? + FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); +} +inline char* FastUIntToBuffer(unsigned int i, char* buffer) { + return (sizeof(i) == 4 ? + FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); +} +inline char* FastLongToBuffer(long i, char* buffer) { + return (sizeof(i) == 4 ? + FastInt32ToBuffer(i, buffer) : FastInt64ToBuffer(i, buffer)); +} +inline char* FastULongToBuffer(unsigned long i, char* buffer) { + return (sizeof(i) == 4 ? + FastUInt32ToBuffer(i, buffer) : FastUInt64ToBuffer(i, buffer)); +} + +// ---------------------------------------------------------------------- +// FastInt32ToBufferLeft() +// FastUInt32ToBufferLeft() +// FastInt64ToBufferLeft() +// FastUInt64ToBufferLeft() +// +// Like the Fast*ToBuffer() functions above, these are intended for speed. +// Unlike the Fast*ToBuffer() functions, however, these functions write +// their output to the beginning of the buffer (hence the name, as the +// output is left-aligned). The caller is responsible for ensuring that +// the buffer has enough space to hold the output. +// +// Returns a pointer to the end of the string (i.e. the null character +// terminating the string). +// ---------------------------------------------------------------------- + +PROTOBUF_EXPORT char* FastInt32ToBufferLeft(int32_t i, char* buffer); +PROTOBUF_EXPORT char* FastUInt32ToBufferLeft(uint32_t i, char* buffer); +PROTOBUF_EXPORT char* FastInt64ToBufferLeft(int64_t i, char* buffer); +PROTOBUF_EXPORT char* FastUInt64ToBufferLeft(uint64_t i, char* buffer); + +// Just define these in terms of the above. +inline char* FastUInt32ToBuffer(uint32_t i, char* buffer) { + FastUInt32ToBufferLeft(i, buffer); + return buffer; +} +inline char* FastUInt64ToBuffer(uint64_t i, char* buffer) { + FastUInt64ToBufferLeft(i, buffer); + return buffer; +} + +inline std::string SimpleBtoa(bool value) { return value ? "true" : "false"; } + +// ---------------------------------------------------------------------- +// SimpleItoa() +// Description: converts an integer to a string. +// +// Return value: string +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT std::string SimpleItoa(int i); +PROTOBUF_EXPORT std::string SimpleItoa(unsigned int i); +PROTOBUF_EXPORT std::string SimpleItoa(long i); +PROTOBUF_EXPORT std::string SimpleItoa(unsigned long i); +PROTOBUF_EXPORT std::string SimpleItoa(long long i); +PROTOBUF_EXPORT std::string SimpleItoa(unsigned long long i); + // ---------------------------------------------------------------------- // SimpleDtoa() // SimpleFtoa() +// DoubleToBuffer() +// FloatToBuffer() // Description: converts a double or float to a string which, if // passed to NoLocaleStrtod(), will produce the exact same original double // (except in case of NaN; all NaNs are considered the same value). // We try to keep the string short but it's not guaranteed to be as // short as possible. // +// DoubleToBuffer() and FloatToBuffer() write the text to the given +// buffer and return it. The buffer must be at least +// kDoubleToBufferSize bytes for doubles and kFloatToBufferSize +// bytes for floats. kFastToBufferSize is also guaranteed to be large +// enough to hold either. +// // Return value: string // ---------------------------------------------------------------------- PROTOBUF_EXPORT std::string SimpleDtoa(double value); PROTOBUF_EXPORT std::string SimpleFtoa(float value); +PROTOBUF_EXPORT char* DoubleToBuffer(double i, char* buffer); +PROTOBUF_EXPORT char* FloatToBuffer(float i, char* buffer); + +// In practice, doubles should never need more than 24 bytes and floats +// should never need more than 14 (including null terminators), but we +// overestimate to be safe. +static const int kDoubleToBufferSize = 32; +static const int kFloatToBufferSize = 24; + namespace strings { -using Hex = absl::Hex; +enum PadSpec { + NO_PAD = 1, + ZERO_PAD_2, + ZERO_PAD_3, + ZERO_PAD_4, + ZERO_PAD_5, + ZERO_PAD_6, + ZERO_PAD_7, + ZERO_PAD_8, + ZERO_PAD_9, + ZERO_PAD_10, + ZERO_PAD_11, + ZERO_PAD_12, + ZERO_PAD_13, + ZERO_PAD_14, + ZERO_PAD_15, + ZERO_PAD_16, +}; + +struct Hex { + uint64_t value; + enum PadSpec spec; + template + explicit Hex(Int v, PadSpec s = NO_PAD) + : spec(s) { + // Prevent sign-extension by casting integers to + // their unsigned counterparts. +#ifdef LANG_CXX11 + static_assert( + sizeof(v) == 1 || sizeof(v) == 2 || sizeof(v) == 4 || sizeof(v) == 8, + "Unknown integer type"); +#endif + value = sizeof(v) == 1 ? static_cast(v) + : sizeof(v) == 2 ? static_cast(v) + : sizeof(v) == 4 ? static_cast(v) + : static_cast(v); + } +}; + +struct PROTOBUF_EXPORT AlphaNum { + const char *piece_data_; // move these to string_ref eventually + size_t piece_size_; // move these to string_ref eventually + + char digits[kFastToBufferSize]; + + // No bool ctor -- bools convert to an integral type. + // A bool ctor would also convert incoming pointers (bletch). + + AlphaNum(int i32) + : piece_data_(digits), + piece_size_(FastInt32ToBufferLeft(i32, digits) - &digits[0]) {} + AlphaNum(unsigned int u32) + : piece_data_(digits), + piece_size_(FastUInt32ToBufferLeft(u32, digits) - &digits[0]) {} + AlphaNum(long long i64) + : piece_data_(digits), + piece_size_(FastInt64ToBufferLeft(i64, digits) - &digits[0]) {} + AlphaNum(unsigned long long u64) + : piece_data_(digits), + piece_size_(FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {} + + // Note: on some architectures, "long" is only 32 bits, not 64, but the + // performance hit of using FastInt64ToBufferLeft to handle 32-bit values + // is quite minor. + AlphaNum(long i64) + : piece_data_(digits), + piece_size_(FastInt64ToBufferLeft(i64, digits) - &digits[0]) {} + AlphaNum(unsigned long u64) + : piece_data_(digits), + piece_size_(FastUInt64ToBufferLeft(u64, digits) - &digits[0]) {} + + AlphaNum(float f) + : piece_data_(digits), piece_size_(strlen(FloatToBuffer(f, digits))) {} + AlphaNum(double f) + : piece_data_(digits), piece_size_(strlen(DoubleToBuffer(f, digits))) {} + + AlphaNum(Hex hex); + + AlphaNum(const char* c_str) + : piece_data_(c_str), piece_size_(strlen(c_str)) {} + // TODO: Add a string_ref constructor, eventually + // AlphaNum(const StringPiece &pc) : piece(pc) {} + + AlphaNum(const std::string& str) + : piece_data_(str.data()), piece_size_(str.size()) {} + + AlphaNum(StringPiece str) + : piece_data_(str.data()), piece_size_(str.size()) {} + + size_t size() const { return piece_size_; } + const char *data() const { return piece_data_; } + + private: + // Use ":" not ':' + AlphaNum(char c); // NOLINT(runtime/explicit) + + // Disallow copy and assign. + AlphaNum(const AlphaNum&); + void operator=(const AlphaNum&); +}; } // namespace strings +using strings::AlphaNum; + +// ---------------------------------------------------------------------- +// StrCat() +// This merges the given strings or numbers, with no delimiter. This +// is designed to be the fastest possible way to construct a string out +// of a mix of raw C strings, strings, bool values, +// and numeric values. +// +// Don't use this for user-visible strings. The localization process +// works poorly on strings built up out of fragments. +// +// For clarity and performance, don't use StrCat when appending to a +// string. In particular, avoid using any of these (anti-)patterns: +// str.append(StrCat(...) +// str += StrCat(...) +// str = StrCat(str, ...) +// where the last is the worse, with the potential to change a loop +// from a linear time operation with O(1) dynamic allocations into a +// quadratic time operation with O(n) dynamic allocations. StrAppend +// is a better choice than any of the above, subject to the restriction +// of StrAppend(&str, a, b, c, ...) that none of the a, b, c, ... may +// be a reference into str. +// ---------------------------------------------------------------------- + +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h); +PROTOBUF_EXPORT std::string StrCat(const AlphaNum& a, const AlphaNum& b, + const AlphaNum& c, const AlphaNum& d, + const AlphaNum& e, const AlphaNum& f, + const AlphaNum& g, const AlphaNum& h, + const AlphaNum& i); + +inline std::string StrCat(const AlphaNum& a) { + return std::string(a.data(), a.size()); +} + +// ---------------------------------------------------------------------- +// StrAppend() +// Same as above, but adds the output to the given string. +// WARNING: For speed, StrAppend does not try to check each of its input +// arguments to be sure that they are not a subset of the string being +// appended to. That is, while this will work: +// +// string s = "foo"; +// s += s; +// +// This will not (necessarily) work: +// +// string s = "foo"; +// StrAppend(&s, s); +// +// Note: while StrCat supports appending up to 9 arguments, StrAppend +// is currently limited to 4. That's rarely an issue except when +// automatically transforming StrCat to StrAppend, and can easily be +// worked around as consecutive calls to StrAppend are quite efficient. +// ---------------------------------------------------------------------- + +PROTOBUF_EXPORT void StrAppend(std::string* dest, const AlphaNum& a); +PROTOBUF_EXPORT void StrAppend(std::string* dest, const AlphaNum& a, + const AlphaNum& b); +PROTOBUF_EXPORT void StrAppend(std::string* dest, const AlphaNum& a, + const AlphaNum& b, const AlphaNum& c); +PROTOBUF_EXPORT void StrAppend(std::string* dest, const AlphaNum& a, + const AlphaNum& b, const AlphaNum& c, + const AlphaNum& d); + +// ---------------------------------------------------------------------- +// Join() +// These methods concatenate a range of components into a C++ string, using +// the C-string "delim" as a separator between components. +// ---------------------------------------------------------------------- +template +void Join(Iterator start, Iterator end, const char* delim, + std::string* result) { + for (Iterator it = start; it != end; ++it) { + if (it != start) { + result->append(delim); + } + StrAppend(result, *it); + } +} + +template +std::string Join(const Range& components, const char* delim) { + std::string result; + Join(components.begin(), components.end(), delim, &result); + return result; +} + // ---------------------------------------------------------------------- // ToHex() // Return a lower-case hex string representation of the given integer. // ---------------------------------------------------------------------- PROTOBUF_EXPORT std::string ToHex(uint64_t num); -namespace strings { +// ---------------------------------------------------------------------- +// GlobalReplaceSubstring() +// Replaces all instances of a substring in a string. Does nothing +// if 'substring' is empty. Returns the number of replacements. +// +// NOTE: The string pieces must not overlap s. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT int GlobalReplaceSubstring(const std::string& substring, + const std::string& replacement, + std::string* s); + +// ---------------------------------------------------------------------- +// Base64Unescape() +// Converts "src" which is encoded in Base64 to its binary equivalent and +// writes it to "dest". If src contains invalid characters, dest is cleared +// and the function returns false. Returns true on success. +// ---------------------------------------------------------------------- +PROTOBUF_EXPORT bool Base64Unescape(StringPiece src, std::string* dest); + +// ---------------------------------------------------------------------- +// WebSafeBase64Unescape() +// This is a variation of Base64Unescape which uses '-' instead of '+', and +// '_' instead of '/'. src is not null terminated, instead specify len. I +// recommend that slen #endif // GOOGLE_PROTOBUF_STUBS_STRUTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/stubs/strutil_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/strutil_unittest.cc index ea15b1d..0bb9558 100644 --- a/libs/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +++ b/libs/protobuf/src/google/protobuf/stubs/strutil_unittest.cc @@ -30,12 +30,13 @@ // Author: kenton@google.com (Kenton Varda) -#include "google/protobuf/stubs/strutil.h" +#include -#include #include -#include "google/protobuf/testing/googletest.h" +#include +#include +#include #ifdef _WIN32 #define snprintf _snprintf @@ -73,6 +74,811 @@ TEST(StringUtilityTest, ImmuneToLocales) { setlocale(LC_NUMERIC, old_locale.c_str()); } +#define EXPECT_EQ_ARRAY(len, x, y, msg) \ + for (int j = 0; j < len; ++j) { \ + EXPECT_EQ(x[j], y[j]) << "" # x << " != " # y \ + << " byte " << j << ": " << msg; \ + } + +static struct { + int plain_length; + const char* plaintext; + const char* ciphertext; +} base64_tests[] = { + // Empty string. + { 0, "", ""}, + + // Basic bit patterns; + // values obtained with "echo -n '...' | uuencode -m test" + + { 1, "\000", "AA==" }, + { 1, "\001", "AQ==" }, + { 1, "\002", "Ag==" }, + { 1, "\004", "BA==" }, + { 1, "\010", "CA==" }, + { 1, "\020", "EA==" }, + { 1, "\040", "IA==" }, + { 1, "\100", "QA==" }, + { 1, "\200", "gA==" }, + + { 1, "\377", "/w==" }, + { 1, "\376", "/g==" }, + { 1, "\375", "/Q==" }, + { 1, "\373", "+w==" }, + { 1, "\367", "9w==" }, + { 1, "\357", "7w==" }, + { 1, "\337", "3w==" }, + { 1, "\277", "vw==" }, + { 1, "\177", "fw==" }, + { 2, "\000\000", "AAA=" }, + { 2, "\000\001", "AAE=" }, + { 2, "\000\002", "AAI=" }, + { 2, "\000\004", "AAQ=" }, + { 2, "\000\010", "AAg=" }, + { 2, "\000\020", "ABA=" }, + { 2, "\000\040", "ACA=" }, + { 2, "\000\100", "AEA=" }, + { 2, "\000\200", "AIA=" }, + { 2, "\001\000", "AQA=" }, + { 2, "\002\000", "AgA=" }, + { 2, "\004\000", "BAA=" }, + { 2, "\010\000", "CAA=" }, + { 2, "\020\000", "EAA=" }, + { 2, "\040\000", "IAA=" }, + { 2, "\100\000", "QAA=" }, + { 2, "\200\000", "gAA=" }, + + { 2, "\377\377", "//8=" }, + { 2, "\377\376", "//4=" }, + { 2, "\377\375", "//0=" }, + { 2, "\377\373", "//s=" }, + { 2, "\377\367", "//c=" }, + { 2, "\377\357", "/+8=" }, + { 2, "\377\337", "/98=" }, + { 2, "\377\277", "/78=" }, + { 2, "\377\177", "/38=" }, + { 2, "\376\377", "/v8=" }, + { 2, "\375\377", "/f8=" }, + { 2, "\373\377", "+/8=" }, + { 2, "\367\377", "9/8=" }, + { 2, "\357\377", "7/8=" }, + { 2, "\337\377", "3/8=" }, + { 2, "\277\377", "v/8=" }, + { 2, "\177\377", "f/8=" }, + + { 3, "\000\000\000", "AAAA" }, + { 3, "\000\000\001", "AAAB" }, + { 3, "\000\000\002", "AAAC" }, + { 3, "\000\000\004", "AAAE" }, + { 3, "\000\000\010", "AAAI" }, + { 3, "\000\000\020", "AAAQ" }, + { 3, "\000\000\040", "AAAg" }, + { 3, "\000\000\100", "AABA" }, + { 3, "\000\000\200", "AACA" }, + { 3, "\000\001\000", "AAEA" }, + { 3, "\000\002\000", "AAIA" }, + { 3, "\000\004\000", "AAQA" }, + { 3, "\000\010\000", "AAgA" }, + { 3, "\000\020\000", "ABAA" }, + { 3, "\000\040\000", "ACAA" }, + { 3, "\000\100\000", "AEAA" }, + { 3, "\000\200\000", "AIAA" }, + { 3, "\001\000\000", "AQAA" }, + { 3, "\002\000\000", "AgAA" }, + { 3, "\004\000\000", "BAAA" }, + { 3, "\010\000\000", "CAAA" }, + { 3, "\020\000\000", "EAAA" }, + { 3, "\040\000\000", "IAAA" }, + { 3, "\100\000\000", "QAAA" }, + { 3, "\200\000\000", "gAAA" }, + + { 3, "\377\377\377", "////" }, + { 3, "\377\377\376", "///+" }, + { 3, "\377\377\375", "///9" }, + { 3, "\377\377\373", "///7" }, + { 3, "\377\377\367", "///3" }, + { 3, "\377\377\357", "///v" }, + { 3, "\377\377\337", "///f" }, + { 3, "\377\377\277", "//+/" }, + { 3, "\377\377\177", "//9/" }, + { 3, "\377\376\377", "//7/" }, + { 3, "\377\375\377", "//3/" }, + { 3, "\377\373\377", "//v/" }, + { 3, "\377\367\377", "//f/" }, + { 3, "\377\357\377", "/+//" }, + { 3, "\377\337\377", "/9//" }, + { 3, "\377\277\377", "/7//" }, + { 3, "\377\177\377", "/3//" }, + { 3, "\376\377\377", "/v//" }, + { 3, "\375\377\377", "/f//" }, + { 3, "\373\377\377", "+///" }, + { 3, "\367\377\377", "9///" }, + { 3, "\357\377\377", "7///" }, + { 3, "\337\377\377", "3///" }, + { 3, "\277\377\377", "v///" }, + { 3, "\177\377\377", "f///" }, + + // Random numbers: values obtained with + // + // #! /bin/bash + // dd bs=$1 count=1 if=/dev/random of=/tmp/bar.random + // od -N $1 -t o1 /tmp/bar.random + // uuencode -m test < /tmp/bar.random + // + // where $1 is the number of bytes (2, 3) + + { 2, "\243\361", "o/E=" }, + { 2, "\024\167", "FHc=" }, + { 2, "\313\252", "y6o=" }, + { 2, "\046\041", "JiE=" }, + { 2, "\145\236", "ZZ4=" }, + { 2, "\254\325", "rNU=" }, + { 2, "\061\330", "Mdg=" }, + { 2, "\245\032", "pRo=" }, + { 2, "\006\000", "BgA=" }, + { 2, "\375\131", "/Vk=" }, + { 2, "\303\210", "w4g=" }, + { 2, "\040\037", "IB8=" }, + { 2, "\261\372", "sfo=" }, + { 2, "\335\014", "3Qw=" }, + { 2, "\233\217", "m48=" }, + { 2, "\373\056", "+y4=" }, + { 2, "\247\232", "p5o=" }, + { 2, "\107\053", "Rys=" }, + { 2, "\204\077", "hD8=" }, + { 2, "\276\211", "vok=" }, + { 2, "\313\110", "y0g=" }, + { 2, "\363\376", "8/4=" }, + { 2, "\251\234", "qZw=" }, + { 2, "\103\262", "Q7I=" }, + { 2, "\142\312", "Yso=" }, + { 2, "\067\211", "N4k=" }, + { 2, "\220\001", "kAE=" }, + { 2, "\152\240", "aqA=" }, + { 2, "\367\061", "9zE=" }, + { 2, "\133\255", "W60=" }, + { 2, "\176\035", "fh0=" }, + { 2, "\032\231", "Gpk=" }, + + { 3, "\013\007\144", "Cwdk" }, + { 3, "\030\112\106", "GEpG" }, + { 3, "\047\325\046", "J9Um" }, + { 3, "\310\160\022", "yHAS" }, + { 3, "\131\100\237", "WUCf" }, + { 3, "\064\342\134", "NOJc" }, + { 3, "\010\177\004", "CH8E" }, + { 3, "\345\147\205", "5WeF" }, + { 3, "\300\343\360", "wOPw" }, + { 3, "\061\240\201", "MaCB" }, + { 3, "\225\333\044", "ldsk" }, + { 3, "\215\137\352", "jV/q" }, + { 3, "\371\147\160", "+Wdw" }, + { 3, "\030\320\051", "GNAp" }, + { 3, "\044\174\241", "JHyh" }, + { 3, "\260\127\037", "sFcf" }, + { 3, "\111\045\033", "SSUb" }, + { 3, "\202\114\107", "gkxH" }, + { 3, "\057\371\042", "L/ki" }, + { 3, "\223\247\244", "k6ek" }, + { 3, "\047\216\144", "J45k" }, + { 3, "\203\070\327", "gzjX" }, + { 3, "\247\140\072", "p2A6" }, + { 3, "\124\115\116", "VE1O" }, + { 3, "\157\162\050", "b3Io" }, + { 3, "\357\223\004", "75ME" }, + { 3, "\052\117\156", "Kk9u" }, + { 3, "\347\154\000", "52wA" }, + { 3, "\303\012\142", "wwpi" }, + { 3, "\060\035\362", "MB3y" }, + { 3, "\130\226\361", "WJbx" }, + { 3, "\173\013\071", "ews5" }, + { 3, "\336\004\027", "3gQX" }, + { 3, "\357\366\234", "7/ac" }, + { 3, "\353\304\111", "68RJ" }, + { 3, "\024\264\131", "FLRZ" }, + { 3, "\075\114\251", "PUyp" }, + { 3, "\315\031\225", "zRmV" }, + { 3, "\154\201\276", "bIG+" }, + { 3, "\200\066\072", "gDY6" }, + { 3, "\142\350\267", "Yui3" }, + { 3, "\033\000\166", "GwB2" }, + { 3, "\210\055\077", "iC0/" }, + { 3, "\341\037\124", "4R9U" }, + { 3, "\161\103\152", "cUNq" }, + { 3, "\270\142\131", "uGJZ" }, + { 3, "\337\076\074", "3z48" }, + { 3, "\375\106\362", "/Uby" }, + { 3, "\227\301\127", "l8FX" }, + { 3, "\340\002\234", "4AKc" }, + { 3, "\121\064\033", "UTQb" }, + { 3, "\157\134\143", "b1xj" }, + { 3, "\247\055\327", "py3X" }, + { 3, "\340\142\005", "4GIF" }, + { 3, "\060\260\143", "MLBj" }, + { 3, "\075\203\170", "PYN4" }, + { 3, "\143\160\016", "Y3AO" }, + { 3, "\313\013\063", "ywsz" }, + { 3, "\174\236\135", "fJ5d" }, + { 3, "\103\047\026", "QycW" }, + { 3, "\365\005\343", "9QXj" }, + { 3, "\271\160\223", "uXCT" }, + { 3, "\362\255\172", "8q16" }, + { 3, "\113\012\015", "SwoN" }, + + // various lengths, generated by this python script: + // + // from string import lowercase as lc + // for i in range(27): + // print '{ %2d, "%s",%s "%s" },' % (i, lc[:i], ' ' * (26-i), + // lc[:i].encode('base64').strip()) + + { 0, "", "" }, + { 1, "a", "YQ==" }, + { 2, "ab", "YWI=" }, + { 3, "abc", "YWJj" }, + { 4, "abcd", "YWJjZA==" }, + { 5, "abcde", "YWJjZGU=" }, + { 6, "abcdef", "YWJjZGVm" }, + { 7, "abcdefg", "YWJjZGVmZw==" }, + { 8, "abcdefgh", "YWJjZGVmZ2g=" }, + { 9, "abcdefghi", "YWJjZGVmZ2hp" }, + { 10, "abcdefghij", "YWJjZGVmZ2hpag==" }, + { 11, "abcdefghijk", "YWJjZGVmZ2hpams=" }, + { 12, "abcdefghijkl", "YWJjZGVmZ2hpamts" }, + { 13, "abcdefghijklm", "YWJjZGVmZ2hpamtsbQ==" }, + { 14, "abcdefghijklmn", "YWJjZGVmZ2hpamtsbW4=" }, + { 15, "abcdefghijklmno", "YWJjZGVmZ2hpamtsbW5v" }, + { 16, "abcdefghijklmnop", "YWJjZGVmZ2hpamtsbW5vcA==" }, + { 17, "abcdefghijklmnopq", "YWJjZGVmZ2hpamtsbW5vcHE=" }, + { 18, "abcdefghijklmnopqr", "YWJjZGVmZ2hpamtsbW5vcHFy" }, + { 19, "abcdefghijklmnopqrs", "YWJjZGVmZ2hpamtsbW5vcHFycw==" }, + { 20, "abcdefghijklmnopqrst", "YWJjZGVmZ2hpamtsbW5vcHFyc3Q=" }, + { 21, "abcdefghijklmnopqrstu", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1" }, + { 22, "abcdefghijklmnopqrstuv", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dg==" }, + { 23, "abcdefghijklmnopqrstuvw", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnc=" }, + { 24, "abcdefghijklmnopqrstuvwx", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4" }, + { 25, "abcdefghijklmnopqrstuvwxy", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eQ==" }, + { 26, "abcdefghijklmnopqrstuvwxyz", "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo=" }, +}; + +static struct { + const char* plaintext; + const char* ciphertext; +} base64_strings[] = { + // Some google quotes + // Ciphertext created with "uuencode (GNU sharutils) 4.6.3" + // (Note that we're testing the websafe encoding, though, so if + // you add messages, be sure to run "tr -- '+/' '-_'" on the output) + {"I was always good at math and science, and I never realized " + "that was unusual or somehow undesirable. So one of the things " + "I care a lot about is helping to remove that stigma, " + "to show girls that you can be feminine, you can like the things " + "that girls like, but you can also be really good at technology. " + "You can be really good at building things." + " - Marissa Meyer, Newsweek, 2010-12-22" + "\n", + + "SSB3YXMgYWx3YXlzIGdvb2QgYXQgbWF0aCBhbmQgc2NpZW5jZSwgYW5kIEkg" + "bmV2ZXIgcmVhbGl6ZWQgdGhhdCB3YXMgdW51c3VhbCBvciBzb21laG93IHVu" + "ZGVzaXJhYmxlLiBTbyBvbmUgb2YgdGhlIHRoaW5ncyBJIGNhcmUgYSBsb3Qg" + "YWJvdXQgaXMgaGVscGluZyB0byByZW1vdmUgdGhhdCBzdGlnbWEsIHRvIHNo" + "b3cgZ2lybHMgdGhhdCB5b3UgY2FuIGJlIGZlbWluaW5lLCB5b3UgY2FuIGxp" + "a2UgdGhlIHRoaW5ncyB0aGF0IGdpcmxzIGxpa2UsIGJ1dCB5b3UgY2FuIGFs" + "c28gYmUgcmVhbGx5IGdvb2QgYXQgdGVjaG5vbG9neS4gWW91IGNhbiBiZSBy" + "ZWFsbHkgZ29vZCBhdCBidWlsZGluZyB0aGluZ3MuIC0gTWFyaXNzYSBNZXll" + "ciwgTmV3c3dlZWssIDIwMTAtMTItMjIK"}, + + {"Typical first year for a new cluster: " + "~0.5 overheating " + "~1 PDU failure " + "~1 rack-move " + "~1 network rewiring " + "~20 rack failures " + "~5 racks go wonky " + "~8 network maintenances " + "~12 router reloads " + "~3 router failures " + "~dozens of minor 30-second blips for dns " + "~1000 individual machine failures " + "~thousands of hard drive failures " + "slow disks, bad memory, misconfigured machines, flaky machines, etc." + " - Jeff Dean, The Joys of Real Hardware" + "\n", + + "VHlwaWNhbCBmaXJzdCB5ZWFyIGZvciBhIG5ldyBjbHVzdGVyOiB-MC41IG92" + "ZXJoZWF0aW5nIH4xIFBEVSBmYWlsdXJlIH4xIHJhY2stbW92ZSB-MSBuZXR3" + "b3JrIHJld2lyaW5nIH4yMCByYWNrIGZhaWx1cmVzIH41IHJhY2tzIGdvIHdv" + "bmt5IH44IG5ldHdvcmsgbWFpbnRlbmFuY2VzIH4xMiByb3V0ZXIgcmVsb2Fk" + "cyB-MyByb3V0ZXIgZmFpbHVyZXMgfmRvemVucyBvZiBtaW5vciAzMC1zZWNv" + "bmQgYmxpcHMgZm9yIGRucyB-MTAwMCBpbmRpdmlkdWFsIG1hY2hpbmUgZmFp" + "bHVyZXMgfnRob3VzYW5kcyBvZiBoYXJkIGRyaXZlIGZhaWx1cmVzIHNsb3cg" + "ZGlza3MsIGJhZCBtZW1vcnksIG1pc2NvbmZpZ3VyZWQgbWFjaGluZXMsIGZs" + "YWt5IG1hY2hpbmVzLCBldGMuIC0gSmVmZiBEZWFuLCBUaGUgSm95cyBvZiBS" + "ZWFsIEhhcmR3YXJlCg"}, + + {"I'm the head of the webspam team at Google. " + "That means that if you type your name into Google and get porn back, " + "it's my fault. Unless you're a porn star, in which case porn is a " + "completely reasonable response." + " - Matt Cutts, Google Plus" + "\n", + + "SSdtIHRoZSBoZWFkIG9mIHRoZSB3ZWJzcGFtIHRlYW0gYXQgR29vZ2xlLiAg" + "VGhhdCBtZWFucyB0aGF0IGlmIHlvdSB0eXBlIHlvdXIgbmFtZSBpbnRvIEdv" + "b2dsZSBhbmQgZ2V0IHBvcm4gYmFjaywgaXQncyBteSBmYXVsdC4gVW5sZXNz" + "IHlvdSdyZSBhIHBvcm4gc3RhciwgaW4gd2hpY2ggY2FzZSBwb3JuIGlzIGEg" + "Y29tcGxldGVseSByZWFzb25hYmxlIHJlc3BvbnNlLiAtIE1hdHQgQ3V0dHMs" + "IEdvb2dsZSBQbHVzCg"}, + + {"It will still be a long time before machines approach human " + "intelligence. " + "But luckily, machines don't actually have to be intelligent; " + "they just have to fake it. Access to a wealth of information, " + "combined with a rudimentary decision-making capacity, " + "can often be almost as useful. Of course, the results are better yet " + "when coupled with intelligence. A reference librarian with access to " + "a good search engine is a formidable tool." + " - Craig Silverstein, Siemens Pictures of the Future, Spring 2004" + "\n", + + "SXQgd2lsbCBzdGlsbCBiZSBhIGxvbmcgdGltZSBiZWZvcmUgbWFjaGluZXMg" + "YXBwcm9hY2ggaHVtYW4gaW50ZWxsaWdlbmNlLiBCdXQgbHVja2lseSwgbWFj" + "aGluZXMgZG9uJ3QgYWN0dWFsbHkgaGF2ZSB0byBiZSBpbnRlbGxpZ2VudDsg" + "dGhleSBqdXN0IGhhdmUgdG8gZmFrZSBpdC4gQWNjZXNzIHRvIGEgd2VhbHRo" + "IG9mIGluZm9ybWF0aW9uLCBjb21iaW5lZCB3aXRoIGEgcnVkaW1lbnRhcnkg" + "ZGVjaXNpb24tbWFraW5nIGNhcGFjaXR5LCBjYW4gb2Z0ZW4gYmUgYWxtb3N0" + "IGFzIHVzZWZ1bC4gT2YgY291cnNlLCB0aGUgcmVzdWx0cyBhcmUgYmV0dGVy" + "IHlldCB3aGVuIGNvdXBsZWQgd2l0aCBpbnRlbGxpZ2VuY2UuIEEgcmVmZXJl" + "bmNlIGxpYnJhcmlhbiB3aXRoIGFjY2VzcyB0byBhIGdvb2Qgc2VhcmNoIGVu" + "Z2luZSBpcyBhIGZvcm1pZGFibGUgdG9vbC4gLSBDcmFpZyBTaWx2ZXJzdGVp" + "biwgU2llbWVucyBQaWN0dXJlcyBvZiB0aGUgRnV0dXJlLCBTcHJpbmcgMjAw" + "NAo"}, + + // Degenerate edge case + {"", ""}, +}; + +TEST(Base64, EscapeAndUnescape) { + // Check the short strings; this tests the math (and boundaries) + for (int i = 0; i < sizeof(base64_tests) / sizeof(base64_tests[0]); ++i) { + char encode_buffer[100]; + int encode_length; + char decode_buffer[100]; + int decode_length; + int cipher_length; + std::string decode_str; + + const unsigned char* unsigned_plaintext = + reinterpret_cast(base64_tests[i].plaintext); + + StringPiece plaintext(base64_tests[i].plaintext, + base64_tests[i].plain_length); + + cipher_length = strlen(base64_tests[i].ciphertext); + + // The basic escape function: + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = Base64Escape(unsigned_plaintext, + base64_tests[i].plain_length, + encode_buffer, + sizeof(encode_buffer)); + // Is it of the expected length? + EXPECT_EQ(encode_length, cipher_length); + // Would it have been okay to allocate only CalculateBase64EscapeLen()? + EXPECT_EQ(CalculateBase64EscapedLen(base64_tests[i].plain_length), + encode_length); + + // Is it the expected encoded value? + ASSERT_STREQ(encode_buffer, base64_tests[i].ciphertext); + + // If we encode it into a buffer of exactly the right length... + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = + Base64Escape(unsigned_plaintext, base64_tests[i].plain_length, + encode_buffer, cipher_length); + // Is it still of the expected length? + EXPECT_EQ(encode_length, cipher_length); + + // And is the value still correct? (i.e., not losing the last byte) + EXPECT_STREQ(encode_buffer, base64_tests[i].ciphertext); + + // If we decode it back: + decode_str.clear(); + EXPECT_TRUE( + Base64Unescape(StringPiece(encode_buffer, cipher_length), &decode_str)); + + // Is it of the expected length? + EXPECT_EQ(base64_tests[i].plain_length, decode_str.length()); + + // Is it the expected decoded value? + EXPECT_EQ(plaintext, decode_str); + + // Let's try with a pre-populated string. + std::string encoded("this junk should be ignored"); + Base64Escape( + std::string(base64_tests[i].plaintext, base64_tests[i].plain_length), + &encoded); + EXPECT_EQ(encoded, std::string(encode_buffer, cipher_length)); + + std::string decoded("this junk should be ignored"); + EXPECT_TRUE( + Base64Unescape(StringPiece(encode_buffer, cipher_length), &decoded)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // Our decoder treats the padding '=' characters at the end as + // optional (but if there are any, there must be the correct + // number of them.) If encode_buffer has any, run some additional + // tests that fiddle with them. + char* first_equals = strchr(encode_buffer, '='); + if (first_equals) { + // How many equals signs does the string start with? + int equals = (*(first_equals+1) == '=') ? 2 : 1; + + // Try chopping off the equals sign(s) entirely. The decoder + // should still be okay with this. + std::string decoded2("this junk should also be ignored"); + *first_equals = '\0'; + EXPECT_TRUE(Base64Unescape( + StringPiece(encode_buffer, first_equals - encode_buffer), &decoded2)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // Now test chopping off the equals sign(s) and adding + // whitespace. Our decoder should still accept this. + decoded2.assign("this junk should be ignored"); + *first_equals = ' '; + *(first_equals+1) = '\0'; + EXPECT_TRUE(Base64Unescape( + StringPiece(encode_buffer, first_equals - encode_buffer + 1), + &decoded2)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // Now stick a bad character at the end of the string. The decoder + // should refuse this string. + decoded2.assign("this junk should be ignored"); + *first_equals = '?'; + *(first_equals+1) = '\0'; + EXPECT_TRUE( + !Base64Unescape( + StringPiece(encode_buffer, first_equals - encode_buffer + 1), + &decoded2)); + + int len; + + // Test whitespace mixed with the padding. (eg "AA = = ") The + // decoder should accept this. + if (equals == 2) { + snprintf(first_equals, 6, " = = "); + len = first_equals - encode_buffer + 5; + } else { + snprintf(first_equals, 6, " = "); + len = first_equals - encode_buffer + 3; + } + decoded2.assign("this junk should be ignored"); + EXPECT_TRUE( + Base64Unescape(StringPiece(encode_buffer, len), &decoded2)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // Test whitespace mixed with the padding, but with the wrong + // number of equals signs (eg "AA = "). The decoder should + // refuse these strings. + if (equals == 1) { + snprintf(first_equals, 6, " = = "); + len = first_equals - encode_buffer + 5; + } else { + snprintf(first_equals, 6, " = "); + len = first_equals - encode_buffer + 3; + } + EXPECT_TRUE( + !Base64Unescape(StringPiece(encode_buffer, len), &decoded2)); + } + + // Cool! the basic Base64 encoder/decoder works. + // Let's try the alternate alphabet: tr -- '+/' '-_' + + char websafe[100]; + memset(websafe, 0, sizeof(websafe)); + strncpy(websafe, base64_tests[i].ciphertext, cipher_length); + for (int c = 0; c < sizeof(websafe); ++c) { + if ('+' == websafe[c]) { websafe[c] = '-'; } + if ('/' == websafe[c]) { websafe[c] = '_'; } + } + + // The websafe escape function: + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = WebSafeBase64Escape(unsigned_plaintext, + base64_tests[i].plain_length, + encode_buffer, + sizeof(encode_buffer), + true); + // Is it of the expected length? + EXPECT_EQ(encode_length, cipher_length); + EXPECT_EQ( + CalculateBase64EscapedLen(base64_tests[i].plain_length, true), + encode_length); + + // Is it the expected encoded value? + EXPECT_STREQ(encode_buffer, websafe); + + // If we encode it into a buffer of exactly the right length... + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = + WebSafeBase64Escape(unsigned_plaintext, base64_tests[i].plain_length, + encode_buffer, cipher_length, true); + // Is it still of the expected length? + EXPECT_EQ(encode_length, cipher_length); + + // And is the value still correct? (i.e., not losing the last byte) + EXPECT_STREQ(encode_buffer, websafe); + + // Let's try the string version of the encoder + encoded = "this junk should be ignored"; + WebSafeBase64Escape( + unsigned_plaintext, base64_tests[i].plain_length, + &encoded, true); + EXPECT_EQ(encoded.size(), cipher_length); + EXPECT_STREQ(encoded.c_str(), websafe); + + // If we decode it back: + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, sizeof(decode_buffer)); + + // Is it of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // Is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + // If we decode it into a buffer of exactly the right length... + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, decode_length); + + // Is it still of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // And is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + // Try using '.' for the pad character. + for (int c = cipher_length - 1; c >= 0 && '=' == encode_buffer[c]; --c) { + encode_buffer[c] = '.'; + } + + // If we decode it back: + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, sizeof(decode_buffer)); + + // Is it of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // Is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + // If we decode it into a buffer of exactly the right length... + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, decode_length); + + // Is it still of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // And is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + // Let's try the string version of the decoder + decoded = "this junk should be ignored"; + EXPECT_TRUE(WebSafeBase64Unescape(StringPiece(encode_buffer, cipher_length), + &decoded)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // Okay! the websafe Base64 encoder/decoder works. + // Let's try the unpadded version + + for (int c = 0; c < sizeof(websafe); ++c) { + if ('=' == websafe[c]) { + websafe[c] = '\0'; + cipher_length = c; + break; + } + } + + // The websafe escape function: + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = WebSafeBase64Escape(unsigned_plaintext, + base64_tests[i].plain_length, + encode_buffer, + sizeof(encode_buffer), + false); + // Is it of the expected length? + EXPECT_EQ(encode_length, cipher_length); + EXPECT_EQ( + CalculateBase64EscapedLen(base64_tests[i].plain_length, false), + encode_length); + + // Is it the expected encoded value? + EXPECT_STREQ(encode_buffer, websafe); + + // If we encode it into a buffer of exactly the right length... + memset(encode_buffer, 0, sizeof(encode_buffer)); + encode_length = + WebSafeBase64Escape(unsigned_plaintext, base64_tests[i].plain_length, + encode_buffer, cipher_length, false); + // Is it still of the expected length? + EXPECT_EQ(encode_length, cipher_length); + + // And is the value still correct? (i.e., not losing the last byte) + EXPECT_STREQ(encode_buffer, websafe); + + // Let's try the (other) string version of the encoder + std::string plain(base64_tests[i].plaintext, base64_tests[i].plain_length); + encoded = "this junk should be ignored"; + WebSafeBase64Escape(plain, &encoded); + EXPECT_EQ(encoded.size(), cipher_length); + EXPECT_STREQ(encoded.c_str(), websafe); + + // If we decode it back: + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, sizeof(decode_buffer)); + + // Is it of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // Is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + // If we decode it into a buffer of exactly the right length... + memset(decode_buffer, 0, sizeof(decode_buffer)); + decode_length = WebSafeBase64Unescape(encode_buffer, cipher_length, + decode_buffer, decode_length); + + // Is it still of the expected length? + EXPECT_EQ(decode_length, base64_tests[i].plain_length); + + // And is it the expected decoded value? + EXPECT_EQ(0, + memcmp(decode_buffer, base64_tests[i].plaintext, decode_length)); + + + // Let's try the string version of the decoder + decoded = "this junk should be ignored"; + EXPECT_TRUE(WebSafeBase64Unescape(StringPiece(encode_buffer, cipher_length), + &decoded)); + EXPECT_EQ(decoded.size(), base64_tests[i].plain_length); + EXPECT_EQ_ARRAY(decoded.size(), decoded, base64_tests[i].plaintext, i); + + // This value works. Try the next. + } + + // Now try the long strings, this tests the streaming + for (int i = 0; i < sizeof(base64_strings) / sizeof(base64_strings[0]); + ++i) { + const unsigned char* unsigned_plaintext = + reinterpret_cast(base64_strings[i].plaintext); + int plain_length = strlen(base64_strings[i].plaintext); + int cipher_length = strlen(base64_strings[i].ciphertext); + std::vector buffer(cipher_length + 1); + int encode_length = WebSafeBase64Escape(unsigned_plaintext, + plain_length, + &buffer[0], + buffer.size(), + false); + EXPECT_EQ(cipher_length, encode_length); + EXPECT_EQ( + CalculateBase64EscapedLen(plain_length, false), encode_length); + buffer[ encode_length ] = '\0'; + EXPECT_STREQ(base64_strings[i].ciphertext, &buffer[0]); + } + + // Verify the behavior when decoding bad data + { + const char* bad_data = "ab-/"; + std::string buf; + EXPECT_FALSE(Base64Unescape(StringPiece(bad_data), &buf)); + EXPECT_TRUE(!WebSafeBase64Unescape(bad_data, &buf)); + EXPECT_TRUE(buf.empty()); + } +} + +// Test StrCat of ints and longs of various sizes and signdedness. +TEST(StrCat, Ints) { + const short s = -1; // NOLINT(runtime/int) + const uint16_t us = 2; + const int i = -3; + const unsigned int ui = 4; + const long l = -5; // NOLINT(runtime/int) + const unsigned long ul = 6; // NOLINT(runtime/int) + const long long ll = -7; // NOLINT(runtime/int) + const unsigned long long ull = 8; // NOLINT(runtime/int) + const ptrdiff_t ptrdiff = -9; + const size_t size = 10; + const intptr_t intptr = -12; + const uintptr_t uintptr = 13; + std::string answer; + answer = StrCat(s, us); + EXPECT_EQ(answer, "-12"); + answer = StrCat(i, ui); + EXPECT_EQ(answer, "-34"); + answer = StrCat(l, ul); + EXPECT_EQ(answer, "-56"); + answer = StrCat(ll, ull); + EXPECT_EQ(answer, "-78"); + answer = StrCat(ptrdiff, size); + EXPECT_EQ(answer, "-910"); + answer = StrCat(ptrdiff, intptr); + EXPECT_EQ(answer, "-9-12"); + answer = StrCat(uintptr, 0); + EXPECT_EQ(answer, "130"); +} + +class ReplaceChars + : public ::testing::TestWithParam< + std::tuple> {}; + +TEST_P(ReplaceChars, ReplacesAllOccurencesOfAnyCharInReplaceWithAReplaceChar) { + std::string expected = std::get<0>(GetParam()); + std::string string_to_replace_in = std::get<1>(GetParam()); + const char* what_to_replace = std::get<2>(GetParam()); + char replacement = std::get<3>(GetParam()); + ReplaceCharacters(&string_to_replace_in, what_to_replace, replacement); + ASSERT_EQ(expected, string_to_replace_in); +} + +INSTANTIATE_TEST_CASE_P( + Replace, ReplaceChars, + ::testing::Values( + std::make_tuple("", "", "", '_'), // empty string should remain empty + std::make_tuple(" ", " ", "", '_'), // no replacement string + std::make_tuple(" ", " ", "_-abcedf", + '*'), // replacement character not in string + std::make_tuple("replace", "Replace", "R", + 'r'), // replace one character + std::make_tuple("not_spaces__", "not\nspaces\t ", " \t\r\n", + '_'), // replace some special characters + std::make_tuple("c++", "cxx", "x", + '+'), // same character multiple times + std::make_tuple("qvvvvvng v T", "queueing a T", "aeiou", + 'v'))); // replace all voewls + +class StripWs + : public ::testing::TestWithParam> {}; + +TEST_P(StripWs, AlwaysStripsLeadingAndTrailingWhitespace) { + std::string expected = std::get<0>(GetParam()); + std::string string_to_strip = std::get<1>(GetParam()); + StripWhitespace(&string_to_strip); + ASSERT_EQ(expected, string_to_strip); +} + +INSTANTIATE_TEST_CASE_P( + Strip, StripWs, + ::testing::Values( + std::make_tuple("", ""), // empty string should remain empty + std::make_tuple("", " "), // only ws should become empty + std::make_tuple("no whitespace", + " no whitespace"), // leading ws removed + std::make_tuple("no whitespace", + "no whitespace "), // trailing ws removed + std::make_tuple("no whitespace", + " no whitespace "), // same nb. of leading and trailing + std::make_tuple( + "no whitespace", + " no whitespace "), // different nb. of leading/trailing + std::make_tuple("no whitespace", + " no whitespace "))); // more trailing than leading + } // anonymous namespace } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/substitute.cc b/libs/protobuf/src/google/protobuf/stubs/substitute.cc new file mode 100644 index 0000000..d301682 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/substitute.cc @@ -0,0 +1,136 @@ +// 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. + +// Author: kenton@google.com (Kenton Varda) + +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace strings { + +using internal::SubstituteArg; + +// Returns the number of args in arg_array which were passed explicitly +// to Substitute(). +static int CountSubstituteArgs(const SubstituteArg* const* args_array) { + int count = 0; + while (args_array[count] != nullptr && args_array[count]->size() != -1) { + ++count; + } + return count; +} + +std::string Substitute(const std::string& format, const SubstituteArg& arg0, + const SubstituteArg& arg1, const SubstituteArg& arg2, + const SubstituteArg& arg3, const SubstituteArg& arg4, + const SubstituteArg& arg5, const SubstituteArg& arg6, + const SubstituteArg& arg7, const SubstituteArg& arg8, + const SubstituteArg& arg9) { + std::string result; + SubstituteAndAppend(&result, format.c_str(), arg0, arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8, arg9); + return result; +} + +void SubstituteAndAppend(std::string* output, const char* format, + const SubstituteArg& arg0, const SubstituteArg& arg1, + const SubstituteArg& arg2, const SubstituteArg& arg3, + const SubstituteArg& arg4, const SubstituteArg& arg5, + const SubstituteArg& arg6, const SubstituteArg& arg7, + const SubstituteArg& arg8, const SubstituteArg& arg9) { + const SubstituteArg* const args_array[] = { + &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8, &arg9, nullptr + }; + + // Determine total size needed. + int size = 0; + for (int i = 0; format[i] != '\0'; i++) { + if (format[i] == '$') { + if (ascii_isdigit(format[i+1])) { + int index = format[i+1] - '0'; + if (args_array[index]->size() == -1) { + GOOGLE_LOG(DFATAL) + << "strings::Substitute format string invalid: asked for \"$" + << index << "\", but only " << CountSubstituteArgs(args_array) + << " args were given. Full format string was: \"" + << CEscape(format) << "\"."; + return; + } + size += args_array[index]->size(); + ++i; // Skip next char. + } else if (format[i+1] == '$') { + ++size; + ++i; // Skip next char. + } else { + GOOGLE_LOG(DFATAL) + << "Invalid strings::Substitute() format string: \"" + << CEscape(format) << "\"."; + return; + } + } else { + ++size; + } + } + + if (size == 0) return; + + // Build the string. + int original_size = output->size(); + STLStringResizeUninitialized(output, original_size + size); + char* target = string_as_array(output) + original_size; + for (int i = 0; format[i] != '\0'; i++) { + if (format[i] == '$') { + if (ascii_isdigit(format[i+1])) { + unsigned int index = format[i+1] - '0'; + assert(index < 10); + const SubstituteArg* src = args_array[index]; + memcpy(target, src->data(), src->size()); + target += src->size(); + ++i; // Skip next char. + } else if (format[i+1] == '$') { + *target++ = '$'; + ++i; // Skip next char. + } + } else { + *target++ = format[i]; + } + } + + GOOGLE_DCHECK_EQ(target - output->data(), output->size()); +} + +} // namespace strings +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/substitute.h b/libs/protobuf/src/google/protobuf/stubs/substitute.h new file mode 100644 index 0000000..0f851de --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/substitute.h @@ -0,0 +1,178 @@ +// 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. + +// Author: kenton@google.com (Kenton Varda) +// from google3/strings/substitute.h + +#include +#include +#include + +#include + +#ifndef GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ +#define GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ + +#include + +namespace google { +namespace protobuf { +namespace strings { + +// ---------------------------------------------------------------------- +// strings::Substitute() +// strings::SubstituteAndAppend() +// Kind of like StringPrintf, but different. +// +// Example: +// string GetMessage(string first_name, string last_name, int age) { +// return strings::Substitute("My name is $0 $1 and I am $2 years old.", +// first_name, last_name, age); +// } +// +// Differences from StringPrintf: +// * The format string does not identify the types of arguments. +// Instead, the magic of C++ deals with this for us. See below +// for a list of accepted types. +// * Substitutions in the format string are identified by a '$' +// followed by a digit. So, you can use arguments out-of-order and +// use the same argument multiple times. +// * It's much faster than StringPrintf. +// +// Supported types: +// * Strings (const char*, const string&) +// * Note that this means you do not have to add .c_str() to all of +// your strings. In fact, you shouldn't; it will be slower. +// * int32, int64, uint32, uint64: Formatted using SimpleItoa(). +// * float, double: Formatted using SimpleFtoa() and SimpleDtoa(). +// * bool: Printed as "true" or "false". +// +// SubstituteAndAppend() is like Substitute() but appends the result to +// *output. Example: +// +// string str; +// strings::SubstituteAndAppend(&str, +// "My name is $0 $1 and I am $2 years old.", +// first_name, last_name, age); +// +// Substitute() is significantly faster than StringPrintf(). For very +// large strings, it may be orders of magnitude faster. +// ---------------------------------------------------------------------- + +namespace internal { // Implementation details. + +class SubstituteArg { + public: + inline SubstituteArg(const char* value) + : text_(value), size_(strlen(text_)) {} + inline SubstituteArg(const std::string& value) + : text_(value.data()), size_(value.size()) {} + inline SubstituteArg(const StringPiece value) + : text_(value.data()), size_(value.size()) {} + + // Indicates that no argument was given. + inline explicit SubstituteArg() + : text_(nullptr), size_(-1) {} + + // Primitives + // We don't overload for signed and unsigned char because if people are + // explicitly declaring their chars as signed or unsigned then they are + // probably actually using them as 8-bit integers and would probably + // prefer an integer representation. But, we don't really know. So, we + // make the caller decide what to do. + inline SubstituteArg(char value) + : text_(scratch_), size_(1) { scratch_[0] = value; } + inline SubstituteArg(short value) + : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned short value) + : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(int value) + : text_(FastInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned int value) + : text_(FastUInt32ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(long value) + : text_(FastLongToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned long value) + : text_(FastULongToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(long long value) + : text_(FastInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(unsigned long long value) + : text_(FastUInt64ToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(float value) + : text_(FloatToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(double value) + : text_(DoubleToBuffer(value, scratch_)), size_(strlen(text_)) {} + inline SubstituteArg(bool value) + : text_(value ? "true" : "false"), size_(strlen(text_)) {} + + inline const char* data() const { return text_; } + inline int size() const { return size_; } + + private: + const char* text_; + int size_; + char scratch_[kFastToBufferSize]; +}; + +} // namespace internal + +PROTOBUF_EXPORT std::string Substitute( + const std::string& format, + const internal::SubstituteArg& arg0 = internal::SubstituteArg(), + const internal::SubstituteArg& arg1 = internal::SubstituteArg(), + const internal::SubstituteArg& arg2 = internal::SubstituteArg(), + const internal::SubstituteArg& arg3 = internal::SubstituteArg(), + const internal::SubstituteArg& arg4 = internal::SubstituteArg(), + const internal::SubstituteArg& arg5 = internal::SubstituteArg(), + const internal::SubstituteArg& arg6 = internal::SubstituteArg(), + const internal::SubstituteArg& arg7 = internal::SubstituteArg(), + const internal::SubstituteArg& arg8 = internal::SubstituteArg(), + const internal::SubstituteArg& arg9 = internal::SubstituteArg()); + +PROTOBUF_EXPORT void SubstituteAndAppend( + std::string* output, const char* format, + const internal::SubstituteArg& arg0 = internal::SubstituteArg(), + const internal::SubstituteArg& arg1 = internal::SubstituteArg(), + const internal::SubstituteArg& arg2 = internal::SubstituteArg(), + const internal::SubstituteArg& arg3 = internal::SubstituteArg(), + const internal::SubstituteArg& arg4 = internal::SubstituteArg(), + const internal::SubstituteArg& arg5 = internal::SubstituteArg(), + const internal::SubstituteArg& arg6 = internal::SubstituteArg(), + const internal::SubstituteArg& arg7 = internal::SubstituteArg(), + const internal::SubstituteArg& arg8 = internal::SubstituteArg(), + const internal::SubstituteArg& arg9 = internal::SubstituteArg()); + +} // namespace strings +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_STUBS_SUBSTITUTE_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/template_util.h b/libs/protobuf/src/google/protobuf/stubs/template_util.h new file mode 100644 index 0000000..feef904 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/template_util.h @@ -0,0 +1,138 @@ +// Copyright 2005 Google Inc. +// All rights reserved. +// +// 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. + +// ---- +// Author: lar@google.com (Laramie Leavitt) +// +// Template metaprogramming utility functions. +// +// This code is compiled directly on many platforms, including client +// platforms like Windows, Mac, and embedded systems. Before making +// any changes here, make sure that you're not breaking any platforms. +// +// +// The names chosen here reflect those used in tr1 and the boost::mpl +// library, there are similar operations used in the Loki library as +// well. I prefer the boost names for 2 reasons: +// 1. I think that portions of the Boost libraries are more likely to +// be included in the c++ standard. +// 2. It is not impossible that some of the boost libraries will be +// included in our own build in the future. +// Both of these outcomes means that we may be able to directly replace +// some of these with boost equivalents. +// +#ifndef GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ +#define GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ + +namespace google { +namespace protobuf { +namespace internal { + +// Types small_ and big_ are guaranteed such that sizeof(small_) < +// sizeof(big_) +typedef char small_; + +struct big_ { + char dummy[2]; +}; + +// Identity metafunction. +template +struct identity_ { + typedef T type; +}; + +// integral_constant, defined in tr1, is a wrapper for an integer +// value. We don't really need this generality; we could get away +// with hardcoding the integer type to bool. We use the fully +// general integer_constant for compatibility with tr1. + +template +struct integral_constant { + static const T value = v; + typedef T value_type; + typedef integral_constant type; +}; + +template const T integral_constant::value; + + +// Abbreviations: true_type and false_type are structs that represent boolean +// true and false values. Also define the boost::mpl versions of those names, +// true_ and false_. +typedef integral_constant true_type; +typedef integral_constant false_type; +typedef true_type true_; +typedef false_type false_; + +// if_ is a templatized conditional statement. +// if_ is a compile time evaluation of cond. +// if_<>::type contains A if cond is true, B otherwise. +template +struct if_{ + typedef A type; +}; + +template +struct if_ { + typedef B type; +}; + + +// type_equals_ is a template type comparator, similar to Loki IsSameType. +// type_equals_::value is true iff "A" is the same type as "B". +// +// New code should prefer base::is_same, defined in base/type_traits.h. +// It is functionally identical, but is_same is the standard spelling. +template +struct type_equals_ : public false_ { +}; + +template +struct type_equals_ : public true_ { +}; + +// and_ is a template && operator. +// and_::value evaluates "A::value && B::value". +template +struct and_ : public integral_constant { +}; + +// or_ is a template || operator. +// or_::value evaluates "A::value || B::value". +template +struct or_ : public integral_constant { +}; + + +} // namespace internal +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/template_util_unittest.cc b/libs/protobuf/src/google/protobuf/stubs/template_util_unittest.cc new file mode 100644 index 0000000..b1745e2 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/template_util_unittest.cc @@ -0,0 +1,130 @@ +// Copyright 2005 Google Inc. +// All rights reserved. +// +// 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. + +// ---- +// Author: lar@google.com (Laramie Leavitt) +// +// These tests are really compile time tests. +// If you try to step through this in a debugger +// you will not see any evaluations, merely that +// value is assigned true or false sequentially. + +#include + +#include +#include + +namespace GOOGLE_NAMESPACE = google::protobuf::internal; + +namespace google { +namespace protobuf { +namespace internal { +namespace { + +TEST(TemplateUtilTest, TestSize) { + EXPECT_GT(sizeof(GOOGLE_NAMESPACE::big_), sizeof(GOOGLE_NAMESPACE::small_)); +} + +TEST(TemplateUtilTest, TestIntegralConstants) { + // test the built-in types. + EXPECT_TRUE(true_type::value); + EXPECT_FALSE(false_type::value); + + typedef integral_constant one_type; + EXPECT_EQ(1, one_type::value); +} + +TEST(TemplateUtilTest, TestTemplateIf) { + typedef if_::type if_true; + EXPECT_TRUE(if_true::value); + + typedef if_::type if_false; + EXPECT_FALSE(if_false::value); +} + +TEST(TemplateUtilTest, TestTemplateTypeEquals) { + // Check that the TemplateTypeEquals works correctly. + bool value = false; + + // Test the same type is true. + value = type_equals_::value; + EXPECT_TRUE(value); + + // Test different types are false. + value = type_equals_::value; + EXPECT_FALSE(value); + + // Test type aliasing. + typedef const int foo; + value = type_equals_::value; + EXPECT_TRUE(value); +} + +TEST(TemplateUtilTest, TestTemplateAndOr) { + // Check that the TemplateTypeEquals works correctly. + bool value = false; + + // Yes && Yes == true. + value = and_::value; + EXPECT_TRUE(value); + // Yes && No == false. + value = and_::value; + EXPECT_FALSE(value); + // No && Yes == false. + value = and_::value; + EXPECT_FALSE(value); + // No && No == false. + value = and_::value; + EXPECT_FALSE(value); + + // Yes || Yes == true. + value = or_::value; + EXPECT_TRUE(value); + // Yes || No == true. + value = or_::value; + EXPECT_TRUE(value); + // No || Yes == true. + value = or_::value; + EXPECT_TRUE(value); + // No || No == false. + value = or_::value; + EXPECT_FALSE(value); +} + +TEST(TemplateUtilTest, TestIdentity) { + EXPECT_TRUE( + (type_equals_::type, int>::value)); + EXPECT_TRUE( + (type_equals_::type, void>::value)); +} + +} // anonymous namespace +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/stubs/time.cc b/libs/protobuf/src/google/protobuf/stubs/time.cc new file mode 100644 index 0000000..692cb82 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/time.cc @@ -0,0 +1,365 @@ +#include + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace internal { + +namespace { +static const int64_t kSecondsPerMinute = 60; +static const int64_t kSecondsPerHour = 3600; +static const int64_t kSecondsPerDay = kSecondsPerHour * 24; +static const int64_t kSecondsPer400Years = + kSecondsPerDay * (400 * 365 + 400 / 4 - 3); +// Seconds from 0001-01-01T00:00:00 to 1970-01-01T:00:00:00 +static const int64_t kSecondsFromEraToEpoch = 62135596800LL; +// The range of timestamp values we support. +static const int64_t kMinTime = -62135596800LL; // 0001-01-01T00:00:00 +static const int64_t kMaxTime = 253402300799LL; // 9999-12-31T23:59:59 + +static const int kNanosPerMillisecond = 1000000; +static const int kNanosPerMicrosecond = 1000; + +// Count the seconds from the given year (start at Jan 1, 00:00) to 100 years +// after. +int64_t SecondsPer100Years(int year) { + if (year % 400 == 0 || year % 400 > 300) { + return kSecondsPerDay * (100 * 365 + 100 / 4); + } else { + return kSecondsPerDay * (100 * 365 + 100 / 4 - 1); + } +} + +// Count the seconds from the given year (start at Jan 1, 00:00) to 4 years +// after. +int64_t SecondsPer4Years(int year) { + if ((year % 100 == 0 || year % 100 > 96) && + !(year % 400 == 0 || year % 400 > 396)) { + // No leap years. + return kSecondsPerDay * (4 * 365); + } else { + // One leap years. + return kSecondsPerDay * (4 * 365 + 1); + } +} + +bool IsLeapYear(int year) { + return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); +} + +int64_t SecondsPerYear(int year) { + return kSecondsPerDay * (IsLeapYear(year) ? 366 : 365); +} + +static const int kDaysInMonth[13] = { + 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +int64_t SecondsPerMonth(int month, bool leap) { + if (month == 2 && leap) { + return kSecondsPerDay * (kDaysInMonth[month] + 1); + } + return kSecondsPerDay * kDaysInMonth[month]; +} + +static const int kDaysSinceJan[13] = { + 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, +}; + +bool ValidateDateTime(const DateTime& time) { + if (time.year < 1 || time.year > 9999 || + time.month < 1 || time.month > 12 || + time.day < 1 || time.day > 31 || + time.hour < 0 || time.hour > 23 || + time.minute < 0 || time.minute > 59 || + time.second < 0 || time.second > 59) { + return false; + } + if (time.month == 2 && IsLeapYear(time.year)) { + return time.day <= kDaysInMonth[time.month] + 1; + } else { + return time.day <= kDaysInMonth[time.month]; + } +} + +// Count the number of seconds elapsed from 0001-01-01T00:00:00 to the given +// time. +int64_t SecondsSinceCommonEra(const DateTime& time) { + int64_t result = 0; + // Years should be between 1 and 9999. + assert(time.year >= 1 && time.year <= 9999); + int year = 1; + if ((time.year - year) >= 400) { + int count_400years = (time.year - year) / 400; + result += kSecondsPer400Years * count_400years; + year += count_400years * 400; + } + while ((time.year - year) >= 100) { + result += SecondsPer100Years(year); + year += 100; + } + while ((time.year - year) >= 4) { + result += SecondsPer4Years(year); + year += 4; + } + while (time.year > year) { + result += SecondsPerYear(year); + ++year; + } + // Months should be between 1 and 12. + assert(time.month >= 1 && time.month <= 12); + int month = time.month; + result += kSecondsPerDay * kDaysSinceJan[month]; + if (month > 2 && IsLeapYear(year)) { + result += kSecondsPerDay; + } + assert(time.day >= 1 && + time.day <= (month == 2 && IsLeapYear(year) + ? kDaysInMonth[month] + 1 + : kDaysInMonth[month])); + result += kSecondsPerDay * (time.day - 1); + result += kSecondsPerHour * time.hour + + kSecondsPerMinute * time.minute + + time.second; + return result; +} + +// Format nanoseconds with either 3, 6, or 9 digits depending on the required +// precision to represent the exact value. +std::string FormatNanos(int32_t nanos) { + if (nanos % kNanosPerMillisecond == 0) { + return StringPrintf("%03d", nanos / kNanosPerMillisecond); + } else if (nanos % kNanosPerMicrosecond == 0) { + return StringPrintf("%06d", nanos / kNanosPerMicrosecond); + } else { + return StringPrintf("%09d", nanos); + } +} + +// Parses an integer from a null-terminated char sequence. The method +// consumes at most "width" chars. Returns a pointer after the consumed +// integer, or nullptr if the data does not start with an integer or the +// integer value does not fall in the range of [min_value, max_value]. +const char* ParseInt(const char* data, int width, int min_value, + int max_value, int* result) { + if (!ascii_isdigit(*data)) { + return nullptr; + } + int value = 0; + for (int i = 0; i < width; ++i, ++data) { + if (ascii_isdigit(*data)) { + value = value * 10 + (*data - '0'); + } else { + break; + } + } + if (value >= min_value && value <= max_value) { + *result = value; + return data; + } else { + return nullptr; + } +} + +// Consumes the fractional parts of a second into nanos. For example, +// "010" will be parsed to 10000000 nanos. +const char* ParseNanos(const char* data, int32_t* nanos) { + if (!ascii_isdigit(*data)) { + return nullptr; + } + int value = 0; + int len = 0; + // Consume as many digits as there are but only take the first 9 into + // account. + while (ascii_isdigit(*data)) { + if (len < 9) { + value = value * 10 + *data - '0'; + } + ++len; + ++data; + } + while (len < 9) { + value = value * 10; + ++len; + } + *nanos = value; + return data; +} + +const char* ParseTimezoneOffset(const char* data, int64_t* offset) { + // Accept format "HH:MM". E.g., "08:00" + int hour; + if ((data = ParseInt(data, 2, 0, 23, &hour)) == nullptr) { + return nullptr; + } + if (*data++ != ':') { + return nullptr; + } + int minute; + if ((data = ParseInt(data, 2, 0, 59, &minute)) == nullptr) { + return nullptr; + } + *offset = (hour * 60 + minute) * 60; + return data; +} +} // namespace + +bool SecondsToDateTime(int64_t seconds, DateTime* time) { + if (seconds < kMinTime || seconds > kMaxTime) { + return false; + } + // It's easier to calculate the DateTime starting from 0001-01-01T00:00:00 + seconds = seconds + kSecondsFromEraToEpoch; + int year = 1; + if (seconds >= kSecondsPer400Years) { + int count_400years = seconds / kSecondsPer400Years; + year += 400 * count_400years; + seconds %= kSecondsPer400Years; + } + while (seconds >= SecondsPer100Years(year)) { + seconds -= SecondsPer100Years(year); + year += 100; + } + while (seconds >= SecondsPer4Years(year)) { + seconds -= SecondsPer4Years(year); + year += 4; + } + while (seconds >= SecondsPerYear(year)) { + seconds -= SecondsPerYear(year); + year += 1; + } + bool leap = IsLeapYear(year); + int month = 1; + while (seconds >= SecondsPerMonth(month, leap)) { + seconds -= SecondsPerMonth(month, leap); + ++month; + } + int day = 1 + seconds / kSecondsPerDay; + seconds %= kSecondsPerDay; + int hour = seconds / kSecondsPerHour; + seconds %= kSecondsPerHour; + int minute = seconds / kSecondsPerMinute; + seconds %= kSecondsPerMinute; + time->year = year; + time->month = month; + time->day = day; + time->hour = hour; + time->minute = minute; + time->second = static_cast(seconds); + return true; +} + +bool DateTimeToSeconds(const DateTime& time, int64_t* seconds) { + if (!ValidateDateTime(time)) { + return false; + } + *seconds = SecondsSinceCommonEra(time) - kSecondsFromEraToEpoch; + return true; +} + +void GetCurrentTime(int64_t* seconds, int32_t* nanos) { + // TODO(xiaofeng): Improve the accuracy of this implementation (or just + // remove this method from protobuf). + *seconds = time(nullptr); + *nanos = 0; +} + +std::string FormatTime(int64_t seconds, int32_t nanos) { + DateTime time; + if (nanos < 0 || nanos > 999999999 || !SecondsToDateTime(seconds, &time)) { + return "InvalidTime"; + } + std::string result = + StringPrintf("%04d-%02d-%02dT%02d:%02d:%02d", time.year, time.month, + time.day, time.hour, time.minute, time.second); + if (nanos != 0) { + result += "." + FormatNanos(nanos); + } + return result + "Z"; +} + +bool ParseTime(const std::string& value, int64_t* seconds, int32_t* nanos) { + DateTime time; + const char* data = value.c_str(); + // We only accept: + // Z-normalized: 2015-05-20T13:29:35.120Z + // With UTC offset: 2015-05-20T13:29:35.120-08:00 + + // Parse year + if ((data = ParseInt(data, 4, 1, 9999, &time.year)) == nullptr) { + return false; + } + // Expect '-' + if (*data++ != '-') return false; + // Parse month + if ((data = ParseInt(data, 2, 1, 12, &time.month)) == nullptr) { + return false; + } + // Expect '-' + if (*data++ != '-') return false; + // Parse day + if ((data = ParseInt(data, 2, 1, 31, &time.day)) == nullptr) { + return false; + } + // Expect 'T' + if (*data++ != 'T') return false; + // Parse hour + if ((data = ParseInt(data, 2, 0, 23, &time.hour)) == nullptr) { + return false; + } + // Expect ':' + if (*data++ != ':') return false; + // Parse minute + if ((data = ParseInt(data, 2, 0, 59, &time.minute)) == nullptr) { + return false; + } + // Expect ':' + if (*data++ != ':') return false; + // Parse second + if ((data = ParseInt(data, 2, 0, 59, &time.second)) == nullptr) { + return false; + } + if (!DateTimeToSeconds(time, seconds)) { + return false; + } + // Parse nanoseconds. + if (*data == '.') { + ++data; + // Parse nanoseconds. + if ((data = ParseNanos(data, nanos)) == nullptr) { + return false; + } + } else { + *nanos = 0; + } + // Parse UTC offsets. + if (*data == 'Z') { + ++data; + } else if (*data == '+') { + ++data; + int64_t offset; + if ((data = ParseTimezoneOffset(data, &offset)) == nullptr) { + return false; + } + *seconds -= offset; + } else if (*data == '-') { + ++data; + int64_t offset; + if ((data = ParseTimezoneOffset(data, &offset)) == nullptr) { + return false; + } + *seconds += offset; + } else { + return false; + } + // Done with parsing. + return *data == 0; +} + +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/arena_config.h b/libs/protobuf/src/google/protobuf/stubs/time.h similarity index 53% rename from libs/protobuf/src/google/protobuf/arena_config.h rename to libs/protobuf/src/google/protobuf/stubs/time.h index f16d86a..8b6e562 100644 --- a/libs/protobuf/src/google/protobuf/arena_config.h +++ b/libs/protobuf/src/google/protobuf/stubs/time.h @@ -27,47 +27,56 @@ // 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_STUBS_TIME_H_ +#define GOOGLE_PROTOBUF_STUBS_TIME_H_ -#ifndef GOOGLE_PROTOBUF_ARENA_CONFIG_H__ -#define GOOGLE_PROTOBUF_ARENA_CONFIG_H__ +#include -#include -#include +#include -// Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { namespace internal { -namespace arena_config_internal { -// We use an atomic here only for correctness so that we can read/write -// concurrently. We don't have memory order requirements so we use relaxed -// memory ordering. -PROTOBUF_EXPORT extern std::atomic default_arena_max_block_size; +struct DateTime { + int year; + int month; + int day; + int hour; + int minute; + int second; +}; -} // namespace arena_config_internal +// Converts a timestamp (seconds elapsed since 1970-01-01T00:00:00, could be +// negative to represent time before 1970-01-01) to DateTime. Returns false +// if the timestamp is not in the range between 0001-01-01T00:00:00 and +// 9999-12-31T23:59:59. +bool PROTOBUF_EXPORT SecondsToDateTime(int64_t seconds, DateTime* time); +// Converts DateTime to a timestamp (seconds since 1970-01-01T00:00:00). +// Returns false if the DateTime is not valid or is not in the valid range. +bool PROTOBUF_EXPORT DateTimeToSeconds(const DateTime& time, int64_t* seconds); -// The default value to use for DefaultArenaMaxBlockSize when -// SetDefaultArenaMaxBlockSize hasn't been called. -PROTOBUF_EXPORT extern const size_t kDefaultDefaultArenaMaxBlockSize; +void PROTOBUF_EXPORT GetCurrentTime(int64_t* seconds, int32_t* nanos); -// The default value to use for arena max block size when no value is provided -// in ArenaOptions. -inline size_t GetDefaultArenaMaxBlockSize() { - return arena_config_internal::default_arena_max_block_size.load( - std::memory_order_relaxed); -} -inline void SetDefaultArenaMaxBlockSize(size_t default_arena_max_block_size) { - return arena_config_internal::default_arena_max_block_size.store( - default_arena_max_block_size, std::memory_order_relaxed); -} +// Formats a time string in RFC3339 format. +// +// For example, "2015-05-20T13:29:35.120Z". For nanos, 0, 3, 6 or 9 fractional +// digits will be used depending on how many are required to represent the exact +// value. +// +// Note that "nanos" must in the range of [0, 999999999]. +std::string PROTOBUF_EXPORT FormatTime(int64_t seconds, int32_t nanos); +// Parses a time string. This method accepts RFC3339 date/time string with UTC +// offset. For example, "2015-05-20T13:29:35.120-08:00". +bool PROTOBUF_EXPORT ParseTime(const std::string& value, int64_t* seconds, + int32_t* nanos); } // namespace internal } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include -#endif // GOOGLE_PROTOBUF_ARENA_CONFIG_H__ +#endif // GOOGLE_PROTOBUF_STUBS_TIME_H_ diff --git a/libs/protobuf/src/google/protobuf/stubs/time_test.cc b/libs/protobuf/src/google/protobuf/stubs/time_test.cc new file mode 100644 index 0000000..1ce0a1c --- /dev/null +++ b/libs/protobuf/src/google/protobuf/stubs/time_test.cc @@ -0,0 +1,261 @@ +// 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 + +#include +#include + +namespace google { +namespace protobuf { +namespace internal { +namespace { +static const int64 kSecondsPerDay = 3600 * 24; + +// For DateTime, tests will mostly focus on the date part because that's +// the tricky one. +int64 CreateTimestamp(int year, int month, int day) { + DateTime time; + time.year = year; + time.month = month; + time.day = day; + time.hour = time.minute = time.second = 0; + int64 result; + GOOGLE_CHECK(DateTimeToSeconds(time, &result)); + // Check that a roundtrip produces the same result. + GOOGLE_CHECK(SecondsToDateTime(result, &time)); + GOOGLE_CHECK(time.year == year); + GOOGLE_CHECK(time.month == month); + GOOGLE_CHECK(time.day == day); + return result; +} + +TEST(DateTimeTest, SimpleTime) { + DateTime time; + ASSERT_TRUE(SecondsToDateTime(1, &time)); + EXPECT_EQ(1970, time.year); + EXPECT_EQ(1, time.month); + EXPECT_EQ(1, time.day); + EXPECT_EQ(0, time.hour); + EXPECT_EQ(0, time.minute); + EXPECT_EQ(1, time.second); + int64 seconds; + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + EXPECT_EQ(1, seconds); + + ASSERT_TRUE(SecondsToDateTime(-1, &time)); + EXPECT_EQ(1969, time.year); + EXPECT_EQ(12, time.month); + EXPECT_EQ(31, time.day); + EXPECT_EQ(23, time.hour); + EXPECT_EQ(59, time.minute); + EXPECT_EQ(59, time.second); + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + EXPECT_EQ(-1, seconds); + + DateTime start, end; + start.year = 1; + start.month = 1; + start.day = 1; + start.hour = 0; + start.minute = 0; + start.second = 0; + end.year = 9999; + end.month = 12; + end.day = 31; + end.hour = 23; + end.minute = 59; + end.second = 59; + int64 start_time, end_time; + ASSERT_TRUE(DateTimeToSeconds(start, &start_time)); + ASSERT_TRUE(DateTimeToSeconds(end, &end_time)); + EXPECT_EQ(315537897599LL, end_time - start_time); + ASSERT_TRUE(SecondsToDateTime(start_time, &time)); + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + EXPECT_EQ(start_time, seconds); + ASSERT_TRUE(SecondsToDateTime(end_time, &time)); + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + EXPECT_EQ(end_time, seconds); +} + +TEST(DateTimeTest, DayInMonths) { + // Check that month boundaries are handled correctly. + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 1, 1) - CreateTimestamp(2014, 12, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 2, 1) - CreateTimestamp(2015, 1, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 3, 1) - CreateTimestamp(2015, 2, 28)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 4, 1) - CreateTimestamp(2015, 3, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 5, 1) - CreateTimestamp(2015, 4, 30)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 6, 1) - CreateTimestamp(2015, 5, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 7, 1) - CreateTimestamp(2015, 6, 30)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 8, 1) - CreateTimestamp(2015, 7, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 9, 1) - CreateTimestamp(2015, 8, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 10, 1) - CreateTimestamp(2015, 9, 30)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 11, 1) - CreateTimestamp(2015, 10, 31)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 12, 1) - CreateTimestamp(2015, 11, 30)); + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2016, 1, 1) - CreateTimestamp(2015, 12, 31)); +} + +TEST(DateTimeTest, LeapYear) { + // Non-leap year. + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2015, 3, 1) - CreateTimestamp(2015, 2, 28)); + // Leap year. + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2016, 3, 1) - CreateTimestamp(2016, 2, 29)); + // Non-leap year. + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2100, 3, 1) - CreateTimestamp(2100, 2, 28)); + // Leap year. + EXPECT_EQ(kSecondsPerDay, + CreateTimestamp(2400, 3, 1) - CreateTimestamp(2400, 2, 29)); +} + +TEST(DateTimeTest, WrongDays) { + int64 seconds; + DateTime time; + time.hour = 0; + time.minute = 0; + time.second = 0; + time.month = 2; + + // Non-leap year. + time.year = 2015; + time.day = 29; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + + // Leap year. + time.year = 2016; + time.day = 29; + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + time.day = 30; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + + // Non-leap year. + time.year = 2100; + time.day = 29; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + + // Leap year. + time.year = 2400; + time.day = 29; + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + time.day = 30; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + + // Non-february + time.year = 2015; + time.month = 1; + time.day = 0; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + time.day = 1; + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + time.day = 31; + ASSERT_TRUE(DateTimeToSeconds(time, &seconds)); + time.day = 32; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + + // Bad month + time.year = 2015; + time.month = 0; + time.day = 1; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); + time.month = 13; + ASSERT_FALSE(DateTimeToSeconds(time, &seconds)); +} + +TEST(DateTimeTest, StringFormat) { + DateTime start, end; + start.year = 1; + start.month = 1; + start.day = 1; + start.hour = 0; + start.minute = 0; + start.second = 0; + end.year = 9999; + end.month = 12; + end.day = 31; + end.hour = 23; + end.minute = 59; + end.second = 59; + int64 start_time, end_time; + ASSERT_TRUE(DateTimeToSeconds(start, &start_time)); + ASSERT_TRUE(DateTimeToSeconds(end, &end_time)); + + EXPECT_EQ("0001-01-01T00:00:00Z", FormatTime(start_time, 0)); + EXPECT_EQ("9999-12-31T23:59:59Z", FormatTime(end_time, 0)); + + // Make sure the nanoseconds part is formatted correctly. + EXPECT_EQ("1970-01-01T00:00:00.010Z", FormatTime(0, 10000000)); + EXPECT_EQ("1970-01-01T00:00:00.000010Z", FormatTime(0, 10000)); + EXPECT_EQ("1970-01-01T00:00:00.000000010Z", FormatTime(0, 10)); +} + +TEST(DateTimeTest, ParseString) { + int64 seconds; + int32 nanos; + ASSERT_TRUE(ParseTime("0001-01-01T00:00:00Z", &seconds, &nanos)); + EXPECT_EQ("0001-01-01T00:00:00Z", FormatTime(seconds, nanos)); + ASSERT_TRUE(ParseTime("9999-12-31T23:59:59.999999999Z", &seconds, &nanos)); + EXPECT_EQ("9999-12-31T23:59:59.999999999Z", FormatTime(seconds, nanos)); + + // Test time zone offsets. + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00-08:00", &seconds, &nanos)); + EXPECT_EQ("1970-01-01T08:00:00Z", FormatTime(seconds, nanos)); + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00+08:00", &seconds, &nanos)); + EXPECT_EQ("1969-12-31T16:00:00Z", FormatTime(seconds, nanos)); + + // Test nanoseconds. + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00.01Z", &seconds, &nanos)); + EXPECT_EQ("1970-01-01T00:00:00.010Z", FormatTime(seconds, nanos)); + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00.00001-08:00", &seconds, &nanos)); + EXPECT_EQ("1970-01-01T08:00:00.000010Z", FormatTime(seconds, nanos)); + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00.00000001+08:00", &seconds, &nanos)); + EXPECT_EQ("1969-12-31T16:00:00.000000010Z", FormatTime(seconds, nanos)); + // Fractional parts less than 1 nanosecond will be ignored. + ASSERT_TRUE(ParseTime("1970-01-01T00:00:00.0123456789Z", &seconds, &nanos)); + EXPECT_EQ("1970-01-01T00:00:00.012345678Z", FormatTime(seconds, nanos)); +} + +} // namespace +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/test_messages_proto2.proto b/libs/protobuf/src/google/protobuf/test_messages_proto2.proto index 1cc7c86..c7b9c48 100644 --- a/libs/protobuf/src/google/protobuf/test_messages_proto2.proto +++ b/libs/protobuf/src/google/protobuf/test_messages_proto2.proto @@ -40,7 +40,6 @@ syntax = "proto2"; package protobuf_test_messages.proto2; option java_package = "com.google.protobuf_test_messages.proto2"; -option objc_class_prefix = "Proto2"; // This is the default, but we specify it here explicitly. option optimize_for = SPEED; @@ -196,21 +195,21 @@ message TestAllTypesProto2 { } // default values - optional int32 default_int32 = 241 [default = -123456789]; - optional int64 default_int64 = 242 [default = -9123456789123456789]; - optional uint32 default_uint32 = 243 [default = 2123456789]; - optional uint64 default_uint64 = 244 [default = 10123456789123456789]; - optional sint32 default_sint32 = 245 [default = -123456789]; + optional int32 default_int32 = 241 [ default = -123456789]; + optional int64 default_int64 = 242 [ default = -9123456789123456789]; + optional uint32 default_uint32 = 243 [ default = 2123456789]; + optional uint64 default_uint64 = 244 [ default = 10123456789123456789]; + optional sint32 default_sint32 = 245 [ default = -123456789]; optional sint64 default_sint64 = 246 [default = -9123456789123456789]; - optional fixed32 default_fixed32 = 247 [default = 2123456789]; - optional fixed64 default_fixed64 = 248 [default = 10123456789123456789]; - optional sfixed32 default_sfixed32 = 249 [default = -123456789]; + optional fixed32 default_fixed32 = 247 [ default = 2123456789]; + optional fixed64 default_fixed64 = 248 [ default = 10123456789123456789]; + optional sfixed32 default_sfixed32 = 249 [ default = -123456789]; optional sfixed64 default_sfixed64 = 250 [default = -9123456789123456789]; - optional float default_float = 251 [default = 9e9]; - optional double default_double = 252 [default = 7e22]; - optional bool default_bool = 253 [default = true]; - optional string default_string = 254 [default = "Rosebud"]; - optional bytes default_bytes = 255 [default = "joshua"]; + optional float default_float = 251 [ default = 9e9]; + optional double default_double = 252 [ default = 7e22]; + optional bool default_bool = 253 [ default = true]; + optional string default_string = 254 [ default = "Rosebud"]; + optional bytes default_bytes = 255 [ default = "joshua"]; // Test field-name-to-JSON-name convention. // (protobuf says names can be any valid C/C++ identifier.) @@ -283,7 +282,8 @@ message UnknownToTestAllTypes { repeated int32 repeated_int32 = 1011; } -message NullHypothesisProto2 {} +message NullHypothesisProto2 { +} message EnumOnlyProto2 { enum Bool { @@ -295,9 +295,3 @@ message EnumOnlyProto2 { message OneStringProto2 { optional string data = 1; } - -message ProtoWithKeywords { - optional int32 inline = 1; - optional string concept = 2; - repeated string requires = 3; -} diff --git a/libs/protobuf/src/google/protobuf/test_util.cc b/libs/protobuf/src/google/protobuf/test_util.cc index 5fee8ff..795cb6a 100644 --- a/libs/protobuf/src/google/protobuf/test_util.cc +++ b/libs/protobuf/src/google/protobuf/test_util.cc @@ -38,7 +38,7 @@ #include #endif -#include "google/protobuf/test_util.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/test_util.h b/libs/protobuf/src/google/protobuf/test_util.h index 5449ed6..b18d7b6 100644 --- a/libs/protobuf/src/google/protobuf/test_util.h +++ b/libs/protobuf/src/google/protobuf/test_util.h @@ -35,17 +35,17 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL_H__ #define GOOGLE_PROTOBUF_TEST_UTIL_H__ -#include "google/protobuf/unittest.pb.h" +#include #define UNITTEST ::protobuf_unittest #define UNITTEST_IMPORT ::protobuf_unittest_import // Must be included when the preprocessor symbols above are defined. -#include "google/protobuf/test_util.inc" +#include #undef UNITTEST #undef UNITTEST_IMPORT // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -63,8 +63,6 @@ class ReflectionTester { // the latter case, ReflectionTester searches for extension fields in // its file. explicit ReflectionTester(const Descriptor* base_descriptor); - ReflectionTester(const ReflectionTester&) = delete; - ReflectionTester& operator=(const ReflectionTester&) = delete; void SetAllFieldsViaReflection(Message* message); void ModifyRepeatedFieldsViaReflection(Message* message); @@ -122,6 +120,8 @@ class ReflectionTester { void ExpectAllFieldsSetViaReflection1(const Message& message); void ExpectAllFieldsSetViaReflection2(const Message& message); void ExpectAllFieldsSetViaReflection3(const Message& message); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionTester); }; inline TestUtil::ReflectionTester::ReflectionTester( @@ -1223,7 +1223,7 @@ inline void TestUtil::ReflectionTester::ExpectMessagesReleasedViaReflection( "optional_foreign_message", "optional_import_message", }; - for (int i = 0; i < ABSL_ARRAYSIZE(fields); i++) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(fields); i++) { Message* released = reflection->ReleaseMessage(message, F(fields[i])); switch (expected_release_state) { case IS_NULL: @@ -1272,6 +1272,6 @@ inline void ExpectAllFieldsAndExtensionsInOrder(const std::string& serialized) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_TEST_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/test_util.inc b/libs/protobuf/src/google/protobuf/test_util.inc index 4512db2..8d44afa 100644 --- a/libs/protobuf/src/google/protobuf/test_util.inc +++ b/libs/protobuf/src/google/protobuf/test_util.inc @@ -37,11 +37,11 @@ // within an enclosing namespace and requires header files to be included // out of this file. -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" +#include +#include namespace google { namespace protobuf { @@ -1935,7 +1935,7 @@ inline void TestUtil::ExpectUnpackedExtensionsSet( message.GetExtension(UNITTEST::unpacked_sfixed64_extension, 1)); EXPECT_EQ(711, message.GetExtension(UNITTEST::unpacked_float_extension, 1)); EXPECT_EQ(712, message.GetExtension(UNITTEST::unpacked_double_extension, 1)); - EXPECT_FALSE(message.GetExtension(UNITTEST::unpacked_bool_extension, 1)); + EXPECT_EQ(false, message.GetExtension(UNITTEST::unpacked_bool_extension, 1)); EXPECT_EQ(UNITTEST::FOREIGN_BAZ, message.GetExtension(UNITTEST::unpacked_enum_extension, 1)); } diff --git a/libs/protobuf/src/google/protobuf/test_util2.h b/libs/protobuf/src/google/protobuf/test_util2.h index 1f51ec8..540af63 100644 --- a/libs/protobuf/src/google/protobuf/test_util2.h +++ b/libs/protobuf/src/google/protobuf/test_util2.h @@ -31,29 +31,22 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL2_H__ #define GOOGLE_PROTOBUF_TEST_UTIL2_H__ -#include "google/protobuf/stubs/strutil.h" +#include -#include "google/protobuf/testing/googletest.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/util/message_differencer.h" +#include +#include +#include +#include namespace google { namespace protobuf { namespace TestUtil { -// Translate net/proto2/* or third_party/protobuf/* to google/protobuf/*. +// Translate net/proto2/* -> google/protobuf/* inline std::string TranslatePathToOpensource(const std::string& google3_path) { - std::string net_proto2 = "net/proto2/"; - std::string third_party_protobuf = "third_party/protobuf/"; - std::string path; - if (google3_path.find(net_proto2) == 0) { - path = google3_path.substr(net_proto2.size()); - } else { - GOOGLE_CHECK(google3_path.find(third_party_protobuf) == 0) << google3_path; - path = google3_path.substr(third_party_protobuf.size()); - } + const std::string prefix = "net/proto2/"; + GOOGLE_CHECK(google3_path.find(prefix) == 0) << google3_path; + std::string path = google3_path.substr(prefix.size()); path = StringReplace(path, "internal/", "", false); path = StringReplace(path, "proto/", "", false); diff --git a/libs/protobuf/src/google/protobuf/test_util_lite.cc b/libs/protobuf/src/google/protobuf/test_util_lite.cc index f09a218..628f1a0 100644 --- a/libs/protobuf/src/google/protobuf/test_util_lite.cc +++ b/libs/protobuf/src/google/protobuf/test_util_lite.cc @@ -32,12 +32,12 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/test_util_lite.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include #include -#include "absl/strings/string_view.h" +#include namespace google { namespace protobuf { @@ -326,9 +326,7 @@ void TestUtilLite::ExpectAllFieldsSet( EXPECT_EQ(310, message.repeated_sfixed64(1)); EXPECT_EQ(311, message.repeated_float(1)); EXPECT_EQ(312, message.repeated_double(1)); - // EXPECT_EQ(false, ...) triggers a compiler warning in some platforms. - // warning: converting ‘false’ to pointer type - EXPECT_FALSE(message.repeated_bool(1)); + EXPECT_EQ(false, message.repeated_bool(1)); EXPECT_EQ("315", message.repeated_string(1)); EXPECT_EQ("316", message.repeated_bytes(1)); @@ -378,7 +376,7 @@ void TestUtilLite::ExpectAllFieldsSet( EXPECT_EQ(410, message.default_sfixed64()); EXPECT_EQ(411, message.default_float()); EXPECT_EQ(412, message.default_double()); - EXPECT_FALSE(message.default_bool()); + EXPECT_EQ(false, message.default_bool()); EXPECT_EQ("415", message.default_string()); EXPECT_EQ("416", message.default_bytes()); @@ -441,7 +439,7 @@ void TestUtilLite::ExpectClear(const unittest::TestAllTypesLite& message) { EXPECT_EQ(0, message.optional_sfixed64()); EXPECT_EQ(0, message.optional_float()); EXPECT_EQ(0, message.optional_double()); - EXPECT_FALSE(message.optional_bool()); + EXPECT_EQ(false, message.optional_bool()); EXPECT_EQ("", message.optional_string()); EXPECT_EQ("", message.optional_bytes()); @@ -730,7 +728,7 @@ void TestUtilLite::ExpectPackedFieldsSet( EXPECT_EQ(710, message.packed_sfixed64(1)); EXPECT_EQ(711, message.packed_float(1)); EXPECT_EQ(712, message.packed_double(1)); - EXPECT_FALSE(message.packed_bool(1)); + EXPECT_EQ(false, message.packed_bool(1)); EXPECT_EQ(unittest::FOREIGN_LITE_BAZ, message.packed_enum(1)); } @@ -1258,7 +1256,8 @@ void TestUtilLite::ExpectAllExtensionsSet( message.GetExtension(unittest::repeated_float_extension_lite, 1)); EXPECT_EQ(312, message.GetExtension(unittest::repeated_double_extension_lite, 1)); - EXPECT_FALSE(message.GetExtension(unittest::repeated_bool_extension_lite, 1)); + EXPECT_EQ(false, + message.GetExtension(unittest::repeated_bool_extension_lite, 1)); EXPECT_EQ("315", message.GetExtension(unittest::repeated_string_extension_lite, 1)); EXPECT_EQ("316", @@ -1336,7 +1335,7 @@ void TestUtilLite::ExpectAllExtensionsSet( message.GetExtension(unittest::default_sfixed64_extension_lite)); EXPECT_EQ(411, message.GetExtension(unittest::default_float_extension_lite)); EXPECT_EQ(412, message.GetExtension(unittest::default_double_extension_lite)); - EXPECT_FALSE(message.GetExtension(unittest::default_bool_extension_lite)); + EXPECT_EQ(false, message.GetExtension(unittest::default_bool_extension_lite)); EXPECT_EQ("415", message.GetExtension(unittest::default_string_extension_lite)); EXPECT_EQ("416", @@ -1429,7 +1428,8 @@ void TestUtilLite::ExpectExtensionsClear( message.GetExtension(unittest::optional_sfixed64_extension_lite)); EXPECT_EQ(0, message.GetExtension(unittest::optional_float_extension_lite)); EXPECT_EQ(0, message.GetExtension(unittest::optional_double_extension_lite)); - EXPECT_FALSE(message.GetExtension(unittest::optional_bool_extension_lite)); + EXPECT_EQ(false, + message.GetExtension(unittest::optional_bool_extension_lite)); EXPECT_EQ("", message.GetExtension(unittest::optional_string_extension_lite)); EXPECT_EQ("", message.GetExtension(unittest::optional_bytes_extension_lite)); @@ -1883,7 +1883,8 @@ void TestUtilLite::ExpectPackedExtensionsSet( message.GetExtension(unittest::packed_float_extension_lite, 1)); EXPECT_EQ(712, message.GetExtension(unittest::packed_double_extension_lite, 1)); - EXPECT_FALSE(message.GetExtension(unittest::packed_bool_extension_lite, 1)); + EXPECT_EQ(false, + message.GetExtension(unittest::packed_bool_extension_lite, 1)); EXPECT_EQ(unittest::FOREIGN_LITE_BAZ, message.GetExtension(unittest::packed_enum_extension_lite, 1)); } diff --git a/libs/protobuf/src/google/protobuf/test_util_lite.h b/libs/protobuf/src/google/protobuf/test_util_lite.h index 7ed6029..34edf94 100644 --- a/libs/protobuf/src/google/protobuf/test_util_lite.h +++ b/libs/protobuf/src/google/protobuf/test_util_lite.h @@ -35,7 +35,7 @@ #ifndef GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ #define GOOGLE_PROTOBUF_TEST_UTIL_LITE_H__ -#include "google/protobuf/unittest_lite.pb.h" +#include namespace google { namespace protobuf { @@ -45,8 +45,6 @@ namespace unittest_import = protobuf_unittest_import; class TestUtilLite { public: - TestUtilLite() = delete; - // Set every field in the message to a unique value. static void SetAllFields(unittest::TestAllTypesLite* message); static void SetAllExtensions(unittest::TestAllExtensionsLite* message); @@ -92,6 +90,9 @@ class TestUtilLite { static void ExpectPackedClear(const unittest::TestPackedTypesLite& message); static void ExpectPackedExtensionsClear( const unittest::TestPackedExtensionsLite& message); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TestUtilLite); }; } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/testing/BUILD.bazel b/libs/protobuf/src/google/protobuf/testing/BUILD.bazel deleted file mode 100644 index 20e37b6..0000000 --- a/libs/protobuf/src/google/protobuf/testing/BUILD.bazel +++ /dev/null @@ -1,42 +0,0 @@ -# Protobuf testing support. -# This package contains testonly utilities used in C++ unit tests. - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") - -package(default_visibility = ["//:__subpackages__"]) - -cc_library( - name = "testing", - testonly = 1, - srcs = [ - "file.cc", - "googletest.cc", - ], - hdrs = [ - "file.h", - "googletest.h", - ], - copts = COPTS, - include_prefix = "google/protobuf/testing", - linkopts = LINK_OPTS, - deps = [ - "//:protobuf_lite", # for ShutdownProtobufLibrary - "//src/google/protobuf/io", - "//src/google/protobuf/stubs:lite", - "@com_google_absl//absl/strings", - "@com_google_googletest//:gtest", - ], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**/*"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/testing/file.cc b/libs/protobuf/src/google/protobuf/testing/file.cc index c4acd4b..7b62887 100644 --- a/libs/protobuf/src/google/protobuf/testing/file.cc +++ b/libs/protobuf/src/google/protobuf/testing/file.cc @@ -31,8 +31,7 @@ // Author: kenton@google.com (Kenton Varda) // emulates google3/file/base/file.cc -#include "google/protobuf/testing/file.h" - +#include #include #include #include @@ -46,8 +45,8 @@ #endif #include -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/stubs/logging.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/testing/file.h b/libs/protobuf/src/google/protobuf/testing/file.h index 18348a6..f18f685 100644 --- a/libs/protobuf/src/google/protobuf/testing/file.h +++ b/libs/protobuf/src/google/protobuf/testing/file.h @@ -34,7 +34,7 @@ #ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__ #define GOOGLE_PROTOBUF_TESTING_FILE_H__ -#include "google/protobuf/stubs/common.h" +#include namespace google { namespace protobuf { @@ -45,9 +45,6 @@ const int DEFAULT_FILE_MODE = 0777; // in tests. class File { public: - File(const File&) = delete; - File& operator=(const File&) = delete; - // Check if the file exists. static bool Exists(const std::string& name); @@ -99,6 +96,9 @@ class File { bool /*is_default*/) { return WriteStringToFile(contents, name); } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(File); }; } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/testing/googletest.cc b/libs/protobuf/src/google/protobuf/testing/googletest.cc index 5f6a4fb..88343f9 100644 --- a/libs/protobuf/src/google/protobuf/testing/googletest.cc +++ b/libs/protobuf/src/google/protobuf/testing/googletest.cc @@ -31,18 +31,14 @@ // Author: kenton@google.com (Kenton Varda) // emulates google3/testing/base/public/googletest.cc -#include "google/protobuf/testing/googletest.h" - -#include -#include +#include +#include +#include +#include #include #include - -#include "absl/strings/match.h" -#include "absl/strings/str_replace.h" -#include "google/protobuf/io/io_win32.h" -#include "google/protobuf/stubs/strutil.h" -#include "google/protobuf/testing/file.h" +#include +#include #ifdef _MSC_VER // #include #else @@ -148,13 +144,13 @@ std::string GetTemporaryDirectoryName() { } // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed // to be used in the current working directory. WTF? - if (absl::StartsWith(result, "\\")) { + if (HasPrefixString(result, "\\")) { result.erase(0, 1); } // The Win32 API accepts forward slashes as a path delimiter as long as the // path doesn't use the "\\?\" prefix. // Let's avoid confusion and use only forward slashes. - result = absl::StrReplaceAll(result, {{"\\", "/"}}); + result = StringReplace(result, "\\", "/", true); #endif // _WIN32 return result; } diff --git a/libs/protobuf/src/google/protobuf/testing/googletest.h b/libs/protobuf/src/google/protobuf/testing/googletest.h index 87c8a41..6a0c694 100644 --- a/libs/protobuf/src/google/protobuf/testing/googletest.h +++ b/libs/protobuf/src/google/protobuf/testing/googletest.h @@ -34,14 +34,11 @@ #ifndef GOOGLE_PROTOBUF_GOOGLETEST_H__ #define GOOGLE_PROTOBUF_GOOGLETEST_H__ -#include - #include #include - -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" - +#include +#include +#include // Disable death tests if we use exceptions in CHECK(). #if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) && \ !GTEST_OS_WINDOWS @@ -84,8 +81,6 @@ static const LogLevel WARNING = LOGLEVEL_WARNING; class ScopedMemoryLog { public: ScopedMemoryLog(); - ScopedMemoryLog(const ScopedMemoryLog&) = delete; - ScopedMemoryLog& operator=(const ScopedMemoryLog&) = delete; virtual ~ScopedMemoryLog(); // Fetches all messages with the given severity level. @@ -99,6 +94,8 @@ class ScopedMemoryLog { const std::string& message); static ScopedMemoryLog* active_log_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ScopedMemoryLog); }; } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/testing/zcgunzip.cc b/libs/protobuf/src/google/protobuf/testing/zcgunzip.cc index facb1ca..68f8172 100644 --- a/libs/protobuf/src/google/protobuf/testing/zcgunzip.cc +++ b/libs/protobuf/src/google/protobuf/testing/zcgunzip.cc @@ -53,8 +53,8 @@ #endif #endif -#include "google/protobuf/io/gzip_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include using google::protobuf::io::FileInputStream; using google::protobuf::io::GzipInputStream; diff --git a/libs/protobuf/src/google/protobuf/testing/zcgzip.cc b/libs/protobuf/src/google/protobuf/testing/zcgzip.cc index 3ac2cf2..808d058 100644 --- a/libs/protobuf/src/google/protobuf/testing/zcgzip.cc +++ b/libs/protobuf/src/google/protobuf/testing/zcgzip.cc @@ -52,8 +52,8 @@ #endif #endif -#include "google/protobuf/io/gzip_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include using google::protobuf::io::FileOutputStream; using google::protobuf::io::GzipOutputStream; diff --git a/libs/protobuf/src/google/protobuf/text_format.cc b/libs/protobuf/src/google/protobuf/text_format.cc index 30132a1..05987d3 100644 --- a/libs/protobuf/src/google/protobuf/text_format.cc +++ b/libs/protobuf/src/google/protobuf/text_format.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/text_format.h" +#include #include #include @@ -42,34 +42,29 @@ #include #include #include -#include #include #include -#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/stubs/strutil.h" -#include "absl/strings/ascii.h" -#include "absl/strings/escaping.h" -#include "absl/strings/numbers.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_join.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/any.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/io/strtod.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -92,12 +87,6 @@ namespace internal { const char kDebugStringSilentMarker[] = ""; const char kDebugStringSilentMarkerForDetection[] = "\t "; -// Controls insertion of a marker making debug strings non-parseable. -PROTOBUF_EXPORT std::atomic enable_debug_text_redaction_marker; - -// Controls insertion of a randomized marker in debug strings. -PROTOBUF_EXPORT std::atomic enable_debug_text_random_marker; - // Controls insertion of kDebugStringSilentMarker. PROTOBUF_EXPORT std::atomic enable_debug_text_format_marker; } // namespace internal @@ -109,12 +98,6 @@ std::string Message::DebugString() const { printer.SetExpandAny(true); printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load( std::memory_order_relaxed)); - printer.SetRedactDebugString( - internal::enable_debug_text_redaction_marker.load( - std::memory_order_relaxed)); - printer.SetRandomizeDebugString( - internal::enable_debug_text_random_marker.load( - std::memory_order_relaxed)); printer.PrintToString(*this, &debug_string); @@ -129,12 +112,6 @@ std::string Message::ShortDebugString() const { printer.SetExpandAny(true); printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load( std::memory_order_relaxed)); - printer.SetRedactDebugString( - internal::enable_debug_text_redaction_marker.load( - std::memory_order_relaxed)); - printer.SetRandomizeDebugString( - internal::enable_debug_text_random_marker.load( - std::memory_order_relaxed)); printer.PrintToString(*this, &debug_string); // Single line mode currently might have an extra space at the end. @@ -153,12 +130,6 @@ std::string Message::Utf8DebugString() const { printer.SetExpandAny(true); printer.SetInsertSilentMarker(internal::enable_debug_text_format_marker.load( std::memory_order_relaxed)); - printer.SetRedactDebugString( - internal::enable_debug_text_redaction_marker.load( - std::memory_order_relaxed)); - printer.SetRandomizeDebugString( - internal::enable_debug_text_random_marker.load( - std::memory_order_relaxed)); printer.PrintToString(*this, &debug_string); @@ -204,13 +175,14 @@ TextFormat::ParseLocationRange TextFormat::ParseInfoTree::GetLocationRange( index = 0; } - auto it = locations_.find(field); - if (it == locations_.end() || - index >= static_cast(it->second.size())) { + const std::vector* locations = + FindOrNull(locations_, field); + if (locations == nullptr || + index >= static_cast(locations->size())) { return TextFormat::ParseLocationRange(); } - return it->second[static_cast(index)]; + return (*locations)[index]; } TextFormat::ParseInfoTree* TextFormat::ParseInfoTree::GetTreeForNested( @@ -225,7 +197,7 @@ TextFormat::ParseInfoTree* TextFormat::ParseInfoTree::GetTreeForNested( return nullptr; } - return it->second[static_cast(index)].get(); + return it->second[index].get(); } namespace { @@ -322,8 +294,6 @@ class TextFormat::Parser::ParserImpl { // Consume the starting token. tokenizer_.Next(); } - ParserImpl(const ParserImpl&) = delete; - ParserImpl& operator=(const ParserImpl&) = delete; ~ParserImpl() {} // Parses the ASCII representation specified in input and saves the @@ -398,6 +368,8 @@ class TextFormat::Parser::ParserImpl { static constexpr int64_t kint64max = std::numeric_limits::max(); static constexpr uint64_t kuint64max = std::numeric_limits::max(); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParserImpl); + // Reports an error with the given message with information indicating // the position (as derived from the current token). void ReportError(const std::string& message) { @@ -457,7 +429,7 @@ class TextFormat::Parser::ParserImpl { std::string full_type_name, prefix; DO(ConsumeAnyTypeUrl(&full_type_name, &prefix)); std::string prefix_and_full_type_name = - absl::StrCat(prefix, full_type_name); + StrCat(prefix, full_type_name); DO(ConsumeBeforeWhitespace("]")); TryConsumeWhitespace(); // ':' is optional between message labels and values. @@ -517,7 +489,7 @@ class TextFormat::Parser::ParserImpl { TryConsumeWhitespace(); int32_t field_number; - if (allow_field_number_ && absl::SimpleAtoi(field_name, &field_number)) { + if (allow_field_number_ && safe_strto32(field_name, &field_number)) { if (descriptor->IsExtensionNumber(field_number)) { field = finder_ ? finder_->FindExtensionByNumber(descriptor, field_number) @@ -535,7 +507,7 @@ class TextFormat::Parser::ParserImpl { // field names. if (field == nullptr) { std::string lower_field_name = field_name; - absl::AsciiStrToLower(&lower_field_name); + LowerString(&lower_field_name); field = descriptor->FindFieldByName(lower_field_name); // If the case-insensitive match worked but the field is NOT a group, if (field != nullptr && @@ -551,7 +523,7 @@ class TextFormat::Parser::ParserImpl { if (field == nullptr && allow_case_insensitive_field_) { std::string lower_field_name = field_name; - absl::AsciiStrToLower(&lower_field_name); + LowerString(&lower_field_name); field = descriptor->FindFieldByLowercaseName(lower_field_name); } @@ -723,7 +695,7 @@ class TextFormat::Parser::ParserImpl { const FieldDescriptor* field) { if (--recursion_limit_ < 0) { ReportError( - absl::StrCat("Message is too deep, the parser exceeded the " + StrCat("Message is too deep, the parser exceeded the " "configured recursion limit of ", initial_recursion_limit_, ".")); return false; @@ -759,7 +731,7 @@ class TextFormat::Parser::ParserImpl { bool SkipFieldMessage() { if (--recursion_limit_ < 0) { ReportError( - absl::StrCat("Message is too deep, the parser exceeded the " + StrCat("Message is too deep, the parser exceeded the " "configured recursion limit of ", initial_recursion_limit_, ".")); return false; @@ -873,7 +845,7 @@ class TextFormat::Parser::ParserImpl { } else if (LookingAt("-") || LookingAtType(io::Tokenizer::TYPE_INTEGER)) { DO(ConsumeSignedInteger(&int_value, kint32max)); - value = absl::StrCat(int_value); // for error reporting + value = StrCat(int_value); // for error reporting enum_value = enum_type->FindValueByNumber(int_value); } else { ReportError("Expected integer or identifier, got: " + @@ -919,7 +891,7 @@ class TextFormat::Parser::ParserImpl { bool SkipFieldValue() { if (--recursion_limit_ < 0) { ReportError( - absl::StrCat("Message is too deep, the parser exceeded the " + StrCat("Message is too deep, the parser exceeded the " "configured recursion limit of ", initial_recursion_limit_, ".")); return false; @@ -933,18 +905,16 @@ class TextFormat::Parser::ParserImpl { return true; } if (TryConsume("[")) { - if (!TryConsume("]")) { - while (true) { - if (!LookingAt("{") && !LookingAt("<")) { - DO(SkipFieldValue()); - } else { - DO(SkipFieldMessage()); - } - if (TryConsume("]")) { - break; - } - DO(Consume(",")); + while (true) { + if (!LookingAt("{") && !LookingAt("<")) { + DO(SkipFieldValue()); + } else { + DO(SkipFieldMessage()); } + if (TryConsume("]")) { + break; + } + DO(Consume(",")); } ++recursion_limit_; return true; @@ -987,7 +957,7 @@ class TextFormat::Parser::ParserImpl { // inf, inff, infinity, nan if (has_minus && LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { std::string text = tokenizer_.current().text; - absl::AsciiStrToLower(&text); + LowerString(&text); if (text != "inf" && text != "infinity" && text != "nan") { ReportError("Invalid float number: " + text); @@ -1192,7 +1162,7 @@ class TextFormat::Parser::ParserImpl { tokenizer_.Next(); } else if (LookingAtType(io::Tokenizer::TYPE_IDENTIFIER)) { std::string text = tokenizer_.current().text; - absl::AsciiStrToLower(&text); + LowerString(&text); if (text == "inf" || text == "infinity") { *value = std::numeric_limits::infinity(); @@ -1314,7 +1284,7 @@ class TextFormat::Parser::ParserImpl { had_silent_marker_ = false; if (LookingAtType(io::Tokenizer::TYPE_WHITESPACE)) { if (tokenizer_.current().text == - absl::StrCat(" ", internal::kDebugStringSilentMarkerForDetection)) { + StrCat(" ", internal::kDebugStringSilentMarkerForDetection)) { had_silent_marker_ = true; } tokenizer_.Next(); @@ -1330,8 +1300,6 @@ class TextFormat::Parser::ParserImpl { explicit ParserErrorCollector(TextFormat::Parser::ParserImpl* parser) : parser_(parser) {} - ParserErrorCollector(const ParserErrorCollector&) = delete; - ParserErrorCollector& operator=(const ParserErrorCollector&) = delete; ~ParserErrorCollector() override {} void AddError(int line, int column, const std::string& message) override { @@ -1343,6 +1311,7 @@ class TextFormat::Parser::ParserImpl { } private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParserErrorCollector); TextFormat::Parser::ParserImpl* parser_; }; @@ -1393,8 +1362,6 @@ class TextFormat::Printer::TextGenerator indent_level_(initial_indent_level), initial_indent_level_(initial_indent_level) {} - TextGenerator(const TextGenerator&) = delete; - TextGenerator& operator=(const TextGenerator&) = delete; ~TextGenerator() override { // Only BackUp() if we're sure we've successfully called Next() at least // once. @@ -1454,15 +1421,15 @@ class TextFormat::Printer::TextGenerator // error.) bool failed() const { return failed_; } - void PrintMaybeWithMarker(absl::string_view text) { + void PrintMaybeWithMarker(StringPiece text) { Print(text.data(), text.size()); if (ConsumeInsertSilentMarker()) { PrintLiteral(internal::kDebugStringSilentMarker); } } - void PrintMaybeWithMarker(absl::string_view text_head, - absl::string_view text_tail) { + void PrintMaybeWithMarker(StringPiece text_head, + StringPiece text_tail) { Print(text_head.data(), text_head.size()); if (ConsumeInsertSilentMarker()) { PrintLiteral(internal::kDebugStringSilentMarker); @@ -1471,6 +1438,8 @@ class TextFormat::Printer::TextGenerator } private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextGenerator); + void Write(const char* data, size_t size) { if (failed_) return; if (size == 0) return; @@ -1580,7 +1549,7 @@ class TextFormat::Printer::FastFieldValuePrinterUtf8Escaping void PrintString(const std::string& val, TextFormat::BaseTextGenerator* generator) const override { generator->PrintLiteral("\""); - generator->PrintString(absl::Utf8SafeCEscape(val)); + generator->PrintString(strings::Utf8SafeCEscape(val)); generator->PrintLiteral("\""); } void PrintBytes(const std::string& val, @@ -1634,12 +1603,12 @@ TextFormat::Parser::~Parser() {} namespace { -bool CheckParseInputSize(absl::string_view input, +bool CheckParseInputSize(StringPiece input, io::ErrorCollector* error_collector) { if (input.size() > INT_MAX) { error_collector->AddError( -1, 0, - absl::StrCat( + StrCat( "Input size too large: ", static_cast(input.size()), " bytes", " > ", INT_MAX, " bytes.")); return false; @@ -1666,7 +1635,7 @@ bool TextFormat::Parser::Parse(io::ZeroCopyInputStream* input, return MergeUsingImpl(input, output, &parser); } -bool TextFormat::Parser::ParseFromString(absl::string_view input, +bool TextFormat::Parser::ParseFromString(ConstStringParam input, Message* output) { DO(CheckParseInputSize(input, error_collector_)); io::ArrayInputStream input_stream(input.data(), input.size()); @@ -1684,7 +1653,7 @@ bool TextFormat::Parser::Merge(io::ZeroCopyInputStream* input, return MergeUsingImpl(input, output, &parser); } -bool TextFormat::Parser::MergeFromString(absl::string_view input, +bool TextFormat::Parser::MergeFromString(ConstStringParam input, Message* output) { DO(CheckParseInputSize(input, error_collector_)); io::ArrayInputStream input_stream(input.data(), input.size()); @@ -1700,7 +1669,7 @@ bool TextFormat::Parser::MergeUsingImpl(io::ZeroCopyInputStream* /* input */, output->FindInitializationErrors(&missing_fields); parser_impl->ReportError(-1, 0, "Message missing required fields: " + - absl::StrJoin(missing_fields, ", ")); + Join(missing_fields, ", ")); return false; } return true; @@ -1729,12 +1698,12 @@ bool TextFormat::Parser::ParseFieldValueFromString(const std::string& input, return Parser().Merge(input, output); } -/* static */ bool TextFormat::ParseFromString(absl::string_view input, +/* static */ bool TextFormat::ParseFromString(ConstStringParam input, Message* output) { return Parser().ParseFromString(input, output); } -/* static */ bool TextFormat::MergeFromString(absl::string_view input, +/* static */ bool TextFormat::MergeFromString(ConstStringParam input, Message* output) { return Parser().MergeFromString(input, output); } @@ -1850,19 +1819,19 @@ void TextFormat::FastFieldValuePrinter::PrintBool( } void TextFormat::FastFieldValuePrinter::PrintInt32( int32_t val, BaseTextGenerator* generator) const { - generator->PrintString(absl::StrCat(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintUInt32( uint32_t val, BaseTextGenerator* generator) const { - generator->PrintString(absl::StrCat(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintInt64( int64_t val, BaseTextGenerator* generator) const { - generator->PrintString(absl::StrCat(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintUInt64( uint64_t val, BaseTextGenerator* generator) const { - generator->PrintString(absl::StrCat(val)); + generator->PrintString(StrCat(val)); } void TextFormat::FastFieldValuePrinter::PrintFloat( float val, BaseTextGenerator* generator) const { @@ -1881,7 +1850,7 @@ void TextFormat::FastFieldValuePrinter::PrintEnum( void TextFormat::FastFieldValuePrinter::PrintString( const std::string& val, BaseTextGenerator* generator) const { generator->PrintLiteral("\""); - generator->PrintString(absl::CEscape(val)); + generator->PrintString(CEscape(val)); generator->PrintLiteral("\""); } void TextFormat::FastFieldValuePrinter::PrintBytes( @@ -2028,8 +1997,6 @@ TextFormat::Printer::Printer() use_field_number_(false), use_short_repeated_primitives_(false), insert_silent_marker_(false), - redact_debug_string_(false), - randomize_debug_string_(false), hide_unknown_fields_(false), print_message_fields_in_index_order_(false), expand_any_(false), @@ -2543,7 +2510,7 @@ void TextFormat::Printer::PrintFieldName(const Message& message, // if use_field_number_ is true, prints field number instead // of field name. if (use_field_number_) { - generator->PrintString(absl::StrCat(field->number())); + generator->PrintString(StrCat(field->number())); return; } @@ -2622,7 +2589,7 @@ void TextFormat::Printer::PrintFieldValue(const Message& message, // 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. - printer->PrintEnum(enum_value, absl::StrCat(enum_value), generator); + printer->PrintEnum(enum_value, StrCat(enum_value), generator); } break; } @@ -2672,13 +2639,13 @@ void TextFormat::Printer::PrintUnknownFields( int recursion_budget) const { for (int i = 0; i < unknown_fields.field_count(); i++) { const UnknownField& field = unknown_fields.field(i); - std::string field_number = absl::StrCat(field.number()); + std::string field_number = StrCat(field.number()); switch (field.type()) { case UnknownField::TYPE_VARINT: generator->PrintString(field_number); generator->PrintMaybeWithMarker(": "); - generator->PrintString(absl::StrCat(field.varint())); + generator->PrintString(StrCat(field.varint())); if (single_line_mode_) { generator->PrintLiteral(" "); } else { @@ -2689,7 +2656,7 @@ void TextFormat::Printer::PrintUnknownFields( generator->PrintString(field_number); generator->PrintMaybeWithMarker(": ", "0x"); generator->PrintString( - absl::StrCat(absl::Hex(field.fixed32(), absl::kZeroPad8))); + StrCat(strings::Hex(field.fixed32(), strings::ZERO_PAD_8))); if (single_line_mode_) { generator->PrintLiteral(" "); } else { @@ -2701,7 +2668,7 @@ void TextFormat::Printer::PrintUnknownFields( generator->PrintString(field_number); generator->PrintMaybeWithMarker(": ", "0x"); generator->PrintString( - absl::StrCat(absl::Hex(field.fixed64(), absl::kZeroPad16))); + StrCat(strings::Hex(field.fixed64(), strings::ZERO_PAD_16))); if (single_line_mode_) { generator->PrintLiteral(" "); } else { @@ -2741,7 +2708,7 @@ void TextFormat::Printer::PrintUnknownFields( // This field is not parseable as a Message (or we ran out of // recursion budget). So it is probably just a plain string. generator->PrintMaybeWithMarker(": ", "\""); - generator->PrintString(absl::CEscape(value)); + generator->PrintString(CEscape(value)); if (single_line_mode_) { generator->PrintLiteral("\" "); } else { @@ -2776,4 +2743,4 @@ void TextFormat::Printer::PrintUnknownFields( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/text_format.h b/libs/protobuf/src/google/protobuf/text_format.h index 7dc776e..e10bef7 100644 --- a/libs/protobuf/src/google/protobuf/text_format.h +++ b/libs/protobuf/src/google/protobuf/text_format.h @@ -39,22 +39,19 @@ #define GOOGLE_PROTOBUF_TEXT_FORMAT_H__ -#include #include #include #include #include -#include "google/protobuf/port.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -66,11 +63,6 @@ namespace protobuf { namespace internal { PROTOBUF_EXPORT extern const char kDebugStringSilentMarker[1]; PROTOBUF_EXPORT extern const char kDebugStringSilentMarkerForDetection[3]; - -PROTOBUF_EXPORT extern std::atomic enable_debug_text_redaction_marker; -PROTOBUF_EXPORT extern std::atomic enable_debug_text_random_marker; -PROTOBUF_EXPORT extern std::atomic enable_debug_text_format_marker; - } // namespace internal namespace io { @@ -84,9 +76,6 @@ class ErrorCollector; // tokenizer.h // This class is really a namespace that contains only static methods. class PROTOBUF_EXPORT TextFormat { public: - TextFormat(const TextFormat&) = delete; - TextFormat& operator=(const TextFormat&) = delete; - // Outputs a textual representation of the given message to the given // output stream. Returns false if printing fails. static bool Print(const Message& message, io::ZeroCopyOutputStream* output); @@ -142,8 +131,6 @@ class PROTOBUF_EXPORT TextFormat { class PROTOBUF_EXPORT FastFieldValuePrinter { public: FastFieldValuePrinter(); - FastFieldValuePrinter(const FastFieldValuePrinter&) = delete; - FastFieldValuePrinter& operator=(const FastFieldValuePrinter&) = delete; virtual ~FastFieldValuePrinter(); virtual void PrintBool(bool val, BaseTextGenerator* generator) const; virtual void PrintInt32(int32_t val, BaseTextGenerator* generator) const; @@ -180,14 +167,15 @@ class PROTOBUF_EXPORT TextFormat { 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 instead. class PROTOBUF_EXPORT FieldValuePrinter { public: FieldValuePrinter(); - FieldValuePrinter(const FieldValuePrinter&) = delete; - FieldValuePrinter& operator=(const FieldValuePrinter&) = delete; virtual ~FieldValuePrinter(); virtual std::string PrintBool(bool val) const; virtual std::string PrintInt32(int32_t val) const; @@ -211,16 +199,18 @@ class PROTOBUF_EXPORT TextFormat { private: FastFieldValuePrinter delegate_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldValuePrinter); }; class PROTOBUF_EXPORT MessagePrinter { public: MessagePrinter() {} - MessagePrinter(const MessagePrinter&) = delete; - MessagePrinter& operator=(const MessagePrinter&) = delete; virtual ~MessagePrinter() {} virtual void Print(const Message& message, bool single_line_mode, BaseTextGenerator* generator) const = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessagePrinter); }; // Interface that Printers or Parsers can use to find extensions, or types @@ -386,18 +376,9 @@ class PROTOBUF_EXPORT TextFormat { friend std::string Message::ShortDebugString() const; friend std::string Message::Utf8DebugString() const; - // Sets whether silent markers will be inserted. + // Sets whether *DebugString should insert a silent marker. void SetInsertSilentMarker(bool v) { insert_silent_marker_ = v; } - // Sets whether strings will be redacted and thus unparsable. - void SetRedactDebugString(bool redact) { redact_debug_string_ = redact; } - - // Sets whether the output string should be made non-deterministic. - // This discourages equality checks based on serialized string comparisons. - void SetRandomizeDebugString(bool randomize) { - randomize_debug_string_ = randomize; - } - // Forward declaration of an internal class used to print the text // output to the OutputStream (see text_format.cc for implementation). class TextGenerator; @@ -461,8 +442,6 @@ class PROTOBUF_EXPORT TextFormat { bool use_field_number_; bool use_short_repeated_primitives_; bool insert_silent_marker_; - bool redact_debug_string_; - bool randomize_debug_string_; bool hide_unknown_fields_; bool print_message_fields_in_index_order_; bool expand_any_; @@ -497,13 +476,13 @@ class PROTOBUF_EXPORT TextFormat { // google::protobuf::MessageLite::ParseFromString(). static bool Parse(io::ZeroCopyInputStream* input, Message* output); // Like Parse(), but reads directly from a string. - static bool ParseFromString(absl::string_view input, Message* output); + static bool ParseFromString(ConstStringParam input, Message* output); // Like Parse(), but the data is merged into the given message, as if // using Message::MergeFrom(). static bool Merge(io::ZeroCopyInputStream* input, Message* output); // Like Merge(), but reads directly from a string. - static bool MergeFromString(absl::string_view input, Message* output); + static bool MergeFromString(ConstStringParam input, Message* output); // Parse the given text as a single field value and store it into the // given field of the given message. If the field is a repeated field, @@ -592,11 +571,11 @@ class PROTOBUF_EXPORT TextFormat { // Like TextFormat::Parse(). bool Parse(io::ZeroCopyInputStream* input, Message* output); // Like TextFormat::ParseFromString(). - bool ParseFromString(absl::string_view input, Message* output); + bool ParseFromString(ConstStringParam input, Message* output); // Like TextFormat::Merge(). bool Merge(io::ZeroCopyInputStream* input, Message* output); // Like TextFormat::MergeFromString(). - bool MergeFromString(absl::string_view input, Message* output); + bool MergeFromString(ConstStringParam input, Message* output); // Set where to report parse errors. If nullptr (the default), errors will // be printed to stderr. @@ -691,6 +670,8 @@ class PROTOBUF_EXPORT TextFormat { ParseLocationRange location); static inline ParseInfoTree* CreateNested(ParseInfoTree* info_tree, const FieldDescriptor* field); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat); }; inline void TextFormat::RecordLocation(ParseInfoTree* info_tree, @@ -707,6 +688,6 @@ inline TextFormat::ParseInfoTree* TextFormat::CreateNested( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ diff --git a/libs/protobuf/src/google/protobuf/text_format_unittest.cc b/libs/protobuf/src/google/protobuf/text_format_unittest.cc index fa7cc63..126f2f3 100644 --- a/libs/protobuf/src/google/protobuf/text_format_unittest.cc +++ b/libs/protobuf/src/google/protobuf/text_format_unittest.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/text_format.h" +#include #include #include @@ -40,39 +40,40 @@ #include #include #include -#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/testing/file.h" -#include "google/protobuf/any.pb.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_mset.pb.h" -#include "google/protobuf/unittest_mset_wire_format.pb.h" -#include "google/protobuf/unittest_proto3.pb.h" -#include "google/protobuf/io/tokenizer.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_replace.h" -#include "absl/strings/substitute.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/test_util2.h" +#include +#include +#include +#include -#include "google/protobuf/stubs/strutil.h" // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { +namespace internal { +// Controls insertion of DEBUG_STRING_SILENT_MARKER. +extern PROTOBUF_EXPORT std::atomic enable_debug_text_format_marker; +} // namespace internal + // Can't use an anonymous namespace here due to brokenness of Tru64 compiler. namespace text_format_unittest { @@ -93,9 +94,10 @@ class TextFormatTest : public testing::Test { static void SetUpTestSuite() { GOOGLE_CHECK_OK(File::GetContents( TestUtil::GetTestDataPath( - "third_party/protobuf/" + "net/proto2/internal/" "testdata/text_format_unittest_data_oneof_implemented.txt"), &static_proto_text_format_, true)); + CleanStringLineEndings(&static_proto_text_format_, false); } TextFormatTest() : proto_text_format_(static_proto_text_format_) {} @@ -114,9 +116,10 @@ class TextFormatExtensionsTest : public testing::Test { public: static void SetUpTestSuite() { GOOGLE_CHECK_OK(File::GetContents( - TestUtil::GetTestDataPath("third_party/protobuf/testdata/" + TestUtil::GetTestDataPath("net/proto2/internal/testdata/" "text_format_unittest_extensions_data.txt"), &static_proto_text_format_, true)); + CleanStringLineEndings(&static_proto_text_format_, false); } TextFormatExtensionsTest() : proto_text_format_(static_proto_text_format_) {} @@ -152,7 +155,7 @@ TEST_F(TextFormatTest, ShortDebugString) { proto_.mutable_optional_foreign_message(); EXPECT_EQ(proto_.ShortDebugString(), - absl::StrCat("optional_int32: ", kDebugStringSilentMarker, + StrCat("optional_int32: ", kDebugStringSilentMarker, "1 " "optional_string: \"hello\" " "optional_nested_message { bb: 2 } " @@ -226,7 +229,7 @@ TEST_F(TextFormatTest, StringEscape) { // Hardcode a correct value to test against. std::string correct_string = - absl::StrCat("optional_string: ", kDebugStringSilentMarker, + StrCat("optional_string: ", kDebugStringSilentMarker, kEscapeTestStringEscaped, "\n"); // Compare. @@ -235,7 +238,7 @@ TEST_F(TextFormatTest, StringEscape) { // the protocol buffer contains no UTF-8 text. EXPECT_EQ(correct_string, utf8_debug_string); - std::string expected_short_debug_string = absl::StrCat( + std::string expected_short_debug_string = StrCat( "optional_string: ", kDebugStringSilentMarker, kEscapeTestStringEscaped); EXPECT_EQ(expected_short_debug_string, proto_.ShortDebugString()); } @@ -251,11 +254,11 @@ TEST_F(TextFormatTest, Utf8DebugString) { // Hardcode a correct value to test against. std::string correct_utf8_string = - absl::StrCat("optional_string: ", kDebugStringSilentMarker, + StrCat("optional_string: ", kDebugStringSilentMarker, "\"\350\260\267\346\255\214\"\n" "optional_bytes: \"\\350\\260\\267\\346\\255\\214\"\n"); std::string correct_string = - absl::StrCat("optional_string: ", kDebugStringSilentMarker, + StrCat("optional_string: ", kDebugStringSilentMarker, "\"\\350\\260\\267\\346\\255\\214\"\n" "optional_bytes: \"\\350\\260\\267\\346\\255\\214\"\n"); @@ -280,7 +283,7 @@ TEST_F(TextFormatTest, PrintUnknownFields) { unknown_fields->AddVarint(8, 2); unknown_fields->AddVarint(8, 3); - EXPECT_EQ(absl::StrCat("5: ", kDebugStringSilentMarker, + EXPECT_EQ(StrCat("5: ", kDebugStringSilentMarker, "1\n" "5: 0x00000002\n" "5: 0x0000000000000003\n" @@ -456,7 +459,7 @@ TEST_F(TextFormatTest, PrintBufferTooSmall) { class CustomUInt32FieldValuePrinter : public TextFormat::FieldValuePrinter { public: std::string PrintUInt32(uint32_t val) const override { - return absl::StrCat(FieldValuePrinter::PrintUInt32(val), "u"); + return StrCat(FieldValuePrinter::PrintUInt32(val), "u"); } }; @@ -480,7 +483,7 @@ TEST_F(TextFormatTest, DefaultCustomFieldPrinter) { class CustomInt32FieldValuePrinter : public TextFormat::FieldValuePrinter { public: std::string PrintInt32(int32_t val) const override { - return absl::StrCat("value-is(", FieldValuePrinter::PrintInt32(val), ")"); + return StrCat("value-is(", FieldValuePrinter::PrintInt32(val), ")"); } }; @@ -531,8 +534,8 @@ TEST_F(TextFormatTest, ErrorCasesRegisteringFieldValuePrinterShouldFail) { class CustomMessageFieldValuePrinter : public TextFormat::FieldValuePrinter { public: std::string PrintInt32(int32_t v) const override { - return absl::StrCat(FieldValuePrinter::PrintInt32(v), " # x", - absl::Hex(v)); + return StrCat(FieldValuePrinter::PrintInt32(v), " # x", + strings::Hex(v)); } std::string PrintMessageStart(const Message& message, int field_index, @@ -541,7 +544,7 @@ class CustomMessageFieldValuePrinter : public TextFormat::FieldValuePrinter { if (single_line_mode) { return " { "; } - return absl::StrCat(" { # ", message.GetDescriptor()->name(), ": ", + return StrCat(" { # ", message.GetDescriptor()->name(), ": ", field_index, "\n"); } }; @@ -587,7 +590,7 @@ class CustomMessageContentFieldValuePrinter TextFormat::BaseTextGenerator* generator) const override { if (message.ByteSizeLong() > 0) { generator->PrintString( - absl::Substitute("# REDACTED, $0 bytes\n", message.ByteSizeLong())); + strings::Substitute("# REDACTED, $0 bytes\n", message.ByteSizeLong())); } return true; } @@ -631,7 +634,7 @@ class CustomMultilineCommentPrinter : public TextFormat::FieldValuePrinter { std::string PrintMessageStart(const Message& message, int field_index, int field_count, bool single_line_comment) const override { - return absl::StrCat(" { # 1\n", " # 2\n"); + return StrCat(" { # 1\n", " # 2\n"); } }; @@ -814,7 +817,7 @@ TEST_F(TextFormatExtensionsTest, ParseExtensions) { TEST_F(TextFormatTest, ParseEnumFieldFromNumber) { // Create a parse string with a numerical value for an enum field. std::string parse_string = - absl::Substitute("optional_nested_enum: $0", unittest::TestAllTypes::BAZ); + strings::Substitute("optional_nested_enum: $0", unittest::TestAllTypes::BAZ); EXPECT_TRUE(TextFormat::ParseFromString(parse_string, &proto_)); EXPECT_TRUE(proto_.has_optional_nested_enum()); EXPECT_EQ(unittest::TestAllTypes::BAZ, proto_.optional_nested_enum()); @@ -823,7 +826,7 @@ TEST_F(TextFormatTest, ParseEnumFieldFromNumber) { TEST_F(TextFormatTest, ParseEnumFieldFromNegativeNumber) { ASSERT_LT(unittest::SPARSE_E, 0); std::string parse_string = - absl::Substitute("sparse_enum: $0", unittest::SPARSE_E); + strings::Substitute("sparse_enum: $0", unittest::SPARSE_E); unittest::SparseEnumMessage proto; EXPECT_TRUE(TextFormat::ParseFromString(parse_string, &proto)); EXPECT_TRUE(proto.has_sparse_enum()); @@ -842,7 +845,7 @@ TEST_F(TextFormatTest, PrintUnknownEnumFieldProto3) { proto.add_repeated_nested_enum( static_cast(-2147483648)); - EXPECT_EQ(absl::StrCat("repeated_nested_enum: ", kDebugStringSilentMarker, + EXPECT_EQ(StrCat("repeated_nested_enum: ", kDebugStringSilentMarker, "10\n" "repeated_nested_enum: -10\n" "repeated_nested_enum: 2147483647\n" @@ -1032,19 +1035,6 @@ TEST_F(TextFormatTest, ParseShortRepeatedConcatenatedWithEmpty) { EXPECT_EQ(4, proto_.repeatedgroup(1).a()); } -TEST_F(TextFormatTest, ParseShortRepeatedUnknownEmpty) { - std::string parse_string = - "repeated_string: \"before\"\n" - "unknown_field: []\n" - "repeated_string: \"after\"\n"; - TextFormat::Parser parser; - parser.AllowUnknownField(true); - - ASSERT_TRUE(parser.ParseFromString(parse_string, &proto_)); - - EXPECT_EQ(2, proto_.repeated_string_size()); -} - TEST_F(TextFormatTest, Comments) { // Test that comments are ignored. @@ -1079,8 +1069,10 @@ TEST_F(TextFormatTest, OptionalColon) { // Some platforms (e.g. Windows) insist on padding the exponent to three // digits when one or two would be just fine. -static std::string RemoveRedundantZeros(absl::string_view text) { - return absl::StrReplaceAll(text, {{"e+0", "e+"}, {"e-0", "e-"}}); +static std::string RemoveRedundantZeros(std::string text) { + text = StringReplace(text, "e+0", "e+", true); + text = StringReplace(text, "e-0", "e-", true); + return text; } TEST_F(TextFormatTest, PrintExotic) { @@ -1111,7 +1103,7 @@ TEST_F(TextFormatTest, PrintExotic) { // have this problem, so we switched to that instead. EXPECT_EQ( - absl::StrCat("repeated_int64: ", kDebugStringSilentMarker, + StrCat("repeated_int64: ", kDebugStringSilentMarker, "-9223372036854775808\n" "repeated_uint64: 18446744073709551615\n" "repeated_double: 123.456\n" @@ -1171,7 +1163,7 @@ TEST_F(TextFormatTest, PrintFloatPrecision) { message.add_repeated_double(1.2345678987654e100); message.add_repeated_double(1.23456789876543e100); - EXPECT_EQ(absl::StrCat("repeated_float: ", kDebugStringSilentMarker, + EXPECT_EQ(StrCat("repeated_float: ", kDebugStringSilentMarker, "1\n" "repeated_float: 1.2\n" "repeated_float: 1.23\n" @@ -1409,7 +1401,7 @@ class TextFormatParserTest : public testing::Test { parser_.RecordErrorsTo(&error_collector); EXPECT_EQ(expected_result, parser_.ParseFromString(input, proto)) << input << " -> " << proto->DebugString(); - EXPECT_EQ(absl::StrCat(line, ":", col, ": ", message, "\n"), + EXPECT_EQ(StrCat(line, ":", col, ": ", message, "\n"), error_collector.text_); parser_.RecordErrorsTo(nullptr); } @@ -1450,7 +1442,7 @@ class TextFormatParserTest : public testing::Test { // implements ErrorCollector ------------------------------------- void AddError(int line, int column, const std::string& message) override { - absl::SubstituteAndAppend(&text_, "$0:$1: $2\n", line + 1, column + 1, + strings::SubstituteAndAppend(&text_, "$0:$1: $2\n", line + 1, column + 1, message); } @@ -1644,7 +1636,7 @@ TEST_F(TextFormatParserTest, ParseFieldValueFromString) { // enum EXPECT_FIELD(nested_enum, unittest::TestAllTypes::BAR, "BAR"); EXPECT_FIELD(nested_enum, unittest::TestAllTypes::BAZ, - absl::StrCat(unittest::TestAllTypes::BAZ)); + StrCat(unittest::TestAllTypes::BAZ)); EXPECT_INVALID(nested_enum, "FOOBAR"); // message @@ -1912,12 +1904,12 @@ TEST_F(TextFormatParserTest, ParseDeprecatedField) { TEST_F(TextFormatParserTest, SetRecursionLimit) { const char* format = "child: { $0 }"; std::string input; - for (int i = 0; i < 100; ++i) input = absl::Substitute(format, input); + for (int i = 0; i < 100; ++i) input = strings::Substitute(format, input); unittest::NestedTestAllTypes message; ExpectSuccessAndTree(input, &message, nullptr); - input = absl::Substitute(format, input); + input = strings::Substitute(format, input); parser_.SetRecursionLimit(100); ExpectMessage(input, "Message is too deep, the parser exceeded the configured " @@ -1931,8 +1923,8 @@ TEST_F(TextFormatParserTest, SetRecursionLimit) { TEST_F(TextFormatParserTest, SetRecursionLimitUnknownFieldValue) { const char* format = "[$0]"; std::string input = "\"test_value\""; - for (int i = 0; i < 99; ++i) input = absl::Substitute(format, input); - std::string not_deep_input = absl::StrCat("unknown_nested_array: ", input); + for (int i = 0; i < 99; ++i) input = strings::Substitute(format, input); + std::string not_deep_input = StrCat("unknown_nested_array: ", input); parser_.AllowUnknownField(true); parser_.SetRecursionLimit(100); @@ -1940,8 +1932,8 @@ TEST_F(TextFormatParserTest, SetRecursionLimitUnknownFieldValue) { unittest::NestedTestAllTypes message; ExpectSuccessAndTree(not_deep_input, &message, nullptr); - input = absl::Substitute(format, input); - std::string deep_input = absl::StrCat("unknown_nested_array: ", input); + input = strings::Substitute(format, input); + std::string deep_input = StrCat("unknown_nested_array: ", input); ExpectMessage( deep_input, "WARNING:Message type \"protobuf_unittest.NestedTestAllTypes\" has no " @@ -1956,7 +1948,7 @@ TEST_F(TextFormatParserTest, SetRecursionLimitUnknownFieldValue) { TEST_F(TextFormatParserTest, SetRecursionLimitUnknownFieldMessage) { const char* format = "unknown_child: { $0 }"; std::string input; - for (int i = 0; i < 100; ++i) input = absl::Substitute(format, input); + for (int i = 0; i < 100; ++i) input = strings::Substitute(format, input); parser_.AllowUnknownField(true); parser_.SetRecursionLimit(100); @@ -1964,7 +1956,7 @@ TEST_F(TextFormatParserTest, SetRecursionLimitUnknownFieldMessage) { unittest::NestedTestAllTypes message; ExpectSuccessAndTree(input, &message, nullptr); - input = absl::Substitute(format, input); + input = strings::Substitute(format, input); ExpectMessage( input, "WARNING:Message type \"protobuf_unittest.NestedTestAllTypes\" has no " @@ -2285,4 +2277,4 @@ TEST(TextFormatFloatingPointTest, PreservesNegative0) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/timestamp.pb.cc b/libs/protobuf/src/google/protobuf/timestamp.pb.cc index a26f164..728a004 100644 --- a/libs/protobuf/src/google/protobuf/timestamp.pb.cc +++ b/libs/protobuf/src/google/protobuf/timestamp.pb.cc @@ -1,23 +1,25 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -#include "google/protobuf/timestamp.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Timestamp::Timestamp( ::_pbi::ConstantInitialized): _impl_{ @@ -25,88 +27,62 @@ PROTOBUF_CONSTEXPR Timestamp::Timestamp( , /*decltype(_impl_.nanos_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct TimestampDefaultTypeInternal { - PROTOBUF_CONSTEXPR TimestampDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR TimestampDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~TimestampDefaultTypeInternal() {} union { Timestamp _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TimestampDefaultTypeInternal _Timestamp_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TimestampDefaultTypeInternal _Timestamp_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto[1]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _impl_.seconds_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _impl_.nanos_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2ftimestamp_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Timestamp)}, +const uint32_t TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _impl_.seconds_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Timestamp, _impl_.nanos_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Timestamp)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Timestamp_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2ftimestamp_2eproto[] PROTOBUF_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\205\001\n\023com.google.protobufB" - "\016TimestampProtoP\001Z2google.golang.org/pro" - "tobuf/types/known/timestamppb\370\001\001\242\002\003GPB\252\002" - "\036Google.Protobuf.WellKnownTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ftimestamp_2eproto = { - false, - false, - 239, - descriptor_table_protodef_google_2fprotobuf_2ftimestamp_2eproto, - "google/protobuf/timestamp.proto", - &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once, - nullptr, - 0, - 1, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto, - file_level_service_descriptors_google_2fprotobuf_2ftimestamp_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Timestamp_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2ftimestamp_2eproto[] PROTOBUF_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\205\001\n\023com.google.protobufB" + "\016TimestampProtoP\001Z2google.golang.org/pro" + "tobuf/types/known/timestamppb\370\001\001\242\002\003GPB\252\002" + "\036Google.Protobuf.WellKnownTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ftimestamp_2eproto = { + false, false, 239, descriptor_table_protodef_google_2fprotobuf_2ftimestamp_2eproto, + "google/protobuf/timestamp.proto", + &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once, nullptr, 0, 1, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2ftimestamp_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto, file_level_enum_descriptors_google_2fprotobuf_2ftimestamp_2eproto, + file_level_service_descriptors_google_2fprotobuf_2ftimestamp_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ftimestamp_2eproto(&descriptor_table_google_2fprotobuf_2ftimestamp_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ftimestamp_2eproto(&descriptor_table_google_2fprotobuf_2ftimestamp_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class Timestamp::_Internal { @@ -120,9 +96,17 @@ Timestamp::Timestamp(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.Timestamp) } Timestamp::Timestamp(const Timestamp& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + Timestamp* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.seconds_){} + , decltype(_impl_.nanos_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::memcpy(&_impl_.seconds_, &from._impl_.seconds_, + static_cast(reinterpret_cast(&_impl_.nanos_) - + reinterpret_cast(&_impl_.seconds_)) + sizeof(_impl_.nanos_)); // @@protoc_insertion_point(copy_constructor:google.protobuf.Timestamp) } @@ -167,7 +151,6 @@ void Timestamp::Clear() { } const char* Timestamp::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -214,7 +197,6 @@ failure: uint8_t* Timestamp::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -240,7 +222,6 @@ uint8_t* Timestamp::_InternalSerialize( } size_t Timestamp::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Timestamp) size_t total_size = 0; @@ -271,7 +252,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Timestamp::GetClassData() cons void Timestamp::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Timestamp) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -309,11 +289,11 @@ void Timestamp::InternalSwap(Timestamp* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Timestamp::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftimestamp_2eproto_once, file_level_metadata_google_2fprotobuf_2ftimestamp_2eproto[0]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -322,5 +302,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Timestamp >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Timestamp >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/timestamp.pb.h b/libs/protobuf/src/google/protobuf/timestamp.pb.h index d752b99..540194b 100644 --- a/libs/protobuf/src/google/protobuf/timestamp.pb.h +++ b/libs/protobuf/src/google/protobuf/timestamp.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/timestamp.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ftimestamp_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,23 +43,19 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ftimestamp_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2ftimestamp_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ftimestamp_2eproto; PROTOBUF_NAMESPACE_OPEN class Timestamp; struct TimestampDefaultTypeInternal; PROTOBUF_EXPORT extern TimestampDefaultTypeInternal _Timestamp_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Timestamp* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Timestamp>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Timestamp* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Timestamp>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Timestamp final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Timestamp) */ { public: @@ -168,7 +159,7 @@ class PROTOBUF_EXPORT Timestamp final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Timestamp"; } protected: @@ -225,17 +216,12 @@ class PROTOBUF_EXPORT Timestamp final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Timestamp // int64 seconds = 1; @@ -250,7 +236,7 @@ inline int64_t Timestamp::seconds() const { return _internal_seconds(); } inline void Timestamp::_internal_set_seconds(int64_t value) { - + _impl_.seconds_ = value; } inline void Timestamp::set_seconds(int64_t value) { @@ -270,7 +256,7 @@ inline int32_t Timestamp::nanos() const { return _internal_nanos(); } inline void Timestamp::_internal_set_nanos(int32_t value) { - + _impl_.nanos_ = value; } inline void Timestamp::set_nanos(int32_t value) { @@ -279,15 +265,14 @@ inline void Timestamp::set_nanos(int32_t value) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftimestamp_2eproto diff --git a/libs/protobuf/src/google/protobuf/timestamp.proto b/libs/protobuf/src/google/protobuf/timestamp.proto index 184a18f..3b2df6d 100644 --- a/libs/protobuf/src/google/protobuf/timestamp.proto +++ b/libs/protobuf/src/google/protobuf/timestamp.proto @@ -90,6 +90,7 @@ option objc_class_prefix = "GPB"; // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) // .setNanos((int) ((millis % 1000) * 1000000)).build(); // +// // Example 5: Compute Timestamp from Java `Instant.now()`. // // Instant now = Instant.now(); @@ -98,6 +99,7 @@ option objc_class_prefix = "GPB"; // Timestamp.newBuilder().setSeconds(now.getEpochSecond()) // .setNanos(now.getNano()).build(); // +// // Example 6: Compute Timestamp from current time in Python. // // timestamp = Timestamp() @@ -130,6 +132,7 @@ option objc_class_prefix = "GPB"; // http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D // ) to obtain a formatter capable of generating timestamps in this format. // +// message Timestamp { // Represents seconds of UTC time since Unix epoch // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to diff --git a/libs/protobuf/src/google/protobuf/type.pb.cc b/libs/protobuf/src/google/protobuf/type.pb.cc index 096d52e..e29bbb8 100644 --- a/libs/protobuf/src/google/protobuf/type.pb.cc +++ b/libs/protobuf/src/google/protobuf/type.pb.cc @@ -1,23 +1,25 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -#include "google/protobuf/type.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR Type::Type( ::_pbi::ConstantInitialized): _impl_{ @@ -29,15 +31,14 @@ PROTOBUF_CONSTEXPR Type::Type( , /*decltype(_impl_.syntax_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct TypeDefaultTypeInternal { - PROTOBUF_CONSTEXPR TypeDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR TypeDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~TypeDefaultTypeInternal() {} union { Type _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TypeDefaultTypeInternal _Type_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TypeDefaultTypeInternal _Type_default_instance_; PROTOBUF_CONSTEXPR Field::Field( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.options_)*/{} @@ -52,15 +53,14 @@ PROTOBUF_CONSTEXPR Field::Field( , /*decltype(_impl_.packed_)*/false , /*decltype(_impl_._cached_size_)*/{}} {} struct FieldDefaultTypeInternal { - PROTOBUF_CONSTEXPR FieldDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FieldDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FieldDefaultTypeInternal() {} union { Field _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldDefaultTypeInternal _Field_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FieldDefaultTypeInternal _Field_default_instance_; PROTOBUF_CONSTEXPR Enum::Enum( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.enumvalue_)*/{} @@ -70,15 +70,14 @@ PROTOBUF_CONSTEXPR Enum::Enum( , /*decltype(_impl_.syntax_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct EnumDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumDefaultTypeInternal() {} union { Enum _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDefaultTypeInternal _Enum_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumDefaultTypeInternal _Enum_default_instance_; PROTOBUF_CONSTEXPR EnumValue::EnumValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.options_)*/{} @@ -86,204 +85,168 @@ PROTOBUF_CONSTEXPR EnumValue::EnumValue( , /*decltype(_impl_.number_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct EnumValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR EnumValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR EnumValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~EnumValueDefaultTypeInternal() {} union { EnumValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueDefaultTypeInternal _EnumValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 EnumValueDefaultTypeInternal _EnumValue_default_instance_; PROTOBUF_CONSTEXPR Option::Option( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_.value_)*/nullptr , /*decltype(_impl_._cached_size_)*/{}} {} struct OptionDefaultTypeInternal { - PROTOBUF_CONSTEXPR OptionDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR OptionDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~OptionDefaultTypeInternal() {} union { Option _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OptionDefaultTypeInternal _Option_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 OptionDefaultTypeInternal _Option_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2ftype_2eproto[5]; static const ::_pb::EnumDescriptor* file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[3]; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2ftype_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2ftype_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.fields_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.oneofs_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.source_context_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.syntax_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.kind_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.cardinality_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.number_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.type_url_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.oneof_index_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.packed_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.json_name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.default_value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.enumvalue_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.options_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.source_context_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.syntax_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.number_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.options_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _impl_.name_), - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _impl_.value_), -}; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2ftype_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Type)}, - { 14, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Field)}, - { 32, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Enum)}, - { 45, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValue)}, - { 56, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Option)}, +const uint32_t TableStruct_google_2fprotobuf_2ftype_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.fields_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.oneofs_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.source_context_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Type, _impl_.syntax_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.kind_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.cardinality_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.number_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.type_url_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.oneof_index_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.packed_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.json_name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Field, _impl_.default_value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.enumvalue_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.options_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.source_context_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Enum, _impl_.syntax_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.number_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::EnumValue, _impl_.options_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Option, _impl_.value_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Type)}, + { 12, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Field)}, + { 28, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Enum)}, + { 39, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::EnumValue)}, + { 48, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Option)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_Type_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Field_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Enum_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_EnumValue_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Option_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2ftype_2eproto[] PROTOBUF_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" - "\014\n\004name\030\001 \001(\t\022&\n\006fields\030\002 \003(\0132\026.google.p" - "rotobuf.Field\022\016\n\006oneofs\030\003 \003(\t\022(\n\007options" - "\030\004 \003(\0132\027.google.protobuf.Option\0226\n\016sourc" - "e_context\030\005 \001(\0132\036.google.protobuf.Source" - "Context\022\'\n\006syntax\030\006 \001(\0162\027.google.protobu" - "f.Syntax\"\325\005\n\005Field\022)\n\004kind\030\001 \001(\0162\033.googl" - "e.protobuf.Field.Kind\0227\n\013cardinality\030\002 \001" - "(\0162\".google.protobuf.Field.Cardinality\022\016" - "\n\006number\030\003 \001(\005\022\014\n\004name\030\004 \001(\t\022\020\n\010type_url" - "\030\006 \001(\t\022\023\n\013oneof_index\030\007 \001(\005\022\016\n\006packed\030\010 " - "\001(\010\022(\n\007options\030\t \003(\0132\027.google.protobuf.O" - "ption\022\021\n\tjson_name\030\n \001(\t\022\025\n\rdefault_valu" - "e\030\013 \001(\t\"\310\002\n\004Kind\022\020\n\014TYPE_UNKNOWN\020\000\022\017\n\013TY" - "PE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE_INT6" - "4\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020\005\022\020\n\014" - "TYPE_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\013TY" - "PE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_SFIXE" - "D32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SINT32\020" - "\021\022\017\n\013TYPE_SINT64\020\022\"t\n\013Cardinality\022\027\n\023CAR" - "DINALITY_UNKNOWN\020\000\022\030\n\024CARDINALITY_OPTION" - "AL\020\001\022\030\n\024CARDINALITY_REQUIRED\020\002\022\030\n\024CARDIN" - "ALITY_REPEATED\020\003\"\316\001\n\004Enum\022\014\n\004name\030\001 \001(\t\022" - "-\n\tenumvalue\030\002 \003(\0132\032.google.protobuf.Enu" - "mValue\022(\n\007options\030\003 \003(\0132\027.google.protobu" - "f.Option\0226\n\016source_context\030\004 \001(\0132\036.googl" - "e.protobuf.SourceContext\022\'\n\006syntax\030\005 \001(\016" - "2\027.google.protobuf.Syntax\"S\n\tEnumValue\022\014" - "\n\004name\030\001 \001(\t\022\016\n\006number\030\002 \001(\005\022(\n\007options\030" - "\003 \003(\0132\027.google.protobuf.Option\";\n\006Option" - "\022\014\n\004name\030\001 \001(\t\022#\n\005value\030\002 \001(\0132\024.google.p" - "rotobuf.Any*.\n\006Syntax\022\021\n\rSYNTAX_PROTO2\020\000" - "\022\021\n\rSYNTAX_PROTO3\020\001B{\n\023com.google.protob" - "ufB\tTypeProtoP\001Z-google.golang.org/proto" - "buf/types/known/typepb\370\001\001\242\002\003GPB\252\002\036Google" - ".Protobuf.WellKnownTypesb\006proto3" -}; -static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2ftype_2eproto_deps[2] = - { - &::descriptor_table_google_2fprotobuf_2fany_2eproto, - &::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto, -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2ftype_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ftype_2eproto = { - false, - false, - 1592, - descriptor_table_protodef_google_2fprotobuf_2ftype_2eproto, - "google/protobuf/type.proto", - &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, - descriptor_table_google_2fprotobuf_2ftype_2eproto_deps, - 2, - 5, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2ftype_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2ftype_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto, - file_level_service_descriptors_google_2fprotobuf_2ftype_2eproto, + &::PROTOBUF_NAMESPACE_ID::_Type_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Field_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Enum_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_EnumValue_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Option_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2ftype_2eproto[] PROTOBUF_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" + "\014\n\004name\030\001 \001(\t\022&\n\006fields\030\002 \003(\0132\026.google.p" + "rotobuf.Field\022\016\n\006oneofs\030\003 \003(\t\022(\n\007options" + "\030\004 \003(\0132\027.google.protobuf.Option\0226\n\016sourc" + "e_context\030\005 \001(\0132\036.google.protobuf.Source" + "Context\022\'\n\006syntax\030\006 \001(\0162\027.google.protobu" + "f.Syntax\"\325\005\n\005Field\022)\n\004kind\030\001 \001(\0162\033.googl" + "e.protobuf.Field.Kind\0227\n\013cardinality\030\002 \001" + "(\0162\".google.protobuf.Field.Cardinality\022\016" + "\n\006number\030\003 \001(\005\022\014\n\004name\030\004 \001(\t\022\020\n\010type_url" + "\030\006 \001(\t\022\023\n\013oneof_index\030\007 \001(\005\022\016\n\006packed\030\010 " + "\001(\010\022(\n\007options\030\t \003(\0132\027.google.protobuf.O" + "ption\022\021\n\tjson_name\030\n \001(\t\022\025\n\rdefault_valu" + "e\030\013 \001(\t\"\310\002\n\004Kind\022\020\n\014TYPE_UNKNOWN\020\000\022\017\n\013TY" + "PE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE_INT6" + "4\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020\005\022\020\n\014" + "TYPE_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\013TY" + "PE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_SFIXE" + "D32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SINT32\020" + "\021\022\017\n\013TYPE_SINT64\020\022\"t\n\013Cardinality\022\027\n\023CAR" + "DINALITY_UNKNOWN\020\000\022\030\n\024CARDINALITY_OPTION" + "AL\020\001\022\030\n\024CARDINALITY_REQUIRED\020\002\022\030\n\024CARDIN" + "ALITY_REPEATED\020\003\"\316\001\n\004Enum\022\014\n\004name\030\001 \001(\t\022" + "-\n\tenumvalue\030\002 \003(\0132\032.google.protobuf.Enu" + "mValue\022(\n\007options\030\003 \003(\0132\027.google.protobu" + "f.Option\0226\n\016source_context\030\004 \001(\0132\036.googl" + "e.protobuf.SourceContext\022\'\n\006syntax\030\005 \001(\016" + "2\027.google.protobuf.Syntax\"S\n\tEnumValue\022\014" + "\n\004name\030\001 \001(\t\022\016\n\006number\030\002 \001(\005\022(\n\007options\030" + "\003 \003(\0132\027.google.protobuf.Option\";\n\006Option" + "\022\014\n\004name\030\001 \001(\t\022#\n\005value\030\002 \001(\0132\024.google.p" + "rotobuf.Any*.\n\006Syntax\022\021\n\rSYNTAX_PROTO2\020\000" + "\022\021\n\rSYNTAX_PROTO3\020\001B{\n\023com.google.protob" + "ufB\tTypeProtoP\001Z-google.golang.org/proto" + "buf/types/known/typepb\370\001\001\242\002\003GPB\252\002\036Google" + ".Protobuf.WellKnownTypesb\006proto3" + ; +static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2ftype_2eproto_deps[2] = { + &::descriptor_table_google_2fprotobuf_2fany_2eproto, + &::descriptor_table_google_2fprotobuf_2fsource_5fcontext_2eproto, +}; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2ftype_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2ftype_2eproto = { + false, false, 1592, descriptor_table_protodef_google_2fprotobuf_2ftype_2eproto, + "google/protobuf/type.proto", + &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, descriptor_table_google_2fprotobuf_2ftype_2eproto_deps, 2, 5, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2ftype_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2ftype_2eproto, file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto, + file_level_service_descriptors_google_2fprotobuf_2ftype_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2ftype_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2ftype_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ftype_2eproto(&descriptor_table_google_2fprotobuf_2ftype_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2ftype_2eproto(&descriptor_table_google_2fprotobuf_2ftype_2eproto); PROTOBUF_NAMESPACE_OPEN const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Kind_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2ftype_2eproto); @@ -315,9 +278,8 @@ bool Field_Kind_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr Field_Kind Field::TYPE_UNKNOWN; constexpr Field_Kind Field::TYPE_DOUBLE; constexpr Field_Kind Field::TYPE_FLOAT; @@ -340,9 +302,7 @@ constexpr Field_Kind Field::TYPE_SINT64; constexpr Field_Kind Field::Kind_MIN; constexpr Field_Kind Field::Kind_MAX; constexpr int Field::Kind_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Cardinality_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2ftype_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[1]; @@ -358,9 +318,8 @@ bool Field_Cardinality_IsValid(int value) { return false; } } -#if (__cplusplus < 201703) && \ - (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#if (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) constexpr Field_Cardinality Field::CARDINALITY_UNKNOWN; constexpr Field_Cardinality Field::CARDINALITY_OPTIONAL; constexpr Field_Cardinality Field::CARDINALITY_REQUIRED; @@ -368,9 +327,7 @@ constexpr Field_Cardinality Field::CARDINALITY_REPEATED; constexpr Field_Cardinality Field::Cardinality_MIN; constexpr Field_Cardinality Field::Cardinality_MAX; constexpr int Field::Cardinality_ARRAYSIZE; - -#endif // (__cplusplus < 201703) && - // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +#endif // (__cplusplus < 201703) && (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Syntax_descriptor() { ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_google_2fprotobuf_2ftype_2eproto); return file_level_enum_descriptors_google_2fprotobuf_2ftype_2eproto[2]; @@ -384,6 +341,8 @@ bool Syntax_IsValid(int value) { return false; } } + + // =================================================================== class Type::_Internal { @@ -495,7 +454,6 @@ void Type::Clear() { } const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -563,7 +521,7 @@ const char* Type::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Syntax syntax = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 48)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); } else @@ -594,7 +552,6 @@ failure: uint8_t* Type::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -658,7 +615,6 @@ uint8_t* Type::_InternalSerialize( } size_t Type::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Type) size_t total_size = 0; @@ -721,7 +677,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Type::GetClassData() const { r void Type::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Type) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -775,11 +730,11 @@ void Type::InternalSwap(Type* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Type::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, file_level_metadata_google_2fprotobuf_2ftype_2eproto[0]); } + // =================================================================== class Field::_Internal { @@ -922,7 +877,6 @@ void Field::Clear() { } const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -931,7 +885,7 @@ const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Field.Kind kind = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 8)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_kind(static_cast<::PROTOBUF_NAMESPACE_ID::Field_Kind>(val)); } else @@ -940,7 +894,7 @@ const char* Field::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Field.Cardinality cardinality = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_cardinality(static_cast<::PROTOBUF_NAMESPACE_ID::Field_Cardinality>(val)); } else @@ -1048,7 +1002,6 @@ failure: uint8_t* Field::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1142,7 +1095,6 @@ uint8_t* Field::_InternalSerialize( } size_t Field::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Field) size_t total_size = 0; @@ -1225,7 +1177,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Field::GetClassData() const { void Field::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Field) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1304,11 +1255,11 @@ void Field::InternalSwap(Field* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Field::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, file_level_metadata_google_2fprotobuf_2ftype_2eproto[1]); } + // =================================================================== class Enum::_Internal { @@ -1416,7 +1367,6 @@ void Enum::Clear() { } const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1469,7 +1419,7 @@ const char* Enum::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { // .google.protobuf.Syntax syntax = 5; case 5: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 40)) { - uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); CHK_(ptr); _internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val)); } else @@ -1500,7 +1450,6 @@ failure: uint8_t* Enum::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1554,7 +1503,6 @@ uint8_t* Enum::_InternalSerialize( } size_t Enum::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Enum) size_t total_size = 0; @@ -1609,7 +1557,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Enum::GetClassData() const { r void Enum::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Enum) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1661,11 +1608,11 @@ void Enum::InternalSwap(Enum* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Enum::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, file_level_metadata_google_2fprotobuf_2ftype_2eproto[2]); } + // =================================================================== class EnumValue::_Internal { @@ -1748,7 +1695,6 @@ void EnumValue::Clear() { } const char* EnumValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1810,7 +1756,6 @@ failure: uint8_t* EnumValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1848,7 +1793,6 @@ uint8_t* EnumValue::_InternalSerialize( } size_t EnumValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValue) size_t total_size = 0; @@ -1888,7 +1832,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*EnumValue::GetClassData() cons void EnumValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.EnumValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1929,11 +1872,11 @@ void EnumValue::InternalSwap(EnumValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata EnumValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, file_level_metadata_google_2fprotobuf_2ftype_2eproto[3]); } + // =================================================================== class Option::_Internal { @@ -2029,7 +1972,6 @@ void Option::Clear() { } const char* Option::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -2078,7 +2020,6 @@ failure: uint8_t* Option::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -2109,7 +2050,6 @@ uint8_t* Option::_InternalSerialize( } size_t Option::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Option) size_t total_size = 0; @@ -2144,7 +2084,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Option::GetClassData() const { void Option::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -2184,11 +2123,11 @@ void Option::InternalSwap(Option* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Option::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2ftype_2eproto_getter, &descriptor_table_google_2fprotobuf_2ftype_2eproto_once, file_level_metadata_google_2fprotobuf_2ftype_2eproto[4]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -2213,5 +2152,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::Option >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::Option >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/type.pb.h b/libs/protobuf/src/google/protobuf/type.pb.h index 423cede..cb8105a 100644 --- a/libs/protobuf/src/google/protobuf/type.pb.h +++ b/libs/protobuf/src/google/protobuf/type.pb.h @@ -1,46 +1,41 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/type.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/any.pb.h" -#include "google/protobuf/source_context.pb.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +#include +#include +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2ftype_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -51,8 +46,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2ftype_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2ftype_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2ftype_2eproto; PROTOBUF_NAMESPACE_OPEN class Enum; struct EnumDefaultTypeInternal; @@ -69,19 +63,16 @@ PROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_; class Type; struct TypeDefaultTypeInternal; PROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Enum* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Enum>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Field* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Field>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Option* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Option>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Type* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Type>(Arena*); PROTOBUF_NAMESPACE_CLOSE - PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Enum* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Enum>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::EnumValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::EnumValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Field* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Field>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Option* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Option>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Type* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Type>(Arena*); +PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_OPEN + enum Field_Kind : int { Field_Kind_TYPE_UNKNOWN = 0, Field_Kind_TYPE_DOUBLE = 1, @@ -102,107 +93,82 @@ enum Field_Kind : int { Field_Kind_TYPE_SFIXED64 = 16, Field_Kind_TYPE_SINT32 = 17, Field_Kind_TYPE_SINT64 = 18, - Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), - Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), + Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; - PROTOBUF_EXPORT bool Field_Kind_IsValid(int value); -constexpr Field_Kind Field_Kind_Kind_MIN = static_cast(0); -constexpr Field_Kind Field_Kind_Kind_MAX = static_cast(18); -constexpr int Field_Kind_Kind_ARRAYSIZE = 18 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -Field_Kind_descriptor(); -template -const std::string& Field_Kind_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Kind_Name()."); - return Field_Kind_Name(static_cast(value)); +constexpr Field_Kind Field_Kind_Kind_MIN = Field_Kind_TYPE_UNKNOWN; +constexpr Field_Kind Field_Kind_Kind_MAX = Field_Kind_TYPE_SINT64; +constexpr int Field_Kind_Kind_ARRAYSIZE = Field_Kind_Kind_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Kind_descriptor(); +template +inline const std::string& Field_Kind_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Field_Kind_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + Field_Kind_descriptor(), enum_t_value); } -template <> -inline const std::string& Field_Kind_Name(Field_Kind value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool Field_Kind_Parse(absl::string_view name, Field_Kind* value) { +inline bool Field_Kind_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, Field_Kind* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - Field_Kind_descriptor(), name, value); + Field_Kind_descriptor(), name, value); } enum Field_Cardinality : int { Field_Cardinality_CARDINALITY_UNKNOWN = 0, Field_Cardinality_CARDINALITY_OPTIONAL = 1, Field_Cardinality_CARDINALITY_REQUIRED = 2, Field_Cardinality_CARDINALITY_REPEATED = 3, - Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), - Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), + Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; - PROTOBUF_EXPORT bool Field_Cardinality_IsValid(int value); -constexpr Field_Cardinality Field_Cardinality_Cardinality_MIN = static_cast(0); -constexpr Field_Cardinality Field_Cardinality_Cardinality_MAX = static_cast(3); -constexpr int Field_Cardinality_Cardinality_ARRAYSIZE = 3 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -Field_Cardinality_descriptor(); -template -const std::string& Field_Cardinality_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Cardinality_Name()."); - return Field_Cardinality_Name(static_cast(value)); +constexpr Field_Cardinality Field_Cardinality_Cardinality_MIN = Field_Cardinality_CARDINALITY_UNKNOWN; +constexpr Field_Cardinality Field_Cardinality_Cardinality_MAX = Field_Cardinality_CARDINALITY_REPEATED; +constexpr int Field_Cardinality_Cardinality_ARRAYSIZE = Field_Cardinality_Cardinality_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Field_Cardinality_descriptor(); +template +inline const std::string& Field_Cardinality_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Field_Cardinality_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + Field_Cardinality_descriptor(), enum_t_value); } -template <> -inline const std::string& Field_Cardinality_Name(Field_Cardinality value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool Field_Cardinality_Parse(absl::string_view name, Field_Cardinality* value) { +inline bool Field_Cardinality_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, Field_Cardinality* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - Field_Cardinality_descriptor(), name, value); + Field_Cardinality_descriptor(), name, value); } enum Syntax : int { SYNTAX_PROTO2 = 0, SYNTAX_PROTO3 = 1, - Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::min(), - Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ = - std::numeric_limits::max(), + Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits::min(), + Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits::max() }; - PROTOBUF_EXPORT bool Syntax_IsValid(int value); -constexpr Syntax Syntax_MIN = static_cast(0); -constexpr Syntax Syntax_MAX = static_cast(1); -constexpr int Syntax_ARRAYSIZE = 1 + 1; -PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* -Syntax_descriptor(); -template -const std::string& Syntax_Name(T value) { - static_assert(std::is_same::value || - std::is_integral::value, - "Incorrect type passed to Syntax_Name()."); - return Syntax_Name(static_cast(value)); +constexpr Syntax Syntax_MIN = SYNTAX_PROTO2; +constexpr Syntax Syntax_MAX = SYNTAX_PROTO3; +constexpr int Syntax_ARRAYSIZE = Syntax_MAX + 1; + +PROTOBUF_EXPORT const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Syntax_descriptor(); +template +inline const std::string& Syntax_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Syntax_Name."); + return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum( + Syntax_descriptor(), enum_t_value); } -template <> -inline const std::string& Syntax_Name(Syntax value) { - return ::PROTOBUF_NAMESPACE_ID::internal::NameOfDenseEnum( - static_cast(value)); -} -inline bool Syntax_Parse(absl::string_view name, Syntax* value) { +inline bool Syntax_Parse( + ::PROTOBUF_NAMESPACE_ID::ConstStringParam name, Syntax* value) { return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum( - Syntax_descriptor(), name, value); + Syntax_descriptor(), name, value); } - // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT Type final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Type) */ { public: @@ -306,7 +272,7 @@ class PROTOBUF_EXPORT Type final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Type"; } protected: @@ -450,7 +416,8 @@ class PROTOBUF_EXPORT Type final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2ftype_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Field final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Field) */ { @@ -555,7 +522,7 @@ class PROTOBUF_EXPORT Field final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Field"; } protected: @@ -570,62 +537,101 @@ class PROTOBUF_EXPORT Field final : // nested types ---------------------------------------------------- - using Kind = Field_Kind; - static constexpr Kind TYPE_UNKNOWN = Field_Kind_TYPE_UNKNOWN; - static constexpr Kind TYPE_DOUBLE = Field_Kind_TYPE_DOUBLE; - static constexpr Kind TYPE_FLOAT = Field_Kind_TYPE_FLOAT; - static constexpr Kind TYPE_INT64 = Field_Kind_TYPE_INT64; - static constexpr Kind TYPE_UINT64 = Field_Kind_TYPE_UINT64; - static constexpr Kind TYPE_INT32 = Field_Kind_TYPE_INT32; - static constexpr Kind TYPE_FIXED64 = Field_Kind_TYPE_FIXED64; - static constexpr Kind TYPE_FIXED32 = Field_Kind_TYPE_FIXED32; - static constexpr Kind TYPE_BOOL = Field_Kind_TYPE_BOOL; - static constexpr Kind TYPE_STRING = Field_Kind_TYPE_STRING; - static constexpr Kind TYPE_GROUP = Field_Kind_TYPE_GROUP; - static constexpr Kind TYPE_MESSAGE = Field_Kind_TYPE_MESSAGE; - static constexpr Kind TYPE_BYTES = Field_Kind_TYPE_BYTES; - static constexpr Kind TYPE_UINT32 = Field_Kind_TYPE_UINT32; - static constexpr Kind TYPE_ENUM = Field_Kind_TYPE_ENUM; - static constexpr Kind TYPE_SFIXED32 = Field_Kind_TYPE_SFIXED32; - static constexpr Kind TYPE_SFIXED64 = Field_Kind_TYPE_SFIXED64; - static constexpr Kind TYPE_SINT32 = Field_Kind_TYPE_SINT32; - static constexpr Kind TYPE_SINT64 = Field_Kind_TYPE_SINT64; + typedef Field_Kind Kind; + static constexpr Kind TYPE_UNKNOWN = + Field_Kind_TYPE_UNKNOWN; + static constexpr Kind TYPE_DOUBLE = + Field_Kind_TYPE_DOUBLE; + static constexpr Kind TYPE_FLOAT = + Field_Kind_TYPE_FLOAT; + static constexpr Kind TYPE_INT64 = + Field_Kind_TYPE_INT64; + static constexpr Kind TYPE_UINT64 = + Field_Kind_TYPE_UINT64; + static constexpr Kind TYPE_INT32 = + Field_Kind_TYPE_INT32; + static constexpr Kind TYPE_FIXED64 = + Field_Kind_TYPE_FIXED64; + static constexpr Kind TYPE_FIXED32 = + Field_Kind_TYPE_FIXED32; + static constexpr Kind TYPE_BOOL = + Field_Kind_TYPE_BOOL; + static constexpr Kind TYPE_STRING = + Field_Kind_TYPE_STRING; + static constexpr Kind TYPE_GROUP = + Field_Kind_TYPE_GROUP; + static constexpr Kind TYPE_MESSAGE = + Field_Kind_TYPE_MESSAGE; + static constexpr Kind TYPE_BYTES = + Field_Kind_TYPE_BYTES; + static constexpr Kind TYPE_UINT32 = + Field_Kind_TYPE_UINT32; + static constexpr Kind TYPE_ENUM = + Field_Kind_TYPE_ENUM; + static constexpr Kind TYPE_SFIXED32 = + Field_Kind_TYPE_SFIXED32; + static constexpr Kind TYPE_SFIXED64 = + Field_Kind_TYPE_SFIXED64; + static constexpr Kind TYPE_SINT32 = + Field_Kind_TYPE_SINT32; + static constexpr Kind TYPE_SINT64 = + Field_Kind_TYPE_SINT64; static inline bool Kind_IsValid(int value) { return Field_Kind_IsValid(value); } - static constexpr Kind Kind_MIN = Field_Kind_Kind_MIN; - static constexpr Kind Kind_MAX = Field_Kind_Kind_MAX; - static constexpr int Kind_ARRAYSIZE = Field_Kind_Kind_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Kind_descriptor() { + static constexpr Kind Kind_MIN = + Field_Kind_Kind_MIN; + static constexpr Kind Kind_MAX = + Field_Kind_Kind_MAX; + static constexpr int Kind_ARRAYSIZE = + Field_Kind_Kind_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + Kind_descriptor() { return Field_Kind_descriptor(); } - template - static inline const std::string& Kind_Name(T value) { - return Field_Kind_Name(value); + template + static inline const std::string& Kind_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Kind_Name."); + return Field_Kind_Name(enum_t_value); } - static inline bool Kind_Parse(absl::string_view name, Kind* value) { + static inline bool Kind_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + Kind* value) { return Field_Kind_Parse(name, value); } - using Cardinality = Field_Cardinality; - static constexpr Cardinality CARDINALITY_UNKNOWN = Field_Cardinality_CARDINALITY_UNKNOWN; - static constexpr Cardinality CARDINALITY_OPTIONAL = Field_Cardinality_CARDINALITY_OPTIONAL; - static constexpr Cardinality CARDINALITY_REQUIRED = Field_Cardinality_CARDINALITY_REQUIRED; - static constexpr Cardinality CARDINALITY_REPEATED = Field_Cardinality_CARDINALITY_REPEATED; + typedef Field_Cardinality Cardinality; + static constexpr Cardinality CARDINALITY_UNKNOWN = + Field_Cardinality_CARDINALITY_UNKNOWN; + static constexpr Cardinality CARDINALITY_OPTIONAL = + Field_Cardinality_CARDINALITY_OPTIONAL; + static constexpr Cardinality CARDINALITY_REQUIRED = + Field_Cardinality_CARDINALITY_REQUIRED; + static constexpr Cardinality CARDINALITY_REPEATED = + Field_Cardinality_CARDINALITY_REPEATED; static inline bool Cardinality_IsValid(int value) { return Field_Cardinality_IsValid(value); } - static constexpr Cardinality Cardinality_MIN = Field_Cardinality_Cardinality_MIN; - static constexpr Cardinality Cardinality_MAX = Field_Cardinality_Cardinality_MAX; - static constexpr int Cardinality_ARRAYSIZE = Field_Cardinality_Cardinality_ARRAYSIZE; - static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* Cardinality_descriptor() { + static constexpr Cardinality Cardinality_MIN = + Field_Cardinality_Cardinality_MIN; + static constexpr Cardinality Cardinality_MAX = + Field_Cardinality_Cardinality_MAX; + static constexpr int Cardinality_ARRAYSIZE = + Field_Cardinality_Cardinality_ARRAYSIZE; + static inline const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* + Cardinality_descriptor() { return Field_Cardinality_descriptor(); } - template - static inline const std::string& Cardinality_Name(T value) { - return Field_Cardinality_Name(value); + template + static inline const std::string& Cardinality_Name(T enum_t_value) { + static_assert(::std::is_same::value || + ::std::is_integral::value, + "Incorrect type passed to function Cardinality_Name."); + return Field_Cardinality_Name(enum_t_value); } - static inline bool Cardinality_Parse(absl::string_view name, Cardinality* value) { + static inline bool Cardinality_Parse(::PROTOBUF_NAMESPACE_ID::ConstStringParam name, + Cardinality* value) { return Field_Cardinality_Parse(name, value); } @@ -784,7 +790,8 @@ class PROTOBUF_EXPORT Field final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2ftype_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Enum final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Enum) */ { @@ -889,7 +896,7 @@ class PROTOBUF_EXPORT Enum final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Enum"; } protected: @@ -1007,7 +1014,8 @@ class PROTOBUF_EXPORT Enum final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2ftype_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT EnumValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValue) */ { @@ -1112,7 +1120,7 @@ class PROTOBUF_EXPORT EnumValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.EnumValue"; } protected: @@ -1190,7 +1198,8 @@ class PROTOBUF_EXPORT EnumValue final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2ftype_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Option final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Option) */ { @@ -1295,7 +1304,7 @@ class PROTOBUF_EXPORT Option final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Option"; } protected: @@ -1366,17 +1375,12 @@ class PROTOBUF_EXPORT Option final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // Type // string name = 1; @@ -1403,11 +1407,11 @@ inline const std::string& Type::_internal_name() const { return _impl_.name_.Get(); } inline void Type::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Type::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Type::release_name() { @@ -1415,6 +1419,11 @@ inline std::string* Type::release_name() { return _impl_.name_.Release(); } inline void Type::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -1499,7 +1508,8 @@ inline void Type::set_oneofs(int index, std::string&& value) { // @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs) } inline void Type::set_oneofs(int index, const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Mutable(index)->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.oneofs_.Mutable(index)->assign(value); // @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs) } inline void Type::set_oneofs(int index, const char* value, size_t size) { @@ -1519,7 +1529,8 @@ inline void Type::add_oneofs(std::string&& value) { // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs) } inline void Type::add_oneofs(const char* value) { - GOOGLE_DCHECK(value != nullptr); _impl_.oneofs_.Add()->assign(value); + GOOGLE_DCHECK(value != nullptr); + _impl_.oneofs_.Add()->assign(value); // @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs) } inline void Type::add_oneofs(const char* value, size_t size) { @@ -1599,6 +1610,11 @@ inline void Type::unsafe_arena_set_allocated_source_context( delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_); } _impl_.source_context_ = source_context; + if (source_context) { + + } else { + + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.source_context) } inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Type::release_source_context() { @@ -1649,9 +1665,9 @@ inline void Type::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCo source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.source_context) @@ -1733,7 +1749,7 @@ inline int32_t Field::number() const { return _internal_number(); } inline void Field::_internal_set_number(int32_t value) { - + _impl_.number_ = value; } inline void Field::set_number(int32_t value) { @@ -1765,11 +1781,11 @@ inline const std::string& Field::_internal_name() const { return _impl_.name_.Get(); } inline void Field::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_name() { @@ -1777,6 +1793,11 @@ inline std::string* Field::release_name() { return _impl_.name_.Release(); } inline void Field::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -1810,11 +1831,11 @@ inline const std::string& Field::_internal_type_url() const { return _impl_.type_url_.Get(); } inline void Field::_internal_set_type_url(const std::string& value) { - + _impl_.type_url_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_type_url() { - + return _impl_.type_url_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_type_url() { @@ -1822,6 +1843,11 @@ inline std::string* Field::release_type_url() { return _impl_.type_url_.Release(); } inline void Field::set_allocated_type_url(std::string* type_url) { + if (type_url != nullptr) { + + } else { + + } _impl_.type_url_.SetAllocated(type_url, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.type_url_.IsDefault()) { @@ -1843,7 +1869,7 @@ inline int32_t Field::oneof_index() const { return _internal_oneof_index(); } inline void Field::_internal_set_oneof_index(int32_t value) { - + _impl_.oneof_index_ = value; } inline void Field::set_oneof_index(int32_t value) { @@ -1863,7 +1889,7 @@ inline bool Field::packed() const { return _internal_packed(); } inline void Field::_internal_set_packed(bool value) { - + _impl_.packed_ = value; } inline void Field::set_packed(bool value) { @@ -1935,11 +1961,11 @@ inline const std::string& Field::_internal_json_name() const { return _impl_.json_name_.Get(); } inline void Field::_internal_set_json_name(const std::string& value) { - + _impl_.json_name_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_json_name() { - + return _impl_.json_name_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_json_name() { @@ -1947,6 +1973,11 @@ inline std::string* Field::release_json_name() { return _impl_.json_name_.Release(); } inline void Field::set_allocated_json_name(std::string* json_name) { + if (json_name != nullptr) { + + } else { + + } _impl_.json_name_.SetAllocated(json_name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.json_name_.IsDefault()) { @@ -1980,11 +2011,11 @@ inline const std::string& Field::_internal_default_value() const { return _impl_.default_value_.Get(); } inline void Field::_internal_set_default_value(const std::string& value) { - + _impl_.default_value_.Set(value, GetArenaForAllocation()); } inline std::string* Field::_internal_mutable_default_value() { - + return _impl_.default_value_.Mutable(GetArenaForAllocation()); } inline std::string* Field::release_default_value() { @@ -1992,6 +2023,11 @@ inline std::string* Field::release_default_value() { return _impl_.default_value_.Release(); } inline void Field::set_allocated_default_value(std::string* default_value) { + if (default_value != nullptr) { + + } else { + + } _impl_.default_value_.SetAllocated(default_value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.default_value_.IsDefault()) { @@ -2029,11 +2065,11 @@ inline const std::string& Enum::_internal_name() const { return _impl_.name_.Get(); } inline void Enum::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Enum::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Enum::release_name() { @@ -2041,6 +2077,11 @@ inline std::string* Enum::release_name() { return _impl_.name_.Release(); } inline void Enum::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -2152,6 +2193,11 @@ inline void Enum::unsafe_arena_set_allocated_source_context( delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.source_context_); } _impl_.source_context_ = source_context; + if (source_context) { + + } else { + + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.source_context) } inline ::PROTOBUF_NAMESPACE_ID::SourceContext* Enum::release_source_context() { @@ -2202,9 +2248,9 @@ inline void Enum::set_allocated_source_context(::PROTOBUF_NAMESPACE_ID::SourceCo source_context = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, source_context, submessage_arena); } - + } else { - + } _impl_.source_context_ = source_context; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.source_context) @@ -2258,11 +2304,11 @@ inline const std::string& EnumValue::_internal_name() const { return _impl_.name_.Get(); } inline void EnumValue::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* EnumValue::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* EnumValue::release_name() { @@ -2270,6 +2316,11 @@ inline std::string* EnumValue::release_name() { return _impl_.name_.Release(); } inline void EnumValue::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -2291,7 +2342,7 @@ inline int32_t EnumValue::number() const { return _internal_number(); } inline void EnumValue::_internal_set_number(int32_t value) { - + _impl_.number_ = value; } inline void EnumValue::set_number(int32_t value) { @@ -2367,11 +2418,11 @@ inline const std::string& Option::_internal_name() const { return _impl_.name_.Get(); } inline void Option::_internal_set_name(const std::string& value) { - + _impl_.name_.Set(value, GetArenaForAllocation()); } inline std::string* Option::_internal_mutable_name() { - + return _impl_.name_.Mutable(GetArenaForAllocation()); } inline std::string* Option::release_name() { @@ -2379,6 +2430,11 @@ inline std::string* Option::release_name() { return _impl_.name_.Release(); } inline void Option::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } _impl_.name_.SetAllocated(name, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.name_.IsDefault()) { @@ -2410,6 +2466,11 @@ inline void Option::unsafe_arena_set_allocated_value( delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.value_); } _impl_.value_ = value; + if (value) { + + } else { + + } // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.value) } inline ::PROTOBUF_NAMESPACE_ID::Any* Option::release_value() { @@ -2460,40 +2521,45 @@ inline void Option::set_allocated_value(::PROTOBUF_NAMESPACE_ID::Any* value) { value = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( message_arena, value, submessage_arena); } - + } else { - + } _impl_.value_ = value; // @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.value) } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Field_Kind> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Field_Kind> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Field_Kind>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Field_Kind>() { return ::PROTOBUF_NAMESPACE_ID::Field_Kind_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Field_Cardinality> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Field_Cardinality> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Field_Cardinality>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Field_Cardinality>() { return ::PROTOBUF_NAMESPACE_ID::Field_Cardinality_descriptor(); } +template <> struct is_proto_enum< ::PROTOBUF_NAMESPACE_ID::Syntax> : ::std::true_type {}; template <> -struct is_proto_enum<::PROTOBUF_NAMESPACE_ID::Syntax> : std::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor<::PROTOBUF_NAMESPACE_ID::Syntax>() { +inline const EnumDescriptor* GetEnumDescriptor< ::PROTOBUF_NAMESPACE_ID::Syntax>() { return ::PROTOBUF_NAMESPACE_ID::Syntax_descriptor(); } @@ -2501,6 +2567,5 @@ PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2ftype_2eproto diff --git a/libs/protobuf/src/google/protobuf/unittest.proto b/libs/protobuf/src/google/protobuf/unittest.proto index 440a6f0..f1b0bd0 100644 --- a/libs/protobuf/src/google/protobuf/unittest.proto +++ b/libs/protobuf/src/google/protobuf/unittest.proto @@ -221,12 +221,6 @@ message TestReservedFields { reserved "bar", "baz"; } -enum TestReservedEnumFields { - UNKNOWN = 0; - reserved 2, 15, 9 to 11; - reserved "bar", "baz"; -} - message TestAllExtensions { extensions 1 to max; } @@ -346,22 +340,9 @@ extend TestAllExtensions { optional bytes oneof_bytes_extension = 114; } -message TestMixedFieldsAndExtensions { - optional int32 a = 1; - repeated fixed32 b = 3; - extensions 2, 4; - extend TestMixedFieldsAndExtensions { - optional int32 c = 2; - repeated fixed32 d = 4; - } -} - message TestGroup { optional group OptionalGroup = 16 { optional int32 a = 17; - optional int32 zz = 89; // fast table size must be at least 16, for this - // field to be parsed by the fast parser, since - // 89 - 17 = 72 is a multiple of 8. } optional ForeignEnum optional_foreign_enum = 22; } @@ -478,9 +459,6 @@ message TestRequiredForeign { optional TestRequired optional_message = 1; repeated TestRequired repeated_message = 2; optional int32 dummy = 3; - - // Missing required fields must not affect verification of child messages. - optional NestedTestAllTypes optional_lazy_message = 4 [lazy = true]; } message TestRequiredMessage { @@ -889,6 +867,7 @@ message TestRequiredOneof { } } + // Test messages for packed fields message TestPackedTypes { @@ -1069,6 +1048,7 @@ message TestMessageSize { optional int64 m6 = 6; } + // Test that RPC services work. message FooRequest {} message FooResponse {} @@ -1081,6 +1061,7 @@ service TestService { rpc Bar(BarRequest) returns (BarResponse); } + message BarRequest {} message BarResponse {} @@ -1434,130 +1415,4 @@ message TestVerifyBigFieldNumberUint32 { optional Nested optional_nested = 1; } -// This message contains different kind of enums to exercise the different -// parsers in table-driven. -message EnumParseTester { - enum SeqSmall0 { - SEQ_SMALL_0_DEFAULT = 0; - SEQ_SMALL_0_1 = 1; - SEQ_SMALL_0_2 = 2; - }; - optional SeqSmall0 optional_seq_small_0_lowfield = 1; - optional SeqSmall0 optional_seq_small_0_midfield = 1001; - optional SeqSmall0 optional_seq_small_0_hifield = 1000001; - repeated SeqSmall0 repeated_seq_small_0_lowfield = 2; - repeated SeqSmall0 repeated_seq_small_0_midfield = 1002; - repeated SeqSmall0 repeated_seq_small_0_hifield = 1000002; - repeated SeqSmall0 packed_seq_small_0_lowfield = 3 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_midfield = 1003 [packed = true]; - repeated SeqSmall0 packed_seq_small_0_hifield = 1000003 [packed = true]; - enum SeqSmall1 { - SEQ_SMALL_1_DEFAULT = 1; - SEQ_SMALL_1_2 = 2; - SEQ_SMALL_1_3 = 3; - }; - optional SeqSmall1 optional_seq_small_1_lowfield = 4; - optional SeqSmall1 optional_seq_small_1_midfield = 1004; - optional SeqSmall1 optional_seq_small_1_hifield = 1000004; - repeated SeqSmall1 repeated_seq_small_1_lowfield = 5; - repeated SeqSmall1 repeated_seq_small_1_midfield = 1005; - repeated SeqSmall1 repeated_seq_small_1_hifield = 1000005; - repeated SeqSmall1 packed_seq_small_1_lowfield = 6 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_midfield = 1006 [packed = true]; - repeated SeqSmall1 packed_seq_small_1_hifield = 1000006 [packed = true]; - - enum SeqLarge { - SEQ_LARGE_DEFAULT = -1; - SEQ_LARGE_0 = 0; - SEQ_LARGE_1 = 1; - SEQ_LARGE_2 = 2; - SEQ_LARGE_3 = 3; - SEQ_LARGE_4 = 4; - SEQ_LARGE_5 = 5; - SEQ_LARGE_6 = 6; - SEQ_LARGE_7 = 7; - SEQ_LARGE_8 = 8; - SEQ_LARGE_9 = 9; - SEQ_LARGE_10 = 10; - SEQ_LARGE_11 = 11; - SEQ_LARGE_12 = 12; - SEQ_LARGE_13 = 13; - SEQ_LARGE_14 = 14; - SEQ_LARGE_15 = 15; - SEQ_LARGE_16 = 16; - SEQ_LARGE_17 = 17; - SEQ_LARGE_18 = 18; - SEQ_LARGE_19 = 19; - SEQ_LARGE_20 = 20; - SEQ_LARGE_21 = 21; - SEQ_LARGE_22 = 22; - SEQ_LARGE_23 = 23; - SEQ_LARGE_24 = 24; - SEQ_LARGE_25 = 25; - SEQ_LARGE_26 = 26; - SEQ_LARGE_27 = 27; - SEQ_LARGE_28 = 28; - SEQ_LARGE_29 = 29; - SEQ_LARGE_30 = 30; - SEQ_LARGE_31 = 31; - SEQ_LARGE_32 = 32; - SEQ_LARGE_33 = 33; - }; - optional SeqLarge optional_seq_large_lowfield = 7; - optional SeqLarge optional_seq_large_midfield = 1007; - optional SeqLarge optional_seq_large_hifield = 1000007; - repeated SeqLarge repeated_seq_large_lowfield = 8; - repeated SeqLarge repeated_seq_large_midfield = 1008; - repeated SeqLarge repeated_seq_large_hifield = 1000008; - repeated SeqLarge packed_seq_large_lowfield = 9 [packed = true]; - repeated SeqLarge packed_seq_large_midfield = 1009 [packed = true]; - repeated SeqLarge packed_seq_large_hifield = 1000009 [packed = true]; - - enum Arbitrary { - ARBITRARY_DEFAULT = -123123; - ARBITRARY_1 = -123; - ARBITRARY_2 = 213; - ARBITRARY_3 = 213213; - ARBITRARY_MIN = -2147483648; - ARBITRARY_MAX = 2147483647; - }; - optional Arbitrary optional_arbitrary_lowfield = 10; - optional Arbitrary optional_arbitrary_midfield = 1010; - optional Arbitrary optional_arbitrary_hifield = 1000010; - repeated Arbitrary repeated_arbitrary_lowfield = 11; - repeated Arbitrary repeated_arbitrary_midfield = 1011; - repeated Arbitrary repeated_arbitrary_hifield = 1000011; - repeated Arbitrary packed_arbitrary_lowfield = 12 [packed = true]; - repeated Arbitrary packed_arbitrary_midfield = 1012 [packed = true]; - repeated Arbitrary packed_arbitrary_hifield = 1000012 [packed = true]; - - // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; -}; - -// This message contains different kind of bool fields to exercise the different -// parsers in table-drived. -message BoolParseTester { - optional bool optional_bool_lowfield = 1; - optional bool optional_bool_midfield = 1001; - optional bool optional_bool_hifield = 1000001; - repeated bool repeated_bool_lowfield = 2; - repeated bool repeated_bool_midfield = 1002; - repeated bool repeated_bool_hifield = 1000002; - repeated bool packed_bool_lowfield = 3 [packed = true]; - repeated bool packed_bool_midfield = 1003 [packed = true]; - repeated bool packed_bool_hifield = 1000003 [packed = true]; - - // An arbitrary field we can append to to break the runs of repeated fields. - optional int32 other_field = 99; -}; - -message StringParseTester { - optional string optional_string_lowfield = 1; - optional string optional_string_midfield = 1001; - optional string optional_string_hifield = 1000001; - repeated string repeated_string_lowfield = 2; - repeated string repeated_string_midfield = 1002; - repeated string repeated_string_hifield = 1000002; -}; diff --git a/libs/protobuf/src/google/protobuf/unittest_import.proto b/libs/protobuf/src/google/protobuf/unittest_import.proto index 4fc0ebb..8d03e38 100644 --- a/libs/protobuf/src/google/protobuf/unittest_import.proto +++ b/libs/protobuf/src/google/protobuf/unittest_import.proto @@ -64,6 +64,7 @@ enum ImportEnum { IMPORT_BAZ = 9; } + // To use an enum in a map, it must has the first value as 0. enum ImportEnumForMap { UNKNOWN = 0; diff --git a/libs/protobuf/src/google/protobuf/unittest_mset.proto b/libs/protobuf/src/google/protobuf/unittest_mset.proto index fd6aaa5..3294994 100644 --- a/libs/protobuf/src/google/protobuf/unittest_mset.proto +++ b/libs/protobuf/src/google/protobuf/unittest_mset.proto @@ -53,12 +53,6 @@ message NestedTestMessageSetContainer { optional NestedTestMessageSetContainer child = 2; } -message NestedTestInt { - optional fixed32 a = 1; - optional int32 b = 3; - optional NestedTestInt child = 2; -} - message TestMessageSetExtension1 { extend proto2_wireformat_unittest.TestMessageSet { optional TestMessageSetExtension1 message_set_extension = 1545008; @@ -75,6 +69,11 @@ message TestMessageSetExtension2 { optional string str = 25; } +message NestedTestInt { + optional fixed32 a = 1; + optional NestedTestInt child = 2; +} + message TestMessageSetExtension3 { extend proto2_wireformat_unittest.TestMessageSet { optional TestMessageSetExtension3 message_set_extension = 195273129; diff --git a/libs/protobuf/src/google/protobuf/unknown_field_set.cc b/libs/protobuf/src/google/protobuf/unknown_field_set.cc index 7eecd30..74c358e 100644 --- a/libs/protobuf/src/google/protobuf/unknown_field_set.cc +++ b/libs/protobuf/src/google/protobuf/unknown_field_set.cc @@ -32,26 +32,24 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/unknown_field_set.h" - -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "absl/strings/cord.h" -#include "absl/strings/internal/resize_uninitialized.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/generated_message_tctable_decl.h" -#include "google/protobuf/generated_message_tctable_impl.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -245,7 +243,7 @@ bool UnknownFieldSet::ParseFromArray(const void* data, int size) { bool UnknownFieldSet::SerializeToString(std::string* output) const { const size_t size = google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(*this); - absl::strings_internal::STLStringResizeUninitializedAmortized(output, size); + STLStringResizeUninitializedAmortized(output, size); google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( *this, reinterpret_cast(const_cast(output->data()))); return true; @@ -349,4 +347,4 @@ const char* UnknownFieldParse(uint64_t tag, UnknownFieldSet* unknown, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/unknown_field_set.h b/libs/protobuf/src/google/protobuf/unknown_field_set.h index 04b630e..9aa2cbb 100644 --- a/libs/protobuf/src/google/protobuf/unknown_field_set.h +++ b/libs/protobuf/src/google/protobuf/unknown_field_set.h @@ -44,17 +44,16 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/port.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include #ifdef SWIG #error "You cannot SWIG proto headers" @@ -87,8 +86,6 @@ class UnknownField; // below class PROTOBUF_EXPORT UnknownFieldSet { public: UnknownFieldSet(); - UnknownFieldSet(const UnknownFieldSet&) = delete; - UnknownFieldSet& operator=(const UnknownFieldSet&) = delete; ~UnknownFieldSet(); // Remove all fields. @@ -212,6 +209,7 @@ class PROTOBUF_EXPORT UnknownFieldSet { } std::vector fields_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UnknownFieldSet); }; namespace internal { @@ -219,7 +217,7 @@ namespace internal { inline void WriteVarint(uint32_t num, uint64_t val, UnknownFieldSet* unknown) { unknown->AddVarint(num, val); } -inline void WriteLengthDelimited(uint32_t num, absl::string_view val, +inline void WriteLengthDelimited(uint32_t num, StringPiece val, UnknownFieldSet* unknown) { unknown->AddLengthDelimited(num)->assign(val.data(), val.size()); } @@ -405,5 +403,5 @@ inline void UnknownField::SetType(Type type) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UNKNOWN_FIELD_SET_H__ diff --git a/libs/protobuf/src/google/protobuf/unknown_field_set_unittest.cc b/libs/protobuf/src/google/protobuf/unknown_field_set_unittest.cc index 38337a4..7f9a598 100644 --- a/libs/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +++ b/libs/protobuf/src/google/protobuf/unknown_field_set_unittest.cc @@ -35,31 +35,29 @@ // This test is testing a lot more than just the UnknownFieldSet class. It // tests handling of unknown fields throughout the system. -#include "google/protobuf/unknown_field_set.h" +#include #include #include #include -#include "google/protobuf/stubs/callback.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_lite.pb.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "absl/strings/cord.h" -#include "absl/synchronization/mutex.h" -#include "absl/time/clock.h" -#include "absl/time/time.h" -#include "google/protobuf/test_util.h" - +#include +#include +#include namespace google { namespace protobuf { @@ -206,13 +204,15 @@ TEST_F(UnknownFieldSetTest, SerializeFastAndSlowAreEquivalent) { slow_buffer.resize(size); fast_buffer.resize(size); - uint8_t* target = reinterpret_cast(&fast_buffer[0]); + uint8_t* target = + reinterpret_cast(::google::protobuf::string_as_array(&fast_buffer)); uint8_t* result = WireFormat::SerializeUnknownFieldsToArray( empty_message_.unknown_fields(), target); EXPECT_EQ(size, result - target); { - io::ArrayOutputStream raw_stream(&slow_buffer[0], size, 1); + io::ArrayOutputStream raw_stream(::google::protobuf::string_as_array(&slow_buffer), size, + 1); io::CodedOutputStream output_stream(&raw_stream); WireFormat::SerializeUnknownFields(empty_message_.unknown_fields(), &output_stream); @@ -648,7 +648,7 @@ void CheckDeleteByNumber(const std::vector& field_numbers, } } -#define MAKE_VECTOR(x) std::vector(x, x + ABSL_ARRAYSIZE(x)) +#define MAKE_VECTOR(x) std::vector(x, x + GOOGLE_ARRAYSIZE(x)) TEST_F(UnknownFieldSetTest, DeleteByNumber) { CheckDeleteByNumber(std::vector(), 1, std::vector()); static const int kTestFieldNumbers1[] = {1, 2, 3}; diff --git a/libs/protobuf/src/google/protobuf/util/BUILD.bazel b/libs/protobuf/src/google/protobuf/util/BUILD.bazel deleted file mode 100644 index 404b346..0000000 --- a/libs/protobuf/src/google/protobuf/util/BUILD.bazel +++ /dev/null @@ -1,280 +0,0 @@ -################################################################################ -# Protocol Buffers C++ Utilities -################################################################################ - -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_proto_library", "cc_test") -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_proto//proto:defs.bzl", "proto_library") -load("//build_defs:cpp_opts.bzl", "COPTS") - -cc_library( - name = "delimited_message_util", - srcs = ["delimited_message_util.cc"], - hdrs = ["delimited_message_util.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - "//:protobuf_lite", - "//src/google/protobuf/io", - ], -) - -cc_test( - name = "delimited_message_util_test", - srcs = ["delimited_message_util_test.cc"], - copts = COPTS, - deps = [ - ":delimited_message_util", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "differencer", - srcs = [ - "field_comparator.cc", - "message_differencer.cc", - ], - hdrs = [ - "field_comparator.h", - "message_differencer.h", - ], - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - ], -) - -cc_test( - name = "field_comparator_test", - srcs = ["field_comparator_test.cc"], - deps = [ - ":differencer", - ":message_differencer_unittest_cc_proto", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "message_differencer_unittest", - srcs = ["message_differencer_unittest.cc"], - copts = COPTS + select({ - "//build_defs:config_msvc": [], - "//conditions:default": [ - "-Wno-deprecated-declarations", - ], - }), - deps = [ - ":differencer", - ":message_differencer_unittest_cc_proto", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util", - "//src/google/protobuf/testing", - "@com_google_absl//absl/functional:bind_front", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "field_mask_util", - srcs = ["field_mask_util.cc"], - hdrs = ["field_mask_util.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/stubs", - ], -) - -cc_test( - name = "field_mask_util_test", - srcs = ["field_mask_util_test.cc"], - copts = COPTS, - deps = [ - ":field_mask_util", - "//src/google/protobuf", - "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:test_util", - "//src/google/protobuf/stubs", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "json_util", - hdrs = ["json_util.h"], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = ["//src/google/protobuf/json"], -) - -cc_library( - name = "time_util", - srcs = ["time_util.cc"], - hdrs = ["time_util.h"], - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/stubs", - ], -) - -cc_test( - name = "time_util_test", - srcs = ["time_util_test.cc"], - deps = [ - ":time_util", - "//src/google/protobuf", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -cc_library( - name = "type_resolver_util", - srcs = ["type_resolver_util.cc"], - hdrs = [ - "type_resolver.h", - "type_resolver_util.h", - ], - copts = COPTS, - strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/io", - "//src/google/protobuf/stubs", - "@com_google_absl//absl/status", - ], -) - -cc_test( - name = "type_resolver_util_test", - srcs = ["type_resolver_util_test.cc"], - copts = COPTS, - deps = [ - ":json_format_cc_proto", - ":json_format_proto3_cc_proto", - ":json_util", - "//src/google/protobuf", - "//src/google/protobuf:test_util", - "//src/google/protobuf/testing", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - ], -) - -# Testonly protos - -filegroup( - name = "test_proto_srcs", - testonly = 1, - srcs = [ - "json_format.proto", - "json_format_proto3.proto", - "message_differencer_unittest.proto", - ], - visibility = [ - "//pkg:__pkg__", - "//python:__pkg__", - ], -) - -proto_library( - name = "json_format_proto", - testonly = 1, - srcs = ["json_format.proto"], - strip_import_prefix = "/src", - deps = [ - "//:any_proto", - "//:duration_proto", - "//:field_mask_proto", - "//:struct_proto", - "//:test_protos", - "//:timestamp_proto", - "//:wrappers_proto", - ], -) - -cc_proto_library( - name = "json_format_cc_proto", - testonly = 1, - visibility = ["//:__subpackages__"], - deps = [":json_format_proto"], -) - -proto_library( - name = "json_format_proto3_proto", - testonly = 1, - srcs = ["json_format_proto3.proto"], - strip_import_prefix = "/src", - deps = [ - "//:any_proto", - "//:duration_proto", - "//:field_mask_proto", - "//:struct_proto", - "//:test_protos", - "//:timestamp_proto", - "//:wrappers_proto", - ], -) - -cc_proto_library( - name = "json_format_proto3_cc_proto", - testonly = 1, - visibility = ["//:__subpackages__"], - deps = [":json_format_proto3_proto"], -) - -proto_library( - name = "message_differencer_unittest_proto", - testonly = 1, - srcs = ["message_differencer_unittest.proto"], - strip_import_prefix = "/src", - deps = ["//:any_proto"], -) - -cc_proto_library( - name = "message_differencer_unittest_cc_proto", - testonly = 1, - deps = [":message_differencer_unittest_proto"], -) - -################################################################################ -# Distribution packaging -################################################################################ - -pkg_files( - name = "dist_files", - srcs = glob(["**"]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//src:__pkg__"], -) - -filegroup( - name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ]), - visibility = ["//pkg:__pkg__"], -) diff --git a/libs/protobuf/src/google/protobuf/util/delimited_message_util.cc b/libs/protobuf/src/google/protobuf/util/delimited_message_util.cc index 36b51e9..fdc633f 100644 --- a/libs/protobuf/src/google/protobuf/util/delimited_message_util.cc +++ b/libs/protobuf/src/google/protobuf/util/delimited_message_util.cc @@ -31,8 +31,8 @@ // Adapted from the patch of kenton@google.com (Kenton Varda) // See https://github.com/protocolbuffers/protobuf/pull/710 for details. -#include "google/protobuf/util/delimited_message_util.h" -#include "google/protobuf/io/coded_stream.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/util/delimited_message_util.h b/libs/protobuf/src/google/protobuf/util/delimited_message_util.h index 9a4e066..78625cf 100644 --- a/libs/protobuf/src/google/protobuf/util/delimited_message_util.h +++ b/libs/protobuf/src/google/protobuf/util/delimited_message_util.h @@ -37,12 +37,12 @@ #include -#include "google/protobuf/message_lite.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -104,6 +104,6 @@ bool PROTOBUF_EXPORT SerializeDelimitedToCodedStream( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/util/delimited_message_util_test.cc b/libs/protobuf/src/google/protobuf/util/delimited_message_util_test.cc index 954afb2..9483a64 100644 --- a/libs/protobuf/src/google/protobuf/util/delimited_message_util_test.cc +++ b/libs/protobuf/src/google/protobuf/util/delimited_message_util_test.cc @@ -31,13 +31,13 @@ // Adapted from the patch of kenton@google.com (Kenton Varda) // See https://github.com/protocolbuffers/protobuf/pull/710 for details. -#include "google/protobuf/util/delimited_message_util.h" +#include #include -#include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include #include namespace google { diff --git a/libs/protobuf/src/google/protobuf/util/field_comparator.cc b/libs/protobuf/src/google/protobuf/util/field_comparator.cc index bfab75a..5d8e865 100644 --- a/libs/protobuf/src/google/protobuf/util/field_comparator.cc +++ b/libs/protobuf/src/google/protobuf/util/field_comparator.cc @@ -30,15 +30,16 @@ // Author: ksroka@google.com (Krzysztof Sroka) -#include "google/protobuf/util/field_comparator.h" +#include #include #include -#include "google/protobuf/descriptor.h" -#include "google/protobuf/message.h" -#include "google/protobuf/util/message_differencer.h" -#include "google/protobuf/stubs/mathutil.h" +#include +#include +#include +#include +#include namespace google { namespace protobuf { @@ -129,7 +130,7 @@ FieldComparator::ComparisonResult SimpleFieldComparator::SimpleCompare( bool SimpleFieldComparator::CompareWithDifferencer( MessageDifferencer* differencer, const Message& message1, const Message& message2, const util::FieldContext* field_context) { - return differencer->Compare(message1, message2, false, + return differencer->Compare(message1, message2, field_context->parent_fields()); } @@ -182,23 +183,19 @@ bool SimpleFieldComparator::CompareDoubleOrFloat(const FieldDescriptor& field, return true; } // float_comparison_ == APPROXIMATE covers two use cases. - Tolerance* tolerance = nullptr; - if (has_default_tolerance_) tolerance = &default_tolerance_; - - auto it = map_tolerance_.find(&field); - if (it != map_tolerance_.end()) { - tolerance = &it->second; + Tolerance* tolerance = FindOrNull(map_tolerance_, &field); + if (tolerance == NULL && has_default_tolerance_) { + tolerance = &default_tolerance_; } - - if (tolerance != nullptr) { + if (tolerance == NULL) { + return MathUtil::AlmostEquals(value_1, value_2); + } else { // Use user-provided fraction and margin. Since they are stored as // doubles, we explicitly cast them to types of values provided. This // is very likely to fail if provided values are not numeric. return MathUtil::WithinFractionOrMargin( value_1, value_2, static_cast(tolerance->fraction), static_cast(tolerance->margin)); - } else { - return MathUtil::AlmostEquals(value_1, value_2); } } } diff --git a/libs/protobuf/src/google/protobuf/util/field_comparator.h b/libs/protobuf/src/google/protobuf/util/field_comparator.h index 1988b9e..5706da3 100644 --- a/libs/protobuf/src/google/protobuf/util/field_comparator.h +++ b/libs/protobuf/src/google/protobuf/util/field_comparator.h @@ -39,11 +39,10 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/port.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -64,8 +63,6 @@ class MessageDifferencer; class PROTOBUF_EXPORT FieldComparator { public: FieldComparator(); - FieldComparator(const FieldComparator&) = delete; - FieldComparator& operator=(const FieldComparator&) = delete; virtual ~FieldComparator(); enum ComparisonResult { @@ -95,6 +92,9 @@ class PROTOBUF_EXPORT FieldComparator { const FieldDescriptor* field, int index_1, int index_2, const util::FieldContext* field_context) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldComparator); }; // Basic implementation of FieldComparator. Supports three modes of floating @@ -113,8 +113,6 @@ class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator { // Creates new comparator with float comparison set to EXACT. SimpleFieldComparator(); - SimpleFieldComparator(const SimpleFieldComparator&) = delete; - SimpleFieldComparator& operator=(const SimpleFieldComparator&) = delete; ~SimpleFieldComparator() override; @@ -259,11 +257,18 @@ class PROTOBUF_EXPORT SimpleFieldComparator : public FieldComparator { // Field-specific float/double tolerances, which override any default for // those particular fields. ToleranceMap map_tolerance_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleFieldComparator); }; // Default field comparison: use the basic implementation of FieldComparator. -class PROTOBUF_EXPORT DefaultFieldComparator PROTOBUF_FUTURE_FINAL - : public SimpleFieldComparator { +#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES +class PROTOBUF_EXPORT DefaultFieldComparator final + : public SimpleFieldComparator +#else // PROTOBUF_FUTURE_BREAKING_CHANGES +class PROTOBUF_EXPORT DefaultFieldComparator : public SimpleFieldComparator +#endif // PROTOBUF_FUTURE_BREAKING_CHANGES +{ public: ComparisonResult Compare(const Message& message_1, const Message& message_2, const FieldDescriptor* field, int index_1, @@ -278,6 +283,6 @@ class PROTOBUF_EXPORT DefaultFieldComparator PROTOBUF_FUTURE_FINAL } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__ diff --git a/libs/protobuf/src/google/protobuf/util/field_comparator_test.cc b/libs/protobuf/src/google/protobuf/util/field_comparator_test.cc index a6de21c..b680277 100644 --- a/libs/protobuf/src/google/protobuf/util/field_comparator_test.cc +++ b/libs/protobuf/src/google/protobuf/util/field_comparator_test.cc @@ -30,14 +30,14 @@ // Author: ksroka@google.com (Krzysztof Sroka) -#include "google/protobuf/util/field_comparator.h" +#include #include -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/descriptor.h" +#include +#include #include -#include "google/protobuf/stubs/mathutil.h" +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/util/field_mask_util.cc b/libs/protobuf/src/google/protobuf/util/field_mask_util.cc index ef47730..700e590 100644 --- a/libs/protobuf/src/google/protobuf/util/field_mask_util.cc +++ b/libs/protobuf/src/google/protobuf/util/field_mask_util.cc @@ -28,19 +28,16 @@ // (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/util/field_mask_util.h" +#include #include -#include -#include -#include -#include "absl/strings/str_join.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/message.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -49,19 +46,19 @@ namespace util { using google::protobuf::FieldMask; std::string FieldMaskUtil::ToString(const FieldMask& mask) { - return absl::StrJoin(mask.paths(), ","); + return Join(mask.paths(), ","); } -void FieldMaskUtil::FromString(absl::string_view str, FieldMask* out) { +void FieldMaskUtil::FromString(StringPiece str, FieldMask* out) { out->Clear(); - std::vector paths = absl::StrSplit(str, ','); + std::vector paths = Split(str, ","); for (const std::string& path : paths) { if (path.empty()) continue; out->add_paths(path); } } -bool FieldMaskUtil::SnakeCaseToCamelCase(absl::string_view input, +bool FieldMaskUtil::SnakeCaseToCamelCase(StringPiece input, std::string* output) { output->clear(); bool after_underscore = false; @@ -91,7 +88,7 @@ bool FieldMaskUtil::SnakeCaseToCamelCase(absl::string_view input, return true; } -bool FieldMaskUtil::CamelCaseToSnakeCase(absl::string_view input, +bool FieldMaskUtil::CamelCaseToSnakeCase(StringPiece input, std::string* output) { output->clear(); for (const char c : input) { @@ -125,9 +122,9 @@ bool FieldMaskUtil::ToJsonString(const FieldMask& mask, std::string* out) { return true; } -bool FieldMaskUtil::FromJsonString(absl::string_view str, FieldMask* out) { +bool FieldMaskUtil::FromJsonString(StringPiece str, FieldMask* out) { out->Clear(); - std::vector paths = absl::StrSplit(str, ','); + std::vector paths = Split(str, ","); for (const std::string& path : paths) { if (path.empty()) continue; std::string snakecase_path; @@ -140,12 +137,12 @@ bool FieldMaskUtil::FromJsonString(absl::string_view str, FieldMask* out) { } bool FieldMaskUtil::GetFieldDescriptors( - const Descriptor* descriptor, absl::string_view path, + const Descriptor* descriptor, StringPiece path, std::vector* field_descriptors) { if (field_descriptors != nullptr) { field_descriptors->clear(); } - std::vector parts = absl::StrSplit(path, '.'); + std::vector parts = Split(path, "."); for (const std::string& field_name : parts) { if (descriptor == nullptr) { return false; @@ -188,8 +185,6 @@ namespace { class FieldMaskTree { public: FieldMaskTree(); - FieldMaskTree(const FieldMaskTree&) = delete; - FieldMaskTree& operator=(const FieldMaskTree&) = delete; ~FieldMaskTree(); void MergeFromFieldMask(const FieldMask& mask); @@ -251,19 +246,21 @@ class FieldMaskTree { private: struct Node { Node() {} - Node(const Node&) = delete; - Node& operator=(const Node&) = delete; ~Node() { ClearChildren(); } void ClearChildren() { - for (auto& p : children) { - delete p.second; + for (std::map::iterator it = children.begin(); + it != children.end(); ++it) { + delete it->second; } children.clear(); } std::map children; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Node); }; // Merge a sub-tree to mask. This method adds the field paths represented @@ -291,6 +288,8 @@ class FieldMaskTree { bool TrimMessage(const Node* node, Message* message); Node root_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldMaskTree); }; FieldMaskTree::FieldMaskTree() {} @@ -326,7 +325,7 @@ void FieldMaskTree::MergeToFieldMask(const std::string& prefix, } void FieldMaskTree::AddPath(const std::string& path) { - std::vector parts = absl::StrSplit(path, '.'); + std::vector parts = Split(path, "."); if (parts.empty()) { return; } @@ -359,7 +358,7 @@ void FieldMaskTree::RemovePath(const std::string& path, // code below. return; } - std::vector parts = absl::StrSplit(path, '.'); + std::vector parts = Split(path, "."); if (parts.empty()) { return; } @@ -390,11 +389,14 @@ void FieldMaskTree::RemovePath(const std::string& path, node->children[current_descriptor->field(j)->name()] = new Node(); } } - auto it = node->children.find(parts[i]); - if (it == node->children.end()) return; - node = it->second; - if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - current_descriptor = field_descriptor->message_type(); + if (ContainsKey(node->children, parts[i])) { + node = node->children[parts[i]]; + if (field_descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + current_descriptor = field_descriptor->message_type(); + } + } else { + // Path does not exist. + return; } } // Remove path. @@ -408,7 +410,7 @@ void FieldMaskTree::RemovePath(const std::string& path, } void FieldMaskTree::IntersectPath(const std::string& path, FieldMaskTree* out) { - std::vector parts = absl::StrSplit(path, '.'); + std::vector parts = Split(path, "."); if (parts.empty()) { return; } @@ -420,12 +422,12 @@ void FieldMaskTree::IntersectPath(const std::string& path, FieldMaskTree* out) { } return; } - auto it = node->children.find(node_name); - if (it == node->children.end()) { + const Node* result = FindPtrOrNull(node->children, node_name); + if (result == nullptr) { // No intersection found. return; } - node = it->second; + node = result; } // Now we found a matching node with the given path. Add all leaf nodes // to out. @@ -663,7 +665,7 @@ void FieldMaskUtil::Subtract(const Descriptor* descriptor, tree.MergeToFieldMask(out); } -bool FieldMaskUtil::IsPathInFieldMask(absl::string_view path, +bool FieldMaskUtil::IsPathInFieldMask(StringPiece path, const FieldMask& mask) { for (int i = 0; i < mask.paths_size(); ++i) { const std::string& mask_path = mask.paths(i); diff --git a/libs/protobuf/src/google/protobuf/util/field_mask_util.h b/libs/protobuf/src/google/protobuf/util/field_mask_util.h index 03fb6a1..d51a332 100644 --- a/libs/protobuf/src/google/protobuf/util/field_mask_util.h +++ b/libs/protobuf/src/google/protobuf/util/field_mask_util.h @@ -35,14 +35,13 @@ #include #include -#include -#include "google/protobuf/field_mask.pb.h" -#include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -55,7 +54,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Converts FieldMask to/from string, formatted by separating each path // with a comma (e.g., "foo_bar,baz.quz"). static std::string ToString(const FieldMask& mask); - static void FromString(absl::string_view str, FieldMask* out); + static void FromString(StringPiece str, FieldMask* out); // Populates the FieldMask with the paths corresponding to the fields with the // given numbers, after checking that all field numbers are valid. @@ -77,19 +76,19 @@ class PROTOBUF_EXPORT FieldMaskUtil { // style conforming (i.e., not snake_case when converted to string, or not // camelCase when converted from string), the conversion will fail. static bool ToJsonString(const FieldMask& mask, std::string* out); - static bool FromJsonString(absl::string_view str, FieldMask* out); + static bool FromJsonString(StringPiece str, FieldMask* out); // Get the descriptors of the fields which the given path from the message // descriptor traverses, if field_descriptors is not null. // Return false if the path is not valid, and the content of field_descriptors // is unspecified. static bool GetFieldDescriptors( - const Descriptor* descriptor, absl::string_view path, + const Descriptor* descriptor, StringPiece path, std::vector* field_descriptors); // Checks whether the given path is valid for type T. template - static bool IsValidPath(absl::string_view path) { + static bool IsValidPath(StringPiece path) { return GetFieldDescriptors(T::descriptor(), path, nullptr); } @@ -107,7 +106,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Adds a path to FieldMask after checking whether the given path is valid. // This method check-fails if the path is not a valid path for type T. template - static void AddPathToFieldMask(absl::string_view path, FieldMask* mask) { + static void AddPathToFieldMask(StringPiece path, FieldMask* mask) { GOOGLE_CHECK(IsValidPath(path)) << path; mask->add_paths(std::string(path)); } @@ -160,7 +159,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // "foo.bar" covers all paths like "foo.bar.baz", "foo.bar.quz.x", etc. // Also note that parent paths are not covered by explicit child path, i.e. // "foo.bar" does NOT cover "foo", even if "bar" is the only child. - static bool IsPathInFieldMask(absl::string_view path, const FieldMask& mask); + static bool IsPathInFieldMask(StringPiece path, const FieldMask& mask); class MergeOptions; // Merges fields specified in a FieldMask into another message. @@ -195,7 +194,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Note that the input can contain characters not allowed in C identifiers. // For example, "foo_bar,baz_quz" will be converted to "fooBar,bazQuz" // successfully. - static bool SnakeCaseToCamelCase(absl::string_view input, + static bool SnakeCaseToCamelCase(StringPiece input, std::string* output); // Converts a field name from camelCase to snake_case: // 1. Every uppercase letter is converted to lowercase with an additional @@ -209,7 +208,7 @@ class PROTOBUF_EXPORT FieldMaskUtil { // Note that the input can contain characters not allowed in C identifiers. // For example, "fooBar,bazQuz" will be converted to "foo_bar,baz_quz" // successfully. - static bool CamelCaseToSnakeCase(absl::string_view input, + static bool CamelCaseToSnakeCase(StringPiece input, std::string* output); }; @@ -259,6 +258,6 @@ class PROTOBUF_EXPORT FieldMaskUtil::TrimOptions { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/util/field_mask_util_test.cc b/libs/protobuf/src/google/protobuf/util/field_mask_util_test.cc index a67a025..bcad739 100644 --- a/libs/protobuf/src/google/protobuf/util/field_mask_util_test.cc +++ b/libs/protobuf/src/google/protobuf/util/field_mask_util_test.cc @@ -28,18 +28,18 @@ // (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/util/field_mask_util.h" +#include #include #include #include -#include "google/protobuf/field_mask.pb.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" +#include +#include +#include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/util/internal/constants.h b/libs/protobuf/src/google/protobuf/util/internal/constants.h new file mode 100644 index 0000000..8bded86 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/constants.h @@ -0,0 +1,101 @@ +// 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_UTIL_INTERNAL_CONSTANTS_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_CONSTANTS_H__ + +#include + +#include + +// This file contains constants used by //net/proto2/util/converter. + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +// Prefix for type URLs. +const char kTypeServiceBaseUrl[] = "type.googleapis.com"; + +// Format string for RFC3339 timestamp formatting. +const char kRfc3339TimeFormat[] = "%E4Y-%m-%dT%H:%M:%S"; + +// Same as above, but the year value is not zero-padded i.e. this accepts +// timestamps like "1-01-0001T23:59:59Z" instead of "0001-01-0001T23:59:59Z". +const char kRfc3339TimeFormatNoPadding[] = "%Y-%m-%dT%H:%M:%S"; + +// Minimum seconds allowed in a google.protobuf.Timestamp value. +const int64_t kTimestampMinSeconds = -62135596800LL; + +// Maximum seconds allowed in a google.protobuf.Timestamp value. +const int64_t kTimestampMaxSeconds = 253402300799LL; + +// Minimum seconds allowed in a google.protobuf.Duration value. +const int64_t kDurationMinSeconds = -315576000000LL; + +// Maximum seconds allowed in a google.protobuf.Duration value. +const int64_t kDurationMaxSeconds = 315576000000LL; + +// Nano seconds in a second. +const int32_t kNanosPerSecond = 1000000000; + +// Type url representing NULL values in google.protobuf.Struct type. +const char kStructNullValueTypeUrl[] = + "type.googleapis.com/google.protobuf.NullValue"; + +// Type string for google.protobuf.Struct +const char kStructType[] = "google.protobuf.Struct"; + +// Type string for struct.proto's google.protobuf.Value value type. +const char kStructValueType[] = "google.protobuf.Value"; + +// Type string for struct.proto's google.protobuf.ListValue value type. +const char kStructListValueType[] = "google.protobuf.ListValue"; + +// Type string for google.protobuf.Timestamp +const char kTimestampType[] = "google.protobuf.Timestamp"; + +// Type string for google.protobuf.Duration +const char kDurationType[] = "google.protobuf.Duration"; + +// Type URL for struct value type google.protobuf.Value +const char kStructValueTypeUrl[] = "type.googleapis.com/google.protobuf.Value"; + +// Type string for google.protobuf.Any +const char kAnyType[] = "google.protobuf.Any"; + +// The protobuf option name of jspb.message_id; +const char kOptionJspbMessageId[] = "jspb.message_id"; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_CONSTANTS_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/datapiece.cc b/libs/protobuf/src/google/protobuf/util/internal/datapiece.cc new file mode 100644 index 0000000..3e7aa84 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/datapiece.cc @@ -0,0 +1,441 @@ +// 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using util::Status; + +namespace { + +template +util::StatusOr ValidateNumberConversion(To after, From before) { + if (after == before && + MathUtil::Sign(before) == MathUtil::Sign(after)) { + return after; + } else { + return util::InvalidArgumentError( + std::is_integral::value ? ValueAsString(before) + : std::is_same::value ? DoubleAsString(before) + : FloatAsString(before)); + } +} + +// For general conversion between +// int32, int64, uint32, uint64, double and float +// except conversion between double and float. +template +util::StatusOr NumberConvertAndCheck(From before) { + if (std::is_same::value) return before; + + To after = static_cast(before); + return ValidateNumberConversion(after, before); +} + +// For conversion to integer types (int32, int64, uint32, uint64) from floating +// point types (double, float) only. +template +util::StatusOr FloatingPointToIntConvertAndCheck(From before) { + if (std::is_same::value) return before; + + To after = static_cast(before); + return ValidateNumberConversion(after, before); +} + +// For conversion between double and float only. +util::StatusOr FloatToDouble(float before) { + // Casting float to double should just work as double has more precision + // than float. + return static_cast(before); +} + +util::StatusOr DoubleToFloat(double before) { + if (std::isnan(before)) { + return std::numeric_limits::quiet_NaN(); + } else if (!std::isfinite(before)) { + // Converting a double +inf/-inf to float should just work. + return static_cast(before); + } else if (before > std::numeric_limits::max() || + before < -std::numeric_limits::max()) { + // Some doubles are larger than the largest float, but after + // rounding they will be equal to the largest float. + // We can't just attempt the conversion because that has UB if + // the value really is out-of-range. + // Here we take advantage that 1/2-ing a large floating point + // will not lose precision. + double half_before = before * 0.5; + if (half_before < std::numeric_limits::max() && + half_before > -std::numeric_limits::max()) { + const float half_fmax = std::numeric_limits::max() * 0.5f; + // If after being cut in half, the value is less than the largest float, + // then it's safe to convert it to float. Importantly, this conversion + // rounds in the same way that the original does. + float half_after = static_cast(half_before); + if (half_after <= half_fmax && half_after >= -half_fmax) { + return half_after + half_after; + } + } + // Double value outside of the range of float. + return util::InvalidArgumentError(DoubleAsString(before)); + } else { + return static_cast(before); + } +} + +} // namespace + +util::StatusOr DataPiece::ToInt32() const { + if (type_ == TYPE_STRING) + return StringToNumber(safe_strto32); + + if (type_ == TYPE_DOUBLE) + return FloatingPointToIntConvertAndCheck(double_); + + if (type_ == TYPE_FLOAT) + return FloatingPointToIntConvertAndCheck(float_); + + return GenericConvert(); +} + +util::StatusOr DataPiece::ToUint32() const { + if (type_ == TYPE_STRING) + return StringToNumber(safe_strtou32); + + if (type_ == TYPE_DOUBLE) + return FloatingPointToIntConvertAndCheck(double_); + + if (type_ == TYPE_FLOAT) + return FloatingPointToIntConvertAndCheck(float_); + + return GenericConvert(); +} + +util::StatusOr DataPiece::ToInt64() const { + if (type_ == TYPE_STRING) + return StringToNumber(safe_strto64); + + if (type_ == TYPE_DOUBLE) + return FloatingPointToIntConvertAndCheck(double_); + + if (type_ == TYPE_FLOAT) + return FloatingPointToIntConvertAndCheck(float_); + + return GenericConvert(); +} + +util::StatusOr DataPiece::ToUint64() const { + if (type_ == TYPE_STRING) + return StringToNumber(safe_strtou64); + + if (type_ == TYPE_DOUBLE) + return FloatingPointToIntConvertAndCheck(double_); + + if (type_ == TYPE_FLOAT) + return FloatingPointToIntConvertAndCheck(float_); + + return GenericConvert(); +} + +util::StatusOr DataPiece::ToDouble() const { + if (type_ == TYPE_FLOAT) { + return FloatToDouble(float_); + } + if (type_ == TYPE_STRING) { + if (str_ == "Infinity") return std::numeric_limits::infinity(); + if (str_ == "-Infinity") return -std::numeric_limits::infinity(); + if (str_ == "NaN") return std::numeric_limits::quiet_NaN(); + util::StatusOr value = StringToNumber(safe_strtod); + if (value.ok() && !std::isfinite(value.value())) { + // safe_strtod converts out-of-range values to +inf/-inf, but we want + // to report them as errors. + return util::InvalidArgumentError(StrCat("\"", str_, "\"")); + } else { + return value; + } + } + return GenericConvert(); +} + +util::StatusOr DataPiece::ToFloat() const { + if (type_ == TYPE_DOUBLE) { + return DoubleToFloat(double_); + } + if (type_ == TYPE_STRING) { + if (str_ == "Infinity") return std::numeric_limits::infinity(); + if (str_ == "-Infinity") return -std::numeric_limits::infinity(); + if (str_ == "NaN") return std::numeric_limits::quiet_NaN(); + // SafeStrToFloat() is used instead of safe_strtof() because the later + // does not fail on inputs like SimpleDtoa(DBL_MAX). + return StringToNumber(SafeStrToFloat); + } + return GenericConvert(); +} + +util::StatusOr DataPiece::ToBool() const { + switch (type_) { + case TYPE_BOOL: + return bool_; + case TYPE_STRING: + return StringToNumber(safe_strtob); + default: + return util::InvalidArgumentError( + ValueAsStringOrDefault("Wrong type. Cannot convert to Bool.")); + } +} + +util::StatusOr DataPiece::ToString() const { + switch (type_) { + case TYPE_STRING: + return std::string(str_); + case TYPE_BYTES: { + std::string base64; + Base64Escape(str_, &base64); + return base64; + } + default: + return util::InvalidArgumentError( + ValueAsStringOrDefault("Cannot convert to string.")); + } +} + +std::string DataPiece::ValueAsStringOrDefault( + StringPiece default_string) const { + switch (type_) { + case TYPE_INT32: + return StrCat(i32_); + case TYPE_INT64: + return StrCat(i64_); + case TYPE_UINT32: + return StrCat(u32_); + case TYPE_UINT64: + return StrCat(u64_); + case TYPE_DOUBLE: + return DoubleAsString(double_); + case TYPE_FLOAT: + return FloatAsString(float_); + case TYPE_BOOL: + return SimpleBtoa(bool_); + case TYPE_STRING: + return StrCat("\"", str_.ToString(), "\""); + case TYPE_BYTES: { + std::string base64; + WebSafeBase64Escape(str_, &base64); + return StrCat("\"", base64, "\""); + } + case TYPE_NULL: + return "null"; + default: + return std::string(default_string); + } +} + +util::StatusOr DataPiece::ToBytes() const { + if (type_ == TYPE_BYTES) return str_.ToString(); + if (type_ == TYPE_STRING) { + std::string decoded; + if (!DecodeBase64(str_, &decoded)) { + return util::InvalidArgumentError( + ValueAsStringOrDefault("Invalid data in input.")); + } + return decoded; + } else { + return util::InvalidArgumentError(ValueAsStringOrDefault( + "Wrong type. Only String or Bytes can be converted to Bytes.")); + } +} + +util::StatusOr DataPiece::ToEnum(const google::protobuf::Enum* enum_type, + bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, + bool ignore_unknown_enum_values, + bool* is_unknown_enum_value) const { + if (type_ == TYPE_NULL) return google::protobuf::NULL_VALUE; + + if (type_ == TYPE_STRING) { + // First try the given value as a name. + std::string enum_name = std::string(str_); + const google::protobuf::EnumValue* value = + FindEnumValueByNameOrNull(enum_type, enum_name); + if (value != nullptr) return value->number(); + + // Check if int version of enum is sent as string. + util::StatusOr int_value = ToInt32(); + if (int_value.ok()) { + if (const google::protobuf::EnumValue* enum_value = + FindEnumValueByNumberOrNull(enum_type, int_value.value())) { + return enum_value->number(); + } + } + + // Next try a normalized name. + bool should_normalize_enum = + case_insensitive_enum_parsing || use_lower_camel_for_enums; + if (should_normalize_enum) { + for (std::string::iterator it = enum_name.begin(); it != enum_name.end(); + ++it) { + *it = *it == '-' ? '_' : ascii_toupper(*it); + } + value = FindEnumValueByNameOrNull(enum_type, enum_name); + if (value != nullptr) return value->number(); + } + + // If use_lower_camel_for_enums is true try with enum name without + // underscore. This will also accept camel case names as the enum_name has + // been normalized before. + if (use_lower_camel_for_enums) { + value = FindEnumValueByNameWithoutUnderscoreOrNull(enum_type, enum_name); + if (value != nullptr) return value->number(); + } + + // If ignore_unknown_enum_values is true an unknown enum value is ignored. + if (ignore_unknown_enum_values) { + *is_unknown_enum_value = true; + if (enum_type->enumvalue_size() > 0) { + return enum_type->enumvalue(0).number(); + } + } + } else { + // We don't need to check whether the value is actually declared in the + // enum because we preserve unknown enum values as well. + return ToInt32(); + } + return util::InvalidArgumentError( + ValueAsStringOrDefault("Cannot find enum with given value.")); +} + +template +util::StatusOr DataPiece::GenericConvert() const { + switch (type_) { + case TYPE_INT32: + return NumberConvertAndCheck(i32_); + case TYPE_INT64: + return NumberConvertAndCheck(i64_); + case TYPE_UINT32: + return NumberConvertAndCheck(u32_); + case TYPE_UINT64: + return NumberConvertAndCheck(u64_); + case TYPE_DOUBLE: + return NumberConvertAndCheck(double_); + case TYPE_FLOAT: + return NumberConvertAndCheck(float_); + default: // TYPE_ENUM, TYPE_STRING, TYPE_CORD, TYPE_BOOL + return util::InvalidArgumentError(ValueAsStringOrDefault( + "Wrong type. Bool, Enum, String and Cord not supported in " + "GenericConvert.")); + } +} + +template +util::StatusOr DataPiece::StringToNumber(bool (*func)(StringPiece, + To*)) const { + if (str_.size() > 0 && (str_[0] == ' ' || str_[str_.size() - 1] == ' ')) { + return util::InvalidArgumentError(StrCat("\"", str_, "\"")); + } + To result; + if (func(str_, &result)) return result; + return util::InvalidArgumentError( + StrCat("\"", std::string(str_), "\"")); +} + +bool DataPiece::DecodeBase64(StringPiece src, std::string* dest) const { + // Try web-safe decode first, if it fails, try the non-web-safe decode. + if (WebSafeBase64Unescape(src, dest)) { + if (use_strict_base64_decoding_) { + // In strict mode, check if the escaped version gives us the same value as + // unescaped. + std::string encoded; + // WebSafeBase64Escape does no padding by default. + WebSafeBase64Escape(*dest, &encoded); + // Remove trailing padding '=' characters before comparison. + StringPiece src_no_padding = StringPiece(src).substr( + 0, HasSuffixString(src, "=") ? src.find_last_not_of('=') + 1 + : src.length()); + return encoded == src_no_padding; + } + return true; + } + + if (Base64Unescape(src, dest)) { + if (use_strict_base64_decoding_) { + std::string encoded; + Base64Escape(reinterpret_cast(dest->data()), + dest->length(), &encoded, false); + StringPiece src_no_padding = StringPiece(src).substr( + 0, HasSuffixString(src, "=") ? src.find_last_not_of('=') + 1 + : src.length()); + return encoded == src_no_padding; + } + return true; + } + + return false; +} + +void DataPiece::InternalCopy(const DataPiece& other) { + type_ = other.type_; + use_strict_base64_decoding_ = other.use_strict_base64_decoding_; + switch (type_) { + case TYPE_INT32: + case TYPE_INT64: + case TYPE_UINT32: + case TYPE_UINT64: + case TYPE_DOUBLE: + case TYPE_FLOAT: + case TYPE_BOOL: + case TYPE_ENUM: + case TYPE_NULL: + case TYPE_BYTES: + case TYPE_STRING: { + str_ = other.str_; + break; + } + } +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/datapiece.h b/libs/protobuf/src/google/protobuf/util/internal/datapiece.h new file mode 100644 index 0000000..6d08349 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/datapiece.h @@ -0,0 +1,219 @@ +// 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_UTIL_INTERNAL_DATAPIECE_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_DATAPIECE_H__ + +#include +#include + +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +class ProtoWriter; + +// Container for a single piece of data together with its data type. +// +// For primitive types (int32, int64, uint32, uint64, double, float, bool), +// the data is stored by value. +// +// For string, a StringPiece is stored. For Cord, a pointer to Cord is stored. +// Just like StringPiece, the DataPiece class does not own the storage for +// the actual string or Cord, so it is the user's responsibility to guarantee +// that the underlying storage is still valid when the DataPiece is accessed. +class PROTOBUF_EXPORT DataPiece { + public: + // Identifies data type of the value. + // These are the types supported by DataPiece. + enum Type { + TYPE_INT32 = 1, + TYPE_INT64 = 2, + TYPE_UINT32 = 3, + TYPE_UINT64 = 4, + TYPE_DOUBLE = 5, + TYPE_FLOAT = 6, + TYPE_BOOL = 7, + TYPE_ENUM = 8, + TYPE_STRING = 9, + TYPE_BYTES = 10, + TYPE_NULL = 11, // explicit NULL type + }; + + // Constructors and Destructor + explicit DataPiece(const int32_t value) + : type_(TYPE_INT32), i32_(value), use_strict_base64_decoding_(false) {} + explicit DataPiece(const int64_t value) + : type_(TYPE_INT64), i64_(value), use_strict_base64_decoding_(false) {} + explicit DataPiece(const uint32_t value) + : type_(TYPE_UINT32), u32_(value), use_strict_base64_decoding_(false) {} + explicit DataPiece(const uint64_t value) + : type_(TYPE_UINT64), u64_(value), use_strict_base64_decoding_(false) {} + explicit DataPiece(const double value) + : type_(TYPE_DOUBLE), + double_(value), + use_strict_base64_decoding_(false) {} + explicit DataPiece(const float value) + : type_(TYPE_FLOAT), float_(value), use_strict_base64_decoding_(false) {} + explicit DataPiece(const bool value) + : type_(TYPE_BOOL), bool_(value), use_strict_base64_decoding_(false) {} + DataPiece(StringPiece value, bool use_strict_base64_decoding) + : type_(TYPE_STRING), + str_(value), + use_strict_base64_decoding_(use_strict_base64_decoding) {} + // Constructor for bytes. The second parameter is not used. + DataPiece(StringPiece value, bool /*dummy*/, bool use_strict_base64_decoding) + : type_(TYPE_BYTES), + str_(value), + use_strict_base64_decoding_(use_strict_base64_decoding) {} + + DataPiece(const DataPiece& r) : type_(r.type_) { InternalCopy(r); } + + DataPiece& operator=(const DataPiece& x) { + InternalCopy(x); + return *this; + } + + static DataPiece NullData() { return DataPiece(TYPE_NULL, 0); } + + virtual ~DataPiece() { + } + + // Accessors + Type type() const { return type_; } + + bool use_strict_base64_decoding() { return use_strict_base64_decoding_; } + + StringPiece str() const { + GOOGLE_LOG_IF(DFATAL, type_ != TYPE_STRING) << "Not a string type."; + return str_; + } + + + // Parses, casts or converts the value stored in the DataPiece into an int32. + util::StatusOr ToInt32() const; + + // Parses, casts or converts the value stored in the DataPiece into a uint32. + util::StatusOr ToUint32() const; + + // Parses, casts or converts the value stored in the DataPiece into an int64. + util::StatusOr ToInt64() const; + + // Parses, casts or converts the value stored in the DataPiece into a uint64. + util::StatusOr ToUint64() const; + + // Parses, casts or converts the value stored in the DataPiece into a double. + util::StatusOr ToDouble() const; + + // Parses, casts or converts the value stored in the DataPiece into a float. + util::StatusOr ToFloat() const; + + // Parses, casts or converts the value stored in the DataPiece into a bool. + util::StatusOr ToBool() const; + + // Parses, casts or converts the value stored in the DataPiece into a string. + util::StatusOr ToString() const; + + // Tries to convert the value contained in this datapiece to string. If the + // conversion fails, it returns the default_string. + std::string ValueAsStringOrDefault(StringPiece default_string) const; + + util::StatusOr ToBytes() const; + + private: + friend class ProtoWriter; + + // Disallow implicit constructor. + DataPiece(); + + // Helper to create NULL or ENUM types. + DataPiece(Type type, int32_t val) + : type_(type), i32_(val), use_strict_base64_decoding_(false) {} + + // Same as the ToEnum() method above but with additional flag to ignore + // unknown enum values. + util::StatusOr ToEnum(const google::protobuf::Enum* enum_type, + bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, + bool ignore_unknown_enum_values, + bool* is_unknown_enum_value) const; + + // For numeric conversion between + // int32, int64, uint32, uint64, double, float and bool + template + util::StatusOr GenericConvert() const; + + // For conversion from string to + // int32, int64, uint32, uint64, double, float and bool + template + util::StatusOr StringToNumber(bool (*func)(StringPiece, To*)) const; + + // Decodes a base64 string. Returns true on success. + bool DecodeBase64(StringPiece src, std::string* dest) const; + + // Helper function to initialize this DataPiece with 'other'. + void InternalCopy(const DataPiece& other); + + // Data type for this piece of data. + Type type_; + + // Stored piece of data. + union { + int32_t i32_; + int64_t i64_; + uint32_t u32_; + uint64_t u64_; + double double_; + float float_; + bool bool_; + StringPiece str_; + }; + + // Uses a stricter version of base64 decoding for byte fields. + bool use_strict_base64_decoding_; +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_DATAPIECE_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc new file mode 100644 index 0000000..7f61cda --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -0,0 +1,642 @@ +// 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 + +#include +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +namespace { +// Helper function to convert string value to given data type by calling the +// passed converter function on the DataPiece created from "value" argument. +// If value is empty or if conversion fails, the default_value is returned. +template +T ConvertTo(StringPiece value, + util::StatusOr (DataPiece::*converter_fn)() const, + T default_value) { + if (value.empty()) return default_value; + util::StatusOr result = (DataPiece(value, true).*converter_fn)(); + return result.ok() ? result.value() : default_value; +} +} // namespace + +DefaultValueObjectWriter::DefaultValueObjectWriter( + TypeResolver* type_resolver, const google::protobuf::Type& type, + ObjectWriter* ow) + : typeinfo_(TypeInfo::NewTypeInfo(type_resolver)), + own_typeinfo_(true), + type_(type), + current_(nullptr), + root_(nullptr), + suppress_empty_list_(false), + preserve_proto_field_names_(false), + use_ints_for_enums_(false), + ow_(ow) {} + +DefaultValueObjectWriter::~DefaultValueObjectWriter() { + if (own_typeinfo_) { + delete typeinfo_; + } +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderBool( + StringPiece name, bool value) { + if (current_ == nullptr) { + ow_->RenderBool(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderInt32( + StringPiece name, int32_t value) { + if (current_ == nullptr) { + ow_->RenderInt32(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderUint32( + StringPiece name, uint32_t value) { + if (current_ == nullptr) { + ow_->RenderUint32(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderInt64( + StringPiece name, int64_t value) { + if (current_ == nullptr) { + ow_->RenderInt64(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderUint64( + StringPiece name, uint64_t value) { + if (current_ == nullptr) { + ow_->RenderUint64(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderDouble( + StringPiece name, double value) { + if (current_ == nullptr) { + ow_->RenderDouble(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderFloat( + StringPiece name, float value) { + if (current_ == nullptr) { + ow_->RenderBool(name, value); + } else { + RenderDataPiece(name, DataPiece(value)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderString( + StringPiece name, StringPiece value) { + if (current_ == nullptr) { + ow_->RenderString(name, value); + } else { + // Since StringPiece is essentially a pointer, takes a copy of "value" to + // avoid ownership issues. + string_values_.emplace_back(new std::string(value)); + RenderDataPiece(name, DataPiece(*string_values_.back(), true)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderBytes( + StringPiece name, StringPiece value) { + if (current_ == nullptr) { + ow_->RenderBytes(name, value); + } else { + // Since StringPiece is essentially a pointer, takes a copy of "value" to + // avoid ownership issues. + string_values_.emplace_back(new std::string(value)); + RenderDataPiece(name, DataPiece(*string_values_.back(), false, true)); + } + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::RenderNull( + StringPiece name) { + if (current_ == nullptr) { + ow_->RenderNull(name); + } else { + RenderDataPiece(name, DataPiece::NullData()); + } + return this; +} + +void DefaultValueObjectWriter::RegisterFieldScrubCallBack( + FieldScrubCallBack field_scrub_callback) { + field_scrub_callback_ = std::move(field_scrub_callback); +} + +DefaultValueObjectWriter::Node* DefaultValueObjectWriter::CreateNewNode( + const std::string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, bool suppress_empty_list, + bool preserve_proto_field_names, bool use_ints_for_enums, + FieldScrubCallBack field_scrub_callback) { + return new Node(name, type, kind, data, is_placeholder, path, + suppress_empty_list, preserve_proto_field_names, + use_ints_for_enums, std::move(field_scrub_callback)); +} + +DefaultValueObjectWriter::Node::Node( + const std::string& name, const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, bool suppress_empty_list, + bool preserve_proto_field_names, bool use_ints_for_enums, + FieldScrubCallBack field_scrub_callback) + : name_(name), + type_(type), + kind_(kind), + is_any_(false), + data_(data), + is_placeholder_(is_placeholder), + path_(path), + suppress_empty_list_(suppress_empty_list), + preserve_proto_field_names_(preserve_proto_field_names), + use_ints_for_enums_(use_ints_for_enums), + field_scrub_callback_(std::move(field_scrub_callback)) {} + +DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild( + StringPiece name) { + if (name.empty() || kind_ != OBJECT) { + return nullptr; + } + for (Node* child : children_) { + if (child->name() == name) { + return child; + } + } + return nullptr; +} + +void DefaultValueObjectWriter::Node::WriteTo(ObjectWriter* ow) { + if (kind_ == PRIMITIVE) { + ObjectWriter::RenderDataPieceTo(data_, name_, ow); + return; + } + + // Render maps. Empty maps are rendered as "{}". + if (kind_ == MAP) { + ow->StartObject(name_); + WriteChildren(ow); + ow->EndObject(); + return; + } + + // Write out lists. If we didn't have any list in response, write out empty + // list. + if (kind_ == LIST) { + // Suppress empty lists if requested. + if (suppress_empty_list_ && is_placeholder_) return; + + ow->StartList(name_); + WriteChildren(ow); + ow->EndList(); + return; + } + + // If is_placeholder_ = true, we didn't see this node in the response, so + // skip output. + if (is_placeholder_) return; + + ow->StartObject(name_); + WriteChildren(ow); + ow->EndObject(); +} + +void DefaultValueObjectWriter::Node::WriteChildren(ObjectWriter* ow) { + for (Node* child : children_) { + child->WriteTo(ow); + } +} + +const google::protobuf::Type* DefaultValueObjectWriter::Node::GetMapValueType( + const google::protobuf::Type& found_type, const TypeInfo* typeinfo) { + // If this field is a map, we should use the type of its "Value" as + // the type of the child node. + for (int i = 0; i < found_type.fields_size(); ++i) { + const google::protobuf::Field& sub_field = found_type.fields(i); + if (sub_field.number() != 2) { + continue; + } + if (sub_field.kind() != google::protobuf::Field::TYPE_MESSAGE) { + // This map's value type is not a message type. We don't need to + // get the field_type in this case. + break; + } + util::StatusOr sub_type = + typeinfo->ResolveTypeUrl(sub_field.type_url()); + if (!sub_type.ok()) { + GOOGLE_LOG(WARNING) << "Cannot resolve type '" << sub_field.type_url() << "'."; + } else { + return sub_type.value(); + } + break; + } + return nullptr; +} + +void DefaultValueObjectWriter::Node::PopulateChildren( + const TypeInfo* typeinfo) { + // Ignores well known types that don't require automatically populating their + // primitive children. For type "Any", we only populate its children when the + // "@type" field is set. + // TODO(tsun): remove "kStructValueType" from the list. It's being checked + // now because of a bug in the tool-chain that causes the "oneof_index" + // of kStructValueType to not be set correctly. + if (type_ == nullptr || type_->name() == kAnyType || + type_->name() == kStructType || type_->name() == kTimestampType || + type_->name() == kDurationType || type_->name() == kStructValueType) { + return; + } + std::vector new_children; + std::unordered_map orig_children_map; + + // Creates a map of child nodes to speed up lookup. + for (int i = 0; i < children_.size(); ++i) { + InsertIfNotPresent(&orig_children_map, children_[i]->name_, i); + } + + for (int i = 0; i < type_->fields_size(); ++i) { + const google::protobuf::Field& field = type_->fields(i); + + // This code is checking if the field to be added to the tree should be + // scrubbed or not by calling the field_scrub_callback_ callback function. + std::vector path; + if (!path_.empty()) { + path.insert(path.begin(), path_.begin(), path_.end()); + } + path.push_back(field.name()); + if (field_scrub_callback_ && field_scrub_callback_(path, &field)) { + continue; + } + + std::unordered_map::iterator found = + orig_children_map.find(field.name()); + // If the child field has already been set, we just add it to the new list + // of children. + if (found != orig_children_map.end()) { + new_children.push_back(children_[found->second]); + children_[found->second] = nullptr; + continue; + } + + const google::protobuf::Type* field_type = nullptr; + bool is_map = false; + NodeKind kind = PRIMITIVE; + + if (field.kind() == google::protobuf::Field::TYPE_MESSAGE) { + kind = OBJECT; + util::StatusOr found_result = + typeinfo->ResolveTypeUrl(field.type_url()); + if (!found_result.ok()) { + // "field" is of an unknown type. + GOOGLE_LOG(WARNING) << "Cannot resolve type '" << field.type_url() << "'."; + } else { + const google::protobuf::Type* found_type = found_result.value(); + is_map = IsMap(field, *found_type); + + if (!is_map) { + field_type = found_type; + } else { + // If this field is a map, we should use the type of its "Value" as + // the type of the child node. + field_type = GetMapValueType(*found_type, typeinfo); + kind = MAP; + } + } + } + + if (!is_map && + field.cardinality() == google::protobuf::Field::CARDINALITY_REPEATED) { + kind = LIST; + } + + // If oneof_index() != 0, the child field is part of a "oneof", which means + // the child field is optional and we shouldn't populate its default + // primitive value. + if (field.oneof_index() != 0 && kind == PRIMITIVE) continue; + + // If the child field is of primitive type, sets its data to the default + // value of its type. + std::unique_ptr child( + new Node(preserve_proto_field_names_ ? field.name() : field.json_name(), + field_type, kind, + kind == PRIMITIVE ? CreateDefaultDataPieceForField( + field, typeinfo, use_ints_for_enums_) + : DataPiece::NullData(), + true, path, suppress_empty_list_, preserve_proto_field_names_, + use_ints_for_enums_, field_scrub_callback_)); + new_children.push_back(child.release()); + } + // Adds all leftover nodes in children_ to the beginning of new_child. + for (int i = 0; i < children_.size(); ++i) { + if (children_[i] == nullptr) { + continue; + } + new_children.insert(new_children.begin(), children_[i]); + children_[i] = nullptr; + } + children_.swap(new_children); +} + +void DefaultValueObjectWriter::MaybePopulateChildrenOfAny(Node* node) { + // If this is an "Any" node with "@type" already given and no other children + // have been added, populates its children. + if (node != nullptr && node->is_any() && node->type() != nullptr && + node->type()->name() != kAnyType && node->number_of_children() == 1) { + node->PopulateChildren(typeinfo_); + } +} + +DataPiece DefaultValueObjectWriter::FindEnumDefault( + const google::protobuf::Field& field, const TypeInfo* typeinfo, + bool use_ints_for_enums) { + const google::protobuf::Enum* enum_type = + typeinfo->GetEnumByTypeUrl(field.type_url()); + if (!enum_type) { + GOOGLE_LOG(WARNING) << "Could not find enum with type '" << field.type_url() + << "'"; + return DataPiece::NullData(); + } + if (!field.default_value().empty()) { + if (!use_ints_for_enums) { + return DataPiece(field.default_value(), true); + } else { + const std::string& enum_default_value_name = field.default_value(); + for (int enum_index = 0; enum_index < enum_type->enumvalue_size(); + ++enum_index) { + auto& enum_value = enum_type->enumvalue(enum_index); + if (enum_value.name() == enum_default_value_name) + return DataPiece(enum_value.number()); + } + GOOGLE_LOG(WARNING) << "Could not find enum value '" << enum_default_value_name + << "' with type '" << field.type_url() << "'"; + return DataPiece::NullData(); + } + } + // We treat the first value as the default if none is specified. + return enum_type->enumvalue_size() > 0 + ? (use_ints_for_enums + ? DataPiece(enum_type->enumvalue(0).number()) + : DataPiece(enum_type->enumvalue(0).name(), true)) + : DataPiece::NullData(); +} + +DataPiece DefaultValueObjectWriter::CreateDefaultDataPieceForField( + const google::protobuf::Field& field, const TypeInfo* typeinfo, + bool use_ints_for_enums) { + switch (field.kind()) { + case google::protobuf::Field::TYPE_DOUBLE: { + return DataPiece(ConvertTo( + field.default_value(), &DataPiece::ToDouble, static_cast(0))); + } + case google::protobuf::Field::TYPE_FLOAT: { + return DataPiece(ConvertTo( + field.default_value(), &DataPiece::ToFloat, static_cast(0))); + } + case google::protobuf::Field::TYPE_INT64: + case google::protobuf::Field::TYPE_SINT64: + case google::protobuf::Field::TYPE_SFIXED64: { + return DataPiece(ConvertTo( + field.default_value(), &DataPiece::ToInt64, static_cast(0))); + } + case google::protobuf::Field::TYPE_UINT64: + case google::protobuf::Field::TYPE_FIXED64: { + return DataPiece(ConvertTo(field.default_value(), + &DataPiece::ToUint64, + static_cast(0))); + } + case google::protobuf::Field::TYPE_INT32: + case google::protobuf::Field::TYPE_SINT32: + case google::protobuf::Field::TYPE_SFIXED32: { + return DataPiece(ConvertTo( + field.default_value(), &DataPiece::ToInt32, static_cast(0))); + } + case google::protobuf::Field::TYPE_BOOL: { + return DataPiece( + ConvertTo(field.default_value(), &DataPiece::ToBool, false)); + } + case google::protobuf::Field::TYPE_STRING: { + return DataPiece(field.default_value(), true); + } + case google::protobuf::Field::TYPE_BYTES: { + return DataPiece(field.default_value(), false, true); + } + case google::protobuf::Field::TYPE_UINT32: + case google::protobuf::Field::TYPE_FIXED32: { + return DataPiece(ConvertTo(field.default_value(), + &DataPiece::ToUint32, + static_cast(0))); + } + case google::protobuf::Field::TYPE_ENUM: { + return FindEnumDefault(field, typeinfo, use_ints_for_enums); + } + default: { + return DataPiece::NullData(); + } + } +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject( + StringPiece name) { + if (current_ == nullptr) { + std::vector path; + root_.reset(CreateNewNode(std::string(name), &type_, OBJECT, + DataPiece::NullData(), false, path, + suppress_empty_list_, preserve_proto_field_names_, + use_ints_for_enums_, field_scrub_callback_)); + root_->PopulateChildren(typeinfo_); + current_ = root_.get(); + return this; + } + MaybePopulateChildrenOfAny(current_); + Node* child = current_->FindChild(name); + if (current_->kind() == LIST || current_->kind() == MAP || child == nullptr) { + // If current_ is a list or a map node, we should create a new child and use + // the type of current_ as the type of the new child. + std::unique_ptr node( + CreateNewNode(std::string(name), + ((current_->kind() == LIST || current_->kind() == MAP) + ? current_->type() + : nullptr), + OBJECT, DataPiece::NullData(), false, + child == nullptr ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, + use_ints_for_enums_, field_scrub_callback_)); + child = node.get(); + current_->AddChild(node.release()); + } + + child->set_is_placeholder(false); + if (child->kind() == OBJECT && child->number_of_children() == 0) { + child->PopulateChildren(typeinfo_); + } + + stack_.push(current_); + current_ = child; + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::EndObject() { + if (stack_.empty()) { + // The root object ends here. Writes out the tree. + WriteRoot(); + return this; + } + current_ = stack_.top(); + stack_.pop(); + return this; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::StartList( + StringPiece name) { + if (current_ == nullptr) { + std::vector path; + root_.reset(CreateNewNode(std::string(name), &type_, LIST, + DataPiece::NullData(), false, path, + suppress_empty_list_, preserve_proto_field_names_, + use_ints_for_enums_, field_scrub_callback_)); + current_ = root_.get(); + return this; + } + MaybePopulateChildrenOfAny(current_); + Node* child = current_->FindChild(name); + if (child == nullptr || child->kind() != LIST) { + std::unique_ptr node(CreateNewNode( + std::string(name), nullptr, LIST, DataPiece::NullData(), false, + child == nullptr ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, use_ints_for_enums_, + field_scrub_callback_)); + child = node.get(); + current_->AddChild(node.release()); + } + child->set_is_placeholder(false); + + stack_.push(current_); + current_ = child; + return this; +} + +void DefaultValueObjectWriter::WriteRoot() { + root_->WriteTo(ow_); + root_.reset(nullptr); + current_ = nullptr; +} + +DefaultValueObjectWriter* DefaultValueObjectWriter::EndList() { + if (stack_.empty()) { + WriteRoot(); + return this; + } + current_ = stack_.top(); + stack_.pop(); + return this; +} + +void DefaultValueObjectWriter::RenderDataPiece(StringPiece name, + const DataPiece& data) { + MaybePopulateChildrenOfAny(current_); + if (current_->type() != nullptr && current_->type()->name() == kAnyType && + name == "@type") { + util::StatusOr data_string = data.ToString(); + if (data_string.ok()) { + const std::string& string_value = data_string.value(); + // If the type of current_ is "Any" and its "@type" field is being set + // here, sets the type of current_ to be the type specified by the + // "@type". + util::StatusOr found_type = + typeinfo_->ResolveTypeUrl(string_value); + if (!found_type.ok()) { + GOOGLE_LOG(WARNING) << "Failed to resolve type '" << string_value << "'."; + } else { + current_->set_type(found_type.value()); + } + current_->set_is_any(true); + // If the "@type" field is placed after other fields, we should populate + // other children of primitive type now. Otherwise, we should wait until + // the first value field is rendered before we populate the children, + // because the "value" field of a Any message could be omitted. + if (current_->number_of_children() > 1 && current_->type() != nullptr) { + current_->PopulateChildren(typeinfo_); + } + } + } + Node* child = current_->FindChild(name); + if (child == nullptr || child->kind() != PRIMITIVE) { + // No children are found, creates a new child. + std::unique_ptr node( + CreateNewNode(std::string(name), nullptr, PRIMITIVE, data, false, + child == nullptr ? current_->path() : child->path(), + suppress_empty_list_, preserve_proto_field_names_, + use_ints_for_enums_, field_scrub_callback_)); + current_->AddChild(node.release()); + } else { + child->set_data(data); + child->set_is_placeholder(false); + } +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h new file mode 100644 index 0000000..a9e1673 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -0,0 +1,332 @@ +// 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_UTIL_INTERNAL_DEFAULT_VALUE_OBJECTWRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_DEFAULT_VALUE_OBJECTWRITER_H__ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +// An ObjectWriter that renders non-repeated primitive fields of proto messages +// with their default values. DefaultValueObjectWriter holds objects, lists and +// fields it receives in a tree structure and writes them out to another +// ObjectWriter when EndObject() is called on the root object. It also writes +// out all non-repeated primitive fields that haven't been explicitly rendered +// with their default values (0 for numbers, "" for strings, etc). +class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { + public: + // A Callback function to check whether a field needs to be scrubbed. + // + // Returns true if the field should not be present in the output. Returns + // false otherwise. + // + // The 'path' parameter is a vector of path to the field from root. For + // example: if a nested field "a.b.c" (b is the parent message field of c and + // a is the parent message field of b), then the vector should contain { "a", + // "b", "c" }. + // + // The Field* should point to the google::protobuf::Field of "c". + typedef std::function& /*path of the field*/, + const google::protobuf::Field* /*field*/)> + FieldScrubCallBack; + + DefaultValueObjectWriter(TypeResolver* type_resolver, + const google::protobuf::Type& type, + ObjectWriter* ow); + + ~DefaultValueObjectWriter() override; + + // ObjectWriter methods. + DefaultValueObjectWriter* StartObject(StringPiece name) override; + + DefaultValueObjectWriter* EndObject() override; + + DefaultValueObjectWriter* StartList(StringPiece name) override; + + DefaultValueObjectWriter* EndList() override; + + DefaultValueObjectWriter* RenderBool(StringPiece name, + bool value) override; + + DefaultValueObjectWriter* RenderInt32(StringPiece name, + int32_t value) override; + + DefaultValueObjectWriter* RenderUint32(StringPiece name, + uint32_t value) override; + + DefaultValueObjectWriter* RenderInt64(StringPiece name, + int64_t value) override; + + DefaultValueObjectWriter* RenderUint64(StringPiece name, + uint64_t value) override; + + DefaultValueObjectWriter* RenderDouble(StringPiece name, + double value) override; + + DefaultValueObjectWriter* RenderFloat(StringPiece name, + float value) override; + + DefaultValueObjectWriter* RenderString(StringPiece name, + StringPiece value) override; + DefaultValueObjectWriter* RenderBytes(StringPiece name, + StringPiece value) override; + + DefaultValueObjectWriter* RenderNull(StringPiece name) override; + + // Register the callback for scrubbing of fields. + void RegisterFieldScrubCallBack(FieldScrubCallBack field_scrub_callback); + + // If set to true, empty lists are suppressed from output when default values + // are written. + void set_suppress_empty_list(bool value) { suppress_empty_list_ = value; } + + // If set to true, original proto field names are used + void set_preserve_proto_field_names(bool value) { + preserve_proto_field_names_ = value; + } + + // If set to true, enums are rendered as ints from output when default values + // are written. + void set_print_enums_as_ints(bool value) { use_ints_for_enums_ = value; } + + protected: + enum NodeKind { + PRIMITIVE = 0, + OBJECT = 1, + LIST = 2, + MAP = 3, + }; + + // "Node" represents a node in the tree that holds the input of + // DefaultValueObjectWriter. + class PROTOBUF_EXPORT Node { + public: + Node(const std::string& name, const google::protobuf::Type* type, + NodeKind kind, const DataPiece& data, bool is_placeholder, + const std::vector& path, bool suppress_empty_list, + bool preserve_proto_field_names, bool use_ints_for_enums, + FieldScrubCallBack field_scrub_callback); + virtual ~Node() { + for (int i = 0; i < children_.size(); ++i) { + delete children_[i]; + } + } + + // Adds a child to this node. Takes ownership of this child. + void AddChild(Node* child) { children_.push_back(child); } + + // Finds the child given its name. + Node* FindChild(StringPiece name); + + // Populates children of this Node based on its type. If there are already + // children created, they will be merged to the result. Caller should pass + // in TypeInfo for looking up types of the children. + virtual void PopulateChildren(const TypeInfo* typeinfo); + + // 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. + virtual void WriteTo(ObjectWriter* ow); + + // Accessors + const std::string& name() const { return name_; } + + const std::vector& path() const { return path_; } + + const google::protobuf::Type* type() const { return type_; } + + void set_type(const google::protobuf::Type* type) { type_ = type; } + + NodeKind kind() const { return kind_; } + + int number_of_children() const { return children_.size(); } + + void set_data(const DataPiece& data) { data_ = data; } + + bool is_any() const { return is_any_; } + + void set_is_any(bool is_any) { is_any_ = is_any; } + + void set_is_placeholder(bool is_placeholder) { + is_placeholder_ = is_placeholder; + } + + protected: + // Returns the Value Type of a map given the Type of the map entry and a + // TypeInfo instance. + const google::protobuf::Type* GetMapValueType( + const google::protobuf::Type& found_type, const TypeInfo* typeinfo); + + // Calls WriteTo() on every child in children_. + void WriteChildren(ObjectWriter* ow); + + // The name of this node. + std::string name_; + // google::protobuf::Type of this node. Owned by TypeInfo. + const google::protobuf::Type* type_; + // The kind of this node. + NodeKind kind_; + // Whether this is a node for "Any". + bool is_any_; + // The data of this node when it is a leaf node. + DataPiece data_; + // Children of this node. + std::vector children_; + // Whether this node is a placeholder for an object or list automatically + // generated when creating the parent node. Should be set to false after + // the parent node's StartObject()/StartList() method is called with this + // node's name. + bool is_placeholder_; + + // Path of the field of this node + std::vector path_; + + // Whether to suppress empty list output. + bool suppress_empty_list_; + + // Whether to preserve original proto field names + bool preserve_proto_field_names_; + + // Whether to always print enums as ints + bool use_ints_for_enums_; + + // Function for determining whether a field needs to be scrubbed or not. + FieldScrubCallBack field_scrub_callback_; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Node); + }; + + // Creates a new Node and returns it. Caller owns memory of returned object. + virtual Node* CreateNewNode(const std::string& name, + const google::protobuf::Type* type, NodeKind kind, + const DataPiece& data, bool is_placeholder, + const std::vector& path, + bool suppress_empty_list, + bool preserve_proto_field_names, + bool use_ints_for_enums, + FieldScrubCallBack field_scrub_callback); + + // Creates a DataPiece containing the default value of the type of the field. + static DataPiece CreateDefaultDataPieceForField( + const google::protobuf::Field& field, const TypeInfo* typeinfo) { + return CreateDefaultDataPieceForField(field, typeinfo, false); + } + + // Same as the above but with a flag to use ints instead of enum names. + static DataPiece CreateDefaultDataPieceForField( + const google::protobuf::Field& field, const TypeInfo* typeinfo, + bool use_ints_for_enums); + + 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. + void MaybePopulateChildrenOfAny(Node* node); + + // Writes the root_ node to ow_ and resets the root_ and current_ pointer to + // nullptr. + void WriteRoot(); + + // Adds or replaces the data_ of a primitive child node. + void RenderDataPiece(StringPiece name, const DataPiece& data); + + // Returns the default enum value as a DataPiece, or the first enum value if + // there is no default. For proto3, where we cannot specify an explicit + // default, a zero value will always be returned. + static DataPiece FindEnumDefault(const google::protobuf::Field& field, + const TypeInfo* typeinfo, + bool use_ints_for_enums); + + // Type information for all the types used in the descriptor. Used to find + // google::protobuf::Type of nested messages/enums. + const TypeInfo* typeinfo_; + // Whether the TypeInfo object is owned by this class. + bool own_typeinfo_; + // google::protobuf::Type of the root message type. + const google::protobuf::Type& type_; + // Holds copies of strings passed to RenderString. + std::vector> string_values_; + + // The current Node. Owned by its parents. + Node* current_; + // The root Node. + std::unique_ptr root_; + // The stack to hold the path of Nodes from current_ to root_; + std::stack stack_; + + // Whether to suppress output of empty lists. + bool suppress_empty_list_; + + // Whether to preserve original proto field names + bool preserve_proto_field_names_; + + // Whether to always print enums as ints + bool use_ints_for_enums_; + + // Function for determining whether a field needs to be scrubbed or not. + FieldScrubCallBack field_scrub_callback_; + + ObjectWriter* ow_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DefaultValueObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_DEFAULT_VALUE_OBJECTWRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc new file mode 100644 index 0000000..96b14db --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc @@ -0,0 +1,191 @@ +// 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 + +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +namespace testing { + +using proto_util_converter::testing::DefaultValueTest; + +// Base class for setting up required state for running default values tests on +// different descriptors. +class BaseDefaultValueObjectWriterTest + : public ::testing::TestWithParam { + protected: + explicit BaseDefaultValueObjectWriterTest(const Descriptor* descriptor) + : helper_(GetParam()), mock_(), expects_(&mock_) { + helper_.ResetTypeInfo(descriptor); + testing_.reset(helper_.NewDefaultValueWriter( + std::string(kTypeServiceBaseUrl) + "/" + descriptor->full_name(), + &mock_)); + } + + ~BaseDefaultValueObjectWriterTest() override {} + + TypeInfoTestHelper helper_; + MockObjectWriter mock_; + ExpectingObjectWriter expects_; + std::unique_ptr testing_; +}; + +// Tests to cover some basic DefaultValueObjectWriter use cases. More tests are +// in the marshalling_test.cc and translator_integration_test.cc. +class DefaultValueObjectWriterTest : public BaseDefaultValueObjectWriterTest { + protected: + DefaultValueObjectWriterTest() + : BaseDefaultValueObjectWriterTest(DefaultValueTest::descriptor()) {} + ~DefaultValueObjectWriterTest() override {} +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + DefaultValueObjectWriterTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(DefaultValueObjectWriterTest, Empty) { + // Set expectation + expects_.StartObject("") + ->RenderDouble("doubleValue", 0.0) + ->StartList("repeatedDouble") + ->EndList() + ->RenderFloat("floatValue", 0.0) + ->RenderInt64("int64Value", 0) + ->RenderUint64("uint64Value", 0) + ->RenderInt32("int32Value", 0) + ->RenderUint32("uint32Value", 0) + ->RenderBool("boolValue", false) + ->RenderString("stringValue", "") + ->RenderBytes("bytesValue", "") + ->RenderString("enumValue", "ENUM_FIRST") + ->EndObject(); + + // Actual testing + testing_->StartObject("")->EndObject(); +} + +TEST_P(DefaultValueObjectWriterTest, NonDefaultDouble) { + // Set expectation + expects_.StartObject("") + ->RenderDouble("doubleValue", 1.0) + ->StartList("repeatedDouble") + ->EndList() + ->RenderFloat("floatValue", 0.0) + ->RenderInt64("int64Value", 0) + ->RenderUint64("uint64Value", 0) + ->RenderInt32("int32Value", 0) + ->RenderUint32("uint32Value", 0) + ->RenderBool("boolValue", false) + ->RenderString("stringValue", "") + ->RenderString("enumValue", "ENUM_FIRST") + ->EndObject(); + + // Actual testing + testing_->StartObject("")->RenderDouble("doubleValue", 1.0)->EndObject(); +} + +TEST_P(DefaultValueObjectWriterTest, ShouldRetainUnknownField) { + // Set expectation + expects_.StartObject("") + ->RenderDouble("doubleValue", 1.0) + ->StartList("repeatedDouble") + ->EndList() + ->RenderFloat("floatValue", 0.0) + ->RenderInt64("int64Value", 0) + ->RenderUint64("uint64Value", 0) + ->RenderInt32("int32Value", 0) + ->RenderUint32("uint32Value", 0) + ->RenderBool("boolValue", false) + ->RenderString("stringValue", "") + ->RenderString("unknown", "abc") + ->StartObject("unknownObject") + ->RenderString("unknown", "def") + ->EndObject() + ->RenderString("enumValue", "ENUM_FIRST") + ->EndObject(); + + // Actual testing + testing_->StartObject("") + ->RenderDouble("doubleValue", 1.0) + ->RenderString("unknown", "abc") + ->StartObject("unknownObject") + ->RenderString("unknown", "def") + ->EndObject() + ->EndObject(); +} + + +class DefaultValueObjectWriterSuppressListTest + : public BaseDefaultValueObjectWriterTest { + protected: + DefaultValueObjectWriterSuppressListTest() + : BaseDefaultValueObjectWriterTest(DefaultValueTest::descriptor()) { + testing_->set_suppress_empty_list(true); + } + ~DefaultValueObjectWriterSuppressListTest() override {} +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + DefaultValueObjectWriterSuppressListTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(DefaultValueObjectWriterSuppressListTest, Empty) { + // Set expectation. Empty lists should be suppressed. + expects_.StartObject("") + ->RenderDouble("doubleValue", 0.0) + ->RenderFloat("floatValue", 0.0) + ->RenderInt64("int64Value", 0) + ->RenderUint64("uint64Value", 0) + ->RenderInt32("int32Value", 0) + ->RenderUint32("uint32Value", 0) + ->RenderBool("boolValue", false) + ->RenderString("stringValue", "") + ->RenderBytes("bytesValue", "") + ->RenderString("enumValue", "ENUM_FIRST") + ->EndObject(); + + // Actual testing + testing_->StartObject("")->EndObject(); +} +} // namespace testing +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/arena_align.cc b/libs/protobuf/src/google/protobuf/util/internal/error_listener.cc similarity index 87% rename from libs/protobuf/src/google/protobuf/arena_align.cc rename to libs/protobuf/src/google/protobuf/util/internal/error_listener.cc index 882ae5a..538307b 100644 --- a/libs/protobuf/src/google/protobuf/arena_align.cc +++ b/libs/protobuf/src/google/protobuf/util/internal/error_listener.cc @@ -28,18 +28,15 @@ // (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/arena_align.h" - -#include -#include +#include namespace google { namespace protobuf { -namespace internal { +namespace util { +namespace converter { -// There are still compilers (open source) requiring a definition for constexpr. -constexpr size_t ArenaAlignDefault::align; // NOLINT -} // namespace internal +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/error_listener.h b/libs/protobuf/src/google/protobuf/util/internal/error_listener.h new file mode 100644 index 0000000..8c9c501 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/error_listener.h @@ -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. + +#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_ERROR_LISTENER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_ERROR_LISTENER_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +// Interface for error listener. +class PROTOBUF_EXPORT ErrorListener { + public: + virtual ~ErrorListener() {} + + // Reports an invalid name at the given location. + virtual void InvalidName(const LocationTrackerInterface& loc, + StringPiece invalid_name, + StringPiece message) = 0; + + // Reports an invalid value for a field. + virtual void InvalidValue(const LocationTrackerInterface& loc, + StringPiece type_name, + StringPiece value) = 0; + + // Reports a missing required field. + virtual void MissingField(const LocationTrackerInterface& loc, + StringPiece missing_name) = 0; + + protected: + ErrorListener() {} + + private: + // Do not add any data members to this class. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorListener); +}; + +// An error listener that ignores all errors. +class PROTOBUF_EXPORT NoopErrorListener : public ErrorListener { + public: + NoopErrorListener() {} + ~NoopErrorListener() override {} + + void InvalidName(const LocationTrackerInterface& /*loc*/, + StringPiece /* invalid_name */, + StringPiece /* message */) override {} + + void InvalidValue(const LocationTrackerInterface& /*loc*/, + StringPiece /* type_name */, + StringPiece /* value */) override {} + + void MissingField(const LocationTrackerInterface& /* loc */, + StringPiece /* missing_name */) override {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(NoopErrorListener); +}; + + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_ERROR_LISTENER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h b/libs/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h new file mode 100644 index 0000000..76fe2b6 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h @@ -0,0 +1,250 @@ +// 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_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__ + +// An implementation of ObjectWriter that automatically sets the +// gmock expectations for the response to a method. Every method +// returns the object itself for chaining. +// +// Usage: +// // Setup +// MockObjectWriter mock; +// ExpectingObjectWriter ow(&mock); +// +// // Set expectation +// ow.StartObject("") +// ->RenderString("key", "value") +// ->EndObject(); +// +// // Actual testing +// mock.StartObject(StringPiece()) +// ->RenderString("key", "value") +// ->EndObject(); + +#include + +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using testing::Eq; +using testing::IsEmpty; +using testing::NanSensitiveDoubleEq; +using testing::NanSensitiveFloatEq; +using testing::Return; +using testing::StrEq; +using testing::TypedEq; + +class MockObjectWriter : public ObjectWriter { + public: + MockObjectWriter() {} + + MOCK_METHOD(ObjectWriter*, StartObject, (StringPiece), (override)); + MOCK_METHOD(ObjectWriter*, EndObject, (), (override)); + MOCK_METHOD(ObjectWriter*, StartList, (StringPiece), (override)); + MOCK_METHOD(ObjectWriter*, EndList, (), (override)); + MOCK_METHOD(ObjectWriter*, RenderBool, (StringPiece, bool), (override)); + MOCK_METHOD(ObjectWriter*, RenderInt32, (StringPiece, int32_t), + (override)); + MOCK_METHOD(ObjectWriter*, RenderUint32, (StringPiece, uint32_t), + (override)); + MOCK_METHOD(ObjectWriter*, RenderInt64, (StringPiece, int64_t), + (override)); + MOCK_METHOD(ObjectWriter*, RenderUint64, (StringPiece, uint64_t), + (override)); + MOCK_METHOD(ObjectWriter*, RenderDouble, (StringPiece, double), + (override)); + MOCK_METHOD(ObjectWriter*, RenderFloat, (StringPiece, float), + (override)); + MOCK_METHOD(ObjectWriter*, RenderString, + (StringPiece, StringPiece), (override)); + MOCK_METHOD(ObjectWriter*, RenderBytes, (StringPiece, StringPiece), + (override)); + MOCK_METHOD(ObjectWriter*, RenderNull, (StringPiece), (override)); +}; + +class ExpectingObjectWriter : public ObjectWriter { + public: + explicit ExpectingObjectWriter(MockObjectWriter* mock) : mock_(mock) {} + + ObjectWriter* StartObject(StringPiece name) override { + (name.empty() ? EXPECT_CALL(*mock_, StartObject(IsEmpty())) + : EXPECT_CALL(*mock_, StartObject(Eq(std::string(name))))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* EndObject() override { + EXPECT_CALL(*mock_, EndObject()) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* StartList(StringPiece name) override { + (name.empty() ? EXPECT_CALL(*mock_, StartList(IsEmpty())) + : EXPECT_CALL(*mock_, StartList(Eq(std::string(name))))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* EndList() override { + EXPECT_CALL(*mock_, EndList()) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderBool(StringPiece name, bool value) override { + (name.empty() + ? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq(value))) + : EXPECT_CALL(*mock_, + RenderBool(Eq(std::string(name)), TypedEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderInt32(StringPiece name, int32_t value) override { + (name.empty() + ? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq(value))) + : EXPECT_CALL(*mock_, RenderInt32(Eq(std::string(name)), + TypedEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderUint32(StringPiece name, uint32_t value) override { + (name.empty() ? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), + TypedEq(value))) + : EXPECT_CALL(*mock_, RenderUint32(Eq(std::string(name)), + TypedEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderInt64(StringPiece name, int64_t value) override { + (name.empty() + ? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq(value))) + : EXPECT_CALL(*mock_, RenderInt64(Eq(std::string(name)), + TypedEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderUint64(StringPiece name, uint64_t value) override { + (name.empty() ? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), + TypedEq(value))) + : EXPECT_CALL(*mock_, RenderUint64(Eq(std::string(name)), + TypedEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderDouble(StringPiece name, double value) override { + (name.empty() + ? EXPECT_CALL(*mock_, + RenderDouble(IsEmpty(), NanSensitiveDoubleEq(value))) + : EXPECT_CALL(*mock_, RenderDouble(Eq(std::string(name)), + NanSensitiveDoubleEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderFloat(StringPiece name, float value) override { + (name.empty() + ? EXPECT_CALL(*mock_, + RenderFloat(IsEmpty(), NanSensitiveFloatEq(value))) + : EXPECT_CALL(*mock_, RenderFloat(Eq(std::string(name)), + NanSensitiveFloatEq(value)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderString(StringPiece name, + StringPiece value) override { + (name.empty() ? EXPECT_CALL(*mock_, RenderString(IsEmpty(), + TypedEq( + std::string(value)))) + : EXPECT_CALL(*mock_, RenderString(Eq(std::string(name)), + TypedEq( + std::string(value))))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + virtual ObjectWriter* RenderBytes(StringPiece name, StringPiece value) { + (name.empty() + ? EXPECT_CALL(*mock_, RenderBytes(IsEmpty(), TypedEq( + value.ToString()))) + : EXPECT_CALL(*mock_, + RenderBytes(Eq(std::string(name)), + TypedEq(value.ToString())))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation(); + return this; + } + + ObjectWriter* RenderNull(StringPiece name) override { + (name.empty() ? EXPECT_CALL(*mock_, RenderNull(IsEmpty())) + : EXPECT_CALL(*mock_, RenderNull(Eq(std::string(name)))) + .WillOnce(Return(mock_)) + .RetiresOnSaturation()); + return this; + } + + private: + MockObjectWriter* mock_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ExpectingObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_EXPECTING_OBJECTWRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc b/libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc new file mode 100644 index 0000000..521bf48 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc @@ -0,0 +1,218 @@ +// 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 + +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +namespace { + +// Appends a FieldMask path segment to a prefix. +std::string AppendPathSegmentToPrefix(StringPiece prefix, + StringPiece segment) { + if (prefix.empty()) { + return std::string(segment); + } + if (segment.empty()) { + return std::string(prefix); + } + // If the segment is a map key, appends it to the prefix without the ".". + if (HasPrefixString(segment, "[\"")) { + return StrCat(prefix, segment); + } + return StrCat(prefix, ".", segment); +} + +} // namespace + +std::string ConvertFieldMaskPath(const StringPiece path, + ConverterCallback converter) { + std::string result; + result.reserve(path.size() << 1); + + bool is_quoted = false; + bool is_escaping = false; + int current_segment_start = 0; + + // Loops until 1 passed the end of the input to make handling the last + // segment easier. + for (size_t i = 0; i <= path.size(); ++i) { + // Outputs quoted string as-is. + if (is_quoted) { + if (i == path.size()) { + break; + } + result.push_back(path[i]); + if (is_escaping) { + is_escaping = false; + } else if (path[i] == '\\') { + is_escaping = true; + } else if (path[i] == '\"') { + current_segment_start = i + 1; + is_quoted = false; + } + continue; + } + if (i == path.size() || path[i] == '.' || path[i] == '(' || + path[i] == ')' || path[i] == '\"') { + result += converter( + path.substr(current_segment_start, i - current_segment_start)); + if (i < path.size()) { + result.push_back(path[i]); + } + current_segment_start = i + 1; + } + if (i < path.size() && path[i] == '\"') { + is_quoted = true; + } + } + return result; +} + +util::Status DecodeCompactFieldMaskPaths(StringPiece paths, + PathSinkCallback path_sink) { + std::stack prefix; + int length = paths.length(); + int previous_position = 0; + bool in_map_key = false; + bool is_escaping = false; + // Loops until 1 passed the end of the input to make the handle of the last + // segment easier. + for (int i = 0; i <= length; ++i) { + if (i != length) { + // Skips everything in a map key until we hit the end of it, which is + // marked by an un-escaped '"' immediately followed by a ']'. + if (in_map_key) { + if (is_escaping) { + is_escaping = false; + continue; + } + if (paths[i] == '\\') { + is_escaping = true; + continue; + } + if (paths[i] != '\"') { + continue; + } + // Un-escaped '"' must be followed with a ']'. + if (i >= length - 1 || paths[i + 1] != ']') { + return util::InvalidArgumentError(StrCat( + "Invalid FieldMask '", paths, + "'. Map keys should be represented as [\"some_key\"].")); + } + // The end of the map key ("\"]") has been found. + in_map_key = false; + // Skips ']'. + i++; + // Checks whether the key ends at the end of a path segment. + if (i < length - 1 && paths[i + 1] != '.' && paths[i + 1] != ',' && + paths[i + 1] != ')' && paths[i + 1] != '(') { + return util::InvalidArgumentError(StrCat( + "Invalid FieldMask '", paths, + "'. Map keys should be at the end of a path segment.")); + } + is_escaping = false; + continue; + } + + // We are not in a map key, look for the start of one. + if (paths[i] == '[') { + if (i >= length - 1 || paths[i + 1] != '\"') { + return util::InvalidArgumentError(StrCat( + "Invalid FieldMask '", paths, + "'. Map keys should be represented as [\"some_key\"].")); + } + // "[\"" starts a map key. + in_map_key = true; + i++; // Skips the '\"'. + continue; + } + // If the current character is not a special character (',', '(' or ')'), + // continue to the next. + if (paths[i] != ',' && paths[i] != ')' && paths[i] != '(') { + continue; + } + } + // Gets the current segment - sub-string between previous position (after + // '(', ')', ',', or the beginning of the input) and the current position. + StringPiece segment = + paths.substr(previous_position, i - previous_position); + std::string current_prefix = prefix.empty() ? "" : prefix.top(); + + if (i < length && paths[i] == '(') { + // Builds a prefix and save it into the stack. + prefix.push(AppendPathSegmentToPrefix(current_prefix, segment)); + } else if (!segment.empty()) { + // When the current character is ')', ',' or the current position has + // passed the end of the input, builds and outputs a new paths by + // concatenating the last prefix with the current segment. + RETURN_IF_ERROR( + path_sink(AppendPathSegmentToPrefix(current_prefix, segment))); + } + + // Removes the last prefix after seeing a ')'. + if (i < length && paths[i] == ')') { + if (prefix.empty()) { + return util::InvalidArgumentError( + StrCat("Invalid FieldMask '", paths, + "'. Cannot find matching '(' for all ')'.")); + } + prefix.pop(); + } + previous_position = i + 1; + } + if (in_map_key) { + return util::InvalidArgumentError( + StrCat("Invalid FieldMask '", paths, + "'. Cannot find matching ']' for all '['.")); + } + if (!prefix.empty()) { + return util::InvalidArgumentError( + StrCat("Invalid FieldMask '", paths, + "'. Cannot find matching ')' for all '('.")); + } + return util::Status(); +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.h b/libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.h similarity index 51% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.h rename to libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.h index e6fc628..1882333 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/import_writer.h +++ b/libs/protobuf/src/google/protobuf/util/internal/field_mask_utility.h @@ -28,56 +28,47 @@ // (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_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ +// FieldMask related utility methods. -#include -#include +#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_FIELD_MASK_UTILITY_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_FIELD_MASK_UTILITY_H__ -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" +#include +#include + +#include +#include +#include +#include +#include namespace google { namespace protobuf { -namespace compiler { -namespace objectivec { +namespace util { +namespace converter { -// Helper class for parsing framework import mappings and generating -// import statements. -class ImportWriter { - public: - ImportWriter(const std::string& generate_for_named_framework, - const std::string& named_framework_to_proto_path_mappings_path, - const std::string& runtime_import_prefix, - bool include_wkt_imports); - ~ImportWriter(); +typedef std::function ConverterCallback; +typedef std::function PathSinkCallback; - void AddFile(const FileDescriptor* file, const std::string& header_extension); - void Print(io::Printer* printer) const; +// Applies a 'converter' to each segment of a FieldMask path and returns the +// result. Quoted strings in the 'path' are copied to the output as-is without +// converting their content. Escaping is supported within quoted strings. +// For example, "ab\"_c" will be returned as "ab\"_c" without any changes. +std::string ConvertFieldMaskPath(const StringPiece path, + ConverterCallback converter); - static void PrintRuntimeImports( - io::Printer* printer, const std::vector& header_to_import, - const std::string& runtime_import_prefix, - bool default_cpp_symbol = false); +// Decodes a compact list of FieldMasks. For example, "a.b,a.c.d,a.c.e" will be +// decoded into a list of field paths - "a.b", "a.c.d", "a.c.e". And the results +// will be sent to 'path_sink', i.e. 'path_sink' will be called once per +// resulting path. +// Note that we also support Apiary style FieldMask form. The above example in +// the Apiary style will look like "a.b,a.c(d,e)". +util::Status DecodeCompactFieldMaskPaths(StringPiece paths, + PathSinkCallback path_sink); - private: - void ParseFrameworkMappings(); - - const std::string generate_for_named_framework_; - const std::string named_framework_to_proto_path_mappings_path_; - const std::string runtime_import_prefix_; - const bool include_wkt_imports_; - std::map proto_file_to_framework_name_; - bool need_to_parse_mapping_file_; - - std::vector protobuf_imports_; - std::vector other_framework_imports_; - std::vector other_imports_; -}; - -} // namespace objectivec -} // namespace compiler +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_IMPORT_WRITER_H__ +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_FIELD_MASK_UTILITY_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_escaping.cc b/libs/protobuf/src/google/protobuf/util/internal/json_escaping.cc new file mode 100644 index 0000000..e4fa8cf --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_escaping.cc @@ -0,0 +1,372 @@ +// 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 + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +namespace { + +// Array of hex characters for conversion to hex. +static const char kHex[] = "0123456789abcdef"; + +// Characters 0x00 to 0x9f are very commonly used, so we provide a special +// table lookup. +// +// For unicode code point ch < 0xa0: +// kCommonEscapes[ch] is the escaped string of ch, if escaping is needed; +// or an empty string, if escaping is not needed. +static const char kCommonEscapes[160][7] = { + // C0 (ASCII and derivatives) control characters + "\\u0000", "\\u0001", "\\u0002", "\\u0003", // 0x00 + "\\u0004", "\\u0005", "\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\u000b", + "\\f", "\\r", "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", + "\\u0013", // 0x10 + "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a", + "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f", + // Escaping of " and \ are required by www.json.org string definition. + // Escaping of < and > are required for HTML security. + "", "", "\\\"", "", "", "", "", "", // 0x20 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x30 + "", "", "", "", "\\u003c", "", "\\u003e", "", "", "", "", "", "", "", "", + "", // 0x40 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x50 + "", "", "", "", "\\\\", "", "", "", "", "", "", "", "", "", "", "", // 0x60 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x70 + "", "", "", "", "", "", "", "\\u007f", + // C1 (ISO 8859 and Unicode) extended control characters + "\\u0080", "\\u0081", "\\u0082", "\\u0083", // 0x80 + "\\u0084", "\\u0085", "\\u0086", "\\u0087", "\\u0088", "\\u0089", "\\u008a", + "\\u008b", "\\u008c", "\\u008d", "\\u008e", "\\u008f", "\\u0090", "\\u0091", + "\\u0092", "\\u0093", // 0x90 + "\\u0094", "\\u0095", "\\u0096", "\\u0097", "\\u0098", "\\u0099", "\\u009a", + "\\u009b", "\\u009c", "\\u009d", "\\u009e", "\\u009f"}; + +// Determines if the given char value is a unicode surrogate code unit (either +// high-surrogate or low-surrogate). +inline bool IsSurrogate(uint32_t c) { + // Optimized form of: + // return c >= kMinHighSurrogate && c <= kMaxLowSurrogate; + // (Reduced from 3 ALU instructions to 2 ALU instructions) + return (c & 0xfffff800) == JsonEscaping::kMinHighSurrogate; +} + +// Returns true if the given unicode code point cp is a valid +// unicode code point (i.e. in the range 0 <= cp <= kMaxCodePoint). +inline bool IsValidCodePoint(uint32_t cp) { + return cp <= JsonEscaping::kMaxCodePoint; +} + +// Returns the low surrogate for the given unicode code point. The result is +// meaningless if the given code point is not a supplementary character. +inline uint16_t ToLowSurrogate(uint32_t cp) { + return (cp & + (JsonEscaping::kMaxLowSurrogate - JsonEscaping::kMinLowSurrogate)) + + JsonEscaping::kMinLowSurrogate; +} + +// Returns the high surrogate for the given unicode code point. The result is +// meaningless if the given code point is not a supplementary character. +inline uint16_t ToHighSurrogate(uint32_t cp) { + return (cp >> 10) + (JsonEscaping::kMinHighSurrogate - + (JsonEscaping::kMinSupplementaryCodePoint >> 10)); +} + +// Input str is encoded in UTF-8. A unicode code point could be encoded in +// UTF-8 using anywhere from 1 to 4 characters, and it could span multiple +// reads of the ByteSource. +// +// This function reads the next unicode code point from the input (str) at +// the given position (index), taking into account any left-over partial +// code point from the previous iteration (cp), together with the number +// of characters left to read to complete this code point (num_left). +// +// This function assumes that the input (str) is valid at the given position +// (index). In order words, at least one character could be read successfully. +// +// The code point read (partial or complete) is stored in (cp). Upon return, +// (num_left) stores the number of characters that has yet to be read in +// order to complete the current unicode code point. If the read is complete, +// then (num_left) is 0. Also, (num_read) is the number of characters read. +// +// Returns false if we encounter an invalid UTF-8 string. Returns true +// otherwise, including the case when we reach the end of the input (str) +// before a complete unicode code point is read. +bool ReadCodePoint(StringPiece str, int index, uint32_t* cp, + int* num_left, int* num_read) { + if (*num_left == 0) { + // Last read was complete. Start reading a new unicode code point. + *cp = static_cast(str[index++]); + *num_read = 1; + // The length of the code point is determined from reading the first byte. + // + // If the first byte is between: + // 0..0x7f: that's the value of the code point. + // 0x80..0xbf: + // 0xc0..0xdf: 11-bit code point encoded in 2 bytes. + // bit 10-6, bit 5-0 + // 0xe0..0xef: 16-bit code point encoded in 3 bytes. + // bit 15-12, bit 11-6, bit 5-0 + // 0xf0..0xf7: 21-bit code point encoded in 4 bytes. + // bit 20-18, bit 17-12, bit 11-6, bit 5-0 + // 0xf8..0xff: + // + // Meaning of each bit: + // bit 7: 0 - single byte code point: bits 6-0 are values. + // 1 - multibyte code point + // bit 6: 0 - subsequent bytes of multibyte code point: + // bits 5-0 are values. + // 1 - first byte of multibyte code point + // bit 5: 0 - first byte of 2-byte code point: bits 4-0 are values. + // 1 - first byte of code point with >= 3 bytes. + // bit 4: 0 - first byte of 3-byte code point: bits 3-0 are values. + // 1 - first byte of code point with >= 4 bytes. + // bit 3: 0 - first byte of 4-byte code point: bits 2-0 are values. + // 1 - reserved for future expansion. + if (*cp <= 0x7f) { + return true; + } else if (*cp <= 0xbf) { + return false; + } else if (*cp <= 0xdf) { + *cp &= 0x1f; + *num_left = 1; + } else if (*cp <= 0xef) { + *cp &= 0x0f; + *num_left = 2; + } else if (*cp <= 0xf7) { + *cp &= 0x07; + *num_left = 3; + } else { + return false; + } + } else { + // Last read was partial. Initialize num_read to 0 and continue reading + // the last unicode code point. + *num_read = 0; + } + while (*num_left > 0 && index < str.size()) { + uint32_t ch = static_cast(str[index++]); + --(*num_left); + ++(*num_read); + *cp = (*cp << 6) | (ch & 0x3f); + if (ch < 0x80 || ch > 0xbf) return false; + } + return *num_left > 0 || (!IsSurrogate(*cp) && IsValidCodePoint(*cp)); +} + +// Stores the 16-bit unicode code point as its hexadecimal digits in buffer +// and returns a StringPiece that points to this buffer. The input buffer needs +// to be at least 6 bytes long. +StringPiece ToHex(uint16_t cp, char* buffer) { + buffer[5] = kHex[cp & 0x0f]; + cp >>= 4; + buffer[4] = kHex[cp & 0x0f]; + cp >>= 4; + buffer[3] = kHex[cp & 0x0f]; + cp >>= 4; + buffer[2] = kHex[cp & 0x0f]; + return StringPiece(buffer, 6); +} + +// Stores the 32-bit unicode code point as its hexadecimal digits in buffer +// and returns a StringPiece that points to this buffer. The input buffer needs +// to be at least 12 bytes long. +StringPiece ToSurrogateHex(uint32_t cp, char* buffer) { + uint16_t low = ToLowSurrogate(cp); + uint16_t high = ToHighSurrogate(cp); + + buffer[11] = kHex[low & 0x0f]; + low >>= 4; + buffer[10] = kHex[low & 0x0f]; + low >>= 4; + buffer[9] = kHex[low & 0x0f]; + low >>= 4; + buffer[8] = kHex[low & 0x0f]; + + buffer[5] = kHex[high & 0x0f]; + high >>= 4; + buffer[4] = kHex[high & 0x0f]; + high >>= 4; + buffer[3] = kHex[high & 0x0f]; + high >>= 4; + buffer[2] = kHex[high & 0x0f]; + + return StringPiece(buffer, 12); +} + +// If the given unicode code point needs escaping, then returns the +// escaped form. The returned StringPiece either points to statically +// pre-allocated char[] or to the given buffer. The input buffer needs +// to be at least 12 bytes long. +// +// If the given unicode code point does not need escaping, an empty +// StringPiece is returned. +StringPiece EscapeCodePoint(uint32_t cp, char* buffer) { + if (cp < 0xa0) return kCommonEscapes[cp]; + switch (cp) { + // These are not required by json spec + // but used to prevent security bugs in javascript. + case 0xfeff: // Zero width no-break space + case 0xfff9: // Interlinear annotation anchor + case 0xfffa: // Interlinear annotation separator + case 0xfffb: // Interlinear annotation terminator + + case 0x00ad: // Soft-hyphen + case 0x06dd: // Arabic end of ayah + case 0x070f: // Syriac abbreviation mark + case 0x17b4: // Khmer vowel inherent Aq + case 0x17b5: // Khmer vowel inherent Aa + return ToHex(cp, buffer); + + default: + if ((cp >= 0x0600 && cp <= 0x0603) || // Arabic signs + (cp >= 0x200b && cp <= 0x200f) || // Zero width etc. + (cp >= 0x2028 && cp <= 0x202e) || // Separators etc. + (cp >= 0x2060 && cp <= 0x2064) || // Invisible etc. + (cp >= 0x206a && cp <= 0x206f)) { // Shaping etc. + return ToHex(cp, buffer); + } + + if (cp == 0x000e0001 || // Language tag + (cp >= 0x0001d173 && cp <= 0x0001d17a) || // Music formatting + (cp >= 0x000e0020 && cp <= 0x000e007f)) { // TAG symbols + return ToSurrogateHex(cp, buffer); + } + } + return StringPiece(); +} + +// Tries to escape the given code point first. If the given code point +// does not need to be escaped, but force_output is true, then render +// the given multi-byte code point in UTF8 in the buffer and returns it. +StringPiece EscapeCodePoint(uint32_t cp, char* buffer, + bool force_output) { + StringPiece sp = EscapeCodePoint(cp, buffer); + if (force_output && sp.empty()) { + buffer[5] = (cp & 0x3f) | 0x80; + cp >>= 6; + if (cp <= 0x1f) { + buffer[4] = cp | 0xc0; + sp = StringPiece(buffer + 4, 2); + return sp; + } + buffer[4] = (cp & 0x3f) | 0x80; + cp >>= 6; + if (cp <= 0x0f) { + buffer[3] = cp | 0xe0; + sp = StringPiece(buffer + 3, 3); + return sp; + } + buffer[3] = (cp & 0x3f) | 0x80; + buffer[2] = ((cp >> 6) & 0x07) | 0xf0; + sp = StringPiece(buffer + 2, 4); + } + return sp; +} + +} // namespace + +void JsonEscaping::Escape(strings::ByteSource* input, + strings::ByteSink* output) { + char buffer[12] = "\\udead\\ubee"; + uint32_t cp = 0; // Current unicode code point. + int num_left = 0; // Num of chars to read to complete the code point. + while (input->Available() > 0) { + StringPiece str = input->Peek(); + StringPiece escaped; + int i = 0; + int num_read; + bool ok; + bool cp_was_split = num_left > 0; + // Loop until we encounter either + // i) a code point that needs to be escaped; or + // ii) a split code point is completely read; or + // iii) a character that is not a valid utf8; or + // iv) end of the StringPiece str is reached. + do { + ok = ReadCodePoint(str, i, &cp, &num_left, &num_read); + if (num_left > 0 || !ok) break; // case iii or iv + escaped = EscapeCodePoint(cp, buffer, cp_was_split); + if (!escaped.empty()) break; // case i or ii + i += num_read; + num_read = 0; + } while (i < str.length()); // case iv + // First copy the un-escaped prefix, if any, to the output ByteSink. + if (i > 0) input->CopyTo(output, i); + if (num_read > 0) input->Skip(num_read); + if (!ok) { + // Case iii: Report error. + // TODO(wpoon): Add error reporting. + num_left = 0; + } else if (num_left == 0 && !escaped.empty()) { + // Case i or ii: Append the escaped code point to the output ByteSink. + output->Append(escaped.data(), escaped.size()); + } + } + if (num_left > 0) { + // Treat as case iii: report error. + // TODO(wpoon): Add error reporting. + } +} + +void JsonEscaping::Escape(StringPiece input, strings::ByteSink* output) { + const size_t len = input.length(); + const char* p = input.data(); + + bool can_skip_escaping = true; + for (int i = 0; i < len; i++) { + char c = p[i]; + if (c < 0x20 || c >= 0x7F || c == '"' || c == '<' || c == '>' || + c == '\\') { + can_skip_escaping = false; + break; + } + } + + if (can_skip_escaping) { + output->Append(input.data(), input.length()); + } else { + strings::ArrayByteSource source(input); + Escape(&source, output); + } +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_escaping.h b/libs/protobuf/src/google/protobuf/util/internal/json_escaping.h new file mode 100644 index 0000000..7d54f22 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_escaping.h @@ -0,0 +1,98 @@ +// 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_UTIL_INTERNAL_JSON_ESCAPING_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_ESCAPING_H__ + +#include + +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +class JsonEscaping { + public: + // The minimum value of a unicode high-surrogate code unit in the utf-16 + // encoding. A high-surrogate is also known as a leading-surrogate. + // See http://www.unicode.org/glossary/#high_surrogate_code_unit + static constexpr uint16_t kMinHighSurrogate = 0xd800; + + // The maximum value of a unicide high-surrogate code unit in the utf-16 + // encoding. A high-surrogate is also known as a leading-surrogate. + // See http://www.unicode.org/glossary/#high_surrogate_code_unit + static constexpr uint16_t kMaxHighSurrogate = 0xdbff; + + // The minimum value of a unicode low-surrogate code unit in the utf-16 + // encoding. A low-surrogate is also known as a trailing-surrogate. + // See http://www.unicode.org/glossary/#low_surrogate_code_unit + static constexpr uint16_t kMinLowSurrogate = 0xdc00; + + // The maximum value of a unicode low-surrogate code unit in the utf-16 + // encoding. A low-surrogate is also known as a trailing surrogate. + // See http://www.unicode.org/glossary/#low_surrogate_code_unit + static constexpr uint16_t kMaxLowSurrogate = 0xdfff; + + // The minimum value of a unicode supplementary code point. + // See http://www.unicode.org/glossary/#supplementary_code_point + static constexpr uint32_t kMinSupplementaryCodePoint = 0x010000; + + // The minimum value of a unicode code point. + // See http://www.unicode.org/glossary/#code_point + static constexpr uint32_t kMinCodePoint = 0x000000; + + // The maximum value of a unicode code point. + // See http://www.unicode.org/glossary/#code_point + static constexpr uint32_t kMaxCodePoint = 0x10ffff; + + JsonEscaping() {} + virtual ~JsonEscaping() {} + + // Escape the given ByteSource to the given ByteSink. + static void Escape(strings::ByteSource* input, strings::ByteSink* output); + + // Escape the given ByteSource to the given ByteSink. + // This is optimized for the case where the string is all printable 7-bit + // ASCII and does not contain a few other characters (such as quotes). + static void Escape(StringPiece input, strings::ByteSink* output); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JsonEscaping); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_ESCAPING_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc new file mode 100644 index 0000000..1a86f00 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc @@ -0,0 +1,190 @@ +// 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +JsonObjectWriter::~JsonObjectWriter() { + if (element_ && !element_->is_root()) { + GOOGLE_LOG(WARNING) << "JsonObjectWriter was not fully closed."; + } +} + +JsonObjectWriter* JsonObjectWriter::StartObject(StringPiece name) { + WritePrefix(name); + WriteChar('{'); + PushObject(); + return this; +} + +JsonObjectWriter* JsonObjectWriter::EndObject() { + Pop(); + WriteChar('}'); + if (element() && element()->is_root()) NewLine(); + return this; +} + +JsonObjectWriter* JsonObjectWriter::StartList(StringPiece name) { + WritePrefix(name); + WriteChar('['); + PushArray(); + return this; +} + +JsonObjectWriter* JsonObjectWriter::EndList() { + Pop(); + WriteChar(']'); + if (element()->is_root()) NewLine(); + return this; +} + +JsonObjectWriter* JsonObjectWriter::RenderBool(StringPiece name, + bool value) { + return RenderSimple(name, value ? "true" : "false"); +} + +JsonObjectWriter* JsonObjectWriter::RenderInt32(StringPiece name, + int32_t value) { + return RenderSimple(name, StrCat(value)); +} + +JsonObjectWriter* JsonObjectWriter::RenderUint32(StringPiece name, + uint32_t value) { + return RenderSimple(name, StrCat(value)); +} + +JsonObjectWriter* JsonObjectWriter::RenderInt64(StringPiece name, + int64_t value) { + WritePrefix(name); + WriteChar('"'); + WriteRawString(StrCat(value)); + WriteChar('"'); + return this; +} + +JsonObjectWriter* JsonObjectWriter::RenderUint64(StringPiece name, + uint64_t value) { + WritePrefix(name); + WriteChar('"'); + WriteRawString(StrCat(value)); + WriteChar('"'); + return this; +} + +JsonObjectWriter* JsonObjectWriter::RenderDouble(StringPiece name, + double value) { + if (std::isfinite(value)) { + return RenderSimple(name, SimpleDtoa(value)); + } + + // Render quoted with NaN/Infinity-aware DoubleAsString. + return RenderString(name, DoubleAsString(value)); +} + +JsonObjectWriter* JsonObjectWriter::RenderFloat(StringPiece name, + float value) { + if (std::isfinite(value)) { + return RenderSimple(name, SimpleFtoa(value)); + } + + // Render quoted with NaN/Infinity-aware FloatAsString. + return RenderString(name, FloatAsString(value)); +} + +JsonObjectWriter* JsonObjectWriter::RenderString(StringPiece name, + StringPiece value) { + WritePrefix(name); + WriteChar('"'); + JsonEscaping::Escape(value, &sink_); + WriteChar('"'); + return this; +} + +JsonObjectWriter* JsonObjectWriter::RenderBytes(StringPiece name, + StringPiece value) { + WritePrefix(name); + std::string base64; + + if (use_websafe_base64_for_bytes_) + WebSafeBase64EscapeWithPadding(std::string(value), &base64); + else + Base64Escape(value, &base64); + + WriteChar('"'); + // TODO(wpoon): Consider a ByteSink solution that writes the base64 bytes + // directly to the stream, rather than first putting them + // into a string and then writing them to the stream. + stream_->WriteRaw(base64.data(), base64.size()); + WriteChar('"'); + return this; +} + +JsonObjectWriter* JsonObjectWriter::RenderNull(StringPiece name) { + return RenderSimple(name, "null"); +} + +JsonObjectWriter* JsonObjectWriter::RenderNullAsEmpty(StringPiece name) { + return RenderSimple(name, ""); +} + +void JsonObjectWriter::WritePrefix(StringPiece name) { + bool not_first = !element()->is_first(); + if (not_first) WriteChar(','); + if (not_first || !element()->is_root()) NewLine(); + if (!name.empty() || element()->is_json_object()) { + WriteChar('"'); + if (!name.empty()) { + JsonEscaping::Escape(name, &sink_); + } + WriteRawString("\":"); + if (!indent_string_.empty()) WriteChar(' '); + } +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.h b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.h new file mode 100644 index 0000000..cb7dff6 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter.h @@ -0,0 +1,278 @@ +// 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_UTIL_INTERNAL_JSON_OBJECTWRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_OBJECTWRITER_H__ + +#include +#include +#include + +#include +#include +#include + +// clang-format off +#include +// clang-format on + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +// An ObjectWriter implementation that outputs JSON. This ObjectWriter +// supports writing a compact form or a pretty printed form. +// +// Sample usage: +// string output; +// StringOutputStream* str_stream = new StringOutputStream(&output); +// CodedOutputStream* out_stream = new CodedOutputStream(str_stream); +// JsonObjectWriter* ow = new JsonObjectWriter(" ", out_stream); +// ow->StartObject("") +// ->RenderString("name", "value") +// ->RenderString("emptystring", string()) +// ->StartObject("nested") +// ->RenderInt64("light", 299792458); +// ->RenderDouble("pi", 3.141592653589793); +// ->EndObject() +// ->StartList("empty") +// ->EndList() +// ->EndObject(); +// +// And then the output string would become: +// { +// "name": "value", +// "emptystring": "", +// "nested": { +// "light": "299792458", +// "pi": 3.141592653589793 +// }, +// "empty": [] +// } +// +// JsonObjectWriter does not validate if calls actually result in valid JSON. +// For example, passing an empty name when one would be required won't result +// in an error, just an invalid output. +// +// Note that all int64 and uint64 are rendered as strings instead of numbers. +// This is because JavaScript parses numbers as 64-bit float thus int64 and +// uint64 would lose precision if rendered as numbers. +// +// JsonObjectWriter is thread-unsafe. +class PROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter { + public: + JsonObjectWriter(StringPiece indent_string, io::CodedOutputStream* out) + : element_(new Element(/*parent=*/nullptr, /*is_json_object=*/false)), + stream_(out), + sink_(out), + indent_string_(indent_string), + indent_char_('\0'), + indent_count_(0), + use_websafe_base64_for_bytes_(false) { + // See if we have a trivial sequence of indent characters. + if (!indent_string.empty()) { + indent_char_ = indent_string[0]; + indent_count_ = indent_string.length(); + for (int i = 1; i < indent_string.length(); i++) { + if (indent_char_ != indent_string_[i]) { + indent_char_ = '\0'; + indent_count_ = 0; + break; + } + } + } + } + ~JsonObjectWriter() override; + + // ObjectWriter methods. + JsonObjectWriter* StartObject(StringPiece name) override; + JsonObjectWriter* EndObject() override; + JsonObjectWriter* StartList(StringPiece name) override; + JsonObjectWriter* EndList() override; + JsonObjectWriter* RenderBool(StringPiece name, bool value) override; + JsonObjectWriter* RenderInt32(StringPiece name, int32_t value) override; + JsonObjectWriter* RenderUint32(StringPiece name, + uint32_t value) override; + JsonObjectWriter* RenderInt64(StringPiece name, int64_t value) override; + JsonObjectWriter* RenderUint64(StringPiece name, + uint64_t value) override; + JsonObjectWriter* RenderDouble(StringPiece name, double value) override; + JsonObjectWriter* RenderFloat(StringPiece name, float value) override; + JsonObjectWriter* RenderString(StringPiece name, + StringPiece value) override; + JsonObjectWriter* RenderBytes(StringPiece name, StringPiece value) override; + JsonObjectWriter* RenderNull(StringPiece name) override; + virtual JsonObjectWriter* RenderNullAsEmpty(StringPiece name); + + void set_use_websafe_base64_for_bytes(bool value) { + use_websafe_base64_for_bytes_ = value; + } + + protected: + class PROTOBUF_EXPORT Element : public BaseElement { + public: + Element(Element* parent, bool is_json_object) + : BaseElement(parent), + is_first_(true), + is_json_object_(is_json_object) {} + + // Called before each field of the Element is to be processed. + // Returns true if this is the first call (processing the first field). + bool is_first() { + if (is_first_) { + is_first_ = false; + return true; + } + return false; + } + + // Whether we are currently rendering inside a JSON object (i.e., between + // StartObject() and EndObject()). + bool is_json_object() const { return is_json_object_; } + + private: + bool is_first_; + bool is_json_object_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(Element); + }; + + Element* element() override { return element_.get(); } + + private: + class PROTOBUF_EXPORT ByteSinkWrapper : public strings::ByteSink { + public: + explicit ByteSinkWrapper(io::CodedOutputStream* stream) : stream_(stream) {} + ~ByteSinkWrapper() override {} + + // ByteSink methods. + void Append(const char* bytes, size_t n) override { + stream_->WriteRaw(bytes, n); + } + + private: + io::CodedOutputStream* stream_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSinkWrapper); + }; + + // Renders a simple value as a string. By default all non-string Render + // methods convert their argument to a string and call this method. This + // method can then be used to render the simple value without escaping it. + JsonObjectWriter* RenderSimple(StringPiece name, + StringPiece value) { + WritePrefix(name); + WriteRawString(value); + return this; + } + + // Pushes a new JSON array element to the stack. + void PushArray() { + element_.reset(new Element(element_.release(), /*is_json_object=*/false)); + } + + // Pushes a new JSON object element to the stack. + void PushObject() { + element_.reset(new Element(element_.release(), /*is_json_object=*/true)); + } + + // Pops an element off of the stack and deletes the popped element. + void Pop() { + bool needs_newline = !element_->is_first(); + element_.reset(element_->pop()); + if (needs_newline) NewLine(); + } + + // If pretty printing is enabled, this will write a newline to the output, + // followed by optional indentation. Otherwise this method is a noop. + void NewLine() { + if (!indent_string_.empty()) { + size_t len = sizeof('\n') + (indent_string_.size() * element()->level()); + + // Take the slow-path if we don't have sufficient characters remaining in + // our buffer or we have a non-trivial indent string which would prevent + // us from using memset. + uint8_t* out = nullptr; + if (indent_count_ > 0) { + out = stream_->GetDirectBufferForNBytesAndAdvance(len); + } + + if (out != nullptr) { + out[0] = '\n'; + memset(&out[1], indent_char_, len - 1); + } else { + // Slow path, no contiguous output buffer available. + WriteChar('\n'); + for (int i = 0; i < element()->level(); i++) { + stream_->WriteRaw(indent_string_.c_str(), indent_string_.length()); + } + } + } + } + + // Writes a prefix. This will write out any pretty printing and + // commas that are required, followed by the name and a ':' if + // the name is not null. + void WritePrefix(StringPiece name); + + // Writes an individual character to the output. + void WriteChar(const char c) { stream_->WriteRaw(&c, sizeof(c)); } + + // Writes a string to the output. + void WriteRawString(StringPiece s) { + stream_->WriteRaw(s.data(), s.length()); + } + + std::unique_ptr element_; + io::CodedOutputStream* stream_; + ByteSinkWrapper sink_; + const std::string indent_string_; + + // For the common case of indent being a single character repeated. + char indent_char_; + int indent_count_; + + // Whether to use regular or websafe base64 encoding for byte fields. Defaults + // to regular base64 encoding. + bool use_websafe_base64_for_bytes_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_OBJECTWRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc new file mode 100644 index 0000000..8acf2c5 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc @@ -0,0 +1,315 @@ +// 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 + +#include + +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using io::CodedOutputStream; +using io::StringOutputStream; + +class JsonObjectWriterTest : public ::testing::Test { + protected: + JsonObjectWriterTest() + : str_stream_(new StringOutputStream(&output_)), + out_stream_(new CodedOutputStream(str_stream_)), + ow_(nullptr) {} + + ~JsonObjectWriterTest() override { delete ow_; } + + std::string CloseStreamAndGetString() { + delete out_stream_; + delete str_stream_; + return output_; + } + + std::string output_; + StringOutputStream* const str_stream_; + CodedOutputStream* const out_stream_; + JsonObjectWriter* ow_; +}; + +TEST_F(JsonObjectWriterTest, EmptyRootObject) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("")->EndObject(); + EXPECT_EQ("{}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, EmptyObject) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->RenderString("test", "value") + ->StartObject("empty") + ->EndObject() + ->EndObject(); + EXPECT_EQ("{\"test\":\"value\",\"empty\":{}}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, EmptyRootList) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartList("")->EndList(); + EXPECT_EQ("[]", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, EmptyList) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->RenderString("test", "value") + ->StartList("empty") + ->EndList() + ->EndObject(); + EXPECT_EQ("{\"test\":\"value\",\"empty\":[]}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, EmptyObjectKey) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("")->RenderString("", "value")->EndObject(); + EXPECT_EQ("{\"\":\"value\"}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, ObjectInObject) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->StartObject("nested") + ->RenderString("field", "value") + ->EndObject() + ->EndObject(); + EXPECT_EQ("{\"nested\":{\"field\":\"value\"}}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, ListInObject) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->StartList("nested") + ->RenderString("", "value") + ->EndList() + ->EndObject(); + EXPECT_EQ("{\"nested\":[\"value\"]}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, ObjectInList) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartList("") + ->StartObject("") + ->RenderString("field", "value") + ->EndObject() + ->EndList(); + EXPECT_EQ("[{\"field\":\"value\"}]", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, ListInList) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartList("") + ->StartList("") + ->RenderString("", "value") + ->EndList() + ->EndList(); + EXPECT_EQ("[[\"value\"]]", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, RenderPrimitives) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->RenderBool("bool", true) + ->RenderDouble("double", std::numeric_limits::max()) + ->RenderFloat("float", std::numeric_limits::max()) + ->RenderInt32("int", std::numeric_limits::min()) + ->RenderInt64("long", std::numeric_limits::min()) + ->RenderBytes("bytes", "abracadabra") + ->RenderString("string", "string") + ->RenderBytes("emptybytes", "") + ->RenderString("emptystring", std::string()) + ->EndObject(); + EXPECT_EQ( + "{\"bool\":true," + "\"double\":" + + ValueAsString(std::numeric_limits::max()) + + "," + "\"float\":" + + ValueAsString(std::numeric_limits::max()) + + "," + "\"int\":-2147483648," + "\"long\":\"-9223372036854775808\"," + "\"bytes\":\"YWJyYWNhZGFicmE=\"," + "\"string\":\"string\"," + "\"emptybytes\":\"\"," + "\"emptystring\":\"\"}", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, BytesEncodesAsNonWebSafeBase64) { + std::string s; + s.push_back('\377'); + s.push_back('\357'); + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("")->RenderBytes("bytes", s)->EndObject(); + // Non-web-safe would encode this as "/+8=" + EXPECT_EQ("{\"bytes\":\"/+8=\"}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, PrettyPrintList) { + ow_ = new JsonObjectWriter(" ", out_stream_); + ow_->StartObject("") + ->StartList("items") + ->RenderString("", "item1") + ->RenderString("", "item2") + ->RenderString("", "item3") + ->EndList() + ->StartList("empty") + ->EndList() + ->EndObject(); + EXPECT_EQ( + "{\n" + " \"items\": [\n" + " \"item1\",\n" + " \"item2\",\n" + " \"item3\"\n" + " ],\n" + " \"empty\": []\n" + "}\n", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, PrettyPrintObject) { + ow_ = new JsonObjectWriter(" ", out_stream_); + ow_->StartObject("") + ->StartObject("items") + ->RenderString("key1", "item1") + ->RenderString("key2", "item2") + ->RenderString("key3", "item3") + ->EndObject() + ->StartObject("empty") + ->EndObject() + ->EndObject(); + EXPECT_EQ( + "{\n" + " \"items\": {\n" + " \"key1\": \"item1\",\n" + " \"key2\": \"item2\",\n" + " \"key3\": \"item3\"\n" + " },\n" + " \"empty\": {}\n" + "}\n", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, PrettyPrintEmptyObjectInEmptyList) { + ow_ = new JsonObjectWriter(" ", out_stream_); + ow_->StartObject("") + ->StartList("list") + ->StartObject("") + ->EndObject() + ->EndList() + ->EndObject(); + EXPECT_EQ( + "{\n" + " \"list\": [\n" + " {}\n" + " ]\n" + "}\n", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, PrettyPrintDoubleIndent) { + ow_ = new JsonObjectWriter(" ", out_stream_); + ow_->StartObject("") + ->RenderBool("bool", true) + ->RenderInt32("int", 42) + ->EndObject(); + EXPECT_EQ( + "{\n" + " \"bool\": true,\n" + " \"int\": 42\n" + "}\n", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, StringsEscapedAndEnclosedInDoubleQuotes) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("")->RenderString("string", "'<>&\\\"\r\n")->EndObject(); + EXPECT_EQ("{\"string\":\"'\\u003c\\u003e&\\\\\\\"\\r\\n\"}", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, Stringification) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->RenderDouble("double_nan", std::numeric_limits::quiet_NaN()) + ->RenderFloat("float_nan", std::numeric_limits::quiet_NaN()) + ->RenderDouble("double_pos", std::numeric_limits::infinity()) + ->RenderFloat("float_pos", std::numeric_limits::infinity()) + ->RenderDouble("double_neg", -std::numeric_limits::infinity()) + ->RenderFloat("float_neg", -std::numeric_limits::infinity()) + ->EndObject(); + EXPECT_EQ( + "{\"double_nan\":\"NaN\"," + "\"float_nan\":\"NaN\"," + "\"double_pos\":\"Infinity\"," + "\"float_pos\":\"Infinity\"," + "\"double_neg\":\"-Infinity\"," + "\"float_neg\":\"-Infinity\"}", + CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, TestRegularByteEncoding) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->StartObject("") + ->RenderBytes("bytes", "\x03\xef\xc0") + ->EndObject(); + + // Test that we get regular (non websafe) base64 encoding on byte fields by + // default. + EXPECT_EQ("{\"bytes\":\"A+/A\"}", CloseStreamAndGetString()); +} + +TEST_F(JsonObjectWriterTest, TestWebsafeByteEncoding) { + ow_ = new JsonObjectWriter("", out_stream_); + ow_->set_use_websafe_base64_for_bytes(true); + ow_->StartObject("") + ->RenderBytes("bytes", "\x03\xef\xc0\x10") + ->EndObject(); + + // Test that we get websafe base64 encoding when explicitly asked. + EXPECT_EQ("{\"bytes\":\"A-_AEA==\"}", CloseStreamAndGetString()); +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc new file mode 100644 index 0000000..5c34dbc --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc @@ -0,0 +1,995 @@ +// 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 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace util { + +namespace converter { + +// Number of digits in an escaped UTF-16 code unit ('\\' 'u' X X X X) +static const int kUnicodeEscapedLength = 6; + +static const int kDefaultMaxRecursionDepth = 100; + +// These cannot be constexpr for portability with VS2015. +static const StringPiece kKeywordTrue = "true"; +static const StringPiece kKeywordFalse = "false"; +static const StringPiece kKeywordNull = "null"; + +inline bool IsLetter(char c) { + return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || (c == '_') || + (c == '$'); +} + +inline bool IsAlphanumeric(char c) { + return IsLetter(c) || ('0' <= c && c <= '9'); +} + +// Indicates a character may not be part of an unquoted key. +inline bool IsKeySeparator(char c) { + return (ascii_isspace(c) || c == '"' || c == '\'' || c == '{' || + c == '}' || c == '[' || c == ']' || c == ':' || c == ','); +} + +inline void ReplaceInvalidCodePoints(StringPiece str, + const std::string& replacement, + std::string* dst) { + while (!str.empty()) { + int n_valid_bytes = internal::UTF8SpnStructurallyValid(str); + StringPiece valid_part = str.substr(0, n_valid_bytes); + StrAppend(dst, valid_part); + + if (n_valid_bytes == str.size()) { + break; + } + + // Append replacement value. + StrAppend(dst, replacement); + + // Move past valid bytes + one invalid byte. + str.remove_prefix(n_valid_bytes + 1); + } +} + +static bool ConsumeKey(StringPiece* input, StringPiece* key) { + if (input->empty() || !IsLetter((*input)[0])) return false; + int len = 1; + for (; len < input->size(); ++len) { + if (!IsAlphanumeric((*input)[len])) { + break; + } + } + *key = StringPiece(input->data(), len); + *input = StringPiece(input->data() + len, input->size() - len); + return true; +} + +// Same as 'ConsumeKey', but allows a widened set of key characters. +static bool ConsumeKeyPermissive(StringPiece* input, + StringPiece* key) { + if (input->empty() || !IsLetter((*input)[0])) return false; + int len = 1; + for (; len < input->size(); ++len) { + if (IsKeySeparator((*input)[len])) { + break; + } + } + *key = StringPiece(input->data(), len); + *input = StringPiece(input->data() + len, input->size() - len); + return true; +} + +static bool MatchKey(StringPiece input) { + return !input.empty() && IsLetter(input[0]); +} + +JsonStreamParser::JsonStreamParser(ObjectWriter* ow) + : ow_(ow), + stack_(), + leftover_(), + json_(), + p_(), + key_(), + key_storage_(), + finishing_(false), + seen_non_whitespace_(false), + allow_no_root_element_(false), + parsed_(), + parsed_storage_(), + string_open_(0), + chunk_storage_(), + coerce_to_utf8_(false), + utf8_replacement_character_(" "), + allow_empty_null_(false), + allow_permissive_key_naming_(false), + loose_float_number_conversion_(false), + recursion_depth_(0), + max_recursion_depth_(kDefaultMaxRecursionDepth) { + // Initialize the stack with a single value to be parsed. + stack_.push(VALUE); +} + +JsonStreamParser::~JsonStreamParser() {} + + +util::Status JsonStreamParser::Parse(StringPiece json) { + StringPiece chunk = json; + // If we have leftovers from a previous chunk, append the new chunk to it + // and create a new StringPiece pointing at the string's data. This could + // be large but we rely on the chunks to be small, assuming they are + // fragments of a Cord. + if (!leftover_.empty()) { + // Don't point chunk to leftover_ because leftover_ will be updated in + // ParseChunk(chunk). + chunk_storage_.swap(leftover_); + StrAppend(&chunk_storage_, json); + chunk = StringPiece(chunk_storage_); + } + + // Find the structurally valid UTF8 prefix and parse only that. + int n = internal::UTF8SpnStructurallyValid(chunk); + if (n > 0) { + util::Status status = ParseChunk(chunk.substr(0, n)); + + // Any leftover characters are stashed in leftover_ for later parsing when + // there is more data available. + StrAppend(&leftover_, chunk.substr(n)); + return status; + } else { + leftover_.assign(chunk.data(), chunk.size()); + return util::Status(); + } +} + +util::Status JsonStreamParser::FinishParse() { + // If we do not expect anything and there is nothing left to parse we're all + // done. + if (stack_.empty() && leftover_.empty()) { + return util::Status(); + } + + // Lifetime needs to last until RunParser returns, so keep this variable + // outside of the coerce_to_utf8 block. + std::unique_ptr scratch; + + bool is_valid_utf8 = internal::IsStructurallyValidUTF8(leftover_); + if (coerce_to_utf8_ && !is_valid_utf8) { + scratch.reset(new std::string); + scratch->reserve(leftover_.size() * utf8_replacement_character_.size()); + ReplaceInvalidCodePoints(leftover_, utf8_replacement_character_, + scratch.get()); + p_ = json_ = *scratch; + } else { + p_ = json_ = leftover_; + if (!is_valid_utf8) { + return ReportFailure("Encountered non UTF-8 code points.", + ParseErrorType::NON_UTF_8); + } + } + + // Parse the remainder in finishing mode, which reports errors for things like + // unterminated strings or unknown tokens that would normally be retried. + finishing_ = true; + util::Status result = RunParser(); + if (result.ok()) { + SkipWhitespace(); + if (!p_.empty()) { + result = + ReportFailure("Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } + } + return result; +} + +util::Status JsonStreamParser::ParseChunk(StringPiece chunk) { + // Do not do any work if the chunk is empty. + if (chunk.empty()) return util::Status(); + + p_ = json_ = chunk; + + finishing_ = false; + util::Status result = RunParser(); + if (!result.ok()) return result; + + SkipWhitespace(); + if (p_.empty()) { + // If we parsed everything we had, clear the leftover. + leftover_.clear(); + } else { + // If we do not expect anything i.e. stack is empty, and we have non-empty + // string left to parse, we report an error. + if (stack_.empty()) { + return ReportFailure( + "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } + // If we expect future data i.e. stack is non-empty, and we have some + // unparsed data left, we save it for later parse. + leftover_ = std::string(p_); + } + return util::Status(); +} + +bool JsonStreamParser::IsInputAllWhiteSpaces(TokenType type) { + // Conclude the whole input is full of white spaces by: + // - it is at the finishing stage + // - we have run out of the input data + // - haven't seen non-whitespace char so far + if (finishing_ && p_.empty() && type == UNKNOWN && !seen_non_whitespace_) { + return true; + } + return false; +} + +util::Status JsonStreamParser::RunParser() { + while (!stack_.empty()) { + ParseType type = stack_.top(); + TokenType t = (string_open_ == 0) ? GetNextTokenType() : BEGIN_STRING; + stack_.pop(); + util::Status result; + switch (type) { + case VALUE: + if (allow_no_root_element_ && IsInputAllWhiteSpaces(t)) { + return util::Status(); + } + result = ParseValue(t); + break; + + case OBJ_MID: + result = ParseObjectMid(t); + break; + + case ENTRY: + result = ParseEntry(t); + break; + + case ENTRY_MID: + result = ParseEntryMid(t); + break; + + case ARRAY_VALUE: + result = ParseArrayValue(t); + break; + + case ARRAY_MID: + result = ParseArrayMid(t); + break; + + default: + result = + util::InternalError(StrCat("Unknown parse type: ", type)); + break; + } + if (!result.ok()) { + // If we were cancelled, save our state and try again later. + if (!finishing_ && util::IsCancelled(result)) { + stack_.push(type); + // If we have a key we still need to render, make sure to save off the + // contents in our own storage. + if (!key_.empty() && key_storage_.empty()) { + StrAppend(&key_storage_, key_); + key_ = StringPiece(key_storage_); + } + result = util::Status(); + } + return result; + } + } + return util::Status(); +} + +util::Status JsonStreamParser::ParseValue(TokenType type) { + switch (type) { + case BEGIN_OBJECT: + return HandleBeginObject(); + case BEGIN_ARRAY: + return HandleBeginArray(); + case BEGIN_STRING: + return ParseString(); + case BEGIN_NUMBER: + return ParseNumber(); + case BEGIN_TRUE: + return ParseTrue(); + case BEGIN_FALSE: + return ParseFalse(); + case BEGIN_NULL: + return ParseNull(); + case UNKNOWN: + return ReportUnknown("Expected a value.", ParseErrorType::EXPECTED_VALUE); + default: { + // Special case for having been cut off while parsing, wait for more data. + // This handles things like 'fals' being at the end of the string, we + // don't know if the next char would be e, completing it, or something + // else, making it invalid. + if (!finishing_ && p_.length() < kKeywordFalse.length()) { + return util::CancelledError(""); + } + + if (allow_empty_null_ && IsEmptyNullAllowed(type)) { + return ParseEmptyNull(); + } + return ReportFailure("Unexpected token.", + ParseErrorType::UNEXPECTED_TOKEN); + } + } +} + +util::Status JsonStreamParser::ParseString() { + util::Status result = ParseStringHelper(); + if (result.ok()) { + ow_->RenderString(key_, parsed_); + key_ = StringPiece(); + parsed_ = StringPiece(); + parsed_storage_.clear(); + } + return result; +} + +util::Status JsonStreamParser::ParseStringHelper() { + // If we haven't seen the start quote, grab it and remember it for later. + if (string_open_ == 0) { + string_open_ = *p_.data(); + GOOGLE_DCHECK(string_open_ == '\"' || string_open_ == '\''); + Advance(); + } + // Track where we last copied data from so we can minimize copying. + const char* last = p_.data(); + while (!p_.empty()) { + const char* data = p_.data(); + if (*data == '\\') { + // We're about to handle an escape, copy all bytes from last to data. + if (last < data) { + parsed_storage_.append(last, data - last); + } + // If we ran out of string after the \, cancel or report an error + // depending on if we expect more data later. + if (p_.length() == 1) { + if (!finishing_) { + return util::CancelledError(""); + } + return ReportFailure("Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } + // Parse a unicode escape if we found \u in the string. + if (data[1] == 'u') { + util::Status result = ParseUnicodeEscape(); + if (!result.ok()) { + return result; + } + // Move last pointer past the unicode escape and continue. + last = p_.data(); + continue; + } + // Handle the standard set of backslash-escaped characters. + switch (data[1]) { + case 'b': + parsed_storage_.push_back('\b'); + break; + case 'f': + parsed_storage_.push_back('\f'); + break; + case 'n': + parsed_storage_.push_back('\n'); + break; + case 'r': + parsed_storage_.push_back('\r'); + break; + case 't': + parsed_storage_.push_back('\t'); + break; + case 'v': + parsed_storage_.push_back('\v'); + break; + default: + parsed_storage_.push_back(data[1]); + } + // We handled two characters, so advance past them and continue. + p_.remove_prefix(2); + last = p_.data(); + continue; + } + // If we found the closing quote note it, advance past it, and return. + if (*data == string_open_) { + // If we didn't copy anything, reuse the input buffer. + if (parsed_storage_.empty()) { + parsed_ = StringPiece(last, data - last); + } else { + if (last < data) { + parsed_storage_.append(last, data - last); + } + parsed_ = StringPiece(parsed_storage_); + } + // Clear the quote char so next time we try to parse a string we'll + // start fresh. + string_open_ = 0; + Advance(); + return util::Status(); + } + // Normal character, just advance past it. + Advance(); + } + // If we ran out of characters, copy over what we have so far. + if (last < p_.data()) { + parsed_storage_.append(last, p_.data() - last); + } + // If we didn't find the closing quote but we expect more data, cancel for now + if (!finishing_) { + return util::CancelledError(""); + } + // End of string reached without a closing quote, report an error. + string_open_ = 0; + return ReportFailure("Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); +} + +// Converts a unicode escaped character to a decimal value stored in a char32 +// for use in UTF8 encoding utility. We assume that str begins with \uhhhh and +// convert that from the hex number to a decimal value. +// +// There are some security exploits with UTF-8 that we should be careful of: +// - http://www.unicode.org/reports/tr36/#UTF-8_Exploit +// - http://sites/intl-eng/design-guide/core-application +util::Status JsonStreamParser::ParseUnicodeEscape() { + if (p_.length() < kUnicodeEscapedLength) { + if (!finishing_) { + return util::CancelledError(""); + } + return ReportFailure("Illegal hex string.", + ParseErrorType::ILLEGAL_HEX_STRING); + } + GOOGLE_DCHECK_EQ('\\', p_.data()[0]); + GOOGLE_DCHECK_EQ('u', p_.data()[1]); + uint32_t code = 0; + for (int i = 2; i < kUnicodeEscapedLength; ++i) { + if (!isxdigit(p_.data()[i])) { + return ReportFailure("Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } + code = (code << 4) + hex_digit_to_int(p_.data()[i]); + } + if (code >= JsonEscaping::kMinHighSurrogate && + code <= JsonEscaping::kMaxHighSurrogate) { + if (p_.length() < 2 * kUnicodeEscapedLength) { + if (!finishing_) { + return util::CancelledError(""); + } + if (!coerce_to_utf8_) { + return ReportFailure("Missing low surrogate.", + ParseErrorType::MISSING_LOW_SURROGATE); + } + } else if (p_.data()[kUnicodeEscapedLength] == '\\' && + p_.data()[kUnicodeEscapedLength + 1] == 'u') { + uint32_t low_code = 0; + for (int i = kUnicodeEscapedLength + 2; i < 2 * kUnicodeEscapedLength; + ++i) { + if (!isxdigit(p_.data()[i])) { + return ReportFailure("Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } + low_code = (low_code << 4) + hex_digit_to_int(p_.data()[i]); + } + if (low_code >= JsonEscaping::kMinLowSurrogate && + low_code <= JsonEscaping::kMaxLowSurrogate) { + // Convert UTF-16 surrogate pair to 21-bit Unicode codepoint. + code = (((code & 0x3FF) << 10) | (low_code & 0x3FF)) + + JsonEscaping::kMinSupplementaryCodePoint; + // Advance past the first code unit escape. + p_.remove_prefix(kUnicodeEscapedLength); + } else if (!coerce_to_utf8_) { + return ReportFailure("Invalid low surrogate.", + ParseErrorType::INVALID_LOW_SURROGATE); + } + } else if (!coerce_to_utf8_) { + return ReportFailure("Missing low surrogate.", + ParseErrorType::MISSING_LOW_SURROGATE); + } + } + if (!coerce_to_utf8_ && !IsValidCodePoint(code)) { + return ReportFailure("Invalid unicode code point.", + ParseErrorType::INVALID_UNICODE); + } + char buf[UTFmax]; + int len = EncodeAsUTF8Char(code, buf); + // Advance past the [final] code unit escape. + p_.remove_prefix(kUnicodeEscapedLength); + parsed_storage_.append(buf, len); + return util::Status(); +} + +util::Status JsonStreamParser::ParseNumber() { + NumberResult number; + util::Status result = ParseNumberHelper(&number); + if (result.ok()) { + switch (number.type) { + case NumberResult::DOUBLE: + ow_->RenderDouble(key_, number.double_val); + key_ = StringPiece(); + break; + + case NumberResult::INT: + ow_->RenderInt64(key_, number.int_val); + key_ = StringPiece(); + break; + + case NumberResult::UINT: + ow_->RenderUint64(key_, number.uint_val); + key_ = StringPiece(); + break; + + default: + return ReportFailure("Unable to parse number.", + ParseErrorType::UNABLE_TO_PARSE_NUMBER); + } + } + return result; +} + +util::Status JsonStreamParser::ParseDoubleHelper(const std::string& number, + NumberResult* result) { + if (!safe_strtod(number, &result->double_val)) { + return ReportFailure("Unable to parse number.", + ParseErrorType::UNABLE_TO_PARSE_NUMBER); + } + if (!loose_float_number_conversion_ && !std::isfinite(result->double_val)) { + return ReportFailure("Number exceeds the range of double.", + ParseErrorType::NUMBER_EXCEEDS_RANGE_DOUBLE); + } + result->type = NumberResult::DOUBLE; + return util::Status(); +} + +util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) { + const char* data = p_.data(); + int length = p_.length(); + + // Look for the first non-numeric character, or the end of the string. + int index = 0; + bool floating = false; + bool negative = data[index] == '-'; + // Find the first character that cannot be part of the number. Along the way + // detect if the number needs to be parsed as a double. + // Note that this restricts numbers to the JSON specification, so for example + // we do not support hex or octal notations. + for (; index < length; ++index) { + char c = data[index]; + if (isdigit(c)) continue; + if (c == '.' || c == 'e' || c == 'E') { + floating = true; + continue; + } + if (c == '+' || c == '-' || c == 'x') continue; + // Not a valid number character, break out. + break; + } + + // If the entire input is a valid number, and we may have more content in the + // future, we abort for now and resume when we know more. + if (index == length && !finishing_) { + return util::CancelledError(""); + } + + // Create a string containing just the number, so we can use safe_strtoX + std::string number = std::string(p_.substr(0, index)); + + // Floating point number, parse as a double. + if (floating) { + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); + } + return status; + } + + // Positive non-floating point number, parse as a uint64_t. + if (!negative) { + // Octal/Hex numbers are not valid JSON values. + if (number.length() >= 2 && number[0] == '0') { + return ReportFailure( + "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } + if (safe_strtou64(number, &result->uint_val)) { + result->type = NumberResult::UINT; + p_.remove_prefix(index); + return util::Status(); + } else { + // If the value is too large, parse it as double. + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); + } + return status; + } + } + + // Octal/Hex numbers are not valid JSON values. + if (number.length() >= 3 && number[1] == '0') { + return ReportFailure( + "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } + // Negative non-floating point number, parse as an int64_t. + if (safe_strto64(number, &result->int_val)) { + result->type = NumberResult::INT; + p_.remove_prefix(index); + return util::Status(); + } else { + // If the value is too large, parse it as double. + util::Status status = ParseDoubleHelper(number, result); + if (status.ok()) { + p_.remove_prefix(index); + } + return status; + } +} + +util::Status JsonStreamParser::HandleBeginObject() { + GOOGLE_DCHECK_EQ('{', *p_.data()); + Advance(); + ow_->StartObject(key_); + auto status = IncrementRecursionDepth(key_); + if (!status.ok()) { + return status; + } + key_ = StringPiece(); + stack_.push(ENTRY); + return util::Status(); +} + +util::Status JsonStreamParser::ParseObjectMid(TokenType type) { + if (type == UNKNOWN) { + return ReportUnknown("Expected , or } after key:value pair.", + ParseErrorType::EXPECTED_COMMA_OR_BRACES); + } + + // Object is complete, advance past the comma and render the EndObject. + if (type == END_OBJECT) { + Advance(); + ow_->EndObject(); + --recursion_depth_; + return util::Status(); + } + // Found a comma, advance past it and get ready for an entry. + if (type == VALUE_SEPARATOR) { + Advance(); + stack_.push(ENTRY); + return util::Status(); + } + // Illegal token after key:value pair. + return ReportFailure("Expected , or } after key:value pair.", + ParseErrorType::EXPECTED_COMMA_OR_BRACES); +} + +util::Status JsonStreamParser::ParseEntry(TokenType type) { + if (type == UNKNOWN) { + return ReportUnknown("Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } + + // Close the object and return. This allows for trailing commas. + if (type == END_OBJECT) { + ow_->EndObject(); + Advance(); + --recursion_depth_; + return util::Status(); + } + + util::Status result; + if (type == BEGIN_STRING) { + // Key is a string (standard JSON), parse it and store the string. + result = ParseStringHelper(); + if (result.ok()) { + key_storage_.clear(); + if (!parsed_storage_.empty()) { + parsed_storage_.swap(key_storage_); + key_ = StringPiece(key_storage_); + } else { + key_ = parsed_; + } + parsed_ = StringPiece(); + } + } else if (type == BEGIN_KEY) { + // Key is a bare key (back compat), create a StringPiece pointing to it. + result = ParseKey(); + } else if (type == BEGIN_NULL || type == BEGIN_TRUE || type == BEGIN_FALSE) { + // Key may be a bare key that begins with a reserved word. + result = ParseKey(); + if (result.ok() && (key_ == kKeywordNull || key_ == kKeywordTrue || + key_ == kKeywordFalse)) { + result = ReportFailure("Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } + } else { + // Unknown key type, report an error. + result = ReportFailure("Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } + // On success we next expect an entry mid ':' then an object mid ',' or '}' + if (result.ok()) { + stack_.push(OBJ_MID); + stack_.push(ENTRY_MID); + } + return result; +} + +util::Status JsonStreamParser::ParseEntryMid(TokenType type) { + if (type == UNKNOWN) { + return ReportUnknown("Expected : between key:value pair.", + ParseErrorType::EXPECTED_COLON); + } + if (type == ENTRY_SEPARATOR) { + Advance(); + stack_.push(VALUE); + return util::Status(); + } + return ReportFailure("Expected : between key:value pair.", + ParseErrorType::EXPECTED_COLON); +} + +util::Status JsonStreamParser::HandleBeginArray() { + GOOGLE_DCHECK_EQ('[', *p_.data()); + Advance(); + ow_->StartList(key_); + key_ = StringPiece(); + stack_.push(ARRAY_VALUE); + return util::Status(); +} + +util::Status JsonStreamParser::ParseArrayValue(TokenType type) { + if (type == UNKNOWN) { + return ReportUnknown("Expected a value or ] within an array.", + ParseErrorType::EXPECTED_VALUE_OR_BRACKET); + } + + if (type == END_ARRAY) { + ow_->EndList(); + Advance(); + return util::Status(); + } + + // The ParseValue call may push something onto the stack so we need to make + // sure an ARRAY_MID is after it, so we push it on now. Also, the parsing of + // empty-null array value is relying on this ARRAY_MID token. + stack_.push(ARRAY_MID); + util::Status result = ParseValue(type); + if (util::IsCancelled(result)) { + // If we were cancelled, pop back off the ARRAY_MID so we don't try to + // push it on again when we try over. + stack_.pop(); + } + return result; +} + +util::Status JsonStreamParser::ParseArrayMid(TokenType type) { + if (type == UNKNOWN) { + return ReportUnknown("Expected , or ] after array value.", + ParseErrorType::EXPECTED_COMMA_OR_BRACKET); + } + + if (type == END_ARRAY) { + ow_->EndList(); + Advance(); + return util::Status(); + } + + // Found a comma, advance past it and expect an array value next. + if (type == VALUE_SEPARATOR) { + Advance(); + stack_.push(ARRAY_VALUE); + return util::Status(); + } + // Illegal token after array value. + return ReportFailure("Expected , or ] after array value.", + ParseErrorType::EXPECTED_COMMA_OR_BRACKET); +} + +util::Status JsonStreamParser::ParseTrue() { + ow_->RenderBool(key_, true); + key_ = StringPiece(); + p_.remove_prefix(kKeywordTrue.length()); + return util::Status(); +} + +util::Status JsonStreamParser::ParseFalse() { + ow_->RenderBool(key_, false); + key_ = StringPiece(); + p_.remove_prefix(kKeywordFalse.length()); + return util::Status(); +} + +util::Status JsonStreamParser::ParseNull() { + ow_->RenderNull(key_); + key_ = StringPiece(); + p_.remove_prefix(kKeywordNull.length()); + return util::Status(); +} + +util::Status JsonStreamParser::ParseEmptyNull() { + ow_->RenderNull(key_); + key_ = StringPiece(); + return util::Status(); +} + +bool JsonStreamParser::IsEmptyNullAllowed(TokenType type) { + if (stack_.empty()) return false; + return (stack_.top() == ARRAY_MID && type == VALUE_SEPARATOR) || + stack_.top() == OBJ_MID; +} + +util::Status JsonStreamParser::ReportFailure(StringPiece message, + ParseErrorType parse_code) { + (void)parse_code; // Parameter is used in Google-internal code. + static const int kContextLength = 20; + const char* p_start = p_.data(); + const char* json_start = json_.data(); + const char* begin = std::max(p_start - kContextLength, json_start); + const char* end = + std::min(p_start + kContextLength, json_start + json_.size()); + StringPiece segment(begin, end - begin); + std::string location(p_start - begin, ' '); + location.push_back('^'); + auto status = util::InvalidArgumentError( + StrCat(message, "\n", segment, "\n", location)); + return status; +} + +util::Status JsonStreamParser::ReportUnknown(StringPiece message, + ParseErrorType parse_code) { + // If we aren't finishing the parse, cancel parsing and try later. + if (!finishing_) { + return util::CancelledError(""); + } + if (p_.empty()) { + return ReportFailure(StrCat("Unexpected end of string. ", message), + parse_code); + } + return ReportFailure(message, parse_code); +} + +util::Status JsonStreamParser::IncrementRecursionDepth( + StringPiece key) const { + if (++recursion_depth_ > max_recursion_depth_) { + return util::InvalidArgumentError(StrCat( + "Message too deep. Max recursion depth reached for key '", key, "'")); + } + return util::Status(); +} + +void JsonStreamParser::SkipWhitespace() { + while (!p_.empty() && ascii_isspace(*p_.data())) { + Advance(); + } + if (!p_.empty() && !ascii_isspace(*p_.data())) { + seen_non_whitespace_ = true; + } +} + +void JsonStreamParser::Advance() { + // Advance by moving one UTF8 character while making sure we don't go beyond + // the length of StringPiece. + p_.remove_prefix(std::min( + p_.length(), UTF8FirstLetterNumBytes(p_.data(), p_.length()))); +} + +util::Status JsonStreamParser::ParseKey() { + StringPiece original = p_; + + if (allow_permissive_key_naming_) { + if (!ConsumeKeyPermissive(&p_, &key_)) { + return ReportFailure("Invalid key or variable name.", + ParseErrorType::INVALID_KEY_OR_VARIABLE_NAME); + } + } else { + if (!ConsumeKey(&p_, &key_)) { + return ReportFailure("Invalid key or variable name.", + ParseErrorType::INVALID_KEY_OR_VARIABLE_NAME); + } + } + + // If we consumed everything but expect more data, reset p_ and cancel since + // we can't know if the key was complete or not. + if (!finishing_ && p_.empty()) { + p_ = original; + return util::CancelledError(""); + } + // Since we aren't using the key storage, clear it out. + key_storage_.clear(); + return util::Status(); +} + +JsonStreamParser::TokenType JsonStreamParser::GetNextTokenType() { + SkipWhitespace(); + + int size = p_.size(); + if (size == 0) { + // If we ran out of data, report unknown and we'll place the previous parse + // type onto the stack and try again when we have more data. + return UNKNOWN; + } + // TODO(sven): Split this method based on context since different contexts + // support different tokens. Would slightly speed up processing? + const char* data = p_.data(); + StringPiece data_view = StringPiece(data, size); + if (*data == '\"' || *data == '\'') return BEGIN_STRING; + if (*data == '-' || ('0' <= *data && *data <= '9')) { + return BEGIN_NUMBER; + } + if (size >= kKeywordTrue.length() && + HasPrefixString(data_view, kKeywordTrue)) { + return BEGIN_TRUE; + } + if (size >= kKeywordFalse.length() && + HasPrefixString(data_view, kKeywordFalse)) { + return BEGIN_FALSE; + } + if (size >= kKeywordNull.length() && + HasPrefixString(data_view, kKeywordNull)) { + return BEGIN_NULL; + } + if (*data == '{') return BEGIN_OBJECT; + if (*data == '}') return END_OBJECT; + if (*data == '[') return BEGIN_ARRAY; + if (*data == ']') return END_ARRAY; + if (*data == ':') return ENTRY_SEPARATOR; + if (*data == ',') return VALUE_SEPARATOR; + if (MatchKey(p_)) { + return BEGIN_KEY; + } + + // We don't know that we necessarily have an invalid token here, just that we + // can't parse what we have so far. So we don't report an error and just + // return UNKNOWN so we can try again later when we have more data, or if we + // finish and we have leftovers. + return UNKNOWN; +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.h b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.h new file mode 100644 index 0000000..09f17ad --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser.h @@ -0,0 +1,350 @@ +// 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_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ + +#include +#include +#include + +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +class ObjectWriter; + +// A JSON parser that can parse a stream of JSON chunks rather than needing the +// entire JSON string up front. It is a modified version of the parser in +// //net/proto/json/json-parser.h that has been changed in the following ways: +// - Changed from recursion to an explicit stack to allow resumption +// - Added support for int64 and uint64 numbers +// - Removed support for octal and decimal escapes +// - Removed support for numeric keys +// - Removed support for functions (javascript) +// - Removed some lax-comma support (but kept trailing comma support) +// - Writes directly to an ObjectWriter rather than using subclassing +// +// Here is an example usage: +// JsonStreamParser parser(ow_.get()); +// util::Status result = parser.Parse(chunk1); +// result.Update(parser.Parse(chunk2)); +// result.Update(parser.FinishParse()); +// GOOGLE_DCHECK(result.ok()) << "Failed to parse JSON"; +// +// This parser is thread-compatible as long as only one thread is calling a +// Parse() method at a time. +class PROTOBUF_EXPORT JsonStreamParser { + public: + // Creates a JsonStreamParser that will write to the given ObjectWriter. + explicit JsonStreamParser(ObjectWriter* ow); + virtual ~JsonStreamParser(); + + // Parses a UTF-8 encoded JSON string from a StringPiece. If the returned + // status is non-ok, the status might contain a payload ParseErrorType with + // type_url kParseErrorTypeUrl and a payload containing string snippet of the + // error with type_url kParseErrorSnippetUrl. + util::Status Parse(StringPiece json); + + + // Finish parsing the JSON string. If the returned status is non-ok, the + // status might contain a payload ParseErrorType with type_url + // kParseErrorTypeUrl and a payload containing string snippet of the error + // with type_url kParseErrorSnippetUrl. + util::Status FinishParse(); + + + // Sets the max recursion depth of JSON message to be deserialized. JSON + // messages over this depth will fail to be deserialized. + // Default value is 100. + void set_max_recursion_depth(int max_depth) { + max_recursion_depth_ = max_depth; + } + + // Denotes the cause of error. + enum ParseErrorType { + UNKNOWN_PARSE_ERROR, + OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES, + EXPECTED_COLON, + EXPECTED_COMMA_OR_BRACKET, + EXPECTED_VALUE, + EXPECTED_COMMA_OR_BRACES, + EXPECTED_OBJECT_KEY_OR_BRACES, + EXPECTED_VALUE_OR_BRACKET, + INVALID_KEY_OR_VARIABLE_NAME, + NON_UTF_8, + PARSING_TERMINATED_BEFORE_END_OF_INPUT, + UNEXPECTED_TOKEN, + EXPECTED_CLOSING_QUOTE, + ILLEGAL_HEX_STRING, + INVALID_ESCAPE_SEQUENCE, + MISSING_LOW_SURROGATE, + INVALID_LOW_SURROGATE, + INVALID_UNICODE, + UNABLE_TO_PARSE_NUMBER, + NUMBER_EXCEEDS_RANGE_DOUBLE + }; + + private: + friend class JsonStreamParserTest; + // Return the current recursion depth. + int recursion_depth() { return recursion_depth_; } + + enum TokenType { + BEGIN_STRING, // " or ' + BEGIN_NUMBER, // - or digit + BEGIN_TRUE, // true + BEGIN_FALSE, // false + BEGIN_NULL, // null + BEGIN_OBJECT, // { + END_OBJECT, // } + BEGIN_ARRAY, // [ + END_ARRAY, // ] + ENTRY_SEPARATOR, // : + VALUE_SEPARATOR, // , + BEGIN_KEY, // letter, _, $ or digit. Must begin with non-digit + UNKNOWN // Unknown token or we ran out of the stream. + }; + + enum ParseType { + VALUE, // Expects a {, [, true, false, null, string or number + OBJ_MID, // Expects a ',' or } + ENTRY, // Expects a key or } + ENTRY_MID, // Expects a : + ARRAY_VALUE, // Expects a value or ] + ARRAY_MID // Expects a ',' or ] + }; + + // Holds the result of parsing a number + struct NumberResult { + enum Type { DOUBLE, INT, UINT }; + Type type; + union { + double double_val; + int64_t int_val; + uint64_t uint_val; + }; + }; + + // Parses a single chunk of JSON, returning an error if the JSON was invalid. + util::Status ParseChunk(StringPiece chunk); + + // Runs the parser based on stack_ and p_, until the stack is empty or p_ runs + // out of data. If we unexpectedly run out of p_ we push the latest back onto + // the stack and return. + util::Status RunParser(); + + // Parses a value from p_ and writes it to ow_. + // A value may be an object, array, true, false, null, string or number. + util::Status ParseValue(TokenType type); + + // Parses a string and writes it out to the ow_. + util::Status ParseString(); + + // Parses a string, storing the result in parsed_. + util::Status ParseStringHelper(); + + // This function parses unicode escape sequences in strings. It returns an + // error when there's a parsing error, either the size is not the expected + // size or a character is not a hex digit. When it returns str will contain + // what has been successfully parsed so far. + util::Status ParseUnicodeEscape(); + + // Expects p_ to point to a JSON number, writes the number to the writer using + // the appropriate Render method based on the type of number. + util::Status ParseNumber(); + + // Parse a number into a NumberResult, reporting an error if no number could + // be parsed. This method will try to parse into a uint64, int64, or double + // based on whether the number was positive or negative or had a decimal + // component. + util::Status ParseNumberHelper(NumberResult* result); + + // Parse a number as double into a NumberResult. + util::Status ParseDoubleHelper(const std::string& number, + NumberResult* result); + + // Handles a { during parsing of a value. + util::Status HandleBeginObject(); + + // Parses from the ENTRY state. + util::Status ParseEntry(TokenType type); + + // Parses from the ENTRY_MID state. + util::Status ParseEntryMid(TokenType type); + + // Parses from the OBJ_MID state. + util::Status ParseObjectMid(TokenType type); + + // Handles a [ during parsing of a value. + util::Status HandleBeginArray(); + + // Parses from the ARRAY_VALUE state. + util::Status ParseArrayValue(TokenType type); + + // Parses from the ARRAY_MID state. + util::Status ParseArrayMid(TokenType type); + + // Expects p_ to point to an unquoted literal + util::Status ParseTrue(); + util::Status ParseFalse(); + util::Status ParseNull(); + util::Status ParseEmptyNull(); + + // Whether an empty-null is allowed in the current state. + bool IsEmptyNullAllowed(TokenType type); + + // Whether the whole input is all whitespaces. + bool IsInputAllWhiteSpaces(TokenType type); + + // Report a failure as a util::Status. + util::Status ReportFailure(StringPiece message, + ParseErrorType parse_code); + + // Report a failure due to an UNKNOWN token type. We check if we hit the + // end of the stream and if we're finishing or not to detect what type of + // status to return in this case. + util::Status ReportUnknown(StringPiece message, + ParseErrorType parse_code); + + // Helper function to check recursion depth and increment it. It will return + // OkStatus() if the current depth is allowed. Otherwise an error is returned. + // key is used for error reporting. + util::Status IncrementRecursionDepth(StringPiece key) const; + + // Advance p_ past all whitespace or until the end of the string. + void SkipWhitespace(); + + // Advance p_ one UTF-8 character + void Advance(); + + // Expects p_ to point to the beginning of a key. + util::Status ParseKey(); + + // Return the type of the next token at p_. + TokenType GetNextTokenType(); + + // The object writer to write parse events to. + ObjectWriter* ow_; + + // The stack of parsing we still need to do. When the stack runs empty we will + // have parsed a single value from the root (e.g. an object or list). + std::stack stack_; + + // Contains any leftover text from a previous chunk that we weren't able to + // fully parse, for example the start of a key or number. + std::string leftover_; + + // The current chunk of JSON being parsed. Primarily used for providing + // context during error reporting. + StringPiece json_; + + // A pointer within the current JSON being parsed, used to track location. + StringPiece p_; + + // Stores the last key read, as we separate parsing of keys and values. + StringPiece key_; + + // Storage for key_ if we need to keep ownership, for example between chunks + // or if the key was unescaped from a JSON string. + std::string key_storage_; + + // True during the FinishParse() call, so we know that any errors are fatal. + // For example an unterminated string will normally result in cancelling and + // trying during the next chunk, but during FinishParse() it is an error. + bool finishing_; + + // Whether non whitespace tokens have been seen during parsing. + // It is used to handle the case of a pure whitespace stream input. + bool seen_non_whitespace_; + + // The JsonStreamParser requires a root element by default and it will raise + // error if the root element is missing. If `allow_no_root_element_` is true, + // the JsonStreamParser can also handle this case. + bool allow_no_root_element_; + + // String we parsed during a call to ParseStringHelper(). + StringPiece parsed_; + + // Storage for the string we parsed. This may be empty if the string was able + // to be parsed directly from the input. + std::string parsed_storage_; + + // The character that opened the string, either ' or ". + // A value of 0 indicates that string parsing is not in process. + char string_open_; + + // Storage for the chunk that are being parsed in ParseChunk(). + std::string chunk_storage_; + + // Whether to allow non UTF-8 encoded input and replace invalid code points. + bool coerce_to_utf8_; + + // Replacement character for invalid UTF-8 code points. + std::string utf8_replacement_character_; + + // Whether allows empty string represented null array value or object entry + // value. + bool allow_empty_null_; + + // Whether unquoted object keys can contain embedded non-alphanumeric + // characters when this is unambiguous for parsing. + bool allow_permissive_key_naming_; + + // Whether allows out-of-range floating point numbers or reject them. + bool loose_float_number_conversion_; + + // Tracks current recursion depth. + mutable int recursion_depth_; + + // Maximum allowed recursion depth. + int max_recursion_depth_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonStreamParser); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_JSON_STREAM_PARSER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc new file mode 100644 index 0000000..40157a2 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc @@ -0,0 +1,979 @@ +// 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 + +#include + +#include +#include +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using ParseErrorType = + ::google::protobuf::util::converter::JsonStreamParser::ParseErrorType; + + +// Tests for the JSON Stream Parser. These tests are intended to be +// comprehensive and cover the following: +// +// Positive tests: +// - true, false, null +// - empty object or array. +// - negative and positive double and int, unsigned int +// - single and double quoted strings +// - string key, unquoted key, numeric key +// - array containing array, object, value +// - object containing array, object, value +// - unicode handling in strings +// - ascii escaping (\b, \f, \n, \r, \t, \v) +// - trailing commas +// +// Negative tests: +// - illegal literals +// - mismatched quotes failure on strings +// - unterminated string failure +// - unexpected end of string failure +// - mismatched object and array closing +// - Failure to close array or object +// - numbers too large +// - invalid unicode escapes. +// - invalid unicode sequences. +// - numbers as keys +// +// For each test we split the input string on every possible character to ensure +// the parser is able to handle arbitrarily split input for all cases. We also +// do a final test of the entire test case one character at a time. +// +// It is verified that expected calls to the mocked objects are in sequence. +class JsonStreamParserTest : public ::testing::Test { + protected: + JsonStreamParserTest() : mock_(), ow_(&mock_) {} + ~JsonStreamParserTest() override {} + + util::Status RunTest(StringPiece json, int split, + std::function setup) { + JsonStreamParser parser(&mock_); + setup(&parser); + + // Special case for split == length, test parsing one character at a time. + if (split == json.length()) { + GOOGLE_LOG(INFO) << "Testing split every char: " << json; + for (int i = 0; i < json.length(); ++i) { + StringPiece single = json.substr(i, 1); + util::Status result = parser.Parse(single); + if (!result.ok()) { + return result; + } + } + return parser.FinishParse(); + } + + // Normal case, split at the split point and parse two substrings. + StringPiece first = json.substr(0, split); + StringPiece rest = json.substr(split); + GOOGLE_LOG(INFO) << "Testing split: " << first << "><" << rest; + util::Status result = parser.Parse(first); + if (result.ok()) { + result = parser.Parse(rest); + if (result.ok()) { + result = parser.FinishParse(); + } + } + if (result.ok()) { + EXPECT_EQ(parser.recursion_depth(), 0); + } + return result; + } + + void DoTest( + StringPiece json, int split, + std::function setup = [](JsonStreamParser* p) { + }) { + util::Status result = RunTest(json, split, setup); + if (!result.ok()) { + GOOGLE_LOG(WARNING) << result; + } + EXPECT_TRUE(result.ok()); + } + + void DoErrorTest( + StringPiece json, int split, StringPiece error_prefix, + std::function setup = [](JsonStreamParser* p) { + }) { + util::Status result = RunTest(json, split, setup); + EXPECT_TRUE(util::IsInvalidArgument(result)); + StringPiece error_message(result.message()); + EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); + } + + void DoErrorTest( + StringPiece json, int split, StringPiece error_prefix, + ParseErrorType expected_parse_error_type, + std::function setup = [](JsonStreamParser* p) { + }) { + util::Status result = RunTest(json, split, setup); + EXPECT_TRUE(util::IsInvalidArgument(result)); + StringPiece error_message(result.message()); + EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size())); + } + + +#ifndef _MSC_VER + // TODO(xiaofeng): We have to disable InSequence check for MSVC because it + // causes stack overflow due to its use of a linked list that is destructed + // recursively. + ::testing::InSequence in_sequence_; +#endif // !_MSC_VER + MockObjectWriter mock_; + ExpectingObjectWriter ow_; +}; + + +// Positive tests + +// - true, false, null +TEST_F(JsonStreamParserTest, SimpleTrue) { + StringPiece str = "true"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderBool("", true); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleFalse) { + StringPiece str = "false"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderBool("", false); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleNull) { + StringPiece str = "null"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderNull(""); + DoTest(str, i); + } +} + +// - empty object and array. +TEST_F(JsonStreamParserTest, EmptyObject) { + StringPiece str = "{}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->EndObject(); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, EmptyList) { + StringPiece str = "[]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("")->EndList(); + DoTest(str, i); + } +} + +// - negative and positive double and int, unsigned int +TEST_F(JsonStreamParserTest, SimpleDouble) { + StringPiece str = "42.5"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderDouble("", 42.5); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, ScientificDouble) { + StringPiece str = "1.2345e-10"; + for (int i = 0; i < str.length(); ++i) { + ow_.RenderDouble("", 1.2345e-10); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleNegativeDouble) { + StringPiece str = "-1045.235"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderDouble("", -1045.235); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleInt) { + StringPiece str = "123456"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderUint64("", 123456); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleNegativeInt) { + StringPiece str = "-79497823553162765"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderInt64("", int64_t{-79497823553162765}); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleUnsignedInt) { + StringPiece str = "11779497823553162765"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderUint64("", uint64_t{11779497823553162765u}); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, OctalNumberIsInvalid) { + StringPiece str = "01234"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } + str = "-01234"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } +} + +TEST_F(JsonStreamParserTest, HexNumberIsInvalid) { + StringPiece str = "0x1234"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } + str = "-0x1234"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Octal/hex numbers are not valid JSON values.", + ParseErrorType::OCTAL_OR_HEX_ARE_NOT_VALID_JSON_VALUES); + } + str = "12x34"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Unable to parse number.", + ParseErrorType::UNABLE_TO_PARSE_NUMBER); + } +} + +// - single and double quoted strings +TEST_F(JsonStreamParserTest, EmptyDoubleQuotedString) { + StringPiece str = "\"\""; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderString("", ""); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, EmptySingleQuotedString) { + StringPiece str = "''"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderString("", ""); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleDoubleQuotedString) { + StringPiece str = "\"Some String\""; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderString("", "Some String"); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, SimpleSingleQuotedString) { + StringPiece str = "'Another String'"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderString("", "Another String"); + DoTest(str, i); + } +} + +// - string key, unquoted key, numeric key +TEST_F(JsonStreamParserTest, ObjectKeyTypes) { + StringPiece str = + "{'s': true, \"d\": false, key: null, snake_key: [], camelKey: {}}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("") + ->RenderBool("s", true) + ->RenderBool("d", false) + ->RenderNull("key") + ->StartList("snake_key") + ->EndList() + ->StartObject("camelKey") + ->EndObject() + ->EndObject(); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, UnquotedObjectKeyWithReservedPrefxes) { + StringPiece str = "{ nullkey: \"a\", truekey: \"b\", falsekey: \"c\"}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("") + ->RenderString("nullkey", "a") + ->RenderString("truekey", "b") + ->RenderString("falsekey", "c") + ->EndObject(); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, UnquotedObjectKeyWithReservedKeyword) { + StringPiece str = "{ null: \"a\", true: \"b\", false: \"c\"}"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, UnquotedObjectKeyWithEmbeddedNonAlphanumeric) { + StringPiece str = "{ foo-bar-baz: \"a\"}"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Expected : between key:value pair.", + ParseErrorType::EXPECTED_COLON); + } +} + + +// - array containing primitive values (true, false, null, num, string) +TEST_F(JsonStreamParserTest, ArrayPrimitiveValues) { + StringPiece str = "[true, false, null, 'one', \"two\"]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->RenderBool("", true) + ->RenderBool("", false) + ->RenderNull("") + ->RenderString("", "one") + ->RenderString("", "two") + ->EndList(); + DoTest(str, i); + } +} + +// - array containing array, object +TEST_F(JsonStreamParserTest, ArrayComplexValues) { + StringPiece str = + "[[22, -127, 45.3, -1056.4, 11779497823553162765], {'key': true}]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->StartList("") + ->RenderUint64("", 22) + ->RenderInt64("", -127) + ->RenderDouble("", 45.3) + ->RenderDouble("", -1056.4) + ->RenderUint64("", uint64_t{11779497823553162765u}) + ->EndList() + ->StartObject("") + ->RenderBool("key", true) + ->EndObject() + ->EndList(); + DoTest(str, i); + } +} + + +// - object containing array, object, value (true, false, null, num, string) +TEST_F(JsonStreamParserTest, ObjectValues) { + StringPiece str = + "{t: true, f: false, n: null, s: 'a string', d: \"another string\", pi: " + "22, ni: -127, pd: 45.3, nd: -1056.4, pl: 11779497823553162765, l: [[]], " + "o: {'key': true}}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("") + ->RenderBool("t", true) + ->RenderBool("f", false) + ->RenderNull("n") + ->RenderString("s", "a string") + ->RenderString("d", "another string") + ->RenderUint64("pi", 22) + ->RenderInt64("ni", -127) + ->RenderDouble("pd", 45.3) + ->RenderDouble("nd", -1056.4) + ->RenderUint64("pl", uint64_t{11779497823553162765u}) + ->StartList("l") + ->StartList("") + ->EndList() + ->EndList() + ->StartObject("o") + ->RenderBool("key", true) + ->EndObject() + ->EndObject(); + DoTest(str, i); + } +} + + +TEST_F(JsonStreamParserTest, RejectNonUtf8WhenNotCoerced) { + StringPiece json = "{\"address\":\xFF\"חרושת 23, רעננה, ישראל\"}"; + for (int i = 0; i <= json.length(); ++i) { + DoErrorTest(json, i, "Encountered non UTF-8 code points.", + ParseErrorType::NON_UTF_8); + } + json = "{\"address\": \"חרושת 23,\xFFרעננה, ישראל\"}"; + for (int i = 0; i <= json.length(); ++i) { + DoErrorTest(json, i, "Encountered non UTF-8 code points.", + ParseErrorType::NON_UTF_8); + } + DoErrorTest("\xFF{}", 0, "Encountered non UTF-8 code points.", + ParseErrorType::NON_UTF_8); +} + +// - unicode handling in strings +TEST_F(JsonStreamParserTest, UnicodeEscaping) { + StringPiece str = "[\"\\u0639\\u0631\\u0628\\u0649\"]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->RenderString("", "\xD8\xB9\xD8\xB1\xD8\xA8\xD9\x89") + ->EndList(); + DoTest(str, i); + } +} + +// - unicode UTF-16 surrogate pair handling in strings +TEST_F(JsonStreamParserTest, UnicodeSurrogatePairEscaping) { + StringPiece str = + "[\"\\u0bee\\ud800\\uddf1\\uD80C\\uDDA4\\uD83d\\udC1D\\uD83C\\uDF6F\"]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->RenderString("", + "\xE0\xAF\xAE\xF0\x90\x87\xB1\xF0\x93\x86\xA4\xF0" + "\x9F\x90\x9D\xF0\x9F\x8D\xAF") + ->EndList(); + DoTest(str, i); + } +} + + +TEST_F(JsonStreamParserTest, UnicodeEscapingInvalidCodePointWhenNotCoerced) { + // A low surrogate alone. + StringPiece str = "[\"\\ude36\"]"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid unicode code point.", + ParseErrorType::INVALID_UNICODE); + } +} + +TEST_F(JsonStreamParserTest, UnicodeEscapingMissingLowSurrogateWhenNotCoerced) { + // A high surrogate alone. + StringPiece str = "[\"\\ud83d\"]"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Missing low surrogate.", + ParseErrorType::MISSING_LOW_SURROGATE); + } + // A high surrogate with some trailing characters. + str = "[\"\\ud83d|ude36\"]"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Missing low surrogate.", + ParseErrorType::MISSING_LOW_SURROGATE); + } + // A high surrogate with half a low surrogate. + str = "[\"\\ud83d\\ude--\"]"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } + // Two high surrogates. + str = "[\"\\ud83d\\ud83d\"]"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid low surrogate.", + ParseErrorType::INVALID_LOW_SURROGATE); + } +} + +// - ascii escaping (\b, \f, \n, \r, \t, \v) +TEST_F(JsonStreamParserTest, AsciiEscaping) { + StringPiece str = + "[\"\\b\", \"\\ning\", \"test\\f\", \"\\r\\t\", \"test\\\\\\ving\"]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->RenderString("", "\b") + ->RenderString("", "\ning") + ->RenderString("", "test\f") + ->RenderString("", "\r\t") + ->RenderString("", "test\\\ving") + ->EndList(); + DoTest(str, i); + } +} + +// - trailing commas, we support a single trailing comma but no internal commas. +TEST_F(JsonStreamParserTest, TrailingCommas) { + StringPiece str = "[['a',true,], {b: null,},]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("") + ->StartList("") + ->RenderString("", "a") + ->RenderBool("", true) + ->EndList() + ->StartObject("") + ->RenderNull("b") + ->EndObject() + ->EndList(); + DoTest(str, i); + } +} + +// Negative tests + +// illegal literals +TEST_F(JsonStreamParserTest, ExtraTextAfterTrue) { + StringPiece str = "truee"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderBool("", true); + DoErrorTest(str, i, "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } +} + +TEST_F(JsonStreamParserTest, InvalidNumberDashOnly) { + StringPiece str = "-"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Unable to parse number.", + ParseErrorType::UNABLE_TO_PARSE_NUMBER); + } +} + +TEST_F(JsonStreamParserTest, InvalidNumberDashName) { + StringPiece str = "-foo"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Unable to parse number.", + ParseErrorType::UNABLE_TO_PARSE_NUMBER); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralInArray) { + StringPiece str = "[nule]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Unexpected token.", ParseErrorType::UNEXPECTED_TOKEN); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralInObject) { + StringPiece str = "{123false}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +// mismatched quotes failure on strings +TEST_F(JsonStreamParserTest, MismatchedSingleQuotedLiteral) { + StringPiece str = "'Some str\""; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +TEST_F(JsonStreamParserTest, MismatchedDoubleQuotedLiteral) { + StringPiece str = "\"Another string that ends poorly!'"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +// unterminated strings +TEST_F(JsonStreamParserTest, UnterminatedLiteralString) { + StringPiece str = "\"Forgot the rest of i"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +TEST_F(JsonStreamParserTest, UnterminatedStringEscape) { + StringPiece str = "\"Forgot the rest of \\"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +TEST_F(JsonStreamParserTest, UnterminatedStringInArray) { + StringPiece str = "[\"Forgot to close the string]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +TEST_F(JsonStreamParserTest, UnterminatedStringInObject) { + StringPiece str = "{f: \"Forgot to close the string}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +TEST_F(JsonStreamParserTest, UnterminatedObject) { + StringPiece str = "{"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Unexpected end of string.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + + +// mismatched object and array closing +TEST_F(JsonStreamParserTest, MismatchedCloseObject) { + StringPiece str = "{'key': true]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->RenderBool("key", true); + DoErrorTest(str, i, "Expected , or } after key:value pair.", + ParseErrorType::EXPECTED_COMMA_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, MismatchedCloseArray) { + StringPiece str = "[true, null}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("")->RenderBool("", true)->RenderNull(""); + DoErrorTest(str, i, "Expected , or ] after array value.", + ParseErrorType::EXPECTED_COMMA_OR_BRACKET); + } +} + +// Invalid object keys. +TEST_F(JsonStreamParserTest, InvalidNumericObjectKey) { + StringPiece str = "{42: true}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralObjectInObject) { + StringPiece str = "{{bob: true}}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralArrayInObject) { + StringPiece str = "{[null]}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralValueInObject) { + StringPiece str = "{false}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, MissingColonAfterStringInObject) { + StringPiece str = "{\"key\"}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected : between key:value pair.", + ParseErrorType::EXPECTED_COLON); + } +} + +TEST_F(JsonStreamParserTest, MissingColonAfterKeyInObject) { + StringPiece str = "{key}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected : between key:value pair.", + ParseErrorType::EXPECTED_COLON); + } +} + +TEST_F(JsonStreamParserTest, EndOfTextAfterKeyInObject) { + StringPiece str = "{key"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Unexpected end of string.", + ParseErrorType::EXPECTED_COLON); + } +} + +TEST_F(JsonStreamParserTest, MissingValueAfterColonInObject) { + StringPiece str = "{key:}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Unexpected token.", ParseErrorType::UNEXPECTED_TOKEN); + } +} + +TEST_F(JsonStreamParserTest, MissingCommaBetweenObjectEntries) { + StringPiece str = "{key:20 'hello': true}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->RenderUint64("key", 20); + DoErrorTest(str, i, "Expected , or } after key:value pair.", + ParseErrorType::EXPECTED_COMMA_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, InvalidLiteralAsObjectKey) { + StringPiece str = "{false: 20}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, ExtraCharactersAfterObject) { + StringPiece str = "{}}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->EndObject(); + DoErrorTest(str, i, "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } +} + +TEST_F(JsonStreamParserTest, PositiveNumberTooBigIsDouble) { + StringPiece str = "18446744073709551616"; // 2^64 + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderDouble("", 18446744073709552000.0); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, NegativeNumberTooBigIsDouble) { + StringPiece str = "-18446744073709551616"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderDouble("", -18446744073709551616.0); + DoTest(str, i); + } +} + +TEST_F(JsonStreamParserTest, DoubleTooBig) { + StringPiece str = "[1.89769e+308]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Number exceeds the range of double.", + ParseErrorType::NUMBER_EXCEEDS_RANGE_DOUBLE); + } + str = "[-1.89769e+308]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Number exceeds the range of double.", + ParseErrorType::NUMBER_EXCEEDS_RANGE_DOUBLE); + } +} + + +// invalid bare backslash. +TEST_F(JsonStreamParserTest, UnfinishedEscape) { + StringPiece str = "\"\\"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Closing quote expected in string.", + ParseErrorType::EXPECTED_CLOSING_QUOTE); + } +} + +// invalid bare backslash u. +TEST_F(JsonStreamParserTest, UnfinishedUnicodeEscape) { + StringPiece str = "\"\\u"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Illegal hex string.", + ParseErrorType::ILLEGAL_HEX_STRING); + } +} + +// invalid unicode sequence. +TEST_F(JsonStreamParserTest, UnicodeEscapeCutOff) { + StringPiece str = "\"\\u12"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Illegal hex string.", + ParseErrorType::ILLEGAL_HEX_STRING); + } +} + +// invalid unicode sequence (valid in modern EcmaScript but not in JSON). +TEST_F(JsonStreamParserTest, BracketedUnicodeEscape) { + StringPiece str = "\"\\u{1f36f}\""; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } +} + + +TEST_F(JsonStreamParserTest, UnicodeEscapeInvalidCharacters) { + StringPiece str = "\"\\u12$4hello"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } +} + +// invalid unicode sequence in low half surrogate: g is not a hex digit. +TEST_F(JsonStreamParserTest, UnicodeEscapeLowHalfSurrogateInvalidCharacters) { + StringPiece str = "\"\\ud800\\udcfg\""; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Invalid escape sequence.", + ParseErrorType::INVALID_ESCAPE_SEQUENCE); + } +} + +// Extra commas with an object or array. +TEST_F(JsonStreamParserTest, ExtraCommaInObject) { + StringPiece str = "{'k1': true,,'k2': false}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->RenderBool("k1", true); + DoErrorTest(str, i, "Expected an object key or }.", + ParseErrorType::EXPECTED_OBJECT_KEY_OR_BRACES); + } +} + +TEST_F(JsonStreamParserTest, ExtraCommaInArray) { + StringPiece str = "[true,,false}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("")->RenderBool("", true); + DoErrorTest(str, i, "Unexpected token.", ParseErrorType::UNEXPECTED_TOKEN); + } +} + +// Extra text beyond end of value. +TEST_F(JsonStreamParserTest, ExtraTextAfterLiteral) { + StringPiece str = "'hello', 'world'"; + for (int i = 0; i <= str.length(); ++i) { + ow_.RenderString("", "hello"); + DoErrorTest(str, i, "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } +} + +TEST_F(JsonStreamParserTest, ExtraTextAfterObject) { + StringPiece str = "{'key': true} 'oops'"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject("")->RenderBool("key", true)->EndObject(); + DoErrorTest(str, i, "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } +} + +TEST_F(JsonStreamParserTest, ExtraTextAfterArray) { + StringPiece str = "[null] 'oops'"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList("")->RenderNull("")->EndList(); + DoErrorTest(str, i, "Parsing terminated before end of input.", + ParseErrorType::PARSING_TERMINATED_BEFORE_END_OF_INPUT); + } +} + +// Random unknown text in the value. +TEST_F(JsonStreamParserTest, UnknownCharactersAsValue) { + StringPiece str = "*"; + for (int i = 0; i <= str.length(); ++i) { + DoErrorTest(str, i, "Expected a value.", ParseErrorType::EXPECTED_VALUE); + } +} + +TEST_F(JsonStreamParserTest, UnknownCharactersInArray) { + StringPiece str = "[*]"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartList(""); + DoErrorTest(str, i, "Expected a value or ] within an array.", + ParseErrorType::EXPECTED_VALUE_OR_BRACKET); + } +} + +TEST_F(JsonStreamParserTest, UnknownCharactersInObject) { + StringPiece str = "{'key': *}"; + for (int i = 0; i <= str.length(); ++i) { + ow_.StartObject(""); + DoErrorTest(str, i, "Expected a value.", ParseErrorType::EXPECTED_VALUE); + } +} + +TEST_F(JsonStreamParserTest, DeepNestJsonNotExceedLimit) { + int count = 99; + std::string str; + for (int i = 0; i < count; ++i) { + StrAppend(&str, "{'a':"); + } + StrAppend(&str, "{'nest64':'v1', 'nest64': false, 'nest64': ['v2']}"); + for (int i = 0; i < count; ++i) { + StrAppend(&str, "}"); + } + ow_.StartObject(""); + for (int i = 0; i < count; ++i) { + ow_.StartObject("a"); + } + ow_.RenderString("nest64", "v1") + ->RenderBool("nest64", false) + ->StartList("nest64") + ->RenderString("", "v2") + ->EndList(); + for (int i = 0; i < count; ++i) { + ow_.EndObject(); + } + ow_.EndObject(); + DoTest(str, 0); +} + +TEST_F(JsonStreamParserTest, DeepNestJsonExceedLimit) { + int count = 98; + std::string str; + for (int i = 0; i < count; ++i) { + StrAppend(&str, "{'a':"); + } + // Supports trailing commas. + StrAppend(&str, + "{'nest11' : [{'nest12' : null,},]," + "'nest21' : {'nest22' : {'nest23' : false}}}"); + for (int i = 0; i < count; ++i) { + StrAppend(&str, "}"); + } + DoErrorTest(str, 0, + "Message too deep. Max recursion depth reached for key 'nest22'"); +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/json/internal/message_path.cc b/libs/protobuf/src/google/protobuf/util/internal/location_tracker.h similarity index 66% rename from libs/protobuf/src/google/protobuf/json/internal/message_path.cc rename to libs/protobuf/src/google/protobuf/util/internal/location_tracker.h index f3a41c1..68fefcc 100644 --- a/libs/protobuf/src/google/protobuf/json/internal/message_path.cc +++ b/libs/protobuf/src/google/protobuf/util/internal/location_tracker.h @@ -28,40 +28,43 @@ // (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/json/internal/message_path.h" +#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_LOCATION_TRACKER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_LOCATION_TRACKER_H__ #include -#include "absl/strings/str_cat.h" +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { -namespace json_internal { -void MessagePath::Describe(std::string& out) const { - absl::StrAppend(&out, components_.front().type_name); - if (components_.size() == 1) { - return; - } +namespace util { +namespace converter { - absl::StrAppend(&out, " @ "); - for (size_t i = 1; i < components_.size(); ++i) { - absl::StrAppend(&out, i == 1 ? "" : ".", components_[i].field_name); - if (components_[i].repeated_index >= 0) { - absl::StrAppend(&out, "[", components_[i].repeated_index, "]"); - } - } - absl::string_view kind_name = - FieldDescriptor::TypeName(components_.back().type); - absl::StrAppend(&out, ": ", kind_name); +// LocationTrackerInterface is an interface for classes that track +// the location information for the purpose of error reporting. +class PROTOBUF_EXPORT LocationTrackerInterface { + public: + virtual ~LocationTrackerInterface() {} - absl::string_view type_name = components_.back().type_name; - if (!type_name.empty()) { - absl::StrAppend(&out, " ", type_name); - } -} -} // namespace json_internal + // Returns the object location as human readable string. + virtual std::string ToString() const = 0; + + protected: + LocationTrackerInterface() {} + + private: + // Please do not add any data members to this class. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LocationTrackerInterface); +}; + +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_LOCATION_TRACKER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/mock_error_listener.h b/libs/protobuf/src/google/protobuf/util/internal/mock_error_listener.h new file mode 100644 index 0000000..3fbdd88 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/mock_error_listener.h @@ -0,0 +1,68 @@ +// 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_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__ + +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +class MockErrorListener : public ErrorListener { + public: + MockErrorListener() {} + ~MockErrorListener() override {} + + MOCK_METHOD(void, InvalidName, + (const LocationTrackerInterface& loc, + StringPiece unknown_name, StringPiece message), + (override)); + MOCK_METHOD(void, InvalidValue, + (const LocationTrackerInterface& loc, StringPiece type_name, + StringPiece value), + (override)); + MOCK_METHOD(void, MissingField, + (const LocationTrackerInterface& loc, + StringPiece missing_name), + (override)); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_MOCK_ERROR_LISTENER_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/objectivec/options.h b/libs/protobuf/src/google/protobuf/util/internal/object_location_tracker.h similarity index 68% rename from libs/protobuf/src/google/protobuf/compiler/objectivec/options.h rename to libs/protobuf/src/google/protobuf/util/internal/object_location_tracker.h index 388d1ca..47821e6 100644 --- a/libs/protobuf/src/google/protobuf/compiler/objectivec/options.h +++ b/libs/protobuf/src/google/protobuf/util/internal/object_location_tracker.h @@ -28,29 +28,37 @@ // (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_COMPILER_OBJECTIVEC_OPTIONS_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_OPTIONS_H__ +#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_LOCATION_TRACKER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_LOCATION_TRACKER_H__ #include +#include +#include + namespace google { namespace protobuf { -namespace compiler { -namespace objectivec { +namespace util { +namespace converter { -// Generation options, documented within generator.cc. -struct GenerationOptions { - std::string generate_for_named_framework; - std::string named_framework_to_proto_path_mappings_path; - std::string runtime_import_prefix; - // TODO(thomasvl): Eventually flip this default to false for better interop - // with Swift if proto usages span modules made from ObjC sources. - bool headers_use_forward_declarations = true; +// An empty concrete implementation of LocationTrackerInterface. +class ObjectLocationTracker : public LocationTrackerInterface { + public: + // Creates an empty location tracker. + ObjectLocationTracker() {} + + ~ObjectLocationTracker() override {} + + // Returns empty because nothing is tracked. + std::string ToString() const override { return ""; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectLocationTracker); }; -} // namespace objectivec -} // namespace compiler +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_OPTIONS_H__ +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_LOCATION_TRACKER_H__ diff --git a/libs/protobuf/src/google/protobuf/io/zero_copy_sink.h b/libs/protobuf/src/google/protobuf/util/internal/object_source.h similarity index 55% rename from libs/protobuf/src/google/protobuf/io/zero_copy_sink.h rename to libs/protobuf/src/google/protobuf/util/internal/object_source.h index 4d70d39..fc7672e 100644 --- a/libs/protobuf/src/google/protobuf/io/zero_copy_sink.h +++ b/libs/protobuf/src/google/protobuf/util/internal/object_source.h @@ -28,53 +28,58 @@ // (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_UTIL_ZERO_COPY_SINK_H__ -#define GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__ +#ifndef GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ -#include - -#include "google/protobuf/stubs/bytestream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/port.h" +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { -namespace io { -namespace zc_sink_internal { -// Internal helper class, for turning a ZeroCopyOutputStream into a sink. -class PROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink { - public: - explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream) - : stream_(stream) {} - ZeroCopyStreamByteSink(const ZeroCopyStreamByteSink&) = delete; - ZeroCopyStreamByteSink& operator=(const ZeroCopyStreamByteSink&) = delete; +namespace util { +namespace converter { - ~ZeroCopyStreamByteSink() override { - if (buffer_size_ > 0) { - stream_->BackUp(buffer_size_); - } +class ObjectWriter; + +// An ObjectSource is anything that can write to an ObjectWriter. +// Implementation of this interface typically provide constructors or +// factory methods to create an instance based on some source data, for +// example, a character stream, or protobuf. +// +// Derived classes could be thread-unsafe. +class PROTOBUF_EXPORT ObjectSource { + public: + virtual ~ObjectSource() {} + + // Writes to the ObjectWriter + virtual util::Status WriteTo(ObjectWriter* ow) const { + return NamedWriteTo("", ow); } - void Append(const char* bytes, size_t len) override; - void Write(absl::string_view str) { Append(str.data(), str.size()); } + // Writes to the ObjectWriter with a custom name for the message. + // This is useful when you chain ObjectSource together by embedding one + // within another. + virtual util::Status NamedWriteTo(StringPiece name, + ObjectWriter* ow) const = 0; - size_t bytes_written() { return bytes_written_; } - bool failed() { return failed_; } + protected: + ObjectSource() {} private: - io::ZeroCopyOutputStream* stream_; - void* buffer_ = nullptr; - size_t buffer_size_ = 0; - size_t bytes_written_ = 0; - bool failed_ = false; + // Do not add any data members to this class. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectSource); }; -} // namespace zc_sink_internal -} // namespace io + +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" -#endif // GOOGLE_PROTOBUF_UTIL_ZERO_COPY_SINK_H__ +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_SOURCE_H__ diff --git a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization.cc b/libs/protobuf/src/google/protobuf/util/internal/object_writer.cc similarity index 54% rename from libs/protobuf/src/google/protobuf/compiler/java/message_serialization.cc rename to libs/protobuf/src/google/protobuf/util/internal/object_writer.cc index d0a0fe2..4dabd37 100644 --- a/libs/protobuf/src/google/protobuf/compiler/java/message_serialization.cc +++ b/libs/protobuf/src/google/protobuf/util/internal/object_writer.cc @@ -28,24 +28,66 @@ // (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/compiler/java/message_serialization.h" +#include -#include "google/protobuf/io/printer.h" -#include "google/protobuf/descriptor.h" -#include "absl/strings/str_cat.h" +#include namespace google { namespace protobuf { -namespace compiler { -namespace java { +namespace util { +namespace converter { -void GenerateSerializeExtensionRange(io::Printer* printer, - const Descriptor::ExtensionRange* range) { - printer->Print("extensionWriter.writeUntil($end$, output);\n", "end", - absl::StrCat(range->end)); +// static +void ObjectWriter::RenderDataPieceTo(const DataPiece& data, + StringPiece name, ObjectWriter* ow) { + switch (data.type()) { + case DataPiece::TYPE_INT32: { + ow->RenderInt32(name, data.ToInt32().value()); + break; + } + case DataPiece::TYPE_INT64: { + ow->RenderInt64(name, data.ToInt64().value()); + break; + } + case DataPiece::TYPE_UINT32: { + ow->RenderUint32(name, data.ToUint32().value()); + break; + } + case DataPiece::TYPE_UINT64: { + ow->RenderUint64(name, data.ToUint64().value()); + break; + } + case DataPiece::TYPE_DOUBLE: { + ow->RenderDouble(name, data.ToDouble().value()); + break; + } + case DataPiece::TYPE_FLOAT: { + ow->RenderFloat(name, data.ToFloat().value()); + break; + } + case DataPiece::TYPE_BOOL: { + ow->RenderBool(name, data.ToBool().value()); + break; + } + case DataPiece::TYPE_STRING: { + ow->RenderString(name, data.ToString().value()); + break; + } + case DataPiece::TYPE_BYTES: { + ow->RenderBytes(name, data.ToBytes().value()); + break; + } + case DataPiece::TYPE_NULL: { + ow->RenderNull(name); + break; + } + default: + break; + } } -} // namespace java -} // namespace compiler + +} // namespace converter +} // namespace util } // namespace protobuf } // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/object_writer.h b/libs/protobuf/src/google/protobuf/util/internal/object_writer.h new file mode 100644 index 0000000..bc4095b --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/object_writer.h @@ -0,0 +1,151 @@ +// 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_UTIL_INTERNAL_OBJECT_WRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_WRITER_H__ + +#include + +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +class DataPiece; + +// An ObjectWriter is an interface for writing a stream of events +// representing objects and collections. Implementation of this +// interface can be used to write an object stream to an in-memory +// structure, protobufs, JSON, XML, or any other output format +// desired. The ObjectSource interface is typically used as the +// source of an object stream. +// +// See JsonObjectWriter for a sample implementation of ObjectWriter +// and its use. +// +// Derived classes could be thread-unsafe. +// +// TODO(xinb): seems like a prime candidate to apply the RAII paradigm +// and get rid the need to call EndXXX(). +class PROTOBUF_EXPORT ObjectWriter { + public: + virtual ~ObjectWriter() {} + + // Starts an object. If the name is empty, the object will not be named. + virtual ObjectWriter* StartObject(StringPiece name) = 0; + + // Ends an object. + virtual ObjectWriter* EndObject() = 0; + + // Starts a list. If the name is empty, the list will not be named. + virtual ObjectWriter* StartList(StringPiece name) = 0; + + // Ends a list. + virtual ObjectWriter* EndList() = 0; + + // Renders a boolean value. + virtual ObjectWriter* RenderBool(StringPiece name, bool value) = 0; + + // Renders an 32-bit integer value. + virtual ObjectWriter* RenderInt32(StringPiece name, int32_t value) = 0; + + // Renders an 32-bit unsigned integer value. + virtual ObjectWriter* RenderUint32(StringPiece name, + uint32_t value) = 0; + + // Renders a 64-bit integer value. + virtual ObjectWriter* RenderInt64(StringPiece name, int64_t value) = 0; + + // Renders an 64-bit unsigned integer value. + virtual ObjectWriter* RenderUint64(StringPiece name, + uint64_t value) = 0; + + + // Renders a double value. + virtual ObjectWriter* RenderDouble(StringPiece name, double value) = 0; + // Renders a float value. + virtual ObjectWriter* RenderFloat(StringPiece name, float value) = 0; + + // Renders a StringPiece value. This is for rendering strings. + virtual ObjectWriter* RenderString(StringPiece name, + StringPiece value) = 0; + + // Renders a bytes value. + virtual ObjectWriter* RenderBytes(StringPiece name, StringPiece value) = 0; + + // Renders a Null value. + virtual ObjectWriter* RenderNull(StringPiece name) = 0; + + + // Renders a DataPiece object to a ObjectWriter. + static void RenderDataPieceTo(const DataPiece& data, StringPiece name, + ObjectWriter* ow); + + + // Indicates whether this ObjectWriter has completed writing the root message, + // usually this means writing of one complete object. Subclasses must override + // this behavior appropriately. + virtual bool done() { return false; } + + void set_use_strict_base64_decoding(bool value) { + use_strict_base64_decoding_ = value; + } + + bool use_strict_base64_decoding() const { + return use_strict_base64_decoding_; + } + + protected: + ObjectWriter() : use_strict_base64_decoding_(true) {} + + private: + // If set to true, we use the stricter version of base64 decoding for byte + // fields by making sure decoded version encodes back to the original string. + bool use_strict_base64_decoding_; + + // Do not add any data members to this class. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_OBJECT_WRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/proto_writer.cc b/libs/protobuf/src/google/protobuf/util/internal/proto_writer.cc new file mode 100644 index 0000000..afa5e2e --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/proto_writer.cc @@ -0,0 +1,827 @@ +// 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 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using io::CodedOutputStream; +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; + +ProtoWriter::ProtoWriter(TypeResolver* type_resolver, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener) + : master_type_(type), + typeinfo_(TypeInfo::NewTypeInfo(type_resolver)), + own_typeinfo_(true), + done_(false), + ignore_unknown_fields_(false), + ignore_unknown_enum_values_(false), + use_lower_camel_for_enums_(false), + case_insensitive_enum_parsing_(true), + use_json_name_in_missing_fields_(false), + element_(nullptr), + size_insert_(), + output_(output), + buffer_(), + adapter_(&buffer_), + stream_(new CodedOutputStream(&adapter_)), + listener_(listener), + invalid_depth_(0), + tracker_(new ObjectLocationTracker()) {} + +ProtoWriter::ProtoWriter(const TypeInfo* typeinfo, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener) + : master_type_(type), + typeinfo_(typeinfo), + own_typeinfo_(false), + done_(false), + ignore_unknown_fields_(false), + ignore_unknown_enum_values_(false), + use_lower_camel_for_enums_(false), + case_insensitive_enum_parsing_(true), + use_json_name_in_missing_fields_(false), + element_(nullptr), + size_insert_(), + output_(output), + buffer_(), + adapter_(&buffer_), + stream_(new CodedOutputStream(&adapter_)), + listener_(listener), + invalid_depth_(0), + tracker_(new ObjectLocationTracker()) {} + +ProtoWriter::~ProtoWriter() { + if (own_typeinfo_) { + delete typeinfo_; + } + if (element_ == nullptr) return; + // Cleanup explicitly in order to avoid destructor stack overflow when input + // is deeply nested. + // Cast to BaseElement to avoid doing additional checks (like missing fields) + // during pop(). + std::unique_ptr element( + static_cast(element_.get())->pop()); + while (element != nullptr) { + element.reset(element->pop()); + } +} + +namespace { + +// Writes an INT32 field, including tag to the stream. +inline util::Status WriteInt32(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i32 = data.ToInt32(); + if (i32.ok()) { + WireFormatLite::WriteInt32(field_number, i32.value(), stream); + } + return i32.status(); +} + +// writes an SFIXED32 field, including tag, to the stream. +inline util::Status WriteSFixed32(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i32 = data.ToInt32(); + if (i32.ok()) { + WireFormatLite::WriteSFixed32(field_number, i32.value(), stream); + } + return i32.status(); +} + +// Writes an SINT32 field, including tag, to the stream. +inline util::Status WriteSInt32(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i32 = data.ToInt32(); + if (i32.ok()) { + WireFormatLite::WriteSInt32(field_number, i32.value(), stream); + } + return i32.status(); +} + +// Writes a FIXED32 field, including tag, to the stream. +inline util::Status WriteFixed32(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr u32 = data.ToUint32(); + if (u32.ok()) { + WireFormatLite::WriteFixed32(field_number, u32.value(), stream); + } + return u32.status(); +} + +// Writes a UINT32 field, including tag, to the stream. +inline util::Status WriteUInt32(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr u32 = data.ToUint32(); + if (u32.ok()) { + WireFormatLite::WriteUInt32(field_number, u32.value(), stream); + } + return u32.status(); +} + +// Writes an INT64 field, including tag, to the stream. +inline util::Status WriteInt64(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i64 = data.ToInt64(); + if (i64.ok()) { + WireFormatLite::WriteInt64(field_number, i64.value(), stream); + } + return i64.status(); +} + +// Writes an SFIXED64 field, including tag, to the stream. +inline util::Status WriteSFixed64(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i64 = data.ToInt64(); + if (i64.ok()) { + WireFormatLite::WriteSFixed64(field_number, i64.value(), stream); + } + return i64.status(); +} + +// Writes an SINT64 field, including tag, to the stream. +inline util::Status WriteSInt64(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr i64 = data.ToInt64(); + if (i64.ok()) { + WireFormatLite::WriteSInt64(field_number, i64.value(), stream); + } + return i64.status(); +} + +// Writes a FIXED64 field, including tag, to the stream. +inline util::Status WriteFixed64(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr u64 = data.ToUint64(); + if (u64.ok()) { + WireFormatLite::WriteFixed64(field_number, u64.value(), stream); + } + return u64.status(); +} + +// Writes a UINT64 field, including tag, to the stream. +inline util::Status WriteUInt64(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr u64 = data.ToUint64(); + if (u64.ok()) { + WireFormatLite::WriteUInt64(field_number, u64.value(), stream); + } + return u64.status(); +} + +// Writes a DOUBLE field, including tag, to the stream. +inline util::Status WriteDouble(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr d = data.ToDouble(); + if (d.ok()) { + WireFormatLite::WriteDouble(field_number, d.value(), stream); + } + return d.status(); +} + +// Writes a FLOAT field, including tag, to the stream. +inline util::Status WriteFloat(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr f = data.ToFloat(); + if (f.ok()) { + WireFormatLite::WriteFloat(field_number, f.value(), stream); + } + return f.status(); +} + +// Writes a BOOL field, including tag, to the stream. +inline util::Status WriteBool(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr b = data.ToBool(); + if (b.ok()) { + WireFormatLite::WriteBool(field_number, b.value(), stream); + } + return b.status(); +} + +// Writes a BYTES field, including tag, to the stream. +inline util::Status WriteBytes(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr c = data.ToBytes(); + if (c.ok()) { + WireFormatLite::WriteBytes(field_number, c.value(), stream); + } + return c.status(); +} + +// Writes a STRING field, including tag, to the stream. +inline util::Status WriteString(int field_number, const DataPiece& data, + CodedOutputStream* stream) { + util::StatusOr s = data.ToString(); + if (s.ok()) { + WireFormatLite::WriteString(field_number, s.value(), stream); + } + return s.status(); +} + +// Given a google::protobuf::Type, returns the set of all required fields. +std::unordered_set GetRequiredFields( + const google::protobuf::Type& type) { + std::unordered_set required; + for (int i = 0; i < type.fields_size(); i++) { + const google::protobuf::Field& field = type.fields(i); + if (field.cardinality() == google::protobuf::Field::CARDINALITY_REQUIRED) { + required.insert(&field); + } + } + return required; +} + +} // namespace + +ProtoWriter::ProtoElement::ProtoElement(const TypeInfo* typeinfo, + const google::protobuf::Type& type, + ProtoWriter* enclosing) + : BaseElement(nullptr), + ow_(enclosing), + parent_field_(nullptr), + typeinfo_(typeinfo), + proto3_(type.syntax() == google::protobuf::SYNTAX_PROTO3), + type_(type), + size_index_(-1), + array_index_(-1), + // oneof_indices_ values are 1-indexed (0 means not present). + oneof_indices_(type.oneofs_size() + 1) { + if (!proto3_) { + required_fields_ = GetRequiredFields(type_); + } +} + +ProtoWriter::ProtoElement::ProtoElement(ProtoWriter::ProtoElement* parent, + const google::protobuf::Field* field, + const google::protobuf::Type& type, + bool is_list) + : BaseElement(parent), + ow_(this->parent()->ow_), + parent_field_(field), + typeinfo_(this->parent()->typeinfo_), + proto3_(type.syntax() == google::protobuf::SYNTAX_PROTO3), + type_(type), + size_index_(!is_list && + field->kind() == google::protobuf::Field::TYPE_MESSAGE + ? ow_->size_insert_.size() + : -1), + array_index_(is_list ? 0 : -1), + // oneof_indices_ values are 1-indexed (0 means not present). + oneof_indices_(type_.oneofs_size() + 1) { + if (!is_list) { + if (ow_->IsRepeated(*field)) { + // Update array_index_ if it is an explicit list. + if (this->parent()->array_index_ >= 0) this->parent()->array_index_++; + } else if (!proto3_) { + // For required fields tracking. + this->parent()->RegisterField(field); + } + + if (field->kind() == google::protobuf::Field::TYPE_MESSAGE) { + if (!proto3_) { + required_fields_ = GetRequiredFields(type_); + } + int start_pos = ow_->stream_->ByteCount(); + // length of serialized message is the final buffer position minus + // starting buffer position, plus length adjustments for size fields + // of any nested messages. We start with -start_pos here, so we only + // need to add the final buffer position to it at the end. + SizeInfo info = {start_pos, -start_pos}; + ow_->size_insert_.push_back(info); + } + } +} + +ProtoWriter::ProtoElement* ProtoWriter::ProtoElement::pop() { + if (!proto3_) { + // Calls the registered error listener for any required field(s) not yet + // seen. + for (std::unordered_set::iterator it = + required_fields_.begin(); + it != required_fields_.end(); ++it) { + ow_->MissingField(ow_->use_json_name_in_missing_fields_ + ? (*it)->json_name() + : (*it)->name()); + } + } + // Computes the total number of proto bytes used by a message, also adjusts + // the size of all parent messages by the length of this size field. + // If size_index_ < 0, this is not a message, so no size field is added. + if (size_index_ >= 0) { + // Add the final buffer position to compute the total length of this + // serialized message. The stored value (before this addition) already + // contains the total length of the size fields of all nested messages + // minus the initial buffer position. + ow_->size_insert_[size_index_].size += ow_->stream_->ByteCount(); + // Calculate the length required to serialize the size field of the + // message, and propagate this additional size information upward to + // all enclosing messages. + int size = ow_->size_insert_[size_index_].size; + int length = CodedOutputStream::VarintSize32(size); + for (ProtoElement* e = parent(); e != nullptr; e = e->parent()) { + // Only nested messages have size field, lists do not have size field. + if (e->size_index_ >= 0) { + ow_->size_insert_[e->size_index_].size += length; + } + } + } + return BaseElement::pop(); +} + +void ProtoWriter::ProtoElement::RegisterField( + const google::protobuf::Field* field) { + if (!required_fields_.empty() && + field->cardinality() == google::protobuf::Field::CARDINALITY_REQUIRED) { + required_fields_.erase(field); + } +} + +std::string ProtoWriter::ProtoElement::ToString() const { + std::string loc = ""; + + // first populate a stack with the nodes since we need to process them + // from root to leaf when generating the string location + const ProtoWriter::ProtoElement* now = this; + std::stack element_stack; + while (now->parent() != nullptr) { + element_stack.push(now); + now = now->parent(); + } + + // now pop each node from the stack and append to the location string + while (!element_stack.empty()) { + now = element_stack.top(); + element_stack.pop(); + + if (!ow_->IsRepeated(*(now->parent_field_)) || + now->parent()->parent_field_ != now->parent_field_) { + std::string name = now->parent_field_->name(); + int i = 0; + while (i < name.size() && + (ascii_isalnum(name[i]) || name[i] == '_')) + ++i; + if (i > 0 && i == name.size()) { // safe field name + if (loc.empty()) { + loc = name; + } else { + StrAppend(&loc, ".", name); + } + } else { + StrAppend(&loc, "[\"", CEscape(name), "\"]"); + } + } + + int array_index_now = now->array_index_; + if (ow_->IsRepeated(*(now->parent_field_)) && array_index_now > 0) { + StrAppend(&loc, "[", array_index_now - 1, "]"); + } + } + + return loc; +} + +bool ProtoWriter::ProtoElement::IsOneofIndexTaken(int32_t index) { + return oneof_indices_[index]; +} + +void ProtoWriter::ProtoElement::TakeOneofIndex(int32_t index) { + oneof_indices_[index] = true; +} + +void ProtoWriter::InvalidName(StringPiece unknown_name, + StringPiece message) { + listener_->InvalidName(location(), unknown_name, message); +} + +void ProtoWriter::InvalidValue(StringPiece type_name, + StringPiece value) { + listener_->InvalidValue(location(), type_name, value); +} + +void ProtoWriter::MissingField(StringPiece missing_name) { + listener_->MissingField(location(), missing_name); +} + +ProtoWriter* ProtoWriter::StartObject( + StringPiece name) { + // Starting the root message. Create the root ProtoElement and return. + if (element_ == nullptr) { + if (!name.empty()) { + InvalidName(name, "Root element should not be named."); + } + element_.reset(new ProtoElement(typeinfo_, master_type_, this)); + return this; + } + + const google::protobuf::Field* field = BeginNamed(name, false); + + if (field == nullptr) return this; + + // Check to see if this field is a oneof and that no oneof in that group has + // already been set. + if (!ValidOneof(*field, name)) { + ++invalid_depth_; + return this; + } + + const google::protobuf::Type* type = LookupType(field); + if (type == nullptr) { + ++invalid_depth_; + InvalidName(name, StrCat("Missing descriptor for field: ", + field->type_url())); + return this; + } + + return StartObjectField(*field, *type); +} + + +ProtoWriter* ProtoWriter::EndObject() { + if (invalid_depth_ > 0) { + --invalid_depth_; + return this; + } + + if (element_ != nullptr) { + element_.reset(element_->pop()); + } + + + // If ending the root element, + // then serialize the full message with calculated sizes. + if (element_ == nullptr) { + WriteRootMessage(); + } + return this; +} + +ProtoWriter* ProtoWriter::StartList( + StringPiece name) { + + const google::protobuf::Field* field = BeginNamed(name, true); + + if (field == nullptr) return this; + + if (!ValidOneof(*field, name)) { + ++invalid_depth_; + return this; + } + + const google::protobuf::Type* type = LookupType(field); + if (type == nullptr) { + ++invalid_depth_; + InvalidName(name, StrCat("Missing descriptor for field: ", + field->type_url())); + return this; + } + + return StartListField(*field, *type); +} + + +ProtoWriter* ProtoWriter::EndList() { + if (invalid_depth_ > 0) { + --invalid_depth_; + } else if (element_ != nullptr) { + element_.reset(element_->pop()); + } + return this; +} + +ProtoWriter* ProtoWriter::RenderDataPiece( + StringPiece name, const DataPiece& data) { + util::Status status; + if (invalid_depth_ > 0) return this; + + const google::protobuf::Field* field = Lookup(name); + + if (field == nullptr) return this; + + if (!ValidOneof(*field, name)) return this; + + const google::protobuf::Type* type = LookupType(field); + if (type == nullptr) { + InvalidName(name, StrCat("Missing descriptor for field: ", + field->type_url())); + return this; + } + + return RenderPrimitiveField(*field, *type, data); +} + +bool ProtoWriter::ValidOneof(const google::protobuf::Field& field, + StringPiece unnormalized_name) { + if (element_ == nullptr) return true; + + if (field.oneof_index() > 0) { + if (element_->IsOneofIndexTaken(field.oneof_index())) { + InvalidValue( + "oneof", + StrCat( + "oneof field '", element_->type().oneofs(field.oneof_index() - 1), + "' is already set. Cannot set '", unnormalized_name, "'")); + return false; + } + element_->TakeOneofIndex(field.oneof_index()); + } + return true; +} + +bool ProtoWriter::IsRepeated(const google::protobuf::Field& field) { + return field.cardinality() == google::protobuf::Field::CARDINALITY_REPEATED; +} + +ProtoWriter* ProtoWriter::StartObjectField(const google::protobuf::Field& field, + const google::protobuf::Type& type) { + WriteTag(field); + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + return this; +} + +ProtoWriter* ProtoWriter::StartListField(const google::protobuf::Field& field, + const google::protobuf::Type& type) { + element_.reset(new ProtoElement(element_.release(), &field, type, true)); + return this; +} + +util::Status ProtoWriter::WriteEnum(int field_number, const DataPiece& data, + const google::protobuf::Enum* enum_type, + CodedOutputStream* stream, + bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, + bool ignore_unknown_values) { + bool is_unknown_enum_value = false; + util::StatusOr e = data.ToEnum( + enum_type, use_lower_camel_for_enums, case_insensitive_enum_parsing, + ignore_unknown_values, &is_unknown_enum_value); + if (e.ok() && !is_unknown_enum_value) { + WireFormatLite::WriteEnum(field_number, e.value(), stream); + } + return e.status(); +} + +ProtoWriter* ProtoWriter::RenderPrimitiveField( + const google::protobuf::Field& field, const google::protobuf::Type& type, + const DataPiece& data) { + util::Status status; + + // Pushing a ProtoElement and then pop it off at the end for 2 purposes: + // error location reporting and required field accounting. + // + // For proto3, since there is no required field tracking, we only need to + // push ProtoElement for error cases. + if (!element_->proto3()) { + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + } + + switch (field.kind()) { + case google::protobuf::Field::TYPE_INT32: { + status = WriteInt32(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_SFIXED32: { + status = WriteSFixed32(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_SINT32: { + status = WriteSInt32(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_FIXED32: { + status = WriteFixed32(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_UINT32: { + status = WriteUInt32(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_INT64: { + status = WriteInt64(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_SFIXED64: { + status = WriteSFixed64(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_SINT64: { + status = WriteSInt64(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_FIXED64: { + status = WriteFixed64(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_UINT64: { + status = WriteUInt64(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_DOUBLE: { + status = WriteDouble(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_FLOAT: { + status = WriteFloat(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_BOOL: { + status = WriteBool(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_BYTES: { + status = WriteBytes(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_STRING: { + status = WriteString(field.number(), data, stream_.get()); + break; + } + case google::protobuf::Field::TYPE_ENUM: { + status = WriteEnum( + field.number(), data, typeinfo_->GetEnumByTypeUrl(field.type_url()), + stream_.get(), use_lower_camel_for_enums_, + case_insensitive_enum_parsing_, ignore_unknown_enum_values_); + break; + } + default: // TYPE_GROUP, TYPE_MESSAGE, TYPE_UNKNOWN. + status = util::InvalidArgumentError(data.ValueAsStringOrDefault("")); + } + + if (!status.ok()) { + // Push a ProtoElement for location reporting purposes. + if (element_->proto3()) { + element_.reset(new ProtoElement(element_.release(), &field, type, false)); + } + InvalidValue(field.type_url().empty() + ? google::protobuf::Field_Kind_Name(field.kind()) + : field.type_url(), + status.message()); + element_.reset(element()->pop()); + return this; + } + + if (!element_->proto3()) element_.reset(element()->pop()); + + return this; +} + +const google::protobuf::Field* ProtoWriter::BeginNamed(StringPiece name, + bool is_list) { + if (invalid_depth_ > 0) { + ++invalid_depth_; + return nullptr; + } + const google::protobuf::Field* field = Lookup(name); + if (field == nullptr) { + ++invalid_depth_; + // InvalidName() already called in Lookup(). + return nullptr; + } + if (is_list && !IsRepeated(*field)) { + ++invalid_depth_; + InvalidName(name, "Proto field is not repeating, cannot start list."); + return nullptr; + } + return field; +} + +const google::protobuf::Field* ProtoWriter::Lookup( + StringPiece unnormalized_name) { + ProtoElement* e = element(); + if (e == nullptr) { + InvalidName(unnormalized_name, "Root element must be a message."); + return nullptr; + } + if (unnormalized_name.empty()) { + // Objects in repeated field inherit the same field descriptor. + if (e->parent_field() == nullptr) { + InvalidName(unnormalized_name, "Proto fields must have a name."); + } else if (!IsRepeated(*e->parent_field())) { + InvalidName(unnormalized_name, "Proto fields must have a name."); + return nullptr; + } + return e->parent_field(); + } + const google::protobuf::Field* field = + typeinfo_->FindField(&e->type(), unnormalized_name); + if (field == nullptr && !ignore_unknown_fields_) { + InvalidName(unnormalized_name, "Cannot find field."); + } + return field; +} + +const google::protobuf::Type* ProtoWriter::LookupType( + const google::protobuf::Field* field) { + return ((field->kind() == google::protobuf::Field::TYPE_MESSAGE || + field->kind() == google::protobuf::Field::TYPE_GROUP) + ? typeinfo_->GetTypeByTypeUrl(field->type_url()) + : &element_->type()); +} + +void ProtoWriter::WriteRootMessage() { + GOOGLE_DCHECK(!done_); + int curr_pos = 0; + // Calls the destructor of CodedOutputStream to remove any uninitialized + // memory from the Cord before we read it. + stream_.reset(nullptr); + const void* data; + int length; + io::ArrayInputStream input_stream(buffer_.data(), buffer_.size()); + while (input_stream.Next(&data, &length)) { + if (length == 0) continue; + int num_bytes = length; + // Write up to where we need to insert the size field. + // The number of bytes we may write is the smaller of: + // - the current fragment size + // - the distance to the next position where a size field needs to be + // inserted. + if (!size_insert_.empty() && + size_insert_.front().pos - curr_pos < num_bytes) { + num_bytes = size_insert_.front().pos - curr_pos; + } + output_->Append(static_cast(data), num_bytes); + if (num_bytes < length) { + input_stream.BackUp(length - num_bytes); + } + curr_pos += num_bytes; + // Insert the size field. + // size_insert_.front(): the next pair to be written. + // size_insert_.front().pos: position of the size field. + // size_insert_.front().size: the size (integer) to be inserted. + if (!size_insert_.empty() && curr_pos == size_insert_.front().pos) { + // Varint32 occupies at most 10 bytes. + uint8_t insert_buffer[10]; + uint8_t* insert_buffer_pos = CodedOutputStream::WriteVarint32ToArray( + size_insert_.front().size, insert_buffer); + output_->Append(reinterpret_cast(insert_buffer), + insert_buffer_pos - insert_buffer); + size_insert_.pop_front(); + } + } + output_->Flush(); + stream_.reset(new CodedOutputStream(&adapter_)); + done_ = true; +} + +void ProtoWriter::WriteTag(const google::protobuf::Field& field) { + WireFormatLite::WireType wire_type = WireFormatLite::WireTypeForFieldType( + static_cast(field.kind())); + stream_->WriteTag(WireFormatLite::MakeTag(field.number(), wire_type)); +} + + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/proto_writer.h b/libs/protobuf/src/google/protobuf/util/internal/proto_writer.h new file mode 100644 index 0000000..a7cf6ac --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/proto_writer.h @@ -0,0 +1,389 @@ +// 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_UTIL_INTERNAL_PROTO_WRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTO_WRITER_H__ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +class ObjectLocationTracker; + +// An ObjectWriter that can write protobuf bytes directly from writer events. +// This class does not support special types like Struct or Map. However, since +// this class supports raw protobuf, it can be used to provide support for +// special types by inheriting from it or by wrapping it. +// +// It also supports streaming. +class PROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter { + public: +// Constructor. Does not take ownership of any parameter passed in. + ProtoWriter(TypeResolver* type_resolver, const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener); + ~ProtoWriter() override; + + // ObjectWriter methods. + ProtoWriter* StartObject(StringPiece name) override; + ProtoWriter* EndObject() override; + ProtoWriter* StartList(StringPiece name) override; + ProtoWriter* EndList() override; + ProtoWriter* RenderBool(StringPiece name, bool value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderInt32(StringPiece name, int32_t value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderUint32(StringPiece name, uint32_t value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderInt64(StringPiece name, int64_t value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderUint64(StringPiece name, uint64_t value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderDouble(StringPiece name, double value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderFloat(StringPiece name, float value) override { + return RenderDataPiece(name, DataPiece(value)); + } + ProtoWriter* RenderString(StringPiece name, + StringPiece value) override { + return RenderDataPiece(name, + DataPiece(value, use_strict_base64_decoding())); + } + + ProtoWriter* RenderBytes(StringPiece name, StringPiece value) override { + return RenderDataPiece( + name, DataPiece(value, false, use_strict_base64_decoding())); + } + + ProtoWriter* RenderNull(StringPiece name) override { + return RenderDataPiece(name, DataPiece::NullData()); + } + + + // Renders a DataPiece 'value' into a field whose wire type is determined + // from the given field 'name'. + virtual ProtoWriter* RenderDataPiece(StringPiece name, + const DataPiece& data); + + + // Returns the location tracker to use for tracking locations for errors. + const LocationTrackerInterface& location() { + return element_ != nullptr ? *element_ : *tracker_; + } + + // When true, we finished writing to output a complete message. + bool done() override { return done_; } + + // Returns the proto stream object. + io::CodedOutputStream* stream() { return stream_.get(); } + + // Getters and mutators of invalid_depth_. + void IncrementInvalidDepth() { ++invalid_depth_; } + void DecrementInvalidDepth() { --invalid_depth_; } + int invalid_depth() { return invalid_depth_; } + + ErrorListener* listener() { return listener_; } + + const TypeInfo* typeinfo() { return typeinfo_; } + + void set_ignore_unknown_fields(bool ignore_unknown_fields) { + ignore_unknown_fields_ = ignore_unknown_fields; + } + + bool ignore_unknown_fields() { return ignore_unknown_fields_; } + + void set_ignore_unknown_enum_values(bool ignore_unknown_enum_values) { + ignore_unknown_enum_values_ = ignore_unknown_enum_values; + } + + void set_use_lower_camel_for_enums(bool use_lower_camel_for_enums) { + use_lower_camel_for_enums_ = use_lower_camel_for_enums; + } + + void set_case_insensitive_enum_parsing(bool case_insensitive_enum_parsing) { + case_insensitive_enum_parsing_ = case_insensitive_enum_parsing; + } + + void set_use_json_name_in_missing_fields( + bool use_json_name_in_missing_fields) { + use_json_name_in_missing_fields_ = use_json_name_in_missing_fields; + } + + protected: + class PROTOBUF_EXPORT ProtoElement : public BaseElement, + public LocationTrackerInterface { + public: + // Constructor for the root element. No parent nor field. + ProtoElement(const TypeInfo* typeinfo, const google::protobuf::Type& type, + ProtoWriter* enclosing); + + // Constructor for a field of an element. + ProtoElement(ProtoElement* parent, const google::protobuf::Field* field, + const google::protobuf::Type& type, bool is_list); + + ~ProtoElement() override {} + + // Called just before the destructor for clean up: + // - reports any missing required fields + // - computes the space needed by the size field, and augment the + // length of all parent messages by this additional space. + // - releases and returns the parent pointer. + ProtoElement* pop(); + + // Accessors + // parent_field() may be nullptr if we are at root. + const google::protobuf::Field* parent_field() const { + return parent_field_; + } + const google::protobuf::Type& type() const { return type_; } + + // Registers field for accounting required fields. + void RegisterField(const google::protobuf::Field* field); + + // To report location on error messages. + std::string ToString() const override; + + ProtoElement* parent() const override { + return static_cast(BaseElement::parent()); + } + + // Returns true if the index is already taken by a preceding oneof input. + bool IsOneofIndexTaken(int32_t index); + + // Marks the oneof 'index' as taken. Future inputs to this oneof will + // generate an error. + void TakeOneofIndex(int32_t index); + + bool proto3() { return proto3_; } + + private: + // Used for access to variables of the enclosing instance of + // ProtoWriter. + ProtoWriter* ow_; + + // Describes the element as a field in the parent message. + // parent_field_ is nullptr if and only if this element is the root element. + const google::protobuf::Field* parent_field_; + + // TypeInfo to lookup types. + const TypeInfo* typeinfo_; + + // Whether the type_ is proto3 or not. + bool proto3_; + + // Additional variables if this element is a message: + // (Root element is always a message). + // type_ : the type of this element. + // required_fields_ : set of required fields. + // size_index_ : index into ProtoWriter::size_insert_ + // for later insertion of serialized message length. + const google::protobuf::Type& type_; + std::unordered_set required_fields_; + const int size_index_; + + // Tracks position in repeated fields, needed for LocationTrackerInterface. + int array_index_; + + // Set of oneof indices already seen for the type_. Used to validate + // incoming messages so no more than one oneof is set. + std::vector oneof_indices_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoElement); + }; + + // Container for inserting 'size' information at the 'pos' position. + struct SizeInfo { + const int pos; + int size; + }; + + ProtoWriter(const TypeInfo* typeinfo, const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener); + + ProtoElement* element() override { return element_.get(); } + + // Helper methods for calling ErrorListener. See error_listener.h. + void InvalidName(StringPiece unknown_name, StringPiece message); + void InvalidValue(StringPiece type_name, StringPiece value); + void MissingField(StringPiece missing_name); + + // Common code for BeginObject() and BeginList() that does invalid_depth_ + // bookkeeping associated with name lookup. + const google::protobuf::Field* BeginNamed(StringPiece name, + bool is_list); + + // Lookup the field in the current element. Looks in the base descriptor + // and in any extension. This will report an error if the field cannot be + // found when ignore_unknown_names_ is false or if multiple matching + // extensions are found. + const google::protobuf::Field* Lookup(StringPiece name); + + // Lookup the field type in the type descriptor. Returns nullptr if the type + // is not known. + const google::protobuf::Type* LookupType( + const google::protobuf::Field* field); + + // Write serialized output to the final output ByteSink, inserting all + // the size information for nested messages that are missing from the + // intermediate Cord buffer. + void WriteRootMessage(); + + // Helper method to write proto tags based on the given field. + void WriteTag(const google::protobuf::Field& field); + + + // Returns true if the field for type_ can be set as a oneof. If field is not + // a oneof type, this function does nothing and returns true. + // If another field for this oneof is already set, this function returns + // false. It also calls the appropriate error callback. + // unnormalized_name is used for error string. + bool ValidOneof(const google::protobuf::Field& field, + StringPiece unnormalized_name); + + // Returns true if the field is repeated. + bool IsRepeated(const google::protobuf::Field& field); + + // Starts an object given the field and the enclosing type. + ProtoWriter* StartObjectField(const google::protobuf::Field& field, + const google::protobuf::Type& type); + + // Starts a list given the field and the enclosing type. + ProtoWriter* StartListField(const google::protobuf::Field& field, + const google::protobuf::Type& type); + + // Renders a primitive field given the field and the enclosing type. + ProtoWriter* RenderPrimitiveField(const google::protobuf::Field& field, + const google::protobuf::Type& type, + const DataPiece& data); + + private: + // Writes an ENUM field, including tag, to the stream. + static util::Status WriteEnum(int field_number, const DataPiece& data, + const google::protobuf::Enum* enum_type, + io::CodedOutputStream* stream, + bool use_lower_camel_for_enums, + bool case_insensitive_enum_parsing, + bool ignore_unknown_values); + + // Variables for describing the structure of the input tree: + // master_type_: descriptor for the whole protobuf message. + // typeinfo_ : the TypeInfo object to lookup types. + const google::protobuf::Type& master_type_; + const TypeInfo* typeinfo_; + // Whether we own the typeinfo_ object. + bool own_typeinfo_; + + // Indicates whether we finished writing root message completely. + bool done_; + + // If true, don't report unknown field names to the listener. + bool ignore_unknown_fields_; + + // If true, don't report unknown enum values to the listener. + bool ignore_unknown_enum_values_; + + // If true, check if enum name in camel case or without underscore matches the + // field name. + bool use_lower_camel_for_enums_; + + // If true, check if enum name in UPPER_CASE matches the field name. + bool case_insensitive_enum_parsing_; + + // If true, use the json name in missing fields errors. + bool use_json_name_in_missing_fields_; + + // Variable for internal state processing: + // element_ : the current element. + // size_insert_: sizes of nested messages. + // pos - position to insert the size field. + // size - size value to be inserted. + std::unique_ptr element_; + std::deque size_insert_; + + // Variables for output generation: + // output_ : pointer to an external ByteSink for final user-visible output. + // buffer_ : buffer holding partial message before being ready for output_. + // adapter_ : internal adapter between CodedOutputStream and buffer_. + // stream_ : wrapper for writing tags and other encodings in wire format. + strings::ByteSink* output_; + std::string buffer_; + io::StringOutputStream adapter_; + std::unique_ptr stream_; + + // Variables for error tracking and reporting: + // listener_ : a place to report any errors found. + // invalid_depth_: number of enclosing invalid nested messages. + // tracker_ : the root location tracker interface. + ErrorListener* listener_; + int invalid_depth_; + std::unique_ptr tracker_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTO_WRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc new file mode 100644 index 0000000..cf6c99a --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -0,0 +1,1114 @@ +// 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Must be included last. +#include + + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormat; +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; + +namespace { + +static int kDefaultMaxRecursionDepth = 64; + +// Finds a field with the given number. nullptr if none found. +const google::protobuf::Field* FindFieldByNumber( + const google::protobuf::Type& type, int number); + +// Returns true if the field is packable. +bool IsPackable(const google::protobuf::Field& field); + +// Finds an enum value with the given number. nullptr if none found. +const google::protobuf::EnumValue* FindEnumValueByNumber( + const google::protobuf::Enum& tech_enum, int number); + +// Utility function to format nanos. +const std::string FormatNanos(uint32_t nanos, bool with_trailing_zeros); + +util::StatusOr MapKeyDefaultValueAsString( + const google::protobuf::Field& field) { + switch (field.kind()) { + case google::protobuf::Field::TYPE_BOOL: + return std::string("false"); + case google::protobuf::Field::TYPE_INT32: + case google::protobuf::Field::TYPE_INT64: + case google::protobuf::Field::TYPE_UINT32: + case google::protobuf::Field::TYPE_UINT64: + case google::protobuf::Field::TYPE_SINT32: + case google::protobuf::Field::TYPE_SINT64: + case google::protobuf::Field::TYPE_SFIXED32: + case google::protobuf::Field::TYPE_SFIXED64: + case google::protobuf::Field::TYPE_FIXED32: + case google::protobuf::Field::TYPE_FIXED64: + return std::string("0"); + case google::protobuf::Field::TYPE_STRING: + return std::string(); + default: + return util::InternalError("Invalid map key type."); + } +} +} // namespace + + +ProtoStreamObjectSource::ProtoStreamObjectSource( + io::CodedInputStream* stream, TypeResolver* type_resolver, + const google::protobuf::Type& type, const RenderOptions& render_options) + : stream_(stream), + typeinfo_(TypeInfo::NewTypeInfo(type_resolver)), + own_typeinfo_(true), + type_(type), + render_options_(render_options), + recursion_depth_(0), + max_recursion_depth_(kDefaultMaxRecursionDepth) { + GOOGLE_LOG_IF(DFATAL, stream == nullptr) << "Input stream is nullptr."; +} + +ProtoStreamObjectSource::ProtoStreamObjectSource( + io::CodedInputStream* stream, const TypeInfo* typeinfo, + const google::protobuf::Type& type, const RenderOptions& render_options) + : stream_(stream), + typeinfo_(typeinfo), + own_typeinfo_(false), + type_(type), + render_options_(render_options), + recursion_depth_(0), + max_recursion_depth_(kDefaultMaxRecursionDepth) { + GOOGLE_LOG_IF(DFATAL, stream == nullptr) << "Input stream is nullptr."; +} + +ProtoStreamObjectSource::~ProtoStreamObjectSource() { + if (own_typeinfo_) { + delete typeinfo_; + } +} + +util::Status ProtoStreamObjectSource::NamedWriteTo(StringPiece name, + ObjectWriter* ow) const { + return WriteMessage(type_, name, 0, true, ow); +} + +const google::protobuf::Field* ProtoStreamObjectSource::FindAndVerifyField( + const google::protobuf::Type& type, uint32_t tag) const { + // Lookup the new field in the type by tag number. + const google::protobuf::Field* field = FindFieldByNumber(type, tag >> 3); + // Verify if the field corresponds to the wire type in tag. + // If there is any discrepancy, mark the field as not found. + if (field != nullptr) { + WireFormatLite::WireType expected_type = + WireFormatLite::WireTypeForFieldType( + static_cast(field->kind())); + WireFormatLite::WireType actual_type = WireFormatLite::GetTagWireType(tag); + if (actual_type != expected_type && + (!IsPackable(*field) || + actual_type != WireFormatLite::WIRETYPE_LENGTH_DELIMITED)) { + field = nullptr; + } + } + return field; +} + +util::Status ProtoStreamObjectSource::WriteMessage( + const google::protobuf::Type& type, StringPiece name, + const uint32_t end_tag, bool include_start_and_end, + ObjectWriter* ow) const { + + const TypeRenderer* type_renderer = FindTypeRenderer(type.name()); + if (type_renderer != nullptr) { + return (*type_renderer)(this, type, name, ow); + } + + const google::protobuf::Field* field = nullptr; + std::string field_name; + // last_tag set to dummy value that is different from tag. + uint32_t tag = stream_->ReadTag(), last_tag = tag + 1; + UnknownFieldSet unknown_fields; + + + if (include_start_and_end) { + ow->StartObject(name); + } + while (tag != end_tag && tag != 0) { + if (tag != last_tag) { // Update field only if tag is changed. + last_tag = tag; + field = FindAndVerifyField(type, tag); + if (field != nullptr) { + if (render_options_.preserve_proto_field_names) { + field_name = field->name(); + } else { + field_name = field->json_name(); + } + } + } + if (field == nullptr) { + // If we didn't find a field, skip this unknown tag. + // TODO(wpoon): Check return boolean value. + WireFormat::SkipField( + stream_, tag, + nullptr); + tag = stream_->ReadTag(); + continue; + } + + if (field->cardinality() == google::protobuf::Field::CARDINALITY_REPEATED) { + if (IsMap(*field)) { + ow->StartObject(field_name); + ASSIGN_OR_RETURN(tag, RenderMap(field, field_name, tag, ow)); + ow->EndObject(); + } else { + ASSIGN_OR_RETURN(tag, RenderList(field, field_name, tag, ow)); + } + } else { + // Render the field. + RETURN_IF_ERROR(RenderField(field, field_name, ow)); + tag = stream_->ReadTag(); + } + } + + + if (include_start_and_end) { + ow->EndObject(); + } + return util::Status(); +} + +util::StatusOr ProtoStreamObjectSource::RenderList( + const google::protobuf::Field* field, StringPiece name, + uint32_t list_tag, ObjectWriter* ow) const { + uint32_t tag_to_return = 0; + ow->StartList(name); + if (IsPackable(*field) && + list_tag == + WireFormatLite::MakeTag(field->number(), + WireFormatLite::WIRETYPE_LENGTH_DELIMITED)) { + RETURN_IF_ERROR(RenderPacked(field, ow)); + // Since packed fields have a single tag, read another tag from stream to + // return. + tag_to_return = stream_->ReadTag(); + } else { + do { + RETURN_IF_ERROR(RenderField(field, "", ow)); + } while ((tag_to_return = stream_->ReadTag()) == list_tag); + } + ow->EndList(); + return tag_to_return; +} + +util::StatusOr ProtoStreamObjectSource::RenderMap( + const google::protobuf::Field* field, StringPiece /* name */, + uint32_t list_tag, ObjectWriter* ow) const { + const google::protobuf::Type* field_type = + typeinfo_->GetTypeByTypeUrl(field->type_url()); + uint32_t tag_to_return = 0; + do { + // Render map entry message type. + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); // message length + int old_limit = stream_->PushLimit(buffer32); + std::string map_key; + for (uint32_t tag = stream_->ReadTag(); tag != 0; + tag = stream_->ReadTag()) { + const google::protobuf::Field* map_entry_field = + FindAndVerifyField(*field_type, tag); + if (map_entry_field == nullptr) { + WireFormat::SkipField(stream_, tag, nullptr); + continue; + } + // Map field numbers are key = 1 and value = 2 + if (map_entry_field->number() == 1) { + map_key = ReadFieldValueAsString(*map_entry_field); + } else if (map_entry_field->number() == 2) { + if (map_key.empty()) { + // An absent map key is treated as the default. + const google::protobuf::Field* key_field = + FindFieldByNumber(*field_type, 1); + if (key_field == nullptr) { + // The Type info for this map entry is incorrect. It should always + // have a field named "key" and with field number 1. + return util::InternalError("Invalid map entry."); + } + ASSIGN_OR_RETURN(map_key, MapKeyDefaultValueAsString(*key_field)); + } + RETURN_IF_ERROR(RenderField(map_entry_field, map_key, ow)); + } else { + // The Type info for this map entry is incorrect. It should contain + // exactly two fields with field number 1 and 2. + return util::InternalError("Invalid map entry."); + } + } + stream_->PopLimit(old_limit); + } while ((tag_to_return = stream_->ReadTag()) == list_tag); + return tag_to_return; +} + +util::Status ProtoStreamObjectSource::RenderPacked( + const google::protobuf::Field* field, ObjectWriter* ow) const { + uint32_t length; + stream_->ReadVarint32(&length); + int old_limit = stream_->PushLimit(length); + while (stream_->BytesUntilLimit() > 0) { + RETURN_IF_ERROR(RenderField(field, StringPiece(), ow)); + } + stream_->PopLimit(old_limit); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderTimestamp( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + std::pair p = os->ReadSecondsAndNanos(type); + int64_t seconds = p.first; + int32_t nanos = p.second; + if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) { + return util::InternalError(StrCat( + "Timestamp seconds exceeds limit for field: ", field_name)); + } + + if (nanos < 0 || nanos >= kNanosPerSecond) { + return util::InternalError( + StrCat("Timestamp nanos exceeds limit for field: ", field_name)); + } + + ow->RenderString(field_name, + ::google::protobuf::internal::FormatTime(seconds, nanos)); + + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderDuration( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + std::pair p = os->ReadSecondsAndNanos(type); + int64_t seconds = p.first; + int32_t nanos = p.second; + if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds) { + return util::InternalError( + StrCat("Duration seconds exceeds limit for field: ", field_name)); + } + + if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { + return util::InternalError( + StrCat("Duration nanos exceeds limit for field: ", field_name)); + } + + std::string sign = ""; + if (seconds < 0) { + if (nanos > 0) { + return util::InternalError( + StrCat("Duration nanos is non-negative, but seconds is " + "negative for field: ", + field_name)); + } + sign = "-"; + seconds = -seconds; + nanos = -nanos; + } else if (seconds == 0 && nanos < 0) { + sign = "-"; + nanos = -nanos; + } + std::string formatted_duration = StringPrintf( + "%s%lld%ss", sign.c_str(), static_cast(seconds), // NOLINT + FormatNanos( + nanos, + false + ) + .c_str()); + ow->RenderString(field_name, formatted_duration); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderDouble( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint64_t buffer64 = 0; // default value of Double wrapper value + if (tag != 0) { + os->stream_->ReadLittleEndian64(&buffer64); + os->stream_->ReadTag(); + } + ow->RenderDouble(field_name, bit_cast(buffer64)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderFloat( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint32_t buffer32 = 0; // default value of Float wrapper value + if (tag != 0) { + os->stream_->ReadLittleEndian32(&buffer32); + os->stream_->ReadTag(); + } + ow->RenderFloat(field_name, bit_cast(buffer32)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderInt64( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint64_t buffer64 = 0; // default value of Int64 wrapper value + if (tag != 0) { + os->stream_->ReadVarint64(&buffer64); + os->stream_->ReadTag(); + } + ow->RenderInt64(field_name, bit_cast(buffer64)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderUInt64( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint64_t buffer64 = 0; // default value of UInt64 wrapper value + if (tag != 0) { + os->stream_->ReadVarint64(&buffer64); + os->stream_->ReadTag(); + } + ow->RenderUint64(field_name, bit_cast(buffer64)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderInt32( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint32_t buffer32 = 0; // default value of Int32 wrapper value + if (tag != 0) { + os->stream_->ReadVarint32(&buffer32); + os->stream_->ReadTag(); + } + ow->RenderInt32(field_name, bit_cast(buffer32)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderUInt32( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint32_t buffer32 = 0; // default value of UInt32 wrapper value + if (tag != 0) { + os->stream_->ReadVarint32(&buffer32); + os->stream_->ReadTag(); + } + ow->RenderUint32(field_name, bit_cast(buffer32)); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderBool( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint64_t buffer64 = 0; // results in 'false' value as default, which is the + // default value of Bool wrapper + if (tag != 0) { + os->stream_->ReadVarint64(&buffer64); + os->stream_->ReadTag(); + } + ow->RenderBool(field_name, buffer64 != 0); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderString( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint32_t buffer32; + std::string str; // default value of empty for String wrapper + if (tag != 0) { + os->stream_->ReadVarint32(&buffer32); // string size. + os->stream_->ReadString(&str, buffer32); + os->stream_->ReadTag(); + } + ow->RenderString(field_name, str); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderBytes( + const ProtoStreamObjectSource* os, const google::protobuf::Type& /*type*/, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + uint32_t buffer32; + std::string str; + if (tag != 0) { + os->stream_->ReadVarint32(&buffer32); + os->stream_->ReadString(&str, buffer32); + os->stream_->ReadTag(); + } + ow->RenderBytes(field_name, str); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderStruct( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + const google::protobuf::Field* field = nullptr; + uint32_t tag = os->stream_->ReadTag(); + ow->StartObject(field_name); + while (tag != 0) { + field = os->FindAndVerifyField(type, tag); + if (field == nullptr) { + WireFormat::SkipField(os->stream_, tag, nullptr); + tag = os->stream_->ReadTag(); + continue; + } + // google.protobuf.Struct has only one field that is a map. Hence we use + // RenderMap to render that field. + if (os->IsMap(*field)) { + ASSIGN_OR_RETURN(tag, os->RenderMap(field, field_name, tag, ow)); + } + } + ow->EndObject(); + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderStructValue( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + const google::protobuf::Field* field = nullptr; + for (uint32_t tag = os->stream_->ReadTag(); tag != 0; + tag = os->stream_->ReadTag()) { + field = os->FindAndVerifyField(type, tag); + if (field == nullptr) { + WireFormat::SkipField(os->stream_, tag, nullptr); + continue; + } + RETURN_IF_ERROR(os->RenderField(field, field_name, ow)); + } + return util::Status(); +} + +// TODO(skarvaje): Avoid code duplication of for loops and SkipField logic. +util::Status ProtoStreamObjectSource::RenderStructListValue( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + uint32_t tag = os->stream_->ReadTag(); + + // Render empty list when we find empty ListValue message. + if (tag == 0) { + ow->StartList(field_name); + ow->EndList(); + return util::Status(); + } + + while (tag != 0) { + const google::protobuf::Field* field = os->FindAndVerifyField(type, tag); + if (field == nullptr) { + WireFormat::SkipField(os->stream_, tag, nullptr); + tag = os->stream_->ReadTag(); + continue; + } + ASSIGN_OR_RETURN(tag, os->RenderList(field, field_name, tag, ow)); + } + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderAny( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + // An Any is of the form { string type_url = 1; bytes value = 2; } + uint32_t tag; + std::string type_url; + std::string value; + + // First read out the type_url and value from the proto stream + for (tag = os->stream_->ReadTag(); tag != 0; tag = os->stream_->ReadTag()) { + const google::protobuf::Field* field = os->FindAndVerifyField(type, tag); + if (field == nullptr) { + WireFormat::SkipField(os->stream_, tag, nullptr); + continue; + } + // 'type_url' has field number of 1 and 'value' has field number 2 + // //google/protobuf/any.proto + if (field->number() == 1) { + // read type_url + uint32_t type_url_size; + os->stream_->ReadVarint32(&type_url_size); + os->stream_->ReadString(&type_url, type_url_size); + } else if (field->number() == 2) { + // read value + uint32_t value_size; + os->stream_->ReadVarint32(&value_size); + os->stream_->ReadString(&value, value_size); + } + } + + // If there is no value, we don't lookup the type, we just output it (if + // present). If both type and value are empty we output an empty object. + if (value.empty()) { + ow->StartObject(field_name); + if (!type_url.empty()) { + ow->RenderString("@type", type_url); + } + ow->EndObject(); + return util::Status(); + } + + // If there is a value but no type, we cannot render it, so report an error. + if (type_url.empty()) { + // TODO(sven): Add an external message once those are ready. + return util::InternalError("Invalid Any, the type_url is missing."); + } + + util::StatusOr resolved_type = + os->typeinfo_->ResolveTypeUrl(type_url); + + if (!resolved_type.ok()) { + // Convert into an internal error, since this means the backend gave us + // an invalid response (missing or invalid type information). + return util::InternalError(resolved_type.status().message()); + } + // nested_type cannot be null at this time. + const google::protobuf::Type* nested_type = resolved_type.value(); + + io::ArrayInputStream zero_copy_stream(value.data(), value.size()); + io::CodedInputStream in_stream(&zero_copy_stream); + // We know the type so we can render it. Recursively parse the nested stream + // using a nested ProtoStreamObjectSource using our nested type information. + ProtoStreamObjectSource nested_os(&in_stream, os->typeinfo_, *nested_type, + os->render_options_); + + // We manually call start and end object here so we can inject the @type. + ow->StartObject(field_name); + ow->RenderString("@type", type_url); + util::Status result = + nested_os.WriteMessage(nested_os.type_, "value", 0, false, ow); + ow->EndObject(); + return result; +} + +util::Status ProtoStreamObjectSource::RenderFieldMask( + const ProtoStreamObjectSource* os, const google::protobuf::Type& type, + StringPiece field_name, ObjectWriter* ow) { + std::string combined; + uint32_t buffer32; + uint32_t paths_field_tag = 0; + for (uint32_t tag = os->stream_->ReadTag(); tag != 0; + tag = os->stream_->ReadTag()) { + if (paths_field_tag == 0) { + const google::protobuf::Field* field = os->FindAndVerifyField(type, tag); + if (field != nullptr && field->number() == 1 && + field->name() == "paths") { + paths_field_tag = tag; + } + } + if (paths_field_tag != tag) { + return util::InternalError("Invalid FieldMask, unexpected field."); + } + std::string str; + os->stream_->ReadVarint32(&buffer32); // string size. + os->stream_->ReadString(&str, buffer32); + if (!combined.empty()) { + combined.append(","); + } + combined.append(ConvertFieldMaskPath(str, &ToCamelCase)); + } + ow->RenderString(field_name, combined); + return util::Status(); +} + + +std::unordered_map* + ProtoStreamObjectSource::renderers_ = nullptr; +PROTOBUF_NAMESPACE_ID::internal::once_flag source_renderers_init_; + + +void ProtoStreamObjectSource::InitRendererMap() { + renderers_ = new std::unordered_map(); + (*renderers_)["google.protobuf.Timestamp"] = + &ProtoStreamObjectSource::RenderTimestamp; + (*renderers_)["google.protobuf.Duration"] = + &ProtoStreamObjectSource::RenderDuration; + (*renderers_)["google.protobuf.DoubleValue"] = + &ProtoStreamObjectSource::RenderDouble; + (*renderers_)["google.protobuf.FloatValue"] = + &ProtoStreamObjectSource::RenderFloat; + (*renderers_)["google.protobuf.Int64Value"] = + &ProtoStreamObjectSource::RenderInt64; + (*renderers_)["google.protobuf.UInt64Value"] = + &ProtoStreamObjectSource::RenderUInt64; + (*renderers_)["google.protobuf.Int32Value"] = + &ProtoStreamObjectSource::RenderInt32; + (*renderers_)["google.protobuf.UInt32Value"] = + &ProtoStreamObjectSource::RenderUInt32; + (*renderers_)["google.protobuf.BoolValue"] = + &ProtoStreamObjectSource::RenderBool; + (*renderers_)["google.protobuf.StringValue"] = + &ProtoStreamObjectSource::RenderString; + (*renderers_)["google.protobuf.BytesValue"] = + &ProtoStreamObjectSource::RenderBytes; + (*renderers_)["google.protobuf.Any"] = &ProtoStreamObjectSource::RenderAny; + (*renderers_)["google.protobuf.Struct"] = + &ProtoStreamObjectSource::RenderStruct; + (*renderers_)["google.protobuf.Value"] = + &ProtoStreamObjectSource::RenderStructValue; + (*renderers_)["google.protobuf.ListValue"] = + &ProtoStreamObjectSource::RenderStructListValue; + (*renderers_)["google.protobuf.FieldMask"] = + &ProtoStreamObjectSource::RenderFieldMask; + ::google::protobuf::internal::OnShutdown(&DeleteRendererMap); +} + +void ProtoStreamObjectSource::DeleteRendererMap() { + delete ProtoStreamObjectSource::renderers_; + renderers_ = nullptr; +} + +// static +ProtoStreamObjectSource::TypeRenderer* +ProtoStreamObjectSource::FindTypeRenderer(const std::string& type_url) { + PROTOBUF_NAMESPACE_ID::internal::call_once(source_renderers_init_, + InitRendererMap); + return FindOrNull(*renderers_, type_url); +} + +util::Status ProtoStreamObjectSource::RenderField( + const google::protobuf::Field* field, StringPiece field_name, + ObjectWriter* ow) const { + // Short-circuit message types as it tends to call WriteMessage recursively + // and ends up using a lot of stack space. Keep the stack usage of this + // message small in order to preserve stack space and not crash. + if (field->kind() == google::protobuf::Field::TYPE_MESSAGE) { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); // message length + int old_limit = stream_->PushLimit(buffer32); + // Get the nested message type for this field. + const google::protobuf::Type* type = + typeinfo_->GetTypeByTypeUrl(field->type_url()); + if (type == nullptr) { + return util::InternalError( + StrCat("Invalid configuration. Could not find the type: ", + field->type_url())); + } + + // Short-circuit any special type rendering to save call-stack space. + const TypeRenderer* type_renderer = FindTypeRenderer(type->name()); + + RETURN_IF_ERROR(IncrementRecursionDepth(type->name(), field_name)); + if (type_renderer != nullptr) { + RETURN_IF_ERROR((*type_renderer)(this, *type, field_name, ow)); + } else { + RETURN_IF_ERROR(WriteMessage(*type, field_name, 0, true, ow)); + } + --recursion_depth_; + + if (!stream_->ConsumedEntireMessage()) { + return util::InvalidArgumentError( + "Nested protocol message not parsed in its entirety."); + } + stream_->PopLimit(old_limit); + } else { + // Render all other non-message types. + return RenderNonMessageField(field, field_name, ow); + } + return util::Status(); +} + +util::Status ProtoStreamObjectSource::RenderNonMessageField( + const google::protobuf::Field* field, StringPiece field_name, + ObjectWriter* ow) const { + // Temporary buffers of different types. + uint32_t buffer32 = 0; + uint64_t buffer64 = 0; + std::string strbuffer; + switch (field->kind()) { + case google::protobuf::Field::TYPE_BOOL: { + stream_->ReadVarint64(&buffer64); + ow->RenderBool(field_name, buffer64 != 0); + break; + } + case google::protobuf::Field::TYPE_INT32: { + stream_->ReadVarint32(&buffer32); + ow->RenderInt32(field_name, bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_INT64: { + stream_->ReadVarint64(&buffer64); + ow->RenderInt64(field_name, bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_UINT32: { + stream_->ReadVarint32(&buffer32); + ow->RenderUint32(field_name, bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_UINT64: { + stream_->ReadVarint64(&buffer64); + ow->RenderUint64(field_name, bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_SINT32: { + stream_->ReadVarint32(&buffer32); + ow->RenderInt32(field_name, WireFormatLite::ZigZagDecode32(buffer32)); + break; + } + case google::protobuf::Field::TYPE_SINT64: { + stream_->ReadVarint64(&buffer64); + ow->RenderInt64(field_name, WireFormatLite::ZigZagDecode64(buffer64)); + break; + } + case google::protobuf::Field::TYPE_SFIXED32: { + stream_->ReadLittleEndian32(&buffer32); + ow->RenderInt32(field_name, bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_SFIXED64: { + stream_->ReadLittleEndian64(&buffer64); + ow->RenderInt64(field_name, bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_FIXED32: { + stream_->ReadLittleEndian32(&buffer32); + ow->RenderUint32(field_name, bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_FIXED64: { + stream_->ReadLittleEndian64(&buffer64); + ow->RenderUint64(field_name, bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_FLOAT: { + stream_->ReadLittleEndian32(&buffer32); + ow->RenderFloat(field_name, bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_DOUBLE: { + stream_->ReadLittleEndian64(&buffer64); + ow->RenderDouble(field_name, bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_ENUM: { + stream_->ReadVarint32(&buffer32); + + // If the field represents an explicit NULL value, render null. + if (field->type_url() == kStructNullValueTypeUrl) { + ow->RenderNull(field_name); + break; + } + + // Get the nested enum type for this field. + // TODO(skarvaje): Avoid string manipulation. Find ways to speed this + // up. + const google::protobuf::Enum* en = + typeinfo_->GetEnumByTypeUrl(field->type_url()); + // Lookup the name of the enum, and render that. Unknown enum values + // are printed as integers. + if (en != nullptr) { + const google::protobuf::EnumValue* enum_value = + FindEnumValueByNumber(*en, buffer32); + if (enum_value != nullptr) { + if (render_options_.use_ints_for_enums) { + ow->RenderInt32(field_name, buffer32); + } else if (render_options_.use_lower_camel_for_enums) { + ow->RenderString(field_name, + EnumValueNameToLowerCamelCase(enum_value->name())); + } else { + ow->RenderString(field_name, enum_value->name()); + } + } else { + ow->RenderInt32(field_name, buffer32); + } + } else { + ow->RenderInt32(field_name, buffer32); + } + break; + } + case google::protobuf::Field::TYPE_STRING: { + stream_->ReadVarint32(&buffer32); // string size. + stream_->ReadString(&strbuffer, buffer32); + ow->RenderString(field_name, strbuffer); + break; + } + case google::protobuf::Field::TYPE_BYTES: { + stream_->ReadVarint32(&buffer32); // bytes size. + stream_->ReadString(&strbuffer, buffer32); + ow->RenderBytes(field_name, strbuffer); + break; + } + default: + break; + } + return util::Status(); +} + +// TODO(skarvaje): Fix this to avoid code duplication. +const std::string ProtoStreamObjectSource::ReadFieldValueAsString( + const google::protobuf::Field& field) const { + std::string result; + switch (field.kind()) { + case google::protobuf::Field::TYPE_BOOL: { + uint64_t buffer64; + stream_->ReadVarint64(&buffer64); + result = buffer64 != 0 ? "true" : "false"; + break; + } + case google::protobuf::Field::TYPE_INT32: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); + result = StrCat(bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_INT64: { + uint64_t buffer64; + stream_->ReadVarint64(&buffer64); + result = StrCat(bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_UINT32: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); + result = StrCat(bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_UINT64: { + uint64_t buffer64; + stream_->ReadVarint64(&buffer64); + result = StrCat(bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_SINT32: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); + result = StrCat(WireFormatLite::ZigZagDecode32(buffer32)); + break; + } + case google::protobuf::Field::TYPE_SINT64: { + uint64_t buffer64; + stream_->ReadVarint64(&buffer64); + result = StrCat(WireFormatLite::ZigZagDecode64(buffer64)); + break; + } + case google::protobuf::Field::TYPE_SFIXED32: { + uint32_t buffer32; + stream_->ReadLittleEndian32(&buffer32); + result = StrCat(bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_SFIXED64: { + uint64_t buffer64; + stream_->ReadLittleEndian64(&buffer64); + result = StrCat(bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_FIXED32: { + uint32_t buffer32; + stream_->ReadLittleEndian32(&buffer32); + result = StrCat(bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_FIXED64: { + uint64_t buffer64; + stream_->ReadLittleEndian64(&buffer64); + result = StrCat(bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_FLOAT: { + uint32_t buffer32; + stream_->ReadLittleEndian32(&buffer32); + result = SimpleFtoa(bit_cast(buffer32)); + break; + } + case google::protobuf::Field::TYPE_DOUBLE: { + uint64_t buffer64; + stream_->ReadLittleEndian64(&buffer64); + result = SimpleDtoa(bit_cast(buffer64)); + break; + } + case google::protobuf::Field::TYPE_ENUM: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); + // Get the nested enum type for this field. + // TODO(skarvaje): Avoid string manipulation. Find ways to speed this + // up. + const google::protobuf::Enum* en = + typeinfo_->GetEnumByTypeUrl(field.type_url()); + // Lookup the name of the enum, and render that. Skips unknown enums. + if (en != nullptr) { + const google::protobuf::EnumValue* enum_value = + FindEnumValueByNumber(*en, buffer32); + if (enum_value != nullptr) { + result = enum_value->name(); + } + } + break; + } + case google::protobuf::Field::TYPE_STRING: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); // string size. + stream_->ReadString(&result, buffer32); + break; + } + case google::protobuf::Field::TYPE_BYTES: { + uint32_t buffer32; + stream_->ReadVarint32(&buffer32); // bytes size. + stream_->ReadString(&result, buffer32); + break; + } + default: + break; + } + return result; +} + +// Field is a map if it is a repeated message and it has an option "map_type". +// TODO(skarvaje): Consider pre-computing the IsMap() into Field directly. +bool ProtoStreamObjectSource::IsMap( + const google::protobuf::Field& field) const { + const google::protobuf::Type* field_type = + typeinfo_->GetTypeByTypeUrl(field.type_url()); + return field.kind() == google::protobuf::Field::TYPE_MESSAGE && + util::converter::IsMap(field, *field_type); +} + +std::pair ProtoStreamObjectSource::ReadSecondsAndNanos( + const google::protobuf::Type& type) const { + uint64_t seconds = 0; + uint32_t nanos = 0; + uint32_t tag = 0; + int64_t signed_seconds = 0; + int32_t signed_nanos = 0; + + for (tag = stream_->ReadTag(); tag != 0; tag = stream_->ReadTag()) { + const google::protobuf::Field* field = FindAndVerifyField(type, tag); + if (field == nullptr) { + WireFormat::SkipField(stream_, tag, nullptr); + continue; + } + // 'seconds' has field number of 1 and 'nanos' has field number 2 + // //google/protobuf/timestamp.proto & duration.proto + if (field->number() == 1) { + // read seconds + stream_->ReadVarint64(&seconds); + signed_seconds = bit_cast(seconds); + } else if (field->number() == 2) { + // read nanos + stream_->ReadVarint32(&nanos); + signed_nanos = bit_cast(nanos); + } + } + return std::pair(signed_seconds, signed_nanos); +} + +util::Status ProtoStreamObjectSource::IncrementRecursionDepth( + StringPiece type_name, StringPiece field_name) const { + if (++recursion_depth_ > max_recursion_depth_) { + return util::InvalidArgumentError( + StrCat("Message too deep. Max recursion depth reached for type '", + type_name, "', field '", field_name, "'")); + } + return util::Status(); +} + +namespace { +// TODO(skarvaje): Speed this up by not doing a linear scan. +const google::protobuf::Field* FindFieldByNumber( + const google::protobuf::Type& type, int number) { + for (int i = 0; i < type.fields_size(); ++i) { + if (type.fields(i).number() == number) { + return &type.fields(i); + } + } + return nullptr; +} + +// TODO(skarvaje): Replace FieldDescriptor by implementing IsTypePackable() +// using tech Field. +bool IsPackable(const google::protobuf::Field& field) { + return field.cardinality() == google::protobuf::Field::CARDINALITY_REPEATED && + FieldDescriptor::IsTypePackable( + static_cast(field.kind())); +} + +// TODO(skarvaje): Speed this up by not doing a linear scan. +const google::protobuf::EnumValue* FindEnumValueByNumber( + const google::protobuf::Enum& tech_enum, int number) { + for (int i = 0; i < tech_enum.enumvalue_size(); ++i) { + const google::protobuf::EnumValue& ev = tech_enum.enumvalue(i); + if (ev.number() == number) { + return &ev; + } + } + return nullptr; +} + +// TODO(skarvaje): Look into optimizing this by not doing computation on +// double. +const std::string FormatNanos(uint32_t nanos, bool with_trailing_zeros) { + if (nanos == 0) { + return with_trailing_zeros ? ".000" : ""; + } + + const int precision = (nanos % 1000 != 0) ? 9 + : (nanos % 1000000 != 0) ? 6 + : 3; + std::string formatted = StringPrintf( + "%.*f", precision, static_cast(nanos) / kNanosPerSecond); + // remove the leading 0 before decimal. + return formatted.substr(1); +} +} // namespace + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h new file mode 100644 index 0000000..8ed2ca9 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h @@ -0,0 +1,329 @@ +// 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_UTIL_INTERNAL_PROTOSTREAM_OBJECTSOURCE_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTSOURCE_H__ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +class TypeInfo; + +// An ObjectSource that can parse a stream of bytes as a protocol buffer. +// Its WriteTo() method can be given an ObjectWriter. +// This implementation uses a google.protobuf.Type for tag and name lookup. +// The field names are converted into lower camel-case when writing to the +// ObjectWriter. +// +// Sample usage: (suppose input is: string proto) +// ArrayInputStream arr_stream(proto.data(), proto.size()); +// CodedInputStream in_stream(&arr_stream); +// ProtoStreamObjectSource os(&in_stream, /*ServiceTypeInfo*/ typeinfo, +// ); +// +// Status status = os.WriteTo(); +class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { + public: + + struct RenderOptions { + RenderOptions() = default; + RenderOptions(const RenderOptions&) = default; + + // Sets whether or not to use lowerCamelCase casing for enum values. If set + // to false, enum values are output without any case conversions. + // + // For example, if we have an enum: + // enum Type { + // ACTION_AND_ADVENTURE = 1; + // } + // Type type = 20; + // + // And this option is set to true. Then the rendered "type" field will have + // the string "actionAndAdventure". + // { + // ... + // "type": "actionAndAdventure", + // ... + // } + // + // If set to false, the rendered "type" field will have the string + // "ACTION_AND_ADVENTURE". + // { + // ... + // "type": "ACTION_AND_ADVENTURE", + // ... + // } + bool use_lower_camel_for_enums = false; + + // Sets whether to always output enums as ints, by default this is off, and + // enums are rendered as strings. + bool use_ints_for_enums = false; + + // Whether to preserve proto field names + bool preserve_proto_field_names = false; + + }; + + ProtoStreamObjectSource(io::CodedInputStream* stream, + TypeResolver* type_resolver, + const google::protobuf::Type& type) + : ProtoStreamObjectSource(stream, type_resolver, type, RenderOptions()) {} + ProtoStreamObjectSource(io::CodedInputStream* stream, + TypeResolver* type_resolver, + const google::protobuf::Type& type, + const RenderOptions& render_options); + + ~ProtoStreamObjectSource() override; + + util::Status NamedWriteTo(StringPiece name, + ObjectWriter* ow) const override; + + // Sets the max recursion depth of proto message to be deserialized. Proto + // messages over this depth will fail to be deserialized. + // Default value is 64. + void set_max_recursion_depth(int max_depth) { + max_recursion_depth_ = max_depth; + } + + protected: + // Writes a proto2 Message to the ObjectWriter. When the given end_tag is + // found this method will complete, allowing it to be used for parsing both + // nested messages (end with 0) and nested groups (end with group end tag). + // The include_start_and_end parameter allows this method to be called when + // already inside of an object, and skip calling StartObject and EndObject. + virtual util::Status WriteMessage(const google::protobuf::Type& type, + StringPiece name, + const uint32_t end_tag, + bool include_start_and_end, + ObjectWriter* ow) const; + + // Renders a repeating field (packed or unpacked). Returns the next tag after + // reading all sequential repeating elements. The caller should use this tag + // before reading more tags from the stream. + virtual util::StatusOr RenderList( + const google::protobuf::Field* field, StringPiece name, + uint32_t list_tag, ObjectWriter* ow) const; + + // Looks up a field and verify its consistency with wire type in tag. + const google::protobuf::Field* FindAndVerifyField( + const google::protobuf::Type& type, uint32_t tag) const; + + // Renders a field value to the ObjectWriter. + virtual util::Status RenderField(const google::protobuf::Field* field, + StringPiece field_name, + ObjectWriter* ow) const; + + // Reads field value according to Field spec in 'field' and returns the read + // value as string. This only works for primitive datatypes (no message + // types). + const std::string ReadFieldValueAsString( + const google::protobuf::Field& field) const; + + + // Returns the input stream. + io::CodedInputStream* stream() const { return stream_; } + + private: + ProtoStreamObjectSource(io::CodedInputStream* stream, + const TypeInfo* typeinfo, + const google::protobuf::Type& type, + const RenderOptions& render_options); + // Function that renders a well known type with a modified behavior. + typedef util::Status (*TypeRenderer)(const ProtoStreamObjectSource*, + const google::protobuf::Type&, + StringPiece, ObjectWriter*); + + // TODO(skarvaje): Mark these methods as non-const as they modify internal + // state (stream_). + // + // Renders a NWP map. + // Returns the next tag after reading all map entries. The caller should use + // this tag before reading more tags from the stream. + util::StatusOr RenderMap(const google::protobuf::Field* field, + StringPiece name, uint32_t list_tag, + ObjectWriter* ow) const; + + // Renders a packed repeating field. A packed field is stored as: + // {tag length item1 item2 item3} instead of the less efficient + // {tag item1 tag item2 tag item3}. + util::Status RenderPacked(const google::protobuf::Field* field, + ObjectWriter* ow) const; + + // Renders a google.protobuf.Timestamp value to ObjectWriter + static util::Status RenderTimestamp(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + // Renders a google.protobuf.Duration value to ObjectWriter + static util::Status RenderDuration(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + // Following RenderTYPE functions render well known types in + // google/protobuf/wrappers.proto corresponding to TYPE. + static util::Status RenderDouble(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderFloat(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderInt64(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderUInt64(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderInt32(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderUInt32(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderBool(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderString(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + static util::Status RenderBytes(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + // Renders a google.protobuf.Struct to ObjectWriter. + static util::Status RenderStruct(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + // Helper to render google.protobuf.Struct's Value fields to ObjectWriter. + static util::Status RenderStructValue(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, + ObjectWriter* ow); + + // Helper to render google.protobuf.Struct's ListValue fields to ObjectWriter. + static util::Status RenderStructListValue(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, + ObjectWriter* ow); + + // Render the "Any" type. + static util::Status RenderAny(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + // Render the "FieldMask" type. + static util::Status RenderFieldMask(const ProtoStreamObjectSource* os, + const google::protobuf::Type& type, + StringPiece name, ObjectWriter* ow); + + static std::unordered_map* renderers_; + static void InitRendererMap(); + static void DeleteRendererMap(); + static TypeRenderer* FindTypeRenderer(const std::string& type_url); + + // Same as above but renders all non-message field types. Callers don't call + // this function directly. They just use RenderField. + util::Status RenderNonMessageField(const google::protobuf::Field* field, + StringPiece field_name, + ObjectWriter* ow) const; + + + // Utility function to detect proto maps. The 'field' MUST be repeated. + bool IsMap(const google::protobuf::Field& field) const; + + // Utility to read int64 and int32 values from a message type in stream_. + // Used for reading google.protobuf.Timestamp and Duration messages. + std::pair ReadSecondsAndNanos( + const google::protobuf::Type& type) const; + + // Helper function to check recursion depth and increment it. It will return + // OkStatus() if the current depth is allowed. Otherwise an error is returned. + // type_name and field_name are used for error reporting. + util::Status IncrementRecursionDepth(StringPiece type_name, + StringPiece field_name) const; + + // Input stream to read from. Ownership rests with the caller. + mutable io::CodedInputStream* stream_; + + // Type information for all the types used in the descriptor. Used to find + // google::protobuf::Type of nested messages/enums. + const TypeInfo* typeinfo_; + + // Whether this class owns the typeinfo_ object. If true the typeinfo_ object + // should be deleted in the destructor. + bool own_typeinfo_; + + // google::protobuf::Type of the message source. + const google::protobuf::Type& type_; + + + const RenderOptions render_options_; + + // Tracks current recursion depth. + mutable int recursion_depth_; + + // Maximum allowed recursion depth. + int max_recursion_depth_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTSOURCE_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc new file mode 100644 index 0000000..e16db78 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -0,0 +1,1165 @@ +// 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using ::google::protobuf::Any; +using io::ArrayInputStream; +using io::CodedInputStream; +using proto_util_converter::testing::AnyM; +using proto_util_converter::testing::AnyOut; +using proto_util_converter::testing::Author; +using proto_util_converter::testing::BadAuthor; +using proto_util_converter::testing::BadNestedBook; +using proto_util_converter::testing::Book; +using proto_util_converter::testing::Book_Label; +using proto_util_converter::testing::Cyclic; +using proto_util_converter::testing::FieldMaskTest; +using proto_util_converter::testing::MapOut; +using proto_util_converter::testing::MapOutWireFormat; +using proto_util_converter::testing::NestedBook; +using proto_util_converter::testing::NestedFieldMask; +using proto_util_converter::testing::PackedPrimitive; +using proto_util_converter::testing::Primitive; +using proto_util_converter::testing::Proto3Message; +using proto_util_converter::testing::StructType; +using proto_util_converter::testing::TimestampDuration; +using ::testing::_; + + +namespace { +std::string GetTypeUrl(const Descriptor* descriptor) { + return std::string(kTypeServiceBaseUrl) + "/" + descriptor->full_name(); +} +} // namespace + +class ProtostreamObjectSourceTest + : public ::testing::TestWithParam { + protected: + ProtostreamObjectSourceTest() + : helper_(GetParam()), + mock_(), + ow_(&mock_), + use_lower_camel_for_enums_(false), + use_ints_for_enums_(false), + use_preserve_proto_field_names_(false), + add_trailing_zeros_(false), + render_unknown_enum_values_(true) { + helper_.ResetTypeInfo(Book::descriptor(), Proto3Message::descriptor()); + } + + ~ProtostreamObjectSourceTest() override {} + + void DoTest(const Message& msg, const Descriptor* descriptor) { + util::Status status = ExecuteTest(msg, descriptor); + EXPECT_EQ(util::Status(), status); + } + + util::Status ExecuteTest(const Message& msg, const Descriptor* descriptor) { + std::ostringstream oss; + msg.SerializePartialToOstream(&oss); + std::string proto = oss.str(); + ArrayInputStream arr_stream(proto.data(), proto.size()); + CodedInputStream in_stream(&arr_stream); + + ProtoStreamObjectSource::RenderOptions render_options; + render_options.use_lower_camel_for_enums = use_lower_camel_for_enums_; + render_options.use_ints_for_enums = use_ints_for_enums_; + render_options.preserve_proto_field_names = use_preserve_proto_field_names_; + std::unique_ptr os(helper_.NewProtoSource( + &in_stream, GetTypeUrl(descriptor), render_options)); + os->set_max_recursion_depth(64); + return os->WriteTo(&mock_); + } + + void PrepareExpectingObjectWriterForRepeatedPrimitive() { + ow_.StartObject("") + ->StartList("repFix32") + ->RenderUint32("", bit_cast(3201)) + ->RenderUint32("", bit_cast(0)) + ->RenderUint32("", bit_cast(3202)) + ->EndList() + ->StartList("repU32") + ->RenderUint32("", bit_cast(3203)) + ->RenderUint32("", bit_cast(0)) + ->EndList() + ->StartList("repI32") + ->RenderInt32("", 0) + ->RenderInt32("", 3204) + ->RenderInt32("", 3205) + ->EndList() + ->StartList("repSf32") + ->RenderInt32("", 3206) + ->RenderInt32("", 0) + ->EndList() + ->StartList("repS32") + ->RenderInt32("", 0) + ->RenderInt32("", 3207) + ->RenderInt32("", 3208) + ->EndList() + ->StartList("repFix64") + ->RenderUint64("", bit_cast(int64_t{6401})) + ->RenderUint64("", bit_cast(int64_t{0})) + ->EndList() + ->StartList("repU64") + ->RenderUint64("", bit_cast(int64_t{0})) + ->RenderUint64("", bit_cast(int64_t{6402})) + ->RenderUint64("", bit_cast(int64_t{6403})) + ->EndList() + ->StartList("repI64") + ->RenderInt64("", 6404L) + ->RenderInt64("", 0L) + ->EndList() + ->StartList("repSf64") + ->RenderInt64("", 0L) + ->RenderInt64("", 6405L) + ->RenderInt64("", 6406L) + ->EndList() + ->StartList("repS64") + ->RenderInt64("", 6407L) + ->RenderInt64("", 0L) + ->EndList() + ->StartList("repFloat") + ->RenderFloat("", 0.0f) + ->RenderFloat("", 32.1f) + ->RenderFloat("", 32.2f) + ->EndList() + ->StartList("repDouble") + ->RenderDouble("", 64.1L) + ->RenderDouble("", 0.0L) + ->EndList() + ->StartList("repBool") + ->RenderBool("", true) + ->RenderBool("", false) + ->EndList() + ->EndObject(); + } + + Primitive PrepareRepeatedPrimitive() { + Primitive primitive; + primitive.add_rep_fix32(3201); + primitive.add_rep_fix32(0); + primitive.add_rep_fix32(3202); + primitive.add_rep_u32(3203); + primitive.add_rep_u32(0); + primitive.add_rep_i32(0); + primitive.add_rep_i32(3204); + primitive.add_rep_i32(3205); + primitive.add_rep_sf32(3206); + primitive.add_rep_sf32(0); + primitive.add_rep_s32(0); + primitive.add_rep_s32(3207); + primitive.add_rep_s32(3208); + primitive.add_rep_fix64(6401L); + primitive.add_rep_fix64(0L); + primitive.add_rep_u64(0L); + primitive.add_rep_u64(6402L); + primitive.add_rep_u64(6403L); + primitive.add_rep_i64(6404L); + primitive.add_rep_i64(0L); + primitive.add_rep_sf64(0L); + primitive.add_rep_sf64(6405L); + primitive.add_rep_sf64(6406L); + primitive.add_rep_s64(6407L); + primitive.add_rep_s64(0L); + primitive.add_rep_float(0.0f); + primitive.add_rep_float(32.1f); + primitive.add_rep_float(32.2f); + primitive.add_rep_double(64.1L); + primitive.add_rep_double(0.0); + primitive.add_rep_bool(true); + primitive.add_rep_bool(false); + + PrepareExpectingObjectWriterForRepeatedPrimitive(); + return primitive; + } + + PackedPrimitive PreparePackedPrimitive() { + PackedPrimitive primitive; + primitive.add_rep_fix32(3201); + primitive.add_rep_fix32(0); + primitive.add_rep_fix32(3202); + primitive.add_rep_u32(3203); + primitive.add_rep_u32(0); + primitive.add_rep_i32(0); + primitive.add_rep_i32(3204); + primitive.add_rep_i32(3205); + primitive.add_rep_sf32(3206); + primitive.add_rep_sf32(0); + primitive.add_rep_s32(0); + primitive.add_rep_s32(3207); + primitive.add_rep_s32(3208); + primitive.add_rep_fix64(6401L); + primitive.add_rep_fix64(0L); + primitive.add_rep_u64(0L); + primitive.add_rep_u64(6402L); + primitive.add_rep_u64(6403L); + primitive.add_rep_i64(6404L); + primitive.add_rep_i64(0L); + primitive.add_rep_sf64(0L); + primitive.add_rep_sf64(6405L); + primitive.add_rep_sf64(6406L); + primitive.add_rep_s64(6407L); + primitive.add_rep_s64(0L); + primitive.add_rep_float(0.0f); + primitive.add_rep_float(32.1f); + primitive.add_rep_float(32.2f); + primitive.add_rep_double(64.1L); + primitive.add_rep_double(0.0); + primitive.add_rep_bool(true); + primitive.add_rep_bool(false); + + PrepareExpectingObjectWriterForRepeatedPrimitive(); + return primitive; + } + + void UseLowerCamelForEnums() { use_lower_camel_for_enums_ = true; } + + void UseIntsForEnums() { use_ints_for_enums_ = true; } + + void UsePreserveProtoFieldNames() { use_preserve_proto_field_names_ = true; } + + void AddTrailingZeros() { add_trailing_zeros_ = true; } + + void SetRenderUnknownEnumValues(bool value) { + render_unknown_enum_values_ = value; + } + + testing::TypeInfoTestHelper helper_; + + ::testing::NiceMock mock_; + ExpectingObjectWriter ow_; + bool use_lower_camel_for_enums_; + bool use_ints_for_enums_; + bool use_preserve_proto_field_names_; + bool add_trailing_zeros_; + bool render_unknown_enum_values_; +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtostreamObjectSourceTest, EmptyMessage) { + Book empty; + ow_.StartObject("")->EndObject(); + DoTest(empty, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, Primitives) { + Primitive primitive; + primitive.set_fix32(3201); + primitive.set_u32(3202); + primitive.set_i32(3203); + primitive.set_sf32(3204); + primitive.set_s32(3205); + primitive.set_fix64(6401L); + primitive.set_u64(6402L); + primitive.set_i64(6403L); + primitive.set_sf64(6404L); + primitive.set_s64(6405L); + primitive.set_str("String Value"); + primitive.set_bytes("Some Bytes"); + primitive.set_float_(32.1f); + primitive.set_double_(64.1L); + primitive.set_bool_(true); + + ow_.StartObject("") + ->RenderUint32("fix32", bit_cast(3201)) + ->RenderUint32("u32", bit_cast(3202)) + ->RenderInt32("i32", 3203) + ->RenderInt32("sf32", 3204) + ->RenderInt32("s32", 3205) + ->RenderUint64("fix64", bit_cast(int64_t{6401})) + ->RenderUint64("u64", bit_cast(int64_t{6402})) + ->RenderInt64("i64", 6403L) + ->RenderInt64("sf64", 6404L) + ->RenderInt64("s64", 6405L) + ->RenderString("str", "String Value") + ->RenderBytes("bytes", "Some Bytes") + ->RenderFloat("float", 32.1f) + ->RenderDouble("double", 64.1L) + ->RenderBool("bool", true) + ->EndObject(); + DoTest(primitive, Primitive::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, RepeatingPrimitives) { + Primitive primitive = PrepareRepeatedPrimitive(); + primitive.add_rep_str("String One"); + primitive.add_rep_str("String Two"); + primitive.add_rep_bytes("Some Bytes"); + + ow_.StartList("repStr") + ->RenderString("", "String One") + ->RenderString("", "String Two") + ->EndList() + ->StartList("repBytes") + ->RenderBytes("", "Some Bytes") + ->EndList(); + DoTest(primitive, Primitive::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, CustomJsonName) { + Author author; + author.set_id(12345); + + ow_.StartObject("")->RenderUint64("@id", 12345)->EndObject(); + DoTest(author, Author::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, NestedMessage) { + Author* author = new Author(); + author->set_name("Tolstoy"); + Book book; + book.set_title("My Book"); + book.set_allocated_author(author); + + ow_.StartObject("") + ->RenderString("title", "My Book") + ->StartObject("author") + ->RenderString("name", "Tolstoy") + ->EndObject() + ->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, RepeatingField) { + Author author; + author.set_alive(false); + author.set_name("john"); + author.add_pseudonym("phil"); + author.add_pseudonym("bob"); + + ow_.StartObject("") + ->RenderBool("alive", false) + ->RenderString("name", "john") + ->StartList("pseudonym") + ->RenderString("", "phil") + ->RenderString("", "bob") + ->EndList() + ->EndObject(); + DoTest(author, Author::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, PackedRepeatingFields) { + DoTest(PreparePackedPrimitive(), PackedPrimitive::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, NonPackedPackableFieldsActuallyPacked) { + // Protostream is packed, but parse with non-packed Primitive. + DoTest(PreparePackedPrimitive(), Primitive::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, PackedPackableFieldNotActuallyPacked) { + // Protostream is not packed, but parse with PackedPrimitive. + DoTest(PrepareRepeatedPrimitive(), PackedPrimitive::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, BadAuthor) { + Author author; + author.set_alive(false); + author.set_name("john"); + author.set_id(1234L); + author.add_pseudonym("phil"); + author.add_pseudonym("bob"); + + ow_.StartObject("") + ->StartList("alive") + ->RenderBool("", false) + ->EndList() + ->StartList("name") + ->RenderUint64("", static_cast('j')) + ->RenderUint64("", static_cast('o')) + ->RenderUint64("", static_cast('h')) + ->RenderUint64("", static_cast('n')) + ->EndList() + ->RenderString("pseudonym", "phil") + ->RenderString("pseudonym", "bob") + ->EndObject(); + // Protostream created with Author, but parsed with BadAuthor. + DoTest(author, BadAuthor::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, NestedBookToBadNestedBook) { + Book* book = new Book(); + book->set_length(250); + book->set_published(2014L); + NestedBook nested; + nested.set_allocated_book(book); + + ow_.StartObject("") + ->StartList("book") + ->RenderUint32("", 24) // tag for field length (3 << 3) + ->RenderUint32("", 250) + ->RenderUint32("", 32) // tag for field published (4 << 3) + ->RenderUint32("", 2014) + ->EndList() + ->EndObject(); + // Protostream created with NestedBook, but parsed with BadNestedBook. + DoTest(nested, BadNestedBook::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, BadNestedBookToNestedBook) { + BadNestedBook nested; + nested.add_book(1); + nested.add_book(2); + nested.add_book(3); + nested.add_book(4); + nested.add_book(5); + nested.add_book(6); + nested.add_book(7); + + ow_.StartObject("")->StartObject("book")->EndObject()->EndObject(); + // Protostream created with BadNestedBook, but parsed with NestedBook. + DoTest(nested, NestedBook::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, + LongRepeatedListDoesNotBreakIntoMultipleJsonLists) { + Book book; + + int repeat = 10000; + for (int i = 0; i < repeat; ++i) { + Book_Label* label = book.add_labels(); + label->set_key(StrCat("i", i)); + label->set_value(StrCat("v", i)); + } + + // Make sure StartList and EndList are called exactly once (see b/18227499 for + // problems when this doesn't happen) + EXPECT_CALL(mock_, StartList(_)).Times(1); + EXPECT_CALL(mock_, EndList()).Times(1); + + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, LowerCamelEnumOutputMacroCase) { + Book book; + book.set_type(Book::ACTION_AND_ADVENTURE); + + UseLowerCamelForEnums(); + + ow_.StartObject("")->RenderString("type", "actionAndAdventure")->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, LowerCamelEnumOutputSnakeCase) { + Book book; + book.set_type(Book::arts_and_photography); + + UseLowerCamelForEnums(); + + ow_.StartObject("")->RenderString("type", "artsAndPhotography")->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, LowerCamelEnumOutputWithNumber) { + Book book; + book.set_type(Book::I18N_Tech); + + UseLowerCamelForEnums(); + + ow_.StartObject("")->RenderString("type", "i18nTech")->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, EnumCaseIsUnchangedByDefault) { + Book book; + book.set_type(Book::ACTION_AND_ADVENTURE); + ow_.StartObject("") + ->RenderString("type", "ACTION_AND_ADVENTURE") + ->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) { + Book book; + book.set_type(Book::ACTION_AND_ADVENTURE); + + UseIntsForEnums(); + + ow_.StartObject("")->RenderInt32("type", 3)->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, UsePreserveProtoFieldNames) { + Book book; + book.set_snake_field("foo"); + + UsePreserveProtoFieldNames(); + + ow_.StartObject("")->RenderString("snake_field", "foo")->EndObject(); + DoTest(book, Book::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, + UnknownEnumAreDroppedWhenRenderUnknownEnumValuesIsUnset) { + Proto3Message message; + message.set_enum_value(static_cast(1234)); + + 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(1234)); + + SetRenderUnknownEnumValues(true); + + // Unknown enum values are output. + ow_.StartObject("")->RenderInt32("enumValue", 1234)->EndObject(); + DoTest(message, Proto3Message::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, CyclicMessageDepthTest) { + Cyclic cyclic; + cyclic.set_m_int(123); + + Book* book = cyclic.mutable_m_book(); + book->set_title("book title"); + Cyclic* current = cyclic.mutable_m_cyclic(); + Author* current_author = cyclic.add_m_author(); + for (int i = 0; i < 63; ++i) { + Author* next = current_author->add_friend_(); + next->set_id(i); + next->set_name(StrCat("author_name_", i)); + next->set_alive(true); + current_author = next; + } + + // Recursive message with depth (65) > max (max is 64). + for (int i = 0; i < 64; ++i) { + Cyclic* next = current->mutable_m_cyclic(); + next->set_m_str(StrCat("count_", i)); + current = next; + } + + util::Status status = ExecuteTest(cyclic, Cyclic::descriptor()); + EXPECT_TRUE(util::IsInvalidArgument(status)); +} + +class ProtostreamObjectSourceMapsTest : public ProtostreamObjectSourceTest { + protected: + ProtostreamObjectSourceMapsTest() { + helper_.ResetTypeInfo(MapOut::descriptor()); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceMapsTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +// Tests JSON map. +// +// This is the example expected output. +// { +// "map1": { +// "key1": { +// "foo": "foovalue" +// }, +// "key2": { +// "foo": "barvalue" +// } +// }, +// "map2": { +// "nestedself": { +// "map1": { +// "nested_key1": { +// "foo": "nested_foo" +// } +// }, +// "bar": "nested_bar_string" +// } +// }, +// "map3": { +// "111": "one one one" +// }, +// "bar": "top bar" +// } +TEST_P(ProtostreamObjectSourceMapsTest, MapsTest) { + MapOut out; + (*out.mutable_map1())["key1"].set_foo("foovalue"); + (*out.mutable_map1())["key2"].set_foo("barvalue"); + + MapOut* nested_value = &(*out.mutable_map2())["nestedself"]; + (*nested_value->mutable_map1())["nested_key1"].set_foo("nested_foo"); + nested_value->set_bar("nested_bar_string"); + + (*out.mutable_map3())[111] = "one one one"; + + out.set_bar("top bar"); + + ow_.StartObject("") + ->StartObject("map1") + ->StartObject("key1") + ->RenderString("foo", "foovalue") + ->EndObject() + ->StartObject("key2") + ->RenderString("foo", "barvalue") + ->EndObject() + ->StartObject("map2") + ->StartObject("nestedself") + ->StartObject("map1") + ->StartObject("nested_key1") + ->RenderString("foo", "nested_foo") + ->EndObject() + ->EndObject() + ->RenderString("bar", "nested_bar_string") + ->EndObject() + ->EndObject() + ->StartObject("map3") + ->RenderString("111", "one one one") + ->EndObject() + ->EndObject() + ->RenderString("bar", "top bar") + ->EndObject(); + + DoTest(out, MapOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceMapsTest, MissingKeysTest) { + // MapOutWireFormat has the same wire representation with MapOut but uses + // repeated message fields to represent map fields so we can intentionally + // leave out the key field or the value field of a map entry. + MapOutWireFormat out; + // Create some map entries without keys. They will be rendered with the + // default values ("" for strings, "0" for integers, etc.). + // { + // "map1": { + // "": { + // "foo": "foovalue" + // } + // }, + // "map2": { + // "": { + // "map1": { + // "nested_key1": { + // "foo": "nested_foo" + // } + // } + // } + // }, + // "map3": { + // "0": "one one one" + // }, + // "map4": { + // "false": "bool" + // } + // } + out.add_map1()->mutable_value()->set_foo("foovalue"); + MapOut* nested = out.add_map2()->mutable_value(); + (*nested->mutable_map1())["nested_key1"].set_foo("nested_foo"); + out.add_map3()->set_value("one one one"); + out.add_map4()->set_value("bool"); + + ow_.StartObject("") + ->StartObject("map1") + ->StartObject("") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject() + ->StartObject("map2") + ->StartObject("") + ->StartObject("map1") + ->StartObject("nested_key1") + ->RenderString("foo", "nested_foo") + ->EndObject() + ->EndObject() + ->EndObject() + ->EndObject() + ->StartObject("map3") + ->RenderString("0", "one one one") + ->EndObject() + ->StartObject("map4") + ->RenderString("false", "bool") + ->EndObject() + ->EndObject(); + + DoTest(out, MapOut::descriptor()); +} + +class ProtostreamObjectSourceAnysTest : public ProtostreamObjectSourceTest { + protected: + ProtostreamObjectSourceAnysTest() { + helper_.ResetTypeInfo({AnyOut::descriptor(), Book::descriptor(), + google::protobuf::Any::descriptor()}); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceAnysTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +// Tests JSON any support. +// +// This is the example expected output. +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.testing.AnyM" +// "foo": "foovalue" +// } +// } +TEST_P(ProtostreamObjectSourceAnysTest, BasicAny) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + AnyM m; + m.set_foo("foovalue"); + any->PackFrom(m); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.AnyM") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, LowerCamelEnumOutputSnakeCase) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + Book book; + book.set_type(Book::arts_and_photography); + any->PackFrom(book); + + UseLowerCamelForEnums(); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.Book") + ->RenderString("type", "artsAndPhotography") + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, UseIntsForEnumsTest) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + Book book; + book.set_type(Book::ACTION_AND_ADVENTURE); + any->PackFrom(book); + + UseIntsForEnums(); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.Book") + ->RenderInt32("type", 3) + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, UsePreserveProtoFieldNames) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + Book book; + book.set_snake_field("foo"); + any->PackFrom(book); + + UsePreserveProtoFieldNames(); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.Book") + ->RenderString("snake_field", "foo") + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, RecursiveAny) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any nested_any; + nested_any.set_type_url( + "type.googleapis.com/proto_util_converter.testing.AnyM"); + + AnyM m; + m.set_foo("foovalue"); + nested_any.set_value(m.SerializeAsString()); + + any->set_value(nested_any.SerializeAsString()); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.AnyM") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, DoubleRecursiveAny) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any nested_any; + nested_any.set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any second_nested_any; + second_nested_any.set_type_url( + "type.googleapis.com/proto_util_converter.testing.AnyM"); + + AnyM m; + m.set_foo("foovalue"); + second_nested_any.set_value(m.SerializeAsString()); + nested_any.set_value(second_nested_any.SerializeAsString()); + any->set_value(nested_any.SerializeAsString()); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.AnyM") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject() + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, EmptyAnyOutputsEmptyObject) { + AnyOut out; + out.mutable_any(); + + ow_.StartObject("")->StartObject("any")->EndObject()->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, EmptyWithTypeAndNoValueOutputsType) { + AnyOut out; + out.mutable_any()->set_type_url("foo.googleapis.com/my.Type"); + + ow_.StartObject("") + ->StartObject("any") + ->RenderString("@type", "foo.googleapis.com/my.Type") + ->EndObject() + ->EndObject(); + + DoTest(out, AnyOut::descriptor()); +} + +TEST_P(ProtostreamObjectSourceAnysTest, MissingTypeUrlError) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + AnyM m; + m.set_foo("foovalue"); + any->set_value(m.SerializeAsString()); + + // We start the "AnyOut" part and then fail when we hit the Any object. + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, AnyOut::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeServiceError) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("foo.googleapis.com/my.own.Type"); + + AnyM m; + m.set_foo("foovalue"); + any->set_value(m.SerializeAsString()); + + // We start the "AnyOut" part and then fail when we hit the Any object. + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, AnyOut::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceAnysTest, UnknownTypeError) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("type.googleapis.com/unknown.Type"); + + AnyM m; + m.set_foo("foovalue"); + any->set_value(m.SerializeAsString()); + + // We start the "AnyOut" part and then fail when we hit the Any object. + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, AnyOut::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +class ProtostreamObjectSourceStructTest : public ProtostreamObjectSourceTest { + protected: + ProtostreamObjectSourceStructTest() { + helper_.ResetTypeInfo(StructType::descriptor(), + google::protobuf::Struct::descriptor()); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceStructTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +// Tests struct +// +// "object": { +// "k1": 123, +// "k2": true +// } +TEST_P(ProtostreamObjectSourceStructTest, StructRenderSuccess) { + StructType out; + google::protobuf::Struct* s = out.mutable_object(); + s->mutable_fields()->operator[]("k1").set_number_value(123); + s->mutable_fields()->operator[]("k2").set_bool_value(true); + + ow_.StartObject("") + ->StartObject("object") + ->RenderDouble("k1", 123) + ->RenderBool("k2", true) + ->EndObject() + ->EndObject(); + + DoTest(out, StructType::descriptor()); +} + +TEST_P(ProtostreamObjectSourceStructTest, MissingValueSkipsField) { + StructType out; + google::protobuf::Struct* s = out.mutable_object(); + s->mutable_fields()->operator[]("k1"); + + ow_.StartObject("")->StartObject("object")->EndObject()->EndObject(); + + DoTest(out, StructType::descriptor()); +} + +class ProtostreamObjectSourceFieldMaskTest + : public ProtostreamObjectSourceTest { + protected: + ProtostreamObjectSourceFieldMaskTest() { + helper_.ResetTypeInfo(FieldMaskTest::descriptor(), + google::protobuf::FieldMask::descriptor()); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceFieldMaskTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtostreamObjectSourceFieldMaskTest, FieldMaskRenderSuccess) { + FieldMaskTest out; + out.set_id("1"); + out.mutable_single_mask()->add_paths("path1"); + out.mutable_single_mask()->add_paths("snake_case_path2"); + ::google::protobuf::FieldMask* mask = out.add_repeated_mask(); + mask->add_paths("path3"); + mask = out.add_repeated_mask(); + mask->add_paths("snake_case_path4"); + mask->add_paths("path5"); + NestedFieldMask* nested = out.add_nested_mask(); + nested->set_data("data"); + nested->mutable_single_mask()->add_paths("nested.path1"); + nested->mutable_single_mask()->add_paths("nested_field.snake_case_path2"); + mask = nested->add_repeated_mask(); + mask->add_paths("nested_field.path3"); + mask->add_paths("nested.snake_case_path4"); + mask = nested->add_repeated_mask(); + mask->add_paths("nested.path5"); + mask = nested->add_repeated_mask(); + mask->add_paths( + "snake_case.map_field[\"map_key_should_be_ignored\"].nested_snake_case." + "map_field[\"map_key_sho\\\"uld_be_ignored\"]"); + + ow_.StartObject("") + ->RenderString("id", "1") + ->RenderString("singleMask", "path1,snakeCasePath2") + ->StartList("repeatedMask") + ->RenderString("", "path3") + ->RenderString("", "snakeCasePath4,path5") + ->EndList() + ->StartList("nestedMask") + ->StartObject("") + ->RenderString("data", "data") + ->RenderString("singleMask", "nested.path1,nestedField.snakeCasePath2") + ->StartList("repeatedMask") + ->RenderString("", "nestedField.path3,nested.snakeCasePath4") + ->RenderString("", "nested.path5") + ->RenderString("", + "snakeCase.mapField[\"map_key_should_be_ignored\"]." + "nestedSnakeCase.mapField[\"map_key_sho\\\"uld_be_" + "ignored\"]") + ->EndList() + ->EndObject() + ->EndList() + ->EndObject(); + + DoTest(out, FieldMaskTest::descriptor()); +} + +class ProtostreamObjectSourceTimestampTest + : public ProtostreamObjectSourceTest { + protected: + ProtostreamObjectSourceTimestampTest() { + helper_.ResetTypeInfo(TimestampDuration::descriptor()); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtostreamObjectSourceTimestampTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampBelowMinTest) { + TimestampDuration out; + google::protobuf::Timestamp* ts = out.mutable_ts(); + // Min allowed seconds - 1 + ts->set_seconds(kTimestampMinSeconds - 1); + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceTimestampTest, InvalidTimestampAboveMaxTest) { + TimestampDuration out; + google::protobuf::Timestamp* ts = out.mutable_ts(); + // Max allowed seconds + 1 + ts->set_seconds(kTimestampMaxSeconds + 1); + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationBelowMinTest) { + TimestampDuration out; + google::protobuf::Duration* dur = out.mutable_dur(); + // Min allowed seconds - 1 + dur->set_seconds(kDurationMinSeconds - 1); + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) { + TimestampDuration out; + google::protobuf::Duration* dur = out.mutable_dur(); + // Min allowed seconds + 1 + dur->set_seconds(kDurationMaxSeconds + 1); + ow_.StartObject(""); + + util::Status status = ExecuteTest(out, TimestampDuration::descriptor()); + EXPECT_TRUE(util::IsInternal(status)); +} + +TEST_P(ProtostreamObjectSourceTimestampTest, TimestampDurationDefaultValue) { + TimestampDuration out; + out.mutable_ts()->set_seconds(0); + out.mutable_dur()->set_seconds(0); + + ow_.StartObject("") + ->RenderString("ts", "1970-01-01T00:00:00Z") + ->RenderString("dur", "0s") + ->EndObject(); + + DoTest(out, TimestampDuration::descriptor()); +} + + + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc new file mode 100644 index 0000000..ecb219e --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -0,0 +1,1401 @@ +// 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 + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +using util::Status; +using ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite; +using std::placeholders::_1; + + +ProtoStreamObjectWriter::ProtoStreamObjectWriter( + TypeResolver* type_resolver, const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener, + const ProtoStreamObjectWriter::Options& options) + : ProtoWriter(type_resolver, type, output, listener), + master_type_(type), + current_(nullptr), + options_(options) { + set_ignore_unknown_fields(options_.ignore_unknown_fields); + set_ignore_unknown_enum_values(options_.ignore_unknown_enum_values); + set_use_lower_camel_for_enums(options_.use_lower_camel_for_enums); + set_case_insensitive_enum_parsing(options_.case_insensitive_enum_parsing); + set_use_json_name_in_missing_fields(options.use_json_name_in_missing_fields); +} + +ProtoStreamObjectWriter::ProtoStreamObjectWriter( + const TypeInfo* typeinfo, const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener, + const ProtoStreamObjectWriter::Options& options) + : ProtoWriter(typeinfo, type, output, listener), + master_type_(type), + current_(nullptr), + options_(options) { + set_ignore_unknown_fields(options_.ignore_unknown_fields); + set_use_lower_camel_for_enums(options.use_lower_camel_for_enums); + set_case_insensitive_enum_parsing(options_.case_insensitive_enum_parsing); + set_use_json_name_in_missing_fields(options.use_json_name_in_missing_fields); +} + +ProtoStreamObjectWriter::ProtoStreamObjectWriter( + const TypeInfo* typeinfo, const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener) + : ProtoWriter(typeinfo, type, output, listener), + master_type_(type), + current_(nullptr), + options_(ProtoStreamObjectWriter::Options::Defaults()) {} + +ProtoStreamObjectWriter::~ProtoStreamObjectWriter() { + if (current_ == nullptr) return; + // Cleanup explicitly in order to avoid destructor stack overflow when input + // is deeply nested. + // Cast to BaseElement to avoid doing additional checks (like missing fields) + // during pop(). + std::unique_ptr element( + static_cast(current_.get())->pop()); + while (element != nullptr) { + element.reset(element->pop()); + } +} + +namespace { +// Utility method to split a string representation of Timestamp or Duration and +// return the parts. +void SplitSecondsAndNanos(StringPiece input, StringPiece* seconds, + StringPiece* nanos) { + size_t idx = input.rfind('.'); + if (idx != std::string::npos) { + *seconds = input.substr(0, idx); + *nanos = input.substr(idx + 1); + } else { + *seconds = input; + *nanos = StringPiece(); + } +} + +Status GetNanosFromStringPiece(StringPiece s_nanos, + const char* parse_failure_message, + const char* exceeded_limit_message, + int32_t* nanos) { + *nanos = 0; + + // Count the number of leading 0s and consume them. + int num_leading_zeros = 0; + while (s_nanos.Consume("0")) { + num_leading_zeros++; + } + int32_t i_nanos = 0; + // 's_nanos' contains fractional seconds -- i.e. 'nanos' is equal to + // "0." + s_nanos.ToString() seconds. An int32_t is used for the + // conversion to 'nanos', rather than a double, so that there is no + // loss of precision. + if (!s_nanos.empty() && !safe_strto32(s_nanos, &i_nanos)) { + return util::InvalidArgumentError(parse_failure_message); + } + if (i_nanos > kNanosPerSecond || i_nanos < 0) { + return util::InvalidArgumentError(exceeded_limit_message); + } + // s_nanos should only have digits. No whitespace. + if (s_nanos.find_first_not_of("0123456789") != StringPiece::npos) { + return util::InvalidArgumentError(parse_failure_message); + } + + if (i_nanos > 0) { + // 'scale' is the number of digits to the right of the decimal + // point in "0." + s_nanos.ToString() + int32_t scale = num_leading_zeros + s_nanos.size(); + // 'conversion' converts i_nanos into nanoseconds. + // conversion = kNanosPerSecond / static_cast(std::pow(10, scale)) + // For efficiency, we precompute the conversion factor. + int32_t conversion = 0; + switch (scale) { + case 1: + conversion = 100000000; + break; + case 2: + conversion = 10000000; + break; + case 3: + conversion = 1000000; + break; + case 4: + conversion = 100000; + break; + case 5: + conversion = 10000; + break; + case 6: + conversion = 1000; + break; + case 7: + conversion = 100; + break; + case 8: + conversion = 10; + break; + case 9: + conversion = 1; + break; + default: + return util::InvalidArgumentError(exceeded_limit_message); + } + *nanos = i_nanos * conversion; + } + + return Status(); +} + +} // namespace + +ProtoStreamObjectWriter::AnyWriter::AnyWriter(ProtoStreamObjectWriter* parent) + : parent_(parent), + ow_(), + invalid_(false), + data_(), + output_(&data_), + depth_(0), + is_well_known_type_(false), + well_known_type_render_(nullptr) {} + +ProtoStreamObjectWriter::AnyWriter::~AnyWriter() {} + +void ProtoStreamObjectWriter::AnyWriter::StartObject(StringPiece name) { + ++depth_; + // If an object writer is absent, that means we have not called StartAny() + // before reaching here, which happens when we have data before the "@type" + // field. + if (ow_ == nullptr) { + // Save data before the "@type" field for later replay. + uninterpreted_events_.push_back(Event(Event::START_OBJECT, name)); + } else if (is_well_known_type_ && depth_ == 1) { + // For well-known types, the only other field besides "@type" should be a + // "value" field. + if (name != "value" && !invalid_) { + parent_->InvalidValue("Any", + "Expect a \"value\" field for well-known types."); + invalid_ = true; + } + ow_->StartObject(""); + } else { + // Forward the call to the child writer if: + // 1. the type is not a well-known type. + // 2. or, we are in a nested Any, Struct, or Value object. + ow_->StartObject(name); + } +} + +bool ProtoStreamObjectWriter::AnyWriter::EndObject() { + --depth_; + if (ow_ == nullptr) { + if (depth_ >= 0) { + // Save data before the "@type" field for later replay. + uninterpreted_events_.push_back(Event(Event::END_OBJECT)); + } + } else if (depth_ >= 0 || !is_well_known_type_) { + // As long as depth_ >= 0, we know we haven't reached the end of Any. + // Propagate these EndObject() calls to the contained ow_. For regular + // message types, we propagate the end of Any as well. + ow_->EndObject(); + } + // A negative depth_ implies that we have reached the end of Any + // object. Now we write out its contents. + if (depth_ < 0) { + WriteAny(); + return false; + } + return true; +} + +void ProtoStreamObjectWriter::AnyWriter::StartList(StringPiece name) { + ++depth_; + if (ow_ == nullptr) { + // Save data before the "@type" field for later replay. + uninterpreted_events_.push_back(Event(Event::START_LIST, name)); + } else if (is_well_known_type_ && depth_ == 1) { + if (name != "value" && !invalid_) { + parent_->InvalidValue("Any", + "Expect a \"value\" field for well-known types."); + invalid_ = true; + } + ow_->StartList(""); + } else { + ow_->StartList(name); + } +} + +void ProtoStreamObjectWriter::AnyWriter::EndList() { + --depth_; + if (depth_ < 0) { + GOOGLE_LOG(DFATAL) << "Mismatched EndList found, should not be possible"; + depth_ = 0; + } + if (ow_ == nullptr) { + // Save data before the "@type" field for later replay. + uninterpreted_events_.push_back(Event(Event::END_LIST)); + } else { + ow_->EndList(); + } +} + +void ProtoStreamObjectWriter::AnyWriter::RenderDataPiece( + StringPiece name, const DataPiece& value) { + // Start an Any only at depth_ 0. Other RenderDataPiece calls with "@type" + // should go to the contained ow_ as they indicate nested Anys. + if (depth_ == 0 && ow_ == nullptr && name == "@type") { + StartAny(value); + } else if (ow_ == nullptr) { + // Save data before the "@type" field. + uninterpreted_events_.push_back(Event(name, value)); + } else if (depth_ == 0 && is_well_known_type_) { + if (name != "value" && !invalid_) { + parent_->InvalidValue("Any", + "Expect a \"value\" field for well-known types."); + invalid_ = true; + } + if (well_known_type_render_ == nullptr) { + // Only Any and Struct don't have a special type render but both of + // them expect a JSON object (i.e., a StartObject() call). + if (value.type() != DataPiece::TYPE_NULL && !invalid_) { + parent_->InvalidValue("Any", "Expect a JSON object."); + invalid_ = true; + } + } else { + ow_->ProtoWriter::StartObject(""); + Status status = (*well_known_type_render_)(ow_.get(), value); + if (!status.ok()) ow_->InvalidValue("Any", status.message()); + ow_->ProtoWriter::EndObject(); + } + } else { + ow_->RenderDataPiece(name, value); + } +} + +void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) { + // Figure out the type url. This is a copy-paste from WriteString but we also + // need the value, so we can't just call through to that. + if (value.type() == DataPiece::TYPE_STRING) { + type_url_ = std::string(value.str()); + } else { + util::StatusOr s = value.ToString(); + if (!s.ok()) { + parent_->InvalidValue("String", s.status().message()); + invalid_ = true; + return; + } + type_url_ = s.value(); + } + // Resolve the type url, and report an error if we failed to resolve it. + util::StatusOr resolved_type = + parent_->typeinfo()->ResolveTypeUrl(type_url_); + if (!resolved_type.ok()) { + parent_->InvalidValue("Any", resolved_type.status().message()); + invalid_ = true; + return; + } + // At this point, type is never null. + const google::protobuf::Type* type = resolved_type.value(); + + well_known_type_render_ = FindTypeRenderer(type_url_); + if (well_known_type_render_ != nullptr || + // Explicitly list Any and Struct here because they don't have a + // custom renderer. + type->name() == kAnyType || type->name() == kStructType) { + is_well_known_type_ = true; + } + + // Create our object writer and initialize it with the first StartObject + // call. + ow_.reset(new ProtoStreamObjectWriter(parent_->typeinfo(), *type, &output_, + parent_->listener(), + parent_->options_)); + + // Don't call StartObject() for well-known types yet. Depending on the + // type of actual data, we may not need to call StartObject(). For + // example: + // { + // "@type": "type.googleapis.com/google.protobuf.Value", + // "value": [1, 2, 3], + // } + // With the above JSON representation, we will only call StartList() on the + // contained ow_. + if (!is_well_known_type_) { + ow_->StartObject(""); + } + + // Now we know the proto type and can interpret all data fields we gathered + // before the "@type" field. + for (int i = 0; i < uninterpreted_events_.size(); ++i) { + uninterpreted_events_[i].Replay(this); + } +} + +void ProtoStreamObjectWriter::AnyWriter::WriteAny() { + if (ow_ == nullptr) { + if (uninterpreted_events_.empty()) { + // We never got any content, so just return immediately, which is + // equivalent to writing an empty Any. + return; + } else { + // There are uninterpreted data, but we never got a "@type" field. + if (!invalid_) { + parent_->InvalidValue("Any", + StrCat("Missing @type for any field in ", + parent_->master_type_.name())); + invalid_ = true; + } + return; + } + } + // Render the type_url and value fields directly to the stream. + // type_url has tag 1 and value has tag 2. + WireFormatLite::WriteString(1, type_url_, parent_->stream()); + if (!data_.empty()) { + WireFormatLite::WriteBytes(2, data_, parent_->stream()); + } +} + +void ProtoStreamObjectWriter::AnyWriter::Event::Replay( + AnyWriter* writer) const { + switch (type_) { + case START_OBJECT: + writer->StartObject(name_); + break; + case END_OBJECT: + writer->EndObject(); + break; + case START_LIST: + writer->StartList(name_); + break; + case END_LIST: + writer->EndList(); + break; + case RENDER_DATA_PIECE: + writer->RenderDataPiece(name_, value_); + break; + } +} + +void ProtoStreamObjectWriter::AnyWriter::Event::DeepCopy() { + // DataPiece only contains a string reference. To make sure the referenced + // string value stays valid, we make a copy of the string value and update + // DataPiece to reference our own copy. + if (value_.type() == DataPiece::TYPE_STRING) { + StrAppend(&value_storage_, value_.str()); + value_ = DataPiece(value_storage_, value_.use_strict_base64_decoding()); + } else if (value_.type() == DataPiece::TYPE_BYTES) { + value_storage_ = value_.ToBytes().value(); + value_ = + DataPiece(value_storage_, true, value_.use_strict_base64_decoding()); + } +} + +ProtoStreamObjectWriter::Item::Item(ProtoStreamObjectWriter* enclosing, + ItemType item_type, bool is_placeholder, + bool is_list) + : BaseElement(nullptr), + ow_(enclosing), + any_(), + item_type_(item_type), + is_placeholder_(is_placeholder), + is_list_(is_list) { + if (item_type_ == ANY) { + any_.reset(new AnyWriter(ow_)); + } + if (item_type == MAP) { + map_keys_.reset(new std::unordered_set); + } +} + +ProtoStreamObjectWriter::Item::Item(ProtoStreamObjectWriter::Item* parent, + ItemType item_type, bool is_placeholder, + bool is_list) + : BaseElement(parent), + ow_(this->parent()->ow_), + any_(), + item_type_(item_type), + is_placeholder_(is_placeholder), + is_list_(is_list) { + if (item_type == ANY) { + any_.reset(new AnyWriter(ow_)); + } + if (item_type == MAP) { + map_keys_.reset(new std::unordered_set); + } +} + +bool ProtoStreamObjectWriter::Item::InsertMapKeyIfNotPresent( + StringPiece map_key) { + return InsertIfNotPresent(map_keys_.get(), std::string(map_key)); +} + + +ProtoStreamObjectWriter* ProtoStreamObjectWriter::StartObject( + StringPiece name) { + if (invalid_depth() > 0) { + IncrementInvalidDepth(); + return this; + } + + // Starting the root message. Create the root Item and return. + // ANY message type does not need special handling, just set the ItemType + // to ANY. + if (current_ == nullptr) { + ProtoWriter::StartObject(name); + current_.reset(new Item( + this, master_type_.name() == kAnyType ? Item::ANY : Item::MESSAGE, + false, false)); + + // If master type is a special type that needs extra values to be written to + // stream, we write those values. + if (master_type_.name() == kStructType) { + // Struct has a map field called "fields". + // https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/struct.proto + // "fields": [ + Push("fields", Item::MAP, true, true); + return this; + } + + if (master_type_.name() == kStructValueType) { + // We got a StartObject call with google.protobuf.Value field. The only + // object within that type is a struct type. So start a struct. + // + // The struct field in Value type is named "struct_value" + // https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/struct.proto + // Also start the map field "fields" within the struct. + // "struct_value": { + // "fields": [ + Push("struct_value", Item::MESSAGE, true, false); + Push("fields", Item::MAP, true, true); + return this; + } + + if (master_type_.name() == kStructListValueType) { + InvalidValue(kStructListValueType, + "Cannot start root message with ListValue."); + } + + return this; + } + + // Send all ANY events to AnyWriter. + if (current_->IsAny()) { + current_->any()->StartObject(name); + return this; + } + + // If we are within a map, we render name as keys and send StartObject to the + // value field. + if (current_->IsMap()) { + if (!ValidMapKey(name)) { + IncrementInvalidDepth(); + return this; + } + + // Map is a repeated field of message type with a "key" and a "value" field. + // https://developers.google.com/protocol-buffers/docs/proto3?hl=en#maps + // message MapFieldEntry { + // key_type key = 1; + // value_type value = 2; + // } + // + // repeated MapFieldEntry map_field = N; + // + // That means, we render the following element within a list (hence no + // name): + // { "key": "", "value": { + Push("", Item::MESSAGE, false, false); + ProtoWriter::RenderDataPiece("key", + DataPiece(name, use_strict_base64_decoding())); + Push("value", IsAny(*Lookup("value")) ? Item::ANY : Item::MESSAGE, true, + false); + + // Make sure we are valid so far after starting map fields. + if (invalid_depth() > 0) return this; + + // If top of stack is g.p.Struct type, start the struct the map field within + // it. + if (element() != nullptr && IsStruct(*element()->parent_field())) { + // Render "fields": [ + Push("fields", Item::MAP, true, true); + return this; + } + + // If top of stack is g.p.Value type, start the Struct within it. + if (element() != nullptr && IsStructValue(*element()->parent_field())) { + // Render + // "struct_value": { + // "fields": [ + Push("struct_value", Item::MESSAGE, true, false); + Push("fields", Item::MAP, true, true); + } + return this; + } + + const google::protobuf::Field* field = BeginNamed(name, false); + + if (field == nullptr) return this; + + // Legacy JSON map is a list of key value pairs. Starts a map entry object. + if (options_.use_legacy_json_map_format && name.empty()) { + Push(name, IsAny(*field) ? Item::ANY : Item::MESSAGE, false, false); + return this; + } + + if (IsMap(*field)) { + // Begin a map. A map is triggered by a StartObject() call if the current + // field has a map type. + // A map type is always repeated, hence set is_list to true. + // Render + // "": [ + Push(name, Item::MAP, false, true); + return this; + } + + if (options_.disable_implicit_message_list) { + // If the incoming object is repeated, the top-level object on stack should + // be list. Report an error otherwise. + if (IsRepeated(*field) && !current_->is_list()) { + IncrementInvalidDepth(); + + if (!options_.suppress_implicit_message_list_error) { + InvalidValue( + field->name(), + "Starting an object in a repeated field but the parent object " + "is not a list"); + } + return this; + } + } + + if (IsStruct(*field)) { + // Start a struct object. + // Render + // "": { + // "fields": { + Push(name, Item::MESSAGE, false, false); + Push("fields", Item::MAP, true, true); + return this; + } + + if (IsStructValue(*field)) { + // We got a StartObject call with google.protobuf.Value field. The only + // object within that type is a struct type. So start a struct. + // Render + // "": { + // "struct_value": { + // "fields": { + Push(name, Item::MESSAGE, false, false); + Push("struct_value", Item::MESSAGE, true, false); + Push("fields", Item::MAP, true, true); + return this; + } + + if (field->kind() != google::protobuf::Field::TYPE_GROUP && + field->kind() != google::protobuf::Field::TYPE_MESSAGE) { + IncrementInvalidDepth(); + if (!options_.suppress_object_to_scalar_error) { + InvalidValue(field->name(), "Starting an object on a scalar field"); + } + + return this; + } + + // A regular message type. Pass it directly to ProtoWriter. + // Render + // "": { + Push(name, IsAny(*field) ? Item::ANY : Item::MESSAGE, false, false); + return this; +} + +ProtoStreamObjectWriter* ProtoStreamObjectWriter::EndObject() { + if (invalid_depth() > 0) { + DecrementInvalidDepth(); + return this; + } + + if (current_ == nullptr) return this; + + if (current_->IsAny()) { + if (current_->any()->EndObject()) return this; + } + + Pop(); + + return this; +} + + +ProtoStreamObjectWriter* ProtoStreamObjectWriter::StartList( + StringPiece name) { + if (invalid_depth() > 0) { + IncrementInvalidDepth(); + return this; + } + + // Since we cannot have a top-level repeated item in protobuf, the only way + // this is valid is if we start a special type google.protobuf.ListValue or + // google.protobuf.Value. + if (current_ == nullptr) { + if (!name.empty()) { + InvalidName(name, "Root element should not be named."); + IncrementInvalidDepth(); + return this; + } + + // If master type is a special type that needs extra values to be written to + // stream, we write those values. + if (master_type_.name() == kStructValueType) { + // We got a StartList with google.protobuf.Value master type. This means + // we have to start the "list_value" within google.protobuf.Value. + // + // See + // https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/struct.proto + // + // Render + // "": { + // "list_value": { + // "values": [ // Start this list. + ProtoWriter::StartObject(name); + current_.reset(new Item(this, Item::MESSAGE, false, false)); + Push("list_value", Item::MESSAGE, true, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + + if (master_type_.name() == kStructListValueType) { + // We got a StartList with google.protobuf.ListValue master type. This + // means we have to start the "values" within google.protobuf.ListValue. + // + // Render + // "": { + // "values": [ // Start this list. + ProtoWriter::StartObject(name); + current_.reset(new Item(this, Item::MESSAGE, false, false)); + Push("values", Item::MESSAGE, true, true); + return this; + } + + // Send the event to ProtoWriter so proper errors can be reported. + // + // Render a regular list: + // "": [ + ProtoWriter::StartList(name); + current_.reset(new Item(this, Item::MESSAGE, false, true)); + return this; + } + + if (current_->IsAny()) { + current_->any()->StartList(name); + return this; + } + + // If the top of stack is a map, we are starting a list value within a map. + // Since map does not allow repeated values, this can only happen when the map + // value is of a special type that renders a list in JSON. These can be one + // of 3 cases: + // i. We are rendering a list value within google.protobuf.Struct + // ii. We are rendering a list value within google.protobuf.Value + // iii. We are rendering a list value with type google.protobuf.ListValue. + if (current_->IsMap()) { + if (!ValidMapKey(name)) { + IncrementInvalidDepth(); + return this; + } + + // Start the repeated map entry object. + // Render + // { "key": "", "value": { + Push("", Item::MESSAGE, false, false); + ProtoWriter::RenderDataPiece("key", + DataPiece(name, use_strict_base64_decoding())); + Push("value", Item::MESSAGE, true, false); + + // Make sure we are valid after pushing all above items. + if (invalid_depth() > 0) return this; + + // case i and ii above. Start "list_value" field within g.p.Value + if (element() != nullptr && element()->parent_field() != nullptr) { + // Render + // "list_value": { + // "values": [ // Start this list + if (IsStructValue(*element()->parent_field())) { + Push("list_value", Item::MESSAGE, true, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + + // Render + // "values": [ + if (IsStructListValue(*element()->parent_field())) { + // case iii above. Bind directly to g.p.ListValue + Push("values", Item::MESSAGE, true, true); + return this; + } + } + + // Report an error. + InvalidValue("Map", StrCat("Cannot have repeated items ('", name, + "') within a map.")); + return this; + } + + // When name is empty and stack is not empty, we are rendering an item within + // a list. + if (name.empty()) { + if (element() != nullptr && element()->parent_field() != nullptr) { + if (IsStructValue(*element()->parent_field())) { + // Since it is g.p.Value, we bind directly to the list_value. + // Render + // { // g.p.Value item within the list + // "list_value": { + // "values": [ + Push("", Item::MESSAGE, false, false); + Push("list_value", Item::MESSAGE, true, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + + if (IsStructListValue(*element()->parent_field())) { + // Since it is g.p.ListValue, we bind to it directly. + // Render + // { // g.p.ListValue item within the list + // "values": [ + Push("", Item::MESSAGE, false, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + } + + // Pass the event to underlying ProtoWriter. + Push(name, Item::MESSAGE, false, true); + return this; + } + + // name is not empty + const google::protobuf::Field* field = Lookup(name); + + if (field == nullptr) { + IncrementInvalidDepth(); + return this; + } + + if (IsStructValue(*field)) { + // If g.p.Value is repeated, start that list. Otherwise, start the + // "list_value" within it. + if (IsRepeated(*field)) { + // Render it just like a regular repeated field. + // "": [ + Push(name, Item::MESSAGE, false, true); + return this; + } + + // Start the "list_value" field. + // Render + // "": { + // "list_value": { + // "values": [ + Push(name, Item::MESSAGE, false, false); + Push("list_value", Item::MESSAGE, true, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + + if (IsStructListValue(*field)) { + // If g.p.ListValue is repeated, start that list. Otherwise, start the + // "values" within it. + if (IsRepeated(*field)) { + // Render it just like a regular repeated field. + // "": [ + Push(name, Item::MESSAGE, false, true); + return this; + } + + // Start the "values" field within g.p.ListValue. + // Render + // "": { + // "values": [ + Push(name, Item::MESSAGE, false, false); + Push("values", Item::MESSAGE, true, true); + return this; + } + + // If we are here, the field should be repeated. Report an error otherwise. + if (!IsRepeated(*field)) { + IncrementInvalidDepth(); + InvalidName(name, "Proto field is not repeating, cannot start list."); + return this; + } + + if (IsMap(*field)) { + if (options_.use_legacy_json_map_format) { + Push(name, Item::MESSAGE, false, true); + return this; + } + InvalidValue("Map", StrCat("Cannot bind a list to map for field '", + name, "'.")); + IncrementInvalidDepth(); + return this; + } + + // Pass the event to ProtoWriter. + // Render + // "": [ + Push(name, Item::MESSAGE, false, true); + return this; +} + +ProtoStreamObjectWriter* ProtoStreamObjectWriter::EndList() { + if (invalid_depth() > 0) { + DecrementInvalidDepth(); + return this; + } + + if (current_ == nullptr) return this; + + if (current_->IsAny()) { + current_->any()->EndList(); + return this; + } + + Pop(); + return this; +} + +Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow, + const DataPiece& data) { + std::string struct_field_name; + switch (data.type()) { + case DataPiece::TYPE_INT32: { + if (ow->options_.struct_integers_as_strings) { + util::StatusOr int_value = data.ToInt32(); + if (int_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", + DataPiece(SimpleDtoa(int_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_UINT32: { + if (ow->options_.struct_integers_as_strings) { + util::StatusOr int_value = data.ToUint32(); + if (int_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", + DataPiece(SimpleDtoa(int_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_INT64: { + // If the option to treat integers as strings is set, then render them as + // strings. Otherwise, fallback to rendering them as double. + if (ow->options_.struct_integers_as_strings) { + util::StatusOr int_value = data.ToInt64(); + if (int_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", DataPiece(StrCat(int_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_UINT64: { + // If the option to treat integers as strings is set, then render them as + // strings. Otherwise, fallback to rendering them as double. + if (ow->options_.struct_integers_as_strings) { + util::StatusOr int_value = data.ToUint64(); + if (int_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", DataPiece(StrCat(int_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_FLOAT: { + if (ow->options_.struct_integers_as_strings) { + util::StatusOr float_value = data.ToFloat(); + if (float_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", + DataPiece(SimpleDtoa(float_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_DOUBLE: { + if (ow->options_.struct_integers_as_strings) { + util::StatusOr double_value = data.ToDouble(); + if (double_value.ok()) { + ow->ProtoWriter::RenderDataPiece( + "string_value", + DataPiece(SimpleDtoa(double_value.value()), true)); + return Status(); + } + } + struct_field_name = "number_value"; + break; + } + case DataPiece::TYPE_STRING: { + struct_field_name = "string_value"; + break; + } + case DataPiece::TYPE_BOOL: { + struct_field_name = "bool_value"; + break; + } + case DataPiece::TYPE_NULL: { + struct_field_name = "null_value"; + break; + } + default: { + return util::InvalidArgumentError( + "Invalid struct data type. Only number, string, boolean or null " + "values are supported."); + } + } + ow->ProtoWriter::RenderDataPiece(struct_field_name, data); + return Status(); +} + +Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow, + const DataPiece& data) { + if (data.type() == DataPiece::TYPE_NULL) return Status(); + if (data.type() != DataPiece::TYPE_STRING) { + return util::InvalidArgumentError( + StrCat("Invalid data type for timestamp, value is ", + data.ValueAsStringOrDefault(""))); + } + + StringPiece value(data.str()); + + int64_t seconds; + int32_t nanos; + if (!::google::protobuf::internal::ParseTime(value.ToString(), &seconds, + &nanos)) { + return util::InvalidArgumentError(StrCat("Invalid time format: ", value)); + } + + + ow->ProtoWriter::RenderDataPiece("seconds", DataPiece(seconds)); + ow->ProtoWriter::RenderDataPiece("nanos", DataPiece(nanos)); + return Status(); +} + +static inline util::Status RenderOneFieldPath(ProtoStreamObjectWriter* ow, + StringPiece path) { + ow->ProtoWriter::RenderDataPiece( + "paths", DataPiece(ConvertFieldMaskPath(path, &ToSnakeCase), true)); + return Status(); +} + +Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow, + const DataPiece& data) { + if (data.type() == DataPiece::TYPE_NULL) return Status(); + if (data.type() != DataPiece::TYPE_STRING) { + return util::InvalidArgumentError( + StrCat("Invalid data type for field mask, value is ", + data.ValueAsStringOrDefault(""))); + } + + // TODO(tsun): figure out how to do proto descriptor based snake case + // conversions as much as possible. Because ToSnakeCase sometimes returns the + // wrong value. + return DecodeCompactFieldMaskPaths(data.str(), + std::bind(&RenderOneFieldPath, ow, _1)); +} + +Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow, + const DataPiece& data) { + if (data.type() == DataPiece::TYPE_NULL) return Status(); + if (data.type() != DataPiece::TYPE_STRING) { + return util::InvalidArgumentError( + StrCat("Invalid data type for duration, value is ", + data.ValueAsStringOrDefault(""))); + } + + StringPiece value(data.str()); + + if (!HasSuffixString(value, "s")) { + return util::InvalidArgumentError( + "Illegal duration format; duration must end with 's'"); + } + value = value.substr(0, value.size() - 1); + int sign = 1; + if (HasPrefixString(value, "-")) { + sign = -1; + value = value.substr(1); + } + + StringPiece s_secs, s_nanos; + SplitSecondsAndNanos(value, &s_secs, &s_nanos); + uint64_t unsigned_seconds; + if (!safe_strtou64(s_secs, &unsigned_seconds)) { + return util::InvalidArgumentError( + "Invalid duration format, failed to parse seconds"); + } + + int32_t nanos = 0; + Status nanos_status = GetNanosFromStringPiece( + s_nanos, "Invalid duration format, failed to parse nano seconds", + "Duration value exceeds limits", &nanos); + if (!nanos_status.ok()) { + return nanos_status; + } + nanos = sign * nanos; + + int64_t seconds = sign * unsigned_seconds; + if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds || + nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { + return util::InvalidArgumentError("Duration value exceeds limits"); + } + + ow->ProtoWriter::RenderDataPiece("seconds", DataPiece(seconds)); + ow->ProtoWriter::RenderDataPiece("nanos", DataPiece(nanos)); + return Status(); +} + +Status ProtoStreamObjectWriter::RenderWrapperType(ProtoStreamObjectWriter* ow, + const DataPiece& data) { + if (data.type() == DataPiece::TYPE_NULL) return Status(); + ow->ProtoWriter::RenderDataPiece("value", data); + return Status(); +} + +ProtoStreamObjectWriter* ProtoStreamObjectWriter::RenderDataPiece( + StringPiece name, const DataPiece& data) { + Status status; + if (invalid_depth() > 0) return this; + + if (current_ == nullptr) { + const TypeRenderer* type_renderer = + FindTypeRenderer(GetFullTypeWithUrl(master_type_.name())); + if (type_renderer == nullptr) { + InvalidName(name, "Root element must be a message."); + return this; + } + // Render the special type. + // "": { + // ... Render special type ... + // } + ProtoWriter::StartObject(name); + status = (*type_renderer)(this, data); + if (!status.ok()) { + InvalidValue(master_type_.name(), + StrCat("Field '", name, "', ", status.message())); + } + ProtoWriter::EndObject(); + return this; + } + + if (current_->IsAny()) { + current_->any()->RenderDataPiece(name, data); + return this; + } + + const google::protobuf::Field* field = nullptr; + if (current_->IsMap()) { + if (!ValidMapKey(name)) return this; + + field = Lookup("value"); + if (field == nullptr) { + GOOGLE_LOG(DFATAL) << "Map does not have a value field."; + return this; + } + + if (options_.ignore_null_value_map_entry) { + // If we are rendering explicit null values and the backend proto field is + // not of the google.protobuf.NullType type, interpret null as absence. + if (data.type() == DataPiece::TYPE_NULL && + field->type_url() != kStructNullValueTypeUrl) { + return this; + } + } + + // Render an item in repeated map list. + // { "key": "", "value": + Push("", Item::MESSAGE, false, false); + ProtoWriter::RenderDataPiece("key", + DataPiece(name, use_strict_base64_decoding())); + + const TypeRenderer* type_renderer = FindTypeRenderer(field->type_url()); + if (type_renderer != nullptr) { + // Map's value type is a special type. Render it like a message: + // "value": { + // ... Render special type ... + // } + Push("value", Item::MESSAGE, true, false); + status = (*type_renderer)(this, data); + if (!status.ok()) { + InvalidValue(field->type_url(), + StrCat("Field '", name, "', ", status.message())); + } + Pop(); + return this; + } + + // If we are rendering explicit null values and the backend proto field is + // not of the google.protobuf.NullType type, we do nothing. + if (data.type() == DataPiece::TYPE_NULL && + field->type_url() != kStructNullValueTypeUrl) { + Pop(); + return this; + } + + // Render the map value as a primitive type. + ProtoWriter::RenderDataPiece("value", data); + Pop(); + return this; + } + + field = Lookup(name); + if (field == nullptr) return this; + + // Check if the field is of special type. Render it accordingly if so. + const TypeRenderer* type_renderer = FindTypeRenderer(field->type_url()); + if (type_renderer != nullptr) { + // Pass through null value only for google.protobuf.Value. For other + // types we ignore null value just like for regular field types. + if (data.type() != DataPiece::TYPE_NULL || + field->type_url() == kStructValueTypeUrl) { + Push(name, Item::MESSAGE, false, false); + status = (*type_renderer)(this, data); + if (!status.ok()) { + InvalidValue(field->type_url(), + StrCat("Field '", name, "', ", status.message())); + } + Pop(); + } + return this; + } + + // If we are rendering explicit null values and the backend proto field is + // not of the google.protobuf.NullType type, we do nothing. + if (data.type() == DataPiece::TYPE_NULL && + field->type_url() != kStructNullValueTypeUrl) { + return this; + } + + if (IsRepeated(*field) && !current_->is_list()) { + if (options_.disable_implicit_scalar_list) { + if (!options_.suppress_implicit_scalar_list_error) { + InvalidValue( + field->name(), + "Starting an primitive in a repeated field but the parent field " + "is not a list"); + } + + return this; + } + } + + ProtoWriter::RenderDataPiece(name, data); + return this; +} + +// Map of functions that are responsible for rendering well known type +// represented by the key. +std::unordered_map* + ProtoStreamObjectWriter::renderers_ = nullptr; +PROTOBUF_NAMESPACE_ID::internal::once_flag writer_renderers_init_; + +void ProtoStreamObjectWriter::InitRendererMap() { + renderers_ = new std::unordered_map(); + (*renderers_)["type.googleapis.com/google.protobuf.Timestamp"] = + &ProtoStreamObjectWriter::RenderTimestamp; + (*renderers_)["type.googleapis.com/google.protobuf.Duration"] = + &ProtoStreamObjectWriter::RenderDuration; + (*renderers_)["type.googleapis.com/google.protobuf.FieldMask"] = + &ProtoStreamObjectWriter::RenderFieldMask; + (*renderers_)["type.googleapis.com/google.protobuf.Double"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Float"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Int64"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.UInt64"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Int32"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.UInt32"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Bool"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.String"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Bytes"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.DoubleValue"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.FloatValue"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Int64Value"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.UInt64Value"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Int32Value"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.UInt32Value"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.BoolValue"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.StringValue"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.BytesValue"] = + &ProtoStreamObjectWriter::RenderWrapperType; + (*renderers_)["type.googleapis.com/google.protobuf.Value"] = + &ProtoStreamObjectWriter::RenderStructValue; + ::google::protobuf::internal::OnShutdown(&DeleteRendererMap); +} + +void ProtoStreamObjectWriter::DeleteRendererMap() { + delete ProtoStreamObjectWriter::renderers_; + renderers_ = nullptr; +} + +ProtoStreamObjectWriter::TypeRenderer* +ProtoStreamObjectWriter::FindTypeRenderer(const std::string& type_url) { + PROTOBUF_NAMESPACE_ID::internal::call_once(writer_renderers_init_, + InitRendererMap); + return FindOrNull(*renderers_, type_url); +} + +bool ProtoStreamObjectWriter::ValidMapKey(StringPiece unnormalized_name) { + if (current_ == nullptr) return true; + + if (!current_->InsertMapKeyIfNotPresent(unnormalized_name)) { + listener()->InvalidName( + location(), unnormalized_name, + StrCat("Repeated map key: '", unnormalized_name, + "' is already set.")); + return false; + } + + return true; +} + +void ProtoStreamObjectWriter::Push( + StringPiece name, Item::ItemType item_type, bool is_placeholder, + bool is_list) { + is_list ? ProtoWriter::StartList(name) : ProtoWriter::StartObject(name); + + // invalid_depth == 0 means it is a successful StartObject or StartList. + if (invalid_depth() == 0) + current_.reset( + new Item(current_.release(), item_type, is_placeholder, is_list)); +} + +void ProtoStreamObjectWriter::Pop() { + // Pop all placeholder items sending StartObject or StartList events to + // ProtoWriter according to is_list value. + while (current_ != nullptr && current_->is_placeholder()) { + PopOneElement(); + } + if (current_ != nullptr) { + PopOneElement(); + } +} + +void ProtoStreamObjectWriter::PopOneElement() { + current_->is_list() ? ProtoWriter::EndList() : ProtoWriter::EndObject(); + current_.reset(current_->pop()); +} + +bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) { + if (field.type_url().empty() || + field.kind() != google::protobuf::Field::TYPE_MESSAGE || + field.cardinality() != google::protobuf::Field::CARDINALITY_REPEATED) { + return false; + } + const google::protobuf::Type* field_type = + typeinfo()->GetTypeByTypeUrl(field.type_url()); + + return converter::IsMap(field, *field_type); +} + +bool ProtoStreamObjectWriter::IsAny(const google::protobuf::Field& field) { + return GetTypeWithoutUrl(field.type_url()) == kAnyType; +} + +bool ProtoStreamObjectWriter::IsStruct(const google::protobuf::Field& field) { + return GetTypeWithoutUrl(field.type_url()) == kStructType; +} + +bool ProtoStreamObjectWriter::IsStructValue( + const google::protobuf::Field& field) { + return GetTypeWithoutUrl(field.type_url()) == kStructValueType; +} + +bool ProtoStreamObjectWriter::IsStructListValue( + const google::protobuf::Field& field) { + return GetTypeWithoutUrl(field.type_url()) == kStructListValueType; +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h new file mode 100644 index 0000000..ce2517f --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h @@ -0,0 +1,453 @@ +// 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_UTIL_INTERNAL_PROTOSTREAM_OBJECTWRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTWRITER_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +class ObjectLocationTracker; + +// An ObjectWriter that can write protobuf bytes directly from writer events. +// This class supports all special types like Struct and Map. It uses +// the ProtoWriter class to write raw proto bytes. +// +// It also supports streaming. +class PROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter { + public: + // Options that control ProtoStreamObjectWriter class's behavior. + struct Options { + // Treats numeric inputs in google.protobuf.Struct as strings. Normally, + // numeric values are returned in double field "number_value" of + // google.protobuf.Struct. However, this can cause precision loss for + // int64/uint64/double inputs. This option is provided for cases that want + // to preserve number precision. + // + // TODO(skarvaje): Rename to struct_numbers_as_strings as it covers double + // as well. + bool struct_integers_as_strings; + + // Not treat unknown fields as an error. If there is an unknown fields, + // just ignore it and continue to process the rest. Note that this doesn't + // apply to unknown enum values. + bool ignore_unknown_fields; + + // Ignore unknown enum values. + bool ignore_unknown_enum_values; + + // If true, check if enum name in camel case or without underscore matches + // the field name. + bool use_lower_camel_for_enums; + + // If true, check if enum name in UPPER_CASE matches the field name. + bool case_insensitive_enum_parsing; + + // If true, skips rendering the map entry if map value is null unless the + // value type is google.protobuf.NullType. + bool ignore_null_value_map_entry; + + // If true, accepts repeated key/value pair for a map proto field. + bool use_legacy_json_map_format; + + // If true, disable implicitly creating message list. + bool disable_implicit_message_list; + + // If true, suppress the error of implicitly creating message list when it + // is disabled. + bool suppress_implicit_message_list_error; + + // If true, disable implicitly creating scalar list. + bool disable_implicit_scalar_list; + + // If true, suppress the error of implicitly creating scalar list when it + // is disabled. + bool suppress_implicit_scalar_list_error; + + // If true, suppress the error of rendering scalar field if the source is an + // object. + bool suppress_object_to_scalar_error; + + // If true, use the json name in missing fields errors. + bool use_json_name_in_missing_fields; + + Options() + : struct_integers_as_strings(false), + ignore_unknown_fields(false), + ignore_unknown_enum_values(false), + use_lower_camel_for_enums(false), + case_insensitive_enum_parsing(false), + ignore_null_value_map_entry(false), + use_legacy_json_map_format(false), + disable_implicit_message_list(false), + suppress_implicit_message_list_error(false), + disable_implicit_scalar_list(false), + suppress_implicit_scalar_list_error(false), + suppress_object_to_scalar_error(false), + use_json_name_in_missing_fields(false) {} + + // Default instance of Options with all options set to defaults. + static const Options& Defaults() { + static Options defaults; + return defaults; + } + }; + + // Constructor. Does not take ownership of any parameter passed in. + ProtoStreamObjectWriter(TypeResolver* type_resolver, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener, + const ProtoStreamObjectWriter::Options& options = + ProtoStreamObjectWriter::Options::Defaults()); + ~ProtoStreamObjectWriter() override; + + // ObjectWriter methods. + ProtoStreamObjectWriter* StartObject(StringPiece name) override; + ProtoStreamObjectWriter* EndObject() override; + ProtoStreamObjectWriter* StartList(StringPiece name) override; + ProtoStreamObjectWriter* EndList() override; + + // Renders a DataPiece 'value' into a field whose wire type is determined + // from the given field 'name'. + ProtoStreamObjectWriter* RenderDataPiece(StringPiece name, + const DataPiece& data) override; + + protected: + // Function that renders a well known type with modified behavior. + typedef util::Status (*TypeRenderer)(ProtoStreamObjectWriter*, + const DataPiece&); + + // Handles writing Anys out using nested object writers and the like. + class PROTOBUF_EXPORT AnyWriter { + public: + explicit AnyWriter(ProtoStreamObjectWriter* parent); + ~AnyWriter(); + + // Passes a StartObject call through to the Any writer. + void StartObject(StringPiece name); + + // Passes an EndObject call through to the Any. Returns true if the any + // handled the EndObject call, false if the Any is now all done and is no + // longer needed. + bool EndObject(); + + // Passes a StartList call through to the Any writer. + void StartList(StringPiece name); + + // Passes an EndList call through to the Any writer. + void EndList(); + + // Renders a data piece on the any. + void RenderDataPiece(StringPiece name, const DataPiece& value); + + private: + // Before the "@type" field is encountered, we store all incoming data + // into this Event struct and replay them after we get the "@type" field. + class PROTOBUF_EXPORT Event { + public: + enum Type { + START_OBJECT = 0, + END_OBJECT = 1, + START_LIST = 2, + END_LIST = 3, + RENDER_DATA_PIECE = 4, + }; + + // Constructor for END_OBJECT and END_LIST events. + explicit Event(Type type) : type_(type), value_(DataPiece::NullData()) {} + + // Constructor for START_OBJECT and START_LIST events. + explicit Event(Type type, StringPiece name) + : type_(type), name_(name), value_(DataPiece::NullData()) {} + + // Constructor for RENDER_DATA_PIECE events. + explicit Event(StringPiece name, const DataPiece& value) + : type_(RENDER_DATA_PIECE), name_(name), value_(value) { + DeepCopy(); + } + + Event(const Event& other) + : type_(other.type_), name_(other.name_), value_(other.value_) { + DeepCopy(); + } + + Event& operator=(const Event& other) { + type_ = other.type_; + name_ = other.name_; + value_ = other.value_; + DeepCopy(); + return *this; + } + + void Replay(AnyWriter* writer) const; + + private: + void DeepCopy(); + + Type type_; + std::string name_; + DataPiece value_; + std::string value_storage_; + }; + + // Handles starting up the any once we have a type. + void StartAny(const DataPiece& value); + + // Writes the Any out to the parent writer in its serialized form. + void WriteAny(); + + // The parent of this writer, needed for various bits such as type info and + // the listeners. + ProtoStreamObjectWriter* parent_; + + // The nested object writer, used to write events. + std::unique_ptr ow_; + + // The type_url_ that this Any represents. + std::string type_url_; + + // Whether this any is invalid. This allows us to only report an invalid + // Any message a single time rather than every time we get a nested field. + bool invalid_; + + // The output data and wrapping ByteSink. + std::string data_; + strings::StringByteSink output_; + + // The depth within the Any, so we can track when we're done. + int depth_; + + // True if the type is a well-known type. Well-known types in Any + // has a special formatting: + // { + // "@type": "type.googleapis.com/google.protobuf.XXX", + // "value": , + // } + bool is_well_known_type_; + TypeRenderer* well_known_type_render_; + + // Store data before the "@type" field. + std::vector uninterpreted_events_; + }; + + // Represents an item in a stack of items used to keep state between + // ObjectWrier events. + class PROTOBUF_EXPORT Item : public BaseElement { + public: + // Indicates the type of item. + enum ItemType { + MESSAGE, // Simple message + MAP, // Proto3 map type + ANY, // Proto3 Any type + }; + + // Constructor for the root item. + Item(ProtoStreamObjectWriter* enclosing, ItemType item_type, + bool is_placeholder, bool is_list); + + // Constructor for a field of a message. + Item(Item* parent, ItemType item_type, bool is_placeholder, bool is_list); + + ~Item() override {} + + // These functions return true if the element type is corresponding to the + // type in function name. + bool IsMap() { return item_type_ == MAP; } + bool IsAny() { return item_type_ == ANY; } + + AnyWriter* any() const { return any_.get(); } + + Item* parent() const override { + return static_cast(BaseElement::parent()); + } + + // Inserts map key into hash set if and only if the key did NOT already + // exist in hash set. + // The hash set (map_keys_) is ONLY used to keep track of map keys. + // Return true if insert successfully; returns false if the map key was + // already present. + bool InsertMapKeyIfNotPresent(StringPiece map_key); + + bool is_placeholder() const { return is_placeholder_; } + bool is_list() const { return is_list_; } + + private: + // Used for access to variables of the enclosing instance of + // ProtoStreamObjectWriter. + ProtoStreamObjectWriter* ow_; + + // A writer for Any objects, handles all Any-related nonsense. + std::unique_ptr any_; + + // The type of this element, see enum for permissible types. + ItemType item_type_; + + // Set of map keys already seen for the type_. Used to validate incoming + // messages so no map key appears more than once. + std::unique_ptr > map_keys_; + + // Conveys whether this Item is a placeholder or not. Placeholder items are + // pushed to stack to account for special types. + bool is_placeholder_; + + // Conveys whether this Item is a list or not. This is used to send + // StartList or EndList calls to underlying ObjectWriter. + bool is_list_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(Item); + }; + + ProtoStreamObjectWriter(const TypeInfo* typeinfo, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener); + + ProtoStreamObjectWriter(const TypeInfo* typeinfo, + const google::protobuf::Type& type, + strings::ByteSink* output, ErrorListener* listener, + const ProtoStreamObjectWriter::Options& options); + + // Returns true if the field is a map. + inline bool IsMap(const google::protobuf::Field& field); + + // Returns true if the field is an any. + inline bool IsAny(const google::protobuf::Field& field); + + // Returns true if the field is google.protobuf.Struct. + inline bool IsStruct(const google::protobuf::Field& field); + + // Returns true if the field is google.protobuf.Value. + inline bool IsStructValue(const google::protobuf::Field& field); + + // Returns true if the field is google.protobuf.ListValue. + inline bool IsStructListValue(const google::protobuf::Field& field); + + // Renders google.protobuf.Value in struct.proto. It picks the right oneof + // type based on value's type. + static util::Status RenderStructValue(ProtoStreamObjectWriter* ow, + const DataPiece& data); + + // Renders google.protobuf.Timestamp value. + static util::Status RenderTimestamp(ProtoStreamObjectWriter* ow, + const DataPiece& data); + + // Renders google.protobuf.FieldMask value. + static util::Status RenderFieldMask(ProtoStreamObjectWriter* ow, + const DataPiece& data); + + // Renders google.protobuf.Duration value. + static util::Status RenderDuration(ProtoStreamObjectWriter* ow, + const DataPiece& data); + + // Renders wrapper message types for primitive types in + // google/protobuf/wrappers.proto. + static util::Status RenderWrapperType(ProtoStreamObjectWriter* ow, + const DataPiece& data); + + static void InitRendererMap(); + static void DeleteRendererMap(); + static TypeRenderer* FindTypeRenderer(const std::string& type_url); + + // Returns true if the map key for type_ is not duplicated key. + // If map key is duplicated key, this function returns false. + // Note that caller should make sure that the current proto element (current_) + // is of element type MAP or STRUCT_MAP. + // It also calls the appropriate error callback and unnormalzied_name is used + // for error string. + bool ValidMapKey(StringPiece unnormalized_name); + + // Pushes an item on to the stack. Also calls either StartObject or StartList + // on the underlying ObjectWriter depending on whether is_list is false or + // not. + // is_placeholder conveys whether the item is a placeholder item or not. + // Placeholder items are pushed when adding auxiliary types' StartObject or + // StartList calls. + void Push(StringPiece name, Item::ItemType item_type, + bool is_placeholder, bool is_list); + + + // Pops items from the stack. All placeholder items are popped until a + // non-placeholder item is found. + void Pop(); + + // Pops one element from the stack. Calls EndObject() or EndList() on the + // underlying ObjectWriter depending on the value of is_list_. + void PopOneElement(); + + private: + // Helper functions to create the map and find functions responsible for + // rendering well known types, keyed by type URL. + static std::unordered_map* renderers_; + + // Variables for describing the structure of the input tree: + // master_type_: descriptor for the whole protobuf message. + const google::protobuf::Type& master_type_; + + // The current element, variable for internal state processing. + std::unique_ptr current_; + + // Reference to the options that control this class's behavior. + const ProtoStreamObjectWriter::Options options_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_PROTOSTREAM_OBJECTWRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc new file mode 100644 index 0000000..3348999 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc @@ -0,0 +1,3032 @@ +// 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 + +#include // For size_t + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + + +using proto_util_converter::testing::AnyM; +using proto_util_converter::testing::AnyOut; +using proto_util_converter::testing::Author; +using proto_util_converter::testing::Book; +using proto_util_converter::testing::FieldMaskTest; +using proto_util_converter::testing::Int32Wrapper; +using proto_util_converter::testing::MapIn; +using proto_util_converter::testing::Primitive; +using proto_util_converter::testing::Proto3Message; +using proto_util_converter::testing::Publisher; +using proto_util_converter::testing::StructType; +using proto_util_converter::testing::TestJsonName1; +using proto_util_converter::testing::TestJsonName2; +using proto_util_converter::testing::TimestampDuration; +using proto_util_converter::testing::ValueWrapper; +using proto_util_converter::testing::oneofs::OneOfsRequest; +using strings::GrowingArrayByteSink; +using ::testing::_; +using ::testing::Args; + + +namespace { +std::string GetTypeUrl(const Descriptor* descriptor) { + return std::string(kTypeServiceBaseUrl) + "/" + descriptor->full_name(); +} +} // namespace + +class BaseProtoStreamObjectWriterTest + : public ::testing::TestWithParam { + protected: + BaseProtoStreamObjectWriterTest() + : helper_(GetParam()), + listener_(), + output_(new GrowingArrayByteSink(1000)), + ow_() {} + + explicit BaseProtoStreamObjectWriterTest(const Descriptor* descriptor) + : helper_(GetParam()), + listener_(), + output_(new GrowingArrayByteSink(1000)), + ow_() { + std::vector descriptors; + descriptors.push_back(descriptor); + ResetTypeInfo(descriptors); + } + + explicit BaseProtoStreamObjectWriterTest( + std::vector descriptors) + : helper_(GetParam()), + listener_(), + output_(new GrowingArrayByteSink(1000)), + ow_() { + ResetTypeInfo(descriptors); + } + + void ResetTypeInfo(std::vector descriptors) { + GOOGLE_CHECK(!descriptors.empty()) << "Must have at least one descriptor!"; + helper_.ResetTypeInfo(descriptors); + ow_.reset(helper_.NewProtoWriter(GetTypeUrl(descriptors[0]), output_.get(), + &listener_, options_)); + } + + void ResetTypeInfo(const Descriptor* descriptor) { + std::vector descriptors; + descriptors.push_back(descriptor); + ResetTypeInfo(descriptors); + } + + ~BaseProtoStreamObjectWriterTest() override {} + + void CheckOutput(const Message& expected, int expected_length) { + size_t nbytes; + std::unique_ptr buffer(output_->GetBuffer(&nbytes)); + if (expected_length >= 0) { + EXPECT_EQ(expected_length, nbytes); + } + std::string str(buffer.get(), nbytes); + + std::stringbuf str_buf(str, std::ios_base::in); + std::istream istream(&str_buf); + std::unique_ptr message(expected.New()); + message->ParsePartialFromIstream(&istream); + + if (!MessageDifferencer::Equivalent(expected, *message)) { + EXPECT_EQ(expected.DebugString(), message->DebugString()); + } + } + + void CheckOutput(const Message& expected) { CheckOutput(expected, -1); } + + testing::TypeInfoTestHelper helper_; + MockErrorListener listener_; + std::unique_ptr output_; + std::unique_ptr ow_; + ProtoStreamObjectWriter::Options options_; +}; + +MATCHER_P(HasObjectLocation, expected, + "Verifies the expected object location") { + std::string actual = std::get<0>(arg).ToString(); + if (actual == expected) return true; + *result_listener << "actual location is: " << actual; + return false; +} + +class ProtoStreamObjectWriterTest : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterTest() + : BaseProtoStreamObjectWriterTest(Book::descriptor()) {} + + void ResetProtoWriter() { ResetTypeInfo(Book::descriptor()); } + + ~ProtoStreamObjectWriterTest() override {} +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterTest, EmptyObject) { + Book empty; + ow_->StartObject("")->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, SimpleObject) { + std::string content("My content"); + + Book book; + book.set_title("My Title"); + book.set_length(222); + book.set_content(content); + + ow_->StartObject("") + ->RenderString("title", "My Title") + ->RenderInt32("length", 222) + ->RenderBytes("content", content) + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, SimpleMessage) { + Book book; + book.set_title("Some Book"); + book.set_length(102); + Publisher* publisher = book.mutable_publisher(); + publisher->set_name("My Publisher"); + Author* robert = book.mutable_author(); + robert->set_alive(true); + robert->set_name("robert"); + robert->add_pseudonym("bob"); + robert->add_pseudonym("bobby"); + robert->add_friend_()->set_name("john"); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderInt32("length", 102) + ->StartObject("publisher") + ->RenderString("name", "My Publisher") + ->EndObject() + ->StartObject("author") + ->RenderBool("alive", true) + ->RenderString("name", "robert") + ->StartList("pseudonym") + ->RenderString("", "bob") + ->RenderString("", "bobby") + ->EndList() + ->StartList("friend") + ->StartObject("") + ->RenderString("name", "john") + ->EndObject() + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, CustomJsonName) { + Book book; + Author* robert = book.mutable_author(); + robert->set_id(12345); + robert->set_name("robert"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderUint64("@id", 12345) + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +// Test that two messages can have different fields mapped to the same JSON +// name. See: https://github.com/protocolbuffers/protobuf/issues/1415 +TEST_P(ProtoStreamObjectWriterTest, ConflictingJsonName) { + ResetTypeInfo(TestJsonName1::descriptor()); + TestJsonName1 message1; + message1.set_one_value(12345); + ow_->StartObject("")->RenderInt32("value", 12345)->EndObject(); + CheckOutput(message1); + + ResetTypeInfo(TestJsonName2::descriptor()); + TestJsonName2 message2; + message2.set_another_value(12345); + ow_->StartObject("")->RenderInt32("value", 12345)->EndObject(); + CheckOutput(message2); +} + + +TEST_P(ProtoStreamObjectWriterTest, IntEnumValuesAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::KIDS); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "2") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithDifferentCaseIsRejected) { + Book book; + book.set_title("Some Book"); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action_and_adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithSameCaseIsAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "ACTION_AND_ADVENTURE") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithDifferentCaseIsAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.case_insensitive_enum_parsing = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action_AND_adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithoutUnderscoreAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.use_lower_camel_for_enums = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "ACTIONANDADVENTURE") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, EnumValuesInCamelCaseAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.use_lower_camel_for_enums = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "actionAndAdventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, + EnumValuesInCamelCaseRemoveDashAndUnderscoreAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::ACTION_AND_ADVENTURE); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.use_lower_camel_for_enums = true; + options_.case_insensitive_enum_parsing = false; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "action-And_Adventure") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, + EnumValuesInCamelCaseWithNameNotUppercaseAreAccepted) { + Book book; + book.set_title("Some Book"); + book.set_type(proto_util_converter::testing::Book::arts_and_photography); + Author* robert = book.mutable_author(); + robert->set_name("robert"); + + options_.use_lower_camel_for_enums = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->RenderString("title", "Some Book") + ->RenderString("type", "artsAndPhotography") + ->StartObject("author") + ->RenderString("name", "robert") + ->EndObject() + ->EndObject(); + CheckOutput(book); +} + +TEST_P(ProtoStreamObjectWriterTest, PrimitiveFromStringConversion) { + Primitive full; + full.set_fix32(101); + full.set_u32(102); + full.set_i32(-103); + full.set_sf32(-104); + full.set_s32(-105); + full.set_fix64(40000000001L); + full.set_u64(40000000002L); + full.set_i64(-40000000003L); + full.set_sf64(-40000000004L); + full.set_s64(-40000000005L); + full.set_str("string1"); + full.set_bytes("Some Bytes"); + full.set_float_(3.14f); + full.set_double_(-4.05L); + full.set_bool_(true); + full.add_rep_fix32(201); + full.add_rep_u32(202); + full.add_rep_i32(-203); + full.add_rep_sf32(-204); + full.add_rep_s32(-205); + full.add_rep_fix64(80000000001L); + full.add_rep_u64(80000000002L); + full.add_rep_i64(-80000000003L); + full.add_rep_sf64(-80000000004L); + full.add_rep_s64(-80000000005L); + full.add_rep_str("string2"); + full.add_rep_bytes("More Bytes"); + full.add_rep_float(6.14f); + full.add_rep_double(-8.05L); + full.add_rep_bool(false); + + ResetTypeInfo(Primitive::descriptor()); + + ow_->StartObject("") + ->RenderString("fix32", "101") + ->RenderString("u32", "102") + ->RenderString("i32", "-103") + ->RenderString("sf32", "-104") + ->RenderString("s32", "-105") + ->RenderString("fix64", "40000000001") + ->RenderString("u64", "40000000002") + ->RenderString("i64", "-40000000003") + ->RenderString("sf64", "-40000000004") + ->RenderString("s64", "-40000000005") + ->RenderString("str", "string1") + ->RenderString("bytes", "U29tZSBCeXRlcw==") // "Some Bytes" + ->RenderString("float", "3.14") + ->RenderString("double", "-4.05") + ->RenderString("bool", "true") + ->StartList("rep_fix32") + ->RenderString("", "201") + ->EndList() + ->StartList("rep_u32") + ->RenderString("", "202") + ->EndList() + ->StartList("rep_i32") + ->RenderString("", "-203") + ->EndList() + ->StartList("rep_sf32") + ->RenderString("", "-204") + ->EndList() + ->StartList("rep_s32") + ->RenderString("", "-205") + ->EndList() + ->StartList("rep_fix64") + ->RenderString("", "80000000001") + ->EndList() + ->StartList("rep_u64") + ->RenderString("", "80000000002") + ->EndList() + ->StartList("rep_i64") + ->RenderString("", "-80000000003") + ->EndList() + ->StartList("rep_sf64") + ->RenderString("", "-80000000004") + ->EndList() + ->StartList("rep_s64") + ->RenderString("", "-80000000005") + ->EndList() + ->StartList("rep_str") + ->RenderString("", "string2") + ->EndList() + ->StartList("rep_bytes") + ->RenderString("", "TW9yZSBCeXRlcw==") // "More Bytes" + ->EndList() + ->StartList("rep_float") + ->RenderString("", "6.14") + ->EndList() + ->StartList("rep_double") + ->RenderString("", "-8.05") + ->EndList() + ->StartList("rep_bool") + ->RenderString("", "false") + ->EndList() + ->EndObject(); + CheckOutput(full); +} + +TEST_P(ProtoStreamObjectWriterTest, InfinityInputTest) { + Primitive full; + full.set_double_(std::numeric_limits::infinity()); + full.set_float_(std::numeric_limits::infinity()); + full.set_str("-Infinity"); + + ResetTypeInfo(Primitive::descriptor()); + + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_INT32"), + StringPiece("\"Infinity\""))) + .With(Args<0>(HasObjectLocation("i32"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_UINT32"), + StringPiece("\"Infinity\""))) + .With(Args<0>(HasObjectLocation("u32"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_SFIXED64"), + StringPiece("\"-Infinity\""))) + .With(Args<0>(HasObjectLocation("sf64"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_BOOL"), + StringPiece("\"Infinity\""))) + .With(Args<0>(HasObjectLocation("bool"))); + + ow_->StartObject("") + ->RenderString("double", "Infinity") + ->RenderString("float", "Infinity") + ->RenderString("i32", "Infinity") + ->RenderString("u32", "Infinity") + ->RenderString("sf64", "-Infinity") + ->RenderString("str", "-Infinity") + ->RenderString("bool", "Infinity") + ->EndObject(); + CheckOutput(full); +} + +TEST_P(ProtoStreamObjectWriterTest, NaNInputTest) { + Primitive full; + full.set_double_(std::numeric_limits::quiet_NaN()); + full.set_float_(std::numeric_limits::quiet_NaN()); + full.set_str("NaN"); + + ResetTypeInfo(Primitive::descriptor()); + + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_INT32"), + StringPiece("\"NaN\""))) + .With(Args<0>(HasObjectLocation("i32"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_UINT32"), + StringPiece("\"NaN\""))) + .With(Args<0>(HasObjectLocation("u32"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_SFIXED64"), + StringPiece("\"NaN\""))) + .With(Args<0>(HasObjectLocation("sf64"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_BOOL"), + StringPiece("\"NaN\""))) + .With(Args<0>(HasObjectLocation("bool"))); + + ow_->StartObject("") + ->RenderString("double", "NaN") + ->RenderString("float", "NaN") + ->RenderString("i32", "NaN") + ->RenderString("u32", "NaN") + ->RenderString("sf64", "NaN") + ->RenderString("str", "NaN") + ->RenderString("bool", "NaN") + ->EndObject(); + + CheckOutput(full); +} + +TEST_P(ProtoStreamObjectWriterTest, ImplicitPrimitiveList) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("The Author"); + author->add_pseudonym("first"); + author->add_pseudonym("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "The Author") + ->RenderString("pseudonym", "first") + ->RenderString("pseudonym", "second") + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, + LastWriteWinsOnNonRepeatedPrimitiveFieldWithDuplicates) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "first") + ->RenderString("name", "second") + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, ExplicitPrimitiveList) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("The Author"); + author->add_pseudonym("first"); + author->add_pseudonym("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "The Author") + ->StartList("pseudonym") + ->RenderString("", "first") + ->RenderString("", "second") + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, NonRepeatedExplicitPrimitiveList) { + Book expected; + expected.set_allocated_author(new Author()); + + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("name"), + StringPiece( + "Proto field is not repeating, cannot start list."))) + .With(Args<0>(HasObjectLocation("author"))); + ow_->StartObject("") + ->StartObject("author") + ->StartList("name") + ->RenderString("", "first") + ->RenderString("", "second") + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, ImplicitMessageList) { + Book expected; + Author* outer = expected.mutable_author(); + outer->set_name("outer"); + outer->set_alive(true); + Author* first = outer->add_friend_(); + first->set_name("first"); + Author* second = outer->add_friend_(); + second->set_name("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "outer") + ->RenderBool("alive", true) + ->StartObject("friend") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("friend") + ->RenderString("name", "second") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, DisableImplicitMessageList) { + options_.disable_implicit_message_list = true; + options_.suppress_implicit_message_list_error = true; + ResetProtoWriter(); + + Book expected; + // The repeated friend field of the author is empty. + expected.mutable_author(); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + + ow_->StartObject("") + ->StartObject("author") + ->StartObject("friend") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("friend") + ->RenderString("name", "second") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, + DisableImplicitMessageListWithoutErrorSuppressed) { + options_.disable_implicit_message_list = true; + ResetProtoWriter(); + + Book expected; + // The repeated friend field of the author is empty. + expected.mutable_author(); + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("friend"), + StringPiece( + "Starting an object in a repeated field but the parent object " + "is not a list"))) + .With(Args<0>(HasObjectLocation("author"))) + .Times(2); + + ow_->StartObject("") + ->StartObject("author") + ->StartObject("friend") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("friend") + ->RenderString("name", "second") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, + LastWriteWinsOnNonRepeatedMessageFieldWithDuplicates) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("The Author"); + Publisher* publisher = expected.mutable_publisher(); + publisher->set_name("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "The Author") + ->EndObject() + ->StartObject("publisher") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("publisher") + ->RenderString("name", "second") + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, ExplicitMessageList) { + Book expected; + Author* outer = expected.mutable_author(); + outer->set_name("outer"); + outer->set_alive(true); + Author* first = outer->add_friend_(); + first->set_name("first"); + Author* second = outer->add_friend_(); + second->set_name("second"); + + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "outer") + ->RenderBool("alive", true) + ->StartList("friend") + ->StartObject("") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("") + ->RenderString("name", "second") + ->EndObject() + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, NonRepeatedExplicitMessageList) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("The Author"); + + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("publisher"), + StringPiece( + "Proto field is not repeating, cannot start list."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "The Author") + ->EndObject() + ->StartList("publisher") + ->StartObject("") + ->RenderString("name", "first") + ->EndObject() + ->StartObject("") + ->RenderString("name", "second") + ->EndObject() + ->EndList() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownFieldAtRoot) { + Book empty; + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("unknown"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("")->RenderString("unknown", "Nope!")->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownFieldAtAuthorFriend) { + Book expected; + Author* paul = expected.mutable_author(); + paul->set_name("Paul"); + Author* mark = paul->add_friend_(); + mark->set_name("Mark"); + Author* john = paul->add_friend_(); + john->set_name("John"); + Author* luke = paul->add_friend_(); + luke->set_name("Luke"); + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("address"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation("author.friend[1]"))); + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "Paul") + ->StartList("friend") + ->StartObject("") + ->RenderString("name", "Mark") + ->EndObject() + ->StartObject("") + ->RenderString("name", "John") + ->RenderString("address", "Patmos") + ->EndObject() + ->StartObject("") + ->RenderString("name", "Luke") + ->EndObject() + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownObjectAtRoot) { + Book empty; + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("unknown"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("")->StartObject("unknown")->EndObject()->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownObjectAtAuthor) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("William"); + author->add_pseudonym("Bill"); + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("wife"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation("author"))); + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "William") + ->StartObject("wife") + ->RenderString("name", "Hilary") + ->EndObject() + ->RenderString("pseudonym", "Bill") + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownListAtRoot) { + Book empty; + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("unknown"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("")->StartList("unknown")->EndList()->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, UnknownListAtPublisher) { + Book expected; + expected.set_title("Brainwashing"); + Publisher* publisher = expected.mutable_publisher(); + publisher->set_name("propaganda"); + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("alliance"), + StringPiece("Cannot find field."))) + .With(Args<0>(HasObjectLocation("publisher"))); + ow_->StartObject("") + ->StartObject("publisher") + ->RenderString("name", "propaganda") + ->StartList("alliance") + ->EndList() + ->EndObject() + ->RenderString("title", "Brainwashing") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownFieldAtRoot) { + Book empty; + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("")->RenderString("unknown", "Nope!")->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownFieldAtAuthorFriend) { + Book expected; + Author* paul = expected.mutable_author(); + paul->set_name("Paul"); + Author* mark = paul->add_friend_(); + mark->set_name("Mark"); + Author* john = paul->add_friend_(); + john->set_name("John"); + Author* luke = paul->add_friend_(); + luke->set_name("Luke"); + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "Paul") + ->StartList("friend") + ->StartObject("") + ->RenderString("name", "Mark") + ->EndObject() + ->StartObject("") + ->RenderString("name", "John") + ->RenderString("address", "Patmos") + ->EndObject() + ->StartObject("") + ->RenderString("name", "Luke") + ->EndObject() + ->EndList() + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownObjectAtRoot) { + Book empty; + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, StringPiece("unknown"), + StringPiece("Cannot find field."))) + .Times(0); + ow_->StartObject("")->StartObject("unknown")->EndObject()->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownObjectAtAuthor) { + Book expected; + Author* author = expected.mutable_author(); + author->set_name("William"); + author->add_pseudonym("Bill"); + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("author") + ->RenderString("name", "William") + ->StartObject("wife") + ->RenderString("name", "Hilary") + ->EndObject() + ->RenderString("pseudonym", "Bill") + ->EndObject() + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownListAtRoot) { + Book empty; + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("")->StartList("unknown")->EndList()->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownListAtPublisher) { + Book expected; + expected.set_title("Brainwashing"); + Publisher* publisher = expected.mutable_publisher(); + publisher->set_name("propaganda"); + + options_.ignore_unknown_fields = true; + ResetProtoWriter(); + + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("publisher") + ->RenderString("name", "propaganda") + ->StartList("alliance") + ->EndList() + ->EndObject() + ->RenderString("title", "Brainwashing") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, + IgnoreUnknownFieldsDontIgnoreUnknownEnumValues) { + ResetTypeInfo(Proto3Message::descriptor()); + + Proto3Message expected; + EXPECT_CALL( + listener_, + InvalidValue(_, + StringPiece( + "type.googleapis.com/" + "proto_util_converter.testing.Proto3Message.NestedEnum"), + StringPiece("\"someunknownvalueyouwillneverknow\""))) + .With(Args<0>(HasObjectLocation("enum_value"))); + ow_->StartObject("") + ->RenderString("enumValue", "someunknownvalueyouwillneverknow") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, AcceptUnknownEnumValue) { + ResetTypeInfo(Proto3Message::descriptor()); + + Proto3Message expected; + expected.set_enum_value(static_cast(12345)); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderInt32("enumValue", 12345)->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, MissingRequiredField) { + Book expected; + expected.set_title("My Title"); + expected.set_allocated_publisher(new Publisher()); + + EXPECT_CALL(listener_, MissingField(_, StringPiece("name"))) + .With(Args<0>(HasObjectLocation("publisher"))); + ow_->StartObject("") + ->StartObject("publisher") + ->EndObject() + ->RenderString("title", "My Title") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, InvalidFieldValueAtRoot) { + Book empty; + + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_UINT32"), + StringPiece("\"garbage\""))) + .With(Args<0>(HasObjectLocation("length"))); + ow_->StartObject("")->RenderString("length", "garbage")->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, MultipleInvalidFieldValues) { + Book expected; + expected.set_title("My Title"); + + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_UINT32"), + StringPiece("\"-400\""))) + .With(Args<0>(HasObjectLocation("length"))); + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("TYPE_INT64"), + StringPiece("\"3.14\""))) + .With(Args<0>(HasObjectLocation("published"))); + ow_->StartObject("") + ->RenderString("length", "-400") + ->RenderString("published", "3.14") + ->RenderString("title", "My Title") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, UnnamedFieldAtRoot) { + Book empty; + + EXPECT_CALL(listener_, + InvalidName(_, StringPiece(""), + StringPiece("Proto fields must have a name."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("")->RenderFloat("", 3.14)->EndObject(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, UnnamedFieldAtAuthor) { + Book expected; + expected.set_title("noname"); + expected.set_allocated_author(new Author()); + + EXPECT_CALL(listener_, + InvalidName(_, StringPiece(""), + StringPiece("Proto fields must have a name."))) + .With(Args<0>(HasObjectLocation("author"))); + ow_->StartObject("") + ->StartObject("author") + ->RenderInt32("", 123) + ->EndObject() + ->RenderString("title", "noname") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, UnnamedListAtRoot) { + Book expected; + expected.set_title("noname"); + + EXPECT_CALL(listener_, + InvalidName(_, StringPiece(""), + StringPiece("Proto fields must have a name."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("") + ->StartList("") + ->EndList() + ->RenderString("title", "noname") + ->EndObject(); + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterTest, RootNamedObject) { + Book expected; + expected.set_title("Annie"); + + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("oops"), + StringPiece("Root element should not be named."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("oops")->RenderString("title", "Annie")->EndObject(); + CheckOutput(expected, 7); +} + +TEST_P(ProtoStreamObjectWriterTest, RootNamedList) { + Book empty; + + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("oops"), + StringPiece("Root element should not be named."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartList("oops")->RenderString("", "item")->EndList(); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, RootUnnamedField) { + Book empty; + + EXPECT_CALL(listener_, + InvalidName(_, StringPiece(""), + StringPiece("Root element must be a message."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->RenderBool("", true); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, RootNamedField) { + Book empty; + + EXPECT_CALL(listener_, + InvalidName(_, StringPiece("oops"), + StringPiece("Root element must be a message."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->RenderBool("oops", true); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, NullValue) { + Book empty; + + ow_->RenderNull(""); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, NullValueForMessageField) { + Book empty; + + ow_->RenderNull("author"); + CheckOutput(empty, 0); +} + +TEST_P(ProtoStreamObjectWriterTest, NullValueForPrimitiveField) { + Book empty; + + ow_->RenderNull("length"); + CheckOutput(empty, 0); +} + +class ProtoStreamObjectWriterTimestampDurationTest + : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterTimestampDurationTest() { + std::vector descriptors; + descriptors.push_back(TimestampDuration::descriptor()); + descriptors.push_back(google::protobuf::Timestamp::descriptor()); + descriptors.push_back(google::protobuf::Duration::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterTimestampDurationTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, ParseTimestamp) { + TimestampDuration timestamp; + google::protobuf::Timestamp* ts = timestamp.mutable_ts(); + ts->set_seconds(1448249855); + ts->set_nanos(33155000); + + ow_->StartObject("") + ->RenderString("ts", "2015-11-23T03:37:35.033155Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + ParseTimestampYearNotZeroPadded) { + TimestampDuration timestamp; + google::protobuf::Timestamp* ts = timestamp.mutable_ts(); + ts->set_seconds(-61665654145); + ts->set_nanos(33155000); + + ow_->StartObject("") + ->RenderString("ts", "15-11-23T03:37:35.033155Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + ParseTimestampYearZeroPadded) { + TimestampDuration timestamp; + google::protobuf::Timestamp* ts = timestamp.mutable_ts(); + ts->set_seconds(-61665654145); + ts->set_nanos(33155000); + + ow_->StartObject("") + ->RenderString("ts", "0015-11-23T03:37:35.033155Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + ParseTimestampWithPositiveOffset) { + TimestampDuration timestamp; + google::protobuf::Timestamp* ts = timestamp.mutable_ts(); + ts->set_seconds(1448249855); + ts->set_nanos(33155000); + + ow_->StartObject("") + ->RenderString("ts", "2015-11-23T11:47:35.033155+08:10") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + ParseTimestampWithNegativeOffset) { + TimestampDuration timestamp; + google::protobuf::Timestamp* ts = timestamp.mutable_ts(); + ts->set_seconds(1448249855); + ts->set_nanos(33155000); + + ow_->StartObject("") + ->RenderString("ts", "2015-11-22T19:47:35.033155-07:50") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + TimestampWithInvalidOffset1) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2016-03-07T15:14:23+"))); + + ow_->StartObject("")->RenderString("ts", "2016-03-07T15:14:23+")->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + TimestampWithInvalidOffset2) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2016-03-07T15:14:23+08-10"))); + + ow_->StartObject("") + ->RenderString("ts", "2016-03-07T15:14:23+08-10") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + TimestampWithInvalidOffset3) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2016-03-07T15:14:23+24:10"))); + + ow_->StartObject("") + ->RenderString("ts", "2016-03-07T15:14:23+24:10") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + TimestampWithInvalidOffset4) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2016-03-07T15:14:23+04:60"))); + + ow_->StartObject("") + ->RenderString("ts", "2016-03-07T15:14:23+04:60") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError1) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: "))); + + ow_->StartObject("")->RenderString("ts", "")->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError2) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: Z"))); + + ow_->StartObject("")->RenderString("ts", "Z")->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError3) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "1970-01-01T00:00:00.ABZ"))); + + ow_->StartObject("") + ->RenderString("ts", "1970-01-01T00:00:00.ABZ") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError4) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "-8031-10-18T00:00:00.000Z"))); + + ow_->StartObject("") + ->RenderString("ts", "-8031-10-18T00:00:00.000Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError5) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2015-11-23T03:37:35.033155 Z"))); + + ow_->StartObject("") + // Whitespace in the Timestamp nanos is not allowed. + ->RenderString("ts", "2015-11-23T03:37:35.033155 Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError6) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2015-11-23T03:37:35.033155 1234Z"))); + + ow_->StartObject("") + // Whitespace in the Timestamp nanos is not allowed. + ->RenderString("ts", "2015-11-23T03:37:35.033155 1234Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError7) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "2015-11-23T03:37:35.033abc155Z"))); + + ow_->StartObject("") + // Non-numeric characters in the Timestamp nanos is not allowed. + ->RenderString("ts", "2015-11-23T03:37:35.033abc155Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidTimestampError8) { + TimestampDuration timestamp; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece("Field 'ts', Invalid time format: " + "0-12-31T23:59:59.000Z"))); + + ow_->StartObject("") + ->RenderString("ts", "0-12-31T23:59:59.000Z") + ->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, ParseDuration) { + TimestampDuration duration; + google::protobuf::Duration* dur = duration.mutable_dur(); + dur->set_seconds(1448216930); + dur->set_nanos(132262000); + + ow_->StartObject("")->RenderString("dur", "1448216930.132262s")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidDurationError1) { + TimestampDuration duration; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece( + "Field 'dur', Illegal duration format; duration must " + "end with 's'"))); + + ow_->StartObject("")->RenderString("dur", "")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidDurationError2) { + TimestampDuration duration; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece( + "Field 'dur', Invalid duration format, failed to parse " + "seconds"))); + + ow_->StartObject("")->RenderString("dur", "s")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidDurationError3) { + TimestampDuration duration; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece("Field 'dur', Invalid duration format, failed to " + "parse nano seconds"))); + + ow_->StartObject("")->RenderString("dur", "123.DEFs")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidDurationError4) { + TimestampDuration duration; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece("Field 'dur', Duration value exceeds limits"))); + + ow_->StartObject("")->RenderString("dur", "315576000002s")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, InvalidDurationError5) { + TimestampDuration duration; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece("Field 'dur', Duration value exceeds limits"))); + + ow_->StartObject("")->RenderString("dur", "0.1000000001s")->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + MismatchedTimestampTypeInput) { + TimestampDuration timestamp; + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Timestamp"), + StringPiece( + "Field 'ts', Invalid data type for timestamp, value is 1"))) + .With(Args<0>(HasObjectLocation("ts"))); + ow_->StartObject("")->RenderInt32("ts", 1)->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, + MismatchedDurationTypeInput) { + TimestampDuration duration; + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Duration"), + StringPiece( + "Field 'dur', Invalid data type for duration, value is 1"))) + .With(Args<0>(HasObjectLocation("dur"))); + ow_->StartObject("")->RenderInt32("dur", 1)->EndObject(); + CheckOutput(duration); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, TimestampAcceptsNull) { + TimestampDuration timestamp; + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("ts")->EndObject(); + CheckOutput(timestamp); +} + +TEST_P(ProtoStreamObjectWriterTimestampDurationTest, DurationAcceptsNull) { + TimestampDuration duration; + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("dur")->EndObject(); + CheckOutput(duration); +} + +class ProtoStreamObjectWriterStructTest + : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterStructTest() { ResetProtoWriter(); } + + // Resets ProtoWriter with current set of options and other state. + void ResetProtoWriter() { + std::vector descriptors; + descriptors.push_back(StructType::descriptor()); + descriptors.push_back(google::protobuf::Struct::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterStructTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +// TODO(skarvaje): Write tests for failure cases. +TEST_P(ProtoStreamObjectWriterStructTest, StructRenderSuccess) { + StructType struct_type; + google::protobuf::Struct* s = struct_type.mutable_object(); + s->mutable_fields()->operator[]("k1").set_number_value(123); + s->mutable_fields()->operator[]("k2").set_bool_value(true); + + ow_->StartObject("") + ->StartObject("object") + ->RenderDouble("k1", 123) + ->RenderBool("k2", true) + ->EndObject() + ->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, StructNullInputSuccess) { + StructType struct_type; + EXPECT_CALL(listener_, + InvalidName(_, StringPiece(""), + StringPiece("Proto fields must have a name."))) + .With(Args<0>(HasObjectLocation(""))); + ow_->StartObject("")->RenderNull("")->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, StructInvalidInputFailure) { + StructType struct_type; + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.Struct"), + StringPiece("true"))) + .With(Args<0>(HasObjectLocation("object"))); + + ow_->StartObject("")->RenderBool("object", true)->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, StructAcceptsNull) { + StructType struct_type; + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + + ow_->StartObject("")->RenderNull("object")->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, StructValuePreservesNull) { + StructType struct_type; + (*struct_type.mutable_object()->mutable_fields())["key"].set_null_value( + google::protobuf::NULL_VALUE); + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + + ow_->StartObject("") + ->StartObject("object") + ->RenderNull("key") + ->EndObject() + ->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, SimpleRepeatedStructMapKeyTest) { + EXPECT_CALL(listener_, + InvalidName(_, StringPiece("gBike"), + StringPiece( + "Repeated map key: 'gBike' is already set."))); + ow_->StartObject("") + ->StartObject("object") + ->RenderString("gBike", "v1") + ->RenderString("gBike", "v2") + ->EndObject() + ->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterStructTest, RepeatedStructMapListKeyTest) { + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("k1"), + StringPiece("Repeated map key: 'k1' is already set."))); + ow_->StartObject("") + ->StartObject("object") + ->RenderString("k1", "v1") + ->StartList("k1") + ->RenderString("", "v2") + ->EndList() + ->EndObject() + ->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterStructTest, RepeatedStructMapObjectKeyTest) { + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("k1"), + StringPiece("Repeated map key: 'k1' is already set."))); + ow_->StartObject("") + ->StartObject("object") + ->StartObject("k1") + ->RenderString("sub_k1", "v1") + ->EndObject() + ->StartObject("k1") + ->RenderString("sub_k2", "v2") + ->EndObject() + ->EndObject() + ->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterStructTest, OptionStructIntAsStringsTest) { + StructType struct_type; + google::protobuf::Struct* s = struct_type.mutable_object(); + s->mutable_fields()->operator[]("k1").set_string_value("123"); + s->mutable_fields()->operator[]("k2").set_bool_value(true); + s->mutable_fields()->operator[]("k3").set_string_value("-222222222"); + s->mutable_fields()->operator[]("k4").set_string_value("33333333"); + + options_.struct_integers_as_strings = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->StartObject("object") + ->RenderDouble("k1", 123) + ->RenderBool("k2", true) + ->RenderInt64("k3", -222222222) + ->RenderUint64("k4", 33333333) + ->EndObject() + ->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, Struct32BitIntsAndFloatsTest) { + StructType struct_type; + google::protobuf::Struct* s = struct_type.mutable_object(); + s->mutable_fields()->operator[]("k1").set_number_value(1.5); + s->mutable_fields()->operator[]("k2").set_number_value(100); + s->mutable_fields()->operator[]("k3").set_number_value(100); + ResetProtoWriter(); + + ow_->StartObject("") + ->StartObject("object") + ->RenderFloat("k1", 1.5) + ->RenderInt32("k2", 100) + ->RenderUint32("k3", 100) + ->EndObject() + ->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, + Struct32BitIntsAndFloatsAsStringsTest) { + StructType struct_type; + google::protobuf::Struct* s = struct_type.mutable_object(); + s->mutable_fields()->operator[]("k1").set_string_value("1.5"); + s->mutable_fields()->operator[]("k2").set_string_value("100"); + s->mutable_fields()->operator[]("k3").set_string_value("100"); + + options_.struct_integers_as_strings = true; + ResetProtoWriter(); + + ow_->StartObject("") + ->StartObject("object") + ->RenderFloat("k1", 1.5) + ->RenderInt32("k2", 100) + ->RenderUint32("k3", 100) + ->EndObject() + ->EndObject(); + CheckOutput(struct_type); +} + +TEST_P(ProtoStreamObjectWriterStructTest, ValuePreservesNull) { + ValueWrapper value; + value.mutable_value()->set_null_value(google::protobuf::NULL_VALUE); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("value")->EndObject(); + CheckOutput(value); +} + +class ProtoStreamObjectWriterMapTest : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterMapTest() { + std::vector descriptors; + descriptors.push_back(MapIn::descriptor()); + descriptors.push_back(google::protobuf::DoubleValue::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterMapTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterMapTest, MapShouldNotAcceptList) { + MapIn mm; + EXPECT_CALL( + listener_, + InvalidValue(_, StringPiece("Map"), + StringPiece( + "Cannot bind a list to map for field 'map_input'."))); + ow_->StartObject("") + ->StartList("map_input") + ->RenderString("a", "b") + ->EndList() + ->EndObject(); + CheckOutput(mm); +} + +TEST_P(ProtoStreamObjectWriterMapTest, MapAcceptsNullValue) { + // Null should not be a valid map value. + // See http://go/proto3-json-spec#heading=h.r2ddatp7y4vi + // This test is added for backward compatibility. + MapIn mm; + (*mm.mutable_map_input())["a"] = "b"; + (*mm.mutable_map_input())["x"] = ""; + ow_->StartObject("") + ->StartObject("map_input") + ->RenderString("a", "b") + ->RenderNull("x") + ->EndObject() + ->EndObject(); + CheckOutput(mm); +} + +TEST_P(ProtoStreamObjectWriterMapTest, MapShouldIgnoreNullValueEntry) { + options_.ignore_null_value_map_entry = true; + ResetTypeInfo(MapIn::descriptor()); + MapIn mm; + (*mm.mutable_map_input())["a"] = "b"; + ow_->StartObject("") + ->StartObject("map_input") + ->RenderString("a", "b") + ->RenderNull("x") + ->EndObject() + ->EndObject(); + CheckOutput(mm); +} + +TEST_P(ProtoStreamObjectWriterMapTest, RepeatedMapKeyTest) { + EXPECT_CALL( + listener_, + InvalidName(_, StringPiece("k1"), + StringPiece("Repeated map key: 'k1' is already set."))); + ow_->StartObject("") + ->RenderString("other", "test") + ->StartObject("map_input") + ->RenderString("k1", "v1") + ->RenderString("k1", "v2") + ->EndObject() + ->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterMapTest, AnyInMap) { + MapIn mm; + google::protobuf::DoubleValue d; + d.set_value(40.2); + (*mm.mutable_map_any())["foo"].PackFrom(d); + ow_->StartObject("") + ->StartObject("map_any") + ->StartObject("foo") + ->RenderString("@type", "type.googleapis.com/google.protobuf.DoubleValue") + ->RenderDouble("value", 40.2) + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(mm); +} + +class ProtoStreamObjectWriterAnyTest : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterAnyTest() { + std::vector descriptors; + descriptors.push_back(AnyOut::descriptor()); + descriptors.push_back(Book::descriptor()); + descriptors.push_back(google::protobuf::Any::descriptor()); + descriptors.push_back(google::protobuf::DoubleValue::descriptor()); + descriptors.push_back(google::protobuf::FieldMask::descriptor()); + descriptors.push_back(google::protobuf::Int32Value::descriptor()); + descriptors.push_back(google::protobuf::Struct::descriptor()); + descriptors.push_back(google::protobuf::Timestamp::descriptor()); + descriptors.push_back(google::protobuf::Value::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterAnyTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyRenderSuccess) { + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.DoubleValue"); + google::protobuf::DoubleValue d; + d.set_value(40.2); + any_type->set_value(d.SerializeAsString()); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.DoubleValue") + ->RenderDouble("value", 40.2) + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, RecursiveAny) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any nested_any; + nested_any.set_type_url( + "type.googleapis.com/proto_util_converter.testing.AnyM"); + + AnyM m; + m.set_foo("foovalue"); + nested_any.set_value(m.SerializeAsString()); + + any->set_value(nested_any.SerializeAsString()); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.AnyM") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(out, 112); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, DoubleRecursiveAny) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + any->set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any nested_any; + nested_any.set_type_url("type.googleapis.com/google.protobuf.Any"); + + ::google::protobuf::Any second_nested_any; + second_nested_any.set_type_url( + "type.googleapis.com/proto_util_converter.testing.AnyM"); + + AnyM m; + m.set_foo("foovalue"); + second_nested_any.set_value(m.SerializeAsString()); + + nested_any.set_value(second_nested_any.SerializeAsString()); + any->set_value(nested_any.SerializeAsString()); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->StartObject("value") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.AnyM") + ->RenderString("foo", "foovalue") + ->EndObject() + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(out, 156); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, TypeUrlAtEnd) { + Book book; + book.set_title("C++"); + book.set_length(1234); + book.set_content("Hello World!"); + + ::google::protobuf::Any any; + any.PackFrom(book); + + ::google::protobuf::Any outer_any; + outer_any.PackFrom(any); + + AnyOut out; + out.mutable_any()->PackFrom(outer_any); + + // Put the @type field at the end of each Any message. Parsers should + // be able to accept that. + ow_->StartObject("") + ->StartObject("any") + ->StartObject("value") + ->StartObject("value") + ->RenderString("title", "C++") + ->RenderInt32("length", 1234) + ->RenderBytes("content", "Hello World!") + ->RenderString("@type", + "type.googleapis.com/proto_util_converter.testing.Book") + ->EndObject() + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->EndObject() + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// Same as TypeUrlAtEnd, but use temporary string values to make sure we don't +// mistakenly store StringPiece objects pointing to invalid memory. +TEST_P(ProtoStreamObjectWriterAnyTest, TypeUrlAtEndWithTemporaryStrings) { + Book book; + book.set_title("C++"); + book.set_length(1234); + book.set_content("Hello World!"); + + ::google::protobuf::Any any; + any.PackFrom(book); + + ::google::protobuf::Any outer_any; + outer_any.PackFrom(any); + + AnyOut out; + out.mutable_any()->PackFrom(outer_any); + + std::string name, value; + // Put the @type field at the end of each Any message. Parsers should + // be able to accept that. + ow_->StartObject("")->StartObject("any"); + { + ow_->StartObject("value"); + { + ow_->StartObject("value"); + { + name = "title"; + value = "C++"; + ow_->RenderString(name, value); + name = "length"; + ow_->RenderInt32(name, 1234); + name = "content"; + value = "Hello World!"; + ow_->RenderBytes(name, value); + name = "@type"; + value = "type.googleapis.com/proto_util_converter.testing.Book"; + ow_->RenderString(name, value); + } + ow_->EndObject(); + + name = "@type"; + value = "type.googleapis.com/google.protobuf.Any"; + ow_->RenderString(name, value); + } + ow_->EndObject(); + + name = "@type"; + value = "type.googleapis.com/google.protobuf.Any"; + ow_->RenderString(name, value); + } + ow_->EndObject()->EndObject(); + CheckOutput(out); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, EmptyAnyFromEmptyObject) { + AnyOut out; + out.mutable_any(); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + + ow_->StartObject("")->StartObject("any")->EndObject()->EndObject(); + + CheckOutput(out, 2); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails1) { + AnyOut any; + + EXPECT_CALL( + listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece("Missing @type for any field in " + "proto_util_converter.testing.AnyOut"))); + + ow_->StartObject("") + ->StartObject("any") + ->StartObject("another") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails2) { + AnyOut any; + + EXPECT_CALL( + listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece("Missing @type for any field in " + "proto_util_converter.testing.AnyOut"))); + + ow_->StartObject("") + ->StartObject("any") + ->StartList("another") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails3) { + AnyOut any; + + EXPECT_CALL( + listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece("Missing @type for any field in " + "proto_util_converter.testing.AnyOut"))); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("value", "somevalue") + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithInvalidTypeUrlFails) { + AnyOut any; + + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("Any"), + StringPiece("Invalid type URL, type URLs must be of the form " + "'type.googleapis.com/', got: " + "type.other.com/some.Type"))); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.other.com/some.Type") + ->RenderDouble("value", 40.2) + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithUnknownTypeFails) { + AnyOut any; + + EXPECT_CALL(listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece( + "Invalid type URL, unknown type: some.Type"))); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/some.Type") + ->RenderDouble("value", 40.2) + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyIncorrectInputTypeFails) { + AnyOut any; + + EXPECT_CALL( + listener_, + InvalidValue(_, + StringPiece("type.googleapis.com/google.protobuf.Any"), + StringPiece("1"))); + ow_->StartObject("")->RenderInt32("any", 1)->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyAcceptsNull) { + AnyOut any; + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("any")->EndObject(); + CheckOutput(any); +} + +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypeErrorTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("Any"), + StringPiece("Invalid time format: "))); + + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Timestamp"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Timestamp") + ->RenderString("value", "") + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "value": "abc" +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithNestedPrimitiveValue) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + ::google::protobuf::Value value; + value.set_string_value("abc"); + any->PackFrom(value); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->RenderString("value", "abc") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "value": { +// "foo": "abc" +// } +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithNestedObjectValue) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + ::google::protobuf::Value value; + (*value.mutable_struct_value()->mutable_fields())["foo"].set_string_value( + "abc"); + any->PackFrom(value); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->StartObject("value") + ->RenderString("foo", "abc") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "value": ["hello"], +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithNestedArrayValue) { + AnyOut out; + ::google::protobuf::Any* any = out.mutable_any(); + + ::google::protobuf::Value value; + value.mutable_list_value()->add_values()->set_string_value("hello"); + any->PackFrom(value); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->StartList("value") + ->RenderString("", "hello") + ->EndList() + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "not_value": "" +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, + AnyWellKnownTypesNoValueFieldForPrimitive) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("Any"), + StringPiece("Expect a \"value\" field for well-known types."))); + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Value"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->RenderString("not_value", "") + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "not_value": {} +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypesNoValueFieldForObject) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("Any"), + StringPiece("Expect a \"value\" field for well-known types."))); + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Value"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->StartObject("not_value") + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Value", +// "not_value": [], +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypesNoValueFieldForArray) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("Any"), + StringPiece("Expect a \"value\" field for well-known types."))); + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Value"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Value") + ->StartList("not_value") + ->EndList() + ->EndObject() + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Struct", +// "value": "", +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypesExpectObjectForStruct) { + EXPECT_CALL(listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece("Expect a JSON object."))); + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Struct"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Struct") + ->RenderString("value", "") + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// Test the following case: +// +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Any", +// "value": "", +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypesExpectObjectForAny) { + EXPECT_CALL(listener_, + InvalidValue(_, StringPiece("Any"), + StringPiece("Expect a JSON object."))); + AnyOut any; + google::protobuf::Any* any_type = any.mutable_any(); + any_type->set_type_url("type.googleapis.com/google.protobuf.Any"); + + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->RenderString("value", "") + ->EndObject() + ->EndObject(); + CheckOutput(any); +} + +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Any", +// "value": null +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, AnyInAnyAcceptsNull) { + AnyOut out; + google::protobuf::Any empty; + out.mutable_any()->PackFrom(empty); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Any") + ->RenderNull("value") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Timestamp", +// "value": null +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, TimestampInAnyAcceptsNull) { + AnyOut out; + google::protobuf::Timestamp empty; + out.mutable_any()->PackFrom(empty); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Timestamp") + ->RenderNull("value") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Duration", +// "value": null +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, DurationInAnyAcceptsNull) { + AnyOut out; + google::protobuf::Duration empty; + out.mutable_any()->PackFrom(empty); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Duration") + ->RenderNull("value") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.FieldMask", +// "value": null +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, FieldMaskInAnyAcceptsNull) { + AnyOut out; + google::protobuf::FieldMask empty; + out.mutable_any()->PackFrom(empty); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.FieldMask") + ->RenderNull("value") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +// { +// "any": { +// "@type": "type.googleapis.com/google.protobuf.Int32Value", +// "value": null +// } +// } +TEST_P(ProtoStreamObjectWriterAnyTest, WrapperInAnyAcceptsNull) { + AnyOut out; + google::protobuf::Int32Value empty; + out.mutable_any()->PackFrom(empty); + + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("") + ->StartObject("any") + ->RenderString("@type", "type.googleapis.com/google.protobuf.Int32Value") + ->RenderNull("value") + ->EndObject() + ->EndObject(); + CheckOutput(out); +} + +class ProtoStreamObjectWriterFieldMaskTest + : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterFieldMaskTest() { + std::vector descriptors; + descriptors.push_back(FieldMaskTest::descriptor()); + descriptors.push_back(google::protobuf::FieldMask::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterFieldMaskTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, SimpleFieldMaskTest) { + FieldMaskTest expected; + expected.set_id("1"); + expected.mutable_single_mask()->add_paths("path1"); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->RenderString("single_mask", "path1"); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MultipleMasksInCompactForm) { + FieldMaskTest expected; + expected.set_id("1"); + expected.mutable_single_mask()->add_paths("camel_case1"); + expected.mutable_single_mask()->add_paths("camel_case2"); + expected.mutable_single_mask()->add_paths("camel_case3"); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->RenderString("single_mask", "camelCase1,camelCase2,camelCase3"); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, RepeatedFieldMaskTest) { + FieldMaskTest expected; + expected.set_id("1"); + google::protobuf::FieldMask* mask = expected.add_repeated_mask(); + mask->add_paths("field1"); + mask->add_paths("field2"); + expected.add_repeated_mask()->add_paths("field3"); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->StartList("repeated_mask"); + ow_->RenderString("", "field1,field2"); + ow_->RenderString("", "field3"); + ow_->EndList(); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, EmptyFieldMaskTest) { + FieldMaskTest expected; + expected.set_id("1"); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->RenderString("single_mask", ""); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MaskUsingApiaryStyleShouldWork) { + FieldMaskTest expected; + expected.set_id("1"); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + // Case1 + ow_->RenderString("single_mask", + "outerField(camelCase1,camelCase2,camelCase3)"); + expected.mutable_single_mask()->add_paths("outer_field.camel_case1"); + expected.mutable_single_mask()->add_paths("outer_field.camel_case2"); + expected.mutable_single_mask()->add_paths("outer_field.camel_case3"); + + ow_->StartList("repeated_mask"); + + ow_->RenderString("", "a(field1,field2)"); + google::protobuf::FieldMask* mask = expected.add_repeated_mask(); + mask->add_paths("a.field1"); + mask->add_paths("a.field2"); + + ow_->RenderString("", "a(field3)"); + mask = expected.add_repeated_mask(); + mask->add_paths("a.field3"); + + ow_->RenderString("", "a()"); + expected.add_repeated_mask(); + + ow_->RenderString("", "a(,)"); + expected.add_repeated_mask(); + + ow_->RenderString("", "a(field1(field2(field3)))"); + mask = expected.add_repeated_mask(); + mask->add_paths("a.field1.field2.field3"); + + ow_->RenderString("", "a(field1(field2(field3,field4),field5),field6)"); + mask = expected.add_repeated_mask(); + mask->add_paths("a.field1.field2.field3"); + mask->add_paths("a.field1.field2.field4"); + mask->add_paths("a.field1.field5"); + mask->add_paths("a.field6"); + + ow_->RenderString("", "a(id,field1(id,field2(field3,field4),field5),field6)"); + mask = expected.add_repeated_mask(); + mask->add_paths("a.id"); + mask->add_paths("a.field1.id"); + mask->add_paths("a.field1.field2.field3"); + mask->add_paths("a.field1.field2.field4"); + mask->add_paths("a.field1.field5"); + mask->add_paths("a.field6"); + + ow_->RenderString("", "a(((field3,field4)))"); + mask = expected.add_repeated_mask(); + mask->add_paths("a.field3"); + mask->add_paths("a.field4"); + + ow_->EndList(); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MoreCloseThanOpenParentheses) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.FieldMask"), + StringPiece("Field 'single_mask', Invalid FieldMask 'a(b,c))'. " + "Cannot find matching '(' for all ')'."))); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->RenderString("single_mask", "a(b,c))"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MoreOpenThanCloseParentheses) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.FieldMask"), + StringPiece( + "Field 'single_mask', Invalid FieldMask 'a(((b,c)'. Cannot " + "find matching ')' for all '('."))); + + ow_->StartObject(""); + ow_->RenderString("id", "1"); + ow_->RenderString("single_mask", "a(((b,c)"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, PathWithMapKeyShouldWork) { + FieldMaskTest expected; + expected.mutable_single_mask()->add_paths("path.to.map[\"key1\"]"); + expected.mutable_single_mask()->add_paths( + "path.to.map[\"e\\\"[]][scape\\\"\"]"); + expected.mutable_single_mask()->add_paths("path.to.map[\"key2\"]"); + + ow_->StartObject(""); + ow_->RenderString("single_mask", + "path.to.map[\"key1\"],path.to.map[\"e\\\"[]][scape\\\"\"]," + "path.to.map[\"key2\"]"); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, + MapKeyMustBeAtTheEndOfAPathSegment) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.FieldMask"), + StringPiece( + "Field 'single_mask', Invalid FieldMask " + "'path.to.map[\"key1\"]a,path.to.map[\"key2\"]'. " + "Map keys should be at the end of a path segment."))); + + ow_->StartObject(""); + ow_->RenderString("single_mask", + "path.to.map[\"key1\"]a,path.to.map[\"key2\"]"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyMustEnd) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.FieldMask"), + StringPiece("Field 'single_mask', Invalid FieldMask " + "'path.to.map[\"key1\"'. Map keys should be " + "represented as [\"some_key\"]."))); + + ow_->StartObject(""); + ow_->RenderString("single_mask", "path.to.map[\"key1\""); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyMustBeEscapedCorrectly) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("type.googleapis.com/google.protobuf.FieldMask"), + StringPiece("Field 'single_mask', Invalid FieldMask " + "'path.to.map[\"ke\"y1\"]'. Map keys should be " + "represented as [\"some_key\"]."))); + + ow_->StartObject(""); + ow_->RenderString("single_mask", "path.to.map[\"ke\"y1\"]"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyCanContainAnyChars) { + FieldMaskTest expected; + expected.mutable_single_mask()->add_paths( + // \xE5\xAD\x99 is the UTF-8 byte sequence for chinese character 孙. + // We cannot embed non-ASCII characters in the code directly because + // some windows compilers will try to interpret them using the system's + // current encoding and end up with invalid UTF-8 byte sequence. + "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"]"); + expected.mutable_single_mask()->add_paths("path.to.map[\"key2\"]"); + + ow_->StartObject(""); + ow_->RenderString( + "single_mask", + "path.to.map[\"(),[],\\\"'!@#$%^&*123_|War\xE5\xAD\x99,./?><\\\\\"]," + "path.to.map[\"key2\"]"); + ow_->EndObject(); + + CheckOutput(expected); +} + +TEST_P(ProtoStreamObjectWriterFieldMaskTest, FieldMaskAcceptsNull) { + FieldMaskTest expected; + EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("single_mask")->EndObject(); + CheckOutput(expected); +} + +class ProtoStreamObjectWriterWrappersTest + : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterWrappersTest() { + std::vector descriptors; + descriptors.push_back(Int32Wrapper::descriptor()); + descriptors.push_back(google::protobuf::Int32Value::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterWrappersTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterWrappersTest, WrapperAcceptsNull) { + Int32Wrapper wrapper; + EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0); + ow_->StartObject("")->RenderNull("int32")->EndObject(); + CheckOutput(wrapper); +} + +class ProtoStreamObjectWriterOneOfsTest + : public BaseProtoStreamObjectWriterTest { + protected: + ProtoStreamObjectWriterOneOfsTest() { + std::vector descriptors; + descriptors.push_back(OneOfsRequest::descriptor()); + descriptors.push_back(google::protobuf::Struct::descriptor()); + ResetTypeInfo(descriptors); + } +}; + +INSTANTIATE_TEST_SUITE_P(DifferentTypeInfoSourceTest, + ProtoStreamObjectWriterOneOfsTest, + ::testing::Values( + testing::USE_TYPE_RESOLVER)); + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForPrimitiveTypesTest) { + EXPECT_CALL( + listener_, + InvalidValue( + _, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. Cannot set 'intData'"))); + + ow_->StartObject(""); + ow_->RenderString("strData", "blah"); + ow_->RenderString("intData", "123"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForMessageTypesPrimitiveFirstTest) { + // Test for setting primitive oneof field first and then message field. + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'messageData'"))); + + // JSON: { "strData": "blah", "messageData": { "dataValue": 123 } } + ow_->StartObject(""); + ow_->RenderString("strData", "blah"); + ow_->StartObject("messageData"); + ow_->RenderInt32("dataValue", 123); + ow_->EndObject(); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForMessageTypesMessageFirstTest) { + // Test for setting message oneof field first and then primitive field. + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'strData'"))); + + // JSON: { "messageData": { "dataValue": 123 }, "strData": "blah" } + ow_->StartObject(""); + ow_->StartObject("messageData"); + ow_->RenderInt32("dataValue", 123); + ow_->EndObject(); + ow_->RenderString("strData", "blah"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForStructTypesPrimitiveFirstTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'structData'"))); + + // JSON: { "strData": "blah", "structData": { "a": "b" } } + ow_->StartObject(""); + ow_->RenderString("strData", "blah"); + ow_->StartObject("structData"); + ow_->RenderString("a", "b"); + ow_->EndObject(); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForStructTypesStructFirstTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'strData'"))); + + // JSON: { "structData": { "a": "b" }, "strData": "blah" } + ow_->StartObject(""); + ow_->StartObject("structData"); + ow_->RenderString("a", "b"); + ow_->EndObject(); + ow_->RenderString("strData", "blah"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForStructValueTypesTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'valueData'"))); + + // JSON: { "messageData": { "dataValue": 123 }, "valueData": { "a": "b" } } + ow_->StartObject(""); + ow_->StartObject("messageData"); + ow_->RenderInt32("dataValue", 123); + ow_->EndObject(); + ow_->StartObject("valueData"); + ow_->RenderString("a", "b"); + ow_->EndObject(); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForWellKnownTypesPrimitiveFirstTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'tsData'"))); + + // JSON: { "intData": 123, "tsData": "1970-01-02T01:00:00.000Z" } + ow_->StartObject(""); + ow_->RenderInt32("intData", 123); + ow_->RenderString("tsData", "1970-01-02T01:00:00.000Z"); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForWellKnownTypesWktFirstTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'intData'"))); + + // JSON: { "tsData": "1970-01-02T01:00:00.000Z", "intData": 123 } + ow_->StartObject(""); + ow_->RenderString("tsData", "1970-01-02T01:00:00.000Z"); + ow_->RenderInt32("intData", 123); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForWellKnownTypesAndMessageTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'messageData'"))); + + // JSON: { "tsData": "1970-01-02T01:00:00.000Z", + // "messageData": { "dataValue": 123 } } + ow_->StartObject(""); + ow_->RenderString("tsData", "1970-01-02T01:00:00.000Z"); + ow_->StartObject("messageData"); + ow_->RenderInt32("dataValue", 123); + ow_->EndObject(); + ow_->EndObject(); +} + +TEST_P(ProtoStreamObjectWriterOneOfsTest, + MultipleOneofsFailForOneofWithinAnyTest) { + EXPECT_CALL(listener_, InvalidValue(_, StringPiece("oneof"), + StringPiece( + "oneof field 'data' is already set. " + "Cannot set 'intData'"))); + + // JSON: + // { "anyData": + // { "@type": + // "type.googleapis.com/proto_util_converter.testing.oneofs.OneOfsRequest", + // "strData": "blah", + // "intData": 123 + // } + // } + ow_->StartObject(""); + ow_->StartObject("anyData"); + ow_->RenderString( + "@type", + "type.googleapis.com/proto_util_converter.testing.oneofs.OneOfsRequest"); + ow_->RenderString("strData", "blah"); + ow_->RenderInt32("intData", 123); + ow_->EndObject(); + ow_->EndObject(); +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h b/libs/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h new file mode 100644 index 0000000..f6f7c89 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h @@ -0,0 +1,121 @@ +// 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_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__ + +#include + +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +// An StructuredObjectWriter is an ObjectWriter for writing +// tree-structured data in a stream of events representing objects +// and collections. Implementation of this interface can be used to +// write an object stream to an in-memory structure, protobufs, +// JSON, XML, or any other output format desired. The ObjectSource +// interface is typically used as the source of an object stream. +// +// See JsonObjectWriter for a sample implementation of +// StructuredObjectWriter and its use. +// +// Derived classes could be thread-unsafe. +class PROTOBUF_EXPORT StructuredObjectWriter : public ObjectWriter { + public: + ~StructuredObjectWriter() override {} + + protected: + // A base element class for subclasses to extend, makes tracking state easier. + // + // StructuredObjectWriter behaves as a visitor. BaseElement represents a node + // in the input tree. Implementation of StructuredObjectWriter should also + // extend BaseElement to keep track of the location in the input tree. + class PROTOBUF_EXPORT BaseElement { + public: + // Takes ownership of the parent Element. + explicit BaseElement(BaseElement* parent) + : parent_(parent), + level_(parent == nullptr ? 0 : parent->level() + 1) {} + virtual ~BaseElement() {} + + // Releases ownership of the parent and returns a pointer to it. + template + ElementType* pop() { + return down_cast(parent_.release()); + } + + // Returns true if this element is the root. + bool is_root() const { return parent_ == nullptr; } + + // Returns the number of hops from this element to the root element. + int level() const { return level_; } + + protected: + // Returns pointer to parent element without releasing ownership. + virtual BaseElement* parent() const { return parent_.get(); } + + private: + // Pointer to the parent Element. + std::unique_ptr parent_; + + // Number of hops to the root Element. + // The root Element has nullptr parent_ and a level_ of 0. + const int level_; + + GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(BaseElement); + }; + + StructuredObjectWriter() {} + + // Returns the current element. Used for indentation and name overrides. + virtual BaseElement* element() = 0; + + private: + // Do not add any data members to this class. + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StructuredObjectWriter); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_STRUCTURED_OBJECTWRITER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/anys.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/anys.proto new file mode 100644 index 0000000..b6fc3f6 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/anys.proto @@ -0,0 +1,118 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +// Top-level test cases proto used by MarshallingTest. See description +// at the top of the class MarshallingTest for details on how to write +// test cases. +message AnyTestCases { + AnyWrapper empty_any = 1; + AnyWrapper type_only_any = 2; + AnyWrapper wrapper_any = 3; + AnyWrapper any_with_timestamp_value = 4; + AnyWrapper any_with_duration_value = 5; + AnyWrapper any_with_struct_value = 6; + AnyWrapper recursive_any = 7; + AnyWrapper any_with_message_value = 8; + AnyWrapper any_with_nested_message = 9; + AnyWrapper any_with_message_with_wrapper_type = 10; + AnyWrapper any_with_message_with_timestamp = 11; + AnyWrapper any_with_message_containing_map = 12; + AnyWrapper any_with_message_containing_struct = 13; + AnyWrapper any_with_message_containing_repeated_message = 14; + AnyWrapper recursive_any_with_type_field_at_end = 15; + AnyWrapper repeated_any = 16; + AnyWrapper empty_any_with_null_type_url = 17; + AnyWrapper any_with_empty = 18; + AnyWrapper any_with_default_timestamp = 19; + + google.protobuf.Any top_level_any = 50; + google.protobuf.Any top_level_any_with_type_field_at_end = 51; + google.protobuf.Any top_level_any_with_pivot_one = 52; + google.protobuf.Any top_level_any_with_pivot_two = 53; + google.protobuf.Any top_level_any_unordered = 54; +} + +message AnyWrapper { + google.protobuf.Any any = 1; +} + +// Hack to make sure the types we put into the any are included in the types. +// Real solution is to add these types to the service config. +message Imports { + google.protobuf.DoubleValue dbl = 1; + google.protobuf.Struct struct = 2; + google.protobuf.Timestamp timestamp = 3; + google.protobuf.Duration duration = 4; + google.protobuf.Int32Value i32 = 5; + google.protobuf.Empty empty = 6; + Data data = 100; +} + +message Data { + int32 attr = 1; + string str = 2; + repeated string msgs = 3; + Data nested_data = 4; + google.protobuf.Int32Value int_wrapper = 5; + google.protobuf.Timestamp time = 6; + map map_data = 7; + google.protobuf.Struct struct_data = 8; + repeated Data repeated_data = 9; + repeated google.protobuf.Any repeated_any = 10; +} + +service AnyTestService { + rpc Call(AnyTestCases) returns (AnyTestCases); + rpc Call1(Imports) returns (Imports); +} + +message AnyIn { + string something = 1; + google.protobuf.Any any = 2; +} + +message AnyOut { + google.protobuf.Any any = 1; +} + +message AnyM { + string foo = 1; +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/books.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/books.proto new file mode 100644 index 0000000..328c5ce --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/books.proto @@ -0,0 +1,251 @@ +// 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. + +// Author: sven@google.com (Sven Mawson) +// +// Sample protos for testing. + +// Some of the older enums don't use CAPITALS_WITH_UNDERSCORES for testing. +// LINT: LEGACY_NAMES +// LINT: ALLOW_GROUPS + +syntax = "proto2"; + +package proto_util_converter.testing; + +import "google/protobuf/util/internal/testdata/anys.proto"; + +// A book +message Book { + optional string title = 1; + optional Author author = 2; + optional uint32 length = 3; + optional int64 published = 4; + optional bytes content = 5; + + optional group Data = 6 { + optional uint32 year = 7; + optional string copyright = 8; + } + + message Label { + optional string key = 1; + optional string value = 2; + } + + optional Publisher publisher = 9; + repeated Label labels = 10; + + enum Type { + FICTION = 1; + KIDS = 2; + ACTION_AND_ADVENTURE = 3; + arts_and_photography = 4; + I18N_Tech = 5; + } + optional Type type = 11; + + // Useful for testing JSON snake/camel-case conversions. + optional string snake_field = 12; + + // Used to test type not found in type info. Messages defined in other files + // are not added when adding Book to type info. + optional AnyWrapper type_not_found = 13; + + // Used to test invalid value inside of primitive repeated fields. + repeated int32 primitive_repeated = 14; + + extensions 200 to 499; +} + +// A publisher of a book, tests required fields. +message Publisher { + required string name = 1; +} + +// An author of a book +message Author { + optional uint64 id = 1 [json_name = "@id"]; + optional string name = 2; + repeated string pseudonym = 3; + optional bool alive = 4; + repeated Author friend = 5; +} + +// For testing resiliency of our protostream parser. +// Field numbers of Author are reused for something else. +message BadAuthor { + optional string id = 1; // non-length-delimited to length-delimited. + repeated uint64 name = 2; // string to repeated (both length-delimited). + optional string pseudonym = 3; // Repeated to optional. + repeated bool alive = 4 [packed = true]; // Optional to repeated. +} + +// All primitive types +message Primitive { + // 32 bit numbers: + optional fixed32 fix32 = 1; + optional uint32 u32 = 2; + optional int32 i32 = 3; + optional sfixed32 sf32 = 4; + optional sint32 s32 = 5; + + // 64 bit numbers: + optional fixed64 fix64 = 6; + optional uint64 u64 = 7; + optional int64 i64 = 8; + optional sfixed64 sf64 = 9; + optional sint64 s64 = 10; + + // The other stuff. + optional string str = 11; + optional bytes bytes = 12; + optional float float = 13; + optional double double = 14; + optional bool bool = 15; + + // repeated 32 bit numbers: + repeated fixed32 rep_fix32 = 16; + repeated uint32 rep_u32 = 17; + repeated int32 rep_i32 = 18; + repeated sfixed32 rep_sf32 = 19; + repeated sint32 rep_s32 = 20; + + // repeated 64 bit numbers: + repeated fixed64 rep_fix64 = 21; + repeated uint64 rep_u64 = 22; + repeated int64 rep_i64 = 23; + repeated sfixed64 rep_sf64 = 24; + repeated sint64 rep_s64 = 25; + + // repeated other stuff: + repeated string rep_str = 26; + repeated bytes rep_bytes = 27; + repeated float rep_float = 28; + repeated double rep_double = 29; + repeated bool rep_bool = 30; +} + +// Test packed versions of all repeated primitives. +// The field numbers should match their non-packed version in Primitive message. +message PackedPrimitive { + // repeated 32 bit numbers: + repeated fixed32 rep_fix32 = 16 [packed = true]; + repeated uint32 rep_u32 = 17 [packed = true]; + repeated int32 rep_i32 = 18 [packed = true]; + repeated sfixed32 rep_sf32 = 19 [packed = true]; + repeated sint32 rep_s32 = 20 [packed = true]; + + // repeated 64 bit numbers: + repeated fixed64 rep_fix64 = 21 [packed = true]; + repeated uint64 rep_u64 = 22 [packed = true]; + repeated int64 rep_i64 = 23 [packed = true]; + repeated sfixed64 rep_sf64 = 24 [packed = true]; + repeated sint64 rep_s64 = 25 [packed = true]; + + // repeated other stuff: + repeated float rep_float = 28 [packed = true]; + repeated double rep_double = 29 [packed = true]; + repeated bool rep_bool = 30 [packed = true]; +} + +// Test extensions. +extend Book { + repeated Author more_author = 201; +} + +// Test nested extensions. +message NestedBook { + extend Book { + optional NestedBook another_book = 301; + } + // Recurse + optional Book book = 1; +} + +// For testing resiliency of our protostream parser. +// Field number of NestedBook is reused for something else. +message BadNestedBook { + repeated uint32 book = 1 [packed = true]; // Packed to optional message. +} + +// A recursively defined message. +message Cyclic { + optional int32 m_int = 1; + optional string m_str = 2; + optional Book m_book = 3; + repeated Author m_author = 5; + optional Cyclic m_cyclic = 4; +} + +// Test that two messages can have different fields mapped to the same JSON +// name. See: https://github.com/protocolbuffers/protobuf/issues/1415 +message TestJsonName1 { + optional int32 one_value = 1 [json_name = "value"]; +} +message TestJsonName2 { + optional int32 another_value = 1 [json_name = "value"]; +} + +message TestPrimitiveFieldsWithSameJsonName { + optional string val_str1 = 1; + optional string val_str_1 = 2; + + optional int32 val_int321 = 3; + optional int32 val_int32_1 = 4; + + optional uint32 val_uint321 = 5; + optional uint32 val_uint32_1 = 6; + + optional int64 val_int641 = 7; + optional int64 val_int64_1 = 8; + + optional uint64 val_uint641 = 9; + optional uint64 val_uint64_1 = 10; + + optional bool val_bool1 = 11; + optional bool val_bool_1 = 12; + + optional double val_double1 = 13; + optional double val_double_1 = 14; + + optional float val_float1 = 15; + optional float val_float_1 = 16; +} + +message TestRepeatedFieldsWithSameJsonName { + repeated string rep_str1 = 1; + repeated string rep_str_1 = 2; +} + +message TestMessageFieldsWithSameJsonName { + optional Primitive prim1 = 1; + optional Primitive prim_1 = 2; +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto new file mode 100644 index 0000000..79ce144 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto @@ -0,0 +1,170 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/any.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/wrappers.proto"; + +message DefaultValueTestCases { + DoubleMessage empty_double = 1; + DoubleMessage double_with_default_value = 2; + DoubleMessage double_with_nondefault_value = 3; + DoubleMessage repeated_double = 4; + DoubleMessage nested_message = 5; + DoubleMessage repeated_nested_message = 6; + DoubleMessage double_message_with_oneof = 7; + StructMessage empty_struct = 201; + StructMessage empty_struct2 = 202; + StructMessage struct_with_null_value = 203; + StructMessage struct_with_values = 204; + StructMessage struct_with_nested_struct = 205; + StructMessage struct_with_nested_list = 206; + StructMessage struct_with_list_of_nulls = 207; + StructMessage struct_with_list_of_lists = 208; + StructMessage struct_with_list_of_structs = 209; + google.protobuf.Struct top_level_struct = 210; + ValueMessage value_wrapper_simple = 212; + ValueMessage value_wrapper_with_struct = 213; + ValueMessage value_wrapper_with_list = 214; + ListValueMessage list_value_wrapper = 215; + google.protobuf.Value top_level_value_simple = 216; + google.protobuf.Value top_level_value_with_struct = 217; + google.protobuf.Value top_level_value_with_list = 218; + google.protobuf.ListValue top_level_listvalue = 219; + AnyMessage empty_any = 301; + AnyMessage type_only_any = 302; + AnyMessage recursive_any = 303; + AnyMessage any_with_message_value = 304; + AnyMessage any_with_nested_message = 305; + AnyMessage any_with_message_containing_map = 306; + AnyMessage any_with_message_containing_struct = 307; + google.protobuf.Any top_level_any = 308; + StringtoIntMap empty_map = 401; + StringtoIntMap string_to_int = 402; + IntToStringMap int_to_string = 403; + MixedMap mixed1 = 404; + MixedMap2 mixed2 = 405; + MixedMap2 empty_mixed2 = 406; + MessageMap map_of_objects = 407; + MixedMap mixed_empty = 408; + MessageMap message_map_empty = 409; + DoubleValueMessage double_value = 501; + DoubleValueMessage double_value_default = 502; +} + +message DoubleMessage { + double double_value = 1; + repeated double repeated_double = 2; + DoubleMessage nested_message = 3; + repeated DoubleMessage repeated_nested_message = 4; + google.protobuf.DoubleValue double_wrapper = 100; + oneof value { + string str_value = 112; + int64 num_value = 113; + } +} + +message StructMessage { + google.protobuf.Struct struct = 1; +} + +message ValueMessage { + google.protobuf.Value value = 1; +} + +message ListValueMessage { + google.protobuf.ListValue shopping_list = 1; +} +message RequestMessage { + string content = 1; +} + +// A test service. +service DefaultValueTestService { + // A test method. + rpc Call(RequestMessage) returns (DefaultValueTestCases); +} + +message AnyMessage { + google.protobuf.Any any = 1; + AnyData data = 2; +} + +message AnyData { + int32 attr = 1; + string str = 2; + repeated string msgs = 3; + AnyData nested_data = 4; + map map_data = 7; + google.protobuf.Struct struct_data = 8; + repeated AnyData repeated_data = 9; +} + +message StringtoIntMap { + map map = 1; +} + +message IntToStringMap { + map map = 1; +} + +message MixedMap { + string msg = 1; + map map = 2; + int32 int_value = 3; +} + +message MixedMap2 { + enum E { + E0 = 0; + E1 = 1; + E2 = 2; + E3 = 3; + } + map map = 1; + E ee = 2; + string msg = 4; +} + +message MessageMap { + message M { + int32 inner_int = 1; + string inner_text = 2; + } + map map = 1; +} + +message DoubleValueMessage { + google.protobuf.DoubleValue double = 1; +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto new file mode 100644 index 0000000..af755d3 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto @@ -0,0 +1,53 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +message DefaultValueTest { + double double_value = 1; + repeated double repeated_double = 2; + float float_value = 3; + int64 int64_value = 5; + uint64 uint64_value = 7; + int32 int32_value = 9; + uint32 uint32_value = 11; + bool bool_value = 13; + string string_value = 15; + bytes bytes_value = 17 [ctype = CORD]; + + enum EnumDefault { + ENUM_FIRST = 0; + ENUM_SECOND = 1; + ENUM_THIRD = 2; + } + EnumDefault enum_value = 18; +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto new file mode 100644 index 0000000..9d2bc40 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto @@ -0,0 +1,71 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/field_mask.proto"; + +message NestedFieldMask { + string data = 1; + google.protobuf.FieldMask single_mask = 2; + repeated google.protobuf.FieldMask repeated_mask = 3; +} + +message FieldMaskTest { + string id = 1; + google.protobuf.FieldMask single_mask = 2; + repeated google.protobuf.FieldMask repeated_mask = 3; + repeated NestedFieldMask nested_mask = 4; +} + +message FieldMaskTestCases { + FieldMaskWrapper single_mask = 1; + FieldMaskWrapper multiple_mask = 2; + FieldMaskWrapper snake_camel = 3; + FieldMaskWrapper empty_field = 4; + FieldMaskWrapper apiary_format1 = 5; + FieldMaskWrapper apiary_format2 = 6; + FieldMaskWrapper apiary_format3 = 7; + FieldMaskWrapper map_key1 = 8; + FieldMaskWrapper map_key2 = 9; + FieldMaskWrapper map_key3 = 10; + FieldMaskWrapper map_key4 = 11; + FieldMaskWrapper map_key5 = 12; +} + +message FieldMaskWrapper { + google.protobuf.FieldMask mask = 1; +} + +service FieldMaskTestService { + rpc Call(FieldMaskTestCases) returns (FieldMaskTestCases); +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/maps.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/maps.proto new file mode 100644 index 0000000..a9fdbe6 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/maps.proto @@ -0,0 +1,148 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/any.proto"; + +// Top-level test cases proto used by MarshallingTest. See description +// at the top of the class MarshallingTest for details on how to write +// test cases. +message MapsTestCases { + EmptyMap empty_map = 1; + StringtoInt string_to_int = 2; + IntToString int_to_string = 3; + Mixed1 mixed1 = 4; + Mixed2 mixed2 = 5; + MapOfObjects map_of_objects = 6; + + // Empty key tests + StringtoInt empty_key_string_to_int1 = 7; + StringtoInt empty_key_string_to_int2 = 8; + StringtoInt empty_key_string_to_int3 = 9; + BoolToString empty_key_bool_to_string = 10; + IntToString empty_key_int_to_string = 11; + Mixed1 empty_key_mixed = 12; + MapOfObjects empty_key_map_objects = 13; +} + +message EmptyMap { + map map = 1; +} + +message StringtoInt { + map map = 1; +} + +message IntToString { + map map = 1; +} + +message BoolToString { + map map = 1; +} + +message Mixed1 { + string msg = 1; + map map = 2; +} + +message Mixed2 { + enum E { + E0 = 0; + E1 = 1; + E2 = 2; + E3 = 3; + } + map map = 1; + E ee = 2; +} + +message MapOfObjects { + message M { + string inner_text = 1; + } + map map = 1; +} + +message DummyRequest {} + +service MapsTestService { + rpc Call(DummyRequest) returns (MapsTestCases); +} + +message MapIn { + string other = 1; + repeated string things = 2; + map map_input = 3; + map map_any = 4; +} + +message MapOut { + map map1 = 1; + map map2 = 2; + map map3 = 3; + map map4 = 5; + string bar = 4; +} + +// A message with exactly the same wire representation as MapOut, but using +// repeated message fields instead of map fields. We use this message to test +// the wire-format compatibility of the JSON transcoder (e.g., whether it +// handles missing keys correctly). +message MapOutWireFormat { + message Map1Entry { + string key = 1; + MapM value = 2; + } + repeated Map1Entry map1 = 1; + message Map2Entry { + string key = 1; + MapOut value = 2; + } + repeated Map2Entry map2 = 2; + message Map3Entry { + int32 key = 1; + string value = 2; + } + repeated Map3Entry map3 = 3; + message Map4Entry { + bool key = 1; + string value = 2; + } + repeated Map4Entry map4 = 5; + string bar = 4; +} + +message MapM { + string foo = 1; +} diff --git a/libs/protobuf/objectivec/Tests/unittest_preserve_unknown_enum.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto similarity index 64% rename from libs/protobuf/objectivec/Tests/unittest_preserve_unknown_enum.proto rename to libs/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto index 8cdd58d..7706af0 100644 --- a/libs/protobuf/objectivec/Tests/unittest_preserve_unknown_enum.proto +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto @@ -28,42 +28,50 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// Proto to test proto3 oneofs. syntax = "proto3"; -package objc.protobuf.tests.proto3_preserve_unknown_enum; -option objc_class_prefix = "UnknownEnums"; +package proto_util_converter.testing.oneofs; -enum MyEnum { - FOO = 0; - BAR = 1; - BAZ = 2; +import "google/protobuf/any.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; + +message OneOfsRequest { + string value = 1; + oneof data { + string str_data = 2; + int32 int_data = 3; + // Simple message + Data message_data = 4; + MoreData more_data = 5; + // Well known types + google.protobuf.Struct struct_data = 6; + google.protobuf.Value value_data = 7; + google.protobuf.ListValue list_value_data = 8; + google.protobuf.Timestamp ts_data = 9; + } + google.protobuf.Any any_data = 19; } -enum MyEnumPlusExtra { - E_FOO = 0; - E_BAR = 1; - E_BAZ = 2; - E_EXTRA = 3; -} - -message MyMessage { - MyEnum e = 1; - repeated MyEnum repeated_e = 2; - repeated MyEnum repeated_packed_e = 3 [packed=true]; - repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4; // not packed - oneof o { - MyEnum oneof_e_1 = 5; - MyEnum oneof_e_2 = 6; +message RequestWithSimpleOneof { + string value = 1; + oneof data { + string str_data = 2; + int32 int_data = 3; + Data message_data = 4; + MoreData more_data = 5; } } -message MyMessagePlusExtra { - MyEnumPlusExtra e = 1; - repeated MyEnumPlusExtra repeated_e = 2; - repeated MyEnumPlusExtra repeated_packed_e = 3 [packed=true]; - repeated MyEnumPlusExtra repeated_packed_unexpected_e = 4 [packed=true]; - oneof o { - MyEnumPlusExtra oneof_e_1 = 5; - MyEnumPlusExtra oneof_e_2 = 6; - } +message Data { + int32 data_value = 1; +} + +message MoreData { + string str_value = 1; +} + +message Response { + string value = 1; } diff --git a/libs/protobuf/objectivec/Tests/unittest_import_public.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto similarity index 89% rename from libs/protobuf/objectivec/Tests/unittest_import_public.proto rename to libs/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto index 05969b6..01434b0 100644 --- a/libs/protobuf/objectivec/Tests/unittest_import_public.proto +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto @@ -28,14 +28,15 @@ // (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: liujisi@google.com (Pherl Liu) +syntax = "proto3"; -syntax = "proto2"; +package proto_util_converter.testing; -package objc.protobuf.tests.public_import; - -option objc_class_prefix = "PublicImport"; - -message Message { - optional int32 e = 1; +message Proto3Message { + enum NestedEnum { + FOO = 0; + BAR = 1; + BAZ = 2; + } + NestedEnum enum_value = 1; } diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/struct.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/struct.proto new file mode 100644 index 0000000..a50ea87 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/struct.proto @@ -0,0 +1,117 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/struct.proto"; + +message StructTestCases { + StructWrapper empty_value = 1; + StructWrapper empty_value2 = 2; + StructWrapper null_value = 3; + StructWrapper simple_struct = 4; + StructWrapper longer_struct = 5; + StructWrapper struct_with_nested_struct = 6; + StructWrapper struct_with_nested_list = 7; + StructWrapper struct_with_list_of_nulls = 8; + StructWrapper struct_with_list_of_lists = 9; + StructWrapper struct_with_list_of_structs = 10; + StructWrapper struct_with_empty_list = 11; + StructWrapper struct_with_list_with_empty_struct = 12; + google.protobuf.Struct top_level_struct = 13; + google.protobuf.Struct top_level_struct_with_empty_list = 14; + google.protobuf.Struct top_level_struct_with_list_with_empty_struct = 15; + ValueWrapper value_wrapper_simple = 16; + ValueWrapper value_wrapper_with_struct = 17; + ValueWrapper value_wrapper_with_list = 18; + ValueWrapper value_wrapper_with_empty_list = 19; + ValueWrapper value_wrapper_with_list_with_empty_struct = 20; + ListValueWrapper list_value_wrapper = 21; + ListValueWrapper list_value_wrapper_with_empty_list = 22; + ListValueWrapper list_value_wrapper_with_list_with_empty_struct = 23; + google.protobuf.Value top_level_value_simple = 24; + google.protobuf.Value top_level_value_with_struct = 25; + google.protobuf.Value top_level_value_with_list = 26; + google.protobuf.Value top_level_value_with_empty_list = 27; + google.protobuf.Value top_level_value_with_list_with_empty_struct = 28; + google.protobuf.ListValue top_level_listvalue = 29; + google.protobuf.ListValue top_level_empty_listvalue = 30; + google.protobuf.ListValue top_level_listvalue_with_empty_struct = 31; + RepeatedValueWrapper repeated_value = 32; + RepeatedValueWrapper repeated_value_nested_list = 33; + RepeatedValueWrapper repeated_value_nested_list2 = 34; + RepeatedValueWrapper repeated_value_nested_list3 = 35; + RepeatedListValueWrapper repeated_listvalue = 36; + MapOfStruct map_of_struct = 37; + MapOfStruct map_of_struct_value = 38; + MapOfStruct map_of_listvalue = 39; +} + +message StructWrapper { + google.protobuf.Struct struct = 1; +} + +message ValueWrapper { + google.protobuf.Value value = 1; +} + +message RepeatedValueWrapper { + repeated google.protobuf.Value values = 1; +} + +message ListValueWrapper { + google.protobuf.ListValue shopping_list = 1; +} + +message RepeatedListValueWrapper { + repeated google.protobuf.ListValue dimensions = 1; +} + +message MapOfStruct { + map struct_map = 1; + map value_map = 2; + map listvalue_map = 3; +} + +// Hack to test return types with Struct as top-level message. Struct typers +// cannot be directly used in API requests. Hence using Dummy as request type. +message Dummy { + string text = 1; +} + +service StructTestService { + rpc Call(Dummy) returns (StructTestCases); +} + +message StructType { + google.protobuf.Struct object = 1; +} diff --git a/libs/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto new file mode 100644 index 0000000..8e87bdd --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto @@ -0,0 +1,80 @@ +// 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. + +syntax = "proto3"; + +package proto_util_converter.testing; + +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + +message TimestampDurationTestCases { + // Timestamp tests + TimeStampType epoch = 1; + TimeStampType epoch2 = 2; + TimeStampType mintime = 3; + TimeStampType maxtime = 4; + TimeStampType timeval1 = 5; + TimeStampType timeval2 = 6; + TimeStampType timeval3 = 7; + TimeStampType timeval4 = 8; + TimeStampType timeval5 = 9; + TimeStampType timeval6 = 10; + TimeStampType timeval7 = 11; + google.protobuf.Timestamp timeval8 = 12; + + // Duration tests + DurationType zero_duration = 101; + DurationType min_duration = 102; + DurationType max_duration = 103; + DurationType duration1 = 104; + DurationType duration2 = 105; + DurationType duration3 = 106; + DurationType duration4 = 107; + google.protobuf.Duration duration5 = 108; +} + +message TimeStampType { + google.protobuf.Timestamp timestamp = 1; +} + +message DurationType { + google.protobuf.Duration duration = 1; +} + +service TimestampDurationTestService { + rpc Call(TimestampDurationTestCases) returns (TimestampDurationTestCases); +} + +message TimestampDuration { + google.protobuf.Timestamp ts = 1; + google.protobuf.Duration dur = 2; + repeated google.protobuf.Timestamp rep_ts = 3; +} diff --git a/libs/protobuf/objectivec/Tests/map_proto2_unittest.proto b/libs/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto similarity index 50% rename from libs/protobuf/objectivec/Tests/map_proto2_unittest.proto rename to libs/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto index d7b494c..e7a0541 100644 --- a/libs/protobuf/objectivec/Tests/map_proto2_unittest.proto +++ b/libs/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto @@ -28,63 +28,73 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -syntax = "proto2"; +syntax = "proto3"; -import "objectivec/Tests/unittest_import.proto"; +package proto_util_converter.testing; -package objc.protobuf.tests; +import "google/protobuf/wrappers.proto"; -// Explicit empty prefix, tests some validations code paths also. -option objc_class_prefix = ""; +// Top-level test cases proto used by MarshallingTest. See description +// at the top of the class MarshallingTest for details on how to write +// test cases. +message WrappersTestCases { + DoubleWrapper double_wrapper = 1; + FloatWrapper float_wrapper = 2; + Int64Wrapper int64_wrapper = 3; + UInt64Wrapper uint64_wrapper = 4; + Int32Wrapper int32_wrapper = 5; + UInt32Wrapper uint32_wrapper = 6; + BoolWrapper bool_wrapper = 7; + StringWrapper string_wrapper = 8; + BytesWrapper bytes_wrapper = 9; -enum Proto2MapEnum { - PROTO2_MAP_ENUM_FOO = 0; - PROTO2_MAP_ENUM_BAR = 1; - PROTO2_MAP_ENUM_BAZ = 2; + DoubleWrapper double_wrapper_default = 10; + FloatWrapper float_wrapper_default = 11; + Int64Wrapper int64_wrapper_default = 12; + UInt64Wrapper uint64_wrapper_default = 13; + Int32Wrapper int32_wrapper_default = 14; + UInt32Wrapper uint32_wrapper_default = 15; + BoolWrapper bool_wrapper_default = 16; + StringWrapper string_wrapper_default = 17; + BytesWrapper bytes_wrapper_default = 18; } -enum Proto2MapEnumPlusExtra { - E_PROTO2_MAP_ENUM_FOO = 0; - E_PROTO2_MAP_ENUM_BAR = 1; - E_PROTO2_MAP_ENUM_BAZ = 2; - E_PROTO2_MAP_ENUM_EXTRA = 3; +message DoubleWrapper { + google.protobuf.DoubleValue double = 1; } -message TestEnumMap { - map known_map_field = 101; - map unknown_map_field = 102; +message FloatWrapper { + google.protobuf.FloatValue float = 1; } -message TestEnumMapPlusExtra { - map known_map_field = 101; - map unknown_map_field = 102; +message Int64Wrapper { + google.protobuf.Int64Value int64 = 1; } -message TestImportEnumMap { - map import_enum_amp = 1; +message UInt64Wrapper { + google.protobuf.UInt64Value uint64 = 1; } -message TestIntIntMap { - map m = 1; +message Int32Wrapper { + google.protobuf.Int32Value int32 = 1; } -// Test all key types: string, plus the non-floating-point scalars. -message TestMaps { - map m_int32 = 1; - map m_int64 = 2; - map m_uint32 = 3; - map m_uint64 = 4; - map m_sint32 = 5; - map m_sint64 = 6; - map m_fixed32 = 7; - map m_fixed64 = 8; - map m_sfixed32 = 9; - map m_sfixed64 = 10; - map m_bool = 11; - map m_string = 12; +message UInt32Wrapper { + google.protobuf.UInt32Value uint32 = 1; } -// Test maps in submessages. -message TestSubmessageMaps { - optional TestMaps m = 1; +message BoolWrapper { + google.protobuf.BoolValue bool = 1; +} + +message StringWrapper { + google.protobuf.StringValue string = 1; +} + +message BytesWrapper { + google.protobuf.BytesValue bytes = 1; +} + +service WrappersTestService { + rpc Call(WrappersTestCases) returns (WrappersTestCases); } diff --git a/libs/protobuf/src/google/protobuf/util/internal/type_info.cc b/libs/protobuf/src/google/protobuf/util/internal/type_info.cc new file mode 100644 index 0000000..b6cf536 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/type_info.cc @@ -0,0 +1,182 @@ +// 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +namespace { +// A TypeInfo that looks up information provided by a TypeResolver. +class TypeInfoForTypeResolver : public TypeInfo { + public: + explicit TypeInfoForTypeResolver(TypeResolver* type_resolver) + : type_resolver_(type_resolver) {} + + ~TypeInfoForTypeResolver() override { + DeleteCachedTypes(&cached_types_); + DeleteCachedTypes(&cached_enums_); + } + + util::StatusOr ResolveTypeUrl( + StringPiece type_url) const override { + std::map::iterator it = + cached_types_.find(type_url); + if (it != cached_types_.end()) { + return it->second; + } + // Stores the string value so it can be referenced using StringPiece in the + // cached_types_ map. + const std::string& string_type_url = + *string_storage_.insert(std::string(type_url)).first; + std::unique_ptr type(new google::protobuf::Type()); + util::Status status = + type_resolver_->ResolveMessageType(string_type_url, type.get()); + StatusOrType result = + status.ok() ? StatusOrType(type.release()) : StatusOrType(status); + cached_types_[string_type_url] = result; + return result; + } + + const google::protobuf::Type* GetTypeByTypeUrl( + StringPiece type_url) const override { + StatusOrType result = ResolveTypeUrl(type_url); + return result.ok() ? result.value() : NULL; + } + + const google::protobuf::Enum* GetEnumByTypeUrl( + StringPiece type_url) const override { + std::map::iterator it = + cached_enums_.find(type_url); + if (it != cached_enums_.end()) { + return it->second.ok() ? it->second.value() : NULL; + } + // Stores the string value so it can be referenced using StringPiece in the + // cached_enums_ map. + const std::string& string_type_url = + *string_storage_.insert(std::string(type_url)).first; + std::unique_ptr enum_type( + new google::protobuf::Enum()); + util::Status status = + type_resolver_->ResolveEnumType(string_type_url, enum_type.get()); + StatusOrEnum result = + status.ok() ? StatusOrEnum(enum_type.release()) : StatusOrEnum(status); + cached_enums_[string_type_url] = result; + return result.ok() ? result.value() : NULL; + } + + const google::protobuf::Field* FindField( + const google::protobuf::Type* type, + StringPiece camel_case_name) const override { + std::map::const_iterator + it = indexed_types_.find(type); + const CamelCaseNameTable& camel_case_name_table = + (it == indexed_types_.end()) + ? PopulateNameLookupTable(type, &indexed_types_[type]) + : it->second; + StringPiece name = FindWithDefault( + camel_case_name_table, camel_case_name, StringPiece()); + if (name.empty()) { + // Didn't find a mapping. Use whatever provided. + name = camel_case_name; + } + return FindFieldInTypeOrNull(type, name); + } + + private: + typedef util::StatusOr StatusOrType; + typedef util::StatusOr StatusOrEnum; + typedef std::map CamelCaseNameTable; + + template + static void DeleteCachedTypes(std::map* cached_types) { + for (typename std::map::iterator it = + cached_types->begin(); + it != cached_types->end(); ++it) { + if (it->second.ok()) { + delete it->second.value(); + } + } + } + + const CamelCaseNameTable& PopulateNameLookupTable( + const google::protobuf::Type* type, + CamelCaseNameTable* camel_case_name_table) const { + for (int i = 0; i < type->fields_size(); ++i) { + const google::protobuf::Field& field = type->fields(i); + StringPiece name = field.name(); + StringPiece camel_case_name = field.json_name(); + const StringPiece* existing = InsertOrReturnExisting( + camel_case_name_table, camel_case_name, name); + if (existing && *existing != name) { + GOOGLE_LOG(WARNING) << "Field '" << name << "' and '" << *existing + << "' map to the same camel case name '" << camel_case_name + << "'."; + } + } + return *camel_case_name_table; + } + + TypeResolver* type_resolver_; + + // Stores string values that will be referenced by StringPieces in + // cached_types_, cached_enums_. + mutable std::set string_storage_; + + mutable std::map cached_types_; + mutable std::map cached_enums_; + + mutable std::map + indexed_types_; +}; +} // namespace + +TypeInfo* TypeInfo::NewTypeInfo(TypeResolver* type_resolver) { + return new TypeInfoForTypeResolver(type_resolver); +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/type_info.h b/libs/protobuf/src/google/protobuf/util/internal/type_info.h new file mode 100644 index 0000000..257df5b --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/type_info.h @@ -0,0 +1,97 @@ +// 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_UTIL_INTERNAL_TYPE_INFO_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_H__ + +#include +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +// Internal helper class for type resolving. Note that this class is not +// thread-safe and should only be accessed in one thread. +class PROTOBUF_EXPORT TypeInfo { + public: + TypeInfo() {} + virtual ~TypeInfo() {} + + // Resolves a type url into a Type. If the type url is invalid, returns + // INVALID_ARGUMENT error status. If the type url is valid but the + // corresponding type cannot be found, returns a NOT_FOUND error status. + // + // This TypeInfo class retains the ownership of the returned pointer. + virtual util::StatusOr ResolveTypeUrl( + StringPiece type_url) const = 0; + + // Resolves a type url into a Type. Like ResolveTypeUrl() but returns + // NULL if the type url is invalid or the type cannot be found. + // + // This TypeInfo class retains the ownership of the returned pointer. + virtual const google::protobuf::Type* GetTypeByTypeUrl( + StringPiece type_url) const = 0; + + // Resolves a type url for an enum. Returns NULL if the type url is + // invalid or the type cannot be found. + // + // This TypeInfo class retains the ownership of the returned pointer. + virtual const google::protobuf::Enum* GetEnumByTypeUrl( + StringPiece type_url) const = 0; + + // Looks up a field in the specified type given a CamelCase name. + virtual const google::protobuf::Field* FindField( + const google::protobuf::Type* type, + StringPiece camel_case_name) const = 0; + + // Creates a TypeInfo object that looks up type information from a + // TypeResolver. Caller takes ownership of the returned pointer. + static TypeInfo* NewTypeInfo(TypeResolver* type_resolver); + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeInfo); +}; + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc b/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc new file mode 100644 index 0000000..088f412 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc @@ -0,0 +1,132 @@ +// 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +namespace testing { + + +void TypeInfoTestHelper::ResetTypeInfo( + const std::vector& descriptors) { + switch (type_) { + case USE_TYPE_RESOLVER: { + const DescriptorPool* pool = descriptors[0]->file()->pool(); + for (int i = 1; i < descriptors.size(); ++i) { + GOOGLE_CHECK(pool == descriptors[i]->file()->pool()) + << "Descriptors from different pools are not supported."; + } + type_resolver_.reset( + NewTypeResolverForDescriptorPool(kTypeServiceBaseUrl, pool)); + typeinfo_.reset(TypeInfo::NewTypeInfo(type_resolver_.get())); + return; + } + } + GOOGLE_LOG(FATAL) << "Can not reach here."; +} + +void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor) { + std::vector descriptors; + descriptors.push_back(descriptor); + ResetTypeInfo(descriptors); +} + +void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor1, + const Descriptor* descriptor2) { + std::vector descriptors; + descriptors.push_back(descriptor1); + descriptors.push_back(descriptor2); + ResetTypeInfo(descriptors); +} + +TypeInfo* TypeInfoTestHelper::GetTypeInfo() { return typeinfo_.get(); } + +ProtoStreamObjectSource* TypeInfoTestHelper::NewProtoSource( + io::CodedInputStream* coded_input, const std::string& type_url, + ProtoStreamObjectSource::RenderOptions render_options) { + const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(type_url); + switch (type_) { + case USE_TYPE_RESOLVER: { + return new ProtoStreamObjectSource(coded_input, type_resolver_.get(), + *type, render_options); + } + } + GOOGLE_LOG(FATAL) << "Can not reach here."; + return nullptr; +} + +ProtoStreamObjectWriter* TypeInfoTestHelper::NewProtoWriter( + const std::string& type_url, strings::ByteSink* output, + ErrorListener* listener, const ProtoStreamObjectWriter::Options& options) { + const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(type_url); + switch (type_) { + case USE_TYPE_RESOLVER: { + return new ProtoStreamObjectWriter(type_resolver_.get(), *type, output, + listener, options); + } + } + GOOGLE_LOG(FATAL) << "Can not reach here."; + return nullptr; +} + +DefaultValueObjectWriter* TypeInfoTestHelper::NewDefaultValueWriter( + const std::string& type_url, ObjectWriter* writer) { + const google::protobuf::Type* type = typeinfo_->GetTypeByTypeUrl(type_url); + switch (type_) { + case USE_TYPE_RESOLVER: { + return new DefaultValueObjectWriter(type_resolver_.get(), *type, writer); + } + } + GOOGLE_LOG(FATAL) << "Can not reach here."; + return nullptr; +} + +} // namespace testing +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h b/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h new file mode 100644 index 0000000..1110a34 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h @@ -0,0 +1,96 @@ +// 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_UTIL_INTERNAL_TYPE_INFO_TEST_HELPER_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_TEST_HELPER_H__ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { +namespace testing { + +enum TypeInfoSource { + USE_TYPE_RESOLVER, +}; + +// In the unit-tests we want to test two scenarios: one with type info from +// ServiceTypeInfo, the other with type info from TypeResolver. This class +// wraps the detail of where the type info is from and provides the same +// interface so the same unit-test code can test both scenarios. +class TypeInfoTestHelper { + public: + explicit TypeInfoTestHelper(TypeInfoSource type) : type_(type) {} + + // Creates a TypeInfo object for the given set of descriptors. + void ResetTypeInfo(const std::vector& descriptors); + + // Convenient overloads. + void ResetTypeInfo(const Descriptor* descriptor); + void ResetTypeInfo(const Descriptor* descriptor1, + const Descriptor* descriptor2); + + // Returns the TypeInfo created after ResetTypeInfo. + TypeInfo* GetTypeInfo(); + + ProtoStreamObjectSource* NewProtoSource( + io::CodedInputStream* coded_input, const std::string& type_url, + ProtoStreamObjectSource::RenderOptions render_options = {}); + + ProtoStreamObjectWriter* NewProtoWriter( + const std::string& type_url, strings::ByteSink* output, + ErrorListener* listener, const ProtoStreamObjectWriter::Options& options); + + DefaultValueObjectWriter* NewDefaultValueWriter(const std::string& type_url, + ObjectWriter* writer); + + private: + TypeInfoSource type_; + std::unique_ptr typeinfo_; + std::unique_ptr type_resolver_; +}; +} // namespace testing +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_TYPE_INFO_TEST_HELPER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/internal/utility.cc b/libs/protobuf/src/google/protobuf/util/internal/utility.cc new file mode 100644 index 0000000..918ee17 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/utility.cc @@ -0,0 +1,416 @@ +// 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 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// clang-format off +#include +// clang-format on + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +bool GetBoolOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, bool default_value) { + const google::protobuf::Option* opt = FindOptionOrNull(options, option_name); + if (opt == nullptr) { + return default_value; + } + return GetBoolFromAny(opt->value()); +} + +int64_t GetInt64OptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, int64_t default_value) { + const google::protobuf::Option* opt = FindOptionOrNull(options, option_name); + if (opt == nullptr) { + return default_value; + } + return GetInt64FromAny(opt->value()); +} + +double GetDoubleOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, double default_value) { + const google::protobuf::Option* opt = FindOptionOrNull(options, option_name); + if (opt == nullptr) { + return default_value; + } + return GetDoubleFromAny(opt->value()); +} + +std::string GetStringOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, StringPiece default_value) { + const google::protobuf::Option* opt = FindOptionOrNull(options, option_name); + if (opt == nullptr) { + return std::string(default_value); + } + return GetStringFromAny(opt->value()); +} + +template +void ParseFromAny(const std::string& data, T* result) { + result->ParseFromString(data); +} + +// Returns a boolean value contained in Any type. +// TODO(skarvaje): Add type checking & error messages here. +bool GetBoolFromAny(const google::protobuf::Any& any) { + google::protobuf::BoolValue b; + ParseFromAny(any.value(), &b); + return b.value(); +} + +int64_t GetInt64FromAny(const google::protobuf::Any& any) { + google::protobuf::Int64Value i; + ParseFromAny(any.value(), &i); + return i.value(); +} + +double GetDoubleFromAny(const google::protobuf::Any& any) { + google::protobuf::DoubleValue i; + ParseFromAny(any.value(), &i); + return i.value(); +} + +std::string GetStringFromAny(const google::protobuf::Any& any) { + google::protobuf::StringValue s; + ParseFromAny(any.value(), &s); + return s.value(); +} + +const StringPiece GetTypeWithoutUrl(StringPiece type_url) { + if (type_url.size() > kTypeUrlSize && type_url[kTypeUrlSize] == '/') { + return type_url.substr(kTypeUrlSize + 1); + } else { + size_t idx = type_url.rfind('/'); + if (idx != type_url.npos) { + type_url.remove_prefix(idx + 1); + } + return type_url; + } +} + +const std::string GetFullTypeWithUrl(StringPiece simple_type) { + return StrCat(kTypeServiceBaseUrl, "/", simple_type); +} + +const google::protobuf::Option* FindOptionOrNull( + const RepeatedPtrField& options, + StringPiece option_name) { + for (int i = 0; i < options.size(); ++i) { + const google::protobuf::Option& opt = options.Get(i); + if (opt.name() == option_name) { + return &opt; + } + } + return nullptr; +} + +const google::protobuf::Field* FindFieldInTypeOrNull( + const google::protobuf::Type* type, StringPiece field_name) { + if (type != nullptr) { + for (int i = 0; i < type->fields_size(); ++i) { + const google::protobuf::Field& field = type->fields(i); + if (field.name() == field_name) { + return &field; + } + } + } + return nullptr; +} + +const google::protobuf::Field* FindJsonFieldInTypeOrNull( + const google::protobuf::Type* type, StringPiece json_name) { + if (type != nullptr) { + for (int i = 0; i < type->fields_size(); ++i) { + const google::protobuf::Field& field = type->fields(i); + if (field.json_name() == json_name) { + return &field; + } + } + } + return nullptr; +} + +const google::protobuf::Field* FindFieldInTypeByNumberOrNull( + const google::protobuf::Type* type, int32_t number) { + if (type != nullptr) { + for (int i = 0; i < type->fields_size(); ++i) { + const google::protobuf::Field& field = type->fields(i); + if (field.number() == number) { + return &field; + } + } + } + return nullptr; +} + +const google::protobuf::EnumValue* FindEnumValueByNameOrNull( + const google::protobuf::Enum* enum_type, StringPiece enum_name) { + if (enum_type != nullptr) { + for (int i = 0; i < enum_type->enumvalue_size(); ++i) { + const google::protobuf::EnumValue& enum_value = enum_type->enumvalue(i); + if (enum_value.name() == enum_name) { + return &enum_value; + } + } + } + return nullptr; +} + +const google::protobuf::EnumValue* FindEnumValueByNumberOrNull( + const google::protobuf::Enum* enum_type, int32_t value) { + if (enum_type != nullptr) { + for (int i = 0; i < enum_type->enumvalue_size(); ++i) { + const google::protobuf::EnumValue& enum_value = enum_type->enumvalue(i); + if (enum_value.number() == value) { + return &enum_value; + } + } + } + return nullptr; +} + +const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull( + const google::protobuf::Enum* enum_type, StringPiece enum_name) { + if (enum_type != nullptr) { + for (int i = 0; i < enum_type->enumvalue_size(); ++i) { + const google::protobuf::EnumValue& enum_value = enum_type->enumvalue(i); + std::string enum_name_without_underscore = enum_value.name(); + + // Remove underscore from the name. + enum_name_without_underscore.erase( + std::remove(enum_name_without_underscore.begin(), + enum_name_without_underscore.end(), '_'), + enum_name_without_underscore.end()); + // Make the name uppercase. + for (std::string::iterator it = enum_name_without_underscore.begin(); + it != enum_name_without_underscore.end(); ++it) { + *it = ascii_toupper(*it); + } + + if (enum_name_without_underscore == enum_name) { + return &enum_value; + } + } + } + return nullptr; +} + +std::string EnumValueNameToLowerCamelCase(StringPiece input) { + std::string input_string(input); + std::transform(input_string.begin(), input_string.end(), input_string.begin(), + ::tolower); + return ToCamelCase(input_string); +} + +std::string ToCamelCase(StringPiece input) { + bool capitalize_next = false; + bool was_cap = true; + bool is_cap = false; + bool first_word = true; + std::string result; + result.reserve(input.size()); + + for (size_t i = 0; i < input.size(); ++i, was_cap = is_cap) { + is_cap = ascii_isupper(input[i]); + if (input[i] == '_') { + capitalize_next = true; + if (!result.empty()) first_word = false; + continue; + } else if (first_word) { + // Consider when the current character B is capitalized, + // first word ends when: + // 1) following a lowercase: "...aB..." + // 2) followed by a lowercase: "...ABc..." + if (!result.empty() && is_cap && + (!was_cap || + (i + 1 < input.size() && ascii_islower(input[i + 1])))) { + first_word = false; + result.push_back(input[i]); + } else { + result.push_back(ascii_tolower(input[i])); + continue; + } + } else if (capitalize_next) { + capitalize_next = false; + if (ascii_islower(input[i])) { + result.push_back(ascii_toupper(input[i])); + continue; + } else { + result.push_back(input[i]); + continue; + } + } else { + result.push_back(ascii_tolower(input[i])); + } + } + return result; +} + +std::string ToSnakeCase(StringPiece input) { + bool was_not_underscore = false; // Initialize to false for case 1 (below) + bool was_not_cap = false; + std::string result; + result.reserve(input.size() << 1); + + for (size_t i = 0; i < input.size(); ++i) { + if (ascii_isupper(input[i])) { + // Consider when the current character B is capitalized: + // 1) At beginning of input: "B..." => "b..." + // (e.g. "Biscuit" => "biscuit") + // 2) Following a lowercase: "...aB..." => "...a_b..." + // (e.g. "gBike" => "g_bike") + // 3) At the end of input: "...AB" => "...ab" + // (e.g. "GoogleLAB" => "google_lab") + // 4) Followed by a lowercase: "...ABc..." => "...a_bc..." + // (e.g. "GBike" => "g_bike") + if (was_not_underscore && // case 1 out + (was_not_cap || // case 2 in, case 3 out + (i + 1 < input.size() && // case 3 out + ascii_islower(input[i + 1])))) { // case 4 in + // We add an underscore for case 2 and case 4. + result.push_back('_'); + } + result.push_back(ascii_tolower(input[i])); + was_not_underscore = true; + was_not_cap = false; + } else { + result.push_back(input[i]); + was_not_underscore = input[i] != '_'; + was_not_cap = true; + } + } + return result; +} + +std::set* well_known_types_ = nullptr; +PROTOBUF_NAMESPACE_ID::internal::once_flag well_known_types_init_; +const char* well_known_types_name_array_[] = { + "google.protobuf.Timestamp", "google.protobuf.Duration", + "google.protobuf.DoubleValue", "google.protobuf.FloatValue", + "google.protobuf.Int64Value", "google.protobuf.UInt64Value", + "google.protobuf.Int32Value", "google.protobuf.UInt32Value", + "google.protobuf.BoolValue", "google.protobuf.StringValue", + "google.protobuf.BytesValue", "google.protobuf.FieldMask"}; + +void DeleteWellKnownTypes() { delete well_known_types_; } + +void InitWellKnownTypes() { + well_known_types_ = new std::set; + for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) { + well_known_types_->insert(well_known_types_name_array_[i]); + } + google::protobuf::internal::OnShutdown(&DeleteWellKnownTypes); +} + +bool IsWellKnownType(const std::string& type_name) { + PROTOBUF_NAMESPACE_ID::internal::call_once(well_known_types_init_, + InitWellKnownTypes); + return ContainsKey(*well_known_types_, type_name); +} + +bool IsValidBoolString(StringPiece bool_string) { + return bool_string == "true" || bool_string == "false" || + bool_string == "1" || bool_string == "0"; +} + +bool IsMap(const google::protobuf::Field& field, + const google::protobuf::Type& type) { + return field.cardinality() == google::protobuf::Field::CARDINALITY_REPEATED && + (GetBoolOptionOrDefault(type.options(), "map_entry", false) || + GetBoolOptionOrDefault(type.options(), + "google.protobuf.MessageOptions.map_entry", + false)); +} + +bool IsMessageSetWireFormat(const google::protobuf::Type& type) { + return GetBoolOptionOrDefault(type.options(), "message_set_wire_format", + false) || + GetBoolOptionOrDefault( + type.options(), + "google.protobuf.MessageOptions.message_set_wire_format", false); +} + +std::string DoubleAsString(double value) { + if (value == std::numeric_limits::infinity()) return "Infinity"; + if (value == -std::numeric_limits::infinity()) return "-Infinity"; + if (std::isnan(value)) return "NaN"; + + return SimpleDtoa(value); +} + +std::string FloatAsString(float value) { + if (std::isfinite(value)) return SimpleFtoa(value); + return DoubleAsString(value); +} + +bool SafeStrToFloat(StringPiece str, float* value) { + double double_value; + if (!safe_strtod(str, &double_value)) { + return false; + } + + if (std::isinf(double_value) || std::isnan(double_value)) return false; + + // Fail if the value is not representable in float. + if (double_value > std::numeric_limits::max() || + double_value < -std::numeric_limits::max()) { + return false; + } + + *value = static_cast(double_value); + return true; +} + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/internal/utility.h b/libs/protobuf/src/google/protobuf/util/internal/utility.h new file mode 100644 index 0000000..79d6779 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/internal/utility.h @@ -0,0 +1,204 @@ +// 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_UTIL_INTERNAL_UTILITY_H__ +#define GOOGLE_PROTOBUF_UTIL_INTERNAL_UTILITY_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +// Must be included last. +#include + +namespace google { +namespace protobuf { +namespace util { +namespace converter { + +// Size of "type.googleapis.com" +static const int64_t kTypeUrlSize = 19; + +// Finds the tech option identified by option_name. Parses the boolean value and +// returns it. +// When the option with the given name is not found, default_value is returned. +PROTOBUF_EXPORT bool GetBoolOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, bool default_value); + +// Returns int64 option value. If the option isn't found, returns the +// default_value. +PROTOBUF_EXPORT int64_t GetInt64OptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, int64_t default_value); + +// Returns double option value. If the option isn't found, returns the +// default_value. +PROTOBUF_EXPORT double GetDoubleOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, double default_value); + +// Returns string option value. If the option isn't found, returns the +// default_value. +PROTOBUF_EXPORT std::string GetStringOptionOrDefault( + const RepeatedPtrField& options, + StringPiece option_name, StringPiece default_value); + +// Returns a boolean value contained in Any type. +// TODO(skarvaje): Make these utilities dealing with Any types more generic, +// add more error checking and move to a more public/shareable location so +// others can use. +PROTOBUF_EXPORT bool GetBoolFromAny(const google::protobuf::Any& any); + +// Returns int64 value contained in Any type. +PROTOBUF_EXPORT int64_t GetInt64FromAny(const google::protobuf::Any& any); + +// Returns double value contained in Any type. +PROTOBUF_EXPORT double GetDoubleFromAny(const google::protobuf::Any& any); + +// Returns string value contained in Any type. +PROTOBUF_EXPORT std::string GetStringFromAny(const google::protobuf::Any& any); + +// Returns the type string without the url prefix. e.g.: If the passed type is +// 'type.googleapis.com/tech.type.Bool', the returned value is 'tech.type.Bool'. +PROTOBUF_EXPORT const StringPiece GetTypeWithoutUrl( + StringPiece type_url); + +// Returns the simple_type with the base type url (kTypeServiceBaseUrl) +// prefixed. +// +// E.g: +// GetFullTypeWithUrl("google.protobuf.Timestamp") returns the string +// "type.googleapis.com/google.protobuf.Timestamp". +PROTOBUF_EXPORT const std::string GetFullTypeWithUrl( + StringPiece simple_type); + +// Finds and returns option identified by name and option_name within the +// provided map. Returns nullptr if none found. +const google::protobuf::Option* FindOptionOrNull( + const RepeatedPtrField& options, + StringPiece option_name); + +// Finds and returns the field identified by field_name in the passed tech Type +// object. Returns nullptr if none found. +const google::protobuf::Field* FindFieldInTypeOrNull( + const google::protobuf::Type* type, StringPiece field_name); + +// Similar to FindFieldInTypeOrNull, but this looks up fields with given +// json_name. +const google::protobuf::Field* FindJsonFieldInTypeOrNull( + const google::protobuf::Type* type, StringPiece json_name); + +// Similar to FindFieldInTypeOrNull, but this looks up fields by number. +const google::protobuf::Field* FindFieldInTypeByNumberOrNull( + const google::protobuf::Type* type, int32_t number); + +// Finds and returns the EnumValue identified by enum_name in the passed tech +// Enum object. Returns nullptr if none found. +const google::protobuf::EnumValue* FindEnumValueByNameOrNull( + const google::protobuf::Enum* enum_type, StringPiece enum_name); + +// Finds and returns the EnumValue identified by value in the passed tech +// Enum object. Returns nullptr if none found. +const google::protobuf::EnumValue* FindEnumValueByNumberOrNull( + const google::protobuf::Enum* enum_type, int32_t value); + +// Finds and returns the EnumValue identified by enum_name without underscore in +// the passed tech Enum object. Returns nullptr if none found. +// For Ex. if enum_name is ACTIONANDADVENTURE it can get accepted if +// EnumValue's name is action_and_adventure or ACTION_AND_ADVENTURE. +const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull( + const google::protobuf::Enum* enum_type, StringPiece enum_name); + +// Converts input to camel-case and returns it. +PROTOBUF_EXPORT std::string ToCamelCase(const StringPiece input); + +// Converts enum name string to camel-case and returns it. +std::string EnumValueNameToLowerCamelCase(const StringPiece input); + +// Converts input to snake_case and returns it. +PROTOBUF_EXPORT std::string ToSnakeCase(StringPiece input); + +// Returns true if type_name represents a well-known type. +PROTOBUF_EXPORT bool IsWellKnownType(const std::string& type_name); + +// Returns true if 'bool_string' represents a valid boolean value. Only "true", +// "false", "0" and "1" are allowed. +PROTOBUF_EXPORT bool IsValidBoolString(StringPiece bool_string); + +// Returns true if "field" is a protobuf map field based on its type. +PROTOBUF_EXPORT bool IsMap(const google::protobuf::Field& field, + const google::protobuf::Type& type); + +// Returns true if the given type has special MessageSet wire format. +bool IsMessageSetWireFormat(const google::protobuf::Type& type); + +// Infinity/NaN-aware conversion to string. +PROTOBUF_EXPORT std::string DoubleAsString(double value); +PROTOBUF_EXPORT std::string FloatAsString(float value); + +// Convert from int32, int64, uint32, uint64, double or float to string. +template +std::string ValueAsString(T value) { + return StrCat(value); +} + +template <> +inline std::string ValueAsString(float value) { + return FloatAsString(value); +} + +template <> +inline std::string ValueAsString(double value) { + return DoubleAsString(value); +} + +// Converts a string to float. Unlike safe_strtof, conversion will fail if the +// value fits into double but not float (e.g., DBL_MAX). +PROTOBUF_EXPORT bool SafeStrToFloat(StringPiece str, float* value); + +} // namespace converter +} // namespace util +} // namespace protobuf +} // namespace google + +#include + +#endif // GOOGLE_PROTOBUF_UTIL_INTERNAL_UTILITY_H__ diff --git a/libs/protobuf/src/google/protobuf/util/json_format.proto b/libs/protobuf/src/google/protobuf/util/json_format.proto index a2703ce..7b7100d 100644 --- a/libs/protobuf/src/google/protobuf/util/json_format.proto +++ b/libs/protobuf/src/google/protobuf/util/json_format.proto @@ -38,9 +38,6 @@ syntax = "proto2"; package protobuf_unittest; -import "google/protobuf/any.proto"; -import "google/protobuf/struct.proto"; - message TestFlagsAndStrings { required int32 A = 1; repeated group RepeatedGroup = 2 { @@ -95,6 +92,7 @@ message TestNumbers { optional uint32 f = 6; } + message TestCamelCase { optional string normal_field = 1; optional int32 CAPITAL_FIELD = 2; diff --git a/libs/protobuf/src/google/protobuf/util/json_format_proto3.proto b/libs/protobuf/src/google/protobuf/util/json_format_proto3.proto index 62c2316..0eec9da 100644 --- a/libs/protobuf/src/google/protobuf/util/json_format_proto3.proto +++ b/libs/protobuf/src/google/protobuf/util/json_format_proto3.proto @@ -46,7 +46,6 @@ option java_outer_classname = "JsonFormatProto3"; enum EnumType { FOO = 0; BAR = 1; - TLSv1_2 = 2; } message MessageType { @@ -180,23 +179,10 @@ message TestBoolValue { map bool_map = 2; } -message TestNullValue { - google.protobuf.NullValue null_value = 20; - repeated google.protobuf.NullValue repeated_null_value = 21; -} - message TestCustomJsonName { int32 value = 1 [json_name = "@value"]; } -message TestEvilJson { - int32 regular_value = 1 [json_name = "regular_name"]; - int32 script = 2 [json_name = ""]; - int32 quotes = 3 [json_name = "unbalanced\"quotes"]; - int32 script_and_quotes = 4 - [json_name = "\""]; -} - message TestExtensions { .protobuf_unittest.TestAllExtensions extensions = 1; } @@ -206,107 +192,3 @@ message TestEnumValue { EnumType enum_value2 = 2; EnumType enum_value3 = 3; } - -message MapsTestCases { - EmptyMap empty_map = 1; - StringtoInt string_to_int = 2; - IntToString int_to_string = 3; - Mixed1 mixed1 = 4; - Mixed2 mixed2 = 5; - MapOfObjects map_of_objects = 6; - - // Empty key tests - StringtoInt empty_key_string_to_int1 = 7; - StringtoInt empty_key_string_to_int2 = 8; - StringtoInt empty_key_string_to_int3 = 9; - BoolToString empty_key_bool_to_string = 10; - IntToString empty_key_int_to_string = 11; - Mixed1 empty_key_mixed = 12; - MapOfObjects empty_key_map_objects = 13; -} - -message EmptyMap { - map map = 1; -} - -message StringtoInt { - map map = 1; -} - -message IntToString { - map map = 1; -} - -message BoolToString { - map map = 1; -} - -message Mixed1 { - string msg = 1; - map map = 2; -} - -message Mixed2 { - enum E { - E0 = 0; - E1 = 1; - E2 = 2; - E3 = 3; - } - map map = 1; - E ee = 2; -} - -message MapOfObjects { - message M { - string inner_text = 1; - } - map map = 1; -} - -message MapIn { - string other = 1; - repeated string things = 2; - map map_input = 3; - map map_any = 4; -} - -message MapOut { - map map1 = 1; - map map2 = 2; - map map3 = 3; - map map4 = 5; - string bar = 4; -} - -// A message with exactly the same wire representation as MapOut, but using -// repeated message fields instead of map fields. We use this message to test -// the wire-format compatibility of the JSON transcoder (e.g., whether it -// handles missing keys correctly). -message MapOutWireFormat { - message Map1Entry { - string key = 1; - MapM value = 2; - } - repeated Map1Entry map1 = 1; - message Map2Entry { - string key = 1; - MapOut value = 2; - } - repeated Map2Entry map2 = 2; - message Map3Entry { - int32 key = 1; - string value = 2; - } - repeated Map3Entry map3 = 3; - message Map4Entry { - bool key = 1; - string value = 2; - } - repeated Map4Entry map4 = 5; - string bar = 4; -} - -message MapM { - string foo = 1; -} diff --git a/libs/protobuf/src/google/protobuf/util/json_util.cc b/libs/protobuf/src/google/protobuf/util/json_util.cc new file mode 100644 index 0000000..c39c10d --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/json_util.cc @@ -0,0 +1,284 @@ +// 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// clang-format off +#include +// clang-format on + +namespace google { +namespace protobuf { +namespace util { + +namespace internal { +ZeroCopyStreamByteSink::~ZeroCopyStreamByteSink() { + if (buffer_size_ > 0) { + stream_->BackUp(buffer_size_); + } +} + +void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) { + while (true) { + if (len <= buffer_size_) { // NOLINT + memcpy(buffer_, bytes, len); + buffer_ = static_cast(buffer_) + len; + buffer_size_ -= len; + return; + } + if (buffer_size_ > 0) { + memcpy(buffer_, bytes, buffer_size_); + bytes += buffer_size_; + len -= buffer_size_; + } + if (!stream_->Next(&buffer_, &buffer_size_)) { + // There isn't a way for ByteSink to report errors. + buffer_size_ = 0; + return; + } + } +} +} // namespace internal + +util::Status BinaryToJsonStream(TypeResolver* resolver, + const std::string& type_url, + io::ZeroCopyInputStream* binary_input, + io::ZeroCopyOutputStream* json_output, + const JsonPrintOptions& options) { + io::CodedInputStream in_stream(binary_input); + google::protobuf::Type type; + RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type)); + converter::ProtoStreamObjectSource::RenderOptions render_options; + render_options.use_ints_for_enums = options.always_print_enums_as_ints; + render_options.preserve_proto_field_names = + options.preserve_proto_field_names; + converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type, + render_options); + io::CodedOutputStream out_stream(json_output); + converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "", + &out_stream); + if (options.always_print_primitive_fields) { + converter::DefaultValueObjectWriter default_value_writer(resolver, type, + &json_writer); + default_value_writer.set_preserve_proto_field_names( + options.preserve_proto_field_names); + default_value_writer.set_print_enums_as_ints( + options.always_print_enums_as_ints); + return proto_source.WriteTo(&default_value_writer); + } else { + return proto_source.WriteTo(&json_writer); + } +} + +util::Status BinaryToJsonString(TypeResolver* resolver, + const std::string& type_url, + const std::string& binary_input, + std::string* json_output, + const JsonPrintOptions& options) { + io::ArrayInputStream input_stream(binary_input.data(), binary_input.size()); + io::StringOutputStream output_stream(json_output); + return BinaryToJsonStream(resolver, type_url, &input_stream, &output_stream, + options); +} + +namespace { +class StatusErrorListener : public converter::ErrorListener { + public: + StatusErrorListener() {} + ~StatusErrorListener() override {} + + util::Status GetStatus() { return status_; } + + void InvalidName(const converter::LocationTrackerInterface& loc, + StringPiece unknown_name, + StringPiece message) override { + std::string loc_string = GetLocString(loc); + if (!loc_string.empty()) { + loc_string.append(" "); + } + status_ = util::InvalidArgumentError( + StrCat(loc_string, unknown_name, ": ", message)); + } + + void InvalidValue(const converter::LocationTrackerInterface& loc, + StringPiece type_name, + StringPiece value) override { + status_ = util::InvalidArgumentError( + StrCat(GetLocString(loc), ": invalid value ", std::string(value), + " for type ", std::string(type_name))); + } + + void MissingField(const converter::LocationTrackerInterface& loc, + StringPiece missing_name) override { + status_ = util::InvalidArgumentError(StrCat( + GetLocString(loc), ": missing field ", std::string(missing_name))); + } + + private: + util::Status status_; + + std::string GetLocString(const converter::LocationTrackerInterface& loc) { + std::string loc_string = loc.ToString(); + StripWhitespace(&loc_string); + if (!loc_string.empty()) { + loc_string = StrCat("(", loc_string, ")"); + } + return loc_string; + } + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StatusErrorListener); +}; +} // namespace + +util::Status JsonToBinaryStream(TypeResolver* resolver, + const std::string& type_url, + io::ZeroCopyInputStream* json_input, + io::ZeroCopyOutputStream* binary_output, + const JsonParseOptions& options) { + google::protobuf::Type type; + RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type)); + internal::ZeroCopyStreamByteSink sink(binary_output); + StatusErrorListener listener; + converter::ProtoStreamObjectWriter::Options proto_writer_options; + proto_writer_options.ignore_unknown_fields = options.ignore_unknown_fields; + proto_writer_options.ignore_unknown_enum_values = + options.ignore_unknown_fields; + proto_writer_options.case_insensitive_enum_parsing = + options.case_insensitive_enum_parsing; + converter::ProtoStreamObjectWriter proto_writer( + resolver, type, &sink, &listener, proto_writer_options); + + converter::JsonStreamParser parser(&proto_writer); + const void* buffer; + int length; + while (json_input->Next(&buffer, &length)) { + if (length == 0) continue; + RETURN_IF_ERROR(parser.Parse( + StringPiece(static_cast(buffer), length))); + } + RETURN_IF_ERROR(parser.FinishParse()); + + return listener.GetStatus(); +} + +util::Status JsonToBinaryString(TypeResolver* resolver, + const std::string& type_url, + StringPiece json_input, + std::string* binary_output, + const JsonParseOptions& options) { + io::ArrayInputStream input_stream(json_input.data(), json_input.size()); + io::StringOutputStream output_stream(binary_output); + return JsonToBinaryStream(resolver, type_url, &input_stream, &output_stream, + options); +} + +namespace { +const char* kTypeUrlPrefix = "type.googleapis.com"; +TypeResolver* generated_type_resolver_ = nullptr; +PROTOBUF_NAMESPACE_ID::internal::once_flag generated_type_resolver_init_; + +std::string GetTypeUrl(const Message& message) { + return std::string(kTypeUrlPrefix) + "/" + + message.GetDescriptor()->full_name(); +} + +void DeleteGeneratedTypeResolver() { // NOLINT + delete generated_type_resolver_; +} + +void InitGeneratedTypeResolver() { + generated_type_resolver_ = NewTypeResolverForDescriptorPool( + kTypeUrlPrefix, DescriptorPool::generated_pool()); + ::google::protobuf::internal::OnShutdown(&DeleteGeneratedTypeResolver); +} + +TypeResolver* GetGeneratedTypeResolver() { + PROTOBUF_NAMESPACE_ID::internal::call_once(generated_type_resolver_init_, + InitGeneratedTypeResolver); + return generated_type_resolver_; +} +} // namespace + +util::Status MessageToJsonString(const Message& message, std::string* output, + const JsonOptions& options) { + const DescriptorPool* pool = message.GetDescriptor()->file()->pool(); + TypeResolver* resolver = + pool == DescriptorPool::generated_pool() + ? GetGeneratedTypeResolver() + : NewTypeResolverForDescriptorPool(kTypeUrlPrefix, pool); + util::Status result = + BinaryToJsonString(resolver, GetTypeUrl(message), + message.SerializeAsString(), output, options); + if (pool != DescriptorPool::generated_pool()) { + delete resolver; + } + return result; +} + +util::Status JsonStringToMessage(StringPiece input, Message* message, + const JsonParseOptions& options) { + const DescriptorPool* pool = message->GetDescriptor()->file()->pool(); + TypeResolver* resolver = + pool == DescriptorPool::generated_pool() + ? GetGeneratedTypeResolver() + : NewTypeResolverForDescriptorPool(kTypeUrlPrefix, pool); + std::string binary; + util::Status result = JsonToBinaryString(resolver, GetTypeUrl(*message), + input, &binary, options); + if (result.ok() && !message->ParseFromString(binary)) { + result = util::InvalidArgumentError( + "JSON transcoder produced invalid protobuf output."); + } + if (pool != DescriptorPool::generated_pool()) { + delete resolver; + } + return result; +} + +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/json_util.h b/libs/protobuf/src/google/protobuf/util/json_util.h index 2f4f2cb..0f1c4d8 100644 --- a/libs/protobuf/src/google/protobuf/util/json_util.h +++ b/libs/protobuf/src/google/protobuf/util/json_util.h @@ -33,30 +33,172 @@ #ifndef GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ #define GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ -#include "absl/base/attributes.h" +#include +#include +#include +#include +#include - -#include "google/protobuf/json/json.h" +// Must be included last. +#include namespace google { namespace protobuf { +namespace io { +class ZeroCopyInputStream; +class ZeroCopyOutputStream; +} // namespace io namespace util { -using JsonParseOptions = ::google::protobuf::json::ParseOptions; -using JsonPrintOptions = ::google::protobuf::json::PrintOptions; -using JsonOptions ABSL_DEPRECATED("use JsonPrintOptions instead") = - JsonPrintOptions; +struct JsonParseOptions { + // Whether to ignore unknown JSON fields during parsing + bool ignore_unknown_fields; -using ::google::protobuf::json::BinaryToJsonStream; -using ::google::protobuf::json::BinaryToJsonString; + // If true, when a lowercase enum value fails to parse, try convert it to + // UPPER_CASE and see if it matches a valid enum. + // WARNING: This option exists only to preserve legacy behavior. Avoid using + // this option. If your enum needs to support different casing, consider using + // allow_alias instead. + bool case_insensitive_enum_parsing; -using ::google::protobuf::json::JsonStringToMessage; -using ::google::protobuf::json::JsonToBinaryStream; + JsonParseOptions() + : ignore_unknown_fields(false), case_insensitive_enum_parsing(false) {} +}; + +struct JsonPrintOptions { + // Whether to add spaces, line breaks and indentation to make the JSON output + // easy to read. + bool add_whitespace; + // Whether to always print primitive fields. By default proto3 primitive + // fields with default values will be omitted in JSON output. For example, an + // int32 field set to 0 will be omitted. Set this flag to true will override + // the default behavior and print primitive fields regardless of their values. + bool always_print_primitive_fields; + // Whether to always print enums as ints. By default they are rendered as + // strings. + bool always_print_enums_as_ints; + // Whether to preserve proto field names + bool preserve_proto_field_names; + + JsonPrintOptions() + : add_whitespace(false), + always_print_primitive_fields(false), + always_print_enums_as_ints(false), + preserve_proto_field_names(false) {} +}; + +// DEPRECATED. Use JsonPrintOptions instead. +typedef JsonPrintOptions JsonOptions; + +// Converts from protobuf message to JSON and appends it to |output|. This is a +// simple wrapper of BinaryToJsonString(). It will use the DescriptorPool of the +// passed-in message to resolve Any types. +PROTOBUF_EXPORT util::Status MessageToJsonString(const Message& message, + std::string* output, + const JsonOptions& options); + +inline util::Status MessageToJsonString(const Message& message, + std::string* output) { + return MessageToJsonString(message, output, JsonOptions()); +} + +// Converts from JSON to protobuf message. This is a simple wrapper of +// JsonStringToBinary(). It will use the DescriptorPool of the passed-in +// message to resolve Any types. +PROTOBUF_EXPORT util::Status JsonStringToMessage( + StringPiece input, Message* message, const JsonParseOptions& options); + +inline util::Status JsonStringToMessage(StringPiece input, + Message* message) { + return JsonStringToMessage(input, message, JsonParseOptions()); +} + +// Converts protobuf binary data to JSON. +// The conversion will fail if: +// 1. TypeResolver fails to resolve a type. +// 2. input is not valid protobuf wire format, or conflicts with the type +// information returned by TypeResolver. +// Note that unknown fields will be discarded silently. +PROTOBUF_EXPORT util::Status BinaryToJsonStream( + TypeResolver* resolver, const std::string& type_url, + io::ZeroCopyInputStream* binary_input, + io::ZeroCopyOutputStream* json_output, const JsonPrintOptions& options); + +inline util::Status BinaryToJsonStream(TypeResolver* resolver, + const std::string& type_url, + io::ZeroCopyInputStream* binary_input, + io::ZeroCopyOutputStream* json_output) { + return BinaryToJsonStream(resolver, type_url, binary_input, json_output, + JsonPrintOptions()); +} + +PROTOBUF_EXPORT util::Status BinaryToJsonString( + TypeResolver* resolver, const std::string& type_url, + const std::string& binary_input, std::string* json_output, + const JsonPrintOptions& options); + +inline util::Status BinaryToJsonString(TypeResolver* resolver, + const std::string& type_url, + const std::string& binary_input, + std::string* json_output) { + return BinaryToJsonString(resolver, type_url, binary_input, json_output, + JsonPrintOptions()); +} + +// Converts JSON data to protobuf binary format. +// The conversion will fail if: +// 1. TypeResolver fails to resolve a type. +// 2. input is not valid JSON format, or conflicts with the type +// information returned by TypeResolver. +PROTOBUF_EXPORT util::Status JsonToBinaryStream( + TypeResolver* resolver, const std::string& type_url, + io::ZeroCopyInputStream* json_input, + io::ZeroCopyOutputStream* binary_output, const JsonParseOptions& options); + +inline util::Status JsonToBinaryStream( + TypeResolver* resolver, const std::string& type_url, + io::ZeroCopyInputStream* json_input, + io::ZeroCopyOutputStream* binary_output) { + return JsonToBinaryStream(resolver, type_url, json_input, binary_output, + JsonParseOptions()); +} + +PROTOBUF_EXPORT util::Status JsonToBinaryString( + TypeResolver* resolver, const std::string& type_url, + StringPiece json_input, std::string* binary_output, + const JsonParseOptions& options); + +inline util::Status JsonToBinaryString(TypeResolver* resolver, + const std::string& type_url, + StringPiece json_input, + std::string* binary_output) { + return JsonToBinaryString(resolver, type_url, json_input, binary_output, + JsonParseOptions()); +} + +namespace internal { +// Internal helper class. Put in the header so we can write unit-tests for it. +class PROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink { + public: + explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream) + : stream_(stream), buffer_(nullptr), buffer_size_(0) {} + ~ZeroCopyStreamByteSink() override; + + void Append(const char* bytes, size_t len) override; + + private: + io::ZeroCopyOutputStream* stream_; + void* buffer_; + int buffer_size_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyStreamByteSink); +}; +} // namespace internal -using ::google::protobuf::json::JsonToBinaryString; -using ::google::protobuf::json::MessageToJsonString; } // namespace util } // namespace protobuf } // namespace google +#include + #endif // GOOGLE_PROTOBUF_UTIL_JSON_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/util/json_util_test.cc b/libs/protobuf/src/google/protobuf/util/json_util_test.cc new file mode 100644 index 0000000..7216199 --- /dev/null +++ b/libs/protobuf/src/google/protobuf/util/json_util_test.cc @@ -0,0 +1,672 @@ +// 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace google { +namespace protobuf { +namespace util { +namespace { + +using proto3::BAR; +using proto3::FOO; +using proto3::TestAny; +using proto3::TestEnumValue; +using proto3::TestMap; +using proto3::TestMessage; +using proto3::TestOneof; +using proto_util_converter::testing::MapIn; + +// As functions defined in json_util.h are just thin wrappers around the +// JSON conversion code in //net/proto2/util/converter, in this test we +// only cover some very basic cases to make sure the wrappers have forwarded +// parameters to the underlying implementation correctly. More detailed +// tests are contained in the //net/proto2/util/converter directory. +class JsonUtilTest : public ::testing::Test { + protected: + JsonUtilTest() {} + + std::string ToJson(const Message& message, const JsonPrintOptions& options) { + std::string result; + GOOGLE_CHECK_OK(MessageToJsonString(message, &result, options)); + return result; + } + + bool FromJson(const std::string& json, Message* message, + const JsonParseOptions& options) { + return JsonStringToMessage(json, message, options).ok(); + } + + bool FromJson(const std::string& json, Message* message) { + return FromJson(json, message, JsonParseOptions()); + } + + std::unique_ptr resolver_; +}; + +TEST_F(JsonUtilTest, TestWhitespaces) { + TestMessage m; + m.mutable_message_value(); + + JsonPrintOptions options; + EXPECT_EQ("{\"messageValue\":{}}", ToJson(m, options)); + options.add_whitespace = true; + EXPECT_EQ( + "{\n" + " \"messageValue\": {}\n" + "}\n", + ToJson(m, options)); +} + +TEST_F(JsonUtilTest, TestDefaultValues) { + TestMessage m; + JsonPrintOptions options; + EXPECT_EQ("{}", ToJson(m, options)); + options.always_print_primitive_fields = true; + EXPECT_EQ( + "{\"boolValue\":false," + "\"int32Value\":0," + "\"int64Value\":\"0\"," + "\"uint32Value\":0," + "\"uint64Value\":\"0\"," + "\"floatValue\":0," + "\"doubleValue\":0," + "\"stringValue\":\"\"," + "\"bytesValue\":\"\"," + "\"enumValue\":\"FOO\"," + "\"repeatedBoolValue\":[]," + "\"repeatedInt32Value\":[]," + "\"repeatedInt64Value\":[]," + "\"repeatedUint32Value\":[]," + "\"repeatedUint64Value\":[]," + "\"repeatedFloatValue\":[]," + "\"repeatedDoubleValue\":[]," + "\"repeatedStringValue\":[]," + "\"repeatedBytesValue\":[]," + "\"repeatedEnumValue\":[]," + "\"repeatedMessageValue\":[]" + "}", + ToJson(m, options)); + + options.always_print_primitive_fields = true; + m.set_string_value("i am a test string value"); + m.set_bytes_value("i am a test bytes value"); + EXPECT_EQ( + "{\"boolValue\":false," + "\"int32Value\":0," + "\"int64Value\":\"0\"," + "\"uint32Value\":0," + "\"uint64Value\":\"0\"," + "\"floatValue\":0," + "\"doubleValue\":0," + "\"stringValue\":\"i am a test string value\"," + "\"bytesValue\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\"," + "\"enumValue\":\"FOO\"," + "\"repeatedBoolValue\":[]," + "\"repeatedInt32Value\":[]," + "\"repeatedInt64Value\":[]," + "\"repeatedUint32Value\":[]," + "\"repeatedUint64Value\":[]," + "\"repeatedFloatValue\":[]," + "\"repeatedDoubleValue\":[]," + "\"repeatedStringValue\":[]," + "\"repeatedBytesValue\":[]," + "\"repeatedEnumValue\":[]," + "\"repeatedMessageValue\":[]" + "}", + ToJson(m, options)); + + options.preserve_proto_field_names = true; + m.set_string_value("i am a test string value"); + m.set_bytes_value("i am a test bytes value"); + EXPECT_EQ( + "{\"bool_value\":false," + "\"int32_value\":0," + "\"int64_value\":\"0\"," + "\"uint32_value\":0," + "\"uint64_value\":\"0\"," + "\"float_value\":0," + "\"double_value\":0," + "\"string_value\":\"i am a test string value\"," + "\"bytes_value\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\"," + "\"enum_value\":\"FOO\"," + "\"repeated_bool_value\":[]," + "\"repeated_int32_value\":[]," + "\"repeated_int64_value\":[]," + "\"repeated_uint32_value\":[]," + "\"repeated_uint64_value\":[]," + "\"repeated_float_value\":[]," + "\"repeated_double_value\":[]," + "\"repeated_string_value\":[]," + "\"repeated_bytes_value\":[]," + "\"repeated_enum_value\":[]," + "\"repeated_message_value\":[]" + "}", + ToJson(m, options)); +} + +TEST_F(JsonUtilTest, TestPreserveProtoFieldNames) { + TestMessage m; + m.mutable_message_value(); + + JsonPrintOptions options; + options.preserve_proto_field_names = true; + EXPECT_EQ("{\"message_value\":{}}", ToJson(m, options)); +} + +TEST_F(JsonUtilTest, TestAlwaysPrintEnumsAsInts) { + TestMessage orig; + orig.set_enum_value(proto3::BAR); + orig.add_repeated_enum_value(proto3::FOO); + orig.add_repeated_enum_value(proto3::BAR); + + JsonPrintOptions print_options; + print_options.always_print_enums_as_ints = true; + + std::string expected_json = "{\"enumValue\":1,\"repeatedEnumValue\":[0,1]}"; + EXPECT_EQ(expected_json, ToJson(orig, print_options)); + + TestMessage parsed; + JsonParseOptions parse_options; + ASSERT_TRUE(FromJson(expected_json, &parsed, parse_options)); + + EXPECT_EQ(proto3::BAR, parsed.enum_value()); + EXPECT_EQ(2, parsed.repeated_enum_value_size()); + EXPECT_EQ(proto3::FOO, parsed.repeated_enum_value(0)); + EXPECT_EQ(proto3::BAR, parsed.repeated_enum_value(1)); +} + +TEST_F(JsonUtilTest, TestPrintEnumsAsIntsWithDefaultValue) { + TestEnumValue orig; + // orig.set_enum_value1(proto3::FOO) + orig.set_enum_value2(proto3::FOO); + orig.set_enum_value3(proto3::BAR); + + JsonPrintOptions print_options; + print_options.always_print_enums_as_ints = true; + print_options.always_print_primitive_fields = true; + + std::string expected_json = + "{\"enumValue1\":0,\"enumValue2\":0,\"enumValue3\":1}"; + EXPECT_EQ(expected_json, ToJson(orig, print_options)); + + TestEnumValue parsed; + JsonParseOptions parse_options; + ASSERT_TRUE(FromJson(expected_json, &parsed, parse_options)); + + EXPECT_EQ(proto3::FOO, parsed.enum_value1()); + EXPECT_EQ(proto3::FOO, parsed.enum_value2()); + EXPECT_EQ(proto3::BAR, parsed.enum_value3()); +} + +TEST_F(JsonUtilTest, TestPrintProto2EnumAsIntWithDefaultValue) { + protobuf_unittest::TestDefaultEnumValue orig; + + JsonPrintOptions print_options; + // use enum as int + print_options.always_print_enums_as_ints = true; + print_options.always_print_primitive_fields = true; + + // result should be int rather than string + std::string expected_json = "{\"enumValue\":2}"; + EXPECT_EQ(expected_json, ToJson(orig, print_options)); + + protobuf_unittest::TestDefaultEnumValue parsed; + JsonParseOptions parse_options; + ASSERT_TRUE(FromJson(expected_json, &parsed, parse_options)); + + EXPECT_EQ(protobuf_unittest::DEFAULT, parsed.enum_value()); +} + +TEST_F(JsonUtilTest, ParseMessage) { + // Some random message but good enough to verify that the parsing wrapper + // functions are working properly. + std::string input = + "{\n" + " \"int32Value\": 1234567891,\n" + " \"int64Value\": 5302428716536692736,\n" + " \"floatValue\": 3.4028235e+38,\n" + " \"repeatedInt32Value\": [1, 2],\n" + " \"messageValue\": {\n" + " \"value\": 2048\n" + " },\n" + " \"repeatedMessageValue\": [\n" + " {\"value\": 40}, {\"value\": 96}\n" + " ]\n" + "}\n"; + JsonParseOptions options; + TestMessage m; + ASSERT_TRUE(FromJson(input, &m, options)); + EXPECT_EQ(1234567891, m.int32_value()); + EXPECT_EQ(5302428716536692736, m.int64_value()); + EXPECT_EQ(3.402823466e+38f, m.float_value()); + ASSERT_EQ(2, m.repeated_int32_value_size()); + EXPECT_EQ(1, m.repeated_int32_value(0)); + EXPECT_EQ(2, m.repeated_int32_value(1)); + EXPECT_EQ(2048, m.message_value().value()); + ASSERT_EQ(2, m.repeated_message_value_size()); + EXPECT_EQ(40, m.repeated_message_value(0).value()); + EXPECT_EQ(96, m.repeated_message_value(1).value()); +} + +TEST_F(JsonUtilTest, ParseMap) { + TestMap message; + (*message.mutable_string_map())["hello"] = 1234; + JsonPrintOptions print_options; + JsonParseOptions parse_options; + EXPECT_EQ("{\"stringMap\":{\"hello\":1234}}", ToJson(message, print_options)); + TestMap other; + ASSERT_TRUE(FromJson(ToJson(message, print_options), &other, parse_options)); + EXPECT_EQ(message.DebugString(), other.DebugString()); +} + +TEST_F(JsonUtilTest, ParsePrimitiveMapIn) { + MapIn message; + JsonPrintOptions print_options; + print_options.always_print_primitive_fields = true; + JsonParseOptions parse_options; + EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{},\"mapAny\":{}}", + ToJson(message, print_options)); + MapIn other; + ASSERT_TRUE(FromJson(ToJson(message, print_options), &other, parse_options)); + EXPECT_EQ(message.DebugString(), other.DebugString()); +} + +TEST_F(JsonUtilTest, PrintPrimitiveOneof) { + TestOneof message; + JsonPrintOptions options; + options.always_print_primitive_fields = true; + message.mutable_oneof_message_value(); + EXPECT_EQ("{\"oneofMessageValue\":{\"value\":0}}", ToJson(message, options)); + + message.set_oneof_int32_value(1); + EXPECT_EQ("{\"oneofInt32Value\":1}", ToJson(message, options)); +} + +TEST_F(JsonUtilTest, TestParseIgnoreUnknownFields) { + TestMessage m; + JsonParseOptions options; + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson("{\"unknownName\":0}", &m, options)); +} + +TEST_F(JsonUtilTest, TestParseErrors) { + TestMessage m; + JsonParseOptions options; + // Parsing should fail if the field name can not be recognized. + EXPECT_FALSE(FromJson("{\"unknownName\":0}", &m, options)); + // Parsing should fail if the value is invalid. + EXPECT_FALSE(FromJson("{\"int32Value\":2147483648}", &m, options)); +} + +TEST_F(JsonUtilTest, TestDynamicMessage) { + // Some random message but good enough to test the wrapper functions. + std::string input = + "{\n" + " \"int32Value\": 1024,\n" + " \"repeatedInt32Value\": [1, 2],\n" + " \"messageValue\": {\n" + " \"value\": 2048\n" + " },\n" + " \"repeatedMessageValue\": [\n" + " {\"value\": 40}, {\"value\": 96}\n" + " ]\n" + "}\n"; + + // Create a new DescriptorPool with the same protos as the generated one. + DescriptorPoolDatabase database(*DescriptorPool::generated_pool()); + DescriptorPool pool(&database); + // A dynamic version of the test proto. + DynamicMessageFactory factory; + std::unique_ptr message( + factory.GetPrototype(pool.FindMessageTypeByName("proto3.TestMessage")) + ->New()); + EXPECT_TRUE(FromJson(input, message.get())); + + // Convert to generated message for easy inspection. + TestMessage generated; + EXPECT_TRUE(generated.ParseFromString(message->SerializeAsString())); + EXPECT_EQ(1024, generated.int32_value()); + ASSERT_EQ(2, generated.repeated_int32_value_size()); + EXPECT_EQ(1, generated.repeated_int32_value(0)); + EXPECT_EQ(2, generated.repeated_int32_value(1)); + EXPECT_EQ(2048, generated.message_value().value()); + ASSERT_EQ(2, generated.repeated_message_value_size()); + EXPECT_EQ(40, generated.repeated_message_value(0).value()); + EXPECT_EQ(96, generated.repeated_message_value(1).value()); + + JsonOptions options; + EXPECT_EQ(ToJson(generated, options), ToJson(*message, options)); +} + +TEST_F(JsonUtilTest, TestParsingUnknownAnyFields) { + std::string input = + "{\n" + " \"value\": {\n" + " \"@type\": \"type.googleapis.com/proto3.TestMessage\",\n" + " \"unknown_field\": \"UNKNOWN_VALUE\",\n" + " \"string_value\": \"expected_value\"\n" + " }\n" + "}"; + + TestAny m; + JsonParseOptions options; + EXPECT_FALSE(FromJson(input, &m, options)); + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + + TestMessage t; + EXPECT_TRUE(m.value().UnpackTo(&t)); + EXPECT_EQ("expected_value", t.string_value()); +} + +TEST_F(JsonUtilTest, TestParsingUnknownEnumsProto2) { + std::string input = + "{\n" + " \"a\": \"UNKNOWN_VALUE\"\n" + "}"; + protobuf_unittest::TestNumbers m; + JsonParseOptions options; + EXPECT_FALSE(FromJson(input, &m, options)); + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + EXPECT_FALSE(m.has_a()); +} + +TEST_F(JsonUtilTest, TestParsingUnknownEnumsProto3) { + TestMessage m; + { + JsonParseOptions options; + ASSERT_FALSE(options.ignore_unknown_fields); + std::string input = + "{\n" + " \"enum_value\":\"UNKNOWN_VALUE\"\n" + "}"; + m.set_enum_value(proto3::BAR); + EXPECT_FALSE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::BAR, m.enum_value()); // Keep previous value + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + EXPECT_EQ(0, m.enum_value()); // Unknown enum value must be decoded as 0 + } + // Integer values are read as usual + { + JsonParseOptions options; + std::string input = + "{\n" + " \"enum_value\":12345\n" + "}"; + m.set_enum_value(proto3::BAR); + EXPECT_TRUE(FromJson(input, &m, options)); + ASSERT_EQ(12345, m.enum_value()); + + options.ignore_unknown_fields = true; + EXPECT_TRUE(FromJson(input, &m, options)); + EXPECT_EQ(12345, m.enum_value()); + } + + // Trying to pass an object as an enum field value is always treated as an + // error + { + JsonParseOptions options; + std::string input = + "{\n" + " \"enum_value\":{}\n" + "}"; + options.ignore_unknown_fields = true; + EXPECT_FALSE(FromJson(input, &m, options)); + options.ignore_unknown_fields = false; + EXPECT_FALSE(FromJson(input, &m, options)); + } + // Trying to pass an array as an enum field value is always treated as an + // error + { + JsonParseOptions options; + std::string input = + "{\n" + " \"enum_value\":[]\n" + "}"; + EXPECT_FALSE(FromJson(input, &m, options)); + options.ignore_unknown_fields = true; + EXPECT_FALSE(FromJson(input, &m, options)); + } +} + +TEST_F(JsonUtilTest, TestParsingEnumIgnoreCase) { + TestMessage m; + { + JsonParseOptions options; + std::string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_FALSE(FromJson(input, &m, options)); + // Default behavior is case-sensitive, so keep previous value. + ASSERT_EQ(proto3::FOO, m.enum_value()); + } + { + JsonParseOptions options; + options.case_insensitive_enum_parsing = false; + std::string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_FALSE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::FOO, m.enum_value()); // Keep previous value + } + { + JsonParseOptions options; + options.case_insensitive_enum_parsing = true; + std::string input = + "{\n" + " \"enum_value\":\"bar\"\n" + "}"; + m.set_enum_value(proto3::FOO); + EXPECT_TRUE(FromJson(input, &m, options)); + ASSERT_EQ(proto3::BAR, m.enum_value()); + } +} + +typedef std::pair Segment; +// A ZeroCopyOutputStream that writes to multiple buffers. +class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream { + public: + explicit SegmentedZeroCopyOutputStream(std::list segments) + : segments_(segments), + last_segment_(static_cast(NULL), 0), + byte_count_(0) {} + + bool Next(void** buffer, int* length) override { + if (segments_.empty()) { + return false; + } + last_segment_ = segments_.front(); + segments_.pop_front(); + *buffer = last_segment_.first; + *length = last_segment_.second; + byte_count_ += *length; + return true; + } + + void BackUp(int length) override { + GOOGLE_CHECK(length <= last_segment_.second); + segments_.push_front( + Segment(last_segment_.first + last_segment_.second - length, length)); + last_segment_ = Segment(last_segment_.first, last_segment_.second - length); + byte_count_ -= length; + } + + int64_t ByteCount() const override { return byte_count_; } + + private: + std::list segments_; + Segment last_segment_; + int64_t byte_count_; +}; + +// This test splits the output buffer and also the input data into multiple +// segments and checks that the implementation of ZeroCopyStreamByteSink +// handles all possible cases correctly. +TEST(ZeroCopyStreamByteSinkTest, TestAllInputOutputPatterns) { + static const int kOutputBufferLength = 10; + // An exhaustive test takes too long, skip some combinations to make the test + // run faster. + static const int kSkippedPatternCount = 7; + + char buffer[kOutputBufferLength]; + for (int split_pattern = 0; split_pattern < (1 << (kOutputBufferLength - 1)); + split_pattern += kSkippedPatternCount) { + // Split the buffer into small segments according to the split_pattern. + std::list segments; + int segment_start = 0; + for (int i = 0; i < kOutputBufferLength - 1; ++i) { + if (split_pattern & (1 << i)) { + segments.push_back( + Segment(buffer + segment_start, i - segment_start + 1)); + segment_start = i + 1; + } + } + segments.push_back( + Segment(buffer + segment_start, kOutputBufferLength - segment_start)); + + // Write exactly 10 bytes through the ByteSink. + std::string input_data = "0123456789"; + for (int input_pattern = 0; input_pattern < (1 << (input_data.size() - 1)); + input_pattern += kSkippedPatternCount) { + memset(buffer, 0, sizeof(buffer)); + { + SegmentedZeroCopyOutputStream output_stream(segments); + internal::ZeroCopyStreamByteSink byte_sink(&output_stream); + int start = 0; + for (int j = 0; j < input_data.length() - 1; ++j) { + if (input_pattern & (1 << j)) { + byte_sink.Append(&input_data[start], j - start + 1); + start = j + 1; + } + } + byte_sink.Append(&input_data[start], input_data.length() - start); + } + EXPECT_EQ(input_data, std::string(buffer, input_data.length())); + } + + // Write only 9 bytes through the ByteSink. + input_data = "012345678"; + for (int input_pattern = 0; input_pattern < (1 << (input_data.size() - 1)); + input_pattern += kSkippedPatternCount) { + memset(buffer, 0, sizeof(buffer)); + { + SegmentedZeroCopyOutputStream output_stream(segments); + internal::ZeroCopyStreamByteSink byte_sink(&output_stream); + int start = 0; + for (int j = 0; j < input_data.length() - 1; ++j) { + if (input_pattern & (1 << j)) { + byte_sink.Append(&input_data[start], j - start + 1); + start = j + 1; + } + } + byte_sink.Append(&input_data[start], input_data.length() - start); + } + EXPECT_EQ(input_data, std::string(buffer, input_data.length())); + EXPECT_EQ(0, buffer[input_data.length()]); + } + + // Write 11 bytes through the ByteSink. The extra byte will just + // be ignored. + input_data = "0123456789A"; + for (int input_pattern = 0; input_pattern < (1 << (input_data.size() - 1)); + input_pattern += kSkippedPatternCount) { + memset(buffer, 0, sizeof(buffer)); + { + SegmentedZeroCopyOutputStream output_stream(segments); + internal::ZeroCopyStreamByteSink byte_sink(&output_stream); + int start = 0; + for (int j = 0; j < input_data.length() - 1; ++j) { + if (input_pattern & (1 << j)) { + byte_sink.Append(&input_data[start], j - start + 1); + start = j + 1; + } + } + byte_sink.Append(&input_data[start], input_data.length() - start); + } + EXPECT_EQ(input_data.substr(0, kOutputBufferLength), + std::string(buffer, kOutputBufferLength)); + } + } +} + +TEST_F(JsonUtilTest, TestWrongJsonInput) { + const char json[] = "{\"unknown_field\":\"some_value\"}"; + io::ArrayInputStream input_stream(json, strlen(json)); + char proto_buffer[10000]; + io::ArrayOutputStream output_stream(proto_buffer, sizeof(proto_buffer)); + std::string message_type = "type.googleapis.com/proto3.TestMessage"; + TypeResolver* resolver = NewTypeResolverForDescriptorPool( + "type.googleapis.com", DescriptorPool::generated_pool()); + + auto result_status = util::JsonToBinaryStream(resolver, message_type, + &input_stream, &output_stream); + + delete resolver; + + EXPECT_FALSE(result_status.ok()); + EXPECT_TRUE(util::IsInvalidArgument(result_status)); +} + +TEST_F(JsonUtilTest, HtmlEscape) { + TestMessage m; + m.set_string_value(""); + JsonPrintOptions options; + EXPECT_EQ("{\"stringValue\":\"\\u003c/script\\u003e\"}", ToJson(m, options)); +} + +} // namespace +} // namespace util +} // namespace protobuf +} // namespace google diff --git a/libs/protobuf/src/google/protobuf/util/message_differencer.cc b/libs/protobuf/src/google/protobuf/util/message_differencer.cc index 3c990c9..30560ed 100644 --- a/libs/protobuf/src/google/protobuf/util/message_differencer.cc +++ b/libs/protobuf/src/google/protobuf/util/message_differencer.cc @@ -32,7 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/util/message_differencer.h" +#include #include #include @@ -42,27 +42,24 @@ #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#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/descriptor.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/generated_enum_reflection.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/message.h" -#include "google/protobuf/text_format.h" -#include "absl/container/fixed_array.h" -#include "absl/strings/escaping.h" -#include "absl/strings/match.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "google/protobuf/util/field_comparator.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Always include as last one, otherwise it can break compilation -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -155,16 +152,10 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator key_field_path.push_back(key); key_field_paths_.push_back(key_field_path); } - MultipleFieldsMapKeyComparator(const MultipleFieldsMapKeyComparator&) = - delete; - MultipleFieldsMapKeyComparator& operator=( - const MultipleFieldsMapKeyComparator&) = delete; bool IsMatch(const Message& message1, const Message& message2, - int unpacked_any, const std::vector& parent_fields) const override { for (const auto& path : key_field_paths_) { - if (!IsMatchInternal(message1, message2, unpacked_any, parent_fields, - path, 0)) { + if (!IsMatchInternal(message1, message2, parent_fields, path, 0)) { return false; } } @@ -173,7 +164,7 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator private: bool IsMatchInternal( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const std::vector& parent_fields, const std::vector& key_field_path, int path_index) const { @@ -181,15 +172,14 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator std::vector current_parent_fields(parent_fields); if (path_index == static_cast(key_field_path.size() - 1)) { if (field->is_map()) { - return message_differencer_->CompareMapField( - message1, message2, unpacked_any, field, ¤t_parent_fields); + return message_differencer_->CompareMapField(message1, message2, field, + ¤t_parent_fields); } else if (field->is_repeated()) { return message_differencer_->CompareRepeatedField( - message1, message2, unpacked_any, field, ¤t_parent_fields); + message1, message2, field, ¤t_parent_fields); } else { return message_differencer_->CompareFieldValueUsingParentFields( - message1, message2, unpacked_any, field, -1, -1, - ¤t_parent_fields); + message1, message2, field, -1, -1, ¤t_parent_fields); } } else { const Reflection* reflection1 = message1.GetReflection(); @@ -203,19 +193,17 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator return false; } SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field; current_parent_fields.push_back(specific_field); return IsMatchInternal(reflection1->GetMessage(message1, field), reflection2->GetMessage(message2, field), - false /*key is never Any*/, current_parent_fields, - key_field_path, path_index + 1); + current_parent_fields, key_field_path, + path_index + 1); } } MessageDifferencer* message_differencer_; std::vector > key_field_paths_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultipleFieldsMapKeyComparator); }; // Preserve the order when treating repeated field as SMART_LIST. The current @@ -266,7 +254,7 @@ MessageDifferencer::MapEntryKeyComparator::MapEntryKeyComparator( : message_differencer_(message_differencer) {} bool MessageDifferencer::MapEntryKeyComparator::IsMatch( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const std::vector& parent_fields) const { // Map entry has its key in the field with tag 1. See the comment for // map_entry in MessageOptions. @@ -280,11 +268,11 @@ bool MessageDifferencer::MapEntryKeyComparator::IsMatch( std::vector current_parent_fields(parent_fields); if (treat_as_set) { - return message_differencer_->Compare(message1, message2, unpacked_any, + return message_differencer_->Compare(message1, message2, ¤t_parent_fields); } return message_differencer_->CompareFieldValueUsingParentFields( - message1, message2, unpacked_any, key, -1, -1, ¤t_parent_fields); + message1, message2, key, -1, -1, ¤t_parent_fields); } bool MessageDifferencer::Equals(const Message& message1, @@ -338,6 +326,9 @@ MessageDifferencer::~MessageDifferencer() { for (MapKeyComparator* comparator : owned_key_comparators_) { delete comparator; } + for (IgnoreCriteria* criteria : ignore_criteria_) { + delete criteria; + } } void MessageDifferencer::set_field_comparator(FieldComparator* comparator) { @@ -346,14 +337,14 @@ void MessageDifferencer::set_field_comparator(FieldComparator* comparator) { field_comparator_.base = comparator; } -#ifdef PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR +#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES void MessageDifferencer::set_field_comparator( DefaultFieldComparator* comparator) { GOOGLE_CHECK(comparator) << "Field comparator can't be NULL."; field_comparator_kind_ = kFCDefault; field_comparator_.default_impl = comparator; } -#endif // PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR +#endif // PROTOBUF_FUTURE_BREAKING_CHANGES void MessageDifferencer::set_message_field_comparison( MessageFieldComparison comparison) { @@ -499,9 +490,8 @@ void MessageDifferencer::TreatAsMapUsingKeyComparator( map_field_key_comparator_[field] = key_comparator; } -void MessageDifferencer::AddIgnoreCriteria( - std::unique_ptr ignore_criteria) { - ignore_criteria_.push_back(std::move(ignore_criteria)); +void MessageDifferencer::AddIgnoreCriteria(IgnoreCriteria* ignore_criteria) { + ignore_criteria_.push_back(ignore_criteria); } void MessageDifferencer::IgnoreField(const FieldDescriptor* field) { @@ -557,10 +547,10 @@ bool MessageDifferencer::Compare(const Message& message1, StreamReporter reporter(&output_stream); reporter.SetMessages(message1, message2); reporter_ = &reporter; - result = Compare(message1, message2, false, &parent_fields); + result = Compare(message1, message2, &parent_fields); reporter_ = NULL; } else { - result = Compare(message1, message2, false, &parent_fields); + result = Compare(message1, message2, &parent_fields); } return result; } @@ -600,20 +590,18 @@ bool MessageDifferencer::CompareWithFields( StreamReporter reporter(&output_stream); reporter_ = &reporter; result = CompareRequestedFieldsUsingSettings( - message1, message2, false, message1_fields, message2_fields, - &parent_fields); + message1, message2, message1_fields, message2_fields, &parent_fields); reporter_ = NULL; } else { result = CompareRequestedFieldsUsingSettings( - message1, message2, false, message1_fields, message2_fields, - &parent_fields); + message1, message2, message1_fields, message2_fields, &parent_fields); } return result; } bool MessageDifferencer::Compare(const Message& message1, - const Message& message2, int unpacked_any, + const Message& message2, std::vector* parent_fields) { const Descriptor* descriptor1 = message1.GetDescriptor(); const Descriptor* descriptor2 = message2.GetDescriptor(); @@ -634,7 +622,7 @@ bool MessageDifferencer::Compare(const Message& message1, if (data1->GetDescriptor() != data2->GetDescriptor()) { return false; } - return Compare(*data1, *data2, unpacked_any + 1, parent_fields); + return Compare(*data1, *data2, parent_fields); } } const Reflection* reflection1 = message1.GetReflection(); @@ -659,7 +647,7 @@ bool MessageDifferencer::Compare(const Message& message1, FieldDescriptorArray message1_fields = RetrieveFields(message1, true); FieldDescriptorArray message2_fields = RetrieveFields(message2, false); - return CompareRequestedFieldsUsingSettings(message1, message2, unpacked_any, + return CompareRequestedFieldsUsingSettings(message1, message2, message1_fields, message2_fields, parent_fields) && unknown_compare_result; @@ -697,7 +685,7 @@ FieldDescriptorArray MessageDifferencer::RetrieveFields(const Message& message, } bool MessageDifferencer::CompareRequestedFieldsUsingSettings( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptorArray& message1_fields, const FieldDescriptorArray& message2_fields, std::vector* parent_fields) { @@ -708,23 +696,20 @@ bool MessageDifferencer::CompareRequestedFieldsUsingSettings( // rather than the addition or deletion of fields). FieldDescriptorArray fields_union = CombineFields(message1_fields, FULL, message2_fields, FULL); - return CompareWithFieldsInternal(message1, message2, unpacked_any, - fields_union, fields_union, - parent_fields); + return CompareWithFieldsInternal(message1, message2, fields_union, + fields_union, parent_fields); } else { // Simple equality comparison, use the unaltered field lists. - return CompareWithFieldsInternal(message1, message2, unpacked_any, - message1_fields, message2_fields, - parent_fields); + return CompareWithFieldsInternal(message1, message2, message1_fields, + message2_fields, parent_fields); } } else { if (message_field_comparison_ == EQUIVALENT) { // We use the list of fields for message1 for both messages when // comparing. This way, extra fields in message2 are ignored, // and missing fields in message2 use their default value. - return CompareWithFieldsInternal(message1, message2, unpacked_any, - message1_fields, message1_fields, - parent_fields); + return CompareWithFieldsInternal(message1, message2, message1_fields, + message1_fields, parent_fields); } else { // We need to consider the full list of fields for message1 // but only the intersection for message2. This way, any fields @@ -732,9 +717,8 @@ bool MessageDifferencer::CompareRequestedFieldsUsingSettings( // present in message1 will be marked as a difference. FieldDescriptorArray fields_intersection = CombineFields(message1_fields, PARTIAL, message2_fields, PARTIAL); - return CompareWithFieldsInternal(message1, message2, unpacked_any, - message1_fields, fields_intersection, - parent_fields); + return CompareWithFieldsInternal(message1, message2, message1_fields, + fields_intersection, parent_fields); } } } @@ -777,7 +761,7 @@ FieldDescriptorArray MessageDifferencer::CombineFields( } bool MessageDifferencer::CompareWithFieldsInternal( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptorArray& message1_fields, const FieldDescriptorArray& message2_fields, std::vector* parent_fields) { @@ -805,9 +789,6 @@ bool MessageDifferencer::CompareWithFieldsInternal( // the next field in message1_fields. if (reporter_ != NULL) { SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field1; parent_fields->push_back(specific_field); if (report_ignores_) { @@ -827,9 +808,6 @@ bool MessageDifferencer::CompareWithFieldsInternal( for (int i = 0; i < count; ++i) { SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field1; if (field1->is_repeated()) { AddSpecificIndex(&specific_field, message1, field1, i); @@ -856,9 +834,6 @@ bool MessageDifferencer::CompareWithFieldsInternal( // the next field in message2_fields. if (reporter_ != NULL) { SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field2; parent_fields->push_back(specific_field); if (report_ignores_) { @@ -877,9 +852,6 @@ bool MessageDifferencer::CompareWithFieldsInternal( for (int i = 0; i < count; ++i) { SpecificField specific_field; - specific_field.message1 = &message1, - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field2; if (field2->is_repeated()) { specific_field.index = i; @@ -909,9 +881,6 @@ bool MessageDifferencer::CompareWithFieldsInternal( // Ignore this field. Report and move on. if (reporter_ != NULL) { SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field1; parent_fields->push_back(specific_field); if (report_ignores_) { @@ -928,20 +897,17 @@ bool MessageDifferencer::CompareWithFieldsInternal( bool fieldDifferent = false; assert(field1 != NULL); if (field1->is_map()) { - fieldDifferent = !CompareMapField(message1, message2, unpacked_any, - field1, parent_fields); + fieldDifferent = + !CompareMapField(message1, message2, field1, parent_fields); } else if (field1->is_repeated()) { - fieldDifferent = !CompareRepeatedField(message1, message2, unpacked_any, - field1, parent_fields); + fieldDifferent = + !CompareRepeatedField(message1, message2, field1, parent_fields); } else { fieldDifferent = !CompareFieldValueUsingParentFields( - message1, message2, unpacked_any, field1, -1, -1, parent_fields); + message1, message2, field1, -1, -1, parent_fields); if (reporter_ != nullptr) { SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field1; parent_fields->push_back(specific_field); if (fieldDifferent) { @@ -968,14 +934,13 @@ bool MessageDifferencer::CompareWithFieldsInternal( bool MessageDifferencer::IsMatch( const FieldDescriptor* repeated_field, const MapKeyComparator* key_comparator, const Message* message1, - const Message* message2, int unpacked_any, - const std::vector& parent_fields, Reporter* reporter, - int index1, int index2) { + const Message* message2, const std::vector& parent_fields, + Reporter* reporter, int index1, int index2) { std::vector current_parent_fields(parent_fields); if (repeated_field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) { - return CompareFieldValueUsingParentFields( - *message1, *message2, unpacked_any, repeated_field, index1, index2, - ¤t_parent_fields); + return CompareFieldValueUsingParentFields(*message1, *message2, + repeated_field, index1, index2, + ¤t_parent_fields); } // Back up the Reporter and output_string_. They will be reset in the // following code. @@ -986,9 +951,9 @@ bool MessageDifferencer::IsMatch( bool match; if (key_comparator == NULL) { - match = CompareFieldValueUsingParentFields( - *message1, *message2, unpacked_any, repeated_field, index1, index2, - ¤t_parent_fields); + match = CompareFieldValueUsingParentFields(*message1, *message2, + repeated_field, index1, index2, + ¤t_parent_fields); } else { const Reflection* reflection1 = message1->GetReflection(); const Reflection* reflection2 = message2->GetReflection(); @@ -997,9 +962,6 @@ bool MessageDifferencer::IsMatch( const Message& m2 = reflection2->GetRepeatedMessage(*message2, repeated_field, index2); SpecificField specific_field; - specific_field.message1 = message1; - specific_field.message2 = message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = repeated_field; if (repeated_field->is_map()) { specific_field.map_entry1 = &m1; @@ -1008,7 +970,7 @@ bool MessageDifferencer::IsMatch( specific_field.index = index1; specific_field.new_index = index2; current_parent_fields.push_back(specific_field); - match = key_comparator->IsMatch(m1, m2, false, current_parent_fields); + match = key_comparator->IsMatch(m1, m2, current_parent_fields); } reporter_ = backup_reporter; @@ -1017,7 +979,7 @@ bool MessageDifferencer::IsMatch( } bool MessageDifferencer::CompareMapFieldByMapReflection( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* map_field, std::vector* parent_fields, DefaultFieldComparator* comparator) { GOOGLE_DCHECK_EQ(nullptr, reporter_); @@ -1092,14 +1054,10 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( reflection2->LookupMapValue(message2, map_field, it.GetKey(), &value2); // Append currently compared field to the end of parent_fields. SpecificField specific_value_field; - specific_value_field.message1 = &message1; - specific_value_field.message2 = &message2; - specific_value_field.unpacked_any = unpacked_any; specific_value_field.field = val_des; parent_fields->push_back(specific_value_field); - compare_result = - Compare(it.GetValueRef().GetMessageValue(), - value2.GetMessageValue(), false, parent_fields); + compare_result = Compare(it.GetValueRef().GetMessageValue(), + value2.GetMessageValue(), parent_fields); parent_fields->pop_back(); if (!compare_result) { return false; @@ -1112,7 +1070,7 @@ bool MessageDifferencer::CompareMapFieldByMapReflection( } bool MessageDifferencer::CompareMapField( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* repeated_field, std::vector* parent_fields) { GOOGLE_DCHECK(repeated_field->is_map()); @@ -1138,34 +1096,29 @@ bool MessageDifferencer::CompareMapField( repeated_field->message_type()->map_value(); std::vector current_parent_fields(*parent_fields); SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = repeated_field; current_parent_fields.push_back(specific_field); if (!IsIgnored(message1, message2, key_des, current_parent_fields) && !IsIgnored(message1, message2, val_des, current_parent_fields)) { - return CompareMapFieldByMapReflection( - message1, message2, unpacked_any, repeated_field, - ¤t_parent_fields, field_comparator_.default_impl); + return CompareMapFieldByMapReflection(message1, message2, repeated_field, + ¤t_parent_fields, + field_comparator_.default_impl); } } - return CompareRepeatedRep(message1, message2, unpacked_any, repeated_field, - parent_fields); + return CompareRepeatedRep(message1, message2, repeated_field, parent_fields); } bool MessageDifferencer::CompareRepeatedField( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* repeated_field, std::vector* parent_fields) { GOOGLE_DCHECK(!repeated_field->is_map()); - return CompareRepeatedRep(message1, message2, unpacked_any, repeated_field, - parent_fields); + return CompareRepeatedRep(message1, message2, repeated_field, parent_fields); } bool MessageDifferencer::CompareRepeatedRep( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* repeated_field, std::vector* parent_fields) { // the input FieldDescriptor is guaranteed to be repeated field. @@ -1204,9 +1157,9 @@ bool MessageDifferencer::CompareRepeatedRep( // match_list2. if (!simple_list) { // Try to match indices of the repeated fields. Return false if match fails. - if (!MatchRepeatedFieldIndices( - message1, message2, unpacked_any, repeated_field, key_comparator, - *parent_fields, &match_list1, &match_list2) && + if (!MatchRepeatedFieldIndices(message1, message2, repeated_field, + key_comparator, *parent_fields, &match_list1, + &match_list2) && reporter_ == nullptr) { return false; } @@ -1214,9 +1167,6 @@ bool MessageDifferencer::CompareRepeatedRep( bool fieldDifferent = false; SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = repeated_field; // At this point, we have already matched pairs of fields (with the reporting @@ -1263,8 +1213,8 @@ bool MessageDifferencer::CompareRepeatedRep( } const bool result = CompareFieldValueUsingParentFields( - message1, message2, unpacked_any, repeated_field, i, - specific_field.new_index, parent_fields); + message1, message2, repeated_field, i, specific_field.new_index, + parent_fields); // If we have found differences, either report them or terminate if // no reporter is present. Note that ReportModified, ReportMoved, and @@ -1319,15 +1269,14 @@ bool MessageDifferencer::CompareRepeatedRep( bool MessageDifferencer::CompareFieldValue(const Message& message1, const Message& message2, - int unpacked_any, const FieldDescriptor* field, int index1, int index2) { - return CompareFieldValueUsingParentFields(message1, message2, unpacked_any, - field, index1, index2, nullptr); + return CompareFieldValueUsingParentFields(message1, message2, field, index1, + index2, NULL); } bool MessageDifferencer::CompareFieldValueUsingParentFields( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* field, int index1, int index2, std::vector* parent_fields) { FieldContext field_context(parent_fields); @@ -1353,14 +1302,11 @@ bool MessageDifferencer::CompareFieldValueUsingParentFields( if (parent_fields != NULL) { // Append currently compared field to the end of parent_fields. SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; - specific_field.unpacked_any = unpacked_any; specific_field.field = field; AddSpecificIndex(&specific_field, message1, field, index1); AddSpecificNewIndex(&specific_field, message2, field, index2); parent_fields->push_back(specific_field); - const bool compare_result = Compare(m1, m2, false, parent_fields); + const bool compare_result = Compare(m1, m2, parent_fields); parent_fields->pop_back(); return compare_result; } else { @@ -1425,7 +1371,7 @@ bool MessageDifferencer::IsIgnored( if (ignored_fields_.find(field) != ignored_fields_.end()) { return true; } - for (const auto& criteria : ignore_criteria_) { + for (IgnoreCriteria* criteria : ignore_criteria_) { if (criteria->IsIgnored(message1, message2, field, parent_fields)) { return true; } @@ -1437,7 +1383,7 @@ bool MessageDifferencer::IsUnknownFieldIgnored( const Message& message1, const Message& message2, const SpecificField& field, const std::vector& parent_fields) { - for (const auto& criteria : ignore_criteria_) { + for (IgnoreCriteria* criteria : ignore_criteria_) { if (criteria->IsUnknownFieldIgnored(message1, message2, field, parent_fields)) { return true; @@ -1640,8 +1586,6 @@ bool MessageDifferencer::CompareUnknownFields( // Build the SpecificField. This is slightly complicated. SpecificField specific_field; - specific_field.message1 = &message1; - specific_field.message2 = &message2; specific_field.unknown_field_number = focus_field->number(); specific_field.unknown_field_type = focus_field->type(); @@ -1744,8 +1688,6 @@ class MaximumMatcher { // match_list1[i] == -1 means the node is not matched. Same with match_list2. MaximumMatcher(int count1, int count2, NodeMatchCallback callback, std::vector* match_list1, std::vector* match_list2); - MaximumMatcher(const MaximumMatcher&) = delete; - MaximumMatcher& operator=(const MaximumMatcher&) = delete; // Find a maximum match and return the number of matched node pairs. // If early_return is true, this method will return 0 immediately when it // finds that not all nodes on the left side can be matched. @@ -1766,6 +1708,7 @@ class MaximumMatcher { std::map, bool> cached_match_results_; std::vector* match_list1_; std::vector* match_list2_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MaximumMatcher); }; MaximumMatcher::MaximumMatcher(int count1, int count2, @@ -1845,7 +1788,7 @@ bool MaximumMatcher::FindArgumentPathDFS(int v, std::vector* visited) { } // namespace bool MessageDifferencer::MatchRepeatedFieldIndices( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* repeated_field, const MapKeyComparator* key_comparator, const std::vector& parent_fields, @@ -1879,7 +1822,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( // Here we use the augmenting path algorithm. auto callback = [&](int i1, int i2) { return IsMatch(repeated_field, key_comparator, &message1, &message2, - unpacked_any, parent_fields, nullptr, i1, i2); + parent_fields, nullptr, i1, i2); }; MaximumMatcher matcher(count1, count2, std::move(callback), match_list1, match_list2); @@ -1898,7 +1841,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( start_offset = std::min(count1, count2); for (int i = 0; i < count1 && i < count2; i++) { if (IsMatch(repeated_field, key_comparator, &message1, &message2, - unpacked_any, parent_fields, nullptr, i, i)) { + parent_fields, nullptr, i, i)) { match_list1->at(i) = i; match_list2->at(i) = i; } else { @@ -1922,12 +1865,11 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( if (is_treated_as_smart_set) { num_diffs_reporter.Reset(); - match = - IsMatch(repeated_field, key_comparator, &message1, &message2, - unpacked_any, parent_fields, &num_diffs_reporter, i, j); + match = IsMatch(repeated_field, key_comparator, &message1, &message2, + parent_fields, &num_diffs_reporter, i, j); } else { match = IsMatch(repeated_field, key_comparator, &message1, &message2, - unpacked_any, parent_fields, nullptr, i, j); + parent_fields, nullptr, i, j); } if (is_treated_as_smart_set) { @@ -2058,18 +2000,19 @@ void MessageDifferencer::StreamReporter::PrintPath( continue; } } else { - printer_->PrintRaw(absl::StrCat(specific_field.unknown_field_number)); + printer_->PrintRaw(StrCat(specific_field.unknown_field_number)); } if (left_side && specific_field.index >= 0) { - printer_->Print("[$name$]", "name", absl::StrCat(specific_field.index)); + printer_->Print("[$name$]", "name", StrCat(specific_field.index)); } if (!left_side && specific_field.new_index >= 0) { printer_->Print("[$name$]", "name", - absl::StrCat(specific_field.new_index)); + StrCat(specific_field.new_index)); } } } + void MessageDifferencer::StreamReporter::PrintValue( const Message& message, const std::vector& field_path, bool left_side) { @@ -2129,19 +2072,19 @@ void MessageDifferencer::StreamReporter::PrintUnknownFieldValue( std::string output; switch (unknown_field->type()) { case UnknownField::TYPE_VARINT: - output = absl::StrCat(unknown_field->varint()); + output = StrCat(unknown_field->varint()); break; case UnknownField::TYPE_FIXED32: - output = absl::StrCat( - "0x", absl::Hex(unknown_field->fixed32(), absl::kZeroPad8)); + output = StrCat( + "0x", strings::Hex(unknown_field->fixed32(), strings::ZERO_PAD_8)); break; case UnknownField::TYPE_FIXED64: - output = absl::StrCat( - "0x", absl::Hex(unknown_field->fixed64(), absl::kZeroPad16)); + output = StrCat( + "0x", strings::Hex(unknown_field->fixed64(), strings::ZERO_PAD_16)); break; case UnknownField::TYPE_LENGTH_DELIMITED: - output = absl::StrFormat( - "\"%s\"", absl::CEscape(unknown_field->length_delimited()).c_str()); + output = StringPrintf( + "\"%s\"", CEscape(unknown_field->length_delimited()).c_str()); break; case UnknownField::TYPE_GROUP: // TODO(kenton): Print the contents of the group like we do for @@ -2183,7 +2126,7 @@ void MessageDifferencer::StreamReporter::PrintMapKey( if (key_string.empty()) { key_string = "''"; } - printer_->PrintRaw(absl::StrCat("[", key_string, "]")); + printer_->PrintRaw(StrCat("[", key_string, "]")); } } diff --git a/libs/protobuf/src/google/protobuf/util/message_differencer.h b/libs/protobuf/src/google/protobuf/util/message_differencer.h index 1985574..f63cd54 100644 --- a/libs/protobuf/src/google/protobuf/util/message_differencer.h +++ b/libs/protobuf/src/google/protobuf/util/message_differencer.h @@ -51,15 +51,13 @@ #include #include -#include "google/protobuf/descriptor.h" // FieldDescriptor -#include "google/protobuf/message.h" // Message -#include "google/protobuf/unknown_field_set.h" -#include "google/protobuf/stubs/common.h" -#include "absl/container/fixed_array.h" -#include "google/protobuf/util/field_comparator.h" +#include // FieldDescriptor +#include // Message +#include +#include // Always include as last one, otherwise it can break compilation -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -81,7 +79,7 @@ class FieldContext; // declared below MessageDifferencer // In case of internal google codebase we are using absl::FixedArray instead // of vector. It significantly speeds up proto comparison (by ~30%) by // reducing the number of malloc/free operations -typedef absl::FixedArray FieldDescriptorArray; +typedef std::vector FieldDescriptorArray; // A basic differencer that can be used to determine // the differences between two specified Protocol Messages. If any differences @@ -179,22 +177,6 @@ class PROTOBUF_EXPORT MessageDifferencer { // Identifies an individual field in a message instance. Used for field_path, // below. struct SpecificField { - // The messages that contain this field. They are always set. They are valid - // only during a call to Reporter::Report* methods. - // - // If the original messages are of type google.protobuf.Any, these fields - // will store the unpacked payloads, and unpacked_any will become > 0. More - // precisely, unpacked_any defines the nesting level of Any. For example, - // if the original message packs another Any, then unpacked_any=2, assuming - // the differencer unpacked both of them. - // - // When an Any object packs a non-Any proto object whose field includes - // Any, then unpacked_any=1. Thus, in most practical applications, - // unpacked_any will be 0 or 1. - const Message* message1 = nullptr; - const Message* message2 = nullptr; - int unpacked_any = 0; - // For known fields, "field" is filled in and "unknown_field_number" is -1. // For unknown fields, "field" is NULL, "unknown_field_number" is the field // number, and "unknown_field_type" is its type. @@ -256,22 +238,21 @@ class PROTOBUF_EXPORT MessageDifferencer { class PROTOBUF_EXPORT Reporter { public: Reporter(); - Reporter(const Reporter&) = delete; - Reporter& operator=(const Reporter&) = delete; virtual ~Reporter(); // Reports that a field has been added into Message2. virtual void ReportAdded(const Message& message1, const Message& message2, - const std::vector& field_path) {} + const std::vector& field_path) = 0; // Reports that a field has been deleted from Message1. - virtual void ReportDeleted(const Message& message1, const Message& message2, - const std::vector& field_path) {} + virtual void ReportDeleted( + const Message& message1, const Message& message2, + const std::vector& field_path) = 0; // Reports that the value of a field has been modified. - virtual void ReportModified(const Message& message1, - const Message& message2, - const std::vector& field_path) {} + virtual void ReportModified( + const Message& message1, const Message& message2, + const std::vector& field_path) = 0; // Reports that a repeated field has been moved to another location. This // only applies when using TreatAsSet or TreatAsMap() -- see below. Also @@ -319,6 +300,9 @@ class PROTOBUF_EXPORT MessageDifferencer { virtual void ReportUnknownFieldIgnored( const Message& /* message1 */, const Message& /* message2 */, const std::vector& /* field_path */) {} + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reporter); }; // MapKeyComparator is used to determine if two elements have the same key @@ -326,25 +310,17 @@ class PROTOBUF_EXPORT MessageDifferencer { class PROTOBUF_EXPORT MapKeyComparator { public: MapKeyComparator(); - MapKeyComparator(const MapKeyComparator&) = delete; - MapKeyComparator& operator=(const MapKeyComparator&) = delete; virtual ~MapKeyComparator(); - // This method should be overridden by every implementation. The arg - // unmapped_any is nonzero the original messages provided by the user are of - // type google.protobuf.Any. - // - // More precisely, unpacked_any defines the nesting level of Any. For - // example, if Any packs another Any then unpacked_any=2, assuming the - // patcher unpacked both. Note that when an Any object packs a non-Any - // proto object whose field includes Any, then unpacked_any=1. Thus, in most - // practical applications, unpacked_any will be 0 or 1. - virtual bool IsMatch(const Message& message1, const Message& message2, - int /* unmapped_any */, - const std::vector& fields) const { + virtual bool IsMatch( + const Message& /* message1 */, const Message& /* message2 */, + const std::vector& /* parent_fields */) const { GOOGLE_CHECK(false) << "IsMatch() is not implemented."; return false; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapKeyComparator); }; // Abstract base class from which all IgnoreCriteria derive. @@ -378,8 +354,6 @@ class PROTOBUF_EXPORT MessageDifferencer { // To add a Reporter, construct default here, then use ReportDifferencesTo or // ReportDifferencesToString. explicit MessageDifferencer(); - MessageDifferencer(const MessageDifferencer&) = delete; - MessageDifferencer& operator=(const MessageDifferencer&) = delete; ~MessageDifferencer(); @@ -529,10 +503,7 @@ class PROTOBUF_EXPORT MessageDifferencer { // Add a custom ignore criteria that is evaluated in addition to the // ignored fields added with IgnoreField. // Takes ownership of ignore_criteria. - void AddIgnoreCriteria(IgnoreCriteria* ignore_criteria) { - AddIgnoreCriteria(absl::WrapUnique(ignore_criteria)); - } - void AddIgnoreCriteria(std::unique_ptr ignore_criteria); + void AddIgnoreCriteria(IgnoreCriteria* ignore_criteria); // Indicates that any field with the given descriptor should be // ignored for the purposes of comparing two messages. This applies @@ -553,9 +524,9 @@ class PROTOBUF_EXPORT MessageDifferencer { // Note that this method must be called before Compare for the comparator to // be used. void set_field_comparator(FieldComparator* comparator); -#ifdef PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR +#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES void set_field_comparator(DefaultFieldComparator* comparator); -#endif // PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR +#endif // PROTOBUF_FUTURE_BREAKING_CHANGES // DEPRECATED. Pass a DefaultFieldComparator instance instead. // Sets the fraction and margin for the float comparison of a given field. @@ -677,8 +648,6 @@ class PROTOBUF_EXPORT MessageDifferencer { public: explicit StreamReporter(io::ZeroCopyOutputStream* output); explicit StreamReporter(io::Printer* printer); // delimiter '$' - StreamReporter(const StreamReporter&) = delete; - StreamReporter& operator=(const StreamReporter&) = delete; ~StreamReporter() override; // When set to true, the stream reporter will also output aggregates nodes @@ -746,6 +715,7 @@ class PROTOBUF_EXPORT MessageDifferencer { const Message* message1_; const Message* message2_; MessageDifferencer::UnpackAnyField unpack_any_field_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StreamReporter); }; private: @@ -762,7 +732,7 @@ class PROTOBUF_EXPORT MessageDifferencer { public: explicit MapEntryKeyComparator(MessageDifferencer* message_differencer); bool IsMatch( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const std::vector& parent_fields) const override; private: @@ -792,7 +762,7 @@ class PROTOBUF_EXPORT MessageDifferencer { // (i.e. if the current message is an embedded message, the parent_fields // vector will contain the field that has this embedded message). bool Compare(const Message& message1, const Message& message2, - int unpacked_any, std::vector* parent_fields); + std::vector* parent_fields); // Compares all the unknown fields in two messages. bool CompareUnknownFields(const Message& message1, const Message& message2, @@ -803,47 +773,46 @@ class PROTOBUF_EXPORT MessageDifferencer { // lists are modified depending on comparison settings, and then passed to // CompareWithFieldsInternal. bool CompareRequestedFieldsUsingSettings( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptorArray& message1_fields, const FieldDescriptorArray& message2_fields, std::vector* parent_fields); // Compares the specified messages with the specified field lists. bool CompareWithFieldsInternal(const Message& message1, - const Message& message2, int unpacked_any, + const Message& message2, const FieldDescriptorArray& message1_fields, const FieldDescriptorArray& message2_fields, std::vector* parent_fields); // Compares the repeated fields, and report the error. bool CompareRepeatedField(const Message& message1, const Message& message2, - int unpacked_any, const FieldDescriptor* field, + const FieldDescriptor* field, std::vector* parent_fields); // Compares map fields, and report the error. bool CompareMapField(const Message& message1, const Message& message2, - int unpacked_any, const FieldDescriptor* field, + const FieldDescriptor* field, std::vector* parent_fields); // Helper for CompareRepeatedField and CompareMapField: compares and reports // differences element-wise. This is the implementation for non-map fields, // and can also compare map fields by using the underlying representation. bool CompareRepeatedRep(const Message& message1, const Message& message2, - int unpacked_any, const FieldDescriptor* field, + const FieldDescriptor* field, std::vector* parent_fields); // Helper for CompareMapField: compare the map fields using map reflection // instead of sync to repeated. bool CompareMapFieldByMapReflection(const Message& message1, - const Message& message2, int unpacked_any, + const Message& message2, const FieldDescriptor* field, std::vector* parent_fields, DefaultFieldComparator* comparator); // Shorthand for CompareFieldValueUsingParentFields with NULL parent_fields. bool CompareFieldValue(const Message& message1, const Message& message2, - int unpacked_any, const FieldDescriptor* field, - int index1, int index2); + const FieldDescriptor* field, int index1, int index2); // Compares the specified field on the two messages, returning // true if they are the same, false otherwise. For repeated fields, @@ -855,7 +824,7 @@ class PROTOBUF_EXPORT MessageDifferencer { // To avoid confusing users you should not set it to NULL unless you modified // Reporter to handle the change of parent_fields correctly. bool CompareFieldValueUsingParentFields( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* field, int index1, int index2, std::vector* parent_fields); @@ -871,7 +840,7 @@ class PROTOBUF_EXPORT MessageDifferencer { // elements are equal. bool IsMatch(const FieldDescriptor* repeated_field, const MapKeyComparator* key_comparator, const Message* message1, - const Message* message2, int unpacked_any, + const Message* message2, const std::vector& parent_fields, Reporter* reporter, int index1, int index2); @@ -919,7 +888,7 @@ class PROTOBUF_EXPORT MessageDifferencer { // that the comparison succeeds when this method returns true (you need to // double-check in this case). bool MatchRepeatedFieldIndices( - const Message& message1, const Message& message2, int unpacked_any, + const Message& message1, const Message& message2, const FieldDescriptor* repeated_field, const MapKeyComparator* key_comparator, const std::vector& parent_fields, @@ -960,7 +929,7 @@ class PROTOBUF_EXPORT MessageDifferencer { std::vector owned_key_comparators_; FieldKeyComparatorMap map_field_key_comparator_; MapEntryKeyComparator map_entry_key_comparator_; - std::vector> ignore_criteria_; + std::vector ignore_criteria_; // Reused multiple times in RetrieveFields to avoid extra allocations std::vector tmp_message_fields_; @@ -983,6 +952,7 @@ class PROTOBUF_EXPORT MessageDifferencer { match_indices_for_smart_list_callback_; MessageDifferencer::UnpackAnyField unpack_any_field_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageDifferencer); }; // This class provides extra information to the FieldComparator::Compare @@ -1005,6 +975,6 @@ class PROTOBUF_EXPORT FieldContext { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/message_differencer_unittest.cc b/libs/protobuf/src/google/protobuf/util/message_differencer_unittest.cc index 8dbe947..f8e44df 100644 --- a/libs/protobuf/src/google/protobuf/util/message_differencer_unittest.cc +++ b/libs/protobuf/src/google/protobuf/util/message_differencer_unittest.cc @@ -39,25 +39,25 @@ #include #include -#include "google/protobuf/stubs/common.h" +#include -#include "google/protobuf/stubs/strutil.h" +#include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/any_test.pb.h" -#include "google/protobuf/map_test_util.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/util/field_comparator.h" -#include "google/protobuf/util/message_differencer.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "absl/functional/bind_front.h" -#include "absl/strings/str_split.h" -#include "google/protobuf/util/message_differencer_unittest.pb.h" namespace google { namespace protobuf { @@ -68,7 +68,7 @@ namespace { const FieldDescriptor* GetFieldDescriptor(const Message& message, const std::string& field_name) { std::vector field_path = - absl::StrSplit(field_name, ".", absl::SkipEmpty()); + Split(field_name, ".", true); const Descriptor* descriptor = message.GetDescriptor(); const FieldDescriptor* field = nullptr; for (int i = 0; i < field_path.size(); i++) { @@ -1869,7 +1869,7 @@ class TestIgnorer : public util::MessageDifferencer::IgnoreCriteria { name += parent_fields[i].field->name() + "."; } name += field->name(); - for (int i = 0; i < ABSL_ARRAYSIZE(kIgnoredFields); ++i) { + for (int i = 0; i < GOOGLE_ARRAYSIZE(kIgnoredFields); ++i) { if (name.compare(kIgnoredFields[i]) == 0) { return true; } @@ -1907,7 +1907,6 @@ class ValueProductMapKeyComparator public: typedef util::MessageDifferencer::SpecificField SpecificField; bool IsMatch(const Message& message1, const Message& message2, - int unpacked_any, const std::vector& parent_fields) const override { const Reflection* reflection1 = message1.GetReflection(); const Reflection* reflection2 = message2.GetReflection(); @@ -1969,7 +1968,6 @@ class OffsetByOneMapKeyComparator public: typedef util::MessageDifferencer::SpecificField SpecificField; bool IsMatch(const Message& message1, const Message& message2, - int unpacked_any, const std::vector& parent_fields) const override { return parent_fields.back().index + 1 == parent_fields.back().new_index; } @@ -3404,7 +3402,6 @@ class LengthMapKeyComparator public: typedef util::MessageDifferencer::SpecificField SpecificField; bool IsMatch(const Message& message1, const Message& message2, - int unpacked_any, const std::vector& parent_fields) const override { const Reflection* reflection1 = message1.GetReflection(); const Reflection* reflection2 = message2.GetReflection(); @@ -3475,6 +3472,9 @@ class MatchingTest : public testing::Test { } return output; } + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MatchingTest); }; TEST_F(MatchingTest, StreamReporterMatching) { diff --git a/libs/protobuf/src/google/protobuf/util/time_util.cc b/libs/protobuf/src/google/protobuf/util/time_util.cc index 0d5a173..9893aa3 100644 --- a/libs/protobuf/src/google/protobuf/util/time_util.cc +++ b/libs/protobuf/src/google/protobuf/util/time_util.cc @@ -28,21 +28,19 @@ // (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/util/time_util.h" +#include #include -#include "google/protobuf/stubs/strutil.h" -#include "google/protobuf/duration.pb.h" -#include "google/protobuf/timestamp.pb.h" -#include "absl/numeric/int128.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" -#include "absl/time/clock.h" -#include "absl/time/time.h" +#include +#include +#include +#include +#include +#include // Must go after other includes. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -52,24 +50,19 @@ using google::protobuf::Duration; using google::protobuf::Timestamp; namespace { -static constexpr int32_t kNanosPerSecond = 1000000000; -static constexpr int32_t kMicrosPerSecond = 1000000; -static constexpr int32_t kMillisPerSecond = 1000; -static constexpr int32_t kNanosPerMillisecond = 1000000; -static constexpr int32_t kNanosPerMicrosecond = 1000; -static constexpr int32_t kSecondsPerMinute = - 60; // Note that we ignore leap seconds. -static constexpr int32_t kSecondsPerHour = 3600; +static const int kNanosPerSecond = 1000000000; +static const int kMicrosPerSecond = 1000000; +static const int kMillisPerSecond = 1000; +static const int kNanosPerMillisecond = 1000000; +static const int kNanosPerMicrosecond = 1000; +static const int kSecondsPerMinute = 60; // Note that we ignore leap seconds. +static const int kSecondsPerHour = 3600; template -T CreateNormalized(int64_t seconds, int32_t nanos); +T CreateNormalized(int64_t seconds, int64_t nanos); template <> -Timestamp CreateNormalized(int64_t seconds, int32_t nanos) { - GOOGLE_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds && - seconds <= TimeUtil::kTimestampMaxSeconds) - << "Timestamp seconds are outside of the valid range"; - +Timestamp CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -80,12 +73,8 @@ Timestamp CreateNormalized(int64_t seconds, int32_t nanos) { seconds -= 1; nanos += kNanosPerSecond; } - GOOGLE_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds && - seconds <= TimeUtil::kTimestampMaxSeconds && - nanos >= TimeUtil::kTimestampMinNanoseconds && - nanos <= TimeUtil::kTimestampMaxNanoseconds) - << "Timestamp is outside of the valid range"; + seconds <= TimeUtil::kTimestampMaxSeconds); Timestamp result; result.set_seconds(seconds); result.set_nanos(static_cast(nanos)); @@ -93,11 +82,7 @@ Timestamp CreateNormalized(int64_t seconds, int32_t nanos) { } template <> -Duration CreateNormalized(int64_t seconds, int32_t nanos) { - GOOGLE_DCHECK(seconds >= TimeUtil::kDurationMinSeconds && - seconds <= TimeUtil::kDurationMaxSeconds) - << "Duration seconds are outside of the valid range"; - +Duration CreateNormalized(int64_t seconds, int64_t nanos) { // Make sure nanos is in the range. if (nanos <= -kNanosPerSecond || nanos >= kNanosPerSecond) { seconds += nanos / kNanosPerSecond; @@ -111,12 +96,8 @@ Duration CreateNormalized(int64_t seconds, int32_t nanos) { seconds -= 1; nanos += kNanosPerSecond; } - GOOGLE_DCHECK(seconds >= TimeUtil::kDurationMinSeconds && - seconds <= TimeUtil::kDurationMaxSeconds && - nanos >= TimeUtil::kDurationMinNanoseconds && - nanos <= TimeUtil::kDurationMaxNanoseconds) - << "Duration is outside of the valid range"; + seconds <= TimeUtil::kDurationMaxSeconds); Duration result; result.set_seconds(seconds); result.set_nanos(static_cast(nanos)); @@ -127,49 +108,24 @@ Duration CreateNormalized(int64_t seconds, int32_t nanos) { // precision to represent the exact value. std::string FormatNanos(int32_t nanos) { if (nanos % kNanosPerMillisecond == 0) { - return absl::StrFormat("%03d", nanos / kNanosPerMillisecond); + return StringPrintf("%03d", nanos / kNanosPerMillisecond); } else if (nanos % kNanosPerMicrosecond == 0) { - return absl::StrFormat("%06d", nanos / kNanosPerMicrosecond); + return StringPrintf("%06d", nanos / kNanosPerMicrosecond); } else { - return absl::StrFormat("%09d", nanos); + return StringPrintf("%09d", nanos); } } std::string FormatTime(int64_t seconds, int32_t nanos) { - static const char kTimestampFormat[] = "%E4Y-%m-%dT%H:%M:%S"; - - timespec spec; - spec.tv_sec = seconds; - // We only use absl::FormatTime to format the seconds part because we need - // finer control over the precision of nanoseconds. - spec.tv_nsec = 0; - std::string result = absl::FormatTime( - kTimestampFormat, absl::TimeFromTimespec(spec), absl::UTCTimeZone()); - // We format the nanoseconds part separately to meet the precision - // requirement. - if (nanos != 0) { - result += "." + FormatNanos(nanos); - } - result += "Z"; - return result; + return ::google::protobuf::internal::FormatTime(seconds, nanos); } bool ParseTime(const std::string& value, int64_t* seconds, int32_t* nanos) { - absl::Time result; - if (!absl::ParseTime(absl::RFC3339_full, value, &result, nullptr)) { - return false; - } - timespec spec = absl::ToTimespec(result); - *seconds = spec.tv_sec; - *nanos = spec.tv_nsec; - return true; + return ::google::protobuf::internal::ParseTime(value, seconds, nanos); } void CurrentTime(int64_t* seconds, int32_t* nanos) { - absl::Time now = absl::Now(); - timespec spec = absl::ToTimespec(now); - *seconds = spec.tv_sec; - *nanos = spec.tv_nsec; + return ::google::protobuf::internal::GetCurrentTime(seconds, nanos); } // Truncates the remainder part after division. @@ -192,14 +148,10 @@ int64_t RoundTowardZero(int64_t value, int64_t divider) { // Actually define these static const integers. Required by C++ standard (but // some compilers don't like it). #ifndef _MSC_VER -constexpr int64_t TimeUtil::kTimestampMinSeconds; -constexpr int64_t TimeUtil::kTimestampMaxSeconds; -constexpr int32_t TimeUtil::kTimestampMinNanoseconds; -constexpr int32_t TimeUtil::kTimestampMaxNanoseconds; -constexpr int64_t TimeUtil::kDurationMaxSeconds; -constexpr int64_t TimeUtil::kDurationMinSeconds; -constexpr int32_t TimeUtil::kDurationMaxNanoseconds; -constexpr int32_t TimeUtil::kDurationMinNanoseconds; +const int64_t TimeUtil::kTimestampMinSeconds; +const int64_t TimeUtil::kTimestampMaxSeconds; +const int64_t TimeUtil::kDurationMaxSeconds; +const int64_t TimeUtil::kDurationMinSeconds; #endif // !_MSC_VER std::string TimeUtil::ToString(const Timestamp& timestamp) { @@ -234,7 +186,7 @@ std::string TimeUtil::ToString(const Duration& duration) { seconds = -seconds; nanos = -nanos; } - result += absl::StrCat(seconds); + result += StrCat(seconds); if (nanos != 0) { result += "." + FormatNanos(nanos); } @@ -309,43 +261,37 @@ Duration TimeUtil::SecondsToDuration(int64_t seconds) { } Duration TimeUtil::MinutesToDuration(int64_t minutes) { - GOOGLE_DCHECK(minutes >= TimeUtil::kDurationMinSeconds / kSecondsPerMinute && - minutes <= TimeUtil::kDurationMaxSeconds / kSecondsPerMinute) - << "Duration minutes are outside of the valid range"; - return SecondsToDuration(minutes * kSecondsPerMinute); + return CreateNormalized(minutes * kSecondsPerMinute, 0); } Duration TimeUtil::HoursToDuration(int64_t hours) { - GOOGLE_DCHECK(hours >= TimeUtil::kDurationMinSeconds / kSecondsPerHour && - hours <= TimeUtil::kDurationMaxSeconds / kSecondsPerHour) - << "Duration hours are outside of the valid range"; - return SecondsToDuration(hours * kSecondsPerHour); + return CreateNormalized(hours * kSecondsPerHour, 0); } int64_t TimeUtil::DurationToNanoseconds(const Duration& duration) { - GOOGLE_DCHECK(IsDurationValid(duration)) << "Duration is outside of the valid range"; return duration.seconds() * kNanosPerSecond + duration.nanos(); } int64_t TimeUtil::DurationToMicroseconds(const Duration& duration) { - return RoundTowardZero(DurationToNanoseconds(duration), kNanosPerMicrosecond); + return duration.seconds() * kMicrosPerSecond + + RoundTowardZero(duration.nanos(), kNanosPerMicrosecond); } int64_t TimeUtil::DurationToMilliseconds(const Duration& duration) { - return RoundTowardZero(DurationToNanoseconds(duration), kNanosPerMillisecond); + return duration.seconds() * kMillisPerSecond + + RoundTowardZero(duration.nanos(), kNanosPerMillisecond); } int64_t TimeUtil::DurationToSeconds(const Duration& duration) { - GOOGLE_DCHECK(IsDurationValid(duration)) << "Duration is outside of the valid range"; return duration.seconds(); } int64_t TimeUtil::DurationToMinutes(const Duration& duration) { - return RoundTowardZero(DurationToSeconds(duration), kSecondsPerMinute); + return RoundTowardZero(duration.seconds(), kSecondsPerMinute); } int64_t TimeUtil::DurationToHours(const Duration& duration) { - return RoundTowardZero(DurationToSeconds(duration), kSecondsPerHour); + return RoundTowardZero(duration.seconds(), kSecondsPerHour); } Timestamp TimeUtil::NanosecondsToTimestamp(int64_t nanos) { @@ -370,28 +316,20 @@ Timestamp TimeUtil::SecondsToTimestamp(int64_t seconds) { } int64_t TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) { - GOOGLE_DCHECK(IsTimestampValid(timestamp)) - << "Timestamp is outside of the valid range"; return timestamp.seconds() * kNanosPerSecond + timestamp.nanos(); } int64_t TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) { - GOOGLE_DCHECK(IsTimestampValid(timestamp)) - << "Timestamp is outside of the valid range"; return timestamp.seconds() * kMicrosPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMicrosecond); } int64_t TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) { - GOOGLE_DCHECK(IsTimestampValid(timestamp)) - << "Timestamp is outside of the valid range"; return timestamp.seconds() * kMillisPerSecond + RoundTowardZero(timestamp.nanos(), kNanosPerMillisecond); } int64_t TimeUtil::TimestampToSeconds(const Timestamp& timestamp) { - GOOGLE_DCHECK(IsTimestampValid(timestamp)) - << "Timestamp is outside of the valid range"; return timestamp.seconds(); } @@ -443,7 +381,7 @@ using ::PROTOBUF_NAMESPACE_ID::util::CreateNormalized; using ::PROTOBUF_NAMESPACE_ID::util::kNanosPerSecond; // Convert a Duration to uint128. -void ToUint128(const Duration& value, absl::uint128* result, bool* negative) { +void ToUint128(const Duration& value, uint128* result, bool* negative) { if (value.seconds() < 0 || value.nanos() < 0) { *negative = true; *result = static_cast(-value.seconds()); @@ -455,11 +393,11 @@ void ToUint128(const Duration& value, absl::uint128* result, bool* negative) { } } -void ToDuration(const absl::uint128& value, bool negative, Duration* duration) { +void ToDuration(const uint128& value, bool negative, Duration* duration) { int64_t seconds = - static_cast(absl::Uint128Low64(value / kNanosPerSecond)); + static_cast(Uint128Low64(value / kNanosPerSecond)); int32_t nanos = - static_cast(absl::Uint128Low64(value % kNanosPerSecond)); + static_cast(Uint128Low64(value % kNanosPerSecond)); if (negative) { seconds = -seconds; nanos = -nanos; @@ -483,7 +421,7 @@ Duration& operator-=(Duration& d1, const Duration& d2) { // NOLINT Duration& operator*=(Duration& d, int64_t r) { // NOLINT bool negative; - absl::uint128 value; + uint128 value; ToUint128(d, &value, &negative); if (r > 0) { value *= static_cast(r); @@ -512,7 +450,7 @@ Duration& operator*=(Duration& d, double r) { // NOLINT Duration& operator/=(Duration& d, int64_t r) { // NOLINT bool negative; - absl::uint128 value; + uint128 value; ToUint128(d, &value, &negative); if (r > 0) { value /= static_cast(r); @@ -530,10 +468,10 @@ Duration& operator/=(Duration& d, double r) { // NOLINT Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT bool negative1, negative2; - absl::uint128 value1, value2; + uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - absl::uint128 result = value1 % value2; + uint128 result = value1 % value2; // When negative values are involved in division, we round the division // result towards zero. With this semantics, sign of the remainder is the // same as the dividend. For example: @@ -546,10 +484,10 @@ Duration& operator%=(Duration& d1, const Duration& d2) { // NOLINT int64_t operator/(const Duration& d1, const Duration& d2) { bool negative1, negative2; - absl::uint128 value1, value2; + uint128 value1, value2; ToUint128(d1, &value1, &negative1); ToUint128(d2, &value2, &negative2); - int64_t result = absl::Uint128Low64(value1 / value2); + int64_t result = Uint128Low64(value1 / value2); if (negative1 != negative2) { result = -result; } diff --git a/libs/protobuf/src/google/protobuf/util/time_util.h b/libs/protobuf/src/google/protobuf/util/time_util.h index c272199..709527e 100644 --- a/libs/protobuf/src/google/protobuf/util/time_util.h +++ b/libs/protobuf/src/google/protobuf/util/time_util.h @@ -50,11 +50,11 @@ struct timeval { #include #endif -#include "google/protobuf/duration.pb.h" -#include "google/protobuf/timestamp.pb.h" +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -69,31 +69,11 @@ class PROTOBUF_EXPORT TimeUtil { // The min/max Timestamp/Duration values we support. // // For "0001-01-01T00:00:00Z". - static constexpr int64_t kTimestampMinSeconds = -62135596800LL; + static const int64_t kTimestampMinSeconds = -62135596800LL; // For "9999-12-31T23:59:59.999999999Z". - static constexpr int64_t kTimestampMaxSeconds = 253402300799LL; - static constexpr int32_t kTimestampMinNanoseconds = 0; - static constexpr int32_t kTimestampMaxNanoseconds = 999999999; - static constexpr int64_t kDurationMinSeconds = -315576000000LL; - static constexpr int64_t kDurationMaxSeconds = 315576000000LL; - static constexpr int32_t kDurationMinNanoseconds = -999999999; - static constexpr int32_t kDurationMaxNanoseconds = 999999999; - - static bool IsTimestampValid(const Timestamp& timestamp) { - return timestamp.seconds() <= kTimestampMaxSeconds && - timestamp.seconds() >= kTimestampMinSeconds && - timestamp.nanos() <= kTimestampMaxNanoseconds && - timestamp.nanos() >= kTimestampMinNanoseconds; - } - - static bool IsDurationValid(const Duration& duration) { - return duration.seconds() <= kDurationMaxSeconds && - duration.seconds() >= kDurationMinSeconds && - duration.nanos() <= kDurationMaxNanoseconds && - duration.nanos() >= kDurationMinNanoseconds && - !(duration.seconds() >= 1 && duration.nanos() < 0) && - !(duration.seconds() <= -1 && duration.nanos() > 0); - } + static const int64_t kTimestampMaxSeconds = 253402300799LL; + static const int64_t kDurationMinSeconds = -315576000000LL; + static const int64_t kDurationMaxSeconds = 315576000000LL; // Converts Timestamp to/from RFC 3339 date string format. // Generated output will always be Z-normalized and uses 3, 6 or 9 @@ -122,6 +102,9 @@ class PROTOBUF_EXPORT TimeUtil { static std::string ToString(const Duration& duration); static bool FromString(const std::string& value, Duration* timestamp); +#ifdef GetCurrentTime +#undef GetCurrentTime // Visual Studio has macro GetCurrentTime +#endif // Gets the current UTC time. static Timestamp GetCurrentTime(); // Returns the Time representing "1970-01-01 00:00:00". @@ -326,6 +309,6 @@ inline std::ostream& operator<<(std::ostream& out, const Timestamp& t) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/util/time_util_test.cc b/libs/protobuf/src/google/protobuf/util/time_util_test.cc index dceb6db..79e2427 100644 --- a/libs/protobuf/src/google/protobuf/util/time_util_test.cc +++ b/libs/protobuf/src/google/protobuf/util/time_util_test.cc @@ -28,14 +28,14 @@ // (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/util/time_util.h" +#include #include #include -#include "google/protobuf/duration.pb.h" -#include "google/protobuf/timestamp.pb.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include #include namespace google { @@ -48,18 +48,15 @@ using google::protobuf::Timestamp; namespace { TEST(TimeUtilTest, TimestampStringFormat) { - // These these are out of bounds for 32-bit architectures. - if(sizeof(time_t) >= sizeof(uint64_t)) { - Timestamp begin, end; - EXPECT_TRUE(TimeUtil::FromString("0001-01-01T00:00:00Z", &begin)); - EXPECT_EQ(TimeUtil::kTimestampMinSeconds, begin.seconds()); - EXPECT_EQ(0, begin.nanos()); - EXPECT_TRUE(TimeUtil::FromString("9999-12-31T23:59:59.999999999Z", &end)); - EXPECT_EQ(TimeUtil::kTimestampMaxSeconds, end.seconds()); - EXPECT_EQ(999999999, end.nanos()); - EXPECT_EQ("0001-01-01T00:00:00Z", TimeUtil::ToString(begin)); - EXPECT_EQ("9999-12-31T23:59:59.999999999Z", TimeUtil::ToString(end)); - } + Timestamp begin, end; + EXPECT_TRUE(TimeUtil::FromString("0001-01-01T00:00:00Z", &begin)); + EXPECT_EQ(TimeUtil::kTimestampMinSeconds, begin.seconds()); + EXPECT_EQ(0, begin.nanos()); + EXPECT_TRUE(TimeUtil::FromString("9999-12-31T23:59:59.999999999Z", &end)); + EXPECT_EQ(TimeUtil::kTimestampMaxSeconds, end.seconds()); + EXPECT_EQ(999999999, end.nanos()); + EXPECT_EQ("0001-01-01T00:00:00Z", TimeUtil::ToString(begin)); + EXPECT_EQ("9999-12-31T23:59:59.999999999Z", TimeUtil::ToString(end)); // Test negative timestamps. Timestamp time = TimeUtil::NanosecondsToTimestamp(-1); @@ -97,12 +94,9 @@ TEST(TimeUtilTest, DurationStringFormat) { EXPECT_TRUE(TimeUtil::FromString("0001-01-01T00:00:00Z", &begin)); EXPECT_TRUE(TimeUtil::FromString("9999-12-31T23:59:59.999999999Z", &end)); - // These these are out of bounds for 32-bit architectures. - if(sizeof(time_t) >= sizeof(uint64_t)) { - EXPECT_EQ("315537897599.999999999s", TimeUtil::ToString(end - begin)); - EXPECT_EQ("-315537897599.999999999s", TimeUtil::ToString(begin - end)); - } + EXPECT_EQ("315537897599.999999999s", TimeUtil::ToString(end - begin)); EXPECT_EQ(999999999, (end - begin).nanos()); + EXPECT_EQ("-315537897599.999999999s", TimeUtil::ToString(begin - end)); EXPECT_EQ(-999999999, (begin - end).nanos()); // Generated output should contain 3, 6, or 9 fractional digits. @@ -384,147 +378,6 @@ TEST(TimeUtilTest, TimestampOperators) { EXPECT_TRUE(t2 != t1); } -TEST(TimeUtilTest, IsDurationValid) { - Duration valid; - Duration overflow; - overflow.set_seconds(TimeUtil::kDurationMaxSeconds + 1); - Duration underflow; - underflow.set_seconds(TimeUtil::kDurationMinSeconds - 1); - Duration overflow_nanos; - overflow_nanos.set_nanos(TimeUtil::kDurationMaxNanoseconds + 1); - Duration underflow_nanos; - underflow_nanos.set_nanos(TimeUtil::kDurationMinNanoseconds - 1); - Duration positive_seconds_negative_nanos; - positive_seconds_negative_nanos.set_seconds(1); - positive_seconds_negative_nanos.set_nanos(-1); - Duration negative_seconds_positive_nanos; - negative_seconds_positive_nanos.set_seconds(-1); - negative_seconds_positive_nanos.set_nanos(1); - - EXPECT_TRUE(TimeUtil::IsDurationValid(valid)); - EXPECT_FALSE(TimeUtil::IsDurationValid(overflow)); - EXPECT_FALSE(TimeUtil::IsDurationValid(underflow)); - EXPECT_FALSE(TimeUtil::IsDurationValid(overflow_nanos)); - EXPECT_FALSE(TimeUtil::IsDurationValid(underflow_nanos)); - EXPECT_FALSE(TimeUtil::IsDurationValid(positive_seconds_negative_nanos)); - EXPECT_FALSE(TimeUtil::IsDurationValid(negative_seconds_positive_nanos)); -} - -TEST(TimeUtilTest, IsTimestampValid) { - Timestamp valid; - Timestamp overflow; - overflow.set_seconds(TimeUtil::kTimestampMaxSeconds + 1); - Timestamp underflow; - underflow.set_seconds(TimeUtil::kTimestampMinSeconds - 1); - Timestamp overflow_nanos; - overflow_nanos.set_nanos(TimeUtil::kTimestampMaxNanoseconds + 1); - Timestamp underflow_nanos; - underflow_nanos.set_nanos(TimeUtil::kTimestampMinNanoseconds - 1); - - EXPECT_TRUE(TimeUtil::IsTimestampValid(valid)); - EXPECT_FALSE(TimeUtil::IsTimestampValid(overflow)); - EXPECT_FALSE(TimeUtil::IsTimestampValid(underflow)); - EXPECT_FALSE(TimeUtil::IsTimestampValid(overflow_nanos)); - EXPECT_FALSE(TimeUtil::IsTimestampValid(underflow_nanos)); -} - -#ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet. -#ifndef NDEBUG - -TEST(TimeUtilTest, DurationBounds) { - Duration overflow; - overflow.set_seconds(TimeUtil::kDurationMaxSeconds + 1); - Duration underflow; - underflow.set_seconds(TimeUtil::kDurationMinSeconds - 1); - Duration overflow_nanos; - overflow_nanos.set_nanos(TimeUtil::kDurationMaxNanoseconds + 1); - Duration underflow_nanos; - underflow_nanos.set_nanos(TimeUtil::kDurationMinNanoseconds - 1); - - EXPECT_DEATH({ TimeUtil::SecondsToDuration(overflow.seconds()); }, - "Duration seconds"); - EXPECT_DEATH({ TimeUtil::SecondsToDuration(underflow.seconds()); }, - "Duration seconds"); - EXPECT_DEATH( - { TimeUtil::MinutesToDuration(overflow.seconds() / 60 + 1); }, - "Duration minutes"); - EXPECT_DEATH( - { TimeUtil::MinutesToDuration(underflow.seconds() / 60 - 1); }, - "Duration minutes"); - EXPECT_DEATH( - { TimeUtil::HoursToDuration(overflow.seconds() / 60 + 1); }, - "Duration hours"); - EXPECT_DEATH( - { TimeUtil::HoursToDuration(underflow.seconds() / 60 - 1); }, - "Duration hours"); - - EXPECT_DEATH({ TimeUtil::DurationToNanoseconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToNanoseconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToNanoseconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToNanoseconds(underflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToSeconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToSeconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToSeconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::DurationToSeconds(underflow_nanos); }, - "outside of the valid range"); -} - -TEST(TimeUtilTest, TimestampBounds) { - Timestamp overflow; - overflow.set_seconds(TimeUtil::kDurationMaxSeconds + 1); - Timestamp underflow; - underflow.set_seconds(TimeUtil::kDurationMinSeconds - 1); - Timestamp overflow_nanos; - overflow_nanos.set_nanos(TimeUtil::kDurationMaxNanoseconds + 1); - Timestamp underflow_nanos; - underflow_nanos.set_nanos(TimeUtil::kDurationMinNanoseconds - 1); - - EXPECT_DEATH({ TimeUtil::TimestampToNanoseconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToNanoseconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToNanoseconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToNanoseconds(underflow_nanos); }, - "outside of the valid range"); - - EXPECT_DEATH({ TimeUtil::TimestampToMicroseconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMicroseconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMicroseconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMicroseconds(underflow_nanos); }, - "outside of the valid range"); - - EXPECT_DEATH({ TimeUtil::TimestampToMilliseconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMilliseconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMilliseconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToMilliseconds(underflow_nanos); }, - "outside of the valid range"); - - EXPECT_DEATH({ TimeUtil::TimestampToSeconds(overflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToSeconds(underflow); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToSeconds(overflow_nanos); }, - "outside of the valid range"); - EXPECT_DEATH({ TimeUtil::TimestampToSeconds(underflow_nanos); }, - "outside of the valid range"); -} -#endif // !NDEBUG -#endif // PROTOBUF_HAS_DEATH_TEST - } // namespace } // namespace util } // namespace protobuf diff --git a/libs/protobuf/src/google/protobuf/util/type_resolver.h b/libs/protobuf/src/google/protobuf/util/type_resolver.h index f5c3338..b2e7b43 100644 --- a/libs/protobuf/src/google/protobuf/util/type_resolver.h +++ b/libs/protobuf/src/google/protobuf/util/type_resolver.h @@ -35,13 +35,13 @@ #include -#include "google/protobuf/type.pb.h" -#include "absl/status/status.h" -#include "google/protobuf/port.h" - +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -54,23 +54,24 @@ namespace util { class PROTOBUF_EXPORT TypeResolver { public: TypeResolver() {} - TypeResolver(const TypeResolver&) = delete; - TypeResolver& operator=(const TypeResolver&) = delete; virtual ~TypeResolver() {} // Resolves a type url for a message type. - virtual absl::Status ResolveMessageType( + virtual util::Status ResolveMessageType( const std::string& type_url, google::protobuf::Type* message_type) = 0; // Resolves a type url for an enum type. - virtual absl::Status ResolveEnumType(const std::string& type_url, + virtual util::Status ResolveEnumType(const std::string& type_url, google::protobuf::Enum* enum_type) = 0; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeResolver); }; } // namespace util } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_H__ diff --git a/libs/protobuf/src/google/protobuf/util/type_resolver_util.cc b/libs/protobuf/src/google/protobuf/util/type_resolver_util.cc index cd01d87..8be0efb 100644 --- a/libs/protobuf/src/google/protobuf/util/type_resolver_util.cc +++ b/libs/protobuf/src/google/protobuf/util/type_resolver_util.cc @@ -28,20 +28,20 @@ // (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/util/type_resolver_util.h" +#include -#include "google/protobuf/type.pb.h" -#include "google/protobuf/wrappers.pb.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/stubs/strutil.h" -#include "absl/status/status.h" -#include "absl/strings/escaping.h" -#include "absl/strings/str_cat.h" -#include "google/protobuf/util/type_resolver.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { @@ -70,38 +70,38 @@ class DescriptorPoolTypeResolver : public TypeResolver { const DescriptorPool* pool) : url_prefix_(url_prefix), pool_(pool) {} - absl::Status ResolveMessageType(const std::string& type_url, + util::Status ResolveMessageType(const std::string& type_url, Type* type) override { std::string type_name; - absl::Status status = ParseTypeUrl(type_url, &type_name); + util::Status status = ParseTypeUrl(type_url, &type_name); if (!status.ok()) { return status; } const Descriptor* descriptor = pool_->FindMessageTypeByName(type_name); if (descriptor == NULL) { - return absl::NotFoundError("Invalid type URL, unknown type: " + + return util::NotFoundError("Invalid type URL, unknown type: " + type_name); } ConvertDescriptor(descriptor, type); - return absl::Status(); + return util::Status(); } - absl::Status ResolveEnumType(const std::string& type_url, + util::Status ResolveEnumType(const std::string& type_url, Enum* enum_type) override { std::string type_name; - absl::Status status = ParseTypeUrl(type_url, &type_name); + util::Status status = ParseTypeUrl(type_url, &type_name); if (!status.ok()) { return status; } const EnumDescriptor* descriptor = pool_->FindEnumTypeByName(type_name); if (descriptor == NULL) { - return absl::InvalidArgumentError("Invalid type URL, unknown type: " + + return util::InvalidArgumentError("Invalid type URL, unknown type: " + type_name); } ConvertEnumDescriptor(descriptor, enum_type); - return absl::Status(); + return util::Status(); } private: @@ -303,30 +303,30 @@ class DescriptorPoolTypeResolver : public TypeResolver { return url_prefix_ + "/" + descriptor->full_name(); } - absl::Status ParseTypeUrl(const std::string& type_url, + util::Status ParseTypeUrl(const std::string& type_url, std::string* type_name) { if (type_url.substr(0, url_prefix_.size() + 1) != url_prefix_ + "/") { - return absl::InvalidArgumentError( - absl::StrCat("Invalid type URL, type URLs must be of the form '", + return util::InvalidArgumentError( + StrCat("Invalid type URL, type URLs must be of the form '", url_prefix_, "/', got: ", type_url)); } *type_name = type_url.substr(url_prefix_.size() + 1); - return absl::Status(); + return util::Status(); } std::string DefaultValueAsString(const FieldDescriptor* descriptor) { switch (descriptor->cpp_type()) { case FieldDescriptor::CPPTYPE_INT32: - return absl::StrCat(descriptor->default_value_int32()); + return StrCat(descriptor->default_value_int32()); break; case FieldDescriptor::CPPTYPE_INT64: - return absl::StrCat(descriptor->default_value_int64()); + return StrCat(descriptor->default_value_int64()); break; case FieldDescriptor::CPPTYPE_UINT32: - return absl::StrCat(descriptor->default_value_uint32()); + return StrCat(descriptor->default_value_uint32()); break; case FieldDescriptor::CPPTYPE_UINT64: - return absl::StrCat(descriptor->default_value_uint64()); + return StrCat(descriptor->default_value_uint64()); break; case FieldDescriptor::CPPTYPE_FLOAT: return SimpleFtoa(descriptor->default_value_float()); @@ -339,7 +339,7 @@ class DescriptorPoolTypeResolver : public TypeResolver { break; case FieldDescriptor::CPPTYPE_STRING: if (descriptor->type() == FieldDescriptor::TYPE_BYTES) { - return absl::CEscape(descriptor->default_value_string()); + return CEscape(descriptor->default_value_string()); } else { return descriptor->default_value_string(); } diff --git a/libs/protobuf/src/google/protobuf/util/type_resolver_util.h b/libs/protobuf/src/google/protobuf/util/type_resolver_util.h index 0327e61..7f6a4b9 100644 --- a/libs/protobuf/src/google/protobuf/util/type_resolver_util.h +++ b/libs/protobuf/src/google/protobuf/util/type_resolver_util.h @@ -35,15 +35,15 @@ #include -// Must be included last. -#include "google/protobuf/port_def.inc" - namespace google { namespace protobuf { class DescriptorPool; namespace util { class TypeResolver; +// Must be included last. +#include + // Creates a TypeResolver that serves type information in the given descriptor // pool. Caller takes ownership of the returned TypeResolver. PROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool( @@ -53,6 +53,6 @@ PROTOBUF_EXPORT TypeResolver* NewTypeResolverForDescriptorPool( } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_UTIL_H__ diff --git a/libs/protobuf/src/google/protobuf/util/type_resolver_util_test.cc b/libs/protobuf/src/google/protobuf/util/type_resolver_util_test.cc index d926541..2780a39 100644 --- a/libs/protobuf/src/google/protobuf/util/type_resolver_util_test.cc +++ b/libs/protobuf/src/google/protobuf/util/type_resolver_util_test.cc @@ -28,7 +28,7 @@ // (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/util/type_resolver_util.h" +#include #include #include @@ -36,16 +36,16 @@ #include #include -#include "google/protobuf/type.pb.h" -#include "google/protobuf/wrappers.pb.h" -#include "google/protobuf/map_unittest.pb.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_custom_options.pb.h" -#include "google/protobuf/util/type_resolver.h" -#include "google/protobuf/testing/googletest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/util/json_format_proto3.pb.h" namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/well_known_types_unittest.cc b/libs/protobuf/src/google/protobuf/well_known_types_unittest.cc index 4d7a0ff..c9a9aa1 100644 --- a/libs/protobuf/src/google/protobuf/well_known_types_unittest.cc +++ b/libs/protobuf/src/google/protobuf/well_known_types_unittest.cc @@ -27,11 +27,12 @@ // 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 +#include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/testing/googletest.h" -#include "google/protobuf/unittest_well_known_types.pb.h" +#include +#include +#include +#include namespace google { namespace protobuf { diff --git a/libs/protobuf/src/google/protobuf/wire_format.cc b/libs/protobuf/src/google/protobuf/wire_format.cc index e65dad0..6fe63c8 100644 --- a/libs/protobuf/src/google/protobuf/wire_format.cc +++ b/libs/protobuf/src/google/protobuf/wire_format.cc @@ -32,31 +32,30 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/wire_format.h" +#include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "absl/strings/cord.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/descriptor.pb.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/map_field.h" -#include "google/protobuf/map_field_inl.h" -#include "google/protobuf/message.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include const size_t kMapEntryTagByteSize = 2; @@ -1766,4 +1765,4 @@ size_t ComputeUnknownFieldsSize(const InternalMetadata& metadata, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/wire_format.h b/libs/protobuf/src/google/protobuf/wire_format.h index 027fcb3..1acbf9e 100644 --- a/libs/protobuf/src/google/protobuf/wire_format.h +++ b/libs/protobuf/src/google/protobuf/wire_format.h @@ -40,23 +40,22 @@ #define GOOGLE_PROTOBUF_WIRE_FORMAT_H__ -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "absl/base/casts.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/message.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/parse_context.h" -#include "google/protobuf/port.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef SWIG #error "You cannot SWIG proto headers" #endif // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -80,8 +79,6 @@ namespace internal { // This class is really a namespace that contains only static methods class PROTOBUF_EXPORT WireFormat { public: - WireFormat() = delete; - // Given a field return its WireType static inline WireFormatLite::WireType WireTypeForField( const FieldDescriptor* field); @@ -288,7 +285,6 @@ class PROTOBUF_EXPORT WireFormat { private: struct MessageSetParser; - friend class TcParser; // Skip a MessageSet field. static bool SkipMessageSetField(io::CodedInputStream* input, uint32_t field_number, @@ -305,6 +301,8 @@ class PROTOBUF_EXPORT WireFormat { uint64_t tag, const Reflection* reflection, const FieldDescriptor* field); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormat); }; // Subclass of FieldSkipper which saves skipped fields to an UnknownFieldSet. @@ -339,7 +337,7 @@ inline WireFormatLite::WireType WireFormat::WireTypeForFieldType( // Some compilers don't like enum -> enum casts, so we implicit_cast to // int first. return WireFormatLite::WireTypeForFieldType( - static_cast(absl::implicit_cast(type))); + static_cast(implicit_cast(type))); } inline uint32_t WireFormat::MakeTag(const FieldDescriptor* field) { @@ -352,7 +350,7 @@ inline size_t WireFormat::TagSize(int field_number, // int first. return WireFormatLite::TagSize( field_number, - static_cast(absl::implicit_cast(type))); + static_cast(implicit_cast(type))); } inline void WireFormat::VerifyUTF8String(const char* data, int size, @@ -411,6 +409,6 @@ uint8_t* SerializeMapKeyWithCachedSizes(const FieldDescriptor* field, } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_H__ diff --git a/libs/protobuf/src/google/protobuf/wire_format_lite.cc b/libs/protobuf/src/google/protobuf/wire_format_lite.cc index 089b0bc..5ab1ca1 100644 --- a/libs/protobuf/src/google/protobuf/wire_format_lite.cc +++ b/libs/protobuf/src/google/protobuf/wire_format_lite.cc @@ -32,25 +32,23 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/wire_format_lite.h" +#include #include #include #include #include -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "absl/strings/cord.h" -#include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" +#include +#include +#include +#include +#include +#include // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -595,8 +593,8 @@ bool WireFormatLite::ReadBytes(io::CodedInputStream* input, std::string** p) { return ReadBytesToString(input, *p); } -void PrintUTF8ErrorLog(absl::string_view message_name, - absl::string_view field_name, const char* operation_str, +void PrintUTF8ErrorLog(StringPiece message_name, + StringPiece field_name, const char* operation_str, bool emit_stacktrace) { std::string stacktrace; (void)emit_stacktrace; // Parameter is used by Google-internal code. @@ -604,13 +602,13 @@ void PrintUTF8ErrorLog(absl::string_view message_name, if (!field_name.empty()) { if (!message_name.empty()) { quoted_field_name = - absl::StrCat(" '", message_name, ".", field_name, "'"); + StrCat(" '", message_name, ".", field_name, "'"); } else { - quoted_field_name = absl::StrCat(" '", field_name, "'"); + quoted_field_name = StrCat(" '", field_name, "'"); } } std::string error_message = - absl::StrCat("String field", quoted_field_name, + StrCat("String field", quoted_field_name, " contains invalid UTF-8 data " "when ", operation_str, @@ -622,7 +620,7 @@ void PrintUTF8ErrorLog(absl::string_view message_name, bool WireFormatLite::VerifyUtf8String(const char* data, int size, Operation op, const char* field_name) { - if (!::google::protobuf::internal::IsStructurallyValidUTF8(data, size)) { + if (!IsStructurallyValidUTF8(data, size)) { const char* operation_str = nullptr; switch (op) { case PARSE: @@ -817,4 +815,4 @@ size_t WireFormatLite::SInt64Size(const RepeatedField& value) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/wire_format_lite.h b/libs/protobuf/src/google/protobuf/wire_format_lite.h index 1af4d06..80d3961 100644 --- a/libs/protobuf/src/google/protobuf/wire_format_lite.h +++ b/libs/protobuf/src/google/protobuf/wire_format_lite.h @@ -44,16 +44,16 @@ #include #include -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/port.h" -#include "absl/base/casts.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/message_lite.h" -#include "google/protobuf/port.h" -#include "google/protobuf/repeated_field.h" +#include +#include +#include +#include +#include +#include +#include +#include +// Do UTF-8 validation on string type in Debug build only #ifndef NDEBUG #define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED #endif @@ -70,7 +70,7 @@ // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -87,7 +87,6 @@ namespace internal { // This class is really a namespace that contains only static methods. class PROTOBUF_EXPORT WireFormatLite { public: - WireFormatLite() = delete; // ----------------------------------------------------------------- // Helper constants and functions related to the format. These are // mostly meant for internal and generated code to use. @@ -103,11 +102,7 @@ class PROTOBUF_EXPORT WireFormatLite { // identifies the encoding of this data, it is possible to skip // unrecognized fields for forwards compatibility. - enum WireType -#ifndef SWIG - : int -#endif // !SWIG - { + enum WireType { WIRETYPE_VARINT = 0, WIRETYPE_FIXED64 = 1, WIRETYPE_LENGTH_DELIMITED = 2, @@ -747,6 +742,8 @@ class PROTOBUF_EXPORT WireFormatLite { static const WireFormatLite::WireType kWireTypeForFieldType[]; static void WriteSubMessageMaybeToArray(int size, const MessageLite& value, io::CodedOutputStream* output); + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(WireFormatLite); }; // A class which deals with unknown values. The default implementation just @@ -821,19 +818,19 @@ inline size_t WireFormatLite::TagSize(int field_number, } inline uint32_t WireFormatLite::EncodeFloat(float value) { - return absl::bit_cast(value); + return bit_cast(value); } inline float WireFormatLite::DecodeFloat(uint32_t value) { - return absl::bit_cast(value); + return bit_cast(value); } inline uint64_t WireFormatLite::EncodeDouble(double value) { - return absl::bit_cast(value); + return bit_cast(value); } inline double WireFormatLite::DecodeDouble(uint64_t value) { - return absl::bit_cast(value); + return bit_cast(value); } // ZigZag Transform: Encodes signed integers so that they can be @@ -1906,6 +1903,6 @@ bool ParseMessageSetItemImpl(io::CodedInputStream* input, MS ms) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include #endif // GOOGLE_PROTOBUF_WIRE_FORMAT_LITE_H__ diff --git a/libs/protobuf/src/google/protobuf/wire_format_unittest.cc b/libs/protobuf/src/google/protobuf/wire_format_unittest.cc index f51cf53..f1ed951 100644 --- a/libs/protobuf/src/google/protobuf/wire_format_unittest.cc +++ b/libs/protobuf/src/google/protobuf/wire_format_unittest.cc @@ -32,12 +32,12 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/wire_format.h" +#include -#include "google/protobuf/unittest.pb.h" -#include "google/protobuf/unittest_mset.pb.h" -#include "google/protobuf/unittest_mset_wire_format.pb.h" -#include "google/protobuf/unittest_proto3_arena.pb.h" +#include +#include +#include +#include #include #include @@ -49,12 +49,12 @@ // Must include after defining UNITTEST, etc. // clang-format off -#include "google/protobuf/test_util.inc" -#include "google/protobuf/wire_format_unittest.inc" +#include +#include // clang-format on // Must be included last. -#include "google/protobuf/port_def.inc" +#include namespace google { namespace protobuf { @@ -67,4 +67,4 @@ namespace { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/wire_format_unittest.inc b/libs/protobuf/src/google/protobuf/wire_format_unittest.inc index 81a577e..0e3869c 100644 --- a/libs/protobuf/src/google/protobuf/wire_format_unittest.inc +++ b/libs/protobuf/src/google/protobuf/wire_format_unittest.inc @@ -32,26 +32,26 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. -#include "google/protobuf/stubs/logging.h" -#include "google/protobuf/stubs/common.h" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" -#include "google/protobuf/io/zero_copy_stream_impl_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/wire_format.h" -#include "google/protobuf/wire_format_lite.h" +#include +#include +#include +#include +#include +#include +#include +#include #include -#include "google/protobuf/testing/googletest.h" +#include #include -#include "absl/base/casts.h" -#include "google/protobuf/stubs/logging.h" -#include "absl/strings/cord.h" -#include "absl/strings/match.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/test_util2.h" +#include +#include +#include +#include +#include +#include // clang-format off -#include "google/protobuf/port_def.inc" +#include // clang-format on namespace google { @@ -63,15 +63,15 @@ TEST(WireFormatTest, EnumsInSync) { // Verify that WireFormatLite::FieldType and WireFormatLite::CppType match // FieldDescriptor::Type and FieldDescriptor::CppType. - EXPECT_EQ(absl::implicit_cast(FieldDescriptor::MAX_TYPE), - absl::implicit_cast(WireFormatLite::MAX_FIELD_TYPE)); - EXPECT_EQ(absl::implicit_cast(FieldDescriptor::MAX_CPPTYPE), - absl::implicit_cast(WireFormatLite::MAX_CPPTYPE)); + EXPECT_EQ(implicit_cast(FieldDescriptor::MAX_TYPE), + implicit_cast(WireFormatLite::MAX_FIELD_TYPE)); + EXPECT_EQ(implicit_cast(FieldDescriptor::MAX_CPPTYPE), + implicit_cast(WireFormatLite::MAX_CPPTYPE)); for (int i = 1; i <= WireFormatLite::MAX_FIELD_TYPE; i++) { - EXPECT_EQ(absl::implicit_cast(FieldDescriptor::TypeToCppType( + EXPECT_EQ(implicit_cast(FieldDescriptor::TypeToCppType( static_cast(i))), - absl::implicit_cast(WireFormatLite::FieldTypeToCppType( + implicit_cast(WireFormatLite::FieldTypeToCppType( static_cast(i)))); } } @@ -493,14 +493,16 @@ TEST(WireFormatTest, SerializeMessageSetVariousWaysAreEqual) { // Serialize to flat array { - uint8_t* target = reinterpret_cast(&flat_data[0]); + uint8_t* target = + reinterpret_cast(::google::protobuf::string_as_array(&flat_data)); uint8_t* end = message_set.SerializeWithCachedSizesToArray(target); EXPECT_EQ(size, end - target); } // Serialize to buffer { - io::ArrayOutputStream array_stream(&stream_data[0], size, 1); + io::ArrayOutputStream array_stream(::google::protobuf::string_as_array(&stream_data), size, + 1); io::CodedOutputStream output_stream(&array_stream); message_set.SerializeWithCachedSizes(&output_stream); ASSERT_FALSE(output_stream.HadError()); @@ -1558,7 +1560,7 @@ TEST_F(Utf8ValidationTest, OldVerifyUTF8String) { #ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED ASSERT_EQ(1, errors.size()); EXPECT_TRUE( - absl::StartsWith(errors[0], + HasPrefixString(errors[0], "String field contains invalid UTF-8 data when " "serializing a protocol buffer. Use the " "'bytes' type if you intend to send raw bytes.")); @@ -1704,4 +1706,4 @@ TEST(RepeatedVarint, Enum) { } // namespace protobuf } // namespace google -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/wrappers.pb.cc b/libs/protobuf/src/google/protobuf/wrappers.pb.cc index 9bc7397..40ba60a 100644 --- a/libs/protobuf/src/google/protobuf/wrappers.pb.cc +++ b/libs/protobuf/src/google/protobuf/wrappers.pb.cc @@ -1,316 +1,268 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -#include "google/protobuf/wrappers.pb.h" +#include #include -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/extension_set.h" -#include "google/protobuf/wire_format_lite.h" -#include "google/protobuf/descriptor.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/reflection_ops.h" -#include "google/protobuf/wire_format.h" -// @@protoc_insertion_point(includes) -// Must be included last. -#include "google/protobuf/port_def.inc" +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + PROTOBUF_PRAGMA_INIT_SEG + namespace _pb = ::PROTOBUF_NAMESPACE_ID; -namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace _pbi = _pb::internal; + PROTOBUF_NAMESPACE_OPEN PROTOBUF_CONSTEXPR DoubleValue::DoubleValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct DoubleValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR DoubleValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR DoubleValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~DoubleValueDefaultTypeInternal() {} union { DoubleValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; PROTOBUF_CONSTEXPR FloatValue::FloatValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct FloatValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR FloatValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR FloatValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~FloatValueDefaultTypeInternal() {} union { FloatValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FloatValueDefaultTypeInternal _FloatValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FloatValueDefaultTypeInternal _FloatValue_default_instance_; PROTOBUF_CONSTEXPR Int64Value::Int64Value( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/int64_t{0} , /*decltype(_impl_._cached_size_)*/{}} {} struct Int64ValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR Int64ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR Int64ValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~Int64ValueDefaultTypeInternal() {} union { Int64Value _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Int64ValueDefaultTypeInternal _Int64Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Int64ValueDefaultTypeInternal _Int64Value_default_instance_; PROTOBUF_CONSTEXPR UInt64Value::UInt64Value( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/uint64_t{0u} , /*decltype(_impl_._cached_size_)*/{}} {} struct UInt64ValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR UInt64ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR UInt64ValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~UInt64ValueDefaultTypeInternal() {} union { UInt64Value _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; PROTOBUF_CONSTEXPR Int32Value::Int32Value( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/0 , /*decltype(_impl_._cached_size_)*/{}} {} struct Int32ValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR Int32ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR Int32ValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~Int32ValueDefaultTypeInternal() {} union { Int32Value _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Int32ValueDefaultTypeInternal _Int32Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Int32ValueDefaultTypeInternal _Int32Value_default_instance_; PROTOBUF_CONSTEXPR UInt32Value::UInt32Value( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/0u , /*decltype(_impl_._cached_size_)*/{}} {} struct UInt32ValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR UInt32ValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR UInt32ValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~UInt32ValueDefaultTypeInternal() {} union { UInt32Value _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; PROTOBUF_CONSTEXPR BoolValue::BoolValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/false , /*decltype(_impl_._cached_size_)*/{}} {} struct BoolValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR BoolValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR BoolValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~BoolValueDefaultTypeInternal() {} union { BoolValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 BoolValueDefaultTypeInternal _BoolValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 BoolValueDefaultTypeInternal _BoolValue_default_instance_; PROTOBUF_CONSTEXPR StringValue::StringValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_._cached_size_)*/{}} {} struct StringValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR StringValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR StringValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~StringValueDefaultTypeInternal() {} union { StringValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StringValueDefaultTypeInternal _StringValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StringValueDefaultTypeInternal _StringValue_default_instance_; PROTOBUF_CONSTEXPR BytesValue::BytesValue( ::_pbi::ConstantInitialized): _impl_{ /*decltype(_impl_.value_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} , /*decltype(_impl_._cached_size_)*/{}} {} struct BytesValueDefaultTypeInternal { - PROTOBUF_CONSTEXPR BytesValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + PROTOBUF_CONSTEXPR BytesValueDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} ~BytesValueDefaultTypeInternal() {} union { BytesValue _instance; }; }; - -PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT - PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 BytesValueDefaultTypeInternal _BytesValue_default_instance_; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 BytesValueDefaultTypeInternal _BytesValue_default_instance_; PROTOBUF_NAMESPACE_CLOSE static ::_pb::Metadata file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[9]; -static constexpr const ::_pb::EnumDescriptor** - file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; -static constexpr const ::_pb::ServiceDescriptor** - file_level_service_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; -const uint32_t TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( - protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DoubleValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DoubleValue, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FloatValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FloatValue, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int64Value, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int64Value, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt64Value, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt64Value, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int32Value, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int32Value, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt32Value, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt32Value, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BoolValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BoolValue, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::StringValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::StringValue, _impl_.value_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BytesValue, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - ~0u, // no _inlined_string_donated_ - ~0u, // no _split_ - ~0u, // no sizeof(Split) - PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BytesValue, _impl_.value_), -}; +static constexpr ::_pb::EnumDescriptor const** file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; +static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_google_2fprotobuf_2fwrappers_2eproto = nullptr; -static const ::_pbi::MigrationSchema - schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DoubleValue)}, - { 9, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FloatValue)}, - { 18, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Int64Value)}, - { 27, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UInt64Value)}, - { 36, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Int32Value)}, - { 45, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UInt32Value)}, - { 54, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::BoolValue)}, - { 63, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::StringValue)}, - { 72, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::BytesValue)}, +const uint32_t TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DoubleValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::DoubleValue, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FloatValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::FloatValue, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int64Value, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int64Value, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt64Value, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt64Value, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int32Value, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::Int32Value, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt32Value, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::UInt32Value, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BoolValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BoolValue, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::StringValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::StringValue, _impl_.value_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BytesValue, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + PROTOBUF_FIELD_OFFSET(::PROTOBUF_NAMESPACE_ID::BytesValue, _impl_.value_), +}; +static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::DoubleValue)}, + { 7, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::FloatValue)}, + { 14, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Int64Value)}, + { 21, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UInt64Value)}, + { 28, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::Int32Value)}, + { 35, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::UInt32Value)}, + { 42, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::BoolValue)}, + { 49, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::StringValue)}, + { 56, -1, -1, sizeof(::PROTOBUF_NAMESPACE_ID::BytesValue)}, }; static const ::_pb::Message* const file_default_instances[] = { - &::PROTOBUF_NAMESPACE_ID::_DoubleValue_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_FloatValue_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Int64Value_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_UInt64Value_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_Int32Value_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_UInt32Value_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_BoolValue_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_StringValue_default_instance_._instance, - &::PROTOBUF_NAMESPACE_ID::_BytesValue_default_instance_._instance, -}; -const char descriptor_table_protodef_google_2fprotobuf_2fwrappers_2eproto[] PROTOBUF_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" - "ue\022\r\n\005value\030\001 \001(\003\"\034\n\013UInt64Value\022\r\n\005valu" - "e\030\001 \001(\004\"\033\n\nInt32Value\022\r\n\005value\030\001 \001(\005\"\034\n\013" - "UInt32Value\022\r\n\005value\030\001 \001(\r\"\032\n\tBoolValue\022" - "\r\n\005value\030\001 \001(\010\"\034\n\013StringValue\022\r\n\005value\030\001" - " \001(\t\"\033\n\nBytesValue\022\r\n\005value\030\001 \001(\014B\203\001\n\023co" - "m.google.protobufB\rWrappersProtoP\001Z1goog" - "le.golang.org/protobuf/types/known/wrapp" - "erspb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKno" - "wnTypesb\006proto3" -}; -static ::absl::once_flag descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once; -const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fwrappers_2eproto = { - false, - false, - 455, - descriptor_table_protodef_google_2fprotobuf_2fwrappers_2eproto, - "google/protobuf/wrappers.proto", - &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, - nullptr, - 0, - 9, - schemas, - file_default_instances, - TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets, - file_level_metadata_google_2fprotobuf_2fwrappers_2eproto, - file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto, - file_level_service_descriptors_google_2fprotobuf_2fwrappers_2eproto, + &::PROTOBUF_NAMESPACE_ID::_DoubleValue_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_FloatValue_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Int64Value_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_UInt64Value_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_Int32Value_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_UInt32Value_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_BoolValue_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_StringValue_default_instance_._instance, + &::PROTOBUF_NAMESPACE_ID::_BytesValue_default_instance_._instance, }; -// This function exists to be marked as weak. -// It can significantly speed up compilation by breaking up LLVM's SCC -// in the .pb.cc translation units. Large translation units see a -// reduction of more than 35% of walltime for optimized builds. Without -// the weak attribute all the messages in the file, including all the -// vtables and everything they use become part of the same SCC through -// a cycle like: -// GetMetadata -> descriptor table -> default instances -> -// vtables -> GetMetadata -// By adding a weak function here we break the connection from the -// individual vtables back into the descriptor table. +const char descriptor_table_protodef_google_2fprotobuf_2fwrappers_2eproto[] PROTOBUF_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" + "ue\022\r\n\005value\030\001 \001(\003\"\034\n\013UInt64Value\022\r\n\005valu" + "e\030\001 \001(\004\"\033\n\nInt32Value\022\r\n\005value\030\001 \001(\005\"\034\n\013" + "UInt32Value\022\r\n\005value\030\001 \001(\r\"\032\n\tBoolValue\022" + "\r\n\005value\030\001 \001(\010\"\034\n\013StringValue\022\r\n\005value\030\001" + " \001(\t\"\033\n\nBytesValue\022\r\n\005value\030\001 \001(\014B\203\001\n\023co" + "m.google.protobufB\rWrappersProtoP\001Z1goog" + "le.golang.org/protobuf/types/known/wrapp" + "erspb\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKno" + "wnTypesb\006proto3" + ; +static ::_pbi::once_flag descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fwrappers_2eproto = { + false, false, 455, descriptor_table_protodef_google_2fprotobuf_2fwrappers_2eproto, + "google/protobuf/wrappers.proto", + &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, nullptr, 0, 9, + schemas, file_default_instances, TableStruct_google_2fprotobuf_2fwrappers_2eproto::offsets, + file_level_metadata_google_2fprotobuf_2fwrappers_2eproto, file_level_enum_descriptors_google_2fprotobuf_2fwrappers_2eproto, + file_level_service_descriptors_google_2fprotobuf_2fwrappers_2eproto, +}; PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter() { return &descriptor_table_google_2fprotobuf_2fwrappers_2eproto; } + // Force running AddDescriptors() at dynamic initialization time. -PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 -static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fwrappers_2eproto(&descriptor_table_google_2fprotobuf_2fwrappers_2eproto); +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_google_2fprotobuf_2fwrappers_2eproto(&descriptor_table_google_2fprotobuf_2fwrappers_2eproto); PROTOBUF_NAMESPACE_OPEN + // =================================================================== class DoubleValue::_Internal { @@ -324,9 +276,14 @@ DoubleValue::DoubleValue(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.DoubleValue) } DoubleValue::DoubleValue(const DoubleValue& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + DoubleValue* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.DoubleValue) } @@ -368,7 +325,6 @@ void DoubleValue::Clear() { } const char* DoubleValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -407,7 +363,6 @@ failure: uint8_t* DoubleValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -431,7 +386,6 @@ uint8_t* DoubleValue::_InternalSerialize( } size_t DoubleValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DoubleValue) size_t total_size = 0; @@ -461,7 +415,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*DoubleValue::GetClassData() co void DoubleValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -495,11 +448,11 @@ void DoubleValue::InternalSwap(DoubleValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata DoubleValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[0]); } + // =================================================================== class FloatValue::_Internal { @@ -513,9 +466,14 @@ FloatValue::FloatValue(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.FloatValue) } FloatValue::FloatValue(const FloatValue& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + FloatValue* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.FloatValue) } @@ -557,7 +515,6 @@ void FloatValue::Clear() { } const char* FloatValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -596,7 +553,6 @@ failure: uint8_t* FloatValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -620,7 +576,6 @@ uint8_t* FloatValue::_InternalSerialize( } size_t FloatValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FloatValue) size_t total_size = 0; @@ -650,7 +605,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*FloatValue::GetClassData() con void FloatValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -684,11 +638,11 @@ void FloatValue::InternalSwap(FloatValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata FloatValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[1]); } + // =================================================================== class Int64Value::_Internal { @@ -702,9 +656,14 @@ Int64Value::Int64Value(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.Int64Value) } Int64Value::Int64Value(const Int64Value& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + Int64Value* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Int64Value) } @@ -746,7 +705,6 @@ void Int64Value::Clear() { } const char* Int64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -785,7 +743,6 @@ failure: uint8_t* Int64Value::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -805,7 +762,6 @@ uint8_t* Int64Value::_InternalSerialize( } size_t Int64Value::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int64Value) size_t total_size = 0; @@ -831,7 +787,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Int64Value::GetClassData() con void Int64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -861,11 +816,11 @@ void Int64Value::InternalSwap(Int64Value* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Int64Value::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[2]); } + // =================================================================== class UInt64Value::_Internal { @@ -879,9 +834,14 @@ UInt64Value::UInt64Value(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt64Value) } UInt64Value::UInt64Value(const UInt64Value& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + UInt64Value* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.UInt64Value) } @@ -923,7 +883,6 @@ void UInt64Value::Clear() { } const char* UInt64Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -962,7 +921,6 @@ failure: uint8_t* UInt64Value::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -982,7 +940,6 @@ uint8_t* UInt64Value::_InternalSerialize( } size_t UInt64Value::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt64Value) size_t total_size = 0; @@ -1008,7 +965,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UInt64Value::GetClassData() co void UInt64Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1038,11 +994,11 @@ void UInt64Value::InternalSwap(UInt64Value* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata UInt64Value::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[3]); } + // =================================================================== class Int32Value::_Internal { @@ -1056,9 +1012,14 @@ Int32Value::Int32Value(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.Int32Value) } Int32Value::Int32Value(const Int32Value& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + Int32Value* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.Int32Value) } @@ -1100,7 +1061,6 @@ void Int32Value::Clear() { } const char* Int32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1139,7 +1099,6 @@ failure: uint8_t* Int32Value::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1159,7 +1118,6 @@ uint8_t* Int32Value::_InternalSerialize( } size_t Int32Value::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int32Value) size_t total_size = 0; @@ -1185,7 +1143,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*Int32Value::GetClassData() con void Int32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1215,11 +1172,11 @@ void Int32Value::InternalSwap(Int32Value* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata Int32Value::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[4]); } + // =================================================================== class UInt32Value::_Internal { @@ -1233,9 +1190,14 @@ UInt32Value::UInt32Value(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt32Value) } UInt32Value::UInt32Value(const UInt32Value& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + UInt32Value* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.UInt32Value) } @@ -1277,7 +1239,6 @@ void UInt32Value::Clear() { } const char* UInt32Value::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1316,7 +1277,6 @@ failure: uint8_t* UInt32Value::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1336,7 +1296,6 @@ uint8_t* UInt32Value::_InternalSerialize( } size_t UInt32Value::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt32Value) size_t total_size = 0; @@ -1362,7 +1321,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*UInt32Value::GetClassData() co void UInt32Value::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1392,11 +1350,11 @@ void UInt32Value::InternalSwap(UInt32Value* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata UInt32Value::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[5]); } + // =================================================================== class BoolValue::_Internal { @@ -1410,9 +1368,14 @@ BoolValue::BoolValue(::PROTOBUF_NAMESPACE_ID::Arena* arena, // @@protoc_insertion_point(arena_constructor:google.protobuf.BoolValue) } BoolValue::BoolValue(const BoolValue& from) - : ::PROTOBUF_NAMESPACE_ID::Message(), _impl_(from._impl_) { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>( - from._internal_metadata_); + : ::PROTOBUF_NAMESPACE_ID::Message() { + BoolValue* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.value_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.value_ = from._impl_.value_; // @@protoc_insertion_point(copy_constructor:google.protobuf.BoolValue) } @@ -1454,7 +1417,6 @@ void BoolValue::Clear() { } const char* BoolValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1493,7 +1455,6 @@ failure: uint8_t* BoolValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1513,7 +1474,6 @@ uint8_t* BoolValue::_InternalSerialize( } size_t BoolValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BoolValue) size_t total_size = 0; @@ -1539,7 +1499,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*BoolValue::GetClassData() cons void BoolValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1569,11 +1528,11 @@ void BoolValue::InternalSwap(BoolValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata BoolValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[6]); } + // =================================================================== class StringValue::_Internal { @@ -1648,7 +1607,6 @@ void StringValue::Clear() { } const char* StringValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1689,7 +1647,6 @@ failure: uint8_t* StringValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1713,7 +1670,6 @@ uint8_t* StringValue::_InternalSerialize( } size_t StringValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.StringValue) size_t total_size = 0; @@ -1741,7 +1697,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*StringValue::GetClassData() co void StringValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1776,11 +1731,11 @@ void StringValue::InternalSwap(StringValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata StringValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[7]); } + // =================================================================== class BytesValue::_Internal { @@ -1855,7 +1810,6 @@ void BytesValue::Clear() { } const char* BytesValue::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { - #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { uint32_t tag; @@ -1895,7 +1849,6 @@ failure: uint8_t* BytesValue::_InternalSerialize( uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue) uint32_t cached_has_bits = 0; (void) cached_has_bits; @@ -1915,7 +1868,6 @@ uint8_t* BytesValue::_InternalSerialize( } size_t BytesValue::ByteSizeLong() const { - // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BytesValue) size_t total_size = 0; @@ -1943,7 +1895,6 @@ const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*BytesValue::GetClassData() con void BytesValue::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { auto* const _this = static_cast(&to_msg); auto& from = static_cast(from_msg); - // @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue) GOOGLE_DCHECK_NE(&from, _this); uint32_t cached_has_bits = 0; @@ -1978,11 +1929,11 @@ void BytesValue::InternalSwap(BytesValue* other) { } ::PROTOBUF_NAMESPACE_ID::Metadata BytesValue::GetMetadata() const { - return ::_pbi::AssignDescriptors( &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_getter, &descriptor_table_google_2fprotobuf_2fwrappers_2eproto_once, file_level_metadata_google_2fprotobuf_2fwrappers_2eproto[8]); } + // @@protoc_insertion_point(namespace_scope) PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN @@ -2023,5 +1974,6 @@ Arena::CreateMaybeMessage< ::PROTOBUF_NAMESPACE_ID::BytesValue >(Arena* arena) { return Arena::CreateMessageInternal< ::PROTOBUF_NAMESPACE_ID::BytesValue >(arena); } PROTOBUF_NAMESPACE_CLOSE + // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" +#include diff --git a/libs/protobuf/src/google/protobuf/wrappers.pb.h b/libs/protobuf/src/google/protobuf/wrappers.pb.h index 85837b8..0f4b835 100644 --- a/libs/protobuf/src/google/protobuf/wrappers.pb.h +++ b/libs/protobuf/src/google/protobuf/wrappers.pb.h @@ -1,43 +1,38 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: google/protobuf/wrappers.proto -#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh -#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh +#ifndef GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto #include #include -#include -#include "google/protobuf/port_def.inc" +#include #if PROTOBUF_VERSION < 3021000 -#error "This file was generated by a newer version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please update" -#error "your headers." -#endif // PROTOBUF_VERSION +#error This file was generated by a newer version of protoc which is +#error incompatible with your Protocol Buffer headers. Please update +#error your headers. +#endif +#if 3021012 < PROTOBUF_MIN_PROTOC_VERSION +#error This file was generated by an older version of protoc which is +#error incompatible with your Protocol Buffer headers. Please +#error regenerate this file with a newer version of protoc. +#endif -#if 3021008 < PROTOBUF_MIN_PROTOC_VERSION -#error "This file was generated by an older version of protoc which is" -#error "incompatible with your Protocol Buffer headers. Please" -#error "regenerate this file with a newer version of protoc." -#endif // PROTOBUF_MIN_PROTOC_VERSION -#include "google/protobuf/port_undef.inc" -#include "google/protobuf/io/coded_stream.h" -#include "google/protobuf/arena.h" -#include "google/protobuf/arenastring.h" -#include "google/protobuf/generated_message_util.h" -#include "google/protobuf/metadata_lite.h" -#include "google/protobuf/generated_message_reflection.h" -#include "google/protobuf/message.h" -#include "google/protobuf/repeated_field.h" // IWYU pragma: export -#include "google/protobuf/extension_set.h" // IWYU pragma: export -#include "google/protobuf/unknown_field_set.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // @@protoc_insertion_point(includes) - -// Must be included last. -#include "google/protobuf/port_def.inc" - +#include #define PROTOBUF_INTERNAL_EXPORT_google_2fprotobuf_2fwrappers_2eproto PROTOBUF_EXPORT - PROTOBUF_NAMESPACE_OPEN namespace internal { class AnyMetadata; @@ -48,8 +43,7 @@ PROTOBUF_NAMESPACE_CLOSE struct PROTOBUF_EXPORT TableStruct_google_2fprotobuf_2fwrappers_2eproto { static const uint32_t offsets[]; }; -PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable - descriptor_table_google_2fprotobuf_2fwrappers_2eproto; +PROTOBUF_EXPORT extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_google_2fprotobuf_2fwrappers_2eproto; PROTOBUF_NAMESPACE_OPEN class BoolValue; struct BoolValueDefaultTypeInternal; @@ -78,33 +72,22 @@ PROTOBUF_EXPORT extern UInt32ValueDefaultTypeInternal _UInt32Value_default_insta class UInt64Value; struct UInt64ValueDefaultTypeInternal; PROTOBUF_EXPORT extern UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::BoolValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::BoolValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::BytesValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::BytesValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DoubleValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DoubleValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FloatValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FloatValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Int32Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Int32Value>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Int64Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Int64Value>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::StringValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::StringValue>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UInt32Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UInt32Value>(Arena*); -template <> -PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UInt64Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UInt64Value>(Arena*); PROTOBUF_NAMESPACE_CLOSE - +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::BoolValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::BoolValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::BytesValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::BytesValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::DoubleValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::DoubleValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::FloatValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::FloatValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Int32Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Int32Value>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::Int64Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Int64Value>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::StringValue* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::StringValue>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UInt32Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UInt32Value>(Arena*); +template<> PROTOBUF_EXPORT ::PROTOBUF_NAMESPACE_ID::UInt64Value* Arena::CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::UInt64Value>(Arena*); +PROTOBUF_NAMESPACE_CLOSE PROTOBUF_NAMESPACE_OPEN // =================================================================== - -// ------------------------------------------------------------------- - class PROTOBUF_EXPORT DoubleValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DoubleValue) */ { public: @@ -208,7 +191,7 @@ class PROTOBUF_EXPORT DoubleValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.DoubleValue"; } protected: @@ -250,7 +233,8 @@ class PROTOBUF_EXPORT DoubleValue final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT FloatValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FloatValue) */ { @@ -355,7 +339,7 @@ class PROTOBUF_EXPORT FloatValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.FloatValue"; } protected: @@ -397,7 +381,8 @@ class PROTOBUF_EXPORT FloatValue final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Int64Value final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int64Value) */ { @@ -502,7 +487,7 @@ class PROTOBUF_EXPORT Int64Value final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Int64Value"; } protected: @@ -544,7 +529,8 @@ class PROTOBUF_EXPORT Int64Value final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT UInt64Value final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt64Value) */ { @@ -649,7 +635,7 @@ class PROTOBUF_EXPORT UInt64Value final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.UInt64Value"; } protected: @@ -691,7 +677,8 @@ class PROTOBUF_EXPORT UInt64Value final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT Int32Value final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Int32Value) */ { @@ -796,7 +783,7 @@ class PROTOBUF_EXPORT Int32Value final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.Int32Value"; } protected: @@ -838,7 +825,8 @@ class PROTOBUF_EXPORT Int32Value final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT UInt32Value final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UInt32Value) */ { @@ -943,7 +931,7 @@ class PROTOBUF_EXPORT UInt32Value final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.UInt32Value"; } protected: @@ -985,7 +973,8 @@ class PROTOBUF_EXPORT UInt32Value final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT BoolValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BoolValue) */ { @@ -1090,7 +1079,7 @@ class PROTOBUF_EXPORT BoolValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.BoolValue"; } protected: @@ -1132,7 +1121,8 @@ class PROTOBUF_EXPORT BoolValue final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT StringValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.StringValue) */ { @@ -1237,7 +1227,7 @@ class PROTOBUF_EXPORT StringValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.StringValue"; } protected: @@ -1284,7 +1274,8 @@ class PROTOBUF_EXPORT StringValue final : }; union { Impl_ _impl_; }; friend struct ::TableStruct_google_2fprotobuf_2fwrappers_2eproto; -};// ------------------------------------------------------------------- +}; +// ------------------------------------------------------------------- class PROTOBUF_EXPORT BytesValue final : public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:google.protobuf.BytesValue) */ { @@ -1389,7 +1380,7 @@ class PROTOBUF_EXPORT BytesValue final : private: friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::absl::string_view FullMessageName() { + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "google.protobuf.BytesValue"; } protected: @@ -1440,17 +1431,12 @@ class PROTOBUF_EXPORT BytesValue final : // =================================================================== - - // =================================================================== - #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ -// ------------------------------------------------------------------- - // DoubleValue // double value = 1; @@ -1465,7 +1451,7 @@ inline double DoubleValue::value() const { return _internal_value(); } inline void DoubleValue::_internal_set_value(double value) { - + _impl_.value_ = value; } inline void DoubleValue::set_value(double value) { @@ -1489,7 +1475,7 @@ inline float FloatValue::value() const { return _internal_value(); } inline void FloatValue::_internal_set_value(float value) { - + _impl_.value_ = value; } inline void FloatValue::set_value(float value) { @@ -1513,7 +1499,7 @@ inline int64_t Int64Value::value() const { return _internal_value(); } inline void Int64Value::_internal_set_value(int64_t value) { - + _impl_.value_ = value; } inline void Int64Value::set_value(int64_t value) { @@ -1537,7 +1523,7 @@ inline uint64_t UInt64Value::value() const { return _internal_value(); } inline void UInt64Value::_internal_set_value(uint64_t value) { - + _impl_.value_ = value; } inline void UInt64Value::set_value(uint64_t value) { @@ -1561,7 +1547,7 @@ inline int32_t Int32Value::value() const { return _internal_value(); } inline void Int32Value::_internal_set_value(int32_t value) { - + _impl_.value_ = value; } inline void Int32Value::set_value(int32_t value) { @@ -1585,7 +1571,7 @@ inline uint32_t UInt32Value::value() const { return _internal_value(); } inline void UInt32Value::_internal_set_value(uint32_t value) { - + _impl_.value_ = value; } inline void UInt32Value::set_value(uint32_t value) { @@ -1609,7 +1595,7 @@ inline bool BoolValue::value() const { return _internal_value(); } inline void BoolValue::_internal_set_value(bool value) { - + _impl_.value_ = value; } inline void BoolValue::set_value(bool value) { @@ -1645,11 +1631,11 @@ inline const std::string& StringValue::_internal_value() const { return _impl_.value_.Get(); } inline void StringValue::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* StringValue::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* StringValue::release_value() { @@ -1657,6 +1643,11 @@ inline std::string* StringValue::release_value() { return _impl_.value_.Release(); } inline void StringValue::set_allocated_value(std::string* value) { + if (value != nullptr) { + + } else { + + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.value_.IsDefault()) { @@ -1694,11 +1685,11 @@ inline const std::string& BytesValue::_internal_value() const { return _impl_.value_.Get(); } inline void BytesValue::_internal_set_value(const std::string& value) { - + _impl_.value_.Set(value, GetArenaForAllocation()); } inline std::string* BytesValue::_internal_mutable_value() { - + return _impl_.value_.Mutable(GetArenaForAllocation()); } inline std::string* BytesValue::release_value() { @@ -1706,6 +1697,11 @@ inline std::string* BytesValue::release_value() { return _impl_.value_.Release(); } inline void BytesValue::set_allocated_value(std::string* value) { + if (value != nullptr) { + + } else { + + } _impl_.value_.SetAllocated(value, GetArenaForAllocation()); #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING if (_impl_.value_.IsDefault()) { @@ -1716,15 +1712,30 @@ inline void BytesValue::set_allocated_value(std::string* value) { } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) -PROTOBUF_NAMESPACE_CLOSE +PROTOBUF_NAMESPACE_CLOSE // @@protoc_insertion_point(global_scope) -#include "google/protobuf/port_undef.inc" - -#endif // GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto_2epb_2eh +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_google_2fprotobuf_2fwrappers_2eproto diff --git a/libs/protobuf/tests.sh b/libs/protobuf/tests.sh new file mode 100755 index 0000000..180b870 --- /dev/null +++ b/libs/protobuf/tests.sh @@ -0,0 +1,611 @@ +#!/bin/bash +# +# Build and run tests for the protobuf project. We use this script to run +# tests on kokoro (Ubuntu and MacOS). It can run locally as well but you +# need to make sure the required compilers/tools are available. + +internal_build_cpp() { + if [ -f src/protoc ]; then + # Already built. + return + fi + + # Initialize any submodules. + git submodule update --init --recursive + + ./autogen.sh + ./configure CXXFLAGS="-fPIC -std=c++11" # -fPIC is needed for python cpp test. + # See python/setup.py for more details + make -j$(nproc) +} + +build_cpp() { + internal_build_cpp + make check -j$(nproc) || (cat src/test-suite.log; false) + cd conformance && make test_cpp && cd .. +} + +build_cpp_tcmalloc() { + internal_build_cpp + ./configure LIBS=-ltcmalloc && make clean && make \ + PTHREAD_CFLAGS='-pthread -DGOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN' \ + check + cd src + PPROF_PATH=/usr/bin/google-pprof HEAPCHECK=strict ./protobuf-test +} + +build_cpp_distcheck() { + grep -q -- "-Og" src/Makefile.am && + echo "The -Og flag is incompatible with Clang versions older than 4.0." && + exit 1 + + # Initialize any submodules. + git submodule update --init --recursive + ./autogen.sh + ./configure + make dist + + # List all files that should be included in the distribution package. + git ls-files | grep "^\(java\|python\|objectivec\|csharp\|ruby\|php\|cmake\|examples\|src/google/protobuf/.*\.proto\)" |\ + grep -v ".gitignore" | grep -v "java/lite/proguard.pgcfg" |\ + grep -v "python/compatibility_tests" | grep -v "python/docs" | grep -v "python/.repo-metadata.json" |\ + grep -v "python/protobuf_distutils" | grep -v "csharp/compatibility_tests" > dist.lst + # Unzip the dist tar file. + DIST=`ls *.tar.gz` + tar -xf $DIST + cd ${DIST//.tar.gz} + # Check if every file exists in the dist tar file. + FILES_MISSING="" + for FILE in $(<../dist.lst); do + [ -f "$FILE" ] || { + echo "$FILE is not found!" + FILES_MISSING="$FILE $FILES_MISSING" + } + done + cd .. + if [ ! -z "$FILES_MISSING" ]; then + echo "Missing files in EXTRA_DIST: $FILES_MISSING" + exit 1 + fi + + # Do the regular dist-check for C++. + make distcheck -j$(nproc) +} + +build_dist_install() { + # Create a symlink pointing to python2 and put it at the beginning of $PATH. + # This is necessary because the googletest build system involves a Python + # script that is not compatible with Python 3. More recent googletest + # versions have fixed this, but they have also removed the autotools build + # system support that we rely on. This is a temporary workaround to keep the + # googletest build working when the default python binary is Python 3. + mkdir tmp || true + pushd tmp + ln -s /usr/bin/python2 ./python + popd + PATH=$PWD/tmp:$PATH + + # Initialize any submodules. + git submodule update --init --recursive + ./autogen.sh + ./configure + make dist + + # Unzip the dist tar file and install it. + DIST=`ls *.tar.gz` + tar -xf $DIST + pushd ${DIST//.tar.gz} + ./configure && make check -j4 && make install + + export LD_LIBRARY_PATH=/usr/local/lib + + # Try to install Java + pushd java + use_java jdk11 + $MVN install + popd + + # Try to install Python + python3 -m venv venv + source venv/bin/activate + pushd python + python3 setup.py clean build sdist + pip3 install dist/protobuf-*.tar.gz + popd + deactivate + rm -rf python/venv +} + +build_csharp() { + # Required for conformance tests and to regenerate protos. + internal_build_cpp + NUGET=/usr/local/bin/nuget.exe + + # Disable some unwanted dotnet options + export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true + export DOTNET_CLI_TELEMETRY_OPTOUT=true + + # TODO(jtattermusch): is this still needed with "first time experience" + # disabled? + # Perform "dotnet new" once to get the setup preprocessing out of the + # way. That spews a lot of output (including backspaces) into logs + # otherwise, and can cause problems. It doesn't matter if this step + # is performed multiple times; it's cheap after the first time anyway. + # (It also doesn't matter if it's unnecessary, which it will be on some + # systems. It's necessary on Jenkins in order to avoid unprintable + # characters appearing in the JUnit output.) + mkdir dotnettmp + (cd dotnettmp; dotnet new > /dev/null) + rm -rf dotnettmp + + # Check that the protos haven't broken C# codegen. + # TODO(jonskeet): Fail if regenerating creates any changes. + csharp/generate_protos.sh + + csharp/buildall.sh + cd conformance && make test_csharp && cd .. + + # Run csharp compatibility test between 3.0.0 and the current version. + csharp/compatibility_tests/v3.0.0/test.sh 3.0.0 + + # Regression test for https://github.com/protocolbuffers/protobuf/issues/9526 + # - all line endings in .proto and .cs (and .csproj) files should be LF. + if git ls-files --eol csharp | grep -E '\.cs|\.proto' | grep -v w/lf + then + echo "The files listed above have mixed or CRLF line endings; please change to LF." + exit 1 + fi +} + +build_golang() { + # Go build needs `protoc`. + internal_build_cpp + # Add protoc to the path so that the examples build finds it. + export PATH="`pwd`/src:$PATH" + + export GOPATH="$HOME/gocode" + mkdir -p "$GOPATH/src/github.com/protocolbuffers" + mkdir -p "$GOPATH/src/github.com/golang" + rm -f "$GOPATH/src/github.com/protocolbuffers/protobuf" + rm -f "$GOPATH/src/github.com/golang/protobuf" + ln -s "`pwd`" "$GOPATH/src/github.com/protocolbuffers/protobuf" + export PATH="$GOPATH/bin:$PATH" + (cd $GOPATH/src/github.com/golang && git clone https://github.com/golang/protobuf.git && cd protobuf && git checkout v1.3.5) + go install github.com/golang/protobuf/protoc-gen-go + + cd examples && PROTO_PATH="-I../src -I." make gotest && cd .. +} + +use_java() { + version=$1 + case "$version" in + jdk17) + export PATH=/usr/lib/jvm/java-17-openjdk-amd64/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 + ;; + jdk11) + export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 + ;; + jdk8) + export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + ;; + jdk7) + export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 + ;; + oracle7) + export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH + export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 + ;; + esac + + MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository + MVN="$MVN -e --quiet -Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY" + + which java + java -version + $MVN -version +} + +# --batch-mode suppresses download progress output that spams the logs. +MVN="mvn --batch-mode" + +internal_build_java() { + version=$1 + dir=java_$version + # Java build needs `protoc`. + internal_build_cpp + cp -r java $dir + cd $dir && $MVN clean + # Skip tests here - callers will decide what tests they want to run + $MVN install -Dmaven.test.skip=true +} + +build_java() { + version=$1 + internal_build_java $version + # Skip the Kotlin tests on Oracle 7 + if [ "$version" == "oracle7" ]; then + $MVN test -pl bom,lite,core,util + else + $MVN test + fi + cd ../.. +} + +# The conformance tests are hard-coded to work with the $ROOT/java directory. +# So this can't run in parallel with two different sets of tests. +build_java_with_conformance_tests() { + # Java build needs `protoc`. + internal_build_cpp + # This local installation avoids the problem caused by a new version not yet in Maven Central + cd java/bom && $MVN install + cd ../.. + cd java/core && $MVN test && $MVN install + cd ../lite && $MVN test && $MVN install + cd ../util && $MVN test && $MVN install && $MVN package assembly:single + if [ "$version" == "jdk8" ]; then + cd ../kotlin && $MVN test && $MVN install + cd ../kotlin-lite && $MVN test && $MVN install + fi + cd ../.. + cd conformance && make test_java && cd .. +} + +build_java_jdk7() { + use_java jdk7 + build_java_with_conformance_tests +} + +build_java_oracle7() { + use_java oracle7 + build_java oracle7 +} + +build_java_jdk8() { + use_java jdk8 + build_java_with_conformance_tests +} + +build_java_jdk11() { + use_java jdk11 + build_java +} + +build_java_jdk17() { + use_java jdk17 + build_java +} + +build_java_linkage_monitor() { + # Linkage Monitor checks compatibility with other Google libraries + # https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + + use_java jdk11 + internal_build_cpp + + # Linkage Monitor uses $HOME/.m2 local repository + MVN="mvn -e -B -Dhttps.protocols=TLSv1.2" + cd java + # Installs the snapshot version locally + $MVN install -Dmaven.test.skip=true + + # Linkage Monitor uses the snapshot versions installed in $HOME/.m2 to verify compatibility + JAR=linkage-monitor-latest-all-deps.jar + curl -v -O "https://storage.googleapis.com/cloud-opensource-java-linkage-monitor/${JAR}" + # Fails if there's new linkage errors compared with baseline + java -jar $JAR com.google.cloud:libraries-bom +} + +build_objectivec_ios() { + # Reused the build script that takes care of configuring and ensuring things + # are up to date. The OS X test runs the objc conformance test, so skip it + # here. + objectivec/DevTools/full_mac_build.sh \ + --core-only --skip-xcode-osx --skip-xcode-tvos --skip-objc-conformance "$@" +} + +build_objectivec_ios_debug() { + build_objectivec_ios --skip-xcode-release +} + +build_objectivec_ios_release() { + build_objectivec_ios --skip-xcode-debug +} + +build_objectivec_osx() { + # Reused the build script that takes care of configuring and ensuring things + # are up to date. + objectivec/DevTools/full_mac_build.sh \ + --core-only --skip-xcode-ios --skip-xcode-tvos +} + +build_objectivec_tvos() { + # Reused the build script that takes care of configuring and ensuring things + # are up to date. The OS X test runs the objc conformance test, so skip it + # here. + objectivec/DevTools/full_mac_build.sh \ + --core-only --skip-xcode-ios --skip-xcode-osx --skip-objc-conformance "$@" +} + +build_objectivec_tvos_debug() { + build_objectivec_tvos --skip-xcode-release +} + +build_objectivec_tvos_release() { + build_objectivec_tvos --skip-xcode-debug +} + +build_python() { + internal_build_cpp + cd python + tox --skip-missing-interpreters + cd .. +} + +build_python_version() { + internal_build_cpp + cd python + envlist=$1 + tox -e $envlist + cd .. +} + +build_python37() { + build_python_version py37-python +} + +build_python38() { + build_python_version py38-python +} + +build_python39() { + build_python_version py39-python +} + +build_python310() { + build_python_version py310-python +} + +build_python_cpp() { + internal_build_cpp + export LD_LIBRARY_PATH=../src/.libs # for Linux + export DYLD_LIBRARY_PATH=../src/.libs # for OS X + cd python + tox --skip-missing-interpreters + cd .. +} + +build_python_cpp_version() { + internal_build_cpp + export LD_LIBRARY_PATH=../src/.libs # for Linux + export DYLD_LIBRARY_PATH=../src/.libs # for OS X + cd python + envlist=$1 + tox -e $envlist + cd .. +} + +build_python37_cpp() { + build_python_cpp_version py37-cpp +} + +build_python38_cpp() { + build_python_cpp_version py38-cpp +} + +build_python39_cpp() { + build_python_cpp_version py39-cpp +} + +build_python310_cpp() { + build_python_cpp_version py310-cpp +} + +build_ruby23() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.3.8 && cd .. +} +build_ruby24() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.4 && cd .. +} +build_ruby25() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.5.1 && cd .. +} +build_ruby26() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.6.0 && cd .. +} +build_ruby27() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-2.7.0 && cd .. +} +build_ruby30() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-3.0.2 && cd .. +} +build_ruby31() { + internal_build_cpp # For conformance tests. + cd ruby && bash travis-test.sh ruby-3.1.0 && cd .. +} + +build_jruby92() { + internal_build_cpp # For conformance tests. + internal_build_java jdk8 && cd .. # For Maven protobuf jar with local changes + cd ruby && bash travis-test.sh jruby-9.2.20.1 && cd .. +} + +build_jruby93() { + internal_build_cpp # For conformance tests. + internal_build_java jdk8 && cd .. # For Maven protobuf jar with local changes + cd ruby && bash travis-test.sh jruby-9.3.4.0 && cd .. +} + +use_php() { + VERSION=$1 + export PATH=/usr/local/php-${VERSION}/bin:$PATH + internal_build_cpp +} + +build_php() { + use_php $1 + pushd php + rm -rf vendor + php -v + php -m + composer update + composer test + popd + (cd conformance && make test_php) +} + +test_php_c() { + pushd php + rm -rf vendor + php -v + php -m + composer update + composer test_c + popd + (cd conformance && make test_php_c) +} + +build_php_c() { + use_php $1 + test_php_c +} + +build_php7.0_mac() { + internal_build_cpp + # Install PHP + curl -s https://php-osx.liip.ch/install.sh | bash -s 7.0 + PHP_FOLDER=`find /usr/local -type d -name "php5-7.0*"` # The folder name may change upon time + test ! -z "$PHP_FOLDER" + export PATH="$PHP_FOLDER/bin:$PATH" + + # Install Composer + wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer + chmod a+x /usr/local/bin/composer + + # Install valgrind + echo "#! /bin/bash" > valgrind + chmod ug+x valgrind + sudo mv valgrind /usr/local/bin/valgrind + + # Test + test_php_c +} + +build_php7.3_mac() { + internal_build_cpp + # Install PHP + # We can't test PHP 7.4 with these binaries yet: + # https://github.com/liip/php-osx/issues/276 + curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3 + PHP_FOLDER=`find /usr/local -type d -name "php5-7.3*"` # The folder name may change upon time + test ! -z "$PHP_FOLDER" + export PATH="$PHP_FOLDER/bin:$PATH" + + # Install Composer + wget https://getcomposer.org/download/2.0.13/composer.phar --progress=dot:mega -O /usr/local/bin/composer + chmod a+x /usr/local/bin/composer + + # Install valgrind + echo "#! /bin/bash" > valgrind + chmod ug+x valgrind + sudo mv valgrind /usr/local/bin/valgrind + + # Test + test_php_c +} + +build_php_compatibility() { + internal_build_cpp +} + +build_php_multirequest() { + use_php 7.4 + php/tests/multirequest.sh +} + +build_php8.0_all() { + build_php 8.0 + build_php 8.1 + build_php_c 8.0 + build_php_c 8.1 +} + +build_php_all_32() { + build_php 7.0 + build_php 7.1 + build_php 7.4 + build_php_c 7.0 + build_php_c 7.1 + build_php_c 7.4 + build_php_c 7.1-zts + build_php_c 7.2-zts + build_php_c 7.5-zts +} + +build_php_all() { + build_php_all_32 + build_php_multirequest + build_php_compatibility +} + +build_benchmark() { + use_php 7.2 + cd kokoro/linux/benchmark && ./run.sh +} + +# -------- main -------- + +if [ "$#" -ne 1 ]; then + echo " +Usage: $0 { cpp | + cpp_distcheck | + csharp | + java_jdk7 | + java_oracle7 | + java_jdk8 | + java_jdk11 | + java_jdk17 | + java_linkage_monitor | + objectivec_ios | + objectivec_ios_debug | + objectivec_ios_release | + objectivec_osx | + objectivec_tvos | + objectivec_tvos_debug | + objectivec_tvos_release | + python | + python_cpp | + python_compatibility | + ruby23 | + ruby24 | + ruby25 | + ruby26 | + ruby27 | + ruby30 | + ruby31 | + jruby92 | + jruby93 | + ruby_all | + php_all | + php_all_32 | + php7.0_mac | + php7.3_mac | + dist_install | + benchmark } +" + exit 1 +fi + +set -e # exit immediately on error +set -x # display all commands +cd $(dirname $0) +eval "build_$1" diff --git a/libs/protobuf/third_party/abseil-cpp b/libs/protobuf/third_party/abseil-cpp deleted file mode 160000 index 273292d..0000000 --- a/libs/protobuf/third_party/abseil-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 273292d1cfc0a94a65082ee350509af1d113344d diff --git a/libs/protobuf/third_party/jsoncpp b/libs/protobuf/third_party/jsoncpp deleted file mode 160000 index 9059f5c..0000000 --- a/libs/protobuf/third_party/jsoncpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9059f5cad030ba11d37818847443a53918c327b1 diff --git a/libs/protobuf/third_party/jsoncpp.BUILD b/libs/protobuf/third_party/jsoncpp.BUILD deleted file mode 100644 index 6d7ac3d..0000000 --- a/libs/protobuf/third_party/jsoncpp.BUILD +++ /dev/null @@ -1,37 +0,0 @@ -licenses(["unencumbered"]) # Public Domain or MIT - -exports_files(["LICENSE"]) - -cc_library( - name = "jsoncpp", - srcs = [ - "src/lib_json/json_reader.cpp", - "src/lib_json/json_tool.h", - "src/lib_json/json_value.cpp", - "src/lib_json/json_writer.cpp", - ], - hdrs = [ - "include/json/allocator.h", - "include/json/assertions.h", - "include/json/config.h", - "include/json/json_features.h", - "include/json/forwards.h", - "include/json/json.h", - "include/json/reader.h", - "include/json/value.h", - "include/json/version.h", - "include/json/writer.h", - ], - copts = [ - "-DJSON_USE_EXCEPTION=0", - "-DJSON_HAS_INT64", - ], - includes = ["include"], - visibility = ["//visibility:public"], - deps = [":private"], -) - -cc_library( - name = "private", - textual_hdrs = ["src/lib_json/json_valueiterator.inl"], -) diff --git a/libs/protobuf/toolchain/toolchains.bazelrc b/libs/protobuf/toolchain/toolchains.bazelrc index 908a26e..fbd655b 100644 --- a/libs/protobuf/toolchain/toolchains.bazelrc +++ b/libs/protobuf/toolchain/toolchains.bazelrc @@ -2,12 +2,9 @@ build:cross_config --crosstool_top=//toolchain:clang_suite build:cross_config --host_crosstool_top=@bazel_tools//tools/cpp:toolchain build:linux-aarch_64 --config=cross_config --cpu=linux-aarch_64 -build:linux-aarch64 --config=cross_config --cpu=linux-aarch_64 build:linux-ppcle_64 --config=cross_config --cpu=linux-ppcle_64 -build:linux-ppc64le --config=cross_config --cpu=linux-ppcle_64 build:linux-s390_64 --config=cross_config --cpu=linux-s390_64 build:linux-x86_32 --config=cross_config --cpu=linux-x86_32 -build:linux-i386 --config=cross_config --cpu=linux-x86_32 build:linux-x86_64 --config=cross_config --cpu=linux-x86_64 build:osx-aarch_64 --config=cross_config --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-aarch_64 build:osx-x86_64 --config=cross_config --action_env=MACOSX_DEPLOYMENT_TARGET=10.9 --cpu=osx-x86_64 diff --git a/libs/protobuf/update_compatibility_version.py b/libs/protobuf/update_compatibility_version.py new file mode 100755 index 0000000..f93479b --- /dev/null +++ b/libs/protobuf/update_compatibility_version.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +"""Compatibility tests between last released and the current version. + +Usage: ./update_compatibility_version.py .. [] +Example: ./update_compatibility_version.py 3.7.1 +""" + +from __future__ import print_function +import re +import sys + +if len(sys.argv) < 2 or len(sys.argv) > 3: + print(""" +[ERROR] Please specify a version. + +./update_compatibility_version.py.py .. [] + +Example: +./update_compatibility_version.py.py 3.7.1 2 +""") + exit(1) + +NEW_VERSION = sys.argv[1] +NEW_VERSION_INFO = NEW_VERSION.split('.') +if len(NEW_VERSION_INFO) != 3: + print(""" +[ERROR] Version must be in the format .. + +Example: +./update_compatibility_version.py.py 3.7.3 +""") + exit(1) + +if len(sys.argv) > 2: + RC_VERSION = int(sys.argv[2]) + # Do not update compatibility versions for rc release + if RC_VERSION != 0: + exit(0) + + +def RewriteTextFile(filename, line_rewriter): + lines = open(filename, 'r').readlines() + updated_lines = [] + for line in lines: + updated_lines.append(line_rewriter(line)) + if lines == updated_lines: + print('%s was not updated. Please double check.' % filename) + f = open(filename, 'w') + f.write(''.join(updated_lines)) + f.close() + + +def ReplaceVersion(line): + return re.sub(r'LAST_RELEASED=.*$', 'LAST_RELEASED=%s' % NEW_VERSION, line) + +RewriteTextFile('tests.sh', ReplaceVersion) diff --git a/libs/protobuf/update_file_lists.sh b/libs/protobuf/update_file_lists.sh new file mode 100755 index 0000000..3ef366d --- /dev/null +++ b/libs/protobuf/update_file_lists.sh @@ -0,0 +1,195 @@ +#!/bin/bash -u + +# This script copies source file lists from src/Makefile.am to cmake files. + +get_variable_value() { + local FILENAME=$1 + local VARNAME=$2 + awk " + BEGIN { start = 0; } + /^$VARNAME =/ { start = 1; } + { if (start) { print \$0; } } + /\\\\\$/ { next; } + { start = 0; } + " $FILENAME \ + | sed "s/^$VARNAME =//" \ + | sed "s/[ \\]//g" \ + | grep -v "^\\$" \ + | grep -v "^$" \ + | LC_ALL=C sort | uniq +} + +get_header_files() { + get_variable_value $@ | grep '\.h$' +} + +get_source_files() { + get_variable_value $@ | grep "cc$\|inc$" +} + +get_proto_files() { + get_variable_value $@ | grep "pb.cc$" | sed "s/pb.cc/proto/" +} + +sort_files() { + for FILE in $@; do + echo $FILE + done | LC_ALL=C sort | uniq +} + +MAKEFILE=src/Makefile.am + +[ -f "$MAKEFILE" ] || { + echo "Cannot find: $MAKEFILE" + exit 1 +} + +# Extract file lists from src/Makefile.am +GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS) +LIBPROTOBUF_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep -v /compiler/) +LIBPROTOBUF_HEADERS=$(sort_files $GZHEADERS $LIBPROTOBUF_HEADERS) +LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES) +LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES) +LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES) +LIBPROTOC_HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS | grep /compiler/) +LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs) +PROTOS=$(get_proto_files $MAKEFILE protoc_outputs) +WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA) +COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES) +COMMON_LITE_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_LITE_TEST_SOURCES) +TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES) +NON_MSVC_TEST_SOURCES=$(get_source_files $MAKEFILE NON_MSVC_TEST_SOURCES) +LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES) +LITE_ARENA_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_arena_test_SOURCES) +TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES) + +################################################################################ +# Update cmake files. +################################################################################ + +CMAKE_DIR=cmake +EXTRACT_INCLUDES_BAT=cmake/extract_includes.bat.in +[ -d "$CMAKE_DIR" ] || { + echo "Cannot find: $CMAKE_DIR" + exit 1 +} + +[ -f "$EXTRACT_INCLUDES_BAT" ] || { + echo "Cannot find: $EXTRACT_INCLUDES_BAT" + exit 1 +} + +set_cmake_value() { + local FILENAME=$1 + local VARNAME=$2 + local PREFIX=$3 + shift + shift + shift + awk -v values="$*" -v prefix="$PREFIX" " + BEGIN { start = 0; } + /^set\\($VARNAME/ { + start = 1; + print \$0; + len = split(values, vlist, \" \"); + for (i = 1; i <= len; ++i) { + printf(\" \"); + if (vlist[i] !~ /^\\\$/) { + printf(\"%s\", prefix); + } + printf(\"%s\\n\", vlist[i]); + } + next; + } + start && /^\\)/ { + start = 0; + } + !start { + print \$0; + } + " $FILENAME > /tmp/$$ + cp /tmp/$$ $FILENAME +} + + +# Replace file lists in cmake files. +CMAKE_PREFIX="\${protobuf_SOURCE_DIR}/src/" +set_cmake_value $CMAKE_DIR/libprotobuf-lite.cmake libprotobuf_lite_files $CMAKE_PREFIX $LIBPROTOBUF_LITE_SOURCES +set_cmake_value $CMAKE_DIR/libprotobuf.cmake libprotobuf_files $CMAKE_PREFIX $LIBPROTOBUF_SOURCES +set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $CMAKE_PREFIX $LIBPROTOC_SOURCES +set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_headers $CMAKE_PREFIX $LIBPROTOC_HEADERS +set_cmake_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS +set_cmake_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS +set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX '${common_lite_test_files}' $COMMON_TEST_SOURCES +set_cmake_value $CMAKE_DIR/tests.cmake common_lite_test_files $CMAKE_PREFIX $COMMON_LITE_TEST_SOURCES +set_cmake_value $CMAKE_DIR/tests.cmake tests_files $CMAKE_PREFIX $TEST_SOURCES +set_cmake_value $CMAKE_DIR/tests.cmake non_msvc_tests_files $CMAKE_PREFIX $NON_MSVC_TEST_SOURCES +set_cmake_value $CMAKE_DIR/tests.cmake lite_test_files $CMAKE_PREFIX $LITE_TEST_SOURCES +set_cmake_value $CMAKE_DIR/tests.cmake lite_arena_test_files $CMAKE_PREFIX $LITE_ARENA_TEST_SOURCES + +# Generate extract_includes.bat +echo "mkdir include" > $EXTRACT_INCLUDES_BAT +for INCLUDE in $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS $WKT_PROTOS; do + INCLUDE_DIR=$(dirname "$INCLUDE") + while [ ! "$INCLUDE_DIR" = "." ]; do + echo "mkdir include\\${INCLUDE_DIR//\//\\}" + INCLUDE_DIR=$(dirname "$INCLUDE_DIR") + done +done | sort | uniq >> $EXTRACT_INCLUDES_BAT +for INCLUDE in $(sort_files $LIBPROTOBUF_HEADERS $LIBPROTOC_HEADERS) $WKT_PROTOS; do + WINPATH=${INCLUDE//\//\\} + echo "copy \"\${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH\" include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT +done + +################################################################################ +# Update bazel BUILD files. +################################################################################ + +set_bazel_value() { + local FILENAME=$1 + local VARNAME=$2 + local PREFIX=$3 + shift + shift + shift + awk -v values="$*" -v prefix="$PREFIX" " + BEGIN { start = 0; } + /# AUTOGEN\\($VARNAME\\)/ { + start = 1; + print \$0; + # replace \$0 with indent. + sub(/#.*/, \"\", \$0) + len = split(values, vlist, \" \"); + for (i = 1; i <= len; ++i) { + printf(\"%s\\\"%s%s\\\",\n\", \$0, prefix, vlist[i]); + } + next; + } + start && /\]/ { + start = 0 + } + !start { + print \$0; + } + " $FILENAME > /tmp/$$ + cp /tmp/$$ $FILENAME +} + + +BAZEL_BUILD=./BUILD +BAZEL_PREFIX="src/" +if [ -f "$BAZEL_BUILD" ]; then + set_bazel_value $BAZEL_BUILD protobuf_lite_srcs $BAZEL_PREFIX $LIBPROTOBUF_LITE_SOURCES + set_bazel_value $BAZEL_BUILD protobuf_srcs $BAZEL_PREFIX $LIBPROTOBUF_SOURCES + set_bazel_value $BAZEL_BUILD protoc_lib_srcs $BAZEL_PREFIX $LIBPROTOC_SOURCES + set_bazel_value $BAZEL_BUILD lite_test_protos "" $LITE_PROTOS + set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS + set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS + set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_LITE_TEST_SOURCES $COMMON_TEST_SOURCES + set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES + set_bazel_value $BAZEL_BUILD non_msvc_test_srcs $BAZEL_PREFIX $NON_MSVC_TEST_SOURCES + set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES +else + echo "Skipped BUILD file update." +fi + diff --git a/libs/protobuf/update_version.py b/libs/protobuf/update_version.py new file mode 100755 index 0000000..cb9f4db --- /dev/null +++ b/libs/protobuf/update_version.py @@ -0,0 +1,405 @@ +#!/usr/bin/env python3 +# Usage: ./update_version.py .. [] +# +# Example: +# ./update_version.py 3.7.1 2 +# => Version will become 3.7.1-rc-2 (beta) +# ./update_version.py 3.7.1 +# => Version will become 3.7.1 (stable) + +import datetime +import re +import sys +from xml.dom import minidom + +if len(sys.argv) < 2 or len(sys.argv) > 3: + print(""" +[ERROR] Please specify a version. + +./update_version.py .. [] + +Example: +./update_version.py 3.7.1 2 +""") + exit(1) + +NEW_VERSION = sys.argv[1] +NEW_VERSION_INFO = [int(x) for x in NEW_VERSION.split('.')] +if len(NEW_VERSION_INFO) != 3: + print(""" +[ERROR] Version must be in the format .. + +Example: +./update_version.py 3.7.3 +""") + exit(1) + +RC_VERSION = -1 +if len(sys.argv) > 2: + RC_VERSION = int(sys.argv[2]) + + +def Find(elem, tagname): + for child in elem.childNodes: + if child.nodeName == tagname: + return child + return None + + +def FindAndClone(elem, tagname): + return Find(elem, tagname).cloneNode(True) + + +def ReplaceText(elem, text): + elem.firstChild.replaceWholeText(text) + + +def GetFullVersion(rc_suffix = '-rc-'): + if RC_VERSION < 0: + return NEW_VERSION + else: + return '%s%s%s' % (NEW_VERSION, rc_suffix, RC_VERSION) + + +def GetSharedObjectVersion(): + protobuf_version_offset = 11 + expected_major_version = 3 + if NEW_VERSION_INFO[0] != expected_major_version: + print("""[ERROR] Major protobuf version has changed. Please update +update_version.py to readjust the protobuf_version_offset and +expected_major_version such that the PROTOBUF_VERSION in src/Makefile.am is +always increasing. + """) + exit(1) + return [NEW_VERSION_INFO[1] + protobuf_version_offset, NEW_VERSION_INFO[2], 0] + + +def RewriteXml(filename, rewriter, add_xml_prefix=True): + document = minidom.parse(filename) + rewriter(document) + # document.toxml() always prepend the XML version without inserting new line. + # We wants to preserve as much of the original formatting as possible, so we + # will remove the default XML version and replace it with our custom one when + # wherever necessary. + content = document.toxml().replace('', '') + file_handle = open(filename, 'wb') + if add_xml_prefix: + file_handle.write(b'\n') + file_handle.write(content.encode('utf-8')) + file_handle.write(b'\n') + file_handle.close() + + +def RewriteTextFile(filename, line_rewriter): + lines = open(filename, 'r').readlines() + updated_lines = [] + for line in lines: + updated_lines.append(line_rewriter(line)) + if lines == updated_lines: + print('%s was not updated. Please double check.' % filename) + f = open(filename, 'w') + f.write(''.join(updated_lines)) + f.close() + + +def UpdateCMake(): + cmake_files = ( + 'cmake/libprotobuf.cmake', + 'cmake/libprotobuf-lite.cmake', + 'cmake/libprotoc.cmake' + ) + for cmake_file in cmake_files: + RewriteTextFile(cmake_file, + lambda line : re.sub( + r'SOVERSION ([0-9]+)$', + 'SOVERSION %s' % GetSharedObjectVersion()[0], + line)) + + +def UpdateConfigure(): + RewriteTextFile('configure.ac', + lambda line : re.sub( + r'^AC_INIT\(\[Protocol Buffers\],\[.*\],\[protobuf@googlegroups.com\],\[protobuf\]\)$', + ('AC_INIT([Protocol Buffers],[%s],[protobuf@googlegroups.com],[protobuf])' + % GetFullVersion()), + line)) + + +def UpdateCpp(): + cpp_version = '%d%03d%03d' % ( + NEW_VERSION_INFO[0], NEW_VERSION_INFO[1], NEW_VERSION_INFO[2]) + version_suffix = '' + if RC_VERSION != -1: + version_suffix = '-rc%s' % RC_VERSION + def RewriteCommon(line): + line = re.sub( + r'^#define GOOGLE_PROTOBUF_VERSION .*$', + '#define GOOGLE_PROTOBUF_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^#define PROTOBUF_VERSION .*$', + '#define PROTOBUF_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^#define GOOGLE_PROTOBUF_VERSION_SUFFIX .*$', + '#define GOOGLE_PROTOBUF_VERSION_SUFFIX "%s"' % version_suffix, + line) + line = re.sub( + r'^#define PROTOBUF_VERSION_SUFFIX .*$', + '#define PROTOBUF_VERSION_SUFFIX "%s"' % version_suffix, + line) + if NEW_VERSION_INFO[2] == 0: + line = re.sub( + r'^#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC .*$', + '#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC %s' % cpp_version, + line) + line = re.sub( + r'^#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION .*$', + '#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^static const int kMinHeaderVersionForLibrary = .*$', + 'static const int kMinHeaderVersionForLibrary = %s;' % cpp_version, + line) + line = re.sub( + r'^static const int kMinHeaderVersionForProtoc = .*$', + 'static const int kMinHeaderVersionForProtoc = %s;' % cpp_version, + line) + return line + + def RewritePortDef(line): + line = re.sub( + r'^#define PROTOBUF_VERSION .*$', + '#define PROTOBUF_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^#define PROTOBUF_VERSION_SUFFIX .*$', + '#define PROTOBUF_VERSION_SUFFIX "%s"' % version_suffix, + line) + if NEW_VERSION_INFO[2] == 0: + line = re.sub( + r'^#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC .*$', + '#define PROTOBUF_MIN_HEADER_VERSION_FOR_PROTOC %s' % cpp_version, + line) + line = re.sub( + r'^#define PROTOBUF_MIN_PROTOC_VERSION .*$', + '#define PROTOBUF_MIN_PROTOC_VERSION %s' % cpp_version, + line) + line = re.sub( + r'^#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION .*$', + '#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION %s' % cpp_version, + line) + return line + + def RewritePbH(line): + line = re.sub( + r'^#if PROTOBUF_VERSION < .*$', + '#if PROTOBUF_VERSION < %s' % cpp_version, + line) + line = re.sub( + r'^#if .* < PROTOBUF_MIN_PROTOC_VERSION$', + '#if %s < PROTOBUF_MIN_PROTOC_VERSION' % cpp_version, + line) + return line + + RewriteTextFile('src/google/protobuf/stubs/common.h', RewriteCommon) + RewriteTextFile('src/google/protobuf/port_def.inc', RewritePortDef) + RewriteTextFile('src/google/protobuf/any.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/api.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/descriptor.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/duration.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/empty.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/field_mask.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/source_context.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/struct.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/timestamp.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/type.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/wrappers.pb.h', RewritePbH) + RewriteTextFile('src/google/protobuf/compiler/plugin.pb.h', RewritePbH) + + +def UpdateCsharp(): + RewriteXml('csharp/src/Google.Protobuf/Google.Protobuf.csproj', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'PropertyGroup'), 'VersionPrefix'), + GetFullVersion(rc_suffix = '-rc')), + add_xml_prefix=False) + + RewriteXml('csharp/Google.Protobuf.Tools.nuspec', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'metadata'), 'version'), + GetFullVersion(rc_suffix = '-rc'))) + + +def UpdateJava(): + RewriteXml('java/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), GetFullVersion())) + + RewriteXml('java/bom/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), GetFullVersion())) + + RewriteXml('java/core/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + GetFullVersion())) + + RewriteXml('java/lite/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + GetFullVersion())) + + RewriteXml('java/util/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + GetFullVersion())) + + RewriteXml('java/kotlin/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + GetFullVersion())) + + RewriteXml('java/kotlin-lite/pom.xml', + lambda document : ReplaceText( + Find(Find(document.documentElement, 'parent'), 'version'), + GetFullVersion())) + + RewriteXml('protoc-artifacts/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), GetFullVersion())) + + RewriteTextFile('java/README.md', + lambda line : re.sub( + r'.*', + '%s' % GetFullVersion(), + line)) + + RewriteTextFile('java/README.md', + lambda line : re.sub( + r'implementation \'com.google.protobuf:protobuf-java:.*\'', + 'implementation \'com.google.protobuf:protobuf-java:%s\'' % GetFullVersion(), + line)) + + RewriteTextFile('java/lite.md', + lambda line : re.sub( + r'.*', + '%s' % GetFullVersion(), + line)) + + +def UpdateMakefile(): + RewriteTextFile('src/Makefile.am', + lambda line : re.sub( + r'^PROTOBUF_VERSION = .*$', + 'PROTOBUF_VERSION = %s' % ":".join(map(str,GetSharedObjectVersion())), + line)) + + +def UpdateObjectiveC(): + RewriteTextFile('Protobuf.podspec', + lambda line : re.sub( + r"^ s.version = '.*'$", + " s.version = '%s'" % GetFullVersion(rc_suffix = '-rc'), + line)) + RewriteTextFile('Protobuf-C++.podspec', + lambda line : re.sub( + r"^ s.version = '.*'$", + " s.version = '%s'" % GetFullVersion(rc_suffix = '-rc'), + line)) + + +def UpdatePhp(): + def Callback(document): + def CreateNode(tagname, indent, children): + elem = document.createElement(tagname) + indent += 1 + for child in children: + elem.appendChild(document.createTextNode('\n' + (' ' * indent))) + elem.appendChild(child) + indent -= 1 + elem.appendChild(document.createTextNode('\n' + (' ' * indent))) + return elem + + root = document.documentElement + now = datetime.datetime.now() + ReplaceText(Find(root, 'date'), now.strftime('%Y-%m-%d')) + ReplaceText(Find(root, 'time'), now.strftime('%H:%M:%S')) + version = Find(root, 'version') + ReplaceText(Find(version, 'release'), GetFullVersion(rc_suffix = 'RC')) + ReplaceText(Find(version, 'api'), NEW_VERSION) + stability = Find(root, 'stability') + ReplaceText(Find(stability, 'release'), + 'stable' if RC_VERSION < 0 else 'beta') + ReplaceText(Find(stability, 'api'), 'stable' if RC_VERSION < 0 else 'beta') + changelog = Find(root, 'changelog') + for old_version in changelog.getElementsByTagName('version'): + if Find(old_version, 'release').firstChild.nodeValue == NEW_VERSION: + print ('[WARNING] Version %s already exists in the change log.' + % NEW_VERSION) + return + if RC_VERSION != 0: + changelog.appendChild(document.createTextNode(' ')) + release = CreateNode('release', 2, [ + CreateNode('version', 3, [ + FindAndClone(version, 'release'), + FindAndClone(version, 'api') + ]), + CreateNode('stability', 3, [ + FindAndClone(stability, 'release'), + FindAndClone(stability, 'api') + ]), + FindAndClone(root, 'date'), + FindAndClone(root, 'time'), + FindAndClone(root, 'license'), + CreateNode('notes', 3, []), + ]) + changelog.appendChild(release) + changelog.appendChild(document.createTextNode('\n ')) + RewriteXml('php/ext/google/protobuf/package.xml', Callback) + RewriteTextFile('php/ext/google/protobuf/protobuf.h', + lambda line : re.sub( + r"^#define PHP_PROTOBUF_VERSION .*$", + "#define PHP_PROTOBUF_VERSION \"%s\"" % GetFullVersion(rc_suffix = 'RC'), + line)) + +def UpdatePython(): + RewriteTextFile('python/google/protobuf/__init__.py', + lambda line : re.sub( + r"^__version__ = '.*'$", + "__version__ = '%s'" % GetFullVersion(rc_suffix = 'rc'), + line)) + +def UpdateRuby(): + RewriteXml('ruby/pom.xml', + lambda document : ReplaceText( + Find(document.documentElement, 'version'), GetFullVersion())) + RewriteXml('ruby/pom.xml', + lambda document : ReplaceText( + Find(Find(Find(document.documentElement, 'dependencies'), 'dependency'), 'version'), + GetFullVersion())) + RewriteTextFile('ruby/google-protobuf.gemspec', + lambda line : re.sub( + r'^ s.version = ".*"$', + ' s.version = "%s"' % GetFullVersion(rc_suffix = '.rc.'), + line)) + +def UpdateBazel(): + RewriteTextFile('protobuf_version.bzl', + lambda line : re.sub( + r"^PROTOBUF_VERSION = '.*'$", + "PROTOBUF_VERSION = '%s'" % GetFullVersion(), + line)) + + +UpdateCMake() +UpdateConfigure() +UpdateCsharp() +UpdateCpp() +UpdateJava() +UpdateMakefile() +UpdateObjectiveC() +UpdatePhp() +UpdatePython() +UpdateRuby() +UpdateBazel() diff --git a/libs/protobuf/util/python/BUILD.bazel b/libs/protobuf/util/python/BUILD.bazel new file mode 100644 index 0000000..071efd2 --- /dev/null +++ b/libs/protobuf/util/python/BUILD.bazel @@ -0,0 +1,22 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +exports_files(["BUILD.bazel"]) + +# This is a placeholder for python headers. Projects needing to use +# fast cpp protos in protobuf's python interface should build with +# --define=use_fast_cpp_protos=true, and in addition, provide +# //external:python_headers dependency that in turn provides Python.h. +# +# Projects that include protobuf using a Bazel external repository will need to +# add a workspace rule to their WORKSPACE files to add an external workspace +# that includes the Python headers. For example, the protobuf WORKSPACE file +# includes the following local_repository rule that points to this directory: +# +# new_local_repository( +# name = "python_headers", +# path = __workspace_dir__ + "/util/python", +# ) +cc_library( + name = "python_headers", + visibility = ["//visibility:public"], +) diff --git a/libs/protobuf/version.json b/libs/protobuf/version.json index 4244127..fad4094 100644 --- a/libs/protobuf/version.json +++ b/libs/protobuf/version.json @@ -1,17 +1,17 @@ { - "main": { - "protoc_version": "22-dev", + "21.x": { + "protoc_version": "21.12", "lts": false, - "date": "2022-07-21", + "date": "2022-12-12", "languages": { - "cpp": "3.22-dev", - "csharp": "3.22-dev", - "java": "3.22-dev", - "javascript": "3.22-dev", - "objectivec": "3.22-dev", - "php": "3.22-dev", - "python": "4.22-dev", - "ruby": "3.22-dev" + "cpp": "3.21.12", + "csharp": "3.21.12", + "java": "3.21.12", + "javascript": "3.21.12", + "objectivec": "3.21.12", + "php": "3.21.12", + "python": "4.21.12", + "ruby": "3.21.12" } } -} +} \ No newline at end of file diff --git a/tests/test_test.cpp b/tests/test_test.cpp index ecd9d13..c09f6be 100644 --- a/tests/test_test.cpp +++ b/tests/test_test.cpp @@ -18,6 +18,15 @@ #include +#include "WHISPER/InternalUDPService.hpp" +#include "WHISPER/Messages/Message.hpp" +#include "WHISPER/Messages/Track.hpp" +#include "zmq.hpp" + +#include +#include +#include + /** * @brief brief test description * @ingroup group