diff --git a/.gitignore b/.gitignore index 40974dd..66b42bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -*.pb.cc -*.pb.cc +tinypb.pb.cc +tinypb.pb.h bin/ build/ lib/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c81fe..40a0df3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,13 +40,6 @@ add_library(tinyrpc ${ASM_FILES} ) -aux_source_directory(${CMAKE_SOURCE_DIR}/test/returntest TEST_SRC_LIST) - - -add_executable(test_tinyrpc - ${TEST_SRC_LIST} -) - # 引入 abseil-cpp 子目录 add_subdirectory(./third_party/abseil-cpp absl) @@ -86,12 +79,31 @@ set(ABSEL_LIBARARY absl::utility absl::variant ) - # 链接库 target_link_libraries(tinyrpc PRIVATE protobuf) # 链接 Protobuf 库 target_link_libraries(tinyrpc PRIVATE ${ABSEL_LIBARARY}) # 链接 Protobuf 库 + + +aux_source_directory(${CMAKE_SOURCE_DIR}/test/servertest SER_TEST_SRC_LIST) +aux_source_directory(${CMAKE_SOURCE_DIR}/test/clienttest CLI_TEST_SRC_LIST) + + +add_executable(test_tinyrpc_server + ${SER_TEST_SRC_LIST} +) +add_executable(test_tinyrpc_client + ${CLI_TEST_SRC_LIST} +) + + +target_link_libraries(test_tinyrpc_server PRIVATE tinyrpc) +target_link_libraries(test_tinyrpc_client PRIVATE tinyrpc) + + +aux_source_directory(${CMAKE_SOURCE_DIR}/test/codertest TEST_SRC_LIST) + +add_executable(test_tinyrpc + ${TEST_SRC_LIST} +) + target_link_libraries(test_tinyrpc PRIVATE tinyrpc) - - - - diff --git a/includes/coroutine/coroutine.hpp b/includes/coroutine/coroutine.hpp index 474359f..6b7cc4f 100644 --- a/includes/coroutine/coroutine.hpp +++ b/includes/coroutine/coroutine.hpp @@ -8,17 +8,16 @@ namespace tinyrpc { friend void coFunction(Coroutine* co); private: Coroutine(); + void operator()() const { // 调用 这个协程的回调 + m_callback(); + } public: // Coroutine(std::size_t stack_size, char* stack_sp); Coroutine(std::function cb, std::size_t stack_size = 1 * 1024 * 1024/* , char* stack_sp */); - + Coroutine(const Coroutine&) = delete; // int getCorID() const {return m_cor_id;} - void operator()() const { // 调用 这个协程的回调 - m_callback(); - } - bool isMainCoroutine() const {return m_stack_sp == nullptr;} // coctx* getContext() {return &m_ctx;} diff --git a/includes/net/abstract_coder.hpp b/includes/net/abstract_coder.hpp index 15c92bf..d0faaf8 100644 --- a/includes/net/abstract_coder.hpp +++ b/includes/net/abstract_coder.hpp @@ -18,7 +18,7 @@ namespace tinyrpc { AbstractCoder() = default; virtual ~AbstractCoder() = default; - virtual bool encoder(TcpBuffer& buffer, AbstractData& data) = 0; // 编码 + virtual bool encoder(TcpBuffer& buffer, const AbstractData& data) = 0; // 编码 virtual bool decoder(TcpBuffer& buffer, AbstractData& data) = 0; // 解码 diff --git a/includes/net/error_code.hpp b/includes/net/error_code.hpp index 1a3becc..efbec7a 100644 --- a/includes/net/error_code.hpp +++ b/includes/net/error_code.hpp @@ -3,7 +3,8 @@ namespace tinyrpc { enum ErrorCode { - ERROR_PEER_CLOSED, // connect when peer close + + ERROR_PEER_CLOSED = 1, // connect when peer close ERROR_FAILED_CONNECT, // failed to connection peer host ERROR_FAILED_GET_REPLY, // failed to get server reply ERROR_FAILED_DESERIALIZE, // deserialize failed @@ -19,7 +20,7 @@ enum ErrorCode { ERROR_METHOD_NOT_FOUND, // not found method ERROR_PARSE_SERVICE_NAME, // not found service name - ERROR_ASYNC_RPC_CALL_SINGLE_IOTHREAD, // not supoort async rpc call when only have single iothread + ERROR_ASYNC_RPC_CALL_SINGLE_IOTHREAD = 12, // not supoort async rpc call when only have single iothread }; diff --git a/includes/net/tcp/abstract_tcp_connect.hpp b/includes/net/tcp/abstract_tcp_connect.hpp index ebf1e9d..cb24220 100644 --- a/includes/net/tcp/abstract_tcp_connect.hpp +++ b/includes/net/tcp/abstract_tcp_connect.hpp @@ -25,8 +25,9 @@ namespace tinyrpc { State getState() {return m_state;} // bool getResPackageData(const std::string& msg_req, std::shared_ptr& pb_struct); //cli virtual ~AbstractTcpConnection(); + void addMainTaskToReactor(); - protected: + public: void input(); void output(); virtual void process() = 0; diff --git a/includes/net/tcp/client_tcp_connect.hpp b/includes/net/tcp/client_tcp_connect.hpp index d7f44f1..57e2cea 100644 --- a/includes/net/tcp/client_tcp_connect.hpp +++ b/includes/net/tcp/client_tcp_connect.hpp @@ -2,18 +2,19 @@ #include "abstract_coder.hpp" #include "abstract_tcp_connect.hpp" +#include "tcp_buffer.hpp" #include namespace tinyrpc { class TcpClient; - class ClientTcpConnection : AbstractTcpConnection { + class ClientTcpConnection : public AbstractTcpConnection { public: ClientTcpConnection(int fd, Reactor& reactor, TcpClient& cli); ~ClientTcpConnection(); - - private: + TcpBuffer& getSendBuffer() {return m_writeBuffer;} + bool getResPackageData(const std::string& msg_req, std::shared_ptr& pb_struct); void process() override; private: diff --git a/includes/net/tcp/server_tcp_connect.hpp b/includes/net/tcp/server_tcp_connect.hpp index 9b9de44..e306f81 100644 --- a/includes/net/tcp/server_tcp_connect.hpp +++ b/includes/net/tcp/server_tcp_connect.hpp @@ -6,7 +6,7 @@ namespace tinyrpc { class TcpServer; - class ServerTcpConnection : AbstractTcpConnection { + class ServerTcpConnection : public AbstractTcpConnection { public: ServerTcpConnection(int fd, Reactor& reactor, TcpServer& ser); diff --git a/includes/net/tcp/tcp_buffer.hpp b/includes/net/tcp/tcp_buffer.hpp index bab4911..721b762 100644 --- a/includes/net/tcp/tcp_buffer.hpp +++ b/includes/net/tcp/tcp_buffer.hpp @@ -1,4 +1,5 @@ #pragma once +#include "logger.hpp" #include #include #include @@ -14,7 +15,13 @@ namespace tinyrpc { ~TcpBuffer() { } - + void reserved(std::size_t spaceSize) { // 预留空间 + if(getWriteable() <= spaceSize) { + + resize((getReadable() + spaceSize) * 2); + } + + } void dilatation() { resize(m_buffer.size() * 2); } diff --git a/includes/net/tcp/tcp_client.hpp b/includes/net/tcp/tcp_client.hpp index 39941f2..ac016b6 100644 --- a/includes/net/tcp/tcp_client.hpp +++ b/includes/net/tcp/tcp_client.hpp @@ -2,21 +2,31 @@ #include "abstract_coder.hpp" #include "client_tcp_connect.hpp" +#include "coroutine.hpp" #include "net_address.hpp" #include "reactor.hpp" +#include "tinypb_data.hpp" +#include namespace tinyrpc { class TcpClient { public: TcpClient(const NetAddress& peerAddr); AbstractCoder& getCoder() {return *m_coder;} + const NetAddress& getLocalAddr() const {return m_local_addr;} + const NetAddress& getPeerAddr() const {return m_peer_addr;} + bool writeToSendBuffer(const AbstractData& data); + int sendAndRecvData(const std::string& msg_req, std::shared_ptr& res); + void addCoroutine(Coroutine& cor); + bool connectToServer(); + void start(); ~TcpClient(); private: int m_fd{-1}; NetAddress m_local_addr{}; NetAddress m_peer_addr{}; Reactor& m_reactor; - ClientTcpConnection *m_connection; + std::unique_ptr m_connection; AbstractCoder* m_coder{}; }; diff --git a/includes/net/tinypb/tinypb_channel.hpp b/includes/net/tinypb/tinypb_channel.hpp new file mode 100644 index 0000000..cf3503d --- /dev/null +++ b/includes/net/tinypb/tinypb_channel.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "net_address.hpp" +#include "tcp_client.hpp" +#include + +namespace tinyrpc { + +class TinypbChannel : public google::protobuf::RpcChannel { +public: + TinypbChannel(const NetAddress& peerAddr); + ~TinypbChannel() = default; + void CallMethod(const google::protobuf::MethodDescriptor* method, + google::protobuf::RpcController* controller, + const google::protobuf::Message* request, + google::protobuf::Message* response, + google::protobuf::Closure* done) override; + +private: + TcpClient m_client; +}; + +} \ No newline at end of file diff --git a/includes/net/tinypb/tinypb_coder.hpp b/includes/net/tinypb/tinypb_coder.hpp index 6f6a4a7..80faf63 100644 --- a/includes/net/tinypb/tinypb_coder.hpp +++ b/includes/net/tinypb/tinypb_coder.hpp @@ -7,7 +7,7 @@ namespace tinyrpc { public: TinypbCoder(); ~TinypbCoder(); - bool encoder(TcpBuffer& buffer, AbstractData& data) override; // 编码 + bool encoder(TcpBuffer& buffer, const AbstractData& data) override; // 编码 bool decoder(TcpBuffer& buffer, AbstractData& data) override; // 解码 private: diff --git a/includes/net/tinypb/tinypb_data.hpp b/includes/net/tinypb/tinypb_data.hpp index ac86985..10df1b2 100644 --- a/includes/net/tinypb/tinypb_data.hpp +++ b/includes/net/tinypb/tinypb_data.hpp @@ -1,31 +1,73 @@ #pragma once - #include "abstract_coder.hpp" #include #include +#include +#include +#include +#include namespace tinyrpc { +static thread_local std::string t_msg_req_nu; +static thread_local std::string t_max_msg_req_nu; +static int g_random_fd = -1; +struct TinypbData : public AbstractData { + static std::string genMsgNumber() + { + int t_msg_req_len = 8; - struct TinypbData : public AbstractData { - - TinypbData() {}; - ~TinypbData() {}; - - // char start = 0x02; // indentify start of a TinyPb protocal data - int32_t pk_len {0}; // len of all package(include start char and end char) - int32_t msg_req_len {0}; // len of msg_req - std::string msg_req; // msg_req, which identify a request - int32_t service_name_len {0}; // len of service full name - std::string service_full_name; // service full name, like QueryService.query_name - int32_t err_code {0}; // err_code, 0 -- call rpc success, otherwise -- call rpc failed. it only be seted by RpcController - int32_t err_info_len {0}; // len of err_info - std::string err_info; // err_info, empty -- call rpc success, otherwise -- call rpc failed, it will display details of reason why call rpc failed. it only be seted by RpcController - std::string pb_data; // business pb data - int32_t check_num {-1}; // check_num of all package. to check legality of data - // char end = 0x03; // identify end of a TinyPb protocal data - }; + if (t_msg_req_nu.empty() || t_msg_req_nu == t_max_msg_req_nu) { + if (g_random_fd == -1) { + g_random_fd = open("/dev/urandom", O_RDONLY); + } + std::string res(t_msg_req_len, 0); + + if ((read(g_random_fd, &res[0], t_msg_req_len)) != t_msg_req_len) { + return ""; + } + t_max_msg_req_nu = ""; + + for (int i = 0; i < t_msg_req_len; ++i) { + uint8_t x = ((uint8_t)(res[i])) % 10; + res[i] = x + '0'; + t_max_msg_req_nu += "9"; + } + + t_msg_req_nu = res; + } else { + int i = t_msg_req_nu.length() - 1; + while (t_msg_req_nu[i] == '9' && i >= 0) { + i--; + } + if (i >= 0) { + t_msg_req_nu[i] += 1; + for (size_t j = i + 1; j < t_msg_req_nu.length(); ++j) { + t_msg_req_nu[j] = '0'; + } + } + } + return t_msg_req_nu; + } + + + TinypbData() {}; + ~TinypbData() {}; + + // char start = 0x02; // indentify start of a TinyPb protocal data + int32_t pk_len { 0 }; // len of all package(include start char and end char) + int32_t msg_req_len { 0 }; // len of msg_req + std::string msg_req; // msg_req, which identify a request + int32_t service_name_len { 0 }; // len of service full name + std::string service_full_name; // service full name, like QueryService.query_name + int32_t err_code { 0 }; // err_code, 0 -- call rpc success, otherwise -- call rpc failed. it only be seted by RpcController + int32_t err_info_len { 0 }; // len of err_info + std::string err_info; // err_info, empty -- call rpc success, otherwise -- call rpc failed, it will display details of reason why call rpc failed. it only be seted by RpcController + std::string pb_data; // business pb data + int32_t check_num { -1 }; // check_num of all package. to check legality of data + // char end = 0x03; // identify end of a TinyPb protocal data +}; } \ No newline at end of file diff --git a/src/net/tcp/abstract_tcp_connect.cc b/src/net/tcp/abstract_tcp_connect.cc index 8bc07e6..ea994bc 100644 --- a/src/net/tcp/abstract_tcp_connect.cc +++ b/src/net/tcp/abstract_tcp_connect.cc @@ -13,15 +13,17 @@ namespace tinyrpc { m_reactor(reactor) { + + + } + void AbstractTcpConnection::addMainTaskToReactor() { Reactor::Task task = [this] { logger() << "conn coroutine is resume"; m_mainCoroutine.resume(); }; - reactor.addTask(task, true); - + m_reactor.addTask(task, true); } - void AbstractTcpConnection::mainLoopFun() { while(m_state == State::Connected) { diff --git a/src/net/tcp/client_tcp_connect.cc b/src/net/tcp/client_tcp_connect.cc index c0b83c0..1394a82 100644 --- a/src/net/tcp/client_tcp_connect.cc +++ b/src/net/tcp/client_tcp_connect.cc @@ -29,10 +29,18 @@ namespace tinyrpc { logger() << "decode error"; break; } - + std::shared_ptr tmp = std::dynamic_pointer_cast(data); m_respond_datas[tmp->msg_req] = data; } } + + bool ClientTcpConnection::getResPackageData(const std::string& msg_req, std::shared_ptr& pb_struct) { + auto it = m_respond_datas.find(msg_req); + if(it == m_respond_datas.end()) return false; + pb_struct = it->second; + m_respond_datas.erase(it); + return true; + } } \ No newline at end of file diff --git a/src/net/tcp/io_thread.cc b/src/net/tcp/io_thread.cc index 3387094..7af89a0 100644 --- a/src/net/tcp/io_thread.cc +++ b/src/net/tcp/io_thread.cc @@ -25,9 +25,8 @@ namespace tinyrpc { void IOThread::addClient(TcpServer* ser, int fd) { - m_clients[fd] = std::shared_ptr(new ServerTcpConnection(fd, *m_reactor, *ser)); - + m_clients[fd]->addMainTaskToReactor(); } void IOThread::mainFunc() { diff --git a/src/net/tcp/server_tcp_connect.cc b/src/net/tcp/server_tcp_connect.cc index 47fbf2b..7837fc6 100644 --- a/src/net/tcp/server_tcp_connect.cc +++ b/src/net/tcp/server_tcp_connect.cc @@ -7,8 +7,8 @@ namespace tinyrpc { ServerTcpConnection::ServerTcpConnection(int fd, Reactor& reactor, TcpServer& ser) : - AbstractTcpConnection(fd, reactor), - m_server(ser) + AbstractTcpConnection(fd, reactor), + m_server(ser) { } @@ -22,7 +22,7 @@ namespace tinyrpc { bool ret = m_server.getCoder().decoder(m_readBuffer, *data); if(ret == false) { - logger() << "decode error"; + logger() << "decode uncompleted"; break; } diff --git a/src/net/tcp/tcp_client.cc b/src/net/tcp/tcp_client.cc index 2ddea7c..fe6fbca 100644 --- a/src/net/tcp/tcp_client.cc +++ b/src/net/tcp/tcp_client.cc @@ -1,5 +1,8 @@ #include "tcp_client.hpp" +#include "abstract_tcp_connect.hpp" #include "client_tcp_connect.hpp" +#include "coroutine.hpp" +#include "error_code.hpp" #include "fd_event.hpp" #include "logger.hpp" #include "net_address.hpp" @@ -11,6 +14,7 @@ namespace tinyrpc { TcpClient::TcpClient(const NetAddress& peerAddr) : + m_local_addr("127.0.0.1", 0), m_peer_addr(peerAddr), m_reactor(*Reactor::getReactor()) @@ -19,9 +23,9 @@ namespace tinyrpc { if (m_fd == -1) { logger() << "call socket error, fd=-1, sys error=" << strerror(errno); } - m_local_addr = NetAddress("127.0.0.1", 0); + m_coder = new TinypbCoder(); - m_connection = new ClientTcpConnection(m_fd, m_reactor, *this); + // m_connection = new ClientTcpConnection(m_fd, m_reactor, *this); } @@ -29,7 +33,56 @@ namespace tinyrpc { m_reactor.delFdEvent(FdEventPool::getInstance()->getFdEvent(m_fd)); if(m_fd != -1) close(m_fd); delete m_coder; - delete m_connection; + } + bool TcpClient::connectToServer() { + if(m_connection.get() == nullptr || m_connection->getState() == ClientTcpConnection::State::Disconnected) { + int ret = connect(m_fd, m_peer_addr.getSockaddr(), m_peer_addr.getSockLen()); + if(ret == -1) return false; + m_connection.reset(new ClientTcpConnection(m_fd, m_reactor, *this)); + } + return true; } + bool TcpClient::writeToSendBuffer(const AbstractData& data) { + connectToServer(); + return m_coder->encoder(m_connection->getSendBuffer(), data); + } + + int TcpClient::sendAndRecvData(const std::string& msg_req, std::shared_ptr& res) { + + if(!connectToServer()) { + logger() << "error1"; + return ERROR_FAILED_CONNECT; + } + m_connection->output(); + + if(m_connection->getState() == ClientTcpConnection::State::Disconnected) { + logger() << "error1"; + return ERROR_FAILED_GET_REPLY; + } + + do { + m_connection->input(); + m_connection->process(); + if(m_connection->getState() != ClientTcpConnection::State::Connected) { + logger() << "error1"; + return ERROR_FAILED_GET_REPLY; + } + }while(!m_connection->getResPackageData(msg_req, res)); + + return 0; + } + + + void TcpClient::addCoroutine(Coroutine& cor) { + Reactor::Task task = [&cor] { + cor.resume(); + }; + + m_reactor.addTask(task); + } + void TcpClient::start() { + Coroutine::getMainCoroutine(); + m_reactor.loop(); + } } \ No newline at end of file diff --git a/src/net/tinypb/tinypb_channel.cc b/src/net/tinypb/tinypb_channel.cc new file mode 100644 index 0000000..9a85cdd --- /dev/null +++ b/src/net/tinypb/tinypb_channel.cc @@ -0,0 +1,77 @@ +#include "tinypb_channel.hpp" +#include "error_code.hpp" +#include "logger.hpp" +#include "tinypb_controller.hpp" +#include "tinypb_data.hpp" +#include +#include + + + +namespace tinyrpc { + TinypbChannel::TinypbChannel(const NetAddress& peerAddr) : + m_client(peerAddr) + { + + + } + + void TinypbChannel::CallMethod(const google::protobuf::MethodDescriptor* method, + google::protobuf::RpcController* controller, + const google::protobuf::Message* request, + google::protobuf::Message* response, + google::protobuf::Closure* done) + { + + TinypbController* rpc_controller = dynamic_cast(controller); + rpc_controller->SetLocalAddr(m_client.getLocalAddr()); + rpc_controller->SetPeerAddr(m_client.getPeerAddr()); + + std::unique_ptr data(new TinypbData); + + data->service_full_name = method->full_name(); + + if (!request->SerializeToString(&(data->pb_data))) { + logger() << "serialize send package error"; + return; + } + + data->msg_req = TinypbData::genMsgNumber(); + data->msg_req_len = data->msg_req.length(); + rpc_controller->SetMsgReq(data->msg_req); + + m_client.writeToSendBuffer(*data); + + std::shared_ptr res; + + int ret = m_client.sendAndRecvData(data->msg_req, res); + + if(ret != 0) { + rpc_controller->SetError(ret, "sendAndRecvData err"); + return; + } + + std::shared_ptr res_data = std::dynamic_pointer_cast(res); + // CONTINUE + if(!response->ParseFromString(res_data->pb_data)) { + rpc_controller->SetError(ERROR_FAILED_DESERIALIZE, "failed to deserialize data from server"); + return; + } + + if(res_data->err_code != 0) { + rpc_controller->SetError(res_data->err_code, res_data->err_info); + return; + } + + logger() << "============================================================"; + logger() << data->msg_req << "|" << rpc_controller->PeerAddr().toString() + << "|call rpc server [" << data->service_full_name << "] succ" + << ". Get server reply response data:" << response->ShortDebugString(); + logger() << "============================================================"; + + if(done) done->Run(); + + } + + +} \ No newline at end of file diff --git a/src/net/tinypb/tinypb_coder.cc b/src/net/tinypb/tinypb_coder.cc index 18a35f3..2d09ea6 100644 --- a/src/net/tinypb/tinypb_coder.cc +++ b/src/net/tinypb/tinypb_coder.cc @@ -1,12 +1,11 @@ #include "tinypb_coder.hpp" #include "abstract_coder.hpp" +#include "logger.hpp" #include "tinypb_data.hpp" #include #include #include #include -#include -#include namespace tinyrpc { @@ -16,13 +15,16 @@ namespace tinyrpc { // static const int MSG_REQ_LEN = 20; // default length of msg_req TinypbCoder::TinypbCoder() { - // TODO + } TinypbCoder::~TinypbCoder() { - // TODO + } - bool TinypbCoder::encoder(TcpBuffer& buffer, AbstractData& data) { - TinypbData& pbdata = dynamic_cast(data); + bool TinypbCoder::encoder(TcpBuffer& buffer, const AbstractData& data) { + logger() << "encoder"; + const TinypbData& pbdata = dynamic_cast(data); + //TinypbData->encode_succ = false; TODO? + if(pbdata.msg_req.empty()) return false; if(pbdata.service_full_name.empty()) return false; if(pbdata.pb_data.empty()) return false; @@ -52,7 +54,7 @@ namespace tinyrpc { int32_t service_name_len_net = htonl(service_name_len); memcpy(&buf[cur_index], &service_name_len_net, sizeof(service_name_len_net)); cur_index += sizeof(service_name_len_net); - memcpy(&buf[cur_index], pbdata.msg_req.c_str(), service_name_len); + memcpy(&buf[cur_index], pbdata.service_full_name.c_str(), service_name_len); cur_index += service_name_len; int32_t err_code = pbdata.err_code; @@ -66,26 +68,29 @@ namespace tinyrpc { cur_index += sizeof(err_info_len_net); memcpy(&buf[cur_index], pbdata.err_info.c_str(), err_info_len); cur_index += err_info_len; - - int32_t pb_data_len = pbdata.err_info.length(); + + int32_t pb_data_len = pbdata.pb_data.length(); memcpy(&buf[cur_index], pbdata.pb_data.c_str(), pb_data_len); cur_index += pb_data_len; - int32_t check_num = 1; + int32_t check_num = 1; // checksum has not been implemented yet, directly skip chcksum int32_t check_num_net = htonl(check_num); memcpy(&buf[cur_index], &check_num_net, sizeof(check_num_net)); cur_index += sizeof(check_num_net); buf[cur_index++] = PB_END; - - memcpy(buffer.getWriteAddress(), buf.get(), pk_len); + + buffer.reserved(pk_len); + + memcpy(buffer.getWriteAddress(), buf.get(), pk_len); // 预留 buffer.writeOffset(pk_len); + return true; } bool TinypbCoder::decoder(TcpBuffer& buffer, AbstractData& data) { - + logger() << "decoder"; char* buff = static_cast(buffer.getReadAddress()); int start_index = -1; @@ -94,30 +99,33 @@ namespace tinyrpc { int pack_len = -1; for(int i = 0; i < static_cast(buffer.getReadable()); i++) { - if(buff[i] == PB_START) { + if(buff[i] != PB_START) continue; - if(i + 1 >= static_cast(buffer.getReadable())) { - return false; // 包不完整 - } - - pack_len = getInt32FromNetByte(buff[i + 1]); - end_index = pack_len + i - 1; - - if(end_index >= static_cast(buffer.getReadable())) { - continue; - } - - if(buff[end_index] == PB_END) { - isFullPack = true; - start_index = i; - break; - } - - + + if(i + 1 >= static_cast(buffer.getReadable())) { + return false; // 包不完整 } + + pack_len = getInt32FromNetByte(buff[i + 1]); + + end_index = pack_len + i - 1; + if(end_index >= static_cast(buffer.getReadable())) { + continue; // 不符合格式 + } + + + if(buff[end_index] != PB_END) { + + continue; // 不符合格式 + } + isFullPack = true; + start_index = i; + break; + } if(isFullPack == false) { + return false; // 包不完整 } @@ -207,7 +215,7 @@ namespace tinyrpc { pbdata.pb_data = std::string(&buff[cur_index], pb_data_len); cur_index += pb_data_len; - buffer.readOffset(cur_index - start_index); + buffer.readOffset(end_index + 1); return true; diff --git a/src/net/tinypb/tinypb_dispatcher.cc b/src/net/tinypb/tinypb_dispatcher.cc index 28a3483..77ab2dd 100644 --- a/src/net/tinypb/tinypb_dispatcher.cc +++ b/src/net/tinypb/tinypb_dispatcher.cc @@ -72,7 +72,7 @@ namespace tinyrpc { return; } - std::unique_ptr respondMsg (service->GetRequestPrototype(method).New()); + std::unique_ptr respondMsg (service->GetResponsePrototype(method).New()); auto callback = [&respond, &respondMsg] { if(!respondMsg->SerializePartialToString(&respond.pb_data)) { @@ -92,7 +92,7 @@ namespace tinyrpc { TinypbClosure done(callback); service->CallMethod(method, rpcController.get(), requestMsg.get(), respondMsg.get(), &done /* callback */); - + } bool TinypbDispatcher::parseServiceFullName(const std::string& name, std::string& serviceName, std::string& methodName) { diff --git a/test/clienttest/clienttest.cc b/test/clienttest/clienttest.cc new file mode 100644 index 0000000..fc71eea --- /dev/null +++ b/test/clienttest/clienttest.cc @@ -0,0 +1,66 @@ +#include "coroutine.hpp" +#include "logger.hpp" +#include "net_address.hpp" +#include "reactor.hpp" +#include "tcp_client.hpp" +#include "tcp_server.hpp" +#include "tinypb.pb.h" +#include "tinypb_channel.hpp" +#include "tinypb_closure.hpp" +#include "tinypb_controller.hpp" +#include +using namespace std; +using namespace tinyrpc; + +int n = 10; + +void test() +{ + NetAddress addr("127.0.0.1", 9001); + TinypbChannel channel(addr); + while (n--) { + logger() << "============== test no:" << n << "==============="; + + queryNameReq req_name; + req_name.set_req_no(20220315); + req_name.set_id(1100110001); + req_name.set_type(1); + queryNameRes res_name; + + queryAgeReq req_age; + req_age.set_req_no(00001111); + req_age.set_id(6781); + queryAgeRes res_age; + + TinypbClosure cb([]() { + logger() << "=========================="; + logger() << "succ call rpc"; + logger() << "=========================="; + }); + + QueryService_Stub stub(&channel); + TinypbController rpc_controller; + + stub.query_name(&rpc_controller, &req_name, &res_name, &cb); + + if (rpc_controller.ErrorCode() != 0) { + logger() << "call rpc method query_name failed, errcode=" << rpc_controller.ErrorCode() << ",error=" << rpc_controller.ErrorText(); + } + if (res_name.ret_code() != 0) { + logger() << "query name error, errcode=" << res_name.ret_code() << ", res_info=" << res_name.res_info(); + } else { + logger() << "get res_name.age = " << res_name.name(); + } + + } +} + +int main() +{ + // TcpServer server; + TcpClient client(NetAddress("127.0.0.1", 9001)); + Coroutine cor(test); + client.addCoroutine(cor); + client.start(); + return 0; +} \ No newline at end of file diff --git a/test/clienttest/tinypb.proto b/test/clienttest/tinypb.proto new file mode 100644 index 0000000..90597dd --- /dev/null +++ b/test/clienttest/tinypb.proto @@ -0,0 +1,38 @@ +syntax = "proto3"; +option cc_generic_services = true; + +message queryAgeReq { + int32 req_no = 1; + int32 id = 2; +} + +message queryAgeRes { + int32 ret_code = 1; + string res_info = 2; + int32 req_no = 3; + int32 id = 4; + int32 age = 5; +} + +message queryNameReq { + int32 req_no = 1; + int32 id = 2; + int32 type = 3; +} + +message queryNameRes { + int32 ret_code = 1; + string res_info = 2; + int32 req_no = 3; + int32 id = 4; + string name = 5; +} + + +service QueryService { + // rpc method name + rpc query_name(queryNameReq) returns (queryNameRes); + + // rpc method name + rpc query_age(queryAgeReq) returns (queryAgeRes); +} \ No newline at end of file diff --git a/test/codertest/main.cc b/test/codertest/main.cc new file mode 100644 index 0000000..2b59735 --- /dev/null +++ b/test/codertest/main.cc @@ -0,0 +1,27 @@ +#include +#include "tinypb_coder.hpp" +#include "tinypb_data.hpp" + +using namespace std; +using namespace tinyrpc; + + +int main() { + TinypbData data; + data.msg_req = "11231231312"; + data.pb_data = "121231233456"; + data.service_full_name = "aaa.b12313bb"; + TinypbCoder coder; + TcpBuffer buffer; + TinypbData newdata; + coder.encoder(buffer, data); + coder.decoder(buffer, newdata); + + + cout << newdata.msg_req << endl; + cout << newdata.pb_data << endl; + cout << newdata.service_full_name << endl; + + + return 0; +} \ No newline at end of file diff --git a/test/protobuftest/addressbook.pb.cc b/test/protobuftest/addressbook.pb.cc deleted file mode 100644 index ceed90a..0000000 --- a/test/protobuftest/addressbook.pb.cc +++ /dev/null @@ -1,1051 +0,0 @@ -// 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 deleted file mode 100644 index 41ec1f9..0000000 --- a/test/protobuftest/addressbook.pb.h +++ /dev/null @@ -1,1196 +0,0 @@ -// 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/err.info b/test/protobuftest/err.info deleted file mode 100644 index e69de29..0000000 diff --git a/test/protobuftest/my_program b/test/protobuftest/my_program deleted file mode 100755 index af5a36f..0000000 Binary files a/test/protobuftest/my_program and /dev/null differ diff --git a/test/servertest/clienttest.cc b/test/servertest/clienttest.cc deleted file mode 100644 index b7d4199..0000000 --- a/test/servertest/clienttest.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "reactor.hpp" -#include "tcp_server.hpp" -using namespace std; -using namespace tinyrpc; -void test() { - - - -} - - - -int main() { - TcpServer server; - - // server. - Reactor::getReactor()->addTask(test); - server.start(); - - return 0; -} \ No newline at end of file diff --git a/test/servertest/servertest.cc b/test/servertest/servertest.cc index 4583d56..4007d77 100644 --- a/test/servertest/servertest.cc +++ b/test/servertest/servertest.cc @@ -16,12 +16,17 @@ public: ::queryNameRes* response, ::google::protobuf::Closure* done) override { + logger() << "QueryServiceImpl.query_name, req={" << request->ShortDebugString() << "}"; + logger() << response; response->set_ret_code(0); + response->set_res_info("OK"); + response->set_req_no(request->req_no()); response->set_id(request->id()); response->set_name("yyy"); + done->Run(); }