diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d7cdb7..cdeb559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,13 @@ cmake_minimum_required(VERSION 3.0) project(tinyrpc) -# set(CMAKE_CXX_STANDARD 14) + + +set(CMAKE_CXX_STANDARD 17) enable_language(CXX ASM) -add_compile_options(-g -Wall -std=c++17) +add_compile_options(-g -Wall) include_directories(includes/coroutine) include_directories(includes/log) @@ -14,6 +16,7 @@ include_directories(includes/net) include_directories(includes/net/tcp) include_directories(includes/net/tinypb) +aux_source_directory(${CMAKE_SOURCE_DIR}/src SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/src/coroutine COROUTINE_SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/src/net NET_SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/src/net/tcp TCP_SRC_LIST) @@ -29,6 +32,7 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) add_library(tinyrpc + # ${SRC_LIST} ${COROUTINE_SRC_LIST} ${TCP_SRC_LIST} ${NET_SRC_LIST} @@ -43,6 +47,53 @@ add_executable(test_tinyrpc ${TEST_SRC_LIST} ) +# 引入 abseil-cpp 子目录 +add_subdirectory(./third_party/abseil-cpp absl) + + +set(ABSEL_LIBARARY + absl::absl_check + absl::absl_log + absl::algorithm + absl::base + absl::bind_front + absl::bits + absl::btree + absl::cleanup + absl::cord + absl::core_headers + absl::debugging + absl::die_if_null + absl::dynamic_annotations + absl::flags + absl::flat_hash_map + absl::flat_hash_set + absl::function_ref + absl::hash + absl::layout + absl::log_initialize + absl::log_severity + absl::memory + absl::node_hash_map + absl::node_hash_set + absl::optional + absl::span + absl::status + absl::statusor + absl::strings + absl::synchronization + absl::time + absl::type_traits + absl::utility + absl::variant +) + + +# 链接库 +target_link_libraries(tinyrpc PRIVATE protobuf) # 链接 Protobuf 库 +target_link_libraries(tinyrpc PRIVATE ${ABSEL_LIBARARY}) # 链接 Protobuf 库 target_link_libraries(test_tinyrpc PRIVATE tinyrpc) -target_link_libraries(test_tinyrpc PUBLIC protobuf) -target_link_libraries(test_tinyrpc PUBLIC stdc++) + + + + diff --git a/includes/net/tinypb/tinypb_dispatcher.hpp b/includes/net/tinypb/tinypb_dispatcher.hpp index 7575aa7..2606995 100644 --- a/includes/net/tinypb/tinypb_dispatcher.hpp +++ b/includes/net/tinypb/tinypb_dispatcher.hpp @@ -10,6 +10,8 @@ namespace tinyrpc { class TinypbDispatcher : public AbstractDispatcher { using Service = google::protobuf::Service; + using Method = google::protobuf::MethodDescriptor; + using Message = google::protobuf::Message; public: TinypbDispatcher(); ~TinypbDispatcher(); diff --git a/src/net/reactor.cc b/src/net/reactor.cc index 0cdd2dd..3dca607 100644 --- a/src/net/reactor.cc +++ b/src/net/reactor.cc @@ -274,4 +274,6 @@ namespace tinyrpc { close(m_rousefd); t_reactor = nullptr; } -} \ No newline at end of file +} + + diff --git a/src/net/tcp/tcp_connection.cc b/src/net/tcp/tcp_connection.cc index 45419b9..3f3a5b4 100644 --- a/src/net/tcp/tcp_connection.cc +++ b/src/net/tcp/tcp_connection.cc @@ -137,6 +137,8 @@ namespace tinyrpc { } std::unique_ptr resp(new TinypbData); m_server.getDispatcher().dispatcher(*this, *data, *resp); + + m_server.getCoder().encoder(m_writeBuffer, *resp); } diff --git a/src/net/tinypb/tinypb_coder.cc b/src/net/tinypb/tinypb_coder.cc index b931b63..18a35f3 100644 --- a/src/net/tinypb/tinypb_coder.cc +++ b/src/net/tinypb/tinypb_coder.cc @@ -13,7 +13,7 @@ namespace tinyrpc { static const char PB_START = 0x02; // start char static const char PB_END = 0x03; // end char - static const int MSG_REQ_LEN = 20; // default length of msg_req + // static const int MSG_REQ_LEN = 20; // default length of msg_req TinypbCoder::TinypbCoder() { // TODO @@ -79,7 +79,7 @@ namespace tinyrpc { buf[cur_index++] = PB_END; memcpy(buffer.getWriteAddress(), buf.get(), pk_len); - + buffer.writeOffset(pk_len); return true; } @@ -93,17 +93,17 @@ namespace tinyrpc { bool isFullPack = false; int pack_len = -1; - for(int i = 0; i < buffer.getReadable(); i++) { + for(int i = 0; i < static_cast(buffer.getReadable()); i++) { if(buff[i] == PB_START) { - if(i + 1 >= buffer.getReadable()) { + if(i + 1 >= static_cast(buffer.getReadable())) { return false; // 包不完整 } pack_len = getInt32FromNetByte(buff[i + 1]); end_index = pack_len + i - 1; - if(end_index >= buffer.getReadable()) { + if(end_index >= static_cast(buffer.getReadable())) { continue; } @@ -144,7 +144,7 @@ namespace tinyrpc { cur_index = cur_index + pbdata.msg_req_len; - if (cur_index > end_index || cur_index + sizeof(int32_t) - 1 > end_index) { + if (cur_index > end_index || cur_index + static_cast(sizeof(int32_t)) - 1 > end_index) { return false; } @@ -167,7 +167,7 @@ namespace tinyrpc { cur_index = cur_index + pbdata.service_name_len; - if(cur_index > end_index || cur_index + sizeof(int32_t) - 1 > end_index) { + if(cur_index > end_index || cur_index + static_cast(sizeof(int32_t)) - 1 > end_index) { return false; } @@ -175,7 +175,7 @@ namespace tinyrpc { cur_index = cur_index + sizeof(int32_t); - if(cur_index > end_index || cur_index + sizeof(int32_t) - 1 > end_index) { + if(cur_index > end_index || cur_index + static_cast(sizeof(int32_t)) - 1 > end_index) { return false; } @@ -205,7 +205,9 @@ namespace tinyrpc { pbdata.pb_data = std::string(&buff[cur_index], pb_data_len); + cur_index += pb_data_len; + buffer.readOffset(cur_index - start_index); return true; diff --git a/src/net/tinypb/tinypb_dispatcher.cc b/src/net/tinypb/tinypb_dispatcher.cc index 1a94dd4..1f36245 100644 --- a/src/net/tinypb/tinypb_dispatcher.cc +++ b/src/net/tinypb/tinypb_dispatcher.cc @@ -2,11 +2,13 @@ #include "logger.hpp" #include "tinypb_data.hpp" #include "error_code.hpp" +#include +#include #include namespace tinyrpc { TinypbDispatcher::TinypbDispatcher() {} - // TODO + TinypbDispatcher::~TinypbDispatcher() { } @@ -30,7 +32,7 @@ namespace tinyrpc { auto it = m_service_map.find(service_name); - if (it == m_service_map.end() || !((*it).second)) { + if (it == m_service_map.end() || !(it->second)) { respond.err_code = ERROR_SERVICE_NOT_FOUND; std::stringstream ss; ss << "not found service_name:[" << service_name << "]"; @@ -41,7 +43,42 @@ namespace tinyrpc { Service* service = it->second; - const google::protobuf::MethodDescriptor* method = service->GetDescriptor()->FindMethodByName(method_name); + const Method* method = service->GetDescriptor()->FindMethodByName(method_name); + // const Method* method = nullptr; + if(method == nullptr) { + respond.err_code = ERROR_METHOD_NOT_FOUND; + std::stringstream ss; + ss << "not found service_name:[" << service_name << "]"; + respond.err_info = ss.str(); + return; + } + std::unique_ptr requestMsg (service->GetRequestPrototype(method).New()); + + ret = requestMsg->ParseFromString(pbdata.pb_data); + + if(ret == false) { + respond.err_code = ERROR_FAILED_SERIALIZE; + std::stringstream ss; + ss << "faild to parse request data, request.name:[" << requestMsg->GetDescriptor()->full_name() << "]"; + respond.err_info = ss.str(); + return; + } + + std::unique_ptr respondMsg (service->GetRequestPrototype(method).New()); + + auto callback = [&respond, &respondMsg] { + if(!respondMsg->SerializePartialToString(&respond.pb_data)) { + respond.pb_data = ""; + logger() << respond.msg_req << "|reply error! encode reply package error"; + respond.err_code = ERROR_FAILED_SERIALIZE; + respond.err_info = "failed to serilize relpy data"; + } else { + logger() << respond.msg_req << "|Set server response data:" << respondMsg->ShortDebugString(); + } + }; + + service->CallMethod(method, nullptr, requestMsg.get(), respondMsg.get(), nullptr /* callback */); + } bool TinypbDispatcher::parseServiceFullName(const std::string& name, std::string& serviceName, std::string& methodName) { diff --git a/test/protobuftest/addressbook.pb.cc b/test/protobuftest/addressbook.pb.cc new file mode 100644 index 0000000..ceed90a --- /dev/null +++ b/test/protobuftest/addressbook.pb.cc @@ -0,0 +1,1051 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: addressbook.proto +// Protobuf C++ Version: 5.28.0 + +#include "addressbook.pb.h" + +#include +#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/generated_message_tctable_impl.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" +PROTOBUF_PRAGMA_INIT_SEG +namespace _pb = ::google::protobuf; +namespace _pbi = ::google::protobuf::internal; +namespace _fl = ::google::protobuf::internal::field_layout; +namespace tutorial { + +inline constexpr Person_PhoneNumber::Impl_::Impl_( + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + number_( + &::google::protobuf::internal::fixed_address_empty_string, + ::_pbi::ConstantInitialized()), + type_{static_cast< ::tutorial::Person_PhoneType >(2)} {} + +template +PROTOBUF_CONSTEXPR Person_PhoneNumber::Person_PhoneNumber(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(::_pbi::ConstantInitialized()) { +} +struct Person_PhoneNumberDefaultTypeInternal { + PROTOBUF_CONSTEXPR Person_PhoneNumberDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~Person_PhoneNumberDefaultTypeInternal() {} + union { + Person_PhoneNumber _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 Person_PhoneNumberDefaultTypeInternal _Person_PhoneNumber_default_instance_; + +inline constexpr Person::Impl_::Impl_( + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + phones_{}, + name_( + &::google::protobuf::internal::fixed_address_empty_string, + ::_pbi::ConstantInitialized()), + email_( + &::google::protobuf::internal::fixed_address_empty_string, + ::_pbi::ConstantInitialized()), + id_{0} {} + +template +PROTOBUF_CONSTEXPR Person::Person(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(::_pbi::ConstantInitialized()) { +} +struct PersonDefaultTypeInternal { + PROTOBUF_CONSTEXPR PersonDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~PersonDefaultTypeInternal() {} + union { + Person _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 PersonDefaultTypeInternal _Person_default_instance_; + +inline constexpr AddressBook::Impl_::Impl_( + ::_pbi::ConstantInitialized) noexcept + : people_{}, + _cached_size_{0} {} + +template +PROTOBUF_CONSTEXPR AddressBook::AddressBook(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(::_pbi::ConstantInitialized()) { +} +struct AddressBookDefaultTypeInternal { + PROTOBUF_CONSTEXPR AddressBookDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~AddressBookDefaultTypeInternal() {} + union { + AddressBook _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 AddressBookDefaultTypeInternal _AddressBook_default_instance_; +} // namespace tutorial +static const ::_pb::EnumDescriptor* file_level_enum_descriptors_addressbook_2eproto[1]; +static constexpr const ::_pb::ServiceDescriptor** + file_level_service_descriptors_addressbook_2eproto = nullptr; +const ::uint32_t + TableStruct_addressbook_2eproto::offsets[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::tutorial::Person_PhoneNumber, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person_PhoneNumber, _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(::tutorial::Person_PhoneNumber, _impl_.number_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person_PhoneNumber, _impl_.type_), + 0, + 1, + PROTOBUF_FIELD_OFFSET(::tutorial::Person, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person, _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(::tutorial::Person, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person, _impl_.id_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person, _impl_.email_), + PROTOBUF_FIELD_OFFSET(::tutorial::Person, _impl_.phones_), + 0, + 2, + 1, + ~0u, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::tutorial::AddressBook, _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(::tutorial::AddressBook, _impl_.people_), +}; + +static const ::_pbi::MigrationSchema + schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + {0, 10, -1, sizeof(::tutorial::Person_PhoneNumber)}, + {12, 24, -1, sizeof(::tutorial::Person)}, + {28, -1, -1, sizeof(::tutorial::AddressBook)}, +}; +static const ::_pb::Message* const file_default_instances[] = { + &::tutorial::_Person_PhoneNumber_default_instance_._instance, + &::tutorial::_Person_default_instance_._instance, + &::tutorial::_AddressBook_default_instance_._instance, +}; +const char descriptor_table_protodef_addressbook_2eproto[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + "\n\021addressbook.proto\022\010tutorial\"\243\002\n\006Person" + "\022\014\n\004name\030\001 \001(\t\022\n\n\002id\030\002 \001(\005\022\r\n\005email\030\003 \001(" + "\t\022,\n\006phones\030\004 \003(\0132\034.tutorial.Person.Phon" + "eNumber\032X\n\013PhoneNumber\022\016\n\006number\030\001 \001(\t\0229" + "\n\004type\030\002 \001(\0162\032.tutorial.Person.PhoneType" + ":\017PHONE_TYPE_HOME\"h\n\tPhoneType\022\032\n\026PHONE_" + "TYPE_UNSPECIFIED\020\000\022\025\n\021PHONE_TYPE_MOBILE\020" + "\001\022\023\n\017PHONE_TYPE_HOME\020\002\022\023\n\017PHONE_TYPE_WOR" + "K\020\003\"/\n\013AddressBook\022 \n\006people\030\001 \003(\0132\020.tut" + "orial.Person" +}; +static ::absl::once_flag descriptor_table_addressbook_2eproto_once; +PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_addressbook_2eproto = { + false, + false, + 372, + descriptor_table_protodef_addressbook_2eproto, + "addressbook.proto", + &descriptor_table_addressbook_2eproto_once, + nullptr, + 0, + 3, + schemas, + file_default_instances, + TableStruct_addressbook_2eproto::offsets, + file_level_enum_descriptors_addressbook_2eproto, + file_level_service_descriptors_addressbook_2eproto, +}; +namespace tutorial { +const ::google::protobuf::EnumDescriptor* Person_PhoneType_descriptor() { + ::google::protobuf::internal::AssignDescriptors(&descriptor_table_addressbook_2eproto); + return file_level_enum_descriptors_addressbook_2eproto[0]; +} +PROTOBUF_CONSTINIT const uint32_t Person_PhoneType_internal_data_[] = { + 262144u, 0u, }; +bool Person_PhoneType_IsValid(int value) { + return 0 <= value && value <= 3; +} +#if (__cplusplus < 201703) && \ + (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) + +constexpr Person_PhoneType Person::PHONE_TYPE_UNSPECIFIED; +constexpr Person_PhoneType Person::PHONE_TYPE_MOBILE; +constexpr Person_PhoneType Person::PHONE_TYPE_HOME; +constexpr Person_PhoneType Person::PHONE_TYPE_WORK; +constexpr Person_PhoneType Person::PhoneType_MIN; +constexpr Person_PhoneType Person::PhoneType_MAX; +constexpr int Person::PhoneType_ARRAYSIZE; + +#endif // (__cplusplus < 201703) && + // (!defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)) +// =================================================================== + +class Person_PhoneNumber::_Internal { + public: + using HasBits = + decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_._has_bits_); +}; + +Person_PhoneNumber::Person_PhoneNumber(::google::protobuf::Arena* arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:tutorial.Person.PhoneNumber) +} +inline PROTOBUF_NDEBUG_INLINE Person_PhoneNumber::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, ::google::protobuf::Arena* arena, + const Impl_& from, const ::tutorial::Person_PhoneNumber& from_msg) + : _has_bits_{from._has_bits_}, + _cached_size_{0}, + number_(arena, from.number_) {} + +Person_PhoneNumber::Person_PhoneNumber( + ::google::protobuf::Arena* arena, + const Person_PhoneNumber& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + Person_PhoneNumber* const _this = this; + (void)_this; + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); + new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from); + _impl_.type_ = from._impl_.type_; + + // @@protoc_insertion_point(copy_constructor:tutorial.Person.PhoneNumber) +} +inline PROTOBUF_NDEBUG_INLINE Person_PhoneNumber::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena) + : _cached_size_{0}, + number_(arena), + type_{static_cast< ::tutorial::Person_PhoneType >(2)} {} + +inline void Person_PhoneNumber::SharedCtor(::_pb::Arena* arena) { + new (&_impl_) Impl_(internal_visibility(), arena); +} +Person_PhoneNumber::~Person_PhoneNumber() { + // @@protoc_insertion_point(destructor:tutorial.Person.PhoneNumber) + _internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + SharedDtor(); +} +inline void Person_PhoneNumber::SharedDtor() { + ABSL_DCHECK(GetArena() == nullptr); + _impl_.number_.Destroy(); + _impl_.~Impl_(); +} + +PROTOBUF_CONSTINIT +PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::google::protobuf::MessageLite::ClassDataFull + Person_PhoneNumber::_class_data_ = { + ::google::protobuf::Message::ClassData{ + &_Person_PhoneNumber_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &Person_PhoneNumber::MergeImpl, +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::google::protobuf::Message::GetDeleteImpl(), + ::google::protobuf::Message::GetNewImpl(), + ::google::protobuf::Message::GetClearImpl(), &Person_PhoneNumber::ByteSizeLong, + &Person_PhoneNumber::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_._cached_size_), + false, + }, + &Person_PhoneNumber::kDescriptorMethods, + &descriptor_table_addressbook_2eproto, + nullptr, // tracker +}; +const ::google::protobuf::MessageLite::ClassData* Person_PhoneNumber::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(_class_data_.tc_table); + return _class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<1, 2, 1, 42, 2> Person_PhoneNumber::_table_ = { + { + PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_._has_bits_), + 0, // no _extensions_ + 2, 8, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967292, // skipmap + offsetof(decltype(_table_), field_entries), + 2, // num_field_entries + 1, // num_aux_entries + offsetof(decltype(_table_), aux_entries), + _class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::tutorial::Person_PhoneNumber>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; + {::_pbi::TcParser::FastEr0S1, + {16, 1, 3, PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_.type_)}}, + // optional string number = 1; + {::_pbi::TcParser::FastSS1, + {10, 0, 0, PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_.number_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // optional string number = 1; + {PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_.number_), _Internal::kHasBitsOffset + 0, 0, + (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, + // optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; + {PROTOBUF_FIELD_OFFSET(Person_PhoneNumber, _impl_.type_), _Internal::kHasBitsOffset + 1, 0, + (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, + }}, {{ + {0, 4}, + }}, {{ + "\33\6\0\0\0\0\0\0" + "tutorial.Person.PhoneNumber" + "number" + }}, +}; + +PROTOBUF_NOINLINE void Person_PhoneNumber::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.Person.PhoneNumber) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _impl_._has_bits_[0]; + if (cached_has_bits & 0x00000003u) { + if (cached_has_bits & 0x00000001u) { + _impl_.number_.ClearNonDefaultToEmpty(); + } + _impl_.type_ = 2; + } + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::uint8_t* Person_PhoneNumber::_InternalSerialize( + const MessageLite& base, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) { + const Person_PhoneNumber& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::uint8_t* Person_PhoneNumber::_InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + const Person_PhoneNumber& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(serialize_to_array_start:tutorial.Person.PhoneNumber) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // optional string number = 1; + if (cached_has_bits & 0x00000001u) { + const std::string& _s = this_._internal_number(); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(_s.data(), static_cast(_s.length()), ::google::protobuf::internal::WireFormat::SERIALIZE, + "tutorial.Person.PhoneNumber.number"); + target = stream->WriteStringMaybeAliased(1, _s, target); + } + + // optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; + if (cached_has_bits & 0x00000002u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteEnumToArray( + 2, this_._internal_type(), target); + } + + if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.Person.PhoneNumber) + return target; + } + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::size_t Person_PhoneNumber::ByteSizeLong(const MessageLite& base) { + const Person_PhoneNumber& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::size_t Person_PhoneNumber::ByteSizeLong() const { + const Person_PhoneNumber& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:tutorial.Person.PhoneNumber) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + ::_pbi::Prefetch5LinesFrom7Lines(&this_); + cached_has_bits = this_._impl_._has_bits_[0]; + if (cached_has_bits & 0x00000003u) { + // optional string number = 1; + if (cached_has_bits & 0x00000001u) { + total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( + this_._internal_number()); + } + // optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; + if (cached_has_bits & 0x00000002u) { + total_size += 1 + + ::_pbi::WireFormatLite::EnumSize(this_._internal_type()); + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); + } + +void Person_PhoneNumber::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.Person.PhoneNumber) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + cached_has_bits = from._impl_._has_bits_[0]; + if (cached_has_bits & 0x00000003u) { + if (cached_has_bits & 0x00000001u) { + _this->_internal_set_number(from._internal_number()); + } + if (cached_has_bits & 0x00000002u) { + _this->_impl_.type_ = from._impl_.type_; + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); +} + +void Person_PhoneNumber::CopyFrom(const Person_PhoneNumber& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.Person.PhoneNumber) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void Person_PhoneNumber::InternalSwap(Person_PhoneNumber* PROTOBUF_RESTRICT other) { + using std::swap; + auto* arena = GetArena(); + ABSL_DCHECK_EQ(arena, other->GetArena()); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.number_, &other->_impl_.number_, arena); + swap(_impl_.type_, other->_impl_.type_); +} + +::google::protobuf::Metadata Person_PhoneNumber::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// =================================================================== + +class Person::_Internal { + public: + using HasBits = + decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(Person, _impl_._has_bits_); +}; + +Person::Person(::google::protobuf::Arena* arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:tutorial.Person) +} +inline PROTOBUF_NDEBUG_INLINE Person::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, ::google::protobuf::Arena* arena, + const Impl_& from, const ::tutorial::Person& from_msg) + : _has_bits_{from._has_bits_}, + _cached_size_{0}, + phones_{visibility, arena, from.phones_}, + name_(arena, from.name_), + email_(arena, from.email_) {} + +Person::Person( + ::google::protobuf::Arena* arena, + const Person& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + Person* const _this = this; + (void)_this; + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); + new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from); + _impl_.id_ = from._impl_.id_; + + // @@protoc_insertion_point(copy_constructor:tutorial.Person) +} +inline PROTOBUF_NDEBUG_INLINE Person::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena) + : _cached_size_{0}, + phones_{visibility, arena}, + name_(arena), + email_(arena) {} + +inline void Person::SharedCtor(::_pb::Arena* arena) { + new (&_impl_) Impl_(internal_visibility(), arena); + _impl_.id_ = {}; +} +Person::~Person() { + // @@protoc_insertion_point(destructor:tutorial.Person) + _internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + SharedDtor(); +} +inline void Person::SharedDtor() { + ABSL_DCHECK(GetArena() == nullptr); + _impl_.name_.Destroy(); + _impl_.email_.Destroy(); + _impl_.~Impl_(); +} + +PROTOBUF_CONSTINIT +PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::google::protobuf::MessageLite::ClassDataFull + Person::_class_data_ = { + ::google::protobuf::Message::ClassData{ + &_Person_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &Person::MergeImpl, +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::google::protobuf::Message::GetDeleteImpl(), + ::google::protobuf::Message::GetNewImpl(), + ::google::protobuf::Message::GetClearImpl(), &Person::ByteSizeLong, + &Person::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(Person, _impl_._cached_size_), + false, + }, + &Person::kDescriptorMethods, + &descriptor_table_addressbook_2eproto, + nullptr, // tracker +}; +const ::google::protobuf::MessageLite::ClassData* Person::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(_class_data_.tc_table); + return _class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<2, 4, 1, 33, 2> Person::_table_ = { + { + PROTOBUF_FIELD_OFFSET(Person, _impl_._has_bits_), + 0, // no _extensions_ + 4, 24, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967280, // skipmap + offsetof(decltype(_table_), field_entries), + 4, // num_field_entries + 1, // num_aux_entries + offsetof(decltype(_table_), aux_entries), + _class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::tutorial::Person>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // repeated .tutorial.Person.PhoneNumber phones = 4; + {::_pbi::TcParser::FastMtR1, + {34, 63, 0, PROTOBUF_FIELD_OFFSET(Person, _impl_.phones_)}}, + // optional string name = 1; + {::_pbi::TcParser::FastSS1, + {10, 0, 0, PROTOBUF_FIELD_OFFSET(Person, _impl_.name_)}}, + // optional int32 id = 2; + {::_pbi::TcParser::SingularVarintNoZag1<::uint32_t, offsetof(Person, _impl_.id_), 2>(), + {16, 2, 0, PROTOBUF_FIELD_OFFSET(Person, _impl_.id_)}}, + // optional string email = 3; + {::_pbi::TcParser::FastSS1, + {26, 1, 0, PROTOBUF_FIELD_OFFSET(Person, _impl_.email_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // optional string name = 1; + {PROTOBUF_FIELD_OFFSET(Person, _impl_.name_), _Internal::kHasBitsOffset + 0, 0, + (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, + // optional int32 id = 2; + {PROTOBUF_FIELD_OFFSET(Person, _impl_.id_), _Internal::kHasBitsOffset + 2, 0, + (0 | ::_fl::kFcOptional | ::_fl::kInt32)}, + // optional string email = 3; + {PROTOBUF_FIELD_OFFSET(Person, _impl_.email_), _Internal::kHasBitsOffset + 1, 0, + (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, + // repeated .tutorial.Person.PhoneNumber phones = 4; + {PROTOBUF_FIELD_OFFSET(Person, _impl_.phones_), -1, 0, + (0 | ::_fl::kFcRepeated | ::_fl::kMessage | ::_fl::kTvTable)}, + }}, {{ + {::_pbi::TcParser::GetTable<::tutorial::Person_PhoneNumber>()}, + }}, {{ + "\17\4\0\5\0\0\0\0" + "tutorial.Person" + "name" + "email" + }}, +}; + +PROTOBUF_NOINLINE void Person::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.Person) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.phones_.Clear(); + cached_has_bits = _impl_._has_bits_[0]; + if (cached_has_bits & 0x00000003u) { + if (cached_has_bits & 0x00000001u) { + _impl_.name_.ClearNonDefaultToEmpty(); + } + if (cached_has_bits & 0x00000002u) { + _impl_.email_.ClearNonDefaultToEmpty(); + } + } + _impl_.id_ = 0; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::uint8_t* Person::_InternalSerialize( + const MessageLite& base, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) { + const Person& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::uint8_t* Person::_InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + const Person& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(serialize_to_array_start:tutorial.Person) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + const std::string& _s = this_._internal_name(); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(_s.data(), static_cast(_s.length()), ::google::protobuf::internal::WireFormat::SERIALIZE, + "tutorial.Person.name"); + target = stream->WriteStringMaybeAliased(1, _s, target); + } + + // optional int32 id = 2; + if (cached_has_bits & 0x00000004u) { + target = ::google::protobuf::internal::WireFormatLite:: + WriteInt32ToArrayWithField<2>( + stream, this_._internal_id(), target); + } + + // optional string email = 3; + if (cached_has_bits & 0x00000002u) { + const std::string& _s = this_._internal_email(); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(_s.data(), static_cast(_s.length()), ::google::protobuf::internal::WireFormat::SERIALIZE, + "tutorial.Person.email"); + target = stream->WriteStringMaybeAliased(3, _s, target); + } + + // repeated .tutorial.Person.PhoneNumber phones = 4; + for (unsigned i = 0, n = static_cast( + this_._internal_phones_size()); + i < n; i++) { + const auto& repfield = this_._internal_phones().Get(i); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 4, repfield, repfield.GetCachedSize(), + target, stream); + } + + if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.Person) + return target; + } + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::size_t Person::ByteSizeLong(const MessageLite& base) { + const Person& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::size_t Person::ByteSizeLong() const { + const Person& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:tutorial.Person) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + ::_pbi::Prefetch5LinesFrom7Lines(&this_); + { + // repeated .tutorial.Person.PhoneNumber phones = 4; + { + total_size += 1UL * this_._internal_phones_size(); + for (const auto& msg : this_._internal_phones()) { + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + } + } + } + cached_has_bits = this_._impl_._has_bits_[0]; + if (cached_has_bits & 0x00000007u) { + // optional string name = 1; + if (cached_has_bits & 0x00000001u) { + total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( + this_._internal_name()); + } + // optional string email = 3; + if (cached_has_bits & 0x00000002u) { + total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( + this_._internal_email()); + } + // optional int32 id = 2; + if (cached_has_bits & 0x00000004u) { + total_size += ::_pbi::WireFormatLite::Int32SizePlusOne( + this_._internal_id()); + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); + } + +void Person::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.Person) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_internal_mutable_phones()->MergeFrom( + from._internal_phones()); + cached_has_bits = from._impl_._has_bits_[0]; + if (cached_has_bits & 0x00000007u) { + if (cached_has_bits & 0x00000001u) { + _this->_internal_set_name(from._internal_name()); + } + if (cached_has_bits & 0x00000002u) { + _this->_internal_set_email(from._internal_email()); + } + if (cached_has_bits & 0x00000004u) { + _this->_impl_.id_ = from._impl_.id_; + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); +} + +void Person::CopyFrom(const Person& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.Person) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void Person::InternalSwap(Person* PROTOBUF_RESTRICT other) { + using std::swap; + auto* arena = GetArena(); + ABSL_DCHECK_EQ(arena, other->GetArena()); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + _impl_.phones_.InternalSwap(&other->_impl_.phones_); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.name_, &other->_impl_.name_, arena); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.email_, &other->_impl_.email_, arena); + swap(_impl_.id_, other->_impl_.id_); +} + +::google::protobuf::Metadata Person::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// =================================================================== + +class AddressBook::_Internal { + public: +}; + +AddressBook::AddressBook(::google::protobuf::Arena* arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:tutorial.AddressBook) +} +inline PROTOBUF_NDEBUG_INLINE AddressBook::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, ::google::protobuf::Arena* arena, + const Impl_& from, const ::tutorial::AddressBook& from_msg) + : people_{visibility, arena, from.people_}, + _cached_size_{0} {} + +AddressBook::AddressBook( + ::google::protobuf::Arena* arena, + const AddressBook& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, _class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + AddressBook* const _this = this; + (void)_this; + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); + new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from); + + // @@protoc_insertion_point(copy_constructor:tutorial.AddressBook) +} +inline PROTOBUF_NDEBUG_INLINE AddressBook::Impl_::Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena) + : people_{visibility, arena}, + _cached_size_{0} {} + +inline void AddressBook::SharedCtor(::_pb::Arena* arena) { + new (&_impl_) Impl_(internal_visibility(), arena); +} +AddressBook::~AddressBook() { + // @@protoc_insertion_point(destructor:tutorial.AddressBook) + _internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + SharedDtor(); +} +inline void AddressBook::SharedDtor() { + ABSL_DCHECK(GetArena() == nullptr); + _impl_.~Impl_(); +} + +PROTOBUF_CONSTINIT +PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::google::protobuf::MessageLite::ClassDataFull + AddressBook::_class_data_ = { + ::google::protobuf::Message::ClassData{ + &_AddressBook_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &AddressBook::MergeImpl, +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::google::protobuf::Message::GetDeleteImpl(), + ::google::protobuf::Message::GetNewImpl(), + ::google::protobuf::Message::GetClearImpl(), &AddressBook::ByteSizeLong, + &AddressBook::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(AddressBook, _impl_._cached_size_), + false, + }, + &AddressBook::kDescriptorMethods, + &descriptor_table_addressbook_2eproto, + nullptr, // tracker +}; +const ::google::protobuf::MessageLite::ClassData* AddressBook::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(_class_data_.tc_table); + return _class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 1, 1, 0, 2> AddressBook::_table_ = { + { + 0, // no _has_bits_ + 0, // no _extensions_ + 1, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967294, // skipmap + offsetof(decltype(_table_), field_entries), + 1, // num_field_entries + 1, // num_aux_entries + offsetof(decltype(_table_), aux_entries), + _class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::tutorial::AddressBook>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // repeated .tutorial.Person people = 1; + {::_pbi::TcParser::FastMtR1, + {10, 63, 0, PROTOBUF_FIELD_OFFSET(AddressBook, _impl_.people_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // repeated .tutorial.Person people = 1; + {PROTOBUF_FIELD_OFFSET(AddressBook, _impl_.people_), 0, 0, + (0 | ::_fl::kFcRepeated | ::_fl::kMessage | ::_fl::kTvTable)}, + }}, {{ + {::_pbi::TcParser::GetTable<::tutorial::Person>()}, + }}, {{ + }}, +}; + +PROTOBUF_NOINLINE void AddressBook::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.AddressBook) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.people_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::uint8_t* AddressBook::_InternalSerialize( + const MessageLite& base, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) { + const AddressBook& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::uint8_t* AddressBook::_InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + const AddressBook& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(serialize_to_array_start:tutorial.AddressBook) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + // repeated .tutorial.Person people = 1; + for (unsigned i = 0, n = static_cast( + this_._internal_people_size()); + i < n; i++) { + const auto& repfield = this_._internal_people().Get(i); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); + } + + if (PROTOBUF_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.AddressBook) + return target; + } + +#if defined(PROTOBUF_CUSTOM_VTABLE) + ::size_t AddressBook::ByteSizeLong(const MessageLite& base) { + const AddressBook& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE + ::size_t AddressBook::ByteSizeLong() const { + const AddressBook& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:tutorial.AddressBook) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + ::_pbi::Prefetch5LinesFrom7Lines(&this_); + { + // repeated .tutorial.Person people = 1; + { + total_size += 1UL * this_._internal_people_size(); + for (const auto& msg : this_._internal_people()) { + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + } + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); + } + +void AddressBook::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.AddressBook) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_internal_mutable_people()->MergeFrom( + from._internal_people()); + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_); +} + +void AddressBook::CopyFrom(const AddressBook& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.AddressBook) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void AddressBook::InternalSwap(AddressBook* PROTOBUF_RESTRICT other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + _impl_.people_.InternalSwap(&other->_impl_.people_); +} + +::google::protobuf::Metadata AddressBook::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// @@protoc_insertion_point(namespace_scope) +} // namespace tutorial +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google +// @@protoc_insertion_point(global_scope) +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type + _static_init2_ PROTOBUF_UNUSED = + (::_pbi::AddDescriptors(&descriptor_table_addressbook_2eproto), + ::std::false_type{}); +#include "google/protobuf/port_undef.inc" diff --git a/test/protobuftest/addressbook.pb.h b/test/protobuftest/addressbook.pb.h new file mode 100644 index 0000000..41ec1f9 --- /dev/null +++ b/test/protobuftest/addressbook.pb.h @@ -0,0 +1,1196 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: addressbook.proto +// Protobuf C++ Version: 5.28.0 + +#ifndef GOOGLE_PROTOBUF_INCLUDED_addressbook_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_addressbook_2eproto_2epb_2eh + +#include +#include +#include +#include + +#include "google/protobuf/runtime_version.h" +#if PROTOBUF_VERSION != 5028000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_tctable_decl.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" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" + +#define PROTOBUF_INTERNAL_EXPORT_addressbook_2eproto + +namespace google { +namespace protobuf { +namespace internal { +class AnyMetadata; +} // namespace internal +} // namespace protobuf +} // namespace google + +// Internal implementation detail -- do not use these members. +struct TableStruct_addressbook_2eproto { + static const ::uint32_t offsets[]; +}; +extern const ::google::protobuf::internal::DescriptorTable + descriptor_table_addressbook_2eproto; +namespace tutorial { +class AddressBook; +struct AddressBookDefaultTypeInternal; +extern AddressBookDefaultTypeInternal _AddressBook_default_instance_; +class Person; +struct PersonDefaultTypeInternal; +extern PersonDefaultTypeInternal _Person_default_instance_; +class Person_PhoneNumber; +struct Person_PhoneNumberDefaultTypeInternal; +extern Person_PhoneNumberDefaultTypeInternal _Person_PhoneNumber_default_instance_; +} // namespace tutorial +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google + +namespace tutorial { +enum Person_PhoneType : int { + Person_PhoneType_PHONE_TYPE_UNSPECIFIED = 0, + Person_PhoneType_PHONE_TYPE_MOBILE = 1, + Person_PhoneType_PHONE_TYPE_HOME = 2, + Person_PhoneType_PHONE_TYPE_WORK = 3, +}; + +bool Person_PhoneType_IsValid(int value); +extern const uint32_t Person_PhoneType_internal_data_[]; +constexpr Person_PhoneType Person_PhoneType_PhoneType_MIN = static_cast(0); +constexpr Person_PhoneType Person_PhoneType_PhoneType_MAX = static_cast(3); +constexpr int Person_PhoneType_PhoneType_ARRAYSIZE = 3 + 1; +const ::google::protobuf::EnumDescriptor* +Person_PhoneType_descriptor(); +template +const std::string& Person_PhoneType_Name(T value) { + static_assert(std::is_same::value || + std::is_integral::value, + "Incorrect type passed to PhoneType_Name()."); + return Person_PhoneType_Name(static_cast(value)); +} +template <> +inline const std::string& Person_PhoneType_Name(Person_PhoneType value) { + return ::google::protobuf::internal::NameOfDenseEnum( + static_cast(value)); +} +inline bool Person_PhoneType_Parse(absl::string_view name, Person_PhoneType* value) { + return ::google::protobuf::internal::ParseNamedEnum( + Person_PhoneType_descriptor(), name, value); +} + +// =================================================================== + + +// ------------------------------------------------------------------- + +class Person_PhoneNumber final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:tutorial.Person.PhoneNumber) */ { + public: + inline Person_PhoneNumber() : Person_PhoneNumber(nullptr) {} + ~Person_PhoneNumber() PROTOBUF_FINAL; + template + explicit PROTOBUF_CONSTEXPR Person_PhoneNumber( + ::google::protobuf::internal::ConstantInitialized); + + inline Person_PhoneNumber(const Person_PhoneNumber& from) : Person_PhoneNumber(nullptr, from) {} + inline Person_PhoneNumber(Person_PhoneNumber&& from) noexcept + : Person_PhoneNumber(nullptr, std::move(from)) {} + inline Person_PhoneNumber& operator=(const Person_PhoneNumber& from) { + CopyFrom(from); + return *this; + } + inline Person_PhoneNumber& operator=(Person_PhoneNumber&& from) noexcept { + if (this == &from) return *this; + if (GetArena() == from.GetArena() +#ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetArena() != nullptr +#endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const Person_PhoneNumber& default_instance() { + return *internal_default_instance(); + } + static inline const Person_PhoneNumber* internal_default_instance() { + return reinterpret_cast( + &_Person_PhoneNumber_default_instance_); + } + static constexpr int kIndexInFileMessages = 0; + friend void swap(Person_PhoneNumber& a, Person_PhoneNumber& b) { a.Swap(&b); } + inline void Swap(Person_PhoneNumber* other) { + if (other == this) return; +#ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() != nullptr && GetArena() == other->GetArena()) { +#else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() == other->GetArena()) { +#endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Person_PhoneNumber* other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + Person_PhoneNumber* New(::google::protobuf::Arena* arena = nullptr) const PROTOBUF_FINAL { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const Person_PhoneNumber& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const Person_PhoneNumber& from) { Person_PhoneNumber::MergeImpl(*this, from); } + + private: + static void MergeImpl( + ::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* _InternalSerialize( + const MessageLite& msg, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* arena); + void SharedDtor(); + void InternalSwap(Person_PhoneNumber* other); + private: + friend class ::google::protobuf::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { return "tutorial.Person.PhoneNumber"; } + + protected: + explicit Person_PhoneNumber(::google::protobuf::Arena* arena); + Person_PhoneNumber(::google::protobuf::Arena* arena, const Person_PhoneNumber& from); + Person_PhoneNumber(::google::protobuf::Arena* arena, Person_PhoneNumber&& from) noexcept + : Person_PhoneNumber(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::Message::ClassData* GetClassData() const PROTOBUF_FINAL; + static const ::google::protobuf::Message::ClassDataFull _class_data_; + + public: + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kNumberFieldNumber = 1, + kTypeFieldNumber = 2, + }; + // optional string number = 1; + bool has_number() const; + void clear_number() ; + const std::string& number() const; + template + void set_number(Arg_&& arg, Args_... args); + std::string* mutable_number(); + PROTOBUF_NODISCARD std::string* release_number(); + void set_allocated_number(std::string* value); + + private: + const std::string& _internal_number() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_number( + const std::string& value); + std::string* _internal_mutable_number(); + + public: + // optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; + bool has_type() const; + void clear_type() ; + ::tutorial::Person_PhoneType type() const; + void set_type(::tutorial::Person_PhoneType value); + + private: + ::tutorial::Person_PhoneType _internal_type() const; + void _internal_set_type(::tutorial::Person_PhoneType value); + + public: + // @@protoc_insertion_point(class_scope:tutorial.Person.PhoneNumber) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable< + 1, 2, 1, + 42, 2> + _table_; + + static constexpr const void* _raw_default_instance_ = + &_Person_PhoneNumber_default_instance_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_( + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena); + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena, const Impl_& from, + const Person_PhoneNumber& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable ::google::protobuf::internal::CachedSize _cached_size_; + ::google::protobuf::internal::ArenaStringPtr number_; + int type_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_addressbook_2eproto; +}; +// ------------------------------------------------------------------- + +class Person final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:tutorial.Person) */ { + public: + inline Person() : Person(nullptr) {} + ~Person() PROTOBUF_FINAL; + template + explicit PROTOBUF_CONSTEXPR Person( + ::google::protobuf::internal::ConstantInitialized); + + inline Person(const Person& from) : Person(nullptr, from) {} + inline Person(Person&& from) noexcept + : Person(nullptr, std::move(from)) {} + inline Person& operator=(const Person& from) { + CopyFrom(from); + return *this; + } + inline Person& operator=(Person&& from) noexcept { + if (this == &from) return *this; + if (GetArena() == from.GetArena() +#ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetArena() != nullptr +#endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const Person& default_instance() { + return *internal_default_instance(); + } + static inline const Person* internal_default_instance() { + return reinterpret_cast( + &_Person_default_instance_); + } + static constexpr int kIndexInFileMessages = 1; + friend void swap(Person& a, Person& b) { a.Swap(&b); } + inline void Swap(Person* other) { + if (other == this) return; +#ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() != nullptr && GetArena() == other->GetArena()) { +#else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() == other->GetArena()) { +#endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Person* other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + Person* New(::google::protobuf::Arena* arena = nullptr) const PROTOBUF_FINAL { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const Person& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const Person& from) { Person::MergeImpl(*this, from); } + + private: + static void MergeImpl( + ::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* _InternalSerialize( + const MessageLite& msg, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* arena); + void SharedDtor(); + void InternalSwap(Person* other); + private: + friend class ::google::protobuf::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { return "tutorial.Person"; } + + protected: + explicit Person(::google::protobuf::Arena* arena); + Person(::google::protobuf::Arena* arena, const Person& from); + Person(::google::protobuf::Arena* arena, Person&& from) noexcept + : Person(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::Message::ClassData* GetClassData() const PROTOBUF_FINAL; + static const ::google::protobuf::Message::ClassDataFull _class_data_; + + public: + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + using PhoneNumber = Person_PhoneNumber; + using PhoneType = Person_PhoneType; + static constexpr PhoneType PHONE_TYPE_UNSPECIFIED = Person_PhoneType_PHONE_TYPE_UNSPECIFIED; + static constexpr PhoneType PHONE_TYPE_MOBILE = Person_PhoneType_PHONE_TYPE_MOBILE; + static constexpr PhoneType PHONE_TYPE_HOME = Person_PhoneType_PHONE_TYPE_HOME; + static constexpr PhoneType PHONE_TYPE_WORK = Person_PhoneType_PHONE_TYPE_WORK; + static inline bool PhoneType_IsValid(int value) { + return Person_PhoneType_IsValid(value); + } + static constexpr PhoneType PhoneType_MIN = Person_PhoneType_PhoneType_MIN; + static constexpr PhoneType PhoneType_MAX = Person_PhoneType_PhoneType_MAX; + static constexpr int PhoneType_ARRAYSIZE = Person_PhoneType_PhoneType_ARRAYSIZE; + static inline const ::google::protobuf::EnumDescriptor* PhoneType_descriptor() { + return Person_PhoneType_descriptor(); + } + template + static inline const std::string& PhoneType_Name(T value) { + return Person_PhoneType_Name(value); + } + static inline bool PhoneType_Parse(absl::string_view name, PhoneType* value) { + return Person_PhoneType_Parse(name, value); + } + + // accessors ------------------------------------------------------- + enum : int { + kPhonesFieldNumber = 4, + kNameFieldNumber = 1, + kEmailFieldNumber = 3, + kIdFieldNumber = 2, + }; + // repeated .tutorial.Person.PhoneNumber phones = 4; + int phones_size() const; + private: + int _internal_phones_size() const; + + public: + void clear_phones() ; + ::tutorial::Person_PhoneNumber* mutable_phones(int index); + ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>* mutable_phones(); + + private: + const ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>& _internal_phones() const; + ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>* _internal_mutable_phones(); + public: + const ::tutorial::Person_PhoneNumber& phones(int index) const; + ::tutorial::Person_PhoneNumber* add_phones(); + const ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>& phones() const; + // optional string name = 1; + bool has_name() const; + void clear_name() ; + const std::string& name() const; + template + void set_name(Arg_&& arg, Args_... args); + std::string* mutable_name(); + PROTOBUF_NODISCARD std::string* release_name(); + void set_allocated_name(std::string* value); + + private: + const std::string& _internal_name() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_name( + const std::string& value); + std::string* _internal_mutable_name(); + + public: + // optional string email = 3; + bool has_email() const; + void clear_email() ; + const std::string& email() const; + template + void set_email(Arg_&& arg, Args_... args); + std::string* mutable_email(); + PROTOBUF_NODISCARD std::string* release_email(); + void set_allocated_email(std::string* value); + + private: + const std::string& _internal_email() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_email( + const std::string& value); + std::string* _internal_mutable_email(); + + public: + // optional int32 id = 2; + bool has_id() const; + void clear_id() ; + ::int32_t id() const; + void set_id(::int32_t value); + + private: + ::int32_t _internal_id() const; + void _internal_set_id(::int32_t value); + + public: + // @@protoc_insertion_point(class_scope:tutorial.Person) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable< + 2, 4, 1, + 33, 2> + _table_; + + static constexpr const void* _raw_default_instance_ = + &_Person_default_instance_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_( + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena); + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena, const Impl_& from, + const Person& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable ::google::protobuf::internal::CachedSize _cached_size_; + ::google::protobuf::RepeatedPtrField< ::tutorial::Person_PhoneNumber > phones_; + ::google::protobuf::internal::ArenaStringPtr name_; + ::google::protobuf::internal::ArenaStringPtr email_; + ::int32_t id_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_addressbook_2eproto; +}; +// ------------------------------------------------------------------- + +class AddressBook final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:tutorial.AddressBook) */ { + public: + inline AddressBook() : AddressBook(nullptr) {} + ~AddressBook() PROTOBUF_FINAL; + template + explicit PROTOBUF_CONSTEXPR AddressBook( + ::google::protobuf::internal::ConstantInitialized); + + inline AddressBook(const AddressBook& from) : AddressBook(nullptr, from) {} + inline AddressBook(AddressBook&& from) noexcept + : AddressBook(nullptr, std::move(from)) {} + inline AddressBook& operator=(const AddressBook& from) { + CopyFrom(from); + return *this; + } + inline AddressBook& operator=(AddressBook&& from) noexcept { + if (this == &from) return *this; + if (GetArena() == from.GetArena() +#ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetArena() != nullptr +#endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const AddressBook& default_instance() { + return *internal_default_instance(); + } + static inline const AddressBook* internal_default_instance() { + return reinterpret_cast( + &_AddressBook_default_instance_); + } + static constexpr int kIndexInFileMessages = 2; + friend void swap(AddressBook& a, AddressBook& b) { a.Swap(&b); } + inline void Swap(AddressBook* other) { + if (other == this) return; +#ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() != nullptr && GetArena() == other->GetArena()) { +#else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetArena() == other->GetArena()) { +#endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(AddressBook* other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + AddressBook* New(::google::protobuf::Arena* arena = nullptr) const PROTOBUF_FINAL { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const AddressBook& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const AddressBook& from) { AddressBook::MergeImpl(*this, from); } + + private: + static void MergeImpl( + ::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* _InternalSerialize( + const MessageLite& msg, ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, + ::google::protobuf::io::EpsCopyOutputStream* stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* arena); + void SharedDtor(); + void InternalSwap(AddressBook* other); + private: + friend class ::google::protobuf::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { return "tutorial.AddressBook"; } + + protected: + explicit AddressBook(::google::protobuf::Arena* arena); + AddressBook(::google::protobuf::Arena* arena, const AddressBook& from); + AddressBook(::google::protobuf::Arena* arena, AddressBook&& from) noexcept + : AddressBook(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::Message::ClassData* GetClassData() const PROTOBUF_FINAL; + static const ::google::protobuf::Message::ClassDataFull _class_data_; + + public: + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kPeopleFieldNumber = 1, + }; + // repeated .tutorial.Person people = 1; + int people_size() const; + private: + int _internal_people_size() const; + + public: + void clear_people() ; + ::tutorial::Person* mutable_people(int index); + ::google::protobuf::RepeatedPtrField<::tutorial::Person>* mutable_people(); + + private: + const ::google::protobuf::RepeatedPtrField<::tutorial::Person>& _internal_people() const; + ::google::protobuf::RepeatedPtrField<::tutorial::Person>* _internal_mutable_people(); + public: + const ::tutorial::Person& people(int index) const; + ::tutorial::Person* add_people(); + const ::google::protobuf::RepeatedPtrField<::tutorial::Person>& people() const; + // @@protoc_insertion_point(class_scope:tutorial.AddressBook) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable< + 0, 1, 1, + 0, 2> + _table_; + + static constexpr const void* _raw_default_instance_ = + &_AddressBook_default_instance_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_( + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena); + inline explicit Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* arena, const Impl_& from, + const AddressBook& from_msg); + ::google::protobuf::RepeatedPtrField< ::tutorial::Person > people_; + mutable ::google::protobuf::internal::CachedSize _cached_size_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_addressbook_2eproto; +}; + +// =================================================================== + + + + +// =================================================================== + + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// Person_PhoneNumber + +// optional string number = 1; +inline bool Person_PhoneNumber::has_number() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline void Person_PhoneNumber::clear_number() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.number_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline const std::string& Person_PhoneNumber::number() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:tutorial.Person.PhoneNumber.number) + return _internal_number(); +} +template +inline PROTOBUF_ALWAYS_INLINE void Person_PhoneNumber::set_number(Arg_&& arg, + Args_... args) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.number_.Set(static_cast(arg), args..., GetArena()); + // @@protoc_insertion_point(field_set:tutorial.Person.PhoneNumber.number) +} +inline std::string* Person_PhoneNumber::mutable_number() ABSL_ATTRIBUTE_LIFETIME_BOUND { + std::string* _s = _internal_mutable_number(); + // @@protoc_insertion_point(field_mutable:tutorial.Person.PhoneNumber.number) + return _s; +} +inline const std::string& Person_PhoneNumber::_internal_number() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.number_.Get(); +} +inline void Person_PhoneNumber::_internal_set_number(const std::string& value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.number_.Set(value, GetArena()); +} +inline std::string* Person_PhoneNumber::_internal_mutable_number() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + return _impl_.number_.Mutable( GetArena()); +} +inline std::string* Person_PhoneNumber::release_number() { + ::google::protobuf::internal::TSanWrite(&_impl_); + // @@protoc_insertion_point(field_release:tutorial.Person.PhoneNumber.number) + if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000001u; + auto* released = _impl_.number_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.number_.Set("", GetArena()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void Person_PhoneNumber::set_allocated_number(std::string* value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000001u; + } else { + _impl_._has_bits_[0] &= ~0x00000001u; + } + _impl_.number_.SetAllocated(value, GetArena()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.number_.IsDefault()) { + _impl_.number_.Set("", GetArena()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:tutorial.Person.PhoneNumber.number) +} + +// optional .tutorial.Person.PhoneType type = 2 [default = PHONE_TYPE_HOME]; +inline bool Person_PhoneNumber::has_type() const { + bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; + return value; +} +inline void Person_PhoneNumber::clear_type() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.type_ = 2; + _impl_._has_bits_[0] &= ~0x00000002u; +} +inline ::tutorial::Person_PhoneType Person_PhoneNumber::type() const { + // @@protoc_insertion_point(field_get:tutorial.Person.PhoneNumber.type) + return _internal_type(); +} +inline void Person_PhoneNumber::set_type(::tutorial::Person_PhoneType value) { + _internal_set_type(value); + _impl_._has_bits_[0] |= 0x00000002u; + // @@protoc_insertion_point(field_set:tutorial.Person.PhoneNumber.type) +} +inline ::tutorial::Person_PhoneType Person_PhoneNumber::_internal_type() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return static_cast<::tutorial::Person_PhoneType>(_impl_.type_); +} +inline void Person_PhoneNumber::_internal_set_type(::tutorial::Person_PhoneType value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + assert(::tutorial::Person_PhoneType_IsValid(value)); + _impl_.type_ = value; +} + +// ------------------------------------------------------------------- + +// Person + +// optional string name = 1; +inline bool Person::has_name() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline void Person::clear_name() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.name_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline const std::string& Person::name() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:tutorial.Person.name) + return _internal_name(); +} +template +inline PROTOBUF_ALWAYS_INLINE void Person::set_name(Arg_&& arg, + Args_... args) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.name_.Set(static_cast(arg), args..., GetArena()); + // @@protoc_insertion_point(field_set:tutorial.Person.name) +} +inline std::string* Person::mutable_name() ABSL_ATTRIBUTE_LIFETIME_BOUND { + std::string* _s = _internal_mutable_name(); + // @@protoc_insertion_point(field_mutable:tutorial.Person.name) + return _s; +} +inline const std::string& Person::_internal_name() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.name_.Get(); +} +inline void Person::_internal_set_name(const std::string& value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.name_.Set(value, GetArena()); +} +inline std::string* Person::_internal_mutable_name() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000001u; + return _impl_.name_.Mutable( GetArena()); +} +inline std::string* Person::release_name() { + ::google::protobuf::internal::TSanWrite(&_impl_); + // @@protoc_insertion_point(field_release:tutorial.Person.name) + if ((_impl_._has_bits_[0] & 0x00000001u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000001u; + auto* released = _impl_.name_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.name_.Set("", GetArena()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void Person::set_allocated_name(std::string* value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000001u; + } else { + _impl_._has_bits_[0] &= ~0x00000001u; + } + _impl_.name_.SetAllocated(value, GetArena()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArena()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:tutorial.Person.name) +} + +// optional int32 id = 2; +inline bool Person::has_id() const { + bool value = (_impl_._has_bits_[0] & 0x00000004u) != 0; + return value; +} +inline void Person::clear_id() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.id_ = 0; + _impl_._has_bits_[0] &= ~0x00000004u; +} +inline ::int32_t Person::id() const { + // @@protoc_insertion_point(field_get:tutorial.Person.id) + return _internal_id(); +} +inline void Person::set_id(::int32_t value) { + _internal_set_id(value); + _impl_._has_bits_[0] |= 0x00000004u; + // @@protoc_insertion_point(field_set:tutorial.Person.id) +} +inline ::int32_t Person::_internal_id() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.id_; +} +inline void Person::_internal_set_id(::int32_t value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.id_ = value; +} + +// optional string email = 3; +inline bool Person::has_email() const { + bool value = (_impl_._has_bits_[0] & 0x00000002u) != 0; + return value; +} +inline void Person::clear_email() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.email_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000002u; +} +inline const std::string& Person::email() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:tutorial.Person.email) + return _internal_email(); +} +template +inline PROTOBUF_ALWAYS_INLINE void Person::set_email(Arg_&& arg, + Args_... args) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000002u; + _impl_.email_.Set(static_cast(arg), args..., GetArena()); + // @@protoc_insertion_point(field_set:tutorial.Person.email) +} +inline std::string* Person::mutable_email() ABSL_ATTRIBUTE_LIFETIME_BOUND { + std::string* _s = _internal_mutable_email(); + // @@protoc_insertion_point(field_mutable:tutorial.Person.email) + return _s; +} +inline const std::string& Person::_internal_email() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.email_.Get(); +} +inline void Person::_internal_set_email(const std::string& value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000002u; + _impl_.email_.Set(value, GetArena()); +} +inline std::string* Person::_internal_mutable_email() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_._has_bits_[0] |= 0x00000002u; + return _impl_.email_.Mutable( GetArena()); +} +inline std::string* Person::release_email() { + ::google::protobuf::internal::TSanWrite(&_impl_); + // @@protoc_insertion_point(field_release:tutorial.Person.email) + if ((_impl_._has_bits_[0] & 0x00000002u) == 0) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000002u; + auto* released = _impl_.email_.Release(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.email_.Set("", GetArena()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return released; +} +inline void Person::set_allocated_email(std::string* value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value != nullptr) { + _impl_._has_bits_[0] |= 0x00000002u; + } else { + _impl_._has_bits_[0] &= ~0x00000002u; + } + _impl_.email_.SetAllocated(value, GetArena()); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.email_.IsDefault()) { + _impl_.email_.Set("", GetArena()); + } + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:tutorial.Person.email) +} + +// repeated .tutorial.Person.PhoneNumber phones = 4; +inline int Person::_internal_phones_size() const { + return _internal_phones().size(); +} +inline int Person::phones_size() const { + return _internal_phones_size(); +} +inline void Person::clear_phones() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.phones_.Clear(); +} +inline ::tutorial::Person_PhoneNumber* Person::mutable_phones(int index) + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_mutable:tutorial.Person.phones) + return _internal_mutable_phones()->Mutable(index); +} +inline ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>* Person::mutable_phones() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_mutable_list:tutorial.Person.phones) + ::google::protobuf::internal::TSanWrite(&_impl_); + return _internal_mutable_phones(); +} +inline const ::tutorial::Person_PhoneNumber& Person::phones(int index) const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:tutorial.Person.phones) + return _internal_phones().Get(index); +} +inline ::tutorial::Person_PhoneNumber* Person::add_phones() ABSL_ATTRIBUTE_LIFETIME_BOUND { + ::google::protobuf::internal::TSanWrite(&_impl_); + ::tutorial::Person_PhoneNumber* _add = _internal_mutable_phones()->Add(); + // @@protoc_insertion_point(field_add:tutorial.Person.phones) + return _add; +} +inline const ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>& Person::phones() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_list:tutorial.Person.phones) + return _internal_phones(); +} +inline const ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>& +Person::_internal_phones() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.phones_; +} +inline ::google::protobuf::RepeatedPtrField<::tutorial::Person_PhoneNumber>* +Person::_internal_mutable_phones() { + ::google::protobuf::internal::TSanRead(&_impl_); + return &_impl_.phones_; +} + +// ------------------------------------------------------------------- + +// AddressBook + +// repeated .tutorial.Person people = 1; +inline int AddressBook::_internal_people_size() const { + return _internal_people().size(); +} +inline int AddressBook::people_size() const { + return _internal_people_size(); +} +inline void AddressBook::clear_people() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.people_.Clear(); +} +inline ::tutorial::Person* AddressBook::mutable_people(int index) + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_mutable:tutorial.AddressBook.people) + return _internal_mutable_people()->Mutable(index); +} +inline ::google::protobuf::RepeatedPtrField<::tutorial::Person>* AddressBook::mutable_people() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_mutable_list:tutorial.AddressBook.people) + ::google::protobuf::internal::TSanWrite(&_impl_); + return _internal_mutable_people(); +} +inline const ::tutorial::Person& AddressBook::people(int index) const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:tutorial.AddressBook.people) + return _internal_people().Get(index); +} +inline ::tutorial::Person* AddressBook::add_people() ABSL_ATTRIBUTE_LIFETIME_BOUND { + ::google::protobuf::internal::TSanWrite(&_impl_); + ::tutorial::Person* _add = _internal_mutable_people()->Add(); + // @@protoc_insertion_point(field_add:tutorial.AddressBook.people) + return _add; +} +inline const ::google::protobuf::RepeatedPtrField<::tutorial::Person>& AddressBook::people() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_list:tutorial.AddressBook.people) + return _internal_people(); +} +inline const ::google::protobuf::RepeatedPtrField<::tutorial::Person>& +AddressBook::_internal_people() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.people_; +} +inline ::google::protobuf::RepeatedPtrField<::tutorial::Person>* +AddressBook::_internal_mutable_people() { + ::google::protobuf::internal::TSanRead(&_impl_); + return &_impl_.people_; +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) +} // namespace tutorial + + +namespace google { +namespace protobuf { + +template <> +struct is_proto_enum<::tutorial::Person_PhoneType> : std::true_type {}; +template <> +inline const EnumDescriptor* GetEnumDescriptor<::tutorial::Person_PhoneType>() { + return ::tutorial::Person_PhoneType_descriptor(); +} + +} // namespace protobuf +} // namespace google + +// @@protoc_insertion_point(global_scope) + +#include "google/protobuf/port_undef.inc" + +#endif // GOOGLE_PROTOBUF_INCLUDED_addressbook_2eproto_2epb_2eh diff --git a/test/protobuftest/addressbook.proto b/test/protobuftest/addressbook.proto new file mode 100644 index 0000000..3408747 --- /dev/null +++ b/test/protobuftest/addressbook.proto @@ -0,0 +1,27 @@ +syntax = "proto2"; + +package tutorial; + +message Person { + optional string name = 1; + optional int32 id = 2; + optional string email = 3; + + enum PhoneType { + PHONE_TYPE_UNSPECIFIED = 0; + PHONE_TYPE_MOBILE = 1; + PHONE_TYPE_HOME = 2; + PHONE_TYPE_WORK = 3; + } + + message PhoneNumber { + optional string number = 1; + optional PhoneType type = 2 [default = PHONE_TYPE_HOME]; + } + + repeated PhoneNumber phones = 4; +} + +message AddressBook { + repeated Person people = 1; +} \ No newline at end of file diff --git a/test/protobuftest/err.info b/test/protobuftest/err.info new file mode 100644 index 0000000..e69de29 diff --git a/test/protobuftest/main.cc b/test/protobuftest/main.cc new file mode 100644 index 0000000..6a05d0a --- /dev/null +++ b/test/protobuftest/main.cc @@ -0,0 +1,93 @@ +#include +#include +#include +#include "addressbook.pb.h" +using namespace std; + +// This function fills in a Person message based on user input. +void PromptForAddress(tutorial::Person* person) { + cout << "Enter person ID number: "; + int id; + cin >> id; + person->set_id(id); + cin.ignore(256, '\n'); + + cout << "Enter name: "; + getline(cin, *person->mutable_name()); + + cout << "Enter email address (blank for none): "; + string email; + getline(cin, email); + if (!email.empty()) { + person->set_email(email); + } + + while (true) { + cout << "Enter a phone number (or leave blank to finish): "; + string number; + getline(cin, number); + if (number.empty()) { + break; + } + + tutorial::Person::PhoneNumber* phone_number = person->add_phones(); + phone_number->set_number(number); + + cout << "Is this a mobile, home, or work phone? "; + string type; + getline(cin, type); + if (type == "mobile") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_MOBILE); + } else if (type == "home") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_HOME); + } else if (type == "work") { + phone_number->set_type(tutorial::Person::PHONE_TYPE_WORK); + } else { + cout << "Unknown phone type. Using default." << endl; + } + } +} + +// Main function: Reads the entire address book from a file, +// adds one person based on user input, then writes it back out to the same +// file. +int main(int argc, char* argv[]) { + // Verify that the version of the library that we linked against is + // compatible with the version of the headers we compiled against. + GOOGLE_PROTOBUF_VERIFY_VERSION; + + if (argc != 2) { + cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl; + return -1; + } + + tutorial::AddressBook address_book; + + { + // Read the existing address book. + fstream input(argv[1], ios::in | ios::binary); + if (!input) { + cout << argv[1] << ": File not found. Creating a new file." << endl; + } else if (!address_book.ParseFromIstream(&input)) { + cerr << "Failed to parse address book." << endl; + return -1; + } + } + + // Add an address. + PromptForAddress(address_book.add_people()); + + { + // Write the new address book back to disk. + fstream output(argv[1], ios::out | ios::trunc | ios::binary); + if (!address_book.SerializeToOstream(&output)) { + cerr << "Failed to write address book." << endl; + return -1; + } + } + + // Optional: Delete all global objects allocated by libprotobuf. + google::protobuf::ShutdownProtobufLibrary(); + + return 0; +} \ No newline at end of file diff --git a/test/protobuftest/my_program b/test/protobuftest/my_program new file mode 100755 index 0000000..af5a36f Binary files /dev/null and b/test/protobuftest/my_program differ diff --git a/third_party/abseil-cpp b/third_party/abseil-cpp new file mode 160000 index 0000000..d7aaad8 --- /dev/null +++ b/third_party/abseil-cpp @@ -0,0 +1 @@ +Subproject commit d7aaad83b488fd62bd51c81ecf16cd938532cc0a